-rw-r--r-- | libopie2/opiepim/backend/ocontactaccessbackend_sql.cpp | 1 | ||||
-rw-r--r-- | libopie2/opiepim/core/ocontactaccess.cpp | 6 | ||||
-rw-r--r-- | libopie2/opiepim/core/ocontactaccess.h | 5 | ||||
-rw-r--r-- | libopie2/opiepim/core/odatebookaccess.cpp | 5 | ||||
-rw-r--r-- | libopie2/opiepim/core/odatebookaccess.h | 6 | ||||
-rw-r--r-- | libopie2/opiepim/core/opimaccesstemplate.h | 28 | ||||
-rw-r--r-- | libopie2/opiepim/core/opimtemplatebase.h | 16 | ||||
-rw-r--r-- | libopie2/opiepim/core/otodoaccess.cpp | 7 | ||||
-rw-r--r-- | libopie2/opiepim/core/otodoaccess.h | 6 |
9 files changed, 65 insertions, 15 deletions
diff --git a/libopie2/opiepim/backend/ocontactaccessbackend_sql.cpp b/libopie2/opiepim/backend/ocontactaccessbackend_sql.cpp index 401a3c1..14207be 100644 --- a/libopie2/opiepim/backend/ocontactaccessbackend_sql.cpp +++ b/libopie2/opiepim/backend/ocontactaccessbackend_sql.cpp | |||
@@ -1,851 +1,852 @@ | |||
1 | /* | 1 | /* |
2 | This file is part of the Opie Project | 2 | This file is part of the Opie Project |
3 | Copyright (C) Stefan Eilers <eilers.stefan@epost.de> | 3 | Copyright (C) Stefan Eilers <eilers.stefan@epost.de> |
4 | =. Copyright (C) The Opie Team <opie-devel@handhelds.org> | 4 | =. Copyright (C) The Opie Team <opie-devel@handhelds.org> |
5 | .=l. | 5 | .=l. |
6 | .>+-= | 6 | .>+-= |
7 | _;:, .> :=|. This program is free software; you can | 7 | _;:, .> :=|. This program is free software; you can |
8 | .> <`_, > . <= redistribute it and/or modify it under | 8 | .> <`_, > . <= redistribute it and/or modify it under |
9 | :`=1 )Y*s>-.-- : the terms of the GNU Library General Public | 9 | :`=1 )Y*s>-.-- : the terms of the GNU Library General Public |
10 | .="- .-=="i, .._ License as published by the Free Software | 10 | .="- .-=="i, .._ License as published by the Free Software |
11 | - . .-<_> .<> Foundation; either version 2 of the License, | 11 | - . .-<_> .<> Foundation; either version 2 of the License, |
12 | ._= =} : or (at your option) any later version. | 12 | ._= =} : or (at your option) any later version. |
13 | .%`+i> _;_. | 13 | .%`+i> _;_. |
14 | .i_,=:_. -<s. This program is distributed in the hope that | 14 | .i_,=:_. -<s. This program is distributed in the hope that |
15 | + . -:. = it will be useful, but WITHOUT ANY WARRANTY; | 15 | + . -:. = it will be useful, but WITHOUT ANY WARRANTY; |
16 | : .. .:, . . . without even the implied warranty of | 16 | : .. .:, . . . without even the implied warranty of |
17 | =_ + =;=|` MERCHANTABILITY or FITNESS FOR A | 17 | =_ + =;=|` MERCHANTABILITY or FITNESS FOR A |
18 | _.=:. : :=>`: PARTICULAR PURPOSE. See the GNU | 18 | _.=:. : :=>`: PARTICULAR PURPOSE. See the GNU |
19 | ..}^=.= = ; Library General Public License for more | 19 | ..}^=.= = ; Library General Public License for more |
20 | ++= -. .` .: details. | 20 | ++= -. .` .: details. |
21 | : = ...= . :.=- | 21 | : = ...= . :.=- |
22 | -. .:....=;==+<; You should have received a copy of the GNU | 22 | -. .:....=;==+<; You should have received a copy of the GNU |
23 | -_. . . )=. = Library General Public License along with | 23 | -_. . . )=. = Library General Public License along with |
24 | -- :-=` this library; see the file COPYING.LIB. | 24 | -- :-=` this library; see the file COPYING.LIB. |
25 | If not, write to the Free Software Foundation, | 25 | If not, write to the Free Software Foundation, |
26 | Inc., 59 Temple Place - Suite 330, | 26 | Inc., 59 Temple Place - Suite 330, |
27 | Boston, MA 02111-1307, USA. | 27 | Boston, MA 02111-1307, USA. |
28 | */ | 28 | */ |
29 | /* | 29 | /* |
30 | * SQL Backend for the OPIE-Contact Database. | 30 | * SQL Backend for the OPIE-Contact Database. |
31 | */ | 31 | */ |
32 | 32 | ||
33 | #include "ocontactaccessbackend_sql.h" | 33 | #include "ocontactaccessbackend_sql.h" |
34 | 34 | ||
35 | #include <qarray.h> | 35 | #include <qarray.h> |
36 | #include <qdatetime.h> | 36 | #include <qdatetime.h> |
37 | #include <qstringlist.h> | 37 | #include <qstringlist.h> |
38 | 38 | ||
39 | #include <qpe/global.h> | 39 | #include <qpe/global.h> |
40 | #include <qpe/recordfields.h> | 40 | #include <qpe/recordfields.h> |
41 | 41 | ||
42 | #include <opie2/opimcontact.h> | 42 | #include <opie2/opimcontact.h> |
43 | #include <opie2/opimcontactfields.h> | 43 | #include <opie2/opimcontactfields.h> |
44 | #include <opie2/opimdateconversion.h> | 44 | #include <opie2/opimdateconversion.h> |
45 | #include <opie2/osqldriver.h> | 45 | #include <opie2/osqldriver.h> |
46 | #include <opie2/osqlresult.h> | 46 | #include <opie2/osqlresult.h> |
47 | #include <opie2/osqlmanager.h> | 47 | #include <opie2/osqlmanager.h> |
48 | #include <opie2/osqlquery.h> | 48 | #include <opie2/osqlquery.h> |
49 | 49 | ||
50 | using namespace Opie; | 50 | using namespace Opie; |
51 | using namespace Opie::DB; | 51 | using namespace Opie::DB; |
52 | 52 | ||
53 | 53 | ||
54 | /* | 54 | /* |
55 | * Implementation of used query types * CREATE query | 55 | * Implementation of used query types * CREATE query |
56 | * LOAD query | 56 | * LOAD query |
57 | * INSERT | 57 | * INSERT |
58 | * REMOVE | 58 | * REMOVE |
59 | * CLEAR | 59 | * CLEAR |
60 | */ | 60 | */ |
61 | namespace { | 61 | namespace { |
62 | /** | 62 | /** |
63 | * CreateQuery for the Todolist Table | 63 | * CreateQuery for the Todolist Table |
64 | */ | 64 | */ |
65 | class CreateQuery : public OSQLQuery { | 65 | class CreateQuery : public OSQLQuery { |
66 | public: | 66 | public: |
67 | CreateQuery(); | 67 | CreateQuery(); |
68 | ~CreateQuery(); | 68 | ~CreateQuery(); |
69 | QString query()const; | 69 | QString query()const; |
70 | }; | 70 | }; |
71 | 71 | ||
72 | /** | 72 | /** |
73 | * Clears (delete) a Table | 73 | * Clears (delete) a Table |
74 | */ | 74 | */ |
75 | class ClearQuery : public OSQLQuery { | 75 | class ClearQuery : public OSQLQuery { |
76 | public: | 76 | public: |
77 | ClearQuery(); | 77 | ClearQuery(); |
78 | ~ClearQuery(); | 78 | ~ClearQuery(); |
79 | QString query()const; | 79 | QString query()const; |
80 | 80 | ||
81 | }; | 81 | }; |
82 | 82 | ||
83 | 83 | ||
84 | /** | 84 | /** |
85 | * LoadQuery | 85 | * LoadQuery |
86 | * this one queries for all uids | 86 | * this one queries for all uids |
87 | */ | 87 | */ |
88 | class LoadQuery : public OSQLQuery { | 88 | class LoadQuery : public OSQLQuery { |
89 | public: | 89 | public: |
90 | LoadQuery(); | 90 | LoadQuery(); |
91 | ~LoadQuery(); | 91 | ~LoadQuery(); |
92 | QString query()const; | 92 | QString query()const; |
93 | }; | 93 | }; |
94 | 94 | ||
95 | /** | 95 | /** |
96 | * inserts/adds a OPimContact to the table | 96 | * inserts/adds a OPimContact to the table |
97 | */ | 97 | */ |
98 | class InsertQuery : public OSQLQuery { | 98 | class InsertQuery : public OSQLQuery { |
99 | public: | 99 | public: |
100 | InsertQuery(const OPimContact& ); | 100 | InsertQuery(const OPimContact& ); |
101 | ~InsertQuery(); | 101 | ~InsertQuery(); |
102 | QString query()const; | 102 | QString query()const; |
103 | private: | 103 | private: |
104 | OPimContact m_contact; | 104 | OPimContact m_contact; |
105 | }; | 105 | }; |
106 | 106 | ||
107 | 107 | ||
108 | /** | 108 | /** |
109 | * removes one from the table | 109 | * removes one from the table |
110 | */ | 110 | */ |
111 | class RemoveQuery : public OSQLQuery { | 111 | class RemoveQuery : public OSQLQuery { |
112 | public: | 112 | public: |
113 | RemoveQuery(int uid ); | 113 | RemoveQuery(int uid ); |
114 | ~RemoveQuery(); | 114 | ~RemoveQuery(); |
115 | QString query()const; | 115 | QString query()const; |
116 | private: | 116 | private: |
117 | int m_uid; | 117 | int m_uid; |
118 | }; | 118 | }; |
119 | 119 | ||
120 | /** | 120 | /** |
121 | * a find query for noncustom elements | 121 | * a find query for noncustom elements |
122 | */ | 122 | */ |
123 | class FindQuery : public OSQLQuery { | 123 | class FindQuery : public OSQLQuery { |
124 | public: | 124 | public: |
125 | FindQuery(int uid); | 125 | FindQuery(int uid); |
126 | FindQuery(const QArray<int>& ); | 126 | FindQuery(const QArray<int>& ); |
127 | ~FindQuery(); | 127 | ~FindQuery(); |
128 | QString query()const; | 128 | QString query()const; |
129 | private: | 129 | private: |
130 | QString single()const; | 130 | QString single()const; |
131 | QString multi()const; | 131 | QString multi()const; |
132 | QArray<int> m_uids; | 132 | QArray<int> m_uids; |
133 | int m_uid; | 133 | int m_uid; |
134 | }; | 134 | }; |
135 | 135 | ||
136 | /** | 136 | /** |
137 | * a find query for custom elements | 137 | * a find query for custom elements |
138 | */ | 138 | */ |
139 | class FindCustomQuery : public OSQLQuery { | 139 | class FindCustomQuery : public OSQLQuery { |
140 | public: | 140 | public: |
141 | FindCustomQuery(int uid); | 141 | FindCustomQuery(int uid); |
142 | FindCustomQuery(const QArray<int>& ); | 142 | FindCustomQuery(const QArray<int>& ); |
143 | ~FindCustomQuery(); | 143 | ~FindCustomQuery(); |
144 | QString query()const; | 144 | QString query()const; |
145 | private: | 145 | private: |
146 | QString single()const; | 146 | QString single()const; |
147 | QString multi()const; | 147 | QString multi()const; |
148 | QArray<int> m_uids; | 148 | QArray<int> m_uids; |
149 | int m_uid; | 149 | int m_uid; |
150 | }; | 150 | }; |
151 | 151 | ||
152 | 152 | ||
153 | 153 | ||
154 | // We using two tables to store the information: | 154 | // We using two tables to store the information: |
155 | // 1. addressbook : It contains General information about the contact (non custom) | 155 | // 1. addressbook : It contains General information about the contact (non custom) |
156 | // 2. custom_data : Not official supported entries | 156 | // 2. custom_data : Not official supported entries |
157 | // All tables are connected by the uid of the contact. | 157 | // All tables are connected by the uid of the contact. |
158 | // Maybe I should add a table for meta-information ? | 158 | // Maybe I should add a table for meta-information ? |
159 | CreateQuery::CreateQuery() : OSQLQuery() {} | 159 | CreateQuery::CreateQuery() : OSQLQuery() {} |
160 | CreateQuery::~CreateQuery() {} | 160 | CreateQuery::~CreateQuery() {} |
161 | QString CreateQuery::query()const { | 161 | QString CreateQuery::query()const { |
162 | QString qu; | 162 | QString qu; |
163 | 163 | ||
164 | qu += "create table addressbook( uid PRIMARY KEY "; | 164 | qu += "create table addressbook( uid PRIMARY KEY "; |
165 | 165 | ||
166 | QStringList fieldList = OPimContactFields::untrfields( false ); | 166 | QStringList fieldList = OPimContactFields::untrfields( false ); |
167 | for ( QStringList::Iterator it = ++fieldList.begin(); it != fieldList.end(); ++it ){ | 167 | for ( QStringList::Iterator it = ++fieldList.begin(); it != fieldList.end(); ++it ){ |
168 | qu += QString( ",\"%1\" VARCHAR(10)" ).arg( *it ); | 168 | qu += QString( ",\"%1\" VARCHAR(10)" ).arg( *it ); |
169 | } | 169 | } |
170 | qu += " );"; | 170 | qu += " );"; |
171 | 171 | ||
172 | qu += "create table custom_data( uid INTEGER, id INTEGER, type VARCHAR(10), priority INTEGER, value VARCHAR(10), PRIMARY KEY /* identifier */ (uid, id) );"; | 172 | qu += "create table custom_data( uid INTEGER, id INTEGER, type VARCHAR(10), priority INTEGER, value VARCHAR(10), PRIMARY KEY /* identifier */ (uid, id) );"; |
173 | 173 | ||
174 | return qu; | 174 | return qu; |
175 | } | 175 | } |
176 | 176 | ||
177 | ClearQuery::ClearQuery() | 177 | ClearQuery::ClearQuery() |
178 | : OSQLQuery() {} | 178 | : OSQLQuery() {} |
179 | ClearQuery::~ClearQuery() {} | 179 | ClearQuery::~ClearQuery() {} |
180 | QString ClearQuery::query()const { | 180 | QString ClearQuery::query()const { |
181 | QString qu = "drop table addressbook;"; | 181 | QString qu = "drop table addressbook;"; |
182 | qu += "drop table custom_data;"; | 182 | qu += "drop table custom_data;"; |
183 | // qu += "drop table dates;"; | 183 | // qu += "drop table dates;"; |
184 | return qu; | 184 | return qu; |
185 | } | 185 | } |
186 | 186 | ||
187 | 187 | ||
188 | LoadQuery::LoadQuery() : OSQLQuery() {} | 188 | LoadQuery::LoadQuery() : OSQLQuery() {} |
189 | LoadQuery::~LoadQuery() {} | 189 | LoadQuery::~LoadQuery() {} |
190 | QString LoadQuery::query()const { | 190 | QString LoadQuery::query()const { |
191 | QString qu; | 191 | QString qu; |
192 | qu += "select uid from addressbook"; | 192 | qu += "select uid from addressbook"; |
193 | 193 | ||
194 | return qu; | 194 | return qu; |
195 | } | 195 | } |
196 | 196 | ||
197 | 197 | ||
198 | InsertQuery::InsertQuery( const OPimContact& contact ) | 198 | InsertQuery::InsertQuery( const OPimContact& contact ) |
199 | : OSQLQuery(), m_contact( contact ) { | 199 | : OSQLQuery(), m_contact( contact ) { |
200 | } | 200 | } |
201 | 201 | ||
202 | InsertQuery::~InsertQuery() { | 202 | InsertQuery::~InsertQuery() { |
203 | } | 203 | } |
204 | 204 | ||
205 | /* | 205 | /* |
206 | * converts from a OPimContact to a query | 206 | * converts from a OPimContact to a query |
207 | */ | 207 | */ |
208 | QString InsertQuery::query()const{ | 208 | QString InsertQuery::query()const{ |
209 | 209 | ||
210 | QString qu; | 210 | QString qu; |
211 | qu += "insert into addressbook VALUES( " + | 211 | qu += "insert into addressbook VALUES( " + |
212 | QString::number( m_contact.uid() ); | 212 | QString::number( m_contact.uid() ); |
213 | 213 | ||
214 | // Get all information out of the contact-class | 214 | // Get all information out of the contact-class |
215 | // Remember: The category is stored in contactMap, too ! | 215 | // Remember: The category is stored in contactMap, too ! |
216 | QMap<int, QString> contactMap = m_contact.toMap(); | 216 | QMap<int, QString> contactMap = m_contact.toMap(); |
217 | 217 | ||
218 | QStringList fieldList = OPimContactFields::untrfields( false ); | 218 | QStringList fieldList = OPimContactFields::untrfields( false ); |
219 | QMap<QString, int> translate = OPimContactFields::untrFieldsToId(); | 219 | QMap<QString, int> translate = OPimContactFields::untrFieldsToId(); |
220 | for ( QStringList::Iterator it = ++fieldList.begin(); it != fieldList.end(); ++it ){ | 220 | for ( QStringList::Iterator it = ++fieldList.begin(); it != fieldList.end(); ++it ){ |
221 | // Convert Column-String to Id and get value for this id.. | 221 | // Convert Column-String to Id and get value for this id.. |
222 | // Hmmm.. Maybe not very cute solution.. | 222 | // Hmmm.. Maybe not very cute solution.. |
223 | int id = translate[*it]; | 223 | int id = translate[*it]; |
224 | switch ( id ){ | 224 | switch ( id ){ |
225 | case Qtopia::Birthday: | 225 | case Qtopia::Birthday: |
226 | case Qtopia::Anniversary:{ | 226 | case Qtopia::Anniversary:{ |
227 | QDate day; | 227 | QDate day; |
228 | if ( id == Qtopia::Birthday ){ | 228 | if ( id == Qtopia::Birthday ){ |
229 | day = m_contact.birthday(); | 229 | day = m_contact.birthday(); |
230 | } else { | 230 | } else { |
231 | day = m_contact.anniversary(); | 231 | day = m_contact.anniversary(); |
232 | } | 232 | } |
233 | // These entries should stored in a special format | 233 | // These entries should stored in a special format |
234 | // year-month-day | 234 | // year-month-day |
235 | if ( day.isValid() ){ | 235 | if ( day.isValid() ){ |
236 | qu += QString(",\"%1-%2-%3\"") | 236 | qu += QString(",\"%1-%2-%3\"") |
237 | .arg( QString::number( day.year() ).rightJustify( 4, '0' ) ) | 237 | .arg( QString::number( day.year() ).rightJustify( 4, '0' ) ) |
238 | .arg( QString::number( day.month() ).rightJustify( 2, '0' ) ) | 238 | .arg( QString::number( day.month() ).rightJustify( 2, '0' ) ) |
239 | .arg( QString::number( day.day() ).rightJustify( 2, '0' ) ); | 239 | .arg( QString::number( day.day() ).rightJustify( 2, '0' ) ); |
240 | } else { | 240 | } else { |
241 | qu += ",\"\""; | 241 | qu += ",\"\""; |
242 | } | 242 | } |
243 | } | 243 | } |
244 | break; | 244 | break; |
245 | default: | 245 | default: |
246 | qu += QString( ",\"%1\"" ).arg( contactMap[id] ); | 246 | qu += QString( ",\"%1\"" ).arg( contactMap[id] ); |
247 | } | 247 | } |
248 | } | 248 | } |
249 | qu += " );"; | 249 | qu += " );"; |
250 | 250 | ||
251 | 251 | ||
252 | // Now add custom data.. | 252 | // Now add custom data.. |
253 | int id = 0; | 253 | int id = 0; |
254 | id = 0; | 254 | id = 0; |
255 | QMap<QString, QString> customMap = m_contact.toExtraMap(); | 255 | QMap<QString, QString> customMap = m_contact.toExtraMap(); |
256 | for( QMap<QString, QString>::Iterator it = customMap.begin(); | 256 | for( QMap<QString, QString>::Iterator it = customMap.begin(); |
257 | it != customMap.end(); ++it ){ | 257 | it != customMap.end(); ++it ){ |
258 | qu += "insert into custom_data VALUES(" | 258 | qu += "insert into custom_data VALUES(" |
259 | + QString::number( m_contact.uid() ) | 259 | + QString::number( m_contact.uid() ) |
260 | + "," | 260 | + "," |
261 | + QString::number( id++ ) | 261 | + QString::number( id++ ) |
262 | + ",'" | 262 | + ",'" |
263 | + it.key() | 263 | + it.key() |
264 | + "'," | 264 | + "'," |
265 | + "0" // Priority for future enhancements | 265 | + "0" // Priority for future enhancements |
266 | + ",'" | 266 | + ",'" |
267 | + it.data() | 267 | + it.data() |
268 | + "');"; | 268 | + "');"; |
269 | } | 269 | } |
270 | // qu += "commit;"; | 270 | // qu += "commit;"; |
271 | qDebug("add %s", qu.latin1() ); | 271 | qDebug("add %s", qu.latin1() ); |
272 | return qu; | 272 | return qu; |
273 | } | 273 | } |
274 | 274 | ||
275 | 275 | ||
276 | RemoveQuery::RemoveQuery(int uid ) | 276 | RemoveQuery::RemoveQuery(int uid ) |
277 | : OSQLQuery(), m_uid( uid ) {} | 277 | : OSQLQuery(), m_uid( uid ) {} |
278 | RemoveQuery::~RemoveQuery() {} | 278 | RemoveQuery::~RemoveQuery() {} |
279 | QString RemoveQuery::query()const { | 279 | QString RemoveQuery::query()const { |
280 | QString qu = "DELETE from addressbook where uid = " | 280 | QString qu = "DELETE from addressbook where uid = " |
281 | + QString::number(m_uid) + ";"; | 281 | + QString::number(m_uid) + ";"; |
282 | qu += "DELETE from custom_data where uid = " | 282 | qu += "DELETE from custom_data where uid = " |
283 | + QString::number(m_uid) + ";"; | 283 | + QString::number(m_uid) + ";"; |
284 | return qu; | 284 | return qu; |
285 | } | 285 | } |
286 | 286 | ||
287 | 287 | ||
288 | 288 | ||
289 | 289 | ||
290 | FindQuery::FindQuery(int uid) | 290 | FindQuery::FindQuery(int uid) |
291 | : OSQLQuery(), m_uid( uid ) { | 291 | : OSQLQuery(), m_uid( uid ) { |
292 | } | 292 | } |
293 | FindQuery::FindQuery(const QArray<int>& ints) | 293 | FindQuery::FindQuery(const QArray<int>& ints) |
294 | : OSQLQuery(), m_uids( ints ){ | 294 | : OSQLQuery(), m_uids( ints ){ |
295 | } | 295 | } |
296 | FindQuery::~FindQuery() { | 296 | FindQuery::~FindQuery() { |
297 | } | 297 | } |
298 | QString FindQuery::query()const{ | 298 | QString FindQuery::query()const{ |
299 | // if ( m_uids.count() == 0 ) | 299 | // if ( m_uids.count() == 0 ) |
300 | return single(); | 300 | return single(); |
301 | } | 301 | } |
302 | /* | 302 | /* |
303 | else | 303 | else |
304 | return multi(); | 304 | return multi(); |
305 | } | 305 | } |
306 | QString FindQuery::multi()const { | 306 | QString FindQuery::multi()const { |
307 | QString qu = "select uid, type, value from addressbook where"; | 307 | QString qu = "select uid, type, value from addressbook where"; |
308 | for (uint i = 0; i < m_uids.count(); i++ ) { | 308 | for (uint i = 0; i < m_uids.count(); i++ ) { |
309 | qu += " UID = " + QString::number( m_uids[i] ) + " OR"; | 309 | qu += " UID = " + QString::number( m_uids[i] ) + " OR"; |
310 | } | 310 | } |
311 | qu.remove( qu.length()-2, 2 ); // Hmmmm.. | 311 | qu.remove( qu.length()-2, 2 ); // Hmmmm.. |
312 | return qu; | 312 | return qu; |
313 | } | 313 | } |
314 | */ | 314 | */ |
315 | QString FindQuery::single()const{ | 315 | QString FindQuery::single()const{ |
316 | QString qu = "select *"; | 316 | QString qu = "select *"; |
317 | qu += " from addressbook where uid = " + QString::number(m_uid); | 317 | qu += " from addressbook where uid = " + QString::number(m_uid); |
318 | 318 | ||
319 | // qWarning("find query: %s", qu.latin1() ); | 319 | // qWarning("find query: %s", qu.latin1() ); |
320 | return qu; | 320 | return qu; |
321 | } | 321 | } |
322 | 322 | ||
323 | 323 | ||
324 | FindCustomQuery::FindCustomQuery(int uid) | 324 | FindCustomQuery::FindCustomQuery(int uid) |
325 | : OSQLQuery(), m_uid( uid ) { | 325 | : OSQLQuery(), m_uid( uid ) { |
326 | } | 326 | } |
327 | FindCustomQuery::FindCustomQuery(const QArray<int>& ints) | 327 | FindCustomQuery::FindCustomQuery(const QArray<int>& ints) |
328 | : OSQLQuery(), m_uids( ints ){ | 328 | : OSQLQuery(), m_uids( ints ){ |
329 | } | 329 | } |
330 | FindCustomQuery::~FindCustomQuery() { | 330 | FindCustomQuery::~FindCustomQuery() { |
331 | } | 331 | } |
332 | QString FindCustomQuery::query()const{ | 332 | QString FindCustomQuery::query()const{ |
333 | // if ( m_uids.count() == 0 ) | 333 | // if ( m_uids.count() == 0 ) |
334 | return single(); | 334 | return single(); |
335 | } | 335 | } |
336 | QString FindCustomQuery::single()const{ | 336 | QString FindCustomQuery::single()const{ |
337 | QString qu = "select uid, type, value from custom_data where uid = "; | 337 | QString qu = "select uid, type, value from custom_data where uid = "; |
338 | qu += QString::number(m_uid); | 338 | qu += QString::number(m_uid); |
339 | return qu; | 339 | return qu; |
340 | } | 340 | } |
341 | 341 | ||
342 | }; | 342 | }; |
343 | 343 | ||
344 | 344 | ||
345 | /* --------------------------------------------------------------------------- */ | 345 | /* --------------------------------------------------------------------------- */ |
346 | 346 | ||
347 | namespace Opie { | 347 | namespace Opie { |
348 | 348 | ||
349 | OPimContactAccessBackend_SQL::OPimContactAccessBackend_SQL ( const QString& /* appname */, | 349 | OPimContactAccessBackend_SQL::OPimContactAccessBackend_SQL ( const QString& /* appname */, |
350 | const QString& filename ): | 350 | const QString& filename ): |
351 | OPimContactAccessBackend(), m_changed(false), m_driver( NULL ) | 351 | OPimContactAccessBackend(), m_changed(false), m_driver( NULL ) |
352 | { | 352 | { |
353 | qDebug("C'tor OPimContactAccessBackend_SQL starts"); | 353 | qDebug("C'tor OPimContactAccessBackend_SQL starts"); |
354 | QTime t; | 354 | QTime t; |
355 | t.start(); | 355 | t.start(); |
356 | 356 | ||
357 | /* Expecting to access the default filename if nothing else is set */ | 357 | /* Expecting to access the default filename if nothing else is set */ |
358 | if ( filename.isEmpty() ){ | 358 | if ( filename.isEmpty() ){ |
359 | m_fileName = Global::applicationFileName( "addressbook","addressbook.db" ); | 359 | m_fileName = Global::applicationFileName( "addressbook","addressbook.db" ); |
360 | } else | 360 | } else |
361 | m_fileName = filename; | 361 | m_fileName = filename; |
362 | 362 | ||
363 | // Get the standart sql-driver from the OSQLManager.. | 363 | // Get the standart sql-driver from the OSQLManager.. |
364 | OSQLManager man; | 364 | OSQLManager man; |
365 | m_driver = man.standard(); | 365 | m_driver = man.standard(); |
366 | m_driver->setUrl( m_fileName ); | 366 | m_driver->setUrl( m_fileName ); |
367 | 367 | ||
368 | load(); | 368 | load(); |
369 | 369 | ||
370 | qDebug("C'tor OPimContactAccessBackend_SQL ends: %d ms", t.elapsed() ); | 370 | qDebug("C'tor OPimContactAccessBackend_SQL ends: %d ms", t.elapsed() ); |
371 | } | 371 | } |
372 | 372 | ||
373 | OPimContactAccessBackend_SQL::~OPimContactAccessBackend_SQL () | 373 | OPimContactAccessBackend_SQL::~OPimContactAccessBackend_SQL () |
374 | { | 374 | { |
375 | if( m_driver ) | 375 | if( m_driver ) |
376 | delete m_driver; | 376 | delete m_driver; |
377 | } | 377 | } |
378 | 378 | ||
379 | bool OPimContactAccessBackend_SQL::load () | 379 | bool OPimContactAccessBackend_SQL::load () |
380 | { | 380 | { |
381 | if (!m_driver->open() ) | 381 | if (!m_driver->open() ) |
382 | return false; | 382 | return false; |
383 | 383 | ||
384 | // Don't expect that the database exists. | 384 | // Don't expect that the database exists. |
385 | // It is save here to create the table, even if it | 385 | // It is save here to create the table, even if it |
386 | // do exist. ( Is that correct for all databases ?? ) | 386 | // do exist. ( Is that correct for all databases ?? ) |
387 | CreateQuery creat; | 387 | CreateQuery creat; |
388 | OSQLResult res = m_driver->query( &creat ); | 388 | OSQLResult res = m_driver->query( &creat ); |
389 | 389 | ||
390 | update(); | 390 | update(); |
391 | 391 | ||
392 | return true; | 392 | return true; |
393 | 393 | ||
394 | } | 394 | } |
395 | 395 | ||
396 | bool OPimContactAccessBackend_SQL::reload() | 396 | bool OPimContactAccessBackend_SQL::reload() |
397 | { | 397 | { |
398 | return load(); | 398 | return load(); |
399 | } | 399 | } |
400 | 400 | ||
401 | bool OPimContactAccessBackend_SQL::save() | 401 | bool OPimContactAccessBackend_SQL::save() |
402 | { | 402 | { |
403 | return m_driver->close(); // Shouldn't m_driver->sync be better than close ? (eilers) | 403 | return m_driver->close(); // Shouldn't m_driver->sync be better than close ? (eilers) |
404 | } | 404 | } |
405 | 405 | ||
406 | 406 | ||
407 | void OPimContactAccessBackend_SQL::clear () | 407 | void OPimContactAccessBackend_SQL::clear () |
408 | { | 408 | { |
409 | ClearQuery cle; | 409 | ClearQuery cle; |
410 | OSQLResult res = m_driver->query( &cle ); | 410 | OSQLResult res = m_driver->query( &cle ); |
411 | 411 | ||
412 | reload(); | 412 | reload(); |
413 | } | 413 | } |
414 | 414 | ||
415 | bool OPimContactAccessBackend_SQL::wasChangedExternally() | 415 | bool OPimContactAccessBackend_SQL::wasChangedExternally() |
416 | { | 416 | { |
417 | return false; | 417 | return false; |
418 | } | 418 | } |
419 | 419 | ||
420 | QArray<int> OPimContactAccessBackend_SQL::allRecords() const | 420 | QArray<int> OPimContactAccessBackend_SQL::allRecords() const |
421 | { | 421 | { |
422 | 422 | ||
423 | // FIXME: Think about cute handling of changed tables.. | 423 | // FIXME: Think about cute handling of changed tables.. |
424 | // Thus, we don't have to call update here... | 424 | // Thus, we don't have to call update here... |
425 | if ( m_changed ) | 425 | if ( m_changed ) |
426 | ((OPimContactAccessBackend_SQL*)this)->update(); | 426 | ((OPimContactAccessBackend_SQL*)this)->update(); |
427 | 427 | ||
428 | return m_uids; | 428 | return m_uids; |
429 | } | 429 | } |
430 | 430 | ||
431 | bool OPimContactAccessBackend_SQL::add ( const OPimContact &newcontact ) | 431 | bool OPimContactAccessBackend_SQL::add ( const OPimContact &newcontact ) |
432 | { | 432 | { |
433 | qDebug("add in contact SQL-Backend"); | ||
433 | InsertQuery ins( newcontact ); | 434 | InsertQuery ins( newcontact ); |
434 | OSQLResult res = m_driver->query( &ins ); | 435 | OSQLResult res = m_driver->query( &ins ); |
435 | 436 | ||
436 | if ( res.state() == OSQLResult::Failure ) | 437 | if ( res.state() == OSQLResult::Failure ) |
437 | return false; | 438 | return false; |
438 | 439 | ||
439 | int c = m_uids.count(); | 440 | int c = m_uids.count(); |
440 | m_uids.resize( c+1 ); | 441 | m_uids.resize( c+1 ); |
441 | m_uids[c] = newcontact.uid(); | 442 | m_uids[c] = newcontact.uid(); |
442 | 443 | ||
443 | return true; | 444 | return true; |
444 | } | 445 | } |
445 | 446 | ||
446 | 447 | ||
447 | bool OPimContactAccessBackend_SQL::remove ( int uid ) | 448 | bool OPimContactAccessBackend_SQL::remove ( int uid ) |
448 | { | 449 | { |
449 | RemoveQuery rem( uid ); | 450 | RemoveQuery rem( uid ); |
450 | OSQLResult res = m_driver->query(&rem ); | 451 | OSQLResult res = m_driver->query(&rem ); |
451 | 452 | ||
452 | if ( res.state() == OSQLResult::Failure ) | 453 | if ( res.state() == OSQLResult::Failure ) |
453 | return false; | 454 | return false; |
454 | 455 | ||
455 | m_changed = true; | 456 | m_changed = true; |
456 | 457 | ||
457 | return true; | 458 | return true; |
458 | } | 459 | } |
459 | 460 | ||
460 | bool OPimContactAccessBackend_SQL::replace ( const OPimContact &contact ) | 461 | bool OPimContactAccessBackend_SQL::replace ( const OPimContact &contact ) |
461 | { | 462 | { |
462 | if ( !remove( contact.uid() ) ) | 463 | if ( !remove( contact.uid() ) ) |
463 | return false; | 464 | return false; |
464 | 465 | ||
465 | return add( contact ); | 466 | return add( contact ); |
466 | } | 467 | } |
467 | 468 | ||
468 | 469 | ||
469 | OPimContact OPimContactAccessBackend_SQL::find ( int uid ) const | 470 | OPimContact OPimContactAccessBackend_SQL::find ( int uid ) const |
470 | { | 471 | { |
471 | qDebug("OPimContactAccessBackend_SQL::find()"); | 472 | qDebug("OPimContactAccessBackend_SQL::find()"); |
472 | QTime t; | 473 | QTime t; |
473 | t.start(); | 474 | t.start(); |
474 | 475 | ||
475 | OPimContact retContact( requestNonCustom( uid ) ); | 476 | OPimContact retContact( requestNonCustom( uid ) ); |
476 | retContact.setExtraMap( requestCustom( uid ) ); | 477 | retContact.setExtraMap( requestCustom( uid ) ); |
477 | 478 | ||
478 | qDebug("OPimContactAccessBackend_SQL::find() needed: %d ms", t.elapsed() ); | 479 | qDebug("OPimContactAccessBackend_SQL::find() needed: %d ms", t.elapsed() ); |
479 | return retContact; | 480 | return retContact; |
480 | } | 481 | } |
481 | 482 | ||
482 | 483 | ||
483 | 484 | ||
484 | QArray<int> OPimContactAccessBackend_SQL::queryByExample ( const OPimContact &query, int settings, const QDateTime& qd ) | 485 | QArray<int> OPimContactAccessBackend_SQL::queryByExample ( const OPimContact &query, int settings, const QDateTime& qd ) |
485 | { | 486 | { |
486 | QString qu = "SELECT uid FROM addressbook WHERE"; | 487 | QString qu = "SELECT uid FROM addressbook WHERE"; |
487 | QString searchQuery =""; | 488 | QString searchQuery =""; |
488 | 489 | ||
489 | QDate startDate; | 490 | QDate startDate; |
490 | 491 | ||
491 | if ( qd.isValid() ) | 492 | if ( qd.isValid() ) |
492 | startDate = qd.date(); | 493 | startDate = qd.date(); |
493 | else | 494 | else |
494 | startDate = QDate::currentDate(); | 495 | startDate = QDate::currentDate(); |
495 | 496 | ||
496 | 497 | ||
497 | QMap<int, QString> queryFields = query.toMap(); | 498 | QMap<int, QString> queryFields = query.toMap(); |
498 | QStringList fieldList = OPimContactFields::untrfields( false ); | 499 | QStringList fieldList = OPimContactFields::untrfields( false ); |
499 | QMap<QString, int> translate = OPimContactFields::untrFieldsToId(); | 500 | QMap<QString, int> translate = OPimContactFields::untrFieldsToId(); |
500 | 501 | ||
501 | // Convert every filled field to a SQL-Query | 502 | // Convert every filled field to a SQL-Query |
502 | // bool isAnyFieldSelected = false; | 503 | // bool isAnyFieldSelected = false; |
503 | for ( QStringList::Iterator it = ++fieldList.begin(); it != fieldList.end(); ++it ){ | 504 | for ( QStringList::Iterator it = ++fieldList.begin(); it != fieldList.end(); ++it ){ |
504 | 505 | ||
505 | int id = translate[*it]; | 506 | int id = translate[*it]; |
506 | QString queryStr = queryFields[id]; | 507 | QString queryStr = queryFields[id]; |
507 | QDate* endDate = 0l; | 508 | QDate* endDate = 0l; |
508 | 509 | ||
509 | if ( !queryStr.isEmpty() ){ | 510 | if ( !queryStr.isEmpty() ){ |
510 | // If something is alredy stored in the query, add an "AND" | 511 | // If something is alredy stored in the query, add an "AND" |
511 | // to the end of the string to prepare for the next .. | 512 | // to the end of the string to prepare for the next .. |
512 | if ( !searchQuery.isEmpty() ) | 513 | if ( !searchQuery.isEmpty() ) |
513 | searchQuery += " AND"; | 514 | searchQuery += " AND"; |
514 | 515 | ||
515 | // isAnyFieldSelected = true; | 516 | // isAnyFieldSelected = true; |
516 | switch( id ){ | 517 | switch( id ){ |
517 | case Qtopia::Birthday: | 518 | case Qtopia::Birthday: |
518 | endDate = new QDate( query.birthday() ); | 519 | endDate = new QDate( query.birthday() ); |
519 | // Fall through ! | 520 | // Fall through ! |
520 | case Qtopia::Anniversary: | 521 | case Qtopia::Anniversary: |
521 | if ( endDate == 0l ) | 522 | if ( endDate == 0l ) |
522 | endDate = new QDate( query.anniversary() ); | 523 | endDate = new QDate( query.anniversary() ); |
523 | 524 | ||
524 | if ( settings & OPimContactAccess::DateDiff ) { | 525 | if ( settings & OPimContactAccess::DateDiff ) { |
525 | searchQuery += QString( " (\"%1\" <= '%2-%3-%4\' AND \"%5\" >= '%6-%7-%8')" ) | 526 | searchQuery += QString( " (\"%1\" <= '%2-%3-%4\' AND \"%5\" >= '%6-%7-%8')" ) |
526 | .arg( *it ) | 527 | .arg( *it ) |
527 | .arg( QString::number( endDate->year() ).rightJustify( 4, '0' ) ) | 528 | .arg( QString::number( endDate->year() ).rightJustify( 4, '0' ) ) |
528 | .arg( QString::number( endDate->month() ).rightJustify( 2, '0' ) ) | 529 | .arg( QString::number( endDate->month() ).rightJustify( 2, '0' ) ) |
529 | .arg( QString::number( endDate->day() ).rightJustify( 2, '0' ) ) | 530 | .arg( QString::number( endDate->day() ).rightJustify( 2, '0' ) ) |
530 | .arg( *it ) | 531 | .arg( *it ) |
531 | .arg( QString::number( startDate.year() ).rightJustify( 4, '0' ) ) | 532 | .arg( QString::number( startDate.year() ).rightJustify( 4, '0' ) ) |
532 | .arg( QString::number( startDate.month() ).rightJustify( 2, '0' ) ) | 533 | .arg( QString::number( startDate.month() ).rightJustify( 2, '0' ) ) |
533 | .arg( QString::number( startDate.day() ).rightJustify( 2, '0' ) ) ; | 534 | .arg( QString::number( startDate.day() ).rightJustify( 2, '0' ) ) ; |
534 | } | 535 | } |
535 | 536 | ||
536 | if ( settings & OPimContactAccess::DateYear ){ | 537 | if ( settings & OPimContactAccess::DateYear ){ |
537 | if ( settings & OPimContactAccess::DateDiff ) | 538 | if ( settings & OPimContactAccess::DateDiff ) |
538 | searchQuery += " AND"; | 539 | searchQuery += " AND"; |
539 | 540 | ||
540 | searchQuery += QString( " (\"%1\" LIKE '%2-%')" ) | 541 | searchQuery += QString( " (\"%1\" LIKE '%2-%')" ) |
541 | .arg( *it ) | 542 | .arg( *it ) |
542 | .arg( QString::number( endDate->year() ).rightJustify( 4, '0' ) ); | 543 | .arg( QString::number( endDate->year() ).rightJustify( 4, '0' ) ); |
543 | } | 544 | } |
544 | 545 | ||
545 | if ( settings & OPimContactAccess::DateMonth ){ | 546 | if ( settings & OPimContactAccess::DateMonth ){ |
546 | if ( ( settings & OPimContactAccess::DateDiff ) | 547 | if ( ( settings & OPimContactAccess::DateDiff ) |
547 | || ( settings & OPimContactAccess::DateYear ) ) | 548 | || ( settings & OPimContactAccess::DateYear ) ) |
548 | searchQuery += " AND"; | 549 | searchQuery += " AND"; |
549 | 550 | ||
550 | searchQuery += QString( " (\"%1\" LIKE '%-%2-%')" ) | 551 | searchQuery += QString( " (\"%1\" LIKE '%-%2-%')" ) |
551 | .arg( *it ) | 552 | .arg( *it ) |
552 | .arg( QString::number( endDate->month() ).rightJustify( 2, '0' ) ); | 553 | .arg( QString::number( endDate->month() ).rightJustify( 2, '0' ) ); |
553 | } | 554 | } |
554 | 555 | ||
555 | if ( settings & OPimContactAccess::DateDay ){ | 556 | if ( settings & OPimContactAccess::DateDay ){ |
556 | if ( ( settings & OPimContactAccess::DateDiff ) | 557 | if ( ( settings & OPimContactAccess::DateDiff ) |
557 | || ( settings & OPimContactAccess::DateYear ) | 558 | || ( settings & OPimContactAccess::DateYear ) |
558 | || ( settings & OPimContactAccess::DateMonth ) ) | 559 | || ( settings & OPimContactAccess::DateMonth ) ) |
559 | searchQuery += " AND"; | 560 | searchQuery += " AND"; |
560 | 561 | ||
561 | searchQuery += QString( " (\"%1\" LIKE '%-%-%2')" ) | 562 | searchQuery += QString( " (\"%1\" LIKE '%-%-%2')" ) |
562 | .arg( *it ) | 563 | .arg( *it ) |
563 | .arg( QString::number( endDate->day() ).rightJustify( 2, '0' ) ); | 564 | .arg( QString::number( endDate->day() ).rightJustify( 2, '0' ) ); |
564 | } | 565 | } |
565 | 566 | ||
566 | break; | 567 | break; |
567 | default: | 568 | default: |
568 | // Switching between case sensitive and insensitive... | 569 | // Switching between case sensitive and insensitive... |
569 | // LIKE is not case sensitive, GLOB is case sensitive | 570 | // LIKE is not case sensitive, GLOB is case sensitive |
570 | // Do exist a better solution to switch this ? | 571 | // Do exist a better solution to switch this ? |
571 | if ( settings & OPimContactAccess::IgnoreCase ) | 572 | if ( settings & OPimContactAccess::IgnoreCase ) |
572 | searchQuery += "(\"" + *it + "\"" + " LIKE " + "'" | 573 | searchQuery += "(\"" + *it + "\"" + " LIKE " + "'" |
573 | + queryStr.replace(QRegExp("\\*"),"%") + "'" + ")"; | 574 | + queryStr.replace(QRegExp("\\*"),"%") + "'" + ")"; |
574 | else | 575 | else |
575 | searchQuery += "(\"" + *it + "\"" + " GLOB " + "'" | 576 | searchQuery += "(\"" + *it + "\"" + " GLOB " + "'" |
576 | + queryStr + "'" + ")"; | 577 | + queryStr + "'" + ")"; |
577 | 578 | ||
578 | } | 579 | } |
579 | } | 580 | } |
580 | } | 581 | } |
581 | // Skip trailing "AND" | 582 | // Skip trailing "AND" |
582 | // if ( isAnyFieldSelected ) | 583 | // if ( isAnyFieldSelected ) |
583 | // qu = qu.left( qu.length() - 4 ); | 584 | // qu = qu.left( qu.length() - 4 ); |
584 | 585 | ||
585 | qu += searchQuery; | 586 | qu += searchQuery; |
586 | 587 | ||
587 | qDebug( "queryByExample query: %s", qu.latin1() ); | 588 | qDebug( "queryByExample query: %s", qu.latin1() ); |
588 | 589 | ||
589 | // Execute query and return the received uid's | 590 | // Execute query and return the received uid's |
590 | OSQLRawQuery raw( qu ); | 591 | OSQLRawQuery raw( qu ); |
591 | OSQLResult res = m_driver->query( &raw ); | 592 | OSQLResult res = m_driver->query( &raw ); |
592 | if ( res.state() != OSQLResult::Success ){ | 593 | if ( res.state() != OSQLResult::Success ){ |
593 | QArray<int> empty; | 594 | QArray<int> empty; |
594 | return empty; | 595 | return empty; |
595 | } | 596 | } |
596 | 597 | ||
597 | QArray<int> list = extractUids( res ); | 598 | QArray<int> list = extractUids( res ); |
598 | 599 | ||
599 | return list; | 600 | return list; |
600 | } | 601 | } |
601 | 602 | ||
602 | QArray<int> OPimContactAccessBackend_SQL::matchRegexp( const QRegExp &r ) const | 603 | QArray<int> OPimContactAccessBackend_SQL::matchRegexp( const QRegExp &r ) const |
603 | { | 604 | { |
604 | #if 0 | 605 | #if 0 |
605 | QArray<int> nix(0); | 606 | QArray<int> nix(0); |
606 | return nix; | 607 | return nix; |
607 | 608 | ||
608 | #else | 609 | #else |
609 | QString qu = "SELECT uid FROM addressbook WHERE ("; | 610 | QString qu = "SELECT uid FROM addressbook WHERE ("; |
610 | QString searchlist; | 611 | QString searchlist; |
611 | 612 | ||
612 | QStringList fieldList = OPimContactFields::untrfields( false ); | 613 | QStringList fieldList = OPimContactFields::untrfields( false ); |
613 | // QMap<QString, int> translate = OPimContactFields::untrFieldsToId(); | 614 | // QMap<QString, int> translate = OPimContactFields::untrFieldsToId(); |
614 | for ( QStringList::Iterator it = ++fieldList.begin(); it != fieldList.end(); ++it ){ | 615 | for ( QStringList::Iterator it = ++fieldList.begin(); it != fieldList.end(); ++it ){ |
615 | if ( !searchlist.isEmpty() ) | 616 | if ( !searchlist.isEmpty() ) |
616 | searchlist += " OR "; | 617 | searchlist += " OR "; |
617 | searchlist += " rlike(\""+ r.pattern() + "\",\"" + *it + "\") "; | 618 | searchlist += " rlike(\""+ r.pattern() + "\",\"" + *it + "\") "; |
618 | } | 619 | } |
619 | 620 | ||
620 | qu = qu + searchlist + ")"; | 621 | qu = qu + searchlist + ")"; |
621 | 622 | ||
622 | qDebug( "query: %s", qu.latin1() ); | 623 | qDebug( "query: %s", qu.latin1() ); |
623 | 624 | ||
624 | OSQLRawQuery raw( qu ); | 625 | OSQLRawQuery raw( qu ); |
625 | OSQLResult res = m_driver->query( &raw ); | 626 | OSQLResult res = m_driver->query( &raw ); |
626 | 627 | ||
627 | return extractUids( res ); | 628 | return extractUids( res ); |
628 | 629 | ||
629 | 630 | ||
630 | #endif | 631 | #endif |
631 | } | 632 | } |
632 | 633 | ||
633 | const uint OPimContactAccessBackend_SQL::querySettings() | 634 | const uint OPimContactAccessBackend_SQL::querySettings() |
634 | { | 635 | { |
635 | return OPimContactAccess::IgnoreCase | 636 | return OPimContactAccess::IgnoreCase |
636 | | OPimContactAccess::WildCards | 637 | | OPimContactAccess::WildCards |
637 | | OPimContactAccess::DateDiff | 638 | | OPimContactAccess::DateDiff |
638 | | OPimContactAccess::DateYear | 639 | | OPimContactAccess::DateYear |
639 | | OPimContactAccess::DateMonth | 640 | | OPimContactAccess::DateMonth |
640 | | OPimContactAccess::DateDay | 641 | | OPimContactAccess::DateDay |
641 | ; | 642 | ; |
642 | } | 643 | } |
643 | 644 | ||
644 | bool OPimContactAccessBackend_SQL::hasQuerySettings (uint querySettings) const | 645 | bool OPimContactAccessBackend_SQL::hasQuerySettings (uint querySettings) const |
645 | { | 646 | { |
646 | /* OPimContactAccess::IgnoreCase, DateDiff, DateYear, DateMonth, DateDay | 647 | /* OPimContactAccess::IgnoreCase, DateDiff, DateYear, DateMonth, DateDay |
647 | * may be added with any of the other settings. IgnoreCase should never used alone. | 648 | * may be added with any of the other settings. IgnoreCase should never used alone. |
648 | * Wildcards, RegExp, ExactMatch should never used at the same time... | 649 | * Wildcards, RegExp, ExactMatch should never used at the same time... |
649 | */ | 650 | */ |
650 | 651 | ||
651 | // Step 1: Check whether the given settings are supported by this backend | 652 | // Step 1: Check whether the given settings are supported by this backend |
652 | if ( ( querySettings & ( | 653 | if ( ( querySettings & ( |
653 | OPimContactAccess::IgnoreCase | 654 | OPimContactAccess::IgnoreCase |
654 | | OPimContactAccess::WildCards | 655 | | OPimContactAccess::WildCards |
655 | | OPimContactAccess::DateDiff | 656 | | OPimContactAccess::DateDiff |
656 | | OPimContactAccess::DateYear | 657 | | OPimContactAccess::DateYear |
657 | | OPimContactAccess::DateMonth | 658 | | OPimContactAccess::DateMonth |
658 | | OPimContactAccess::DateDay | 659 | | OPimContactAccess::DateDay |
659 | // | OPimContactAccess::RegExp | 660 | // | OPimContactAccess::RegExp |
660 | // | OPimContactAccess::ExactMatch | 661 | // | OPimContactAccess::ExactMatch |
661 | ) ) != querySettings ) | 662 | ) ) != querySettings ) |
662 | return false; | 663 | return false; |
663 | 664 | ||
664 | // Step 2: Check whether the given combinations are ok.. | 665 | // Step 2: Check whether the given combinations are ok.. |
665 | 666 | ||
666 | // IngoreCase alone is invalid | 667 | // IngoreCase alone is invalid |
667 | if ( querySettings == OPimContactAccess::IgnoreCase ) | 668 | if ( querySettings == OPimContactAccess::IgnoreCase ) |
668 | return false; | 669 | return false; |
669 | 670 | ||
670 | // WildCards, RegExp and ExactMatch should never used at the same time | 671 | // WildCards, RegExp and ExactMatch should never used at the same time |
671 | switch ( querySettings & ~( OPimContactAccess::IgnoreCase | 672 | switch ( querySettings & ~( OPimContactAccess::IgnoreCase |
672 | | OPimContactAccess::DateDiff | 673 | | OPimContactAccess::DateDiff |
673 | | OPimContactAccess::DateYear | 674 | | OPimContactAccess::DateYear |
674 | | OPimContactAccess::DateMonth | 675 | | OPimContactAccess::DateMonth |
675 | | OPimContactAccess::DateDay | 676 | | OPimContactAccess::DateDay |
676 | ) | 677 | ) |
677 | ){ | 678 | ){ |
678 | case OPimContactAccess::RegExp: | 679 | case OPimContactAccess::RegExp: |
679 | return ( true ); | 680 | return ( true ); |
680 | case OPimContactAccess::WildCards: | 681 | case OPimContactAccess::WildCards: |
681 | return ( true ); | 682 | return ( true ); |
682 | case OPimContactAccess::ExactMatch: | 683 | case OPimContactAccess::ExactMatch: |
683 | return ( true ); | 684 | return ( true ); |
684 | case 0: // one of the upper removed bits were set.. | 685 | case 0: // one of the upper removed bits were set.. |
685 | return ( true ); | 686 | return ( true ); |
686 | default: | 687 | default: |
687 | return ( false ); | 688 | return ( false ); |
688 | } | 689 | } |
689 | 690 | ||
690 | } | 691 | } |
691 | 692 | ||
692 | QArray<int> OPimContactAccessBackend_SQL::sorted( bool asc, int , int , int ) | 693 | QArray<int> OPimContactAccessBackend_SQL::sorted( bool asc, int , int , int ) |
693 | { | 694 | { |
694 | QTime t; | 695 | QTime t; |
695 | t.start(); | 696 | t.start(); |
696 | 697 | ||
697 | QString query = "SELECT uid FROM addressbook "; | 698 | QString query = "SELECT uid FROM addressbook "; |
698 | query += "ORDER BY \"Last Name\" "; | 699 | query += "ORDER BY \"Last Name\" "; |
699 | 700 | ||
700 | if ( !asc ) | 701 | if ( !asc ) |
701 | query += "DESC"; | 702 | query += "DESC"; |
702 | 703 | ||
703 | // qDebug("sorted query is: %s", query.latin1() ); | 704 | // qDebug("sorted query is: %s", query.latin1() ); |
704 | 705 | ||
705 | OSQLRawQuery raw( query ); | 706 | OSQLRawQuery raw( query ); |
706 | OSQLResult res = m_driver->query( &raw ); | 707 | OSQLResult res = m_driver->query( &raw ); |
707 | if ( res.state() != OSQLResult::Success ){ | 708 | if ( res.state() != OSQLResult::Success ){ |
708 | QArray<int> empty; | 709 | QArray<int> empty; |
709 | return empty; | 710 | return empty; |
710 | } | 711 | } |
711 | 712 | ||
712 | QArray<int> list = extractUids( res ); | 713 | QArray<int> list = extractUids( res ); |
713 | 714 | ||
714 | qDebug("sorted needed %d ms!", t.elapsed() ); | 715 | qDebug("sorted needed %d ms!", t.elapsed() ); |
715 | return list; | 716 | return list; |
716 | } | 717 | } |
717 | 718 | ||
718 | 719 | ||
719 | void OPimContactAccessBackend_SQL::update() | 720 | void OPimContactAccessBackend_SQL::update() |
720 | { | 721 | { |
721 | qDebug("Update starts"); | 722 | qDebug("Update starts"); |
722 | QTime t; | 723 | QTime t; |
723 | t.start(); | 724 | t.start(); |
724 | 725 | ||
725 | // Now load the database set and extract the uid's | 726 | // Now load the database set and extract the uid's |
726 | // which will be held locally | 727 | // which will be held locally |
727 | 728 | ||
728 | LoadQuery lo; | 729 | LoadQuery lo; |
729 | OSQLResult res = m_driver->query(&lo); | 730 | OSQLResult res = m_driver->query(&lo); |
730 | if ( res.state() != OSQLResult::Success ) | 731 | if ( res.state() != OSQLResult::Success ) |
731 | return; | 732 | return; |
732 | 733 | ||
733 | m_uids = extractUids( res ); | 734 | m_uids = extractUids( res ); |
734 | 735 | ||
735 | m_changed = false; | 736 | m_changed = false; |
736 | 737 | ||
737 | qDebug("Update ends %d ms", t.elapsed() ); | 738 | qDebug("Update ends %d ms", t.elapsed() ); |
738 | } | 739 | } |
739 | 740 | ||
740 | QArray<int> OPimContactAccessBackend_SQL::extractUids( OSQLResult& res ) const | 741 | QArray<int> OPimContactAccessBackend_SQL::extractUids( OSQLResult& res ) const |
741 | { | 742 | { |
742 | qDebug("extractUids"); | 743 | qDebug("extractUids"); |
743 | QTime t; | 744 | QTime t; |
744 | t.start(); | 745 | t.start(); |
745 | OSQLResultItem::ValueList list = res.results(); | 746 | OSQLResultItem::ValueList list = res.results(); |
746 | OSQLResultItem::ValueList::Iterator it; | 747 | OSQLResultItem::ValueList::Iterator it; |
747 | QArray<int> ints(list.count() ); | 748 | QArray<int> ints(list.count() ); |
748 | qDebug(" count = %d", list.count() ); | 749 | qDebug(" count = %d", list.count() ); |
749 | 750 | ||
750 | int i = 0; | 751 | int i = 0; |
751 | for (it = list.begin(); it != list.end(); ++it ) { | 752 | for (it = list.begin(); it != list.end(); ++it ) { |
752 | ints[i] = (*it).data("uid").toInt(); | 753 | ints[i] = (*it).data("uid").toInt(); |
753 | i++; | 754 | i++; |
754 | } | 755 | } |
755 | qDebug("extractUids ready: count2 = %d needs %d ms", i, t.elapsed() ); | 756 | qDebug("extractUids ready: count2 = %d needs %d ms", i, t.elapsed() ); |
756 | 757 | ||
757 | return ints; | 758 | return ints; |
758 | 759 | ||
759 | } | 760 | } |
760 | 761 | ||
761 | QMap<int, QString> OPimContactAccessBackend_SQL::requestNonCustom( int uid ) const | 762 | QMap<int, QString> OPimContactAccessBackend_SQL::requestNonCustom( int uid ) const |
762 | { | 763 | { |
763 | QTime t; | 764 | QTime t; |
764 | t.start(); | 765 | t.start(); |
765 | 766 | ||
766 | QMap<int, QString> nonCustomMap; | 767 | QMap<int, QString> nonCustomMap; |
767 | 768 | ||
768 | int t2needed = 0; | 769 | int t2needed = 0; |
769 | int t3needed = 0; | 770 | int t3needed = 0; |
770 | QTime t2; | 771 | QTime t2; |
771 | t2.start(); | 772 | t2.start(); |
772 | FindQuery query( uid ); | 773 | FindQuery query( uid ); |
773 | OSQLResult res_noncustom = m_driver->query( &query ); | 774 | OSQLResult res_noncustom = m_driver->query( &query ); |
774 | t2needed = t2.elapsed(); | 775 | t2needed = t2.elapsed(); |
775 | 776 | ||
776 | OSQLResultItem resItem = res_noncustom.first(); | 777 | OSQLResultItem resItem = res_noncustom.first(); |
777 | 778 | ||
778 | QTime t3; | 779 | QTime t3; |
779 | t3.start(); | 780 | t3.start(); |
780 | // Now loop through all columns | 781 | // Now loop through all columns |
781 | QStringList fieldList = OPimContactFields::untrfields( false ); | 782 | QStringList fieldList = OPimContactFields::untrfields( false ); |
782 | QMap<QString, int> translate = OPimContactFields::untrFieldsToId(); | 783 | QMap<QString, int> translate = OPimContactFields::untrFieldsToId(); |
783 | for ( QStringList::Iterator it = ++fieldList.begin(); it != fieldList.end(); ++it ){ | 784 | for ( QStringList::Iterator it = ++fieldList.begin(); it != fieldList.end(); ++it ){ |
784 | // Get data for the selected column and store it with the | 785 | // Get data for the selected column and store it with the |
785 | // corresponding id into the map.. | 786 | // corresponding id into the map.. |
786 | 787 | ||
787 | int id = translate[*it]; | 788 | int id = translate[*it]; |
788 | QString value = resItem.data( (*it) ); | 789 | QString value = resItem.data( (*it) ); |
789 | 790 | ||
790 | // qDebug("Reading %s... found: %s", (*it).latin1(), value.latin1() ); | 791 | // qDebug("Reading %s... found: %s", (*it).latin1(), value.latin1() ); |
791 | 792 | ||
792 | switch( id ){ | 793 | switch( id ){ |
793 | case Qtopia::Birthday: | 794 | case Qtopia::Birthday: |
794 | case Qtopia::Anniversary:{ | 795 | case Qtopia::Anniversary:{ |
795 | // Birthday and Anniversary are encoded special ( yyyy-mm-dd ) | 796 | // Birthday and Anniversary are encoded special ( yyyy-mm-dd ) |
796 | QStringList list = QStringList::split( '-', value ); | 797 | QStringList list = QStringList::split( '-', value ); |
797 | QStringList::Iterator lit = list.begin(); | 798 | QStringList::Iterator lit = list.begin(); |
798 | int year = (*lit).toInt(); | 799 | int year = (*lit).toInt(); |
799 | int month = (*(++lit)).toInt(); | 800 | int month = (*(++lit)).toInt(); |
800 | int day = (*(++lit)).toInt(); | 801 | int day = (*(++lit)).toInt(); |
801 | if ( ( day != 0 ) && ( month != 0 ) && ( year != 0 ) ){ | 802 | if ( ( day != 0 ) && ( month != 0 ) && ( year != 0 ) ){ |
802 | QDate date( year, month, day ); | 803 | QDate date( year, month, day ); |
803 | nonCustomMap.insert( id, OPimDateConversion::dateToString( date ) ); | 804 | nonCustomMap.insert( id, OPimDateConversion::dateToString( date ) ); |
804 | } | 805 | } |
805 | } | 806 | } |
806 | break; | 807 | break; |
807 | case Qtopia::AddressCategory: | 808 | case Qtopia::AddressCategory: |
808 | qDebug("Category is: %s", value.latin1() ); | 809 | qDebug("Category is: %s", value.latin1() ); |
809 | default: | 810 | default: |
810 | nonCustomMap.insert( id, value ); | 811 | nonCustomMap.insert( id, value ); |
811 | } | 812 | } |
812 | } | 813 | } |
813 | 814 | ||
814 | // First insert uid | 815 | // First insert uid |
815 | nonCustomMap.insert( Qtopia::AddressUid, resItem.data( "uid" ) ); | 816 | nonCustomMap.insert( Qtopia::AddressUid, resItem.data( "uid" ) ); |
816 | t3needed = t3.elapsed(); | 817 | t3needed = t3.elapsed(); |
817 | 818 | ||
818 | // qDebug("Adding UID: %s", resItem.data( "uid" ).latin1() ); | 819 | // qDebug("Adding UID: %s", resItem.data( "uid" ).latin1() ); |
819 | qDebug("RequestNonCustom needed: insg.:%d ms, query: %d ms, mapping: %d ms", | 820 | qDebug("RequestNonCustom needed: insg.:%d ms, query: %d ms, mapping: %d ms", |
820 | t.elapsed(), t2needed, t3needed ); | 821 | t.elapsed(), t2needed, t3needed ); |
821 | 822 | ||
822 | return nonCustomMap; | 823 | return nonCustomMap; |
823 | } | 824 | } |
824 | 825 | ||
825 | QMap<QString, QString> OPimContactAccessBackend_SQL::requestCustom( int uid ) const | 826 | QMap<QString, QString> OPimContactAccessBackend_SQL::requestCustom( int uid ) const |
826 | { | 827 | { |
827 | QTime t; | 828 | QTime t; |
828 | t.start(); | 829 | t.start(); |
829 | 830 | ||
830 | QMap<QString, QString> customMap; | 831 | QMap<QString, QString> customMap; |
831 | 832 | ||
832 | FindCustomQuery query( uid ); | 833 | FindCustomQuery query( uid ); |
833 | OSQLResult res_custom = m_driver->query( &query ); | 834 | OSQLResult res_custom = m_driver->query( &query ); |
834 | 835 | ||
835 | if ( res_custom.state() == OSQLResult::Failure ) { | 836 | if ( res_custom.state() == OSQLResult::Failure ) { |
836 | qWarning("OSQLResult::Failure in find query !!"); | 837 | qWarning("OSQLResult::Failure in find query !!"); |
837 | QMap<QString, QString> empty; | 838 | QMap<QString, QString> empty; |
838 | return empty; | 839 | return empty; |
839 | } | 840 | } |
840 | 841 | ||
841 | OSQLResultItem::ValueList list = res_custom.results(); | 842 | OSQLResultItem::ValueList list = res_custom.results(); |
842 | OSQLResultItem::ValueList::Iterator it = list.begin(); | 843 | OSQLResultItem::ValueList::Iterator it = list.begin(); |
843 | for ( ; it != list.end(); ++it ) { | 844 | for ( ; it != list.end(); ++it ) { |
844 | customMap.insert( (*it).data( "type" ), (*it).data( "value" ) ); | 845 | customMap.insert( (*it).data( "type" ), (*it).data( "value" ) ); |
845 | } | 846 | } |
846 | 847 | ||
847 | qDebug("RequestCustom needed: %d ms", t.elapsed() ); | 848 | qDebug("RequestCustom needed: %d ms", t.elapsed() ); |
848 | return customMap; | 849 | return customMap; |
849 | } | 850 | } |
850 | 851 | ||
851 | } | 852 | } |
diff --git a/libopie2/opiepim/core/ocontactaccess.cpp b/libopie2/opiepim/core/ocontactaccess.cpp index 4f9b504..67f267f 100644 --- a/libopie2/opiepim/core/ocontactaccess.cpp +++ b/libopie2/opiepim/core/ocontactaccess.cpp | |||
@@ -1,152 +1,158 @@ | |||
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) The Main Author <main-author@whereever.org> |
4 | =. Copyright (C) The Opie Team <opie-devel@handhelds.org> | 4 | =. Copyright (C) The Opie Team <opie-devel@handhelds.org> |
5 | .=l. | 5 | .=l. |
6 | .>+-= | 6 | .>+-= |
7 | _;:, .> :=|. This program is free software; you can | 7 | _;:, .> :=|. This program is free software; you can |
8 | .> <`_, > . <= redistribute it and/or modify it under | 8 | .> <`_, > . <= redistribute it and/or modify it under |
9 | :`=1 )Y*s>-.-- : the terms of the GNU Library General Public | 9 | :`=1 )Y*s>-.-- : the terms of the GNU Library General Public |
10 | .="- .-=="i, .._ License as published by the Free Software | 10 | .="- .-=="i, .._ License as published by the Free Software |
11 | - . .-<_> .<> Foundation; either version 2 of the License, | 11 | - . .-<_> .<> Foundation; either version 2 of the License, |
12 | ._= =} : or (at your option) any later version. | 12 | ._= =} : or (at your option) any later version. |
13 | .%`+i> _;_. | 13 | .%`+i> _;_. |
14 | .i_,=:_. -<s. This program is distributed in the hope that | 14 | .i_,=:_. -<s. This program is distributed in the hope that |
15 | + . -:. = it will be useful, but WITHOUT ANY WARRANTY; | 15 | + . -:. = it will be useful, but WITHOUT ANY WARRANTY; |
16 | : .. .:, . . . without even the implied warranty of | 16 | : .. .:, . . . without even the implied warranty of |
17 | =_ + =;=|` MERCHANTABILITY or FITNESS FOR A | 17 | =_ + =;=|` MERCHANTABILITY or FITNESS FOR A |
18 | _.=:. : :=>`: PARTICULAR PURPOSE. See the GNU | 18 | _.=:. : :=>`: PARTICULAR PURPOSE. See the GNU |
19 | ..}^=.= = ; Library General Public License for more | 19 | ..}^=.= = ; Library General Public License for more |
20 | ++= -. .` .: details. | 20 | ++= -. .` .: details. |
21 | : = ...= . :.=- | 21 | : = ...= . :.=- |
22 | -. .:....=;==+<; You should have received a copy of the GNU | 22 | -. .:....=;==+<; You should have received a copy of the GNU |
23 | -_. . . )=. = Library General Public License along with | 23 | -_. . . )=. = Library General Public License along with |
24 | -- :-=` this library; see the file COPYING.LIB. | 24 | -- :-=` this library; see the file COPYING.LIB. |
25 | If not, write to the Free Software Foundation, | 25 | If not, write to the Free Software Foundation, |
26 | Inc., 59 Temple Place - Suite 330, | 26 | Inc., 59 Temple Place - Suite 330, |
27 | Boston, MA 02111-1307, USA. | 27 | Boston, MA 02111-1307, USA. |
28 | */ | 28 | */ |
29 | /* | 29 | /* |
30 | * ===================================================================== | 30 | * ===================================================================== |
31 | * ToDo: XML-Backend: Automatic reload if something was changed... | 31 | * ToDo: XML-Backend: Automatic reload if something was changed... |
32 | * | 32 | * |
33 | * | 33 | * |
34 | */ | 34 | */ |
35 | 35 | ||
36 | #include "ocontactaccess.h" | 36 | #include "ocontactaccess.h" |
37 | #include "obackendfactory.h" | 37 | #include "obackendfactory.h" |
38 | 38 | ||
39 | #include <qasciidict.h> | 39 | #include <qasciidict.h> |
40 | #include <qdatetime.h> | 40 | #include <qdatetime.h> |
41 | #include <qfile.h> | 41 | #include <qfile.h> |
42 | #include <qregexp.h> | 42 | #include <qregexp.h> |
43 | #include <qlist.h> | 43 | #include <qlist.h> |
44 | #include <qcopchannel_qws.h> | 44 | #include <qcopchannel_qws.h> |
45 | 45 | ||
46 | //#include <qpe/qcopenvelope_qws.h> | 46 | //#include <qpe/qcopenvelope_qws.h> |
47 | #include <qpe/global.h> | 47 | #include <qpe/global.h> |
48 | 48 | ||
49 | #include <errno.h> | 49 | #include <errno.h> |
50 | #include <fcntl.h> | 50 | #include <fcntl.h> |
51 | #include <unistd.h> | 51 | #include <unistd.h> |
52 | #include <stdlib.h> | 52 | #include <stdlib.h> |
53 | 53 | ||
54 | #include <opie2/ocontactaccessbackend_xml.h> | 54 | #include <opie2/ocontactaccessbackend_xml.h> |
55 | #include <opie2/opimresolver.h> | ||
55 | 56 | ||
56 | namespace Opie { | 57 | namespace Opie { |
57 | 58 | ||
58 | OPimContactAccess::OPimContactAccess ( const QString appname, const QString , | 59 | OPimContactAccess::OPimContactAccess ( const QString appname, const QString , |
59 | OPimContactAccessBackend* end, bool autosync ): | 60 | OPimContactAccessBackend* end, bool autosync ): |
60 | OPimAccessTemplate<OPimContact>( end ) | 61 | OPimAccessTemplate<OPimContact>( end ) |
61 | { | 62 | { |
62 | /* take care of the backend. If there is no one defined, we | 63 | /* take care of the backend. If there is no one defined, we |
63 | * will use the XML-Backend as default (until we have a cute SQL-Backend..). | 64 | * will use the XML-Backend as default (until we have a cute SQL-Backend..). |
64 | */ | 65 | */ |
65 | if( end == 0 ) { | 66 | if( end == 0 ) { |
66 | qWarning ("Using BackendFactory !"); | 67 | qWarning ("Using BackendFactory !"); |
67 | end = OBackendFactory<OPimContactAccessBackend>::Default( "contact", appname ); | 68 | end = OBackendFactory<OPimContactAccessBackend>::Default( "contact", appname ); |
68 | } | 69 | } |
69 | // Set backend locally and in template | 70 | // Set backend locally and in template |
70 | m_backEnd = end; | 71 | m_backEnd = end; |
71 | OPimAccessTemplate<OPimContact>::setBackEnd (end); | 72 | OPimAccessTemplate<OPimContact>::setBackEnd (end); |
72 | 73 | ||
73 | 74 | ||
74 | /* Connect signal of external db change to function */ | 75 | /* Connect signal of external db change to function */ |
75 | QCopChannel *dbchannel = new QCopChannel( "QPE/PIM", this ); | 76 | QCopChannel *dbchannel = new QCopChannel( "QPE/PIM", this ); |
76 | connect( dbchannel, SIGNAL(received(const QCString&,const QByteArray&)), | 77 | connect( dbchannel, SIGNAL(received(const QCString&,const QByteArray&)), |
77 | this, SLOT(copMessage(const QCString&,const QByteArray&)) ); | 78 | this, SLOT(copMessage(const QCString&,const QByteArray&)) ); |
78 | if ( autosync ){ | 79 | if ( autosync ){ |
79 | QCopChannel *syncchannel = new QCopChannel( "QPE/Sync", this ); | 80 | QCopChannel *syncchannel = new QCopChannel( "QPE/Sync", this ); |
80 | connect( syncchannel, SIGNAL(received(const QCString&,const QByteArray&)), | 81 | connect( syncchannel, SIGNAL(received(const QCString&,const QByteArray&)), |
81 | this, SLOT(copMessage(const QCString&,const QByteArray&)) ); | 82 | this, SLOT(copMessage(const QCString&,const QByteArray&)) ); |
82 | } | 83 | } |
83 | 84 | ||
84 | 85 | ||
85 | } | 86 | } |
86 | OPimContactAccess::~OPimContactAccess () | 87 | OPimContactAccess::~OPimContactAccess () |
87 | { | 88 | { |
88 | /* The user may forget to save the changed database, therefore try to | 89 | /* The user may forget to save the changed database, therefore try to |
89 | * do it for him.. | 90 | * do it for him.. |
90 | */ | 91 | */ |
91 | save(); | 92 | save(); |
92 | // delete m_backEnd; is done by template.. | 93 | // delete m_backEnd; is done by template.. |
93 | } | 94 | } |
94 | 95 | ||
95 | 96 | ||
96 | bool OPimContactAccess::save () | 97 | bool OPimContactAccess::save () |
97 | { | 98 | { |
98 | /* If the database was changed externally, we could not save the | 99 | /* If the database was changed externally, we could not save the |
99 | * Data. This will remove added items which is unacceptable ! | 100 | * Data. This will remove added items which is unacceptable ! |
100 | * Therefore: Reload database and merge the data... | 101 | * Therefore: Reload database and merge the data... |
101 | */ | 102 | */ |
102 | if ( OPimAccessTemplate<OPimContact>::wasChangedExternally() ) | 103 | if ( OPimAccessTemplate<OPimContact>::wasChangedExternally() ) |
103 | reload(); | 104 | reload(); |
104 | 105 | ||
105 | bool status = OPimAccessTemplate<OPimContact>::save(); | 106 | bool status = OPimAccessTemplate<OPimContact>::save(); |
106 | if ( !status ) return false; | 107 | if ( !status ) return false; |
107 | 108 | ||
108 | /* Now tell everyone that new data is available. | 109 | /* Now tell everyone that new data is available. |
109 | */ | 110 | */ |
110 | QCopEnvelope e( "QPE/PIM", "addressbookUpdated()" ); | 111 | QCopEnvelope e( "QPE/PIM", "addressbookUpdated()" ); |
111 | 112 | ||
112 | return true; | 113 | return true; |
113 | } | 114 | } |
114 | 115 | ||
115 | const uint OPimContactAccess::querySettings() | 116 | const uint OPimContactAccess::querySettings() |
116 | { | 117 | { |
117 | return ( m_backEnd->querySettings() ); | 118 | return ( m_backEnd->querySettings() ); |
118 | } | 119 | } |
119 | 120 | ||
120 | bool OPimContactAccess::hasQuerySettings ( int querySettings ) const | 121 | bool OPimContactAccess::hasQuerySettings ( int querySettings ) const |
121 | { | 122 | { |
122 | return ( m_backEnd->hasQuerySettings ( querySettings ) ); | 123 | return ( m_backEnd->hasQuerySettings ( querySettings ) ); |
123 | } | 124 | } |
124 | OPimRecordList<OPimContact> OPimContactAccess::sorted( bool ascending, int sortOrder, int sortFilter, int cat ) const | 125 | OPimRecordList<OPimContact> OPimContactAccess::sorted( bool ascending, int sortOrder, int sortFilter, int cat ) const |
125 | { | 126 | { |
126 | QArray<int> matchingContacts = m_backEnd -> sorted( ascending, sortOrder, sortFilter, cat ); | 127 | QArray<int> matchingContacts = m_backEnd -> sorted( ascending, sortOrder, sortFilter, cat ); |
127 | return ( OPimRecordList<OPimContact>(matchingContacts, this) ); | 128 | return ( OPimRecordList<OPimContact>(matchingContacts, this) ); |
128 | } | 129 | } |
129 | 130 | ||
130 | 131 | ||
131 | bool OPimContactAccess::wasChangedExternally()const | 132 | bool OPimContactAccess::wasChangedExternally()const |
132 | { | 133 | { |
133 | return ( m_backEnd->wasChangedExternally() ); | 134 | return ( m_backEnd->wasChangedExternally() ); |
134 | } | 135 | } |
135 | 136 | ||
136 | 137 | ||
137 | void OPimContactAccess::copMessage( const QCString &msg, const QByteArray & ) | 138 | void OPimContactAccess::copMessage( const QCString &msg, const QByteArray & ) |
138 | { | 139 | { |
139 | if ( msg == "addressbookUpdated()" ){ | 140 | if ( msg == "addressbookUpdated()" ){ |
140 | qWarning ("OPimContactAccess: Received addressbokUpdated()"); | 141 | qWarning ("OPimContactAccess: Received addressbokUpdated()"); |
141 | emit signalChanged ( this ); | 142 | emit signalChanged ( this ); |
142 | } else if ( msg == "flush()" ) { | 143 | } else if ( msg == "flush()" ) { |
143 | qWarning ("OPimContactAccess: Received flush()"); | 144 | qWarning ("OPimContactAccess: Received flush()"); |
144 | save (); | 145 | save (); |
145 | } else if ( msg == "reload()" ) { | 146 | } else if ( msg == "reload()" ) { |
146 | qWarning ("OPimContactAccess: Received reload()"); | 147 | qWarning ("OPimContactAccess: Received reload()"); |
147 | reload (); | 148 | reload (); |
148 | emit signalChanged ( this ); | 149 | emit signalChanged ( this ); |
149 | } | 150 | } |
150 | } | 151 | } |
151 | 152 | ||
153 | int OPimContactAccess::rtti() const | ||
154 | { | ||
155 | return OPimResolver::AddressBook; | ||
156 | } | ||
157 | |||
152 | } | 158 | } |
diff --git a/libopie2/opiepim/core/ocontactaccess.h b/libopie2/opiepim/core/ocontactaccess.h index cf5333a..4429b6f 100644 --- a/libopie2/opiepim/core/ocontactaccess.h +++ b/libopie2/opiepim/core/ocontactaccess.h | |||
@@ -1,158 +1,163 @@ | |||
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) The Main Author <main-author@whereever.org> |
4 | =. Copyright (C) The Opie Team <opie-devel@handhelds.org> | 4 | =. Copyright (C) The Opie Team <opie-devel@handhelds.org> |
5 | .=l. | 5 | .=l. |
6 | .>+-= | 6 | .>+-= |
7 | _;:, .> :=|. This program is free software; you can | 7 | _;:, .> :=|. This program is free software; you can |
8 | .> <`_, > . <= redistribute it and/or modify it under | 8 | .> <`_, > . <= redistribute it and/or modify it under |
9 | :`=1 )Y*s>-.-- : the terms of the GNU Library General Public | 9 | :`=1 )Y*s>-.-- : the terms of the GNU Library General Public |
10 | .="- .-=="i, .._ License as published by the Free Software | 10 | .="- .-=="i, .._ License as published by the Free Software |
11 | - . .-<_> .<> Foundation; either version 2 of the License, | 11 | - . .-<_> .<> Foundation; either version 2 of the License, |
12 | ._= =} : or (at your option) any later version. | 12 | ._= =} : or (at your option) any later version. |
13 | .%`+i> _;_. | 13 | .%`+i> _;_. |
14 | .i_,=:_. -<s. This program is distributed in the hope that | 14 | .i_,=:_. -<s. This program is distributed in the hope that |
15 | + . -:. = it will be useful, but WITHOUT ANY WARRANTY; | 15 | + . -:. = it will be useful, but WITHOUT ANY WARRANTY; |
16 | : .. .:, . . . without even the implied warranty of | 16 | : .. .:, . . . without even the implied warranty of |
17 | =_ + =;=|` MERCHANTABILITY or FITNESS FOR A | 17 | =_ + =;=|` MERCHANTABILITY or FITNESS FOR A |
18 | _.=:. : :=>`: PARTICULAR PURPOSE. See the GNU | 18 | _.=:. : :=>`: PARTICULAR PURPOSE. See the GNU |
19 | ..}^=.= = ; Library General Public License for more | 19 | ..}^=.= = ; Library General Public License for more |
20 | ++= -. .` .: details. | 20 | ++= -. .` .: details. |
21 | : = ...= . :.=- | 21 | : = ...= . :.=- |
22 | -. .:....=;==+<; You should have received a copy of the GNU | 22 | -. .:....=;==+<; You should have received a copy of the GNU |
23 | -_. . . )=. = Library General Public License along with | 23 | -_. . . )=. = Library General Public License along with |
24 | -- :-=` this library; see the file COPYING.LIB. | 24 | -- :-=` this library; see the file COPYING.LIB. |
25 | If not, write to the Free Software Foundation, | 25 | If not, write to the Free Software Foundation, |
26 | Inc., 59 Temple Place - Suite 330, | 26 | Inc., 59 Temple Place - Suite 330, |
27 | Boston, MA 02111-1307, USA. | 27 | Boston, MA 02111-1307, USA. |
28 | */ | 28 | */ |
29 | /* | 29 | /* |
30 | * ===================================================================== | 30 | * ===================================================================== |
31 | * ToDo: Define enum for query settings | 31 | * ToDo: Define enum for query settings |
32 | * ===================================================================== | 32 | * ===================================================================== |
33 | */ | 33 | */ |
34 | #ifndef _OCONTACTACCESS_H | 34 | #ifndef _OCONTACTACCESS_H |
35 | #define _OCONTACTACCESS_H | 35 | #define _OCONTACTACCESS_H |
36 | 36 | ||
37 | #include <qobject.h> | 37 | #include <qobject.h> |
38 | 38 | ||
39 | #include <qpe/qcopenvelope_qws.h> | 39 | #include <qpe/qcopenvelope_qws.h> |
40 | 40 | ||
41 | #include <qvaluelist.h> | 41 | #include <qvaluelist.h> |
42 | #include <qfileinfo.h> | 42 | #include <qfileinfo.h> |
43 | 43 | ||
44 | #include <opie2/opimcontact.h> | 44 | #include <opie2/opimcontact.h> |
45 | #include <opie2/ocontactaccessbackend.h> | 45 | #include <opie2/ocontactaccessbackend.h> |
46 | #include <opie2/opimaccesstemplate.h> | 46 | #include <opie2/opimaccesstemplate.h> |
47 | 47 | ||
48 | namespace Opie { | 48 | namespace Opie { |
49 | /** | 49 | /** |
50 | * Class to access the contacts database. | 50 | * Class to access the contacts database. |
51 | * This is just a frontend for the real database handling which is | 51 | * This is just a frontend for the real database handling which is |
52 | * done by the backend. | 52 | * done by the backend. |
53 | * This class is used to access the Contacts on a system. This class as any OPIE PIM | 53 | * This class is used to access the Contacts on a system. This class as any OPIE PIM |
54 | * class is backend independent. | 54 | * class is backend independent. |
55 | * @author Stefan Eilers, Holger Freyther | 55 | * @author Stefan Eilers, Holger Freyther |
56 | * @see OPimAccessTemplate | 56 | * @see OPimAccessTemplate |
57 | */ | 57 | */ |
58 | class OPimContactAccess: public QObject, public OPimAccessTemplate<OPimContact> | 58 | class OPimContactAccess: public QObject, public OPimAccessTemplate<OPimContact> |
59 | { | 59 | { |
60 | Q_OBJECT | 60 | Q_OBJECT |
61 | 61 | ||
62 | public: | 62 | public: |
63 | /** | 63 | /** |
64 | * Create Database with contacts (addressbook). | 64 | * Create Database with contacts (addressbook). |
65 | * @param appname Name of application which wants access to the database | 65 | * @param appname Name of application which wants access to the database |
66 | * (i.e. "todolist") | 66 | * (i.e. "todolist") |
67 | * @param filename The name of the database file. If not set, the default one | 67 | * @param filename The name of the database file. If not set, the default one |
68 | * is used. | 68 | * is used. |
69 | * @param backend Pointer to an alternative Backend. If not set, we will use | 69 | * @param backend Pointer to an alternative Backend. If not set, we will use |
70 | * the default backend. | 70 | * the default backend. |
71 | * @param handlesync If <b>true</b> the database stores the current state | 71 | * @param handlesync If <b>true</b> the database stores the current state |
72 | * automatically if it receives the signals <i>flush()</i> and <i>reload()</i> | 72 | * automatically if it receives the signals <i>flush()</i> and <i>reload()</i> |
73 | * which are used before and after synchronisation. If the application wants | 73 | * which are used before and after synchronisation. If the application wants |
74 | * to react itself, it should be disabled by setting it to <b>false</b> | 74 | * to react itself, it should be disabled by setting it to <b>false</b> |
75 | * @see OPimContactAccessBackend | 75 | * @see OPimContactAccessBackend |
76 | */ | 76 | */ |
77 | OPimContactAccess (const QString appname, const QString filename = 0l, | 77 | OPimContactAccess (const QString appname, const QString filename = 0l, |
78 | OPimContactAccessBackend* backend = 0l, bool handlesync = true); | 78 | OPimContactAccessBackend* backend = 0l, bool handlesync = true); |
79 | ~OPimContactAccess (); | 79 | ~OPimContactAccess (); |
80 | 80 | ||
81 | /** Constants for query. | 81 | /** Constants for query. |
82 | * Use this constants to set the query parameters. | 82 | * Use this constants to set the query parameters. |
83 | * Note: <i>query_IgnoreCase</i> just make sense with one of the other attributes ! | 83 | * Note: <i>query_IgnoreCase</i> just make sense with one of the other attributes ! |
84 | * @see queryByExample() | 84 | * @see queryByExample() |
85 | */ | 85 | */ |
86 | enum QuerySettings { | 86 | enum QuerySettings { |
87 | WildCards = 0x0001, | 87 | WildCards = 0x0001, |
88 | IgnoreCase = 0x0002, | 88 | IgnoreCase = 0x0002, |
89 | RegExp = 0x0004, | 89 | RegExp = 0x0004, |
90 | ExactMatch = 0x0008, | 90 | ExactMatch = 0x0008, |
91 | MatchOne = 0x0010, // Only one Entry must match | 91 | MatchOne = 0x0010, // Only one Entry must match |
92 | DateDiff = 0x0020, // Find all entries from today until given date | 92 | DateDiff = 0x0020, // Find all entries from today until given date |
93 | DateYear = 0x0040, // The year matches | 93 | DateYear = 0x0040, // The year matches |
94 | DateMonth = 0x0080, // The month matches | 94 | DateMonth = 0x0080, // The month matches |
95 | DateDay = 0x0100, // The day matches | 95 | DateDay = 0x0100, // The day matches |
96 | }; | 96 | }; |
97 | 97 | ||
98 | 98 | ||
99 | /** Return all Contacts in a sorted manner. | 99 | /** Return all Contacts in a sorted manner. |
100 | * @param ascending true: Sorted in acending order. | 100 | * @param ascending true: Sorted in acending order. |
101 | * @param sortOrder Currently not implemented. Just defined to stay compatible to otodoaccess | 101 | * @param sortOrder Currently not implemented. Just defined to stay compatible to otodoaccess |
102 | * @param sortFilter Currently not implemented. Just defined to stay compatible to otodoaccess | 102 | * @param sortFilter Currently not implemented. Just defined to stay compatible to otodoaccess |
103 | * @param cat Currently not implemented. Just defined to stay compatible to otodoaccess | 103 | * @param cat Currently not implemented. Just defined to stay compatible to otodoaccess |
104 | */ | 104 | */ |
105 | List sorted( bool ascending, int sortOrder, int sortFilter, int cat ) const; | 105 | List sorted( bool ascending, int sortOrder, int sortFilter, int cat ) const; |
106 | 106 | ||
107 | /** Return all possible settings. | 107 | /** Return all possible settings. |
108 | * @return All settings provided by the current backend | 108 | * @return All settings provided by the current backend |
109 | * (i.e.: query_WildCards & query_IgnoreCase) | 109 | * (i.e.: query_WildCards & query_IgnoreCase) |
110 | */ | 110 | */ |
111 | const uint querySettings(); | 111 | const uint querySettings(); |
112 | 112 | ||
113 | /** Check whether settings are correct. | 113 | /** Check whether settings are correct. |
114 | * @return <i>true</i> if the given settings are correct and possible. | 114 | * @return <i>true</i> if the given settings are correct and possible. |
115 | */ | 115 | */ |
116 | bool hasQuerySettings ( int querySettings ) const; | 116 | bool hasQuerySettings ( int querySettings ) const; |
117 | 117 | ||
118 | /** | 118 | /** |
119 | * if the resource was changed externally. | 119 | * if the resource was changed externally. |
120 | * You should use the signal instead of polling possible changes ! | 120 | * You should use the signal instead of polling possible changes ! |
121 | */ | 121 | */ |
122 | bool wasChangedExternally()const; | 122 | bool wasChangedExternally()const; |
123 | 123 | ||
124 | 124 | ||
125 | /** Save contacts database. | 125 | /** Save contacts database. |
126 | * Save is more a "commit". After calling this function, all changes are public available. | 126 | * Save is more a "commit". After calling this function, all changes are public available. |
127 | * @return true if successful | 127 | * @return true if successful |
128 | */ | 128 | */ |
129 | bool save(); | 129 | bool save(); |
130 | |||
131 | /** | ||
132 | * Return identification of used records | ||
133 | */ | ||
134 | int rtti() const; | ||
130 | 135 | ||
131 | signals: | 136 | signals: |
132 | /* Signal is emitted if the database was changed. Therefore | 137 | /* Signal is emitted if the database was changed. Therefore |
133 | * we may need to reload to stay consistent. | 138 | * we may need to reload to stay consistent. |
134 | * @param which Pointer to the database who created this event. This pointer | 139 | * @param which Pointer to the database who created this event. This pointer |
135 | * is useful if an application has to handle multiple databases at the same time. | 140 | * is useful if an application has to handle multiple databases at the same time. |
136 | * @see reload() | 141 | * @see reload() |
137 | */ | 142 | */ |
138 | void signalChanged ( const OPimContactAccess *which ); | 143 | void signalChanged ( const OPimContactAccess *which ); |
139 | 144 | ||
140 | 145 | ||
141 | private: | 146 | private: |
142 | // class OPimContactAccessPrivate; | 147 | // class OPimContactAccessPrivate; |
143 | // OPimContactAccessPrivate* d; | 148 | // OPimContactAccessPrivate* d; |
144 | OPimContactAccessBackend *m_backEnd; | 149 | OPimContactAccessBackend *m_backEnd; |
145 | bool m_loading:1; | 150 | bool m_loading:1; |
146 | 151 | ||
147 | private slots: | 152 | private slots: |
148 | void copMessage( const QCString &msg, const QByteArray &data ); | 153 | void copMessage( const QCString &msg, const QByteArray &data ); |
149 | 154 | ||
150 | private: | 155 | private: |
151 | class Private; | 156 | class Private; |
152 | Private *d; | 157 | Private *d; |
153 | 158 | ||
154 | }; | 159 | }; |
155 | 160 | ||
156 | } | 161 | } |
157 | 162 | ||
158 | #endif | 163 | #endif |
diff --git a/libopie2/opiepim/core/odatebookaccess.cpp b/libopie2/opiepim/core/odatebookaccess.cpp index ac310c1..29298ea 100644 --- a/libopie2/opiepim/core/odatebookaccess.cpp +++ b/libopie2/opiepim/core/odatebookaccess.cpp | |||
@@ -1,112 +1,117 @@ | |||
1 | /* | 1 | /* |
2 | This file is part of the Opie Project | 2 | This file is part of the Opie Project |
3 | Copyright (C) Stefan Eilers (Eilers.Stefan@epost.de) | 3 | Copyright (C) Stefan Eilers (Eilers.Stefan@epost.de) |
4 | =. Copyright (C) The Opie Team <opie-devel@handhelds.org> | 4 | =. Copyright (C) The Opie Team <opie-devel@handhelds.org> |
5 | .=l. | 5 | .=l. |
6 | .>+-= | 6 | .>+-= |
7 | _;:, .> :=|. This program is free software; you can | 7 | _;:, .> :=|. This program is free software; you can |
8 | .> <`_, > . <= redistribute it and/or modify it under | 8 | .> <`_, > . <= redistribute it and/or modify it under |
9 | :`=1 )Y*s>-.-- : the terms of the GNU Library General Public | 9 | :`=1 )Y*s>-.-- : the terms of the GNU Library General Public |
10 | .="- .-=="i, .._ License as published by the Free Software | 10 | .="- .-=="i, .._ License as published by the Free Software |
11 | - . .-<_> .<> Foundation; either version 2 of the License, | 11 | - . .-<_> .<> Foundation; either version 2 of the License, |
12 | ._= =} : or (at your option) any later version. | 12 | ._= =} : or (at your option) any later version. |
13 | .%`+i> _;_. | 13 | .%`+i> _;_. |
14 | .i_,=:_. -<s. This program is distributed in the hope that | 14 | .i_,=:_. -<s. This program is distributed in the hope that |
15 | + . -:. = it will be useful, but WITHOUT ANY WARRANTY; | 15 | + . -:. = it will be useful, but WITHOUT ANY WARRANTY; |
16 | : .. .:, . . . without even the implied warranty of | 16 | : .. .:, . . . without even the implied warranty of |
17 | =_ + =;=|` MERCHANTABILITY or FITNESS FOR A | 17 | =_ + =;=|` MERCHANTABILITY or FITNESS FOR A |
18 | _.=:. : :=>`: PARTICULAR PURPOSE. See the GNU | 18 | _.=:. : :=>`: PARTICULAR PURPOSE. See the GNU |
19 | ..}^=.= = ; Library General Public License for more | 19 | ..}^=.= = ; Library General Public License for more |
20 | ++= -. .` .: details. | 20 | ++= -. .` .: details. |
21 | : = ...= . :.=- | 21 | : = ...= . :.=- |
22 | -. .:....=;==+<; You should have received a copy of the GNU | 22 | -. .:....=;==+<; You should have received a copy of the GNU |
23 | -_. . . )=. = Library General Public License along with | 23 | -_. . . )=. = Library General Public License along with |
24 | -- :-=` this library; see the file COPYING.LIB. | 24 | -- :-=` this library; see the file COPYING.LIB. |
25 | If not, write to the Free Software Foundation, | 25 | If not, write to the Free Software Foundation, |
26 | Inc., 59 Temple Place - Suite 330, | 26 | Inc., 59 Temple Place - Suite 330, |
27 | Boston, MA 02111-1307, USA. | 27 | Boston, MA 02111-1307, USA. |
28 | */ | 28 | */ |
29 | #include <opie2/obackendfactory.h> | 29 | #include <opie2/obackendfactory.h> |
30 | #include <opie2/odatebookaccess.h> | 30 | #include <opie2/odatebookaccess.h> |
31 | #include <opie2/opimresolver.h> | ||
31 | 32 | ||
32 | namespace Opie { | 33 | namespace Opie { |
33 | /** | 34 | /** |
34 | * Simple constructor | 35 | * Simple constructor |
35 | * It takes a ODateBookAccessBackend as parent. If it is 0 the default implementation | 36 | * It takes a ODateBookAccessBackend as parent. If it is 0 the default implementation |
36 | * will be used! | 37 | * will be used! |
37 | * @param back The backend to be used or 0 for the default backend | 38 | * @param back The backend to be used or 0 for the default backend |
38 | * @param ac What kind of access is intended | 39 | * @param ac What kind of access is intended |
39 | */ | 40 | */ |
40 | ODateBookAccess::ODateBookAccess( ODateBookAccessBackend* back, enum Access ac ) | 41 | ODateBookAccess::ODateBookAccess( ODateBookAccessBackend* back, enum Access ac ) |
41 | : OPimAccessTemplate<OPimEvent>( back ) | 42 | : OPimAccessTemplate<OPimEvent>( back ) |
42 | { | 43 | { |
43 | if (!back ) | 44 | if (!back ) |
44 | back = OBackendFactory<ODateBookAccessBackend>::Default("datebook", QString::null ); | 45 | back = OBackendFactory<ODateBookAccessBackend>::Default("datebook", QString::null ); |
45 | 46 | ||
46 | m_backEnd = back; | 47 | m_backEnd = back; |
47 | setBackEnd( m_backEnd ); | 48 | setBackEnd( m_backEnd ); |
48 | } | 49 | } |
49 | ODateBookAccess::~ODateBookAccess() { | 50 | ODateBookAccess::~ODateBookAccess() { |
50 | } | 51 | } |
51 | 52 | ||
52 | /** | 53 | /** |
53 | * @return all events available | 54 | * @return all events available |
54 | */ | 55 | */ |
55 | ODateBookAccess::List ODateBookAccess::rawEvents()const { | 56 | ODateBookAccess::List ODateBookAccess::rawEvents()const { |
56 | QArray<int> ints = m_backEnd->rawEvents(); | 57 | QArray<int> ints = m_backEnd->rawEvents(); |
57 | 58 | ||
58 | List lis( ints, this ); | 59 | List lis( ints, this ); |
59 | return lis; | 60 | return lis; |
60 | } | 61 | } |
61 | 62 | ||
62 | /** | 63 | /** |
63 | * @return all repeating events | 64 | * @return all repeating events |
64 | */ | 65 | */ |
65 | ODateBookAccess::List ODateBookAccess::rawRepeats()const { | 66 | ODateBookAccess::List ODateBookAccess::rawRepeats()const { |
66 | QArray<int> ints = m_backEnd->rawRepeats(); | 67 | QArray<int> ints = m_backEnd->rawRepeats(); |
67 | 68 | ||
68 | List lis( ints, this ); | 69 | List lis( ints, this ); |
69 | return lis; | 70 | return lis; |
70 | } | 71 | } |
71 | 72 | ||
72 | /** | 73 | /** |
73 | * @return all non repeating events | 74 | * @return all non repeating events |
74 | */ | 75 | */ |
75 | ODateBookAccess::List ODateBookAccess::nonRepeats()const { | 76 | ODateBookAccess::List ODateBookAccess::nonRepeats()const { |
76 | QArray<int> ints = m_backEnd->nonRepeats(); | 77 | QArray<int> ints = m_backEnd->nonRepeats(); |
77 | 78 | ||
78 | List lis( ints, this ); | 79 | List lis( ints, this ); |
79 | return lis; | 80 | return lis; |
80 | } | 81 | } |
81 | 82 | ||
82 | /** | 83 | /** |
83 | * @return dates in the time span between from and to | 84 | * @return dates in the time span between from and to |
84 | * @param from Include all events from... | 85 | * @param from Include all events from... |
85 | * @param to Include all events to... | 86 | * @param to Include all events to... |
86 | */ | 87 | */ |
87 | OEffectiveEvent::ValueList ODateBookAccess::effectiveEvents( const QDate& from, const QDate& to ) const { | 88 | OEffectiveEvent::ValueList ODateBookAccess::effectiveEvents( const QDate& from, const QDate& to ) const { |
88 | return m_backEnd->effectiveEvents( from, to ); | 89 | return m_backEnd->effectiveEvents( from, to ); |
89 | } | 90 | } |
90 | /** | 91 | /** |
91 | * @return all events at a given datetime | 92 | * @return all events at a given datetime |
92 | */ | 93 | */ |
93 | OEffectiveEvent::ValueList ODateBookAccess::effectiveEvents( const QDateTime& start ) const { | 94 | OEffectiveEvent::ValueList ODateBookAccess::effectiveEvents( const QDateTime& start ) const { |
94 | return m_backEnd->effectiveEvents( start ); | 95 | return m_backEnd->effectiveEvents( start ); |
95 | } | 96 | } |
96 | 97 | ||
97 | /** | 98 | /** |
98 | * @return non repeating dates in the time span between from and to | 99 | * @return non repeating dates in the time span between from and to |
99 | * @param from Include all events from... | 100 | * @param from Include all events from... |
100 | * @param to Include all events to... | 101 | * @param to Include all events to... |
101 | */ | 102 | */ |
102 | OEffectiveEvent::ValueList ODateBookAccess::effectiveNonRepeatingEvents( const QDate& from, const QDate& to ) const { | 103 | OEffectiveEvent::ValueList ODateBookAccess::effectiveNonRepeatingEvents( const QDate& from, const QDate& to ) const { |
103 | return m_backEnd->effectiveNonRepeatingEvents( from, to ); | 104 | return m_backEnd->effectiveNonRepeatingEvents( from, to ); |
104 | } | 105 | } |
105 | /** | 106 | /** |
106 | * @return all non repeating events at a given datetime | 107 | * @return all non repeating events at a given datetime |
107 | */ | 108 | */ |
108 | OEffectiveEvent::ValueList ODateBookAccess::effectiveNonRepeatingEvents( const QDateTime& start ) const { | 109 | OEffectiveEvent::ValueList ODateBookAccess::effectiveNonRepeatingEvents( const QDateTime& start ) const { |
109 | return m_backEnd->effectiveNonRepeatingEvents( start ); | 110 | return m_backEnd->effectiveNonRepeatingEvents( start ); |
110 | } | 111 | } |
112 | int ODateBookAccess::rtti() const | ||
113 | { | ||
114 | return OPimResolver::DateBook; | ||
115 | } | ||
111 | 116 | ||
112 | } | 117 | } |
diff --git a/libopie2/opiepim/core/odatebookaccess.h b/libopie2/opiepim/core/odatebookaccess.h index 6c9290f..c6c3598 100644 --- a/libopie2/opiepim/core/odatebookaccess.h +++ b/libopie2/opiepim/core/odatebookaccess.h | |||
@@ -1,75 +1,81 @@ | |||
1 | /* | 1 | /* |
2 | This file is part of the Opie Project | 2 | This file is part of the Opie Project |
3 | Copyright (C) Stefan Eilers (Eilers.Stefan@epost.de) | 3 | Copyright (C) Stefan Eilers (Eilers.Stefan@epost.de) |
4 | =. Copyright (C) The Opie Team <opie-devel@handhelds.org> | 4 | =. Copyright (C) The Opie Team <opie-devel@handhelds.org> |
5 | .=l. | 5 | .=l. |
6 | .>+-= | 6 | .>+-= |
7 | _;:, .> :=|. This program is free software; you can | 7 | _;:, .> :=|. This program is free software; you can |
8 | .> <`_, > . <= redistribute it and/or modify it under | 8 | .> <`_, > . <= redistribute it and/or modify it under |
9 | :`=1 )Y*s>-.-- : the terms of the GNU Library General Public | 9 | :`=1 )Y*s>-.-- : the terms of the GNU Library General Public |
10 | .="- .-=="i, .._ License as published by the Free Software | 10 | .="- .-=="i, .._ License as published by the Free Software |
11 | - . .-<_> .<> Foundation; either version 2 of the License, | 11 | - . .-<_> .<> Foundation; either version 2 of the License, |
12 | ._= =} : or (at your option) any later version. | 12 | ._= =} : or (at your option) any later version. |
13 | .%`+i> _;_. | 13 | .%`+i> _;_. |
14 | .i_,=:_. -<s. This program is distributed in the hope that | 14 | .i_,=:_. -<s. This program is distributed in the hope that |
15 | + . -:. = it will be useful, but WITHOUT ANY WARRANTY; | 15 | + . -:. = it will be useful, but WITHOUT ANY WARRANTY; |
16 | : .. .:, . . . without even the implied warranty of | 16 | : .. .:, . . . without even the implied warranty of |
17 | =_ + =;=|` MERCHANTABILITY or FITNESS FOR A | 17 | =_ + =;=|` MERCHANTABILITY or FITNESS FOR A |
18 | _.=:. : :=>`: PARTICULAR PURPOSE. See the GNU | 18 | _.=:. : :=>`: PARTICULAR PURPOSE. See the GNU |
19 | ..}^=.= = ; Library General Public License for more | 19 | ..}^=.= = ; Library General Public License for more |
20 | ++= -. .` .: details. | 20 | ++= -. .` .: details. |
21 | : = ...= . :.=- | 21 | : = ...= . :.=- |
22 | -. .:....=;==+<; You should have received a copy of the GNU | 22 | -. .:....=;==+<; You should have received a copy of the GNU |
23 | -_. . . )=. = Library General Public License along with | 23 | -_. . . )=. = Library General Public License along with |
24 | -- :-=` this library; see the file COPYING.LIB. | 24 | -- :-=` this library; see the file COPYING.LIB. |
25 | If not, write to the Free Software Foundation, | 25 | If not, write to the Free Software Foundation, |
26 | Inc., 59 Temple Place - Suite 330, | 26 | Inc., 59 Temple Place - Suite 330, |
27 | Boston, MA 02111-1307, USA. | 27 | Boston, MA 02111-1307, USA. |
28 | */ | 28 | */ |
29 | #ifndef OPIE_DATE_BOOK_ACCESS_H | 29 | #ifndef OPIE_DATE_BOOK_ACCESS_H |
30 | #define OPIE_DATE_BOOK_ACCESS_H | 30 | #define OPIE_DATE_BOOK_ACCESS_H |
31 | 31 | ||
32 | #include "odatebookaccessbackend.h" | 32 | #include "odatebookaccessbackend.h" |
33 | #include "opimaccesstemplate.h" | 33 | #include "opimaccesstemplate.h" |
34 | 34 | ||
35 | #include <opie2/opimevent.h> | 35 | #include <opie2/opimevent.h> |
36 | 36 | ||
37 | namespace Opie { | 37 | namespace Opie { |
38 | /** | 38 | /** |
39 | * This is the object orientated datebook database. It'll use OBackendFactory | 39 | * This is the object orientated datebook database. It'll use OBackendFactory |
40 | * to query for a backend. | 40 | * to query for a backend. |
41 | * All access to the datebook should be done via this class. | 41 | * All access to the datebook should be done via this class. |
42 | * Make sure to load and save the datebook this is not part of | 42 | * Make sure to load and save the datebook this is not part of |
43 | * destructing and creating the object | 43 | * destructing and creating the object |
44 | * | 44 | * |
45 | * @author Holger Freyther, Stefan Eilers | 45 | * @author Holger Freyther, Stefan Eilers |
46 | */ | 46 | */ |
47 | class ODateBookAccess : public OPimAccessTemplate<OPimEvent> { | 47 | class ODateBookAccess : public OPimAccessTemplate<OPimEvent> { |
48 | public: | 48 | public: |
49 | ODateBookAccess( ODateBookAccessBackend* = 0l, enum Access acc = Random ); | 49 | ODateBookAccess( ODateBookAccessBackend* = 0l, enum Access acc = Random ); |
50 | ~ODateBookAccess(); | 50 | ~ODateBookAccess(); |
51 | 51 | ||
52 | /* return all events */ | 52 | /* return all events */ |
53 | List rawEvents()const; | 53 | List rawEvents()const; |
54 | 54 | ||
55 | /* return repeating events */ | 55 | /* return repeating events */ |
56 | List rawRepeats()const; | 56 | List rawRepeats()const; |
57 | 57 | ||
58 | /* return non repeating events */ | 58 | /* return non repeating events */ |
59 | List nonRepeats()const; | 59 | List nonRepeats()const; |
60 | 60 | ||
61 | /* return non repeating events (from,to) */ | 61 | /* return non repeating events (from,to) */ |
62 | OEffectiveEvent::ValueList effectiveEvents( const QDate& from, const QDate& to ) const; | 62 | OEffectiveEvent::ValueList effectiveEvents( const QDate& from, const QDate& to ) const; |
63 | OEffectiveEvent::ValueList effectiveEvents( const QDateTime& start ) const; | 63 | OEffectiveEvent::ValueList effectiveEvents( const QDateTime& start ) const; |
64 | OEffectiveEvent::ValueList effectiveNonRepeatingEvents( const QDate& from, const QDate& to ) const; | 64 | OEffectiveEvent::ValueList effectiveNonRepeatingEvents( const QDate& from, const QDate& to ) const; |
65 | OEffectiveEvent::ValueList effectiveNonRepeatingEvents( const QDateTime& start ) const; | 65 | OEffectiveEvent::ValueList effectiveNonRepeatingEvents( const QDateTime& start ) const; |
66 | 66 | ||
67 | /** | ||
68 | * Return identification of used records | ||
69 | */ | ||
70 | int rtti() const; | ||
71 | |||
72 | |||
67 | private: | 73 | private: |
68 | ODateBookAccessBackend* m_backEnd; | 74 | ODateBookAccessBackend* m_backEnd; |
69 | class Private; | 75 | class Private; |
70 | Private* d; | 76 | Private* d; |
71 | }; | 77 | }; |
72 | 78 | ||
73 | } | 79 | } |
74 | 80 | ||
75 | #endif | 81 | #endif |
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,335 +1,357 @@ | |||
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 | ||
41 | namespace Opie { | 42 | namespace Opie { |
42 | 43 | ||
43 | class OPimAccessTemplatePrivate; | 44 | class 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 | */ |
52 | 53 | ||
53 | template <class T = OPimRecord > | 54 | template <class T = OPimRecord > |
54 | class OPimAccessTemplate : public OTemplateBase<T> { | 55 | class OPimAccessTemplate : public OTemplateBase<T> { |
55 | public: | 56 | public: |
56 | enum Access { | 57 | enum Access { |
57 | Random = 0, | 58 | Random = 0, |
58 | SortedAccess | 59 | SortedAccess |
59 | }; | 60 | }; |
60 | typedef OPimRecordList<T> List; | 61 | typedef OPimRecordList<T> List; |
61 | typedef OPimAccessBackend<T> BackEnd; | 62 | typedef OPimAccessBackend<T> BackEnd; |
62 | typedef OPimCache<T> Cache; | 63 | typedef OPimCache<T> Cache; |
63 | 64 | ||
64 | /** | 65 | /** |
65 | * c'tor BackEnd | 66 | * c'tor BackEnd |
66 | * enum Access a small hint on how to handle the backend | 67 | * enum Access a small hint on how to handle the backend |
67 | */ | 68 | */ |
68 | OPimAccessTemplate( BackEnd* end); | 69 | OPimAccessTemplate( BackEnd* end); |
69 | 70 | ||
70 | virtual ~OPimAccessTemplate(); | 71 | virtual ~OPimAccessTemplate(); |
71 | 72 | ||
72 | /** | 73 | /** |
73 | * load from the backend | 74 | * load from the backend |
74 | */ | 75 | */ |
75 | bool load(); | 76 | bool load(); |
76 | 77 | ||
77 | /** Reload database. | 78 | /** Reload database. |
78 | * You should execute this function if the external database | 79 | * You should execute this function if the external database |
79 | * was changed. | 80 | * was changed. |
80 | * This function will load the external database and afterwards | 81 | * This function will load the external database and afterwards |
81 | * rejoin the local changes. Therefore the local database will be set consistent. | 82 | * rejoin the local changes. Therefore the local database will be set consistent. |
82 | */ | 83 | */ |
83 | virtual bool reload(); | 84 | virtual bool reload(); |
84 | 85 | ||
85 | /** Save contacts database. | 86 | /** Save contacts database. |
86 | * Save is more a "commit". After calling this function, all changes are public available. | 87 | * Save is more a "commit". After calling this function, all changes are public available. |
87 | * @return true if successful | 88 | * @return true if successful |
88 | */ | 89 | */ |
89 | bool save(); | 90 | bool save(); |
90 | 91 | ||
91 | /** | 92 | /** |
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; |
172 | protected: | 180 | protected: |
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 | ||
186 | private: | 194 | private: |
187 | OPimAccessTemplatePrivate *d; | 195 | OPimAccessTemplatePrivate *d; |
188 | 196 | ||
189 | }; | 197 | }; |
190 | 198 | ||
191 | template <class T> | 199 | template <class T> |
192 | OPimAccessTemplate<T>::OPimAccessTemplate( BackEnd* end ) | 200 | OPimAccessTemplate<T>::OPimAccessTemplate( BackEnd* end ) |
193 | : OTemplateBase<T>(), m_backEnd( end ) | 201 | : OTemplateBase<T>(), m_backEnd( end ) |
194 | { | 202 | { |
195 | if (end ) | 203 | if (end ) |
196 | end->setFrontend( this ); | 204 | end->setFrontend( this ); |
197 | } | 205 | } |
198 | template <class T> | 206 | template <class T> |
199 | OPimAccessTemplate<T>::~OPimAccessTemplate() { | 207 | OPimAccessTemplate<T>::~OPimAccessTemplate() { |
200 | qWarning("~OPimAccessTemplate<T>"); | 208 | qWarning("~OPimAccessTemplate<T>"); |
201 | delete m_backEnd; | 209 | delete m_backEnd; |
202 | } | 210 | } |
203 | template <class T> | 211 | template <class T> |
204 | bool OPimAccessTemplate<T>::load() { | 212 | bool OPimAccessTemplate<T>::load() { |
205 | invalidateCache(); | 213 | invalidateCache(); |
206 | return m_backEnd->load(); | 214 | return m_backEnd->load(); |
207 | } | 215 | } |
208 | template <class T> | 216 | template <class T> |
209 | bool OPimAccessTemplate<T>::reload() { | 217 | bool OPimAccessTemplate<T>::reload() { |
210 | invalidateCache(); // zecke: I think this should be added (se) | 218 | invalidateCache(); // zecke: I think this should be added (se) |
211 | return m_backEnd->reload(); | 219 | return m_backEnd->reload(); |
212 | } | 220 | } |
213 | template <class T> | 221 | template <class T> |
214 | bool OPimAccessTemplate<T>::save() { | 222 | bool OPimAccessTemplate<T>::save() { |
215 | return m_backEnd->save(); | 223 | return m_backEnd->save(); |
216 | } | 224 | } |
217 | template <class T> | 225 | template <class T> |
218 | typename OPimAccessTemplate<T>::List OPimAccessTemplate<T>::allRecords()const { | 226 | typename OPimAccessTemplate<T>::List OPimAccessTemplate<T>::allRecords()const { |
219 | QArray<int> ints = m_backEnd->allRecords(); | 227 | QArray<int> ints = m_backEnd->allRecords(); |
220 | List lis(ints, this ); | 228 | List lis(ints, this ); |
221 | return lis; | 229 | return lis; |
222 | } | 230 | } |
223 | template <class T> | 231 | template <class T> |
224 | typename OPimAccessTemplate<T>::List OPimAccessTemplate<T>::matchRegexp( const QRegExp &r )const { | 232 | typename OPimAccessTemplate<T>::List OPimAccessTemplate<T>::matchRegexp( const QRegExp &r )const { |
225 | QArray<int> ints = m_backEnd->matchRegexp( r ); | 233 | QArray<int> ints = m_backEnd->matchRegexp( r ); |
226 | List lis(ints, this ); | 234 | List lis(ints, this ); |
227 | return lis; | 235 | return lis; |
228 | } | 236 | } |
229 | template <class T> | 237 | template <class T> |
230 | QArray<int> OPimAccessTemplate<T>::records()const { | 238 | QArray<int> OPimAccessTemplate<T>::records()const { |
231 | return m_backEnd->allRecords(); | 239 | return m_backEnd->allRecords(); |
232 | } | 240 | } |
233 | template <class T> | 241 | template <class T> |
234 | typename OPimAccessTemplate<T>::List | 242 | typename OPimAccessTemplate<T>::List |
235 | OPimAccessTemplate<T>::queryByExample( const T& t, int settings, const QDateTime& d ) { | 243 | OPimAccessTemplate<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 | } |
241 | template <class T> | 249 | template <class T> |
242 | T OPimAccessTemplate<T>::find( int uid ) const{ | 250 | T 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 | } |
247 | template <class T> | 255 | template <class T> |
248 | T OPimAccessTemplate<T>::find( int uid, const QArray<int>& ar, | 256 | T 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 | } |
264 | template <class T> | 272 | template <class T> |
265 | void OPimAccessTemplate<T>::clear() { | 273 | void OPimAccessTemplate<T>::clear() { |
266 | invalidateCache(); | 274 | invalidateCache(); |
267 | m_backEnd->clear(); | 275 | m_backEnd->clear(); |
268 | } | 276 | } |
269 | template <class T> | 277 | template <class T> |
270 | bool OPimAccessTemplate<T>::add( const T& t ) { | 278 | bool 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 | |||
274 | template <class T> | 283 | template <class T> |
275 | bool OPimAccessTemplate<T>::add( const OPimRecord& rec) { | 284 | bool 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 | |||
294 | template <class T> | ||
295 | bool 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 | |||
283 | template <class T> | 305 | template <class T> |
284 | bool OPimAccessTemplate<T>::remove( const T& t ) { | 306 | bool OPimAccessTemplate<T>::remove( const T& t ) { |
285 | return remove( t.uid() ); | 307 | return remove( t.uid() ); |
286 | } | 308 | } |
287 | template <class T> | 309 | template <class T> |
288 | bool OPimAccessTemplate<T>::remove( int uid ) { | 310 | bool 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 | } |
292 | template <class T> | 314 | template <class T> |
293 | bool OPimAccessTemplate<T>::remove( const OPimRecord& rec) { | 315 | bool OPimAccessTemplate<T>::remove( const OPimRecord& rec) { |
294 | return remove( rec.uid() ); | 316 | return remove( rec.uid() ); |
295 | } | 317 | } |
296 | template <class T> | 318 | template <class T> |
297 | bool OPimAccessTemplate<T>::replace( const T& t ) { | 319 | bool 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 | } |
301 | template <class T> | 323 | template <class T> |
302 | void OPimAccessTemplate<T>::invalidateCache() { | 324 | void OPimAccessTemplate<T>::invalidateCache() { |
303 | m_cache.invalidate(); | 325 | m_cache.invalidate(); |
304 | } | 326 | } |
305 | template <class T> | 327 | template <class T> |
306 | typename OPimAccessTemplate<T>::BackEnd* OPimAccessTemplate<T>::backEnd() { | 328 | typename OPimAccessTemplate<T>::BackEnd* OPimAccessTemplate<T>::backEnd() { |
307 | return m_backEnd; | 329 | return m_backEnd; |
308 | } | 330 | } |
309 | template <class T> | 331 | template <class T> |
310 | bool OPimAccessTemplate<T>::wasChangedExternally()const { | 332 | bool OPimAccessTemplate<T>::wasChangedExternally()const { |
311 | return false; | 333 | return false; |
312 | } | 334 | } |
313 | template <class T> | 335 | template <class T> |
314 | void OPimAccessTemplate<T>::setBackEnd( BackEnd* end ) { | 336 | void 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 | } |
319 | template <class T> | 341 | template <class T> |
320 | void OPimAccessTemplate<T>::cache( const T& t ) const{ | 342 | void 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 | } |
324 | template <class T> | 346 | template <class T> |
325 | void OPimAccessTemplate<T>::setSaneCacheSize( int size ) { | 347 | void OPimAccessTemplate<T>::setSaneCacheSize( int size ) { |
326 | m_cache.setSize( size ); | 348 | m_cache.setSize( size ); |
327 | } | 349 | } |
328 | template <class T> | 350 | template <class T> |
329 | void OPimAccessTemplate<T>::setReadAhead( uint count ) { | 351 | void OPimAccessTemplate<T>::setReadAhead( uint count ) { |
330 | m_backEnd->setReadAhead( count ); | 352 | m_backEnd->setReadAhead( count ); |
331 | } | 353 | } |
332 | 354 | ||
333 | } | 355 | } |
334 | 356 | ||
335 | #endif | 357 | #endif |
diff --git a/libopie2/opiepim/core/opimtemplatebase.h b/libopie2/opiepim/core/opimtemplatebase.h index 58cbfeb..b48dfed 100644 --- a/libopie2/opiepim/core/opimtemplatebase.h +++ b/libopie2/opiepim/core/opimtemplatebase.h | |||
@@ -1,130 +1,122 @@ | |||
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) The Opie Team <opie-devel@handhelds.org> | 4 | =. Copyright (C) The Opie Team <opie-devel@handhelds.org> |
5 | .=l. | 5 | .=l. |
6 | .>+-= | 6 | .>+-= |
7 | _;:, .> :=|. This program is free software; you can | 7 | _;:, .> :=|. This program is free software; you can |
8 | .> <`_, > . <= redistribute it and/or modify it under | 8 | .> <`_, > . <= redistribute it and/or modify it under |
9 | :`=1 )Y*s>-.-- : the terms of the GNU Library General Public | 9 | :`=1 )Y*s>-.-- : the terms of the GNU Library General Public |
10 | .="- .-=="i, .._ License as published by the Free Software | 10 | .="- .-=="i, .._ License as published by the Free Software |
11 | - . .-<_> .<> Foundation; either version 2 of the License, | 11 | - . .-<_> .<> Foundation; either version 2 of the License, |
12 | ._= =} : or (at your option) any later version. | 12 | ._= =} : or (at your option) any later version. |
13 | .%`+i> _;_. | 13 | .%`+i> _;_. |
14 | .i_,=:_. -<s. This program is distributed in the hope that | 14 | .i_,=:_. -<s. This program is distributed in the hope that |
15 | + . -:. = it will be useful, but WITHOUT ANY WARRANTY; | 15 | + . -:. = it will be useful, but WITHOUT ANY WARRANTY; |
16 | : .. .:, . . . without even the implied warranty of | 16 | : .. .:, . . . without even the implied warranty of |
17 | =_ + =;=|` MERCHANTABILITY or FITNESS FOR A | 17 | =_ + =;=|` MERCHANTABILITY or FITNESS FOR A |
18 | _.=:. : :=>`: PARTICULAR PURPOSE. See the GNU | 18 | _.=:. : :=>`: PARTICULAR PURPOSE. See the GNU |
19 | ..}^=.= = ; Library General Public License for more | 19 | ..}^=.= = ; Library General Public License for more |
20 | ++= -. .` .: details. | 20 | ++= -. .` .: details. |
21 | : = ...= . :.=- | 21 | : = ...= . :.=- |
22 | -. .:....=;==+<; You should have received a copy of the GNU | 22 | -. .:....=;==+<; You should have received a copy of the GNU |
23 | -_. . . )=. = Library General Public License along with | 23 | -_. . . )=. = Library General Public License along with |
24 | -- :-=` this library; see the file COPYING.LIB. | 24 | -- :-=` this library; see the file COPYING.LIB. |
25 | If not, write to the Free Software Foundation, | 25 | If not, write to the Free Software Foundation, |
26 | Inc., 59 Temple Place - Suite 330, | 26 | Inc., 59 Temple Place - Suite 330, |
27 | Boston, MA 02111-1307, USA. | 27 | Boston, MA 02111-1307, USA. |
28 | */ | 28 | */ |
29 | #ifndef OTEMPLATEBASE_H | 29 | #ifndef OTEMPLATEBASE_H |
30 | #define OTEMPLATEBASE_H | 30 | #define OTEMPLATEBASE_H |
31 | 31 | ||
32 | /* OPIE */ | 32 | /* OPIE */ |
33 | #include <opie2/opimrecord.h> | 33 | #include <opie2/opimrecord.h> |
34 | 34 | ||
35 | /* QT */ | 35 | /* QT */ |
36 | #include <qarray.h> | 36 | #include <qarray.h> |
37 | 37 | ||
38 | namespace Opie { | 38 | namespace Opie { |
39 | /** | 39 | /** |
40 | * Templates do not have a base class, This is why | 40 | * Templates do not have a base class, This is why |
41 | * we've this class | 41 | * we've this class |
42 | * this is here to give us the possibility | 42 | * this is here to give us the possibility |
43 | * to have a common base class | 43 | * to have a common base class |
44 | * You may not want to use that interface internaly | 44 | * You may not want to use that interface internaly |
45 | * POOR mans interface | 45 | * POOR mans interface |
46 | */ | 46 | */ |
47 | class OPimBasePrivate; | 47 | class OPimBasePrivate; |
48 | struct OPimBase { | 48 | struct OPimBase { |
49 | /** | 49 | /** |
50 | * return the rtti | 50 | * return the rtti |
51 | */ | 51 | */ |
52 | virtual int rtti()= 0; | 52 | virtual int rtti() const = 0; |
53 | virtual OPimRecord* record()const = 0; | 53 | virtual OPimRecord* record()const = 0; |
54 | virtual OPimRecord* record(int uid)const = 0; | 54 | virtual OPimRecord* record(int uid)const = 0; |
55 | virtual bool add( const OPimRecord& ) = 0; | 55 | virtual bool add( const OPimRecord& ) = 0; |
56 | virtual bool add( const OPimRecord* ) = 0; | ||
56 | virtual bool remove( int uid ) = 0; | 57 | virtual bool remove( int uid ) = 0; |
57 | virtual bool remove( const OPimRecord& ) = 0; | 58 | virtual bool remove( const OPimRecord& ) = 0; |
58 | virtual void clear() = 0; | 59 | virtual void clear() = 0; |
59 | virtual bool load() = 0; | 60 | virtual bool load() = 0; |
60 | virtual bool save() = 0; | 61 | virtual bool save() = 0; |
61 | virtual QArray<int> records()const = 0; | 62 | virtual QArray<int> records()const = 0; |
62 | /* | 63 | /* |
63 | * ADD editing here? | 64 | * ADD editing here? |
64 | * -zecke | 65 | * -zecke |
65 | */ | 66 | */ |
66 | private: | 67 | private: |
67 | OPimBasePrivate* d; | 68 | OPimBasePrivate* d; |
68 | 69 | ||
69 | }; | 70 | }; |
70 | /** | 71 | /** |
71 | * internal template base | 72 | * internal template base |
72 | * T needs to implement the copy c'tor!!! | 73 | * T needs to implement the copy c'tor!!! |
73 | */ | 74 | */ |
74 | class OTemplateBasePrivate; | 75 | class OTemplateBasePrivate; |
75 | template <class T = OPimRecord> | 76 | template <class T = OPimRecord> |
76 | class OTemplateBase : public OPimBase { | 77 | class OTemplateBase : public OPimBase { |
77 | public: | 78 | public: |
78 | enum CacheDirection { Forward=0, Reverse }; | 79 | enum CacheDirection { Forward=0, Reverse }; |
79 | OTemplateBase() { | 80 | OTemplateBase() { |
80 | }; | 81 | }; |
81 | virtual ~OTemplateBase() { | 82 | virtual ~OTemplateBase() { |
82 | } | 83 | } |
83 | virtual T find( int uid )const = 0; | 84 | virtual T find( int uid )const = 0; |
84 | 85 | ||
85 | /** | 86 | /** |
86 | * read ahead find | 87 | * read ahead find |
87 | */ | 88 | */ |
88 | virtual T find( int uid, const QArray<int>& items, | 89 | virtual T find( int uid, const QArray<int>& items, |
89 | uint current, CacheDirection dir = Forward )const = 0; | 90 | uint current, CacheDirection dir = Forward )const = 0; |
90 | virtual void cache( const T& )const = 0; | 91 | virtual void cache( const T& )const = 0; |
91 | virtual void setSaneCacheSize( int ) = 0; | 92 | virtual void setSaneCacheSize( int ) = 0; |
92 | 93 | ||
93 | /* reimplement of OPimBase */ | ||
94 | int rtti(); | ||
95 | OPimRecord* record()const; | 94 | OPimRecord* record()const; |
96 | OPimRecord* record(int uid )const; | 95 | OPimRecord* record(int uid )const; |
97 | static T* rec(); | 96 | static T* rec(); |
98 | 97 | ||
99 | private: | 98 | private: |
100 | OTemplateBasePrivate *d; | 99 | OTemplateBasePrivate *d; |
101 | }; | 100 | }; |
102 | 101 | ||
103 | /* | 102 | |
104 | * implementation | ||
105 | */ | ||
106 | template <class T> | ||
107 | int | ||
108 | OTemplateBase<T>::rtti() { | ||
109 | return T::rtti(); | ||
110 | } | ||
111 | template <class T> | 103 | template <class T> |
112 | OPimRecord* OTemplateBase<T>::record()const { | 104 | OPimRecord* OTemplateBase<T>::record()const { |
113 | T* t = new T; | 105 | T* t = new T; |
114 | return t; | 106 | return t; |
115 | } | 107 | } |
116 | template <class T> | 108 | template <class T> |
117 | OPimRecord* OTemplateBase<T>::record(int uid )const { | 109 | OPimRecord* OTemplateBase<T>::record(int uid )const { |
118 | T t2 = find(uid ); | 110 | T t2 = find(uid ); |
119 | T* t1 = new T(t2); | 111 | T* t1 = new T(t2); |
120 | 112 | ||
121 | return t1; | 113 | return t1; |
122 | }; | 114 | }; |
123 | template <class T> | 115 | template <class T> |
124 | T* OTemplateBase<T>::rec() { | 116 | T* OTemplateBase<T>::rec() { |
125 | return new T; | 117 | return new T; |
126 | } | 118 | } |
127 | 119 | ||
128 | } | 120 | } |
129 | 121 | ||
130 | #endif | 122 | #endif |
diff --git a/libopie2/opiepim/core/otodoaccess.cpp b/libopie2/opiepim/core/otodoaccess.cpp index 83750d5..6fa0089 100644 --- a/libopie2/opiepim/core/otodoaccess.cpp +++ b/libopie2/opiepim/core/otodoaccess.cpp | |||
@@ -1,93 +1,100 @@ | |||
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) The Main Author <main-author@whereever.org> |
4 | =. Copyright (C) The Opie Team <opie-devel@handhelds.org> | 4 | =. Copyright (C) The Opie Team <opie-devel@handhelds.org> |
5 | .=l. | 5 | .=l. |
6 | .>+-= | 6 | .>+-= |
7 | _;:, .> :=|. This program is free software; you can | 7 | _;:, .> :=|. This program is free software; you can |
8 | .> <`_, > . <= redistribute it and/or modify it under | 8 | .> <`_, > . <= redistribute it and/or modify it under |
9 | :`=1 )Y*s>-.-- : the terms of the GNU Library General Public | 9 | :`=1 )Y*s>-.-- : the terms of the GNU Library General Public |
10 | .="- .-=="i, .._ License as published by the Free Software | 10 | .="- .-=="i, .._ License as published by the Free Software |
11 | - . .-<_> .<> Foundation; either version 2 of the License, | 11 | - . .-<_> .<> Foundation; either version 2 of the License, |
12 | ._= =} : or (at your option) any later version. | 12 | ._= =} : or (at your option) any later version. |
13 | .%`+i> _;_. | 13 | .%`+i> _;_. |
14 | .i_,=:_. -<s. This program is distributed in the hope that | 14 | .i_,=:_. -<s. This program is distributed in the hope that |
15 | + . -:. = it will be useful, but WITHOUT ANY WARRANTY; | 15 | + . -:. = it will be useful, but WITHOUT ANY WARRANTY; |
16 | : .. .:, . . . without even the implied warranty of | 16 | : .. .:, . . . without even the implied warranty of |
17 | =_ + =;=|` MERCHANTABILITY or FITNESS FOR A | 17 | =_ + =;=|` MERCHANTABILITY or FITNESS FOR A |
18 | _.=:. : :=>`: PARTICULAR PURPOSE. See the GNU | 18 | _.=:. : :=>`: PARTICULAR PURPOSE. See the GNU |
19 | ..}^=.= = ; Library General Public License for more | 19 | ..}^=.= = ; Library General Public License for more |
20 | ++= -. .` .: details. | 20 | ++= -. .` .: details. |
21 | : = ...= . :.=- | 21 | : = ...= . :.=- |
22 | -. .:....=;==+<; You should have received a copy of the GNU | 22 | -. .:....=;==+<; You should have received a copy of the GNU |
23 | -_. . . )=. = Library General Public License along with | 23 | -_. . . )=. = Library General Public License along with |
24 | -- :-=` this library; see the file COPYING.LIB. | 24 | -- :-=` this library; see the file COPYING.LIB. |
25 | If not, write to the Free Software Foundation, | 25 | If not, write to the Free Software Foundation, |
26 | Inc., 59 Temple Place - Suite 330, | 26 | Inc., 59 Temple Place - Suite 330, |
27 | Boston, MA 02111-1307, USA. | 27 | Boston, MA 02111-1307, USA. |
28 | */ | 28 | */ |
29 | #include <qdatetime.h> | 29 | #include <qdatetime.h> |
30 | 30 | ||
31 | #include <qpe/alarmserver.h> | 31 | #include <qpe/alarmserver.h> |
32 | 32 | ||
33 | // #include "otodoaccesssql.h" | 33 | // #include "otodoaccesssql.h" |
34 | #include <opie2/otodoaccess.h> | 34 | #include <opie2/otodoaccess.h> |
35 | #include <opie2/obackendfactory.h> | 35 | #include <opie2/obackendfactory.h> |
36 | #include <opie2/opimresolver.h> | ||
36 | 37 | ||
37 | namespace Opie { | 38 | namespace Opie { |
38 | OPimTodoAccess::OPimTodoAccess( OPimTodoAccessBackend* end, enum Access ) | 39 | OPimTodoAccess::OPimTodoAccess( OPimTodoAccessBackend* end, enum Access ) |
39 | : QObject(), OPimAccessTemplate<OPimTodo>( end ), m_todoBackEnd( end ) | 40 | : QObject(), OPimAccessTemplate<OPimTodo>( end ), m_todoBackEnd( end ) |
40 | { | 41 | { |
41 | // if (end == 0l ) | 42 | // if (end == 0l ) |
42 | // m_todoBackEnd = new OPimTodoAccessBackendSQL( QString::null); | 43 | // m_todoBackEnd = new OPimTodoAccessBackendSQL( QString::null); |
43 | 44 | ||
44 | // Zecke: Du musst hier noch fr das XML-Backend einen Appnamen bergeben ! | 45 | // Zecke: Du musst hier noch fr das XML-Backend einen Appnamen bergeben ! |
45 | if (end == 0l ) | 46 | if (end == 0l ) |
46 | m_todoBackEnd = OBackendFactory<OPimTodoAccessBackend>::Default ("todo", QString::null); | 47 | m_todoBackEnd = OBackendFactory<OPimTodoAccessBackend>::Default ("todo", QString::null); |
47 | 48 | ||
48 | setBackEnd( m_todoBackEnd ); | 49 | setBackEnd( m_todoBackEnd ); |
49 | } | 50 | } |
50 | OPimTodoAccess::~OPimTodoAccess() { | 51 | OPimTodoAccess::~OPimTodoAccess() { |
51 | // qWarning("~OPimTodoAccess"); | 52 | // qWarning("~OPimTodoAccess"); |
52 | } | 53 | } |
53 | void OPimTodoAccess::mergeWith( const QValueList<OPimTodo>& list ) { | 54 | void OPimTodoAccess::mergeWith( const QValueList<OPimTodo>& list ) { |
54 | QValueList<OPimTodo>::ConstIterator it; | 55 | QValueList<OPimTodo>::ConstIterator it; |
55 | for ( it = list.begin(); it != list.end(); ++it ) { | 56 | for ( it = list.begin(); it != list.end(); ++it ) { |
56 | replace( (*it) ); | 57 | replace( (*it) ); |
57 | } | 58 | } |
58 | } | 59 | } |
59 | OPimTodoAccess::List OPimTodoAccess::effectiveToDos( const QDate& start, | 60 | OPimTodoAccess::List OPimTodoAccess::effectiveToDos( const QDate& start, |
60 | const QDate& end, | 61 | const QDate& end, |
61 | bool includeNoDates ) { | 62 | bool includeNoDates ) { |
62 | QArray<int> ints = m_todoBackEnd->effectiveToDos( start, end, includeNoDates ); | 63 | QArray<int> ints = m_todoBackEnd->effectiveToDos( start, end, includeNoDates ); |
63 | 64 | ||
64 | List lis( ints, this ); | 65 | List lis( ints, this ); |
65 | return lis; | 66 | return lis; |
66 | } | 67 | } |
67 | OPimTodoAccess::List OPimTodoAccess::effectiveToDos( const QDate& start, | 68 | OPimTodoAccess::List OPimTodoAccess::effectiveToDos( const QDate& start, |
68 | bool includeNoDates ) { | 69 | bool includeNoDates ) { |
69 | return effectiveToDos( start, QDate::currentDate(), | 70 | return effectiveToDos( start, QDate::currentDate(), |
70 | includeNoDates ); | 71 | includeNoDates ); |
71 | } | 72 | } |
72 | OPimTodoAccess::List OPimTodoAccess::overDue() { | 73 | OPimTodoAccess::List OPimTodoAccess::overDue() { |
73 | List lis( m_todoBackEnd->overDue(), this ); | 74 | List lis( m_todoBackEnd->overDue(), this ); |
74 | return lis; | 75 | return lis; |
75 | } | 76 | } |
76 | /* sort order */ | 77 | /* sort order */ |
77 | OPimTodoAccess::List OPimTodoAccess::sorted( bool ascending, int sort,int filter, int cat ) { | 78 | OPimTodoAccess::List OPimTodoAccess::sorted( bool ascending, int sort,int filter, int cat ) { |
78 | QArray<int> ints = m_todoBackEnd->sorted( ascending, sort, | 79 | QArray<int> ints = m_todoBackEnd->sorted( ascending, sort, |
79 | filter, cat ); | 80 | filter, cat ); |
80 | OPimTodoAccess::List list( ints, this ); | 81 | OPimTodoAccess::List list( ints, this ); |
81 | return list; | 82 | return list; |
82 | } | 83 | } |
83 | void OPimTodoAccess::removeAllCompleted() { | 84 | void OPimTodoAccess::removeAllCompleted() { |
84 | m_todoBackEnd->removeAllCompleted(); | 85 | m_todoBackEnd->removeAllCompleted(); |
85 | } | 86 | } |
86 | QBitArray OPimTodoAccess::backendSupport( const QString& ) const{ | 87 | QBitArray OPimTodoAccess::backendSupport( const QString& ) const{ |
87 | return m_todoBackEnd->supports(); | 88 | return m_todoBackEnd->supports(); |
88 | } | 89 | } |
89 | bool OPimTodoAccess::backendSupports( int attr, const QString& ar) const{ | 90 | bool OPimTodoAccess::backendSupports( int attr, const QString& ar) const{ |
90 | return backendSupport(ar).testBit( attr ); | 91 | return backendSupport(ar).testBit( attr ); |
91 | } | 92 | } |
92 | 93 | ||
94 | |||
95 | int OPimTodoAccess::rtti() const | ||
96 | { | ||
97 | return OPimResolver::TodoList; | ||
98 | } | ||
99 | |||
93 | } | 100 | } |
diff --git a/libopie2/opiepim/core/otodoaccess.h b/libopie2/opiepim/core/otodoaccess.h index 51f3793..3f5af30 100644 --- a/libopie2/opiepim/core/otodoaccess.h +++ b/libopie2/opiepim/core/otodoaccess.h | |||
@@ -1,136 +1,142 @@ | |||
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) The Main Author <main-author@whereever.org> |
4 | =. Copyright (C) The Opie Team <opie-devel@handhelds.org> | 4 | =. Copyright (C) The Opie Team <opie-devel@handhelds.org> |
5 | .=l. | 5 | .=l. |
6 | .>+-= | 6 | .>+-= |
7 | _;:, .> :=|. This program is free software; you can | 7 | _;:, .> :=|. This program is free software; you can |
8 | .> <`_, > . <= redistribute it and/or modify it under | 8 | .> <`_, > . <= redistribute it and/or modify it under |
9 | :`=1 )Y*s>-.-- : the terms of the GNU Library General Public | 9 | :`=1 )Y*s>-.-- : the terms of the GNU Library General Public |
10 | .="- .-=="i, .._ License as published by the Free Software | 10 | .="- .-=="i, .._ License as published by the Free Software |
11 | - . .-<_> .<> Foundation; either version 2 of the License, | 11 | - . .-<_> .<> Foundation; either version 2 of the License, |
12 | ._= =} : or (at your option) any later version. | 12 | ._= =} : or (at your option) any later version. |
13 | .%`+i> _;_. | 13 | .%`+i> _;_. |
14 | .i_,=:_. -<s. This program is distributed in the hope that | 14 | .i_,=:_. -<s. This program is distributed in the hope that |
15 | + . -:. = it will be useful, but WITHOUT ANY WARRANTY; | 15 | + . -:. = it will be useful, but WITHOUT ANY WARRANTY; |
16 | : .. .:, . . . without even the implied warranty of | 16 | : .. .:, . . . without even the implied warranty of |
17 | =_ + =;=|` MERCHANTABILITY or FITNESS FOR A | 17 | =_ + =;=|` MERCHANTABILITY or FITNESS FOR A |
18 | _.=:. : :=>`: PARTICULAR PURPOSE. See the GNU | 18 | _.=:. : :=>`: PARTICULAR PURPOSE. See the GNU |
19 | ..}^=.= = ; Library General Public License for more | 19 | ..}^=.= = ; Library General Public License for more |
20 | ++= -. .` .: details. | 20 | ++= -. .` .: details. |
21 | : = ...= . :.=- | 21 | : = ...= . :.=- |
22 | -. .:....=;==+<; You should have received a copy of the GNU | 22 | -. .:....=;==+<; You should have received a copy of the GNU |
23 | -_. . . )=. = Library General Public License along with | 23 | -_. . . )=. = Library General Public License along with |
24 | -- :-=` this library; see the file COPYING.LIB. | 24 | -- :-=` this library; see the file COPYING.LIB. |
25 | If not, write to the Free Software Foundation, | 25 | If not, write to the Free Software Foundation, |
26 | Inc., 59 Temple Place - Suite 330, | 26 | Inc., 59 Temple Place - Suite 330, |
27 | Boston, MA 02111-1307, USA. | 27 | Boston, MA 02111-1307, USA. |
28 | */ | 28 | */ |
29 | #ifndef OPIE_TODO_ACCESS_H | 29 | #ifndef OPIE_TODO_ACCESS_H |
30 | #define OPIE_TODO_ACCESS_H | 30 | #define OPIE_TODO_ACCESS_H |
31 | 31 | ||
32 | #include <qobject.h> | 32 | #include <qobject.h> |
33 | #include <qvaluelist.h> | 33 | #include <qvaluelist.h> |
34 | 34 | ||
35 | #include <opie2/opimtodo.h> | 35 | #include <opie2/opimtodo.h> |
36 | #include <opie2/otodoaccessbackend.h> | 36 | #include <opie2/otodoaccessbackend.h> |
37 | #include <opie2/opimaccesstemplate.h> | 37 | #include <opie2/opimaccesstemplate.h> |
38 | 38 | ||
39 | namespace Opie { | 39 | namespace Opie { |
40 | 40 | ||
41 | /** | 41 | /** |
42 | * OPimTodoAccess | 42 | * OPimTodoAccess |
43 | * the class to get access to | 43 | * the class to get access to |
44 | * the todolist | 44 | * the todolist |
45 | */ | 45 | */ |
46 | class OPimTodoAccess : public QObject, public OPimAccessTemplate<OPimTodo> { | 46 | class OPimTodoAccess : public QObject, public OPimAccessTemplate<OPimTodo> { |
47 | Q_OBJECT | 47 | Q_OBJECT |
48 | public: | 48 | public: |
49 | enum SortOrder { Completed = 0, | 49 | enum SortOrder { Completed = 0, |
50 | Priority, | 50 | Priority, |
51 | Description, | 51 | Description, |
52 | Deadline }; | 52 | Deadline }; |
53 | enum SortFilter{ Category =1, | 53 | enum SortFilter{ Category =1, |
54 | OnlyOverDue= 2, | 54 | OnlyOverDue= 2, |
55 | DoNotShowCompleted =4 }; | 55 | DoNotShowCompleted =4 }; |
56 | /** | 56 | /** |
57 | * if you use 0l | 57 | * if you use 0l |
58 | * the default resource will be | 58 | * the default resource will be |
59 | * picked up | 59 | * picked up |
60 | */ | 60 | */ |
61 | OPimTodoAccess( OPimTodoAccessBackend* = 0l, enum Access acc = Random ); | 61 | OPimTodoAccess( OPimTodoAccessBackend* = 0l, enum Access acc = Random ); |
62 | ~OPimTodoAccess(); | 62 | ~OPimTodoAccess(); |
63 | 63 | ||
64 | 64 | ||
65 | /* our functions here */ | 65 | /* our functions here */ |
66 | /** | 66 | /** |
67 | * include todos from start to end | 67 | * include todos from start to end |
68 | * includeNoDates whether or not to include | 68 | * includeNoDates whether or not to include |
69 | * events with no dates | 69 | * events with no dates |
70 | */ | 70 | */ |
71 | List effectiveToDos( const QDate& start, | 71 | List effectiveToDos( const QDate& start, |
72 | const QDate& end, | 72 | const QDate& end, |
73 | bool includeNoDates = true ); | 73 | bool includeNoDates = true ); |
74 | 74 | ||
75 | /** | 75 | /** |
76 | * start | 76 | * start |
77 | * end date taken from the currentDate() | 77 | * end date taken from the currentDate() |
78 | */ | 78 | */ |
79 | List effectiveToDos( const QDate& start, | 79 | List effectiveToDos( const QDate& start, |
80 | bool includeNoDates = true ); | 80 | bool includeNoDates = true ); |
81 | 81 | ||
82 | 82 | ||
83 | /** | 83 | /** |
84 | * return overdue OPimTodos | 84 | * return overdue OPimTodos |
85 | */ | 85 | */ |
86 | List overDue(); | 86 | List overDue(); |
87 | 87 | ||
88 | /** | 88 | /** |
89 | * | 89 | * |
90 | */ | 90 | */ |
91 | List sorted( bool ascending, int sortOrder, int sortFilter, int cat ); | 91 | List sorted( bool ascending, int sortOrder, int sortFilter, int cat ); |
92 | 92 | ||
93 | /** | 93 | /** |
94 | * merge a list of OPimTodos into | 94 | * merge a list of OPimTodos into |
95 | * the resource | 95 | * the resource |
96 | */ | 96 | */ |
97 | void mergeWith( const QValueList<OPimTodo>& ); | 97 | void mergeWith( const QValueList<OPimTodo>& ); |
98 | 98 | ||
99 | /** | 99 | /** |
100 | * delete all already completed items | 100 | * delete all already completed items |
101 | */ | 101 | */ |
102 | void removeAllCompleted(); | 102 | void removeAllCompleted(); |
103 | 103 | ||
104 | /** | 104 | /** |
105 | * request information about what a backend supports. | 105 | * request information about what a backend supports. |
106 | * Supports in the sense of beeing able to store. | 106 | * Supports in the sense of beeing able to store. |
107 | * This is related to the enum in OPimTodo | 107 | * This is related to the enum in OPimTodo |
108 | * | 108 | * |
109 | * @param backend Will be used in the future when we support multiple backend | 109 | * @param backend Will be used in the future when we support multiple backend |
110 | */ | 110 | */ |
111 | QBitArray backendSupport( const QString& backend = QString::null )const; | 111 | QBitArray backendSupport( const QString& backend = QString::null )const; |
112 | 112 | ||
113 | /** | 113 | /** |
114 | * see above but for a specefic attribute. This method was added for convience | 114 | * see above but for a specefic attribute. This method was added for convience |
115 | * @param attr The attribute to be queried for | 115 | * @param attr The attribute to be queried for |
116 | * @param backend Will be used in the future when we support multiple backends | 116 | * @param backend Will be used in the future when we support multiple backends |
117 | */ | 117 | */ |
118 | bool backendSupports( int attr, const QString& backend = QString::null )const; | 118 | bool backendSupports( int attr, const QString& backend = QString::null )const; |
119 | |||
120 | |||
121 | /** | ||
122 | * Return identification of used records | ||
123 | */ | ||
124 | int rtti() const; | ||
119 | signals: | 125 | signals: |
120 | /** | 126 | /** |
121 | * if the OPimTodoAccess was changed | 127 | * if the OPimTodoAccess was changed |
122 | */ | 128 | */ |
123 | void changed( const OPimTodoAccess* ); | 129 | void changed( const OPimTodoAccess* ); |
124 | void changed( const OPimTodoAccess*, int uid ); | 130 | void changed( const OPimTodoAccess*, int uid ); |
125 | void added( const OPimTodoAccess*, int uid ); | 131 | void added( const OPimTodoAccess*, int uid ); |
126 | void removed( const OPimTodoAccess*, int uid ); | 132 | void removed( const OPimTodoAccess*, int uid ); |
127 | private: | 133 | private: |
128 | int m_cat; | 134 | int m_cat; |
129 | OPimTodoAccessBackend* m_todoBackEnd; | 135 | OPimTodoAccessBackend* m_todoBackEnd; |
130 | class OPimTodoAccessPrivate; | 136 | class OPimTodoAccessPrivate; |
131 | OPimTodoAccessPrivate* d; | 137 | OPimTodoAccessPrivate* d; |
132 | }; | 138 | }; |
133 | 139 | ||
134 | } | 140 | } |
135 | 141 | ||
136 | #endif | 142 | #endif |