author | zautrix <zautrix> | 2004-10-04 19:29:05 (UTC) |
---|---|---|
committer | zautrix <zautrix> | 2004-10-04 19:29:05 (UTC) |
commit | dfc6d084410456037bf6f26f741e7b938085de88 (patch) (side-by-side diff) | |
tree | 6c05462c68067b37af3766020667328f8da839f8 /korganizer | |
parent | 144952942e57780587739a46253cc7305c79f27c (diff) | |
download | kdepimpi-dfc6d084410456037bf6f26f741e7b938085de88.zip kdepimpi-dfc6d084410456037bf6f26f741e7b938085de88.tar.gz kdepimpi-dfc6d084410456037bf6f26f741e7b938085de88.tar.bz2 |
more sync
-rw-r--r-- | korganizer/mainwindow.cpp | 230 | ||||
-rw-r--r-- | korganizer/mainwindow.h | 13 |
2 files changed, 75 insertions, 168 deletions
diff --git a/korganizer/mainwindow.cpp b/korganizer/mainwindow.cpp index da73caf..bce2a54 100644 --- a/korganizer/mainwindow.cpp +++ b/korganizer/mainwindow.cpp @@ -76,4 +76,2 @@ MainWindow::MainWindow( QWidget *parent, const char *name, QString msg) : #endif - mCommandSocket = 0; - mCommandSocketFinish = 0; mSyncActionDialog = 0; @@ -1944,45 +1942,3 @@ void MainWindow::enableQuick() } -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); - lay->setMargin(7); - lay->setSpacing(7); - mSyncActionDialog->setFixedSize( 200,100 ); - mSyncActionDialog->show(); - 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 ); - ts.setCodec( QTextCodec::codecForName("utf8") ); - 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( bool success ) @@ -1998,66 +1954,5 @@ void MainWindow::getFile( bool success ) - -#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() ) ); - } - 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 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") ); - qDebug("finish "); - setCaption( i18n("Writing file to disk...") ); - ts << piFileString; - setCaption( i18n("File received - reloading calendar...") ); - piSocket->close(); - file.close(); - mView->watchSavedFile(); - mView->openCalendar( defaultFileName() ); - 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() @@ -2117,4 +2012,4 @@ void MainWindow::performQuickQuick() } - mCommandSocket = new KCommandSocket( mPassWordPiSync, port, KOPrefs::instance()->mActiveSyncIP, this ); - connect( mCommandSocket, SIGNAL(commandFinished( bool )), this, SLOT(deleteCommandSocket(bool)) ); + KCommandSocket* commandSocket = new KCommandSocket( mPassWordPiSync, port, KOPrefs::instance()->mActiveSyncIP, this ); + connect( commandSocket, SIGNAL(commandFinished( KCommandSocket*, bool )), this, SLOT(deleteCommandSocket(KCommandSocket*,bool)) ); setCaption( i18n("Sending request for remote file ...") ); @@ -2126,5 +2021,5 @@ void MainWindow::performQuickQuick() #endif - mCommandSocket->readFile( fileName ); + commandSocket->readFile( fileName ); } -void MainWindow::deleteCommandSocket( bool success) +void MainWindow::deleteCommandSocket(KCommandSocket*s, bool success) { @@ -2132,2 +2027,3 @@ void MainWindow::deleteCommandSocket( bool success) setCaption( i18n("ERROR:Receiving remote file failed.") ); + delete s; // pending : send stop @@ -2137,12 +2033,15 @@ void MainWindow::deleteCommandSocket( bool success) QTimer::singleShot( 1, this , SLOT ( readFileFromSocket())); - delete mCommandSocket; + qDebug("MainWindow::deleteCommandSocket "); + delete s; } -void MainWindow::deleteCommandSocketFinish() +void MainWindow::deleteCommandSocketFinish(KCommandSocket* s, bool success ) { - if ( ! mCommandSocketFinish) - return; - // KMessageBox::information( 0, i18n("MainWindow::deleteCommandSocketFinish() ")); - qDebug("MainWindow::deletemCommandSocketFinish() "); - delete mCommandSocketFinish; - mCommandSocketFinish = 0; + if ( ! success ) { + setCaption( i18n("ERROR:Writing back file failed.") ); + } else { + qDebug("Syncing succesful! "); + setCaption( i18n("Pi-Sync succesful!") ); + } + qDebug("MainWindow::deleteCommandSocketFinish "); + delete s; } @@ -2185,39 +2084,8 @@ void MainWindow::readFileFromSocket() - if ( !mCommandSocketFinish ) { - mCommandSocketFinish = new QSocket( this ); - connect( mCommandSocketFinish, SIGNAL(delayedCloseFinished ()), this, SLOT(deleteCommandSocketFinish()) ); - } - mCommandSocketFinish->connectToHost( KOPrefs::instance()->mActiveSyncIP, KOPrefs::instance()->mActiveSyncPort.toUInt() ); - - 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 ; - - } - QTextStream ts2( &file2 ); - ts2.setCodec( QTextCodec::codecForName("utf8") ); - QTextStream os2( mCommandSocketFinish ); - os2.setCodec( QTextCodec::codecForName("utf8") ); - //os.setEncoding( QTextStream::UnicodeUTF8 ); - if ( KOPrefs::instance()->mWriteBackFile ) { - setCaption( i18n("Sending back synced file...") ); - os2 << "PUT " << mPassWordPiSync << "\r\n";; - while ( ! ts2.atEnd() ) { - os2 << ts2.readLine() << "\n"; - } - } else { - os2 << "STOP\r\n"; - } - mCommandSocketFinish->close(); - if ( mCommandSocketFinish->state() == QSocket::Idle ) - QTimer::singleShot( 10, this , SLOT ( deleteCommandSocketFinish())); - file2.close(); - qDebug("Syncing succesful! "); - setCaption( i18n("Pi-Sync succesful!") ); - - // KMessageBox::information( 0, i18n(" Pi-Sync succesful! ")); - + KCommandSocket* commandSocket = new KCommandSocket( mPassWordPiSync, KOPrefs::instance()->mActiveSyncPort.toUInt(), KOPrefs::instance()->mActiveSyncIP, this ); + connect( commandSocket, SIGNAL(commandFinished( KCommandSocket*, bool )), this, SLOT(deleteCommandSocketFinish(KCommandSocket*,bool)) ); + if ( KOPrefs::instance()->mWriteBackFile ) + commandSocket->writeFile( fileName ); + else + commandSocket->sendStop(); } @@ -2562,3 +2430,4 @@ void KServerSocket::readClient() if ( tokens[0] == "STOP" ) { - emit endConnect(); + //emit endConnect(); + end_connect(); } @@ -2566,3 +2435,7 @@ void KServerSocket::readClient() } - +void KServerSocket::end_connect() +{ + delete mSyncActionDialog; + mSyncActionDialog = 0; +} void KServerSocket::send_file() @@ -2697,6 +2570,44 @@ void KCommandSocket::readFile( QString fn ) -void KCommandSocket::writeFile( QString ) +void KCommandSocket::writeFile( QString fileName ) { + QFile file2( fileName ); + if (!file2.open( IO_ReadOnly ) ) { + mRetVal= false; + deleteSocket(); + return ; + + } + if ( !mSocket ) { + mSocket = new QSocket( this ); + connect( mSocket, SIGNAL(delayedCloseFinished ()), this, SLOT(deleteSocket()) ); + } + 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"; + } + mSocket->close(); + if ( mSocket->state() == QSocket::Idle ) + QTimer::singleShot( 10, this , SLOT ( deleteSocket())); + file2.close(); +} +void KCommandSocket::sendStop() +{ + if ( !mSocket ) { + mSocket = new QSocket( this ); + connect( mSocket, SIGNAL(delayedCloseFinished ()), this, SLOT(deleteSocket()) ); } + QTextStream os2( mSocket ); + os2.setCodec( QTextCodec::codecForName("utf8") ); + os2 << "STOP\r\n"; + mRetVal= true; + mSocket->close(); + if ( mSocket->state() == QSocket::Idle ) + QTimer::singleShot( 10, this , SLOT ( deleteSocket())); +} + void KCommandSocket::startReadFileFromSocket() @@ -2754,4 +2665,2 @@ void KCommandSocket::deleteSocket() { - if ( !mSocket) - return; if ( mTimerSocket->isActive () ) { @@ -2762,5 +2671,6 @@ void KCommandSocket::deleteSocket() qDebug("KCommandSocket::deleteSocket() %d", mRetVal); + if ( mSocket) delete mSocket; mSocket = 0; - emit commandFinished( mRetVal ); + emit commandFinished( this, mRetVal ); } diff --git a/korganizer/mainwindow.h b/korganizer/mainwindow.h index 8b76067..5a67765 100644 --- a/korganizer/mainwindow.h +++ b/korganizer/mainwindow.h @@ -51,2 +51,3 @@ private slots: void get_file(); + void end_connect(); QDialog* mSyncActionDialog; @@ -67,2 +68,3 @@ public: void writeFile( QString ); + void sendStop(); @@ -70,3 +72,3 @@ public: signals: - void commandFinished( bool ); + void commandFinished( KCommandSocket*, bool ); private slots: @@ -162,10 +164,7 @@ class MainWindow : public QMainWindow QTime piTime; - void deleteCommandSocket(bool); - void deleteCommandSocketFinish(); + void deleteCommandSocket(KCommandSocket* s, bool success); + void deleteCommandSocketFinish(KCommandSocket* s, bool success); void fillSyncMenu(); - void sendFile(QSocket* s); void getFile( bool ); void readFileFromSocket(); - void readBackFileFromSocket(); - void endConnect(); private: @@ -173,4 +172,2 @@ class MainWindow : public QMainWindow QString mPassWordPiSync; - KCommandSocket* mCommandSocket; - QSocket* mCommandSocketFinish; KServerSocket * mServerSocket; |