-rw-r--r-- | kabc/addressbook.cpp | 148 | ||||
-rw-r--r-- | kabc/addressbook.h | 2 | ||||
-rw-r--r-- | kabc/addressee.cpp | 46 | ||||
-rw-r--r-- | kabc/addressee.h | 1 | ||||
-rw-r--r-- | kabc/phonenumber.cpp | 4 |
5 files changed, 182 insertions, 19 deletions
diff --git a/kabc/addressbook.cpp b/kabc/addressbook.cpp index d037d2f..ad0f702 100644 --- a/kabc/addressbook.cpp +++ b/kabc/addressbook.cpp | |||
@@ -320,59 +320,58 @@ void AddressBook::init(const QString &config, const QString &family ) | |||
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 | |||
345 | clear(); | 344 | clear(); |
346 | |||
347 | KRES::Manager<Resource>::ActiveIterator it; | 345 | KRES::Manager<Resource>::ActiveIterator it; |
348 | bool ok = true; | 346 | bool ok = true; |
349 | for ( it = d->mManager->activeBegin(); it != d->mManager->activeEnd(); ++it ) | 347 | for ( it = d->mManager->activeBegin(); it != d->mManager->activeEnd(); ++it ) |
350 | if ( !(*it)->load() ) { | 348 | if ( !(*it)->load() ) { |
351 | error( i18n("Unable to load resource '%1'").arg( (*it)->resourceName() ) ); | 349 | qDebug( i18n("Unable to load resource '%1'").arg( (*it)->resourceName() ) ); |
352 | ok = false; | 350 | ok = false; |
351 | } else { | ||
352 | qDebug( i18n("Resource loaded: '%1'").arg( (*it)->resourceName() ) ); | ||
353 | } | 353 | } |
354 | |||
355 | // mark all addressees as unchanged | 354 | // mark all addressees as unchanged |
356 | Addressee::List::Iterator addrIt; | 355 | Addressee::List::Iterator addrIt; |
357 | for ( addrIt = d->mAddressees.begin(); addrIt != d->mAddressees.end(); ++addrIt ) { | 356 | for ( addrIt = d->mAddressees.begin(); addrIt != d->mAddressees.end(); ++addrIt ) { |
358 | (*addrIt).setChanged( false ); | 357 | (*addrIt).setChanged( false ); |
359 | QString id = (*addrIt).custom( "KADDRESSBOOK", "X-ExternalID" ); | 358 | QString id = (*addrIt).custom( "KADDRESSBOOK", "X-ExternalID" ); |
360 | if ( !id.isEmpty() ) { | 359 | if ( !id.isEmpty() ) { |
361 | //qDebug("setId aa %s ", id.latin1()); | 360 | //qDebug("setId aa %s ", id.latin1()); |
362 | (*addrIt).setIDStr(id ); | 361 | (*addrIt).setIDStr(id ); |
363 | } | 362 | } |
364 | } | 363 | } |
365 | blockLSEchange = true; | 364 | blockLSEchange = true; |
366 | return ok; | 365 | return ok; |
367 | } | 366 | } |
368 | 367 | ||
369 | bool AddressBook::save( Ticket *ticket ) | 368 | bool AddressBook::save( Ticket *ticket ) |
370 | { | 369 | { |
371 | kdDebug(5700) << "AddressBook::save()"<< endl; | 370 | kdDebug(5700) << "AddressBook::save()"<< endl; |
372 | 371 | ||
373 | if ( ticket->resource() ) { | 372 | if ( ticket->resource() ) { |
374 | deleteRemovedAddressees(); | 373 | deleteRemovedAddressees(); |
375 | return ticket->resource()->save( ticket ); | 374 | return ticket->resource()->save( ticket ); |
376 | } | 375 | } |
377 | 376 | ||
378 | return false; | 377 | return false; |
@@ -383,69 +382,141 @@ void AddressBook::export2File( QString fileName ) | |||
383 | QFile outFile( fileName ); | 382 | QFile outFile( fileName ); |
384 | if ( !outFile.open( IO_WriteOnly ) ) { | 383 | if ( !outFile.open( IO_WriteOnly ) ) { |
385 | QString text = i18n( "<qt>Unable to open file <b>%1</b> for export.</qt>" ); | 384 | QString text = i18n( "<qt>Unable to open file <b>%1</b> for export.</qt>" ); |
386 | KMessageBox::error( 0, text.arg( fileName ) ); | 385 | KMessageBox::error( 0, text.arg( fileName ) ); |
387 | return ; | 386 | return ; |
388 | } | 387 | } |
389 | QTextStream t( &outFile ); | 388 | QTextStream t( &outFile ); |
390 | t.setEncoding( QTextStream::UnicodeUTF8 ); | 389 | t.setEncoding( QTextStream::UnicodeUTF8 ); |
391 | Iterator it; | 390 | Iterator it; |
392 | KABC::VCardConverter::Version version; | 391 | KABC::VCardConverter::Version version; |
393 | version = KABC::VCardConverter::v3_0; | 392 | version = KABC::VCardConverter::v3_0; |
394 | for ( it = begin(); it != end(); ++it ) { | 393 | for ( it = begin(); it != end(); ++it ) { |
395 | if ( !(*it).IDStr().isEmpty() ) { | 394 | if ( !(*it).IDStr().isEmpty() ) { |
396 | (*it).insertCustom( "KADDRESSBOOK", "X-ExternalID", (*it).IDStr() ); | 395 | (*it).insertCustom( "KADDRESSBOOK", "X-ExternalID", (*it).IDStr() ); |
397 | } | 396 | } |
398 | KABC::VCardConverter converter; | 397 | KABC::VCardConverter converter; |
399 | QString vcard; | 398 | QString vcard; |
400 | //Resource *resource() const; | 399 | //Resource *resource() const; |
401 | converter.addresseeToVCard( *it, vcard, version ); | 400 | converter.addresseeToVCard( *it, vcard, version ); |
402 | t << vcard << "\r\n"; | 401 | t << vcard << "\r\n"; |
403 | } | 402 | } |
404 | t << "\r\n\r\n"; | 403 | t << "\r\n\r\n"; |
405 | outFile.close(); | 404 | outFile.close(); |
406 | } | 405 | } |
406 | // if QStringList uids is empty, all are exported | ||
407 | bool AddressBook::export2PhoneFormat( QStringList uids ,QString fileName ) | ||
408 | { | ||
409 | KABC::VCardConverter converter; | ||
410 | QString datastream; | ||
411 | Iterator it; | ||
412 | bool all = uids.isEmpty(); | ||
413 | for ( it = begin(); it != end(); ++it ) { | ||
414 | // for( QStringList::ConstIterator it = uids.begin(); it != uids.end(); ++it ) { | ||
415 | if ( ! all ) { | ||
416 | if ( ! ( uids.contains((*it).uid() ) )) | ||
417 | continue; | ||
418 | } | ||
419 | KABC::Addressee a = ( *it ); | ||
420 | if ( a.isEmpty() ) | ||
421 | continue; | ||
422 | a.simplifyEmails(); | ||
423 | a.simplifyPhoneNumbers(); | ||
424 | a.simplifyPhoneNumberTypes(); | ||
425 | a.simplifyAddresses(); | ||
426 | |||
427 | QString vcard; | ||
428 | QString vcardnew; | ||
429 | converter.addresseeToVCard( a, vcard ); | ||
430 | int start = 0; | ||
431 | int next; | ||
432 | while ( (next = vcard.find("TYPE=", start) )>= 0 ) { | ||
433 | int semi = vcard.find(";", next); | ||
434 | int dopp = vcard.find(":", next); | ||
435 | int sep; | ||
436 | if ( semi < dopp && semi >= 0 ) | ||
437 | sep = semi ; | ||
438 | else | ||
439 | sep = dopp; | ||
440 | vcardnew +=vcard.mid( start, next - start); | ||
441 | vcardnew +=vcard.mid( next+5,sep -next -5 ).upper(); | ||
442 | start = sep; | ||
443 | } | ||
444 | vcardnew += vcard.mid( start,vcard.length() ); | ||
445 | vcard = ""; | ||
446 | start = 0; | ||
447 | while ( (next = vcardnew.find("ADR", start) )>= 0 ) { | ||
448 | int sep = vcardnew.find(":", next); | ||
449 | vcard +=vcardnew.mid( start, next - start+3); | ||
450 | start = sep; | ||
451 | } | ||
452 | vcard += vcardnew.mid( start,vcardnew.length() ); | ||
453 | vcard.replace ( QRegExp(";;;") , "" ); | ||
454 | vcard.replace ( QRegExp(";;") , "" ); | ||
455 | datastream += vcard; | ||
456 | |||
457 | } | ||
458 | |||
459 | QFile outFile(fileName); | ||
460 | if ( outFile.open(IO_WriteOnly) ) { | ||
461 | datastream.replace ( QRegExp("VERSION:3.0") , "VERSION:2.1" ); | ||
462 | QTextStream t( &outFile ); // use a text stream | ||
463 | t.setEncoding( QTextStream::UnicodeUTF8 ); | ||
464 | t <<datastream; | ||
465 | t << "\r\n\r\n"; | ||
466 | outFile.close(); | ||
467 | |||
468 | } else { | ||
469 | qDebug("Error open temp file "); | ||
470 | return false; | ||
471 | } | ||
472 | return true; | ||
473 | |||
474 | } | ||
407 | void AddressBook::importFromFile( QString fileName, bool replaceLabel, bool removeOld ) | 475 | void AddressBook::importFromFile( QString fileName, bool replaceLabel, bool removeOld ) |
408 | { | 476 | { |
409 | 477 | ||
410 | if ( removeOld ) | 478 | if ( removeOld ) |
411 | setUntagged(); | 479 | setUntagged(); |
412 | KABC::Addressee::List list; | 480 | KABC::Addressee::List list; |
413 | QFile file( fileName ); | 481 | QFile file( fileName ); |
414 | file.open( IO_ReadOnly ); | 482 | file.open( IO_ReadOnly ); |
415 | QByteArray rawData = file.readAll(); | 483 | QByteArray rawData = file.readAll(); |
416 | file.close(); | 484 | file.close(); |
417 | QString data; | 485 | QString data; |
418 | if ( replaceLabel ) { | 486 | if ( replaceLabel ) { |
419 | data = QString::fromLatin1( rawData.data(), rawData.size() + 1 ); | 487 | data = QString::fromLatin1( rawData.data(), rawData.size() + 1 ); |
420 | data.replace ( QRegExp("LABEL") , "ADR" ); | 488 | data.replace ( QRegExp("LABEL") , "ADR" ); |
421 | data.replace ( QRegExp("CHARSET=ISO-8859-1") , "" ); | 489 | data.replace ( QRegExp("CHARSET=ISO-8859-1") , "" ); |
422 | } else | 490 | } else |
423 | data = QString::fromUtf8( rawData.data(), rawData.size() + 1 ); | 491 | data = QString::fromUtf8( rawData.data(), rawData.size() + 1 ); |
424 | KABC::VCardTool tool; | 492 | KABC::VCardTool tool; |
425 | list = tool.parseVCards( data ); | 493 | list = tool.parseVCards( data ); |
426 | KABC::Addressee::List::Iterator it; | 494 | KABC::Addressee::List::Iterator it; |
427 | for ( it = list.begin(); it != list.end(); ++it ) { | 495 | for ( it = list.begin(); it != list.end(); ++it ) { |
496 | QString id = (*it).custom( "KADDRESSBOOK", "X-ExternalID" ); | ||
497 | if ( !id.isEmpty() ) | ||
498 | (*it).setIDStr(id ); | ||
428 | (*it).setResource( 0 ); | 499 | (*it).setResource( 0 ); |
429 | if ( replaceLabel ) | 500 | if ( replaceLabel ) |
430 | (*it).removeVoice(); | 501 | (*it).removeVoice(); |
431 | if ( removeOld ) | 502 | if ( removeOld ) |
432 | (*it).setTagged( true ); | 503 | (*it).setTagged( true ); |
433 | insertAddressee( (*it), false, true ); | 504 | insertAddressee( (*it), false, true ); |
434 | } | 505 | } |
435 | if ( removeOld ) | 506 | if ( removeOld ) |
436 | removeUntagged(); | 507 | removeUntagged(); |
437 | } | 508 | } |
438 | void AddressBook::setUntagged() | 509 | void AddressBook::setUntagged() |
439 | { | 510 | { |
440 | Iterator ait; | 511 | Iterator ait; |
441 | for ( ait = begin(); ait != end(); ++ait ) { | 512 | for ( ait = begin(); ait != end(); ++ait ) { |
442 | (*ait).setTagged( false ); | 513 | (*ait).setTagged( false ); |
443 | } | 514 | } |
444 | } | 515 | } |
445 | void AddressBook::removeUntagged() | 516 | void AddressBook::removeUntagged() |
446 | { | 517 | { |
447 | Iterator ait; | 518 | Iterator ait; |
448 | bool todelete = false; | 519 | bool todelete = false; |
449 | Iterator todel; | 520 | Iterator todel; |
450 | for ( ait = begin(); ait != end(); ++ait ) { | 521 | for ( ait = begin(); ait != end(); ++ait ) { |
451 | if ( todelete ) | 522 | if ( todelete ) |
@@ -459,98 +530,149 @@ void AddressBook::removeUntagged() | |||
459 | if ( todelete ) | 530 | if ( todelete ) |
460 | removeAddressee( todel ); | 531 | removeAddressee( todel ); |
461 | deleteRemovedAddressees(); | 532 | deleteRemovedAddressees(); |
462 | } | 533 | } |
463 | void AddressBook::smplifyAddressees() | 534 | void AddressBook::smplifyAddressees() |
464 | { | 535 | { |
465 | Iterator ait; | 536 | Iterator ait; |
466 | for ( ait = begin(); ait != end(); ++ait ) { | 537 | for ( ait = begin(); ait != end(); ++ait ) { |
467 | (*ait).simplifyEmails(); | 538 | (*ait).simplifyEmails(); |
468 | (*ait).simplifyPhoneNumbers(); | 539 | (*ait).simplifyPhoneNumbers(); |
469 | (*ait).simplifyPhoneNumberTypes(); | 540 | (*ait).simplifyPhoneNumberTypes(); |
470 | (*ait).simplifyAddresses(); | 541 | (*ait).simplifyAddresses(); |
471 | } | 542 | } |
472 | } | 543 | } |
473 | void AddressBook::preparePhoneSync( QString currentSyncDevice, bool isPreSync ) | 544 | void AddressBook::preparePhoneSync( QString currentSyncDevice, bool isPreSync ) |
474 | { | 545 | { |
475 | Iterator ait; | 546 | Iterator ait; |
476 | for ( ait = begin(); ait != end(); ++ait ) { | 547 | for ( ait = begin(); ait != end(); ++ait ) { |
477 | QString id = (*ait).IDStr(); | 548 | QString id = (*ait).IDStr(); |
478 | (*ait).setIDStr( ":"); | 549 | (*ait).setIDStr( ":"); |
479 | (*ait).setExternalUID( id ); | 550 | (*ait).setExternalUID( id ); |
480 | (*ait).setOriginalExternalUID( id ); | 551 | (*ait).setOriginalExternalUID( id ); |
481 | if ( isPreSync ) | 552 | if ( isPreSync ) |
482 | (*ait).setTempSyncStat( SYNC_TEMPSTATE_NEW_EXTERNAL ); | 553 | (*ait).setTempSyncStat( SYNC_TEMPSTATE_NEW_EXTERNAL ); |
483 | else | 554 | else { |
484 | (*ait).setTempSyncStat( SYNC_TEMPSTATE_NEW_ID ); | 555 | (*ait).setTempSyncStat( SYNC_TEMPSTATE_NEW_ID ); |
556 | (*ait).setID( currentSyncDevice,id ); | ||
557 | |||
558 | } | ||
559 | } | ||
560 | } | ||
561 | void AddressBook::findNewExtIds( QString fileName, QString currentSyncDevice ) | ||
562 | { | ||
563 | |||
564 | setUntagged(); | ||
565 | KABC::Addressee::List list; | ||
566 | QFile file( fileName ); | ||
567 | file.open( IO_ReadOnly ); | ||
568 | QByteArray rawData = file.readAll(); | ||
569 | file.close(); | ||
570 | QString data; | ||
571 | |||
572 | data = QString::fromUtf8( rawData.data(), rawData.size() + 1 ); | ||
573 | KABC::VCardTool tool; | ||
574 | list = tool.parseVCards( data ); | ||
575 | KABC::Addressee::List::Iterator it; | ||
576 | for ( it = list.begin(); it != list.end(); ++it ) { | ||
577 | Iterator ait; | ||
578 | for ( ait = begin(); ait != end(); ++ait ) { | ||
579 | if ( !(*ait).tagged() ) { | ||
580 | if ( (*ait).containsAdr(*it)) { | ||
581 | (*ait).setTagged(true); | ||
582 | QString id = (*it).custom( "KADDRESSBOOK", "X-ExternalID" ); | ||
583 | (*it).setIDStr( ":"); | ||
584 | (*it).setID( currentSyncDevice,id ); | ||
585 | (*it).setExternalUID( id ); | ||
586 | (*it).setTempSyncStat( SYNC_TEMPSTATE_NEW_ID ); | ||
587 | (*it).setUid( ( (*ait).uid() )); | ||
588 | break; | ||
589 | } | ||
590 | } | ||
591 | |||
592 | } | ||
593 | if ( ait == end() ) | ||
594 | qDebug("ERROR:: no ext ID found for uid: %s", (*it).uid().latin1()); | ||
595 | } | ||
596 | clear(); | ||
597 | for ( it = list.begin(); it != list.end(); ++it ) { | ||
598 | insertAddressee( (*it) ); | ||
485 | } | 599 | } |
486 | } | 600 | } |
601 | |||
487 | bool AddressBook::saveABphone( QString fileName ) | 602 | bool AddressBook::saveABphone( QString fileName ) |
488 | { | 603 | { |
489 | smplifyAddressees(); | 604 | //smplifyAddressees(); |
490 | qDebug("saveABphone:: saving AB... "); | 605 | qDebug("saveABphone:: saving AB... "); |
491 | if ( ! saveAB() ) | 606 | if ( ! export2PhoneFormat( QStringList() ,fileName ) ) |
492 | return false; | 607 | return false; |
493 | qDebug("saveABphone:: writing to phone... "); | 608 | qDebug("saveABphone:: writing to phone... "); |
494 | if ( !PhoneAccess::writeToPhone( fileName) ) { | 609 | if ( !PhoneAccess::writeToPhone( fileName) ) { |
495 | return false; | 610 | return false; |
496 | } | 611 | } |
497 | qDebug("saveABphone:: re-reading from phone... "); | 612 | qDebug("saveABphone:: re-reading from phone... "); |
498 | if ( !PhoneAccess::readFromPhone( fileName) ) { | 613 | if ( !PhoneAccess::readFromPhone( fileName) ) { |
499 | return false; | 614 | return false; |
500 | } | 615 | } |
501 | qDebug("reloading phone book... "); | ||
502 | if ( !load() ) | ||
503 | return false; | ||
504 | return true; | 616 | return true; |
505 | } | 617 | } |
506 | bool AddressBook::saveAB() | 618 | bool AddressBook::saveAB() |
507 | { | 619 | { |
508 | bool ok = true; | 620 | bool ok = true; |
509 | 621 | ||
510 | deleteRemovedAddressees(); | 622 | deleteRemovedAddressees(); |
511 | Iterator ait; | 623 | Iterator ait; |
512 | for ( ait = begin(); ait != end(); ++ait ) { | 624 | for ( ait = begin(); ait != end(); ++ait ) { |
513 | if ( !(*ait).IDStr().isEmpty() ) { | 625 | if ( !(*ait).IDStr().isEmpty() ) { |
514 | (*ait).insertCustom( "KADDRESSBOOK", "X-ExternalID", (*ait).IDStr() ); | 626 | (*ait).insertCustom( "KADDRESSBOOK", "X-ExternalID", (*ait).IDStr() ); |
515 | } | 627 | } |
516 | } | 628 | } |
517 | KRES::Manager<Resource>::ActiveIterator it; | 629 | KRES::Manager<Resource>::ActiveIterator it; |
518 | KRES::Manager<Resource> *manager = d->mManager; | 630 | KRES::Manager<Resource> *manager = d->mManager; |
631 | qDebug("SaveAB::saving..." ); | ||
519 | for ( it = manager->activeBegin(); it != manager->activeEnd(); ++it ) { | 632 | for ( it = manager->activeBegin(); it != manager->activeEnd(); ++it ) { |
633 | qDebug("SaveAB::checking resource..." ); | ||
634 | if ( (*it)->readOnly() ) | ||
635 | qDebug("readonly." ); | ||
636 | if ( (*it)->isOpen() ) | ||
637 | qDebug("open" ); | ||
638 | |||
520 | if ( !(*it)->readOnly() && (*it)->isOpen() ) { | 639 | if ( !(*it)->readOnly() && (*it)->isOpen() ) { |
521 | Ticket *ticket = requestSaveTicket( *it ); | 640 | Ticket *ticket = requestSaveTicket( *it ); |
522 | // qDebug("StdAddressBook::save '%s'", (*it)->resourceName().latin1() ); | 641 | qDebug("StdAddressBook::save '%s'", (*it)->resourceName().latin1() ); |
523 | if ( !ticket ) { | 642 | if ( !ticket ) { |
524 | error( i18n( "Unable to save to resource '%1'. It is locked." ) | 643 | qDebug( i18n( "Unable to save to resource '%1'. It is locked." ) |
525 | .arg( (*it)->resourceName() ) ); | 644 | .arg( (*it)->resourceName() ) ); |
526 | return false; | 645 | return false; |
527 | } | 646 | } |
528 | 647 | ||
529 | //if ( !save( ticket ) ) | 648 | //if ( !save( ticket ) ) |
530 | if ( ticket->resource() ) { | 649 | if ( ticket->resource() ) { |
531 | if ( ! ticket->resource()->save( ticket ) ) | 650 | if ( ! ticket->resource()->save( ticket ) ) |
532 | ok = false; | 651 | ok = false; |
652 | else | ||
653 | qDebug("StdAddressBook::saved '%s'", ticket->resource()->resourceName().latin1() ); | ||
654 | |||
533 | } else | 655 | } else |
534 | ok = false; | 656 | ok = false; |
535 | 657 | ||
536 | } | 658 | } |
537 | } | 659 | } |
538 | return ok; | 660 | return ok; |
539 | } | 661 | } |
540 | 662 | ||
541 | AddressBook::Iterator AddressBook::begin() | 663 | AddressBook::Iterator AddressBook::begin() |
542 | { | 664 | { |
543 | Iterator it = Iterator(); | 665 | Iterator it = Iterator(); |
544 | it.d->mIt = d->mAddressees.begin(); | 666 | it.d->mIt = d->mAddressees.begin(); |
545 | return it; | 667 | return it; |
546 | } | 668 | } |
547 | 669 | ||
548 | AddressBook::ConstIterator AddressBook::begin() const | 670 | AddressBook::ConstIterator AddressBook::begin() const |
549 | { | 671 | { |
550 | ConstIterator it = ConstIterator(); | 672 | ConstIterator it = ConstIterator(); |
551 | it.d->mIt = d->mAddressees.begin(); | 673 | it.d->mIt = d->mAddressees.begin(); |
552 | return it; | 674 | return it; |
553 | } | 675 | } |
554 | 676 | ||
555 | AddressBook::Iterator AddressBook::end() | 677 | AddressBook::Iterator AddressBook::end() |
556 | { | 678 | { |
@@ -572,49 +694,49 @@ void AddressBook::clear() | |||
572 | } | 694 | } |
573 | 695 | ||
574 | Ticket *AddressBook::requestSaveTicket( Resource *resource ) | 696 | Ticket *AddressBook::requestSaveTicket( Resource *resource ) |
575 | { | 697 | { |
576 | kdDebug(5700) << "AddressBook::requestSaveTicket()" << endl; | 698 | kdDebug(5700) << "AddressBook::requestSaveTicket()" << endl; |
577 | 699 | ||
578 | if ( !resource ) | 700 | if ( !resource ) |
579 | { | 701 | { |
580 | qDebug("AddressBook::requestSaveTicket no resource" ); | 702 | qDebug("AddressBook::requestSaveTicket no resource" ); |
581 | resource = standardResource(); | 703 | resource = standardResource(); |
582 | } | 704 | } |
583 | 705 | ||
584 | KRES::Manager<Resource>::ActiveIterator it; | 706 | KRES::Manager<Resource>::ActiveIterator it; |
585 | for ( it = d->mManager->activeBegin(); it != d->mManager->activeEnd(); ++it ) { | 707 | for ( it = d->mManager->activeBegin(); it != d->mManager->activeEnd(); ++it ) { |
586 | if ( (*it) == resource ) { | 708 | if ( (*it) == resource ) { |
587 | if ( (*it)->readOnly() || !(*it)->isOpen() ) | 709 | if ( (*it)->readOnly() || !(*it)->isOpen() ) |
588 | return 0; | 710 | return 0; |
589 | else | 711 | else |
590 | return (*it)->requestSaveTicket(); | 712 | return (*it)->requestSaveTicket(); |
591 | } | 713 | } |
592 | } | 714 | } |
593 | 715 | ||
594 | return 0; | 716 | return 0; |
595 | } | 717 | } |
596 | 718 | //void insertAddressee( const Addressee &, bool setRev = true, bool takeResource = false); | |
597 | void AddressBook::insertAddressee( const Addressee &a, bool setRev, bool takeResource ) | 719 | void AddressBook::insertAddressee( const Addressee &a, bool setRev, bool takeResource ) |
598 | { | 720 | { |
599 | if ( blockLSEchange && setRev && a.uid().left( 19 ) == QString("last-syncAddressee-") ) { | 721 | if ( blockLSEchange && setRev && a.uid().left( 19 ) == QString("last-syncAddressee-") ) { |
600 | //qDebug("block insert "); | 722 | //qDebug("block insert "); |
601 | return; | 723 | return; |
602 | } | 724 | } |
603 | //qDebug("inserting.... %s ",a.uid().latin1() ); | 725 | //qDebug("inserting.... %s ",a.uid().latin1() ); |
604 | bool found = false; | 726 | bool found = false; |
605 | Addressee::List::Iterator it; | 727 | Addressee::List::Iterator it; |
606 | for ( it = d->mAddressees.begin(); it != d->mAddressees.end(); ++it ) { | 728 | for ( it = d->mAddressees.begin(); it != d->mAddressees.end(); ++it ) { |
607 | if ( a.uid() == (*it).uid() ) { | 729 | if ( a.uid() == (*it).uid() ) { |
608 | 730 | ||
609 | bool changed = false; | 731 | bool changed = false; |
610 | Addressee addr = a; | 732 | Addressee addr = a; |
611 | if ( addr != (*it) ) | 733 | if ( addr != (*it) ) |
612 | changed = true; | 734 | changed = true; |
613 | 735 | ||
614 | if ( takeResource ) { | 736 | if ( takeResource ) { |
615 | Resource * res = (*it).resource(); | 737 | Resource * res = (*it).resource(); |
616 | (*it) = a; | 738 | (*it) = a; |
617 | (*it).setResource( res ); | 739 | (*it).setResource( res ); |
618 | } else { | 740 | } else { |
619 | (*it) = a; | 741 | (*it) = a; |
620 | if ( (*it).resource() == 0 ) | 742 | if ( (*it).resource() == 0 ) |
diff --git a/kabc/addressbook.h b/kabc/addressbook.h index cc755d1..df9048b 100644 --- a/kabc/addressbook.h +++ b/kabc/addressbook.h | |||
@@ -125,51 +125,53 @@ class AddressBook : public QObject | |||
125 | locked the function returns 0. You need the returned @ref Ticket object | 125 | locked the function returns 0. You need the returned @ref Ticket object |
126 | for calling the @ref save() function. | 126 | for calling the @ref save() function. |
127 | 127 | ||
128 | @see save() | 128 | @see save() |
129 | */ | 129 | */ |
130 | Ticket *requestSaveTicket( Resource *resource=0 ); | 130 | Ticket *requestSaveTicket( Resource *resource=0 ); |
131 | 131 | ||
132 | /** | 132 | /** |
133 | Load address book from file. | 133 | Load address book from file. |
134 | */ | 134 | */ |
135 | bool load(); | 135 | bool load(); |
136 | 136 | ||
137 | /** | 137 | /** |
138 | Save address book. The address book is saved to the file, the Ticket | 138 | Save address book. The address book is saved to the file, the Ticket |
139 | object has been requested for by @ref requestSaveTicket(). | 139 | object has been requested for by @ref requestSaveTicket(). |
140 | 140 | ||
141 | @param ticket a ticket object returned by @ref requestSaveTicket() | 141 | @param ticket a ticket object returned by @ref requestSaveTicket() |
142 | */ | 142 | */ |
143 | bool save( Ticket *ticket ); | 143 | bool save( Ticket *ticket ); |
144 | bool saveAB( ); | 144 | bool saveAB( ); |
145 | bool saveABphone( QString fileName ); | 145 | bool saveABphone( QString fileName ); |
146 | void smplifyAddressees(); | 146 | void smplifyAddressees(); |
147 | void preparePhoneSync( QString currentSyncDevice, bool isPreSync ); | 147 | void preparePhoneSync( QString currentSyncDevice, bool isPreSync ); |
148 | void export2File( QString fileName ); | 148 | void export2File( QString fileName ); |
149 | bool export2PhoneFormat( QStringList uids ,QString fileName ); | ||
149 | void importFromFile( QString fileName, bool replaceLabel = false, bool removeOld = false ); | 150 | void importFromFile( QString fileName, bool replaceLabel = false, bool removeOld = false ); |
150 | void setUntagged(); | 151 | void setUntagged(); |
151 | void removeUntagged(); | 152 | void removeUntagged(); |
153 | void findNewExtIds( QString fileName, QString currentSyncDevice ); | ||
152 | /** | 154 | /** |
153 | Returns a iterator for first entry of address book. | 155 | Returns a iterator for first entry of address book. |
154 | */ | 156 | */ |
155 | Iterator begin(); | 157 | Iterator begin(); |
156 | 158 | ||
157 | /** | 159 | /** |
158 | Returns a const iterator for first entry of address book. | 160 | Returns a const iterator for first entry of address book. |
159 | */ | 161 | */ |
160 | ConstIterator begin() const; | 162 | ConstIterator begin() const; |
161 | 163 | ||
162 | /** | 164 | /** |
163 | Returns a iterator for first entry of address book. | 165 | Returns a iterator for first entry of address book. |
164 | */ | 166 | */ |
165 | Iterator end(); | 167 | Iterator end(); |
166 | 168 | ||
167 | /** | 169 | /** |
168 | Returns a const iterator for first entry of address book. | 170 | Returns a const iterator for first entry of address book. |
169 | */ | 171 | */ |
170 | ConstIterator end() const; | 172 | ConstIterator end() const; |
171 | 173 | ||
172 | /** | 174 | /** |
173 | Removes all entries from address book. | 175 | Removes all entries from address book. |
174 | */ | 176 | */ |
175 | void clear(); | 177 | void clear(); |
diff --git a/kabc/addressee.cpp b/kabc/addressee.cpp index 607ae26..548305a 100644 --- a/kabc/addressee.cpp +++ b/kabc/addressee.cpp | |||
@@ -282,86 +282,126 @@ void Addressee::mergeContact( const Addressee& ad ) | |||
282 | 282 | ||
283 | detach(); | 283 | detach(); |
284 | if ( mData->name.isEmpty() ) mData->name = ad.mData->name; | 284 | if ( mData->name.isEmpty() ) mData->name = ad.mData->name; |
285 | if ( mData->formattedName.isEmpty() ) mData->formattedName = ad.mData->formattedName; | 285 | if ( mData->formattedName.isEmpty() ) mData->formattedName = ad.mData->formattedName; |
286 | if ( mData->familyName.isEmpty() ) mData->familyName = ad.mData->familyName; | 286 | if ( mData->familyName.isEmpty() ) mData->familyName = ad.mData->familyName; |
287 | if ( mData->givenName.isEmpty() ) mData->givenName = ad.mData->givenName ; | 287 | if ( mData->givenName.isEmpty() ) mData->givenName = ad.mData->givenName ; |
288 | if ( mData->additionalName ) mData->additionalName = ad.mData->additionalName; | 288 | if ( mData->additionalName ) mData->additionalName = ad.mData->additionalName; |
289 | if ( mData->prefix.isEmpty() ) mData->prefix = ad.mData->prefix; | 289 | if ( mData->prefix.isEmpty() ) mData->prefix = ad.mData->prefix; |
290 | if ( mData->suffix.isEmpty() ) mData->suffix = ad.mData->suffix; | 290 | if ( mData->suffix.isEmpty() ) mData->suffix = ad.mData->suffix; |
291 | if ( mData->nickName.isEmpty() ) mData->nickName = ad.mData->nickName; | 291 | if ( mData->nickName.isEmpty() ) mData->nickName = ad.mData->nickName; |
292 | if ( !mData->birthday.isValid() ) | 292 | if ( !mData->birthday.isValid() ) |
293 | if ( ad.mData->birthday.isValid()) | 293 | if ( ad.mData->birthday.isValid()) |
294 | mData->birthday = ad.mData->birthday; | 294 | mData->birthday = ad.mData->birthday; |
295 | if ( mData->mailer.isEmpty() ) mData->mailer = ad.mData->mailer; | 295 | if ( mData->mailer.isEmpty() ) mData->mailer = ad.mData->mailer; |
296 | if ( !mData->timeZone.isValid() ) mData->timeZone = ad.mData->timeZone; | 296 | if ( !mData->timeZone.isValid() ) mData->timeZone = ad.mData->timeZone; |
297 | if ( !mData->geo.isValid() ) mData->geo = ad.mData->geo; | 297 | if ( !mData->geo.isValid() ) mData->geo = ad.mData->geo; |
298 | if ( mData->title .isEmpty() ) mData->title = ad.mData->title ; | 298 | if ( mData->title .isEmpty() ) mData->title = ad.mData->title ; |
299 | if ( mData->role.isEmpty() ) mData->role = ad.mData->role ; | 299 | if ( mData->role.isEmpty() ) mData->role = ad.mData->role ; |
300 | if ( mData->organization.isEmpty() ) mData->organization = ad.mData->organization ; | 300 | if ( mData->organization.isEmpty() ) mData->organization = ad.mData->organization ; |
301 | if ( mData->note.isEmpty() ) mData->note = ad.mData->note ; | 301 | if ( mData->note.isEmpty() ) mData->note = ad.mData->note ; |
302 | if ( mData->productId.isEmpty() ) mData->productId = ad.mData->productId; | 302 | if ( mData->productId.isEmpty() ) mData->productId = ad.mData->productId; |
303 | if ( mData->sortString.isEmpty() ) mData->sortString = ad.mData->sortString; | 303 | if ( mData->sortString.isEmpty() ) mData->sortString = ad.mData->sortString; |
304 | if ( !mData->secrecy.isValid() ) mData->secrecy = ad.mData->secrecy; | 304 | if ( !mData->secrecy.isValid() ) mData->secrecy = ad.mData->secrecy; |
305 | if ( ( !mData->url.isValid() && ad.mData->url.isValid() ) ) mData->url = ad.mData->url ; | 305 | if ( ( !mData->url.isValid() && ad.mData->url.isValid() ) ) mData->url = ad.mData->url ; |
306 | PhoneNumber::List phoneAD = phoneNumbers(); | ||
307 | PhoneNumber::List::Iterator phoneItAD; | ||
308 | bool found = false; | ||
309 | for ( phoneItAD = phoneAD.begin(); phoneItAD != phoneAD.end(); ++phoneItAD ) { | ||
306 | 310 | ||
311 | |||
312 | } | ||
307 | // pending: | 313 | // pending: |
308 | // merging phonenumbers | 314 | // merging phonenumbers |
309 | // merging addresses | 315 | // merging addresses |
310 | // merging emails; | 316 | // merging emails; |
311 | // merging categories; | 317 | // merging categories; |
312 | // merging custom; | 318 | // merging custom; |
313 | // merging keys | 319 | // merging keys |
314 | qDebug("merge contact %s ", ad.uid().latin1()); | 320 | //qDebug("merge contact %s ", ad.uid().latin1()); |
315 | setUid( ad.uid() ); | 321 | setUid( ad.uid() ); |
316 | setRevision( ad.revision() ); | 322 | setRevision( ad.revision() ); |
317 | } | 323 | } |
318 | 324 | ||
319 | bool Addressee::removeVoice() | 325 | bool Addressee::removeVoice() |
320 | { | 326 | { |
321 | PhoneNumber::List phoneN = phoneNumbers(); | 327 | PhoneNumber::List phoneN = phoneNumbers(); |
322 | PhoneNumber::List::Iterator phoneIt; | 328 | PhoneNumber::List::Iterator phoneIt; |
323 | bool found = false; | 329 | bool found = false; |
324 | for ( phoneIt = phoneN.begin(); phoneIt != phoneN.end(); ++phoneIt ) { | 330 | for ( phoneIt = phoneN.begin(); phoneIt != phoneN.end(); ++phoneIt ) { |
325 | if ( (*phoneIt).type() & PhoneNumber::Voice) { // voice found | 331 | if ( (*phoneIt).type() & PhoneNumber::Voice) { // voice found |
326 | if ((*phoneIt).type() - PhoneNumber::Voice ) { | 332 | if ((*phoneIt).type() - PhoneNumber::Voice ) { |
327 | (*phoneIt).setType((*phoneIt).type() - PhoneNumber::Voice ); | 333 | (*phoneIt).setType((*phoneIt).type() - PhoneNumber::Voice ); |
328 | insertPhoneNumber( (*phoneIt) ); | 334 | insertPhoneNumber( (*phoneIt) ); |
329 | found = true; | 335 | found = true; |
330 | } | 336 | } |
331 | } | 337 | } |
332 | 338 | ||
333 | } | 339 | } |
334 | return found; | 340 | return found; |
335 | } | 341 | } |
342 | |||
343 | bool Addressee::containsAdr(const Addressee& ad ) | ||
344 | { | ||
345 | if ( ! ad.mData->familyName.isEmpty() ) if ( mData->familyName != ad.mData->familyName) return false; | ||
346 | if ( ! ad.mData->givenName.isEmpty() )if ( mData->givenName != ad.mData->givenName ) return false; | ||
347 | if ( ad.mData->url.isValid() ) if (mData->url != ad.mData->url) return false ; | ||
348 | if ( ! ad.mData->role.isEmpty() ) if (mData->role != ad.mData->role) return false ; | ||
349 | if ( ! ad.mData->organization.isEmpty() ) if (mData->organization != ad.mData->organization) return false ; | ||
350 | if ( ! ad.mData->note.isEmpty() ) if (mData->note != ad.mData->note) return false ; | ||
351 | if ( ! ad.mData->title .isEmpty() ) if (mData->title != ad.mData->title ) return false ; | ||
352 | |||
353 | // compare phone numbers | ||
354 | PhoneNumber::List phoneN = ad.phoneNumbers(); | ||
355 | PhoneNumber::List::Iterator phoneIt; | ||
356 | bool found = false; | ||
357 | for ( phoneIt = phoneN.begin(); phoneIt != phoneN.end(); ++phoneIt ) { | ||
358 | bool found = false; | ||
359 | PhoneNumber::List phoneL = ad.phoneNumbers(); | ||
360 | PhoneNumber::List::Iterator phoneItL; | ||
361 | for ( phoneItL = phoneL.begin(); phoneItL != phoneL.end(); ++phoneItL ) { | ||
362 | if ( ( *phoneItL ).number() == ( *phoneIt ).number() ) { | ||
363 | found = true; | ||
364 | break; | ||
365 | } | ||
366 | } | ||
367 | if ( ! found ) | ||
368 | return false; | ||
369 | } | ||
370 | return true; | ||
371 | |||
372 | } | ||
336 | void Addressee::simplifyAddresses() | 373 | void Addressee::simplifyAddresses() |
337 | { | 374 | { |
338 | if ( mData->addresses.count() < 3 ) return ; | 375 | int max = 2; |
376 | if ( mData->url.isValid() ) | ||
377 | max = 1; | ||
378 | if ( mData->addresses.count() <= max ) return ; | ||
339 | int count = 0; | 379 | int count = 0; |
340 | Address::List list; | 380 | Address::List list; |
341 | Address::List::Iterator it; | 381 | Address::List::Iterator it; |
342 | for( it = mData->addresses.begin(); it != mData->addresses.end(); ++it ) { | 382 | for( it = mData->addresses.begin(); it != mData->addresses.end(); ++it ) { |
343 | if ( count > 1 ) | 383 | if ( count >= max ) |
344 | list.append( *it ); | 384 | list.append( *it ); |
345 | ++count; | 385 | ++count; |
346 | } | 386 | } |
347 | for( it = list.begin(); it != list.end(); ++it ) { | 387 | for( it = list.begin(); it != list.end(); ++it ) { |
348 | removeAddress( (*it) ); | 388 | removeAddress( (*it) ); |
349 | } | 389 | } |
350 | } | 390 | } |
351 | 391 | ||
352 | // removes all emails but the first | 392 | // removes all emails but the first |
353 | // needed by phone sync | 393 | // needed by phone sync |
354 | void Addressee::simplifyEmails() | 394 | void Addressee::simplifyEmails() |
355 | { | 395 | { |
356 | if ( mData->emails.count() == 0 ) return ; | 396 | if ( mData->emails.count() == 0 ) return ; |
357 | QString email = mData->emails.first(); | 397 | QString email = mData->emails.first(); |
358 | detach(); | 398 | detach(); |
359 | mData->emails.clear(); | 399 | mData->emails.clear(); |
360 | mData->emails.append( email ); | 400 | mData->emails.append( email ); |
361 | } | 401 | } |
362 | 402 | ||
363 | void Addressee::simplifyPhoneNumbers() | 403 | void Addressee::simplifyPhoneNumbers() |
364 | { | 404 | { |
365 | KABC::PhoneNumber::List removeNumbers; | 405 | KABC::PhoneNumber::List removeNumbers; |
366 | KABC::PhoneNumber::List::Iterator phoneIter; | 406 | KABC::PhoneNumber::List::Iterator phoneIter; |
367 | for ( phoneIter = mData->phoneNumbers.begin(); phoneIter != mData->phoneNumbers.end(); | 407 | for ( phoneIter = mData->phoneNumbers.begin(); phoneIter != mData->phoneNumbers.end(); |
diff --git a/kabc/addressee.h b/kabc/addressee.h index 0aa2c51..03138f6 100644 --- a/kabc/addressee.h +++ b/kabc/addressee.h | |||
@@ -101,48 +101,49 @@ class Addressee | |||
101 | int tempSyncStat() const; | 101 | int tempSyncStat() const; |
102 | void setIDStr( const QString & ); | 102 | void setIDStr( const QString & ); |
103 | QString IDStr() const; | 103 | QString IDStr() const; |
104 | void setID( const QString &, const QString & ); | 104 | void setID( const QString &, const QString & ); |
105 | QString getID( const QString & ); | 105 | QString getID( const QString & ); |
106 | void setCsum( const QString &, const QString & ); | 106 | void setCsum( const QString &, const QString & ); |
107 | QString getCsum( const QString & ); | 107 | QString getCsum( const QString & ); |
108 | void removeID(const QString &); | 108 | void removeID(const QString &); |
109 | void computeCsum(const QString &dev); | 109 | void computeCsum(const QString &dev); |
110 | ulong getCsum4List( const QStringList & attList); | 110 | ulong getCsum4List( const QStringList & attList); |
111 | /** | 111 | /** |
112 | Return, if the address book entry is empty. | 112 | Return, if the address book entry is empty. |
113 | */ | 113 | */ |
114 | bool isEmpty() const; | 114 | bool isEmpty() const; |
115 | void setExternalUID( const QString &id ); | 115 | void setExternalUID( const QString &id ); |
116 | QString externalUID() const; | 116 | QString externalUID() const; |
117 | void setOriginalExternalUID( const QString &id ); | 117 | void setOriginalExternalUID( const QString &id ); |
118 | QString originalExternalUID() const; | 118 | QString originalExternalUID() const; |
119 | void mergeContact( const Addressee& ad ); | 119 | void mergeContact( const Addressee& ad ); |
120 | void simplifyEmails(); | 120 | void simplifyEmails(); |
121 | void simplifyAddresses(); | 121 | void simplifyAddresses(); |
122 | void simplifyPhoneNumbers(); | 122 | void simplifyPhoneNumbers(); |
123 | void simplifyPhoneNumberTypes(); | 123 | void simplifyPhoneNumberTypes(); |
124 | bool removeVoice(); | 124 | bool removeVoice(); |
125 | bool containsAdr(const Addressee& addr ); | ||
125 | 126 | ||
126 | /** | 127 | /** |
127 | Set unique identifier. | 128 | Set unique identifier. |
128 | */ | 129 | */ |
129 | void setUid( const QString &uid ); | 130 | void setUid( const QString &uid ); |
130 | /** | 131 | /** |
131 | Return unique identifier. | 132 | Return unique identifier. |
132 | */ | 133 | */ |
133 | QString uid() const; | 134 | QString uid() const; |
134 | /** | 135 | /** |
135 | Return translated label for uid field. | 136 | Return translated label for uid field. |
136 | */ | 137 | */ |
137 | static QString uidLabel(); | 138 | static QString uidLabel(); |
138 | 139 | ||
139 | /** | 140 | /** |
140 | Set name. | 141 | Set name. |
141 | */ | 142 | */ |
142 | void setName( const QString &name ); | 143 | void setName( const QString &name ); |
143 | /** | 144 | /** |
144 | Return name. | 145 | Return name. |
145 | */ | 146 | */ |
146 | QString name() const; | 147 | QString name() const; |
147 | /** | 148 | /** |
148 | Return translated label for name field. | 149 | Return translated label for name field. |
diff --git a/kabc/phonenumber.cpp b/kabc/phonenumber.cpp index e5abc0e..6e94c7e 100644 --- a/kabc/phonenumber.cpp +++ b/kabc/phonenumber.cpp | |||
@@ -51,52 +51,50 @@ PhoneNumber::~PhoneNumber() | |||
51 | void PhoneNumber::init() | 51 | void PhoneNumber::init() |
52 | { | 52 | { |
53 | mId = KApplication::randomString( 8 ); | 53 | mId = KApplication::randomString( 8 ); |
54 | } | 54 | } |
55 | 55 | ||
56 | bool PhoneNumber::operator==( const PhoneNumber &p ) const | 56 | bool PhoneNumber::operator==( const PhoneNumber &p ) const |
57 | { | 57 | { |
58 | if ( mNumber != p.mNumber ) return false; | 58 | if ( mNumber != p.mNumber ) return false; |
59 | if ( mType != p.mType ) return false; | 59 | if ( mType != p.mType ) return false; |
60 | 60 | ||
61 | return true; | 61 | return true; |
62 | } | 62 | } |
63 | 63 | ||
64 | bool PhoneNumber::operator!=( const PhoneNumber &p ) const | 64 | bool PhoneNumber::operator!=( const PhoneNumber &p ) const |
65 | { | 65 | { |
66 | return !( p == *this ); | 66 | return !( p == *this ); |
67 | } | 67 | } |
68 | 68 | ||
69 | bool PhoneNumber::simplifyNumber() | 69 | bool PhoneNumber::simplifyNumber() |
70 | { | 70 | { |
71 | QString Number; | 71 | QString Number; |
72 | int i; | 72 | int i; |
73 | Number = mNumber.stripWhiteSpace (); | 73 | Number = mNumber.stripWhiteSpace (); |
74 | mNumber = ""; | 74 | mNumber = ""; |
75 | if ( Number.at(0) == '+' ) | ||
76 | mNumber += "+"; | ||
77 | for ( i = 0; i < Number.length(); ++i) { | 75 | for ( i = 0; i < Number.length(); ++i) { |
78 | if ( Number.at(i).isDigit() ) | 76 | if ( Number.at(i).isDigit() || Number.at(i) == '+'|| Number.at(i) == '*'|| Number.at(i) == '#' ) |
79 | mNumber += Number.at(i); | 77 | mNumber += Number.at(i); |
80 | } | 78 | } |
81 | return ( mNumber.length() > 0 ); | 79 | return ( mNumber.length() > 0 ); |
82 | } | 80 | } |
83 | // make cellphone compatible | 81 | // make cellphone compatible |
84 | void PhoneNumber::simplifyType() | 82 | void PhoneNumber::simplifyType() |
85 | { | 83 | { |
86 | if ( mType & Fax ) mType = Fax; | 84 | if ( mType & Fax ) mType = Fax; |
87 | else if ( mType & Cell ) mType = Cell; | 85 | else if ( mType & Cell ) mType = Cell; |
88 | else if ( mType & Work ) mType = Work ; | 86 | else if ( mType & Work ) mType = Work ; |
89 | else if ( mType & Home ) mType = Home; | 87 | else if ( mType & Home ) mType = Home; |
90 | else mType = Pref; | 88 | else mType = Pref; |
91 | } | 89 | } |
92 | void PhoneNumber::setId( const QString &id ) | 90 | void PhoneNumber::setId( const QString &id ) |
93 | { | 91 | { |
94 | mId = id; | 92 | mId = id; |
95 | } | 93 | } |
96 | 94 | ||
97 | QString PhoneNumber::id() const | 95 | QString PhoneNumber::id() const |
98 | { | 96 | { |
99 | return mId; | 97 | return mId; |
100 | } | 98 | } |
101 | 99 | ||
102 | void PhoneNumber::setNumber( const QString &number ) | 100 | void PhoneNumber::setNumber( const QString &number ) |