-rw-r--r-- | kabc/addressbook.cpp | 3 |
1 files changed, 2 insertions, 1 deletions
diff --git a/kabc/addressbook.cpp b/kabc/addressbook.cpp index c584c35..3641c0c 100644 --- a/kabc/addressbook.cpp +++ b/kabc/addressbook.cpp @@ -448,97 +448,98 @@ bool AddressBook::export2PhoneFormat( QStringList uids ,QString fileName ) } 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; t << "\r\n\r\n"; outFile.close(); } else { qDebug("Error open temp file "); return false; } return true; } -void AddressBook::importFromFile( QString fileName, bool replaceLabel, bool removeOld ) +int AddressBook::importFromFile( QString fileName, bool replaceLabel, bool removeOld ) { if ( removeOld ) setUntagged( true ); 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; for ( it = list.begin(); it != list.end(); ++it ) { QString id = (*it).custom( "KADDRESSBOOK", "X-ExternalID" ); if ( !id.isEmpty() ) (*it).setIDStr(id ); (*it).setResource( 0 ); 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) { Iterator ait; 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 ); } } 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(); } |