summaryrefslogtreecommitdiff
path: root/libopie
Unidiff
Diffstat (limited to 'libopie') (more/less context) (ignore whitespace changes)
-rw-r--r--libopie/pim/ocontactfields.cpp233
-rw-r--r--libopie/pim/ocontactfields.h7
-rw-r--r--libopie/pim/opimnotifymanager.cpp72
-rw-r--r--libopie/pim/opimnotifymanager.h24
-rw-r--r--libopie/pim/otodoaccesssql.cpp52
-rw-r--r--libopie/pim/otodoaccesssql.h2
-rw-r--r--libopie/pim/otodoaccessxml.cpp2
7 files changed, 260 insertions, 132 deletions
diff --git a/libopie/pim/ocontactfields.cpp b/libopie/pim/ocontactfields.cpp
index 7206f0d..0f08a5a 100644
--- a/libopie/pim/ocontactfields.cpp
+++ b/libopie/pim/ocontactfields.cpp
@@ -1,466 +1,477 @@
1 1
2#include "ocontactfields.h" 2#include "ocontactfields.h"
3 3
4#include <qstringlist.h> 4#include <qstringlist.h>
5#include <qobject.h> 5#include <qobject.h>
6 6
7// We should use our own enum in the future .. 7// We should use our own enum in the future ..
8#include <qpe/recordfields.h> 8#include <qpe/recordfields.h>
9#include <qpe/config.h> 9#include <qpe/config.h>
10#include <opie/ocontact.h> 10#include <opie/ocontact.h>
11 11
12/*! 12/*!
13 \internal 13 \internal
14 Returns a list of details field names for a contact. 14 Returns a list of personal field names for a contact.
15*/ 15*/
16QStringList OContactFields::untrdetailsfields( bool sorted ) 16QStringList OContactFields::personalfields( bool sorted, bool translated )
17{ 17{
18 QStringList list; 18 QStringList list;
19 QMap<int, QString> mapIdToStr = idToUntrFields(); 19 QMap<int, QString> mapIdToStr;
20 if ( translated )
21 mapIdToStr = idToTrFields();
22 else
23 mapIdToStr = idToUntrFields();
20 24
21 list.append( mapIdToStr[ Qtopia::Office ] ); 25 list.append( mapIdToStr[ Qtopia::AddressUid ] );
22 list.append( mapIdToStr[ Qtopia::Profession ] ); 26 list.append( mapIdToStr[ Qtopia::AddressCategory ] );
23 list.append( mapIdToStr[ Qtopia::Assistant ] );
24 list.append( mapIdToStr[ Qtopia::Manager ] );
25 27
26 list.append( mapIdToStr[ Qtopia::Spouse ] ); 28 list.append( mapIdToStr[ Qtopia::Title ] );
27 list.append( mapIdToStr[ Qtopia::Gender ] ); 29 list.append( mapIdToStr[ Qtopia::FirstName ] );
28 list.append( mapIdToStr[ Qtopia::Birthday ] ); 30 list.append( mapIdToStr[ Qtopia::MiddleName ] );
29 list.append( mapIdToStr[ Qtopia::Anniversary ] ); 31 list.append( mapIdToStr[ Qtopia::LastName ] );
30 list.append( mapIdToStr[ Qtopia::Nickname ] ); 32 list.append( mapIdToStr[ Qtopia::Suffix ] );
31 list.append( mapIdToStr[ Qtopia::Children ] ); 33 list.append( mapIdToStr[ Qtopia::FileAs ] );
34
35 list.append( mapIdToStr[ Qtopia::JobTitle ] );
36 list.append( mapIdToStr[ Qtopia::Department ] );
37 list.append( mapIdToStr[ Qtopia::Company ] );
38
39 list.append( mapIdToStr[ Qtopia::Notes ] );
40 list.append( mapIdToStr[ Qtopia::Groups ] );
32 41
33 if (sorted) list.sort(); 42 if (sorted) list.sort();
34 return list; 43 return list;
35} 44}
36 45
37/*! 46/*!
38 \internal 47 \internal
39 Returns a translated list of details field names for a contact. 48 Returns a list of details field names for a contact.
40*/ 49*/
41QStringList OContactFields::trdetailsfields( bool sorted ) 50QStringList OContactFields::detailsfields( bool sorted, bool translated )
42{ 51{
43 QStringList list; 52 QStringList list;
44 QMap<int, QString> mapIdToStr = idToTrFields(); 53 QMap<int, QString> mapIdToStr;
54 if ( translated )
55 mapIdToStr = idToTrFields();
56 else
57 mapIdToStr = idToUntrFields();
45 58
46 list.append( mapIdToStr[Qtopia::Office] ); 59 list.append( mapIdToStr[ Qtopia::Office ] );
47 list.append( mapIdToStr[Qtopia::Profession] ); 60 list.append( mapIdToStr[ Qtopia::Profession ] );
48 list.append( mapIdToStr[Qtopia::Assistant] ); 61 list.append( mapIdToStr[ Qtopia::Assistant ] );
49 list.append( mapIdToStr[Qtopia::Manager] ); 62 list.append( mapIdToStr[ Qtopia::Manager ] );
50 63
51 list.append( mapIdToStr[Qtopia::Spouse] ); 64 list.append( mapIdToStr[ Qtopia::Spouse ] );
52 list.append( mapIdToStr[Qtopia::Gender] ); 65 list.append( mapIdToStr[ Qtopia::Gender ] );
53 list.append( mapIdToStr[Qtopia::Birthday] ); 66 list.append( mapIdToStr[ Qtopia::Birthday ] );
54 list.append( mapIdToStr[Qtopia::Anniversary] ); 67 list.append( mapIdToStr[ Qtopia::Anniversary ] );
55 list.append( mapIdToStr[Qtopia::Nickname] ); 68 list.append( mapIdToStr[ Qtopia::Nickname ] );
56 list.append( mapIdToStr[Qtopia::Children] ); 69 list.append( mapIdToStr[ Qtopia::Children ] );
57 70
58 if (sorted) list.sort(); 71 if (sorted) list.sort();
59 return list; 72 return list;
60} 73}
61 74
62
63/*! 75/*!
64 \internal 76 \internal
65 Returns a translated list of phone field names for a contact. 77 Returns a list of phone field names for a contact.
66*/ 78*/
67QStringList OContactFields::trphonefields( bool sorted ) 79QStringList OContactFields::phonefields( bool sorted, bool translated )
68{ 80{
69 QStringList list; 81 QStringList list;
70 QMap<int, QString> mapIdToStr = idToTrFields(); 82 QMap<int, QString> mapIdToStr;
83 if ( translated )
84 mapIdToStr = idToTrFields();
85 else
86 mapIdToStr = idToUntrFields();
71 87
72 list.append( mapIdToStr[Qtopia::BusinessPhone] ); 88 list.append( mapIdToStr[Qtopia::BusinessPhone] );
73 list.append( mapIdToStr[Qtopia::BusinessFax] ); 89 list.append( mapIdToStr[Qtopia::BusinessFax] );
74 list.append( mapIdToStr[Qtopia::BusinessMobile] ); 90 list.append( mapIdToStr[Qtopia::BusinessMobile] );
75 list.append( mapIdToStr[Qtopia::BusinessPager] ); 91 list.append( mapIdToStr[Qtopia::BusinessPager] );
76 list.append( mapIdToStr[Qtopia::BusinessWebPage] ); 92 list.append( mapIdToStr[Qtopia::BusinessWebPage] );
77 93
78 list.append( mapIdToStr[Qtopia::DefaultEmail] ); 94 list.append( mapIdToStr[Qtopia::DefaultEmail] );
79 list.append( mapIdToStr[Qtopia::Emails] ); 95 list.append( mapIdToStr[Qtopia::Emails] );
80 96
81 list.append( mapIdToStr[Qtopia::HomePhone] ); 97 list.append( mapIdToStr[Qtopia::HomePhone] );
82 list.append( mapIdToStr[Qtopia::HomeFax] ); 98 list.append( mapIdToStr[Qtopia::HomeFax] );
83 list.append( mapIdToStr[Qtopia::HomeMobile] ); 99 list.append( mapIdToStr[Qtopia::HomeMobile] );
84 // list.append( mapIdToStr[Qtopia::HomePager] ); 100 // list.append( mapIdToStr[Qtopia::HomePager] );
85 list.append( mapIdToStr[Qtopia::HomeWebPage] ); 101 list.append( mapIdToStr[Qtopia::HomeWebPage] );
86 102
87 if (sorted) list.sort(); 103 if (sorted) list.sort();
88 104
89 return list; 105 return list;
90} 106}
91 107
92
93/*! 108/*!
94 \internal 109 \internal
95 Returns a list of phone field names for a contact. 110 Returns a list of field names for a contact.
96*/ 111*/
97QStringList OContactFields::untrphonefields( bool sorted ) 112QStringList OContactFields::fields( bool sorted, bool translated )
98{ 113{
99 QStringList list; 114 QStringList list;
100 QMap<int, QString> mapIdToStr = idToUntrFields(); 115 QMap<int, QString> mapIdToStr;
101 116 if ( translated )
102 list.append( mapIdToStr[ Qtopia::BusinessPhone ] ); 117 mapIdToStr = idToTrFields();
103 list.append( mapIdToStr[ Qtopia::BusinessFax ] ); 118 else
104 list.append( mapIdToStr[ Qtopia::BusinessMobile ] ); 119 mapIdToStr = idToUntrFields();
105 list.append( mapIdToStr[ Qtopia::BusinessPager ] );
106 list.append( mapIdToStr[ Qtopia::BusinessWebPage ] );
107
108 list.append( mapIdToStr[ Qtopia::DefaultEmail ] );
109 list.append( mapIdToStr[ Qtopia::Emails ] );
110 120
111 list.append( mapIdToStr[ Qtopia::HomePhone ] ); 121 list += personalfields( sorted, translated );
112 list.append( mapIdToStr[ Qtopia::HomeFax ] );
113 list.append( mapIdToStr[ Qtopia::HomeMobile ] );
114 //list.append( mapIdToStr[Qtopia::HomePager] );
115 list.append( mapIdToStr[Qtopia::HomeWebPage] );
116 122
117 if (sorted) list.sort(); 123 list += phonefields( sorted, translated );
118
119 return list;
120}
121
122
123/*!
124 \internal
125 Returns a translated list of field names for a contact.
126*/
127QStringList OContactFields::trfields( bool sorted )
128{
129 QStringList list;
130 QMap<int, QString> mapIdToStr = idToTrFields();
131
132 list.append( mapIdToStr[Qtopia::Title]);
133 list.append( mapIdToStr[Qtopia::FirstName] );
134 list.append( mapIdToStr[Qtopia::MiddleName] );
135 list.append( mapIdToStr[Qtopia::LastName] );
136 list.append( mapIdToStr[Qtopia::Suffix] );
137 list.append( mapIdToStr[Qtopia::FileAs] );
138
139 list.append( mapIdToStr[Qtopia::JobTitle] );
140 list.append( mapIdToStr[Qtopia::Department] );
141 list.append( mapIdToStr[Qtopia::Company] );
142
143 list += trphonefields( sorted );
144 124
145 list.append( mapIdToStr[Qtopia::BusinessStreet] ); 125 list.append( mapIdToStr[Qtopia::BusinessStreet] );
146 list.append( mapIdToStr[Qtopia::BusinessCity] ); 126 list.append( mapIdToStr[Qtopia::BusinessCity] );
147 list.append( mapIdToStr[Qtopia::BusinessState] ); 127 list.append( mapIdToStr[Qtopia::BusinessState] );
148 list.append( mapIdToStr[Qtopia::BusinessZip] ); 128 list.append( mapIdToStr[Qtopia::BusinessZip] );
149 list.append( mapIdToStr[Qtopia::BusinessCountry] ); 129 list.append( mapIdToStr[Qtopia::BusinessCountry] );
150 130
151 list.append( mapIdToStr[Qtopia::HomeStreet] ); 131 list.append( mapIdToStr[Qtopia::HomeStreet] );
152 list.append( mapIdToStr[Qtopia::HomeCity] ); 132 list.append( mapIdToStr[Qtopia::HomeCity] );
153 list.append( mapIdToStr[Qtopia::HomeState] ); 133 list.append( mapIdToStr[Qtopia::HomeState] );
154 list.append( mapIdToStr[Qtopia::HomeZip] ); 134 list.append( mapIdToStr[Qtopia::HomeZip] );
155 list.append( mapIdToStr[Qtopia::HomeCountry] ); 135 list.append( mapIdToStr[Qtopia::HomeCountry] );
156 136
157 list += trdetailsfields( sorted ); 137 list += detailsfields( sorted, translated );
158
159 list.append( mapIdToStr[Qtopia::Notes] );
160 list.append( mapIdToStr[Qtopia::Groups] );
161 138
162 if (sorted) list.sort(); 139 if (sorted) list.sort();
163 140
164 return list; 141 return list;
165} 142}
166 143
144
167/*! 145/*!
168 \internal 146 \internal
169 Returns an untranslated list of field names for a contact. 147 Returns an untranslated list of personal field names for a contact.
170*/ 148*/
171QStringList OContactFields::untrfields( bool sorted ) 149QStringList OContactFields::untrpersonalfields( bool sorted )
172{ 150{
173 QStringList list; 151 return personalfields( sorted, false );
174 QMap<int, QString> mapIdToStr = idToUntrFields(); 152}
175 153
176 list.append( mapIdToStr[ Qtopia::AddressUid ] );
177 list.append( mapIdToStr[ Qtopia::AddressCategory ] );
178 154
179 list.append( mapIdToStr[ Qtopia::Title ] ); 155/*!
180 list.append( mapIdToStr[ Qtopia::FirstName ] ); 156 \internal
181 list.append( mapIdToStr[ Qtopia::MiddleName ] ); 157 Returns a translated list of personal field names for a contact.
182 list.append( mapIdToStr[ Qtopia::LastName ] ); 158*/
183 list.append( mapIdToStr[ Qtopia::Suffix ] ); 159QStringList OContactFields::trpersonalfields( bool sorted )
184 list.append( mapIdToStr[ Qtopia::FileAs ] ); 160{
161 return personalfields( sorted, true );
162}
185 163
186 list.append( mapIdToStr[ Qtopia::JobTitle ] );
187 list.append( mapIdToStr[ Qtopia::Department ] );
188 list.append( mapIdToStr[ Qtopia::Company ] );
189 164
190 list += untrphonefields( sorted ); 165/*!
166 \internal
167 Returns an untranslated list of details field names for a contact.
168*/
169QStringList OContactFields::untrdetailsfields( bool sorted )
170{
171 return detailsfields( sorted, false );
172}
191 173
192 list.append( mapIdToStr[ Qtopia::BusinessStreet ] );
193 list.append( mapIdToStr[ Qtopia::BusinessCity ] );
194 list.append( mapIdToStr[ Qtopia::BusinessState ] );
195 list.append( mapIdToStr[ Qtopia::BusinessZip ] );
196 list.append( mapIdToStr[ Qtopia::BusinessCountry ] );
197 174
198 list.append( mapIdToStr[ Qtopia::HomeStreet ] ); 175/*!
199 list.append( mapIdToStr[ Qtopia::HomeCity ] ); 176 \internal
200 list.append( mapIdToStr[ Qtopia::HomeState ] ); 177 Returns a translated list of details field names for a contact.
201 list.append( mapIdToStr[ Qtopia::HomeZip ] ); 178*/
202 list.append( mapIdToStr[ Qtopia::HomeCountry ] ); 179QStringList OContactFields::trdetailsfields( bool sorted )
180{
181 return detailsfields( sorted, true );
182}
203 183
204 list += untrdetailsfields( sorted );
205 184
206 list.append( mapIdToStr[ Qtopia::Notes ] ); 185/*!
207 list.append( mapIdToStr[ Qtopia::Groups ] ); 186 \internal
187 Returns a translated list of phone field names for a contact.
188*/
189QStringList OContactFields::trphonefields( bool sorted )
190{
191 return phonefields( sorted, true );
192}
208 193
209 if (sorted) list.sort(); 194/*!
195 \internal
196 Returns an untranslated list of phone field names for a contact.
197*/
198QStringList OContactFields::untrphonefields( bool sorted )
199{
200 return phonefields( sorted, false );
201}
210 202
211 return list; 203
204/*!
205 \internal
206 Returns a translated list of field names for a contact.
207*/
208QStringList OContactFields::trfields( bool sorted )
209{
210 return fields( sorted, true );
211}
212
213/*!
214 \internal
215 Returns an untranslated list of field names for a contact.
216*/
217QStringList OContactFields::untrfields( bool sorted )
218{
219 return fields( sorted, false );
212} 220}
221
213QMap<int, QString> OContactFields::idToTrFields() 222QMap<int, QString> OContactFields::idToTrFields()
214{ 223{
215 QMap<int, QString> ret_map; 224 QMap<int, QString> ret_map;
216 225
217 ret_map.insert( Qtopia::AddressUid, QObject::tr( "User Id" ) ); 226 ret_map.insert( Qtopia::AddressUid, QObject::tr( "User Id" ) );
218 ret_map.insert( Qtopia::AddressCategory, QObject::tr( "Categories" ) ); 227 ret_map.insert( Qtopia::AddressCategory, QObject::tr( "Categories" ) );
219 228
220 ret_map.insert( Qtopia::Title, QObject::tr( "Name Title") ); 229 ret_map.insert( Qtopia::Title, QObject::tr( "Name Title") );
221 ret_map.insert( Qtopia::FirstName, QObject::tr( "First Name" ) ); 230 ret_map.insert( Qtopia::FirstName, QObject::tr( "First Name" ) );
222 ret_map.insert( Qtopia::MiddleName, QObject::tr( "Middle Name" ) ); 231 ret_map.insert( Qtopia::MiddleName, QObject::tr( "Middle Name" ) );
223 ret_map.insert( Qtopia::LastName, QObject::tr( "Last Name" ) ); 232 ret_map.insert( Qtopia::LastName, QObject::tr( "Last Name" ) );
224 ret_map.insert( Qtopia::Suffix, QObject::tr( "Suffix" )); 233 ret_map.insert( Qtopia::Suffix, QObject::tr( "Suffix" ));
225 ret_map.insert( Qtopia::FileAs, QObject::tr( "File As" ) ); 234 ret_map.insert( Qtopia::FileAs, QObject::tr( "File As" ) );
226 235
227 ret_map.insert( Qtopia::JobTitle, QObject::tr( "Job Title" ) ); 236 ret_map.insert( Qtopia::JobTitle, QObject::tr( "Job Title" ) );
228 ret_map.insert( Qtopia::Department, QObject::tr( "Department" ) ); 237 ret_map.insert( Qtopia::Department, QObject::tr( "Department" ) );
229 ret_map.insert( Qtopia::Company, QObject::tr( "Company" ) ); 238 ret_map.insert( Qtopia::Company, QObject::tr( "Company" ) );
230 ret_map.insert( Qtopia::BusinessPhone, QObject::tr( "Business Phone" ) ); 239 ret_map.insert( Qtopia::BusinessPhone, QObject::tr( "Business Phone" ) );
231 ret_map.insert( Qtopia::BusinessFax, QObject::tr( "Business Fax" ) ); 240 ret_map.insert( Qtopia::BusinessFax, QObject::tr( "Business Fax" ) );
232 ret_map.insert( Qtopia::BusinessMobile, QObject::tr( "Business Mobile" )); 241 ret_map.insert( Qtopia::BusinessMobile, QObject::tr( "Business Mobile" ));
233 242
234 // email 243 // email
235 ret_map.insert( Qtopia::DefaultEmail, QObject::tr( "Default Email" ) ); 244 ret_map.insert( Qtopia::DefaultEmail, QObject::tr( "Default Email" ) );
236 ret_map.insert( Qtopia::Emails, QObject::tr( "Emails" ) ); 245 ret_map.insert( Qtopia::Emails, QObject::tr( "Emails" ) );
237 246
238 ret_map.insert( Qtopia::HomePhone, QObject::tr( "Home Phone" ) ); 247 ret_map.insert( Qtopia::HomePhone, QObject::tr( "Home Phone" ) );
239 ret_map.insert( Qtopia::HomeFax, QObject::tr( "Home Fax" ) ); 248 ret_map.insert( Qtopia::HomeFax, QObject::tr( "Home Fax" ) );
240 ret_map.insert( Qtopia::HomeMobile, QObject::tr( "Home Mobile" ) ); 249 ret_map.insert( Qtopia::HomeMobile, QObject::tr( "Home Mobile" ) );
241 250
242 // business 251 // business
243 ret_map.insert( Qtopia::BusinessStreet, QObject::tr( "Business Street" ) ); 252 ret_map.insert( Qtopia::BusinessStreet, QObject::tr( "Business Street" ) );
244 ret_map.insert( Qtopia::BusinessCity, QObject::tr( "Business City" ) ); 253 ret_map.insert( Qtopia::BusinessCity, QObject::tr( "Business City" ) );
245 ret_map.insert( Qtopia::BusinessState, QObject::tr( "Business State" ) ); 254 ret_map.insert( Qtopia::BusinessState, QObject::tr( "Business State" ) );
246 ret_map.insert( Qtopia::BusinessZip, QObject::tr( "Business Zip" ) ); 255 ret_map.insert( Qtopia::BusinessZip, QObject::tr( "Business Zip" ) );
247 ret_map.insert( Qtopia::BusinessCountry, QObject::tr( "Business Country" ) ); 256 ret_map.insert( Qtopia::BusinessCountry, QObject::tr( "Business Country" ) );
248 ret_map.insert( Qtopia::BusinessPager, QObject::tr( "Business Pager" ) ); 257 ret_map.insert( Qtopia::BusinessPager, QObject::tr( "Business Pager" ) );
249 ret_map.insert( Qtopia::BusinessWebPage, QObject::tr( "Business WebPage" ) ); 258 ret_map.insert( Qtopia::BusinessWebPage, QObject::tr( "Business WebPage" ) );
250 259
251 ret_map.insert( Qtopia::Office, QObject::tr( "Office" ) ); 260 ret_map.insert( Qtopia::Office, QObject::tr( "Office" ) );
252 ret_map.insert( Qtopia::Profession, QObject::tr( "Profession" ) ); 261 ret_map.insert( Qtopia::Profession, QObject::tr( "Profession" ) );
253 ret_map.insert( Qtopia::Assistant, QObject::tr( "Assistant" ) ); 262 ret_map.insert( Qtopia::Assistant, QObject::tr( "Assistant" ) );
254 ret_map.insert( Qtopia::Manager, QObject::tr( "Manager" ) ); 263 ret_map.insert( Qtopia::Manager, QObject::tr( "Manager" ) );
255 264
256 // home 265 // home
257 ret_map.insert( Qtopia::HomeStreet, QObject::tr( "Home Street" ) ); 266 ret_map.insert( Qtopia::HomeStreet, QObject::tr( "Home Street" ) );
258 ret_map.insert( Qtopia::HomeCity, QObject::tr( "Home City" ) ); 267 ret_map.insert( Qtopia::HomeCity, QObject::tr( "Home City" ) );
259 ret_map.insert( Qtopia::HomeState, QObject::tr( "Home State" ) ); 268 ret_map.insert( Qtopia::HomeState, QObject::tr( "Home State" ) );
260 ret_map.insert( Qtopia::HomeZip, QObject::tr( "Home Zip" ) ); 269 ret_map.insert( Qtopia::HomeZip, QObject::tr( "Home Zip" ) );
261 ret_map.insert( Qtopia::HomeCountry, QObject::tr( "Home Country" ) ); 270 ret_map.insert( Qtopia::HomeCountry, QObject::tr( "Home Country" ) );
262 ret_map.insert( Qtopia::HomeWebPage, QObject::tr( "Home Web Page" ) ); 271 ret_map.insert( Qtopia::HomeWebPage, QObject::tr( "Home Web Page" ) );
263 272
264 //personal 273 //personal
265 ret_map.insert( Qtopia::Spouse, QObject::tr( "Spouse" ) ); 274 ret_map.insert( Qtopia::Spouse, QObject::tr( "Spouse" ) );
266 ret_map.insert( Qtopia::Gender, QObject::tr( "Gender" ) ); 275 ret_map.insert( Qtopia::Gender, QObject::tr( "Gender" ) );
267 ret_map.insert( Qtopia::Birthday, QObject::tr( "Birthday" ) ); 276 ret_map.insert( Qtopia::Birthday, QObject::tr( "Birthday" ) );
268 ret_map.insert( Qtopia::Anniversary, QObject::tr( "Anniversary" ) ); 277 ret_map.insert( Qtopia::Anniversary, QObject::tr( "Anniversary" ) );
269 ret_map.insert( Qtopia::Nickname, QObject::tr( "Nickname" ) ); 278 ret_map.insert( Qtopia::Nickname, QObject::tr( "Nickname" ) );
270 ret_map.insert( Qtopia::Children, QObject::tr( "Children" ) ); 279 ret_map.insert( Qtopia::Children, QObject::tr( "Children" ) );
271 280
272 // other 281 // other
273 ret_map.insert( Qtopia::Notes, QObject::tr( "Notes" ) ); 282 ret_map.insert( Qtopia::Notes, QObject::tr( "Notes" ) );
274 283
275 284
276 return ret_map; 285 return ret_map;
277} 286}
278 287
279QMap<int, QString> OContactFields::idToUntrFields() 288QMap<int, QString> OContactFields::idToUntrFields()
280{ 289{
281 QMap<int, QString> ret_map; 290 QMap<int, QString> ret_map;
282 291
283 ret_map.insert( Qtopia::AddressUid, "User Id" ); 292 ret_map.insert( Qtopia::AddressUid, "User Id" );
284 ret_map.insert( Qtopia::AddressCategory, "Categories" ); 293 ret_map.insert( Qtopia::AddressCategory, "Categories" );
285 294
286 ret_map.insert( Qtopia::Title, "Name Title" ); 295 ret_map.insert( Qtopia::Title, "Name Title" );
287 ret_map.insert( Qtopia::FirstName, "First Name" ); 296 ret_map.insert( Qtopia::FirstName, "First Name" );
288 ret_map.insert( Qtopia::MiddleName, "Middle Name" ); 297 ret_map.insert( Qtopia::MiddleName, "Middle Name" );
289 ret_map.insert( Qtopia::LastName, "Last Name" ); 298 ret_map.insert( Qtopia::LastName, "Last Name" );
290 ret_map.insert( Qtopia::Suffix, "Suffix" ); 299 ret_map.insert( Qtopia::Suffix, "Suffix" );
291 ret_map.insert( Qtopia::FileAs, "File As" ); 300 ret_map.insert( Qtopia::FileAs, "File As" );
292 301
293 ret_map.insert( Qtopia::JobTitle, "Job Title" ); 302 ret_map.insert( Qtopia::JobTitle, "Job Title" );
294 ret_map.insert( Qtopia::Department, "Department" ); 303 ret_map.insert( Qtopia::Department, "Department" );
295 ret_map.insert( Qtopia::Company, "Company" ); 304 ret_map.insert( Qtopia::Company, "Company" );
296 ret_map.insert( Qtopia::BusinessPhone, "Business Phone" ); 305 ret_map.insert( Qtopia::BusinessPhone, "Business Phone" );
297 ret_map.insert( Qtopia::BusinessFax, "Business Fax" ); 306 ret_map.insert( Qtopia::BusinessFax, "Business Fax" );
298 ret_map.insert( Qtopia::BusinessMobile, "Business Mobile" ); 307 ret_map.insert( Qtopia::BusinessMobile, "Business Mobile" );
299 308
300 // email 309 // email
301 ret_map.insert( Qtopia::DefaultEmail, "Default Email" ); 310 ret_map.insert( Qtopia::DefaultEmail, "Default Email" );
302 ret_map.insert( Qtopia::Emails, "Emails" ); 311 ret_map.insert( Qtopia::Emails, "Emails" );
303 312
304 ret_map.insert( Qtopia::HomePhone, "Home Phone" ); 313 ret_map.insert( Qtopia::HomePhone, "Home Phone" );
305 ret_map.insert( Qtopia::HomeFax, "Home Fax" ); 314 ret_map.insert( Qtopia::HomeFax, "Home Fax" );
306 ret_map.insert( Qtopia::HomeMobile, "Home Mobile" ); 315 ret_map.insert( Qtopia::HomeMobile, "Home Mobile" );
307 316
308 // business 317 // business
309 ret_map.insert( Qtopia::BusinessStreet, "Business Street" ); 318 ret_map.insert( Qtopia::BusinessStreet, "Business Street" );
310 ret_map.insert( Qtopia::BusinessCity, "Business City" ); 319 ret_map.insert( Qtopia::BusinessCity, "Business City" );
311 ret_map.insert( Qtopia::BusinessState, "Business State" ); 320 ret_map.insert( Qtopia::BusinessState, "Business State" );
312 ret_map.insert( Qtopia::BusinessZip, "Business Zip" ); 321 ret_map.insert( Qtopia::BusinessZip, "Business Zip" );
313 ret_map.insert( Qtopia::BusinessCountry, "Business Country" ); 322 ret_map.insert( Qtopia::BusinessCountry, "Business Country" );
314 ret_map.insert( Qtopia::BusinessPager, "Business Pager" ); 323 ret_map.insert( Qtopia::BusinessPager, "Business Pager" );
315 ret_map.insert( Qtopia::BusinessWebPage, "Business WebPage" ); 324 ret_map.insert( Qtopia::BusinessWebPage, "Business WebPage" );
316 325
317 ret_map.insert( Qtopia::Office, "Office" ); 326 ret_map.insert( Qtopia::Office, "Office" );
318 ret_map.insert( Qtopia::Profession, "Profession" ); 327 ret_map.insert( Qtopia::Profession, "Profession" );
319 ret_map.insert( Qtopia::Assistant, "Assistant" ); 328 ret_map.insert( Qtopia::Assistant, "Assistant" );
320 ret_map.insert( Qtopia::Manager, "Manager" ); 329 ret_map.insert( Qtopia::Manager, "Manager" );
321 330
322 // home 331 // home
323 ret_map.insert( Qtopia::HomeStreet, "Home Street" ); 332 ret_map.insert( Qtopia::HomeStreet, "Home Street" );
324 ret_map.insert( Qtopia::HomeCity, "Home City" ); 333 ret_map.insert( Qtopia::HomeCity, "Home City" );
325 ret_map.insert( Qtopia::HomeState, "Home State" ); 334 ret_map.insert( Qtopia::HomeState, "Home State" );
326 ret_map.insert( Qtopia::HomeZip, "Home Zip" ); 335 ret_map.insert( Qtopia::HomeZip, "Home Zip" );
327 ret_map.insert( Qtopia::HomeCountry, "Home Country" ); 336 ret_map.insert( Qtopia::HomeCountry, "Home Country" );
328 ret_map.insert( Qtopia::HomeWebPage, "Home Web Page" ); 337 ret_map.insert( Qtopia::HomeWebPage, "Home Web Page" );
329 338
330 //personal 339 //personal
331 ret_map.insert( Qtopia::Spouse, "Spouse" ); 340 ret_map.insert( Qtopia::Spouse, "Spouse" );
332 ret_map.insert( Qtopia::Gender, "Gender" ); 341 ret_map.insert( Qtopia::Gender, "Gender" );
333 ret_map.insert( Qtopia::Birthday, "Birthday" ); 342 ret_map.insert( Qtopia::Birthday, "Birthday" );
334 ret_map.insert( Qtopia::Anniversary, "Anniversary" ); 343 ret_map.insert( Qtopia::Anniversary, "Anniversary" );
335 ret_map.insert( Qtopia::Nickname, "Nickname" ); 344 ret_map.insert( Qtopia::Nickname, "Nickname" );
336 ret_map.insert( Qtopia::Children, "Children" ); 345 ret_map.insert( Qtopia::Children, "Children" );
337 346
338 // other 347 // other
339 ret_map.insert( Qtopia::Notes, "Notes" ); 348 ret_map.insert( Qtopia::Notes, "Notes" );
340 ret_map.insert( Qtopia::Groups, "Groups" ); 349 ret_map.insert( Qtopia::Groups, "Groups" );
341 350
342 351
343 return ret_map; 352 return ret_map;
344} 353}
345 354
346QMap<QString, int> OContactFields::trFieldsToId() 355QMap<QString, int> OContactFields::trFieldsToId()
347{ 356{
348 QMap<int, QString> idtostr = idToTrFields(); 357 QMap<int, QString> idtostr = idToTrFields();
349 QMap<QString, int> ret_map; 358 QMap<QString, int> ret_map;
350 359
351 360
352 QMap<int, QString>::Iterator it; 361 QMap<int, QString>::Iterator it;
353 for( it = idtostr.begin(); it != idtostr.end(); ++it ) 362 for( it = idtostr.begin(); it != idtostr.end(); ++it )
354 ret_map.insert( *it, it.key() ); 363 ret_map.insert( *it, it.key() );
355 364
356 365
357 return ret_map; 366 return ret_map;
358} 367}
359 368
369/* ======================================================================= */
370
360QMap<QString, int> OContactFields::untrFieldsToId() 371QMap<QString, int> OContactFields::untrFieldsToId()
361{ 372{
362 QMap<int, QString> idtostr = idToUntrFields(); 373 QMap<int, QString> idtostr = idToUntrFields();
363 QMap<QString, int> ret_map; 374 QMap<QString, int> ret_map;
364 375
365 376
366 QMap<int, QString>::Iterator it; 377 QMap<int, QString>::Iterator it;
367 for( it = idtostr.begin(); it != idtostr.end(); ++it ) 378 for( it = idtostr.begin(); it != idtostr.end(); ++it )
368 ret_map.insert( *it, it.key() ); 379 ret_map.insert( *it, it.key() );
369 380
370 381
371 return ret_map; 382 return ret_map;
372} 383}
373 384
374 385
375OContactFields::OContactFields(): 386OContactFields::OContactFields():
376 fieldOrder( DEFAULT_FIELD_ORDER ), 387 fieldOrder( DEFAULT_FIELD_ORDER ),
377 changedFieldOrder( false ) 388 changedFieldOrder( false )
378{ 389{
379 // Get the global field order from the config file and 390 // Get the global field order from the config file and
380 // use it as a start pattern 391 // use it as a start pattern
381 Config cfg ( "AddressBook" ); 392 Config cfg ( "AddressBook" );
382 cfg.setGroup( "ContactFieldOrder" ); 393 cfg.setGroup( "ContactFieldOrder" );
383 globalFieldOrder = cfg.readEntry( "General", DEFAULT_FIELD_ORDER ); 394 globalFieldOrder = cfg.readEntry( "General", DEFAULT_FIELD_ORDER );
384} 395}
385 396
386OContactFields::~OContactFields(){ 397OContactFields::~OContactFields(){
387 398
388 // We will store the fieldorder into the config file 399 // We will store the fieldorder into the config file
389 // to reuse it for the future.. 400 // to reuse it for the future..
390 if ( changedFieldOrder ){ 401 if ( changedFieldOrder ){
391 Config cfg ( "AddressBook" ); 402 Config cfg ( "AddressBook" );
392 cfg.setGroup( "ContactFieldOrder" ); 403 cfg.setGroup( "ContactFieldOrder" );
393 cfg.writeEntry( "General", globalFieldOrder ); 404 cfg.writeEntry( "General", globalFieldOrder );
394 } 405 }
395} 406}
396 407
397 408
398 409
399void OContactFields::saveToRecord( OContact &cnt ){ 410void OContactFields::saveToRecord( OContact &cnt ){
400 411
401 qDebug("ocontactfields saveToRecord: >%s<",fieldOrder.latin1()); 412 qDebug("ocontactfields saveToRecord: >%s<",fieldOrder.latin1());
402 413
403 // Store fieldorder into this contact. 414 // Store fieldorder into this contact.
404 cnt.setCustomField( CONTACT_FIELD_ORDER_NAME, fieldOrder ); 415 cnt.setCustomField( CONTACT_FIELD_ORDER_NAME, fieldOrder );
405 416
406 globalFieldOrder = fieldOrder; 417 globalFieldOrder = fieldOrder;
407 changedFieldOrder = true; 418 changedFieldOrder = true;
408 419
409} 420}
410 421
411void OContactFields::loadFromRecord( const OContact &cnt ){ 422void OContactFields::loadFromRecord( const OContact &cnt ){
412 qDebug("ocontactfields loadFromRecord"); 423 qDebug("ocontactfields loadFromRecord");
413 qDebug("loading >%s<",cnt.fullName().latin1()); 424 qDebug("loading >%s<",cnt.fullName().latin1());
414 425
415 // Get fieldorder for this contact. If none is defined, 426 // Get fieldorder for this contact. If none is defined,
416 // we will use the global one from the config file.. 427 // we will use the global one from the config file..
417 428
418 fieldOrder = cnt.customField( CONTACT_FIELD_ORDER_NAME ); 429 fieldOrder = cnt.customField( CONTACT_FIELD_ORDER_NAME );
419 430
420 qDebug("fieldOrder from contact>%s<",fieldOrder.latin1()); 431 qDebug("fieldOrder from contact>%s<",fieldOrder.latin1());
421 432
422 if (fieldOrder.isEmpty()){ 433 if (fieldOrder.isEmpty()){
423 fieldOrder = globalFieldOrder; 434 fieldOrder = globalFieldOrder;
424 } 435 }
425 436
426 437
427 qDebug("effective fieldOrder in loadFromRecord >%s<",fieldOrder.latin1()); 438 qDebug("effective fieldOrder in loadFromRecord >%s<",fieldOrder.latin1());
428} 439}
429 440
430void OContactFields::setFieldOrder( int num, int index ){ 441void OContactFields::setFieldOrder( int num, int index ){
431 qDebug("qcontactfields setfieldorder pos %i -> %i",num,index); 442 qDebug("qcontactfields setfieldorder pos %i -> %i",num,index);
432 443
433 fieldOrder[num] = QString::number( index, 16 )[0]; 444 fieldOrder[num] = QString::number( index, 16 )[0];
434 445
435 // We will store this new fieldorder globally to 446 // We will store this new fieldorder globally to
436 // remember it for contacts which have none 447 // remember it for contacts which have none
437 globalFieldOrder = fieldOrder; 448 globalFieldOrder = fieldOrder;
438 changedFieldOrder = true; 449 changedFieldOrder = true;
439 450
440 qDebug("fieldOrder >%s<",fieldOrder.latin1()); 451 qDebug("fieldOrder >%s<",fieldOrder.latin1());
441} 452}
442 453
443int OContactFields::getFieldOrder( int num, int defIndex ){ 454int OContactFields::getFieldOrder( int num, int defIndex ){
444 qDebug("ocontactfields getFieldOrder"); 455 qDebug("ocontactfields getFieldOrder");
445 qDebug("fieldOrder >%s<",fieldOrder.latin1()); 456 qDebug("fieldOrder >%s<",fieldOrder.latin1());
446 457
447 // Get index of combo as char.. 458 // Get index of combo as char..
448 QChar poschar = fieldOrder[num]; 459 QChar poschar = fieldOrder[num];
449 460
450 bool ok; 461 bool ok;
451 int ret = 0; 462 int ret = 0;
452 // Convert char to number.. 463 // Convert char to number..
453 if ( !( poschar == QChar::null ) ) 464 if ( !( poschar == QChar::null ) )
454 ret = QString( poschar ).toInt(&ok, 16); 465 ret = QString( poschar ).toInt(&ok, 16);
455 else 466 else
456 ok = false; 467 ok = false;
457 468
458 // Return default value if index for 469 // Return default value if index for
459 // num was not set or if anything else happened.. 470 // num was not set or if anything else happened..
460 if ( !ok ) ret = defIndex; 471 if ( !ok ) ret = defIndex;
461 472
462 qDebug("returning >%i<",ret); 473 qDebug("returning >%i<",ret);
463 474
464 return ret; 475 return ret;
465 476
466} 477}
diff --git a/libopie/pim/ocontactfields.h b/libopie/pim/ocontactfields.h
index 9f6171b..f105de7 100644
--- a/libopie/pim/ocontactfields.h
+++ b/libopie/pim/ocontactfields.h
@@ -1,60 +1,67 @@
1#ifndef OPIE_CONTACTS_FIELDS 1#ifndef OPIE_CONTACTS_FIELDS
2#define OPIE_CONTACTS_FIELDS 2#define OPIE_CONTACTS_FIELDS
3 3
4class QStringList; 4class QStringList;
5 5
6#include <qmap.h> 6#include <qmap.h>
7#include <qstring.h> 7#include <qstring.h>
8#include <opie/ocontact.h> 8#include <opie/ocontact.h>
9 9
10#define CONTACT_FIELD_ORDER_NAME "opie-contactfield-order" 10#define CONTACT_FIELD_ORDER_NAME "opie-contactfield-order"
11#define DEFAULT_FIELD_ORDER "__________" 11#define DEFAULT_FIELD_ORDER "__________"
12 12
13class OContactFields{ 13class OContactFields{
14 14
15 public: 15 public:
16 OContactFields(); 16 OContactFields();
17 ~OContactFields(); 17 ~OContactFields();
18 /** Set the index for combo boxes. 18 /** Set the index for combo boxes.
19 * Sets the <b>index</b> of combo <b>num</b>. 19 * Sets the <b>index</b> of combo <b>num</b>.
20 * @param num selects the number of the combo 20 * @param num selects the number of the combo
21 * @param index sets the index in the combo 21 * @param index sets the index in the combo
22 */ 22 */
23 void setFieldOrder( int num, int index ); 23 void setFieldOrder( int num, int index );
24 24
25 /** Get the index for combo boxes. 25 /** Get the index for combo boxes.
26 * Returns the index of combo <b>num</b> or defindex 26 * Returns the index of combo <b>num</b> or defindex
27 * if none was defined.. 27 * if none was defined..
28 * @param num Selects the number of the combo 28 * @param num Selects the number of the combo
29 * @param defIndex will be returned if none was defined (either 29 * @param defIndex will be returned if none was defined (either
30 * globally in the config file, nor by the contact which was used 30 * globally in the config file, nor by the contact which was used
31 * by loadFromRecord() ) 31 * by loadFromRecord() )
32 */ 32 */
33 int getFieldOrder( int num, int defIndex); 33 int getFieldOrder( int num, int defIndex);
34 34
35 /** Store fieldorder to contact. */ 35 /** Store fieldorder to contact. */
36 void saveToRecord( OContact& ); 36 void saveToRecord( OContact& );
37 /** Get Fieldorder from contact. */ 37 /** Get Fieldorder from contact. */
38 void loadFromRecord( const OContact& ); 38 void loadFromRecord( const OContact& );
39 39
40 private: 40 private:
41 QString fieldOrder; 41 QString fieldOrder;
42 QString globalFieldOrder; 42 QString globalFieldOrder;
43 bool changedFieldOrder; 43 bool changedFieldOrder;
44 44
45 public: 45 public:
46 static QStringList personalfields( bool sorted = true, bool translated = false );
47 static QStringList phonefields( bool sorted = true, bool translated = false );
48 static QStringList detailsfields( bool sorted = true, bool translated = false );
49 static QStringList fields( bool sorted = true, bool translated = false );
50
51 static QStringList trpersonalfields( bool sorted = true );
52 static QStringList untrpersonalfields( bool sorted = true );
46 static QStringList trphonefields( bool sorted = true ); 53 static QStringList trphonefields( bool sorted = true );
47 static QStringList untrphonefields( bool sorted = true ); 54 static QStringList untrphonefields( bool sorted = true );
48 static QStringList trdetailsfields( bool sorted = true ); 55 static QStringList trdetailsfields( bool sorted = true );
49 static QStringList untrdetailsfields( bool sorted = true ); 56 static QStringList untrdetailsfields( bool sorted = true );
50 static QStringList trfields( bool sorted = true ); 57 static QStringList trfields( bool sorted = true );
51 static QStringList untrfields( bool sorted = true ); 58 static QStringList untrfields( bool sorted = true );
52 59
53 static QMap<int, QString> idToTrFields(); 60 static QMap<int, QString> idToTrFields();
54 static QMap<QString, int> trFieldsToId(); 61 static QMap<QString, int> trFieldsToId();
55 static QMap<int, QString> idToUntrFields(); 62 static QMap<int, QString> idToUntrFields();
56 static QMap<QString, int> untrFieldsToId(); 63 static QMap<QString, int> untrFieldsToId();
57 64
58}; 65};
59 66
60#endif 67#endif
diff --git a/libopie/pim/opimnotifymanager.cpp b/libopie/pim/opimnotifymanager.cpp
index 06b5987..53ad4c3 100644
--- a/libopie/pim/opimnotifymanager.cpp
+++ b/libopie/pim/opimnotifymanager.cpp
@@ -1,74 +1,146 @@
1#include "opimnotifymanager.h" 1#include "opimnotifymanager.h"
2 2
3#include "oconversion.h"
4
5#include <qstringlist.h>
6
3OPimNotifyManager::OPimNotifyManager( const Reminders& rem, const Alarms& al) 7OPimNotifyManager::OPimNotifyManager( const Reminders& rem, const Alarms& al)
4 : m_rem( rem ), m_al( al ) 8 : m_rem( rem ), m_al( al )
5{} 9{}
6OPimNotifyManager::~OPimNotifyManager() { 10OPimNotifyManager::~OPimNotifyManager() {
7} 11}
8/* use static_cast and type instead of dynamic... */ 12/* use static_cast and type instead of dynamic... */
9void OPimNotifyManager::add( const OPimNotify& noti) { 13void OPimNotifyManager::add( const OPimNotify& noti) {
10 if ( noti.type() == QString::fromLatin1("OPimReminder") ) { 14 if ( noti.type() == QString::fromLatin1("OPimReminder") ) {
11 const OPimReminder& rem = static_cast<const OPimReminder&>(noti); 15 const OPimReminder& rem = static_cast<const OPimReminder&>(noti);
12 m_rem.append( rem ); 16 m_rem.append( rem );
13 }else if ( noti.type() == QString::fromLatin1("OPimAlarm") ) { 17 }else if ( noti.type() == QString::fromLatin1("OPimAlarm") ) {
14 const OPimAlarm& al = static_cast<const OPimAlarm&>(noti); 18 const OPimAlarm& al = static_cast<const OPimAlarm&>(noti);
15 m_al.append( al ); 19 m_al.append( al );
16 } 20 }
17} 21}
18void OPimNotifyManager::remove( const OPimNotify& noti) { 22void OPimNotifyManager::remove( const OPimNotify& noti) {
19 if ( noti.type() == QString::fromLatin1("OPimReminder") ) { 23 if ( noti.type() == QString::fromLatin1("OPimReminder") ) {
20 const OPimReminder& rem = static_cast<const OPimReminder&>(noti); 24 const OPimReminder& rem = static_cast<const OPimReminder&>(noti);
21 m_rem.remove( rem ); 25 m_rem.remove( rem );
22 }else if ( noti.type() == QString::fromLatin1("OPimAlarm") ) { 26 }else if ( noti.type() == QString::fromLatin1("OPimAlarm") ) {
23 const OPimAlarm& al = static_cast<const OPimAlarm&>(noti); 27 const OPimAlarm& al = static_cast<const OPimAlarm&>(noti);
24 m_al.remove( al ); 28 m_al.remove( al );
25 } 29 }
26} 30}
27void OPimNotifyManager::replace( const OPimNotify& noti) { 31void OPimNotifyManager::replace( const OPimNotify& noti) {
28 if ( noti.type() == QString::fromLatin1("OPimReminder") ) { 32 if ( noti.type() == QString::fromLatin1("OPimReminder") ) {
29 const OPimReminder& rem = static_cast<const OPimReminder&>(noti); 33 const OPimReminder& rem = static_cast<const OPimReminder&>(noti);
30 m_rem.remove( rem ); 34 m_rem.remove( rem );
31 m_rem.append( rem ); 35 m_rem.append( rem );
32 }else if ( noti.type() == QString::fromLatin1("OPimAlarm") ) { 36 }else if ( noti.type() == QString::fromLatin1("OPimAlarm") ) {
33 const OPimAlarm& al = static_cast<const OPimAlarm&>(noti); 37 const OPimAlarm& al = static_cast<const OPimAlarm&>(noti);
34 m_al.remove( al ); 38 m_al.remove( al );
35 m_al.append( al ); 39 m_al.append( al );
36 } 40 }
37} 41}
38OPimNotifyManager::Reminders OPimNotifyManager::reminders()const { 42OPimNotifyManager::Reminders OPimNotifyManager::reminders()const {
39 return m_rem; 43 return m_rem;
40} 44}
41OPimNotifyManager::Alarms OPimNotifyManager::alarms()const { 45OPimNotifyManager::Alarms OPimNotifyManager::alarms()const {
42 return m_al; 46 return m_al;
43} 47}
44void OPimNotifyManager::setAlarms( const Alarms& al) { 48void OPimNotifyManager::setAlarms( const Alarms& al) {
45 m_al = al; 49 m_al = al;
46} 50}
47void OPimNotifyManager::setReminders( const Reminders& rem) { 51void OPimNotifyManager::setReminders( const Reminders& rem) {
48 m_rem = rem; 52 m_rem = rem;
49} 53}
50/* FIXME!!! */ 54/* FIXME!!! */
51/** 55/**
52 * The idea is to check if the provider for our service 56 * The idea is to check if the provider for our service
53 * is online 57 * is online
54 * if it is we will use QCOP 58 * if it is we will use QCOP
55 * if not the Factory to get the backend... 59 * if not the Factory to get the backend...
56 * Qtopia1.6 services would be kewl to have here.... 60 * Qtopia1.6 services would be kewl to have here....
57 */ 61 */
58void OPimNotifyManager::registerNotify( const OPimNotify& ) { 62void OPimNotifyManager::registerNotify( const OPimNotify& ) {
59 63
60} 64}
61/* FIXME!!! */ 65/* FIXME!!! */
62/** 66/**
63 * same as above... 67 * same as above...
64 * Also implement Url model 68 * Also implement Url model
65 * have a MainWindow.... 69 * have a MainWindow....
66 */ 70 */
67void OPimNotifyManager::deregister( const OPimNotify& ) { 71void OPimNotifyManager::deregister( const OPimNotify& ) {
68 72
69} 73}
74
70bool OPimNotifyManager::isEmpty()const { 75bool OPimNotifyManager::isEmpty()const {
71 qWarning("is Empty called on OPimNotifyManager %d %d", m_rem.count(), m_al.count() ); 76 qWarning("is Empty called on OPimNotifyManager %d %d", m_rem.count(), m_al.count() );
72 if ( m_rem.isEmpty() && m_al.isEmpty() ) return true; 77 if ( m_rem.isEmpty() && m_al.isEmpty() ) return true;
73 else return false; 78 else return false;
74} 79}
80
81// Taken from otodoaccessxml..
82QString OPimNotifyManager::alarmsToString() const
83{
84 QString str;
85
86 OPimNotifyManager::Alarms alarms = m_al;
87 if ( !alarms.isEmpty() ) {
88 QStringList als;
89 OPimNotifyManager::Alarms::Iterator it = alarms.begin();
90 for ( ; it != alarms.end(); ++it ) {
91 /* only if time is valid */
92 if ( (*it).dateTime().isValid() ) {
93 als << OConversion::dateTimeToString( (*it).dateTime() )
94 + ":" + QString::number( (*it).duration() )
95 + ":" + QString::number( (*it).sound() )
96 + ":";
97 }
98 }
99 // now write the list
100 qWarning("als: %s", als.join("____________").latin1() );
101 str = als.join(";");
102 }
103
104 return str;
105}
106QString OPimNotifyManager::remindersToString() const
107{
108 QString str;
109
110 OPimNotifyManager::Reminders reminders = m_rem;
111 if (!reminders.isEmpty() ) {
112 OPimNotifyManager::Reminders::Iterator it = reminders.begin();
113 QStringList records;
114 for ( ; it != reminders.end(); ++it ) {
115 records << QString::number( (*it).recordUid() );
116 }
117 str = records.join(";");
118 }
119
120 return str;
121}
122
123void OPimNotifyManager::alarmsFromString( const QString& str )
124{
125 QStringList als = QStringList::split(";", str );
126 for (QStringList::Iterator it = als.begin(); it != als.end(); ++it ) {
127 QStringList alarm = QStringList::split(":", (*it), TRUE ); // allow empty
128 qWarning("alarm: %s", alarm.join("___").latin1() );
129 qWarning("alarm[0]: %s %s", alarm[0].latin1(),
130 OConversion::dateTimeFromString( alarm[0] ).toString().latin1() );
131 OPimAlarm al( alarm[2].toInt(), OConversion::dateTimeFromString( alarm[0] ),
132 alarm[1].toInt() );
133 add( al );
134 }
135}
136
137void OPimNotifyManager::remindersFromString( const QString& str )
138{
139
140 QStringList rems = QStringList::split(";", str );
141 for (QStringList::Iterator it = rems.begin(); it != rems.end(); ++it ) {
142 OPimReminder rem( (*it).toInt() );
143 add( rem );
144 }
145
146}
diff --git a/libopie/pim/opimnotifymanager.h b/libopie/pim/opimnotifymanager.h
index 0ac30a1..48410e7 100644
--- a/libopie/pim/opimnotifymanager.h
+++ b/libopie/pim/opimnotifymanager.h
@@ -1,54 +1,76 @@
1#ifndef OPIE_PIM_NOTIFY_MANAGER_H 1#ifndef OPIE_PIM_NOTIFY_MANAGER_H
2#define OPIE_PIM_NOTIFY_MANAGER_H 2#define OPIE_PIM_NOTIFY_MANAGER_H
3 3
4#include <qvaluelist.h> 4#include <qvaluelist.h>
5 5
6#include <opie/opimnotify.h> 6#include <opie/opimnotify.h>
7 7
8/** 8/**
9 * The notify manager keeps track of the Notifiers.... 9 * The notify manager keeps track of the Notifiers....
10 */ 10 */
11class OPimNotifyManager { 11class OPimNotifyManager {
12public: 12public:
13 typedef QValueList<OPimReminder> Reminders; 13 typedef QValueList<OPimReminder> Reminders;
14 typedef QValueList<OPimAlarm> Alarms; 14 typedef QValueList<OPimAlarm> Alarms;
15 OPimNotifyManager( const Reminders& rems = Reminders(), const Alarms& alarms = Alarms() ); 15 OPimNotifyManager( const Reminders& rems = Reminders(), const Alarms& alarms = Alarms() );
16 ~OPimNotifyManager(); 16 ~OPimNotifyManager();
17 17
18 /* we will cast it for you ;) */ 18 /* we will cast it for you ;) */
19 void add( const OPimNotify& ); 19 void add( const OPimNotify& );
20 void remove( const OPimNotify& ); 20 void remove( const OPimNotify& );
21 /* replaces all with this one! */ 21 /* replaces all with this one! */
22 void replace( const OPimNotify& ); 22 void replace( const OPimNotify& );
23 23
24 Reminders reminders()const; 24 Reminders reminders()const;
25 Alarms alarms()const; 25 Alarms alarms()const;
26 26
27 void setAlarms( const Alarms& ); 27 void setAlarms( const Alarms& );
28 void setReminders( const Reminders& ); 28 void setReminders( const Reminders& );
29 29
30 /* register is a Ansi C keyword... */ 30 /* register is a Ansi C keyword... */
31 /** 31 /**
32 * This function will register the Notify to the Alarm Server 32 * This function will register the Notify to the Alarm Server
33 * or datebook depending on the type of the notify 33 * or datebook depending on the type of the notify
34 */ 34 */
35 void registerNotify( const OPimNotify& ); 35 void registerNotify( const OPimNotify& );
36 36
37 /** 37 /**
38 * this will do the opposite.. 38 * this will do the opposite..
39 */ 39 */
40 void deregister( const OPimNotify& ); 40 void deregister( const OPimNotify& );
41 41
42
43 bool isEmpty()const; 42 bool isEmpty()const;
44 43
44 /**
45 * Return all alarms as string
46 */
47 QString alarmsToString() const;
48 /**
49 * Return all notifiers as string
50 */
51 QString remindersToString() const;
52
53 /**
54 * Convert string to alarms
55 * @param str String created by alarmsToString()
56 */
57 void alarmsFromString( const QString& str );
58
59 /**
60 * Convert string to reminders
61 * @param str String created by remindersToString()
62 */
63 void remindersFromString( const QString& str );
64
65
66
45private: 67private:
46 Reminders m_rem; 68 Reminders m_rem;
47 Alarms m_al; 69 Alarms m_al;
48 70
49 class Private; 71 class Private;
50 Private *d; 72 Private *d;
51 73
52}; 74};
53 75
54#endif 76#endif
diff --git a/libopie/pim/otodoaccesssql.cpp b/libopie/pim/otodoaccesssql.cpp
index d255c66..ebd03bb 100644
--- a/libopie/pim/otodoaccesssql.cpp
+++ b/libopie/pim/otodoaccesssql.cpp
@@ -1,651 +1,667 @@
1 1
2#include <qdatetime.h> 2#include <qdatetime.h>
3 3
4#include <qpe/global.h> 4#include <qpe/global.h>
5 5
6#include <opie2/osqldriver.h> 6#include <opie2/osqldriver.h>
7#include <opie2/osqlresult.h> 7#include <opie2/osqlresult.h>
8#include <opie2/osqlmanager.h> 8#include <opie2/osqlmanager.h>
9#include <opie2/osqlquery.h> 9#include <opie2/osqlquery.h>
10 10
11#include "otodoaccesssql.h" 11#include "otodoaccesssql.h"
12#include "opimstate.h"
13#include "opimnotifymanager.h"
14#include "orecur.h"
12 15
13/* 16/*
14 * first some query 17 * first some query
15 * CREATE query 18 * CREATE query
16 * LOAD query 19 * LOAD query
17 * INSERT 20 * INSERT
18 * REMOVE 21 * REMOVE
19 * CLEAR 22 * CLEAR
20 */ 23 */
21namespace { 24namespace {
22 /** 25 /**
23 * CreateQuery for the Todolist Table 26 * CreateQuery for the Todolist Table
24 */ 27 */
25 class CreateQuery : public OSQLQuery { 28 class CreateQuery : public OSQLQuery {
26 public: 29 public:
27 CreateQuery(); 30 CreateQuery();
28 ~CreateQuery(); 31 ~CreateQuery();
29 QString query()const; 32 QString query()const;
30 }; 33 };
31 34
32 /** 35 /**
33 * LoadQuery 36 * LoadQuery
34 * this one queries for all uids 37 * this one queries for all uids
35 */ 38 */
36 class LoadQuery : public OSQLQuery { 39 class LoadQuery : public OSQLQuery {
37 public: 40 public:
38 LoadQuery(); 41 LoadQuery();
39 ~LoadQuery(); 42 ~LoadQuery();
40 QString query()const; 43 QString query()const;
41 }; 44 };
42 45
43 /** 46 /**
44 * inserts/adds a OTodo to the table 47 * inserts/adds a OTodo to the table
45 */ 48 */
46 class InsertQuery : public OSQLQuery { 49 class InsertQuery : public OSQLQuery {
47 public: 50 public:
48 InsertQuery(const OTodo& ); 51 InsertQuery(const OTodo& );
49 ~InsertQuery(); 52 ~InsertQuery();
50 QString query()const; 53 QString query()const;
51 private: 54 private:
52 OTodo m_todo; 55 OTodo m_todo;
53 }; 56 };
54 57
55 /** 58 /**
56 * removes one from the table 59 * removes one from the table
57 */ 60 */
58 class RemoveQuery : public OSQLQuery { 61 class RemoveQuery : public OSQLQuery {
59 public: 62 public:
60 RemoveQuery(int uid ); 63 RemoveQuery(int uid );
61 ~RemoveQuery(); 64 ~RemoveQuery();
62 QString query()const; 65 QString query()const;
63 private: 66 private:
64 int m_uid; 67 int m_uid;
65 }; 68 };
66 69
67 /** 70 /**
68 * Clears (delete) a Table 71 * Clears (delete) a Table
69 */ 72 */
70 class ClearQuery : public OSQLQuery { 73 class ClearQuery : public OSQLQuery {
71 public: 74 public:
72 ClearQuery(); 75 ClearQuery();
73 ~ClearQuery(); 76 ~ClearQuery();
74 QString query()const; 77 QString query()const;
75 78
76 }; 79 };
77 80
78 /** 81 /**
79 * a find query 82 * a find query
80 */ 83 */
81 class FindQuery : public OSQLQuery { 84 class FindQuery : public OSQLQuery {
82 public: 85 public:
83 FindQuery(int uid); 86 FindQuery(int uid);
84 FindQuery(const QArray<int>& ); 87 FindQuery(const QArray<int>& );
85 ~FindQuery(); 88 ~FindQuery();
86 QString query()const; 89 QString query()const;
87 private: 90 private:
88 QString single()const; 91 QString single()const;
89 QString multi()const; 92 QString multi()const;
90 QArray<int> m_uids; 93 QArray<int> m_uids;
91 int m_uid; 94 int m_uid;
92 }; 95 };
93 96
94 /** 97 /**
95 * overdue query 98 * overdue query
96 */ 99 */
97 class OverDueQuery : public OSQLQuery { 100 class OverDueQuery : public OSQLQuery {
98 public: 101 public:
99 OverDueQuery(); 102 OverDueQuery();
100 ~OverDueQuery(); 103 ~OverDueQuery();
101 QString query()const; 104 QString query()const;
102 }; 105 };
103 class EffQuery : public OSQLQuery { 106 class EffQuery : public OSQLQuery {
104 public: 107 public:
105 EffQuery( const QDate&, const QDate&, bool inc ); 108 EffQuery( const QDate&, const QDate&, bool inc );
106 ~EffQuery(); 109 ~EffQuery();
107 QString query()const; 110 QString query()const;
108 private: 111 private:
109 QString with()const; 112 QString with()const;
110 QString out()const; 113 QString out()const;
111 QDate m_start; 114 QDate m_start;
112 QDate m_end; 115 QDate m_end;
113 bool m_inc :1; 116 bool m_inc :1;
114 }; 117 };
115 118
116 119
117 CreateQuery::CreateQuery() : OSQLQuery() {} 120 CreateQuery::CreateQuery() : OSQLQuery() {}
118 CreateQuery::~CreateQuery() {} 121 CreateQuery::~CreateQuery() {}
119 QString CreateQuery::query()const { 122 QString CreateQuery::query()const {
120 QString qu; 123 QString qu;
121 qu += "create table todolist( uid PRIMARY KEY, categories, completed, "; 124 qu += "create table todolist( uid PRIMARY KEY, categories, completed, ";
122 qu += "description, summary, priority, DueDate, progress , state, "; 125 qu += "description, summary, priority, DueDate, progress , state, ";
123 qu += "Recurrence, notifiers, maintainer, startdate, completeddate)"; 126 qu += "Recurrence, reminders, alarms, maintainer, startdate, completeddate);";
127 qu += "create table custom_data( uid INTEGER, id INTEGER, type VARCHAR(10), value VARCHAR(10), PRIMARY KEY /* identifier */ (uid, id) );";
124 return qu; 128 return qu;
125 } 129 }
126 130
127 LoadQuery::LoadQuery() : OSQLQuery() {} 131 LoadQuery::LoadQuery() : OSQLQuery() {}
128 LoadQuery::~LoadQuery() {} 132 LoadQuery::~LoadQuery() {}
129 QString LoadQuery::query()const { 133 QString LoadQuery::query()const {
130 QString qu; 134 QString qu;
131 // We do not need "distinct" here. The primary key is always unique.. 135 // We do not need "distinct" here. The primary key is always unique..
132 //qu += "select distinct uid from todolist"; 136 //qu += "select distinct uid from todolist";
133 qu += "select uid from todolist"; 137 qu += "select uid from todolist";
134 138
135 return qu; 139 return qu;
136 } 140 }
137 141
138 InsertQuery::InsertQuery( const OTodo& todo ) 142 InsertQuery::InsertQuery( const OTodo& todo )
139 : OSQLQuery(), m_todo( todo ) { 143 : OSQLQuery(), m_todo( todo ) {
140 } 144 }
141 InsertQuery::~InsertQuery() { 145 InsertQuery::~InsertQuery() {
142 } 146 }
143 /* 147 /*
144 * converts from a OTodo to a query 148 * converts from a OTodo to a query
145 * we leave out X-Ref + Alarms 149 * we leave out X-Ref + Alarms
146 */ 150 */
147 QString InsertQuery::query()const{ 151 QString InsertQuery::query()const{
148 152
149 int year, month, day; 153 int year, month, day;
150 year = month = day = 0; 154 year = month = day = 0;
151 if (m_todo.hasDueDate() ) { 155 if (m_todo.hasDueDate() ) {
152 QDate date = m_todo.dueDate(); 156 QDate date = m_todo.dueDate();
153 year = date.year(); 157 year = date.year();
154 month = date.month(); 158 month = date.month();
155 day = date.day(); 159 day = date.day();
156 } 160 }
157 int sYear = 0, sMonth = 0, sDay = 0; 161 int sYear = 0, sMonth = 0, sDay = 0;
158 if( m_todo.hasStartDate() ){ 162 if( m_todo.hasStartDate() ){
159 QDate sDate = m_todo.startDate(); 163 QDate sDate = m_todo.startDate();
160 sYear = sDate.year(); 164 sYear = sDate.year();
161 sMonth= sDate.month(); 165 sMonth= sDate.month();
162 sDay = sDate.day(); 166 sDay = sDate.day();
163 } 167 }
164 168
165 int eYear = 0, eMonth = 0, eDay = 0; 169 int eYear = 0, eMonth = 0, eDay = 0;
166 if( m_todo.hasCompletedDate() ){ 170 if( m_todo.hasCompletedDate() ){
167 QDate eDate = m_todo.completedDate(); 171 QDate eDate = m_todo.completedDate();
168 eYear = eDate.year(); 172 eYear = eDate.year();
169 eMonth= eDate.month(); 173 eMonth= eDate.month();
170 eDay = eDate.day(); 174 eDay = eDate.day();
171 } 175 }
172 QString qu; 176 QString qu;
173 qu = "insert into todolist VALUES(" 177 qu = "insert into todolist VALUES("
174 + QString::number( m_todo.uid() ) + "," 178 + QString::number( m_todo.uid() ) + ","
175 + "'" + m_todo.idsToString( m_todo.categories() ) + "'" + "," 179 + "'" + m_todo.idsToString( m_todo.categories() ) + "'" + ","
176 + QString::number( m_todo.isCompleted() ) + "," 180 + QString::number( m_todo.isCompleted() ) + ","
177 + "'" + m_todo.description() + "'" + "," 181 + "'" + m_todo.description() + "'" + ","
178 + "'" + m_todo.summary() + "'" + "," 182 + "'" + m_todo.summary() + "'" + ","
179 + QString::number(m_todo.priority() ) + "," 183 + QString::number(m_todo.priority() ) + ","
180 + "'" + QString::number(year) + "-" 184 + "'" + QString::number(year) + "-"
181 + QString::number(month) 185 + QString::number(month)
182 + "-" + QString::number( day ) + "'" + "," 186 + "-" + QString::number( day ) + "'" + ","
183 + QString::number( m_todo.progress() ) + "," 187 + QString::number( m_todo.progress() ) + ","
184 + "''" + "," // state (conversion needed) 188 + QString::number( m_todo.state().state() ) + ","
185 // + QString::number( m_todo.state() ) + "," 189 + "'" + m_todo.recurrence().toString() + "'"+ ",";
186 + "''" + "," // Recurrence (conversion needed) 190
187 + "''" + "," // Notifiers (conversion needed) 191 if ( m_todo.hasNotifiers() ) {
188 + "''" + "," // Maintainers (conversion needed) 192 OPimNotifyManager manager = m_todo.notifiers();
193 qu += "'" + manager.remindersToString() + "'" + ","
194 + "'" + manager.alarmsToString() + "'" + ",";
195 }
196 else{
197 qu += QString( "''" ) + ","
198 + "''" + ",";
199 }
200
201 qu += QString( "''" ) + QString( "," ) // Maintainers (cur. not supported !)
189 + "'" + QString::number(sYear) + "-" 202 + "'" + QString::number(sYear) + "-"
190 + QString::number(sMonth) 203 + QString::number(sMonth)
191 + "-" + QString::number(sDay) + "'" + "," 204 + "-" + QString::number(sDay) + "'" + ","
192 + "'" + QString::number(eYear) + "-" 205 + "'" + QString::number(eYear) + "-"
193 + QString::number(eMonth) 206 + QString::number(eMonth)
194 + "-"+QString::number(eDay) + "'" 207 + "-"+QString::number(eDay) + "'"
195 + ")"; 208 + ")";
196 209
197 qWarning("add %s", qu.latin1() ); 210 qWarning("add %s", qu.latin1() );
198 return qu; 211 return qu;
199 } 212 }
200 213
201 RemoveQuery::RemoveQuery(int uid ) 214 RemoveQuery::RemoveQuery(int uid )
202 : OSQLQuery(), m_uid( uid ) {} 215 : OSQLQuery(), m_uid( uid ) {}
203 RemoveQuery::~RemoveQuery() {} 216 RemoveQuery::~RemoveQuery() {}
204 QString RemoveQuery::query()const { 217 QString RemoveQuery::query()const {
205 QString qu = "DELETE from todolist where uid = " + QString::number(m_uid); 218 QString qu = "DELETE from todolist where uid = " + QString::number(m_uid);
206 return qu; 219 return qu;
207 } 220 }
208 221
209 222
210 ClearQuery::ClearQuery() 223 ClearQuery::ClearQuery()
211 : OSQLQuery() {} 224 : OSQLQuery() {}
212 ClearQuery::~ClearQuery() {} 225 ClearQuery::~ClearQuery() {}
213 QString ClearQuery::query()const { 226 QString ClearQuery::query()const {
214 QString qu = "drop table todolist"; 227 QString qu = "drop table todolist";
215 return qu; 228 return qu;
216 } 229 }
217 FindQuery::FindQuery(int uid) 230 FindQuery::FindQuery(int uid)
218 : OSQLQuery(), m_uid(uid ) { 231 : OSQLQuery(), m_uid(uid ) {
219 } 232 }
220 FindQuery::FindQuery(const QArray<int>& ints) 233 FindQuery::FindQuery(const QArray<int>& ints)
221 : OSQLQuery(), m_uids(ints){ 234 : OSQLQuery(), m_uids(ints){
222 } 235 }
223 FindQuery::~FindQuery() { 236 FindQuery::~FindQuery() {
224 } 237 }
225 QString FindQuery::query()const{ 238 QString FindQuery::query()const{
226 if (m_uids.count() == 0 ) 239 if (m_uids.count() == 0 )
227 return single(); 240 return single();
228 else 241 else
229 return multi(); 242 return multi();
230 } 243 }
231 QString FindQuery::single()const{ 244 QString FindQuery::single()const{
232 QString qu = "select * from todolist where uid = " + QString::number(m_uid); 245 QString qu = "select * from todolist where uid = " + QString::number(m_uid);
233 return qu; 246 return qu;
234 } 247 }
235 QString FindQuery::multi()const { 248 QString FindQuery::multi()const {
236 QString qu = "select * from todolist where "; 249 QString qu = "select * from todolist where ";
237 for (uint i = 0; i < m_uids.count(); i++ ) { 250 for (uint i = 0; i < m_uids.count(); i++ ) {
238 qu += " UID = " + QString::number( m_uids[i] ) + " OR"; 251 qu += " UID = " + QString::number( m_uids[i] ) + " OR";
239 } 252 }
240 qu.remove( qu.length()-2, 2 ); 253 qu.remove( qu.length()-2, 2 );
241 return qu; 254 return qu;
242 } 255 }
243 256
244 OverDueQuery::OverDueQuery(): OSQLQuery() {} 257 OverDueQuery::OverDueQuery(): OSQLQuery() {}
245 OverDueQuery::~OverDueQuery() {} 258 OverDueQuery::~OverDueQuery() {}
246 QString OverDueQuery::query()const { 259 QString OverDueQuery::query()const {
247 QDate date = QDate::currentDate(); 260 QDate date = QDate::currentDate();
248 QString str; 261 QString str;
249 str = QString("select uid from todolist where DueDate ='%1-%2-%3'").arg(date.year() ).arg(date.month() ).arg(date.day() ); 262 str = QString("select uid from todolist where DueDate ='%1-%2-%3'").arg(date.year() ).arg(date.month() ).arg(date.day() );
250 263
251 return str; 264 return str;
252 } 265 }
253 266
254 267
255 EffQuery::EffQuery( const QDate& start, const QDate& end, bool inc ) 268 EffQuery::EffQuery( const QDate& start, const QDate& end, bool inc )
256 : OSQLQuery(), m_start( start ), m_end( end ),m_inc(inc) {} 269 : OSQLQuery(), m_start( start ), m_end( end ),m_inc(inc) {}
257 EffQuery::~EffQuery() {} 270 EffQuery::~EffQuery() {}
258 QString EffQuery::query()const { 271 QString EffQuery::query()const {
259 return m_inc ? with() : out(); 272 return m_inc ? with() : out();
260 } 273 }
261 QString EffQuery::with()const { 274 QString EffQuery::with()const {
262 QString str; 275 QString str;
263 str = QString("select uid from todolist where ( DueDate >= '%1-%2-%3' AND DueDate <= '%4-%5-%6' ) OR DueDate = '0-0-0' ") 276 str = QString("select uid from todolist where ( DueDate >= '%1-%2-%3' AND DueDate <= '%4-%5-%6' ) OR DueDate = '0-0-0' ")
264 .arg( m_start.year() ).arg( m_start.month() ).arg( m_start.day() ) 277 .arg( m_start.year() ).arg( m_start.month() ).arg( m_start.day() )
265 .arg( m_end .year() ).arg( m_end .month() ).arg( m_end .day() ); 278 .arg( m_end .year() ).arg( m_end .month() ).arg( m_end .day() );
266 return str; 279 return str;
267 } 280 }
268 QString EffQuery::out()const { 281 QString EffQuery::out()const {
269 QString str; 282 QString str;
270 str = QString("select uid from todolist where DueDate >= '%1-%2-%3' AND DueDate <= '%4-%5-%6'") 283 str = QString("select uid from todolist where DueDate >= '%1-%2-%3' AND DueDate <= '%4-%5-%6'")
271 .arg(m_start.year() ).arg(m_start.month() ).arg( m_start.day() ) 284 .arg(m_start.year() ).arg(m_start.month() ).arg( m_start.day() )
272 .arg(m_end. year() ).arg(m_end. month() ).arg(m_end.day() ); 285 .arg(m_end. year() ).arg(m_end. month() ).arg(m_end.day() );
273 286
274 return str; 287 return str;
275 } 288 }
276}; 289};
277 290
278OTodoAccessBackendSQL::OTodoAccessBackendSQL( const QString& file ) 291OTodoAccessBackendSQL::OTodoAccessBackendSQL( const QString& file )
279 : OTodoAccessBackend(), m_dict(15), m_dirty(true) 292 : OTodoAccessBackend(), m_dict(15), m_dirty(true)
280{ 293{
281 QString fi = file; 294 QString fi = file;
282 if ( fi.isEmpty() ) 295 if ( fi.isEmpty() )
283 fi = Global::applicationFileName( "todolist", "todolist.db" ); 296 fi = Global::applicationFileName( "todolist", "todolist.db" );
284 OSQLManager man; 297 OSQLManager man;
285 m_driver = man.standard(); 298 m_driver = man.standard();
286 m_driver->setUrl(fi); 299 m_driver->setUrl(fi);
287 // fillDict(); 300 // fillDict();
288} 301}
289 302
290OTodoAccessBackendSQL::~OTodoAccessBackendSQL(){ 303OTodoAccessBackendSQL::~OTodoAccessBackendSQL(){
291} 304}
292bool OTodoAccessBackendSQL::load(){ 305bool OTodoAccessBackendSQL::load(){
293 if (!m_driver->open() ) 306 if (!m_driver->open() )
294 return false; 307 return false;
295 308
296 CreateQuery creat; 309 CreateQuery creat;
297 OSQLResult res = m_driver->query(&creat ); 310 OSQLResult res = m_driver->query(&creat );
298 311
299 m_dirty = true; 312 m_dirty = true;
300 return true; 313 return true;
301} 314}
302bool OTodoAccessBackendSQL::reload(){ 315bool OTodoAccessBackendSQL::reload(){
303 return load(); 316 return load();
304} 317}
305 318
306bool OTodoAccessBackendSQL::save(){ 319bool OTodoAccessBackendSQL::save(){
307 return m_driver->close(); 320 return m_driver->close();
308} 321}
309QArray<int> OTodoAccessBackendSQL::allRecords()const { 322QArray<int> OTodoAccessBackendSQL::allRecords()const {
310 if (m_dirty ) 323 if (m_dirty )
311 update(); 324 update();
312 325
313 return m_uids; 326 return m_uids;
314} 327}
315QArray<int> OTodoAccessBackendSQL::queryByExample( const OTodo& , int, const QDateTime& ){ 328QArray<int> OTodoAccessBackendSQL::queryByExample( const OTodo& , int, const QDateTime& ){
316 QArray<int> ints(0); 329 QArray<int> ints(0);
317 return ints; 330 return ints;
318} 331}
319OTodo OTodoAccessBackendSQL::find(int uid ) const{ 332OTodo OTodoAccessBackendSQL::find(int uid ) const{
320 FindQuery query( uid ); 333 FindQuery query( uid );
321 return todo( m_driver->query(&query) ); 334 return todo( m_driver->query(&query) );
322 335
323} 336}
324OTodo OTodoAccessBackendSQL::find( int uid, const QArray<int>& ints, 337OTodo OTodoAccessBackendSQL::find( int uid, const QArray<int>& ints,
325 uint cur, Frontend::CacheDirection dir ) const{ 338 uint cur, Frontend::CacheDirection dir ) const{
326 uint CACHE = readAhead(); 339 uint CACHE = readAhead();
327 qWarning("searching for %d", uid ); 340 qWarning("searching for %d", uid );
328 QArray<int> search( CACHE ); 341 QArray<int> search( CACHE );
329 uint size =0; 342 uint size =0;
330 OTodo to; 343 OTodo to;
331 344
332 // we try to cache CACHE items 345 // we try to cache CACHE items
333 switch( dir ) { 346 switch( dir ) {
334 /* forward */ 347 /* forward */
335 case 0: // FIXME: Not a good style to use magic numbers here (eilers) 348 case 0: // FIXME: Not a good style to use magic numbers here (eilers)
336 for (uint i = cur; i < ints.count() && size < CACHE; i++ ) { 349 for (uint i = cur; i < ints.count() && size < CACHE; i++ ) {
337 qWarning("size %d %d", size, ints[i] ); 350 qWarning("size %d %d", size, ints[i] );
338 search[size] = ints[i]; 351 search[size] = ints[i];
339 size++; 352 size++;
340 } 353 }
341 break; 354 break;
342 /* reverse */ 355 /* reverse */
343 case 1: // FIXME: Not a good style to use magic numbers here (eilers) 356 case 1: // FIXME: Not a good style to use magic numbers here (eilers)
344 for (uint i = cur; i != 0 && size < CACHE; i-- ) { 357 for (uint i = cur; i != 0 && size < CACHE; i-- ) {
345 search[size] = ints[i]; 358 search[size] = ints[i];
346 size++; 359 size++;
347 } 360 }
348 break; 361 break;
349 } 362 }
350 search.resize( size ); 363 search.resize( size );
351 FindQuery query( search ); 364 FindQuery query( search );
352 OSQLResult res = m_driver->query( &query ); 365 OSQLResult res = m_driver->query( &query );
353 if ( res.state() != OSQLResult::Success ) 366 if ( res.state() != OSQLResult::Success )
354 return to; 367 return to;
355 368
356 return todo( res ); 369 return todo( res );
357} 370}
358void OTodoAccessBackendSQL::clear() { 371void OTodoAccessBackendSQL::clear() {
359 ClearQuery cle; 372 ClearQuery cle;
360 OSQLResult res = m_driver->query( &cle ); 373 OSQLResult res = m_driver->query( &cle );
361 CreateQuery qu; 374 CreateQuery qu;
362 res = m_driver->query(&qu); 375 res = m_driver->query(&qu);
363} 376}
364bool OTodoAccessBackendSQL::add( const OTodo& t) { 377bool OTodoAccessBackendSQL::add( const OTodo& t) {
365 InsertQuery ins( t ); 378 InsertQuery ins( t );
366 OSQLResult res = m_driver->query( &ins ); 379 OSQLResult res = m_driver->query( &ins );
367 380
368 if ( res.state() == OSQLResult::Failure ) 381 if ( res.state() == OSQLResult::Failure )
369 return false; 382 return false;
370 int c = m_uids.count(); 383 int c = m_uids.count();
371 m_uids.resize( c+1 ); 384 m_uids.resize( c+1 );
372 m_uids[c] = t.uid(); 385 m_uids[c] = t.uid();
373 386
374 return true; 387 return true;
375} 388}
376bool OTodoAccessBackendSQL::remove( int uid ) { 389bool OTodoAccessBackendSQL::remove( int uid ) {
377 RemoveQuery rem( uid ); 390 RemoveQuery rem( uid );
378 OSQLResult res = m_driver->query(&rem ); 391 OSQLResult res = m_driver->query(&rem );
379 392
380 if ( res.state() == OSQLResult::Failure ) 393 if ( res.state() == OSQLResult::Failure )
381 return false; 394 return false;
382 395
383 m_dirty = true; 396 m_dirty = true;
384 return true; 397 return true;
385} 398}
386/* 399/*
387 * FIXME better set query 400 * FIXME better set query
388 * but we need the cache for that 401 * but we need the cache for that
389 * now we remove 402 * now we remove
390 */ 403 */
391bool OTodoAccessBackendSQL::replace( const OTodo& t) { 404bool OTodoAccessBackendSQL::replace( const OTodo& t) {
392 remove( t.uid() ); 405 remove( t.uid() );
393 bool b= add(t); 406 bool b= add(t);
394 m_dirty = false; // we changed some stuff but the UID stayed the same 407 m_dirty = false; // we changed some stuff but the UID stayed the same
395 return b; 408 return b;
396} 409}
397QArray<int> OTodoAccessBackendSQL::overDue() { 410QArray<int> OTodoAccessBackendSQL::overDue() {
398 OverDueQuery qu; 411 OverDueQuery qu;
399 return uids( m_driver->query(&qu ) ); 412 return uids( m_driver->query(&qu ) );
400} 413}
401QArray<int> OTodoAccessBackendSQL::effectiveToDos( const QDate& s, 414QArray<int> OTodoAccessBackendSQL::effectiveToDos( const QDate& s,
402 const QDate& t, 415 const QDate& t,
403 bool u) { 416 bool u) {
404 EffQuery ef(s, t, u ); 417 EffQuery ef(s, t, u );
405 return uids (m_driver->query(&ef) ); 418 return uids (m_driver->query(&ef) );
406} 419}
407/* 420/*
408 * 421 *
409 */ 422 */
410QArray<int> OTodoAccessBackendSQL::sorted( bool asc, int sortOrder, 423QArray<int> OTodoAccessBackendSQL::sorted( bool asc, int sortOrder,
411 int sortFilter, int cat ) { 424 int sortFilter, int cat ) {
412 qWarning("sorted %d, %d", asc, sortOrder ); 425 qWarning("sorted %d, %d", asc, sortOrder );
413 QString query; 426 QString query;
414 query = "select uid from todolist WHERE "; 427 query = "select uid from todolist WHERE ";
415 428
416 /* 429 /*
417 * Sort Filter stuff 430 * Sort Filter stuff
418 * not that straight forward 431 * not that straight forward
419 * FIXME: Replace magic numbers 432 * FIXME: Replace magic numbers
420 * 433 *
421 */ 434 */
422 /* Category */ 435 /* Category */
423 if ( sortFilter & 1 ) { 436 if ( sortFilter & 1 ) {
424 QString str; 437 QString str;
425 if (cat != 0 ) str = QString::number( cat ); 438 if (cat != 0 ) str = QString::number( cat );
426 query += " categories like '%" +str+"%' AND"; 439 query += " categories like '%" +str+"%' AND";
427 } 440 }
428 /* Show only overdue */ 441 /* Show only overdue */
429 if ( sortFilter & 2 ) { 442 if ( sortFilter & 2 ) {
430 QDate date = QDate::currentDate(); 443 QDate date = QDate::currentDate();
431 QString due; 444 QString due;
432 QString base; 445 QString base;
433 base = QString("DueDate <= '%1-%2-%3' AND completed = 0").arg( date.year() ).arg( date.month() ).arg( date.day() ); 446 base = QString("DueDate <= '%1-%2-%3' AND completed = 0").arg( date.year() ).arg( date.month() ).arg( date.day() );
434 query += " " + base + " AND"; 447 query += " " + base + " AND";
435 } 448 }
436 /* not show completed */ 449 /* not show completed */
437 if ( sortFilter & 4 ) { 450 if ( sortFilter & 4 ) {
438 query += " completed = 0 AND"; 451 query += " completed = 0 AND";
439 }else{ 452 }else{
440 query += " ( completed = 1 OR completed = 0) AND"; 453 query += " ( completed = 1 OR completed = 0) AND";
441 } 454 }
442 /* srtip the end */ 455 /* srtip the end */
443 query = query.remove( query.length()-3, 3 ); 456 query = query.remove( query.length()-3, 3 );
444 457
445 458
446 /* 459 /*
447 * sort order stuff 460 * sort order stuff
448 * quite straight forward 461 * quite straight forward
449 */ 462 */
450 query += "ORDER BY "; 463 query += "ORDER BY ";
451 switch( sortOrder ) { 464 switch( sortOrder ) {
452 /* completed */ 465 /* completed */
453 case 0: 466 case 0:
454 query += "completed"; 467 query += "completed";
455 break; 468 break;
456 case 1: 469 case 1:
457 query += "priority"; 470 query += "priority";
458 break; 471 break;
459 case 2: 472 case 2:
460 query += "summary"; 473 query += "summary";
461 break; 474 break;
462 case 3: 475 case 3:
463 query += "DueDate"; 476 query += "DueDate";
464 break; 477 break;
465 } 478 }
466 479
467 if ( !asc ) { 480 if ( !asc ) {
468 qWarning("not ascending!"); 481 qWarning("not ascending!");
469 query += " DESC"; 482 query += " DESC";
470 } 483 }
471 484
472 qWarning( query ); 485 qWarning( query );
473 OSQLRawQuery raw(query ); 486 OSQLRawQuery raw(query );
474 return uids( m_driver->query(&raw) ); 487 return uids( m_driver->query(&raw) );
475} 488}
476bool OTodoAccessBackendSQL::date( QDate& da, const QString& str ) const{ 489bool OTodoAccessBackendSQL::date( QDate& da, const QString& str ) const{
477 if ( str == "0-0-0" ) 490 if ( str == "0-0-0" )
478 return false; 491 return false;
479 else{ 492 else{
480 int day, year, month; 493 int day, year, month;
481 QStringList list = QStringList::split("-", str ); 494 QStringList list = QStringList::split("-", str );
482 year = list[0].toInt(); 495 year = list[0].toInt();
483 month = list[1].toInt(); 496 month = list[1].toInt();
484 day = list[2].toInt(); 497 day = list[2].toInt();
485 da.setYMD( year, month, day ); 498 da.setYMD( year, month, day );
486 return true; 499 return true;
487 } 500 }
488} 501}
489OTodo OTodoAccessBackendSQL::todo( const OSQLResult& res) const{ 502OTodo OTodoAccessBackendSQL::todo( const OSQLResult& res) const{
490 if ( res.state() == OSQLResult::Failure ) { 503 if ( res.state() == OSQLResult::Failure ) {
491 OTodo to; 504 OTodo to;
492 return to; 505 return to;
493 } 506 }
494 507
495 OSQLResultItem::ValueList list = res.results(); 508 OSQLResultItem::ValueList list = res.results();
496 OSQLResultItem::ValueList::Iterator it = list.begin(); 509 OSQLResultItem::ValueList::Iterator it = list.begin();
497 qWarning("todo1"); 510 qWarning("todo1");
498 OTodo to = todo( (*it) ); 511 OTodo to = todo( (*it) );
499 cache( to ); 512 cache( to );
500 ++it; 513 ++it;
501 514
502 for ( ; it != list.end(); ++it ) { 515 for ( ; it != list.end(); ++it ) {
503 qWarning("caching"); 516 qWarning("caching");
504 cache( todo( (*it) ) ); 517 cache( todo( (*it) ) );
505 } 518 }
506 return to; 519 return to;
507} 520}
508OTodo OTodoAccessBackendSQL::todo( OSQLResultItem& item )const { 521OTodo OTodoAccessBackendSQL::todo( OSQLResultItem& item )const {
509 qWarning("todo"); 522 qWarning("todo");
510 bool hasDueDate = false; QDate dueDate = QDate::currentDate(); 523 bool hasDueDate = false; QDate dueDate = QDate::currentDate();
511 hasDueDate = date( dueDate, item.data("DueDate") ); 524 hasDueDate = date( dueDate, item.data("DueDate") );
512 QStringList cats = QStringList::split(";", item.data("categories") ); 525 QStringList cats = QStringList::split(";", item.data("categories") );
513 526
514 OTodo to( (bool)item.data("completed").toInt(), item.data("priority").toInt(), 527 OTodo to( (bool)item.data("completed").toInt(), item.data("priority").toInt(),
515 cats, item.data("summary"), item.data("description"), 528 cats, item.data("summary"), item.data("description"),
516 item.data("progress").toUShort(), hasDueDate, dueDate, 529 item.data("progress").toUShort(), hasDueDate, dueDate,
517 item.data("uid").toInt() ); 530 item.data("uid").toInt() );
518 531
519 bool isOk; 532 bool isOk;
520 int prioInt = QString( item.data("priority") ).toInt( &isOk ); 533 int prioInt = QString( item.data("priority") ).toInt( &isOk );
521 if ( isOk ) 534 if ( isOk )
522 to.setPriority( prioInt ); 535 to.setPriority( prioInt );
523 536
524 bool hasStartDate = false; QDate startDate = QDate::currentDate(); 537 bool hasStartDate = false; QDate startDate = QDate::currentDate();
525 hasStartDate = date( startDate, item.data("startdate") ); 538 hasStartDate = date( startDate, item.data("startdate") );
526 bool hasCompletedDate = false; QDate completedDate = QDate::currentDate(); 539 bool hasCompletedDate = false; QDate completedDate = QDate::currentDate();
527 hasCompletedDate = date( completedDate, item.data("completeddate") ); 540 hasCompletedDate = date( completedDate, item.data("completeddate") );
528 541
529 if ( hasStartDate ) 542 if ( hasStartDate )
530 to.setStartDate( startDate ); 543 to.setStartDate( startDate );
531 if ( hasCompletedDate ) 544 if ( hasCompletedDate )
532 to.setCompletedDate( completedDate ); 545 to.setCompletedDate( completedDate );
546
547 OPimNotifyManager& manager = to.notifiers();
548 manager.alarmsFromString( item.data("alarms") );
549 manager.remindersFromString( item.data("reminders") );
550
551 OPimState pimState;
552 pimState.setState( QString( item.data("state") ).toInt() );
553 to.setState( pimState );
554
555 // Recurrence not supported yet
556 // to.setRecurrence(
533 557
534 return to; 558 return to;
535} 559}
536OTodo OTodoAccessBackendSQL::todo( int uid )const { 560OTodo OTodoAccessBackendSQL::todo( int uid )const {
537 FindQuery find( uid ); 561 FindQuery find( uid );
538 return todo( m_driver->query(&find) ); 562 return todo( m_driver->query(&find) );
539} 563}
540/* 564/*
541 * update the dict 565 * update the dict
542 */ 566 */
543void OTodoAccessBackendSQL::fillDict() { 567void OTodoAccessBackendSQL::fillDict() {
544 /* initialize dict */ 568 /* initialize dict */
545 /* 569 /*
546 * UPDATE dict if you change anything!!! 570 * UPDATE dict if you change anything!!!
547 * FIXME: Isn't this dict obsolete ? (eilers) 571 * FIXME: Isn't this dict obsolete ? (eilers)
548 */ 572 */
549 m_dict.setAutoDelete( TRUE ); 573 m_dict.setAutoDelete( TRUE );
550 m_dict.insert("Categories" , new int(OTodo::Category) ); 574 m_dict.insert("Categories" , new int(OTodo::Category) );
551 m_dict.insert("Uid" , new int(OTodo::Uid) ); 575 m_dict.insert("Uid" , new int(OTodo::Uid) );
552 m_dict.insert("HasDate" , new int(OTodo::HasDate) ); 576 m_dict.insert("HasDate" , new int(OTodo::HasDate) );
553 m_dict.insert("Completed" , new int(OTodo::Completed) ); 577 m_dict.insert("Completed" , new int(OTodo::Completed) );
554 m_dict.insert("Description" , new int(OTodo::Description) ); 578 m_dict.insert("Description" , new int(OTodo::Description) );
555 m_dict.insert("Summary" , new int(OTodo::Summary) ); 579 m_dict.insert("Summary" , new int(OTodo::Summary) );
556 m_dict.insert("Priority" , new int(OTodo::Priority) ); 580 m_dict.insert("Priority" , new int(OTodo::Priority) );
557 m_dict.insert("DateDay" , new int(OTodo::DateDay) ); 581 m_dict.insert("DateDay" , new int(OTodo::DateDay) );
558 m_dict.insert("DateMonth" , new int(OTodo::DateMonth) ); 582 m_dict.insert("DateMonth" , new int(OTodo::DateMonth) );
559 m_dict.insert("DateYear" , new int(OTodo::DateYear) ); 583 m_dict.insert("DateYear" , new int(OTodo::DateYear) );
560 m_dict.insert("Progress" , new int(OTodo::Progress) ); 584 m_dict.insert("Progress" , new int(OTodo::Progress) );
561 m_dict.insert("Completed", new int(OTodo::Completed) ); // Why twice ? (eilers) 585 m_dict.insert("Completed", new int(OTodo::Completed) ); // Why twice ? (eilers)
562 m_dict.insert("CrossReference", new int(OTodo::CrossReference) ); 586 m_dict.insert("CrossReference", new int(OTodo::CrossReference) );
563// m_dict.insert("HasAlarmDateTime",new int(OTodo::HasAlarmDateTime) ); // old stuff (eilers) 587// m_dict.insert("HasAlarmDateTime",new int(OTodo::HasAlarmDateTime) ); // old stuff (eilers)
564// m_dict.insert("AlarmDateTime", new int(OTodo::AlarmDateTime) ); // old stuff (eilers) 588// m_dict.insert("AlarmDateTime", new int(OTodo::AlarmDateTime) ); // old stuff (eilers)
565} 589}
566/* 590/*
567 * need to be const so let's fool the 591 * need to be const so let's fool the
568 * compiler :( 592 * compiler :(
569 */ 593 */
570void OTodoAccessBackendSQL::update()const { 594void OTodoAccessBackendSQL::update()const {
571 ((OTodoAccessBackendSQL*)this)->m_dirty = false; 595 ((OTodoAccessBackendSQL*)this)->m_dirty = false;
572 LoadQuery lo; 596 LoadQuery lo;
573 OSQLResult res = m_driver->query(&lo); 597 OSQLResult res = m_driver->query(&lo);
574 if ( res.state() != OSQLResult::Success ) 598 if ( res.state() != OSQLResult::Success )
575 return; 599 return;
576 600
577 ((OTodoAccessBackendSQL*)this)->m_uids = uids( res ); 601 ((OTodoAccessBackendSQL*)this)->m_uids = uids( res );
578} 602}
579QArray<int> OTodoAccessBackendSQL::uids( const OSQLResult& res) const{ 603QArray<int> OTodoAccessBackendSQL::uids( const OSQLResult& res) const{
580 604
581 OSQLResultItem::ValueList list = res.results(); 605 OSQLResultItem::ValueList list = res.results();
582 OSQLResultItem::ValueList::Iterator it; 606 OSQLResultItem::ValueList::Iterator it;
583 QArray<int> ints(list.count() ); 607 QArray<int> ints(list.count() );
584 qWarning(" count = %d", list.count() ); 608 qWarning(" count = %d", list.count() );
585 609
586 int i = 0; 610 int i = 0;
587 for (it = list.begin(); it != list.end(); ++it ) { 611 for (it = list.begin(); it != list.end(); ++it ) {
588 ints[i] = (*it).data("uid").toInt(); 612 ints[i] = (*it).data("uid").toInt();
589 i++; 613 i++;
590 } 614 }
591 return ints; 615 return ints;
592} 616}
593 617
594QArray<int> OTodoAccessBackendSQL::matchRegexp( const QRegExp &r ) const 618QArray<int> OTodoAccessBackendSQL::matchRegexp( const QRegExp &r ) const
595{ 619{
596 620
597#warning OTodoAccessBackendSQL::matchRegexp() not implemented !! 621#warning OTodoAccessBackendSQL::matchRegexp() not implemented !!
598 622
599#if 0 623#if 0
600 624
601 Copied from xml-backend by not adapted to sql (eilers) 625 Copied from xml-backend by not adapted to sql (eilers)
602 626
603 QArray<int> m_currentQuery( m_events.count() ); 627 QArray<int> m_currentQuery( m_events.count() );
604 uint arraycounter = 0; 628 uint arraycounter = 0;
605 629
606 630
607 631
608 QMap<int, OTodo>::ConstIterator it; 632 QMap<int, OTodo>::ConstIterator it;
609 for (it = m_events.begin(); it != m_events.end(); ++it ) { 633 for (it = m_events.begin(); it != m_events.end(); ++it ) {
610 if ( it.data().match( r ) ) 634 if ( it.data().match( r ) )
611 m_currentQuery[arraycounter++] = it.data().uid(); 635 m_currentQuery[arraycounter++] = it.data().uid();
612 636
613 } 637 }
614 // Shrink to fit.. 638 // Shrink to fit..
615 m_currentQuery.resize(arraycounter); 639 m_currentQuery.resize(arraycounter);
616 640
617 return m_currentQuery; 641 return m_currentQuery;
618#endif 642#endif
619 QArray<int> empty; 643 QArray<int> empty;
620 return empty; 644 return empty;
621} 645}
622QBitArray OTodoAccessBackendSQL::supports()const { 646QBitArray OTodoAccessBackendSQL::supports()const {
623 647
624 QBitArray ar( OTodo::CompletedDate + 1 ); 648 return sup();
625 ar.fill( true );
626 ar[OTodo::CrossReference] = false;
627 ar[OTodo::State ] = false;
628 ar[OTodo::Reminders] = false;
629 ar[OTodo::Notifiers] = false;
630 ar[OTodo::Maintainer] = false;
631
632 return ar;
633} 649}
634 650
635QBitArray OTodoAccessBackendSQL::sup() { 651QBitArray OTodoAccessBackendSQL::sup() const{
636 652
637 QBitArray ar( OTodo::CompletedDate + 1 ); 653 QBitArray ar( OTodo::CompletedDate + 1 );
638 ar.fill( true ); 654 ar.fill( true );
639 ar[OTodo::CrossReference] = false; 655 ar[OTodo::CrossReference] = false;
640 ar[OTodo::State ] = false; 656 ar[OTodo::State ] = false;
641 ar[OTodo::Reminders] = false; 657 ar[OTodo::Reminders] = false;
642 ar[OTodo::Notifiers] = false; 658 ar[OTodo::Notifiers] = false;
643 ar[OTodo::Maintainer] = false; 659 ar[OTodo::Maintainer] = false;
644 660
645 return ar; 661 return ar;
646} 662}
647 663
648void OTodoAccessBackendSQL::removeAllCompleted(){ 664void OTodoAccessBackendSQL::removeAllCompleted(){
649#warning OTodoAccessBackendSQL::removeAllCompleted() not implemented !! 665#warning OTodoAccessBackendSQL::removeAllCompleted() not implemented !!
650 666
651} 667}
diff --git a/libopie/pim/otodoaccesssql.h b/libopie/pim/otodoaccesssql.h
index 77d8b77..1c55567 100644
--- a/libopie/pim/otodoaccesssql.h
+++ b/libopie/pim/otodoaccesssql.h
@@ -1,56 +1,56 @@
1#ifndef OPIE_PIM_ACCESS_SQL_H 1#ifndef OPIE_PIM_ACCESS_SQL_H
2#define OPIE_PIM_ACCESS_SQL_H 2#define OPIE_PIM_ACCESS_SQL_H
3 3
4#include <qasciidict.h> 4#include <qasciidict.h>
5 5
6#include "otodoaccessbackend.h" 6#include "otodoaccessbackend.h"
7 7
8class OSQLDriver; 8class OSQLDriver;
9class OSQLResult; 9class OSQLResult;
10class OSQLResultItem; 10class OSQLResultItem;
11class OTodoAccessBackendSQL : public OTodoAccessBackend { 11class OTodoAccessBackendSQL : public OTodoAccessBackend {
12public: 12public:
13 OTodoAccessBackendSQL( const QString& file ); 13 OTodoAccessBackendSQL( const QString& file );
14 ~OTodoAccessBackendSQL(); 14 ~OTodoAccessBackendSQL();
15 15
16 bool load(); 16 bool load();
17 bool reload(); 17 bool reload();
18 bool save(); 18 bool save();
19 QArray<int> allRecords()const; 19 QArray<int> allRecords()const;
20 20
21 QArray<int> queryByExample( const OTodo& t, int settings, const QDateTime& d = QDateTime() ); 21 QArray<int> queryByExample( const OTodo& t, int settings, const QDateTime& d = QDateTime() );
22 OTodo find(int uid)const; 22 OTodo find(int uid)const;
23 OTodo find(int uid, const QArray<int>&, uint cur, Frontend::CacheDirection )const; 23 OTodo find(int uid, const QArray<int>&, uint cur, Frontend::CacheDirection )const;
24 void clear(); 24 void clear();
25 bool add( const OTodo& t ); 25 bool add( const OTodo& t );
26 bool remove( int uid ); 26 bool remove( int uid );
27 bool replace( const OTodo& t ); 27 bool replace( const OTodo& t );
28 28
29 QArray<int> overDue(); 29 QArray<int> overDue();
30 QArray<int> effectiveToDos( const QDate& start, 30 QArray<int> effectiveToDos( const QDate& start,
31 const QDate& end, bool includeNoDates ); 31 const QDate& end, bool includeNoDates );
32 QArray<int> sorted(bool asc, int sortOrder, int sortFilter, int cat ); 32 QArray<int> sorted(bool asc, int sortOrder, int sortFilter, int cat );
33 33
34 QBitArray supports()const; 34 QBitArray supports()const;
35 QArray<int> matchRegexp( const QRegExp &r ) const; 35 QArray<int> matchRegexp( const QRegExp &r ) const;
36 void removeAllCompleted(); 36 void removeAllCompleted();
37 37
38 38
39private: 39private:
40 void update()const; 40 void update()const;
41 void fillDict(); 41 void fillDict();
42 inline bool date( QDate& date, const QString& )const; 42 inline bool date( QDate& date, const QString& )const;
43 inline OTodo todo( const OSQLResult& )const; 43 inline OTodo todo( const OSQLResult& )const;
44 inline OTodo todo( OSQLResultItem& )const; 44 inline OTodo todo( OSQLResultItem& )const;
45 inline QArray<int> uids( const OSQLResult& )const; 45 inline QArray<int> uids( const OSQLResult& )const;
46 OTodo todo( int uid )const; 46 OTodo todo( int uid )const;
47 QBitArray sup(); 47 QBitArray sup() const;
48 48
49 QAsciiDict<int> m_dict; 49 QAsciiDict<int> m_dict;
50 OSQLDriver* m_driver; 50 OSQLDriver* m_driver;
51 QArray<int> m_uids; 51 QArray<int> m_uids;
52 bool m_dirty : 1; 52 bool m_dirty : 1;
53}; 53};
54 54
55 55
56#endif 56#endif
diff --git a/libopie/pim/otodoaccessxml.cpp b/libopie/pim/otodoaccessxml.cpp
index f688735..4a5cb33 100644
--- a/libopie/pim/otodoaccessxml.cpp
+++ b/libopie/pim/otodoaccessxml.cpp
@@ -59,818 +59,818 @@ char *strstrlen(const char *haystack, int hLen, const char* needle, int nLen)
59 if (hsearch >= haystack + hLen) 59 if (hsearch >= haystack + hLen)
60 return (0); 60 return (0);
61 } while (haystackChar != needleChar); 61 } while (haystackChar != needleChar);
62 } while (strncmp(hsearch, needle, QMIN(hLen - (hsearch - haystack), nLen)) != 0); 62 } while (strncmp(hsearch, needle, QMIN(hLen - (hsearch - haystack), nLen)) != 0);
63 hsearch--; 63 hsearch--;
64 } 64 }
65 return ((char *)hsearch); 65 return ((char *)hsearch);
66} 66}
67} 67}
68 68
69 69
70OTodoAccessXML::OTodoAccessXML( const QString& appName, 70OTodoAccessXML::OTodoAccessXML( const QString& appName,
71 const QString& fileName ) 71 const QString& fileName )
72 : OTodoAccessBackend(), m_app( appName ), m_opened( false ), m_changed( false ) 72 : OTodoAccessBackend(), m_app( appName ), m_opened( false ), m_changed( false )
73{ 73{
74 if (!fileName.isEmpty() ) 74 if (!fileName.isEmpty() )
75 m_file = fileName; 75 m_file = fileName;
76 else 76 else
77 m_file = Global::applicationFileName( "todolist", "todolist.xml" ); 77 m_file = Global::applicationFileName( "todolist", "todolist.xml" );
78} 78}
79OTodoAccessXML::~OTodoAccessXML() { 79OTodoAccessXML::~OTodoAccessXML() {
80 80
81} 81}
82bool OTodoAccessXML::load() { 82bool OTodoAccessXML::load() {
83 rec = 0; 83 rec = 0;
84 m_opened = true; 84 m_opened = true;
85 m_changed = false; 85 m_changed = false;
86 /* initialize dict */ 86 /* initialize dict */
87 /* 87 /*
88 * UPDATE dict if you change anything!!! 88 * UPDATE dict if you change anything!!!
89 */ 89 */
90 QAsciiDict<int> dict(26); 90 QAsciiDict<int> dict(26);
91 dict.setAutoDelete( TRUE ); 91 dict.setAutoDelete( TRUE );
92 dict.insert("Categories" , new int(OTodo::Category) ); 92 dict.insert("Categories" , new int(OTodo::Category) );
93 dict.insert("Uid" , new int(OTodo::Uid) ); 93 dict.insert("Uid" , new int(OTodo::Uid) );
94 dict.insert("HasDate" , new int(OTodo::HasDate) ); 94 dict.insert("HasDate" , new int(OTodo::HasDate) );
95 dict.insert("Completed" , new int(OTodo::Completed) ); 95 dict.insert("Completed" , new int(OTodo::Completed) );
96 dict.insert("Description" , new int(OTodo::Description) ); 96 dict.insert("Description" , new int(OTodo::Description) );
97 dict.insert("Summary" , new int(OTodo::Summary) ); 97 dict.insert("Summary" , new int(OTodo::Summary) );
98 dict.insert("Priority" , new int(OTodo::Priority) ); 98 dict.insert("Priority" , new int(OTodo::Priority) );
99 dict.insert("DateDay" , new int(OTodo::DateDay) ); 99 dict.insert("DateDay" , new int(OTodo::DateDay) );
100 dict.insert("DateMonth" , new int(OTodo::DateMonth) ); 100 dict.insert("DateMonth" , new int(OTodo::DateMonth) );
101 dict.insert("DateYear" , new int(OTodo::DateYear) ); 101 dict.insert("DateYear" , new int(OTodo::DateYear) );
102 dict.insert("Progress" , new int(OTodo::Progress) ); 102 dict.insert("Progress" , new int(OTodo::Progress) );
103 dict.insert("CompletedDate", new int(OTodo::CompletedDate) ); 103 dict.insert("CompletedDate", new int(OTodo::CompletedDate) );
104 dict.insert("StartDate", new int(OTodo::StartDate) ); 104 dict.insert("StartDate", new int(OTodo::StartDate) );
105 dict.insert("CrossReference", new int(OTodo::CrossReference) ); 105 dict.insert("CrossReference", new int(OTodo::CrossReference) );
106 dict.insert("State", new int(OTodo::State) ); 106 dict.insert("State", new int(OTodo::State) );
107 dict.insert("Alarms", new int(OTodo::Alarms) ); 107 dict.insert("Alarms", new int(OTodo::Alarms) );
108 dict.insert("Reminders", new int(OTodo::Reminders) ); 108 dict.insert("Reminders", new int(OTodo::Reminders) );
109 dict.insert("Notifiers", new int(OTodo::Notifiers) ); 109 dict.insert("Notifiers", new int(OTodo::Notifiers) );
110 dict.insert("Maintainer", new int(OTodo::Maintainer) ); 110 dict.insert("Maintainer", new int(OTodo::Maintainer) );
111 dict.insert("rtype", new int(FRType) ); 111 dict.insert("rtype", new int(FRType) );
112 dict.insert("rweekdays", new int(FRWeekdays) ); 112 dict.insert("rweekdays", new int(FRWeekdays) );
113 dict.insert("rposition", new int(FRPosition) ); 113 dict.insert("rposition", new int(FRPosition) );
114 dict.insert("rfreq", new int(FRFreq) ); 114 dict.insert("rfreq", new int(FRFreq) );
115 dict.insert("start", new int(FRStart) ); 115 dict.insert("start", new int(FRStart) );
116 dict.insert("rhasenddate", new int(FRHasEndDate) ); 116 dict.insert("rhasenddate", new int(FRHasEndDate) );
117 dict.insert("enddt", new int(FREndDate) ); 117 dict.insert("enddt", new int(FREndDate) );
118 118
119 // here the custom XML parser from TT it's GPL 119 // here the custom XML parser from TT it's GPL
120 // but we want to push OpiePIM... to TT..... 120 // but we want to push OpiePIM... to TT.....
121 // mmap part from zecke :) 121 // mmap part from zecke :)
122 int fd = ::open( QFile::encodeName(m_file).data(), O_RDONLY ); 122 int fd = ::open( QFile::encodeName(m_file).data(), O_RDONLY );
123 struct stat attribut; 123 struct stat attribut;
124 if ( fd < 0 ) return false; 124 if ( fd < 0 ) return false;
125 125
126 if ( fstat(fd, &attribut ) == -1 ) { 126 if ( fstat(fd, &attribut ) == -1 ) {
127 ::close( fd ); 127 ::close( fd );
128 return false; 128 return false;
129 } 129 }
130 void* map_addr = ::mmap(NULL, attribut.st_size, PROT_READ, MAP_SHARED, fd, 0 ); 130 void* map_addr = ::mmap(NULL, attribut.st_size, PROT_READ, MAP_SHARED, fd, 0 );
131 if ( map_addr == ( (caddr_t)-1) ) { 131 if ( map_addr == ( (caddr_t)-1) ) {
132 ::close(fd ); 132 ::close(fd );
133 return false; 133 return false;
134 } 134 }
135 /* advise the kernel who we want to read it */ 135 /* advise the kernel who we want to read it */
136 ::madvise( map_addr, attribut.st_size, MADV_SEQUENTIAL ); 136 ::madvise( map_addr, attribut.st_size, MADV_SEQUENTIAL );
137 /* we do not the file any more */ 137 /* we do not the file any more */
138 ::close( fd ); 138 ::close( fd );
139 139
140 char* dt = (char*)map_addr; 140 char* dt = (char*)map_addr;
141 int len = attribut.st_size; 141 int len = attribut.st_size;
142 int i = 0; 142 int i = 0;
143 char *point; 143 char *point;
144 const char* collectionString = "<Task "; 144 const char* collectionString = "<Task ";
145 int strLen = strlen(collectionString); 145 int strLen = strlen(collectionString);
146 while ( ( point = strstrlen( dt+i, len -i, collectionString, strLen ) ) != 0l ) { 146 while ( ( point = strstrlen( dt+i, len -i, collectionString, strLen ) ) != 0l ) {
147 i = point -dt; 147 i = point -dt;
148 i+= strLen; 148 i+= strLen;
149 qWarning("Found a start at %d %d", i, (point-dt) ); 149 qWarning("Found a start at %d %d", i, (point-dt) );
150 150
151 OTodo ev; 151 OTodo ev;
152 m_year = m_month = m_day = 0; 152 m_year = m_month = m_day = 0;
153 153
154 while ( TRUE ) { 154 while ( TRUE ) {
155 while ( i < len && (dt[i] == ' ' || dt[i] == '\n' || dt[i] == '\r') ) 155 while ( i < len && (dt[i] == ' ' || dt[i] == '\n' || dt[i] == '\r') )
156 ++i; 156 ++i;
157 if ( i >= len-2 || (dt[i] == '/' && dt[i+1] == '>') ) 157 if ( i >= len-2 || (dt[i] == '/' && dt[i+1] == '>') )
158 break; 158 break;
159 159
160 // we have another attribute, read it. 160 // we have another attribute, read it.
161 int j = i; 161 int j = i;
162 while ( j < len && dt[j] != '=' ) 162 while ( j < len && dt[j] != '=' )
163 ++j; 163 ++j;
164 QCString attr( dt+i, j-i+1); 164 QCString attr( dt+i, j-i+1);
165 165
166 i = ++j; // skip = 166 i = ++j; // skip =
167 167
168 // find the start of quotes 168 // find the start of quotes
169 while ( i < len && dt[i] != '"' ) 169 while ( i < len && dt[i] != '"' )
170 ++i; 170 ++i;
171 j = ++i; 171 j = ++i;
172 172
173 bool haveUtf = FALSE; 173 bool haveUtf = FALSE;
174 bool haveEnt = FALSE; 174 bool haveEnt = FALSE;
175 while ( j < len && dt[j] != '"' ) { 175 while ( j < len && dt[j] != '"' ) {
176 if ( ((unsigned char)dt[j]) > 0x7f ) 176 if ( ((unsigned char)dt[j]) > 0x7f )
177 haveUtf = TRUE; 177 haveUtf = TRUE;
178 if ( dt[j] == '&' ) 178 if ( dt[j] == '&' )
179 haveEnt = TRUE; 179 haveEnt = TRUE;
180 ++j; 180 ++j;
181 } 181 }
182 if ( i == j ) { 182 if ( i == j ) {
183 // empty value 183 // empty value
184 i = j + 1; 184 i = j + 1;
185 continue; 185 continue;
186 } 186 }
187 187
188 QCString value( dt+i, j-i+1 ); 188 QCString value( dt+i, j-i+1 );
189 i = j + 1; 189 i = j + 1;
190 190
191 QString str = (haveUtf ? QString::fromUtf8( value ) 191 QString str = (haveUtf ? QString::fromUtf8( value )
192 : QString::fromLatin1( value ) ); 192 : QString::fromLatin1( value ) );
193 if ( haveEnt ) 193 if ( haveEnt )
194 str = Qtopia::plainString( str ); 194 str = Qtopia::plainString( str );
195 195
196 /* 196 /*
197 * add key + value 197 * add key + value
198 */ 198 */
199 todo( &dict, ev, attr, str ); 199 todo( &dict, ev, attr, str );
200 200
201 } 201 }
202 /* 202 /*
203 * now add it 203 * now add it
204 */ 204 */
205 qWarning("End at %d", i ); 205 qWarning("End at %d", i );
206 if (m_events.contains( ev.uid() ) || ev.uid() == 0) { 206 if (m_events.contains( ev.uid() ) || ev.uid() == 0) {
207 ev.setUid( 1 ); 207 ev.setUid( 1 );
208 m_changed = true; 208 m_changed = true;
209 } 209 }
210 if ( ev.hasDueDate() ) { 210 if ( ev.hasDueDate() ) {
211 ev.setDueDate( QDate(m_year, m_month, m_day) ); 211 ev.setDueDate( QDate(m_year, m_month, m_day) );
212 } 212 }
213 if ( rec && rec->doesRecur() ) { 213 if ( rec && rec->doesRecur() ) {
214 OTimeZone utc = OTimeZone::utc(); 214 OTimeZone utc = OTimeZone::utc();
215 ORecur recu( *rec ); // call copy c'tor 215 ORecur recu( *rec ); // call copy c'tor
216 recu.setEndDate( utc.fromUTCDateTime( rp_end ).date() ); 216 recu.setEndDate( utc.fromUTCDateTime( rp_end ).date() );
217 recu.setStart( ev.dueDate() ); 217 recu.setStart( ev.dueDate() );
218 ev.setRecurrence( recu ); 218 ev.setRecurrence( recu );
219 } 219 }
220 m_events.insert(ev.uid(), ev ); 220 m_events.insert(ev.uid(), ev );
221 m_year = m_month = m_day = -1; 221 m_year = m_month = m_day = -1;
222 delete rec; 222 delete rec;
223 rec = 0; 223 rec = 0;
224 } 224 }
225 225
226 munmap(map_addr, attribut.st_size ); 226 munmap(map_addr, attribut.st_size );
227 227
228 qWarning("counts %d records loaded!", m_events.count() ); 228 qWarning("counts %d records loaded!", m_events.count() );
229 return true; 229 return true;
230} 230}
231bool OTodoAccessXML::reload() { 231bool OTodoAccessXML::reload() {
232 m_events.clear(); 232 m_events.clear();
233 return load(); 233 return load();
234} 234}
235bool OTodoAccessXML::save() { 235bool OTodoAccessXML::save() {
236// qWarning("saving"); 236// qWarning("saving");
237 if (!m_opened || !m_changed ) { 237 if (!m_opened || !m_changed ) {
238// qWarning("not saving"); 238// qWarning("not saving");
239 return true; 239 return true;
240 } 240 }
241 QString strNewFile = m_file + ".new"; 241 QString strNewFile = m_file + ".new";
242 QFile f( strNewFile ); 242 QFile f( strNewFile );
243 if (!f.open( IO_WriteOnly|IO_Raw ) ) 243 if (!f.open( IO_WriteOnly|IO_Raw ) )
244 return false; 244 return false;
245 245
246 int written; 246 int written;
247 QString out; 247 QString out;
248 out = "<!DOCTYPE Tasks>\n<Tasks>\n"; 248 out = "<!DOCTYPE Tasks>\n<Tasks>\n";
249 249
250 // for all todos 250 // for all todos
251 QMap<int, OTodo>::Iterator it; 251 QMap<int, OTodo>::Iterator it;
252 for (it = m_events.begin(); it != m_events.end(); ++it ) { 252 for (it = m_events.begin(); it != m_events.end(); ++it ) {
253 out+= "<Task " + toString( (*it) ) + " />\n"; 253 out+= "<Task " + toString( (*it) ) + " />\n";
254 QCString cstr = out.utf8(); 254 QCString cstr = out.utf8();
255 written = f.writeBlock( cstr.data(), cstr.length() ); 255 written = f.writeBlock( cstr.data(), cstr.length() );
256 256
257 /* less written then we wanted */ 257 /* less written then we wanted */
258 if ( written != (int)cstr.length() ) { 258 if ( written != (int)cstr.length() ) {
259 f.close(); 259 f.close();
260 QFile::remove( strNewFile ); 260 QFile::remove( strNewFile );
261 return false; 261 return false;
262 } 262 }
263 out = QString::null; 263 out = QString::null;
264 } 264 }
265 265
266 out += "</Tasks>"; 266 out += "</Tasks>";
267 QCString cstr = out.utf8(); 267 QCString cstr = out.utf8();
268 written = f.writeBlock( cstr.data(), cstr.length() ); 268 written = f.writeBlock( cstr.data(), cstr.length() );
269 269
270 if ( written != (int)cstr.length() ) { 270 if ( written != (int)cstr.length() ) {
271 f.close(); 271 f.close();
272 QFile::remove( strNewFile ); 272 QFile::remove( strNewFile );
273 return false; 273 return false;
274 } 274 }
275 /* flush before renaming */ 275 /* flush before renaming */
276 f.close(); 276 f.close();
277 277
278 if( ::rename( strNewFile.latin1(), m_file.latin1() ) < 0 ) { 278 if( ::rename( strNewFile.latin1(), m_file.latin1() ) < 0 ) {
279// qWarning("error renaming"); 279// qWarning("error renaming");
280 QFile::remove( strNewFile ); 280 QFile::remove( strNewFile );
281 } 281 }
282 282
283 m_changed = false; 283 m_changed = false;
284 return true; 284 return true;
285} 285}
286QArray<int> OTodoAccessXML::allRecords()const { 286QArray<int> OTodoAccessXML::allRecords()const {
287 QArray<int> ids( m_events.count() ); 287 QArray<int> ids( m_events.count() );
288 QMap<int, OTodo>::ConstIterator it; 288 QMap<int, OTodo>::ConstIterator it;
289 int i = 0; 289 int i = 0;
290 290
291 for ( it = m_events.begin(); it != m_events.end(); ++it ) { 291 for ( it = m_events.begin(); it != m_events.end(); ++it ) {
292 ids[i] = it.key(); 292 ids[i] = it.key();
293 i++; 293 i++;
294 } 294 }
295 return ids; 295 return ids;
296} 296}
297QArray<int> OTodoAccessXML::queryByExample( const OTodo&, int, const QDateTime& ) { 297QArray<int> OTodoAccessXML::queryByExample( const OTodo&, int, const QDateTime& ) {
298 QArray<int> ids(0); 298 QArray<int> ids(0);
299 return ids; 299 return ids;
300} 300}
301OTodo OTodoAccessXML::find( int uid )const { 301OTodo OTodoAccessXML::find( int uid )const {
302 OTodo todo; 302 OTodo todo;
303 todo.setUid( 0 ); // isEmpty() 303 todo.setUid( 0 ); // isEmpty()
304 QMap<int, OTodo>::ConstIterator it = m_events.find( uid ); 304 QMap<int, OTodo>::ConstIterator it = m_events.find( uid );
305 if ( it != m_events.end() ) 305 if ( it != m_events.end() )
306 todo = it.data(); 306 todo = it.data();
307 307
308 return todo; 308 return todo;
309} 309}
310void OTodoAccessXML::clear() { 310void OTodoAccessXML::clear() {
311 if (m_opened ) 311 if (m_opened )
312 m_changed = true; 312 m_changed = true;
313 313
314 m_events.clear(); 314 m_events.clear();
315} 315}
316bool OTodoAccessXML::add( const OTodo& todo ) { 316bool OTodoAccessXML::add( const OTodo& todo ) {
317// qWarning("add"); 317// qWarning("add");
318 m_changed = true; 318 m_changed = true;
319 m_events.insert( todo.uid(), todo ); 319 m_events.insert( todo.uid(), todo );
320 320
321 return true; 321 return true;
322} 322}
323bool OTodoAccessXML::remove( int uid ) { 323bool OTodoAccessXML::remove( int uid ) {
324 m_changed = true; 324 m_changed = true;
325 m_events.remove( uid ); 325 m_events.remove( uid );
326 326
327 return true; 327 return true;
328} 328}
329bool OTodoAccessXML::replace( const OTodo& todo) { 329bool OTodoAccessXML::replace( const OTodo& todo) {
330 m_changed = true; 330 m_changed = true;
331 m_events.replace( todo.uid(), todo ); 331 m_events.replace( todo.uid(), todo );
332 332
333 return true; 333 return true;
334} 334}
335QArray<int> OTodoAccessXML::effectiveToDos( const QDate& start, 335QArray<int> OTodoAccessXML::effectiveToDos( const QDate& start,
336 const QDate& end, 336 const QDate& end,
337 bool includeNoDates ) { 337 bool includeNoDates ) {
338 QArray<int> ids( m_events.count() ); 338 QArray<int> ids( m_events.count() );
339 QMap<int, OTodo>::Iterator it; 339 QMap<int, OTodo>::Iterator it;
340 340
341 int i = 0; 341 int i = 0;
342 for ( it = m_events.begin(); it != m_events.end(); ++it ) { 342 for ( it = m_events.begin(); it != m_events.end(); ++it ) {
343 if ( !it.data().hasDueDate() ) { 343 if ( !it.data().hasDueDate() ) {
344 if ( includeNoDates ) { 344 if ( includeNoDates ) {
345 ids[i] = it.key(); 345 ids[i] = it.key();
346 i++; 346 i++;
347 } 347 }
348 }else if ( it.data().dueDate() >= start && 348 }else if ( it.data().dueDate() >= start &&
349 it.data().dueDate() <= end ) { 349 it.data().dueDate() <= end ) {
350 ids[i] = it.key(); 350 ids[i] = it.key();
351 i++; 351 i++;
352 } 352 }
353 } 353 }
354 ids.resize( i ); 354 ids.resize( i );
355 return ids; 355 return ids;
356} 356}
357QArray<int> OTodoAccessXML::overDue() { 357QArray<int> OTodoAccessXML::overDue() {
358 QArray<int> ids( m_events.count() ); 358 QArray<int> ids( m_events.count() );
359 int i = 0; 359 int i = 0;
360 360
361 QMap<int, OTodo>::Iterator it; 361 QMap<int, OTodo>::Iterator it;
362 for ( it = m_events.begin(); it != m_events.end(); ++it ) { 362 for ( it = m_events.begin(); it != m_events.end(); ++it ) {
363 if ( it.data().isOverdue() ) { 363 if ( it.data().isOverdue() ) {
364 ids[i] = it.key(); 364 ids[i] = it.key();
365 i++; 365 i++;
366 } 366 }
367 } 367 }
368 ids.resize( i ); 368 ids.resize( i );
369 return ids; 369 return ids;
370} 370}
371 371
372 372
373/* private */ 373/* private */
374void OTodoAccessXML::todo( QAsciiDict<int>* dict, OTodo& ev, 374void OTodoAccessXML::todo( QAsciiDict<int>* dict, OTodo& ev,
375 const QCString& attr, const QString& val) { 375 const QCString& attr, const QString& val) {
376// qWarning("parse to do from XMLElement" ); 376// qWarning("parse to do from XMLElement" );
377 377
378 int *find=0; 378 int *find=0;
379 379
380 find = (*dict)[ attr.data() ]; 380 find = (*dict)[ attr.data() ];
381 if (!find ) { 381 if (!find ) {
382// qWarning("Unknown option" + it.key() ); 382// qWarning("Unknown option" + it.key() );
383 ev.setCustomField( attr, val ); 383 ev.setCustomField( attr, val );
384 return; 384 return;
385 } 385 }
386 386
387 switch( *find ) { 387 switch( *find ) {
388 case OTodo::Uid: 388 case OTodo::Uid:
389 ev.setUid( val.toInt() ); 389 ev.setUid( val.toInt() );
390 break; 390 break;
391 case OTodo::Category: 391 case OTodo::Category:
392 ev.setCategories( ev.idsFromString( val ) ); 392 ev.setCategories( ev.idsFromString( val ) );
393 break; 393 break;
394 case OTodo::HasDate: 394 case OTodo::HasDate:
395 ev.setHasDueDate( val.toInt() ); 395 ev.setHasDueDate( val.toInt() );
396 break; 396 break;
397 case OTodo::Completed: 397 case OTodo::Completed:
398 ev.setCompleted( val.toInt() ); 398 ev.setCompleted( val.toInt() );
399 break; 399 break;
400 case OTodo::Description: 400 case OTodo::Description:
401 ev.setDescription( val ); 401 ev.setDescription( val );
402 break; 402 break;
403 case OTodo::Summary: 403 case OTodo::Summary:
404 ev.setSummary( val ); 404 ev.setSummary( val );
405 break; 405 break;
406 case OTodo::Priority: 406 case OTodo::Priority:
407 ev.setPriority( val.toInt() ); 407 ev.setPriority( val.toInt() );
408 break; 408 break;
409 case OTodo::DateDay: 409 case OTodo::DateDay:
410 m_day = val.toInt(); 410 m_day = val.toInt();
411 break; 411 break;
412 case OTodo::DateMonth: 412 case OTodo::DateMonth:
413 m_month = val.toInt(); 413 m_month = val.toInt();
414 break; 414 break;
415 case OTodo::DateYear: 415 case OTodo::DateYear:
416 m_year = val.toInt(); 416 m_year = val.toInt();
417 break; 417 break;
418 case OTodo::Progress: 418 case OTodo::Progress:
419 ev.setProgress( val.toInt() ); 419 ev.setProgress( val.toInt() );
420 break; 420 break;
421 case OTodo::CompletedDate: 421 case OTodo::CompletedDate:
422 ev.setCompletedDate( OConversion::dateFromString( val ) ); 422 ev.setCompletedDate( OConversion::dateFromString( val ) );
423 break; 423 break;
424 case OTodo::StartDate: 424 case OTodo::StartDate:
425 ev.setStartDate( OConversion::dateFromString( val ) ); 425 ev.setStartDate( OConversion::dateFromString( val ) );
426 break; 426 break;
427 case OTodo::State: 427 case OTodo::State:
428 ev.setState( val.toInt() ); 428 ev.setState( val.toInt() );
429 break; 429 break;
430 case OTodo::Alarms:{ 430 case OTodo::Alarms:{
431 OPimNotifyManager &manager = ev.notifiers(); 431 OPimNotifyManager &manager = ev.notifiers();
432 QStringList als = QStringList::split(";", val ); 432 QStringList als = QStringList::split(";", val );
433 for (QStringList::Iterator it = als.begin(); it != als.end(); ++it ) { 433 for (QStringList::Iterator it = als.begin(); it != als.end(); ++it ) {
434 QStringList alarm = QStringList::split(":", (*it), TRUE ); // allow empty 434 QStringList alarm = QStringList::split(":", (*it), TRUE ); // allow empty
435 qWarning("alarm: %s", alarm.join("___").latin1() ); 435 qWarning("alarm: %s", alarm.join("___").latin1() );
436 qWarning("alarm[0]: %s %s", alarm[0].latin1(), OConversion::dateTimeFromString( alarm[0] ).toString().latin1() ); 436 qWarning("alarm[0]: %s %s", alarm[0].latin1(), OConversion::dateTimeFromString( alarm[0] ).toString().latin1() );
437 OPimAlarm al( alarm[2].toInt(), OConversion::dateTimeFromString( alarm[0] ), alarm[1].toInt() ); 437 OPimAlarm al( alarm[2].toInt(), OConversion::dateTimeFromString( alarm[0] ), alarm[1].toInt() );
438 manager.add( al ); 438 manager.add( al );
439 } 439 }
440 } 440 }
441 break; 441 break;
442 case OTodo::Reminders:{ 442 case OTodo::Reminders:{
443 OPimNotifyManager &manager = ev.notifiers(); 443 OPimNotifyManager &manager = ev.notifiers();
444 QStringList rems = QStringList::split(";", val ); 444 QStringList rems = QStringList::split(";", val );
445 for (QStringList::Iterator it = rems.begin(); it != rems.end(); ++it ) { 445 for (QStringList::Iterator it = rems.begin(); it != rems.end(); ++it ) {
446 OPimReminder rem( (*it).toInt() ); 446 OPimReminder rem( (*it).toInt() );
447 manager.add( rem ); 447 manager.add( rem );
448 } 448 }
449 } 449 }
450 break; 450 break;
451 case OTodo::CrossReference: 451 case OTodo::CrossReference:
452 { 452 {
453 /* 453 /*
454 * A cross refernce looks like 454 * A cross refernce looks like
455 * appname,id;appname,id 455 * appname,id;appname,id
456 * we need to split it up 456 * we need to split it up
457 */ 457 */
458 QStringList refs = QStringList::split(';', val ); 458 QStringList refs = QStringList::split(';', val );
459 QStringList::Iterator strIt; 459 QStringList::Iterator strIt;
460 for (strIt = refs.begin(); strIt != refs.end(); ++strIt ) { 460 for (strIt = refs.begin(); strIt != refs.end(); ++strIt ) {
461 int pos = (*strIt).find(','); 461 int pos = (*strIt).find(',');
462 if ( pos > -1 ) 462 if ( pos > -1 )
463 ; // ev.addRelation( (*strIt).left(pos), (*strIt).mid(pos+1).toInt() ); 463 ; // ev.addRelation( (*strIt).left(pos), (*strIt).mid(pos+1).toInt() );
464 464
465 } 465 }
466 break; 466 break;
467 } 467 }
468 /* Recurrence stuff below + post processing later */ 468 /* Recurrence stuff below + post processing later */
469 case FRType: 469 case FRType:
470 if ( val == "Daily" ) 470 if ( val == "Daily" )
471 recur()->setType( ORecur::Daily ); 471 recur()->setType( ORecur::Daily );
472 else if ( val == "Weekly" ) 472 else if ( val == "Weekly" )
473 recur()->setType( ORecur::Weekly); 473 recur()->setType( ORecur::Weekly);
474 else if ( val == "MonthlyDay" ) 474 else if ( val == "MonthlyDay" )
475 recur()->setType( ORecur::MonthlyDay ); 475 recur()->setType( ORecur::MonthlyDay );
476 else if ( val == "MonthlyDate" ) 476 else if ( val == "MonthlyDate" )
477 recur()->setType( ORecur::MonthlyDate ); 477 recur()->setType( ORecur::MonthlyDate );
478 else if ( val == "Yearly" ) 478 else if ( val == "Yearly" )
479 recur()->setType( ORecur::Yearly ); 479 recur()->setType( ORecur::Yearly );
480 else 480 else
481 recur()->setType( ORecur::NoRepeat ); 481 recur()->setType( ORecur::NoRepeat );
482 break; 482 break;
483 case FRWeekdays: 483 case FRWeekdays:
484 recur()->setDays( val.toInt() ); 484 recur()->setDays( val.toInt() );
485 break; 485 break;
486 case FRPosition: 486 case FRPosition:
487 recur()->setPosition( val.toInt() ); 487 recur()->setPosition( val.toInt() );
488 break; 488 break;
489 case FRFreq: 489 case FRFreq:
490 recur()->setFrequency( val.toInt() ); 490 recur()->setFrequency( val.toInt() );
491 break; 491 break;
492 case FRHasEndDate: 492 case FRHasEndDate:
493 recur()->setHasEndDate( val.toInt() ); 493 recur()->setHasEndDate( val.toInt() );
494 break; 494 break;
495 case FREndDate: { 495 case FREndDate: {
496 rp_end = (time_t) val.toLong(); 496 rp_end = (time_t) val.toLong();
497 break; 497 break;
498 } 498 }
499 default: 499 default:
500 ev.setCustomField( attr, val ); 500 ev.setCustomField( attr, val );
501 break; 501 break;
502 } 502 }
503} 503}
504 504
505// from PalmtopRecord... GPL ### FIXME 505// from PalmtopRecord... GPL ### FIXME
506namespace { 506namespace {
507QString customToXml(const QMap<QString, QString>& customMap ) 507QString customToXml(const QMap<QString, QString>& customMap )
508{ 508{
509 //qWarning(QString("writing custom %1").arg(customMap.count())); 509 //qWarning(QString("writing custom %1").arg(customMap.count()));
510 QString buf(" "); 510 QString buf(" ");
511 for ( QMap<QString, QString>::ConstIterator cit = customMap.begin(); 511 for ( QMap<QString, QString>::ConstIterator cit = customMap.begin();
512 cit != customMap.end(); ++cit) { 512 cit != customMap.end(); ++cit) {
513 // qWarning(".ITEM."); 513 // qWarning(".ITEM.");
514 buf += cit.key(); 514 buf += cit.key();
515 buf += "=\""; 515 buf += "=\"";
516 buf += Qtopia::escapeString(cit.data()); 516 buf += Qtopia::escapeString(cit.data());
517 buf += "\" "; 517 buf += "\" ";
518 } 518 }
519 return buf; 519 return buf;
520} 520}
521 521
522 522
523} 523}
524 524
525QString OTodoAccessXML::toString( const OTodo& ev )const { 525QString OTodoAccessXML::toString( const OTodo& ev )const {
526 QString str; 526 QString str;
527 527
528 str += "Completed=\"" + QString::number( ev.isCompleted() ) + "\" "; 528 str += "Completed=\"" + QString::number( ev.isCompleted() ) + "\" ";
529 str += "HasDate=\"" + QString::number( ev.hasDueDate() ) + "\" "; 529 str += "HasDate=\"" + QString::number( ev.hasDueDate() ) + "\" ";
530 str += "Priority=\"" + QString::number( ev.priority() ) + "\" "; 530 str += "Priority=\"" + QString::number( ev.priority() ) + "\" ";
531 str += "Progress=\"" + QString::number(ev.progress() ) + "\" "; 531 str += "Progress=\"" + QString::number(ev.progress() ) + "\" ";
532 532
533 str += "Categories=\"" + toString( ev.categories() ) + "\" "; 533 str += "Categories=\"" + toString( ev.categories() ) + "\" ";
534 str += "Description=\"" + Qtopia::escapeString( ev.description() ) + "\" "; 534 str += "Description=\"" + Qtopia::escapeString( ev.description() ) + "\" ";
535 str += "Summary=\"" + Qtopia::escapeString( ev.summary() ) + "\" "; 535 str += "Summary=\"" + Qtopia::escapeString( ev.summary() ) + "\" ";
536 536
537 if ( ev.hasDueDate() ) { 537 if ( ev.hasDueDate() ) {
538 str += "DateYear=\"" + QString::number( ev.dueDate().year() ) + "\" "; 538 str += "DateYear=\"" + QString::number( ev.dueDate().year() ) + "\" ";
539 str += "DateMonth=\"" + QString::number( ev.dueDate().month() ) + "\" "; 539 str += "DateMonth=\"" + QString::number( ev.dueDate().month() ) + "\" ";
540 str += "DateDay=\"" + QString::number( ev.dueDate().day() ) + "\" "; 540 str += "DateDay=\"" + QString::number( ev.dueDate().day() ) + "\" ";
541 } 541 }
542// qWarning( "Uid %d", ev.uid() ); 542// qWarning( "Uid %d", ev.uid() );
543 str += "Uid=\"" + QString::number( ev.uid() ) + "\" "; 543 str += "Uid=\"" + QString::number( ev.uid() ) + "\" ";
544 544
545// append the extra options 545// append the extra options
546 /* FIXME Qtopia::Record this is currently not 546 /* FIXME Qtopia::Record this is currently not
547 * possible you can set custom fields 547 * possible you can set custom fields
548 * but don' iterate over the list 548 * but don' iterate over the list
549 * I may do #define private protected 549 * I may do #define private protected
550 * for this case - cough --zecke 550 * for this case - cough --zecke
551 */ 551 */
552 /* 552 /*
553 QMap<QString, QString> extras = ev.extras(); 553 QMap<QString, QString> extras = ev.extras();
554 QMap<QString, QString>::Iterator extIt; 554 QMap<QString, QString>::Iterator extIt;
555 for (extIt = extras.begin(); extIt != extras.end(); ++extIt ) 555 for (extIt = extras.begin(); extIt != extras.end(); ++extIt )
556 str += extIt.key() + "=\"" + extIt.data() + "\" "; 556 str += extIt.key() + "=\"" + extIt.data() + "\" ";
557 */ 557 */
558 // cross refernce 558 // cross refernce
559 if ( ev.hasRecurrence() ) { 559 if ( ev.hasRecurrence() ) {
560 str += ev.recurrence().toString(); 560 str += ev.recurrence().toString();
561 } 561 }
562 if ( ev.hasStartDate() ) 562 if ( ev.hasStartDate() )
563 str += "StartDate=\""+ OConversion::dateToString( ev.startDate() ) +"\" "; 563 str += "StartDate=\""+ OConversion::dateToString( ev.startDate() ) +"\" ";
564 if ( ev.hasCompletedDate() ) 564 if ( ev.hasCompletedDate() )
565 str += "CompletedDate=\""+ OConversion::dateToString( ev.completedDate() ) +"\" "; 565 str += "CompletedDate=\""+ OConversion::dateToString( ev.completedDate() ) +"\" ";
566 if ( ev.hasState() ) 566 if ( ev.hasState() )
567 str += "State=\""+QString::number( ev.state().state() )+"\" "; 567 str += "State=\""+QString::number( ev.state().state() )+"\" ";
568 568
569 /* 569 /*
570 * save reminders and notifiers! 570 * save reminders and notifiers!
571 * DATE_TIME:DURATION:SOUND:NOT_USED_YET;OTHER_DATE_TIME:OTHER:DURATION:SOUND:.... 571 * DATE_TIME:DURATION:SOUND:NOT_USED_YET;OTHER_DATE_TIME:OTHER_DURATION:SOUND:....
572 */ 572 */
573 if ( ev.hasNotifiers() ) { 573 if ( ev.hasNotifiers() ) {
574 OPimNotifyManager manager = ev.notifiers(); 574 OPimNotifyManager manager = ev.notifiers();
575 OPimNotifyManager::Alarms alarms = manager.alarms(); 575 OPimNotifyManager::Alarms alarms = manager.alarms();
576 if (!alarms.isEmpty() ) { 576 if (!alarms.isEmpty() ) {
577 QStringList als; 577 QStringList als;
578 OPimNotifyManager::Alarms::Iterator it = alarms.begin(); 578 OPimNotifyManager::Alarms::Iterator it = alarms.begin();
579 for ( ; it != alarms.end(); ++it ) { 579 for ( ; it != alarms.end(); ++it ) {
580 /* only if time is valid */ 580 /* only if time is valid */
581 if ( (*it).dateTime().isValid() ) { 581 if ( (*it).dateTime().isValid() ) {
582 als << OConversion::dateTimeToString( (*it).dateTime() ) 582 als << OConversion::dateTimeToString( (*it).dateTime() )
583 + ":" + QString::number( (*it).duration() ) 583 + ":" + QString::number( (*it).duration() )
584 + ":" + QString::number( (*it).sound() ) 584 + ":" + QString::number( (*it).sound() )
585 + ":"; 585 + ":";
586 } 586 }
587 } 587 }
588 // now write the list 588 // now write the list
589 qWarning("als: %s", als.join("____________").latin1() ); 589 qWarning("als: %s", als.join("____________").latin1() );
590 str += "Alarms=\""+als.join(";") +"\" "; 590 str += "Alarms=\""+als.join(";") +"\" ";
591 } 591 }
592 592
593 /* 593 /*
594 * now the same for reminders but more easy. We just save the uid of the OEvent. 594 * now the same for reminders but more easy. We just save the uid of the OEvent.
595 */ 595 */
596 OPimNotifyManager::Reminders reminders = manager.reminders(); 596 OPimNotifyManager::Reminders reminders = manager.reminders();
597 if (!reminders.isEmpty() ) { 597 if (!reminders.isEmpty() ) {
598 OPimNotifyManager::Reminders::Iterator it = reminders.begin(); 598 OPimNotifyManager::Reminders::Iterator it = reminders.begin();
599 QStringList records; 599 QStringList records;
600 for ( ; it != reminders.end(); ++it ) { 600 for ( ; it != reminders.end(); ++it ) {
601 records << QString::number( (*it).recordUid() ); 601 records << QString::number( (*it).recordUid() );
602 } 602 }
603 str += "Reminders=\""+ records.join(";") +"\" "; 603 str += "Reminders=\""+ records.join(";") +"\" ";
604 } 604 }
605 } 605 }
606 str += customToXml( ev.toExtraMap() ); 606 str += customToXml( ev.toExtraMap() );
607 607
608 608
609 return str; 609 return str;
610} 610}
611QString OTodoAccessXML::toString( const QArray<int>& ints ) const { 611QString OTodoAccessXML::toString( const QArray<int>& ints ) const {
612 return Qtopia::Record::idsToString( ints ); 612 return Qtopia::Record::idsToString( ints );
613} 613}
614 614
615/* internal class for sorting 615/* internal class for sorting
616 * 616 *
617 * Inspired by todoxmlio.cpp from TT 617 * Inspired by todoxmlio.cpp from TT
618 */ 618 */
619 619
620struct OTodoXMLContainer { 620struct OTodoXMLContainer {
621 OTodo todo; 621 OTodo todo;
622}; 622};
623 623
624namespace { 624namespace {
625 inline QString string( const OTodo& todo) { 625 inline QString string( const OTodo& todo) {
626 return todo.summary().isEmpty() ? 626 return todo.summary().isEmpty() ?
627 todo.description().left(20 ) : 627 todo.description().left(20 ) :
628 todo.summary(); 628 todo.summary();
629 } 629 }
630 inline int completed( const OTodo& todo1, const OTodo& todo2) { 630 inline int completed( const OTodo& todo1, const OTodo& todo2) {
631 int ret = 0; 631 int ret = 0;
632 if ( todo1.isCompleted() ) ret++; 632 if ( todo1.isCompleted() ) ret++;
633 if ( todo2.isCompleted() ) ret--; 633 if ( todo2.isCompleted() ) ret--;
634 return ret; 634 return ret;
635 } 635 }
636 inline int priority( const OTodo& t1, const OTodo& t2) { 636 inline int priority( const OTodo& t1, const OTodo& t2) {
637 return ( t1.priority() - t2.priority() ); 637 return ( t1.priority() - t2.priority() );
638 } 638 }
639 inline int description( const OTodo& t1, const OTodo& t2) { 639 inline int description( const OTodo& t1, const OTodo& t2) {
640 return QString::compare( string(t1), string(t2) ); 640 return QString::compare( string(t1), string(t2) );
641 } 641 }
642 inline int deadline( const OTodo& t1, const OTodo& t2) { 642 inline int deadline( const OTodo& t1, const OTodo& t2) {
643 int ret = 0; 643 int ret = 0;
644 if ( t1.hasDueDate() && 644 if ( t1.hasDueDate() &&
645 t2.hasDueDate() ) 645 t2.hasDueDate() )
646 ret = t2.dueDate().daysTo( t1.dueDate() ); 646 ret = t2.dueDate().daysTo( t1.dueDate() );
647 else if ( t1.hasDueDate() ) 647 else if ( t1.hasDueDate() )
648 ret = -1; 648 ret = -1;
649 else if ( t2.hasDueDate() ) 649 else if ( t2.hasDueDate() )
650 ret = 1; 650 ret = 1;
651 else 651 else
652 ret = 0; 652 ret = 0;
653 653
654 return ret; 654 return ret;
655 } 655 }
656 656
657}; 657};
658 658
659/* 659/*
660 * Returns: 660 * Returns:
661 * 0 if item1 == item2 661 * 0 if item1 == item2
662 * 662 *
663 * non-zero if item1 != item2 663 * non-zero if item1 != item2
664 * 664 *
665 * This function returns int rather than bool so that reimplementations 665 * This function returns int rather than bool so that reimplementations
666 * can return one of three values and use it to sort by: 666 * can return one of three values and use it to sort by:
667 * 667 *
668 * 0 if item1 == item2 668 * 0 if item1 == item2
669 * 669 *
670 * > 0 (positive integer) if item1 > item2 670 * > 0 (positive integer) if item1 > item2
671 * 671 *
672 * < 0 (negative integer) if item1 < item2 672 * < 0 (negative integer) if item1 < item2
673 * 673 *
674 */ 674 */
675class OTodoXMLVector : public QVector<OTodoXMLContainer> { 675class OTodoXMLVector : public QVector<OTodoXMLContainer> {
676public: 676public:
677 OTodoXMLVector(int size, bool asc, int sort) 677 OTodoXMLVector(int size, bool asc, int sort)
678 : QVector<OTodoXMLContainer>( size ) 678 : QVector<OTodoXMLContainer>( size )
679 { 679 {
680 setAutoDelete( true ); 680 setAutoDelete( true );
681 m_asc = asc; 681 m_asc = asc;
682 m_sort = sort; 682 m_sort = sort;
683 } 683 }
684 /* return the summary/description */ 684 /* return the summary/description */
685 QString string( const OTodo& todo) { 685 QString string( const OTodo& todo) {
686 return todo.summary().isEmpty() ? 686 return todo.summary().isEmpty() ?
687 todo.description().left(20 ) : 687 todo.description().left(20 ) :
688 todo.summary(); 688 todo.summary();
689 } 689 }
690 /** 690 /**
691 * we take the sortorder( switch on it ) 691 * we take the sortorder( switch on it )
692 * 692 *
693 */ 693 */
694 int compareItems( Item d1, Item d2 ) { 694 int compareItems( Item d1, Item d2 ) {
695 bool seComp, sePrio, seDesc, seDeadline; 695 bool seComp, sePrio, seDesc, seDeadline;
696 seComp = sePrio = seDeadline = seDesc = false; 696 seComp = sePrio = seDeadline = seDesc = false;
697 int ret =0; 697 int ret =0;
698 OTodoXMLContainer* con1 = (OTodoXMLContainer*)d1; 698 OTodoXMLContainer* con1 = (OTodoXMLContainer*)d1;
699 OTodoXMLContainer* con2 = (OTodoXMLContainer*)d2; 699 OTodoXMLContainer* con2 = (OTodoXMLContainer*)d2;
700 700
701 /* same item */ 701 /* same item */
702 if ( con1->todo.uid() == con2->todo.uid() ) 702 if ( con1->todo.uid() == con2->todo.uid() )
703 return 0; 703 return 0;
704 704
705 switch ( m_sort ) { 705 switch ( m_sort ) {
706 /* completed */ 706 /* completed */
707 case 0: { 707 case 0: {
708 ret = completed( con1->todo, con2->todo ); 708 ret = completed( con1->todo, con2->todo );
709 seComp = TRUE; 709 seComp = TRUE;
710 break; 710 break;
711 } 711 }
712 /* priority */ 712 /* priority */
713 case 1: { 713 case 1: {
714 ret = priority( con1->todo, con2->todo ); 714 ret = priority( con1->todo, con2->todo );
715 sePrio = TRUE; 715 sePrio = TRUE;
716 break; 716 break;
717 } 717 }
718 /* description */ 718 /* description */
719 case 2: { 719 case 2: {
720 ret = description( con1->todo, con2->todo ); 720 ret = description( con1->todo, con2->todo );
721 seDesc = TRUE; 721 seDesc = TRUE;
722 break; 722 break;
723 } 723 }
724 /* deadline */ 724 /* deadline */
725 case 3: { 725 case 3: {
726 ret = deadline( con1->todo, con2->todo ); 726 ret = deadline( con1->todo, con2->todo );
727 seDeadline = TRUE; 727 seDeadline = TRUE;
728 break; 728 break;
729 } 729 }
730 default: 730 default:
731 ret = 0; 731 ret = 0;
732 break; 732 break;
733 }; 733 };
734 /* 734 /*
735 * FIXME do better sorting if the first sort criteria 735 * FIXME do better sorting if the first sort criteria
736 * ret equals 0 start with complete and so on... 736 * ret equals 0 start with complete and so on...
737 */ 737 */
738 738
739 /* twist it we're not ascending*/ 739 /* twist it we're not ascending*/
740 if (!m_asc) 740 if (!m_asc)
741 ret = ret * -1; 741 ret = ret * -1;
742 742
743 if ( ret ) 743 if ( ret )
744 return ret; 744 return ret;
745 745
746 // default did not gave difference let's try it other way around 746 // default did not gave difference let's try it other way around
747 /* 747 /*
748 * General try if already checked if not test 748 * General try if already checked if not test
749 * and return 749 * and return
750 * 1.Completed 750 * 1.Completed
751 * 2.Priority 751 * 2.Priority
752 * 3.Description 752 * 3.Description
753 * 4.DueDate 753 * 4.DueDate
754 */ 754 */
755 if (!seComp ) { 755 if (!seComp ) {
756 if ( (ret = completed( con1->todo, con2->todo ) ) ) { 756 if ( (ret = completed( con1->todo, con2->todo ) ) ) {
757 if (!m_asc ) ret *= -1; 757 if (!m_asc ) ret *= -1;
758 return ret; 758 return ret;
759 } 759 }
760 } 760 }
761 if (!sePrio ) { 761 if (!sePrio ) {
762 if ( (ret = priority( con1->todo, con2->todo ) ) ) { 762 if ( (ret = priority( con1->todo, con2->todo ) ) ) {
763 if (!m_asc ) ret *= -1; 763 if (!m_asc ) ret *= -1;
764 return ret; 764 return ret;
765 } 765 }
766 } 766 }
767 if (!seDesc ) { 767 if (!seDesc ) {
768 if ( (ret = description(con1->todo, con2->todo ) ) ) { 768 if ( (ret = description(con1->todo, con2->todo ) ) ) {
769 if (!m_asc) ret *= -1; 769 if (!m_asc) ret *= -1;
770 return ret; 770 return ret;
771 } 771 }
772 } 772 }
773 if (!seDeadline) { 773 if (!seDeadline) {
774 if ( (ret = deadline( con1->todo, con2->todo ) ) ) { 774 if ( (ret = deadline( con1->todo, con2->todo ) ) ) {
775 if (!m_asc) ret *= -1; 775 if (!m_asc) ret *= -1;
776 return ret; 776 return ret;
777 } 777 }
778 } 778 }
779 779
780 return 0; 780 return 0;
781 } 781 }
782 private: 782 private:
783 bool m_asc; 783 bool m_asc;
784 int m_sort; 784 int m_sort;
785 785
786}; 786};
787 787
788QArray<int> OTodoAccessXML::sorted( bool asc, int sortOrder, 788QArray<int> OTodoAccessXML::sorted( bool asc, int sortOrder,
789 int sortFilter, int cat ) { 789 int sortFilter, int cat ) {
790 OTodoXMLVector vector(m_events.count(), asc,sortOrder ); 790 OTodoXMLVector vector(m_events.count(), asc,sortOrder );
791 QMap<int, OTodo>::Iterator it; 791 QMap<int, OTodo>::Iterator it;
792 int item = 0; 792 int item = 0;
793 793
794 bool bCat = sortFilter & 1 ? true : false; 794 bool bCat = sortFilter & 1 ? true : false;
795 bool bOnly = sortFilter & 2 ? true : false; 795 bool bOnly = sortFilter & 2 ? true : false;
796 bool comp = sortFilter & 4 ? true : false; 796 bool comp = sortFilter & 4 ? true : false;
797 for ( it = m_events.begin(); it != m_events.end(); ++it ) { 797 for ( it = m_events.begin(); it != m_events.end(); ++it ) {
798 798
799 /* show category */ 799 /* show category */
800 /* -1 == unfiled */ 800 /* -1 == unfiled */
801 if ( bCat && cat == -1 ) { 801 if ( bCat && cat == -1 ) {
802 if(!(*it).categories().isEmpty() ) 802 if(!(*it).categories().isEmpty() )
803 continue; 803 continue;
804 }else if ( bCat && cat != 0) 804 }else if ( bCat && cat != 0)
805 if (!(*it).categories().contains( cat ) ) { 805 if (!(*it).categories().contains( cat ) ) {
806 continue; 806 continue;
807 } 807 }
808 /* isOverdue but we should not show overdue - why?*/ 808 /* isOverdue but we should not show overdue - why?*/
809/* if ( (*it).isOverdue() && !bOnly ) { 809/* if ( (*it).isOverdue() && !bOnly ) {
810 qWarning("item is overdue but !bOnly"); 810 qWarning("item is overdue but !bOnly");
811 continue; 811 continue;
812 } 812 }
813*/ 813*/
814 if ( !(*it).isOverdue() && bOnly ) { 814 if ( !(*it).isOverdue() && bOnly ) {
815 continue; 815 continue;
816 } 816 }
817 817
818 if ((*it).isCompleted() && comp ) { 818 if ((*it).isCompleted() && comp ) {
819 continue; 819 continue;
820 } 820 }
821 821
822 822
823 OTodoXMLContainer* con = new OTodoXMLContainer(); 823 OTodoXMLContainer* con = new OTodoXMLContainer();
824 con->todo = (*it); 824 con->todo = (*it);
825 vector.insert(item, con ); 825 vector.insert(item, con );
826 item++; 826 item++;
827 } 827 }
828 vector.resize( item ); 828 vector.resize( item );
829 /* sort it now */ 829 /* sort it now */
830 vector.sort(); 830 vector.sort();
831 /* now get the uids */ 831 /* now get the uids */
832 QArray<int> array( vector.count() ); 832 QArray<int> array( vector.count() );
833 for (uint i= 0; i < vector.count(); i++ ) { 833 for (uint i= 0; i < vector.count(); i++ ) {
834 array[i] = ( vector.at(i) )->todo.uid(); 834 array[i] = ( vector.at(i) )->todo.uid();
835 } 835 }
836 return array; 836 return array;
837}; 837};
838void OTodoAccessXML::removeAllCompleted() { 838void OTodoAccessXML::removeAllCompleted() {
839 QMap<int, OTodo> events = m_events; 839 QMap<int, OTodo> events = m_events;
840 for ( QMap<int, OTodo>::Iterator it = m_events.begin(); it != m_events.end(); ++it ) { 840 for ( QMap<int, OTodo>::Iterator it = m_events.begin(); it != m_events.end(); ++it ) {
841 if ( (*it).isCompleted() ) 841 if ( (*it).isCompleted() )
842 events.remove( it.key() ); 842 events.remove( it.key() );
843 } 843 }
844 m_events = events; 844 m_events = events;
845} 845}
846QBitArray OTodoAccessXML::supports()const { 846QBitArray OTodoAccessXML::supports()const {
847 static QBitArray ar = sup(); 847 static QBitArray ar = sup();
848 return ar; 848 return ar;
849} 849}
850QBitArray OTodoAccessXML::sup() { 850QBitArray OTodoAccessXML::sup() {
851 QBitArray ar( OTodo::CompletedDate +1 ); 851 QBitArray ar( OTodo::CompletedDate +1 );
852 ar.fill( true ); 852 ar.fill( true );
853 ar[OTodo::CrossReference] = false; 853 ar[OTodo::CrossReference] = false;
854 ar[OTodo::State ] = false; 854 ar[OTodo::State ] = false;
855 ar[OTodo::Reminders] = false; 855 ar[OTodo::Reminders] = false;
856 ar[OTodo::Notifiers] = false; 856 ar[OTodo::Notifiers] = false;
857 ar[OTodo::Maintainer] = false; 857 ar[OTodo::Maintainer] = false;
858 858
859 return ar; 859 return ar;
860} 860}
861QArray<int> OTodoAccessXML::matchRegexp( const QRegExp &r ) const 861QArray<int> OTodoAccessXML::matchRegexp( const QRegExp &r ) const
862{ 862{
863 QArray<int> m_currentQuery( m_events.count() ); 863 QArray<int> m_currentQuery( m_events.count() );
864 uint arraycounter = 0; 864 uint arraycounter = 0;
865 865
866 QMap<int, OTodo>::ConstIterator it; 866 QMap<int, OTodo>::ConstIterator it;
867 for (it = m_events.begin(); it != m_events.end(); ++it ) { 867 for (it = m_events.begin(); it != m_events.end(); ++it ) {
868 if ( it.data().match( r ) ) 868 if ( it.data().match( r ) )
869 m_currentQuery[arraycounter++] = it.data().uid(); 869 m_currentQuery[arraycounter++] = it.data().uid();
870 870
871 } 871 }
872 // Shrink to fit.. 872 // Shrink to fit..
873 m_currentQuery.resize(arraycounter); 873 m_currentQuery.resize(arraycounter);
874 874
875 return m_currentQuery; 875 return m_currentQuery;
876} 876}