summaryrefslogtreecommitdiffabout
authorzautrix <zautrix>2004-10-10 16:00:04 (UTC)
committer zautrix <zautrix>2004-10-10 16:00:04 (UTC)
commitee6e29a5092d32165b7bf6b39069bd8a1dcd5b0a (patch) (unidiff)
tree1d908bfc23b8a49d43a58bbeadd82c4e08faeff6
parent213a9d993e5a4751b64e18320cfbebb000681d13 (diff)
downloadkdepimpi-ee6e29a5092d32165b7bf6b39069bd8a1dcd5b0a.zip
kdepimpi-ee6e29a5092d32165b7bf6b39069bd8a1dcd5b0a.tar.gz
kdepimpi-ee6e29a5092d32165b7bf6b39069bd8a1dcd5b0a.tar.bz2
many phone AB sync fixes
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--gammu/emb/common/service/gsmmisc.c4
-rw-r--r--gammu/emb/common/service/gsmpbk.c17
-rw-r--r--gammu/emb/gammu/gammu.c2
-rw-r--r--kabc/addressbook.cpp148
-rw-r--r--kabc/addressbook.h2
-rw-r--r--kabc/addressee.cpp46
-rw-r--r--kabc/addressee.h1
-rw-r--r--kabc/phonenumber.cpp4
-rw-r--r--kaddressbook/kabcore.cpp86
-rw-r--r--libkdepim/ksyncprefsdialog.cpp11
10 files changed, 217 insertions, 104 deletions
diff --git a/gammu/emb/common/service/gsmmisc.c b/gammu/emb/common/service/gsmmisc.c
index 6959a22..1c6ec8b 100644
--- a/gammu/emb/common/service/gsmmisc.c
+++ b/gammu/emb/common/service/gsmmisc.c
@@ -202,11 +202,11 @@ void SaveVCALText(char *Buffer, int *Length, char *Text, char *Start)
202 char buffer[1000]; 202 char buffer[1000];
203 203
204 if (UnicodeLength(Text) != 0) { 204 if (UnicodeLength(Text) != 0) {
205 EncodeUTF8QuotedPrintable(buffer,Text); 205 EncodeUTF8(buffer,Text);
206 if (UnicodeLength(Text)==strlen(buffer)) { 206 if (UnicodeLength(Text)==strlen(buffer)) {
207 *Length+=sprintf(Buffer+(*Length), "%s:%s%c%c",Start,DecodeUnicodeString(Text),13,10); 207 *Length+=sprintf(Buffer+(*Length), "%s:%s%c%c",Start,DecodeUnicodeString(Text),13,10);
208 } else { 208 } else {
209 *Length+=sprintf(Buffer+(*Length), "%s;CHARSET=UTF-8;ENCODING=QUOTED-PRINTABLE:%s%c%c",Start,buffer,13,10); 209 *Length+=sprintf(Buffer+(*Length), "%s:%s%c%c",Start,buffer,13,10);
210 } 210 }
211 } 211 }
212} 212}
diff --git a/gammu/emb/common/service/gsmpbk.c b/gammu/emb/common/service/gsmpbk.c
index 05e5cb9..f7cf7d7 100644
--- a/gammu/emb/common/service/gsmpbk.c
+++ b/gammu/emb/common/service/gsmpbk.c
@@ -131,27 +131,27 @@ void GSM_EncodeVCARD(char *Buffer, int *Length, GSM_MemoryEntry *pbk, bool heade
131 break; 131 break;
132 case PBK_Number_General : 132 case PBK_Number_General :
133 *Length+=sprintf(Buffer+(*Length),"TEL"); 133 *Length+=sprintf(Buffer+(*Length),"TEL");
134 if (Number == i) (*Length)+=sprintf(Buffer+(*Length),";PREF"); 134 (*Length)+=sprintf(Buffer+(*Length),";PREF");
135 break; 135 break;
136 case PBK_Number_Mobile : 136 case PBK_Number_Mobile :
137 *Length+=sprintf(Buffer+(*Length),"TEL"); 137 *Length+=sprintf(Buffer+(*Length),"TEL");
138 if (Number == i) (*Length)+=sprintf(Buffer+(*Length),";PREF"); 138 //if (Number == i) (*Length)+=sprintf(Buffer+(*Length),";PREF");
139 *Length+=sprintf(Buffer+(*Length),";CELL"); 139 *Length+=sprintf(Buffer+(*Length),";CELL");
140 break; 140 break;
141 case PBK_Number_Work : 141 case PBK_Number_Work :
142 *Length+=sprintf(Buffer+(*Length),"TEL"); 142 *Length+=sprintf(Buffer+(*Length),"TEL");
143 if (Number == i) (*Length)+=sprintf(Buffer+(*Length),";PREF"); 143 //if (Number == i) (*Length)+=sprintf(Buffer+(*Length),";PREF");
144 *Length+=sprintf(Buffer+(*Length),";WORK;VOICE"); 144 *Length+=sprintf(Buffer+(*Length),";WORK");
145 break; 145 break;
146 case PBK_Number_Fax : 146 case PBK_Number_Fax :
147 *Length+=sprintf(Buffer+(*Length),"TEL"); 147 *Length+=sprintf(Buffer+(*Length),"TEL");
148 if (Number == i) (*Length)+=sprintf(Buffer+(*Length),";PREF"); 148 //if (Number == i) (*Length)+=sprintf(Buffer+(*Length),";PREF");
149 *Length+=sprintf(Buffer+(*Length),";FAX"); 149 *Length+=sprintf(Buffer+(*Length),";FAX");
150 break; 150 break;
151 case PBK_Number_Home : 151 case PBK_Number_Home :
152 *Length+=sprintf(Buffer+(*Length),"TEL"); 152 *Length+=sprintf(Buffer+(*Length),"TEL");
153 if (Number == i) (*Length)+=sprintf(Buffer+(*Length),";PREF"); 153 //if (Number == i) (*Length)+=sprintf(Buffer+(*Length),";PREF");
154 *Length+=sprintf(Buffer+(*Length),";HOME;VOICE"); 154 *Length+=sprintf(Buffer+(*Length),";HOME");
155 break; 155 break;
156 case PBK_Text_Note : 156 case PBK_Text_Note :
157 *Length+=sprintf(Buffer+(*Length),"NOTE"); 157 *Length+=sprintf(Buffer+(*Length),"NOTE");
@@ -160,7 +160,7 @@ void GSM_EncodeVCARD(char *Buffer, int *Length, GSM_MemoryEntry *pbk, bool heade
160 /* Don't ask why. Nokia phones save postal address 160 /* Don't ask why. Nokia phones save postal address
161 * double - once like LABEL, second like ADR 161 * double - once like LABEL, second like ADR
162 */ 162 */
163 SaveVCALText(Buffer, Length, pbk->Entries[i].Text, "LABEL"); 163 //SaveVCALText(Buffer, Length, pbk->Entries[i].Text, "LABEL");
164 *Length+=sprintf(Buffer+(*Length),"ADR"); 164 *Length+=sprintf(Buffer+(*Length),"ADR");
165 break; 165 break;
166 case PBK_Text_Email : 166 case PBK_Text_Email :
@@ -179,6 +179,7 @@ void GSM_EncodeVCARD(char *Buffer, int *Length, GSM_MemoryEntry *pbk, bool heade
179 } 179 }
180 } 180 }
181 } 181 }
182 *Length+=sprintf(Buffer+(*Length), "X-KADDRESSBOOK-X-ExternalID:%d%c%c",pbk->Location,13,10);
182 if (header) *Length+=sprintf(Buffer+(*Length),"END:VCARD%c%c",13,10); 183 if (header) *Length+=sprintf(Buffer+(*Length),"END:VCARD%c%c",13,10);
183 } 184 }
184} 185}
diff --git a/gammu/emb/gammu/gammu.c b/gammu/emb/gammu/gammu.c
index 8db9afb..684e67c 100644
--- a/gammu/emb/gammu/gammu.c
+++ b/gammu/emb/gammu/gammu.c
@@ -4686,7 +4686,7 @@ static void Restore(int argc, char *argv[])
4686 max = 0; 4686 max = 0;
4687 while (Backup.PhonePhonebook[max]!=NULL) max++; 4687 while (Backup.PhonePhonebook[max]!=NULL) max++;
4688 printmsgerr("%i entries in backup file\n",max); 4688 printmsgerr("%i entries in backup file\n",max);
4689 if (answer_yes("Restore phone phonebook")) DoRestore = true; 4689 /* LR if (answer_yes("Restore phone phonebook")) */DoRestore = true;
4690 } 4690 }
4691 } 4691 }
4692 if (DoRestore) { 4692 if (DoRestore) {
diff --git a/kabc/addressbook.cpp b/kabc/addressbook.cpp
index d037d2f..ad0f702 100644
--- a/kabc/addressbook.cpp
+++ b/kabc/addressbook.cpp
@@ -341,17 +341,16 @@ AddressBook::~AddressBook()
341bool AddressBook::load() 341bool 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 ) {
@@ -404,6 +403,75 @@ void AddressBook::export2File( QString fileName )
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
407bool 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}
407void AddressBook::importFromFile( QString fileName, bool replaceLabel, bool removeOld ) 475void AddressBook::importFromFile( QString fileName, bool replaceLabel, bool removeOld )
408{ 476{
409 477
@@ -425,6 +493,9 @@ void AddressBook::importFromFile( QString fileName, bool replaceLabel, bool rem
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();
@@ -480,15 +551,59 @@ void AddressBook::preparePhoneSync( QString currentSyncDevice, bool isPreSync )
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}
561void 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
487bool AddressBook::saveABphone( QString fileName ) 602bool 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) ) {
@@ -498,9 +613,6 @@ bool AddressBook::saveABphone( QString fileName )
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}
506bool AddressBook::saveAB() 618bool AddressBook::saveAB()
@@ -516,12 +628,19 @@ bool AddressBook::saveAB()
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 }
@@ -530,6 +649,9 @@ bool AddressBook::saveAB()
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
@@ -593,7 +715,7 @@ Ticket *AddressBook::requestSaveTicket( Resource *resource )
593 715
594 return 0; 716 return 0;
595} 717}
596 718//void insertAddressee( const Addressee &, bool setRev = true, bool takeResource = false);
597void AddressBook::insertAddressee( const Addressee &a, bool setRev, bool takeResource ) 719void 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-") ) {
diff --git a/kabc/addressbook.h b/kabc/addressbook.h
index cc755d1..df9048b 100644
--- a/kabc/addressbook.h
+++ b/kabc/addressbook.h
@@ -146,9 +146,11 @@ class AddressBook : public QObject
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 */
diff --git a/kabc/addressee.cpp b/kabc/addressee.cpp
index 607ae26..548305a 100644
--- a/kabc/addressee.cpp
+++ b/kabc/addressee.cpp
@@ -303,7 +303,13 @@ void Addressee::mergeContact( const Addressee& ad )
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
@@ -311,7 +317,7 @@ void Addressee::mergeContact( const Addressee& ad )
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}
@@ -333,14 +339,48 @@ bool Addressee::removeVoice()
333 } 339 }
334 return found; 340 return found;
335} 341}
342
343bool 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}
336void Addressee::simplifyAddresses() 373void 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 }
diff --git a/kabc/addressee.h b/kabc/addressee.h
index 0aa2c51..03138f6 100644
--- a/kabc/addressee.h
+++ b/kabc/addressee.h
@@ -122,6 +122,7 @@ class Addressee
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.
diff --git a/kabc/phonenumber.cpp b/kabc/phonenumber.cpp
index e5abc0e..6e94c7e 100644
--- a/kabc/phonenumber.cpp
+++ b/kabc/phonenumber.cpp
@@ -72,10 +72,8 @@ bool PhoneNumber::simplifyNumber()
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 );
diff --git a/kaddressbook/kabcore.cpp b/kaddressbook/kabcore.cpp
index a7967cb..cd261f6 100644
--- a/kaddressbook/kabcore.cpp
+++ b/kaddressbook/kabcore.cpp
@@ -185,8 +185,8 @@ class KAex2phonePrefs : public QDialog
185 new QLabel( i18n("Model(opt.): "), temphb ); 185 new QLabel( i18n("Model(opt.): "), temphb );
186 mPhoneModel = new QLineEdit( temphb); 186 mPhoneModel = new QLineEdit( temphb);
187 lay->addWidget( temphb ); 187 lay->addWidget( temphb );
188 mWriteToSim= new QCheckBox( i18n("Write Contacts to SIM card\n(if not, write to phone memory)"), this ); 188 // mWriteToSim = new QCheckBox( i18n("Write Contacts to SIM card\n(if not, write to phone memory)"), this );
189 lay->addWidget( mWriteToSim ); 189 // lay->addWidget( mWriteToSim );
190 lay->addWidget(lab = new QLabel( i18n("NOTE: This will remove all old\ncontact data on phone!"), this ) ); 190 lay->addWidget(lab = new QLabel( i18n("NOTE: This will remove all old\ncontact data on phone!"), this ) );
191 lab->setAlignment (AlignHCenter ); 191 lab->setAlignment (AlignHCenter );
192 QPushButton * ok = new QPushButton( i18n("Export to mobile phone!"), this ); 192 QPushButton * ok = new QPushButton( i18n("Export to mobile phone!"), this );
@@ -694,74 +694,19 @@ void KABCore::export2phone()
694 return; 694 return;
695 695
696#ifdef _WIN32_ 696#ifdef _WIN32_
697 QString fileName = locateLocal("tmp", "tempfile.vcf"); 697 QString fileName = locateLocal("tmp", "phonefile.vcf");
698#else 698#else
699 QString fileName = "/tmp/kdepimtemp.vcf"; 699 QString fileName = "/tmp/phonefile.vcf";
700#endif 700#endif
701 701
702 KABC::VCardConverter converter; 702 if ( ! mAddressBook->export2PhoneFormat( uids ,fileName ) )
703 QString description;
704 QString datastream;
705 for( QStringList::ConstIterator it = uids.begin(); it != uids.end(); ++it ) {
706 KABC::Addressee a = mAddressBook->findByUid( *it );
707
708 if ( a.isEmpty() )
709 continue;
710 a.simplifyEmails();
711 a.simplifyPhoneNumbers();
712 a.simplifyPhoneNumberTypes();
713 a.simplifyAddresses();
714
715 if (description.isEmpty())
716 description = a.formattedName();
717 QString vcard;
718 QString vcardnew;
719 converter.addresseeToVCard( a, vcard );
720 int start = 0;
721 int next;
722 while ( (next = vcard.find("TYPE=", start) )>= 0 ) {
723 int semi = vcard.find(";", next);
724 int dopp = vcard.find(":", next);
725 int sep;
726 if ( semi < dopp && semi >= 0 )
727 sep = semi ;
728 else
729 sep = dopp;
730 vcardnew +=vcard.mid( start, next - start);
731 vcardnew +=vcard.mid( next+5,sep -next -5 ).upper();
732 start = sep;
733 }
734 vcardnew += vcard.mid( start,vcard.length() );
735 vcard = "";
736 start = 0;
737 while ( (next = vcardnew.find("ADR", start) )>= 0 ) {
738 int sep = vcardnew.find(":", next);
739 vcard +=vcardnew.mid( start, next - start+3);
740 start = sep;
741 }
742 vcard += vcardnew.mid( start,vcardnew.length() );
743 vcard.replace ( QRegExp(";;;") , "" );
744 vcard.replace ( QRegExp(";;") , "" );
745 datastream += vcard;
746
747 }
748 QFile outFile(fileName);
749 if ( outFile.open(IO_WriteOnly) ) {
750 datastream.replace ( QRegExp("VERSION:3.0") , "VERSION:2.1" );
751 QTextStream t( &outFile ); // use a text stream
752 t.setEncoding( QTextStream::UnicodeUTF8 );
753 t <<datastream;
754 outFile.close();
755 if ( PhoneAccess::writeToPhone( fileName ) )
756 qDebug("Export okay ");
757 else
758 qDebug("Error export contacts ");
759
760 } else {
761 qDebug("Error open temp file ");
762 return; 703 return;
763 } 704
764 705 if ( PhoneAccess::writeToPhone( fileName ) )
706 qDebug("Export okay ");
707 else
708 qDebug("Error export contacts ");
709
765 710
766#if 0 711#if 0
767 712
@@ -2843,6 +2788,7 @@ bool KABCore::syncExternal(KSyncManager* manager, QString resource)
2843 syncOK = synchronizeAddressbooks( mAddressBook, &abLocal, syncManager->mSyncAlgoPrefs ); 2788 syncOK = synchronizeAddressbooks( mAddressBook, &abLocal, syncManager->mSyncAlgoPrefs );
2844 if ( syncOK ) { 2789 if ( syncOK ) {
2845 if ( syncManager->mWriteBackFile ) { 2790 if ( syncManager->mWriteBackFile ) {
2791 abLocal.removeSyncAddressees( false );
2846 abLocal.saveAB(); 2792 abLocal.saveAB();
2847 abLocal.postExternSync( mAddressBook,mCurrentSyncDevice ); 2793 abLocal.postExternSync( mAddressBook,mCurrentSyncDevice );
2848 } 2794 }
@@ -2875,7 +2821,8 @@ bool KABCore::syncPhone()
2875 } 2821 }
2876 AddressBook abLocal( fileName,"syncContact"); 2822 AddressBook abLocal( fileName,"syncContact");
2877 bool syncOK = false; 2823 bool syncOK = false;
2878 if ( abLocal.load() ) { 2824 {
2825 abLocal.importFromFile( fileName );
2879 qDebug("AB phone loaded ,sync device %s",mCurrentSyncDevice.latin1()); 2826 qDebug("AB phone loaded ,sync device %s",mCurrentSyncDevice.latin1());
2880 mGlobalSyncMode = SYNC_MODE_EXTERNAL; 2827 mGlobalSyncMode = SYNC_MODE_EXTERNAL;
2881 abLocal.preparePhoneSync( mCurrentSyncDevice, true ); 2828 abLocal.preparePhoneSync( mCurrentSyncDevice, true );
@@ -2883,9 +2830,10 @@ bool KABCore::syncPhone()
2883 syncOK = synchronizeAddressbooks( mAddressBook, &abLocal, syncManager->mSyncAlgoPrefs ); 2830 syncOK = synchronizeAddressbooks( mAddressBook, &abLocal, syncManager->mSyncAlgoPrefs );
2884 if ( syncOK ) { 2831 if ( syncOK ) {
2885 if ( syncManager->mWriteBackFile ) { 2832 if ( syncManager->mWriteBackFile ) {
2833 abLocal.removeSyncAddressees( true );
2886 abLocal.saveABphone( fileName ); 2834 abLocal.saveABphone( fileName );
2887 abLocal.preparePhoneSync( mCurrentSyncDevice, false ); 2835 abLocal.findNewExtIds( fileName, mCurrentSyncDevice );
2888 abLocal.preExternSync( mAddressBook ,mCurrentSyncDevice ); 2836 //abLocal.preparePhoneSync( mCurrentSyncDevice, false );
2889 abLocal.postExternSync( mAddressBook,mCurrentSyncDevice ); 2837 abLocal.postExternSync( mAddressBook,mCurrentSyncDevice );
2890 } 2838 }
2891 } 2839 }
diff --git a/libkdepim/ksyncprefsdialog.cpp b/libkdepim/ksyncprefsdialog.cpp
index 84cc448..cf8f996 100644
--- a/libkdepim/ksyncprefsdialog.cpp
+++ b/libkdepim/ksyncprefsdialog.cpp
@@ -200,7 +200,7 @@ void KSyncPrefsDialog::setupSyncAlgTab()
200 phoneWidget = new QVBox( topFrame); 200 phoneWidget = new QVBox( topFrame);
201 topLayout->addMultiCellWidget(phoneWidget, iii,iii,0,1); 201 topLayout->addMultiCellWidget(phoneWidget, iii,iii,0,1);
202 ++iii; 202 ++iii;
203 mWriteContactToSIM= new QCheckBox( i18n("Sync contacts with phone SIM card (If not, sync with phone memory)"), phoneWidget ); 203 mWriteContactToSIM = 0;//new QCheckBox( i18n("Sync contacts with phone SIM card (If not, sync with phone memory)"), phoneWidget );
204 QHBox* temphb = new QHBox( phoneWidget ); 204 QHBox* temphb = new QHBox( phoneWidget );
205 new QLabel( i18n("I/O device: "), temphb ); 205 new QLabel( i18n("I/O device: "), temphb );
206 mPhoneDevice = new QLineEdit( temphb); 206 mPhoneDevice = new QLineEdit( temphb);
@@ -413,7 +413,8 @@ void KSyncPrefsDialog::profileChanged( int item )
413 mLocalTempFilePWM->setText(prof->getLocalTempFilePWM()); 413 mLocalTempFilePWM->setText(prof->getLocalTempFilePWM());
414 mRemoteFilePWM->setText(prof->getRemoteFileNamePWM()) ; 414 mRemoteFilePWM->setText(prof->getRemoteFileNamePWM()) ;
415 415
416 mWriteContactToSIM->setChecked( prof->getWriteContactToSIM()); 416 if ( mWriteContactToSIM )
417 mWriteContactToSIM->setChecked( prof->getWriteContactToSIM());
417 mPhoneDevice->setText(prof->getPhoneDevice()); 418 mPhoneDevice->setText(prof->getPhoneDevice());
418 mPhoneConnection->setText(prof->getPhoneConnection()); 419 mPhoneConnection->setText(prof->getPhoneConnection());
419 mPhoneModel->setText(prof->getPhoneModel()); 420 mPhoneModel->setText(prof->getPhoneModel());
@@ -580,8 +581,8 @@ void KSyncPrefsDialog::saveProfile()
580 prof->setIsPiSync( mIsPi->isChecked() ); 581 prof->setIsPiSync( mIsPi->isChecked() );
581 prof->setWriteBackFuture(mWriteBackFuture->isChecked()); 582 prof->setWriteBackFuture(mWriteBackFuture->isChecked());
582 prof->setWriteBackFutureWeeks(mWriteBackFutureWeeks->value()); 583 prof->setWriteBackFutureWeeks(mWriteBackFutureWeeks->value());
583 584 if ( mWriteContactToSIM )
584 prof->setWriteContactToSIM(mWriteContactToSIM->isChecked()); 585 prof->setWriteContactToSIM(mWriteContactToSIM->isChecked());
585 prof->setPhoneDevice( mPhoneDevice->text() ); 586 prof->setPhoneDevice( mPhoneDevice->text() );
586 prof->setPhoneConnection( mPhoneConnection->text() ); 587 prof->setPhoneConnection( mPhoneConnection->text() );
587 prof->setPhoneModel( mPhoneModel->text() ); 588 prof->setPhoneModel( mPhoneModel->text() );
@@ -715,7 +716,7 @@ void KSyncPrefsDialog::helpDevice()
715} 716}
716void KSyncPrefsDialog::helpModel() 717void KSyncPrefsDialog::helpModel()
717{ 718{
718 QString hint = i18n("Leave empty or\ninsert name of phone model:\n"); 719 QString hint = i18n("Recommended: Leave empty!\n(Such that model can\nbe auto detected)\nOr insert name of model:\n");
719 hint += "E.g. for Nokia 6310i:\n6310i\nAlso possible:\nobex\nfor Obex connection"; 720 hint += "E.g. for Nokia 6310i:\n6310i\nAlso possible:\nobex\nfor Obex connection";
720 KMessageBox::information(this,hint,i18n("KDE-Pim sync config")); 721 KMessageBox::information(this,hint,i18n("KDE-Pim sync config"));
721 722