-rw-r--r-- | kaddressbook/kabcore.cpp | 52 |
1 files changed, 32 insertions, 20 deletions
diff --git a/kaddressbook/kabcore.cpp b/kaddressbook/kabcore.cpp index 6538295..d1d385c 100644 --- a/kaddressbook/kabcore.cpp +++ b/kaddressbook/kabcore.cpp @@ -597,130 +597,142 @@ void KABCore::beamVCard(const QStringList& uids) /*US QString beamFilename; Opie::OPimContact c; if ( actionPersonal->isOn() ) { beamFilename = addressbookPersonalVCardName(); if ( !QFile::exists( beamFilename ) ) return; // can't beam a non-existent file Opie::OPimContactAccessBackend* vcard_backend = new Opie::OPimContactAccessBackend_VCard( QString::null, beamFilename ); Opie::OPimContactAccess* access = new Opie::OPimContactAccess ( "addressbook", QString::null , vcard_backend, true ); Opie::OPimContactAccess::List allList = access->allRecords(); Opie::OPimContactAccess::List::Iterator it = allList.begin(); // Just take first c = *it; delete access; } else { unlink( beamfile ); // delete if exists mkdir("/tmp/obex/", 0755); c = m_abView -> currentEntry(); Opie::OPimContactAccessBackend* vcard_backend = new Opie::OPimContactAccessBackend_VCard( QString::null, beamfile ); Opie::OPimContactAccess* access = new Opie::OPimContactAccess ( "addressbook", QString::null , vcard_backend, true ); access->add( c ); access->save(); delete access; beamFilename = beamfile; } owarn << "Beaming: " << beamFilename << oendl; */ #if 0 QString tmpdir = locateLocal("tmp", KGlobal::getAppName()); QString dirName = tmpdir + "/" + KApplication::randomString( 8 ); QString name = "contact.vcf"; QString fileName = dirName + "/" + name; #endif // LR: we should use the /tmp dir, because: /tmp = RAM, (HOME)/kdepim = flash memory // QString fileName = "/tmp/kapibeamfile.vcf"; //QDir().mkdir( dirName, true ); - QFile outFile(fileName); + KABC::VCardConverter converter; QString description; - - if ( outFile.open(IO_WriteOnly) ) { // file opened successfully - - QTextStream t( &outFile ); // use a text stream - t.setEncoding( QTextStream::UnicodeUTF8 ); - - for( QStringList::ConstIterator it = uids.begin(); it != uids.end(); ++it ) { + QString datastream; + for( QStringList::ConstIterator it = uids.begin(); it != uids.end(); ++it ) { KABC::Addressee a = mAddressBook->findByUid( *it ); if ( a.isEmpty() ) - continue; + continue; if (description.isEmpty()) - description = a.formattedName(); + description = a.formattedName(); QString vcard; converter.addresseeToVCard( a, vcard ); - t << 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; + datastream +=vcard.mid( start, next - start); + datastream +=vcard.mid( next+5,sep -next -5 ).upper(); + start = sep; + } + datastream += vcard.mid( start,vcard.length() ); + } +#ifndef DESKTOP_VERSION + 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(); + Ir *ir = new Ir( this ); + connect( ir, SIGNAL( done(Ir*) ), this, SLOT( beamDone(Ir*) ) ); + ir->send( fileName, description, "text/x-vCard" ); } else { qDebug("Error open temp beam file "); return; } - - outFile.close(); - -#ifndef DESKTOP_VERSION - Ir *ir = new Ir( this ); - connect( ir, SIGNAL( done(Ir*) ), this, SLOT( beamDone(Ir*) ) ); - ir->send( fileName, description, "text/x-vCard" ); #endif } void KABCore::beamDone( Ir *ir ) { #ifndef DESKTOP_VERSION delete ir; #endif } void KABCore::browse( const QString& url ) { #ifndef KAB_EMBEDDED kapp->invokeBrowser( url ); #else //KAB_EMBEDDED qDebug("KABCore::browse must be fixed"); #endif //KAB_EMBEDDED } void KABCore::selectAllContacts() { mViewManager->setSelected( QString::null, true ); } void KABCore::deleteContacts() { QStringList uidList = mViewManager->selectedUids(); deleteContacts( uidList ); } void KABCore::deleteContacts( const QStringList &uids ) { if ( uids.count() > 0 ) { PwDeleteCommand *command = new PwDeleteCommand( mAddressBook, uids ); UndoStack::instance()->push( command ); RedoStack::instance()->clear(); // now if we deleted anything, refresh setContactSelected( QString::null ); setModified( true ); } } void KABCore::copyContacts() { KABC::Addressee::List addrList = mViewManager->selectedAddressees(); |