author | zautrix <zautrix> | 2004-10-09 17:36:32 (UTC) |
---|---|---|
committer | zautrix <zautrix> | 2004-10-09 17:36:32 (UTC) |
commit | d68435216e1ebc5a7fed391157197994e13992b3 (patch) (unidiff) | |
tree | 3cb23a2cf1ee55ab881670c2d7bb3b54d60c3b59 | |
parent | 59ed933d6c43ecb0ddd3dec53cc289ee8aa68482 (diff) | |
download | kdepimpi-d68435216e1ebc5a7fed391157197994e13992b3.zip kdepimpi-d68435216e1ebc5a7fed391157197994e13992b3.tar.gz kdepimpi-d68435216e1ebc5a7fed391157197994e13992b3.tar.bz2 |
sync fix
-rw-r--r-- | kabc/addressbook.cpp | 16 |
1 files changed, 12 insertions, 4 deletions
diff --git a/kabc/addressbook.cpp b/kabc/addressbook.cpp index ff05f7e..16927e2 100644 --- a/kabc/addressbook.cpp +++ b/kabc/addressbook.cpp | |||
@@ -383,133 +383,141 @@ void AddressBook::export2File( QString fileName ) | |||
383 | if ( !outFile.open( IO_WriteOnly ) ) { | 383 | if ( !outFile.open( IO_WriteOnly ) ) { |
384 | QString text = i18n( "<qt>Unable to open file <b>%1</b> for export.</qt>" ); | 384 | QString text = i18n( "<qt>Unable to open file <b>%1</b> for export.</qt>" ); |
385 | KMessageBox::error( 0, text.arg( fileName ) ); | 385 | KMessageBox::error( 0, text.arg( fileName ) ); |
386 | return ; | 386 | return ; |
387 | } | 387 | } |
388 | QTextStream t( &outFile ); | 388 | QTextStream t( &outFile ); |
389 | t.setEncoding( QTextStream::UnicodeUTF8 ); | 389 | t.setEncoding( QTextStream::UnicodeUTF8 ); |
390 | Iterator it; | 390 | Iterator it; |
391 | KABC::VCardConverter::Version version; | 391 | KABC::VCardConverter::Version version; |
392 | version = KABC::VCardConverter::v3_0; | 392 | version = KABC::VCardConverter::v3_0; |
393 | for ( it = begin(); it != end(); ++it ) { | 393 | for ( it = begin(); it != end(); ++it ) { |
394 | if ( !(*it).IDStr().isEmpty() ) { | 394 | if ( !(*it).IDStr().isEmpty() ) { |
395 | (*it).insertCustom( "KADDRESSBOOK", "X-ExternalID", (*it).IDStr() ); | 395 | (*it).insertCustom( "KADDRESSBOOK", "X-ExternalID", (*it).IDStr() ); |
396 | } | 396 | } |
397 | KABC::VCardConverter converter; | 397 | KABC::VCardConverter converter; |
398 | QString vcard; | 398 | QString vcard; |
399 | //Resource *resource() const; | 399 | //Resource *resource() const; |
400 | converter.addresseeToVCard( *it, vcard, version ); | 400 | converter.addresseeToVCard( *it, vcard, version ); |
401 | t << vcard << "\r\n"; | 401 | t << vcard << "\r\n"; |
402 | } | 402 | } |
403 | t << "\r\n\r\n"; | 403 | t << "\r\n\r\n"; |
404 | outFile.close(); | 404 | outFile.close(); |
405 | } | 405 | } |
406 | void AddressBook::importFromFile( QString fileName, bool replaceLabel, bool removeOld ) | 406 | void AddressBook::importFromFile( QString fileName, bool replaceLabel, bool removeOld ) |
407 | { | 407 | { |
408 | 408 | ||
409 | if ( removeOld ) | 409 | if ( removeOld ) |
410 | setUntagged(); | 410 | setUntagged(); |
411 | KABC::Addressee::List list; | 411 | KABC::Addressee::List list; |
412 | QFile file( fileName ); | 412 | QFile file( fileName ); |
413 | file.open( IO_ReadOnly ); | 413 | file.open( IO_ReadOnly ); |
414 | QByteArray rawData = file.readAll(); | 414 | QByteArray rawData = file.readAll(); |
415 | file.close(); | 415 | file.close(); |
416 | QString data; | 416 | QString data; |
417 | if ( replaceLabel ) { | 417 | if ( replaceLabel ) { |
418 | data = QString::fromLatin1( rawData.data(), rawData.size() + 1 ); | 418 | data = QString::fromLatin1( rawData.data(), rawData.size() + 1 ); |
419 | data.replace ( QRegExp("LABEL") , "ADR" ); | 419 | data.replace ( QRegExp("LABEL") , "ADR" ); |
420 | data.replace ( QRegExp("CHARSET=ISO-8859-1") , "" ); | 420 | data.replace ( QRegExp("CHARSET=ISO-8859-1") , "" ); |
421 | } else | 421 | } else |
422 | data = QString::fromUtf8( rawData.data(), rawData.size() + 1 ); | 422 | data = QString::fromUtf8( rawData.data(), rawData.size() + 1 ); |
423 | KABC::VCardTool tool; | 423 | KABC::VCardTool tool; |
424 | list = tool.parseVCards( data ); | 424 | list = tool.parseVCards( data ); |
425 | KABC::Addressee::List::Iterator it; | 425 | KABC::Addressee::List::Iterator it; |
426 | for ( it = list.begin(); it != list.end(); ++it ) { | 426 | for ( it = list.begin(); it != list.end(); ++it ) { |
427 | (*it).setResource( 0 ); | 427 | (*it).setResource( 0 ); |
428 | if ( replaceLabel ) | 428 | if ( replaceLabel ) |
429 | (*it).removeVoice(); | 429 | (*it).removeVoice(); |
430 | if ( removeOld ) | 430 | if ( removeOld ) |
431 | (*it).setTagged( true ); | 431 | (*it).setTagged( true ); |
432 | insertAddressee( (*it), false, true ); | 432 | insertAddressee( (*it), false, true ); |
433 | } | 433 | } |
434 | if ( removeOld ) | 434 | if ( removeOld ) |
435 | removeUntagged(); | 435 | removeUntagged(); |
436 | } | 436 | } |
437 | void AddressBook::setUntagged() | 437 | void AddressBook::setUntagged() |
438 | { | 438 | { |
439 | Iterator ait; | 439 | Iterator ait; |
440 | for ( ait = begin(); ait != end(); ++ait ) { | 440 | for ( ait = begin(); ait != end(); ++ait ) { |
441 | (*ait).setTagged( false ); | 441 | (*ait).setTagged( false ); |
442 | } | 442 | } |
443 | } | 443 | } |
444 | void AddressBook::removeUntagged() | 444 | void AddressBook::removeUntagged() |
445 | { | 445 | { |
446 | Iterator ait; | 446 | Iterator ait; |
447 | bool todelete = false; | ||
448 | Iterator todel; | ||
447 | for ( ait = begin(); ait != end(); ++ait ) { | 449 | for ( ait = begin(); ait != end(); ++ait ) { |
448 | if (!(*ait).tagged()) | 450 | if ( todelete ) |
449 | removeAddressee( ait ); | 451 | removeAddressee( todel ); |
450 | } | 452 | if (!(*ait).tagged()) { |
451 | 453 | todelete = true; | |
454 | todel = ait; | ||
455 | } else | ||
456 | todelete = false; | ||
457 | } | ||
458 | if ( todelete ) | ||
459 | removeAddressee( todel ); | ||
452 | deleteRemovedAddressees(); | 460 | deleteRemovedAddressees(); |
453 | } | 461 | } |
454 | bool AddressBook::saveAB() | 462 | bool AddressBook::saveAB() |
455 | { | 463 | { |
456 | bool ok = true; | 464 | bool ok = true; |
457 | 465 | ||
458 | deleteRemovedAddressees(); | 466 | deleteRemovedAddressees(); |
459 | Iterator ait; | 467 | Iterator ait; |
460 | for ( ait = begin(); ait != end(); ++ait ) { | 468 | for ( ait = begin(); ait != end(); ++ait ) { |
461 | if ( !(*ait).IDStr().isEmpty() ) { | 469 | if ( !(*ait).IDStr().isEmpty() ) { |
462 | (*ait).insertCustom( "KADDRESSBOOK", "X-ExternalID", (*ait).IDStr() ); | 470 | (*ait).insertCustom( "KADDRESSBOOK", "X-ExternalID", (*ait).IDStr() ); |
463 | } | 471 | } |
464 | } | 472 | } |
465 | KRES::Manager<Resource>::ActiveIterator it; | 473 | KRES::Manager<Resource>::ActiveIterator it; |
466 | KRES::Manager<Resource> *manager = d->mManager; | 474 | KRES::Manager<Resource> *manager = d->mManager; |
467 | for ( it = manager->activeBegin(); it != manager->activeEnd(); ++it ) { | 475 | for ( it = manager->activeBegin(); it != manager->activeEnd(); ++it ) { |
468 | if ( !(*it)->readOnly() && (*it)->isOpen() ) { | 476 | if ( !(*it)->readOnly() && (*it)->isOpen() ) { |
469 | Ticket *ticket = requestSaveTicket( *it ); | 477 | Ticket *ticket = requestSaveTicket( *it ); |
470 | // qDebug("StdAddressBook::save '%s'", (*it)->resourceName().latin1() ); | 478 | // qDebug("StdAddressBook::save '%s'", (*it)->resourceName().latin1() ); |
471 | if ( !ticket ) { | 479 | if ( !ticket ) { |
472 | error( i18n( "Unable to save to resource '%1'. It is locked." ) | 480 | error( i18n( "Unable to save to resource '%1'. It is locked." ) |
473 | .arg( (*it)->resourceName() ) ); | 481 | .arg( (*it)->resourceName() ) ); |
474 | return false; | 482 | return false; |
475 | } | 483 | } |
476 | 484 | ||
477 | //if ( !save( ticket ) ) | 485 | //if ( !save( ticket ) ) |
478 | if ( ticket->resource() ) { | 486 | if ( ticket->resource() ) { |
479 | if ( ! ticket->resource()->save( ticket ) ) | 487 | if ( ! ticket->resource()->save( ticket ) ) |
480 | ok = false; | 488 | ok = false; |
481 | } else | 489 | } else |
482 | ok = false; | 490 | ok = false; |
483 | 491 | ||
484 | } | 492 | } |
485 | } | 493 | } |
486 | return ok; | 494 | return ok; |
487 | } | 495 | } |
488 | 496 | ||
489 | AddressBook::Iterator AddressBook::begin() | 497 | AddressBook::Iterator AddressBook::begin() |
490 | { | 498 | { |
491 | Iterator it = Iterator(); | 499 | Iterator it = Iterator(); |
492 | it.d->mIt = d->mAddressees.begin(); | 500 | it.d->mIt = d->mAddressees.begin(); |
493 | return it; | 501 | return it; |
494 | } | 502 | } |
495 | 503 | ||
496 | AddressBook::ConstIterator AddressBook::begin() const | 504 | AddressBook::ConstIterator AddressBook::begin() const |
497 | { | 505 | { |
498 | ConstIterator it = ConstIterator(); | 506 | ConstIterator it = ConstIterator(); |
499 | it.d->mIt = d->mAddressees.begin(); | 507 | it.d->mIt = d->mAddressees.begin(); |
500 | return it; | 508 | return it; |
501 | } | 509 | } |
502 | 510 | ||
503 | AddressBook::Iterator AddressBook::end() | 511 | AddressBook::Iterator AddressBook::end() |
504 | { | 512 | { |
505 | Iterator it = Iterator(); | 513 | Iterator it = Iterator(); |
506 | it.d->mIt = d->mAddressees.end(); | 514 | it.d->mIt = d->mAddressees.end(); |
507 | return it; | 515 | return it; |
508 | } | 516 | } |
509 | 517 | ||
510 | AddressBook::ConstIterator AddressBook::end() const | 518 | AddressBook::ConstIterator AddressBook::end() const |
511 | { | 519 | { |
512 | ConstIterator it = ConstIterator(); | 520 | ConstIterator it = ConstIterator(); |
513 | it.d->mIt = d->mAddressees.end(); | 521 | it.d->mIt = d->mAddressees.end(); |
514 | return it; | 522 | return it; |
515 | } | 523 | } |