author | zautrix <zautrix> | 2004-10-07 11:44:35 (UTC) |
---|---|---|
committer | zautrix <zautrix> | 2004-10-07 11:44:35 (UTC) |
commit | 43c82cc5393522d2c34f34a4339cb6a1d1c6c555 (patch) (unidiff) | |
tree | 49916cfb6f12c846fa52f9697f9b0285c2902772 /libkdepim/ksyncmanager.cpp | |
parent | f0e8b8f36bccda952fa662e4faf2d58fcee67262 (diff) | |
download | kdepimpi-43c82cc5393522d2c34f34a4339cb6a1d1c6c555.zip kdepimpi-43c82cc5393522d2c34f34a4339cb6a1d1c6c555.tar.gz kdepimpi-43c82cc5393522d2c34f34a4339cb6a1d1c6c555.tar.bz2 |
sync fixes
-rw-r--r-- | libkdepim/ksyncmanager.cpp | 75 |
1 files changed, 27 insertions, 48 deletions
diff --git a/libkdepim/ksyncmanager.cpp b/libkdepim/ksyncmanager.cpp index b360644..a663427 100644 --- a/libkdepim/ksyncmanager.cpp +++ b/libkdepim/ksyncmanager.cpp | |||
@@ -186,97 +186,97 @@ void KSyncManager::slotSyncMenu( int action ) | |||
186 | } else if ( action == 1001 ) { | 186 | } else if ( action == 1001 ) { |
187 | syncLocalFile(); | 187 | syncLocalFile(); |
188 | 188 | ||
189 | } else if ( action == 1002 ) { | 189 | } else if ( action == 1002 ) { |
190 | quickSyncLocalFile(); | 190 | quickSyncLocalFile(); |
191 | 191 | ||
192 | } else if ( action >= 1003 ) { | 192 | } else if ( action >= 1003 ) { |
193 | if ( temp->getIsLocalFileSync() ) { | 193 | if ( temp->getIsLocalFileSync() ) { |
194 | switch(mTargetApp) | 194 | switch(mTargetApp) |
195 | { | 195 | { |
196 | case (KAPI): | 196 | case (KAPI): |
197 | if ( syncWithFile( temp->getRemoteFileNameAB( ), false ) ) | 197 | if ( syncWithFile( temp->getRemoteFileNameAB( ), false ) ) |
198 | mLastSyncedLocalFile = temp->getRemoteFileNameAB(); | 198 | mLastSyncedLocalFile = temp->getRemoteFileNameAB(); |
199 | break; | 199 | break; |
200 | case (KOPI): | 200 | case (KOPI): |
201 | if ( syncWithFile( temp->getRemoteFileName( ), false ) ) | 201 | if ( syncWithFile( temp->getRemoteFileName( ), false ) ) |
202 | mLastSyncedLocalFile = temp->getRemoteFileName(); | 202 | mLastSyncedLocalFile = temp->getRemoteFileName(); |
203 | break; | 203 | break; |
204 | case (PWMPI): | 204 | case (PWMPI): |
205 | if ( syncWithFile( temp->getRemoteFileNamePWM( ), false ) ) | 205 | if ( syncWithFile( temp->getRemoteFileNamePWM( ), false ) ) |
206 | mLastSyncedLocalFile = temp->getRemoteFileNamePWM(); | 206 | mLastSyncedLocalFile = temp->getRemoteFileNamePWM(); |
207 | break; | 207 | break; |
208 | default: | 208 | default: |
209 | qDebug("KSyncManager::slotSyncMenu: invalid apptype selected"); | 209 | qDebug("KSyncManager::slotSyncMenu: invalid apptype selected"); |
210 | break; | 210 | break; |
211 | 211 | ||
212 | } | 212 | } |
213 | } else { | 213 | } else { |
214 | if ( temp->getIsPhoneSync() ) { | 214 | if ( temp->getIsPhoneSync() ) { |
215 | mPhoneDevice = temp->getPhoneDevice( ) ; | 215 | mPhoneDevice = temp->getPhoneDevice( ) ; |
216 | mPhoneConnection = temp->getPhoneConnection( ); | 216 | mPhoneConnection = temp->getPhoneConnection( ); |
217 | mPhoneModel = temp->getPhoneModel( ); | 217 | mPhoneModel = temp->getPhoneModel( ); |
218 | syncPhone(); | 218 | syncPhone(); |
219 | } else if ( temp->getIsPiSync() ) { | 219 | } else if ( temp->getIsPiSync() ) { |
220 | if ( mTargetApp == KAPI ) { | 220 | if ( mTargetApp == KAPI ) { |
221 | mPassWordPiSync = temp->getRemotePwAB(); | 221 | mPassWordPiSync = temp->getRemotePwAB(); |
222 | mActiveSyncPort = temp->getRemotePortAB(); | 222 | mActiveSyncPort = temp->getRemotePortAB(); |
223 | mActiveSyncIP = temp->getRemoteIPAB(); | 223 | mActiveSyncIP = temp->getRemoteIPAB(); |
224 | } else if ( mTargetApp == KOPI ) { | 224 | } else if ( mTargetApp == KOPI ) { |
225 | mPassWordPiSync = temp->getRemotePw(); | 225 | mPassWordPiSync = temp->getRemotePw(); |
226 | mActiveSyncPort = temp->getRemotePort(); | 226 | mActiveSyncPort = temp->getRemotePort(); |
227 | mActiveSyncIP = temp->getRemoteIP(); | 227 | mActiveSyncIP = temp->getRemoteIP(); |
228 | } else { | 228 | } else { |
229 | mPassWordPiSync = temp->getRemotePwPWM(); | 229 | mPassWordPiSync = temp->getRemotePwPWM(); |
230 | mActiveSyncPort = temp->getRemotePortPWM(); | 230 | mActiveSyncPort = temp->getRemotePortPWM(); |
231 | mActiveSyncIP = temp->getRemoteIPPWM(); | 231 | mActiveSyncIP = temp->getRemoteIPPWM(); |
232 | } | 232 | } |
233 | syncPi(); | 233 | syncPi(); |
234 | } | 234 | } else |
235 | syncRemote( temp ); | 235 | syncRemote( temp ); |
236 | 236 | ||
237 | } | 237 | } |
238 | } | 238 | } |
239 | delete temp; | 239 | delete temp; |
240 | setBlockSave(false); | 240 | setBlockSave(false); |
241 | } | 241 | } |
242 | void KSyncManager::enableQuick() | 242 | void KSyncManager::enableQuick() |
243 | { | 243 | { |
244 | QDialog dia ( 0, "input-dialog", true ); | 244 | QDialog dia ( 0, "input-dialog", true ); |
245 | QLineEdit lab ( &dia ); | 245 | QLineEdit lab ( &dia ); |
246 | QVBoxLayout lay( &dia ); | 246 | QVBoxLayout lay( &dia ); |
247 | lab.setText( mPrefs->mPassiveSyncPort ); | 247 | lab.setText( mPrefs->mPassiveSyncPort ); |
248 | lay.setMargin(7); | 248 | lay.setMargin(7); |
249 | lay.setSpacing(7); | 249 | lay.setSpacing(7); |
250 | int po = 9197+mTargetApp; | 250 | int po = 9197+mTargetApp; |
251 | QLabel label ( i18n("Port number (Default: %1)").arg(po), &dia ); | 251 | QLabel label ( i18n("Port number (Default: %1)").arg(po), &dia ); |
252 | lay.addWidget( &label); | 252 | lay.addWidget( &label); |
253 | lay.addWidget( &lab); | 253 | lay.addWidget( &lab); |
254 | 254 | ||
255 | QLineEdit lepw ( &dia ); | 255 | QLineEdit lepw ( &dia ); |
256 | lepw.setText( mPrefs->mPassiveSyncPw ); | 256 | lepw.setText( mPrefs->mPassiveSyncPw ); |
257 | QLabel label2 ( i18n("Password to enable\naccess from remote:"), &dia ); | 257 | QLabel label2 ( i18n("Password to enable\naccess from remote:"), &dia ); |
258 | lay.addWidget( &label2); | 258 | lay.addWidget( &label2); |
259 | lay.addWidget( &lepw); | 259 | lay.addWidget( &lepw); |
260 | dia.setFixedSize( 230,80 ); | 260 | dia.setFixedSize( 230,80 ); |
261 | dia.setCaption( i18n("Enter port for Pi-Sync") ); | 261 | dia.setCaption( i18n("Enter port for Pi-Sync") ); |
262 | QPushButton pb ( "OK", &dia); | 262 | QPushButton pb ( "OK", &dia); |
263 | lay.addWidget( &pb ); | 263 | lay.addWidget( &pb ); |
264 | connect(&pb, SIGNAL( clicked() ), &dia, SLOT ( accept() ) ); | 264 | connect(&pb, SIGNAL( clicked() ), &dia, SLOT ( accept() ) ); |
265 | dia.show(); | 265 | dia.show(); |
266 | if ( ! dia.exec() ) | 266 | if ( ! dia.exec() ) |
267 | return; | 267 | return; |
268 | dia.hide(); | 268 | dia.hide(); |
269 | qApp->processEvents(); | 269 | qApp->processEvents(); |
270 | mPrefs->mPassiveSyncPw = lepw.text(); | 270 | mPrefs->mPassiveSyncPw = lepw.text(); |
271 | mPrefs->mPassiveSyncPort = lab.text(); | 271 | mPrefs->mPassiveSyncPort = lab.text(); |
272 | bool ok; | 272 | bool ok; |
273 | Q_UINT16 port = mPrefs->mPassiveSyncPort.toUInt(&ok); | 273 | Q_UINT16 port = mPrefs->mPassiveSyncPort.toUInt(&ok); |
274 | if ( ! ok ) { | 274 | if ( ! ok ) { |
275 | KMessageBox::information( 0, i18n("No valid port")); | 275 | KMessageBox::information( 0, i18n("No valid port")); |
276 | return; | 276 | return; |
277 | } | 277 | } |
278 | //qDebug("port %d ", port); | 278 | //qDebug("port %d ", port); |
279 | mServerSocket = new KServerSocket ( mPrefs->mPassiveSyncPw, port ,1 ); | 279 | mServerSocket = new KServerSocket ( mPrefs->mPassiveSyncPw, port ,1 ); |
280 | mServerSocket->setFileName( defaultFileName() ); | 280 | mServerSocket->setFileName( defaultFileName() ); |
281 | //qDebug("connected "); | 281 | //qDebug("connected "); |
282 | if ( !mServerSocket->ok() ) { | 282 | if ( !mServerSocket->ok() ) { |
@@ -304,333 +304,333 @@ void KSyncManager::syncLocalFile() | |||
304 | case (KOPI): | 304 | case (KOPI): |
305 | ext = "(*.ics/*.vcs)"; | 305 | ext = "(*.ics/*.vcs)"; |
306 | break; | 306 | break; |
307 | case (PWMPI): | 307 | case (PWMPI): |
308 | ext = "(*.pwm)"; | 308 | ext = "(*.pwm)"; |
309 | break; | 309 | break; |
310 | default: | 310 | default: |
311 | qDebug("KSyncManager::syncLocalFile: invalid apptype selected"); | 311 | qDebug("KSyncManager::syncLocalFile: invalid apptype selected"); |
312 | break; | 312 | break; |
313 | 313 | ||
314 | } | 314 | } |
315 | 315 | ||
316 | fn =KFileDialog:: getOpenFileName( fn, i18n("Sync filename"+ext), mParent ); | 316 | fn =KFileDialog:: getOpenFileName( fn, i18n("Sync filename"+ext), mParent ); |
317 | if ( fn == "" ) | 317 | if ( fn == "" ) |
318 | return; | 318 | return; |
319 | if ( syncWithFile( fn, false ) ) { | 319 | if ( syncWithFile( fn, false ) ) { |
320 | qDebug("syncLocalFile() successful "); | 320 | qDebug("syncLocalFile() successful "); |
321 | } | 321 | } |
322 | 322 | ||
323 | } | 323 | } |
324 | bool KSyncManager::syncWithFile( QString fn , bool quick ) | 324 | bool KSyncManager::syncWithFile( QString fn , bool quick ) |
325 | { | 325 | { |
326 | bool ret = false; | 326 | bool ret = false; |
327 | QFileInfo info; | 327 | QFileInfo info; |
328 | info.setFile( fn ); | 328 | info.setFile( fn ); |
329 | QString mess; | 329 | QString mess; |
330 | bool loadbup = true; | 330 | bool loadbup = true; |
331 | if ( !info. exists() ) { | 331 | if ( !info. exists() ) { |
332 | mess = i18n( "Sync file \n...%1\ndoes not exist!\nNothing synced!\n").arg(fn.right( 30) ); | 332 | mess = i18n( "Sync file \n...%1\ndoes not exist!\nNothing synced!\n").arg(fn.right( 30) ); |
333 | int result = QMessageBox::warning( mParent, i18n("Warning!"), | 333 | int result = QMessageBox::warning( mParent, i18n("Warning!"), |
334 | mess ); | 334 | mess ); |
335 | return ret; | 335 | return ret; |
336 | } | 336 | } |
337 | int result = 0; | 337 | int result = 0; |
338 | if ( !quick ) { | 338 | if ( !quick ) { |
339 | mess = i18n("Sync with file \n...%1\nfrom:\n%2\n").arg(fn.right( 25)).arg(KGlobal::locale()->formatDateTime(info.lastModified (), true, false )); | 339 | mess = i18n("Sync with file \n...%1\nfrom:\n%2\n").arg(fn.right( 25)).arg(KGlobal::locale()->formatDateTime(info.lastModified (), true, false )); |
340 | result = QMessageBox::warning( mParent, i18n("Warning!"), | 340 | result = QMessageBox::warning( mParent, i18n("Warning!"), |
341 | mess, | 341 | mess, |
342 | i18n("Sync"), i18n("Cancel"), 0, | 342 | i18n("Sync"), i18n("Cancel"), 0, |
343 | 0, 1 ); | 343 | 0, 1 ); |
344 | if ( result ) | 344 | if ( result ) |
345 | return false; | 345 | return false; |
346 | } | 346 | } |
347 | if ( mAskForPreferences ) | 347 | if ( mAskForPreferences ) |
348 | edit_sync_options(); | 348 | edit_sync_options(); |
349 | if ( result == 0 ) { | 349 | if ( result == 0 ) { |
350 | //qDebug("Now sycing ... "); | 350 | //qDebug("Now sycing ... "); |
351 | if ( ret = mImplementation->sync( this, fn, mSyncAlgoPrefs ) ) | 351 | if ( ret = mImplementation->sync( this, fn, mSyncAlgoPrefs ) ) |
352 | mParent->setCaption( i18n("Synchronization successful") ); | 352 | mParent->topLevelWidget()->setCaption( i18n("Synchronization successful") ); |
353 | else | 353 | else |
354 | mParent->setCaption( i18n("Sync cancelled or failed. Nothing synced.") ); | 354 | mParent->topLevelWidget()->setCaption( i18n("Sync cancelled or failed. Nothing synced.") ); |
355 | if ( ! quick ) | 355 | if ( ! quick ) |
356 | mLastSyncedLocalFile = fn; | 356 | mLastSyncedLocalFile = fn; |
357 | } | 357 | } |
358 | return ret; | 358 | return ret; |
359 | } | 359 | } |
360 | void KSyncManager::quickSyncLocalFile() | 360 | void KSyncManager::quickSyncLocalFile() |
361 | { | 361 | { |
362 | 362 | ||
363 | if ( syncWithFile( mLastSyncedLocalFile, false ) ) { | 363 | if ( syncWithFile( mLastSyncedLocalFile, false ) ) { |
364 | qDebug("quick syncLocalFile() successful "); | 364 | qDebug("quick syncLocalFile() successful "); |
365 | 365 | ||
366 | } | 366 | } |
367 | } | 367 | } |
368 | void KSyncManager::multiSync( bool askforPrefs ) | 368 | void KSyncManager::multiSync( bool askforPrefs ) |
369 | { | 369 | { |
370 | if (blockSave()) | 370 | if (blockSave()) |
371 | return; | 371 | return; |
372 | setBlockSave(true); | 372 | setBlockSave(true); |
373 | QString question = i18n("Do you really want\nto multiple sync\nwith all checked profiles?\nSyncing takes some\ntime - all profiles\nare synced twice!"); | 373 | QString question = i18n("Do you really want\nto multiple sync\nwith all checked profiles?\nSyncing takes some\ntime - all profiles\nare synced twice!"); |
374 | if ( QMessageBox::information( mParent, i18n("Sync"), | 374 | if ( QMessageBox::information( mParent, i18n("Sync"), |
375 | question, | 375 | question, |
376 | i18n("Yes"), i18n("No"), | 376 | i18n("Yes"), i18n("No"), |
377 | 0, 0 ) != 0 ) { | 377 | 0, 0 ) != 0 ) { |
378 | setBlockSave(false); | 378 | setBlockSave(false); |
379 | mParent->setCaption(i18n("Aborted! Nothing synced!")); | 379 | mParent->topLevelWidget()->setCaption(i18n("Aborted! Nothing synced!")); |
380 | return; | 380 | return; |
381 | } | 381 | } |
382 | mCurrentSyncDevice = i18n("Multiple profiles") ; | 382 | mCurrentSyncDevice = i18n("Multiple profiles") ; |
383 | mSyncAlgoPrefs = mRingSyncAlgoPrefs; | 383 | mSyncAlgoPrefs = mRingSyncAlgoPrefs; |
384 | if ( askforPrefs ) { | 384 | if ( askforPrefs ) { |
385 | edit_sync_options(); | 385 | edit_sync_options(); |
386 | mRingSyncAlgoPrefs = mSyncAlgoPrefs; | 386 | mRingSyncAlgoPrefs = mSyncAlgoPrefs; |
387 | } | 387 | } |
388 | mParent->setCaption(i18n("Multiple sync started.") ); | 388 | mParent->topLevelWidget()->setCaption(i18n("Multiple sync started.") ); |
389 | qApp->processEvents(); | 389 | qApp->processEvents(); |
390 | int num = ringSync() ; | 390 | int num = ringSync() ; |
391 | if ( num > 1 ) | 391 | if ( num > 1 ) |
392 | ringSync(); | 392 | ringSync(); |
393 | setBlockSave(false); | 393 | setBlockSave(false); |
394 | if ( num ) | 394 | if ( num ) |
395 | emit save(); | 395 | emit save(); |
396 | if ( num ) | 396 | if ( num ) |
397 | mParent->setCaption(i18n("%1 profiles synced. Multiple sync completed!").arg(num) ); | 397 | mParent->topLevelWidget()->setCaption(i18n("%1 profiles synced. Multiple sync completed!").arg(num) ); |
398 | else | 398 | else |
399 | mParent->setCaption(i18n("Nothing synced! No profiles defined for multisync!")); | 399 | mParent->topLevelWidget()->setCaption(i18n("Nothing synced! No profiles defined for multisync!")); |
400 | return; | 400 | return; |
401 | } | 401 | } |
402 | int KSyncManager::ringSync() | 402 | int KSyncManager::ringSync() |
403 | { | 403 | { |
404 | int syncedProfiles = 0; | 404 | int syncedProfiles = 0; |
405 | unsigned int i; | 405 | unsigned int i; |
406 | QTime timer; | 406 | QTime timer; |
407 | KConfig config ( locateLocal( "config","ksyncprofilesrc" ) ); | 407 | KConfig config ( locateLocal( "config","ksyncprofilesrc" ) ); |
408 | QStringList syncProfileNames = mSyncProfileNames; | 408 | QStringList syncProfileNames = mSyncProfileNames; |
409 | KSyncProfile* temp = new KSyncProfile (); | 409 | KSyncProfile* temp = new KSyncProfile (); |
410 | mAskForPreferences = false; | 410 | mAskForPreferences = false; |
411 | for ( i = 0; i < syncProfileNames.count(); ++i ) { | 411 | for ( i = 0; i < syncProfileNames.count(); ++i ) { |
412 | mCurrentSyncProfile = i; | 412 | mCurrentSyncProfile = i; |
413 | temp->setName(syncProfileNames[mCurrentSyncProfile]); | 413 | temp->setName(syncProfileNames[mCurrentSyncProfile]); |
414 | temp->readConfig(&config); | 414 | temp->readConfig(&config); |
415 | 415 | ||
416 | QString includeInRingSync; | 416 | QString includeInRingSync; |
417 | switch(mTargetApp) | 417 | switch(mTargetApp) |
418 | { | 418 | { |
419 | case (KAPI): | 419 | case (KAPI): |
420 | includeInRingSync = temp->getIncludeInRingSyncAB(); | 420 | includeInRingSync = temp->getIncludeInRingSyncAB(); |
421 | break; | 421 | break; |
422 | case (KOPI): | 422 | case (KOPI): |
423 | includeInRingSync = temp->getIncludeInRingSync(); | 423 | includeInRingSync = temp->getIncludeInRingSync(); |
424 | break; | 424 | break; |
425 | case (PWMPI): | 425 | case (PWMPI): |
426 | includeInRingSync = temp->getIncludeInRingSyncPWM(); | 426 | includeInRingSync = temp->getIncludeInRingSyncPWM(); |
427 | break; | 427 | break; |
428 | default: | 428 | default: |
429 | qDebug("KSyncManager::ringSync: invalid apptype selected"); | 429 | qDebug("KSyncManager::ringSync: invalid apptype selected"); |
430 | break; | 430 | break; |
431 | 431 | ||
432 | } | 432 | } |
433 | 433 | ||
434 | 434 | ||
435 | if ( includeInRingSync && ( i < 1 || i > 2 )) { | 435 | if ( includeInRingSync && ( i < 1 || i > 2 )) { |
436 | mParent->setCaption(i18n("Profile ")+syncProfileNames[mCurrentSyncProfile]+ i18n(" is synced ... ")); | 436 | mParent->topLevelWidget()->setCaption(i18n("Profile ")+syncProfileNames[mCurrentSyncProfile]+ i18n(" is synced ... ")); |
437 | ++syncedProfiles; | 437 | ++syncedProfiles; |
438 | // mAskForPreferences = temp->getAskForPreferences(); | 438 | // mAskForPreferences = temp->getAskForPreferences(); |
439 | mWriteBackFile = temp->getWriteBackFile(); | 439 | mWriteBackFile = temp->getWriteBackFile(); |
440 | mWriteBackExistingOnly = temp->getWriteBackExisting(); | 440 | mWriteBackExistingOnly = temp->getWriteBackExisting(); |
441 | mWriteBackInFuture = 0; | 441 | mWriteBackInFuture = 0; |
442 | if ( temp->getWriteBackFuture() ) | 442 | if ( temp->getWriteBackFuture() ) |
443 | mWriteBackInFuture = temp->getWriteBackFutureWeeks( ); | 443 | mWriteBackInFuture = temp->getWriteBackFutureWeeks( ); |
444 | mShowSyncSummary = false; | 444 | mShowSyncSummary = false; |
445 | mCurrentSyncDevice = syncProfileNames[i] ; | 445 | mCurrentSyncDevice = syncProfileNames[i] ; |
446 | mCurrentSyncName = mLocalMachineName; | 446 | mCurrentSyncName = mLocalMachineName; |
447 | if ( i == 0 ) { | 447 | if ( i == 0 ) { |
448 | syncSharp(); | 448 | syncSharp(); |
449 | } else { | 449 | } else { |
450 | if ( temp->getIsLocalFileSync() ) { | 450 | if ( temp->getIsLocalFileSync() ) { |
451 | switch(mTargetApp) | 451 | switch(mTargetApp) |
452 | { | 452 | { |
453 | case (KAPI): | 453 | case (KAPI): |
454 | if ( syncWithFile( temp->getRemoteFileNameAB( ), false ) ) | 454 | if ( syncWithFile( temp->getRemoteFileNameAB( ), false ) ) |
455 | mLastSyncedLocalFile = temp->getRemoteFileNameAB(); | 455 | mLastSyncedLocalFile = temp->getRemoteFileNameAB(); |
456 | break; | 456 | break; |
457 | case (KOPI): | 457 | case (KOPI): |
458 | if ( syncWithFile( temp->getRemoteFileName( ), false ) ) | 458 | if ( syncWithFile( temp->getRemoteFileName( ), false ) ) |
459 | mLastSyncedLocalFile = temp->getRemoteFileName(); | 459 | mLastSyncedLocalFile = temp->getRemoteFileName(); |
460 | break; | 460 | break; |
461 | case (PWMPI): | 461 | case (PWMPI): |
462 | if ( syncWithFile( temp->getRemoteFileNamePWM( ), false ) ) | 462 | if ( syncWithFile( temp->getRemoteFileNamePWM( ), false ) ) |
463 | mLastSyncedLocalFile = temp->getRemoteFileNamePWM(); | 463 | mLastSyncedLocalFile = temp->getRemoteFileNamePWM(); |
464 | break; | 464 | break; |
465 | default: | 465 | default: |
466 | qDebug("KSyncManager::slotSyncMenu: invalid apptype selected"); | 466 | qDebug("KSyncManager::slotSyncMenu: invalid apptype selected"); |
467 | break; | 467 | break; |
468 | } | 468 | } |
469 | } else { | 469 | } else { |
470 | if ( temp->getIsPhoneSync() ) { | 470 | if ( temp->getIsPhoneSync() ) { |
471 | mPhoneDevice = temp->getPhoneDevice( ) ; | 471 | mPhoneDevice = temp->getPhoneDevice( ) ; |
472 | mPhoneConnection = temp->getPhoneConnection( ); | 472 | mPhoneConnection = temp->getPhoneConnection( ); |
473 | mPhoneModel = temp->getPhoneModel( ); | 473 | mPhoneModel = temp->getPhoneModel( ); |
474 | syncPhone(); | 474 | syncPhone(); |
475 | } else | 475 | } else |
476 | syncRemote( temp, false ); | 476 | syncRemote( temp, false ); |
477 | 477 | ||
478 | } | 478 | } |
479 | } | 479 | } |
480 | timer.start(); | 480 | timer.start(); |
481 | mParent->setCaption(i18n("Multiple sync in progress ... please wait!") ); | 481 | mParent->topLevelWidget()->setCaption(i18n("Multiple sync in progress ... please wait!") ); |
482 | while ( timer.elapsed () < 2000 ) { | 482 | while ( timer.elapsed () < 2000 ) { |
483 | qApp->processEvents(); | 483 | qApp->processEvents(); |
484 | #ifndef _WIN32_ | 484 | #ifndef _WIN32_ |
485 | sleep (1); | 485 | sleep (1); |
486 | #endif | 486 | #endif |
487 | } | 487 | } |
488 | 488 | ||
489 | } | 489 | } |
490 | 490 | ||
491 | } | 491 | } |
492 | delete temp; | 492 | delete temp; |
493 | return syncedProfiles; | 493 | return syncedProfiles; |
494 | } | 494 | } |
495 | 495 | ||
496 | void KSyncManager::syncRemote( KSyncProfile* prof, bool ask) | 496 | void KSyncManager::syncRemote( KSyncProfile* prof, bool ask) |
497 | { | 497 | { |
498 | QString question; | 498 | QString question; |
499 | if ( ask ) { | 499 | if ( ask ) { |
500 | question = i18n("Do you really want\nto remote sync\nwith profile \n")+ prof->getName()+" ?\n"; | 500 | question = i18n("Do you really want\nto remote sync\nwith profile \n")+ prof->getName()+" ?\n"; |
501 | if ( QMessageBox::information( mParent, i18n("Sync"), | 501 | if ( QMessageBox::information( mParent, i18n("Sync"), |
502 | question, | 502 | question, |
503 | i18n("Yes"), i18n("No"), | 503 | i18n("Yes"), i18n("No"), |
504 | 0, 0 ) != 0 ) | 504 | 0, 0 ) != 0 ) |
505 | return; | 505 | return; |
506 | } | 506 | } |
507 | 507 | ||
508 | QString preCommand; | 508 | QString preCommand; |
509 | QString localTempFile; | 509 | QString localTempFile; |
510 | QString postCommand; | 510 | QString postCommand; |
511 | 511 | ||
512 | switch(mTargetApp) | 512 | switch(mTargetApp) |
513 | { | 513 | { |
514 | case (KAPI): | 514 | case (KAPI): |
515 | preCommand = prof->getPreSyncCommandAB(); | 515 | preCommand = prof->getPreSyncCommandAB(); |
516 | postCommand = prof->getPostSyncCommandAB(); | 516 | postCommand = prof->getPostSyncCommandAB(); |
517 | localTempFile = prof->getLocalTempFileAB(); | 517 | localTempFile = prof->getLocalTempFileAB(); |
518 | break; | 518 | break; |
519 | case (KOPI): | 519 | case (KOPI): |
520 | preCommand = prof->getPreSyncCommand(); | 520 | preCommand = prof->getPreSyncCommand(); |
521 | postCommand = prof->getPostSyncCommand(); | 521 | postCommand = prof->getPostSyncCommand(); |
522 | localTempFile = prof->getLocalTempFile(); | 522 | localTempFile = prof->getLocalTempFile(); |
523 | break; | 523 | break; |
524 | case (PWMPI): | 524 | case (PWMPI): |
525 | preCommand = prof->getPreSyncCommandPWM(); | 525 | preCommand = prof->getPreSyncCommandPWM(); |
526 | postCommand = prof->getPostSyncCommandPWM(); | 526 | postCommand = prof->getPostSyncCommandPWM(); |
527 | localTempFile = prof->getLocalTempFilePWM(); | 527 | localTempFile = prof->getLocalTempFilePWM(); |
528 | break; | 528 | break; |
529 | default: | 529 | default: |
530 | qDebug("KSyncManager::syncRemote: invalid apptype selected"); | 530 | qDebug("KSyncManager::syncRemote: invalid apptype selected"); |
531 | break; | 531 | break; |
532 | } | 532 | } |
533 | 533 | ||
534 | 534 | ||
535 | int fi; | 535 | int fi; |
536 | if ( (fi = preCommand.find("$PWD$")) > 0 ) { | 536 | if ( (fi = preCommand.find("$PWD$")) > 0 ) { |
537 | QString pwd = getPassword(); | 537 | QString pwd = getPassword(); |
538 | preCommand = preCommand.left( fi )+ pwd + preCommand.mid( fi+5 ); | 538 | preCommand = preCommand.left( fi )+ pwd + preCommand.mid( fi+5 ); |
539 | 539 | ||
540 | } | 540 | } |
541 | int maxlen = 30; | 541 | int maxlen = 30; |
542 | if ( QApplication::desktop()->width() > 320 ) | 542 | if ( QApplication::desktop()->width() > 320 ) |
543 | maxlen += 25; | 543 | maxlen += 25; |
544 | mParent->setCaption ( i18n( "Copy remote file to local machine..." ) ); | 544 | mParent->topLevelWidget()->setCaption ( i18n( "Copy remote file to local machine..." ) ); |
545 | int fileSize = 0; | 545 | int fileSize = 0; |
546 | int result = system ( preCommand ); | 546 | int result = system ( preCommand ); |
547 | // 0 : okay | 547 | // 0 : okay |
548 | // 256: no such file or dir | 548 | // 256: no such file or dir |
549 | // | 549 | // |
550 | qDebug("KO: Remote copy result(0 = okay): %d ",result ); | 550 | qDebug("KO: Remote copy result(0 = okay): %d ",result ); |
551 | if ( result != 0 ) { | 551 | if ( result != 0 ) { |
552 | unsigned int len = maxlen; | 552 | unsigned int len = maxlen; |
553 | while ( len < preCommand.length() ) { | 553 | while ( len < preCommand.length() ) { |
554 | preCommand.insert( len , "\n" ); | 554 | preCommand.insert( len , "\n" ); |
555 | len += maxlen +2; | 555 | len += maxlen +2; |
556 | } | 556 | } |
557 | question = i18n("Sorry, the copy command failed!\nCommand was:\n%1\n \nTry command on console to get more\ndetailed info about the reason.\n").arg (preCommand) ; | 557 | question = i18n("Sorry, the copy command failed!\nCommand was:\n%1\n \nTry command on console to get more\ndetailed info about the reason.\n").arg (preCommand) ; |
558 | QMessageBox::information( mParent, i18n("Sync - ERROR"), | 558 | QMessageBox::information( mParent, i18n("Sync - ERROR"), |
559 | question, | 559 | question, |
560 | i18n("Okay!")) ; | 560 | i18n("Okay!")) ; |
561 | mParent->setCaption (""); | 561 | mParent->topLevelWidget()->setCaption (""); |
562 | return; | 562 | return; |
563 | } | 563 | } |
564 | mParent->setCaption ( i18n( "Copying succeed." ) ); | 564 | mParent->topLevelWidget()->setCaption ( i18n( "Copying succeed." ) ); |
565 | //qDebug(" file **%s** ",prof->getLocalTempFile().latin1() ); | 565 | //qDebug(" file **%s** ",prof->getLocalTempFile().latin1() ); |
566 | 566 | ||
567 | 567 | ||
568 | 568 | ||
569 | if ( syncWithFile( localTempFile, true ) ) { | 569 | if ( syncWithFile( localTempFile, true ) ) { |
570 | // Event* e = mView->getLastSyncEvent(); | 570 | // Event* e = mView->getLastSyncEvent(); |
571 | // e->setReadOnly( false ); | 571 | // e->setReadOnly( false ); |
572 | // e->setLocation( KOPrefs::instance()->mSyncProfileNames[mCurrentSyncProfile]); | 572 | // e->setLocation( KOPrefs::instance()->mSyncProfileNames[mCurrentSyncProfile]); |
573 | // e->setReadOnly( true ); | 573 | // e->setReadOnly( true ); |
574 | if ( mWriteBackFile ) { | 574 | if ( mWriteBackFile ) { |
575 | int fi; | 575 | int fi; |
576 | if ( (fi = postCommand.find("$PWD$")) > 0 ) { | 576 | if ( (fi = postCommand.find("$PWD$")) > 0 ) { |
577 | QString pwd = getPassword(); | 577 | QString pwd = getPassword(); |
578 | postCommand = postCommand.left( fi )+ pwd + postCommand.mid( fi+5 ); | 578 | postCommand = postCommand.left( fi )+ pwd + postCommand.mid( fi+5 ); |
579 | 579 | ||
580 | } | 580 | } |
581 | mParent->setCaption ( i18n( "Writing back file ..." ) ); | 581 | mParent->topLevelWidget()->setCaption ( i18n( "Writing back file ..." ) ); |
582 | result = system ( postCommand ); | 582 | result = system ( postCommand ); |
583 | qDebug("Writing back file result: %d ", result); | 583 | qDebug("Writing back file result: %d ", result); |
584 | if ( result != 0 ) { | 584 | if ( result != 0 ) { |
585 | mParent->setCaption ( i18n( "Writing back file result: " )+QString::number( result ) ); | 585 | mParent->topLevelWidget()->setCaption ( i18n( "Writing back file result: " )+QString::number( result ) ); |
586 | return; | 586 | return; |
587 | } else { | 587 | } else { |
588 | mParent->setCaption ( i18n( "Syncronization sucessfully completed" ) ); | 588 | mParent->topLevelWidget()->setCaption ( i18n( "Syncronization sucessfully completed" ) ); |
589 | } | 589 | } |
590 | } | 590 | } |
591 | } | 591 | } |
592 | return; | 592 | return; |
593 | } | 593 | } |
594 | 594 | ||
595 | void KSyncManager::edit_sync_options() | 595 | void KSyncManager::edit_sync_options() |
596 | { | 596 | { |
597 | //mDialogManager->showSyncOptions(); | 597 | //mDialogManager->showSyncOptions(); |
598 | //mSyncAlgoPrefs | 598 | //mSyncAlgoPrefs |
599 | QDialog dia( mParent, "dia", true ); | 599 | QDialog dia( mParent, "dia", true ); |
600 | dia.setCaption( i18n("Device: " ) +mCurrentSyncDevice ); | 600 | dia.setCaption( i18n("Device: " ) +mCurrentSyncDevice ); |
601 | QButtonGroup gr ( 1, Qt::Horizontal, i18n("Sync preferences"), &dia); | 601 | QButtonGroup gr ( 1, Qt::Horizontal, i18n("Sync preferences"), &dia); |
602 | QVBoxLayout lay ( &dia ); | 602 | QVBoxLayout lay ( &dia ); |
603 | lay.setSpacing( 2 ); | 603 | lay.setSpacing( 2 ); |
604 | lay.setMargin( 3 ); | 604 | lay.setMargin( 3 ); |
605 | lay.addWidget(&gr); | 605 | lay.addWidget(&gr); |
606 | QRadioButton loc ( i18n("Take local entry on conflict"), &gr ); | 606 | QRadioButton loc ( i18n("Take local entry on conflict"), &gr ); |
607 | QRadioButton rem ( i18n("Take remote entry on conflict"), &gr ); | 607 | QRadioButton rem ( i18n("Take remote entry on conflict"), &gr ); |
608 | QRadioButton newest( i18n("Take newest entry on conflict"), &gr ); | 608 | QRadioButton newest( i18n("Take newest entry on conflict"), &gr ); |
609 | QRadioButton ask( i18n("Ask for every entry on conflict"), &gr ); | 609 | QRadioButton ask( i18n("Ask for every entry on conflict"), &gr ); |
610 | QRadioButton f_loc( i18n("Force: Take local entry always"), &gr ); | 610 | QRadioButton f_loc( i18n("Force: Take local entry always"), &gr ); |
611 | QRadioButton f_rem( i18n("Force: Take remote entry always"), &gr ); | 611 | QRadioButton f_rem( i18n("Force: Take remote entry always"), &gr ); |
612 | //QRadioButton both( i18n("Take both on conflict"), &gr ); | 612 | //QRadioButton both( i18n("Take both on conflict"), &gr ); |
613 | QPushButton pb ( "OK", &dia); | 613 | QPushButton pb ( "OK", &dia); |
614 | lay.addWidget( &pb ); | 614 | lay.addWidget( &pb ); |
615 | connect(&pb, SIGNAL( clicked() ), &dia, SLOT ( accept() ) ); | 615 | connect(&pb, SIGNAL( clicked() ), &dia, SLOT ( accept() ) ); |
616 | switch ( mSyncAlgoPrefs ) { | 616 | switch ( mSyncAlgoPrefs ) { |
617 | case 0: | 617 | case 0: |
618 | loc.setChecked( true); | 618 | loc.setChecked( true); |
619 | break; | 619 | break; |
620 | case 1: | 620 | case 1: |
621 | rem.setChecked( true ); | 621 | rem.setChecked( true ); |
622 | break; | 622 | break; |
623 | case 2: | 623 | case 2: |
624 | newest.setChecked( true); | 624 | newest.setChecked( true); |
625 | break; | 625 | break; |
626 | case 3: | 626 | case 3: |
627 | ask.setChecked( true); | 627 | ask.setChecked( true); |
628 | break; | 628 | break; |
629 | case 4: | 629 | case 4: |
630 | f_loc.setChecked( true); | 630 | f_loc.setChecked( true); |
631 | break; | 631 | break; |
632 | case 5: | 632 | case 5: |
633 | f_rem.setChecked( true); | 633 | f_rem.setChecked( true); |
634 | break; | 634 | break; |
635 | case 6: | 635 | case 6: |
636 | // both.setChecked( true); | 636 | // both.setChecked( true); |
@@ -704,285 +704,264 @@ bool KSyncManager::syncExternalApplication(QString resource) | |||
704 | 704 | ||
705 | qDebug("sync %s", resource.latin1()); | 705 | qDebug("sync %s", resource.latin1()); |
706 | 706 | ||
707 | bool syncOK = mImplementation->syncExternal(this, resource); | 707 | bool syncOK = mImplementation->syncExternal(this, resource); |
708 | 708 | ||
709 | return syncOK; | 709 | return syncOK; |
710 | 710 | ||
711 | } | 711 | } |
712 | 712 | ||
713 | void KSyncManager::syncPhone() | 713 | void KSyncManager::syncPhone() |
714 | { | 714 | { |
715 | emit save(); | 715 | emit save(); |
716 | 716 | ||
717 | qDebug("pending syncPhone(); "); | 717 | qDebug("pending syncPhone(); "); |
718 | //mView->syncPhone(); | 718 | //mView->syncPhone(); |
719 | 719 | ||
720 | } | 720 | } |
721 | 721 | ||
722 | void KSyncManager::showProgressBar(int percentage, QString caption, int total) | 722 | void KSyncManager::showProgressBar(int percentage, QString caption, int total) |
723 | { | 723 | { |
724 | if (!bar->isVisible()) | 724 | if (!bar->isVisible()) |
725 | { | 725 | { |
726 | bar->setCaption (caption); | 726 | bar->setCaption (caption); |
727 | bar->setTotalSteps ( total ) ; | 727 | bar->setTotalSteps ( total ) ; |
728 | 728 | ||
729 | bar->show(); | 729 | bar->show(); |
730 | } | 730 | } |
731 | 731 | ||
732 | bar->setProgress( percentage ); | 732 | bar->setProgress( percentage ); |
733 | } | 733 | } |
734 | 734 | ||
735 | void KSyncManager::hideProgressBar() | 735 | void KSyncManager::hideProgressBar() |
736 | { | 736 | { |
737 | bar->hide(); | 737 | bar->hide(); |
738 | } | 738 | } |
739 | 739 | ||
740 | bool KSyncManager::isProgressBarCanceled() | 740 | bool KSyncManager::isProgressBarCanceled() |
741 | { | 741 | { |
742 | return !bar->isVisible(); | 742 | return !bar->isVisible(); |
743 | } | 743 | } |
744 | 744 | ||
745 | QString KSyncManager::syncFileName() | 745 | QString KSyncManager::syncFileName() |
746 | { | 746 | { |
747 | 747 | ||
748 | QString fn = "tempfile"; | 748 | QString fn = "tempfile"; |
749 | switch(mTargetApp) | 749 | switch(mTargetApp) |
750 | { | 750 | { |
751 | case (KAPI): | 751 | case (KAPI): |
752 | fn = "addressbook.vcf"; | 752 | fn = "tempsyncab.vcf"; |
753 | break; | 753 | break; |
754 | case (KOPI): | 754 | case (KOPI): |
755 | fn = "synccalendar.ics"; | 755 | fn = "tempsynccal.ics"; |
756 | break; | 756 | break; |
757 | case (PWMPI): | 757 | case (PWMPI): |
758 | fn = "manager.pwm"; | 758 | fn = "tempsyncpw.pwm"; |
759 | break; | 759 | break; |
760 | default: | 760 | default: |
761 | break; | 761 | break; |
762 | } | 762 | } |
763 | #ifdef _WIN32_ | 763 | #ifdef _WIN32_ |
764 | return locateLocal( "tmp", fn ); | 764 | return locateLocal( "tmp", fn ); |
765 | #else | 765 | #else |
766 | return (QString( "/tmp/" )+ fn ); | 766 | return (QString( "/tmp/" )+ fn ); |
767 | #endif | 767 | #endif |
768 | } | 768 | } |
769 | 769 | ||
770 | void KSyncManager::syncPi() | 770 | void KSyncManager::syncPi() |
771 | { | 771 | { |
772 | qApp->processEvents(); | 772 | qApp->processEvents(); |
773 | bool ok; | 773 | bool ok; |
774 | Q_UINT16 port = mActiveSyncPort.toUInt(&ok); | 774 | Q_UINT16 port = mActiveSyncPort.toUInt(&ok); |
775 | if ( ! ok ) { | 775 | if ( ! ok ) { |
776 | mParent->setCaption( i18n("Sorry, no valid port.Syncing cancelled.") ); | 776 | mParent->topLevelWidget()->setCaption( i18n("Sorry, no valid port.Syncing cancelled.") ); |
777 | return; | 777 | return; |
778 | } | 778 | } |
779 | KCommandSocket* commandSocket = new KCommandSocket( mPassWordPiSync, port, mActiveSyncIP, this ); | 779 | KCommandSocket* commandSocket = new KCommandSocket( mPassWordPiSync, port, mActiveSyncIP, this ); |
780 | connect( commandSocket, SIGNAL(commandFinished( KCommandSocket*, int )), this, SLOT(deleteCommandSocket(KCommandSocket*, int)) ); | 780 | connect( commandSocket, SIGNAL(commandFinished( KCommandSocket*, int )), this, SLOT(deleteCommandSocket(KCommandSocket*, int)) ); |
781 | mParent->setCaption( i18n("Sending request for remote file ...") ); | 781 | mParent->topLevelWidget()->setCaption( i18n("Sending request for remote file ...") ); |
782 | commandSocket->readFile( syncFileName() ); | 782 | commandSocket->readFile( syncFileName() ); |
783 | } | 783 | } |
784 | 784 | ||
785 | void KSyncManager::deleteCommandSocket(KCommandSocket*s, int state) | 785 | void KSyncManager::deleteCommandSocket(KCommandSocket*s, int state) |
786 | { | 786 | { |
787 | qDebug("MainWindow::deleteCommandSocket %d", state); | 787 | qDebug("MainWindow::deleteCommandSocket %d", state); |
788 | 788 | ||
789 | //enum { success, errorW, errorR, quiet }; | 789 | //enum { success, errorW, errorR, quiet }; |
790 | if ( state == KCommandSocket::errorR ) { | 790 | if ( state == KCommandSocket::errorR ) { |
791 | mParent->setCaption( i18n("ERROR: Receiving remote file failed.") ); | 791 | mParent->topLevelWidget()->setCaption( i18n("ERROR: Receiving remote file failed.") ); |
792 | delete s; | 792 | delete s; |
793 | KCommandSocket* commandSocket = new KCommandSocket( mPassWordPiSync, mActiveSyncPort.toUInt(), mActiveSyncIP, this ); | 793 | KCommandSocket* commandSocket = new KCommandSocket( mPassWordPiSync, mActiveSyncPort.toUInt(), mActiveSyncIP, this ); |
794 | connect( commandSocket, SIGNAL(commandFinished( KCommandSocket*, int)), this, SLOT(deleteCommandSocket(KCommandSocket*, int )) ); | 794 | connect( commandSocket, SIGNAL(commandFinished( KCommandSocket*, int)), this, SLOT(deleteCommandSocket(KCommandSocket*, int )) ); |
795 | commandSocket->sendStop(); | 795 | commandSocket->sendStop(); |
796 | return; | 796 | return; |
797 | 797 | ||
798 | } else if ( state == KCommandSocket::errorW ) { | 798 | } else if ( state == KCommandSocket::errorW ) { |
799 | mParent->setCaption( i18n("ERROR:Writing back file failed.") ); | 799 | mParent->topLevelWidget()->setCaption( i18n("ERROR:Writing back file failed.") ); |
800 | 800 | ||
801 | } else if ( state == KCommandSocket::successR ) { | 801 | } else if ( state == KCommandSocket::successR ) { |
802 | QTimer::singleShot( 1, this , SLOT ( readFileFromSocket())); | 802 | QTimer::singleShot( 1, this , SLOT ( readFileFromSocket())); |
803 | 803 | ||
804 | } else if ( state == KCommandSocket::successW ) { | 804 | } else if ( state == KCommandSocket::successW ) { |
805 | mParent->setCaption( i18n("Pi-Sync succesful!") ); | 805 | mParent->topLevelWidget()->setCaption( i18n("Pi-Sync succesful!") ); |
806 | } | 806 | } |
807 | 807 | ||
808 | delete s; | 808 | delete s; |
809 | } | 809 | } |
810 | 810 | ||
811 | void KSyncManager::readFileFromSocket() | 811 | void KSyncManager::readFileFromSocket() |
812 | { | 812 | { |
813 | QString fileName = syncFileName(); | 813 | QString fileName = syncFileName(); |
814 | mParent->setCaption( i18n("Remote file saved to temp file.") ); | 814 | mParent->topLevelWidget()->setCaption( i18n("Remote file saved to temp file.") ); |
815 | if ( ! syncWithFile( fileName , true ) ) { | 815 | if ( ! syncWithFile( fileName , true ) ) { |
816 | mParent->setCaption( i18n("Syncing failed.") ); | 816 | mParent->topLevelWidget()->setCaption( i18n("Syncing failed.") ); |
817 | qDebug("Syncing failed "); | 817 | qDebug("Syncing failed "); |
818 | return; | 818 | return; |
819 | } | 819 | } |
820 | KCommandSocket* commandSocket = new KCommandSocket( mPassWordPiSync, mActiveSyncPort.toUInt(), mActiveSyncIP, this ); | 820 | KCommandSocket* commandSocket = new KCommandSocket( mPassWordPiSync, mActiveSyncPort.toUInt(), mActiveSyncIP, this ); |
821 | connect( commandSocket, SIGNAL(commandFinished( KCommandSocket*, int)), this, SLOT(deleteCommandSocket(KCommandSocket*, int )) ); | 821 | connect( commandSocket, SIGNAL(commandFinished( KCommandSocket*, int)), this, SLOT(deleteCommandSocket(KCommandSocket*, int )) ); |
822 | if ( mWriteBackFile ) | 822 | if ( mWriteBackFile ) |
823 | commandSocket->writeFile( fileName ); | 823 | commandSocket->writeFile( fileName ); |
824 | else { | 824 | else { |
825 | commandSocket->sendStop(); | 825 | commandSocket->sendStop(); |
826 | mParent->setCaption( i18n("Pi-Sync succesful!") ); | 826 | mParent->topLevelWidget()->setCaption( i18n("Pi-Sync succesful!") ); |
827 | } | 827 | } |
828 | } | 828 | } |
829 | 829 | ||
830 | |||
831 | |||
832 | |||
833 | |||
834 | |||
835 | |||
836 | |||
837 | |||
838 | |||
839 | |||
840 | |||
841 | |||
842 | |||
843 | |||
844 | |||
845 | |||
846 | |||
847 | |||
848 | |||
849 | |||
850 | |||
851 | |||
852 | KServerSocket:: KServerSocket ( QString pw, Q_UINT16 port, int backlog, QObject * parent, const char * name ) : QServerSocket( port, backlog, parent, name ) | 830 | KServerSocket:: KServerSocket ( QString pw, Q_UINT16 port, int backlog, QObject * parent, const char * name ) : QServerSocket( port, backlog, parent, name ) |
853 | { | 831 | { |
854 | mPassWord = pw; | 832 | mPassWord = pw; |
855 | mSocket = 0; | 833 | mSocket = 0; |
856 | mSyncActionDialog = 0; | 834 | mSyncActionDialog = 0; |
857 | blockRC = false; | 835 | blockRC = false; |
858 | }; | 836 | }; |
859 | 837 | ||
860 | void KServerSocket::newConnection ( int socket ) | 838 | void KServerSocket::newConnection ( int socket ) |
861 | { | 839 | { |
862 | // qDebug("KServerSocket:New connection %d ", socket); | 840 | // qDebug("KServerSocket:New connection %d ", socket); |
863 | if ( mSocket ) { | 841 | if ( mSocket ) { |
864 | qDebug("KServerSocket::newConnection Socket deleted! "); | 842 | qDebug("KServerSocket::newConnection Socket deleted! "); |
865 | delete mSocket; | 843 | delete mSocket; |
866 | mSocket = 0; | 844 | mSocket = 0; |
867 | } | 845 | } |
868 | mSocket = new QSocket( this ); | 846 | mSocket = new QSocket( this ); |
869 | connect( mSocket , SIGNAL(readyRead()), this, SLOT(readClient()) ); | 847 | connect( mSocket , SIGNAL(readyRead()), this, SLOT(readClient()) ); |
870 | connect( mSocket , SIGNAL(delayedCloseFinished()), this, SLOT(discardClient()) ); | 848 | connect( mSocket , SIGNAL(delayedCloseFinished()), this, SLOT(discardClient()) ); |
871 | mSocket->setSocket( socket ); | 849 | mSocket->setSocket( socket ); |
872 | } | 850 | } |
873 | 851 | ||
874 | void KServerSocket::discardClient() | 852 | void KServerSocket::discardClient() |
875 | { | 853 | { |
876 | //qDebug(" KServerSocket::discardClient()"); | 854 | //qDebug(" KServerSocket::discardClient()"); |
877 | if ( mSocket ) { | 855 | if ( mSocket ) { |
878 | delete mSocket; | 856 | delete mSocket; |
879 | mSocket = 0; | 857 | mSocket = 0; |
880 | } | 858 | } |
881 | //emit endConnect(); | 859 | //emit endConnect(); |
882 | } | 860 | } |
883 | void KServerSocket::readClient() | 861 | void KServerSocket::readClient() |
884 | { | 862 | { |
885 | if ( blockRC ) | 863 | if ( blockRC ) |
886 | return; | 864 | return; |
887 | if ( mSocket == 0 ) { | 865 | if ( mSocket == 0 ) { |
888 | qDebug("ERROR::KServerSocket::readClient(): mSocket == 0 "); | 866 | qDebug("ERROR::KServerSocket::readClient(): mSocket == 0 "); |
889 | return; | 867 | return; |
890 | } | 868 | } |
891 | qDebug("KServerSocket readClient()"); | 869 | qDebug("KServerSocket readClient()"); |
892 | if ( mSocket->canReadLine() ) { | 870 | if ( mSocket->canReadLine() ) { |
893 | QString line = mSocket->readLine(); | 871 | QString line = mSocket->readLine(); |
894 | qDebug("KServerSocket readline: %s ", line.latin1()); | 872 | qDebug("KServerSocket readline: %s ", line.latin1()); |
895 | QStringList tokens = QStringList::split( QRegExp("[ \r\n][ \r\n]*"), line ); | 873 | QStringList tokens = QStringList::split( QRegExp("[ \r\n][ \r\n]*"), line ); |
896 | if ( tokens[0] == "GET" ) { | 874 | if ( tokens[0] == "GET" ) { |
897 | if ( tokens[1] == mPassWord ) | 875 | if ( tokens[1] == mPassWord ) |
898 | //emit sendFile( mSocket ); | 876 | //emit sendFile( mSocket ); |
899 | send_file(); | 877 | send_file(); |
900 | else { | 878 | else { |
901 | KMessageBox::information( 0, i18n("ERROR:\nGot send file request\nwith invalid password")); | 879 | KMessageBox::information( 0, i18n("ERROR:\nGot send file request\nwith invalid password")); |
902 | qDebug("password %s, invalid password %s ",mPassWord.latin1(), tokens[1].latin1() ); | 880 | qDebug("password %s, invalid password %s ",mPassWord.latin1(), tokens[1].latin1() ); |
903 | } | 881 | } |
904 | } | 882 | } |
905 | if ( tokens[0] == "PUT" ) { | 883 | if ( tokens[0] == "PUT" ) { |
906 | if ( tokens[1] == mPassWord ) { | 884 | if ( tokens[1] == mPassWord ) { |
907 | //emit getFile( mSocket ); | 885 | //emit getFile( mSocket ); |
908 | blockRC = true; | 886 | blockRC = true; |
909 | get_file(); | 887 | get_file(); |
910 | } | 888 | } |
911 | else { | 889 | else { |
912 | KMessageBox::information( 0, i18n("ERROR:\nGot receive file request\nwith invalid password")); | 890 | KMessageBox::information( 0, i18n("ERROR:\nGot receive file request\nwith invalid password")); |
913 | qDebug("password %s, invalid password %s ",mPassWord.latin1(), tokens[1].latin1() ); | 891 | qDebug("password %s, invalid password %s ",mPassWord.latin1(), tokens[1].latin1() ); |
914 | } | 892 | } |
915 | } | 893 | } |
916 | if ( tokens[0] == "STOP" ) { | 894 | if ( tokens[0] == "STOP" ) { |
917 | //emit endConnect(); | 895 | //emit endConnect(); |
918 | end_connect(); | 896 | end_connect(); |
919 | } | 897 | } |
920 | } | 898 | } |
921 | } | 899 | } |
922 | void KServerSocket::end_connect() | 900 | void KServerSocket::end_connect() |
923 | { | 901 | { |
924 | delete mSyncActionDialog; | 902 | delete mSyncActionDialog; |
925 | mSyncActionDialog = 0; | 903 | mSyncActionDialog = 0; |
926 | } | 904 | } |
927 | void KServerSocket::send_file() | 905 | void KServerSocket::send_file() |
928 | { | 906 | { |
929 | //qDebug("MainWindow::sendFile(QSocket* s) "); | 907 | //qDebug("MainWindow::sendFile(QSocket* s) "); |
930 | if ( mSyncActionDialog ) | 908 | if ( mSyncActionDialog ) |
931 | delete mSyncActionDialog; | 909 | delete mSyncActionDialog; |
932 | mSyncActionDialog = new QDialog ( 0, "input-dialog", true ); | 910 | mSyncActionDialog = new QDialog ( 0, "input-dialog", true ); |
933 | mSyncActionDialog->setCaption(i18n("Received sync request")); | 911 | mSyncActionDialog->setCaption(i18n("Received sync request")); |
934 | QLabel* label = new QLabel( i18n("Synchronizing from remote ...\n\nDo not use this application!\n\nIf syncing fails\nyou can close this dialog."), mSyncActionDialog ); | 912 | QLabel* label = new QLabel( i18n("Synchronizing from remote ...\n\nDo not use this application!\n\nIf syncing fails\nyou can close this dialog."), mSyncActionDialog ); |
935 | QVBoxLayout* lay = new QVBoxLayout( mSyncActionDialog ); | 913 | QVBoxLayout* lay = new QVBoxLayout( mSyncActionDialog ); |
936 | lay->addWidget( label); | 914 | lay->addWidget( label); |
937 | lay->setMargin(7); | 915 | lay->setMargin(7); |
938 | lay->setSpacing(7); | 916 | lay->setSpacing(7); |
939 | mSyncActionDialog->setFixedSize( 230, 120); | 917 | mSyncActionDialog->setFixedSize( 230, 120); |
940 | mSyncActionDialog->show(); | 918 | mSyncActionDialog->show(); |
919 | mSyncActionDialog->raise(); | ||
941 | qDebug("KSS::saving ... "); | 920 | qDebug("KSS::saving ... "); |
942 | emit request_file(); | 921 | emit request_file(); |
943 | qApp->processEvents(); | 922 | qApp->processEvents(); |
944 | QString fileName = mFileName; | 923 | QString fileName = mFileName; |
945 | QFile file( fileName ); | 924 | QFile file( fileName ); |
946 | if (!file.open( IO_ReadOnly ) ) { | 925 | if (!file.open( IO_ReadOnly ) ) { |
947 | delete mSyncActionDialog; | 926 | delete mSyncActionDialog; |
948 | mSyncActionDialog = 0; | 927 | mSyncActionDialog = 0; |
949 | qDebug("KSS::error open file "); | 928 | qDebug("KSS::error open file "); |
950 | mSocket->close(); | 929 | mSocket->close(); |
951 | if ( mSocket->state() == QSocket::Idle ) | 930 | if ( mSocket->state() == QSocket::Idle ) |
952 | QTimer::singleShot( 10, this , SLOT ( discardClient())); | 931 | QTimer::singleShot( 10, this , SLOT ( discardClient())); |
953 | return ; | 932 | return ; |
954 | 933 | ||
955 | } | 934 | } |
956 | mSyncActionDialog->setCaption( i18n("Sending file...") ); | 935 | mSyncActionDialog->setCaption( i18n("Sending file...") ); |
957 | QTextStream ts( &file ); | 936 | QTextStream ts( &file ); |
958 | ts.setCodec( QTextCodec::codecForName("utf8") ); | 937 | ts.setCodec( QTextCodec::codecForName("utf8") ); |
959 | QTextStream os( mSocket ); | 938 | QTextStream os( mSocket ); |
960 | os.setCodec( QTextCodec::codecForName("utf8") ); | 939 | os.setCodec( QTextCodec::codecForName("utf8") ); |
961 | //os.setEncoding( QTextStream::UnicodeUTF8 ); | 940 | //os.setEncoding( QTextStream::UnicodeUTF8 ); |
962 | while ( ! ts.atEnd() ) { | 941 | while ( ! ts.atEnd() ) { |
963 | os << ts.readLine() << "\n"; | 942 | os << ts.readLine() << "\n"; |
964 | } | 943 | } |
965 | //os << ts.read(); | 944 | //os << ts.read(); |
966 | file.close(); | 945 | file.close(); |
967 | mSyncActionDialog->setCaption( i18n("Waiting for synced file...") ); | 946 | mSyncActionDialog->setCaption( i18n("Waiting for synced file...") ); |
968 | mSocket->close(); | 947 | mSocket->close(); |
969 | if ( mSocket->state() == QSocket::Idle ) | 948 | if ( mSocket->state() == QSocket::Idle ) |
970 | QTimer::singleShot( 10, this , SLOT ( discardClient())); | 949 | QTimer::singleShot( 10, this , SLOT ( discardClient())); |
971 | } | 950 | } |
972 | void KServerSocket::get_file() | 951 | void KServerSocket::get_file() |
973 | { | 952 | { |
974 | mSyncActionDialog->setCaption( i18n("Receiving synced file...") ); | 953 | mSyncActionDialog->setCaption( i18n("Receiving synced file...") ); |
975 | 954 | ||
976 | piTime.start(); | 955 | piTime.start(); |
977 | piFileString = ""; | 956 | piFileString = ""; |
978 | QTimer::singleShot( 1, this , SLOT (readBackFileFromSocket( ) )); | 957 | QTimer::singleShot( 1, this , SLOT (readBackFileFromSocket( ) )); |
979 | } | 958 | } |
980 | 959 | ||
981 | 960 | ||
982 | void KServerSocket::readBackFileFromSocket() | 961 | void KServerSocket::readBackFileFromSocket() |
983 | { | 962 | { |
984 | //qDebug("readBackFileFromSocket() %d ", piTime.elapsed ()); | 963 | //qDebug("readBackFileFromSocket() %d ", piTime.elapsed ()); |
985 | while ( mSocket->canReadLine () ) { | 964 | while ( mSocket->canReadLine () ) { |
986 | piTime.restart(); | 965 | piTime.restart(); |
987 | QString line = mSocket->readLine (); | 966 | QString line = mSocket->readLine (); |
988 | piFileString += line; | 967 | piFileString += line; |