summaryrefslogtreecommitdiffabout
path: root/libkdepim/ksyncmanager.cpp
Unidiff
Diffstat (limited to 'libkdepim/ksyncmanager.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r--libkdepim/ksyncmanager.cpp2
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
@@ -963,510 +963,510 @@ bool KSyncManager::syncExternalApplication(QString resource)
963 963
964 qDebug("Sync extern %s", resource.latin1()); 964 qDebug("Sync extern %s", resource.latin1());
965 965
966 bool syncOK = mImplementation->syncExternal(this, resource); 966 bool syncOK = mImplementation->syncExternal(this, resource);
967 967
968 return syncOK; 968 return syncOK;
969 969
970} 970}
971 971
972void KSyncManager::syncPhone() 972void KSyncManager::syncPhone()
973{ 973{
974 974
975 syncExternalApplication("phone"); 975 syncExternalApplication("phone");
976 976
977} 977}
978 978
979void KSyncManager::showProgressBar(int percentage, QString caption, int total) 979void KSyncManager::showProgressBar(int percentage, QString caption, int total)
980{ 980{
981 if (!bar->isVisible()) 981 if (!bar->isVisible())
982 { 982 {
983 bar->setCaption (caption); 983 bar->setCaption (caption);
984 bar->setTotalSteps ( total ) ; 984 bar->setTotalSteps ( total ) ;
985 985
986 bar->show(); 986 bar->show();
987 } 987 }
988 988
989 bar->setProgress( percentage ); 989 bar->setProgress( percentage );
990} 990}
991 991
992void KSyncManager::hideProgressBar() 992void KSyncManager::hideProgressBar()
993{ 993{
994 bar->hide(); 994 bar->hide();
995} 995}
996 996
997bool KSyncManager::isProgressBarCanceled() 997bool KSyncManager::isProgressBarCanceled()
998{ 998{
999 return !bar->isVisible(); 999 return !bar->isVisible();
1000} 1000}
1001 1001
1002QString KSyncManager::syncFileName() 1002QString KSyncManager::syncFileName()
1003{ 1003{
1004 1004
1005 QString fn = "tempfile"; 1005 QString fn = "tempfile";
1006 switch(mTargetApp) 1006 switch(mTargetApp)
1007 { 1007 {
1008 case (KAPI): 1008 case (KAPI):
1009 fn = "tempsyncab.vcf"; 1009 fn = "tempsyncab.vcf";
1010 break; 1010 break;
1011 case (KOPI): 1011 case (KOPI):
1012 fn = "tempsynccal.ics"; 1012 fn = "tempsynccal.ics";
1013 break; 1013 break;
1014 case (PWMPI): 1014 case (PWMPI):
1015 fn = "tempsyncpw.pwm"; 1015 fn = "tempsyncpw.pwm";
1016 break; 1016 break;
1017 default: 1017 default:
1018 break; 1018 break;
1019 } 1019 }
1020#ifdef _WIN32_ 1020#ifdef _WIN32_
1021 return locateLocal( "tmp", fn ); 1021 return locateLocal( "tmp", fn );
1022#else 1022#else
1023 return (QString( "/tmp/" )+ fn ); 1023 return (QString( "/tmp/" )+ fn );
1024#endif 1024#endif
1025} 1025}
1026 1026
1027void KSyncManager::syncPi() 1027void KSyncManager::syncPi()
1028{ 1028{
1029 mIsKapiFile = true; 1029 mIsKapiFile = true;
1030 mPisyncFinished = false; 1030 mPisyncFinished = false;
1031 qApp->processEvents(); 1031 qApp->processEvents();
1032 if ( mAskForPreferences ) 1032 if ( mAskForPreferences )
1033 if ( !edit_pisync_options()) { 1033 if ( !edit_pisync_options()) {
1034 mParent->topLevelWidget()->setCaption( i18n("Syncing aborted. Nothing synced.") ); 1034 mParent->topLevelWidget()->setCaption( i18n("Syncing aborted. Nothing synced.") );
1035 return; 1035 return;
1036 } 1036 }
1037 bool ok; 1037 bool ok;
1038 Q_UINT16 port = mActiveSyncPort.toUInt(&ok); 1038 Q_UINT16 port = mActiveSyncPort.toUInt(&ok);
1039 if ( ! ok ) { 1039 if ( ! ok ) {
1040 mParent->topLevelWidget()->setCaption( i18n("Sorry, no valid port.Syncing cancelled.") ); 1040 mParent->topLevelWidget()->setCaption( i18n("Sorry, no valid port.Syncing cancelled.") );
1041 return; 1041 return;
1042 } 1042 }
1043 KCommandSocket* commandSocket = new KCommandSocket( mPassWordPiSync, port, mActiveSyncIP, this ); 1043 KCommandSocket* commandSocket = new KCommandSocket( mPassWordPiSync, port, mActiveSyncIP, this );
1044 connect( commandSocket, SIGNAL(commandFinished( KCommandSocket*, int )), this, SLOT(deleteCommandSocket(KCommandSocket*, int)) ); 1044 connect( commandSocket, SIGNAL(commandFinished( KCommandSocket*, int )), this, SLOT(deleteCommandSocket(KCommandSocket*, int)) );
1045 mParent->topLevelWidget()->setCaption( i18n("Sending request for remote file ...") ); 1045 mParent->topLevelWidget()->setCaption( i18n("Sending request for remote file ...") );
1046 commandSocket->readFile( syncFileName() ); 1046 commandSocket->readFile( syncFileName() );
1047} 1047}
1048 1048
1049void KSyncManager::deleteCommandSocket(KCommandSocket*s, int state) 1049void KSyncManager::deleteCommandSocket(KCommandSocket*s, int state)
1050{ 1050{
1051 //enum { success, errorW, errorR, quiet }; 1051 //enum { success, errorW, errorR, quiet };
1052 if ( state == KCommandSocket::errorR ||state == KCommandSocket::errorTO ) { 1052 if ( state == KCommandSocket::errorR ||state == KCommandSocket::errorTO ) {
1053 mParent->topLevelWidget()->setCaption( i18n("ERROR: Receiving remote file failed.") ); 1053 mParent->topLevelWidget()->setCaption( i18n("ERROR: Receiving remote file failed.") );
1054 delete s; 1054 delete s;
1055 if ( state == KCommandSocket::errorR ) { 1055 if ( state == KCommandSocket::errorR ) {
1056 KCommandSocket* commandSocket = new KCommandSocket( mPassWordPiSync, mActiveSyncPort.toUInt(), mActiveSyncIP, this ); 1056 KCommandSocket* commandSocket = new KCommandSocket( mPassWordPiSync, mActiveSyncPort.toUInt(), mActiveSyncIP, this );
1057 connect( commandSocket, SIGNAL(commandFinished( KCommandSocket*, int)), this, SLOT(deleteCommandSocket(KCommandSocket*, int )) ); 1057 connect( commandSocket, SIGNAL(commandFinished( KCommandSocket*, int)), this, SLOT(deleteCommandSocket(KCommandSocket*, int )) );
1058 commandSocket->sendStop(); 1058 commandSocket->sendStop();
1059 } 1059 }
1060 mPisyncFinished = true; 1060 mPisyncFinished = true;
1061 return; 1061 return;
1062 1062
1063 } else if ( state == KCommandSocket::errorW ) { 1063 } else if ( state == KCommandSocket::errorW ) {
1064 mParent->topLevelWidget()->setCaption( i18n("ERROR:Writing back file failed.") ); 1064 mParent->topLevelWidget()->setCaption( i18n("ERROR:Writing back file failed.") );
1065 mPisyncFinished = true; 1065 mPisyncFinished = true;
1066 1066
1067 } else if ( state == KCommandSocket::successR ) { 1067 } else if ( state == KCommandSocket::successR ) {
1068 QTimer::singleShot( 1, this , SLOT ( readFileFromSocket())); 1068 QTimer::singleShot( 1, this , SLOT ( readFileFromSocket()));
1069 1069
1070 } else if ( state == KCommandSocket::successW ) { 1070 } else if ( state == KCommandSocket::successW ) {
1071 mParent->topLevelWidget()->setCaption( i18n("Pi-Sync succesful!") ); 1071 mParent->topLevelWidget()->setCaption( i18n("Pi-Sync succesful!") );
1072 mPisyncFinished = true; 1072 mPisyncFinished = true;
1073 } 1073 }
1074 1074
1075 delete s; 1075 delete s;
1076} 1076}
1077 1077
1078void KSyncManager::readFileFromSocket() 1078void KSyncManager::readFileFromSocket()
1079{ 1079{
1080 QString fileName = syncFileName(); 1080 QString fileName = syncFileName();
1081 mParent->topLevelWidget()->setCaption( i18n("Remote file saved to temp file.") ); 1081 mParent->topLevelWidget()->setCaption( i18n("Remote file saved to temp file.") );
1082 if ( ! syncWithFile( fileName , true ) ) { 1082 if ( ! syncWithFile( fileName , true ) ) {
1083 mParent->topLevelWidget()->setCaption( i18n("Syncing failed.") ); 1083 mParent->topLevelWidget()->setCaption( i18n("Syncing failed.") );
1084 mPisyncFinished = true; 1084 mPisyncFinished = true;
1085 return; 1085 return;
1086 } 1086 }
1087 KCommandSocket* commandSocket = new KCommandSocket( mPassWordPiSync, mActiveSyncPort.toUInt(), mActiveSyncIP, this ); 1087 KCommandSocket* commandSocket = new KCommandSocket( mPassWordPiSync, mActiveSyncPort.toUInt(), mActiveSyncIP, this );
1088 connect( commandSocket, SIGNAL(commandFinished( KCommandSocket*, int)), this, SLOT(deleteCommandSocket(KCommandSocket*, int )) ); 1088 connect( commandSocket, SIGNAL(commandFinished( KCommandSocket*, int)), this, SLOT(deleteCommandSocket(KCommandSocket*, int )) );
1089 if ( mWriteBackFile ) 1089 if ( mWriteBackFile )
1090 commandSocket->writeFile( fileName ); 1090 commandSocket->writeFile( fileName );
1091 else { 1091 else {
1092 commandSocket->sendStop(); 1092 commandSocket->sendStop();
1093 mParent->topLevelWidget()->setCaption( i18n("Pi-Sync succesful!") ); 1093 mParent->topLevelWidget()->setCaption( i18n("Pi-Sync succesful!") );
1094 mPisyncFinished = true; 1094 mPisyncFinished = true;
1095 } 1095 }
1096} 1096}
1097 1097
1098KServerSocket:: KServerSocket ( QString pw, Q_UINT16 port, int backlog, QObject * parent, const char * name ) : QServerSocket( port, backlog, parent, name ) 1098KServerSocket:: KServerSocket ( QString pw, Q_UINT16 port, int backlog, QObject * parent, const char * name ) : QServerSocket( port, backlog, parent, name )
1099{ 1099{
1100 mPassWord = pw; 1100 mPassWord = pw;
1101 mSocket = 0; 1101 mSocket = 0;
1102 mSyncActionDialog = 0; 1102 mSyncActionDialog = 0;
1103 blockRC = false; 1103 blockRC = false;
1104}; 1104};
1105 1105
1106void KServerSocket::newConnection ( int socket ) 1106void KServerSocket::newConnection ( int socket )
1107{ 1107{
1108 // qDebug("KServerSocket:New connection %d ", socket); 1108 // qDebug("KServerSocket:New connection %d ", socket);
1109 if ( mSocket ) { 1109 if ( mSocket ) {
1110 qDebug("KServerSocket::newConnection Socket deleted! "); 1110 qDebug("KServerSocket::newConnection Socket deleted! ");
1111 delete mSocket; 1111 delete mSocket;
1112 mSocket = 0; 1112 mSocket = 0;
1113 } 1113 }
1114 mSocket = new QSocket( this ); 1114 mSocket = new QSocket( this );
1115 connect( mSocket , SIGNAL(readyRead()), this, SLOT(readClient()) ); 1115 connect( mSocket , SIGNAL(readyRead()), this, SLOT(readClient()) );
1116 connect( mSocket , SIGNAL(delayedCloseFinished()), this, SLOT(discardClient()) ); 1116 connect( mSocket , SIGNAL(delayedCloseFinished()), this, SLOT(discardClient()) );
1117 mSocket->setSocket( socket ); 1117 mSocket->setSocket( socket );
1118} 1118}
1119 1119
1120void KServerSocket::discardClient() 1120void KServerSocket::discardClient()
1121{ 1121{
1122 //qDebug(" KServerSocket::discardClient()"); 1122 //qDebug(" KServerSocket::discardClient()");
1123 if ( mSocket ) { 1123 if ( mSocket ) {
1124 delete mSocket; 1124 delete mSocket;
1125 mSocket = 0; 1125 mSocket = 0;
1126 } 1126 }
1127 //emit endConnect(); 1127 //emit endConnect();
1128} 1128}
1129void KServerSocket::readClient() 1129void KServerSocket::readClient()
1130{ 1130{
1131 if ( blockRC ) 1131 if ( blockRC )
1132 return; 1132 return;
1133 if ( mSocket == 0 ) { 1133 if ( mSocket == 0 ) {
1134 qDebug("ERROR::KServerSocket::readClient(): mSocket == 0 "); 1134 qDebug("ERROR::KServerSocket::readClient(): mSocket == 0 ");
1135 return; 1135 return;
1136 } 1136 }
1137 //qDebug("KServerSocket::readClient()"); 1137 //qDebug("KServerSocket::readClient()");
1138 if ( mSocket->canReadLine() ) { 1138 if ( mSocket->canReadLine() ) {
1139 QString line = mSocket->readLine(); 1139 QString line = mSocket->readLine();
1140 //qDebug("KServerSocket readline: %s ", line.latin1()); 1140 //qDebug("KServerSocket readline: %s ", line.latin1());
1141 QStringList tokens = QStringList::split( QRegExp("[ \r\n][ \r\n]*"), line ); 1141 QStringList tokens = QStringList::split( QRegExp("[ \r\n][ \r\n]*"), line );
1142 if ( tokens[0] == "GET" ) { 1142 if ( tokens[0] == "GET" ) {
1143 if ( tokens[1] == mPassWord ) { 1143 if ( tokens[1] == mPassWord ) {
1144 //emit sendFile( mSocket ); 1144 //emit sendFile( mSocket );
1145 bool ok = false; 1145 bool ok = false;
1146 QDateTime dt = KGlobal::locale()->readDateTime( tokens[2], KLocale::ISODate, &ok); 1146 QDateTime dt = KGlobal::locale()->readDateTime( tokens[2], KLocale::ISODate, &ok);
1147 if ( ok ) { 1147 if ( ok ) {
1148 KSyncManager::mRequestedSyncEvent = dt; 1148 KSyncManager::mRequestedSyncEvent = dt;
1149 } 1149 }
1150 else 1150 else
1151 KSyncManager::mRequestedSyncEvent = QDateTime(); 1151 KSyncManager::mRequestedSyncEvent = QDateTime();
1152 send_file(); 1152 send_file();
1153 } 1153 }
1154 else { 1154 else {
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}
1176void KServerSocket::end_connect() 1176void KServerSocket::end_connect()
1177{ 1177{
1178 delete mSyncActionDialog; 1178 delete mSyncActionDialog;
1179 mSyncActionDialog = 0; 1179 mSyncActionDialog = 0;
1180} 1180}
1181void KServerSocket::send_file() 1181void 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}
1263void KServerSocket::get_file() 1263void 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
1273void KServerSocket::readBackFileFromSocket() 1273void 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
1320KCommandSocket::KCommandSocket ( QString password, Q_UINT16 port, QString host, QObject * parent, const char * name ): QObject( parent, name ) 1320KCommandSocket::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}
1331void KCommandSocket::readFile( QString fn ) 1331void 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
1350void KCommandSocket::writeFile( QString fileName ) 1350void 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}
1360void KCommandSocket::writeFileToSocket() 1360void 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}
1384void KCommandSocket::sendStop() 1384void 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
1399void KCommandSocket::startReadFileFromSocket() 1399void 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}
1410void KCommandSocket::readFileFromSocket() 1410void 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
1449void KCommandSocket::deleteSocket() 1449void 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}