-rw-r--r-- | kabc/addressbook.cpp | 70 | ||||
-rw-r--r-- | kabc/addressbook.h | 5 | ||||
-rw-r--r-- | kaddressbook/kabcore.cpp | 20 | ||||
-rw-r--r-- | kaddressbook/kabcore.h | 2 | ||||
-rw-r--r-- | kaddressbook/xxport/vcard_xxport.cpp | 1 | ||||
-rw-r--r-- | libkdepim/ksyncmanager.cpp | 5 | ||||
-rw-r--r-- | libkdepim/ksyncmanager.h | 5 |
7 files changed, 90 insertions, 18 deletions
diff --git a/kabc/addressbook.cpp b/kabc/addressbook.cpp index 5fb49eb..295cf03 100644 --- a/kabc/addressbook.cpp +++ b/kabc/addressbook.cpp @@ -38,13 +38,18 @@ $Id$ #include "errorhandler.h" */ #include <qptrlist.h> +#include <qtextstream.h> +#include <qfile.h> #include <kglobal.h> -#include <klocale.h> +#include <klocale.h>> +#include <kmessagebox.h> #include <kdebug.h> #include <libkcal/syncdefines.h> #include "addressbook.h" #include "resource.h" +#include "vcardconverter.h" +#include "vcardparser/vcardtool.h" //US #include "addressbook.moc" @@ -370,6 +375,54 @@ bool AddressBook::save( Ticket *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"; + } + outFile.close(); +} +void AddressBook::importFromFile( QString fileName ) +{ + + 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 ); + KABC::VCardTool tool; + list = tool.parseVCards( data ); + + KABC::Addressee::List::Iterator it; + for ( it = list.begin(); it != list.end(); ++it ) { + (*it).setResource( 0 ); + insertAddressee( (*it), false, true ); + } + +} + bool AddressBook::saveAB() { bool ok = true; @@ -461,7 +514,7 @@ Ticket *AddressBook::requestSaveTicket( Resource *resource ) return 0; } -void AddressBook::insertAddressee( const Addressee &a, bool setRev ) +void AddressBook::insertAddressee( const Addressee &a, bool setRev, bool takeResource ) { if ( blockLSEchange && setRev && a.uid().left( 19 ) == QString("last-syncAddressee-") ) { //qDebug("block insert "); @@ -478,10 +531,15 @@ void AddressBook::insertAddressee( const Addressee &a, bool setRev ) if ( addr != (*it) ) changed = true; - (*it) = a; - if ( (*it).resource() == 0 ) - (*it).setResource( standardResource() ); - + if ( takeResource ) { + Resource * res = (*it).resource(); + (*it) = a; + (*it).setResource( res ); + } else { + (*it) = a; + if ( (*it).resource() == 0 ) + (*it).setResource( standardResource() ); + } if ( changed ) { if ( setRev ) { diff --git a/kabc/addressbook.h b/kabc/addressbook.h index 8f62f0d..3603ec1 100644 --- a/kabc/addressbook.h +++ b/kabc/addressbook.h @@ -142,7 +142,8 @@ class AddressBook : public QObject */ bool save( Ticket *ticket ); bool saveAB( ); - + void export2File( QString fileName ); + void importFromFile( QString fileName ); /** Returns a iterator for first entry of address book. */ @@ -173,7 +174,7 @@ class AddressBook : public QObject unique id already exists in the address book it it replaced by the new one. If not the new object is appended to the address book. */ - void insertAddressee( const Addressee &, bool setRev = true ); + void insertAddressee( const Addressee &, bool setRev = true, bool takeResource = false); /** Removes entry from the address book. diff --git a/kaddressbook/kabcore.cpp b/kaddressbook/kabcore.cpp index 83fede4..6404410 100644 --- a/kaddressbook/kabcore.cpp +++ b/kaddressbook/kabcore.cpp @@ -1683,9 +1683,9 @@ void KABCore::initGUI() syncManager = new KSyncManager((QWidget*)this, (KSyncInterface*)this, KSyncManager::KAPI, KABPrefs::instance(), syncMenu); syncManager->setBlockSave(false); - connect(syncManager , SIGNAL( save() ), this, SLOT( save() ) ); + connect(syncManager , SIGNAL( request_file() ), this, SLOT( syncFileRequest() ) ); connect(syncManager , SIGNAL( getFile( bool )), this, SLOT(getFile( bool ) ) ); - syncManager->setDefaultFileName(locateLocal( "apps","kabc/std.vcf") ); + syncManager->setDefaultFileName( sentSyncFile()); //connect(syncManager , SIGNAL( ), this, SLOT( ) ); #endif //KAB_EMBEDDED @@ -2862,10 +2862,20 @@ void KABCore::getFile( bool success ) setCaption( i18n("Error receiving file. Nothing changed!") ); return; } - //mView->watchSavedFile(); - //mView->openCalendar( defaultFileName() ); - // pending: reload received file! + mAddressBook->importFromFile( sentSyncFile() ); setCaption( i18n("Pi-Sync successful!") ); } +void KABCore::syncFileRequest() +{ + mAddressBook->export2File( sentSyncFile() ); +} +QString KABCore::sentSyncFile() +{ +#ifdef _WIN32_ + return locateLocal( "tmp", "syncab.ics" ); +#else + return QString( "/tmp/kapitempfile.vcf" ); +#endif +} diff --git a/kaddressbook/kabcore.h b/kaddressbook/kabcore.h index 355e828..987369d 100644 --- a/kaddressbook/kabcore.h +++ b/kaddressbook/kabcore.h @@ -343,6 +343,7 @@ class KABCore : public QWidget, public KSyncInterface void contactSelected( const QPixmap &pixmap ); public slots: void getFile( bool success ); + void syncFileRequest(); void setDetailsVisible( bool visible ); void setDetailsToState(); // void slotSyncMenu( int ); @@ -465,6 +466,7 @@ class KABCore : public QWidget, public KSyncInterface // LR ******************************* // sync stuff! + QString sentSyncFile(); QPopupMenu *syncMenu; KSyncManager* syncManager; int mGlobalSyncMode; diff --git a/kaddressbook/xxport/vcard_xxport.cpp b/kaddressbook/xxport/vcard_xxport.cpp index acf6419..3079d42 100644 --- a/kaddressbook/xxport/vcard_xxport.cpp +++ b/kaddressbook/xxport/vcard_xxport.cpp @@ -121,6 +121,7 @@ bool VCardXXPort::exportContacts( const KABC::AddresseeList &list, const QString else version = KABC::VCardConverter::v3_0; + version = KABC::VCardConverter::v2_1; converter.addresseeToVCard( *it, vcard, version ); t << vcard << "\r\n\r\n"; } diff --git a/libkdepim/ksyncmanager.cpp b/libkdepim/ksyncmanager.cpp index 5d48884..ea543dd 100644 --- a/libkdepim/ksyncmanager.cpp +++ b/libkdepim/ksyncmanager.cpp @@ -275,7 +275,8 @@ void KSyncManager::enableQuick() mServerSocket = 0; return; } - connect( mServerSocket, SIGNAL ( saveFile() ),this, SIGNAL ( save() ) ); + //connect( mServerSocket, SIGNAL ( saveFile() ),this, SIGNAL ( save() ) ); + connect( mServerSocket, SIGNAL ( request_file() ),this, SIGNAL ( request_file() ) ); connect( mServerSocket, SIGNAL ( file_received( bool ) ), this, SIGNAL ( getFile( bool ) ) ); } @@ -928,7 +929,7 @@ void KServerSocket::send_file() mSyncActionDialog->setFixedSize( 230, 120); mSyncActionDialog->show(); qDebug("KSS::saving ... "); - emit saveFile(); + emit request_file(); qApp->processEvents(); QString fileName = mFileName; QFile file( fileName ); diff --git a/libkdepim/ksyncmanager.h b/libkdepim/ksyncmanager.h index 52e2772..0eb3323 100644 --- a/libkdepim/ksyncmanager.h +++ b/libkdepim/ksyncmanager.h @@ -50,10 +50,8 @@ public: void setFileName( QString fn ) {mFileName = fn;}; signals: - //void sendFile(QSocket*); - //void getFile(QSocket*); void file_received( bool ); - //void file_sent(); + void request_file(); void saveFile(); void endConnect(); private slots: @@ -156,6 +154,7 @@ class KSyncManager : public QObject signals: void save(); + void request_file(); void getFile( bool ); public slots: |