summaryrefslogtreecommitdiffabout
path: root/kabc
Unidiff
Diffstat (limited to 'kabc') (more/less context) (ignore whitespace changes)
-rw-r--r--kabc/addressbook.cpp6
1 files changed, 3 insertions, 3 deletions
diff --git a/kabc/addressbook.cpp b/kabc/addressbook.cpp
index bdc2762..ed3ac84 100644
--- a/kabc/addressbook.cpp
+++ b/kabc/addressbook.cpp
@@ -366,65 +366,65 @@ bool AddressBook::load()
366} 366}
367 367
368bool AddressBook::save( Ticket *ticket ) 368bool 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
380void AddressBook::export2File( QString fileName, QString resourceName ) 380void 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()->resourceName() );
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
416bool AddressBook::export2PhoneFormat( QStringList uids ,QString fileName ) 416bool 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;
@@ -481,92 +481,92 @@ bool AddressBook::export2PhoneFormat( QStringList uids ,QString fileName )
481 return false; 481 return false;
482 } 482 }
483 return true; 483 return true;
484 484
485} 485}
486int AddressBook::importFromFile( QString fileName, bool replaceLabel, bool removeOld, QString resource ) 486int AddressBook::importFromFile( QString fileName, bool replaceLabel, bool removeOld, QString resource )
487{ 487{
488 488
489 if ( removeOld ) 489 if ( removeOld )
490 setUntagged( true, resource ); 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 506
507 Resource * setRes = 0; 507 Resource * setRes = 0;
508 if ( !resource.isEmpty() ) { 508 if ( !resource.isEmpty() ) {
509 KRES::Manager<Resource>::ActiveIterator it; 509 KRES::Manager<Resource>::ActiveIterator it;
510 KRES::Manager<Resource> *manager = d->mManager; 510 KRES::Manager<Resource> *manager = d->mManager;
511 for ( it = manager->activeBegin(); it != manager->activeEnd(); ++it ) { 511 for ( it = manager->activeBegin(); it != manager->activeEnd(); ++it ) {
512 qDebug("SaveAB::checking resource..." ); 512 qDebug("SaveAB::checking resource..." );
513 if ( (*it)->name() == resource ) { 513 if ( (*it)->resourceName() == resource ) {
514 setRes = (*it); 514 setRes = (*it);
515 qDebug("Inserting imported contacs to resource %s", resource.latin1()); 515 qDebug("Inserting imported contacs to resource %s", resource.latin1());
516 break; 516 break;
517 } 517 }
518 } 518 }
519 } 519 }
520 for ( it = list.begin(); it != list.end(); ++it ) { 520 for ( it = list.begin(); it != list.end(); ++it ) {
521 QString id = (*it).custom( "KADDRESSBOOK", "X-ExternalID" ); 521 QString id = (*it).custom( "KADDRESSBOOK", "X-ExternalID" );
522 if ( !id.isEmpty() ) 522 if ( !id.isEmpty() )
523 (*it).setIDStr(id ); 523 (*it).setIDStr(id );
524 (*it).setResource( setRes ); 524 (*it).setResource( setRes );
525 if ( replaceLabel ) 525 if ( replaceLabel )
526 (*it).removeVoice(); 526 (*it).removeVoice();
527 if ( removeOld ) 527 if ( removeOld )
528 (*it).setTagged( true ); 528 (*it).setTagged( true );
529 insertAddressee( (*it), false, true ); 529 insertAddressee( (*it), false, true );
530 } 530 }
531 if ( removeOld ) 531 if ( removeOld )
532 removeUntagged(); 532 removeUntagged();
533 return list.count(); 533 return list.count();
534} 534}
535void AddressBook::setUntagged(bool setNonSyncTagged, QString resource) // = false , "") 535void AddressBook::setUntagged(bool setNonSyncTagged, QString resource) // = false , "")
536{ 536{
537 Iterator ait; 537 Iterator ait;
538 if ( !resource.isEmpty() ) { 538 if ( !resource.isEmpty() ) {
539 for ( ait = begin(); ait != end(); ++ait ) { 539 for ( ait = begin(); ait != end(); ++ait ) {
540 if ( (*ait).resource() && (*ait).resource()->name() == resource ) { 540 if ( (*ait).resource() && (*ait).resource()->resourceName() == resource ) {
541 (*ait).setTagged( false ); 541 (*ait).setTagged( false );
542 } 542 }
543 else 543 else
544 (*ait).setTagged( true ); 544 (*ait).setTagged( true );
545 } 545 }
546 } else { 546 } else {
547 for ( ait = begin(); ait != end(); ++ait ) { 547 for ( ait = begin(); ait != end(); ++ait ) {
548 if ( setNonSyncTagged ) { 548 if ( setNonSyncTagged ) {
549 if ( (*ait).resource() && ! (*ait).resource()->includeInSync() ) { 549 if ( (*ait).resource() && ! (*ait).resource()->includeInSync() ) {
550 (*ait).setTagged( true ); 550 (*ait).setTagged( true );
551 } else 551 } else
552 (*ait).setTagged( false ); 552 (*ait).setTagged( false );
553 } else 553 } else
554 (*ait).setTagged( false ); 554 (*ait).setTagged( false );
555 } 555 }
556 } 556 }
557} 557}
558void AddressBook::removeUntagged() 558void AddressBook::removeUntagged()
559{ 559{
560 Iterator ait; 560 Iterator ait;
561 bool todelete = false; 561 bool todelete = false;
562 Iterator todel; 562 Iterator todel;
563 for ( ait = begin(); ait != end(); ++ait ) { 563 for ( ait = begin(); ait != end(); ++ait ) {
564 if ( todelete ) 564 if ( todelete )
565 removeAddressee( todel ); 565 removeAddressee( todel );
566 if (!(*ait).tagged()) { 566 if (!(*ait).tagged()) {
567 todelete = true; 567 todelete = true;
568 todel = ait; 568 todel = ait;
569 } else 569 } else
570 todelete = false; 570 todelete = false;
571 } 571 }
572 if ( todelete ) 572 if ( todelete )