Diffstat (limited to 'libopie/pim/opimaccesstemplate.h') (more/less context) (ignore whitespace changes)
-rw-r--r-- | libopie/pim/opimaccesstemplate.h | 7 |
1 files changed, 6 insertions, 1 deletions
diff --git a/libopie/pim/opimaccesstemplate.h b/libopie/pim/opimaccesstemplate.h index 50cb1e4..c5523a8 100644 --- a/libopie/pim/opimaccesstemplate.h +++ b/libopie/pim/opimaccesstemplate.h | |||
@@ -1,254 +1,259 @@ | |||
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 | * c'tor BackEnd | 30 | * c'tor BackEnd |
31 | */ | 31 | */ |
32 | OPimAccessTemplate( BackEnd* end); | 32 | OPimAccessTemplate( BackEnd* end); |
33 | virtual ~OPimAccessTemplate(); | 33 | virtual ~OPimAccessTemplate(); |
34 | 34 | ||
35 | /** | 35 | /** |
36 | * load from the backend | 36 | * load from the backend |
37 | */ | 37 | */ |
38 | virtual bool load(); | 38 | virtual bool load(); |
39 | 39 | ||
40 | /** Reload database. | 40 | /** Reload database. |
41 | * You should execute this function if the external database | 41 | * You should execute this function if the external database |
42 | * was changed. | 42 | * was changed. |
43 | * This function will load the external database and afterwards | 43 | * This function will load the external database and afterwards |
44 | * rejoin the local changes. Therefore the local database will be set consistent. | 44 | * rejoin the local changes. Therefore the local database will be set consistent. |
45 | */ | 45 | */ |
46 | virtual bool reload(); | 46 | virtual bool reload(); |
47 | 47 | ||
48 | /** Save contacts database. | 48 | /** Save contacts database. |
49 | * Save is more a "commit". After calling this function, all changes are public available. | 49 | * Save is more a "commit". After calling this function, all changes are public available. |
50 | * @return true if successful | 50 | * @return true if successful |
51 | */ | 51 | */ |
52 | virtual bool save(); | 52 | virtual bool save(); |
53 | 53 | ||
54 | /** | 54 | /** |
55 | * if the resource was changed externally | 55 | * if the resource was changed externally |
56 | * You should use the signal handling instead of polling possible changes ! | 56 | * You should use the signal handling instead of polling possible changes ! |
57 | * zecke: Do you implement a signal for otodoaccess ? | 57 | * zecke: Do you implement a signal for otodoaccess ? |
58 | */ | 58 | */ |
59 | bool wasChangedExternally()const; | 59 | bool wasChangedExternally()const; |
60 | 60 | ||
61 | /** | 61 | /** |
62 | * return a List of records | 62 | * return a List of records |
63 | * you can iterate over them | 63 | * you can iterate over them |
64 | */ | 64 | */ |
65 | virtual List allRecords()const; | 65 | virtual List allRecords()const; |
66 | 66 | ||
67 | /** | 67 | /** |
68 | * queryByExample. | 68 | * queryByExample. |
69 | * @see otodoaccess, ocontactaccess | 69 | * @see otodoaccess, ocontactaccess |
70 | */ | 70 | */ |
71 | virtual List queryByExample( const T& t, int querySettings ); | 71 | virtual List queryByExample( const T& t, int querySettings ); |
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 | * @param t The item to add. | 92 | * @param t The item to add. |
93 | * @return <i>true</i> if added successfully. | 93 | * @return <i>true</i> if added successfully. |
94 | */ | 94 | */ |
95 | virtual bool add( const T& t ) ; | 95 | virtual bool add( const T& t ) ; |
96 | 96 | ||
97 | /* only the uid matters */ | 97 | /* only the uid matters */ |
98 | /** | 98 | /** |
99 | * remove T from the backend | 99 | * remove T from the backend |
100 | * @param t The item to remove | 100 | * @param t The item to remove |
101 | * @return <i>true</i> if successful. | 101 | * @return <i>true</i> if successful. |
102 | */ | 102 | */ |
103 | virtual bool remove( const T& t ); | 103 | virtual bool remove( const T& t ); |
104 | 104 | ||
105 | /** | 105 | /** |
106 | * remove the OPimRecord with uid | 106 | * remove the OPimRecord with uid |
107 | * @param uid The ID of the item to remove | 107 | * @param uid The ID of the item to remove |
108 | * @return <i>true</i> if successful. | 108 | * @return <i>true</i> if successful. |
109 | */ | 109 | */ |
110 | virtual bool remove( int uid ); | 110 | virtual bool remove( int uid ); |
111 | 111 | ||
112 | /** | 112 | /** |
113 | * replace T from backend | 113 | * replace T from backend |
114 | * @param t The item to replace | 114 | * @param t The item to replace |
115 | * @return <i>true</i> if successful. | 115 | * @return <i>true</i> if successful. |
116 | */ | 116 | */ |
117 | virtual bool replace( const T& t) ; | 117 | virtual bool replace( const T& t) ; |
118 | 118 | ||
119 | void setReadAhead( uint count ); | ||
119 | /** | 120 | /** |
120 | * @internal | 121 | * @internal |
121 | */ | 122 | */ |
122 | void cache( const T& )const; | 123 | void cache( const T& )const; |
123 | void setSaneCacheSize( int ); | 124 | void setSaneCacheSize( int ); |
124 | protected: | 125 | protected: |
125 | /** | 126 | /** |
126 | * invalidate the cache | 127 | * invalidate the cache |
127 | */ | 128 | */ |
128 | void invalidateCache(); | 129 | void invalidateCache(); |
129 | 130 | ||
130 | void setBackEnd( BackEnd* end ); | 131 | void setBackEnd( BackEnd* end ); |
131 | /** | 132 | /** |
132 | * returns the backend | 133 | * returns the backend |
133 | */ | 134 | */ |
134 | BackEnd* backEnd(); | 135 | BackEnd* backEnd(); |
135 | BackEnd* m_backEnd; | 136 | BackEnd* m_backEnd; |
136 | Cache m_cache; | 137 | Cache m_cache; |
137 | 138 | ||
138 | }; | 139 | }; |
139 | 140 | ||
140 | template <class T> | 141 | template <class T> |
141 | OPimAccessTemplate<T>::OPimAccessTemplate( BackEnd* end ) | 142 | OPimAccessTemplate<T>::OPimAccessTemplate( BackEnd* end ) |
142 | : OTemplateBase<T>(), m_backEnd( end ) | 143 | : OTemplateBase<T>(), m_backEnd( end ) |
143 | { | 144 | { |
144 | if (end ) | 145 | if (end ) |
145 | end->setFrontend( this ); | 146 | end->setFrontend( this ); |
146 | } | 147 | } |
147 | template <class T> | 148 | template <class T> |
148 | OPimAccessTemplate<T>::~OPimAccessTemplate() { | 149 | OPimAccessTemplate<T>::~OPimAccessTemplate() { |
149 | qWarning("~OPimAccessTemplate<T>"); | 150 | qWarning("~OPimAccessTemplate<T>"); |
150 | delete m_backEnd; | 151 | delete m_backEnd; |
151 | } | 152 | } |
152 | template <class T> | 153 | template <class T> |
153 | bool OPimAccessTemplate<T>::load() { | 154 | bool OPimAccessTemplate<T>::load() { |
154 | invalidateCache(); | 155 | invalidateCache(); |
155 | return m_backEnd->load(); | 156 | return m_backEnd->load(); |
156 | } | 157 | } |
157 | template <class T> | 158 | template <class T> |
158 | bool OPimAccessTemplate<T>::reload() { | 159 | bool OPimAccessTemplate<T>::reload() { |
159 | invalidateCache(); // zecke: I think this should be added (se) | 160 | invalidateCache(); // zecke: I think this should be added (se) |
160 | return m_backEnd->reload(); | 161 | return m_backEnd->reload(); |
161 | } | 162 | } |
162 | template <class T> | 163 | template <class T> |
163 | bool OPimAccessTemplate<T>::save() { | 164 | bool OPimAccessTemplate<T>::save() { |
164 | return m_backEnd->save(); | 165 | return m_backEnd->save(); |
165 | } | 166 | } |
166 | template <class T> | 167 | template <class T> |
167 | OPimAccessTemplate<T>::List OPimAccessTemplate<T>::allRecords()const { | 168 | OPimAccessTemplate<T>::List OPimAccessTemplate<T>::allRecords()const { |
168 | QArray<int> ints = m_backEnd->allRecords(); | 169 | QArray<int> ints = m_backEnd->allRecords(); |
169 | List lis(ints, this ); | 170 | List lis(ints, this ); |
170 | return lis; | 171 | return lis; |
171 | } | 172 | } |
172 | template <class T> | 173 | template <class T> |
173 | OPimAccessTemplate<T>::List | 174 | OPimAccessTemplate<T>::List |
174 | OPimAccessTemplate<T>::queryByExample( const T& t, int sortOrder ) { | 175 | OPimAccessTemplate<T>::queryByExample( const T& t, int sortOrder ) { |
175 | QArray<int> ints = m_backEnd->queryByExample( t, sortOrder ); | 176 | QArray<int> ints = m_backEnd->queryByExample( t, sortOrder ); |
176 | 177 | ||
177 | List lis(ints, this ); | 178 | List lis(ints, this ); |
178 | return lis; | 179 | return lis; |
179 | } | 180 | } |
180 | template <class T> | 181 | template <class T> |
181 | T OPimAccessTemplate<T>::find( int uid ) const{ | 182 | T OPimAccessTemplate<T>::find( int uid ) const{ |
182 | T t = m_backEnd->find( uid ); | 183 | T t = m_backEnd->find( uid ); |
183 | cache( t ); | 184 | cache( t ); |
184 | return t; | 185 | return t; |
185 | } | 186 | } |
186 | template <class T> | 187 | template <class T> |
187 | T OPimAccessTemplate<T>::find( int uid, const QArray<int>& ar, | 188 | T OPimAccessTemplate<T>::find( int uid, const QArray<int>& ar, |
188 | uint current, CacheDirection dir )const { | 189 | uint current, CacheDirection dir )const { |
189 | /* | 190 | /* |
190 | * better do T.isEmpty() | 191 | * better do T.isEmpty() |
191 | * after a find this way we would | 192 | * after a find this way we would |
192 | * avoid two finds in QCache... | 193 | * avoid two finds in QCache... |
193 | */ | 194 | */ |
194 | // qWarning("find it now %d", uid ); | 195 | // qWarning("find it now %d", uid ); |
195 | if (m_cache.contains( uid ) ) { | 196 | if (m_cache.contains( uid ) ) { |
196 | return m_cache.find( uid ); | 197 | return m_cache.find( uid ); |
197 | } | 198 | } |
198 | 199 | ||
199 | T t = m_backEnd->find( uid, ar, current, dir ); | 200 | T t = m_backEnd->find( uid, ar, current, dir ); |
200 | cache( t ); | 201 | cache( t ); |
201 | return t; | 202 | return t; |
202 | } | 203 | } |
203 | template <class T> | 204 | template <class T> |
204 | void OPimAccessTemplate<T>::clear() { | 205 | void OPimAccessTemplate<T>::clear() { |
205 | invalidateCache(); | 206 | invalidateCache(); |
206 | m_backEnd->clear(); | 207 | m_backEnd->clear(); |
207 | } | 208 | } |
208 | template <class T> | 209 | template <class T> |
209 | bool OPimAccessTemplate<T>::add( const T& t ) { | 210 | bool OPimAccessTemplate<T>::add( const T& t ) { |
210 | cache( t ); | 211 | cache( t ); |
211 | return m_backEnd->add( t ); | 212 | return m_backEnd->add( t ); |
212 | } | 213 | } |
213 | template <class T> | 214 | template <class T> |
214 | bool OPimAccessTemplate<T>::remove( const T& t ) { | 215 | bool OPimAccessTemplate<T>::remove( const T& t ) { |
215 | return remove( t.uid() ); | 216 | return remove( t.uid() ); |
216 | } | 217 | } |
217 | template <class T> | 218 | template <class T> |
218 | bool OPimAccessTemplate<T>::remove( int uid ) { | 219 | bool OPimAccessTemplate<T>::remove( int uid ) { |
219 | m_cache.remove( uid ); | 220 | m_cache.remove( uid ); |
220 | return m_backEnd->remove( uid ); | 221 | return m_backEnd->remove( uid ); |
221 | } | 222 | } |
222 | template <class T> | 223 | template <class T> |
223 | bool OPimAccessTemplate<T>::replace( const T& t ) { | 224 | bool OPimAccessTemplate<T>::replace( const T& t ) { |
224 | m_cache.replace( t ); | 225 | m_cache.replace( t ); |
225 | return m_backEnd->replace( t ); | 226 | return m_backEnd->replace( t ); |
226 | } | 227 | } |
227 | template <class T> | 228 | template <class T> |
228 | void OPimAccessTemplate<T>::invalidateCache() { | 229 | void OPimAccessTemplate<T>::invalidateCache() { |
229 | m_cache.invalidate(); | 230 | m_cache.invalidate(); |
230 | } | 231 | } |
231 | template <class T> | 232 | template <class T> |
232 | OPimAccessTemplate<T>::BackEnd* OPimAccessTemplate<T>::backEnd() { | 233 | OPimAccessTemplate<T>::BackEnd* OPimAccessTemplate<T>::backEnd() { |
233 | return m_backEnd; | 234 | return m_backEnd; |
234 | } | 235 | } |
235 | template <class T> | 236 | template <class T> |
236 | bool OPimAccessTemplate<T>::wasChangedExternally()const { | 237 | bool OPimAccessTemplate<T>::wasChangedExternally()const { |
237 | return false; | 238 | return false; |
238 | } | 239 | } |
239 | template <class T> | 240 | template <class T> |
240 | void OPimAccessTemplate<T>::setBackEnd( BackEnd* end ) { | 241 | void OPimAccessTemplate<T>::setBackEnd( BackEnd* end ) { |
241 | m_backEnd = end; | 242 | m_backEnd = end; |
242 | if (m_backEnd ) | 243 | if (m_backEnd ) |
243 | m_backEnd->setFrontend( this ); | 244 | m_backEnd->setFrontend( this ); |
244 | } | 245 | } |
245 | template <class T> | 246 | template <class T> |
246 | void OPimAccessTemplate<T>::cache( const T& t ) const{ | 247 | void OPimAccessTemplate<T>::cache( const T& t ) const{ |
247 | /* hacky we need to work around the const*/ | 248 | /* hacky we need to work around the const*/ |
248 | ((OPimAccessTemplate<T>*)this)->m_cache.add( t ); | 249 | ((OPimAccessTemplate<T>*)this)->m_cache.add( t ); |
249 | } | 250 | } |
250 | template <class T> | 251 | template <class T> |
251 | void OPimAccessTemplate<T>::setSaneCacheSize( int size ) { | 252 | void OPimAccessTemplate<T>::setSaneCacheSize( int size ) { |
252 | m_cache.setSize( size ); | 253 | m_cache.setSize( size ); |
253 | } | 254 | } |
255 | template <class T> | ||
256 | void OPimAccessTemplate<T>::setReadAhead( uint count ) { | ||
257 | m_backEnd->setReadAhead( count ); | ||
258 | } | ||
254 | #endif | 259 | #endif |