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