author | zautrix <zautrix> | 2004-10-08 20:03:23 (UTC) |
---|---|---|
committer | zautrix <zautrix> | 2004-10-08 20:03:23 (UTC) |
commit | 10a0e05cc4962d9412a7a5faf3d69a3caf6d1c34 (patch) (side-by-side diff) | |
tree | 3105b985a9dbedd31dff52e14fe667eeff4f9ff4 /kabc | |
parent | 13bd085e06b76228321f5a004759fcdf19cca711 (diff) | |
download | kdepimpi-10a0e05cc4962d9412a7a5faf3d69a3caf6d1c34.zip kdepimpi-10a0e05cc4962d9412a7a5faf3d69a3caf6d1c34.tar.gz kdepimpi-10a0e05cc4962d9412a7a5faf3d69a3caf6d1c34.tar.bz2 |
added contact phone support
-rw-r--r-- | kabc/addressee.cpp | 32 | ||||
-rw-r--r-- | kabc/addressee.h | 4 | ||||
-rw-r--r-- | kabc/phonenumber.cpp | 23 | ||||
-rw-r--r-- | kabc/phonenumber.h | 2 |
4 files changed, 61 insertions, 0 deletions
diff --git a/kabc/addressee.cpp b/kabc/addressee.cpp index 25c77f6..e571980 100644 --- a/kabc/addressee.cpp +++ b/kabc/addressee.cpp @@ -222,192 +222,224 @@ void Addressee::computeCsum(const QString &dev) if ( mData->geo.isValid() ) l.append( mData->geo.asString() ); if ( !mData->title .isEmpty() ) l.append( mData->title ); if ( !mData->role.isEmpty() ) l.append( mData->role ); if ( !mData->organization.isEmpty() ) l.append( mData->organization ); if ( !mData->note.isEmpty() ) l.append( mData->note ); if ( !mData->productId.isEmpty() ) l.append(mData->productId ); if ( !mData->sortString.isEmpty() ) l.append( mData->sortString ); if ( mData->secrecy.isValid() ) l.append( mData->secrecy.asString()); // if ( !mData->logo.isEmpty() ) l.append( ); //if ( !mData->photo.isEmpty() ) l.append( ); //if ( !mData->sound.isEmpty() ) l.append( ); //if ( !mData->agent.isEmpty() ) l.append( ); //if ( mData->url.isValid() ) l.append( ); #if 0 if ( !mData->phoneNumbers.isEmpty() ) l.append( ); if ( !mData->addresses.isEmpty() ) l.append( ); //if ( !mData->keys.isEmpty() ) l.append( ); if ( !mData->emails.isEmpty() ) l.append( ); if ( !mData->categories .isEmpty() ) l.append( ); if ( !mData->custom.isEmpty() ) l.append( ); #endif KABC::PhoneNumber::List phoneNumbers; KABC::PhoneNumber::List::Iterator phoneIter; QStringList t; for ( phoneIter = mData->phoneNumbers.begin(); phoneIter != mData->phoneNumbers.end(); ++phoneIter ) t.append( ( *phoneIter ).number()+QString::number( ( *phoneIter ).type() ) ); t.sort(); uint iii; for ( iii = 0; iii < t.count(); ++iii) l.append( t[iii] ); t = mData->emails; t.sort(); for ( iii = 0; iii < t.count(); ++iii) l.append( t[iii] ); t = mData->categories; t.sort(); for ( iii = 0; iii < t.count(); ++iii) l.append( t[iii] ); t = mData->custom; t.sort(); for ( iii = 0; iii < t.count(); ++iii) l.append( t[iii] ); KABC::Address::List::Iterator addressIter; for ( addressIter = mData->addresses.begin(); addressIter != mData->addresses.end(); ++addressIter ) { t = (*addressIter).asList(); t.sort(); for ( iii = 0; iii < t.count(); ++iii) l.append( t[iii] ); } uint cs = getCsum4List(l); // qDebug("CSUM computed %d %s %s", cs,QString::number (cs ).latin1(), uid().latin1() ); setCsum( dev, QString::number (cs )); } void Addressee::mergeContact( const Addressee& ad ) { detach(); if ( mData->name.isEmpty() ) mData->name = ad.mData->name; if ( mData->formattedName.isEmpty() ) mData->formattedName = ad.mData->formattedName; if ( mData->familyName.isEmpty() ) mData->familyName = ad.mData->familyName; if ( mData->givenName.isEmpty() ) mData->givenName = ad.mData->givenName ; if ( mData->additionalName ) mData->additionalName = ad.mData->additionalName; if ( mData->prefix.isEmpty() ) mData->prefix = ad.mData->prefix; if ( mData->suffix.isEmpty() ) mData->suffix = ad.mData->suffix; if ( mData->nickName.isEmpty() ) mData->nickName = ad.mData->nickName; if ( !mData->birthday.isValid() ) if ( ad.mData->birthday.isValid()) mData->birthday = ad.mData->birthday; if ( mData->mailer.isEmpty() ) mData->mailer = ad.mData->mailer; if ( !mData->timeZone.isValid() ) mData->timeZone = ad.mData->timeZone; if ( !mData->geo.isValid() ) mData->geo = ad.mData->geo; if ( mData->title .isEmpty() ) mData->title = ad.mData->title ; if ( mData->role.isEmpty() ) mData->role = ad.mData->role ; if ( mData->organization.isEmpty() ) mData->organization = ad.mData->organization ; if ( mData->note.isEmpty() ) mData->note = ad.mData->note ; if ( mData->productId.isEmpty() ) mData->productId = ad.mData->productId; if ( mData->sortString.isEmpty() ) mData->sortString = ad.mData->sortString; if ( !mData->secrecy.isValid() ) mData->secrecy = ad.mData->secrecy; if ( ( !mData->url.isValid() && ad.mData->url.isValid() ) ) mData->url = ad.mData->url ; // pending: // merging phonenumbers // merging addresses // merging emails; // merging categories; // merging custom; // merging keys qDebug("merge contact %s ", ad.uid().latin1()); setUid( ad.uid() ); setRevision( ad.revision() ); } +// removes all emails but the first +// needed by phone sync +void Addressee::simplifyEmails() +{ + if ( mData->emails.count() == 0 ) return ; + QString email = mData->emails.first(); + detach(); + mData->emails.clear(); + mData->emails.append( email ); +} + +void Addressee::simplifyPhoneNumbers() +{ + KABC::PhoneNumber::List removeNumbers; + KABC::PhoneNumber::List::Iterator phoneIter; + for ( phoneIter = mData->phoneNumbers.begin(); phoneIter != mData->phoneNumbers.end(); + ++phoneIter ) { + if ( ! ( *phoneIter ).simplifyNumber() ) + removeNumbers.append( ( *phoneIter ) ); + } + for ( phoneIter = removeNumbers.begin(); phoneIter != removeNumbers.end(); + ++phoneIter ) { + removePhoneNumber(( *phoneIter )); + } +} +void Addressee::simplifyPhoneNumberTypes() +{ + KABC::PhoneNumber::List::Iterator phoneIter; + for ( phoneIter = mData->phoneNumbers.begin(); phoneIter != mData->phoneNumbers.end(); + ++phoneIter ) + ( *phoneIter ).simplifyType(); +} void Addressee::removeID(const QString &prof) { detach(); mData->mExternalId = KIdManager::removeId ( mData->mExternalId, prof); } void Addressee::setID( const QString & prof , const QString & id ) { detach(); mData->mExternalId = KIdManager::setId ( mData->mExternalId, prof, id ); //qDebug("setID2 %s %s %s",mData->mExternalId.latin1(), prof.latin1(), id.latin1() ); } void Addressee::setTempSyncStat( int id ) { if ( mData->mTempSyncStat == id ) return; detach(); mData->mTempSyncStat = id; } int Addressee::tempSyncStat() const { return mData->mTempSyncStat; } QString Addressee::getID( const QString & prof) { return KIdManager::getId ( mData->mExternalId, prof ); } void Addressee::setCsum( const QString & prof , const QString & id ) { detach(); //qDebug("setcsum1 %s %s %s",mData->mExternalId.latin1(), prof.latin1(), id.latin1() ); mData->mExternalId = KIdManager::setCsum ( mData->mExternalId, prof, id ); //qDebug("setcsum2 %s ",mData->mExternalId.latin1() ); } QString Addressee::getCsum( const QString & prof) { return KIdManager::getCsum ( mData->mExternalId, prof ); } void Addressee::setIDStr( const QString & s ) { detach(); mData->mExternalId = s; } QString Addressee::IDStr() const { return mData->mExternalId; } void Addressee::setExternalUID( const QString &id ) { if ( id == mData->externalUID ) return; detach(); mData->empty = false; mData->externalUID = id; } QString Addressee::externalUID() const { return mData->externalUID; } void Addressee::setOriginalExternalUID( const QString &id ) { if ( id == mData->originalExternalUID ) return; detach(); mData->empty = false; //qDebug("*******Set orig uid %s ", id.latin1()); mData->originalExternalUID = id; } QString Addressee::originalExternalUID() const { return mData->originalExternalUID; } void Addressee::setUid( const QString &id ) { if ( id == mData->uid ) return; detach(); //qDebug("****setuid %s ", id.latin1()); mData->empty = false; mData->uid = id; } QString Addressee::uid() const { if ( mData->uid.isEmpty() ) mData->uid = KApplication::randomString( 10 ); return mData->uid; } QString Addressee::uidLabel() diff --git a/kabc/addressee.h b/kabc/addressee.h index 8baa888..4cafa86 100644 --- a/kabc/addressee.h +++ b/kabc/addressee.h @@ -24,192 +24,196 @@ Enhanced Version of the file for platform independent KDE tools. Copyright (c) 2004 Ulf Schenk $Id$ */ #ifndef KABC_ADDRESSEE_H #define KABC_ADDRESSEE_H #include <qdatetime.h> #include <qstring.h> #include <qstringlist.h> #include <qvaluelist.h> #include <ksharedptr.h> #include <kurl.h> #include "address.h" #include "agent.h" #include "geo.h" #include "key.h" #include "phonenumber.h" #include "picture.h" #include "secrecy.h" #include "sound.h" #include "timezone.h" namespace KABC { class Resource; /** @short address book entry This class represents an entry in the address book. The data of this class is implicitly shared. You can pass this class by value. If you need the name of a field for presenting it to the user you should use the functions ending in Label(). They return a translated string which can be used as label for the corresponding field. About the name fields: givenName() is the first name and familyName() the last name. In some countries the family name comes first, that's the reason for the naming. formattedName() is the full name with the correct formatting. It is used as an override, when the correct formatting can't be generated from the other name fields automatically. realName() returns a fully formatted name(). It uses formattedName, if set, otherwise it constucts the name from the name fields. As fallback, if nothing else is set it uses name(). name() is the NAME type of RFC2426. It can be used as internal name for the data enty, but shouldn't be used for displaying the data to the user. */ class Addressee { friend QDataStream &operator<<( QDataStream &, const Addressee & ); friend QDataStream &operator>>( QDataStream &, Addressee & ); public: typedef QValueList<Addressee> List; /** Construct an empty address book entry. */ Addressee(); ~Addressee(); Addressee( const Addressee & ); Addressee &operator=( const Addressee & ); bool operator==( const Addressee & ) const; bool operator!=( const Addressee & ) const; // sync stuff void setTempSyncStat(int id); int tempSyncStat() const; void setIDStr( const QString & ); QString IDStr() const; void setID( const QString &, const QString & ); QString getID( const QString & ); void setCsum( const QString &, const QString & ); QString getCsum( const QString & ); void removeID(const QString &); void computeCsum(const QString &dev); ulong getCsum4List( const QStringList & attList); /** Return, if the address book entry is empty. */ bool isEmpty() const; void setExternalUID( const QString &id ); QString externalUID() const; void setOriginalExternalUID( const QString &id ); QString originalExternalUID() const; void mergeContact( const Addressee& ad ); + void simplifyEmails(); + void simplifyPhoneNumbers(); + void simplifyPhoneNumberTypes(); + /** Set unique identifier. */ void setUid( const QString &uid ); /** Return unique identifier. */ QString uid() const; /** Return translated label for uid field. */ static QString uidLabel(); /** Set name. */ void setName( const QString &name ); /** Return name. */ QString name() const; /** Return translated label for name field. */ static QString nameLabel(); /** Set formatted name. */ void setFormattedName( const QString &formattedName ); /** Return formatted name. */ QString formattedName() const; /** Return translated label for formattedName field. */ static QString formattedNameLabel(); /** Set family name. */ void setFamilyName( const QString &familyName ); /** Return family name. */ QString familyName() const; /** Return translated label for familyName field. */ static QString familyNameLabel(); /** Set given name. */ void setGivenName( const QString &givenName ); /** Return given name. */ QString givenName() const; /** Return translated label for givenName field. */ static QString givenNameLabel(); /** Set additional names. */ void setAdditionalName( const QString &additionalName ); /** Return additional names. */ QString additionalName() const; /** Return translated label for additionalName field. */ static QString additionalNameLabel(); /** Set honorific prefixes. */ void setPrefix( const QString &prefix ); /** Return honorific prefixes. */ QString prefix() const; /** Return translated label for prefix field. */ static QString prefixLabel(); /** Set honorific suffixes. */ void setSuffix( const QString &suffix ); /** diff --git a/kabc/phonenumber.cpp b/kabc/phonenumber.cpp index 7aeb2ee..e5abc0e 100644 --- a/kabc/phonenumber.cpp +++ b/kabc/phonenumber.cpp @@ -1,164 +1,187 @@ /* This file is part of libkabc. Copyright (c) 2001 Cornelius Schumacher <schumacher@kde.org> This library is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with this library; see the file COPYING.LIB. If not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ /* Enhanced Version of the file for platform independent KDE tools. Copyright (c) 2004 Ulf Schenk $Id$ */ #include <kapplication.h> #include <klocale.h> #include "phonenumber.h" using namespace KABC; PhoneNumber::PhoneNumber() : mType( Home ) { init(); } PhoneNumber::PhoneNumber( const QString &number, int type ) : mType( type ), mNumber( number ) { init(); } PhoneNumber::~PhoneNumber() { } void PhoneNumber::init() { mId = KApplication::randomString( 8 ); } bool PhoneNumber::operator==( const PhoneNumber &p ) const { if ( mNumber != p.mNumber ) return false; if ( mType != p.mType ) return false; return true; } bool PhoneNumber::operator!=( const PhoneNumber &p ) const { return !( p == *this ); } +bool PhoneNumber::simplifyNumber() +{ + QString Number; + int i; + Number = mNumber.stripWhiteSpace (); + mNumber = ""; + if ( Number.at(0) == '+' ) + mNumber += "+"; + for ( i = 0; i < Number.length(); ++i) { + if ( Number.at(i).isDigit() ) + mNumber += Number.at(i); + } + return ( mNumber.length() > 0 ); +} +// make cellphone compatible +void PhoneNumber::simplifyType() +{ + if ( mType & Fax ) mType = Fax; + else if ( mType & Cell ) mType = Cell; + else if ( mType & Work ) mType = Work ; + else if ( mType & Home ) mType = Home; + else mType = Pref; +} void PhoneNumber::setId( const QString &id ) { mId = id; } QString PhoneNumber::id() const { return mId; } void PhoneNumber::setNumber( const QString &number ) { mNumber = number; } QString PhoneNumber::number() const { return mNumber; } void PhoneNumber::setType( int type ) { mType = type; } int PhoneNumber::type() const { return mType; } QString PhoneNumber::typeLabel() const { QString label; bool first = true; TypeList list = typeList(); TypeList::Iterator it; for ( it = list.begin(); it != list.end(); ++it ) { if ( ( type() & (*it) ) && ( (*it) != Pref ) ) { label.append( ( first ? "" : "/" ) + typeLabel( *it ) ); if ( first ) first = false; } } return label; } QString PhoneNumber::label() const { return typeLabel( type() ); } PhoneNumber::TypeList PhoneNumber::typeList() { TypeList list; list << Home << Work << Msg << Pref << Voice << Fax << Cell << Video << Bbs << Modem << Car << Isdn << Pcs << Pager << Sip; return list; } QString PhoneNumber::label( int type ) { return typeLabel( type ); } QString PhoneNumber::typeLabel( int type ) { QString typeString; if ((type & Home) == Home) typeString += i18n("Home"); else if ((type & Work) == Work) typeString += i18n("Work"); if (!typeString.isEmpty()) typeString += " "; if ((type & Cell) == Cell) typeString += i18n("Mobile"); else if ((type & Fax) == Fax) typeString += i18n("Fax"); else if ((type & Msg) == Msg) typeString += i18n("Messenger"); else if ((type & Voice) == Voice) { // add nothing in case of the Voice flag // typeString += i18n("Voice"); } else if ((type & Video) == Video) typeString += i18n("Video"); else if ((type & Bbs) == Bbs) typeString += i18n("Mailbox"); else if ((type & Modem) == Modem) diff --git a/kabc/phonenumber.h b/kabc/phonenumber.h index 1df344f..410a52f 100644 --- a/kabc/phonenumber.h +++ b/kabc/phonenumber.h @@ -55,112 +55,114 @@ class PhoneNumber @li @p Msg - Messaging @li @p Pref - Preferred number @li @p Voice - Voice @li @p Fax - Fax machine @li @p Cell - Cell phone @li @p Video - Video phone @li @p Bbs - Mailbox @li @p Modem - Modem @li @p Car - Car phone @li @p Isdn - ISDN connection @li @p Pcs - Personal Communication Service @li @p Pager - Pager @li @p SIP - VoIP */ enum Types { Home = 1, Work = 2, Msg = 4, Pref = 8, Voice = 16, Fax = 32, Cell = 64, Video = 128, Bbs = 256, Modem = 512, Car = 1024, Isdn = 2048, Pcs = 4096, Pager = 8192, Sip = 16384 }; /** Create an empty phone number object. */ PhoneNumber(); /** Create a phonenumber object. @param number Number @param type Type as defined in enum. Multiple types can be specified by combining them by a logical or. */ PhoneNumber( const QString &number, int type = Home ); /** Destructor. */ ~PhoneNumber(); bool operator==( const PhoneNumber & ) const; bool operator!=( const PhoneNumber & ) const; /** Sets the unique identifier. */ void setId( const QString &id ); /** Returns the unique identifier. */ QString id() const; /** Sets the number. */ void setNumber( const QString & ); /** Returns the number. */ QString number() const; /** Sets the type. Multiple types can be specified by combining them by a logical or. */ void setType( int ); /** Returns the type. Can be a multiple types combined by a logical or. */ int type() const; /** Returns a translated string of all types the address has. */ QString typeLabel() const; /** Returns the translated label for phone number depending on its type. */ QString label() const; /** Returns a list of all available types */ static TypeList typeList(); /** Returns the translated label for phone number type. */ static QString typeLabel( int type ); /** Returns the translated label for phone number type. @obsolete */ static QString label( int type ); + bool simplifyNumber(); + void simplifyType(); private: void init(); QString mId; int mType; QString mNumber; }; QDataStream &operator<<( QDataStream &, const PhoneNumber & ); QDataStream &operator>>( QDataStream &, PhoneNumber & ); } #endif |