-rw-r--r-- | library/backend/contact.h | 102 |
1 files changed, 93 insertions, 9 deletions
diff --git a/library/backend/contact.h b/library/backend/contact.h index a74cbbe..4999430 100644 --- a/library/backend/contact.h +++ b/library/backend/contact.h @@ -1,6 +1,6 @@ /********************************************************************** -** Copyright (C) 2001 Trolltech AS. All rights reserved. +** Copyright (C) 2000-2002 Trolltech AS. All rights reserved. ** -** This file is part of Qtopia Environment. +** This file is part of the Qtopia Environment. ** ** This file may be distributed and/or modified under the terms of the @@ -22,6 +22,6 @@ #define __CONTACT_H__ -#include <qpe/palmtoprecord.h> -#include <qpe/recordfields.h> +#include <qtopia/private/palmtoprecord.h> +#include <qtopia/private/recordfields.h> #include <qstringlist.h> @@ -29,5 +29,5 @@ #if defined(QPC_TEMPLATEDLL) // MOC_SKIP_BEGIN -template class QPC_EXPORT QMap<int, QString>; +QPC_TEMPLATEEXTERN template class QPC_EXPORT QMap<int, QString>; // MOC_SKIP_END #endif @@ -57,7 +57,10 @@ public: // default email address - void setDefaultEmail( const QString &v ) { replace( Qtopia::DefaultEmail, v ); } - // the emails should be seperated by a semicolon - void setEmails( const QString &v ); + void setDefaultEmail( const QString &v ); + // inserts email to list and ensure's doesn't already exist + void insertEmail( const QString &v ); + void removeEmail( const QString &v ); + void clearEmails(); + void insertEmails( const QStringList &v ); // home @@ -124,5 +127,4 @@ public: // email QString defaultEmail() const { return find( Qtopia::DefaultEmail ); } - QString emails() const { return find( Qtopia::Emails ); } QStringList emailList() const; @@ -203,5 +205,14 @@ public: private: + friend class AbEditor; friend class AbTable; + friend class AddressBookAccessPrivate; + friend class XMLIO; + + QString emailSeparator() const { return " "; } + // the emails should be seperated by a comma + void setEmails( const QString &v ); + QString emails() const { return find( Qtopia::Emails ); } + void insert( int key, const QString &value ); void replace( int key, const QString &value ); @@ -220,3 +231,76 @@ private: }; +// these methods are inlined to keep binary compatability with Qtopia 1.5 +inline void Contact::insertEmail( const QString &v ) +{ + //qDebug("insertEmail %s", v.latin1()); + QString e = v.simplifyWhiteSpace(); + QString def = defaultEmail(); + + // if no default, set it as the default email and don't insert + if ( def.isEmpty() ) { + setDefaultEmail( e ); // will insert into the list for us + return; + } + + // otherwise, insert assuming doesn't already exist + QString emailsStr = find( Qtopia::Emails ); + if ( emailsStr.contains( e )) + return; + if ( !emailsStr.isEmpty() ) + emailsStr += emailSeparator(); + emailsStr += e; + replace( Qtopia::Emails, emailsStr ); +} + +inline void Contact::removeEmail( const QString &v ) +{ + QString e = v.simplifyWhiteSpace(); + QString def = defaultEmail(); + QString emailsStr = find( Qtopia::Emails ); + QStringList emails = emailList(); + + // otherwise, must first contain it + if ( !emailsStr.contains( e ) ) + return; + + // remove it + //qDebug(" removing email from list %s", e.latin1()); + emails.remove( e ); + // reset the string + emailsStr = emails.join(emailSeparator()); // Sharp's brain dead separator + replace( Qtopia::Emails, emailsStr ); + + // if default, then replace the default email with the first one + if ( def == e ) { + //qDebug("removeEmail is default; setting new default"); + if ( !emails.count() ) + clearEmails(); + else // setDefaultEmail will remove e from the list + setDefaultEmail( emails.first() ); + } +} +inline void Contact::clearEmails() +{ + mMap.remove( Qtopia::DefaultEmail ); + mMap.remove( Qtopia::Emails ); +} +inline void Contact::setDefaultEmail( const QString &v ) +{ + QString e = v.simplifyWhiteSpace(); + + //qDebug("Contact::setDefaultEmail %s", e.latin1()); + replace( Qtopia::DefaultEmail, e ); + + if ( !e.isEmpty() ) + insertEmail( e ); + +} + +inline void Contact::insertEmails( const QStringList &v ) +{ + for ( QStringList::ConstIterator it = v.begin(); it != v.end(); ++it ) + insertEmail( *it ); +} + #endif |