-rw-r--r-- | libkdepim/ksyncmanager.cpp | 186 |
1 files changed, 161 insertions, 25 deletions
diff --git a/libkdepim/ksyncmanager.cpp b/libkdepim/ksyncmanager.cpp index 87f200a..07e6761 100644 --- a/libkdepim/ksyncmanager.cpp +++ b/libkdepim/ksyncmanager.cpp | |||
@@ -21,104 +21,118 @@ | |||
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 | 35 | ||
36 | #include <qdir.h> | 36 | #include <qdir.h> |
37 | #include <qprogressbar.h> | ||
37 | #include <qpopupmenu.h> | 38 | #include <qpopupmenu.h> |
38 | #include <qpushbutton.h> | 39 | #include <qpushbutton.h> |
39 | #include <qradiobutton.h> | 40 | #include <qradiobutton.h> |
40 | #include <qbuttongroup.h> | 41 | #include <qbuttongroup.h> |
41 | #include <qtimer.h> | 42 | #include <qtimer.h> |
42 | #include <qmessagebox.h> | 43 | #include <qmessagebox.h> |
43 | #include <qapplication.h> | 44 | #include <qapplication.h> |
44 | #include <qlineedit.h> | 45 | #include <qlineedit.h> |
45 | #include <qdialog.h> | 46 | #include <qdialog.h> |
46 | #include <qlayout.h> | 47 | #include <qlayout.h> |
47 | 48 | ||
48 | #include <klocale.h> | 49 | #include <klocale.h> |
49 | #include <kglobal.h> | 50 | #include <kglobal.h> |
50 | #include <kconfig.h> | 51 | #include <kconfig.h> |
51 | #include <kfiledialog.h> | 52 | #include <kfiledialog.h> |
52 | 53 | ||
53 | KSyncManager::KSyncManager(QWidget* parent, KSyncInterface* implementation, TargetApp ta, KPimPrefs* prefs, QPopupMenu* syncmenu) | 54 | KSyncManager::KSyncManager(QWidget* parent, KSyncInterface* implementation, TargetApp ta, KPimPrefs* prefs, QPopupMenu* syncmenu) |
54 | : QObject(), mParent(parent), mImplementation(implementation), mTargetApp(ta), mPrefs(prefs), mSyncMenu(syncmenu) | 55 | : QObject(), mParent(parent), mImplementation(implementation), mTargetApp(ta), mPrefs(prefs), mSyncMenu(syncmenu) |
55 | { | 56 | { |
57 | bar = new QProgressBar ( 1, 0 ); | ||
58 | bar->setCaption (""); | ||
59 | |||
60 | int w = 300; | ||
61 | if ( QApplication::desktop()->width() < 320 ) | ||
62 | w = 220; | ||
63 | int h = bar->sizeHint().height() ; | ||
64 | int dw = QApplication::desktop()->width(); | ||
65 | int dh = QApplication::desktop()->height(); | ||
66 | bar->setGeometry( (dw-w)/2, (dh - h )/2 ,w,h ); | ||
56 | 67 | ||
57 | } | 68 | } |
58 | 69 | ||
59 | KSyncManager::~KSyncManager() | 70 | KSyncManager::~KSyncManager() |
60 | { | 71 | { |
61 | 72 | delete bar; | |
62 | } | 73 | } |
63 | 74 | ||
64 | 75 | ||
65 | void KSyncManager::fillSyncMenu() | 76 | void KSyncManager::fillSyncMenu() |
66 | { | 77 | { |
67 | if ( mSyncMenu->count() ) | 78 | if ( mSyncMenu->count() ) |
68 | mSyncMenu->clear(); | 79 | mSyncMenu->clear(); |
69 | 80 | ||
70 | mSyncMenu->insertItem( i18n("Configure..."), 0 ); | 81 | mSyncMenu->insertItem( i18n("Configure..."), 0 ); |
71 | mSyncMenu->insertSeparator(); | 82 | mSyncMenu->insertSeparator(); |
72 | mSyncMenu->insertItem( i18n("Multiple sync"), 1 ); | 83 | mSyncMenu->insertItem( i18n("Multiple sync"), 1 ); |
73 | mSyncMenu->insertSeparator(); | 84 | mSyncMenu->insertSeparator(); |
74 | 85 | ||
75 | KConfig config ( locateLocal( "config","ksyncprofilesrc" ) ); | 86 | KConfig config ( locateLocal( "config","ksyncprofilesrc" ) ); |
76 | config.setGroup("General"); | 87 | config.setGroup("General"); |
77 | QStringList prof = config.readListEntry("SyncProfileNames"); | 88 | QStringList prof = config.readListEntry("SyncProfileNames"); |
78 | mPrefs->mLocalMachineName = config.readEntry("LocalMachineName","undefined"); | 89 | mPrefs->mLocalMachineName = config.readEntry("LocalMachineName","undefined"); |
79 | if ( prof.count() < 3 ) { | 90 | if ( prof.count() < 3 ) { |
80 | prof.clear(); | 91 | prof.clear(); |
81 | prof << i18n("Sharp_DTM"); | 92 | prof << i18n("Sharp_DTM"); |
82 | prof << i18n("Local_file"); | 93 | prof << i18n("Local_file"); |
83 | prof << i18n("Last_file"); | 94 | prof << i18n("Last_file"); |
84 | KSyncProfile* temp = new KSyncProfile (); | 95 | KSyncProfile* temp = new KSyncProfile (); |
85 | temp->setName( prof[0] ); | 96 | temp->setName( prof[0] ); |
86 | temp->writeConfig(&config); | 97 | temp->writeConfig(&config); |
87 | temp->setName( prof[1] ); | 98 | temp->setName( prof[1] ); |
88 | temp->writeConfig(&config); | 99 | temp->writeConfig(&config); |
89 | temp->setName( prof[2] ); | 100 | temp->setName( prof[2] ); |
90 | temp->writeConfig(&config); | 101 | temp->writeConfig(&config); |
91 | config.setGroup("General"); | 102 | config.setGroup("General"); |
92 | config.writeEntry("SyncProfileNames",prof); | 103 | config.writeEntry("SyncProfileNames",prof); |
93 | config.writeEntry("ExternSyncProfiles","Sharp_DTM"); | 104 | config.writeEntry("ExternSyncProfiles","Sharp_DTM"); |
94 | config.sync(); | 105 | config.sync(); |
95 | delete temp; | 106 | delete temp; |
96 | } | 107 | } |
97 | mPrefs->mExternSyncProfiles = config.readListEntry("ExternSyncProfiles"); | 108 | mPrefs->mExternSyncProfiles = config.readListEntry("ExternSyncProfiles"); |
98 | mPrefs->mSyncProfileNames = prof; | 109 | mPrefs->mSyncProfileNames = prof; |
99 | unsigned int i; | 110 | unsigned int i; |
100 | for ( i = 0; i < prof.count(); ++i ) { | 111 | for ( i = 0; i < prof.count(); ++i ) { |
101 | |||
102 | mSyncMenu->insertItem( prof[i], 1000+i ); | 112 | mSyncMenu->insertItem( prof[i], 1000+i ); |
103 | if ( i == 2 ) | 113 | if ( i == 2 ) |
104 | mSyncMenu->insertSeparator(); | 114 | mSyncMenu->insertSeparator(); |
105 | } | 115 | } |
106 | QDir app_dir; | 116 | QDir app_dir; |
107 | if ( !app_dir.exists(QDir::homeDirPath()+"/Applications/dtm" ) ) { | 117 | //US do not display SharpDTM if app is pwmpi, or no sharpfiles available |
108 | mSyncMenu->setItemEnabled( false , 1000 ); | 118 | if ( mTargetApp == PWMPI) { |
119 | mSyncMenu->removeItem( 1000 ); | ||
120 | } | ||
121 | else if (!app_dir.exists(QDir::homeDirPath()+"/Applications/dtm" ) ) { | ||
122 | mSyncMenu->setItemEnabled( 1000, false ); | ||
109 | } | 123 | } |
110 | //probaly useless | 124 | //probaly useless |
111 | //mView->setupExternSyncProfiles(); | 125 | //mView->setupExternSyncProfiles(); |
112 | } | 126 | } |
113 | 127 | ||
114 | void KSyncManager::slotSyncMenu( int action ) | 128 | void KSyncManager::slotSyncMenu( int action ) |
115 | { | 129 | { |
116 | //qDebug("syncaction %d ", action); | 130 | //qDebug("syncaction %d ", action); |
117 | if ( action == 0 ) { | 131 | if ( action == 0 ) { |
118 | 132 | ||
119 | // seems to be a Qt2 event handling bug | 133 | // seems to be a Qt2 event handling bug |
120 | // syncmenu.clear causes a segfault at first time | 134 | // syncmenu.clear causes a segfault at first time |
121 | // when we call it after the main event loop, it is ok | 135 | // when we call it after the main event loop, it is ok |
122 | // same behaviour when calling OM/Pi via QCOP for the first time | 136 | // same behaviour when calling OM/Pi via QCOP for the first time |
123 | QTimer::singleShot ( 1, this, SLOT ( confSync() ) ); | 137 | QTimer::singleShot ( 1, this, SLOT ( confSync() ) ); |
124 | //confSync(); | 138 | //confSync(); |
@@ -148,56 +162,90 @@ void KSyncManager::slotSyncMenu( int action ) | |||
148 | mPrefs->mWriteBackExistingOnly = temp->getWriteBackExisting(); | 162 | mPrefs->mWriteBackExistingOnly = temp->getWriteBackExisting(); |
149 | mPrefs->mWriteBackInFuture = 0; | 163 | mPrefs->mWriteBackInFuture = 0; |
150 | if ( temp->getWriteBackFuture() ) | 164 | if ( temp->getWriteBackFuture() ) |
151 | mPrefs->mWriteBackInFuture = temp->getWriteBackFutureWeeks( ); | 165 | mPrefs->mWriteBackInFuture = temp->getWriteBackFutureWeeks( ); |
152 | mPrefs->mShowSyncSummary = temp->getShowSummaryAfterSync(); | 166 | mPrefs->mShowSyncSummary = temp->getShowSummaryAfterSync(); |
153 | if ( action == 1000 ) { | 167 | if ( action == 1000 ) { |
154 | syncSharp(); | 168 | syncSharp(); |
155 | 169 | ||
156 | } else if ( action == 1001 ) { | 170 | } else if ( action == 1001 ) { |
157 | syncLocalFile(); | 171 | syncLocalFile(); |
158 | 172 | ||
159 | } else if ( action == 1002 ) { | 173 | } else if ( action == 1002 ) { |
160 | quickSyncLocalFile(); | 174 | quickSyncLocalFile(); |
161 | 175 | ||
162 | } else if ( action >= 1003 ) { | 176 | } else if ( action >= 1003 ) { |
163 | if ( temp->getIsLocalFileSync() ) { | 177 | if ( temp->getIsLocalFileSync() ) { |
164 | if ( syncWithFile( temp->getRemoteFileNameAB( ), false ) ) | 178 | switch(mTargetApp) |
179 | { | ||
180 | case (KAPI): | ||
181 | if ( syncWithFile( temp->getRemoteFileNameAB( ), false ) ) | ||
165 | mPrefs->mLastSyncedLocalFile = temp->getRemoteFileNameAB(); | 182 | mPrefs->mLastSyncedLocalFile = temp->getRemoteFileNameAB(); |
166 | 183 | break; | |
184 | case (KOPI): | ||
185 | if ( syncWithFile( temp->getRemoteFileName( ), false ) ) | ||
186 | mPrefs->mLastSyncedLocalFile = temp->getRemoteFileName(); | ||
187 | break; | ||
188 | case (PWMPI): | ||
189 | if ( syncWithFile( temp->getRemoteFileNamePWM( ), false ) ) | ||
190 | mPrefs->mLastSyncedLocalFile = temp->getRemoteFileNamePWM(); | ||
191 | break; | ||
192 | default: | ||
193 | qDebug("KSyncManager::slotSyncMenu: invalid apptype selected"); | ||
194 | break; | ||
195 | |||
196 | } | ||
167 | } else { | 197 | } else { |
168 | if ( temp->getIsPhoneSync() ) { | 198 | if ( temp->getIsPhoneSync() ) { |
169 | mPrefs->mPhoneDevice = temp->getPhoneDevice( ) ; | 199 | mPrefs->mPhoneDevice = temp->getPhoneDevice( ) ; |
170 | mPrefs->mPhoneConnection = temp->getPhoneConnection( ); | 200 | mPrefs->mPhoneConnection = temp->getPhoneConnection( ); |
171 | mPrefs->mPhoneModel = temp->getPhoneModel( ); | 201 | mPrefs->mPhoneModel = temp->getPhoneModel( ); |
172 | syncPhone(); | 202 | syncPhone(); |
173 | } else | 203 | } else |
174 | syncRemote( temp ); | 204 | syncRemote( temp ); |
175 | 205 | ||
176 | } | 206 | } |
177 | } | 207 | } |
178 | delete temp; | 208 | delete temp; |
179 | setBlockSave(false); | 209 | setBlockSave(false); |
180 | } | 210 | } |
181 | 211 | ||
182 | void KSyncManager::syncLocalFile() | 212 | void KSyncManager::syncLocalFile() |
183 | { | 213 | { |
184 | 214 | ||
185 | QString fn =mPrefs->mLastSyncedLocalFile; | 215 | QString fn =mPrefs->mLastSyncedLocalFile; |
186 | 216 | QString ext; | |
187 | fn =KFileDialog:: getOpenFileName( fn, i18n("Sync filename(*.ics/*.vcs)"), mParent ); | 217 | |
218 | switch(mTargetApp) | ||
219 | { | ||
220 | case (KAPI): | ||
221 | ext = "(*.vcf)"; | ||
222 | break; | ||
223 | case (KOPI): | ||
224 | ext = "(*.ics/*.vcs)"; | ||
225 | break; | ||
226 | case (PWMPI): | ||
227 | ext = "(*.pwm)"; | ||
228 | break; | ||
229 | default: | ||
230 | qDebug("KSyncManager::syncLocalFile: invalid apptype selected"); | ||
231 | break; | ||
232 | |||
233 | } | ||
234 | |||
235 | fn =KFileDialog:: getOpenFileName( fn, i18n("Sync filename"+ext), mParent ); | ||
188 | if ( fn == "" ) | 236 | if ( fn == "" ) |
189 | return; | 237 | return; |
190 | if ( syncWithFile( fn, false ) ) { | 238 | if ( syncWithFile( fn, false ) ) { |
191 | qDebug("syncLocalFile() successful "); | 239 | qDebug("syncLocalFile() successful "); |
192 | } | 240 | } |
193 | 241 | ||
194 | } | 242 | } |
195 | bool KSyncManager::syncWithFile( QString fn , bool quick ) | 243 | bool KSyncManager::syncWithFile( QString fn , bool quick ) |
196 | { | 244 | { |
197 | bool ret = false; | 245 | bool ret = false; |
198 | QFileInfo info; | 246 | QFileInfo info; |
199 | info.setFile( fn ); | 247 | info.setFile( fn ); |
200 | QString mess; | 248 | QString mess; |
201 | bool loadbup = true; | 249 | bool loadbup = true; |
202 | if ( !info. exists() ) { | 250 | if ( !info. exists() ) { |
203 | mess = i18n( "Sync file \n...%1\ndoes not exist!\nNothing synced!\n").arg(fn.right( 30) ); | 251 | mess = i18n( "Sync file \n...%1\ndoes not exist!\nNothing synced!\n").arg(fn.right( 30) ); |
@@ -271,50 +319,86 @@ void KSyncManager::multiSync( bool askforPrefs ) | |||
271 | mParent->setCaption(i18n("Nothing synced! No profiles defined for multisync!")); | 319 | mParent->setCaption(i18n("Nothing synced! No profiles defined for multisync!")); |
272 | return; | 320 | return; |
273 | } | 321 | } |
274 | int KSyncManager::ringSync() | 322 | int KSyncManager::ringSync() |
275 | { | 323 | { |
276 | int syncedProfiles = 0; | 324 | int syncedProfiles = 0; |
277 | unsigned int i; | 325 | unsigned int i; |
278 | QTime timer; | 326 | QTime timer; |
279 | KConfig config ( locateLocal( "config","ksyncprofilesrc" ) ); | 327 | KConfig config ( locateLocal( "config","ksyncprofilesrc" ) ); |
280 | QStringList syncProfileNames = mPrefs->mSyncProfileNames; | 328 | QStringList syncProfileNames = mPrefs->mSyncProfileNames; |
281 | KSyncProfile* temp = new KSyncProfile (); | 329 | KSyncProfile* temp = new KSyncProfile (); |
282 | mPrefs->mAskForPreferences = false; | 330 | mPrefs->mAskForPreferences = false; |
283 | for ( i = 0; i < syncProfileNames.count(); ++i ) { | 331 | for ( i = 0; i < syncProfileNames.count(); ++i ) { |
284 | mCurrentSyncProfile = i; | 332 | mCurrentSyncProfile = i; |
285 | temp->setName(syncProfileNames[mCurrentSyncProfile]); | 333 | temp->setName(syncProfileNames[mCurrentSyncProfile]); |
286 | temp->readConfig(&config); | 334 | temp->readConfig(&config); |
287 | if ( temp->getIncludeInRingSyncAB() && ( i < 1 || i > 2 )) { | 335 | |
336 | QString includeInRingSync; | ||
337 | switch(mTargetApp) | ||
338 | { | ||
339 | case (KAPI): | ||
340 | includeInRingSync = temp->getIncludeInRingSyncAB(); | ||
341 | break; | ||
342 | case (KOPI): | ||
343 | includeInRingSync = temp->getIncludeInRingSync(); | ||
344 | break; | ||
345 | case (PWMPI): | ||
346 | includeInRingSync = temp->getIncludeInRingSyncPWM(); | ||
347 | break; | ||
348 | default: | ||
349 | qDebug("KSyncManager::ringSync: invalid apptype selected"); | ||
350 | break; | ||
351 | |||
352 | } | ||
353 | |||
354 | |||
355 | if ( includeInRingSync && ( i < 1 || i > 2 )) { | ||
288 | mParent->setCaption(i18n("Profile ")+syncProfileNames[mCurrentSyncProfile]+ i18n(" is synced ... ")); | 356 | mParent->setCaption(i18n("Profile ")+syncProfileNames[mCurrentSyncProfile]+ i18n(" is synced ... ")); |
289 | ++syncedProfiles; | 357 | ++syncedProfiles; |
290 | // mPrefs->mAskForPreferences = temp->getAskForPreferences(); | 358 | // mPrefs->mAskForPreferences = temp->getAskForPreferences(); |
291 | mPrefs->mWriteBackFile = temp->getWriteBackFile(); | 359 | mPrefs->mWriteBackFile = temp->getWriteBackFile(); |
292 | mPrefs->mWriteBackExistingOnly = temp->getWriteBackExisting(); | 360 | mPrefs->mWriteBackExistingOnly = temp->getWriteBackExisting(); |
293 | mPrefs->mWriteBackInFuture = 0; | 361 | mPrefs->mWriteBackInFuture = 0; |
294 | if ( temp->getWriteBackFuture() ) | 362 | if ( temp->getWriteBackFuture() ) |
295 | mPrefs->mWriteBackInFuture = temp->getWriteBackFutureWeeks( ); | 363 | mPrefs->mWriteBackInFuture = temp->getWriteBackFutureWeeks( ); |
296 | mPrefs->mShowSyncSummary = false; | 364 | mPrefs->mShowSyncSummary = false; |
297 | mCurrentSyncDevice = syncProfileNames[i] ; | 365 | mCurrentSyncDevice = syncProfileNames[i] ; |
298 | mCurrentSyncName = mPrefs->mLocalMachineName; | 366 | mCurrentSyncName = mPrefs->mLocalMachineName; |
299 | if ( i == 0 ) { | 367 | if ( i == 0 ) { |
300 | syncSharp(); | 368 | syncSharp(); |
301 | } else { | 369 | } else { |
302 | if ( temp->getIsLocalFileSync() ) { | 370 | if ( temp->getIsLocalFileSync() ) { |
303 | if ( syncWithFile( temp->getRemoteFileNameAB( ), true ) ) | 371 | switch(mTargetApp) |
304 | mPrefs->mLastSyncedLocalFile = temp->getRemoteFileNameAB(); | 372 | { |
373 | case (KAPI): | ||
374 | if ( syncWithFile( temp->getRemoteFileNameAB( ), false ) ) | ||
375 | mPrefs->mLastSyncedLocalFile = temp->getRemoteFileNameAB(); | ||
376 | break; | ||
377 | case (KOPI): | ||
378 | if ( syncWithFile( temp->getRemoteFileName( ), false ) ) | ||
379 | mPrefs->mLastSyncedLocalFile = temp->getRemoteFileName(); | ||
380 | break; | ||
381 | case (PWMPI): | ||
382 | if ( syncWithFile( temp->getRemoteFileNamePWM( ), false ) ) | ||
383 | mPrefs->mLastSyncedLocalFile = temp->getRemoteFileNamePWM(); | ||
384 | break; | ||
385 | default: | ||
386 | qDebug("KSyncManager::slotSyncMenu: invalid apptype selected"); | ||
387 | break; | ||
388 | } | ||
305 | } else { | 389 | } else { |
306 | if ( temp->getIsPhoneSync() ) { | 390 | if ( temp->getIsPhoneSync() ) { |
307 | mPrefs->mPhoneDevice = temp->getPhoneDevice( ) ; | 391 | mPrefs->mPhoneDevice = temp->getPhoneDevice( ) ; |
308 | mPrefs->mPhoneConnection = temp->getPhoneConnection( ); | 392 | mPrefs->mPhoneConnection = temp->getPhoneConnection( ); |
309 | mPrefs->mPhoneModel = temp->getPhoneModel( ); | 393 | mPrefs->mPhoneModel = temp->getPhoneModel( ); |
310 | syncPhone(); | 394 | syncPhone(); |
311 | } else | 395 | } else |
312 | syncRemote( temp, false ); | 396 | syncRemote( temp, false ); |
313 | 397 | ||
314 | } | 398 | } |
315 | } | 399 | } |
316 | timer.start(); | 400 | timer.start(); |
317 | mParent->setCaption(i18n("Multiple sync in progress ... please wait!") ); | 401 | mParent->setCaption(i18n("Multiple sync in progress ... please wait!") ); |
318 | while ( timer.elapsed () < 2000 ) { | 402 | while ( timer.elapsed () < 2000 ) { |
319 | qApp->processEvents(); | 403 | qApp->processEvents(); |
320 | #ifndef _WIN32_ | 404 | #ifndef _WIN32_ |
@@ -327,79 +411,108 @@ int KSyncManager::ringSync() | |||
327 | } | 411 | } |
328 | delete temp; | 412 | delete temp; |
329 | return syncedProfiles; | 413 | return syncedProfiles; |
330 | } | 414 | } |
331 | 415 | ||
332 | void KSyncManager::syncRemote( KSyncProfile* prof, bool ask) | 416 | void KSyncManager::syncRemote( KSyncProfile* prof, bool ask) |
333 | { | 417 | { |
334 | QString question; | 418 | QString question; |
335 | if ( ask ) { | 419 | if ( ask ) { |
336 | question = i18n("Do you really want\nto remote sync\nwith profile \n")+ prof->getName()+" ?\n"; | 420 | question = i18n("Do you really want\nto remote sync\nwith profile \n")+ prof->getName()+" ?\n"; |
337 | if ( QMessageBox::information( mParent, i18n("Sync"), | 421 | if ( QMessageBox::information( mParent, i18n("Sync"), |
338 | question, | 422 | question, |
339 | i18n("Yes"), i18n("No"), | 423 | i18n("Yes"), i18n("No"), |
340 | 0, 0 ) != 0 ) | 424 | 0, 0 ) != 0 ) |
341 | return; | 425 | return; |
342 | } | 426 | } |
343 | QString command = prof->getPreSyncCommandAB(); | 427 | |
428 | QString preCommand; | ||
429 | QString localTempFile; | ||
430 | QString postCommand; | ||
431 | |||
432 | switch(mTargetApp) | ||
433 | { | ||
434 | case (KAPI): | ||
435 | preCommand = prof->getPreSyncCommandAB(); | ||
436 | postCommand = prof->getPostSyncCommandAB(); | ||
437 | localTempFile = prof->getLocalTempFileAB(); | ||
438 | break; | ||
439 | case (KOPI): | ||
440 | preCommand = prof->getPreSyncCommand(); | ||
441 | postCommand = prof->getPostSyncCommand(); | ||
442 | localTempFile = prof->getLocalTempFile(); | ||
443 | break; | ||
444 | case (PWMPI): | ||
445 | preCommand = prof->getPreSyncCommandPWM(); | ||
446 | postCommand = prof->getPostSyncCommandPWM(); | ||
447 | localTempFile = prof->getLocalTempFilePWM(); | ||
448 | break; | ||
449 | default: | ||
450 | qDebug("KSyncManager::syncRemote: invalid apptype selected"); | ||
451 | break; | ||
452 | } | ||
453 | |||
454 | |||
344 | int fi; | 455 | int fi; |
345 | if ( (fi = command.find("$PWD$")) > 0 ) { | 456 | if ( (fi = preCommand.find("$PWD$")) > 0 ) { |
346 | QString pwd = getPassword(); | 457 | QString pwd = getPassword(); |
347 | command = command.left( fi )+ pwd + command.mid( fi+5 ); | 458 | preCommand = preCommand.left( fi )+ pwd + preCommand.mid( fi+5 ); |
348 | 459 | ||
349 | } | 460 | } |
350 | int maxlen = 30; | 461 | int maxlen = 30; |
351 | if ( QApplication::desktop()->width() > 320 ) | 462 | if ( QApplication::desktop()->width() > 320 ) |
352 | maxlen += 25; | 463 | maxlen += 25; |
353 | mParent->setCaption ( i18n( "Copy remote file to local machine..." ) ); | 464 | mParent->setCaption ( i18n( "Copy remote file to local machine..." ) ); |
354 | int fileSize = 0; | 465 | int fileSize = 0; |
355 | int result = system ( command ); | 466 | int result = system ( preCommand ); |
356 | // 0 : okay | 467 | // 0 : okay |
357 | // 256: no such file or dir | 468 | // 256: no such file or dir |
358 | // | 469 | // |
359 | qDebug("KO: Remote copy result(0 = okay): %d ",result ); | 470 | qDebug("KO: Remote copy result(0 = okay): %d ",result ); |
360 | if ( result != 0 ) { | 471 | if ( result != 0 ) { |
361 | unsigned int len = maxlen; | 472 | unsigned int len = maxlen; |
362 | while ( len < command.length() ) { | 473 | while ( len < preCommand.length() ) { |
363 | command.insert( len , "\n" ); | 474 | preCommand.insert( len , "\n" ); |
364 | len += maxlen +2; | 475 | len += maxlen +2; |
365 | } | 476 | } |
366 | 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 (command) ; | 477 | 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) ; |
367 | QMessageBox::information( mParent, i18n("Sync - ERROR"), | 478 | QMessageBox::information( mParent, i18n("Sync - ERROR"), |
368 | question, | 479 | question, |
369 | i18n("Okay!")) ; | 480 | i18n("Okay!")) ; |
370 | mParent->setCaption (""); | 481 | mParent->setCaption (""); |
371 | return; | 482 | return; |
372 | } | 483 | } |
373 | mParent->setCaption ( i18n( "Copying succeed." ) ); | 484 | mParent->setCaption ( i18n( "Copying succeed." ) ); |
374 | //qDebug(" file **%s** ",prof->getLocalTempFile().latin1() ); | 485 | //qDebug(" file **%s** ",prof->getLocalTempFile().latin1() ); |
375 | if ( syncWithFile( prof->getLocalTempFileAB(), true ) ) { | 486 | |
487 | |||
488 | |||
489 | if ( syncWithFile( localTempFile, true ) ) { | ||
376 | // Event* e = mView->getLastSyncEvent(); | 490 | // Event* e = mView->getLastSyncEvent(); |
377 | // e->setReadOnly( false ); | 491 | // e->setReadOnly( false ); |
378 | // e->setLocation( KOPrefs::instance()->mSyncProfileNames[mCurrentSyncProfile]); | 492 | // e->setLocation( KOPrefs::instance()->mSyncProfileNames[mCurrentSyncProfile]); |
379 | // e->setReadOnly( true ); | 493 | // e->setReadOnly( true ); |
380 | if ( mPrefs->mWriteBackFile ) { | 494 | if ( mPrefs->mWriteBackFile ) { |
381 | command = prof->getPostSyncCommandAB(); | ||
382 | int fi; | 495 | int fi; |
383 | if ( (fi = command.find("$PWD$")) > 0 ) { | 496 | if ( (fi = postCommand.find("$PWD$")) > 0 ) { |
384 | QString pwd = getPassword(); | 497 | QString pwd = getPassword(); |
385 | command = command.left( fi )+ pwd + command.mid( fi+5 ); | 498 | postCommand = postCommand.left( fi )+ pwd + postCommand.mid( fi+5 ); |
386 | 499 | ||
387 | } | 500 | } |
388 | mParent->setCaption ( i18n( "Writing back file ..." ) ); | 501 | mParent->setCaption ( i18n( "Writing back file ..." ) ); |
389 | result = system ( command ); | 502 | result = system ( postCommand ); |
390 | qDebug("Writing back file result: %d ", result); | 503 | qDebug("Writing back file result: %d ", result); |
391 | if ( result != 0 ) { | 504 | if ( result != 0 ) { |
392 | mParent->setCaption ( i18n( "Writing back file result: " )+QString::number( result ) ); | 505 | mParent->setCaption ( i18n( "Writing back file result: " )+QString::number( result ) ); |
393 | return; | 506 | return; |
394 | } else { | 507 | } else { |
395 | mParent->setCaption ( i18n( "Syncronization sucessfully completed" ) ); | 508 | mParent->setCaption ( i18n( "Syncronization sucessfully completed" ) ); |
396 | } | 509 | } |
397 | } | 510 | } |
398 | } | 511 | } |
399 | return; | 512 | return; |
400 | } | 513 | } |
401 | 514 | ||
402 | void KSyncManager::edit_sync_options() | 515 | void KSyncManager::edit_sync_options() |
403 | { | 516 | { |
404 | //mDialogManager->showSyncOptions(); | 517 | //mDialogManager->showSyncOptions(); |
405 | //mPrefs->mSyncAlgoPrefs | 518 | //mPrefs->mSyncAlgoPrefs |
@@ -514,16 +627,39 @@ bool KSyncManager::syncExternalApplication(QString resource) | |||
514 | bool syncOK = mImplementation->syncExternal(this, resource); | 627 | bool syncOK = mImplementation->syncExternal(this, resource); |
515 | 628 | ||
516 | return syncOK; | 629 | return syncOK; |
517 | 630 | ||
518 | } | 631 | } |
519 | 632 | ||
520 | void KSyncManager::syncPhone() | 633 | void KSyncManager::syncPhone() |
521 | { | 634 | { |
522 | if ( mImplementation->sync_isModified() ) | 635 | if ( mImplementation->sync_isModified() ) |
523 | mImplementation->sync_save(); | 636 | mImplementation->sync_save(); |
524 | 637 | ||
525 | qDebug("pending syncPhone(); "); | 638 | qDebug("pending syncPhone(); "); |
526 | //mView->syncPhone(); | 639 | //mView->syncPhone(); |
527 | mImplementation->sync_setModified(); | 640 | mImplementation->sync_setModified(); |
528 | 641 | ||
529 | } | 642 | } |
643 | |||
644 | void KSyncManager::showProgressBar(int percentage, QString caption, int total) | ||
645 | { | ||
646 | if (!bar->isVisible()) | ||
647 | { | ||
648 | bar->setCaption (caption); | ||
649 | bar->setTotalSteps ( total ) ; | ||
650 | |||
651 | bar->show(); | ||
652 | } | ||
653 | |||
654 | bar->setProgress( percentage ); | ||
655 | } | ||
656 | |||
657 | void KSyncManager::hideProgressBar() | ||
658 | { | ||
659 | bar->hide(); | ||
660 | } | ||
661 | |||
662 | bool KSyncManager::isProgressBarCanceled() | ||
663 | { | ||
664 | return !bar->isVisible(); | ||
665 | } | ||