author | zautrix <zautrix> | 2004-09-18 08:25:05 (UTC) |
---|---|---|
committer | zautrix <zautrix> | 2004-09-18 08:25:05 (UTC) |
commit | 983b010853dfadfec3638e2afd90e522985f67fb (patch) (unidiff) | |
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 | |||
@@ -233,9 +233,29 @@ AddressBook::AddressBook( const QString &config, const QString &family ) | |||
233 | // the default family is "contact" | 233 | // the default family is "contact" |
234 | void AddressBook::init(const QString &config, const QString &family ) | 234 | void AddressBook::init(const QString &config, const QString &family ) |
235 | { | 235 | { |
236 | d = new AddressBookData; | 236 | d = new AddressBookData; |
237 | QString fami = family; | ||
238 | qDebug("new ab "); | ||
237 | if (config != 0) { | 239 | if (config != 0) { |
240 | qDebug("config != 0 "); | ||
241 | if ( family == "syncContact" ) { | ||
242 | qDebug("creating sync config "); | ||
243 | fami = "contact"; | ||
244 | KConfig* con = new KConfig( locateLocal("config", "syncContactrc") ); | ||
245 | con->setGroup( "General" ); | ||
246 | con->writeEntry( "ResourceKeys", QString("sync") ); | ||
247 | con->writeEntry( "Standard", QString("sync") ); | ||
248 | con->setGroup( "Resource_sync" ); | ||
249 | con->writeEntry( "FileFormat", QString("vcard") ); | ||
250 | con->writeEntry( "FileName", config ); | ||
251 | con->writeEntry( "ResourceIdentifier", QString("sync") ); | ||
252 | con->writeEntry( "ResourceName", QString("sync_res") ); | ||
253 | con->writeEntry( "ResourceType", QString("file") ); | ||
254 | //con->sync(); | ||
255 | d->mConfig = con; | ||
256 | } | ||
257 | else | ||
238 | d->mConfig = new KConfig( locateLocal("config", config) ); | 258 | d->mConfig = new KConfig( locateLocal("config", config) ); |
239 | // qDebug("AddressBook::init 1 config=%s",config.latin1() ); | 259 | // qDebug("AddressBook::init 1 config=%s",config.latin1() ); |
240 | } | 260 | } |
241 | else { | 261 | else { |
@@ -243,10 +263,59 @@ void AddressBook::init(const QString &config, const QString &family ) | |||
243 | // qDebug("AddressBook::init 1 config=0"); | 263 | // qDebug("AddressBook::init 1 config=0"); |
244 | } | 264 | } |
245 | 265 | ||
246 | //US d->mErrorHandler = 0; | 266 | //US d->mErrorHandler = 0; |
247 | d->mManager = new KRES::Manager<Resource>( family, false ); | 267 | d->mManager = new KRES::Manager<Resource>( fami, false ); |
248 | d->mManager->readConfig( d->mConfig ); | 268 | d->mManager->readConfig( d->mConfig ); |
269 | if ( family == "syncContact" ) { | ||
270 | KRES::Manager<Resource> *manager = d->mManager; | ||
271 | KRES::Manager<Resource>::ActiveIterator it; | ||
272 | for ( it = manager->activeBegin(); it != manager->activeEnd(); ++it ) { | ||
273 | (*it)->setAddressBook( this ); | ||
274 | if ( !(*it)->open() ) | ||
275 | error( QString( "Unable to open resource '%1'!" ).arg( (*it)->resourceName() ) ); | ||
276 | } | ||
277 | Resource *res = standardResource(); | ||
278 | if ( !res ) { | ||
279 | qDebug("ERROR: no standard resource"); | ||
280 | res = manager->createResource( "file" ); | ||
281 | if ( res ) | ||
282 | { | ||
283 | addResource( res ); | ||
284 | } | ||
285 | else | ||
286 | qDebug(" No resource available!!!"); | ||
287 | } | ||
288 | setStandardResource( res ); | ||
289 | manager->writeConfig(); | ||
290 | } | ||
291 | addCustomField( i18n( "Department" ), KABC::Field::Organization, | ||
292 | "X-Department", "KADDRESSBOOK" ); | ||
293 | addCustomField( i18n( "Profession" ), KABC::Field::Organization, | ||
294 | "X-Profession", "KADDRESSBOOK" ); | ||
295 | addCustomField( i18n( "Assistant's Name" ), KABC::Field::Organization, | ||
296 | "X-AssistantsName", "KADDRESSBOOK" ); | ||
297 | addCustomField( i18n( "Manager's Name" ), KABC::Field::Organization, | ||
298 | "X-ManagersName", "KADDRESSBOOK" ); | ||
299 | addCustomField( i18n( "Spouse's Name" ), KABC::Field::Personal, | ||
300 | "X-SpousesName", "KADDRESSBOOK" ); | ||
301 | addCustomField( i18n( "Office" ), KABC::Field::Personal, | ||
302 | "X-Office", "KADDRESSBOOK" ); | ||
303 | addCustomField( i18n( "IM Address" ), KABC::Field::Personal, | ||
304 | "X-IMAddress", "KADDRESSBOOK" ); | ||
305 | addCustomField( i18n( "Anniversary" ), KABC::Field::Personal, | ||
306 | "X-Anniversary", "KADDRESSBOOK" ); | ||
307 | |||
308 | //US added this field to become compatible with Opie/qtopia addressbook | ||
309 | // values can be "female" or "male" or "". An empty field represents undefined. | ||
310 | addCustomField( i18n( "Gender" ), KABC::Field::Personal, | ||
311 | "X-Gender", "KADDRESSBOOK" ); | ||
312 | addCustomField( i18n( "Children" ), KABC::Field::Personal, | ||
313 | "X-Children", "KADDRESSBOOK" ); | ||
314 | addCustomField( i18n( "FreeBusyUrl" ), KABC::Field::Personal, | ||
315 | "X-FreeBusyUrl", "KADDRESSBOOK" ); | ||
316 | addCustomField( i18n( "ExternalID" ), KABC::Field::Personal, | ||
317 | "X-ExternalID", "KADDRESSBOOK" ); | ||
249 | } | 318 | } |
250 | 319 | ||
251 | AddressBook::~AddressBook() | 320 | AddressBook::~AddressBook() |
252 | { | 321 | { |
@@ -283,14 +352,42 @@ bool AddressBook::save( Ticket *ticket ) | |||
283 | kdDebug(5700) << "AddressBook::save()"<< endl; | 352 | kdDebug(5700) << "AddressBook::save()"<< endl; |
284 | 353 | ||
285 | if ( ticket->resource() ) { | 354 | if ( ticket->resource() ) { |
286 | deleteRemovedAddressees(); | 355 | deleteRemovedAddressees(); |
287 | |||
288 | return ticket->resource()->save( ticket ); | 356 | return ticket->resource()->save( ticket ); |
289 | } | 357 | } |
290 | 358 | ||
291 | return false; | 359 | return false; |
292 | } | 360 | } |
361 | bool AddressBook::saveAB() | ||
362 | { | ||
363 | bool ok = true; | ||
364 | |||
365 | deleteRemovedAddressees(); | ||
366 | |||
367 | KRES::Manager<Resource>::ActiveIterator it; | ||
368 | KRES::Manager<Resource> *manager = d->mManager; | ||
369 | for ( it = manager->activeBegin(); it != manager->activeEnd(); ++it ) { | ||
370 | if ( !(*it)->readOnly() && (*it)->isOpen() ) { | ||
371 | Ticket *ticket = requestSaveTicket( *it ); | ||
372 | // qDebug("StdAddressBook::save '%s'", (*it)->resourceName().latin1() ); | ||
373 | if ( !ticket ) { | ||
374 | error( i18n( "Unable to save to resource '%1'. It is locked." ) | ||
375 | .arg( (*it)->resourceName() ) ); | ||
376 | return false; | ||
377 | } | ||
378 | |||
379 | //if ( !save( ticket ) ) | ||
380 | if ( ticket->resource() ) { | ||
381 | if ( ! ticket->resource()->save( ticket ) ) | ||
382 | ok = false; | ||
383 | } else | ||
384 | ok = false; | ||
385 | |||
386 | } | ||
387 | } | ||
388 | return ok; | ||
389 | } | ||
293 | 390 | ||
294 | AddressBook::Iterator AddressBook::begin() | 391 | AddressBook::Iterator AddressBook::begin() |
295 | { | 392 | { |
296 | Iterator it = Iterator(); | 393 | Iterator it = Iterator(); |
diff --git a/kabc/addressbook.h b/kabc/addressbook.h index f89d7da..e43de31 100644 --- a/kabc/addressbook.h +++ b/kabc/addressbook.h | |||
@@ -140,8 +140,9 @@ class AddressBook : public QObject | |||
140 | 140 | ||
141 | @param ticket a ticket object returned by @ref requestSaveTicket() | 141 | @param ticket a ticket object returned by @ref requestSaveTicket() |
142 | */ | 142 | */ |
143 | bool save( Ticket *ticket ); | 143 | bool save( Ticket *ticket ); |
144 | bool saveAB( ); | ||
144 | 145 | ||
145 | /** | 146 | /** |
146 | Returns a iterator for first entry of address book. | 147 | Returns a iterator for first entry of address book. |
147 | */ | 148 | */ |