summaryrefslogtreecommitdiff
path: root/library/backend/contact.cpp
Unidiff
Diffstat (limited to 'library/backend/contact.cpp') (more/less context) (show whitespace changes)
-rw-r--r--library/backend/contact.cpp526
1 files changed, 505 insertions, 21 deletions
diff --git a/library/backend/contact.cpp b/library/backend/contact.cpp
index b10b19a..3f4934a 100644
--- a/library/backend/contact.cpp
+++ b/library/backend/contact.cpp
@@ -1,5 +1,5 @@
1/********************************************************************** 1/**********************************************************************
2** Copyright (C) 2001 Trolltech AS. All rights reserved. 2** Copyright (C) 2000-2002 Trolltech AS. All rights reserved.
3** 3**
4** This file is part of Qtopia Environment. 4** This file is part of the Qtopia Environment.
5** 5**
@@ -36,4 +36,18 @@
36 36
37/*!
38 \class Contact contact.h
39 \brief The Contact class holds the data of an address book entry.
40
41 This data includes information the name of the person, contact
42 information, and business information such as deparment and job title.
43
44 \ingroup qtopiaemb
45 \ingroup qtopiadesktop
46*/
47
37Qtopia::UidGen Contact::sUidGen( Qtopia::UidGen::Qtopia ); 48Qtopia::UidGen Contact::sUidGen( Qtopia::UidGen::Qtopia );
38 49
50/*!
51 Creates a new, empty contact.
52*/
39Contact::Contact() 53Contact::Contact()
@@ -43,2 +57,7 @@ Contact::Contact()
43 57
58/*!
59 \internal
60 Creates a new contact. The properties of the contact are
61 set from \a fromMap.
62*/
44Contact::Contact( const QMap<int, QString> &fromMap ) : 63Contact::Contact( const QMap<int, QString> &fromMap ) :
@@ -50,2 +69,3 @@ Contact::Contact( const QMap<int, QString> &fromMap ) :
50 QString uidStr = find( Qtopia::AddressUid ); 69 QString uidStr = find( Qtopia::AddressUid );
70
51 if ( uidStr.isEmpty() ) 71 if ( uidStr.isEmpty() )
@@ -54,4 +74,10 @@ Contact::Contact( const QMap<int, QString> &fromMap ) :
54 setUid( uidStr.toInt() ); 74 setUid( uidStr.toInt() );
75
76 if ( !uidStr.isEmpty() )
77 setUid( uidStr.toInt() );
55} 78}
56 79
80/*!
81 Destroys a contact.
82*/
57Contact::~Contact() 83Contact::~Contact()
@@ -60,2 +86,352 @@ Contact::~Contact()
60 86
87/*! \fn void Contact::setTitle( const QString &str )
88 Sets the title of the contact to \a str.
89*/
90
91/*! \fn void Contact::setFirstName( const QString &str )
92 Sets the first name of the contact to \a str.
93*/
94
95/*! \fn void Contact::setMiddleName( const QString &str )
96 Sets the middle name of the contact to \a str.
97*/
98
99/*! \fn void Contact::setLastName( const QString &str )
100 Sets the last name of the contact to \a str.
101*/
102
103/*! \fn void Contact::setSuffix( const QString &str )
104 Sets the suffix of the contact to \a str.
105*/
106
107/*! \fn void Contact::setFileAs( const QString &str )
108 Sets the contact to filed as \a str.
109*/
110
111/*! \fn void Contact::setDefaultEmail( const QString &str )
112 Sets the default email of the contact to \a str.
113*/
114
115/*! \fn void Contact::setHomeStreet( const QString &str )
116 Sets the home street address of the contact to \a str.
117*/
118
119/*! \fn void Contact::setHomeCity( const QString &str )
120 Sets the home city of the contact to \a str.
121*/
122
123/*! \fn void Contact::setHomeState( const QString &str )
124 Sets the home state of the contact to \a str.
125*/
126
127/*! \fn void Contact::setHomeZip( const QString &str )
128 Sets the home zip code of the contact to \a str.
129*/
130
131/*! \fn void Contact::setHomeCountry( const QString &str )
132 Sets the home country of the contact to \a str.
133*/
134
135/*! \fn void Contact::setHomePhone( const QString &str )
136 Sets the home phone number of the contact to \a str.
137*/
138
139/*! \fn void Contact::setHomeFax( const QString &str )
140 Sets the home fax number of the contact to \a str.
141*/
142
143/*! \fn void Contact::setHomeMobile( const QString &str )
144 Sets the home mobile phone number of the contact to \a str.
145*/
146
147/*! \fn void Contact::setHomeWebpage( const QString &str )
148 Sets the home webpage of the contact to \a str.
149*/
150
151/*! \fn void Contact::setCompany( const QString &str )
152 Sets the company for contact to \a str.
153*/
154
155/*! \fn void Contact::setJobTitle( const QString &str )
156 Sets the job title of the contact to \a str.
157*/
158
159/*! \fn void Contact::setDepartment( const QString &str )
160 Sets the department for contact to \a str.
161*/
162
163/*! \fn void Contact::setOffice( const QString &str )
164 Sets the office for contact to \a str.
165*/
166
167/*! \fn void Contact::setBusinessStreet( const QString &str )
168 Sets the business street address of the contact to \a str.
169*/
170
171/*! \fn void Contact::setBusinessCity( const QString &str )
172 Sets the business city of the contact to \a str.
173*/
174
175/*! \fn void Contact::setBusinessState( const QString &str )
176 Sets the business state of the contact to \a str.
177*/
178
179/*! \fn void Contact::setBusinessZip( const QString &str )
180 Sets the business zip code of the contact to \a str.
181*/
182
183/*! \fn void Contact::setBusinessCountry( const QString &str )
184 Sets the business country of the contact to \a str.
185*/
186
187/*! \fn void Contact::setBusinessPhone( const QString &str )
188 Sets the business phone number of the contact to \a str.
189*/
190
191/*! \fn void Contact::setBusinessFax( const QString &str )
192 Sets the business fax number of the contact to \a str.
193*/
194
195/*! \fn void Contact::setBusinessMobile( const QString &str )
196 Sets the business mobile phone number of the contact to \a str.
197*/
198
199/*! \fn void Contact::setBusinessPager( const QString &str )
200 Sets the business pager number of the contact to \a str.
201*/
202
203/*! \fn void Contact::setBusinessWebpage( const QString &str )
204 Sets the business webpage of the contact to \a str.
205*/
206
207/*! \fn void Contact::setProfession( const QString &str )
208 Sets the profession of the contact to \a str.
209*/
210
211/*! \fn void Contact::setAssistant( const QString &str )
212 Sets the assistant of the contact to \a str.
213*/
214
215/*! \fn void Contact::setManager( const QString &str )
216 Sets the manager of the contact to \a str.
217*/
218
219/*! \fn void Contact::setSpouse( const QString &str )
220 Sets the spouse of the contact to \a str.
221*/
222
223/*! \fn void Contact::setGender( const QString &str )
224 Sets the gender of the contact to \a str.
225*/
226
227/*! \fn void Contact::setBirthday( const QString &str )
228 Sets the birthday for the contact to \a str.
229*/
230
231/*! \fn void Contact::setAnniversary( const QString &str )
232 Sets the anniversary of the contact to \a str.
233*/
234
235/*! \fn void Contact::setNickname( const QString &str )
236 Sets the nickname of the contact to \a str.
237*/
238
239/*! \fn void Contact::setNotes( const QString &str )
240 Sets the notes about the contact to \a str.
241*/
242
243/*! \fn QString Contact::title() const
244 Returns the title of the contact.
245*/
246
247/*! \fn QString Contact::firstName() const
248 Returns the first name of the contact.
249*/
250
251/*! \fn QString Contact::middleName() const
252 Returns the middle name of the contact.
253*/
254
255/*! \fn QString Contact::lastName() const
256 Returns the last name of the contact.
257*/
258
259/*! \fn QString Contact::suffix() const
260 Returns the suffix of the contact.
261*/
262
263/*! \fn QString Contact::fileAs() const
264 Returns the string the contact is filed as.
265*/
266
267/*! \fn QString Contact::defaultEmail() const
268 Returns the default email address of the contact.
269*/
270
271/*! \fn QString Contact::emails() const
272 Returns the list of email address for a contact separated by ';'s in a single
273 string.
274*/
275
276/*! \fn QString Contact::homeStreet() const
277 Returns the home street address of the contact.
278*/
279
280/*! \fn QString Contact::homeCity() const
281 Returns the home city of the contact.
282*/
283
284/*! \fn QString Contact::homeState() const
285 Returns the home state of the contact.
286*/
287
288/*! \fn QString Contact::homeZip() const
289 Returns the home zip of the contact.
290*/
291
292/*! \fn QString Contact::homeCountry() const
293 Returns the home country of the contact.
294*/
295
296/*! \fn QString Contact::homePhone() const
297 Returns the home phone number of the contact.
298*/
299
300/*! \fn QString Contact::homeFax() const
301 Returns the home fax number of the contact.
302*/
303
304/*! \fn QString Contact::homeMobile() const
305 Returns the home mobile number of the contact.
306*/
307
308/*! \fn QString Contact::homeWebpage() const
309 Returns the home webpage of the contact.
310*/
311
312/*! \fn QString Contact::company() const
313 Returns the company for the contact.
314*/
315
316/*! \fn QString Contact::department() const
317 Returns the department for the contact.
318*/
319
320/*! \fn QString Contact::office() const
321 Returns the office for the contact.
322*/
323
324/*! \fn QString Contact::jobTitle() const
325 Returns the job title of the contact.
326*/
327
328/*! \fn QString Contact::profession() const
329 Returns the profession of the contact.
330*/
331
332/*! \fn QString Contact::assistant() const
333 Returns the assistant of the contact.
334*/
335
336/*! \fn QString Contact::manager() const
337 Returns the manager of the contact.
338*/
339
340/*! \fn QString Contact::businessStreet() const
341 Returns the business street address of the contact.
342*/
343
344/*! \fn QString Contact::businessCity() const
345 Returns the business city of the contact.
346*/
347
348/*! \fn QString Contact::businessState() const
349 Returns the business state of the contact.
350*/
351
352/*! \fn QString Contact::businessZip() const
353 Returns the business zip of the contact.
354*/
355
356/*! \fn QString Contact::businessCountry() const
357 Returns the business country of the contact.
358*/
359
360/*! \fn QString Contact::businessPhone() const
361 Returns the business phone number of the contact.
362*/
363
364/*! \fn QString Contact::businessFax() const
365 Returns the business fax number of the contact.
366*/
367
368/*! \fn QString Contact::businessMobile() const
369 Returns the business mobile number of the contact.
370*/
371
372/*! \fn QString Contact::businessPager() const
373 Returns the business pager number of the contact.
374*/
375
376/*! \fn QString Contact::businessWebpage() const
377 Returns the business webpage of the contact.
378*/
379
380/*! \fn QString Contact::spouse() const
381 Returns the spouse of the contact.
382*/
383
384/*! \fn QString Contact::gender() const
385 Returns the gender of the contact.
386*/
387
388/*! \fn QString Contact::birthday() const
389 Returns the birthday of the contact.
390*/
391
392/*! \fn QString Contact::anniversary() const
393 Returns the anniversary of the contact.
394*/
395
396/*! \fn QString Contact::nickname() const
397 Returns the nickname of the contact.
398*/
399
400/*! \fn QString Contact::children() const
401 Returns the children of the contact.
402*/
403
404/*! \fn QString Contact::notes() const
405 Returns the notes relating to the the contact.
406*/
407
408/*! \fn QString Contact::groups() const
409 \internal
410 Returns the groups for the contact.
411*/
412
413/*! \fn QStringList Contact::groupList() const
414 \internal
415*/
416
417/*! \fn QString Contact::field(int) const
418 \internal
419*/
420
421/*! \fn void Contact::saveJournal( journal_action, const QString & = QString::null )
422 \internal
423*/
424
425/*! \fn void Contact::setUid( int id )
426 \internal
427 Sets the uid for this record to \a id.
428*/
429
430/*! \enum Contact::journal_action
431 \internal
432*/
433
434/*!
435 \internal
436*/
61QMap<int, QString> Contact::toMap() const 437QMap<int, QString> Contact::toMap() const
@@ -63,3 +439,5 @@ QMap<int, QString> Contact::toMap() const
63 QMap<int, QString> map = mMap; 439 QMap<int, QString> map = mMap;
64 map.insert( Qtopia::AddressCategory, idsToString( categories() )); 440 QString cats = idsToString( categories() );
441 if ( !cats.isEmpty() )
442 map.insert( Qtopia::AddressCategory, cats );
65 return map; 443 return map;
@@ -68,3 +446,3 @@ QMap<int, QString> Contact::toMap() const
68/*! 446/*!
69 Returns a rich text formatted QString of the Contact. 447 Returns a rich text formatted QString representing the contents the contact.
70*/ 448*/
@@ -233,2 +611,5 @@ QString Contact::toRichText() const
233 611
612/*!
613 \internal
614*/
234void Contact::insert( int key, const QString &v ) 615void Contact::insert( int key, const QString &v )
@@ -242,2 +623,5 @@ void Contact::insert( int key, const QString &v )
242 623
624/*!
625 \internal
626*/
243void Contact::replace( int key, const QString & v ) 627void Contact::replace( int key, const QString & v )
@@ -251,2 +635,5 @@ void Contact::replace( int key, const QString & v )
251 635
636/*!
637 \internal
638*/
252QString Contact::find( int key ) const 639QString Contact::find( int key ) const
@@ -256,2 +643,5 @@ QString Contact::find( int key ) const
256 643
644/*!
645 \internal
646*/
257QString Contact::displayAddress( const QString &street, 647QString Contact::displayAddress( const QString &street,
@@ -278,2 +668,5 @@ QString Contact::displayAddress( const QString &street,
278 668
669/*!
670 \internal
671*/
279QString Contact::displayBusinessAddress() const 672QString Contact::displayBusinessAddress() const
@@ -285,2 +678,5 @@ QString Contact::displayBusinessAddress() const
285 678
679/*!
680 \internal
681*/
286QString Contact::displayHomeAddress() const 682QString Contact::displayHomeAddress() const
@@ -292,2 +688,5 @@ QString Contact::displayHomeAddress() const
292 688
689/*!
690 Returns the full name of the contact
691*/
293QString Contact::fullName() const 692QString Contact::fullName() const
@@ -324,2 +723,5 @@ QString Contact::fullName() const
324 723
724/*!
725 Returns a list of the names of the children of the contact.
726*/
325QStringList Contact::childrenList() const 727QStringList Contact::childrenList() const
@@ -329,7 +731,50 @@ QStringList Contact::childrenList() const
329 731
732/*! \fn void Contact::insertEmail( const QString &email )
733
734 Insert \a email into the email list. Ensures \a email can only be added
735 once. If there is no default email address set, it sets it to the \a email.
736*/
737
738/*! \fn void Contact::removeEmail( const QString &email )
739
740 Removes the \a email from the email list. If the default email was \a email,
741 then the default email address is assigned to the first email in the
742 email list
743*/
744
745/*! \fn void Contact::clearEmails()
746
747 Clears the email list.
748 */
749
750/*! \fn void Contact::insertEmails( const QStringList &emailList )
751
752 Appends the \a emailList to the exiting email list
753 */
754
755/*!
756 Returns a list of email addresses belonging to the contact, including
757 the default email address.
758*/
330QStringList Contact::emailList() const 759QStringList Contact::emailList() const
331{ 760{
332 return QStringList::split( ";", find( Qtopia::Emails ) ); 761 QString emailStr = emails();
762
763 QStringList r;
764 if ( !emailStr.isEmpty() ) {
765 qDebug(" emailstr ");
766 QStringList l = QStringList::split( emailSeparator(), emailStr );
767 for ( QStringList::ConstIterator it = l.begin();it != l.end();++it )
768 r += (*it).simplifyWhiteSpace();
769 }
770
771 return r;
333} 772}
334 773
774/*!
775 \overload
776
777 Generates the string for the contact to be filed as from the first,
778 middle and last name of the contact.
779*/
335void Contact::setFileAs() 780void Contact::setFileAs()
@@ -355,2 +800,6 @@ void Contact::setFileAs()
355 800
801/*!
802 \internal
803 Appends the contact information to \a buf.
804*/
356void Contact::save( QString &buf ) const 805void Contact::save( QString &buf ) const
@@ -379,2 +828,6 @@ void Contact::save( QString &buf ) const
379 828
829/*!
830 \internal
831 Returns the list of fields belonging to a contact
832*/
380QStringList Contact::fields() 833QStringList Contact::fields()
@@ -437,2 +890,6 @@ QStringList Contact::fields()
437 890
891/*!
892 \internal
893 Returns a translated list of field names for a contact.
894*/
438QStringList Contact::trfields() 895QStringList Contact::trfields()
@@ -495,6 +952,10 @@ QStringList Contact::trfields()
495 952
496void Contact::setEmails( const QString &v ) 953/*!
954 Sets the list of email address for contact to those contained in \a str.
955 Email address should be separated by ';'s.
956*/
957void Contact::setEmails( const QString &str )
497{ 958{
498 replace( Qtopia::Emails, v ); 959 replace( Qtopia::Emails, str );
499 if ( v.isEmpty() ) 960 if ( str.isEmpty() )
500 setDefaultEmail( QString::null ); 961 setDefaultEmail( QString::null );
@@ -502,5 +963,8 @@ void Contact::setEmails( const QString &v )
502 963
503void Contact::setChildren( const QString &v ) 964/*!
965 Sets the list of children for the contact to those contained in \a str.
966*/
967void Contact::setChildren( const QString &str )
504{ 968{
505 replace( Qtopia::Children, v ); 969 replace( Qtopia::Children, str );
506} 970}
@@ -508,2 +972,5 @@ void Contact::setChildren( const QString &v )
508// vcard conversion code 972// vcard conversion code
973/*!
974 \internal
975*/
509static inline VObject *safeAddPropValue( VObject *o, const char *prop, const QString &value ) 976static inline VObject *safeAddPropValue( VObject *o, const char *prop, const QString &value )
@@ -516,2 +983,5 @@ static inline VObject *safeAddPropValue( VObject *o, const char *prop, const QSt
516 983
984/*!
985 \internal
986*/
517static inline VObject *safeAddProp( VObject *o, const char *prop) 987static inline VObject *safeAddProp( VObject *o, const char *prop)
@@ -524,2 +994,5 @@ static inline VObject *safeAddProp( VObject *o, const char *prop)
524 994
995/*!
996 \internal
997*/
525static VObject *createVObject( const Contact &c ) 998static VObject *createVObject( const Contact &c )
@@ -624,2 +1097,5 @@ static VObject *createVObject( const Contact &c )
624 1097
1098/*!
1099 \internal
1100*/
625static Contact parseVObject( VObject *obj ) 1101static Contact parseVObject( VObject *obj )
@@ -628,4 +1104,2 @@ static Contact parseVObject( VObject *obj )
628 1104
629 bool haveDefaultEmail = FALSE;
630
631 VObjectIterator it; 1105 VObjectIterator it;
@@ -769,10 +1243,3 @@ static Contact parseVObject( VObject *obj )
769 if ( valid ) { 1243 if ( valid ) {
770 if ( haveDefaultEmail ) { 1244 c.insertEmail( email );
771 QString str = c.emails();
772 if ( !str.isEmpty() )
773 str += ","+email;
774 c.setEmails( str );
775 } else {
776 c.setDefaultEmail( email );
777 }
778 } 1245 }
@@ -853,2 +1320,5 @@ static Contact parseVObject( VObject *obj )
853 1320
1321/*!
1322 Writes the list of \a contacts as a set of VCards to the file \a filename.
1323*/
854void Contact::writeVCard( const QString &filename, const QValueList<Contact> &contacts) 1324void Contact::writeVCard( const QString &filename, const QValueList<Contact> &contacts)
@@ -870,2 +1340,5 @@ void Contact::writeVCard( const QString &filename, const QValueList<Contact> &co
870 1340
1341/*!
1342 writes \a contact as a VCard to the file \a filename.
1343*/
871void Contact::writeVCard( const QString &filename, const Contact &contact) 1344void Contact::writeVCard( const QString &filename, const Contact &contact)
@@ -885,3 +1358,5 @@ void Contact::writeVCard( const QString &filename, const Contact &contact)
885 1358
886 1359/*!
1360 Returns the set of contacts read as VCards from the file \a filename.
1361*/
887QValueList<Contact> Contact::readVCard( const QString &filename ) 1362QValueList<Contact> Contact::readVCard( const QString &filename )
@@ -906,2 +1381,6 @@ QValueList<Contact> Contact::readVCard( const QString &filename )
906 1381
1382/*!
1383 Returns TRUE if the contact matches the regular expression \a regexp.
1384 Otherwise returns FALSE.
1385*/
907bool Contact::match( const QString &regexp ) const 1386bool Contact::match( const QString &regexp ) const
@@ -911,2 +1390,7 @@ bool Contact::match( const QString &regexp ) const
911 1390
1391/*!
1392 \overload
1393 Returns TRUE if the contact matches the regular expression \a regexp.
1394 Otherwise returns FALSE.
1395*/
912bool Contact::match( const QRegExp &r ) const 1396bool Contact::match( const QRegExp &r ) const