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