summaryrefslogtreecommitdiffabout
path: root/korganizer
authorzautrix <zautrix>2004-10-04 10:05:42 (UTC)
committer zautrix <zautrix>2004-10-04 10:05:42 (UTC)
commit743f44c45534a6e1df17ddc7b5f3c62b73921455 (patch) (side-by-side diff)
tree83795806d28b2614639082e944558a470f039daf /korganizer
parentaaea91151fe9a747e9eddfb8ba7d5896744faf30 (diff)
downloadkdepimpi-743f44c45534a6e1df17ddc7b5f3c62b73921455.zip
kdepimpi-743f44c45534a6e1df17ddc7b5f3c62b73921455.tar.gz
kdepimpi-743f44c45534a6e1df17ddc7b5f3c62b73921455.tar.bz2
sync fixes
Diffstat (limited to 'korganizer') (more/less context) (show whitespace changes)
-rw-r--r--korganizer/mainwindow.cpp163
-rw-r--r--korganizer/mainwindow.h14
2 files changed, 115 insertions, 62 deletions
diff --git a/korganizer/mainwindow.cpp b/korganizer/mainwindow.cpp
index 7bf33d3..8e2f956 100644
--- a/korganizer/mainwindow.cpp
+++ b/korganizer/mainwindow.cpp
@@ -61,25 +61,27 @@
using namespace KCal;
#ifndef _WIN32_
#include <unistd.h>
#else
#include "koimportoldialog.h"
#endif
#include "mainwindow.h"
int globalFlagBlockStartup;
MainWindow::MainWindow( QWidget *parent, const char *name, QString msg) :
QMainWindow( parent, name )
{
-
+ mPassWordPiSync = "abc";
+ mTimerCommandSocket = new QTimer ( this );
+ connect( mTimerCommandSocket, SIGNAL ( timeout () ), this, SLOT ( deleteCommandSocket() ) );
#ifdef DESKTOP_VERSION
setFont( QFont("Arial"), 14 );
#endif
mCommandSocket = 0;
mCommandSocketFinish = 0;
mSyncActionDialog = 0;
mServerSocket = 0;
mClosed = false;
//QString confFile = KStandardDirs::appDir() + "config/korganizerrc";
QString confFile = locateLocal("config","korganizerrc");
QFileInfo finf ( confFile );
bool showWarning = !finf.exists();
@@ -1880,56 +1882,64 @@ QString MainWindow::getPassword( )
dia.show();
int res = dia.exec();
if ( res )
retfile = lab.text();
dia.hide();
qApp->processEvents();
return retfile;
}
void MainWindow::enableQuick()
{
+ QString passWordPiSync = "bhdrvmk";
QString retfile = "";
QDialog dia ( this, "input-dialog", true );
QLineEdit lab ( &dia );
QVBoxLayout lay( &dia );
lab.setText( KOPrefs::instance()->mPassiveSyncPort );
lay.setMargin(7);
lay.setSpacing(7);
QLabel label ( i18n("Port number (Default: 9197)"), &dia );
lay.addWidget( &label);
lay.addWidget( &lab);
+
+ QLineEdit lepw ( &dia );
+ lepw.setText( "abc" );
+ 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 Easy-Pi-Sync") );
+ dia.setCaption( i18n("Enter port for Pi-Sync") );
QPushButton pb ( "OK", &dia);
lay.addWidget( &pb );
connect(&pb, SIGNAL( clicked() ), &dia, SLOT ( accept() ) );
dia.show();
int res = dia.exec();
if ( res )
retfile = lab.text();
else
return;
dia.hide();
+ passWordPiSync = lepw.text();
qApp->processEvents();
KOPrefs::instance()->mPassiveSyncPort = retfile;
bool ok;
Q_UINT16 port = retfile.toUInt(&ok);
if ( ! ok ) {
- qDebug("no valid port ");
+ KMessageBox::information( this, i18n("No valid port"));
return;
}
qDebug("port %d ", port);
- mServerSocket = new KServerSocket ( port ,1 );
+ mServerSocket = new KServerSocket ( passWordPiSync, port ,1 );
qDebug("connected ");
if ( !mServerSocket->ok() ) {
qWarning("Failed to bind to port %d", port);
delete mServerSocket;
mServerSocket = 0;
return;
}
connect( mServerSocket, SIGNAL ( sendFile(QSocket*) ), this, SLOT ( sendFile(QSocket*) ) );
connect( mServerSocket, SIGNAL ( getFile(QSocket*) ), this, SLOT ( getFile(QSocket*) ) );
}
void MainWindow::sendFile(QSocket* socket)
{
@@ -1937,27 +1947,27 @@ void MainWindow::sendFile(QSocket* socket)
qDebug("MainWindow::sendFile(QSocket* s) ");
if ( mSyncActionDialog )
delete mSyncActionDialog;
mSyncActionDialog = new QDialog ( this, "input-dialog", true );
mSyncActionDialog->setCaption(i18n("KO/Pi - WARNING"));
QLabel* label = new QLabel( i18n("Synchronizing...\nDo not use\nthis application!\n"), mSyncActionDialog );
QVBoxLayout* lay = new QVBoxLayout( mSyncActionDialog );
lay->addWidget( label);
lay->setMargin(7);
lay->setSpacing(7);
mSyncActionDialog->setFixedSize( 200,100 );
mSyncActionDialog->show();
- qApp->processEvents();
qDebug("saving ... ");
save();
+ qApp->processEvents();
QString fileName = defaultFileName();
QFile file( fileName );
if (!file.open( IO_ReadOnly ) ) {
setCaption( i18n("Error open file") );
delete mSyncActionDialog;
mSyncActionDialog = 0;
qDebug("error open cal file ");
return ;
}
setCaption( i18n("Sending file...") );
QTextStream ts( &file );
@@ -1969,160 +1979,179 @@ void MainWindow::sendFile(QSocket* socket)
os << ts.readLine() << "\n";
}
//os << ts.read();
socket->close();
file.close();
setCaption( i18n("File sent. Waiting to get back synced file") );
qDebug("file sent ");
}
void MainWindow::getFile(QSocket* socket)
{
setCaption( i18n("Receiving synced file...") );
+ piTime.start();
+ piSocket = socket;
+ piFileString = "";
+ QTimer::singleShot( 1, this , SLOT (readBackFileFromSocket( ) ));
+
+
+}
+void MainWindow::readBackFileFromSocket()
+{
+ qDebug("readBackFileFromSocket() %d ", piTime.elapsed ());
+ while ( piSocket->canReadLine () ) {
+ piTime.restart();
+ QString line = piSocket->readLine ();
+ piFileString += line;
+ qDebug("readline: %s ", line.latin1());
+ 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 = defaultFileName();
QFile file( fileName );
if (!file.open( IO_WriteOnly ) ) {
- setCaption( i18n("Error open file") );
+ setCaption( i18n("Error open file for writing!") );
delete mSyncActionDialog;
mSyncActionDialog = 0;
qDebug("error open cal file ");
+ piFileString = "";
return ;
}
mView->setLoadedFileVersion(QDateTime::currentDateTime().addSecs( -1));
QTextStream ts( &file );
ts.setCodec( QTextCodec::codecForName("utf8") );
- bool first = true;
- while ( socket->canReadLine () || first ) {
- first = false;
- while ( socket->canReadLine () ) {
- qDebug("avail %d ", socket->bytesAvailable () );
- ts << socket->readLine ();
- }
- QTime ti;
- ti.start();
- while ( ti.elapsed () < 5000 && !socket->canReadLine () ) {
- qDebug("waiting1a %d %d ",ti.elapsed (), socket->bytesAvailable () );
- //qApp->processEvents();
- qDebug("waiting1b %d ",ti.elapsed () );
- if ( !socket->canReadLine () ) {
- qDebug("waiting1c %d ",ti.elapsed () );
-#ifndef _WIN32_
- usleep( 100000);
-#endif
- }
- //socket->waitForMore ( 100 );
- }
- ts << socket->readLine ();
-#if 0
-#ifdef DESKTOP_VERSION
- socket->waitForMore ( 5000 );
-#else
- // socket->waitForMore ( 5000 );
- // seems to be broken in qt2
- bool stop = false;
- QTime ti;
- ti.start();
- while ( ti.elapsed < 5000 && !stop ) {
- qApp->processEvents();
- if ( socket->canReadLine () )
- stop = true ;
- else {
- usleep( 100000 );
-
- }
- }
-#endif
-#endif
- }
+ qDebug("finish ");
+ setCaption( i18n("Writing file to disk...") );
+ ts << piFileString;
setCaption( i18n("File received - reloading calendar...") );
- socket->close();
+ piSocket->close();
file.close();
mView->watchSavedFile();
mView->openCalendar( defaultFileName() );
- setCaption( i18n("Easy-Pi-Sync successful!") );
+ setCaption( i18n("Pi-Sync successful!") );
delete mSyncActionDialog;
mSyncActionDialog = 0;
+ piFileString = "";
}
void MainWindow::endConnect()
{
setCaption( i18n("No file received - syncing successful") );
delete mSyncActionDialog;
mSyncActionDialog = 0;
}
void MainWindow::performQuick()
{
+
setCaption( i18n("Please input connection settings") );
QString retfile = "";
QDialog dia ( this, "input-dialog", true );
QLineEdit lab ( &dia );
QVBoxLayout lay( &dia );
QLabel label ( i18n("IP address\n(Example: 192.168.0.40)"), &dia );
lay.addWidget( &label);
lab.setText( KOPrefs::instance()->mActiveSyncIP );
lay.setMargin(7);
lay.setSpacing(7);
lay.addWidget( &lab);
QLabel label2 ( i18n("Port number (Default: 9197)"), &dia );
lay.addWidget( &label2);
QLineEdit lab2 ( &dia );
lab2.setText( KOPrefs::instance()->mActiveSyncPort );
lay.addWidget( &lab2);
+
+ QLineEdit lepw ( &dia );
+ lepw.setText( mPassWordPiSync );
+ QLabel label3 ( i18n("Password to enable\naccess to remote:"), &dia );
+ lay.addWidget( &label3);
+ lay.addWidget( &lepw);
+
dia.setFixedSize( 230,200 );
- dia.setCaption( i18n("Enter port for Easy-Pi-Sync ") );
+ dia.setCaption( i18n("Enter port for Pi-Sync ") );
QPushButton pb ( "OK", &dia);
lay.addWidget( &pb );
connect(&pb, SIGNAL( clicked() ), &dia, SLOT ( accept() ) );
dia.show();
int res = dia.exec();
if ( !res ) {
setCaption( i18n("Syncing cancelled!") );
return;
}
+ mPassWordPiSync = lepw.text();
dia.hide();
KOPrefs::instance()->mActiveSyncPort = lab2.text();
KOPrefs::instance()->mActiveSyncIP = lab.text();
qApp->processEvents();
performQuickQuick();
}
void MainWindow::performQuickQuick()
{
// setCaption( i18n("") );
bool ok;
Q_UINT16 port = KOPrefs::instance()->mActiveSyncPort.toUInt(&ok);
if ( ! ok ) {
setCaption( i18n("Sorry, no valid port.Syncing cancelled.") );
return;
}
if ( !mCommandSocket ) {
mCommandSocket = new QSocket( this );
// delete mCommandSocket;
//mCommandSocket = new QSocket( this );
connect( mCommandSocket, SIGNAL(readyRead()), this, SLOT(readFileFromSocket()) );
+ connect( mCommandSocket, SIGNAL(delayedCloseFinished ()), this, SLOT(deleteCommandSocket()) );
}
QString host = KOPrefs::instance()->mActiveSyncIP;
mCommandSocket->connectToHost( host, port );
QTextStream os( mCommandSocket );
os.setEncoding( QTextStream::UnicodeUTF8 );
- os << "GET\r\n";
+ os << "GET " << mPassWordPiSync << "\r\n";
setCaption( i18n("Sending request for remote file ...") );
+ mTimerCommandSocket->start( 15000 );
}
+void MainWindow::deleteCommandSocket()
+{
+ if ( !mCommandSocket)
+ return;
+ if ( mTimerCommandSocket->isActive () ) {
+ KMessageBox::information( 0, i18n("ERROR:\nConnection to remote host timed out "));
+ mTimerCommandSocket->stop();
+ }
+ qDebug("MainWindow::deletemCommandSocket() ");
+ delete mCommandSocket;
+ mCommandSocket = 0;
+}
+void MainWindow::deleteCommandSocketFinish()
+{
+ if ( ! mCommandSocketFinish)
+ return;
+ //KMessageBox::information( 0, i18n("MainWindow::deleteCommandSocketFinish() "));
+ qDebug("MainWindow::deletemCommandSocketFinish() ");
+ delete mCommandSocketFinish;
+ mCommandSocketFinish = 0;
+}
void MainWindow::readFileFromSocket()
{
+ mTimerCommandSocket->stop();
setCaption( i18n("Receiving remote file ...") );
qDebug("MainWindow::readFileFromSocket() ");
QString fileName;
#ifdef _WIN32_
fileName = defaultFileName() +"sync";
#else
fileName = "/tmp/kopitempfile.ics";
#endif
QFile file( fileName );
if (!file.open( IO_WriteOnly ) ) {
setCaption( i18n("Error: Cannot open temp file for write.") );
qDebug("Error open temp calender file for writing: %s",fileName.latin1() );
@@ -2143,86 +2172,88 @@ void MainWindow::readFileFromSocket()
QTime ti;
ti.start();
while ( ti.elapsed () < 5000 && !mCommandSocket->canReadLine () ) {
qApp->processEvents();
qDebug("waiting2 %d ",ti.elapsed () );
if ( !mCommandSocket->canReadLine () )
mCommandSocket->waitForMore ( 100 );
}
//mCommandSocket->waitForMore ( 5000 );
}
file.close();
mCommandSocket->close();
+ if ( mCommandSocket->state() == QSocket::Idle )
+ deleteCommandSocket();
// pending: deleting after signal SIGNAL(delayedCloseFinished())
//delete mCommandSocket;
setCaption( i18n("Remote file saved to temp file.") );
//mCommandSocket = 0;
mCurrentSyncProfile = 2 ; // last file
mView->setSyncDevice(KOPrefs::instance()->mSyncProfileNames[mCurrentSyncProfile] );
mView->setSyncName( KOPrefs::instance()->mLocalMachineName );
KConfig config ( locateLocal( "config","ksyncprofilesrc" ) );
KSyncProfile* temp = new KSyncProfile ();
temp->setName(KOPrefs::instance()->mSyncProfileNames[mCurrentSyncProfile]);
temp->readConfig(&config);
KOPrefs::instance()->mAskForPreferences = temp->getAskForPreferences();
KOPrefs::instance()->mSyncAlgoPrefs = temp->getSyncPrefs();
KOPrefs::instance()->mWriteBackFile = temp->getWriteBackFile();
KOPrefs::instance()->mWriteBackExistingOnly = temp->getWriteBackExisting();
KOPrefs::instance()->mWriteBackInFuture = 0;
if ( temp->getWriteBackFuture() )
KOPrefs::instance()->mWriteBackInFuture = temp->getWriteBackFutureWeeks( );
KOPrefs::instance()->mShowSyncSummary = temp->getShowSummaryAfterSync();
-
+ delete temp;
setCaption( i18n("Remote file saved to temp file.") );
if ( ! syncWithFile( fileName , true ) ) {
setCaption( i18n("Syncing failed.") );
qDebug("Syncing failed ");
return;
}
if ( !mCommandSocketFinish ) {
mCommandSocketFinish = new QSocket( this );
+ connect( mCommandSocketFinish, SIGNAL(delayedCloseFinished ()), this, SLOT(deleteCommandSocketFinish()) );
}
mCommandSocketFinish->connectToHost( KOPrefs::instance()->mActiveSyncIP, KOPrefs::instance()->mActiveSyncPort.toUInt() );
// pending connect signals connected () and error to new slots
QString host = KOPrefs::instance()->mActiveSyncIP;
QFile file2( fileName );
if (!file2.open( IO_ReadOnly ) ) {
setCaption( i18n("Error: Cannot open temp file for read.") );
qDebug("error open cal file ");
return ;
}
setCaption( i18n("Sending back synced file...") );
QTextStream ts2( &file2 );
ts2.setCodec( QTextCodec::codecForName("utf8") );
QTextStream os2( mCommandSocketFinish );
os2.setCodec( QTextCodec::codecForName("utf8") );
//os.setEncoding( QTextStream::UnicodeUTF8 );
if ( KOPrefs::instance()->mWriteBackFile ) {
- os2 << "PUT\r\n";
+ os2 << "PUT " << mPassWordPiSync << "\r\n";;
while ( ! ts2.atEnd() ) {
os2 << ts2.readLine() << "\n";
}
} else {
os2 << "STOP\r\n";
}
mCommandSocketFinish->close();
+ if ( mCommandSocketFinish->state() == QSocket::Idle )
+ deleteCommandSocketFinish();
file.close();
- // pending: deleting after signal SIGNAL(delayedCloseFinished())
- //delete ( mCommandSocket);
- //mCommandSocket = 0;
qDebug("Syncing succesful! ");
- setCaption( i18n("Easy-Pi-Sync succesful!") );
+ setCaption( i18n("Pi-Sync succesful!") );
}
void MainWindow::syncLocalFile()
{
QString fn =KOPrefs::instance()->mLastSyncedLocalFile;
fn =KFileDialog:: getOpenFileName( fn, i18n("Sync filename(*.ics/*.vcs)"), this );
if ( fn == "" )
return;
@@ -2487,27 +2518,27 @@ void MainWindow::syncPhone()
void MainWindow::printSel( )
{
mView->viewManager()->agendaView()->agenda()->printSelection();
}
void MainWindow::printCal()
{
mView->print();//mCp->showDialog();
}
-KServerSocket:: KServerSocket ( Q_UINT16 port, int backlog, QObject * parent, const char * name ) : QServerSocket( port, backlog, parent, name )
+KServerSocket:: KServerSocket ( QString pw, Q_UINT16 port, int backlog, QObject * parent, const char * name ) : QServerSocket( port, backlog, parent, name )
{
-
+ mPassWord = pw;
mSocket = 0;
};
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 );
@@ -2528,28 +2559,38 @@ void KServerSocket::discardClient()
}
void KServerSocket::readClient()
{
if ( mSocket == 0 ) {
qDebug("ERROR::KServerSocket::readClient(): mSocket == 0 ");
return;
}
qDebug("KServerSocket readClient()");
if ( mSocket->canReadLine() ) {
QStringList tokens = QStringList::split( QRegExp("[ \r\n][ \r\n]*"), mSocket->readLine() );
qDebug("KServerSocket socket->canReadLine()");
if ( tokens[0] == "GET" ) {
+ if ( tokens[1] == mPassWord )
emit sendFile( mSocket );
+ 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 );
+ 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();
}
}
}
diff --git a/korganizer/mainwindow.h b/korganizer/mainwindow.h
index cc656a3..d217578 100644
--- a/korganizer/mainwindow.h
+++ b/korganizer/mainwindow.h
@@ -1,54 +1,58 @@
#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"
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 ( Q_UINT16 port, int backlog = 0, QObject * parent=0, const char * name=0 );
+ KServerSocket ( QString password, Q_UINT16 port, int backlog = 0, QObject * parent=0, const char * name=0 );
void newConnection ( int socket ) ;
signals:
void sendFile(QSocket*);
void getFile(QSocket*);
void endConnect();
private slots:
void discardClient();
void readClient();
private :
QSocket* mSocket;
+ QString mPassWord;
};
namespace KCal {
class CalendarLocal;
}
using namespace KCal;
class MainWindow : public QMainWindow
{
Q_OBJECT
@@ -105,30 +109,38 @@ class MainWindow : public QMainWindow
void syncLocalFile();
bool syncWithFile( QString, bool );
void quickSyncLocalFile();
protected:
void displayText( QString, QString);
void displayFile( QString, QString);
void enableIncidenceActions( bool );
private slots:
+ QSocket* piSocket;
+ QString piFileString;
+ QTime piTime;
+ void deleteCommandSocket();
+ void deleteCommandSocketFinish();
void fillSyncMenu();
void sendFile(QSocket* s);
void getFile(QSocket* socket);
void readFileFromSocket();
+ void readBackFileFromSocket();
void endConnect();
private:
+ QTimer* mTimerCommandSocket;
+ QString mPassWordPiSync;
QSocket* mCommandSocket;
QSocket* mCommandSocketFinish;
KServerSocket * mServerSocket;
bool mClosed;
void saveOnClose();
int mCurrentSyncProfile;
void enableQuick();
void performQuick();
void performQuickQuick();
void syncRemote( KSyncProfile* , bool ask = true);
bool mFlagKeyPressed;
bool mBlockAtStartup;