-rw-r--r-- | libkdepim/ksyncmanager.cpp | 13 | ||||
-rw-r--r-- | libkdepim/ksyncmanager.h | 2 |
2 files changed, 9 insertions, 6 deletions
diff --git a/libkdepim/ksyncmanager.cpp b/libkdepim/ksyncmanager.cpp index 9177f63..c8d0e0d 100644 --- a/libkdepim/ksyncmanager.cpp +++ b/libkdepim/ksyncmanager.cpp | |||
@@ -11,138 +11,142 @@ | |||
11 | but WITHOUT ANY WARRANTY; without even the implied warranty of | 11 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
13 | Library General Public License for more details. | 13 | Library General Public License for more details. |
14 | 14 | ||
15 | You should have received a copy of the GNU Library General Public License | 15 | You should have received a copy of the GNU Library General Public License |
16 | along with this library; see the file COPYING.LIB. If not, write to | 16 | along with this library; see the file COPYING.LIB. If not, write to |
17 | the Free Software Foundation, Inc., 59 Temple Place - Suite 330, | 17 | the Free Software Foundation, Inc., 59 Temple Place - Suite 330, |
18 | Boston, MA 02111-1307, USA. | 18 | Boston, MA 02111-1307, USA. |
19 | */ | 19 | */ |
20 | 20 | ||
21 | // $Id$ | 21 | // $Id$ |
22 | 22 | ||
23 | #include "ksyncmanager.h" | 23 | #include "ksyncmanager.h" |
24 | 24 | ||
25 | #include <stdlib.h> | 25 | #include <stdlib.h> |
26 | 26 | ||
27 | #ifndef _WIN32_ | 27 | #ifndef _WIN32_ |
28 | #include <unistd.h> | 28 | #include <unistd.h> |
29 | #endif | 29 | #endif |
30 | 30 | ||
31 | 31 | ||
32 | #include "ksyncprofile.h" | 32 | #include "ksyncprofile.h" |
33 | #include "ksyncprefsdialog.h" | 33 | #include "ksyncprefsdialog.h" |
34 | #include "kpimprefs.h" | 34 | #include "kpimprefs.h" |
35 | #include <kmessagebox.h> | 35 | #include <kmessagebox.h> |
36 | 36 | ||
37 | #include <qdir.h> | 37 | #include <qdir.h> |
38 | #include <qprogressbar.h> | 38 | #include <qprogressbar.h> |
39 | #include <qpopupmenu.h> | 39 | #include <qpopupmenu.h> |
40 | #include <qpushbutton.h> | 40 | #include <qpushbutton.h> |
41 | #include <qradiobutton.h> | 41 | #include <qradiobutton.h> |
42 | #include <qbuttongroup.h> | 42 | #include <qbuttongroup.h> |
43 | #include <qtimer.h> | 43 | #include <qtimer.h> |
44 | #include <qmessagebox.h> | 44 | #include <qmessagebox.h> |
45 | #include <qapplication.h> | 45 | #include <qapplication.h> |
46 | #include <qlineedit.h> | 46 | #include <qlineedit.h> |
47 | #include <qdialog.h> | 47 | #include <qdialog.h> |
48 | #include <qlayout.h> | 48 | #include <qlayout.h> |
49 | #include <qtextcodec.h> | 49 | #include <qtextcodec.h> |
50 | #include <qlabel.h> | 50 | #include <qlabel.h> |
51 | #include <qcheckbox.h> | 51 | #include <qcheckbox.h> |
52 | 52 | ||
53 | #include <klocale.h> | 53 | #include <klocale.h> |
54 | #include <kglobal.h> | 54 | #include <kglobal.h> |
55 | #include <kconfig.h> | 55 | #include <kconfig.h> |
56 | #include <kfiledialog.h> | 56 | #include <kfiledialog.h> |
57 | 57 | ||
58 | QDateTime KSyncManager::mRequestedSyncEvent; | 58 | QDateTime KSyncManager::mRequestedSyncEvent; |
59 | 59 | ||
60 | 60 | ||
61 | KSyncManager::KSyncManager(QWidget* parent, KSyncInterface* implementation, TargetApp ta, KPimPrefs* prefs, QPopupMenu* syncmenu) | 61 | KSyncManager::KSyncManager(QWidget* parent, KSyncInterface* implementation, TargetApp ta, KPimPrefs* prefs, QPopupMenu* syncmenu) |
62 | : QObject(), mPrefs(prefs ), mParent(parent),mImplementation(implementation), mTargetApp(ta), mSyncMenu(syncmenu) | 62 | : QObject(), mPrefs(prefs ), mParent(parent),mImplementation(implementation), mTargetApp(ta), mSyncMenu(syncmenu) |
63 | { | 63 | { |
64 | mServerSocket = 0; | 64 | mServerSocket = 0; |
65 | bar = new QProgressBar ( 1, 0 ); | 65 | bar = new QProgressBar ( 1, 0 ); |
66 | bar->setCaption (""); | 66 | bar->setCaption (""); |
67 | mWriteBackInPast = 2; | 67 | mWriteBackInPast = 2; |
68 | int w = 300; | 68 | int w = 300; |
69 | if ( QApplication::desktop()->width() < 320 ) | 69 | if ( QApplication::desktop()->width() < 320 ) |
70 | w = 220; | 70 | w = 220; |
71 | int h = bar->sizeHint().height() ; | 71 | int h = bar->sizeHint().height() ; |
72 | int dw = QApplication::desktop()->width(); | 72 | int dw = QApplication::desktop()->width(); |
73 | int dh = QApplication::desktop()->height(); | 73 | int dh = QApplication::desktop()->height(); |
74 | bar->setGeometry( (dw-w)/2, (dh - h )/2 ,w,h ); | 74 | bar->setGeometry( (dw-w)/2, (dh - h )/2 ,w,h ); |
75 | if ( mPrefs->mPassiveSyncAutoStart ) | ||
76 | enableQuick( false ); | ||
77 | 75 | ||
78 | } | 76 | } |
79 | 77 | ||
80 | KSyncManager::~KSyncManager() | 78 | KSyncManager::~KSyncManager() |
81 | { | 79 | { |
82 | delete bar; | 80 | delete bar; |
83 | } | 81 | } |
84 | 82 | ||
83 | void KSyncManager::setDefaultFileName( QString s) | ||
84 | { | ||
85 | mDefFileName = s ; | ||
86 | if ( mPrefs->mPassiveSyncAutoStart ) | ||
87 | enableQuick( false ); | ||
88 | } | ||
85 | 89 | ||
86 | void KSyncManager::fillSyncMenu() | 90 | void KSyncManager::fillSyncMenu() |
87 | { | 91 | { |
88 | if ( mSyncMenu->count() ) | 92 | if ( mSyncMenu->count() ) |
89 | mSyncMenu->clear(); | 93 | mSyncMenu->clear(); |
90 | 94 | ||
91 | mSyncMenu->insertItem( i18n("Configure..."), 0 ); | 95 | mSyncMenu->insertItem( i18n("Configure..."), 0 ); |
92 | mSyncMenu->insertSeparator(); | 96 | mSyncMenu->insertSeparator(); |
93 | QPopupMenu *clearMenu = new QPopupMenu ( mSyncMenu ); | 97 | QPopupMenu *clearMenu = new QPopupMenu ( mSyncMenu ); |
94 | mSyncMenu->insertItem( i18n("Remove sync info"),clearMenu, 5000 ); | 98 | mSyncMenu->insertItem( i18n("Remove sync info"),clearMenu, 5000 ); |
95 | clearMenu->insertItem( i18n("For all profiles"), 1 ); | 99 | clearMenu->insertItem( i18n("For all profiles"), 1 ); |
96 | clearMenu->insertSeparator(); | 100 | clearMenu->insertSeparator(); |
97 | connect ( clearMenu, SIGNAL( activated ( int ) ), this, SLOT (slotClearMenu( int ) ) ); | 101 | connect ( clearMenu, SIGNAL( activated ( int ) ), this, SLOT (slotClearMenu( int ) ) ); |
98 | mSyncMenu->insertSeparator(); | 102 | mSyncMenu->insertSeparator(); |
99 | if ( mServerSocket == 0 ) { | 103 | if ( mServerSocket == 0 ) { |
100 | mSyncMenu->insertItem( i18n("Enable Pi-Sync"), 2 ); | 104 | mSyncMenu->insertItem( i18n("Enable Pi-Sync"), 2 ); |
101 | } else { | 105 | } else { |
102 | mSyncMenu->insertItem( i18n("Disable Pi-Sync"), 3 ); | 106 | mSyncMenu->insertItem( i18n("Disable Pi-Sync"), 3 ); |
103 | } | 107 | } |
104 | mSyncMenu->insertSeparator(); | 108 | mSyncMenu->insertSeparator(); |
105 | mSyncMenu->insertItem( i18n("Multiple sync"), 1 ); | 109 | mSyncMenu->insertItem( i18n("Multiple sync"), 1 ); |
106 | mSyncMenu->insertSeparator(); | 110 | mSyncMenu->insertSeparator(); |
107 | KConfig config ( locateLocal( "config","ksyncprofilesrc" ) ); | 111 | KConfig config ( locateLocal( "config","ksyncprofilesrc" ) ); |
108 | config.setGroup("General"); | 112 | config.setGroup("General"); |
109 | QStringList prof = config.readListEntry("SyncProfileNames"); | 113 | QStringList prof = config.readListEntry("SyncProfileNames"); |
110 | mLocalMachineName = config.readEntry("LocalMachineName","undefined"); | 114 | mLocalMachineName = config.readEntry("LocalMachineName","undefined"); |
111 | if ( prof.count() < 2 ) { | 115 | if ( prof.count() < 2 ) { |
112 | prof.clear(); | 116 | prof.clear(); |
113 | QString externalName; | 117 | QString externalName; |
114 | #ifdef DESKTOP_VERSION | 118 | #ifdef DESKTOP_VERSION |
115 | #ifdef _WIN32_ | 119 | #ifdef _WIN32_ |
116 | externalName = "OutLook(not_implemented)"; | 120 | externalName = "OutLook(not_implemented)"; |
117 | #else | 121 | #else |
118 | externalName = "KDE_Desktop"; | 122 | externalName = "KDE_Desktop"; |
119 | #endif | 123 | #endif |
120 | #else | 124 | #else |
121 | externalName = "Sharp_DTM"; | 125 | externalName = "Sharp_DTM"; |
122 | #endif | 126 | #endif |
123 | prof << externalName; | 127 | prof << externalName; |
124 | prof << i18n("Local_file"); | 128 | prof << i18n("Local_file"); |
125 | prof << i18n("Last_file"); | 129 | prof << i18n("Last_file"); |
126 | KSyncProfile* temp = new KSyncProfile (); | 130 | KSyncProfile* temp = new KSyncProfile (); |
127 | temp->setName( prof[0] ); | 131 | temp->setName( prof[0] ); |
128 | temp->writeConfig(&config); | 132 | temp->writeConfig(&config); |
129 | temp->setName( prof[1] ); | 133 | temp->setName( prof[1] ); |
130 | temp->writeConfig(&config); | 134 | temp->writeConfig(&config); |
131 | temp->setName( prof[2] ); | 135 | temp->setName( prof[2] ); |
132 | temp->writeConfig(&config); | 136 | temp->writeConfig(&config); |
133 | config.setGroup("General"); | 137 | config.setGroup("General"); |
134 | config.writeEntry("SyncProfileNames",prof); | 138 | config.writeEntry("SyncProfileNames",prof); |
135 | config.writeEntry("ExternSyncProfiles",externalName); | 139 | config.writeEntry("ExternSyncProfiles",externalName); |
136 | config.sync(); | 140 | config.sync(); |
137 | delete temp; | 141 | delete temp; |
138 | } | 142 | } |
139 | mExternSyncProfiles = config.readListEntry("ExternSyncProfiles"); | 143 | mExternSyncProfiles = config.readListEntry("ExternSyncProfiles"); |
140 | mSyncProfileNames = prof; | 144 | mSyncProfileNames = prof; |
141 | unsigned int i; | 145 | unsigned int i; |
142 | for ( i = 0; i < prof.count(); ++i ) { | 146 | for ( i = 0; i < prof.count(); ++i ) { |
143 | mSyncMenu->insertItem( prof[i], 1000+i ); | 147 | mSyncMenu->insertItem( prof[i], 1000+i ); |
144 | clearMenu->insertItem( prof[i], 1000+i ); | 148 | clearMenu->insertItem( prof[i], 1000+i ); |
145 | if ( i == 2 ) | 149 | if ( i == 2 ) |
146 | mSyncMenu->insertSeparator(); | 150 | mSyncMenu->insertSeparator(); |
147 | } | 151 | } |
148 | QDir app_dir; | 152 | QDir app_dir; |
@@ -351,129 +355,128 @@ void KSyncManager::enableQuick( bool ask ) | |||
351 | QLabel label2 ( i18n("Password to enable\naccess from remote:"), &dia ); | 355 | QLabel label2 ( i18n("Password to enable\naccess from remote:"), &dia ); |
352 | lay.addWidget( &label2); | 356 | lay.addWidget( &label2); |
353 | lay.addWidget( &lepw); | 357 | lay.addWidget( &lepw); |
354 | QCheckBox autostart(i18n("Automatically start\nat application startup"), &dia ); | 358 | QCheckBox autostart(i18n("Automatically start\nat application startup"), &dia ); |
355 | lay.addWidget( &autostart); | 359 | lay.addWidget( &autostart); |
356 | autostart.setChecked( mPrefs->mPassiveSyncAutoStart ); | 360 | autostart.setChecked( mPrefs->mPassiveSyncAutoStart ); |
357 | #ifdef DESKTOP_VERSION | 361 | #ifdef DESKTOP_VERSION |
358 | #ifdef _WIN32_ | 362 | #ifdef _WIN32_ |
359 | QCheckBox syncdesktop( i18n("Automatically sync with Outlook\nwhen receiving sync request"),&dia ); | 363 | QCheckBox syncdesktop( i18n("Automatically sync with Outlook\nwhen receiving sync request"),&dia ); |
360 | syncdesktop.hide();// not implemented! | 364 | syncdesktop.hide();// not implemented! |
361 | #else | 365 | #else |
362 | QCheckBox syncdesktop( i18n("Automatically sync with KDE-Desktop\nwhen receiving sync request"),&dia ); | 366 | QCheckBox syncdesktop( i18n("Automatically sync with KDE-Desktop\nwhen receiving sync request"),&dia ); |
363 | #endif | 367 | #endif |
364 | lay.addWidget( &syncdesktop); | 368 | lay.addWidget( &syncdesktop); |
365 | #else | 369 | #else |
366 | mPrefs->mPassiveSyncWithDesktop = false; | 370 | mPrefs->mPassiveSyncWithDesktop = false; |
367 | QCheckBox syncdesktop( i18n("Automatically sync\nwith KDE-Desktop"),&dia ); | 371 | QCheckBox syncdesktop( i18n("Automatically sync\nwith KDE-Desktop"),&dia ); |
368 | syncdesktop.hide(); | 372 | syncdesktop.hide(); |
369 | #endif | 373 | #endif |
370 | syncdesktop.setChecked( mPrefs->mPassiveSyncWithDesktop ); | 374 | syncdesktop.setChecked( mPrefs->mPassiveSyncWithDesktop ); |
371 | 375 | ||
372 | QPushButton pb ( "OK", &dia); | 376 | QPushButton pb ( "OK", &dia); |
373 | lay.addWidget( &pb ); | 377 | lay.addWidget( &pb ); |
374 | connect(&pb, SIGNAL( clicked() ), &dia, SLOT ( accept() ) ); | 378 | connect(&pb, SIGNAL( clicked() ), &dia, SLOT ( accept() ) ); |
375 | dia.resize( 230,120 ); | 379 | dia.resize( 230,120 ); |
376 | dia.setCaption( i18n("Enter port for Pi-Sync") ); | 380 | dia.setCaption( i18n("Enter port for Pi-Sync") ); |
377 | dia.show(); | 381 | dia.show(); |
378 | #ifndef DESKTOP_VERSION | 382 | #ifndef DESKTOP_VERSION |
379 | int dw = QApplication::desktop()->width(); | 383 | int dw = QApplication::desktop()->width(); |
380 | int dh = QApplication::desktop()->height(); | 384 | int dh = QApplication::desktop()->height(); |
381 | dia.move( (dw-dia.width())/2, (dh - dia.height() )/2 ); | 385 | dia.move( (dw-dia.width())/2, (dh - dia.height() )/2 ); |
382 | #endif | 386 | #endif |
383 | if ( ! dia.exec() ) | 387 | if ( ! dia.exec() ) |
384 | return; | 388 | return; |
385 | dia.hide(); | 389 | dia.hide(); |
386 | qApp->processEvents(); | 390 | qApp->processEvents(); |
387 | if ( mPrefs->mPassiveSyncPw != lepw.text() ) { | 391 | if ( mPrefs->mPassiveSyncPw != lepw.text() ) { |
388 | changed = true; | 392 | changed = true; |
389 | mPrefs->mPassiveSyncPw = lepw.text(); | 393 | mPrefs->mPassiveSyncPw = lepw.text(); |
390 | } | 394 | } |
391 | if ( mPrefs->mPassiveSyncPort != lab.text() ) { | 395 | if ( mPrefs->mPassiveSyncPort != lab.text() ) { |
392 | mPrefs->mPassiveSyncPort = lab.text(); | 396 | mPrefs->mPassiveSyncPort = lab.text(); |
393 | changed = true; | 397 | changed = true; |
394 | } | 398 | } |
395 | autoStart = autostart.isChecked(); | 399 | autoStart = autostart.isChecked(); |
396 | if (mPrefs->mPassiveSyncWithDesktop != syncdesktop.isChecked() ) { | 400 | if (mPrefs->mPassiveSyncWithDesktop != syncdesktop.isChecked() ) { |
397 | changed = true; | 401 | changed = true; |
398 | mPrefs->mPassiveSyncWithDesktop = syncdesktop.isChecked(); | 402 | mPrefs->mPassiveSyncWithDesktop = syncdesktop.isChecked(); |
399 | } | 403 | } |
400 | } | 404 | } |
401 | else | 405 | else |
402 | autoStart = mPrefs->mPassiveSyncAutoStart; | 406 | autoStart = mPrefs->mPassiveSyncAutoStart; |
403 | if ( autoStart != mPrefs->mPassiveSyncAutoStart ) | 407 | if ( autoStart != mPrefs->mPassiveSyncAutoStart ) |
404 | changed = true; | 408 | changed = true; |
405 | bool ok; | 409 | bool ok; |
406 | mPrefs->mPassiveSyncAutoStart = false; | 410 | mPrefs->mPassiveSyncAutoStart = false; |
407 | Q_UINT16 port = mPrefs->mPassiveSyncPort.toUInt(&ok); | 411 | Q_UINT16 port = mPrefs->mPassiveSyncPort.toUInt(&ok); |
408 | if ( ! ok ) { | 412 | if ( ! ok ) { |
409 | KMessageBox::information( 0, i18n("No valid port")); | 413 | KMessageBox::information( 0, i18n("No valid port")); |
410 | return; | 414 | return; |
411 | } | 415 | } |
412 | //qDebug("port %d ", port); | 416 | //qDebug("port %d ", port); |
413 | mServerSocket = new KServerSocket ( mPrefs->mPassiveSyncPw, port ,1 ); | 417 | mServerSocket = new KServerSocket ( mPrefs->mPassiveSyncPw, port ,1 ); |
414 | mServerSocket->setFileName( defaultFileName() );//bbb | 418 | mServerSocket->setFileName( defaultFileName() );//bbb |
415 | //qDebug("connected "); | ||
416 | if ( !mServerSocket->ok() ) { | 419 | if ( !mServerSocket->ok() ) { |
417 | KMessageBox::information( 0, i18n("Failed to bind or\nlisten to the port!")); | 420 | KMessageBox::information( 0, i18n("Failed to bind or\nlisten to the port!")); |
418 | delete mServerSocket; | 421 | delete mServerSocket; |
419 | mServerSocket = 0; | 422 | mServerSocket = 0; |
420 | return; | 423 | return; |
421 | } | 424 | } |
422 | mPrefs->mPassiveSyncAutoStart = autoStart; | 425 | mPrefs->mPassiveSyncAutoStart = autoStart; |
423 | if ( changed ) { | 426 | if ( changed ) { |
424 | mPrefs->writeConfig(); | 427 | mPrefs->writeConfig(); |
425 | } | 428 | } |
426 | connect( mServerSocket, SIGNAL ( request_file() ),this, SIGNAL ( request_file() ) ); | 429 | connect( mServerSocket, SIGNAL ( request_file() ),this, SIGNAL ( request_file() ) ); |
427 | connect( mServerSocket, SIGNAL ( file_received( bool ) ), this, SIGNAL ( getFile( bool ) ) ); | 430 | connect( mServerSocket, SIGNAL ( file_received( bool ) ), this, SIGNAL ( getFile( bool ) ) ); |
428 | } | 431 | } |
429 | 432 | ||
430 | void KSyncManager::syncLocalFile() | 433 | void KSyncManager::syncLocalFile() |
431 | { | 434 | { |
432 | 435 | ||
433 | QString fn =mPrefs->mLastSyncedLocalFile; | 436 | QString fn =mPrefs->mLastSyncedLocalFile; |
434 | QString ext; | 437 | QString ext; |
435 | 438 | ||
436 | switch(mTargetApp) | 439 | switch(mTargetApp) |
437 | { | 440 | { |
438 | case (KAPI): | 441 | case (KAPI): |
439 | ext = "(*.vcf)"; | 442 | ext = "(*.vcf)"; |
440 | break; | 443 | break; |
441 | case (KOPI): | 444 | case (KOPI): |
442 | ext = "(*.ics/*.vcs)"; | 445 | ext = "(*.ics/*.vcs)"; |
443 | break; | 446 | break; |
444 | case (PWMPI): | 447 | case (PWMPI): |
445 | ext = "(*.pwm)"; | 448 | ext = "(*.pwm)"; |
446 | break; | 449 | break; |
447 | default: | 450 | default: |
448 | qDebug("KSM::syncLocalFile: invalid apptype selected"); | 451 | qDebug("KSM::syncLocalFile: invalid apptype selected"); |
449 | break; | 452 | break; |
450 | 453 | ||
451 | } | 454 | } |
452 | 455 | ||
453 | fn =KFileDialog:: getOpenFileName( fn, i18n("Sync filename"+ext), mParent ); | 456 | fn =KFileDialog:: getOpenFileName( fn, i18n("Sync filename"+ext), mParent ); |
454 | if ( fn == "" ) | 457 | if ( fn == "" ) |
455 | return; | 458 | return; |
456 | if ( syncWithFile( fn, false ) ) { | 459 | if ( syncWithFile( fn, false ) ) { |
457 | qDebug("KSM::syncLocalFile() successful "); | 460 | qDebug("KSM::syncLocalFile() successful "); |
458 | } | 461 | } |
459 | 462 | ||
460 | } | 463 | } |
461 | 464 | ||
462 | bool KSyncManager::syncWithFile( QString fn , bool quick ) | 465 | bool KSyncManager::syncWithFile( QString fn , bool quick ) |
463 | { | 466 | { |
464 | bool ret = false; | 467 | bool ret = false; |
465 | QFileInfo info; | 468 | QFileInfo info; |
466 | info.setFile( fn ); | 469 | info.setFile( fn ); |
467 | QString mess; | 470 | QString mess; |
468 | if ( !info. exists() ) { | 471 | if ( !info. exists() ) { |
469 | mess = i18n( "Sync file \n...%1\ndoes not exist!\nNothing synced!\n").arg(fn.right( 30) ); | 472 | mess = i18n( "Sync file \n...%1\ndoes not exist!\nNothing synced!\n").arg(fn.right( 30) ); |
470 | QMessageBox::warning( mParent, i18n("Warning!"), | 473 | QMessageBox::warning( mParent, i18n("Warning!"), |
471 | mess ); | 474 | mess ); |
472 | return ret; | 475 | return ret; |
473 | } | 476 | } |
474 | int result = 0; | 477 | int result = 0; |
475 | if ( !quick ) { | 478 | if ( !quick ) { |
476 | mess = i18n("Sync with file \n...%1\nfrom:\n%2\n").arg(fn.right( 25)).arg(KGlobal::locale()->formatDateTime(info.lastModified (), true, false )); | 479 | mess = i18n("Sync with file \n...%1\nfrom:\n%2\n").arg(fn.right( 25)).arg(KGlobal::locale()->formatDateTime(info.lastModified (), true, false )); |
477 | result = QMessageBox::warning( mParent, i18n("Warning!"), | 480 | result = QMessageBox::warning( mParent, i18n("Warning!"), |
478 | mess, | 481 | mess, |
479 | i18n("Sync"), i18n("Cancel"), 0, | 482 | i18n("Sync"), i18n("Cancel"), 0, |
@@ -1056,129 +1059,129 @@ void KSyncManager::syncPi() | |||
1056 | if ( ! ok ) { | 1059 | if ( ! ok ) { |
1057 | mParent->topLevelWidget()->setCaption( i18n("Sorry, no valid port.Syncing cancelled.") ); | 1060 | mParent->topLevelWidget()->setCaption( i18n("Sorry, no valid port.Syncing cancelled.") ); |
1058 | return; | 1061 | return; |
1059 | } | 1062 | } |
1060 | KCommandSocket* commandSocket = new KCommandSocket( mPassWordPiSync, port, mActiveSyncIP, this, mParent->topLevelWidget() ); | 1063 | KCommandSocket* commandSocket = new KCommandSocket( mPassWordPiSync, port, mActiveSyncIP, this, mParent->topLevelWidget() ); |
1061 | connect( commandSocket, SIGNAL(commandFinished( KCommandSocket*, int )), this, SLOT(deleteCommandSocket(KCommandSocket*, int)) ); | 1064 | connect( commandSocket, SIGNAL(commandFinished( KCommandSocket*, int )), this, SLOT(deleteCommandSocket(KCommandSocket*, int)) ); |
1062 | commandSocket->readFile( syncFileName() ); | 1065 | commandSocket->readFile( syncFileName() ); |
1063 | } | 1066 | } |
1064 | 1067 | ||
1065 | void KSyncManager::deleteCommandSocket(KCommandSocket*s, int state) | 1068 | void KSyncManager::deleteCommandSocket(KCommandSocket*s, int state) |
1066 | { | 1069 | { |
1067 | //enum { success, errorW, errorR, quiet }; | 1070 | //enum { success, errorW, errorR, quiet }; |
1068 | if ( state == KCommandSocket::errorR ||state == KCommandSocket::errorTO ) { | 1071 | if ( state == KCommandSocket::errorR ||state == KCommandSocket::errorTO ) { |
1069 | mParent->topLevelWidget()->setCaption( i18n("ERROR: Receiving remote file failed.") ); | 1072 | mParent->topLevelWidget()->setCaption( i18n("ERROR: Receiving remote file failed.") ); |
1070 | delete s; | 1073 | delete s; |
1071 | if ( state == KCommandSocket::errorR ) { | 1074 | if ( state == KCommandSocket::errorR ) { |
1072 | KCommandSocket* commandSocket = new KCommandSocket( mPassWordPiSync, mActiveSyncPort.toUInt(), mActiveSyncIP, this, mParent->topLevelWidget()); | 1075 | KCommandSocket* commandSocket = new KCommandSocket( mPassWordPiSync, mActiveSyncPort.toUInt(), mActiveSyncIP, this, mParent->topLevelWidget()); |
1073 | connect( commandSocket, SIGNAL(commandFinished( KCommandSocket*, int)), this, SLOT(deleteCommandSocket(KCommandSocket*, int )) ); | 1076 | connect( commandSocket, SIGNAL(commandFinished( KCommandSocket*, int)), this, SLOT(deleteCommandSocket(KCommandSocket*, int )) ); |
1074 | commandSocket->sendStop(); | 1077 | commandSocket->sendStop(); |
1075 | } | 1078 | } |
1076 | mPisyncFinished = true; | 1079 | mPisyncFinished = true; |
1077 | return; | 1080 | return; |
1078 | 1081 | ||
1079 | } else if ( state == KCommandSocket::errorW ) { | 1082 | } else if ( state == KCommandSocket::errorW ) { |
1080 | mParent->topLevelWidget()->setCaption( i18n("ERROR:Writing back file failed.") ); | 1083 | mParent->topLevelWidget()->setCaption( i18n("ERROR:Writing back file failed.") ); |
1081 | mPisyncFinished = true; | 1084 | mPisyncFinished = true; |
1082 | 1085 | ||
1083 | } else if ( state == KCommandSocket::successR ) { | 1086 | } else if ( state == KCommandSocket::successR ) { |
1084 | QTimer::singleShot( 1, this , SLOT ( readFileFromSocket())); | 1087 | QTimer::singleShot( 1, this , SLOT ( readFileFromSocket())); |
1085 | 1088 | ||
1086 | } else if ( state == KCommandSocket::successW ) { | 1089 | } else if ( state == KCommandSocket::successW ) { |
1087 | mParent->topLevelWidget()->setCaption( i18n("Pi-Sync succesful!") ); | 1090 | mParent->topLevelWidget()->setCaption( i18n("Pi-Sync succesful!") ); |
1088 | mPisyncFinished = true; | 1091 | mPisyncFinished = true; |
1089 | } | 1092 | } |
1090 | 1093 | ||
1091 | delete s; | 1094 | delete s; |
1092 | } | 1095 | } |
1093 | 1096 | ||
1094 | void KSyncManager::readFileFromSocket() | 1097 | void KSyncManager::readFileFromSocket() |
1095 | { | 1098 | { |
1096 | QString fileName = syncFileName(); | 1099 | QString fileName = syncFileName(); |
1097 | mParent->topLevelWidget()->setCaption( i18n("Remote file saved to temp file.") ); | 1100 | mParent->topLevelWidget()->setCaption( i18n("Remote file saved to temp file.") ); |
1098 | if ( ! syncWithFile( fileName , true ) ) { | 1101 | if ( ! syncWithFile( fileName , true ) ) { |
1099 | mParent->topLevelWidget()->setCaption( i18n("Syncing failed.") ); | 1102 | mParent->topLevelWidget()->setCaption( i18n("Syncing failed.") ); |
1100 | mPisyncFinished = true; | 1103 | mPisyncFinished = true; |
1101 | return; | 1104 | return; |
1102 | } | 1105 | } |
1103 | KCommandSocket* commandSocket = new KCommandSocket( mPassWordPiSync, mActiveSyncPort.toUInt(), mActiveSyncIP, this, mParent->topLevelWidget() ); | 1106 | KCommandSocket* commandSocket = new KCommandSocket( mPassWordPiSync, mActiveSyncPort.toUInt(), mActiveSyncIP, this, mParent->topLevelWidget() ); |
1104 | connect( commandSocket, SIGNAL(commandFinished( KCommandSocket*, int)), this, SLOT(deleteCommandSocket(KCommandSocket*, int )) ); | 1107 | connect( commandSocket, SIGNAL(commandFinished( KCommandSocket*, int)), this, SLOT(deleteCommandSocket(KCommandSocket*, int )) ); |
1105 | if ( mWriteBackFile ) | 1108 | if ( mWriteBackFile ) |
1106 | commandSocket->writeFile( fileName ); | 1109 | commandSocket->writeFile( fileName ); |
1107 | else { | 1110 | else { |
1108 | commandSocket->sendStop(); | 1111 | commandSocket->sendStop(); |
1109 | mParent->topLevelWidget()->setCaption( i18n("Pi-Sync succesful!") ); | 1112 | mParent->topLevelWidget()->setCaption( i18n("Pi-Sync succesful!") ); |
1110 | mPisyncFinished = true; | 1113 | mPisyncFinished = true; |
1111 | } | 1114 | } |
1112 | } | 1115 | } |
1113 | 1116 | ||
1114 | KServerSocket:: KServerSocket ( QString pw, Q_UINT16 port, int backlog, QObject * parent, const char * name ) : QServerSocket( port, backlog, parent, name ) | 1117 | KServerSocket:: KServerSocket ( QString pw, Q_UINT16 port, int backlog, QObject * parent, const char * name ) : QServerSocket( port, backlog, parent, name ) |
1115 | { | 1118 | { |
1116 | mPassWord = pw; | 1119 | mPassWord = pw; |
1117 | mSocket = 0; | 1120 | mSocket = 0; |
1118 | mSyncActionDialog = 0; | 1121 | mSyncActionDialog = 0; |
1119 | blockRC = false; | 1122 | blockRC = false; |
1120 | }; | 1123 | } |
1121 | 1124 | ||
1122 | void KServerSocket::newConnection ( int socket ) | 1125 | void KServerSocket::newConnection ( int socket ) |
1123 | { | 1126 | { |
1124 | // qDebug("KServerSocket:New connection %d ", socket); | 1127 | // qDebug("KServerSocket:New connection %d ", socket); |
1125 | if ( mSocket ) { | 1128 | if ( mSocket ) { |
1126 | qDebug("KSS::newConnection Socket deleted! "); | 1129 | qDebug("KSS::newConnection Socket deleted! "); |
1127 | delete mSocket; | 1130 | delete mSocket; |
1128 | mSocket = 0; | 1131 | mSocket = 0; |
1129 | } | 1132 | } |
1130 | mSocket = new QSocket( this ); | 1133 | mSocket = new QSocket( this ); |
1131 | connect( mSocket , SIGNAL(readyRead()), this, SLOT(readClient()) ); | 1134 | connect( mSocket , SIGNAL(readyRead()), this, SLOT(readClient()) ); |
1132 | connect( mSocket , SIGNAL(delayedCloseFinished()), this, SLOT(discardClient()) ); | 1135 | connect( mSocket , SIGNAL(delayedCloseFinished()), this, SLOT(discardClient()) ); |
1133 | mSocket->setSocket( socket ); | 1136 | mSocket->setSocket( socket ); |
1134 | } | 1137 | } |
1135 | 1138 | ||
1136 | void KServerSocket::discardClient() | 1139 | void KServerSocket::discardClient() |
1137 | { | 1140 | { |
1138 | //qDebug(" KServerSocket::discardClient()"); | 1141 | //qDebug(" KServerSocket::discardClient()"); |
1139 | if ( mSocket ) { | 1142 | if ( mSocket ) { |
1140 | delete mSocket; | 1143 | delete mSocket; |
1141 | mSocket = 0; | 1144 | mSocket = 0; |
1142 | } | 1145 | } |
1143 | //emit endConnect(); | 1146 | //emit endConnect(); |
1144 | } | 1147 | } |
1145 | void KServerSocket::readClient() | 1148 | void KServerSocket::readClient() |
1146 | { | 1149 | { |
1147 | if ( blockRC ) | 1150 | if ( blockRC ) |
1148 | return; | 1151 | return; |
1149 | if ( mSocket == 0 ) { | 1152 | if ( mSocket == 0 ) { |
1150 | qDebug("ERROR::KSS::readClient(): mSocket == 0 "); | 1153 | qDebug("ERROR::KSS::readClient(): mSocket == 0 "); |
1151 | return; | 1154 | return; |
1152 | } | 1155 | } |
1153 | //qDebug("KServerSocket::readClient()"); | 1156 | //qDebug("KServerSocket::readClient()"); |
1154 | if ( mSocket->canReadLine() ) { | 1157 | if ( mSocket->canReadLine() ) { |
1155 | QString line = mSocket->readLine(); | 1158 | QString line = mSocket->readLine(); |
1156 | //qDebug("KServerSocket readline: %s ", line.latin1()); | 1159 | //qDebug("KServerSocket readline: %s ", line.latin1()); |
1157 | QStringList tokens = QStringList::split( QRegExp("[ \r\n][ \r\n]*"), line ); | 1160 | QStringList tokens = QStringList::split( QRegExp("[ \r\n][ \r\n]*"), line ); |
1158 | if ( tokens[0] == "GET" ) { | 1161 | if ( tokens[0] == "GET" ) { |
1159 | if ( tokens[1] == mPassWord ) { | 1162 | if ( tokens[1] == mPassWord ) { |
1160 | //emit sendFile( mSocket ); | 1163 | //emit sendFile( mSocket ); |
1161 | bool ok = false; | 1164 | bool ok = false; |
1162 | QDateTime dt = KGlobal::locale()->readDateTime( tokens[2], KLocale::ISODate, &ok); | 1165 | QDateTime dt = KGlobal::locale()->readDateTime( tokens[2], KLocale::ISODate, &ok); |
1163 | if ( ok ) { | 1166 | if ( ok ) { |
1164 | KSyncManager::mRequestedSyncEvent = dt; | 1167 | KSyncManager::mRequestedSyncEvent = dt; |
1165 | } | 1168 | } |
1166 | else | 1169 | else |
1167 | KSyncManager::mRequestedSyncEvent = QDateTime(); | 1170 | KSyncManager::mRequestedSyncEvent = QDateTime(); |
1168 | send_file(); | 1171 | send_file(); |
1169 | } | 1172 | } |
1170 | else { | 1173 | else { |
1171 | KMessageBox::error( 0, i18n("Got send file request\nwith invalid password")); | 1174 | KMessageBox::error( 0, i18n("Got send file request\nwith invalid password")); |
1172 | //qDebug("password %s, invalid password %s ",mPassWord.latin1(), tokens[1].latin1() ); | 1175 | //qDebug("password %s, invalid password %s ",mPassWord.latin1(), tokens[1].latin1() ); |
1173 | } | 1176 | } |
1174 | } | 1177 | } |
1175 | if ( tokens[0] == "PUT" ) { | 1178 | if ( tokens[0] == "PUT" ) { |
1176 | if ( tokens[1] == mPassWord ) { | 1179 | if ( tokens[1] == mPassWord ) { |
1177 | //emit getFile( mSocket ); | 1180 | //emit getFile( mSocket ); |
1178 | blockRC = true; | 1181 | blockRC = true; |
1179 | get_file(); | 1182 | get_file(); |
1180 | } | 1183 | } |
1181 | else { | 1184 | else { |
1182 | KMessageBox::error( 0, i18n("Got receive file request\nwith invalid password")); | 1185 | KMessageBox::error( 0, i18n("Got receive file request\nwith invalid password")); |
1183 | //qDebug("password %s, invalid password %s ",mPassWord.latin1(), tokens[1].latin1() ); | 1186 | //qDebug("password %s, invalid password %s ",mPassWord.latin1(), tokens[1].latin1() ); |
1184 | } | 1187 | } |
diff --git a/libkdepim/ksyncmanager.h b/libkdepim/ksyncmanager.h index 9a3066e..09bd1c1 100644 --- a/libkdepim/ksyncmanager.h +++ b/libkdepim/ksyncmanager.h | |||
@@ -60,129 +60,129 @@ class KServerSocket : public QServerSocket | |||
60 | private : | 60 | private : |
61 | bool blockRC; | 61 | bool blockRC; |
62 | void send_file(); | 62 | void send_file(); |
63 | void get_file(); | 63 | void get_file(); |
64 | void end_connect(); | 64 | void end_connect(); |
65 | QDialog* mSyncActionDialog; | 65 | QDialog* mSyncActionDialog; |
66 | QSocket* mSocket; | 66 | QSocket* mSocket; |
67 | QString mPassWord; | 67 | QString mPassWord; |
68 | QString mFileName; | 68 | QString mFileName; |
69 | QTime piTime; | 69 | QTime piTime; |
70 | QString piFileString; | 70 | QString piFileString; |
71 | }; | 71 | }; |
72 | 72 | ||
73 | class KCommandSocket : public QObject | 73 | class KCommandSocket : public QObject |
74 | { | 74 | { |
75 | Q_OBJECT | 75 | Q_OBJECT |
76 | public: | 76 | public: |
77 | enum state { successR, errorR, successW, errorW, errorTO, quiet }; | 77 | enum state { successR, errorR, successW, errorW, errorTO, quiet }; |
78 | KCommandSocket ( QString password, Q_UINT16 port, QString host, QObject * parent=0, QWidget* cap = 0, const char * name=0 ); | 78 | KCommandSocket ( QString password, Q_UINT16 port, QString host, QObject * parent=0, QWidget* cap = 0, const char * name=0 ); |
79 | void readFile( QString ); | 79 | void readFile( QString ); |
80 | void writeFile( QString ); | 80 | void writeFile( QString ); |
81 | void sendStop(); | 81 | void sendStop(); |
82 | 82 | ||
83 | private slots : | 83 | private slots : |
84 | void sendFileRequest(); | 84 | void sendFileRequest(); |
85 | 85 | ||
86 | signals: | 86 | signals: |
87 | void commandFinished( KCommandSocket*, int ); | 87 | void commandFinished( KCommandSocket*, int ); |
88 | private slots: | 88 | private slots: |
89 | void startReadFileFromSocket(); | 89 | void startReadFileFromSocket(); |
90 | void readFileFromSocket(); | 90 | void readFileFromSocket(); |
91 | void deleteSocket(); | 91 | void deleteSocket(); |
92 | void writeFileToSocket(); | 92 | void writeFileToSocket(); |
93 | private : | 93 | private : |
94 | QWidget* tlw; | 94 | QWidget* tlw; |
95 | QSocket* mSocket; | 95 | QSocket* mSocket; |
96 | QString mPassWord; | 96 | QString mPassWord; |
97 | Q_UINT16 mPort; | 97 | Q_UINT16 mPort; |
98 | QString mHost; | 98 | QString mHost; |
99 | QString mFileName; | 99 | QString mFileName; |
100 | QTimer* mTimerSocket; | 100 | QTimer* mTimerSocket; |
101 | int mRetVal; | 101 | int mRetVal; |
102 | QTime mTime; | 102 | QTime mTime; |
103 | QString mFileString; | 103 | QString mFileString; |
104 | bool mFirst; | 104 | bool mFirst; |
105 | }; | 105 | }; |
106 | 106 | ||
107 | 107 | ||
108 | class KSyncManager : public QObject | 108 | class KSyncManager : public QObject |
109 | { | 109 | { |
110 | Q_OBJECT | 110 | Q_OBJECT |
111 | 111 | ||
112 | public: | 112 | public: |
113 | enum TargetApp { | 113 | enum TargetApp { |
114 | KOPI = 0, | 114 | KOPI = 0, |
115 | KAPI = 1, | 115 | KAPI = 1, |
116 | PWMPI = 2 }; | 116 | PWMPI = 2 }; |
117 | 117 | ||
118 | KSyncManager(QWidget* parent, KSyncInterface* implementation, TargetApp ta, KPimPrefs* prefs, QPopupMenu* syncmenu); | 118 | KSyncManager(QWidget* parent, KSyncInterface* implementation, TargetApp ta, KPimPrefs* prefs, QPopupMenu* syncmenu); |
119 | ~KSyncManager() ; | 119 | ~KSyncManager() ; |
120 | 120 | ||
121 | void multiSync( bool askforPrefs ); | 121 | void multiSync( bool askforPrefs ); |
122 | bool blockSave() { return mBlockSaveFlag; } | 122 | bool blockSave() { return mBlockSaveFlag; } |
123 | void setBlockSave(bool sa) { mBlockSaveFlag = sa; } | 123 | void setBlockSave(bool sa) { mBlockSaveFlag = sa; } |
124 | void setDefaultFileName( QString s) { mDefFileName = s ;} | 124 | void setDefaultFileName( QString s) ; |
125 | QString defaultFileName() { return mDefFileName ;} | 125 | QString defaultFileName() { return mDefFileName ;} |
126 | QString syncFileName(); | 126 | QString syncFileName(); |
127 | void enableQuick( bool ask = true); | 127 | void enableQuick( bool ask = true); |
128 | 128 | ||
129 | bool syncWithDesktop () { return mSyncWithDesktop;} | 129 | bool syncWithDesktop () { return mSyncWithDesktop;} |
130 | QString getCurrentSyncDevice() { return mCurrentSyncDevice; } | 130 | QString getCurrentSyncDevice() { return mCurrentSyncDevice; } |
131 | QString getCurrentSyncName() { return mCurrentSyncName; } | 131 | QString getCurrentSyncName() { return mCurrentSyncName; } |
132 | 132 | ||
133 | void showProgressBar(int percentage, QString caption = QString::null, int total=100); | 133 | void showProgressBar(int percentage, QString caption = QString::null, int total=100); |
134 | void hideProgressBar(); | 134 | void hideProgressBar(); |
135 | bool isProgressBarCanceled(); | 135 | bool isProgressBarCanceled(); |
136 | 136 | ||
137 | // sync stuff | 137 | // sync stuff |
138 | QString mLocalMachineName; | 138 | QString mLocalMachineName; |
139 | QStringList mExternSyncProfiles; | 139 | QStringList mExternSyncProfiles; |
140 | QStringList mSyncProfileNames; | 140 | QStringList mSyncProfileNames; |
141 | bool mAskForPreferences; | 141 | bool mAskForPreferences; |
142 | bool mShowSyncSummary; | 142 | bool mShowSyncSummary; |
143 | bool mIsKapiFile; | 143 | bool mIsKapiFile; |
144 | bool mWriteBackExistingOnly; | 144 | bool mWriteBackExistingOnly; |
145 | int mSyncAlgoPrefs; | 145 | int mSyncAlgoPrefs; |
146 | bool mWriteBackFile; | 146 | bool mWriteBackFile; |
147 | int mWriteBackInFuture; | 147 | int mWriteBackInFuture; |
148 | int mWriteBackInPast; | 148 | int mWriteBackInPast; |
149 | QString mPhoneDevice; | 149 | QString mPhoneDevice; |
150 | QString mPhoneConnection; | 150 | QString mPhoneConnection; |
151 | QString mPhoneModel; | 151 | QString mPhoneModel; |
152 | QString mPassWordPiSync; | 152 | QString mPassWordPiSync; |
153 | QString mActiveSyncPort; | 153 | QString mActiveSyncPort; |
154 | QString mActiveSyncIP ; | 154 | QString mActiveSyncIP ; |
155 | QString mFilterInCal; | 155 | QString mFilterInCal; |
156 | QString mFilterOutCal; | 156 | QString mFilterOutCal; |
157 | QString mFilterInAB; | 157 | QString mFilterInAB; |
158 | QString mFilterOutAB; | 158 | QString mFilterOutAB; |
159 | static QDateTime mRequestedSyncEvent; | 159 | static QDateTime mRequestedSyncEvent; |
160 | 160 | ||
161 | signals: | 161 | signals: |
162 | void save(); | 162 | void save(); |
163 | void request_file(); | 163 | void request_file(); |
164 | void getFile( bool ); | 164 | void getFile( bool ); |
165 | 165 | ||
166 | public slots: | 166 | public slots: |
167 | void slotSyncMenu( int ); | 167 | void slotSyncMenu( int ); |
168 | void slotClearMenu( int action ); | 168 | void slotClearMenu( int action ); |
169 | void deleteCommandSocket(KCommandSocket*s, int state); | 169 | void deleteCommandSocket(KCommandSocket*s, int state); |
170 | void readFileFromSocket(); | 170 | void readFileFromSocket(); |
171 | void fillSyncMenu(); | 171 | void fillSyncMenu(); |
172 | 172 | ||
173 | private: | 173 | private: |
174 | void syncPi(); | 174 | void syncPi(); |
175 | KServerSocket * mServerSocket; | 175 | KServerSocket * mServerSocket; |
176 | KPimPrefs* mPrefs; | 176 | KPimPrefs* mPrefs; |
177 | QString mDefFileName; | 177 | QString mDefFileName; |
178 | QString mCurrentSyncDevice; | 178 | QString mCurrentSyncDevice; |
179 | QString mCurrentSyncName; | 179 | QString mCurrentSyncName; |
180 | void quickSyncLocalFile(); | 180 | void quickSyncLocalFile(); |
181 | bool syncWithFile( QString fn , bool quick ); | 181 | bool syncWithFile( QString fn , bool quick ); |
182 | void syncLocalFile(); | 182 | void syncLocalFile(); |
183 | void syncPhone(); | 183 | void syncPhone(); |
184 | void syncSharp(); | 184 | void syncSharp(); |
185 | void syncKDE(); | 185 | void syncKDE(); |
186 | bool syncExternalApplication(QString); | 186 | bool syncExternalApplication(QString); |
187 | int mCurrentSyncProfile ; | 187 | int mCurrentSyncProfile ; |
188 | void syncRemote( KSyncProfile* prof, bool ask = true); | 188 | void syncRemote( KSyncProfile* prof, bool ask = true); |