summaryrefslogtreecommitdiffabout
path: root/kabc/addressbook.cpp
Unidiff
Diffstat (limited to 'kabc/addressbook.cpp') (more/less context) (show whitespace changes)
-rw-r--r--kabc/addressbook.cpp64
1 files changed, 61 insertions, 3 deletions
diff --git a/kabc/addressbook.cpp b/kabc/addressbook.cpp
index 5fb49eb..295cf03 100644
--- a/kabc/addressbook.cpp
+++ b/kabc/addressbook.cpp
@@ -40,5 +40,8 @@ $Id$
40#include <qptrlist.h> 40#include <qptrlist.h>
41#include <qtextstream.h>
42#include <qfile.h>
41 43
42#include <kglobal.h> 44#include <kglobal.h>
43#include <klocale.h> 45#include <klocale.h>>
46#include <kmessagebox.h>
44#include <kdebug.h> 47#include <kdebug.h>
@@ -47,2 +50,4 @@ $Id$
47#include "resource.h" 50#include "resource.h"
51#include "vcardconverter.h"
52#include "vcardparser/vcardtool.h"
48 53
@@ -372,2 +377,50 @@ bool AddressBook::save( Ticket *ticket )
372} 377}
378void AddressBook::export2File( QString fileName )
379{
380
381 QFile outFile( fileName );
382 if ( !outFile.open( IO_WriteOnly ) ) {
383 QString text = i18n( "<qt>Unable to open file <b>%1</b> for export.</qt>" );
384 KMessageBox::error( 0, text.arg( fileName ) );
385 return ;
386 }
387 QTextStream t( &outFile );
388 t.setEncoding( QTextStream::UnicodeUTF8 );
389 Iterator it;
390 KABC::VCardConverter::Version version;
391 version = KABC::VCardConverter::v3_0;
392 for ( it = begin(); it != end(); ++it ) {
393 if ( !(*it).IDStr().isEmpty() ) {
394 (*it).insertCustom( "KADDRESSBOOK", "X-ExternalID", (*it).IDStr() );
395 }
396 KABC::VCardConverter converter;
397 QString vcard;
398 //Resource *resource() const;
399 converter.addresseeToVCard( *it, vcard, version );
400 t << vcard << "\r\n";
401 }
402 outFile.close();
403}
404void AddressBook::importFromFile( QString fileName )
405{
406
407 KABC::Addressee::List list;
408 QFile file( fileName );
409
410 file.open( IO_ReadOnly );
411 QByteArray rawData = file.readAll();
412 file.close();
413
414 QString data = QString::fromUtf8( rawData.data(), rawData.size() + 1 );
415 KABC::VCardTool tool;
416 list = tool.parseVCards( data );
417
418 KABC::Addressee::List::Iterator it;
419 for ( it = list.begin(); it != list.end(); ++it ) {
420 (*it).setResource( 0 );
421 insertAddressee( (*it), false, true );
422 }
423
424}
425
373bool AddressBook::saveAB() 426bool AddressBook::saveAB()
@@ -463,3 +516,3 @@ Ticket *AddressBook::requestSaveTicket( Resource *resource )
463 516
464void AddressBook::insertAddressee( const Addressee &a, bool setRev ) 517void AddressBook::insertAddressee( const Addressee &a, bool setRev, bool takeResource )
465{ 518{
@@ -480,2 +533,7 @@ void AddressBook::insertAddressee( const Addressee &a, bool setRev )
480 533
534 if ( takeResource ) {
535 Resource * res = (*it).resource();
536 (*it) = a;
537 (*it).setResource( res );
538 } else {
481 (*it) = a; 539 (*it) = a;
@@ -483,3 +541,3 @@ void AddressBook::insertAddressee( const Addressee &a, bool setRev )
483 (*it).setResource( standardResource() ); 541 (*it).setResource( standardResource() );
484 542 }
485 if ( changed ) { 543 if ( changed ) {