author | zautrix <zautrix> | 2004-09-18 22:33:39 (UTC) |
---|---|---|
committer | zautrix <zautrix> | 2004-09-18 22:33:39 (UTC) |
commit | f370d0f89bcaeeb68bd60152a9812a9cd55e5d8a (patch) (side-by-side diff) | |
tree | c1a9de8b305200a7cec885764a0afb4beb92dabb /kabc | |
parent | 28f894fd2a0dfbd5f09f9e530f359981efe0198c (diff) | |
download | kdepimpi-f370d0f89bcaeeb68bd60152a9812a9cd55e5d8a.zip kdepimpi-f370d0f89bcaeeb68bd60152a9812a9cd55e5d8a.tar.gz kdepimpi-f370d0f89bcaeeb68bd60152a9812a9cd55e5d8a.tar.bz2 |
more AB sync
-rw-r--r-- | kabc/address.cpp | 13 | ||||
-rw-r--r-- | kabc/address.h | 1 | ||||
-rw-r--r-- | kabc/addressbook.cpp | 133 | ||||
-rw-r--r-- | kabc/addressbook.h | 4 | ||||
-rw-r--r-- | kabc/addressee.cpp | 99 | ||||
-rw-r--r-- | kabc/addressee.h | 2 |
6 files changed, 213 insertions, 39 deletions
diff --git a/kabc/address.cpp b/kabc/address.cpp index c820a6c..5ffe511 100644 --- a/kabc/address.cpp +++ b/kabc/address.cpp @@ -43,96 +43,109 @@ using namespace KABC; QMap<QString, QString> Address::mISOMap; Address::Address() : mEmpty( true ), mType( 0 ) { mId = KApplication::randomString( 10 ); } Address::Address( int type ) : mEmpty( true ), mType( type ) { mId = KApplication::randomString( 10 ); } bool Address::operator==( const Address &a ) const { if ( mPostOfficeBox != a.mPostOfficeBox ) return false; if ( mExtended != a.mExtended ) return false; if ( mStreet != a.mStreet ) return false; if ( mLocality != a.mLocality ) return false; if ( mRegion != a.mRegion ) return false; if ( mPostalCode != a.mPostalCode ) return false; if ( mCountry != a.mCountry ) return false; if ( mLabel != a.mLabel ) return false; return true; } bool Address::operator!=( const Address &a ) const { return !( a == *this ); } bool Address::isEmpty() const { if ( mPostOfficeBox.isEmpty() && mExtended.isEmpty() && mStreet.isEmpty() && mLocality.isEmpty() && mRegion.isEmpty() && mPostalCode.isEmpty() && mCountry.isEmpty() && mLabel.isEmpty() ) { return true; } return false; } +QStringList Address::asList() +{ + QStringList result; + if ( ! mPostOfficeBox.isEmpty() )result.append(mPostOfficeBox); + if ( ! mExtended.isEmpty())result.append(mExtended); + if ( ! mStreet.isEmpty())result.append(mStreet); + if ( ! mLocality.isEmpty() )result.append(mLocality); + if ( ! mRegion.isEmpty())result.append(mRegion); + if ( ! mPostalCode.isEmpty())result.append(mPostalCode); + if ( ! mCountry.isEmpty())result.append(mCountry); + if ( ! mLabel.isEmpty() )result.append(mLabel); + return result; +} void Address::clear() { *this = Address(); } void Address::setId( const QString &id ) { mEmpty = false; mId = id; } QString Address::id() const { return mId; } void Address::setType( int type ) { mEmpty = false; mType = type; } int Address::type() const { return mType; } QString Address::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; } diff --git a/kabc/address.h b/kabc/address.h index ad132a7..6b53c7e 100644 --- a/kabc/address.h +++ b/kabc/address.h @@ -62,96 +62,97 @@ class Address friend QDataStream &operator<<( QDataStream &, const Address & ); friend QDataStream &operator>>( QDataStream &, Address & ); public: /** List of addresses. */ typedef QValueList<Address> List; typedef QValueList<int> TypeList; /** Address types: @li @p Dom - domestic @li @p Intl - international @li @p Postal - postal @li @p Parcel - parcel @li @p Home - home address @li @p Work - address at work @li @p Pref - preferred address */ enum Type { Dom = 1, Intl = 2, Postal = 4, Parcel = 8, Home = 16, Work = 32, Pref = 64 }; /** Constructor that creates an empty Address, which is initialized with a unique id (see @ref id()). */ Address(); /** This is like @ref Address() just above, with the difference that you can specify the type. */ Address( int ); bool operator==( const Address & ) const; bool operator!=( const Address & ) const; /** Returns true, if the address is empty. */ bool isEmpty() const; /** Clears all entries of the address. */ void clear(); + QStringList asList(); /** Sets the unique id. */ void setId( const QString & ); /* Returns the unique id. */ QString id() const; /** Sets the type of address. See enum for definiton of types. @param type type, can be a bitwise or of multiple types. */ void setType( int type ); /** Returns the type of address. Can be a bitwise or of multiple types. */ int type() const; /** Returns a translated string of all types the address has. */ QString typeLabel() const; /** Sets the post office box. */ void setPostOfficeBox( const QString & ); /** Returns the post office box. */ QString postOfficeBox() const; /** Returns the translated label for post office box field. */ static QString postOfficeBoxLabel(); /** Sets the extended address information. */ void setExtended( const QString & ); diff --git a/kabc/addressbook.cpp b/kabc/addressbook.cpp index 16e1653..ec9f893 100644 --- a/kabc/addressbook.cpp +++ b/kabc/addressbook.cpp @@ -189,96 +189,97 @@ AddressBook::ConstIterator &AddressBook::ConstIterator::operator++() AddressBook::ConstIterator &AddressBook::ConstIterator::operator++(int) { (d->mIt)++; return *this; } AddressBook::ConstIterator &AddressBook::ConstIterator::operator--() { (d->mIt)--; return *this; } AddressBook::ConstIterator &AddressBook::ConstIterator::operator--(int) { (d->mIt)--; return *this; } bool AddressBook::ConstIterator::operator==( const ConstIterator &it ) { return ( d->mIt == it.d->mIt ); } bool AddressBook::ConstIterator::operator!=( const ConstIterator &it ) { return ( d->mIt != it.d->mIt ); } AddressBook::AddressBook() { init(0, "contact"); } AddressBook::AddressBook( const QString &config ) { init(config, "contact"); } AddressBook::AddressBook( const QString &config, const QString &family ) { init(config, family); } // the default family is "contact" void AddressBook::init(const QString &config, const QString &family ) { + blockLSEchange = false; d = new AddressBookData; QString fami = family; qDebug("new ab "); if (config != 0) { qDebug("config != 0 "); if ( family == "syncContact" ) { qDebug("creating sync config "); fami = "contact"; KConfig* con = new KConfig( locateLocal("config", "syncContactrc") ); con->setGroup( "General" ); con->writeEntry( "ResourceKeys", QString("sync") ); con->writeEntry( "Standard", QString("sync") ); con->setGroup( "Resource_sync" ); con->writeEntry( "FileFormat", QString("vcard") ); con->writeEntry( "FileName", config ); con->writeEntry( "ResourceIdentifier", QString("sync") ); con->writeEntry( "ResourceName", QString("sync_res") ); con->writeEntry( "ResourceType", QString("file") ); //con->sync(); d->mConfig = con; } else d->mConfig = new KConfig( locateLocal("config", config) ); // qDebug("AddressBook::init 1 config=%s",config.latin1() ); } else { d->mConfig = 0; // qDebug("AddressBook::init 1 config=0"); } //US d->mErrorHandler = 0; d->mManager = new KRES::Manager<Resource>( fami, false ); d->mManager->readConfig( d->mConfig ); if ( family == "syncContact" ) { KRES::Manager<Resource> *manager = d->mManager; KRES::Manager<Resource>::ActiveIterator it; for ( it = manager->activeBegin(); it != manager->activeEnd(); ++it ) { (*it)->setAddressBook( this ); if ( !(*it)->open() ) error( QString( "Unable to open resource '%1'!" ).arg( (*it)->resourceName() ) ); } Resource *res = standardResource(); if ( !res ) { qDebug("ERROR: no standard resource"); res = manager->createResource( "file" ); if ( res ) { addResource( res ); @@ -300,96 +301,97 @@ void AddressBook::init(const QString &config, const QString &family ) addCustomField( i18n( "Spouse's Name" ), KABC::Field::Personal, "X-SpousesName", "KADDRESSBOOK" ); addCustomField( i18n( "Office" ), KABC::Field::Personal, "X-Office", "KADDRESSBOOK" ); addCustomField( i18n( "IM Address" ), KABC::Field::Personal, "X-IMAddress", "KADDRESSBOOK" ); addCustomField( i18n( "Anniversary" ), KABC::Field::Personal, "X-Anniversary", "KADDRESSBOOK" ); //US added this field to become compatible with Opie/qtopia addressbook // values can be "female" or "male" or "". An empty field represents undefined. addCustomField( i18n( "Gender" ), KABC::Field::Personal, "X-Gender", "KADDRESSBOOK" ); addCustomField( i18n( "Children" ), KABC::Field::Personal, "X-Children", "KADDRESSBOOK" ); addCustomField( i18n( "FreeBusyUrl" ), KABC::Field::Personal, "X-FreeBusyUrl", "KADDRESSBOOK" ); addCustomField( i18n( "ExternalID" ), KABC::Field::Personal, "X-ExternalID", "KADDRESSBOOK" ); } AddressBook::~AddressBook() { delete d->mConfig; d->mConfig = 0; delete d->mManager; d->mManager = 0; //US delete d->mErrorHandler; d->mErrorHandler = 0; delete d; d = 0; } bool AddressBook::load() { clear(); KRES::Manager<Resource>::ActiveIterator it; bool ok = true; for ( it = d->mManager->activeBegin(); it != d->mManager->activeEnd(); ++it ) if ( !(*it)->load() ) { error( i18n("Unable to load resource '%1'").arg( (*it)->resourceName() ) ); ok = false; } // mark all addressees as unchanged Addressee::List::Iterator addrIt; for ( addrIt = d->mAddressees.begin(); addrIt != d->mAddressees.end(); ++addrIt ) (*addrIt).setChanged( false ); + blockLSEchange = true; return ok; } bool AddressBook::save( Ticket *ticket ) { kdDebug(5700) << "AddressBook::save()"<< endl; if ( ticket->resource() ) { deleteRemovedAddressees(); return ticket->resource()->save( ticket ); } return false; } bool AddressBook::saveAB() { bool ok = true; deleteRemovedAddressees(); KRES::Manager<Resource>::ActiveIterator it; KRES::Manager<Resource> *manager = d->mManager; for ( it = manager->activeBegin(); it != manager->activeEnd(); ++it ) { if ( !(*it)->readOnly() && (*it)->isOpen() ) { Ticket *ticket = requestSaveTicket( *it ); // qDebug("StdAddressBook::save '%s'", (*it)->resourceName().latin1() ); if ( !ticket ) { error( i18n( "Unable to save to resource '%1'. It is locked." ) .arg( (*it)->resourceName() ) ); return false; } //if ( !save( ticket ) ) if ( ticket->resource() ) { if ( ! ticket->resource()->save( ticket ) ) ok = false; } else ok = false; } } return ok; } AddressBook::Iterator AddressBook::begin() { Iterator it = Iterator(); it.d->mIt = d->mAddressees.begin(); @@ -402,186 +404,245 @@ AddressBook::ConstIterator AddressBook::begin() const it.d->mIt = d->mAddressees.begin(); return it; } AddressBook::Iterator AddressBook::end() { Iterator it = Iterator(); it.d->mIt = d->mAddressees.end(); return it; } AddressBook::ConstIterator AddressBook::end() const { ConstIterator it = ConstIterator(); it.d->mIt = d->mAddressees.end(); return it; } void AddressBook::clear() { d->mAddressees.clear(); } Ticket *AddressBook::requestSaveTicket( Resource *resource ) { kdDebug(5700) << "AddressBook::requestSaveTicket()" << endl; if ( !resource ) { qDebug("AddressBook::requestSaveTicket no resource" ); resource = standardResource(); } KRES::Manager<Resource>::ActiveIterator it; for ( it = d->mManager->activeBegin(); it != d->mManager->activeEnd(); ++it ) { if ( (*it) == resource ) { if ( (*it)->readOnly() || !(*it)->isOpen() ) return 0; else return (*it)->requestSaveTicket(); } } return 0; } void AddressBook::insertAddressee( const Addressee &a, bool setRev ) { - Addressee::List::Iterator it; - for ( it = d->mAddressees.begin(); it != d->mAddressees.end(); ++it ) { - if ( a.uid() == (*it).uid() ) { - if ( setRev && (*it).uid().left( 19 ) == QString("last-syncAddressee-") ) { - return; - } - bool changed = false; - Addressee addr = a; - if ( addr != (*it) ) - changed = true; - - (*it) = a; - if ( (*it).resource() == 0 ) - (*it).setResource( standardResource() ); - - if ( changed ) { - if ( setRev ) { + if ( blockLSEchange && setRev && a.uid().left( 19 ) == QString("last-syncAddressee-") ) { + return; + } + bool found = false; + Addressee::List::Iterator it; + for ( it = d->mAddressees.begin(); it != d->mAddressees.end(); ++it ) { + if ( a.uid() == (*it).uid() ) { + + bool changed = false; + Addressee addr = a; + if ( addr != (*it) ) + changed = true; + + (*it) = a; + if ( (*it).resource() == 0 ) + (*it).setResource( standardResource() ); + + if ( changed ) { + if ( setRev ) { - // get rid of micro seconds - QDateTime dt = QDateTime::currentDateTime(); - QTime t = dt.time(); - dt.setTime( QTime (t.hour (), t.minute (), t.second () ) ); - (*it).setRevision( dt ); - } - (*it).setChanged( true ); - } - - return; + // get rid of micro seconds + QDateTime dt = QDateTime::currentDateTime(); + QTime t = dt.time(); + dt.setTime( QTime (t.hour (), t.minute (), t.second () ) ); + (*it).setRevision( dt ); + } + (*it).setChanged( true ); + } + + found = true; + } else { + if ( (*it).uid() == QString("last-syncAddressee-") ) { + QString name = (*it).uid().mid( 19 ); + Addressee b = a; + QString id = b.getID( name ); + if ( ! id.isEmpty() ) { + QString des = (*it).note(); + int startN; + if( (startN = des.find( id ) ) >= 0 ) { + int endN = des.find( ",", startN+1 ); + des = des.left( startN ) + des.mid( endN+1 ); + (*it).setNote( des ); + } + } + } + } } - } - d->mAddressees.append( a ); - Addressee& addr = d->mAddressees.last(); - if ( addr.resource() == 0 ) - addr.setResource( standardResource() ); + if ( found ) + return; + d->mAddressees.append( a ); + Addressee& addr = d->mAddressees.last(); + if ( addr.resource() == 0 ) + addr.setResource( standardResource() ); - addr.setChanged( true ); + addr.setChanged( true ); } void AddressBook::removeAddressee( const Addressee &a ) { Iterator it; + Iterator it2; + bool found = false; for ( it = begin(); it != end(); ++it ) { if ( a.uid() == (*it).uid() ) { - removeAddressee( it ); - return; + found = true; + it2 = it; + } else { + if ( (*it).uid() == QString("last-syncAddressee-") ) { + QString name = (*it).uid().mid( 19 ); + Addressee b = a; + QString id = b.getID( name ); + if ( ! id.isEmpty() ) { + QString des = (*it).note(); + if( des.find( id ) < 0 ) { + des += id + ","; + (*it).setNote( des ); + } + } + } + } } + + if ( found ) + removeAddressee( it2 ); + +} + +void AddressBook::removeDeletedAddressees() +{ + deleteRemovedAddressees(); + Iterator it = begin(); + Iterator it2 ; + QDateTime dt ( QDate( 2004,1,1) ); + while ( it != end() ) { + (*it).setRevision( dt ); + if ( (*it).tempSyncStat() == SYNC_TEMPSTATE_DELETE ) { + it2 = it; + ++it; + removeAddressee( it2 ); + } else + ++it; + } + deleteRemovedAddressees(); } void AddressBook::removeAddressee( const Iterator &it ) { d->mRemovedAddressees.append( (*it) ); d->mAddressees.remove( it.d->mIt ); } AddressBook::Iterator AddressBook::find( const Addressee &a ) { Iterator it; for ( it = begin(); it != end(); ++it ) { if ( a.uid() == (*it).uid() ) { return it; } } return end(); } Addressee AddressBook::findByUid( const QString &uid ) { Iterator it; for ( it = begin(); it != end(); ++it ) { if ( uid == (*it).uid() ) { return *it; } } return Addressee(); } +#if 0 Addressee::List AddressBook::getExternLastSyncAddressees() { Addressee::List results; Iterator it; for ( it = begin(); it != end(); ++it ) { if ( (*it).uid().left( 19 ) == "last-syncAddressee-" ) { - if ( (*it).familyName().left(3) == "E: " ) + if ( (*it).familyName().left(4) == "!E: " ) results.append( *it ); } } return results; } +#endif void AddressBook::resetTempSyncStat() { Iterator it; for ( it = begin(); it != end(); ++it ) { (*it).setTempSyncStat ( SYNC_TEMPSTATE_INITIAL ); } } QStringList AddressBook:: uidList() { QStringList results; Iterator it; for ( it = begin(); it != end(); ++it ) { results.append( (*it).uid() ); } return results; } Addressee::List AddressBook::allAddressees() { return d->mAddressees; } Addressee::List AddressBook::findByName( const QString &name ) { Addressee::List results; Iterator it; for ( it = begin(); it != end(); ++it ) { if ( name == (*it).realName() ) { results.append( *it ); } } return results; } Addressee::List AddressBook::findByEmail( const QString &email ) { Addressee::List results; QStringList mailList; Iterator it; for ( it = begin(); it != end(); ++it ) { mailList = (*it).emails(); diff --git a/kabc/addressbook.h b/kabc/addressbook.h index 253de68..2f2678b 100644 --- a/kabc/addressbook.h +++ b/kabc/addressbook.h @@ -244,91 +244,93 @@ class AddressBook : public QObject Field::List fields( int category = Field::All ); /** Add custom field to address book. @param label User visible label of the field. @param category Ored list of field categories. @param key Identifier used as key for reading and writing the field. @param app String used as application key for reading and writing the field. */ bool addCustomField( const QString &label, int category = Field::All, const QString &key = QString::null, const QString &app = QString::null ); /** Add address book resource. */ bool addResource( Resource * ); /** Remove address book resource. */ bool removeResource( Resource * ); /** Return pointer list of all resources. */ QPtrList<Resource> resources(); /** Set the @p ErrorHandler, that is used by @ref error() to provide gui-independend error messages. */ void setErrorHandler( ErrorHandler * ); /** Shows gui independend error messages. */ void error( const QString& ); /** Query all resources to clean up their lock files */ void cleanUp(); // sync stuff - Addressee::List getExternLastSyncAddressees(); + //Addressee::List getExternLastSyncAddressees(); void resetTempSyncStat(); QStringList uidList(); + void removeDeletedAddressees(); signals: /** Emitted, when the address book has changed on disk. */ void addressBookChanged( AddressBook * ); /** Emitted, when the address book has been locked for writing. */ void addressBookLocked( AddressBook * ); /** Emitted, when the address book has been unlocked. */ void addressBookUnlocked( AddressBook * ); protected: void deleteRemovedAddressees(); void setStandardResource( Resource * ); Resource *standardResource(); KRES::Manager<Resource> *resourceManager(); void init(const QString &config, const QString &family); private: //US QPtrList<Resource> mDummy; // Remove in KDE 4 struct AddressBookData; AddressBookData *d; + bool blockLSEchange; }; QDataStream &operator<<( QDataStream &, const AddressBook & ); QDataStream &operator>>( QDataStream &, AddressBook & ); } #endif diff --git a/kabc/addressee.cpp b/kabc/addressee.cpp index 7f04d8f..0f5d605 100644 --- a/kabc/addressee.cpp +++ b/kabc/addressee.cpp @@ -129,96 +129,192 @@ void Addressee::detach() bool Addressee::operator==( const Addressee &a ) const { if ( uid() != a.uid() ) return false; if ( mData->name != a.mData->name ) return false; if ( mData->formattedName != a.mData->formattedName ) return false; if ( mData->familyName != a.mData->familyName ) return false; if ( mData->givenName != a.mData->givenName ) return false; if ( mData->additionalName != a.mData->additionalName ) return false; if ( mData->prefix != a.mData->prefix ) return false; if ( mData->suffix != a.mData->suffix ) return false; if ( mData->nickName != a.mData->nickName ) return false; if ( mData->birthday != a.mData->birthday ) return false; if ( mData->mailer != a.mData->mailer ) return false; if ( mData->timeZone != a.mData->timeZone ) return false; if ( mData->geo != a.mData->geo ) return false; if ( mData->title != a.mData->title ) return false; if ( mData->role != a.mData->role ) return false; if ( mData->organization != a.mData->organization ) return false; if ( mData->note != a.mData->note ) return false; if ( mData->productId != a.mData->productId ) return false; if ( mData->revision != a.mData->revision ) return false; if ( mData->sortString != a.mData->sortString ) return false; if ( mData->secrecy != a.mData->secrecy ) return false; if ( mData->logo != a.mData->logo ) return false; if ( mData->photo != a.mData->photo ) return false; if ( mData->sound != a.mData->sound ) return false; if ( mData->agent != a.mData->agent ) return false; if ( ( mData->url.isValid() || a.mData->url.isValid() ) && ( mData->url != a.mData->url ) ) return false; if ( mData->phoneNumbers != a.mData->phoneNumbers ) return false; if ( mData->addresses != a.mData->addresses ) return false; if ( mData->keys != a.mData->keys ) return false; if ( mData->emails != a.mData->emails ) return false; if ( mData->categories != a.mData->categories ) return false; if ( mData->custom != a.mData->custom ) return false; return true; } bool Addressee::operator!=( const Addressee &a ) const { return !( a == *this ); } bool Addressee::isEmpty() const { return mData->empty; } +ulong Addressee::getCsum4List( const QStringList & attList) +{ + int max = attList.count(); + ulong cSum = 0; + int j,k,i; + int add; + for ( i = 0; i < max ; ++i ) { + QString s = attList[i]; + if ( ! s.isEmpty() ){ + j = s.length(); + for ( k = 0; k < j; ++k ) { + int mul = k +1; + add = s[k].unicode (); + if ( k < 16 ) + mul = mul * mul; + int ii = i+1; + add = add * mul *ii*ii*ii; + cSum += add; + } + } + + } + //QString dump = attList.join(","); + //qDebug("csum: %d %s", cSum,dump.latin1()); + + return cSum; + +} +void Addressee::computeCsum(const QString &dev) +{ + QStringList l; + if ( !mData->name.isEmpty() ) l.append(mData->name); + if ( !mData->formattedName.isEmpty() ) l.append(mData->formattedName ); + 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() ) 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] ); + } + setCsum( dev, QString::number (getCsum4List(l)) ); +} 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 ); } void Addressee::setTempSyncStat( int id ) { mTempSyncStat = id; } int Addressee::tempSyncStat() const { return mTempSyncStat; } QString Addressee::getID( const QString & prof) { return KIdManager::getId ( mData->mExternalId, prof ); } void Addressee::setCsum( const QString & prof , const QString & id ) { detach(); mData->mExternalId = KIdManager::setCsum ( mData->mExternalId, prof, id ); } 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; } @@ -1405,101 +1501,100 @@ void Addressee::insertCategory( const QString &c ) mData->empty = false; if ( mData->categories.contains( c ) ) return; mData->categories.append( c ); } void Addressee::removeCategory( const QString &c ) { detach(); QStringList::Iterator it = mData->categories.find( c ); if ( it == mData->categories.end() ) return; mData->categories.remove( it ); } bool Addressee::hasCategory( const QString &c ) const { return ( mData->categories.contains( c ) ); } void Addressee::setCategories( const QStringList &c ) { detach(); mData->empty = false; mData->categories = c; } QStringList Addressee::categories() const { return mData->categories; } void Addressee::insertCustom( const QString &app, const QString &name, const QString &value ) { if ( value.isNull() || name.isEmpty() || app.isEmpty() ) return; detach(); mData->empty = false; QString qualifiedName = app + "-" + name + ":"; QStringList::Iterator it; for( it = mData->custom.begin(); it != mData->custom.end(); ++it ) { if ( (*it).startsWith( qualifiedName ) ) { - (*it) = qualifiedName + value; + (*it) = qualifiedName + value; return; } } - mData->custom.append( qualifiedName + value ); } void Addressee::removeCustom( const QString &app, const QString &name) { detach(); QString qualifiedName = app + "-" + name + ":"; QStringList::Iterator it; for( it = mData->custom.begin(); it != mData->custom.end(); ++it ) { if ( (*it).startsWith( qualifiedName ) ) { mData->custom.remove( it ); return; } } } QString Addressee::custom( const QString &app, const QString &name ) const { QString qualifiedName = app + "-" + name + ":"; QString value; QStringList::ConstIterator it; for( it = mData->custom.begin(); it != mData->custom.end(); ++it ) { if ( (*it).startsWith( qualifiedName ) ) { value = (*it).mid( (*it).find( ":" ) + 1 ); break; } } return value; } void Addressee::setCustoms( const QStringList &l ) { detach(); mData->empty = false; mData->custom = l; } QStringList Addressee::customs() const { return mData->custom; } void Addressee::parseEmailAddress( const QString &rawEmail, QString &fullName, diff --git a/kabc/addressee.h b/kabc/addressee.h index f098371..0805458 100644 --- a/kabc/addressee.h +++ b/kabc/addressee.h @@ -61,96 +61,98 @@ class Resource; 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; /** 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 ); |