summaryrefslogtreecommitdiffabout
authorzautrix <zautrix>2004-10-07 09:56:31 (UTC)
committer zautrix <zautrix>2004-10-07 09:56:31 (UTC)
commitedd36b813763c304b104f276437c2c60ee9bd1f1 (patch) (unidiff)
treeda3a9f6fbd905fe876131af5025690806ce60704
parent9345818e9c291130691288e4b065190259eb4e01 (diff)
downloadkdepimpi-edd36b813763c304b104f276437c2c60ee9bd1f1.zip
kdepimpi-edd36b813763c304b104f276437c2c60ee9bd1f1.tar.gz
kdepimpi-edd36b813763c304b104f276437c2c60ee9bd1f1.tar.bz2
sync fixes
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
@@ -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,6 +533,11 @@ void AddressBook::insertAddressee( const Addressee &a, bool setRev )
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 ) {
diff --git a/kabc/addressbook.h b/kabc/addressbook.h
index 8f62f0d..3603ec1 100644
--- a/kabc/addressbook.h
+++ b/kabc/addressbook.h
@@ -144,3 +144,4 @@ class AddressBook : public QObject
144 bool saveAB( ); 144 bool saveAB( );
145 145 void export2File( QString fileName );
146 void importFromFile( QString fileName );
146 /** 147 /**
@@ -175,3 +176,3 @@ class AddressBook : public QObject
175 */ 176 */
176 void insertAddressee( const Addressee &, bool setRev = true ); 177 void insertAddressee( const Addressee &, bool setRev = true, bool takeResource = false);
177 178
diff --git a/kaddressbook/kabcore.cpp b/kaddressbook/kabcore.cpp
index 83fede4..6404410 100644
--- a/kaddressbook/kabcore.cpp
+++ b/kaddressbook/kabcore.cpp
@@ -1685,5 +1685,5 @@ void KABCore::initGUI()
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( ) );
@@ -2864,7 +2864,17 @@ void KABCore::getFile( bool success )
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
diff --git a/kaddressbook/kabcore.h b/kaddressbook/kabcore.h
index 355e828..987369d 100644
--- a/kaddressbook/kabcore.h
+++ b/kaddressbook/kabcore.h
@@ -345,2 +345,3 @@ class KABCore : public QWidget, public KSyncInterface
345 void getFile( bool success ); 345 void getFile( bool success );
346 void syncFileRequest();
346 void setDetailsVisible( bool visible ); 347 void setDetailsVisible( bool visible );
@@ -467,2 +468,3 @@ class KABCore : public QWidget, public KSyncInterface
467 // sync stuff! 468 // sync stuff!
469 QString sentSyncFile();
468 QPopupMenu *syncMenu; 470 QPopupMenu *syncMenu;
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
@@ -123,2 +123,3 @@ bool VCardXXPort::exportContacts( const KABC::AddresseeList &list, const QString
123 123
124 version = KABC::VCardConverter::v2_1;
124 converter.addresseeToVCard( *it, vcard, version ); 125 converter.addresseeToVCard( *it, vcard, version );
diff --git a/libkdepim/ksyncmanager.cpp b/libkdepim/ksyncmanager.cpp
index 5d48884..ea543dd 100644
--- a/libkdepim/ksyncmanager.cpp
+++ b/libkdepim/ksyncmanager.cpp
@@ -277,3 +277,4 @@ void KSyncManager::enableQuick()
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 ) ) );
@@ -930,3 +931,3 @@ void KServerSocket::send_file()
930 qDebug("KSS::saving ... "); 931 qDebug("KSS::saving ... ");
931 emit saveFile(); 932 emit request_file();
932 qApp->processEvents(); 933 qApp->processEvents();
diff --git a/libkdepim/ksyncmanager.h b/libkdepim/ksyncmanager.h
index 52e2772..0eb3323 100644
--- a/libkdepim/ksyncmanager.h
+++ b/libkdepim/ksyncmanager.h
@@ -52,6 +52,4 @@ public:
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();
@@ -158,2 +156,3 @@ class KSyncManager : public QObject
158 void save(); 156 void save();
157 void request_file();
159 void getFile( bool ); 158 void getFile( bool );