From e6c53c4d7317e766235449535b22d0d2fe709214 Mon Sep 17 00:00:00 2001 From: zecke Date: Sat, 21 Sep 2002 15:02:50 +0000 Subject: Some more implementation in OPimRecord::setUid ORecordList implemented never compiled it though OTodo a new c'tor and some more changes --- (limited to 'libopie/pim') diff --git a/libopie/pim/opimrecord.cpp b/libopie/pim/opimrecord.cpp index d8f73c7..e510f4e 100644 --- a/libopie/pim/opimrecord.cpp +++ b/libopie/pim/opimrecord.cpp @@ -4,9 +4,6 @@ OPimRecord::OPimRecord( int uid ) : Qtopia::Record() { setUid( uid ); - /* assign a new UID */ - if ( uid == 1 ) - assignUid(); } OPimRecord::~OPimRecord() { } @@ -104,3 +101,11 @@ QString OPimRecord::crossToString()const { return str; } +/* if uid = 1 assign a new one */ +void OPimRecord::setUid( int uid ) { + + if ( uid == 1) + uid = uidGen().generate(); + + Qtopia::Record::setUid( uid ); +}; diff --git a/libopie/pim/opimrecord.h b/libopie/pim/opimrecord.h index 18112d4..297ff12 100644 --- a/libopie/pim/opimrecord.h +++ b/libopie/pim/opimrecord.h @@ -101,6 +101,7 @@ public: * */ void setRelations( const QString&, QArray ids ); + virtual void setUid( int uid ); protected: QString crossToString()const; diff --git a/libopie/pim/orecordlist.h b/libopie/pim/orecordlist.h index c17186f..65c2169 100644 --- a/libopie/pim/orecordlist.h +++ b/libopie/pim/orecordlist.h @@ -11,25 +11,34 @@ public: class Iterator { friend class ORecordList; public: - Iterator() {} - ~Iterator() {} - Iterator(const Iterator& ) {} + Iterator(); + ~Iterator(); + Iterator(const Iterator& ); Iterator &operator=(const Iterator& ); - T &operator*() {} + T &operator*(); Iterator &operator++(); + Iterator &operator--(); bool operator==( const Iterator& it ); bool operator!=( const Iterator& it ); - } - ORecordList( const QArray& ids, - OPimAccessTemplate* acc ) - : m_ids(ids ), m_acc( acc ) { + private: + Iterator( const QArray, + OPimAccessTemplate* ); - } - ~ORecordList() { + QArray m_uids; + int m_current; + OPimAccessTemplate* m_temp; + bool m_end : 1; + T m_record; - } + /* d pointer for future versions */ + class IteratorPrivate; + IteratorPrivate *d; + }; + ORecordList( const QArray& ids, + OPimAccessTemplate* acc ); + ~ORecordList(); Iterator begin(); Iterator end(); /* @@ -37,8 +46,114 @@ public: ConstIterator end()const; */ private: - QArray ids; + QArray m_ids; OPimAccessTemplate* m_acc; }; +/* ok now implement it */ +template +ORecordList::Iterator::Iterator() { + m_current = 0; + m_temp = 0l; + m_end = true; +} +template +ORecordList::Iterator::~Iterator() { +/* nothing to delete */ +} + +template +ORecordList::Iterator::Iterator( const ORecordList::Iterator& 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; +} + +template +ORecordList::Iterator &ORecordList::Iterator::operator=( const ORecordList::Iterator& 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; + + return *this; +} + +template +T &ORecordList::Iterator::operator*() { + if (!m_end ) + m_record = m_temp->find( m_uids[m_current] ); + else + m_record = T; + + return m_record; +} + +template +ORecordList::Iterator &ORecordList::Iterator::operator++() { + if (m_current < m_uids.count() ) { + m_end = false; + ++m_current; + }else + m_end = true; + + return *this; +} +template +ORecordList::Iterator &ORecordList::Iterator::operator--() { + if ( m_current > 0 ) { + --m_current; + m_end = false; + } else + m_end = true; + + return *this; +} + +template +bool ORecordList::Iterator::operator==( const ORecordList::Iterator& it ) { + + /* if both are at we're the same.... */ + if ( m_end == it.m_end ) return true; + + if ( m_uids != it.m_uids ) return false; + if ( m_current != it.m_current ) return false; + if ( m_temp != it.m_temp ) return false; + + return true; +} +template +bool ORecordList::Iterator::operator!=( const ORecordList::Iterator it ) { + return !(*this == it ); +} +template +ORecordList::Iterator::Iterator( const QArray uids, + OPimAccessTemplate* t ) + : m_uids( uids ), m_current( 0 ), m_temp( t ), m_end( false ) +{ +} +template +ORecordList::ORecordList( const QArray& ids, + OPimAccessTemplate* acc ) + : m_ids( ids ), m_acc( acc ) +{ +} +template +ORecordList::~ORecordList() { +/* nothing to do here */ +} +template +ORecordList::Iterator ORecordList::begin() { + Iterator it( m_ids, m_acc ); + return it; +} +template +ORecordList::Iterator ORecordList::end() { + Iterator it( m_ids, m_acc ); + it.m_end = true; + it.m_current = m_ids.count(); +} #endif diff --git a/libopie/pim/otodo.cpp b/libopie/pim/otodo.cpp index 3c93838..8239ba6 100644 --- a/libopie/pim/otodo.cpp +++ b/libopie/pim/otodo.cpp @@ -24,7 +24,6 @@ struct OTodo::OTodoData : public QShared { bool isCompleted:1; bool hasDate:1; int priority; - QStringList category; QString desc; QString sum; QMap extra; @@ -46,7 +45,27 @@ OTodo::~OTodo() { data = 0l; } } +OTodo::OTodo(bool completed, int priority, + const QArray &category, + const QString& summary, + const QString &description, + ushort progress, + bool hasDate, QDate date, int uid ) + : OPimRecord( uid ) +{ + //qWarning("OTodoData"); + 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, @@ -267,19 +286,19 @@ bool OTodo::operator>=(const OTodo &toDoEvent )const } bool OTodo::operator==(const OTodo &toDoEvent )const { - if( data->priority == toDoEvent.data->priority && - data->priority == toDoEvent.data->prog && - data->isCompleted == toDoEvent.data->isCompleted && - data->hasDate == toDoEvent.data->hasDate && - data->date == toDoEvent.data->date && - data->category == toDoEvent.data->category && - data->sum == toDoEvent.data->sum && - data->desc == toDoEvent.data->desc && - data->hasAlarmDateTime == toDoEvent.data->hasAlarmDateTime && - data->alarmDateTime == toDoEvent.data->alarmDateTime ) - return true; + 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 false; + return OPimRecord::operator==( toDoEvent ); } void OTodo::deref() { @@ -350,5 +369,10 @@ void OTodo::copy( OTodoData* src, OTodoData* dest ) { 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/otodo.h b/libopie/pim/otodo.h index e1729db..75af44c 100644 --- a/libopie/pim/otodo.h +++ b/libopie/pim/otodo.h @@ -55,7 +55,15 @@ public: const QString &description = QString::null, ushort progress = 0, bool hasDate = false, QDate date = QDate::currentDate(), - int uid = -1 ); + int uid = 0 /*empty*/ ); + + OTodo( bool completed, int priority, + const QArray& category, + const QString& summary = QString::null, + const QString& description = QString::null, + ushort progress = 0, + bool hasDate = false, QDate date = QDate::currentDate(), + int uid = 0 /* empty */ ); /* Copy c'tor -- cgit v0.9.0.2