summaryrefslogtreecommitdiff
path: root/library/backend/contact.cpp
Unidiff
Diffstat (limited to 'library/backend/contact.cpp') (more/less context) (ignore 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,16 +1,16 @@
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**
6** This file may be distributed and/or modified under the terms of the 6** This file may be distributed and/or modified under the terms of the
7** GNU General Public License version 2 as published by the Free Software 7** GNU General Public License version 2 as published by the Free Software
8** Foundation and appearing in the file LICENSE.GPL included in the 8** Foundation and appearing in the file LICENSE.GPL included in the
9** packaging of this file. 9** packaging of this file.
10** 10**
11** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE 11** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
12** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. 12** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
13** 13**
14** See http://www.trolltech.com/gpl/ for GPL licensing information. 14** See http://www.trolltech.com/gpl/ for GPL licensing information.
15** 15**
16** Contact info@trolltech.com if any conditions of this licensing are 16** Contact info@trolltech.com if any conditions of this licensing are
@@ -25,57 +25,435 @@
25#include "qfiledirect_p.h" 25#include "qfiledirect_p.h"
26 26
27#include <qpe/stringutil.h> 27#include <qpe/stringutil.h>
28#include <qpe/timeconversion.h> 28#include <qpe/timeconversion.h>
29 29
30#include <qobject.h> 30#include <qobject.h>
31#include <qregexp.h> 31#include <qregexp.h>
32#include <qstylesheet.h> 32#include <qstylesheet.h>
33#include <qfileinfo.h> 33#include <qfileinfo.h>
34 34
35#include <stdio.h> 35#include <stdio.h>
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()
40 : Record(), mMap(), d( 0 ) 54 : Record(), mMap(), d( 0 )
41{ 55{
42} 56}
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 ) :
45 Record(), mMap( fromMap ), d( 0 ) 64 Record(), mMap( fromMap ), d( 0 )
46{ 65{
47 QString cats = mMap[ Qtopia::AddressCategory ]; 66 QString cats = mMap[ Qtopia::AddressCategory ];
48 if ( !cats.isEmpty() ) 67 if ( !cats.isEmpty() )
49 setCategories( idsFromString( cats ) ); 68 setCategories( idsFromString( cats ) );
50 QString uidStr = find( Qtopia::AddressUid ); 69 QString uidStr = find( Qtopia::AddressUid );
70
51 if ( uidStr.isEmpty() ) 71 if ( uidStr.isEmpty() )
52 setUid( uidGen().generate() ); 72 setUid( uidGen().generate() );
53 else 73 else
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()
58{ 84{
59} 85}
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
62{ 438{
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;
66} 444}
67 445
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*/
71QString Contact::toRichText() const 449QString Contact::toRichText() const
72{ 450{
73 QString text; 451 QString text;
74 QString value, comp, state; 452 QString value, comp, state;
75 453
76 // name, jobtitle and company 454 // name, jobtitle and company
77 if ( !(value = fullName()).isEmpty() ) 455 if ( !(value = fullName()).isEmpty() )
78 text += "<b>" + Qtopia::escapeString(value) + "</b><br>"; 456 text += "<b>" + Qtopia::escapeString(value) + "</b><br>";
79 if ( !(value = jobTitle()).isEmpty() ) 457 if ( !(value = jobTitle()).isEmpty() )
80 text += Qtopia::escapeString(value) + "<br>"; 458 text += Qtopia::escapeString(value) + "<br>";
81 459
@@ -222,83 +600,104 @@ QString Contact::toRichText() const
222 // notes last 600 // notes last
223 if ( (value = notes()) ) { 601 if ( (value = notes()) ) {
224 QRegExp reg("\n"); 602 QRegExp reg("\n");
225 603
226 //QString tmp = Qtopia::escapeString(value); 604 //QString tmp = Qtopia::escapeString(value);
227 QString tmp = QStyleSheet::convertFromPlainText(value); 605 QString tmp = QStyleSheet::convertFromPlainText(value);
228 //tmp.replace( reg, "<br>" ); 606 //tmp.replace( reg, "<br>" );
229 text += "<br>" + tmp + "<br>"; 607 text += "<br>" + tmp + "<br>";
230 } 608 }
231 return text; 609 return text;
232} 610}
233 611
612/*!
613 \internal
614*/
234void Contact::insert( int key, const QString &v ) 615void Contact::insert( int key, const QString &v )
235{ 616{
236 QString value = v.stripWhiteSpace(); 617 QString value = v.stripWhiteSpace();
237 if ( value.isEmpty() ) 618 if ( value.isEmpty() )
238 mMap.remove( key ); 619 mMap.remove( key );
239 else 620 else
240 mMap.insert( key, value ); 621 mMap.insert( key, value );
241} 622}
242 623
624/*!
625 \internal
626*/
243void Contact::replace( int key, const QString & v ) 627void Contact::replace( int key, const QString & v )
244{ 628{
245 QString value = v.stripWhiteSpace(); 629 QString value = v.stripWhiteSpace();
246 if ( value.isEmpty() ) 630 if ( value.isEmpty() )
247 mMap.remove( key ); 631 mMap.remove( key );
248 else 632 else
249 mMap.replace( key, value ); 633 mMap.replace( key, value );
250} 634}
251 635
636/*!
637 \internal
638*/
252QString Contact::find( int key ) const 639QString Contact::find( int key ) const
253{ 640{
254 return mMap[key]; 641 return mMap[key];
255} 642}
256 643
644/*!
645 \internal
646*/
257QString Contact::displayAddress( const QString &street, 647QString Contact::displayAddress( const QString &street,
258 const QString &city, 648 const QString &city,
259 const QString &state, 649 const QString &state,
260 const QString &zip, 650 const QString &zip,
261 const QString &country ) const 651 const QString &country ) const
262{ 652{
263 QString s = street; 653 QString s = street;
264 if ( !street.isEmpty() ) 654 if ( !street.isEmpty() )
265 s+= "\n"; 655 s+= "\n";
266 s += city; 656 s += city;
267 if ( !city.isEmpty() && !state.isEmpty() ) 657 if ( !city.isEmpty() && !state.isEmpty() )
268 s += ", "; 658 s += ", ";
269 s += state; 659 s += state;
270 if ( !state.isEmpty() && !zip.isEmpty() ) 660 if ( !state.isEmpty() && !zip.isEmpty() )
271 s += " "; 661 s += " ";
272 s += zip; 662 s += zip;
273 if ( !country.isEmpty() && !s.isEmpty() ) 663 if ( !country.isEmpty() && !s.isEmpty() )
274 s += "\n"; 664 s += "\n";
275 s += country; 665 s += country;
276 return s; 666 return s;
277} 667}
278 668
669/*!
670 \internal
671*/
279QString Contact::displayBusinessAddress() const 672QString Contact::displayBusinessAddress() const
280{ 673{
281 return displayAddress( businessStreet(), businessCity(), 674 return displayAddress( businessStreet(), businessCity(),
282 businessState(), businessZip(), 675 businessState(), businessZip(),
283 businessCountry() ); 676 businessCountry() );
284} 677}
285 678
679/*!
680 \internal
681*/
286QString Contact::displayHomeAddress() const 682QString Contact::displayHomeAddress() const
287{ 683{
288 return displayAddress( homeStreet(), homeCity(), 684 return displayAddress( homeStreet(), homeCity(),
289 homeState(), homeZip(), 685 homeState(), homeZip(),
290 homeCountry() ); 686 homeCountry() );
291} 687}
292 688
689/*!
690 Returns the full name of the contact
691*/
293QString Contact::fullName() const 692QString Contact::fullName() const
294{ 693{
295 QString title = find( Qtopia::Title ); 694 QString title = find( Qtopia::Title );
296 QString firstName = find( Qtopia::FirstName ); 695 QString firstName = find( Qtopia::FirstName );
297 QString middleName = find( Qtopia::MiddleName ); 696 QString middleName = find( Qtopia::MiddleName );
298 QString lastName = find( Qtopia::LastName ); 697 QString lastName = find( Qtopia::LastName );
299 QString suffix = find( Qtopia::Suffix ); 698 QString suffix = find( Qtopia::Suffix );
300 699
301 QString name = title; 700 QString name = title;
302 if ( !firstName.isEmpty() ) { 701 if ( !firstName.isEmpty() ) {
303 if ( !name.isEmpty() ) 702 if ( !name.isEmpty() )
304 name += " "; 703 name += " ";
@@ -313,79 +712,133 @@ QString Contact::fullName() const
313 if ( !name.isEmpty() ) 712 if ( !name.isEmpty() )
314 name += " "; 713 name += " ";
315 name += lastName; 714 name += lastName;
316 } 715 }
317 if ( !suffix.isEmpty() ) { 716 if ( !suffix.isEmpty() ) {
318 if ( !name.isEmpty() ) 717 if ( !name.isEmpty() )
319 name += " "; 718 name += " ";
320 name += suffix; 719 name += suffix;
321 } 720 }
322 return name.simplifyWhiteSpace(); 721 return name.simplifyWhiteSpace();
323} 722}
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
326{ 728{
327 return QStringList::split( " ", find( Qtopia::Children ) ); 729 return QStringList::split( " ", find( Qtopia::Children ) );
328} 730}
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()
336{ 781{
337 QString lastName, firstName, middleName, fileas; 782 QString lastName, firstName, middleName, fileas;
338 783
339 lastName = find( Qtopia::LastName ); 784 lastName = find( Qtopia::LastName );
340 firstName = find( Qtopia::FirstName ); 785 firstName = find( Qtopia::FirstName );
341 middleName = find( Qtopia::MiddleName ); 786 middleName = find( Qtopia::MiddleName );
342 if ( !lastName.isEmpty() && !firstName.isEmpty() 787 if ( !lastName.isEmpty() && !firstName.isEmpty()
343 && !middleName.isEmpty() ) 788 && !middleName.isEmpty() )
344 fileas = lastName + ", " + firstName + " " + middleName; 789 fileas = lastName + ", " + firstName + " " + middleName;
345 else if ( !lastName.isEmpty() && !firstName.isEmpty() ) 790 else if ( !lastName.isEmpty() && !firstName.isEmpty() )
346 fileas = lastName + ", " + firstName; 791 fileas = lastName + ", " + firstName;
347 else if ( !lastName.isEmpty() || !firstName.isEmpty() || 792 else if ( !lastName.isEmpty() || !firstName.isEmpty() ||
348 !middleName.isEmpty() ) 793 !middleName.isEmpty() )
349 fileas = firstName + ( firstName.isEmpty() ? "" : " " ) 794 fileas = firstName + ( firstName.isEmpty() ? "" : " " )
350 + middleName + ( middleName.isEmpty() ? "" : " " ) 795 + middleName + ( middleName.isEmpty() ? "" : " " )
351 + lastName; 796 + lastName;
352 797
353 replace( Qtopia::FileAs, fileas ); 798 replace( Qtopia::FileAs, fileas );
354} 799}
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
357{ 806{
358 static const QStringList SLFIELDS = fields(); 807 static const QStringList SLFIELDS = fields();
359 // I'm expecting "<Contact " in front of this... 808 // I'm expecting "<Contact " in front of this...
360 for ( QMap<int, QString>::ConstIterator it = mMap.begin(); 809 for ( QMap<int, QString>::ConstIterator it = mMap.begin();
361 it != mMap.end(); ++it ) { 810 it != mMap.end(); ++it ) {
362 const QString &value = it.data(); 811 const QString &value = it.data();
363 int key = it.key(); 812 int key = it.key();
364 if ( !value.isEmpty() ) { 813 if ( !value.isEmpty() ) {
365 if ( key == Qtopia::AddressCategory || key == Qtopia::AddressUid) 814 if ( key == Qtopia::AddressCategory || key == Qtopia::AddressUid)
366 continue; 815 continue;
367 816
368 key -= Qtopia::AddressCategory+1; 817 key -= Qtopia::AddressCategory+1;
369 buf += SLFIELDS[key]; 818 buf += SLFIELDS[key];
370 buf += "=\"" + Qtopia::escapeString(value) + "\" "; 819 buf += "=\"" + Qtopia::escapeString(value) + "\" ";
371 } 820 }
372 } 821 }
373 buf += customToXml(); 822 buf += customToXml();
374 if ( categories().count() > 0 ) 823 if ( categories().count() > 0 )
375 buf += "Categories=\"" + idsToString( categories() ) + "\" "; 824 buf += "Categories=\"" + idsToString( categories() ) + "\" ";
376 buf += "Uid=\"" + QString::number( uid() ) + "\" "; 825 buf += "Uid=\"" + QString::number( uid() ) + "\" ";
377 // You need to close this yourself 826 // You need to close this yourself
378} 827}
379 828
829/*!
830 \internal
831 Returns the list of fields belonging to a contact
832*/
380QStringList Contact::fields() 833QStringList Contact::fields()
381{ 834{
382 QStringList list; 835 QStringList list;
383 836
384 list.append( "Title" ); // Not Used! 837 list.append( "Title" ); // Not Used!
385 list.append( "FirstName" ); 838 list.append( "FirstName" );
386 list.append( "MiddleName" ); 839 list.append( "MiddleName" );
387 list.append( "LastName" ); 840 list.append( "LastName" );
388 list.append( "Suffix" ); 841 list.append( "Suffix" );
389 list.append( "FileAs" ); 842 list.append( "FileAs" );
390 843
391 list.append( "JobTitle" ); 844 list.append( "JobTitle" );
@@ -426,24 +879,28 @@ QStringList Contact::fields()
426 list.append( "Gender" ); 879 list.append( "Gender" );
427 list.append( "Birthday" ); 880 list.append( "Birthday" );
428 list.append( "Anniversary" ); 881 list.append( "Anniversary" );
429 list.append( "Nickname" ); 882 list.append( "Nickname" );
430 list.append( "Children" ); 883 list.append( "Children" );
431 884
432 list.append( "Notes" ); 885 list.append( "Notes" );
433 list.append( "Groups" ); 886 list.append( "Groups" );
434 887
435 return list; 888 return list;
436} 889}
437 890
891/*!
892 \internal
893 Returns a translated list of field names for a contact.
894*/
438QStringList Contact::trfields() 895QStringList Contact::trfields()
439{ 896{
440 QStringList list; 897 QStringList list;
441 898
442 list.append( QObject::tr( "Name Title") ); 899 list.append( QObject::tr( "Name Title") );
443 list.append( QObject::tr( "First Name" ) ); 900 list.append( QObject::tr( "First Name" ) );
444 list.append( QObject::tr( "Middle Name" ) ); 901 list.append( QObject::tr( "Middle Name" ) );
445 list.append( QObject::tr( "Last Name" ) ); 902 list.append( QObject::tr( "Last Name" ) );
446 list.append( QObject::tr( "Suffix" ) ); 903 list.append( QObject::tr( "Suffix" ) );
447 list.append( QObject::tr( "File As" ) ); 904 list.append( QObject::tr( "File As" ) );
448 905
449 list.append( QObject::tr( "Job Title" ) ); 906 list.append( QObject::tr( "Job Title" ) );
@@ -484,53 +941,69 @@ QStringList Contact::trfields()
484 list.append( QObject::tr( "Gender" ) ); 941 list.append( QObject::tr( "Gender" ) );
485 list.append( QObject::tr( "Birthday" ) ); 942 list.append( QObject::tr( "Birthday" ) );
486 list.append( QObject::tr( "Anniversary" ) ); 943 list.append( QObject::tr( "Anniversary" ) );
487 list.append( QObject::tr( "Nickname" ) ); 944 list.append( QObject::tr( "Nickname" ) );
488 list.append( QObject::tr( "Children" ) ); 945 list.append( QObject::tr( "Children" ) );
489 946
490 list.append( QObject::tr( "Notes" ) ); 947 list.append( QObject::tr( "Notes" ) );
491 list.append( QObject::tr( "Groups" ) ); 948 list.append( QObject::tr( "Groups" ) );
492 949
493 return list; 950 return list;
494} 951}
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 );
501} 962}
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}
507 971
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 )
510{ 977{
511 VObject *ret = 0; 978 VObject *ret = 0;
512 if ( o && !value.isEmpty() ) 979 if ( o && !value.isEmpty() )
513 ret = addPropValue( o, prop, value.latin1() ); 980 ret = addPropValue( o, prop, value.latin1() );
514 return ret; 981 return ret;
515} 982}
516 983
984/*!
985 \internal
986*/
517static inline VObject *safeAddProp( VObject *o, const char *prop) 987static inline VObject *safeAddProp( VObject *o, const char *prop)
518{ 988{
519 VObject *ret = 0; 989 VObject *ret = 0;
520 if ( o ) 990 if ( o )
521 ret = addProp( o, prop ); 991 ret = addProp( o, prop );
522 return ret; 992 return ret;
523} 993}
524 994
995/*!
996 \internal
997*/
525static VObject *createVObject( const Contact &c ) 998static VObject *createVObject( const Contact &c )
526{ 999{
527 VObject *vcard = newVObject( VCCardProp ); 1000 VObject *vcard = newVObject( VCCardProp );
528 safeAddPropValue( vcard, VCVersionProp, "2.1" ); 1001 safeAddPropValue( vcard, VCVersionProp, "2.1" );
529 safeAddPropValue( vcard, VCLastRevisedProp, TimeConversion::toISO8601( QDateTime::currentDateTime() ) ); 1002 safeAddPropValue( vcard, VCLastRevisedProp, TimeConversion::toISO8601( QDateTime::currentDateTime() ) );
530 safeAddPropValue( vcard, VCUniqueStringProp, QString::number(c.uid()) ); 1003 safeAddPropValue( vcard, VCUniqueStringProp, QString::number(c.uid()) );
531 1004
532 // full name 1005 // full name
533 safeAddPropValue( vcard, VCFullNameProp, c.fullName() ); 1006 safeAddPropValue( vcard, VCFullNameProp, c.fullName() );
534 1007
535 // name properties 1008 // name properties
536 VObject *name = safeAddProp( vcard, VCNameProp ); 1009 VObject *name = safeAddProp( vcard, VCNameProp );
@@ -613,30 +1086,31 @@ static VObject *createVObject( const Contact &c )
613 safeAddPropValue( vcard, "X-Qtopia-Assistant", c.assistant() ); 1086 safeAddPropValue( vcard, "X-Qtopia-Assistant", c.assistant() );
614 1087
615 safeAddPropValue( vcard, "X-Qtopia-Spouse", c.spouse() ); 1088 safeAddPropValue( vcard, "X-Qtopia-Spouse", c.spouse() );
616 safeAddPropValue( vcard, "X-Qtopia-Gender", c.gender() ); 1089 safeAddPropValue( vcard, "X-Qtopia-Gender", c.gender() );
617 safeAddPropValue( vcard, "X-Qtopia-Anniversary", c.anniversary() ); 1090 safeAddPropValue( vcard, "X-Qtopia-Anniversary", c.anniversary() );
618 safeAddPropValue( vcard, "X-Qtopia-Nickname", c.nickname() ); 1091 safeAddPropValue( vcard, "X-Qtopia-Nickname", c.nickname() );
619 safeAddPropValue( vcard, "X-Qtopia-Children", c.children() ); 1092 safeAddPropValue( vcard, "X-Qtopia-Children", c.children() );
620 1093
621 return vcard; 1094 return vcard;
622} 1095}
623 1096
624 1097
1098/*!
1099 \internal
1100*/
625static Contact parseVObject( VObject *obj ) 1101static Contact parseVObject( VObject *obj )
626{ 1102{
627 Contact c; 1103 Contact c;
628 1104
629 bool haveDefaultEmail = FALSE;
630
631 VObjectIterator it; 1105 VObjectIterator it;
632 initPropIterator( &it, obj ); 1106 initPropIterator( &it, obj );
633 while( moreIteration( &it ) ) { 1107 while( moreIteration( &it ) ) {
634 VObject *o = nextVObject( &it ); 1108 VObject *o = nextVObject( &it );
635 QCString name = vObjectName( o ); 1109 QCString name = vObjectName( o );
636 QCString value = vObjectStringZValue( o ); 1110 QCString value = vObjectStringZValue( o );
637 if ( name == VCNameProp ) { 1111 if ( name == VCNameProp ) {
638 VObjectIterator nit; 1112 VObjectIterator nit;
639 initPropIterator( &nit, o ); 1113 initPropIterator( &nit, o );
640 while( moreIteration( &nit ) ) { 1114 while( moreIteration( &nit ) ) {
641 VObject *o = nextVObject( &nit ); 1115 VObject *o = nextVObject( &nit );
642 QCString name = vObjectTypeInfo( o ); 1116 QCString name = vObjectTypeInfo( o );
@@ -758,32 +1232,25 @@ static Contact parseVObject( VObject *obj )
758 VObjectIterator nit; 1232 VObjectIterator nit;
759 initPropIterator( &nit, o ); 1233 initPropIterator( &nit, o );
760 while( moreIteration( &nit ) ) { 1234 while( moreIteration( &nit ) ) {
761 VObject *o = nextVObject( &nit ); 1235 VObject *o = nextVObject( &nit );
762 QCString name = vObjectTypeInfo( o ); 1236 QCString name = vObjectTypeInfo( o );
763 if ( name != VCInternetProp && name != VCHomeProp && 1237 if ( name != VCInternetProp && name != VCHomeProp &&
764 name != VCWorkProp && 1238 name != VCWorkProp &&
765 name != VCPreferredProp ) 1239 name != VCPreferredProp )
766 // ### preffered should map to default email 1240 // ### preffered should map to default email
767 valid = FALSE; 1241 valid = FALSE;
768 } 1242 }
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 }
779 } 1246 }
780 else if ( name == VCURLProp ) { 1247 else if ( name == VCURLProp ) {
781 VObjectIterator nit; 1248 VObjectIterator nit;
782 initPropIterator( &nit, o ); 1249 initPropIterator( &nit, o );
783 while( moreIteration( &nit ) ) { 1250 while( moreIteration( &nit ) ) {
784 VObject *o = nextVObject( &nit ); 1251 VObject *o = nextVObject( &nit );
785 QCString name = vObjectTypeInfo( o ); 1252 QCString name = vObjectTypeInfo( o );
786 if ( name == VCHomeProp ) 1253 if ( name == VCHomeProp )
787 c.setHomeWebpage( value ); 1254 c.setHomeWebpage( value );
788 else if ( name == VCWorkProp ) 1255 else if ( name == VCWorkProp )
789 c.setBusinessWebpage( value ); 1256 c.setBusinessWebpage( value );
@@ -842,82 +1309,99 @@ static Contact parseVObject( VObject *obj )
842 VObject *o = nextVObject( &nit ); 1309 VObject *o = nextVObject( &nit );
843 QCString name = vObjectName( o ); 1310 QCString name = vObjectName( o );
844 QString value = vObjectStringZValue( o ); 1311 QString value = vObjectStringZValue( o );
845 printf(" subprop: %s = %s\n", name.data(), value.latin1() ); 1312 printf(" subprop: %s = %s\n", name.data(), value.latin1() );
846 } 1313 }
847 } 1314 }
848#endif 1315#endif
849 } 1316 }
850 c.setFileAs(); 1317 c.setFileAs();
851 return c; 1318 return c;
852} 1319}
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)
855{ 1325{
856 QFileDirect f( filename.utf8().data() ); 1326 QFileDirect f( filename.utf8().data() );
857 if ( !f.open( IO_WriteOnly ) ) { 1327 if ( !f.open( IO_WriteOnly ) ) {
858 qWarning("Unable to open vcard write"); 1328 qWarning("Unable to open vcard write");
859 return; 1329 return;
860 } 1330 }
861 1331
862 QValueList<Contact>::ConstIterator it; 1332 QValueList<Contact>::ConstIterator it;
863 for( it = contacts.begin(); it != contacts.end(); ++it ) { 1333 for( it = contacts.begin(); it != contacts.end(); ++it ) {
864 VObject *obj = createVObject( *it ); 1334 VObject *obj = createVObject( *it );
865 writeVObject(f.directHandle() , obj ); 1335 writeVObject(f.directHandle() , obj );
866 cleanVObject( obj ); 1336 cleanVObject( obj );
867 } 1337 }
868 cleanStrTbl(); 1338 cleanStrTbl();
869} 1339}
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)
872{ 1345{
873 QFileDirect f( filename.utf8().data() ); 1346 QFileDirect f( filename.utf8().data() );
874 if ( !f.open( IO_WriteOnly ) ) { 1347 if ( !f.open( IO_WriteOnly ) ) {
875 qWarning("Unable to open vcard write"); 1348 qWarning("Unable to open vcard write");
876 return; 1349 return;
877 } 1350 }
878 1351
879 VObject *obj = createVObject( contact ); 1352 VObject *obj = createVObject( contact );
880 writeVObject( f.directHandle() , obj ); 1353 writeVObject( f.directHandle() , obj );
881 cleanVObject( obj ); 1354 cleanVObject( obj );
882 1355
883 cleanStrTbl(); 1356 cleanStrTbl();
884} 1357}
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 )
888{ 1363{
889 qDebug("trying to open %s, exists=%d", filename.utf8().data(), QFileInfo( filename.utf8().data() ).size() ); 1364 qDebug("trying to open %s, exists=%d", filename.utf8().data(), QFileInfo( filename.utf8().data() ).size() );
890 VObject *obj = Parse_MIME_FromFileName( (char *)filename.utf8().data() ); 1365 VObject *obj = Parse_MIME_FromFileName( (char *)filename.utf8().data() );
891 1366
892 qDebug("vobject = %p", obj ); 1367 qDebug("vobject = %p", obj );
893 1368
894 QValueList<Contact> contacts; 1369 QValueList<Contact> contacts;
895 1370
896 while ( obj ) { 1371 while ( obj ) {
897 contacts.append( parseVObject( obj ) ); 1372 contacts.append( parseVObject( obj ) );
898 1373
899 VObject *t = obj; 1374 VObject *t = obj;
900 obj = nextVObjectInList(obj); 1375 obj = nextVObjectInList(obj);
901 cleanVObject( t ); 1376 cleanVObject( t );
902 } 1377 }
903 1378
904 return contacts; 1379 return contacts;
905} 1380}
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
908{ 1387{
909 return match(QRegExp(regexp)); 1388 return match(QRegExp(regexp));
910} 1389}
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
913{ 1397{
914 bool match; 1398 bool match;
915 match = false; 1399 match = false;
916 QMap<int, QString>::ConstIterator it; 1400 QMap<int, QString>::ConstIterator it;
917 for ( it = mMap.begin(); it != mMap.end(); ++it ) { 1401 for ( it = mMap.begin(); it != mMap.end(); ++it ) {
918 if ( (*it).find( r ) > -1 ) { 1402 if ( (*it).find( r ) > -1 ) {
919 match = true; 1403 match = true;
920 break; 1404 break;
921 } 1405 }
922 } 1406 }
923 return match; 1407 return match;