-rw-r--r-- | libkdepim/ksyncmanager.cpp | 37 |
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 | |||
@@ -1138,117 +1138,134 @@ void KServerSocket::readClient() | |||
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 | } |
1174 | void KServerSocket::end_connect() | 1174 | void KServerSocket::end_connect() |
1175 | { | 1175 | { |
1176 | delete mSyncActionDialog; | 1176 | delete mSyncActionDialog; |
1177 | mSyncActionDialog = 0; | 1177 | mSyncActionDialog = 0; |
1178 | } | 1178 | } |
1179 | void KServerSocket::send_file() | 1179 | void 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 | } |
1244 | void KServerSocket::get_file() | 1261 | void 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 | ||
1254 | void KServerSocket::readBackFileFromSocket() | 1271 | void KServerSocket::readBackFileFromSocket() |