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.h12
1 files changed, 12 insertions, 0 deletions
diff --git a/libopie2/opiepim/core/opimaccesstemplate.h b/libopie2/opiepim/core/opimaccesstemplate.h
index 6a3a0db..8ff205c 100644
--- a/libopie2/opiepim/core/opimaccesstemplate.h
+++ b/libopie2/opiepim/core/opimaccesstemplate.h
@@ -24,96 +24,102 @@ class OPimAccessTemplate : public OTemplateBase<T> {
24public: 24public:
25 enum Access { 25 enum Access {
26 Random = 0, 26 Random = 0,
27 SortedAccess 27 SortedAccess
28 }; 28 };
29 typedef ORecordList<T> List; 29 typedef ORecordList<T> List;
30 typedef OPimAccessBackend<T> BackEnd; 30 typedef OPimAccessBackend<T> BackEnd;
31 typedef OPimCache<T> Cache; 31 typedef OPimCache<T> Cache;
32 32
33 /** 33 /**
34 * c'tor BackEnd 34 * c'tor BackEnd
35 * enum Access a small hint on how to handle the backend 35 * enum Access a small hint on how to handle the backend
36 */ 36 */
37 OPimAccessTemplate( BackEnd* end); 37 OPimAccessTemplate( BackEnd* end);
38 38
39 virtual ~OPimAccessTemplate(); 39 virtual ~OPimAccessTemplate();
40 40
41 /** 41 /**
42 * load from the backend 42 * load from the backend
43 */ 43 */
44 bool load(); 44 bool load();
45 45
46 /** Reload database. 46 /** Reload database.
47 * You should execute this function if the external database 47 * You should execute this function if the external database
48 * was changed. 48 * was changed.
49 * This function will load the external database and afterwards 49 * This function will load the external database and afterwards
50 * rejoin the local changes. Therefore the local database will be set consistent. 50 * rejoin the local changes. Therefore the local database will be set consistent.
51 */ 51 */
52 virtual bool reload(); 52 virtual bool reload();
53 53
54 /** Save contacts database. 54 /** Save contacts database.
55 * Save is more a "commit". After calling this function, all changes are public available. 55 * Save is more a "commit". After calling this function, all changes are public available.
56 * @return true if successful 56 * @return true if successful
57 */ 57 */
58 bool save(); 58 bool save();
59 59
60 /** 60 /**
61 * if the resource was changed externally 61 * if the resource was changed externally
62 * You should use the signal handling instead of polling possible changes ! 62 * You should use the signal handling instead of polling possible changes !
63 * zecke: Do you implement a signal for otodoaccess ? 63 * zecke: Do you implement a signal for otodoaccess ?
64 */ 64 */
65 bool wasChangedExternally()const; 65 bool wasChangedExternally()const;
66 66
67 /** 67 /**
68 * return a List of records 68 * return a List of records
69 * you can iterate over them 69 * you can iterate over them
70 */ 70 */
71 virtual List allRecords()const; 71 virtual List allRecords()const;
72
73 /**
74 * return a List of records
75 * that match the regex
76 */
77 virtual List matchRegexp( const QRegExp &r ) const;
72 78
73 /** 79 /**
74 * queryByExample. 80 * queryByExample.
75 * @see otodoaccess, ocontactaccess 81 * @see otodoaccess, ocontactaccess
76 */ 82 */
77 virtual List queryByExample( const T& t, int querySettings, const QDateTime& d = QDateTime() ); 83 virtual List queryByExample( const T& t, int querySettings, const QDateTime& d = QDateTime() );
78 84
79 /** 85 /**
80 * find the OPimRecord uid 86 * find the OPimRecord uid
81 */ 87 */
82 virtual T find( int uid )const; 88 virtual T find( int uid )const;
83 89
84 /** 90 /**
85 * read ahead cache find method ;) 91 * read ahead cache find method ;)
86 */ 92 */
87 virtual T find( int uid, const QArray<int>&, 93 virtual T find( int uid, const QArray<int>&,
88 uint current, typename OTemplateBase<T>::CacheDirection dir = OTemplateBase<T>::Forward )const; 94 uint current, typename OTemplateBase<T>::CacheDirection dir = OTemplateBase<T>::Forward )const;
89 95
90 /* invalidate cache here */ 96 /* invalidate cache here */
91 /** 97 /**
92 * clears the backend and invalidates the backend 98 * clears the backend and invalidates the backend
93 */ 99 */
94 void clear() ; 100 void clear() ;
95 101
96 /** 102 /**
97 * add T to the backend 103 * add T to the backend
98 * @param t The item to add. 104 * @param t The item to add.
99 * @return <i>true</i> if added successfully. 105 * @return <i>true</i> if added successfully.
100 */ 106 */
101 virtual bool add( const T& t ) ; 107 virtual bool add( const T& t ) ;
102 bool add( const OPimRecord& ); 108 bool add( const OPimRecord& );
103 109
104 /* only the uid matters */ 110 /* only the uid matters */
105 /** 111 /**
106 * remove T from the backend 112 * remove T from the backend
107 * @param t The item to remove 113 * @param t The item to remove
108 * @return <i>true</i> if successful. 114 * @return <i>true</i> if successful.
109 */ 115 */
110 virtual bool remove( const T& t ); 116 virtual bool remove( const T& t );
111 117
112 /** 118 /**
113 * remove the OPimRecord with uid 119 * remove the OPimRecord with uid
114 * @param uid The ID of the item to remove 120 * @param uid The ID of the item to remove
115 * @return <i>true</i> if successful. 121 * @return <i>true</i> if successful.
116 */ 122 */
117 bool remove( int uid ); 123 bool remove( int uid );
118 bool remove( const OPimRecord& ); 124 bool remove( const OPimRecord& );
119 125
@@ -136,96 +142,102 @@ protected:
136 /** 142 /**
137 * invalidate the cache 143 * invalidate the cache
138 */ 144 */
139 void invalidateCache(); 145 void invalidateCache();
140 146
141 void setBackEnd( BackEnd* end ); 147 void setBackEnd( BackEnd* end );
142 /** 148 /**
143 * returns the backend 149 * returns the backend
144 */ 150 */
145 BackEnd* backEnd(); 151 BackEnd* backEnd();
146 BackEnd* m_backEnd; 152 BackEnd* m_backEnd;
147 Cache m_cache; 153 Cache m_cache;
148 154
149}; 155};
150 156
151template <class T> 157template <class T>
152OPimAccessTemplate<T>::OPimAccessTemplate( BackEnd* end ) 158OPimAccessTemplate<T>::OPimAccessTemplate( BackEnd* end )
153 : OTemplateBase<T>(), m_backEnd( end ) 159 : OTemplateBase<T>(), m_backEnd( end )
154{ 160{
155 if (end ) 161 if (end )
156 end->setFrontend( this ); 162 end->setFrontend( this );
157} 163}
158template <class T> 164template <class T>
159OPimAccessTemplate<T>::~OPimAccessTemplate() { 165OPimAccessTemplate<T>::~OPimAccessTemplate() {
160 qWarning("~OPimAccessTemplate<T>"); 166 qWarning("~OPimAccessTemplate<T>");
161 delete m_backEnd; 167 delete m_backEnd;
162} 168}
163template <class T> 169template <class T>
164bool OPimAccessTemplate<T>::load() { 170bool OPimAccessTemplate<T>::load() {
165 invalidateCache(); 171 invalidateCache();
166 return m_backEnd->load(); 172 return m_backEnd->load();
167} 173}
168template <class T> 174template <class T>
169bool OPimAccessTemplate<T>::reload() { 175bool OPimAccessTemplate<T>::reload() {
170 invalidateCache(); // zecke: I think this should be added (se) 176 invalidateCache(); // zecke: I think this should be added (se)
171 return m_backEnd->reload(); 177 return m_backEnd->reload();
172} 178}
173template <class T> 179template <class T>
174bool OPimAccessTemplate<T>::save() { 180bool OPimAccessTemplate<T>::save() {
175 return m_backEnd->save(); 181 return m_backEnd->save();
176} 182}
177template <class T> 183template <class T>
178typename OPimAccessTemplate<T>::List OPimAccessTemplate<T>::allRecords()const { 184typename OPimAccessTemplate<T>::List OPimAccessTemplate<T>::allRecords()const {
179 QArray<int> ints = m_backEnd->allRecords(); 185 QArray<int> ints = m_backEnd->allRecords();
180 List lis(ints, this ); 186 List lis(ints, this );
181 return lis; 187 return lis;
182} 188}
183template <class T> 189template <class T>
190typename OPimAccessTemplate<T>::List OPimAccessTemplate<T>::matchRegexp( const QRegExp &r )const {
191 QArray<int> ints = m_backEnd->matchRegexp( r );
192 List lis(ints, this );
193 return lis;
194}
195template <class T>
184QArray<int> OPimAccessTemplate<T>::records()const { 196QArray<int> OPimAccessTemplate<T>::records()const {
185 return m_backEnd->allRecords(); 197 return m_backEnd->allRecords();
186} 198}
187template <class T> 199template <class T>
188typename OPimAccessTemplate<T>::List 200typename OPimAccessTemplate<T>::List
189OPimAccessTemplate<T>::queryByExample( const T& t, int settings, const QDateTime& d ) { 201OPimAccessTemplate<T>::queryByExample( const T& t, int settings, const QDateTime& d ) {
190 QArray<int> ints = m_backEnd->queryByExample( t, settings, d ); 202 QArray<int> ints = m_backEnd->queryByExample( t, settings, d );
191 203
192 List lis(ints, this ); 204 List lis(ints, this );
193 return lis; 205 return lis;
194} 206}
195template <class T> 207template <class T>
196T OPimAccessTemplate<T>::find( int uid ) const{ 208T OPimAccessTemplate<T>::find( int uid ) const{
197 T t = m_backEnd->find( uid ); 209 T t = m_backEnd->find( uid );
198 cache( t ); 210 cache( t );
199 return t; 211 return t;
200} 212}
201template <class T> 213template <class T>
202T OPimAccessTemplate<T>::find( int uid, const QArray<int>& ar, 214T OPimAccessTemplate<T>::find( int uid, const QArray<int>& ar,
203 uint current, typename OTemplateBase<T>::CacheDirection dir )const { 215 uint current, typename OTemplateBase<T>::CacheDirection dir )const {
204 /* 216 /*
205 * better do T.isEmpty() 217 * better do T.isEmpty()
206 * after a find this way we would 218 * after a find this way we would
207 * avoid two finds in QCache... 219 * avoid two finds in QCache...
208 */ 220 */
209 // qWarning("find it now %d", uid ); 221 // qWarning("find it now %d", uid );
210 if (m_cache.contains( uid ) ) { 222 if (m_cache.contains( uid ) ) {
211 return m_cache.find( uid ); 223 return m_cache.find( uid );
212 } 224 }
213 225
214 T t = m_backEnd->find( uid, ar, current, dir ); 226 T t = m_backEnd->find( uid, ar, current, dir );
215 cache( t ); 227 cache( t );
216 return t; 228 return t;
217} 229}
218template <class T> 230template <class T>
219void OPimAccessTemplate<T>::clear() { 231void OPimAccessTemplate<T>::clear() {
220 invalidateCache(); 232 invalidateCache();
221 m_backEnd->clear(); 233 m_backEnd->clear();
222} 234}
223template <class T> 235template <class T>
224bool OPimAccessTemplate<T>::add( const T& t ) { 236bool OPimAccessTemplate<T>::add( const T& t ) {
225 cache( t ); 237 cache( t );
226 return m_backEnd->add( t ); 238 return m_backEnd->add( t );
227} 239}
228template <class T> 240template <class T>
229bool OPimAccessTemplate<T>::add( const OPimRecord& rec) { 241bool OPimAccessTemplate<T>::add( const OPimRecord& rec) {
230 /* same type */ 242 /* same type */
231 if ( rec.rtti() == T::rtti() ) { 243 if ( rec.rtti() == T::rtti() ) {