summaryrefslogtreecommitdiffabout
path: root/libkdepim/ksyncmanager.cpp
authorzautrix <zautrix>2004-10-28 17:59:33 (UTC)
committer zautrix <zautrix>2004-10-28 17:59:33 (UTC)
commita9ca33a6c78026396ff081572e96f0d1e3eb63fa (patch) (unidiff)
tree559ce203ce5adb871f8636a8f2213cf4a472d576 /libkdepim/ksyncmanager.cpp
parent5c64eb04c048d7e51f1c71621e1d37c5c0c580a0 (diff)
downloadkdepimpi-a9ca33a6c78026396ff081572e96f0d1e3eb63fa.zip
kdepimpi-a9ca33a6c78026396ff081572e96f0d1e3eb63fa.tar.gz
kdepimpi-a9ca33a6c78026396ff081572e96f0d1e3eb63fa.tar.bz2
showing clcok skew in pisync with warning
Diffstat (limited to 'libkdepim/ksyncmanager.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r--libkdepim/ksyncmanager.cpp37
1 files changed, 27 insertions, 10 deletions
diff --git a/libkdepim/ksyncmanager.cpp b/libkdepim/ksyncmanager.cpp
index 9a1f2a9..21af295 100644
--- a/libkdepim/ksyncmanager.cpp
+++ b/libkdepim/ksyncmanager.cpp
@@ -930,524 +930,541 @@ void KSyncManager::syncKDE()
930 } 930 }
931 931
932 } 932 }
933 break; 933 break;
934 case (PWMPI): 934 case (PWMPI):
935 935
936 break; 936 break;
937 default: 937 default:
938 qDebug("KSyncManager::slotSyncMenu: invalid apptype selected"); 938 qDebug("KSyncManager::slotSyncMenu: invalid apptype selected");
939 break; 939 break;
940 940
941 } 941 }
942} 942}
943 943
944void KSyncManager::syncSharp() 944void KSyncManager::syncSharp()
945{ 945{
946 946
947 if ( ! syncExternalApplication("sharp") ) 947 if ( ! syncExternalApplication("sharp") )
948 qDebug("ERROR sync sharp "); 948 qDebug("ERROR sync sharp ");
949} 949}
950 950
951bool KSyncManager::syncExternalApplication(QString resource) 951bool KSyncManager::syncExternalApplication(QString resource)
952{ 952{
953 953
954 emit save(); 954 emit save();
955 955
956 if ( mAskForPreferences ) 956 if ( mAskForPreferences )
957 if ( !edit_sync_options()) { 957 if ( !edit_sync_options()) {
958 mParent->topLevelWidget()->setCaption( i18n("Syncing aborted. Nothing synced.") ); 958 mParent->topLevelWidget()->setCaption( i18n("Syncing aborted. Nothing synced.") );
959 return false; 959 return false;
960 } 960 }
961 961
962 qDebug("Sync extern %s", resource.latin1()); 962 qDebug("Sync extern %s", resource.latin1());
963 963
964 bool syncOK = mImplementation->syncExternal(this, resource); 964 bool syncOK = mImplementation->syncExternal(this, resource);
965 965
966 return syncOK; 966 return syncOK;
967 967
968} 968}
969 969
970void KSyncManager::syncPhone() 970void KSyncManager::syncPhone()
971{ 971{
972 972
973 syncExternalApplication("phone"); 973 syncExternalApplication("phone");
974 974
975} 975}
976 976
977void KSyncManager::showProgressBar(int percentage, QString caption, int total) 977void KSyncManager::showProgressBar(int percentage, QString caption, int total)
978{ 978{
979 if (!bar->isVisible()) 979 if (!bar->isVisible())
980 { 980 {
981 bar->setCaption (caption); 981 bar->setCaption (caption);
982 bar->setTotalSteps ( total ) ; 982 bar->setTotalSteps ( total ) ;
983 983
984 bar->show(); 984 bar->show();
985 } 985 }
986 986
987 bar->setProgress( percentage ); 987 bar->setProgress( percentage );
988} 988}
989 989
990void KSyncManager::hideProgressBar() 990void KSyncManager::hideProgressBar()
991{ 991{
992 bar->hide(); 992 bar->hide();
993} 993}
994 994
995bool KSyncManager::isProgressBarCanceled() 995bool KSyncManager::isProgressBarCanceled()
996{ 996{
997 return !bar->isVisible(); 997 return !bar->isVisible();
998} 998}
999 999
1000QString KSyncManager::syncFileName() 1000QString KSyncManager::syncFileName()
1001{ 1001{
1002 1002
1003 QString fn = "tempfile"; 1003 QString fn = "tempfile";
1004 switch(mTargetApp) 1004 switch(mTargetApp)
1005 { 1005 {
1006 case (KAPI): 1006 case (KAPI):
1007 fn = "tempsyncab.vcf"; 1007 fn = "tempsyncab.vcf";
1008 break; 1008 break;
1009 case (KOPI): 1009 case (KOPI):
1010 fn = "tempsynccal.ics"; 1010 fn = "tempsynccal.ics";
1011 break; 1011 break;
1012 case (PWMPI): 1012 case (PWMPI):
1013 fn = "tempsyncpw.pwm"; 1013 fn = "tempsyncpw.pwm";
1014 break; 1014 break;
1015 default: 1015 default:
1016 break; 1016 break;
1017 } 1017 }
1018#ifdef _WIN32_ 1018#ifdef _WIN32_
1019 return locateLocal( "tmp", fn ); 1019 return locateLocal( "tmp", fn );
1020#else 1020#else
1021 return (QString( "/tmp/" )+ fn ); 1021 return (QString( "/tmp/" )+ fn );
1022#endif 1022#endif
1023} 1023}
1024 1024
1025void KSyncManager::syncPi() 1025void KSyncManager::syncPi()
1026{ 1026{
1027 mIsKapiFile = true; 1027 mIsKapiFile = true;
1028 mPisyncFinished = false; 1028 mPisyncFinished = false;
1029 qApp->processEvents(); 1029 qApp->processEvents();
1030 if ( mAskForPreferences ) 1030 if ( mAskForPreferences )
1031 if ( !edit_pisync_options()) { 1031 if ( !edit_pisync_options()) {
1032 mParent->topLevelWidget()->setCaption( i18n("Syncing aborted. Nothing synced.") ); 1032 mParent->topLevelWidget()->setCaption( i18n("Syncing aborted. Nothing synced.") );
1033 return; 1033 return;
1034 } 1034 }
1035 bool ok; 1035 bool ok;
1036 Q_UINT16 port = mActiveSyncPort.toUInt(&ok); 1036 Q_UINT16 port = mActiveSyncPort.toUInt(&ok);
1037 if ( ! ok ) { 1037 if ( ! ok ) {
1038 mParent->topLevelWidget()->setCaption( i18n("Sorry, no valid port.Syncing cancelled.") ); 1038 mParent->topLevelWidget()->setCaption( i18n("Sorry, no valid port.Syncing cancelled.") );
1039 return; 1039 return;
1040 } 1040 }
1041 KCommandSocket* commandSocket = new KCommandSocket( mPassWordPiSync, port, mActiveSyncIP, this ); 1041 KCommandSocket* commandSocket = new KCommandSocket( mPassWordPiSync, port, mActiveSyncIP, this );
1042 connect( commandSocket, SIGNAL(commandFinished( KCommandSocket*, int )), this, SLOT(deleteCommandSocket(KCommandSocket*, int)) ); 1042 connect( commandSocket, SIGNAL(commandFinished( KCommandSocket*, int )), this, SLOT(deleteCommandSocket(KCommandSocket*, int)) );
1043 mParent->topLevelWidget()->setCaption( i18n("Sending request for remote file ...") ); 1043 mParent->topLevelWidget()->setCaption( i18n("Sending request for remote file ...") );
1044 commandSocket->readFile( syncFileName() ); 1044 commandSocket->readFile( syncFileName() );
1045} 1045}
1046 1046
1047void KSyncManager::deleteCommandSocket(KCommandSocket*s, int state) 1047void KSyncManager::deleteCommandSocket(KCommandSocket*s, int state)
1048{ 1048{
1049 //enum { success, errorW, errorR, quiet }; 1049 //enum { success, errorW, errorR, quiet };
1050 if ( state == KCommandSocket::errorR ||state == KCommandSocket::errorTO ) { 1050 if ( state == KCommandSocket::errorR ||state == KCommandSocket::errorTO ) {
1051 mParent->topLevelWidget()->setCaption( i18n("ERROR: Receiving remote file failed.") ); 1051 mParent->topLevelWidget()->setCaption( i18n("ERROR: Receiving remote file failed.") );
1052 delete s; 1052 delete s;
1053 if ( state == KCommandSocket::errorR ) { 1053 if ( state == KCommandSocket::errorR ) {
1054 KCommandSocket* commandSocket = new KCommandSocket( mPassWordPiSync, mActiveSyncPort.toUInt(), mActiveSyncIP, this ); 1054 KCommandSocket* commandSocket = new KCommandSocket( mPassWordPiSync, mActiveSyncPort.toUInt(), mActiveSyncIP, this );
1055 connect( commandSocket, SIGNAL(commandFinished( KCommandSocket*, int)), this, SLOT(deleteCommandSocket(KCommandSocket*, int )) ); 1055 connect( commandSocket, SIGNAL(commandFinished( KCommandSocket*, int)), this, SLOT(deleteCommandSocket(KCommandSocket*, int )) );
1056 commandSocket->sendStop(); 1056 commandSocket->sendStop();
1057 } 1057 }
1058 mPisyncFinished = true; 1058 mPisyncFinished = true;
1059 return; 1059 return;
1060 1060
1061 } else if ( state == KCommandSocket::errorW ) { 1061 } else if ( state == KCommandSocket::errorW ) {
1062 mParent->topLevelWidget()->setCaption( i18n("ERROR:Writing back file failed.") ); 1062 mParent->topLevelWidget()->setCaption( i18n("ERROR:Writing back file failed.") );
1063 mPisyncFinished = true; 1063 mPisyncFinished = true;
1064 1064
1065 } else if ( state == KCommandSocket::successR ) { 1065 } else if ( state == KCommandSocket::successR ) {
1066 QTimer::singleShot( 1, this , SLOT ( readFileFromSocket())); 1066 QTimer::singleShot( 1, this , SLOT ( readFileFromSocket()));
1067 1067
1068 } else if ( state == KCommandSocket::successW ) { 1068 } else if ( state == KCommandSocket::successW ) {
1069 mParent->topLevelWidget()->setCaption( i18n("Pi-Sync succesful!") ); 1069 mParent->topLevelWidget()->setCaption( i18n("Pi-Sync succesful!") );
1070 mPisyncFinished = true; 1070 mPisyncFinished = true;
1071 } 1071 }
1072 1072
1073 delete s; 1073 delete s;
1074} 1074}
1075 1075
1076void KSyncManager::readFileFromSocket() 1076void KSyncManager::readFileFromSocket()
1077{ 1077{
1078 QString fileName = syncFileName(); 1078 QString fileName = syncFileName();
1079 mParent->topLevelWidget()->setCaption( i18n("Remote file saved to temp file.") ); 1079 mParent->topLevelWidget()->setCaption( i18n("Remote file saved to temp file.") );
1080 if ( ! syncWithFile( fileName , true ) ) { 1080 if ( ! syncWithFile( fileName , true ) ) {
1081 mParent->topLevelWidget()->setCaption( i18n("Syncing failed.") ); 1081 mParent->topLevelWidget()->setCaption( i18n("Syncing failed.") );
1082 mPisyncFinished = true; 1082 mPisyncFinished = true;
1083 return; 1083 return;
1084 } 1084 }
1085 KCommandSocket* commandSocket = new KCommandSocket( mPassWordPiSync, mActiveSyncPort.toUInt(), mActiveSyncIP, this ); 1085 KCommandSocket* commandSocket = new KCommandSocket( mPassWordPiSync, mActiveSyncPort.toUInt(), mActiveSyncIP, this );
1086 connect( commandSocket, SIGNAL(commandFinished( KCommandSocket*, int)), this, SLOT(deleteCommandSocket(KCommandSocket*, int )) ); 1086 connect( commandSocket, SIGNAL(commandFinished( KCommandSocket*, int)), this, SLOT(deleteCommandSocket(KCommandSocket*, int )) );
1087 if ( mWriteBackFile ) 1087 if ( mWriteBackFile )
1088 commandSocket->writeFile( fileName ); 1088 commandSocket->writeFile( fileName );
1089 else { 1089 else {
1090 commandSocket->sendStop(); 1090 commandSocket->sendStop();
1091 mParent->topLevelWidget()->setCaption( i18n("Pi-Sync succesful!") ); 1091 mParent->topLevelWidget()->setCaption( i18n("Pi-Sync succesful!") );
1092 mPisyncFinished = true; 1092 mPisyncFinished = true;
1093 } 1093 }
1094} 1094}
1095 1095
1096KServerSocket:: KServerSocket ( QString pw, Q_UINT16 port, int backlog, QObject * parent, const char * name ) : QServerSocket( port, backlog, parent, name ) 1096KServerSocket:: KServerSocket ( QString pw, Q_UINT16 port, int backlog, QObject * parent, const char * name ) : QServerSocket( port, backlog, parent, name )
1097{ 1097{
1098 mPassWord = pw; 1098 mPassWord = pw;
1099 mSocket = 0; 1099 mSocket = 0;
1100 mSyncActionDialog = 0; 1100 mSyncActionDialog = 0;
1101 blockRC = false; 1101 blockRC = false;
1102}; 1102};
1103 1103
1104void KServerSocket::newConnection ( int socket ) 1104void KServerSocket::newConnection ( int socket )
1105{ 1105{
1106 // qDebug("KServerSocket:New connection %d ", socket); 1106 // qDebug("KServerSocket:New connection %d ", socket);
1107 if ( mSocket ) { 1107 if ( mSocket ) {
1108 qDebug("KServerSocket::newConnection Socket deleted! "); 1108 qDebug("KServerSocket::newConnection Socket deleted! ");
1109 delete mSocket; 1109 delete mSocket;
1110 mSocket = 0; 1110 mSocket = 0;
1111 } 1111 }
1112 mSocket = new QSocket( this ); 1112 mSocket = new QSocket( this );
1113 connect( mSocket , SIGNAL(readyRead()), this, SLOT(readClient()) ); 1113 connect( mSocket , SIGNAL(readyRead()), this, SLOT(readClient()) );
1114 connect( mSocket , SIGNAL(delayedCloseFinished()), this, SLOT(discardClient()) ); 1114 connect( mSocket , SIGNAL(delayedCloseFinished()), this, SLOT(discardClient()) );
1115 mSocket->setSocket( socket ); 1115 mSocket->setSocket( socket );
1116} 1116}
1117 1117
1118void KServerSocket::discardClient() 1118void KServerSocket::discardClient()
1119{ 1119{
1120 //qDebug(" KServerSocket::discardClient()"); 1120 //qDebug(" KServerSocket::discardClient()");
1121 if ( mSocket ) { 1121 if ( mSocket ) {
1122 delete mSocket; 1122 delete mSocket;
1123 mSocket = 0; 1123 mSocket = 0;
1124 } 1124 }
1125 //emit endConnect(); 1125 //emit endConnect();
1126} 1126}
1127void KServerSocket::readClient() 1127void KServerSocket::readClient()
1128{ 1128{
1129 if ( blockRC ) 1129 if ( blockRC )
1130 return; 1130 return;
1131 if ( mSocket == 0 ) { 1131 if ( mSocket == 0 ) {
1132 qDebug("ERROR::KServerSocket::readClient(): mSocket == 0 "); 1132 qDebug("ERROR::KServerSocket::readClient(): mSocket == 0 ");
1133 return; 1133 return;
1134 } 1134 }
1135 //qDebug("KServerSocket::readClient()"); 1135 //qDebug("KServerSocket::readClient()");
1136 if ( mSocket->canReadLine() ) { 1136 if ( mSocket->canReadLine() ) {
1137 QString line = mSocket->readLine(); 1137 QString line = mSocket->readLine();
1138 //qDebug("KServerSocket readline: %s ", line.latin1()); 1138 //qDebug("KServerSocket readline: %s ", line.latin1());
1139 QStringList tokens = QStringList::split( QRegExp("[ \r\n][ \r\n]*"), line ); 1139 QStringList tokens = QStringList::split( QRegExp("[ \r\n][ \r\n]*"), line );
1140 if ( tokens[0] == "GET" ) { 1140 if ( tokens[0] == "GET" ) {
1141 if ( tokens[1] == mPassWord ) { 1141 if ( tokens[1] == mPassWord ) {
1142 //emit sendFile( mSocket ); 1142 //emit sendFile( mSocket );
1143 bool ok = false; 1143 bool ok = false;
1144 QDateTime dt = KGlobal::locale()->readDateTime( tokens[2], KLocale::ISODate, &ok); 1144 QDateTime dt = KGlobal::locale()->readDateTime( tokens[2], KLocale::ISODate, &ok);
1145 if ( ok ) { 1145 if ( ok ) {
1146 KSyncManager::mRequestedSyncEvent = dt; 1146 KSyncManager::mRequestedSyncEvent = dt;
1147 } 1147 }
1148 else 1148 else
1149 KSyncManager::mRequestedSyncEvent = QDateTime(); 1149 KSyncManager::mRequestedSyncEvent = QDateTime();
1150 send_file(); 1150 send_file();
1151 } 1151 }
1152 else { 1152 else {
1153 KMessageBox::error( 0, i18n("Got send file request\nwith invalid password")); 1153 KMessageBox::error( 0, i18n("Got send file request\nwith invalid password"));
1154 //qDebug("password %s, invalid password %s ",mPassWord.latin1(), tokens[1].latin1() ); 1154 //qDebug("password %s, invalid password %s ",mPassWord.latin1(), tokens[1].latin1() );
1155 } 1155 }
1156 } 1156 }
1157 if ( tokens[0] == "PUT" ) { 1157 if ( tokens[0] == "PUT" ) {
1158 if ( tokens[1] == mPassWord ) { 1158 if ( tokens[1] == mPassWord ) {
1159 //emit getFile( mSocket ); 1159 //emit getFile( mSocket );
1160 blockRC = true; 1160 blockRC = true;
1161 get_file(); 1161 get_file();
1162 } 1162 }
1163 else { 1163 else {
1164 KMessageBox::error( 0, i18n("Got receive file request\nwith invalid password")); 1164 KMessageBox::error( 0, i18n("Got receive file request\nwith invalid password"));
1165 //qDebug("password %s, invalid password %s ",mPassWord.latin1(), tokens[1].latin1() ); 1165 //qDebug("password %s, invalid password %s ",mPassWord.latin1(), tokens[1].latin1() );
1166 } 1166 }
1167 } 1167 }
1168 if ( tokens[0] == "STOP" ) { 1168 if ( tokens[0] == "STOP" ) {
1169 //emit endConnect(); 1169 //emit endConnect();
1170 end_connect(); 1170 end_connect();
1171 } 1171 }
1172 } 1172 }
1173} 1173}
1174void KServerSocket::end_connect() 1174void KServerSocket::end_connect()
1175{ 1175{
1176 delete mSyncActionDialog; 1176 delete mSyncActionDialog;
1177 mSyncActionDialog = 0; 1177 mSyncActionDialog = 0;
1178} 1178}
1179void KServerSocket::send_file() 1179void KServerSocket::send_file()
1180{ 1180{
1181 //qDebug("MainWindow::sendFile(QSocket* s) "); 1181 //qDebug("MainWindow::sendFile(QSocket* s) ");
1182 if ( mSyncActionDialog ) 1182 if ( mSyncActionDialog )
1183 delete mSyncActionDialog; 1183 delete mSyncActionDialog;
1184 mSyncActionDialog = new QDialog ( 0, "input-dialog", true ); 1184 mSyncActionDialog = new QDialog ( 0, "input-dialog", true );
1185 mSyncActionDialog->setCaption(i18n("Received sync request")); 1185 mSyncActionDialog->setCaption(i18n("Received sync request"));
1186 QLabel* label = new QLabel( i18n("Synchronizing from remote ...\n\nDo not use this application!\n\nIf syncing fails\nyou can close this dialog."), mSyncActionDialog ); 1186 QLabel* label = new QLabel( i18n("Synchronizing from remote ...\n\nDo not use this application!\n\nIf syncing fails\nyou can close this dialog."), mSyncActionDialog );
1187 label->setAlignment ( Qt::AlignHCenter );
1187 QVBoxLayout* lay = new QVBoxLayout( mSyncActionDialog ); 1188 QVBoxLayout* lay = new QVBoxLayout( mSyncActionDialog );
1188 lay->addWidget( label); 1189 lay->addWidget( label);
1189 lay->setMargin(7); 1190 lay->setMargin(7);
1190 lay->setSpacing(7); 1191 lay->setSpacing(7);
1191 if ( KSyncManager::mRequestedSyncEvent.isValid() ) { 1192 if ( KSyncManager::mRequestedSyncEvent.isValid() ) {
1192 int secs = QDateTime::currentDateTime().secsTo( KSyncManager::mRequestedSyncEvent ); 1193 int secs = QDateTime::currentDateTime().secsTo( KSyncManager::mRequestedSyncEvent );
1193 //if ( secs > 30 ) 1194 if ( secs < 0 )
1194 if ( true ) 1195 secs = secs * (-1);
1196 if ( secs > 30 )
1197 //if ( true )
1195 { 1198 {
1196 QString warning = i18n("Clock skew of\nsyncing devices\nis %1 seconds!").arg( secs ); 1199 QString warning = i18n("Clock skew of\nsyncing devices\nis %1 seconds!").arg( secs );
1197 QLabel* label = new QLabel( warning, mSyncActionDialog ); 1200 QLabel* label = new QLabel( warning, mSyncActionDialog );
1198 if ( secs > 600 ) 1201 label->setAlignment ( Qt::AlignHCenter );
1202 lay->addWidget( label);
1203 if ( secs > 180 )
1199 { 1204 {
1205 if ( secs > 300 ) {
1206 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!"))) {
1207 qDebug("cancelled ");
1208 return ;
1209 }
1210 }
1200 QFont f = label->font(); 1211 QFont f = label->font();
1212 f.setPointSize ( f.pointSize() *2 );
1201 f. setBold (true ); 1213 f. setBold (true );
1202 f.setPointSize ( f.pointSize() + 10); 1214 QLabel* label = new QLabel( warning, mSyncActionDialog );
1203 label->setFont( f ); 1215 label->setFont( f );
1204 } 1216 warning = i18n("ADJUST\nYOUR\nCLOCKS!");
1205 lay->addWidget( label); 1217 label->setText( warning );
1206 mSyncActionDialog->setFixedSize( 230, 200); 1218 label->setAlignment ( Qt::AlignHCenter );
1219 lay->addWidget( label);
1220 mSyncActionDialog->setFixedSize( 230, 300);
1221 } else {
1222 mSyncActionDialog->setFixedSize( 230, 200);
1223 }
1207 } else { 1224 } else {
1208 mSyncActionDialog->setFixedSize( 230, 120); 1225 mSyncActionDialog->setFixedSize( 230, 120);
1209 } 1226 }
1210 } else 1227 } else
1211 mSyncActionDialog->setFixedSize( 230, 120); 1228 mSyncActionDialog->setFixedSize( 230, 120);
1212 mSyncActionDialog->show(); 1229 mSyncActionDialog->show();
1213 mSyncActionDialog->raise(); 1230 mSyncActionDialog->raise();
1214 emit request_file(); 1231 emit request_file();
1215 qApp->processEvents(); 1232 qApp->processEvents();
1216 QString fileName = mFileName; 1233 QString fileName = mFileName;
1217 QFile file( fileName ); 1234 QFile file( fileName );
1218 if (!file.open( IO_ReadOnly ) ) { 1235 if (!file.open( IO_ReadOnly ) ) {
1219 delete mSyncActionDialog; 1236 delete mSyncActionDialog;
1220 mSyncActionDialog = 0; 1237 mSyncActionDialog = 0;
1221 qDebug("KSS::error open file "); 1238 qDebug("KSS::error open file ");
1222 mSocket->close(); 1239 mSocket->close();
1223 if ( mSocket->state() == QSocket::Idle ) 1240 if ( mSocket->state() == QSocket::Idle )
1224 QTimer::singleShot( 10, this , SLOT ( discardClient())); 1241 QTimer::singleShot( 10, this , SLOT ( discardClient()));
1225 return ; 1242 return ;
1226 1243
1227 } 1244 }
1228 mSyncActionDialog->setCaption( i18n("Sending file...") ); 1245 mSyncActionDialog->setCaption( i18n("Sending file...") );
1229 QTextStream ts( &file ); 1246 QTextStream ts( &file );
1230 ts.setEncoding( QTextStream::Latin1 ); 1247 ts.setEncoding( QTextStream::Latin1 );
1231 1248
1232 QTextStream os( mSocket ); 1249 QTextStream os( mSocket );
1233 os.setEncoding( QTextStream::Latin1 ); 1250 os.setEncoding( QTextStream::Latin1 );
1234 while ( ! ts.atEnd() ) { 1251 while ( ! ts.atEnd() ) {
1235 os << ts.readLine() << "\r\n"; 1252 os << ts.readLine() << "\r\n";
1236 } 1253 }
1237 //os << ts.read(); 1254 //os << ts.read();
1238 file.close(); 1255 file.close();
1239 mSyncActionDialog->setCaption( i18n("Waiting for synced file...") ); 1256 mSyncActionDialog->setCaption( i18n("Waiting for synced file...") );
1240 mSocket->close(); 1257 mSocket->close();
1241 if ( mSocket->state() == QSocket::Idle ) 1258 if ( mSocket->state() == QSocket::Idle )
1242 QTimer::singleShot( 10, this , SLOT ( discardClient())); 1259 QTimer::singleShot( 10, this , SLOT ( discardClient()));
1243} 1260}
1244void KServerSocket::get_file() 1261void KServerSocket::get_file()
1245{ 1262{
1246 mSyncActionDialog->setCaption( i18n("Receiving synced file...") ); 1263 mSyncActionDialog->setCaption( i18n("Receiving synced file...") );
1247 1264
1248 piTime.start(); 1265 piTime.start();
1249 piFileString = ""; 1266 piFileString = "";
1250 QTimer::singleShot( 1, this , SLOT (readBackFileFromSocket( ) )); 1267 QTimer::singleShot( 1, this , SLOT (readBackFileFromSocket( ) ));
1251} 1268}
1252 1269
1253 1270
1254void KServerSocket::readBackFileFromSocket() 1271void KServerSocket::readBackFileFromSocket()
1255{ 1272{
1256 //qDebug("readBackFileFromSocket() %d ", piTime.elapsed ()); 1273 //qDebug("readBackFileFromSocket() %d ", piTime.elapsed ());
1257 while ( mSocket->canReadLine () ) { 1274 while ( mSocket->canReadLine () ) {
1258 piTime.restart(); 1275 piTime.restart();
1259 QString line = mSocket->readLine (); 1276 QString line = mSocket->readLine ();
1260 piFileString += line; 1277 piFileString += line;
1261 //qDebug("readline: %s ", line.latin1()); 1278 //qDebug("readline: %s ", line.latin1());
1262 mSyncActionDialog->setCaption( i18n("Received %1 bytes").arg( piFileString.length() ) ); 1279 mSyncActionDialog->setCaption( i18n("Received %1 bytes").arg( piFileString.length() ) );
1263 1280
1264 } 1281 }
1265 if ( piTime.elapsed () < 3000 ) { 1282 if ( piTime.elapsed () < 3000 ) {
1266 // wait for more 1283 // wait for more
1267 //qDebug("waitformore "); 1284 //qDebug("waitformore ");
1268 QTimer::singleShot( 100, this , SLOT (readBackFileFromSocket( ) )); 1285 QTimer::singleShot( 100, this , SLOT (readBackFileFromSocket( ) ));
1269 return; 1286 return;
1270 } 1287 }
1271 QString fileName = mFileName; 1288 QString fileName = mFileName;
1272 QFile file ( fileName ); 1289 QFile file ( fileName );
1273 if (!file.open( IO_WriteOnly ) ) { 1290 if (!file.open( IO_WriteOnly ) ) {
1274 delete mSyncActionDialog; 1291 delete mSyncActionDialog;
1275 mSyncActionDialog = 0; 1292 mSyncActionDialog = 0;
1276 qDebug("KSS:Error open read back file "); 1293 qDebug("KSS:Error open read back file ");
1277 piFileString = ""; 1294 piFileString = "";
1278 emit file_received( false ); 1295 emit file_received( false );
1279 blockRC = false; 1296 blockRC = false;
1280 return ; 1297 return ;
1281 1298
1282 } 1299 }
1283 1300
1284 // mView->setLoadedFileVersion(QDateTime::currentDateTime().addSecs( -1)); 1301 // mView->setLoadedFileVersion(QDateTime::currentDateTime().addSecs( -1));
1285 QTextStream ts ( &file ); 1302 QTextStream ts ( &file );
1286 ts.setEncoding( QTextStream::Latin1 ); 1303 ts.setEncoding( QTextStream::Latin1 );
1287 mSyncActionDialog->setCaption( i18n("Writing file to disk...") ); 1304 mSyncActionDialog->setCaption( i18n("Writing file to disk...") );
1288 ts << piFileString; 1305 ts << piFileString;
1289 mSocket->close(); 1306 mSocket->close();
1290 if ( mSocket->state() == QSocket::Idle ) 1307 if ( mSocket->state() == QSocket::Idle )
1291 QTimer::singleShot( 10, this , SLOT ( discardClient())); 1308 QTimer::singleShot( 10, this , SLOT ( discardClient()));
1292 file.close(); 1309 file.close();
1293 piFileString = ""; 1310 piFileString = "";
1294 emit file_received( true ); 1311 emit file_received( true );
1295 delete mSyncActionDialog; 1312 delete mSyncActionDialog;
1296 mSyncActionDialog = 0; 1313 mSyncActionDialog = 0;
1297 blockRC = false; 1314 blockRC = false;
1298 1315
1299} 1316}
1300 1317
1301KCommandSocket::KCommandSocket ( QString password, Q_UINT16 port, QString host, QObject * parent, const char * name ): QObject( parent, name ) 1318KCommandSocket::KCommandSocket ( QString password, Q_UINT16 port, QString host, QObject * parent, const char * name ): QObject( parent, name )
1302{ 1319{
1303 mPassWord = password; 1320 mPassWord = password;
1304 mSocket = 0; 1321 mSocket = 0;
1305 mPort = port; 1322 mPort = port;
1306 mHost = host; 1323 mHost = host;
1307 1324
1308 mRetVal = quiet; 1325 mRetVal = quiet;
1309 mTimerSocket = new QTimer ( this ); 1326 mTimerSocket = new QTimer ( this );
1310 connect( mTimerSocket, SIGNAL ( timeout () ), this, SLOT ( deleteSocket() ) ); 1327 connect( mTimerSocket, SIGNAL ( timeout () ), this, SLOT ( deleteSocket() ) );
1311} 1328}
1312void KCommandSocket::readFile( QString fn ) 1329void KCommandSocket::readFile( QString fn )
1313{ 1330{
1314 if ( !mSocket ) { 1331 if ( !mSocket ) {
1315 mSocket = new QSocket( this ); 1332 mSocket = new QSocket( this );
1316 connect( mSocket, SIGNAL(readyRead()), this, SLOT(startReadFileFromSocket()) ); 1333 connect( mSocket, SIGNAL(readyRead()), this, SLOT(startReadFileFromSocket()) );
1317 connect( mSocket, SIGNAL(delayedCloseFinished ()), this, SLOT(deleteSocket()) ); 1334 connect( mSocket, SIGNAL(delayedCloseFinished ()), this, SLOT(deleteSocket()) );
1318 } 1335 }
1319 mFileString = ""; 1336 mFileString = "";
1320 mFileName = fn; 1337 mFileName = fn;
1321 mFirst = true; 1338 mFirst = true;
1322 mSocket->connectToHost( mHost, mPort ); 1339 mSocket->connectToHost( mHost, mPort );
1323 QTextStream os( mSocket ); 1340 QTextStream os( mSocket );
1324 os.setEncoding( QTextStream::Latin1 ); 1341 os.setEncoding( QTextStream::Latin1 );
1325 1342
1326 QString curDt = " " +KGlobal::locale()->formatDateTime(QDateTime::currentDateTime().addSecs(-1),true, true,KLocale::ISODate ); 1343 QString curDt = " " +KGlobal::locale()->formatDateTime(QDateTime::currentDateTime().addSecs(-1),true, true,KLocale::ISODate );
1327 os << "GET " << mPassWord << curDt <<"\r\n"; 1344 os << "GET " << mPassWord << curDt <<"\r\n";
1328 mTimerSocket->start( 20000 ); 1345 mTimerSocket->start( 20000 );
1329} 1346}
1330 1347
1331void KCommandSocket::writeFile( QString fileName ) 1348void KCommandSocket::writeFile( QString fileName )
1332{ 1349{
1333 if ( !mSocket ) { 1350 if ( !mSocket ) {
1334 mSocket = new QSocket( this ); 1351 mSocket = new QSocket( this );
1335 connect( mSocket, SIGNAL(delayedCloseFinished ()), this, SLOT(deleteSocket()) ); 1352 connect( mSocket, SIGNAL(delayedCloseFinished ()), this, SLOT(deleteSocket()) );
1336 connect( mSocket, SIGNAL(connected ()), this, SLOT(writeFileToSocket()) ); 1353 connect( mSocket, SIGNAL(connected ()), this, SLOT(writeFileToSocket()) );
1337 } 1354 }
1338 mFileName = fileName ; 1355 mFileName = fileName ;
1339 mSocket->connectToHost( mHost, mPort ); 1356 mSocket->connectToHost( mHost, mPort );
1340} 1357}
1341void KCommandSocket::writeFileToSocket() 1358void KCommandSocket::writeFileToSocket()
1342{ 1359{
1343 QFile file2( mFileName ); 1360 QFile file2( mFileName );
1344 if (!file2.open( IO_ReadOnly ) ) { 1361 if (!file2.open( IO_ReadOnly ) ) {
1345 mRetVal= errorW; 1362 mRetVal= errorW;
1346 mSocket->close(); 1363 mSocket->close();
1347 if ( mSocket->state() == QSocket::Idle ) 1364 if ( mSocket->state() == QSocket::Idle )
1348 QTimer::singleShot( 10, this , SLOT ( deleteSocket())); 1365 QTimer::singleShot( 10, this , SLOT ( deleteSocket()));
1349 return ; 1366 return ;
1350 } 1367 }
1351 QTextStream ts2( &file2 ); 1368 QTextStream ts2( &file2 );
1352 ts2.setEncoding( QTextStream::Latin1 ); 1369 ts2.setEncoding( QTextStream::Latin1 );
1353 QTextStream os2( mSocket ); 1370 QTextStream os2( mSocket );
1354 os2.setEncoding( QTextStream::Latin1 ); 1371 os2.setEncoding( QTextStream::Latin1 );
1355 os2 << "PUT " << mPassWord << "\r\n";; 1372 os2 << "PUT " << mPassWord << "\r\n";;
1356 while ( ! ts2.atEnd() ) { 1373 while ( ! ts2.atEnd() ) {
1357 os2 << ts2.readLine() << "\r\n"; 1374 os2 << ts2.readLine() << "\r\n";
1358 } 1375 }
1359 mRetVal= successW; 1376 mRetVal= successW;
1360 file2.close(); 1377 file2.close();
1361 mSocket->close(); 1378 mSocket->close();
1362 if ( mSocket->state() == QSocket::Idle ) 1379 if ( mSocket->state() == QSocket::Idle )
1363 QTimer::singleShot( 10, this , SLOT ( deleteSocket())); 1380 QTimer::singleShot( 10, this , SLOT ( deleteSocket()));
1364} 1381}
1365void KCommandSocket::sendStop() 1382void KCommandSocket::sendStop()
1366{ 1383{
1367 if ( !mSocket ) { 1384 if ( !mSocket ) {
1368 mSocket = new QSocket( this ); 1385 mSocket = new QSocket( this );
1369 connect( mSocket, SIGNAL(delayedCloseFinished ()), this, SLOT(deleteSocket()) ); 1386 connect( mSocket, SIGNAL(delayedCloseFinished ()), this, SLOT(deleteSocket()) );
1370 } 1387 }
1371 mSocket->connectToHost( mHost, mPort ); 1388 mSocket->connectToHost( mHost, mPort );
1372 QTextStream os2( mSocket ); 1389 QTextStream os2( mSocket );
1373 os2.setEncoding( QTextStream::Latin1 ); 1390 os2.setEncoding( QTextStream::Latin1 );
1374 os2 << "STOP\r\n"; 1391 os2 << "STOP\r\n";
1375 mSocket->close(); 1392 mSocket->close();
1376 if ( mSocket->state() == QSocket::Idle ) 1393 if ( mSocket->state() == QSocket::Idle )
1377 QTimer::singleShot( 10, this , SLOT ( deleteSocket())); 1394 QTimer::singleShot( 10, this , SLOT ( deleteSocket()));
1378} 1395}
1379 1396
1380void KCommandSocket::startReadFileFromSocket() 1397void KCommandSocket::startReadFileFromSocket()
1381{ 1398{
1382 if ( ! mFirst ) 1399 if ( ! mFirst )
1383 return; 1400 return;
1384 mFirst = false; 1401 mFirst = false;
1385 mTimerSocket->stop(); 1402 mTimerSocket->stop();
1386 mFileString = ""; 1403 mFileString = "";
1387 mTime.start(); 1404 mTime.start();
1388 QTimer::singleShot( 1, this , SLOT (readFileFromSocket( ) )); 1405 QTimer::singleShot( 1, this , SLOT (readFileFromSocket( ) ));
1389 1406
1390} 1407}
1391void KCommandSocket::readFileFromSocket() 1408void KCommandSocket::readFileFromSocket()
1392{ 1409{
1393 //qDebug("readBackFileFromSocket() %d ", mTime.elapsed ()); 1410 //qDebug("readBackFileFromSocket() %d ", mTime.elapsed ());
1394 while ( mSocket->canReadLine () ) { 1411 while ( mSocket->canReadLine () ) {
1395 mTime.restart(); 1412 mTime.restart();
1396 QString line = mSocket->readLine (); 1413 QString line = mSocket->readLine ();
1397 mFileString += line; 1414 mFileString += line;
1398 //qDebug("readline: %s ", line.latin1()); 1415 //qDebug("readline: %s ", line.latin1());
1399 } 1416 }
1400 if ( mTime.elapsed () < 3000 ) { 1417 if ( mTime.elapsed () < 3000 ) {
1401 // wait for more 1418 // wait for more
1402 //qDebug("waitformore "); 1419 //qDebug("waitformore ");
1403 QTimer::singleShot( 100, this , SLOT (readFileFromSocket( ) )); 1420 QTimer::singleShot( 100, this , SLOT (readFileFromSocket( ) ));
1404 return; 1421 return;
1405 } 1422 }
1406 QString fileName = mFileName; 1423 QString fileName = mFileName;
1407 QFile file ( fileName ); 1424 QFile file ( fileName );
1408 if (!file.open( IO_WriteOnly ) ) { 1425 if (!file.open( IO_WriteOnly ) ) {
1409 mFileString = ""; 1426 mFileString = "";
1410 mRetVal = errorR; 1427 mRetVal = errorR;
1411 qDebug("KSS:Error open temp sync file for writing: %s",fileName.latin1() ); 1428 qDebug("KSS:Error open temp sync file for writing: %s",fileName.latin1() );
1412 deleteSocket(); 1429 deleteSocket();
1413 return ; 1430 return ;
1414 1431
1415 } 1432 }
1416 // mView->setLoadedFileVersion(QDateTime::currentDateTime().addSecs( -1)); 1433 // mView->setLoadedFileVersion(QDateTime::currentDateTime().addSecs( -1));
1417 QTextStream ts ( &file ); 1434 QTextStream ts ( &file );
1418 ts.setEncoding( QTextStream::Latin1 ); 1435 ts.setEncoding( QTextStream::Latin1 );
1419 ts << mFileString; 1436 ts << mFileString;
1420 file.close(); 1437 file.close();
1421 mFileString = ""; 1438 mFileString = "";
1422 mRetVal = successR; 1439 mRetVal = successR;
1423 mSocket->close(); 1440 mSocket->close();
1424 // if state is not idle, deleteSocket(); is called via 1441 // if state is not idle, deleteSocket(); is called via
1425 // connect( mSocket, SIGNAL(delayedCloseFinished ()), this, SLOT(deleteSocket()) ); 1442 // connect( mSocket, SIGNAL(delayedCloseFinished ()), this, SLOT(deleteSocket()) );
1426 if ( mSocket->state() == QSocket::Idle ) 1443 if ( mSocket->state() == QSocket::Idle )
1427 deleteSocket(); 1444 deleteSocket();
1428} 1445}
1429 1446
1430void KCommandSocket::deleteSocket() 1447void KCommandSocket::deleteSocket()
1431{ 1448{
1432 //qDebug("KCommandSocket::deleteSocket() "); 1449 //qDebug("KCommandSocket::deleteSocket() ");
1433 if ( mTimerSocket->isActive () ) { 1450 if ( mTimerSocket->isActive () ) {
1434 mTimerSocket->stop(); 1451 mTimerSocket->stop();
1435 mRetVal = errorTO; 1452 mRetVal = errorTO;
1436 qDebug("Connection to remote host timed out"); 1453 qDebug("Connection to remote host timed out");
1437 if ( mSocket ) { 1454 if ( mSocket ) {
1438 mSocket->close(); 1455 mSocket->close();
1439 //if ( mSocket->state() == QSocket::Idle ) 1456 //if ( mSocket->state() == QSocket::Idle )
1440 // deleteSocket(); 1457 // deleteSocket();
1441 delete mSocket; 1458 delete mSocket;
1442 mSocket = 0; 1459 mSocket = 0;
1443 } 1460 }
1444 KMessageBox::error( 0, i18n("Connection to remote\nhost timed out!\nDid you forgot to enable\nsyncing on remote host? ")); 1461 KMessageBox::error( 0, i18n("Connection to remote\nhost timed out!\nDid you forgot to enable\nsyncing on remote host? "));
1445 emit commandFinished( this, mRetVal ); 1462 emit commandFinished( this, mRetVal );
1446 return; 1463 return;
1447 } 1464 }
1448 //qDebug("KCommandSocket::deleteSocket() %d", mRetVal ); 1465 //qDebug("KCommandSocket::deleteSocket() %d", mRetVal );
1449 if ( mSocket) 1466 if ( mSocket)
1450 delete mSocket; 1467 delete mSocket;
1451 mSocket = 0; 1468 mSocket = 0;
1452 emit commandFinished( this, mRetVal ); 1469 emit commandFinished( this, mRetVal );
1453} 1470}