-rw-r--r-- | kabc/addressbook.cpp | 21 |
1 files changed, 21 insertions, 0 deletions
diff --git a/kabc/addressbook.cpp b/kabc/addressbook.cpp index 2785131..df0fba4 100644 --- a/kabc/addressbook.cpp +++ b/kabc/addressbook.cpp | |||
@@ -305,512 +305,533 @@ void AddressBook::init(const QString &config, const QString &family ) | |||
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 ) | 380 | void 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 |
410 | bool AddressBook::export2PhoneFormat( QStringList uids ,QString fileName ) | 410 | bool 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 | } |
480 | int AddressBook::importFromFile( QString fileName, bool replaceLabel, bool removeOld ) | 480 | int 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 | return list.count(); |
514 | } | 514 | } |
515 | void AddressBook::setUntagged(bool setNonSyncTagged) // = false) | 515 | void AddressBook::setUntagged(bool setNonSyncTagged) // = false) |
516 | { | 516 | { |
517 | Iterator ait; | 517 | Iterator ait; |
518 | for ( ait = begin(); ait != end(); ++ait ) { | 518 | for ( ait = begin(); ait != end(); ++ait ) { |
519 | if ( setNonSyncTagged ) { | 519 | if ( setNonSyncTagged ) { |
520 | if ( (*ait).resource() && ! (*ait).resource()->includeInSync() ) { | 520 | if ( (*ait).resource() && ! (*ait).resource()->includeInSync() ) { |
521 | (*ait).setTagged( true ); | 521 | (*ait).setTagged( true ); |
522 | } else | 522 | } else |
523 | (*ait).setTagged( false ); | 523 | (*ait).setTagged( false ); |
524 | } else | 524 | } else |
525 | (*ait).setTagged( false ); | 525 | (*ait).setTagged( false ); |
526 | } | 526 | } |
527 | } | 527 | } |
528 | void AddressBook::removeUntagged() | 528 | void AddressBook::removeUntagged() |
529 | { | 529 | { |
530 | Iterator ait; | 530 | Iterator ait; |
531 | bool todelete = false; | 531 | bool todelete = false; |
532 | Iterator todel; | 532 | Iterator todel; |
533 | for ( ait = begin(); ait != end(); ++ait ) { | 533 | for ( ait = begin(); ait != end(); ++ait ) { |
534 | if ( todelete ) | 534 | if ( todelete ) |
535 | removeAddressee( todel ); | 535 | removeAddressee( todel ); |
536 | if (!(*ait).tagged()) { | 536 | if (!(*ait).tagged()) { |
537 | todelete = true; | 537 | todelete = true; |
538 | todel = ait; | 538 | todel = ait; |
539 | } else | 539 | } else |
540 | todelete = false; | 540 | todelete = false; |
541 | } | 541 | } |
542 | if ( todelete ) | 542 | if ( todelete ) |
543 | removeAddressee( todel ); | 543 | removeAddressee( todel ); |
544 | deleteRemovedAddressees(); | 544 | deleteRemovedAddressees(); |
545 | } | 545 | } |
546 | void AddressBook::smplifyAddressees() | 546 | void AddressBook::smplifyAddressees() |
547 | { | 547 | { |
548 | Iterator ait; | 548 | Iterator ait; |
549 | for ( ait = begin(); ait != end(); ++ait ) { | 549 | for ( ait = begin(); ait != end(); ++ait ) { |
550 | (*ait).simplifyEmails(); | 550 | (*ait).simplifyEmails(); |
551 | (*ait).simplifyPhoneNumbers(); | 551 | (*ait).simplifyPhoneNumbers(); |
552 | (*ait).simplifyPhoneNumberTypes(); | 552 | (*ait).simplifyPhoneNumberTypes(); |
553 | (*ait).simplifyAddresses(); | 553 | (*ait).simplifyAddresses(); |
554 | } | 554 | } |
555 | } | 555 | } |
556 | void AddressBook::removeSyncInfo( QString syncProfile) | 556 | void AddressBook::removeSyncInfo( QString syncProfile) |
557 | { | 557 | { |
558 | Iterator ait; | 558 | Iterator ait; |
559 | for ( ait = begin(); ait != end(); ++ait ) { | 559 | for ( ait = begin(); ait != end(); ++ait ) { |
560 | (*ait).removeID( syncProfile ); | 560 | (*ait).removeID( syncProfile ); |
561 | } | ||
562 | if ( syncProfile.isEmpty() ) { | ||
563 | Iterator it = begin(); | ||
564 | Iterator it2 ; | ||
565 | QDateTime dt ( QDate( 2004,1,1) ); | ||
566 | while ( it != end() ) { | ||
567 | if ( (*it).uid().left( 19 ) == QString("last-syncAddressee-") ) { | ||
568 | it2 = it; | ||
569 | //qDebug("removing %s ",(*it).uid().latin1() ); | ||
570 | ++it; | ||
571 | removeAddressee( it2 ); | ||
572 | } else { | ||
573 | //qDebug("skipping %s ",(*it).uid().latin1() ); | ||
574 | ++it; | ||
575 | } | ||
576 | } | ||
577 | } else { | ||
578 | Addressee lse; | ||
579 | lse = mAddressBook->findByUid( "last-syncAddressee-"+ syncProfile ); | ||
580 | if ( ! lse.isEmpty() ) | ||
581 | removeAddressee( lse ); | ||
561 | } | 582 | } |
562 | 583 | ||
563 | } | 584 | } |
564 | void AddressBook::preparePhoneSync( QString currentSyncDevice, bool isPreSync ) | 585 | void AddressBook::preparePhoneSync( QString currentSyncDevice, bool isPreSync ) |
565 | { | 586 | { |
566 | Iterator ait; | 587 | Iterator ait; |
567 | for ( ait = begin(); ait != end(); ++ait ) { | 588 | for ( ait = begin(); ait != end(); ++ait ) { |
568 | QString id = (*ait).IDStr(); | 589 | QString id = (*ait).IDStr(); |
569 | (*ait).setIDStr( ":"); | 590 | (*ait).setIDStr( ":"); |
570 | (*ait).setExternalUID( id ); | 591 | (*ait).setExternalUID( id ); |
571 | (*ait).setOriginalExternalUID( id ); | 592 | (*ait).setOriginalExternalUID( id ); |
572 | if ( isPreSync ) | 593 | if ( isPreSync ) |
573 | (*ait).setTempSyncStat( SYNC_TEMPSTATE_NEW_EXTERNAL ); | 594 | (*ait).setTempSyncStat( SYNC_TEMPSTATE_NEW_EXTERNAL ); |
574 | else { | 595 | else { |
575 | (*ait).setTempSyncStat( SYNC_TEMPSTATE_NEW_ID ); | 596 | (*ait).setTempSyncStat( SYNC_TEMPSTATE_NEW_ID ); |
576 | (*ait).setID( currentSyncDevice,id ); | 597 | (*ait).setID( currentSyncDevice,id ); |
577 | 598 | ||
578 | } | 599 | } |
579 | } | 600 | } |
580 | } | 601 | } |
581 | void AddressBook::findNewExtIds( QString fileName, QString currentSyncDevice ) | 602 | void AddressBook::findNewExtIds( QString fileName, QString currentSyncDevice ) |
582 | { | 603 | { |
583 | 604 | ||
584 | setUntagged(); | 605 | setUntagged(); |
585 | KABC::Addressee::List list; | 606 | KABC::Addressee::List list; |
586 | QFile file( fileName ); | 607 | QFile file( fileName ); |
587 | file.open( IO_ReadOnly ); | 608 | file.open( IO_ReadOnly ); |
588 | QByteArray rawData = file.readAll(); | 609 | QByteArray rawData = file.readAll(); |
589 | file.close(); | 610 | file.close(); |
590 | QString data; | 611 | QString data; |
591 | 612 | ||
592 | data = QString::fromUtf8( rawData.data(), rawData.size() + 1 ); | 613 | data = QString::fromUtf8( rawData.data(), rawData.size() + 1 ); |
593 | KABC::VCardTool tool; | 614 | KABC::VCardTool tool; |
594 | list = tool.parseVCards( data ); | 615 | list = tool.parseVCards( data ); |
595 | KABC::Addressee::List::Iterator it; | 616 | KABC::Addressee::List::Iterator it; |
596 | for ( it = list.begin(); it != list.end(); ++it ) { | 617 | for ( it = list.begin(); it != list.end(); ++it ) { |
597 | Iterator ait; | 618 | Iterator ait; |
598 | for ( ait = begin(); ait != end(); ++ait ) { | 619 | for ( ait = begin(); ait != end(); ++ait ) { |
599 | if ( !(*ait).tagged() ) { | 620 | if ( !(*ait).tagged() ) { |
600 | if ( (*ait).containsAdr(*it)) { | 621 | if ( (*ait).containsAdr(*it)) { |
601 | (*ait).setTagged(true); | 622 | (*ait).setTagged(true); |
602 | QString id = (*it).custom( "KADDRESSBOOK", "X-ExternalID" ); | 623 | QString id = (*it).custom( "KADDRESSBOOK", "X-ExternalID" ); |
603 | (*it).setIDStr( ":"); | 624 | (*it).setIDStr( ":"); |
604 | (*it).setID( currentSyncDevice,id ); | 625 | (*it).setID( currentSyncDevice,id ); |
605 | (*it).setExternalUID( id ); | 626 | (*it).setExternalUID( id ); |
606 | (*it).setTempSyncStat( SYNC_TEMPSTATE_NEW_ID ); | 627 | (*it).setTempSyncStat( SYNC_TEMPSTATE_NEW_ID ); |
607 | (*it).setUid( ( (*ait).uid() )); | 628 | (*it).setUid( ( (*ait).uid() )); |
608 | break; | 629 | break; |
609 | } | 630 | } |
610 | } | 631 | } |
611 | 632 | ||
612 | } | 633 | } |
613 | if ( ait == end() ) | 634 | if ( ait == end() ) |
614 | qDebug("ERROR:: no ext ID found for uid: %s", (*it).uid().latin1()); | 635 | qDebug("ERROR:: no ext ID found for uid: %s", (*it).uid().latin1()); |
615 | } | 636 | } |
616 | clear(); | 637 | clear(); |
617 | for ( it = list.begin(); it != list.end(); ++it ) { | 638 | for ( it = list.begin(); it != list.end(); ++it ) { |
618 | insertAddressee( (*it) ); | 639 | insertAddressee( (*it) ); |
619 | } | 640 | } |
620 | } | 641 | } |
621 | 642 | ||
622 | bool AddressBook::saveABphone( QString fileName ) | 643 | bool AddressBook::saveABphone( QString fileName ) |
623 | { | 644 | { |
624 | //smplifyAddressees(); | 645 | //smplifyAddressees(); |
625 | qDebug("saveABphone:: saving AB... "); | 646 | qDebug("saveABphone:: saving AB... "); |
626 | if ( ! export2PhoneFormat( QStringList() ,fileName ) ) | 647 | if ( ! export2PhoneFormat( QStringList() ,fileName ) ) |
627 | return false; | 648 | return false; |
628 | qDebug("saveABphone:: writing to phone... "); | 649 | qDebug("saveABphone:: writing to phone... "); |
629 | if ( !PhoneAccess::writeToPhone( fileName) ) { | 650 | if ( !PhoneAccess::writeToPhone( fileName) ) { |
630 | return false; | 651 | return false; |
631 | } | 652 | } |
632 | qDebug("saveABphone:: re-reading from phone... "); | 653 | qDebug("saveABphone:: re-reading from phone... "); |
633 | if ( !PhoneAccess::readFromPhone( fileName) ) { | 654 | if ( !PhoneAccess::readFromPhone( fileName) ) { |
634 | return false; | 655 | return false; |
635 | } | 656 | } |
636 | return true; | 657 | return true; |
637 | } | 658 | } |
638 | bool AddressBook::saveAB() | 659 | bool AddressBook::saveAB() |
639 | { | 660 | { |
640 | bool ok = true; | 661 | bool ok = true; |
641 | 662 | ||
642 | deleteRemovedAddressees(); | 663 | deleteRemovedAddressees(); |
643 | Iterator ait; | 664 | Iterator ait; |
644 | for ( ait = begin(); ait != end(); ++ait ) { | 665 | for ( ait = begin(); ait != end(); ++ait ) { |
645 | if ( !(*ait).IDStr().isEmpty() ) { | 666 | if ( !(*ait).IDStr().isEmpty() ) { |
646 | (*ait).insertCustom( "KADDRESSBOOK", "X-ExternalID", (*ait).IDStr() ); | 667 | (*ait).insertCustom( "KADDRESSBOOK", "X-ExternalID", (*ait).IDStr() ); |
647 | } | 668 | } |
648 | } | 669 | } |
649 | KRES::Manager<Resource>::ActiveIterator it; | 670 | KRES::Manager<Resource>::ActiveIterator it; |
650 | KRES::Manager<Resource> *manager = d->mManager; | 671 | KRES::Manager<Resource> *manager = d->mManager; |
651 | qDebug("SaveAB::saving..." ); | 672 | qDebug("SaveAB::saving..." ); |
652 | for ( it = manager->activeBegin(); it != manager->activeEnd(); ++it ) { | 673 | for ( it = manager->activeBegin(); it != manager->activeEnd(); ++it ) { |
653 | qDebug("SaveAB::checking resource..." ); | 674 | qDebug("SaveAB::checking resource..." ); |
654 | if ( (*it)->readOnly() ) | 675 | if ( (*it)->readOnly() ) |
655 | qDebug("resource is readonly." ); | 676 | qDebug("resource is readonly." ); |
656 | if ( (*it)->isOpen() ) | 677 | if ( (*it)->isOpen() ) |
657 | qDebug("resource is open" ); | 678 | qDebug("resource is open" ); |
658 | 679 | ||
659 | if ( !(*it)->readOnly() && (*it)->isOpen() ) { | 680 | if ( !(*it)->readOnly() && (*it)->isOpen() ) { |
660 | Ticket *ticket = requestSaveTicket( *it ); | 681 | Ticket *ticket = requestSaveTicket( *it ); |
661 | qDebug("StdAddressBook::save '%s'", (*it)->resourceName().latin1() ); | 682 | qDebug("StdAddressBook::save '%s'", (*it)->resourceName().latin1() ); |
662 | if ( !ticket ) { | 683 | if ( !ticket ) { |
663 | qDebug( i18n( "Unable to save to resource '%1'. It is locked." ) | 684 | qDebug( i18n( "Unable to save to resource '%1'. It is locked." ) |
664 | .arg( (*it)->resourceName() ) ); | 685 | .arg( (*it)->resourceName() ) ); |
665 | return false; | 686 | return false; |
666 | } | 687 | } |
667 | 688 | ||
668 | //if ( !save( ticket ) ) | 689 | //if ( !save( ticket ) ) |
669 | if ( ticket->resource() ) { | 690 | if ( ticket->resource() ) { |
670 | QString name = ticket->resource()->resourceName(); | 691 | QString name = ticket->resource()->resourceName(); |
671 | if ( ! ticket->resource()->save( ticket ) ) | 692 | if ( ! ticket->resource()->save( ticket ) ) |
672 | ok = false; | 693 | ok = false; |
673 | else | 694 | else |
674 | qDebug("StdAddressBook::resource saved '%s'", name.latin1() ); | 695 | qDebug("StdAddressBook::resource saved '%s'", name.latin1() ); |
675 | 696 | ||
676 | } else | 697 | } else |
677 | ok = false; | 698 | ok = false; |
678 | 699 | ||
679 | } | 700 | } |
680 | } | 701 | } |
681 | return ok; | 702 | return ok; |
682 | } | 703 | } |
683 | 704 | ||
684 | AddressBook::Iterator AddressBook::begin() | 705 | AddressBook::Iterator AddressBook::begin() |
685 | { | 706 | { |
686 | Iterator it = Iterator(); | 707 | Iterator it = Iterator(); |
687 | it.d->mIt = d->mAddressees.begin(); | 708 | it.d->mIt = d->mAddressees.begin(); |
688 | return it; | 709 | return it; |
689 | } | 710 | } |
690 | 711 | ||
691 | AddressBook::ConstIterator AddressBook::begin() const | 712 | AddressBook::ConstIterator AddressBook::begin() const |
692 | { | 713 | { |
693 | ConstIterator it = ConstIterator(); | 714 | ConstIterator it = ConstIterator(); |
694 | it.d->mIt = d->mAddressees.begin(); | 715 | it.d->mIt = d->mAddressees.begin(); |
695 | return it; | 716 | return it; |
696 | } | 717 | } |
697 | 718 | ||
698 | AddressBook::Iterator AddressBook::end() | 719 | AddressBook::Iterator AddressBook::end() |
699 | { | 720 | { |
700 | Iterator it = Iterator(); | 721 | Iterator it = Iterator(); |
701 | it.d->mIt = d->mAddressees.end(); | 722 | it.d->mIt = d->mAddressees.end(); |
702 | return it; | 723 | return it; |
703 | } | 724 | } |
704 | 725 | ||
705 | AddressBook::ConstIterator AddressBook::end() const | 726 | AddressBook::ConstIterator AddressBook::end() const |
706 | { | 727 | { |
707 | ConstIterator it = ConstIterator(); | 728 | ConstIterator it = ConstIterator(); |
708 | it.d->mIt = d->mAddressees.end(); | 729 | it.d->mIt = d->mAddressees.end(); |
709 | return it; | 730 | return it; |
710 | } | 731 | } |
711 | 732 | ||
712 | void AddressBook::clear() | 733 | void AddressBook::clear() |
713 | { | 734 | { |
714 | d->mAddressees.clear(); | 735 | d->mAddressees.clear(); |
715 | } | 736 | } |
716 | 737 | ||
717 | Ticket *AddressBook::requestSaveTicket( Resource *resource ) | 738 | Ticket *AddressBook::requestSaveTicket( Resource *resource ) |
718 | { | 739 | { |
719 | kdDebug(5700) << "AddressBook::requestSaveTicket()" << endl; | 740 | kdDebug(5700) << "AddressBook::requestSaveTicket()" << endl; |
720 | 741 | ||
721 | if ( !resource ) | 742 | if ( !resource ) |
722 | { | 743 | { |
723 | qDebug("AddressBook::requestSaveTicket no resource" ); | 744 | qDebug("AddressBook::requestSaveTicket no resource" ); |
724 | resource = standardResource(); | 745 | resource = standardResource(); |
725 | } | 746 | } |
726 | 747 | ||
727 | KRES::Manager<Resource>::ActiveIterator it; | 748 | KRES::Manager<Resource>::ActiveIterator it; |
728 | for ( it = d->mManager->activeBegin(); it != d->mManager->activeEnd(); ++it ) { | 749 | for ( it = d->mManager->activeBegin(); it != d->mManager->activeEnd(); ++it ) { |
729 | if ( (*it) == resource ) { | 750 | if ( (*it) == resource ) { |
730 | if ( (*it)->readOnly() || !(*it)->isOpen() ) | 751 | if ( (*it)->readOnly() || !(*it)->isOpen() ) |
731 | return 0; | 752 | return 0; |
732 | else | 753 | else |
733 | return (*it)->requestSaveTicket(); | 754 | return (*it)->requestSaveTicket(); |
734 | } | 755 | } |
735 | } | 756 | } |
736 | 757 | ||
737 | return 0; | 758 | return 0; |
738 | } | 759 | } |
739 | //void insertAddressee( const Addressee &, bool setRev = true, bool takeResource = false); | 760 | //void insertAddressee( const Addressee &, bool setRev = true, bool takeResource = false); |
740 | void AddressBook::insertAddressee( const Addressee &a, bool setRev, bool takeResource ) | 761 | void AddressBook::insertAddressee( const Addressee &a, bool setRev, bool takeResource ) |
741 | { | 762 | { |
742 | if ( blockLSEchange && setRev && a.uid().left( 19 ) == QString("last-syncAddressee-") ) { | 763 | if ( blockLSEchange && setRev && a.uid().left( 19 ) == QString("last-syncAddressee-") ) { |
743 | //qDebug("block insert "); | 764 | //qDebug("block insert "); |
744 | return; | 765 | return; |
745 | } | 766 | } |
746 | //qDebug("inserting.... %s ",a.uid().latin1() ); | 767 | //qDebug("inserting.... %s ",a.uid().latin1() ); |
747 | bool found = false; | 768 | bool found = false; |
748 | Addressee::List::Iterator it; | 769 | Addressee::List::Iterator it; |
749 | for ( it = d->mAddressees.begin(); it != d->mAddressees.end(); ++it ) { | 770 | for ( it = d->mAddressees.begin(); it != d->mAddressees.end(); ++it ) { |
750 | if ( a.uid() == (*it).uid() ) { | 771 | if ( a.uid() == (*it).uid() ) { |
751 | 772 | ||
752 | bool changed = false; | 773 | bool changed = false; |
753 | Addressee addr = a; | 774 | Addressee addr = a; |
754 | if ( addr != (*it) ) | 775 | if ( addr != (*it) ) |
755 | changed = true; | 776 | changed = true; |
756 | 777 | ||
757 | if ( takeResource ) { | 778 | if ( takeResource ) { |
758 | Resource * res = (*it).resource(); | 779 | Resource * res = (*it).resource(); |
759 | (*it) = a; | 780 | (*it) = a; |
760 | (*it).setResource( res ); | 781 | (*it).setResource( res ); |
761 | } else { | 782 | } else { |
762 | (*it) = a; | 783 | (*it) = a; |
763 | if ( (*it).resource() == 0 ) | 784 | if ( (*it).resource() == 0 ) |
764 | (*it).setResource( standardResource() ); | 785 | (*it).setResource( standardResource() ); |
765 | } | 786 | } |
766 | if ( changed ) { | 787 | if ( changed ) { |
767 | if ( setRev ) { | 788 | if ( setRev ) { |
768 | 789 | ||
769 | // get rid of micro seconds | 790 | // get rid of micro seconds |
770 | QDateTime dt = QDateTime::currentDateTime(); | 791 | QDateTime dt = QDateTime::currentDateTime(); |
771 | QTime t = dt.time(); | 792 | QTime t = dt.time(); |
772 | dt.setTime( QTime (t.hour (), t.minute (), t.second () ) ); | 793 | dt.setTime( QTime (t.hour (), t.minute (), t.second () ) ); |
773 | (*it).setRevision( dt ); | 794 | (*it).setRevision( dt ); |
774 | } | 795 | } |
775 | (*it).setChanged( true ); | 796 | (*it).setChanged( true ); |
776 | } | 797 | } |
777 | 798 | ||
778 | found = true; | 799 | found = true; |
779 | } else { | 800 | } else { |
780 | if ( (*it).uid().left( 19 ) == QString("last-syncAddressee-") ) { | 801 | if ( (*it).uid().left( 19 ) == QString("last-syncAddressee-") ) { |
781 | QString name = (*it).uid().mid( 19 ); | 802 | QString name = (*it).uid().mid( 19 ); |
782 | Addressee b = a; | 803 | Addressee b = a; |
783 | QString id = b.getID( name ); | 804 | QString id = b.getID( name ); |
784 | if ( ! id.isEmpty() ) { | 805 | if ( ! id.isEmpty() ) { |
785 | QString des = (*it).note(); | 806 | QString des = (*it).note(); |
786 | int startN; | 807 | int startN; |
787 | if( (startN = des.find( id ) ) >= 0 ) { | 808 | if( (startN = des.find( id ) ) >= 0 ) { |
788 | int endN = des.find( ",", startN+1 ); | 809 | int endN = des.find( ",", startN+1 ); |
789 | des = des.left( startN ) + des.mid( endN+1 ); | 810 | des = des.left( startN ) + des.mid( endN+1 ); |
790 | (*it).setNote( des ); | 811 | (*it).setNote( des ); |
791 | } | 812 | } |
792 | } | 813 | } |
793 | } | 814 | } |
794 | } | 815 | } |
795 | } | 816 | } |
796 | if ( found ) | 817 | if ( found ) |
797 | return; | 818 | return; |
798 | d->mAddressees.append( a ); | 819 | d->mAddressees.append( a ); |
799 | Addressee& addr = d->mAddressees.last(); | 820 | Addressee& addr = d->mAddressees.last(); |
800 | if ( addr.resource() == 0 ) | 821 | if ( addr.resource() == 0 ) |
801 | addr.setResource( standardResource() ); | 822 | addr.setResource( standardResource() ); |
802 | 823 | ||
803 | addr.setChanged( true ); | 824 | addr.setChanged( true ); |
804 | } | 825 | } |
805 | 826 | ||
806 | void AddressBook::removeAddressee( const Addressee &a ) | 827 | void AddressBook::removeAddressee( const Addressee &a ) |
807 | { | 828 | { |
808 | Iterator it; | 829 | Iterator it; |
809 | Iterator it2; | 830 | Iterator it2; |
810 | bool found = false; | 831 | bool found = false; |
811 | for ( it = begin(); it != end(); ++it ) { | 832 | for ( it = begin(); it != end(); ++it ) { |
812 | if ( a.uid() == (*it).uid() ) { | 833 | if ( a.uid() == (*it).uid() ) { |
813 | found = true; | 834 | found = true; |
814 | it2 = it; | 835 | it2 = it; |
815 | } else { | 836 | } else { |
816 | if ( (*it).uid().left( 19 ) == QString("last-syncAddressee-") ) { | 837 | if ( (*it).uid().left( 19 ) == QString("last-syncAddressee-") ) { |