summaryrefslogtreecommitdiff
path: root/libopie2/opiepim
authoreilers <eilers>2002-11-01 09:03:40 (UTC)
committer eilers <eilers>2002-11-01 09:03:40 (UTC)
commitdb5e359a4477b61d49328ee9d060e92bf1098980 (patch) (unidiff)
tree1a6e5face7043a1d2798b9fa8f6b7a8479a2af12 /libopie2/opiepim
parent9764202a3e4d35d8b2a0b6330ecfad5a29d56e01 (diff)
downloadopie-db5e359a4477b61d49328ee9d060e92bf1098980.zip
opie-db5e359a4477b61d49328ee9d060e92bf1098980.tar.gz
opie-db5e359a4477b61d49328ee9d060e92bf1098980.tar.bz2
Bugfix #383 && #356
Diffstat (limited to 'libopie2/opiepim') (more/less context) (ignore whitespace changes)
-rw-r--r--libopie2/opiepim/ocontact.cpp33
1 files changed, 19 insertions, 14 deletions
diff --git a/libopie2/opiepim/ocontact.cpp b/libopie2/opiepim/ocontact.cpp
index bf27d0f..acd65c4 100644
--- a/libopie2/opiepim/ocontact.cpp
+++ b/libopie2/opiepim/ocontact.cpp
@@ -1,272 +1,274 @@
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 by Stefan Eilers (eilers.stefan@epost.de) 3** Copyright (C) 2002 by Stefan Eilers (eilers.stefan@epost.de)
4** 4**
5** This file is part of the Qtopia Environment. 5** This file is part of the Qtopia Environment.
6** 6**
7** This file may be distributed and/or modified under the terms of the 7** This file may be distributed and/or modified under the terms of the
8** GNU General Public License version 2 as published by the Free Software 8** GNU General Public License version 2 as published by the Free Software
9** Foundation and appearing in the file LICENSE.GPL included in the 9** Foundation and appearing in the file LICENSE.GPL included in the
10** packaging of this file. 10** packaging of this file.
11** 11**
12** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE 12** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
13** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. 13** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
14** 14**
15** See http://www.trolltech.com/gpl/ for GPL licensing information. 15** See http://www.trolltech.com/gpl/ for GPL licensing information.
16** 16**
17** Contact info@trolltech.com if any conditions of this licensing are 17** Contact info@trolltech.com if any conditions of this licensing are
18** not clear to you. 18** not clear to you.
19** 19**
20**********************************************************************/ 20**********************************************************************/
21 21
22#define QTOPIA_INTERNAL_CONTACT_MRE 22#define QTOPIA_INTERNAL_CONTACT_MRE
23 23
24#include "ocontact.h" 24#include "ocontact.h"
25#include "../../library/backend/vobject_p.h" 25#include "../../library/backend/vobject_p.h"
26#include "../../library/backend/qfiledirect_p.h" 26#include "../../library/backend/qfiledirect_p.h"
27 27
28#include <qpe/stringutil.h> 28#include <qpe/stringutil.h>
29#include <qpe/timeconversion.h> 29#include <qpe/timeconversion.h>
30#include <qpe/timestring.h> 30#include <qpe/timestring.h>
31 31
32#include <qobject.h> 32#include <qobject.h>
33#include <qregexp.h> 33#include <qregexp.h>
34#include <qstylesheet.h> 34#include <qstylesheet.h>
35#include <qfileinfo.h> 35#include <qfileinfo.h>
36#include <qmap.h> 36#include <qmap.h>
37 37
38#include <stdio.h> 38#include <stdio.h>
39 39
40/*! 40/*!
41 \class Contact contact.h 41 \class Contact contact.h
42 \brief The Contact class holds the data of an address book entry. 42 \brief The Contact class holds the data of an address book entry.
43 43
44 This data includes information the name of the person, contact 44 This data includes information the name of the person, contact
45 information, and business information such as deparment and job title. 45 information, and business information such as deparment and job title.
46 46
47 \ingroup qtopiaemb 47 \ingroup qtopiaemb
48 \ingroup qtopiadesktop 48 \ingroup qtopiadesktop
49*/ 49*/
50 50
51Qtopia::UidGen OContact::sUidGen( Qtopia::UidGen::Qtopia ); 51Qtopia::UidGen OContact::sUidGen( Qtopia::UidGen::Qtopia );
52 52
53/*! 53/*!
54 Creates a new, empty contact. 54 Creates a new, empty contact.
55*/ 55*/
56OContact::OContact() 56OContact::OContact()
57 : OPimRecord(), mMap(), d( 0 ) 57 : OPimRecord(), mMap(), d( 0 )
58{ 58{
59} 59}
60 60
61/*! 61/*!
62 \internal 62 \internal
63 Creates a new contact. The properties of the contact are 63 Creates a new contact. The properties of the contact are
64 set from \a fromMap. 64 set from \a fromMap.
65*/ 65*/
66OContact::OContact( const QMap<int, QString> &fromMap ) : 66OContact::OContact( const QMap<int, QString> &fromMap ) :
67 OPimRecord(), mMap( fromMap ), d( 0 ) 67 OPimRecord(), mMap( fromMap ), d( 0 )
68{ 68{
69 QString cats = mMap[ Qtopia::AddressCategory ]; 69 QString cats = mMap[ Qtopia::AddressCategory ];
70 if ( !cats.isEmpty() ) 70 if ( !cats.isEmpty() )
71 setCategories( idsFromString( cats ) ); 71 setCategories( idsFromString( cats ) );
72
72 QString uidStr = find( Qtopia::AddressUid ); 73 QString uidStr = find( Qtopia::AddressUid );
73 74
74 if ( uidStr.isEmpty() ) 75 if ( uidStr.isEmpty() || (uidStr.toInt() == 0) ){
76 qWarning( "Invalid UID found. Generate new one.." );
75 setUid( uidGen().generate() ); 77 setUid( uidGen().generate() );
76 else 78 }else
77 setUid( uidStr.toInt() ); 79 setUid( uidStr.toInt() );
78 80
79 if ( !uidStr.isEmpty() ) 81// if ( !uidStr.isEmpty() )
80 setUid( uidStr.toInt() ); 82 // setUid( uidStr.toInt() );
81} 83}
82 84
83/*! 85/*!
84 Destroys a contact. 86 Destroys a contact.
85*/ 87*/
86OContact::~OContact() 88OContact::~OContact()
87{ 89{
88} 90}
89 91
90/*! \fn void OContact::setTitle( const QString &str ) 92/*! \fn void OContact::setTitle( const QString &str )
91 Sets the title of the contact to \a str. 93 Sets the title of the contact to \a str.
92*/ 94*/
93 95
94/*! \fn void OContact::setFirstName( const QString &str ) 96/*! \fn void OContact::setFirstName( const QString &str )
95 Sets the first name of the contact to \a str. 97 Sets the first name of the contact to \a str.
96*/ 98*/
97 99
98/*! \fn void OContact::setMiddleName( const QString &str ) 100/*! \fn void OContact::setMiddleName( const QString &str )
99 Sets the middle name of the contact to \a str. 101 Sets the middle name of the contact to \a str.
100*/ 102*/
101 103
102/*! \fn void OContact::setLastName( const QString &str ) 104/*! \fn void OContact::setLastName( const QString &str )
103 Sets the last name of the contact to \a str. 105 Sets the last name of the contact to \a str.
104*/ 106*/
105 107
106/*! \fn void OContact::setSuffix( const QString &str ) 108/*! \fn void OContact::setSuffix( const QString &str )
107 Sets the suffix of the contact to \a str. 109 Sets the suffix of the contact to \a str.
108*/ 110*/
109 111
110/*! \fn void OContact::setFileAs( const QString &str ) 112/*! \fn void OContact::setFileAs( const QString &str )
111 Sets the contact to filed as \a str. 113 Sets the contact to filed as \a str.
112*/ 114*/
113 115
114/*! \fn void OContact::setDefaultEmail( const QString &str ) 116/*! \fn void OContact::setDefaultEmail( const QString &str )
115 Sets the default email of the contact to \a str. 117 Sets the default email of the contact to \a str.
116*/ 118*/
117 119
118/*! \fn void OContact::setHomeStreet( const QString &str ) 120/*! \fn void OContact::setHomeStreet( const QString &str )
119 Sets the home street address of the contact to \a str. 121 Sets the home street address of the contact to \a str.
120*/ 122*/
121 123
122/*! \fn void OContact::setHomeCity( const QString &str ) 124/*! \fn void OContact::setHomeCity( const QString &str )
123 Sets the home city of the contact to \a str. 125 Sets the home city of the contact to \a str.
124*/ 126*/
125 127
126/*! \fn void OContact::setHomeState( const QString &str ) 128/*! \fn void OContact::setHomeState( const QString &str )
127 Sets the home state of the contact to \a str. 129 Sets the home state of the contact to \a str.
128*/ 130*/
129 131
130/*! \fn void OContact::setHomeZip( const QString &str ) 132/*! \fn void OContact::setHomeZip( const QString &str )
131 Sets the home zip code of the contact to \a str. 133 Sets the home zip code of the contact to \a str.
132*/ 134*/
133 135
134/*! \fn void OContact::setHomeCountry( const QString &str ) 136/*! \fn void OContact::setHomeCountry( const QString &str )
135 Sets the home country of the contact to \a str. 137 Sets the home country of the contact to \a str.
136*/ 138*/
137 139
138/*! \fn void OContact::setHomePhone( const QString &str ) 140/*! \fn void OContact::setHomePhone( const QString &str )
139 Sets the home phone number of the contact to \a str. 141 Sets the home phone number of the contact to \a str.
140*/ 142*/
141 143
142/*! \fn void OContact::setHomeFax( const QString &str ) 144/*! \fn void OContact::setHomeFax( const QString &str )
143 Sets the home fax number of the contact to \a str. 145 Sets the home fax number of the contact to \a str.
144*/ 146*/
145 147
146/*! \fn void OContact::setHomeMobile( const QString &str ) 148/*! \fn void OContact::setHomeMobile( const QString &str )
147 Sets the home mobile phone number of the contact to \a str. 149 Sets the home mobile phone number of the contact to \a str.
148*/ 150*/
149 151
150/*! \fn void OContact::setHomeWebpage( const QString &str ) 152/*! \fn void OContact::setHomeWebpage( const QString &str )
151 Sets the home webpage of the contact to \a str. 153 Sets the home webpage of the contact to \a str.
152*/ 154*/
153 155
154/*! \fn void OContact::setCompany( const QString &str ) 156/*! \fn void OContact::setCompany( const QString &str )
155 Sets the company for contact to \a str. 157 Sets the company for contact to \a str.
156*/ 158*/
157 159
158/*! \fn void OContact::setJobTitle( const QString &str ) 160/*! \fn void OContact::setJobTitle( const QString &str )
159 Sets the job title of the contact to \a str. 161 Sets the job title of the contact to \a str.
160*/ 162*/
161 163
162/*! \fn void OContact::setDepartment( const QString &str ) 164/*! \fn void OContact::setDepartment( const QString &str )
163 Sets the department for contact to \a str. 165 Sets the department for contact to \a str.
164*/ 166*/
165 167
166/*! \fn void OContact::setOffice( const QString &str ) 168/*! \fn void OContact::setOffice( const QString &str )
167 Sets the office for contact to \a str. 169 Sets the office for contact to \a str.
168*/ 170*/
169 171
170/*! \fn void OContact::setBusinessStreet( const QString &str ) 172/*! \fn void OContact::setBusinessStreet( const QString &str )
171 Sets the business street address of the contact to \a str. 173 Sets the business street address of the contact to \a str.
172*/ 174*/
173 175
174/*! \fn void OContact::setBusinessCity( const QString &str ) 176/*! \fn void OContact::setBusinessCity( const QString &str )
175 Sets the business city of the contact to \a str. 177 Sets the business city of the contact to \a str.
176*/ 178*/
177 179
178/*! \fn void OContact::setBusinessState( const QString &str ) 180/*! \fn void OContact::setBusinessState( const QString &str )
179 Sets the business state of the contact to \a str. 181 Sets the business state of the contact to \a str.
180*/ 182*/
181 183
182/*! \fn void OContact::setBusinessZip( const QString &str ) 184/*! \fn void OContact::setBusinessZip( const QString &str )
183 Sets the business zip code of the contact to \a str. 185 Sets the business zip code of the contact to \a str.
184*/ 186*/
185 187
186/*! \fn void OContact::setBusinessCountry( const QString &str ) 188/*! \fn void OContact::setBusinessCountry( const QString &str )
187 Sets the business country of the contact to \a str. 189 Sets the business country of the contact to \a str.
188*/ 190*/
189 191
190/*! \fn void OContact::setBusinessPhone( const QString &str ) 192/*! \fn void OContact::setBusinessPhone( const QString &str )
191 Sets the business phone number of the contact to \a str. 193 Sets the business phone number of the contact to \a str.
192*/ 194*/
193 195
194/*! \fn void OContact::setBusinessFax( const QString &str ) 196/*! \fn void OContact::setBusinessFax( const QString &str )
195 Sets the business fax number of the contact to \a str. 197 Sets the business fax number of the contact to \a str.
196*/ 198*/
197 199
198/*! \fn void OContact::setBusinessMobile( const QString &str ) 200/*! \fn void OContact::setBusinessMobile( const QString &str )
199 Sets the business mobile phone number of the contact to \a str. 201 Sets the business mobile phone number of the contact to \a str.
200*/ 202*/
201 203
202/*! \fn void OContact::setBusinessPager( const QString &str ) 204/*! \fn void OContact::setBusinessPager( const QString &str )
203 Sets the business pager number of the contact to \a str. 205 Sets the business pager number of the contact to \a str.
204*/ 206*/
205 207
206/*! \fn void OContact::setBusinessWebpage( const QString &str ) 208/*! \fn void OContact::setBusinessWebpage( const QString &str )
207 Sets the business webpage of the contact to \a str. 209 Sets the business webpage of the contact to \a str.
208*/ 210*/
209 211
210/*! \fn void OContact::setProfession( const QString &str ) 212/*! \fn void OContact::setProfession( const QString &str )
211 Sets the profession of the contact to \a str. 213 Sets the profession of the contact to \a str.
212*/ 214*/
213 215
214/*! \fn void OContact::setAssistant( const QString &str ) 216/*! \fn void OContact::setAssistant( const QString &str )
215 Sets the assistant of the contact to \a str. 217 Sets the assistant of the contact to \a str.
216*/ 218*/
217 219
218/*! \fn void OContact::setManager( const QString &str ) 220/*! \fn void OContact::setManager( const QString &str )
219 Sets the manager of the contact to \a str. 221 Sets the manager of the contact to \a str.
220*/ 222*/
221 223
222/*! \fn void OContact::setSpouse( const QString &str ) 224/*! \fn void OContact::setSpouse( const QString &str )
223 Sets the spouse of the contact to \a str. 225 Sets the spouse of the contact to \a str.
224*/ 226*/
225 227
226/*! \fn void OContact::setGender( const QString &str ) 228/*! \fn void OContact::setGender( const QString &str )
227 Sets the gender of the contact to \a str. 229 Sets the gender of the contact to \a str.
228*/ 230*/
229 231
230/*! \fn void OContact::setNickname( const QString &str ) 232/*! \fn void OContact::setNickname( const QString &str )
231 Sets the nickname of the contact to \a str. 233 Sets the nickname of the contact to \a str.
232*/ 234*/
233 235
234/*! \fn void OContact::setNotes( const QString &str ) 236/*! \fn void OContact::setNotes( const QString &str )
235 Sets the notes about the contact to \a str. 237 Sets the notes about the contact to \a str.
236*/ 238*/
237 239
238/*! \fn QString OContact::title() const 240/*! \fn QString OContact::title() const
239 Returns the title of the contact. 241 Returns the title of the contact.
240*/ 242*/
241 243
242/*! \fn QString OContact::firstName() const 244/*! \fn QString OContact::firstName() const
243 Returns the first name of the contact. 245 Returns the first name of the contact.
244*/ 246*/
245 247
246/*! \fn QString OContact::middleName() const 248/*! \fn QString OContact::middleName() const
247 Returns the middle name of the contact. 249 Returns the middle name of the contact.
248*/ 250*/
249 251
250/*! \fn QString OContact::lastName() const 252/*! \fn QString OContact::lastName() const
251 Returns the last name of the contact. 253 Returns the last name of the contact.
252*/ 254*/
253 255
254/*! \fn QString OContact::suffix() const 256/*! \fn QString OContact::suffix() const
255 Returns the suffix of the contact. 257 Returns the suffix of the contact.
256*/ 258*/
257 259
258/*! \fn QString OContact::fileAs() const 260/*! \fn QString OContact::fileAs() const
259 Returns the string the contact is filed as. 261 Returns the string the contact is filed as.
260*/ 262*/
261 263
262/*! \fn QString OContact::defaultEmail() const 264/*! \fn QString OContact::defaultEmail() const
263 Returns the default email address of the contact. 265 Returns the default email address of the contact.
264*/ 266*/
265 267
266/*! \fn QString OContact::emails() const 268/*! \fn QString OContact::emails() const
267 Returns the list of email address for a contact separated by ';'s in a single 269 Returns the list of email address for a contact separated by ';'s in a single
268 string. 270 string.
269*/ 271*/
270 272
271/*! \fn QString OContact::homeStreet() const 273/*! \fn QString OContact::homeStreet() const
272 Returns the home street address of the contact. 274 Returns the home street address of the contact.
@@ -382,390 +384,390 @@ OContact::~OContact()
382 384
383/*! \fn QString OContact::nickname() const 385/*! \fn QString OContact::nickname() const
384 Returns the nickname of the contact. 386 Returns the nickname of the contact.
385*/ 387*/
386 388
387/*! \fn QString OContact::children() const 389/*! \fn QString OContact::children() const
388 Returns the children of the contact. 390 Returns the children of the contact.
389*/ 391*/
390 392
391/*! \fn QString OContact::notes() const 393/*! \fn QString OContact::notes() const
392 Returns the notes relating to the the contact. 394 Returns the notes relating to the the contact.
393*/ 395*/
394 396
395/*! \fn QString OContact::groups() const 397/*! \fn QString OContact::groups() const
396 \internal 398 \internal
397 Returns the groups for the contact. 399 Returns the groups for the contact.
398*/ 400*/
399 401
400/*! \fn QStringList OContact::groupList() const 402/*! \fn QStringList OContact::groupList() const
401 \internal 403 \internal
402*/ 404*/
403 405
404/*! \fn QString OContact::field(int) const 406/*! \fn QString OContact::field(int) const
405 \internal 407 \internal
406*/ 408*/
407 409
408/*! \fn void OContact::saveJournal( journal_action, const QString & = QString::null ) 410/*! \fn void OContact::saveJournal( journal_action, const QString & = QString::null )
409 \internal 411 \internal
410*/ 412*/
411 413
412/*! \fn void OContact::setUid( int id ) 414/*! \fn void OContact::setUid( int id )
413 \internal 415 \internal
414 Sets the uid for this record to \a id. 416 Sets the uid for this record to \a id.
415*/ 417*/
416 418
417/*! \enum OContact::journal_action 419/*! \enum OContact::journal_action
418 \internal 420 \internal
419*/ 421*/
420 422
421/*! 423/*!
422 \internal 424 \internal
423*/ 425*/
424QMap<int, QString> OContact::toMap() const 426QMap<int, QString> OContact::toMap() const
425{ 427{
426 QMap<int, QString> map = mMap; 428 QMap<int, QString> map = mMap;
427 QString cats = idsToString( categories() ); 429 QString cats = idsToString( categories() );
428 if ( !cats.isEmpty() ) 430 if ( !cats.isEmpty() )
429 map.insert( Qtopia::AddressCategory, cats ); 431 map.insert( Qtopia::AddressCategory, cats );
430 return map; 432 return map;
431} 433}
432 434
433/*! 435/*!
434 Returns a rich text formatted QString representing the contents the contact. 436 Returns a rich text formatted QString representing the contents the contact.
435*/ 437*/
436QString OContact::toRichText() const 438QString OContact::toRichText() const
437{ 439{
438 QString text; 440 QString text;
439 QString value, comp, state; 441 QString value, comp, state;
440 442
441 // name, jobtitle and company 443 // name, jobtitle and company
442 if ( !(value = fullName()).isEmpty() ) 444 if ( !(value = fullName()).isEmpty() )
443 text += "<b>" + Qtopia::escapeString(value) + "</b><br>"; 445 text += "<b>" + Qtopia::escapeString(value) + "</b><br>";
444 if ( !(value = jobTitle()).isEmpty() ) 446 if ( !(value = jobTitle()).isEmpty() )
445 text += Qtopia::escapeString(value) + "<br>"; 447 text += Qtopia::escapeString(value) + "<br>";
446 448
447 comp = company(); 449 comp = company();
448 if ( !(value = department()).isEmpty() ) { 450 if ( !(value = department()).isEmpty() ) {
449 text += Qtopia::escapeString(value); 451 text += Qtopia::escapeString(value);
450 if ( comp ) 452 if ( comp )
451 text += ", "; 453 text += ", ";
452 else 454 else
453 text += "<br>"; 455 text += "<br>";
454 } 456 }
455 if ( !comp.isEmpty() ) 457 if ( !comp.isEmpty() )
456 text += Qtopia::escapeString(comp) + "<br>"; 458 text += Qtopia::escapeString(comp) + "<br>";
457 459
458 // business address 460 // business address
459 if ( !businessStreet().isEmpty() || !businessCity().isEmpty() || 461 if ( !businessStreet().isEmpty() || !businessCity().isEmpty() ||
460 !businessZip().isEmpty() || !businessCountry().isEmpty() ) { 462 !businessZip().isEmpty() || !businessCountry().isEmpty() ) {
461 text += "<br>"; 463 text += "<br>";
462 text += QObject::tr( "<b>Work Address:</b>" ); 464 text += QObject::tr( "<b>Work Address:</b>" );
463 text += "<br>"; 465 text += "<br>";
464 } 466 }
465 467
466 if ( !(value = businessStreet()).isEmpty() ) 468 if ( !(value = businessStreet()).isEmpty() )
467 text += Qtopia::escapeString(value) + "<br>"; 469 text += Qtopia::escapeString(value) + "<br>";
468 state = businessState(); 470 state = businessState();
469 if ( !(value = businessCity()).isEmpty() ) { 471 if ( !(value = businessCity()).isEmpty() ) {
470 text += Qtopia::escapeString(value); 472 text += Qtopia::escapeString(value);
471 if ( state ) 473 if ( state )
472 text += ", " + Qtopia::escapeString(state); 474 text += ", " + Qtopia::escapeString(state);
473 text += "<br>"; 475 text += "<br>";
474 } else if ( !state.isEmpty() ) 476 } else if ( !state.isEmpty() )
475 text += Qtopia::escapeString(state) + "<br>"; 477 text += Qtopia::escapeString(state) + "<br>";
476 if ( !(value = businessZip()).isEmpty() ) 478 if ( !(value = businessZip()).isEmpty() )
477 text += Qtopia::escapeString(value) + "<br>"; 479 text += Qtopia::escapeString(value) + "<br>";
478 if ( !(value = businessCountry()).isEmpty() ) 480 if ( !(value = businessCountry()).isEmpty() )
479 text += Qtopia::escapeString(value) + "<br>"; 481 text += Qtopia::escapeString(value) + "<br>";
480 482
481 // home address 483 // home address
482 if ( !homeStreet().isEmpty() || !homeCity().isEmpty() || 484 if ( !homeStreet().isEmpty() || !homeCity().isEmpty() ||
483 !homeZip().isEmpty() || !homeCountry().isEmpty() ) { 485 !homeZip().isEmpty() || !homeCountry().isEmpty() ) {
484 text += "<br>"; 486 text += "<br>";
485 text += QObject::tr( "<b>Home Address:</b>" ); 487 text += QObject::tr( "<b>Home Address:</b>" );
486 text += "<br>"; 488 text += "<br>";
487 } 489 }
488 490
489 if ( !(value = homeStreet()).isEmpty() ) 491 if ( !(value = homeStreet()).isEmpty() )
490 text += Qtopia::escapeString(value) + "<br>"; 492 text += Qtopia::escapeString(value) + "<br>";
491 state = homeState(); 493 state = homeState();
492 if ( !(value = homeCity()).isEmpty() ) { 494 if ( !(value = homeCity()).isEmpty() ) {
493 text += Qtopia::escapeString(value); 495 text += Qtopia::escapeString(value);
494 if ( !state.isEmpty() ) 496 if ( !state.isEmpty() )
495 text += ", " + Qtopia::escapeString(state); 497 text += ", " + Qtopia::escapeString(state);
496 text += "<br>"; 498 text += "<br>";
497 } else if (!state.isEmpty()) 499 } else if (!state.isEmpty())
498 text += Qtopia::escapeString(state) + "<br>"; 500 text += Qtopia::escapeString(state) + "<br>";
499 if ( !(value = homeZip()).isEmpty() ) 501 if ( !(value = homeZip()).isEmpty() )
500 text += Qtopia::escapeString(value) + "<br>"; 502 text += Qtopia::escapeString(value) + "<br>";
501 if ( !(value = homeCountry()).isEmpty() ) 503 if ( !(value = homeCountry()).isEmpty() )
502 text += Qtopia::escapeString(value) + "<br>"; 504 text += Qtopia::escapeString(value) + "<br>";
503 505
504 // the others... 506 // the others...
505 QString str; 507 QString str;
506 str = emails(); 508 str = emails();
507 if ( !str.isEmpty() ) 509 if ( !str.isEmpty() )
508 text += "<b>" + QObject::tr("Email Addresses: ") + "</b>" 510 text += "<b>" + QObject::tr("Email Addresses: ") + "</b>"
509 + Qtopia::escapeString(str) + "<br>"; 511 + Qtopia::escapeString(str) + "<br>";
510 str = homePhone(); 512 str = homePhone();
511 if ( !str.isEmpty() ) 513 if ( !str.isEmpty() )
512 text += "<b>" + QObject::tr("Home Phone: ") + "</b>" 514 text += "<b>" + QObject::tr("Home Phone: ") + "</b>"
513 + Qtopia::escapeString(str) + "<br>"; 515 + Qtopia::escapeString(str) + "<br>";
514 str = homeFax(); 516 str = homeFax();
515 if ( !str.isEmpty() ) 517 if ( !str.isEmpty() )
516 text += "<b>" + QObject::tr("Home Fax: ") + "</b>" 518 text += "<b>" + QObject::tr("Home Fax: ") + "</b>"
517 + Qtopia::escapeString(str) + "<br>"; 519 + Qtopia::escapeString(str) + "<br>";
518 str = homeMobile(); 520 str = homeMobile();
519 if ( !str.isEmpty() ) 521 if ( !str.isEmpty() )
520 text += "<b>" + QObject::tr("Home Mobile: ") + "</b>" 522 text += "<b>" + QObject::tr("Home Mobile: ") + "</b>"
521 + Qtopia::escapeString(str) + "<br>"; 523 + Qtopia::escapeString(str) + "<br>";
522 str = homeWebpage(); 524 str = homeWebpage();
523 if ( !str.isEmpty() ) 525 if ( !str.isEmpty() )
524 text += "<b>" + QObject::tr("Home Web Page: ") + "</b>" 526 text += "<b>" + QObject::tr("Home Web Page: ") + "</b>"
525 + Qtopia::escapeString(str) + "<br>"; 527 + Qtopia::escapeString(str) + "<br>";
526 str = businessWebpage(); 528 str = businessWebpage();
527 if ( !str.isEmpty() ) 529 if ( !str.isEmpty() )
528 text += "<b>" + QObject::tr("Business Web Page: ") + "</b>" 530 text += "<b>" + QObject::tr("Business Web Page: ") + "</b>"
529 + Qtopia::escapeString(str) + "<br>"; 531 + Qtopia::escapeString(str) + "<br>";
530 str = office(); 532 str = office();
531 if ( !str.isEmpty() ) 533 if ( !str.isEmpty() )
532 text += "<b>" + QObject::tr("Office: ") + "</b>" 534 text += "<b>" + QObject::tr("Office: ") + "</b>"
533 + Qtopia::escapeString(str) + "<br>"; 535 + Qtopia::escapeString(str) + "<br>";
534 str = businessPhone(); 536 str = businessPhone();
535 if ( !str.isEmpty() ) 537 if ( !str.isEmpty() )
536 text += "<b>" + QObject::tr("Business Phone: ") + "</b>" 538 text += "<b>" + QObject::tr("Business Phone: ") + "</b>"
537 + Qtopia::escapeString(str) + "<br>"; 539 + Qtopia::escapeString(str) + "<br>";
538 str = businessFax(); 540 str = businessFax();
539 if ( !str.isEmpty() ) 541 if ( !str.isEmpty() )
540 text += "<b>" + QObject::tr("Business Fax: ") + "</b>" 542 text += "<b>" + QObject::tr("Business Fax: ") + "</b>"
541 + Qtopia::escapeString(str) + "<br>"; 543 + Qtopia::escapeString(str) + "<br>";
542 str = businessMobile(); 544 str = businessMobile();
543 if ( !str.isEmpty() ) 545 if ( !str.isEmpty() )
544 text += "<b>" + QObject::tr("Business Mobile: ") + "</b>" 546 text += "<b>" + QObject::tr("Business Mobile: ") + "</b>"
545 + Qtopia::escapeString(str) + "<br>"; 547 + Qtopia::escapeString(str) + "<br>";
546 str = businessPager(); 548 str = businessPager();
547 if ( !str.isEmpty() ) 549 if ( !str.isEmpty() )
548 text += "<b>" + QObject::tr("Business Pager: ") + "</b>" 550 text += "<b>" + QObject::tr("Business Pager: ") + "</b>"
549 + Qtopia::escapeString(str) + "<br>"; 551 + Qtopia::escapeString(str) + "<br>";
550 str = profession(); 552 str = profession();
551 if ( !str.isEmpty() ) 553 if ( !str.isEmpty() )
552 text += "<b>" + QObject::tr("Profession: ") + "</b>" 554 text += "<b>" + QObject::tr("Profession: ") + "</b>"
553 + Qtopia::escapeString(str) + "<br>"; 555 + Qtopia::escapeString(str) + "<br>";
554 str = assistant(); 556 str = assistant();
555 if ( !str.isEmpty() ) 557 if ( !str.isEmpty() )
556 text += "<b>" + QObject::tr("Assistant: ") + "</b>" 558 text += "<b>" + QObject::tr("Assistant: ") + "</b>"
557 + Qtopia::escapeString(str) + "<br>"; 559 + Qtopia::escapeString(str) + "<br>";
558 str = manager(); 560 str = manager();
559 if ( !str.isEmpty() ) 561 if ( !str.isEmpty() )
560 text += "<b>" + QObject::tr("Manager: ") + "</b>" 562 text += "<b>" + QObject::tr("Manager: ") + "</b>"
561 + Qtopia::escapeString(str) + "<br>"; 563 + Qtopia::escapeString(str) + "<br>";
562 str = gender(); 564 str = gender();
563 if ( !str.isEmpty() && str.toInt() != 0 ) { 565 if ( !str.isEmpty() && str.toInt() != 0 ) {
564 if ( str.toInt() == 1 ) 566 if ( str.toInt() == 1 )
565 str = QObject::tr( "Male" ); 567 str = QObject::tr( "Male" );
566 else if ( str.toInt() == 2 ) 568 else if ( str.toInt() == 2 )
567 str = QObject::tr( "Female" ); 569 str = QObject::tr( "Female" );
568 text += "<b>" + QObject::tr("Gender: ") + "</b>" + str + "<br>"; 570 text += "<b>" + QObject::tr("Gender: ") + "</b>" + str + "<br>";
569 } 571 }
570 str = spouse(); 572 str = spouse();
571 if ( !str.isEmpty() ) 573 if ( !str.isEmpty() )
572 text += "<b>" + QObject::tr("Spouse: ") + "</b>" 574 text += "<b>" + QObject::tr("Spouse: ") + "</b>"
573 + Qtopia::escapeString(str) + "<br>"; 575 + Qtopia::escapeString(str) + "<br>";
574 if ( !birthday().isValid() ){ 576 if ( birthday().isValid() ){
575 str = TimeString::numberDateString( birthday() ); 577 str = TimeString::numberDateString( birthday() );
576 text += "<b>" + QObject::tr("Birthday: ") + "</b>" 578 text += "<b>" + QObject::tr("Birthday: ") + "</b>"
577 + Qtopia::escapeString(str) + "<br>"; 579 + Qtopia::escapeString(str) + "<br>";
578 } 580 }
579 if ( !anniversary().isValid() ){ 581 if ( anniversary().isValid() ){
580 str = TimeString::numberDateString( anniversary() ); 582 str = TimeString::numberDateString( anniversary() );
581 text += "<b>" + QObject::tr("Anniversary: ") + "</b>" 583 text += "<b>" + QObject::tr("Anniversary: ") + "</b>"
582 + Qtopia::escapeString(str) + "<br>"; 584 + Qtopia::escapeString(str) + "<br>";
583 } 585 }
584 str = nickname(); 586 str = nickname();
585 if ( !str.isEmpty() ) 587 if ( !str.isEmpty() )
586 text += "<b>" + QObject::tr("Nickname: ") + "</b>" 588 text += "<b>" + QObject::tr("Nickname: ") + "</b>"
587 + Qtopia::escapeString(str) + "<br>"; 589 + Qtopia::escapeString(str) + "<br>";
588 590
589 // notes last 591 // notes last
590 if ( (value = notes()) ) { 592 if ( (value = notes()) ) {
591 QRegExp reg("\n"); 593 QRegExp reg("\n");
592 594
593 //QString tmp = Qtopia::escapeString(value); 595 //QString tmp = Qtopia::escapeString(value);
594 QString tmp = QStyleSheet::convertFromPlainText(value); 596 QString tmp = QStyleSheet::convertFromPlainText(value);
595 //tmp.replace( reg, "<br>" ); 597 //tmp.replace( reg, "<br>" );
596 text += "<br>" + tmp + "<br>"; 598 text += "<br>" + tmp + "<br>";
597 } 599 }
598 return text; 600 return text;
599} 601}
600 602
601/*! 603/*!
602 \internal 604 \internal
603*/ 605*/
604void OContact::insert( int key, const QString &v ) 606void OContact::insert( int key, const QString &v )
605{ 607{
606 QString value = v.stripWhiteSpace(); 608 QString value = v.stripWhiteSpace();
607 if ( value.isEmpty() ) 609 if ( value.isEmpty() )
608 mMap.remove( key ); 610 mMap.remove( key );
609 else 611 else
610 mMap.insert( key, value ); 612 mMap.insert( key, value );
611} 613}
612 614
613/*! 615/*!
614 \internal 616 \internal
615*/ 617*/
616void OContact::replace( int key, const QString & v ) 618void OContact::replace( int key, const QString & v )
617{ 619{
618 QString value = v.stripWhiteSpace(); 620 QString value = v.stripWhiteSpace();
619 if ( value.isEmpty() ) 621 if ( value.isEmpty() )
620 mMap.remove( key ); 622 mMap.remove( key );
621 else 623 else
622 mMap.replace( key, value ); 624 mMap.replace( key, value );
623} 625}
624 626
625/*! 627/*!
626 \internal 628 \internal
627*/ 629*/
628QString OContact::find( int key ) const 630QString OContact::find( int key ) const
629{ 631{
630 return mMap[key]; 632 return mMap[key];
631} 633}
632 634
633/*! 635/*!
634 \internal 636 \internal
635*/ 637*/
636QString OContact::displayAddress( const QString &street, 638QString OContact::displayAddress( const QString &street,
637 const QString &city, 639 const QString &city,
638 const QString &state, 640 const QString &state,
639 const QString &zip, 641 const QString &zip,
640 const QString &country ) const 642 const QString &country ) const
641{ 643{
642 QString s = street; 644 QString s = street;
643 if ( !street.isEmpty() ) 645 if ( !street.isEmpty() )
644 s+= "\n"; 646 s+= "\n";
645 s += city; 647 s += city;
646 if ( !city.isEmpty() && !state.isEmpty() ) 648 if ( !city.isEmpty() && !state.isEmpty() )
647 s += ", "; 649 s += ", ";
648 s += state; 650 s += state;
649 if ( !state.isEmpty() && !zip.isEmpty() ) 651 if ( !state.isEmpty() && !zip.isEmpty() )
650 s += " "; 652 s += " ";
651 s += zip; 653 s += zip;
652 if ( !country.isEmpty() && !s.isEmpty() ) 654 if ( !country.isEmpty() && !s.isEmpty() )
653 s += "\n"; 655 s += "\n";
654 s += country; 656 s += country;
655 return s; 657 return s;
656} 658}
657 659
658/*! 660/*!
659 \internal 661 \internal
660*/ 662*/
661QString OContact::displayBusinessAddress() const 663QString OContact::displayBusinessAddress() const
662{ 664{
663 return displayAddress( businessStreet(), businessCity(), 665 return displayAddress( businessStreet(), businessCity(),
664 businessState(), businessZip(), 666 businessState(), businessZip(),
665 businessCountry() ); 667 businessCountry() );
666} 668}
667 669
668/*! 670/*!
669 \internal 671 \internal
670*/ 672*/
671QString OContact::displayHomeAddress() const 673QString OContact::displayHomeAddress() const
672{ 674{
673 return displayAddress( homeStreet(), homeCity(), 675 return displayAddress( homeStreet(), homeCity(),
674 homeState(), homeZip(), 676 homeState(), homeZip(),
675 homeCountry() ); 677 homeCountry() );
676} 678}
677 679
678/*! 680/*!
679 Returns the full name of the contact 681 Returns the full name of the contact
680*/ 682*/
681QString OContact::fullName() const 683QString OContact::fullName() const
682{ 684{
683 QString title = find( Qtopia::Title ); 685 QString title = find( Qtopia::Title );
684 QString firstName = find( Qtopia::FirstName ); 686 QString firstName = find( Qtopia::FirstName );
685 QString middleName = find( Qtopia::MiddleName ); 687 QString middleName = find( Qtopia::MiddleName );
686 QString lastName = find( Qtopia::LastName ); 688 QString lastName = find( Qtopia::LastName );
687 QString suffix = find( Qtopia::Suffix ); 689 QString suffix = find( Qtopia::Suffix );
688 690
689 QString name = title; 691 QString name = title;
690 if ( !firstName.isEmpty() ) { 692 if ( !firstName.isEmpty() ) {
691 if ( !name.isEmpty() ) 693 if ( !name.isEmpty() )
692 name += " "; 694 name += " ";
693 name += firstName; 695 name += firstName;
694 } 696 }
695 if ( !middleName.isEmpty() ) { 697 if ( !middleName.isEmpty() ) {
696 if ( !name.isEmpty() ) 698 if ( !name.isEmpty() )
697 name += " "; 699 name += " ";
698 name += middleName; 700 name += middleName;
699 } 701 }
700 if ( !lastName.isEmpty() ) { 702 if ( !lastName.isEmpty() ) {
701 if ( !name.isEmpty() ) 703 if ( !name.isEmpty() )
702 name += " "; 704 name += " ";
703 name += lastName; 705 name += lastName;
704 } 706 }
705 if ( !suffix.isEmpty() ) { 707 if ( !suffix.isEmpty() ) {
706 if ( !name.isEmpty() ) 708 if ( !name.isEmpty() )
707 name += " "; 709 name += " ";
708 name += suffix; 710 name += suffix;
709 } 711 }
710 return name.simplifyWhiteSpace(); 712 return name.simplifyWhiteSpace();
711} 713}
712 714
713/*! 715/*!
714 Returns a list of the names of the children of the contact. 716 Returns a list of the names of the children of the contact.
715*/ 717*/
716QStringList OContact::childrenList() const 718QStringList OContact::childrenList() const
717{ 719{
718 return QStringList::split( " ", find( Qtopia::Children ) ); 720 return QStringList::split( " ", find( Qtopia::Children ) );
719} 721}
720 722
721/*! \fn void OContact::insertEmail( const QString &email ) 723/*! \fn void OContact::insertEmail( const QString &email )
722 724
723 Insert \a email into the email list. Ensures \a email can only be added 725 Insert \a email into the email list. Ensures \a email can only be added
724 once. If there is no default email address set, it sets it to the \a email. 726 once. If there is no default email address set, it sets it to the \a email.
725*/ 727*/
726 728
727/*! \fn void OContact::removeEmail( const QString &email ) 729/*! \fn void OContact::removeEmail( const QString &email )
728 730
729 Removes the \a email from the email list. If the default email was \a email, 731 Removes the \a email from the email list. If the default email was \a email,
730 then the default email address is assigned to the first email in the 732 then the default email address is assigned to the first email in the
731 email list 733 email list
732*/ 734*/
733 735
734/*! \fn void OContact::clearEmails() 736/*! \fn void OContact::clearEmails()
735 737
736 Clears the email list. 738 Clears the email list.
737 */ 739 */
738 740
739/*! \fn void OContact::insertEmails( const QStringList &emailList ) 741/*! \fn void OContact::insertEmails( const QStringList &emailList )
740 742
741 Appends the \a emailList to the exiting email list 743 Appends the \a emailList to the exiting email list
742 */ 744 */
743 745
744/*! 746/*!
745 Returns a list of email addresses belonging to the contact, including 747 Returns a list of email addresses belonging to the contact, including
746 the default email address. 748 the default email address.
747*/ 749*/
748QStringList OContact::emailList() const 750QStringList OContact::emailList() const
749{ 751{
750 QString emailStr = emails(); 752 QString emailStr = emails();
751 753
752 QStringList r; 754 QStringList r;
753 if ( !emailStr.isEmpty() ) { 755 if ( !emailStr.isEmpty() ) {
754 qDebug(" emailstr "); 756 qDebug(" emailstr ");
755 QStringList l = QStringList::split( emailSeparator(), emailStr ); 757 QStringList l = QStringList::split( emailSeparator(), emailStr );
756 for ( QStringList::ConstIterator it = l.begin();it != l.end();++it ) 758 for ( QStringList::ConstIterator it = l.begin();it != l.end();++it )
757 r += (*it).simplifyWhiteSpace(); 759 r += (*it).simplifyWhiteSpace();
758 } 760 }
759 761
760 return r; 762 return r;
761} 763}
762 764
763/*! 765/*!
764 \overload 766 \overload
765 767
766 Generates the string for the contact to be filed as from the first, 768 Generates the string for the contact to be filed as from the first,
767 middle and last name of the contact. 769 middle and last name of the contact.
768*/ 770*/
769void OContact::setFileAs() 771void OContact::setFileAs()
770{ 772{
771 QString lastName, firstName, middleName, fileas; 773 QString lastName, firstName, middleName, fileas;
@@ -934,715 +936,718 @@ QStringList OContact::trfields()
934 list.append( QObject::tr( "Children" ) ); 936 list.append( QObject::tr( "Children" ) );
935 937
936 list.append( QObject::tr( "Notes" ) ); 938 list.append( QObject::tr( "Notes" ) );
937 list.append( QObject::tr( "Groups" ) ); 939 list.append( QObject::tr( "Groups" ) );
938 940
939 return list; 941 return list;
940} 942}
941 943
942/*! 944/*!
943 \internal 945 \internal
944 Returns an untranslated list of field names for a contact. 946 Returns an untranslated list of field names for a contact.
945*/ 947*/
946QStringList OContact::untrfields() 948QStringList OContact::untrfields()
947{ 949{
948 QStringList list; 950 QStringList list;
949 951
950 list.append( "Name Title" ); 952 list.append( "Name Title" );
951 list.append( "First Name" ); 953 list.append( "First Name" );
952 list.append( "Middle Name" ); 954 list.append( "Middle Name" );
953 list.append( "Last Name" ); 955 list.append( "Last Name" );
954 list.append( "Suffix" ); 956 list.append( "Suffix" );
955 list.append( "File As" ); 957 list.append( "File As" );
956 958
957 list.append( "Job Title" ); 959 list.append( "Job Title" );
958 list.append( "Department" ); 960 list.append( "Department" );
959 list.append( "Company" ); 961 list.append( "Company" );
960 list.append( "Business Phone" ); 962 list.append( "Business Phone" );
961 list.append( "Business Fax" ); 963 list.append( "Business Fax" );
962 list.append( "Business Mobile" ); 964 list.append( "Business Mobile" );
963 965
964 list.append( "Default Email" ); 966 list.append( "Default Email" );
965 list.append( "Emails" ); 967 list.append( "Emails" );
966 968
967 list.append( "Home Phone" ); 969 list.append( "Home Phone" );
968 list.append( "Home Fax" ); 970 list.append( "Home Fax" );
969 list.append( "Home Mobile" ); 971 list.append( "Home Mobile" );
970 972
971 list.append( "Business Street" ); 973 list.append( "Business Street" );
972 list.append( "Business City" ); 974 list.append( "Business City" );
973 list.append( "Business State" ); 975 list.append( "Business State" );
974 list.append( "Business Zip" ); 976 list.append( "Business Zip" );
975 list.append( "Business Country" ); 977 list.append( "Business Country" );
976 list.append( "Business Pager" ); 978 list.append( "Business Pager" );
977 list.append( "Business WebPage" ); 979 list.append( "Business WebPage" );
978 980
979 list.append( "Office" ); 981 list.append( "Office" );
980 list.append( "Profession" ); 982 list.append( "Profession" );
981 list.append( "Assistant" ); 983 list.append( "Assistant" );
982 list.append( "Manager" ); 984 list.append( "Manager" );
983 985
984 list.append( "Home Street" ); 986 list.append( "Home Street" );
985 list.append( "Home City" ); 987 list.append( "Home City" );
986 list.append( "Home State" ); 988 list.append( "Home State" );
987 list.append( "Home Zip" ); 989 list.append( "Home Zip" );
988 list.append( "Home Country" ); 990 list.append( "Home Country" );
989 list.append( "Home Web Page" ); 991 list.append( "Home Web Page" );
990 992
991 list.append( "Spouse" ); 993 list.append( "Spouse" );
992 list.append( "Gender" ); 994 list.append( "Gender" );
993 list.append( "Birthday" ); 995 list.append( "Birthday" );
994 list.append( "Anniversary" ); 996 list.append( "Anniversary" );
995 list.append( "Nickname" ); 997 list.append( "Nickname" );
996 list.append( "Children" ); 998 list.append( "Children" );
997 999
998 list.append( "Notes" ); 1000 list.append( "Notes" );
999 list.append( "Groups" ); 1001 list.append( "Groups" );
1000 1002
1001 return list; 1003 return list;
1002} 1004}
1003 1005
1004/*! 1006/*!
1005 Sets the list of email address for contact to those contained in \a str. 1007 Sets the list of email address for contact to those contained in \a str.
1006 Email address should be separated by ';'s. 1008 Email address should be separated by ';'s.
1007*/ 1009*/
1008void OContact::setEmails( const QString &str ) 1010void OContact::setEmails( const QString &str )
1009{ 1011{
1010 replace( Qtopia::Emails, str ); 1012 replace( Qtopia::Emails, str );
1011 if ( str.isEmpty() ) 1013 if ( str.isEmpty() )
1012 setDefaultEmail( QString::null ); 1014 setDefaultEmail( QString::null );
1013} 1015}
1014 1016
1015/*! 1017/*!
1016 Sets the list of children for the contact to those contained in \a str. 1018 Sets the list of children for the contact to those contained in \a str.
1017*/ 1019*/
1018void OContact::setChildren( const QString &str ) 1020void OContact::setChildren( const QString &str )
1019{ 1021{
1020 replace( Qtopia::Children, str ); 1022 replace( Qtopia::Children, str );
1021} 1023}
1022 1024
1023// vcard conversion code 1025// vcard conversion code
1024/*! 1026/*!
1025 \internal 1027 \internal
1026*/ 1028*/
1027static inline VObject *safeAddPropValue( VObject *o, const char *prop, const QString &value ) 1029static inline VObject *safeAddPropValue( VObject *o, const char *prop, const QString &value )
1028{ 1030{
1029 VObject *ret = 0; 1031 VObject *ret = 0;
1030 if ( o && !value.isEmpty() ) 1032 if ( o && !value.isEmpty() )
1031 ret = addPropValue( o, prop, value.latin1() ); 1033 ret = addPropValue( o, prop, value.latin1() );
1032 return ret; 1034 return ret;
1033} 1035}
1034 1036
1035/*! 1037/*!
1036 \internal 1038 \internal
1037*/ 1039*/
1038static inline VObject *safeAddProp( VObject *o, const char *prop) 1040static inline VObject *safeAddProp( VObject *o, const char *prop)
1039{ 1041{
1040 VObject *ret = 0; 1042 VObject *ret = 0;
1041 if ( o ) 1043 if ( o )
1042 ret = addProp( o, prop ); 1044 ret = addProp( o, prop );
1043 return ret; 1045 return ret;
1044} 1046}
1045 1047
1046/*! 1048/*!
1047 \internal 1049 \internal
1048*/ 1050*/
1049static VObject *createVObject( const OContact &c ) 1051static VObject *createVObject( const OContact &c )
1050{ 1052{
1051 VObject *vcard = newVObject( VCCardProp ); 1053 VObject *vcard = newVObject( VCCardProp );
1052 safeAddPropValue( vcard, VCVersionProp, "2.1" ); 1054 safeAddPropValue( vcard, VCVersionProp, "2.1" );
1053 safeAddPropValue( vcard, VCLastRevisedProp, TimeConversion::toISO8601( QDateTime::currentDateTime() ) ); 1055 safeAddPropValue( vcard, VCLastRevisedProp, TimeConversion::toISO8601( QDateTime::currentDateTime() ) );
1054 safeAddPropValue( vcard, VCUniqueStringProp, QString::number(c.uid()) ); 1056 safeAddPropValue( vcard, VCUniqueStringProp, QString::number(c.uid()) );
1055 1057
1056 // full name 1058 // full name
1057 safeAddPropValue( vcard, VCFullNameProp, c.fullName() ); 1059 safeAddPropValue( vcard, VCFullNameProp, c.fullName() );
1058 1060
1059 // name properties 1061 // name properties
1060 VObject *name = safeAddProp( vcard, VCNameProp ); 1062 VObject *name = safeAddProp( vcard, VCNameProp );
1061 safeAddPropValue( name, VCFamilyNameProp, c.lastName() ); 1063 safeAddPropValue( name, VCFamilyNameProp, c.lastName() );
1062 safeAddPropValue( name, VCGivenNameProp, c.firstName() ); 1064 safeAddPropValue( name, VCGivenNameProp, c.firstName() );
1063 safeAddPropValue( name, VCAdditionalNamesProp, c.middleName() ); 1065 safeAddPropValue( name, VCAdditionalNamesProp, c.middleName() );
1064 safeAddPropValue( name, VCNamePrefixesProp, c.title() ); 1066 safeAddPropValue( name, VCNamePrefixesProp, c.title() );
1065 safeAddPropValue( name, VCNameSuffixesProp, c.suffix() ); 1067 safeAddPropValue( name, VCNameSuffixesProp, c.suffix() );
1066 1068
1067 // home properties 1069 // home properties
1068 VObject *home_adr= safeAddProp( vcard, VCAdrProp ); 1070 VObject *home_adr= safeAddProp( vcard, VCAdrProp );
1069 safeAddProp( home_adr, VCHomeProp ); 1071 safeAddProp( home_adr, VCHomeProp );
1070 safeAddPropValue( home_adr, VCStreetAddressProp, c.homeStreet() ); 1072 safeAddPropValue( home_adr, VCStreetAddressProp, c.homeStreet() );
1071 safeAddPropValue( home_adr, VCCityProp, c.homeCity() ); 1073 safeAddPropValue( home_adr, VCCityProp, c.homeCity() );
1072 safeAddPropValue( home_adr, VCRegionProp, c.homeState() ); 1074 safeAddPropValue( home_adr, VCRegionProp, c.homeState() );
1073 safeAddPropValue( home_adr, VCPostalCodeProp, c.homeZip() ); 1075 safeAddPropValue( home_adr, VCPostalCodeProp, c.homeZip() );
1074 safeAddPropValue( home_adr, VCCountryNameProp, c.homeCountry() ); 1076 safeAddPropValue( home_adr, VCCountryNameProp, c.homeCountry() );
1075 1077
1076 VObject *home_phone = safeAddPropValue( vcard, VCTelephoneProp, c.homePhone() ); 1078 VObject *home_phone = safeAddPropValue( vcard, VCTelephoneProp, c.homePhone() );
1077 safeAddProp( home_phone, VCHomeProp ); 1079 safeAddProp( home_phone, VCHomeProp );
1078 home_phone = safeAddPropValue( vcard, VCTelephoneProp, c.homeMobile() ); 1080 home_phone = safeAddPropValue( vcard, VCTelephoneProp, c.homeMobile() );
1079 safeAddProp( home_phone, VCHomeProp ); 1081 safeAddProp( home_phone, VCHomeProp );
1080 safeAddProp( home_phone, VCCellularProp ); 1082 safeAddProp( home_phone, VCCellularProp );
1081 home_phone = safeAddPropValue( vcard, VCTelephoneProp, c.homeFax() ); 1083 home_phone = safeAddPropValue( vcard, VCTelephoneProp, c.homeFax() );
1082 safeAddProp( home_phone, VCHomeProp ); 1084 safeAddProp( home_phone, VCHomeProp );
1083 safeAddProp( home_phone, VCFaxProp ); 1085 safeAddProp( home_phone, VCFaxProp );
1084 1086
1085 VObject *url = safeAddPropValue( vcard, VCURLProp, c.homeWebpage() ); 1087 VObject *url = safeAddPropValue( vcard, VCURLProp, c.homeWebpage() );
1086 safeAddProp( url, VCHomeProp ); 1088 safeAddProp( url, VCHomeProp );
1087 1089
1088 // work properties 1090 // work properties
1089 VObject *work_adr= safeAddProp( vcard, VCAdrProp ); 1091 VObject *work_adr= safeAddProp( vcard, VCAdrProp );
1090 safeAddProp( work_adr, VCWorkProp ); 1092 safeAddProp( work_adr, VCWorkProp );
1091 safeAddPropValue( work_adr, VCStreetAddressProp, c.businessStreet() ); 1093 safeAddPropValue( work_adr, VCStreetAddressProp, c.businessStreet() );
1092 safeAddPropValue( work_adr, VCCityProp, c.businessCity() ); 1094 safeAddPropValue( work_adr, VCCityProp, c.businessCity() );
1093 safeAddPropValue( work_adr, VCRegionProp, c.businessState() ); 1095 safeAddPropValue( work_adr, VCRegionProp, c.businessState() );
1094 safeAddPropValue( work_adr, VCPostalCodeProp, c.businessZip() ); 1096 safeAddPropValue( work_adr, VCPostalCodeProp, c.businessZip() );
1095 safeAddPropValue( work_adr, VCCountryNameProp, c.businessCountry() ); 1097 safeAddPropValue( work_adr, VCCountryNameProp, c.businessCountry() );
1096 1098
1097 VObject *work_phone = safeAddPropValue( vcard, VCTelephoneProp, c.businessPhone() ); 1099 VObject *work_phone = safeAddPropValue( vcard, VCTelephoneProp, c.businessPhone() );
1098 safeAddProp( work_phone, VCWorkProp ); 1100 safeAddProp( work_phone, VCWorkProp );
1099 work_phone = safeAddPropValue( vcard, VCTelephoneProp, c.businessMobile() ); 1101 work_phone = safeAddPropValue( vcard, VCTelephoneProp, c.businessMobile() );
1100 safeAddProp( work_phone, VCWorkProp ); 1102 safeAddProp( work_phone, VCWorkProp );
1101 safeAddProp( work_phone, VCCellularProp ); 1103 safeAddProp( work_phone, VCCellularProp );
1102 work_phone = safeAddPropValue( vcard, VCTelephoneProp, c.businessFax() ); 1104 work_phone = safeAddPropValue( vcard, VCTelephoneProp, c.businessFax() );
1103 safeAddProp( work_phone, VCWorkProp ); 1105 safeAddProp( work_phone, VCWorkProp );
1104 safeAddProp( work_phone, VCFaxProp ); 1106 safeAddProp( work_phone, VCFaxProp );
1105 work_phone = safeAddPropValue( vcard, VCTelephoneProp, c.businessPager() ); 1107 work_phone = safeAddPropValue( vcard, VCTelephoneProp, c.businessPager() );
1106 safeAddProp( work_phone, VCWorkProp ); 1108 safeAddProp( work_phone, VCWorkProp );
1107 safeAddProp( work_phone, VCPagerProp ); 1109 safeAddProp( work_phone, VCPagerProp );
1108 1110
1109 url = safeAddPropValue( vcard, VCURLProp, c.businessWebpage() ); 1111 url = safeAddPropValue( vcard, VCURLProp, c.businessWebpage() );
1110 safeAddProp( url, VCWorkProp ); 1112 safeAddProp( url, VCWorkProp );
1111 1113
1112 VObject *title = safeAddPropValue( vcard, VCTitleProp, c.jobTitle() ); 1114 VObject *title = safeAddPropValue( vcard, VCTitleProp, c.jobTitle() );
1113 safeAddProp( title, VCWorkProp ); 1115 safeAddProp( title, VCWorkProp );
1114 1116
1115 1117
1116 QStringList emails = c.emailList(); 1118 QStringList emails = c.emailList();
1117 emails.prepend( c.defaultEmail() ); 1119 emails.prepend( c.defaultEmail() );
1118 for( QStringList::Iterator it = emails.begin(); it != emails.end(); ++it ) { 1120 for( QStringList::Iterator it = emails.begin(); it != emails.end(); ++it ) {
1119 VObject *email = safeAddPropValue( vcard, VCEmailAddressProp, *it ); 1121 VObject *email = safeAddPropValue( vcard, VCEmailAddressProp, *it );
1120 safeAddProp( email, VCInternetProp ); 1122 safeAddProp( email, VCInternetProp );
1121 } 1123 }
1122 1124
1123 safeAddPropValue( vcard, VCNoteProp, c.notes() ); 1125 safeAddPropValue( vcard, VCNoteProp, c.notes() );
1124 1126
1125 // Exporting Birthday regarding RFC 2425 (5.8.4) 1127 // Exporting Birthday regarding RFC 2425 (5.8.4)
1126 if ( !c.birthday().isValid() ){ 1128 if ( c.birthday().isValid() ){
1127 QString birthd_rfc2425 = QString("%1-%2-%3") 1129 QString birthd_rfc2425 = QString("%1-%2-%3")
1128 .arg( c.birthday().year() ) 1130 .arg( c.birthday().year() )
1129 .arg( c.birthday().month(), 2 ) 1131 .arg( c.birthday().month(), 2 )
1130 .arg( c.birthday().day(), 2 ); 1132 .arg( c.birthday().day(), 2 );
1131 // Now replace spaces with "0"... 1133 // Now replace spaces with "0"...
1132 int pos = 0; 1134 int pos = 0;
1133 while ( ( pos = birthd_rfc2425.find (' ') ) > 0 ) 1135 while ( ( pos = birthd_rfc2425.find (' ') ) > 0 )
1134 birthd_rfc2425.replace( pos, 1, "0" ); 1136 birthd_rfc2425.replace( pos, 1, "0" );
1135 1137
1136 qWarning("Exporting birthday as: %s", birthd_rfc2425.latin1()); 1138 qWarning("Exporting birthday as: %s", birthd_rfc2425.latin1());
1137 safeAddPropValue( vcard, VCBirthDateProp, birthd_rfc2425.latin1() ); 1139 safeAddPropValue( vcard, VCBirthDateProp, birthd_rfc2425.latin1() );
1138 } 1140 }
1139 1141
1140 if ( !c.company().isEmpty() || !c.department().isEmpty() || !c.office().isEmpty() ) { 1142 if ( !c.company().isEmpty() || !c.department().isEmpty() || !c.office().isEmpty() ) {
1141 VObject *org = safeAddProp( vcard, VCOrgProp ); 1143 VObject *org = safeAddProp( vcard, VCOrgProp );
1142 safeAddPropValue( org, VCOrgNameProp, c.company() ); 1144 safeAddPropValue( org, VCOrgNameProp, c.company() );
1143 safeAddPropValue( org, VCOrgUnitProp, c.department() ); 1145 safeAddPropValue( org, VCOrgUnitProp, c.department() );
1144 safeAddPropValue( org, VCOrgUnit2Prop, c.office() ); 1146 safeAddPropValue( org, VCOrgUnit2Prop, c.office() );
1145 } 1147 }
1146 1148
1147 // some values we have to export as custom fields 1149 // some values we have to export as custom fields
1148 safeAddPropValue( vcard, "X-Qtopia-Profession", c.profession() ); 1150 safeAddPropValue( vcard, "X-Qtopia-Profession", c.profession() );
1149 safeAddPropValue( vcard, "X-Qtopia-Manager", c.manager() ); 1151 safeAddPropValue( vcard, "X-Qtopia-Manager", c.manager() );
1150 safeAddPropValue( vcard, "X-Qtopia-Assistant", c.assistant() ); 1152 safeAddPropValue( vcard, "X-Qtopia-Assistant", c.assistant() );
1151 1153
1152 safeAddPropValue( vcard, "X-Qtopia-Spouse", c.spouse() ); 1154 safeAddPropValue( vcard, "X-Qtopia-Spouse", c.spouse() );
1153 safeAddPropValue( vcard, "X-Qtopia-Gender", c.gender() ); 1155 safeAddPropValue( vcard, "X-Qtopia-Gender", c.gender() );
1154 safeAddPropValue( vcard, "X-Qtopia-Anniversary", TimeConversion::toString( c.anniversary() ) ); 1156 safeAddPropValue( vcard, "X-Qtopia-Anniversary", TimeConversion::toString( c.anniversary() ) );
1155 safeAddPropValue( vcard, "X-Qtopia-Nickname", c.nickname() ); 1157 safeAddPropValue( vcard, "X-Qtopia-Nickname", c.nickname() );
1156 safeAddPropValue( vcard, "X-Qtopia-Children", c.children() ); 1158 safeAddPropValue( vcard, "X-Qtopia-Children", c.children() );
1157 1159
1158 return vcard; 1160 return vcard;
1159} 1161}
1160 1162
1161 1163
1162/*! 1164/*!
1163 \internal 1165 \internal
1164*/ 1166*/
1165static QDate convVCardDateToDate( const QString& datestr ) 1167static QDate convVCardDateToDate( const QString& datestr )
1166{ 1168{
1167 int monthPos = datestr.find('-'); 1169 int monthPos = datestr.find('-');
1168 int dayPos = datestr.find('-', monthPos+1 ); 1170 int dayPos = datestr.find('-', monthPos+1 );
1169 int sep_ignore = 1; 1171 int sep_ignore = 1;
1170 if ( monthPos == -1 || dayPos == -1 ) { 1172 if ( monthPos == -1 || dayPos == -1 ) {
1171 qDebug("fromString didn't find - in str = %s; mpos = %d ypos = %d", datestr.latin1(), monthPos, dayPos ); 1173 qDebug("fromString didn't find - in str = %s; mpos = %d ypos = %d", datestr.latin1(), monthPos, dayPos );
1172 // Ok.. Outlook is violating ISO 8601, therefore we will try to read their format ( YYYYMMDD ) 1174 // Ok.. No "-" found, therefore we will try to read other format ( YYYYMMDD )
1173 monthPos = 4; 1175 if ( datestr.length() == 8 ){
1174 dayPos = 6; 1176 monthPos = 4;
1175 sep_ignore = 0; 1177 dayPos = 6;
1176 qDebug("Try with follwing positions str = %s; mpos = %d ypos = %d", datestr.latin1(), monthPos, dayPos ); 1178 sep_ignore = 0;
1179 qDebug("Try with follwing positions str = %s; mpos = %d ypos = %d", datestr.latin1(), monthPos, dayPos );
1180 } else {
1181 return QDate();
1182 }
1177 } 1183 }
1178 int y = datestr.left( monthPos ).toInt(); 1184 int y = datestr.left( monthPos ).toInt();
1179 int m = datestr.mid( monthPos + sep_ignore, dayPos - monthPos - sep_ignore ).toInt(); 1185 int m = datestr.mid( monthPos + sep_ignore, dayPos - monthPos - sep_ignore ).toInt();
1180 int d = datestr.mid( dayPos + sep_ignore ).toInt(); 1186 int d = datestr.mid( dayPos + sep_ignore ).toInt();
1181 qDebug("TimeConversion::fromString ymd = %s => %d %d %d; mpos = %d ypos = %d", datestr.latin1(), y, m, d, monthPos, dayPos); 1187 qDebug("TimeConversion::fromString ymd = %s => %d %d %d; mpos = %d ypos = %d", datestr.latin1(), y, m, d, monthPos, dayPos);
1182 QDate date ( y,m,d ); 1188 QDate date ( y,m,d );
1183 return date; 1189 return date;
1184} 1190}
1185 1191
1186static OContact parseVObject( VObject *obj ) 1192static OContact parseVObject( VObject *obj )
1187{ 1193{
1188 OContact c; 1194 OContact c;
1189 1195
1190 VObjectIterator it; 1196 VObjectIterator it;
1191 initPropIterator( &it, obj ); 1197 initPropIterator( &it, obj );
1192 while( moreIteration( &it ) ) { 1198 while( moreIteration( &it ) ) {
1193 VObject *o = nextVObject( &it ); 1199 VObject *o = nextVObject( &it );
1194 QCString name = vObjectName( o ); 1200 QCString name = vObjectName( o );
1195 QCString value = vObjectStringZValue( o ); 1201 QCString value = vObjectStringZValue( o );
1196 if ( name == VCNameProp ) { 1202 if ( name == VCNameProp ) {
1197 VObjectIterator nit; 1203 VObjectIterator nit;
1198 initPropIterator( &nit, o ); 1204 initPropIterator( &nit, o );
1199 while( moreIteration( &nit ) ) { 1205 while( moreIteration( &nit ) ) {
1200 VObject *o = nextVObject( &nit ); 1206 VObject *o = nextVObject( &nit );
1201 QCString name = vObjectTypeInfo( o ); 1207 QCString name = vObjectTypeInfo( o );
1202 QString value = vObjectStringZValue( o ); 1208 QString value = vObjectStringZValue( o );
1203 if ( name == VCNamePrefixesProp ) 1209 if ( name == VCNamePrefixesProp )
1204 c.setTitle( value ); 1210 c.setTitle( value );
1205 else if ( name == VCNameSuffixesProp ) 1211 else if ( name == VCNameSuffixesProp )
1206 c.setSuffix( value ); 1212 c.setSuffix( value );
1207 else if ( name == VCFamilyNameProp ) 1213 else if ( name == VCFamilyNameProp )
1208 c.setLastName( value ); 1214 c.setLastName( value );
1209 else if ( name == VCGivenNameProp ) 1215 else if ( name == VCGivenNameProp )
1210 c.setFirstName( value ); 1216 c.setFirstName( value );
1211 else if ( name == VCAdditionalNamesProp ) 1217 else if ( name == VCAdditionalNamesProp )
1212 c.setMiddleName( value ); 1218 c.setMiddleName( value );
1213 } 1219 }
1214 } 1220 }
1215 else if ( name == VCAdrProp ) { 1221 else if ( name == VCAdrProp ) {
1216 bool work = TRUE; // default address is work address 1222 bool work = TRUE; // default address is work address
1217 QString street; 1223 QString street;
1218 QString city; 1224 QString city;
1219 QString region; 1225 QString region;
1220 QString postal; 1226 QString postal;
1221 QString country; 1227 QString country;
1222 1228
1223 VObjectIterator nit; 1229 VObjectIterator nit;
1224 initPropIterator( &nit, o ); 1230 initPropIterator( &nit, o );
1225 while( moreIteration( &nit ) ) { 1231 while( moreIteration( &nit ) ) {
1226 VObject *o = nextVObject( &nit ); 1232 VObject *o = nextVObject( &nit );
1227 QCString name = vObjectName( o ); 1233 QCString name = vObjectName( o );
1228 QString value = vObjectStringZValue( o ); 1234 QString value = vObjectStringZValue( o );
1229 if ( name == VCHomeProp ) 1235 if ( name == VCHomeProp )
1230 work = FALSE; 1236 work = FALSE;
1231 else if ( name == VCWorkProp ) 1237 else if ( name == VCWorkProp )
1232 work = TRUE; 1238 work = TRUE;
1233 else if ( name == VCStreetAddressProp ) 1239 else if ( name == VCStreetAddressProp )
1234 street = value; 1240 street = value;
1235 else if ( name == VCCityProp ) 1241 else if ( name == VCCityProp )
1236 city = value; 1242 city = value;
1237 else if ( name == VCRegionProp ) 1243 else if ( name == VCRegionProp )
1238 region = value; 1244 region = value;
1239 else if ( name == VCPostalCodeProp ) 1245 else if ( name == VCPostalCodeProp )
1240 postal = value; 1246 postal = value;
1241 else if ( name == VCCountryNameProp ) 1247 else if ( name == VCCountryNameProp )
1242 country = value; 1248 country = value;
1243 } 1249 }
1244 if ( work ) { 1250 if ( work ) {
1245 c.setBusinessStreet( street ); 1251 c.setBusinessStreet( street );
1246 c.setBusinessCity( city ); 1252 c.setBusinessCity( city );
1247 c.setBusinessCountry( country ); 1253 c.setBusinessCountry( country );
1248 c.setBusinessZip( postal ); 1254 c.setBusinessZip( postal );
1249 c.setBusinessState( region ); 1255 c.setBusinessState( region );
1250 } else { 1256 } else {
1251 c.setHomeStreet( street ); 1257 c.setHomeStreet( street );
1252 c.setHomeCity( city ); 1258 c.setHomeCity( city );
1253 c.setHomeCountry( country ); 1259 c.setHomeCountry( country );
1254 c.setHomeZip( postal ); 1260 c.setHomeZip( postal );
1255 c.setHomeState( region ); 1261 c.setHomeState( region );
1256 } 1262 }
1257 } 1263 }
1258 else if ( name == VCTelephoneProp ) { 1264 else if ( name == VCTelephoneProp ) {
1259 enum { 1265 enum {
1260 HOME = 0x01, 1266 HOME = 0x01,
1261 WORK = 0x02, 1267 WORK = 0x02,
1262 VOICE = 0x04, 1268 VOICE = 0x04,
1263 CELL = 0x08, 1269 CELL = 0x08,
1264 FAX = 0x10, 1270 FAX = 0x10,
1265 PAGER = 0x20, 1271 PAGER = 0x20,
1266 UNKNOWN = 0x80 1272 UNKNOWN = 0x80
1267 }; 1273 };
1268 int type = 0; 1274 int type = 0;
1269 1275
1270 VObjectIterator nit; 1276 VObjectIterator nit;
1271 initPropIterator( &nit, o ); 1277 initPropIterator( &nit, o );
1272 while( moreIteration( &nit ) ) { 1278 while( moreIteration( &nit ) ) {
1273 VObject *o = nextVObject( &nit ); 1279 VObject *o = nextVObject( &nit );
1274 QCString name = vObjectTypeInfo( o ); 1280 QCString name = vObjectTypeInfo( o );
1275 if ( name == VCHomeProp ) 1281 if ( name == VCHomeProp )
1276 type |= HOME; 1282 type |= HOME;
1277 else if ( name == VCWorkProp ) 1283 else if ( name == VCWorkProp )
1278 type |= WORK; 1284 type |= WORK;
1279 else if ( name == VCVoiceProp ) 1285 else if ( name == VCVoiceProp )
1280 type |= VOICE; 1286 type |= VOICE;
1281 else if ( name == VCCellularProp ) 1287 else if ( name == VCCellularProp )
1282 type |= CELL; 1288 type |= CELL;
1283 else if ( name == VCFaxProp ) 1289 else if ( name == VCFaxProp )
1284 type |= FAX; 1290 type |= FAX;
1285 else if ( name == VCPagerProp ) 1291 else if ( name == VCPagerProp )
1286 type |= PAGER; 1292 type |= PAGER;
1287 else if ( name == VCPreferredProp ) 1293 else if ( name == VCPreferredProp )
1288 ; 1294 ;
1289 else 1295 else
1290 type |= UNKNOWN; 1296 type |= UNKNOWN;
1291 } 1297 }
1292 if ( (type & UNKNOWN) != UNKNOWN ) { 1298 if ( (type & UNKNOWN) != UNKNOWN ) {
1293 if ( ( type & (HOME|WORK) ) == 0 ) // default 1299 if ( ( type & (HOME|WORK) ) == 0 ) // default
1294 type |= HOME; 1300 type |= HOME;
1295 if ( ( type & (VOICE|CELL|FAX|PAGER) ) == 0 ) // default 1301 if ( ( type & (VOICE|CELL|FAX|PAGER) ) == 0 ) // default
1296 type |= VOICE; 1302 type |= VOICE;
1297 1303
1298 if ( (type & (VOICE|HOME) ) == (VOICE|HOME) ) 1304 if ( (type & (VOICE|HOME) ) == (VOICE|HOME) )
1299 c.setHomePhone( value ); 1305 c.setHomePhone( value );
1300 if ( ( type & (FAX|HOME) ) == (FAX|HOME) ) 1306 if ( ( type & (FAX|HOME) ) == (FAX|HOME) )
1301 c.setHomeFax( value ); 1307 c.setHomeFax( value );
1302 if ( ( type & (CELL|HOME) ) == (CELL|HOME) ) 1308 if ( ( type & (CELL|HOME) ) == (CELL|HOME) )
1303 c.setHomeMobile( value ); 1309 c.setHomeMobile( value );
1304 if ( ( type & (VOICE|WORK) ) == (VOICE|WORK) ) 1310 if ( ( type & (VOICE|WORK) ) == (VOICE|WORK) )
1305 c.setBusinessPhone( value ); 1311 c.setBusinessPhone( value );
1306 if ( ( type & (FAX|WORK) ) == (FAX|WORK) ) 1312 if ( ( type & (FAX|WORK) ) == (FAX|WORK) )
1307 c.setBusinessFax( value ); 1313 c.setBusinessFax( value );
1308 if ( ( type & (CELL|WORK) ) == (CELL|WORK) ) 1314 if ( ( type & (CELL|WORK) ) == (CELL|WORK) )
1309 c.setBusinessMobile( value ); 1315 c.setBusinessMobile( value );
1310 if ( ( type & (PAGER|WORK) ) == (PAGER|WORK) ) 1316 if ( ( type & (PAGER|WORK) ) == (PAGER|WORK) )
1311 c.setBusinessPager( value ); 1317 c.setBusinessPager( value );
1312 } 1318 }
1313 } 1319 }
1314 else if ( name == VCEmailAddressProp ) { 1320 else if ( name == VCEmailAddressProp ) {
1315 QString email = vObjectStringZValue( o ); 1321 QString email = vObjectStringZValue( o );
1316 bool valid = TRUE; 1322 bool valid = TRUE;
1317 VObjectIterator nit; 1323 VObjectIterator nit;
1318 initPropIterator( &nit, o ); 1324 initPropIterator( &nit, o );
1319 while( moreIteration( &nit ) ) { 1325 while( moreIteration( &nit ) ) {
1320 VObject *o = nextVObject( &nit ); 1326 VObject *o = nextVObject( &nit );
1321 QCString name = vObjectTypeInfo( o ); 1327 QCString name = vObjectTypeInfo( o );
1322 if ( name != VCInternetProp && name != VCHomeProp && 1328 if ( name != VCInternetProp && name != VCHomeProp &&
1323 name != VCWorkProp && 1329 name != VCWorkProp &&
1324 name != VCPreferredProp ) 1330 name != VCPreferredProp )
1325 // ### preffered should map to default email 1331 // ### preffered should map to default email
1326 valid = FALSE; 1332 valid = FALSE;
1327 } 1333 }
1328 if ( valid ) { 1334 if ( valid ) {
1329 c.insertEmail( email ); 1335 c.insertEmail( email );
1330 } 1336 }
1331 } 1337 }
1332 else if ( name == VCURLProp ) { 1338 else if ( name == VCURLProp ) {
1333 VObjectIterator nit; 1339 VObjectIterator nit;
1334 initPropIterator( &nit, o ); 1340 initPropIterator( &nit, o );
1335 while( moreIteration( &nit ) ) { 1341 while( moreIteration( &nit ) ) {
1336 VObject *o = nextVObject( &nit ); 1342 VObject *o = nextVObject( &nit );
1337 QCString name = vObjectTypeInfo( o ); 1343 QCString name = vObjectTypeInfo( o );
1338 if ( name == VCHomeProp ) 1344 if ( name == VCHomeProp )
1339 c.setHomeWebpage( value ); 1345 c.setHomeWebpage( value );
1340 else if ( name == VCWorkProp ) 1346 else if ( name == VCWorkProp )
1341 c.setBusinessWebpage( value ); 1347 c.setBusinessWebpage( value );
1342 } 1348 }
1343 } 1349 }
1344 else if ( name == VCOrgProp ) { 1350 else if ( name == VCOrgProp ) {
1345 VObjectIterator nit; 1351 VObjectIterator nit;
1346 initPropIterator( &nit, o ); 1352 initPropIterator( &nit, o );
1347 while( moreIteration( &nit ) ) { 1353 while( moreIteration( &nit ) ) {
1348 VObject *o = nextVObject( &nit ); 1354 VObject *o = nextVObject( &nit );
1349 QCString name = vObjectName( o ); 1355 QCString name = vObjectName( o );
1350 QString value = vObjectStringZValue( o ); 1356 QString value = vObjectStringZValue( o );
1351 if ( name == VCOrgNameProp ) 1357 if ( name == VCOrgNameProp )
1352 c.setCompany( value ); 1358 c.setCompany( value );
1353 else if ( name == VCOrgUnitProp ) 1359 else if ( name == VCOrgUnitProp )
1354 c.setDepartment( value ); 1360 c.setDepartment( value );
1355 else if ( name == VCOrgUnit2Prop ) 1361 else if ( name == VCOrgUnit2Prop )
1356 c.setOffice( value ); 1362 c.setOffice( value );
1357 } 1363 }
1358 } 1364 }
1359 else if ( name == VCTitleProp ) { 1365 else if ( name == VCTitleProp ) {
1360 c.setJobTitle( value ); 1366 c.setJobTitle( value );
1361 } 1367 }
1362 else if ( name == "X-Qtopia-Profession" ) { 1368 else if ( name == "X-Qtopia-Profession" ) {
1363 c.setProfession( value ); 1369 c.setProfession( value );
1364 } 1370 }
1365 else if ( name == "X-Qtopia-Manager" ) { 1371 else if ( name == "X-Qtopia-Manager" ) {
1366 c.setManager( value ); 1372 c.setManager( value );
1367 } 1373 }
1368 else if ( name == "X-Qtopia-Assistant" ) { 1374 else if ( name == "X-Qtopia-Assistant" ) {
1369 c.setAssistant( value ); 1375 c.setAssistant( value );
1370 } 1376 }
1371 else if ( name == "X-Qtopia-Spouse" ) { 1377 else if ( name == "X-Qtopia-Spouse" ) {
1372 c.setSpouse( value ); 1378 c.setSpouse( value );
1373 } 1379 }
1374 else if ( name == "X-Qtopia-Gender" ) { 1380 else if ( name == "X-Qtopia-Gender" ) {
1375 c.setGender( value ); 1381 c.setGender( value );
1376 } 1382 }
1377 else if ( name == "X-Qtopia-Anniversary" ) { 1383 else if ( name == "X-Qtopia-Anniversary" ) {
1378 c.setAnniversary( TimeConversion::fromString( value ) ); 1384 c.setAnniversary( TimeConversion::fromString( value ) );
1379 } 1385 }
1380 else if ( name == "X-Qtopia-Nickname" ) { 1386 else if ( name == "X-Qtopia-Nickname" ) {
1381 c.setNickname( value ); 1387 c.setNickname( value );
1382 } 1388 }
1383 else if ( name == "X-Qtopia-Children" ) { 1389 else if ( name == "X-Qtopia-Children" ) {
1384 c.setChildren( value ); 1390 c.setChildren( value );
1385 } 1391 }
1386 else if ( name == VCBirthDateProp ) { 1392 else if ( name == VCBirthDateProp ) {
1387 // Reading Birthdate regarding RFC 2425 (5.8.4) 1393 // Reading Birthdate regarding RFC 2425 (5.8.4)
1388 c.setBirthday( convVCardDateToDate( value ) ); 1394 c.setBirthday( convVCardDateToDate( value ) );
1389 1395
1390 } 1396 }
1391 1397
1392#if 0 1398#if 0
1393 else { 1399 else {
1394 printf("Name: %s, value=%s\n", name.data(), vObjectStringZValue( o ) ); 1400 printf("Name: %s, value=%s\n", name.data(), vObjectStringZValue( o ) );
1395 VObjectIterator nit; 1401 VObjectIterator nit;
1396 initPropIterator( &nit, o ); 1402 initPropIterator( &nit, o );
1397 while( moreIteration( &nit ) ) { 1403 while( moreIteration( &nit ) ) {
1398 VObject *o = nextVObject( &nit ); 1404 VObject *o = nextVObject( &nit );
1399 QCString name = vObjectName( o ); 1405 QCString name = vObjectName( o );
1400 QString value = vObjectStringZValue( o ); 1406 QString value = vObjectStringZValue( o );
1401 printf(" subprop: %s = %s\n", name.data(), value.latin1() ); 1407 printf(" subprop: %s = %s\n", name.data(), value.latin1() );
1402 } 1408 }
1403 } 1409 }
1404#endif 1410#endif
1405 } 1411 }
1406 c.setFileAs(); 1412 c.setFileAs();
1407 return c; 1413 return c;
1408} 1414}
1409 1415
1410/*! 1416/*!
1411 Writes the list of \a contacts as a set of VCards to the file \a filename. 1417 Writes the list of \a contacts as a set of VCards to the file \a filename.
1412*/ 1418*/
1413void OContact::writeVCard( const QString &filename, const QValueList<OContact> &contacts) 1419void OContact::writeVCard( const QString &filename, const QValueList<OContact> &contacts)
1414{ 1420{
1415 QFileDirect f( filename.utf8().data() ); 1421 QFileDirect f( filename.utf8().data() );
1416 if ( !f.open( IO_WriteOnly ) ) { 1422 if ( !f.open( IO_WriteOnly ) ) {
1417 qWarning("Unable to open vcard write"); 1423 qWarning("Unable to open vcard write");
1418 return; 1424 return;
1419 } 1425 }
1420 1426
1421 QValueList<OContact>::ConstIterator it; 1427 QValueList<OContact>::ConstIterator it;
1422 for( it = contacts.begin(); it != contacts.end(); ++it ) { 1428 for( it = contacts.begin(); it != contacts.end(); ++it ) {
1423 VObject *obj = createVObject( *it ); 1429 VObject *obj = createVObject( *it );
1424 writeVObject(f.directHandle() , obj ); 1430 writeVObject(f.directHandle() , obj );
1425 cleanVObject( obj ); 1431 cleanVObject( obj );
1426 } 1432 }
1427 cleanStrTbl(); 1433 cleanStrTbl();
1428} 1434}
1429 1435
1430/*! 1436/*!
1431 writes \a contact as a VCard to the file \a filename. 1437 writes \a contact as a VCard to the file \a filename.
1432*/ 1438*/
1433void OContact::writeVCard( const QString &filename, const OContact &contact) 1439void OContact::writeVCard( const QString &filename, const OContact &contact)
1434{ 1440{
1435 QFileDirect f( filename.utf8().data() ); 1441 QFileDirect f( filename.utf8().data() );
1436 if ( !f.open( IO_WriteOnly ) ) { 1442 if ( !f.open( IO_WriteOnly ) ) {
1437 qWarning("Unable to open vcard write"); 1443 qWarning("Unable to open vcard write");
1438 return; 1444 return;
1439 } 1445 }
1440 1446
1441 VObject *obj = createVObject( contact ); 1447 VObject *obj = createVObject( contact );
1442 writeVObject( f.directHandle() , obj ); 1448 writeVObject( f.directHandle() , obj );
1443 cleanVObject( obj ); 1449 cleanVObject( obj );
1444 1450
1445 cleanStrTbl(); 1451 cleanStrTbl();
1446} 1452}
1447 1453
1448/*! 1454/*!
1449 Returns the set of contacts read as VCards from the file \a filename. 1455 Returns the set of contacts read as VCards from the file \a filename.
1450*/ 1456*/
1451QValueList<OContact> OContact::readVCard( const QString &filename ) 1457QValueList<OContact> OContact::readVCard( const QString &filename )
1452{ 1458{
1453 qDebug("trying to open %s, exists=%d", filename.utf8().data(), QFileInfo( filename.utf8().data() ).size() ); 1459 qDebug("trying to open %s, exists=%d", filename.utf8().data(), QFileInfo( filename.utf8().data() ).size() );
1454 VObject *obj = Parse_MIME_FromFileName( (char *)filename.utf8().data() ); 1460 VObject *obj = Parse_MIME_FromFileName( (char *)filename.utf8().data() );
1455 1461
1456 qDebug("vobject = %p", obj ); 1462 qDebug("vobject = %p", obj );
1457 1463
1458 QValueList<OContact> contacts; 1464 QValueList<OContact> contacts;
1459 1465
1460 while ( obj ) { 1466 while ( obj ) {
1461 contacts.append( parseVObject( obj ) ); 1467 contacts.append( parseVObject( obj ) );
1462 1468
1463 VObject *t = obj; 1469 VObject *t = obj;
1464 obj = nextVObjectInList(obj); 1470 obj = nextVObjectInList(obj);
1465 cleanVObject( t ); 1471 cleanVObject( t );
1466 } 1472 }
1467 1473
1468 return contacts; 1474 return contacts;
1469} 1475}
1470 1476
1471/*! 1477/*!
1472 Returns TRUE if the contact matches the regular expression \a regexp. 1478 Returns TRUE if the contact matches the regular expression \a regexp.
1473 Otherwise returns FALSE. 1479 Otherwise returns FALSE.
1474*/ 1480*/
1475bool OContact::match( const QString &regexp ) const 1481bool OContact::match( const QString &regexp ) const
1476{ 1482{
1477 return match(QRegExp(regexp)); 1483 return match(QRegExp(regexp));
1478} 1484}
1479 1485
1480/*! 1486/*!
1481 \overload 1487 \overload
1482 Returns TRUE if the contact matches the regular expression \a regexp. 1488 Returns TRUE if the contact matches the regular expression \a regexp.
1483 Otherwise returns FALSE. 1489 Otherwise returns FALSE.
1484*/ 1490*/
1485bool OContact::match( const QRegExp &r ) const 1491bool OContact::match( const QRegExp &r ) const
1486{ 1492{
1487 bool match; 1493 bool match;
1488 match = false; 1494 match = false;
1489 QMap<int, QString>::ConstIterator it; 1495 QMap<int, QString>::ConstIterator it;
1490 for ( it = mMap.begin(); it != mMap.end(); ++it ) { 1496 for ( it = mMap.begin(); it != mMap.end(); ++it ) {
1491 if ( (*it).find( r ) > -1 ) { 1497 if ( (*it).find( r ) > -1 ) {
1492 match = true; 1498 match = true;
1493 break; 1499 break;
1494 } 1500 }
1495 } 1501 }
1496 return match; 1502 return match;
1497} 1503}
1498 1504
1499 1505
1500QString OContact::toShortText() const 1506QString OContact::toShortText() const
1501{ 1507{
1502 return ( fullName() ); 1508 return ( fullName() );
1503} 1509}
1504QString OContact::type() const 1510QString OContact::type() const
1505{ 1511{
1506 return QString::fromLatin1( "OContact" ); 1512 return QString::fromLatin1( "OContact" );
1507} 1513}
1508 1514
1509// Definition is missing ! (se) 1515// Definition is missing ! (se)
1510QMap<QString,QString> OContact::toExtraMap() const 1516QMap<QString,QString> OContact::toExtraMap() const
1511{ 1517{
1512 qWarning ("Function not implemented: OContact::toExtraMap()"); 1518 qWarning ("Function not implemented: OContact::toExtraMap()");
1513 QMap <QString,QString> useless; 1519 QMap <QString,QString> useless;
1514 return useless; 1520 return useless;
1515} 1521}
1516 1522
1517class QString OContact::recordField( int pos ) const 1523class QString OContact::recordField( int pos ) const
1518{ 1524{
1519 QStringList SLFIELDS = fields(); // ?? why this ? (se) 1525 QStringList SLFIELDS = fields(); // ?? why this ? (se)
1520 return SLFIELDS[pos]; 1526 return SLFIELDS[pos];
1521} 1527}
1522 1528
1523// In future releases, we should store birthday and anniversary 1529// In future releases, we should store birthday and anniversary
1524// internally as QDate instead of QString ! 1530// internally as QDate instead of QString !
1525// QString is always too complicate to interprete (DD.MM.YY, DD/MM/YY, MM/DD/YY, etc..)(se) 1531// QString is always too complicate to interprete (DD.MM.YY, DD/MM/YY, MM/DD/YY, etc..)(se)
1526 1532
1527/*! \fn void OContact::setBirthday( const QDate& date ) 1533/*! \fn void OContact::setBirthday( const QDate& date )
1528 Sets the birthday for the contact to \a date. 1534 Sets the birthday for the contact to \a date.
1529*/ 1535*/
1530void OContact::setBirthday( const QDate &v ) 1536void OContact::setBirthday( const QDate &v )
1531{ 1537{
1532 if ( ( !v.isNull() ) && ( v.isValid() ) ) 1538 if ( ( !v.isNull() ) && ( v.isValid() ) )
1533 replace( Qtopia::Birthday, TimeConversion::toString( v ) ); 1539 replace( Qtopia::Birthday, TimeConversion::toString( v ) );
1534 1540
1535} 1541}
1536 1542
1537 1543
1538/*! \fn void OContact::setAnniversary( const QDate &date ) 1544/*! \fn void OContact::setAnniversary( const QDate &date )
1539 Sets the anniversary of the contact to \a date. 1545 Sets the anniversary of the contact to \a date.
1540*/ 1546*/
1541void OContact::setAnniversary( const QDate &v ) 1547void OContact::setAnniversary( const QDate &v )
1542{ 1548{
1543 if ( ( !v.isNull() ) && ( v.isValid() ) ) 1549 if ( ( !v.isNull() ) && ( v.isValid() ) )
1544 replace( Qtopia::Anniversary, TimeConversion::toString( v ) ); 1550 replace( Qtopia::Anniversary, TimeConversion::toString( v ) );
1545} 1551}
1546 1552
1547/*! \fn QDate OContact::birthday() const 1553/*! \fn QDate OContact::birthday() const
1548 Returns the birthday of the contact. 1554 Returns the birthday of the contact.
1549*/ 1555*/
1550QDate OContact::birthday() const 1556QDate OContact::birthday() const
1551{ 1557{
1552 QDate empty;
1553 QString str = find( Qtopia::Birthday ); 1558 QString str = find( Qtopia::Birthday );
1554 qWarning ("Birthday %s", str.latin1() ); 1559 qWarning ("Birthday %s", str.latin1() );
1555 if ( !str.isEmpty() ) 1560 if ( !str.isEmpty() )
1556 return TimeConversion::fromString ( str ); 1561 return TimeConversion::fromString ( str );
1557 else 1562 else
1558 return empty; 1563 return QDate();
1559} 1564}
1560 1565
1561 1566
1562/*! \fn QDate OContact::anniversary() const 1567/*! \fn QDate OContact::anniversary() const
1563 Returns the anniversary of the contact. 1568 Returns the anniversary of the contact.
1564*/ 1569*/
1565QDate OContact::anniversary() const 1570QDate OContact::anniversary() const
1566{ 1571{
1567 QDate empty; 1572 QDate empty;
1568 QString str = find( Qtopia::Anniversary ); 1573 QString str = find( Qtopia::Anniversary );
1569 qWarning ("Anniversary %s", str.latin1() ); 1574 qWarning ("Anniversary %s", str.latin1() );
1570 if ( !str.isEmpty() ) 1575 if ( !str.isEmpty() )
1571 return TimeConversion::fromString ( str ); 1576 return TimeConversion::fromString ( str );
1572 else 1577 else
1573 return empty; 1578 return empty;
1574} 1579}
1575 1580
1576 1581
1577void OContact::insertEmail( const QString &v ) 1582void OContact::insertEmail( const QString &v )
1578{ 1583{
1579 //qDebug("insertEmail %s", v.latin1()); 1584 //qDebug("insertEmail %s", v.latin1());
1580 QString e = v.simplifyWhiteSpace(); 1585 QString e = v.simplifyWhiteSpace();
1581 QString def = defaultEmail(); 1586 QString def = defaultEmail();
1582 1587
1583 // if no default, set it as the default email and don't insert 1588 // if no default, set it as the default email and don't insert
1584 if ( def.isEmpty() ) { 1589 if ( def.isEmpty() ) {
1585 setDefaultEmail( e ); // will insert into the list for us 1590 setDefaultEmail( e ); // will insert into the list for us
1586 return; 1591 return;
1587 } 1592 }
1588 1593
1589 // otherwise, insert assuming doesn't already exist 1594 // otherwise, insert assuming doesn't already exist
1590 QString emailsStr = find( Qtopia::Emails ); 1595 QString emailsStr = find( Qtopia::Emails );
1591 if ( emailsStr.contains( e )) 1596 if ( emailsStr.contains( e ))
1592 return; 1597 return;
1593 if ( !emailsStr.isEmpty() ) 1598 if ( !emailsStr.isEmpty() )
1594 emailsStr += emailSeparator(); 1599 emailsStr += emailSeparator();
1595 emailsStr += e; 1600 emailsStr += e;
1596 replace( Qtopia::Emails, emailsStr ); 1601 replace( Qtopia::Emails, emailsStr );
1597} 1602}
1598 1603
1599void OContact::removeEmail( const QString &v ) 1604void OContact::removeEmail( const QString &v )
1600{ 1605{
1601 QString e = v.simplifyWhiteSpace(); 1606 QString e = v.simplifyWhiteSpace();
1602 QString def = defaultEmail(); 1607 QString def = defaultEmail();
1603 QString emailsStr = find( Qtopia::Emails ); 1608 QString emailsStr = find( Qtopia::Emails );
1604 QStringList emails = emailList(); 1609 QStringList emails = emailList();
1605 1610
1606 // otherwise, must first contain it 1611 // otherwise, must first contain it
1607 if ( !emailsStr.contains( e ) ) 1612 if ( !emailsStr.contains( e ) )
1608 return; 1613 return;
1609 1614
1610 // remove it 1615 // remove it
1611 //qDebug(" removing email from list %s", e.latin1()); 1616 //qDebug(" removing email from list %s", e.latin1());
1612 emails.remove( e ); 1617 emails.remove( e );
1613 // reset the string 1618 // reset the string
1614 emailsStr = emails.join(emailSeparator()); // Sharp's brain dead separator 1619 emailsStr = emails.join(emailSeparator()); // Sharp's brain dead separator
1615 replace( Qtopia::Emails, emailsStr ); 1620 replace( Qtopia::Emails, emailsStr );
1616 1621
1617 // if default, then replace the default email with the first one 1622 // if default, then replace the default email with the first one
1618 if ( def == e ) { 1623 if ( def == e ) {
1619 //qDebug("removeEmail is default; setting new default"); 1624 //qDebug("removeEmail is default; setting new default");
1620 if ( !emails.count() ) 1625 if ( !emails.count() )
1621 clearEmails(); 1626 clearEmails();
1622 else // setDefaultEmail will remove e from the list 1627 else // setDefaultEmail will remove e from the list
1623 setDefaultEmail( emails.first() ); 1628 setDefaultEmail( emails.first() );
1624 } 1629 }
1625} 1630}
1626void OContact::clearEmails() 1631void OContact::clearEmails()
1627{ 1632{
1628 mMap.remove( Qtopia::DefaultEmail ); 1633 mMap.remove( Qtopia::DefaultEmail );
1629 mMap.remove( Qtopia::Emails ); 1634 mMap.remove( Qtopia::Emails );
1630} 1635}
1631void OContact::setDefaultEmail( const QString &v ) 1636void OContact::setDefaultEmail( const QString &v )
1632{ 1637{
1633 QString e = v.simplifyWhiteSpace(); 1638 QString e = v.simplifyWhiteSpace();
1634 1639
1635 //qDebug("OContact::setDefaultEmail %s", e.latin1()); 1640 //qDebug("OContact::setDefaultEmail %s", e.latin1());
1636 replace( Qtopia::DefaultEmail, e ); 1641 replace( Qtopia::DefaultEmail, e );
1637 1642
1638 if ( !e.isEmpty() ) 1643 if ( !e.isEmpty() )
1639 insertEmail( e ); 1644 insertEmail( e );
1640 1645
1641} 1646}
1642 1647
1643void OContact::insertEmails( const QStringList &v ) 1648void OContact::insertEmails( const QStringList &v )
1644{ 1649{
1645 for ( QStringList::ConstIterator it = v.begin(); it != v.end(); ++it ) 1650 for ( QStringList::ConstIterator it = v.begin(); it != v.end(); ++it )
1646 insertEmail( *it ); 1651 insertEmail( *it );
1647} 1652}
1648 1653