author | zecke <zecke> | 2002-10-13 02:22:58 (UTC) |
---|---|---|
committer | zecke <zecke> | 2002-10-13 02:22:58 (UTC) |
commit | d96ce086c617b5b2efc5081cd10a43257a78f488 (patch) (unidiff) | |
tree | 4f6b80b7295127bd82cc5fb8ffd1d532c42a396b | |
parent | 2ce86d9be1bbf99092348adf815578b110fe7289 (diff) | |
download | opie-d96ce086c617b5b2efc5081cd10a43257a78f488.zip opie-d96ce086c617b5b2efc5081cd10a43257a78f488.tar.gz opie-d96ce086c617b5b2efc5081cd10a43257a78f488.tar.bz2 |
OPimAccessBackend nothing tried a isDirty()const ... but removed it
ORecordList uidAt(uint index ) added
Speed Improvements at the SQL backend
do not load the list of uids until it's really needed
do not reload the uid list until it's really needed
we got a bitfield m_dirty there...
-rw-r--r-- | libopie/pim/opimaccesstemplate.h | 2 | ||||
-rw-r--r-- | libopie/pim/orecordlist.h | 5 | ||||
-rw-r--r-- | libopie/pim/otodoaccesssql.cpp | 31 | ||||
-rw-r--r-- | libopie/pim/otodoaccesssql.h | 3 | ||||
-rw-r--r-- | libopie2/opiepim/backend/otodoaccesssql.cpp | 31 | ||||
-rw-r--r-- | libopie2/opiepim/backend/otodoaccesssql.h | 3 | ||||
-rw-r--r-- | libopie2/opiepim/core/opimaccesstemplate.h | 2 | ||||
-rw-r--r-- | libopie2/opiepim/orecordlist.h | 5 |
8 files changed, 58 insertions, 24 deletions
diff --git a/libopie/pim/opimaccesstemplate.h b/libopie/pim/opimaccesstemplate.h index 92d7192..a0d8f63 100644 --- a/libopie/pim/opimaccesstemplate.h +++ b/libopie/pim/opimaccesstemplate.h | |||
@@ -1,247 +1,245 @@ | |||
1 | #ifndef OPIE_PIM_ACCESS_TEMPLATE_H | 1 | #ifndef OPIE_PIM_ACCESS_TEMPLATE_H |
2 | #define OPIE_PIM_ACCESS_TEMPLATE_H | 2 | #define OPIE_PIM_ACCESS_TEMPLATE_H |
3 | 3 | ||
4 | #include <qarray.h> | 4 | #include <qarray.h> |
5 | 5 | ||
6 | #include <opie/opimrecord.h> | 6 | #include <opie/opimrecord.h> |
7 | #include <opie/opimaccessbackend.h> | 7 | #include <opie/opimaccessbackend.h> |
8 | #include <opie/orecordlist.h> | 8 | #include <opie/orecordlist.h> |
9 | 9 | ||
10 | #include "opimcache.h" | 10 | #include "opimcache.h" |
11 | #include "otemplatebase.h" | 11 | #include "otemplatebase.h" |
12 | 12 | ||
13 | /** | 13 | /** |
14 | * Thats the frontend to our OPIE PIM | 14 | * Thats the frontend to our OPIE PIM |
15 | * Library. Either you want to use it's | 15 | * Library. Either you want to use it's |
16 | * interface or you want to implement | 16 | * interface or you want to implement |
17 | * your own Access lib | 17 | * your own Access lib |
18 | * Just create a OPimRecord and inherit from | 18 | * Just create a OPimRecord and inherit from |
19 | * the plugins | 19 | * the plugins |
20 | */ | 20 | */ |
21 | 21 | ||
22 | template <class T = OPimRecord > | 22 | template <class T = OPimRecord > |
23 | class OPimAccessTemplate : public OTemplateBase<T> { | 23 | class OPimAccessTemplate : public OTemplateBase<T> { |
24 | public: | 24 | public: |
25 | typedef ORecordList<T> List; | 25 | typedef ORecordList<T> List; |
26 | typedef OPimAccessBackend<T> BackEnd; | 26 | typedef OPimAccessBackend<T> BackEnd; |
27 | typedef OPimCache<T> Cache; | 27 | typedef OPimCache<T> Cache; |
28 | 28 | ||
29 | /** | 29 | /** |
30 | * our sort order | 30 | * our sort order |
31 | * should be safe explaining | 31 | * should be safe explaining |
32 | */ | 32 | */ |
33 | enum SortOrder { WildCards = 0, IgnoreCase = 1, | 33 | enum SortOrder { WildCards = 0, IgnoreCase = 1, |
34 | RegExp = 2, ExactMatch = 4 }; | 34 | RegExp = 2, ExactMatch = 4 }; |
35 | 35 | ||
36 | /** | 36 | /** |
37 | * c'tor BackEnd | 37 | * c'tor BackEnd |
38 | */ | 38 | */ |
39 | OPimAccessTemplate( BackEnd* end); | 39 | OPimAccessTemplate( BackEnd* end); |
40 | virtual ~OPimAccessTemplate(); | 40 | virtual ~OPimAccessTemplate(); |
41 | 41 | ||
42 | /** | 42 | /** |
43 | * load from the backend | 43 | * load from the backend |
44 | */ | 44 | */ |
45 | virtual bool load(); | 45 | virtual bool load(); |
46 | 46 | ||
47 | /** | 47 | /** |
48 | * reload from the backend | 48 | * reload from the backend |
49 | */ | 49 | */ |
50 | virtual bool reload(); | 50 | virtual bool reload(); |
51 | 51 | ||
52 | /** | 52 | /** |
53 | * save to the backend | 53 | * save to the backend |
54 | */ | 54 | */ |
55 | virtual bool save(); | 55 | virtual bool save(); |
56 | 56 | ||
57 | /** | 57 | /** |
58 | * if the resource was changed externally | 58 | * if the resource was changed externally |
59 | */ | 59 | */ |
60 | bool wasChangedExternally()const; | 60 | bool wasChangedExternally()const; |
61 | 61 | ||
62 | /** | 62 | /** |
63 | * return a List of records | 63 | * return a List of records |
64 | * you can iterate over them | 64 | * you can iterate over them |
65 | */ | 65 | */ |
66 | virtual List allRecords()const; | 66 | virtual List allRecords()const; |
67 | 67 | ||
68 | /** | 68 | /** |
69 | * queryByExample | 69 | * queryByExample |
70 | */ | 70 | */ |
71 | virtual List queryByExample( const T& t, int sortOrder ); | 71 | virtual List queryByExample( const T& t, int sortOrder ); |
72 | 72 | ||
73 | /** | 73 | /** |
74 | * find the OPimRecord uid | 74 | * find the OPimRecord uid |
75 | */ | 75 | */ |
76 | virtual T find( int uid )const; | 76 | virtual T find( int uid )const; |
77 | 77 | ||
78 | /** | 78 | /** |
79 | * read ahead cache find method ;) | 79 | * read ahead cache find method ;) |
80 | */ | 80 | */ |
81 | virtual T find( int uid, const QArray<int>&, | 81 | virtual T find( int uid, const QArray<int>&, |
82 | uint current, CacheDirection dir = Forward )const; | 82 | uint current, CacheDirection dir = Forward )const; |
83 | 83 | ||
84 | /* invalidate cache here */ | 84 | /* invalidate cache here */ |
85 | /** | 85 | /** |
86 | * clears the backend and invalidates the backend | 86 | * clears the backend and invalidates the backend |
87 | */ | 87 | */ |
88 | virtual void clear() ; | 88 | virtual void clear() ; |
89 | 89 | ||
90 | /** | 90 | /** |
91 | * add T to the backend | 91 | * add T to the backend |
92 | */ | 92 | */ |
93 | virtual bool add( const T& t ) ; | 93 | virtual bool add( const T& t ) ; |
94 | 94 | ||
95 | /* only the uid matters */ | 95 | /* only the uid matters */ |
96 | /** | 96 | /** |
97 | * remove T from the backend | 97 | * remove T from the backend |
98 | */ | 98 | */ |
99 | virtual bool remove( const T& t ); | 99 | virtual bool remove( const T& t ); |
100 | 100 | ||
101 | /** | 101 | /** |
102 | * remove the OPimRecord with uid | 102 | * remove the OPimRecord with uid |
103 | */ | 103 | */ |
104 | virtual bool remove( int uid ); | 104 | virtual bool remove( int uid ); |
105 | 105 | ||
106 | /** | 106 | /** |
107 | * replace T from backend | 107 | * replace T from backend |
108 | */ | 108 | */ |
109 | virtual bool replace( const T& t) ; | 109 | virtual bool replace( const T& t) ; |
110 | 110 | ||
111 | /** | 111 | /** |
112 | * @internal | 112 | * @internal |
113 | */ | 113 | */ |
114 | void cache( const T& )const; | 114 | void cache( const T& )const; |
115 | void setSaneCacheSize( int ); | 115 | void setSaneCacheSize( int ); |
116 | protected: | 116 | protected: |
117 | /** | 117 | /** |
118 | * invalidate the cache | 118 | * invalidate the cache |
119 | */ | 119 | */ |
120 | void invalidateCache(); | 120 | void invalidateCache(); |
121 | 121 | ||
122 | void setBackEnd( BackEnd* end ); | 122 | void setBackEnd( BackEnd* end ); |
123 | /** | 123 | /** |
124 | * returns the backend | 124 | * returns the backend |
125 | */ | 125 | */ |
126 | BackEnd* backEnd(); | 126 | BackEnd* backEnd(); |
127 | BackEnd* m_backEnd; | 127 | BackEnd* m_backEnd; |
128 | Cache m_cache; | 128 | Cache m_cache; |
129 | 129 | ||
130 | }; | 130 | }; |
131 | 131 | ||
132 | template <class T> | 132 | template <class T> |
133 | OPimAccessTemplate<T>::OPimAccessTemplate( BackEnd* end ) | 133 | OPimAccessTemplate<T>::OPimAccessTemplate( BackEnd* end ) |
134 | : OTemplateBase<T>(), m_backEnd( end ) | 134 | : OTemplateBase<T>(), m_backEnd( end ) |
135 | { | 135 | { |
136 | if (end ) | 136 | if (end ) |
137 | end->setFrontend( this ); | 137 | end->setFrontend( this ); |
138 | } | 138 | } |
139 | template <class T> | 139 | template <class T> |
140 | OPimAccessTemplate<T>::~OPimAccessTemplate() { | 140 | OPimAccessTemplate<T>::~OPimAccessTemplate() { |
141 | qWarning("~OPimAccessTemplate<T>"); | 141 | qWarning("~OPimAccessTemplate<T>"); |
142 | delete m_backEnd; | 142 | delete m_backEnd; |
143 | } | 143 | } |
144 | template <class T> | 144 | template <class T> |
145 | bool OPimAccessTemplate<T>::load() { | 145 | bool OPimAccessTemplate<T>::load() { |
146 | invalidateCache(); | 146 | invalidateCache(); |
147 | return m_backEnd->load(); | 147 | return m_backEnd->load(); |
148 | } | 148 | } |
149 | template <class T> | 149 | template <class T> |
150 | bool OPimAccessTemplate<T>::reload() { | 150 | bool OPimAccessTemplate<T>::reload() { |
151 | return m_backEnd->reload(); | 151 | return m_backEnd->reload(); |
152 | } | 152 | } |
153 | template <class T> | 153 | template <class T> |
154 | bool OPimAccessTemplate<T>::save() { | 154 | bool OPimAccessTemplate<T>::save() { |
155 | return m_backEnd->save(); | 155 | return m_backEnd->save(); |
156 | } | 156 | } |
157 | template <class T> | 157 | template <class T> |
158 | OPimAccessTemplate<T>::List OPimAccessTemplate<T>::allRecords()const { | 158 | OPimAccessTemplate<T>::List OPimAccessTemplate<T>::allRecords()const { |
159 | QArray<int> ints = m_backEnd->allRecords(); | 159 | QArray<int> ints = m_backEnd->allRecords(); |
160 | List lis(ints, this ); | 160 | List lis(ints, this ); |
161 | return lis; | 161 | return lis; |
162 | } | 162 | } |
163 | template <class T> | 163 | template <class T> |
164 | OPimAccessTemplate<T>::List | 164 | OPimAccessTemplate<T>::List |
165 | OPimAccessTemplate<T>::queryByExample( const T& t, int sortOrder ) { | 165 | OPimAccessTemplate<T>::queryByExample( const T& t, int sortOrder ) { |
166 | QArray<int> ints = m_backEnd->queryByExample( t, sortOrder ); | 166 | QArray<int> ints = m_backEnd->queryByExample( t, sortOrder ); |
167 | 167 | ||
168 | List lis(ints, this ); | 168 | List lis(ints, this ); |
169 | return lis; | 169 | return lis; |
170 | } | 170 | } |
171 | template <class T> | 171 | template <class T> |
172 | T OPimAccessTemplate<T>::find( int uid ) const{ | 172 | T OPimAccessTemplate<T>::find( int uid ) const{ |
173 | T t = m_backEnd->find( uid ); | 173 | T t = m_backEnd->find( uid ); |
174 | cache( t ); | 174 | cache( t ); |
175 | return t; | 175 | return t; |
176 | } | 176 | } |
177 | template <class T> | 177 | template <class T> |
178 | T OPimAccessTemplate<T>::find( int uid, const QArray<int>& ar, | 178 | T OPimAccessTemplate<T>::find( int uid, const QArray<int>& ar, |
179 | uint current, CacheDirection dir )const { | 179 | uint current, CacheDirection dir )const { |
180 | /* | 180 | /* |
181 | * better do T.isEmpty() | 181 | * better do T.isEmpty() |
182 | * after a find this way we would | 182 | * after a find this way we would |
183 | * avoid two finds in QCache... | 183 | * avoid two finds in QCache... |
184 | */ | 184 | */ |
185 | // qWarning("find it now %d", uid ); | 185 | // qWarning("find it now %d", uid ); |
186 | if (m_cache.contains( uid ) ) { | 186 | if (m_cache.contains( uid ) ) { |
187 | qWarning("m cache contains %d", uid); | ||
188 | return m_cache.find( uid ); | 187 | return m_cache.find( uid ); |
189 | } | 188 | } |
190 | 189 | ||
191 | T t = m_backEnd->find( uid, ar, current, dir ); | 190 | T t = m_backEnd->find( uid, ar, current, dir ); |
192 | qWarning("found it and cache it now %d", uid); | ||
193 | cache( t ); | 191 | cache( t ); |
194 | return t; | 192 | return t; |
195 | } | 193 | } |
196 | template <class T> | 194 | template <class T> |
197 | void OPimAccessTemplate<T>::clear() { | 195 | void OPimAccessTemplate<T>::clear() { |
198 | invalidateCache(); | 196 | invalidateCache(); |
199 | m_backEnd->clear(); | 197 | m_backEnd->clear(); |
200 | } | 198 | } |
201 | template <class T> | 199 | template <class T> |
202 | bool OPimAccessTemplate<T>::add( const T& t ) { | 200 | bool OPimAccessTemplate<T>::add( const T& t ) { |
203 | cache( t ); | 201 | cache( t ); |
204 | return m_backEnd->add( t ); | 202 | return m_backEnd->add( t ); |
205 | } | 203 | } |
206 | template <class T> | 204 | template <class T> |
207 | bool OPimAccessTemplate<T>::remove( const T& t ) { | 205 | bool OPimAccessTemplate<T>::remove( const T& t ) { |
208 | return remove( t.uid() ); | 206 | return remove( t.uid() ); |
209 | } | 207 | } |
210 | template <class T> | 208 | template <class T> |
211 | bool OPimAccessTemplate<T>::remove( int uid ) { | 209 | bool OPimAccessTemplate<T>::remove( int uid ) { |
212 | m_cache.remove( uid ); | 210 | m_cache.remove( uid ); |
213 | return m_backEnd->remove( uid ); | 211 | return m_backEnd->remove( uid ); |
214 | } | 212 | } |
215 | template <class T> | 213 | template <class T> |
216 | bool OPimAccessTemplate<T>::replace( const T& t ) { | 214 | bool OPimAccessTemplate<T>::replace( const T& t ) { |
217 | m_cache.replace( t ); | 215 | m_cache.replace( t ); |
218 | return m_backEnd->replace( t ); | 216 | return m_backEnd->replace( t ); |
219 | } | 217 | } |
220 | template <class T> | 218 | template <class T> |
221 | void OPimAccessTemplate<T>::invalidateCache() { | 219 | void OPimAccessTemplate<T>::invalidateCache() { |
222 | m_cache.invalidate(); | 220 | m_cache.invalidate(); |
223 | } | 221 | } |
224 | template <class T> | 222 | template <class T> |
225 | OPimAccessTemplate<T>::BackEnd* OPimAccessTemplate<T>::backEnd() { | 223 | OPimAccessTemplate<T>::BackEnd* OPimAccessTemplate<T>::backEnd() { |
226 | return m_backEnd; | 224 | return m_backEnd; |
227 | } | 225 | } |
228 | template <class T> | 226 | template <class T> |
229 | bool OPimAccessTemplate<T>::wasChangedExternally()const { | 227 | bool OPimAccessTemplate<T>::wasChangedExternally()const { |
230 | return false; | 228 | return false; |
231 | } | 229 | } |
232 | template <class T> | 230 | template <class T> |
233 | void OPimAccessTemplate<T>::setBackEnd( BackEnd* end ) { | 231 | void OPimAccessTemplate<T>::setBackEnd( BackEnd* end ) { |
234 | m_backEnd = end; | 232 | m_backEnd = end; |
235 | if (m_backEnd ) | 233 | if (m_backEnd ) |
236 | m_backEnd->setFrontend( this ); | 234 | m_backEnd->setFrontend( this ); |
237 | } | 235 | } |
238 | template <class T> | 236 | template <class T> |
239 | void OPimAccessTemplate<T>::cache( const T& t ) const{ | 237 | void OPimAccessTemplate<T>::cache( const T& t ) const{ |
240 | /* hacky we need to work around the const*/ | 238 | /* hacky we need to work around the const*/ |
241 | ((OPimAccessTemplate<T>*)this)->m_cache.add( t ); | 239 | ((OPimAccessTemplate<T>*)this)->m_cache.add( t ); |
242 | } | 240 | } |
243 | template <class T> | 241 | template <class T> |
244 | void OPimAccessTemplate<T>::setSaneCacheSize( int size ) { | 242 | void OPimAccessTemplate<T>::setSaneCacheSize( int size ) { |
245 | m_cache.setSize( size ); | 243 | m_cache.setSize( size ); |
246 | } | 244 | } |
247 | #endif | 245 | #endif |
diff --git a/libopie/pim/orecordlist.h b/libopie/pim/orecordlist.h index 08f5c85..5404910 100644 --- a/libopie/pim/orecordlist.h +++ b/libopie/pim/orecordlist.h | |||
@@ -1,265 +1,270 @@ | |||
1 | 1 | ||
2 | #ifndef OPIE_RECORD_LIST_H | 2 | #ifndef OPIE_RECORD_LIST_H |
3 | #define OPIE_RECORD_LIST_H | 3 | #define OPIE_RECORD_LIST_H |
4 | 4 | ||
5 | #include <qarray.h> | 5 | #include <qarray.h> |
6 | 6 | ||
7 | #include "otemplatebase.h" | 7 | #include "otemplatebase.h" |
8 | #include "opimrecord.h" | 8 | #include "opimrecord.h" |
9 | 9 | ||
10 | /** | 10 | /** |
11 | * Our List Iterator | 11 | * Our List Iterator |
12 | * it behaves like STL or Qt | 12 | * it behaves like STL or Qt |
13 | * | 13 | * |
14 | * for(it = list.begin(); it != list.end(); ++it ) | 14 | * for(it = list.begin(); it != list.end(); ++it ) |
15 | * doSomeCoolStuff( (*it) ); | 15 | * doSomeCoolStuff( (*it) ); |
16 | */ | 16 | */ |
17 | template <class T> class ORecordList; | 17 | template <class T> class ORecordList; |
18 | template <class T = OPimRecord> | 18 | template <class T = OPimRecord> |
19 | class ORecordListIterator { | 19 | class ORecordListIterator { |
20 | friend class ORecordList<T>; | 20 | friend class ORecordList<T>; |
21 | public: | 21 | public: |
22 | typedef OTemplateBase<T> Base; | 22 | typedef OTemplateBase<T> Base; |
23 | 23 | ||
24 | /** | 24 | /** |
25 | * The c'tor used internally from | 25 | * The c'tor used internally from |
26 | * ORecordList | 26 | * ORecordList |
27 | */ | 27 | */ |
28 | ORecordListIterator( const QArray<int>, const Base* ); | 28 | ORecordListIterator( const QArray<int>, const Base* ); |
29 | 29 | ||
30 | /** | 30 | /** |
31 | * The standard c'tor | 31 | * The standard c'tor |
32 | */ | 32 | */ |
33 | ORecordListIterator(); | 33 | ORecordListIterator(); |
34 | ~ORecordListIterator(); | 34 | ~ORecordListIterator(); |
35 | 35 | ||
36 | ORecordListIterator( const ORecordListIterator& ); | 36 | ORecordListIterator( const ORecordListIterator& ); |
37 | ORecordListIterator &operator=(const ORecordListIterator& ); | 37 | ORecordListIterator &operator=(const ORecordListIterator& ); |
38 | 38 | ||
39 | /** | 39 | /** |
40 | * a * operator ;) | 40 | * a * operator ;) |
41 | * use it like this T = (*it); | 41 | * use it like this T = (*it); |
42 | */ | 42 | */ |
43 | T operator*(); | 43 | T operator*(); |
44 | ORecordListIterator &operator++(); | 44 | ORecordListIterator &operator++(); |
45 | ORecordListIterator &operator--(); | 45 | ORecordListIterator &operator--(); |
46 | 46 | ||
47 | bool operator==( const ORecordListIterator& it ); | 47 | bool operator==( const ORecordListIterator& it ); |
48 | bool operator!=( const ORecordListIterator& it ); | 48 | bool operator!=( const ORecordListIterator& it ); |
49 | 49 | ||
50 | /** | 50 | /** |
51 | * the current item | 51 | * the current item |
52 | */ | 52 | */ |
53 | uint current()const; | 53 | uint current()const; |
54 | 54 | ||
55 | /** | 55 | /** |
56 | * the number of items | 56 | * the number of items |
57 | */ | 57 | */ |
58 | uint count()const; | 58 | uint count()const; |
59 | 59 | ||
60 | /** | 60 | /** |
61 | * sets the current item | 61 | * sets the current item |
62 | */ | 62 | */ |
63 | void setCurrent( uint cur ); | 63 | void setCurrent( uint cur ); |
64 | 64 | ||
65 | private: | 65 | private: |
66 | QArray<int> m_uids; | 66 | QArray<int> m_uids; |
67 | uint m_current; | 67 | uint m_current; |
68 | const Base* m_temp; | 68 | const Base* m_temp; |
69 | bool m_end : 1; | 69 | bool m_end : 1; |
70 | T m_record; | 70 | T m_record; |
71 | bool m_direction :1; | 71 | bool m_direction :1; |
72 | 72 | ||
73 | /* d pointer for future versions */ | 73 | /* d pointer for future versions */ |
74 | class IteratorPrivate; | 74 | class IteratorPrivate; |
75 | IteratorPrivate *d; | 75 | IteratorPrivate *d; |
76 | }; | 76 | }; |
77 | /** | 77 | /** |
78 | * The recordlist used as a return type | 78 | * The recordlist used as a return type |
79 | * from OPimAccessTemplate | 79 | * from OPimAccessTemplate |
80 | */ | 80 | */ |
81 | template <class T = OPimRecord > | 81 | template <class T = OPimRecord > |
82 | class ORecordList { | 82 | class ORecordList { |
83 | public: | 83 | public: |
84 | typedef OTemplateBase<T> Base; | 84 | typedef OTemplateBase<T> Base; |
85 | typedef ORecordListIterator<T> Iterator; | 85 | typedef ORecordListIterator<T> Iterator; |
86 | 86 | ||
87 | /** | 87 | /** |
88 | * c'tor | 88 | * c'tor |
89 | */ | 89 | */ |
90 | ORecordList () { | 90 | ORecordList () { |
91 | } | 91 | } |
92 | ORecordList( const QArray<int>& ids, | 92 | ORecordList( const QArray<int>& ids, |
93 | const Base* ); | 93 | const Base* ); |
94 | ~ORecordList(); | 94 | ~ORecordList(); |
95 | 95 | ||
96 | /** | 96 | /** |
97 | * the first iterator | 97 | * the first iterator |
98 | */ | 98 | */ |
99 | Iterator begin(); | 99 | Iterator begin(); |
100 | 100 | ||
101 | /** | 101 | /** |
102 | * the end | 102 | * the end |
103 | */ | 103 | */ |
104 | Iterator end(); | 104 | Iterator end(); |
105 | 105 | ||
106 | /** | 106 | /** |
107 | * the number of items in the list | 107 | * the number of items in the list |
108 | */ | 108 | */ |
109 | uint count()const; | 109 | uint count()const; |
110 | 110 | ||
111 | T operator[]( uint i ); | 111 | T operator[]( uint i ); |
112 | int uidAt(uint i ); | ||
112 | // FIXME implemenent remove | 113 | // FIXME implemenent remove |
113 | /* | 114 | /* |
114 | ConstIterator begin()const; | 115 | ConstIterator begin()const; |
115 | ConstIterator end()const; | 116 | ConstIterator end()const; |
116 | */ | 117 | */ |
117 | private: | 118 | private: |
118 | QArray<int> m_ids; | 119 | QArray<int> m_ids; |
119 | const Base* m_acc; | 120 | const Base* m_acc; |
120 | }; | 121 | }; |
121 | 122 | ||
122 | /* ok now implement it */ | 123 | /* ok now implement it */ |
123 | template <class T> | 124 | template <class T> |
124 | ORecordListIterator<T>::ORecordListIterator() { | 125 | ORecordListIterator<T>::ORecordListIterator() { |
125 | m_current = 0; | 126 | m_current = 0; |
126 | m_temp = 0l; | 127 | m_temp = 0l; |
127 | m_end = true; | 128 | m_end = true; |
128 | m_record = T(); | 129 | m_record = T(); |
129 | /* forward */ | 130 | /* forward */ |
130 | m_direction = TRUE; | 131 | m_direction = TRUE; |
131 | } | 132 | } |
132 | template <class T> | 133 | template <class T> |
133 | ORecordListIterator<T>::~ORecordListIterator() { | 134 | ORecordListIterator<T>::~ORecordListIterator() { |
134 | /* nothing to delete */ | 135 | /* nothing to delete */ |
135 | } | 136 | } |
136 | 137 | ||
137 | template <class T> | 138 | template <class T> |
138 | ORecordListIterator<T>::ORecordListIterator( const ORecordListIterator<T>& it) { | 139 | ORecordListIterator<T>::ORecordListIterator( const ORecordListIterator<T>& it) { |
139 | // qWarning("ORecordListIterator copy c'tor"); | 140 | // qWarning("ORecordListIterator copy c'tor"); |
140 | m_uids = it.m_uids; | 141 | m_uids = it.m_uids; |
141 | m_current = it.m_current; | 142 | m_current = it.m_current; |
142 | m_temp = it.m_temp; | 143 | m_temp = it.m_temp; |
143 | m_end = it.m_end; | 144 | m_end = it.m_end; |
144 | m_record = it.m_record; | 145 | m_record = it.m_record; |
145 | m_direction = it.m_direction; | 146 | m_direction = it.m_direction; |
146 | } | 147 | } |
147 | 148 | ||
148 | template <class T> | 149 | template <class T> |
149 | ORecordListIterator<T> &ORecordListIterator<T>::operator=( const ORecordListIterator<T>& it) { | 150 | ORecordListIterator<T> &ORecordListIterator<T>::operator=( const ORecordListIterator<T>& it) { |
150 | m_uids = it.m_uids; | 151 | m_uids = it.m_uids; |
151 | m_current = it.m_current; | 152 | m_current = it.m_current; |
152 | m_temp = it.m_temp; | 153 | m_temp = it.m_temp; |
153 | m_end = it.m_end; | 154 | m_end = it.m_end; |
154 | m_record = it.m_record; | 155 | m_record = it.m_record; |
155 | 156 | ||
156 | return *this; | 157 | return *this; |
157 | } | 158 | } |
158 | 159 | ||
159 | template <class T> | 160 | template <class T> |
160 | T ORecordListIterator<T>::operator*() { | 161 | T ORecordListIterator<T>::operator*() { |
161 | qWarning("operator* %d %d", m_current, m_uids[m_current] ); | 162 | qWarning("operator* %d %d", m_current, m_uids[m_current] ); |
162 | if (!m_end ) | 163 | if (!m_end ) |
163 | m_record = m_temp->find( m_uids[m_current], m_uids, m_current, | 164 | m_record = m_temp->find( m_uids[m_current], m_uids, m_current, |
164 | m_direction ? Base::Forward : | 165 | m_direction ? Base::Forward : |
165 | Base::Reverse ); | 166 | Base::Reverse ); |
166 | else | 167 | else |
167 | m_record = T(); | 168 | m_record = T(); |
168 | 169 | ||
169 | return m_record; | 170 | return m_record; |
170 | } | 171 | } |
171 | 172 | ||
172 | template <class T> | 173 | template <class T> |
173 | ORecordListIterator<T> &ORecordListIterator<T>::operator++() { | 174 | ORecordListIterator<T> &ORecordListIterator<T>::operator++() { |
174 | m_direction = true; | 175 | m_direction = true; |
175 | if (m_current < m_uids.count() ) { | 176 | if (m_current < m_uids.count() ) { |
176 | m_end = false; | 177 | m_end = false; |
177 | ++m_current; | 178 | ++m_current; |
178 | }else | 179 | }else |
179 | m_end = true; | 180 | m_end = true; |
180 | 181 | ||
181 | return *this; | 182 | return *this; |
182 | } | 183 | } |
183 | template <class T> | 184 | template <class T> |
184 | ORecordListIterator<T> &ORecordListIterator<T>::operator--() { | 185 | ORecordListIterator<T> &ORecordListIterator<T>::operator--() { |
185 | m_direction = false; | 186 | m_direction = false; |
186 | if ( m_current > 0 ) { | 187 | if ( m_current > 0 ) { |
187 | --m_current; | 188 | --m_current; |
188 | m_end = false; | 189 | m_end = false; |
189 | } else | 190 | } else |
190 | m_end = true; | 191 | m_end = true; |
191 | 192 | ||
192 | return *this; | 193 | return *this; |
193 | } | 194 | } |
194 | 195 | ||
195 | template <class T> | 196 | template <class T> |
196 | bool ORecordListIterator<T>::operator==( const ORecordListIterator<T>& it ) { | 197 | bool ORecordListIterator<T>::operator==( const ORecordListIterator<T>& it ) { |
197 | 198 | ||
198 | /* if both are at we're the same.... */ | 199 | /* if both are at we're the same.... */ |
199 | if ( m_end == it.m_end ) return true; | 200 | if ( m_end == it.m_end ) return true; |
200 | 201 | ||
201 | if ( m_uids != it.m_uids ) return false; | 202 | if ( m_uids != it.m_uids ) return false; |
202 | if ( m_current != it.m_current ) return false; | 203 | if ( m_current != it.m_current ) return false; |
203 | if ( m_temp != it.m_temp ) return false; | 204 | if ( m_temp != it.m_temp ) return false; |
204 | 205 | ||
205 | return true; | 206 | return true; |
206 | } | 207 | } |
207 | template <class T> | 208 | template <class T> |
208 | bool ORecordListIterator<T>::operator!=( const ORecordListIterator<T>& it ) { | 209 | bool ORecordListIterator<T>::operator!=( const ORecordListIterator<T>& it ) { |
209 | return !(*this == it ); | 210 | return !(*this == it ); |
210 | } | 211 | } |
211 | template <class T> | 212 | template <class T> |
212 | ORecordListIterator<T>::ORecordListIterator( const QArray<int> uids, | 213 | ORecordListIterator<T>::ORecordListIterator( const QArray<int> uids, |
213 | const Base* t ) | 214 | const Base* t ) |
214 | : m_uids( uids ), m_current( 0 ), m_temp( t ), m_end( false ), | 215 | : m_uids( uids ), m_current( 0 ), m_temp( t ), m_end( false ), |
215 | m_direction( false ) | 216 | m_direction( false ) |
216 | { | 217 | { |
217 | } | 218 | } |
218 | template <class T> | 219 | template <class T> |
219 | uint ORecordListIterator<T>::current()const { | 220 | uint ORecordListIterator<T>::current()const { |
220 | return m_current; | 221 | return m_current; |
221 | } | 222 | } |
222 | template <class T> | 223 | template <class T> |
223 | void ORecordListIterator<T>::setCurrent( uint cur ) { | 224 | void ORecordListIterator<T>::setCurrent( uint cur ) { |
224 | if( cur < m_uids.count() ) { | 225 | if( cur < m_uids.count() ) { |
225 | m_end = false; | 226 | m_end = false; |
226 | m_current= cur; | 227 | m_current= cur; |
227 | } | 228 | } |
228 | } | 229 | } |
229 | template <class T> | 230 | template <class T> |
230 | uint ORecordListIterator<T>::count()const { | 231 | uint ORecordListIterator<T>::count()const { |
231 | return m_uids.count(); | 232 | return m_uids.count(); |
232 | } | 233 | } |
233 | template <class T> | 234 | template <class T> |
234 | ORecordList<T>::ORecordList( const QArray<int>& ids, | 235 | ORecordList<T>::ORecordList( const QArray<int>& ids, |
235 | const Base* acc ) | 236 | const Base* acc ) |
236 | : m_ids( ids ), m_acc( acc ) | 237 | : m_ids( ids ), m_acc( acc ) |
237 | { | 238 | { |
238 | } | 239 | } |
239 | template <class T> | 240 | template <class T> |
240 | ORecordList<T>::~ORecordList() { | 241 | ORecordList<T>::~ORecordList() { |
241 | /* nothing to do here */ | 242 | /* nothing to do here */ |
242 | } | 243 | } |
243 | template <class T> | 244 | template <class T> |
244 | ORecordList<T>::Iterator ORecordList<T>::begin() { | 245 | ORecordList<T>::Iterator ORecordList<T>::begin() { |
245 | Iterator it( m_ids, m_acc ); | 246 | Iterator it( m_ids, m_acc ); |
246 | return it; | 247 | return it; |
247 | } | 248 | } |
248 | template <class T> | 249 | template <class T> |
249 | ORecordList<T>::Iterator ORecordList<T>::end() { | 250 | ORecordList<T>::Iterator ORecordList<T>::end() { |
250 | Iterator it( m_ids, m_acc ); | 251 | Iterator it( m_ids, m_acc ); |
251 | it.m_end = true; | 252 | it.m_end = true; |
252 | it.m_current = m_ids.count(); | 253 | it.m_current = m_ids.count(); |
253 | 254 | ||
254 | return it; | 255 | return it; |
255 | } | 256 | } |
256 | template <class T> | 257 | template <class T> |
257 | uint ORecordList<T>::count()const { | 258 | uint ORecordList<T>::count()const { |
258 | return m_ids.count(); | 259 | return m_ids.count(); |
259 | } | 260 | } |
260 | template <class T> | 261 | template <class T> |
261 | T ORecordList<T>::operator[]( uint i ) { | 262 | T ORecordList<T>::operator[]( uint i ) { |
262 | /* forward */ | 263 | /* forward */ |
263 | return m_acc->find( m_ids[i], m_ids, i ); | 264 | return m_acc->find( m_ids[i], m_ids, i ); |
264 | } | 265 | } |
266 | template <class T> | ||
267 | int ORecordList<T>::uidAt( uint i ) { | ||
268 | return m_ids[i]; | ||
269 | } | ||
265 | #endif | 270 | #endif |
diff --git a/libopie/pim/otodoaccesssql.cpp b/libopie/pim/otodoaccesssql.cpp index a059dab..ea8b3c9 100644 --- a/libopie/pim/otodoaccesssql.cpp +++ b/libopie/pim/otodoaccesssql.cpp | |||
@@ -52,475 +52,488 @@ namespace { | |||
52 | OTodo m_todo; | 52 | OTodo m_todo; |
53 | }; | 53 | }; |
54 | 54 | ||
55 | /** | 55 | /** |
56 | * removes one from the table | 56 | * removes one from the table |
57 | */ | 57 | */ |
58 | class RemoveQuery : public OSQLQuery { | 58 | class RemoveQuery : public OSQLQuery { |
59 | public: | 59 | public: |
60 | RemoveQuery(int uid ); | 60 | RemoveQuery(int uid ); |
61 | ~RemoveQuery(); | 61 | ~RemoveQuery(); |
62 | QString query()const; | 62 | QString query()const; |
63 | private: | 63 | private: |
64 | int m_uid; | 64 | int m_uid; |
65 | }; | 65 | }; |
66 | 66 | ||
67 | /** | 67 | /** |
68 | * Clears (delete) a Table | 68 | * Clears (delete) a Table |
69 | */ | 69 | */ |
70 | class ClearQuery : public OSQLQuery { | 70 | class ClearQuery : public OSQLQuery { |
71 | public: | 71 | public: |
72 | ClearQuery(); | 72 | ClearQuery(); |
73 | ~ClearQuery(); | 73 | ~ClearQuery(); |
74 | QString query()const; | 74 | QString query()const; |
75 | 75 | ||
76 | }; | 76 | }; |
77 | 77 | ||
78 | /** | 78 | /** |
79 | * a find query | 79 | * a find query |
80 | */ | 80 | */ |
81 | class FindQuery : public OSQLQuery { | 81 | class FindQuery : public OSQLQuery { |
82 | public: | 82 | public: |
83 | FindQuery(int uid); | 83 | FindQuery(int uid); |
84 | FindQuery(const QArray<int>& ); | 84 | FindQuery(const QArray<int>& ); |
85 | ~FindQuery(); | 85 | ~FindQuery(); |
86 | QString query()const; | 86 | QString query()const; |
87 | private: | 87 | private: |
88 | QString single()const; | 88 | QString single()const; |
89 | QString multi()const; | 89 | QString multi()const; |
90 | QArray<int> m_uids; | 90 | QArray<int> m_uids; |
91 | int m_uid; | 91 | int m_uid; |
92 | }; | 92 | }; |
93 | 93 | ||
94 | /** | 94 | /** |
95 | * overdue query | 95 | * overdue query |
96 | */ | 96 | */ |
97 | class OverDueQuery : public OSQLQuery { | 97 | class OverDueQuery : public OSQLQuery { |
98 | public: | 98 | public: |
99 | OverDueQuery(); | 99 | OverDueQuery(); |
100 | ~OverDueQuery(); | 100 | ~OverDueQuery(); |
101 | QString query()const; | 101 | QString query()const; |
102 | }; | 102 | }; |
103 | class EffQuery : public OSQLQuery { | 103 | class EffQuery : public OSQLQuery { |
104 | public: | 104 | public: |
105 | EffQuery( const QDate&, const QDate&, bool inc ); | 105 | EffQuery( const QDate&, const QDate&, bool inc ); |
106 | ~EffQuery(); | 106 | ~EffQuery(); |
107 | QString query()const; | 107 | QString query()const; |
108 | private: | 108 | private: |
109 | QString with()const; | 109 | QString with()const; |
110 | QString out()const; | 110 | QString out()const; |
111 | QDate m_start; | 111 | QDate m_start; |
112 | QDate m_end; | 112 | QDate m_end; |
113 | bool m_inc :1; | 113 | bool m_inc :1; |
114 | }; | 114 | }; |
115 | 115 | ||
116 | 116 | ||
117 | CreateQuery::CreateQuery() : OSQLQuery() {} | 117 | CreateQuery::CreateQuery() : OSQLQuery() {} |
118 | CreateQuery::~CreateQuery() {} | 118 | CreateQuery::~CreateQuery() {} |
119 | QString CreateQuery::query()const { | 119 | QString CreateQuery::query()const { |
120 | QString qu; | 120 | QString qu; |
121 | qu += "create table todolist( uid, categories, completed, progress, "; | 121 | qu += "create table todolist( uid, categories, completed, progress, "; |
122 | qu += "summary, DueDate, priority, description )"; | 122 | qu += "summary, DueDate, priority, description )"; |
123 | return qu; | 123 | return qu; |
124 | } | 124 | } |
125 | 125 | ||
126 | LoadQuery::LoadQuery() : OSQLQuery() {} | 126 | LoadQuery::LoadQuery() : OSQLQuery() {} |
127 | LoadQuery::~LoadQuery() {} | 127 | LoadQuery::~LoadQuery() {} |
128 | QString LoadQuery::query()const { | 128 | QString LoadQuery::query()const { |
129 | QString qu; | 129 | QString qu; |
130 | qu += "select distinct uid from todolist"; | 130 | qu += "select distinct uid from todolist"; |
131 | 131 | ||
132 | return qu; | 132 | return qu; |
133 | } | 133 | } |
134 | 134 | ||
135 | InsertQuery::InsertQuery( const OTodo& todo ) | 135 | InsertQuery::InsertQuery( const OTodo& todo ) |
136 | : OSQLQuery(), m_todo( todo ) { | 136 | : OSQLQuery(), m_todo( todo ) { |
137 | } | 137 | } |
138 | InsertQuery::~InsertQuery() { | 138 | InsertQuery::~InsertQuery() { |
139 | } | 139 | } |
140 | /* | 140 | /* |
141 | * converts from a OTodo to a query | 141 | * converts from a OTodo to a query |
142 | * we leave out X-Ref + Alarms | 142 | * we leave out X-Ref + Alarms |
143 | */ | 143 | */ |
144 | QString InsertQuery::query()const{ | 144 | QString InsertQuery::query()const{ |
145 | 145 | ||
146 | int year, month, day; | 146 | int year, month, day; |
147 | year = month = day = 0; | 147 | year = month = day = 0; |
148 | if (m_todo.hasDueDate() ) { | 148 | if (m_todo.hasDueDate() ) { |
149 | QDate date = m_todo.dueDate(); | 149 | QDate date = m_todo.dueDate(); |
150 | year = date.year(); | 150 | year = date.year(); |
151 | month = date.month(); | 151 | month = date.month(); |
152 | day = date.day(); | 152 | day = date.day(); |
153 | } | 153 | } |
154 | QString qu; | 154 | QString qu; |
155 | qu = "insert into todolist VALUES(" + QString::number( m_todo.uid() ) + ",'" + m_todo.idsToString( m_todo.categories() ) + "',"; | 155 | qu = "insert into todolist VALUES(" + QString::number( m_todo.uid() ) + ",'" + m_todo.idsToString( m_todo.categories() ) + "',"; |
156 | qu += QString::number( m_todo.isCompleted() ) + "," + QString::number( m_todo.progress() ) + ","; | 156 | qu += QString::number( m_todo.isCompleted() ) + "," + QString::number( m_todo.progress() ) + ","; |
157 | qu += "'"+m_todo.summary()+"','"+QString::number(year)+"-"+QString::number(month)+"-"+QString::number(day)+"',"; | 157 | qu += "'"+m_todo.summary()+"','"+QString::number(year)+"-"+QString::number(month)+"-"+QString::number(day)+"',"; |
158 | qu += QString::number(m_todo.priority() ) +",'" + m_todo.description() + "')"; | 158 | qu += QString::number(m_todo.priority() ) +",'" + m_todo.description() + "')"; |
159 | 159 | ||
160 | qWarning("add %s", qu.latin1() ); | 160 | qWarning("add %s", qu.latin1() ); |
161 | return qu; | 161 | return qu; |
162 | } | 162 | } |
163 | 163 | ||
164 | RemoveQuery::RemoveQuery(int uid ) | 164 | RemoveQuery::RemoveQuery(int uid ) |
165 | : OSQLQuery(), m_uid( uid ) {} | 165 | : OSQLQuery(), m_uid( uid ) {} |
166 | RemoveQuery::~RemoveQuery() {} | 166 | RemoveQuery::~RemoveQuery() {} |
167 | QString RemoveQuery::query()const { | 167 | QString RemoveQuery::query()const { |
168 | QString qu = "DELETE from todolist where uid = " + QString::number(m_uid); | 168 | QString qu = "DELETE from todolist where uid = " + QString::number(m_uid); |
169 | return qu; | 169 | return qu; |
170 | } | 170 | } |
171 | 171 | ||
172 | 172 | ||
173 | ClearQuery::ClearQuery() | 173 | ClearQuery::ClearQuery() |
174 | : OSQLQuery() {} | 174 | : OSQLQuery() {} |
175 | ClearQuery::~ClearQuery() {} | 175 | ClearQuery::~ClearQuery() {} |
176 | QString ClearQuery::query()const { | 176 | QString ClearQuery::query()const { |
177 | QString qu = "drop table todolist"; | 177 | QString qu = "drop table todolist"; |
178 | return qu; | 178 | return qu; |
179 | } | 179 | } |
180 | FindQuery::FindQuery(int uid) | 180 | FindQuery::FindQuery(int uid) |
181 | : OSQLQuery(), m_uid(uid ) { | 181 | : OSQLQuery(), m_uid(uid ) { |
182 | } | 182 | } |
183 | FindQuery::FindQuery(const QArray<int>& ints) | 183 | FindQuery::FindQuery(const QArray<int>& ints) |
184 | : OSQLQuery(), m_uids(ints){ | 184 | : OSQLQuery(), m_uids(ints){ |
185 | } | 185 | } |
186 | FindQuery::~FindQuery() { | 186 | FindQuery::~FindQuery() { |
187 | } | 187 | } |
188 | QString FindQuery::query()const{ | 188 | QString FindQuery::query()const{ |
189 | if (m_uids.count() == 0 ) | 189 | if (m_uids.count() == 0 ) |
190 | return single(); | 190 | return single(); |
191 | else | 191 | else |
192 | return multi(); | 192 | return multi(); |
193 | } | 193 | } |
194 | QString FindQuery::single()const{ | 194 | QString FindQuery::single()const{ |
195 | QString qu = "select uid, categories, completed, progress, summary, "; | 195 | QString qu = "select uid, categories, completed, progress, summary, "; |
196 | qu += "DueDate, priority, description from todolist where uid = " + QString::number(m_uid); | 196 | qu += "DueDate, priority, description from todolist where uid = " + QString::number(m_uid); |
197 | return qu; | 197 | return qu; |
198 | } | 198 | } |
199 | QString FindQuery::multi()const { | 199 | QString FindQuery::multi()const { |
200 | QString qu = "select uid, categories, completed, progress, summary, "; | 200 | QString qu = "select uid, categories, completed, progress, summary, "; |
201 | qu += "DueDate, priority, description from todolist where "; | 201 | qu += "DueDate, priority, description from todolist where "; |
202 | for (uint i = 0; i < m_uids.count(); i++ ) { | 202 | for (uint i = 0; i < m_uids.count(); i++ ) { |
203 | qu += " UID = " + QString::number( m_uids[i] ) + " OR"; | 203 | qu += " UID = " + QString::number( m_uids[i] ) + " OR"; |
204 | } | 204 | } |
205 | qu.remove( qu.length()-2, 2 ); | 205 | qu.remove( qu.length()-2, 2 ); |
206 | return qu; | 206 | return qu; |
207 | } | 207 | } |
208 | 208 | ||
209 | OverDueQuery::OverDueQuery(): OSQLQuery() {} | 209 | OverDueQuery::OverDueQuery(): OSQLQuery() {} |
210 | OverDueQuery::~OverDueQuery() {} | 210 | OverDueQuery::~OverDueQuery() {} |
211 | QString OverDueQuery::query()const { | 211 | QString OverDueQuery::query()const { |
212 | QDate date = QDate::currentDate(); | 212 | QDate date = QDate::currentDate(); |
213 | QString str; | 213 | QString str; |
214 | str = QString("select uid from todolist where DueDate ='%1-%2-%3'").arg(date.year() ).arg(date.month() ).arg(date.day() ); | 214 | str = QString("select uid from todolist where DueDate ='%1-%2-%3'").arg(date.year() ).arg(date.month() ).arg(date.day() ); |
215 | 215 | ||
216 | return str; | 216 | return str; |
217 | } | 217 | } |
218 | 218 | ||
219 | 219 | ||
220 | EffQuery::EffQuery( const QDate& start, const QDate& end, bool inc ) | 220 | EffQuery::EffQuery( const QDate& start, const QDate& end, bool inc ) |
221 | : OSQLQuery(), m_start( start ), m_end( end ),m_inc(inc) {} | 221 | : OSQLQuery(), m_start( start ), m_end( end ),m_inc(inc) {} |
222 | EffQuery::~EffQuery() {} | 222 | EffQuery::~EffQuery() {} |
223 | QString EffQuery::query()const { | 223 | QString EffQuery::query()const { |
224 | return m_inc ? with() : out(); | 224 | return m_inc ? with() : out(); |
225 | } | 225 | } |
226 | QString EffQuery::with()const { | 226 | QString EffQuery::with()const { |
227 | QString str; | 227 | QString str; |
228 | str = QString("select uid from todolist where ( DueDate >= '%1-%2-%3' AND DueDate <= '%4-%5-%6' ) OR DueDate = '0-0-0' ") | 228 | str = QString("select uid from todolist where ( DueDate >= '%1-%2-%3' AND DueDate <= '%4-%5-%6' ) OR DueDate = '0-0-0' ") |
229 | .arg( m_start.year() ).arg( m_start.month() ).arg( m_start.day() ) | 229 | .arg( m_start.year() ).arg( m_start.month() ).arg( m_start.day() ) |
230 | .arg( m_end .year() ).arg( m_end .month() ).arg( m_end .day() ); | 230 | .arg( m_end .year() ).arg( m_end .month() ).arg( m_end .day() ); |
231 | return str; | 231 | return str; |
232 | } | 232 | } |
233 | QString EffQuery::out()const { | 233 | QString EffQuery::out()const { |
234 | QString str; | 234 | QString str; |
235 | str = QString("select uid from todolist where DueDate >= '%1-%2-%3' AND DueDate <= '%4-%5-%6'") | 235 | str = QString("select uid from todolist where DueDate >= '%1-%2-%3' AND DueDate <= '%4-%5-%6'") |
236 | .arg(m_start.year() ).arg(m_start.month() ).arg( m_start.day() ) | 236 | .arg(m_start.year() ).arg(m_start.month() ).arg( m_start.day() ) |
237 | .arg(m_end. year() ).arg(m_end. month() ).arg(m_end.day() ); | 237 | .arg(m_end. year() ).arg(m_end. month() ).arg(m_end.day() ); |
238 | 238 | ||
239 | return str; | 239 | return str; |
240 | } | 240 | } |
241 | }; | 241 | }; |
242 | 242 | ||
243 | OTodoAccessBackendSQL::OTodoAccessBackendSQL( const QString& file ) | 243 | OTodoAccessBackendSQL::OTodoAccessBackendSQL( const QString& file ) |
244 | : OTodoAccessBackend(), m_dict(15) | 244 | : OTodoAccessBackend(), m_dict(15), m_dirty(true) |
245 | { | 245 | { |
246 | QString fi = file; | 246 | QString fi = file; |
247 | if ( fi.isEmpty() ) | 247 | if ( fi.isEmpty() ) |
248 | fi = Global::applicationFileName( "todolist", "todolist.db" ); | 248 | fi = Global::applicationFileName( "todolist", "todolist.db" ); |
249 | OSQLManager man; | 249 | OSQLManager man; |
250 | m_driver = man.standard(); | 250 | m_driver = man.standard(); |
251 | m_driver->setUrl(fi); | 251 | m_driver->setUrl(fi); |
252 | fillDict(); | 252 | fillDict(); |
253 | } | 253 | } |
254 | 254 | ||
255 | OTodoAccessBackendSQL::~OTodoAccessBackendSQL(){ | 255 | OTodoAccessBackendSQL::~OTodoAccessBackendSQL(){ |
256 | } | 256 | } |
257 | bool OTodoAccessBackendSQL::load(){ | 257 | bool OTodoAccessBackendSQL::load(){ |
258 | if (!m_driver->open() ) | 258 | if (!m_driver->open() ) |
259 | return false; | 259 | return false; |
260 | 260 | ||
261 | CreateQuery creat; | 261 | CreateQuery creat; |
262 | OSQLResult res = m_driver->query(&creat ); | 262 | OSQLResult res = m_driver->query(&creat ); |
263 | 263 | ||
264 | update(); | 264 | m_dirty = true; |
265 | qWarning("loaded %d", m_uids.count() ); | ||
266 | return true; | 265 | return true; |
267 | } | 266 | } |
268 | bool OTodoAccessBackendSQL::reload(){ | 267 | bool OTodoAccessBackendSQL::reload(){ |
269 | return load(); | 268 | return load(); |
270 | } | 269 | } |
271 | 270 | ||
272 | bool OTodoAccessBackendSQL::save(){ | 271 | bool OTodoAccessBackendSQL::save(){ |
273 | return m_driver->close(); | 272 | return m_driver->close(); |
274 | } | 273 | } |
275 | QArray<int> OTodoAccessBackendSQL::allRecords()const { | 274 | QArray<int> OTodoAccessBackendSQL::allRecords()const { |
275 | if (m_dirty ) | ||
276 | update(); | ||
277 | |||
276 | return m_uids; | 278 | return m_uids; |
277 | } | 279 | } |
278 | QArray<int> OTodoAccessBackendSQL::queryByExample( const OTodo& , int ){ | 280 | QArray<int> OTodoAccessBackendSQL::queryByExample( const OTodo& , int ){ |
279 | QArray<int> ints(0); | 281 | QArray<int> ints(0); |
280 | return ints; | 282 | return ints; |
281 | } | 283 | } |
282 | OTodo OTodoAccessBackendSQL::find(int uid ) const{ | 284 | OTodo OTodoAccessBackendSQL::find(int uid ) const{ |
283 | FindQuery query( uid ); | 285 | FindQuery query( uid ); |
284 | return todo( m_driver->query(&query) ); | 286 | return todo( m_driver->query(&query) ); |
285 | 287 | ||
286 | } | 288 | } |
287 | OTodo OTodoAccessBackendSQL::find( int uid, const QArray<int>& ints, | 289 | OTodo OTodoAccessBackendSQL::find( int uid, const QArray<int>& ints, |
288 | uint cur, Frontend::CacheDirection dir ) const{ | 290 | uint cur, Frontend::CacheDirection dir ) const{ |
289 | qWarning("searching for %d", uid ); | 291 | qWarning("searching for %d", uid ); |
290 | QArray<int> search( 8 ); | 292 | QArray<int> search( 8 ); |
291 | uint size =0; | 293 | uint size =0; |
292 | OTodo to; | 294 | OTodo to; |
293 | 295 | ||
294 | // we try to cache 8 items | 296 | // we try to cache 8 items |
295 | switch( dir ) { | 297 | switch( dir ) { |
296 | /* forward */ | 298 | /* forward */ |
297 | case 0: | 299 | case 0: |
298 | for (uint i = cur; i < ints.count() && size < 8; i++ ) { | 300 | for (uint i = cur; i < ints.count() && size < 8; i++ ) { |
299 | qWarning("size %d %d", size, ints[i] ); | 301 | qWarning("size %d %d", size, ints[i] ); |
300 | search[size] = ints[i]; | 302 | search[size] = ints[i]; |
301 | size++; | 303 | size++; |
302 | } | 304 | } |
303 | break; | 305 | break; |
304 | /* reverse */ | 306 | /* reverse */ |
305 | case 1: | 307 | case 1: |
306 | for (uint i = cur; i >= 0 && size < 8; i-- ) { | 308 | for (uint i = cur; i != 0 && size < 8; i-- ) { |
307 | search[size] = ints[i]; | 309 | search[size] = ints[i]; |
308 | size++; | 310 | size++; |
309 | } | 311 | } |
310 | break; | 312 | break; |
311 | } | 313 | } |
312 | search.resize( size ); | 314 | search.resize( size ); |
313 | FindQuery query( search ); | 315 | FindQuery query( search ); |
314 | OSQLResult res = m_driver->query( &query ); | 316 | OSQLResult res = m_driver->query( &query ); |
315 | if ( res.state() != OSQLResult::Success ) | 317 | if ( res.state() != OSQLResult::Success ) |
316 | return to; | 318 | return to; |
317 | 319 | ||
318 | return todo( res ); | 320 | return todo( res ); |
319 | } | 321 | } |
320 | void OTodoAccessBackendSQL::clear() { | 322 | void OTodoAccessBackendSQL::clear() { |
321 | ClearQuery cle; | 323 | ClearQuery cle; |
322 | OSQLResult res = m_driver->query( &cle ); | 324 | OSQLResult res = m_driver->query( &cle ); |
323 | CreateQuery qu; | 325 | CreateQuery qu; |
324 | res = m_driver->query(&qu); | 326 | res = m_driver->query(&qu); |
325 | } | 327 | } |
326 | bool OTodoAccessBackendSQL::add( const OTodo& t) { | 328 | bool OTodoAccessBackendSQL::add( const OTodo& t) { |
327 | InsertQuery ins( t ); | 329 | InsertQuery ins( t ); |
328 | OSQLResult res = m_driver->query( &ins ); | 330 | OSQLResult res = m_driver->query( &ins ); |
329 | 331 | ||
330 | if ( res.state() == OSQLResult::Failure ) | 332 | if ( res.state() == OSQLResult::Failure ) |
331 | return false; | 333 | return false; |
332 | int c = m_uids.count(); | 334 | int c = m_uids.count(); |
333 | m_uids.resize( c+1 ); | 335 | m_uids.resize( c+1 ); |
334 | m_uids[c] = t.uid(); | 336 | m_uids[c] = t.uid(); |
335 | 337 | ||
336 | return true; | 338 | return true; |
337 | } | 339 | } |
338 | bool OTodoAccessBackendSQL::remove( int uid ) { | 340 | bool OTodoAccessBackendSQL::remove( int uid ) { |
339 | RemoveQuery rem( uid ); | 341 | RemoveQuery rem( uid ); |
340 | OSQLResult res = m_driver->query(&rem ); | 342 | OSQLResult res = m_driver->query(&rem ); |
341 | 343 | ||
342 | if ( res.state() == OSQLResult::Failure ) | 344 | if ( res.state() == OSQLResult::Failure ) |
343 | return false; | 345 | return false; |
344 | 346 | ||
345 | update(); | 347 | m_dirty = true; |
346 | return true; | 348 | return true; |
347 | } | 349 | } |
348 | /* | 350 | /* |
349 | * FIXME better set query | 351 | * FIXME better set query |
350 | * but we need the cache for that | 352 | * but we need the cache for that |
351 | * now we remove | 353 | * now we remove |
352 | */ | 354 | */ |
353 | bool OTodoAccessBackendSQL::replace( const OTodo& t) { | 355 | bool OTodoAccessBackendSQL::replace( const OTodo& t) { |
354 | remove( t.uid() ); | 356 | remove( t.uid() ); |
355 | return add(t); | 357 | bool b= add(t); |
358 | m_dirty = false; // we changed some stuff but the UID stayed the same | ||
359 | return b; | ||
356 | } | 360 | } |
357 | QArray<int> OTodoAccessBackendSQL::overDue() { | 361 | QArray<int> OTodoAccessBackendSQL::overDue() { |
358 | OverDueQuery qu; | 362 | OverDueQuery qu; |
359 | return uids( m_driver->query(&qu ) ); | 363 | return uids( m_driver->query(&qu ) ); |
360 | } | 364 | } |
361 | QArray<int> OTodoAccessBackendSQL::effectiveToDos( const QDate& s, | 365 | QArray<int> OTodoAccessBackendSQL::effectiveToDos( const QDate& s, |
362 | const QDate& t, | 366 | const QDate& t, |
363 | bool u) { | 367 | bool u) { |
364 | EffQuery ef(s, t, u ); | 368 | EffQuery ef(s, t, u ); |
365 | return uids (m_driver->query(&ef) ); | 369 | return uids (m_driver->query(&ef) ); |
366 | } | 370 | } |
367 | /* | 371 | /* |
368 | * | 372 | * |
369 | */ | 373 | */ |
370 | QArray<int> OTodoAccessBackendSQL::sorted( bool asc, int sortOrder, | 374 | QArray<int> OTodoAccessBackendSQL::sorted( bool asc, int sortOrder, |
371 | int sortFilter, int cat ) { | 375 | int sortFilter, int cat ) { |
376 | qWarning("sorted %d, %d", asc, sortOrder ); | ||
372 | QString query; | 377 | QString query; |
373 | query = "select uid from todolist WHERE "; | 378 | query = "select uid from todolist WHERE "; |
374 | 379 | ||
375 | /* | 380 | /* |
376 | * Sort Filter stuff | 381 | * Sort Filter stuff |
377 | * not that straight forward | 382 | * not that straight forward |
378 | * | 383 | * |
379 | */ | 384 | */ |
380 | /* Category */ | 385 | /* Category */ |
381 | if ( sortFilter & 1 ) { | 386 | if ( sortFilter & 1 ) { |
382 | QString str; | 387 | QString str; |
383 | if (cat != 0 ) str = QString::number( cat ); | 388 | if (cat != 0 ) str = QString::number( cat ); |
384 | query += " categories like '%" +str+"%' AND"; | 389 | query += " categories like '%" +str+"%' AND"; |
385 | } | 390 | } |
386 | /* Show only overdue */ | 391 | /* Show only overdue */ |
387 | if ( sortFilter & 2 ) { | 392 | if ( sortFilter & 2 ) { |
388 | QDate date = QDate::currentDate(); | 393 | QDate date = QDate::currentDate(); |
389 | QString due; | 394 | QString due; |
390 | QString base; | 395 | QString base; |
391 | base = QString("DueDate <= '%1-%2-%3' AND completed = 0").arg( date.year() ).arg( date.month() ).arg( date.day() ); | 396 | base = QString("DueDate <= '%1-%2-%3' AND completed = 0").arg( date.year() ).arg( date.month() ).arg( date.day() ); |
392 | query += " " + base + " AND"; | 397 | query += " " + base + " AND"; |
393 | } | 398 | } |
394 | /* not show completed */ | 399 | /* not show completed */ |
395 | if ( sortFilter & 4 ) { | 400 | if ( sortFilter & 4 ) { |
396 | query += " completed = 0 AND"; | 401 | query += " completed = 0 AND"; |
397 | }else{ | 402 | }else{ |
398 | query += " ( completed = 1 OR completed = 0) AND"; | 403 | query += " ( completed = 1 OR completed = 0) AND"; |
399 | } | 404 | } |
400 | /* srtip the end */ | 405 | /* srtip the end */ |
401 | query = query.remove( query.length()-3, 3 ); | 406 | query = query.remove( query.length()-3, 3 ); |
402 | 407 | ||
403 | 408 | ||
404 | /* | 409 | /* |
405 | * sort order stuff | 410 | * sort order stuff |
406 | * quite straight forward | 411 | * quite straight forward |
407 | */ | 412 | */ |
408 | query += "ORDER BY "; | 413 | query += "ORDER BY "; |
409 | switch( sortOrder ) { | 414 | switch( sortOrder ) { |
410 | /* completed */ | 415 | /* completed */ |
411 | case 0: | 416 | case 0: |
412 | query += "completed"; | 417 | query += "completed"; |
413 | break; | 418 | break; |
414 | case 1: | 419 | case 1: |
415 | query += "priority"; | 420 | query += "priority"; |
416 | break; | 421 | break; |
417 | case 2: | 422 | case 2: |
418 | query += "description"; | 423 | query += "description"; |
419 | break; | 424 | break; |
420 | case 3: | 425 | case 3: |
421 | query += "DueDate"; | 426 | query += "DueDate"; |
422 | break; | 427 | break; |
423 | } | 428 | } |
424 | if ( !asc ) | 429 | |
430 | if ( !asc ) { | ||
431 | qWarning("not ascending!"); | ||
425 | query += " DESC"; | 432 | query += " DESC"; |
433 | } | ||
426 | 434 | ||
427 | qWarning( query ); | 435 | qWarning( query ); |
428 | OSQLRawQuery raw(query ); | 436 | OSQLRawQuery raw(query ); |
429 | return uids( m_driver->query(&raw) ); | 437 | return uids( m_driver->query(&raw) ); |
430 | } | 438 | } |
431 | bool OTodoAccessBackendSQL::date( QDate& da, const QString& str ) const{ | 439 | bool OTodoAccessBackendSQL::date( QDate& da, const QString& str ) const{ |
432 | if ( str == "0-0-0" ) | 440 | if ( str == "0-0-0" ) |
433 | return false; | 441 | return false; |
434 | else{ | 442 | else{ |
435 | int day, year, month; | 443 | int day, year, month; |
436 | QStringList list = QStringList::split("-", str ); | 444 | QStringList list = QStringList::split("-", str ); |
437 | year = list[0].toInt(); | 445 | year = list[0].toInt(); |
438 | month = list[1].toInt(); | 446 | month = list[1].toInt(); |
439 | day = list[2].toInt(); | 447 | day = list[2].toInt(); |
440 | da.setYMD( year, month, day ); | 448 | da.setYMD( year, month, day ); |
441 | return true; | 449 | return true; |
442 | } | 450 | } |
443 | } | 451 | } |
444 | OTodo OTodoAccessBackendSQL::todo( const OSQLResult& res) const{ | 452 | OTodo OTodoAccessBackendSQL::todo( const OSQLResult& res) const{ |
445 | if ( res.state() == OSQLResult::Failure ) { | 453 | if ( res.state() == OSQLResult::Failure ) { |
446 | OTodo to; | 454 | OTodo to; |
447 | return to; | 455 | return to; |
448 | } | 456 | } |
449 | 457 | ||
450 | OSQLResultItem::ValueList list = res.results(); | 458 | OSQLResultItem::ValueList list = res.results(); |
451 | OSQLResultItem::ValueList::Iterator it = list.begin(); | 459 | OSQLResultItem::ValueList::Iterator it = list.begin(); |
452 | qWarning("todo1"); | 460 | qWarning("todo1"); |
453 | OTodo to = todo( (*it) ); | 461 | OTodo to = todo( (*it) ); |
454 | cache( to ); | 462 | cache( to ); |
455 | ++it; | 463 | ++it; |
456 | 464 | ||
457 | for ( ; it != list.end(); ++it ) { | 465 | for ( ; it != list.end(); ++it ) { |
458 | qWarning("caching"); | 466 | qWarning("caching"); |
459 | cache( todo( (*it) ) ); | 467 | cache( todo( (*it) ) ); |
460 | } | 468 | } |
461 | return to; | 469 | return to; |
462 | } | 470 | } |
463 | OTodo OTodoAccessBackendSQL::todo( OSQLResultItem& item )const { | 471 | OTodo OTodoAccessBackendSQL::todo( OSQLResultItem& item )const { |
464 | qWarning("todo"); | 472 | qWarning("todo"); |
465 | bool has = false; QDate da = QDate::currentDate(); | 473 | bool has = false; QDate da = QDate::currentDate(); |
466 | has = date( da, item.data("DueDate") ); | 474 | has = date( da, item.data("DueDate") ); |
467 | QStringList cats = QStringList::split(";", item.data("categories") ); | 475 | QStringList cats = QStringList::split(";", item.data("categories") ); |
468 | 476 | ||
469 | OTodo to( (bool)item.data("completed").toInt(), item.data("priority").toInt(), | 477 | OTodo to( (bool)item.data("completed").toInt(), item.data("priority").toInt(), |
470 | cats, item.data("summary"), item.data("description"), | 478 | cats, item.data("summary"), item.data("description"), |
471 | item.data("progress").toUShort(), has, da, | 479 | item.data("progress").toUShort(), has, da, |
472 | item.data("uid").toInt() ); | 480 | item.data("uid").toInt() ); |
473 | return to; | 481 | return to; |
474 | } | 482 | } |
475 | OTodo OTodoAccessBackendSQL::todo( int uid )const { | 483 | OTodo OTodoAccessBackendSQL::todo( int uid )const { |
476 | FindQuery find( uid ); | 484 | FindQuery find( uid ); |
477 | return todo( m_driver->query(&find) ); | 485 | return todo( m_driver->query(&find) ); |
478 | } | 486 | } |
479 | /* | 487 | /* |
480 | * update the dict | 488 | * update the dict |
481 | */ | 489 | */ |
482 | void OTodoAccessBackendSQL::fillDict() { | 490 | void OTodoAccessBackendSQL::fillDict() { |
483 | /* initialize dict */ | 491 | /* initialize dict */ |
484 | /* | 492 | /* |
485 | * UPDATE dict if you change anything!!! | 493 | * UPDATE dict if you change anything!!! |
486 | */ | 494 | */ |
487 | m_dict.setAutoDelete( TRUE ); | 495 | m_dict.setAutoDelete( TRUE ); |
488 | m_dict.insert("Categories" , new int(OTodo::Category) ); | 496 | m_dict.insert("Categories" , new int(OTodo::Category) ); |
489 | m_dict.insert("Uid" , new int(OTodo::Uid) ); | 497 | m_dict.insert("Uid" , new int(OTodo::Uid) ); |
490 | m_dict.insert("HasDate" , new int(OTodo::HasDate) ); | 498 | m_dict.insert("HasDate" , new int(OTodo::HasDate) ); |
491 | m_dict.insert("Completed" , new int(OTodo::Completed) ); | 499 | m_dict.insert("Completed" , new int(OTodo::Completed) ); |
492 | m_dict.insert("Description" , new int(OTodo::Description) ); | 500 | m_dict.insert("Description" , new int(OTodo::Description) ); |
493 | m_dict.insert("Summary" , new int(OTodo::Summary) ); | 501 | m_dict.insert("Summary" , new int(OTodo::Summary) ); |
494 | m_dict.insert("Priority" , new int(OTodo::Priority) ); | 502 | m_dict.insert("Priority" , new int(OTodo::Priority) ); |
495 | m_dict.insert("DateDay" , new int(OTodo::DateDay) ); | 503 | m_dict.insert("DateDay" , new int(OTodo::DateDay) ); |
496 | m_dict.insert("DateMonth" , new int(OTodo::DateMonth) ); | 504 | m_dict.insert("DateMonth" , new int(OTodo::DateMonth) ); |
497 | m_dict.insert("DateYear" , new int(OTodo::DateYear) ); | 505 | m_dict.insert("DateYear" , new int(OTodo::DateYear) ); |
498 | m_dict.insert("Progress" , new int(OTodo::Progress) ); | 506 | m_dict.insert("Progress" , new int(OTodo::Progress) ); |
499 | m_dict.insert("Completed", new int(OTodo::Completed) ); | 507 | m_dict.insert("Completed", new int(OTodo::Completed) ); |
500 | m_dict.insert("CrossReference", new int(OTodo::CrossReference) ); | 508 | m_dict.insert("CrossReference", new int(OTodo::CrossReference) ); |
501 | m_dict.insert("HasAlarmDateTime",new int(OTodo::HasAlarmDateTime) ); | 509 | m_dict.insert("HasAlarmDateTime",new int(OTodo::HasAlarmDateTime) ); |
502 | m_dict.insert("AlarmDateTime", new int(OTodo::AlarmDateTime) ); | 510 | m_dict.insert("AlarmDateTime", new int(OTodo::AlarmDateTime) ); |
503 | } | 511 | } |
504 | void OTodoAccessBackendSQL::update() { | 512 | /* |
513 | * need to be const so let's fool the | ||
514 | * compiler :( | ||
515 | */ | ||
516 | void OTodoAccessBackendSQL::update()const { | ||
517 | ((OTodoAccessBackendSQL*)this)->m_dirty = false; | ||
505 | LoadQuery lo; | 518 | LoadQuery lo; |
506 | OSQLResult res = m_driver->query(&lo); | 519 | OSQLResult res = m_driver->query(&lo); |
507 | if ( res.state() != OSQLResult::Success ) | 520 | if ( res.state() != OSQLResult::Success ) |
508 | return; | 521 | return; |
509 | 522 | ||
510 | m_uids = uids( res ); | 523 | ((OTodoAccessBackendSQL*)this)->m_uids = uids( res ); |
511 | } | 524 | } |
512 | QArray<int> OTodoAccessBackendSQL::uids( const OSQLResult& res) const{ | 525 | QArray<int> OTodoAccessBackendSQL::uids( const OSQLResult& res) const{ |
513 | 526 | ||
514 | OSQLResultItem::ValueList list = res.results(); | 527 | OSQLResultItem::ValueList list = res.results(); |
515 | OSQLResultItem::ValueList::Iterator it; | 528 | OSQLResultItem::ValueList::Iterator it; |
516 | QArray<int> ints(list.count() ); | 529 | QArray<int> ints(list.count() ); |
517 | qWarning(" count = %d", list.count() ); | 530 | qWarning(" count = %d", list.count() ); |
518 | 531 | ||
519 | int i = 0; | 532 | int i = 0; |
520 | for (it = list.begin(); it != list.end(); ++it ) { | 533 | for (it = list.begin(); it != list.end(); ++it ) { |
521 | ints[i] = (*it).data("uid").toInt(); | 534 | ints[i] = (*it).data("uid").toInt(); |
522 | i++; | 535 | i++; |
523 | } | 536 | } |
524 | return ints; | 537 | return ints; |
525 | } | 538 | } |
526 | 539 | ||
diff --git a/libopie/pim/otodoaccesssql.h b/libopie/pim/otodoaccesssql.h index c1aa2ed..0f6dd2c 100644 --- a/libopie/pim/otodoaccesssql.h +++ b/libopie/pim/otodoaccesssql.h | |||
@@ -1,49 +1,50 @@ | |||
1 | #ifndef OPIE_PIM_ACCESS_SQL_H | 1 | #ifndef OPIE_PIM_ACCESS_SQL_H |
2 | #define OPIE_PIM_ACCESS_SQL_H | 2 | #define OPIE_PIM_ACCESS_SQL_H |
3 | 3 | ||
4 | #include <qasciidict.h> | 4 | #include <qasciidict.h> |
5 | 5 | ||
6 | #include "otodoaccessbackend.h" | 6 | #include "otodoaccessbackend.h" |
7 | 7 | ||
8 | class OSQLDriver; | 8 | class OSQLDriver; |
9 | class OSQLResult; | 9 | class OSQLResult; |
10 | class OSQLResultItem; | 10 | class OSQLResultItem; |
11 | class OTodoAccessBackendSQL : public OTodoAccessBackend { | 11 | class OTodoAccessBackendSQL : public OTodoAccessBackend { |
12 | public: | 12 | public: |
13 | OTodoAccessBackendSQL( const QString& file ); | 13 | OTodoAccessBackendSQL( const QString& file ); |
14 | ~OTodoAccessBackendSQL(); | 14 | ~OTodoAccessBackendSQL(); |
15 | 15 | ||
16 | bool load(); | 16 | bool load(); |
17 | bool reload(); | 17 | bool reload(); |
18 | bool save(); | 18 | bool save(); |
19 | QArray<int> allRecords()const; | 19 | QArray<int> allRecords()const; |
20 | 20 | ||
21 | QArray<int> queryByExample( const OTodo& t, int sort ); | 21 | QArray<int> queryByExample( const OTodo& t, int sort ); |
22 | OTodo find(int uid)const; | 22 | OTodo find(int uid)const; |
23 | OTodo find(int uid, const QArray<int>&, uint cur, Frontend::CacheDirection )const; | 23 | OTodo find(int uid, const QArray<int>&, uint cur, Frontend::CacheDirection )const; |
24 | void clear(); | 24 | void clear(); |
25 | bool add( const OTodo& t ); | 25 | bool add( const OTodo& t ); |
26 | bool remove( int uid ); | 26 | bool remove( int uid ); |
27 | bool replace( const OTodo& t ); | 27 | bool replace( const OTodo& t ); |
28 | 28 | ||
29 | QArray<int> overDue(); | 29 | QArray<int> overDue(); |
30 | QArray<int> effectiveToDos( const QDate& start, | 30 | QArray<int> effectiveToDos( const QDate& start, |
31 | const QDate& end, bool includeNoDates ); | 31 | const QDate& end, bool includeNoDates ); |
32 | QArray<int> sorted(bool asc, int sortOrder, int sortFilter, int cat ); | 32 | QArray<int> sorted(bool asc, int sortOrder, int sortFilter, int cat ); |
33 | 33 | ||
34 | private: | 34 | private: |
35 | void update(); | 35 | void update()const; |
36 | void fillDict(); | 36 | void fillDict(); |
37 | inline bool date( QDate& date, const QString& )const; | 37 | inline bool date( QDate& date, const QString& )const; |
38 | inline OTodo todo( const OSQLResult& )const; | 38 | inline OTodo todo( const OSQLResult& )const; |
39 | inline OTodo todo( OSQLResultItem& )const; | 39 | inline OTodo todo( OSQLResultItem& )const; |
40 | inline QArray<int> uids( const OSQLResult& )const; | 40 | inline QArray<int> uids( const OSQLResult& )const; |
41 | OTodo todo( int uid )const; | 41 | OTodo todo( int uid )const; |
42 | 42 | ||
43 | QAsciiDict<int> m_dict; | 43 | QAsciiDict<int> m_dict; |
44 | OSQLDriver* m_driver; | 44 | OSQLDriver* m_driver; |
45 | QArray<int> m_uids; | 45 | QArray<int> m_uids; |
46 | bool m_dirty : 1; | ||
46 | }; | 47 | }; |
47 | 48 | ||
48 | 49 | ||
49 | #endif | 50 | #endif |
diff --git a/libopie2/opiepim/backend/otodoaccesssql.cpp b/libopie2/opiepim/backend/otodoaccesssql.cpp index a059dab..ea8b3c9 100644 --- a/libopie2/opiepim/backend/otodoaccesssql.cpp +++ b/libopie2/opiepim/backend/otodoaccesssql.cpp | |||
@@ -52,475 +52,488 @@ namespace { | |||
52 | OTodo m_todo; | 52 | OTodo m_todo; |
53 | }; | 53 | }; |
54 | 54 | ||
55 | /** | 55 | /** |
56 | * removes one from the table | 56 | * removes one from the table |
57 | */ | 57 | */ |
58 | class RemoveQuery : public OSQLQuery { | 58 | class RemoveQuery : public OSQLQuery { |
59 | public: | 59 | public: |
60 | RemoveQuery(int uid ); | 60 | RemoveQuery(int uid ); |
61 | ~RemoveQuery(); | 61 | ~RemoveQuery(); |
62 | QString query()const; | 62 | QString query()const; |
63 | private: | 63 | private: |
64 | int m_uid; | 64 | int m_uid; |
65 | }; | 65 | }; |
66 | 66 | ||
67 | /** | 67 | /** |
68 | * Clears (delete) a Table | 68 | * Clears (delete) a Table |
69 | */ | 69 | */ |
70 | class ClearQuery : public OSQLQuery { | 70 | class ClearQuery : public OSQLQuery { |
71 | public: | 71 | public: |
72 | ClearQuery(); | 72 | ClearQuery(); |
73 | ~ClearQuery(); | 73 | ~ClearQuery(); |
74 | QString query()const; | 74 | QString query()const; |
75 | 75 | ||
76 | }; | 76 | }; |
77 | 77 | ||
78 | /** | 78 | /** |
79 | * a find query | 79 | * a find query |
80 | */ | 80 | */ |
81 | class FindQuery : public OSQLQuery { | 81 | class FindQuery : public OSQLQuery { |
82 | public: | 82 | public: |
83 | FindQuery(int uid); | 83 | FindQuery(int uid); |
84 | FindQuery(const QArray<int>& ); | 84 | FindQuery(const QArray<int>& ); |
85 | ~FindQuery(); | 85 | ~FindQuery(); |
86 | QString query()const; | 86 | QString query()const; |
87 | private: | 87 | private: |
88 | QString single()const; | 88 | QString single()const; |
89 | QString multi()const; | 89 | QString multi()const; |
90 | QArray<int> m_uids; | 90 | QArray<int> m_uids; |
91 | int m_uid; | 91 | int m_uid; |
92 | }; | 92 | }; |
93 | 93 | ||
94 | /** | 94 | /** |
95 | * overdue query | 95 | * overdue query |
96 | */ | 96 | */ |
97 | class OverDueQuery : public OSQLQuery { | 97 | class OverDueQuery : public OSQLQuery { |
98 | public: | 98 | public: |
99 | OverDueQuery(); | 99 | OverDueQuery(); |
100 | ~OverDueQuery(); | 100 | ~OverDueQuery(); |
101 | QString query()const; | 101 | QString query()const; |
102 | }; | 102 | }; |
103 | class EffQuery : public OSQLQuery { | 103 | class EffQuery : public OSQLQuery { |
104 | public: | 104 | public: |
105 | EffQuery( const QDate&, const QDate&, bool inc ); | 105 | EffQuery( const QDate&, const QDate&, bool inc ); |
106 | ~EffQuery(); | 106 | ~EffQuery(); |
107 | QString query()const; | 107 | QString query()const; |
108 | private: | 108 | private: |
109 | QString with()const; | 109 | QString with()const; |
110 | QString out()const; | 110 | QString out()const; |
111 | QDate m_start; | 111 | QDate m_start; |
112 | QDate m_end; | 112 | QDate m_end; |
113 | bool m_inc :1; | 113 | bool m_inc :1; |
114 | }; | 114 | }; |
115 | 115 | ||
116 | 116 | ||
117 | CreateQuery::CreateQuery() : OSQLQuery() {} | 117 | CreateQuery::CreateQuery() : OSQLQuery() {} |
118 | CreateQuery::~CreateQuery() {} | 118 | CreateQuery::~CreateQuery() {} |
119 | QString CreateQuery::query()const { | 119 | QString CreateQuery::query()const { |
120 | QString qu; | 120 | QString qu; |
121 | qu += "create table todolist( uid, categories, completed, progress, "; | 121 | qu += "create table todolist( uid, categories, completed, progress, "; |
122 | qu += "summary, DueDate, priority, description )"; | 122 | qu += "summary, DueDate, priority, description )"; |
123 | return qu; | 123 | return qu; |
124 | } | 124 | } |
125 | 125 | ||
126 | LoadQuery::LoadQuery() : OSQLQuery() {} | 126 | LoadQuery::LoadQuery() : OSQLQuery() {} |
127 | LoadQuery::~LoadQuery() {} | 127 | LoadQuery::~LoadQuery() {} |
128 | QString LoadQuery::query()const { | 128 | QString LoadQuery::query()const { |
129 | QString qu; | 129 | QString qu; |
130 | qu += "select distinct uid from todolist"; | 130 | qu += "select distinct uid from todolist"; |
131 | 131 | ||
132 | return qu; | 132 | return qu; |
133 | } | 133 | } |
134 | 134 | ||
135 | InsertQuery::InsertQuery( const OTodo& todo ) | 135 | InsertQuery::InsertQuery( const OTodo& todo ) |
136 | : OSQLQuery(), m_todo( todo ) { | 136 | : OSQLQuery(), m_todo( todo ) { |
137 | } | 137 | } |
138 | InsertQuery::~InsertQuery() { | 138 | InsertQuery::~InsertQuery() { |
139 | } | 139 | } |
140 | /* | 140 | /* |
141 | * converts from a OTodo to a query | 141 | * converts from a OTodo to a query |
142 | * we leave out X-Ref + Alarms | 142 | * we leave out X-Ref + Alarms |
143 | */ | 143 | */ |
144 | QString InsertQuery::query()const{ | 144 | QString InsertQuery::query()const{ |
145 | 145 | ||
146 | int year, month, day; | 146 | int year, month, day; |
147 | year = month = day = 0; | 147 | year = month = day = 0; |
148 | if (m_todo.hasDueDate() ) { | 148 | if (m_todo.hasDueDate() ) { |
149 | QDate date = m_todo.dueDate(); | 149 | QDate date = m_todo.dueDate(); |
150 | year = date.year(); | 150 | year = date.year(); |
151 | month = date.month(); | 151 | month = date.month(); |
152 | day = date.day(); | 152 | day = date.day(); |
153 | } | 153 | } |
154 | QString qu; | 154 | QString qu; |
155 | qu = "insert into todolist VALUES(" + QString::number( m_todo.uid() ) + ",'" + m_todo.idsToString( m_todo.categories() ) + "',"; | 155 | qu = "insert into todolist VALUES(" + QString::number( m_todo.uid() ) + ",'" + m_todo.idsToString( m_todo.categories() ) + "',"; |
156 | qu += QString::number( m_todo.isCompleted() ) + "," + QString::number( m_todo.progress() ) + ","; | 156 | qu += QString::number( m_todo.isCompleted() ) + "," + QString::number( m_todo.progress() ) + ","; |
157 | qu += "'"+m_todo.summary()+"','"+QString::number(year)+"-"+QString::number(month)+"-"+QString::number(day)+"',"; | 157 | qu += "'"+m_todo.summary()+"','"+QString::number(year)+"-"+QString::number(month)+"-"+QString::number(day)+"',"; |
158 | qu += QString::number(m_todo.priority() ) +",'" + m_todo.description() + "')"; | 158 | qu += QString::number(m_todo.priority() ) +",'" + m_todo.description() + "')"; |
159 | 159 | ||
160 | qWarning("add %s", qu.latin1() ); | 160 | qWarning("add %s", qu.latin1() ); |
161 | return qu; | 161 | return qu; |
162 | } | 162 | } |
163 | 163 | ||
164 | RemoveQuery::RemoveQuery(int uid ) | 164 | RemoveQuery::RemoveQuery(int uid ) |
165 | : OSQLQuery(), m_uid( uid ) {} | 165 | : OSQLQuery(), m_uid( uid ) {} |
166 | RemoveQuery::~RemoveQuery() {} | 166 | RemoveQuery::~RemoveQuery() {} |
167 | QString RemoveQuery::query()const { | 167 | QString RemoveQuery::query()const { |
168 | QString qu = "DELETE from todolist where uid = " + QString::number(m_uid); | 168 | QString qu = "DELETE from todolist where uid = " + QString::number(m_uid); |
169 | return qu; | 169 | return qu; |
170 | } | 170 | } |
171 | 171 | ||
172 | 172 | ||
173 | ClearQuery::ClearQuery() | 173 | ClearQuery::ClearQuery() |
174 | : OSQLQuery() {} | 174 | : OSQLQuery() {} |
175 | ClearQuery::~ClearQuery() {} | 175 | ClearQuery::~ClearQuery() {} |
176 | QString ClearQuery::query()const { | 176 | QString ClearQuery::query()const { |
177 | QString qu = "drop table todolist"; | 177 | QString qu = "drop table todolist"; |
178 | return qu; | 178 | return qu; |
179 | } | 179 | } |
180 | FindQuery::FindQuery(int uid) | 180 | FindQuery::FindQuery(int uid) |
181 | : OSQLQuery(), m_uid(uid ) { | 181 | : OSQLQuery(), m_uid(uid ) { |
182 | } | 182 | } |
183 | FindQuery::FindQuery(const QArray<int>& ints) | 183 | FindQuery::FindQuery(const QArray<int>& ints) |
184 | : OSQLQuery(), m_uids(ints){ | 184 | : OSQLQuery(), m_uids(ints){ |
185 | } | 185 | } |
186 | FindQuery::~FindQuery() { | 186 | FindQuery::~FindQuery() { |
187 | } | 187 | } |
188 | QString FindQuery::query()const{ | 188 | QString FindQuery::query()const{ |
189 | if (m_uids.count() == 0 ) | 189 | if (m_uids.count() == 0 ) |
190 | return single(); | 190 | return single(); |
191 | else | 191 | else |
192 | return multi(); | 192 | return multi(); |
193 | } | 193 | } |
194 | QString FindQuery::single()const{ | 194 | QString FindQuery::single()const{ |
195 | QString qu = "select uid, categories, completed, progress, summary, "; | 195 | QString qu = "select uid, categories, completed, progress, summary, "; |
196 | qu += "DueDate, priority, description from todolist where uid = " + QString::number(m_uid); | 196 | qu += "DueDate, priority, description from todolist where uid = " + QString::number(m_uid); |
197 | return qu; | 197 | return qu; |
198 | } | 198 | } |
199 | QString FindQuery::multi()const { | 199 | QString FindQuery::multi()const { |
200 | QString qu = "select uid, categories, completed, progress, summary, "; | 200 | QString qu = "select uid, categories, completed, progress, summary, "; |
201 | qu += "DueDate, priority, description from todolist where "; | 201 | qu += "DueDate, priority, description from todolist where "; |
202 | for (uint i = 0; i < m_uids.count(); i++ ) { | 202 | for (uint i = 0; i < m_uids.count(); i++ ) { |
203 | qu += " UID = " + QString::number( m_uids[i] ) + " OR"; | 203 | qu += " UID = " + QString::number( m_uids[i] ) + " OR"; |
204 | } | 204 | } |
205 | qu.remove( qu.length()-2, 2 ); | 205 | qu.remove( qu.length()-2, 2 ); |
206 | return qu; | 206 | return qu; |
207 | } | 207 | } |
208 | 208 | ||
209 | OverDueQuery::OverDueQuery(): OSQLQuery() {} | 209 | OverDueQuery::OverDueQuery(): OSQLQuery() {} |
210 | OverDueQuery::~OverDueQuery() {} | 210 | OverDueQuery::~OverDueQuery() {} |
211 | QString OverDueQuery::query()const { | 211 | QString OverDueQuery::query()const { |
212 | QDate date = QDate::currentDate(); | 212 | QDate date = QDate::currentDate(); |
213 | QString str; | 213 | QString str; |
214 | str = QString("select uid from todolist where DueDate ='%1-%2-%3'").arg(date.year() ).arg(date.month() ).arg(date.day() ); | 214 | str = QString("select uid from todolist where DueDate ='%1-%2-%3'").arg(date.year() ).arg(date.month() ).arg(date.day() ); |
215 | 215 | ||
216 | return str; | 216 | return str; |
217 | } | 217 | } |
218 | 218 | ||
219 | 219 | ||
220 | EffQuery::EffQuery( const QDate& start, const QDate& end, bool inc ) | 220 | EffQuery::EffQuery( const QDate& start, const QDate& end, bool inc ) |
221 | : OSQLQuery(), m_start( start ), m_end( end ),m_inc(inc) {} | 221 | : OSQLQuery(), m_start( start ), m_end( end ),m_inc(inc) {} |
222 | EffQuery::~EffQuery() {} | 222 | EffQuery::~EffQuery() {} |
223 | QString EffQuery::query()const { | 223 | QString EffQuery::query()const { |
224 | return m_inc ? with() : out(); | 224 | return m_inc ? with() : out(); |
225 | } | 225 | } |
226 | QString EffQuery::with()const { | 226 | QString EffQuery::with()const { |
227 | QString str; | 227 | QString str; |
228 | str = QString("select uid from todolist where ( DueDate >= '%1-%2-%3' AND DueDate <= '%4-%5-%6' ) OR DueDate = '0-0-0' ") | 228 | str = QString("select uid from todolist where ( DueDate >= '%1-%2-%3' AND DueDate <= '%4-%5-%6' ) OR DueDate = '0-0-0' ") |
229 | .arg( m_start.year() ).arg( m_start.month() ).arg( m_start.day() ) | 229 | .arg( m_start.year() ).arg( m_start.month() ).arg( m_start.day() ) |
230 | .arg( m_end .year() ).arg( m_end .month() ).arg( m_end .day() ); | 230 | .arg( m_end .year() ).arg( m_end .month() ).arg( m_end .day() ); |
231 | return str; | 231 | return str; |
232 | } | 232 | } |
233 | QString EffQuery::out()const { | 233 | QString EffQuery::out()const { |
234 | QString str; | 234 | QString str; |
235 | str = QString("select uid from todolist where DueDate >= '%1-%2-%3' AND DueDate <= '%4-%5-%6'") | 235 | str = QString("select uid from todolist where DueDate >= '%1-%2-%3' AND DueDate <= '%4-%5-%6'") |
236 | .arg(m_start.year() ).arg(m_start.month() ).arg( m_start.day() ) | 236 | .arg(m_start.year() ).arg(m_start.month() ).arg( m_start.day() ) |
237 | .arg(m_end. year() ).arg(m_end. month() ).arg(m_end.day() ); | 237 | .arg(m_end. year() ).arg(m_end. month() ).arg(m_end.day() ); |
238 | 238 | ||
239 | return str; | 239 | return str; |
240 | } | 240 | } |
241 | }; | 241 | }; |
242 | 242 | ||
243 | OTodoAccessBackendSQL::OTodoAccessBackendSQL( const QString& file ) | 243 | OTodoAccessBackendSQL::OTodoAccessBackendSQL( const QString& file ) |
244 | : OTodoAccessBackend(), m_dict(15) | 244 | : OTodoAccessBackend(), m_dict(15), m_dirty(true) |
245 | { | 245 | { |
246 | QString fi = file; | 246 | QString fi = file; |
247 | if ( fi.isEmpty() ) | 247 | if ( fi.isEmpty() ) |
248 | fi = Global::applicationFileName( "todolist", "todolist.db" ); | 248 | fi = Global::applicationFileName( "todolist", "todolist.db" ); |
249 | OSQLManager man; | 249 | OSQLManager man; |
250 | m_driver = man.standard(); | 250 | m_driver = man.standard(); |
251 | m_driver->setUrl(fi); | 251 | m_driver->setUrl(fi); |
252 | fillDict(); | 252 | fillDict(); |
253 | } | 253 | } |
254 | 254 | ||
255 | OTodoAccessBackendSQL::~OTodoAccessBackendSQL(){ | 255 | OTodoAccessBackendSQL::~OTodoAccessBackendSQL(){ |
256 | } | 256 | } |
257 | bool OTodoAccessBackendSQL::load(){ | 257 | bool OTodoAccessBackendSQL::load(){ |
258 | if (!m_driver->open() ) | 258 | if (!m_driver->open() ) |
259 | return false; | 259 | return false; |
260 | 260 | ||
261 | CreateQuery creat; | 261 | CreateQuery creat; |
262 | OSQLResult res = m_driver->query(&creat ); | 262 | OSQLResult res = m_driver->query(&creat ); |
263 | 263 | ||
264 | update(); | 264 | m_dirty = true; |
265 | qWarning("loaded %d", m_uids.count() ); | ||
266 | return true; | 265 | return true; |
267 | } | 266 | } |
268 | bool OTodoAccessBackendSQL::reload(){ | 267 | bool OTodoAccessBackendSQL::reload(){ |
269 | return load(); | 268 | return load(); |
270 | } | 269 | } |
271 | 270 | ||
272 | bool OTodoAccessBackendSQL::save(){ | 271 | bool OTodoAccessBackendSQL::save(){ |
273 | return m_driver->close(); | 272 | return m_driver->close(); |
274 | } | 273 | } |
275 | QArray<int> OTodoAccessBackendSQL::allRecords()const { | 274 | QArray<int> OTodoAccessBackendSQL::allRecords()const { |
275 | if (m_dirty ) | ||
276 | update(); | ||
277 | |||
276 | return m_uids; | 278 | return m_uids; |
277 | } | 279 | } |
278 | QArray<int> OTodoAccessBackendSQL::queryByExample( const OTodo& , int ){ | 280 | QArray<int> OTodoAccessBackendSQL::queryByExample( const OTodo& , int ){ |
279 | QArray<int> ints(0); | 281 | QArray<int> ints(0); |
280 | return ints; | 282 | return ints; |
281 | } | 283 | } |
282 | OTodo OTodoAccessBackendSQL::find(int uid ) const{ | 284 | OTodo OTodoAccessBackendSQL::find(int uid ) const{ |
283 | FindQuery query( uid ); | 285 | FindQuery query( uid ); |
284 | return todo( m_driver->query(&query) ); | 286 | return todo( m_driver->query(&query) ); |
285 | 287 | ||
286 | } | 288 | } |
287 | OTodo OTodoAccessBackendSQL::find( int uid, const QArray<int>& ints, | 289 | OTodo OTodoAccessBackendSQL::find( int uid, const QArray<int>& ints, |
288 | uint cur, Frontend::CacheDirection dir ) const{ | 290 | uint cur, Frontend::CacheDirection dir ) const{ |
289 | qWarning("searching for %d", uid ); | 291 | qWarning("searching for %d", uid ); |
290 | QArray<int> search( 8 ); | 292 | QArray<int> search( 8 ); |
291 | uint size =0; | 293 | uint size =0; |
292 | OTodo to; | 294 | OTodo to; |
293 | 295 | ||
294 | // we try to cache 8 items | 296 | // we try to cache 8 items |
295 | switch( dir ) { | 297 | switch( dir ) { |
296 | /* forward */ | 298 | /* forward */ |
297 | case 0: | 299 | case 0: |
298 | for (uint i = cur; i < ints.count() && size < 8; i++ ) { | 300 | for (uint i = cur; i < ints.count() && size < 8; i++ ) { |
299 | qWarning("size %d %d", size, ints[i] ); | 301 | qWarning("size %d %d", size, ints[i] ); |
300 | search[size] = ints[i]; | 302 | search[size] = ints[i]; |
301 | size++; | 303 | size++; |
302 | } | 304 | } |
303 | break; | 305 | break; |
304 | /* reverse */ | 306 | /* reverse */ |
305 | case 1: | 307 | case 1: |
306 | for (uint i = cur; i >= 0 && size < 8; i-- ) { | 308 | for (uint i = cur; i != 0 && size < 8; i-- ) { |
307 | search[size] = ints[i]; | 309 | search[size] = ints[i]; |
308 | size++; | 310 | size++; |
309 | } | 311 | } |
310 | break; | 312 | break; |
311 | } | 313 | } |
312 | search.resize( size ); | 314 | search.resize( size ); |
313 | FindQuery query( search ); | 315 | FindQuery query( search ); |
314 | OSQLResult res = m_driver->query( &query ); | 316 | OSQLResult res = m_driver->query( &query ); |
315 | if ( res.state() != OSQLResult::Success ) | 317 | if ( res.state() != OSQLResult::Success ) |
316 | return to; | 318 | return to; |
317 | 319 | ||
318 | return todo( res ); | 320 | return todo( res ); |
319 | } | 321 | } |
320 | void OTodoAccessBackendSQL::clear() { | 322 | void OTodoAccessBackendSQL::clear() { |
321 | ClearQuery cle; | 323 | ClearQuery cle; |
322 | OSQLResult res = m_driver->query( &cle ); | 324 | OSQLResult res = m_driver->query( &cle ); |
323 | CreateQuery qu; | 325 | CreateQuery qu; |
324 | res = m_driver->query(&qu); | 326 | res = m_driver->query(&qu); |
325 | } | 327 | } |
326 | bool OTodoAccessBackendSQL::add( const OTodo& t) { | 328 | bool OTodoAccessBackendSQL::add( const OTodo& t) { |
327 | InsertQuery ins( t ); | 329 | InsertQuery ins( t ); |
328 | OSQLResult res = m_driver->query( &ins ); | 330 | OSQLResult res = m_driver->query( &ins ); |
329 | 331 | ||
330 | if ( res.state() == OSQLResult::Failure ) | 332 | if ( res.state() == OSQLResult::Failure ) |
331 | return false; | 333 | return false; |
332 | int c = m_uids.count(); | 334 | int c = m_uids.count(); |
333 | m_uids.resize( c+1 ); | 335 | m_uids.resize( c+1 ); |
334 | m_uids[c] = t.uid(); | 336 | m_uids[c] = t.uid(); |
335 | 337 | ||
336 | return true; | 338 | return true; |
337 | } | 339 | } |
338 | bool OTodoAccessBackendSQL::remove( int uid ) { | 340 | bool OTodoAccessBackendSQL::remove( int uid ) { |
339 | RemoveQuery rem( uid ); | 341 | RemoveQuery rem( uid ); |
340 | OSQLResult res = m_driver->query(&rem ); | 342 | OSQLResult res = m_driver->query(&rem ); |
341 | 343 | ||
342 | if ( res.state() == OSQLResult::Failure ) | 344 | if ( res.state() == OSQLResult::Failure ) |
343 | return false; | 345 | return false; |
344 | 346 | ||
345 | update(); | 347 | m_dirty = true; |
346 | return true; | 348 | return true; |
347 | } | 349 | } |
348 | /* | 350 | /* |
349 | * FIXME better set query | 351 | * FIXME better set query |
350 | * but we need the cache for that | 352 | * but we need the cache for that |
351 | * now we remove | 353 | * now we remove |
352 | */ | 354 | */ |
353 | bool OTodoAccessBackendSQL::replace( const OTodo& t) { | 355 | bool OTodoAccessBackendSQL::replace( const OTodo& t) { |
354 | remove( t.uid() ); | 356 | remove( t.uid() ); |
355 | return add(t); | 357 | bool b= add(t); |
358 | m_dirty = false; // we changed some stuff but the UID stayed the same | ||
359 | return b; | ||
356 | } | 360 | } |
357 | QArray<int> OTodoAccessBackendSQL::overDue() { | 361 | QArray<int> OTodoAccessBackendSQL::overDue() { |
358 | OverDueQuery qu; | 362 | OverDueQuery qu; |
359 | return uids( m_driver->query(&qu ) ); | 363 | return uids( m_driver->query(&qu ) ); |
360 | } | 364 | } |
361 | QArray<int> OTodoAccessBackendSQL::effectiveToDos( const QDate& s, | 365 | QArray<int> OTodoAccessBackendSQL::effectiveToDos( const QDate& s, |
362 | const QDate& t, | 366 | const QDate& t, |
363 | bool u) { | 367 | bool u) { |
364 | EffQuery ef(s, t, u ); | 368 | EffQuery ef(s, t, u ); |
365 | return uids (m_driver->query(&ef) ); | 369 | return uids (m_driver->query(&ef) ); |
366 | } | 370 | } |
367 | /* | 371 | /* |
368 | * | 372 | * |
369 | */ | 373 | */ |
370 | QArray<int> OTodoAccessBackendSQL::sorted( bool asc, int sortOrder, | 374 | QArray<int> OTodoAccessBackendSQL::sorted( bool asc, int sortOrder, |
371 | int sortFilter, int cat ) { | 375 | int sortFilter, int cat ) { |
376 | qWarning("sorted %d, %d", asc, sortOrder ); | ||
372 | QString query; | 377 | QString query; |
373 | query = "select uid from todolist WHERE "; | 378 | query = "select uid from todolist WHERE "; |
374 | 379 | ||
375 | /* | 380 | /* |
376 | * Sort Filter stuff | 381 | * Sort Filter stuff |
377 | * not that straight forward | 382 | * not that straight forward |
378 | * | 383 | * |
379 | */ | 384 | */ |
380 | /* Category */ | 385 | /* Category */ |
381 | if ( sortFilter & 1 ) { | 386 | if ( sortFilter & 1 ) { |
382 | QString str; | 387 | QString str; |
383 | if (cat != 0 ) str = QString::number( cat ); | 388 | if (cat != 0 ) str = QString::number( cat ); |
384 | query += " categories like '%" +str+"%' AND"; | 389 | query += " categories like '%" +str+"%' AND"; |
385 | } | 390 | } |
386 | /* Show only overdue */ | 391 | /* Show only overdue */ |
387 | if ( sortFilter & 2 ) { | 392 | if ( sortFilter & 2 ) { |
388 | QDate date = QDate::currentDate(); | 393 | QDate date = QDate::currentDate(); |
389 | QString due; | 394 | QString due; |
390 | QString base; | 395 | QString base; |
391 | base = QString("DueDate <= '%1-%2-%3' AND completed = 0").arg( date.year() ).arg( date.month() ).arg( date.day() ); | 396 | base = QString("DueDate <= '%1-%2-%3' AND completed = 0").arg( date.year() ).arg( date.month() ).arg( date.day() ); |
392 | query += " " + base + " AND"; | 397 | query += " " + base + " AND"; |
393 | } | 398 | } |
394 | /* not show completed */ | 399 | /* not show completed */ |
395 | if ( sortFilter & 4 ) { | 400 | if ( sortFilter & 4 ) { |
396 | query += " completed = 0 AND"; | 401 | query += " completed = 0 AND"; |
397 | }else{ | 402 | }else{ |
398 | query += " ( completed = 1 OR completed = 0) AND"; | 403 | query += " ( completed = 1 OR completed = 0) AND"; |
399 | } | 404 | } |
400 | /* srtip the end */ | 405 | /* srtip the end */ |
401 | query = query.remove( query.length()-3, 3 ); | 406 | query = query.remove( query.length()-3, 3 ); |
402 | 407 | ||
403 | 408 | ||
404 | /* | 409 | /* |
405 | * sort order stuff | 410 | * sort order stuff |
406 | * quite straight forward | 411 | * quite straight forward |
407 | */ | 412 | */ |
408 | query += "ORDER BY "; | 413 | query += "ORDER BY "; |
409 | switch( sortOrder ) { | 414 | switch( sortOrder ) { |
410 | /* completed */ | 415 | /* completed */ |
411 | case 0: | 416 | case 0: |
412 | query += "completed"; | 417 | query += "completed"; |
413 | break; | 418 | break; |
414 | case 1: | 419 | case 1: |
415 | query += "priority"; | 420 | query += "priority"; |
416 | break; | 421 | break; |
417 | case 2: | 422 | case 2: |
418 | query += "description"; | 423 | query += "description"; |
419 | break; | 424 | break; |
420 | case 3: | 425 | case 3: |
421 | query += "DueDate"; | 426 | query += "DueDate"; |
422 | break; | 427 | break; |
423 | } | 428 | } |
424 | if ( !asc ) | 429 | |
430 | if ( !asc ) { | ||
431 | qWarning("not ascending!"); | ||
425 | query += " DESC"; | 432 | query += " DESC"; |
433 | } | ||
426 | 434 | ||
427 | qWarning( query ); | 435 | qWarning( query ); |
428 | OSQLRawQuery raw(query ); | 436 | OSQLRawQuery raw(query ); |
429 | return uids( m_driver->query(&raw) ); | 437 | return uids( m_driver->query(&raw) ); |
430 | } | 438 | } |
431 | bool OTodoAccessBackendSQL::date( QDate& da, const QString& str ) const{ | 439 | bool OTodoAccessBackendSQL::date( QDate& da, const QString& str ) const{ |
432 | if ( str == "0-0-0" ) | 440 | if ( str == "0-0-0" ) |
433 | return false; | 441 | return false; |
434 | else{ | 442 | else{ |
435 | int day, year, month; | 443 | int day, year, month; |
436 | QStringList list = QStringList::split("-", str ); | 444 | QStringList list = QStringList::split("-", str ); |
437 | year = list[0].toInt(); | 445 | year = list[0].toInt(); |
438 | month = list[1].toInt(); | 446 | month = list[1].toInt(); |
439 | day = list[2].toInt(); | 447 | day = list[2].toInt(); |
440 | da.setYMD( year, month, day ); | 448 | da.setYMD( year, month, day ); |
441 | return true; | 449 | return true; |
442 | } | 450 | } |
443 | } | 451 | } |
444 | OTodo OTodoAccessBackendSQL::todo( const OSQLResult& res) const{ | 452 | OTodo OTodoAccessBackendSQL::todo( const OSQLResult& res) const{ |
445 | if ( res.state() == OSQLResult::Failure ) { | 453 | if ( res.state() == OSQLResult::Failure ) { |
446 | OTodo to; | 454 | OTodo to; |
447 | return to; | 455 | return to; |
448 | } | 456 | } |
449 | 457 | ||
450 | OSQLResultItem::ValueList list = res.results(); | 458 | OSQLResultItem::ValueList list = res.results(); |
451 | OSQLResultItem::ValueList::Iterator it = list.begin(); | 459 | OSQLResultItem::ValueList::Iterator it = list.begin(); |
452 | qWarning("todo1"); | 460 | qWarning("todo1"); |
453 | OTodo to = todo( (*it) ); | 461 | OTodo to = todo( (*it) ); |
454 | cache( to ); | 462 | cache( to ); |
455 | ++it; | 463 | ++it; |
456 | 464 | ||
457 | for ( ; it != list.end(); ++it ) { | 465 | for ( ; it != list.end(); ++it ) { |
458 | qWarning("caching"); | 466 | qWarning("caching"); |
459 | cache( todo( (*it) ) ); | 467 | cache( todo( (*it) ) ); |
460 | } | 468 | } |
461 | return to; | 469 | return to; |
462 | } | 470 | } |
463 | OTodo OTodoAccessBackendSQL::todo( OSQLResultItem& item )const { | 471 | OTodo OTodoAccessBackendSQL::todo( OSQLResultItem& item )const { |
464 | qWarning("todo"); | 472 | qWarning("todo"); |
465 | bool has = false; QDate da = QDate::currentDate(); | 473 | bool has = false; QDate da = QDate::currentDate(); |
466 | has = date( da, item.data("DueDate") ); | 474 | has = date( da, item.data("DueDate") ); |
467 | QStringList cats = QStringList::split(";", item.data("categories") ); | 475 | QStringList cats = QStringList::split(";", item.data("categories") ); |
468 | 476 | ||
469 | OTodo to( (bool)item.data("completed").toInt(), item.data("priority").toInt(), | 477 | OTodo to( (bool)item.data("completed").toInt(), item.data("priority").toInt(), |
470 | cats, item.data("summary"), item.data("description"), | 478 | cats, item.data("summary"), item.data("description"), |
471 | item.data("progress").toUShort(), has, da, | 479 | item.data("progress").toUShort(), has, da, |
472 | item.data("uid").toInt() ); | 480 | item.data("uid").toInt() ); |
473 | return to; | 481 | return to; |
474 | } | 482 | } |
475 | OTodo OTodoAccessBackendSQL::todo( int uid )const { | 483 | OTodo OTodoAccessBackendSQL::todo( int uid )const { |
476 | FindQuery find( uid ); | 484 | FindQuery find( uid ); |
477 | return todo( m_driver->query(&find) ); | 485 | return todo( m_driver->query(&find) ); |
478 | } | 486 | } |
479 | /* | 487 | /* |
480 | * update the dict | 488 | * update the dict |
481 | */ | 489 | */ |
482 | void OTodoAccessBackendSQL::fillDict() { | 490 | void OTodoAccessBackendSQL::fillDict() { |
483 | /* initialize dict */ | 491 | /* initialize dict */ |
484 | /* | 492 | /* |
485 | * UPDATE dict if you change anything!!! | 493 | * UPDATE dict if you change anything!!! |
486 | */ | 494 | */ |
487 | m_dict.setAutoDelete( TRUE ); | 495 | m_dict.setAutoDelete( TRUE ); |
488 | m_dict.insert("Categories" , new int(OTodo::Category) ); | 496 | m_dict.insert("Categories" , new int(OTodo::Category) ); |
489 | m_dict.insert("Uid" , new int(OTodo::Uid) ); | 497 | m_dict.insert("Uid" , new int(OTodo::Uid) ); |
490 | m_dict.insert("HasDate" , new int(OTodo::HasDate) ); | 498 | m_dict.insert("HasDate" , new int(OTodo::HasDate) ); |
491 | m_dict.insert("Completed" , new int(OTodo::Completed) ); | 499 | m_dict.insert("Completed" , new int(OTodo::Completed) ); |
492 | m_dict.insert("Description" , new int(OTodo::Description) ); | 500 | m_dict.insert("Description" , new int(OTodo::Description) ); |
493 | m_dict.insert("Summary" , new int(OTodo::Summary) ); | 501 | m_dict.insert("Summary" , new int(OTodo::Summary) ); |
494 | m_dict.insert("Priority" , new int(OTodo::Priority) ); | 502 | m_dict.insert("Priority" , new int(OTodo::Priority) ); |
495 | m_dict.insert("DateDay" , new int(OTodo::DateDay) ); | 503 | m_dict.insert("DateDay" , new int(OTodo::DateDay) ); |
496 | m_dict.insert("DateMonth" , new int(OTodo::DateMonth) ); | 504 | m_dict.insert("DateMonth" , new int(OTodo::DateMonth) ); |
497 | m_dict.insert("DateYear" , new int(OTodo::DateYear) ); | 505 | m_dict.insert("DateYear" , new int(OTodo::DateYear) ); |
498 | m_dict.insert("Progress" , new int(OTodo::Progress) ); | 506 | m_dict.insert("Progress" , new int(OTodo::Progress) ); |
499 | m_dict.insert("Completed", new int(OTodo::Completed) ); | 507 | m_dict.insert("Completed", new int(OTodo::Completed) ); |
500 | m_dict.insert("CrossReference", new int(OTodo::CrossReference) ); | 508 | m_dict.insert("CrossReference", new int(OTodo::CrossReference) ); |
501 | m_dict.insert("HasAlarmDateTime",new int(OTodo::HasAlarmDateTime) ); | 509 | m_dict.insert("HasAlarmDateTime",new int(OTodo::HasAlarmDateTime) ); |
502 | m_dict.insert("AlarmDateTime", new int(OTodo::AlarmDateTime) ); | 510 | m_dict.insert("AlarmDateTime", new int(OTodo::AlarmDateTime) ); |
503 | } | 511 | } |
504 | void OTodoAccessBackendSQL::update() { | 512 | /* |
513 | * need to be const so let's fool the | ||
514 | * compiler :( | ||
515 | */ | ||
516 | void OTodoAccessBackendSQL::update()const { | ||
517 | ((OTodoAccessBackendSQL*)this)->m_dirty = false; | ||
505 | LoadQuery lo; | 518 | LoadQuery lo; |
506 | OSQLResult res = m_driver->query(&lo); | 519 | OSQLResult res = m_driver->query(&lo); |
507 | if ( res.state() != OSQLResult::Success ) | 520 | if ( res.state() != OSQLResult::Success ) |
508 | return; | 521 | return; |
509 | 522 | ||
510 | m_uids = uids( res ); | 523 | ((OTodoAccessBackendSQL*)this)->m_uids = uids( res ); |
511 | } | 524 | } |
512 | QArray<int> OTodoAccessBackendSQL::uids( const OSQLResult& res) const{ | 525 | QArray<int> OTodoAccessBackendSQL::uids( const OSQLResult& res) const{ |
513 | 526 | ||
514 | OSQLResultItem::ValueList list = res.results(); | 527 | OSQLResultItem::ValueList list = res.results(); |
515 | OSQLResultItem::ValueList::Iterator it; | 528 | OSQLResultItem::ValueList::Iterator it; |
516 | QArray<int> ints(list.count() ); | 529 | QArray<int> ints(list.count() ); |
517 | qWarning(" count = %d", list.count() ); | 530 | qWarning(" count = %d", list.count() ); |
518 | 531 | ||
519 | int i = 0; | 532 | int i = 0; |
520 | for (it = list.begin(); it != list.end(); ++it ) { | 533 | for (it = list.begin(); it != list.end(); ++it ) { |
521 | ints[i] = (*it).data("uid").toInt(); | 534 | ints[i] = (*it).data("uid").toInt(); |
522 | i++; | 535 | i++; |
523 | } | 536 | } |
524 | return ints; | 537 | return ints; |
525 | } | 538 | } |
526 | 539 | ||
diff --git a/libopie2/opiepim/backend/otodoaccesssql.h b/libopie2/opiepim/backend/otodoaccesssql.h index c1aa2ed..0f6dd2c 100644 --- a/libopie2/opiepim/backend/otodoaccesssql.h +++ b/libopie2/opiepim/backend/otodoaccesssql.h | |||
@@ -1,49 +1,50 @@ | |||
1 | #ifndef OPIE_PIM_ACCESS_SQL_H | 1 | #ifndef OPIE_PIM_ACCESS_SQL_H |
2 | #define OPIE_PIM_ACCESS_SQL_H | 2 | #define OPIE_PIM_ACCESS_SQL_H |
3 | 3 | ||
4 | #include <qasciidict.h> | 4 | #include <qasciidict.h> |
5 | 5 | ||
6 | #include "otodoaccessbackend.h" | 6 | #include "otodoaccessbackend.h" |
7 | 7 | ||
8 | class OSQLDriver; | 8 | class OSQLDriver; |
9 | class OSQLResult; | 9 | class OSQLResult; |
10 | class OSQLResultItem; | 10 | class OSQLResultItem; |
11 | class OTodoAccessBackendSQL : public OTodoAccessBackend { | 11 | class OTodoAccessBackendSQL : public OTodoAccessBackend { |
12 | public: | 12 | public: |
13 | OTodoAccessBackendSQL( const QString& file ); | 13 | OTodoAccessBackendSQL( const QString& file ); |
14 | ~OTodoAccessBackendSQL(); | 14 | ~OTodoAccessBackendSQL(); |
15 | 15 | ||
16 | bool load(); | 16 | bool load(); |
17 | bool reload(); | 17 | bool reload(); |
18 | bool save(); | 18 | bool save(); |
19 | QArray<int> allRecords()const; | 19 | QArray<int> allRecords()const; |
20 | 20 | ||
21 | QArray<int> queryByExample( const OTodo& t, int sort ); | 21 | QArray<int> queryByExample( const OTodo& t, int sort ); |
22 | OTodo find(int uid)const; | 22 | OTodo find(int uid)const; |
23 | OTodo find(int uid, const QArray<int>&, uint cur, Frontend::CacheDirection )const; | 23 | OTodo find(int uid, const QArray<int>&, uint cur, Frontend::CacheDirection )const; |
24 | void clear(); | 24 | void clear(); |
25 | bool add( const OTodo& t ); | 25 | bool add( const OTodo& t ); |
26 | bool remove( int uid ); | 26 | bool remove( int uid ); |
27 | bool replace( const OTodo& t ); | 27 | bool replace( const OTodo& t ); |
28 | 28 | ||
29 | QArray<int> overDue(); | 29 | QArray<int> overDue(); |
30 | QArray<int> effectiveToDos( const QDate& start, | 30 | QArray<int> effectiveToDos( const QDate& start, |
31 | const QDate& end, bool includeNoDates ); | 31 | const QDate& end, bool includeNoDates ); |
32 | QArray<int> sorted(bool asc, int sortOrder, int sortFilter, int cat ); | 32 | QArray<int> sorted(bool asc, int sortOrder, int sortFilter, int cat ); |
33 | 33 | ||
34 | private: | 34 | private: |
35 | void update(); | 35 | void update()const; |
36 | void fillDict(); | 36 | void fillDict(); |
37 | inline bool date( QDate& date, const QString& )const; | 37 | inline bool date( QDate& date, const QString& )const; |
38 | inline OTodo todo( const OSQLResult& )const; | 38 | inline OTodo todo( const OSQLResult& )const; |
39 | inline OTodo todo( OSQLResultItem& )const; | 39 | inline OTodo todo( OSQLResultItem& )const; |
40 | inline QArray<int> uids( const OSQLResult& )const; | 40 | inline QArray<int> uids( const OSQLResult& )const; |
41 | OTodo todo( int uid )const; | 41 | OTodo todo( int uid )const; |
42 | 42 | ||
43 | QAsciiDict<int> m_dict; | 43 | QAsciiDict<int> m_dict; |
44 | OSQLDriver* m_driver; | 44 | OSQLDriver* m_driver; |
45 | QArray<int> m_uids; | 45 | QArray<int> m_uids; |
46 | bool m_dirty : 1; | ||
46 | }; | 47 | }; |
47 | 48 | ||
48 | 49 | ||
49 | #endif | 50 | #endif |
diff --git a/libopie2/opiepim/core/opimaccesstemplate.h b/libopie2/opiepim/core/opimaccesstemplate.h index 92d7192..a0d8f63 100644 --- a/libopie2/opiepim/core/opimaccesstemplate.h +++ b/libopie2/opiepim/core/opimaccesstemplate.h | |||
@@ -1,247 +1,245 @@ | |||
1 | #ifndef OPIE_PIM_ACCESS_TEMPLATE_H | 1 | #ifndef OPIE_PIM_ACCESS_TEMPLATE_H |
2 | #define OPIE_PIM_ACCESS_TEMPLATE_H | 2 | #define OPIE_PIM_ACCESS_TEMPLATE_H |
3 | 3 | ||
4 | #include <qarray.h> | 4 | #include <qarray.h> |
5 | 5 | ||
6 | #include <opie/opimrecord.h> | 6 | #include <opie/opimrecord.h> |
7 | #include <opie/opimaccessbackend.h> | 7 | #include <opie/opimaccessbackend.h> |
8 | #include <opie/orecordlist.h> | 8 | #include <opie/orecordlist.h> |
9 | 9 | ||
10 | #include "opimcache.h" | 10 | #include "opimcache.h" |
11 | #include "otemplatebase.h" | 11 | #include "otemplatebase.h" |
12 | 12 | ||
13 | /** | 13 | /** |
14 | * Thats the frontend to our OPIE PIM | 14 | * Thats the frontend to our OPIE PIM |
15 | * Library. Either you want to use it's | 15 | * Library. Either you want to use it's |
16 | * interface or you want to implement | 16 | * interface or you want to implement |
17 | * your own Access lib | 17 | * your own Access lib |
18 | * Just create a OPimRecord and inherit from | 18 | * Just create a OPimRecord and inherit from |
19 | * the plugins | 19 | * the plugins |
20 | */ | 20 | */ |
21 | 21 | ||
22 | template <class T = OPimRecord > | 22 | template <class T = OPimRecord > |
23 | class OPimAccessTemplate : public OTemplateBase<T> { | 23 | class OPimAccessTemplate : public OTemplateBase<T> { |
24 | public: | 24 | public: |
25 | typedef ORecordList<T> List; | 25 | typedef ORecordList<T> List; |
26 | typedef OPimAccessBackend<T> BackEnd; | 26 | typedef OPimAccessBackend<T> BackEnd; |
27 | typedef OPimCache<T> Cache; | 27 | typedef OPimCache<T> Cache; |
28 | 28 | ||
29 | /** | 29 | /** |
30 | * our sort order | 30 | * our sort order |
31 | * should be safe explaining | 31 | * should be safe explaining |
32 | */ | 32 | */ |
33 | enum SortOrder { WildCards = 0, IgnoreCase = 1, | 33 | enum SortOrder { WildCards = 0, IgnoreCase = 1, |
34 | RegExp = 2, ExactMatch = 4 }; | 34 | RegExp = 2, ExactMatch = 4 }; |
35 | 35 | ||
36 | /** | 36 | /** |
37 | * c'tor BackEnd | 37 | * c'tor BackEnd |
38 | */ | 38 | */ |
39 | OPimAccessTemplate( BackEnd* end); | 39 | OPimAccessTemplate( BackEnd* end); |
40 | virtual ~OPimAccessTemplate(); | 40 | virtual ~OPimAccessTemplate(); |
41 | 41 | ||
42 | /** | 42 | /** |
43 | * load from the backend | 43 | * load from the backend |
44 | */ | 44 | */ |
45 | virtual bool load(); | 45 | virtual bool load(); |
46 | 46 | ||
47 | /** | 47 | /** |
48 | * reload from the backend | 48 | * reload from the backend |
49 | */ | 49 | */ |
50 | virtual bool reload(); | 50 | virtual bool reload(); |
51 | 51 | ||
52 | /** | 52 | /** |
53 | * save to the backend | 53 | * save to the backend |
54 | */ | 54 | */ |
55 | virtual bool save(); | 55 | virtual bool save(); |
56 | 56 | ||
57 | /** | 57 | /** |
58 | * if the resource was changed externally | 58 | * if the resource was changed externally |
59 | */ | 59 | */ |
60 | bool wasChangedExternally()const; | 60 | bool wasChangedExternally()const; |
61 | 61 | ||
62 | /** | 62 | /** |
63 | * return a List of records | 63 | * return a List of records |
64 | * you can iterate over them | 64 | * you can iterate over them |
65 | */ | 65 | */ |
66 | virtual List allRecords()const; | 66 | virtual List allRecords()const; |
67 | 67 | ||
68 | /** | 68 | /** |
69 | * queryByExample | 69 | * queryByExample |
70 | */ | 70 | */ |
71 | virtual List queryByExample( const T& t, int sortOrder ); | 71 | virtual List queryByExample( const T& t, int sortOrder ); |
72 | 72 | ||
73 | /** | 73 | /** |
74 | * find the OPimRecord uid | 74 | * find the OPimRecord uid |
75 | */ | 75 | */ |
76 | virtual T find( int uid )const; | 76 | virtual T find( int uid )const; |
77 | 77 | ||
78 | /** | 78 | /** |
79 | * read ahead cache find method ;) | 79 | * read ahead cache find method ;) |
80 | */ | 80 | */ |
81 | virtual T find( int uid, const QArray<int>&, | 81 | virtual T find( int uid, const QArray<int>&, |
82 | uint current, CacheDirection dir = Forward )const; | 82 | uint current, CacheDirection dir = Forward )const; |
83 | 83 | ||
84 | /* invalidate cache here */ | 84 | /* invalidate cache here */ |
85 | /** | 85 | /** |
86 | * clears the backend and invalidates the backend | 86 | * clears the backend and invalidates the backend |
87 | */ | 87 | */ |
88 | virtual void clear() ; | 88 | virtual void clear() ; |
89 | 89 | ||
90 | /** | 90 | /** |
91 | * add T to the backend | 91 | * add T to the backend |
92 | */ | 92 | */ |
93 | virtual bool add( const T& t ) ; | 93 | virtual bool add( const T& t ) ; |
94 | 94 | ||
95 | /* only the uid matters */ | 95 | /* only the uid matters */ |
96 | /** | 96 | /** |
97 | * remove T from the backend | 97 | * remove T from the backend |
98 | */ | 98 | */ |
99 | virtual bool remove( const T& t ); | 99 | virtual bool remove( const T& t ); |
100 | 100 | ||
101 | /** | 101 | /** |
102 | * remove the OPimRecord with uid | 102 | * remove the OPimRecord with uid |
103 | */ | 103 | */ |
104 | virtual bool remove( int uid ); | 104 | virtual bool remove( int uid ); |
105 | 105 | ||
106 | /** | 106 | /** |
107 | * replace T from backend | 107 | * replace T from backend |
108 | */ | 108 | */ |
109 | virtual bool replace( const T& t) ; | 109 | virtual bool replace( const T& t) ; |
110 | 110 | ||
111 | /** | 111 | /** |
112 | * @internal | 112 | * @internal |
113 | */ | 113 | */ |
114 | void cache( const T& )const; | 114 | void cache( const T& )const; |
115 | void setSaneCacheSize( int ); | 115 | void setSaneCacheSize( int ); |
116 | protected: | 116 | protected: |
117 | /** | 117 | /** |
118 | * invalidate the cache | 118 | * invalidate the cache |
119 | */ | 119 | */ |
120 | void invalidateCache(); | 120 | void invalidateCache(); |
121 | 121 | ||
122 | void setBackEnd( BackEnd* end ); | 122 | void setBackEnd( BackEnd* end ); |
123 | /** | 123 | /** |
124 | * returns the backend | 124 | * returns the backend |
125 | */ | 125 | */ |
126 | BackEnd* backEnd(); | 126 | BackEnd* backEnd(); |
127 | BackEnd* m_backEnd; | 127 | BackEnd* m_backEnd; |
128 | Cache m_cache; | 128 | Cache m_cache; |
129 | 129 | ||
130 | }; | 130 | }; |
131 | 131 | ||
132 | template <class T> | 132 | template <class T> |
133 | OPimAccessTemplate<T>::OPimAccessTemplate( BackEnd* end ) | 133 | OPimAccessTemplate<T>::OPimAccessTemplate( BackEnd* end ) |
134 | : OTemplateBase<T>(), m_backEnd( end ) | 134 | : OTemplateBase<T>(), m_backEnd( end ) |
135 | { | 135 | { |
136 | if (end ) | 136 | if (end ) |
137 | end->setFrontend( this ); | 137 | end->setFrontend( this ); |
138 | } | 138 | } |
139 | template <class T> | 139 | template <class T> |
140 | OPimAccessTemplate<T>::~OPimAccessTemplate() { | 140 | OPimAccessTemplate<T>::~OPimAccessTemplate() { |
141 | qWarning("~OPimAccessTemplate<T>"); | 141 | qWarning("~OPimAccessTemplate<T>"); |
142 | delete m_backEnd; | 142 | delete m_backEnd; |
143 | } | 143 | } |
144 | template <class T> | 144 | template <class T> |
145 | bool OPimAccessTemplate<T>::load() { | 145 | bool OPimAccessTemplate<T>::load() { |
146 | invalidateCache(); | 146 | invalidateCache(); |
147 | return m_backEnd->load(); | 147 | return m_backEnd->load(); |
148 | } | 148 | } |
149 | template <class T> | 149 | template <class T> |
150 | bool OPimAccessTemplate<T>::reload() { | 150 | bool OPimAccessTemplate<T>::reload() { |
151 | return m_backEnd->reload(); | 151 | return m_backEnd->reload(); |
152 | } | 152 | } |
153 | template <class T> | 153 | template <class T> |
154 | bool OPimAccessTemplate<T>::save() { | 154 | bool OPimAccessTemplate<T>::save() { |
155 | return m_backEnd->save(); | 155 | return m_backEnd->save(); |
156 | } | 156 | } |
157 | template <class T> | 157 | template <class T> |
158 | OPimAccessTemplate<T>::List OPimAccessTemplate<T>::allRecords()const { | 158 | OPimAccessTemplate<T>::List OPimAccessTemplate<T>::allRecords()const { |
159 | QArray<int> ints = m_backEnd->allRecords(); | 159 | QArray<int> ints = m_backEnd->allRecords(); |
160 | List lis(ints, this ); | 160 | List lis(ints, this ); |
161 | return lis; | 161 | return lis; |
162 | } | 162 | } |
163 | template <class T> | 163 | template <class T> |
164 | OPimAccessTemplate<T>::List | 164 | OPimAccessTemplate<T>::List |
165 | OPimAccessTemplate<T>::queryByExample( const T& t, int sortOrder ) { | 165 | OPimAccessTemplate<T>::queryByExample( const T& t, int sortOrder ) { |
166 | QArray<int> ints = m_backEnd->queryByExample( t, sortOrder ); | 166 | QArray<int> ints = m_backEnd->queryByExample( t, sortOrder ); |
167 | 167 | ||
168 | List lis(ints, this ); | 168 | List lis(ints, this ); |
169 | return lis; | 169 | return lis; |
170 | } | 170 | } |
171 | template <class T> | 171 | template <class T> |
172 | T OPimAccessTemplate<T>::find( int uid ) const{ | 172 | T OPimAccessTemplate<T>::find( int uid ) const{ |
173 | T t = m_backEnd->find( uid ); | 173 | T t = m_backEnd->find( uid ); |
174 | cache( t ); | 174 | cache( t ); |
175 | return t; | 175 | return t; |
176 | } | 176 | } |
177 | template <class T> | 177 | template <class T> |
178 | T OPimAccessTemplate<T>::find( int uid, const QArray<int>& ar, | 178 | T OPimAccessTemplate<T>::find( int uid, const QArray<int>& ar, |
179 | uint current, CacheDirection dir )const { | 179 | uint current, CacheDirection dir )const { |
180 | /* | 180 | /* |
181 | * better do T.isEmpty() | 181 | * better do T.isEmpty() |
182 | * after a find this way we would | 182 | * after a find this way we would |
183 | * avoid two finds in QCache... | 183 | * avoid two finds in QCache... |
184 | */ | 184 | */ |
185 | // qWarning("find it now %d", uid ); | 185 | // qWarning("find it now %d", uid ); |
186 | if (m_cache.contains( uid ) ) { | 186 | if (m_cache.contains( uid ) ) { |
187 | qWarning("m cache contains %d", uid); | ||
188 | return m_cache.find( uid ); | 187 | return m_cache.find( uid ); |
189 | } | 188 | } |
190 | 189 | ||
191 | T t = m_backEnd->find( uid, ar, current, dir ); | 190 | T t = m_backEnd->find( uid, ar, current, dir ); |
192 | qWarning("found it and cache it now %d", uid); | ||
193 | cache( t ); | 191 | cache( t ); |
194 | return t; | 192 | return t; |
195 | } | 193 | } |
196 | template <class T> | 194 | template <class T> |
197 | void OPimAccessTemplate<T>::clear() { | 195 | void OPimAccessTemplate<T>::clear() { |
198 | invalidateCache(); | 196 | invalidateCache(); |
199 | m_backEnd->clear(); | 197 | m_backEnd->clear(); |
200 | } | 198 | } |
201 | template <class T> | 199 | template <class T> |
202 | bool OPimAccessTemplate<T>::add( const T& t ) { | 200 | bool OPimAccessTemplate<T>::add( const T& t ) { |
203 | cache( t ); | 201 | cache( t ); |
204 | return m_backEnd->add( t ); | 202 | return m_backEnd->add( t ); |
205 | } | 203 | } |
206 | template <class T> | 204 | template <class T> |
207 | bool OPimAccessTemplate<T>::remove( const T& t ) { | 205 | bool OPimAccessTemplate<T>::remove( const T& t ) { |
208 | return remove( t.uid() ); | 206 | return remove( t.uid() ); |
209 | } | 207 | } |
210 | template <class T> | 208 | template <class T> |
211 | bool OPimAccessTemplate<T>::remove( int uid ) { | 209 | bool OPimAccessTemplate<T>::remove( int uid ) { |
212 | m_cache.remove( uid ); | 210 | m_cache.remove( uid ); |
213 | return m_backEnd->remove( uid ); | 211 | return m_backEnd->remove( uid ); |
214 | } | 212 | } |
215 | template <class T> | 213 | template <class T> |
216 | bool OPimAccessTemplate<T>::replace( const T& t ) { | 214 | bool OPimAccessTemplate<T>::replace( const T& t ) { |
217 | m_cache.replace( t ); | 215 | m_cache.replace( t ); |
218 | return m_backEnd->replace( t ); | 216 | return m_backEnd->replace( t ); |
219 | } | 217 | } |
220 | template <class T> | 218 | template <class T> |
221 | void OPimAccessTemplate<T>::invalidateCache() { | 219 | void OPimAccessTemplate<T>::invalidateCache() { |
222 | m_cache.invalidate(); | 220 | m_cache.invalidate(); |
223 | } | 221 | } |
224 | template <class T> | 222 | template <class T> |
225 | OPimAccessTemplate<T>::BackEnd* OPimAccessTemplate<T>::backEnd() { | 223 | OPimAccessTemplate<T>::BackEnd* OPimAccessTemplate<T>::backEnd() { |
226 | return m_backEnd; | 224 | return m_backEnd; |
227 | } | 225 | } |
228 | template <class T> | 226 | template <class T> |
229 | bool OPimAccessTemplate<T>::wasChangedExternally()const { | 227 | bool OPimAccessTemplate<T>::wasChangedExternally()const { |
230 | return false; | 228 | return false; |
231 | } | 229 | } |
232 | template <class T> | 230 | template <class T> |
233 | void OPimAccessTemplate<T>::setBackEnd( BackEnd* end ) { | 231 | void OPimAccessTemplate<T>::setBackEnd( BackEnd* end ) { |
234 | m_backEnd = end; | 232 | m_backEnd = end; |
235 | if (m_backEnd ) | 233 | if (m_backEnd ) |
236 | m_backEnd->setFrontend( this ); | 234 | m_backEnd->setFrontend( this ); |
237 | } | 235 | } |
238 | template <class T> | 236 | template <class T> |
239 | void OPimAccessTemplate<T>::cache( const T& t ) const{ | 237 | void OPimAccessTemplate<T>::cache( const T& t ) const{ |
240 | /* hacky we need to work around the const*/ | 238 | /* hacky we need to work around the const*/ |
241 | ((OPimAccessTemplate<T>*)this)->m_cache.add( t ); | 239 | ((OPimAccessTemplate<T>*)this)->m_cache.add( t ); |
242 | } | 240 | } |
243 | template <class T> | 241 | template <class T> |
244 | void OPimAccessTemplate<T>::setSaneCacheSize( int size ) { | 242 | void OPimAccessTemplate<T>::setSaneCacheSize( int size ) { |
245 | m_cache.setSize( size ); | 243 | m_cache.setSize( size ); |
246 | } | 244 | } |
247 | #endif | 245 | #endif |
diff --git a/libopie2/opiepim/orecordlist.h b/libopie2/opiepim/orecordlist.h index 08f5c85..5404910 100644 --- a/libopie2/opiepim/orecordlist.h +++ b/libopie2/opiepim/orecordlist.h | |||
@@ -1,265 +1,270 @@ | |||
1 | 1 | ||
2 | #ifndef OPIE_RECORD_LIST_H | 2 | #ifndef OPIE_RECORD_LIST_H |
3 | #define OPIE_RECORD_LIST_H | 3 | #define OPIE_RECORD_LIST_H |
4 | 4 | ||
5 | #include <qarray.h> | 5 | #include <qarray.h> |
6 | 6 | ||
7 | #include "otemplatebase.h" | 7 | #include "otemplatebase.h" |
8 | #include "opimrecord.h" | 8 | #include "opimrecord.h" |
9 | 9 | ||
10 | /** | 10 | /** |
11 | * Our List Iterator | 11 | * Our List Iterator |
12 | * it behaves like STL or Qt | 12 | * it behaves like STL or Qt |
13 | * | 13 | * |
14 | * for(it = list.begin(); it != list.end(); ++it ) | 14 | * for(it = list.begin(); it != list.end(); ++it ) |
15 | * doSomeCoolStuff( (*it) ); | 15 | * doSomeCoolStuff( (*it) ); |
16 | */ | 16 | */ |
17 | template <class T> class ORecordList; | 17 | template <class T> class ORecordList; |
18 | template <class T = OPimRecord> | 18 | template <class T = OPimRecord> |
19 | class ORecordListIterator { | 19 | class ORecordListIterator { |
20 | friend class ORecordList<T>; | 20 | friend class ORecordList<T>; |
21 | public: | 21 | public: |
22 | typedef OTemplateBase<T> Base; | 22 | typedef OTemplateBase<T> Base; |
23 | 23 | ||
24 | /** | 24 | /** |
25 | * The c'tor used internally from | 25 | * The c'tor used internally from |
26 | * ORecordList | 26 | * ORecordList |
27 | */ | 27 | */ |
28 | ORecordListIterator( const QArray<int>, const Base* ); | 28 | ORecordListIterator( const QArray<int>, const Base* ); |
29 | 29 | ||
30 | /** | 30 | /** |
31 | * The standard c'tor | 31 | * The standard c'tor |
32 | */ | 32 | */ |
33 | ORecordListIterator(); | 33 | ORecordListIterator(); |
34 | ~ORecordListIterator(); | 34 | ~ORecordListIterator(); |
35 | 35 | ||
36 | ORecordListIterator( const ORecordListIterator& ); | 36 | ORecordListIterator( const ORecordListIterator& ); |
37 | ORecordListIterator &operator=(const ORecordListIterator& ); | 37 | ORecordListIterator &operator=(const ORecordListIterator& ); |
38 | 38 | ||
39 | /** | 39 | /** |
40 | * a * operator ;) | 40 | * a * operator ;) |
41 | * use it like this T = (*it); | 41 | * use it like this T = (*it); |
42 | */ | 42 | */ |
43 | T operator*(); | 43 | T operator*(); |
44 | ORecordListIterator &operator++(); | 44 | ORecordListIterator &operator++(); |
45 | ORecordListIterator &operator--(); | 45 | ORecordListIterator &operator--(); |
46 | 46 | ||
47 | bool operator==( const ORecordListIterator& it ); | 47 | bool operator==( const ORecordListIterator& it ); |
48 | bool operator!=( const ORecordListIterator& it ); | 48 | bool operator!=( const ORecordListIterator& it ); |
49 | 49 | ||
50 | /** | 50 | /** |
51 | * the current item | 51 | * the current item |
52 | */ | 52 | */ |
53 | uint current()const; | 53 | uint current()const; |
54 | 54 | ||
55 | /** | 55 | /** |
56 | * the number of items | 56 | * the number of items |
57 | */ | 57 | */ |
58 | uint count()const; | 58 | uint count()const; |
59 | 59 | ||
60 | /** | 60 | /** |
61 | * sets the current item | 61 | * sets the current item |
62 | */ | 62 | */ |
63 | void setCurrent( uint cur ); | 63 | void setCurrent( uint cur ); |
64 | 64 | ||
65 | private: | 65 | private: |
66 | QArray<int> m_uids; | 66 | QArray<int> m_uids; |
67 | uint m_current; | 67 | uint m_current; |
68 | const Base* m_temp; | 68 | const Base* m_temp; |
69 | bool m_end : 1; | 69 | bool m_end : 1; |
70 | T m_record; | 70 | T m_record; |
71 | bool m_direction :1; | 71 | bool m_direction :1; |
72 | 72 | ||
73 | /* d pointer for future versions */ | 73 | /* d pointer for future versions */ |
74 | class IteratorPrivate; | 74 | class IteratorPrivate; |
75 | IteratorPrivate *d; | 75 | IteratorPrivate *d; |
76 | }; | 76 | }; |
77 | /** | 77 | /** |
78 | * The recordlist used as a return type | 78 | * The recordlist used as a return type |
79 | * from OPimAccessTemplate | 79 | * from OPimAccessTemplate |
80 | */ | 80 | */ |
81 | template <class T = OPimRecord > | 81 | template <class T = OPimRecord > |
82 | class ORecordList { | 82 | class ORecordList { |
83 | public: | 83 | public: |
84 | typedef OTemplateBase<T> Base; | 84 | typedef OTemplateBase<T> Base; |
85 | typedef ORecordListIterator<T> Iterator; | 85 | typedef ORecordListIterator<T> Iterator; |
86 | 86 | ||
87 | /** | 87 | /** |
88 | * c'tor | 88 | * c'tor |
89 | */ | 89 | */ |
90 | ORecordList () { | 90 | ORecordList () { |
91 | } | 91 | } |
92 | ORecordList( const QArray<int>& ids, | 92 | ORecordList( const QArray<int>& ids, |
93 | const Base* ); | 93 | const Base* ); |
94 | ~ORecordList(); | 94 | ~ORecordList(); |
95 | 95 | ||
96 | /** | 96 | /** |
97 | * the first iterator | 97 | * the first iterator |
98 | */ | 98 | */ |
99 | Iterator begin(); | 99 | Iterator begin(); |
100 | 100 | ||
101 | /** | 101 | /** |
102 | * the end | 102 | * the end |
103 | */ | 103 | */ |
104 | Iterator end(); | 104 | Iterator end(); |
105 | 105 | ||
106 | /** | 106 | /** |
107 | * the number of items in the list | 107 | * the number of items in the list |
108 | */ | 108 | */ |
109 | uint count()const; | 109 | uint count()const; |
110 | 110 | ||
111 | T operator[]( uint i ); | 111 | T operator[]( uint i ); |
112 | int uidAt(uint i ); | ||
112 | // FIXME implemenent remove | 113 | // FIXME implemenent remove |
113 | /* | 114 | /* |
114 | ConstIterator begin()const; | 115 | ConstIterator begin()const; |
115 | ConstIterator end()const; | 116 | ConstIterator end()const; |
116 | */ | 117 | */ |
117 | private: | 118 | private: |
118 | QArray<int> m_ids; | 119 | QArray<int> m_ids; |
119 | const Base* m_acc; | 120 | const Base* m_acc; |
120 | }; | 121 | }; |
121 | 122 | ||
122 | /* ok now implement it */ | 123 | /* ok now implement it */ |
123 | template <class T> | 124 | template <class T> |
124 | ORecordListIterator<T>::ORecordListIterator() { | 125 | ORecordListIterator<T>::ORecordListIterator() { |
125 | m_current = 0; | 126 | m_current = 0; |
126 | m_temp = 0l; | 127 | m_temp = 0l; |
127 | m_end = true; | 128 | m_end = true; |
128 | m_record = T(); | 129 | m_record = T(); |
129 | /* forward */ | 130 | /* forward */ |
130 | m_direction = TRUE; | 131 | m_direction = TRUE; |
131 | } | 132 | } |
132 | template <class T> | 133 | template <class T> |
133 | ORecordListIterator<T>::~ORecordListIterator() { | 134 | ORecordListIterator<T>::~ORecordListIterator() { |
134 | /* nothing to delete */ | 135 | /* nothing to delete */ |
135 | } | 136 | } |
136 | 137 | ||
137 | template <class T> | 138 | template <class T> |
138 | ORecordListIterator<T>::ORecordListIterator( const ORecordListIterator<T>& it) { | 139 | ORecordListIterator<T>::ORecordListIterator( const ORecordListIterator<T>& it) { |
139 | // qWarning("ORecordListIterator copy c'tor"); | 140 | // qWarning("ORecordListIterator copy c'tor"); |
140 | m_uids = it.m_uids; | 141 | m_uids = it.m_uids; |
141 | m_current = it.m_current; | 142 | m_current = it.m_current; |
142 | m_temp = it.m_temp; | 143 | m_temp = it.m_temp; |
143 | m_end = it.m_end; | 144 | m_end = it.m_end; |
144 | m_record = it.m_record; | 145 | m_record = it.m_record; |
145 | m_direction = it.m_direction; | 146 | m_direction = it.m_direction; |
146 | } | 147 | } |
147 | 148 | ||
148 | template <class T> | 149 | template <class T> |
149 | ORecordListIterator<T> &ORecordListIterator<T>::operator=( const ORecordListIterator<T>& it) { | 150 | ORecordListIterator<T> &ORecordListIterator<T>::operator=( const ORecordListIterator<T>& it) { |
150 | m_uids = it.m_uids; | 151 | m_uids = it.m_uids; |
151 | m_current = it.m_current; | 152 | m_current = it.m_current; |
152 | m_temp = it.m_temp; | 153 | m_temp = it.m_temp; |
153 | m_end = it.m_end; | 154 | m_end = it.m_end; |
154 | m_record = it.m_record; | 155 | m_record = it.m_record; |
155 | 156 | ||
156 | return *this; | 157 | return *this; |
157 | } | 158 | } |
158 | 159 | ||
159 | template <class T> | 160 | template <class T> |
160 | T ORecordListIterator<T>::operator*() { | 161 | T ORecordListIterator<T>::operator*() { |
161 | qWarning("operator* %d %d", m_current, m_uids[m_current] ); | 162 | qWarning("operator* %d %d", m_current, m_uids[m_current] ); |
162 | if (!m_end ) | 163 | if (!m_end ) |
163 | m_record = m_temp->find( m_uids[m_current], m_uids, m_current, | 164 | m_record = m_temp->find( m_uids[m_current], m_uids, m_current, |
164 | m_direction ? Base::Forward : | 165 | m_direction ? Base::Forward : |
165 | Base::Reverse ); | 166 | Base::Reverse ); |
166 | else | 167 | else |
167 | m_record = T(); | 168 | m_record = T(); |
168 | 169 | ||
169 | return m_record; | 170 | return m_record; |
170 | } | 171 | } |
171 | 172 | ||
172 | template <class T> | 173 | template <class T> |
173 | ORecordListIterator<T> &ORecordListIterator<T>::operator++() { | 174 | ORecordListIterator<T> &ORecordListIterator<T>::operator++() { |
174 | m_direction = true; | 175 | m_direction = true; |
175 | if (m_current < m_uids.count() ) { | 176 | if (m_current < m_uids.count() ) { |
176 | m_end = false; | 177 | m_end = false; |
177 | ++m_current; | 178 | ++m_current; |
178 | }else | 179 | }else |
179 | m_end = true; | 180 | m_end = true; |
180 | 181 | ||
181 | return *this; | 182 | return *this; |
182 | } | 183 | } |
183 | template <class T> | 184 | template <class T> |
184 | ORecordListIterator<T> &ORecordListIterator<T>::operator--() { | 185 | ORecordListIterator<T> &ORecordListIterator<T>::operator--() { |
185 | m_direction = false; | 186 | m_direction = false; |
186 | if ( m_current > 0 ) { | 187 | if ( m_current > 0 ) { |
187 | --m_current; | 188 | --m_current; |
188 | m_end = false; | 189 | m_end = false; |
189 | } else | 190 | } else |
190 | m_end = true; | 191 | m_end = true; |
191 | 192 | ||
192 | return *this; | 193 | return *this; |
193 | } | 194 | } |
194 | 195 | ||
195 | template <class T> | 196 | template <class T> |
196 | bool ORecordListIterator<T>::operator==( const ORecordListIterator<T>& it ) { | 197 | bool ORecordListIterator<T>::operator==( const ORecordListIterator<T>& it ) { |
197 | 198 | ||
198 | /* if both are at we're the same.... */ | 199 | /* if both are at we're the same.... */ |
199 | if ( m_end == it.m_end ) return true; | 200 | if ( m_end == it.m_end ) return true; |
200 | 201 | ||
201 | if ( m_uids != it.m_uids ) return false; | 202 | if ( m_uids != it.m_uids ) return false; |
202 | if ( m_current != it.m_current ) return false; | 203 | if ( m_current != it.m_current ) return false; |
203 | if ( m_temp != it.m_temp ) return false; | 204 | if ( m_temp != it.m_temp ) return false; |
204 | 205 | ||
205 | return true; | 206 | return true; |
206 | } | 207 | } |
207 | template <class T> | 208 | template <class T> |
208 | bool ORecordListIterator<T>::operator!=( const ORecordListIterator<T>& it ) { | 209 | bool ORecordListIterator<T>::operator!=( const ORecordListIterator<T>& it ) { |
209 | return !(*this == it ); | 210 | return !(*this == it ); |
210 | } | 211 | } |
211 | template <class T> | 212 | template <class T> |
212 | ORecordListIterator<T>::ORecordListIterator( const QArray<int> uids, | 213 | ORecordListIterator<T>::ORecordListIterator( const QArray<int> uids, |
213 | const Base* t ) | 214 | const Base* t ) |
214 | : m_uids( uids ), m_current( 0 ), m_temp( t ), m_end( false ), | 215 | : m_uids( uids ), m_current( 0 ), m_temp( t ), m_end( false ), |
215 | m_direction( false ) | 216 | m_direction( false ) |
216 | { | 217 | { |
217 | } | 218 | } |
218 | template <class T> | 219 | template <class T> |
219 | uint ORecordListIterator<T>::current()const { | 220 | uint ORecordListIterator<T>::current()const { |
220 | return m_current; | 221 | return m_current; |
221 | } | 222 | } |
222 | template <class T> | 223 | template <class T> |
223 | void ORecordListIterator<T>::setCurrent( uint cur ) { | 224 | void ORecordListIterator<T>::setCurrent( uint cur ) { |
224 | if( cur < m_uids.count() ) { | 225 | if( cur < m_uids.count() ) { |
225 | m_end = false; | 226 | m_end = false; |
226 | m_current= cur; | 227 | m_current= cur; |
227 | } | 228 | } |
228 | } | 229 | } |
229 | template <class T> | 230 | template <class T> |
230 | uint ORecordListIterator<T>::count()const { | 231 | uint ORecordListIterator<T>::count()const { |
231 | return m_uids.count(); | 232 | return m_uids.count(); |
232 | } | 233 | } |
233 | template <class T> | 234 | template <class T> |
234 | ORecordList<T>::ORecordList( const QArray<int>& ids, | 235 | ORecordList<T>::ORecordList( const QArray<int>& ids, |
235 | const Base* acc ) | 236 | const Base* acc ) |
236 | : m_ids( ids ), m_acc( acc ) | 237 | : m_ids( ids ), m_acc( acc ) |
237 | { | 238 | { |
238 | } | 239 | } |
239 | template <class T> | 240 | template <class T> |
240 | ORecordList<T>::~ORecordList() { | 241 | ORecordList<T>::~ORecordList() { |
241 | /* nothing to do here */ | 242 | /* nothing to do here */ |
242 | } | 243 | } |
243 | template <class T> | 244 | template <class T> |
244 | ORecordList<T>::Iterator ORecordList<T>::begin() { | 245 | ORecordList<T>::Iterator ORecordList<T>::begin() { |
245 | Iterator it( m_ids, m_acc ); | 246 | Iterator it( m_ids, m_acc ); |
246 | return it; | 247 | return it; |
247 | } | 248 | } |
248 | template <class T> | 249 | template <class T> |
249 | ORecordList<T>::Iterator ORecordList<T>::end() { | 250 | ORecordList<T>::Iterator ORecordList<T>::end() { |
250 | Iterator it( m_ids, m_acc ); | 251 | Iterator it( m_ids, m_acc ); |
251 | it.m_end = true; | 252 | it.m_end = true; |
252 | it.m_current = m_ids.count(); | 253 | it.m_current = m_ids.count(); |
253 | 254 | ||
254 | return it; | 255 | return it; |
255 | } | 256 | } |
256 | template <class T> | 257 | template <class T> |
257 | uint ORecordList<T>::count()const { | 258 | uint ORecordList<T>::count()const { |
258 | return m_ids.count(); | 259 | return m_ids.count(); |
259 | } | 260 | } |
260 | template <class T> | 261 | template <class T> |
261 | T ORecordList<T>::operator[]( uint i ) { | 262 | T ORecordList<T>::operator[]( uint i ) { |
262 | /* forward */ | 263 | /* forward */ |
263 | return m_acc->find( m_ids[i], m_ids, i ); | 264 | return m_acc->find( m_ids[i], m_ids, i ); |
264 | } | 265 | } |
266 | template <class T> | ||
267 | int ORecordList<T>::uidAt( uint i ) { | ||
268 | return m_ids[i]; | ||
269 | } | ||
265 | #endif | 270 | #endif |