-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 @@ -213,104 +213,201 @@ 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 ) { 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; //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 ); 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(); return it; } AddressBook::ConstIterator AddressBook::begin() const { ConstIterator it = ConstIterator(); 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 { diff --git a/kabc/addressbook.h b/kabc/addressbook.h index f89d7da..e43de31 100644 --- a/kabc/addressbook.h +++ b/kabc/addressbook.h @@ -120,48 +120,49 @@ class AddressBook : public QObject virtual ~AddressBook(); /** Requests a ticket for saving the addressbook. Calling this function locks the addressbook for all other processes. If the address book is already locked the function returns 0. You need the returned @ref Ticket object for calling the @ref save() function. @see save() */ Ticket *requestSaveTicket( Resource *resource=0 ); /** Load address book from file. */ bool load(); /** 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(); /** Returns a const iterator for first entry of address book. */ ConstIterator begin() const; /** Returns a iterator for first entry of address book. */ Iterator end(); /** Returns a const iterator for first entry of address book. */ ConstIterator end() const; /** Removes all entries from address book. */ |