summaryrefslogtreecommitdiffabout
path: root/korganizer/mainwindow.cpp
Unidiff
Diffstat (limited to 'korganizer/mainwindow.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r--korganizer/mainwindow.cpp236
1 files changed, 73 insertions, 163 deletions
diff --git a/korganizer/mainwindow.cpp b/korganizer/mainwindow.cpp
index da73caf..bce2a54 100644
--- a/korganizer/mainwindow.cpp
+++ b/korganizer/mainwindow.cpp
@@ -74,8 +74,6 @@ MainWindow::MainWindow( QWidget *parent, const char *name, QString msg) :
74#ifdef DESKTOP_VERSION 74#ifdef DESKTOP_VERSION
75 setFont( QFont("Arial"), 14 ); 75 setFont( QFont("Arial"), 14 );
76#endif 76#endif
77 mCommandSocket = 0;
78 mCommandSocketFinish = 0;
79 mSyncActionDialog = 0; 77 mSyncActionDialog = 0;
80 mServerSocket = 0; 78 mServerSocket = 0;
81 mClosed = false; 79 mClosed = false;
@@ -1942,49 +1940,7 @@ void MainWindow::enableQuick()
1942 // connect( mServerSocket, SIGNAL ( sendFile(QSocket*) ), this, SLOT ( sendFile(QSocket*) ) ); 1940 // connect( mServerSocket, SIGNAL ( sendFile(QSocket*) ), this, SLOT ( sendFile(QSocket*) ) );
1943 //connect( mServerSocket, SIGNAL ( getFile(QSocket*) ), this, SLOT ( getFile(QSocket*) ) ); 1941 //connect( mServerSocket, SIGNAL ( getFile(QSocket*) ), this, SLOT ( getFile(QSocket*) ) );
1944} 1942}
1945void MainWindow::sendFile(QSocket* socket) 1943
1946{
1947 setCaption( i18n("Received request for file") );
1948 qDebug("MainWindow::sendFile(QSocket* s) ");
1949 if ( mSyncActionDialog )
1950 delete mSyncActionDialog;
1951 mSyncActionDialog = new QDialog ( this, "input-dialog", true );
1952 mSyncActionDialog->setCaption(i18n("KO/Pi - WARNING"));
1953 QLabel* label = new QLabel( i18n("Synchronizing...\nDo not use\nthis application!\n"), mSyncActionDialog );
1954 QVBoxLayout* lay = new QVBoxLayout( mSyncActionDialog );
1955 lay->addWidget( label);
1956 lay->setMargin(7);
1957 lay->setSpacing(7);
1958 mSyncActionDialog->setFixedSize( 200,100 );
1959 mSyncActionDialog->show();
1960 qDebug("saving ... ");
1961 save();
1962 qApp->processEvents();
1963 QString fileName = defaultFileName();
1964 QFile file( fileName );
1965 if (!file.open( IO_ReadOnly ) ) {
1966 setCaption( i18n("Error open file") );
1967 delete mSyncActionDialog;
1968 mSyncActionDialog = 0;
1969 qDebug("error open cal file ");
1970 return ;
1971
1972 }
1973 setCaption( i18n("Sending file...") );
1974 QTextStream ts( &file );
1975 ts.setCodec( QTextCodec::codecForName("utf8") );
1976 QTextStream os( socket );
1977 os.setCodec( QTextCodec::codecForName("utf8") );
1978 //os.setEncoding( QTextStream::UnicodeUTF8 );
1979 while ( ! ts.atEnd() ) {
1980 os << ts.readLine() << "\n";
1981 }
1982 //os << ts.read();
1983 socket->close();
1984 file.close();
1985 setCaption( i18n("File sent. Waiting to get back synced file") );
1986 qDebug("file sent ");
1987}
1988void MainWindow::getFile( bool success ) 1944void MainWindow::getFile( bool success )
1989{ 1945{
1990 if ( ! success ) { 1946 if ( ! success ) {
@@ -1996,70 +1952,9 @@ void MainWindow::getFile( bool success )
1996 mView->openCalendar( defaultFileName() ); 1952 mView->openCalendar( defaultFileName() );
1997 setCaption( i18n("Pi-Sync successful!") ); 1953 setCaption( i18n("Pi-Sync successful!") );
1998 1954
1999
2000#if 0
2001 setCaption( i18n("Receiving synced file...") );
2002
2003 piTime.start();
2004 piSocket = socket;
2005 piFileString = "";
2006 QTimer::singleShot( 1, this , SLOT (readBackFileFromSocket( ) ));
2007#endif
2008
2009} 1955}
2010void MainWindow::readBackFileFromSocket()
2011{
2012 qDebug("readBackFileFromSocket() %d ", piTime.elapsed ());
2013 while ( piSocket->canReadLine () ) {
2014 piTime.restart();
2015 QString line = piSocket->readLine ();
2016 piFileString += line;
2017 qDebug("readline: %s ", line.latin1());
2018 setCaption( i18n("Received %1 bytes").arg( piFileString.length() ) );
2019 1956
2020 }
2021 if ( piTime.elapsed () < 3000 ) {
2022 // wait for more
2023 qDebug("waitformore ");
2024 QTimer::singleShot( 100, this , SLOT (readBackFileFromSocket( ) ));
2025 return;
2026 }
2027 QString fileName = defaultFileName();
2028 QFile file ( fileName );
2029 if (!file.open( IO_WriteOnly ) ) {
2030 setCaption( i18n("Error open file for writing!") );
2031 delete mSyncActionDialog;
2032 mSyncActionDialog = 0;
2033 qDebug("error open cal file ");
2034 piFileString = "";
2035 return ;
2036
2037 }
2038
2039 mView->setLoadedFileVersion(QDateTime::currentDateTime().addSecs( -1));
2040 QTextStream ts ( &file );
2041 ts.setCodec( QTextCodec::codecForName("utf8") );
2042 qDebug("finish ");
2043 setCaption( i18n("Writing file to disk...") );
2044 ts << piFileString;
2045 setCaption( i18n("File received - reloading calendar...") );
2046 piSocket->close();
2047 file.close();
2048 mView->watchSavedFile();
2049 mView->openCalendar( defaultFileName() );
2050 setCaption( i18n("Pi-Sync successful!") );
2051 delete mSyncActionDialog;
2052 mSyncActionDialog = 0;
2053 piFileString = "";
2054 1957
2055
2056}
2057void MainWindow::endConnect()
2058{
2059 setCaption( i18n("No file received - syncing successful") );
2060 delete mSyncActionDialog;
2061 mSyncActionDialog = 0;
2062}
2063void MainWindow::performQuick() 1958void MainWindow::performQuick()
2064{ 1959{
2065 1960
@@ -2115,8 +2010,8 @@ void MainWindow::performQuickQuick()
2115 setCaption( i18n("Sorry, no valid port.Syncing cancelled.") ); 2010 setCaption( i18n("Sorry, no valid port.Syncing cancelled.") );
2116 return; 2011 return;
2117 } 2012 }
2118 mCommandSocket = new KCommandSocket( mPassWordPiSync, port, KOPrefs::instance()->mActiveSyncIP, this ); 2013 KCommandSocket* commandSocket = new KCommandSocket( mPassWordPiSync, port, KOPrefs::instance()->mActiveSyncIP, this );
2119 connect( mCommandSocket, SIGNAL(commandFinished( bool )), this, SLOT(deleteCommandSocket(bool)) ); 2014 connect( commandSocket, SIGNAL(commandFinished( KCommandSocket*, bool )), this, SLOT(deleteCommandSocket(KCommandSocket*,bool)) );
2120 setCaption( i18n("Sending request for remote file ...") ); 2015 setCaption( i18n("Sending request for remote file ...") );
2121 QString fileName; 2016 QString fileName;
2122#ifdef _WIN32_ 2017#ifdef _WIN32_
@@ -2124,27 +2019,31 @@ void MainWindow::performQuickQuick()
2124#else 2019#else
2125 fileName = "/tmp/kopitempfile.ics"; 2020 fileName = "/tmp/kopitempfile.ics";
2126#endif 2021#endif
2127 mCommandSocket->readFile( fileName ); 2022 commandSocket->readFile( fileName );
2128} 2023}
2129void MainWindow::deleteCommandSocket( bool success) 2024void MainWindow::deleteCommandSocket(KCommandSocket*s, bool success)
2130{ 2025{
2131 if ( ! success ) { 2026 if ( ! success ) {
2132 setCaption( i18n("ERROR:Receiving remote file failed.") ); 2027 setCaption( i18n("ERROR:Receiving remote file failed.") );
2028 delete s;
2133 // pending : send stop 2029 // pending : send stop
2134 return; 2030 return;
2135 2031
2136 } 2032 }
2137 QTimer::singleShot( 1, this , SLOT ( readFileFromSocket())); 2033 QTimer::singleShot( 1, this , SLOT ( readFileFromSocket()));
2138 delete mCommandSocket; 2034 qDebug("MainWindow::deleteCommandSocket ");
2035 delete s;
2139} 2036}
2140void MainWindow::deleteCommandSocketFinish() 2037void MainWindow::deleteCommandSocketFinish(KCommandSocket* s, bool success )
2141{ 2038{
2142 if ( ! mCommandSocketFinish) 2039 if ( ! success ) {
2143 return; 2040 setCaption( i18n("ERROR:Writing back file failed.") );
2144 // KMessageBox::information( 0, i18n("MainWindow::deleteCommandSocketFinish() ")); 2041 } else {
2145 qDebug("MainWindow::deletemCommandSocketFinish() "); 2042 qDebug("Syncing succesful! ");
2146 delete mCommandSocketFinish; 2043 setCaption( i18n("Pi-Sync succesful!") );
2147 mCommandSocketFinish = 0; 2044 }
2045 qDebug("MainWindow::deleteCommandSocketFinish ");
2046 delete s;
2148} 2047}
2149void MainWindow::readFileFromSocket() 2048void MainWindow::readFileFromSocket()
2150{ 2049{
@@ -2183,43 +2082,12 @@ void MainWindow::readFileFromSocket()
2183 return; 2082 return;
2184 } 2083 }
2185 2084
2186 if ( !mCommandSocketFinish ) { 2085 KCommandSocket* commandSocket = new KCommandSocket( mPassWordPiSync, KOPrefs::instance()->mActiveSyncPort.toUInt(), KOPrefs::instance()->mActiveSyncIP, this );
2187 mCommandSocketFinish = new QSocket( this ); 2086 connect( commandSocket, SIGNAL(commandFinished( KCommandSocket*, bool )), this, SLOT(deleteCommandSocketFinish(KCommandSocket*,bool)) );
2188 connect( mCommandSocketFinish, SIGNAL(delayedCloseFinished ()), this, SLOT(deleteCommandSocketFinish()) ); 2087 if ( KOPrefs::instance()->mWriteBackFile )
2189 } 2088 commandSocket->writeFile( fileName );
2190 mCommandSocketFinish->connectToHost( KOPrefs::instance()->mActiveSyncIP, KOPrefs::instance()->mActiveSyncPort.toUInt() ); 2089 else
2191 2090 commandSocket->sendStop();
2192 QString host = KOPrefs::instance()->mActiveSyncIP;
2193 QFile file2( fileName );
2194 if (!file2.open( IO_ReadOnly ) ) {
2195 setCaption( i18n("Error: Cannot open temp file for read.") );
2196 qDebug("error open cal file ");
2197 return ;
2198
2199 }
2200 QTextStream ts2( &file2 );
2201 ts2.setCodec( QTextCodec::codecForName("utf8") );
2202 QTextStream os2( mCommandSocketFinish );
2203 os2.setCodec( QTextCodec::codecForName("utf8") );
2204 //os.setEncoding( QTextStream::UnicodeUTF8 );
2205 if ( KOPrefs::instance()->mWriteBackFile ) {
2206 setCaption( i18n("Sending back synced file...") );
2207 os2 << "PUT " << mPassWordPiSync << "\r\n";;
2208 while ( ! ts2.atEnd() ) {
2209 os2 << ts2.readLine() << "\n";
2210 }
2211 } else {
2212 os2 << "STOP\r\n";
2213 }
2214 mCommandSocketFinish->close();
2215 if ( mCommandSocketFinish->state() == QSocket::Idle )
2216 QTimer::singleShot( 10, this , SLOT ( deleteCommandSocketFinish()));
2217 file2.close();
2218 qDebug("Syncing succesful! ");
2219 setCaption( i18n("Pi-Sync succesful!") );
2220
2221 // KMessageBox::information( 0, i18n(" Pi-Sync succesful! "));
2222
2223} 2091}
2224 2092
2225void MainWindow::syncLocalFile() 2093void MainWindow::syncLocalFile()
@@ -2560,11 +2428,16 @@ void KServerSocket::readClient()
2560 } 2428 }
2561 } 2429 }
2562 if ( tokens[0] == "STOP" ) { 2430 if ( tokens[0] == "STOP" ) {
2563 emit endConnect(); 2431 //emit endConnect();
2432 end_connect();
2564 } 2433 }
2565 } 2434 }
2566} 2435}
2567 2436void KServerSocket::end_connect()
2437{
2438 delete mSyncActionDialog;
2439 mSyncActionDialog = 0;
2440}
2568void KServerSocket::send_file() 2441void KServerSocket::send_file()
2569{ 2442{
2570 qDebug("MainWindow::sendFile(QSocket* s) "); 2443 qDebug("MainWindow::sendFile(QSocket* s) ");
@@ -2695,10 +2568,48 @@ void KCommandSocket::readFile( QString fn )
2695 mTimerSocket->start( 10000 ); 2568 mTimerSocket->start( 10000 );
2696} 2569}
2697 2570
2698void KCommandSocket::writeFile( QString ) 2571void KCommandSocket::writeFile( QString fileName )
2699{ 2572{
2573 QFile file2( fileName );
2574 if (!file2.open( IO_ReadOnly ) ) {
2575 mRetVal= false;
2576 deleteSocket();
2577 return ;
2578
2579 }
2580 if ( !mSocket ) {
2581 mSocket = new QSocket( this );
2582 connect( mSocket, SIGNAL(delayedCloseFinished ()), this, SLOT(deleteSocket()) );
2583 }
2584 QTextStream ts2( &file2 );
2585 ts2.setCodec( QTextCodec::codecForName("utf8") );
2586 QTextStream os2( mSocket );
2587 os2.setCodec( QTextCodec::codecForName("utf8") );
2588 os2 << "PUT " << mPassWord << "\r\n";;
2589 while ( ! ts2.atEnd() ) {
2590 os2 << ts2.readLine() << "\n";
2591 }
2592 mSocket->close();
2593 if ( mSocket->state() == QSocket::Idle )
2594 QTimer::singleShot( 10, this , SLOT ( deleteSocket()));
2595 file2.close();
2596}
2700 2597
2598void KCommandSocket::sendStop()
2599{
2600 if ( !mSocket ) {
2601 mSocket = new QSocket( this );
2602 connect( mSocket, SIGNAL(delayedCloseFinished ()), this, SLOT(deleteSocket()) );
2603 }
2604 QTextStream os2( mSocket );
2605 os2.setCodec( QTextCodec::codecForName("utf8") );
2606 os2 << "STOP\r\n";
2607 mRetVal= true;
2608 mSocket->close();
2609 if ( mSocket->state() == QSocket::Idle )
2610 QTimer::singleShot( 10, this , SLOT ( deleteSocket()));
2701} 2611}
2612
2702void KCommandSocket::startReadFileFromSocket() 2613void KCommandSocket::startReadFileFromSocket()
2703{ 2614{
2704 if ( ! mFirst ) 2615 if ( ! mFirst )
@@ -2752,16 +2663,15 @@ void KCommandSocket::readFileFromSocket()
2752 2663
2753void KCommandSocket::deleteSocket() 2664void KCommandSocket::deleteSocket()
2754{ 2665{
2755 if ( !mSocket)
2756 return;
2757 if ( mTimerSocket->isActive () ) { 2666 if ( mTimerSocket->isActive () ) {
2758 mTimerSocket->stop(); 2667 mTimerSocket->stop();
2759 KMessageBox::information( 0, i18n("ERROR:\nConnection to remote host timed out!\nDid you forgot to enable\nsyncing on remote host? ")); 2668 KMessageBox::information( 0, i18n("ERROR:\nConnection to remote host timed out!\nDid you forgot to enable\nsyncing on remote host? "));
2760 mRetVal = false; 2669 mRetVal = false;
2761 } 2670 }
2762 qDebug("KCommandSocket::deleteSocket() %d", mRetVal); 2671 qDebug("KCommandSocket::deleteSocket() %d", mRetVal );
2763 delete mSocket; 2672 if ( mSocket)
2673 delete mSocket;
2764 mSocket = 0; 2674 mSocket = 0;
2765 emit commandFinished( mRetVal ); 2675 emit commandFinished( this, mRetVal );
2766} 2676}
2767 2677