author | zautrix <zautrix> | 2004-09-23 08:26:01 (UTC) |
---|---|---|
committer | zautrix <zautrix> | 2004-09-23 08:26:01 (UTC) |
commit | a9e235027e0c92fb53462e968dee2b43228d7984 (patch) (unidiff) | |
tree | 91565646ef5eeccd0f51a679add40499586abf8e | |
parent | e395b9a15f5047582c17665de85d28dad64b8a8e (diff) | |
download | kdepimpi-a9e235027e0c92fb53462e968dee2b43228d7984.zip kdepimpi-a9e235027e0c92fb53462e968dee2b43228d7984.tar.gz kdepimpi-a9e235027e0c92fb53462e968dee2b43228d7984.tar.bz2 |
sync fixes
-rw-r--r-- | korganizer/mainwindow.cpp | 52 | ||||
-rw-r--r-- | korganizer/mainwindow.h | 2 |
2 files changed, 37 insertions, 17 deletions
diff --git a/korganizer/mainwindow.cpp b/korganizer/mainwindow.cpp index 460bbdc..f4ac0d6 100644 --- a/korganizer/mainwindow.cpp +++ b/korganizer/mainwindow.cpp | |||
@@ -1997,25 +1997,25 @@ void MainWindow::getFile(QSocket* socket) | |||
1997 | first = false; | 1997 | first = false; |
1998 | while ( socket->canReadLine () ) { | 1998 | while ( socket->canReadLine () ) { |
1999 | qDebug("avail %d ", socket->bytesAvailable () ); | 1999 | qDebug("avail %d ", socket->bytesAvailable () ); |
2000 | ts << socket->readLine (); | 2000 | ts << socket->readLine (); |
2001 | } | 2001 | } |
2002 | QTime ti; | 2002 | QTime ti; |
2003 | ti.start(); | 2003 | ti.start(); |
2004 | while ( ti.elapsed () < 5000 && !socket->canReadLine () ) { | 2004 | while ( ti.elapsed () < 5000 && !socket->canReadLine () ) { |
2005 | qDebug("waiting1a %d %d ",ti.elapsed (), socket->bytesAvailable () ); | 2005 | qDebug("waiting1a %d %d ",ti.elapsed (), socket->bytesAvailable () ); |
2006 | //qApp->processEvents(); | 2006 | //qApp->processEvents(); |
2007 | qDebug("waiting1b %d ",ti.elapsed () ); | 2007 | qDebug("waiting1b %d ",ti.elapsed () ); |
2008 | if ( !socket->canReadLine () ) { | 2008 | if ( !socket->canReadLine () ) { |
2009 | qDebug("waiting1c %d ",ti.elapsed () ); | 2009 | qDebug("waiting1c %d ",ti.elapsed () ); |
2010 | usleep( 100000); | 2010 | usleep( 100000); |
2011 | } | 2011 | } |
2012 | //socket->waitForMore ( 100 ); | 2012 | //socket->waitForMore ( 100 ); |
2013 | } | 2013 | } |
2014 | ts << socket->readLine (); | 2014 | ts << socket->readLine (); |
2015 | #if 0 | 2015 | #if 0 |
2016 | #ifdef DESKTOP_VERSION | 2016 | #ifdef DESKTOP_VERSION |
2017 | socket->waitForMore ( 5000 ); | 2017 | socket->waitForMore ( 5000 ); |
2018 | #else | 2018 | #else |
2019 | // socket->waitForMore ( 5000 ); | 2019 | // socket->waitForMore ( 5000 ); |
2020 | // seems to be broken in qt2 | 2020 | // seems to be broken in qt2 |
2021 | bool stop = false; | 2021 | bool stop = false; |
@@ -2025,26 +2025,26 @@ void MainWindow::getFile(QSocket* socket) | |||
2025 | qApp->processEvents(); | 2025 | qApp->processEvents(); |
2026 | if ( socket->canReadLine () ) | 2026 | if ( socket->canReadLine () ) |
2027 | stop = true ; | 2027 | stop = true ; |
2028 | else { | 2028 | else { |
2029 | usleep( 100000 ); | 2029 | usleep( 100000 ); |
2030 | 2030 | ||
2031 | } | 2031 | } |
2032 | } | 2032 | } |
2033 | #endif | 2033 | #endif |
2034 | #endif | 2034 | #endif |
2035 | } | 2035 | } |
2036 | setCaption( i18n("File received - reloading calendar...") ); | 2036 | setCaption( i18n("File received - reloading calendar...") ); |
2037 | file.close(); | ||
2038 | socket->close(); | 2037 | socket->close(); |
2038 | file.close(); | ||
2039 | mView->watchSavedFile(); | 2039 | mView->watchSavedFile(); |
2040 | mView->openCalendar( defaultFileName() ); | 2040 | mView->openCalendar( defaultFileName() ); |
2041 | setCaption( i18n("Easy-Pi-Sync successful!") ); | 2041 | setCaption( i18n("Easy-Pi-Sync successful!") ); |
2042 | delete mSyncActionDialog; | 2042 | delete mSyncActionDialog; |
2043 | mSyncActionDialog = 0; | 2043 | mSyncActionDialog = 0; |
2044 | 2044 | ||
2045 | 2045 | ||
2046 | } | 2046 | } |
2047 | void MainWindow::endConnect() | 2047 | void MainWindow::endConnect() |
2048 | { | 2048 | { |
2049 | setCaption( i18n("No file received - syncing successful") ); | 2049 | setCaption( i18n("No file received - syncing successful") ); |
2050 | delete mSyncActionDialog; | 2050 | delete mSyncActionDialog; |
@@ -2105,34 +2105,34 @@ void MainWindow::performQuickQuick() | |||
2105 | QString host = KOPrefs::instance()->mActiveSyncIP; | 2105 | QString host = KOPrefs::instance()->mActiveSyncIP; |
2106 | mCommandSocket->connectToHost( host, port ); | 2106 | mCommandSocket->connectToHost( host, port ); |
2107 | QTextStream os( mCommandSocket ); | 2107 | QTextStream os( mCommandSocket ); |
2108 | os.setEncoding( QTextStream::UnicodeUTF8 ); | 2108 | os.setEncoding( QTextStream::UnicodeUTF8 ); |
2109 | os << "GET\r\n"; | 2109 | os << "GET\r\n"; |
2110 | setCaption( i18n("Sending request for remote file ...") ); | 2110 | setCaption( i18n("Sending request for remote file ...") ); |
2111 | 2111 | ||
2112 | } | 2112 | } |
2113 | void MainWindow::readFileFromSocket() | 2113 | void MainWindow::readFileFromSocket() |
2114 | { | 2114 | { |
2115 | setCaption( i18n("Receiving remote file ...") ); | 2115 | setCaption( i18n("Receiving remote file ...") ); |
2116 | qDebug("MainWindow::readFileFromSocket() "); | 2116 | qDebug("MainWindow::readFileFromSocket() "); |
2117 | QString fileName; | 2117 | QString fileName; |
2118 | #ifdef _WIN32_ | 2118 | #ifdef _WIN32_ |
2119 | fileName = defaultFileName() +"sync"; | 2119 | fileName = defaultFileName() +"sync"; |
2120 | #else | 2120 | #else |
2121 | fileName = "/tmp/kopitempfile.ics"; | 2121 | fileName = "/tmp/kopitempfile.ics"; |
2122 | #endif | 2122 | #endif |
2123 | QFile file( fileName ); | 2123 | QFile file( fileName ); |
2124 | if (!file.open( IO_WriteOnly ) ) { | 2124 | if (!file.open( IO_WriteOnly ) ) { |
2125 | setCaption( i18n("Error: Cannot open temp file for write.") ); | 2125 | setCaption( i18n("Error: Cannot open temp file for write.") ); |
2126 | qDebug("Error open calender file for writing: %s",fileName.latin1() ); | 2126 | qDebug("Error open temp calender file for writing: %s",fileName.latin1() ); |
2127 | return ; | 2127 | return ; |
2128 | } | 2128 | } |
2129 | 2129 | ||
2130 | //QTextStream os2( mCommandSocket ); | 2130 | //QTextStream os2( mCommandSocket ); |
2131 | //os2.setEncoding( QTextStream::UnicodeUTF8 ); | 2131 | //os2.setEncoding( QTextStream::UnicodeUTF8 ); |
2132 | 2132 | ||
2133 | QTextStream ts( &file ); | 2133 | QTextStream ts( &file ); |
2134 | ts.setCodec( QTextCodec::codecForName("utf8") ); | 2134 | ts.setCodec( QTextCodec::codecForName("utf8") ); |
2135 | bool first = true; | 2135 | bool first = true; |
2136 | while ( mCommandSocket->canReadLine () || first) { | 2136 | while ( mCommandSocket->canReadLine () || first) { |
2137 | first = false; | 2137 | first = false; |
2138 | while ( mCommandSocket->canReadLine () ) { | 2138 | while ( mCommandSocket->canReadLine () ) { |
@@ -2141,24 +2141,25 @@ QString fileName; | |||
2141 | QTime ti; | 2141 | QTime ti; |
2142 | ti.start(); | 2142 | ti.start(); |
2143 | while ( ti.elapsed () < 5000 && !mCommandSocket->canReadLine () ) { | 2143 | while ( ti.elapsed () < 5000 && !mCommandSocket->canReadLine () ) { |
2144 | qApp->processEvents(); | 2144 | qApp->processEvents(); |
2145 | qDebug("waiting2 %d ",ti.elapsed () ); | 2145 | qDebug("waiting2 %d ",ti.elapsed () ); |
2146 | if ( !mCommandSocket->canReadLine () ) | 2146 | if ( !mCommandSocket->canReadLine () ) |
2147 | mCommandSocket->waitForMore ( 100 ); | 2147 | mCommandSocket->waitForMore ( 100 ); |
2148 | } | 2148 | } |
2149 | //mCommandSocket->waitForMore ( 5000 ); | 2149 | //mCommandSocket->waitForMore ( 5000 ); |
2150 | } | 2150 | } |
2151 | file.close(); | 2151 | file.close(); |
2152 | mCommandSocket->close(); | 2152 | mCommandSocket->close(); |
2153 | // pending: deleting after signal SIGNAL(delayedCloseFinished()) | ||
2153 | //delete mCommandSocket; | 2154 | //delete mCommandSocket; |
2154 | setCaption( i18n("Remote file saved to temp file.") ); | 2155 | setCaption( i18n("Remote file saved to temp file.") ); |
2155 | //mCommandSocket = 0; | 2156 | //mCommandSocket = 0; |
2156 | mCurrentSyncProfile = 2 ; // last file | 2157 | mCurrentSyncProfile = 2 ; // last file |
2157 | mView->setSyncDevice(KOPrefs::instance()->mSyncProfileNames[mCurrentSyncProfile] ); | 2158 | mView->setSyncDevice(KOPrefs::instance()->mSyncProfileNames[mCurrentSyncProfile] ); |
2158 | mView->setSyncName( KOPrefs::instance()->mLocalMachineName ); | 2159 | mView->setSyncName( KOPrefs::instance()->mLocalMachineName ); |
2159 | KConfig config ( locateLocal( "config","ksyncprofilesrc" ) ); | 2160 | KConfig config ( locateLocal( "config","ksyncprofilesrc" ) ); |
2160 | KSyncProfile* temp = new KSyncProfile (); | 2161 | KSyncProfile* temp = new KSyncProfile (); |
2161 | temp->setName(KOPrefs::instance()->mSyncProfileNames[mCurrentSyncProfile]); | 2162 | temp->setName(KOPrefs::instance()->mSyncProfileNames[mCurrentSyncProfile]); |
2162 | temp->readConfig(&config); | 2163 | temp->readConfig(&config); |
2163 | KOPrefs::instance()->mAskForPreferences = temp->getAskForPreferences(); | 2164 | KOPrefs::instance()->mAskForPreferences = temp->getAskForPreferences(); |
2164 | KOPrefs::instance()->mSyncAlgoPrefs = temp->getSyncPrefs(); | 2165 | KOPrefs::instance()->mSyncAlgoPrefs = temp->getSyncPrefs(); |
@@ -2172,48 +2173,50 @@ QString fileName; | |||
2172 | setCaption( i18n("Remote file saved to temp file.") ); | 2173 | setCaption( i18n("Remote file saved to temp file.") ); |
2173 | if ( ! syncWithFile( fileName , true ) ) { | 2174 | if ( ! syncWithFile( fileName , true ) ) { |
2174 | setCaption( i18n("Syncing failed.") ); | 2175 | setCaption( i18n("Syncing failed.") ); |
2175 | qDebug("Syncing failed "); | 2176 | qDebug("Syncing failed "); |
2176 | return; | 2177 | return; |
2177 | } | 2178 | } |
2178 | 2179 | ||
2179 | if ( !mCommandSocketFinish ) { | 2180 | if ( !mCommandSocketFinish ) { |
2180 | mCommandSocketFinish = new QSocket( this ); | 2181 | mCommandSocketFinish = new QSocket( this ); |
2181 | } | 2182 | } |
2182 | mCommandSocketFinish->connectToHost( KOPrefs::instance()->mActiveSyncIP, KOPrefs::instance()->mActiveSyncPort.toUInt() ); | 2183 | mCommandSocketFinish->connectToHost( KOPrefs::instance()->mActiveSyncIP, KOPrefs::instance()->mActiveSyncPort.toUInt() ); |
2183 | 2184 | ||
2185 | // pending connect signals connected () and error to new slots | ||
2184 | QString host = KOPrefs::instance()->mActiveSyncIP; | 2186 | QString host = KOPrefs::instance()->mActiveSyncIP; |
2185 | QFile file2( fileName ); | 2187 | QFile file2( fileName ); |
2186 | if (!file2.open( IO_ReadOnly ) ) { | 2188 | if (!file2.open( IO_ReadOnly ) ) { |
2187 | setCaption( i18n("Error: Cannot open temp file for read.") ); | 2189 | setCaption( i18n("Error: Cannot open temp file for read.") ); |
2188 | qDebug("error open cal file "); | 2190 | qDebug("error open cal file "); |
2189 | return ; | 2191 | return ; |
2190 | 2192 | ||
2191 | } | 2193 | } |
2192 | setCaption( i18n("Sending back synced file...") ); | 2194 | setCaption( i18n("Sending back synced file...") ); |
2193 | QTextStream ts2( &file2 ); | 2195 | QTextStream ts2( &file2 ); |
2194 | ts2.setCodec( QTextCodec::codecForName("utf8") ); | 2196 | ts2.setCodec( QTextCodec::codecForName("utf8") ); |
2195 | QTextStream os2( mCommandSocketFinish ); | 2197 | QTextStream os2( mCommandSocketFinish ); |
2196 | os2.setCodec( QTextCodec::codecForName("utf8") ); | 2198 | os2.setCodec( QTextCodec::codecForName("utf8") ); |
2197 | //os.setEncoding( QTextStream::UnicodeUTF8 ); | 2199 | //os.setEncoding( QTextStream::UnicodeUTF8 ); |
2198 | if ( KOPrefs::instance()->mWriteBackFile ) { | 2200 | if ( KOPrefs::instance()->mWriteBackFile ) { |
2199 | os2 << "PUT\r\n"; | 2201 | os2 << "PUT\r\n"; |
2200 | while ( ! ts2.atEnd() ) { | 2202 | while ( ! ts2.atEnd() ) { |
2201 | os2 << ts2.readLine() << "\n"; | 2203 | os2 << ts2.readLine() << "\n"; |
2202 | } | 2204 | } |
2203 | } else { | 2205 | } else { |
2204 | os2 << "STOP\r\n"; | 2206 | os2 << "STOP\r\n"; |
2205 | } | 2207 | } |
2206 | mCommandSocketFinish->close(); | 2208 | mCommandSocketFinish->close(); |
2207 | file.close(); | 2209 | file.close(); |
2210 | // pending: deleting after signal SIGNAL(delayedCloseFinished()) | ||
2208 | //delete ( mCommandSocket); | 2211 | //delete ( mCommandSocket); |
2209 | //mCommandSocket = 0; | 2212 | //mCommandSocket = 0; |
2210 | qDebug("Syncing succesful! "); | 2213 | qDebug("Syncing succesful! "); |
2211 | setCaption( i18n("Easy-Pi-Sync succesful!") ); | 2214 | setCaption( i18n("Easy-Pi-Sync succesful!") ); |
2212 | 2215 | ||
2213 | 2216 | ||
2214 | } | 2217 | } |
2215 | 2218 | ||
2216 | void MainWindow::syncLocalFile() | 2219 | void MainWindow::syncLocalFile() |
2217 | { | 2220 | { |
2218 | 2221 | ||
2219 | QString fn =KOPrefs::instance()->mLastSyncedLocalFile; | 2222 | QString fn =KOPrefs::instance()->mLastSyncedLocalFile; |
@@ -2482,54 +2485,69 @@ void MainWindow::syncPhone() | |||
2482 | void MainWindow::printSel( ) | 2485 | void MainWindow::printSel( ) |
2483 | { | 2486 | { |
2484 | mView->viewManager()->agendaView()->agenda()->printSelection(); | 2487 | mView->viewManager()->agendaView()->agenda()->printSelection(); |
2485 | } | 2488 | } |
2486 | 2489 | ||
2487 | void MainWindow::printCal() | 2490 | void MainWindow::printCal() |
2488 | { | 2491 | { |
2489 | mView->print();//mCp->showDialog(); | 2492 | mView->print();//mCp->showDialog(); |
2490 | } | 2493 | } |
2491 | 2494 | ||
2492 | 2495 | ||
2493 | 2496 | ||
2494 | KServerSocket:: KServerSocket ( Q_UINT16 port, int backlog, QObject * parent, const char * name ) : QServerSocket( port, backlog, parent, name ){;}; | 2497 | KServerSocket:: KServerSocket ( Q_UINT16 port, int backlog, QObject * parent, const char * name ) : QServerSocket( port, backlog, parent, name ) |
2498 | { | ||
2499 | |||
2500 | mSocket = 0; | ||
2501 | }; | ||
2495 | 2502 | ||
2496 | void KServerSocket::newConnection ( int socket ) | 2503 | void KServerSocket::newConnection ( int socket ) |
2497 | { | 2504 | { |
2498 | qDebug("KServerSocket:New connection %d ", socket); | 2505 | qDebug("KServerSocket:New connection %d ", socket); |
2499 | QSocket* s = new QSocket( this ); | 2506 | if ( mSocket ) { |
2500 | connect( s, SIGNAL(readyRead()), this, SLOT(readClient()) ); | 2507 | qDebug("KServerSocket::newConnection Socket deleted! "); |
2501 | connect( s, SIGNAL(delayedCloseFinished()), this, SLOT(discardClient()) ); | 2508 | delete mSocket; |
2502 | s->setSocket( socket ); | 2509 | mSocket = 0; |
2510 | } | ||
2511 | mSocket = new QSocket( this ); | ||
2512 | connect( mSocket , SIGNAL(readyRead()), this, SLOT(readClient()) ); | ||
2513 | connect( mSocket , SIGNAL(delayedCloseFinished()), this, SLOT(discardClient()) ); | ||
2514 | mSocket->setSocket( socket ); | ||
2503 | } | 2515 | } |
2504 | 2516 | ||
2505 | void KServerSocket::discardClient() | 2517 | void KServerSocket::discardClient() |
2506 | { | 2518 | { |
2507 | qDebug(" KServerSocket::discardClient()"); | 2519 | qDebug(" KServerSocket::discardClient()"); |
2508 | QSocket* socket = (QSocket*)sender(); | 2520 | if ( mSocket ) { |
2509 | delete socket; | 2521 | qDebug("delete "); |
2522 | delete mSocket; | ||
2523 | mSocket = 0; | ||
2524 | } | ||
2510 | //emit endConnect(); | 2525 | //emit endConnect(); |
2511 | } | 2526 | } |
2512 | void KServerSocket::readClient() | 2527 | void KServerSocket::readClient() |
2513 | { | 2528 | { |
2529 | if ( mSocket == 0 ) { | ||
2530 | qDebug("ERROR::KServerSocket::readClient(): mSocket == 0 "); | ||
2531 | return; | ||
2532 | } | ||
2514 | qDebug("KServerSocket readClient()"); | 2533 | qDebug("KServerSocket readClient()"); |
2515 | QSocket* socket = (QSocket*)sender(); | 2534 | if ( mSocket->canReadLine() ) { |
2516 | if ( socket->canReadLine() ) { | 2535 | QStringList tokens = QStringList::split( QRegExp("[ \r\n][ \r\n]*"), mSocket->readLine() ); |
2517 | QStringList tokens = QStringList::split( QRegExp("[ \r\n][ \r\n]*"), socket->readLine() ); | ||
2518 | qDebug("KServerSocket socket->canReadLine()"); | 2536 | qDebug("KServerSocket socket->canReadLine()"); |
2519 | if ( tokens[0] == "GET" ) { | 2537 | if ( tokens[0] == "GET" ) { |
2520 | emit sendFile( socket ); | 2538 | emit sendFile( mSocket ); |
2521 | } | 2539 | } |
2522 | if ( tokens[0] == "PUT" ) { | 2540 | if ( tokens[0] == "PUT" ) { |
2523 | emit getFile( socket ); | 2541 | emit getFile( mSocket ); |
2524 | } | 2542 | } |
2525 | if ( tokens[0] == "STOP" ) { | 2543 | if ( tokens[0] == "STOP" ) { |
2526 | emit endConnect(); | 2544 | emit endConnect(); |
2527 | } | 2545 | } |
2528 | } | 2546 | } |
2529 | } | 2547 | } |
2530 | 2548 | ||
2531 | 2549 | ||
2532 | 2550 | ||
2533 | 2551 | ||
2534 | 2552 | ||
2535 | 2553 | ||
diff --git a/korganizer/mainwindow.h b/korganizer/mainwindow.h index 7b4fd27..cc656a3 100644 --- a/korganizer/mainwindow.h +++ b/korganizer/mainwindow.h | |||
@@ -29,24 +29,26 @@ class KServerSocket : public QServerSocket | |||
29 | public: | 29 | public: |
30 | KServerSocket ( Q_UINT16 port, int backlog = 0, QObject * parent=0, const char * name=0 ); | 30 | KServerSocket ( Q_UINT16 port, int backlog = 0, QObject * parent=0, const char * name=0 ); |
31 | 31 | ||
32 | void newConnection ( int socket ) ; | 32 | void newConnection ( int socket ) ; |
33 | 33 | ||
34 | signals: | 34 | signals: |
35 | void sendFile(QSocket*); | 35 | void sendFile(QSocket*); |
36 | void getFile(QSocket*); | 36 | void getFile(QSocket*); |
37 | void endConnect(); | 37 | void endConnect(); |
38 | private slots: | 38 | private slots: |
39 | void discardClient(); | 39 | void discardClient(); |
40 | void readClient(); | 40 | void readClient(); |
41 | private : | ||
42 | QSocket* mSocket; | ||
41 | }; | 43 | }; |
42 | 44 | ||
43 | 45 | ||
44 | namespace KCal { | 46 | namespace KCal { |
45 | class CalendarLocal; | 47 | class CalendarLocal; |
46 | } | 48 | } |
47 | 49 | ||
48 | using namespace KCal; | 50 | using namespace KCal; |
49 | 51 | ||
50 | class MainWindow : public QMainWindow | 52 | class MainWindow : public QMainWindow |
51 | { | 53 | { |
52 | Q_OBJECT | 54 | Q_OBJECT |