-rw-r--r-- | korganizer/mainwindow.cpp | 133 |
1 files changed, 126 insertions, 7 deletions
diff --git a/korganizer/mainwindow.cpp b/korganizer/mainwindow.cpp index e4b7869..da73caf 100644 --- a/korganizer/mainwindow.cpp +++ b/korganizer/mainwindow.cpp | |||
@@ -1931,2 +1931,3 @@ void MainWindow::enableQuick() | |||
1931 | mServerSocket = new KServerSocket ( passWordPiSync, port ,1 ); | 1931 | mServerSocket = new KServerSocket ( passWordPiSync, port ,1 ); |
1932 | mServerSocket->setFileName( defaultFileName() ); | ||
1932 | qDebug("connected "); | 1933 | qDebug("connected "); |
@@ -1938,4 +1939,6 @@ void MainWindow::enableQuick() | |||
1938 | } | 1939 | } |
1939 | connect( mServerSocket, SIGNAL ( sendFile(QSocket*) ), this, SLOT ( sendFile(QSocket*) ) ); | 1940 | connect( mServerSocket, SIGNAL ( saveFile() ), this, SLOT ( save() ) ); |
1940 | connect( mServerSocket, SIGNAL ( getFile(QSocket*) ), this, SLOT ( getFile(QSocket*) ) ); | 1941 | connect( mServerSocket, SIGNAL ( file_received( bool ) ), this, SLOT ( getFile( bool ) ) ); |
1942 | // connect( mServerSocket, SIGNAL ( sendFile(QSocket*) ), this, SLOT ( sendFile(QSocket*) ) ); | ||
1943 | //connect( mServerSocket, SIGNAL ( getFile(QSocket*) ), this, SLOT ( getFile(QSocket*) ) ); | ||
1941 | } | 1944 | } |
@@ -1984,4 +1987,15 @@ void MainWindow::sendFile(QSocket* socket) | |||
1984 | } | 1987 | } |
1985 | void MainWindow::getFile(QSocket* socket) | 1988 | void MainWindow::getFile( bool success ) |
1986 | { | 1989 | { |
1990 | if ( ! success ) { | ||
1991 | setCaption( i18n("Error receiving file. Nothing changed!") ); | ||
1992 | return; | ||
1993 | } | ||
1994 | // pending adjust time for watchSavedFile() | ||
1995 | //mView->watchSavedFile(); | ||
1996 | mView->openCalendar( defaultFileName() ); | ||
1997 | setCaption( i18n("Pi-Sync successful!") ); | ||
1998 | |||
1999 | |||
2000 | #if 0 | ||
1987 | setCaption( i18n("Receiving synced file...") ); | 2001 | setCaption( i18n("Receiving synced file...") ); |
@@ -1992,3 +2006,3 @@ void MainWindow::getFile(QSocket* socket) | |||
1992 | QTimer::singleShot( 1, this , SLOT (readBackFileFromSocket( ) )); | 2006 | QTimer::singleShot( 1, this , SLOT (readBackFileFromSocket( ) )); |
1993 | 2007 | #endif | |
1994 | 2008 | ||
@@ -2492,2 +2506,3 @@ KServerSocket:: KServerSocket ( QString pw, Q_UINT16 port, int backlog, QObject | |||
2492 | mSocket = 0; | 2506 | mSocket = 0; |
2507 | mSyncActionDialog = 0; | ||
2493 | }; | 2508 | }; |
@@ -2530,3 +2545,4 @@ void KServerSocket::readClient() | |||
2530 | if ( tokens[1] == mPassWord ) | 2545 | if ( tokens[1] == mPassWord ) |
2531 | emit sendFile( mSocket ); | 2546 | //emit sendFile( mSocket ); |
2547 | send_file(); | ||
2532 | else { | 2548 | else { |
@@ -2538,3 +2554,4 @@ void KServerSocket::readClient() | |||
2538 | if ( tokens[1] == mPassWord ) | 2554 | if ( tokens[1] == mPassWord ) |
2539 | emit getFile( mSocket ); | 2555 | //emit getFile( mSocket ); |
2556 | get_file(); | ||
2540 | else { | 2557 | else { |
@@ -2550,2 +2567,104 @@ void KServerSocket::readClient() | |||
2550 | 2567 | ||
2568 | void KServerSocket::send_file() | ||
2569 | { | ||
2570 | qDebug("MainWindow::sendFile(QSocket* s) "); | ||
2571 | if ( mSyncActionDialog ) | ||
2572 | delete mSyncActionDialog; | ||
2573 | mSyncActionDialog = new QDialog ( 0, "input-dialog", true ); | ||
2574 | mSyncActionDialog->setCaption(i18n("Received sync request")); | ||
2575 | QLabel* label = new QLabel( i18n("Synchronizing...\nDo not use this application!\n\nIf syncing fails you can close this dialog."), mSyncActionDialog ); | ||
2576 | QVBoxLayout* lay = new QVBoxLayout( mSyncActionDialog ); | ||
2577 | lay->addWidget( label); | ||
2578 | lay->setMargin(7); | ||
2579 | lay->setSpacing(7); | ||
2580 | mSyncActionDialog->setFixedSize( 230, 120); | ||
2581 | mSyncActionDialog->show(); | ||
2582 | qDebug("KSS::saving ... "); | ||
2583 | emit saveFile(); | ||
2584 | qApp->processEvents(); | ||
2585 | QString fileName = mFileName; | ||
2586 | QFile file( fileName ); | ||
2587 | if (!file.open( IO_ReadOnly ) ) { | ||
2588 | delete mSyncActionDialog; | ||
2589 | mSyncActionDialog = 0; | ||
2590 | qDebug("KSS::error open file "); | ||
2591 | mSocket->close(); | ||
2592 | if ( mSocket->state() == QSocket::Idle ) | ||
2593 | QTimer::singleShot( 10, this , SLOT ( discardClient())); | ||
2594 | return ; | ||
2595 | |||
2596 | } | ||
2597 | mSyncActionDialog->setCaption( i18n("Sending file...") ); | ||
2598 | QTextStream ts( &file ); | ||
2599 | ts.setCodec( QTextCodec::codecForName("utf8") ); | ||
2600 | QTextStream os( mSocket ); | ||
2601 | os.setCodec( QTextCodec::codecForName("utf8") ); | ||
2602 | //os.setEncoding( QTextStream::UnicodeUTF8 ); | ||
2603 | while ( ! ts.atEnd() ) { | ||
2604 | os << ts.readLine() << "\n"; | ||
2605 | } | ||
2606 | //os << ts.read(); | ||
2607 | file.close(); | ||
2608 | mSyncActionDialog->setCaption( i18n("Waiting to get back synced file") ); | ||
2609 | qDebug("file sent "); | ||
2610 | mSocket->close(); | ||
2611 | if ( mSocket->state() == QSocket::Idle ) | ||
2612 | QTimer::singleShot( 10, this , SLOT ( discardClient())); | ||
2613 | } | ||
2614 | void KServerSocket::get_file() | ||
2615 | { | ||
2616 | mSyncActionDialog->setCaption( i18n("Receiving synced file...") ); | ||
2617 | |||
2618 | piTime.start(); | ||
2619 | piFileString = ""; | ||
2620 | QTimer::singleShot( 1, this , SLOT (readBackFileFromSocket( ) )); | ||
2621 | } | ||
2622 | |||
2623 | |||
2624 | void KServerSocket::readBackFileFromSocket() | ||
2625 | { | ||
2626 | qDebug("readBackFileFromSocket() %d ", piTime.elapsed ()); | ||
2627 | while ( mSocket->canReadLine () ) { | ||
2628 | piTime.restart(); | ||
2629 | QString line = mSocket->readLine (); | ||
2630 | piFileString += line; | ||
2631 | qDebug("readline: %s ", line.latin1()); | ||
2632 | mSyncActionDialog->setCaption( i18n("Received %1 bytes").arg( piFileString.length() ) ); | ||
2633 | |||
2634 | } | ||
2635 | if ( piTime.elapsed () < 3000 ) { | ||
2636 | // wait for more | ||
2637 | qDebug("waitformore "); | ||
2638 | QTimer::singleShot( 100, this , SLOT (readBackFileFromSocket( ) )); | ||
2639 | return; | ||
2640 | } | ||
2641 | QString fileName = mFileName; | ||
2642 | QFile file ( fileName ); | ||
2643 | if (!file.open( IO_WriteOnly ) ) { | ||
2644 | delete mSyncActionDialog; | ||
2645 | mSyncActionDialog = 0; | ||
2646 | qDebug("error open cal file "); | ||
2647 | piFileString = ""; | ||
2648 | emit file_received( false ); | ||
2649 | return ; | ||
2650 | |||
2651 | } | ||
2652 | |||
2653 | // mView->setLoadedFileVersion(QDateTime::currentDateTime().addSecs( -1)); | ||
2654 | QTextStream ts ( &file ); | ||
2655 | ts.setCodec( QTextCodec::codecForName("utf8") ); | ||
2656 | qDebug("finish "); | ||
2657 | mSyncActionDialog->setCaption( i18n("Writing file to disk...") ); | ||
2658 | ts << piFileString; | ||
2659 | mSocket->close(); | ||
2660 | if ( mSocket->state() == QSocket::Idle ) | ||
2661 | QTimer::singleShot( 10, this , SLOT ( discardClient())); | ||
2662 | file.close(); | ||
2663 | delete mSyncActionDialog; | ||
2664 | mSyncActionDialog = 0; | ||
2665 | piFileString = ""; | ||
2666 | emit file_received( true ); | ||
2667 | |||
2668 | } | ||
2669 | |||
2551 | KCommandSocket::KCommandSocket ( QString password, Q_UINT16 port, QString host, QObject * parent, const char * name ): QObject( parent, name ) | 2670 | KCommandSocket::KCommandSocket ( QString password, Q_UINT16 port, QString host, QObject * parent, const char * name ): QObject( parent, name ) |
@@ -2639,3 +2758,3 @@ void KCommandSocket::deleteSocket() | |||
2639 | mTimerSocket->stop(); | 2758 | mTimerSocket->stop(); |
2640 | KMessageBox::information( 0, i18n("ERROR:\nConnection to remote host timed out ")); | 2759 | KMessageBox::information( 0, i18n("ERROR:\nConnection to remote host timed out!\nDid you forgot to enable\nsyncing on remote host? ")); |
2641 | mRetVal = false; | 2760 | mRetVal = false; |