summaryrefslogtreecommitdiffabout
Side-by-side diff
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--kaddressbook/kabcore.cpp31
-rw-r--r--kaddressbook/kabcore.h7
-rw-r--r--korganizer/koprefs.cpp2
-rw-r--r--korganizer/koprefs.h3
-rw-r--r--korganizer/mainwindow.cpp321
-rw-r--r--korganizer/mainwindow.h70
-rw-r--r--libkdepim/kpimprefs.cpp3
-rw-r--r--libkdepim/kpimprefs.h3
-rw-r--r--libkdepim/ksyncmanager.cpp567
-rw-r--r--libkdepim/ksyncmanager.h107
10 files changed, 646 insertions, 468 deletions
diff --git a/kaddressbook/kabcore.cpp b/kaddressbook/kabcore.cpp
index d9eb391..83fede4 100644
--- a/kaddressbook/kabcore.cpp
+++ b/kaddressbook/kabcore.cpp
@@ -1662,48 +1662,52 @@ void KABCore::initGUI()
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( getFile( bool )), this, SLOT(getFile( bool ) ) );
+ syncManager->setDefaultFileName(locateLocal( "apps","kabc/std.vcf") );
+ //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 );
@@ -2816,61 +2820,52 @@ bool KABCore::sync(KSyncManager* manager, QString filename, int mode)
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 );
- qDebug("KABCore::syncExternal: why do we acces here KABPrefs and not somehow KSyncProfile? ");
syncOK = synchronizeAddressbooks( mAddressBook, &abLocal, syncManager->mSyncAlgoPrefs );
if ( syncOK ) {
if ( syncManager->mWriteBackFile ) {
abLocal.saveAB();
abLocal.postExternSync( mAddressBook,mCurrentSyncDevice );
}
}
setModified();
}
if ( syncOK )
mViewManager->refreshView();
return syncOK;
}
-//called by the syncmanager to indicate that the work has to marked as dirty.
-void KABCore::sync_setModified()
+void KABCore::getFile( bool success )
{
- setModified();
-}
-
-//called by the syncmanager to ask if the dirty flag is set.
-bool KABCore::sync_isModified()
-{
- return mModified;
-}
-
-
-//called by the syncmanager to indicate that the work has to be saved.
-void KABCore::sync_save()
-{
- save();
+ if ( ! success ) {
+ setCaption( i18n("Error receiving file. Nothing changed!") );
+ return;
+ }
+ //mView->watchSavedFile();
+ //mView->openCalendar( defaultFileName() );
+ // pending: reload received file!
+ setCaption( i18n("Pi-Sync successful!") );
}
-
diff --git a/kaddressbook/kabcore.h b/kaddressbook/kabcore.h
index c9c0d38..355e828 100644
--- a/kaddressbook/kabcore.h
+++ b/kaddressbook/kabcore.h
@@ -321,48 +321,49 @@ class KABCore : public QWidget, public KSyncInterface
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 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();
@@ -440,45 +441,39 @@ class KABCore : public QWidget, public KSyncInterface
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);
- //called by the syncmanager to indicate that the work has to marked as dirty.
- virtual void sync_setModified();
- //called by the syncmanager to ask if the dirty flag is set.
- virtual bool sync_isModified();
- //called by the syncmanager to indicate that the work has to be saved.
- virtual void sync_save();
// LR *******************************
// sync stuff!
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/korganizer/koprefs.cpp b/korganizer/koprefs.cpp
index 84e3d00..1210094 100644
--- a/korganizer/koprefs.cpp
+++ b/korganizer/koprefs.cpp
@@ -171,50 +171,48 @@ KOPrefs::KOPrefs() :
addItemFont("TimeBar Font",&mTimeBarFont);
addItemFont("MonthView Font",&mMonthViewFont);
addItemFont("AgendaView Font",&mAgendaViewFont);
addItemFont("MarcusBains Font",&mMarcusBainsFont);
addItemFont("TimeLabels Font",&mTimeLabelsFont);
addItemFont("TodoView Font",&mTodoViewFont);
addItemFont("ListView Font",&mListViewFont);
addItemFont("DateNavigator Font",&mDateNavigatorFont);
addItemFont("EditBox Font",&mEditBoxFont);
addItemFont("JournalView Font",&mJornalViewFont);
addItemFont("WhatsNextView Font",&mWhatsNextFont);
addItemFont("EventView Font",&mEventViewFont);
// KPrefs::setCurrentGroup("SyncProfiles");
// addItemString("LocalMachineName",&mLocalMachineName, "undefined");
// addItemStringList("SyncProfileNames",&mSyncProfileNames);
// addItemStringList("ExternSyncProfiles",&mExternSyncProfileNames);
KPrefs::setCurrentGroup("RemoteSyncing");
// addItemBool("UsePasswd",&mUsePassWd,false);
// addItemBool("WriteBackFile",&mWriteBackFile,true);
// addItemBool("WriteBackExistingOnly",&mWriteBackExistingOnly,false);
// addItemBool("AskForPreferences",&mAskForPreferences,true);
// addItemBool("ShowSyncSummary",&mShowSyncSummary,true);
- addItemString("PassiveSyncPort",&mPassiveSyncPort,"9197" );
- addItemString("PassiveSyncPw",&mPassiveSyncPw,"abc" );
addItemString("ActiveSyncPort",&mActiveSyncPort,"9197" );
addItemString("ActiveSyncIP",&mActiveSyncIP,"192.168.0.40" );
addItemBool("ShowSyncEvents",&mShowSyncEvents,false);
addItemInt("LastSyncTime",&mLastSyncTime,0);
addItemInt("SyncAlgoPrefs",&mSyncAlgoPrefs,3);
addItemInt("RingSyncAlgoPrefs",&mRingSyncAlgoPrefs,3);
#ifdef _WIN32_
QString hdp= locateLocal("data","korganizer")+"\\\\";
#else
QString hdp= locateLocal("data","korganizer")+"/";
#endif
// addItemString("RemoteIP",&mRemoteIP, "192.168.0.65");
// addItemString("RemoteUser",&mRemoteUser, "zaurus");
// addItemString("RemotePassWd",&mRemotePassWd, "");
// addItemString("RemoteFile", &mRemoteFile, hdp+"mycalendar.ics");
// addItemString("LocalTempFile",&mLocalTempFile, "/tmp/tempsyncfile.ics" );
KPrefs::setCurrentGroup("LoadSaveFileNames");
addItemString("LastImportFile", &mLastImportFile ,hdp +"import.ics" );
addItemString("LastVcalFile", &mLastVcalFile ,hdp +"export.vcs" );
addItemString("LastSaveFile", &mLastSaveFile ,hdp +"mybackup.ics" );
diff --git a/korganizer/koprefs.h b/korganizer/koprefs.h
index d9ac851..ff09e19 100644
--- a/korganizer/koprefs.h
+++ b/korganizer/koprefs.h
@@ -257,50 +257,49 @@ class KOPrefs : public KPimPrefs
bool mHighlightCurrentDay;
bool mUseHighlightLightColor;
bool mListViewMonthTimespan;
bool mWNViewShowsParents;
bool mWNViewShowLocation;
bool mTodoViewShowsPercentage;
bool mTodoViewUsesCatColors;
bool mTodoViewUsesSmallFont;
bool mTodoViewUsesForegroundColor;
bool mMonthViewUsesForegroundColor;
bool mHightlightDateTimeEdit;
bool mShortDateInViewer;
QStringList mLocationDefaults;
QStringList mEventSummaryUser;
QStringList mTodoSummaryUser;
bool mUseInternalAlarmNotification;
int mAlarmPlayBeeps;
int mAlarmSuspendTime;
int mAlarmSuspendCount;
int mAlarmBeepInterval;
- QString mPassiveSyncPort;
- QString mPassiveSyncPw;
+
QString mActiveSyncPort;
QString mActiveSyncIP;
//US I copied the following settings into KPimGlobalPrefs
// that allows us later to easily remove the settings from here.
int mPreferredDate;
QString mUserDateFormatLong;
QString mUserDateFormatShort;
int mPreferredLanguage;
int mPreferredTime;
bool mWeekStartsOnSunday;
QString mTimeZoneId;
bool mUseDaylightsaving;
int mDaylightsavingStart;
int mDaylightsavingEnd;
private:
QDict<QColor> mCategoryColors;
QColor mDefaultCategoryColor;
QFont mDefaultTimeBarFont;
QFont mDefaultViewFont;
diff --git a/korganizer/mainwindow.cpp b/korganizer/mainwindow.cpp
index 9104347..e3324ee 100644
--- a/korganizer/mainwindow.cpp
+++ b/korganizer/mainwindow.cpp
@@ -109,49 +109,48 @@ class KOex2phonePrefs : public QDialog
QPushButton * ok = new QPushButton( i18n("Export to mobile phone!"), this );
lay->addWidget( ok );
QPushButton * cancel = new QPushButton( i18n("Cancel"), this );
lay->addWidget( cancel );
connect ( ok,SIGNAL(clicked() ),this , SLOT ( accept() ) );
connect (cancel, SIGNAL(clicked() ), this, SLOT ( reject()) );
resize( 220, 240 );
}
public:
QLineEdit* mPhoneConnection, *mPhoneDevice, *mPhoneModel;
QCheckBox* mWriteBackFuture;
QSpinBox* mWriteBackFutureWeeks;
};
int globalFlagBlockStartup;
MainWindow::MainWindow( QWidget *parent, const char *name, QString msg) :
QMainWindow( parent, name )
{
mPassWordPiSync = "abc";
#ifdef DESKTOP_VERSION
setFont( QFont("Arial"), 14 );
#endif
- mSyncActionDialog = 0;
mServerSocket = 0;
mClosed = false;
//QString confFile = KStandardDirs::appDir() + "config/korganizerrc";
QString confFile = locateLocal("config","korganizerrc");
QFileInfo finf ( confFile );
bool showWarning = !finf.exists();
setIcon(SmallIcon( "ko24" ) );
mBlockAtStartup = true;
mFlagKeyPressed = false;
setCaption("KOrganizer/Pi");
KOPrefs *p = KOPrefs::instance();
KPimGlobalPrefs::instance()->setGlobalConfig();
// if ( QApplication::desktop()->height() > 480 ) {
// if ( p->mHourSize == 4 )
// p->mHourSize = 6;
// }
if ( p->mHourSize > 18 )
p->mHourSize = 18;
QMainWindow::ToolBarDock tbd;
if ( p->mToolBarHor ) {
if ( p->mToolBarUp )
tbd = Bottom;
else
tbd = Top;
@@ -2326,344 +2325,24 @@ void MainWindow::syncSharp()
save();
mView->syncSharp();
slotModifiedChanged( true );
}
void MainWindow::syncPhone()
{
if ( mCalendarModifiedFlag )
save();
mView->syncPhone();
slotModifiedChanged( true );
}
void MainWindow::printSel( )
{
mView->viewManager()->agendaView()->agenda()->printSelection();
}
void MainWindow::printCal()
{
mView->print();//mCp->showDialog();
}
-
-
-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();
- 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() ) );
-}
-void KCommandSocket::readFile( QString fn )
-{
- if ( !mSocket ) {
- mSocket = new QSocket( this );
- connect( mSocket, SIGNAL(readyRead()), this, SLOT(startReadFileFromSocket()) );
- connect( mSocket, SIGNAL(delayedCloseFinished ()), this, SLOT(deleteSocket()) );
- }
- mFileString = "";
- mFileName = fn;
- mFirst = true;
- mSocket->connectToHost( mHost, mPort );
- QTextStream os( mSocket );
- os.setEncoding( QTextStream::UnicodeUTF8 );
- os << "GET " << mPassWord << "\r\n";
- mTimerSocket->start( 10000 );
-}
-
-void KCommandSocket::writeFile( QString fileName )
-{
- if ( !mSocket ) {
- mSocket = new QSocket( this );
- connect( mSocket, SIGNAL(delayedCloseFinished ()), this, SLOT(deleteSocket()) );
- connect( mSocket, SIGNAL(connected ()), this, SLOT(writeFileToSocket()) );
- }
- mFileName = fileName ;
- mSocket->connectToHost( mHost, mPort );
-}
-void KCommandSocket::writeFileToSocket()
-{
- QFile file2( mFileName );
- if (!file2.open( IO_ReadOnly ) ) {
- mRetVal= errorW;
- mSocket->close();
- if ( mSocket->state() == QSocket::Idle )
- QTimer::singleShot( 10, this , SLOT ( deleteSocket()));
- return ;
- }
- QTextStream ts2( &file2 );
- ts2.setCodec( QTextCodec::codecForName("utf8") );
- QTextStream os2( mSocket );
- os2.setCodec( QTextCodec::codecForName("utf8") );
- os2 << "PUT " << mPassWord << "\r\n";;
- while ( ! ts2.atEnd() ) {
- os2 << ts2.readLine() << "\n";
- }
- mRetVal= successW;
- file2.close();
- mSocket->close();
- if ( mSocket->state() == QSocket::Idle )
- QTimer::singleShot( 10, this , SLOT ( deleteSocket()));
-}
-void KCommandSocket::sendStop()
-{
- if ( !mSocket ) {
- mSocket = new QSocket( this );
- connect( mSocket, SIGNAL(delayedCloseFinished ()), this, SLOT(deleteSocket()) );
- }
- mSocket->connectToHost( mHost, mPort );
- QTextStream os2( mSocket );
- os2.setCodec( QTextCodec::codecForName("utf8") );
- os2 << "STOP\r\n";
- mSocket->close();
- if ( mSocket->state() == QSocket::Idle )
- QTimer::singleShot( 10, this , SLOT ( deleteSocket()));
-}
-
-void KCommandSocket::startReadFileFromSocket()
-{
- if ( ! mFirst )
- return;
- mFirst = false;
- mTimerSocket->stop();
- mFileString = "";
- mTime.start();
- QTimer::singleShot( 1, this , SLOT (readFileFromSocket( ) ));
-
-}
-void KCommandSocket::readFileFromSocket()
-{
- //qDebug("readBackFileFromSocket() %d ", mTime.elapsed ());
- while ( mSocket->canReadLine () ) {
- mTime.restart();
- QString line = mSocket->readLine ();
- mFileString += line;
- //qDebug("readline: %s ", line.latin1());
- }
- if ( mTime.elapsed () < 3000 ) {
- // wait for more
- //qDebug("waitformore ");
- QTimer::singleShot( 100, this , SLOT (readFileFromSocket( ) ));
- return;
- }
- QString fileName = mFileName;
- QFile file ( fileName );
- if (!file.open( IO_WriteOnly ) ) {
- mFileString = "";
- mRetVal = errorR;
- qDebug("Error open temp calender file for writing: %s",fileName.latin1() );
- deleteSocket();
- return ;
-
- }
- // mView->setLoadedFileVersion(QDateTime::currentDateTime().addSecs( -1));
- QTextStream ts ( &file );
- ts.setCodec( QTextCodec::codecForName("utf8") );
- ts << mFileString;
- file.close();
- mFileString = "";
- mRetVal = successR;
- mSocket->close();
- // if state is not idle, deleteSocket(); is called via
- // connect( mSocket, SIGNAL(delayedCloseFinished ()), this, SLOT(deleteSocket()) );
- if ( mSocket->state() == QSocket::Idle )
- deleteSocket();
-}
-
-void KCommandSocket::deleteSocket()
-{
- if ( mTimerSocket->isActive () ) {
- mTimerSocket->stop();
- KMessageBox::information( 0, i18n("ERROR:\nConnection to remote host timed out!\nDid you forgot to enable\nsyncing on remote host? "));
- mRetVal = errorR;
- }
- //qDebug("KCommandSocket::deleteSocket() %d", mRetVal );
- if ( mSocket)
- delete mSocket;
- mSocket = 0;
- emit commandFinished( this, mRetVal );
-}
-
diff --git a/korganizer/mainwindow.h b/korganizer/mainwindow.h
index 4f89e03..0da0be0 100644
--- a/korganizer/mainwindow.h
+++ b/korganizer/mainwindow.h
@@ -1,115 +1,48 @@
#ifndef KORGE_MAINWINDOW_H
#define KORGE_MAINWINDOW_H
#include <qmainwindow.h>
#include <qtimer.h>
#include <qdict.h>
#include <qfile.h>
-#include <qsocket.h>
#include <qtextstream.h>
#include <qregexp.h>
#include <libkcal/incidence.h>
#include "simplealarmclient.h"
+#include <ksyncmanager.h>
class QAction;
class CalendarView;
class KSyncProfile;
#ifdef DESKTOP_VERSION
#define QPEToolBar QToolBar
#define QPEMenuBar QMenuBar
#endif
class QPEToolBar;
-#include <qserversocket.h>
-#include <qsocket.h>
-#include <qnetworkprotocol.h>
-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 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;
-};
namespace KCal {
class CalendarLocal;
}
using namespace KCal;
class MainWindow : public QMainWindow
{
Q_OBJECT
public:
MainWindow( QWidget *parent = 0, const char *name = 0, QString command = "");
~MainWindow();
public slots:
virtual void showMaximized ();
void configureAgenda( int );
void recieve( const QCString& msg, const QByteArray& data );
static QString defaultFileName();
static QString syncFileName();
static QString resourcePath();
protected slots:
void setCaptionToDates();
int ringSync();
void multiSync( bool askforPrefs = false );
@@ -188,29 +121,28 @@ class MainWindow : public QMainWindow
void keyReleaseEvent ( QKeyEvent * ) ;
QPopupMenu *configureToolBarMenu;
QPopupMenu *selectFilterMenu;
QPopupMenu *configureAgendaMenu, *syncMenu;
CalendarLocal *mCalendar;
CalendarView *mView;
QString getPassword();
QAction *mNewSubTodoAction;
QAction *mShowAction;
QAction *mEditAction;
QAction *mDeleteAction;
QAction *mCloneAction;
QAction *mMoveAction;
QAction *mBeamAction;
QAction *mCancelAction;
void closeEvent( QCloseEvent* ce );
SimpleAlarmClient mAlarmClient;
QTimer mSaveTimer;
bool mBlockSaveFlag;
bool mCalendarModifiedFlag;
QPixmap loadPixmap( QString );
- QDialog * mSyncActionDialog;
};
#endif
diff --git a/libkdepim/kpimprefs.cpp b/libkdepim/kpimprefs.cpp
index a9ea330..0a2f5f1 100644
--- a/libkdepim/kpimprefs.cpp
+++ b/libkdepim/kpimprefs.cpp
@@ -17,48 +17,51 @@
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
As a special exception, permission is given to link this program
with any edition of Qt, and distribute the resulting executable,
without including the source code for Qt in the source distribution.
*/
/*
Enhanced Version of the file for platform independent KDE tools.
Copyright (c) 2004 Ulf Schenk
$Id$
*/
#include <kglobal.h>
#include <kconfig.h>
#include <klocale.h>
#include <kdebug.h>
#include "kpimprefs.h"
KPimPrefs::KPimPrefs( const QString &name ) :
KPrefs( name )
{
+ config()->setGroup("General");
+ addItemString("PassiveSyncPort",&mPassiveSyncPort,"9197" );
+ addItemString("PassiveSyncPw",&mPassiveSyncPw,"abc" );
}
KPimPrefs::~KPimPrefs()
{
}
void KPimPrefs::usrSetDefaults()
{
setCategoryDefaults();
}
void KPimPrefs::usrReadConfig()
{
kdDebug(5300) << "KPimPrefs::usrReadConfig()" << endl;
config()->setGroup("General");
mCustomCategories = config()->readListEntry("Custom Categories");
if (mCustomCategories.isEmpty()) setCategoryDefaults();
}
void KPimPrefs::usrWriteConfig()
{
config()->setGroup("General");
diff --git a/libkdepim/kpimprefs.h b/libkdepim/kpimprefs.h
index 6f92919..fde8093 100644
--- a/libkdepim/kpimprefs.h
+++ b/libkdepim/kpimprefs.h
@@ -34,36 +34,37 @@ $Id$
#include <qstringlist.h>
#include "kprefs.h"
class KPimPrefs : public KPrefs
{
public:
KPimPrefs( const QString &name = QString::null );
virtual ~KPimPrefs();
/** Set preferences to default values */
void usrSetDefaults();
/** Read preferences from config file */
void usrReadConfig();
/** Write preferences to config file */
void usrWriteConfig();
public:
QStringList mCustomCategories;
-
+ QString mPassiveSyncPort;
+ QString mPassiveSyncPw;
protected:
virtual void setCategoryDefaults();
};
#endif
diff --git a/libkdepim/ksyncmanager.cpp b/libkdepim/ksyncmanager.cpp
index c0cc840..5d48884 100644
--- a/libkdepim/ksyncmanager.cpp
+++ b/libkdepim/ksyncmanager.cpp
@@ -11,157 +11,175 @@
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$
#include "ksyncmanager.h"
#include <stdlib.h>
#ifndef _WIN32_
#include <unistd.h>
#endif
#include "ksyncprofile.h"
#include "ksyncprefsdialog.h"
#include "kpimprefs.h"
+#include <kmessagebox.h>
#include <qdir.h>
#include <qprogressbar.h>
#include <qpopupmenu.h>
#include <qpushbutton.h>
#include <qradiobutton.h>
#include <qbuttongroup.h>
#include <qtimer.h>
#include <qmessagebox.h>
#include <qapplication.h>
#include <qlineedit.h>
#include <qdialog.h>
#include <qlayout.h>
+#include <qtextcodec.h>
+#include <qlabel.h>
#include <klocale.h>
#include <kglobal.h>
#include <kconfig.h>
#include <kfiledialog.h>
KSyncManager::KSyncManager(QWidget* parent, KSyncInterface* implementation, TargetApp ta, KPimPrefs* prefs, QPopupMenu* syncmenu)
- : QObject(), mParent(parent), mImplementation(implementation), mTargetApp(ta), mSyncMenu(syncmenu)
+ : QObject(), mParent(parent), mImplementation(implementation), mTargetApp(ta), mPrefs(prefs ),mSyncMenu(syncmenu)
{
+ mServerSocket = 0;
bar = new QProgressBar ( 1, 0 );
bar->setCaption ("");
int w = 300;
if ( QApplication::desktop()->width() < 320 )
w = 220;
int h = bar->sizeHint().height() ;
int dw = QApplication::desktop()->width();
int dh = QApplication::desktop()->height();
bar->setGeometry( (dw-w)/2, (dh - h )/2 ,w,h );
}
KSyncManager::~KSyncManager()
{
delete bar;
}
-
+//LR ok
void KSyncManager::fillSyncMenu()
{
if ( mSyncMenu->count() )
mSyncMenu->clear();
mSyncMenu->insertItem( i18n("Configure..."), 0 );
mSyncMenu->insertSeparator();
+ if ( mServerSocket == 0 ) {
+ mSyncMenu->insertItem( i18n("Enable Pi-Sync"), 2 );
+ } else {
+ mSyncMenu->insertItem( i18n("Disable Pi-Sync"), 3 );
+ }
+ mSyncMenu->insertSeparator();
mSyncMenu->insertItem( i18n("Multiple sync"), 1 );
mSyncMenu->insertSeparator();
KConfig config ( locateLocal( "config","ksyncprofilesrc" ) );
config.setGroup("General");
QStringList prof = config.readListEntry("SyncProfileNames");
mLocalMachineName = config.readEntry("LocalMachineName","undefined");
- if ( prof.count() < 3 ) {
+ if ( prof.count() < 2 ) {
prof.clear();
- prof << i18n("Sharp_DTM");
- prof << i18n("Local_file");
- prof << i18n("Last_file");
+ prof << i18n("Sharp_DTM");
+ prof << i18n("Local_file");
KSyncProfile* temp = new KSyncProfile ();
temp->setName( prof[0] );
temp->writeConfig(&config);
temp->setName( prof[1] );
temp->writeConfig(&config);
- temp->setName( prof[2] );
- temp->writeConfig(&config);
config.setGroup("General");
config.writeEntry("SyncProfileNames",prof);
config.writeEntry("ExternSyncProfiles","Sharp_DTM");
config.sync();
delete temp;
}
mExternSyncProfiles = config.readListEntry("ExternSyncProfiles");
mSyncProfileNames = prof;
unsigned int i;
for ( i = 0; i < prof.count(); ++i ) {
mSyncMenu->insertItem( prof[i], 1000+i );
if ( i == 2 )
mSyncMenu->insertSeparator();
}
QDir app_dir;
//US do not display SharpDTM if app is pwmpi, or no sharpfiles available
if ( mTargetApp == PWMPI) {
mSyncMenu->removeItem( 1000 );
}
else if (!app_dir.exists(QDir::homeDirPath()+"/Applications/dtm" ) ) {
mSyncMenu->setItemEnabled( 1000, false );
}
}
void KSyncManager::slotSyncMenu( int action )
{
//qDebug("syncaction %d ", action);
if ( action == 0 ) {
// seems to be a Qt2 event handling bug
// syncmenu.clear causes a segfault at first time
// when we call it after the main event loop, it is ok
// same behaviour when calling OM/Pi via QCOP for the first time
QTimer::singleShot ( 1, this, SLOT ( confSync() ) );
//confSync();
return;
}
if ( action == 1 ) {
multiSync( true );
return;
}
+ if ( action == 2 ) {
+ enableQuick();
+ QTimer::singleShot ( 1, this, SLOT ( fillSyncMenu() ) );
+ return;
+ }
+ if ( action == 3 ) {
+ delete mServerSocket;
+ mServerSocket = 0;
+ QTimer::singleShot ( 1, this, SLOT ( fillSyncMenu() ) );
+ return;
+ }
if (blockSave())
return;
setBlockSave(true);
mCurrentSyncProfile = action - 1000 ;
mCurrentSyncDevice = mSyncProfileNames[mCurrentSyncProfile] ;
mCurrentSyncName = mLocalMachineName ;
KConfig config ( locateLocal( "config","ksyncprofilesrc" ) );
KSyncProfile* temp = new KSyncProfile ();
temp->setName(mSyncProfileNames[mCurrentSyncProfile]);
temp->readConfig(&config);
mAskForPreferences = temp->getAskForPreferences();
mSyncAlgoPrefs = temp->getSyncPrefs();
mWriteBackFile = temp->getWriteBackFile();
mWriteBackExistingOnly = temp->getWriteBackExisting();
mWriteBackInFuture = 0;
if ( temp->getWriteBackFuture() )
mWriteBackInFuture = temp->getWriteBackFutureWeeks( );
mShowSyncSummary = temp->getShowSummaryAfterSync();
if ( action == 1000 ) {
syncSharp();
@@ -177,56 +195,110 @@ void KSyncManager::slotSyncMenu( int action )
{
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
+ } 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 ( 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;
}
@@ -250,88 +322,87 @@ bool KSyncManager::syncWithFile( QString fn , bool quick )
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;
- mImplementation->sync_setModified();
}
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();
mRingSyncAlgoPrefs = mSyncAlgoPrefs;
}
mParent->setCaption(i18n("Multiple sync started.") );
qApp->processEvents();
int num = ringSync() ;
if ( num > 1 )
ringSync();
setBlockSave(false);
if ( num )
- mImplementation->sync_save();
+ emit save();
if ( num )
mParent->setCaption(i18n("%1 profiles synced. Multiple sync completed!").arg(num) );
else
mParent->setCaption(i18n("Nothing synced! No profiles defined for multisync!"));
return;
}
int KSyncManager::ringSync()
{
int syncedProfiles = 0;
unsigned int i;
QTime timer;
KConfig config ( locateLocal( "config","ksyncprofilesrc" ) );
QStringList syncProfileNames = mSyncProfileNames;
KSyncProfile* temp = new KSyncProfile ();
mAskForPreferences = false;
for ( i = 0; i < syncProfileNames.count(); ++i ) {
mCurrentSyncProfile = i;
temp->setName(syncProfileNames[mCurrentSyncProfile]);
temp->readConfig(&config);
QString includeInRingSync;
switch(mTargetApp)
{
case (KAPI):
@@ -407,68 +478,68 @@ int KSyncManager::ringSync()
}
}
delete temp;
return syncedProfiles;
}
void KSyncManager::syncRemote( KSyncProfile* prof, bool ask)
{
QString question;
if ( ask ) {
question = i18n("Do you really want\nto remote sync\nwith profile \n")+ prof->getName()+" ?\n";
if ( QMessageBox::information( mParent, i18n("Sync"),
question,
i18n("Yes"), i18n("No"),
0, 0 ) != 0 )
return;
}
QString preCommand;
QString localTempFile;
QString postCommand;
switch(mTargetApp)
- {
- case (KAPI):
- preCommand = prof->getPreSyncCommandAB();
- postCommand = prof->getPostSyncCommandAB();
- localTempFile = prof->getLocalTempFileAB();
- break;
- case (KOPI):
- preCommand = prof->getPreSyncCommand();
- postCommand = prof->getPostSyncCommand();
- localTempFile = prof->getLocalTempFile();
- break;
- case (PWMPI):
- preCommand = prof->getPreSyncCommandPWM();
- postCommand = prof->getPostSyncCommandPWM();
- localTempFile = prof->getLocalTempFilePWM();
- break;
- default:
- qDebug("KSyncManager::syncRemote: invalid apptype selected");
- break;
- }
+ {
+ case (KAPI):
+ preCommand = prof->getPreSyncCommandAB();
+ postCommand = prof->getPostSyncCommandAB();
+ localTempFile = prof->getLocalTempFileAB();
+ break;
+ case (KOPI):
+ preCommand = prof->getPreSyncCommand();
+ postCommand = prof->getPostSyncCommand();
+ localTempFile = prof->getLocalTempFile();
+ break;
+ case (PWMPI):
+ preCommand = prof->getPreSyncCommandPWM();
+ postCommand = prof->getPostSyncCommandPWM();
+ localTempFile = prof->getLocalTempFilePWM();
+ break;
+ default:
+ qDebug("KSyncManager::syncRemote: invalid apptype selected");
+ break;
+ }
int fi;
if ( (fi = preCommand.find("$PWD$")) > 0 ) {
QString pwd = getPassword();
preCommand = preCommand.left( fi )+ pwd + preCommand.mid( fi+5 );
}
int maxlen = 30;
if ( QApplication::desktop()->width() > 320 )
maxlen += 25;
mParent->setCaption ( i18n( "Copy remote file to local machine..." ) );
int fileSize = 0;
int result = system ( preCommand );
// 0 : okay
// 256: no such file or dir
//
qDebug("KO: Remote copy result(0 = okay): %d ",result );
if ( result != 0 ) {
unsigned int len = maxlen;
while ( len < preCommand.length() ) {
preCommand.insert( len , "\n" );
len += maxlen +2;
}
@@ -593,71 +664,495 @@ void KSyncManager::confSync()
static KSyncPrefsDialog* sp = 0;
if ( ! sp ) {
sp = new KSyncPrefsDialog( mParent, "syncprefs", true );
}
sp->usrReadConfig();
#ifndef DESKTOP_VERSION
sp->showMaximized();
#else
sp->show();
#endif
sp->exec();
mSyncProfileNames = sp->getSyncProfileNames();
mLocalMachineName = sp->getLocalMachineName ();
fillSyncMenu();
}
void KSyncManager::syncSharp()
{
if ( ! syncExternalApplication("sharp") )
qDebug("ERROR sync sharp ");;
}
bool KSyncManager::syncExternalApplication(QString resource)
{
- if ( mImplementation->sync_isModified() )
- mImplementation->sync_save();
+
+ emit save();
if ( mAskForPreferences )
edit_sync_options();
qDebug("sync %s", resource.latin1());
bool syncOK = mImplementation->syncExternal(this, resource);
return syncOK;
}
void KSyncManager::syncPhone()
{
- if ( mImplementation->sync_isModified() )
- mImplementation->sync_save();
+ emit save();
qDebug("pending syncPhone(); ");
//mView->syncPhone();
- mImplementation->sync_setModified();
}
void KSyncManager::showProgressBar(int percentage, QString caption, int total)
{
if (!bar->isVisible())
{
bar->setCaption (caption);
bar->setTotalSteps ( total ) ;
bar->show();
}
bar->setProgress( percentage );
}
void KSyncManager::hideProgressBar()
{
bar->hide();
}
bool KSyncManager::isProgressBarCanceled()
{
return !bar->isVisible();
}
+
+QString KSyncManager::syncFileName()
+{
+
+ QString fn = "tempfile";
+ switch(mTargetApp)
+ {
+ case (KAPI):
+ fn = "addressbook.vcf";
+ break;
+ case (KOPI):
+ fn = "synccalendar.ics";
+ break;
+ case (PWMPI):
+ fn = "manager.pwm";
+ break;
+ default:
+ break;
+ }
+#ifdef _WIN32_
+ return locateLocal( "tmp", fn );
+#else
+ return (QString( "/tmp/" )+ fn );
+#endif
+}
+
+void KSyncManager::syncPi()
+{
+ qApp->processEvents();
+ bool ok;
+ Q_UINT16 port = mActiveSyncPort.toUInt(&ok);
+ if ( ! ok ) {
+ mParent->setCaption( i18n("Sorry, no valid port.Syncing cancelled.") );
+ return;
+ }
+ KCommandSocket* commandSocket = new KCommandSocket( mPassWordPiSync, port, mActiveSyncIP, this );
+ connect( commandSocket, SIGNAL(commandFinished( KCommandSocket*, int )), this, SLOT(deleteCommandSocket(KCommandSocket*, int)) );
+ mParent->setCaption( i18n("Sending request for remote file ...") );
+ commandSocket->readFile( syncFileName() );
+}
+
+void KSyncManager::deleteCommandSocket(KCommandSocket*s, int state)
+{
+ qDebug("MainWindow::deleteCommandSocket %d", state);
+
+ //enum { success, errorW, errorR, quiet };
+ if ( state == KCommandSocket::errorR ) {
+ mParent->setCaption( i18n("ERROR: Receiving remote file failed.") );
+ delete s;
+ KCommandSocket* commandSocket = new KCommandSocket( mPassWordPiSync, mActiveSyncPort.toUInt(), mActiveSyncIP, this );
+ connect( commandSocket, SIGNAL(commandFinished( KCommandSocket*, int)), this, SLOT(deleteCommandSocket(KCommandSocket*, int )) );
+ commandSocket->sendStop();
+ return;
+
+ } else if ( state == KCommandSocket::errorW ) {
+ mParent->setCaption( i18n("ERROR:Writing back file failed.") );
+
+ } else if ( state == KCommandSocket::successR ) {
+ QTimer::singleShot( 1, this , SLOT ( readFileFromSocket()));
+
+ } else if ( state == KCommandSocket::successW ) {
+ mParent->setCaption( i18n("Pi-Sync succesful!") );
+ }
+
+ delete s;
+}
+
+void KSyncManager::readFileFromSocket()
+{
+ QString fileName = syncFileName();
+ mParent->setCaption( i18n("Remote file saved to temp file.") );
+ if ( ! syncWithFile( fileName , true ) ) {
+ mParent->setCaption( i18n("Syncing failed.") );
+ qDebug("Syncing failed ");
+ return;
+ }
+ KCommandSocket* commandSocket = new KCommandSocket( mPassWordPiSync, mActiveSyncPort.toUInt(), mActiveSyncIP, this );
+ connect( commandSocket, SIGNAL(commandFinished( KCommandSocket*, int)), this, SLOT(deleteCommandSocket(KCommandSocket*, int )) );
+ if ( mWriteBackFile )
+ commandSocket->writeFile( fileName );
+ else {
+ commandSocket->sendStop();
+ mParent->setCaption( i18n("Pi-Sync succesful!") );
+ }
+}
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+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();
+ 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() ) );
+}
+void KCommandSocket::readFile( QString fn )
+{
+ if ( !mSocket ) {
+ mSocket = new QSocket( this );
+ connect( mSocket, SIGNAL(readyRead()), this, SLOT(startReadFileFromSocket()) );
+ connect( mSocket, SIGNAL(delayedCloseFinished ()), this, SLOT(deleteSocket()) );
+ }
+ mFileString = "";
+ mFileName = fn;
+ mFirst = true;
+ mSocket->connectToHost( mHost, mPort );
+ QTextStream os( mSocket );
+ os.setEncoding( QTextStream::UnicodeUTF8 );
+ os << "GET " << mPassWord << "\r\n";
+ mTimerSocket->start( 10000 );
+}
+
+void KCommandSocket::writeFile( QString fileName )
+{
+ if ( !mSocket ) {
+ mSocket = new QSocket( this );
+ connect( mSocket, SIGNAL(delayedCloseFinished ()), this, SLOT(deleteSocket()) );
+ connect( mSocket, SIGNAL(connected ()), this, SLOT(writeFileToSocket()) );
+ }
+ mFileName = fileName ;
+ mSocket->connectToHost( mHost, mPort );
+}
+void KCommandSocket::writeFileToSocket()
+{
+ QFile file2( mFileName );
+ if (!file2.open( IO_ReadOnly ) ) {
+ mRetVal= errorW;
+ mSocket->close();
+ if ( mSocket->state() == QSocket::Idle )
+ QTimer::singleShot( 10, this , SLOT ( deleteSocket()));
+ return ;
+ }
+ QTextStream ts2( &file2 );
+ ts2.setCodec( QTextCodec::codecForName("utf8") );
+ QTextStream os2( mSocket );
+ os2.setCodec( QTextCodec::codecForName("utf8") );
+ os2 << "PUT " << mPassWord << "\r\n";;
+ while ( ! ts2.atEnd() ) {
+ os2 << ts2.readLine() << "\n";
+ }
+ mRetVal= successW;
+ file2.close();
+ mSocket->close();
+ if ( mSocket->state() == QSocket::Idle )
+ QTimer::singleShot( 10, this , SLOT ( deleteSocket()));
+}
+void KCommandSocket::sendStop()
+{
+ if ( !mSocket ) {
+ mSocket = new QSocket( this );
+ connect( mSocket, SIGNAL(delayedCloseFinished ()), this, SLOT(deleteSocket()) );
+ }
+ mSocket->connectToHost( mHost, mPort );
+ QTextStream os2( mSocket );
+ os2.setCodec( QTextCodec::codecForName("utf8") );
+ os2 << "STOP\r\n";
+ mSocket->close();
+ if ( mSocket->state() == QSocket::Idle )
+ QTimer::singleShot( 10, this , SLOT ( deleteSocket()));
+}
+
+void KCommandSocket::startReadFileFromSocket()
+{
+ if ( ! mFirst )
+ return;
+ mFirst = false;
+ mTimerSocket->stop();
+ mFileString = "";
+ mTime.start();
+ QTimer::singleShot( 1, this , SLOT (readFileFromSocket( ) ));
+
+}
+void KCommandSocket::readFileFromSocket()
+{
+ //qDebug("readBackFileFromSocket() %d ", mTime.elapsed ());
+ while ( mSocket->canReadLine () ) {
+ mTime.restart();
+ QString line = mSocket->readLine ();
+ mFileString += line;
+ //qDebug("readline: %s ", line.latin1());
+ }
+ if ( mTime.elapsed () < 3000 ) {
+ // wait for more
+ //qDebug("waitformore ");
+ QTimer::singleShot( 100, this , SLOT (readFileFromSocket( ) ));
+ return;
+ }
+ QString fileName = mFileName;
+ QFile file ( fileName );
+ if (!file.open( IO_WriteOnly ) ) {
+ mFileString = "";
+ mRetVal = errorR;
+ qDebug("Error open temp calender file for writing: %s",fileName.latin1() );
+ deleteSocket();
+ return ;
+
+ }
+ // mView->setLoadedFileVersion(QDateTime::currentDateTime().addSecs( -1));
+ QTextStream ts ( &file );
+ ts.setCodec( QTextCodec::codecForName("utf8") );
+ ts << mFileString;
+ file.close();
+ mFileString = "";
+ mRetVal = successR;
+ mSocket->close();
+ // if state is not idle, deleteSocket(); is called via
+ // connect( mSocket, SIGNAL(delayedCloseFinished ()), this, SLOT(deleteSocket()) );
+ if ( mSocket->state() == QSocket::Idle )
+ deleteSocket();
+}
+
+void KCommandSocket::deleteSocket()
+{
+ if ( mTimerSocket->isActive () ) {
+ mTimerSocket->stop();
+ KMessageBox::information( 0, i18n("ERROR:\nConnection to remote host timed out!\nDid you forgot to enable\nsyncing on remote host? "));
+ mRetVal = errorR;
+ }
+ //qDebug("KCommandSocket::deleteSocket() %d", mRetVal );
+ if ( mSocket)
+ delete mSocket;
+ mSocket = 0;
+ emit commandFinished( this, mRetVal );
+}
+
diff --git a/libkdepim/ksyncmanager.h b/libkdepim/ksyncmanager.h
index 6b10016..52e2772 100644
--- a/libkdepim/ksyncmanager.h
+++ b/libkdepim/ksyncmanager.h
@@ -3,145 +3,226 @@
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 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 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:
+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;
}
- //called by the syncmanager to indicate that the work has to be marked as dirty.
- virtual void sync_setModified() = 0;
-
- //called by the syncmanager to ask if the dirty flag is set.
- virtual bool sync_isModified() = 0;
-
- //called by the syncmanager to indicate that the work has to be saved.
- virtual void sync_save() = 0;
+
};
#endif