author | mickeyl <mickeyl> | 2004-11-16 19:14:18 (UTC) |
---|---|---|
committer | mickeyl <mickeyl> | 2004-11-16 19:14:18 (UTC) |
commit | ea3945a9bd8f9830f70b1efa133f9df13b19362f (patch) (unidiff) | |
tree | f2ea22cc50e9aa8aa73ee7dea148f41c563c9666 /libopie/pim/opimaccesstemplate.h | |
parent | 1c6f490e8541626f68422e0a3a7c7281d7f5b7d3 (diff) | |
download | opie-ea3945a9bd8f9830f70b1efa133f9df13b19362f.zip opie-ea3945a9bd8f9830f70b1efa133f9df13b19362f.tar.gz opie-ea3945a9bd8f9830f70b1efa133f9df13b19362f.tar.bz2 |
libopie1 goes into unsupported
Diffstat (limited to 'libopie/pim/opimaccesstemplate.h') (more/less context) (ignore whitespace changes)
-rw-r--r-- | libopie/pim/opimaccesstemplate.h | 302 |
1 files changed, 0 insertions, 302 deletions
diff --git a/libopie/pim/opimaccesstemplate.h b/libopie/pim/opimaccesstemplate.h deleted file mode 100644 index ecbeb68..0000000 --- a/libopie/pim/opimaccesstemplate.h +++ b/dev/null | |||
@@ -1,302 +0,0 @@ | |||
1 | #ifndef OPIE_PIM_ACCESS_TEMPLATE_H | ||
2 | #define OPIE_PIM_ACCESS_TEMPLATE_H | ||
3 | |||
4 | #include <qarray.h> | ||
5 | |||
6 | #include <opie/opimrecord.h> | ||
7 | #include <opie/opimaccessbackend.h> | ||
8 | #include <opie/orecordlist.h> | ||
9 | |||
10 | #include "opimcache.h" | ||
11 | #include "otemplatebase.h" | ||
12 | |||
13 | class OPimAccessTemplatePrivate; | ||
14 | /** | ||
15 | * Thats the frontend to our OPIE PIM | ||
16 | * Library. Either you want to use it's | ||
17 | * interface or you want to implement | ||
18 | * your own Access lib | ||
19 | * Just create a OPimRecord and inherit from | ||
20 | * the plugins | ||
21 | */ | ||
22 | |||
23 | template <class T = OPimRecord > | ||
24 | class OPimAccessTemplate : public OTemplateBase<T> { | ||
25 | public: | ||
26 | enum Access { | ||
27 | Random = 0, | ||
28 | SortedAccess | ||
29 | }; | ||
30 | typedef ORecordList<T> List; | ||
31 | typedef OPimAccessBackend<T> BackEnd; | ||
32 | typedef OPimCache<T> Cache; | ||
33 | |||
34 | /** | ||
35 | * c'tor BackEnd | ||
36 | * enum Access a small hint on how to handle the backend | ||
37 | */ | ||
38 | OPimAccessTemplate( BackEnd* end); | ||
39 | |||
40 | virtual ~OPimAccessTemplate(); | ||
41 | |||
42 | /** | ||
43 | * load from the backend | ||
44 | */ | ||
45 | bool load(); | ||
46 | |||
47 | /** Reload database. | ||
48 | * You should execute this function if the external database | ||
49 | * was changed. | ||
50 | * This function will load the external database and afterwards | ||
51 | * rejoin the local changes. Therefore the local database will be set consistent. | ||
52 | */ | ||
53 | virtual bool reload(); | ||
54 | |||
55 | /** Save contacts database. | ||
56 | * Save is more a "commit". After calling this function, all changes are public available. | ||
57 | * @return true if successful | ||
58 | */ | ||
59 | bool save(); | ||
60 | |||
61 | /** | ||
62 | * if the resource was changed externally | ||
63 | * You should use the signal handling instead of polling possible changes ! | ||
64 | * zecke: Do you implement a signal for otodoaccess ? | ||
65 | */ | ||
66 | bool wasChangedExternally()const; | ||
67 | |||
68 | /** | ||
69 | * return a List of records | ||
70 | * you can iterate over them | ||
71 | */ | ||
72 | virtual List allRecords()const; | ||
73 | |||
74 | /** | ||
75 | * return a List of records | ||
76 | * that match the regex | ||
77 | */ | ||
78 | virtual List matchRegexp( const QRegExp &r ) const; | ||
79 | |||
80 | /** | ||
81 | * queryByExample. | ||
82 | * @see otodoaccess, ocontactaccess | ||
83 | */ | ||
84 | virtual List queryByExample( const T& t, int querySettings, const QDateTime& d = QDateTime() ); | ||
85 | |||
86 | /** | ||
87 | * find the OPimRecord uid | ||
88 | */ | ||
89 | virtual T find( int uid )const; | ||
90 | |||
91 | /** | ||
92 | * read ahead cache find method ;) | ||
93 | */ | ||
94 | virtual T find( int uid, const QArray<int>&, | ||
95 | uint current, typename OTemplateBase<T>::CacheDirection dir = OTemplateBase<T>::Forward )const; | ||
96 | |||
97 | /* invalidate cache here */ | ||
98 | /** | ||
99 | * clears the backend and invalidates the backend | ||
100 | */ | ||
101 | void clear() ; | ||
102 | |||
103 | /** | ||
104 | * add T to the backend | ||
105 | * @param t The item to add. | ||
106 | * @return <i>true</i> if added successfully. | ||
107 | */ | ||
108 | virtual bool add( const T& t ) ; | ||
109 | bool add( const OPimRecord& ); | ||
110 | |||
111 | /* only the uid matters */ | ||
112 | /** | ||
113 | * remove T from the backend | ||
114 | * @param t The item to remove | ||
115 | * @return <i>true</i> if successful. | ||
116 | */ | ||
117 | virtual bool remove( const T& t ); | ||
118 | |||
119 | /** | ||
120 | * remove the OPimRecord with uid | ||
121 | * @param uid The ID of the item to remove | ||
122 | * @return <i>true</i> if successful. | ||
123 | */ | ||
124 | bool remove( int uid ); | ||
125 | bool remove( const OPimRecord& ); | ||
126 | |||
127 | /** | ||
128 | * replace T from backend | ||
129 | * @param t The item to replace | ||
130 | * @return <i>true</i> if successful. | ||
131 | */ | ||
132 | virtual bool replace( const T& t) ; | ||
133 | |||
134 | void setReadAhead( uint count ); | ||
135 | /** | ||
136 | * @internal | ||
137 | */ | ||
138 | void cache( const T& )const; | ||
139 | void setSaneCacheSize( int ); | ||
140 | |||
141 | QArray<int> records()const; | ||
142 | protected: | ||
143 | /** | ||
144 | * invalidate the cache | ||
145 | */ | ||
146 | void invalidateCache(); | ||
147 | |||
148 | void setBackEnd( BackEnd* end ); | ||
149 | /** | ||
150 | * returns the backend | ||
151 | */ | ||
152 | BackEnd* backEnd(); | ||
153 | BackEnd* m_backEnd; | ||
154 | Cache m_cache; | ||
155 | |||
156 | private: | ||
157 | OPimAccessTemplatePrivate *d; | ||
158 | |||
159 | }; | ||
160 | |||
161 | template <class T> | ||
162 | OPimAccessTemplate<T>::OPimAccessTemplate( BackEnd* end ) | ||
163 | : OTemplateBase<T>(), m_backEnd( end ) | ||
164 | { | ||
165 | if (end ) | ||
166 | end->setFrontend( this ); | ||
167 | } | ||
168 | template <class T> | ||
169 | OPimAccessTemplate<T>::~OPimAccessTemplate() { | ||
170 | qWarning("~OPimAccessTemplate<T>"); | ||
171 | delete m_backEnd; | ||
172 | } | ||
173 | template <class T> | ||
174 | bool OPimAccessTemplate<T>::load() { | ||
175 | invalidateCache(); | ||
176 | return m_backEnd->load(); | ||
177 | } | ||
178 | template <class T> | ||
179 | bool OPimAccessTemplate<T>::reload() { | ||
180 | invalidateCache(); // zecke: I think this should be added (se) | ||
181 | return m_backEnd->reload(); | ||
182 | } | ||
183 | template <class T> | ||
184 | bool OPimAccessTemplate<T>::save() { | ||
185 | return m_backEnd->save(); | ||
186 | } | ||
187 | template <class T> | ||
188 | typename OPimAccessTemplate<T>::List OPimAccessTemplate<T>::allRecords()const { | ||
189 | QArray<int> ints = m_backEnd->allRecords(); | ||
190 | List lis(ints, this ); | ||
191 | return lis; | ||
192 | } | ||
193 | template <class T> | ||
194 | typename OPimAccessTemplate<T>::List OPimAccessTemplate<T>::matchRegexp( const QRegExp &r )const { | ||
195 | QArray<int> ints = m_backEnd->matchRegexp( r ); | ||
196 | List lis(ints, this ); | ||
197 | return lis; | ||
198 | } | ||
199 | template <class T> | ||
200 | QArray<int> OPimAccessTemplate<T>::records()const { | ||
201 | return m_backEnd->allRecords(); | ||
202 | } | ||
203 | template <class T> | ||
204 | typename OPimAccessTemplate<T>::List | ||
205 | OPimAccessTemplate<T>::queryByExample( const T& t, int settings, const QDateTime& d ) { | ||
206 | QArray<int> ints = m_backEnd->queryByExample( t, settings, d ); | ||
207 | |||
208 | List lis(ints, this ); | ||
209 | return lis; | ||
210 | } | ||
211 | template <class T> | ||
212 | T OPimAccessTemplate<T>::find( int uid ) const{ | ||
213 | T t = m_backEnd->find( uid ); | ||
214 | cache( t ); | ||
215 | return t; | ||
216 | } | ||
217 | template <class T> | ||
218 | T OPimAccessTemplate<T>::find( int uid, const QArray<int>& ar, | ||
219 | uint current, typename OTemplateBase<T>::CacheDirection dir )const { | ||
220 | /* | ||
221 | * better do T.isEmpty() | ||
222 | * after a find this way we would | ||
223 | * avoid two finds in QCache... | ||
224 | */ | ||
225 | // qWarning("find it now %d", uid ); | ||
226 | if (m_cache.contains( uid ) ) { | ||
227 | return m_cache.find( uid ); | ||
228 | } | ||
229 | |||
230 | T t = m_backEnd->find( uid, ar, current, dir ); | ||
231 | cache( t ); | ||
232 | return t; | ||
233 | } | ||
234 | template <class T> | ||
235 | void OPimAccessTemplate<T>::clear() { | ||
236 | invalidateCache(); | ||
237 | m_backEnd->clear(); | ||
238 | } | ||
239 | template <class T> | ||
240 | bool OPimAccessTemplate<T>::add( const T& t ) { | ||
241 | cache( t ); | ||
242 | return m_backEnd->add( t ); | ||
243 | } | ||
244 | template <class T> | ||
245 | bool OPimAccessTemplate<T>::add( const OPimRecord& rec) { | ||
246 | /* same type */ | ||
247 | if ( rec.rtti() == T::rtti() ) { | ||
248 | const T &t = static_cast<const T&>(rec); | ||
249 | return add(t); | ||
250 | } | ||
251 | return false; | ||
252 | } | ||
253 | template <class T> | ||
254 | bool OPimAccessTemplate<T>::remove( const T& t ) { | ||
255 | return remove( t.uid() ); | ||
256 | } | ||
257 | template <class T> | ||
258 | bool OPimAccessTemplate<T>::remove( int uid ) { | ||
259 | m_cache.remove( uid ); | ||
260 | return m_backEnd->remove( uid ); | ||
261 | } | ||
262 | template <class T> | ||
263 | bool OPimAccessTemplate<T>::remove( const OPimRecord& rec) { | ||
264 | return remove( rec.uid() ); | ||
265 | } | ||
266 | template <class T> | ||
267 | bool OPimAccessTemplate<T>::replace( const T& t ) { | ||
268 | m_cache.replace( t ); | ||
269 | return m_backEnd->replace( t ); | ||
270 | } | ||
271 | template <class T> | ||
272 | void OPimAccessTemplate<T>::invalidateCache() { | ||
273 | m_cache.invalidate(); | ||
274 | } | ||
275 | template <class T> | ||
276 | typename OPimAccessTemplate<T>::BackEnd* OPimAccessTemplate<T>::backEnd() { | ||
277 | return m_backEnd; | ||
278 | } | ||
279 | template <class T> | ||
280 | bool OPimAccessTemplate<T>::wasChangedExternally()const { | ||
281 | return false; | ||
282 | } | ||
283 | template <class T> | ||
284 | void OPimAccessTemplate<T>::setBackEnd( BackEnd* end ) { | ||
285 | m_backEnd = end; | ||
286 | if (m_backEnd ) | ||
287 | m_backEnd->setFrontend( this ); | ||
288 | } | ||
289 | template <class T> | ||
290 | void OPimAccessTemplate<T>::cache( const T& t ) const{ | ||
291 | /* hacky we need to work around the const*/ | ||
292 | ((OPimAccessTemplate<T>*)this)->m_cache.add( t ); | ||
293 | } | ||
294 | template <class T> | ||
295 | void OPimAccessTemplate<T>::setSaneCacheSize( int size ) { | ||
296 | m_cache.setSize( size ); | ||
297 | } | ||
298 | template <class T> | ||
299 | void OPimAccessTemplate<T>::setReadAhead( uint count ) { | ||
300 | m_backEnd->setReadAhead( count ); | ||
301 | } | ||
302 | #endif | ||