summaryrefslogtreecommitdiffabout
authorzautrix <zautrix>2004-10-04 17:32:48 (UTC)
committer zautrix <zautrix>2004-10-04 17:32:48 (UTC)
commit2a99a7ca0816fd68b7fcf2f1fee023aef019000d (patch) (unidiff)
treecef1bc6813689ecc05ef8d1d4323947adeabafcb
parent01b5806c61deb8368f8f454fdec1c4767c73a840 (diff)
downloadkdepimpi-2a99a7ca0816fd68b7fcf2f1fee023aef019000d.zip
kdepimpi-2a99a7ca0816fd68b7fcf2f1fee023aef019000d.tar.gz
kdepimpi-2a99a7ca0816fd68b7fcf2f1fee023aef019000d.tar.bz2
more sync fixes
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--korganizer/mainwindow.cpp178
-rw-r--r--korganizer/mainwindow.h34
-rw-r--r--version2
3 files changed, 143 insertions, 71 deletions
diff --git a/korganizer/mainwindow.cpp b/korganizer/mainwindow.cpp
index 10cb2a2..e4b7869 100644
--- a/korganizer/mainwindow.cpp
+++ b/korganizer/mainwindow.cpp
@@ -71,8 +71,6 @@ MainWindow::MainWindow( QWidget *parent, const char *name, QString msg) :
71 QMainWindow( parent, name ) 71 QMainWindow( parent, name )
72{ 72{
73 mPassWordPiSync = "abc"; 73 mPassWordPiSync = "abc";
74 mTimerCommandSocket = new QTimer ( this );
75 connect( mTimerCommandSocket, SIGNAL ( timeout () ), this, SLOT ( deleteCommandSocket() ) );
76#ifdef DESKTOP_VERSION 74#ifdef DESKTOP_VERSION
77 setFont( QFont("Arial"), 14 ); 75 setFont( QFont("Arial"), 14 );
78#endif 76#endif
@@ -2103,34 +2101,27 @@ void MainWindow::performQuickQuick()
2103 setCaption( i18n("Sorry, no valid port.Syncing cancelled.") ); 2101 setCaption( i18n("Sorry, no valid port.Syncing cancelled.") );
2104 return; 2102 return;
2105 } 2103 }
2106 if ( !mCommandSocket ) { 2104 mCommandSocket = new KCommandSocket( mPassWordPiSync, port, KOPrefs::instance()->mActiveSyncIP, this );
2107 mCommandSocket = new QSocket( this ); 2105 connect( mCommandSocket, SIGNAL(commandFinished( bool )), this, SLOT(deleteCommandSocket(bool)) );
2108 // delete mCommandSocket;
2109 //mCommandSocket = new QSocket( this );
2110 connect( mCommandSocket, SIGNAL(readyRead()), this, SLOT(readFileFromSocket()) );
2111 connect( mCommandSocket, SIGNAL(delayedCloseFinished ()), this, SLOT(deleteCommandSocket()) );
2112 }
2113 QString host = KOPrefs::instance()->mActiveSyncIP;
2114 mCommandSocket->connectToHost( host, port );
2115 QTextStream os( mCommandSocket );
2116 os.setEncoding( QTextStream::UnicodeUTF8 );
2117 os << "GET " << mPassWordPiSync << "\r\n";
2118 setCaption( i18n("Sending request for remote file ...") ); 2106 setCaption( i18n("Sending request for remote file ...") );
2119 mTimerCommandSocket->start( 10000 ); 2107 QString fileName;
2120 2108#ifdef _WIN32_
2109 fileName = defaultFileName() +"sync";
2110#else
2111 fileName = "/tmp/kopitempfile.ics";
2112#endif
2113 mCommandSocket->readFile( fileName );
2121} 2114}
2122void MainWindow::deleteCommandSocket() 2115void MainWindow::deleteCommandSocket( bool success)
2123{ 2116{
2124 if ( !mCommandSocket) 2117 if ( ! success ) {
2118 setCaption( i18n("ERROR:Receiving remote file failed.") );
2119 // pending : send stop
2125 return; 2120 return;
2126 if ( mTimerCommandSocket->isActive () ) { 2121
2127 KMessageBox::information( 0, i18n("ERROR:\nConnection to remote host timed out "));
2128 mTimerCommandSocket->stop();
2129 } 2122 }
2130 //KMessageBox::information( 0, i18n("MainWindow::deleteCommandSocket ")); 2123 QTimer::singleShot( 1, this , SLOT ( readFileFromSocket()));
2131 qDebug("MainWindow::deletemCommandSocket() "); 2124 delete mCommandSocket;
2132 delete mCommandSocket;
2133 mCommandSocket = 0;
2134} 2125}
2135void MainWindow::deleteCommandSocketFinish() 2126void MainWindow::deleteCommandSocketFinish()
2136{ 2127{
@@ -2143,7 +2134,7 @@ void MainWindow::deleteCommandSocketFinish()
2143} 2134}
2144void MainWindow::readFileFromSocket() 2135void MainWindow::readFileFromSocket()
2145{ 2136{
2146 mTimerCommandSocket->stop(); 2137 // mTimerCommandSocket->stop();
2147 setCaption( i18n("Receiving remote file ...") ); 2138 setCaption( i18n("Receiving remote file ...") );
2148 qDebug("MainWindow::readFileFromSocket() "); 2139 qDebug("MainWindow::readFileFromSocket() ");
2149 QString fileName; 2140 QString fileName;
@@ -2152,40 +2143,7 @@ void MainWindow::readFileFromSocket()
2152#else 2143#else
2153 fileName = "/tmp/kopitempfile.ics"; 2144 fileName = "/tmp/kopitempfile.ics";
2154#endif 2145#endif
2155 QFile file( fileName ); 2146
2156 if (!file.open( IO_WriteOnly ) ) {
2157 setCaption( i18n("Error: Cannot open temp file for write.") );
2158 qDebug("Error open temp calender file for writing: %s",fileName.latin1() );
2159 return ;
2160 }
2161
2162 //QTextStream os2( mCommandSocket );
2163 //os2.setEncoding( QTextStream::UnicodeUTF8 );
2164
2165 QTextStream ts( &file );
2166 ts.setCodec( QTextCodec::codecForName("utf8") );
2167 bool first = true;
2168 while ( mCommandSocket->canReadLine () || first) {
2169 first = false;
2170 while ( mCommandSocket->canReadLine () ) {
2171 ts << mCommandSocket->readLine ();
2172 }
2173 QTime ti;
2174 ti.start();
2175 while ( ti.elapsed () < 3000 && !mCommandSocket->canReadLine () ) {
2176 qApp->processEvents();
2177 qDebug("waiting2 %d ",ti.elapsed () );
2178 if ( !mCommandSocket->canReadLine () )
2179 mCommandSocket->waitForMore ( 100 );
2180 }
2181 //mCommandSocket->waitForMore ( 5000 );
2182 }
2183 file.close();
2184 mCommandSocket->close();
2185 if ( mCommandSocket->state() == QSocket::Idle )
2186 deleteCommandSocket();
2187 // pending: deleting after signal SIGNAL(delayedCloseFinished())
2188 //delete mCommandSocket;
2189 setCaption( i18n("Remote file saved to temp file.") ); 2147 setCaption( i18n("Remote file saved to temp file.") );
2190 //mCommandSocket = 0; 2148 //mCommandSocket = 0;
2191 mCurrentSyncProfile = 2 ; // last file 2149 mCurrentSyncProfile = 2 ; // last file
@@ -2217,7 +2175,6 @@ void MainWindow::readFileFromSocket()
2217 } 2175 }
2218 mCommandSocketFinish->connectToHost( KOPrefs::instance()->mActiveSyncIP, KOPrefs::instance()->mActiveSyncPort.toUInt() ); 2176 mCommandSocketFinish->connectToHost( KOPrefs::instance()->mActiveSyncIP, KOPrefs::instance()->mActiveSyncPort.toUInt() );
2219 2177
2220 // pending connect signals connected () and error to new slots
2221 QString host = KOPrefs::instance()->mActiveSyncIP; 2178 QString host = KOPrefs::instance()->mActiveSyncIP;
2222 QFile file2( fileName ); 2179 QFile file2( fileName );
2223 if (!file2.open( IO_ReadOnly ) ) { 2180 if (!file2.open( IO_ReadOnly ) ) {
@@ -2243,7 +2200,7 @@ void MainWindow::readFileFromSocket()
2243 mCommandSocketFinish->close(); 2200 mCommandSocketFinish->close();
2244 if ( mCommandSocketFinish->state() == QSocket::Idle ) 2201 if ( mCommandSocketFinish->state() == QSocket::Idle )
2245 QTimer::singleShot( 10, this , SLOT ( deleteCommandSocketFinish())); 2202 QTimer::singleShot( 10, this , SLOT ( deleteCommandSocketFinish()));
2246 file.close(); 2203 file2.close();
2247 qDebug("Syncing succesful! "); 2204 qDebug("Syncing succesful! ");
2248 setCaption( i18n("Pi-Sync succesful!") ); 2205 setCaption( i18n("Pi-Sync succesful!") );
2249 2206
@@ -2591,14 +2548,101 @@ void KServerSocket::readClient()
2591 } 2548 }
2592} 2549}
2593 2550
2551KCommandSocket::KCommandSocket ( QString password, Q_UINT16 port, QString host, QObject * parent, const char * name ): QObject( parent, name )
2552{
2553 mPassWord = password;
2554 mSocket = 0;
2555 mPort = port;
2556 mHost = host;
2594 2557
2558 mRetVal = false;
2559 mTimerSocket = new QTimer ( this );
2560 connect( mTimerSocket, SIGNAL ( timeout () ), this, SLOT ( deleteSocket() ) );
2561}
2562void KCommandSocket::readFile( QString fn )
2563{
2564 if ( !mSocket ) {
2565 mSocket = new QSocket( this );
2566 connect( mSocket, SIGNAL(readyRead()), this, SLOT(startReadFileFromSocket()) );
2567 connect( mSocket, SIGNAL(delayedCloseFinished ()), this, SLOT(deleteSocket()) );
2568 }
2569 mFileString = "";
2570 mFileName = fn;
2571 mFirst = true;
2572 mSocket->connectToHost( mHost, mPort );
2573 QTextStream os( mSocket );
2574 os.setEncoding( QTextStream::UnicodeUTF8 );
2575 os << "GET " << mPassWord << "\r\n";
2576 mTimerSocket->start( 10000 );
2577}
2595 2578
2579void KCommandSocket::writeFile( QString )
2580{
2596 2581
2582}
2583void KCommandSocket::startReadFileFromSocket()
2584{
2585 if ( ! mFirst )
2586 return;
2587 mFirst = false;
2588 mTimerSocket->stop();
2589 mFileString = "";
2590 mTime.start();
2591 QTimer::singleShot( 1, this , SLOT (readFileFromSocket( ) ));
2597 2592
2593}
2594void KCommandSocket::readFileFromSocket()
2595{
2596 qDebug("readBackFileFromSocket() %d ", mTime.elapsed ());
2597 while ( mSocket->canReadLine () ) {
2598 mTime.restart();
2599 QString line = mSocket->readLine ();
2600 mFileString += line;
2601 qDebug("readline: %s ", line.latin1());
2602 }
2603 if ( mTime.elapsed () < 3000 ) {
2604 // wait for more
2605 qDebug("waitformore ");
2606 QTimer::singleShot( 100, this , SLOT (readFileFromSocket( ) ));
2607 return;
2608 }
2609 QString fileName = mFileName;
2610 QFile file ( fileName );
2611 if (!file.open( IO_WriteOnly ) ) {
2612 mFileString = "";
2613 mRetVal = false;
2614 qDebug("Error open temp calender file for writing: %s",fileName.latin1() );
2615 deleteSocket();
2616 return ;
2617
2618 }
2619 // mView->setLoadedFileVersion(QDateTime::currentDateTime().addSecs( -1));
2620 QTextStream ts ( &file );
2621 ts.setCodec( QTextCodec::codecForName("utf8") );
2622 qDebug("finish ");
2623 ts << mFileString;
2624 file.close();
2625 mFileString = "";
2626 mRetVal = true;
2627 mSocket->close();
2628 // if state is not idle, deleteSocket(); is called via
2629 // connect( mSocket, SIGNAL(delayedCloseFinished ()), this, SLOT(deleteSocket()) );
2630 if ( mSocket->state() == QSocket::Idle )
2631 deleteSocket();
2632}
2598 2633
2599 2634void KCommandSocket::deleteSocket()
2600 2635{
2601 2636 if ( !mSocket)
2602 2637 return;
2603 2638 if ( mTimerSocket->isActive () ) {
2639 mTimerSocket->stop();
2640 KMessageBox::information( 0, i18n("ERROR:\nConnection to remote host timed out "));
2641 mRetVal = false;
2642 }
2643 qDebug("KCommandSocket::deleteSocket() %d", mRetVal);
2644 delete mSocket;
2645 mSocket = 0;
2646 emit commandFinished( mRetVal );
2647}
2604 2648
diff --git a/korganizer/mainwindow.h b/korganizer/mainwindow.h
index d217578..11a816c 100644
--- a/korganizer/mainwindow.h
+++ b/korganizer/mainwindow.h
@@ -46,6 +46,34 @@ private slots:
46 QString mPassWord; 46 QString mPassWord;
47}; 47};
48 48
49class KCommandSocket : public QObject
50{
51 Q_OBJECT
52
53public:
54 KCommandSocket ( QString password, Q_UINT16 port, QString host, QObject * parent=0, const char * name=0 );
55 void readFile( QString );
56 void writeFile( QString );
57
58
59signals:
60 void commandFinished( bool );
61private slots:
62 void startReadFileFromSocket();
63 void readFileFromSocket();
64 void deleteSocket();
65 private :
66 QSocket* mSocket;
67 QString mPassWord;
68 Q_UINT16 mPort;
69 QString mHost;
70 QString mFileName;
71 QTimer* mTimerSocket;
72 bool mRetVal;
73 QTime mTime;
74 QString mFileString;
75 bool mFirst;
76};
49 77
50namespace KCal { 78namespace KCal {
51class CalendarLocal; 79class CalendarLocal;
@@ -121,7 +149,7 @@ class MainWindow : public QMainWindow
121 QSocket* piSocket; 149 QSocket* piSocket;
122 QString piFileString; 150 QString piFileString;
123 QTime piTime; 151 QTime piTime;
124 void deleteCommandSocket(); 152 void deleteCommandSocket(bool);
125 void deleteCommandSocketFinish(); 153 void deleteCommandSocketFinish();
126 void fillSyncMenu(); 154 void fillSyncMenu();
127 void sendFile(QSocket* s); 155 void sendFile(QSocket* s);
@@ -130,9 +158,9 @@ class MainWindow : public QMainWindow
130 void readBackFileFromSocket(); 158 void readBackFileFromSocket();
131 void endConnect(); 159 void endConnect();
132 private: 160 private:
133 QTimer* mTimerCommandSocket; 161 //QTimer* mTimerCommandSocket;
134 QString mPassWordPiSync; 162 QString mPassWordPiSync;
135 QSocket* mCommandSocket; 163 KCommandSocket* mCommandSocket;
136 QSocket* mCommandSocketFinish; 164 QSocket* mCommandSocketFinish;
137 KServerSocket * mServerSocket; 165 KServerSocket * mServerSocket;
138 bool mClosed; 166 bool mClosed;
diff --git a/version b/version
index 576852d..f085278 100644
--- a/version
+++ b/version
@@ -1 +1 @@
version = "1.9.6"; version = "1.9.7";