-rw-r--r-- | libkdepim/ksyncmanager.cpp | 87 |
1 files changed, 58 insertions, 29 deletions
diff --git a/libkdepim/ksyncmanager.cpp b/libkdepim/ksyncmanager.cpp index 40d8e47..75c0b2b 100644 --- a/libkdepim/ksyncmanager.cpp +++ b/libkdepim/ksyncmanager.cpp | |||
@@ -3,116 +3,119 @@ | |||
3 | Copyright (c) 2004 Ulf Schenk | 3 | Copyright (c) 2004 Ulf Schenk |
4 | 4 | ||
5 | This library is free software; you can redistribute it and/or | 5 | This library is free software; you can redistribute it and/or |
6 | modify it under the terms of the GNU Library General Public | 6 | modify it under the terms of the GNU Library General Public |
7 | License as published by the Free Software Foundation; either | 7 | License as published by the Free Software Foundation; either |
8 | version 2 of the License, or (at your option) any later version. | 8 | version 2 of the License, or (at your option) any later version. |
9 | 9 | ||
10 | This library is distributed in the hope that it will be useful, | 10 | This library is distributed in the hope that it will be useful, |
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 | 52 | ||
52 | #include <klocale.h> | 53 | #include <klocale.h> |
53 | #include <kglobal.h> | 54 | #include <kglobal.h> |
54 | #include <kconfig.h> | 55 | #include <kconfig.h> |
55 | #include <kfiledialog.h> | 56 | #include <kfiledialog.h> |
56 | 57 | ||
57 | KSyncManager::KSyncManager(QWidget* parent, KSyncInterface* implementation, TargetApp ta, KPimPrefs* prefs, QPopupMenu* syncmenu) | 58 | KSyncManager::KSyncManager(QWidget* parent, KSyncInterface* implementation, TargetApp ta, KPimPrefs* prefs, QPopupMenu* syncmenu) |
58 | : QObject(), mParent(parent), mImplementation(implementation), mTargetApp(ta), mPrefs(prefs ),mSyncMenu(syncmenu) | 59 | : QObject(), mParent(parent), mImplementation(implementation), mTargetApp(ta), mPrefs(prefs ),mSyncMenu(syncmenu) |
59 | { | 60 | { |
60 | mServerSocket = 0; | 61 | mServerSocket = 0; |
61 | bar = new QProgressBar ( 1, 0 ); | 62 | bar = new QProgressBar ( 1, 0 ); |
62 | bar->setCaption (""); | 63 | bar->setCaption (""); |
63 | 64 | ||
64 | int w = 300; | 65 | int w = 300; |
65 | if ( QApplication::desktop()->width() < 320 ) | 66 | if ( QApplication::desktop()->width() < 320 ) |
66 | w = 220; | 67 | w = 220; |
67 | int h = bar->sizeHint().height() ; | 68 | int h = bar->sizeHint().height() ; |
68 | int dw = QApplication::desktop()->width(); | 69 | int dw = QApplication::desktop()->width(); |
69 | int dh = QApplication::desktop()->height(); | 70 | int dh = QApplication::desktop()->height(); |
70 | bar->setGeometry( (dw-w)/2, (dh - h )/2 ,w,h ); | 71 | bar->setGeometry( (dw-w)/2, (dh - h )/2 ,w,h ); |
72 | if ( mPrefs->mPassiveSyncAutoStart ) | ||
73 | enableQuick( false ); | ||
71 | 74 | ||
72 | } | 75 | } |
73 | 76 | ||
74 | KSyncManager::~KSyncManager() | 77 | KSyncManager::~KSyncManager() |
75 | { | 78 | { |
76 | delete bar; | 79 | delete bar; |
77 | } | 80 | } |
78 | 81 | ||
79 | 82 | ||
80 | void KSyncManager::fillSyncMenu() | 83 | void KSyncManager::fillSyncMenu() |
81 | { | 84 | { |
82 | if ( mSyncMenu->count() ) | 85 | if ( mSyncMenu->count() ) |
83 | mSyncMenu->clear(); | 86 | mSyncMenu->clear(); |
84 | 87 | ||
85 | mSyncMenu->insertItem( i18n("Configure..."), 0 ); | 88 | mSyncMenu->insertItem( i18n("Configure..."), 0 ); |
86 | mSyncMenu->insertSeparator(); | 89 | mSyncMenu->insertSeparator(); |
87 | if ( mServerSocket == 0 ) { | 90 | if ( mServerSocket == 0 ) { |
88 | mSyncMenu->insertItem( i18n("Enable Pi-Sync"), 2 ); | 91 | mSyncMenu->insertItem( i18n("Enable Pi-Sync"), 2 ); |
89 | } else { | 92 | } else { |
90 | mSyncMenu->insertItem( i18n("Disable Pi-Sync"), 3 ); | 93 | mSyncMenu->insertItem( i18n("Disable Pi-Sync"), 3 ); |
91 | } | 94 | } |
92 | mSyncMenu->insertSeparator(); | 95 | mSyncMenu->insertSeparator(); |
93 | mSyncMenu->insertItem( i18n("Multiple sync"), 1 ); | 96 | mSyncMenu->insertItem( i18n("Multiple sync"), 1 ); |
94 | mSyncMenu->insertSeparator(); | 97 | mSyncMenu->insertSeparator(); |
95 | 98 | ||
96 | KConfig config ( locateLocal( "config","ksyncprofilesrc" ) ); | 99 | KConfig config ( locateLocal( "config","ksyncprofilesrc" ) ); |
97 | config.setGroup("General"); | 100 | config.setGroup("General"); |
98 | QStringList prof = config.readListEntry("SyncProfileNames"); | 101 | QStringList prof = config.readListEntry("SyncProfileNames"); |
99 | mLocalMachineName = config.readEntry("LocalMachineName","undefined"); | 102 | mLocalMachineName = config.readEntry("LocalMachineName","undefined"); |
100 | if ( prof.count() < 2 ) { | 103 | if ( prof.count() < 2 ) { |
101 | prof.clear(); | 104 | prof.clear(); |
102 | #ifdef DESKTOP_VERSION | 105 | #ifdef DESKTOP_VERSION |
103 | #ifdef _WIN32_ | 106 | #ifdef _WIN32_ |
104 | prof << i18n("OutLook(not_implemented)"); | 107 | prof << i18n("OutLook(not_implemented)"); |
105 | #else | 108 | #else |
106 | prof << i18n("KDE_Desktop"); | 109 | prof << i18n("KDE_Desktop"); |
107 | #endif | 110 | #endif |
108 | #else | 111 | #else |
109 | prof << i18n("Sharp_DTM"); | 112 | prof << i18n("Sharp_DTM"); |
110 | #endif | 113 | #endif |
111 | prof << i18n("Local_file"); | 114 | prof << i18n("Local_file"); |
112 | prof << i18n("Last_file"); | 115 | prof << i18n("Last_file"); |
113 | KSyncProfile* temp = new KSyncProfile (); | 116 | KSyncProfile* temp = new KSyncProfile (); |
114 | temp->setName( prof[0] ); | 117 | temp->setName( prof[0] ); |
115 | temp->writeConfig(&config); | 118 | temp->writeConfig(&config); |
116 | temp->setName( prof[1] ); | 119 | temp->setName( prof[1] ); |
117 | temp->writeConfig(&config); | 120 | temp->writeConfig(&config); |
118 | temp->setName( prof[2] ); | 121 | temp->setName( prof[2] ); |
@@ -222,142 +225,168 @@ void KSyncManager::slotSyncMenu( int action ) | |||
222 | break; | 225 | break; |
223 | case (KOPI): | 226 | case (KOPI): |
224 | if ( syncWithFile( temp->getRemoteFileName( ), false ) ) | 227 | if ( syncWithFile( temp->getRemoteFileName( ), false ) ) |
225 | mPrefs->mLastSyncedLocalFile = temp->getRemoteFileName(); | 228 | mPrefs->mLastSyncedLocalFile = temp->getRemoteFileName(); |
226 | break; | 229 | break; |
227 | case (PWMPI): | 230 | case (PWMPI): |
228 | if ( syncWithFile( temp->getRemoteFileNamePWM( ), false ) ) | 231 | if ( syncWithFile( temp->getRemoteFileNamePWM( ), false ) ) |
229 | mPrefs->mLastSyncedLocalFile = temp->getRemoteFileNamePWM(); | 232 | mPrefs->mLastSyncedLocalFile = temp->getRemoteFileNamePWM(); |
230 | break; | 233 | break; |
231 | default: | 234 | default: |
232 | qDebug("KSyncManager::slotSyncMenu: invalid apptype selected"); | 235 | qDebug("KSyncManager::slotSyncMenu: invalid apptype selected"); |
233 | break; | 236 | break; |
234 | 237 | ||
235 | } | 238 | } |
236 | } else { | 239 | } else { |
237 | if ( temp->getIsPhoneSync() ) { | 240 | if ( temp->getIsPhoneSync() ) { |
238 | mPhoneDevice = temp->getPhoneDevice( ) ; | 241 | mPhoneDevice = temp->getPhoneDevice( ) ; |
239 | mPhoneConnection = temp->getPhoneConnection( ); | 242 | mPhoneConnection = temp->getPhoneConnection( ); |
240 | mPhoneModel = temp->getPhoneModel( ); | 243 | mPhoneModel = temp->getPhoneModel( ); |
241 | syncPhone(); | 244 | syncPhone(); |
242 | } else if ( temp->getIsPiSync() ) { | 245 | } else if ( temp->getIsPiSync() ) { |
243 | if ( mTargetApp == KAPI ) { | 246 | if ( mTargetApp == KAPI ) { |
244 | mPassWordPiSync = temp->getRemotePwAB(); | 247 | mPassWordPiSync = temp->getRemotePwAB(); |
245 | mActiveSyncPort = temp->getRemotePortAB(); | 248 | mActiveSyncPort = temp->getRemotePortAB(); |
246 | mActiveSyncIP = temp->getRemoteIPAB(); | 249 | mActiveSyncIP = temp->getRemoteIPAB(); |
247 | } else if ( mTargetApp == KOPI ) { | 250 | } else if ( mTargetApp == KOPI ) { |
248 | mPassWordPiSync = temp->getRemotePw(); | 251 | mPassWordPiSync = temp->getRemotePw(); |
249 | mActiveSyncPort = temp->getRemotePort(); | 252 | mActiveSyncPort = temp->getRemotePort(); |
250 | mActiveSyncIP = temp->getRemoteIP(); | 253 | mActiveSyncIP = temp->getRemoteIP(); |
251 | } else { | 254 | } else { |
252 | mPassWordPiSync = temp->getRemotePwPWM(); | 255 | mPassWordPiSync = temp->getRemotePwPWM(); |
253 | mActiveSyncPort = temp->getRemotePortPWM(); | 256 | mActiveSyncPort = temp->getRemotePortPWM(); |
254 | mActiveSyncIP = temp->getRemoteIPPWM(); | 257 | mActiveSyncIP = temp->getRemoteIPPWM(); |
255 | } | 258 | } |
256 | syncPi(); | 259 | syncPi(); |
257 | while ( !mPisyncFinished ) { | 260 | while ( !mPisyncFinished ) { |
258 | //qDebug("waiting "); | 261 | //qDebug("waiting "); |
259 | qApp->processEvents(); | 262 | qApp->processEvents(); |
260 | } | 263 | } |
261 | } else | 264 | } else |
262 | syncRemote( temp ); | 265 | syncRemote( temp ); |
263 | 266 | ||
264 | } | 267 | } |
265 | } | 268 | } |
266 | delete temp; | 269 | delete temp; |
267 | setBlockSave(false); | 270 | setBlockSave(false); |
268 | } | 271 | } |
269 | 272 | ||
270 | void KSyncManager::enableQuick() | 273 | void KSyncManager::enableQuick( bool ask ) |
271 | { | 274 | { |
272 | QDialog dia ( 0, "input-dialog", true ); | 275 | bool autoStart; |
273 | QLineEdit lab ( &dia ); | 276 | if ( ask ) { |
274 | QVBoxLayout lay( &dia ); | 277 | QDialog dia ( 0, "input-dialog", true ); |
275 | lab.setText( mPrefs->mPassiveSyncPort ); | 278 | QLineEdit lab ( &dia ); |
276 | lay.setMargin(7); | 279 | QVBoxLayout lay( &dia ); |
277 | lay.setSpacing(7); | 280 | lab.setText( mPrefs->mPassiveSyncPort ); |
278 | int po = 9197+mTargetApp; | 281 | lay.setMargin(7); |
279 | QLabel label ( i18n("Port number (Default: %1)").arg(po), &dia ); | 282 | lay.setSpacing(7); |
280 | lay.addWidget( &label); | 283 | int po = 9197+mTargetApp; |
281 | lay.addWidget( &lab); | 284 | QLabel label ( i18n("Port number (Default: %1)").arg(po), &dia ); |
282 | 285 | lay.addWidget( &label); | |
283 | QLineEdit lepw ( &dia ); | 286 | lay.addWidget( &lab); |
284 | lepw.setText( mPrefs->mPassiveSyncPw ); | 287 | |
285 | QLabel label2 ( i18n("Password to enable\naccess from remote:"), &dia ); | 288 | QLineEdit lepw ( &dia ); |
286 | lay.addWidget( &label2); | 289 | lepw.setText( mPrefs->mPassiveSyncPw ); |
287 | lay.addWidget( &lepw); | 290 | QLabel label2 ( i18n("Password to enable\naccess from remote:"), &dia ); |
288 | dia.setFixedSize( 230,80 ); | 291 | lay.addWidget( &label2); |
289 | dia.setCaption( i18n("Enter port for Pi-Sync") ); | 292 | lay.addWidget( &lepw); |
290 | QPushButton pb ( "OK", &dia); | 293 | QCheckBox autostart(i18n("Automatically start\nat application startup"), &dia ); |
291 | lay.addWidget( &pb ); | 294 | lay.addWidget( &autostart); |
292 | connect(&pb, SIGNAL( clicked() ), &dia, SLOT ( accept() ) ); | 295 | autostart.setChecked( mPrefs->mPassiveSyncAutoStart ); |
293 | dia.show(); | 296 | #ifdef DESKTOP_VERSION |
294 | if ( ! dia.exec() ) | 297 | #ifdef _WIN32_ |
295 | return; | 298 | QCheckBox syncdesktop( i18n("Automatically sync with Outlook\nwhen receiving sync request"),&dia ); |
296 | dia.hide(); | 299 | #else |
297 | qApp->processEvents(); | 300 | QCheckBox syncdesktop( i18n("Automatically sync with KDE-Desktop\nwhen receiving sync request"),&dia ); |
298 | mPrefs->mPassiveSyncPw = lepw.text(); | 301 | #endif |
299 | mPrefs->mPassiveSyncPort = lab.text(); | 302 | lay.addWidget( &syncdesktop); |
303 | #else | ||
304 | QCheckBox syncdesktop( i18n("Automatically sync\nwith KDE-Desktop"),&dia ); | ||
305 | syncdesktop.hide(); | ||
306 | #endif | ||
307 | syncdesktop.setChecked( mPrefs->mPassiveSyncWithDesktop ); | ||
308 | |||
309 | dia.setFixedSize( 230,120 ); | ||
310 | dia.setCaption( i18n("Enter port for Pi-Sync") ); | ||
311 | QPushButton pb ( "OK", &dia); | ||
312 | lay.addWidget( &pb ); | ||
313 | connect(&pb, SIGNAL( clicked() ), &dia, SLOT ( accept() ) ); | ||
314 | dia.show(); | ||
315 | if ( ! dia.exec() ) | ||
316 | return; | ||
317 | dia.hide(); | ||
318 | qApp->processEvents(); | ||
319 | mPrefs->mPassiveSyncPw = lepw.text(); | ||
320 | mPrefs->mPassiveSyncPort = lab.text(); | ||
321 | autoStart = autostart.isChecked(); | ||
322 | mPrefs->mPassiveSyncWithDesktop = syncdesktop.isChecked(); | ||
323 | } | ||
324 | else | ||
325 | autoStart = mPrefs->mPassiveSyncAutoStart; | ||
300 | bool ok; | 326 | bool ok; |
327 | mPrefs->mPassiveSyncAutoStart = false; | ||
301 | Q_UINT16 port = mPrefs->mPassiveSyncPort.toUInt(&ok); | 328 | Q_UINT16 port = mPrefs->mPassiveSyncPort.toUInt(&ok); |
302 | if ( ! ok ) { | 329 | if ( ! ok ) { |
303 | KMessageBox::information( 0, i18n("No valid port")); | 330 | KMessageBox::information( 0, i18n("No valid port")); |
304 | return; | 331 | return; |
305 | } | 332 | } |
306 | //qDebug("port %d ", port); | 333 | //qDebug("port %d ", port); |
307 | mServerSocket = new KServerSocket ( mPrefs->mPassiveSyncPw, port ,1 ); | 334 | mServerSocket = new KServerSocket ( mPrefs->mPassiveSyncPw, port ,1 ); |
308 | mServerSocket->setFileName( defaultFileName() ); | 335 | mServerSocket->setFileName( defaultFileName() ); |
309 | //qDebug("connected "); | 336 | //qDebug("connected "); |
310 | if ( !mServerSocket->ok() ) { | 337 | if ( !mServerSocket->ok() ) { |
311 | KMessageBox::information( 0, i18n("Failed to bind or\nlisten to the port!")); | 338 | KMessageBox::information( 0, i18n("Failed to bind or\nlisten to the port!")); |
312 | delete mServerSocket; | 339 | delete mServerSocket; |
313 | mServerSocket = 0; | 340 | mServerSocket = 0; |
314 | return; | 341 | return; |
315 | } | 342 | } |
343 | |||
344 | mPrefs->mPassiveSyncAutoStart = autoStart; | ||
316 | connect( mServerSocket, SIGNAL ( request_file() ),this, SIGNAL ( request_file() ) ); | 345 | connect( mServerSocket, SIGNAL ( request_file() ),this, SIGNAL ( request_file() ) ); |
317 | connect( mServerSocket, SIGNAL ( file_received( bool ) ), this, SIGNAL ( getFile( bool ) ) ); | 346 | connect( mServerSocket, SIGNAL ( file_received( bool ) ), this, SIGNAL ( getFile( bool ) ) ); |
318 | } | 347 | } |
319 | 348 | ||
320 | void KSyncManager::syncLocalFile() | 349 | void KSyncManager::syncLocalFile() |
321 | { | 350 | { |
322 | 351 | ||
323 | QString fn =mPrefs->mLastSyncedLocalFile; | 352 | QString fn =mPrefs->mLastSyncedLocalFile; |
324 | QString ext; | 353 | QString ext; |
325 | 354 | ||
326 | switch(mTargetApp) | 355 | switch(mTargetApp) |
327 | { | 356 | { |
328 | case (KAPI): | 357 | case (KAPI): |
329 | ext = "(*.vcf)"; | 358 | ext = "(*.vcf)"; |
330 | break; | 359 | break; |
331 | case (KOPI): | 360 | case (KOPI): |
332 | ext = "(*.ics/*.vcs)"; | 361 | ext = "(*.ics/*.vcs)"; |
333 | break; | 362 | break; |
334 | case (PWMPI): | 363 | case (PWMPI): |
335 | ext = "(*.pwm)"; | 364 | ext = "(*.pwm)"; |
336 | break; | 365 | break; |
337 | default: | 366 | default: |
338 | qDebug("KSyncManager::syncLocalFile: invalid apptype selected"); | 367 | qDebug("KSyncManager::syncLocalFile: invalid apptype selected"); |
339 | break; | 368 | break; |
340 | 369 | ||
341 | } | 370 | } |
342 | 371 | ||
343 | fn =KFileDialog:: getOpenFileName( fn, i18n("Sync filename"+ext), mParent ); | 372 | fn =KFileDialog:: getOpenFileName( fn, i18n("Sync filename"+ext), mParent ); |
344 | if ( fn == "" ) | 373 | if ( fn == "" ) |
345 | return; | 374 | return; |
346 | if ( syncWithFile( fn, false ) ) { | 375 | if ( syncWithFile( fn, false ) ) { |
347 | qDebug("syncLocalFile() successful "); | 376 | qDebug("syncLocalFile() successful "); |
348 | } | 377 | } |
349 | 378 | ||
350 | } | 379 | } |
351 | 380 | ||
352 | bool KSyncManager::syncWithFile( QString fn , bool quick ) | 381 | bool KSyncManager::syncWithFile( QString fn , bool quick ) |
353 | { | 382 | { |
354 | bool ret = false; | 383 | bool ret = false; |
355 | QFileInfo info; | 384 | QFileInfo info; |
356 | info.setFile( fn ); | 385 | info.setFile( fn ); |
357 | QString mess; | 386 | QString mess; |
358 | bool loadbup = true; | 387 | bool loadbup = true; |
359 | if ( !info. exists() ) { | 388 | if ( !info. exists() ) { |
360 | mess = i18n( "Sync file \n...%1\ndoes not exist!\nNothing synced!\n").arg(fn.right( 30) ); | 389 | mess = i18n( "Sync file \n...%1\ndoes not exist!\nNothing synced!\n").arg(fn.right( 30) ); |
361 | int result = QMessageBox::warning( mParent, i18n("Warning!"), | 390 | int result = QMessageBox::warning( mParent, i18n("Warning!"), |
362 | mess ); | 391 | mess ); |
363 | return ret; | 392 | return ret; |