author | zautrix <zautrix> | 2004-10-13 12:38:18 (UTC) |
---|---|---|
committer | zautrix <zautrix> | 2004-10-13 12:38:18 (UTC) |
commit | efdd0735bda81dcd82dfb6d6dc0d0c143f249336 (patch) (side-by-side diff) | |
tree | 8d67e4b51fbc3e8c48e1656c78054cfe6d2ead66 /kabc | |
parent | f22ee1ec902fe2fc610786f39049fb84542b8726 (diff) | |
download | kdepimpi-efdd0735bda81dcd82dfb6d6dc0d0c143f249336.zip kdepimpi-efdd0735bda81dcd82dfb6d6dc0d0c143f249336.tar.gz kdepimpi-efdd0735bda81dcd82dfb6d6dc0d0c143f249336.tar.bz2 |
mege contact fixes
-rw-r--r-- | kabc/addressee.cpp | 67 | ||||
-rw-r--r-- | kabc/phonenumber.cpp | 22 | ||||
-rw-r--r-- | kabc/phonenumber.h | 1 |
3 files changed, 53 insertions, 37 deletions
diff --git a/kabc/addressee.cpp b/kabc/addressee.cpp index cb10160..2aca559 100644 --- a/kabc/addressee.cpp +++ b/kabc/addressee.cpp @@ -214,285 +214,278 @@ void Addressee::computeCsum(const QString &dev) if ( !mData->familyName.isEmpty() ) l.append( mData->familyName ); if ( !mData->givenName.isEmpty() ) l.append(mData->givenName ); if ( !mData->additionalName ) l.append( mData->additionalName ); if ( !mData->prefix.isEmpty() ) l.append( mData->prefix ); if ( !mData->suffix.isEmpty() ) l.append( mData->suffix ); if ( !mData->nickName.isEmpty() ) l.append( mData->nickName ); if ( mData->birthday.isValid() ) l.append( mData->birthday.toString() ); if ( !mData->mailer.isEmpty() ) l.append( mData->mailer ); if ( mData->timeZone.isValid() ) l.append( mData->timeZone.asString() ); 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() ) if ( ! mData->url.path().isEmpty()) l.append( mData->url.path() ); 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 , bool isSubSet) // = false) { 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 ; QStringList t; QStringList tAD; uint iii; if ( isSubSet ) { // ********** phone numbers PhoneNumber::List phoneAD = ad.phoneNumbers(); PhoneNumber::List::Iterator phoneItAD; for ( phoneItAD = phoneAD.begin(); phoneItAD != phoneAD.end(); ++phoneItAD ) { bool found = false; PhoneNumber::List::Iterator it; for( it = mData->phoneNumbers.begin(); it != mData->phoneNumbers.end(); ++it ) { - if ( (*it) == ( *phoneItAD ) ) { + if ( ( *phoneItAD ).contains( (*it) ) ) { found = true; + (*it).setType( ( *phoneItAD ).type() ); break; } } if ( ! found ) mData->phoneNumbers.append( *phoneItAD ); } // ************* emails; t = mData->emails; tAD = ad.mData->emails; for ( iii = 0; iii < tAD.count(); ++iii) if ( !t.contains(tAD[iii] ) ) mData->emails.append( tAD[iii] ); // ************* categories; t = mData->categories; tAD = ad.mData->categories; for ( iii = 0; iii < tAD.count(); ++iii) if ( !t.contains(tAD[iii] ) ) mData->categories.append( tAD[iii] ); } QStringList::ConstIterator it; for( it = ad.mData->custom.begin(); it != ad.mData->custom.end(); ++it ) { QString qualifiedName = (*it).left( (*it).find( ":" )); bool found = false; QStringList::ConstIterator itL; for( itL = mData->custom.begin(); itL != mData->custom.end(); ++itL ) { if ( (*itL).startsWith( qualifiedName ) ) { found = true; break; } } if ( ! found ) { mData->custom.append( *it ); } } if ( mData->logo.undefined() && !ad.mData->logo.undefined() ) mData->logo = ad.mData->logo; if ( mData->photo.undefined() && !ad.mData->photo.undefined() ) mData->photo = ad.mData->photo; if ( !mData->sound.isIntern() ) { if ( mData->sound.url().isEmpty() ) { mData->sound = ad.mData->sound; } } if ( !mData->agent.isIntern() ) { if ( mData->agent.url().isEmpty() ) { mData->agent = ad.mData->agent; } } + { + Key::List::Iterator itA; + for( itA = ad.mData->keys.begin(); itA != ad.mData->keys.end(); ++itA ) { + bool found = false; + Key::List::Iterator it; + for( it = mData->keys.begin(); it != mData->keys.end(); ++it ) { + if ( (*it) == (*itA)) { + found = true; + break; -#if 0 - - if ( mData->url.isValid() ) - if ( ! mData->url.path().isEmpty()) l.append( mData->url.path() ); - 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] ); + } + } + if ( ! found ) { + mData->keys.append( *itA ); + } + } + } + KABC::Address::List::Iterator addressIterA; + for ( addressIterA = ad.mData->addresses.begin(); addressIterA != ad.mData->addresses.end(); ++addressIterA ) { + bool found = false; 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] ); + if ( (*addressIter) == (*addressIterA)) { + found = true; + (*addressIter).setType( (*addressIterA).type() ); + break; } -#endif - - // pending: - // merging addresses - // merging keys + } + if ( ! found ) { + mData->addresses.append( *addressIterA ); + } + } //qDebug("merge contact %s ", ad.uid().latin1()); setUid( ad.uid() ); setRevision( ad.revision() ); } bool Addressee::removeVoice() { PhoneNumber::List phoneN = phoneNumbers(); PhoneNumber::List::Iterator phoneIt; bool found = false; for ( phoneIt = phoneN.begin(); phoneIt != phoneN.end(); ++phoneIt ) { if ( (*phoneIt).type() & PhoneNumber::Voice) { // voice found if ((*phoneIt).type() - PhoneNumber::Voice ) { (*phoneIt).setType((*phoneIt).type() - PhoneNumber::Voice ); insertPhoneNumber( (*phoneIt) ); found = true; } } } return found; } bool Addressee::containsAdr(const Addressee& ad ) { if ( ! ad.mData->familyName.isEmpty() ) if ( mData->familyName != ad.mData->familyName) return false; if ( ! ad.mData->givenName.isEmpty() )if ( mData->givenName != ad.mData->givenName ) return false; if ( ad.mData->url.isValid() ) if (mData->url != ad.mData->url) return false ; if ( ! ad.mData->role.isEmpty() ) if (mData->role != ad.mData->role) return false ; if ( ! ad.mData->organization.isEmpty() ) if (mData->organization != ad.mData->organization) return false ; if ( ! ad.mData->note.isEmpty() ) if (mData->note != ad.mData->note) return false ; if ( ! ad.mData->title .isEmpty() ) if (mData->title != ad.mData->title ) return false ; // compare phone numbers PhoneNumber::List phoneN = ad.phoneNumbers(); PhoneNumber::List::Iterator phoneIt; bool found = false; for ( phoneIt = phoneN.begin(); phoneIt != phoneN.end(); ++phoneIt ) { bool found = false; PhoneNumber::List phoneL = ad.phoneNumbers(); PhoneNumber::List::Iterator phoneItL; for ( phoneItL = phoneL.begin(); phoneItL != phoneL.end(); ++phoneItL ) { if ( ( *phoneItL ).number() == ( *phoneIt ).number() ) { found = true; break; } } if ( ! found ) return false; } return true; } void Addressee::simplifyAddresses() { int max = 2; if ( mData->url.isValid() ) max = 1; if ( mData->addresses.count() <= max ) return ; int count = 0; Address::List list; Address::List::Iterator it; for( it = mData->addresses.begin(); it != mData->addresses.end(); ++it ) { if ( count >= max ) list.append( *it ); ++count; } for( it = list.begin(); it != list.end(); ++it ) { removeAddress( (*it) ); } } // 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 )); } diff --git a/kabc/phonenumber.cpp b/kabc/phonenumber.cpp index d7e3925..3d82553 100644 --- a/kabc/phonenumber.cpp +++ b/kabc/phonenumber.cpp @@ -1,185 +1,207 @@ /* 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 = ""; for ( i = 0; i < Number.length(); ++i) { if ( Number.at(i).isDigit() || Number.at(i) == '+'|| Number.at(i) == '*'|| Number.at(i) == '#' ) 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; } +bool PhoneNumber::contains( const PhoneNumber &p ) +{ + QString Number; + QString Num; + uint i; + Number = mNumber.stripWhiteSpace (); + Num = ""; + for ( i = 0; i < Number.length(); ++i) { + if ( Number.at(i).isDigit() || Number.at(i) == '+'|| Number.at(i) == '*'|| Number.at(i) == '#' ) + Num += Number.at(i); + } + QString NumberR; + QString NumR; + NumberR = p.mNumber.stripWhiteSpace (); + NumR = ""; + for ( i = 0; i < NumberR.length(); ++i) { + if ( NumberR.at(i).isDigit() || NumberR.at(i) == '+'|| NumberR.at(i) == '*'|| NumberR.at(i) == '#' ) + NumR += NumberR.at(i); + } + return (Num == NumR); +} + 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 410a52f..2d4d3e0 100644 --- a/kabc/phonenumber.h +++ b/kabc/phonenumber.h @@ -1,168 +1,169 @@ /* 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$ */ #ifndef KABC_PHONENUMBER_H #define KABC_PHONENUMBER_H #include <qvaluelist.h> #include <qstring.h> namespace KABC { /** @short Phonenumber information. This class provides phone number information. A phone number is classified by a type. The following types are available, it's possible to use multiple types @ref Types for a number by combining them through a logical or. */ class PhoneNumber { friend QDataStream &operator<<( QDataStream &, const PhoneNumber & ); friend QDataStream &operator>>( QDataStream &, PhoneNumber & ); public: typedef QValueList<PhoneNumber> List; typedef QValueList<int> TypeList; /** @li @p Home - Home number @li @p Work - Office number @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; + bool contains( const PhoneNumber &p ); /** 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 |