-rw-r--r-- | kabc/addressbook.cpp | 27 | ||||
-rw-r--r-- | kabc/addressbook.h | 3 | ||||
-rw-r--r-- | kabc/addressee.cpp | 6 | ||||
-rw-r--r-- | kabc/plugins/qtopia/qtopiaconverter.cpp | 2 | ||||
-rw-r--r-- | kabc/plugins/qtopia/resourceqtopia.cpp | 79 | ||||
-rw-r--r-- | kaddressbook/kabcore.cpp | 58 | ||||
-rw-r--r-- | korganizer/calendarview.cpp | 44 |
7 files changed, 153 insertions, 66 deletions
diff --git a/kabc/addressbook.cpp b/kabc/addressbook.cpp index 86dc7c2..17b9ba2 100644 --- a/kabc/addressbook.cpp +++ b/kabc/addressbook.cpp @@ -554,5 +554,4 @@ void AddressBook::removeAddressee( const Addressee &a ) -void AddressBook::removeDeletedAddressees() +void AddressBook::removeSyncAddressees( bool removeDeleted ) { - deleteRemovedAddressees(); Iterator it = begin(); @@ -564,3 +563,3 @@ void AddressBook::removeDeletedAddressees() (*it).setIDStr(""); - if ( (*it).tempSyncStat() == SYNC_TEMPSTATE_DELETE || (*it).uid().left( 19 ) == QString("last-syncAddressee-")) { + if ( ( (*it).tempSyncStat() == SYNC_TEMPSTATE_DELETE && removeDeleted )|| (*it).uid().left( 19 ) == QString("last-syncAddressee-")) { it2 = it; @@ -569,3 +568,3 @@ void AddressBook::removeDeletedAddressees() removeAddressee( it2 ); - } else { + } else { //qDebug("skipping %s ",(*it).uid().latin1() ); @@ -619,2 +618,3 @@ void AddressBook::postExternSync( AddressBook* aBook , const QString& csd) for ( it = begin(); it != end(); ++it ) { + qDebug("check uid %s ", (*it).uid().latin1() ); if ( (*it).tempSyncStat() == SYNC_TEMPSTATE_NEW_ID || @@ -623,3 +623,3 @@ void AddressBook::postExternSync( AddressBook* aBook , const QString& csd) if ( ad.isEmpty() ) { - qDebug("ERROR ad empty "); + qDebug("postExternSync:ERROR addressee is empty: %s ", (*it).uid().latin1()); } else { @@ -635,3 +635,11 @@ void AddressBook::postExternSync( AddressBook* aBook , const QString& csd) - +bool AddressBook::containsExternalUid( const QString& uid ) +{ + Iterator it; + for ( it = begin(); it != end(); ++it ) { + if ( uid == (*it).externalUID( ) ) + return true; + } + return false; +} Addressee AddressBook::findByExternUid( const QString& uid , const QString& profile ) @@ -655,2 +663,9 @@ void AddressBook::mergeAB( AddressBook *aBook, const QString& profile ) } +#if 0 + // test only + for ( it = begin(); it != end(); ++it ) { + + qDebug("uid %s ", (*it).uid().latin1()); + } +#endif } diff --git a/kabc/addressbook.h b/kabc/addressbook.h index 157dc56..8f62f0d 100644 --- a/kabc/addressbook.h +++ b/kabc/addressbook.h @@ -294,5 +294,6 @@ class AddressBook : public QObject QStringList uidList(); - void removeDeletedAddressees(); + void removeSyncAddressees( bool removeDeleted = false ); void mergeAB( AddressBook *aBook, const QString& profile ); Addressee findByExternUid( const QString& uid , const QString& profile ); + bool containsExternalUid( const QString& uid ); diff --git a/kabc/addressee.cpp b/kabc/addressee.cpp index fda62f1..e241281 100644 --- a/kabc/addressee.cpp +++ b/kabc/addressee.cpp @@ -97,3 +97,3 @@ Addressee::Addressee() mData->mExternalId = ":"; - mData->revision = QDateTime ( QDate( 2004,1,1)); + mData->revision = QDateTime ( QDate( 2003,1,1)); mData->mTempSyncStat = SYNC_TEMPSTATE_INITIAL; @@ -310,2 +310,4 @@ void Addressee::mergeContact( const Addressee& ad ) // merging keys + qDebug("merge contact %s ", ad.uid().latin1()); + setUid( ad.uid() ); } @@ -381,2 +383,3 @@ void Addressee::setOriginalExternalUID( const QString &id ) mData->empty = false; + qDebug("*******Set orig uid %s ", id.latin1()); mData->originalExternalUID = id; @@ -393,2 +396,3 @@ void Addressee::setUid( const QString &id ) detach(); + qDebug("****setuid %s ", id.latin1()); mData->empty = false; diff --git a/kabc/plugins/qtopia/qtopiaconverter.cpp b/kabc/plugins/qtopia/qtopiaconverter.cpp index de45e63..430c7b3 100644 --- a/kabc/plugins/qtopia/qtopiaconverter.cpp +++ b/kabc/plugins/qtopia/qtopiaconverter.cpp @@ -88,3 +88,3 @@ bool QtopiaConverter::qtopiaToAddressee( const PimContact &contact, Addressee &a addr.setExternalUID( exuid ); - //qDebug("QtopiaConverter:set uid %s ",addr.externalUID().latin1() ); + qDebug("QtopiaConverter:set %s uid %s ",addr.originalExternalUID().latin1(),addr.externalUID().latin1() ); diff --git a/kabc/plugins/qtopia/resourceqtopia.cpp b/kabc/plugins/qtopia/resourceqtopia.cpp index 935a1cf..1f90fcb 100644 --- a/kabc/plugins/qtopia/resourceqtopia.cpp +++ b/kabc/plugins/qtopia/resourceqtopia.cpp @@ -199,5 +199,7 @@ bool ResourceQtopia::save( Ticket *ticket ) bool res; - + KABC::Addressee::List changedAddressees; + QStringList addedUID; for ( it = addressBook()->begin(); it != addressBook()->end(); ++it ) { //KABC::Addressee addressee = (*it); + // qDebug("AAAfor uid %s ", (*it).originalExternalUID().latin1() ); if ( (*it).tempSyncStat() != SYNC_TEMPSTATE_NEW_EXTERNAL ) { @@ -206,2 +208,3 @@ bool ResourceQtopia::save( Ticket *ticket ) PimContact c = mAccess->contactForId( uid, &ok ); + qDebug("ResourceQtopia::save:Found %d for uid %s ", ok,(*it).originalExternalUID().latin1() ); res = mConverter->addresseeToQtopia( *it, c ); @@ -209,9 +212,58 @@ bool ResourceQtopia::save( Ticket *ticket ) if ( (*it).tempSyncStat() == SYNC_TEMPSTATE_ADDED_EXTERNAL ) { - mAccess->addContact(c); - KABC::Addressee addressee; - mConverter->qtopiaToAddressee( c, addressee ); - addressee.setTempSyncStat( SYNC_TEMPSTATE_NEW_ID ); - addressBook()->insertAddressee( addressee ); + qDebug("skipping adding of contact "); + continue; + PimContact e; + AddressBookAccess Access2; + Access2.addContact(e); + const PimContact* contact; + bool res; + QString uid2, Ouid; + AddressBookIterator itt(Access2); + for (contact=itt.toFirst(); itt.current(); ++itt) + { + contact = itt.current(); + QString exuid = contact->uid().toString(); + Ouid =exuid; + int ente = exuid.find( "-0000"); + if ( exuid.left(1) == "{" ) + exuid = exuid.mid(1); + if ( ente > -1 ) + exuid = exuid.left( ente-1 ); + uid2 = exuid; + qDebug("trying find uid "); + if ( !addressBook()->containsExternalUid( uid2 ) ) { + qDebug("ab not contains "); + if ( !addedUID.contains( uid2 )) { + qDebug("list not contains "); + break; + } + } + + } + if ( !itt.current()) { + qDebug("ERROR uid "); + continue; + } + else + qDebug("ADD uid detected "); + + + QUuid uid3( Ouid); + PimContact d = Access2.contactForId( uid3, &ok ); + if ( ! ok ) { + qDebug("ADD: Error getting new uid "); + } else { + qDebug("NEW UID found "); + PimContact g = mAccess->contactForId( c.uid(), &ok ); + KABC::Addressee addressee; + mConverter->qtopiaToAddressee( g, addressee ); + addressee.setUid((*it).uid() ); + addressee.setTempSyncStat( SYNC_TEMPSTATE_NEW_ID ); + changedAddressees.append( addressee ); + addedUID.append( uid2 ); + } + } else if ( (*it).tempSyncStat() == SYNC_TEMPSTATE_DELETE ) { + qDebug("Remove contact "); if ( ok ) @@ -219,10 +271,13 @@ bool ResourceQtopia::save( Ticket *ticket ) else - qDebug("Error revoe contact from qtopia "); + qDebug("Error remove contact from qtopia "); } else if ( (*it).tempSyncStat() != SYNC_TEMPSTATE_NEW_EXTERNAL ) { if ( ok ) { + qDebug("Update contact "); mAccess->updateContact(c); + PimContact g = mAccess->contactForId( c.uid(), &ok ); KABC::Addressee addressee; - mConverter->qtopiaToAddressee( c, addressee ); + mConverter->qtopiaToAddressee( g, addressee ); + addressee.setUid((*it).uid() ); addressee.setTempSyncStat( SYNC_TEMPSTATE_NEW_CSUM ); - addressBook()->insertAddressee( addressee ); + changedAddressees.append( addressee ); } @@ -239,3 +294,7 @@ bool ResourceQtopia::save( Ticket *ticket ) - // mAccess->addressBookUpdated(); + KABC::Addressee::List::Iterator it2; + for ( it2 = changedAddressees.begin(); it2 != changedAddressees.end(); ++it2 ) + addressBook()->insertAddressee((*it2)); + + diff --git a/kaddressbook/kabcore.cpp b/kaddressbook/kabcore.cpp index 8f3ca9b..f8683e7 100644 --- a/kaddressbook/kabcore.cpp +++ b/kaddressbook/kabcore.cpp @@ -2551,2 +2551,4 @@ int KABCore::takeAddressee( KABC::Addressee* local, KABC::Addressee* remote, i QDateTime lastSync = mLastAddressbookSync; + QDateTime localMod = local->revision(); + QDateTime remoteMod = remote->revision(); if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) { @@ -2555,7 +2557,7 @@ int KABCore::takeAddressee( KABC::Addressee* local, KABC::Addressee* remote, i - //qDebug("loc %s rem %s", local->getCsum(mCurrentSyncDevice).latin1(), remote->getCsum(mCurrentSyncDevice).latin1() ); - locCh = ( local->revision() > mLastAddressbookSync ); + qDebug("loc %s rem %s", local->getCsum(mCurrentSyncDevice).latin1(), remote->getCsum(mCurrentSyncDevice).latin1() ); + locCh = ( localMod > mLastAddressbookSync ); if ( !remCh && ! locCh ) { - //qDebug("both not changed "); - lastSync = local->revision().addDays(1); + qDebug("both not changed "); + lastSync = localMod.addDays(1); if ( mode <= SYNC_PREF_ASK ) @@ -2564,11 +2566,11 @@ int KABCore::takeAddressee( KABC::Addressee* local, KABC::Addressee* remote, i if ( locCh ) { - //qDebug("loc changed %s %s", local->revision().toString().latin1(), mLastAddressbookSync.toString().latin1()); - lastSync = local->revision().addDays( -1 ); + qDebug("loc changed %s %s", localMod.toString().latin1(), mLastAddressbookSync.toString().latin1()); + lastSync = localMod.addDays( -1 ); if ( !remCh ) - remote->setRevision( lastSync.addDays( -1 ) ); + remoteMod =( lastSync.addDays( -1 ) ); } else { //qDebug(" not loc changed "); - lastSync = local->revision().addDays( 1 ); + lastSync = localMod.addDays( 1 ); if ( remCh ) - remote->setRevision( lastSync.addDays( 1 ) ); + remoteMod =( lastSync.addDays( 1 ) ); @@ -2580,3 +2582,3 @@ int KABCore::takeAddressee( KABC::Addressee* local, KABC::Addressee* remote, i } else { - if ( local->revision() == remote->revision() ) + if ( localMod == remoteMod ) return 0; @@ -2586,3 +2588,3 @@ int KABCore::takeAddressee( KABC::Addressee* local, KABC::Addressee* remote, i - //qDebug("%s %d %s %d", local->lastModified().toString().latin1() , local->revision(), remote->lastModified().toString().latin1(), remote->revision()); + //qDebug("%s %d %s %d", local->lastModified().toString().latin1() , localMod, remote->lastModified().toString().latin1(), remoteMod); //qDebug("%d %d %d %d ", local->lastModified().time().second(), local->lastModified().time().msec(), remote->lastModified().time().second(), remote->lastModified().time().msec() ); @@ -2611,5 +2613,5 @@ int KABCore::takeAddressee( KABC::Addressee* local, KABC::Addressee* remote, i case SYNC_PREF_LOCAL: - if ( lastSync > remote->revision() ) + if ( lastSync > remoteMod ) return 1; - if ( lastSync > local->revision() ) + if ( lastSync > localMod ) return 2; @@ -2618,5 +2620,5 @@ int KABCore::takeAddressee( KABC::Addressee* local, KABC::Addressee* remote, i case SYNC_PREF_REMOTE: - if ( lastSync > remote->revision() ) + if ( lastSync > remoteMod ) return 1; - if ( lastSync > local->revision() ) + if ( lastSync > localMod ) return 2; @@ -2625,3 +2627,3 @@ int KABCore::takeAddressee( KABC::Addressee* local, KABC::Addressee* remote, i case SYNC_PREF_NEWEST: - if ( local->revision() > remote->revision() ) + if ( localMod > remoteMod ) return 1; @@ -2631,8 +2633,8 @@ int KABCore::takeAddressee( KABC::Addressee* local, KABC::Addressee* remote, i case SYNC_PREF_ASK: - //qDebug("lsy %s --- lo %s --- re %s ", lastSync.toString().latin1(), local->revision().toString().latin1(), remote->revision().toString().latin1() ); - if ( lastSync > remote->revision() ) + //qDebug("lsy %s --- lo %s --- re %s ", lastSync.toString().latin1(), localMod.toString().latin1(), remoteMod.toString().latin1() ); + if ( lastSync > remoteMod ) return 1; - if ( lastSync > local->revision() ) + if ( lastSync > localMod ) return 2; - localIsNew = local->revision() >= remote->revision(); + localIsNew = localMod >= remoteMod; //qDebug("conflict! ************************************** "); @@ -2788,2 +2790,6 @@ bool KABCore::synchronizeAddressbooks( KABC::AddressBook* local, KABC::AddressBo } else { // take == 2 take remote + if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) { + if ( inR.revision().date().year() < 2004 ) + inR.setRevision( modifiedCalendar ); + } idS = inL.IDStr(); @@ -2927,5 +2933,6 @@ bool KABCore::syncAB(QString filename, int mode) bool external = false; - + bool isXML = false; if ( filename.right(4) == ".xml") { mGlobalSyncMode = SYNC_MODE_EXTERNAL; + isXML = true; abLocal.preExternSync( mAddressBook ,mCurrentSyncDevice ); @@ -2938,6 +2945,5 @@ bool KABCore::syncAB(QString filename, int mode) bool found = false; - QDateTime dt( QDate( 2004,1,1)); AddressBook::Iterator it; for ( it = abLocal.begin(); it != abLocal.end(); ++it ) { - if ( (*it).revision() != dt ) { + if ( (*it).revision().date().year() > 2003 ) { found = true; @@ -2968,7 +2974,7 @@ bool KABCore::syncAB(QString filename, int mode) { - if ( external && filename.right(4) != ".xml") - abLocal.removeDeletedAddressees(); + if ( external ) + abLocal.removeSyncAddressees( !isXML); qDebug("Saving remote AB "); abLocal.saveAB(); - if ( external && filename.right(4) == ".xml") { + if ( isXML ) { // afterwrite processing diff --git a/korganizer/calendarview.cpp b/korganizer/calendarview.cpp index 0c75632..8e83723 100644 --- a/korganizer/calendarview.cpp +++ b/korganizer/calendarview.cpp @@ -728,2 +728,4 @@ int CalendarView::takeEvent( Incidence* local, Incidence* remote, int mode , b QDateTime lastSync = mLastCalendarSync; + QDateTime localMod = local->lastModified(); + QDateTime remoteMod = remote->lastModified(); if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) { @@ -733,6 +735,6 @@ int CalendarView::takeEvent( Incidence* local, Incidence* remote, int mode , b //qDebug("loc %s rem %s", local->getCsum(mCurrentSyncDevice).latin1(), remote->getCsum(mCurrentSyncDevice).latin1() ); - locCh = ( local->lastModified() > mLastCalendarSync ); + locCh = ( localMod > mLastCalendarSync ); if ( !remCh && ! locCh ) { //qDebug("both not changed "); - lastSync = local->lastModified().addDays(1); + lastSync = localMod.addDays(1); if ( mode <= SYNC_PREF_ASK ) @@ -741,11 +743,11 @@ int CalendarView::takeEvent( Incidence* local, Incidence* remote, int mode , b if ( locCh ) { - //qDebug("loc changed %d %s %s", local->revision() , local->lastModified().toString().latin1(), mLastCalendarSync.toString().latin1()); - lastSync = local->lastModified().addDays( -1 ); + //qDebug("loc changed %d %s %s", local->revision() , localMod.toString().latin1(), mLastCalendarSync.toString().latin1()); + lastSync = localMod.addDays( -1 ); if ( !remCh ) - remote->setLastModified( lastSync.addDays( -1 ) ); + remoteMod = ( lastSync.addDays( -1 ) ); } else { //qDebug(" not loc changed "); - lastSync = local->lastModified().addDays( 1 ); + lastSync = localMod.addDays( 1 ); if ( remCh ) - remote->setLastModified( lastSync.addDays( 1 ) ); + remoteMod =( lastSync.addDays( 1 ) ); @@ -757,3 +759,3 @@ int CalendarView::takeEvent( Incidence* local, Incidence* remote, int mode , b } else { - if ( local->lastModified() == remote->lastModified() ) + if ( localMod == remoteMod ) if ( local->revision() == remote->revision() ) @@ -764,4 +766,4 @@ int CalendarView::takeEvent( Incidence* local, Incidence* remote, int mode , b - //qDebug("%s %d %s %d", local->lastModified().toString().latin1() , local->revision(), remote->lastModified().toString().latin1(), remote->revision()); - //qDebug("%d %d %d %d ", local->lastModified().time().second(), local->lastModified().time().msec(), remote->lastModified().time().second(), remote->lastModified().time().msec() ); + //qDebug("%s %d %s %d", localMod.toString().latin1() , local->revision(), remoteMod.toString().latin1(), remote->revision()); + //qDebug("%d %d %d %d ", localMod.time().second(), localMod.time().msec(), remoteMod.time().second(), remoteMod.time().msec() ); //full = true; //debug only @@ -789,3 +791,3 @@ int CalendarView::takeEvent( Incidence* local, Incidence* remote, int mode , b bool localIsNew; - //qDebug("%s -- %s mLastCalendarSync %s lastsync %s --- local %s remote %s ",local->summary().latin1(), remote->summary().latin1(),mLastCalendarSync.toString().latin1() ,lastSync.toString().latin1() , local->lastModified().toString().latin1() , remote->lastModified().toString().latin1() ); + //qDebug("%s -- %s mLastCalendarSync %s lastsync %s --- local %s remote %s ",local->summary().latin1(), remote->summary().latin1(),mLastCalendarSync.toString().latin1() ,lastSync.toString().latin1() , localMod.toString().latin1() , remoteMod.toString().latin1() ); @@ -796,5 +798,5 @@ int CalendarView::takeEvent( Incidence* local, Incidence* remote, int mode , b case SYNC_PREF_LOCAL: - if ( lastSync > remote->lastModified() ) + if ( lastSync > remoteMod ) return 1; - if ( lastSync > local->lastModified() ) + if ( lastSync > localMod ) return 2; @@ -803,5 +805,5 @@ int CalendarView::takeEvent( Incidence* local, Incidence* remote, int mode , b case SYNC_PREF_REMOTE: - if ( lastSync > remote->lastModified() ) + if ( lastSync > remoteMod ) return 1; - if ( lastSync > local->lastModified() ) + if ( lastSync > localMod ) return 2; @@ -810,3 +812,3 @@ int CalendarView::takeEvent( Incidence* local, Incidence* remote, int mode , b case SYNC_PREF_NEWEST: - if ( local->lastModified() > remote->lastModified() ) + if ( localMod > remoteMod ) return 1; @@ -816,9 +818,9 @@ int CalendarView::takeEvent( Incidence* local, Incidence* remote, int mode , b case SYNC_PREF_ASK: - //qDebug("lsy %s --- lo %s --- re %s ", lastSync.toString().latin1(), local->lastModified().toString().latin1(), remote->lastModified().toString().latin1() ); - if ( lastSync > remote->lastModified() ) + //qDebug("lsy %s --- lo %s --- re %s ", lastSync.toString().latin1(), localMod.toString().latin1(), remoteMod.toString().latin1() ); + if ( lastSync > remoteMod ) return 1; - if ( lastSync > local->lastModified() ) + if ( lastSync > localMod ) return 2; - //qDebug("lsy %s --- lo %s --- re %s ", lastSync.toString().latin1(), local->lastModified().toString().latin1(), remote->lastModified().toString().latin1() ); - localIsNew = local->lastModified() >= remote->lastModified(); + //qDebug("lsy %s --- lo %s --- re %s ", lastSync.toString().latin1(), localMod.toString().latin1(), remoteMod.toString().latin1() ); + localIsNew = localMod >= remoteMod; if ( localIsNew ) |