From ee6e29a5092d32165b7bf6b39069bd8a1dcd5b0a Mon Sep 17 00:00:00 2001 From: zautrix Date: Sun, 10 Oct 2004 16:00:04 +0000 Subject: many phone AB sync fixes --- 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) char buffer[1000]; if (UnicodeLength(Text) != 0) { - EncodeUTF8QuotedPrintable(buffer,Text); + EncodeUTF8(buffer,Text); if (UnicodeLength(Text)==strlen(buffer)) { *Length+=sprintf(Buffer+(*Length), "%s:%s%c%c",Start,DecodeUnicodeString(Text),13,10); } else { - *Length+=sprintf(Buffer+(*Length), "%s;CHARSET=UTF-8;ENCODING=QUOTED-PRINTABLE:%s%c%c",Start,buffer,13,10); + *Length+=sprintf(Buffer+(*Length), "%s:%s%c%c",Start,buffer,13,10); } } } 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 break; case PBK_Number_General : *Length+=sprintf(Buffer+(*Length),"TEL"); - if (Number == i) (*Length)+=sprintf(Buffer+(*Length),";PREF"); + (*Length)+=sprintf(Buffer+(*Length),";PREF"); break; case PBK_Number_Mobile : *Length+=sprintf(Buffer+(*Length),"TEL"); - if (Number == i) (*Length)+=sprintf(Buffer+(*Length),";PREF"); + //if (Number == i) (*Length)+=sprintf(Buffer+(*Length),";PREF"); *Length+=sprintf(Buffer+(*Length),";CELL"); break; case PBK_Number_Work : *Length+=sprintf(Buffer+(*Length),"TEL"); - if (Number == i) (*Length)+=sprintf(Buffer+(*Length),";PREF"); - *Length+=sprintf(Buffer+(*Length),";WORK;VOICE"); + //if (Number == i) (*Length)+=sprintf(Buffer+(*Length),";PREF"); + *Length+=sprintf(Buffer+(*Length),";WORK"); break; case PBK_Number_Fax : *Length+=sprintf(Buffer+(*Length),"TEL"); - if (Number == i) (*Length)+=sprintf(Buffer+(*Length),";PREF"); + //if (Number == i) (*Length)+=sprintf(Buffer+(*Length),";PREF"); *Length+=sprintf(Buffer+(*Length),";FAX"); break; case PBK_Number_Home : *Length+=sprintf(Buffer+(*Length),"TEL"); - if (Number == i) (*Length)+=sprintf(Buffer+(*Length),";PREF"); - *Length+=sprintf(Buffer+(*Length),";HOME;VOICE"); + //if (Number == i) (*Length)+=sprintf(Buffer+(*Length),";PREF"); + *Length+=sprintf(Buffer+(*Length),";HOME"); break; case PBK_Text_Note : *Length+=sprintf(Buffer+(*Length),"NOTE"); @@ -160,7 +160,7 @@ void GSM_EncodeVCARD(char *Buffer, int *Length, GSM_MemoryEntry *pbk, bool heade /* Don't ask why. Nokia phones save postal address * double - once like LABEL, second like ADR */ - SaveVCALText(Buffer, Length, pbk->Entries[i].Text, "LABEL"); + //SaveVCALText(Buffer, Length, pbk->Entries[i].Text, "LABEL"); *Length+=sprintf(Buffer+(*Length),"ADR"); break; case PBK_Text_Email : @@ -179,6 +179,7 @@ void GSM_EncodeVCARD(char *Buffer, int *Length, GSM_MemoryEntry *pbk, bool heade } } } + *Length+=sprintf(Buffer+(*Length), "X-KADDRESSBOOK-X-ExternalID:%d%c%c",pbk->Location,13,10); if (header) *Length+=sprintf(Buffer+(*Length),"END:VCARD%c%c",13,10); } } 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[]) max = 0; while (Backup.PhonePhonebook[max]!=NULL) max++; printmsgerr("%i entries in backup file\n",max); - if (answer_yes("Restore phone phonebook")) DoRestore = true; + /* LR if (answer_yes("Restore phone phonebook")) */DoRestore = true; } } 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() bool AddressBook::load() { - clear(); - KRES::Manager::ActiveIterator it; bool ok = true; for ( it = d->mManager->activeBegin(); it != d->mManager->activeEnd(); ++it ) if ( !(*it)->load() ) { - error( i18n("Unable to load resource '%1'").arg( (*it)->resourceName() ) ); + qDebug( i18n("Unable to load resource '%1'").arg( (*it)->resourceName() ) ); ok = false; + } else { + qDebug( i18n("Resource loaded: '%1'").arg( (*it)->resourceName() ) ); } - // mark all addressees as unchanged Addressee::List::Iterator addrIt; for ( addrIt = d->mAddressees.begin(); addrIt != d->mAddressees.end(); ++addrIt ) { @@ -404,6 +403,75 @@ void AddressBook::export2File( QString fileName ) t << "\r\n\r\n"; outFile.close(); } +// if QStringList uids is empty, all are exported +bool AddressBook::export2PhoneFormat( QStringList uids ,QString fileName ) +{ + KABC::VCardConverter converter; + QString datastream; + Iterator it; + bool all = uids.isEmpty(); + for ( it = begin(); it != end(); ++it ) { + // for( QStringList::ConstIterator it = uids.begin(); it != uids.end(); ++it ) { + if ( ! all ) { + if ( ! ( uids.contains((*it).uid() ) )) + continue; + } + KABC::Addressee a = ( *it ); + if ( a.isEmpty() ) + continue; + a.simplifyEmails(); + a.simplifyPhoneNumbers(); + a.simplifyPhoneNumberTypes(); + a.simplifyAddresses(); + + QString vcard; + QString vcardnew; + converter.addresseeToVCard( a, vcard ); + int start = 0; + int next; + while ( (next = vcard.find("TYPE=", start) )>= 0 ) { + int semi = vcard.find(";", next); + int dopp = vcard.find(":", next); + int sep; + if ( semi < dopp && semi >= 0 ) + sep = semi ; + else + sep = dopp; + vcardnew +=vcard.mid( start, next - start); + vcardnew +=vcard.mid( next+5,sep -next -5 ).upper(); + start = sep; + } + vcardnew += vcard.mid( start,vcard.length() ); + vcard = ""; + start = 0; + while ( (next = vcardnew.find("ADR", start) )>= 0 ) { + int sep = vcardnew.find(":", next); + vcard +=vcardnew.mid( start, next - start+3); + start = sep; + } + vcard += vcardnew.mid( start,vcardnew.length() ); + vcard.replace ( QRegExp(";;;") , "" ); + vcard.replace ( QRegExp(";;") , "" ); + datastream += vcard; + + } + + QFile outFile(fileName); + if ( outFile.open(IO_WriteOnly) ) { + datastream.replace ( QRegExp("VERSION:3.0") , "VERSION:2.1" ); + QTextStream t( &outFile ); // use a text stream + t.setEncoding( QTextStream::UnicodeUTF8 ); + t <::ActiveIterator it; KRES::Manager *manager = d->mManager; + qDebug("SaveAB::saving..." ); for ( it = manager->activeBegin(); it != manager->activeEnd(); ++it ) { + qDebug("SaveAB::checking resource..." ); + if ( (*it)->readOnly() ) + qDebug("readonly." ); + if ( (*it)->isOpen() ) + qDebug("open" ); + if ( !(*it)->readOnly() && (*it)->isOpen() ) { Ticket *ticket = requestSaveTicket( *it ); -// qDebug("StdAddressBook::save '%s'", (*it)->resourceName().latin1() ); + qDebug("StdAddressBook::save '%s'", (*it)->resourceName().latin1() ); if ( !ticket ) { - error( i18n( "Unable to save to resource '%1'. It is locked." ) + qDebug( i18n( "Unable to save to resource '%1'. It is locked." ) .arg( (*it)->resourceName() ) ); return false; } @@ -530,6 +649,9 @@ bool AddressBook::saveAB() if ( ticket->resource() ) { if ( ! ticket->resource()->save( ticket ) ) ok = false; + else + qDebug("StdAddressBook::saved '%s'", ticket->resource()->resourceName().latin1() ); + } else ok = false; @@ -593,7 +715,7 @@ Ticket *AddressBook::requestSaveTicket( Resource *resource ) return 0; } - +//void insertAddressee( const Addressee &, bool setRev = true, bool takeResource = false); void AddressBook::insertAddressee( const Addressee &a, bool setRev, bool takeResource ) { 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 void smplifyAddressees(); void preparePhoneSync( QString currentSyncDevice, bool isPreSync ); void export2File( QString fileName ); + bool export2PhoneFormat( QStringList uids ,QString fileName ); void importFromFile( QString fileName, bool replaceLabel = false, bool removeOld = false ); void setUntagged(); void removeUntagged(); + void findNewExtIds( QString fileName, QString currentSyncDevice ); /** Returns a iterator for first entry of address book. */ 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 ) if ( mData->sortString.isEmpty() ) mData->sortString = ad.mData->sortString; if ( !mData->secrecy.isValid() ) mData->secrecy = ad.mData->secrecy; if ( ( !mData->url.isValid() && ad.mData->url.isValid() ) ) mData->url = ad.mData->url ; + PhoneNumber::List phoneAD = phoneNumbers(); + PhoneNumber::List::Iterator phoneItAD; + bool found = false; + for ( phoneItAD = phoneAD.begin(); phoneItAD != phoneAD.end(); ++phoneItAD ) { + + } // pending: // merging phonenumbers // merging addresses @@ -311,7 +317,7 @@ void Addressee::mergeContact( const Addressee& ad ) // merging categories; // merging custom; // merging keys - qDebug("merge contact %s ", ad.uid().latin1()); + //qDebug("merge contact %s ", ad.uid().latin1()); setUid( ad.uid() ); setRevision( ad.revision() ); } @@ -333,14 +339,48 @@ bool Addressee::removeVoice() } return found; } + +bool Addressee::containsAdr(const Addressee& ad ) +{ + if ( ! ad.mData->familyName.isEmpty() ) if ( mData->familyName != ad.mData->familyName) return false; + if ( ! ad.mData->givenName.isEmpty() )if ( mData->givenName != ad.mData->givenName ) return false; + if ( ad.mData->url.isValid() ) if (mData->url != ad.mData->url) return false ; + if ( ! ad.mData->role.isEmpty() ) if (mData->role != ad.mData->role) return false ; + if ( ! ad.mData->organization.isEmpty() ) if (mData->organization != ad.mData->organization) return false ; + if ( ! ad.mData->note.isEmpty() ) if (mData->note != ad.mData->note) return false ; + if ( ! ad.mData->title .isEmpty() ) if (mData->title != ad.mData->title ) return false ; + + // compare phone numbers + PhoneNumber::List phoneN = ad.phoneNumbers(); + PhoneNumber::List::Iterator phoneIt; + bool found = false; + for ( phoneIt = phoneN.begin(); phoneIt != phoneN.end(); ++phoneIt ) { + bool found = false; + PhoneNumber::List phoneL = ad.phoneNumbers(); + PhoneNumber::List::Iterator phoneItL; + for ( phoneItL = phoneL.begin(); phoneItL != phoneL.end(); ++phoneItL ) { + if ( ( *phoneItL ).number() == ( *phoneIt ).number() ) { + found = true; + break; + } + } + if ( ! found ) + return false; + } + return true; + +} void Addressee::simplifyAddresses() { - if ( mData->addresses.count() < 3 ) return ; + int max = 2; + if ( mData->url.isValid() ) + max = 1; + if ( mData->addresses.count() <= max ) return ; int count = 0; Address::List list; Address::List::Iterator it; for( it = mData->addresses.begin(); it != mData->addresses.end(); ++it ) { - if ( count > 1 ) + if ( count >= max ) list.append( *it ); ++count; } 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 void simplifyPhoneNumbers(); void simplifyPhoneNumberTypes(); bool removeVoice(); + bool containsAdr(const Addressee& addr ); /** 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() int i; Number = mNumber.stripWhiteSpace (); mNumber = ""; - if ( Number.at(0) == '+' ) - mNumber += "+"; for ( i = 0; i < Number.length(); ++i) { - if ( Number.at(i).isDigit() ) + if ( Number.at(i).isDigit() || Number.at(i) == '+'|| Number.at(i) == '*'|| Number.at(i) == '#' ) mNumber += Number.at(i); } 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 new QLabel( i18n("Model(opt.): "), temphb ); mPhoneModel = new QLineEdit( temphb); lay->addWidget( temphb ); - mWriteToSim= new QCheckBox( i18n("Write Contacts to SIM card\n(if not, write to phone memory)"), this ); - lay->addWidget( mWriteToSim ); + // mWriteToSim = new QCheckBox( i18n("Write Contacts to SIM card\n(if not, write to phone memory)"), this ); + // lay->addWidget( mWriteToSim ); lay->addWidget(lab = new QLabel( i18n("NOTE: This will remove all old\ncontact data on phone!"), this ) ); lab->setAlignment (AlignHCenter ); QPushButton * ok = new QPushButton( i18n("Export to mobile phone!"), this ); @@ -694,74 +694,19 @@ void KABCore::export2phone() return; #ifdef _WIN32_ - QString fileName = locateLocal("tmp", "tempfile.vcf"); + QString fileName = locateLocal("tmp", "phonefile.vcf"); #else - QString fileName = "/tmp/kdepimtemp.vcf"; + QString fileName = "/tmp/phonefile.vcf"; #endif - KABC::VCardConverter converter; - QString description; - QString datastream; - for( QStringList::ConstIterator it = uids.begin(); it != uids.end(); ++it ) { - KABC::Addressee a = mAddressBook->findByUid( *it ); - - if ( a.isEmpty() ) - continue; - a.simplifyEmails(); - a.simplifyPhoneNumbers(); - a.simplifyPhoneNumberTypes(); - a.simplifyAddresses(); - - if (description.isEmpty()) - description = a.formattedName(); - QString vcard; - QString vcardnew; - converter.addresseeToVCard( a, vcard ); - int start = 0; - int next; - while ( (next = vcard.find("TYPE=", start) )>= 0 ) { - int semi = vcard.find(";", next); - int dopp = vcard.find(":", next); - int sep; - if ( semi < dopp && semi >= 0 ) - sep = semi ; - else - sep = dopp; - vcardnew +=vcard.mid( start, next - start); - vcardnew +=vcard.mid( next+5,sep -next -5 ).upper(); - start = sep; - } - vcardnew += vcard.mid( start,vcard.length() ); - vcard = ""; - start = 0; - while ( (next = vcardnew.find("ADR", start) )>= 0 ) { - int sep = vcardnew.find(":", next); - vcard +=vcardnew.mid( start, next - start+3); - start = sep; - } - vcard += vcardnew.mid( start,vcardnew.length() ); - vcard.replace ( QRegExp(";;;") , "" ); - vcard.replace ( QRegExp(";;") , "" ); - datastream += vcard; - - } - QFile outFile(fileName); - if ( outFile.open(IO_WriteOnly) ) { - datastream.replace ( QRegExp("VERSION:3.0") , "VERSION:2.1" ); - QTextStream t( &outFile ); // use a text stream - t.setEncoding( QTextStream::UnicodeUTF8 ); - t <export2PhoneFormat( uids ,fileName ) ) return; - } - + + if ( PhoneAccess::writeToPhone( fileName ) ) + qDebug("Export okay "); + else + qDebug("Error export contacts "); + #if 0 @@ -2843,6 +2788,7 @@ bool KABCore::syncExternal(KSyncManager* manager, QString resource) syncOK = synchronizeAddressbooks( mAddressBook, &abLocal, syncManager->mSyncAlgoPrefs ); if ( syncOK ) { if ( syncManager->mWriteBackFile ) { + abLocal.removeSyncAddressees( false ); abLocal.saveAB(); abLocal.postExternSync( mAddressBook,mCurrentSyncDevice ); } @@ -2875,7 +2821,8 @@ bool KABCore::syncPhone() } AddressBook abLocal( fileName,"syncContact"); bool syncOK = false; - if ( abLocal.load() ) { + { + abLocal.importFromFile( fileName ); qDebug("AB phone loaded ,sync device %s",mCurrentSyncDevice.latin1()); mGlobalSyncMode = SYNC_MODE_EXTERNAL; abLocal.preparePhoneSync( mCurrentSyncDevice, true ); @@ -2883,9 +2830,10 @@ bool KABCore::syncPhone() syncOK = synchronizeAddressbooks( mAddressBook, &abLocal, syncManager->mSyncAlgoPrefs ); if ( syncOK ) { if ( syncManager->mWriteBackFile ) { + abLocal.removeSyncAddressees( true ); abLocal.saveABphone( fileName ); - abLocal.preparePhoneSync( mCurrentSyncDevice, false ); - abLocal.preExternSync( mAddressBook ,mCurrentSyncDevice ); + abLocal.findNewExtIds( fileName, mCurrentSyncDevice ); + //abLocal.preparePhoneSync( mCurrentSyncDevice, false ); abLocal.postExternSync( mAddressBook,mCurrentSyncDevice ); } } 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() phoneWidget = new QVBox( topFrame); topLayout->addMultiCellWidget(phoneWidget, iii,iii,0,1); ++iii; - mWriteContactToSIM= new QCheckBox( i18n("Sync contacts with phone SIM card (If not, sync with phone memory)"), phoneWidget ); + mWriteContactToSIM = 0;//new QCheckBox( i18n("Sync contacts with phone SIM card (If not, sync with phone memory)"), phoneWidget ); QHBox* temphb = new QHBox( phoneWidget ); new QLabel( i18n("I/O device: "), temphb ); mPhoneDevice = new QLineEdit( temphb); @@ -413,7 +413,8 @@ void KSyncPrefsDialog::profileChanged( int item ) mLocalTempFilePWM->setText(prof->getLocalTempFilePWM()); mRemoteFilePWM->setText(prof->getRemoteFileNamePWM()) ; - mWriteContactToSIM->setChecked( prof->getWriteContactToSIM()); + if ( mWriteContactToSIM ) + mWriteContactToSIM->setChecked( prof->getWriteContactToSIM()); mPhoneDevice->setText(prof->getPhoneDevice()); mPhoneConnection->setText(prof->getPhoneConnection()); mPhoneModel->setText(prof->getPhoneModel()); @@ -580,8 +581,8 @@ void KSyncPrefsDialog::saveProfile() prof->setIsPiSync( mIsPi->isChecked() ); prof->setWriteBackFuture(mWriteBackFuture->isChecked()); prof->setWriteBackFutureWeeks(mWriteBackFutureWeeks->value()); - - prof->setWriteContactToSIM(mWriteContactToSIM->isChecked()); + if ( mWriteContactToSIM ) + prof->setWriteContactToSIM(mWriteContactToSIM->isChecked()); prof->setPhoneDevice( mPhoneDevice->text() ); prof->setPhoneConnection( mPhoneConnection->text() ); prof->setPhoneModel( mPhoneModel->text() ); @@ -715,7 +716,7 @@ void KSyncPrefsDialog::helpDevice() } void KSyncPrefsDialog::helpModel() { - QString hint = i18n("Leave empty or\ninsert name of phone model:\n"); + QString hint = i18n("Recommended: Leave empty!\n(Such that model can\nbe auto detected)\nOr insert name of model:\n"); hint += "E.g. for Nokia 6310i:\n6310i\nAlso possible:\nobex\nfor Obex connection"; KMessageBox::information(this,hint,i18n("KDE-Pim sync config")); -- cgit v0.9.0.2