-rw-r--r-- | kabc/addressee.cpp | 22 |
1 files changed, 20 insertions, 2 deletions
diff --git a/kabc/addressee.cpp b/kabc/addressee.cpp index 295ee4f..2564894 100644 --- a/kabc/addressee.cpp +++ b/kabc/addressee.cpp | |||
@@ -322,263 +322,281 @@ void Addressee::mergeContact( const Addressee& ad , bool isSubSet) // = false) | |||
322 | tAD = ad.mData->emails; | 322 | tAD = ad.mData->emails; |
323 | for ( iii = 0; iii < tAD.count(); ++iii) | 323 | for ( iii = 0; iii < tAD.count(); ++iii) |
324 | if ( !t.contains(tAD[iii] ) ) | 324 | if ( !t.contains(tAD[iii] ) ) |
325 | mData->emails.append( tAD[iii] ); | 325 | mData->emails.append( tAD[iii] ); |
326 | } | 326 | } |
327 | 327 | ||
328 | // ************* categories; | 328 | // ************* categories; |
329 | t = mData->categories; | 329 | t = mData->categories; |
330 | tAD = ad.mData->categories; | 330 | tAD = ad.mData->categories; |
331 | for ( iii = 0; iii < tAD.count(); ++iii) | 331 | for ( iii = 0; iii < tAD.count(); ++iii) |
332 | if ( !t.contains(tAD[iii] ) ) | 332 | if ( !t.contains(tAD[iii] ) ) |
333 | mData->categories.append( tAD[iii] ); | 333 | mData->categories.append( tAD[iii] ); |
334 | QStringList::ConstIterator it; | 334 | QStringList::ConstIterator it; |
335 | for( it = ad.mData->custom.begin(); it != ad.mData->custom.end(); ++it ) { | 335 | for( it = ad.mData->custom.begin(); it != ad.mData->custom.end(); ++it ) { |
336 | QString qualifiedName = (*it).left( (*it).find( ":" )); | 336 | QString qualifiedName = (*it).left( (*it).find( ":" )); |
337 | bool found = false; | 337 | bool found = false; |
338 | QStringList::ConstIterator itL; | 338 | QStringList::ConstIterator itL; |
339 | for( itL = mData->custom.begin(); itL != mData->custom.end(); ++itL ) { | 339 | for( itL = mData->custom.begin(); itL != mData->custom.end(); ++itL ) { |
340 | if ( (*itL).startsWith( qualifiedName ) ) { | 340 | if ( (*itL).startsWith( qualifiedName ) ) { |
341 | found = true; | 341 | found = true; |
342 | break; | 342 | break; |
343 | } | 343 | } |
344 | } | 344 | } |
345 | if ( ! found ) { | 345 | if ( ! found ) { |
346 | mData->custom.append( *it ); | 346 | mData->custom.append( *it ); |
347 | } | 347 | } |
348 | } | 348 | } |
349 | if ( mData->logo.undefined() && !ad.mData->logo.undefined() ) mData->logo = ad.mData->logo; | 349 | if ( mData->logo.undefined() && !ad.mData->logo.undefined() ) mData->logo = ad.mData->logo; |
350 | if ( mData->photo.undefined() && !ad.mData->photo.undefined() ) mData->photo = ad.mData->photo; | 350 | if ( mData->photo.undefined() && !ad.mData->photo.undefined() ) mData->photo = ad.mData->photo; |
351 | if ( !mData->sound.isIntern() ) { | 351 | if ( !mData->sound.isIntern() ) { |
352 | if ( mData->sound.url().isEmpty() ) { | 352 | if ( mData->sound.url().isEmpty() ) { |
353 | mData->sound = ad.mData->sound; | 353 | mData->sound = ad.mData->sound; |
354 | } | 354 | } |
355 | } | 355 | } |
356 | if ( !mData->agent.isIntern() ) { | 356 | if ( !mData->agent.isIntern() ) { |
357 | if ( mData->agent.url().isEmpty() ) { | 357 | if ( mData->agent.url().isEmpty() ) { |
358 | mData->agent = ad.mData->agent; | 358 | mData->agent = ad.mData->agent; |
359 | } | 359 | } |
360 | } | 360 | } |
361 | { | 361 | { |
362 | Key::List::Iterator itA; | 362 | Key::List::Iterator itA; |
363 | for( itA = ad.mData->keys.begin(); itA != ad.mData->keys.end(); ++itA ) { | 363 | for( itA = ad.mData->keys.begin(); itA != ad.mData->keys.end(); ++itA ) { |
364 | bool found = false; | 364 | bool found = false; |
365 | Key::List::Iterator it; | 365 | Key::List::Iterator it; |
366 | for( it = mData->keys.begin(); it != mData->keys.end(); ++it ) { | 366 | for( it = mData->keys.begin(); it != mData->keys.end(); ++it ) { |
367 | if ( (*it) == (*itA)) { | 367 | if ( (*it) == (*itA)) { |
368 | found = true; | 368 | found = true; |
369 | break; | 369 | break; |
370 | 370 | ||
371 | } | 371 | } |
372 | } | 372 | } |
373 | if ( ! found ) { | 373 | if ( ! found ) { |
374 | mData->keys.append( *itA ); | 374 | mData->keys.append( *itA ); |
375 | } | 375 | } |
376 | } | 376 | } |
377 | } | 377 | } |
378 | KABC::Address::List::Iterator addressIterA; | 378 | KABC::Address::List::Iterator addressIterA; |
379 | for ( addressIterA = ad.mData->addresses.begin(); addressIterA != ad.mData->addresses.end(); ++addressIterA ) { | 379 | for ( addressIterA = ad.mData->addresses.begin(); addressIterA != ad.mData->addresses.end(); ++addressIterA ) { |
380 | bool found = false; | 380 | bool found = false; |
381 | KABC::Address::List::Iterator addressIter; | 381 | KABC::Address::List::Iterator addressIter; |
382 | for ( addressIter = mData->addresses.begin(); addressIter != mData->addresses.end(); | 382 | for ( addressIter = mData->addresses.begin(); addressIter != mData->addresses.end(); |
383 | ++addressIter ) { | 383 | ++addressIter ) { |
384 | if ( (*addressIter) == (*addressIterA)) { | 384 | if ( (*addressIter) == (*addressIterA)) { |
385 | found = true; | 385 | found = true; |
386 | (*addressIter).setType( (*addressIterA).type() ); | 386 | (*addressIter).setType( (*addressIterA).type() ); |
387 | break; | 387 | break; |
388 | } | 388 | } |
389 | 389 | ||
390 | } | 390 | } |
391 | if ( isSubSet && ! found ) { | 391 | if ( isSubSet && ! found ) { |
392 | mData->addresses.append( *addressIterA ); | 392 | mData->addresses.append( *addressIterA ); |
393 | } | 393 | } |
394 | } | 394 | } |
395 | //qDebug("merge contact %s ", ad.uid().latin1()); | 395 | //qDebug("merge contact %s ", ad.uid().latin1()); |
396 | setUid( ad.uid() ); | 396 | setUid( ad.uid() ); |
397 | setRevision( ad.revision() ); | 397 | setRevision( ad.revision() ); |
398 | } | 398 | } |
399 | 399 | ||
400 | bool Addressee::removeVoice() | 400 | bool Addressee::removeVoice() |
401 | { | 401 | { |
402 | PhoneNumber::List phoneN = phoneNumbers(); | 402 | PhoneNumber::List phoneN = phoneNumbers(); |
403 | PhoneNumber::List::Iterator phoneIt; | 403 | PhoneNumber::List::Iterator phoneIt; |
404 | bool found = false; | 404 | bool found = false; |
405 | for ( phoneIt = phoneN.begin(); phoneIt != phoneN.end(); ++phoneIt ) { | 405 | for ( phoneIt = phoneN.begin(); phoneIt != phoneN.end(); ++phoneIt ) { |
406 | if ( (*phoneIt).type() & PhoneNumber::Voice) { // voice found | 406 | if ( (*phoneIt).type() & PhoneNumber::Voice) { // voice found |
407 | if ((*phoneIt).type() - PhoneNumber::Voice ) { | 407 | if ((*phoneIt).type() - PhoneNumber::Voice ) { |
408 | (*phoneIt).setType((*phoneIt).type() - PhoneNumber::Voice ); | 408 | (*phoneIt).setType((*phoneIt).type() - PhoneNumber::Voice ); |
409 | insertPhoneNumber( (*phoneIt) ); | 409 | insertPhoneNumber( (*phoneIt) ); |
410 | found = true; | 410 | found = true; |
411 | } | 411 | } |
412 | } | 412 | } |
413 | 413 | ||
414 | } | 414 | } |
415 | return found; | 415 | return found; |
416 | } | 416 | } |
417 | 417 | ||
418 | bool Addressee::containsAdr(const Addressee& ad ) | 418 | bool Addressee::containsAdr(const Addressee& ad ) |
419 | { | 419 | { |
420 | if ( ! ad.mData->familyName.isEmpty() ) if ( mData->familyName != ad.mData->familyName) return false; | 420 | if ( ! ad.mData->familyName.isEmpty() ) if ( mData->familyName != ad.mData->familyName) return false; |
421 | if ( ! ad.mData->givenName.isEmpty() )if ( mData->givenName != ad.mData->givenName ) return false; | 421 | if ( ! ad.mData->givenName.isEmpty() )if ( mData->givenName != ad.mData->givenName ) return false; |
422 | if ( ad.mData->url.isValid() ) if (mData->url != ad.mData->url) return false ; | 422 | if ( ad.mData->url.isValid() ) if (mData->url != ad.mData->url) return false ; |
423 | if ( ! ad.mData->role.isEmpty() ) if (mData->role != ad.mData->role) return false ; | 423 | if ( ! ad.mData->role.isEmpty() ) if (mData->role != ad.mData->role) return false ; |
424 | if ( ! ad.mData->organization.isEmpty() ) if (mData->organization != ad.mData->organization) return false ; | 424 | if ( ! ad.mData->organization.isEmpty() ) if (mData->organization != ad.mData->organization) return false ; |
425 | if ( ! ad.mData->note.isEmpty() ) if (mData->note != ad.mData->note) return false ; | 425 | if ( ! ad.mData->note.isEmpty() ) if (mData->note != ad.mData->note) return false ; |
426 | if ( ! ad.mData->title .isEmpty() ) if (mData->title != ad.mData->title ) return false ; | 426 | if ( ! ad.mData->title .isEmpty() ) if (mData->title != ad.mData->title ) return false ; |
427 | 427 | ||
428 | // compare phone numbers | 428 | // compare phone numbers |
429 | PhoneNumber::List phoneN = ad.phoneNumbers(); | 429 | PhoneNumber::List phoneN = ad.phoneNumbers(); |
430 | PhoneNumber::List::Iterator phoneIt; | 430 | PhoneNumber::List::Iterator phoneIt; |
431 | bool found = false; | 431 | bool found = false; |
432 | for ( phoneIt = phoneN.begin(); phoneIt != phoneN.end(); ++phoneIt ) { | 432 | for ( phoneIt = phoneN.begin(); phoneIt != phoneN.end(); ++phoneIt ) { |
433 | bool found = false; | 433 | bool found = false; |
434 | PhoneNumber::List phoneL = ad.phoneNumbers(); | 434 | PhoneNumber::List phoneL = ad.phoneNumbers(); |
435 | PhoneNumber::List::Iterator phoneItL; | 435 | PhoneNumber::List::Iterator phoneItL; |
436 | for ( phoneItL = phoneL.begin(); phoneItL != phoneL.end(); ++phoneItL ) { | 436 | for ( phoneItL = phoneL.begin(); phoneItL != phoneL.end(); ++phoneItL ) { |
437 | if ( ( *phoneItL ).number() == ( *phoneIt ).number() ) { | 437 | if ( ( *phoneItL ).number() == ( *phoneIt ).number() ) { |
438 | found = true; | 438 | found = true; |
439 | break; | 439 | break; |
440 | } | 440 | } |
441 | } | 441 | } |
442 | if ( ! found ) | 442 | if ( ! found ) |
443 | return false; | 443 | return false; |
444 | } | 444 | } |
445 | return true; | 445 | return true; |
446 | 446 | ||
447 | } | 447 | } |
448 | void Addressee::simplifyAddresses() | 448 | void Addressee::simplifyAddresses() |
449 | { | 449 | { |
450 | |||
451 | |||
452 | Address::List list; | ||
453 | Address::List::Iterator it; | ||
454 | Address::List::Iterator it2; | ||
455 | for( it = mData->addresses.begin(); it != mData->addresses.end(); ++it ) { | ||
456 | it2 = it; | ||
457 | ++it2; | ||
458 | for( ; it2 != mData->addresses.end(); ++it2 ) { | ||
459 | if ( (*it) == (*it2) ) { | ||
460 | list.append( *it ); | ||
461 | break; | ||
462 | } | ||
463 | } | ||
464 | } | ||
465 | for( it = list.begin(); it != list.end(); ++it ) { | ||
466 | removeAddress( (*it) ); | ||
467 | } | ||
468 | |||
469 | list.clear(); | ||
450 | int max = 2; | 470 | int max = 2; |
451 | if ( mData->url.isValid() ) | 471 | if ( mData->url.isValid() ) |
452 | max = 1; | 472 | max = 1; |
453 | if ( mData->addresses.count() <= max ) return ; | 473 | if ( mData->addresses.count() <= max ) return ; |
454 | int count = 0; | 474 | int count = 0; |
455 | Address::List list; | ||
456 | Address::List::Iterator it; | ||
457 | for( it = mData->addresses.begin(); it != mData->addresses.end(); ++it ) { | 475 | for( it = mData->addresses.begin(); it != mData->addresses.end(); ++it ) { |
458 | if ( count >= max ) | 476 | if ( count >= max ) |
459 | list.append( *it ); | 477 | list.append( *it ); |
460 | ++count; | 478 | ++count; |
461 | } | 479 | } |
462 | for( it = list.begin(); it != list.end(); ++it ) { | 480 | for( it = list.begin(); it != list.end(); ++it ) { |
463 | removeAddress( (*it) ); | 481 | removeAddress( (*it) ); |
464 | } | 482 | } |
465 | } | 483 | } |
466 | 484 | ||
467 | // removes all emails but the first | 485 | // removes all emails but the first |
468 | // needed by phone sync | 486 | // needed by phone sync |
469 | void Addressee::simplifyEmails() | 487 | void Addressee::simplifyEmails() |
470 | { | 488 | { |
471 | if ( mData->emails.count() == 0 ) return ; | 489 | if ( mData->emails.count() == 0 ) return ; |
472 | QString email = mData->emails.first(); | 490 | QString email = mData->emails.first(); |
473 | detach(); | 491 | detach(); |
474 | mData->emails.clear(); | 492 | mData->emails.clear(); |
475 | mData->emails.append( email ); | 493 | mData->emails.append( email ); |
476 | } | 494 | } |
477 | 495 | ||
478 | void Addressee::simplifyPhoneNumbers() | 496 | void Addressee::simplifyPhoneNumbers() |
479 | { | 497 | { |
480 | int max = 4; | 498 | int max = 4; |
481 | int inList = mData->phoneNumbers.count(); | 499 | int inList = mData->phoneNumbers.count(); |
482 | KABC::PhoneNumber::List removeNumbers; | 500 | KABC::PhoneNumber::List removeNumbers; |
483 | KABC::PhoneNumber::List::Iterator phoneIter; | 501 | KABC::PhoneNumber::List::Iterator phoneIter; |
484 | if ( inList > max ) { | 502 | if ( inList > max ) { |
485 | // delete non-preferred numbers | 503 | // delete non-preferred numbers |
486 | for ( phoneIter = mData->phoneNumbers.begin(); phoneIter != mData->phoneNumbers.end(); | 504 | for ( phoneIter = mData->phoneNumbers.begin(); phoneIter != mData->phoneNumbers.end(); |
487 | ++phoneIter ) { | 505 | ++phoneIter ) { |
488 | if ( inList > max ) { | 506 | if ( inList > max ) { |
489 | if ( ! (( *phoneIter ).type() & PhoneNumber::Pref )) { | 507 | if ( ! (( *phoneIter ).type() & PhoneNumber::Pref )) { |
490 | removeNumbers.append( ( *phoneIter ) ); | 508 | removeNumbers.append( ( *phoneIter ) ); |
491 | --inList; | 509 | --inList; |
492 | } | 510 | } |
493 | } else | 511 | } else |
494 | break; | 512 | break; |
495 | } | 513 | } |
496 | for ( phoneIter = removeNumbers.begin(); phoneIter != removeNumbers.end(); | 514 | for ( phoneIter = removeNumbers.begin(); phoneIter != removeNumbers.end(); |
497 | ++phoneIter ) { | 515 | ++phoneIter ) { |
498 | removePhoneNumber(( *phoneIter )); | 516 | removePhoneNumber(( *phoneIter )); |
499 | } | 517 | } |
500 | // delete preferred numbers | 518 | // delete preferred numbers |
501 | if ( inList > max ) { | 519 | if ( inList > max ) { |
502 | for ( phoneIter = mData->phoneNumbers.begin(); phoneIter != mData->phoneNumbers.end(); | 520 | for ( phoneIter = mData->phoneNumbers.begin(); phoneIter != mData->phoneNumbers.end(); |
503 | ++phoneIter ) { | 521 | ++phoneIter ) { |
504 | if ( inList > max ) { | 522 | if ( inList > max ) { |
505 | removeNumbers.append( ( *phoneIter ) ); | 523 | removeNumbers.append( ( *phoneIter ) ); |
506 | --inList; | 524 | --inList; |
507 | } else | 525 | } else |
508 | break; | 526 | break; |
509 | } | 527 | } |
510 | for ( phoneIter = removeNumbers.begin(); phoneIter != removeNumbers.end(); | 528 | for ( phoneIter = removeNumbers.begin(); phoneIter != removeNumbers.end(); |
511 | ++phoneIter ) { | 529 | ++phoneIter ) { |
512 | removePhoneNumber(( *phoneIter )); | 530 | removePhoneNumber(( *phoneIter )); |
513 | } | 531 | } |
514 | } | 532 | } |
515 | } | 533 | } |
516 | // remove non-numeric characters | 534 | // remove non-numeric characters |
517 | for ( phoneIter = mData->phoneNumbers.begin(); phoneIter != mData->phoneNumbers.end(); | 535 | for ( phoneIter = mData->phoneNumbers.begin(); phoneIter != mData->phoneNumbers.end(); |
518 | ++phoneIter ) { | 536 | ++phoneIter ) { |
519 | if ( ! ( *phoneIter ).simplifyNumber() ) | 537 | if ( ! ( *phoneIter ).simplifyNumber() ) |
520 | removeNumbers.append( ( *phoneIter ) ); | 538 | removeNumbers.append( ( *phoneIter ) ); |
521 | } | 539 | } |
522 | for ( phoneIter = removeNumbers.begin(); phoneIter != removeNumbers.end(); | 540 | for ( phoneIter = removeNumbers.begin(); phoneIter != removeNumbers.end(); |
523 | ++phoneIter ) { | 541 | ++phoneIter ) { |
524 | removePhoneNumber(( *phoneIter )); | 542 | removePhoneNumber(( *phoneIter )); |
525 | } | 543 | } |
526 | } | 544 | } |
527 | void Addressee::simplifyPhoneNumberTypes() | 545 | void Addressee::simplifyPhoneNumberTypes() |
528 | { | 546 | { |
529 | KABC::PhoneNumber::List::Iterator phoneIter; | 547 | KABC::PhoneNumber::List::Iterator phoneIter; |
530 | for ( phoneIter = mData->phoneNumbers.begin(); phoneIter != mData->phoneNumbers.end(); | 548 | for ( phoneIter = mData->phoneNumbers.begin(); phoneIter != mData->phoneNumbers.end(); |
531 | ++phoneIter ) | 549 | ++phoneIter ) |
532 | ( *phoneIter ).simplifyType(); | 550 | ( *phoneIter ).simplifyType(); |
533 | } | 551 | } |
534 | void Addressee::removeID(const QString &prof) | 552 | void Addressee::removeID(const QString &prof) |
535 | { | 553 | { |
536 | detach(); | 554 | detach(); |
537 | mData->mExternalId = KIdManager::removeId ( mData->mExternalId, prof); | 555 | mData->mExternalId = KIdManager::removeId ( mData->mExternalId, prof); |
538 | 556 | ||
539 | } | 557 | } |
540 | void Addressee::setID( const QString & prof , const QString & id ) | 558 | void Addressee::setID( const QString & prof , const QString & id ) |
541 | { | 559 | { |
542 | detach(); | 560 | detach(); |
543 | mData->mExternalId = KIdManager::setId ( mData->mExternalId, prof, id ); | 561 | mData->mExternalId = KIdManager::setId ( mData->mExternalId, prof, id ); |
544 | //qDebug("setID2 %s %s %s",mData->mExternalId.latin1(), prof.latin1(), id.latin1() ); | 562 | //qDebug("setID2 %s %s %s",mData->mExternalId.latin1(), prof.latin1(), id.latin1() ); |
545 | } | 563 | } |
546 | void Addressee::setTempSyncStat( int id ) | 564 | void Addressee::setTempSyncStat( int id ) |
547 | { | 565 | { |
548 | if ( mData->mTempSyncStat == id ) return; | 566 | if ( mData->mTempSyncStat == id ) return; |
549 | detach(); | 567 | detach(); |
550 | mData->mTempSyncStat = id; | 568 | mData->mTempSyncStat = id; |
551 | } | 569 | } |
552 | int Addressee::tempSyncStat() const | 570 | int Addressee::tempSyncStat() const |
553 | { | 571 | { |
554 | return mData->mTempSyncStat; | 572 | return mData->mTempSyncStat; |
555 | } | 573 | } |
556 | 574 | ||
557 | QString Addressee::getID( const QString & prof) | 575 | QString Addressee::getID( const QString & prof) |
558 | { | 576 | { |
559 | return KIdManager::getId ( mData->mExternalId, prof ); | 577 | return KIdManager::getId ( mData->mExternalId, prof ); |
560 | } | 578 | } |
561 | 579 | ||
562 | void Addressee::setCsum( const QString & prof , const QString & id ) | 580 | void Addressee::setCsum( const QString & prof , const QString & id ) |
563 | { | 581 | { |
564 | detach(); | 582 | detach(); |
565 | //qDebug("setcsum1 %s %s %s",mData->mExternalId.latin1(), prof.latin1(), id.latin1() ); | 583 | //qDebug("setcsum1 %s %s %s",mData->mExternalId.latin1(), prof.latin1(), id.latin1() ); |
566 | mData->mExternalId = KIdManager::setCsum ( mData->mExternalId, prof, id ); | 584 | mData->mExternalId = KIdManager::setCsum ( mData->mExternalId, prof, id ); |
567 | //qDebug("setcsum2 %s ",mData->mExternalId.latin1() ); | 585 | //qDebug("setcsum2 %s ",mData->mExternalId.latin1() ); |
568 | } | 586 | } |
569 | 587 | ||
570 | QString Addressee::getCsum( const QString & prof) | 588 | QString Addressee::getCsum( const QString & prof) |
571 | { | 589 | { |
572 | return KIdManager::getCsum ( mData->mExternalId, prof ); | 590 | return KIdManager::getCsum ( mData->mExternalId, prof ); |
573 | } | 591 | } |
574 | 592 | ||
575 | void Addressee::setIDStr( const QString & s ) | 593 | void Addressee::setIDStr( const QString & s ) |
576 | { | 594 | { |
577 | detach(); | 595 | detach(); |
578 | mData->mExternalId = s; | 596 | mData->mExternalId = s; |
579 | } | 597 | } |
580 | 598 | ||
581 | QString Addressee::IDStr() const | 599 | QString Addressee::IDStr() const |
582 | { | 600 | { |
583 | return mData->mExternalId; | 601 | return mData->mExternalId; |
584 | } | 602 | } |