author | zautrix <zautrix> | 2004-10-10 16:00:04 (UTC) |
---|---|---|
committer | zautrix <zautrix> | 2004-10-10 16:00:04 (UTC) |
commit | ee6e29a5092d32165b7bf6b39069bd8a1dcd5b0a (patch) (side-by-side diff) | |
tree | 1d908bfc23b8a49d43a58bbeadd82c4e08faeff6 /kaddressbook/kabcore.cpp | |
parent | 213a9d993e5a4751b64e18320cfbebb000681d13 (diff) | |
download | kdepimpi-ee6e29a5092d32165b7bf6b39069bd8a1dcd5b0a.zip kdepimpi-ee6e29a5092d32165b7bf6b39069bd8a1dcd5b0a.tar.gz kdepimpi-ee6e29a5092d32165b7bf6b39069bd8a1dcd5b0a.tar.bz2 |
many phone AB sync fixes
-rw-r--r-- | kaddressbook/kabcore.cpp | 86 |
1 files changed, 17 insertions, 69 deletions
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 <<datastream; - outFile.close(); - if ( PhoneAccess::writeToPhone( fileName ) ) - qDebug("Export okay "); - else - qDebug("Error export contacts "); - - } else { - qDebug("Error open temp file "); + if ( ! mAddressBook->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 ); } } |