From 6b77a1cdb9536b1c135eb86d53a6b2c22c19b0a4 Mon Sep 17 00:00:00 2001 From: zecke Date: Tue, 10 Sep 2002 12:09:49 +0000 Subject: Qtopia1-6 merge still to test bic changes to be resolved more changes to be made? --- (limited to 'library/backend/contact.h') 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,7 +1,7 @@ /********************************************************************** -** 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 ** GNU General Public License version 2 as published by the Free Software @@ -21,14 +21,14 @@ #ifndef __CONTACT_H__ #define __CONTACT_H__ -#include -#include +#include +#include #include #if defined(QPC_TEMPLATEDLL) // MOC_SKIP_BEGIN -template class QPC_EXPORT QMap; +QPC_TEMPLATEEXTERN template class QPC_EXPORT QMap; // MOC_SKIP_END #endif @@ -56,9 +56,12 @@ public: void setFileAs(); // 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 void setHomeStreet( const QString &v ) { replace( Qtopia::HomeStreet, v ); } @@ -123,7 +126,6 @@ public: // email QString defaultEmail() const { return find( Qtopia::DefaultEmail ); } - QString emails() const { return find( Qtopia::Emails ); } QStringList emailList() const; // home @@ -202,7 +204,16 @@ public: { Record::setUid(i); replace( Qtopia::AddressUid , QString::number(i)); } 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 ); QString find( int key ) const; @@ -219,4 +230,77 @@ private: ContactPrivate *d; }; +// 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 -- cgit v0.9.0.2