summaryrefslogtreecommitdiffabout
path: root/kabc/addressbook.cpp
Unidiff
Diffstat (limited to 'kabc/addressbook.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r--kabc/addressbook.cpp3
1 files changed, 2 insertions, 1 deletions
diff --git a/kabc/addressbook.cpp b/kabc/addressbook.cpp
index c584c35..3641c0c 100644
--- a/kabc/addressbook.cpp
+++ b/kabc/addressbook.cpp
@@ -288,417 +288,418 @@ void AddressBook::init(const QString &config, const QString &family )
288 error( QString( "Unable to open resource '%1'!" ).arg( (*it)->resourceName() ) ); 288 error( QString( "Unable to open resource '%1'!" ).arg( (*it)->resourceName() ) );
289 } 289 }
290 Resource *res = standardResource(); 290 Resource *res = standardResource();
291 if ( !res ) { 291 if ( !res ) {
292 qDebug("ERROR: no standard resource"); 292 qDebug("ERROR: no standard resource");
293 res = manager->createResource( "file" ); 293 res = manager->createResource( "file" );
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
333AddressBook::~AddressBook() 333AddressBook::~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
341bool AddressBook::load() 341bool 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
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 ) 380void AddressBook::export2File( QString fileName )
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() && (*it).resource()->includeInSync() ) { 395 if ( (*it).resource() && (*it).resource()->includeInSync() ) {
396 if ( !(*it).IDStr().isEmpty() ) { 396 if ( !(*it).IDStr().isEmpty() ) {
397 (*it).insertCustom( "KADDRESSBOOK", "X-ExternalID", (*it).IDStr() ); 397 (*it).insertCustom( "KADDRESSBOOK", "X-ExternalID", (*it).IDStr() );
398 } 398 }
399 KABC::VCardConverter converter; 399 KABC::VCardConverter converter;
400 QString vcard; 400 QString vcard;
401 //Resource *resource() const; 401 //Resource *resource() const;
402 converter.addresseeToVCard( *it, vcard, version ); 402 converter.addresseeToVCard( *it, vcard, version );
403 t << vcard << "\r\n"; 403 t << vcard << "\r\n";
404 } 404 }
405 } 405 }
406 t << "\r\n\r\n"; 406 t << "\r\n\r\n";
407 outFile.close(); 407 outFile.close();
408} 408}
409// if QStringList uids is empty, all are exported 409// if QStringList uids is empty, all are exported
410bool AddressBook::export2PhoneFormat( QStringList uids ,QString fileName ) 410bool AddressBook::export2PhoneFormat( QStringList uids ,QString fileName )
411{ 411{
412 KABC::VCardConverter converter; 412 KABC::VCardConverter converter;
413 QString datastream; 413 QString datastream;
414 Iterator it; 414 Iterator it;
415 bool all = uids.isEmpty(); 415 bool all = uids.isEmpty();
416 for ( it = begin(); it != end(); ++it ) { 416 for ( it = begin(); it != end(); ++it ) {
417 // for( QStringList::ConstIterator it = uids.begin(); it != uids.end(); ++it ) { 417 // for( QStringList::ConstIterator it = uids.begin(); it != uids.end(); ++it ) {
418 if ( ! all ) { 418 if ( ! all ) {
419 if ( ! ( uids.contains((*it).uid() ) )) 419 if ( ! ( uids.contains((*it).uid() ) ))
420 continue; 420 continue;
421 } 421 }
422 KABC::Addressee a = ( *it ); 422 KABC::Addressee a = ( *it );
423 if ( a.isEmpty() ) 423 if ( a.isEmpty() )
424 continue; 424 continue;
425 if ( all && a.resource() && !a.resource()->includeInSync() ) 425 if ( all && a.resource() && !a.resource()->includeInSync() )
426 continue; 426 continue;
427 a.simplifyEmails(); 427 a.simplifyEmails();
428 a.simplifyPhoneNumbers(); 428 a.simplifyPhoneNumbers();
429 a.simplifyPhoneNumberTypes(); 429 a.simplifyPhoneNumberTypes();
430 a.simplifyAddresses(); 430 a.simplifyAddresses();
431 431
432 QString vcard; 432 QString vcard;
433 QString vcardnew; 433 QString vcardnew;
434 converter.addresseeToVCard( a, vcard ); 434 converter.addresseeToVCard( a, vcard );
435 int start = 0; 435 int start = 0;
436 int next; 436 int next;
437 while ( (next = vcard.find("TYPE=", start) )>= 0 ) { 437 while ( (next = vcard.find("TYPE=", start) )>= 0 ) {
438 int semi = vcard.find(";", next); 438 int semi = vcard.find(";", next);
439 int dopp = vcard.find(":", next); 439 int dopp = vcard.find(":", next);
440 int sep; 440 int sep;
441 if ( semi < dopp && semi >= 0 ) 441 if ( semi < dopp && semi >= 0 )
442 sep = semi ; 442 sep = semi ;
443 else 443 else
444 sep = dopp; 444 sep = dopp;
445 vcardnew +=vcard.mid( start, next - start); 445 vcardnew +=vcard.mid( start, next - start);
446 vcardnew +=vcard.mid( next+5,sep -next -5 ).upper(); 446 vcardnew +=vcard.mid( next+5,sep -next -5 ).upper();
447 start = sep; 447 start = sep;
448 } 448 }
449 vcardnew += vcard.mid( start,vcard.length() ); 449 vcardnew += vcard.mid( start,vcard.length() );
450 vcard = ""; 450 vcard = "";
451 start = 0; 451 start = 0;
452 while ( (next = vcardnew.find("ADR", start) )>= 0 ) { 452 while ( (next = vcardnew.find("ADR", start) )>= 0 ) {
453 int sep = vcardnew.find(":", next); 453 int sep = vcardnew.find(":", next);
454 vcard +=vcardnew.mid( start, next - start+3); 454 vcard +=vcardnew.mid( start, next - start+3);
455 start = sep; 455 start = sep;
456 } 456 }
457 vcard += vcardnew.mid( start,vcardnew.length() ); 457 vcard += vcardnew.mid( start,vcardnew.length() );
458 vcard.replace ( QRegExp(";;;") , "" ); 458 vcard.replace ( QRegExp(";;;") , "" );
459 vcard.replace ( QRegExp(";;") , "" ); 459 vcard.replace ( QRegExp(";;") , "" );
460 datastream += vcard; 460 datastream += vcard;
461 461
462 } 462 }
463 463
464 QFile outFile(fileName); 464 QFile outFile(fileName);
465 if ( outFile.open(IO_WriteOnly) ) { 465 if ( outFile.open(IO_WriteOnly) ) {
466 datastream.replace ( QRegExp("VERSION:3.0") , "VERSION:2.1" ); 466 datastream.replace ( QRegExp("VERSION:3.0") , "VERSION:2.1" );
467 QTextStream t( &outFile ); // use a text stream 467 QTextStream t( &outFile ); // use a text stream
468 t.setEncoding( QTextStream::UnicodeUTF8 ); 468 t.setEncoding( QTextStream::UnicodeUTF8 );
469 t <<datastream; 469 t <<datastream;
470 t << "\r\n\r\n"; 470 t << "\r\n\r\n";
471 outFile.close(); 471 outFile.close();
472 472
473 } else { 473 } else {
474 qDebug("Error open temp file "); 474 qDebug("Error open temp file ");
475 return false; 475 return false;
476 } 476 }
477 return true; 477 return true;
478 478
479} 479}
480void AddressBook::importFromFile( QString fileName, bool replaceLabel, bool removeOld ) 480int AddressBook::importFromFile( QString fileName, bool replaceLabel, bool removeOld )
481{ 481{
482 482
483 if ( removeOld ) 483 if ( removeOld )
484 setUntagged( true ); 484 setUntagged( true );
485 KABC::Addressee::List list; 485 KABC::Addressee::List list;
486 QFile file( fileName ); 486 QFile file( fileName );
487 file.open( IO_ReadOnly ); 487 file.open( IO_ReadOnly );
488 QByteArray rawData = file.readAll(); 488 QByteArray rawData = file.readAll();
489 file.close(); 489 file.close();
490 QString data; 490 QString data;
491 if ( replaceLabel ) { 491 if ( replaceLabel ) {
492 data = QString::fromLatin1( rawData.data(), rawData.size() + 1 ); 492 data = QString::fromLatin1( rawData.data(), rawData.size() + 1 );
493 data.replace ( QRegExp("LABEL") , "ADR" ); 493 data.replace ( QRegExp("LABEL") , "ADR" );
494 data.replace ( QRegExp("CHARSET=ISO-8859-1") , "" ); 494 data.replace ( QRegExp("CHARSET=ISO-8859-1") , "" );
495 } else 495 } else
496 data = QString::fromUtf8( rawData.data(), rawData.size() + 1 ); 496 data = QString::fromUtf8( rawData.data(), rawData.size() + 1 );
497 KABC::VCardTool tool; 497 KABC::VCardTool tool;
498 list = tool.parseVCards( data ); 498 list = tool.parseVCards( data );
499 KABC::Addressee::List::Iterator it; 499 KABC::Addressee::List::Iterator it;
500 for ( it = list.begin(); it != list.end(); ++it ) { 500 for ( it = list.begin(); it != list.end(); ++it ) {
501 QString id = (*it).custom( "KADDRESSBOOK", "X-ExternalID" ); 501 QString id = (*it).custom( "KADDRESSBOOK", "X-ExternalID" );
502 if ( !id.isEmpty() ) 502 if ( !id.isEmpty() )
503 (*it).setIDStr(id ); 503 (*it).setIDStr(id );
504 (*it).setResource( 0 ); 504 (*it).setResource( 0 );
505 if ( replaceLabel ) 505 if ( replaceLabel )
506 (*it).removeVoice(); 506 (*it).removeVoice();
507 if ( removeOld ) 507 if ( removeOld )
508 (*it).setTagged( true ); 508 (*it).setTagged( true );
509 insertAddressee( (*it), false, true ); 509 insertAddressee( (*it), false, true );
510 } 510 }
511 if ( removeOld ) 511 if ( removeOld )
512 removeUntagged(); 512 removeUntagged();
513 return list.count();
513} 514}
514void AddressBook::setUntagged(bool setNonSyncTagged) // = false) 515void AddressBook::setUntagged(bool setNonSyncTagged) // = false)
515{ 516{
516 Iterator ait; 517 Iterator ait;
517 for ( ait = begin(); ait != end(); ++ait ) { 518 for ( ait = begin(); ait != end(); ++ait ) {
518 if ( setNonSyncTagged ) { 519 if ( setNonSyncTagged ) {
519 if ( (*ait).resource() && ! (*ait).resource()->includeInSync() ) { 520 if ( (*ait).resource() && ! (*ait).resource()->includeInSync() ) {
520 (*ait).setTagged( true ); 521 (*ait).setTagged( true );
521 } else 522 } else
522 (*ait).setTagged( false ); 523 (*ait).setTagged( false );
523 } else 524 } else
524 (*ait).setTagged( false ); 525 (*ait).setTagged( false );
525 } 526 }
526} 527}
527void AddressBook::removeUntagged() 528void AddressBook::removeUntagged()
528{ 529{
529 Iterator ait; 530 Iterator ait;
530 bool todelete = false; 531 bool todelete = false;
531 Iterator todel; 532 Iterator todel;
532 for ( ait = begin(); ait != end(); ++ait ) { 533 for ( ait = begin(); ait != end(); ++ait ) {
533 if ( todelete ) 534 if ( todelete )
534 removeAddressee( todel ); 535 removeAddressee( todel );
535 if (!(*ait).tagged()) { 536 if (!(*ait).tagged()) {
536 todelete = true; 537 todelete = true;
537 todel = ait; 538 todel = ait;
538 } else 539 } else
539 todelete = false; 540 todelete = false;
540 } 541 }
541 if ( todelete ) 542 if ( todelete )
542 removeAddressee( todel ); 543 removeAddressee( todel );
543 deleteRemovedAddressees(); 544 deleteRemovedAddressees();
544} 545}
545void AddressBook::smplifyAddressees() 546void AddressBook::smplifyAddressees()
546{ 547{
547 Iterator ait; 548 Iterator ait;
548 for ( ait = begin(); ait != end(); ++ait ) { 549 for ( ait = begin(); ait != end(); ++ait ) {
549 (*ait).simplifyEmails(); 550 (*ait).simplifyEmails();
550 (*ait).simplifyPhoneNumbers(); 551 (*ait).simplifyPhoneNumbers();
551 (*ait).simplifyPhoneNumberTypes(); 552 (*ait).simplifyPhoneNumberTypes();
552 (*ait).simplifyAddresses(); 553 (*ait).simplifyAddresses();
553 } 554 }
554} 555}
555void AddressBook::preparePhoneSync( QString currentSyncDevice, bool isPreSync ) 556void AddressBook::preparePhoneSync( QString currentSyncDevice, bool isPreSync )
556{ 557{
557 Iterator ait; 558 Iterator ait;
558 for ( ait = begin(); ait != end(); ++ait ) { 559 for ( ait = begin(); ait != end(); ++ait ) {
559 QString id = (*ait).IDStr(); 560 QString id = (*ait).IDStr();
560 (*ait).setIDStr( ":"); 561 (*ait).setIDStr( ":");
561 (*ait).setExternalUID( id ); 562 (*ait).setExternalUID( id );
562 (*ait).setOriginalExternalUID( id ); 563 (*ait).setOriginalExternalUID( id );
563 if ( isPreSync ) 564 if ( isPreSync )
564 (*ait).setTempSyncStat( SYNC_TEMPSTATE_NEW_EXTERNAL ); 565 (*ait).setTempSyncStat( SYNC_TEMPSTATE_NEW_EXTERNAL );
565 else { 566 else {
566 (*ait).setTempSyncStat( SYNC_TEMPSTATE_NEW_ID ); 567 (*ait).setTempSyncStat( SYNC_TEMPSTATE_NEW_ID );
567 (*ait).setID( currentSyncDevice,id ); 568 (*ait).setID( currentSyncDevice,id );
568 569
569 } 570 }
570 } 571 }
571} 572}
572void AddressBook::findNewExtIds( QString fileName, QString currentSyncDevice ) 573void AddressBook::findNewExtIds( QString fileName, QString currentSyncDevice )
573{ 574{
574 575
575 setUntagged(); 576 setUntagged();
576 KABC::Addressee::List list; 577 KABC::Addressee::List list;
577 QFile file( fileName ); 578 QFile file( fileName );
578 file.open( IO_ReadOnly ); 579 file.open( IO_ReadOnly );
579 QByteArray rawData = file.readAll(); 580 QByteArray rawData = file.readAll();
580 file.close(); 581 file.close();
581 QString data; 582 QString data;
582 583
583 data = QString::fromUtf8( rawData.data(), rawData.size() + 1 ); 584 data = QString::fromUtf8( rawData.data(), rawData.size() + 1 );
584 KABC::VCardTool tool; 585 KABC::VCardTool tool;
585 list = tool.parseVCards( data ); 586 list = tool.parseVCards( data );
586 KABC::Addressee::List::Iterator it; 587 KABC::Addressee::List::Iterator it;
587 for ( it = list.begin(); it != list.end(); ++it ) { 588 for ( it = list.begin(); it != list.end(); ++it ) {
588 Iterator ait; 589 Iterator ait;
589 for ( ait = begin(); ait != end(); ++ait ) { 590 for ( ait = begin(); ait != end(); ++ait ) {
590 if ( !(*ait).tagged() ) { 591 if ( !(*ait).tagged() ) {
591 if ( (*ait).containsAdr(*it)) { 592 if ( (*ait).containsAdr(*it)) {
592 (*ait).setTagged(true); 593 (*ait).setTagged(true);
593 QString id = (*it).custom( "KADDRESSBOOK", "X-ExternalID" ); 594 QString id = (*it).custom( "KADDRESSBOOK", "X-ExternalID" );
594 (*it).setIDStr( ":"); 595 (*it).setIDStr( ":");
595 (*it).setID( currentSyncDevice,id ); 596 (*it).setID( currentSyncDevice,id );
596 (*it).setExternalUID( id ); 597 (*it).setExternalUID( id );
597 (*it).setTempSyncStat( SYNC_TEMPSTATE_NEW_ID ); 598 (*it).setTempSyncStat( SYNC_TEMPSTATE_NEW_ID );
598 (*it).setUid( ( (*ait).uid() )); 599 (*it).setUid( ( (*ait).uid() ));
599 break; 600 break;
600 } 601 }
601 } 602 }
602 603
603 } 604 }
604 if ( ait == end() ) 605 if ( ait == end() )
605 qDebug("ERROR:: no ext ID found for uid: %s", (*it).uid().latin1()); 606 qDebug("ERROR:: no ext ID found for uid: %s", (*it).uid().latin1());
606 } 607 }
607 clear(); 608 clear();
608 for ( it = list.begin(); it != list.end(); ++it ) { 609 for ( it = list.begin(); it != list.end(); ++it ) {
609 insertAddressee( (*it) ); 610 insertAddressee( (*it) );
610 } 611 }
611} 612}
612 613
613bool AddressBook::saveABphone( QString fileName ) 614bool AddressBook::saveABphone( QString fileName )
614{ 615{
615 //smplifyAddressees(); 616 //smplifyAddressees();
616 qDebug("saveABphone:: saving AB... "); 617 qDebug("saveABphone:: saving AB... ");
617 if ( ! export2PhoneFormat( QStringList() ,fileName ) ) 618 if ( ! export2PhoneFormat( QStringList() ,fileName ) )
618 return false; 619 return false;
619 qDebug("saveABphone:: writing to phone... "); 620 qDebug("saveABphone:: writing to phone... ");
620 if ( !PhoneAccess::writeToPhone( fileName) ) { 621 if ( !PhoneAccess::writeToPhone( fileName) ) {
621 return false; 622 return false;
622 } 623 }
623 qDebug("saveABphone:: re-reading from phone... "); 624 qDebug("saveABphone:: re-reading from phone... ");
624 if ( !PhoneAccess::readFromPhone( fileName) ) { 625 if ( !PhoneAccess::readFromPhone( fileName) ) {
625 return false; 626 return false;
626 } 627 }
627 return true; 628 return true;
628} 629}
629bool AddressBook::saveAB() 630bool AddressBook::saveAB()
630{ 631{
631 bool ok = true; 632 bool ok = true;
632 633
633 deleteRemovedAddressees(); 634 deleteRemovedAddressees();
634 Iterator ait; 635 Iterator ait;
635 for ( ait = begin(); ait != end(); ++ait ) { 636 for ( ait = begin(); ait != end(); ++ait ) {
636 if ( !(*ait).IDStr().isEmpty() ) { 637 if ( !(*ait).IDStr().isEmpty() ) {
637 (*ait).insertCustom( "KADDRESSBOOK", "X-ExternalID", (*ait).IDStr() ); 638 (*ait).insertCustom( "KADDRESSBOOK", "X-ExternalID", (*ait).IDStr() );
638 } 639 }
639 } 640 }
640 KRES::Manager<Resource>::ActiveIterator it; 641 KRES::Manager<Resource>::ActiveIterator it;
641 KRES::Manager<Resource> *manager = d->mManager; 642 KRES::Manager<Resource> *manager = d->mManager;
642 qDebug("SaveAB::saving..." ); 643 qDebug("SaveAB::saving..." );
643 for ( it = manager->activeBegin(); it != manager->activeEnd(); ++it ) { 644 for ( it = manager->activeBegin(); it != manager->activeEnd(); ++it ) {
644 qDebug("SaveAB::checking resource..." ); 645 qDebug("SaveAB::checking resource..." );
645 if ( (*it)->readOnly() ) 646 if ( (*it)->readOnly() )
646 qDebug("resource is readonly." ); 647 qDebug("resource is readonly." );
647 if ( (*it)->isOpen() ) 648 if ( (*it)->isOpen() )
648 qDebug("resource is open" ); 649 qDebug("resource is open" );
649 650
650 if ( !(*it)->readOnly() && (*it)->isOpen() ) { 651 if ( !(*it)->readOnly() && (*it)->isOpen() ) {
651 Ticket *ticket = requestSaveTicket( *it ); 652 Ticket *ticket = requestSaveTicket( *it );
652 qDebug("StdAddressBook::save '%s'", (*it)->resourceName().latin1() ); 653 qDebug("StdAddressBook::save '%s'", (*it)->resourceName().latin1() );
653 if ( !ticket ) { 654 if ( !ticket ) {
654 qDebug( i18n( "Unable to save to resource '%1'. It is locked." ) 655 qDebug( i18n( "Unable to save to resource '%1'. It is locked." )
655 .arg( (*it)->resourceName() ) ); 656 .arg( (*it)->resourceName() ) );
656 return false; 657 return false;
657 } 658 }
658 659
659 //if ( !save( ticket ) ) 660 //if ( !save( ticket ) )
660 if ( ticket->resource() ) { 661 if ( ticket->resource() ) {
661 QString name = ticket->resource()->resourceName(); 662 QString name = ticket->resource()->resourceName();
662 if ( ! ticket->resource()->save( ticket ) ) 663 if ( ! ticket->resource()->save( ticket ) )
663 ok = false; 664 ok = false;
664 else 665 else
665 qDebug("StdAddressBook::resource saved '%s'", name.latin1() ); 666 qDebug("StdAddressBook::resource saved '%s'", name.latin1() );
666 667
667 } else 668 } else
668 ok = false; 669 ok = false;
669 670
670 } 671 }
671 } 672 }
672 return ok; 673 return ok;
673} 674}
674 675
675AddressBook::Iterator AddressBook::begin() 676AddressBook::Iterator AddressBook::begin()
676{ 677{
677 Iterator it = Iterator(); 678 Iterator it = Iterator();
678 it.d->mIt = d->mAddressees.begin(); 679 it.d->mIt = d->mAddressees.begin();
679 return it; 680 return it;
680} 681}
681 682
682AddressBook::ConstIterator AddressBook::begin() const 683AddressBook::ConstIterator AddressBook::begin() const
683{ 684{
684 ConstIterator it = ConstIterator(); 685 ConstIterator it = ConstIterator();
685 it.d->mIt = d->mAddressees.begin(); 686 it.d->mIt = d->mAddressees.begin();
686 return it; 687 return it;
687} 688}
688 689
689AddressBook::Iterator AddressBook::end() 690AddressBook::Iterator AddressBook::end()
690{ 691{
691 Iterator it = Iterator(); 692 Iterator it = Iterator();
692 it.d->mIt = d->mAddressees.end(); 693 it.d->mIt = d->mAddressees.end();
693 return it; 694 return it;
694} 695}
695 696
696AddressBook::ConstIterator AddressBook::end() const 697AddressBook::ConstIterator AddressBook::end() const
697{ 698{
698 ConstIterator it = ConstIterator(); 699 ConstIterator it = ConstIterator();
699 it.d->mIt = d->mAddressees.end(); 700 it.d->mIt = d->mAddressees.end();
700 return it; 701 return it;
701} 702}
702 703
703void AddressBook::clear() 704void AddressBook::clear()
704{ 705{