summaryrefslogtreecommitdiff
authoreilers <eilers>2002-10-27 16:20:03 (UTC)
committer eilers <eilers>2002-10-27 16:20:03 (UTC)
commit1d1fdae1ff88ed6f1e331cbbab59fc978c04b370 (patch) (unidiff)
tree42041d05d79624d247a52375b9a9e19d70efaca5
parentcc01384d8c2b421d5f455f32631d8c2ec4b7e844 (diff)
downloadopie-1d1fdae1ff88ed6f1e331cbbab59fc978c04b370.zip
opie-1d1fdae1ff88ed6f1e331cbbab59fc978c04b370.tar.gz
opie-1d1fdae1ff88ed6f1e331cbbab59fc978c04b370.tar.bz2
ocontact now uses QDate for Birthday and Anniversary.. Moved
some inline functions into the library
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--libopie/pim/ocontact.cpp168
-rw-r--r--libopie/pim/ocontact.h82
-rw-r--r--libopie2/opiepim/ocontact.cpp168
-rw-r--r--libopie2/opiepim/ocontact.h82
4 files changed, 294 insertions, 206 deletions
diff --git a/libopie/pim/ocontact.cpp b/libopie/pim/ocontact.cpp
index 6f648ac..21fc088 100644
--- a/libopie/pim/ocontact.cpp
+++ b/libopie/pim/ocontact.cpp
@@ -1,14 +1,15 @@
1/********************************************************************** 1/**********************************************************************
2** Copyright (C) 2000-2002 Trolltech AS. All rights reserved. 2** Copyright (C) 2000-2002 Trolltech AS. All rights reserved.
3** Copyright (C) 2002 by Stefan Eilers (eilers.stefan@epost.de)
3** 4**
4** This file is part of the Qtopia Environment. 5** This file is part of the Qtopia Environment.
5** 6**
6** This file may be distributed and/or modified under the terms of the 7** This file may be distributed and/or modified under the terms of the
7** GNU General Public License version 2 as published by the Free Software 8** GNU General Public License version 2 as published by the Free Software
8** Foundation and appearing in the file LICENSE.GPL included in the 9** Foundation and appearing in the file LICENSE.GPL included in the
9** packaging of this file. 10** packaging of this file.
10** 11**
11** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE 12** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
12** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. 13** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
13** 14**
14** See http://www.trolltech.com/gpl/ for GPL licensing information. 15** See http://www.trolltech.com/gpl/ for GPL licensing information.
@@ -17,24 +18,25 @@
17** not clear to you. 18** not clear to you.
18** 19**
19**********************************************************************/ 20**********************************************************************/
20 21
21#define QTOPIA_INTERNAL_CONTACT_MRE 22#define QTOPIA_INTERNAL_CONTACT_MRE
22 23
23#include "ocontact.h" 24#include "ocontact.h"
24#include "../../library/backend/vobject_p.h" 25#include "../../library/backend/vobject_p.h"
25#include "../../library/backend/qfiledirect_p.h" 26#include "../../library/backend/qfiledirect_p.h"
26 27
27#include <qpe/stringutil.h> 28#include <qpe/stringutil.h>
28#include <qpe/timeconversion.h> 29#include <qpe/timeconversion.h>
30#include <qpe/timestring.h>
29 31
30#include <qobject.h> 32#include <qobject.h>
31#include <qregexp.h> 33#include <qregexp.h>
32#include <qstylesheet.h> 34#include <qstylesheet.h>
33#include <qfileinfo.h> 35#include <qfileinfo.h>
34#include <qmap.h> 36#include <qmap.h>
35 37
36#include <stdio.h> 38#include <stdio.h>
37 39
38/*! 40/*!
39 \class Contact contact.h 41 \class Contact contact.h
40 \brief The Contact class holds the data of an address book entry. 42 \brief The Contact class holds the data of an address book entry.
@@ -216,32 +218,24 @@ OContact::~OContact()
216/*! \fn void OContact::setManager( const QString &str ) 218/*! \fn void OContact::setManager( const QString &str )
217 Sets the manager of the contact to \a str. 219 Sets the manager of the contact to \a str.
218*/ 220*/
219 221
220/*! \fn void OContact::setSpouse( const QString &str ) 222/*! \fn void OContact::setSpouse( const QString &str )
221 Sets the spouse of the contact to \a str. 223 Sets the spouse of the contact to \a str.
222*/ 224*/
223 225
224/*! \fn void OContact::setGender( const QString &str ) 226/*! \fn void OContact::setGender( const QString &str )
225 Sets the gender of the contact to \a str. 227 Sets the gender of the contact to \a str.
226*/ 228*/
227 229
228/*! \fn void OContact::setBirthday( const QString &str )
229 Sets the birthday for the contact to \a str.
230*/
231
232/*! \fn void OContact::setAnniversary( const QString &str )
233 Sets the anniversary of the contact to \a str.
234*/
235
236/*! \fn void OContact::setNickname( const QString &str ) 230/*! \fn void OContact::setNickname( const QString &str )
237 Sets the nickname of the contact to \a str. 231 Sets the nickname of the contact to \a str.
238*/ 232*/
239 233
240/*! \fn void OContact::setNotes( const QString &str ) 234/*! \fn void OContact::setNotes( const QString &str )
241 Sets the notes about the contact to \a str. 235 Sets the notes about the contact to \a str.
242*/ 236*/
243 237
244/*! \fn QString OContact::title() const 238/*! \fn QString OContact::title() const
245 Returns the title of the contact. 239 Returns the title of the contact.
246*/ 240*/
247 241
@@ -377,32 +371,24 @@ OContact::~OContact()
377/*! \fn QString OContact::businessWebpage() const 371/*! \fn QString OContact::businessWebpage() const
378 Returns the business webpage of the contact. 372 Returns the business webpage of the contact.
379*/ 373*/
380 374
381/*! \fn QString OContact::spouse() const 375/*! \fn QString OContact::spouse() const
382 Returns the spouse of the contact. 376 Returns the spouse of the contact.
383*/ 377*/
384 378
385/*! \fn QString OContact::gender() const 379/*! \fn QString OContact::gender() const
386 Returns the gender of the contact. 380 Returns the gender of the contact.
387*/ 381*/
388 382
389/*! \fn QString OContact::birthday() const
390 Returns the birthday of the contact.
391*/
392
393/*! \fn QString OContact::anniversary() const
394 Returns the anniversary of the contact.
395*/
396
397/*! \fn QString OContact::nickname() const 383/*! \fn QString OContact::nickname() const
398 Returns the nickname of the contact. 384 Returns the nickname of the contact.
399*/ 385*/
400 386
401/*! \fn QString OContact::children() const 387/*! \fn QString OContact::children() const
402 Returns the children of the contact. 388 Returns the children of the contact.
403*/ 389*/
404 390
405/*! \fn QString OContact::notes() const 391/*! \fn QString OContact::notes() const
406 Returns the notes relating to the the contact. 392 Returns the notes relating to the the contact.
407*/ 393*/
408 394
@@ -576,32 +562,34 @@ QString OContact::toRichText() const
576 str = gender(); 562 str = gender();
577 if ( !str.isEmpty() && str.toInt() != 0 ) { 563 if ( !str.isEmpty() && str.toInt() != 0 ) {
578 if ( str.toInt() == 1 ) 564 if ( str.toInt() == 1 )
579 str = QObject::tr( "Male" ); 565 str = QObject::tr( "Male" );
580 else if ( str.toInt() == 2 ) 566 else if ( str.toInt() == 2 )
581 str = QObject::tr( "Female" ); 567 str = QObject::tr( "Female" );
582 text += "<b>" + QObject::tr("Gender: ") + "</b>" + str + "<br>"; 568 text += "<b>" + QObject::tr("Gender: ") + "</b>" + str + "<br>";
583 } 569 }
584 str = spouse(); 570 str = spouse();
585 if ( !str.isEmpty() ) 571 if ( !str.isEmpty() )
586 text += "<b>" + QObject::tr("Spouse: ") + "</b>" 572 text += "<b>" + QObject::tr("Spouse: ") + "</b>"
587 + Qtopia::escapeString(str) + "<br>"; 573 + Qtopia::escapeString(str) + "<br>";
588 str = birthday(); 574 if ( !birthday().isNull() ){
589 if ( !str.isEmpty() ) 575 str = TimeString::numberDateString( birthday() );
590 text += "<b>" + QObject::tr("Birthday: ") + "</b>" 576 text += "<b>" + QObject::tr("Birthday: ") + "</b>"
591 + Qtopia::escapeString(str) + "<br>"; 577 + Qtopia::escapeString(str) + "<br>";
592 str = anniversary(); 578 }
593 if ( !str.isEmpty() ) 579 if ( !anniversary().isNull() ){
594 text += "<b>" + QObject::tr("Anniversary: ") + "</b>" 580 str = TimeString::numberDateString( anniversary() );
595 + Qtopia::escapeString(str) + "<br>"; 581 text += "<b>" + QObject::tr("Anniversary: ") + "</b>"
582 + Qtopia::escapeString(str) + "<br>";
583 }
596 str = nickname(); 584 str = nickname();
597 if ( !str.isEmpty() ) 585 if ( !str.isEmpty() )
598 text += "<b>" + QObject::tr("Nickname: ") + "</b>" 586 text += "<b>" + QObject::tr("Nickname: ") + "</b>"
599 + Qtopia::escapeString(str) + "<br>"; 587 + Qtopia::escapeString(str) + "<br>";
600 588
601 // notes last 589 // notes last
602 if ( (value = notes()) ) { 590 if ( (value = notes()) ) {
603 QRegExp reg("\n"); 591 QRegExp reg("\n");
604 592
605 //QString tmp = Qtopia::escapeString(value); 593 //QString tmp = Qtopia::escapeString(value);
606 QString tmp = QStyleSheet::convertFromPlainText(value); 594 QString tmp = QStyleSheet::convertFromPlainText(value);
607 //tmp.replace( reg, "<br>" ); 595 //tmp.replace( reg, "<br>" );
@@ -1125,41 +1113,41 @@ static VObject *createVObject( const OContact &c )
1125 safeAddProp( title, VCWorkProp ); 1113 safeAddProp( title, VCWorkProp );
1126 1114
1127 1115
1128 QStringList emails = c.emailList(); 1116 QStringList emails = c.emailList();
1129 emails.prepend( c.defaultEmail() ); 1117 emails.prepend( c.defaultEmail() );
1130 for( QStringList::Iterator it = emails.begin(); it != emails.end(); ++it ) { 1118 for( QStringList::Iterator it = emails.begin(); it != emails.end(); ++it ) {
1131 VObject *email = safeAddPropValue( vcard, VCEmailAddressProp, *it ); 1119 VObject *email = safeAddPropValue( vcard, VCEmailAddressProp, *it );
1132 safeAddProp( email, VCInternetProp ); 1120 safeAddProp( email, VCInternetProp );
1133 } 1121 }
1134 1122
1135 safeAddPropValue( vcard, VCNoteProp, c.notes() ); 1123 safeAddPropValue( vcard, VCNoteProp, c.notes() );
1136 1124
1137 safeAddPropValue( vcard, VCBirthDateProp, c.birthday() ); 1125 safeAddPropValue( vcard, VCBirthDateProp, TimeConversion::toString( c.birthday() ) );
1138 1126
1139 if ( !c.company().isEmpty() || !c.department().isEmpty() || !c.office().isEmpty() ) { 1127 if ( !c.company().isEmpty() || !c.department().isEmpty() || !c.office().isEmpty() ) {
1140 VObject *org = safeAddProp( vcard, VCOrgProp ); 1128 VObject *org = safeAddProp( vcard, VCOrgProp );
1141 safeAddPropValue( org, VCOrgNameProp, c.company() ); 1129 safeAddPropValue( org, VCOrgNameProp, c.company() );
1142 safeAddPropValue( org, VCOrgUnitProp, c.department() ); 1130 safeAddPropValue( org, VCOrgUnitProp, c.department() );
1143 safeAddPropValue( org, VCOrgUnit2Prop, c.office() ); 1131 safeAddPropValue( org, VCOrgUnit2Prop, c.office() );
1144 } 1132 }
1145 1133
1146 // some values we have to export as custom fields 1134 // some values we have to export as custom fields
1147 safeAddPropValue( vcard, "X-Qtopia-Profession", c.profession() ); 1135 safeAddPropValue( vcard, "X-Qtopia-Profession", c.profession() );
1148 safeAddPropValue( vcard, "X-Qtopia-Manager", c.manager() ); 1136 safeAddPropValue( vcard, "X-Qtopia-Manager", c.manager() );
1149 safeAddPropValue( vcard, "X-Qtopia-Assistant", c.assistant() ); 1137 safeAddPropValue( vcard, "X-Qtopia-Assistant", c.assistant() );
1150 1138
1151 safeAddPropValue( vcard, "X-Qtopia-Spouse", c.spouse() ); 1139 safeAddPropValue( vcard, "X-Qtopia-Spouse", c.spouse() );
1152 safeAddPropValue( vcard, "X-Qtopia-Gender", c.gender() ); 1140 safeAddPropValue( vcard, "X-Qtopia-Gender", c.gender() );
1153 safeAddPropValue( vcard, "X-Qtopia-Anniversary", c.anniversary() ); 1141 safeAddPropValue( vcard, "X-Qtopia-Anniversary", TimeConversion::toString( c.anniversary() ) );
1154 safeAddPropValue( vcard, "X-Qtopia-Nickname", c.nickname() ); 1142 safeAddPropValue( vcard, "X-Qtopia-Nickname", c.nickname() );
1155 safeAddPropValue( vcard, "X-Qtopia-Children", c.children() ); 1143 safeAddPropValue( vcard, "X-Qtopia-Children", c.children() );
1156 1144
1157 return vcard; 1145 return vcard;
1158} 1146}
1159 1147
1160 1148
1161/*! 1149/*!
1162 \internal 1150 \internal
1163*/ 1151*/
1164static OContact parseVObject( VObject *obj ) 1152static OContact parseVObject( VObject *obj )
1165{ 1153{
@@ -1344,25 +1332,25 @@ static OContact parseVObject( VObject *obj )
1344 c.setManager( value ); 1332 c.setManager( value );
1345 } 1333 }
1346 else if ( name == "X-Qtopia-Assistant" ) { 1334 else if ( name == "X-Qtopia-Assistant" ) {
1347 c.setAssistant( value ); 1335 c.setAssistant( value );
1348 } 1336 }
1349 else if ( name == "X-Qtopia-Spouse" ) { 1337 else if ( name == "X-Qtopia-Spouse" ) {
1350 c.setSpouse( value ); 1338 c.setSpouse( value );
1351 } 1339 }
1352 else if ( name == "X-Qtopia-Gender" ) { 1340 else if ( name == "X-Qtopia-Gender" ) {
1353 c.setGender( value ); 1341 c.setGender( value );
1354 } 1342 }
1355 else if ( name == "X-Qtopia-Anniversary" ) { 1343 else if ( name == "X-Qtopia-Anniversary" ) {
1356 c.setAnniversary( value ); 1344 c.setAnniversary( TimeConversion::fromString( value ) );
1357 } 1345 }
1358 else if ( name == "X-Qtopia-Nickname" ) { 1346 else if ( name == "X-Qtopia-Nickname" ) {
1359 c.setNickname( value ); 1347 c.setNickname( value );
1360 } 1348 }
1361 else if ( name == "X-Qtopia-Children" ) { 1349 else if ( name == "X-Qtopia-Children" ) {
1362 c.setChildren( value ); 1350 c.setChildren( value );
1363 } 1351 }
1364 1352
1365 1353
1366#if 0 1354#if 0
1367 else { 1355 else {
1368 printf("Name: %s, value=%s\n", name.data(), vObjectStringZValue( o ) ); 1356 printf("Name: %s, value=%s\n", name.data(), vObjectStringZValue( o ) );
@@ -1484,12 +1472,138 @@ QString OContact::type() const
1484QMap<QString,QString> OContact::toExtraMap() const 1472QMap<QString,QString> OContact::toExtraMap() const
1485{ 1473{
1486 qWarning ("Function not implemented: OContact::toExtraMap()"); 1474 qWarning ("Function not implemented: OContact::toExtraMap()");
1487 QMap <QString,QString> useless; 1475 QMap <QString,QString> useless;
1488 return useless; 1476 return useless;
1489} 1477}
1490 1478
1491class QString OContact::recordField( int pos ) const 1479class QString OContact::recordField( int pos ) const
1492{ 1480{
1493 QStringList SLFIELDS = fields(); // ?? why this ? (se) 1481 QStringList SLFIELDS = fields(); // ?? why this ? (se)
1494 return SLFIELDS[pos]; 1482 return SLFIELDS[pos];
1495} 1483}
1484
1485// In future releases, we should store birthday and anniversary
1486// internally as QDate instead of QString !
1487// QString is always too complicate to interprete (DD.MM.YY, DD/MM/YY, MM/DD/YY, etc..)(se)
1488
1489/*! \fn void OContact::setBirthday( const QDate& date )
1490 Sets the birthday for the contact to \a date.
1491*/
1492void OContact::setBirthday( const QDate &v )
1493{
1494 if ( ( !v.isNull() ) && ( v.isValid() ) )
1495 replace( Qtopia::Birthday, TimeConversion::toString( v ) );
1496
1497}
1498
1499
1500/*! \fn void OContact::setAnniversary( const QDate &date )
1501 Sets the anniversary of the contact to \a date.
1502*/
1503void OContact::setAnniversary( const QDate &v )
1504{
1505 if ( ( !v.isNull() ) && ( v.isValid() ) )
1506 replace( Qtopia::Anniversary, TimeConversion::toString( v ) );
1507}
1508
1509/*! \fn QDate OContact::birthday() const
1510 Returns the birthday of the contact.
1511*/
1512QDate OContact::birthday() const
1513{
1514 QDate empty;
1515 QString str = find( Qtopia::Birthday );
1516 qWarning ("Birthday %s", str.latin1() );
1517 if ( !str.isEmpty() )
1518 return TimeConversion::fromString ( str );
1519 else
1520 return empty;
1521}
1522
1523
1524/*! \fn QDate OContact::anniversary() const
1525 Returns the anniversary of the contact.
1526*/
1527QDate OContact::anniversary() const
1528{
1529 QDate empty;
1530 QString str = find( Qtopia::Anniversary );
1531 qWarning ("Anniversary %s", str.latin1() );
1532 if ( !str.isEmpty() )
1533 return TimeConversion::fromString ( str );
1534 else
1535 return empty;
1536}
1537
1538
1539void OContact::insertEmail( const QString &v )
1540{
1541 //qDebug("insertEmail %s", v.latin1());
1542 QString e = v.simplifyWhiteSpace();
1543 QString def = defaultEmail();
1544
1545 // if no default, set it as the default email and don't insert
1546 if ( def.isEmpty() ) {
1547 setDefaultEmail( e ); // will insert into the list for us
1548 return;
1549 }
1550
1551 // otherwise, insert assuming doesn't already exist
1552 QString emailsStr = find( Qtopia::Emails );
1553 if ( emailsStr.contains( e ))
1554 return;
1555 if ( !emailsStr.isEmpty() )
1556 emailsStr += emailSeparator();
1557 emailsStr += e;
1558 replace( Qtopia::Emails, emailsStr );
1559}
1560
1561void OContact::removeEmail( const QString &v )
1562{
1563 QString e = v.simplifyWhiteSpace();
1564 QString def = defaultEmail();
1565 QString emailsStr = find( Qtopia::Emails );
1566 QStringList emails = emailList();
1567
1568 // otherwise, must first contain it
1569 if ( !emailsStr.contains( e ) )
1570 return;
1571
1572 // remove it
1573 //qDebug(" removing email from list %s", e.latin1());
1574 emails.remove( e );
1575 // reset the string
1576 emailsStr = emails.join(emailSeparator()); // Sharp's brain dead separator
1577 replace( Qtopia::Emails, emailsStr );
1578
1579 // if default, then replace the default email with the first one
1580 if ( def == e ) {
1581 //qDebug("removeEmail is default; setting new default");
1582 if ( !emails.count() )
1583 clearEmails();
1584 else // setDefaultEmail will remove e from the list
1585 setDefaultEmail( emails.first() );
1586 }
1587}
1588void OContact::clearEmails()
1589{
1590 mMap.remove( Qtopia::DefaultEmail );
1591 mMap.remove( Qtopia::Emails );
1592}
1593void OContact::setDefaultEmail( const QString &v )
1594{
1595 QString e = v.simplifyWhiteSpace();
1596
1597 //qDebug("OContact::setDefaultEmail %s", e.latin1());
1598 replace( Qtopia::DefaultEmail, e );
1599
1600 if ( !e.isEmpty() )
1601 insertEmail( e );
1602
1603}
1604
1605void OContact::insertEmails( const QStringList &v )
1606{
1607 for ( QStringList::ConstIterator it = v.begin(); it != v.end(); ++it )
1608 insertEmail( *it );
1609}
diff --git a/libopie/pim/ocontact.h b/libopie/pim/ocontact.h
index f916cf2..9e83150 100644
--- a/libopie/pim/ocontact.h
+++ b/libopie/pim/ocontact.h
@@ -1,38 +1,40 @@
1/********************************************************************** 1/**********************************************************************
2** Copyright (C) 2000-2002 Trolltech AS. All rights reserved. 2** Copyright (C) 2000-2002 Trolltech AS. All rights reserved.
3** Copyright (C) 2002 by Stefan Eilers (eilers.stefan@epost.de)
3** 4**
4** This file is part of the Qtopia Environment. 5** This file is part of the Qtopia Environment.
5** 6**
6** This file may be distributed and/or modified under the terms of the 7** This file may be distributed and/or modified under the terms of the
7** GNU General Public License version 2 as published by the Free Software 8** GNU General Public License version 2 as published by the Free Software
8** Foundation and appearing in the file LICENSE.GPL included in the 9** Foundation and appearing in the file LICENSE.GPL included in the
9** packaging of this file. 10** packaging of this file.
10** 11**
11** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE 12** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
12** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. 13** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
13** 14**
14** See http://www.trolltech.com/gpl/ for GPL licensing information. 15** See http://www.trolltech.com/gpl/ for GPL licensing information.
15** 16**
16** Contact info@trolltech.com if any conditions of this licensing are 17** Contact info@trolltech.com if any conditions of this licensing are
17** not clear to you. 18** not clear to you.
18** 19**
19**********************************************************************/ 20**********************************************************************/
20 21
21#ifndef __OCONTACT_H__ 22#ifndef __OCONTACT_H__
22#define __OCONTACT_H__ 23#define __OCONTACT_H__
23 24
24#include <opie/opimrecord.h> 25#include <opie/opimrecord.h>
25#include <qpe/recordfields.h> 26#include <qpe/recordfields.h>
26 27
28#include <qdatetime.h>
27#include <qstringlist.h> 29#include <qstringlist.h>
28 30
29#if defined(QPC_TEMPLATEDLL) 31#if defined(QPC_TEMPLATEDLL)
30// MOC_SKIP_BEGIN 32// MOC_SKIP_BEGIN
31QPC_TEMPLATEEXTERN template class QPC_EXPORT QMap<int, QString>; 33QPC_TEMPLATEEXTERN template class QPC_EXPORT QMap<int, QString>;
32// MOC_SKIP_END 34// MOC_SKIP_END
33#endif 35#endif
34 36
35class ContactPrivate; // Wozu ist das gut und wo ist das decrariert ? (se) 37class ContactPrivate; // Wozu ist das gut und wo ist das decrariert ? (se)
36class QPC_EXPORT OContact : public OPimRecord 38class QPC_EXPORT OContact : public OPimRecord
37{ 39{
38 friend class DataSet; 40 friend class DataSet;
@@ -87,26 +89,26 @@ public:
87 void setOffice( const QString &v ) { replace( Qtopia::Office, v ); } 89 void setOffice( const QString &v ) { replace( Qtopia::Office, v ); }
88 void setBusinessPhone( const QString &v ) { replace( Qtopia::BusinessPhone, v ); } 90 void setBusinessPhone( const QString &v ) { replace( Qtopia::BusinessPhone, v ); }
89 void setBusinessFax( const QString &v ) { replace( Qtopia::BusinessFax, v ); } 91 void setBusinessFax( const QString &v ) { replace( Qtopia::BusinessFax, v ); }
90 void setBusinessMobile( const QString &v ) { replace( Qtopia::BusinessMobile, v ); } 92 void setBusinessMobile( const QString &v ) { replace( Qtopia::BusinessMobile, v ); }
91 void setBusinessPager( const QString &v ) { replace( Qtopia::BusinessPager, v ); } 93 void setBusinessPager( const QString &v ) { replace( Qtopia::BusinessPager, v ); }
92 void setProfession( const QString &v ) { replace( Qtopia::Profession, v ); } 94 void setProfession( const QString &v ) { replace( Qtopia::Profession, v ); }
93 void setAssistant( const QString &v ) { replace( Qtopia::Assistant, v ); } 95 void setAssistant( const QString &v ) { replace( Qtopia::Assistant, v ); }
94 void setManager( const QString &v ) { replace( Qtopia::Manager, v ); } 96 void setManager( const QString &v ) { replace( Qtopia::Manager, v ); }
95 97
96 // personal 98 // personal
97 void setSpouse( const QString &v ) { replace( Qtopia::Spouse, v ); } 99 void setSpouse( const QString &v ) { replace( Qtopia::Spouse, v ); }
98 void setGender( const QString &v ) { replace( Qtopia::Gender, v ); } 100 void setGender( const QString &v ) { replace( Qtopia::Gender, v ); }
99 void setBirthday( const QString &v ) { replace( Qtopia::Birthday, v ); } 101 void setBirthday( const QDate &v );
100 void setAnniversary( const QString &v ) { replace( Qtopia::Anniversary, v ); } 102 void setAnniversary( const QDate &v );
101 void setNickname( const QString &v ) { replace( Qtopia::Nickname, v ); } 103 void setNickname( const QString &v ) { replace( Qtopia::Nickname, v ); }
102 void setChildren( const QString &v ); 104 void setChildren( const QString &v );
103 105
104 // other 106 // other
105 void setNotes( const QString &v ) { replace( Qtopia::Notes, v); } 107 void setNotes( const QString &v ) { replace( Qtopia::Notes, v); }
106 108
107 bool match( const QString &regexp ) const; 109 bool match( const QString &regexp ) const;
108 110
109// DON'T ATTEMPT TO USE THIS 111// DON'T ATTEMPT TO USE THIS
110#ifdef QTOPIA_INTERNAL_CONTACT_MRE 112#ifdef QTOPIA_INTERNAL_CONTACT_MRE
111 bool match( const QRegExp &regexp ) const; 113 bool match( const QRegExp &regexp ) const;
112#endif 114#endif
@@ -164,26 +166,26 @@ public:
164 QString assistant() const { return find( Qtopia::Assistant ); } 166 QString assistant() const { return find( Qtopia::Assistant ); }
165 QString manager() const { return find( Qtopia::Manager ); } 167 QString manager() const { return find( Qtopia::Manager ); }
166 /** Multi line string containing all non-empty address info in the form 168 /** Multi line string containing all non-empty address info in the form
167 * Street 169 * Street
168 * City, State Zip 170 * City, State Zip
169 * Country 171 * Country
170 */ 172 */
171 QString displayBusinessAddress() const; 173 QString displayBusinessAddress() const;
172 174
173 //personal 175 //personal
174 QString spouse() const { return find( Qtopia::Spouse ); } 176 QString spouse() const { return find( Qtopia::Spouse ); }
175 QString gender() const { return find( Qtopia::Gender ); } 177 QString gender() const { return find( Qtopia::Gender ); }
176 QString birthday() const { return find( Qtopia::Birthday ); } 178 QDate birthday() const;
177 QString anniversary() const { return find( Qtopia::Anniversary ); } 179 QDate anniversary() const;
178 QString nickname() const { return find( Qtopia::Nickname ); } 180 QString nickname() const { return find( Qtopia::Nickname ); }
179 QString children() const { return find( Qtopia::Children ); } 181 QString children() const { return find( Qtopia::Children ); }
180 QStringList childrenList() const; 182 QStringList childrenList() const;
181 183
182 // other 184 // other
183 QString notes() const { return find( Qtopia::Notes ); } 185 QString notes() const { return find( Qtopia::Notes ); }
184 QString groups() const { return find( Qtopia::Groups ); } 186 QString groups() const { return find( Qtopia::Groups ); }
185 QStringList groupList() const; 187 QStringList groupList() const;
186 188
187// // custom 189// // custom
188// const QString &customField( const QString &key ) 190// const QString &customField( const QString &key )
189// { return find( Custom- + key ); } 191// { return find( Custom- + key ); }
@@ -230,86 +232,14 @@ private:
230 QString displayAddress( const QString &street, 232 QString displayAddress( const QString &street,
231 const QString &city, 233 const QString &city,
232 const QString &state, 234 const QString &state,
233 const QString &zip, 235 const QString &zip,
234 const QString &country ) const; 236 const QString &country ) const;
235 237
236 Qtopia::UidGen &uidGen() { return sUidGen; } 238 Qtopia::UidGen &uidGen() { return sUidGen; }
237 static Qtopia::UidGen sUidGen; 239 static Qtopia::UidGen sUidGen;
238 QMap<int, QString> mMap; 240 QMap<int, QString> mMap;
239 ContactPrivate *d; 241 ContactPrivate *d;
240}; 242};
241 243
242// these methods are inlined to keep binary compatability with Qtopia 1.5
243inline void OContact::insertEmail( const QString &v )
244{
245 //qDebug("insertEmail %s", v.latin1());
246 QString e = v.simplifyWhiteSpace();
247 QString def = defaultEmail();
248
249 // if no default, set it as the default email and don't insert
250 if ( def.isEmpty() ) {
251 setDefaultEmail( e ); // will insert into the list for us
252 return;
253 }
254
255 // otherwise, insert assuming doesn't already exist
256 QString emailsStr = find( Qtopia::Emails );
257 if ( emailsStr.contains( e ))
258 return;
259 if ( !emailsStr.isEmpty() )
260 emailsStr += emailSeparator();
261 emailsStr += e;
262 replace( Qtopia::Emails, emailsStr );
263}
264
265inline void OContact::removeEmail( const QString &v )
266{
267 QString e = v.simplifyWhiteSpace();
268 QString def = defaultEmail();
269 QString emailsStr = find( Qtopia::Emails );
270 QStringList emails = emailList();
271
272 // otherwise, must first contain it
273 if ( !emailsStr.contains( e ) )
274 return;
275
276 // remove it
277 //qDebug(" removing email from list %s", e.latin1());
278 emails.remove( e );
279 // reset the string
280 emailsStr = emails.join(emailSeparator()); // Sharp's brain dead separator
281 replace( Qtopia::Emails, emailsStr );
282
283 // if default, then replace the default email with the first one
284 if ( def == e ) {
285 //qDebug("removeEmail is default; setting new default");
286 if ( !emails.count() )
287 clearEmails();
288 else // setDefaultEmail will remove e from the list
289 setDefaultEmail( emails.first() );
290 }
291}
292inline void OContact::clearEmails()
293{
294 mMap.remove( Qtopia::DefaultEmail );
295 mMap.remove( Qtopia::Emails );
296}
297inline void OContact::setDefaultEmail( const QString &v )
298{
299 QString e = v.simplifyWhiteSpace();
300
301 //qDebug("OContact::setDefaultEmail %s", e.latin1());
302 replace( Qtopia::DefaultEmail, e );
303
304 if ( !e.isEmpty() )
305 insertEmail( e );
306
307}
308
309inline void OContact::insertEmails( const QStringList &v )
310{
311 for ( QStringList::ConstIterator it = v.begin(); it != v.end(); ++it )
312 insertEmail( *it );
313}
314 244
315#endif 245#endif
diff --git a/libopie2/opiepim/ocontact.cpp b/libopie2/opiepim/ocontact.cpp
index 6f648ac..21fc088 100644
--- a/libopie2/opiepim/ocontact.cpp
+++ b/libopie2/opiepim/ocontact.cpp
@@ -1,14 +1,15 @@
1/********************************************************************** 1/**********************************************************************
2** Copyright (C) 2000-2002 Trolltech AS. All rights reserved. 2** Copyright (C) 2000-2002 Trolltech AS. All rights reserved.
3** Copyright (C) 2002 by Stefan Eilers (eilers.stefan@epost.de)
3** 4**
4** This file is part of the Qtopia Environment. 5** This file is part of the Qtopia Environment.
5** 6**
6** This file may be distributed and/or modified under the terms of the 7** This file may be distributed and/or modified under the terms of the
7** GNU General Public License version 2 as published by the Free Software 8** GNU General Public License version 2 as published by the Free Software
8** Foundation and appearing in the file LICENSE.GPL included in the 9** Foundation and appearing in the file LICENSE.GPL included in the
9** packaging of this file. 10** packaging of this file.
10** 11**
11** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE 12** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
12** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. 13** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
13** 14**
14** See http://www.trolltech.com/gpl/ for GPL licensing information. 15** See http://www.trolltech.com/gpl/ for GPL licensing information.
@@ -17,24 +18,25 @@
17** not clear to you. 18** not clear to you.
18** 19**
19**********************************************************************/ 20**********************************************************************/
20 21
21#define QTOPIA_INTERNAL_CONTACT_MRE 22#define QTOPIA_INTERNAL_CONTACT_MRE
22 23
23#include "ocontact.h" 24#include "ocontact.h"
24#include "../../library/backend/vobject_p.h" 25#include "../../library/backend/vobject_p.h"
25#include "../../library/backend/qfiledirect_p.h" 26#include "../../library/backend/qfiledirect_p.h"
26 27
27#include <qpe/stringutil.h> 28#include <qpe/stringutil.h>
28#include <qpe/timeconversion.h> 29#include <qpe/timeconversion.h>
30#include <qpe/timestring.h>
29 31
30#include <qobject.h> 32#include <qobject.h>
31#include <qregexp.h> 33#include <qregexp.h>
32#include <qstylesheet.h> 34#include <qstylesheet.h>
33#include <qfileinfo.h> 35#include <qfileinfo.h>
34#include <qmap.h> 36#include <qmap.h>
35 37
36#include <stdio.h> 38#include <stdio.h>
37 39
38/*! 40/*!
39 \class Contact contact.h 41 \class Contact contact.h
40 \brief The Contact class holds the data of an address book entry. 42 \brief The Contact class holds the data of an address book entry.
@@ -216,32 +218,24 @@ OContact::~OContact()
216/*! \fn void OContact::setManager( const QString &str ) 218/*! \fn void OContact::setManager( const QString &str )
217 Sets the manager of the contact to \a str. 219 Sets the manager of the contact to \a str.
218*/ 220*/
219 221
220/*! \fn void OContact::setSpouse( const QString &str ) 222/*! \fn void OContact::setSpouse( const QString &str )
221 Sets the spouse of the contact to \a str. 223 Sets the spouse of the contact to \a str.
222*/ 224*/
223 225
224/*! \fn void OContact::setGender( const QString &str ) 226/*! \fn void OContact::setGender( const QString &str )
225 Sets the gender of the contact to \a str. 227 Sets the gender of the contact to \a str.
226*/ 228*/
227 229
228/*! \fn void OContact::setBirthday( const QString &str )
229 Sets the birthday for the contact to \a str.
230*/
231
232/*! \fn void OContact::setAnniversary( const QString &str )
233 Sets the anniversary of the contact to \a str.
234*/
235
236/*! \fn void OContact::setNickname( const QString &str ) 230/*! \fn void OContact::setNickname( const QString &str )
237 Sets the nickname of the contact to \a str. 231 Sets the nickname of the contact to \a str.
238*/ 232*/
239 233
240/*! \fn void OContact::setNotes( const QString &str ) 234/*! \fn void OContact::setNotes( const QString &str )
241 Sets the notes about the contact to \a str. 235 Sets the notes about the contact to \a str.
242*/ 236*/
243 237
244/*! \fn QString OContact::title() const 238/*! \fn QString OContact::title() const
245 Returns the title of the contact. 239 Returns the title of the contact.
246*/ 240*/
247 241
@@ -377,32 +371,24 @@ OContact::~OContact()
377/*! \fn QString OContact::businessWebpage() const 371/*! \fn QString OContact::businessWebpage() const
378 Returns the business webpage of the contact. 372 Returns the business webpage of the contact.
379*/ 373*/
380 374
381/*! \fn QString OContact::spouse() const 375/*! \fn QString OContact::spouse() const
382 Returns the spouse of the contact. 376 Returns the spouse of the contact.
383*/ 377*/
384 378
385/*! \fn QString OContact::gender() const 379/*! \fn QString OContact::gender() const
386 Returns the gender of the contact. 380 Returns the gender of the contact.
387*/ 381*/
388 382
389/*! \fn QString OContact::birthday() const
390 Returns the birthday of the contact.
391*/
392
393/*! \fn QString OContact::anniversary() const
394 Returns the anniversary of the contact.
395*/
396
397/*! \fn QString OContact::nickname() const 383/*! \fn QString OContact::nickname() const
398 Returns the nickname of the contact. 384 Returns the nickname of the contact.
399*/ 385*/
400 386
401/*! \fn QString OContact::children() const 387/*! \fn QString OContact::children() const
402 Returns the children of the contact. 388 Returns the children of the contact.
403*/ 389*/
404 390
405/*! \fn QString OContact::notes() const 391/*! \fn QString OContact::notes() const
406 Returns the notes relating to the the contact. 392 Returns the notes relating to the the contact.
407*/ 393*/
408 394
@@ -576,32 +562,34 @@ QString OContact::toRichText() const
576 str = gender(); 562 str = gender();
577 if ( !str.isEmpty() && str.toInt() != 0 ) { 563 if ( !str.isEmpty() && str.toInt() != 0 ) {
578 if ( str.toInt() == 1 ) 564 if ( str.toInt() == 1 )
579 str = QObject::tr( "Male" ); 565 str = QObject::tr( "Male" );
580 else if ( str.toInt() == 2 ) 566 else if ( str.toInt() == 2 )
581 str = QObject::tr( "Female" ); 567 str = QObject::tr( "Female" );
582 text += "<b>" + QObject::tr("Gender: ") + "</b>" + str + "<br>"; 568 text += "<b>" + QObject::tr("Gender: ") + "</b>" + str + "<br>";
583 } 569 }
584 str = spouse(); 570 str = spouse();
585 if ( !str.isEmpty() ) 571 if ( !str.isEmpty() )
586 text += "<b>" + QObject::tr("Spouse: ") + "</b>" 572 text += "<b>" + QObject::tr("Spouse: ") + "</b>"
587 + Qtopia::escapeString(str) + "<br>"; 573 + Qtopia::escapeString(str) + "<br>";
588 str = birthday(); 574 if ( !birthday().isNull() ){
589 if ( !str.isEmpty() ) 575 str = TimeString::numberDateString( birthday() );
590 text += "<b>" + QObject::tr("Birthday: ") + "</b>" 576 text += "<b>" + QObject::tr("Birthday: ") + "</b>"
591 + Qtopia::escapeString(str) + "<br>"; 577 + Qtopia::escapeString(str) + "<br>";
592 str = anniversary(); 578 }
593 if ( !str.isEmpty() ) 579 if ( !anniversary().isNull() ){
594 text += "<b>" + QObject::tr("Anniversary: ") + "</b>" 580 str = TimeString::numberDateString( anniversary() );
595 + Qtopia::escapeString(str) + "<br>"; 581 text += "<b>" + QObject::tr("Anniversary: ") + "</b>"
582 + Qtopia::escapeString(str) + "<br>";
583 }
596 str = nickname(); 584 str = nickname();
597 if ( !str.isEmpty() ) 585 if ( !str.isEmpty() )
598 text += "<b>" + QObject::tr("Nickname: ") + "</b>" 586 text += "<b>" + QObject::tr("Nickname: ") + "</b>"
599 + Qtopia::escapeString(str) + "<br>"; 587 + Qtopia::escapeString(str) + "<br>";
600 588
601 // notes last 589 // notes last
602 if ( (value = notes()) ) { 590 if ( (value = notes()) ) {
603 QRegExp reg("\n"); 591 QRegExp reg("\n");
604 592
605 //QString tmp = Qtopia::escapeString(value); 593 //QString tmp = Qtopia::escapeString(value);
606 QString tmp = QStyleSheet::convertFromPlainText(value); 594 QString tmp = QStyleSheet::convertFromPlainText(value);
607 //tmp.replace( reg, "<br>" ); 595 //tmp.replace( reg, "<br>" );
@@ -1125,41 +1113,41 @@ static VObject *createVObject( const OContact &c )
1125 safeAddProp( title, VCWorkProp ); 1113 safeAddProp( title, VCWorkProp );
1126 1114
1127 1115
1128 QStringList emails = c.emailList(); 1116 QStringList emails = c.emailList();
1129 emails.prepend( c.defaultEmail() ); 1117 emails.prepend( c.defaultEmail() );
1130 for( QStringList::Iterator it = emails.begin(); it != emails.end(); ++it ) { 1118 for( QStringList::Iterator it = emails.begin(); it != emails.end(); ++it ) {
1131 VObject *email = safeAddPropValue( vcard, VCEmailAddressProp, *it ); 1119 VObject *email = safeAddPropValue( vcard, VCEmailAddressProp, *it );
1132 safeAddProp( email, VCInternetProp ); 1120 safeAddProp( email, VCInternetProp );
1133 } 1121 }
1134 1122
1135 safeAddPropValue( vcard, VCNoteProp, c.notes() ); 1123 safeAddPropValue( vcard, VCNoteProp, c.notes() );
1136 1124
1137 safeAddPropValue( vcard, VCBirthDateProp, c.birthday() ); 1125 safeAddPropValue( vcard, VCBirthDateProp, TimeConversion::toString( c.birthday() ) );
1138 1126
1139 if ( !c.company().isEmpty() || !c.department().isEmpty() || !c.office().isEmpty() ) { 1127 if ( !c.company().isEmpty() || !c.department().isEmpty() || !c.office().isEmpty() ) {
1140 VObject *org = safeAddProp( vcard, VCOrgProp ); 1128 VObject *org = safeAddProp( vcard, VCOrgProp );
1141 safeAddPropValue( org, VCOrgNameProp, c.company() ); 1129 safeAddPropValue( org, VCOrgNameProp, c.company() );
1142 safeAddPropValue( org, VCOrgUnitProp, c.department() ); 1130 safeAddPropValue( org, VCOrgUnitProp, c.department() );
1143 safeAddPropValue( org, VCOrgUnit2Prop, c.office() ); 1131 safeAddPropValue( org, VCOrgUnit2Prop, c.office() );
1144 } 1132 }
1145 1133
1146 // some values we have to export as custom fields 1134 // some values we have to export as custom fields
1147 safeAddPropValue( vcard, "X-Qtopia-Profession", c.profession() ); 1135 safeAddPropValue( vcard, "X-Qtopia-Profession", c.profession() );
1148 safeAddPropValue( vcard, "X-Qtopia-Manager", c.manager() ); 1136 safeAddPropValue( vcard, "X-Qtopia-Manager", c.manager() );
1149 safeAddPropValue( vcard, "X-Qtopia-Assistant", c.assistant() ); 1137 safeAddPropValue( vcard, "X-Qtopia-Assistant", c.assistant() );
1150 1138
1151 safeAddPropValue( vcard, "X-Qtopia-Spouse", c.spouse() ); 1139 safeAddPropValue( vcard, "X-Qtopia-Spouse", c.spouse() );
1152 safeAddPropValue( vcard, "X-Qtopia-Gender", c.gender() ); 1140 safeAddPropValue( vcard, "X-Qtopia-Gender", c.gender() );
1153 safeAddPropValue( vcard, "X-Qtopia-Anniversary", c.anniversary() ); 1141 safeAddPropValue( vcard, "X-Qtopia-Anniversary", TimeConversion::toString( c.anniversary() ) );
1154 safeAddPropValue( vcard, "X-Qtopia-Nickname", c.nickname() ); 1142 safeAddPropValue( vcard, "X-Qtopia-Nickname", c.nickname() );
1155 safeAddPropValue( vcard, "X-Qtopia-Children", c.children() ); 1143 safeAddPropValue( vcard, "X-Qtopia-Children", c.children() );
1156 1144
1157 return vcard; 1145 return vcard;
1158} 1146}
1159 1147
1160 1148
1161/*! 1149/*!
1162 \internal 1150 \internal
1163*/ 1151*/
1164static OContact parseVObject( VObject *obj ) 1152static OContact parseVObject( VObject *obj )
1165{ 1153{
@@ -1344,25 +1332,25 @@ static OContact parseVObject( VObject *obj )
1344 c.setManager( value ); 1332 c.setManager( value );
1345 } 1333 }
1346 else if ( name == "X-Qtopia-Assistant" ) { 1334 else if ( name == "X-Qtopia-Assistant" ) {
1347 c.setAssistant( value ); 1335 c.setAssistant( value );
1348 } 1336 }
1349 else if ( name == "X-Qtopia-Spouse" ) { 1337 else if ( name == "X-Qtopia-Spouse" ) {
1350 c.setSpouse( value ); 1338 c.setSpouse( value );
1351 } 1339 }
1352 else if ( name == "X-Qtopia-Gender" ) { 1340 else if ( name == "X-Qtopia-Gender" ) {
1353 c.setGender( value ); 1341 c.setGender( value );
1354 } 1342 }
1355 else if ( name == "X-Qtopia-Anniversary" ) { 1343 else if ( name == "X-Qtopia-Anniversary" ) {
1356 c.setAnniversary( value ); 1344 c.setAnniversary( TimeConversion::fromString( value ) );
1357 } 1345 }
1358 else if ( name == "X-Qtopia-Nickname" ) { 1346 else if ( name == "X-Qtopia-Nickname" ) {
1359 c.setNickname( value ); 1347 c.setNickname( value );
1360 } 1348 }
1361 else if ( name == "X-Qtopia-Children" ) { 1349 else if ( name == "X-Qtopia-Children" ) {
1362 c.setChildren( value ); 1350 c.setChildren( value );
1363 } 1351 }
1364 1352
1365 1353
1366#if 0 1354#if 0
1367 else { 1355 else {
1368 printf("Name: %s, value=%s\n", name.data(), vObjectStringZValue( o ) ); 1356 printf("Name: %s, value=%s\n", name.data(), vObjectStringZValue( o ) );
@@ -1484,12 +1472,138 @@ QString OContact::type() const
1484QMap<QString,QString> OContact::toExtraMap() const 1472QMap<QString,QString> OContact::toExtraMap() const
1485{ 1473{
1486 qWarning ("Function not implemented: OContact::toExtraMap()"); 1474 qWarning ("Function not implemented: OContact::toExtraMap()");
1487 QMap <QString,QString> useless; 1475 QMap <QString,QString> useless;
1488 return useless; 1476 return useless;
1489} 1477}
1490 1478
1491class QString OContact::recordField( int pos ) const 1479class QString OContact::recordField( int pos ) const
1492{ 1480{
1493 QStringList SLFIELDS = fields(); // ?? why this ? (se) 1481 QStringList SLFIELDS = fields(); // ?? why this ? (se)
1494 return SLFIELDS[pos]; 1482 return SLFIELDS[pos];
1495} 1483}
1484
1485// In future releases, we should store birthday and anniversary
1486// internally as QDate instead of QString !
1487// QString is always too complicate to interprete (DD.MM.YY, DD/MM/YY, MM/DD/YY, etc..)(se)
1488
1489/*! \fn void OContact::setBirthday( const QDate& date )
1490 Sets the birthday for the contact to \a date.
1491*/
1492void OContact::setBirthday( const QDate &v )
1493{
1494 if ( ( !v.isNull() ) && ( v.isValid() ) )
1495 replace( Qtopia::Birthday, TimeConversion::toString( v ) );
1496
1497}
1498
1499
1500/*! \fn void OContact::setAnniversary( const QDate &date )
1501 Sets the anniversary of the contact to \a date.
1502*/
1503void OContact::setAnniversary( const QDate &v )
1504{
1505 if ( ( !v.isNull() ) && ( v.isValid() ) )
1506 replace( Qtopia::Anniversary, TimeConversion::toString( v ) );
1507}
1508
1509/*! \fn QDate OContact::birthday() const
1510 Returns the birthday of the contact.
1511*/
1512QDate OContact::birthday() const
1513{
1514 QDate empty;
1515 QString str = find( Qtopia::Birthday );
1516 qWarning ("Birthday %s", str.latin1() );
1517 if ( !str.isEmpty() )
1518 return TimeConversion::fromString ( str );
1519 else
1520 return empty;
1521}
1522
1523
1524/*! \fn QDate OContact::anniversary() const
1525 Returns the anniversary of the contact.
1526*/
1527QDate OContact::anniversary() const
1528{
1529 QDate empty;
1530 QString str = find( Qtopia::Anniversary );
1531 qWarning ("Anniversary %s", str.latin1() );
1532 if ( !str.isEmpty() )
1533 return TimeConversion::fromString ( str );
1534 else
1535 return empty;
1536}
1537
1538
1539void OContact::insertEmail( const QString &v )
1540{
1541 //qDebug("insertEmail %s", v.latin1());
1542 QString e = v.simplifyWhiteSpace();
1543 QString def = defaultEmail();
1544
1545 // if no default, set it as the default email and don't insert
1546 if ( def.isEmpty() ) {
1547 setDefaultEmail( e ); // will insert into the list for us
1548 return;
1549 }
1550
1551 // otherwise, insert assuming doesn't already exist
1552 QString emailsStr = find( Qtopia::Emails );
1553 if ( emailsStr.contains( e ))
1554 return;
1555 if ( !emailsStr.isEmpty() )
1556 emailsStr += emailSeparator();
1557 emailsStr += e;
1558 replace( Qtopia::Emails, emailsStr );
1559}
1560
1561void OContact::removeEmail( const QString &v )
1562{
1563 QString e = v.simplifyWhiteSpace();
1564 QString def = defaultEmail();
1565 QString emailsStr = find( Qtopia::Emails );
1566 QStringList emails = emailList();
1567
1568 // otherwise, must first contain it
1569 if ( !emailsStr.contains( e ) )
1570 return;
1571
1572 // remove it
1573 //qDebug(" removing email from list %s", e.latin1());
1574 emails.remove( e );
1575 // reset the string
1576 emailsStr = emails.join(emailSeparator()); // Sharp's brain dead separator
1577 replace( Qtopia::Emails, emailsStr );
1578
1579 // if default, then replace the default email with the first one
1580 if ( def == e ) {
1581 //qDebug("removeEmail is default; setting new default");
1582 if ( !emails.count() )
1583 clearEmails();
1584 else // setDefaultEmail will remove e from the list
1585 setDefaultEmail( emails.first() );
1586 }
1587}
1588void OContact::clearEmails()
1589{
1590 mMap.remove( Qtopia::DefaultEmail );
1591 mMap.remove( Qtopia::Emails );
1592}
1593void OContact::setDefaultEmail( const QString &v )
1594{
1595 QString e = v.simplifyWhiteSpace();
1596
1597 //qDebug("OContact::setDefaultEmail %s", e.latin1());
1598 replace( Qtopia::DefaultEmail, e );
1599
1600 if ( !e.isEmpty() )
1601 insertEmail( e );
1602
1603}
1604
1605void OContact::insertEmails( const QStringList &v )
1606{
1607 for ( QStringList::ConstIterator it = v.begin(); it != v.end(); ++it )
1608 insertEmail( *it );
1609}
diff --git a/libopie2/opiepim/ocontact.h b/libopie2/opiepim/ocontact.h
index f916cf2..9e83150 100644
--- a/libopie2/opiepim/ocontact.h
+++ b/libopie2/opiepim/ocontact.h
@@ -1,38 +1,40 @@
1/********************************************************************** 1/**********************************************************************
2** Copyright (C) 2000-2002 Trolltech AS. All rights reserved. 2** Copyright (C) 2000-2002 Trolltech AS. All rights reserved.
3** Copyright (C) 2002 by Stefan Eilers (eilers.stefan@epost.de)
3** 4**
4** This file is part of the Qtopia Environment. 5** This file is part of the Qtopia Environment.
5** 6**
6** This file may be distributed and/or modified under the terms of the 7** This file may be distributed and/or modified under the terms of the
7** GNU General Public License version 2 as published by the Free Software 8** GNU General Public License version 2 as published by the Free Software
8** Foundation and appearing in the file LICENSE.GPL included in the 9** Foundation and appearing in the file LICENSE.GPL included in the
9** packaging of this file. 10** packaging of this file.
10** 11**
11** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE 12** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
12** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. 13** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
13** 14**
14** See http://www.trolltech.com/gpl/ for GPL licensing information. 15** See http://www.trolltech.com/gpl/ for GPL licensing information.
15** 16**
16** Contact info@trolltech.com if any conditions of this licensing are 17** Contact info@trolltech.com if any conditions of this licensing are
17** not clear to you. 18** not clear to you.
18** 19**
19**********************************************************************/ 20**********************************************************************/
20 21
21#ifndef __OCONTACT_H__ 22#ifndef __OCONTACT_H__
22#define __OCONTACT_H__ 23#define __OCONTACT_H__
23 24
24#include <opie/opimrecord.h> 25#include <opie/opimrecord.h>
25#include <qpe/recordfields.h> 26#include <qpe/recordfields.h>
26 27
28#include <qdatetime.h>
27#include <qstringlist.h> 29#include <qstringlist.h>
28 30
29#if defined(QPC_TEMPLATEDLL) 31#if defined(QPC_TEMPLATEDLL)
30// MOC_SKIP_BEGIN 32// MOC_SKIP_BEGIN
31QPC_TEMPLATEEXTERN template class QPC_EXPORT QMap<int, QString>; 33QPC_TEMPLATEEXTERN template class QPC_EXPORT QMap<int, QString>;
32// MOC_SKIP_END 34// MOC_SKIP_END
33#endif 35#endif
34 36
35class ContactPrivate; // Wozu ist das gut und wo ist das decrariert ? (se) 37class ContactPrivate; // Wozu ist das gut und wo ist das decrariert ? (se)
36class QPC_EXPORT OContact : public OPimRecord 38class QPC_EXPORT OContact : public OPimRecord
37{ 39{
38 friend class DataSet; 40 friend class DataSet;
@@ -87,26 +89,26 @@ public:
87 void setOffice( const QString &v ) { replace( Qtopia::Office, v ); } 89 void setOffice( const QString &v ) { replace( Qtopia::Office, v ); }
88 void setBusinessPhone( const QString &v ) { replace( Qtopia::BusinessPhone, v ); } 90 void setBusinessPhone( const QString &v ) { replace( Qtopia::BusinessPhone, v ); }
89 void setBusinessFax( const QString &v ) { replace( Qtopia::BusinessFax, v ); } 91 void setBusinessFax( const QString &v ) { replace( Qtopia::BusinessFax, v ); }
90 void setBusinessMobile( const QString &v ) { replace( Qtopia::BusinessMobile, v ); } 92 void setBusinessMobile( const QString &v ) { replace( Qtopia::BusinessMobile, v ); }
91 void setBusinessPager( const QString &v ) { replace( Qtopia::BusinessPager, v ); } 93 void setBusinessPager( const QString &v ) { replace( Qtopia::BusinessPager, v ); }
92 void setProfession( const QString &v ) { replace( Qtopia::Profession, v ); } 94 void setProfession( const QString &v ) { replace( Qtopia::Profession, v ); }
93 void setAssistant( const QString &v ) { replace( Qtopia::Assistant, v ); } 95 void setAssistant( const QString &v ) { replace( Qtopia::Assistant, v ); }
94 void setManager( const QString &v ) { replace( Qtopia::Manager, v ); } 96 void setManager( const QString &v ) { replace( Qtopia::Manager, v ); }
95 97
96 // personal 98 // personal
97 void setSpouse( const QString &v ) { replace( Qtopia::Spouse, v ); } 99 void setSpouse( const QString &v ) { replace( Qtopia::Spouse, v ); }
98 void setGender( const QString &v ) { replace( Qtopia::Gender, v ); } 100 void setGender( const QString &v ) { replace( Qtopia::Gender, v ); }
99 void setBirthday( const QString &v ) { replace( Qtopia::Birthday, v ); } 101 void setBirthday( const QDate &v );
100 void setAnniversary( const QString &v ) { replace( Qtopia::Anniversary, v ); } 102 void setAnniversary( const QDate &v );
101 void setNickname( const QString &v ) { replace( Qtopia::Nickname, v ); } 103 void setNickname( const QString &v ) { replace( Qtopia::Nickname, v ); }
102 void setChildren( const QString &v ); 104 void setChildren( const QString &v );
103 105
104 // other 106 // other
105 void setNotes( const QString &v ) { replace( Qtopia::Notes, v); } 107 void setNotes( const QString &v ) { replace( Qtopia::Notes, v); }
106 108
107 bool match( const QString &regexp ) const; 109 bool match( const QString &regexp ) const;
108 110
109// DON'T ATTEMPT TO USE THIS 111// DON'T ATTEMPT TO USE THIS
110#ifdef QTOPIA_INTERNAL_CONTACT_MRE 112#ifdef QTOPIA_INTERNAL_CONTACT_MRE
111 bool match( const QRegExp &regexp ) const; 113 bool match( const QRegExp &regexp ) const;
112#endif 114#endif
@@ -164,26 +166,26 @@ public:
164 QString assistant() const { return find( Qtopia::Assistant ); } 166 QString assistant() const { return find( Qtopia::Assistant ); }
165 QString manager() const { return find( Qtopia::Manager ); } 167 QString manager() const { return find( Qtopia::Manager ); }
166 /** Multi line string containing all non-empty address info in the form 168 /** Multi line string containing all non-empty address info in the form
167 * Street 169 * Street
168 * City, State Zip 170 * City, State Zip
169 * Country 171 * Country
170 */ 172 */
171 QString displayBusinessAddress() const; 173 QString displayBusinessAddress() const;
172 174
173 //personal 175 //personal
174 QString spouse() const { return find( Qtopia::Spouse ); } 176 QString spouse() const { return find( Qtopia::Spouse ); }
175 QString gender() const { return find( Qtopia::Gender ); } 177 QString gender() const { return find( Qtopia::Gender ); }
176 QString birthday() const { return find( Qtopia::Birthday ); } 178 QDate birthday() const;
177 QString anniversary() const { return find( Qtopia::Anniversary ); } 179 QDate anniversary() const;
178 QString nickname() const { return find( Qtopia::Nickname ); } 180 QString nickname() const { return find( Qtopia::Nickname ); }
179 QString children() const { return find( Qtopia::Children ); } 181 QString children() const { return find( Qtopia::Children ); }
180 QStringList childrenList() const; 182 QStringList childrenList() const;
181 183
182 // other 184 // other
183 QString notes() const { return find( Qtopia::Notes ); } 185 QString notes() const { return find( Qtopia::Notes ); }
184 QString groups() const { return find( Qtopia::Groups ); } 186 QString groups() const { return find( Qtopia::Groups ); }
185 QStringList groupList() const; 187 QStringList groupList() const;
186 188
187// // custom 189// // custom
188// const QString &customField( const QString &key ) 190// const QString &customField( const QString &key )
189// { return find( Custom- + key ); } 191// { return find( Custom- + key ); }
@@ -230,86 +232,14 @@ private:
230 QString displayAddress( const QString &street, 232 QString displayAddress( const QString &street,
231 const QString &city, 233 const QString &city,
232 const QString &state, 234 const QString &state,
233 const QString &zip, 235 const QString &zip,
234 const QString &country ) const; 236 const QString &country ) const;
235 237
236 Qtopia::UidGen &uidGen() { return sUidGen; } 238 Qtopia::UidGen &uidGen() { return sUidGen; }
237 static Qtopia::UidGen sUidGen; 239 static Qtopia::UidGen sUidGen;
238 QMap<int, QString> mMap; 240 QMap<int, QString> mMap;
239 ContactPrivate *d; 241 ContactPrivate *d;
240}; 242};
241 243
242// these methods are inlined to keep binary compatability with Qtopia 1.5
243inline void OContact::insertEmail( const QString &v )
244{
245 //qDebug("insertEmail %s", v.latin1());
246 QString e = v.simplifyWhiteSpace();
247 QString def = defaultEmail();
248
249 // if no default, set it as the default email and don't insert
250 if ( def.isEmpty() ) {
251 setDefaultEmail( e ); // will insert into the list for us
252 return;
253 }
254
255 // otherwise, insert assuming doesn't already exist
256 QString emailsStr = find( Qtopia::Emails );
257 if ( emailsStr.contains( e ))
258 return;
259 if ( !emailsStr.isEmpty() )
260 emailsStr += emailSeparator();
261 emailsStr += e;
262 replace( Qtopia::Emails, emailsStr );
263}
264
265inline void OContact::removeEmail( const QString &v )
266{
267 QString e = v.simplifyWhiteSpace();
268 QString def = defaultEmail();
269 QString emailsStr = find( Qtopia::Emails );
270 QStringList emails = emailList();
271
272 // otherwise, must first contain it
273 if ( !emailsStr.contains( e ) )
274 return;
275
276 // remove it
277 //qDebug(" removing email from list %s", e.latin1());
278 emails.remove( e );
279 // reset the string
280 emailsStr = emails.join(emailSeparator()); // Sharp's brain dead separator
281 replace( Qtopia::Emails, emailsStr );
282
283 // if default, then replace the default email with the first one
284 if ( def == e ) {
285 //qDebug("removeEmail is default; setting new default");
286 if ( !emails.count() )
287 clearEmails();
288 else // setDefaultEmail will remove e from the list
289 setDefaultEmail( emails.first() );
290 }
291}
292inline void OContact::clearEmails()
293{
294 mMap.remove( Qtopia::DefaultEmail );
295 mMap.remove( Qtopia::Emails );
296}
297inline void OContact::setDefaultEmail( const QString &v )
298{
299 QString e = v.simplifyWhiteSpace();
300
301 //qDebug("OContact::setDefaultEmail %s", e.latin1());
302 replace( Qtopia::DefaultEmail, e );
303
304 if ( !e.isEmpty() )
305 insertEmail( e );
306
307}
308
309inline void OContact::insertEmails( const QStringList &v )
310{
311 for ( QStringList::ConstIterator it = v.begin(); it != v.end(); ++it )
312 insertEmail( *it );
313}
314 244
315#endif 245#endif