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 --- (limited to 'kaddressbook') 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 ); } } -- cgit v0.9.0.2