-rw-r--r-- | korganizer/mainwindow.cpp | 181 | ||||
-rw-r--r-- | korganizer/mainwindow.h | 14 |
2 files changed, 124 insertions, 71 deletions
diff --git a/korganizer/mainwindow.cpp b/korganizer/mainwindow.cpp index 7bf33d3..8e2f956 100644 --- a/korganizer/mainwindow.cpp +++ b/korganizer/mainwindow.cpp | |||
@@ -71,5 +71,7 @@ MainWindow::MainWindow( QWidget *parent, const char *name, QString msg) : | |||
71 | QMainWindow( parent, name ) | 71 | QMainWindow( parent, name ) |
72 | { | 72 | { |
73 | 73 | mPassWordPiSync = "abc"; | |
74 | mTimerCommandSocket = new QTimer ( this ); | ||
75 | connect( mTimerCommandSocket, SIGNAL ( timeout () ), this, SLOT ( deleteCommandSocket() ) ); | ||
74 | #ifdef DESKTOP_VERSION | 76 | #ifdef DESKTOP_VERSION |
75 | setFont( QFont("Arial"), 14 ); | 77 | setFont( QFont("Arial"), 14 ); |
@@ -1890,4 +1892,5 @@ QString MainWindow::getPassword( ) | |||
1890 | void MainWindow::enableQuick() | 1892 | void MainWindow::enableQuick() |
1891 | { | 1893 | { |
1894 | QString passWordPiSync = "bhdrvmk"; | ||
1892 | QString retfile = ""; | 1895 | QString retfile = ""; |
1893 | QDialog dia ( this, "input-dialog", true ); | 1896 | QDialog dia ( this, "input-dialog", true ); |
@@ -1900,6 +1903,12 @@ void MainWindow::enableQuick() | |||
1900 | lay.addWidget( &label); | 1903 | lay.addWidget( &label); |
1901 | lay.addWidget( &lab); | 1904 | lay.addWidget( &lab); |
1905 | |||
1906 | QLineEdit lepw ( &dia ); | ||
1907 | lepw.setText( "abc" ); | ||
1908 | QLabel label2 ( i18n("Password to enable\naccess from remote:"), &dia ); | ||
1909 | lay.addWidget( &label2); | ||
1910 | lay.addWidget( &lepw); | ||
1902 | dia.setFixedSize( 230,80 ); | 1911 | dia.setFixedSize( 230,80 ); |
1903 | dia.setCaption( i18n("Enter port for Easy-Pi-Sync") ); | 1912 | dia.setCaption( i18n("Enter port for Pi-Sync") ); |
1904 | QPushButton pb ( "OK", &dia); | 1913 | QPushButton pb ( "OK", &dia); |
1905 | lay.addWidget( &pb ); | 1914 | lay.addWidget( &pb ); |
@@ -1912,4 +1921,5 @@ void MainWindow::enableQuick() | |||
1912 | return; | 1921 | return; |
1913 | dia.hide(); | 1922 | dia.hide(); |
1923 | passWordPiSync = lepw.text(); | ||
1914 | qApp->processEvents(); | 1924 | qApp->processEvents(); |
1915 | KOPrefs::instance()->mPassiveSyncPort = retfile; | 1925 | KOPrefs::instance()->mPassiveSyncPort = retfile; |
@@ -1917,9 +1927,9 @@ void MainWindow::enableQuick() | |||
1917 | Q_UINT16 port = retfile.toUInt(&ok); | 1927 | Q_UINT16 port = retfile.toUInt(&ok); |
1918 | if ( ! ok ) { | 1928 | if ( ! ok ) { |
1919 | qDebug("no valid port "); | 1929 | KMessageBox::information( this, i18n("No valid port")); |
1920 | return; | 1930 | return; |
1921 | } | 1931 | } |
1922 | qDebug("port %d ", port); | 1932 | qDebug("port %d ", port); |
1923 | mServerSocket = new KServerSocket ( port ,1 ); | 1933 | mServerSocket = new KServerSocket ( passWordPiSync, port ,1 ); |
1924 | qDebug("connected "); | 1934 | qDebug("connected "); |
1925 | if ( !mServerSocket->ok() ) { | 1935 | if ( !mServerSocket->ok() ) { |
@@ -1947,7 +1957,7 @@ void MainWindow::sendFile(QSocket* socket) | |||
1947 | mSyncActionDialog->setFixedSize( 200,100 ); | 1957 | mSyncActionDialog->setFixedSize( 200,100 ); |
1948 | mSyncActionDialog->show(); | 1958 | mSyncActionDialog->show(); |
1949 | qApp->processEvents(); | ||
1950 | qDebug("saving ... "); | 1959 | qDebug("saving ... "); |
1951 | save(); | 1960 | save(); |
1961 | qApp->processEvents(); | ||
1952 | QString fileName = defaultFileName(); | 1962 | QString fileName = defaultFileName(); |
1953 | QFile file( fileName ); | 1963 | QFile file( fileName ); |
@@ -1979,11 +1989,36 @@ void MainWindow::getFile(QSocket* socket) | |||
1979 | setCaption( i18n("Receiving synced file...") ); | 1989 | setCaption( i18n("Receiving synced file...") ); |
1980 | 1990 | ||
1991 | piTime.start(); | ||
1992 | piSocket = socket; | ||
1993 | piFileString = ""; | ||
1994 | QTimer::singleShot( 1, this , SLOT (readBackFileFromSocket( ) )); | ||
1995 | |||
1996 | |||
1997 | } | ||
1998 | void MainWindow::readBackFileFromSocket() | ||
1999 | { | ||
2000 | qDebug("readBackFileFromSocket() %d ", piTime.elapsed ()); | ||
2001 | while ( piSocket->canReadLine () ) { | ||
2002 | piTime.restart(); | ||
2003 | QString line = piSocket->readLine (); | ||
2004 | piFileString += line; | ||
2005 | qDebug("readline: %s ", line.latin1()); | ||
2006 | setCaption( i18n("Received %1 bytes").arg( piFileString.length() ) ); | ||
2007 | |||
2008 | } | ||
2009 | if ( piTime.elapsed () < 3000 ) { | ||
2010 | // wait for more | ||
2011 | qDebug("waitformore "); | ||
2012 | QTimer::singleShot( 100, this , SLOT (readBackFileFromSocket( ) )); | ||
2013 | return; | ||
2014 | } | ||
1981 | QString fileName = defaultFileName(); | 2015 | QString fileName = defaultFileName(); |
1982 | QFile file( fileName ); | 2016 | QFile file ( fileName ); |
1983 | if (!file.open( IO_WriteOnly ) ) { | 2017 | if (!file.open( IO_WriteOnly ) ) { |
1984 | setCaption( i18n("Error open file") ); | 2018 | setCaption( i18n("Error open file for writing!") ); |
1985 | delete mSyncActionDialog; | 2019 | delete mSyncActionDialog; |
1986 | mSyncActionDialog = 0; | 2020 | mSyncActionDialog = 0; |
1987 | qDebug("error open cal file "); | 2021 | qDebug("error open cal file "); |
2022 | piFileString = ""; | ||
1988 | return ; | 2023 | return ; |
1989 | 2024 | ||
@@ -1991,60 +2026,21 @@ void MainWindow::getFile(QSocket* socket) | |||
1991 | 2026 | ||
1992 | mView->setLoadedFileVersion(QDateTime::currentDateTime().addSecs( -1)); | 2027 | mView->setLoadedFileVersion(QDateTime::currentDateTime().addSecs( -1)); |
1993 | QTextStream ts( &file ); | 2028 | QTextStream ts ( &file ); |
1994 | ts.setCodec( QTextCodec::codecForName("utf8") ); | 2029 | ts.setCodec( QTextCodec::codecForName("utf8") ); |
1995 | bool first = true; | 2030 | qDebug("finish "); |
1996 | while ( socket->canReadLine () || first ) { | 2031 | setCaption( i18n("Writing file to disk...") ); |
1997 | first = false; | 2032 | ts << piFileString; |
1998 | while ( socket->canReadLine () ) { | ||
1999 | qDebug("avail %d ", socket->bytesAvailable () ); | ||
2000 | ts << socket->readLine (); | ||
2001 | } | ||
2002 | QTime ti; | ||
2003 | ti.start(); | ||
2004 | while ( ti.elapsed () < 5000 && !socket->canReadLine () ) { | ||
2005 | qDebug("waiting1a %d %d ",ti.elapsed (), socket->bytesAvailable () ); | ||
2006 | //qApp->processEvents(); | ||
2007 | qDebug("waiting1b %d ",ti.elapsed () ); | ||
2008 | if ( !socket->canReadLine () ) { | ||
2009 | qDebug("waiting1c %d ",ti.elapsed () ); | ||
2010 | #ifndef _WIN32_ | ||
2011 | usleep( 100000); | ||
2012 | #endif | ||
2013 | } | ||
2014 | //socket->waitForMore ( 100 ); | ||
2015 | } | ||
2016 | ts << socket->readLine (); | ||
2017 | #if 0 | ||
2018 | #ifdef DESKTOP_VERSION | ||
2019 | socket->waitForMore ( 5000 ); | ||
2020 | #else | ||
2021 | // socket->waitForMore ( 5000 ); | ||
2022 | // seems to be broken in qt2 | ||
2023 | bool stop = false; | ||
2024 | QTime ti; | ||
2025 | ti.start(); | ||
2026 | while ( ti.elapsed < 5000 && !stop ) { | ||
2027 | qApp->processEvents(); | ||
2028 | if ( socket->canReadLine () ) | ||
2029 | stop = true ; | ||
2030 | else { | ||
2031 | usleep( 100000 ); | ||
2032 | |||
2033 | } | ||
2034 | } | ||
2035 | #endif | ||
2036 | #endif | ||
2037 | } | ||
2038 | setCaption( i18n("File received - reloading calendar...") ); | 2033 | setCaption( i18n("File received - reloading calendar...") ); |
2039 | socket->close(); | 2034 | piSocket->close(); |
2040 | file.close(); | 2035 | file.close(); |
2041 | mView->watchSavedFile(); | 2036 | mView->watchSavedFile(); |
2042 | mView->openCalendar( defaultFileName() ); | 2037 | mView->openCalendar( defaultFileName() ); |
2043 | setCaption( i18n("Easy-Pi-Sync successful!") ); | 2038 | setCaption( i18n("Pi-Sync successful!") ); |
2044 | delete mSyncActionDialog; | 2039 | delete mSyncActionDialog; |
2045 | mSyncActionDialog = 0; | 2040 | mSyncActionDialog = 0; |
2041 | piFileString = ""; | ||
2046 | 2042 | ||
2047 | 2043 | ||
2048 | } | 2044 | } |
2049 | void MainWindow::endConnect() | 2045 | void MainWindow::endConnect() |
2050 | { | 2046 | { |
@@ -2055,4 +2051,5 @@ void MainWindow::endConnect() | |||
2055 | void MainWindow::performQuick() | 2051 | void MainWindow::performQuick() |
2056 | { | 2052 | { |
2053 | |||
2057 | setCaption( i18n("Please input connection settings") ); | 2054 | setCaption( i18n("Please input connection settings") ); |
2058 | QString retfile = ""; | 2055 | QString retfile = ""; |
@@ -2071,6 +2068,13 @@ void MainWindow::performQuick() | |||
2071 | lab2.setText( KOPrefs::instance()->mActiveSyncPort ); | 2068 | lab2.setText( KOPrefs::instance()->mActiveSyncPort ); |
2072 | lay.addWidget( &lab2); | 2069 | lay.addWidget( &lab2); |
2070 | |||
2071 | QLineEdit lepw ( &dia ); | ||
2072 | lepw.setText( mPassWordPiSync ); | ||
2073 | QLabel label3 ( i18n("Password to enable\naccess to remote:"), &dia ); | ||
2074 | lay.addWidget( &label3); | ||
2075 | lay.addWidget( &lepw); | ||
2076 | |||
2073 | dia.setFixedSize( 230,200 ); | 2077 | dia.setFixedSize( 230,200 ); |
2074 | dia.setCaption( i18n("Enter port for Easy-Pi-Sync ") ); | 2078 | dia.setCaption( i18n("Enter port for Pi-Sync ") ); |
2075 | QPushButton pb ( "OK", &dia); | 2079 | QPushButton pb ( "OK", &dia); |
2076 | lay.addWidget( &pb ); | 2080 | lay.addWidget( &pb ); |
@@ -2082,4 +2086,5 @@ void MainWindow::performQuick() | |||
2082 | return; | 2086 | return; |
2083 | } | 2087 | } |
2088 | mPassWordPiSync = lepw.text(); | ||
2084 | dia.hide(); | 2089 | dia.hide(); |
2085 | KOPrefs::instance()->mActiveSyncPort = lab2.text(); | 2090 | KOPrefs::instance()->mActiveSyncPort = lab2.text(); |
@@ -2104,4 +2109,5 @@ void MainWindow::performQuickQuick() | |||
2104 | //mCommandSocket = new QSocket( this ); | 2109 | //mCommandSocket = new QSocket( this ); |
2105 | connect( mCommandSocket, SIGNAL(readyRead()), this, SLOT(readFileFromSocket()) ); | 2110 | connect( mCommandSocket, SIGNAL(readyRead()), this, SLOT(readFileFromSocket()) ); |
2111 | connect( mCommandSocket, SIGNAL(delayedCloseFinished ()), this, SLOT(deleteCommandSocket()) ); | ||
2106 | } | 2112 | } |
2107 | QString host = KOPrefs::instance()->mActiveSyncIP; | 2113 | QString host = KOPrefs::instance()->mActiveSyncIP; |
@@ -2109,12 +2115,35 @@ void MainWindow::performQuickQuick() | |||
2109 | QTextStream os( mCommandSocket ); | 2115 | QTextStream os( mCommandSocket ); |
2110 | os.setEncoding( QTextStream::UnicodeUTF8 ); | 2116 | os.setEncoding( QTextStream::UnicodeUTF8 ); |
2111 | os << "GET\r\n"; | 2117 | os << "GET " << mPassWordPiSync << "\r\n"; |
2112 | setCaption( i18n("Sending request for remote file ...") ); | 2118 | setCaption( i18n("Sending request for remote file ...") ); |
2119 | mTimerCommandSocket->start( 15000 ); | ||
2113 | 2120 | ||
2114 | } | 2121 | } |
2122 | void MainWindow::deleteCommandSocket() | ||
2123 | { | ||
2124 | if ( !mCommandSocket) | ||
2125 | return; | ||
2126 | if ( mTimerCommandSocket->isActive () ) { | ||
2127 | KMessageBox::information( 0, i18n("ERROR:\nConnection to remote host timed out ")); | ||
2128 | mTimerCommandSocket->stop(); | ||
2129 | } | ||
2130 | qDebug("MainWindow::deletemCommandSocket() "); | ||
2131 | delete mCommandSocket; | ||
2132 | mCommandSocket = 0; | ||
2133 | } | ||
2134 | void MainWindow::deleteCommandSocketFinish() | ||
2135 | { | ||
2136 | if ( ! mCommandSocketFinish) | ||
2137 | return; | ||
2138 | //KMessageBox::information( 0, i18n("MainWindow::deleteCommandSocketFinish() ")); | ||
2139 | qDebug("MainWindow::deletemCommandSocketFinish() "); | ||
2140 | delete mCommandSocketFinish; | ||
2141 | mCommandSocketFinish = 0; | ||
2142 | } | ||
2115 | void MainWindow::readFileFromSocket() | 2143 | void MainWindow::readFileFromSocket() |
2116 | { | 2144 | { |
2145 | mTimerCommandSocket->stop(); | ||
2117 | setCaption( i18n("Receiving remote file ...") ); | 2146 | setCaption( i18n("Receiving remote file ...") ); |
2118 | qDebug("MainWindow::readFileFromSocket() "); | 2147 | qDebug("MainWindow::readFileFromSocket() "); |
2119 | QString fileName; | 2148 | QString fileName; |
2120 | #ifdef _WIN32_ | 2149 | #ifdef _WIN32_ |
@@ -2153,4 +2182,6 @@ void MainWindow::readFileFromSocket() | |||
2153 | file.close(); | 2182 | file.close(); |
2154 | mCommandSocket->close(); | 2183 | mCommandSocket->close(); |
2184 | if ( mCommandSocket->state() == QSocket::Idle ) | ||
2185 | deleteCommandSocket(); | ||
2155 | // pending: deleting after signal SIGNAL(delayedCloseFinished()) | 2186 | // pending: deleting after signal SIGNAL(delayedCloseFinished()) |
2156 | //delete mCommandSocket; | 2187 | //delete mCommandSocket; |
@@ -2172,5 +2203,5 @@ void MainWindow::readFileFromSocket() | |||
2172 | KOPrefs::instance()->mWriteBackInFuture = temp->getWriteBackFutureWeeks( ); | 2203 | KOPrefs::instance()->mWriteBackInFuture = temp->getWriteBackFutureWeeks( ); |
2173 | KOPrefs::instance()->mShowSyncSummary = temp->getShowSummaryAfterSync(); | 2204 | KOPrefs::instance()->mShowSyncSummary = temp->getShowSummaryAfterSync(); |
2174 | 2205 | delete temp; | |
2175 | setCaption( i18n("Remote file saved to temp file.") ); | 2206 | setCaption( i18n("Remote file saved to temp file.") ); |
2176 | if ( ! syncWithFile( fileName , true ) ) { | 2207 | if ( ! syncWithFile( fileName , true ) ) { |
@@ -2181,5 +2212,6 @@ void MainWindow::readFileFromSocket() | |||
2181 | 2212 | ||
2182 | if ( !mCommandSocketFinish ) { | 2213 | if ( !mCommandSocketFinish ) { |
2183 | mCommandSocketFinish = new QSocket( this ); | 2214 | mCommandSocketFinish = new QSocket( this ); |
2215 | connect( mCommandSocketFinish, SIGNAL(delayedCloseFinished ()), this, SLOT(deleteCommandSocketFinish()) ); | ||
2184 | } | 2216 | } |
2185 | mCommandSocketFinish->connectToHost( KOPrefs::instance()->mActiveSyncIP, KOPrefs::instance()->mActiveSyncPort.toUInt() ); | 2217 | mCommandSocketFinish->connectToHost( KOPrefs::instance()->mActiveSyncIP, KOPrefs::instance()->mActiveSyncPort.toUInt() ); |
@@ -2201,5 +2233,5 @@ void MainWindow::readFileFromSocket() | |||
2201 | //os.setEncoding( QTextStream::UnicodeUTF8 ); | 2233 | //os.setEncoding( QTextStream::UnicodeUTF8 ); |
2202 | if ( KOPrefs::instance()->mWriteBackFile ) { | 2234 | if ( KOPrefs::instance()->mWriteBackFile ) { |
2203 | os2 << "PUT\r\n"; | 2235 | os2 << "PUT " << mPassWordPiSync << "\r\n";; |
2204 | while ( ! ts2.atEnd() ) { | 2236 | while ( ! ts2.atEnd() ) { |
2205 | os2 << ts2.readLine() << "\n"; | 2237 | os2 << ts2.readLine() << "\n"; |
@@ -2209,10 +2241,9 @@ void MainWindow::readFileFromSocket() | |||
2209 | } | 2241 | } |
2210 | mCommandSocketFinish->close(); | 2242 | mCommandSocketFinish->close(); |
2243 | if ( mCommandSocketFinish->state() == QSocket::Idle ) | ||
2244 | deleteCommandSocketFinish(); | ||
2211 | file.close(); | 2245 | file.close(); |
2212 | // pending: deleting after signal SIGNAL(delayedCloseFinished()) | ||
2213 | //delete ( mCommandSocket); | ||
2214 | //mCommandSocket = 0; | ||
2215 | qDebug("Syncing succesful! "); | 2246 | qDebug("Syncing succesful! "); |
2216 | setCaption( i18n("Easy-Pi-Sync succesful!") ); | 2247 | setCaption( i18n("Pi-Sync succesful!") ); |
2217 | 2248 | ||
2218 | 2249 | ||
@@ -2497,8 +2528,8 @@ void MainWindow::printCal() | |||
2497 | 2528 | ||
2498 | 2529 | ||
2499 | KServerSocket:: KServerSocket ( Q_UINT16 port, int backlog, QObject * parent, const char * name ) : QServerSocket( port, backlog, parent, name ) | 2530 | KServerSocket:: KServerSocket ( QString pw, Q_UINT16 port, int backlog, QObject * parent, const char * name ) : QServerSocket( port, backlog, parent, name ) |
2500 | { | 2531 | { |
2501 | 2532 | mPassWord = pw; | |
2502 | mSocket = 0; | 2533 | mSocket = 0; |
2503 | }; | 2534 | }; |
2504 | 2535 | ||
@@ -2538,8 +2569,18 @@ void KServerSocket::readClient() | |||
2538 | qDebug("KServerSocket socket->canReadLine()"); | 2569 | qDebug("KServerSocket socket->canReadLine()"); |
2539 | if ( tokens[0] == "GET" ) { | 2570 | if ( tokens[0] == "GET" ) { |
2540 | emit sendFile( mSocket ); | 2571 | if ( tokens[1] == mPassWord ) |
2572 | emit sendFile( mSocket ); | ||
2573 | else { | ||
2574 | KMessageBox::information( 0, i18n("ERROR:\nGot send file request\nwith invalid password")); | ||
2575 | qDebug("password %s, invalid password %s ",mPassWord.latin1(), tokens[1].latin1() ); | ||
2576 | } | ||
2541 | } | 2577 | } |
2542 | if ( tokens[0] == "PUT" ) { | 2578 | if ( tokens[0] == "PUT" ) { |
2543 | emit getFile( mSocket ); | 2579 | if ( tokens[1] == mPassWord ) |
2580 | emit getFile( mSocket ); | ||
2581 | else { | ||
2582 | KMessageBox::information( 0, i18n("ERROR:\nGot receive file request\nwith invalid password")); | ||
2583 | qDebug("password %s, invalid password %s ",mPassWord.latin1(), tokens[1].latin1() ); | ||
2584 | } | ||
2544 | } | 2585 | } |
2545 | if ( tokens[0] == "STOP" ) { | 2586 | if ( tokens[0] == "STOP" ) { |
diff --git a/korganizer/mainwindow.h b/korganizer/mainwindow.h index cc656a3..d217578 100644 --- a/korganizer/mainwindow.h +++ b/korganizer/mainwindow.h | |||
@@ -5,4 +5,7 @@ | |||
5 | #include <qtimer.h> | 5 | #include <qtimer.h> |
6 | #include <qdict.h> | 6 | #include <qdict.h> |
7 | #include <qfile.h> | ||
8 | #include <qsocket.h> | ||
9 | #include <qtextstream.h> | ||
7 | #include <qregexp.h> | 10 | #include <qregexp.h> |
8 | 11 | ||
@@ -28,5 +31,5 @@ class KServerSocket : public QServerSocket | |||
28 | 31 | ||
29 | public: | 32 | public: |
30 | KServerSocket ( Q_UINT16 port, int backlog = 0, QObject * parent=0, const char * name=0 ); | 33 | KServerSocket ( QString password, Q_UINT16 port, int backlog = 0, QObject * parent=0, const char * name=0 ); |
31 | 34 | ||
32 | void newConnection ( int socket ) ; | 35 | void newConnection ( int socket ) ; |
@@ -41,4 +44,5 @@ private slots: | |||
41 | private : | 44 | private : |
42 | QSocket* mSocket; | 45 | QSocket* mSocket; |
46 | QString mPassWord; | ||
43 | }; | 47 | }; |
44 | 48 | ||
@@ -115,10 +119,18 @@ class MainWindow : public QMainWindow | |||
115 | 119 | ||
116 | private slots: | 120 | private slots: |
121 | QSocket* piSocket; | ||
122 | QString piFileString; | ||
123 | QTime piTime; | ||
124 | void deleteCommandSocket(); | ||
125 | void deleteCommandSocketFinish(); | ||
117 | void fillSyncMenu(); | 126 | void fillSyncMenu(); |
118 | void sendFile(QSocket* s); | 127 | void sendFile(QSocket* s); |
119 | void getFile(QSocket* socket); | 128 | void getFile(QSocket* socket); |
120 | void readFileFromSocket(); | 129 | void readFileFromSocket(); |
130 | void readBackFileFromSocket(); | ||
121 | void endConnect(); | 131 | void endConnect(); |
122 | private: | 132 | private: |
133 | QTimer* mTimerCommandSocket; | ||
134 | QString mPassWordPiSync; | ||
123 | QSocket* mCommandSocket; | 135 | QSocket* mCommandSocket; |
124 | QSocket* mCommandSocketFinish; | 136 | QSocket* mCommandSocketFinish; |