summaryrefslogtreecommitdiff
path: root/libopie2
Unidiff
Diffstat (limited to 'libopie2') (more/less context) (ignore whitespace changes)
-rw-r--r--libopie2/opiepim/ocontact.cpp31
-rw-r--r--libopie2/opiepim/oevent.cpp56
-rw-r--r--libopie2/opiepim/otodo.cpp54
3 files changed, 106 insertions, 35 deletions
diff --git a/libopie2/opiepim/ocontact.cpp b/libopie2/opiepim/ocontact.cpp
index a7ca975..a2fb68c 100644
--- a/libopie2/opiepim/ocontact.cpp
+++ b/libopie2/opiepim/ocontact.cpp
@@ -1,1139 +1,1144 @@
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>" + Qtopia::escapeString(value) + "</h3></b><br>"; 443 text += "<b><h3><img src=\"addressbook/AddressBook\">" + Qtopia::escapeString(value) + "</h3></b>";
444
444 if ( !(value = jobTitle()).isEmpty() ) 445 if ( !(value = jobTitle()).isEmpty() )
445 text += Qtopia::escapeString(value) + "<br>"; 446 text += Qtopia::escapeString(value) + "<br>";
446 447
447 comp = company(); 448 comp = company();
448 if ( !(value = department()).isEmpty() ) { 449 if ( !(value = department()).isEmpty() ) {
449 text += Qtopia::escapeString(value); 450 text += Qtopia::escapeString(value);
450 if ( comp ) 451 if ( comp )
451 text += ", "; 452 text += ", ";
452 else 453 else
453 text += "<br>"; 454 text += "<br>";
454 } 455 }
455 if ( !comp.isEmpty() ) 456 if ( !comp.isEmpty() )
456 text += Qtopia::escapeString(comp) + "<br>"; 457 text += Qtopia::escapeString(comp) + "<br>";
457 458
459 text += "<hr><br>";
460
461 // defailt email
458 QString defEmail = defaultEmail(); 462 QString defEmail = defaultEmail();
459 if ( !defEmail.isEmpty() ) 463 if ( !defEmail.isEmpty() )
460 text += "<b>" + QObject::tr("Default Email: ") + "</b>" 464 text += "<b><img src=\"addressbook/email\">" + QObject::tr("Default Email: ") + "</b>"
461 + Qtopia::escapeString(defEmail) + "<br>"; 465 + Qtopia::escapeString(defEmail) + "<br>";
462 466
463 text += "<hr>"; 467 text += "<br>";
464 468
465 // business address 469 // business address
466 if ( !businessStreet().isEmpty() || !businessCity().isEmpty() || 470 if ( !businessStreet().isEmpty() || !businessCity().isEmpty() ||
467 !businessZip().isEmpty() || !businessCountry().isEmpty() ) { 471 !businessZip().isEmpty() || !businessCountry().isEmpty() ) {
468 text += "<br>";
469 text += QObject::tr( "<b>Work Address:</b>" ); 472 text += QObject::tr( "<b>Work Address:</b>" );
470 text += "<br>"; 473 text += "<br>";
471 marker = true; 474 marker = true;
472 } 475 }
473 476
474 if ( !(value = businessStreet()).isEmpty() ) 477 if ( !(value = businessStreet()).isEmpty() )
475 text += Qtopia::escapeString(value) + "<br>"; 478 text += Qtopia::escapeString(value) + "<br>";
476 state = businessState(); 479 state = businessState();
477 if ( !(value = businessZip()).isEmpty() ) 480 if ( !(value = businessZip()).isEmpty() )
478 text += Qtopia::escapeString(value) + " "; 481 text += Qtopia::escapeString(value) + " ";
479 if ( !(value = businessCity()).isEmpty() ) { 482 if ( !(value = businessCity()).isEmpty() ) {
480 text += Qtopia::escapeString(value); 483 text += Qtopia::escapeString(value);
481 if ( state ) 484 if ( state )
482 text += ", " + Qtopia::escapeString(state); 485 text += ", " + Qtopia::escapeString(state);
483 text += "<br>"; 486 text += "<br>";
484 } else if ( !state.isEmpty() ) 487 } else if ( !state.isEmpty() )
485 text += Qtopia::escapeString(state) + "<br>"; 488 text += Qtopia::escapeString(state) + "<br>";
486 489
487 if ( !(value = businessCountry()).isEmpty() ) 490 if ( !(value = businessCountry()).isEmpty() )
488 text += Qtopia::escapeString(value) + "<br>"; 491 text += Qtopia::escapeString(value) + "<br>";
489 492
490 // rest of Business data 493 // rest of Business data
491 str = office(); 494 str = office();
492 if ( !str.isEmpty() ){ 495 if ( !str.isEmpty() ){
493 text += "<b>" + QObject::tr("Office: ") + "</b>" 496 text += "<b>" + QObject::tr("Office: ") + "</b>"
494 + Qtopia::escapeString(str) + "<br>"; 497 + Qtopia::escapeString(str) + "<br>";
495 marker = true; 498 marker = true;
496 } 499 }
497 str = businessWebpage(); 500 str = businessWebpage();
498 if ( !str.isEmpty() ){ 501 if ( !str.isEmpty() ){
499 text += "<b>" + QObject::tr("Business Web Page: ") + "</b>" 502 text += "<b><img src=\"addressbook/webpagework\">" + QObject::tr("Business Web Page: ") + "</b>"
500 + Qtopia::escapeString(str) + "<br>"; 503 + Qtopia::escapeString(str) + "<br>";
501 marker = true; 504 marker = true;
502 } 505 }
503 str = businessPhone(); 506 str = businessPhone();
504 if ( !str.isEmpty() ){ 507 if ( !str.isEmpty() ){
505 text += "<b>" + QObject::tr("Business Phone: ") + "</b>" 508 text += "<b><img src=\"addressbook/phonework\">" + QObject::tr("Business Phone: ") + "</b>"
506 + Qtopia::escapeString(str) + "<br>"; 509 + Qtopia::escapeString(str) + "<br>";
507 marker = true; 510 marker = true;
508 } 511 }
509 str = businessFax(); 512 str = businessFax();
510 if ( !str.isEmpty() ){ 513 if ( !str.isEmpty() ){
511 text += "<b>" + QObject::tr("Business Fax: ") + "</b>" 514 text += "<b><img src=\"addressbook/faxwork\">" + QObject::tr("Business Fax: ") + "</b>"
512 + Qtopia::escapeString(str) + "<br>"; 515 + Qtopia::escapeString(str) + "<br>";
513 marker = true; 516 marker = true;
514 } 517 }
515 str = businessMobile(); 518 str = businessMobile();
516 if ( !str.isEmpty() ){ 519 if ( !str.isEmpty() ){
517 text += "<b>" + QObject::tr("Business Mobile: ") + "</b>" 520 text += "<b><img src=\"addressbook/mobilework\">" + QObject::tr("Business Mobile: ") + "</b>"
518 + Qtopia::escapeString(str) + "<br>"; 521 + Qtopia::escapeString(str) + "<br>";
519 marker = true; 522 marker = true;
520 } 523 }
521 str = businessPager(); 524 str = businessPager();
522 if ( !str.isEmpty() ){ 525 if ( !str.isEmpty() ){
523 text += "<b>" + QObject::tr("Business Pager: ") + "</b>" 526 text += "<b>" + QObject::tr("Business Pager: ") + "</b>"
524 + Qtopia::escapeString(str) + "<br>"; 527 + Qtopia::escapeString(str) + "<br>";
525 marker = true; 528 marker = true;
526 } 529 }
527 530
531 text += "<br>";
532
528 // home address 533 // home address
529 if ( !homeStreet().isEmpty() || !homeCity().isEmpty() || 534 if ( !homeStreet().isEmpty() || !homeCity().isEmpty() ||
530 !homeZip().isEmpty() || !homeCountry().isEmpty() ) { 535 !homeZip().isEmpty() || !homeCountry().isEmpty() ) {
531 text += "<br>";
532 text += QObject::tr( "<b>Home Address:</b>" ); 536 text += QObject::tr( "<b>Home Address:</b>" );
533 text += "<br>"; 537 text += "<br>";
534 } 538 }
535 539
536 if ( !(value = homeStreet()).isEmpty() ) 540 if ( !(value = homeStreet()).isEmpty() )
537 text += Qtopia::escapeString(value) + "<br>"; 541 text += Qtopia::escapeString(value) + "<br>";
538 state = homeState(); 542 state = homeState();
539 if ( !(value = homeZip()).isEmpty() ) 543 if ( !(value = homeZip()).isEmpty() )
540 text += Qtopia::escapeString(value) + " "; 544 text += Qtopia::escapeString(value) + " ";
541 if ( !(value = homeCity()).isEmpty() ) { 545 if ( !(value = homeCity()).isEmpty() ) {
542 text += Qtopia::escapeString(value); 546 text += Qtopia::escapeString(value);
543 if ( !state.isEmpty() ) 547 if ( !state.isEmpty() )
544 text += ", " + Qtopia::escapeString(state); 548 text += ", " + Qtopia::escapeString(state);
545 text += "<br>"; 549 text += "<br>";
546 } else if (!state.isEmpty()) 550 } else if (!state.isEmpty())
547 text += Qtopia::escapeString(state) + "<br>"; 551 text += Qtopia::escapeString(state) + "<br>";
548 if ( !(value = homeCountry()).isEmpty() ) 552 if ( !(value = homeCountry()).isEmpty() )
549 text += Qtopia::escapeString(value) + "<br>"; 553 text += Qtopia::escapeString(value) + "<br>";
550 554
551 // rest of Home data 555 // rest of Home data
552 str = homeWebpage(); 556 str = homeWebpage();
553 if ( !str.isEmpty() ){ 557 if ( !str.isEmpty() ){
554 text += "<b>" + QObject::tr("Home Web Page: ") + "</b>" 558 text += "<b><img src=\"addressbook/webpagehome\">" + QObject::tr("Home Web Page: ") + "</b>"
555 + Qtopia::escapeString(str) + "<br>"; 559 + Qtopia::escapeString(str) + "<br>";
556 marker = true; 560 marker = true;
557 } 561 }
558 str = homePhone(); 562 str = homePhone();
559 if ( !str.isEmpty() ){ 563 if ( !str.isEmpty() ){
560 text += "<b>" + QObject::tr("Home Phone: ") + "</b>" 564 text += "<b><img src=\"addressbook/phonehome\">" + QObject::tr("Home Phone: ") + "</b>"
561 + Qtopia::escapeString(str) + "<br>"; 565 + Qtopia::escapeString(str) + "<br>";
562 marker = true; 566 marker = true;
563 } 567 }
564 str = homeFax(); 568 str = homeFax();
565 if ( !str.isEmpty() ){ 569 if ( !str.isEmpty() ){
566 text += "<b>" + QObject::tr("Home Fax: ") + "</b>" 570 text += "<b><img src=\"addressbook/faxhome\">" + QObject::tr("Home Fax: ") + "</b>"
567 + Qtopia::escapeString(str) + "<br>"; 571 + Qtopia::escapeString(str) + "<br>";
568 marker = true; 572 marker = true;
569 } 573 }
570 str = homeMobile(); 574 str = homeMobile();
571 if ( !str.isEmpty() ){ 575 if ( !str.isEmpty() ){
572 text += "<b>" + QObject::tr("Home Mobile: ") + "</b>" 576 text += "<b><img src=\"addressbook/mobilehome\">" + QObject::tr("Home Mobile: ") + "</b>"
573 + Qtopia::escapeString(str) + "<br>"; 577 + Qtopia::escapeString(str) + "<br>";
574 marker = true; 578 marker = true;
575 } 579 }
576 580
577 if ( marker ) 581 if ( marker )
578 text += "<br><hr><br>"; 582 text += "<br><hr><br>";
579 // the others... 583 // the others...
580 str = emails(); 584 str = emails();
581 if ( !str.isEmpty() && ( str != defEmail ) ) 585 if ( !str.isEmpty() && ( str != defEmail ) )
582 text += "<b>" + QObject::tr("All Emails: ") + "</b>" 586 text += "<b>" + QObject::tr("All Emails: ") + "</b>"
583 + Qtopia::escapeString(str) + "<br>"; 587 + Qtopia::escapeString(str) + "<br>";
584 str = profession(); 588 str = profession();
585 if ( !str.isEmpty() ) 589 if ( !str.isEmpty() )
586 text += "<b>" + QObject::tr("Profession: ") + "</b>" 590 text += "<b>" + QObject::tr("Profession: ") + "</b>"
587 + Qtopia::escapeString(str) + "<br>"; 591 + Qtopia::escapeString(str) + "<br>";
588 str = assistant(); 592 str = assistant();
589 if ( !str.isEmpty() ) 593 if ( !str.isEmpty() )
590 text += "<b>" + QObject::tr("Assistant: ") + "</b>" 594 text += "<b>" + QObject::tr("Assistant: ") + "</b>"
591 + Qtopia::escapeString(str) + "<br>"; 595 + Qtopia::escapeString(str) + "<br>";
592 str = manager(); 596 str = manager();
593 if ( !str.isEmpty() ) 597 if ( !str.isEmpty() )
594 text += "<b>" + QObject::tr("Manager: ") + "</b>" 598 text += "<b>" + QObject::tr("Manager: ") + "</b>"
595 + Qtopia::escapeString(str) + "<br>"; 599 + Qtopia::escapeString(str) + "<br>";
596 str = gender(); 600 str = gender();
597 if ( !str.isEmpty() && str.toInt() != 0 ) { 601 if ( !str.isEmpty() && str.toInt() != 0 ) {
598 if ( str.toInt() == 1 ) 602 if ( str.toInt() == 1 )
599 str = QObject::tr( "Male" ); 603 str = QObject::tr( "Male" );
600 else if ( str.toInt() == 2 ) 604 else if ( str.toInt() == 2 )
601 str = QObject::tr( "Female" ); 605 str = QObject::tr( "Female" );
602 text += "<b>" + QObject::tr("Gender: ") + "</b>" + str + "<br>"; 606 text += "<b>" + QObject::tr("Gender: ") + "</b>" + str + "<br>";
603 } 607 }
604 str = spouse(); 608 str = spouse();
605 if ( !str.isEmpty() ) 609 if ( !str.isEmpty() )
606 text += "<b>" + QObject::tr("Spouse: ") + "</b>" 610 text += "<b>" + QObject::tr("Spouse: ") + "</b>"
607 + Qtopia::escapeString(str) + "<br>"; 611 + Qtopia::escapeString(str) + "<br>";
608 if ( birthday().isValid() ){ 612 if ( birthday().isValid() ){
609 str = TimeString::numberDateString( birthday() ); 613 str = TimeString::numberDateString( birthday() );
610 text += "<b>" + QObject::tr("Birthday: ") + "</b>" 614 text += "<b>" + QObject::tr("Birthday: ") + "</b>"
611 + Qtopia::escapeString(str) + "<br>"; 615 + Qtopia::escapeString(str) + "<br>";
612 } 616 }
613 if ( anniversary().isValid() ){ 617 if ( anniversary().isValid() ){
614 str = TimeString::numberDateString( anniversary() ); 618 str = TimeString::numberDateString( anniversary() );
615 text += "<b>" + QObject::tr("Anniversary: ") + "</b>" 619 text += "<b>" + QObject::tr("Anniversary: ") + "</b>"
616 + Qtopia::escapeString(str) + "<br>"; 620 + Qtopia::escapeString(str) + "<br>";
617 } 621 }
618 str = children(); 622 str = children();
619 if ( !str.isEmpty() ) 623 if ( !str.isEmpty() )
620 text += "<b>" + QObject::tr("Children: ") + "</b>" 624 text += "<b>" + QObject::tr("Children: ") + "</b>"
621 + Qtopia::escapeString(str) + "<br>"; 625 + Qtopia::escapeString(str) + "<br>";
622 626
623 str = nickname(); 627 str = nickname();
624 if ( !str.isEmpty() ) 628 if ( !str.isEmpty() )
625 text += "<b>" + QObject::tr("Nickname: ") + "</b>" 629 text += "<b>" + QObject::tr("Nickname: ") + "</b>"
626 + Qtopia::escapeString(str) + "<br>"; 630 + Qtopia::escapeString(str) + "<br>";
627 631
632 // categories
628 if ( categoryNames("Contacts").count() ){ 633 if ( categoryNames("Contacts").count() ){
629 text += "<b>" + QObject::tr( "Category:") + "</b> "; 634 text += "<b>" + QObject::tr( "Category:") + "</b> ";
630 text += categoryNames("Contacts").join(", "); 635 text += categoryNames("Contacts").join(", ");
631 text += "<br>"; 636 text += "<br>";
632 } 637 }
633 638
634 // notes last 639 // notes last
635 if ( !(value = notes()).isEmpty() ) { 640 if ( !(value = notes()).isEmpty() ) {
636 text += "<br><hr><b>" + QObject::tr( "Notes:") + "</b> "; 641 text += "<br><hr><b>" + QObject::tr( "Notes:") + "</b> ";
637 QRegExp reg("\n"); 642 QRegExp reg("\n");
638 643
639 //QString tmp = Qtopia::escapeString(value); 644 //QString tmp = Qtopia::escapeString(value);
640 QString tmp = QStyleSheet::convertFromPlainText(value); 645 QString tmp = QStyleSheet::convertFromPlainText(value);
641 //tmp.replace( reg, "<br>" ); 646 //tmp.replace( reg, "<br>" );
642 text += "<br>" + tmp + "<br>"; 647 text += "<br>" + tmp + "<br>";
643 } 648 }
644 return text; 649 return text;
645} 650}
646 651
647/*! 652/*!
648 \internal 653 \internal
649*/ 654*/
650void OContact::insert( int key, const QString &v ) 655void OContact::insert( int key, const QString &v )
651{ 656{
652 QString value = v.stripWhiteSpace(); 657 QString value = v.stripWhiteSpace();
653 if ( value.isEmpty() ) 658 if ( value.isEmpty() )
654 mMap.remove( key ); 659 mMap.remove( key );
655 else 660 else
656 mMap.insert( key, value ); 661 mMap.insert( key, value );
657} 662}
658 663
659/*! 664/*!
660 \internal 665 \internal
661*/ 666*/
662void OContact::replace( int key, const QString & v ) 667void OContact::replace( int key, const QString & v )
663{ 668{
664 QString value = v.stripWhiteSpace(); 669 QString value = v.stripWhiteSpace();
665 if ( value.isEmpty() ) 670 if ( value.isEmpty() )
666 mMap.remove( key ); 671 mMap.remove( key );
667 else 672 else
668 mMap.replace( key, value ); 673 mMap.replace( key, value );
669} 674}
670 675
671/*! 676/*!
672 \internal 677 \internal
673*/ 678*/
674QString OContact::find( int key ) const 679QString OContact::find( int key ) const
675{ 680{
676 return mMap[key]; 681 return mMap[key];
677} 682}
678 683
679/*! 684/*!
680 \internal 685 \internal
681*/ 686*/
682QString OContact::displayAddress( const QString &street, 687QString OContact::displayAddress( const QString &street,
683 const QString &city, 688 const QString &city,
684 const QString &state, 689 const QString &state,
685 const QString &zip, 690 const QString &zip,
686 const QString &country ) const 691 const QString &country ) const
687{ 692{
688 QString s = street; 693 QString s = street;
689 if ( !street.isEmpty() ) 694 if ( !street.isEmpty() )
690 s+= "\n"; 695 s+= "\n";
691 s += city; 696 s += city;
692 if ( !city.isEmpty() && !state.isEmpty() ) 697 if ( !city.isEmpty() && !state.isEmpty() )
693 s += ", "; 698 s += ", ";
694 s += state; 699 s += state;
695 if ( !state.isEmpty() && !zip.isEmpty() ) 700 if ( !state.isEmpty() && !zip.isEmpty() )
696 s += " "; 701 s += " ";
697 s += zip; 702 s += zip;
698 if ( !country.isEmpty() && !s.isEmpty() ) 703 if ( !country.isEmpty() && !s.isEmpty() )
699 s += "\n"; 704 s += "\n";
700 s += country; 705 s += country;
701 return s; 706 return s;
702} 707}
703 708
704/*! 709/*!
705 \internal 710 \internal
706*/ 711*/
707QString OContact::displayBusinessAddress() const 712QString OContact::displayBusinessAddress() const
708{ 713{
709 return displayAddress( businessStreet(), businessCity(), 714 return displayAddress( businessStreet(), businessCity(),
710 businessState(), businessZip(), 715 businessState(), businessZip(),
711 businessCountry() ); 716 businessCountry() );
712} 717}
713 718
714/*! 719/*!
715 \internal 720 \internal
716*/ 721*/
717QString OContact::displayHomeAddress() const 722QString OContact::displayHomeAddress() const
718{ 723{
719 return displayAddress( homeStreet(), homeCity(), 724 return displayAddress( homeStreet(), homeCity(),
720 homeState(), homeZip(), 725 homeState(), homeZip(),
721 homeCountry() ); 726 homeCountry() );
722} 727}
723 728
724/*! 729/*!
725 Returns the full name of the contact 730 Returns the full name of the contact
726*/ 731*/
727QString OContact::fullName() const 732QString OContact::fullName() const
728{ 733{
729 QString title = find( Qtopia::Title ); 734 QString title = find( Qtopia::Title );
730 QString firstName = find( Qtopia::FirstName ); 735 QString firstName = find( Qtopia::FirstName );
731 QString middleName = find( Qtopia::MiddleName ); 736 QString middleName = find( Qtopia::MiddleName );
732 QString lastName = find( Qtopia::LastName ); 737 QString lastName = find( Qtopia::LastName );
733 QString suffix = find( Qtopia::Suffix ); 738 QString suffix = find( Qtopia::Suffix );
734 739
735 QString name = title; 740 QString name = title;
736 if ( !firstName.isEmpty() ) { 741 if ( !firstName.isEmpty() ) {
737 if ( !name.isEmpty() ) 742 if ( !name.isEmpty() )
738 name += " "; 743 name += " ";
739 name += firstName; 744 name += firstName;
740 } 745 }
741 if ( !middleName.isEmpty() ) { 746 if ( !middleName.isEmpty() ) {
742 if ( !name.isEmpty() ) 747 if ( !name.isEmpty() )
743 name += " "; 748 name += " ";
744 name += middleName; 749 name += middleName;
745 } 750 }
746 if ( !lastName.isEmpty() ) { 751 if ( !lastName.isEmpty() ) {
747 if ( !name.isEmpty() ) 752 if ( !name.isEmpty() )
748 name += " "; 753 name += " ";
749 name += lastName; 754 name += lastName;
750 } 755 }
751 if ( !suffix.isEmpty() ) { 756 if ( !suffix.isEmpty() ) {
752 if ( !name.isEmpty() ) 757 if ( !name.isEmpty() )
753 name += " "; 758 name += " ";
754 name += suffix; 759 name += suffix;
755 } 760 }
756 return name.simplifyWhiteSpace(); 761 return name.simplifyWhiteSpace();
757} 762}
758 763
759/*! 764/*!
760 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.
761*/ 766*/
762QStringList OContact::childrenList() const 767QStringList OContact::childrenList() const
763{ 768{
764 return QStringList::split( " ", find( Qtopia::Children ) ); 769 return QStringList::split( " ", find( Qtopia::Children ) );
765} 770}
766 771
767/*! \fn void OContact::insertEmail( const QString &email ) 772/*! \fn void OContact::insertEmail( const QString &email )
768 773
769 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
770 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.
771*/ 776*/
772 777
773/*! \fn void OContact::removeEmail( const QString &email ) 778/*! \fn void OContact::removeEmail( const QString &email )
774 779
775 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,
776 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
777 email list 782 email list
778*/ 783*/
779 784
780/*! \fn void OContact::clearEmails() 785/*! \fn void OContact::clearEmails()
781 786
782 Clears the email list. 787 Clears the email list.
783 */ 788 */
784 789
785/*! \fn void OContact::insertEmails( const QStringList &emailList ) 790/*! \fn void OContact::insertEmails( const QStringList &emailList )
786 791
787 Appends the \a emailList to the exiting email list 792 Appends the \a emailList to the exiting email list
788 */ 793 */
789 794
790/*! 795/*!
791 Returns a list of email addresses belonging to the contact, including 796 Returns a list of email addresses belonging to the contact, including
792 the default email address. 797 the default email address.
793*/ 798*/
794QStringList OContact::emailList() const 799QStringList OContact::emailList() const
795{ 800{
796 QString emailStr = emails(); 801 QString emailStr = emails();
797 802
798 QStringList r; 803 QStringList r;
799 if ( !emailStr.isEmpty() ) { 804 if ( !emailStr.isEmpty() ) {
800 qDebug(" emailstr "); 805 qDebug(" emailstr ");
801 QStringList l = QStringList::split( emailSeparator(), emailStr ); 806 QStringList l = QStringList::split( emailSeparator(), emailStr );
802 for ( QStringList::ConstIterator it = l.begin();it != l.end();++it ) 807 for ( QStringList::ConstIterator it = l.begin();it != l.end();++it )
803 r += (*it).simplifyWhiteSpace(); 808 r += (*it).simplifyWhiteSpace();
804 } 809 }
805 810
806 return r; 811 return r;
807} 812}
808 813
809/*! 814/*!
810 \overload 815 \overload
811 816
812 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,
813 middle and last name of the contact. 818 middle and last name of the contact.
814*/ 819*/
815void OContact::setFileAs() 820void OContact::setFileAs()
816{ 821{
817 QString lastName, firstName, middleName, fileas; 822 QString lastName, firstName, middleName, fileas;
818 823
819 lastName = find( Qtopia::LastName ); 824 lastName = find( Qtopia::LastName );
820 firstName = find( Qtopia::FirstName ); 825 firstName = find( Qtopia::FirstName );
821 middleName = find( Qtopia::MiddleName ); 826 middleName = find( Qtopia::MiddleName );
822 if ( !lastName.isEmpty() && !firstName.isEmpty() 827 if ( !lastName.isEmpty() && !firstName.isEmpty()
823 && !middleName.isEmpty() ) 828 && !middleName.isEmpty() )
824 fileas = lastName + ", " + firstName + " " + middleName; 829 fileas = lastName + ", " + firstName + " " + middleName;
825 else if ( !lastName.isEmpty() && !firstName.isEmpty() ) 830 else if ( !lastName.isEmpty() && !firstName.isEmpty() )
826 fileas = lastName + ", " + firstName; 831 fileas = lastName + ", " + firstName;
827 else if ( !lastName.isEmpty() || !firstName.isEmpty() || 832 else if ( !lastName.isEmpty() || !firstName.isEmpty() ||
828 !middleName.isEmpty() ) 833 !middleName.isEmpty() )
829 fileas = firstName + ( firstName.isEmpty() ? "" : " " ) 834 fileas = firstName + ( firstName.isEmpty() ? "" : " " )
830 + middleName + ( middleName.isEmpty() ? "" : " " ) 835 + middleName + ( middleName.isEmpty() ? "" : " " )
831 + lastName; 836 + lastName;
832 837
833 replace( Qtopia::FileAs, fileas ); 838 replace( Qtopia::FileAs, fileas );
834} 839}
835 840
836/*! 841/*!
837 \internal 842 \internal
838 Appends the contact information to \a buf. 843 Appends the contact information to \a buf.
839*/ 844*/
840void OContact::save( QString &buf ) const 845void OContact::save( QString &buf ) const
841{ 846{
842 static const QStringList SLFIELDS = fields(); 847 static const QStringList SLFIELDS = fields();
843 // I'm expecting "<Contact " in front of this... 848 // I'm expecting "<Contact " in front of this...
844 for ( QMap<int, QString>::ConstIterator it = mMap.begin(); 849 for ( QMap<int, QString>::ConstIterator it = mMap.begin();
845 it != mMap.end(); ++it ) { 850 it != mMap.end(); ++it ) {
846 const QString &value = it.data(); 851 const QString &value = it.data();
847 int key = it.key(); 852 int key = it.key();
848 if ( !value.isEmpty() ) { 853 if ( !value.isEmpty() ) {
849 if ( key == Qtopia::AddressCategory || key == Qtopia::AddressUid) 854 if ( key == Qtopia::AddressCategory || key == Qtopia::AddressUid)
850 continue; 855 continue;
851 856
852 key -= Qtopia::AddressCategory+1; 857 key -= Qtopia::AddressCategory+1;
853 buf += SLFIELDS[key]; 858 buf += SLFIELDS[key];
854 buf += "=\"" + Qtopia::escapeString(value) + "\" "; 859 buf += "=\"" + Qtopia::escapeString(value) + "\" ";
855 } 860 }
856 } 861 }
857 buf += customToXml(); 862 buf += customToXml();
858 if ( categories().count() > 0 ) 863 if ( categories().count() > 0 )
859 buf += "Categories=\"" + idsToString( categories() ) + "\" "; 864 buf += "Categories=\"" + idsToString( categories() ) + "\" ";
860 buf += "Uid=\"" + QString::number( uid() ) + "\" "; 865 buf += "Uid=\"" + QString::number( uid() ) + "\" ";
861 // You need to close this yourself 866 // You need to close this yourself
862} 867}
863 868
864 869
865/*! 870/*!
866 \internal 871 \internal
867 Returns the list of fields belonging to a contact 872 Returns the list of fields belonging to a contact
868 Never change order of this list ! It has to be regarding 873 Never change order of this list ! It has to be regarding
869 enum AddressBookFields !! 874 enum AddressBookFields !!
870*/ 875*/
871QStringList OContact::fields() 876QStringList OContact::fields()
872{ 877{
873 QStringList list; 878 QStringList list;
874 879
875 list.append( "Title" ); // Not Used! 880 list.append( "Title" ); // Not Used!
876 list.append( "FirstName" ); 881 list.append( "FirstName" );
877 list.append( "MiddleName" ); 882 list.append( "MiddleName" );
878 list.append( "LastName" ); 883 list.append( "LastName" );
879 list.append( "Suffix" ); 884 list.append( "Suffix" );
880 list.append( "FileAs" ); 885 list.append( "FileAs" );
881 886
882 list.append( "JobTitle" ); 887 list.append( "JobTitle" );
883 list.append( "Department" ); 888 list.append( "Department" );
884 list.append( "Company" ); 889 list.append( "Company" );
885 list.append( "BusinessPhone" ); 890 list.append( "BusinessPhone" );
886 list.append( "BusinessFax" ); 891 list.append( "BusinessFax" );
887 list.append( "BusinessMobile" ); 892 list.append( "BusinessMobile" );
888 893
889 list.append( "DefaultEmail" ); 894 list.append( "DefaultEmail" );
890 list.append( "Emails" ); 895 list.append( "Emails" );
891 896
892 list.append( "HomePhone" ); 897 list.append( "HomePhone" );
893 list.append( "HomeFax" ); 898 list.append( "HomeFax" );
894 list.append( "HomeMobile" ); 899 list.append( "HomeMobile" );
895 900
896 list.append( "BusinessStreet" ); 901 list.append( "BusinessStreet" );
897 list.append( "BusinessCity" ); 902 list.append( "BusinessCity" );
898 list.append( "BusinessState" ); 903 list.append( "BusinessState" );
899 list.append( "BusinessZip" ); 904 list.append( "BusinessZip" );
900 list.append( "BusinessCountry" ); 905 list.append( "BusinessCountry" );
901 list.append( "BusinessPager" ); 906 list.append( "BusinessPager" );
902 list.append( "BusinessWebPage" ); 907 list.append( "BusinessWebPage" );
903 908
904 list.append( "Office" ); 909 list.append( "Office" );
905 list.append( "Profession" ); 910 list.append( "Profession" );
906 list.append( "Assistant" ); 911 list.append( "Assistant" );
907 list.append( "Manager" ); 912 list.append( "Manager" );
908 913
909 list.append( "HomeStreet" ); 914 list.append( "HomeStreet" );
910 list.append( "HomeCity" ); 915 list.append( "HomeCity" );
911 list.append( "HomeState" ); 916 list.append( "HomeState" );
912 list.append( "HomeZip" ); 917 list.append( "HomeZip" );
913 list.append( "HomeCountry" ); 918 list.append( "HomeCountry" );
914 list.append( "HomeWebPage" ); 919 list.append( "HomeWebPage" );
915 920
916 list.append( "Spouse" ); 921 list.append( "Spouse" );
917 list.append( "Gender" ); 922 list.append( "Gender" );
918 list.append( "Birthday" ); 923 list.append( "Birthday" );
919 list.append( "Anniversary" ); 924 list.append( "Anniversary" );
920 list.append( "Nickname" ); 925 list.append( "Nickname" );
921 list.append( "Children" ); 926 list.append( "Children" );
922 927
923 list.append( "Notes" ); 928 list.append( "Notes" );
924 list.append( "Groups" ); 929 list.append( "Groups" );
925 930
926 return list; 931 return list;
927} 932}
928 933
929 934
930/*! 935/*!
931 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.
932 Email address should be separated by ';'s. 937 Email address should be separated by ';'s.
933*/ 938*/
934void OContact::setEmails( const QString &str ) 939void OContact::setEmails( const QString &str )
935{ 940{
936 replace( Qtopia::Emails, str ); 941 replace( Qtopia::Emails, str );
937 if ( str.isEmpty() ) 942 if ( str.isEmpty() )
938 setDefaultEmail( QString::null ); 943 setDefaultEmail( QString::null );
939} 944}
940 945
941/*! 946/*!
942 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.
943*/ 948*/
944void OContact::setChildren( const QString &str ) 949void OContact::setChildren( const QString &str )
945{ 950{
946 replace( Qtopia::Children, str ); 951 replace( Qtopia::Children, str );
947} 952}
948 953
949/*! 954/*!
950 \overload 955 \overload
951 Returns TRUE if the contact matches the regular expression \a regexp. 956 Returns TRUE if the contact matches the regular expression \a regexp.
952 Otherwise returns FALSE. 957 Otherwise returns FALSE.
953*/ 958*/
954bool OContact::match( const QRegExp &r ) const 959bool OContact::match( const QRegExp &r ) const
955{ 960{
956 setLastHitField( -1 ); 961 setLastHitField( -1 );
957 bool match; 962 bool match;
958 match = false; 963 match = false;
959 QMap<int, QString>::ConstIterator it; 964 QMap<int, QString>::ConstIterator it;
960 for ( it = mMap.begin(); it != mMap.end(); ++it ) { 965 for ( it = mMap.begin(); it != mMap.end(); ++it ) {
961 if ( (*it).find( r ) > -1 ) { 966 if ( (*it).find( r ) > -1 ) {
962 setLastHitField( it.key() ); 967 setLastHitField( it.key() );
963 match = true; 968 match = true;
964 break; 969 break;
965 } 970 }
966 } 971 }
967 return match; 972 return match;
968} 973}
969 974
970 975
971QString OContact::toShortText() const 976QString OContact::toShortText() const
972{ 977{
973 return ( fullName() ); 978 return ( fullName() );
974} 979}
975QString OContact::type() const 980QString OContact::type() const
976{ 981{
977 return QString::fromLatin1( "OContact" ); 982 return QString::fromLatin1( "OContact" );
978} 983}
979 984
980// Definition is missing ! (se) 985// Definition is missing ! (se)
981QMap<QString,QString> OContact::toExtraMap() const 986QMap<QString,QString> OContact::toExtraMap() const
982{ 987{
983 qWarning ("Function not implemented: OContact::toExtraMap()"); 988 qWarning ("Function not implemented: OContact::toExtraMap()");
984 QMap <QString,QString> useless; 989 QMap <QString,QString> useless;
985 return useless; 990 return useless;
986} 991}
987 992
988class QString OContact::recordField( int pos ) const 993class QString OContact::recordField( int pos ) const
989{ 994{
990 QStringList SLFIELDS = fields(); // ?? why this ? (se) 995 QStringList SLFIELDS = fields(); // ?? why this ? (se)
991 return SLFIELDS[pos]; 996 return SLFIELDS[pos];
992} 997}
993 998
994// In future releases, we should store birthday and anniversary 999// In future releases, we should store birthday and anniversary
995// internally as QDate instead of QString ! 1000// internally as QDate instead of QString !
996// QString is always too complicate to interprete (DD.MM.YY, DD/MM/YY, MM/DD/YY, etc..)(se) 1001// QString is always too complicate to interprete (DD.MM.YY, DD/MM/YY, MM/DD/YY, etc..)(se)
997 1002
998/*! \fn void OContact::setBirthday( const QDate& date ) 1003/*! \fn void OContact::setBirthday( const QDate& date )
999 Sets the birthday for the contact to \a date. If date is null 1004 Sets the birthday for the contact to \a date. If date is null
1000 the current stored date will be removed. 1005 the current stored date will be removed.
1001*/ 1006*/
1002void OContact::setBirthday( const QDate &v ) 1007void OContact::setBirthday( const QDate &v )
1003{ 1008{
1004 if ( v.isNull() ){ 1009 if ( v.isNull() ){
1005 qWarning( "Remove Birthday"); 1010 qWarning( "Remove Birthday");
1006 replace( Qtopia::Birthday, QString::null ); 1011 replace( Qtopia::Birthday, QString::null );
1007 return; 1012 return;
1008 } 1013 }
1009 1014
1010 if ( v.isValid() ) 1015 if ( v.isValid() )
1011 replace( Qtopia::Birthday, OConversion::dateToString( v ) ); 1016 replace( Qtopia::Birthday, OConversion::dateToString( v ) );
1012 1017
1013} 1018}
1014 1019
1015 1020
1016/*! \fn void OContact::setAnniversary( const QDate &date ) 1021/*! \fn void OContact::setAnniversary( const QDate &date )
1017 Sets the anniversary of the contact to \a date. If date is 1022 Sets the anniversary of the contact to \a date. If date is
1018 null, the current stored date will be removed. 1023 null, the current stored date will be removed.
1019*/ 1024*/
1020void OContact::setAnniversary( const QDate &v ) 1025void OContact::setAnniversary( const QDate &v )
1021{ 1026{
1022 if ( v.isNull() ){ 1027 if ( v.isNull() ){
1023 qWarning( "Remove Anniversary"); 1028 qWarning( "Remove Anniversary");
1024 replace( Qtopia::Anniversary, QString::null ); 1029 replace( Qtopia::Anniversary, QString::null );
1025 return; 1030 return;
1026 } 1031 }
1027 1032
1028 if ( v.isValid() ) 1033 if ( v.isValid() )
1029 replace( Qtopia::Anniversary, OConversion::dateToString( v ) ); 1034 replace( Qtopia::Anniversary, OConversion::dateToString( v ) );
1030} 1035}
1031 1036
1032/*! \fn QDate OContact::birthday() const 1037/*! \fn QDate OContact::birthday() const
1033 Returns the birthday of the contact. 1038 Returns the birthday of the contact.
1034*/ 1039*/
1035QDate OContact::birthday() const 1040QDate OContact::birthday() const
1036{ 1041{
1037 QString str = find( Qtopia::Birthday ); 1042 QString str = find( Qtopia::Birthday );
1038 qWarning ("Birthday %s", str.latin1() ); 1043 qWarning ("Birthday %s", str.latin1() );
1039 if ( !str.isEmpty() ) 1044 if ( !str.isEmpty() )
1040 return OConversion::dateFromString ( str ); 1045 return OConversion::dateFromString ( str );
1041 else 1046 else
1042 return QDate(); 1047 return QDate();
1043} 1048}
1044 1049
1045 1050
1046/*! \fn QDate OContact::anniversary() const 1051/*! \fn QDate OContact::anniversary() const
1047 Returns the anniversary of the contact. 1052 Returns the anniversary of the contact.
1048*/ 1053*/
1049QDate OContact::anniversary() const 1054QDate OContact::anniversary() const
1050{ 1055{
1051 QDate empty; 1056 QDate empty;
1052 QString str = find( Qtopia::Anniversary ); 1057 QString str = find( Qtopia::Anniversary );
1053 qWarning ("Anniversary %s", str.latin1() ); 1058 qWarning ("Anniversary %s", str.latin1() );
1054 if ( !str.isEmpty() ) 1059 if ( !str.isEmpty() )
1055 return OConversion::dateFromString ( str ); 1060 return OConversion::dateFromString ( str );
1056 else 1061 else
1057 return empty; 1062 return empty;
1058} 1063}
1059 1064
1060 1065
1061void OContact::insertEmail( const QString &v ) 1066void OContact::insertEmail( const QString &v )
1062{ 1067{
1063 //qDebug("insertEmail %s", v.latin1()); 1068 //qDebug("insertEmail %s", v.latin1());
1064 QString e = v.simplifyWhiteSpace(); 1069 QString e = v.simplifyWhiteSpace();
1065 QString def = defaultEmail(); 1070 QString def = defaultEmail();
1066 1071
1067 // if no default, set it as the default email and don't insert 1072 // if no default, set it as the default email and don't insert
1068 if ( def.isEmpty() ) { 1073 if ( def.isEmpty() ) {
1069 setDefaultEmail( e ); // will insert into the list for us 1074 setDefaultEmail( e ); // will insert into the list for us
1070 return; 1075 return;
1071 } 1076 }
1072 1077
1073 // otherwise, insert assuming doesn't already exist 1078 // otherwise, insert assuming doesn't already exist
1074 QString emailsStr = find( Qtopia::Emails ); 1079 QString emailsStr = find( Qtopia::Emails );
1075 if ( emailsStr.contains( e )) 1080 if ( emailsStr.contains( e ))
1076 return; 1081 return;
1077 if ( !emailsStr.isEmpty() ) 1082 if ( !emailsStr.isEmpty() )
1078 emailsStr += emailSeparator(); 1083 emailsStr += emailSeparator();
1079 emailsStr += e; 1084 emailsStr += e;
1080 replace( Qtopia::Emails, emailsStr ); 1085 replace( Qtopia::Emails, emailsStr );
1081} 1086}
1082 1087
1083void OContact::removeEmail( const QString &v ) 1088void OContact::removeEmail( const QString &v )
1084{ 1089{
1085 QString e = v.simplifyWhiteSpace(); 1090 QString e = v.simplifyWhiteSpace();
1086 QString def = defaultEmail(); 1091 QString def = defaultEmail();
1087 QString emailsStr = find( Qtopia::Emails ); 1092 QString emailsStr = find( Qtopia::Emails );
1088 QStringList emails = emailList(); 1093 QStringList emails = emailList();
1089 1094
1090 // otherwise, must first contain it 1095 // otherwise, must first contain it
1091 if ( !emailsStr.contains( e ) ) 1096 if ( !emailsStr.contains( e ) )
1092 return; 1097 return;
1093 1098
1094 // remove it 1099 // remove it
1095 //qDebug(" removing email from list %s", e.latin1()); 1100 //qDebug(" removing email from list %s", e.latin1());
1096 emails.remove( e ); 1101 emails.remove( e );
1097 // reset the string 1102 // reset the string
1098 emailsStr = emails.join(emailSeparator()); // Sharp's brain dead separator 1103 emailsStr = emails.join(emailSeparator()); // Sharp's brain dead separator
1099 replace( Qtopia::Emails, emailsStr ); 1104 replace( Qtopia::Emails, emailsStr );
1100 1105
1101 // if default, then replace the default email with the first one 1106 // if default, then replace the default email with the first one
1102 if ( def == e ) { 1107 if ( def == e ) {
1103 //qDebug("removeEmail is default; setting new default"); 1108 //qDebug("removeEmail is default; setting new default");
1104 if ( !emails.count() ) 1109 if ( !emails.count() )
1105 clearEmails(); 1110 clearEmails();
1106 else // setDefaultEmail will remove e from the list 1111 else // setDefaultEmail will remove e from the list
1107 setDefaultEmail( emails.first() ); 1112 setDefaultEmail( emails.first() );
1108 } 1113 }
1109} 1114}
1110void OContact::clearEmails() 1115void OContact::clearEmails()
1111{ 1116{
1112 mMap.remove( Qtopia::DefaultEmail ); 1117 mMap.remove( Qtopia::DefaultEmail );
1113 mMap.remove( Qtopia::Emails ); 1118 mMap.remove( Qtopia::Emails );
1114} 1119}
1115void OContact::setDefaultEmail( const QString &v ) 1120void OContact::setDefaultEmail( const QString &v )
1116{ 1121{
1117 QString e = v.simplifyWhiteSpace(); 1122 QString e = v.simplifyWhiteSpace();
1118 1123
1119 //qDebug("OContact::setDefaultEmail %s", e.latin1()); 1124 //qDebug("OContact::setDefaultEmail %s", e.latin1());
1120 replace( Qtopia::DefaultEmail, e ); 1125 replace( Qtopia::DefaultEmail, e );
1121 1126
1122 if ( !e.isEmpty() ) 1127 if ( !e.isEmpty() )
1123 insertEmail( e ); 1128 insertEmail( e );
1124 1129
1125} 1130}
1126 1131
1127void OContact::insertEmails( const QStringList &v ) 1132void OContact::insertEmails( const QStringList &v )
1128{ 1133{
1129 for ( QStringList::ConstIterator it = v.begin(); it != v.end(); ++it ) 1134 for ( QStringList::ConstIterator it = v.begin(); it != v.end(); ++it )
1130 insertEmail( *it ); 1135 insertEmail( *it );
1131} 1136}
1132int OContact::rtti() { 1137int OContact::rtti() {
1133 return OPimResolver::AddressBook; 1138 return OPimResolver::AddressBook;
1134} 1139}
1135void OContact::setUid( int i ) 1140void OContact::setUid( int i )
1136{ 1141{
1137 OPimRecord::setUid(i); 1142 OPimRecord::setUid(i);
1138 replace( Qtopia::AddressUid , QString::number(i)); 1143 replace( Qtopia::AddressUid , QString::number(i));
1139} 1144}
diff --git a/libopie2/opiepim/oevent.cpp b/libopie2/opiepim/oevent.cpp
index 83b191f..e4f5d92 100644
--- a/libopie2/opiepim/oevent.cpp
+++ b/libopie2/opiepim/oevent.cpp
@@ -1,548 +1,580 @@
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; 238 QString text, value;
239
240 // description
241 text += "<b><h3><img src=\"datebook/DateBook\">";
239 if ( !description().isEmpty() ) { 242 if ( !description().isEmpty() ) {
240 text += "<b>" + QObject::tr( "Description:") + "</b><br>"; 243 text += Qtopia::escapeString(description() ).replace(QRegExp( "[\n]"), "" );
241 text += Qtopia::escapeString(description() ). 244 }
242 replace(QRegExp( "[\n]"), "<br>" ) + "<br>"; 245 text += "</h3></b><br><hr><br>";
246
247 // location
248 if ( !(value = location()).isEmpty() ) {
249 text += "<b>" + QObject::tr( "Location:" ) + "</b> ";
250 text += Qtopia::escapeString(value) + "<br>";
251 }
252
253 // all day event
254 if ( isAllDay() ) {
255 text += "<b><i>" + QObject::tr( "This is an all day event" ) + "</i></b><br>";
243 } 256 }
244 if ( startDateTime().isValid() ) { 257 // multiple day event
245 text += "<b>" + QObject::tr( "Start:") + "</b> "; 258 else if ( isMultipleDay () ) {
246 text += Qtopia::escapeString(startDateTime().toString() ). 259 text += "<b><i>" + QObject::tr( "This is a multiple day event" ) + "</i></b><br>";
247 replace(QRegExp( "[\n]"), "<br>" ) + "<br>"; 260 }
261 // start & end times
262 else {
263 // start time
264 if ( startDateTime().isValid() ) {
265 text += "<b>" + QObject::tr( "Start:") + "</b> ";
266 text += Qtopia::escapeString(startDateTime().toString() ).
267 replace(QRegExp( "[\n]"), "<br>" ) + "<br>";
268 }
269
270 // end time
271 if ( endDateTime().isValid() ) {
272 text += "<b>" + QObject::tr( "End:") + "</b> ";
273 text += Qtopia::escapeString(endDateTime().toString() ).
274 replace(QRegExp( "[\n]"), "<br>" ) + "<br>";
275 }
248 } 276 }
249 if ( endDateTime().isValid() ) { 277
250 text += "<b>" + QObject::tr( "End:") + "</b> "; 278 // categories
251 text += Qtopia::escapeString(endDateTime().toString() ). 279 if ( categoryNames("Calendar").count() ){
252 replace(QRegExp( "[\n]"), "<br>" ) + "<br>"; 280 text += "<b>" + QObject::tr( "Category:") + "</b> ";
281 text += categoryNames("Calendar").join(", ");
282 text += "<br>";
253 } 283 }
284
285 //notes
254 if ( !note().isEmpty() ) { 286 if ( !note().isEmpty() ) {
255 text += "<b>" + QObject::tr( "Note:") + "</b><br>"; 287 text += "<b>" + QObject::tr( "Note:") + "</b><br>";
256 text += note(); 288 text += note();
257// text += Qtopia::escapeString(note() ). 289// text += Qtopia::escapeString(note() ).
258// replace(QRegExp( "[\n]"), "<br>" ) + "<br>"; 290// replace(QRegExp( "[\n]"), "<br>" ) + "<br>";
259 } 291 }
260 return text; 292 return text;
261} 293}
262QString OEvent::toShortText()const { 294QString OEvent::toShortText()const {
263 QString text; 295 QString text;
264 text += QString::number( startDateTime().date().day() ); 296 text += QString::number( startDateTime().date().day() );
265 text += "."; 297 text += ".";
266 text += QString::number( startDateTime().date().month() ); 298 text += QString::number( startDateTime().date().month() );
267 text += "."; 299 text += ".";
268 text += QString::number( startDateTime().date().year() ); 300 text += QString::number( startDateTime().date().year() );
269 text += " "; 301 text += " ";
270 text += QString::number( startDateTime().time().hour() ); 302 text += QString::number( startDateTime().time().hour() );
271 text += ":"; 303 text += ":";
272 text += QString::number( startDateTime().time().minute() ); 304 text += QString::number( startDateTime().time().minute() );
273 text += " - "; 305 text += " - ";
274 text += description(); 306 text += description();
275 return text; 307 return text;
276} 308}
277QString OEvent::type()const { 309QString OEvent::type()const {
278 return QString::fromLatin1("OEvent"); 310 return QString::fromLatin1("OEvent");
279} 311}
280QString OEvent::recordField( int /*id */ )const { 312QString OEvent::recordField( int /*id */ )const {
281 return QString::null; 313 return QString::null;
282} 314}
283int OEvent::rtti() { 315int OEvent::rtti() {
284 return OPimResolver::DateBook; 316 return OPimResolver::DateBook;
285} 317}
286bool OEvent::loadFromStream( QDataStream& ) { 318bool OEvent::loadFromStream( QDataStream& ) {
287 return true; 319 return true;
288} 320}
289bool OEvent::saveToStream( QDataStream& )const { 321bool OEvent::saveToStream( QDataStream& )const {
290 return true; 322 return true;
291} 323}
292void OEvent::changeOrModify() { 324void OEvent::changeOrModify() {
293 if ( data->count != 1 ) { 325 if ( data->count != 1 ) {
294 data->deref(); 326 data->deref();
295 Data* d2 = new Data; 327 Data* d2 = new Data;
296 d2->description = data->description; 328 d2->description = data->description;
297 d2->location = data->location; 329 d2->location = data->location;
298 330
299 if (data->manager ) 331 if (data->manager )
300 d2->manager = new OPimNotifyManager( *data->manager ); 332 d2->manager = new OPimNotifyManager( *data->manager );
301 333
302 if ( data->recur ) 334 if ( data->recur )
303 d2->recur = new ORecur( *data->recur ); 335 d2->recur = new ORecur( *data->recur );
304 336
305 d2->note = data->note; 337 d2->note = data->note;
306 d2->created = data->created; 338 d2->created = data->created;
307 d2->start = data->start; 339 d2->start = data->start;
308 d2->end = data->end; 340 d2->end = data->end;
309 d2->isAllDay = data->isAllDay; 341 d2->isAllDay = data->isAllDay;
310 d2->timezone = data->timezone; 342 d2->timezone = data->timezone;
311 d2->parent = data->parent; 343 d2->parent = data->parent;
312 344
313 if ( data->child ) { 345 if ( data->child ) {
314 d2->child = new QArray<int>( *data->child ); 346 d2->child = new QArray<int>( *data->child );
315 d2->child->detach(); 347 d2->child->detach();
316 } 348 }
317 349
318 data = d2; 350 data = d2;
319 } 351 }
320} 352}
321void OEvent::deref() { 353void OEvent::deref() {
322 if ( data->deref() ) { 354 if ( data->deref() ) {
323 delete data; 355 delete data;
324 data = 0; 356 data = 0;
325 } 357 }
326} 358}
327// FIXME 359// FIXME
328QMap<int, QString> OEvent::toMap()const { 360QMap<int, QString> OEvent::toMap()const {
329 return QMap<int, QString>(); 361 return QMap<int, QString>();
330} 362}
331QMap<QString, QString> OEvent::toExtraMap()const { 363QMap<QString, QString> OEvent::toExtraMap()const {
332 return QMap<QString, QString>(); 364 return QMap<QString, QString>();
333} 365}
334int OEvent::parent()const { 366int OEvent::parent()const {
335 return data->parent; 367 return data->parent;
336} 368}
337void OEvent::setParent( int uid ) { 369void OEvent::setParent( int uid ) {
338 changeOrModify(); 370 changeOrModify();
339 data->parent = uid; 371 data->parent = uid;
340} 372}
341QArray<int> OEvent::children() const{ 373QArray<int> OEvent::children() const{
342 if (!data->child) return QArray<int>(); 374 if (!data->child) return QArray<int>();
343 else 375 else
344 return data->child->copy(); 376 return data->child->copy();
345} 377}
346void OEvent::setChildren( const QArray<int>& arr ) { 378void OEvent::setChildren( const QArray<int>& arr ) {
347 changeOrModify(); 379 changeOrModify();
348 if (data->child) delete data->child; 380 if (data->child) delete data->child;
349 381
350 data->child = new QArray<int>( arr ); 382 data->child = new QArray<int>( arr );
351 data->child->detach(); 383 data->child->detach();
352} 384}
353void OEvent::addChild( int uid ) { 385void OEvent::addChild( int uid ) {
354 changeOrModify(); 386 changeOrModify();
355 if (!data->child ) { 387 if (!data->child ) {
356 data->child = new QArray<int>(1); 388 data->child = new QArray<int>(1);
357 (*data->child)[0] = uid; 389 (*data->child)[0] = uid;
358 }else{ 390 }else{
359 int count = data->child->count(); 391 int count = data->child->count();
360 data->child->resize( count + 1 ); 392 data->child->resize( count + 1 );
361 (*data->child)[count] = uid; 393 (*data->child)[count] = uid;
362 } 394 }
363} 395}
364void OEvent::removeChild( int uid ) { 396void OEvent::removeChild( int uid ) {
365 if (!data->child || !data->child->contains( uid ) ) return; 397 if (!data->child || !data->child->contains( uid ) ) return;
366 changeOrModify(); 398 changeOrModify();
367 QArray<int> newAr( data->child->count() - 1 ); 399 QArray<int> newAr( data->child->count() - 1 );
368 int j = 0; 400 int j = 0;
369 uint count = data->child->count(); 401 uint count = data->child->count();
370 for ( uint i = 0; i < count; i++ ) { 402 for ( uint i = 0; i < count; i++ ) {
371 if ( (*data->child)[i] != uid ) { 403 if ( (*data->child)[i] != uid ) {
372 newAr[j] = (*data->child)[i]; 404 newAr[j] = (*data->child)[i];
373 j++; 405 j++;
374 } 406 }
375 } 407 }
376 (*data->child) = newAr; 408 (*data->child) = newAr;
377} 409}
378struct OEffectiveEvent::Data : public QShared { 410struct OEffectiveEvent::Data : public QShared {
379 Data() : QShared() { 411 Data() : QShared() {
380 } 412 }
381 OEvent event; 413 OEvent event;
382 QDate date; 414 QDate date;
383 QTime start, end; 415 QTime start, end;
384 QDate startDate, endDate; 416 QDate startDate, endDate;
385 bool dates : 1; 417 bool dates : 1;
386}; 418};
387 419
388OEffectiveEvent::OEffectiveEvent() { 420OEffectiveEvent::OEffectiveEvent() {
389 data = new Data; 421 data = new Data;
390 data->date = QDate::currentDate(); 422 data->date = QDate::currentDate();
391 data->start = data->end = QTime::currentTime(); 423 data->start = data->end = QTime::currentTime();
392 data->dates = false; 424 data->dates = false;
393} 425}
394OEffectiveEvent::OEffectiveEvent( const OEvent& ev, const QDate& startDate, 426OEffectiveEvent::OEffectiveEvent( const OEvent& ev, const QDate& startDate,
395 Position pos ) { 427 Position pos ) {
396 data = new Data; 428 data = new Data;
397 data->event = ev; 429 data->event = ev;
398 data->date = startDate; 430 data->date = startDate;
399 if ( pos & Start ) 431 if ( pos & Start )
400 data->start = ev.startDateTime().time(); 432 data->start = ev.startDateTime().time();
401 else 433 else
402 data->start = QTime( 0, 0, 0 ); 434 data->start = QTime( 0, 0, 0 );
403 435
404 if ( pos & End ) 436 if ( pos & End )
405 data->end = ev.endDateTime().time(); 437 data->end = ev.endDateTime().time();
406 else 438 else
407 data->end = QTime( 23, 59, 59 ); 439 data->end = QTime( 23, 59, 59 );
408 440
409 data->dates = false; 441 data->dates = false;
410} 442}
411OEffectiveEvent::OEffectiveEvent( const OEffectiveEvent& ev) { 443OEffectiveEvent::OEffectiveEvent( const OEffectiveEvent& ev) {
412 data = ev.data; 444 data = ev.data;
413 data->ref(); 445 data->ref();
414} 446}
415OEffectiveEvent::~OEffectiveEvent() { 447OEffectiveEvent::~OEffectiveEvent() {
416 if ( data->deref() ) { 448 if ( data->deref() ) {
417 delete data; 449 delete data;
418 data = 0; 450 data = 0;
419 } 451 }
420} 452}
421OEffectiveEvent& OEffectiveEvent::operator=( const OEffectiveEvent& ev ) { 453OEffectiveEvent& OEffectiveEvent::operator=( const OEffectiveEvent& ev ) {
422 if ( *this == ev ) return *this; 454 if ( *this == ev ) return *this;
423 455
424 ev.data->ref(); 456 ev.data->ref();
425 deref(); 457 deref();
426 data = ev.data; 458 data = ev.data;
427 459
428 return *this; 460 return *this;
429} 461}
430 462
431void OEffectiveEvent::setStartTime( const QTime& ti) { 463void OEffectiveEvent::setStartTime( const QTime& ti) {
432 changeOrModify(); 464 changeOrModify();
433 data->start = ti; 465 data->start = ti;
434} 466}
435void OEffectiveEvent::setEndTime( const QTime& en) { 467void OEffectiveEvent::setEndTime( const QTime& en) {
436 changeOrModify(); 468 changeOrModify();
437 data->end = en; 469 data->end = en;
438} 470}
439void OEffectiveEvent::setEvent( const OEvent& ev) { 471void OEffectiveEvent::setEvent( const OEvent& ev) {
440 changeOrModify(); 472 changeOrModify();
441 data->event = ev; 473 data->event = ev;
442} 474}
443void OEffectiveEvent::setDate( const QDate& da) { 475void OEffectiveEvent::setDate( const QDate& da) {
444 changeOrModify(); 476 changeOrModify();
445 data->date = da; 477 data->date = da;
446} 478}
447void OEffectiveEvent::setEffectiveDates( const QDate& from, 479void OEffectiveEvent::setEffectiveDates( const QDate& from,
448 const QDate& to ) { 480 const QDate& to ) {
449 if (!from.isValid() ) { 481 if (!from.isValid() ) {
450 data->dates = false; 482 data->dates = false;
451 return; 483 return;
452 } 484 }
453 485
454 data->startDate = from; 486 data->startDate = from;
455 data->endDate = to; 487 data->endDate = to;
456} 488}
457QString OEffectiveEvent::description()const { 489QString OEffectiveEvent::description()const {
458 return data->event.description(); 490 return data->event.description();
459} 491}
460QString OEffectiveEvent::location()const { 492QString OEffectiveEvent::location()const {
461 return data->event.location(); 493 return data->event.location();
462} 494}
463QString OEffectiveEvent::note()const { 495QString OEffectiveEvent::note()const {
464 return data->event.note(); 496 return data->event.note();
465} 497}
466OEvent OEffectiveEvent::event()const { 498OEvent OEffectiveEvent::event()const {
467 return data->event; 499 return data->event;
468} 500}
469QTime OEffectiveEvent::startTime()const { 501QTime OEffectiveEvent::startTime()const {
470 return data->start; 502 return data->start;
471} 503}
472QTime OEffectiveEvent::endTime()const { 504QTime OEffectiveEvent::endTime()const {
473 return data->end; 505 return data->end;
474} 506}
475QDate OEffectiveEvent::date()const { 507QDate OEffectiveEvent::date()const {
476 return data->date; 508 return data->date;
477} 509}
478int OEffectiveEvent::length()const { 510int OEffectiveEvent::length()const {
479 return (data->end.hour() * 60 - data->start.hour() * 60) 511 return (data->end.hour() * 60 - data->start.hour() * 60)
480 + QABS(data->start.minute() - data->end.minute() ); 512 + QABS(data->start.minute() - data->end.minute() );
481} 513}
482int OEffectiveEvent::size()const { 514int OEffectiveEvent::size()const {
483 return ( data->end.hour() - data->start.hour() ) * 3600 515 return ( data->end.hour() - data->start.hour() ) * 3600
484 + (data->end.minute() - data->start.minute() * 60 516 + (data->end.minute() - data->start.minute() * 60
485 + data->end.second() - data->start.second() ); 517 + data->end.second() - data->start.second() );
486} 518}
487QDate OEffectiveEvent::startDate()const { 519QDate OEffectiveEvent::startDate()const {
488 if ( data->dates ) 520 if ( data->dates )
489 return data->startDate; 521 return data->startDate;
490 else if ( data->event.hasRecurrence() ) // single day, since multi-day should have a d pointer 522 else if ( data->event.hasRecurrence() ) // single day, since multi-day should have a d pointer
491 return data->date; 523 return data->date;
492 else 524 else
493 return data->event.startDateTime().date(); 525 return data->event.startDateTime().date();
494} 526}
495QDate OEffectiveEvent::endDate()const { 527QDate OEffectiveEvent::endDate()const {
496 if ( data->dates ) 528 if ( data->dates )
497 return data->endDate; 529 return data->endDate;
498 else if ( data->event.hasRecurrence() ) 530 else if ( data->event.hasRecurrence() )
499 return data->date; 531 return data->date;
500 else 532 else
501 return data->event.endDateTime().date(); 533 return data->event.endDateTime().date();
502} 534}
503void OEffectiveEvent::deref() { 535void OEffectiveEvent::deref() {
504 if ( data->deref() ) { 536 if ( data->deref() ) {
505 delete data; 537 delete data;
506 data = 0; 538 data = 0;
507 } 539 }
508} 540}
509void OEffectiveEvent::changeOrModify() { 541void OEffectiveEvent::changeOrModify() {
510 if ( data->count != 1 ) { 542 if ( data->count != 1 ) {
511 data->deref(); 543 data->deref();
512 Data* d2 = new Data; 544 Data* d2 = new Data;
513 d2->event = data->event; 545 d2->event = data->event;
514 d2->date = data->date; 546 d2->date = data->date;
515 d2->start = data->start; 547 d2->start = data->start;
516 d2->end = data->end; 548 d2->end = data->end;
517 d2->startDate = data->startDate; 549 d2->startDate = data->startDate;
518 d2->endDate = data->endDate; 550 d2->endDate = data->endDate;
519 d2->dates = data->dates; 551 d2->dates = data->dates;
520 data = d2; 552 data = d2;
521 } 553 }
522} 554}
523bool OEffectiveEvent::operator<( const OEffectiveEvent &e ) const{ 555bool OEffectiveEvent::operator<( const OEffectiveEvent &e ) const{
524 if ( data->date < e.date() ) 556 if ( data->date < e.date() )
525 return TRUE; 557 return TRUE;
526 if ( data->date == e.date() ) 558 if ( data->date == e.date() )
527 return ( startTime() < e.startTime() ); 559 return ( startTime() < e.startTime() );
528 else 560 else
529 return FALSE; 561 return FALSE;
530} 562}
531bool OEffectiveEvent::operator<=( const OEffectiveEvent &e ) const{ 563bool OEffectiveEvent::operator<=( const OEffectiveEvent &e ) const{
532 return (data->date <= e.date() ); 564 return (data->date <= e.date() );
533} 565}
534bool OEffectiveEvent::operator==( const OEffectiveEvent &e ) const { 566bool OEffectiveEvent::operator==( const OEffectiveEvent &e ) const {
535 return ( date() == e.date() 567 return ( date() == e.date()
536 && startTime() == e.startTime() 568 && startTime() == e.startTime()
537 && endTime()== e.endTime() 569 && endTime()== e.endTime()
538 && event() == e.event() ); 570 && event() == e.event() );
539} 571}
540bool OEffectiveEvent::operator!=( const OEffectiveEvent &e ) const { 572bool OEffectiveEvent::operator!=( const OEffectiveEvent &e ) const {
541 return !(*this == e ); 573 return !(*this == e );
542} 574}
543bool OEffectiveEvent::operator>( const OEffectiveEvent &e ) const { 575bool OEffectiveEvent::operator>( const OEffectiveEvent &e ) const {
544 return !(*this <= e ); 576 return !(*this <= e );
545} 577}
546bool OEffectiveEvent::operator>= ( const OEffectiveEvent &e ) const { 578bool OEffectiveEvent::operator>= ( const OEffectiveEvent &e ) const {
547 return !(*this < e); 579 return !(*this < e);
548} 580}
diff --git a/libopie2/opiepim/otodo.cpp b/libopie2/opiepim/otodo.cpp
index e087a00..c84eeeb 100644
--- a/libopie2/opiepim/otodo.cpp
+++ b/libopie2/opiepim/otodo.cpp
@@ -1,485 +1,519 @@
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 // Description of the todo 276 // summary
277 text += "<b><h3><img src=\"todo/TodoList\">";
277 if ( !summary().isEmpty() ) { 278 if ( !summary().isEmpty() ) {
278 text += "<b>" + QObject::tr( "Summary:") + "</b><br>"; 279 text += Qtopia::escapeString(summary() ).replace(QRegExp( "[\n]"), "" );
279 text += Qtopia::escapeString(summary() ).replace(QRegExp( "[\n]"), "<br>" ) + "<br>";
280 } 280 }
281 text += "</h3></b><br><hr><br>";
282
283 // description
281 if( !description().isEmpty() ){ 284 if( !description().isEmpty() ){
282 text += "<b>" + QObject::tr( "Description:" ) + "</b><br>"; 285 text += "<b>" + QObject::tr( "Description:" ) + "</b><br>";
283 text += Qtopia::escapeString(description() ).replace(QRegExp( "[\n]"), "<br>" ) ; 286 text += Qtopia::escapeString(description() ).replace(QRegExp( "[\n]"), "<br>" ) ;
284 } 287 }
285 text += "<br><br><br>";
286 288
287 text += "<b>" + QObject::tr( "Priority:") +" </b>" 289 // priority
288 + QString::number( priority() ) + " <br>"; 290 int priorityval = priority();
291 text += "<b>" + QObject::tr( "Priority:") +" </b><img src=\"todo/priority" +
292 QString::number( priorityval ) + "\">";
293// text += "<b>" + QObject::tr( "Priority:") +"</b><img src=\"todo/priority" +
294// QString::number( priority() ) + "\"><br>";
295 switch ( priorityval )
296 {
297 case 1 : text += QObject::tr( "Very high" );
298 break;
299 case 2 : text += QObject::tr( "High" );
300 break;
301 case 3 : text += QObject::tr( "Normal" );
302 break;
303 case 4 : text += QObject::tr( "Low" );
304 break;
305 case 5 : text += QObject::tr( "Very low" );
306 break;
307 };
308 text += "<br>";
309
310 // progress
289 text += "<b>" + QObject::tr( "Progress:") + " </b>" 311 text += "<b>" + QObject::tr( "Progress:") + " </b>"
290 + QString::number( progress() ) + " %<br>"; 312 + QString::number( progress() ) + " %<br>";
313
314 // due date
291 if (hasDueDate() ){ 315 if (hasDueDate() ){
292 text += "<b>" + QObject::tr( "Deadline:") + " </b>"; 316 QDate dd = dueDate();
293 text += dueDate().toString(); 317 int off = QDate::currentDate().daysTo( dd );
294 text += "<br>"; 318
319 text += "<b>" + QObject::tr( "Deadline:" ) + " </b><font color=\"";
320 if ( off < 0 )
321 text += "#FF0000";
322 else if ( off == 0 )
323 text += "#FFFF00";
324 else if ( off > 0 )
325 text += "#00FF00";
326
327 text += "\">" + dd.toString() + "</font><br>";
295 } 328 }
296 329
330 // categories
297 text += "<b>" + QObject::tr( "Category:") + "</b> "; 331 text += "<b>" + QObject::tr( "Category:") + "</b> ";
298 text += categoryNames( "Todo List" ).join(", "); 332 text += categoryNames( "Todo List" ).join(", ");
299 text += "<br>"; 333 text += "<br>";
300 334
301 return text; 335 return text;
302} 336}
303bool OTodo::hasNotifiers()const { 337bool OTodo::hasNotifiers()const {
304 if (!data->notifiers) return false; 338 if (!data->notifiers) return false;
305 return !data->notifiers->isEmpty(); 339 return !data->notifiers->isEmpty();
306} 340}
307OPimNotifyManager& OTodo::notifiers() { 341OPimNotifyManager& OTodo::notifiers() {
308 if (!data->notifiers ) 342 if (!data->notifiers )
309 data->notifiers = new OPimNotifyManager; 343 data->notifiers = new OPimNotifyManager;
310 return (*data->notifiers); 344 return (*data->notifiers);
311} 345}
312const OPimNotifyManager& OTodo::notifiers()const{ 346const OPimNotifyManager& OTodo::notifiers()const{
313 if (!data->notifiers ) 347 if (!data->notifiers )
314 data->notifiers = new OPimNotifyManager; 348 data->notifiers = new OPimNotifyManager;
315 349
316 return (*data->notifiers); 350 return (*data->notifiers);
317} 351}
318 352
319bool OTodo::operator<( const OTodo &toDoEvent )const{ 353bool OTodo::operator<( const OTodo &toDoEvent )const{
320 if( !hasDueDate() && !toDoEvent.hasDueDate() ) return true; 354 if( !hasDueDate() && !toDoEvent.hasDueDate() ) return true;
321 if( !hasDueDate() && toDoEvent.hasDueDate() ) return false; 355 if( !hasDueDate() && toDoEvent.hasDueDate() ) return false;
322 if( hasDueDate() && toDoEvent.hasDueDate() ){ 356 if( hasDueDate() && toDoEvent.hasDueDate() ){
323 if( dueDate() == toDoEvent.dueDate() ){ // let's the priority decide 357 if( dueDate() == toDoEvent.dueDate() ){ // let's the priority decide
324 return priority() < toDoEvent.priority(); 358 return priority() < toDoEvent.priority();
325 }else{ 359 }else{
326 return dueDate() < toDoEvent.dueDate(); 360 return dueDate() < toDoEvent.dueDate();
327 } 361 }
328 } 362 }
329 return false; 363 return false;
330} 364}
331bool OTodo::operator<=(const OTodo &toDoEvent )const 365bool OTodo::operator<=(const OTodo &toDoEvent )const
332{ 366{
333 if( !hasDueDate() && !toDoEvent.hasDueDate() ) return true; 367 if( !hasDueDate() && !toDoEvent.hasDueDate() ) return true;
334 if( !hasDueDate() && toDoEvent.hasDueDate() ) return true; 368 if( !hasDueDate() && toDoEvent.hasDueDate() ) return true;
335 if( hasDueDate() && toDoEvent.hasDueDate() ){ 369 if( hasDueDate() && toDoEvent.hasDueDate() ){
336 if( dueDate() == toDoEvent.dueDate() ){ // let's the priority decide 370 if( dueDate() == toDoEvent.dueDate() ){ // let's the priority decide
337 return priority() <= toDoEvent.priority(); 371 return priority() <= toDoEvent.priority();
338 }else{ 372 }else{
339 return dueDate() <= toDoEvent.dueDate(); 373 return dueDate() <= toDoEvent.dueDate();
340 } 374 }
341 } 375 }
342 return true; 376 return true;
343} 377}
344bool OTodo::operator>(const OTodo &toDoEvent )const 378bool OTodo::operator>(const OTodo &toDoEvent )const
345{ 379{
346 if( !hasDueDate() && !toDoEvent.hasDueDate() ) return false; 380 if( !hasDueDate() && !toDoEvent.hasDueDate() ) return false;
347 if( !hasDueDate() && toDoEvent.hasDueDate() ) return false; 381 if( !hasDueDate() && toDoEvent.hasDueDate() ) return false;
348 if( hasDueDate() && toDoEvent.hasDueDate() ){ 382 if( hasDueDate() && toDoEvent.hasDueDate() ){
349 if( dueDate() == toDoEvent.dueDate() ){ // let's the priority decide 383 if( dueDate() == toDoEvent.dueDate() ){ // let's the priority decide
350 return priority() > toDoEvent.priority(); 384 return priority() > toDoEvent.priority();
351 }else{ 385 }else{
352 return dueDate() > toDoEvent.dueDate(); 386 return dueDate() > toDoEvent.dueDate();
353 } 387 }
354 } 388 }
355 return false; 389 return false;
356} 390}
357bool OTodo::operator>=(const OTodo &toDoEvent )const 391bool OTodo::operator>=(const OTodo &toDoEvent )const
358{ 392{
359 if( !hasDueDate() && !toDoEvent.hasDueDate() ) return true; 393 if( !hasDueDate() && !toDoEvent.hasDueDate() ) return true;
360 if( !hasDueDate() && toDoEvent.hasDueDate() ) return false; 394 if( !hasDueDate() && toDoEvent.hasDueDate() ) return false;
361 if( hasDueDate() && toDoEvent.hasDueDate() ){ 395 if( hasDueDate() && toDoEvent.hasDueDate() ){
362 if( dueDate() == toDoEvent.dueDate() ){ // let's the priority decide 396 if( dueDate() == toDoEvent.dueDate() ){ // let's the priority decide
363 return priority() > toDoEvent.priority(); 397 return priority() > toDoEvent.priority();
364 }else{ 398 }else{
365 return dueDate() > toDoEvent.dueDate(); 399 return dueDate() > toDoEvent.dueDate();
366 } 400 }
367 } 401 }
368 return true; 402 return true;
369} 403}
370bool OTodo::operator==(const OTodo &toDoEvent )const 404bool OTodo::operator==(const OTodo &toDoEvent )const
371{ 405{
372 if ( data->priority != toDoEvent.data->priority ) return false; 406 if ( data->priority != toDoEvent.data->priority ) return false;
373 if ( data->priority != toDoEvent.data->prog ) return false; 407 if ( data->priority != toDoEvent.data->prog ) return false;
374 if ( data->isCompleted != toDoEvent.data->isCompleted ) return false; 408 if ( data->isCompleted != toDoEvent.data->isCompleted ) return false;
375 if ( data->hasDate != toDoEvent.data->hasDate ) return false; 409 if ( data->hasDate != toDoEvent.data->hasDate ) return false;
376 if ( data->date != toDoEvent.data->date ) return false; 410 if ( data->date != toDoEvent.data->date ) return false;
377 if ( data->sum != toDoEvent.data->sum ) return false; 411 if ( data->sum != toDoEvent.data->sum ) return false;
378 if ( data->desc != toDoEvent.data->desc ) return false; 412 if ( data->desc != toDoEvent.data->desc ) return false;
379 if ( data->maintainer != toDoEvent.data->maintainer ) 413 if ( data->maintainer != toDoEvent.data->maintainer )
380 return false; 414 return false;
381 415
382 return OPimRecord::operator==( toDoEvent ); 416 return OPimRecord::operator==( toDoEvent );
383} 417}
384void OTodo::deref() { 418void OTodo::deref() {
385 419
386// qWarning("deref in ToDoEvent"); 420// qWarning("deref in ToDoEvent");
387 if ( data->deref() ) { 421 if ( data->deref() ) {
388// qWarning("deleting"); 422// qWarning("deleting");
389 delete data; 423 delete data;
390 data= 0; 424 data= 0;
391 } 425 }
392} 426}
393OTodo &OTodo::operator=(const OTodo &item ) 427OTodo &OTodo::operator=(const OTodo &item )
394{ 428{
395 if ( this == &item ) return *this; 429 if ( this == &item ) return *this;
396 430
397 OPimRecord::operator=( item ); 431 OPimRecord::operator=( item );
398 //qWarning("operator= ref "); 432 //qWarning("operator= ref ");
399 item.data->ref(); 433 item.data->ref();
400 deref(); 434 deref();
401 data = item.data; 435 data = item.data;
402 436
403 return *this; 437 return *this;
404} 438}
405 439
406QMap<int, QString> OTodo::toMap() const { 440QMap<int, QString> OTodo::toMap() const {
407 QMap<int, QString> map; 441 QMap<int, QString> map;
408 442
409 map.insert( Uid, QString::number( uid() ) ); 443 map.insert( Uid, QString::number( uid() ) );
410 map.insert( Category, idsToString( categories() ) ); 444 map.insert( Category, idsToString( categories() ) );
411 map.insert( HasDate, QString::number( data->hasDate ) ); 445 map.insert( HasDate, QString::number( data->hasDate ) );
412 map.insert( Completed, QString::number( data->isCompleted ) ); 446 map.insert( Completed, QString::number( data->isCompleted ) );
413 map.insert( Description, data->desc ); 447 map.insert( Description, data->desc );
414 map.insert( Summary, data->sum ); 448 map.insert( Summary, data->sum );
415 map.insert( Priority, QString::number( data->priority ) ); 449 map.insert( Priority, QString::number( data->priority ) );
416 map.insert( DateDay, QString::number( data->date.day() ) ); 450 map.insert( DateDay, QString::number( data->date.day() ) );
417 map.insert( DateMonth, QString::number( data->date.month() ) ); 451 map.insert( DateMonth, QString::number( data->date.month() ) );
418 map.insert( DateYear, QString::number( data->date.year() ) ); 452 map.insert( DateYear, QString::number( data->date.year() ) );
419 map.insert( Progress, QString::number( data->prog ) ); 453 map.insert( Progress, QString::number( data->prog ) );
420// map.insert( CrossReference, crossToString() ); 454// map.insert( CrossReference, crossToString() );
421 /* FIXME!!! map.insert( State, ); 455 /* FIXME!!! map.insert( State, );
422 map.insert( Recurrence, ); 456 map.insert( Recurrence, );
423 map.insert( Reminders, ); 457 map.insert( Reminders, );
424 map. 458 map.
425 */ 459 */
426 return map; 460 return map;
427} 461}
428 462
429QMap<QString, QString> OTodo::toExtraMap()const { 463QMap<QString, QString> OTodo::toExtraMap()const {
430 return data->extra; 464 return data->extra;
431} 465}
432/** 466/**
433 * change or modify looks at the ref count and either 467 * change or modify looks at the ref count and either
434 * creates a new QShared Object or it can modify it 468 * creates a new QShared Object or it can modify it
435 * right in place 469 * right in place
436 */ 470 */
437void OTodo::changeOrModify() { 471void OTodo::changeOrModify() {
438 if ( data->count != 1 ) { 472 if ( data->count != 1 ) {
439 qWarning("changeOrModify"); 473 qWarning("changeOrModify");
440 data->deref(); 474 data->deref();
441 OTodoData* d2 = new OTodoData(); 475 OTodoData* d2 = new OTodoData();
442 copy(data, d2 ); 476 copy(data, d2 );
443 data = d2; 477 data = d2;
444 } 478 }
445} 479}
446// WATCHOUT 480// WATCHOUT
447/* 481/*
448 * if you add something to the Data struct 482 * if you add something to the Data struct
449 * be sure to copy it here 483 * be sure to copy it here
450 */ 484 */
451void OTodo::copy( OTodoData* src, OTodoData* dest ) { 485void OTodo::copy( OTodoData* src, OTodoData* dest ) {
452 dest->date = src->date; 486 dest->date = src->date;
453 dest->isCompleted = src->isCompleted; 487 dest->isCompleted = src->isCompleted;
454 dest->hasDate = src->hasDate; 488 dest->hasDate = src->hasDate;
455 dest->priority = src->priority; 489 dest->priority = src->priority;
456 dest->desc = src->desc; 490 dest->desc = src->desc;
457 dest->sum = src->sum; 491 dest->sum = src->sum;
458 dest->extra = src->extra; 492 dest->extra = src->extra;
459 dest->prog = src->prog; 493 dest->prog = src->prog;
460 494
461 if (src->state ) 495 if (src->state )
462 dest->state = new OPimState( *src->state ); 496 dest->state = new OPimState( *src->state );
463 497
464 if (src->recur ) 498 if (src->recur )
465 dest->recur = new ORecur( *src->recur ); 499 dest->recur = new ORecur( *src->recur );
466 500
467 if (src->maintainer ) 501 if (src->maintainer )
468 dest->maintainer = new OPimMaintainer( *src->maintainer ) 502 dest->maintainer = new OPimMaintainer( *src->maintainer )
469 ; 503 ;
470 dest->start = src->start; 504 dest->start = src->start;
471 dest->completed = src->completed; 505 dest->completed = src->completed;
472 506
473 if (src->notifiers ) 507 if (src->notifiers )
474 dest->notifiers = new OPimNotifyManager( *src->notifiers ); 508 dest->notifiers = new OPimNotifyManager( *src->notifiers );
475} 509}
476QString OTodo::type() const { 510QString OTodo::type() const {
477 return QString::fromLatin1("OTodo"); 511 return QString::fromLatin1("OTodo");
478} 512}
479QString OTodo::recordField(int /*id*/ )const { 513QString OTodo::recordField(int /*id*/ )const {
480 return QString::null; 514 return QString::null;
481} 515}
482 516
483int OTodo::rtti(){ 517int OTodo::rtti(){
484 return OPimResolver::TodoList; 518 return OPimResolver::TodoList;
485} 519}