summaryrefslogtreecommitdiff
path: root/libopie
Unidiff
Diffstat (limited to 'libopie') (more/less context) (ignore whitespace changes)
-rw-r--r--libopie/pim/ocontact.cpp10
-rw-r--r--libopie/pim/oevent.cpp11
-rw-r--r--libopie/pim/oevent.h1
-rw-r--r--libopie/pim/opimrecord.cpp6
-rw-r--r--libopie/pim/opimrecord.h8
-rw-r--r--libopie/pim/otodo.cpp13
-rw-r--r--libopie/pim/otodo.h1
-rw-r--r--libopie/pim/otodoaccessxml.cpp23
8 files changed, 47 insertions, 26 deletions
diff --git a/libopie/pim/ocontact.cpp b/libopie/pim/ocontact.cpp
index a2fb68c..be4ce0a 100644
--- a/libopie/pim/ocontact.cpp
+++ b/libopie/pim/ocontact.cpp
@@ -1,1144 +1,1138 @@
1/********************************************************************** 1/**********************************************************************
2** Copyright (C) 2000-2002 Trolltech AS. All rights reserved. 2** Copyright (C) 2000-2002 Trolltech AS. All rights reserved.
3** Copyright (C) 2002-2003 by Stefan Eilers (eilers.stefan@epost.de) 3** Copyright (C) 2002-2003 by Stefan Eilers (eilers.stefan@epost.de)
4** 4**
5** This file may be distributed and/or modified under the terms of the 5** This file may be distributed and/or modified under the terms of the
6** GNU General Public License version 2 as published by the Free Software 6** GNU General Public License version 2 as published by the Free Software
7** Foundation and appearing in the file LICENSE.GPL included in the 7** Foundation and appearing in the file LICENSE.GPL included in the
8** packaging of this file. 8** packaging of this file.
9** 9**
10** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE 10** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
11** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. 11** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
12** 12**
13** See http://www.trolltech.com/gpl/ for GPL licensing information. 13** See http://www.trolltech.com/gpl/ for GPL licensing information.
14** 14**
15** Contact info@trolltech.com if any conditions of this licensing are 15** Contact info@trolltech.com if any conditions of this licensing are
16** not clear to you. 16** not clear to you.
17** 17**
18**********************************************************************/ 18**********************************************************************/
19 19
20#define QTOPIA_INTERNAL_CONTACT_MRE 20#define QTOPIA_INTERNAL_CONTACT_MRE
21 21
22#include "ocontact.h" 22#include "ocontact.h"
23#include "opimresolver.h" 23#include "opimresolver.h"
24 24
25#include <qpe/stringutil.h> 25#include <qpe/stringutil.h>
26#include "oconversion.h" 26#include "oconversion.h"
27#include <qpe/timestring.h> 27#include <qpe/timestring.h>
28 28
29#include <qobject.h> 29#include <qobject.h>
30#include <qregexp.h> 30#include <qregexp.h>
31#include <qstylesheet.h> 31#include <qstylesheet.h>
32#include <qfileinfo.h> 32#include <qfileinfo.h>
33#include <qmap.h> 33#include <qmap.h>
34 34
35#include <stdio.h> 35#include <stdio.h>
36 36
37/*! 37/*!
38 \class Contact contact.h 38 \class Contact contact.h
39 \brief The Contact class holds the data of an address book entry. 39 \brief The Contact class holds the data of an address book entry.
40 40
41 This data includes information the name of the person, contact 41 This data includes information the name of the person, contact
42 information, and business information such as deparment and job title. 42 information, and business information such as deparment and job title.
43 43
44 \ingroup qtopiaemb 44 \ingroup qtopiaemb
45 \ingroup qtopiadesktop 45 \ingroup qtopiadesktop
46*/ 46*/
47 47
48 48
49/*! 49/*!
50 Creates a new, empty contact. 50 Creates a new, empty contact.
51*/ 51*/
52OContact::OContact() 52OContact::OContact()
53 : OPimRecord(), mMap(), d( 0 ) 53 : OPimRecord(), mMap(), d( 0 )
54{ 54{
55} 55}
56 56
57/*! 57/*!
58 \internal 58 \internal
59 Creates a new contact. The properties of the contact are 59 Creates a new contact. The properties of the contact are
60 set from \a fromMap. 60 set from \a fromMap.
61*/ 61*/
62OContact::OContact( const QMap<int, QString> &fromMap ) : 62OContact::OContact( const QMap<int, QString> &fromMap ) :
63 OPimRecord(), mMap( fromMap ), d( 0 ) 63 OPimRecord(), mMap( fromMap ), d( 0 )
64{ 64{
65 QString cats = mMap[ Qtopia::AddressCategory ]; 65 QString cats = mMap[ Qtopia::AddressCategory ];
66 if ( !cats.isEmpty() ) 66 if ( !cats.isEmpty() )
67 setCategories( idsFromString( cats ) ); 67 setCategories( idsFromString( cats ) );
68 68
69 QString uidStr = find( Qtopia::AddressUid ); 69 QString uidStr = find( Qtopia::AddressUid );
70 70
71 if ( uidStr.isEmpty() || (uidStr.toInt() == 0) ){ 71 if ( uidStr.isEmpty() || (uidStr.toInt() == 0) ){
72 qWarning( "Invalid UID found. Generate new one.." ); 72 qWarning( "Invalid UID found. Generate new one.." );
73 setUid( uidGen().generate() ); 73 setUid( uidGen().generate() );
74 }else 74 }else
75 setUid( uidStr.toInt() ); 75 setUid( uidStr.toInt() );
76 76
77// if ( !uidStr.isEmpty() ) 77// if ( !uidStr.isEmpty() )
78 // setUid( uidStr.toInt() ); 78 // setUid( uidStr.toInt() );
79} 79}
80 80
81/*! 81/*!
82 Destroys a contact. 82 Destroys a contact.
83*/ 83*/
84OContact::~OContact() 84OContact::~OContact()
85{ 85{
86} 86}
87 87
88/*! \fn void OContact::setTitle( const QString &str ) 88/*! \fn void OContact::setTitle( const QString &str )
89 Sets the title of the contact to \a str. 89 Sets the title of the contact to \a str.
90*/ 90*/
91 91
92/*! \fn void OContact::setFirstName( const QString &str ) 92/*! \fn void OContact::setFirstName( const QString &str )
93 Sets the first name of the contact to \a str. 93 Sets the first name of the contact to \a str.
94*/ 94*/
95 95
96/*! \fn void OContact::setMiddleName( const QString &str ) 96/*! \fn void OContact::setMiddleName( const QString &str )
97 Sets the middle name of the contact to \a str. 97 Sets the middle name of the contact to \a str.
98*/ 98*/
99 99
100/*! \fn void OContact::setLastName( const QString &str ) 100/*! \fn void OContact::setLastName( const QString &str )
101 Sets the last name of the contact to \a str. 101 Sets the last name of the contact to \a str.
102*/ 102*/
103 103
104/*! \fn void OContact::setSuffix( const QString &str ) 104/*! \fn void OContact::setSuffix( const QString &str )
105 Sets the suffix of the contact to \a str. 105 Sets the suffix of the contact to \a str.
106*/ 106*/
107 107
108/*! \fn void OContact::setFileAs( const QString &str ) 108/*! \fn void OContact::setFileAs( const QString &str )
109 Sets the contact to filed as \a str. 109 Sets the contact to filed as \a str.
110*/ 110*/
111 111
112/*! \fn void OContact::setDefaultEmail( const QString &str ) 112/*! \fn void OContact::setDefaultEmail( const QString &str )
113 Sets the default email of the contact to \a str. 113 Sets the default email of the contact to \a str.
114*/ 114*/
115 115
116/*! \fn void OContact::setHomeStreet( const QString &str ) 116/*! \fn void OContact::setHomeStreet( const QString &str )
117 Sets the home street address of the contact to \a str. 117 Sets the home street address of the contact to \a str.
118*/ 118*/
119 119
120/*! \fn void OContact::setHomeCity( const QString &str ) 120/*! \fn void OContact::setHomeCity( const QString &str )
121 Sets the home city of the contact to \a str. 121 Sets the home city of the contact to \a str.
122*/ 122*/
123 123
124/*! \fn void OContact::setHomeState( const QString &str ) 124/*! \fn void OContact::setHomeState( const QString &str )
125 Sets the home state of the contact to \a str. 125 Sets the home state of the contact to \a str.
126*/ 126*/
127 127
128/*! \fn void OContact::setHomeZip( const QString &str ) 128/*! \fn void OContact::setHomeZip( const QString &str )
129 Sets the home zip code of the contact to \a str. 129 Sets the home zip code of the contact to \a str.
130*/ 130*/
131 131
132/*! \fn void OContact::setHomeCountry( const QString &str ) 132/*! \fn void OContact::setHomeCountry( const QString &str )
133 Sets the home country of the contact to \a str. 133 Sets the home country of the contact to \a str.
134*/ 134*/
135 135
136/*! \fn void OContact::setHomePhone( const QString &str ) 136/*! \fn void OContact::setHomePhone( const QString &str )
137 Sets the home phone number of the contact to \a str. 137 Sets the home phone number of the contact to \a str.
138*/ 138*/
139 139
140/*! \fn void OContact::setHomeFax( const QString &str ) 140/*! \fn void OContact::setHomeFax( const QString &str )
141 Sets the home fax number of the contact to \a str. 141 Sets the home fax number of the contact to \a str.
142*/ 142*/
143 143
144/*! \fn void OContact::setHomeMobile( const QString &str ) 144/*! \fn void OContact::setHomeMobile( const QString &str )
145 Sets the home mobile phone number of the contact to \a str. 145 Sets the home mobile phone number of the contact to \a str.
146*/ 146*/
147 147
148/*! \fn void OContact::setHomeWebpage( const QString &str ) 148/*! \fn void OContact::setHomeWebpage( const QString &str )
149 Sets the home webpage of the contact to \a str. 149 Sets the home webpage of the contact to \a str.
150*/ 150*/
151 151
152/*! \fn void OContact::setCompany( const QString &str ) 152/*! \fn void OContact::setCompany( const QString &str )
153 Sets the company for contact to \a str. 153 Sets the company for contact to \a str.
154*/ 154*/
155 155
156/*! \fn void OContact::setJobTitle( const QString &str ) 156/*! \fn void OContact::setJobTitle( const QString &str )
157 Sets the job title of the contact to \a str. 157 Sets the job title of the contact to \a str.
158*/ 158*/
159 159
160/*! \fn void OContact::setDepartment( const QString &str ) 160/*! \fn void OContact::setDepartment( const QString &str )
161 Sets the department for contact to \a str. 161 Sets the department for contact to \a str.
162*/ 162*/
163 163
164/*! \fn void OContact::setOffice( const QString &str ) 164/*! \fn void OContact::setOffice( const QString &str )
165 Sets the office for contact to \a str. 165 Sets the office for contact to \a str.
166*/ 166*/
167 167
168/*! \fn void OContact::setBusinessStreet( const QString &str ) 168/*! \fn void OContact::setBusinessStreet( const QString &str )
169 Sets the business street address of the contact to \a str. 169 Sets the business street address of the contact to \a str.
170*/ 170*/
171 171
172/*! \fn void OContact::setBusinessCity( const QString &str ) 172/*! \fn void OContact::setBusinessCity( const QString &str )
173 Sets the business city of the contact to \a str. 173 Sets the business city of the contact to \a str.
174*/ 174*/
175 175
176/*! \fn void OContact::setBusinessState( const QString &str ) 176/*! \fn void OContact::setBusinessState( const QString &str )
177 Sets the business state of the contact to \a str. 177 Sets the business state of the contact to \a str.
178*/ 178*/
179 179
180/*! \fn void OContact::setBusinessZip( const QString &str ) 180/*! \fn void OContact::setBusinessZip( const QString &str )
181 Sets the business zip code of the contact to \a str. 181 Sets the business zip code of the contact to \a str.
182*/ 182*/
183 183
184/*! \fn void OContact::setBusinessCountry( const QString &str ) 184/*! \fn void OContact::setBusinessCountry( const QString &str )
185 Sets the business country of the contact to \a str. 185 Sets the business country of the contact to \a str.
186*/ 186*/
187 187
188/*! \fn void OContact::setBusinessPhone( const QString &str ) 188/*! \fn void OContact::setBusinessPhone( const QString &str )
189 Sets the business phone number of the contact to \a str. 189 Sets the business phone number of the contact to \a str.
190*/ 190*/
191 191
192/*! \fn void OContact::setBusinessFax( const QString &str ) 192/*! \fn void OContact::setBusinessFax( const QString &str )
193 Sets the business fax number of the contact to \a str. 193 Sets the business fax number of the contact to \a str.
194*/ 194*/
195 195
196/*! \fn void OContact::setBusinessMobile( const QString &str ) 196/*! \fn void OContact::setBusinessMobile( const QString &str )
197 Sets the business mobile phone number of the contact to \a str. 197 Sets the business mobile phone number of the contact to \a str.
198*/ 198*/
199 199
200/*! \fn void OContact::setBusinessPager( const QString &str ) 200/*! \fn void OContact::setBusinessPager( const QString &str )
201 Sets the business pager number of the contact to \a str. 201 Sets the business pager number of the contact to \a str.
202*/ 202*/
203 203
204/*! \fn void OContact::setBusinessWebpage( const QString &str ) 204/*! \fn void OContact::setBusinessWebpage( const QString &str )
205 Sets the business webpage of the contact to \a str. 205 Sets the business webpage of the contact to \a str.
206*/ 206*/
207 207
208/*! \fn void OContact::setProfession( const QString &str ) 208/*! \fn void OContact::setProfession( const QString &str )
209 Sets the profession of the contact to \a str. 209 Sets the profession of the contact to \a str.
210*/ 210*/
211 211
212/*! \fn void OContact::setAssistant( const QString &str ) 212/*! \fn void OContact::setAssistant( const QString &str )
213 Sets the assistant of the contact to \a str. 213 Sets the assistant of the contact to \a str.
214*/ 214*/
215 215
216/*! \fn void OContact::setManager( const QString &str ) 216/*! \fn void OContact::setManager( const QString &str )
217 Sets the manager of the contact to \a str. 217 Sets the manager of the contact to \a str.
218*/ 218*/
219 219
220/*! \fn void OContact::setSpouse( const QString &str ) 220/*! \fn void OContact::setSpouse( const QString &str )
221 Sets the spouse of the contact to \a str. 221 Sets the spouse of the contact to \a str.
222*/ 222*/
223 223
224/*! \fn void OContact::setGender( const QString &str ) 224/*! \fn void OContact::setGender( const QString &str )
225 Sets the gender of the contact to \a str. 225 Sets the gender of the contact to \a str.
226*/ 226*/
227 227
228/*! \fn void OContact::setNickname( const QString &str ) 228/*! \fn void OContact::setNickname( const QString &str )
229 Sets the nickname of the contact to \a str. 229 Sets the nickname of the contact to \a str.
230*/ 230*/
231 231
232/*! \fn void OContact::setNotes( const QString &str ) 232/*! \fn void OContact::setNotes( const QString &str )
233 Sets the notes about the contact to \a str. 233 Sets the notes about the contact to \a str.
234*/ 234*/
235 235
236/*! \fn QString OContact::title() const 236/*! \fn QString OContact::title() const
237 Returns the title of the contact. 237 Returns the title of the contact.
238*/ 238*/
239 239
240/*! \fn QString OContact::firstName() const 240/*! \fn QString OContact::firstName() const
241 Returns the first name of the contact. 241 Returns the first name of the contact.
242*/ 242*/
243 243
244/*! \fn QString OContact::middleName() const 244/*! \fn QString OContact::middleName() const
245 Returns the middle name of the contact. 245 Returns the middle name of the contact.
246*/ 246*/
247 247
248/*! \fn QString OContact::lastName() const 248/*! \fn QString OContact::lastName() const
249 Returns the last name of the contact. 249 Returns the last name of the contact.
250*/ 250*/
251 251
252/*! \fn QString OContact::suffix() const 252/*! \fn QString OContact::suffix() const
253 Returns the suffix of the contact. 253 Returns the suffix of the contact.
254*/ 254*/
255 255
256/*! \fn QString OContact::fileAs() const 256/*! \fn QString OContact::fileAs() const
257 Returns the string the contact is filed as. 257 Returns the string the contact is filed as.
258*/ 258*/
259 259
260/*! \fn QString OContact::defaultEmail() const 260/*! \fn QString OContact::defaultEmail() const
261 Returns the default email address of the contact. 261 Returns the default email address of the contact.
262*/ 262*/
263 263
264/*! \fn QString OContact::emails() const 264/*! \fn QString OContact::emails() const
265 Returns the list of email address for a contact separated by ';'s in a single 265 Returns the list of email address for a contact separated by ';'s in a single
266 string. 266 string.
267*/ 267*/
268 268
269/*! \fn QString OContact::homeStreet() const 269/*! \fn QString OContact::homeStreet() const
270 Returns the home street address of the contact. 270 Returns the home street address of the contact.
271*/ 271*/
272 272
273/*! \fn QString OContact::homeCity() const 273/*! \fn QString OContact::homeCity() const
274 Returns the home city of the contact. 274 Returns the home city of the contact.
275*/ 275*/
276 276
277/*! \fn QString OContact::homeState() const 277/*! \fn QString OContact::homeState() const
278 Returns the home state of the contact. 278 Returns the home state of the contact.
279*/ 279*/
280 280
281/*! \fn QString OContact::homeZip() const 281/*! \fn QString OContact::homeZip() const
282 Returns the home zip of the contact. 282 Returns the home zip of the contact.
283*/ 283*/
284 284
285/*! \fn QString OContact::homeCountry() const 285/*! \fn QString OContact::homeCountry() const
286 Returns the home country of the contact. 286 Returns the home country of the contact.
287*/ 287*/
288 288
289/*! \fn QString OContact::homePhone() const 289/*! \fn QString OContact::homePhone() const
290 Returns the home phone number of the contact. 290 Returns the home phone number of the contact.
291*/ 291*/
292 292
293/*! \fn QString OContact::homeFax() const 293/*! \fn QString OContact::homeFax() const
294 Returns the home fax number of the contact. 294 Returns the home fax number of the contact.
295*/ 295*/
296 296
297/*! \fn QString OContact::homeMobile() const 297/*! \fn QString OContact::homeMobile() const
298 Returns the home mobile number of the contact. 298 Returns the home mobile number of the contact.
299*/ 299*/
300 300
301/*! \fn QString OContact::homeWebpage() const 301/*! \fn QString OContact::homeWebpage() const
302 Returns the home webpage of the contact. 302 Returns the home webpage of the contact.
303*/ 303*/
304 304
305/*! \fn QString OContact::company() const 305/*! \fn QString OContact::company() const
306 Returns the company for the contact. 306 Returns the company for the contact.
307*/ 307*/
308 308
309/*! \fn QString OContact::department() const 309/*! \fn QString OContact::department() const
310 Returns the department for the contact. 310 Returns the department for the contact.
311*/ 311*/
312 312
313/*! \fn QString OContact::office() const 313/*! \fn QString OContact::office() const
314 Returns the office for the contact. 314 Returns the office for the contact.
315*/ 315*/
316 316
317/*! \fn QString OContact::jobTitle() const 317/*! \fn QString OContact::jobTitle() const
318 Returns the job title of the contact. 318 Returns the job title of the contact.
319*/ 319*/
320 320
321/*! \fn QString OContact::profession() const 321/*! \fn QString OContact::profession() const
322 Returns the profession of the contact. 322 Returns the profession of the contact.
323*/ 323*/
324 324
325/*! \fn QString OContact::assistant() const 325/*! \fn QString OContact::assistant() const
326 Returns the assistant of the contact. 326 Returns the assistant of the contact.
327*/ 327*/
328 328
329/*! \fn QString OContact::manager() const 329/*! \fn QString OContact::manager() const
330 Returns the manager of the contact. 330 Returns the manager of the contact.
331*/ 331*/
332 332
333/*! \fn QString OContact::businessStreet() const 333/*! \fn QString OContact::businessStreet() const
334 Returns the business street address of the contact. 334 Returns the business street address of the contact.
335*/ 335*/
336 336
337/*! \fn QString OContact::businessCity() const 337/*! \fn QString OContact::businessCity() const
338 Returns the business city of the contact. 338 Returns the business city of the contact.
339*/ 339*/
340 340
341/*! \fn QString OContact::businessState() const 341/*! \fn QString OContact::businessState() const
342 Returns the business state of the contact. 342 Returns the business state of the contact.
343*/ 343*/
344 344
345/*! \fn QString OContact::businessZip() const 345/*! \fn QString OContact::businessZip() const
346 Returns the business zip of the contact. 346 Returns the business zip of the contact.
347*/ 347*/
348 348
349/*! \fn QString OContact::businessCountry() const 349/*! \fn QString OContact::businessCountry() const
350 Returns the business country of the contact. 350 Returns the business country of the contact.
351*/ 351*/
352 352
353/*! \fn QString OContact::businessPhone() const 353/*! \fn QString OContact::businessPhone() const
354 Returns the business phone number of the contact. 354 Returns the business phone number of the contact.
355*/ 355*/
356 356
357/*! \fn QString OContact::businessFax() const 357/*! \fn QString OContact::businessFax() const
358 Returns the business fax number of the contact. 358 Returns the business fax number of the contact.
359*/ 359*/
360 360
361/*! \fn QString OContact::businessMobile() const 361/*! \fn QString OContact::businessMobile() const
362 Returns the business mobile number of the contact. 362 Returns the business mobile number of the contact.
363*/ 363*/
364 364
365/*! \fn QString OContact::businessPager() const 365/*! \fn QString OContact::businessPager() const
366 Returns the business pager number of the contact. 366 Returns the business pager number of the contact.
367*/ 367*/
368 368
369/*! \fn QString OContact::businessWebpage() const 369/*! \fn QString OContact::businessWebpage() const
370 Returns the business webpage of the contact. 370 Returns the business webpage of the contact.
371*/ 371*/
372 372
373/*! \fn QString OContact::spouse() const 373/*! \fn QString OContact::spouse() const
374 Returns the spouse of the contact. 374 Returns the spouse of the contact.
375*/ 375*/
376 376
377/*! \fn QString OContact::gender() const 377/*! \fn QString OContact::gender() const
378 Returns the gender of the contact. 378 Returns the gender of the contact.
379*/ 379*/
380 380
381/*! \fn QString OContact::nickname() const 381/*! \fn QString OContact::nickname() const
382 Returns the nickname of the contact. 382 Returns the nickname of the contact.
383*/ 383*/
384 384
385/*! \fn QString OContact::children() const 385/*! \fn QString OContact::children() const
386 Returns the children of the contact. 386 Returns the children of the contact.
387*/ 387*/
388 388
389/*! \fn QString OContact::notes() const 389/*! \fn QString OContact::notes() const
390 Returns the notes relating to the the contact. 390 Returns the notes relating to the the contact.
391*/ 391*/
392 392
393/*! \fn QString OContact::groups() const 393/*! \fn QString OContact::groups() const
394 \internal 394 \internal
395 Returns the groups for the contact. 395 Returns the groups for the contact.
396*/ 396*/
397 397
398/*! \fn QStringList OContact::groupList() const 398/*! \fn QStringList OContact::groupList() const
399 \internal 399 \internal
400*/ 400*/
401 401
402/*! \fn QString OContact::field(int) const 402/*! \fn QString OContact::field(int) const
403 \internal 403 \internal
404*/ 404*/
405 405
406/*! \fn void OContact::saveJournal( journal_action, const QString & = QString::null ) 406/*! \fn void OContact::saveJournal( journal_action, const QString & = QString::null )
407 \internal 407 \internal
408*/ 408*/
409 409
410/*! \fn void OContact::setUid( int id ) 410/*! \fn void OContact::setUid( int id )
411 \internal 411 \internal
412 Sets the uid for this record to \a id. 412 Sets the uid for this record to \a id.
413*/ 413*/
414 414
415/*! \enum OContact::journal_action 415/*! \enum OContact::journal_action
416 \internal 416 \internal
417*/ 417*/
418 418
419/*! 419/*!
420 \internal 420 \internal
421*/ 421*/
422QMap<int, QString> OContact::toMap() const 422QMap<int, QString> OContact::toMap() const
423{ 423{
424 QMap<int, QString> map = mMap; 424 QMap<int, QString> map = mMap;
425 QString cats = idsToString( categories() ); 425 QString cats = idsToString( categories() );
426 if ( !cats.isEmpty() ) 426 if ( !cats.isEmpty() )
427 map.insert( Qtopia::AddressCategory, cats ); 427 map.insert( Qtopia::AddressCategory, cats );
428 return map; 428 return map;
429} 429}
430 430
431/*! 431/*!
432 Returns a rich text formatted QString representing the contents the contact. 432 Returns a rich text formatted QString representing the contents the contact.
433*/ 433*/
434QString OContact::toRichText() const 434QString OContact::toRichText() const
435{ 435{
436 QString text; 436 QString text;
437 QString value, comp, state; 437 QString value, comp, state;
438 QString str; 438 QString str;
439 bool marker = false; 439 bool marker = false;
440 440
441 // name, jobtitle and company 441 // name, jobtitle and company
442 if ( !(value = fullName()).isEmpty() ) 442 if ( !(value = fullName()).isEmpty() )
443 text += "<b><h3><img src=\"addressbook/AddressBook\">" + Qtopia::escapeString(value) + "</h3></b>"; 443 text += "<b><h3><img src=\"addressbook/AddressBook\">" + Qtopia::escapeString(value) + "</h3></b>";
444 444
445 if ( !(value = jobTitle()).isEmpty() ) 445 if ( !(value = jobTitle()).isEmpty() )
446 text += Qtopia::escapeString(value) + "<br>"; 446 text += Qtopia::escapeString(value) + "<br>";
447 447
448 comp = company(); 448 comp = company();
449 if ( !(value = department()).isEmpty() ) { 449 if ( !(value = department()).isEmpty() ) {
450 text += Qtopia::escapeString(value); 450 text += Qtopia::escapeString(value);
451 if ( comp ) 451 if ( comp )
452 text += ", "; 452 text += ", ";
453 else 453 else
454 text += "<br>"; 454 text += "<br>";
455 } 455 }
456 if ( !comp.isEmpty() ) 456 if ( !comp.isEmpty() )
457 text += Qtopia::escapeString(comp) + "<br>"; 457 text += Qtopia::escapeString(comp) + "<br>";
458 458
459 text += "<hr><br>"; 459 text += "<hr><br>";
460 460
461 // defailt email 461 // defailt email
462 QString defEmail = defaultEmail(); 462 QString defEmail = defaultEmail();
463 if ( !defEmail.isEmpty() ) 463 if ( !defEmail.isEmpty() )
464 text += "<b><img src=\"addressbook/email\">" + QObject::tr("Default Email: ") + "</b>" 464 text += "<b><img src=\"addressbook/email\">" + QObject::tr("Default Email: ") + "</b>"
465 + Qtopia::escapeString(defEmail) + "<br>"; 465 + Qtopia::escapeString(defEmail) + "<br>";
466 466
467 text += "<br>"; 467 text += "<br>";
468 468
469 // business address 469 // business address
470 if ( !businessStreet().isEmpty() || !businessCity().isEmpty() || 470 if ( !businessStreet().isEmpty() || !businessCity().isEmpty() ||
471 !businessZip().isEmpty() || !businessCountry().isEmpty() ) { 471 !businessZip().isEmpty() || !businessCountry().isEmpty() ) {
472 text += QObject::tr( "<b>Work Address:</b>" ); 472 text += QObject::tr( "<b>Work Address:</b>" );
473 text += "<br>"; 473 text += "<br>";
474 marker = true; 474 marker = true;
475 } 475 }
476 476
477 if ( !(value = businessStreet()).isEmpty() ) 477 if ( !(value = businessStreet()).isEmpty() )
478 text += Qtopia::escapeString(value) + "<br>"; 478 text += Qtopia::escapeString(value) + "<br>";
479 state = businessState(); 479 state = businessState();
480 if ( !(value = businessZip()).isEmpty() ) 480 if ( !(value = businessZip()).isEmpty() )
481 text += Qtopia::escapeString(value) + " "; 481 text += Qtopia::escapeString(value) + " ";
482 if ( !(value = businessCity()).isEmpty() ) { 482 if ( !(value = businessCity()).isEmpty() ) {
483 text += Qtopia::escapeString(value); 483 text += Qtopia::escapeString(value);
484 if ( state ) 484 if ( state )
485 text += ", " + Qtopia::escapeString(state); 485 text += ", " + Qtopia::escapeString(state);
486 text += "<br>"; 486 text += "<br>";
487 } else if ( !state.isEmpty() ) 487 } else if ( !state.isEmpty() )
488 text += Qtopia::escapeString(state) + "<br>"; 488 text += Qtopia::escapeString(state) + "<br>";
489 489
490 if ( !(value = businessCountry()).isEmpty() ) 490 if ( !(value = businessCountry()).isEmpty() )
491 text += Qtopia::escapeString(value) + "<br>"; 491 text += Qtopia::escapeString(value) + "<br>";
492 492
493 // rest of Business data 493 // rest of Business data
494 str = office(); 494 str = office();
495 if ( !str.isEmpty() ){ 495 if ( !str.isEmpty() ){
496 text += "<b>" + QObject::tr("Office: ") + "</b>" 496 text += "<b>" + QObject::tr("Office: ") + "</b>"
497 + Qtopia::escapeString(str) + "<br>"; 497 + Qtopia::escapeString(str) + "<br>";
498 marker = true; 498 marker = true;
499 } 499 }
500 str = businessWebpage(); 500 str = businessWebpage();
501 if ( !str.isEmpty() ){ 501 if ( !str.isEmpty() ){
502 text += "<b><img src=\"addressbook/webpagework\">" + QObject::tr("Business Web Page: ") + "</b>" 502 text += "<b><img src=\"addressbook/webpagework\">" + QObject::tr("Business Web Page: ") + "</b>"
503 + Qtopia::escapeString(str) + "<br>"; 503 + Qtopia::escapeString(str) + "<br>";
504 marker = true; 504 marker = true;
505 } 505 }
506 str = businessPhone(); 506 str = businessPhone();
507 if ( !str.isEmpty() ){ 507 if ( !str.isEmpty() ){
508 text += "<b><img src=\"addressbook/phonework\">" + QObject::tr("Business Phone: ") + "</b>" 508 text += "<b><img src=\"addressbook/phonework\">" + QObject::tr("Business Phone: ") + "</b>"
509 + Qtopia::escapeString(str) + "<br>"; 509 + Qtopia::escapeString(str) + "<br>";
510 marker = true; 510 marker = true;
511 } 511 }
512 str = businessFax(); 512 str = businessFax();
513 if ( !str.isEmpty() ){ 513 if ( !str.isEmpty() ){
514 text += "<b><img src=\"addressbook/faxwork\">" + QObject::tr("Business Fax: ") + "</b>" 514 text += "<b><img src=\"addressbook/faxwork\">" + QObject::tr("Business Fax: ") + "</b>"
515 + Qtopia::escapeString(str) + "<br>"; 515 + Qtopia::escapeString(str) + "<br>";
516 marker = true; 516 marker = true;
517 } 517 }
518 str = businessMobile(); 518 str = businessMobile();
519 if ( !str.isEmpty() ){ 519 if ( !str.isEmpty() ){
520 text += "<b><img src=\"addressbook/mobilework\">" + QObject::tr("Business Mobile: ") + "</b>" 520 text += "<b><img src=\"addressbook/mobilework\">" + QObject::tr("Business Mobile: ") + "</b>"
521 + Qtopia::escapeString(str) + "<br>"; 521 + Qtopia::escapeString(str) + "<br>";
522 marker = true; 522 marker = true;
523 } 523 }
524 str = businessPager(); 524 str = businessPager();
525 if ( !str.isEmpty() ){ 525 if ( !str.isEmpty() ){
526 text += "<b>" + QObject::tr("Business Pager: ") + "</b>" 526 text += "<b>" + QObject::tr("Business Pager: ") + "</b>"
527 + Qtopia::escapeString(str) + "<br>"; 527 + Qtopia::escapeString(str) + "<br>";
528 marker = true; 528 marker = true;
529 } 529 }
530 530
531 text += "<br>"; 531 text += "<br>";
532 532
533 // home address 533 // home address
534 if ( !homeStreet().isEmpty() || !homeCity().isEmpty() || 534 if ( !homeStreet().isEmpty() || !homeCity().isEmpty() ||
535 !homeZip().isEmpty() || !homeCountry().isEmpty() ) { 535 !homeZip().isEmpty() || !homeCountry().isEmpty() ) {
536 text += QObject::tr( "<b>Home Address:</b>" ); 536 text += QObject::tr( "<b>Home Address:</b>" );
537 text += "<br>"; 537 text += "<br>";
538 } 538 }
539 539
540 if ( !(value = homeStreet()).isEmpty() ) 540 if ( !(value = homeStreet()).isEmpty() )
541 text += Qtopia::escapeString(value) + "<br>"; 541 text += Qtopia::escapeString(value) + "<br>";
542 state = homeState(); 542 state = homeState();
543 if ( !(value = homeZip()).isEmpty() ) 543 if ( !(value = homeZip()).isEmpty() )
544 text += Qtopia::escapeString(value) + " "; 544 text += Qtopia::escapeString(value) + " ";
545 if ( !(value = homeCity()).isEmpty() ) { 545 if ( !(value = homeCity()).isEmpty() ) {
546 text += Qtopia::escapeString(value); 546 text += Qtopia::escapeString(value);
547 if ( !state.isEmpty() ) 547 if ( !state.isEmpty() )
548 text += ", " + Qtopia::escapeString(state); 548 text += ", " + Qtopia::escapeString(state);
549 text += "<br>"; 549 text += "<br>";
550 } else if (!state.isEmpty()) 550 } else if (!state.isEmpty())
551 text += Qtopia::escapeString(state) + "<br>"; 551 text += Qtopia::escapeString(state) + "<br>";
552 if ( !(value = homeCountry()).isEmpty() ) 552 if ( !(value = homeCountry()).isEmpty() )
553 text += Qtopia::escapeString(value) + "<br>"; 553 text += Qtopia::escapeString(value) + "<br>";
554 554
555 // rest of Home data 555 // rest of Home data
556 str = homeWebpage(); 556 str = homeWebpage();
557 if ( !str.isEmpty() ){ 557 if ( !str.isEmpty() ){
558 text += "<b><img src=\"addressbook/webpagehome\">" + QObject::tr("Home Web Page: ") + "</b>" 558 text += "<b><img src=\"addressbook/webpagehome\">" + QObject::tr("Home Web Page: ") + "</b>"
559 + Qtopia::escapeString(str) + "<br>"; 559 + Qtopia::escapeString(str) + "<br>";
560 marker = true; 560 marker = true;
561 } 561 }
562 str = homePhone(); 562 str = homePhone();
563 if ( !str.isEmpty() ){ 563 if ( !str.isEmpty() ){
564 text += "<b><img src=\"addressbook/phonehome\">" + QObject::tr("Home Phone: ") + "</b>" 564 text += "<b><img src=\"addressbook/phonehome\">" + QObject::tr("Home Phone: ") + "</b>"
565 + Qtopia::escapeString(str) + "<br>"; 565 + Qtopia::escapeString(str) + "<br>";
566 marker = true; 566 marker = true;
567 } 567 }
568 str = homeFax(); 568 str = homeFax();
569 if ( !str.isEmpty() ){ 569 if ( !str.isEmpty() ){
570 text += "<b><img src=\"addressbook/faxhome\">" + QObject::tr("Home Fax: ") + "</b>" 570 text += "<b><img src=\"addressbook/faxhome\">" + QObject::tr("Home Fax: ") + "</b>"
571 + Qtopia::escapeString(str) + "<br>"; 571 + Qtopia::escapeString(str) + "<br>";
572 marker = true; 572 marker = true;
573 } 573 }
574 str = homeMobile(); 574 str = homeMobile();
575 if ( !str.isEmpty() ){ 575 if ( !str.isEmpty() ){
576 text += "<b><img src=\"addressbook/mobilehome\">" + QObject::tr("Home Mobile: ") + "</b>" 576 text += "<b><img src=\"addressbook/mobilehome\">" + QObject::tr("Home Mobile: ") + "</b>"
577 + Qtopia::escapeString(str) + "<br>"; 577 + Qtopia::escapeString(str) + "<br>";
578 marker = true; 578 marker = true;
579 } 579 }
580 580
581 if ( marker ) 581 if ( marker )
582 text += "<br><hr><br>"; 582 text += "<br><hr><br>";
583 // the others... 583 // the others...
584 str = emails(); 584 str = emails();
585 if ( !str.isEmpty() && ( str != defEmail ) ) 585 if ( !str.isEmpty() && ( str != defEmail ) )
586 text += "<b>" + QObject::tr("All Emails: ") + "</b>" 586 text += "<b>" + QObject::tr("All Emails: ") + "</b>"
587 + Qtopia::escapeString(str) + "<br>"; 587 + Qtopia::escapeString(str) + "<br>";
588 str = profession(); 588 str = profession();
589 if ( !str.isEmpty() ) 589 if ( !str.isEmpty() )
590 text += "<b>" + QObject::tr("Profession: ") + "</b>" 590 text += "<b>" + QObject::tr("Profession: ") + "</b>"
591 + Qtopia::escapeString(str) + "<br>"; 591 + Qtopia::escapeString(str) + "<br>";
592 str = assistant(); 592 str = assistant();
593 if ( !str.isEmpty() ) 593 if ( !str.isEmpty() )
594 text += "<b>" + QObject::tr("Assistant: ") + "</b>" 594 text += "<b>" + QObject::tr("Assistant: ") + "</b>"
595 + Qtopia::escapeString(str) + "<br>"; 595 + Qtopia::escapeString(str) + "<br>";
596 str = manager(); 596 str = manager();
597 if ( !str.isEmpty() ) 597 if ( !str.isEmpty() )
598 text += "<b>" + QObject::tr("Manager: ") + "</b>" 598 text += "<b>" + QObject::tr("Manager: ") + "</b>"
599 + Qtopia::escapeString(str) + "<br>"; 599 + Qtopia::escapeString(str) + "<br>";
600 str = gender(); 600 str = gender();
601 if ( !str.isEmpty() && str.toInt() != 0 ) { 601 if ( !str.isEmpty() && str.toInt() != 0 ) {
602 if ( str.toInt() == 1 ) 602 if ( str.toInt() == 1 )
603 str = QObject::tr( "Male" ); 603 str = QObject::tr( "Male" );
604 else if ( str.toInt() == 2 ) 604 else if ( str.toInt() == 2 )
605 str = QObject::tr( "Female" ); 605 str = QObject::tr( "Female" );
606 text += "<b>" + QObject::tr("Gender: ") + "</b>" + str + "<br>"; 606 text += "<b>" + QObject::tr("Gender: ") + "</b>" + str + "<br>";
607 } 607 }
608 str = spouse(); 608 str = spouse();
609 if ( !str.isEmpty() ) 609 if ( !str.isEmpty() )
610 text += "<b>" + QObject::tr("Spouse: ") + "</b>" 610 text += "<b>" + QObject::tr("Spouse: ") + "</b>"
611 + Qtopia::escapeString(str) + "<br>"; 611 + Qtopia::escapeString(str) + "<br>";
612 if ( birthday().isValid() ){ 612 if ( birthday().isValid() ){
613 str = TimeString::numberDateString( birthday() ); 613 str = TimeString::numberDateString( birthday() );
614 text += "<b>" + QObject::tr("Birthday: ") + "</b>" 614 text += "<b>" + QObject::tr("Birthday: ") + "</b>"
615 + Qtopia::escapeString(str) + "<br>"; 615 + Qtopia::escapeString(str) + "<br>";
616 } 616 }
617 if ( anniversary().isValid() ){ 617 if ( anniversary().isValid() ){
618 str = TimeString::numberDateString( anniversary() ); 618 str = TimeString::numberDateString( anniversary() );
619 text += "<b>" + QObject::tr("Anniversary: ") + "</b>" 619 text += "<b>" + QObject::tr("Anniversary: ") + "</b>"
620 + Qtopia::escapeString(str) + "<br>"; 620 + Qtopia::escapeString(str) + "<br>";
621 } 621 }
622 str = children(); 622 str = children();
623 if ( !str.isEmpty() ) 623 if ( !str.isEmpty() )
624 text += "<b>" + QObject::tr("Children: ") + "</b>" 624 text += "<b>" + QObject::tr("Children: ") + "</b>"
625 + Qtopia::escapeString(str) + "<br>"; 625 + Qtopia::escapeString(str) + "<br>";
626 626
627 str = nickname(); 627 str = nickname();
628 if ( !str.isEmpty() ) 628 if ( !str.isEmpty() )
629 text += "<b>" + QObject::tr("Nickname: ") + "</b>" 629 text += "<b>" + QObject::tr("Nickname: ") + "</b>"
630 + Qtopia::escapeString(str) + "<br>"; 630 + Qtopia::escapeString(str) + "<br>";
631 631
632 // categories 632 // categories
633 if ( categoryNames("Contacts").count() ){ 633 if ( categoryNames("Contacts").count() ){
634 text += "<b>" + QObject::tr( "Category:") + "</b> "; 634 text += "<b>" + QObject::tr( "Category:") + "</b> ";
635 text += categoryNames("Contacts").join(", "); 635 text += categoryNames("Contacts").join(", ");
636 text += "<br>"; 636 text += "<br>";
637 } 637 }
638 638
639 // notes last 639 // notes last
640 if ( !(value = notes()).isEmpty() ) { 640 if ( !(value = notes()).isEmpty() ) {
641 text += "<br><hr><b>" + QObject::tr( "Notes:") + "</b> "; 641 text += "<br><hr><b>" + QObject::tr( "Notes:") + "</b> ";
642 QRegExp reg("\n"); 642 QRegExp reg("\n");
643 643
644 //QString tmp = Qtopia::escapeString(value); 644 //QString tmp = Qtopia::escapeString(value);
645 QString tmp = QStyleSheet::convertFromPlainText(value); 645 QString tmp = QStyleSheet::convertFromPlainText(value);
646 //tmp.replace( reg, "<br>" ); 646 //tmp.replace( reg, "<br>" );
647 text += "<br>" + tmp + "<br>"; 647 text += "<br>" + tmp + "<br>";
648 } 648 }
649 return text; 649 return text;
650} 650}
651 651
652/*! 652/*!
653 \internal 653 \internal
654*/ 654*/
655void OContact::insert( int key, const QString &v ) 655void OContact::insert( int key, const QString &v )
656{ 656{
657 QString value = v.stripWhiteSpace(); 657 QString value = v.stripWhiteSpace();
658 if ( value.isEmpty() ) 658 if ( value.isEmpty() )
659 mMap.remove( key ); 659 mMap.remove( key );
660 else 660 else
661 mMap.insert( key, value ); 661 mMap.insert( key, value );
662} 662}
663 663
664/*! 664/*!
665 \internal 665 \internal
666*/ 666*/
667void OContact::replace( int key, const QString & v ) 667void OContact::replace( int key, const QString & v )
668{ 668{
669 QString value = v.stripWhiteSpace(); 669 QString value = v.stripWhiteSpace();
670 if ( value.isEmpty() ) 670 if ( value.isEmpty() )
671 mMap.remove( key ); 671 mMap.remove( key );
672 else 672 else
673 mMap.replace( key, value ); 673 mMap.replace( key, value );
674} 674}
675 675
676/*! 676/*!
677 \internal 677 \internal
678*/ 678*/
679QString OContact::find( int key ) const 679QString OContact::find( int key ) const
680{ 680{
681 return mMap[key]; 681 return mMap[key];
682} 682}
683 683
684/*! 684/*!
685 \internal 685 \internal
686*/ 686*/
687QString OContact::displayAddress( const QString &street, 687QString OContact::displayAddress( const QString &street,
688 const QString &city, 688 const QString &city,
689 const QString &state, 689 const QString &state,
690 const QString &zip, 690 const QString &zip,
691 const QString &country ) const 691 const QString &country ) const
692{ 692{
693 QString s = street; 693 QString s = street;
694 if ( !street.isEmpty() ) 694 if ( !street.isEmpty() )
695 s+= "\n"; 695 s+= "\n";
696 s += city; 696 s += city;
697 if ( !city.isEmpty() && !state.isEmpty() ) 697 if ( !city.isEmpty() && !state.isEmpty() )
698 s += ", "; 698 s += ", ";
699 s += state; 699 s += state;
700 if ( !state.isEmpty() && !zip.isEmpty() ) 700 if ( !state.isEmpty() && !zip.isEmpty() )
701 s += " "; 701 s += " ";
702 s += zip; 702 s += zip;
703 if ( !country.isEmpty() && !s.isEmpty() ) 703 if ( !country.isEmpty() && !s.isEmpty() )
704 s += "\n"; 704 s += "\n";
705 s += country; 705 s += country;
706 return s; 706 return s;
707} 707}
708 708
709/*! 709/*!
710 \internal 710 \internal
711*/ 711*/
712QString OContact::displayBusinessAddress() const 712QString OContact::displayBusinessAddress() const
713{ 713{
714 return displayAddress( businessStreet(), businessCity(), 714 return displayAddress( businessStreet(), businessCity(),
715 businessState(), businessZip(), 715 businessState(), businessZip(),
716 businessCountry() ); 716 businessCountry() );
717} 717}
718 718
719/*! 719/*!
720 \internal 720 \internal
721*/ 721*/
722QString OContact::displayHomeAddress() const 722QString OContact::displayHomeAddress() const
723{ 723{
724 return displayAddress( homeStreet(), homeCity(), 724 return displayAddress( homeStreet(), homeCity(),
725 homeState(), homeZip(), 725 homeState(), homeZip(),
726 homeCountry() ); 726 homeCountry() );
727} 727}
728 728
729/*! 729/*!
730 Returns the full name of the contact 730 Returns the full name of the contact
731*/ 731*/
732QString OContact::fullName() const 732QString OContact::fullName() const
733{ 733{
734 QString title = find( Qtopia::Title ); 734 QString title = find( Qtopia::Title );
735 QString firstName = find( Qtopia::FirstName ); 735 QString firstName = find( Qtopia::FirstName );
736 QString middleName = find( Qtopia::MiddleName ); 736 QString middleName = find( Qtopia::MiddleName );
737 QString lastName = find( Qtopia::LastName ); 737 QString lastName = find( Qtopia::LastName );
738 QString suffix = find( Qtopia::Suffix ); 738 QString suffix = find( Qtopia::Suffix );
739 739
740 QString name = title; 740 QString name = title;
741 if ( !firstName.isEmpty() ) { 741 if ( !firstName.isEmpty() ) {
742 if ( !name.isEmpty() ) 742 if ( !name.isEmpty() )
743 name += " "; 743 name += " ";
744 name += firstName; 744 name += firstName;
745 } 745 }
746 if ( !middleName.isEmpty() ) { 746 if ( !middleName.isEmpty() ) {
747 if ( !name.isEmpty() ) 747 if ( !name.isEmpty() )
748 name += " "; 748 name += " ";
749 name += middleName; 749 name += middleName;
750 } 750 }
751 if ( !lastName.isEmpty() ) { 751 if ( !lastName.isEmpty() ) {
752 if ( !name.isEmpty() ) 752 if ( !name.isEmpty() )
753 name += " "; 753 name += " ";
754 name += lastName; 754 name += lastName;
755 } 755 }
756 if ( !suffix.isEmpty() ) { 756 if ( !suffix.isEmpty() ) {
757 if ( !name.isEmpty() ) 757 if ( !name.isEmpty() )
758 name += " "; 758 name += " ";
759 name += suffix; 759 name += suffix;
760 } 760 }
761 return name.simplifyWhiteSpace(); 761 return name.simplifyWhiteSpace();
762} 762}
763 763
764/*! 764/*!
765 Returns a list of the names of the children of the contact. 765 Returns a list of the names of the children of the contact.
766*/ 766*/
767QStringList OContact::childrenList() const 767QStringList OContact::childrenList() const
768{ 768{
769 return QStringList::split( " ", find( Qtopia::Children ) ); 769 return QStringList::split( " ", find( Qtopia::Children ) );
770} 770}
771 771
772/*! \fn void OContact::insertEmail( const QString &email ) 772/*! \fn void OContact::insertEmail( const QString &email )
773 773
774 Insert \a email into the email list. Ensures \a email can only be added 774 Insert \a email into the email list. Ensures \a email can only be added
775 once. If there is no default email address set, it sets it to the \a email. 775 once. If there is no default email address set, it sets it to the \a email.
776*/ 776*/
777 777
778/*! \fn void OContact::removeEmail( const QString &email ) 778/*! \fn void OContact::removeEmail( const QString &email )
779 779
780 Removes the \a email from the email list. If the default email was \a email, 780 Removes the \a email from the email list. If the default email was \a email,
781 then the default email address is assigned to the first email in the 781 then the default email address is assigned to the first email in the
782 email list 782 email list
783*/ 783*/
784 784
785/*! \fn void OContact::clearEmails() 785/*! \fn void OContact::clearEmails()
786 786
787 Clears the email list. 787 Clears the email list.
788 */ 788 */
789 789
790/*! \fn void OContact::insertEmails( const QStringList &emailList ) 790/*! \fn void OContact::insertEmails( const QStringList &emailList )
791 791
792 Appends the \a emailList to the exiting email list 792 Appends the \a emailList to the exiting email list
793 */ 793 */
794 794
795/*! 795/*!
796 Returns a list of email addresses belonging to the contact, including 796 Returns a list of email addresses belonging to the contact, including
797 the default email address. 797 the default email address.
798*/ 798*/
799QStringList OContact::emailList() const 799QStringList OContact::emailList() const
800{ 800{
801 QString emailStr = emails(); 801 QString emailStr = emails();
802 802
803 QStringList r; 803 QStringList r;
804 if ( !emailStr.isEmpty() ) { 804 if ( !emailStr.isEmpty() ) {
805 qDebug(" emailstr "); 805 qDebug(" emailstr ");
806 QStringList l = QStringList::split( emailSeparator(), emailStr ); 806 QStringList l = QStringList::split( emailSeparator(), emailStr );
807 for ( QStringList::ConstIterator it = l.begin();it != l.end();++it ) 807 for ( QStringList::ConstIterator it = l.begin();it != l.end();++it )
808 r += (*it).simplifyWhiteSpace(); 808 r += (*it).simplifyWhiteSpace();
809 } 809 }
810 810
811 return r; 811 return r;
812} 812}
813 813
814/*! 814/*!
815 \overload 815 \overload
816 816
817 Generates the string for the contact to be filed as from the first, 817 Generates the string for the contact to be filed as from the first,
818 middle and last name of the contact. 818 middle and last name of the contact.
819*/ 819*/
820void OContact::setFileAs() 820void OContact::setFileAs()
821{ 821{
822 QString lastName, firstName, middleName, fileas; 822 QString lastName, firstName, middleName, fileas;
823 823
824 lastName = find( Qtopia::LastName ); 824 lastName = find( Qtopia::LastName );
825 firstName = find( Qtopia::FirstName ); 825 firstName = find( Qtopia::FirstName );
826 middleName = find( Qtopia::MiddleName ); 826 middleName = find( Qtopia::MiddleName );
827 if ( !lastName.isEmpty() && !firstName.isEmpty() 827 if ( !lastName.isEmpty() && !firstName.isEmpty()
828 && !middleName.isEmpty() ) 828 && !middleName.isEmpty() )
829 fileas = lastName + ", " + firstName + " " + middleName; 829 fileas = lastName + ", " + firstName + " " + middleName;
830 else if ( !lastName.isEmpty() && !firstName.isEmpty() ) 830 else if ( !lastName.isEmpty() && !firstName.isEmpty() )
831 fileas = lastName + ", " + firstName; 831 fileas = lastName + ", " + firstName;
832 else if ( !lastName.isEmpty() || !firstName.isEmpty() || 832 else if ( !lastName.isEmpty() || !firstName.isEmpty() ||
833 !middleName.isEmpty() ) 833 !middleName.isEmpty() )
834 fileas = firstName + ( firstName.isEmpty() ? "" : " " ) 834 fileas = firstName + ( firstName.isEmpty() ? "" : " " )
835 + middleName + ( middleName.isEmpty() ? "" : " " ) 835 + middleName + ( middleName.isEmpty() ? "" : " " )
836 + lastName; 836 + lastName;
837 837
838 replace( Qtopia::FileAs, fileas ); 838 replace( Qtopia::FileAs, fileas );
839} 839}
840 840
841/*! 841/*!
842 \internal 842 \internal
843 Appends the contact information to \a buf. 843 Appends the contact information to \a buf.
844*/ 844*/
845void OContact::save( QString &buf ) const 845void OContact::save( QString &buf ) const
846{ 846{
847 static const QStringList SLFIELDS = fields(); 847 static const QStringList SLFIELDS = fields();
848 // I'm expecting "<Contact " in front of this... 848 // I'm expecting "<Contact " in front of this...
849 for ( QMap<int, QString>::ConstIterator it = mMap.begin(); 849 for ( QMap<int, QString>::ConstIterator it = mMap.begin();
850 it != mMap.end(); ++it ) { 850 it != mMap.end(); ++it ) {
851 const QString &value = it.data(); 851 const QString &value = it.data();
852 int key = it.key(); 852 int key = it.key();
853 if ( !value.isEmpty() ) { 853 if ( !value.isEmpty() ) {
854 if ( key == Qtopia::AddressCategory || key == Qtopia::AddressUid) 854 if ( key == Qtopia::AddressCategory || key == Qtopia::AddressUid)
855 continue; 855 continue;
856 856
857 key -= Qtopia::AddressCategory+1; 857 key -= Qtopia::AddressCategory+1;
858 buf += SLFIELDS[key]; 858 buf += SLFIELDS[key];
859 buf += "=\"" + Qtopia::escapeString(value) + "\" "; 859 buf += "=\"" + Qtopia::escapeString(value) + "\" ";
860 } 860 }
861 } 861 }
862 buf += customToXml(); 862 buf += customToXml();
863 if ( categories().count() > 0 ) 863 if ( categories().count() > 0 )
864 buf += "Categories=\"" + idsToString( categories() ) + "\" "; 864 buf += "Categories=\"" + idsToString( categories() ) + "\" ";
865 buf += "Uid=\"" + QString::number( uid() ) + "\" "; 865 buf += "Uid=\"" + QString::number( uid() ) + "\" ";
866 // You need to close this yourself 866 // You need to close this yourself
867} 867}
868 868
869 869
870/*! 870/*!
871 \internal 871 \internal
872 Returns the list of fields belonging to a contact 872 Returns the list of fields belonging to a contact
873 Never change order of this list ! It has to be regarding 873 Never change order of this list ! It has to be regarding
874 enum AddressBookFields !! 874 enum AddressBookFields !!
875*/ 875*/
876QStringList OContact::fields() 876QStringList OContact::fields()
877{ 877{
878 QStringList list; 878 QStringList list;
879 879
880 list.append( "Title" ); // Not Used! 880 list.append( "Title" ); // Not Used!
881 list.append( "FirstName" ); 881 list.append( "FirstName" );
882 list.append( "MiddleName" ); 882 list.append( "MiddleName" );
883 list.append( "LastName" ); 883 list.append( "LastName" );
884 list.append( "Suffix" ); 884 list.append( "Suffix" );
885 list.append( "FileAs" ); 885 list.append( "FileAs" );
886 886
887 list.append( "JobTitle" ); 887 list.append( "JobTitle" );
888 list.append( "Department" ); 888 list.append( "Department" );
889 list.append( "Company" ); 889 list.append( "Company" );
890 list.append( "BusinessPhone" ); 890 list.append( "BusinessPhone" );
891 list.append( "BusinessFax" ); 891 list.append( "BusinessFax" );
892 list.append( "BusinessMobile" ); 892 list.append( "BusinessMobile" );
893 893
894 list.append( "DefaultEmail" ); 894 list.append( "DefaultEmail" );
895 list.append( "Emails" ); 895 list.append( "Emails" );
896 896
897 list.append( "HomePhone" ); 897 list.append( "HomePhone" );
898 list.append( "HomeFax" ); 898 list.append( "HomeFax" );
899 list.append( "HomeMobile" ); 899 list.append( "HomeMobile" );
900 900
901 list.append( "BusinessStreet" ); 901 list.append( "BusinessStreet" );
902 list.append( "BusinessCity" ); 902 list.append( "BusinessCity" );
903 list.append( "BusinessState" ); 903 list.append( "BusinessState" );
904 list.append( "BusinessZip" ); 904 list.append( "BusinessZip" );
905 list.append( "BusinessCountry" ); 905 list.append( "BusinessCountry" );
906 list.append( "BusinessPager" ); 906 list.append( "BusinessPager" );
907 list.append( "BusinessWebPage" ); 907 list.append( "BusinessWebPage" );
908 908
909 list.append( "Office" ); 909 list.append( "Office" );
910 list.append( "Profession" ); 910 list.append( "Profession" );
911 list.append( "Assistant" ); 911 list.append( "Assistant" );
912 list.append( "Manager" ); 912 list.append( "Manager" );
913 913
914 list.append( "HomeStreet" ); 914 list.append( "HomeStreet" );
915 list.append( "HomeCity" ); 915 list.append( "HomeCity" );
916 list.append( "HomeState" ); 916 list.append( "HomeState" );
917 list.append( "HomeZip" ); 917 list.append( "HomeZip" );
918 list.append( "HomeCountry" ); 918 list.append( "HomeCountry" );
919 list.append( "HomeWebPage" ); 919 list.append( "HomeWebPage" );
920 920
921 list.append( "Spouse" ); 921 list.append( "Spouse" );
922 list.append( "Gender" ); 922 list.append( "Gender" );
923 list.append( "Birthday" ); 923 list.append( "Birthday" );
924 list.append( "Anniversary" ); 924 list.append( "Anniversary" );
925 list.append( "Nickname" ); 925 list.append( "Nickname" );
926 list.append( "Children" ); 926 list.append( "Children" );
927 927
928 list.append( "Notes" ); 928 list.append( "Notes" );
929 list.append( "Groups" ); 929 list.append( "Groups" );
930 930
931 return list; 931 return list;
932} 932}
933 933
934 934
935/*! 935/*!
936 Sets the list of email address for contact to those contained in \a str. 936 Sets the list of email address for contact to those contained in \a str.
937 Email address should be separated by ';'s. 937 Email address should be separated by ';'s.
938*/ 938*/
939void OContact::setEmails( const QString &str ) 939void OContact::setEmails( const QString &str )
940{ 940{
941 replace( Qtopia::Emails, str ); 941 replace( Qtopia::Emails, str );
942 if ( str.isEmpty() ) 942 if ( str.isEmpty() )
943 setDefaultEmail( QString::null ); 943 setDefaultEmail( QString::null );
944} 944}
945 945
946/*! 946/*!
947 Sets the list of children for the contact to those contained in \a str. 947 Sets the list of children for the contact to those contained in \a str.
948*/ 948*/
949void OContact::setChildren( const QString &str ) 949void OContact::setChildren( const QString &str )
950{ 950{
951 replace( Qtopia::Children, str ); 951 replace( Qtopia::Children, str );
952} 952}
953 953
954/*! 954/*!
955 \overload 955 \overload
956 Returns TRUE if the contact matches the regular expression \a regexp. 956 Returns TRUE if the contact matches the regular expression \a regexp.
957 Otherwise returns FALSE. 957 Otherwise returns FALSE.
958*/ 958*/
959bool OContact::match( const QRegExp &r ) const 959bool OContact::match( const QRegExp &r ) const
960{ 960{
961 setLastHitField( -1 ); 961 setLastHitField( -1 );
962 bool match; 962 bool match;
963 match = false; 963 match = false;
964 QMap<int, QString>::ConstIterator it; 964 QMap<int, QString>::ConstIterator it;
965 for ( it = mMap.begin(); it != mMap.end(); ++it ) { 965 for ( it = mMap.begin(); it != mMap.end(); ++it ) {
966 if ( (*it).find( r ) > -1 ) { 966 if ( (*it).find( r ) > -1 ) {
967 setLastHitField( it.key() ); 967 setLastHitField( it.key() );
968 match = true; 968 match = true;
969 break; 969 break;
970 } 970 }
971 } 971 }
972 return match; 972 return match;
973} 973}
974 974
975 975
976QString OContact::toShortText() const 976QString OContact::toShortText() const
977{ 977{
978 return ( fullName() ); 978 return ( fullName() );
979} 979}
980QString OContact::type() const 980QString OContact::type() const
981{ 981{
982 return QString::fromLatin1( "OContact" ); 982 return QString::fromLatin1( "OContact" );
983} 983}
984 984
985// Definition is missing ! (se) 985
986QMap<QString,QString> OContact::toExtraMap() const
987{
988 qWarning ("Function not implemented: OContact::toExtraMap()");
989 QMap <QString,QString> useless;
990 return useless;
991}
992 986
993class QString OContact::recordField( int pos ) const 987class QString OContact::recordField( int pos ) const
994{ 988{
995 QStringList SLFIELDS = fields(); // ?? why this ? (se) 989 QStringList SLFIELDS = fields(); // ?? why this ? (se)
996 return SLFIELDS[pos]; 990 return SLFIELDS[pos];
997} 991}
998 992
999// In future releases, we should store birthday and anniversary 993// In future releases, we should store birthday and anniversary
1000// internally as QDate instead of QString ! 994// internally as QDate instead of QString !
1001// QString is always too complicate to interprete (DD.MM.YY, DD/MM/YY, MM/DD/YY, etc..)(se) 995// QString is always too complicate to interprete (DD.MM.YY, DD/MM/YY, MM/DD/YY, etc..)(se)
1002 996
1003/*! \fn void OContact::setBirthday( const QDate& date ) 997/*! \fn void OContact::setBirthday( const QDate& date )
1004 Sets the birthday for the contact to \a date. If date is null 998 Sets the birthday for the contact to \a date. If date is null
1005 the current stored date will be removed. 999 the current stored date will be removed.
1006*/ 1000*/
1007void OContact::setBirthday( const QDate &v ) 1001void OContact::setBirthday( const QDate &v )
1008{ 1002{
1009 if ( v.isNull() ){ 1003 if ( v.isNull() ){
1010 qWarning( "Remove Birthday"); 1004 qWarning( "Remove Birthday");
1011 replace( Qtopia::Birthday, QString::null ); 1005 replace( Qtopia::Birthday, QString::null );
1012 return; 1006 return;
1013 } 1007 }
1014 1008
1015 if ( v.isValid() ) 1009 if ( v.isValid() )
1016 replace( Qtopia::Birthday, OConversion::dateToString( v ) ); 1010 replace( Qtopia::Birthday, OConversion::dateToString( v ) );
1017 1011
1018} 1012}
1019 1013
1020 1014
1021/*! \fn void OContact::setAnniversary( const QDate &date ) 1015/*! \fn void OContact::setAnniversary( const QDate &date )
1022 Sets the anniversary of the contact to \a date. If date is 1016 Sets the anniversary of the contact to \a date. If date is
1023 null, the current stored date will be removed. 1017 null, the current stored date will be removed.
1024*/ 1018*/
1025void OContact::setAnniversary( const QDate &v ) 1019void OContact::setAnniversary( const QDate &v )
1026{ 1020{
1027 if ( v.isNull() ){ 1021 if ( v.isNull() ){
1028 qWarning( "Remove Anniversary"); 1022 qWarning( "Remove Anniversary");
1029 replace( Qtopia::Anniversary, QString::null ); 1023 replace( Qtopia::Anniversary, QString::null );
1030 return; 1024 return;
1031 } 1025 }
1032 1026
1033 if ( v.isValid() ) 1027 if ( v.isValid() )
1034 replace( Qtopia::Anniversary, OConversion::dateToString( v ) ); 1028 replace( Qtopia::Anniversary, OConversion::dateToString( v ) );
1035} 1029}
1036 1030
1037/*! \fn QDate OContact::birthday() const 1031/*! \fn QDate OContact::birthday() const
1038 Returns the birthday of the contact. 1032 Returns the birthday of the contact.
1039*/ 1033*/
1040QDate OContact::birthday() const 1034QDate OContact::birthday() const
1041{ 1035{
1042 QString str = find( Qtopia::Birthday ); 1036 QString str = find( Qtopia::Birthday );
1043 qWarning ("Birthday %s", str.latin1() ); 1037 qWarning ("Birthday %s", str.latin1() );
1044 if ( !str.isEmpty() ) 1038 if ( !str.isEmpty() )
1045 return OConversion::dateFromString ( str ); 1039 return OConversion::dateFromString ( str );
1046 else 1040 else
1047 return QDate(); 1041 return QDate();
1048} 1042}
1049 1043
1050 1044
1051/*! \fn QDate OContact::anniversary() const 1045/*! \fn QDate OContact::anniversary() const
1052 Returns the anniversary of the contact. 1046 Returns the anniversary of the contact.
1053*/ 1047*/
1054QDate OContact::anniversary() const 1048QDate OContact::anniversary() const
1055{ 1049{
1056 QDate empty; 1050 QDate empty;
1057 QString str = find( Qtopia::Anniversary ); 1051 QString str = find( Qtopia::Anniversary );
1058 qWarning ("Anniversary %s", str.latin1() ); 1052 qWarning ("Anniversary %s", str.latin1() );
1059 if ( !str.isEmpty() ) 1053 if ( !str.isEmpty() )
1060 return OConversion::dateFromString ( str ); 1054 return OConversion::dateFromString ( str );
1061 else 1055 else
1062 return empty; 1056 return empty;
1063} 1057}
1064 1058
1065 1059
1066void OContact::insertEmail( const QString &v ) 1060void OContact::insertEmail( const QString &v )
1067{ 1061{
1068 //qDebug("insertEmail %s", v.latin1()); 1062 //qDebug("insertEmail %s", v.latin1());
1069 QString e = v.simplifyWhiteSpace(); 1063 QString e = v.simplifyWhiteSpace();
1070 QString def = defaultEmail(); 1064 QString def = defaultEmail();
1071 1065
1072 // if no default, set it as the default email and don't insert 1066 // if no default, set it as the default email and don't insert
1073 if ( def.isEmpty() ) { 1067 if ( def.isEmpty() ) {
1074 setDefaultEmail( e ); // will insert into the list for us 1068 setDefaultEmail( e ); // will insert into the list for us
1075 return; 1069 return;
1076 } 1070 }
1077 1071
1078 // otherwise, insert assuming doesn't already exist 1072 // otherwise, insert assuming doesn't already exist
1079 QString emailsStr = find( Qtopia::Emails ); 1073 QString emailsStr = find( Qtopia::Emails );
1080 if ( emailsStr.contains( e )) 1074 if ( emailsStr.contains( e ))
1081 return; 1075 return;
1082 if ( !emailsStr.isEmpty() ) 1076 if ( !emailsStr.isEmpty() )
1083 emailsStr += emailSeparator(); 1077 emailsStr += emailSeparator();
1084 emailsStr += e; 1078 emailsStr += e;
1085 replace( Qtopia::Emails, emailsStr ); 1079 replace( Qtopia::Emails, emailsStr );
1086} 1080}
1087 1081
1088void OContact::removeEmail( const QString &v ) 1082void OContact::removeEmail( const QString &v )
1089{ 1083{
1090 QString e = v.simplifyWhiteSpace(); 1084 QString e = v.simplifyWhiteSpace();
1091 QString def = defaultEmail(); 1085 QString def = defaultEmail();
1092 QString emailsStr = find( Qtopia::Emails ); 1086 QString emailsStr = find( Qtopia::Emails );
1093 QStringList emails = emailList(); 1087 QStringList emails = emailList();
1094 1088
1095 // otherwise, must first contain it 1089 // otherwise, must first contain it
1096 if ( !emailsStr.contains( e ) ) 1090 if ( !emailsStr.contains( e ) )
1097 return; 1091 return;
1098 1092
1099 // remove it 1093 // remove it
1100 //qDebug(" removing email from list %s", e.latin1()); 1094 //qDebug(" removing email from list %s", e.latin1());
1101 emails.remove( e ); 1095 emails.remove( e );
1102 // reset the string 1096 // reset the string
1103 emailsStr = emails.join(emailSeparator()); // Sharp's brain dead separator 1097 emailsStr = emails.join(emailSeparator()); // Sharp's brain dead separator
1104 replace( Qtopia::Emails, emailsStr ); 1098 replace( Qtopia::Emails, emailsStr );
1105 1099
1106 // if default, then replace the default email with the first one 1100 // if default, then replace the default email with the first one
1107 if ( def == e ) { 1101 if ( def == e ) {
1108 //qDebug("removeEmail is default; setting new default"); 1102 //qDebug("removeEmail is default; setting new default");
1109 if ( !emails.count() ) 1103 if ( !emails.count() )
1110 clearEmails(); 1104 clearEmails();
1111 else // setDefaultEmail will remove e from the list 1105 else // setDefaultEmail will remove e from the list
1112 setDefaultEmail( emails.first() ); 1106 setDefaultEmail( emails.first() );
1113 } 1107 }
1114} 1108}
1115void OContact::clearEmails() 1109void OContact::clearEmails()
1116{ 1110{
1117 mMap.remove( Qtopia::DefaultEmail ); 1111 mMap.remove( Qtopia::DefaultEmail );
1118 mMap.remove( Qtopia::Emails ); 1112 mMap.remove( Qtopia::Emails );
1119} 1113}
1120void OContact::setDefaultEmail( const QString &v ) 1114void OContact::setDefaultEmail( const QString &v )
1121{ 1115{
1122 QString e = v.simplifyWhiteSpace(); 1116 QString e = v.simplifyWhiteSpace();
1123 1117
1124 //qDebug("OContact::setDefaultEmail %s", e.latin1()); 1118 //qDebug("OContact::setDefaultEmail %s", e.latin1());
1125 replace( Qtopia::DefaultEmail, e ); 1119 replace( Qtopia::DefaultEmail, e );
1126 1120
1127 if ( !e.isEmpty() ) 1121 if ( !e.isEmpty() )
1128 insertEmail( e ); 1122 insertEmail( e );
1129 1123
1130} 1124}
1131 1125
1132void OContact::insertEmails( const QStringList &v ) 1126void OContact::insertEmails( const QStringList &v )
1133{ 1127{
1134 for ( QStringList::ConstIterator it = v.begin(); it != v.end(); ++it ) 1128 for ( QStringList::ConstIterator it = v.begin(); it != v.end(); ++it )
1135 insertEmail( *it ); 1129 insertEmail( *it );
1136} 1130}
1137int OContact::rtti() { 1131int OContact::rtti() {
1138 return OPimResolver::AddressBook; 1132 return OPimResolver::AddressBook;
1139} 1133}
1140void OContact::setUid( int i ) 1134void OContact::setUid( int i )
1141{ 1135{
1142 OPimRecord::setUid(i); 1136 OPimRecord::setUid(i);
1143 replace( Qtopia::AddressUid , QString::number(i)); 1137 replace( Qtopia::AddressUid , QString::number(i));
1144} 1138}
diff --git a/libopie/pim/oevent.cpp b/libopie/pim/oevent.cpp
index e4f5d92..7bcf944 100644
--- a/libopie/pim/oevent.cpp
+++ b/libopie/pim/oevent.cpp
@@ -1,580 +1,577 @@
1#include <qshared.h> 1#include <qshared.h>
2 2
3#include <qpe/palmtopuidgen.h> 3#include <qpe/palmtopuidgen.h>
4#include <qpe/categories.h> 4#include <qpe/categories.h>
5#include <qpe/stringutil.h> 5#include <qpe/stringutil.h>
6 6
7#include "orecur.h" 7#include "orecur.h"
8#include "opimresolver.h" 8#include "opimresolver.h"
9#include "opimnotifymanager.h" 9#include "opimnotifymanager.h"
10 10
11#include "oevent.h" 11#include "oevent.h"
12 12
13int OCalendarHelper::week( const QDate& date) { 13int OCalendarHelper::week( const QDate& date) {
14 // Calculates the week this date is in within that 14 // Calculates the week this date is in within that
15 // month. Equals the "row" is is in in the month view 15 // month. Equals the "row" is is in in the month view
16 int week = 1; 16 int week = 1;
17 QDate tmp( date.year(), date.month(), 1 ); 17 QDate tmp( date.year(), date.month(), 1 );
18 if ( date.dayOfWeek() < tmp.dayOfWeek() ) 18 if ( date.dayOfWeek() < tmp.dayOfWeek() )
19 ++week; 19 ++week;
20 20
21 week += ( date.day() - 1 ) / 7; 21 week += ( date.day() - 1 ) / 7;
22 22
23 return week; 23 return week;
24} 24}
25int OCalendarHelper::ocurrence( const QDate& date) { 25int OCalendarHelper::ocurrence( const QDate& date) {
26 // calculates the number of occurrances of this day of the 26 // calculates the number of occurrances of this day of the
27 // week till the given date (e.g 3rd Wednesday of the month) 27 // week till the given date (e.g 3rd Wednesday of the month)
28 return ( date.day() - 1 ) / 7 + 1; 28 return ( date.day() - 1 ) / 7 + 1;
29} 29}
30int OCalendarHelper::dayOfWeek( char day ) { 30int OCalendarHelper::dayOfWeek( char day ) {
31 int dayOfWeek = 1; 31 int dayOfWeek = 1;
32 char i = ORecur::MON; 32 char i = ORecur::MON;
33 while ( !( i & day ) && i <= ORecur::SUN ) { 33 while ( !( i & day ) && i <= ORecur::SUN ) {
34 i <<= 1; 34 i <<= 1;
35 ++dayOfWeek; 35 ++dayOfWeek;
36 } 36 }
37 return dayOfWeek; 37 return dayOfWeek;
38} 38}
39int OCalendarHelper::monthDiff( const QDate& first, const QDate& second ) { 39int OCalendarHelper::monthDiff( const QDate& first, const QDate& second ) {
40 return ( second.year() - first.year() ) * 12 + 40 return ( second.year() - first.year() ) * 12 +
41 second.month() - first.month(); 41 second.month() - first.month();
42} 42}
43 43
44struct OEvent::Data : public QShared { 44struct OEvent::Data : public QShared {
45 Data() : QShared() { 45 Data() : QShared() {
46 child = 0; 46 child = 0;
47 recur = 0; 47 recur = 0;
48 manager = 0; 48 manager = 0;
49 isAllDay = false; 49 isAllDay = false;
50 parent = 0; 50 parent = 0;
51 } 51 }
52 ~Data() { 52 ~Data() {
53 delete manager; 53 delete manager;
54 delete recur; 54 delete recur;
55 } 55 }
56 QString description; 56 QString description;
57 QString location; 57 QString location;
58 OPimNotifyManager* manager; 58 OPimNotifyManager* manager;
59 ORecur* recur; 59 ORecur* recur;
60 QString note; 60 QString note;
61 QDateTime created; 61 QDateTime created;
62 QDateTime start; 62 QDateTime start;
63 QDateTime end; 63 QDateTime end;
64 bool isAllDay : 1; 64 bool isAllDay : 1;
65 QString timezone; 65 QString timezone;
66 QArray<int>* child; 66 QArray<int>* child;
67 int parent; 67 int parent;
68}; 68};
69 69
70OEvent::OEvent( int uid ) 70OEvent::OEvent( int uid )
71 : OPimRecord( uid ) { 71 : OPimRecord( uid ) {
72 data = new Data; 72 data = new Data;
73} 73}
74OEvent::OEvent( const OEvent& ev) 74OEvent::OEvent( const OEvent& ev)
75 : OPimRecord( ev ), data( ev.data ) 75 : OPimRecord( ev ), data( ev.data )
76{ 76{
77 data->ref(); 77 data->ref();
78} 78}
79OEvent::~OEvent() { 79OEvent::~OEvent() {
80 if ( data->deref() ) { 80 if ( data->deref() ) {
81 delete data; 81 delete data;
82 data = 0; 82 data = 0;
83 } 83 }
84} 84}
85OEvent& OEvent::operator=( const OEvent& ev) { 85OEvent& OEvent::operator=( const OEvent& ev) {
86 if ( this == &ev ) return *this; 86 if ( this == &ev ) return *this;
87 87
88 OPimRecord::operator=( ev ); 88 OPimRecord::operator=( ev );
89 ev.data->ref(); 89 ev.data->ref();
90 deref(); 90 deref();
91 data = ev.data; 91 data = ev.data;
92 92
93 93
94 return *this; 94 return *this;
95} 95}
96QString OEvent::description()const { 96QString OEvent::description()const {
97 return data->description; 97 return data->description;
98} 98}
99void OEvent::setDescription( const QString& description ) { 99void OEvent::setDescription( const QString& description ) {
100 changeOrModify(); 100 changeOrModify();
101 data->description = description; 101 data->description = description;
102} 102}
103void OEvent::setLocation( const QString& loc ) { 103void OEvent::setLocation( const QString& loc ) {
104 changeOrModify(); 104 changeOrModify();
105 data->location = loc; 105 data->location = loc;
106} 106}
107QString OEvent::location()const { 107QString OEvent::location()const {
108 return data->location; 108 return data->location;
109} 109}
110OPimNotifyManager &OEvent::notifiers()const { 110OPimNotifyManager &OEvent::notifiers()const {
111 // I hope we can skip the changeOrModify here 111 // I hope we can skip the changeOrModify here
112 // the notifier should take care of it 112 // the notifier should take care of it
113 // and OPimNotify is shared too 113 // and OPimNotify is shared too
114 if (!data->manager ) 114 if (!data->manager )
115 data->manager = new OPimNotifyManager; 115 data->manager = new OPimNotifyManager;
116 116
117 return *data->manager; 117 return *data->manager;
118} 118}
119bool OEvent::hasNotifiers()const { 119bool OEvent::hasNotifiers()const {
120 if (!data->manager ) 120 if (!data->manager )
121 return false; 121 return false;
122 if (data->manager->reminders().isEmpty() && 122 if (data->manager->reminders().isEmpty() &&
123 data->manager->alarms().isEmpty() ) 123 data->manager->alarms().isEmpty() )
124 return false; 124 return false;
125 125
126 return true; 126 return true;
127} 127}
128ORecur OEvent::recurrence()const { 128ORecur OEvent::recurrence()const {
129 if (!data->recur) 129 if (!data->recur)
130 data->recur = new ORecur; 130 data->recur = new ORecur;
131 131
132 return *data->recur; 132 return *data->recur;
133} 133}
134void OEvent::setRecurrence( const ORecur& rec) { 134void OEvent::setRecurrence( const ORecur& rec) {
135 changeOrModify(); 135 changeOrModify();
136 if (data->recur ) 136 if (data->recur )
137 (*data->recur) = rec; 137 (*data->recur) = rec;
138 else 138 else
139 data->recur = new ORecur( rec ); 139 data->recur = new ORecur( rec );
140} 140}
141bool OEvent::hasRecurrence()const { 141bool OEvent::hasRecurrence()const {
142 if (!data->recur ) return false; 142 if (!data->recur ) return false;
143 return data->recur->doesRecur(); 143 return data->recur->doesRecur();
144} 144}
145QString OEvent::note()const { 145QString OEvent::note()const {
146 return data->note; 146 return data->note;
147} 147}
148void OEvent::setNote( const QString& note ) { 148void OEvent::setNote( const QString& note ) {
149 changeOrModify(); 149 changeOrModify();
150 data->note = note; 150 data->note = note;
151} 151}
152QDateTime OEvent::createdDateTime()const { 152QDateTime OEvent::createdDateTime()const {
153 return data->created; 153 return data->created;
154} 154}
155void OEvent::setCreatedDateTime( const QDateTime& time ) { 155void OEvent::setCreatedDateTime( const QDateTime& time ) {
156 changeOrModify(); 156 changeOrModify();
157 data->created = time; 157 data->created = time;
158} 158}
159QDateTime OEvent::startDateTime()const { 159QDateTime OEvent::startDateTime()const {
160 if ( data->isAllDay ) 160 if ( data->isAllDay )
161 return QDateTime( data->start.date(), QTime(0, 0, 0 ) ); 161 return QDateTime( data->start.date(), QTime(0, 0, 0 ) );
162 return data->start; 162 return data->start;
163} 163}
164QDateTime OEvent::startDateTimeInZone()const { 164QDateTime OEvent::startDateTimeInZone()const {
165 /* if no timezone, or all day event or if the current and this timeZone match... */ 165 /* if no timezone, or all day event or if the current and this timeZone match... */
166 if (data->timezone.isEmpty() || data->isAllDay || data->timezone == OTimeZone::current().timeZone() ) return startDateTime(); 166 if (data->timezone.isEmpty() || data->isAllDay || data->timezone == OTimeZone::current().timeZone() ) return startDateTime();
167 167
168 OTimeZone zone(data->timezone ); 168 OTimeZone zone(data->timezone );
169 return zone.toDateTime( data->start, OTimeZone::current() ); 169 return zone.toDateTime( data->start, OTimeZone::current() );
170} 170}
171void OEvent::setStartDateTime( const QDateTime& dt ) { 171void OEvent::setStartDateTime( const QDateTime& dt ) {
172 changeOrModify(); 172 changeOrModify();
173 data->start = dt; 173 data->start = dt;
174} 174}
175QDateTime OEvent::endDateTime()const { 175QDateTime OEvent::endDateTime()const {
176 /* 176 /*
177 * if all Day event the end time needs 177 * if all Day event the end time needs
178 * to be on the same day as the start 178 * to be on the same day as the start
179 */ 179 */
180 if ( data->isAllDay ) 180 if ( data->isAllDay )
181 return QDateTime( data->start.date(), QTime(23, 59, 59 ) ); 181 return QDateTime( data->start.date(), QTime(23, 59, 59 ) );
182 return data->end; 182 return data->end;
183} 183}
184QDateTime OEvent::endDateTimeInZone()const { 184QDateTime OEvent::endDateTimeInZone()const {
185 /* if no timezone, or all day event or if the current and this timeZone match... */ 185 /* if no timezone, or all day event or if the current and this timeZone match... */
186 if (data->timezone.isEmpty() || data->isAllDay || data->timezone == OTimeZone::current().timeZone() ) return endDateTime(); 186 if (data->timezone.isEmpty() || data->isAllDay || data->timezone == OTimeZone::current().timeZone() ) return endDateTime();
187 187
188 OTimeZone zone(data->timezone ); 188 OTimeZone zone(data->timezone );
189 return zone.toDateTime( data->end, OTimeZone::current() ); 189 return zone.toDateTime( data->end, OTimeZone::current() );
190} 190}
191void OEvent::setEndDateTime( const QDateTime& dt ) { 191void OEvent::setEndDateTime( const QDateTime& dt ) {
192 changeOrModify(); 192 changeOrModify();
193 data->end = dt; 193 data->end = dt;
194} 194}
195bool OEvent::isMultipleDay()const { 195bool OEvent::isMultipleDay()const {
196 return data->end.date().day() - data->start.date().day(); 196 return data->end.date().day() - data->start.date().day();
197} 197}
198bool OEvent::isAllDay()const { 198bool OEvent::isAllDay()const {
199 return data->isAllDay; 199 return data->isAllDay;
200} 200}
201void OEvent::setAllDay( bool allDay ) { 201void OEvent::setAllDay( bool allDay ) {
202 changeOrModify(); 202 changeOrModify();
203 data->isAllDay = allDay; 203 data->isAllDay = allDay;
204 if (allDay ) data->timezone = "UTC"; 204 if (allDay ) data->timezone = "UTC";
205} 205}
206void OEvent::setTimeZone( const QString& tz ) { 206void OEvent::setTimeZone( const QString& tz ) {
207 changeOrModify(); 207 changeOrModify();
208 data->timezone = tz; 208 data->timezone = tz;
209} 209}
210QString OEvent::timeZone()const { 210QString OEvent::timeZone()const {
211 if (data->isAllDay ) return QString::fromLatin1("UTC"); 211 if (data->isAllDay ) return QString::fromLatin1("UTC");
212 return data->timezone; 212 return data->timezone;
213} 213}
214bool OEvent::match( const QRegExp& re )const { 214bool OEvent::match( const QRegExp& re )const {
215 if ( re.match( data->description ) != -1 ){ 215 if ( re.match( data->description ) != -1 ){
216 setLastHitField( Qtopia::DatebookDescription ); 216 setLastHitField( Qtopia::DatebookDescription );
217 return true; 217 return true;
218 } 218 }
219 if ( re.match( data->note ) != -1 ){ 219 if ( re.match( data->note ) != -1 ){
220 setLastHitField( Qtopia::Note ); 220 setLastHitField( Qtopia::Note );
221 return true; 221 return true;
222 } 222 }
223 if ( re.match( data->location ) != -1 ){ 223 if ( re.match( data->location ) != -1 ){
224 setLastHitField( Qtopia::Location ); 224 setLastHitField( Qtopia::Location );
225 return true; 225 return true;
226 } 226 }
227 if ( re.match( data->start.toString() ) != -1 ){ 227 if ( re.match( data->start.toString() ) != -1 ){
228 setLastHitField( Qtopia::StartDateTime ); 228 setLastHitField( Qtopia::StartDateTime );
229 return true; 229 return true;
230 } 230 }
231 if ( re.match( data->end.toString() ) != -1 ){ 231 if ( re.match( data->end.toString() ) != -1 ){
232 setLastHitField( Qtopia::EndDateTime ); 232 setLastHitField( Qtopia::EndDateTime );
233 return true; 233 return true;
234 } 234 }
235 return false; 235 return false;
236} 236}
237QString OEvent::toRichText()const { 237QString OEvent::toRichText()const {
238 QString text, value; 238 QString text, value;
239 239
240 // description 240 // description
241 text += "<b><h3><img src=\"datebook/DateBook\">"; 241 text += "<b><h3><img src=\"datebook/DateBook\">";
242 if ( !description().isEmpty() ) { 242 if ( !description().isEmpty() ) {
243 text += Qtopia::escapeString(description() ).replace(QRegExp( "[\n]"), "" ); 243 text += Qtopia::escapeString(description() ).replace(QRegExp( "[\n]"), "" );
244 } 244 }
245 text += "</h3></b><br><hr><br>"; 245 text += "</h3></b><br><hr><br>";
246 246
247 // location 247 // location
248 if ( !(value = location()).isEmpty() ) { 248 if ( !(value = location()).isEmpty() ) {
249 text += "<b>" + QObject::tr( "Location:" ) + "</b> "; 249 text += "<b>" + QObject::tr( "Location:" ) + "</b> ";
250 text += Qtopia::escapeString(value) + "<br>"; 250 text += Qtopia::escapeString(value) + "<br>";
251 } 251 }
252 252
253 // all day event 253 // all day event
254 if ( isAllDay() ) { 254 if ( isAllDay() ) {
255 text += "<b><i>" + QObject::tr( "This is an all day event" ) + "</i></b><br>"; 255 text += "<b><i>" + QObject::tr( "This is an all day event" ) + "</i></b><br>";
256 } 256 }
257 // multiple day event 257 // multiple day event
258 else if ( isMultipleDay () ) { 258 else if ( isMultipleDay () ) {
259 text += "<b><i>" + QObject::tr( "This is a multiple day event" ) + "</i></b><br>"; 259 text += "<b><i>" + QObject::tr( "This is a multiple day event" ) + "</i></b><br>";
260 } 260 }
261 // start & end times 261 // start & end times
262 else { 262 else {
263 // start time 263 // start time
264 if ( startDateTime().isValid() ) { 264 if ( startDateTime().isValid() ) {
265 text += "<b>" + QObject::tr( "Start:") + "</b> "; 265 text += "<b>" + QObject::tr( "Start:") + "</b> ";
266 text += Qtopia::escapeString(startDateTime().toString() ). 266 text += Qtopia::escapeString(startDateTime().toString() ).
267 replace(QRegExp( "[\n]"), "<br>" ) + "<br>"; 267 replace(QRegExp( "[\n]"), "<br>" ) + "<br>";
268 } 268 }
269 269
270 // end time 270 // end time
271 if ( endDateTime().isValid() ) { 271 if ( endDateTime().isValid() ) {
272 text += "<b>" + QObject::tr( "End:") + "</b> "; 272 text += "<b>" + QObject::tr( "End:") + "</b> ";
273 text += Qtopia::escapeString(endDateTime().toString() ). 273 text += Qtopia::escapeString(endDateTime().toString() ).
274 replace(QRegExp( "[\n]"), "<br>" ) + "<br>"; 274 replace(QRegExp( "[\n]"), "<br>" ) + "<br>";
275 } 275 }
276 } 276 }
277 277
278 // categories 278 // categories
279 if ( categoryNames("Calendar").count() ){ 279 if ( categoryNames("Calendar").count() ){
280 text += "<b>" + QObject::tr( "Category:") + "</b> "; 280 text += "<b>" + QObject::tr( "Category:") + "</b> ";
281 text += categoryNames("Calendar").join(", "); 281 text += categoryNames("Calendar").join(", ");
282 text += "<br>"; 282 text += "<br>";
283 } 283 }
284 284
285 //notes 285 //notes
286 if ( !note().isEmpty() ) { 286 if ( !note().isEmpty() ) {
287 text += "<b>" + QObject::tr( "Note:") + "</b><br>"; 287 text += "<b>" + QObject::tr( "Note:") + "</b><br>";
288 text += note(); 288 text += note();
289// text += Qtopia::escapeString(note() ). 289// text += Qtopia::escapeString(note() ).
290// replace(QRegExp( "[\n]"), "<br>" ) + "<br>"; 290// replace(QRegExp( "[\n]"), "<br>" ) + "<br>";
291 } 291 }
292 return text; 292 return text;
293} 293}
294QString OEvent::toShortText()const { 294QString OEvent::toShortText()const {
295 QString text; 295 QString text;
296 text += QString::number( startDateTime().date().day() ); 296 text += QString::number( startDateTime().date().day() );
297 text += "."; 297 text += ".";
298 text += QString::number( startDateTime().date().month() ); 298 text += QString::number( startDateTime().date().month() );
299 text += "."; 299 text += ".";
300 text += QString::number( startDateTime().date().year() ); 300 text += QString::number( startDateTime().date().year() );
301 text += " "; 301 text += " ";
302 text += QString::number( startDateTime().time().hour() ); 302 text += QString::number( startDateTime().time().hour() );
303 text += ":"; 303 text += ":";
304 text += QString::number( startDateTime().time().minute() ); 304 text += QString::number( startDateTime().time().minute() );
305 text += " - "; 305 text += " - ";
306 text += description(); 306 text += description();
307 return text; 307 return text;
308} 308}
309QString OEvent::type()const { 309QString OEvent::type()const {
310 return QString::fromLatin1("OEvent"); 310 return QString::fromLatin1("OEvent");
311} 311}
312QString OEvent::recordField( int /*id */ )const { 312QString OEvent::recordField( int /*id */ )const {
313 return QString::null; 313 return QString::null;
314} 314}
315int OEvent::rtti() { 315int OEvent::rtti() {
316 return OPimResolver::DateBook; 316 return OPimResolver::DateBook;
317} 317}
318bool OEvent::loadFromStream( QDataStream& ) { 318bool OEvent::loadFromStream( QDataStream& ) {
319 return true; 319 return true;
320} 320}
321bool OEvent::saveToStream( QDataStream& )const { 321bool OEvent::saveToStream( QDataStream& )const {
322 return true; 322 return true;
323} 323}
324void OEvent::changeOrModify() { 324void OEvent::changeOrModify() {
325 if ( data->count != 1 ) { 325 if ( data->count != 1 ) {
326 data->deref(); 326 data->deref();
327 Data* d2 = new Data; 327 Data* d2 = new Data;
328 d2->description = data->description; 328 d2->description = data->description;
329 d2->location = data->location; 329 d2->location = data->location;
330 330
331 if (data->manager ) 331 if (data->manager )
332 d2->manager = new OPimNotifyManager( *data->manager ); 332 d2->manager = new OPimNotifyManager( *data->manager );
333 333
334 if ( data->recur ) 334 if ( data->recur )
335 d2->recur = new ORecur( *data->recur ); 335 d2->recur = new ORecur( *data->recur );
336 336
337 d2->note = data->note; 337 d2->note = data->note;
338 d2->created = data->created; 338 d2->created = data->created;
339 d2->start = data->start; 339 d2->start = data->start;
340 d2->end = data->end; 340 d2->end = data->end;
341 d2->isAllDay = data->isAllDay; 341 d2->isAllDay = data->isAllDay;
342 d2->timezone = data->timezone; 342 d2->timezone = data->timezone;
343 d2->parent = data->parent; 343 d2->parent = data->parent;
344 344
345 if ( data->child ) { 345 if ( data->child ) {
346 d2->child = new QArray<int>( *data->child ); 346 d2->child = new QArray<int>( *data->child );
347 d2->child->detach(); 347 d2->child->detach();
348 } 348 }
349 349
350 data = d2; 350 data = d2;
351 } 351 }
352} 352}
353void OEvent::deref() { 353void OEvent::deref() {
354 if ( data->deref() ) { 354 if ( data->deref() ) {
355 delete data; 355 delete data;
356 data = 0; 356 data = 0;
357 } 357 }
358} 358}
359// FIXME 359// FIXME
360QMap<int, QString> OEvent::toMap()const { 360QMap<int, QString> OEvent::toMap()const {
361 return QMap<int, QString>(); 361 return QMap<int, QString>();
362} 362}
363QMap<QString, QString> OEvent::toExtraMap()const {
364 return QMap<QString, QString>();
365}
366int OEvent::parent()const { 363int OEvent::parent()const {
367 return data->parent; 364 return data->parent;
368} 365}
369void OEvent::setParent( int uid ) { 366void OEvent::setParent( int uid ) {
370 changeOrModify(); 367 changeOrModify();
371 data->parent = uid; 368 data->parent = uid;
372} 369}
373QArray<int> OEvent::children() const{ 370QArray<int> OEvent::children() const{
374 if (!data->child) return QArray<int>(); 371 if (!data->child) return QArray<int>();
375 else 372 else
376 return data->child->copy(); 373 return data->child->copy();
377} 374}
378void OEvent::setChildren( const QArray<int>& arr ) { 375void OEvent::setChildren( const QArray<int>& arr ) {
379 changeOrModify(); 376 changeOrModify();
380 if (data->child) delete data->child; 377 if (data->child) delete data->child;
381 378
382 data->child = new QArray<int>( arr ); 379 data->child = new QArray<int>( arr );
383 data->child->detach(); 380 data->child->detach();
384} 381}
385void OEvent::addChild( int uid ) { 382void OEvent::addChild( int uid ) {
386 changeOrModify(); 383 changeOrModify();
387 if (!data->child ) { 384 if (!data->child ) {
388 data->child = new QArray<int>(1); 385 data->child = new QArray<int>(1);
389 (*data->child)[0] = uid; 386 (*data->child)[0] = uid;
390 }else{ 387 }else{
391 int count = data->child->count(); 388 int count = data->child->count();
392 data->child->resize( count + 1 ); 389 data->child->resize( count + 1 );
393 (*data->child)[count] = uid; 390 (*data->child)[count] = uid;
394 } 391 }
395} 392}
396void OEvent::removeChild( int uid ) { 393void OEvent::removeChild( int uid ) {
397 if (!data->child || !data->child->contains( uid ) ) return; 394 if (!data->child || !data->child->contains( uid ) ) return;
398 changeOrModify(); 395 changeOrModify();
399 QArray<int> newAr( data->child->count() - 1 ); 396 QArray<int> newAr( data->child->count() - 1 );
400 int j = 0; 397 int j = 0;
401 uint count = data->child->count(); 398 uint count = data->child->count();
402 for ( uint i = 0; i < count; i++ ) { 399 for ( uint i = 0; i < count; i++ ) {
403 if ( (*data->child)[i] != uid ) { 400 if ( (*data->child)[i] != uid ) {
404 newAr[j] = (*data->child)[i]; 401 newAr[j] = (*data->child)[i];
405 j++; 402 j++;
406 } 403 }
407 } 404 }
408 (*data->child) = newAr; 405 (*data->child) = newAr;
409} 406}
410struct OEffectiveEvent::Data : public QShared { 407struct OEffectiveEvent::Data : public QShared {
411 Data() : QShared() { 408 Data() : QShared() {
412 } 409 }
413 OEvent event; 410 OEvent event;
414 QDate date; 411 QDate date;
415 QTime start, end; 412 QTime start, end;
416 QDate startDate, endDate; 413 QDate startDate, endDate;
417 bool dates : 1; 414 bool dates : 1;
418}; 415};
419 416
420OEffectiveEvent::OEffectiveEvent() { 417OEffectiveEvent::OEffectiveEvent() {
421 data = new Data; 418 data = new Data;
422 data->date = QDate::currentDate(); 419 data->date = QDate::currentDate();
423 data->start = data->end = QTime::currentTime(); 420 data->start = data->end = QTime::currentTime();
424 data->dates = false; 421 data->dates = false;
425} 422}
426OEffectiveEvent::OEffectiveEvent( const OEvent& ev, const QDate& startDate, 423OEffectiveEvent::OEffectiveEvent( const OEvent& ev, const QDate& startDate,
427 Position pos ) { 424 Position pos ) {
428 data = new Data; 425 data = new Data;
429 data->event = ev; 426 data->event = ev;
430 data->date = startDate; 427 data->date = startDate;
431 if ( pos & Start ) 428 if ( pos & Start )
432 data->start = ev.startDateTime().time(); 429 data->start = ev.startDateTime().time();
433 else 430 else
434 data->start = QTime( 0, 0, 0 ); 431 data->start = QTime( 0, 0, 0 );
435 432
436 if ( pos & End ) 433 if ( pos & End )
437 data->end = ev.endDateTime().time(); 434 data->end = ev.endDateTime().time();
438 else 435 else
439 data->end = QTime( 23, 59, 59 ); 436 data->end = QTime( 23, 59, 59 );
440 437
441 data->dates = false; 438 data->dates = false;
442} 439}
443OEffectiveEvent::OEffectiveEvent( const OEffectiveEvent& ev) { 440OEffectiveEvent::OEffectiveEvent( const OEffectiveEvent& ev) {
444 data = ev.data; 441 data = ev.data;
445 data->ref(); 442 data->ref();
446} 443}
447OEffectiveEvent::~OEffectiveEvent() { 444OEffectiveEvent::~OEffectiveEvent() {
448 if ( data->deref() ) { 445 if ( data->deref() ) {
449 delete data; 446 delete data;
450 data = 0; 447 data = 0;
451 } 448 }
452} 449}
453OEffectiveEvent& OEffectiveEvent::operator=( const OEffectiveEvent& ev ) { 450OEffectiveEvent& OEffectiveEvent::operator=( const OEffectiveEvent& ev ) {
454 if ( *this == ev ) return *this; 451 if ( *this == ev ) return *this;
455 452
456 ev.data->ref(); 453 ev.data->ref();
457 deref(); 454 deref();
458 data = ev.data; 455 data = ev.data;
459 456
460 return *this; 457 return *this;
461} 458}
462 459
463void OEffectiveEvent::setStartTime( const QTime& ti) { 460void OEffectiveEvent::setStartTime( const QTime& ti) {
464 changeOrModify(); 461 changeOrModify();
465 data->start = ti; 462 data->start = ti;
466} 463}
467void OEffectiveEvent::setEndTime( const QTime& en) { 464void OEffectiveEvent::setEndTime( const QTime& en) {
468 changeOrModify(); 465 changeOrModify();
469 data->end = en; 466 data->end = en;
470} 467}
471void OEffectiveEvent::setEvent( const OEvent& ev) { 468void OEffectiveEvent::setEvent( const OEvent& ev) {
472 changeOrModify(); 469 changeOrModify();
473 data->event = ev; 470 data->event = ev;
474} 471}
475void OEffectiveEvent::setDate( const QDate& da) { 472void OEffectiveEvent::setDate( const QDate& da) {
476 changeOrModify(); 473 changeOrModify();
477 data->date = da; 474 data->date = da;
478} 475}
479void OEffectiveEvent::setEffectiveDates( const QDate& from, 476void OEffectiveEvent::setEffectiveDates( const QDate& from,
480 const QDate& to ) { 477 const QDate& to ) {
481 if (!from.isValid() ) { 478 if (!from.isValid() ) {
482 data->dates = false; 479 data->dates = false;
483 return; 480 return;
484 } 481 }
485 482
486 data->startDate = from; 483 data->startDate = from;
487 data->endDate = to; 484 data->endDate = to;
488} 485}
489QString OEffectiveEvent::description()const { 486QString OEffectiveEvent::description()const {
490 return data->event.description(); 487 return data->event.description();
491} 488}
492QString OEffectiveEvent::location()const { 489QString OEffectiveEvent::location()const {
493 return data->event.location(); 490 return data->event.location();
494} 491}
495QString OEffectiveEvent::note()const { 492QString OEffectiveEvent::note()const {
496 return data->event.note(); 493 return data->event.note();
497} 494}
498OEvent OEffectiveEvent::event()const { 495OEvent OEffectiveEvent::event()const {
499 return data->event; 496 return data->event;
500} 497}
501QTime OEffectiveEvent::startTime()const { 498QTime OEffectiveEvent::startTime()const {
502 return data->start; 499 return data->start;
503} 500}
504QTime OEffectiveEvent::endTime()const { 501QTime OEffectiveEvent::endTime()const {
505 return data->end; 502 return data->end;
506} 503}
507QDate OEffectiveEvent::date()const { 504QDate OEffectiveEvent::date()const {
508 return data->date; 505 return data->date;
509} 506}
510int OEffectiveEvent::length()const { 507int OEffectiveEvent::length()const {
511 return (data->end.hour() * 60 - data->start.hour() * 60) 508 return (data->end.hour() * 60 - data->start.hour() * 60)
512 + QABS(data->start.minute() - data->end.minute() ); 509 + QABS(data->start.minute() - data->end.minute() );
513} 510}
514int OEffectiveEvent::size()const { 511int OEffectiveEvent::size()const {
515 return ( data->end.hour() - data->start.hour() ) * 3600 512 return ( data->end.hour() - data->start.hour() ) * 3600
516 + (data->end.minute() - data->start.minute() * 60 513 + (data->end.minute() - data->start.minute() * 60
517 + data->end.second() - data->start.second() ); 514 + data->end.second() - data->start.second() );
518} 515}
519QDate OEffectiveEvent::startDate()const { 516QDate OEffectiveEvent::startDate()const {
520 if ( data->dates ) 517 if ( data->dates )
521 return data->startDate; 518 return data->startDate;
522 else if ( data->event.hasRecurrence() ) // single day, since multi-day should have a d pointer 519 else if ( data->event.hasRecurrence() ) // single day, since multi-day should have a d pointer
523 return data->date; 520 return data->date;
524 else 521 else
525 return data->event.startDateTime().date(); 522 return data->event.startDateTime().date();
526} 523}
527QDate OEffectiveEvent::endDate()const { 524QDate OEffectiveEvent::endDate()const {
528 if ( data->dates ) 525 if ( data->dates )
529 return data->endDate; 526 return data->endDate;
530 else if ( data->event.hasRecurrence() ) 527 else if ( data->event.hasRecurrence() )
531 return data->date; 528 return data->date;
532 else 529 else
533 return data->event.endDateTime().date(); 530 return data->event.endDateTime().date();
534} 531}
535void OEffectiveEvent::deref() { 532void OEffectiveEvent::deref() {
536 if ( data->deref() ) { 533 if ( data->deref() ) {
537 delete data; 534 delete data;
538 data = 0; 535 data = 0;
539 } 536 }
540} 537}
541void OEffectiveEvent::changeOrModify() { 538void OEffectiveEvent::changeOrModify() {
542 if ( data->count != 1 ) { 539 if ( data->count != 1 ) {
543 data->deref(); 540 data->deref();
544 Data* d2 = new Data; 541 Data* d2 = new Data;
545 d2->event = data->event; 542 d2->event = data->event;
546 d2->date = data->date; 543 d2->date = data->date;
547 d2->start = data->start; 544 d2->start = data->start;
548 d2->end = data->end; 545 d2->end = data->end;
549 d2->startDate = data->startDate; 546 d2->startDate = data->startDate;
550 d2->endDate = data->endDate; 547 d2->endDate = data->endDate;
551 d2->dates = data->dates; 548 d2->dates = data->dates;
552 data = d2; 549 data = d2;
553 } 550 }
554} 551}
555bool OEffectiveEvent::operator<( const OEffectiveEvent &e ) const{ 552bool OEffectiveEvent::operator<( const OEffectiveEvent &e ) const{
556 if ( data->date < e.date() ) 553 if ( data->date < e.date() )
557 return TRUE; 554 return TRUE;
558 if ( data->date == e.date() ) 555 if ( data->date == e.date() )
559 return ( startTime() < e.startTime() ); 556 return ( startTime() < e.startTime() );
560 else 557 else
561 return FALSE; 558 return FALSE;
562} 559}
563bool OEffectiveEvent::operator<=( const OEffectiveEvent &e ) const{ 560bool OEffectiveEvent::operator<=( const OEffectiveEvent &e ) const{
564 return (data->date <= e.date() ); 561 return (data->date <= e.date() );
565} 562}
566bool OEffectiveEvent::operator==( const OEffectiveEvent &e ) const { 563bool OEffectiveEvent::operator==( const OEffectiveEvent &e ) const {
567 return ( date() == e.date() 564 return ( date() == e.date()
568 && startTime() == e.startTime() 565 && startTime() == e.startTime()
569 && endTime()== e.endTime() 566 && endTime()== e.endTime()
570 && event() == e.event() ); 567 && event() == e.event() );
571} 568}
572bool OEffectiveEvent::operator!=( const OEffectiveEvent &e ) const { 569bool OEffectiveEvent::operator!=( const OEffectiveEvent &e ) const {
573 return !(*this == e ); 570 return !(*this == e );
574} 571}
575bool OEffectiveEvent::operator>( const OEffectiveEvent &e ) const { 572bool OEffectiveEvent::operator>( const OEffectiveEvent &e ) const {
576 return !(*this <= e ); 573 return !(*this <= e );
577} 574}
578bool OEffectiveEvent::operator>= ( const OEffectiveEvent &e ) const { 575bool OEffectiveEvent::operator>= ( const OEffectiveEvent &e ) const {
579 return !(*this < e); 576 return !(*this < e);
580} 577}
diff --git a/libopie/pim/oevent.h b/libopie/pim/oevent.h
index b696d81..30f442e 100644
--- a/libopie/pim/oevent.h
+++ b/libopie/pim/oevent.h
@@ -1,221 +1,220 @@
1// CONTAINS GPLed code of TT 1// CONTAINS GPLed code of TT
2 2
3#ifndef OPIE_PIM_EVENT_H 3#ifndef OPIE_PIM_EVENT_H
4#define OPIE_PIM_EVENT_H 4#define OPIE_PIM_EVENT_H
5 5
6#include <qstring.h> 6#include <qstring.h>
7#include <qdatetime.h> 7#include <qdatetime.h>
8#include <qvaluelist.h> 8#include <qvaluelist.h>
9 9
10#include <qpe/recordfields.h> 10#include <qpe/recordfields.h>
11#include <qpe/palmtopuidgen.h> 11#include <qpe/palmtopuidgen.h>
12 12
13#include "otimezone.h" 13#include "otimezone.h"
14#include "opimrecord.h" 14#include "opimrecord.h"
15 15
16struct OCalendarHelper { 16struct OCalendarHelper {
17 /** calculate the week number of the date */ 17 /** calculate the week number of the date */
18 static int week( const QDate& ); 18 static int week( const QDate& );
19 /** calculate the occurence of week days since the start of the month */ 19 /** calculate the occurence of week days since the start of the month */
20 static int ocurrence( const QDate& ); 20 static int ocurrence( const QDate& );
21 21
22 // returns the dayOfWeek for the *first* day it finds (ignores 22 // returns the dayOfWeek for the *first* day it finds (ignores
23 // any further days!). Returns 1 (Monday) if there isn't any day found 23 // any further days!). Returns 1 (Monday) if there isn't any day found
24 static int dayOfWeek( char day ); 24 static int dayOfWeek( char day );
25 25
26 /** returns the diff of month */ 26 /** returns the diff of month */
27 static int monthDiff( const QDate& first, const QDate& second ); 27 static int monthDiff( const QDate& first, const QDate& second );
28 28
29}; 29};
30 30
31class OPimNotifyManager; 31class OPimNotifyManager;
32class ORecur; 32class ORecur;
33 33
34/** 34/**
35 * This is the container for all Events. It encapsules all 35 * This is the container for all Events. It encapsules all
36 * available information for a single Event 36 * available information for a single Event
37 * @short container for events. 37 * @short container for events.
38 */ 38 */
39class OEvent : public OPimRecord { 39class OEvent : public OPimRecord {
40public: 40public:
41 typedef QValueList<OEvent> ValueList; 41 typedef QValueList<OEvent> ValueList;
42 /** 42 /**
43 * RecordFields contain possible attributes 43 * RecordFields contain possible attributes
44 */ 44 */
45 enum RecordFields { 45 enum RecordFields {
46 Uid = Qtopia::UID_ID, 46 Uid = Qtopia::UID_ID,
47 Category = Qtopia::CATEGORY_ID, 47 Category = Qtopia::CATEGORY_ID,
48 Description, 48 Description,
49 Location, 49 Location,
50 Alarm, 50 Alarm,
51 Reminder, 51 Reminder,
52 Recurrence, 52 Recurrence,
53 Note, 53 Note,
54 Created, 54 Created,
55 StartDate, 55 StartDate,
56 EndDate, 56 EndDate,
57 AllDay, 57 AllDay,
58 TimeZone 58 TimeZone
59 }; 59 };
60 60
61 /** 61 /**
62 * Start with an Empty OEvent. UID == 0 means that it is empty 62 * Start with an Empty OEvent. UID == 0 means that it is empty
63 */ 63 */
64 OEvent(int uid = 0); 64 OEvent(int uid = 0);
65 65
66 /** 66 /**
67 * copy c'tor 67 * copy c'tor
68 */ 68 */
69 OEvent( const OEvent& ); 69 OEvent( const OEvent& );
70 ~OEvent(); 70 ~OEvent();
71 OEvent &operator=( const OEvent& ); 71 OEvent &operator=( const OEvent& );
72 72
73 QString description()const; 73 QString description()const;
74 void setDescription( const QString& description ); 74 void setDescription( const QString& description );
75 75
76 QString location()const; 76 QString location()const;
77 void setLocation( const QString& loc ); 77 void setLocation( const QString& loc );
78 78
79 bool hasNotifiers()const; 79 bool hasNotifiers()const;
80 OPimNotifyManager &notifiers()const; 80 OPimNotifyManager &notifiers()const;
81 81
82 ORecur recurrence()const; 82 ORecur recurrence()const;
83 void setRecurrence( const ORecur& ); 83 void setRecurrence( const ORecur& );
84 bool hasRecurrence()const; 84 bool hasRecurrence()const;
85 85
86 QString note()const; 86 QString note()const;
87 void setNote( const QString& note ); 87 void setNote( const QString& note );
88 88
89 89
90 QDateTime createdDateTime()const; 90 QDateTime createdDateTime()const;
91 void setCreatedDateTime( const QDateTime& dt); 91 void setCreatedDateTime( const QDateTime& dt);
92 92
93 /** set the date to dt. dt is the QDateTime in localtime */ 93 /** set the date to dt. dt is the QDateTime in localtime */
94 void setStartDateTime( const QDateTime& ); 94 void setStartDateTime( const QDateTime& );
95 /** returns the datetime in the local timeZone */ 95 /** returns the datetime in the local timeZone */
96 QDateTime startDateTime()const; 96 QDateTime startDateTime()const;
97 97
98 /** returns the start datetime in the current zone */ 98 /** returns the start datetime in the current zone */
99 QDateTime startDateTimeInZone()const; 99 QDateTime startDateTimeInZone()const;
100 100
101 /** in current timezone */ 101 /** in current timezone */
102 void setEndDateTime( const QDateTime& ); 102 void setEndDateTime( const QDateTime& );
103 /** in current timezone */ 103 /** in current timezone */
104 QDateTime endDateTime()const; 104 QDateTime endDateTime()const;
105 QDateTime endDateTimeInZone()const; 105 QDateTime endDateTimeInZone()const;
106 106
107 bool isMultipleDay()const; 107 bool isMultipleDay()const;
108 bool isAllDay()const; 108 bool isAllDay()const;
109 void setAllDay( bool isAllDay ); 109 void setAllDay( bool isAllDay );
110 110
111 /* pin this event to a timezone! FIXME */ 111 /* pin this event to a timezone! FIXME */
112 void setTimeZone( const QString& timeZone ); 112 void setTimeZone( const QString& timeZone );
113 QString timeZone()const; 113 QString timeZone()const;
114 114
115 115
116 virtual bool match( const QRegExp& )const; 116 virtual bool match( const QRegExp& )const;
117 117
118 /** For exception to recurrence here is a list of children... */ 118 /** For exception to recurrence here is a list of children... */
119 QArray<int> children()const; 119 QArray<int> children()const;
120 void setChildren( const QArray<int>& ); 120 void setChildren( const QArray<int>& );
121 void addChild( int uid ); 121 void addChild( int uid );
122 void removeChild( int uid ); 122 void removeChild( int uid );
123 123
124 /** return the parent OEvent */ 124 /** return the parent OEvent */
125 int parent()const; 125 int parent()const;
126 void setParent( int uid ); 126 void setParent( int uid );
127 127
128 128
129 /* needed reimp */ 129 /* needed reimp */
130 QString toRichText()const; 130 QString toRichText()const;
131 QString toShortText()const; 131 QString toShortText()const;
132 QString type()const; 132 QString type()const;
133 133
134 QMap<int, QString> toMap()const; 134 QMap<int, QString> toMap()const;
135 QMap<QString, QString> toExtraMap()const;
136 QString recordField(int )const; 135 QString recordField(int )const;
137 136
138 static int rtti(); 137 static int rtti();
139 138
140 bool loadFromStream( QDataStream& ); 139 bool loadFromStream( QDataStream& );
141 bool saveToStream( QDataStream& )const; 140 bool saveToStream( QDataStream& )const;
142 141
143/* bool operator==( const OEvent& ); 142/* bool operator==( const OEvent& );
144 bool operator!=( const OEvent& ); 143 bool operator!=( const OEvent& );
145 bool operator<( const OEvent& ); 144 bool operator<( const OEvent& );
146 bool operator<=( const OEvent& ); 145 bool operator<=( const OEvent& );
147 bool operator>( const OEvent& ); 146 bool operator>( const OEvent& );
148 bool operator>=(const OEvent& ); 147 bool operator>=(const OEvent& );
149*/ 148*/
150private: 149private:
151 inline void changeOrModify(); 150 inline void changeOrModify();
152 void deref(); 151 void deref();
153 struct Data; 152 struct Data;
154 Data* data; 153 Data* data;
155 class Private; 154 class Private;
156 Private* priv; 155 Private* priv;
157 156
158}; 157};
159 158
160/** 159/**
161 * AN Event can span through multiple days. We split up a multiday eve 160 * AN Event can span through multiple days. We split up a multiday eve
162 */ 161 */
163class OEffectiveEvent { 162class OEffectiveEvent {
164public: 163public:
165 typedef QValueList<OEffectiveEvent> ValueList; 164 typedef QValueList<OEffectiveEvent> ValueList;
166 enum Position { MidWay, Start, End, StartEnd }; 165 enum Position { MidWay, Start, End, StartEnd };
167 // If we calculate the effective event of a multi-day event 166 // If we calculate the effective event of a multi-day event
168 // we have to figure out whether we are at the first day, 167 // we have to figure out whether we are at the first day,
169 // at the end, or anywhere else ("middle"). This is important 168 // at the end, or anywhere else ("middle"). This is important
170 // for the start/end times (00:00/23:59) 169 // for the start/end times (00:00/23:59)
171 // MidWay: 00:00 -> 23:59, as we are "in the middle" of a multi- 170 // MidWay: 00:00 -> 23:59, as we are "in the middle" of a multi-
172 // day event 171 // day event
173 // Start: start time -> 23:59 172 // Start: start time -> 23:59
174 // End: 00:00 -> end time 173 // End: 00:00 -> end time
175 // Start | End == StartEnd: for single-day events (default) 174 // Start | End == StartEnd: for single-day events (default)
176 // here we draw start time -> end time 175 // here we draw start time -> end time
177 OEffectiveEvent(); 176 OEffectiveEvent();
178 OEffectiveEvent( const OEvent& event, const QDate& startDate, Position pos = StartEnd ); 177 OEffectiveEvent( const OEvent& event, const QDate& startDate, Position pos = StartEnd );
179 OEffectiveEvent( const OEffectiveEvent& ); 178 OEffectiveEvent( const OEffectiveEvent& );
180 OEffectiveEvent &operator=(const OEffectiveEvent& ); 179 OEffectiveEvent &operator=(const OEffectiveEvent& );
181 ~OEffectiveEvent(); 180 ~OEffectiveEvent();
182 181
183 void setStartTime( const QTime& ); 182 void setStartTime( const QTime& );
184 void setEndTime( const QTime& ); 183 void setEndTime( const QTime& );
185 void setEvent( const OEvent& ); 184 void setEvent( const OEvent& );
186 void setDate( const QDate& ); 185 void setDate( const QDate& );
187 186
188 void setEffectiveDates( const QDate& from, const QDate& to ); 187 void setEffectiveDates( const QDate& from, const QDate& to );
189 188
190 QString description()const; 189 QString description()const;
191 QString location()const; 190 QString location()const;
192 QString note()const; 191 QString note()const;
193 OEvent event()const; 192 OEvent event()const;
194 QTime startTime()const; 193 QTime startTime()const;
195 QTime endTime()const; 194 QTime endTime()const;
196 QDate date()const; 195 QDate date()const;
197 196
198 /* return the length in hours */ 197 /* return the length in hours */
199 int length()const; 198 int length()const;
200 int size()const; 199 int size()const;
201 200
202 QDate startDate()const; 201 QDate startDate()const;
203 QDate endDate()const; 202 QDate endDate()const;
204 203
205 bool operator<( const OEffectiveEvent &e ) const; 204 bool operator<( const OEffectiveEvent &e ) const;
206 bool operator<=( const OEffectiveEvent &e ) const; 205 bool operator<=( const OEffectiveEvent &e ) const;
207 bool operator==( const OEffectiveEvent &e ) const; 206 bool operator==( const OEffectiveEvent &e ) const;
208 bool operator!=( const OEffectiveEvent &e ) const; 207 bool operator!=( const OEffectiveEvent &e ) const;
209 bool operator>( const OEffectiveEvent &e ) const; 208 bool operator>( const OEffectiveEvent &e ) const;
210 bool operator>= ( const OEffectiveEvent &e ) const; 209 bool operator>= ( const OEffectiveEvent &e ) const;
211 210
212private: 211private:
213 void deref(); 212 void deref();
214 inline void changeOrModify(); 213 inline void changeOrModify();
215 class Private; 214 class Private;
216 Private* priv; 215 Private* priv;
217 struct Data; 216 struct Data;
218 Data* data; 217 Data* data;
219 218
220}; 219};
221#endif 220#endif
diff --git a/libopie/pim/opimrecord.cpp b/libopie/pim/opimrecord.cpp
index 0c9734d..2365748 100644
--- a/libopie/pim/opimrecord.cpp
+++ b/libopie/pim/opimrecord.cpp
@@ -1,176 +1,182 @@
1#include <qarray.h> 1#include <qarray.h>
2 2
3#include <qpe/categories.h> 3#include <qpe/categories.h>
4#include <qpe/categoryselect.h> 4#include <qpe/categoryselect.h>
5 5
6#include "opimrecord.h" 6#include "opimrecord.h"
7 7
8Qtopia::UidGen OPimRecord::m_uidGen( Qtopia::UidGen::Qtopia ); 8Qtopia::UidGen OPimRecord::m_uidGen( Qtopia::UidGen::Qtopia );
9 9
10 10
11OPimRecord::OPimRecord( int uid ) 11OPimRecord::OPimRecord( int uid )
12 : Qtopia::Record() { 12 : Qtopia::Record() {
13 13
14 m_lastHit = -1; 14 m_lastHit = -1;
15 setUid( uid ); 15 setUid( uid );
16} 16}
17OPimRecord::~OPimRecord() { 17OPimRecord::~OPimRecord() {
18} 18}
19OPimRecord::OPimRecord( const OPimRecord& rec ) 19OPimRecord::OPimRecord( const OPimRecord& rec )
20 : Qtopia::Record( rec ) 20 : Qtopia::Record( rec )
21{ 21{
22 (*this) = rec; 22 (*this) = rec;
23} 23}
24 24
25OPimRecord &OPimRecord::operator=( const OPimRecord& rec) { 25OPimRecord &OPimRecord::operator=( const OPimRecord& rec) {
26 if ( this == &rec ) return *this; 26 if ( this == &rec ) return *this;
27 27
28 Qtopia::Record::operator=( rec ); 28 Qtopia::Record::operator=( rec );
29 m_xrefman = rec.m_xrefman; 29 m_xrefman = rec.m_xrefman;
30 m_lastHit = rec.m_lastHit; 30 m_lastHit = rec.m_lastHit;
31 31
32 return *this; 32 return *this;
33} 33}
34/* 34/*
35 * category names 35 * category names
36 */ 36 */
37QStringList OPimRecord::categoryNames( const QString& appname ) const { 37QStringList OPimRecord::categoryNames( const QString& appname ) const {
38 QStringList list; 38 QStringList list;
39 QArray<int> cats = categories(); 39 QArray<int> cats = categories();
40 Categories catDB; 40 Categories catDB;
41 catDB.load( categoryFileName() ); 41 catDB.load( categoryFileName() );
42 42
43 for (uint i = 0; i < cats.count(); i++ ) { 43 for (uint i = 0; i < cats.count(); i++ ) {
44 list << catDB.label( appname, cats[i] ); 44 list << catDB.label( appname, cats[i] );
45 } 45 }
46 46
47 return list; 47 return list;
48} 48}
49void OPimRecord::setCategoryNames( const QStringList& ) { 49void OPimRecord::setCategoryNames( const QStringList& ) {
50 50
51} 51}
52void OPimRecord::addCategoryName( const QString& ) { 52void OPimRecord::addCategoryName( const QString& ) {
53 Categories catDB; 53 Categories catDB;
54 catDB.load( categoryFileName() ); 54 catDB.load( categoryFileName() );
55 55
56 56
57} 57}
58bool OPimRecord::isEmpty()const { 58bool OPimRecord::isEmpty()const {
59 return ( uid() == 0 ); 59 return ( uid() == 0 );
60} 60}
61/*QString OPimRecord::crossToString()const { 61/*QString OPimRecord::crossToString()const {
62 QString str; 62 QString str;
63 QMap<QString, QArray<int> >::ConstIterator it; 63 QMap<QString, QArray<int> >::ConstIterator it;
64 for (it = m_relations.begin(); it != m_relations.end(); ++it ) { 64 for (it = m_relations.begin(); it != m_relations.end(); ++it ) {
65 QArray<int> id = it.data(); 65 QArray<int> id = it.data();
66 for ( uint i = 0; i < id.size(); ++i ) { 66 for ( uint i = 0; i < id.size(); ++i ) {
67 str += it.key() + "," + QString::number( i ) + ";"; 67 str += it.key() + "," + QString::number( i ) + ";";
68 } 68 }
69 } 69 }
70 str = str.remove( str.length()-1, 1); // strip the ; 70 str = str.remove( str.length()-1, 1); // strip the ;
71 //qWarning("IDS " + str ); 71 //qWarning("IDS " + str );
72 72
73 return str; 73 return str;
74 }*/ 74 }*/
75/* if uid = 1 assign a new one */ 75/* if uid = 1 assign a new one */
76void OPimRecord::setUid( int uid ) { 76void OPimRecord::setUid( int uid ) {
77 if ( uid == 1) 77 if ( uid == 1)
78 uid = uidGen().generate(); 78 uid = uidGen().generate();
79 79
80 Qtopia::Record::setUid( uid ); 80 Qtopia::Record::setUid( uid );
81}; 81};
82Qtopia::UidGen &OPimRecord::uidGen() { 82Qtopia::UidGen &OPimRecord::uidGen() {
83 return m_uidGen; 83 return m_uidGen;
84} 84}
85OPimXRefManager &OPimRecord::xrefmanager() { 85OPimXRefManager &OPimRecord::xrefmanager() {
86 return m_xrefman; 86 return m_xrefman;
87} 87}
88int OPimRecord::rtti(){ 88int OPimRecord::rtti(){
89 return 0; 89 return 0;
90} 90}
91 91
92/** 92/**
93 * now let's put our data into the stream 93 * now let's put our data into the stream
94 */ 94 */
95/* 95/*
96 * First read UID 96 * First read UID
97 * Categories 97 * Categories
98 * XRef 98 * XRef
99 */ 99 */
100bool OPimRecord::loadFromStream( QDataStream& stream ) { 100bool OPimRecord::loadFromStream( QDataStream& stream ) {
101 int Int; 101 int Int;
102 uint UInt; 102 uint UInt;
103 stream >> Int; 103 stream >> Int;
104 setUid(Int); 104 setUid(Int);
105 105
106 /** Categories */ 106 /** Categories */
107 stream >> UInt; 107 stream >> UInt;
108 QArray<int> array(UInt); 108 QArray<int> array(UInt);
109 for (uint i = 0; i < UInt; i++ ) { 109 for (uint i = 0; i < UInt; i++ ) {
110 stream >> array[i]; 110 stream >> array[i];
111 } 111 }
112 setCategories( array ); 112 setCategories( array );
113 113
114 /* 114 /*
115 * now we do the X-Ref stuff 115 * now we do the X-Ref stuff
116 */ 116 */
117 OPimXRef xref; 117 OPimXRef xref;
118 stream >> UInt; 118 stream >> UInt;
119 for ( uint i = 0; i < UInt; i++ ) { 119 for ( uint i = 0; i < UInt; i++ ) {
120 xref.setPartner( OPimXRef::One, partner( stream ) ); 120 xref.setPartner( OPimXRef::One, partner( stream ) );
121 xref.setPartner( OPimXRef::Two, partner( stream ) ); 121 xref.setPartner( OPimXRef::Two, partner( stream ) );
122 m_xrefman.add( xref ); 122 m_xrefman.add( xref );
123 } 123 }
124 124
125 return true; 125 return true;
126} 126}
127bool OPimRecord::saveToStream( QDataStream& stream )const { 127bool OPimRecord::saveToStream( QDataStream& stream )const {
128 /** UIDs */ 128 /** UIDs */
129 129
130 stream << uid(); 130 stream << uid();
131 131
132 /** Categories */ 132 /** Categories */
133 stream << categories().count(); 133 stream << categories().count();
134 for ( uint i = 0; i < categories().count(); i++ ) { 134 for ( uint i = 0; i < categories().count(); i++ ) {
135 stream << categories()[i]; 135 stream << categories()[i];
136 } 136 }
137 137
138 /* 138 /*
139 * first the XRef count 139 * first the XRef count
140 * then the xrefs 140 * then the xrefs
141 */ 141 */
142 stream << m_xrefman.list().count(); 142 stream << m_xrefman.list().count();
143 for ( OPimXRef::ValueList::ConstIterator it = m_xrefman.list().begin(); 143 for ( OPimXRef::ValueList::ConstIterator it = m_xrefman.list().begin();
144 it != m_xrefman.list().end(); ++it ) { 144 it != m_xrefman.list().end(); ++it ) {
145 flush( (*it).partner( OPimXRef::One), stream ); 145 flush( (*it).partner( OPimXRef::One), stream );
146 flush( (*it).partner( OPimXRef::Two), stream ); 146 flush( (*it).partner( OPimXRef::Two), stream );
147 } 147 }
148 return true; 148 return true;
149} 149}
150void OPimRecord::flush( const OPimXRefPartner& par, QDataStream& str ) const{ 150void OPimRecord::flush( const OPimXRefPartner& par, QDataStream& str ) const{
151 str << par.service(); 151 str << par.service();
152 str << par.uid(); 152 str << par.uid();
153 str << par.field(); 153 str << par.field();
154} 154}
155OPimXRefPartner OPimRecord::partner( QDataStream& stream ) { 155OPimXRefPartner OPimRecord::partner( QDataStream& stream ) {
156 OPimXRefPartner par; 156 OPimXRefPartner par;
157 QString str; 157 QString str;
158 int i; 158 int i;
159 159
160 stream >> str; 160 stream >> str;
161 par.setService( str ); 161 par.setService( str );
162 162
163 stream >> i; 163 stream >> i;
164 par.setUid( i ); 164 par.setUid( i );
165 165
166 stream >> i ; 166 stream >> i ;
167 par.setField( i ); 167 par.setField( i );
168 168
169 return par; 169 return par;
170} 170}
171void OPimRecord::setLastHitField( int lastHit )const { 171void OPimRecord::setLastHitField( int lastHit )const {
172 m_lastHit = lastHit; 172 m_lastHit = lastHit;
173} 173}
174int OPimRecord::lastHitField()const{ 174int OPimRecord::lastHitField()const{
175 return m_lastHit; 175 return m_lastHit;
176} 176}
177QMap<QString, QString> OPimRecord::toExtraMap()const {
178 return customMap;
179}
180void OPimRecord::setExtraMap( const QMap<QString, QString>& map) {
181 customMap = map;
182}
diff --git a/libopie/pim/opimrecord.h b/libopie/pim/opimrecord.h
index 494c78e..563b19c 100644
--- a/libopie/pim/opimrecord.h
+++ b/libopie/pim/opimrecord.h
@@ -1,151 +1,157 @@
1#ifndef OPIE_PIM_RECORD_H 1#ifndef OPIE_PIM_RECORD_H
2#define OPIE_PIM_RECORD_H 2#define OPIE_PIM_RECORD_H
3 3
4#include <qdatastream.h> 4#include <qdatastream.h>
5#include <qmap.h> 5#include <qmap.h>
6#include <qstring.h> 6#include <qstring.h>
7#include <qstringlist.h> 7#include <qstringlist.h>
8 8
9/*
10 * we need to get customMap which is private...
11 */
12#define private protected
9#include <qpe/palmtoprecord.h> 13#include <qpe/palmtoprecord.h>
14#undef private
10 15
11#include <opie/opimxrefmanager.h> 16#include <opie/opimxrefmanager.h>
12 17
13/** 18/**
14 * This is the base class for 19 * This is the base class for
15 * all PIM Records 20 * all PIM Records
16 * 21 *
17 */ 22 */
18class OPimRecord : public Qtopia::Record { 23class OPimRecord : public Qtopia::Record {
19public: 24public:
20 /** 25 /**
21 * c'tor 26 * c'tor
22 * uid of 0 isEmpty 27 * uid of 0 isEmpty
23 * uid of 1 will be assigned a new one 28 * uid of 1 will be assigned a new one
24 */ 29 */
25 OPimRecord(int uid = 0); 30 OPimRecord(int uid = 0);
26 ~OPimRecord(); 31 ~OPimRecord();
27 32
28 /** 33 /**
29 * copy c'tor 34 * copy c'tor
30 */ 35 */
31 OPimRecord( const OPimRecord& rec ); 36 OPimRecord( const OPimRecord& rec );
32 37
33 /** 38 /**
34 * copy operator 39 * copy operator
35 */ 40 */
36 OPimRecord &operator=( const OPimRecord& ); 41 OPimRecord &operator=( const OPimRecord& );
37 42
38 /** 43 /**
39 * category names resolved 44 * category names resolved
40 */ 45 */
41 QStringList categoryNames( const QString& appname )const; 46 QStringList categoryNames( const QString& appname )const;
42 47
43 /** 48 /**
44 * set category names they will be resolved 49 * set category names they will be resolved
45 */ 50 */
46 void setCategoryNames( const QStringList& ); 51 void setCategoryNames( const QStringList& );
47 52
48 /** 53 /**
49 * addCategoryName adds a name 54 * addCategoryName adds a name
50 * to the internal category list 55 * to the internal category list
51 */ 56 */
52 void addCategoryName( const QString& ); 57 void addCategoryName( const QString& );
53 58
54 /** 59 /**
55 * if a Record isEmpty 60 * if a Record isEmpty
56 * it's empty if it's 0 61 * it's empty if it's 0
57 */ 62 */
58 virtual bool isEmpty()const; 63 virtual bool isEmpty()const;
59 64
60 /** 65 /**
61 * toRichText summary 66 * toRichText summary
62 */ 67 */
63 virtual QString toRichText()const = 0; 68 virtual QString toRichText()const = 0;
64 69
65 /** 70 /**
66 * a small one line summary 71 * a small one line summary
67 */ 72 */
68 virtual QString toShortText()const = 0; 73 virtual QString toShortText()const = 0;
69 74
70 /** 75 /**
71 * the name of the Record 76 * the name of the Record
72 */ 77 */
73 virtual QString type()const = 0; 78 virtual QString type()const = 0;
74 79
75 /** 80 /**
76 * matches the Records the regular expression? 81 * matches the Records the regular expression?
77 */ 82 */
78 virtual bool match( const QString &regexp ) const 83 virtual bool match( const QString &regexp ) const
79 {setLastHitField( -1 ); 84 {setLastHitField( -1 );
80 return Qtopia::Record::match(QRegExp(regexp));}; 85 return Qtopia::Record::match(QRegExp(regexp));};
81 86
82 /** 87 /**
83 * if implemented this function returns which item has been 88 * if implemented this function returns which item has been
84 * last hit by the match() function. 89 * last hit by the match() function.
85 * or -1 if not implemented or no hit has occured 90 * or -1 if not implemented or no hit has occured
86 */ 91 */
87 int lastHitField()const; 92 int lastHitField()const;
88 93
89 /** 94 /**
90 * converts the internal structure to a map 95 * converts the internal structure to a map
91 */ 96 */
92 virtual QMap<int, QString> toMap()const = 0; 97 virtual QMap<int, QString> toMap()const = 0;
93 98
94 /** 99 /**
95 * key value representation of extra items 100 * key value representation of extra items
96 */ 101 */
97 virtual QMap<QString, QString> toExtraMap()const = 0; 102 QMap<QString, QString> toExtraMap()const;
103 void setExtraMap( const QMap<QString, QString>& );
98 104
99 /** 105 /**
100 * the name for a recordField 106 * the name for a recordField
101 */ 107 */
102 virtual QString recordField(int)const = 0; 108 virtual QString recordField(int)const = 0;
103 109
104 /** 110 /**
105 * returns a reference of the 111 * returns a reference of the
106 * Cross Reference Manager 112 * Cross Reference Manager
107 * Partner 'One' is THIS PIM RECORD! 113 * Partner 'One' is THIS PIM RECORD!
108 * 'Two' is the Partner where we link to 114 * 'Two' is the Partner where we link to
109 */ 115 */
110 OPimXRefManager& xrefmanager(); 116 OPimXRefManager& xrefmanager();
111 117
112 /** 118 /**
113 * set the uid 119 * set the uid
114 */ 120 */
115 virtual void setUid( int uid ); 121 virtual void setUid( int uid );
116 122
117 /* 123 /*
118 * used inside the Templates for casting 124 * used inside the Templates for casting
119 * REIMPLEMENT in your .... 125 * REIMPLEMENT in your ....
120 */ 126 */
121 static int rtti(); 127 static int rtti();
122 128
123 /** 129 /**
124 * some marshalling and de marshalling code 130 * some marshalling and de marshalling code
125 * saves the OPimRecord 131 * saves the OPimRecord
126 * to and from a DataStream 132 * to and from a DataStream
127 */ 133 */
128 virtual bool loadFromStream(QDataStream& ); 134 virtual bool loadFromStream(QDataStream& );
129 virtual bool saveToStream( QDataStream& stream )const; 135 virtual bool saveToStream( QDataStream& stream )const;
130 136
131protected: 137protected:
132 // need to be const cause it is called from const methods 138 // need to be const cause it is called from const methods
133 mutable int m_lastHit; 139 mutable int m_lastHit;
134 void setLastHitField( int lastHit )const; 140 void setLastHitField( int lastHit )const;
135 Qtopia::UidGen &uidGen(); 141 Qtopia::UidGen &uidGen();
136// QString crossToString()const; 142// QString crossToString()const;
137 143
138private: 144private:
139 class OPimRecordPrivate; 145 class OPimRecordPrivate;
140 OPimRecordPrivate *d; 146 OPimRecordPrivate *d;
141 OPimXRefManager m_xrefman; 147 OPimXRefManager m_xrefman;
142 static Qtopia::UidGen m_uidGen; 148 static Qtopia::UidGen m_uidGen;
143 149
144private: 150private:
145 void flush( const OPimXRefPartner&, QDataStream& stream )const; 151 void flush( const OPimXRefPartner&, QDataStream& stream )const;
146 OPimXRefPartner partner( QDataStream& ); 152 OPimXRefPartner partner( QDataStream& );
147}; 153};
148 154
149 155
150 156
151#endif 157#endif
diff --git a/libopie/pim/otodo.cpp b/libopie/pim/otodo.cpp
index c84eeeb..38b93f7 100644
--- a/libopie/pim/otodo.cpp
+++ b/libopie/pim/otodo.cpp
@@ -1,519 +1,516 @@
1 1
2#include <qobject.h> 2#include <qobject.h>
3#include <qshared.h> 3#include <qshared.h>
4 4
5 5
6 6
7#include <qpe/palmtopuidgen.h> 7#include <qpe/palmtopuidgen.h>
8#include <qpe/stringutil.h> 8#include <qpe/stringutil.h>
9#include <qpe/palmtoprecord.h> 9#include <qpe/palmtoprecord.h>
10#include <qpe/stringutil.h> 10#include <qpe/stringutil.h>
11#include <qpe/categories.h> 11#include <qpe/categories.h>
12#include <qpe/categoryselect.h> 12#include <qpe/categoryselect.h>
13 13
14 14
15#include "opimstate.h" 15#include "opimstate.h"
16#include "orecur.h" 16#include "orecur.h"
17#include "opimmaintainer.h" 17#include "opimmaintainer.h"
18#include "opimnotifymanager.h" 18#include "opimnotifymanager.h"
19#include "opimresolver.h" 19#include "opimresolver.h"
20 20
21#include "otodo.h" 21#include "otodo.h"
22 22
23 23
24struct OTodo::OTodoData : public QShared { 24struct OTodo::OTodoData : public QShared {
25 OTodoData() : QShared() { 25 OTodoData() : QShared() {
26 recur = 0; 26 recur = 0;
27 state = 0; 27 state = 0;
28 maintainer = 0; 28 maintainer = 0;
29 notifiers = 0; 29 notifiers = 0;
30 }; 30 };
31 31
32 QDate date; 32 QDate date;
33 bool isCompleted:1; 33 bool isCompleted:1;
34 bool hasDate:1; 34 bool hasDate:1;
35 int priority; 35 int priority;
36 QString desc; 36 QString desc;
37 QString sum; 37 QString sum;
38 QMap<QString, QString> extra; 38 QMap<QString, QString> extra;
39 ushort prog; 39 ushort prog;
40 OPimState *state; 40 OPimState *state;
41 ORecur *recur; 41 ORecur *recur;
42 OPimMaintainer *maintainer; 42 OPimMaintainer *maintainer;
43 QDate start; 43 QDate start;
44 QDate completed; 44 QDate completed;
45 OPimNotifyManager *notifiers; 45 OPimNotifyManager *notifiers;
46}; 46};
47 47
48OTodo::OTodo(const OTodo &event ) 48OTodo::OTodo(const OTodo &event )
49 : OPimRecord( event ), data( event.data ) 49 : OPimRecord( event ), data( event.data )
50{ 50{
51 data->ref(); 51 data->ref();
52// qWarning("ref up"); 52// qWarning("ref up");
53} 53}
54OTodo::~OTodo() { 54OTodo::~OTodo() {
55 55
56// qWarning("~OTodo " ); 56// qWarning("~OTodo " );
57 if ( data->deref() ) { 57 if ( data->deref() ) {
58// qWarning("OTodo::dereffing"); 58// qWarning("OTodo::dereffing");
59 delete data; 59 delete data;
60 data = 0l; 60 data = 0l;
61 } 61 }
62} 62}
63OTodo::OTodo(bool completed, int priority, 63OTodo::OTodo(bool completed, int priority,
64 const QArray<int> &category, 64 const QArray<int> &category,
65 const QString& summary, 65 const QString& summary,
66 const QString &description, 66 const QString &description,
67 ushort progress, 67 ushort progress,
68 bool hasDate, QDate date, int uid ) 68 bool hasDate, QDate date, int uid )
69 : OPimRecord( uid ) 69 : OPimRecord( uid )
70{ 70{
71// qWarning("OTodoData " + summary); 71// qWarning("OTodoData " + summary);
72 setCategories( category ); 72 setCategories( category );
73 73
74 data = new OTodoData; 74 data = new OTodoData;
75 75
76 data->date = date; 76 data->date = date;
77 data->isCompleted = completed; 77 data->isCompleted = completed;
78 data->hasDate = hasDate; 78 data->hasDate = hasDate;
79 data->priority = priority; 79 data->priority = priority;
80 data->sum = summary; 80 data->sum = summary;
81 data->prog = progress; 81 data->prog = progress;
82 data->desc = Qtopia::simplifyMultiLineSpace(description ); 82 data->desc = Qtopia::simplifyMultiLineSpace(description );
83} 83}
84OTodo::OTodo(bool completed, int priority, 84OTodo::OTodo(bool completed, int priority,
85 const QStringList &category, 85 const QStringList &category,
86 const QString& summary, 86 const QString& summary,
87 const QString &description, 87 const QString &description,
88 ushort progress, 88 ushort progress,
89 bool hasDate, QDate date, int uid ) 89 bool hasDate, QDate date, int uid )
90 : OPimRecord( uid ) 90 : OPimRecord( uid )
91{ 91{
92// qWarning("OTodoData" + summary); 92// qWarning("OTodoData" + summary);
93 setCategories( idsFromString( category.join(";") ) ); 93 setCategories( idsFromString( category.join(";") ) );
94 94
95 data = new OTodoData; 95 data = new OTodoData;
96 96
97 data->date = date; 97 data->date = date;
98 data->isCompleted = completed; 98 data->isCompleted = completed;
99 data->hasDate = hasDate; 99 data->hasDate = hasDate;
100 data->priority = priority; 100 data->priority = priority;
101 data->sum = summary; 101 data->sum = summary;
102 data->prog = progress; 102 data->prog = progress;
103 data->desc = Qtopia::simplifyMultiLineSpace(description ); 103 data->desc = Qtopia::simplifyMultiLineSpace(description );
104} 104}
105bool OTodo::match( const QRegExp &regExp )const 105bool OTodo::match( const QRegExp &regExp )const
106{ 106{
107 if( QString::number( data->priority ).find( regExp ) != -1 ){ 107 if( QString::number( data->priority ).find( regExp ) != -1 ){
108 setLastHitField( Priority ); 108 setLastHitField( Priority );
109 return true; 109 return true;
110 }else if( data->hasDate && data->date.toString().find( regExp) != -1 ){ 110 }else if( data->hasDate && data->date.toString().find( regExp) != -1 ){
111 setLastHitField( HasDate ); 111 setLastHitField( HasDate );
112 return true; 112 return true;
113 }else if(data->desc.find( regExp ) != -1 ){ 113 }else if(data->desc.find( regExp ) != -1 ){
114 setLastHitField( Description ); 114 setLastHitField( Description );
115 return true; 115 return true;
116 }else if(data->sum.find( regExp ) != -1 ) { 116 }else if(data->sum.find( regExp ) != -1 ) {
117 setLastHitField( Summary ); 117 setLastHitField( Summary );
118 return true; 118 return true;
119 } 119 }
120 return false; 120 return false;
121} 121}
122bool OTodo::isCompleted() const 122bool OTodo::isCompleted() const
123{ 123{
124 return data->isCompleted; 124 return data->isCompleted;
125} 125}
126bool OTodo::hasDueDate() const 126bool OTodo::hasDueDate() const
127{ 127{
128 return data->hasDate; 128 return data->hasDate;
129} 129}
130bool OTodo::hasStartDate()const { 130bool OTodo::hasStartDate()const {
131 return data->start.isValid(); 131 return data->start.isValid();
132} 132}
133bool OTodo::hasCompletedDate()const { 133bool OTodo::hasCompletedDate()const {
134 return data->completed.isValid(); 134 return data->completed.isValid();
135} 135}
136int OTodo::priority()const 136int OTodo::priority()const
137{ 137{
138 return data->priority; 138 return data->priority;
139} 139}
140QString OTodo::summary() const 140QString OTodo::summary() const
141{ 141{
142 return data->sum; 142 return data->sum;
143} 143}
144ushort OTodo::progress() const 144ushort OTodo::progress() const
145{ 145{
146 return data->prog; 146 return data->prog;
147} 147}
148QDate OTodo::dueDate()const 148QDate OTodo::dueDate()const
149{ 149{
150 return data->date; 150 return data->date;
151} 151}
152QDate OTodo::startDate()const { 152QDate OTodo::startDate()const {
153 return data->start; 153 return data->start;
154} 154}
155QDate OTodo::completedDate()const { 155QDate OTodo::completedDate()const {
156 return data->completed; 156 return data->completed;
157} 157}
158QString OTodo::description()const 158QString OTodo::description()const
159{ 159{
160 return data->desc; 160 return data->desc;
161} 161}
162bool OTodo::hasState() const{ 162bool OTodo::hasState() const{
163 if (!data->state ) return false; 163 if (!data->state ) return false;
164 return ( data->state->state() != OPimState::Undefined ); 164 return ( data->state->state() != OPimState::Undefined );
165} 165}
166OPimState OTodo::state()const { 166OPimState OTodo::state()const {
167 if (!data->state ) { 167 if (!data->state ) {
168 OPimState state; 168 OPimState state;
169 return state; 169 return state;
170 } 170 }
171 171
172 return (*data->state); 172 return (*data->state);
173} 173}
174bool OTodo::hasRecurrence()const { 174bool OTodo::hasRecurrence()const {
175 if (!data->recur) return false; 175 if (!data->recur) return false;
176 return data->recur->doesRecur(); 176 return data->recur->doesRecur();
177} 177}
178ORecur OTodo::recurrence()const { 178ORecur OTodo::recurrence()const {
179 if (!data->recur) return ORecur(); 179 if (!data->recur) return ORecur();
180 180
181 return (*data->recur); 181 return (*data->recur);
182} 182}
183bool OTodo::hasMaintainer()const { 183bool OTodo::hasMaintainer()const {
184 if (!data->maintainer) return false; 184 if (!data->maintainer) return false;
185 185
186 return (data->maintainer->mode() != OPimMaintainer::Undefined ); 186 return (data->maintainer->mode() != OPimMaintainer::Undefined );
187} 187}
188OPimMaintainer OTodo::maintainer()const { 188OPimMaintainer OTodo::maintainer()const {
189 if (!data->maintainer) return OPimMaintainer(); 189 if (!data->maintainer) return OPimMaintainer();
190 190
191 return (*data->maintainer); 191 return (*data->maintainer);
192} 192}
193void OTodo::setCompleted( bool completed ) 193void OTodo::setCompleted( bool completed )
194{ 194{
195 changeOrModify(); 195 changeOrModify();
196 data->isCompleted = completed; 196 data->isCompleted = completed;
197} 197}
198void OTodo::setHasDueDate( bool hasDate ) 198void OTodo::setHasDueDate( bool hasDate )
199{ 199{
200 changeOrModify(); 200 changeOrModify();
201 data->hasDate = hasDate; 201 data->hasDate = hasDate;
202} 202}
203void OTodo::setDescription(const QString &desc ) 203void OTodo::setDescription(const QString &desc )
204{ 204{
205// qWarning( "desc " + desc ); 205// qWarning( "desc " + desc );
206 changeOrModify(); 206 changeOrModify();
207 data->desc = Qtopia::simplifyMultiLineSpace(desc ); 207 data->desc = Qtopia::simplifyMultiLineSpace(desc );
208} 208}
209void OTodo::setSummary( const QString& sum ) 209void OTodo::setSummary( const QString& sum )
210{ 210{
211 changeOrModify(); 211 changeOrModify();
212 data->sum = sum; 212 data->sum = sum;
213} 213}
214void OTodo::setPriority(int prio ) 214void OTodo::setPriority(int prio )
215{ 215{
216 changeOrModify(); 216 changeOrModify();
217 data->priority = prio; 217 data->priority = prio;
218} 218}
219void OTodo::setDueDate( const QDate& date ) 219void OTodo::setDueDate( const QDate& date )
220{ 220{
221 changeOrModify(); 221 changeOrModify();
222 data->date = date; 222 data->date = date;
223} 223}
224void OTodo::setStartDate( const QDate& date ) { 224void OTodo::setStartDate( const QDate& date ) {
225 changeOrModify(); 225 changeOrModify();
226 data->start = date; 226 data->start = date;
227} 227}
228void OTodo::setCompletedDate( const QDate& date ) { 228void OTodo::setCompletedDate( const QDate& date ) {
229 changeOrModify(); 229 changeOrModify();
230 data->completed = date; 230 data->completed = date;
231} 231}
232void OTodo::setState( const OPimState& state ) { 232void OTodo::setState( const OPimState& state ) {
233 changeOrModify(); 233 changeOrModify();
234 if (data->state ) 234 if (data->state )
235 (*data->state) = state; 235 (*data->state) = state;
236 else 236 else
237 data->state = new OPimState( state ); 237 data->state = new OPimState( state );
238} 238}
239void OTodo::setRecurrence( const ORecur& rec) { 239void OTodo::setRecurrence( const ORecur& rec) {
240 changeOrModify(); 240 changeOrModify();
241 if (data->recur ) 241 if (data->recur )
242 (*data->recur) = rec; 242 (*data->recur) = rec;
243 else 243 else
244 data->recur = new ORecur( rec ); 244 data->recur = new ORecur( rec );
245} 245}
246void OTodo::setMaintainer( const OPimMaintainer& pim ) { 246void OTodo::setMaintainer( const OPimMaintainer& pim ) {
247 changeOrModify(); 247 changeOrModify();
248 248
249 if (data->maintainer ) 249 if (data->maintainer )
250 (*data->maintainer) = pim; 250 (*data->maintainer) = pim;
251 else 251 else
252 data->maintainer = new OPimMaintainer( pim ); 252 data->maintainer = new OPimMaintainer( pim );
253} 253}
254bool OTodo::isOverdue( ) 254bool OTodo::isOverdue( )
255{ 255{
256 if( data->hasDate && !data->isCompleted) 256 if( data->hasDate && !data->isCompleted)
257 return QDate::currentDate() > data->date; 257 return QDate::currentDate() > data->date;
258 return false; 258 return false;
259} 259}
260void OTodo::setProgress(ushort progress ) 260void OTodo::setProgress(ushort progress )
261{ 261{
262 changeOrModify(); 262 changeOrModify();
263 data->prog = progress; 263 data->prog = progress;
264} 264}
265QString OTodo::toShortText() const { 265QString OTodo::toShortText() const {
266 return summary(); 266 return summary();
267} 267}
268/*! 268/*!
269 Returns a richt text string 269 Returns a richt text string
270*/ 270*/
271QString OTodo::toRichText() const 271QString OTodo::toRichText() const
272{ 272{
273 QString text; 273 QString text;
274 QStringList catlist; 274 QStringList catlist;
275 275
276 // summary 276 // summary
277 text += "<b><h3><img src=\"todo/TodoList\">"; 277 text += "<b><h3><img src=\"todo/TodoList\">";
278 if ( !summary().isEmpty() ) { 278 if ( !summary().isEmpty() ) {
279 text += Qtopia::escapeString(summary() ).replace(QRegExp( "[\n]"), "" ); 279 text += Qtopia::escapeString(summary() ).replace(QRegExp( "[\n]"), "" );
280 } 280 }
281 text += "</h3></b><br><hr><br>"; 281 text += "</h3></b><br><hr><br>";
282 282
283 // description 283 // description
284 if( !description().isEmpty() ){ 284 if( !description().isEmpty() ){
285 text += "<b>" + QObject::tr( "Description:" ) + "</b><br>"; 285 text += "<b>" + QObject::tr( "Description:" ) + "</b><br>";
286 text += Qtopia::escapeString(description() ).replace(QRegExp( "[\n]"), "<br>" ) ; 286 text += Qtopia::escapeString(description() ).replace(QRegExp( "[\n]"), "<br>" ) ;
287 } 287 }
288 288
289 // priority 289 // priority
290 int priorityval = priority(); 290 int priorityval = priority();
291 text += "<b>" + QObject::tr( "Priority:") +" </b><img src=\"todo/priority" + 291 text += "<b>" + QObject::tr( "Priority:") +" </b><img src=\"todo/priority" +
292 QString::number( priorityval ) + "\">"; 292 QString::number( priorityval ) + "\">";
293// text += "<b>" + QObject::tr( "Priority:") +"</b><img src=\"todo/priority" + 293// text += "<b>" + QObject::tr( "Priority:") +"</b><img src=\"todo/priority" +
294// QString::number( priority() ) + "\"><br>"; 294// QString::number( priority() ) + "\"><br>";
295 switch ( priorityval ) 295 switch ( priorityval )
296 { 296 {
297 case 1 : text += QObject::tr( "Very high" ); 297 case 1 : text += QObject::tr( "Very high" );
298 break; 298 break;
299 case 2 : text += QObject::tr( "High" ); 299 case 2 : text += QObject::tr( "High" );
300 break; 300 break;
301 case 3 : text += QObject::tr( "Normal" ); 301 case 3 : text += QObject::tr( "Normal" );
302 break; 302 break;
303 case 4 : text += QObject::tr( "Low" ); 303 case 4 : text += QObject::tr( "Low" );
304 break; 304 break;
305 case 5 : text += QObject::tr( "Very low" ); 305 case 5 : text += QObject::tr( "Very low" );
306 break; 306 break;
307 }; 307 };
308 text += "<br>"; 308 text += "<br>";
309 309
310 // progress 310 // progress
311 text += "<b>" + QObject::tr( "Progress:") + " </b>" 311 text += "<b>" + QObject::tr( "Progress:") + " </b>"
312 + QString::number( progress() ) + " %<br>"; 312 + QString::number( progress() ) + " %<br>";
313 313
314 // due date 314 // due date
315 if (hasDueDate() ){ 315 if (hasDueDate() ){
316 QDate dd = dueDate(); 316 QDate dd = dueDate();
317 int off = QDate::currentDate().daysTo( dd ); 317 int off = QDate::currentDate().daysTo( dd );
318 318
319 text += "<b>" + QObject::tr( "Deadline:" ) + " </b><font color=\""; 319 text += "<b>" + QObject::tr( "Deadline:" ) + " </b><font color=\"";
320 if ( off < 0 ) 320 if ( off < 0 )
321 text += "#FF0000"; 321 text += "#FF0000";
322 else if ( off == 0 ) 322 else if ( off == 0 )
323 text += "#FFFF00"; 323 text += "#FFFF00";
324 else if ( off > 0 ) 324 else if ( off > 0 )
325 text += "#00FF00"; 325 text += "#00FF00";
326 326
327 text += "\">" + dd.toString() + "</font><br>"; 327 text += "\">" + dd.toString() + "</font><br>";
328 } 328 }
329 329
330 // categories 330 // categories
331 text += "<b>" + QObject::tr( "Category:") + "</b> "; 331 text += "<b>" + QObject::tr( "Category:") + "</b> ";
332 text += categoryNames( "Todo List" ).join(", "); 332 text += categoryNames( "Todo List" ).join(", ");
333 text += "<br>"; 333 text += "<br>";
334 334
335 return text; 335 return text;
336} 336}
337bool OTodo::hasNotifiers()const { 337bool OTodo::hasNotifiers()const {
338 if (!data->notifiers) return false; 338 if (!data->notifiers) return false;
339 return !data->notifiers->isEmpty(); 339 return !data->notifiers->isEmpty();
340} 340}
341OPimNotifyManager& OTodo::notifiers() { 341OPimNotifyManager& OTodo::notifiers() {
342 if (!data->notifiers ) 342 if (!data->notifiers )
343 data->notifiers = new OPimNotifyManager; 343 data->notifiers = new OPimNotifyManager;
344 return (*data->notifiers); 344 return (*data->notifiers);
345} 345}
346const OPimNotifyManager& OTodo::notifiers()const{ 346const OPimNotifyManager& OTodo::notifiers()const{
347 if (!data->notifiers ) 347 if (!data->notifiers )
348 data->notifiers = new OPimNotifyManager; 348 data->notifiers = new OPimNotifyManager;
349 349
350 return (*data->notifiers); 350 return (*data->notifiers);
351} 351}
352 352
353bool OTodo::operator<( const OTodo &toDoEvent )const{ 353bool OTodo::operator<( const OTodo &toDoEvent )const{
354 if( !hasDueDate() && !toDoEvent.hasDueDate() ) return true; 354 if( !hasDueDate() && !toDoEvent.hasDueDate() ) return true;
355 if( !hasDueDate() && toDoEvent.hasDueDate() ) return false; 355 if( !hasDueDate() && toDoEvent.hasDueDate() ) return false;
356 if( hasDueDate() && toDoEvent.hasDueDate() ){ 356 if( hasDueDate() && toDoEvent.hasDueDate() ){
357 if( dueDate() == toDoEvent.dueDate() ){ // let's the priority decide 357 if( dueDate() == toDoEvent.dueDate() ){ // let's the priority decide
358 return priority() < toDoEvent.priority(); 358 return priority() < toDoEvent.priority();
359 }else{ 359 }else{
360 return dueDate() < toDoEvent.dueDate(); 360 return dueDate() < toDoEvent.dueDate();
361 } 361 }
362 } 362 }
363 return false; 363 return false;
364} 364}
365bool OTodo::operator<=(const OTodo &toDoEvent )const 365bool OTodo::operator<=(const OTodo &toDoEvent )const
366{ 366{
367 if( !hasDueDate() && !toDoEvent.hasDueDate() ) return true; 367 if( !hasDueDate() && !toDoEvent.hasDueDate() ) return true;
368 if( !hasDueDate() && toDoEvent.hasDueDate() ) return true; 368 if( !hasDueDate() && toDoEvent.hasDueDate() ) return true;
369 if( hasDueDate() && toDoEvent.hasDueDate() ){ 369 if( hasDueDate() && toDoEvent.hasDueDate() ){
370 if( dueDate() == toDoEvent.dueDate() ){ // let's the priority decide 370 if( dueDate() == toDoEvent.dueDate() ){ // let's the priority decide
371 return priority() <= toDoEvent.priority(); 371 return priority() <= toDoEvent.priority();
372 }else{ 372 }else{
373 return dueDate() <= toDoEvent.dueDate(); 373 return dueDate() <= toDoEvent.dueDate();
374 } 374 }
375 } 375 }
376 return true; 376 return true;
377} 377}
378bool OTodo::operator>(const OTodo &toDoEvent )const 378bool OTodo::operator>(const OTodo &toDoEvent )const
379{ 379{
380 if( !hasDueDate() && !toDoEvent.hasDueDate() ) return false; 380 if( !hasDueDate() && !toDoEvent.hasDueDate() ) return false;
381 if( !hasDueDate() && toDoEvent.hasDueDate() ) return false; 381 if( !hasDueDate() && toDoEvent.hasDueDate() ) return false;
382 if( hasDueDate() && toDoEvent.hasDueDate() ){ 382 if( hasDueDate() && toDoEvent.hasDueDate() ){
383 if( dueDate() == toDoEvent.dueDate() ){ // let's the priority decide 383 if( dueDate() == toDoEvent.dueDate() ){ // let's the priority decide
384 return priority() > toDoEvent.priority(); 384 return priority() > toDoEvent.priority();
385 }else{ 385 }else{
386 return dueDate() > toDoEvent.dueDate(); 386 return dueDate() > toDoEvent.dueDate();
387 } 387 }
388 } 388 }
389 return false; 389 return false;
390} 390}
391bool OTodo::operator>=(const OTodo &toDoEvent )const 391bool OTodo::operator>=(const OTodo &toDoEvent )const
392{ 392{
393 if( !hasDueDate() && !toDoEvent.hasDueDate() ) return true; 393 if( !hasDueDate() && !toDoEvent.hasDueDate() ) return true;
394 if( !hasDueDate() && toDoEvent.hasDueDate() ) return false; 394 if( !hasDueDate() && toDoEvent.hasDueDate() ) return false;
395 if( hasDueDate() && toDoEvent.hasDueDate() ){ 395 if( hasDueDate() && toDoEvent.hasDueDate() ){
396 if( dueDate() == toDoEvent.dueDate() ){ // let's the priority decide 396 if( dueDate() == toDoEvent.dueDate() ){ // let's the priority decide
397 return priority() > toDoEvent.priority(); 397 return priority() > toDoEvent.priority();
398 }else{ 398 }else{
399 return dueDate() > toDoEvent.dueDate(); 399 return dueDate() > toDoEvent.dueDate();
400 } 400 }
401 } 401 }
402 return true; 402 return true;
403} 403}
404bool OTodo::operator==(const OTodo &toDoEvent )const 404bool OTodo::operator==(const OTodo &toDoEvent )const
405{ 405{
406 if ( data->priority != toDoEvent.data->priority ) return false; 406 if ( data->priority != toDoEvent.data->priority ) return false;
407 if ( data->priority != toDoEvent.data->prog ) return false; 407 if ( data->priority != toDoEvent.data->prog ) return false;
408 if ( data->isCompleted != toDoEvent.data->isCompleted ) return false; 408 if ( data->isCompleted != toDoEvent.data->isCompleted ) return false;
409 if ( data->hasDate != toDoEvent.data->hasDate ) return false; 409 if ( data->hasDate != toDoEvent.data->hasDate ) return false;
410 if ( data->date != toDoEvent.data->date ) return false; 410 if ( data->date != toDoEvent.data->date ) return false;
411 if ( data->sum != toDoEvent.data->sum ) return false; 411 if ( data->sum != toDoEvent.data->sum ) return false;
412 if ( data->desc != toDoEvent.data->desc ) return false; 412 if ( data->desc != toDoEvent.data->desc ) return false;
413 if ( data->maintainer != toDoEvent.data->maintainer ) 413 if ( data->maintainer != toDoEvent.data->maintainer )
414 return false; 414 return false;
415 415
416 return OPimRecord::operator==( toDoEvent ); 416 return OPimRecord::operator==( toDoEvent );
417} 417}
418void OTodo::deref() { 418void OTodo::deref() {
419 419
420// qWarning("deref in ToDoEvent"); 420// qWarning("deref in ToDoEvent");
421 if ( data->deref() ) { 421 if ( data->deref() ) {
422// qWarning("deleting"); 422// qWarning("deleting");
423 delete data; 423 delete data;
424 data= 0; 424 data= 0;
425 } 425 }
426} 426}
427OTodo &OTodo::operator=(const OTodo &item ) 427OTodo &OTodo::operator=(const OTodo &item )
428{ 428{
429 if ( this == &item ) return *this; 429 if ( this == &item ) return *this;
430 430
431 OPimRecord::operator=( item ); 431 OPimRecord::operator=( item );
432 //qWarning("operator= ref "); 432 //qWarning("operator= ref ");
433 item.data->ref(); 433 item.data->ref();
434 deref(); 434 deref();
435 data = item.data; 435 data = item.data;
436 436
437 return *this; 437 return *this;
438} 438}
439 439
440QMap<int, QString> OTodo::toMap() const { 440QMap<int, QString> OTodo::toMap() const {
441 QMap<int, QString> map; 441 QMap<int, QString> map;
442 442
443 map.insert( Uid, QString::number( uid() ) ); 443 map.insert( Uid, QString::number( uid() ) );
444 map.insert( Category, idsToString( categories() ) ); 444 map.insert( Category, idsToString( categories() ) );
445 map.insert( HasDate, QString::number( data->hasDate ) ); 445 map.insert( HasDate, QString::number( data->hasDate ) );
446 map.insert( Completed, QString::number( data->isCompleted ) ); 446 map.insert( Completed, QString::number( data->isCompleted ) );
447 map.insert( Description, data->desc ); 447 map.insert( Description, data->desc );
448 map.insert( Summary, data->sum ); 448 map.insert( Summary, data->sum );
449 map.insert( Priority, QString::number( data->priority ) ); 449 map.insert( Priority, QString::number( data->priority ) );
450 map.insert( DateDay, QString::number( data->date.day() ) ); 450 map.insert( DateDay, QString::number( data->date.day() ) );
451 map.insert( DateMonth, QString::number( data->date.month() ) ); 451 map.insert( DateMonth, QString::number( data->date.month() ) );
452 map.insert( DateYear, QString::number( data->date.year() ) ); 452 map.insert( DateYear, QString::number( data->date.year() ) );
453 map.insert( Progress, QString::number( data->prog ) ); 453 map.insert( Progress, QString::number( data->prog ) );
454// map.insert( CrossReference, crossToString() ); 454// map.insert( CrossReference, crossToString() );
455 /* FIXME!!! map.insert( State, ); 455 /* FIXME!!! map.insert( State, );
456 map.insert( Recurrence, ); 456 map.insert( Recurrence, );
457 map.insert( Reminders, ); 457 map.insert( Reminders, );
458 map. 458 map.
459 */ 459 */
460 return map; 460 return map;
461} 461}
462 462
463QMap<QString, QString> OTodo::toExtraMap()const {
464 return data->extra;
465}
466/** 463/**
467 * change or modify looks at the ref count and either 464 * change or modify looks at the ref count and either
468 * creates a new QShared Object or it can modify it 465 * creates a new QShared Object or it can modify it
469 * right in place 466 * right in place
470 */ 467 */
471void OTodo::changeOrModify() { 468void OTodo::changeOrModify() {
472 if ( data->count != 1 ) { 469 if ( data->count != 1 ) {
473 qWarning("changeOrModify"); 470 qWarning("changeOrModify");
474 data->deref(); 471 data->deref();
475 OTodoData* d2 = new OTodoData(); 472 OTodoData* d2 = new OTodoData();
476 copy(data, d2 ); 473 copy(data, d2 );
477 data = d2; 474 data = d2;
478 } 475 }
479} 476}
480// WATCHOUT 477// WATCHOUT
481/* 478/*
482 * if you add something to the Data struct 479 * if you add something to the Data struct
483 * be sure to copy it here 480 * be sure to copy it here
484 */ 481 */
485void OTodo::copy( OTodoData* src, OTodoData* dest ) { 482void OTodo::copy( OTodoData* src, OTodoData* dest ) {
486 dest->date = src->date; 483 dest->date = src->date;
487 dest->isCompleted = src->isCompleted; 484 dest->isCompleted = src->isCompleted;
488 dest->hasDate = src->hasDate; 485 dest->hasDate = src->hasDate;
489 dest->priority = src->priority; 486 dest->priority = src->priority;
490 dest->desc = src->desc; 487 dest->desc = src->desc;
491 dest->sum = src->sum; 488 dest->sum = src->sum;
492 dest->extra = src->extra; 489 dest->extra = src->extra;
493 dest->prog = src->prog; 490 dest->prog = src->prog;
494 491
495 if (src->state ) 492 if (src->state )
496 dest->state = new OPimState( *src->state ); 493 dest->state = new OPimState( *src->state );
497 494
498 if (src->recur ) 495 if (src->recur )
499 dest->recur = new ORecur( *src->recur ); 496 dest->recur = new ORecur( *src->recur );
500 497
501 if (src->maintainer ) 498 if (src->maintainer )
502 dest->maintainer = new OPimMaintainer( *src->maintainer ) 499 dest->maintainer = new OPimMaintainer( *src->maintainer )
503 ; 500 ;
504 dest->start = src->start; 501 dest->start = src->start;
505 dest->completed = src->completed; 502 dest->completed = src->completed;
506 503
507 if (src->notifiers ) 504 if (src->notifiers )
508 dest->notifiers = new OPimNotifyManager( *src->notifiers ); 505 dest->notifiers = new OPimNotifyManager( *src->notifiers );
509} 506}
510QString OTodo::type() const { 507QString OTodo::type() const {
511 return QString::fromLatin1("OTodo"); 508 return QString::fromLatin1("OTodo");
512} 509}
513QString OTodo::recordField(int /*id*/ )const { 510QString OTodo::recordField(int /*id*/ )const {
514 return QString::null; 511 return QString::null;
515} 512}
516 513
517int OTodo::rtti(){ 514int OTodo::rtti(){
518 return OPimResolver::TodoList; 515 return OPimResolver::TodoList;
519} 516}
diff --git a/libopie/pim/otodo.h b/libopie/pim/otodo.h
index 4d5ee36..f9a345a 100644
--- a/libopie/pim/otodo.h
+++ b/libopie/pim/otodo.h
@@ -1,295 +1,294 @@
1 1
2#ifndef OPIE_TODO_EVENT_H 2#ifndef OPIE_TODO_EVENT_H
3#define OPIE_TODO_EVENT_H 3#define OPIE_TODO_EVENT_H
4 4
5 5
6#include <qarray.h> 6#include <qarray.h>
7#include <qmap.h> 7#include <qmap.h>
8#include <qregexp.h> 8#include <qregexp.h>
9#include <qstringlist.h> 9#include <qstringlist.h>
10#include <qdatetime.h> 10#include <qdatetime.h>
11#include <qvaluelist.h> 11#include <qvaluelist.h>
12 12
13#include <qpe/recordfields.h> 13#include <qpe/recordfields.h>
14#include <qpe/palmtopuidgen.h> 14#include <qpe/palmtopuidgen.h>
15 15
16#include <opie/opimrecord.h> 16#include <opie/opimrecord.h>
17 17
18 18
19class OPimState; 19class OPimState;
20class ORecur; 20class ORecur;
21class OPimMaintainer; 21class OPimMaintainer;
22class OPimNotifyManager; 22class OPimNotifyManager;
23class OTodo : public OPimRecord { 23class OTodo : public OPimRecord {
24public: 24public:
25 typedef QValueList<OTodo> ValueList; 25 typedef QValueList<OTodo> ValueList;
26 enum RecordFields { 26 enum RecordFields {
27 Uid = Qtopia::UID_ID, 27 Uid = Qtopia::UID_ID,
28 Category = Qtopia::CATEGORY_ID, 28 Category = Qtopia::CATEGORY_ID,
29 HasDate, 29 HasDate,
30 Completed, 30 Completed,
31 Description, 31 Description,
32 Summary, 32 Summary,
33 Priority, 33 Priority,
34 DateDay, 34 DateDay,
35 DateMonth, 35 DateMonth,
36 DateYear, 36 DateYear,
37 Progress, 37 Progress,
38 CrossReference, 38 CrossReference,
39 State, 39 State,
40 Recurrence, 40 Recurrence,
41 Alarms, 41 Alarms,
42 Reminders, 42 Reminders,
43 Notifiers, 43 Notifiers,
44 Maintainer, 44 Maintainer,
45 StartDate, 45 StartDate,
46 CompletedDate 46 CompletedDate
47 }; 47 };
48 public: 48 public:
49 // priorities from Very low to very high 49 // priorities from Very low to very high
50 enum TaskPriority { VeryHigh=1, High, Normal, Low, VeryLow }; 50 enum TaskPriority { VeryHigh=1, High, Normal, Low, VeryLow };
51 51
52 /* Constructs a new ToDoEvent 52 /* Constructs a new ToDoEvent
53 @param completed Is the TodoEvent completed 53 @param completed Is the TodoEvent completed
54 @param priority What is the priority of this ToDoEvent 54 @param priority What is the priority of this ToDoEvent
55 @param category Which category does it belong( uid ) 55 @param category Which category does it belong( uid )
56 @param summary A small summary of the todo 56 @param summary A small summary of the todo
57 @param description What is this ToDoEvent about 57 @param description What is this ToDoEvent about
58 @param hasDate Does this Event got a deadline 58 @param hasDate Does this Event got a deadline
59 @param date what is the deadline? 59 @param date what is the deadline?
60 @param uid what is the UUID of this Event 60 @param uid what is the UUID of this Event
61 **/ 61 **/
62 OTodo( bool completed = false, int priority = Normal, 62 OTodo( bool completed = false, int priority = Normal,
63 const QStringList &category = QStringList(), 63 const QStringList &category = QStringList(),
64 const QString &summary = QString::null , 64 const QString &summary = QString::null ,
65 const QString &description = QString::null, 65 const QString &description = QString::null,
66 ushort progress = 0, 66 ushort progress = 0,
67 bool hasDate = false, QDate date = QDate::currentDate(), 67 bool hasDate = false, QDate date = QDate::currentDate(),
68 int uid = 0 /*empty*/ ); 68 int uid = 0 /*empty*/ );
69 69
70 OTodo( bool completed, int priority, 70 OTodo( bool completed, int priority,
71 const QArray<int>& category, 71 const QArray<int>& category,
72 const QString& summary = QString::null, 72 const QString& summary = QString::null,
73 const QString& description = QString::null, 73 const QString& description = QString::null,
74 ushort progress = 0, 74 ushort progress = 0,
75 bool hasDate = false, QDate date = QDate::currentDate(), 75 bool hasDate = false, QDate date = QDate::currentDate(),
76 int uid = 0 /* empty */ ); 76 int uid = 0 /* empty */ );
77 77
78 /** Copy c'tor 78 /** Copy c'tor
79 * 79 *
80 */ 80 */
81 OTodo(const OTodo & ); 81 OTodo(const OTodo & );
82 82
83 /** 83 /**
84 *destructor 84 *destructor
85 */ 85 */
86 ~OTodo(); 86 ~OTodo();
87 87
88 /** 88 /**
89 * Is this event completed? 89 * Is this event completed?
90 */ 90 */
91 bool isCompleted() const; 91 bool isCompleted() const;
92 92
93 /** 93 /**
94 * Does this Event have a deadline 94 * Does this Event have a deadline
95 */ 95 */
96 bool hasDueDate() const; 96 bool hasDueDate() const;
97 bool hasStartDate()const; 97 bool hasStartDate()const;
98 bool hasCompletedDate()const; 98 bool hasCompletedDate()const;
99 99
100 /** 100 /**
101 * Does this Event has an alarm time ? 101 * Does this Event has an alarm time ?
102 */ 102 */
103 bool hasAlarmDateTime() const; 103 bool hasAlarmDateTime() const;
104 104
105 /** 105 /**
106 * What is the priority? 106 * What is the priority?
107 */ 107 */
108 int priority()const ; 108 int priority()const ;
109 109
110 /** 110 /**
111 * progress as ushort 0, 20, 40, 60, 80 or 100% 111 * progress as ushort 0, 20, 40, 60, 80 or 100%
112 */ 112 */
113 ushort progress() const; 113 ushort progress() const;
114 114
115 /** 115 /**
116 * The due Date 116 * The due Date
117 */ 117 */
118 QDate dueDate()const; 118 QDate dueDate()const;
119 119
120 /** 120 /**
121 * When did it start? 121 * When did it start?
122 */ 122 */
123 QDate startDate()const; 123 QDate startDate()const;
124 124
125 /** 125 /**
126 * When was it completed? 126 * When was it completed?
127 */ 127 */
128 QDate completedDate()const; 128 QDate completedDate()const;
129 129
130 /** 130 /**
131 * does it have a state? 131 * does it have a state?
132 */ 132 */
133 bool hasState()const; 133 bool hasState()const;
134 134
135 /** 135 /**
136 * What is the state of this OTodo? 136 * What is the state of this OTodo?
137 */ 137 */
138 OPimState state()const; 138 OPimState state()const;
139 139
140 /** 140 /**
141 * has recurrence? 141 * has recurrence?
142 */ 142 */
143 bool hasRecurrence()const; 143 bool hasRecurrence()const;
144 144
145 /** 145 /**
146 * the recurrance of this 146 * the recurrance of this
147 */ 147 */
148 ORecur recurrence()const; 148 ORecur recurrence()const;
149 149
150 /** 150 /**
151 * does this OTodo have a maintainer? 151 * does this OTodo have a maintainer?
152 */ 152 */
153 bool hasMaintainer()const; 153 bool hasMaintainer()const;
154 154
155 /** 155 /**
156 * the Maintainer of this OTodo 156 * the Maintainer of this OTodo
157 */ 157 */
158 OPimMaintainer maintainer()const; 158 OPimMaintainer maintainer()const;
159 159
160 /** 160 /**
161 * The description of the todo 161 * The description of the todo
162 */ 162 */
163 QString description()const; 163 QString description()const;
164 164
165 /** 165 /**
166 * A small summary of the todo 166 * A small summary of the todo
167 */ 167 */
168 QString summary() const; 168 QString summary() const;
169 169
170 /** 170 /**
171 * @reimplemented 171 * @reimplemented
172 * Return this todoevent in a RichText formatted QString 172 * Return this todoevent in a RichText formatted QString
173 */ 173 */
174 QString toRichText() const; 174 QString toRichText() const;
175 175
176 bool hasNotifiers()const; 176 bool hasNotifiers()const;
177 /* 177 /*
178 * FIXME check if the sharing is still fine!! -zecke 178 * FIXME check if the sharing is still fine!! -zecke
179 * ### CHECK If API is fine 179 * ### CHECK If API is fine
180 */ 180 */
181 /** 181 /**
182 * return a reference to our notifiers... 182 * return a reference to our notifiers...
183 */ 183 */
184 OPimNotifyManager &notifiers(); 184 OPimNotifyManager &notifiers();
185 185
186 /** 186 /**
187 * 187 *
188 */ 188 */
189 const OPimNotifyManager &notifiers()const; 189 const OPimNotifyManager &notifiers()const;
190 190
191 /** 191 /**
192 * reimplementations 192 * reimplementations
193 */ 193 */
194 QString type()const; 194 QString type()const;
195 QString toShortText()const; 195 QString toShortText()const;
196 QMap<QString, QString> toExtraMap()const;
197 QString recordField(int id )const; 196 QString recordField(int id )const;
198 197
199 /** 198 /**
200 * toMap puts all data into the map. int relates 199 * toMap puts all data into the map. int relates
201 * to ToDoEvent RecordFields enum 200 * to ToDoEvent RecordFields enum
202 */ 201 */
203 QMap<int, QString> toMap()const; 202 QMap<int, QString> toMap()const;
204 203
205 /** 204 /**
206 * Set if this Todo is completed 205 * Set if this Todo is completed
207 */ 206 */
208 void setCompleted(bool completed ); 207 void setCompleted(bool completed );
209 208
210 /** 209 /**
211 * set if this todo got an end data 210 * set if this todo got an end data
212 */ 211 */
213 void setHasDueDate( bool hasDate ); 212 void setHasDueDate( bool hasDate );
214 // FIXME we do not have these for start, completed 213 // FIXME we do not have these for start, completed
215 // cause we'll use the isNull() of QDate for figuring 214 // cause we'll use the isNull() of QDate for figuring
216 // out if it's has a date... 215 // out if it's has a date...
217 // decide what to do here? -zecke 216 // decide what to do here? -zecke
218 217
219 /** 218 /**
220 * Set the priority of the Todo 219 * Set the priority of the Todo
221 */ 220 */
222 void setPriority(int priority ); 221 void setPriority(int priority );
223 222
224 /** 223 /**
225 * Set the progress. 224 * Set the progress.
226 */ 225 */
227 void setProgress( ushort progress ); 226 void setProgress( ushort progress );
228 227
229 /** 228 /**
230 * set the end date 229 * set the end date
231 */ 230 */
232 void setDueDate( const QDate& date ); 231 void setDueDate( const QDate& date );
233 232
234 /** 233 /**
235 * set the start date 234 * set the start date
236 */ 235 */
237 void setStartDate( const QDate& date ); 236 void setStartDate( const QDate& date );
238 237
239 /** 238 /**
240 * set the completed date 239 * set the completed date
241 */ 240 */
242 void setCompletedDate( const QDate& date ); 241 void setCompletedDate( const QDate& date );
243 242
244 void setRecurrence( const ORecur& ); 243 void setRecurrence( const ORecur& );
245 /** 244 /**
246 * set the alarm time 245 * set the alarm time
247 */ 246 */
248 void setAlarmDateTime ( const QDateTime& alarm ); 247 void setAlarmDateTime ( const QDateTime& alarm );
249 248
250 void setDescription(const QString& ); 249 void setDescription(const QString& );
251 void setSummary(const QString& ); 250 void setSummary(const QString& );
252 251
253 /** 252 /**
254 * set the state of a Todo 253 * set the state of a Todo
255 * @param state State what the todo should take 254 * @param state State what the todo should take
256 */ 255 */
257 void setState( const OPimState& state); 256 void setState( const OPimState& state);
258 257
259 /** 258 /**
260 * set the Maintainer Mode 259 * set the Maintainer Mode
261 */ 260 */
262 void setMaintainer( const OPimMaintainer& ); 261 void setMaintainer( const OPimMaintainer& );
263 262
264 bool isOverdue(); 263 bool isOverdue();
265 264
266 265
267 virtual bool match( const QRegExp &r )const; 266 virtual bool match( const QRegExp &r )const;
268 267
269 bool operator<(const OTodo &toDoEvent )const; 268 bool operator<(const OTodo &toDoEvent )const;
270 bool operator<=(const OTodo &toDoEvent )const; 269 bool operator<=(const OTodo &toDoEvent )const;
271 bool operator!=(const OTodo &toDoEvent )const; 270 bool operator!=(const OTodo &toDoEvent )const;
272 bool operator>(const OTodo &toDoEvent )const; 271 bool operator>(const OTodo &toDoEvent )const;
273 bool operator>=(const OTodo &toDoEvent)const; 272 bool operator>=(const OTodo &toDoEvent)const;
274 bool operator==(const OTodo &toDoEvent )const; 273 bool operator==(const OTodo &toDoEvent )const;
275 OTodo &operator=(const OTodo &toDoEvent ); 274 OTodo &operator=(const OTodo &toDoEvent );
276 275
277 static int rtti(); 276 static int rtti();
278 277
279 private: 278 private:
280 class OTodoPrivate; 279 class OTodoPrivate;
281 struct OTodoData; 280 struct OTodoData;
282 281
283 void deref(); 282 void deref();
284 inline void changeOrModify(); 283 inline void changeOrModify();
285 void copy( OTodoData* src, OTodoData* dest ); 284 void copy( OTodoData* src, OTodoData* dest );
286 OTodoPrivate *d; 285 OTodoPrivate *d;
287 OTodoData *data; 286 OTodoData *data;
288 287
289}; 288};
290inline bool OTodo::operator!=(const OTodo &toDoEvent )const { 289inline bool OTodo::operator!=(const OTodo &toDoEvent )const {
291 return !(*this == toDoEvent); 290 return !(*this == toDoEvent);
292} 291}
293 292
294 293
295#endif 294#endif
diff --git a/libopie/pim/otodoaccessxml.cpp b/libopie/pim/otodoaccessxml.cpp
index 2b62f0d..3d15354 100644
--- a/libopie/pim/otodoaccessxml.cpp
+++ b/libopie/pim/otodoaccessxml.cpp
@@ -1,851 +1,874 @@
1#include <errno.h> 1#include <errno.h>
2#include <fcntl.h> 2#include <fcntl.h>
3 3
4#include <sys/mman.h> 4#include <sys/mman.h>
5#include <sys/stat.h> 5#include <sys/stat.h>
6#include <sys/types.h> 6#include <sys/types.h>
7 7
8#include <unistd.h> 8#include <unistd.h>
9 9
10 10
11#include <qfile.h> 11#include <qfile.h>
12#include <qvector.h> 12#include <qvector.h>
13 13
14#include <qpe/global.h> 14#include <qpe/global.h>
15#include <qpe/stringutil.h> 15#include <qpe/stringutil.h>
16#include <qpe/timeconversion.h> 16#include <qpe/timeconversion.h>
17 17
18#include "oconversion.h" 18#include "oconversion.h"
19#include "opimstate.h" 19#include "opimstate.h"
20#include "otimezone.h" 20#include "otimezone.h"
21#include "opimnotifymanager.h" 21#include "opimnotifymanager.h"
22#include "orecur.h" 22#include "orecur.h"
23#include "otodoaccessxml.h" 23#include "otodoaccessxml.h"
24 24
25namespace { 25namespace {
26 time_t rp_end; 26 time_t rp_end;
27 ORecur* rec; 27 ORecur* rec;
28 ORecur *recur() { 28 ORecur *recur() {
29 if (!rec ) rec = new ORecur; 29 if (!rec ) rec = new ORecur;
30 return rec; 30 return rec;
31 } 31 }
32 int snd; 32 int snd;
33 enum MoreAttributes { 33 enum MoreAttributes {
34 FRType = OTodo::CompletedDate + 2, 34 FRType = OTodo::CompletedDate + 2,
35 FRWeekdays, 35 FRWeekdays,
36 FRPosition, 36 FRPosition,
37 FRFreq, 37 FRFreq,
38 FRHasEndDate, 38 FRHasEndDate,
39 FREndDate, 39 FREndDate,
40 FRStart, 40 FRStart,
41 FREnd 41 FREnd
42 }; 42 };
43 // FROM TT again 43 // FROM TT again
44char *strstrlen(const char *haystack, int hLen, const char* needle, int nLen) 44char *strstrlen(const char *haystack, int hLen, const char* needle, int nLen)
45{ 45{
46 char needleChar; 46 char needleChar;
47 char haystackChar; 47 char haystackChar;
48 if (!needle || !haystack || !hLen || !nLen) 48 if (!needle || !haystack || !hLen || !nLen)
49 return 0; 49 return 0;
50 50
51 const char* hsearch = haystack; 51 const char* hsearch = haystack;
52 52
53 if ((needleChar = *needle++) != 0) { 53 if ((needleChar = *needle++) != 0) {
54 nLen--; //(to make up for needle++) 54 nLen--; //(to make up for needle++)
55 do { 55 do {
56 do { 56 do {
57 if ((haystackChar = *hsearch++) == 0) 57 if ((haystackChar = *hsearch++) == 0)
58 return (0); 58 return (0);
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(21); 90 QAsciiDict<int> dict(21);
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 break; 501 break;
501 } 502 }
502} 503}
504
505// from PalmtopRecord... GPL ### FIXME
506namespace {
507QString customToXml(const QMap<QString, QString>& customMap )
508{
509 //qWarning(QString("writing custom %1").arg(customMap.count()));
510 QString buf(" ");
511 for ( QMap<QString, QString>::ConstIterator cit = customMap.begin();
512 cit != customMap.end(); ++cit) {
513 // qWarning(".ITEM.");
514 buf += cit.key();
515 buf += "=\"";
516 buf += Qtopia::escapeString(cit.data());
517 buf += "\" ";
518 }
519 return buf;
520}
521
522
523}
524
503QString OTodoAccessXML::toString( const OTodo& ev )const { 525QString OTodoAccessXML::toString( const OTodo& ev )const {
504 QString str; 526 QString str;
505 527
506 str += "Completed=\"" + QString::number( ev.isCompleted() ) + "\" "; 528 str += "Completed=\"" + QString::number( ev.isCompleted() ) + "\" ";
507 str += "HasDate=\"" + QString::number( ev.hasDueDate() ) + "\" "; 529 str += "HasDate=\"" + QString::number( ev.hasDueDate() ) + "\" ";
508 str += "Priority=\"" + QString::number( ev.priority() ) + "\" "; 530 str += "Priority=\"" + QString::number( ev.priority() ) + "\" ";
509 str += "Progress=\"" + QString::number(ev.progress() ) + "\" "; 531 str += "Progress=\"" + QString::number(ev.progress() ) + "\" ";
510 532
511 str += "Categories=\"" + toString( ev.categories() ) + "\" "; 533 str += "Categories=\"" + toString( ev.categories() ) + "\" ";
512 str += "Description=\"" + Qtopia::escapeString( ev.description() ) + "\" "; 534 str += "Description=\"" + Qtopia::escapeString( ev.description() ) + "\" ";
513 str += "Summary=\"" + Qtopia::escapeString( ev.summary() ) + "\" "; 535 str += "Summary=\"" + Qtopia::escapeString( ev.summary() ) + "\" ";
514 536
515 if ( ev.hasDueDate() ) { 537 if ( ev.hasDueDate() ) {
516 str += "DateYear=\"" + QString::number( ev.dueDate().year() ) + "\" "; 538 str += "DateYear=\"" + QString::number( ev.dueDate().year() ) + "\" ";
517 str += "DateMonth=\"" + QString::number( ev.dueDate().month() ) + "\" "; 539 str += "DateMonth=\"" + QString::number( ev.dueDate().month() ) + "\" ";
518 str += "DateDay=\"" + QString::number( ev.dueDate().day() ) + "\" "; 540 str += "DateDay=\"" + QString::number( ev.dueDate().day() ) + "\" ";
519 } 541 }
520// qWarning( "Uid %d", ev.uid() ); 542// qWarning( "Uid %d", ev.uid() );
521 str += "Uid=\"" + QString::number( ev.uid() ) + "\" "; 543 str += "Uid=\"" + QString::number( ev.uid() ) + "\" ";
522 544
523// append the extra options 545// append the extra options
524 /* FIXME Qtopia::Record this is currently not 546 /* FIXME Qtopia::Record this is currently not
525 * possible you can set custom fields 547 * possible you can set custom fields
526 * but don' iterate over the list 548 * but don' iterate over the list
527 * I may do #define private protected 549 * I may do #define private protected
528 * for this case - cough --zecke 550 * for this case - cough --zecke
529 */ 551 */
530 /* 552 /*
531 QMap<QString, QString> extras = ev.extras(); 553 QMap<QString, QString> extras = ev.extras();
532 QMap<QString, QString>::Iterator extIt; 554 QMap<QString, QString>::Iterator extIt;
533 for (extIt = extras.begin(); extIt != extras.end(); ++extIt ) 555 for (extIt = extras.begin(); extIt != extras.end(); ++extIt )
534 str += extIt.key() + "=\"" + extIt.data() + "\" "; 556 str += extIt.key() + "=\"" + extIt.data() + "\" ";
535 */ 557 */
536 // cross refernce 558 // cross refernce
537 if ( ev.hasRecurrence() ) { 559 if ( ev.hasRecurrence() ) {
538 str += ev.recurrence().toString(); 560 str += ev.recurrence().toString();
539 } 561 }
540 if ( ev.hasStartDate() ) 562 if ( ev.hasStartDate() )
541 str += "StartDate=\""+ OConversion::dateToString( ev.startDate() ) +"\" "; 563 str += "StartDate=\""+ OConversion::dateToString( ev.startDate() ) +"\" ";
542 if ( ev.hasCompletedDate() ) 564 if ( ev.hasCompletedDate() )
543 str += "CompletedDate=\""+ OConversion::dateToString( ev.completedDate() ) +"\" "; 565 str += "CompletedDate=\""+ OConversion::dateToString( ev.completedDate() ) +"\" ";
544 if ( ev.hasState() ) 566 if ( ev.hasState() )
545 str += "State=\""+QString::number( ev.state().state() )+"\" "; 567 str += "State=\""+QString::number( ev.state().state() )+"\" ";
546 568
547 /* 569 /*
548 * save reminders and notifiers! 570 * save reminders and notifiers!
549 * 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:....
550 */ 572 */
551 if ( ev.hasNotifiers() ) { 573 if ( ev.hasNotifiers() ) {
552 OPimNotifyManager manager = ev.notifiers(); 574 OPimNotifyManager manager = ev.notifiers();
553 OPimNotifyManager::Alarms alarms = manager.alarms(); 575 OPimNotifyManager::Alarms alarms = manager.alarms();
554 if (!alarms.isEmpty() ) { 576 if (!alarms.isEmpty() ) {
555 QStringList als; 577 QStringList als;
556 OPimNotifyManager::Alarms::Iterator it = alarms.begin(); 578 OPimNotifyManager::Alarms::Iterator it = alarms.begin();
557 for ( ; it != alarms.end(); ++it ) { 579 for ( ; it != alarms.end(); ++it ) {
558 /* only if time is valid */ 580 /* only if time is valid */
559 if ( (*it).dateTime().isValid() ) { 581 if ( (*it).dateTime().isValid() ) {
560 als << OConversion::dateTimeToString( (*it).dateTime() ) 582 als << OConversion::dateTimeToString( (*it).dateTime() )
561 + ":" + QString::number( (*it).duration() ) 583 + ":" + QString::number( (*it).duration() )
562 + ":" + QString::number( (*it).sound() ) 584 + ":" + QString::number( (*it).sound() )
563 + ":"; 585 + ":";
564 } 586 }
565 } 587 }
566 // now write the list 588 // now write the list
567 qWarning("als: %s", als.join("____________").latin1() ); 589 qWarning("als: %s", als.join("____________").latin1() );
568 str += "Alarms=\""+als.join(";") +"\" "; 590 str += "Alarms=\""+als.join(";") +"\" ";
569 } 591 }
570 592
571 /* 593 /*
572 * 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.
573 */ 595 */
574 OPimNotifyManager::Reminders reminders = manager.reminders(); 596 OPimNotifyManager::Reminders reminders = manager.reminders();
575 if (!reminders.isEmpty() ) { 597 if (!reminders.isEmpty() ) {
576 OPimNotifyManager::Reminders::Iterator it = reminders.begin(); 598 OPimNotifyManager::Reminders::Iterator it = reminders.begin();
577 QStringList records; 599 QStringList records;
578 for ( ; it != reminders.end(); ++it ) { 600 for ( ; it != reminders.end(); ++it ) {
579 records << QString::number( (*it).recordUid() ); 601 records << QString::number( (*it).recordUid() );
580 } 602 }
581 str += "Reminders=\""+ records.join(";") +"\" "; 603 str += "Reminders=\""+ records.join(";") +"\" ";
582 } 604 }
583 } 605 }
606 str += customToXml( ev.toExtraMap() );
584 607
585 608
586 return str; 609 return str;
587} 610}
588QString OTodoAccessXML::toString( const QArray<int>& ints ) const { 611QString OTodoAccessXML::toString( const QArray<int>& ints ) const {
589 return Qtopia::Record::idsToString( ints ); 612 return Qtopia::Record::idsToString( ints );
590} 613}
591 614
592/* internal class for sorting 615/* internal class for sorting
593 * 616 *
594 * Inspired by todoxmlio.cpp from TT 617 * Inspired by todoxmlio.cpp from TT
595 */ 618 */
596 619
597struct OTodoXMLContainer { 620struct OTodoXMLContainer {
598 OTodo todo; 621 OTodo todo;
599}; 622};
600 623
601namespace { 624namespace {
602 inline QString string( const OTodo& todo) { 625 inline QString string( const OTodo& todo) {
603 return todo.summary().isEmpty() ? 626 return todo.summary().isEmpty() ?
604 todo.description().left(20 ) : 627 todo.description().left(20 ) :
605 todo.summary(); 628 todo.summary();
606 } 629 }
607 inline int completed( const OTodo& todo1, const OTodo& todo2) { 630 inline int completed( const OTodo& todo1, const OTodo& todo2) {
608 int ret = 0; 631 int ret = 0;
609 if ( todo1.isCompleted() ) ret++; 632 if ( todo1.isCompleted() ) ret++;
610 if ( todo2.isCompleted() ) ret--; 633 if ( todo2.isCompleted() ) ret--;
611 return ret; 634 return ret;
612 } 635 }
613 inline int priority( const OTodo& t1, const OTodo& t2) { 636 inline int priority( const OTodo& t1, const OTodo& t2) {
614 return ( t1.priority() - t2.priority() ); 637 return ( t1.priority() - t2.priority() );
615 } 638 }
616 inline int description( const OTodo& t1, const OTodo& t2) { 639 inline int description( const OTodo& t1, const OTodo& t2) {
617 return QString::compare( string(t1), string(t2) ); 640 return QString::compare( string(t1), string(t2) );
618 } 641 }
619 inline int deadline( const OTodo& t1, const OTodo& t2) { 642 inline int deadline( const OTodo& t1, const OTodo& t2) {
620 int ret = 0; 643 int ret = 0;
621 if ( t1.hasDueDate() && 644 if ( t1.hasDueDate() &&
622 t2.hasDueDate() ) 645 t2.hasDueDate() )
623 ret = t2.dueDate().daysTo( t1.dueDate() ); 646 ret = t2.dueDate().daysTo( t1.dueDate() );
624 else if ( t1.hasDueDate() ) 647 else if ( t1.hasDueDate() )
625 ret = -1; 648 ret = -1;
626 else if ( t2.hasDueDate() ) 649 else if ( t2.hasDueDate() )
627 ret = 1; 650 ret = 1;
628 else 651 else
629 ret = 0; 652 ret = 0;
630 653
631 return ret; 654 return ret;
632 } 655 }
633 656
634}; 657};
635 658
636/* 659/*
637 * Returns: 660 * Returns:
638 * 0 if item1 == item2 661 * 0 if item1 == item2
639 * 662 *
640 * non-zero if item1 != item2 663 * non-zero if item1 != item2
641 * 664 *
642 * This function returns int rather than bool so that reimplementations 665 * This function returns int rather than bool so that reimplementations
643 * 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:
644 * 667 *
645 * 0 if item1 == item2 668 * 0 if item1 == item2
646 * 669 *
647 * > 0 (positive integer) if item1 > item2 670 * > 0 (positive integer) if item1 > item2
648 * 671 *
649 * < 0 (negative integer) if item1 < item2 672 * < 0 (negative integer) if item1 < item2
650 * 673 *
651 */ 674 */
652class OTodoXMLVector : public QVector<OTodoXMLContainer> { 675class OTodoXMLVector : public QVector<OTodoXMLContainer> {
653public: 676public:
654 OTodoXMLVector(int size, bool asc, int sort) 677 OTodoXMLVector(int size, bool asc, int sort)
655 : QVector<OTodoXMLContainer>( size ) 678 : QVector<OTodoXMLContainer>( size )
656 { 679 {
657 setAutoDelete( true ); 680 setAutoDelete( true );
658 m_asc = asc; 681 m_asc = asc;
659 m_sort = sort; 682 m_sort = sort;
660 } 683 }
661 /* return the summary/description */ 684 /* return the summary/description */
662 QString string( const OTodo& todo) { 685 QString string( const OTodo& todo) {
663 return todo.summary().isEmpty() ? 686 return todo.summary().isEmpty() ?
664 todo.description().left(20 ) : 687 todo.description().left(20 ) :
665 todo.summary(); 688 todo.summary();
666 } 689 }
667 /** 690 /**
668 * we take the sortorder( switch on it ) 691 * we take the sortorder( switch on it )
669 * 692 *
670 */ 693 */
671 int compareItems( Item d1, Item d2 ) { 694 int compareItems( Item d1, Item d2 ) {
672 bool seComp, sePrio, seDesc, seDeadline; 695 bool seComp, sePrio, seDesc, seDeadline;
673 seComp = sePrio = seDeadline = seDesc = false; 696 seComp = sePrio = seDeadline = seDesc = false;
674 int ret =0; 697 int ret =0;
675 OTodoXMLContainer* con1 = (OTodoXMLContainer*)d1; 698 OTodoXMLContainer* con1 = (OTodoXMLContainer*)d1;
676 OTodoXMLContainer* con2 = (OTodoXMLContainer*)d2; 699 OTodoXMLContainer* con2 = (OTodoXMLContainer*)d2;
677 700
678 /* same item */ 701 /* same item */
679 if ( con1->todo.uid() == con2->todo.uid() ) 702 if ( con1->todo.uid() == con2->todo.uid() )
680 return 0; 703 return 0;
681 704
682 switch ( m_sort ) { 705 switch ( m_sort ) {
683 /* completed */ 706 /* completed */
684 case 0: { 707 case 0: {
685 ret = completed( con1->todo, con2->todo ); 708 ret = completed( con1->todo, con2->todo );
686 seComp = TRUE; 709 seComp = TRUE;
687 break; 710 break;
688 } 711 }
689 /* priority */ 712 /* priority */
690 case 1: { 713 case 1: {
691 ret = priority( con1->todo, con2->todo ); 714 ret = priority( con1->todo, con2->todo );
692 sePrio = TRUE; 715 sePrio = TRUE;
693 break; 716 break;
694 } 717 }
695 /* description */ 718 /* description */
696 case 2: { 719 case 2: {
697 ret = description( con1->todo, con2->todo ); 720 ret = description( con1->todo, con2->todo );
698 seDesc = TRUE; 721 seDesc = TRUE;
699 break; 722 break;
700 } 723 }
701 /* deadline */ 724 /* deadline */
702 case 3: { 725 case 3: {
703 ret = deadline( con1->todo, con2->todo ); 726 ret = deadline( con1->todo, con2->todo );
704 seDeadline = TRUE; 727 seDeadline = TRUE;
705 break; 728 break;
706 } 729 }
707 default: 730 default:
708 ret = 0; 731 ret = 0;
709 break; 732 break;
710 }; 733 };
711 /* 734 /*
712 * FIXME do better sorting if the first sort criteria 735 * FIXME do better sorting if the first sort criteria
713 * ret equals 0 start with complete and so on... 736 * ret equals 0 start with complete and so on...
714 */ 737 */
715 738
716 /* twist it we're not ascending*/ 739 /* twist it we're not ascending*/
717 if (!m_asc) 740 if (!m_asc)
718 ret = ret * -1; 741 ret = ret * -1;
719 742
720 if ( ret ) 743 if ( ret )
721 return ret; 744 return ret;
722 745
723 // 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
724 /* 747 /*
725 * General try if already checked if not test 748 * General try if already checked if not test
726 * and return 749 * and return
727 * 1.Completed 750 * 1.Completed
728 * 2.Priority 751 * 2.Priority
729 * 3.Description 752 * 3.Description
730 * 4.DueDate 753 * 4.DueDate
731 */ 754 */
732 if (!seComp ) { 755 if (!seComp ) {
733 if ( (ret = completed( con1->todo, con2->todo ) ) ) { 756 if ( (ret = completed( con1->todo, con2->todo ) ) ) {
734 if (!m_asc ) ret *= -1; 757 if (!m_asc ) ret *= -1;
735 return ret; 758 return ret;
736 } 759 }
737 } 760 }
738 if (!sePrio ) { 761 if (!sePrio ) {
739 if ( (ret = priority( con1->todo, con2->todo ) ) ) { 762 if ( (ret = priority( con1->todo, con2->todo ) ) ) {
740 if (!m_asc ) ret *= -1; 763 if (!m_asc ) ret *= -1;
741 return ret; 764 return ret;
742 } 765 }
743 } 766 }
744 if (!seDesc ) { 767 if (!seDesc ) {
745 if ( (ret = description(con1->todo, con2->todo ) ) ) { 768 if ( (ret = description(con1->todo, con2->todo ) ) ) {
746 if (!m_asc) ret *= -1; 769 if (!m_asc) ret *= -1;
747 return ret; 770 return ret;
748 } 771 }
749 } 772 }
750 if (!seDeadline) { 773 if (!seDeadline) {
751 if ( (ret = deadline( con1->todo, con2->todo ) ) ) { 774 if ( (ret = deadline( con1->todo, con2->todo ) ) ) {
752 if (!m_asc) ret *= -1; 775 if (!m_asc) ret *= -1;
753 return ret; 776 return ret;
754 } 777 }
755 } 778 }
756 779
757 return 0; 780 return 0;
758 } 781 }
759 private: 782 private:
760 bool m_asc; 783 bool m_asc;
761 int m_sort; 784 int m_sort;
762 785
763}; 786};
764 787
765QArray<int> OTodoAccessXML::sorted( bool asc, int sortOrder, 788QArray<int> OTodoAccessXML::sorted( bool asc, int sortOrder,
766 int sortFilter, int cat ) { 789 int sortFilter, int cat ) {
767 OTodoXMLVector vector(m_events.count(), asc,sortOrder ); 790 OTodoXMLVector vector(m_events.count(), asc,sortOrder );
768 QMap<int, OTodo>::Iterator it; 791 QMap<int, OTodo>::Iterator it;
769 int item = 0; 792 int item = 0;
770 793
771 bool bCat = sortFilter & 1 ? true : false; 794 bool bCat = sortFilter & 1 ? true : false;
772 bool bOnly = sortFilter & 2 ? true : false; 795 bool bOnly = sortFilter & 2 ? true : false;
773 bool comp = sortFilter & 4 ? true : false; 796 bool comp = sortFilter & 4 ? true : false;
774 for ( it = m_events.begin(); it != m_events.end(); ++it ) { 797 for ( it = m_events.begin(); it != m_events.end(); ++it ) {
775 798
776 /* show category */ 799 /* show category */
777 /* -1 == unfiled */ 800 /* -1 == unfiled */
778 if ( bCat && cat == -1 ) { 801 if ( bCat && cat == -1 ) {
779 if(!(*it).categories().isEmpty() ) 802 if(!(*it).categories().isEmpty() )
780 continue; 803 continue;
781 }else if ( bCat && cat != 0) 804 }else if ( bCat && cat != 0)
782 if (!(*it).categories().contains( cat ) ) { 805 if (!(*it).categories().contains( cat ) ) {
783 continue; 806 continue;
784 } 807 }
785 /* isOverdue but we should not show overdue - why?*/ 808 /* isOverdue but we should not show overdue - why?*/
786/* if ( (*it).isOverdue() && !bOnly ) { 809/* if ( (*it).isOverdue() && !bOnly ) {
787 qWarning("item is overdue but !bOnly"); 810 qWarning("item is overdue but !bOnly");
788 continue; 811 continue;
789 } 812 }
790*/ 813*/
791 if ( !(*it).isOverdue() && bOnly ) { 814 if ( !(*it).isOverdue() && bOnly ) {
792 continue; 815 continue;
793 } 816 }
794 817
795 if ((*it).isCompleted() && comp ) { 818 if ((*it).isCompleted() && comp ) {
796 continue; 819 continue;
797 } 820 }
798 821
799 822
800 OTodoXMLContainer* con = new OTodoXMLContainer(); 823 OTodoXMLContainer* con = new OTodoXMLContainer();
801 con->todo = (*it); 824 con->todo = (*it);
802 vector.insert(item, con ); 825 vector.insert(item, con );
803 item++; 826 item++;
804 } 827 }
805 vector.resize( item ); 828 vector.resize( item );
806 /* sort it now */ 829 /* sort it now */
807 vector.sort(); 830 vector.sort();
808 /* now get the uids */ 831 /* now get the uids */
809 QArray<int> array( vector.count() ); 832 QArray<int> array( vector.count() );
810 for (uint i= 0; i < vector.count(); i++ ) { 833 for (uint i= 0; i < vector.count(); i++ ) {
811 array[i] = ( vector.at(i) )->todo.uid(); 834 array[i] = ( vector.at(i) )->todo.uid();
812 } 835 }
813 return array; 836 return array;
814}; 837};
815void OTodoAccessXML::removeAllCompleted() { 838void OTodoAccessXML::removeAllCompleted() {
816 for ( QMap<int, OTodo>::Iterator it = m_events.begin(); it != m_events.end(); ++it ) { 839 for ( QMap<int, OTodo>::Iterator it = m_events.begin(); it != m_events.end(); ++it ) {
817 if ( (*it).isCompleted() ) 840 if ( (*it).isCompleted() )
818 m_events.remove( it ); 841 m_events.remove( it );
819 } 842 }
820} 843}
821QBitArray OTodoAccessXML::supports()const { 844QBitArray OTodoAccessXML::supports()const {
822 static QBitArray ar = sup(); 845 static QBitArray ar = sup();
823 return ar; 846 return ar;
824} 847}
825QBitArray OTodoAccessXML::sup() { 848QBitArray OTodoAccessXML::sup() {
826 QBitArray ar( OTodo::CompletedDate +1 ); 849 QBitArray ar( OTodo::CompletedDate +1 );
827 ar.fill( true ); 850 ar.fill( true );
828 ar[OTodo::CrossReference] = false; 851 ar[OTodo::CrossReference] = false;
829 ar[OTodo::State ] = false; 852 ar[OTodo::State ] = false;
830 ar[OTodo::Reminders] = false; 853 ar[OTodo::Reminders] = false;
831 ar[OTodo::Notifiers] = false; 854 ar[OTodo::Notifiers] = false;
832 ar[OTodo::Maintainer] = false; 855 ar[OTodo::Maintainer] = false;
833 856
834 return ar; 857 return ar;
835} 858}
836QArray<int> OTodoAccessXML::matchRegexp( const QRegExp &r ) const 859QArray<int> OTodoAccessXML::matchRegexp( const QRegExp &r ) const
837{ 860{
838 QArray<int> m_currentQuery( m_events.count() ); 861 QArray<int> m_currentQuery( m_events.count() );
839 uint arraycounter = 0; 862 uint arraycounter = 0;
840 863
841 QMap<int, OTodo>::ConstIterator it; 864 QMap<int, OTodo>::ConstIterator it;
842 for (it = m_events.begin(); it != m_events.end(); ++it ) { 865 for (it = m_events.begin(); it != m_events.end(); ++it ) {
843 if ( it.data().match( r ) ) 866 if ( it.data().match( r ) )
844 m_currentQuery[arraycounter++] = it.data().uid(); 867 m_currentQuery[arraycounter++] = it.data().uid();
845 868
846 } 869 }
847 // Shrink to fit.. 870 // Shrink to fit..
848 m_currentQuery.resize(arraycounter); 871 m_currentQuery.resize(arraycounter);
849 872
850 return m_currentQuery; 873 return m_currentQuery;
851} 874}