-rw-r--r-- | libopie/pim/orecordlist.h | 12 | ||||
-rw-r--r-- | libopie/pim/otodo.cpp | 25 | ||||
-rw-r--r-- | libopie/pim/otodoaccessxml.cpp | 2 |
3 files changed, 21 insertions, 18 deletions
diff --git a/libopie/pim/orecordlist.h b/libopie/pim/orecordlist.h index 75bb33c..36728b8 100644 --- a/libopie/pim/orecordlist.h +++ b/libopie/pim/orecordlist.h @@ -19,49 +19,49 @@ template <class T = OPimRecord> class ORecordListIterator { friend class ORecordList<T>; public: typedef OTemplateBase<T> Base; /** * The c'tor used internally from * ORecordList */ ORecordListIterator( const QArray<int>, const Base* ); /** * The standard c'tor */ ORecordListIterator(); ~ORecordListIterator(); ORecordListIterator( const ORecordListIterator& ); ORecordListIterator &operator=(const ORecordListIterator& ); /** * a * operator ;) * use it like this T = (*it); */ - T &operator*(); + T operator*(); ORecordListIterator &operator++(); ORecordListIterator &operator--(); bool operator==( const ORecordListIterator& it ); bool operator!=( const ORecordListIterator& it ); private: QArray<int> m_uids; int m_current; const Base* m_temp; bool m_end : 1; T m_record; /* d pointer for future versions */ class IteratorPrivate; IteratorPrivate *d; }; /** * The recordlist used as a return type * from OPimAccessTemplate */ template <class T = OPimRecord > class ORecordList { public: @@ -78,78 +78,79 @@ public: /** * the first iterator */ Iterator begin(); /** * the end */ Iterator end(); /* ConstIterator begin()const; ConstIterator end()const; */ private: QArray<int> m_ids; const Base* m_acc; }; /* ok now implement it */ template <class T> ORecordListIterator<T>::ORecordListIterator() { m_current = 0; m_temp = 0l; m_end = true; + m_record = T(); } template <class T> ORecordListIterator<T>::~ORecordListIterator() { /* nothing to delete */ } template <class T> ORecordListIterator<T>::ORecordListIterator( const ORecordListIterator<T>& it) { - qWarning("ORecordListIterator"); +// qWarning("ORecordListIterator copy c'tor"); m_uids = it.m_uids; m_current = it.m_current; m_temp = it.m_temp; m_end = it.m_end; m_record = it.m_record; } template <class T> ORecordListIterator<T> &ORecordListIterator<T>::operator=( const ORecordListIterator<T>& it) { m_uids = it.m_uids; m_current = it.m_current; m_temp = it.m_temp; m_end = it.m_end; - m_record = it.m_record; +// m_record = it.m_record; return *this; } template <class T> -T &ORecordListIterator<T>::operator*() { - qWarning("operator* %d %d", m_current, m_uids[m_current] ); +T ORecordListIterator<T>::operator*() { +// qWarning("operator* %d %d", m_current, m_uids[m_current] ); if (!m_end ) m_record = m_temp->find( m_uids[m_current] ); else m_record = T(); return m_record; } template <class T> ORecordListIterator<T> &ORecordListIterator<T>::operator++() { if (m_current < (int)m_uids.count() ) { m_end = false; ++m_current; }else m_end = true; return *this; } template <class T> ORecordListIterator<T> &ORecordListIterator<T>::operator--() { if ( m_current > 0 ) { --m_current; m_end = false; } else @@ -172,37 +173,36 @@ bool ORecordListIterator<T>::operator==( const ORecordListIterator<T>& it ) { } template <class T> bool ORecordListIterator<T>::operator!=( const ORecordListIterator<T>& it ) { return !(*this == it ); } template <class T> ORecordListIterator<T>::ORecordListIterator( const QArray<int> uids, const Base* t ) : m_uids( uids ), m_current( 0 ), m_temp( t ), m_end( false ) { } template <class T> ORecordList<T>::ORecordList( const QArray<int>& ids, const Base* acc ) : m_ids( ids ), m_acc( acc ) { } template <class T> ORecordList<T>::~ORecordList() { /* nothing to do here */ } template <class T> ORecordList<T>::Iterator ORecordList<T>::begin() { - qWarning("ORecordList::begin"); Iterator it( m_ids, m_acc ); return it; } template <class T> ORecordList<T>::Iterator ORecordList<T>::end() { Iterator it( m_ids, m_acc ); it.m_end = true; it.m_current = m_ids.count(); return it; } #endif diff --git a/libopie/pim/otodo.cpp b/libopie/pim/otodo.cpp index b3c14e6..cc46b21 100644 --- a/libopie/pim/otodo.cpp +++ b/libopie/pim/otodo.cpp @@ -15,95 +15,96 @@ #include "otodo.h" struct OTodo::OTodoData : public QShared { OTodoData() : QShared() { }; QDate date; bool isCompleted:1; bool hasDate:1; int priority; QString desc; QString sum; QMap<QString, QString> extra; ushort prog; bool hasAlarmDateTime :1; QDateTime alarmDateTime; }; OTodo::OTodo(const OTodo &event ) : OPimRecord( event ), data( event.data ) { data->ref(); - qWarning("ref up"); +// qWarning("ref up"); } OTodo::~OTodo() { - qWarning("~OTodo " + data->sum ); + +// qWarning("~OTodo " ); if ( data->deref() ) { - qWarning("OTodo::dereffing"); +// qWarning("OTodo::dereffing"); delete data; data = 0l; } } OTodo::OTodo(bool completed, int priority, const QArray<int> &category, const QString& summary, const QString &description, ushort progress, bool hasDate, QDate date, int uid ) : OPimRecord( uid ) { - qWarning("OTodoData " + summary); +// qWarning("OTodoData " + summary); setCategories( category ); data = new OTodoData; data->date = date; data->isCompleted = completed; data->hasDate = hasDate; data->priority = priority; data->sum = summary; data->prog = progress; data->desc = Qtopia::simplifyMultiLineSpace(description ); data->hasAlarmDateTime = false; } OTodo::OTodo(bool completed, int priority, const QStringList &category, const QString& summary, const QString &description, ushort progress, bool hasDate, QDate date, int uid ) : OPimRecord( uid ) { - qWarning("OTodoData" + summary); +// qWarning("OTodoData" + summary); setCategories( idsFromString( category.join(";") ) ); data = new OTodoData; - data->date = date; + data->date = date; data->isCompleted = completed; data->hasDate = hasDate; data->priority = priority; data->sum = summary; data->prog = progress; data->desc = Qtopia::simplifyMultiLineSpace(description ); data->hasAlarmDateTime = false; } bool OTodo::match( const QRegExp ®Exp )const { if( QString::number( data->priority ).find( regExp ) != -1 ){ return true; }else if( data->hasDate && data->date.toString().find( regExp) != -1 ){ return true; }else if(data->desc.find( regExp ) != -1 ){ return true; }else if(data->sum.find( regExp ) != -1 ) { return true; } return false; } bool OTodo::isCompleted() const { @@ -139,48 +140,49 @@ QDateTime OTodo::alarmDateTime() const return data->alarmDateTime; } QString OTodo::description()const { return data->desc; } void OTodo::setCompleted( bool completed ) { changeOrModify(); data->isCompleted = completed; } void OTodo::setHasDueDate( bool hasDate ) { changeOrModify(); data->hasDate = hasDate; } void OTodo::setHasAlarmDateTime( bool hasAlarmDateTime ) { changeOrModify(); data->hasAlarmDateTime = hasAlarmDateTime; } void OTodo::setDescription(const QString &desc ) { + qWarning( "desc " + desc ); changeOrModify(); data->desc = Qtopia::simplifyMultiLineSpace(desc ); } void OTodo::setSummary( const QString& sum ) { changeOrModify(); data->sum = sum; } void OTodo::setPriority(int prio ) { changeOrModify(); data->priority = prio; } void OTodo::setDueDate( QDate date ) { changeOrModify(); data->date = date; } void OTodo::setAlarmDateTime( const QDateTime& alarm ) { changeOrModify(); data->alarmDateTime = alarm; } bool OTodo::isOverdue( ) @@ -286,97 +288,98 @@ bool OTodo::operator>=(const OTodo &toDoEvent )const }else{ return dueDate() > toDoEvent.dueDate(); } } return true; } bool OTodo::operator==(const OTodo &toDoEvent )const { if ( data->priority != toDoEvent.data->priority ) return false; if ( data->priority != toDoEvent.data->prog ) return false; if ( data->isCompleted != toDoEvent.data->isCompleted ) return false; if ( data->hasDate != toDoEvent.data->hasDate ) return false; if ( data->date != toDoEvent.data->date ) return false; if ( data->sum != toDoEvent.data->sum ) return false; if ( data->desc != toDoEvent.data->desc ) return false; if ( data->hasAlarmDateTime != toDoEvent.data->hasAlarmDateTime ) return false; if ( data->alarmDateTime != toDoEvent.data->alarmDateTime ) return false; return OPimRecord::operator==( toDoEvent ); } void OTodo::deref() { - //qWarning("deref in ToDoEvent"); +// qWarning("deref in ToDoEvent"); if ( data->deref() ) { - //qWarning("deleting"); +// qWarning("deleting"); delete data; - d= 0; + data= 0; } } OTodo &OTodo::operator=(const OTodo &item ) { - OPimRecord::operator=( item ); +// OPimRecord::operator=( item ); //qWarning("operator= ref "); item.data->ref(); deref(); + data = item.data; return *this; } QMap<int, QString> OTodo::toMap() const { QMap<int, QString> map; map.insert( Uid, QString::number( uid() ) ); map.insert( Category, idsToString( categories() ) ); map.insert( HasDate, QString::number( data->hasDate ) ); map.insert( Completed, QString::number( data->isCompleted ) ); map.insert( Description, data->desc ); map.insert( Summary, data->sum ); map.insert( Priority, QString::number( data->priority ) ); map.insert( DateDay, QString::number( data->date.day() ) ); map.insert( DateMonth, QString::number( data->date.month() ) ); map.insert( DateYear, QString::number( data->date.year() ) ); map.insert( Progress, QString::number( data->prog ) ); map.insert( CrossReference, crossToString() ); map.insert( HasAlarmDateTime, QString::number( data->hasAlarmDateTime ) ); map.insert( AlarmDateTime, data->alarmDateTime.toString() ); return map; } QMap<QString, QString> OTodo::toExtraMap()const { return data->extra; } /** * change or modify looks at the ref count and either * creates a new QShared Object or it can modify it * right in place */ void OTodo::changeOrModify() { if ( data->count != 1 ) { - qWarning("changeOrModify"); +// qWarning("changeOrModify"); data->deref(); OTodoData* d2 = new OTodoData(); copy(data, d2 ); data = d2; } } void OTodo::copy( OTodoData* src, OTodoData* dest ) { dest->date = src->date; dest->isCompleted = src->isCompleted; dest->hasDate = src->hasDate; dest->priority = src->priority; dest->desc = src->desc; dest->sum = src->sum; dest->extra = src->extra; dest->prog = src->prog; dest->hasAlarmDateTime = src->hasAlarmDateTime; dest->alarmDateTime = src->alarmDateTime; } QString OTodo::type() const { return QString::fromLatin1("OTodo"); } QString OTodo::recordField(int id )const { return QString::null; } diff --git a/libopie/pim/otodoaccessxml.cpp b/libopie/pim/otodoaccessxml.cpp index 21756c9..3a72881 100644 --- a/libopie/pim/otodoaccessxml.cpp +++ b/libopie/pim/otodoaccessxml.cpp @@ -47,56 +47,56 @@ bool OTodoAccessXML::load() { Opie::XMLElement *root = Opie::XMLElement::load( m_file ); int day, year, month; day = year = month = -1; /* if opened */ if ( root != 0l ) { Opie::XMLElement *element = root->firstChild(); if ( element == 0l ) return false; element = element->firstChild(); while ( element ) { if ( element->tagName() != QString::fromLatin1("Task") ) { element = element->nextChild(); continue; } /* here is the right element for a task */ OTodo ev = todo( &dict, element ); m_events.insert( ev.uid(), ev ); element = element->nextChild(); } - return true; }else { qWarning("could not parse"); return false;; } delete root; m_opened = true; + qWarning("Access %d" + m_events.count() ); return true; } bool OTodoAccessXML::reload() { return load(); } bool OTodoAccessXML::save() { if (!m_opened || !m_changed ) return true; QString strNewFile = m_file + ".new"; QFile f( strNewFile ); if (!f.open( IO_WriteOnly|IO_Raw ) ) return false; int written; QString out; out = "<!DOCTYPE Tasks>\n<Tasks>\n"; // for all todos QMap<int, OTodo>::Iterator it; for (it = m_events.begin(); it != m_events.end(); ++it ) { out+= "<Task " + toString( (*it) ) + " />\n"; QCString cstr = out.utf8(); written = f.writeBlock( cstr.data(), cstr.length() ); |