author | zautrix <zautrix> | 2004-10-10 16:00:04 (UTC) |
---|---|---|
committer | zautrix <zautrix> | 2004-10-10 16:00:04 (UTC) |
commit | ee6e29a5092d32165b7bf6b39069bd8a1dcd5b0a (patch) (unidiff) | |
tree | 1d908bfc23b8a49d43a58bbeadd82c4e08faeff6 /kabc | |
parent | 213a9d993e5a4751b64e18320cfbebb000681d13 (diff) | |
download | kdepimpi-ee6e29a5092d32165b7bf6b39069bd8a1dcd5b0a.zip kdepimpi-ee6e29a5092d32165b7bf6b39069bd8a1dcd5b0a.tar.gz kdepimpi-ee6e29a5092d32165b7bf6b39069bd8a1dcd5b0a.tar.bz2 |
many phone AB sync fixes
-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 | |||
@@ -343,5 +343,3 @@ bool AddressBook::load() | |||
343 | 343 | ||
344 | |||
345 | clear(); | 344 | clear(); |
346 | |||
347 | KRES::Manager<Resource>::ActiveIterator it; | 345 | KRES::Manager<Resource>::ActiveIterator it; |
@@ -350,6 +348,7 @@ bool AddressBook::load() | |||
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 |
@@ -406,2 +405,71 @@ void AddressBook::export2File( QString fileName ) | |||
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 ) |
@@ -427,2 +495,5 @@ void AddressBook::importFromFile( QString fileName, bool replaceLabel, bool rem | |||
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 ); |
@@ -482,11 +553,55 @@ void AddressBook::preparePhoneSync( QString currentSyncDevice, bool 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; |
@@ -500,5 +615,2 @@ bool AddressBook::saveABphone( QString fileName ) | |||
500 | } | 615 | } |
501 | qDebug("reloading phone book... "); | ||
502 | if ( !load() ) | ||
503 | return false; | ||
504 | return true; | 616 | return true; |
@@ -518,8 +630,15 @@ bool AddressBook::saveAB() | |||
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() ) ); |
@@ -532,2 +651,5 @@ bool AddressBook::saveAB() | |||
532 | ok = false; | 651 | ok = false; |
652 | else | ||
653 | qDebug("StdAddressBook::saved '%s'", ticket->resource()->resourceName().latin1() ); | ||
654 | |||
533 | } else | 655 | } else |
@@ -595,3 +717,3 @@ Ticket *AddressBook::requestSaveTicket( Resource *resource ) | |||
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 ) |
diff --git a/kabc/addressbook.h b/kabc/addressbook.h index cc755d1..df9048b 100644 --- a/kabc/addressbook.h +++ b/kabc/addressbook.h | |||
@@ -148,2 +148,3 @@ class AddressBook : public QObject | |||
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 ); |
@@ -151,2 +152,3 @@ class AddressBook : public QObject | |||
151 | void removeUntagged(); | 152 | void removeUntagged(); |
153 | void findNewExtIds( QString fileName, QString currentSyncDevice ); | ||
152 | /** | 154 | /** |
diff --git a/kabc/addressee.cpp b/kabc/addressee.cpp index 607ae26..548305a 100644 --- a/kabc/addressee.cpp +++ b/kabc/addressee.cpp | |||
@@ -305,3 +305,9 @@ void Addressee::mergeContact( const Addressee& ad ) | |||
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: |
@@ -313,3 +319,3 @@ void Addressee::mergeContact( const Addressee& ad ) | |||
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() ); |
@@ -335,5 +341,39 @@ bool Addressee::removeVoice() | |||
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; |
@@ -342,3 +382,3 @@ void Addressee::simplifyAddresses() | |||
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 ); |
diff --git a/kabc/addressee.h b/kabc/addressee.h index 0aa2c51..03138f6 100644 --- a/kabc/addressee.h +++ b/kabc/addressee.h | |||
@@ -124,2 +124,3 @@ class Addressee | |||
124 | bool removeVoice(); | 124 | bool removeVoice(); |
125 | bool containsAdr(const Addressee& addr ); | ||
125 | 126 | ||
diff --git a/kabc/phonenumber.cpp b/kabc/phonenumber.cpp index e5abc0e..6e94c7e 100644 --- a/kabc/phonenumber.cpp +++ b/kabc/phonenumber.cpp | |||
@@ -74,6 +74,4 @@ bool PhoneNumber::simplifyNumber() | |||
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); |