summaryrefslogtreecommitdiff
path: root/noncore/unsupported/libopie/pim/ocontact.cpp
Unidiff
Diffstat (limited to 'noncore/unsupported/libopie/pim/ocontact.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/unsupported/libopie/pim/ocontact.cpp1207
1 files changed, 1207 insertions, 0 deletions
diff --git a/noncore/unsupported/libopie/pim/ocontact.cpp b/noncore/unsupported/libopie/pim/ocontact.cpp
new file mode 100644
index 0000000..fcf3b26
--- a/dev/null
+++ b/noncore/unsupported/libopie/pim/ocontact.cpp
@@ -0,0 +1,1207 @@
1/**********************************************************************
2** Copyright (C) 2000-2002 Trolltech AS. All rights reserved.
3** Copyright (C) 2002-2003 by Stefan Eilers (eilers.stefan@epost.de)
4**
5** This file may be distributed and/or modified under the terms of the
6** GNU General Public License version 2 as published by the Free Software
7** Foundation and appearing in the file LICENSE.GPL included in the
8** packaging of this file.
9**
10** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
11** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
12**
13** See http://www.trolltech.com/gpl/ for GPL licensing information.
14**
15** Contact info@trolltech.com if any conditions of this licensing are
16** not clear to you.
17**
18**********************************************************************/
19
20#define QTOPIA_INTERNAL_CONTACT_MRE
21
22#include "ocontact.h"
23#include "opimresolver.h"
24#include "oconversion.h"
25
26#include <qpe/stringutil.h>
27#include <qpe/timestring.h>
28#include <qpe/config.h>
29
30#include <qobject.h>
31#include <qregexp.h>
32#include <qstylesheet.h>
33#include <qfileinfo.h>
34#include <qmap.h>
35
36#include <stdio.h>
37
38/*!
39 \class Contact contact.h
40 \brief The Contact class holds the data of an address book entry.
41
42 This data includes information the name of the person, contact
43 information, and business information such as deparment and job title.
44
45 \ingroup qtopiaemb
46 \ingroup qtopiadesktop
47*/
48
49
50/*!
51 Creates a new, empty contact.
52*/
53OContact::OContact()
54 : OPimRecord(), mMap(), d( 0 )
55{
56}
57
58/*!
59 \internal
60 Creates a new contact. The properties of the contact are
61 set from \a fromMap.
62*/
63OContact::OContact( const QMap<int, QString> &fromMap ) :
64 OPimRecord(), mMap( fromMap ), d( 0 )
65{
66 QString cats = mMap[ Qtopia::AddressCategory ];
67 if ( !cats.isEmpty() )
68 setCategories( idsFromString( cats ) );
69
70 QString uidStr = find( Qtopia::AddressUid );
71
72 if ( uidStr.isEmpty() || (uidStr.toInt() == 0) ){
73 qWarning( "Invalid UID found. Generate new one.." );
74 setUid( uidGen().generate() );
75 }else
76 setUid( uidStr.toInt() );
77
78// if ( !uidStr.isEmpty() )
79 // setUid( uidStr.toInt() );
80}
81
82/*!
83 Destroys a contact.
84*/
85OContact::~OContact()
86{
87}
88
89/*! \fn void OContact::setTitle( const QString &str )
90 Sets the title of the contact to \a str.
91*/
92
93/*! \fn void OContact::setFirstName( const QString &str )
94 Sets the first name of the contact to \a str.
95*/
96
97/*! \fn void OContact::setMiddleName( const QString &str )
98 Sets the middle name of the contact to \a str.
99*/
100
101/*! \fn void OContact::setLastName( const QString &str )
102 Sets the last name of the contact to \a str.
103*/
104
105/*! \fn void OContact::setSuffix( const QString &str )
106 Sets the suffix of the contact to \a str.
107*/
108
109/*! \fn void OContact::setFileAs( const QString &str )
110 Sets the contact to filed as \a str.
111*/
112
113/*! \fn void OContact::setDefaultEmail( const QString &str )
114 Sets the default email of the contact to \a str.
115*/
116
117/*! \fn void OContact::setHomeStreet( const QString &str )
118 Sets the home street address of the contact to \a str.
119*/
120
121/*! \fn void OContact::setHomeCity( const QString &str )
122 Sets the home city of the contact to \a str.
123*/
124
125/*! \fn void OContact::setHomeState( const QString &str )
126 Sets the home state of the contact to \a str.
127*/
128
129/*! \fn void OContact::setHomeZip( const QString &str )
130 Sets the home zip code of the contact to \a str.
131*/
132
133/*! \fn void OContact::setHomeCountry( const QString &str )
134 Sets the home country of the contact to \a str.
135*/
136
137/*! \fn void OContact::setHomePhone( const QString &str )
138 Sets the home phone number of the contact to \a str.
139*/
140
141/*! \fn void OContact::setHomeFax( const QString &str )
142 Sets the home fax number of the contact to \a str.
143*/
144
145/*! \fn void OContact::setHomeMobile( const QString &str )
146 Sets the home mobile phone number of the contact to \a str.
147*/
148
149/*! \fn void OContact::setHomeWebpage( const QString &str )
150 Sets the home webpage of the contact to \a str.
151*/
152
153/*! \fn void OContact::setCompany( const QString &str )
154 Sets the company for contact to \a str.
155*/
156
157/*! \fn void OContact::setJobTitle( const QString &str )
158 Sets the job title of the contact to \a str.
159*/
160
161/*! \fn void OContact::setDepartment( const QString &str )
162 Sets the department for contact to \a str.
163*/
164
165/*! \fn void OContact::setOffice( const QString &str )
166 Sets the office for contact to \a str.
167*/
168
169/*! \fn void OContact::setBusinessStreet( const QString &str )
170 Sets the business street address of the contact to \a str.
171*/
172
173/*! \fn void OContact::setBusinessCity( const QString &str )
174 Sets the business city of the contact to \a str.
175*/
176
177/*! \fn void OContact::setBusinessState( const QString &str )
178 Sets the business state of the contact to \a str.
179*/
180
181/*! \fn void OContact::setBusinessZip( const QString &str )
182 Sets the business zip code of the contact to \a str.
183*/
184
185/*! \fn void OContact::setBusinessCountry( const QString &str )
186 Sets the business country of the contact to \a str.
187*/
188
189/*! \fn void OContact::setBusinessPhone( const QString &str )
190 Sets the business phone number of the contact to \a str.
191*/
192
193/*! \fn void OContact::setBusinessFax( const QString &str )
194 Sets the business fax number of the contact to \a str.
195*/
196
197/*! \fn void OContact::setBusinessMobile( const QString &str )
198 Sets the business mobile phone number of the contact to \a str.
199*/
200
201/*! \fn void OContact::setBusinessPager( const QString &str )
202 Sets the business pager number of the contact to \a str.
203*/
204
205/*! \fn void OContact::setBusinessWebpage( const QString &str )
206 Sets the business webpage of the contact to \a str.
207*/
208
209/*! \fn void OContact::setProfession( const QString &str )
210 Sets the profession of the contact to \a str.
211*/
212
213/*! \fn void OContact::setAssistant( const QString &str )
214 Sets the assistant of the contact to \a str.
215*/
216
217/*! \fn void OContact::setManager( const QString &str )
218 Sets the manager of the contact to \a str.
219*/
220
221/*! \fn void OContact::setSpouse( const QString &str )
222 Sets the spouse of the contact to \a str.
223*/
224
225/*! \fn void OContact::setGender( const QString &str )
226 Sets the gender of the contact to \a str.
227*/
228
229/*! \fn void OContact::setNickname( const QString &str )
230 Sets the nickname of the contact to \a str.
231*/
232
233/*! \fn void OContact::setNotes( const QString &str )
234 Sets the notes about the contact to \a str.
235*/
236
237/*! \fn QString OContact::title() const
238 Returns the title of the contact.
239*/
240
241/*! \fn QString OContact::firstName() const
242 Returns the first name of the contact.
243*/
244
245/*! \fn QString OContact::middleName() const
246 Returns the middle name of the contact.
247*/
248
249/*! \fn QString OContact::lastName() const
250 Returns the last name of the contact.
251*/
252
253/*! \fn QString OContact::suffix() const
254 Returns the suffix of the contact.
255*/
256
257/*! \fn QString OContact::fileAs() const
258 Returns the string the contact is filed as.
259*/
260
261/*! \fn QString OContact::defaultEmail() const
262 Returns the default email address of the contact.
263*/
264
265/*! \fn QString OContact::emails() const
266 Returns the list of email address for a contact separated by ';'s in a single
267 string.
268*/
269
270/*! \fn QString OContact::homeStreet() const
271 Returns the home street address of the contact.
272*/
273
274/*! \fn QString OContact::homeCity() const
275 Returns the home city of the contact.
276*/
277
278/*! \fn QString OContact::homeState() const
279 Returns the home state of the contact.
280*/
281
282/*! \fn QString OContact::homeZip() const
283 Returns the home zip of the contact.
284*/
285
286/*! \fn QString OContact::homeCountry() const
287 Returns the home country of the contact.
288*/
289
290/*! \fn QString OContact::homePhone() const
291 Returns the home phone number of the contact.
292*/
293
294/*! \fn QString OContact::homeFax() const
295 Returns the home fax number of the contact.
296*/
297
298/*! \fn QString OContact::homeMobile() const
299 Returns the home mobile number of the contact.
300*/
301
302/*! \fn QString OContact::homeWebpage() const
303 Returns the home webpage of the contact.
304*/
305
306/*! \fn QString OContact::company() const
307 Returns the company for the contact.
308*/
309
310/*! \fn QString OContact::department() const
311 Returns the department for the contact.
312*/
313
314/*! \fn QString OContact::office() const
315 Returns the office for the contact.
316*/
317
318/*! \fn QString OContact::jobTitle() const
319 Returns the job title of the contact.
320*/
321
322/*! \fn QString OContact::profession() const
323 Returns the profession of the contact.
324*/
325
326/*! \fn QString OContact::assistant() const
327 Returns the assistant of the contact.
328*/
329
330/*! \fn QString OContact::manager() const
331 Returns the manager of the contact.
332*/
333
334/*! \fn QString OContact::businessStreet() const
335 Returns the business street address of the contact.
336*/
337
338/*! \fn QString OContact::businessCity() const
339 Returns the business city of the contact.
340*/
341
342/*! \fn QString OContact::businessState() const
343 Returns the business state of the contact.
344*/
345
346/*! \fn QString OContact::businessZip() const
347 Returns the business zip of the contact.
348*/
349
350/*! \fn QString OContact::businessCountry() const
351 Returns the business country of the contact.
352*/
353
354/*! \fn QString OContact::businessPhone() const
355 Returns the business phone number of the contact.
356*/
357
358/*! \fn QString OContact::businessFax() const
359 Returns the business fax number of the contact.
360*/
361
362/*! \fn QString OContact::businessMobile() const
363 Returns the business mobile number of the contact.
364*/
365
366/*! \fn QString OContact::businessPager() const
367 Returns the business pager number of the contact.
368*/
369
370/*! \fn QString OContact::businessWebpage() const
371 Returns the business webpage of the contact.
372*/
373
374/*! \fn QString OContact::spouse() const
375 Returns the spouse of the contact.
376*/
377
378/*! \fn QString OContact::gender() const
379 Returns the gender of the contact.
380*/
381
382/*! \fn QString OContact::nickname() const
383 Returns the nickname of the contact.
384*/
385
386/*! \fn QString OContact::children() const
387 Returns the children of the contact.
388*/
389
390/*! \fn QString OContact::notes() const
391 Returns the notes relating to the the contact.
392*/
393
394/*! \fn QString OContact::groups() const
395 \internal
396 Returns the groups for the contact.
397*/
398
399/*! \fn QStringList OContact::groupList() const
400 \internal
401*/
402
403/*! \fn QString OContact::field(int) const
404 \internal
405*/
406
407/*! \fn void OContact::saveJournal( journal_action, const QString & = QString::null )
408 \internal
409*/
410
411/*! \fn void OContact::setUid( int id )
412 \internal
413 Sets the uid for this record to \a id.
414*/
415
416/*! \enum OContact::journal_action
417 \internal
418*/
419
420/*!
421 \internal
422*/
423QMap<int, QString> OContact::toMap() const
424{
425 QMap<int, QString> map = mMap;
426 QString cats = idsToString( categories() );
427 if ( !cats.isEmpty() )
428 map.insert( Qtopia::AddressCategory, cats );
429 return map;
430}
431
432/*!
433 Returns a rich text formatted QString representing the contents the contact.
434*/
435QString OContact::toRichText() const
436{
437 QString text;
438 QString value, comp, state;
439 QString str;
440 bool marker = false;
441
442 Config cfg("qpe");
443 cfg.setGroup("Appearance");
444 int addressformat = cfg.readNumEntry( "AddressFormat", Zip_City_State );
445
446 // name, jobtitle and company
447 if ( !(value = fullName()).isEmpty() )
448 text += "<b><h3><img src=\"addressbook/AddressBook\"> " + Qtopia::escapeString(value) + "</h3></b>";
449
450 if ( !(value = jobTitle()).isEmpty() )
451 text += Qtopia::escapeString(value) + " ";
452
453 comp = company();
454 if ( !(value = department()).isEmpty() ) {
455 text += Qtopia::escapeString(value);
456 if ( comp )
457 text += ", " + Qtopia::escapeString(comp);
458 }else if ( comp )
459 text += "<br>" + Qtopia::escapeString(comp);
460 text += "<br><hr>";
461
462 // defailt email
463 QString defEmail = defaultEmail();
464 if ( !defEmail.isEmpty() ){
465 text += "<b><img src=\"addressbook/email\"> " + QObject::tr("Default Email: ") + "</b>"
466 + Qtopia::escapeString(defEmail);
467 marker = true;
468 }
469
470 // business address
471 if ( !businessStreet().isEmpty() || !businessCity().isEmpty() ||
472 !businessZip().isEmpty() || !businessCountry().isEmpty() ) {
473 text += QObject::tr( "<br><b>Work Address:</b>" );
474 marker = true;
475 }
476
477 if ( !(value = businessStreet()).isEmpty() ){
478 text += "<br>" + Qtopia::escapeString(value);
479 marker = true;
480 }
481
482 switch( addressformat ){
483 case Zip_City_State:{ // Zip_Code City, State
484 state = businessState();
485 if ( !(value = businessZip()).isEmpty() ){
486 text += "<br>" + Qtopia::escapeString(value) + " ";
487 marker = true;
488
489 }
490 if ( !(value = businessCity()).isEmpty() ) {
491 marker = true;
492 if ( businessZip().isEmpty() && !businessStreet().isEmpty() )
493 text += "<br>";
494 text += Qtopia::escapeString(value);
495 if ( state )
496 text += ", " + Qtopia::escapeString(state);
497 } else if ( !state.isEmpty() ){
498 text += "<br>" + Qtopia::escapeString(state);
499 marker = true;
500 }
501 break;
502 }
503 case City_State_Zip:{ // City, State Zip_Code
504 state = businessState();
505 if ( !(value = businessCity()).isEmpty() ) {
506 marker = true;
507 text += "<br>" + Qtopia::escapeString(value);
508 if ( state )
509 text += ", " + Qtopia::escapeString(state);
510 } else if ( !state.isEmpty() ){
511 text += "<br>" + Qtopia::escapeString(state);
512 marker = true;
513 }
514 if ( !(value = businessZip()).isEmpty() ){
515 text += " " + Qtopia::escapeString(value);
516 marker = true;
517 }
518 break;
519 }
520 }
521
522 if ( !(value = businessCountry()).isEmpty() ){
523 text += "<br>" + Qtopia::escapeString(value);
524 marker = true;
525 }
526
527 // rest of Business data
528 str = office();
529 if ( !str.isEmpty() ){
530 text += "<br><b>" + QObject::tr("Office: ") + "</b>"
531 + Qtopia::escapeString(str);
532 marker = true;
533 }
534 str = businessWebpage();
535 if ( !str.isEmpty() ){
536 text += "<br><b><img src=\"addressbook/webpagework\"> " + QObject::tr("Business Web Page: ") + "</b>"
537 + Qtopia::escapeString(str);
538 marker = true;
539 }
540 str = businessPhone();
541 if ( !str.isEmpty() ){
542 text += "<br><b><img src=\"addressbook/phonework\"> " + QObject::tr("Business Phone: ") + "</b>"
543 + Qtopia::escapeString(str);
544 marker = true;
545 }
546 str = businessFax();
547 if ( !str.isEmpty() ){
548 text += "<br><b><img src=\"addressbook/faxwork\"> " + QObject::tr("Business Fax: ") + "</b>"
549 + Qtopia::escapeString(str);
550 marker = true;
551 }
552 str = businessMobile();
553 if ( !str.isEmpty() ){
554 text += "<br><b><img src=\"addressbook/mobilework\"> " + QObject::tr("Business Mobile: ") + "</b>"
555 + Qtopia::escapeString(str);
556 marker = true;
557 }
558 str = businessPager();
559 if ( !str.isEmpty() ){
560 text += "<br><b>" + QObject::tr("Business Pager: ") + "</b>"
561 + Qtopia::escapeString(str);
562 marker = true;
563 }
564
565 // text += "<br>";
566
567 // home address
568 if ( !homeStreet().isEmpty() || !homeCity().isEmpty() ||
569 !homeZip().isEmpty() || !homeCountry().isEmpty() ) {
570 text += QObject::tr( "<br><b>Home Address:</b>" );
571 marker = true;
572 }
573
574 if ( !(value = homeStreet()).isEmpty() ){
575 text += "<br>" + Qtopia::escapeString(value);
576 marker = true;
577 }
578
579 switch( addressformat ){
580 case Zip_City_State:{ // Zip_Code City, State
581 state = homeState();
582 if ( !(value = homeZip()).isEmpty() ){
583 text += "<br>" + Qtopia::escapeString(value) + " ";
584 marker = true;
585 }
586 if ( !(value = homeCity()).isEmpty() ) {
587 marker = true;
588 if ( homeZip().isEmpty() && !homeStreet().isEmpty() )
589 text += "<br>";
590 text += Qtopia::escapeString(value);
591 if ( !state.isEmpty() )
592 text += ", " + Qtopia::escapeString(state);
593 } else if (!state.isEmpty()) {
594 text += "<br>" + Qtopia::escapeString(state);
595 marker = true;
596 }
597 break;
598 }
599 case City_State_Zip:{ // City, State Zip_Code
600 state = homeState();
601 if ( !(value = homeCity()).isEmpty() ) {
602 marker = true;
603 text += "<br>" + Qtopia::escapeString(value);
604 if ( state )
605 text += ", " + Qtopia::escapeString(state);
606 } else if ( !state.isEmpty() ){
607 text += "<br>" + Qtopia::escapeString(state);
608 marker = true;
609 }
610 if ( !(value = homeZip()).isEmpty() ){
611 text += " " + Qtopia::escapeString(value);
612 marker = true;
613 }
614 break;
615 }
616 }
617
618 if ( !(value = homeCountry()).isEmpty() ){
619 text += "<br>" + Qtopia::escapeString(value);
620 marker = true;
621 }
622
623 // rest of Home data
624 str = homeWebpage();
625 if ( !str.isEmpty() ){
626 text += "<br><b><img src=\"addressbook/webpagehome\"> " + QObject::tr("Home Web Page: ") + "</b>"
627 + Qtopia::escapeString(str);
628 marker = true;
629 }
630 str = homePhone();
631 if ( !str.isEmpty() ){
632 text += "<br><b><img src=\"addressbook/phonehome\"> " + QObject::tr("Home Phone: ") + "</b>"
633 + Qtopia::escapeString(str);
634 marker = true;
635 }
636 str = homeFax();
637 if ( !str.isEmpty() ){
638 text += "<br><b><img src=\"addressbook/faxhome\"> " + QObject::tr("Home Fax: ") + "</b>"
639 + Qtopia::escapeString(str);
640 marker = true;
641 }
642 str = homeMobile();
643 if ( !str.isEmpty() ){
644 text += "<br><b><img src=\"addressbook/mobilehome\"> " + QObject::tr("Home Mobile: ") + "</b>"
645 + Qtopia::escapeString(str);
646 marker = true;
647 }
648
649 if ( marker )
650 text += "<br><hr>";
651
652 // the rest...
653 str = emails();
654 if ( !str.isEmpty() && ( str != defEmail ) )
655 text += "<br><b>" + QObject::tr("All Emails: ") + "</b>"
656 + Qtopia::escapeString(str);
657 str = profession();
658 if ( !str.isEmpty() )
659 text += "<br><b>" + QObject::tr("Profession: ") + "</b>"
660 + Qtopia::escapeString(str);
661 str = assistant();
662 if ( !str.isEmpty() )
663 text += "<br><b>" + QObject::tr("Assistant: ") + "</b>"
664 + Qtopia::escapeString(str);
665 str = manager();
666 if ( !str.isEmpty() )
667 text += "<br><b>" + QObject::tr("Manager: ") + "</b>"
668 + Qtopia::escapeString(str);
669 str = gender();
670 if ( !str.isEmpty() && str.toInt() != 0 ) {
671 text += "<br>";
672 if ( str.toInt() == 1 )
673 str = QObject::tr( "Male" );
674 else if ( str.toInt() == 2 )
675 str = QObject::tr( "Female" );
676 text += "<b>" + QObject::tr("Gender: ") + "</b>" + str;
677 }
678 str = spouse();
679 if ( !str.isEmpty() )
680 text += "<br><b>" + QObject::tr("Spouse: ") + "</b>"
681 + Qtopia::escapeString(str);
682 if ( birthday().isValid() ){
683 str = TimeString::numberDateString( birthday() );
684 text += "<br><b>" + QObject::tr("Birthday: ") + "</b>"
685 + Qtopia::escapeString(str);
686 }
687 if ( anniversary().isValid() ){
688 str = TimeString::numberDateString( anniversary() );
689 text += "<br><b>" + QObject::tr("Anniversary: ") + "</b>"
690 + Qtopia::escapeString(str);
691 }
692 str = children();
693 if ( !str.isEmpty() )
694 text += "<br><b>" + QObject::tr("Children: ") + "</b>"
695 + Qtopia::escapeString(str);
696
697 str = nickname();
698 if ( !str.isEmpty() )
699 text += "<br><b>" + QObject::tr("Nickname: ") + "</b>"
700 + Qtopia::escapeString(str);
701
702 // categories
703 if ( categoryNames("Contacts").count() ){
704 text += "<br><b>" + QObject::tr( "Category:") + "</b> ";
705 text += categoryNames("Contacts").join(", ");
706 }
707
708 // notes last
709 if ( !(value = notes()).isEmpty() ) {
710 text += "<br><hr><b>" + QObject::tr( "Notes:") + "</b> ";
711 QRegExp reg("\n");
712
713 //QString tmp = Qtopia::escapeString(value);
714 QString tmp = QStyleSheet::convertFromPlainText(value);
715 //tmp.replace( reg, "<br>" );
716 text += "<br>" + tmp + "<br>";
717 }
718 return text;
719}
720
721/*!
722 \internal
723*/
724void OContact::insert( int key, const QString &v )
725{
726 QString value = v.stripWhiteSpace();
727 if ( value.isEmpty() )
728 mMap.remove( key );
729 else
730 mMap.insert( key, value );
731}
732
733/*!
734 \internal
735*/
736void OContact::replace( int key, const QString & v )
737{
738 QString value = v.stripWhiteSpace();
739 if ( value.isEmpty() )
740 mMap.remove( key );
741 else
742 mMap.replace( key, value );
743}
744
745/*!
746 \internal
747*/
748QString OContact::find( int key ) const
749{
750 return mMap[key];
751}
752
753/*!
754 \internal
755*/
756QString OContact::displayAddress( const QString &street,
757 const QString &city,
758 const QString &state,
759 const QString &zip,
760 const QString &country ) const
761{
762 QString s = street;
763 if ( !street.isEmpty() )
764 s+= "\n";
765 s += city;
766 if ( !city.isEmpty() && !state.isEmpty() )
767 s += ", ";
768 s += state;
769 if ( !state.isEmpty() && !zip.isEmpty() )
770 s += " ";
771 s += zip;
772 if ( !country.isEmpty() && !s.isEmpty() )
773 s += "\n";
774 s += country;
775 return s;
776}
777
778/*!
779 \internal
780*/
781QString OContact::displayBusinessAddress() const
782{
783 return displayAddress( businessStreet(), businessCity(),
784 businessState(), businessZip(),
785 businessCountry() );
786}
787
788/*!
789 \internal
790*/
791QString OContact::displayHomeAddress() const
792{
793 return displayAddress( homeStreet(), homeCity(),
794 homeState(), homeZip(),
795 homeCountry() );
796}
797
798/*!
799 Returns the full name of the contact
800*/
801QString OContact::fullName() const
802{
803 QString title = find( Qtopia::Title );
804 QString firstName = find( Qtopia::FirstName );
805 QString middleName = find( Qtopia::MiddleName );
806 QString lastName = find( Qtopia::LastName );
807 QString suffix = find( Qtopia::Suffix );
808
809 QString name = title;
810 if ( !firstName.isEmpty() ) {
811 if ( !name.isEmpty() )
812 name += " ";
813 name += firstName;
814 }
815 if ( !middleName.isEmpty() ) {
816 if ( !name.isEmpty() )
817 name += " ";
818 name += middleName;
819 }
820 if ( !lastName.isEmpty() ) {
821 if ( !name.isEmpty() )
822 name += " ";
823 name += lastName;
824 }
825 if ( !suffix.isEmpty() ) {
826 if ( !name.isEmpty() )
827 name += " ";
828 name += suffix;
829 }
830 return name.simplifyWhiteSpace();
831}
832
833/*!
834 Returns a list of the names of the children of the contact.
835*/
836QStringList OContact::childrenList() const
837{
838 return QStringList::split( " ", find( Qtopia::Children ) );
839}
840
841/*! \fn void OContact::insertEmail( const QString &email )
842
843 Insert \a email into the email list. Ensures \a email can only be added
844 once. If there is no default email address set, it sets it to the \a email.
845*/
846
847/*! \fn void OContact::removeEmail( const QString &email )
848
849 Removes the \a email from the email list. If the default email was \a email,
850 then the default email address is assigned to the first email in the
851 email list
852*/
853
854/*! \fn void OContact::clearEmails()
855
856 Clears the email list.
857 */
858
859/*! \fn void OContact::insertEmails( const QStringList &emailList )
860
861 Appends the \a emailList to the exiting email list
862 */
863
864/*!
865 Returns a list of email addresses belonging to the contact, including
866 the default email address.
867*/
868QStringList OContact::emailList() const
869{
870 QString emailStr = emails();
871
872 QStringList r;
873 if ( !emailStr.isEmpty() ) {
874 qDebug(" emailstr ");
875 QStringList l = QStringList::split( emailSeparator(), emailStr );
876 for ( QStringList::ConstIterator it = l.begin();it != l.end();++it )
877 r += (*it).simplifyWhiteSpace();
878 }
879
880 return r;
881}
882
883/*!
884 \overload
885
886 Generates the string for the contact to be filed as from the first,
887 middle and last name of the contact.
888*/
889void OContact::setFileAs()
890{
891 QString lastName, firstName, middleName, fileas;
892
893 lastName = find( Qtopia::LastName );
894 firstName = find( Qtopia::FirstName );
895 middleName = find( Qtopia::MiddleName );
896 if ( !lastName.isEmpty() && !firstName.isEmpty()
897 && !middleName.isEmpty() )
898 fileas = lastName + ", " + firstName + " " + middleName;
899 else if ( !lastName.isEmpty() && !firstName.isEmpty() )
900 fileas = lastName + ", " + firstName;
901 else if ( !lastName.isEmpty() || !firstName.isEmpty() ||
902 !middleName.isEmpty() )
903 fileas = firstName + ( firstName.isEmpty() ? "" : " " )
904 + middleName + ( middleName.isEmpty() ? "" : " " )
905 + lastName;
906
907 replace( Qtopia::FileAs, fileas );
908}
909
910/*!
911 \internal
912 Appends the contact information to \a buf.
913*/
914void OContact::save( QString &buf ) const
915{
916 static const QStringList SLFIELDS = fields();
917 // I'm expecting "<Contact " in front of this...
918 for ( QMap<int, QString>::ConstIterator it = mMap.begin();
919 it != mMap.end(); ++it ) {
920 const QString &value = it.data();
921 int key = it.key();
922 if ( !value.isEmpty() ) {
923 if ( key == Qtopia::AddressCategory || key == Qtopia::AddressUid)
924 continue;
925
926 key -= Qtopia::AddressCategory+1;
927 buf += SLFIELDS[key];
928 buf += "=\"" + Qtopia::escapeString(value) + "\" ";
929 }
930 }
931 buf += customToXml();
932 if ( categories().count() > 0 )
933 buf += "Categories=\"" + idsToString( categories() ) + "\" ";
934 buf += "Uid=\"" + QString::number( uid() ) + "\" ";
935 // You need to close this yourself
936}
937
938
939/*!
940 \internal
941 Returns the list of fields belonging to a contact
942 Never change order of this list ! It has to be regarding
943 enum AddressBookFields !!
944*/
945QStringList OContact::fields()
946{
947 QStringList list;
948
949 list.append( "Title" ); // Not Used!
950 list.append( "FirstName" );
951 list.append( "MiddleName" );
952 list.append( "LastName" );
953 list.append( "Suffix" );
954 list.append( "FileAs" );
955
956 list.append( "JobTitle" );
957 list.append( "Department" );
958 list.append( "Company" );
959 list.append( "BusinessPhone" );
960 list.append( "BusinessFax" );
961 list.append( "BusinessMobile" );
962
963 list.append( "DefaultEmail" );
964 list.append( "Emails" );
965
966 list.append( "HomePhone" );
967 list.append( "HomeFax" );
968 list.append( "HomeMobile" );
969
970 list.append( "BusinessStreet" );
971 list.append( "BusinessCity" );
972 list.append( "BusinessState" );
973 list.append( "BusinessZip" );
974 list.append( "BusinessCountry" );
975 list.append( "BusinessPager" );
976 list.append( "BusinessWebPage" );
977
978 list.append( "Office" );
979 list.append( "Profession" );
980 list.append( "Assistant" );
981 list.append( "Manager" );
982
983 list.append( "HomeStreet" );
984 list.append( "HomeCity" );
985 list.append( "HomeState" );
986 list.append( "HomeZip" );
987 list.append( "HomeCountry" );
988 list.append( "HomeWebPage" );
989
990 list.append( "Spouse" );
991 list.append( "Gender" );
992 list.append( "Birthday" );
993 list.append( "Anniversary" );
994 list.append( "Nickname" );
995 list.append( "Children" );
996
997 list.append( "Notes" );
998 list.append( "Groups" );
999
1000 return list;
1001}
1002
1003
1004/*!
1005 Sets the list of email address for contact to those contained in \a str.
1006 Email address should be separated by ';'s.
1007*/
1008void OContact::setEmails( const QString &str )
1009{
1010 replace( Qtopia::Emails, str );
1011 if ( str.isEmpty() )
1012 setDefaultEmail( QString::null );
1013}
1014
1015/*!
1016 Sets the list of children for the contact to those contained in \a str.
1017*/
1018void OContact::setChildren( const QString &str )
1019{
1020 replace( Qtopia::Children, str );
1021}
1022
1023/*!
1024 \overload
1025 Returns TRUE if the contact matches the regular expression \a regexp.
1026 Otherwise returns FALSE.
1027*/
1028bool OContact::match( const QRegExp &r ) const
1029{
1030 setLastHitField( -1 );
1031 bool match;
1032 match = false;
1033 QMap<int, QString>::ConstIterator it;
1034 for ( it = mMap.begin(); it != mMap.end(); ++it ) {
1035 if ( (*it).find( r ) > -1 ) {
1036 setLastHitField( it.key() );
1037 match = true;
1038 break;
1039 }
1040 }
1041 return match;
1042}
1043
1044
1045QString OContact::toShortText() const
1046{
1047 return ( fullName() );
1048}
1049QString OContact::type() const
1050{
1051 return QString::fromLatin1( "OContact" );
1052}
1053
1054
1055
1056class QString OContact::recordField( int pos ) const
1057{
1058 QStringList SLFIELDS = fields(); // ?? why this ? (se)
1059 return SLFIELDS[pos];
1060}
1061
1062// In future releases, we should store birthday and anniversary
1063// internally as QDate instead of QString !
1064// QString is always too complicate to interprete (DD.MM.YY, DD/MM/YY, MM/DD/YY, etc..)(se)
1065
1066/*! \fn void OContact::setBirthday( const QDate& date )
1067 Sets the birthday for the contact to \a date. If date is null
1068 the current stored date will be removed.
1069*/
1070void OContact::setBirthday( const QDate &v )
1071{
1072 if ( v.isNull() ){
1073 qWarning( "Remove Birthday");
1074 replace( Qtopia::Birthday, QString::null );
1075 return;
1076 }
1077
1078 if ( v.isValid() )
1079 replace( Qtopia::Birthday, OConversion::dateToString( v ) );
1080
1081}
1082
1083
1084/*! \fn void OContact::setAnniversary( const QDate &date )
1085 Sets the anniversary of the contact to \a date. If date is
1086 null, the current stored date will be removed.
1087*/
1088void OContact::setAnniversary( const QDate &v )
1089{
1090 if ( v.isNull() ){
1091 qWarning( "Remove Anniversary");
1092 replace( Qtopia::Anniversary, QString::null );
1093 return;
1094 }
1095
1096 if ( v.isValid() )
1097 replace( Qtopia::Anniversary, OConversion::dateToString( v ) );
1098}
1099
1100/*! \fn QDate OContact::birthday() const
1101 Returns the birthday of the contact.
1102*/
1103QDate OContact::birthday() const
1104{
1105 QString str = find( Qtopia::Birthday );
1106 // qWarning ("Birthday %s", str.latin1() );
1107 if ( !str.isEmpty() )
1108 return OConversion::dateFromString ( str );
1109 else
1110 return QDate();
1111}
1112
1113
1114/*! \fn QDate OContact::anniversary() const
1115 Returns the anniversary of the contact.
1116*/
1117QDate OContact::anniversary() const
1118{
1119 QDate empty;
1120 QString str = find( Qtopia::Anniversary );
1121 // qWarning ("Anniversary %s", str.latin1() );
1122 if ( !str.isEmpty() )
1123 return OConversion::dateFromString ( str );
1124 else
1125 return empty;
1126}
1127
1128
1129void OContact::insertEmail( const QString &v )
1130{
1131 //qDebug("insertEmail %s", v.latin1());
1132 QString e = v.simplifyWhiteSpace();
1133 QString def = defaultEmail();
1134
1135 // if no default, set it as the default email and don't insert
1136 if ( def.isEmpty() ) {
1137 setDefaultEmail( e ); // will insert into the list for us
1138 return;
1139 }
1140
1141 // otherwise, insert assuming doesn't already exist
1142 QString emailsStr = find( Qtopia::Emails );
1143 if ( emailsStr.contains( e ))
1144 return;
1145 if ( !emailsStr.isEmpty() )
1146 emailsStr += emailSeparator();
1147 emailsStr += e;
1148 replace( Qtopia::Emails, emailsStr );
1149}
1150
1151void OContact::removeEmail( const QString &v )
1152{
1153 QString e = v.simplifyWhiteSpace();
1154 QString def = defaultEmail();
1155 QString emailsStr = find( Qtopia::Emails );
1156 QStringList emails = emailList();
1157
1158 // otherwise, must first contain it
1159 if ( !emailsStr.contains( e ) )
1160 return;
1161
1162 // remove it
1163 //qDebug(" removing email from list %s", e.latin1());
1164 emails.remove( e );
1165 // reset the string
1166 emailsStr = emails.join(emailSeparator()); // Sharp's brain dead separator
1167 replace( Qtopia::Emails, emailsStr );
1168
1169 // if default, then replace the default email with the first one
1170 if ( def == e ) {
1171 //qDebug("removeEmail is default; setting new default");
1172 if ( !emails.count() )
1173 clearEmails();
1174 else // setDefaultEmail will remove e from the list
1175 setDefaultEmail( emails.first() );
1176 }
1177}
1178void OContact::clearEmails()
1179{
1180 mMap.remove( Qtopia::DefaultEmail );
1181 mMap.remove( Qtopia::Emails );
1182}
1183void OContact::setDefaultEmail( const QString &v )
1184{
1185 QString e = v.simplifyWhiteSpace();
1186
1187 //qDebug("OContact::setDefaultEmail %s", e.latin1());
1188 replace( Qtopia::DefaultEmail, e );
1189
1190 if ( !e.isEmpty() )
1191 insertEmail( e );
1192
1193}
1194
1195void OContact::insertEmails( const QStringList &v )
1196{
1197 for ( QStringList::ConstIterator it = v.begin(); it != v.end(); ++it )
1198 insertEmail( *it );
1199}
1200int OContact::rtti() {
1201 return OPimResolver::AddressBook;
1202}
1203void OContact::setUid( int i )
1204{
1205 OPimRecord::setUid(i);
1206 replace( Qtopia::AddressUid , QString::number(i));
1207}