-rw-r--r-- | libkdepim/ksyncmanager.cpp | 2 |
1 files changed, 1 insertions, 1 deletions
diff --git a/libkdepim/ksyncmanager.cpp b/libkdepim/ksyncmanager.cpp index 7c53948..6f68d84 100644 --- a/libkdepim/ksyncmanager.cpp +++ b/libkdepim/ksyncmanager.cpp | |||
@@ -1155,318 +1155,318 @@ void KServerSocket::readClient() | |||
1155 | KMessageBox::error( 0, i18n("Got send file request\nwith invalid password")); | 1155 | KMessageBox::error( 0, i18n("Got send file request\nwith invalid password")); |
1156 | //qDebug("password %s, invalid password %s ",mPassWord.latin1(), tokens[1].latin1() ); | 1156 | //qDebug("password %s, invalid password %s ",mPassWord.latin1(), tokens[1].latin1() ); |
1157 | } | 1157 | } |
1158 | } | 1158 | } |
1159 | if ( tokens[0] == "PUT" ) { | 1159 | if ( tokens[0] == "PUT" ) { |
1160 | if ( tokens[1] == mPassWord ) { | 1160 | if ( tokens[1] == mPassWord ) { |
1161 | //emit getFile( mSocket ); | 1161 | //emit getFile( mSocket ); |
1162 | blockRC = true; | 1162 | blockRC = true; |
1163 | get_file(); | 1163 | get_file(); |
1164 | } | 1164 | } |
1165 | else { | 1165 | else { |
1166 | KMessageBox::error( 0, i18n("Got receive file request\nwith invalid password")); | 1166 | KMessageBox::error( 0, i18n("Got receive file request\nwith invalid password")); |
1167 | //qDebug("password %s, invalid password %s ",mPassWord.latin1(), tokens[1].latin1() ); | 1167 | //qDebug("password %s, invalid password %s ",mPassWord.latin1(), tokens[1].latin1() ); |
1168 | } | 1168 | } |
1169 | } | 1169 | } |
1170 | if ( tokens[0] == "STOP" ) { | 1170 | if ( tokens[0] == "STOP" ) { |
1171 | //emit endConnect(); | 1171 | //emit endConnect(); |
1172 | end_connect(); | 1172 | end_connect(); |
1173 | } | 1173 | } |
1174 | } | 1174 | } |
1175 | } | 1175 | } |
1176 | void KServerSocket::end_connect() | 1176 | void KServerSocket::end_connect() |
1177 | { | 1177 | { |
1178 | delete mSyncActionDialog; | 1178 | delete mSyncActionDialog; |
1179 | mSyncActionDialog = 0; | 1179 | mSyncActionDialog = 0; |
1180 | } | 1180 | } |
1181 | void KServerSocket::send_file() | 1181 | void KServerSocket::send_file() |
1182 | { | 1182 | { |
1183 | //qDebug("MainWindow::sendFile(QSocket* s) "); | 1183 | //qDebug("MainWindow::sendFile(QSocket* s) "); |
1184 | if ( mSyncActionDialog ) | 1184 | if ( mSyncActionDialog ) |
1185 | delete mSyncActionDialog; | 1185 | delete mSyncActionDialog; |
1186 | mSyncActionDialog = new QDialog ( 0, "input-dialog", true ); | 1186 | mSyncActionDialog = new QDialog ( 0, "input-dialog", true ); |
1187 | mSyncActionDialog->setCaption(i18n("Received sync request")); | 1187 | mSyncActionDialog->setCaption(i18n("Received sync request")); |
1188 | QLabel* label = new QLabel( i18n("Synchronizing from remote ...\n\nDo not use this application!\n\nIf syncing fails\nyou can close this dialog."), mSyncActionDialog ); | 1188 | QLabel* label = new QLabel( i18n("Synchronizing from remote ...\n\nDo not use this application!\n\nIf syncing fails\nyou can close this dialog."), mSyncActionDialog ); |
1189 | label->setAlignment ( Qt::AlignHCenter ); | 1189 | label->setAlignment ( Qt::AlignHCenter ); |
1190 | QVBoxLayout* lay = new QVBoxLayout( mSyncActionDialog ); | 1190 | QVBoxLayout* lay = new QVBoxLayout( mSyncActionDialog ); |
1191 | lay->addWidget( label); | 1191 | lay->addWidget( label); |
1192 | lay->setMargin(7); | 1192 | lay->setMargin(7); |
1193 | lay->setSpacing(7); | 1193 | lay->setSpacing(7); |
1194 | if ( KSyncManager::mRequestedSyncEvent.isValid() ) { | 1194 | if ( KSyncManager::mRequestedSyncEvent.isValid() ) { |
1195 | int secs = QDateTime::currentDateTime().secsTo( KSyncManager::mRequestedSyncEvent ); | 1195 | int secs = QDateTime::currentDateTime().secsTo( KSyncManager::mRequestedSyncEvent ); |
1196 | if ( secs < 0 ) | 1196 | if ( secs < 0 ) |
1197 | secs = secs * (-1); | 1197 | secs = secs * (-1); |
1198 | if ( secs > 30 ) | 1198 | if ( secs > 30 ) |
1199 | //if ( true ) | 1199 | //if ( true ) |
1200 | { | 1200 | { |
1201 | QString warning = i18n("Clock skew of\nsyncing devices\nis %1 seconds!").arg( secs ); | 1201 | QString warning = i18n("Clock skew of\nsyncing devices\nis %1 seconds!").arg( secs ); |
1202 | QLabel* label = new QLabel( warning, mSyncActionDialog ); | 1202 | QLabel* label = new QLabel( warning, mSyncActionDialog ); |
1203 | label->setAlignment ( Qt::AlignHCenter ); | 1203 | label->setAlignment ( Qt::AlignHCenter ); |
1204 | lay->addWidget( label); | 1204 | lay->addWidget( label); |
1205 | if ( secs > 180 ) | 1205 | if ( secs > 180 ) |
1206 | { | 1206 | { |
1207 | if ( secs > 300 ) { | 1207 | if ( secs > 300 ) { |
1208 | if ( KMessageBox::Cancel == KMessageBox::warningContinueCancel(0, i18n("The clocks of the syncing\ndevices have a difference\n of more than 5 minutes.\nPlease adjust your clocks.\n<b>You may get wrong syncing results!<\b>\nPlease confirm synchronization!"), i18n("High clock skew!"),i18n("Synchronize!"))) { | 1208 | if ( KMessageBox::Cancel == KMessageBox::warningContinueCancel(0, i18n("The clocks of the syncing\ndevices have a difference\n of more than 5 minutes.\nPlease adjust your clocks.\n<b>You may get wrong syncing results!<\b>\nPlease confirm synchronization!"), i18n("High clock skew!"),i18n("Synchronize!"))) { |
1209 | qDebug("cancelled "); | 1209 | qDebug("cancelled "); |
1210 | return ; | 1210 | return ; |
1211 | } | 1211 | } |
1212 | } | 1212 | } |
1213 | QFont f = label->font(); | 1213 | QFont f = label->font(); |
1214 | f.setPointSize ( f.pointSize() *2 ); | 1214 | f.setPointSize ( f.pointSize() *2 ); |
1215 | f. setBold (true ); | 1215 | f. setBold (true ); |
1216 | QLabel* label = new QLabel( warning, mSyncActionDialog ); | 1216 | QLabel* label = new QLabel( warning, mSyncActionDialog ); |
1217 | label->setFont( f ); | 1217 | label->setFont( f ); |
1218 | warning = i18n("ADJUST\nYOUR\nCLOCKS!"); | 1218 | warning = i18n("ADJUST\nYOUR\nCLOCKS!"); |
1219 | label->setText( warning ); | 1219 | label->setText( warning ); |
1220 | label->setAlignment ( Qt::AlignHCenter ); | 1220 | label->setAlignment ( Qt::AlignHCenter ); |
1221 | lay->addWidget( label); | 1221 | lay->addWidget( label); |
1222 | mSyncActionDialog->setFixedSize( 230, 300); | 1222 | mSyncActionDialog->setFixedSize( 230, 300); |
1223 | } else { | 1223 | } else { |
1224 | mSyncActionDialog->setFixedSize( 230, 200); | 1224 | mSyncActionDialog->setFixedSize( 230, 200); |
1225 | } | 1225 | } |
1226 | } else { | 1226 | } else { |
1227 | mSyncActionDialog->setFixedSize( 230, 120); | 1227 | mSyncActionDialog->setFixedSize( 230, 120); |
1228 | } | 1228 | } |
1229 | } else | 1229 | } else |
1230 | mSyncActionDialog->setFixedSize( 230, 120); | 1230 | mSyncActionDialog->setFixedSize( 230, 120); |
1231 | mSyncActionDialog->show(); | 1231 | mSyncActionDialog->show(); |
1232 | mSyncActionDialog->raise(); | 1232 | mSyncActionDialog->raise(); |
1233 | emit request_file(); | 1233 | emit request_file(); |
1234 | qApp->processEvents(); | 1234 | qApp->processEvents(); |
1235 | QString fileName = mFileName; | 1235 | QString fileName = mFileName; |
1236 | QFile file( fileName ); | 1236 | QFile file( fileName ); |
1237 | if (!file.open( IO_ReadOnly ) ) { | 1237 | if (!file.open( IO_ReadOnly ) ) { |
1238 | delete mSyncActionDialog; | 1238 | delete mSyncActionDialog; |
1239 | mSyncActionDialog = 0; | 1239 | mSyncActionDialog = 0; |
1240 | qDebug("KSS::error open sync file: %s ", fileName.latin1()); | 1240 | qDebug("KSS::error open sync file: %s ", fileName.latin1()); |
1241 | mSocket->close(); | 1241 | mSocket->close(); |
1242 | if ( mSocket->state() == QSocket::Idle ) | 1242 | if ( mSocket->state() == QSocket::Idle ) |
1243 | QTimer::singleShot( 10, this , SLOT ( discardClient())); | 1243 | QTimer::singleShot( 10, this , SLOT ( discardClient())); |
1244 | return ; | 1244 | return ; |
1245 | 1245 | ||
1246 | } | 1246 | } |
1247 | mSyncActionDialog->setCaption( i18n("Sending file...") ); | 1247 | mSyncActionDialog->setCaption( i18n("Sending file...") ); |
1248 | QTextStream ts( &file ); | 1248 | QTextStream ts( &file ); |
1249 | ts.setEncoding( QTextStream::Latin1 ); | 1249 | ts.setEncoding( QTextStream::Latin1 ); |
1250 | 1250 | ||
1251 | QTextStream os( mSocket ); | 1251 | QTextStream os( mSocket ); |
1252 | os.setEncoding( QTextStream::Latin1 ); | 1252 | os.setEncoding( QTextStream::Latin1 ); |
1253 | while ( ! ts.atEnd() ) { | 1253 | while ( ! ts.atEnd() ) { |
1254 | os << ts.readLine() << "\r\n"; | 1254 | os << ts.readLine() << "\r\n"; |
1255 | } | 1255 | } |
1256 | //os << ts.read(); | 1256 | //os << ts.read(); |
1257 | file.close(); | 1257 | file.close(); |
1258 | mSyncActionDialog->setCaption( i18n("Waiting for synced file...") ); | 1258 | mSyncActionDialog->setCaption( i18n("Waiting for synced file...") ); |
1259 | mSocket->close(); | 1259 | mSocket->close(); |
1260 | if ( mSocket->state() == QSocket::Idle ) | 1260 | if ( mSocket->state() == QSocket::Idle ) |
1261 | QTimer::singleShot( 10, this , SLOT ( discardClient())); | 1261 | QTimer::singleShot( 10, this , SLOT ( discardClient())); |
1262 | } | 1262 | } |
1263 | void KServerSocket::get_file() | 1263 | void KServerSocket::get_file() |
1264 | { | 1264 | { |
1265 | mSyncActionDialog->setCaption( i18n("Receiving synced file...") ); | 1265 | mSyncActionDialog->setCaption( i18n("Receiving synced file...") ); |
1266 | 1266 | ||
1267 | piTime.start(); | 1267 | piTime.start(); |
1268 | piFileString = ""; | 1268 | piFileString = ""; |
1269 | QTimer::singleShot( 1, this , SLOT (readBackFileFromSocket( ) )); | 1269 | QTimer::singleShot( 1, this , SLOT (readBackFileFromSocket( ) )); |
1270 | } | 1270 | } |
1271 | 1271 | ||
1272 | 1272 | ||
1273 | void KServerSocket::readBackFileFromSocket() | 1273 | void KServerSocket::readBackFileFromSocket() |
1274 | { | 1274 | { |
1275 | //qDebug("readBackFileFromSocket() %d ", piTime.elapsed ()); | 1275 | //qDebug("readBackFileFromSocket() %d ", piTime.elapsed ()); |
1276 | while ( mSocket->canReadLine () ) { | 1276 | while ( mSocket->canReadLine () ) { |
1277 | piTime.restart(); | 1277 | piTime.restart(); |
1278 | QString line = mSocket->readLine (); | 1278 | QString line = mSocket->readLine (); |
1279 | piFileString += line; | 1279 | piFileString += line; |
1280 | //qDebug("readline: %s ", line.latin1()); | 1280 | //qDebug("readline: %s ", line.latin1()); |
1281 | mSyncActionDialog->setCaption( i18n("Received %1 bytes").arg( piFileString.length() ) ); | 1281 | mSyncActionDialog->setCaption( i18n("Received %1 bytes").arg( piFileString.length() ) ); |
1282 | 1282 | ||
1283 | } | 1283 | } |
1284 | if ( piTime.elapsed () < 3000 ) { | 1284 | if ( piTime.elapsed () < 3000 ) { |
1285 | // wait for more | 1285 | // wait for more |
1286 | //qDebug("waitformore "); | 1286 | //qDebug("waitformore "); |
1287 | QTimer::singleShot( 100, this , SLOT (readBackFileFromSocket( ) )); | 1287 | QTimer::singleShot( 100, this , SLOT (readBackFileFromSocket( ) )); |
1288 | return; | 1288 | return; |
1289 | } | 1289 | } |
1290 | QString fileName = mFileName; | 1290 | QString fileName = mFileName; |
1291 | QFile file ( fileName ); | 1291 | QFile file ( fileName ); |
1292 | if (!file.open( IO_WriteOnly ) ) { | 1292 | if (!file.open( IO_WriteOnly ) ) { |
1293 | delete mSyncActionDialog; | 1293 | delete mSyncActionDialog; |
1294 | mSyncActionDialog = 0; | 1294 | mSyncActionDialog = 0; |
1295 | qDebug("KSS:Error open read back file "); | 1295 | qDebug("KSS:Error open read back file "); |
1296 | piFileString = ""; | 1296 | piFileString = ""; |
1297 | emit file_received( false ); | 1297 | emit file_received( false ); |
1298 | blockRC = false; | 1298 | blockRC = false; |
1299 | return ; | 1299 | return ; |
1300 | 1300 | ||
1301 | } | 1301 | } |
1302 | 1302 | ||
1303 | // mView->setLoadedFileVersion(QDateTime::currentDateTime().addSecs( -1)); | 1303 | // mView->setLoadedFileVersion(QDateTime::currentDateTime().addSecs( -1)); |
1304 | QTextStream ts ( &file ); | 1304 | QTextStream ts ( &file ); |
1305 | ts.setEncoding( QTextStream::Latin1 ); | 1305 | ts.setEncoding( QTextStream::Latin1 ); |
1306 | mSyncActionDialog->setCaption( i18n("Writing file to disk...") ); | 1306 | mSyncActionDialog->setCaption( i18n("Writing file to disk...") ); |
1307 | ts << piFileString; | 1307 | ts << piFileString; |
1308 | mSocket->close(); | 1308 | mSocket->close(); |
1309 | if ( mSocket->state() == QSocket::Idle ) | 1309 | if ( mSocket->state() == QSocket::Idle ) |
1310 | QTimer::singleShot( 10, this , SLOT ( discardClient())); | 1310 | QTimer::singleShot( 10, this , SLOT ( discardClient())); |
1311 | file.close(); | 1311 | file.close(); |
1312 | piFileString = ""; | 1312 | piFileString = ""; |
1313 | emit file_received( true ); | 1313 | emit file_received( true ); |
1314 | delete mSyncActionDialog; | 1314 | delete mSyncActionDialog; |
1315 | mSyncActionDialog = 0; | 1315 | mSyncActionDialog = 0; |
1316 | blockRC = false; | 1316 | blockRC = false; |
1317 | 1317 | ||
1318 | } | 1318 | } |
1319 | 1319 | ||
1320 | KCommandSocket::KCommandSocket ( QString password, Q_UINT16 port, QString host, QObject * parent, const char * name ): QObject( parent, name ) | 1320 | KCommandSocket::KCommandSocket ( QString password, Q_UINT16 port, QString host, QObject * parent, const char * name ): QObject( parent, name ) |
1321 | { | 1321 | { |
1322 | mPassWord = password; | 1322 | mPassWord = password; |
1323 | mSocket = 0; | 1323 | mSocket = 0; |
1324 | mPort = port; | 1324 | mPort = port; |
1325 | mHost = host; | 1325 | mHost = host; |
1326 | 1326 | ||
1327 | mRetVal = quiet; | 1327 | mRetVal = quiet; |
1328 | mTimerSocket = new QTimer ( this ); | 1328 | mTimerSocket = new QTimer ( this ); |
1329 | connect( mTimerSocket, SIGNAL ( timeout () ), this, SLOT ( deleteSocket() ) ); | 1329 | connect( mTimerSocket, SIGNAL ( timeout () ), this, SLOT ( deleteSocket() ) ); |
1330 | } | 1330 | } |
1331 | void KCommandSocket::readFile( QString fn ) | 1331 | void KCommandSocket::readFile( QString fn ) |
1332 | { | 1332 | { |
1333 | if ( !mSocket ) { | 1333 | if ( !mSocket ) { |
1334 | mSocket = new QSocket( this ); | 1334 | mSocket = new QSocket( this ); |
1335 | connect( mSocket, SIGNAL(readyRead()), this, SLOT(startReadFileFromSocket()) ); | 1335 | connect( mSocket, SIGNAL(readyRead()), this, SLOT(startReadFileFromSocket()) ); |
1336 | connect( mSocket, SIGNAL(delayedCloseFinished ()), this, SLOT(deleteSocket()) ); | 1336 | connect( mSocket, SIGNAL(delayedCloseFinished ()), this, SLOT(deleteSocket()) ); |
1337 | } | 1337 | } |
1338 | mFileString = ""; | 1338 | mFileString = ""; |
1339 | mFileName = fn; | 1339 | mFileName = fn; |
1340 | mFirst = true; | 1340 | mFirst = true; |
1341 | mSocket->connectToHost( mHost, mPort ); | 1341 | mSocket->connectToHost( mHost, mPort ); |
1342 | QTextStream os( mSocket ); | 1342 | QTextStream os( mSocket ); |
1343 | os.setEncoding( QTextStream::Latin1 ); | 1343 | os.setEncoding( QTextStream::Latin1 ); |
1344 | 1344 | ||
1345 | QString curDt = " " +KGlobal::locale()->formatDateTime(QDateTime::currentDateTime().addSecs(-1),true, true,KLocale::ISODate ); | 1345 | QString curDt = " " +KGlobal::locale()->formatDateTime(QDateTime::currentDateTime().addSecs(-1),true, true,KLocale::ISODate ); |
1346 | os << "GET " << mPassWord << curDt <<"\r\n"; | 1346 | os << "GET " << mPassWord << curDt <<"\r\n"; |
1347 | mTimerSocket->start( 20000 ); | 1347 | mTimerSocket->start( 300000 ); |
1348 | } | 1348 | } |
1349 | 1349 | ||
1350 | void KCommandSocket::writeFile( QString fileName ) | 1350 | void KCommandSocket::writeFile( QString fileName ) |
1351 | { | 1351 | { |
1352 | if ( !mSocket ) { | 1352 | if ( !mSocket ) { |
1353 | mSocket = new QSocket( this ); | 1353 | mSocket = new QSocket( this ); |
1354 | connect( mSocket, SIGNAL(delayedCloseFinished ()), this, SLOT(deleteSocket()) ); | 1354 | connect( mSocket, SIGNAL(delayedCloseFinished ()), this, SLOT(deleteSocket()) ); |
1355 | connect( mSocket, SIGNAL(connected ()), this, SLOT(writeFileToSocket()) ); | 1355 | connect( mSocket, SIGNAL(connected ()), this, SLOT(writeFileToSocket()) ); |
1356 | } | 1356 | } |
1357 | mFileName = fileName ; | 1357 | mFileName = fileName ; |
1358 | mSocket->connectToHost( mHost, mPort ); | 1358 | mSocket->connectToHost( mHost, mPort ); |
1359 | } | 1359 | } |
1360 | void KCommandSocket::writeFileToSocket() | 1360 | void KCommandSocket::writeFileToSocket() |
1361 | { | 1361 | { |
1362 | QFile file2( mFileName ); | 1362 | QFile file2( mFileName ); |
1363 | if (!file2.open( IO_ReadOnly ) ) { | 1363 | if (!file2.open( IO_ReadOnly ) ) { |
1364 | mRetVal= errorW; | 1364 | mRetVal= errorW; |
1365 | mSocket->close(); | 1365 | mSocket->close(); |
1366 | if ( mSocket->state() == QSocket::Idle ) | 1366 | if ( mSocket->state() == QSocket::Idle ) |
1367 | QTimer::singleShot( 10, this , SLOT ( deleteSocket())); | 1367 | QTimer::singleShot( 10, this , SLOT ( deleteSocket())); |
1368 | return ; | 1368 | return ; |
1369 | } | 1369 | } |
1370 | QTextStream ts2( &file2 ); | 1370 | QTextStream ts2( &file2 ); |
1371 | ts2.setEncoding( QTextStream::Latin1 ); | 1371 | ts2.setEncoding( QTextStream::Latin1 ); |
1372 | QTextStream os2( mSocket ); | 1372 | QTextStream os2( mSocket ); |
1373 | os2.setEncoding( QTextStream::Latin1 ); | 1373 | os2.setEncoding( QTextStream::Latin1 ); |
1374 | os2 << "PUT " << mPassWord << "\r\n";; | 1374 | os2 << "PUT " << mPassWord << "\r\n";; |
1375 | while ( ! ts2.atEnd() ) { | 1375 | while ( ! ts2.atEnd() ) { |
1376 | os2 << ts2.readLine() << "\r\n"; | 1376 | os2 << ts2.readLine() << "\r\n"; |
1377 | } | 1377 | } |
1378 | mRetVal= successW; | 1378 | mRetVal= successW; |
1379 | file2.close(); | 1379 | file2.close(); |
1380 | mSocket->close(); | 1380 | mSocket->close(); |
1381 | if ( mSocket->state() == QSocket::Idle ) | 1381 | if ( mSocket->state() == QSocket::Idle ) |
1382 | QTimer::singleShot( 10, this , SLOT ( deleteSocket())); | 1382 | QTimer::singleShot( 10, this , SLOT ( deleteSocket())); |
1383 | } | 1383 | } |
1384 | void KCommandSocket::sendStop() | 1384 | void KCommandSocket::sendStop() |
1385 | { | 1385 | { |
1386 | if ( !mSocket ) { | 1386 | if ( !mSocket ) { |
1387 | mSocket = new QSocket( this ); | 1387 | mSocket = new QSocket( this ); |
1388 | connect( mSocket, SIGNAL(delayedCloseFinished ()), this, SLOT(deleteSocket()) ); | 1388 | connect( mSocket, SIGNAL(delayedCloseFinished ()), this, SLOT(deleteSocket()) ); |
1389 | } | 1389 | } |
1390 | mSocket->connectToHost( mHost, mPort ); | 1390 | mSocket->connectToHost( mHost, mPort ); |
1391 | QTextStream os2( mSocket ); | 1391 | QTextStream os2( mSocket ); |
1392 | os2.setEncoding( QTextStream::Latin1 ); | 1392 | os2.setEncoding( QTextStream::Latin1 ); |
1393 | os2 << "STOP\r\n"; | 1393 | os2 << "STOP\r\n"; |
1394 | mSocket->close(); | 1394 | mSocket->close(); |
1395 | if ( mSocket->state() == QSocket::Idle ) | 1395 | if ( mSocket->state() == QSocket::Idle ) |
1396 | QTimer::singleShot( 10, this , SLOT ( deleteSocket())); | 1396 | QTimer::singleShot( 10, this , SLOT ( deleteSocket())); |
1397 | } | 1397 | } |
1398 | 1398 | ||
1399 | void KCommandSocket::startReadFileFromSocket() | 1399 | void KCommandSocket::startReadFileFromSocket() |
1400 | { | 1400 | { |
1401 | if ( ! mFirst ) | 1401 | if ( ! mFirst ) |
1402 | return; | 1402 | return; |
1403 | mFirst = false; | 1403 | mFirst = false; |
1404 | mTimerSocket->stop(); | 1404 | mTimerSocket->stop(); |
1405 | mFileString = ""; | 1405 | mFileString = ""; |
1406 | mTime.start(); | 1406 | mTime.start(); |
1407 | QTimer::singleShot( 1, this , SLOT (readFileFromSocket( ) )); | 1407 | QTimer::singleShot( 1, this , SLOT (readFileFromSocket( ) )); |
1408 | 1408 | ||
1409 | } | 1409 | } |
1410 | void KCommandSocket::readFileFromSocket() | 1410 | void KCommandSocket::readFileFromSocket() |
1411 | { | 1411 | { |
1412 | //qDebug("readBackFileFromSocket() %d ", mTime.elapsed ()); | 1412 | //qDebug("readBackFileFromSocket() %d ", mTime.elapsed ()); |
1413 | while ( mSocket->canReadLine () ) { | 1413 | while ( mSocket->canReadLine () ) { |
1414 | mTime.restart(); | 1414 | mTime.restart(); |
1415 | QString line = mSocket->readLine (); | 1415 | QString line = mSocket->readLine (); |
1416 | mFileString += line; | 1416 | mFileString += line; |
1417 | //qDebug("readline: %s ", line.latin1()); | 1417 | //qDebug("readline: %s ", line.latin1()); |
1418 | } | 1418 | } |
1419 | if ( mTime.elapsed () < 3000 ) { | 1419 | if ( mTime.elapsed () < 3000 ) { |
1420 | // wait for more | 1420 | // wait for more |
1421 | //qDebug("waitformore "); | 1421 | //qDebug("waitformore "); |
1422 | QTimer::singleShot( 100, this , SLOT (readFileFromSocket( ) )); | 1422 | QTimer::singleShot( 100, this , SLOT (readFileFromSocket( ) )); |
1423 | return; | 1423 | return; |
1424 | } | 1424 | } |
1425 | QString fileName = mFileName; | 1425 | QString fileName = mFileName; |
1426 | QFile file ( fileName ); | 1426 | QFile file ( fileName ); |
1427 | if (!file.open( IO_WriteOnly ) ) { | 1427 | if (!file.open( IO_WriteOnly ) ) { |
1428 | mFileString = ""; | 1428 | mFileString = ""; |
1429 | mRetVal = errorR; | 1429 | mRetVal = errorR; |
1430 | qDebug("KSS:Error open temp sync file for writing: %s",fileName.latin1() ); | 1430 | qDebug("KSS:Error open temp sync file for writing: %s",fileName.latin1() ); |
1431 | deleteSocket(); | 1431 | deleteSocket(); |
1432 | return ; | 1432 | return ; |
1433 | 1433 | ||
1434 | } | 1434 | } |
1435 | // mView->setLoadedFileVersion(QDateTime::currentDateTime().addSecs( -1)); | 1435 | // mView->setLoadedFileVersion(QDateTime::currentDateTime().addSecs( -1)); |
1436 | QTextStream ts ( &file ); | 1436 | QTextStream ts ( &file ); |
1437 | ts.setEncoding( QTextStream::Latin1 ); | 1437 | ts.setEncoding( QTextStream::Latin1 ); |
1438 | ts << mFileString; | 1438 | ts << mFileString; |
1439 | file.close(); | 1439 | file.close(); |
1440 | mFileString = ""; | 1440 | mFileString = ""; |
1441 | mRetVal = successR; | 1441 | mRetVal = successR; |
1442 | mSocket->close(); | 1442 | mSocket->close(); |
1443 | // if state is not idle, deleteSocket(); is called via | 1443 | // if state is not idle, deleteSocket(); is called via |
1444 | // connect( mSocket, SIGNAL(delayedCloseFinished ()), this, SLOT(deleteSocket()) ); | 1444 | // connect( mSocket, SIGNAL(delayedCloseFinished ()), this, SLOT(deleteSocket()) ); |
1445 | if ( mSocket->state() == QSocket::Idle ) | 1445 | if ( mSocket->state() == QSocket::Idle ) |
1446 | deleteSocket(); | 1446 | deleteSocket(); |
1447 | } | 1447 | } |
1448 | 1448 | ||
1449 | void KCommandSocket::deleteSocket() | 1449 | void KCommandSocket::deleteSocket() |
1450 | { | 1450 | { |
1451 | //qDebug("KCommandSocket::deleteSocket() "); | 1451 | //qDebug("KCommandSocket::deleteSocket() "); |
1452 | if ( mTimerSocket->isActive () ) { | 1452 | if ( mTimerSocket->isActive () ) { |
1453 | mTimerSocket->stop(); | 1453 | mTimerSocket->stop(); |
1454 | mRetVal = errorTO; | 1454 | mRetVal = errorTO; |
1455 | qDebug("Connection to remote host timed out"); | 1455 | qDebug("Connection to remote host timed out"); |
1456 | if ( mSocket ) { | 1456 | if ( mSocket ) { |
1457 | mSocket->close(); | 1457 | mSocket->close(); |
1458 | //if ( mSocket->state() == QSocket::Idle ) | 1458 | //if ( mSocket->state() == QSocket::Idle ) |
1459 | // deleteSocket(); | 1459 | // deleteSocket(); |
1460 | delete mSocket; | 1460 | delete mSocket; |
1461 | mSocket = 0; | 1461 | mSocket = 0; |
1462 | } | 1462 | } |
1463 | KMessageBox::error( 0, i18n("Connection to remote\nhost timed out!\nDid you forgot to enable\nsyncing on remote host? ")); | 1463 | KMessageBox::error( 0, i18n("Connection to remote\nhost timed out!\nDid you forgot to enable\nsyncing on remote host? ")); |
1464 | emit commandFinished( this, mRetVal ); | 1464 | emit commandFinished( this, mRetVal ); |
1465 | return; | 1465 | return; |
1466 | } | 1466 | } |
1467 | //qDebug("KCommandSocket::deleteSocket() %d", mRetVal ); | 1467 | //qDebug("KCommandSocket::deleteSocket() %d", mRetVal ); |
1468 | if ( mSocket) | 1468 | if ( mSocket) |
1469 | delete mSocket; | 1469 | delete mSocket; |
1470 | mSocket = 0; | 1470 | mSocket = 0; |
1471 | emit commandFinished( this, mRetVal ); | 1471 | emit commandFinished( this, mRetVal ); |
1472 | } | 1472 | } |