summaryrefslogtreecommitdiff
path: root/libopie2
Unidiff
Diffstat (limited to 'libopie2') (more/less context) (show whitespace changes)
-rw-r--r--libopie2/opiepim/core/core.pro3
-rw-r--r--libopie2/opiepim/core/ocontactaccess.cpp7
-rw-r--r--libopie2/opiepim/core/ocontactaccess.h47
-rw-r--r--libopie2/opiepim/core/odatebookaccess.cpp35
-rw-r--r--libopie2/opiepim/core/odatebookaccess.h9
-rw-r--r--libopie2/opiepim/core/opimaccesstemplate.h345
-rw-r--r--libopie2/opiepim/core/opimcontact.cpp24
-rw-r--r--libopie2/opiepim/core/opimcontact.h4
-rw-r--r--libopie2/opiepim/core/opimevent.cpp19
-rw-r--r--libopie2/opiepim/core/opimevent.h22
-rw-r--r--libopie2/opiepim/core/opimglobal.h12
-rw-r--r--libopie2/opiepim/core/opimnotifymanager.cpp5
-rw-r--r--libopie2/opiepim/core/opimoccurrence.cpp319
-rw-r--r--libopie2/opiepim/core/opimoccurrence.h142
-rw-r--r--libopie2/opiepim/core/opimrecord.cpp23
-rw-r--r--libopie2/opiepim/core/opimrecord.h9
-rw-r--r--libopie2/opiepim/core/opimrecordlist.h15
-rw-r--r--libopie2/opiepim/core/opimresolver.h2
-rw-r--r--libopie2/opiepim/core/opimstate.h6
-rw-r--r--libopie2/opiepim/core/opimtemplatebase.cpp112
-rw-r--r--libopie2/opiepim/core/opimtemplatebase.h135
-rw-r--r--libopie2/opiepim/core/opimtimezone.cpp44
-rw-r--r--libopie2/opiepim/core/opimtodo.cpp127
-rw-r--r--libopie2/opiepim/core/opimtodo.h11
-rw-r--r--libopie2/opiepim/core/otodoaccess.cpp23
-rw-r--r--libopie2/opiepim/core/otodoaccess.h36
26 files changed, 1226 insertions, 310 deletions
diff --git a/libopie2/opiepim/core/core.pro b/libopie2/opiepim/core/core.pro
index b1b5655..f943318 100644
--- a/libopie2/opiepim/core/core.pro
+++ b/libopie2/opiepim/core/core.pro
@@ -12,6 +12,7 @@ HEADERS += \
12 core/opimmaintainer.h \ 12 core/opimmaintainer.h \
13 core/opimnotify.h \ 13 core/opimnotify.h \
14 core/opimnotifymanager.h \ 14 core/opimnotifymanager.h \
15 core/opimoccurrence.h \
15 core/opimrecord.h \ 16 core/opimrecord.h \
16 core/opimrecordlist.h \ 17 core/opimrecordlist.h \
17 core/opimrecurrence.h \ 18 core/opimrecurrence.h \
@@ -35,10 +36,12 @@ SOURCES += \
35 core/opimmaintainer.cpp \ 36 core/opimmaintainer.cpp \
36 core/opimnotify.cpp \ 37 core/opimnotify.cpp \
37 core/opimnotifymanager.cpp \ 38 core/opimnotifymanager.cpp \
39 core/opimoccurrence.cpp \
38 core/opimrecord.cpp \ 40 core/opimrecord.cpp \
39 core/opimrecurrence.cpp \ 41 core/opimrecurrence.cpp \
40 core/opimresolver.cpp \ 42 core/opimresolver.cpp \
41 core/opimstate.cpp \ 43 core/opimstate.cpp \
44 core/opimtemplatebase.cpp \
42 core/opimtimezone.cpp \ 45 core/opimtimezone.cpp \
43 core/opimtodo.cpp \ 46 core/opimtodo.cpp \
44 core/opimxref.cpp \ 47 core/opimxref.cpp \
diff --git a/libopie2/opiepim/core/ocontactaccess.cpp b/libopie2/opiepim/core/ocontactaccess.cpp
index 771d855..9bbc820 100644
--- a/libopie2/opiepim/core/ocontactaccess.cpp
+++ b/libopie2/opiepim/core/ocontactaccess.cpp
@@ -70,7 +70,6 @@ OPimContactAccess::OPimContactAccess ( const QString appname, const QString ,
70 * will use the XML-Backend as default (until we have a cute SQL-Backend..). 70 * will use the XML-Backend as default (until we have a cute SQL-Backend..).
71 */ 71 */
72 if( end == 0 ) { 72 if( end == 0 ) {
73 owarn << "Using BackendFactory !" << oendl;
74 end = OBackendFactory<OPimContactAccessBackend>::defaultBackend( OPimGlobal::CONTACTLIST, appname ); 73 end = OBackendFactory<OPimContactAccessBackend>::defaultBackend( OPimGlobal::CONTACTLIST, appname );
75 } 74 }
76 // Set backend locally and in template 75 // Set backend locally and in template
@@ -128,11 +127,14 @@ bool OPimContactAccess::hasQuerySettings ( int querySettings ) const
128{ 127{
129 return ( m_backEnd->hasQuerySettings ( querySettings ) ); 128 return ( m_backEnd->hasQuerySettings ( querySettings ) );
130} 129}
130
131#if 0
131OPimRecordList<OPimContact> OPimContactAccess::sorted( bool ascending, int sortOrder, int sortFilter, int cat ) const 132OPimRecordList<OPimContact> OPimContactAccess::sorted( bool ascending, int sortOrder, int sortFilter, int cat ) const
132{ 133{
133 QArray<int> matchingContacts = m_backEnd -> sorted( ascending, sortOrder, sortFilter, cat ); 134 QArray<int> matchingContacts = m_backEnd -> sorted( ascending, sortOrder, sortFilter, cat );
134 return ( OPimRecordList<OPimContact>(matchingContacts, this) ); 135 return ( OPimRecordList<OPimContact>(matchingContacts, this) );
135} 136}
137#endif
136 138
137 139
138bool OPimContactAccess::wasChangedExternally()const 140bool OPimContactAccess::wasChangedExternally()const
@@ -144,13 +146,10 @@ bool OPimContactAccess::wasChangedExternally()const
144void OPimContactAccess::copMessage( const QCString &msg, const QByteArray & ) 146void OPimContactAccess::copMessage( const QCString &msg, const QByteArray & )
145{ 147{
146 if ( msg == "addressbookUpdated()" ){ 148 if ( msg == "addressbookUpdated()" ){
147 owarn << "OPimContactAccess: Received addressbokUpdated()" << oendl;
148 emit signalChanged ( this ); 149 emit signalChanged ( this );
149 } else if ( msg == "flush()" ) { 150 } else if ( msg == "flush()" ) {
150 owarn << "OPimContactAccess: Received flush()" << oendl;
151 save (); 151 save ();
152 } else if ( msg == "reload()" ) { 152 } else if ( msg == "reload()" ) {
153 owarn << "OPimContactAccess: Received reload()" << oendl;
154 reload (); 153 reload ();
155 emit signalChanged ( this ); 154 emit signalChanged ( this );
156 } 155 }
diff --git a/libopie2/opiepim/core/ocontactaccess.h b/libopie2/opiepim/core/ocontactaccess.h
index 4429b6f..691ece2 100644
--- a/libopie2/opiepim/core/ocontactaccess.h
+++ b/libopie2/opiepim/core/ocontactaccess.h
@@ -60,6 +60,26 @@ class OPimContactAccess: public QObject, public OPimAccessTemplate<OPimContact>
60 Q_OBJECT 60 Q_OBJECT
61 61
62 public: 62 public:
63 enum SortFilter {
64 DoNotShowNoneChildren = FilterCustom<<1,
65 DoNotShowNoneAnniversary = FilterCustom<<2,
66 DoNotShowNoneBirthday = FilterCustom<<3,
67 DoNotShowNoHomeAddress = FilterCustom<<4,
68 DoNotShowNoBusinessAddress = FilterCustom<<5
69 };
70
71 enum SortOrder {
72 SortTitle = SortCustom,
73 SortFirstName,
74 SortMiddleName,
75 SortSuffix,
76 SortEmail,
77 SortNickname,
78 SortAnniversary,
79 SortBirthday,
80 SortGender
81 };
82
63 /** 83 /**
64 * Create Database with contacts (addressbook). 84 * Create Database with contacts (addressbook).
65 * @param appname Name of application which wants access to the database 85 * @param appname Name of application which wants access to the database
@@ -78,31 +98,6 @@ class OPimContactAccess: public QObject, public OPimAccessTemplate<OPimContact>
78 OPimContactAccessBackend* backend = 0l, bool handlesync = true); 98 OPimContactAccessBackend* backend = 0l, bool handlesync = true);
79 ~OPimContactAccess (); 99 ~OPimContactAccess ();
80 100
81 /** Constants for query.
82 * Use this constants to set the query parameters.
83 * Note: <i>query_IgnoreCase</i> just make sense with one of the other attributes !
84 * @see queryByExample()
85 */
86 enum QuerySettings {
87 WildCards = 0x0001,
88 IgnoreCase = 0x0002,
89 RegExp = 0x0004,
90 ExactMatch = 0x0008,
91 MatchOne = 0x0010, // Only one Entry must match
92 DateDiff = 0x0020, // Find all entries from today until given date
93 DateYear = 0x0040, // The year matches
94 DateMonth = 0x0080, // The month matches
95 DateDay = 0x0100, // The day matches
96 };
97
98
99 /** Return all Contacts in a sorted manner.
100 * @param ascending true: Sorted in acending order.
101 * @param sortOrder Currently not implemented. Just defined to stay compatible to otodoaccess
102 * @param sortFilter Currently not implemented. Just defined to stay compatible to otodoaccess
103 * @param cat Currently not implemented. Just defined to stay compatible to otodoaccess
104 */
105 List sorted( bool ascending, int sortOrder, int sortFilter, int cat ) const;
106 101
107 /** Return all possible settings. 102 /** Return all possible settings.
108 * @return All settings provided by the current backend 103 * @return All settings provided by the current backend
@@ -144,8 +139,6 @@ class OPimContactAccess: public QObject, public OPimAccessTemplate<OPimContact>
144 139
145 140
146 private: 141 private:
147 // class OPimContactAccessPrivate;
148 // OPimContactAccessPrivate* d;
149 OPimContactAccessBackend *m_backEnd; 142 OPimContactAccessBackend *m_backEnd;
150 bool m_loading:1; 143 bool m_loading:1;
151 144
diff --git a/libopie2/opiepim/core/odatebookaccess.cpp b/libopie2/opiepim/core/odatebookaccess.cpp
index 440ee0a..32fbb7d 100644
--- a/libopie2/opiepim/core/odatebookaccess.cpp
+++ b/libopie2/opiepim/core/odatebookaccess.cpp
@@ -39,7 +39,7 @@ namespace Opie {
39 * @param back The backend to be used or 0 for the default backend 39 * @param back The backend to be used or 0 for the default backend
40 * @param ac What kind of access is intended 40 * @param ac What kind of access is intended
41 */ 41 */
42ODateBookAccess::ODateBookAccess( ODateBookAccessBackend* back, enum Access ac ) 42ODateBookAccess::ODateBookAccess( ODateBookAccessBackend* back, enum Access )
43 : OPimAccessTemplate<OPimEvent>( back ) 43 : OPimAccessTemplate<OPimEvent>( back )
44{ 44{
45 if (!back ) 45 if (!back )
@@ -51,15 +51,6 @@ ODateBookAccess::ODateBookAccess( ODateBookAccessBackend* back, enum Access ac )
51ODateBookAccess::~ODateBookAccess() { 51ODateBookAccess::~ODateBookAccess() {
52} 52}
53 53
54/**
55 * @return all events available
56 */
57ODateBookAccess::List ODateBookAccess::rawEvents()const {
58 QArray<int> ints = m_backEnd->rawEvents();
59
60 List lis( ints, this );
61 return lis;
62}
63 54
64/** 55/**
65 * @return all repeating events 56 * @return all repeating events
@@ -82,34 +73,20 @@ ODateBookAccess::List ODateBookAccess::nonRepeats()const {
82} 73}
83 74
84/** 75/**
85 * @return dates in the time span between from and to
86 * @param from Include all events from...
87 * @param to Include all events to...
88 */
89OEffectiveEvent::ValueList ODateBookAccess::effectiveEvents( const QDate& from, const QDate& to ) const {
90 return m_backEnd->effectiveEvents( from, to );
91}
92/**
93 * @return all events at a given datetime
94 */
95OEffectiveEvent::ValueList ODateBookAccess::effectiveEvents( const QDateTime& start ) const {
96 return m_backEnd->effectiveEvents( start );
97}
98
99/**
100 * @return non repeating dates in the time span between from and to 76 * @return non repeating dates in the time span between from and to
101 * @param from Include all events from... 77 * @param from Include all events from...
102 * @param to Include all events to... 78 * @param to Include all events to...
103 */ 79 */
104OEffectiveEvent::ValueList ODateBookAccess::effectiveNonRepeatingEvents( const QDate& from, const QDate& to ) const { 80OPimOccurrence::List ODateBookAccess::effectiveNonRepeatingEvents( const QDate& from, const QDate& to ) const {
105 return m_backEnd->effectiveNonRepeatingEvents( from, to ); 81 return OPimBase::convertOccurrenceFromBackend( m_backEnd->effectiveNonRepeatingEvents( from, to ) );
106} 82}
107/** 83/**
108 * @return all non repeating events at a given datetime 84 * @return all non repeating events at a given datetime
109 */ 85 */
110OEffectiveEvent::ValueList ODateBookAccess::effectiveNonRepeatingEvents( const QDateTime& start ) const { 86OPimOccurrence::List ODateBookAccess::effectiveNonRepeatingEvents( const QDateTime& start ) const {
111 return m_backEnd->effectiveNonRepeatingEvents( start ); 87 return OPimBase::convertOccurrenceFromBackend( m_backEnd->effectiveNonRepeatingEvents( start ) );
112} 88}
89
113int ODateBookAccess::rtti() const 90int ODateBookAccess::rtti() const
114{ 91{
115 return OPimResolver::DateBook; 92 return OPimResolver::DateBook;
diff --git a/libopie2/opiepim/core/odatebookaccess.h b/libopie2/opiepim/core/odatebookaccess.h
index c6c3598..0be8606 100644
--- a/libopie2/opiepim/core/odatebookaccess.h
+++ b/libopie2/opiepim/core/odatebookaccess.h
@@ -49,9 +49,6 @@ public:
49 ODateBookAccess( ODateBookAccessBackend* = 0l, enum Access acc = Random ); 49 ODateBookAccess( ODateBookAccessBackend* = 0l, enum Access acc = Random );
50 ~ODateBookAccess(); 50 ~ODateBookAccess();
51 51
52 /* return all events */
53 List rawEvents()const;
54
55 /* return repeating events */ 52 /* return repeating events */
56 List rawRepeats()const; 53 List rawRepeats()const;
57 54
@@ -59,10 +56,8 @@ public:
59 List nonRepeats()const; 56 List nonRepeats()const;
60 57
61 /* return non repeating events (from,to) */ 58 /* return non repeating events (from,to) */
62 OEffectiveEvent::ValueList effectiveEvents( const QDate& from, const QDate& to ) const; 59 OPimOccurrence::List effectiveNonRepeatingEvents( const QDate& from, const QDate& to ) const;
63 OEffectiveEvent::ValueList effectiveEvents( const QDateTime& start ) const; 60 OPimOccurrence::List effectiveNonRepeatingEvents( const QDateTime& start ) const;
64 OEffectiveEvent::ValueList effectiveNonRepeatingEvents( const QDate& from, const QDate& to ) const;
65 OEffectiveEvent::ValueList effectiveNonRepeatingEvents( const QDateTime& start ) const;
66 61
67 /** 62 /**
68 * Return identification of used records 63 * Return identification of used records
diff --git a/libopie2/opiepim/core/opimaccesstemplate.h b/libopie2/opiepim/core/opimaccesstemplate.h
index f936d4e..2deb92a 100644
--- a/libopie2/opiepim/core/opimaccesstemplate.h
+++ b/libopie2/opiepim/core/opimaccesstemplate.h
@@ -40,6 +40,7 @@
40 40
41/* QT */ 41/* QT */
42#include <qarray.h> 42#include <qarray.h>
43#include <qdatetime.h>
43 44
44namespace Opie { 45namespace Opie {
45 46
@@ -56,6 +57,9 @@ class OPimAccessTemplatePrivate;
56template <class T = OPimRecord > 57template <class T = OPimRecord >
57class OPimAccessTemplate : public OTemplateBase<T> { 58class OPimAccessTemplate : public OTemplateBase<T> {
58public: 59public:
60 /**
61 *
62 */
59 enum Access { 63 enum Access {
60 Random = 0, 64 Random = 0,
61 SortedAccess 65 SortedAccess
@@ -64,124 +68,72 @@ public:
64 typedef OPimAccessBackend<T> BackEnd; 68 typedef OPimAccessBackend<T> BackEnd;
65 typedef OPimCache<T> Cache; 69 typedef OPimCache<T> Cache;
66 70
67 /** 71 //@{
68 * c'tor BackEnd
69 * enum Access a small hint on how to handle the backend
70 */
71 OPimAccessTemplate( BackEnd* end); 72 OPimAccessTemplate( BackEnd* end);
72
73 virtual ~OPimAccessTemplate(); 73 virtual ~OPimAccessTemplate();
74 //@}
74 75
75 /** 76 //@{
76 * load from the backend
77 */
78 bool load(); 77 bool load();
79
80 /** Reload database.
81 * You should execute this function if the external database
82 * was changed.
83 * This function will load the external database and afterwards
84 * rejoin the local changes. Therefore the local database will be set consistent.
85 */
86 virtual bool reload(); 78 virtual bool reload();
87
88 /** Save contacts database.
89 * Save is more a "commit". After calling this function, all changes are public available.
90 * @return true if successful
91 */
92 bool save(); 79 bool save();
80 void clear() ;
81 //@}
82
93 83
94 /**
95 * if the resource was changed externally
96 * You should use the signal handling instead of polling possible changes !
97 * zecke: Do you implement a signal for otodoaccess ?
98 */
99 bool wasChangedExternally()const; 84 bool wasChangedExternally()const;
100 85
101 /** 86 //@{
102 * return a List of records
103 * you can iterate over them
104 */
105 virtual List allRecords()const; 87 virtual List allRecords()const;
106
107 /**
108 * return a List of records
109 * that match the regex
110 */
111 virtual List matchRegexp( const QRegExp &r ) const; 88 virtual List matchRegexp( const QRegExp &r ) const;
112
113 /**
114 * queryByExample.
115 * @see otodoaccess, ocontactaccess
116 */
117 virtual List queryByExample( const T& t, int querySettings, const QDateTime& d = QDateTime() ); 89 virtual List queryByExample( const T& t, int querySettings, const QDateTime& d = QDateTime() );
118 90 virtual T find( UID uid )const;
119 /** 91 virtual T find( UID uid, const QArray<int>&,
120 * find the OPimRecord uid
121 */
122 T find( int uid )const;
123
124 /**
125 * read ahead cache find method ;)
126 */
127 T find( int uid, const QArray<int>&,
128 uint current, typename OTemplateBase<T>::CacheDirection dir = OTemplateBase<T>::Forward )const; 92 uint current, typename OTemplateBase<T>::CacheDirection dir = OTemplateBase<T>::Forward )const;
93 virtual List sorted( const List&, bool ascending, int sortOrder,
94 int sortFilter, int cat )const;
95 virtual List sorted( const List&, bool ascending, int sortOrder,
96 int sortFilter, const QArray<UID>& cats )const;
97 virtual List sorted( bool ascending, int sortOrder, int sortFilter, int cat )const;
98 virtual List sorted( bool ascending, int sortOrder, int sortOrder,
99 const QArray<UID>& cats )const;
100 //@}
129 101
130
131 /* invalidate cache here */
132 /** 102 /**
133 * clears the backend and invalidates the backend 103 * (Re)Implementation
134 */
135 void clear() ;
136
137 /**
138 * add T to the backend
139 * @param t The item to add.
140 * @return <i>true</i> if added successfully.
141 */ 104 */
105 //@{
106 UIDArray matchRegexpSimple( const QRegExp& r )const;
107 UIDArray queryByExampleSimple( const OPimRecord*, int, const QDateTime& )const;
108 UIDArray sortedSimple( const UIDArray&, bool asc, int sortOrder,
109 int sortFilter, int cat )const;
110 UIDArray sortedSimple( const UIDArray&, bool asc, int sortOrder,
111 int sortFilter, const QArray<int>& )const;
112 UIDArray sortedSimple( bool ascending, int sortOrder, int sortFilter,
113 int cat )const;
114 UIDArray sortedSimple( bool ascending, int sortOrder, int sortFilter,
115 const QArray<int>& )const;
116 OPimOccurrence::List occurrences( const QDate& start, const QDate& end )const;
117 OPimOccurrence::List occurrences( const QDateTime& dt )const;
118 //@}
119
120 //@{
142 virtual bool add( const T& t ) ; 121 virtual bool add( const T& t ) ;
143
144 bool add( const OPimRecord& ); 122 bool add( const OPimRecord& );
145 /**
146 * Add an Opie PimRecord.
147 * Info: Take this if you are working with OPimRecords and you need to add it into any database.
148 * But take care that the accessing database is compatible to the real type of OPimRecord !!
149 * Otherwise this access will be rejected !
150 */
151 bool add( const OPimRecord* ); 123 bool add( const OPimRecord* );
152
153
154 /* only the uid matters */
155 /**
156 * remove T from the backend
157 * @param t The item to remove
158 * @return <i>true</i> if successful.
159 */
160 virtual bool remove( const T& t ); 124 virtual bool remove( const T& t );
161 125 bool remove( UID uid );
162 /**
163 * remove the OPimRecord with uid
164 * @param uid The ID of the item to remove
165 * @return <i>true</i> if successful.
166 */
167 bool remove( int uid );
168 bool remove( const OPimRecord& ); 126 bool remove( const OPimRecord& );
169
170 /**
171 * replace T from backend
172 * @param t The item to replace
173 * @return <i>true</i> if successful.
174 */
175 virtual bool replace( const T& t) ; 127 virtual bool replace( const T& t) ;
176 128
129 //@}
130
177 void setReadAhead( uint count ); 131 void setReadAhead( uint count );
178 /** 132 virtual T cacheFind( int uid )const;
179 * @internal
180 */
181 void cache( const T& )const; 133 void cache( const T& )const;
182 void setSaneCacheSize( int ); 134 void setSaneCacheSize( int );
183 135
184 QArray<int> records()const; 136 QArray<UID> records()const;
185protected: 137protected:
186 /** 138 /**
187 * invalidate the cache 139 * invalidate the cache
@@ -202,6 +154,10 @@ private:
202 154
203}; 155};
204 156
157/**
158 * c'tor BackEnd
159 * enum Access a small hint on how to handle the backend
160 */
205template <class T> 161template <class T>
206OPimAccessTemplate<T>::OPimAccessTemplate( BackEnd* end ) 162OPimAccessTemplate<T>::OPimAccessTemplate( BackEnd* end )
207 : OTemplateBase<T>(), m_backEnd( end ) 163 : OTemplateBase<T>(), m_backEnd( end )
@@ -211,39 +167,76 @@ OPimAccessTemplate<T>::OPimAccessTemplate( BackEnd* end )
211} 167}
212template <class T> 168template <class T>
213OPimAccessTemplate<T>::~OPimAccessTemplate() { 169OPimAccessTemplate<T>::~OPimAccessTemplate() {
214 owarn << "~OPimAccessTemplate<T>" << oendl;
215 delete m_backEnd; 170 delete m_backEnd;
216} 171}
172
173/**
174 * load from the backend
175 */
217template <class T> 176template <class T>
218bool OPimAccessTemplate<T>::load() { 177bool OPimAccessTemplate<T>::load() {
219 invalidateCache(); 178 invalidateCache();
220 return m_backEnd->load(); 179 return m_backEnd->load();
221} 180}
181
182/** Reload database.
183 * You should execute this function if the external database
184 * was changed.
185 * This function will load the external database and afterwards
186 * rejoin the local changes. Therefore the local database will be set consistent.
187 */
222template <class T> 188template <class T>
223bool OPimAccessTemplate<T>::reload() { 189bool OPimAccessTemplate<T>::reload() {
224 invalidateCache(); 190 invalidateCache();
225 return m_backEnd->reload(); 191 return m_backEnd->reload();
226} 192}
193
194/**
195 * Save contacts database.
196 * Save is more a "commit". After calling this function, all changes are public available.
197 * @return true if successful
198 */
227template <class T> 199template <class T>
228bool OPimAccessTemplate<T>::save() { 200bool OPimAccessTemplate<T>::save() {
229 return m_backEnd->save(); 201 return m_backEnd->save();
230} 202}
203
204
205/**
206 * return a List of records
207 * you can iterate over them
208 */
231template <class T> 209template <class T>
232typename OPimAccessTemplate<T>::List OPimAccessTemplate<T>::allRecords()const { 210typename OPimAccessTemplate<T>::List OPimAccessTemplate<T>::allRecords()const {
233 QArray<int> ints = m_backEnd->allRecords(); 211 QArray<int> ints = m_backEnd->allRecords();
234 List lis(ints, this ); 212 List lis(ints, this );
235 return lis; 213 return lis;
236} 214}
215
216/**
217 * return a List of records
218 * that match the regex
219 */
237template <class T> 220template <class T>
238typename OPimAccessTemplate<T>::List OPimAccessTemplate<T>::matchRegexp( const QRegExp &r )const { 221typename OPimAccessTemplate<T>::List OPimAccessTemplate<T>::matchRegexp( const QRegExp &r )const {
239 QArray<int> ints = m_backEnd->matchRegexp( r ); 222 QArray<int> ints = m_backEnd->matchRegexp( r );
240 List lis(ints, this ); 223 List lis(ints, this );
241 return lis; 224 return lis;
242} 225}
226
227/**
228 * find the OPimRecord uid
229 */
243template <class T> 230template <class T>
244QArray<int> OPimAccessTemplate<T>::records()const { 231QArray<int> OPimAccessTemplate<T>::records()const {
245 return m_backEnd->allRecords(); 232 return m_backEnd->allRecords();
246} 233}
234
235
236/**
237 * queryByExample.
238 * @see otodoaccess, ocontactaccess
239 */
247template <class T> 240template <class T>
248typename OPimAccessTemplate<T>::List 241typename OPimAccessTemplate<T>::List
249OPimAccessTemplate<T>::queryByExample( const T& t, int settings, const QDateTime& d ) { 242OPimAccessTemplate<T>::queryByExample( const T& t, int settings, const QDateTime& d ) {
@@ -252,8 +245,9 @@ OPimAccessTemplate<T>::queryByExample( const T& t, int settings, const QDateTime
252 List lis(ints, this ); 245 List lis(ints, this );
253 return lis; 246 return lis;
254} 247}
248
255template <class T> 249template <class T>
256T OPimAccessTemplate<T>::find( int uid ) const{ 250T OPimAccessTemplate<T>::find( UID uid ) const{
257 // First search in cache.. 251 // First search in cache..
258 if ( m_cache.contains( uid ) ) 252 if ( m_cache.contains( uid ) )
259 return m_cache.find( uid ); 253 return m_cache.find( uid );
@@ -265,27 +259,46 @@ T OPimAccessTemplate<T>::find( int uid ) const{
265} 259}
266 260
267template <class T> 261template <class T>
268T OPimAccessTemplate<T>::find( int uid, const QArray<int>& ar, 262T OPimAccessTemplate<T>::cacheFind( int uid ) const
263{
264 return m_cache.find( uid );
265}
266
267/**
268 * read ahead cache find method ;)
269 */
270template <class T>
271T OPimAccessTemplate<T>::find( UID uid, const QArray<int>& ar,
269 uint current, typename OTemplateBase<T>::CacheDirection dir )const { 272 uint current, typename OTemplateBase<T>::CacheDirection dir )const {
270 /* 273 /*
271 * better do T.isEmpty() 274 * better do T.isEmpty()
272 * after a find this way we would 275 * after a find this way we would
273 * avoid two finds in QCache... 276 * avoid two finds in QCache...
274 */ 277 */
275 // owarn << "find it now " << uid << oendl; 278 if (m_cache.contains( uid ) )
276 if ( m_cache.contains( uid ) ) {
277 return m_cache.find( uid ); 279 return m_cache.find( uid );
278 } 280
279 281
280 T t = m_backEnd->find( uid, ar, current, dir ); 282 T t = m_backEnd->find( uid, ar, current, dir );
281 cache( t ); 283 cache( t );
282 return t; 284 return t;
283} 285}
286
287/**
288 * clears the backend and invalidates the backend
289 */
284template <class T> 290template <class T>
285void OPimAccessTemplate<T>::clear() { 291void OPimAccessTemplate<T>::clear() {
286 invalidateCache(); 292 invalidateCache();
287 m_backEnd->clear(); 293 m_backEnd->clear();
288} 294}
295
296
297/**
298 * add T to the backend
299 * @param t The item to add.
300 * @return <i>true</i> if added successfully.
301 */
289template <class T> 302template <class T>
290bool OPimAccessTemplate<T>::add( const T& t ) { 303bool OPimAccessTemplate<T>::add( const T& t ) {
291 cache( t ); 304 cache( t );
@@ -305,6 +318,12 @@ bool OPimAccessTemplate<T>::add( const OPimRecord& rec ) {
305 return false; 318 return false;
306} 319}
307 320
321/**
322 * Add an Opie PimRecord.
323 * Info: Take this if you are working with OPimRecords and you need to add it into any database.
324 * But take care that the accessing database is compatible to the real type of OPimRecord !!
325 * Otherwise this access will be rejected !
326 */
308template <class T> 327template <class T>
309bool OPimAccessTemplate<T>::add( const OPimRecord* rec) { 328bool OPimAccessTemplate<T>::add( const OPimRecord* rec) {
310 /* same type, but pointer */ 329 /* same type, but pointer */
@@ -318,12 +337,23 @@ bool OPimAccessTemplate<T>::add( const OPimRecord* rec) {
318 return false; 337 return false;
319} 338}
320 339
340/**
341 * remove T from the backend
342 * @param t The item to remove
343 * @return <i>true</i> if successful.
344 */
321template <class T> 345template <class T>
322bool OPimAccessTemplate<T>::remove( const T& t ) { 346bool OPimAccessTemplate<T>::remove( const T& t ) {
323 return remove( t.uid() ); 347 return remove( t.uid() );
324} 348}
349
350/**
351 * remove the OPimRecord with uid
352 * @param uid The ID of the item to remove
353 * @return <i>true</i> if successful.
354 */
325template <class T> 355template <class T>
326bool OPimAccessTemplate<T>::remove( int uid ) { 356bool OPimAccessTemplate<T>::remove( UID uid ) {
327 m_cache.remove( uid ); 357 m_cache.remove( uid );
328 return m_backEnd->remove( uid ); 358 return m_backEnd->remove( uid );
329} 359}
@@ -331,11 +361,21 @@ template <class T>
331bool OPimAccessTemplate<T>::remove( const OPimRecord& rec) { 361bool OPimAccessTemplate<T>::remove( const OPimRecord& rec) {
332 return remove( rec.uid() ); 362 return remove( rec.uid() );
333} 363}
364
365/**
366 * replace T from backend
367 * @param t The item to replace
368 * @return <i>true</i> if successful.
369 */
334template <class T> 370template <class T>
335bool OPimAccessTemplate<T>::replace( const T& t ) { 371bool OPimAccessTemplate<T>::replace( const T& t ) {
336 m_cache.replace( t ); 372 m_cache.replace( t );
337 return m_backEnd->replace( t ); 373 return m_backEnd->replace( t );
338} 374}
375
376/**
377 * @internal
378 */
339template <class T> 379template <class T>
340void OPimAccessTemplate<T>::invalidateCache() { 380void OPimAccessTemplate<T>::invalidateCache() {
341 m_cache.invalidate(); 381 m_cache.invalidate();
@@ -344,6 +384,12 @@ template <class T>
344typename OPimAccessTemplate<T>::BackEnd* OPimAccessTemplate<T>::backEnd() { 384typename OPimAccessTemplate<T>::BackEnd* OPimAccessTemplate<T>::backEnd() {
345 return m_backEnd; 385 return m_backEnd;
346} 386}
387
388/**
389 * if the resource was changed externally
390 * You should use the signal handling instead of polling possible changes !
391 * zecke: Do you implement a signal for otodoaccess ?
392 */
347template <class T> 393template <class T>
348bool OPimAccessTemplate<T>::wasChangedExternally()const { 394bool OPimAccessTemplate<T>::wasChangedExternally()const {
349 return false; 395 return false;
@@ -368,6 +414,109 @@ void OPimAccessTemplate<T>::setReadAhead( uint count ) {
368 m_backEnd->setReadAhead( count ); 414 m_backEnd->setReadAhead( count );
369} 415}
370 416
417
418template <class T>
419typename OPimAccessTemplate<T>::List OPimAccessTemplate<T>::sorted( const OPimAccessTemplate::List& lst,
420 bool ascending, int sortOrder,
421 int sortFilter, int cat )const {
422 QArray<int> cats( 1 );
423 cats[0] = cat;
424 UIDArray ints = m_backEnd->sorted( lst.uids(), ascending, sortOrder,
425 sortFilter, cats );
426 return List(ints, this);
427}
428
429template<class T>
430typename OPimAccessTemplate<T>::List OPimAccessTemplate<T>::sorted( const OPimAccessTemplate::List& lst,
431 bool ascending, int sortOrder,
432 int sortFilter, const QArray<UID>& cats )const {
433 UIDArray ints = m_backEnd->sorted( lst.uids(), ascending, sortOrder,
434 sortFilter, cats );
435 return List(ints, this);
436}
437
438template<class T>
439typename OPimAccessTemplate<T>::List OPimAccessTemplate<T>::sorted( bool ascending, int sortOrder,
440 int sortFilter, int cat )const {
441 QArray<int> cats( 1 );
442 cats[0] = cat;
443 UIDArray ints = m_backEnd->sorted( ascending, sortOrder,
444 sortFilter, cats );
445 return List(ints, this);
446}
447
448template<class T>
449typename OPimAccessTemplate<T>::List OPimAccessTemplate<T>::sorted( bool ascending, int sortOrder,
450 int sortFilter, const QArray<UID>& cats )const {
451 UIDArray ints = m_backEnd->sorted( ascending, sortOrder,
452 sortFilter, cats );
453 return List(ints, this);
454}
455
456template <class T>
457OPimOccurrence::List OPimAccessTemplate<T>::occurrences( const QDate& start,
458 const QDate& end ) const {
459 /*
460 * Some magic involved to go from single OPimBackendOccurrence
461 * to multiple OPimOccurrence's
462 */
463 return OPimBase::convertOccurrenceFromBackend( m_backEnd->occurrences( start, end ) );
464}
465
466template<class T>
467OPimOccurrence::List OPimAccessTemplate<T>::occurrences( const QDateTime& dt )const {
468 return OPimBase::convertOccurrenceFromBackend( m_backEnd->occurrences( dt ) );
469}
470
471/*
472 *Implementations!!
473 */
474template <class T>
475UIDArray OPimAccessTemplate<T>::matchRegexpSimple( const QRegExp &r )const {
476 return m_backEnd->matchRegexp( r );
477}
478
479template <class T>
480UIDArray OPimAccessTemplate<T>::queryByExampleSimple( const OPimRecord* rec,
481 int settings,
482 const QDateTime& d )const {
483 return m_backEnd->queryByExample( rec, settings, d );
484}
485
486template <class T>
487UIDArray OPimAccessTemplate<T>::sortedSimple( const UIDArray& lst,
488 bool ascending,
489 int sortOrder, int sortFilter,
490 int cat ) const{
491 QArray<int> cats( 1 );
492 cats[0] = cat;
493 return m_backEnd->sorted( lst, ascending, sortOrder, sortFilter, cats );
494}
495
496template <class T>
497UIDArray OPimAccessTemplate<T>::sortedSimple( const UIDArray& lst,
498 bool ascending,
499 int sortOrder, int sortFilter,
500 const QArray<int>& cats ) const{
501 return m_backEnd->sorted( lst, ascending, sortOrder, sortFilter, cats );
502}
503
504template <class T>
505UIDArray OPimAccessTemplate<T>::sortedSimple( bool ascending,
506 int sortOrder, int sortFilter,
507 int cat ) const{
508 QArray<int> cats( 1 );
509 cats[0] = cat;
510
511 return m_backEnd->sorted( ascending, sortOrder, sortFilter, cats );
512}
513
514template <class T>
515UIDArray OPimAccessTemplate<T>::sortedSimple( bool ascending,
516 int sortOrder, int sortFilter,
517 const QArray<int>& cats ) const{
518 return m_backEnd->sorted( ascending, sortOrder, sortFilter, cats );
519}
371} 520}
372 521
373#endif 522#endif
diff --git a/libopie2/opiepim/core/opimcontact.cpp b/libopie2/opiepim/core/opimcontact.cpp
index 36e9a93..64f195b 100644
--- a/libopie2/opiepim/core/opimcontact.cpp
+++ b/libopie2/opiepim/core/opimcontact.cpp
@@ -81,7 +81,6 @@ OPimContact::OPimContact( const QMap<int, QString> &fromMap ):OPimRecord(), mMap
81 81
82 if ( uidStr.isEmpty() || ( uidStr.toInt() == 0 ) ) 82 if ( uidStr.isEmpty() || ( uidStr.toInt() == 0 ) )
83 { 83 {
84 owarn << "Invalid UID found. Generate new one.." << oendl;
85 setUid( uidGen().generate() ); 84 setUid( uidGen().generate() );
86 } 85 }
87 else 86 else
@@ -1138,7 +1137,6 @@ void OPimContact::setBirthday( const QDate &v )
1138{ 1137{
1139 if ( v.isNull() ) 1138 if ( v.isNull() )
1140 { 1139 {
1141 owarn << "Remove Birthday" << oendl;
1142 replace( Qtopia::Birthday, QString::null ); 1140 replace( Qtopia::Birthday, QString::null );
1143 return ; 1141 return ;
1144 } 1142 }
@@ -1157,7 +1155,6 @@ void OPimContact::setAnniversary( const QDate &v )
1157{ 1155{
1158 if ( v.isNull() ) 1156 if ( v.isNull() )
1159 { 1157 {
1160 owarn << "Remove Anniversary" << oendl;
1161 replace( Qtopia::Anniversary, QString::null ); 1158 replace( Qtopia::Anniversary, QString::null );
1162 return ; 1159 return ;
1163 } 1160 }
@@ -1173,7 +1170,6 @@ void OPimContact::setAnniversary( const QDate &v )
1173QDate OPimContact::birthday() const 1170QDate OPimContact::birthday() const
1174{ 1171{
1175 QString str = find( Qtopia::Birthday ); 1172 QString str = find( Qtopia::Birthday );
1176 // owarn << "Birthday " << str << oendl;
1177 if ( !str.isEmpty() ) 1173 if ( !str.isEmpty() )
1178 return OPimDateConversion::dateFromString ( str ); 1174 return OPimDateConversion::dateFromString ( str );
1179 else 1175 else
@@ -1188,7 +1184,6 @@ QDate OPimContact::anniversary() const
1188{ 1184{
1189 QDate empty; 1185 QDate empty;
1190 QString str = find( Qtopia::Anniversary ); 1186 QString str = find( Qtopia::Anniversary );
1191 // owarn << "Anniversary " << str << oendl;
1192 if ( !str.isEmpty() ) 1187 if ( !str.isEmpty() )
1193 return OPimDateConversion::dateFromString ( str ); 1188 return OPimDateConversion::dateFromString ( str );
1194 else 1189 else
@@ -1282,6 +1277,25 @@ int OPimContact::rtti() const
1282 return OPimResolver::AddressBook; 1277 return OPimResolver::AddressBook;
1283} 1278}
1284 1279
1280/**
1281 * \brief Cast to OPimContact or on failure return 0l
1282 *
1283 * This method tries to cast from a OPimRecord to a
1284 * OPimContact it uses. If the OPimRecord is from type
1285 * OPimContact the case will suceed and a pointer to
1286 * OPimContact is returned otherwise a Null Pointer is returned.
1287 *
1288 *
1289 * @see OPimTodo::safeCast()
1290 * @see OPimEvent::safeCast()
1291 * @return Return a OPimContact or a Null Pointer
1292 */
1293OPimContact* OPimContact::safeCast( const OPimRecord* rec ) {
1294 return( rec && rec->rtti() == OPimResolver::AddressBook ) ?
1295 static_cast<OPimContact*>( const_cast<OPimRecord*>(rec) ) :
1296 0l;
1297}
1298
1285 1299
1286void OPimContact::setUid( int i ) 1300void OPimContact::setUid( int i )
1287{ 1301{
diff --git a/libopie2/opiepim/core/opimcontact.h b/libopie2/opiepim/core/opimcontact.h
index 6891dd6..6fa2c4b 100644
--- a/libopie2/opiepim/core/opimcontact.h
+++ b/libopie2/opiepim/core/opimcontact.h
@@ -228,7 +228,11 @@ class QPC_EXPORT OPimContact : public OPimRecord
228 // the emails should be seperated by a comma 228 // the emails should be seperated by a comma
229 void setEmails( const QString &v ); 229 void setEmails( const QString &v );
230 QString emails() const { return find( Qtopia::Emails ); } 230 QString emails() const { return find( Qtopia::Emails ); }
231
232 //@{
231 int rtti() const; 233 int rtti() const;
234 static OPimContact* safeCast( const OPimRecord* );
235 //@}
232 236
233 private: 237 private:
234 // The XML Backend needs some access to the private functions 238 // The XML Backend needs some access to the private functions
diff --git a/libopie2/opiepim/core/opimevent.cpp b/libopie2/opiepim/core/opimevent.cpp
index 7bc6c32..1b553d8 100644
--- a/libopie2/opiepim/core/opimevent.cpp
+++ b/libopie2/opiepim/core/opimevent.cpp
@@ -489,6 +489,25 @@ int OPimEvent::rtti() const
489 return OPimResolver::DateBook; 489 return OPimResolver::DateBook;
490} 490}
491 491
492/**
493 * \brief Cast safely to OPimEvent from OPimRecord
494 *
495 * Safely cast from OPimRecord to OPimEvent. If the
496 * OPimRecord is not of type OPimEvent Null will be
497 * returned.
498 *
499 * @param rec The OPimRecord to be casted to OPimEvent
500 *
501 * @see OPimTodo::safeCast
502 * @return OPimEvent or Null Pointer
503 */
504OPimEvent* OPimEvent::safeCast( const OPimRecord* rec) {
505 return ( rec && rec->rtti() == OPimResolver::DateBook ) ?
506 static_cast<OPimEvent*>( const_cast<OPimRecord*>(rec) ) :
507 0l;
508}
509
510
492 511
493bool OPimEvent::loadFromStream( QDataStream& ) 512bool OPimEvent::loadFromStream( QDataStream& )
494{ 513{
diff --git a/libopie2/opiepim/core/opimevent.h b/libopie2/opiepim/core/opimevent.h
index 5553cac..32f648f 100644
--- a/libopie2/opiepim/core/opimevent.h
+++ b/libopie2/opiepim/core/opimevent.h
@@ -118,21 +118,29 @@ class OPimEvent : public OPimRecord
118 ~OPimEvent(); 118 ~OPimEvent();
119 OPimEvent &operator=( const OPimEvent& ); 119 OPimEvent &operator=( const OPimEvent& );
120 120
121 //@{
121 QString description() const; 122 QString description() const;
122 void setDescription( const QString& description ); 123 void setDescription( const QString& description );
123 124
124 QString location() const; 125 QString location() const;
125 void setLocation( const QString& loc ); 126 void setLocation( const QString& loc );
127 //@}
126 128
129 //@{
127 bool hasNotifiers() const; 130 bool hasNotifiers() const;
128 OPimNotifyManager &notifiers() const; 131 OPimNotifyManager &notifiers() const;
132 //@}
129 133
134 //@{
130 OPimRecurrence recurrence() const; 135 OPimRecurrence recurrence() const;
131 void setRecurrence( const OPimRecurrence& ); 136 void setRecurrence( const OPimRecurrence& );
132 bool hasRecurrence() const; 137 bool hasRecurrence() const;
138 //@}
133 139
140 //@{
134 QString note() const; 141 QString note() const;
135 void setNote( const QString& note ); 142 void setNote( const QString& note );
143 //@}
136 144
137 145
138 QDateTime createdDateTime() const; 146 QDateTime createdDateTime() const;
@@ -161,13 +169,13 @@ class OPimEvent : public OPimRecord
161 QString timeZone() const; 169 QString timeZone() const;
162 170
163 171
164 virtual bool match( const QRegExp& ) const; 172 //@{
165
166 /** For exception to recurrence here is a list of children... */ 173 /** For exception to recurrence here is a list of children... */
167 QArray<int> children() const; 174 QArray<int> children() const;
168 void setChildren( const QArray<int>& ); 175 void setChildren( const QArray<int>& );
169 void addChild( int uid ); 176 void addChild( int uid );
170 void removeChild( int uid ); 177 void removeChild( int uid );
178 //@}
171 179
172 /** return the parent OPimEvent */ 180 /** return the parent OPimEvent */
173 int parent() const; 181 int parent() const;
@@ -175,6 +183,8 @@ class OPimEvent : public OPimRecord
175 183
176 184
177 /* needed reimp */ 185 /* needed reimp */
186 //@{ Reimplementations
187 virtual bool match( const QRegExp& ) const;
178 QString toRichText() const; 188 QString toRichText() const;
179 QString toShortText() const; 189 QString toShortText() const;
180 QString type() const; 190 QString type() const;
@@ -183,10 +193,14 @@ class OPimEvent : public OPimRecord
183 void fromMap( const QMap<int, QString>& map ); 193 void fromMap( const QMap<int, QString>& map );
184 QString recordField( int ) const; 194 QString recordField( int ) const;
185 195
186 int rtti() const;
187
188 bool loadFromStream( QDataStream& ); 196 bool loadFromStream( QDataStream& );
189 bool saveToStream( QDataStream& ) const; 197 bool saveToStream( QDataStream& ) const;
198 //@}
199
200 //@{
201 int rtti() const;
202 static OPimEvent* safeCast( const OPimRecord* );
203 //@}
190 204
191 /* bool operator==( const OPimEvent& ); 205 /* bool operator==( const OPimEvent& );
192 bool operator!=( const OPimEvent& ); 206 bool operator!=( const OPimEvent& );
diff --git a/libopie2/opiepim/core/opimglobal.h b/libopie2/opiepim/core/opimglobal.h
index 3925c89..9d319a1 100644
--- a/libopie2/opiepim/core/opimglobal.h
+++ b/libopie2/opiepim/core/opimglobal.h
@@ -29,7 +29,19 @@
29#ifndef __OPIMGLOBAL_H_ 29#ifndef __OPIMGLOBAL_H_
30#define __OPIMGLOBAL_H_ 30#define __OPIMGLOBAL_H_
31 31
32#include <qarray.h>
33
32namespace Opie{ 34namespace Opie{
35
36/**
37 * The unique identifier for every
38 * PIM record. For now it is a negative
39 * int but we could change it to long or QUuid
40 * in the future
41 */
42typedef int UID;
43typedef QArray<UID> UIDArray;
44
33namespace Pim{ 45namespace Pim{
34 46
35 47
diff --git a/libopie2/opiepim/core/opimnotifymanager.cpp b/libopie2/opiepim/core/opimnotifymanager.cpp
index 516dc79..77cd922 100644
--- a/libopie2/opiepim/core/opimnotifymanager.cpp
+++ b/libopie2/opiepim/core/opimnotifymanager.cpp
@@ -164,7 +164,6 @@ void OPimNotifyManager::deregister( const OPimNotify& )
164 164
165bool OPimNotifyManager::isEmpty() const 165bool OPimNotifyManager::isEmpty() const
166{ 166{
167 owarn << "is Empty called on OPimNotifyManager " << m_rem.count() << " " << m_al.count() << "" << oendl;
168 if ( m_rem.isEmpty() && m_al.isEmpty() ) return true; 167 if ( m_rem.isEmpty() && m_al.isEmpty() ) return true;
169 else return false; 168 else return false;
170} 169}
@@ -192,7 +191,6 @@ QString OPimNotifyManager::alarmsToString() const
192 } 191 }
193 } 192 }
194 // now write the list 193 // now write the list
195 owarn << "als: " << als.join( "____________" ) << "" << oendl;
196 str = als.join( ";" ); 194 str = als.join( ";" );
197 } 195 }
198 196
@@ -226,9 +224,6 @@ void OPimNotifyManager::alarmsFromString( const QString& str )
226 for ( QStringList::Iterator it = als.begin(); it != als.end(); ++it ) 224 for ( QStringList::Iterator it = als.begin(); it != als.end(); ++it )
227 { 225 {
228 QStringList alarm = QStringList::split( ":", ( *it ), TRUE ); // allow empty 226 QStringList alarm = QStringList::split( ":", ( *it ), TRUE ); // allow empty
229 owarn << "alarm: " << alarm.join( "___" ) << "" << oendl;
230 owarn << "alarm[0]: " << alarm[ 0 ] << " "
231 << OPimDateConversion::dateTimeFromString( alarm[ 0 ] ).toString() << oendl;
232 OPimAlarm al( alarm[ 2 ].toInt(), OPimDateConversion::dateTimeFromString( alarm[ 0 ] ), 227 OPimAlarm al( alarm[ 2 ].toInt(), OPimDateConversion::dateTimeFromString( alarm[ 0 ] ),
233 alarm[ 1 ].toInt() ); 228 alarm[ 1 ].toInt() );
234 add( al ); 229 add( al );
diff --git a/libopie2/opiepim/core/opimoccurrence.cpp b/libopie2/opiepim/core/opimoccurrence.cpp
new file mode 100644
index 0000000..14ab5cf
--- a/dev/null
+++ b/libopie2/opiepim/core/opimoccurrence.cpp
@@ -0,0 +1,319 @@
1/*
2 This file is part of the Opie Project
3 Copyright (C) 2003, 2004 Holger Freyther <zecke@handhelds.org>
4 =. Copyright (C) The Opie Team <opie-devel@handhelds.org>
5 .=l.
6 .>+-=
7 _;:, .> :=|. This program is free software; you can
8.> <`_, > . <= redistribute it and/or modify it under
9:`=1 )Y*s>-.-- : the terms of the GNU Library General Public
10.="- .-=="i, .._ License as published by the Free Software
11 - . .-<_> .<> Foundation; either version 2 of the License,
12 ._= =} : or (at your option) any later version.
13 .%`+i> _;_.
14 .i_,=:_. -<s. This program is distributed in the hope that
15 + . -:. = it will be useful, but WITHOUT ANY WARRANTY;
16 : .. .:, . . . without even the implied warranty of
17 =_ + =;=|` MERCHANTABILITY or FITNESS FOR A
18 _.=:. : :=>`: PARTICULAR PURPOSE. See the GNU
19..}^=.= = ; Library General Public License for more
20++= -. .` .: details.
21 : = ...= . :.=-
22 -. .:....=;==+<; You should have received a copy of the GNU
23 -_. . . )=. = Library General Public License along with
24 -- :-=` this library; see the file COPYING.LIB.
25 If not, write to the Free Software Foundation,
26 Inc., 59 Temple Place - Suite 330,
27 Boston, MA 02111-1307, USA.
28*/
29
30#include "opimoccurrence.h"
31#include <opie2/opimtemplatebase.h>
32#include <opie2/private/opimoccurrence_p.h>
33
34
35/* QT */
36#include <qshared.h>
37
38
39namespace Opie {
40
41OPimOccurrence::OPimOccurrence( OPimOccurrence::Data* _data,
42 enum OPimOccurrence::Position pos )
43 : m_pos( pos ), data( _data )
44{}
45
46/**
47 * \brief Copy constructor
48 */
49OPimOccurrence::OPimOccurrence( const OPimOccurrence& oc )
50 : data( oc.data )
51{
52 /*
53 * Increment the reference count
54 */
55 data->ref();
56
57 /*
58 * copy the other information
59 */
60 m_start = oc.m_start;
61 m_end = oc.m_end;
62 m_occurrence = oc.m_occurrence;
63 m_isAllDay = oc.m_isAllDay;
64 m_pos = oc.m_pos;
65}
66
67OPimOccurrence::OPimOccurrence()
68 : m_isAllDay( false ), m_pos( StartEnd )
69{
70 /* simple convient c'tor */
71 data = new OPimOccurrence::Data();
72}
73
74OPimOccurrence::~OPimOccurrence() {
75 deref();
76}
77
78/**
79 * \brief Copy Operator
80 */
81OPimOccurrence& OPimOccurrence::operator=( const OPimOccurrence& oc ) {
82 /* guard against self assignment */
83 if ( this == &oc ) return *this;
84
85 oc.data->ref();
86 deref();
87 data = oc.data;
88
89
90 /*
91 * copy the other information
92 */
93 m_start = oc.m_start;
94 m_end = oc.m_end;
95 m_occurrence = oc.m_occurrence;
96 m_isAllDay = oc.m_isAllDay;
97 m_pos = oc.m_pos;
98
99 return *this;
100}
101
102
103/**
104 * @internal
105 */
106void OPimOccurrence::deref() {
107 if ( data->deref() ) {
108 delete data;
109 data = 0;
110 }
111}
112
113/**
114 * \brief Set the Occurrence to be All Day on a specified QDate
115 *
116 * If no QTime is associated to a OPimOccurrence use this Method
117 * to set the Period of this Occurrence. When using this Method
118 * later calls to \sa isAllDay() will return true.
119 * The Occurrence will be set to occurr on \par from.
120 *
121 * @param from The Day this OPimOccurrence occurs
122 *
123 */
124void OPimOccurrence::setPeriod( const QDate& from ) {
125 m_occurrence = from;
126 m_start = m_end = QTime(); // assign invalid value just in case
127 m_isAllDay = true;
128}
129
130/**
131 * \brief Set the period of this Occurrence with a QTime associated (overloaded)
132 *
133 * Set the period of time for this Occurrence. Each Ocurrence is limited
134 * to one day. Using this Method will make \sa isAllDay() return false.
135 * If \par from and \par to are on two different days the QDate of the
136 * \par from QDateTime will be used.
137 *
138 * @param from The Start Date Time of the Occurrence
139 * @param to The End Date Time of the Occurrence
140 */
141void OPimOccurrence::setPeriod( const QDateTime& from, const QDateTime& to ) {
142 m_occurrence = from.date();
143 m_start = from.time();
144 m_end = to.time();
145 m_isAllDay = false;
146}
147
148/**
149 * \brief Set the period of this Occurrence with a QTime associated
150 *
151 * @param from The QDate of the Occurrence
152 * @param start The Start QTime of the Occurrence
153 * @param end The End QTime of the Occurrence
154 */
155void OPimOccurrence::setPeriod( const QDate& from, const QTime& start,
156 const QTime& end ) {
157 m_occurrence = from;
158 m_start = start;
159 m_end = end;
160 m_isAllDay = false;
161}
162
163
164/**
165 * \brief Is a QTime associated to the OPimOccurrence
166 *
167 * @return Return true if no QTime is associated
168 */
169bool OPimOccurrence::isAllDay()const {
170 return m_isAllDay;
171}
172
173
174/**
175 * \brief Return the QDate where this OPimOccurrence takes place
176 * @return the QDate where this OPimOccurrence occurrs.
177 */
178QDate OPimOccurrence::date()const {
179 return m_occurrence;
180}
181
182
183/**
184 * \brief Return the start time of the OPimOccurrence
185 *
186 * @return Return the Start Time of the OPimOccurrence. It is
187 * invalid if \sa isAllDay() returns true.
188 */
189QTime OPimOccurrence::startTime()const {
190 return m_start;
191}
192
193QTime OPimOccurrence::endTime()const {
194 return m_end;
195}
196
197QDateTime OPimOccurrence::startDateTime()const {
198 return QDateTime( m_occurrence, m_start );
199}
200
201QDateTime OPimOccurrence::endDateTime()const {
202 return QDateTime( m_occurrence, m_end );
203}
204
205
206QString OPimOccurrence::summary()const {
207 return data->summary;
208}
209
210QString OPimOccurrence::location()const {
211 return data->location;
212}
213
214QString OPimOccurrence::note()const {
215 return data->note;
216}
217
218
219/**
220 * -1 if no time is associated
221 * otherwise the length of the occurrence in hours
222 */
223int OPimOccurrence::length()const {
224 if ( m_isAllDay )
225 return -1;
226 else
227 return ( m_end.hour() * 60 - m_start.hour() * 60 )
228 + QABS( m_start.minute() - m_end.minute() );
229}
230
231enum OPimOccurrence::Position OPimOccurrence::position()const {
232 return m_pos;
233}
234
235void OPimOccurrence::setPosition( enum OPimOccurrence::Position& pos ) {
236 m_pos = pos;
237}
238
239
240Opie::Core::OSharedPointer<OPimRecord> OPimOccurrence::record()const {
241 if ( !data->record && data->backend )
242 data->record = data->backend->record( data->uid );
243 return data->record;
244}
245
246template<class Record> Record OPimOccurrence::internalToRecord()const {
247 Record target;
248
249 /* If it is not loaded, try to load it using OPimBase */
250 if ( !data->record && data->backend )
251 data->record = data->backend->record( data->uid );
252
253 Record *ta = Record::safeCast( data->record );
254 if ( ta )
255 target = *ta;
256
257
258 return target;
259}
260
261OPimEvent OPimOccurrence::toEvent()const {
262 return internalToRecord<OPimEvent>();
263}
264
265OPimTodo OPimOccurrence::toTodo()const {
266 return internalToRecord<OPimTodo>();
267}
268
269OPimContact OPimOccurrence::toContact()const {
270 return internalToRecord<OPimContact>();
271}
272
273bool OPimOccurrence::operator<( const OPimOccurrence& oc )const {
274 if ( m_occurrence < oc.m_occurrence )
275 return true;
276 if ( m_occurrence == oc.m_occurrence )
277 return m_start < oc.m_start;
278 else
279 return false;
280}
281
282bool OPimOccurrence::operator<=( const OPimOccurrence& oc )const {
283 return ( m_occurrence <= oc.m_occurrence );
284}
285
286bool OPimOccurrence::operator==( const OPimOccurrence& oc )const {
287 if ( data->uid != oc.data->uid )
288 return false;
289 if ( m_occurrence != oc.m_occurrence )
290 return false;
291 if ( m_isAllDay != oc.m_isAllDay )
292 return false;
293 if ( m_isAllDay && oc.m_isAllDay )
294 if ( m_start != oc.m_start ||
295 m_end != oc.m_end )
296 return false;
297 if ( data->summary != oc.data->summary )
298 return false;
299 if ( data->note != oc.data->note )
300 return false;
301 if ( data->location != oc.data->location )
302 return false;
303
304 return true;
305}
306
307bool OPimOccurrence::operator!=( const OPimOccurrence& oc )const {
308 return !( *this == oc );
309}
310
311bool OPimOccurrence::operator>( const OPimOccurrence& oc )const {
312 return !( *this <= oc );
313}
314
315bool OPimOccurrence::operator>=( const OPimOccurrence& oc )const {
316 return !( *this < oc );
317}
318
319}
diff --git a/libopie2/opiepim/core/opimoccurrence.h b/libopie2/opiepim/core/opimoccurrence.h
new file mode 100644
index 0000000..902638b
--- a/dev/null
+++ b/libopie2/opiepim/core/opimoccurrence.h
@@ -0,0 +1,142 @@
1/*
2 This file is part of the Opie Project
3 Copyright (C) 2003, 2004 Holger Freyther <zecke@handhelds.org>
4 =. Copyright (C) The Opie Team <opie-devel@handhelds.org>
5 .=l.
6 .>+-=
7 _;:, .> :=|. This program is free software; you can
8.> <`_, > . <= redistribute it and/or modify it under
9:`=1 )Y*s>-.-- : the terms of the GNU Library General Public
10.="- .-=="i, .._ License as published by the Free Software
11 - . .-<_> .<> Foundation; either version 2 of the License,
12 ._= =} : or (at your option) any later version.
13 .%`+i> _;_.
14 .i_,=:_. -<s. This program is distributed in the hope that
15 + . -:. = it will be useful, but WITHOUT ANY WARRANTY;
16 : .. .:, . . . without even the implied warranty of
17 =_ + =;=|` MERCHANTABILITY or FITNESS FOR A
18 _.=:. : :=>`: PARTICULAR PURPOSE. See the GNU
19..}^=.= = ; Library General Public License for more
20++= -. .` .: details.
21 : = ...= . :.=-
22 -. .:....=;==+<; You should have received a copy of the GNU
23 -_. . . )=. = Library General Public License along with
24 -- :-=` this library; see the file COPYING.LIB.
25 If not, write to the Free Software Foundation,
26 Inc., 59 Temple Place - Suite 330,
27 Boston, MA 02111-1307, USA.
28*/
29
30#ifndef OPIE_PIM_OCCURRENCE_H
31#define OPIE_PIM_OCCURRENCE_H
32
33#include <opie2/osharedpointer.h>
34#include <opie2/opimrecord.h>
35#include <opie2/opimevent.h>
36#include <opie2/opimtodo.h>
37#include <opie2/opimcontact.h>
38
39#include <qdatetime.h>
40#include <qstringlist.h>
41
42namespace Opie {
43
44template<class T> class OPimAccessTemplate;
45/**
46 * \brief An OPimOccurrence represents a occurence for one day of a OPimRecord
47 *
48 * An OPimOccurrence represents the occurrence of one OPimRecord
49 * for a period of Time for one day. An occurrence can spawn
50 * more then one day and then is splitted into multiple OPimOccurrence.
51 * By attributes you can find if a OPimOccurrence is the beginning and
52 * end, begin, end or is midway of a multiday occurrence.
53 *
54 */
55class OPimOccurrence {
56 friend class OPimBase;
57public:
58 typedef QValueList<OPimOccurrence> List;
59 /**
60 * The position of the OPimOccurrence in a possible
61 * MultiDay Occurrence.
62 */
63 enum Position {
64 MidWay, /* This OPimOccurrence is somewhere in between Start and End */
65 Start, /* This OPimOccurrence is the Start of a multi day Occurrence */
66 End, /* This OPimOccurrence is the End of a multi day Occurrence */
67 StartEnd /* This OPimOccurrence only spans one day */
68 };
69
70 //@{
71 OPimOccurrence();
72 OPimOccurrence( const OPimOccurrence& );
73 ~OPimOccurrence();
74 //@}
75
76 //@{
77 void setPeriod( const QDate& from );
78 void setPeriod( const QDateTime& from, const QDateTime& to );
79 void setPeriod( const QDate& from, const QTime& start, const QTime& end );
80 //@}
81
82 //@{
83 bool isAllDay()const;
84 QDate date()const;
85 QTime startTime()const;
86 QTime endTime()const;
87 QDateTime startDateTime()const;
88 QDateTime endDateTime()const;
89 //@}
90
91 //@{
92 QString summary()const;
93 QString location()const;
94 QString note()const;
95 //@}
96
97 //@{
98 int length()const;
99 Position position()const;
100 void setPosition( enum Position& );
101 //@}
102
103 //@{
104 Opie::Core::OSharedPointer<OPimRecord> record()const;
105 OPimEvent toEvent()const;
106 OPimTodo toTodo()const;
107 OPimContact toContact()const;
108 //@}
109
110
111 //@{
112 bool operator< ( const OPimOccurrence& )const;
113 bool operator<=( const OPimOccurrence& )const;
114 bool operator==( const OPimOccurrence& )const;
115 bool operator!=( const OPimOccurrence& )const;
116 bool operator> ( const OPimOccurrence& )const;
117 bool operator>=( const OPimOccurrence& )const;
118 OPimOccurrence &operator=( const OPimOccurrence& );
119 //@}
120
121private:
122 QDate m_occurrence;
123 QTime m_start, m_end;
124 bool m_isAllDay : 1;
125 enum Position m_pos;
126
127 void deref();
128 inline void changeOrModify();
129
130 struct Private;
131 struct Data;
132
133 Data *data;
134 Private *d;
135
136private: // ctor
137 OPimOccurrence( OPimOccurrence::Data *, enum Position );
138 template<class T> T internalToRecord()const;
139};
140}
141
142#endif
diff --git a/libopie2/opiepim/core/opimrecord.cpp b/libopie2/opiepim/core/opimrecord.cpp
index 6546d99..60946e0 100644
--- a/libopie2/opiepim/core/opimrecord.cpp
+++ b/libopie2/opiepim/core/opimrecord.cpp
@@ -100,8 +100,6 @@ void OPimRecord::addCategoryName( const QString& )
100{ 100{
101 Categories catDB; 101 Categories catDB;
102 catDB.load( categoryFileName() ); 102 catDB.load( categoryFileName() );
103
104
105} 103}
106 104
107 105
@@ -111,20 +109,6 @@ bool OPimRecord::isEmpty() const
111} 109}
112 110
113 111
114/*QString OPimRecord::crossToString()const {
115 QString str;
116 QMap<QString, QArray<int> >::ConstIterator it;
117 for (it = m_relations.begin(); it != m_relations.end(); ++it ) {
118 QArray<int> id = it.data();
119 for ( uint i = 0; i < id.size(); ++i ) {
120 str += it.key() + "," + QString::number( i ) + ";";
121 }
122 }
123 str = str.remove( str.length()-1, 1); // strip the ;
124 //owarn << "IDS " + str << oendl;
125
126 return str;
127 }*/
128/* if uid = 1 assign a new one */ 112/* if uid = 1 assign a new one */
129void OPimRecord::setUid( int uid ) 113void OPimRecord::setUid( int uid )
130{ 114{
@@ -270,4 +254,11 @@ void OPimRecord::setExtraMap( const QMap<QString, QString>& map )
270 customMap = map; 254 customMap = map;
271} 255}
272 256
257#if 0
258QString OPimRecord::recordAttributeTranslated( int field )const
259{
260 return recordAttributeTranslated()[field];
261}
262#endif
263
273} 264}
diff --git a/libopie2/opiepim/core/opimrecord.h b/libopie2/opiepim/core/opimrecord.h
index 127439a..363cc78 100644
--- a/libopie2/opiepim/core/opimrecord.h
+++ b/libopie2/opiepim/core/opimrecord.h
@@ -32,6 +32,8 @@
32 32
33/* OPIE */ 33/* OPIE */
34#include <opie2/opimxrefmanager.h> 34#include <opie2/opimxrefmanager.h>
35#include <opie2/opimglobal.h>
36
35/* 37/*
36 * we need to get customMap which is private... 38 * we need to get customMap which is private...
37 */ 39 */
@@ -60,7 +62,7 @@ class OPimRecord : public Qtopia::Record
60 * uid of 0 isEmpty 62 * uid of 0 isEmpty
61 * uid of 1 will be assigned a new one 63 * uid of 1 will be assigned a new one
62 */ 64 */
63 OPimRecord( int uid = 0 ); 65 OPimRecord( UID uid = 0 );
64 ~OPimRecord(); 66 ~OPimRecord();
65 67
66 /** 68 /**
@@ -138,10 +140,15 @@ class OPimRecord : public Qtopia::Record
138 QMap<QString, QString> toExtraMap() const; 140 QMap<QString, QString> toExtraMap() const;
139 void setExtraMap( const QMap<QString, QString>& ); 141 void setExtraMap( const QMap<QString, QString>& );
140 142
143//@{
141 /** 144 /**
142 * the name for a recordField 145 * the name for a recordField
143 */ 146 */
144 virtual QString recordField( int ) const = 0; 147 virtual QString recordField( int ) const = 0;
148// virtual QArray<int> recordAttributes()const = 0;
149// virtual QMap<int,QString> recordAttributesTranslated() const = 0;
150// QString recordAttributeTranslated(int field)const;
151//@}
145 152
146 /** 153 /**
147 * returns a reference of the 154 * returns a reference of the
diff --git a/libopie2/opiepim/core/opimrecordlist.h b/libopie2/opiepim/core/opimrecordlist.h
index 1d5027f..0459f41 100644
--- a/libopie2/opiepim/core/opimrecordlist.h
+++ b/libopie2/opiepim/core/opimrecordlist.h
@@ -41,6 +41,7 @@
41namespace Opie 41namespace Opie
42{ 42{
43 43
44template<class T> class OPimAccessTemplate;
44class OPimRecordListIteratorPrivate; 45class OPimRecordListIteratorPrivate;
45/** 46/**
46 * Our List Iterator 47 * Our List Iterator
@@ -120,6 +121,7 @@ class OPimRecordListPrivate;
120template <class T = OPimRecord > 121template <class T = OPimRecord >
121class OPimRecordList 122class OPimRecordList
122{ 123{
124 template<class> friend class OPimAccessTemplate;
123 public: 125 public:
124 typedef OTemplateBase<T> Base; 126 typedef OTemplateBase<T> Base;
125 typedef OPimRecordListIterator<T> Iterator; 127 typedef OPimRecordListIterator<T> Iterator;
@@ -127,8 +129,7 @@ class OPimRecordList
127 /** 129 /**
128 * c'tor 130 * c'tor
129 */ 131 */
130 OPimRecordList () 132 OPimRecordList (){}
131 {}
132 OPimRecordList( const QArray<int>& ids, 133 OPimRecordList( const QArray<int>& ids,
133 const Base* ); 134 const Base* );
134 ~OPimRecordList(); 135 ~OPimRecordList();
@@ -160,6 +161,9 @@ class OPimRecordList
160 ConstIterator begin()const; 161 ConstIterator begin()const;
161 ConstIterator end()const; 162 ConstIterator end()const;
162 */ 163 */
164 protected:
165 UIDArray uids()const;
166
163 private: 167 private:
164 QArray<int> m_ids; 168 QArray<int> m_ids;
165 const Base* m_acc; 169 const Base* m_acc;
@@ -190,7 +194,6 @@ OPimRecordListIterator<T>::~OPimRecordListIterator()
190template <class T> 194template <class T>
191OPimRecordListIterator<T>::OPimRecordListIterator( const OPimRecordListIterator<T>& it ) 195OPimRecordListIterator<T>::OPimRecordListIterator( const OPimRecordListIterator<T>& it )
192{ 196{
193 //owarn << "OPimRecordListIterator copy c'tor" << oendl;
194 m_uids = it.m_uids; 197 m_uids = it.m_uids;
195 m_current = it.m_current; 198 m_current = it.m_current;
196 m_temp = it.m_temp; 199 m_temp = it.m_temp;
@@ -216,7 +219,6 @@ OPimRecordListIterator<T> &OPimRecordListIterator<T>::operator=( const OPimRecor
216template <class T> 219template <class T>
217T OPimRecordListIterator<T>::operator*() 220T OPimRecordListIterator<T>::operator*()
218{ 221{
219 //owarn << "operator* " << m_current << " " << m_uids[m_current] << oendl;
220 if ( !m_end ) 222 if ( !m_end )
221 m_record = m_temp->find( m_uids[ m_current ], m_uids, m_current, 223 m_record = m_temp->find( m_uids[ m_current ], m_uids, m_current,
222 m_direction ? Base::Forward : 224 m_direction ? Base::Forward :
@@ -399,5 +401,10 @@ bool OPimRecordList<T>::remove( int uid )
399 return ret_val; 401 return ret_val;
400} 402}
401 403
404template<class T>
405UIDArray OPimRecordList<T>::uids()const {
406 return m_ids;
407}
408
402} 409}
403#endif 410#endif
diff --git a/libopie2/opiepim/core/opimresolver.h b/libopie2/opiepim/core/opimresolver.h
index 0a6dddf..088474b 100644
--- a/libopie2/opiepim/core/opimresolver.h
+++ b/libopie2/opiepim/core/opimresolver.h
@@ -45,8 +45,6 @@ namespace Opie {
45 * to traverse through a list of alarms, reminders 45 * to traverse through a list of alarms, reminders
46 * to get access to built in PIM functionality 46 * to get access to built in PIM functionality
47 * and to more stuff 47 * and to more stuff
48 * THE PERFORMANCE will depend on THE BACKEND
49 * USING XML is a waste of memory!!!!!
50 */ 48 */
51class OPimResolver { 49class OPimResolver {
52 50
diff --git a/libopie2/opiepim/core/opimstate.h b/libopie2/opiepim/core/opimstate.h
index 8336b3e..ae1e0d2 100644
--- a/libopie2/opiepim/core/opimstate.h
+++ b/libopie2/opiepim/core/opimstate.h
@@ -38,12 +38,6 @@ namespace Opie {
38 * This class encapsules the state of a todo 38 * This class encapsules the state of a todo
39 * and it's shared too 39 * and it's shared too
40 */ 40 */
41/*
42 * in c a simple struct would be enough ;)
43 * g_new_state();
44 * g_do_some_thing( state_t* );
45 * ;)
46 */
47class OPimState { 41class OPimState {
48 42
49 public: 43 public:
diff --git a/libopie2/opiepim/core/opimtemplatebase.cpp b/libopie2/opiepim/core/opimtemplatebase.cpp
new file mode 100644
index 0000000..0a07320
--- a/dev/null
+++ b/libopie2/opiepim/core/opimtemplatebase.cpp
@@ -0,0 +1,112 @@
1/*
2 This file is part of the Opie Project
3 Copyright (C) 2004 Holger Freyther <zecke@handhelds.org>
4 =. Copyright (C) The Opie Team <opie-devel@handhelds.org>
5 .=l.
6 .>+-=
7 _;:, .> :=|. This program is free software; you can
8.> <`_, > . <= redistribute it and/or modify it under
9:`=1 )Y*s>-.-- : the terms of the GNU Library General Public
10.="- .-=="i, .._ License as published by the Free Software
11 - . .-<_> .<> Foundation; either version 2 of the License,
12 ._= =} : or (at your option) any later version.
13 .%`+i> _;_.
14 .i_,=:_. -<s. This program is distributed in the hope that
15 + . -:. = it will be useful, but WITHOUT ANY WARRANTY;
16 : .. .:, . . . without even the implied warranty of
17 =_ + =;=|` MERCHANTABILITY or FITNESS FOR A
18 _.=:. : :=>`: PARTICULAR PURPOSE. See the GNU
19..}^=.= = ; Library General Public License for more
20++= -. .` .: details.
21 : = ...= . :.=-
22 -. .:....=;==+<; You should have received a copy of the GNU
23 -_. . . )=. = Library General Public License along with
24 -- :-=` this library; see the file COPYING.LIB.
25 If not, write to the Free Software Foundation,
26 Inc., 59 Temple Place - Suite 330,
27 Boston, MA 02111-1307, USA.
28*/
29
30#include "opimtemplatebase.h"
31
32#include <opie2/opimoccurrence.h>
33#include <opie2/private/opimoccurrence_p.h>
34
35namespace Opie {
36
37static void setPeriod( OPimOccurrence& oc, bool period, const QDate& d,
38 const QTime& s, const QTime& t ) {
39 if ( period )
40 oc.setPeriod( d );
41 else
42 oc.setPeriod( d, s, t );
43}
44
45// namespace Opie {
46OPimBase::OPimBase() {}
47OPimBase::~OPimBase() {}
48
49/**
50 * @internal Convert internal Occurrence representation
51 * to the external
52 */
53OPimOccurrence::List OPimBase::convertOccurrenceFromBackend( const OPimBackendOccurrence::List& lst )const {
54 OPimOccurrence::List oc_lst;
55
56 /*
57 * Split multiday events up. Create the internal data structure
58 * and then iterate over the days and create the OPimOccurrecne.
59 */
60 for ( OPimBackendOccurrence::List::ConstIterator it = lst.begin(); it != lst.end(); ++it ) {
61 OPimBackendOccurrence boc = *it;
62
63 /*
64 * Create the Shared Data Structure
65 */
66 OPimOccurrence::Data *data = new OPimOccurrence::Data();
67 data->summary = boc.summary();
68 data->location = boc.location();
69 data->note = boc.note();
70 data->uid = boc.uid();
71 data->backend = const_cast<OPimBase*>(this);
72
73 QDateTime start = boc.startDateTime();
74 QDateTime end = boc.endDateTime();
75
76 /*
77 * Start and End are on the same day
78 * Start and End are on two different ways.
79 * - Add Start and End and the days inbetween
80 */
81 int dto = start.daysTo( end );
82 bool allDay = boc.isAllDay();
83
84 if ( dto == 0 ) {
85 OPimOccurrence oc = OPimOccurrence( data, OPimOccurrence::StartEnd );
86 setPeriod( oc, allDay, start.date(), start.time(), end.time() );
87 oc_lst.append( oc );
88 }else {
89
90 OPimOccurrence oc = OPimOccurrence( data, OPimOccurrence::Start );
91 setPeriod( oc, allDay, start.date(), start.time(), QTime(23,59,59));
92 oc_lst.append( oc );
93
94 QDate next = start.addDays( 1 ).date();
95 while ( next != end.date() ) {
96 oc = OPimOccurrence( data, OPimOccurrence::MidWay );
97 setPeriod( oc, allDay, next, QTime(0, 0, 0), QTime(23, 59, 59));
98 oc_lst.append( oc );
99 next = next.addDays( 1 );
100 }
101
102 oc = OPimOccurrence( data, OPimOccurrence::End );
103 setPeriod( oc, allDay, end.date(), QTime(0, 0, 0 ), end.time() );
104 oc_lst.append( oc );
105 }
106 }
107
108 return oc_lst;
109}
110// }
111
112}
diff --git a/libopie2/opiepim/core/opimtemplatebase.h b/libopie2/opiepim/core/opimtemplatebase.h
index 787486c..b238a68 100644
--- a/libopie2/opiepim/core/opimtemplatebase.h
+++ b/libopie2/opiepim/core/opimtemplatebase.h
@@ -32,43 +32,120 @@
32/* OPIE */ 32/* OPIE */
33#include <opie2/opimrecord.h> 33#include <opie2/opimrecord.h>
34#include <opie2/opimcache.h> 34#include <opie2/opimcache.h>
35#include <opie2/opimoccurrence.h>
36#include <opie2/opimbackendoccurrence.h>
35 37
36/* QT */ 38/* QT */
37#include <qarray.h> 39#include <qarray.h>
40#include <qdatetime.h>
38 41
39namespace Opie { 42namespace Opie {
43
44class OPimBasePrivate;
45
40/** 46/**
41 * Templates do not have a base class, This is why 47 * This is the base class for all our Interfaces to the
42 * we've this class 48 * PIM Records. It is pointer based and can be used
43 * this is here to give us the possibility 49 * generically for all types of Records.
44 * to have a common base class 50 *
45 * You may not want to use that interface internaly
46 * POOR mans interface
47 */ 51 */
48class OPimBasePrivate;
49struct OPimBase { 52struct OPimBase {
53 //@{
54 OPimBase();
55 virtual ~OPimBase();
56 //@}
57
58 //@{
50 /** 59 /**
51 * return the rtti 60 * return the rtti
52 */ 61 */
53 virtual int rtti() const = 0; 62 virtual int rtti() const = 0;
54 virtual OPimRecord* record()const = 0; 63 virtual OPimRecord* record()const = 0;
55 virtual OPimRecord* record(int uid)const = 0; 64 virtual OPimRecord* record(int uid)const = 0;
65 //@}
66
67 //@{
56 virtual bool add( const OPimRecord& ) = 0; 68 virtual bool add( const OPimRecord& ) = 0;
57 virtual bool add( const OPimRecord* ) = 0; 69 virtual bool add( const OPimRecord* ) = 0;
70
58 virtual bool remove( int uid ) = 0; 71 virtual bool remove( int uid ) = 0;
59 virtual bool remove( const OPimRecord& ) = 0; 72 virtual bool remove( const OPimRecord& ) = 0;
73 //@}
74
75 //@{
60 virtual void clear() = 0; 76 virtual void clear() = 0;
61 virtual bool load() = 0; 77 virtual bool load() = 0;
62 virtual bool save() = 0; 78 virtual bool save() = 0;
63 virtual QArray<int> records()const = 0; 79 //@}
64 /* 80
65 * ADD editing here? 81 //@{
66 * -zecke 82 virtual QArray<UID> records()const = 0;
83
84 /** Constants for query.
85 * Use this constants to set the query parameters.
86 * Note: <i>query_IgnoreCase</i> just make sense with one of the other attributes !
87 * @see queryByExample()
88 */
89 enum QuerySettings {
90 WildCards = 0x0001, /** Use Wildcards */
91 IgnoreCase = 0x0002, /** Ignore the Case */
92 RegExp = 0x0004, /** Do a Regular Expression match */
93 ExactMatch = 0x0008, /** It needs to exactly match */
94 MatchOne = 0x0010, /** Only one Entry must match */
95 DateDiff = 0x0020, /** Find all entries from today until given date */
96 DateYear = 0x0040, /** The year matches */
97 DateMonth = 0x0080, /** The month matches */
98 DateDay = 0x0100, /** The day matches */
99 LastItem = 0xffff /** the last possible name */
100 };
101
102 /**
103 * Common Attributes for the Sort Order
67 */ 104 */
105 enum SortOrderBase {
106 SortSummary = 0, /** Sort by a Summary of the records */
107 SortByCategory = 1, /** Sort by Category */
108 SortByDate = 2, /** Sort by Date */
109 SortCustom = 10, /** The First available sort number for the OPimAccessTemplates */
110 LastSortOrderBase = 0xffff /** make this enum 16bit large */
111 };
112
113 /**
114 * Sort with the help of the \sa sorted function
115 * a list of Items.
116 * The Item you provide in SortOrder will be used
117 * for sorting.
118 *
119 * @see sorted
120 */
121 enum SortFilterBase {
122 FilterCategory = 1,
123 FilterCustom = 1024,
124 LastSortFilterBase = 0xffffffff
125 };
126
127 virtual UIDArray matchRegexpSimple( const QRegExp& r )const = 0;
128 virtual UIDArray queryByExampleSimple( const OPimRecord*, int settings,
129 const QDateTime& d = QDateTime() )const = 0;
130 virtual UIDArray sortedSimple( const UIDArray& uid, bool ascending,
131 int sortOrder, int sortFilter, int cat)const = 0;
132 virtual UIDArray sortedSimple( const UIDArray& uid, bool ascending,
133 int sortOrder, int sortFilter, const QArray<UID>& cats )const = 0;
134 virtual UIDArray sortedSimple( bool ascending, int sortOrder, int sortFilter, int cat)const = 0;
135 virtual UIDArray sortedSimple( bool ascending, int sortOrder, int sortFilter, const QArray<UID>& cats )const = 0;
136 virtual OPimOccurrence::List occurrences( const QDate& start, const QDate& end )const = 0;
137 virtual OPimOccurrence::List occurrences( const QDateTime& dt )const = 0;
138 //@}
139
140
141protected:
142 OPimOccurrence::List convertOccurrenceFromBackend( const OPimBackendOccurrence::List& )const;
143
68private: 144private:
69 OPimBasePrivate* d; 145 OPimBasePrivate* d;
70
71}; 146};
147
148
72/** 149/**
73 * internal template base 150 * internal template base
74 * Attention: T needs to implement the copy c'tor!!! 151 * Attention: T needs to implement the copy c'tor!!!
@@ -77,13 +154,27 @@ class OTemplateBasePrivate;
77template <class T = OPimRecord> 154template <class T = OPimRecord>
78class OTemplateBase : public OPimBase { 155class OTemplateBase : public OPimBase {
79public: 156public:
80 /** Look ahead direction of cache */ 157 /**
81 enum CacheDirection { Forward=0, Reverse }; 158 * The Direction for ReadAhead/ReadBehind which will
82 159 * be used by the backends to Cache Items in
83 OTemplateBase() { 160 * advance.
161 * For example if you know that you will access the
162 * next ten items you can give the backend a hint
163 * to read ahead or read before.
164 */
165 enum CacheDirection {
166 Forward=0, /** Go forward when caching (++ to the index) */
167 Reverse /** Go backward when caching (-- to the index) */
84 }; 168 };
85 virtual ~OTemplateBase() { 169
86 } 170
171 //@{
172 OTemplateBase() {};
173 virtual ~OTemplateBase() {}
174 //@}
175
176
177 //@{
87 virtual T find( int uid )const = 0; 178 virtual T find( int uid )const = 0;
88 179
89 /** 180 /**
@@ -91,7 +182,9 @@ public:
91 */ 182 */
92 virtual T find( int uid, const QArray<int>& items, 183 virtual T find( int uid, const QArray<int>& items,
93 uint current, CacheDirection dir = Forward )const = 0; 184 uint current, CacheDirection dir = Forward )const = 0;
185 //@}
94 186
187 //@{
95 /** 188 /**
96 * Put element into Cache 189 * Put element into Cache
97 */ 190 */
@@ -101,7 +194,7 @@ public:
101 OPimRecord* record()const; 194 OPimRecord* record()const;
102 OPimRecord* record(int uid )const; 195 OPimRecord* record(int uid )const;
103 static T* rec(); 196 static T* rec();
104 197 //@}
105 198
106private: 199private:
107 OTemplateBasePrivate *d; 200 OTemplateBasePrivate *d;
@@ -119,12 +212,12 @@ OPimRecord* OTemplateBase<T>::record(int uid )const {
119 T* t1 = new T(t2); 212 T* t1 = new T(t2);
120 213
121 return t1; 214 return t1;
122}; 215}
216
123template <class T> 217template <class T>
124T* OTemplateBase<T>::rec() { 218T* OTemplateBase<T>::rec() {
125 return new T; 219 return new T;
126} 220}
127
128} 221}
129 222
130#endif 223#endif
diff --git a/libopie2/opiepim/core/opimtimezone.cpp b/libopie2/opiepim/core/opimtimezone.cpp
index 5b32b1f..1dc36b4 100644
--- a/libopie2/opiepim/core/opimtimezone.cpp
+++ b/libopie2/opiepim/core/opimtimezone.cpp
@@ -40,7 +40,28 @@
40namespace Opie 40namespace Opie
41{ 41{
42 42
43QDateTime utcTime( time_t t ) 43/*
44 * Save the old timeZone in a secure way (NULL Pointer check),
45 * set the new timeZone from the parameter, call tzset
46 * and then return the old timezone
47 */
48static QString setTimeZone( const QString& zone) {
49 QString old;
50 char *org = ::getenv( "TZ" );
51 if( org )
52 old = QString::fromLocal8Bit( org );
53
54 ::setenv( "TZ", zone.local8Bit(), true );
55 ::tzset();
56
57 return old;
58}
59
60static void resetTimeZone( const QString& zone ) {
61 ::setenv( "TZ", zone.local8Bit(), true );
62}
63
64static QDateTime utcTime( time_t t )
44{ 65{
45 tm * broken = ::gmtime( &t ); 66 tm * broken = ::gmtime( &t );
46 QDateTime ret; 67 QDateTime ret;
@@ -49,16 +70,13 @@ QDateTime utcTime( time_t t )
49 return ret; 70 return ret;
50} 71}
51 72
52QDateTime utcTime( time_t t, const QString& zone ) 73static QDateTime utcTime( time_t t, const QString& zone )
53{ 74{
54 QCString org = ::getenv( "TZ" );
55#ifndef Q_OS_MACX // Following line causes bus errors on Mac
56
57 ::setenv( "TZ", zone.latin1(), true );
58 ::tzset();
59 75
76#ifndef Q_OS_MACX // Following line causes bus errors on Mac
77 QString old = setTimeZone( zone );
60 tm* broken = ::localtime( &t ); 78 tm* broken = ::localtime( &t );
61 ::setenv( "TZ", org, true ); 79 resetTimeZone( old );
62#else 80#else
63#warning "Need a replacement for MacOSX!!" 81#warning "Need a replacement for MacOSX!!"
64 82
@@ -73,7 +91,7 @@ QDateTime utcTime( time_t t, const QString& zone )
73} 91}
74 92
75 93
76time_t to_Time_t( const QDateTime& utc, const QString& str ) 94static time_t to_Time_t( const QDateTime& utc, const QString& str )
77{ 95{
78 QDate d = utc.date(); 96 QDate d = utc.date();
79 QTime t = utc.time(); 97 QTime t = utc.time();
@@ -86,14 +104,10 @@ time_t to_Time_t( const QDateTime& utc, const QString& str )
86 broken.tm_min = t.minute(); 104 broken.tm_min = t.minute();
87 broken.tm_sec = t.second(); 105 broken.tm_sec = t.second();
88 106
89 QCString org = ::getenv( "TZ" );
90#ifndef Q_OS_MACX // Following line causes bus errors on Mac 107#ifndef Q_OS_MACX // Following line causes bus errors on Mac
91 108 QString old = setTimeZone( str );
92 ::setenv( "TZ", str.latin1(), true );
93 ::tzset();
94
95 time_t ti = ::mktime( &broken ); 109 time_t ti = ::mktime( &broken );
96 ::setenv( "TZ", org, true ); 110 resetTimeZone( old );
97#else 111#else
98#warning "Need a replacement for MacOSX!!" 112#warning "Need a replacement for MacOSX!!"
99 113
diff --git a/libopie2/opiepim/core/opimtodo.cpp b/libopie2/opiepim/core/opimtodo.cpp
index 27b36a6..16ca987 100644
--- a/libopie2/opiepim/core/opimtodo.cpp
+++ b/libopie2/opiepim/core/opimtodo.cpp
@@ -64,6 +64,7 @@ struct OPimTodo::OPimTodoData : public QShared
64 delete recur; 64 delete recur;
65 delete maintainer; 65 delete maintainer;
66 delete notifiers; 66 delete notifiers;
67 delete state;
67 } 68 }
68 69
69 QDate date; 70 QDate date;
@@ -87,17 +88,14 @@ OPimTodo::OPimTodo( const OPimTodo &event )
87 : OPimRecord( event ), data( event.data ) 88 : OPimRecord( event ), data( event.data )
88{ 89{
89 data->ref(); 90 data->ref();
90 // owarn << "ref up" << oendl;
91} 91}
92 92
93 93
94OPimTodo::~OPimTodo() 94OPimTodo::~OPimTodo()
95{ 95{
96 96
97 // owarn << "~OPimTodo " << oendl;
98 if ( data->deref() ) 97 if ( data->deref() )
99 { 98 {
100 // owarn << "OPimTodo::dereffing" << oendl;
101 delete data; 99 delete data;
102 data = 0l; 100 data = 0l;
103 } 101 }
@@ -112,7 +110,6 @@ OPimTodo::OPimTodo( bool completed, int priority,
112 bool hasDate, QDate date, int uid ) 110 bool hasDate, QDate date, int uid )
113 : OPimRecord( uid ) 111 : OPimRecord( uid )
114{ 112{
115 // owarn << "OPimTodoData " + summary << oendl;
116 setCategories( category ); 113 setCategories( category );
117 114
118 data = new OPimTodoData; 115 data = new OPimTodoData;
@@ -135,7 +132,6 @@ OPimTodo::OPimTodo( bool completed, int priority,
135 bool hasDate, QDate date, int uid ) 132 bool hasDate, QDate date, int uid )
136 : OPimRecord( uid ) 133 : OPimRecord( uid )
137{ 134{
138 // owarn << "OPimTodoData" + summary << oendl;
139 setCategories( idsFromString( category.join( ";" ) ) ); 135 setCategories( idsFromString( category.join( ";" ) ) );
140 136
141 data = new OPimTodoData; 137 data = new OPimTodoData;
@@ -187,13 +183,33 @@ bool OPimTodo::hasDueDate() const
187 return data->hasDate; 183 return data->hasDate;
188} 184}
189 185
190 186/**
187 * \brief Does this Todo have a start date
188 *
189 * Does this Todo have a start date. The decision
190 * is based on if the internal startDate isValid
191 * in the sense of QDate::isValid.
192 *
193 * @return True if the startDate isValid
194 * @see startDate
195 * @see setStartDate
196 * @see QDate::isValid()
197 */
191bool OPimTodo::hasStartDate() const 198bool OPimTodo::hasStartDate() const
192{ 199{
193 return data->start.isValid(); 200 return data->start.isValid();
194} 201}
195 202
196 203/**
204 * \brief Does this Todo have a Date when it was completed
205 *
206 * As in \sa hasStartDate() it is determined if there
207 * is a completed date by looking if the internal date
208 * isValid \sa QDate::isValid.
209 *
210 * @see hasStartDate
211 * @return True if the completedDate is set and valid.
212 */
197bool OPimTodo::hasCompletedDate() const 213bool OPimTodo::hasCompletedDate() const
198{ 214{
199 return data->completed.isValid(); 215 return data->completed.isValid();
@@ -308,7 +324,6 @@ void OPimTodo::setHasDueDate( bool hasDate )
308 324
309void OPimTodo::setDescription( const QString &desc ) 325void OPimTodo::setDescription( const QString &desc )
310{ 326{
311 // owarn << "desc " + desc << oendl;
312 changeOrModify(); 327 changeOrModify();
313 data->desc = Qtopia::simplifyMultiLineSpace( desc ); 328 data->desc = Qtopia::simplifyMultiLineSpace( desc );
314} 329}
@@ -380,7 +395,7 @@ void OPimTodo::setMaintainer( const OPimMaintainer& pim )
380} 395}
381 396
382 397
383bool OPimTodo::isOverdue( ) 398bool OPimTodo::isOverdue( )const
384{ 399{
385 if ( data->hasDate && !data->isCompleted ) 400 if ( data->hasDate && !data->isCompleted )
386 return QDate::currentDate() > data->date; 401 return QDate::currentDate() > data->date;
@@ -593,10 +608,8 @@ bool OPimTodo::operator==( const OPimTodo &toDoEvent ) const
593void OPimTodo::deref() 608void OPimTodo::deref()
594{ 609{
595 610
596 // owarn << "deref in ToDoEvent" << oendl;
597 if ( data->deref() ) 611 if ( data->deref() )
598 { 612 {
599 // owarn << "deleting" << oendl;
600 delete data; 613 delete data;
601 data = 0; 614 data = 0;
602 } 615 }
@@ -608,7 +621,6 @@ OPimTodo &OPimTodo::operator=( const OPimTodo &item )
608 if ( this == &item ) return * this; 621 if ( this == &item ) return * this;
609 622
610 OPimRecord::operator=( item ); 623 OPimRecord::operator=( item );
611 //owarn << "operator= ref " << oendl;
612 item.data->ref(); 624 item.data->ref();
613 deref(); 625 deref();
614 data = item.data; 626 data = item.data;
@@ -651,7 +663,6 @@ void OPimTodo::changeOrModify()
651{ 663{
652 if ( data->count != 1 ) 664 if ( data->count != 1 )
653 { 665 {
654 owarn << "changeOrModify" << oendl;
655 data->deref(); 666 data->deref();
656 OPimTodoData* d2 = new OPimTodoData(); 667 OPimTodoData* d2 = new OPimTodoData();
657 copy( data, d2 ); 668 copy( data, d2 );
@@ -699,9 +710,78 @@ QString OPimTodo::type() const
699} 710}
700 711
701 712
702QString OPimTodo::recordField( int /*id*/ ) const 713QString OPimTodo::recordField( int id) const
703{ 714{
704 return QString::null; 715 QString res;
716 Q_UNUSED( id )
717#if 0
718 switch( id ) {
719 case HasDate:
720 res = (hasDueDate() ?
721 QObject::tr( "Has a due-date" )
722 : QObject::tr( "No due-date" ));
723 break;
724 case Completed:
725 res = ( isCompleted() ?
726 QObject::tr( "Completed" ) :
727 QObject::tr( "Not completed" ));
728 break;
729 case Description:
730 res = description();
731 break;
732 case Summary:
733 res = summary();
734 break;
735 case Priority:
736 res = QString::number( priority() );
737 break;
738 case DateDay:
739 res = QString::number( dueDate().day() );
740 break;
741 case DateMonth:
742 res = QString::number( dueDate().month() );
743 break;
744 case DateYear:
745 res = QString::number( dueDate().year() );
746 break;
747 case Progress:
748 res = QString::number( progress() );
749 break;
750 case State:
751 res = QString::number( state().state() );
752 break;
753 case Recurrence:
754 res = ( hasRecurrence() ?
755 QString::null /*recurrence().summary()*/ :
756 QObject::tr("No reccurrence"));
757 break;
758 case Alarms:
759 break;
760 case Reminders:
761 break;
762 case Maintainer:
763 break;
764 case StartDate:
765 res = ( hasStartDate() ?
766 /*TimeString::()*/ QString::null :
767 QObject::tr( "No start-date" ) );
768 break;
769 case CompletedDate:
770 res = ( hasCompletedDate() ?
771 /*TimeString::()*/ QString::null :
772 QObject::tr( "No completed-date" ) );
773 break;
774 case DueDate:
775 res = ( hasDueDate() ?
776 /*TimeString::()*/ QString::null :
777 QObject::tr( "No due-date" );
778 break;
779 default:
780 res = OPimRecord::recordField( id );
781 }
782
783#endif
784 return res;
705} 785}
706 786
707 787
@@ -710,4 +790,21 @@ int OPimTodo::rtti() const
710 return OPimResolver::TodoList; 790 return OPimResolver::TodoList;
711} 791}
712 792
793/**
794 * \brief Provide a SafeCast to OPimTodo from a OPimRecord
795 *
796 * Provide a safe cast that will return 0 if the record
797 * type is not OPimTodo. In the other case it will
798 * be casted to OPimTodo and returned
799 *
800 * @param rec The OPimRecord to be casted
801 *
802 * @return a pointer to OPimTodo or 0l
803 */
804OPimTodo* OPimTodo::safeCast( const OPimRecord* rec ) {
805 return (rec && rec->rtti() == OPimResolver::TodoList ) ?
806 static_cast<OPimTodo*>( const_cast<OPimRecord*>(rec) ) :
807 0l;
808}
809
713} 810}
diff --git a/libopie2/opiepim/core/opimtodo.h b/libopie2/opiepim/core/opimtodo.h
index e17fe6a..f4f9926 100644
--- a/libopie2/opiepim/core/opimtodo.h
+++ b/libopie2/opiepim/core/opimtodo.h
@@ -71,10 +71,11 @@ class OPimTodo : public OPimRecord
71 Recurrence, 71 Recurrence,
72 Alarms, 72 Alarms,
73 Reminders, 73 Reminders,
74 Notifiers,
75 Maintainer, 74 Maintainer,
76 StartDate, 75 StartDate,
77 CompletedDate 76 CompletedDate,
77//ADDITIONAL FOR RECORDFIELD
78 DueDate,
78 }; 79 };
79 public: 80 public:
80 // priorities from Very low to very high 81 // priorities from Very low to very high
@@ -282,7 +283,7 @@ class OPimTodo : public OPimRecord
282 */ 283 */
283 void setMaintainer( const OPimMaintainer& ); 284 void setMaintainer( const OPimMaintainer& );
284 285
285 bool isOverdue(); 286 bool isOverdue()const;
286 287
287 288
288 virtual bool match( const QRegExp &r ) const; 289 virtual bool match( const QRegExp &r ) const;
@@ -295,7 +296,11 @@ class OPimTodo : public OPimRecord
295 bool operator==( const OPimTodo &toDoEvent ) const; 296 bool operator==( const OPimTodo &toDoEvent ) const;
296 OPimTodo &operator=( const OPimTodo &toDoEvent ); 297 OPimTodo &operator=( const OPimTodo &toDoEvent );
297 298
299 //@{
298 int rtti() const; 300 int rtti() const;
301 static OPimTodo* safeCast( const OPimRecord* );
302 //@}
303
299 304
300 private: 305 private:
301 class OPimTodoPrivate; 306 class OPimTodoPrivate;
diff --git a/libopie2/opiepim/core/otodoaccess.cpp b/libopie2/opiepim/core/otodoaccess.cpp
index 26a68a0..4ad5950 100644
--- a/libopie2/opiepim/core/otodoaccess.cpp
+++ b/libopie2/opiepim/core/otodoaccess.cpp
@@ -50,8 +50,8 @@ OPimTodoAccess::OPimTodoAccess( OPimTodoAccessBackend* end, enum Access )
50 setBackEnd( m_todoBackEnd ); 50 setBackEnd( m_todoBackEnd );
51} 51}
52OPimTodoAccess::~OPimTodoAccess() { 52OPimTodoAccess::~OPimTodoAccess() {
53// owarn << "~OPimTodoAccess" << oendl;
54} 53}
54
55void OPimTodoAccess::mergeWith( const QValueList<OPimTodo>& list ) { 55void OPimTodoAccess::mergeWith( const QValueList<OPimTodo>& list ) {
56 QValueList<OPimTodo>::ConstIterator it; 56 QValueList<OPimTodo>::ConstIterator it;
57 for ( it = list.begin(); it != list.end(); ++it ) { 57 for ( it = list.begin(); it != list.end(); ++it ) {
@@ -60,38 +60,25 @@ void OPimTodoAccess::mergeWith( const QValueList<OPimTodo>& list ) {
60} 60}
61OPimTodoAccess::List OPimTodoAccess::effectiveToDos( const QDate& start, 61OPimTodoAccess::List OPimTodoAccess::effectiveToDos( const QDate& start,
62 const QDate& end, 62 const QDate& end,
63 bool includeNoDates ) { 63 bool includeNoDates )const {
64 QArray<int> ints = m_todoBackEnd->effectiveToDos( start, end, includeNoDates ); 64 QArray<int> ints = m_todoBackEnd->effectiveToDos( start, end, includeNoDates );
65 65
66 List lis( ints, this ); 66 List lis( ints, this );
67 return lis; 67 return lis;
68} 68}
69OPimTodoAccess::List OPimTodoAccess::effectiveToDos( const QDate& start, 69OPimTodoAccess::List OPimTodoAccess::effectiveToDos( const QDate& start,
70 bool includeNoDates ) { 70 bool includeNoDates )const {
71 return effectiveToDos( start, QDate::currentDate(), 71 return effectiveToDos( start, QDate::currentDate(),
72 includeNoDates ); 72 includeNoDates );
73} 73}
74OPimTodoAccess::List OPimTodoAccess::overDue() { 74OPimTodoAccess::List OPimTodoAccess::overDue()const {
75 List lis( m_todoBackEnd->overDue(), this ); 75 List lis( m_todoBackEnd->overDue(), this );
76 return lis; 76 return lis;
77} 77}
78/* sort order */ 78
79OPimTodoAccess::List OPimTodoAccess::sorted( bool ascending, int sort,int filter, int cat ) {
80 QArray<int> ints = m_todoBackEnd->sorted( ascending, sort,
81 filter, cat );
82 OPimTodoAccess::List list( ints, this );
83 return list;
84}
85void OPimTodoAccess::removeAllCompleted() { 79void OPimTodoAccess::removeAllCompleted() {
86 m_todoBackEnd->removeAllCompleted(); 80 m_todoBackEnd->removeAllCompleted();
87} 81}
88QBitArray OPimTodoAccess::backendSupport( const QString& ) const{
89 return m_todoBackEnd->supports();
90}
91bool OPimTodoAccess::backendSupports( int attr, const QString& ar) const{
92 return backendSupport(ar).testBit( attr );
93}
94
95 82
96int OPimTodoAccess::rtti() const 83int OPimTodoAccess::rtti() const
97{ 84{
diff --git a/libopie2/opiepim/core/otodoaccess.h b/libopie2/opiepim/core/otodoaccess.h
index 3f5af30..8338586 100644
--- a/libopie2/opiepim/core/otodoaccess.h
+++ b/libopie2/opiepim/core/otodoaccess.h
@@ -46,13 +46,11 @@ namespace Opie {
46class OPimTodoAccess : public QObject, public OPimAccessTemplate<OPimTodo> { 46class OPimTodoAccess : public QObject, public OPimAccessTemplate<OPimTodo> {
47 Q_OBJECT 47 Q_OBJECT
48public: 48public:
49 enum SortOrder { Completed = 0, 49 enum SortOrder { Completed = SortCustom,
50 Priority, 50 Priority,
51 Description,
52 Deadline }; 51 Deadline };
53 enum SortFilter{ Category =1, 52 enum SortFilter{ OnlyOverDue= FilterCustom,
54 OnlyOverDue= 2, 53 DoNotShowCompleted = FilterCustom<<1 };
55 DoNotShowCompleted =4 };
56 /** 54 /**
57 * if you use 0l 55 * if you use 0l
58 * the default resource will be 56 * the default resource will be
@@ -70,25 +68,20 @@ public:
70 */ 68 */
71 List effectiveToDos( const QDate& start, 69 List effectiveToDos( const QDate& start,
72 const QDate& end, 70 const QDate& end,
73 bool includeNoDates = true ); 71 bool includeNoDates = true )const;
74 72
75 /** 73 /**
76 * start 74 * start
77 * end date taken from the currentDate() 75 * end date taken from the currentDate()
78 */ 76 */
79 List effectiveToDos( const QDate& start, 77 List effectiveToDos( const QDate& start,
80 bool includeNoDates = true ); 78 bool includeNoDates = true )const;
81 79
82 80
83 /** 81 /**
84 * return overdue OPimTodos 82 * return overdue OPimTodos
85 */ 83 */
86 List overDue(); 84 List overDue()const;
87
88 /**
89 *
90 */
91 List sorted( bool ascending, int sortOrder, int sortFilter, int cat );
92 85
93 /** 86 /**
94 * merge a list of OPimTodos into 87 * merge a list of OPimTodos into
@@ -102,23 +95,6 @@ public:
102 void removeAllCompleted(); 95 void removeAllCompleted();
103 96
104 /** 97 /**
105 * request information about what a backend supports.
106 * Supports in the sense of beeing able to store.
107 * This is related to the enum in OPimTodo
108 *
109 * @param backend Will be used in the future when we support multiple backend
110 */
111 QBitArray backendSupport( const QString& backend = QString::null )const;
112
113 /**
114 * see above but for a specefic attribute. This method was added for convience
115 * @param attr The attribute to be queried for
116 * @param backend Will be used in the future when we support multiple backends
117 */
118 bool backendSupports( int attr, const QString& backend = QString::null )const;
119
120
121 /**
122 * Return identification of used records 98 * Return identification of used records
123 */ 99 */
124 int rtti() const; 100 int rtti() const;