-rw-r--r-- | kabc/addressbook.cpp | 14 |
1 files changed, 11 insertions, 3 deletions
diff --git a/kabc/addressbook.cpp b/kabc/addressbook.cpp index dc3cda1..bf6d053 100644 --- a/kabc/addressbook.cpp +++ b/kabc/addressbook.cpp @@ -373,80 +373,88 @@ bool AddressBook::save( Ticket *ticket ) return ticket->resource()->save( ticket ); } return false; } void AddressBook::export2File( QString fileName ) { QFile outFile( fileName ); if ( !outFile.open( IO_WriteOnly ) ) { QString text = i18n( "<qt>Unable to open file <b>%1</b> for export.</qt>" ); KMessageBox::error( 0, text.arg( fileName ) ); return ; } QTextStream t( &outFile ); t.setEncoding( QTextStream::UnicodeUTF8 ); Iterator it; KABC::VCardConverter::Version version; version = KABC::VCardConverter::v3_0; for ( it = begin(); it != end(); ++it ) { if ( !(*it).IDStr().isEmpty() ) { (*it).insertCustom( "KADDRESSBOOK", "X-ExternalID", (*it).IDStr() ); } KABC::VCardConverter converter; QString vcard; //Resource *resource() const; converter.addresseeToVCard( *it, vcard, version ); t << vcard << "\r\n"; } t << "\r\n\r\n"; outFile.close(); } -void AddressBook::importFromFile( QString fileName ) +void AddressBook::importFromFile( QString fileName, bool replaceLabel ) { KABC::Addressee::List list; QFile file( fileName ); file.open( IO_ReadOnly ); QByteArray rawData = file.readAll(); file.close(); - - QString data = QString::fromUtf8( rawData.data(), rawData.size() + 1 ); + qDebug("AddressBook::importFromFile "); + 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 ) { (*it).setResource( 0 ); + if ( replaceLabel ) + (*it).removeVoice(); insertAddressee( (*it), false, true ); } } bool AddressBook::saveAB() { bool ok = true; deleteRemovedAddressees(); Iterator ait; for ( ait = begin(); ait != end(); ++ait ) { if ( !(*ait).IDStr().isEmpty() ) { (*ait).insertCustom( "KADDRESSBOOK", "X-ExternalID", (*ait).IDStr() ); } } KRES::Manager<Resource>::ActiveIterator it; KRES::Manager<Resource> *manager = d->mManager; for ( it = manager->activeBegin(); it != manager->activeEnd(); ++it ) { if ( !(*it)->readOnly() && (*it)->isOpen() ) { Ticket *ticket = requestSaveTicket( *it ); // qDebug("StdAddressBook::save '%s'", (*it)->resourceName().latin1() ); if ( !ticket ) { error( i18n( "Unable to save to resource '%1'. It is locked." ) .arg( (*it)->resourceName() ) ); return false; } //if ( !save( ticket ) ) if ( ticket->resource() ) { if ( ! ticket->resource()->save( ticket ) ) ok = false; |