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/addressbook.cpp | |
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 |
1 files changed, 99 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 @@ -235,5 +235,25 @@ 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() ); @@ -245,6 +265,55 @@ void AddressBook::init(const QString &config, const QString &family ) //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" ); } @@ -285,5 +354,4 @@ bool AddressBook::save( Ticket *ticket ) if ( ticket->resource() ) { deleteRemovedAddressees(); - return ticket->resource()->save( ticket ); } @@ -291,4 +359,33 @@ bool AddressBook::save( Ticket *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() |