summaryrefslogtreecommitdiffabout
path: root/korganizer
authorzautrix <zautrix>2004-10-04 18:41:26 (UTC)
committer zautrix <zautrix>2004-10-04 18:41:26 (UTC)
commit144952942e57780587739a46253cc7305c79f27c (patch) (side-by-side diff)
tree82ad5b9b98c6243a9d2c8902f4851c421e70508c /korganizer
parent2a99a7ca0816fd68b7fcf2f1fee023aef019000d (diff)
downloadkdepimpi-144952942e57780587739a46253cc7305c79f27c.zip
kdepimpi-144952942e57780587739a46253cc7305c79f27c.tar.gz
kdepimpi-144952942e57780587739a46253cc7305c79f27c.tar.bz2
more sync fixes
Diffstat (limited to 'korganizer') (more/less context) (show whitespace changes)
-rw-r--r--korganizer/mainwindow.cpp133
-rw-r--r--korganizer/mainwindow.h17
2 files changed, 140 insertions, 10 deletions
diff --git a/korganizer/mainwindow.cpp b/korganizer/mainwindow.cpp
index e4b7869..da73caf 100644
--- a/korganizer/mainwindow.cpp
+++ b/korganizer/mainwindow.cpp
@@ -1920,33 +1920,36 @@ void MainWindow::enableQuick()
dia.hide();
passWordPiSync = lepw.text();
qApp->processEvents();
KOPrefs::instance()->mPassiveSyncPort = retfile;
bool ok;
Q_UINT16 port = retfile.toUInt(&ok);
if ( ! ok ) {
KMessageBox::information( this, i18n("No valid port"));
return;
}
qDebug("port %d ", port);
mServerSocket = new KServerSocket ( passWordPiSync, port ,1 );
+ mServerSocket->setFileName( defaultFileName() );
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*) ) );
+ connect( mServerSocket, SIGNAL ( saveFile() ), this, SLOT ( save() ) );
+ connect( mServerSocket, SIGNAL ( file_received( bool ) ), this, SLOT ( getFile( bool ) ) );
+ // connect( mServerSocket, SIGNAL ( sendFile(QSocket*) ), this, SLOT ( sendFile(QSocket*) ) );
+ //connect( mServerSocket, SIGNAL ( getFile(QSocket*) ), this, SLOT ( getFile(QSocket*) ) );
}
void MainWindow::sendFile(QSocket* socket)
{
setCaption( i18n("Received request for file") );
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);
@@ -1973,33 +1976,44 @@ void MainWindow::sendFile(QSocket* socket)
QTextStream os( socket );
os.setCodec( QTextCodec::codecForName("utf8") );
//os.setEncoding( QTextStream::UnicodeUTF8 );
while ( ! ts.atEnd() ) {
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)
+void MainWindow::getFile( bool success )
{
+ if ( ! success ) {
+ setCaption( i18n("Error receiving file. Nothing changed!") );
+ return;
+ }
+ // pending adjust time for watchSavedFile()
+ //mView->watchSavedFile();
+ mView->openCalendar( defaultFileName() );
+ setCaption( i18n("Pi-Sync successful!") );
+
+
+#if 0
setCaption( i18n("Receiving synced file...") );
piTime.start();
piSocket = socket;
piFileString = "";
QTimer::singleShot( 1, this , SLOT (readBackFileFromSocket( ) ));
-
+#endif
}
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() ) );
@@ -2481,24 +2495,25 @@ void MainWindow::printSel( )
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;
};
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()) );
@@ -2519,44 +2534,148 @@ 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 );
+ //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 );
+ //emit getFile( mSocket );
+ 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();
}
}
}
+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...\nDo not use this application!\n\nIf syncing fails you 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 to get back synced file") );
+ qDebug("file sent ");
+ 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 );
+ return ;
+
+ }
+
+ // mView->setLoadedFileVersion(QDateTime::currentDateTime().addSecs( -1));
+ QTextStream ts ( &file );
+ ts.setCodec( QTextCodec::codecForName("utf8") );
+ qDebug("finish ");
+ 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 = "";
+ 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 = false;
mTimerSocket = new QTimer ( this );
connect( mTimerSocket, SIGNAL ( timeout () ), this, SLOT ( deleteSocket() ) );
}
void KCommandSocket::readFile( QString fn )
@@ -2628,21 +2747,21 @@ void KCommandSocket::readFileFromSocket()
// 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 ( !mSocket)
return;
if ( mTimerSocket->isActive () ) {
mTimerSocket->stop();
- KMessageBox::information( 0, i18n("ERROR:\nConnection to remote host timed out "));
+ KMessageBox::information( 0, i18n("ERROR:\nConnection to remote host timed out!\nDid you forgot to enable\nsyncing on remote host? "));
mRetVal = false;
}
qDebug("KCommandSocket::deleteSocket() %d", mRetVal);
delete mSocket;
mSocket = 0;
emit commandFinished( mRetVal );
}
diff --git a/korganizer/mainwindow.h b/korganizer/mainwindow.h
index 11a816c..8b76067 100644
--- a/korganizer/mainwindow.h
+++ b/korganizer/mainwindow.h
@@ -24,35 +24,46 @@ 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 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 :
+ void send_file();
+ void get_file();
+ QDialog* mSyncActionDialog;
QSocket* mSocket;
QString mPassWord;
+ QString mFileName;
+ QTime piTime;
+ QString piFileString;
};
class KCommandSocket : public QObject
{
Q_OBJECT
public:
KCommandSocket ( QString password, Q_UINT16 port, QString host, QObject * parent=0, const char * name=0 );
void readFile( QString );
void writeFile( QString );
@@ -144,25 +155,25 @@ class MainWindow : public QMainWindow
void displayFile( QString, QString);
void enableIncidenceActions( bool );
private slots:
QSocket* piSocket;
QString piFileString;
QTime piTime;
void deleteCommandSocket(bool);
void deleteCommandSocketFinish();
void fillSyncMenu();
void sendFile(QSocket* s);
- void getFile(QSocket* socket);
+ void getFile( bool );
void readFileFromSocket();
void readBackFileFromSocket();
void endConnect();
private:
//QTimer* mTimerCommandSocket;
QString mPassWordPiSync;
KCommandSocket* mCommandSocket;
QSocket* mCommandSocketFinish;
KServerSocket * mServerSocket;
bool mClosed;
void saveOnClose();
int mCurrentSyncProfile;