-rw-r--r-- | kabc/plugins/qtopia/resourceqtopia.cpp | 135 |
1 files changed, 26 insertions, 109 deletions
diff --git a/kabc/plugins/qtopia/resourceqtopia.cpp b/kabc/plugins/qtopia/resourceqtopia.cpp index 1f90fcb..f9cabcb 100644 --- a/kabc/plugins/qtopia/resourceqtopia.cpp +++ b/kabc/plugins/qtopia/resourceqtopia.cpp @@ -53,6 +53,4 @@ $Id$ #include "resourceqtopia.h" -#include <libkdepim/ksyncprofile.h> -#include <qpe/quuid.h> using namespace KABC; @@ -192,117 +190,36 @@ bool ResourceQtopia::load() bool ResourceQtopia::save( Ticket *ticket ) { - qDebug("ResourceQtopia::save: %s", fileName().latin1()); - - mDirWatch.stopScan(); - - KABC::AddressBook::Iterator it; - 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 ) { - QUuid uid( (*it).originalExternalUID() ); - bool ok; - PimContact c = mAccess->contactForId( uid, &ok ); - qDebug("ResourceQtopia::save:Found %d for uid %s ", ok,(*it).originalExternalUID().latin1() ); - res = mConverter->addresseeToQtopia( *it, c ); - if (res == true) { - if ( (*it).tempSyncStat() == SYNC_TEMPSTATE_ADDED_EXTERNAL ) { - 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 ) - mAccess->removeContact(c); - else - 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( g, addressee ); - addressee.setUid((*it).uid() ); - addressee.setTempSyncStat( SYNC_TEMPSTATE_NEW_CSUM ); - changedAddressees.append( addressee ); - } - else - qDebug("Error update contact from qtopia "); - - } - - } else { - qDebug("Unable to convert Addressee %s", (*it).formattedName().latin1()); - } - } - } + qDebug("ResourceQtopia::save: %s", fileName().latin1()); - KABC::Addressee::List::Iterator it2; - for ( it2 = changedAddressees.begin(); it2 != changedAddressees.end(); ++it2 ) - addressBook()->insertAddressee((*it2)); + mDirWatch.stopScan(); + KABC::AddressBook::Iterator it; + bool res; + for ( it = addressBook()->begin(); it != addressBook()->end(); ++it ) { + PimContact c; + KABC::Addressee addressee = (*it); - mDirWatch.startScan(); + res = mConverter->addresseeToQtopia( *it, c ); + if (res == true) + { + mAccess->addContact(c); +// if (res == false) +// qDebug("Unable to append Contact %s", c.fullName().latin1()); + } + else + { + qDebug("Unable to convert Addressee %s", addressee.formattedName().latin1()); + } + } - delete ticket; - unlock( fileName() ); +// mAccess->addressBookUpdated(); - return true; + mDirWatch.startScan(); + + delete ticket; + unlock( fileName() ); + + return true; } |