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 | |
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 | 76 |
1 files changed, 12 insertions, 64 deletions
diff --git a/kaddressbook/kabcore.cpp b/kaddressbook/kabcore.cpp index a7967cb..cd261f6 100644 --- a/kaddressbook/kabcore.cpp +++ b/kaddressbook/kabcore.cpp @@ -182,14 +182,14 @@ class KAex2phonePrefs : public QDialog mPhoneConnection = new QLineEdit( temphb); lay->addWidget( temphb ); temphb = new QHBox( this ); 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 ); lay->addWidget( ok ); QPushButton * cancel = new QPushButton( i18n("Cancel"), this ); lay->addWidget( cancel ); @@ -691,80 +691,25 @@ void KABCore::export2phone() QStringList uids = mViewManager->selectedUids(); if ( uids.isEmpty() ) 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; + if ( ! mAddressBook->export2PhoneFormat( uids ,fileName ) ) + return; - } - 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 "); - return; - } - #if 0 setCaption( i18n("Writing to phone...")); if ( PhoneFormat::writeToPhone( cal ) ) setCaption( i18n("Export to phone successful!")); @@ -2840,12 +2785,13 @@ bool KABCore::syncExternal(KSyncManager* manager, QString resource) qDebug("AB sharp loaded ,sync device %s",mCurrentSyncDevice.latin1()); mGlobalSyncMode = SYNC_MODE_EXTERNAL; abLocal.preExternSync( mAddressBook ,mCurrentSyncDevice ); syncOK = synchronizeAddressbooks( mAddressBook, &abLocal, syncManager->mSyncAlgoPrefs ); if ( syncOK ) { if ( syncManager->mWriteBackFile ) { + abLocal.removeSyncAddressees( false ); abLocal.saveAB(); abLocal.postExternSync( mAddressBook,mCurrentSyncDevice ); } } setModified(); } @@ -2872,23 +2818,25 @@ bool KABCore::syncPhone() if ( !PhoneAccess::readFromPhone( fileName) ) { message(i18n("Phone access failed!")); return false; } 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 ); abLocal.preExternSync( mAddressBook ,mCurrentSyncDevice ); 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 ); } } setModified(); } if ( syncOK ) |