-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 @@ -1,143 +1,148 @@ /* This file is part of libkabc. Copyright (c) 2001 Cornelius Schumacher <schumacher@kde.org> This library is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with this library; see the file COPYING.LIB. If not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ /* Enhanced Version of the file for platform independent KDE tools. Copyright (c) 2004 Ulf Schenk $Id$ */ /*US #include <qfile.h> #include <qregexp.h> #include <qtimer.h> #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; Addressee::List mRemovedAddressees; Field::List mAllFields; KConfig *mConfig; KRES::Manager<Resource> *mManager; //US ErrorHandler *mErrorHandler; }; struct AddressBook::Iterator::IteratorData { Addressee::List::Iterator mIt; }; struct AddressBook::ConstIterator::ConstIteratorData { Addressee::List::ConstIterator mIt; }; AddressBook::Iterator::Iterator() { d = new IteratorData; } AddressBook::Iterator::Iterator( const AddressBook::Iterator &i ) { d = new IteratorData; d->mIt = i.d->mIt; } AddressBook::Iterator &AddressBook::Iterator::operator=( const AddressBook::Iterator &i ) { if( this == &i ) return *this; // guard against self assignment delete d; // delete the old data the Iterator was completely constructed before d = new IteratorData; d->mIt = i.d->mIt; return *this; } AddressBook::Iterator::~Iterator() { delete d; } const Addressee &AddressBook::Iterator::operator*() const { return *(d->mIt); } Addressee &AddressBook::Iterator::operator*() { return *(d->mIt); } Addressee *AddressBook::Iterator::operator->() { return &(*(d->mIt)); } AddressBook::Iterator &AddressBook::Iterator::operator++() { (d->mIt)++; return *this; } AddressBook::Iterator &AddressBook::Iterator::operator++(int) { (d->mIt)++; return *this; } AddressBook::Iterator &AddressBook::Iterator::operator--() { (d->mIt)--; return *this; } AddressBook::Iterator &AddressBook::Iterator::operator--(int) { (d->mIt)--; return *this; } bool AddressBook::Iterator::operator==( const Iterator &it ) { return ( d->mIt == it.d->mIt ); } bool AddressBook::Iterator::operator!=( const Iterator &it ) { @@ -277,304 +282,357 @@ void AddressBook::init(const QString &config, const QString &family ) KRES::Manager<Resource>::ActiveIterator it; for ( it = manager->activeBegin(); it != manager->activeEnd(); ++it ) { (*it)->setAddressBook( this ); if ( !(*it)->open() ) error( QString( "Unable to open resource '%1'!" ).arg( (*it)->resourceName() ) ); } Resource *res = standardResource(); if ( !res ) { qDebug("ERROR: no standard resource"); res = manager->createResource( "file" ); if ( res ) { addResource( res ); } else qDebug(" No resource available!!!"); } setStandardResource( res ); manager->writeConfig(); } addCustomField( i18n( "Department" ), KABC::Field::Organization, "X-Department", "KADDRESSBOOK" ); addCustomField( i18n( "Profession" ), KABC::Field::Organization, "X-Profession", "KADDRESSBOOK" ); addCustomField( i18n( "Assistant's Name" ), KABC::Field::Organization, "X-AssistantsName", "KADDRESSBOOK" ); addCustomField( i18n( "Manager's Name" ), KABC::Field::Organization, "X-ManagersName", "KADDRESSBOOK" ); addCustomField( i18n( "Spouse's Name" ), KABC::Field::Personal, "X-SpousesName", "KADDRESSBOOK" ); addCustomField( i18n( "Office" ), KABC::Field::Personal, "X-Office", "KADDRESSBOOK" ); addCustomField( i18n( "IM Address" ), KABC::Field::Personal, "X-IMAddress", "KADDRESSBOOK" ); addCustomField( i18n( "Anniversary" ), KABC::Field::Personal, "X-Anniversary", "KADDRESSBOOK" ); //US added this field to become compatible with Opie/qtopia addressbook // values can be "female" or "male" or "". An empty field represents undefined. addCustomField( i18n( "Gender" ), KABC::Field::Personal, "X-Gender", "KADDRESSBOOK" ); addCustomField( i18n( "Children" ), KABC::Field::Personal, "X-Children", "KADDRESSBOOK" ); addCustomField( i18n( "FreeBusyUrl" ), KABC::Field::Personal, "X-FreeBusyUrl", "KADDRESSBOOK" ); addCustomField( i18n( "ExternalID" ), KABC::Field::Personal, "X-ExternalID", "KADDRESSBOOK" ); } AddressBook::~AddressBook() { delete d->mConfig; d->mConfig = 0; delete d->mManager; d->mManager = 0; //US delete d->mErrorHandler; d->mErrorHandler = 0; delete d; d = 0; } bool AddressBook::load() { clear(); KRES::Manager<Resource>::ActiveIterator it; bool ok = true; for ( it = d->mManager->activeBegin(); it != d->mManager->activeEnd(); ++it ) if ( !(*it)->load() ) { error( i18n("Unable to load resource '%1'").arg( (*it)->resourceName() ) ); ok = false; } // mark all addressees as unchanged Addressee::List::Iterator addrIt; for ( addrIt = d->mAddressees.begin(); addrIt != d->mAddressees.end(); ++addrIt ) { (*addrIt).setChanged( false ); QString id = (*addrIt).custom( "KADDRESSBOOK", "X-ExternalID" ); if ( !id.isEmpty() ) { //qDebug("setId aa %s ", id.latin1()); (*addrIt).setIDStr(id ); } } blockLSEchange = true; return ok; } bool AddressBook::save( Ticket *ticket ) { kdDebug(5700) << "AddressBook::save()"<< endl; 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() ) { (*ait).insertCustom( "KADDRESSBOOK", "X-ExternalID", (*ait).IDStr() ); } } KRES::Manager<Resource>::ActiveIterator it; KRES::Manager<Resource> *manager = d->mManager; for ( it = manager->activeBegin(); it != manager->activeEnd(); ++it ) { if ( !(*it)->readOnly() && (*it)->isOpen() ) { Ticket *ticket = requestSaveTicket( *it ); // qDebug("StdAddressBook::save '%s'", (*it)->resourceName().latin1() ); if ( !ticket ) { error( i18n( "Unable to save to resource '%1'. It is locked." ) .arg( (*it)->resourceName() ) ); return false; } //if ( !save( ticket ) ) if ( ticket->resource() ) { if ( ! ticket->resource()->save( ticket ) ) ok = false; } else ok = false; } } return ok; } AddressBook::Iterator AddressBook::begin() { Iterator it = Iterator(); it.d->mIt = d->mAddressees.begin(); return it; } AddressBook::ConstIterator AddressBook::begin() const { ConstIterator it = ConstIterator(); it.d->mIt = d->mAddressees.begin(); return it; } AddressBook::Iterator AddressBook::end() { Iterator it = Iterator(); it.d->mIt = d->mAddressees.end(); return it; } AddressBook::ConstIterator AddressBook::end() const { ConstIterator it = ConstIterator(); it.d->mIt = d->mAddressees.end(); return it; } void AddressBook::clear() { d->mAddressees.clear(); } Ticket *AddressBook::requestSaveTicket( Resource *resource ) { kdDebug(5700) << "AddressBook::requestSaveTicket()" << endl; if ( !resource ) { qDebug("AddressBook::requestSaveTicket no resource" ); resource = standardResource(); } KRES::Manager<Resource>::ActiveIterator it; for ( it = d->mManager->activeBegin(); it != d->mManager->activeEnd(); ++it ) { if ( (*it) == resource ) { if ( (*it)->readOnly() || !(*it)->isOpen() ) return 0; 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 ); } (*it).setChanged( true ); } found = true; } else { if ( (*it).uid().left( 19 ) == QString("last-syncAddressee-") ) { QString name = (*it).uid().mid( 19 ); Addressee b = a; QString id = b.getID( name ); if ( ! id.isEmpty() ) { QString des = (*it).note(); int startN; if( (startN = des.find( id ) ) >= 0 ) { int endN = des.find( ",", startN+1 ); des = des.left( startN ) + des.mid( endN+1 ); (*it).setNote( des ); } } } } } if ( found ) return; d->mAddressees.append( a ); Addressee& addr = d->mAddressees.last(); if ( addr.resource() == 0 ) addr.setResource( standardResource() ); addr.setChanged( true ); } void AddressBook::removeAddressee( const Addressee &a ) { Iterator it; Iterator it2; bool found = false; for ( it = begin(); it != end(); ++it ) { if ( a.uid() == (*it).uid() ) { found = true; it2 = it; } else { if ( (*it).uid().left( 19 ) == QString("last-syncAddressee-") ) { QString name = (*it).uid().mid( 19 ); Addressee b = a; QString id = b.getID( name ); if ( ! id.isEmpty() ) { QString des = (*it).note(); if( des.find( id ) < 0 ) { des += id + ","; (*it).setNote( des ); } } } } } if ( found ) removeAddressee( it2 ); } void AddressBook::removeSyncAddressees( bool removeDeleted ) { Iterator it = begin(); Iterator it2 ; QDateTime dt ( QDate( 2004,1,1) ); while ( it != end() ) { (*it).setRevision( dt ); (*it).removeCustom( "KADDRESSBOOK", "X-ExternalID" ); (*it).setIDStr(""); if ( ( (*it).tempSyncStat() == SYNC_TEMPSTATE_DELETE && removeDeleted )|| (*it).uid().left( 19 ) == QString("last-syncAddressee-")) { it2 = it; //qDebug("removing %s ",(*it).uid().latin1() ); ++it; removeAddressee( it2 ); } else { //qDebug("skipping %s ",(*it).uid().latin1() ); ++it; } } deleteRemovedAddressees(); } void AddressBook::removeAddressee( const Iterator &it ) { d->mRemovedAddressees.append( (*it) ); diff --git a/kabc/addressbook.h b/kabc/addressbook.h index 8f62f0d..3603ec1 100644 --- a/kabc/addressbook.h +++ b/kabc/addressbook.h @@ -49,224 +49,225 @@ class Ticket; */ class AddressBook : public QObject { Q_OBJECT friend QDataStream &operator<<( QDataStream &, const AddressBook & ); friend QDataStream &operator>>( QDataStream &, AddressBook & ); friend class StdAddressBook; public: /** @short Address Book Iterator This class provides an iterator for address book entries. */ class Iterator { public: Iterator(); Iterator( const Iterator & ); ~Iterator(); Iterator &operator=( const Iterator & ); const Addressee &operator*() const; Addressee &operator*(); Addressee* operator->(); Iterator &operator++(); Iterator &operator++(int); Iterator &operator--(); Iterator &operator--(int); bool operator==( const Iterator &it ); bool operator!=( const Iterator &it ); struct IteratorData; IteratorData *d; }; /** @short Address Book Const Iterator This class provides a const iterator for address book entries. */ class ConstIterator { public: ConstIterator(); ConstIterator( const ConstIterator & ); ~ConstIterator(); ConstIterator &operator=( const ConstIterator & ); const Addressee &operator*() const; const Addressee* operator->() const; ConstIterator &operator++(); ConstIterator &operator++(int); ConstIterator &operator--(); ConstIterator &operator--(int); bool operator==( const ConstIterator &it ); bool operator!=( const ConstIterator &it ); struct ConstIteratorData; ConstIteratorData *d; }; /** Constructs a address book object. @param format File format class. */ AddressBook(); AddressBook( const QString &config ); AddressBook( const QString &config, const QString &family ); virtual ~AddressBook(); /** Requests a ticket for saving the addressbook. Calling this function locks the addressbook for all other processes. If the address book is already locked the function returns 0. You need the returned @ref Ticket object for calling the @ref save() function. @see save() */ Ticket *requestSaveTicket( Resource *resource=0 ); /** Load address book from file. */ bool load(); /** 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. */ ConstIterator begin() const; /** Returns a iterator for first entry of address book. */ Iterator end(); /** Returns a const iterator for first entry of address book. */ ConstIterator end() const; /** Removes all entries from address book. */ 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 the first element is a iterator, returned by @ref begin(). */ void removeAddressee( const Iterator & ); /** Find the specified entry in address book. Returns end(), if the entry couldn't be found. */ Iterator find( const Addressee & ); /** Find the entry specified by an unique id. Returns an empty Addressee object, if the address book does not contain an entry with this id. */ Addressee findByUid( const QString & ); /** Returns a list of all addressees in the address book. This list can be sorted with @ref KABC::AddresseeList for example. */ Addressee::List allAddressees(); /** Find all entries with the specified name in the address book. Returns an empty list, if no entries could be found. */ Addressee::List findByName( const QString & ); /** Find all entries with the specified email address in the address book. Returns an empty list, if no entries could be found. */ Addressee::List findByEmail( const QString & ); /** Find all entries wich have the specified category in the address book. Returns an empty list, if no entries could be found. */ Addressee::List findByCategory( const QString & ); /** Return a string identifying this addressbook. */ virtual QString identifier(); /** Used for debug output. */ void dump() const; void emitAddressBookLocked() { emit addressBookLocked( this ); } void emitAddressBookUnlocked() { emit addressBookUnlocked( this ); } void emitAddressBookChanged() { emit addressBookChanged( this ); } /** Return list of all Fields known to the address book which are associated with the given field category. */ Field::List fields( int category = Field::All ); /** Add custom field to address book. @param label User visible label of the field. @param category Ored list of field categories. @param key Identifier used as key for reading and writing the field. @param app String used as application key for reading and writing the field. */ bool addCustomField( const QString &label, int category = Field::All, const QString &key = QString::null, const QString &app = QString::null ); /** Add address book resource. */ bool addResource( Resource * ); /** Remove address book resource. */ bool removeResource( Resource * ); /** Return pointer list of all resources. */ diff --git a/kaddressbook/kabcore.cpp b/kaddressbook/kabcore.cpp index 83fede4..6404410 100644 --- a/kaddressbook/kabcore.cpp +++ b/kaddressbook/kabcore.cpp @@ -1590,195 +1590,195 @@ void KABCore::initGUI() viewMenu = new QPopupMenu( this ); settingsMenu = new QPopupMenu( this ); //filterMenu = new QPopupMenu( this ); ImportMenu = new QPopupMenu( this ); ExportMenu = new QPopupMenu( this ); syncMenu = new QPopupMenu( this ); changeMenu= new QPopupMenu( this ); //US since we have no splitter for the embedded system, setup // a layout with two frames. One left and one right. QBoxLayout *topLayout; // = new QHBoxLayout( this ); // QBoxLayout *topLayout = (QBoxLayout*)layout(); // QWidget *mainBox = new QWidget( this ); // QBoxLayout * mainBoxLayout = new QHBoxLayout(mainBox); #ifdef DESKTOP_VERSION topLayout = new QHBoxLayout( this ); mMiniSplitter = new KDGanttMinimizeSplitter( Qt::Horizontal, this); mMiniSplitter->setMinimizeDirection ( KDGanttMinimizeSplitter::Right ); topLayout->addWidget(mMiniSplitter ); mExtensionBarSplitter = new KDGanttMinimizeSplitter( Qt::Vertical,mMiniSplitter ); mExtensionBarSplitter->setMinimizeDirection ( KDGanttMinimizeSplitter::Down ); mViewManager = new ViewManager( this, mExtensionBarSplitter ); mDetails = new ViewContainer( mMiniSplitter ); mExtensionManager = new ExtensionManager( this, mExtensionBarSplitter ); #else if ( QApplication::desktop()->width() > 480 ) { topLayout = new QHBoxLayout( this ); mMiniSplitter = new KDGanttMinimizeSplitter( Qt::Horizontal, this); mMiniSplitter->setMinimizeDirection ( KDGanttMinimizeSplitter::Right ); } else { topLayout = new QHBoxLayout( this ); mMiniSplitter = new KDGanttMinimizeSplitter( Qt::Vertical, this); mMiniSplitter->setMinimizeDirection ( KDGanttMinimizeSplitter::Down ); } topLayout->addWidget(mMiniSplitter ); mViewManager = new ViewManager( this, mMiniSplitter ); mDetails = new ViewContainer( mMiniSplitter ); mExtensionManager = new ExtensionManager( this, mMiniSplitter ); #endif //eh->hide(); // topLayout->addWidget(mExtensionManager ); /*US #ifndef KAB_NOSPLITTER QHBoxLayout *topLayout = new QHBoxLayout( this ); //US topLayout->setSpacing( KDialogBase::spacingHint() ); topLayout->setSpacing( 10 ); mDetailsSplitter = new QSplitter( this ); QVBox *viewSpace = new QVBox( mDetailsSplitter ); mViewManager = new ViewManager( this, viewSpace ); viewSpace->setStretchFactor( mViewManager, 1 ); mDetails = new ViewContainer( mDetailsSplitter ); topLayout->addWidget( mDetailsSplitter ); topLayout->setStretchFactor( mDetailsSplitter, 100 ); #else //KAB_NOSPLITTER QHBoxLayout *topLayout = new QHBoxLayout( this ); //US topLayout->setSpacing( KDialogBase::spacingHint() ); topLayout->setSpacing( 10 ); // mDetailsSplitter = new QSplitter( this ); QVBox *viewSpace = new QVBox( this ); mViewManager = new ViewManager( this, viewSpace ); viewSpace->setStretchFactor( mViewManager, 1 ); mDetails = new ViewContainer( this ); topLayout->addWidget( viewSpace ); // 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. mXXPortManager = new XXPortManager( this, this ); // LR mIncSearchWidget = new IncSearchWidget( mMainWindow->getIconToolBar() ); //mMainWindow->toolBar()->insertWidget(-1, 4, mIncSearchWidget); // mActionQuit->plug ( mMainWindow->toolBar()); //mIncSearchWidget = new IncSearchWidget( mMainWindow->toolBar() ); //mMainWindow->toolBar()->insertWidget(-1, 0, mIncSearchWidget); // mIncSearchWidget->hide(); connect( mIncSearchWidget, SIGNAL( doSearch( const QString& ) ), SLOT( incrementalSearch( const QString& ) ) ); mJumpButtonBar = new JumpButtonBar( this, this ); topLayout->addWidget( mJumpButtonBar ); //US topLayout->setStretchFactor( mJumpButtonBar, 10 ); // mMainWindow->getIconToolBar()->raise(); #endif //KAB_EMBEDDED } void KABCore::initActions() { //US qDebug("KABCore::initActions(): mIsPart %i", mIsPart); #ifndef KAB_EMBEDDED connect( QApplication::clipboard(), SIGNAL( dataChanged() ), SLOT( clipboardDataChanged() ) ); #endif //KAB_EMBEDDED // file menu if ( mIsPart ) { mActionMail = new KAction( i18n( "&Mail" ), "mail_generic", 0, this, SLOT( sendMail() ), actionCollection(), "kaddressbook_mail" ); mActionPrint = new KAction( i18n( "&Print" ), "fileprint", CTRL + Key_P, this, SLOT( print() ), actionCollection(), "kaddressbook_print" ); } else { mActionMail = KStdAction::mail( this, SLOT( sendMail() ), actionCollection() ); mActionPrint = KStdAction::print( this, SLOT( print() ), actionCollection() ); } mActionSave = new KAction( i18n( "&Save" ), "filesave", CTRL+Key_S, this, SLOT( save() ), actionCollection(), "file_sync" ); mActionNewContact = new KAction( i18n( "&New Contact..." ), "filenew", CTRL+Key_N, this, SLOT( newContact() ), actionCollection(), "file_new_contact" ); mActionMailVCard = new KAction(i18n("Mail &vCard..."), "mail_post_to", 0, this, SLOT( mailVCard() ), actionCollection(), "file_mail_vcard"); mActionExport2phone = new KAction( i18n( "Selected to phone" ), "ex2phone", 0, this, SLOT( export2phone() ), actionCollection(), "kaddressbook_ex2phone" ); mActionBeamVCard = 0; mActionBeam = 0; #ifndef DESKTOP_VERSION if ( Ir::supported() ) { mActionBeamVCard = new KAction( i18n( "Beam selected v&Card(s)" ), "beam", 0, this, SLOT( beamVCard() ), actionCollection(), "kaddressbook_beam_vcard" ); mActionBeam = new KAction( i18n( "&Beam personal vCard" ), "beam", 0, this, SLOT( beamMySelf() ), actionCollection(), "kaddressbook_beam_myself" ); } #endif mActionEditAddressee = new KAction( i18n( "&Edit Contact..." ), "edit", 0, this, SLOT( editContact2() ), actionCollection(), "file_properties" ); #ifdef KAB_EMBEDDED // mActionQuit = KStdAction::quit( mMainWindow, SLOT( exit() ), actionCollection() ); mActionQuit = new KAction( i18n( "&Exit" ), "exit", 0, mMainWindow, SLOT( exit() ), actionCollection(), "quit" ); #endif //KAB_EMBEDDED // edit menu if ( mIsPart ) { mActionCopy = new KAction( i18n( "&Copy" ), "editcopy", CTRL + Key_C, this, @@ -2769,103 +2769,113 @@ bool KABCore::sync(KSyncManager* manager, QString filename, int mode) for ( it = abLocal.begin(); it != abLocal.end(); ++it ) { if ( (*it).revision().date().year() > 2003 ) { found = true; break; } } external = ! found; } if ( external ) { qDebug("Setting vcf mode to external "); mGlobalSyncMode = SYNC_MODE_EXTERNAL; AddressBook::Iterator it; for ( it = abLocal.begin(); it != abLocal.end(); ++it ) { (*it).setID( mCurrentSyncDevice, (*it).uid() ); (*it).computeCsum( mCurrentSyncDevice ); } } } //AddressBook::Iterator it; //QStringList vcards; //for ( it = abLocal.begin(); it != abLocal.end(); ++it ) { // qDebug("Name %s ", (*it).familyName().latin1()); //} syncOK = synchronizeAddressbooks( mAddressBook, &abLocal, mode ); if ( syncOK ) { if ( syncManager->mWriteBackFile ) { if ( external ) abLocal.removeSyncAddressees( !isXML); qDebug("Saving remote AB "); abLocal.saveAB(); if ( isXML ) { // afterwrite processing abLocal.postExternSync( mAddressBook,mCurrentSyncDevice ); } } } setModified(); } if ( syncOK ) mViewManager->refreshView(); return syncOK; #if 0 if ( storage->load(KOPrefs::instance()->mUseQuicksave) ) { getEventViewerDialog()->setSyncMode( true ); syncOK = synchronizeCalendar( mCalendar, calendar, mode ); getEventViewerDialog()->setSyncMode( false ); if ( syncOK ) { if ( KOPrefs::instance()->mWriteBackFile ) { storage->setSaveFormat( new ICalFormat( KOPrefs::instance()->mUseQuicksave) ); storage->save(); } } setModified(); } #endif } //this is a overwritten callbackmethods from the syncinterface bool KABCore::syncExternal(KSyncManager* manager, QString resource) { QString mCurrentSyncDevice = manager->getCurrentSyncDevice(); AddressBook abLocal( resource,"syncContact"); bool syncOK = false; if ( abLocal.load() ) { qDebug("AB sharp loaded ,sync device %s",mCurrentSyncDevice.latin1()); mGlobalSyncMode = SYNC_MODE_EXTERNAL; abLocal.preExternSync( mAddressBook ,mCurrentSyncDevice ); syncOK = synchronizeAddressbooks( mAddressBook, &abLocal, syncManager->mSyncAlgoPrefs ); if ( syncOK ) { if ( syncManager->mWriteBackFile ) { abLocal.saveAB(); abLocal.postExternSync( mAddressBook,mCurrentSyncDevice ); } } setModified(); } if ( syncOK ) mViewManager->refreshView(); return syncOK; } 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 @@ -250,230 +250,232 @@ class KABCore : public QWidget, public KSyncInterface Marks the address book as modified. */ void setModified(); /** Marks the address book as modified without refreshing the view. */ void setModifiedWOrefresh(); /** Marks the address book as modified concerning the argument. */ void setModified( bool modified ); /** Returns whether the address book is modified. */ bool modified() const; /** Called whenever an contact is modified in the contact editor dialog or the quick edit. */ void contactModified( const KABC::Addressee &addr ); /** DCOP METHODS. */ void addEmail( QString addr ); void importVCard( const KURL& url, bool showPreview ); void importVCard( const QString& vCard, bool showPreview ); void newContact(); QString getNameByPhone( const QString& phone ); /** END DCOP METHODS */ /** Saves the contents of the AddressBook back to disk. */ void save(); /** Undos the last command using the undo stack. */ void undo(); /** Redos the last command that was undone, using the redo stack. */ void redo(); /** Shows the edit dialog for the given uid. If the uid is QString::null, the method will try to find a selected addressee in the view. */ void editContact( const QString &uid /*US = QString::null*/ ); //US added a second method without defaultparameter void editContact2(); /** Shows or edits the detail view for the given uid. If the uid is QString::null, the method will try to find a selected addressee in the view. */ void executeContact( const QString &uid /*US = QString::null*/ ); /** Launches the configuration dialog. */ void openConfigDialog(); /** Launches the ldap search dialog. */ void openLDAPDialog(); /** Creates a KAddressBookPrinter, which will display the print dialog and do the printing. */ void print(); /** Registers a new GUI client, so plugins can register its actions. */ void addGUIClient( KXMLGUIClient *client ); void requestForNameEmailUidList(const QString& sourceChannel, const QString& sessionuid); void requestForDetails(const QString& sourceChannel, const QString& sessionuid, const QString& name, const QString& email, const QString& uid); 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 ); void clipboardDataChanged(); void updateActionMenu(); void configureKeyBindings(); void removeVoice(); #ifdef KAB_EMBEDDED void configureResources(); #endif //KAB_EMBEDDED void slotEditorDestroyed( const QString &uid ); void configurationChanged(); void addressBookChanged(); private: void initGUI(); void initActions(); AddresseeEditorDialog *createAddresseeEditorDialog( QWidget *parent, const char *name = 0 ); KXMLGUIClient *mGUIClient; KABC::AddressBook *mAddressBook; ViewManager *mViewManager; // QSplitter *mDetailsSplitter; KDGanttMinimizeSplitter *mExtensionBarSplitter; ViewContainer *mDetails; KDGanttMinimizeSplitter* mMiniSplitter; XXPortManager *mXXPortManager; JumpButtonBar *mJumpButtonBar; IncSearchWidget *mIncSearchWidget; ExtensionManager *mExtensionManager; KCMultiDialog *mConfigureDialog; #ifndef KAB_EMBEDDED LDAPSearchDialog *mLdapSearchDialog; #endif //KAB_EMBEDDED // QDict<AddresseeEditorDialog> mEditorDict; AddresseeEditorDialog *mEditorDialog; bool mReadWrite; bool mModified; bool mIsPart; bool mMultipleViewsAtOnce; //US file menu KAction *mActionMail; KAction *mActionBeam; KAction *mActionExport2phone; KAction* mActionPrint; KAction* mActionNewContact; KAction *mActionSave; KAction *mActionEditAddressee; KAction *mActionMailVCard; KAction *mActionBeamVCard; KAction *mActionQuit; //US edit menu KAction *mActionCopy; KAction *mActionCut; KAction *mActionPaste; KAction *mActionSelectAll; KAction *mActionUndo; KAction *mActionRedo; KAction *mActionDelete; //US settings menu KAction *mActionConfigResources; KAction *mActionConfigKAddressbook; KAction *mActionConfigShortcuts; KAction *mActionConfigureToolbars; KAction *mActionKeyBindings; KToggleAction *mActionJumpBar; KToggleAction *mActionDetails; KAction *mActionWhoAmI; KAction *mActionCategories; KAction *mActionAboutKAddressbook; KAction *mActionLicence; KAction *mActionFaq; KAction *mActionDeleteView; QPopupMenu *viewMenu; QPopupMenu *filterMenu; QPopupMenu *settingsMenu; QPopupMenu *changeMenu; //US QAction *mActionSave; QPopupMenu *ImportMenu; QPopupMenu *ExportMenu; //LR additional methods KAction *mActionRemoveVoice; KAction * mActionImportOL; #ifndef KAB_EMBEDDED KAddressBookService *mAddressBookService; #endif //KAB_EMBEDDED class KABCorePrivate; KABCorePrivate *d; //US bool mBlockSaveFlag; #ifdef KAB_EMBEDDED KAddressBookMain *mMainWindow; // should be the same like mGUIClient #endif //KAB_EMBEDDED //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 ); // ********************* }; #endif 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 @@ -28,192 +28,193 @@ Copyright (c) 2004 Ulf Schenk $Id$ */ #include <qfile.h> #include <qtextstream.h> #include <kabc/vcardconverter.h> #include <kabc/vcardparser/vcardtool.h> #include <kfiledialog.h> #ifndef KAB_EMBEDDED #include <kio/netaccess.h> #endif //KAB_EMBEDDED #include <klocale.h> #include <kmessagebox.h> #include <ktempfile.h> #include <kurl.h> #include "xxportmanager.h" #include "vcard_xxport.h" #ifndef KAB_EMBEDDED class VCardXXPortFactory : public XXPortFactory { public: XXPortObject *xxportObject( KABC::AddressBook *ab, QWidget *parent, const char *name ) { return new VCardXXPort( ab, parent, name ); } }; #endif //KAB_EMBEDDED extern "C" { #ifndef KAB_EMBEDDED void *init_libkaddrbk_vcard_xxport() #else //KAB_EMBEDDED void *init_microkaddrbk_vcard_xxport() #endif //KAB_EMBEDDED { return ( new VCardXXPortFactory() ); } } VCardXXPort::VCardXXPort( KABC::AddressBook *ab, QWidget *parent, const char *name ) : XXPortObject( ab, parent, name ) { createImportAction( i18n( "Import vCard..." ) ); //US KABC::VCardConverter does not support the export of 2.1 addressbooks. //US createExportAction( i18n( "Export vCard 2.1..." ), "v21" ); createExportAction( i18n( "Export vCard 3.0..." ), "v30" ); } bool VCardXXPort::exportContacts( const KABC::AddresseeList &list, const QString &data ) { QString name; if ( list.count() == 1 ) name = list[ 0 ].givenName() + "_" + list[ 0 ].familyName() + ".vcf"; else name = "addressbook.vcf"; #ifndef KAB_EMBEDDED QString fileName = KFileDialog::getSaveFileName( name ); #else //KAB_EMBEDDED QString fileName = KFileDialog::getSaveFileName( name, i18n("Save file"), parentWidget() ); #endif //KAB_EMBEDDED if ( fileName.isEmpty() ) return false; QFile outFile( fileName ); if ( !outFile.open( IO_WriteOnly ) ) { QString text = i18n( "<qt>Unable to open file <b>%1</b> for export.</qt>" ); KMessageBox::error( parentWidget(), text.arg( fileName ) ); return false; } QTextStream t( &outFile ); t.setEncoding( QTextStream::UnicodeUTF8 ); KABC::Addressee::List::ConstIterator it; for ( it = list.begin(); it != list.end(); ++it ) { KABC::VCardConverter converter; 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; } KABC::AddresseeList VCardXXPort::importContacts( const QString& ) const { QString fileName; KABC::AddresseeList addrList; KURL url; #ifndef KAB_EMBEDDED if ( !XXPortManager::importData.isEmpty() ) addrList = parseVCard( XXPortManager::importData ); else { if ( XXPortManager::importURL.isEmpty() ) { url = KFileDialog::getLoadFileName( QString::null, i18n("Select vCard to Import"), parentWidget() ); } else url = XXPortManager::importURL; if ( url.isEmpty() ) return addrList; QString caption( i18n( "vCard Import Failed" ) ); if ( KIO::NetAccess::download( url, fileName ) ) { QFile file( fileName ); file.open( IO_ReadOnly ); QByteArray rawData = file.readAll(); file.close(); QString data = QString::fromUtf8( rawData.data(), rawData.size() + 1 ); addrList = parseVCard( data ); if ( !url.isLocalFile() ) KIO::NetAccess::removeTempFile( fileName ); } else { QString text = i18n( "<qt>Unable to access <b>%1</b>.</qt>" ); KMessageBox::error( parentWidget(), text.arg( url.url() ), caption ); } } #else //KAB_EMBEDDED if ( !XXPortManager::importData.isEmpty() ) addrList = parseVCard( XXPortManager::importData ); else { if ( XXPortManager::importURL.isEmpty() ) { fileName = KFileDialog::getOpenFileName( QString::null, i18n("Select vCard to Import"), parentWidget() ); if ( fileName.isEmpty() ) return addrList; } else { //US url = XXPortManager::importURL; qDebug("VCardXXPort::importContacts Urls at the moment not supported"); if ( url.isEmpty() ) return addrList; } QFile file( fileName ); file.open( IO_ReadOnly ); QByteArray rawData = file.readAll(); file.close(); QString data = QString::fromUtf8( rawData.data(), rawData.size() + 1 ); addrList = parseVCard( data ); } #endif //KAB_EMBEDDED return addrList; } KABC::AddresseeList VCardXXPort::parseVCard( const QString &data ) const { KABC::VCardTool tool; KABC::AddresseeList addrList; addrList = tool.parseVCards( data ); // LR : I switched to the code, which is in current cvs HEAD diff --git a/libkdepim/ksyncmanager.cpp b/libkdepim/ksyncmanager.cpp index 5d48884..ea543dd 100644 --- a/libkdepim/ksyncmanager.cpp +++ b/libkdepim/ksyncmanager.cpp @@ -182,193 +182,194 @@ void KSyncManager::slotSyncMenu( int action ) mShowSyncSummary = temp->getShowSummaryAfterSync(); if ( action == 1000 ) { syncSharp(); } else if ( action == 1001 ) { syncLocalFile(); } else if ( action == 1002 ) { quickSyncLocalFile(); } else if ( action >= 1003 ) { if ( temp->getIsLocalFileSync() ) { switch(mTargetApp) { case (KAPI): if ( syncWithFile( temp->getRemoteFileNameAB( ), false ) ) mLastSyncedLocalFile = temp->getRemoteFileNameAB(); break; case (KOPI): if ( syncWithFile( temp->getRemoteFileName( ), false ) ) mLastSyncedLocalFile = temp->getRemoteFileName(); break; case (PWMPI): if ( syncWithFile( temp->getRemoteFileNamePWM( ), false ) ) mLastSyncedLocalFile = temp->getRemoteFileNamePWM(); break; default: qDebug("KSyncManager::slotSyncMenu: invalid apptype selected"); break; } } else { if ( temp->getIsPhoneSync() ) { mPhoneDevice = temp->getPhoneDevice( ) ; mPhoneConnection = temp->getPhoneConnection( ); mPhoneModel = temp->getPhoneModel( ); syncPhone(); } else if ( temp->getIsPiSync() ) { mPassWordPiSync = temp->getRemotePw(); mActiveSyncPort = temp->getRemotePort(); mActiveSyncIP = temp->getRemoteIP(); syncPi(); } syncRemote( temp ); } } delete temp; setBlockSave(false); } void KSyncManager::enableQuick() { QDialog dia ( 0, "input-dialog", true ); QLineEdit lab ( &dia ); QVBoxLayout lay( &dia ); lab.setText( mPrefs->mPassiveSyncPort ); lay.setMargin(7); lay.setSpacing(7); int po = 9197+mTargetApp; QLabel label ( i18n("Port number (Default: %1)").arg(po), &dia ); lay.addWidget( &label); lay.addWidget( &lab); QLineEdit lepw ( &dia ); lepw.setText( mPrefs->mPassiveSyncPw ); QLabel label2 ( i18n("Password to enable\naccess from remote:"), &dia ); lay.addWidget( &label2); lay.addWidget( &lepw); dia.setFixedSize( 230,80 ); dia.setCaption( i18n("Enter port for Pi-Sync") ); QPushButton pb ( "OK", &dia); lay.addWidget( &pb ); connect(&pb, SIGNAL( clicked() ), &dia, SLOT ( accept() ) ); dia.show(); if ( ! dia.exec() ) return; dia.hide(); qApp->processEvents(); mPrefs->mPassiveSyncPw = lepw.text(); mPrefs->mPassiveSyncPort = lab.text(); bool ok; Q_UINT16 port = mPrefs->mPassiveSyncPort.toUInt(&ok); if ( ! ok ) { KMessageBox::information( 0, i18n("No valid port")); return; } //qDebug("port %d ", port); mServerSocket = new KServerSocket ( mPrefs->mPassiveSyncPw, port ,1 ); 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; switch(mTargetApp) { case (KAPI): ext = "(*.vcf)"; break; case (KOPI): ext = "(*.ics/*.vcs)"; break; case (PWMPI): ext = "(*.pwm)"; break; default: qDebug("KSyncManager::syncLocalFile: invalid apptype selected"); break; } fn =KFileDialog:: getOpenFileName( fn, i18n("Sync filename"+ext), mParent ); if ( fn == "" ) return; if ( syncWithFile( fn, false ) ) { qDebug("syncLocalFile() successful "); } } bool KSyncManager::syncWithFile( QString fn , bool quick ) { bool ret = false; QFileInfo info; info.setFile( fn ); QString mess; bool loadbup = true; if ( !info. exists() ) { mess = i18n( "Sync file \n...%1\ndoes not exist!\nNothing synced!\n").arg(fn.right( 30) ); int result = QMessageBox::warning( mParent, i18n("Warning!"), mess ); return ret; } int result = 0; if ( !quick ) { mess = i18n("Sync with file \n...%1\nfrom:\n%2\n").arg(fn.right( 25)).arg(KGlobal::locale()->formatDateTime(info.lastModified (), true, false )); result = QMessageBox::warning( mParent, i18n("Warning!"), mess, i18n("Sync"), i18n("Cancel"), 0, 0, 1 ); if ( result ) return false; } if ( mAskForPreferences ) edit_sync_options(); if ( result == 0 ) { //qDebug("Now sycing ... "); if ( ret = mImplementation->sync( this, fn, mSyncAlgoPrefs ) ) mParent->setCaption( i18n("Synchronization successful") ); else mParent->setCaption( i18n("Sync cancelled or failed. Nothing synced.") ); if ( ! quick ) mLastSyncedLocalFile = fn; } return ret; } void KSyncManager::quickSyncLocalFile() { if ( syncWithFile( mLastSyncedLocalFile, false ) ) { qDebug("quick syncLocalFile() successful "); } } void KSyncManager::multiSync( bool askforPrefs ) { if (blockSave()) return; setBlockSave(true); QString question = i18n("Do you really want\nto multiple sync\nwith all checked profiles?\nSyncing takes some\ntime - all profiles\nare synced twice!"); if ( QMessageBox::information( mParent, i18n("Sync"), question, i18n("Yes"), i18n("No"), 0, 0 ) != 0 ) { setBlockSave(false); mParent->setCaption(i18n("Aborted! Nothing synced!")); return; } mCurrentSyncDevice = i18n("Multiple profiles") ; mSyncAlgoPrefs = mRingSyncAlgoPrefs; if ( askforPrefs ) { edit_sync_options(); @@ -835,193 +836,193 @@ void KSyncManager::readFileFromSocket() KServerSocket:: KServerSocket ( QString pw, Q_UINT16 port, int backlog, QObject * parent, const char * name ) : QServerSocket( port, backlog, parent, name ) { mPassWord = pw; mSocket = 0; mSyncActionDialog = 0; blockRC = false; }; void KServerSocket::newConnection ( int socket ) { // qDebug("KServerSocket:New connection %d ", socket); if ( mSocket ) { qDebug("KServerSocket::newConnection Socket deleted! "); delete mSocket; mSocket = 0; } mSocket = new QSocket( this ); connect( mSocket , SIGNAL(readyRead()), this, SLOT(readClient()) ); connect( mSocket , SIGNAL(delayedCloseFinished()), this, SLOT(discardClient()) ); mSocket->setSocket( socket ); } void KServerSocket::discardClient() { //qDebug(" KServerSocket::discardClient()"); if ( mSocket ) { delete mSocket; mSocket = 0; } //emit endConnect(); } void KServerSocket::readClient() { if ( blockRC ) return; if ( mSocket == 0 ) { qDebug("ERROR::KServerSocket::readClient(): mSocket == 0 "); return; } qDebug("KServerSocket readClient()"); if ( mSocket->canReadLine() ) { QString line = mSocket->readLine(); qDebug("KServerSocket readline: %s ", line.latin1()); QStringList tokens = QStringList::split( QRegExp("[ \r\n][ \r\n]*"), line ); if ( tokens[0] == "GET" ) { if ( tokens[1] == mPassWord ) //emit sendFile( mSocket ); send_file(); else { KMessageBox::information( 0, i18n("ERROR:\nGot send file request\nwith invalid password")); qDebug("password %s, invalid password %s ",mPassWord.latin1(), tokens[1].latin1() ); } } if ( tokens[0] == "PUT" ) { if ( tokens[1] == mPassWord ) { //emit getFile( mSocket ); blockRC = true; get_file(); } else { KMessageBox::information( 0, i18n("ERROR:\nGot receive file request\nwith invalid password")); qDebug("password %s, invalid password %s ",mPassWord.latin1(), tokens[1].latin1() ); } } if ( tokens[0] == "STOP" ) { //emit endConnect(); end_connect(); } } } void KServerSocket::end_connect() { delete mSyncActionDialog; mSyncActionDialog = 0; } void KServerSocket::send_file() { //qDebug("MainWindow::sendFile(QSocket* s) "); if ( mSyncActionDialog ) delete mSyncActionDialog; mSyncActionDialog = new QDialog ( 0, "input-dialog", true ); mSyncActionDialog->setCaption(i18n("Received sync request")); 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(); if ( mSocket->state() == QSocket::Idle ) QTimer::singleShot( 10, this , SLOT ( discardClient())); return ; } mSyncActionDialog->setCaption( i18n("Sending file...") ); QTextStream ts( &file ); ts.setCodec( QTextCodec::codecForName("utf8") ); QTextStream os( mSocket ); os.setCodec( QTextCodec::codecForName("utf8") ); //os.setEncoding( QTextStream::UnicodeUTF8 ); while ( ! ts.atEnd() ) { os << ts.readLine() << "\n"; } //os << ts.read(); file.close(); mSyncActionDialog->setCaption( i18n("Waiting for synced file...") ); mSocket->close(); if ( mSocket->state() == QSocket::Idle ) QTimer::singleShot( 10, this , SLOT ( discardClient())); } void KServerSocket::get_file() { mSyncActionDialog->setCaption( i18n("Receiving synced file...") ); piTime.start(); piFileString = ""; QTimer::singleShot( 1, this , SLOT (readBackFileFromSocket( ) )); } void KServerSocket::readBackFileFromSocket() { //qDebug("readBackFileFromSocket() %d ", piTime.elapsed ()); while ( mSocket->canReadLine () ) { piTime.restart(); QString line = mSocket->readLine (); piFileString += line; //qDebug("readline: %s ", line.latin1()); mSyncActionDialog->setCaption( i18n("Received %1 bytes").arg( piFileString.length() ) ); } if ( piTime.elapsed () < 3000 ) { // wait for more //qDebug("waitformore "); QTimer::singleShot( 100, this , SLOT (readBackFileFromSocket( ) )); return; } QString fileName = mFileName; QFile file ( fileName ); if (!file.open( IO_WriteOnly ) ) { delete mSyncActionDialog; mSyncActionDialog = 0; qDebug("error open cal file "); piFileString = ""; emit file_received( false ); blockRC = false; return ; } // mView->setLoadedFileVersion(QDateTime::currentDateTime().addSecs( -1)); QTextStream ts ( &file ); ts.setCodec( QTextCodec::codecForName("utf8") ); mSyncActionDialog->setCaption( i18n("Writing file to disk...") ); ts << piFileString; mSocket->close(); if ( mSocket->state() == QSocket::Idle ) QTimer::singleShot( 10, this , SLOT ( discardClient())); file.close(); delete mSyncActionDialog; mSyncActionDialog = 0; piFileString = ""; blockRC = false; emit file_received( true ); } KCommandSocket::KCommandSocket ( QString password, Q_UINT16 port, QString host, QObject * parent, const char * name ): QObject( parent, name ) { mPassWord = password; mSocket = 0; mPort = port; mHost = host; mRetVal = quiet; mTimerSocket = new QTimer ( this ); connect( mTimerSocket, SIGNAL ( timeout () ), this, SLOT ( deleteSocket() ) ); diff --git a/libkdepim/ksyncmanager.h b/libkdepim/ksyncmanager.h index 52e2772..0eb3323 100644 --- a/libkdepim/ksyncmanager.h +++ b/libkdepim/ksyncmanager.h @@ -1,228 +1,227 @@ /* This file is part of KDE-Pim/Pi. Copyright (c) 2004 Ulf Schenk This library is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with this library; see the file COPYING.LIB. If not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. $Id$ */ #ifndef _KSYNCMANAGER_H #define _KSYNCMANAGER_H #include <qobject.h> #include <qstring.h> #include <qsocket.h> #include <qdatetime.h> #include <qserversocket.h> #include <qtextstream.h> #include <qregexp.h> class QPopupMenu; class KSyncProfile; class KPimPrefs; class QWidget; class KSyncManager; class KSyncInterface; class QProgressBar; class KServerSocket : public QServerSocket { Q_OBJECT 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; void send_file(); void get_file(); void end_connect(); QDialog* mSyncActionDialog; QSocket* mSocket; QString mPassWord; QString mFileName; QTime piTime; QString piFileString; }; class KCommandSocket : public QObject { Q_OBJECT public: enum state { successR, errorR, successW, errorW, quiet }; KCommandSocket ( QString password, Q_UINT16 port, QString host, QObject * parent=0, const char * name=0 ); void readFile( QString ); void writeFile( QString ); void sendStop(); signals: void commandFinished( KCommandSocket*, int ); private slots: void startReadFileFromSocket(); void readFileFromSocket(); void deleteSocket(); void writeFileToSocket(); private : QSocket* mSocket; QString mPassWord; Q_UINT16 mPort; QString mHost; QString mFileName; QTimer* mTimerSocket; int mRetVal; QTime mTime; QString mFileString; bool mFirst; }; class KSyncManager : public QObject { Q_OBJECT public: enum TargetApp { KOPI = 0, KAPI = 1, PWMPI = 2 }; KSyncManager(QWidget* parent, KSyncInterface* implementation, TargetApp ta, KPimPrefs* prefs, QPopupMenu* syncmenu); ~KSyncManager() ; bool blockSave() { return mBlockSaveFlag; } void setBlockSave(bool sa) { mBlockSaveFlag = sa; } void setDefaultFileName( QString s) { mDefFileName = s ;} QString defaultFileName() { return mDefFileName ;} QString syncFileName(); void fillSyncMenu(); QString getCurrentSyncDevice() { return mCurrentSyncDevice; } QString getCurrentSyncName() { return mCurrentSyncName; } void showProgressBar(int percentage, QString caption = QString::null, int total=100); void hideProgressBar(); bool isProgressBarCanceled(); // sync stuff QString mLocalMachineName; QStringList mExternSyncProfiles; QStringList mSyncProfileNames; bool mAskForPreferences; bool mShowSyncSummary; bool mShowSyncEvents; bool mShowTodoInAgenda; bool mWriteBackExistingOnly; int mSyncAlgoPrefs; int mRingSyncAlgoPrefs; bool mWriteBackFile; int mWriteBackInFuture; QString mPhoneDevice; QString mPhoneConnection; 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! void syncPi(); void deleteCommandSocket(KCommandSocket*s, int state); void readFileFromSocket(); KServerSocket * mServerSocket; void enableQuick(); KPimPrefs* mPrefs; QString mDefFileName; QString mCurrentSyncDevice; QString mCurrentSyncName; void quickSyncLocalFile(); bool syncWithFile( QString fn , bool quick ); void syncLocalFile(); void syncPhone(); void syncSharp(); bool syncExternalApplication(QString); void multiSync( bool askforPrefs ); int mCurrentSyncProfile ; void syncRemote( KSyncProfile* prof, bool ask = true); void edit_sync_options(); int ringSync(); QString getPassword( ); private slots: void confSync(); // ********************* private: bool mBlockSaveFlag; QWidget* mParent; KSyncInterface* mImplementation; TargetApp mTargetApp; QPopupMenu* mSyncMenu; QProgressBar* bar; }; class KSyncInterface { public : virtual bool sync(KSyncManager* manager, QString filename, int mode) = 0; virtual bool syncExternal(KSyncManager* manager, QString resource) { // empty implementation, because some syncable applications do not have an external(sharpdtm) syncmode, like pwmanager. return false; } }; #endif |