-rw-r--r-- | kabc/addressbook.cpp | 64 | ||||
-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, 87 insertions, 15 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$ | |||
38 | #include "errorhandler.h" | 38 | #include "errorhandler.h" |
39 | */ | 39 | */ |
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> |
45 | #include <libkcal/syncdefines.h> | 48 | #include <libkcal/syncdefines.h> |
46 | #include "addressbook.h" | 49 | #include "addressbook.h" |
47 | #include "resource.h" | 50 | #include "resource.h" |
51 | #include "vcardconverter.h" | ||
52 | #include "vcardparser/vcardtool.h" | ||
48 | 53 | ||
49 | //US #include "addressbook.moc" | 54 | //US #include "addressbook.moc" |
50 | 55 | ||
@@ -370,6 +375,54 @@ bool AddressBook::save( Ticket *ticket ) | |||
370 | 375 | ||
371 | return false; | 376 | return false; |
372 | } | 377 | } |
378 | void 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 | } | ||
404 | void 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 | |||
373 | bool AddressBook::saveAB() | 426 | bool AddressBook::saveAB() |
374 | { | 427 | { |
375 | bool ok = true; | 428 | bool ok = true; |
@@ -461,7 +514,7 @@ Ticket *AddressBook::requestSaveTicket( Resource *resource ) | |||
461 | return 0; | 514 | return 0; |
462 | } | 515 | } |
463 | 516 | ||
464 | void AddressBook::insertAddressee( const Addressee &a, bool setRev ) | 517 | void AddressBook::insertAddressee( const Addressee &a, bool setRev, bool takeResource ) |
465 | { | 518 | { |
466 | if ( blockLSEchange && setRev && a.uid().left( 19 ) == QString("last-syncAddressee-") ) { | 519 | if ( blockLSEchange && setRev && a.uid().left( 19 ) == QString("last-syncAddressee-") ) { |
467 | //qDebug("block insert "); | 520 | //qDebug("block insert "); |
@@ -478,10 +531,15 @@ void AddressBook::insertAddressee( const Addressee &a, bool setRev ) | |||
478 | if ( addr != (*it) ) | 531 | if ( addr != (*it) ) |
479 | changed = true; | 532 | changed = true; |
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; |
482 | if ( (*it).resource() == 0 ) | 540 | if ( (*it).resource() == 0 ) |
483 | (*it).setResource( standardResource() ); | 541 | (*it).setResource( standardResource() ); |
484 | 542 | } | |
485 | if ( changed ) { | 543 | if ( changed ) { |
486 | if ( setRev ) { | 544 | if ( setRev ) { |
487 | 545 | ||
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 | |||
142 | */ | 142 | */ |
143 | bool save( Ticket *ticket ); | 143 | bool save( Ticket *ticket ); |
144 | bool saveAB( ); | 144 | bool saveAB( ); |
145 | 145 | void export2File( QString fileName ); | |
146 | void importFromFile( QString fileName ); | ||
146 | /** | 147 | /** |
147 | Returns a iterator for first entry of address book. | 148 | Returns a iterator for first entry of address book. |
148 | */ | 149 | */ |
@@ -173,7 +174,7 @@ class AddressBook : public QObject | |||
173 | unique id already exists in the address book it it replaced by the new | 174 | unique id already exists in the address book it it replaced by the new |
174 | one. If not the new object is appended to the address book. | 175 | one. If not the new object is appended to the address book. |
175 | */ | 176 | */ |
176 | void insertAddressee( const Addressee &, bool setRev = true ); | 177 | void insertAddressee( const Addressee &, bool setRev = true, bool takeResource = false); |
177 | 178 | ||
178 | /** | 179 | /** |
179 | Removes entry from the address book. | 180 | 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() | |||
1683 | syncManager = new KSyncManager((QWidget*)this, (KSyncInterface*)this, KSyncManager::KAPI, KABPrefs::instance(), syncMenu); | 1683 | syncManager = new KSyncManager((QWidget*)this, (KSyncInterface*)this, KSyncManager::KAPI, KABPrefs::instance(), syncMenu); |
1684 | syncManager->setBlockSave(false); | 1684 | syncManager->setBlockSave(false); |
1685 | 1685 | ||
1686 | connect(syncManager , SIGNAL( save() ), this, SLOT( save() ) ); | 1686 | connect(syncManager , SIGNAL( request_file() ), this, SLOT( syncFileRequest() ) ); |
1687 | connect(syncManager , SIGNAL( getFile( bool )), this, SLOT(getFile( bool ) ) ); | 1687 | connect(syncManager , SIGNAL( getFile( bool )), this, SLOT(getFile( bool ) ) ); |
1688 | syncManager->setDefaultFileName(locateLocal( "apps","kabc/std.vcf") ); | 1688 | syncManager->setDefaultFileName( sentSyncFile()); |
1689 | //connect(syncManager , SIGNAL( ), this, SLOT( ) ); | 1689 | //connect(syncManager , SIGNAL( ), this, SLOT( ) ); |
1690 | 1690 | ||
1691 | #endif //KAB_EMBEDDED | 1691 | #endif //KAB_EMBEDDED |
@@ -2862,10 +2862,20 @@ void KABCore::getFile( bool success ) | |||
2862 | setCaption( i18n("Error receiving file. Nothing changed!") ); | 2862 | setCaption( i18n("Error receiving file. Nothing changed!") ); |
2863 | return; | 2863 | return; |
2864 | } | 2864 | } |
2865 | //mView->watchSavedFile(); | 2865 | mAddressBook->importFromFile( sentSyncFile() ); |
2866 | //mView->openCalendar( defaultFileName() ); | ||
2867 | // pending: reload received file! | ||
2868 | setCaption( i18n("Pi-Sync successful!") ); | 2866 | setCaption( i18n("Pi-Sync successful!") ); |
2869 | } | 2867 | } |
2868 | void KABCore::syncFileRequest() | ||
2869 | { | ||
2870 | mAddressBook->export2File( sentSyncFile() ); | ||
2871 | } | ||
2872 | QString KABCore::sentSyncFile() | ||
2873 | { | ||
2874 | #ifdef _WIN32_ | ||
2875 | return locateLocal( "tmp", "syncab.ics" ); | ||
2876 | #else | ||
2877 | return QString( "/tmp/kapitempfile.vcf" ); | ||
2878 | #endif | ||
2879 | } | ||
2870 | 2880 | ||
2871 | 2881 | ||
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 | |||
343 | void contactSelected( const QPixmap &pixmap ); | 343 | void contactSelected( const QPixmap &pixmap ); |
344 | public slots: | 344 | public slots: |
345 | void getFile( bool success ); | 345 | void getFile( bool success ); |
346 | void syncFileRequest(); | ||
346 | void setDetailsVisible( bool visible ); | 347 | void setDetailsVisible( bool visible ); |
347 | void setDetailsToState(); | 348 | void setDetailsToState(); |
348 | // void slotSyncMenu( int ); | 349 | // void slotSyncMenu( int ); |
@@ -465,6 +466,7 @@ class KABCore : public QWidget, public KSyncInterface | |||
465 | 466 | ||
466 | // LR ******************************* | 467 | // LR ******************************* |
467 | // sync stuff! | 468 | // sync stuff! |
469 | QString sentSyncFile(); | ||
468 | QPopupMenu *syncMenu; | 470 | QPopupMenu *syncMenu; |
469 | KSyncManager* syncManager; | 471 | KSyncManager* syncManager; |
470 | int mGlobalSyncMode; | 472 | 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 | |||
121 | else | 121 | else |
122 | version = KABC::VCardConverter::v3_0; | 122 | version = KABC::VCardConverter::v3_0; |
123 | 123 | ||
124 | version = KABC::VCardConverter::v2_1; | ||
124 | converter.addresseeToVCard( *it, vcard, version ); | 125 | converter.addresseeToVCard( *it, vcard, version ); |
125 | t << vcard << "\r\n\r\n"; | 126 | t << vcard << "\r\n\r\n"; |
126 | } | 127 | } |
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() | |||
275 | mServerSocket = 0; | 275 | mServerSocket = 0; |
276 | return; | 276 | return; |
277 | } | 277 | } |
278 | connect( mServerSocket, SIGNAL ( saveFile() ),this, SIGNAL ( save() ) ); | 278 | //connect( mServerSocket, SIGNAL ( saveFile() ),this, SIGNAL ( save() ) ); |
279 | connect( mServerSocket, SIGNAL ( request_file() ),this, SIGNAL ( request_file() ) ); | ||
279 | connect( mServerSocket, SIGNAL ( file_received( bool ) ), this, SIGNAL ( getFile( bool ) ) ); | 280 | connect( mServerSocket, SIGNAL ( file_received( bool ) ), this, SIGNAL ( getFile( bool ) ) ); |
280 | } | 281 | } |
281 | 282 | ||
@@ -928,7 +929,7 @@ void KServerSocket::send_file() | |||
928 | mSyncActionDialog->setFixedSize( 230, 120); | 929 | mSyncActionDialog->setFixedSize( 230, 120); |
929 | mSyncActionDialog->show(); | 930 | mSyncActionDialog->show(); |
930 | qDebug("KSS::saving ... "); | 931 | qDebug("KSS::saving ... "); |
931 | emit saveFile(); | 932 | emit request_file(); |
932 | qApp->processEvents(); | 933 | qApp->processEvents(); |
933 | QString fileName = mFileName; | 934 | QString fileName = mFileName; |
934 | QFile file( fileName ); | 935 | 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: | |||
50 | void setFileName( QString fn ) {mFileName = fn;}; | 50 | void setFileName( QString fn ) {mFileName = fn;}; |
51 | 51 | ||
52 | signals: | 52 | signals: |
53 | //void sendFile(QSocket*); | ||
54 | //void getFile(QSocket*); | ||
55 | void file_received( bool ); | 53 | void file_received( bool ); |
56 | //void file_sent(); | 54 | void request_file(); |
57 | void saveFile(); | 55 | void saveFile(); |
58 | void endConnect(); | 56 | void endConnect(); |
59 | private slots: | 57 | private slots: |
@@ -156,6 +154,7 @@ class KSyncManager : public QObject | |||
156 | 154 | ||
157 | signals: | 155 | signals: |
158 | void save(); | 156 | void save(); |
157 | void request_file(); | ||
159 | void getFile( bool ); | 158 | void getFile( bool ); |
160 | 159 | ||
161 | public slots: | 160 | public slots: |