summaryrefslogtreecommitdiff
path: root/libopie2/opiepim/core/opimaccesstemplate.h
Unidiff
Diffstat (limited to 'libopie2/opiepim/core/opimaccesstemplate.h') (more/less context) (ignore whitespace changes)
-rw-r--r--libopie2/opiepim/core/opimaccesstemplate.h28
1 files changed, 25 insertions, 3 deletions
diff --git a/libopie2/opiepim/core/opimaccesstemplate.h b/libopie2/opiepim/core/opimaccesstemplate.h
index f1bcc44..d4c5fbb 100644
--- a/libopie2/opiepim/core/opimaccesstemplate.h
+++ b/libopie2/opiepim/core/opimaccesstemplate.h
@@ -1,51 +1,52 @@
1/* 1/*
2 This file is part of the Opie Project 2 This file is part of the Opie Project
3 Copyright (C) The Main Author <main-author@whereever.org> 3 Copyright (C) Holger Freyther <zecke@handhelds.org>
4 Copyright (C) Stefan Eilers <eilers.stefan@epost.de>
4 =. Copyright (C) The Opie Team <opie-devel@handhelds.org> 5 =. Copyright (C) The Opie Team <opie-devel@handhelds.org>
5 .=l. 6 .=l.
6 .>+-= 7 .>+-=
7 _;:, .> :=|. This program is free software; you can 8 _;:, .> :=|. This program is free software; you can
8.> <`_, > . <= redistribute it and/or modify it under 9.> <`_, > . <= redistribute it and/or modify it under
9:`=1 )Y*s>-.-- : the terms of the GNU Library General Public 10:`=1 )Y*s>-.-- : the terms of the GNU Library General Public
10.="- .-=="i, .._ License as published by the Free Software 11.="- .-=="i, .._ License as published by the Free Software
11 - . .-<_> .<> Foundation; either version 2 of the License, 12 - . .-<_> .<> Foundation; either version 2 of the License,
12 ._= =} : or (at your option) any later version. 13 ._= =} : or (at your option) any later version.
13 .%`+i> _;_. 14 .%`+i> _;_.
14 .i_,=:_. -<s. This program is distributed in the hope that 15 .i_,=:_. -<s. This program is distributed in the hope that
15 + . -:. = it will be useful, but WITHOUT ANY WARRANTY; 16 + . -:. = it will be useful, but WITHOUT ANY WARRANTY;
16 : .. .:, . . . without even the implied warranty of 17 : .. .:, . . . without even the implied warranty of
17 =_ + =;=|` MERCHANTABILITY or FITNESS FOR A 18 =_ + =;=|` MERCHANTABILITY or FITNESS FOR A
18 _.=:. : :=>`: PARTICULAR PURPOSE. See the GNU 19 _.=:. : :=>`: PARTICULAR PURPOSE. See the GNU
19..}^=.= = ; Library General Public License for more 20..}^=.= = ; Library General Public License for more
20++= -. .` .: details. 21++= -. .` .: details.
21 : = ...= . :.=- 22 : = ...= . :.=-
22 -. .:....=;==+<; You should have received a copy of the GNU 23 -. .:....=;==+<; You should have received a copy of the GNU
23 -_. . . )=. = Library General Public License along with 24 -_. . . )=. = Library General Public License along with
24 -- :-=` this library; see the file COPYING.LIB. 25 -- :-=` this library; see the file COPYING.LIB.
25 If not, write to the Free Software Foundation, 26 If not, write to the Free Software Foundation,
26 Inc., 59 Temple Place - Suite 330, 27 Inc., 59 Temple Place - Suite 330,
27 Boston, MA 02111-1307, USA. 28 Boston, MA 02111-1307, USA.
28*/ 29*/
29#ifndef OPIE_PIM_ACCESS_TEMPLATE_H 30#ifndef OPIE_PIM_ACCESS_TEMPLATE_H
30#define OPIE_PIM_ACCESS_TEMPLATE_H 31#define OPIE_PIM_ACCESS_TEMPLATE_H
31 32
32#include <qarray.h> 33#include <qarray.h>
33 34
34#include <opie2/opimrecord.h> 35#include <opie2/opimrecord.h>
35#include <opie2/opimaccessbackend.h> 36#include <opie2/opimaccessbackend.h>
36#include <opie2/opimrecordlist.h> 37#include <opie2/opimrecordlist.h>
37 38
38#include <opie2/opimcache.h> 39#include <opie2/opimcache.h>
39#include <opie2/opimtemplatebase.h> 40#include <opie2/opimtemplatebase.h>
40 41
41namespace Opie { 42namespace Opie {
42 43
43class OPimAccessTemplatePrivate; 44class OPimAccessTemplatePrivate;
44/** 45/**
45 * Thats the frontend to our OPIE PIM 46 * Thats the frontend to our OPIE PIM
46 * Library. Either you want to use it's 47 * Library. Either you want to use it's
47 * interface or you want to implement 48 * interface or you want to implement
48 * your own Access lib 49 * your own Access lib
49 * Just create a OPimRecord and inherit from 50 * Just create a OPimRecord and inherit from
50 * the plugins 51 * the plugins
51 */ 52 */
@@ -92,96 +93,103 @@ public:
92 * if the resource was changed externally 93 * if the resource was changed externally
93 * You should use the signal handling instead of polling possible changes ! 94 * You should use the signal handling instead of polling possible changes !
94 * zecke: Do you implement a signal for otodoaccess ? 95 * zecke: Do you implement a signal for otodoaccess ?
95 */ 96 */
96 bool wasChangedExternally()const; 97 bool wasChangedExternally()const;
97 98
98 /** 99 /**
99 * return a List of records 100 * return a List of records
100 * you can iterate over them 101 * you can iterate over them
101 */ 102 */
102 virtual List allRecords()const; 103 virtual List allRecords()const;
103 104
104 /** 105 /**
105 * return a List of records 106 * return a List of records
106 * that match the regex 107 * that match the regex
107 */ 108 */
108 virtual List matchRegexp( const QRegExp &r ) const; 109 virtual List matchRegexp( const QRegExp &r ) const;
109 110
110 /** 111 /**
111 * queryByExample. 112 * queryByExample.
112 * @see otodoaccess, ocontactaccess 113 * @see otodoaccess, ocontactaccess
113 */ 114 */
114 virtual List queryByExample( const T& t, int querySettings, const QDateTime& d = QDateTime() ); 115 virtual List queryByExample( const T& t, int querySettings, const QDateTime& d = QDateTime() );
115 116
116 /** 117 /**
117 * find the OPimRecord uid 118 * find the OPimRecord uid
118 */ 119 */
119 virtual T find( int uid )const; 120 virtual T find( int uid )const;
120 121
121 /** 122 /**
122 * read ahead cache find method ;) 123 * read ahead cache find method ;)
123 */ 124 */
124 virtual T find( int uid, const QArray<int>&, 125 virtual T find( int uid, const QArray<int>&,
125 uint current, typename OTemplateBase<T>::CacheDirection dir = OTemplateBase<T>::Forward )const; 126 uint current, typename OTemplateBase<T>::CacheDirection dir = OTemplateBase<T>::Forward )const;
126 127
127 /* invalidate cache here */ 128 /* invalidate cache here */
128 /** 129 /**
129 * clears the backend and invalidates the backend 130 * clears the backend and invalidates the backend
130 */ 131 */
131 void clear() ; 132 void clear() ;
132 133
133 /** 134 /**
134 * add T to the backend 135 * add T to the backend
135 * @param t The item to add. 136 * @param t The item to add.
136 * @return <i>true</i> if added successfully. 137 * @return <i>true</i> if added successfully.
137 */ 138 */
138 virtual bool add( const T& t ) ; 139 virtual bool add( const T& t ) ;
139 bool add( const OPimRecord& ); 140 bool add( const OPimRecord& );
141 // Needed for real generic access (eilers)
142 // Info: Take this if you are working with OPimRecord, which is a generic base class, and
143 // you need to add it into any database, you cannot generate a reference to
144 // it and casting may be not approriate, too.
145 // But take care that the accessing database is compatible to the real type of OPimRecord !!
146 bool add( const OPimRecord* );
147
140 148
141 /* only the uid matters */ 149 /* only the uid matters */
142 /** 150 /**
143 * remove T from the backend 151 * remove T from the backend
144 * @param t The item to remove 152 * @param t The item to remove
145 * @return <i>true</i> if successful. 153 * @return <i>true</i> if successful.
146 */ 154 */
147 virtual bool remove( const T& t ); 155 virtual bool remove( const T& t );
148 156
149 /** 157 /**
150 * remove the OPimRecord with uid 158 * remove the OPimRecord with uid
151 * @param uid The ID of the item to remove 159 * @param uid The ID of the item to remove
152 * @return <i>true</i> if successful. 160 * @return <i>true</i> if successful.
153 */ 161 */
154 bool remove( int uid ); 162 bool remove( int uid );
155 bool remove( const OPimRecord& ); 163 bool remove( const OPimRecord& );
156 164
157 /** 165 /**
158 * replace T from backend 166 * replace T from backend
159 * @param t The item to replace 167 * @param t The item to replace
160 * @return <i>true</i> if successful. 168 * @return <i>true</i> if successful.
161 */ 169 */
162 virtual bool replace( const T& t) ; 170 virtual bool replace( const T& t) ;
163 171
164 void setReadAhead( uint count ); 172 void setReadAhead( uint count );
165 /** 173 /**
166 * @internal 174 * @internal
167 */ 175 */
168 void cache( const T& )const; 176 void cache( const T& )const;
169 void setSaneCacheSize( int ); 177 void setSaneCacheSize( int );
170 178
171 QArray<int> records()const; 179 QArray<int> records()const;
172protected: 180protected:
173 /** 181 /**
174 * invalidate the cache 182 * invalidate the cache
175 */ 183 */
176 void invalidateCache(); 184 void invalidateCache();
177 185
178 void setBackEnd( BackEnd* end ); 186 void setBackEnd( BackEnd* end );
179 /** 187 /**
180 * returns the backend 188 * returns the backend
181 */ 189 */
182 BackEnd* backEnd(); 190 BackEnd* backEnd();
183 BackEnd* m_backEnd; 191 BackEnd* m_backEnd;
184 Cache m_cache; 192 Cache m_cache;
185 193
186private: 194private:
187 OPimAccessTemplatePrivate *d; 195 OPimAccessTemplatePrivate *d;
@@ -226,105 +234,119 @@ typename OPimAccessTemplate<T>::List OPimAccessTemplate<T>::matchRegexp( const Q
226 List lis(ints, this ); 234 List lis(ints, this );
227 return lis; 235 return lis;
228} 236}
229template <class T> 237template <class T>
230QArray<int> OPimAccessTemplate<T>::records()const { 238QArray<int> OPimAccessTemplate<T>::records()const {
231 return m_backEnd->allRecords(); 239 return m_backEnd->allRecords();
232} 240}
233template <class T> 241template <class T>
234typename OPimAccessTemplate<T>::List 242typename OPimAccessTemplate<T>::List
235OPimAccessTemplate<T>::queryByExample( const T& t, int settings, const QDateTime& d ) { 243OPimAccessTemplate<T>::queryByExample( const T& t, int settings, const QDateTime& d ) {
236 QArray<int> ints = m_backEnd->queryByExample( t, settings, d ); 244 QArray<int> ints = m_backEnd->queryByExample( t, settings, d );
237 245
238 List lis(ints, this ); 246 List lis(ints, this );
239 return lis; 247 return lis;
240} 248}
241template <class T> 249template <class T>
242T OPimAccessTemplate<T>::find( int uid ) const{ 250T OPimAccessTemplate<T>::find( int uid ) const{
243 T t = m_backEnd->find( uid ); 251 T t = m_backEnd->find( uid );
244 cache( t ); 252 cache( t );
245 return t; 253 return t;
246} 254}
247template <class T> 255template <class T>
248T OPimAccessTemplate<T>::find( int uid, const QArray<int>& ar, 256T OPimAccessTemplate<T>::find( int uid, const QArray<int>& ar,
249 uint current, typename OTemplateBase<T>::CacheDirection dir )const { 257 uint current, typename OTemplateBase<T>::CacheDirection dir )const {
250 /* 258 /*
251 * better do T.isEmpty() 259 * better do T.isEmpty()
252 * after a find this way we would 260 * after a find this way we would
253 * avoid two finds in QCache... 261 * avoid two finds in QCache...
254 */ 262 */
255 // qWarning("find it now %d", uid ); 263 // qWarning("find it now %d", uid );
256 if (m_cache.contains( uid ) ) { 264 if (m_cache.contains( uid ) ) {
257 return m_cache.find( uid ); 265 return m_cache.find( uid );
258 } 266 }
259 267
260 T t = m_backEnd->find( uid, ar, current, dir ); 268 T t = m_backEnd->find( uid, ar, current, dir );
261 cache( t ); 269 cache( t );
262 return t; 270 return t;
263} 271}
264template <class T> 272template <class T>
265void OPimAccessTemplate<T>::clear() { 273void OPimAccessTemplate<T>::clear() {
266 invalidateCache(); 274 invalidateCache();
267 m_backEnd->clear(); 275 m_backEnd->clear();
268} 276}
269template <class T> 277template <class T>
270bool OPimAccessTemplate<T>::add( const T& t ) { 278bool OPimAccessTemplate<T>::add( const T& t ) {
271 cache( t ); 279 cache( t );
272 return m_backEnd->add( t ); 280 return m_backEnd->add( t );
273} 281}
282
274template <class T> 283template <class T>
275bool OPimAccessTemplate<T>::add( const OPimRecord& rec) { 284bool OPimAccessTemplate<T>::add( const OPimRecord& rec) {
276 /* same type */ 285 /* same type */
277 if ( rec.rtti() == T::rtti() ) { 286 T tempInstance;
278 const T &t = static_cast<const T&>(rec); 287 if ( rec.rtti() == tempInstance.rtti() ) {
288 const T& t = static_cast<const T&>(rec);
279 return add(t); 289 return add(t);
280 } 290 }
281 return false; 291 return false;
282} 292}
293
294template <class T>
295bool OPimAccessTemplate<T>::add( const OPimRecord* rec) {
296 /* same type, but pointer */
297 T tempInstance;
298 if ( rec -> rtti() == tempInstance.rtti() ) {
299 const T* t = static_cast<const T*>(rec);
300 return add( *t );
301 }
302 return false;
303}
304
283template <class T> 305template <class T>
284bool OPimAccessTemplate<T>::remove( const T& t ) { 306bool OPimAccessTemplate<T>::remove( const T& t ) {
285 return remove( t.uid() ); 307 return remove( t.uid() );
286} 308}
287template <class T> 309template <class T>
288bool OPimAccessTemplate<T>::remove( int uid ) { 310bool OPimAccessTemplate<T>::remove( int uid ) {
289 m_cache.remove( uid ); 311 m_cache.remove( uid );
290 return m_backEnd->remove( uid ); 312 return m_backEnd->remove( uid );
291} 313}
292template <class T> 314template <class T>
293bool OPimAccessTemplate<T>::remove( const OPimRecord& rec) { 315bool OPimAccessTemplate<T>::remove( const OPimRecord& rec) {
294 return remove( rec.uid() ); 316 return remove( rec.uid() );
295} 317}
296template <class T> 318template <class T>
297bool OPimAccessTemplate<T>::replace( const T& t ) { 319bool OPimAccessTemplate<T>::replace( const T& t ) {
298 m_cache.replace( t ); 320 m_cache.replace( t );
299 return m_backEnd->replace( t ); 321 return m_backEnd->replace( t );
300} 322}
301template <class T> 323template <class T>
302void OPimAccessTemplate<T>::invalidateCache() { 324void OPimAccessTemplate<T>::invalidateCache() {
303 m_cache.invalidate(); 325 m_cache.invalidate();
304} 326}
305template <class T> 327template <class T>
306typename OPimAccessTemplate<T>::BackEnd* OPimAccessTemplate<T>::backEnd() { 328typename OPimAccessTemplate<T>::BackEnd* OPimAccessTemplate<T>::backEnd() {
307 return m_backEnd; 329 return m_backEnd;
308} 330}
309template <class T> 331template <class T>
310bool OPimAccessTemplate<T>::wasChangedExternally()const { 332bool OPimAccessTemplate<T>::wasChangedExternally()const {
311 return false; 333 return false;
312} 334}
313template <class T> 335template <class T>
314void OPimAccessTemplate<T>::setBackEnd( BackEnd* end ) { 336void OPimAccessTemplate<T>::setBackEnd( BackEnd* end ) {
315 m_backEnd = end; 337 m_backEnd = end;
316 if (m_backEnd ) 338 if (m_backEnd )
317 m_backEnd->setFrontend( this ); 339 m_backEnd->setFrontend( this );
318} 340}
319template <class T> 341template <class T>
320void OPimAccessTemplate<T>::cache( const T& t ) const{ 342void OPimAccessTemplate<T>::cache( const T& t ) const{
321 /* hacky we need to work around the const*/ 343 /* hacky we need to work around the const*/
322 ((OPimAccessTemplate<T>*)this)->m_cache.add( t ); 344 ((OPimAccessTemplate<T>*)this)->m_cache.add( t );
323} 345}
324template <class T> 346template <class T>
325void OPimAccessTemplate<T>::setSaneCacheSize( int size ) { 347void OPimAccessTemplate<T>::setSaneCacheSize( int size ) {
326 m_cache.setSize( size ); 348 m_cache.setSize( size );
327} 349}
328template <class T> 350template <class T>
329void OPimAccessTemplate<T>::setReadAhead( uint count ) { 351void OPimAccessTemplate<T>::setReadAhead( uint count ) {
330 m_backEnd->setReadAhead( count ); 352 m_backEnd->setReadAhead( count );