author | zautrix <zautrix> | 2005-12-02 09:42:53 (UTC) |
---|---|---|
committer | zautrix <zautrix> | 2005-12-02 09:42:53 (UTC) |
commit | a75d2c26aba6cffae8c3f61e173940240042427b (patch) (side-by-side diff) | |
tree | 68f4b61c150bc263a98c78fdf8671bbbc17cdaf8 /kabc/addressbook.cpp | |
parent | 64be8d64fc26d1025a24150d065197ba5d608f3d (diff) | |
download | kdepimpi-a75d2c26aba6cffae8c3f61e173940240042427b.zip kdepimpi-a75d2c26aba6cffae8c3f61e173940240042427b.tar.gz kdepimpi-a75d2c26aba6cffae8c3f61e173940240042427b.tar.bz2 |
more sync
-rw-r--r-- | kabc/addressbook.cpp | 42 |
1 files changed, 33 insertions, 9 deletions
diff --git a/kabc/addressbook.cpp b/kabc/addressbook.cpp index e04f4b1..bdc2762 100644 --- a/kabc/addressbook.cpp +++ b/kabc/addressbook.cpp @@ -462,94 +462,118 @@ bool AddressBook::export2PhoneFormat( QStringList uids ,QString fileName ) } 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; t << "\r\n\r\n"; outFile.close(); } else { qDebug("Error open temp file "); return false; } return true; } -int AddressBook::importFromFile( QString fileName, bool replaceLabel, bool removeOld ) +int AddressBook::importFromFile( QString fileName, bool replaceLabel, bool removeOld, QString resource ) { if ( removeOld ) - setUntagged( true ); + setUntagged( true, resource ); KABC::Addressee::List list; QFile file( fileName ); file.open( IO_ReadOnly ); QByteArray rawData = file.readAll(); file.close(); QString data; if ( replaceLabel ) { data = QString::fromLatin1( rawData.data(), rawData.size() + 1 ); data.replace ( QRegExp("LABEL") , "ADR" ); data.replace ( QRegExp("CHARSET=ISO-8859-1") , "" ); } else data = QString::fromUtf8( rawData.data(), rawData.size() + 1 ); KABC::VCardTool tool; list = tool.parseVCards( data ); KABC::Addressee::List::Iterator it; + + Resource * setRes = 0; + if ( !resource.isEmpty() ) { + KRES::Manager<Resource>::ActiveIterator it; + KRES::Manager<Resource> *manager = d->mManager; + for ( it = manager->activeBegin(); it != manager->activeEnd(); ++it ) { + qDebug("SaveAB::checking resource..." ); + if ( (*it)->name() == resource ) { + setRes = (*it); + qDebug("Inserting imported contacs to resource %s", resource.latin1()); + break; + } + } + } for ( it = list.begin(); it != list.end(); ++it ) { QString id = (*it).custom( "KADDRESSBOOK", "X-ExternalID" ); if ( !id.isEmpty() ) (*it).setIDStr(id ); - (*it).setResource( 0 ); + (*it).setResource( setRes ); if ( replaceLabel ) (*it).removeVoice(); if ( removeOld ) (*it).setTagged( true ); insertAddressee( (*it), false, true ); } if ( removeOld ) removeUntagged(); return list.count(); } -void AddressBook::setUntagged(bool setNonSyncTagged) // = false) +void AddressBook::setUntagged(bool setNonSyncTagged, QString resource) // = false , "") { Iterator ait; - for ( ait = begin(); ait != end(); ++ait ) { - if ( setNonSyncTagged ) { - if ( (*ait).resource() && ! (*ait).resource()->includeInSync() ) { + if ( !resource.isEmpty() ) { + for ( ait = begin(); ait != end(); ++ait ) { + if ( (*ait).resource() && (*ait).resource()->name() == resource ) { + (*ait).setTagged( false ); + } + else (*ait).setTagged( true ); + } + } else { + for ( ait = begin(); ait != end(); ++ait ) { + if ( setNonSyncTagged ) { + if ( (*ait).resource() && ! (*ait).resource()->includeInSync() ) { + (*ait).setTagged( true ); + } else + (*ait).setTagged( false ); } else (*ait).setTagged( false ); - } else - (*ait).setTagged( false ); + } } } void AddressBook::removeUntagged() { Iterator ait; bool todelete = false; Iterator todel; for ( ait = begin(); ait != end(); ++ait ) { if ( todelete ) removeAddressee( todel ); if (!(*ait).tagged()) { todelete = true; todel = ait; } else todelete = false; } if ( todelete ) removeAddressee( todel ); deleteRemovedAddressees(); } void AddressBook::smplifyAddressees() { Iterator ait; for ( ait = begin(); ait != end(); ++ait ) { |