-rw-r--r-- | libkdepim/ksyncmanager.cpp | 22 |
1 files changed, 18 insertions, 4 deletions
diff --git a/libkdepim/ksyncmanager.cpp b/libkdepim/ksyncmanager.cpp index 75c0b2b..7ca3ee0 100644 --- a/libkdepim/ksyncmanager.cpp +++ b/libkdepim/ksyncmanager.cpp | |||
@@ -1,728 +1,742 @@ | |||
1 | /* | 1 | /* |
2 | This file is part of KDE-Pim/Pi. | 2 | This file is part of KDE-Pim/Pi. |
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 | #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 | 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) |
59 | : QObject(), mParent(parent), mImplementation(implementation), mTargetApp(ta), mPrefs(prefs ),mSyncMenu(syncmenu) | 59 | : QObject(), mParent(parent), mImplementation(implementation), mTargetApp(ta), mPrefs(prefs ),mSyncMenu(syncmenu) |
60 | { | 60 | { |
61 | mServerSocket = 0; | 61 | mServerSocket = 0; |
62 | bar = new QProgressBar ( 1, 0 ); | 62 | bar = new QProgressBar ( 1, 0 ); |
63 | bar->setCaption (""); | 63 | bar->setCaption (""); |
64 | 64 | ||
65 | int w = 300; | 65 | int w = 300; |
66 | if ( QApplication::desktop()->width() < 320 ) | 66 | if ( QApplication::desktop()->width() < 320 ) |
67 | w = 220; | 67 | w = 220; |
68 | int h = bar->sizeHint().height() ; | 68 | int h = bar->sizeHint().height() ; |
69 | int dw = QApplication::desktop()->width(); | 69 | int dw = QApplication::desktop()->width(); |
70 | int dh = QApplication::desktop()->height(); | 70 | int dh = QApplication::desktop()->height(); |
71 | 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 ) | 72 | if ( mPrefs->mPassiveSyncAutoStart ) |
73 | enableQuick( false ); | 73 | enableQuick( false ); |
74 | 74 | ||
75 | } | 75 | } |
76 | 76 | ||
77 | KSyncManager::~KSyncManager() | 77 | KSyncManager::~KSyncManager() |
78 | { | 78 | { |
79 | delete bar; | 79 | delete bar; |
80 | } | 80 | } |
81 | 81 | ||
82 | 82 | ||
83 | void KSyncManager::fillSyncMenu() | 83 | void KSyncManager::fillSyncMenu() |
84 | { | 84 | { |
85 | if ( mSyncMenu->count() ) | 85 | if ( mSyncMenu->count() ) |
86 | mSyncMenu->clear(); | 86 | mSyncMenu->clear(); |
87 | 87 | ||
88 | mSyncMenu->insertItem( i18n("Configure..."), 0 ); | 88 | mSyncMenu->insertItem( i18n("Configure..."), 0 ); |
89 | mSyncMenu->insertSeparator(); | 89 | mSyncMenu->insertSeparator(); |
90 | if ( mServerSocket == 0 ) { | 90 | if ( mServerSocket == 0 ) { |
91 | mSyncMenu->insertItem( i18n("Enable Pi-Sync"), 2 ); | 91 | mSyncMenu->insertItem( i18n("Enable Pi-Sync"), 2 ); |
92 | } else { | 92 | } else { |
93 | mSyncMenu->insertItem( i18n("Disable Pi-Sync"), 3 ); | 93 | mSyncMenu->insertItem( i18n("Disable Pi-Sync"), 3 ); |
94 | } | 94 | } |
95 | mSyncMenu->insertSeparator(); | 95 | mSyncMenu->insertSeparator(); |
96 | mSyncMenu->insertItem( i18n("Multiple sync"), 1 ); | 96 | mSyncMenu->insertItem( i18n("Multiple sync"), 1 ); |
97 | mSyncMenu->insertSeparator(); | 97 | mSyncMenu->insertSeparator(); |
98 | 98 | ||
99 | KConfig config ( locateLocal( "config","ksyncprofilesrc" ) ); | 99 | KConfig config ( locateLocal( "config","ksyncprofilesrc" ) ); |
100 | config.setGroup("General"); | 100 | config.setGroup("General"); |
101 | QStringList prof = config.readListEntry("SyncProfileNames"); | 101 | QStringList prof = config.readListEntry("SyncProfileNames"); |
102 | mLocalMachineName = config.readEntry("LocalMachineName","undefined"); | 102 | mLocalMachineName = config.readEntry("LocalMachineName","undefined"); |
103 | if ( prof.count() < 2 ) { | 103 | if ( prof.count() < 2 ) { |
104 | prof.clear(); | 104 | prof.clear(); |
105 | #ifdef DESKTOP_VERSION | 105 | #ifdef DESKTOP_VERSION |
106 | #ifdef _WIN32_ | 106 | #ifdef _WIN32_ |
107 | prof << i18n("OutLook(not_implemented)"); | 107 | prof << i18n("OutLook(not_implemented)"); |
108 | #else | 108 | #else |
109 | prof << i18n("KDE_Desktop"); | 109 | prof << i18n("KDE_Desktop"); |
110 | #endif | 110 | #endif |
111 | #else | 111 | #else |
112 | prof << i18n("Sharp_DTM"); | 112 | prof << i18n("Sharp_DTM"); |
113 | #endif | 113 | #endif |
114 | prof << i18n("Local_file"); | 114 | prof << i18n("Local_file"); |
115 | prof << i18n("Last_file"); | 115 | prof << i18n("Last_file"); |
116 | KSyncProfile* temp = new KSyncProfile (); | 116 | KSyncProfile* temp = new KSyncProfile (); |
117 | temp->setName( prof[0] ); | 117 | temp->setName( prof[0] ); |
118 | temp->writeConfig(&config); | 118 | temp->writeConfig(&config); |
119 | temp->setName( prof[1] ); | 119 | temp->setName( prof[1] ); |
120 | temp->writeConfig(&config); | 120 | temp->writeConfig(&config); |
121 | temp->setName( prof[2] ); | 121 | temp->setName( prof[2] ); |
122 | temp->writeConfig(&config); | 122 | temp->writeConfig(&config); |
123 | config.setGroup("General"); | 123 | config.setGroup("General"); |
124 | config.writeEntry("SyncProfileNames",prof); | 124 | config.writeEntry("SyncProfileNames",prof); |
125 | config.writeEntry("ExternSyncProfiles","Sharp_DTM"); | 125 | config.writeEntry("ExternSyncProfiles","Sharp_DTM"); |
126 | config.sync(); | 126 | config.sync(); |
127 | delete temp; | 127 | delete temp; |
128 | } | 128 | } |
129 | mExternSyncProfiles = config.readListEntry("ExternSyncProfiles"); | 129 | mExternSyncProfiles = config.readListEntry("ExternSyncProfiles"); |
130 | mSyncProfileNames = prof; | 130 | mSyncProfileNames = prof; |
131 | unsigned int i; | 131 | unsigned int i; |
132 | for ( i = 0; i < prof.count(); ++i ) { | 132 | for ( i = 0; i < prof.count(); ++i ) { |
133 | mSyncMenu->insertItem( prof[i], 1000+i ); | 133 | mSyncMenu->insertItem( prof[i], 1000+i ); |
134 | if ( i == 2 ) | 134 | if ( i == 2 ) |
135 | mSyncMenu->insertSeparator(); | 135 | mSyncMenu->insertSeparator(); |
136 | } | 136 | } |
137 | QDir app_dir; | 137 | QDir app_dir; |
138 | //US do not display SharpDTM if app is pwmpi, or no sharpfiles available | 138 | //US do not display SharpDTM if app is pwmpi, or no sharpfiles available |
139 | if ( mTargetApp == PWMPI) { | 139 | if ( mTargetApp == PWMPI) { |
140 | mSyncMenu->removeItem( 1000 ); | 140 | mSyncMenu->removeItem( 1000 ); |
141 | } | 141 | } |
142 | #ifndef DESKTOP_VERSION | 142 | #ifndef DESKTOP_VERSION |
143 | else if (!app_dir.exists(QDir::homeDirPath()+"/Applications/dtm" ) ) { | 143 | else if (!app_dir.exists(QDir::homeDirPath()+"/Applications/dtm" ) ) { |
144 | mSyncMenu->removeItem( 1000 ); | 144 | mSyncMenu->removeItem( 1000 ); |
145 | } | 145 | } |
146 | #endif | 146 | #endif |
147 | mSyncMenu->removeItem( 1002 ); | 147 | mSyncMenu->removeItem( 1002 ); |
148 | } | 148 | } |
149 | 149 | ||
150 | void KSyncManager::slotSyncMenu( int action ) | 150 | void KSyncManager::slotSyncMenu( int action ) |
151 | { | 151 | { |
152 | qDebug("syncaction %d ", action); | 152 | qDebug("syncaction %d ", action); |
153 | if ( action == 0 ) { | 153 | if ( action == 0 ) { |
154 | 154 | ||
155 | // seems to be a Qt2 event handling bug | 155 | // seems to be a Qt2 event handling bug |
156 | // syncmenu.clear causes a segfault at first time | 156 | // syncmenu.clear causes a segfault at first time |
157 | // when we call it after the main event loop, it is ok | 157 | // when we call it after the main event loop, it is ok |
158 | // same behaviour when calling OM/Pi via QCOP for the first time | 158 | // same behaviour when calling OM/Pi via QCOP for the first time |
159 | QTimer::singleShot ( 1, this, SLOT ( confSync() ) ); | 159 | QTimer::singleShot ( 1, this, SLOT ( confSync() ) ); |
160 | //confSync(); | 160 | //confSync(); |
161 | 161 | ||
162 | return; | 162 | return; |
163 | } | 163 | } |
164 | if ( action == 1 ) { | 164 | if ( action == 1 ) { |
165 | multiSync( true ); | 165 | multiSync( true ); |
166 | return; | 166 | return; |
167 | } | 167 | } |
168 | if ( action == 2 ) { | 168 | if ( action == 2 ) { |
169 | enableQuick(); | 169 | enableQuick(); |
170 | QTimer::singleShot ( 1, this, SLOT ( fillSyncMenu() ) ); | 170 | QTimer::singleShot ( 1, this, SLOT ( fillSyncMenu() ) ); |
171 | return; | 171 | return; |
172 | } | 172 | } |
173 | if ( action == 3 ) { | 173 | if ( action == 3 ) { |
174 | delete mServerSocket; | 174 | delete mServerSocket; |
175 | mServerSocket = 0; | 175 | mServerSocket = 0; |
176 | QTimer::singleShot ( 1, this, SLOT ( fillSyncMenu() ) ); | 176 | QTimer::singleShot ( 1, this, SLOT ( fillSyncMenu() ) ); |
177 | return; | 177 | return; |
178 | } | 178 | } |
179 | 179 | ||
180 | if (blockSave()) | 180 | if (blockSave()) |
181 | return; | 181 | return; |
182 | 182 | ||
183 | setBlockSave(true); | 183 | setBlockSave(true); |
184 | 184 | ||
185 | mCurrentSyncProfile = action - 1000 ; | 185 | mCurrentSyncProfile = action - 1000 ; |
186 | mCurrentSyncDevice = mSyncProfileNames[mCurrentSyncProfile] ; | 186 | mCurrentSyncDevice = mSyncProfileNames[mCurrentSyncProfile] ; |
187 | mCurrentSyncName = mLocalMachineName ; | 187 | mCurrentSyncName = mLocalMachineName ; |
188 | KConfig config ( locateLocal( "config","ksyncprofilesrc" ) ); | 188 | KConfig config ( locateLocal( "config","ksyncprofilesrc" ) ); |
189 | KSyncProfile* temp = new KSyncProfile (); | 189 | KSyncProfile* temp = new KSyncProfile (); |
190 | temp->setName(mSyncProfileNames[mCurrentSyncProfile]); | 190 | temp->setName(mSyncProfileNames[mCurrentSyncProfile]); |
191 | temp->readConfig(&config); | 191 | temp->readConfig(&config); |
192 | mAskForPreferences = temp->getAskForPreferences(); | 192 | mAskForPreferences = temp->getAskForPreferences(); |
193 | mSyncAlgoPrefs = temp->getSyncPrefs(); | 193 | mSyncAlgoPrefs = temp->getSyncPrefs(); |
194 | mWriteBackFile = temp->getWriteBackFile(); | 194 | mWriteBackFile = temp->getWriteBackFile(); |
195 | mWriteBackExistingOnly = temp->getWriteBackExisting(); | 195 | mWriteBackExistingOnly = temp->getWriteBackExisting(); |
196 | mIsKapiFile = temp->getIsKapiFile(); | 196 | mIsKapiFile = temp->getIsKapiFile(); |
197 | mWriteBackInFuture = 0; | 197 | mWriteBackInFuture = 0; |
198 | if ( temp->getWriteBackFuture() ) | 198 | if ( temp->getWriteBackFuture() ) |
199 | mWriteBackInFuture = temp->getWriteBackFutureWeeks( ); | 199 | mWriteBackInFuture = temp->getWriteBackFutureWeeks( ); |
200 | mShowSyncSummary = temp->getShowSummaryAfterSync(); | 200 | mShowSyncSummary = temp->getShowSummaryAfterSync(); |
201 | if ( action == 1000 ) { | 201 | if ( action == 1000 ) { |
202 | #ifdef DESKTOP_VERSION | 202 | #ifdef DESKTOP_VERSION |
203 | syncKDE(); | 203 | syncKDE(); |
204 | #else | 204 | #else |
205 | syncSharp(); | 205 | syncSharp(); |
206 | #endif | 206 | #endif |
207 | 207 | ||
208 | } else if ( action == 1001 ) { | 208 | } else if ( action == 1001 ) { |
209 | syncLocalFile(); | 209 | syncLocalFile(); |
210 | 210 | ||
211 | } else if ( action == 1002 ) { | 211 | } else if ( action == 1002 ) { |
212 | mWriteBackFile = false; | 212 | mWriteBackFile = false; |
213 | mAskForPreferences = false; | 213 | mAskForPreferences = false; |
214 | mShowSyncSummary = false; | 214 | mShowSyncSummary = false; |
215 | mSyncAlgoPrefs = 3; | 215 | mSyncAlgoPrefs = 3; |
216 | quickSyncLocalFile(); | 216 | quickSyncLocalFile(); |
217 | 217 | ||
218 | } else if ( action >= 1003 ) { | 218 | } else if ( action >= 1003 ) { |
219 | if ( temp->getIsLocalFileSync() ) { | 219 | if ( temp->getIsLocalFileSync() ) { |
220 | switch(mTargetApp) | 220 | switch(mTargetApp) |
221 | { | 221 | { |
222 | case (KAPI): | 222 | case (KAPI): |
223 | if ( syncWithFile( temp->getRemoteFileNameAB( ), false ) ) | 223 | if ( syncWithFile( temp->getRemoteFileNameAB( ), false ) ) |
224 | mPrefs->mLastSyncedLocalFile = temp->getRemoteFileNameAB(); | 224 | mPrefs->mLastSyncedLocalFile = temp->getRemoteFileNameAB(); |
225 | break; | 225 | break; |
226 | case (KOPI): | 226 | case (KOPI): |
227 | if ( syncWithFile( temp->getRemoteFileName( ), false ) ) | 227 | if ( syncWithFile( temp->getRemoteFileName( ), false ) ) |
228 | mPrefs->mLastSyncedLocalFile = temp->getRemoteFileName(); | 228 | mPrefs->mLastSyncedLocalFile = temp->getRemoteFileName(); |
229 | break; | 229 | break; |
230 | case (PWMPI): | 230 | case (PWMPI): |
231 | if ( syncWithFile( temp->getRemoteFileNamePWM( ), false ) ) | 231 | if ( syncWithFile( temp->getRemoteFileNamePWM( ), false ) ) |
232 | mPrefs->mLastSyncedLocalFile = temp->getRemoteFileNamePWM(); | 232 | mPrefs->mLastSyncedLocalFile = temp->getRemoteFileNamePWM(); |
233 | break; | 233 | break; |
234 | default: | 234 | default: |
235 | qDebug("KSyncManager::slotSyncMenu: invalid apptype selected"); | 235 | qDebug("KSyncManager::slotSyncMenu: invalid apptype selected"); |
236 | break; | 236 | break; |
237 | 237 | ||
238 | } | 238 | } |
239 | } else { | 239 | } else { |
240 | if ( temp->getIsPhoneSync() ) { | 240 | if ( temp->getIsPhoneSync() ) { |
241 | mPhoneDevice = temp->getPhoneDevice( ) ; | 241 | mPhoneDevice = temp->getPhoneDevice( ) ; |
242 | mPhoneConnection = temp->getPhoneConnection( ); | 242 | mPhoneConnection = temp->getPhoneConnection( ); |
243 | mPhoneModel = temp->getPhoneModel( ); | 243 | mPhoneModel = temp->getPhoneModel( ); |
244 | syncPhone(); | 244 | syncPhone(); |
245 | } else if ( temp->getIsPiSync() ) { | 245 | } else if ( temp->getIsPiSync() ) { |
246 | if ( mTargetApp == KAPI ) { | 246 | if ( mTargetApp == KAPI ) { |
247 | mPassWordPiSync = temp->getRemotePwAB(); | 247 | mPassWordPiSync = temp->getRemotePwAB(); |
248 | mActiveSyncPort = temp->getRemotePortAB(); | 248 | mActiveSyncPort = temp->getRemotePortAB(); |
249 | mActiveSyncIP = temp->getRemoteIPAB(); | 249 | mActiveSyncIP = temp->getRemoteIPAB(); |
250 | } else if ( mTargetApp == KOPI ) { | 250 | } else if ( mTargetApp == KOPI ) { |
251 | mPassWordPiSync = temp->getRemotePw(); | 251 | mPassWordPiSync = temp->getRemotePw(); |
252 | mActiveSyncPort = temp->getRemotePort(); | 252 | mActiveSyncPort = temp->getRemotePort(); |
253 | mActiveSyncIP = temp->getRemoteIP(); | 253 | mActiveSyncIP = temp->getRemoteIP(); |
254 | } else { | 254 | } else { |
255 | mPassWordPiSync = temp->getRemotePwPWM(); | 255 | mPassWordPiSync = temp->getRemotePwPWM(); |
256 | mActiveSyncPort = temp->getRemotePortPWM(); | 256 | mActiveSyncPort = temp->getRemotePortPWM(); |
257 | mActiveSyncIP = temp->getRemoteIPPWM(); | 257 | mActiveSyncIP = temp->getRemoteIPPWM(); |
258 | } | 258 | } |
259 | syncPi(); | 259 | syncPi(); |
260 | while ( !mPisyncFinished ) { | 260 | while ( !mPisyncFinished ) { |
261 | //qDebug("waiting "); | 261 | //qDebug("waiting "); |
262 | qApp->processEvents(); | 262 | qApp->processEvents(); |
263 | } | 263 | } |
264 | } else | 264 | } else |
265 | syncRemote( temp ); | 265 | syncRemote( temp ); |
266 | 266 | ||
267 | } | 267 | } |
268 | } | 268 | } |
269 | delete temp; | 269 | delete temp; |
270 | setBlockSave(false); | 270 | setBlockSave(false); |
271 | } | 271 | } |
272 | 272 | ||
273 | void KSyncManager::enableQuick( bool ask ) | 273 | void KSyncManager::enableQuick( bool ask ) |
274 | { | 274 | { |
275 | bool autoStart; | 275 | bool autoStart; |
276 | bool changed = false; | ||
276 | if ( ask ) { | 277 | if ( ask ) { |
277 | QDialog dia ( 0, "input-dialog", true ); | 278 | QDialog dia ( 0, "input-dialog", true ); |
278 | QLineEdit lab ( &dia ); | 279 | QLineEdit lab ( &dia ); |
279 | QVBoxLayout lay( &dia ); | 280 | QVBoxLayout lay( &dia ); |
280 | lab.setText( mPrefs->mPassiveSyncPort ); | 281 | lab.setText( mPrefs->mPassiveSyncPort ); |
281 | lay.setMargin(7); | 282 | lay.setMargin(7); |
282 | lay.setSpacing(7); | 283 | lay.setSpacing(7); |
283 | int po = 9197+mTargetApp; | 284 | int po = 9197+mTargetApp; |
284 | QLabel label ( i18n("Port number (Default: %1)").arg(po), &dia ); | 285 | QLabel label ( i18n("Port number (Default: %1)").arg(po), &dia ); |
285 | lay.addWidget( &label); | 286 | lay.addWidget( &label); |
286 | lay.addWidget( &lab); | 287 | lay.addWidget( &lab); |
287 | 288 | ||
288 | QLineEdit lepw ( &dia ); | 289 | QLineEdit lepw ( &dia ); |
289 | lepw.setText( mPrefs->mPassiveSyncPw ); | 290 | lepw.setText( mPrefs->mPassiveSyncPw ); |
290 | QLabel label2 ( i18n("Password to enable\naccess from remote:"), &dia ); | 291 | QLabel label2 ( i18n("Password to enable\naccess from remote:"), &dia ); |
291 | lay.addWidget( &label2); | 292 | lay.addWidget( &label2); |
292 | lay.addWidget( &lepw); | 293 | lay.addWidget( &lepw); |
293 | QCheckBox autostart(i18n("Automatically start\nat application startup"), &dia ); | 294 | QCheckBox autostart(i18n("Automatically start\nat application startup"), &dia ); |
294 | lay.addWidget( &autostart); | 295 | lay.addWidget( &autostart); |
295 | autostart.setChecked( mPrefs->mPassiveSyncAutoStart ); | 296 | autostart.setChecked( mPrefs->mPassiveSyncAutoStart ); |
296 | #ifdef DESKTOP_VERSION | 297 | #ifdef DESKTOP_VERSION |
297 | #ifdef _WIN32_ | 298 | #ifdef _WIN32_ |
298 | QCheckBox syncdesktop( i18n("Automatically sync with Outlook\nwhen receiving sync request"),&dia ); | 299 | QCheckBox syncdesktop( i18n("Automatically sync with Outlook\nwhen receiving sync request"),&dia ); |
299 | #else | 300 | #else |
300 | QCheckBox syncdesktop( i18n("Automatically sync with KDE-Desktop\nwhen receiving sync request"),&dia ); | 301 | QCheckBox syncdesktop( i18n("Automatically sync with KDE-Desktop\nwhen receiving sync request"),&dia ); |
301 | #endif | 302 | #endif |
302 | lay.addWidget( &syncdesktop); | 303 | lay.addWidget( &syncdesktop); |
303 | #else | 304 | #else |
304 | QCheckBox syncdesktop( i18n("Automatically sync\nwith KDE-Desktop"),&dia ); | 305 | QCheckBox syncdesktop( i18n("Automatically sync\nwith KDE-Desktop"),&dia ); |
305 | syncdesktop.hide(); | 306 | syncdesktop.hide(); |
306 | #endif | 307 | #endif |
307 | syncdesktop.setChecked( mPrefs->mPassiveSyncWithDesktop ); | 308 | syncdesktop.setChecked( mPrefs->mPassiveSyncWithDesktop ); |
308 | 309 | ||
309 | dia.setFixedSize( 230,120 ); | 310 | dia.setFixedSize( 230,120 ); |
310 | dia.setCaption( i18n("Enter port for Pi-Sync") ); | 311 | dia.setCaption( i18n("Enter port for Pi-Sync") ); |
311 | QPushButton pb ( "OK", &dia); | 312 | QPushButton pb ( "OK", &dia); |
312 | lay.addWidget( &pb ); | 313 | lay.addWidget( &pb ); |
313 | connect(&pb, SIGNAL( clicked() ), &dia, SLOT ( accept() ) ); | 314 | connect(&pb, SIGNAL( clicked() ), &dia, SLOT ( accept() ) ); |
314 | dia.show(); | 315 | dia.show(); |
315 | if ( ! dia.exec() ) | 316 | if ( ! dia.exec() ) |
316 | return; | 317 | return; |
317 | dia.hide(); | 318 | dia.hide(); |
318 | qApp->processEvents(); | 319 | qApp->processEvents(); |
319 | mPrefs->mPassiveSyncPw = lepw.text(); | 320 | if ( mPrefs->mPassiveSyncPw != lepw.text() ) { |
320 | mPrefs->mPassiveSyncPort = lab.text(); | 321 | changed = true; |
322 | mPrefs->mPassiveSyncPw = lepw.text(); | ||
323 | } | ||
324 | if ( mPrefs->mPassiveSyncPort != lab.text() ) { | ||
325 | mPrefs->mPassiveSyncPort = lab.text(); | ||
326 | changed = true; | ||
327 | } | ||
321 | autoStart = autostart.isChecked(); | 328 | autoStart = autostart.isChecked(); |
322 | mPrefs->mPassiveSyncWithDesktop = syncdesktop.isChecked(); | 329 | if (mPrefs->mPassiveSyncWithDesktop != syncdesktop.isChecked() ) { |
330 | changed = true; | ||
331 | mPrefs->mPassiveSyncWithDesktop = syncdesktop.isChecked(); | ||
332 | } | ||
323 | } | 333 | } |
324 | else | 334 | else |
325 | autoStart = mPrefs->mPassiveSyncAutoStart; | 335 | autoStart = mPrefs->mPassiveSyncAutoStart; |
336 | if ( autoStart != mPrefs->mPassiveSyncAutoStart ) | ||
337 | changed = true; | ||
326 | bool ok; | 338 | bool ok; |
327 | mPrefs->mPassiveSyncAutoStart = false; | 339 | mPrefs->mPassiveSyncAutoStart = false; |
328 | Q_UINT16 port = mPrefs->mPassiveSyncPort.toUInt(&ok); | 340 | Q_UINT16 port = mPrefs->mPassiveSyncPort.toUInt(&ok); |
329 | if ( ! ok ) { | 341 | if ( ! ok ) { |
330 | KMessageBox::information( 0, i18n("No valid port")); | 342 | KMessageBox::information( 0, i18n("No valid port")); |
331 | return; | 343 | return; |
332 | } | 344 | } |
333 | //qDebug("port %d ", port); | 345 | //qDebug("port %d ", port); |
334 | mServerSocket = new KServerSocket ( mPrefs->mPassiveSyncPw, port ,1 ); | 346 | mServerSocket = new KServerSocket ( mPrefs->mPassiveSyncPw, port ,1 ); |
335 | mServerSocket->setFileName( defaultFileName() ); | 347 | mServerSocket->setFileName( defaultFileName() ); |
336 | //qDebug("connected "); | 348 | //qDebug("connected "); |
337 | if ( !mServerSocket->ok() ) { | 349 | if ( !mServerSocket->ok() ) { |
338 | KMessageBox::information( 0, i18n("Failed to bind or\nlisten to the port!")); | 350 | KMessageBox::information( 0, i18n("Failed to bind or\nlisten to the port!")); |
339 | delete mServerSocket; | 351 | delete mServerSocket; |
340 | mServerSocket = 0; | 352 | mServerSocket = 0; |
341 | return; | 353 | return; |
342 | } | 354 | } |
343 | |||
344 | mPrefs->mPassiveSyncAutoStart = autoStart; | 355 | mPrefs->mPassiveSyncAutoStart = autoStart; |
356 | if ( changed ) { | ||
357 | mPrefs->writeConfig(); | ||
358 | } | ||
345 | connect( mServerSocket, SIGNAL ( request_file() ),this, SIGNAL ( request_file() ) ); | 359 | connect( mServerSocket, SIGNAL ( request_file() ),this, SIGNAL ( request_file() ) ); |
346 | connect( mServerSocket, SIGNAL ( file_received( bool ) ), this, SIGNAL ( getFile( bool ) ) ); | 360 | connect( mServerSocket, SIGNAL ( file_received( bool ) ), this, SIGNAL ( getFile( bool ) ) ); |
347 | } | 361 | } |
348 | 362 | ||
349 | void KSyncManager::syncLocalFile() | 363 | void KSyncManager::syncLocalFile() |
350 | { | 364 | { |
351 | 365 | ||
352 | QString fn =mPrefs->mLastSyncedLocalFile; | 366 | QString fn =mPrefs->mLastSyncedLocalFile; |
353 | QString ext; | 367 | QString ext; |
354 | 368 | ||
355 | switch(mTargetApp) | 369 | switch(mTargetApp) |
356 | { | 370 | { |
357 | case (KAPI): | 371 | case (KAPI): |
358 | ext = "(*.vcf)"; | 372 | ext = "(*.vcf)"; |
359 | break; | 373 | break; |
360 | case (KOPI): | 374 | case (KOPI): |
361 | ext = "(*.ics/*.vcs)"; | 375 | ext = "(*.ics/*.vcs)"; |
362 | break; | 376 | break; |
363 | case (PWMPI): | 377 | case (PWMPI): |
364 | ext = "(*.pwm)"; | 378 | ext = "(*.pwm)"; |
365 | break; | 379 | break; |
366 | default: | 380 | default: |
367 | qDebug("KSyncManager::syncLocalFile: invalid apptype selected"); | 381 | qDebug("KSyncManager::syncLocalFile: invalid apptype selected"); |
368 | break; | 382 | break; |
369 | 383 | ||
370 | } | 384 | } |
371 | 385 | ||
372 | fn =KFileDialog:: getOpenFileName( fn, i18n("Sync filename"+ext), mParent ); | 386 | fn =KFileDialog:: getOpenFileName( fn, i18n("Sync filename"+ext), mParent ); |
373 | if ( fn == "" ) | 387 | if ( fn == "" ) |
374 | return; | 388 | return; |
375 | if ( syncWithFile( fn, false ) ) { | 389 | if ( syncWithFile( fn, false ) ) { |
376 | qDebug("syncLocalFile() successful "); | 390 | qDebug("syncLocalFile() successful "); |
377 | } | 391 | } |
378 | 392 | ||
379 | } | 393 | } |
380 | 394 | ||
381 | bool KSyncManager::syncWithFile( QString fn , bool quick ) | 395 | bool KSyncManager::syncWithFile( QString fn , bool quick ) |
382 | { | 396 | { |
383 | bool ret = false; | 397 | bool ret = false; |
384 | QFileInfo info; | 398 | QFileInfo info; |
385 | info.setFile( fn ); | 399 | info.setFile( fn ); |
386 | QString mess; | 400 | QString mess; |
387 | bool loadbup = true; | 401 | bool loadbup = true; |
388 | if ( !info. exists() ) { | 402 | if ( !info. exists() ) { |
389 | mess = i18n( "Sync file \n...%1\ndoes not exist!\nNothing synced!\n").arg(fn.right( 30) ); | 403 | mess = i18n( "Sync file \n...%1\ndoes not exist!\nNothing synced!\n").arg(fn.right( 30) ); |
390 | int result = QMessageBox::warning( mParent, i18n("Warning!"), | 404 | int result = QMessageBox::warning( mParent, i18n("Warning!"), |
391 | mess ); | 405 | mess ); |
392 | return ret; | 406 | return ret; |
393 | } | 407 | } |
394 | int result = 0; | 408 | int result = 0; |
395 | if ( !quick ) { | 409 | if ( !quick ) { |
396 | mess = i18n("Sync with file \n...%1\nfrom:\n%2\n").arg(fn.right( 25)).arg(KGlobal::locale()->formatDateTime(info.lastModified (), true, false )); | 410 | mess = i18n("Sync with file \n...%1\nfrom:\n%2\n").arg(fn.right( 25)).arg(KGlobal::locale()->formatDateTime(info.lastModified (), true, false )); |
397 | result = QMessageBox::warning( mParent, i18n("Warning!"), | 411 | result = QMessageBox::warning( mParent, i18n("Warning!"), |
398 | mess, | 412 | mess, |
399 | i18n("Sync"), i18n("Cancel"), 0, | 413 | i18n("Sync"), i18n("Cancel"), 0, |
400 | 0, 1 ); | 414 | 0, 1 ); |
401 | if ( result ) | 415 | if ( result ) |
402 | return false; | 416 | return false; |
403 | } | 417 | } |
404 | if ( mAskForPreferences ) | 418 | if ( mAskForPreferences ) |
405 | edit_sync_options(); | 419 | edit_sync_options(); |
406 | if ( result == 0 ) { | 420 | if ( result == 0 ) { |
407 | //qDebug("Now sycing ... "); | 421 | //qDebug("Now sycing ... "); |
408 | if ( ret = mImplementation->sync( this, fn, mSyncAlgoPrefs ) ) | 422 | if ( ret = mImplementation->sync( this, fn, mSyncAlgoPrefs ) ) |
409 | mParent->topLevelWidget()->setCaption( i18n("Synchronization successful") ); | 423 | mParent->topLevelWidget()->setCaption( i18n("Synchronization successful") ); |
410 | else | 424 | else |
411 | mParent->topLevelWidget()->setCaption( i18n("Sync cancelled or failed. Nothing synced.") ); | 425 | mParent->topLevelWidget()->setCaption( i18n("Sync cancelled or failed. Nothing synced.") ); |
412 | if ( ! quick ) | 426 | if ( ! quick ) |
413 | mPrefs->mLastSyncedLocalFile = fn; | 427 | mPrefs->mLastSyncedLocalFile = fn; |
414 | } | 428 | } |
415 | return ret; | 429 | return ret; |
416 | } | 430 | } |
417 | 431 | ||
418 | void KSyncManager::quickSyncLocalFile() | 432 | void KSyncManager::quickSyncLocalFile() |
419 | { | 433 | { |
420 | 434 | ||
421 | if ( syncWithFile( mPrefs->mLastSyncedLocalFile, true ) ) { | 435 | if ( syncWithFile( mPrefs->mLastSyncedLocalFile, true ) ) { |
422 | qDebug("quick syncLocalFile() successful "); | 436 | qDebug("quick syncLocalFile() successful "); |
423 | 437 | ||
424 | } | 438 | } |
425 | } | 439 | } |
426 | 440 | ||
427 | void KSyncManager::multiSync( bool askforPrefs ) | 441 | void KSyncManager::multiSync( bool askforPrefs ) |
428 | { | 442 | { |
429 | if (blockSave()) | 443 | if (blockSave()) |
430 | return; | 444 | return; |
431 | setBlockSave(true); | 445 | setBlockSave(true); |
432 | QString question = i18n("Do you really want\nto multiple sync\nwith all checked profiles?\nSyncing takes some\ntime - all profiles\nare synced twice!"); | 446 | QString question = i18n("Do you really want\nto multiple sync\nwith all checked profiles?\nSyncing takes some\ntime - all profiles\nare synced twice!"); |
433 | if ( QMessageBox::information( mParent, i18n("KDE-Pim Sync"), | 447 | if ( QMessageBox::information( mParent, i18n("KDE-Pim Sync"), |
434 | question, | 448 | question, |
435 | i18n("Yes"), i18n("No"), | 449 | i18n("Yes"), i18n("No"), |
436 | 0, 0 ) != 0 ) { | 450 | 0, 0 ) != 0 ) { |
437 | setBlockSave(false); | 451 | setBlockSave(false); |
438 | mParent->topLevelWidget()->setCaption(i18n("Aborted! Nothing synced!")); | 452 | mParent->topLevelWidget()->setCaption(i18n("Aborted! Nothing synced!")); |
439 | return; | 453 | return; |
440 | } | 454 | } |
441 | mCurrentSyncDevice = i18n("Multiple profiles") ; | 455 | mCurrentSyncDevice = i18n("Multiple profiles") ; |
442 | mSyncAlgoPrefs = mPrefs->mRingSyncAlgoPrefs; | 456 | mSyncAlgoPrefs = mPrefs->mRingSyncAlgoPrefs; |
443 | if ( askforPrefs ) { | 457 | if ( askforPrefs ) { |
444 | edit_sync_options(); | 458 | edit_sync_options(); |
445 | mPrefs->mRingSyncAlgoPrefs = mSyncAlgoPrefs; | 459 | mPrefs->mRingSyncAlgoPrefs = mSyncAlgoPrefs; |
446 | } | 460 | } |
447 | mParent->topLevelWidget()->setCaption(i18n("Multiple sync started.") ); | 461 | mParent->topLevelWidget()->setCaption(i18n("Multiple sync started.") ); |
448 | qApp->processEvents(); | 462 | qApp->processEvents(); |
449 | int num = ringSync() ; | 463 | int num = ringSync() ; |
450 | if ( num > 1 ) | 464 | if ( num > 1 ) |
451 | ringSync(); | 465 | ringSync(); |
452 | setBlockSave(false); | 466 | setBlockSave(false); |
453 | if ( num ) | 467 | if ( num ) |
454 | emit save(); | 468 | emit save(); |
455 | if ( num ) | 469 | if ( num ) |
456 | mParent->topLevelWidget()->setCaption(i18n("%1 profiles synced. Multiple sync complete!").arg(num) ); | 470 | mParent->topLevelWidget()->setCaption(i18n("%1 profiles synced. Multiple sync complete!").arg(num) ); |
457 | else | 471 | else |
458 | mParent->topLevelWidget()->setCaption(i18n("Nothing synced! No profiles defined for multisync!")); | 472 | mParent->topLevelWidget()->setCaption(i18n("Nothing synced! No profiles defined for multisync!")); |
459 | return; | 473 | return; |
460 | } | 474 | } |
461 | 475 | ||
462 | int KSyncManager::ringSync() | 476 | int KSyncManager::ringSync() |
463 | { | 477 | { |
464 | int syncedProfiles = 0; | 478 | int syncedProfiles = 0; |
465 | unsigned int i; | 479 | unsigned int i; |
466 | QTime timer; | 480 | QTime timer; |
467 | KConfig config ( locateLocal( "config","ksyncprofilesrc" ) ); | 481 | KConfig config ( locateLocal( "config","ksyncprofilesrc" ) ); |
468 | QStringList syncProfileNames = mSyncProfileNames; | 482 | QStringList syncProfileNames = mSyncProfileNames; |
469 | KSyncProfile* temp = new KSyncProfile (); | 483 | KSyncProfile* temp = new KSyncProfile (); |
470 | mAskForPreferences = false; | 484 | mAskForPreferences = false; |
471 | for ( i = 0; i < syncProfileNames.count(); ++i ) { | 485 | for ( i = 0; i < syncProfileNames.count(); ++i ) { |
472 | mCurrentSyncProfile = i; | 486 | mCurrentSyncProfile = i; |
473 | temp->setName(syncProfileNames[mCurrentSyncProfile]); | 487 | temp->setName(syncProfileNames[mCurrentSyncProfile]); |
474 | temp->readConfig(&config); | 488 | temp->readConfig(&config); |
475 | 489 | ||
476 | bool includeInRingSync; | 490 | bool includeInRingSync; |
477 | switch(mTargetApp) | 491 | switch(mTargetApp) |
478 | { | 492 | { |
479 | case (KAPI): | 493 | case (KAPI): |
480 | includeInRingSync = temp->getIncludeInRingSyncAB(); | 494 | includeInRingSync = temp->getIncludeInRingSyncAB(); |
481 | break; | 495 | break; |
482 | case (KOPI): | 496 | case (KOPI): |
483 | includeInRingSync = temp->getIncludeInRingSync(); | 497 | includeInRingSync = temp->getIncludeInRingSync(); |
484 | break; | 498 | break; |
485 | case (PWMPI): | 499 | case (PWMPI): |
486 | includeInRingSync = temp->getIncludeInRingSyncPWM(); | 500 | includeInRingSync = temp->getIncludeInRingSyncPWM(); |
487 | break; | 501 | break; |
488 | default: | 502 | default: |
489 | qDebug("KSyncManager::ringSync: invalid apptype selected"); | 503 | qDebug("KSyncManager::ringSync: invalid apptype selected"); |
490 | break; | 504 | break; |
491 | 505 | ||
492 | } | 506 | } |
493 | 507 | ||
494 | 508 | ||
495 | if ( includeInRingSync && ( i < 1 || i > 2 )) { | 509 | if ( includeInRingSync && ( i < 1 || i > 2 )) { |
496 | mParent->topLevelWidget()->setCaption(i18n("Profile ")+syncProfileNames[mCurrentSyncProfile]+ i18n(" is synced ... ")); | 510 | mParent->topLevelWidget()->setCaption(i18n("Profile ")+syncProfileNames[mCurrentSyncProfile]+ i18n(" is synced ... ")); |
497 | ++syncedProfiles; | 511 | ++syncedProfiles; |
498 | // mAskForPreferences = temp->getAskForPreferences(); | 512 | // mAskForPreferences = temp->getAskForPreferences(); |
499 | mWriteBackFile = temp->getWriteBackFile(); | 513 | mWriteBackFile = temp->getWriteBackFile(); |
500 | mWriteBackExistingOnly = temp->getWriteBackExisting(); | 514 | mWriteBackExistingOnly = temp->getWriteBackExisting(); |
501 | mWriteBackInFuture = 0; | 515 | mWriteBackInFuture = 0; |
502 | if ( temp->getWriteBackFuture() ) | 516 | if ( temp->getWriteBackFuture() ) |
503 | mWriteBackInFuture = temp->getWriteBackFutureWeeks( ); | 517 | mWriteBackInFuture = temp->getWriteBackFutureWeeks( ); |
504 | mShowSyncSummary = false; | 518 | mShowSyncSummary = false; |
505 | mCurrentSyncDevice = syncProfileNames[i] ; | 519 | mCurrentSyncDevice = syncProfileNames[i] ; |
506 | mCurrentSyncName = mLocalMachineName; | 520 | mCurrentSyncName = mLocalMachineName; |
507 | if ( i == 0 ) { | 521 | if ( i == 0 ) { |
508 | #ifdef DESKTOP_VERSION | 522 | #ifdef DESKTOP_VERSION |
509 | syncKDE(); | 523 | syncKDE(); |
510 | #else | 524 | #else |
511 | syncSharp(); | 525 | syncSharp(); |
512 | #endif | 526 | #endif |
513 | } else { | 527 | } else { |
514 | if ( temp->getIsLocalFileSync() ) { | 528 | if ( temp->getIsLocalFileSync() ) { |
515 | switch(mTargetApp) | 529 | switch(mTargetApp) |
516 | { | 530 | { |
517 | case (KAPI): | 531 | case (KAPI): |
518 | if ( syncWithFile( temp->getRemoteFileNameAB( ), false ) ) | 532 | if ( syncWithFile( temp->getRemoteFileNameAB( ), false ) ) |
519 | mPrefs->mLastSyncedLocalFile = temp->getRemoteFileNameAB(); | 533 | mPrefs->mLastSyncedLocalFile = temp->getRemoteFileNameAB(); |
520 | break; | 534 | break; |
521 | case (KOPI): | 535 | case (KOPI): |
522 | if ( syncWithFile( temp->getRemoteFileName( ), false ) ) | 536 | if ( syncWithFile( temp->getRemoteFileName( ), false ) ) |
523 | mPrefs->mLastSyncedLocalFile = temp->getRemoteFileName(); | 537 | mPrefs->mLastSyncedLocalFile = temp->getRemoteFileName(); |
524 | break; | 538 | break; |
525 | case (PWMPI): | 539 | case (PWMPI): |
526 | if ( syncWithFile( temp->getRemoteFileNamePWM( ), false ) ) | 540 | if ( syncWithFile( temp->getRemoteFileNamePWM( ), false ) ) |
527 | mPrefs->mLastSyncedLocalFile = temp->getRemoteFileNamePWM(); | 541 | mPrefs->mLastSyncedLocalFile = temp->getRemoteFileNamePWM(); |
528 | break; | 542 | break; |
529 | default: | 543 | default: |
530 | qDebug("KSyncManager::slotSyncMenu: invalid apptype selected"); | 544 | qDebug("KSyncManager::slotSyncMenu: invalid apptype selected"); |
531 | break; | 545 | break; |
532 | } | 546 | } |
533 | } else { | 547 | } else { |
534 | if ( temp->getIsPhoneSync() ) { | 548 | if ( temp->getIsPhoneSync() ) { |
535 | mPhoneDevice = temp->getPhoneDevice( ) ; | 549 | mPhoneDevice = temp->getPhoneDevice( ) ; |
536 | mPhoneConnection = temp->getPhoneConnection( ); | 550 | mPhoneConnection = temp->getPhoneConnection( ); |
537 | mPhoneModel = temp->getPhoneModel( ); | 551 | mPhoneModel = temp->getPhoneModel( ); |
538 | syncPhone(); | 552 | syncPhone(); |
539 | } else if ( temp->getIsPiSync() ) { | 553 | } else if ( temp->getIsPiSync() ) { |
540 | if ( mTargetApp == KAPI ) { | 554 | if ( mTargetApp == KAPI ) { |
541 | mPassWordPiSync = temp->getRemotePwAB(); | 555 | mPassWordPiSync = temp->getRemotePwAB(); |
542 | mActiveSyncPort = temp->getRemotePortAB(); | 556 | mActiveSyncPort = temp->getRemotePortAB(); |
543 | mActiveSyncIP = temp->getRemoteIPAB(); | 557 | mActiveSyncIP = temp->getRemoteIPAB(); |
544 | } else if ( mTargetApp == KOPI ) { | 558 | } else if ( mTargetApp == KOPI ) { |
545 | mPassWordPiSync = temp->getRemotePw(); | 559 | mPassWordPiSync = temp->getRemotePw(); |
546 | mActiveSyncPort = temp->getRemotePort(); | 560 | mActiveSyncPort = temp->getRemotePort(); |
547 | mActiveSyncIP = temp->getRemoteIP(); | 561 | mActiveSyncIP = temp->getRemoteIP(); |
548 | } else { | 562 | } else { |
549 | mPassWordPiSync = temp->getRemotePwPWM(); | 563 | mPassWordPiSync = temp->getRemotePwPWM(); |
550 | mActiveSyncPort = temp->getRemotePortPWM(); | 564 | mActiveSyncPort = temp->getRemotePortPWM(); |
551 | mActiveSyncIP = temp->getRemoteIPPWM(); | 565 | mActiveSyncIP = temp->getRemoteIPPWM(); |
552 | } | 566 | } |
553 | syncPi(); | 567 | syncPi(); |
554 | while ( !mPisyncFinished ) { | 568 | while ( !mPisyncFinished ) { |
555 | //qDebug("waiting "); | 569 | //qDebug("waiting "); |
556 | qApp->processEvents(); | 570 | qApp->processEvents(); |
557 | } | 571 | } |
558 | timer.start(); | 572 | timer.start(); |
559 | while ( timer.elapsed () < 2000 ) { | 573 | while ( timer.elapsed () < 2000 ) { |
560 | qApp->processEvents(); | 574 | qApp->processEvents(); |
561 | } | 575 | } |
562 | } else | 576 | } else |
563 | syncRemote( temp, false ); | 577 | syncRemote( temp, false ); |
564 | 578 | ||
565 | } | 579 | } |
566 | } | 580 | } |
567 | timer.start(); | 581 | timer.start(); |
568 | mParent->topLevelWidget()->setCaption(i18n("Multiple sync in progress ... please wait!") ); | 582 | mParent->topLevelWidget()->setCaption(i18n("Multiple sync in progress ... please wait!") ); |
569 | while ( timer.elapsed () < 2000 ) { | 583 | while ( timer.elapsed () < 2000 ) { |
570 | qApp->processEvents(); | 584 | qApp->processEvents(); |
571 | #ifndef _WIN32_ | 585 | #ifndef _WIN32_ |
572 | sleep (1); | 586 | sleep (1); |
573 | #endif | 587 | #endif |
574 | } | 588 | } |
575 | 589 | ||
576 | } | 590 | } |
577 | 591 | ||
578 | } | 592 | } |
579 | delete temp; | 593 | delete temp; |
580 | return syncedProfiles; | 594 | return syncedProfiles; |
581 | } | 595 | } |
582 | 596 | ||
583 | void KSyncManager::syncRemote( KSyncProfile* prof, bool ask) | 597 | void KSyncManager::syncRemote( KSyncProfile* prof, bool ask) |
584 | { | 598 | { |
585 | QString question; | 599 | QString question; |
586 | if ( ask ) { | 600 | if ( ask ) { |
587 | question = i18n("Do you really want\nto remote sync\nwith profile \n")+ prof->getName()+" ?\n"; | 601 | question = i18n("Do you really want\nto remote sync\nwith profile \n")+ prof->getName()+" ?\n"; |
588 | if ( QMessageBox::information( mParent, i18n("Sync"), | 602 | if ( QMessageBox::information( mParent, i18n("Sync"), |
589 | question, | 603 | question, |
590 | i18n("Yes"), i18n("No"), | 604 | i18n("Yes"), i18n("No"), |
591 | 0, 0 ) != 0 ) | 605 | 0, 0 ) != 0 ) |
592 | return; | 606 | return; |
593 | } | 607 | } |
594 | 608 | ||
595 | QString preCommand; | 609 | QString preCommand; |
596 | QString localTempFile; | 610 | QString localTempFile; |
597 | QString postCommand; | 611 | QString postCommand; |
598 | 612 | ||
599 | switch(mTargetApp) | 613 | switch(mTargetApp) |
600 | { | 614 | { |
601 | case (KAPI): | 615 | case (KAPI): |
602 | preCommand = prof->getPreSyncCommandAB(); | 616 | preCommand = prof->getPreSyncCommandAB(); |
603 | postCommand = prof->getPostSyncCommandAB(); | 617 | postCommand = prof->getPostSyncCommandAB(); |
604 | localTempFile = prof->getLocalTempFileAB(); | 618 | localTempFile = prof->getLocalTempFileAB(); |
605 | break; | 619 | break; |
606 | case (KOPI): | 620 | case (KOPI): |
607 | preCommand = prof->getPreSyncCommand(); | 621 | preCommand = prof->getPreSyncCommand(); |
608 | postCommand = prof->getPostSyncCommand(); | 622 | postCommand = prof->getPostSyncCommand(); |
609 | localTempFile = prof->getLocalTempFile(); | 623 | localTempFile = prof->getLocalTempFile(); |
610 | break; | 624 | break; |
611 | case (PWMPI): | 625 | case (PWMPI): |
612 | preCommand = prof->getPreSyncCommandPWM(); | 626 | preCommand = prof->getPreSyncCommandPWM(); |
613 | postCommand = prof->getPostSyncCommandPWM(); | 627 | postCommand = prof->getPostSyncCommandPWM(); |
614 | localTempFile = prof->getLocalTempFilePWM(); | 628 | localTempFile = prof->getLocalTempFilePWM(); |
615 | break; | 629 | break; |
616 | default: | 630 | default: |
617 | qDebug("KSyncManager::syncRemote: invalid apptype selected"); | 631 | qDebug("KSyncManager::syncRemote: invalid apptype selected"); |
618 | break; | 632 | break; |
619 | } | 633 | } |
620 | 634 | ||
621 | 635 | ||
622 | int fi; | 636 | int fi; |
623 | if ( (fi = preCommand.find("$PWD$")) > 0 ) { | 637 | if ( (fi = preCommand.find("$PWD$")) > 0 ) { |
624 | QString pwd = getPassword(); | 638 | QString pwd = getPassword(); |
625 | preCommand = preCommand.left( fi )+ pwd + preCommand.mid( fi+5 ); | 639 | preCommand = preCommand.left( fi )+ pwd + preCommand.mid( fi+5 ); |
626 | 640 | ||
627 | } | 641 | } |
628 | int maxlen = 30; | 642 | int maxlen = 30; |
629 | if ( QApplication::desktop()->width() > 320 ) | 643 | if ( QApplication::desktop()->width() > 320 ) |
630 | maxlen += 25; | 644 | maxlen += 25; |
631 | mParent->topLevelWidget()->setCaption ( i18n( "Copy remote file to local machine..." ) ); | 645 | mParent->topLevelWidget()->setCaption ( i18n( "Copy remote file to local machine..." ) ); |
632 | int fileSize = 0; | 646 | int fileSize = 0; |
633 | int result = system ( preCommand ); | 647 | int result = system ( preCommand ); |
634 | // 0 : okay | 648 | // 0 : okay |
635 | // 256: no such file or dir | 649 | // 256: no such file or dir |
636 | // | 650 | // |
637 | qDebug("Sync: Remote copy result(0 = okay): %d ",result ); | 651 | qDebug("Sync: Remote copy result(0 = okay): %d ",result ); |
638 | if ( result != 0 ) { | 652 | if ( result != 0 ) { |
639 | unsigned int len = maxlen; | 653 | unsigned int len = maxlen; |
640 | while ( len < preCommand.length() ) { | 654 | while ( len < preCommand.length() ) { |
641 | preCommand.insert( len , "\n" ); | 655 | preCommand.insert( len , "\n" ); |
642 | len += maxlen +2; | 656 | len += maxlen +2; |
643 | } | 657 | } |
644 | 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) ; | 658 | 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) ; |
645 | QMessageBox::information( mParent, i18n("Sync - ERROR"), | 659 | QMessageBox::information( mParent, i18n("Sync - ERROR"), |
646 | question, | 660 | question, |
647 | i18n("Okay!")) ; | 661 | i18n("Okay!")) ; |
648 | mParent->topLevelWidget()->setCaption ("KDE-Pim"); | 662 | mParent->topLevelWidget()->setCaption ("KDE-Pim"); |
649 | return; | 663 | return; |
650 | } | 664 | } |
651 | mParent->topLevelWidget()->setCaption ( i18n( "Copying succeed." ) ); | 665 | mParent->topLevelWidget()->setCaption ( i18n( "Copying succeed." ) ); |
652 | //qDebug(" file **%s** ",prof->getLocalTempFile().latin1() ); | 666 | //qDebug(" file **%s** ",prof->getLocalTempFile().latin1() ); |
653 | 667 | ||
654 | if ( syncWithFile( localTempFile, true ) ) { | 668 | if ( syncWithFile( localTempFile, true ) ) { |
655 | 669 | ||
656 | if ( mWriteBackFile ) { | 670 | if ( mWriteBackFile ) { |
657 | int fi; | 671 | int fi; |
658 | if ( (fi = postCommand.find("$PWD$")) > 0 ) { | 672 | if ( (fi = postCommand.find("$PWD$")) > 0 ) { |
659 | QString pwd = getPassword(); | 673 | QString pwd = getPassword(); |
660 | postCommand = postCommand.left( fi )+ pwd + postCommand.mid( fi+5 ); | 674 | postCommand = postCommand.left( fi )+ pwd + postCommand.mid( fi+5 ); |
661 | 675 | ||
662 | } | 676 | } |
663 | mParent->topLevelWidget()->setCaption ( i18n( "Writing back file ..." ) ); | 677 | mParent->topLevelWidget()->setCaption ( i18n( "Writing back file ..." ) ); |
664 | result = system ( postCommand ); | 678 | result = system ( postCommand ); |
665 | qDebug("Sync:Writing back file result: %d ", result); | 679 | qDebug("Sync:Writing back file result: %d ", result); |
666 | if ( result != 0 ) { | 680 | if ( result != 0 ) { |
667 | mParent->topLevelWidget()->setCaption ( i18n( "Writing back file result: " )+QString::number( result ) ); | 681 | mParent->topLevelWidget()->setCaption ( i18n( "Writing back file result: " )+QString::number( result ) ); |
668 | return; | 682 | return; |
669 | } else { | 683 | } else { |
670 | mParent->topLevelWidget()->setCaption ( i18n( "Syncronization sucessfully completed" ) ); | 684 | mParent->topLevelWidget()->setCaption ( i18n( "Syncronization sucessfully completed" ) ); |
671 | } | 685 | } |
672 | } | 686 | } |
673 | } | 687 | } |
674 | return; | 688 | return; |
675 | } | 689 | } |
676 | void KSyncManager::edit_pisync_options() | 690 | void KSyncManager::edit_pisync_options() |
677 | { | 691 | { |
678 | QDialog dia( mParent, "dia", true ); | 692 | QDialog dia( mParent, "dia", true ); |
679 | dia.setCaption( i18n("Pi-Sync options for device: " ) +mCurrentSyncDevice ); | 693 | dia.setCaption( i18n("Pi-Sync options for device: " ) +mCurrentSyncDevice ); |
680 | QVBoxLayout lay ( &dia ); | 694 | QVBoxLayout lay ( &dia ); |
681 | lay.setSpacing( 5 ); | 695 | lay.setSpacing( 5 ); |
682 | lay.setMargin( 3 ); | 696 | lay.setMargin( 3 ); |
683 | QLabel lab1 ( i18n("Password for remote access:"), &dia); | 697 | QLabel lab1 ( i18n("Password for remote access:"), &dia); |
684 | lay.addWidget( &lab1 ); | 698 | lay.addWidget( &lab1 ); |
685 | QLineEdit le1 (&dia ); | 699 | QLineEdit le1 (&dia ); |
686 | lay.addWidget( &le1 ); | 700 | lay.addWidget( &le1 ); |
687 | QLabel lab2 ( i18n("Remote IP address:"), &dia); | 701 | QLabel lab2 ( i18n("Remote IP address:"), &dia); |
688 | lay.addWidget( &lab2 ); | 702 | lay.addWidget( &lab2 ); |
689 | QLineEdit le2 (&dia ); | 703 | QLineEdit le2 (&dia ); |
690 | lay.addWidget( &le2 ); | 704 | lay.addWidget( &le2 ); |
691 | QLabel lab3 ( i18n("Remote port number:"), &dia); | 705 | QLabel lab3 ( i18n("Remote port number:"), &dia); |
692 | lay.addWidget( &lab3 ); | 706 | lay.addWidget( &lab3 ); |
693 | QLineEdit le3 (&dia ); | 707 | QLineEdit le3 (&dia ); |
694 | lay.addWidget( &le3 ); | 708 | lay.addWidget( &le3 ); |
695 | QPushButton pb ( "OK", &dia); | 709 | QPushButton pb ( "OK", &dia); |
696 | lay.addWidget( &pb ); | 710 | lay.addWidget( &pb ); |
697 | connect(&pb, SIGNAL( clicked() ), &dia, SLOT ( accept() ) ); | 711 | connect(&pb, SIGNAL( clicked() ), &dia, SLOT ( accept() ) ); |
698 | le1.setText( mPassWordPiSync ); | 712 | le1.setText( mPassWordPiSync ); |
699 | le2.setText( mActiveSyncIP ); | 713 | le2.setText( mActiveSyncIP ); |
700 | le3.setText( mActiveSyncPort ); | 714 | le3.setText( mActiveSyncPort ); |
701 | if ( dia.exec() ) { | 715 | if ( dia.exec() ) { |
702 | mPassWordPiSync = le1.text(); | 716 | mPassWordPiSync = le1.text(); |
703 | mActiveSyncPort = le3.text(); | 717 | mActiveSyncPort = le3.text(); |
704 | mActiveSyncIP = le2.text(); | 718 | mActiveSyncIP = le2.text(); |
705 | } | 719 | } |
706 | 720 | ||
707 | } | 721 | } |
708 | void KSyncManager::edit_sync_options() | 722 | void KSyncManager::edit_sync_options() |
709 | { | 723 | { |
710 | 724 | ||
711 | QDialog dia( mParent, "dia", true ); | 725 | QDialog dia( mParent, "dia", true ); |
712 | dia.setCaption( i18n("Device: " ) +mCurrentSyncDevice ); | 726 | dia.setCaption( i18n("Device: " ) +mCurrentSyncDevice ); |
713 | QButtonGroup gr ( 1, Qt::Horizontal, i18n("Sync preferences"), &dia); | 727 | QButtonGroup gr ( 1, Qt::Horizontal, i18n("Sync preferences"), &dia); |
714 | QVBoxLayout lay ( &dia ); | 728 | QVBoxLayout lay ( &dia ); |
715 | lay.setSpacing( 2 ); | 729 | lay.setSpacing( 2 ); |
716 | lay.setMargin( 3 ); | 730 | lay.setMargin( 3 ); |
717 | lay.addWidget(&gr); | 731 | lay.addWidget(&gr); |
718 | QRadioButton loc ( i18n("Take local entry on conflict"), &gr ); | 732 | QRadioButton loc ( i18n("Take local entry on conflict"), &gr ); |
719 | QRadioButton rem ( i18n("Take remote entry on conflict"), &gr ); | 733 | QRadioButton rem ( i18n("Take remote entry on conflict"), &gr ); |
720 | QRadioButton newest( i18n("Take newest entry on conflict"), &gr ); | 734 | QRadioButton newest( i18n("Take newest entry on conflict"), &gr ); |
721 | QRadioButton ask( i18n("Ask for every entry on conflict"), &gr ); | 735 | QRadioButton ask( i18n("Ask for every entry on conflict"), &gr ); |
722 | QRadioButton f_loc( i18n("Force: Take local entry always"), &gr ); | 736 | QRadioButton f_loc( i18n("Force: Take local entry always"), &gr ); |
723 | QRadioButton f_rem( i18n("Force: Take remote entry always"), &gr ); | 737 | QRadioButton f_rem( i18n("Force: Take remote entry always"), &gr ); |
724 | //QRadioButton both( i18n("Take both on conflict"), &gr ); | 738 | //QRadioButton both( i18n("Take both on conflict"), &gr ); |
725 | QPushButton pb ( "OK", &dia); | 739 | QPushButton pb ( "OK", &dia); |
726 | lay.addWidget( &pb ); | 740 | lay.addWidget( &pb ); |
727 | connect(&pb, SIGNAL( clicked() ), &dia, SLOT ( accept() ) ); | 741 | connect(&pb, SIGNAL( clicked() ), &dia, SLOT ( accept() ) ); |
728 | switch ( mSyncAlgoPrefs ) { | 742 | switch ( mSyncAlgoPrefs ) { |