author | zautrix <zautrix> | 2005-12-02 09:42:53 (UTC) |
---|---|---|
committer | zautrix <zautrix> | 2005-12-02 09:42:53 (UTC) |
commit | a75d2c26aba6cffae8c3f61e173940240042427b (patch) (unidiff) | |
tree | 68f4b61c150bc263a98c78fdf8671bbbc17cdaf8 /kabc/addressbook.cpp | |
parent | 64be8d64fc26d1025a24150d065197ba5d608f3d (diff) | |
download | kdepimpi-a75d2c26aba6cffae8c3f61e173940240042427b.zip kdepimpi-a75d2c26aba6cffae8c3f61e173940240042427b.tar.gz kdepimpi-a75d2c26aba6cffae8c3f61e173940240042427b.tar.bz2 |
more sync
-rw-r--r-- | kabc/addressbook.cpp | 42 |
1 files changed, 33 insertions, 9 deletions
diff --git a/kabc/addressbook.cpp b/kabc/addressbook.cpp index e04f4b1..bdc2762 100644 --- a/kabc/addressbook.cpp +++ b/kabc/addressbook.cpp | |||
@@ -294,430 +294,454 @@ void AddressBook::init(const QString &config, const QString &family ) | |||
294 | if ( res ) | 294 | if ( res ) |
295 | { | 295 | { |
296 | addResource( res ); | 296 | addResource( res ); |
297 | } | 297 | } |
298 | else | 298 | else |
299 | qDebug(" No resource available!!!"); | 299 | qDebug(" No resource available!!!"); |
300 | } | 300 | } |
301 | setStandardResource( res ); | 301 | setStandardResource( res ); |
302 | manager->writeConfig(); | 302 | manager->writeConfig(); |
303 | } | 303 | } |
304 | addCustomField( i18n( "Department" ), KABC::Field::Organization, | 304 | addCustomField( i18n( "Department" ), KABC::Field::Organization, |
305 | "X-Department", "KADDRESSBOOK" ); | 305 | "X-Department", "KADDRESSBOOK" ); |
306 | addCustomField( i18n( "Profession" ), KABC::Field::Organization, | 306 | addCustomField( i18n( "Profession" ), KABC::Field::Organization, |
307 | "X-Profession", "KADDRESSBOOK" ); | 307 | "X-Profession", "KADDRESSBOOK" ); |
308 | addCustomField( i18n( "Assistant's Name" ), KABC::Field::Organization, | 308 | addCustomField( i18n( "Assistant's Name" ), KABC::Field::Organization, |
309 | "X-AssistantsName", "KADDRESSBOOK" ); | 309 | "X-AssistantsName", "KADDRESSBOOK" ); |
310 | addCustomField( i18n( "Manager's Name" ), KABC::Field::Organization, | 310 | addCustomField( i18n( "Manager's Name" ), KABC::Field::Organization, |
311 | "X-ManagersName", "KADDRESSBOOK" ); | 311 | "X-ManagersName", "KADDRESSBOOK" ); |
312 | addCustomField( i18n( "Spouse's Name" ), KABC::Field::Personal, | 312 | addCustomField( i18n( "Spouse's Name" ), KABC::Field::Personal, |
313 | "X-SpousesName", "KADDRESSBOOK" ); | 313 | "X-SpousesName", "KADDRESSBOOK" ); |
314 | addCustomField( i18n( "Office" ), KABC::Field::Personal, | 314 | addCustomField( i18n( "Office" ), KABC::Field::Personal, |
315 | "X-Office", "KADDRESSBOOK" ); | 315 | "X-Office", "KADDRESSBOOK" ); |
316 | addCustomField( i18n( "IM Address" ), KABC::Field::Personal, | 316 | addCustomField( i18n( "IM Address" ), KABC::Field::Personal, |
317 | "X-IMAddress", "KADDRESSBOOK" ); | 317 | "X-IMAddress", "KADDRESSBOOK" ); |
318 | addCustomField( i18n( "Anniversary" ), KABC::Field::Personal, | 318 | addCustomField( i18n( "Anniversary" ), KABC::Field::Personal, |
319 | "X-Anniversary", "KADDRESSBOOK" ); | 319 | "X-Anniversary", "KADDRESSBOOK" ); |
320 | 320 | ||
321 | //US added this field to become compatible with Opie/qtopia addressbook | 321 | //US added this field to become compatible with Opie/qtopia addressbook |
322 | // values can be "female" or "male" or "". An empty field represents undefined. | 322 | // values can be "female" or "male" or "". An empty field represents undefined. |
323 | addCustomField( i18n( "Gender" ), KABC::Field::Personal, | 323 | addCustomField( i18n( "Gender" ), KABC::Field::Personal, |
324 | "X-Gender", "KADDRESSBOOK" ); | 324 | "X-Gender", "KADDRESSBOOK" ); |
325 | addCustomField( i18n( "Children" ), KABC::Field::Personal, | 325 | addCustomField( i18n( "Children" ), KABC::Field::Personal, |
326 | "X-Children", "KADDRESSBOOK" ); | 326 | "X-Children", "KADDRESSBOOK" ); |
327 | addCustomField( i18n( "FreeBusyUrl" ), KABC::Field::Personal, | 327 | addCustomField( i18n( "FreeBusyUrl" ), KABC::Field::Personal, |
328 | "X-FreeBusyUrl", "KADDRESSBOOK" ); | 328 | "X-FreeBusyUrl", "KADDRESSBOOK" ); |
329 | addCustomField( i18n( "ExternalID" ), KABC::Field::Personal, | 329 | addCustomField( i18n( "ExternalID" ), KABC::Field::Personal, |
330 | "X-ExternalID", "KADDRESSBOOK" ); | 330 | "X-ExternalID", "KADDRESSBOOK" ); |
331 | } | 331 | } |
332 | 332 | ||
333 | AddressBook::~AddressBook() | 333 | AddressBook::~AddressBook() |
334 | { | 334 | { |
335 | delete d->mConfig; d->mConfig = 0; | 335 | delete d->mConfig; d->mConfig = 0; |
336 | delete d->mManager; d->mManager = 0; | 336 | delete d->mManager; d->mManager = 0; |
337 | //US delete d->mErrorHandler; d->mErrorHandler = 0; | 337 | //US delete d->mErrorHandler; d->mErrorHandler = 0; |
338 | delete d; d = 0; | 338 | delete d; d = 0; |
339 | } | 339 | } |
340 | 340 | ||
341 | bool AddressBook::load() | 341 | bool AddressBook::load() |
342 | { | 342 | { |
343 | 343 | ||
344 | clear(); | 344 | clear(); |
345 | KRES::Manager<Resource>::ActiveIterator it; | 345 | KRES::Manager<Resource>::ActiveIterator it; |
346 | bool ok = true; | 346 | bool ok = true; |
347 | for ( it = d->mManager->activeBegin(); it != d->mManager->activeEnd(); ++it ) | 347 | for ( it = d->mManager->activeBegin(); it != d->mManager->activeEnd(); ++it ) |
348 | if ( !(*it)->load() ) { | 348 | if ( !(*it)->load() ) { |
349 | qDebug( i18n("Unable to load resource '%1'").arg( (*it)->resourceName() ) ); | 349 | qDebug( i18n("Unable to load resource '%1'").arg( (*it)->resourceName() ) ); |
350 | ok = false; | 350 | ok = false; |
351 | } else { | 351 | } else { |
352 | qDebug( i18n("Resource loaded: '%1'").arg( (*it)->resourceName() ) ); | 352 | qDebug( i18n("Resource loaded: '%1'").arg( (*it)->resourceName() ) ); |
353 | } | 353 | } |
354 | // mark all addressees as unchanged | 354 | // mark all addressees as unchanged |
355 | Addressee::List::Iterator addrIt; | 355 | Addressee::List::Iterator addrIt; |
356 | for ( addrIt = d->mAddressees.begin(); addrIt != d->mAddressees.end(); ++addrIt ) { | 356 | for ( addrIt = d->mAddressees.begin(); addrIt != d->mAddressees.end(); ++addrIt ) { |
357 | (*addrIt).setChanged( false ); | 357 | (*addrIt).setChanged( false ); |
358 | QString id = (*addrIt).custom( "KADDRESSBOOK", "X-ExternalID" ); | 358 | QString id = (*addrIt).custom( "KADDRESSBOOK", "X-ExternalID" ); |
359 | if ( !id.isEmpty() ) { | 359 | if ( !id.isEmpty() ) { |
360 | //qDebug("setId aa %s ", id.latin1()); | 360 | //qDebug("setId aa %s ", id.latin1()); |
361 | (*addrIt).setIDStr(id ); | 361 | (*addrIt).setIDStr(id ); |
362 | } | 362 | } |
363 | } | 363 | } |
364 | blockLSEchange = true; | 364 | blockLSEchange = true; |
365 | return ok; | 365 | return ok; |
366 | } | 366 | } |
367 | 367 | ||
368 | bool AddressBook::save( Ticket *ticket ) | 368 | bool AddressBook::save( Ticket *ticket ) |
369 | { | 369 | { |
370 | kdDebug(5700) << "AddressBook::save()"<< endl; | 370 | kdDebug(5700) << "AddressBook::save()"<< endl; |
371 | 371 | ||
372 | if ( ticket->resource() ) { | 372 | if ( ticket->resource() ) { |
373 | deleteRemovedAddressees(); | 373 | deleteRemovedAddressees(); |
374 | return ticket->resource()->save( ticket ); | 374 | return ticket->resource()->save( ticket ); |
375 | } | 375 | } |
376 | 376 | ||
377 | return false; | 377 | return false; |
378 | } | 378 | } |
379 | // exports all Addressees, which are syncable | 379 | // exports all Addressees, which are syncable |
380 | void AddressBook::export2File( QString fileName, QString resourceName ) | 380 | void AddressBook::export2File( QString fileName, QString resourceName ) |
381 | { | 381 | { |
382 | 382 | ||
383 | QFile outFile( fileName ); | 383 | QFile outFile( fileName ); |
384 | if ( !outFile.open( IO_WriteOnly ) ) { | 384 | if ( !outFile.open( IO_WriteOnly ) ) { |
385 | QString text = i18n( "<qt>Unable to open file <b>%1</b> for export.</qt>" ); | 385 | QString text = i18n( "<qt>Unable to open file <b>%1</b> for export.</qt>" ); |
386 | KMessageBox::error( 0, text.arg( fileName ) ); | 386 | KMessageBox::error( 0, text.arg( fileName ) ); |
387 | return ; | 387 | return ; |
388 | } | 388 | } |
389 | QTextStream t( &outFile ); | 389 | QTextStream t( &outFile ); |
390 | t.setEncoding( QTextStream::UnicodeUTF8 ); | 390 | t.setEncoding( QTextStream::UnicodeUTF8 ); |
391 | Iterator it; | 391 | Iterator it; |
392 | KABC::VCardConverter::Version version; | 392 | KABC::VCardConverter::Version version; |
393 | version = KABC::VCardConverter::v3_0; | 393 | version = KABC::VCardConverter::v3_0; |
394 | for ( it = begin(); it != end(); ++it ) { | 394 | for ( it = begin(); it != end(); ++it ) { |
395 | if ( (*it).resource() ) { | 395 | if ( (*it).resource() ) { |
396 | bool include = (*it).resource()->includeInSync(); | 396 | bool include = (*it).resource()->includeInSync(); |
397 | if ( !resourceName.isEmpty() ) | 397 | if ( !resourceName.isEmpty() ) |
398 | include = (resourceName == (*it).resource()->name() ); | 398 | include = (resourceName == (*it).resource()->name() ); |
399 | if ( include ) { | 399 | if ( include ) { |
400 | qDebug(QString ("Exporting resource %1 to file %2").arg( (*it).resource()->name() ).arg( fileName ) ); | 400 | qDebug(QString ("Exporting resource %1 to file %2").arg( (*it).resource()->name() ).arg( fileName ) ); |
401 | if ( !(*it).IDStr().isEmpty() ) { | 401 | if ( !(*it).IDStr().isEmpty() ) { |
402 | (*it).insertCustom( "KADDRESSBOOK", "X-ExternalID", (*it).IDStr() ); | 402 | (*it).insertCustom( "KADDRESSBOOK", "X-ExternalID", (*it).IDStr() ); |
403 | } | 403 | } |
404 | KABC::VCardConverter converter; | 404 | KABC::VCardConverter converter; |
405 | QString vcard; | 405 | QString vcard; |
406 | //Resource *resource() const; | 406 | //Resource *resource() const; |
407 | converter.addresseeToVCard( *it, vcard, version ); | 407 | converter.addresseeToVCard( *it, vcard, version ); |
408 | t << vcard << "\r\n"; | 408 | t << vcard << "\r\n"; |
409 | } | 409 | } |
410 | } | 410 | } |
411 | } | 411 | } |
412 | t << "\r\n\r\n"; | 412 | t << "\r\n\r\n"; |
413 | outFile.close(); | 413 | outFile.close(); |
414 | } | 414 | } |
415 | // if QStringList uids is empty, all are exported | 415 | // if QStringList uids is empty, all are exported |
416 | bool AddressBook::export2PhoneFormat( QStringList uids ,QString fileName ) | 416 | bool AddressBook::export2PhoneFormat( QStringList uids ,QString fileName ) |
417 | { | 417 | { |
418 | KABC::VCardConverter converter; | 418 | KABC::VCardConverter converter; |
419 | QString datastream; | 419 | QString datastream; |
420 | Iterator it; | 420 | Iterator it; |
421 | bool all = uids.isEmpty(); | 421 | bool all = uids.isEmpty(); |
422 | for ( it = begin(); it != end(); ++it ) { | 422 | for ( it = begin(); it != end(); ++it ) { |
423 | // for( QStringList::ConstIterator it = uids.begin(); it != uids.end(); ++it ) { | 423 | // for( QStringList::ConstIterator it = uids.begin(); it != uids.end(); ++it ) { |
424 | if ( ! all ) { | 424 | if ( ! all ) { |
425 | if ( ! ( uids.contains((*it).uid() ) )) | 425 | if ( ! ( uids.contains((*it).uid() ) )) |
426 | continue; | 426 | continue; |
427 | } | 427 | } |
428 | KABC::Addressee a = ( *it ); | 428 | KABC::Addressee a = ( *it ); |
429 | if ( a.isEmpty() ) | 429 | if ( a.isEmpty() ) |
430 | continue; | 430 | continue; |
431 | if ( all && a.resource() && !a.resource()->includeInSync() ) | 431 | if ( all && a.resource() && !a.resource()->includeInSync() ) |
432 | continue; | 432 | continue; |
433 | a.simplifyEmails(); | 433 | a.simplifyEmails(); |
434 | a.simplifyPhoneNumbers(); | 434 | a.simplifyPhoneNumbers(); |
435 | a.simplifyPhoneNumberTypes(); | 435 | a.simplifyPhoneNumberTypes(); |
436 | a.simplifyAddresses(); | 436 | a.simplifyAddresses(); |
437 | 437 | ||
438 | QString vcard; | 438 | QString vcard; |
439 | QString vcardnew; | 439 | QString vcardnew; |
440 | converter.addresseeToVCard( a, vcard ); | 440 | converter.addresseeToVCard( a, vcard ); |
441 | int start = 0; | 441 | int start = 0; |
442 | int next; | 442 | int next; |
443 | while ( (next = vcard.find("TYPE=", start) )>= 0 ) { | 443 | while ( (next = vcard.find("TYPE=", start) )>= 0 ) { |
444 | int semi = vcard.find(";", next); | 444 | int semi = vcard.find(";", next); |
445 | int dopp = vcard.find(":", next); | 445 | int dopp = vcard.find(":", next); |
446 | int sep; | 446 | int sep; |
447 | if ( semi < dopp && semi >= 0 ) | 447 | if ( semi < dopp && semi >= 0 ) |
448 | sep = semi ; | 448 | sep = semi ; |
449 | else | 449 | else |
450 | sep = dopp; | 450 | sep = dopp; |
451 | vcardnew +=vcard.mid( start, next - start); | 451 | vcardnew +=vcard.mid( start, next - start); |
452 | vcardnew +=vcard.mid( next+5,sep -next -5 ).upper(); | 452 | vcardnew +=vcard.mid( next+5,sep -next -5 ).upper(); |
453 | start = sep; | 453 | start = sep; |
454 | } | 454 | } |
455 | vcardnew += vcard.mid( start,vcard.length() ); | 455 | vcardnew += vcard.mid( start,vcard.length() ); |
456 | vcard = ""; | 456 | vcard = ""; |
457 | start = 0; | 457 | start = 0; |
458 | while ( (next = vcardnew.find("ADR", start) )>= 0 ) { | 458 | while ( (next = vcardnew.find("ADR", start) )>= 0 ) { |
459 | int sep = vcardnew.find(":", next); | 459 | int sep = vcardnew.find(":", next); |
460 | vcard +=vcardnew.mid( start, next - start+3); | 460 | vcard +=vcardnew.mid( start, next - start+3); |
461 | start = sep; | 461 | start = sep; |
462 | } | 462 | } |
463 | vcard += vcardnew.mid( start,vcardnew.length() ); | 463 | vcard += vcardnew.mid( start,vcardnew.length() ); |
464 | vcard.replace ( QRegExp(";;;") , "" ); | 464 | vcard.replace ( QRegExp(";;;") , "" ); |
465 | vcard.replace ( QRegExp(";;") , "" ); | 465 | vcard.replace ( QRegExp(";;") , "" ); |
466 | datastream += vcard; | 466 | datastream += vcard; |
467 | 467 | ||
468 | } | 468 | } |
469 | 469 | ||
470 | QFile outFile(fileName); | 470 | QFile outFile(fileName); |
471 | if ( outFile.open(IO_WriteOnly) ) { | 471 | if ( outFile.open(IO_WriteOnly) ) { |
472 | datastream.replace ( QRegExp("VERSION:3.0") , "VERSION:2.1" ); | 472 | datastream.replace ( QRegExp("VERSION:3.0") , "VERSION:2.1" ); |
473 | QTextStream t( &outFile ); // use a text stream | 473 | QTextStream t( &outFile ); // use a text stream |
474 | t.setEncoding( QTextStream::UnicodeUTF8 ); | 474 | t.setEncoding( QTextStream::UnicodeUTF8 ); |
475 | t <<datastream; | 475 | t <<datastream; |
476 | t << "\r\n\r\n"; | 476 | t << "\r\n\r\n"; |
477 | outFile.close(); | 477 | outFile.close(); |
478 | 478 | ||
479 | } else { | 479 | } else { |
480 | qDebug("Error open temp file "); | 480 | qDebug("Error open temp file "); |
481 | return false; | 481 | return false; |
482 | } | 482 | } |
483 | return true; | 483 | return true; |
484 | 484 | ||
485 | } | 485 | } |
486 | int AddressBook::importFromFile( QString fileName, bool replaceLabel, bool removeOld ) | 486 | int AddressBook::importFromFile( QString fileName, bool replaceLabel, bool removeOld, QString resource ) |
487 | { | 487 | { |
488 | 488 | ||
489 | if ( removeOld ) | 489 | if ( removeOld ) |
490 | setUntagged( true ); | 490 | setUntagged( true, resource ); |
491 | KABC::Addressee::List list; | 491 | KABC::Addressee::List list; |
492 | QFile file( fileName ); | 492 | QFile file( fileName ); |
493 | file.open( IO_ReadOnly ); | 493 | file.open( IO_ReadOnly ); |
494 | QByteArray rawData = file.readAll(); | 494 | QByteArray rawData = file.readAll(); |
495 | file.close(); | 495 | file.close(); |
496 | QString data; | 496 | QString data; |
497 | if ( replaceLabel ) { | 497 | if ( replaceLabel ) { |
498 | data = QString::fromLatin1( rawData.data(), rawData.size() + 1 ); | 498 | data = QString::fromLatin1( rawData.data(), rawData.size() + 1 ); |
499 | data.replace ( QRegExp("LABEL") , "ADR" ); | 499 | data.replace ( QRegExp("LABEL") , "ADR" ); |
500 | data.replace ( QRegExp("CHARSET=ISO-8859-1") , "" ); | 500 | data.replace ( QRegExp("CHARSET=ISO-8859-1") , "" ); |
501 | } else | 501 | } else |
502 | data = QString::fromUtf8( rawData.data(), rawData.size() + 1 ); | 502 | data = QString::fromUtf8( rawData.data(), rawData.size() + 1 ); |
503 | KABC::VCardTool tool; | 503 | KABC::VCardTool tool; |
504 | list = tool.parseVCards( data ); | 504 | list = tool.parseVCards( data ); |
505 | KABC::Addressee::List::Iterator it; | 505 | KABC::Addressee::List::Iterator it; |
506 | |||
507 | Resource * setRes = 0; | ||
508 | if ( !resource.isEmpty() ) { | ||
509 | KRES::Manager<Resource>::ActiveIterator it; | ||
510 | KRES::Manager<Resource> *manager = d->mManager; | ||
511 | for ( it = manager->activeBegin(); it != manager->activeEnd(); ++it ) { | ||
512 | qDebug("SaveAB::checking resource..." ); | ||
513 | if ( (*it)->name() == resource ) { | ||
514 | setRes = (*it); | ||
515 | qDebug("Inserting imported contacs to resource %s", resource.latin1()); | ||
516 | break; | ||
517 | } | ||
518 | } | ||
519 | } | ||
506 | for ( it = list.begin(); it != list.end(); ++it ) { | 520 | for ( it = list.begin(); it != list.end(); ++it ) { |
507 | QString id = (*it).custom( "KADDRESSBOOK", "X-ExternalID" ); | 521 | QString id = (*it).custom( "KADDRESSBOOK", "X-ExternalID" ); |
508 | if ( !id.isEmpty() ) | 522 | if ( !id.isEmpty() ) |
509 | (*it).setIDStr(id ); | 523 | (*it).setIDStr(id ); |
510 | (*it).setResource( 0 ); | 524 | (*it).setResource( setRes ); |
511 | if ( replaceLabel ) | 525 | if ( replaceLabel ) |
512 | (*it).removeVoice(); | 526 | (*it).removeVoice(); |
513 | if ( removeOld ) | 527 | if ( removeOld ) |
514 | (*it).setTagged( true ); | 528 | (*it).setTagged( true ); |
515 | insertAddressee( (*it), false, true ); | 529 | insertAddressee( (*it), false, true ); |
516 | } | 530 | } |
517 | if ( removeOld ) | 531 | if ( removeOld ) |
518 | removeUntagged(); | 532 | removeUntagged(); |
519 | return list.count(); | 533 | return list.count(); |
520 | } | 534 | } |
521 | void AddressBook::setUntagged(bool setNonSyncTagged) // = false) | 535 | void AddressBook::setUntagged(bool setNonSyncTagged, QString resource) // = false , "") |
522 | { | 536 | { |
523 | Iterator ait; | 537 | Iterator ait; |
524 | for ( ait = begin(); ait != end(); ++ait ) { | 538 | if ( !resource.isEmpty() ) { |
525 | if ( setNonSyncTagged ) { | 539 | for ( ait = begin(); ait != end(); ++ait ) { |
526 | if ( (*ait).resource() && ! (*ait).resource()->includeInSync() ) { | 540 | if ( (*ait).resource() && (*ait).resource()->name() == resource ) { |
541 | (*ait).setTagged( false ); | ||
542 | } | ||
543 | else | ||
527 | (*ait).setTagged( true ); | 544 | (*ait).setTagged( true ); |
545 | } | ||
546 | } else { | ||
547 | for ( ait = begin(); ait != end(); ++ait ) { | ||
548 | if ( setNonSyncTagged ) { | ||
549 | if ( (*ait).resource() && ! (*ait).resource()->includeInSync() ) { | ||
550 | (*ait).setTagged( true ); | ||
551 | } else | ||
552 | (*ait).setTagged( false ); | ||
528 | } else | 553 | } else |
529 | (*ait).setTagged( false ); | 554 | (*ait).setTagged( false ); |
530 | } else | 555 | } |
531 | (*ait).setTagged( false ); | ||
532 | } | 556 | } |
533 | } | 557 | } |
534 | void AddressBook::removeUntagged() | 558 | void AddressBook::removeUntagged() |
535 | { | 559 | { |
536 | Iterator ait; | 560 | Iterator ait; |
537 | bool todelete = false; | 561 | bool todelete = false; |
538 | Iterator todel; | 562 | Iterator todel; |
539 | for ( ait = begin(); ait != end(); ++ait ) { | 563 | for ( ait = begin(); ait != end(); ++ait ) { |
540 | if ( todelete ) | 564 | if ( todelete ) |
541 | removeAddressee( todel ); | 565 | removeAddressee( todel ); |
542 | if (!(*ait).tagged()) { | 566 | if (!(*ait).tagged()) { |
543 | todelete = true; | 567 | todelete = true; |
544 | todel = ait; | 568 | todel = ait; |
545 | } else | 569 | } else |
546 | todelete = false; | 570 | todelete = false; |
547 | } | 571 | } |
548 | if ( todelete ) | 572 | if ( todelete ) |
549 | removeAddressee( todel ); | 573 | removeAddressee( todel ); |
550 | deleteRemovedAddressees(); | 574 | deleteRemovedAddressees(); |
551 | } | 575 | } |
552 | void AddressBook::smplifyAddressees() | 576 | void AddressBook::smplifyAddressees() |
553 | { | 577 | { |
554 | Iterator ait; | 578 | Iterator ait; |
555 | for ( ait = begin(); ait != end(); ++ait ) { | 579 | for ( ait = begin(); ait != end(); ++ait ) { |
556 | (*ait).simplifyEmails(); | 580 | (*ait).simplifyEmails(); |
557 | (*ait).simplifyPhoneNumbers(); | 581 | (*ait).simplifyPhoneNumbers(); |
558 | (*ait).simplifyPhoneNumberTypes(); | 582 | (*ait).simplifyPhoneNumberTypes(); |
559 | (*ait).simplifyAddresses(); | 583 | (*ait).simplifyAddresses(); |
560 | } | 584 | } |
561 | } | 585 | } |
562 | void AddressBook::removeSyncInfo( QString syncProfile) | 586 | void AddressBook::removeSyncInfo( QString syncProfile) |
563 | { | 587 | { |
564 | Iterator ait; | 588 | Iterator ait; |
565 | for ( ait = begin(); ait != end(); ++ait ) { | 589 | for ( ait = begin(); ait != end(); ++ait ) { |
566 | (*ait).removeID( syncProfile ); | 590 | (*ait).removeID( syncProfile ); |
567 | } | 591 | } |
568 | if ( syncProfile.isEmpty() ) { | 592 | if ( syncProfile.isEmpty() ) { |
569 | Iterator it = begin(); | 593 | Iterator it = begin(); |
570 | Iterator it2 ; | 594 | Iterator it2 ; |
571 | while ( it != end() ) { | 595 | while ( it != end() ) { |
572 | if ( (*it).uid().left( 19 ) == QString("last-syncAddressee-") ) { | 596 | if ( (*it).uid().left( 19 ) == QString("last-syncAddressee-") ) { |
573 | it2 = it; | 597 | it2 = it; |
574 | //qDebug("removing %s ",(*it).uid().latin1() ); | 598 | //qDebug("removing %s ",(*it).uid().latin1() ); |
575 | ++it; | 599 | ++it; |
576 | removeAddressee( it2 ); | 600 | removeAddressee( it2 ); |
577 | } else { | 601 | } else { |
578 | //qDebug("skipping %s ",(*it).uid().latin1() ); | 602 | //qDebug("skipping %s ",(*it).uid().latin1() ); |
579 | ++it; | 603 | ++it; |
580 | } | 604 | } |
581 | } | 605 | } |
582 | } else { | 606 | } else { |
583 | Addressee lse; | 607 | Addressee lse; |
584 | lse = findByUid( "last-syncAddressee-"+ syncProfile ); | 608 | lse = findByUid( "last-syncAddressee-"+ syncProfile ); |
585 | if ( ! lse.isEmpty() ) | 609 | if ( ! lse.isEmpty() ) |
586 | removeAddressee( lse ); | 610 | removeAddressee( lse ); |
587 | } | 611 | } |
588 | 612 | ||
589 | } | 613 | } |
590 | void AddressBook::preparePhoneSync( QString currentSyncDevice, bool isPreSync ) | 614 | void AddressBook::preparePhoneSync( QString currentSyncDevice, bool isPreSync ) |
591 | { | 615 | { |
592 | Iterator ait; | 616 | Iterator ait; |
593 | for ( ait = begin(); ait != end(); ++ait ) { | 617 | for ( ait = begin(); ait != end(); ++ait ) { |
594 | QString id = (*ait).IDStr(); | 618 | QString id = (*ait).IDStr(); |
595 | (*ait).setIDStr( ":"); | 619 | (*ait).setIDStr( ":"); |
596 | (*ait).setExternalUID( id ); | 620 | (*ait).setExternalUID( id ); |
597 | (*ait).setOriginalExternalUID( id ); | 621 | (*ait).setOriginalExternalUID( id ); |
598 | if ( isPreSync ) | 622 | if ( isPreSync ) |
599 | (*ait).setTempSyncStat( SYNC_TEMPSTATE_NEW_EXTERNAL ); | 623 | (*ait).setTempSyncStat( SYNC_TEMPSTATE_NEW_EXTERNAL ); |
600 | else { | 624 | else { |
601 | (*ait).setTempSyncStat( SYNC_TEMPSTATE_NEW_ID ); | 625 | (*ait).setTempSyncStat( SYNC_TEMPSTATE_NEW_ID ); |
602 | (*ait).setID( currentSyncDevice,id ); | 626 | (*ait).setID( currentSyncDevice,id ); |
603 | 627 | ||
604 | } | 628 | } |
605 | } | 629 | } |
606 | } | 630 | } |
607 | void AddressBook::findNewExtIds( QString fileName, QString currentSyncDevice ) | 631 | void AddressBook::findNewExtIds( QString fileName, QString currentSyncDevice ) |
608 | { | 632 | { |
609 | 633 | ||
610 | setUntagged(); | 634 | setUntagged(); |
611 | KABC::Addressee::List list; | 635 | KABC::Addressee::List list; |
612 | QFile file( fileName ); | 636 | QFile file( fileName ); |
613 | file.open( IO_ReadOnly ); | 637 | file.open( IO_ReadOnly ); |
614 | QByteArray rawData = file.readAll(); | 638 | QByteArray rawData = file.readAll(); |
615 | file.close(); | 639 | file.close(); |
616 | QString data; | 640 | QString data; |
617 | 641 | ||
618 | data = QString::fromUtf8( rawData.data(), rawData.size() + 1 ); | 642 | data = QString::fromUtf8( rawData.data(), rawData.size() + 1 ); |
619 | KABC::VCardTool tool; | 643 | KABC::VCardTool tool; |
620 | list = tool.parseVCards( data ); | 644 | list = tool.parseVCards( data ); |
621 | KABC::Addressee::List::Iterator it; | 645 | KABC::Addressee::List::Iterator it; |
622 | for ( it = list.begin(); it != list.end(); ++it ) { | 646 | for ( it = list.begin(); it != list.end(); ++it ) { |
623 | Iterator ait; | 647 | Iterator ait; |
624 | for ( ait = begin(); ait != end(); ++ait ) { | 648 | for ( ait = begin(); ait != end(); ++ait ) { |
625 | if ( !(*ait).tagged() ) { | 649 | if ( !(*ait).tagged() ) { |
626 | if ( (*ait).containsAdr(*it)) { | 650 | if ( (*ait).containsAdr(*it)) { |
627 | (*ait).setTagged(true); | 651 | (*ait).setTagged(true); |
628 | QString id = (*it).custom( "KADDRESSBOOK", "X-ExternalID" ); | 652 | QString id = (*it).custom( "KADDRESSBOOK", "X-ExternalID" ); |
629 | (*it).setIDStr( ":"); | 653 | (*it).setIDStr( ":"); |
630 | (*it).setID( currentSyncDevice,id ); | 654 | (*it).setID( currentSyncDevice,id ); |
631 | (*it).setExternalUID( id ); | 655 | (*it).setExternalUID( id ); |
632 | (*it).setTempSyncStat( SYNC_TEMPSTATE_NEW_ID ); | 656 | (*it).setTempSyncStat( SYNC_TEMPSTATE_NEW_ID ); |
633 | (*it).setUid( ( (*ait).uid() )); | 657 | (*it).setUid( ( (*ait).uid() )); |
634 | break; | 658 | break; |
635 | } | 659 | } |
636 | } | 660 | } |
637 | 661 | ||
638 | } | 662 | } |
639 | if ( ait == end() ) | 663 | if ( ait == end() ) |
640 | qDebug("ERROR:: no ext ID found for uid: %s", (*it).uid().latin1()); | 664 | qDebug("ERROR:: no ext ID found for uid: %s", (*it).uid().latin1()); |
641 | } | 665 | } |
642 | clear(); | 666 | clear(); |
643 | for ( it = list.begin(); it != list.end(); ++it ) { | 667 | for ( it = list.begin(); it != list.end(); ++it ) { |
644 | insertAddressee( (*it) ); | 668 | insertAddressee( (*it) ); |
645 | } | 669 | } |
646 | } | 670 | } |
647 | 671 | ||
648 | bool AddressBook::saveABphone( QString fileName ) | 672 | bool AddressBook::saveABphone( QString fileName ) |
649 | { | 673 | { |
650 | //smplifyAddressees(); | 674 | //smplifyAddressees(); |
651 | qDebug("saveABphone:: saving AB... "); | 675 | qDebug("saveABphone:: saving AB... "); |
652 | if ( ! export2PhoneFormat( QStringList() ,fileName ) ) | 676 | if ( ! export2PhoneFormat( QStringList() ,fileName ) ) |
653 | return false; | 677 | return false; |
654 | qDebug("saveABphone:: writing to phone... "); | 678 | qDebug("saveABphone:: writing to phone... "); |
655 | if ( !PhoneAccess::writeToPhone( fileName) ) { | 679 | if ( !PhoneAccess::writeToPhone( fileName) ) { |
656 | return false; | 680 | return false; |
657 | } | 681 | } |
658 | qDebug("saveABphone:: re-reading from phone... "); | 682 | qDebug("saveABphone:: re-reading from phone... "); |
659 | if ( !PhoneAccess::readFromPhone( fileName) ) { | 683 | if ( !PhoneAccess::readFromPhone( fileName) ) { |
660 | return false; | 684 | return false; |
661 | } | 685 | } |
662 | return true; | 686 | return true; |
663 | } | 687 | } |
664 | bool AddressBook::saveAB() | 688 | bool AddressBook::saveAB() |
665 | { | 689 | { |
666 | bool ok = true; | 690 | bool ok = true; |
667 | 691 | ||
668 | deleteRemovedAddressees(); | 692 | deleteRemovedAddressees(); |
669 | Iterator ait; | 693 | Iterator ait; |
670 | for ( ait = begin(); ait != end(); ++ait ) { | 694 | for ( ait = begin(); ait != end(); ++ait ) { |
671 | if ( !(*ait).IDStr().isEmpty() ) { | 695 | if ( !(*ait).IDStr().isEmpty() ) { |
672 | (*ait).insertCustom( "KADDRESSBOOK", "X-ExternalID", (*ait).IDStr() ); | 696 | (*ait).insertCustom( "KADDRESSBOOK", "X-ExternalID", (*ait).IDStr() ); |
673 | } | 697 | } |
674 | } | 698 | } |
675 | KRES::Manager<Resource>::ActiveIterator it; | 699 | KRES::Manager<Resource>::ActiveIterator it; |
676 | KRES::Manager<Resource> *manager = d->mManager; | 700 | KRES::Manager<Resource> *manager = d->mManager; |
677 | qDebug("SaveAB::saving..." ); | 701 | qDebug("SaveAB::saving..." ); |
678 | for ( it = manager->activeBegin(); it != manager->activeEnd(); ++it ) { | 702 | for ( it = manager->activeBegin(); it != manager->activeEnd(); ++it ) { |
679 | qDebug("SaveAB::checking resource..." ); | 703 | qDebug("SaveAB::checking resource..." ); |
680 | if ( (*it)->readOnly() ) | 704 | if ( (*it)->readOnly() ) |
681 | qDebug("SaveAB::resource is readonly." ); | 705 | qDebug("SaveAB::resource is readonly." ); |
682 | if ( (*it)->isOpen() ) | 706 | if ( (*it)->isOpen() ) |
683 | qDebug("SaveAB::resource is open" ); | 707 | qDebug("SaveAB::resource is open" ); |
684 | 708 | ||
685 | if ( !(*it)->readOnly() && (*it)->isOpen() ) { | 709 | if ( !(*it)->readOnly() && (*it)->isOpen() ) { |
686 | Ticket *ticket = requestSaveTicket( *it ); | 710 | Ticket *ticket = requestSaveTicket( *it ); |
687 | qDebug("SaveAB::StdAddressBook::save '%s'", (*it)->resourceName().latin1() ); | 711 | qDebug("SaveAB::StdAddressBook::save '%s'", (*it)->resourceName().latin1() ); |
688 | if ( !ticket ) { | 712 | if ( !ticket ) { |
689 | qDebug( i18n( "SaveAB::Unable to save to resource '%1'. It is locked." ) | 713 | qDebug( i18n( "SaveAB::Unable to save to resource '%1'. It is locked." ) |
690 | .arg( (*it)->resourceName() ) ); | 714 | .arg( (*it)->resourceName() ) ); |
691 | return false; | 715 | return false; |
692 | } | 716 | } |
693 | 717 | ||
694 | //if ( !save( ticket ) ) | 718 | //if ( !save( ticket ) ) |
695 | if ( ticket->resource() ) { | 719 | if ( ticket->resource() ) { |
696 | QString name = ticket->resource()->resourceName(); | 720 | QString name = ticket->resource()->resourceName(); |
697 | if ( ! ticket->resource()->save( ticket ) ) | 721 | if ( ! ticket->resource()->save( ticket ) ) |
698 | ok = false; | 722 | ok = false; |
699 | else | 723 | else |
700 | qDebug("SaveAB::resource saved '%s'", name.latin1() ); | 724 | qDebug("SaveAB::resource saved '%s'", name.latin1() ); |
701 | 725 | ||
702 | } else | 726 | } else |
703 | ok = false; | 727 | ok = false; |
704 | 728 | ||
705 | } | 729 | } |
706 | } | 730 | } |
707 | return ok; | 731 | return ok; |
708 | } | 732 | } |
709 | 733 | ||
710 | AddressBook::Iterator AddressBook::begin() | 734 | AddressBook::Iterator AddressBook::begin() |
711 | { | 735 | { |
712 | Iterator it = Iterator(); | 736 | Iterator it = Iterator(); |
713 | it.d->mIt = d->mAddressees.begin(); | 737 | it.d->mIt = d->mAddressees.begin(); |
714 | return it; | 738 | return it; |
715 | } | 739 | } |
716 | 740 | ||
717 | AddressBook::ConstIterator AddressBook::begin() const | 741 | AddressBook::ConstIterator AddressBook::begin() const |
718 | { | 742 | { |
719 | ConstIterator it = ConstIterator(); | 743 | ConstIterator it = ConstIterator(); |
720 | it.d->mIt = d->mAddressees.begin(); | 744 | it.d->mIt = d->mAddressees.begin(); |
721 | return it; | 745 | return it; |
722 | } | 746 | } |
723 | 747 | ||