summaryrefslogtreecommitdiffabout
authorzautrix <zautrix>2004-10-04 10:38:45 (UTC)
committer zautrix <zautrix>2004-10-04 10:38:45 (UTC)
commit01b5806c61deb8368f8f454fdec1c4767c73a840 (patch) (unidiff)
treef2546296a50444d02d2a74f6bf55fd57b0504ebc
parent743f44c45534a6e1df17ddc7b5f3c62b73921455 (diff)
downloadkdepimpi-01b5806c61deb8368f8f454fdec1c4767c73a840.zip
kdepimpi-01b5806c61deb8368f8f454fdec1c4767c73a840.tar.gz
kdepimpi-01b5806c61deb8368f8f454fdec1c4767c73a840.tar.bz2
sync fixes
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--korganizer/mainwindow.cpp12
1 files changed, 7 insertions, 5 deletions
diff --git a/korganizer/mainwindow.cpp b/korganizer/mainwindow.cpp
index 8e2f956..10cb2a2 100644
--- a/korganizer/mainwindow.cpp
+++ b/korganizer/mainwindow.cpp
@@ -2095,104 +2095,105 @@ void MainWindow::performQuick()
2095 2095
2096void MainWindow::performQuickQuick() 2096void MainWindow::performQuickQuick()
2097{ 2097{
2098 // setCaption( i18n("") ); 2098 // setCaption( i18n("") );
2099 2099
2100 bool ok; 2100 bool ok;
2101 Q_UINT16 port = KOPrefs::instance()->mActiveSyncPort.toUInt(&ok); 2101 Q_UINT16 port = KOPrefs::instance()->mActiveSyncPort.toUInt(&ok);
2102 if ( ! ok ) { 2102 if ( ! ok ) {
2103 setCaption( i18n("Sorry, no valid port.Syncing cancelled.") ); 2103 setCaption( i18n("Sorry, no valid port.Syncing cancelled.") );
2104 return; 2104 return;
2105 } 2105 }
2106 if ( !mCommandSocket ) { 2106 if ( !mCommandSocket ) {
2107 mCommandSocket = new QSocket( this ); 2107 mCommandSocket = new QSocket( this );
2108 // delete mCommandSocket; 2108 // delete mCommandSocket;
2109 //mCommandSocket = new QSocket( this ); 2109 //mCommandSocket = new QSocket( this );
2110 connect( mCommandSocket, SIGNAL(readyRead()), this, SLOT(readFileFromSocket()) ); 2110 connect( mCommandSocket, SIGNAL(readyRead()), this, SLOT(readFileFromSocket()) );
2111 connect( mCommandSocket, SIGNAL(delayedCloseFinished ()), this, SLOT(deleteCommandSocket()) ); 2111 connect( mCommandSocket, SIGNAL(delayedCloseFinished ()), this, SLOT(deleteCommandSocket()) );
2112 } 2112 }
2113 QString host = KOPrefs::instance()->mActiveSyncIP; 2113 QString host = KOPrefs::instance()->mActiveSyncIP;
2114 mCommandSocket->connectToHost( host, port ); 2114 mCommandSocket->connectToHost( host, port );
2115 QTextStream os( mCommandSocket ); 2115 QTextStream os( mCommandSocket );
2116 os.setEncoding( QTextStream::UnicodeUTF8 ); 2116 os.setEncoding( QTextStream::UnicodeUTF8 );
2117 os << "GET " << mPassWordPiSync << "\r\n"; 2117 os << "GET " << mPassWordPiSync << "\r\n";
2118 setCaption( i18n("Sending request for remote file ...") ); 2118 setCaption( i18n("Sending request for remote file ...") );
2119 mTimerCommandSocket->start( 15000 ); 2119 mTimerCommandSocket->start( 10000 );
2120 2120
2121} 2121}
2122void MainWindow::deleteCommandSocket() 2122void MainWindow::deleteCommandSocket()
2123{ 2123{
2124 if ( !mCommandSocket) 2124 if ( !mCommandSocket)
2125 return; 2125 return;
2126 if ( mTimerCommandSocket->isActive () ) { 2126 if ( mTimerCommandSocket->isActive () ) {
2127 KMessageBox::information( 0, i18n("ERROR:\nConnection to remote host timed out ")); 2127 KMessageBox::information( 0, i18n("ERROR:\nConnection to remote host timed out "));
2128 mTimerCommandSocket->stop(); 2128 mTimerCommandSocket->stop();
2129 } 2129 }
2130 //KMessageBox::information( 0, i18n("MainWindow::deleteCommandSocket "));
2130 qDebug("MainWindow::deletemCommandSocket() "); 2131 qDebug("MainWindow::deletemCommandSocket() ");
2131 delete mCommandSocket; 2132 delete mCommandSocket;
2132 mCommandSocket = 0; 2133 mCommandSocket = 0;
2133} 2134}
2134void MainWindow::deleteCommandSocketFinish() 2135void MainWindow::deleteCommandSocketFinish()
2135{ 2136{
2136 if ( ! mCommandSocketFinish) 2137 if ( ! mCommandSocketFinish)
2137 return; 2138 return;
2138 //KMessageBox::information( 0, i18n("MainWindow::deleteCommandSocketFinish() ")); 2139 // KMessageBox::information( 0, i18n("MainWindow::deleteCommandSocketFinish() "));
2139 qDebug("MainWindow::deletemCommandSocketFinish() "); 2140 qDebug("MainWindow::deletemCommandSocketFinish() ");
2140 delete mCommandSocketFinish; 2141 delete mCommandSocketFinish;
2141 mCommandSocketFinish = 0; 2142 mCommandSocketFinish = 0;
2142} 2143}
2143void MainWindow::readFileFromSocket() 2144void MainWindow::readFileFromSocket()
2144{ 2145{
2145 mTimerCommandSocket->stop(); 2146 mTimerCommandSocket->stop();
2146 setCaption( i18n("Receiving remote file ...") ); 2147 setCaption( i18n("Receiving remote file ...") );
2147 qDebug("MainWindow::readFileFromSocket() "); 2148 qDebug("MainWindow::readFileFromSocket() ");
2148 QString fileName; 2149 QString fileName;
2149#ifdef _WIN32_ 2150#ifdef _WIN32_
2150 fileName = defaultFileName() +"sync"; 2151 fileName = defaultFileName() +"sync";
2151#else 2152#else
2152 fileName = "/tmp/kopitempfile.ics"; 2153 fileName = "/tmp/kopitempfile.ics";
2153#endif 2154#endif
2154 QFile file( fileName ); 2155 QFile file( fileName );
2155 if (!file.open( IO_WriteOnly ) ) { 2156 if (!file.open( IO_WriteOnly ) ) {
2156 setCaption( i18n("Error: Cannot open temp file for write.") ); 2157 setCaption( i18n("Error: Cannot open temp file for write.") );
2157 qDebug("Error open temp calender file for writing: %s",fileName.latin1() ); 2158 qDebug("Error open temp calender file for writing: %s",fileName.latin1() );
2158 return ; 2159 return ;
2159 } 2160 }
2160 2161
2161 //QTextStream os2( mCommandSocket ); 2162 //QTextStream os2( mCommandSocket );
2162 //os2.setEncoding( QTextStream::UnicodeUTF8 ); 2163 //os2.setEncoding( QTextStream::UnicodeUTF8 );
2163 2164
2164 QTextStream ts( &file ); 2165 QTextStream ts( &file );
2165 ts.setCodec( QTextCodec::codecForName("utf8") ); 2166 ts.setCodec( QTextCodec::codecForName("utf8") );
2166 bool first = true; 2167 bool first = true;
2167 while ( mCommandSocket->canReadLine () || first) { 2168 while ( mCommandSocket->canReadLine () || first) {
2168 first = false; 2169 first = false;
2169 while ( mCommandSocket->canReadLine () ) { 2170 while ( mCommandSocket->canReadLine () ) {
2170 ts << mCommandSocket->readLine (); 2171 ts << mCommandSocket->readLine ();
2171 } 2172 }
2172 QTime ti; 2173 QTime ti;
2173 ti.start(); 2174 ti.start();
2174 while ( ti.elapsed () < 5000 && !mCommandSocket->canReadLine () ) { 2175 while ( ti.elapsed () < 3000 && !mCommandSocket->canReadLine () ) {
2175 qApp->processEvents(); 2176 qApp->processEvents();
2176 qDebug("waiting2 %d ",ti.elapsed () ); 2177 qDebug("waiting2 %d ",ti.elapsed () );
2177 if ( !mCommandSocket->canReadLine () ) 2178 if ( !mCommandSocket->canReadLine () )
2178 mCommandSocket->waitForMore ( 100 ); 2179 mCommandSocket->waitForMore ( 100 );
2179 } 2180 }
2180 //mCommandSocket->waitForMore ( 5000 ); 2181 //mCommandSocket->waitForMore ( 5000 );
2181 } 2182 }
2182 file.close(); 2183 file.close();
2183 mCommandSocket->close(); 2184 mCommandSocket->close();
2184 if ( mCommandSocket->state() == QSocket::Idle ) 2185 if ( mCommandSocket->state() == QSocket::Idle )
2185 deleteCommandSocket(); 2186 deleteCommandSocket();
2186 // pending: deleting after signal SIGNAL(delayedCloseFinished()) 2187 // pending: deleting after signal SIGNAL(delayedCloseFinished())
2187 //delete mCommandSocket; 2188 //delete mCommandSocket;
2188 setCaption( i18n("Remote file saved to temp file.") ); 2189 setCaption( i18n("Remote file saved to temp file.") );
2189 //mCommandSocket = 0; 2190 //mCommandSocket = 0;
2190 mCurrentSyncProfile = 2 ; // last file 2191 mCurrentSyncProfile = 2 ; // last file
2191 mView->setSyncDevice(KOPrefs::instance()->mSyncProfileNames[mCurrentSyncProfile] ); 2192 mView->setSyncDevice(KOPrefs::instance()->mSyncProfileNames[mCurrentSyncProfile] );
2192 mView->setSyncName( KOPrefs::instance()->mLocalMachineName ); 2193 mView->setSyncName( KOPrefs::instance()->mLocalMachineName );
2193 KConfig config ( locateLocal( "config","ksyncprofilesrc" ) ); 2194 KConfig config ( locateLocal( "config","ksyncprofilesrc" ) );
2194 KSyncProfile* temp = new KSyncProfile (); 2195 KSyncProfile* temp = new KSyncProfile ();
2195 temp->setName(KOPrefs::instance()->mSyncProfileNames[mCurrentSyncProfile]); 2196 temp->setName(KOPrefs::instance()->mSyncProfileNames[mCurrentSyncProfile]);
2196 temp->readConfig(&config); 2197 temp->readConfig(&config);
2197 KOPrefs::instance()->mAskForPreferences = temp->getAskForPreferences(); 2198 KOPrefs::instance()->mAskForPreferences = temp->getAskForPreferences();
2198 KOPrefs::instance()->mSyncAlgoPrefs = temp->getSyncPrefs(); 2199 KOPrefs::instance()->mSyncAlgoPrefs = temp->getSyncPrefs();
@@ -2204,69 +2205,70 @@ void MainWindow::readFileFromSocket()
2204 KOPrefs::instance()->mShowSyncSummary = temp->getShowSummaryAfterSync(); 2205 KOPrefs::instance()->mShowSyncSummary = temp->getShowSummaryAfterSync();
2205 delete temp; 2206 delete temp;
2206 setCaption( i18n("Remote file saved to temp file.") ); 2207 setCaption( i18n("Remote file saved to temp file.") );
2207 if ( ! syncWithFile( fileName , true ) ) { 2208 if ( ! syncWithFile( fileName , true ) ) {
2208 setCaption( i18n("Syncing failed.") ); 2209 setCaption( i18n("Syncing failed.") );
2209 qDebug("Syncing failed "); 2210 qDebug("Syncing failed ");
2210 return; 2211 return;
2211 } 2212 }
2212 2213
2213 if ( !mCommandSocketFinish ) { 2214 if ( !mCommandSocketFinish ) {
2214 mCommandSocketFinish = new QSocket( this ); 2215 mCommandSocketFinish = new QSocket( this );
2215 connect( mCommandSocketFinish, SIGNAL(delayedCloseFinished ()), this, SLOT(deleteCommandSocketFinish()) ); 2216 connect( mCommandSocketFinish, SIGNAL(delayedCloseFinished ()), this, SLOT(deleteCommandSocketFinish()) );
2216 } 2217 }
2217 mCommandSocketFinish->connectToHost( KOPrefs::instance()->mActiveSyncIP, KOPrefs::instance()->mActiveSyncPort.toUInt() ); 2218 mCommandSocketFinish->connectToHost( KOPrefs::instance()->mActiveSyncIP, KOPrefs::instance()->mActiveSyncPort.toUInt() );
2218 2219
2219 // pending connect signals connected () and error to new slots 2220 // pending connect signals connected () and error to new slots
2220 QString host = KOPrefs::instance()->mActiveSyncIP; 2221 QString host = KOPrefs::instance()->mActiveSyncIP;
2221 QFile file2( fileName ); 2222 QFile file2( fileName );
2222 if (!file2.open( IO_ReadOnly ) ) { 2223 if (!file2.open( IO_ReadOnly ) ) {
2223 setCaption( i18n("Error: Cannot open temp file for read.") ); 2224 setCaption( i18n("Error: Cannot open temp file for read.") );
2224 qDebug("error open cal file "); 2225 qDebug("error open cal file ");
2225 return ; 2226 return ;
2226 2227
2227 } 2228 }
2228 setCaption( i18n("Sending back synced file...") );
2229 QTextStream ts2( &file2 ); 2229 QTextStream ts2( &file2 );
2230 ts2.setCodec( QTextCodec::codecForName("utf8") ); 2230 ts2.setCodec( QTextCodec::codecForName("utf8") );
2231 QTextStream os2( mCommandSocketFinish ); 2231 QTextStream os2( mCommandSocketFinish );
2232 os2.setCodec( QTextCodec::codecForName("utf8") ); 2232 os2.setCodec( QTextCodec::codecForName("utf8") );
2233 //os.setEncoding( QTextStream::UnicodeUTF8 ); 2233 //os.setEncoding( QTextStream::UnicodeUTF8 );
2234 if ( KOPrefs::instance()->mWriteBackFile ) { 2234 if ( KOPrefs::instance()->mWriteBackFile ) {
2235 setCaption( i18n("Sending back synced file...") );
2235 os2 << "PUT " << mPassWordPiSync << "\r\n";; 2236 os2 << "PUT " << mPassWordPiSync << "\r\n";;
2236 while ( ! ts2.atEnd() ) { 2237 while ( ! ts2.atEnd() ) {
2237 os2 << ts2.readLine() << "\n"; 2238 os2 << ts2.readLine() << "\n";
2238 } 2239 }
2239 } else { 2240 } else {
2240 os2 << "STOP\r\n"; 2241 os2 << "STOP\r\n";
2241 } 2242 }
2242 mCommandSocketFinish->close(); 2243 mCommandSocketFinish->close();
2243 if ( mCommandSocketFinish->state() == QSocket::Idle ) 2244 if ( mCommandSocketFinish->state() == QSocket::Idle )
2244 deleteCommandSocketFinish(); 2245 QTimer::singleShot( 10, this , SLOT ( deleteCommandSocketFinish()));
2245 file.close(); 2246 file.close();
2246 qDebug("Syncing succesful! "); 2247 qDebug("Syncing succesful! ");
2247 setCaption( i18n("Pi-Sync succesful!") ); 2248 setCaption( i18n("Pi-Sync succesful!") );
2248 2249
2250 // KMessageBox::information( 0, i18n(" Pi-Sync succesful! "));
2249 2251
2250} 2252}
2251 2253
2252void MainWindow::syncLocalFile() 2254void MainWindow::syncLocalFile()
2253{ 2255{
2254 2256
2255 QString fn =KOPrefs::instance()->mLastSyncedLocalFile; 2257 QString fn =KOPrefs::instance()->mLastSyncedLocalFile;
2256 2258
2257 fn =KFileDialog:: getOpenFileName( fn, i18n("Sync filename(*.ics/*.vcs)"), this ); 2259 fn =KFileDialog:: getOpenFileName( fn, i18n("Sync filename(*.ics/*.vcs)"), this );
2258 if ( fn == "" ) 2260 if ( fn == "" )
2259 return; 2261 return;
2260 //mView->setSyncDevice("local-file" ); 2262 //mView->setSyncDevice("local-file" );
2261 if ( syncWithFile( fn, false ) ) { 2263 if ( syncWithFile( fn, false ) ) {
2262 // Event* e = mView->getLastSyncEvent(); 2264 // Event* e = mView->getLastSyncEvent();
2263// e->setReadOnly( false ); 2265// e->setReadOnly( false );
2264// e->setLocation( i18n("Local file: ")+ KOPrefs::instance()->mLastSyncedLocalFile); 2266// e->setLocation( i18n("Local file: ")+ KOPrefs::instance()->mLastSyncedLocalFile);
2265// e->setReadOnly( true ); 2267// e->setReadOnly( true );
2266 } 2268 }
2267 2269
2268} 2270}
2269 2271
2270bool MainWindow::syncWithFile( QString fn , bool quick ) 2272bool MainWindow::syncWithFile( QString fn , bool quick )
2271{ 2273{
2272 bool ret = false; 2274 bool ret = false;