summaryrefslogtreecommitdiffabout
Unidiff
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--kabc/addressbook.cpp70
-rw-r--r--kabc/addressbook.h5
-rw-r--r--kaddressbook/kabcore.cpp20
-rw-r--r--kaddressbook/kabcore.h2
-rw-r--r--kaddressbook/xxport/vcard_xxport.cpp1
-rw-r--r--libkdepim/ksyncmanager.cpp5
-rw-r--r--libkdepim/ksyncmanager.h5
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
@@ -35,19 +35,24 @@ $Id$
35#include <kinstance.h> 35#include <kinstance.h>
36#include <kstandarddirs.h> 36#include <kstandarddirs.h>
37 37
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
51using namespace KABC; 56using namespace KABC;
52 57
53struct AddressBook::AddressBookData 58struct AddressBook::AddressBookData
@@ -367,12 +372,60 @@ bool AddressBook::save( Ticket *ticket )
367 deleteRemovedAddressees(); 372 deleteRemovedAddressees();
368 return ticket->resource()->save( ticket ); 373 return ticket->resource()->save( ticket );
369 } 374 }
370 375
371 return false; 376 return false;
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()
374{ 427{
375 bool ok = true; 428 bool ok = true;
376 429
377 deleteRemovedAddressees(); 430 deleteRemovedAddressees();
378 Iterator ait; 431 Iterator ait;
@@ -458,13 +511,13 @@ Ticket *AddressBook::requestSaveTicket( Resource *resource )
458 } 511 }
459 } 512 }
460 513
461 return 0; 514 return 0;
462} 515}
463 516
464void AddressBook::insertAddressee( const Addressee &a, bool setRev ) 517void 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 ");
468 return; 521 return;
469 } 522 }
470 //qDebug("inserting.... %s ",a.uid().latin1() ); 523 //qDebug("inserting.... %s ",a.uid().latin1() );
@@ -475,16 +528,21 @@ void AddressBook::insertAddressee( const Addressee &a, bool setRev )
475 528
476 bool changed = false; 529 bool changed = false;
477 Addressee addr = a; 530 Addressee addr = a;
478 if ( addr != (*it) ) 531 if ( addr != (*it) )
479 changed = true; 532 changed = true;
480 533
481 (*it) = a; 534 if ( takeResource ) {
482 if ( (*it).resource() == 0 ) 535 Resource * res = (*it).resource();
483 (*it).setResource( standardResource() ); 536 (*it) = a;
484 537 (*it).setResource( res );
538 } else {
539 (*it) = a;
540 if ( (*it).resource() == 0 )
541 (*it).setResource( standardResource() );
542 }
485 if ( changed ) { 543 if ( changed ) {
486 if ( setRev ) { 544 if ( setRev ) {
487 545
488 // get rid of micro seconds 546 // get rid of micro seconds
489 QDateTime dt = QDateTime::currentDateTime(); 547 QDateTime dt = QDateTime::currentDateTime();
490 QTime t = dt.time(); 548 QTime t = dt.time();
diff --git a/kabc/addressbook.h b/kabc/addressbook.h
index 8f62f0d..3603ec1 100644
--- a/kabc/addressbook.h
+++ b/kabc/addressbook.h
@@ -139,13 +139,14 @@ class AddressBook : public QObject
139 object has been requested for by @ref requestSaveTicket(). 139 object has been requested for by @ref requestSaveTicket().
140 140
141 @param ticket a ticket object returned by @ref requestSaveTicket() 141 @param ticket a ticket object returned by @ref requestSaveTicket()
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 */
149 Iterator begin(); 150 Iterator begin();
150 151
151 /** 152 /**
@@ -170,13 +171,13 @@ class AddressBook : public QObject
170 171
171 /** 172 /**
172 Insert an Addressee object into address book. If an object with the same 173 Insert an Addressee object into address book. If an object with the same
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.
180 */ 181 */
181 void removeAddressee( const Addressee & ); 182 void removeAddressee( const Addressee & );
182 183
diff --git a/kaddressbook/kabcore.cpp b/kaddressbook/kabcore.cpp
index 83fede4..6404410 100644
--- a/kaddressbook/kabcore.cpp
+++ b/kaddressbook/kabcore.cpp
@@ -1680,15 +1680,15 @@ void KABCore::initGUI()
1680#endif //KAB_NOSPLITTER 1680#endif //KAB_NOSPLITTER
1681*/ 1681*/
1682 1682
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
1692 initActions(); 1692 initActions();
1693 1693
1694#ifdef KAB_EMBEDDED 1694#ifdef KAB_EMBEDDED
@@ -2859,13 +2859,23 @@ bool KABCore::syncExternal(KSyncManager* manager, QString resource)
2859void KABCore::getFile( bool success ) 2859void KABCore::getFile( bool success )
2860{ 2860{
2861 if ( ! success ) { 2861 if ( ! 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}
2868void KABCore::syncFileRequest()
2869{
2870 mAddressBook->export2File( sentSyncFile() );
2871}
2872QString 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
@@ -340,12 +340,13 @@ class KABCore : public QWidget, public KSyncInterface
340 340
341 signals: 341 signals:
342 void contactSelected( const QString &name ); 342 void contactSelected( const QString &name );
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 );
349 private slots: 350 private slots:
350 void setJumpButtonBarVisible( bool visible ); 351 void setJumpButtonBarVisible( bool visible );
351 void importFromOL(); 352 void importFromOL();
@@ -462,12 +463,13 @@ class KABCore : public QWidget, public KSyncInterface
462 virtual bool sync(KSyncManager* manager, QString filename, int mode); 463 virtual bool sync(KSyncManager* manager, QString filename, int mode);
463 virtual bool syncExternal(KSyncManager* manager, QString resource); 464 virtual bool syncExternal(KSyncManager* manager, QString resource);
464 465
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;
471 bool synchronizeAddressbooks( KABC::AddressBook* local, KABC::AddressBook* remote,int mode); 473 bool synchronizeAddressbooks( KABC::AddressBook* local, KABC::AddressBook* remote,int mode);
472 KABC::Addressee getLastSyncAddressee(); 474 KABC::Addressee getLastSyncAddressee();
473 QDateTime mLastAddressbookSync; 475 QDateTime mLastAddressbookSync;
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
@@ -118,12 +118,13 @@ bool VCardXXPort::exportContacts( const KABC::AddresseeList &list, const QString
118 KABC::VCardConverter::Version version; 118 KABC::VCardConverter::Version version;
119 if ( data == "v21" ) 119 if ( data == "v21" )
120 version = KABC::VCardConverter::v2_1; 120 version = KABC::VCardConverter::v2_1;
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 }
127 128
128 outFile.close(); 129 outFile.close();
129 130
diff --git a/libkdepim/ksyncmanager.cpp b/libkdepim/ksyncmanager.cpp
index 5d48884..ea543dd 100644
--- a/libkdepim/ksyncmanager.cpp
+++ b/libkdepim/ksyncmanager.cpp
@@ -272,13 +272,14 @@ void KSyncManager::enableQuick()
272 if ( !mServerSocket->ok() ) { 272 if ( !mServerSocket->ok() ) {
273 KMessageBox::information( 0, i18n("Failed to bind or\nlisten to the port!")); 273 KMessageBox::information( 0, i18n("Failed to bind or\nlisten to the port!"));
274 delete mServerSocket; 274 delete mServerSocket;
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
282void KSyncManager::syncLocalFile() 283void KSyncManager::syncLocalFile()
283{ 284{
284 285
@@ -925,13 +926,13 @@ void KServerSocket::send_file()
925 lay->addWidget( label); 926 lay->addWidget( label);
926 lay->setMargin(7); 927 lay->setMargin(7);
927 lay->setSpacing(7); 928 lay->setSpacing(7);
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 );
935 if (!file.open( IO_ReadOnly ) ) { 936 if (!file.open( IO_ReadOnly ) ) {
936 delete mSyncActionDialog; 937 delete mSyncActionDialog;
937 mSyncActionDialog = 0; 938 mSyncActionDialog = 0;
diff --git a/libkdepim/ksyncmanager.h b/libkdepim/ksyncmanager.h
index 52e2772..0eb3323 100644
--- a/libkdepim/ksyncmanager.h
+++ b/libkdepim/ksyncmanager.h
@@ -47,16 +47,14 @@ public:
47 KServerSocket ( QString password, Q_UINT16 port, int backlog = 0, QObject * parent=0, const char * name=0 ); 47 KServerSocket ( QString password, Q_UINT16 port, int backlog = 0, QObject * parent=0, const char * name=0 );
48 48
49 void newConnection ( int socket ) ; 49 void newConnection ( int socket ) ;
50 void setFileName( QString fn ) {mFileName = fn;}; 50 void setFileName( QString fn ) {mFileName = fn;};
51 51
52signals: 52signals:
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();
59private slots: 57private slots:
60 void discardClient(); 58 void discardClient();
61 void readClient(); 59 void readClient();
62 void readBackFileFromSocket(); 60 void readBackFileFromSocket();
@@ -153,12 +151,13 @@ class KSyncManager : public QObject
153 QString mPassWordPiSync; 151 QString mPassWordPiSync;
154 QString mActiveSyncPort; 152 QString mActiveSyncPort;
155 QString mActiveSyncIP ; 153 QString mActiveSyncIP ;
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:
162 void slotSyncMenu( int ); 161 void slotSyncMenu( int );
163 162
164 private: 163 private: