summaryrefslogtreecommitdiffabout
authorzautrix <zautrix>2004-10-07 09:56:31 (UTC)
committer zautrix <zautrix>2004-10-07 09:56:31 (UTC)
commitedd36b813763c304b104f276437c2c60ee9bd1f1 (patch) (side-by-side diff)
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
@@ -33,23 +33,28 @@ $Id$
#include <kapplication.h>
#include <kinstance.h>
#include <kstandarddirs.h>
#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"
using namespace KABC;
struct AddressBook::AddressBookData
{
Addressee::List mAddressees;
@@ -365,16 +370,64 @@ bool AddressBook::save( Ticket *ticket )
if ( ticket->resource() ) {
deleteRemovedAddressees();
return ticket->resource()->save( 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;
deleteRemovedAddressees();
Iterator ait;
for ( ait = begin(); ait != end(); ++ait ) {
if ( !(*ait).IDStr().isEmpty() ) {
@@ -456,37 +509,42 @@ Ticket *AddressBook::requestSaveTicket( Resource *resource )
else
return (*it)->requestSaveTicket();
}
}
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 ");
return;
}
//qDebug("inserting.... %s ",a.uid().latin1() );
bool found = false;
Addressee::List::Iterator it;
for ( it = d->mAddressees.begin(); it != d->mAddressees.end(); ++it ) {
if ( a.uid() == (*it).uid() ) {
bool changed = false;
Addressee addr = a;
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 ) {
// get rid of micro seconds
QDateTime dt = QDateTime::currentDateTime();
QTime t = dt.time();
dt.setTime( QTime (t.hour (), t.minute (), t.second () ) );
(*it).setRevision( dt );
diff --git a/kabc/addressbook.h b/kabc/addressbook.h
index 8f62f0d..3603ec1 100644
--- a/kabc/addressbook.h
+++ b/kabc/addressbook.h
@@ -137,17 +137,18 @@ class AddressBook : public QObject
/**
Save address book. The address book is saved to the file, the Ticket
object has been requested for by @ref requestSaveTicket().
@param ticket a ticket object returned by @ref requestSaveTicket()
*/
bool save( Ticket *ticket );
bool saveAB( );
-
+ void export2File( QString fileName );
+ void importFromFile( QString fileName );
/**
Returns a iterator for first entry of address book.
*/
Iterator begin();
/**
Returns a const iterator for first entry of address book.
*/
@@ -168,17 +169,17 @@ class AddressBook : public QObject
*/
void clear();
/**
Insert an Addressee object into address book. If an object with the same
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.
*/
void removeAddressee( const Addressee & );
/**
This is like @ref removeAddressee() just above, with the difference that
diff --git a/kaddressbook/kabcore.cpp b/kaddressbook/kabcore.cpp
index 83fede4..6404410 100644
--- a/kaddressbook/kabcore.cpp
+++ b/kaddressbook/kabcore.cpp
@@ -1678,19 +1678,19 @@ void KABCore::initGUI()
// topLayout->setStretchFactor( mDetailsSplitter, 100 );
topLayout->addWidget( mDetails );
#endif //KAB_NOSPLITTER
*/
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
initActions();
#ifdef KAB_EMBEDDED
addActionsManually();
//US make sure the export and import menues are initialized before creating the xxPortManager.
@@ -2857,15 +2857,25 @@ bool KABCore::syncExternal(KSyncManager* manager, QString resource)
}
void KABCore::getFile( bool success )
{
if ( ! 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
@@ -338,16 +338,17 @@ class KABCore : public QWidget, public KSyncInterface
void requestForBirthdayList(const QString& sourceChannel, const QString& sessionuid);
signals:
void contactSelected( const QString &name );
void contactSelected( const QPixmap &pixmap );
public slots:
void getFile( bool success );
+ void syncFileRequest();
void setDetailsVisible( bool visible );
void setDetailsToState();
// void slotSyncMenu( int );
private slots:
void setJumpButtonBarVisible( bool visible );
void importFromOL();
void extensionModified( const KABC::Addressee::List &list );
void extensionChanged( int id );
@@ -460,16 +461,17 @@ class KABCore : public QWidget, public KSyncInterface
//this are the overwritten callbackmethods from the syncinterface
virtual bool sync(KSyncManager* manager, QString filename, int mode);
virtual bool syncExternal(KSyncManager* manager, QString resource);
// LR *******************************
// sync stuff!
+ QString sentSyncFile();
QPopupMenu *syncMenu;
KSyncManager* syncManager;
int mGlobalSyncMode;
bool synchronizeAddressbooks( KABC::AddressBook* local, KABC::AddressBook* remote,int mode);
KABC::Addressee getLastSyncAddressee();
QDateTime mLastAddressbookSync;
int takeAddressee( KABC::Addressee* local, KABC::Addressee* remote, int mode , bool full );
// *********************
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
@@ -116,16 +116,17 @@ bool VCardXXPort::exportContacts( const KABC::AddresseeList &list, const QString
QString vcard;
KABC::VCardConverter::Version version;
if ( data == "v21" )
version = KABC::VCardConverter::v2_1;
else
version = KABC::VCardConverter::v3_0;
+ version = KABC::VCardConverter::v2_1;
converter.addresseeToVCard( *it, vcard, version );
t << vcard << "\r\n\r\n";
}
outFile.close();
return true;
}
diff --git a/libkdepim/ksyncmanager.cpp b/libkdepim/ksyncmanager.cpp
index 5d48884..ea543dd 100644
--- a/libkdepim/ksyncmanager.cpp
+++ b/libkdepim/ksyncmanager.cpp
@@ -270,17 +270,18 @@ void KSyncManager::enableQuick()
mServerSocket->setFileName( defaultFileName() );
//qDebug("connected ");
if ( !mServerSocket->ok() ) {
KMessageBox::information( 0, i18n("Failed to bind or\nlisten to the port!"));
delete mServerSocket;
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 ) ) );
}
void KSyncManager::syncLocalFile()
{
QString fn =mLastSyncedLocalFile;
QString ext;
@@ -923,17 +924,17 @@ void KServerSocket::send_file()
QLabel* label = new QLabel( i18n("Synchronizing from remote ...\n\nDo not use this application!\n\nIf syncing fails\nyou can close this dialog."), mSyncActionDialog );
QVBoxLayout* lay = new QVBoxLayout( mSyncActionDialog );
lay->addWidget( label);
lay->setMargin(7);
lay->setSpacing(7);
mSyncActionDialog->setFixedSize( 230, 120);
mSyncActionDialog->show();
qDebug("KSS::saving ... ");
- emit saveFile();
+ emit request_file();
qApp->processEvents();
QString fileName = mFileName;
QFile file( fileName );
if (!file.open( IO_ReadOnly ) ) {
delete mSyncActionDialog;
mSyncActionDialog = 0;
qDebug("KSS::error open file ");
mSocket->close();
diff --git a/libkdepim/ksyncmanager.h b/libkdepim/ksyncmanager.h
index 52e2772..0eb3323 100644
--- a/libkdepim/ksyncmanager.h
+++ b/libkdepim/ksyncmanager.h
@@ -45,20 +45,18 @@ class KServerSocket : public QServerSocket
public:
KServerSocket ( QString password, Q_UINT16 port, int backlog = 0, QObject * parent=0, const char * name=0 );
void newConnection ( int socket ) ;
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:
void discardClient();
void readClient();
void readBackFileFromSocket();
private :
bool blockRC;
@@ -151,16 +149,17 @@ class KSyncManager : public QObject
QString mPhoneModel;
QString mLastSyncedLocalFile; // save!
QString mPassWordPiSync;
QString mActiveSyncPort;
QString mActiveSyncIP ;
signals:
void save();
+ void request_file();
void getFile( bool );
public slots:
void slotSyncMenu( int );
private:
// LR *******************************
// sync stuff!