-rw-r--r-- | kabc/addressbook.cpp | 35 |
1 files changed, 23 insertions, 12 deletions
diff --git a/kabc/addressbook.cpp b/kabc/addressbook.cpp index 8882259..592d78d 100644 --- a/kabc/addressbook.cpp +++ b/kabc/addressbook.cpp | |||
@@ -363,75 +363,80 @@ bool AddressBook::load() | |||
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 | void AddressBook::export2File( QString fileName ) | 380 | void AddressBook::export2File( QString fileName ) |
380 | { | 381 | { |
381 | 382 | ||
382 | QFile outFile( fileName ); | 383 | QFile outFile( fileName ); |
383 | if ( !outFile.open( IO_WriteOnly ) ) { | 384 | if ( !outFile.open( IO_WriteOnly ) ) { |
384 | 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>" ); |
385 | KMessageBox::error( 0, text.arg( fileName ) ); | 386 | KMessageBox::error( 0, text.arg( fileName ) ); |
386 | return ; | 387 | return ; |
387 | } | 388 | } |
388 | QTextStream t( &outFile ); | 389 | QTextStream t( &outFile ); |
389 | t.setEncoding( QTextStream::UnicodeUTF8 ); | 390 | t.setEncoding( QTextStream::UnicodeUTF8 ); |
390 | Iterator it; | 391 | Iterator it; |
391 | KABC::VCardConverter::Version version; | 392 | KABC::VCardConverter::Version version; |
392 | version = KABC::VCardConverter::v3_0; | 393 | version = KABC::VCardConverter::v3_0; |
393 | for ( it = begin(); it != end(); ++it ) { | 394 | for ( it = begin(); it != end(); ++it ) { |
394 | if ( !(*it).IDStr().isEmpty() ) { | 395 | if ( (*it).resource() && (*it).resource()->includeInSync() ) { |
395 | (*it).insertCustom( "KADDRESSBOOK", "X-ExternalID", (*it).IDStr() ); | 396 | if ( !(*it).IDStr().isEmpty() ) { |
397 | (*it).insertCustom( "KADDRESSBOOK", "X-ExternalID", (*it).IDStr() ); | ||
398 | } | ||
399 | KABC::VCardConverter converter; | ||
400 | QString vcard; | ||
401 | //Resource *resource() const; | ||
402 | converter.addresseeToVCard( *it, vcard, version ); | ||
403 | t << vcard << "\r\n"; | ||
396 | } | 404 | } |
397 | KABC::VCardConverter converter; | ||
398 | QString vcard; | ||
399 | //Resource *resource() const; | ||
400 | converter.addresseeToVCard( *it, vcard, version ); | ||
401 | t << vcard << "\r\n"; | ||
402 | } | 405 | } |
403 | t << "\r\n\r\n"; | 406 | t << "\r\n\r\n"; |
404 | outFile.close(); | 407 | outFile.close(); |
405 | } | 408 | } |
406 | // if QStringList uids is empty, all are exported | 409 | // if QStringList uids is empty, all are exported |
407 | bool AddressBook::export2PhoneFormat( QStringList uids ,QString fileName ) | 410 | bool AddressBook::export2PhoneFormat( QStringList uids ,QString fileName ) |
408 | { | 411 | { |
409 | KABC::VCardConverter converter; | 412 | KABC::VCardConverter converter; |
410 | QString datastream; | 413 | QString datastream; |
411 | Iterator it; | 414 | Iterator it; |
412 | bool all = uids.isEmpty(); | 415 | bool all = uids.isEmpty(); |
413 | for ( it = begin(); it != end(); ++it ) { | 416 | for ( it = begin(); it != end(); ++it ) { |
414 | // for( QStringList::ConstIterator it = uids.begin(); it != uids.end(); ++it ) { | 417 | // for( QStringList::ConstIterator it = uids.begin(); it != uids.end(); ++it ) { |
415 | if ( ! all ) { | 418 | if ( ! all ) { |
416 | if ( ! ( uids.contains((*it).uid() ) )) | 419 | if ( ! ( uids.contains((*it).uid() ) )) |
417 | continue; | 420 | continue; |
418 | } | 421 | } |
419 | KABC::Addressee a = ( *it ); | 422 | KABC::Addressee a = ( *it ); |
420 | if ( a.isEmpty() ) | 423 | if ( a.isEmpty() ) |
421 | continue; | 424 | continue; |
425 | if ( all && a.resource() && !a.resource()->includeInSync() ) | ||
426 | continue; | ||
422 | a.simplifyEmails(); | 427 | a.simplifyEmails(); |
423 | a.simplifyPhoneNumbers(); | 428 | a.simplifyPhoneNumbers(); |
424 | a.simplifyPhoneNumberTypes(); | 429 | a.simplifyPhoneNumberTypes(); |
425 | a.simplifyAddresses(); | 430 | a.simplifyAddresses(); |
426 | 431 | ||
427 | QString vcard; | 432 | QString vcard; |
428 | QString vcardnew; | 433 | QString vcardnew; |
429 | converter.addresseeToVCard( a, vcard ); | 434 | converter.addresseeToVCard( a, vcard ); |
430 | int start = 0; | 435 | int start = 0; |
431 | int next; | 436 | int next; |
432 | while ( (next = vcard.find("TYPE=", start) )>= 0 ) { | 437 | while ( (next = vcard.find("TYPE=", start) )>= 0 ) { |
433 | int semi = vcard.find(";", next); | 438 | int semi = vcard.find(";", next); |
434 | int dopp = vcard.find(":", next); | 439 | int dopp = vcard.find(":", next); |
435 | int sep; | 440 | int sep; |
436 | if ( semi < dopp && semi >= 0 ) | 441 | if ( semi < dopp && semi >= 0 ) |
437 | sep = semi ; | 442 | sep = semi ; |
@@ -463,67 +468,73 @@ bool AddressBook::export2PhoneFormat( QStringList uids ,QString fileName ) | |||
463 | t.setEncoding( QTextStream::UnicodeUTF8 ); | 468 | t.setEncoding( QTextStream::UnicodeUTF8 ); |
464 | t <<datastream; | 469 | t <<datastream; |
465 | t << "\r\n\r\n"; | 470 | t << "\r\n\r\n"; |
466 | outFile.close(); | 471 | outFile.close(); |
467 | 472 | ||
468 | } else { | 473 | } else { |
469 | qDebug("Error open temp file "); | 474 | qDebug("Error open temp file "); |
470 | return false; | 475 | return false; |
471 | } | 476 | } |
472 | return true; | 477 | return true; |
473 | 478 | ||
474 | } | 479 | } |
475 | void AddressBook::importFromFile( QString fileName, bool replaceLabel, bool removeOld ) | 480 | void AddressBook::importFromFile( QString fileName, bool replaceLabel, bool removeOld ) |
476 | { | 481 | { |
477 | 482 | ||
478 | if ( removeOld ) | 483 | if ( removeOld ) |
479 | setUntagged(); | 484 | setUntagged( true ); |
480 | KABC::Addressee::List list; | 485 | KABC::Addressee::List list; |
481 | QFile file( fileName ); | 486 | QFile file( fileName ); |
482 | file.open( IO_ReadOnly ); | 487 | file.open( IO_ReadOnly ); |
483 | QByteArray rawData = file.readAll(); | 488 | QByteArray rawData = file.readAll(); |
484 | file.close(); | 489 | file.close(); |
485 | QString data; | 490 | QString data; |
486 | if ( replaceLabel ) { | 491 | if ( replaceLabel ) { |
487 | data = QString::fromLatin1( rawData.data(), rawData.size() + 1 ); | 492 | data = QString::fromLatin1( rawData.data(), rawData.size() + 1 ); |
488 | data.replace ( QRegExp("LABEL") , "ADR" ); | 493 | data.replace ( QRegExp("LABEL") , "ADR" ); |
489 | data.replace ( QRegExp("CHARSET=ISO-8859-1") , "" ); | 494 | data.replace ( QRegExp("CHARSET=ISO-8859-1") , "" ); |
490 | } else | 495 | } else |
491 | data = QString::fromUtf8( rawData.data(), rawData.size() + 1 ); | 496 | data = QString::fromUtf8( rawData.data(), rawData.size() + 1 ); |
492 | KABC::VCardTool tool; | 497 | KABC::VCardTool tool; |
493 | list = tool.parseVCards( data ); | 498 | list = tool.parseVCards( data ); |
494 | KABC::Addressee::List::Iterator it; | 499 | KABC::Addressee::List::Iterator it; |
495 | for ( it = list.begin(); it != list.end(); ++it ) { | 500 | for ( it = list.begin(); it != list.end(); ++it ) { |
496 | QString id = (*it).custom( "KADDRESSBOOK", "X-ExternalID" ); | 501 | QString id = (*it).custom( "KADDRESSBOOK", "X-ExternalID" ); |
497 | if ( !id.isEmpty() ) | 502 | if ( !id.isEmpty() ) |
498 | (*it).setIDStr(id ); | 503 | (*it).setIDStr(id ); |
499 | (*it).setResource( 0 ); | 504 | (*it).setResource( 0 ); |
500 | if ( replaceLabel ) | 505 | if ( replaceLabel ) |
501 | (*it).removeVoice(); | 506 | (*it).removeVoice(); |
502 | if ( removeOld ) | 507 | if ( removeOld ) |
503 | (*it).setTagged( true ); | 508 | (*it).setTagged( true ); |
504 | insertAddressee( (*it), false, true ); | 509 | insertAddressee( (*it), false, true ); |
505 | } | 510 | } |
506 | if ( removeOld ) | 511 | if ( removeOld ) |
507 | removeUntagged(); | 512 | removeUntagged(); |
508 | } | 513 | } |
509 | void AddressBook::setUntagged() | 514 | void AddressBook::setUntagged(bool setNonSyncTagged) // = false) |
510 | { | 515 | { |
511 | Iterator ait; | 516 | Iterator ait; |
512 | for ( ait = begin(); ait != end(); ++ait ) { | 517 | for ( ait = begin(); ait != end(); ++ait ) { |
513 | (*ait).setTagged( false ); | 518 | if ( setNonSyncTagged ) { |
519 | if ( (*ait).resource() && ! (*ait).resource()->includeInSync() ) { | ||
520 | (*ait).setTagged( true ); | ||
521 | } else | ||
522 | (*ait).setTagged( false ); | ||
523 | } else | ||
524 | (*ait).setTagged( false ); | ||
514 | } | 525 | } |
515 | } | 526 | } |
516 | void AddressBook::removeUntagged() | 527 | void AddressBook::removeUntagged() |
517 | { | 528 | { |
518 | Iterator ait; | 529 | Iterator ait; |
519 | bool todelete = false; | 530 | bool todelete = false; |
520 | Iterator todel; | 531 | Iterator todel; |
521 | for ( ait = begin(); ait != end(); ++ait ) { | 532 | for ( ait = begin(); ait != end(); ++ait ) { |
522 | if ( todelete ) | 533 | if ( todelete ) |
523 | removeAddressee( todel ); | 534 | removeAddressee( todel ); |
524 | if (!(*ait).tagged()) { | 535 | if (!(*ait).tagged()) { |
525 | todelete = true; | 536 | todelete = true; |
526 | todel = ait; | 537 | todel = ait; |
527 | } else | 538 | } else |
528 | todelete = false; | 539 | todelete = false; |
529 | } | 540 | } |