author | zautrix <zautrix> | 2004-09-18 08:25:05 (UTC) |
---|---|---|
committer | zautrix <zautrix> | 2004-09-18 08:25:05 (UTC) |
commit | 983b010853dfadfec3638e2afd90e522985f67fb (patch) (side-by-side diff) | |
tree | b691b7664b9f6f23d0d92a0e05bf3e8cbcf2df67 /kabc | |
parent | df03bd8c7ff6a738dd386001679542ae4b493a07 (diff) | |
download | kdepimpi-983b010853dfadfec3638e2afd90e522985f67fb.zip kdepimpi-983b010853dfadfec3638e2afd90e522985f67fb.tar.gz kdepimpi-983b010853dfadfec3638e2afd90e522985f67fb.tar.bz2 |
more AB syncing
-rw-r--r-- | kabc/addressbook.cpp | 101 | ||||
-rw-r--r-- | kabc/addressbook.h | 1 |
2 files changed, 100 insertions, 2 deletions
diff --git a/kabc/addressbook.cpp b/kabc/addressbook.cpp index 47d298a..70eda1b 100644 --- a/kabc/addressbook.cpp +++ b/kabc/addressbook.cpp @@ -231,24 +231,93 @@ AddressBook::AddressBook( const QString &config, const QString &family ) } // the default family is "contact" void AddressBook::init(const QString &config, const QString &family ) { 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>( family, false ); + 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 ); + } + else + qDebug(" No resource available!!!"); + } + setStandardResource( res ); + manager->writeConfig(); + } + addCustomField( i18n( "Department" ), KABC::Field::Organization, + "X-Department", "KADDRESSBOOK" ); + addCustomField( i18n( "Profession" ), KABC::Field::Organization, + "X-Profession", "KADDRESSBOOK" ); + addCustomField( i18n( "Assistant's Name" ), KABC::Field::Organization, + "X-AssistantsName", "KADDRESSBOOK" ); + addCustomField( i18n( "Manager's Name" ), KABC::Field::Organization, + "X-ManagersName", "KADDRESSBOOK" ); + 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; @@ -281,18 +350,46 @@ bool AddressBook::load() 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(); return it; diff --git a/kabc/addressbook.h b/kabc/addressbook.h index f89d7da..e43de31 100644 --- a/kabc/addressbook.h +++ b/kabc/addressbook.h @@ -138,12 +138,13 @@ class AddressBook : public QObject Save address book. The address book is saved to the file, the Ticket object has been requested for by @ref requestSaveTicket(). @param ticket a ticket object returned by @ref requestSaveTicket() */ bool save( Ticket *ticket ); + bool saveAB( ); /** Returns a iterator for first entry of address book. */ Iterator begin(); |