summaryrefslogtreecommitdiffabout
path: root/libkdepim/ksyncmanager.cpp
Unidiff
Diffstat (limited to 'libkdepim/ksyncmanager.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r--libkdepim/ksyncmanager.cpp8
1 files changed, 7 insertions, 1 deletions
diff --git a/libkdepim/ksyncmanager.cpp b/libkdepim/ksyncmanager.cpp
index f2ee0ab..2a75bfb 100644
--- a/libkdepim/ksyncmanager.cpp
+++ b/libkdepim/ksyncmanager.cpp
@@ -1057,658 +1057,664 @@ void KSyncManager::showProgressBar(int percentage, QString caption, int total)
1057{ 1057{
1058 if (!bar->isVisible()) 1058 if (!bar->isVisible())
1059 { 1059 {
1060 int w = 300; 1060 int w = 300;
1061 if ( QApplication::desktop()->width() < 320 ) 1061 if ( QApplication::desktop()->width() < 320 )
1062 w = 220; 1062 w = 220;
1063 int h = bar->sizeHint().height() ; 1063 int h = bar->sizeHint().height() ;
1064 int dw = QApplication::desktop()->width(); 1064 int dw = QApplication::desktop()->width();
1065 int dh = QApplication::desktop()->height(); 1065 int dh = QApplication::desktop()->height();
1066 bar->setGeometry( (dw-w)/2, (dh - h )/2 ,w,h ); 1066 bar->setGeometry( (dw-w)/2, (dh - h )/2 ,w,h );
1067 bar->setCaption (caption); 1067 bar->setCaption (caption);
1068 bar->setTotalSteps ( total ) ; 1068 bar->setTotalSteps ( total ) ;
1069 bar->show(); 1069 bar->show();
1070 } 1070 }
1071 bar->raise(); 1071 bar->raise();
1072 bar->setProgress( percentage ); 1072 bar->setProgress( percentage );
1073 qApp->processEvents(); 1073 qApp->processEvents();
1074} 1074}
1075 1075
1076void KSyncManager::hideProgressBar() 1076void KSyncManager::hideProgressBar()
1077{ 1077{
1078 bar->hide(); 1078 bar->hide();
1079 qApp->processEvents(); 1079 qApp->processEvents();
1080} 1080}
1081 1081
1082bool KSyncManager::isProgressBarCanceled() 1082bool KSyncManager::isProgressBarCanceled()
1083{ 1083{
1084 return !bar->isVisible(); 1084 return !bar->isVisible();
1085} 1085}
1086 1086
1087QString KSyncManager::syncFileName() 1087QString KSyncManager::syncFileName()
1088{ 1088{
1089 1089
1090 QString fn = "tempfile"; 1090 QString fn = "tempfile";
1091 switch(mTargetApp) 1091 switch(mTargetApp)
1092 { 1092 {
1093 case (KAPI): 1093 case (KAPI):
1094 fn = "tempsyncab.vcf"; 1094 fn = "tempsyncab.vcf";
1095 break; 1095 break;
1096 case (KOPI): 1096 case (KOPI):
1097 fn = "tempsynccal.ics"; 1097 fn = "tempsynccal.ics";
1098 break; 1098 break;
1099 case (PWMPI): 1099 case (PWMPI):
1100 fn = "tempsyncpw.pwm"; 1100 fn = "tempsyncpw.pwm";
1101 break; 1101 break;
1102 default: 1102 default:
1103 break; 1103 break;
1104 } 1104 }
1105#ifdef _WIN32_ 1105#ifdef _WIN32_
1106 return locateLocal( "tmp", fn ); 1106 return locateLocal( "tmp", fn );
1107#else 1107#else
1108 return (QString( "/tmp/" )+ fn ); 1108 return (QString( "/tmp/" )+ fn );
1109#endif 1109#endif
1110} 1110}
1111 1111
1112void KSyncManager::syncPi() 1112void KSyncManager::syncPi()
1113{ 1113{
1114 mIsKapiFile = true; 1114 mIsKapiFile = true;
1115 mPisyncFinished = false; 1115 mPisyncFinished = false;
1116 qApp->processEvents(); 1116 qApp->processEvents();
1117 if ( mAskForPreferences ) 1117 if ( mAskForPreferences )
1118 if ( !edit_pisync_options()) { 1118 if ( !edit_pisync_options()) {
1119 mParent->topLevelWidget()->setCaption( i18n("Syncing aborted. Nothing synced.") ); 1119 mParent->topLevelWidget()->setCaption( i18n("Syncing aborted. Nothing synced.") );
1120 mPisyncFinished = true; 1120 mPisyncFinished = true;
1121 return; 1121 return;
1122 } 1122 }
1123 bool ok; 1123 bool ok;
1124 Q_UINT16 port = mActiveSyncPort.toUInt(&ok); 1124 Q_UINT16 port = mActiveSyncPort.toUInt(&ok);
1125 if ( ! ok ) { 1125 if ( ! ok ) {
1126 mParent->topLevelWidget()->setCaption( i18n("Sorry, no valid port.Syncing cancelled.") ); 1126 mParent->topLevelWidget()->setCaption( i18n("Sorry, no valid port.Syncing cancelled.") );
1127 mPisyncFinished = true; 1127 mPisyncFinished = true;
1128 return; 1128 return;
1129 } 1129 }
1130 KCommandSocket* commandSocket = new KCommandSocket( mPassWordPiSync, port, mActiveSyncIP, this, mParent->topLevelWidget() ); 1130 KCommandSocket* commandSocket = new KCommandSocket( mPassWordPiSync, port, mActiveSyncIP, this, mParent->topLevelWidget() );
1131 connect( commandSocket, SIGNAL(commandFinished( KCommandSocket*, int )), this, SLOT(deleteCommandSocket(KCommandSocket*, int)) ); 1131 connect( commandSocket, SIGNAL(commandFinished( KCommandSocket*, int )), this, SLOT(deleteCommandSocket(KCommandSocket*, int)) );
1132 commandSocket->readFile( syncFileName() ); 1132 commandSocket->readFile( syncFileName() );
1133} 1133}
1134 1134
1135void KSyncManager::deleteCommandSocket(KCommandSocket*s, int state) 1135void KSyncManager::deleteCommandSocket(KCommandSocket*s, int state)
1136{ 1136{
1137 //enum { success, errorW, errorR, quiet }; 1137 //enum { success, errorW, errorR, quiet };
1138 1138
1139 1139
1140 1140
1141 if ( state == KCommandSocket::errorR ||state == KCommandSocket::errorTO ||state == KCommandSocket::errorPW || 1141 if ( state == KCommandSocket::errorR ||state == KCommandSocket::errorTO ||state == KCommandSocket::errorPW ||
1142 state == KCommandSocket::errorCA ||state == KCommandSocket::errorFI ||state == KCommandSocket::errorUN||state == KCommandSocket::errorED ) { 1142 state == KCommandSocket::errorCA ||state == KCommandSocket::errorFI ||state == KCommandSocket::errorUN||state == KCommandSocket::errorED ) {
1143 if ( state == KCommandSocket::errorPW ) 1143 if ( state == KCommandSocket::errorPW )
1144 mParent->topLevelWidget()->setCaption( i18n("Wrong password: Receiving remote file failed.") ); 1144 mParent->topLevelWidget()->setCaption( i18n("Wrong password: Receiving remote file failed.") );
1145 else if ( state == KCommandSocket::errorR ||state == KCommandSocket::errorTO ) 1145 else if ( state == KCommandSocket::errorR ||state == KCommandSocket::errorTO )
1146 mParent->topLevelWidget()->setCaption( i18n("ERROR: Receiving remote file failed.") ); 1146 mParent->topLevelWidget()->setCaption( i18n("ERROR: Receiving remote file failed.") );
1147 else if ( state == KCommandSocket::errorCA ) 1147 else if ( state == KCommandSocket::errorCA )
1148 mParent->topLevelWidget()->setCaption( i18n("Sync cancelled from remote.") ); 1148 mParent->topLevelWidget()->setCaption( i18n("Sync cancelled from remote.") );
1149 else if ( state == KCommandSocket::errorFI ) 1149 else if ( state == KCommandSocket::errorFI )
1150 mParent->topLevelWidget()->setCaption( i18n("File error on remote.") ); 1150 mParent->topLevelWidget()->setCaption( i18n("File error on remote.") );
1151 else if ( state == KCommandSocket::errorED ) 1151 else if ( state == KCommandSocket::errorED )
1152 mParent->topLevelWidget()->setCaption( i18n("Please close error dialog on remote.") ); 1152 mParent->topLevelWidget()->setCaption( i18n("Please close error dialog on remote.") );
1153 else if ( state == KCommandSocket::errorUN ) 1153 else if ( state == KCommandSocket::errorUN )
1154 mParent->topLevelWidget()->setCaption( i18n("Unknown error on remote.") ); 1154 mParent->topLevelWidget()->setCaption( i18n("Unknown error on remote.") );
1155 delete s; 1155 delete s;
1156 if ( state == KCommandSocket::errorR ) { 1156 if ( state == KCommandSocket::errorR ) {
1157 KCommandSocket* commandSocket = new KCommandSocket( mPassWordPiSync, mActiveSyncPort.toUInt(), mActiveSyncIP, this, mParent->topLevelWidget()); 1157 KCommandSocket* commandSocket = new KCommandSocket( mPassWordPiSync, mActiveSyncPort.toUInt(), mActiveSyncIP, this, mParent->topLevelWidget());
1158 connect( commandSocket, SIGNAL(commandFinished( KCommandSocket*, int)), this, SLOT(deleteCommandSocket(KCommandSocket*, int )) ); 1158 connect( commandSocket, SIGNAL(commandFinished( KCommandSocket*, int)), this, SLOT(deleteCommandSocket(KCommandSocket*, int )) );
1159 commandSocket->sendStop(); 1159 commandSocket->sendStop();
1160 } 1160 }
1161 mPisyncFinished = true; 1161 mPisyncFinished = true;
1162 return; 1162 return;
1163 1163
1164 } else if ( state == KCommandSocket::errorW ) { 1164 } else if ( state == KCommandSocket::errorW ) {
1165 mParent->topLevelWidget()->setCaption( i18n("ERROR:Writing back file failed.") ); 1165 mParent->topLevelWidget()->setCaption( i18n("ERROR:Writing back file failed.") );
1166 mPisyncFinished = true; 1166 mPisyncFinished = true;
1167 1167
1168 } else if ( state == KCommandSocket::successR ) { 1168 } else if ( state == KCommandSocket::successR ) {
1169 QTimer::singleShot( 1, this , SLOT ( readFileFromSocket())); 1169 QTimer::singleShot( 1, this , SLOT ( readFileFromSocket()));
1170 1170
1171 } else if ( state == KCommandSocket::successW ) { 1171 } else if ( state == KCommandSocket::successW ) {
1172 mParent->topLevelWidget()->setCaption( i18n("Pi-Sync successful!") ); 1172 mParent->topLevelWidget()->setCaption( i18n("Pi-Sync successful!") );
1173 mPisyncFinished = true; 1173 mPisyncFinished = true;
1174 } else if ( state == KCommandSocket::quiet ){ 1174 } else if ( state == KCommandSocket::quiet ){
1175 qDebug("KSS: quiet "); 1175 qDebug("KSS: quiet ");
1176 mPisyncFinished = true; 1176 mPisyncFinished = true;
1177 } else { 1177 } else {
1178 qDebug("KSS: Error: unknown state: %d ", state); 1178 qDebug("KSS: Error: unknown state: %d ", state);
1179 mPisyncFinished = true; 1179 mPisyncFinished = true;
1180 } 1180 }
1181 1181
1182 delete s; 1182 delete s;
1183} 1183}
1184 1184
1185void KSyncManager::readFileFromSocket() 1185void KSyncManager::readFileFromSocket()
1186{ 1186{
1187 QString fileName = syncFileName(); 1187 QString fileName = syncFileName();
1188 bool syncOK = true; 1188 bool syncOK = true;
1189 mParent->topLevelWidget()->setCaption( i18n("Remote file saved to temp file.") ); 1189 mParent->topLevelWidget()->setCaption( i18n("Remote file saved to temp file.") );
1190 if ( ! syncWithFile( fileName , true ) ) { 1190 if ( ! syncWithFile( fileName , true ) ) {
1191 mParent->topLevelWidget()->setCaption( i18n("Syncing failed.") ); 1191 mParent->topLevelWidget()->setCaption( i18n("Syncing failed.") );
1192 syncOK = false; 1192 syncOK = false;
1193 } 1193 }
1194 KCommandSocket* commandSocket = new KCommandSocket( mPassWordPiSync, mActiveSyncPort.toUInt(), mActiveSyncIP, this, mParent->topLevelWidget() ); 1194 KCommandSocket* commandSocket = new KCommandSocket( mPassWordPiSync, mActiveSyncPort.toUInt(), mActiveSyncIP, this, mParent->topLevelWidget() );
1195 connect( commandSocket, SIGNAL(commandFinished( KCommandSocket*, int)), this, SLOT(deleteCommandSocket(KCommandSocket*, int )) ); 1195 connect( commandSocket, SIGNAL(commandFinished( KCommandSocket*, int)), this, SLOT(deleteCommandSocket(KCommandSocket*, int )) );
1196 if ( mWriteBackFile && syncOK ) { 1196 if ( mWriteBackFile && syncOK ) {
1197 mParent->topLevelWidget()->setCaption( i18n("Sending back file ...") ); 1197 mParent->topLevelWidget()->setCaption( i18n("Sending back file ...") );
1198 commandSocket->writeFile( fileName ); 1198 commandSocket->writeFile( fileName );
1199 } 1199 }
1200 else { 1200 else {
1201 commandSocket->sendStop(); 1201 commandSocket->sendStop();
1202 if ( syncOK ) 1202 if ( syncOK )
1203 mParent->topLevelWidget()->setCaption( i18n("Pi-Sync succesful!") ); 1203 mParent->topLevelWidget()->setCaption( i18n("Pi-Sync succesful!") );
1204 mPisyncFinished = true; 1204 mPisyncFinished = true;
1205 } 1205 }
1206} 1206}
1207 1207
1208KServerSocket:: KServerSocket ( QString pw, Q_UINT16 port, int backlog, QObject * parent, const char * name ) : QServerSocket( port, backlog, parent, name ) 1208KServerSocket:: KServerSocket ( QString pw, Q_UINT16 port, int backlog, QObject * parent, const char * name ) : QServerSocket( port, backlog, parent, name )
1209{ 1209{
1210 mPassWord = pw; 1210 mPassWord = pw;
1211 mSocket = 0; 1211 mSocket = 0;
1212 mSyncActionDialog = 0; 1212 mSyncActionDialog = 0;
1213 blockRC = false; 1213 blockRC = false;
1214 mErrorMessage = 0; 1214 mErrorMessage = 0;
1215} 1215}
1216 1216
1217void KServerSocket::newConnection ( int socket ) 1217void KServerSocket::newConnection ( int socket )
1218{ 1218{
1219 // qDebug("KServerSocket:New connection %d ", socket); 1219 // qDebug("KServerSocket:New connection %d ", socket);
1220 if ( mSocket ) { 1220 if ( mSocket ) {
1221 qDebug("KSS::newConnection Socket deleted! "); 1221 qDebug("KSS::newConnection Socket deleted! ");
1222 delete mSocket; 1222 delete mSocket;
1223 mSocket = 0; 1223 mSocket = 0;
1224 } 1224 }
1225 mSocket = new QSocket( this ); 1225 mSocket = new QSocket( this );
1226 connect( mSocket , SIGNAL(readyRead()), this, SLOT(readClient()) ); 1226 connect( mSocket , SIGNAL(readyRead()), this, SLOT(readClient()) );
1227 connect( mSocket , SIGNAL(delayedCloseFinished()), this, SLOT(discardClient()) ); 1227 connect( mSocket , SIGNAL(delayedCloseFinished()), this, SLOT(discardClient()) );
1228 mSocket->setSocket( socket ); 1228 mSocket->setSocket( socket );
1229} 1229}
1230 1230
1231void KServerSocket::discardClient() 1231void KServerSocket::discardClient()
1232{ 1232{
1233 QTimer::singleShot( 10, this , SLOT ( deleteSocket())); 1233 QTimer::singleShot( 10, this , SLOT ( deleteSocket()));
1234} 1234}
1235void KServerSocket::deleteSocket() 1235void KServerSocket::deleteSocket()
1236{ 1236{
1237 qDebug("KSS::deleteSocket"); 1237 qDebug("KSS::deleteSocket");
1238 if ( mSocket ) { 1238 if ( mSocket ) {
1239 delete mSocket; 1239 delete mSocket;
1240 mSocket = 0; 1240 mSocket = 0;
1241 } 1241 }
1242 if ( mErrorMessage ) 1242 if ( mErrorMessage )
1243 QTimer::singleShot( 10, this , SLOT ( displayErrorMessage())); 1243 QTimer::singleShot( 10, this , SLOT ( displayErrorMessage()));
1244} 1244}
1245void KServerSocket::readClient() 1245void KServerSocket::readClient()
1246{ 1246{
1247 if ( blockRC ) 1247 if ( blockRC )
1248 return; 1248 return;
1249 if ( mSocket == 0 ) { 1249 if ( mSocket == 0 ) {
1250 qDebug("ERROR::KSS::readClient(): mSocket == 0 "); 1250 qDebug("ERROR::KSS::readClient(): mSocket == 0 ");
1251 return; 1251 return;
1252 } 1252 }
1253 if ( mErrorMessage ) { 1253 if ( mErrorMessage ) {
1254 mErrorMessage = 999; 1254 mErrorMessage = 999;
1255 error_connect("ERROR_ED\r\n\r\n"); 1255 error_connect("ERROR_ED\r\n\r\n");
1256 return; 1256 return;
1257 } 1257 }
1258 mErrorMessage = 0; 1258 mErrorMessage = 0;
1259 //qDebug("KServerSocket::readClient()"); 1259 //qDebug("KServerSocket::readClient()");
1260 if ( mSocket->canReadLine() ) { 1260 if ( mSocket->canReadLine() ) {
1261 QString line = mSocket->readLine(); 1261 QString line = mSocket->readLine();
1262 //qDebug("KServerSocket readline: %s ", line.latin1()); 1262 //qDebug("KServerSocket readline: %s ", line.latin1());
1263 QStringList tokens = QStringList::split( QRegExp("[ \r\n][ \r\n]*"), line ); 1263 QStringList tokens = QStringList::split( QRegExp("[ \r\n][ \r\n]*"), line );
1264 if ( tokens[0] == "GET" ) { 1264 if ( tokens[0] == "GET" ) {
1265 if ( tokens[1] == mPassWord ) { 1265 if ( tokens[1] == mPassWord ) {
1266 //emit sendFile( mSocket ); 1266 //emit sendFile( mSocket );
1267 bool ok = false; 1267 bool ok = false;
1268 QDateTime dt = KGlobal::locale()->readDateTime( tokens[2], KLocale::ISODate, &ok); 1268 QDateTime dt = KGlobal::locale()->readDateTime( tokens[2], KLocale::ISODate, &ok);
1269 if ( ok ) { 1269 if ( ok ) {
1270 KSyncManager::mRequestedSyncEvent = dt; 1270 KSyncManager::mRequestedSyncEvent = dt;
1271 } 1271 }
1272 else 1272 else
1273 KSyncManager::mRequestedSyncEvent = QDateTime(); 1273 KSyncManager::mRequestedSyncEvent = QDateTime();
1274 send_file(); 1274 send_file();
1275 } 1275 }
1276 else { 1276 else {
1277 mErrorMessage = 1; 1277 mErrorMessage = 1;
1278 error_connect("ERROR_PW\r\n\r\n"); 1278 error_connect("ERROR_PW\r\n\r\n");
1279 } 1279 }
1280 } 1280 }
1281 if ( tokens[0] == "PUT" ) { 1281 if ( tokens[0] == "PUT" ) {
1282 if ( tokens[1] == mPassWord ) { 1282 if ( tokens[1] == mPassWord ) {
1283 //emit getFile( mSocket ); 1283 //emit getFile( mSocket );
1284 blockRC = true; 1284 blockRC = true;
1285 get_file(); 1285 get_file();
1286 } 1286 }
1287 else { 1287 else {
1288 mErrorMessage = 2; 1288 mErrorMessage = 2;
1289 error_connect("ERROR_PW\r\n\r\n"); 1289 error_connect("ERROR_PW\r\n\r\n");
1290 end_connect(); 1290 end_connect();
1291 } 1291 }
1292 } 1292 }
1293 if ( tokens[0] == "STOP" ) { 1293 if ( tokens[0] == "STOP" ) {
1294 //emit endConnect(); 1294 //emit endConnect();
1295 end_connect(); 1295 end_connect();
1296 } 1296 }
1297 } 1297 }
1298} 1298}
1299void KServerSocket::displayErrorMessage() 1299void KServerSocket::displayErrorMessage()
1300{ 1300{
1301 if ( mErrorMessage == 1 ) { 1301 if ( mErrorMessage == 1 ) {
1302 KMessageBox::error( 0, i18n("Got send file request\nwith invalid password"), i18n("Pi-Sync Error")); 1302 KMessageBox::error( 0, i18n("Got send file request\nwith invalid password"), i18n("Pi-Sync Error"));
1303 mErrorMessage = 0; 1303 mErrorMessage = 0;
1304 } 1304 }
1305 else if ( mErrorMessage == 2 ) { 1305 else if ( mErrorMessage == 2 ) {
1306 KMessageBox::error( 0, i18n("Got receive file request\nwith invalid password"), i18n("Pi-Sync Error")); 1306 KMessageBox::error( 0, i18n("Got receive file request\nwith invalid password"), i18n("Pi-Sync Error"));
1307 mErrorMessage = 0; 1307 mErrorMessage = 0;
1308 } 1308 }
1309} 1309}
1310void KServerSocket::error_connect( QString errmess ) 1310void KServerSocket::error_connect( QString errmess )
1311{ 1311{
1312 QTextStream os( mSocket ); 1312 QTextStream os( mSocket );
1313 os.setEncoding( QTextStream::Latin1 ); 1313 os.setEncoding( QTextStream::Latin1 );
1314 os << errmess ; 1314 os << errmess ;
1315 mSocket->close(); 1315 mSocket->close();
1316 if ( mSocket->state() == QSocket::Idle ) { 1316 if ( mSocket->state() == QSocket::Idle ) {
1317 QTimer::singleShot( 0, this , SLOT ( discardClient())); 1317 QTimer::singleShot( 0, this , SLOT ( discardClient()));
1318 } 1318 }
1319} 1319}
1320void KServerSocket::end_connect() 1320void KServerSocket::end_connect()
1321{ 1321{
1322 delete mSyncActionDialog; 1322 delete mSyncActionDialog;
1323 mSyncActionDialog = 0; 1323 mSyncActionDialog = 0;
1324} 1324}
1325void KServerSocket::send_file() 1325void KServerSocket::send_file()
1326{ 1326{
1327 //qDebug("MainWindow::sendFile(QSocket* s) "); 1327 //qDebug("MainWindow::sendFile(QSocket* s) ");
1328 if ( mSyncActionDialog ) 1328 if ( mSyncActionDialog )
1329 delete mSyncActionDialog; 1329 delete mSyncActionDialog;
1330 mSyncActionDialog = new QDialog ( 0, "input-dialog", true ); 1330 mSyncActionDialog = new QDialog ( 0, "input-dialog", true );
1331 mSyncActionDialog->setCaption(i18n("Received sync request")); 1331 mSyncActionDialog->setCaption(i18n("Received sync request"));
1332 QLabel* label = new QLabel( i18n("Synchronizing from remote ...\n\nDo not use this application!\n\nIf syncing fails\nyou can close this dialog."), mSyncActionDialog ); 1332 QLabel* label = new QLabel( i18n("Synchronizing from remote ...\n\nDo not use this application!\n\nIf syncing fails\nyou can close this dialog."), mSyncActionDialog );
1333 label->setAlignment ( Qt::AlignHCenter ); 1333 label->setAlignment ( Qt::AlignHCenter );
1334 QVBoxLayout* lay = new QVBoxLayout( mSyncActionDialog ); 1334 QVBoxLayout* lay = new QVBoxLayout( mSyncActionDialog );
1335 lay->addWidget( label); 1335 lay->addWidget( label);
1336 lay->setMargin(7); 1336 lay->setMargin(7);
1337 lay->setSpacing(7); 1337 lay->setSpacing(7);
1338 if ( KSyncManager::mRequestedSyncEvent.isValid() ) { 1338 if ( KSyncManager::mRequestedSyncEvent.isValid() ) {
1339 int secs = QDateTime::currentDateTime().secsTo( KSyncManager::mRequestedSyncEvent ); 1339 int secs = QDateTime::currentDateTime().secsTo( KSyncManager::mRequestedSyncEvent );
1340 //secs = 333; 1340 //secs = 333;
1341 if ( secs < 0 ) 1341 if ( secs < 0 )
1342 secs = secs * (-1); 1342 secs = secs * (-1);
1343 if ( secs > 30 ) 1343 if ( secs > 30 )
1344 //if ( true ) 1344 //if ( true )
1345 { 1345 {
1346 QString warning = i18n("Clock skew of\nsyncing devices\nis %1 seconds!").arg( secs ); 1346 QString warning = i18n("Clock skew of\nsyncing devices\nis %1 seconds!").arg( secs );
1347 QLabel* label = new QLabel( warning, mSyncActionDialog ); 1347 QLabel* label = new QLabel( warning, mSyncActionDialog );
1348 label->setAlignment ( Qt::AlignHCenter ); 1348 label->setAlignment ( Qt::AlignHCenter );
1349 lay->addWidget( label); 1349 lay->addWidget( label);
1350 if ( secs > 180 ) 1350 if ( secs > 180 )
1351 { 1351 {
1352 if ( secs > 300 ) { 1352 if ( secs > 300 ) {
1353 if ( KMessageBox::Cancel == KMessageBox::warningContinueCancel(0, i18n("The clocks of the syncing\ndevices have a difference\nof more than 5 minutes.\nPlease adjust your clocks.\nYou may get wrong syncing results!\nPlease confirm synchronization!"), i18n("High clock skew!"),i18n("Synchronize!"))) { 1353 if ( KMessageBox::Cancel == KMessageBox::warningContinueCancel(0, i18n("The clocks of the syncing\ndevices have a difference\nof more than 5 minutes.\nPlease adjust your clocks.\nYou may get wrong syncing results!\nPlease confirm synchronization!"), i18n("High clock skew!"),i18n("Synchronize!"))) {
1354 qDebug("KSS::Sync cancelled ,cs"); 1354 qDebug("KSS::Sync cancelled ,cs");
1355 mErrorMessage = 0; 1355 mErrorMessage = 0;
1356 end_connect(); 1356 end_connect();
1357 error_connect("ERROR_CA\r\n\r\n"); 1357 error_connect("ERROR_CA\r\n\r\n");
1358 return ; 1358 return ;
1359 } 1359 }
1360 } 1360 }
1361 QFont f = label->font(); 1361 QFont f = label->font();
1362 f.setPointSize ( f.pointSize() *2 ); 1362 f.setPointSize ( f.pointSize() *2 );
1363 f. setBold (true ); 1363 f. setBold (true );
1364 QLabel* label = new QLabel( warning, mSyncActionDialog ); 1364 QLabel* label = new QLabel( warning, mSyncActionDialog );
1365 label->setFont( f ); 1365 label->setFont( f );
1366 warning = i18n("ADJUST\nYOUR\nCLOCKS!"); 1366 warning = i18n("ADJUST\nYOUR\nCLOCKS!");
1367 label->setText( warning ); 1367 label->setText( warning );
1368 label->setAlignment ( Qt::AlignHCenter ); 1368 label->setAlignment ( Qt::AlignHCenter );
1369 lay->addWidget( label); 1369 lay->addWidget( label);
1370 mSyncActionDialog->setFixedSize( 230, 300); 1370 mSyncActionDialog->setFixedSize( 230, 300);
1371 } else { 1371 } else {
1372 mSyncActionDialog->setFixedSize( 230, 200); 1372 mSyncActionDialog->setFixedSize( 230, 200);
1373 } 1373 }
1374 } else { 1374 } else {
1375 mSyncActionDialog->setFixedSize( 230, 120); 1375 mSyncActionDialog->setFixedSize( 230, 120);
1376 } 1376 }
1377 } else 1377 } else
1378 mSyncActionDialog->setFixedSize( 230, 120); 1378 mSyncActionDialog->setFixedSize( 230, 120);
1379 mSyncActionDialog->show(); 1379 mSyncActionDialog->show();
1380 mSyncActionDialog->raise(); 1380 mSyncActionDialog->raise();
1381 emit request_file(); 1381 emit request_file();
1382 qApp->processEvents(); 1382 qApp->processEvents();
1383 QString fileName = mFileName; 1383 QString fileName = mFileName;
1384 QFile file( fileName ); 1384 QFile file( fileName );
1385 if (!file.open( IO_ReadOnly ) ) { 1385 if (!file.open( IO_ReadOnly ) ) {
1386 mErrorMessage = 0; 1386 mErrorMessage = 0;
1387 end_connect(); 1387 end_connect();
1388 error_connect("ERROR_FI\r\n\r\n"); 1388 error_connect("ERROR_FI\r\n\r\n");
1389 return ; 1389 return ;
1390 } 1390 }
1391 mSyncActionDialog->setCaption( i18n("Sending file...") ); 1391 mSyncActionDialog->setCaption( i18n("Sending file...") );
1392 QTextStream ts( &file ); 1392 QTextStream ts( &file );
1393 ts.setEncoding( QTextStream::Latin1 ); 1393 ts.setEncoding( QTextStream::Latin1 );
1394 1394
1395 QTextStream os( mSocket ); 1395 QTextStream os( mSocket );
1396 os.setEncoding( QTextStream::Latin1 ); 1396 os.setEncoding( QTextStream::Latin1 );
1397 while ( ! ts.atEnd() ) { 1397 while ( ! ts.atEnd() ) {
1398 os << ts.readLine() << "\r\n"; 1398 os << ts.readLine() << "\r\n";
1399 } 1399 }
1400 os << "\r\n"; 1400 os << "\r\n";
1401 //os << ts.read(); 1401 //os << ts.read();
1402 file.close(); 1402 file.close();
1403 mSyncActionDialog->setCaption( i18n("Waiting for synced file...") ); 1403 mSyncActionDialog->setCaption( i18n("Waiting for synced file...") );
1404 mSocket->close(); 1404 mSocket->close();
1405 if ( mSocket->state() == QSocket::Idle ) 1405 if ( mSocket->state() == QSocket::Idle )
1406 QTimer::singleShot( 10, this , SLOT ( discardClient())); 1406 QTimer::singleShot( 10, this , SLOT ( discardClient()));
1407} 1407}
1408void KServerSocket::get_file() 1408void KServerSocket::get_file()
1409{ 1409{
1410 mSyncActionDialog->setCaption( i18n("Receiving synced file...") ); 1410 mSyncActionDialog->setCaption( i18n("Receiving synced file...") );
1411 1411
1412 piTime.start(); 1412 piTime.start();
1413 piFileString = ""; 1413 piFileString = "";
1414 QTimer::singleShot( 1, this , SLOT (readBackFileFromSocket( ) )); 1414 QTimer::singleShot( 1, this , SLOT (readBackFileFromSocket( ) ));
1415} 1415}
1416 1416
1417 1417
1418void KServerSocket::readBackFileFromSocket() 1418void KServerSocket::readBackFileFromSocket()
1419{ 1419{
1420 //qDebug("readBackFileFromSocket() %d ", piTime.elapsed ()); 1420 //qDebug("readBackFileFromSocket() %d ", piTime.elapsed ());
1421 while ( mSocket->canReadLine () ) { 1421 while ( mSocket->canReadLine () ) {
1422 piTime.restart(); 1422 piTime.restart();
1423 QString line = mSocket->readLine (); 1423 QString line = mSocket->readLine ();
1424 piFileString += line; 1424 piFileString += line;
1425 //qDebug("readline: %s ", line.latin1()); 1425 //qDebug("readline: %s ", line.latin1());
1426 mSyncActionDialog->setCaption( i18n("Received %1 bytes").arg( piFileString.length() ) ); 1426 mSyncActionDialog->setCaption( i18n("Received %1 bytes").arg( piFileString.length() ) );
1427 1427
1428 } 1428 }
1429 if ( piTime.elapsed () < 3000 ) { 1429 if ( piTime.elapsed () < 3000 ) {
1430 // wait for more 1430 // wait for more
1431 //qDebug("waitformore "); 1431 //qDebug("waitformore ");
1432 QTimer::singleShot( 100, this , SLOT (readBackFileFromSocket( ) )); 1432 QTimer::singleShot( 100, this , SLOT (readBackFileFromSocket( ) ));
1433 return; 1433 return;
1434 } 1434 }
1435 QString fileName = mFileName; 1435 QString fileName = mFileName;
1436 QFile file ( fileName ); 1436 QFile file ( fileName );
1437 if (!file.open( IO_WriteOnly ) ) { 1437 if (!file.open( IO_WriteOnly ) ) {
1438 delete mSyncActionDialog; 1438 delete mSyncActionDialog;
1439 mSyncActionDialog = 0; 1439 mSyncActionDialog = 0;
1440 qDebug("KSS:Error open read back file "); 1440 qDebug("KSS:Error open read back file ");
1441 piFileString = ""; 1441 piFileString = "";
1442 emit file_received( false ); 1442 emit file_received( false );
1443 blockRC = false; 1443 blockRC = false;
1444 return ; 1444 return ;
1445 1445
1446 } 1446 }
1447 1447
1448 // mView->setLoadedFileVersion(QDateTime::currentDateTime().addSecs( -1)); 1448 // mView->setLoadedFileVersion(QDateTime::currentDateTime().addSecs( -1));
1449 QTextStream ts ( &file ); 1449 QTextStream ts ( &file );
1450 ts.setEncoding( QTextStream::Latin1 ); 1450 ts.setEncoding( QTextStream::Latin1 );
1451 mSyncActionDialog->setCaption( i18n("Writing file to disk...") ); 1451 mSyncActionDialog->setCaption( i18n("Writing file to disk...") );
1452 ts << piFileString; 1452 ts << piFileString;
1453 mSocket->close(); 1453 mSocket->close();
1454 if ( mSocket->state() == QSocket::Idle ) 1454 if ( mSocket->state() == QSocket::Idle )
1455 QTimer::singleShot( 10, this , SLOT ( discardClient())); 1455 QTimer::singleShot( 10, this , SLOT ( discardClient()));
1456 file.close(); 1456 file.close();
1457 piFileString = ""; 1457 piFileString = "";
1458 emit file_received( true ); 1458 emit file_received( true );
1459 delete mSyncActionDialog; 1459 delete mSyncActionDialog;
1460 mSyncActionDialog = 0; 1460 mSyncActionDialog = 0;
1461 blockRC = false; 1461 blockRC = false;
1462 1462
1463} 1463}
1464 1464
1465KCommandSocket::KCommandSocket ( QString password, Q_UINT16 port, QString host, QObject * parent, QWidget * cap, const char * name ): QObject( parent, name ) 1465KCommandSocket::KCommandSocket ( QString password, Q_UINT16 port, QString host, QObject * parent, QWidget * cap, const char * name ): QObject( parent, name )
1466{ 1466{
1467 mPassWord = password; 1467 mPassWord = password;
1468 mSocket = 0; 1468 mSocket = 0;
1469 mFirst = false; 1469 mFirst = false;
1470 mFirstLine = true; 1470 mFirstLine = true;
1471 mPort = port; 1471 mPort = port;
1472 mHost = host; 1472 mHost = host;
1473 tlw = cap; 1473 tlw = cap;
1474 mRetVal = quiet; 1474 mRetVal = quiet;
1475 mTimerSocket = new QTimer ( this ); 1475 mTimerSocket = new QTimer ( this );
1476 connect( mTimerSocket, SIGNAL ( timeout () ), this, SLOT ( updateConnectDialog() ) ); 1476 connect( mTimerSocket, SIGNAL ( timeout () ), this, SLOT ( updateConnectDialog() ) );
1477 mConnectProgress.setCaption( i18n("Pi-Sync") ); 1477 mConnectProgress.setCaption( i18n("Pi-Sync") );
1478 connect( &mConnectProgress, SIGNAL ( cancelled () ), this, SLOT ( deleteSocket() ) ); 1478 connect( &mConnectProgress, SIGNAL ( cancelled () ), this, SLOT ( deleteSocket() ) );
1479 mConnectCount = -1; 1479 mConnectCount = -1;
1480} 1480}
1481void KCommandSocket::sendFileRequest() 1481void KCommandSocket::sendFileRequest()
1482{ 1482{
1483 if ( tlw ) 1483 if ( tlw )
1484 tlw->setCaption( i18n("Connected! Sending request for remote file ...") ); 1484 tlw->setCaption( i18n("Connected! Sending request for remote file ...") );
1485 mConnectProgress.hide(); 1485 mConnectProgress.hide();
1486 mConnectCount = 300;mConnectMax = 300; 1486 mConnectCount = 300;mConnectMax = 300;
1487 mConnectProgress.setCaption( i18n("Pi-Sync: Connected!") ); 1487 mConnectProgress.setCaption( i18n("Pi-Sync: Connected!") );
1488 mTimerSocket->start( 100, true ); 1488 mTimerSocket->start( 100, true );
1489 QTextStream os( mSocket ); 1489 QTextStream os( mSocket );
1490 os.setEncoding( QTextStream::Latin1 ); 1490 os.setEncoding( QTextStream::Latin1 );
1491 1491
1492 QString curDt = " " +KGlobal::locale()->formatDateTime(QDateTime::currentDateTime().addSecs(-1),true, true,KLocale::ISODate ); 1492 QString curDt = " " +KGlobal::locale()->formatDateTime(QDateTime::currentDateTime().addSecs(-1),true, true,KLocale::ISODate );
1493 os << "GET " << mPassWord << curDt <<"\r\n\r\n"; 1493 os << "GET " << mPassWord << curDt <<"\r\n\r\n";
1494} 1494}
1495 1495
1496void KCommandSocket::readFile( QString fn ) 1496void KCommandSocket::readFile( QString fn )
1497{ 1497{
1498 if ( !mSocket ) { 1498 if ( !mSocket ) {
1499 mSocket = new QSocket( this ); 1499 mSocket = new QSocket( this );
1500 connect( mSocket, SIGNAL(readyRead()), this, SLOT(startReadFileFromSocket()) ); 1500 connect( mSocket, SIGNAL(readyRead()), this, SLOT(startReadFileFromSocket()) );
1501 connect( mSocket, SIGNAL(delayedCloseFinished ()), this, SLOT(deleteSocket()) ); 1501 connect( mSocket, SIGNAL(delayedCloseFinished ()), this, SLOT(deleteSocket()) );
1502 connect( mSocket, SIGNAL(connected ()), this, SLOT(sendFileRequest() )); 1502 connect( mSocket, SIGNAL(connected ()), this, SLOT(sendFileRequest() ));
1503 } 1503 }
1504 mFileString = ""; 1504 mFileString = "";
1505 mFileName = fn; 1505 mFileName = fn;
1506 mFirst = true; 1506 mFirst = true;
1507 if ( tlw ) 1507 if ( tlw )
1508 tlw->setCaption( i18n("Trying to connect to remote...") ); 1508 tlw->setCaption( i18n("Trying to connect to remote...") );
1509 mConnectCount = 30;mConnectMax = 30; 1509 mConnectCount = 30;mConnectMax = 30;
1510 mTimerSocket->start( 1000, true ); 1510 mTimerSocket->start( 1000, true );
1511 mSocket->connectToHost( mHost, mPort ); 1511 mSocket->connectToHost( mHost, mPort );
1512 qDebug("KSS: Waiting for connection"); 1512 qDebug("KSS: Waiting for connection");
1513} 1513}
1514void KCommandSocket::updateConnectDialog() 1514void KCommandSocket::updateConnectDialog()
1515{ 1515{
1516 1516
1517 if ( mConnectCount == mConnectMax ) { 1517 if ( mConnectCount == mConnectMax ) {
1518 //qDebug("MAXX %d", mConnectMax); 1518 //qDebug("MAXX %d", mConnectMax);
1519 mConnectProgress.setTotalSteps ( 30 ); 1519 mConnectProgress.setTotalSteps ( 30 );
1520 mConnectProgress.show(); 1520 mConnectProgress.show();
1521 mConnectProgress.setLabelText( i18n("Trying to connect to remote...") ); 1521 mConnectProgress.setLabelText( i18n("Trying to connect to remote...") );
1522 } 1522 }
1523 //qDebug("updateConnectDialog() %d", mConnectCount); 1523 //qDebug("updateConnectDialog() %d", mConnectCount);
1524 mConnectProgress.raise(); 1524 mConnectProgress.raise();
1525 mConnectProgress.setProgress( (mConnectMax - mConnectCount)%30 ); 1525 mConnectProgress.setProgress( (mConnectMax - mConnectCount)%30 );
1526 --mConnectCount; 1526 --mConnectCount;
1527 if ( mConnectCount > 0 ) 1527 if ( mConnectCount > 0 )
1528 mTimerSocket->start( 1000, true ); 1528 mTimerSocket->start( 1000, true );
1529 else 1529 else
1530 deleteSocket(); 1530 deleteSocket();
1531 1531
1532} 1532}
1533void KCommandSocket::writeFile( QString fileName ) 1533void KCommandSocket::writeFile( QString fileName )
1534{ 1534{
1535 if ( !mSocket ) { 1535 if ( !mSocket ) {
1536 mSocket = new QSocket( this ); 1536 mSocket = new QSocket( this );
1537 connect( mSocket, SIGNAL(delayedCloseFinished ()), this, SLOT(deleteSocket()) ); 1537 connect( mSocket, SIGNAL(delayedCloseFinished ()), this, SLOT(deleteSocket()) );
1538 connect( mSocket, SIGNAL(connected ()), this, SLOT(writeFileToSocket()) ); 1538 connect( mSocket, SIGNAL(connected ()), this, SLOT(writeFileToSocket()) );
1539 } 1539 }
1540 mFileName = fileName ; 1540 mFileName = fileName ;
1541 mConnectCount = 30;mConnectMax = 30; 1541 mConnectCount = 30;mConnectMax = 30;
1542 mTimerSocket->start( 1000, true ); 1542 mTimerSocket->start( 1000, true );
1543 mSocket->connectToHost( mHost, mPort ); 1543 mSocket->connectToHost( mHost, mPort );
1544} 1544}
1545void KCommandSocket::writeFileToSocket() 1545void KCommandSocket::writeFileToSocket()
1546{ 1546{
1547 mTimerSocket->stop(); 1547 mTimerSocket->stop();
1548 QFile file2( mFileName ); 1548 QFile file2( mFileName );
1549 if (!file2.open( IO_ReadOnly ) ) { 1549 if (!file2.open( IO_ReadOnly ) ) {
1550 mConnectProgress.hide(); 1550 mConnectProgress.hide();
1551 mConnectCount = -1; 1551 mConnectCount = -1;
1552 mRetVal= errorW; 1552 mRetVal= errorW;
1553 mSocket->close(); 1553 mSocket->close();
1554 if ( mSocket->state() == QSocket::Idle ) 1554 if ( mSocket->state() == QSocket::Idle )
1555 QTimer::singleShot( 10, this , SLOT ( deleteSocket())); 1555 QTimer::singleShot( 10, this , SLOT ( deleteSocket()));
1556 return ; 1556 return ;
1557 } 1557 }
1558 mConnectProgress.setTotalSteps ( file2.size() ); 1558 mConnectProgress.setTotalSteps ( file2.size() );
1559 mConnectProgress.show(); 1559 mConnectProgress.show();
1560 int count = 0; 1560 int count = 0;
1561 mConnectProgress.setLabelText( i18n("Sending back synced file...") ); 1561 mConnectProgress.setLabelText( i18n("Sending back synced file...") );
1562 mConnectProgress.setProgress( count ); 1562 mConnectProgress.setProgress( count );
1563 mConnectProgress.blockSignals( true ); 1563 mConnectProgress.blockSignals( true );
1564 QTextStream ts2( &file2 ); 1564 QTextStream ts2( &file2 );
1565 ts2.setEncoding( QTextStream::Latin1 ); 1565 ts2.setEncoding( QTextStream::Latin1 );
1566 QTextStream os2( mSocket ); 1566 QTextStream os2( mSocket );
1567 os2.setEncoding( QTextStream::Latin1 ); 1567 os2.setEncoding( QTextStream::Latin1 );
1568 os2 << "PUT " << mPassWord << "\r\n\r\n";; 1568 os2 << "PUT " << mPassWord << "\r\n\r\n";;
1569 int byteCount = 0;
1570 int byteMax = file2.size()/53;
1569 while ( ! ts2.atEnd() ) { 1571 while ( ! ts2.atEnd() ) {
1570 qApp->processEvents(); 1572 qApp->processEvents();
1571 mConnectProgress.setProgress( count ); 1573 if ( byteCount > byteMax ) {
1574 byteCount = 0;
1575 mConnectProgress.setProgress( count );
1576 }
1572 QString temp = ts2.readLine(); 1577 QString temp = ts2.readLine();
1573 count += temp.length(); 1578 count += temp.length();
1579 byteCount += temp.length();
1574 os2 << temp << "\r\n"; 1580 os2 << temp << "\r\n";
1575 } 1581 }
1576 file2.close(); 1582 file2.close();
1577 mConnectProgress.hide(); 1583 mConnectProgress.hide();
1578 mConnectCount = -1; 1584 mConnectCount = -1;
1579 os2 << "\r\n"; 1585 os2 << "\r\n";
1580 mRetVal= successW; 1586 mRetVal= successW;
1581 mSocket->close(); 1587 mSocket->close();
1582 if ( mSocket->state() == QSocket::Idle ) 1588 if ( mSocket->state() == QSocket::Idle )
1583 QTimer::singleShot( 10, this , SLOT ( deleteSocket())); 1589 QTimer::singleShot( 10, this , SLOT ( deleteSocket()));
1584 mConnectProgress.blockSignals( false ); 1590 mConnectProgress.blockSignals( false );
1585} 1591}
1586void KCommandSocket::sendStop() 1592void KCommandSocket::sendStop()
1587{ 1593{
1588 if ( !mSocket ) { 1594 if ( !mSocket ) {
1589 mSocket = new QSocket( this ); 1595 mSocket = new QSocket( this );
1590 connect( mSocket, SIGNAL(delayedCloseFinished ()), this, SLOT(deleteSocket()) ); 1596 connect( mSocket, SIGNAL(delayedCloseFinished ()), this, SLOT(deleteSocket()) );
1591 } 1597 }
1592 mSocket->connectToHost( mHost, mPort ); 1598 mSocket->connectToHost( mHost, mPort );
1593 QTextStream os2( mSocket ); 1599 QTextStream os2( mSocket );
1594 os2.setEncoding( QTextStream::Latin1 ); 1600 os2.setEncoding( QTextStream::Latin1 );
1595 os2 << "STOP\r\n\r\n"; 1601 os2 << "STOP\r\n\r\n";
1596 mSocket->close(); 1602 mSocket->close();
1597 if ( mSocket->state() == QSocket::Idle ) 1603 if ( mSocket->state() == QSocket::Idle )
1598 QTimer::singleShot( 10, this , SLOT ( deleteSocket())); 1604 QTimer::singleShot( 10, this , SLOT ( deleteSocket()));
1599} 1605}
1600 1606
1601void KCommandSocket::startReadFileFromSocket() 1607void KCommandSocket::startReadFileFromSocket()
1602{ 1608{
1603 if ( ! mFirst ) 1609 if ( ! mFirst )
1604 return; 1610 return;
1605 mConnectProgress.setLabelText( i18n("Receiving file from remote...") ); 1611 mConnectProgress.setLabelText( i18n("Receiving file from remote...") );
1606 mFirst = false; 1612 mFirst = false;
1607 mFileString = ""; 1613 mFileString = "";
1608 mTime.start(); 1614 mTime.start();
1609 mFirstLine = true; 1615 mFirstLine = true;
1610 QTimer::singleShot( 1, this , SLOT (readFileFromSocket( ) )); 1616 QTimer::singleShot( 1, this , SLOT (readFileFromSocket( ) ));
1611 1617
1612} 1618}
1613void KCommandSocket::readFileFromSocket() 1619void KCommandSocket::readFileFromSocket()
1614{ 1620{
1615 //qDebug("readBackFileFromSocket() %d ", mTime.elapsed ()); 1621 //qDebug("readBackFileFromSocket() %d ", mTime.elapsed ());
1616 while ( mSocket->canReadLine () ) { 1622 while ( mSocket->canReadLine () ) {
1617 mTime.restart(); 1623 mTime.restart();
1618 QString line = mSocket->readLine (); 1624 QString line = mSocket->readLine ();
1619 if ( mFirstLine ) { 1625 if ( mFirstLine ) {
1620 mFirstLine = false; 1626 mFirstLine = false;
1621 if ( line.left( 6 ) == "ERROR_" ) { 1627 if ( line.left( 6 ) == "ERROR_" ) {
1622 mTimerSocket->stop(); 1628 mTimerSocket->stop();
1623 mConnectCount = -1; 1629 mConnectCount = -1;
1624 if ( line.left( 8 ) == "ERROR_PW" ) { 1630 if ( line.left( 8 ) == "ERROR_PW" ) {
1625 mRetVal = errorPW; 1631 mRetVal = errorPW;
1626 deleteSocket(); 1632 deleteSocket();
1627 return ; 1633 return ;
1628 } 1634 }
1629 if ( line.left( 8 ) == "ERROR_CA" ) { 1635 if ( line.left( 8 ) == "ERROR_CA" ) {
1630 mRetVal = errorCA; 1636 mRetVal = errorCA;
1631 deleteSocket(); 1637 deleteSocket();
1632 return ; 1638 return ;
1633 } 1639 }
1634 if ( line.left( 8 ) == "ERROR_FI" ) { 1640 if ( line.left( 8 ) == "ERROR_FI" ) {
1635 mRetVal = errorFI; 1641 mRetVal = errorFI;
1636 deleteSocket(); 1642 deleteSocket();
1637 return ; 1643 return ;
1638 } 1644 }
1639 if ( line.left( 8 ) == "ERROR_ED" ) { 1645 if ( line.left( 8 ) == "ERROR_ED" ) {
1640 mRetVal = errorED; 1646 mRetVal = errorED;
1641 deleteSocket(); 1647 deleteSocket();
1642 return ; 1648 return ;
1643 } 1649 }
1644 mRetVal = errorUN; 1650 mRetVal = errorUN;
1645 deleteSocket(); 1651 deleteSocket();
1646 return ; 1652 return ;
1647 } 1653 }
1648 } 1654 }
1649 mFileString += line; 1655 mFileString += line;
1650 //qDebug("readline: %s ", line.latin1()); 1656 //qDebug("readline: %s ", line.latin1());
1651 } 1657 }
1652 if ( mTime.elapsed () < 3000 ) { 1658 if ( mTime.elapsed () < 3000 ) {
1653 // wait for more 1659 // wait for more
1654 //qDebug("waitformore "); 1660 //qDebug("waitformore ");
1655 QTimer::singleShot( 100, this , SLOT (readFileFromSocket( ) )); 1661 QTimer::singleShot( 100, this , SLOT (readFileFromSocket( ) ));
1656 return; 1662 return;
1657 } 1663 }
1658 mTimerSocket->stop(); 1664 mTimerSocket->stop();
1659 mConnectCount = -1; 1665 mConnectCount = -1;
1660 mConnectProgress.hide(); 1666 mConnectProgress.hide();
1661 QString fileName = mFileName; 1667 QString fileName = mFileName;
1662 QFile file ( fileName ); 1668 QFile file ( fileName );
1663 if (!file.open( IO_WriteOnly ) ) { 1669 if (!file.open( IO_WriteOnly ) ) {
1664 mFileString = ""; 1670 mFileString = "";
1665 mRetVal = errorR; 1671 mRetVal = errorR;
1666 qDebug("KSS:Error open temp sync file for writing: %s",fileName.latin1() ); 1672 qDebug("KSS:Error open temp sync file for writing: %s",fileName.latin1() );
1667 deleteSocket(); 1673 deleteSocket();
1668 return ; 1674 return ;
1669 1675
1670 } 1676 }
1671 // mView->setLoadedFileVersion(QDateTime::currentDateTime().addSecs( -1)); 1677 // mView->setLoadedFileVersion(QDateTime::currentDateTime().addSecs( -1));
1672 QTextStream ts ( &file ); 1678 QTextStream ts ( &file );
1673 ts.setEncoding( QTextStream::Latin1 ); 1679 ts.setEncoding( QTextStream::Latin1 );
1674 ts << mFileString; 1680 ts << mFileString;
1675 file.close(); 1681 file.close();
1676 mFileString = ""; 1682 mFileString = "";
1677 mRetVal = successR; 1683 mRetVal = successR;
1678 mSocket->close(); 1684 mSocket->close();
1679 // if state is not idle, deleteSocket(); is called via 1685 // if state is not idle, deleteSocket(); is called via
1680 // connect( mSocket, SIGNAL(delayedCloseFinished ()), this, SLOT(deleteSocket()) ); 1686 // connect( mSocket, SIGNAL(delayedCloseFinished ()), this, SLOT(deleteSocket()) );
1681 if ( mSocket->state() == QSocket::Idle ) 1687 if ( mSocket->state() == QSocket::Idle )
1682 deleteSocket(); 1688 deleteSocket();
1683} 1689}
1684 1690
1685void KCommandSocket::deleteSocket() 1691void KCommandSocket::deleteSocket()
1686{ 1692{
1687 //qDebug("KCommandSocket::deleteSocket() "); 1693 //qDebug("KCommandSocket::deleteSocket() ");
1688 mConnectProgress.hide(); 1694 mConnectProgress.hide();
1689 1695
1690 if ( mConnectCount >= 0 ) { 1696 if ( mConnectCount >= 0 ) {
1691 mTimerSocket->stop(); 1697 mTimerSocket->stop();
1692 mRetVal = errorTO; 1698 mRetVal = errorTO;
1693 qDebug("KCS::Connection to remote host timed out"); 1699 qDebug("KCS::Connection to remote host timed out");
1694 if ( mSocket ) { 1700 if ( mSocket ) {
1695 mSocket->close(); 1701 mSocket->close();
1696 //if ( mSocket->state() == QSocket::Idle ) 1702 //if ( mSocket->state() == QSocket::Idle )
1697 // deleteSocket(); 1703 // deleteSocket();
1698 delete mSocket; 1704 delete mSocket;
1699 mSocket = 0; 1705 mSocket = 0;
1700 } 1706 }
1701 if ( mConnectCount == 0 ) 1707 if ( mConnectCount == 0 )
1702 KMessageBox::error( 0, i18n("Connection to remote\nhost timed out!\nDid you forgot to enable\nsyncing on remote host?")); 1708 KMessageBox::error( 0, i18n("Connection to remote\nhost timed out!\nDid you forgot to enable\nsyncing on remote host?"));
1703 else if ( tlw ) 1709 else if ( tlw )
1704 tlw->setCaption( i18n("Connection to remote host cancelled!") ); 1710 tlw->setCaption( i18n("Connection to remote host cancelled!") );
1705 emit commandFinished( this, mRetVal ); 1711 emit commandFinished( this, mRetVal );
1706 return; 1712 return;
1707 } 1713 }
1708 //qDebug("KCommandSocket::deleteSocket() %d", mRetVal ); 1714 //qDebug("KCommandSocket::deleteSocket() %d", mRetVal );
1709 if ( mSocket) 1715 if ( mSocket)
1710 delete mSocket; 1716 delete mSocket;
1711 mSocket = 0; 1717 mSocket = 0;
1712 qDebug("commandFinished "); 1718 qDebug("commandFinished ");
1713 emit commandFinished( this, mRetVal ); 1719 emit commandFinished( this, mRetVal );
1714} 1720}