-rw-r--r-- | libkdepim/ksyncmanager.cpp | 48 | ||||
-rw-r--r-- | libkdepim/ksyncmanager.h | 2 |
2 files changed, 43 insertions, 7 deletions
diff --git a/libkdepim/ksyncmanager.cpp b/libkdepim/ksyncmanager.cpp index e1b15d2..8bf0d27 100644 --- a/libkdepim/ksyncmanager.cpp +++ b/libkdepim/ksyncmanager.cpp | |||
@@ -1115,205 +1115,237 @@ QString KSyncManager::syncFileName() | |||
1115 | } | 1115 | } |
1116 | #ifdef DESKTOP_VERSION | 1116 | #ifdef DESKTOP_VERSION |
1117 | return locateLocal( "tmp", fn ); | 1117 | return locateLocal( "tmp", fn ); |
1118 | #else | 1118 | #else |
1119 | return (QString( "/tmp/" )+ fn ); | 1119 | return (QString( "/tmp/" )+ fn ); |
1120 | #endif | 1120 | #endif |
1121 | } | 1121 | } |
1122 | 1122 | ||
1123 | void KSyncManager::syncPi() | 1123 | void KSyncManager::syncPi() |
1124 | { | 1124 | { |
1125 | mIsKapiFile = true; | 1125 | mIsKapiFile = true; |
1126 | mPisyncFinished = false; | 1126 | mPisyncFinished = false; |
1127 | qApp->processEvents(); | 1127 | qApp->processEvents(); |
1128 | if ( mAskForPreferences ) | 1128 | if ( mAskForPreferences ) |
1129 | if ( !edit_pisync_options()) { | 1129 | if ( !edit_pisync_options()) { |
1130 | mParent->topLevelWidget()->setCaption( i18n("Syncing aborted. Nothing synced.") ); | 1130 | mParent->topLevelWidget()->setCaption( i18n("Syncing aborted. Nothing synced.") ); |
1131 | mPisyncFinished = true; | 1131 | mPisyncFinished = true; |
1132 | return; | 1132 | return; |
1133 | } | 1133 | } |
1134 | bool ok; | 1134 | bool ok; |
1135 | Q_UINT16 port = mActiveSyncPort.toUInt(&ok); | 1135 | Q_UINT16 port = mActiveSyncPort.toUInt(&ok); |
1136 | if ( ! ok ) { | 1136 | if ( ! ok ) { |
1137 | mParent->topLevelWidget()->setCaption( i18n("Sorry, no valid port.Syncing cancelled.") ); | 1137 | mParent->topLevelWidget()->setCaption( i18n("Sorry, no valid port.Syncing cancelled.") ); |
1138 | mPisyncFinished = true; | 1138 | mPisyncFinished = true; |
1139 | return; | 1139 | return; |
1140 | } | 1140 | } |
1141 | mCurrentResourceLocal = ""; | 1141 | mCurrentResourceLocal = ""; |
1142 | mCurrentResourceRemote = ""; | 1142 | mCurrentResourceRemote = ""; |
1143 | if ( mSpecificResources.count() ) { | 1143 | if ( mSpecificResources.count() ) { |
1144 | int lastSyncRes = mSpecificResources.count()/2; | 1144 | int lastSyncRes = mSpecificResources.count()/2; |
1145 | int ccc = mSpecificResources.count()-1; | 1145 | int ccc = mSpecificResources.count()-1; |
1146 | while ( lastSyncRes > 0 && ccc > 0 && mSpecificResources[ ccc ].isEmpty() ) { | 1146 | while ( lastSyncRes > 0 && ccc > 0 && mSpecificResources[ ccc ].isEmpty() ) { |
1147 | --ccc; | 1147 | --ccc; |
1148 | --lastSyncRes; | 1148 | --lastSyncRes; |
1149 | //qDebug ( "KSM: sync pi %d",ccc ); | 1149 | //qDebug ( "KSM: sync pi %d",ccc ); |
1150 | } | 1150 | } |
1151 | int startLocal = 0; | 1151 | int startLocal = 0; |
1152 | int startRemote = mSpecificResources.count()/2; | 1152 | int startRemote = mSpecificResources.count()/2; |
1153 | emit multiResourceSyncStart( true ); | 1153 | emit multiResourceSyncStart( true ); |
1154 | while ( startLocal < mSpecificResources.count()/2 ) { | 1154 | while ( startLocal < mSpecificResources.count()/2 ) { |
1155 | if ( startLocal+1 >= lastSyncRes ) | 1155 | if ( startLocal+1 >= lastSyncRes ) |
1156 | emit multiResourceSyncStart( false ); | 1156 | emit multiResourceSyncStart( false ); |
1157 | mPisyncFinished = false; | 1157 | mPisyncFinished = false; |
1158 | mCurrentResourceLocal = mSpecificResources[ startLocal ]; | 1158 | mCurrentResourceLocal = mSpecificResources[ startLocal ]; |
1159 | mCurrentResourceRemote = mSpecificResources[ startRemote ]; | 1159 | mCurrentResourceRemote = mSpecificResources[ startRemote ]; |
1160 | //qDebug ( "KSM: AAASyncing resources: Local: %s --- Remote: %s ",mCurrentResourceLocal.latin1(), mCurrentResourceRemote.latin1() ); | 1160 | //qDebug ( "KSM: AAASyncing resources: Local: %s --- Remote: %s ",mCurrentResourceLocal.latin1(), mCurrentResourceRemote.latin1() ); |
1161 | if ( !mCurrentResourceRemote.isEmpty() ) { | 1161 | if ( !mCurrentResourceRemote.isEmpty() ) { |
1162 | qDebug ( "KSM: Syncing resources: Local: %s --- Remote: %s ",mCurrentResourceLocal.latin1(), mCurrentResourceRemote.latin1() ); | 1162 | qDebug ( "KSM: Syncing resources: Local: %s --- Remote: %s ",mCurrentResourceLocal.latin1(), mCurrentResourceRemote.latin1() ); |
1163 | |||
1163 | KCommandSocket* commandSocket = new KCommandSocket( mCurrentResourceRemote, mPassWordPiSync, port, mActiveSyncIP, this, mParent->topLevelWidget() ); | 1164 | KCommandSocket* commandSocket = new KCommandSocket( mCurrentResourceRemote, mPassWordPiSync, port, mActiveSyncIP, this, mParent->topLevelWidget() ); |
1164 | connect( commandSocket, SIGNAL(commandFinished( KCommandSocket*, int )), this, SLOT(deleteCommandSocket(KCommandSocket*, int)) ); | 1165 | connect( commandSocket, SIGNAL(commandFinished( KCommandSocket*, int )), this, SLOT(deleteCommandSocket(KCommandSocket*, int)) ); |
1165 | commandSocket->readFile( syncFileName() ); | 1166 | commandSocket->readFile( syncFileName() ); |
1167 | mParent->topLevelWidget()->setCaption( i18n("Syncing %1 <-> %2").arg( mCurrentResourceLocal ).arg( mCurrentResourceRemote ) ); | ||
1166 | while ( !mPisyncFinished ) { | 1168 | while ( !mPisyncFinished ) { |
1167 | //qDebug("waiting "); | 1169 | //qDebug("waiting "); |
1168 | qApp->processEvents(); | 1170 | qApp->processEvents(); |
1169 | } | 1171 | } |
1172 | if ( startLocal+1 < mSpecificResources.count()/2 ) { | ||
1173 | mParent->topLevelWidget()->setCaption( i18n("Waiting 2 secs before syncing next resource...") ); | ||
1174 | QTime timer; | ||
1175 | timer.start(); | ||
1176 | while ( timer.elapsed () < 2000 ) { | ||
1177 | qApp->processEvents(); | ||
1178 | } | ||
1179 | } | ||
1170 | } | 1180 | } |
1171 | ++startRemote; | 1181 | ++startRemote; |
1172 | ++startLocal; | 1182 | ++startLocal; |
1183 | |||
1173 | } | 1184 | } |
1174 | mPisyncFinished = true; | 1185 | mPisyncFinished = true; |
1175 | } else { | 1186 | } else { |
1176 | KCommandSocket* commandSocket = new KCommandSocket( "", mPassWordPiSync, port, mActiveSyncIP, this, mParent->topLevelWidget() ); | 1187 | KCommandSocket* commandSocket = new KCommandSocket( "", mPassWordPiSync, port, mActiveSyncIP, this, mParent->topLevelWidget() ); |
1177 | connect( commandSocket, SIGNAL(commandFinished( KCommandSocket*, int )), this, SLOT(deleteCommandSocket(KCommandSocket*, int)) ); | 1188 | connect( commandSocket, SIGNAL(commandFinished( KCommandSocket*, int )), this, SLOT(deleteCommandSocket(KCommandSocket*, int)) ); |
1178 | commandSocket->readFile( syncFileName() ); | 1189 | commandSocket->readFile( syncFileName() ); |
1179 | } | 1190 | } |
1180 | } | 1191 | } |
1181 | 1192 | ||
1182 | void KSyncManager::deleteCommandSocket(KCommandSocket*s, int state) | 1193 | void KSyncManager::deleteCommandSocket(KCommandSocket*s, int state) |
1183 | { | 1194 | { |
1184 | //enum { success, errorW, errorR, quiet }; | 1195 | //enum { success, errorW, errorR, quiet }; |
1185 | 1196 | ||
1186 | 1197 | ||
1187 | 1198 | ||
1188 | if ( state == KCommandSocket::errorR ||state == KCommandSocket::errorTO ||state == KCommandSocket::errorPW || | 1199 | if ( state == KCommandSocket::errorR ||state == KCommandSocket::errorTO ||state == KCommandSocket::errorPW || |
1189 | state == KCommandSocket::errorCA ||state == KCommandSocket::errorFI ||state == KCommandSocket::errorUN||state == KCommandSocket::errorED ) { | 1200 | state == KCommandSocket::errorCA ||state == KCommandSocket::errorFI ||state == KCommandSocket::errorUN||state == KCommandSocket::errorED ) { |
1190 | if ( state == KCommandSocket::errorPW ) | 1201 | if ( state == KCommandSocket::errorPW ) |
1191 | mParent->topLevelWidget()->setCaption( i18n("Wrong password: Receiving remote file failed.") ); | 1202 | mParent->topLevelWidget()->setCaption( i18n("Wrong password: Receiving remote file failed.") ); |
1192 | else if ( state == KCommandSocket::errorR ||state == KCommandSocket::errorTO ) | 1203 | else if ( state == KCommandSocket::errorR ||state == KCommandSocket::errorTO ) |
1193 | mParent->topLevelWidget()->setCaption( i18n("ERROR: Receiving remote file failed.") ); | 1204 | mParent->topLevelWidget()->setCaption( i18n("ERROR: Receiving remote file failed.") ); |
1194 | else if ( state == KCommandSocket::errorCA ) | 1205 | else if ( state == KCommandSocket::errorCA ) |
1195 | mParent->topLevelWidget()->setCaption( i18n("Sync cancelled from remote.") ); | 1206 | mParent->topLevelWidget()->setCaption( i18n("Sync cancelled from remote.") ); |
1196 | else if ( state == KCommandSocket::errorFI ) | 1207 | else if ( state == KCommandSocket::errorFI ) |
1197 | mParent->topLevelWidget()->setCaption( i18n("File error on remote.") ); | 1208 | mParent->topLevelWidget()->setCaption( i18n("File error on remote.") ); |
1198 | else if ( state == KCommandSocket::errorED ) | 1209 | else if ( state == KCommandSocket::errorED ) |
1199 | mParent->topLevelWidget()->setCaption( i18n("Please close error dialog on remote.") ); | 1210 | mParent->topLevelWidget()->setCaption( i18n("Please close error dialog on remote.") ); |
1200 | else if ( state == KCommandSocket::errorUN ) | 1211 | else if ( state == KCommandSocket::errorUN ) |
1201 | mParent->topLevelWidget()->setCaption( i18n("Unknown error on remote.") ); | 1212 | mParent->topLevelWidget()->setCaption( i18n("Unknown error on remote.") ); |
1202 | delete s; | 1213 | delete s; |
1203 | if ( state == KCommandSocket::errorR ) { | 1214 | if ( state == KCommandSocket::errorR ) { |
1204 | KCommandSocket* commandSocket = new KCommandSocket( "",mPassWordPiSync, mActiveSyncPort.toUInt(), mActiveSyncIP, this, mParent->topLevelWidget()); | 1215 | KCommandSocket* commandSocket = new KCommandSocket( "",mPassWordPiSync, mActiveSyncPort.toUInt(), mActiveSyncIP, this, mParent->topLevelWidget()); |
1205 | connect( commandSocket, SIGNAL(commandFinished( KCommandSocket*, int)), this, SLOT(deleteCommandSocket(KCommandSocket*, int )) ); | 1216 | connect( commandSocket, SIGNAL(commandFinished( KCommandSocket*, int)), this, SLOT(deleteCommandSocket(KCommandSocket*, int )) ); |
1206 | commandSocket->sendStop(); | 1217 | commandSocket->sendStop(); |
1207 | } | 1218 | } |
1208 | mPisyncFinished = true; | 1219 | mPisyncFinished = true; |
1209 | return; | 1220 | return; |
1210 | 1221 | ||
1211 | } else if ( state == KCommandSocket::errorW ) { | 1222 | } else if ( state == KCommandSocket::errorW ) { |
1212 | mParent->topLevelWidget()->setCaption( i18n("ERROR:Writing back file failed.") ); | 1223 | mParent->topLevelWidget()->setCaption( i18n("ERROR:Writing back file failed.") ); |
1213 | mPisyncFinished = true; | 1224 | mPisyncFinished = true; |
1214 | 1225 | ||
1215 | } else if ( state == KCommandSocket::successR ) { | 1226 | } else if ( state == KCommandSocket::successR ) { |
1216 | QTimer::singleShot( 1, this , SLOT ( readFileFromSocket())); | 1227 | QTimer::singleShot( 1, this , SLOT ( readFileFromSocket())); |
1217 | 1228 | ||
1218 | } else if ( state == KCommandSocket::successW ) { | 1229 | } else if ( state == KCommandSocket::successW ) { |
1219 | mParent->topLevelWidget()->setCaption( i18n("Pi-Sync successful!") ); | 1230 | mParent->topLevelWidget()->setCaption( i18n("Pi-Sync successful!") ); |
1220 | mPisyncFinished = true; | 1231 | mPisyncFinished = true; |
1221 | } else if ( state == KCommandSocket::quiet ){ | 1232 | } else if ( state == KCommandSocket::quiet ){ |
1222 | qDebug("KSS: quiet "); | 1233 | qDebug("KSS: quiet "); |
1223 | mPisyncFinished = true; | 1234 | mPisyncFinished = true; |
1224 | } else { | 1235 | } else { |
1225 | qDebug("KSS: Error: unknown state: %d ", state); | 1236 | qDebug("KSS: Error: unknown state: %d ", state); |
1226 | mPisyncFinished = true; | 1237 | mPisyncFinished = true; |
1227 | } | 1238 | } |
1228 | 1239 | ||
1229 | delete s; | 1240 | delete s; |
1230 | } | 1241 | } |
1231 | 1242 | ||
1232 | void KSyncManager::readFileFromSocket() | 1243 | void KSyncManager::readFileFromSocket() |
1233 | { | 1244 | { |
1234 | QString fileName = syncFileName(); | 1245 | QString fileName = syncFileName(); |
1235 | bool syncOK = true; | 1246 | bool syncOK = true; |
1236 | mParent->topLevelWidget()->setCaption( i18n("Remote file saved to temp file.") ); | 1247 | mParent->topLevelWidget()->setCaption( i18n("Remote file saved to temp file.") ); |
1237 | if ( ! syncWithFile( fileName , true ) ) { | 1248 | if ( ! syncWithFile( fileName , true ) ) { |
1238 | mParent->topLevelWidget()->setCaption( i18n("Syncing failed.") ); | 1249 | mParent->topLevelWidget()->setCaption( i18n("Syncing failed.") ); |
1239 | syncOK = false; | 1250 | syncOK = false; |
1240 | } | 1251 | } |
1241 | KCommandSocket* commandSocket = new KCommandSocket( mCurrentResourceRemote,mPassWordPiSync, mActiveSyncPort.toUInt(), mActiveSyncIP, this, mParent->topLevelWidget() ); | 1252 | KCommandSocket* commandSocket = new KCommandSocket( mCurrentResourceRemote,mPassWordPiSync, mActiveSyncPort.toUInt(), mActiveSyncIP, this, mParent->topLevelWidget() ); |
1242 | connect( commandSocket, SIGNAL(commandFinished( KCommandSocket*, int)), this, SLOT(deleteCommandSocket(KCommandSocket*, int )) ); | 1253 | connect( commandSocket, SIGNAL(commandFinished( KCommandSocket*, int)), this, SLOT(deleteCommandSocket(KCommandSocket*, int )) ); |
1243 | if ( mWriteBackFile && syncOK ) { | 1254 | if ( mWriteBackFile && syncOK ) { |
1244 | mParent->topLevelWidget()->setCaption( i18n("Sending back file ...") ); | 1255 | mParent->topLevelWidget()->setCaption( i18n("Sending back file ...") ); |
1245 | commandSocket->writeFile( fileName ); | 1256 | commandSocket->writeFile( fileName ); |
1246 | } | 1257 | } |
1247 | else { | 1258 | else { |
1248 | commandSocket->sendStop(); | 1259 | commandSocket->sendStop(); |
1249 | if ( syncOK ) | 1260 | if ( syncOK ) |
1250 | mParent->topLevelWidget()->setCaption( i18n("Pi-Sync succesful!") ); | 1261 | mParent->topLevelWidget()->setCaption( i18n("Pi-Sync succesful!") ); |
1251 | mPisyncFinished = true; | 1262 | mPisyncFinished = true; |
1252 | } | 1263 | } |
1253 | } | 1264 | } |
1254 | 1265 | ||
1255 | KServerSocket:: KServerSocket ( QString pw, Q_UINT16 port, int backlog, QObject * parent, const char * name ) : QServerSocket( port, backlog, parent, name ) | 1266 | KServerSocket:: KServerSocket ( QString pw, Q_UINT16 port, int backlog, QObject * parent, const char * name ) : QServerSocket( port, backlog, parent, name ) |
1256 | { | 1267 | { |
1268 | mPendingConnect = 0; | ||
1257 | mPassWord = pw; | 1269 | mPassWord = pw; |
1258 | mSocket = 0; | 1270 | mSocket = 0; |
1259 | mSyncActionDialog = 0; | 1271 | mSyncActionDialog = 0; |
1260 | blockRC = false; | 1272 | blockRC = false; |
1261 | mErrorMessage = 0; | 1273 | mErrorMessage = 0; |
1262 | } | 1274 | } |
1263 | 1275 | void KServerSocket::waitForSocketFinish() | |
1276 | { | ||
1277 | if ( mSocket ) { | ||
1278 | qDebug("KSS:: waiting for finish operation"); | ||
1279 | QTimer::singleShot( 250, this , SLOT ( waitForSocketFinish())); | ||
1280 | return; | ||
1281 | } | ||
1282 | mSocket = new QSocket( this ); | ||
1283 | connect( mSocket , SIGNAL(readyRead()), this, SLOT(readClient()) ); | ||
1284 | connect( mSocket , SIGNAL(delayedCloseFinished()), this, SLOT(discardClient()) ); | ||
1285 | mSocket->setSocket( mPendingConnect ); | ||
1286 | mPendingConnect = 0; | ||
1287 | } | ||
1264 | void KServerSocket::newConnection ( int socket ) | 1288 | void KServerSocket::newConnection ( int socket ) |
1265 | { | 1289 | { |
1266 | // qDebug("KServerSocket:New connection %d ", socket); | 1290 | // qDebug("KServerSocket:New connection %d ", socket); |
1291 | if ( mPendingConnect ) { | ||
1292 | qDebug("KSS::Error : new Connection"); | ||
1293 | return; | ||
1294 | } | ||
1267 | if ( mSocket ) { | 1295 | if ( mSocket ) { |
1296 | mPendingConnect = socket; | ||
1297 | QTimer::singleShot( 250, this , SLOT ( waitForSocketFinish())); | ||
1298 | return; | ||
1268 | qDebug("KSS::newConnection Socket deleted! "); | 1299 | qDebug("KSS::newConnection Socket deleted! "); |
1269 | delete mSocket; | 1300 | delete mSocket; |
1270 | mSocket = 0; | 1301 | mSocket = 0; |
1271 | } | 1302 | } |
1303 | mPendingConnect = 0; | ||
1272 | mSocket = new QSocket( this ); | 1304 | mSocket = new QSocket( this ); |
1273 | connect( mSocket , SIGNAL(readyRead()), this, SLOT(readClient()) ); | 1305 | connect( mSocket , SIGNAL(readyRead()), this, SLOT(readClient()) ); |
1274 | connect( mSocket , SIGNAL(delayedCloseFinished()), this, SLOT(discardClient()) ); | 1306 | connect( mSocket , SIGNAL(delayedCloseFinished()), this, SLOT(discardClient()) ); |
1275 | mSocket->setSocket( socket ); | 1307 | mSocket->setSocket( socket ); |
1276 | } | 1308 | } |
1277 | 1309 | ||
1278 | void KServerSocket::discardClient() | 1310 | void KServerSocket::discardClient() |
1279 | { | 1311 | { |
1280 | QTimer::singleShot( 10, this , SLOT ( deleteSocket())); | 1312 | QTimer::singleShot( 10, this , SLOT ( deleteSocket())); |
1281 | } | 1313 | } |
1282 | void KServerSocket::deleteSocket() | 1314 | void KServerSocket::deleteSocket() |
1283 | { | 1315 | { |
1284 | qDebug("KSS::deleteSocket"); | 1316 | qDebug("KSS::deleteSocket"); |
1285 | if ( mSocket ) { | 1317 | if ( mSocket ) { |
1286 | delete mSocket; | 1318 | delete mSocket; |
1287 | mSocket = 0; | 1319 | mSocket = 0; |
1288 | } | 1320 | } |
1289 | if ( mErrorMessage ) | 1321 | if ( mErrorMessage ) |
1290 | QTimer::singleShot( 10, this , SLOT ( displayErrorMessage())); | 1322 | QTimer::singleShot( 10, this , SLOT ( displayErrorMessage())); |
1291 | } | 1323 | } |
1292 | void KServerSocket::readClient() | 1324 | void KServerSocket::readClient() |
1293 | { | 1325 | { |
1294 | if ( blockRC ) | 1326 | if ( blockRC ) |
1295 | return; | 1327 | return; |
1296 | if ( mSocket == 0 ) { | 1328 | if ( mSocket == 0 ) { |
1297 | qDebug("ERROR::KSS::readClient(): mSocket == 0 "); | 1329 | qDebug("ERROR::KSS::readClient(): mSocket == 0 "); |
1298 | return; | 1330 | return; |
1299 | } | 1331 | } |
1300 | if ( mErrorMessage ) { | 1332 | if ( mErrorMessage ) { |
1301 | mErrorMessage = 999; | 1333 | mErrorMessage = 999; |
1302 | error_connect("ERROR_ED\r\n\r\n"); | 1334 | error_connect("ERROR_ED\r\n\r\n"); |
1303 | return; | 1335 | return; |
1304 | } | 1336 | } |
1305 | mResource = ""; | 1337 | mResource = ""; |
1306 | mErrorMessage = 0; | 1338 | mErrorMessage = 0; |
1307 | //qDebug("KServerSocket::readClient()"); | 1339 | //qDebug("KServerSocket::readClient()"); |
1308 | if ( mSocket->canReadLine() ) { | 1340 | if ( mSocket->canReadLine() ) { |
1309 | QString line = mSocket->readLine(); | 1341 | QString line = mSocket->readLine(); |
1310 | //qDebug("KServerSocket readline: %s ", line.latin1()); | 1342 | //qDebug("KServerSocket readline: %s ", line.latin1()); |
1311 | QStringList tokens = QStringList::split( QRegExp("[ \r\n][ \r\n]*"), line ); | 1343 | QStringList tokens = QStringList::split( QRegExp("[ \r\n][ \r\n]*"), line ); |
1312 | if ( tokens[0] == "GET" ) { | 1344 | if ( tokens[0] == "GET" ) { |
1313 | if ( tokens[1] == mPassWord ) { | 1345 | if ( tokens[1] == mPassWord ) { |
1314 | //emit sendFile( mSocket ); | 1346 | //emit sendFile( mSocket ); |
1315 | bool ok = false; | 1347 | bool ok = false; |
1316 | QDateTime dt = KGlobal::locale()->readDateTime( tokens[2], KLocale::ISODate, &ok); | 1348 | QDateTime dt = KGlobal::locale()->readDateTime( tokens[2], KLocale::ISODate, &ok); |
1317 | if ( ok ) { | 1349 | if ( ok ) { |
1318 | KSyncManager::mRequestedSyncEvent = dt; | 1350 | KSyncManager::mRequestedSyncEvent = dt; |
1319 | } | 1351 | } |
@@ -1498,132 +1530,134 @@ void KServerSocket::readBackFileFromSocket() | |||
1498 | } | 1530 | } |
1499 | 1531 | ||
1500 | // mView->setLoadedFileVersion(QDateTime::currentDateTime().addSecs( -1)); | 1532 | // mView->setLoadedFileVersion(QDateTime::currentDateTime().addSecs( -1)); |
1501 | QTextStream ts ( &file ); | 1533 | QTextStream ts ( &file ); |
1502 | ts.setEncoding( QTextStream::Latin1 ); | 1534 | ts.setEncoding( QTextStream::Latin1 ); |
1503 | mSyncActionDialog->setCaption( i18n("Writing file to disk...") ); | 1535 | mSyncActionDialog->setCaption( i18n("Writing file to disk...") ); |
1504 | ts << piFileString; | 1536 | ts << piFileString; |
1505 | mSocket->close(); | 1537 | mSocket->close(); |
1506 | if ( mSocket->state() == QSocket::Idle ) | 1538 | if ( mSocket->state() == QSocket::Idle ) |
1507 | QTimer::singleShot( 10, this , SLOT ( discardClient())); | 1539 | QTimer::singleShot( 10, this , SLOT ( discardClient())); |
1508 | file.close(); | 1540 | file.close(); |
1509 | piFileString = ""; | 1541 | piFileString = ""; |
1510 | emit file_received( true, mResource ); | 1542 | emit file_received( true, mResource ); |
1511 | emit file_received( true); | 1543 | emit file_received( true); |
1512 | delete mSyncActionDialog; | 1544 | delete mSyncActionDialog; |
1513 | mSyncActionDialog = 0; | 1545 | mSyncActionDialog = 0; |
1514 | blockRC = false; | 1546 | blockRC = false; |
1515 | 1547 | ||
1516 | } | 1548 | } |
1517 | 1549 | ||
1518 | KCommandSocket::KCommandSocket ( QString remres, QString password, Q_UINT16 port, QString host, QObject * parent, QWidget * cap, const char * name ): QObject( parent, name ) | 1550 | KCommandSocket::KCommandSocket ( QString remres, QString password, Q_UINT16 port, QString host, QObject * parent, QWidget * cap, const char * name ): QObject( parent, name ) |
1519 | { | 1551 | { |
1520 | mRemoteResource = remres; | 1552 | mRemoteResource = remres; |
1521 | if ( mRemoteResource.isEmpty() ) | 1553 | if ( mRemoteResource.isEmpty() ) |
1522 | mRemoteResource = "ALL"; | 1554 | mRemoteResource = "ALL"; |
1523 | else | 1555 | else |
1524 | mRemoteResource.replace (QRegExp (" "),"_" ); | 1556 | mRemoteResource.replace (QRegExp (" "),"_" ); |
1525 | mPassWord = password; | 1557 | mPassWord = password; |
1526 | mSocket = 0; | 1558 | mSocket = 0; |
1527 | mFirst = false; | 1559 | mFirst = false; |
1528 | mFirstLine = true; | 1560 | mFirstLine = true; |
1529 | mPort = port; | 1561 | mPort = port; |
1530 | mHost = host; | 1562 | mHost = host; |
1531 | tlw = cap; | 1563 | tlw = cap; |
1532 | mRetVal = quiet; | 1564 | mRetVal = quiet; |
1533 | mTimerSocket = new QTimer ( this ); | 1565 | mTimerSocket = new QTimer ( this ); |
1534 | connect( mTimerSocket, SIGNAL ( timeout () ), this, SLOT ( updateConnectDialog() ) ); | 1566 | connect( mTimerSocket, SIGNAL ( timeout () ), this, SLOT ( updateConnectDialog() ) ); |
1535 | mConnectProgress.setCaption( i18n("Pi-Sync") ); | 1567 | mConnectProgress.setCaption( i18n("Pi-Sync") ); |
1536 | connect( &mConnectProgress, SIGNAL ( cancelled () ), this, SLOT ( deleteSocket() ) ); | 1568 | connect( &mConnectProgress, SIGNAL ( cancelled () ), this, SLOT ( deleteSocket() ) ); |
1537 | mConnectCount = -1; | 1569 | mConnectCount = -1; |
1538 | } | 1570 | } |
1539 | void KCommandSocket::sendFileRequest() | 1571 | void KCommandSocket::sendFileRequest() |
1540 | { | 1572 | { |
1541 | if ( tlw ) | 1573 | if ( tlw ) |
1542 | tlw->setCaption( i18n("Connected! Sending request for remote file ...") ); | 1574 | tlw->setCaption( i18n("Connected! Sending request for remote file ...") ); |
1543 | mConnectProgress.hide(); | 1575 | mConnectProgress.hide(); |
1544 | mConnectCount = 300;mConnectMax = 300; | 1576 | mConnectCount = 300;mConnectMax = 300; |
1545 | mConnectProgress.setCaption( i18n("Pi-Sync: Connected!") ); | 1577 | mConnectProgress.setCaption( i18n("Pi-Sync: Connected!") ); |
1578 | mConnectProgress.setLabelText( i18n("Waiting for remote file...") ); | ||
1546 | mTimerSocket->start( 100, true ); | 1579 | mTimerSocket->start( 100, true ); |
1547 | QTextStream os( mSocket ); | 1580 | QTextStream os( mSocket ); |
1548 | os.setEncoding( QTextStream::Latin1 ); | 1581 | os.setEncoding( QTextStream::Latin1 ); |
1549 | 1582 | ||
1550 | QString curDt = " " +KGlobal::locale()->formatDateTime(QDateTime::currentDateTime().addSecs(-1),true, true,KLocale::ISODate ); | 1583 | QString curDt = " " +KGlobal::locale()->formatDateTime(QDateTime::currentDateTime().addSecs(-1),true, true,KLocale::ISODate ); |
1551 | os << "GET " << mPassWord << curDt << " " << mRemoteResource << "\r\n\r\n"; | 1584 | os << "GET " << mPassWord << curDt << " " << mRemoteResource << "\r\n\r\n"; |
1552 | } | 1585 | } |
1553 | 1586 | ||
1554 | void KCommandSocket::readFile( QString fn ) | 1587 | void KCommandSocket::readFile( QString fn ) |
1555 | { | 1588 | { |
1556 | if ( !mSocket ) { | 1589 | if ( !mSocket ) { |
1557 | mSocket = new QSocket( this ); | 1590 | mSocket = new QSocket( this ); |
1591 | qDebug("KCS: read file - new socket"); | ||
1558 | connect( mSocket, SIGNAL(readyRead()), this, SLOT(startReadFileFromSocket()) ); | 1592 | connect( mSocket, SIGNAL(readyRead()), this, SLOT(startReadFileFromSocket()) ); |
1559 | connect( mSocket, SIGNAL(delayedCloseFinished ()), this, SLOT(deleteSocket()) ); | 1593 | connect( mSocket, SIGNAL(delayedCloseFinished ()), this, SLOT(deleteSocket()) ); |
1560 | connect( mSocket, SIGNAL(connected ()), this, SLOT(sendFileRequest() )); | 1594 | connect( mSocket, SIGNAL(connected ()), this, SLOT(sendFileRequest() )); |
1561 | } | 1595 | } |
1562 | mFileString = ""; | 1596 | mFileString = ""; |
1563 | mFileName = fn; | 1597 | mFileName = fn; |
1564 | mFirst = true; | 1598 | mFirst = true; |
1565 | if ( tlw ) | 1599 | if ( tlw ) |
1566 | tlw->setCaption( i18n("Trying to connect to remote...") ); | 1600 | tlw->setCaption( i18n("Trying to connect to remote...") ); |
1567 | mConnectCount = 30;mConnectMax = 30; | 1601 | mConnectCount = 30;mConnectMax = 30; |
1568 | mTimerSocket->start( 1000, true ); | 1602 | mTimerSocket->start( 1000, true ); |
1569 | mSocket->connectToHost( mHost, mPort ); | 1603 | mSocket->connectToHost( mHost, mPort ); |
1570 | qDebug("KSS: Waiting for connection"); | 1604 | qDebug("KCS: Waiting for connection"); |
1571 | } | 1605 | } |
1572 | void KCommandSocket::updateConnectDialog() | 1606 | void KCommandSocket::updateConnectDialog() |
1573 | { | 1607 | { |
1574 | 1608 | ||
1575 | if ( mConnectCount == mConnectMax ) { | 1609 | if ( mConnectCount == mConnectMax ) { |
1576 | //qDebug("MAXX %d", mConnectMax); | 1610 | qDebug("MAXX %d", mConnectMax); |
1577 | mConnectProgress.setTotalSteps ( 30 ); | 1611 | mConnectProgress.setTotalSteps ( 30 ); |
1578 | mConnectProgress.show(); | 1612 | mConnectProgress.show(); |
1579 | mConnectProgress.setLabelText( i18n("Trying to connect to remote...") ); | 1613 | mConnectProgress.setLabelText( i18n("Trying to connect to remote...") ); |
1580 | } | 1614 | } |
1581 | //qDebug("updateConnectDialog() %d", mConnectCount); | 1615 | qDebug("updateConnectDialog() %d", mConnectCount); |
1582 | mConnectProgress.raise(); | 1616 | mConnectProgress.raise(); |
1583 | mConnectProgress.setProgress( (mConnectMax - mConnectCount)%30 ); | 1617 | mConnectProgress.setProgress( (mConnectMax - mConnectCount)%30 ); |
1584 | --mConnectCount; | 1618 | --mConnectCount; |
1585 | if ( mConnectCount > 0 ) | 1619 | if ( mConnectCount > 0 ) |
1586 | mTimerSocket->start( 1000, true ); | 1620 | mTimerSocket->start( 1000, true ); |
1587 | else | 1621 | else |
1588 | deleteSocket(); | 1622 | deleteSocket(); |
1589 | 1623 | ||
1590 | } | 1624 | } |
1591 | void KCommandSocket::writeFile( QString fileName ) | 1625 | void KCommandSocket::writeFile( QString fileName ) |
1592 | { | 1626 | { |
1593 | if ( !mSocket ) { | 1627 | if ( !mSocket ) { |
1594 | mSocket = new QSocket( this ); | 1628 | mSocket = new QSocket( this ); |
1595 | connect( mSocket, SIGNAL(delayedCloseFinished ()), this, SLOT(deleteSocket()) ); | 1629 | connect( mSocket, SIGNAL(delayedCloseFinished ()), this, SLOT(deleteSocket()) ); |
1596 | connect( mSocket, SIGNAL(connected ()), this, SLOT(writeFileToSocket()) ); | 1630 | connect( mSocket, SIGNAL(connected ()), this, SLOT(writeFileToSocket()) ); |
1597 | } | 1631 | } |
1598 | mFileName = fileName ; | 1632 | mFileName = fileName ; |
1599 | mConnectCount = 30;mConnectMax = 30; | 1633 | mConnectCount = 30;mConnectMax = 30; |
1600 | mTimerSocket->start( 1000, true ); | 1634 | mTimerSocket->start( 1000, true ); |
1601 | mSocket->connectToHost( mHost, mPort ); | 1635 | mSocket->connectToHost( mHost, mPort ); |
1602 | } | 1636 | } |
1603 | void KCommandSocket::writeFileToSocket() | 1637 | void KCommandSocket::writeFileToSocket() |
1604 | { | 1638 | { |
1605 | mTimerSocket->stop(); | 1639 | mTimerSocket->stop(); |
1606 | QFile file2( mFileName ); | 1640 | QFile file2( mFileName ); |
1607 | if (!file2.open( IO_ReadOnly ) ) { | 1641 | if (!file2.open( IO_ReadOnly ) ) { |
1608 | mConnectProgress.hide(); | 1642 | mConnectProgress.hide(); |
1609 | mConnectCount = -1; | 1643 | mConnectCount = -1; |
1610 | mRetVal= errorW; | 1644 | mRetVal= errorW; |
1611 | mSocket->close(); | 1645 | mSocket->close(); |
1612 | if ( mSocket->state() == QSocket::Idle ) | 1646 | if ( mSocket->state() == QSocket::Idle ) |
1613 | QTimer::singleShot( 10, this , SLOT ( deleteSocket())); | 1647 | QTimer::singleShot( 10, this , SLOT ( deleteSocket())); |
1614 | return ; | 1648 | return ; |
1615 | } | 1649 | } |
1616 | mConnectProgress.setTotalSteps ( file2.size() ); | 1650 | mConnectProgress.setTotalSteps ( file2.size() ); |
1617 | mConnectProgress.show(); | 1651 | mConnectProgress.show(); |
1618 | int count = 0; | 1652 | int count = 0; |
1619 | mConnectProgress.setLabelText( i18n("Sending back synced file...") ); | 1653 | mConnectProgress.setLabelText( i18n("Sending back synced file...") ); |
1620 | mConnectProgress.setProgress( count ); | 1654 | mConnectProgress.setProgress( count ); |
1621 | mConnectProgress.blockSignals( true ); | 1655 | mConnectProgress.blockSignals( true ); |
1622 | QTextStream ts2( &file2 ); | 1656 | QTextStream ts2( &file2 ); |
1623 | ts2.setEncoding( QTextStream::Latin1 ); | 1657 | ts2.setEncoding( QTextStream::Latin1 ); |
1624 | QTextStream os2( mSocket ); | 1658 | QTextStream os2( mSocket ); |
1625 | os2.setEncoding( QTextStream::Latin1 ); | 1659 | os2.setEncoding( QTextStream::Latin1 ); |
1626 | os2 << "PUT " << mPassWord << " " << mRemoteResource << "\r\n\r\n";; | 1660 | os2 << "PUT " << mPassWord << " " << mRemoteResource << "\r\n\r\n";; |
1627 | int byteCount = 0; | 1661 | int byteCount = 0; |
1628 | int byteMax = file2.size()/53; | 1662 | int byteMax = file2.size()/53; |
1629 | while ( ! ts2.atEnd() ) { | 1663 | while ( ! ts2.atEnd() ) { |
diff --git a/libkdepim/ksyncmanager.h b/libkdepim/ksyncmanager.h index 53c611d..604adb8 100644 --- a/libkdepim/ksyncmanager.h +++ b/libkdepim/ksyncmanager.h | |||
@@ -13,102 +13,104 @@ | |||
13 | Library General Public License for more details. | 13 | Library General Public License for more details. |
14 | 14 | ||
15 | You should have received a copy of the GNU Library General Public License | 15 | You should have received a copy of the GNU Library General Public License |
16 | along with this library; see the file COPYING.LIB. If not, write to | 16 | along with this library; see the file COPYING.LIB. If not, write to |
17 | the Free Software Foundation, Inc., 59 Temple Place - Suite 330, | 17 | the Free Software Foundation, Inc., 59 Temple Place - Suite 330, |
18 | Boston, MA 02111-1307, USA. | 18 | Boston, MA 02111-1307, USA. |
19 | 19 | ||
20 | $Id$ | 20 | $Id$ |
21 | */ | 21 | */ |
22 | #ifndef _KSYNCMANAGER_H | 22 | #ifndef _KSYNCMANAGER_H |
23 | #define _KSYNCMANAGER_H | 23 | #define _KSYNCMANAGER_H |
24 | 24 | ||
25 | #include <qobject.h> | 25 | #include <qobject.h> |
26 | #include <qstring.h> | 26 | #include <qstring.h> |
27 | #include <qsocket.h> | 27 | #include <qsocket.h> |
28 | #include <qdatetime.h> | 28 | #include <qdatetime.h> |
29 | #include <qserversocket.h> | 29 | #include <qserversocket.h> |
30 | #include <qtextstream.h> | 30 | #include <qtextstream.h> |
31 | #include <qregexp.h> | 31 | #include <qregexp.h> |
32 | #include <qprogressdialog.h> | 32 | #include <qprogressdialog.h> |
33 | #include <kdialog.h> | 33 | #include <kdialog.h> |
34 | 34 | ||
35 | class QPopupMenu; | 35 | class QPopupMenu; |
36 | class KSyncProfile; | 36 | class KSyncProfile; |
37 | class KPimPrefs; | 37 | class KPimPrefs; |
38 | class QWidget; | 38 | class QWidget; |
39 | class KSyncManager; | 39 | class KSyncManager; |
40 | class KSyncInterface; | 40 | class KSyncInterface; |
41 | class QProgressBar; | 41 | class QProgressBar; |
42 | 42 | ||
43 | 43 | ||
44 | class KServerSocket : public QServerSocket | 44 | class KServerSocket : public QServerSocket |
45 | { | 45 | { |
46 | Q_OBJECT | 46 | Q_OBJECT |
47 | 47 | ||
48 | public: | 48 | public: |
49 | KServerSocket ( QString password, Q_UINT16 port, int backlog = 0, QObject * parent=0, const char * name=0 ); | 49 | KServerSocket ( QString password, Q_UINT16 port, int backlog = 0, QObject * parent=0, const char * name=0 ); |
50 | 50 | ||
51 | void newConnection ( int socket ) ; | 51 | void newConnection ( int socket ) ; |
52 | void setFileName( QString fn ) {mFileName = fn;}; | 52 | void setFileName( QString fn ) {mFileName = fn;}; |
53 | signals: | 53 | signals: |
54 | void file_received( bool ); | 54 | void file_received( bool ); |
55 | void request_file(); | 55 | void request_file(); |
56 | void file_received( bool, const QString &); | 56 | void file_received( bool, const QString &); |
57 | void request_file(const QString &); | 57 | void request_file(const QString &); |
58 | void saveFile(); | 58 | void saveFile(); |
59 | void endConnect(); | 59 | void endConnect(); |
60 | private slots: | 60 | private slots: |
61 | void waitForSocketFinish(); | ||
61 | void discardClient(); | 62 | void discardClient(); |
62 | void deleteSocket(); | 63 | void deleteSocket(); |
63 | void readClient(); | 64 | void readClient(); |
64 | void displayErrorMessage(); | 65 | void displayErrorMessage(); |
65 | void readBackFileFromSocket(); | 66 | void readBackFileFromSocket(); |
66 | private : | 67 | private : |
68 | int mPendingConnect; | ||
67 | QString mResource; | 69 | QString mResource; |
68 | int mErrorMessage; | 70 | int mErrorMessage; |
69 | bool blockRC; | 71 | bool blockRC; |
70 | void send_file(); | 72 | void send_file(); |
71 | void get_file(); | 73 | void get_file(); |
72 | void end_connect(); | 74 | void end_connect(); |
73 | void error_connect( QString ); | 75 | void error_connect( QString ); |
74 | QDialog* mSyncActionDialog; | 76 | QDialog* mSyncActionDialog; |
75 | QSocket* mSocket; | 77 | QSocket* mSocket; |
76 | QString mPassWord; | 78 | QString mPassWord; |
77 | QString mFileName; | 79 | QString mFileName; |
78 | QTime piTime; | 80 | QTime piTime; |
79 | QString piFileString; | 81 | QString piFileString; |
80 | }; | 82 | }; |
81 | 83 | ||
82 | class KCommandSocket : public QObject | 84 | class KCommandSocket : public QObject |
83 | { | 85 | { |
84 | Q_OBJECT | 86 | Q_OBJECT |
85 | public: | 87 | public: |
86 | enum state { successR, errorR, successW, errorW, errorTO, errorPW, errorCA, errorFI, errorUN, errorED,quiet }; | 88 | enum state { successR, errorR, successW, errorW, errorTO, errorPW, errorCA, errorFI, errorUN, errorED,quiet }; |
87 | KCommandSocket (QString remoteResource, QString password, Q_UINT16 port, QString host, QObject * parent=0, QWidget* cap = 0, const char * name=0 ); | 89 | KCommandSocket (QString remoteResource, QString password, Q_UINT16 port, QString host, QObject * parent=0, QWidget* cap = 0, const char * name=0 ); |
88 | void readFile( QString ); | 90 | void readFile( QString ); |
89 | void writeFile( QString ); | 91 | void writeFile( QString ); |
90 | void sendStop(); | 92 | void sendStop(); |
91 | 93 | ||
92 | private slots : | 94 | private slots : |
93 | void sendFileRequest(); | 95 | void sendFileRequest(); |
94 | void updateConnectDialog(); | 96 | void updateConnectDialog(); |
95 | 97 | ||
96 | signals: | 98 | signals: |
97 | void commandFinished( KCommandSocket*, int ); | 99 | void commandFinished( KCommandSocket*, int ); |
98 | private slots: | 100 | private slots: |
99 | void startReadFileFromSocket(); | 101 | void startReadFileFromSocket(); |
100 | void readFileFromSocket(); | 102 | void readFileFromSocket(); |
101 | void deleteSocket(); | 103 | void deleteSocket(); |
102 | void writeFileToSocket(); | 104 | void writeFileToSocket(); |
103 | private : | 105 | private : |
104 | QString mRemoteResource; | 106 | QString mRemoteResource; |
105 | int mConnectCount; | 107 | int mConnectCount; |
106 | int mConnectMax; | 108 | int mConnectMax; |
107 | KProgressDialog mConnectProgress; | 109 | KProgressDialog mConnectProgress; |
108 | QWidget* tlw; | 110 | QWidget* tlw; |
109 | QSocket* mSocket; | 111 | QSocket* mSocket; |
110 | QString mPassWord; | 112 | QString mPassWord; |
111 | Q_UINT16 mPort; | 113 | Q_UINT16 mPort; |
112 | QString mHost; | 114 | QString mHost; |
113 | QString mFileName; | 115 | QString mFileName; |
114 | QTimer* mTimerSocket; | 116 | QTimer* mTimerSocket; |