-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 | |||
@@ -1,827 +1,856 @@ | |||
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 | 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] ); |
119 | temp->writeConfig(&config); | 122 | temp->writeConfig(&config); |
120 | config.setGroup("General"); | 123 | config.setGroup("General"); |
121 | config.writeEntry("SyncProfileNames",prof); | 124 | config.writeEntry("SyncProfileNames",prof); |
122 | config.writeEntry("ExternSyncProfiles","Sharp_DTM"); | 125 | config.writeEntry("ExternSyncProfiles","Sharp_DTM"); |
123 | config.sync(); | 126 | config.sync(); |
124 | delete temp; | 127 | delete temp; |
125 | } | 128 | } |
126 | mExternSyncProfiles = config.readListEntry("ExternSyncProfiles"); | 129 | mExternSyncProfiles = config.readListEntry("ExternSyncProfiles"); |
127 | mSyncProfileNames = prof; | 130 | mSyncProfileNames = prof; |
128 | unsigned int i; | 131 | unsigned int i; |
129 | for ( i = 0; i < prof.count(); ++i ) { | 132 | for ( i = 0; i < prof.count(); ++i ) { |
130 | mSyncMenu->insertItem( prof[i], 1000+i ); | 133 | mSyncMenu->insertItem( prof[i], 1000+i ); |
131 | if ( i == 2 ) | 134 | if ( i == 2 ) |
132 | mSyncMenu->insertSeparator(); | 135 | mSyncMenu->insertSeparator(); |
133 | } | 136 | } |
134 | QDir app_dir; | 137 | QDir app_dir; |
135 | //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 |
136 | if ( mTargetApp == PWMPI) { | 139 | if ( mTargetApp == PWMPI) { |
137 | mSyncMenu->removeItem( 1000 ); | 140 | mSyncMenu->removeItem( 1000 ); |
138 | } | 141 | } |
139 | #ifndef DESKTOP_VERSION | 142 | #ifndef DESKTOP_VERSION |
140 | else if (!app_dir.exists(QDir::homeDirPath()+"/Applications/dtm" ) ) { | 143 | else if (!app_dir.exists(QDir::homeDirPath()+"/Applications/dtm" ) ) { |
141 | mSyncMenu->removeItem( 1000 ); | 144 | mSyncMenu->removeItem( 1000 ); |
142 | } | 145 | } |
143 | #endif | 146 | #endif |
144 | mSyncMenu->removeItem( 1002 ); | 147 | mSyncMenu->removeItem( 1002 ); |
145 | } | 148 | } |
146 | 149 | ||
147 | void KSyncManager::slotSyncMenu( int action ) | 150 | void KSyncManager::slotSyncMenu( int action ) |
148 | { | 151 | { |
149 | qDebug("syncaction %d ", action); | 152 | qDebug("syncaction %d ", action); |
150 | if ( action == 0 ) { | 153 | if ( action == 0 ) { |
151 | 154 | ||
152 | // seems to be a Qt2 event handling bug | 155 | // seems to be a Qt2 event handling bug |
153 | // syncmenu.clear causes a segfault at first time | 156 | // syncmenu.clear causes a segfault at first time |
154 | // 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 |
155 | // 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 |
156 | QTimer::singleShot ( 1, this, SLOT ( confSync() ) ); | 159 | QTimer::singleShot ( 1, this, SLOT ( confSync() ) ); |
157 | //confSync(); | 160 | //confSync(); |
158 | 161 | ||
159 | return; | 162 | return; |
160 | } | 163 | } |
161 | if ( action == 1 ) { | 164 | if ( action == 1 ) { |
162 | multiSync( true ); | 165 | multiSync( true ); |
163 | return; | 166 | return; |
164 | } | 167 | } |
165 | if ( action == 2 ) { | 168 | if ( action == 2 ) { |
166 | enableQuick(); | 169 | enableQuick(); |
167 | QTimer::singleShot ( 1, this, SLOT ( fillSyncMenu() ) ); | 170 | QTimer::singleShot ( 1, this, SLOT ( fillSyncMenu() ) ); |
168 | return; | 171 | return; |
169 | } | 172 | } |
170 | if ( action == 3 ) { | 173 | if ( action == 3 ) { |
171 | delete mServerSocket; | 174 | delete mServerSocket; |
172 | mServerSocket = 0; | 175 | mServerSocket = 0; |
173 | QTimer::singleShot ( 1, this, SLOT ( fillSyncMenu() ) ); | 176 | QTimer::singleShot ( 1, this, SLOT ( fillSyncMenu() ) ); |
174 | return; | 177 | return; |
175 | } | 178 | } |
176 | 179 | ||
177 | if (blockSave()) | 180 | if (blockSave()) |
178 | return; | 181 | return; |
179 | 182 | ||
180 | setBlockSave(true); | 183 | setBlockSave(true); |
181 | 184 | ||
182 | mCurrentSyncProfile = action - 1000 ; | 185 | mCurrentSyncProfile = action - 1000 ; |
183 | mCurrentSyncDevice = mSyncProfileNames[mCurrentSyncProfile] ; | 186 | mCurrentSyncDevice = mSyncProfileNames[mCurrentSyncProfile] ; |
184 | mCurrentSyncName = mLocalMachineName ; | 187 | mCurrentSyncName = mLocalMachineName ; |
185 | KConfig config ( locateLocal( "config","ksyncprofilesrc" ) ); | 188 | KConfig config ( locateLocal( "config","ksyncprofilesrc" ) ); |
186 | KSyncProfile* temp = new KSyncProfile (); | 189 | KSyncProfile* temp = new KSyncProfile (); |
187 | temp->setName(mSyncProfileNames[mCurrentSyncProfile]); | 190 | temp->setName(mSyncProfileNames[mCurrentSyncProfile]); |
188 | temp->readConfig(&config); | 191 | temp->readConfig(&config); |
189 | mAskForPreferences = temp->getAskForPreferences(); | 192 | mAskForPreferences = temp->getAskForPreferences(); |
190 | mSyncAlgoPrefs = temp->getSyncPrefs(); | 193 | mSyncAlgoPrefs = temp->getSyncPrefs(); |
191 | mWriteBackFile = temp->getWriteBackFile(); | 194 | mWriteBackFile = temp->getWriteBackFile(); |
192 | mWriteBackExistingOnly = temp->getWriteBackExisting(); | 195 | mWriteBackExistingOnly = temp->getWriteBackExisting(); |
193 | mIsKapiFile = temp->getIsKapiFile(); | 196 | mIsKapiFile = temp->getIsKapiFile(); |
194 | mWriteBackInFuture = 0; | 197 | mWriteBackInFuture = 0; |
195 | if ( temp->getWriteBackFuture() ) | 198 | if ( temp->getWriteBackFuture() ) |
196 | mWriteBackInFuture = temp->getWriteBackFutureWeeks( ); | 199 | mWriteBackInFuture = temp->getWriteBackFutureWeeks( ); |
197 | mShowSyncSummary = temp->getShowSummaryAfterSync(); | 200 | mShowSyncSummary = temp->getShowSummaryAfterSync(); |
198 | if ( action == 1000 ) { | 201 | if ( action == 1000 ) { |
199 | #ifdef DESKTOP_VERSION | 202 | #ifdef DESKTOP_VERSION |
200 | syncKDE(); | 203 | syncKDE(); |
201 | #else | 204 | #else |
202 | syncSharp(); | 205 | syncSharp(); |
203 | #endif | 206 | #endif |
204 | 207 | ||
205 | } else if ( action == 1001 ) { | 208 | } else if ( action == 1001 ) { |
206 | syncLocalFile(); | 209 | syncLocalFile(); |
207 | 210 | ||
208 | } else if ( action == 1002 ) { | 211 | } else if ( action == 1002 ) { |
209 | mWriteBackFile = false; | 212 | mWriteBackFile = false; |
210 | mAskForPreferences = false; | 213 | mAskForPreferences = false; |
211 | mShowSyncSummary = false; | 214 | mShowSyncSummary = false; |
212 | mSyncAlgoPrefs = 3; | 215 | mSyncAlgoPrefs = 3; |
213 | quickSyncLocalFile(); | 216 | quickSyncLocalFile(); |
214 | 217 | ||
215 | } else if ( action >= 1003 ) { | 218 | } else if ( action >= 1003 ) { |
216 | if ( temp->getIsLocalFileSync() ) { | 219 | if ( temp->getIsLocalFileSync() ) { |
217 | switch(mTargetApp) | 220 | switch(mTargetApp) |
218 | { | 221 | { |
219 | case (KAPI): | 222 | case (KAPI): |
220 | if ( syncWithFile( temp->getRemoteFileNameAB( ), false ) ) | 223 | if ( syncWithFile( temp->getRemoteFileNameAB( ), false ) ) |
221 | mPrefs->mLastSyncedLocalFile = temp->getRemoteFileNameAB(); | 224 | mPrefs->mLastSyncedLocalFile = temp->getRemoteFileNameAB(); |
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; |
364 | } | 393 | } |
365 | int result = 0; | 394 | int result = 0; |
366 | if ( !quick ) { | 395 | if ( !quick ) { |
367 | mess = i18n("Sync with file \n...%1\nfrom:\n%2\n").arg(fn.right( 25)).arg(KGlobal::locale()->formatDateTime(info.lastModified (), true, false )); | 396 | mess = i18n("Sync with file \n...%1\nfrom:\n%2\n").arg(fn.right( 25)).arg(KGlobal::locale()->formatDateTime(info.lastModified (), true, false )); |
368 | result = QMessageBox::warning( mParent, i18n("Warning!"), | 397 | result = QMessageBox::warning( mParent, i18n("Warning!"), |
369 | mess, | 398 | mess, |
370 | i18n("Sync"), i18n("Cancel"), 0, | 399 | i18n("Sync"), i18n("Cancel"), 0, |
371 | 0, 1 ); | 400 | 0, 1 ); |
372 | if ( result ) | 401 | if ( result ) |
373 | return false; | 402 | return false; |
374 | } | 403 | } |
375 | if ( mAskForPreferences ) | 404 | if ( mAskForPreferences ) |
376 | edit_sync_options(); | 405 | edit_sync_options(); |
377 | if ( result == 0 ) { | 406 | if ( result == 0 ) { |
378 | //qDebug("Now sycing ... "); | 407 | //qDebug("Now sycing ... "); |
379 | if ( ret = mImplementation->sync( this, fn, mSyncAlgoPrefs ) ) | 408 | if ( ret = mImplementation->sync( this, fn, mSyncAlgoPrefs ) ) |
380 | mParent->topLevelWidget()->setCaption( i18n("Synchronization successful") ); | 409 | mParent->topLevelWidget()->setCaption( i18n("Synchronization successful") ); |
381 | else | 410 | else |
382 | mParent->topLevelWidget()->setCaption( i18n("Sync cancelled or failed. Nothing synced.") ); | 411 | mParent->topLevelWidget()->setCaption( i18n("Sync cancelled or failed. Nothing synced.") ); |
383 | if ( ! quick ) | 412 | if ( ! quick ) |
384 | mPrefs->mLastSyncedLocalFile = fn; | 413 | mPrefs->mLastSyncedLocalFile = fn; |
385 | } | 414 | } |
386 | return ret; | 415 | return ret; |
387 | } | 416 | } |
388 | 417 | ||
389 | void KSyncManager::quickSyncLocalFile() | 418 | void KSyncManager::quickSyncLocalFile() |
390 | { | 419 | { |
391 | 420 | ||
392 | if ( syncWithFile( mPrefs->mLastSyncedLocalFile, true ) ) { | 421 | if ( syncWithFile( mPrefs->mLastSyncedLocalFile, true ) ) { |
393 | qDebug("quick syncLocalFile() successful "); | 422 | qDebug("quick syncLocalFile() successful "); |
394 | 423 | ||
395 | } | 424 | } |
396 | } | 425 | } |
397 | 426 | ||
398 | void KSyncManager::multiSync( bool askforPrefs ) | 427 | void KSyncManager::multiSync( bool askforPrefs ) |
399 | { | 428 | { |
400 | if (blockSave()) | 429 | if (blockSave()) |
401 | return; | 430 | return; |
402 | setBlockSave(true); | 431 | setBlockSave(true); |
403 | QString question = i18n("Do you really want\nto multiple sync\nwith all checked profiles?\nSyncing takes some\ntime - all profiles\nare synced twice!"); | 432 | QString question = i18n("Do you really want\nto multiple sync\nwith all checked profiles?\nSyncing takes some\ntime - all profiles\nare synced twice!"); |
404 | if ( QMessageBox::information( mParent, i18n("KDE-Pim Sync"), | 433 | if ( QMessageBox::information( mParent, i18n("KDE-Pim Sync"), |
405 | question, | 434 | question, |
406 | i18n("Yes"), i18n("No"), | 435 | i18n("Yes"), i18n("No"), |
407 | 0, 0 ) != 0 ) { | 436 | 0, 0 ) != 0 ) { |
408 | setBlockSave(false); | 437 | setBlockSave(false); |
409 | mParent->topLevelWidget()->setCaption(i18n("Aborted! Nothing synced!")); | 438 | mParent->topLevelWidget()->setCaption(i18n("Aborted! Nothing synced!")); |
410 | return; | 439 | return; |
411 | } | 440 | } |
412 | mCurrentSyncDevice = i18n("Multiple profiles") ; | 441 | mCurrentSyncDevice = i18n("Multiple profiles") ; |
413 | mSyncAlgoPrefs = mPrefs->mRingSyncAlgoPrefs; | 442 | mSyncAlgoPrefs = mPrefs->mRingSyncAlgoPrefs; |
414 | if ( askforPrefs ) { | 443 | if ( askforPrefs ) { |
415 | edit_sync_options(); | 444 | edit_sync_options(); |
416 | mPrefs->mRingSyncAlgoPrefs = mSyncAlgoPrefs; | 445 | mPrefs->mRingSyncAlgoPrefs = mSyncAlgoPrefs; |
417 | } | 446 | } |
418 | mParent->topLevelWidget()->setCaption(i18n("Multiple sync started.") ); | 447 | mParent->topLevelWidget()->setCaption(i18n("Multiple sync started.") ); |
419 | qApp->processEvents(); | 448 | qApp->processEvents(); |
420 | int num = ringSync() ; | 449 | int num = ringSync() ; |
421 | if ( num > 1 ) | 450 | if ( num > 1 ) |
422 | ringSync(); | 451 | ringSync(); |
423 | setBlockSave(false); | 452 | setBlockSave(false); |
424 | if ( num ) | 453 | if ( num ) |
425 | emit save(); | 454 | emit save(); |
426 | if ( num ) | 455 | if ( num ) |
427 | mParent->topLevelWidget()->setCaption(i18n("%1 profiles synced. Multiple sync complete!").arg(num) ); | 456 | mParent->topLevelWidget()->setCaption(i18n("%1 profiles synced. Multiple sync complete!").arg(num) ); |
428 | else | 457 | else |
429 | mParent->topLevelWidget()->setCaption(i18n("Nothing synced! No profiles defined for multisync!")); | 458 | mParent->topLevelWidget()->setCaption(i18n("Nothing synced! No profiles defined for multisync!")); |
430 | return; | 459 | return; |
431 | } | 460 | } |
432 | 461 | ||
433 | int KSyncManager::ringSync() | 462 | int KSyncManager::ringSync() |
434 | { | 463 | { |
435 | int syncedProfiles = 0; | 464 | int syncedProfiles = 0; |
436 | unsigned int i; | 465 | unsigned int i; |
437 | QTime timer; | 466 | QTime timer; |
438 | KConfig config ( locateLocal( "config","ksyncprofilesrc" ) ); | 467 | KConfig config ( locateLocal( "config","ksyncprofilesrc" ) ); |
439 | QStringList syncProfileNames = mSyncProfileNames; | 468 | QStringList syncProfileNames = mSyncProfileNames; |
440 | KSyncProfile* temp = new KSyncProfile (); | 469 | KSyncProfile* temp = new KSyncProfile (); |
441 | mAskForPreferences = false; | 470 | mAskForPreferences = false; |
442 | for ( i = 0; i < syncProfileNames.count(); ++i ) { | 471 | for ( i = 0; i < syncProfileNames.count(); ++i ) { |
443 | mCurrentSyncProfile = i; | 472 | mCurrentSyncProfile = i; |
444 | temp->setName(syncProfileNames[mCurrentSyncProfile]); | 473 | temp->setName(syncProfileNames[mCurrentSyncProfile]); |
445 | temp->readConfig(&config); | 474 | temp->readConfig(&config); |
446 | 475 | ||
447 | bool includeInRingSync; | 476 | bool includeInRingSync; |
448 | switch(mTargetApp) | 477 | switch(mTargetApp) |
449 | { | 478 | { |
450 | case (KAPI): | 479 | case (KAPI): |
451 | includeInRingSync = temp->getIncludeInRingSyncAB(); | 480 | includeInRingSync = temp->getIncludeInRingSyncAB(); |
452 | break; | 481 | break; |
453 | case (KOPI): | 482 | case (KOPI): |
454 | includeInRingSync = temp->getIncludeInRingSync(); | 483 | includeInRingSync = temp->getIncludeInRingSync(); |
455 | break; | 484 | break; |
456 | case (PWMPI): | 485 | case (PWMPI): |
457 | includeInRingSync = temp->getIncludeInRingSyncPWM(); | 486 | includeInRingSync = temp->getIncludeInRingSyncPWM(); |
458 | break; | 487 | break; |
459 | default: | 488 | default: |
460 | qDebug("KSyncManager::ringSync: invalid apptype selected"); | 489 | qDebug("KSyncManager::ringSync: invalid apptype selected"); |
461 | break; | 490 | break; |
462 | 491 | ||
463 | } | 492 | } |
464 | 493 | ||
465 | 494 | ||
466 | if ( includeInRingSync && ( i < 1 || i > 2 )) { | 495 | if ( includeInRingSync && ( i < 1 || i > 2 )) { |
467 | mParent->topLevelWidget()->setCaption(i18n("Profile ")+syncProfileNames[mCurrentSyncProfile]+ i18n(" is synced ... ")); | 496 | mParent->topLevelWidget()->setCaption(i18n("Profile ")+syncProfileNames[mCurrentSyncProfile]+ i18n(" is synced ... ")); |
468 | ++syncedProfiles; | 497 | ++syncedProfiles; |
469 | // mAskForPreferences = temp->getAskForPreferences(); | 498 | // mAskForPreferences = temp->getAskForPreferences(); |
470 | mWriteBackFile = temp->getWriteBackFile(); | 499 | mWriteBackFile = temp->getWriteBackFile(); |
471 | mWriteBackExistingOnly = temp->getWriteBackExisting(); | 500 | mWriteBackExistingOnly = temp->getWriteBackExisting(); |
472 | mWriteBackInFuture = 0; | 501 | mWriteBackInFuture = 0; |
473 | if ( temp->getWriteBackFuture() ) | 502 | if ( temp->getWriteBackFuture() ) |
474 | mWriteBackInFuture = temp->getWriteBackFutureWeeks( ); | 503 | mWriteBackInFuture = temp->getWriteBackFutureWeeks( ); |
475 | mShowSyncSummary = false; | 504 | mShowSyncSummary = false; |
476 | mCurrentSyncDevice = syncProfileNames[i] ; | 505 | mCurrentSyncDevice = syncProfileNames[i] ; |
477 | mCurrentSyncName = mLocalMachineName; | 506 | mCurrentSyncName = mLocalMachineName; |
478 | if ( i == 0 ) { | 507 | if ( i == 0 ) { |
479 | #ifdef DESKTOP_VERSION | 508 | #ifdef DESKTOP_VERSION |
480 | syncKDE(); | 509 | syncKDE(); |
481 | #else | 510 | #else |
482 | syncSharp(); | 511 | syncSharp(); |
483 | #endif | 512 | #endif |
484 | } else { | 513 | } else { |
485 | if ( temp->getIsLocalFileSync() ) { | 514 | if ( temp->getIsLocalFileSync() ) { |
486 | switch(mTargetApp) | 515 | switch(mTargetApp) |
487 | { | 516 | { |
488 | case (KAPI): | 517 | case (KAPI): |
489 | if ( syncWithFile( temp->getRemoteFileNameAB( ), false ) ) | 518 | if ( syncWithFile( temp->getRemoteFileNameAB( ), false ) ) |
490 | mPrefs->mLastSyncedLocalFile = temp->getRemoteFileNameAB(); | 519 | mPrefs->mLastSyncedLocalFile = temp->getRemoteFileNameAB(); |
491 | break; | 520 | break; |
492 | case (KOPI): | 521 | case (KOPI): |
493 | if ( syncWithFile( temp->getRemoteFileName( ), false ) ) | 522 | if ( syncWithFile( temp->getRemoteFileName( ), false ) ) |
494 | mPrefs->mLastSyncedLocalFile = temp->getRemoteFileName(); | 523 | mPrefs->mLastSyncedLocalFile = temp->getRemoteFileName(); |
495 | break; | 524 | break; |
496 | case (PWMPI): | 525 | case (PWMPI): |
497 | if ( syncWithFile( temp->getRemoteFileNamePWM( ), false ) ) | 526 | if ( syncWithFile( temp->getRemoteFileNamePWM( ), false ) ) |
498 | mPrefs->mLastSyncedLocalFile = temp->getRemoteFileNamePWM(); | 527 | mPrefs->mLastSyncedLocalFile = temp->getRemoteFileNamePWM(); |
499 | break; | 528 | break; |
500 | default: | 529 | default: |
501 | qDebug("KSyncManager::slotSyncMenu: invalid apptype selected"); | 530 | qDebug("KSyncManager::slotSyncMenu: invalid apptype selected"); |
502 | break; | 531 | break; |
503 | } | 532 | } |
504 | } else { | 533 | } else { |
505 | if ( temp->getIsPhoneSync() ) { | 534 | if ( temp->getIsPhoneSync() ) { |
506 | mPhoneDevice = temp->getPhoneDevice( ) ; | 535 | mPhoneDevice = temp->getPhoneDevice( ) ; |
507 | mPhoneConnection = temp->getPhoneConnection( ); | 536 | mPhoneConnection = temp->getPhoneConnection( ); |
508 | mPhoneModel = temp->getPhoneModel( ); | 537 | mPhoneModel = temp->getPhoneModel( ); |
509 | syncPhone(); | 538 | syncPhone(); |
510 | } else if ( temp->getIsPiSync() ) { | 539 | } else if ( temp->getIsPiSync() ) { |
511 | if ( mTargetApp == KAPI ) { | 540 | if ( mTargetApp == KAPI ) { |
512 | mPassWordPiSync = temp->getRemotePwAB(); | 541 | mPassWordPiSync = temp->getRemotePwAB(); |
513 | mActiveSyncPort = temp->getRemotePortAB(); | 542 | mActiveSyncPort = temp->getRemotePortAB(); |
514 | mActiveSyncIP = temp->getRemoteIPAB(); | 543 | mActiveSyncIP = temp->getRemoteIPAB(); |
515 | } else if ( mTargetApp == KOPI ) { | 544 | } else if ( mTargetApp == KOPI ) { |
516 | mPassWordPiSync = temp->getRemotePw(); | 545 | mPassWordPiSync = temp->getRemotePw(); |
517 | mActiveSyncPort = temp->getRemotePort(); | 546 | mActiveSyncPort = temp->getRemotePort(); |
518 | mActiveSyncIP = temp->getRemoteIP(); | 547 | mActiveSyncIP = temp->getRemoteIP(); |
519 | } else { | 548 | } else { |
520 | mPassWordPiSync = temp->getRemotePwPWM(); | 549 | mPassWordPiSync = temp->getRemotePwPWM(); |
521 | mActiveSyncPort = temp->getRemotePortPWM(); | 550 | mActiveSyncPort = temp->getRemotePortPWM(); |
522 | mActiveSyncIP = temp->getRemoteIPPWM(); | 551 | mActiveSyncIP = temp->getRemoteIPPWM(); |
523 | } | 552 | } |
524 | syncPi(); | 553 | syncPi(); |
525 | while ( !mPisyncFinished ) { | 554 | while ( !mPisyncFinished ) { |
526 | //qDebug("waiting "); | 555 | //qDebug("waiting "); |
527 | qApp->processEvents(); | 556 | qApp->processEvents(); |
528 | } | 557 | } |
529 | timer.start(); | 558 | timer.start(); |
530 | while ( timer.elapsed () < 2000 ) { | 559 | while ( timer.elapsed () < 2000 ) { |
531 | qApp->processEvents(); | 560 | qApp->processEvents(); |
532 | } | 561 | } |
533 | } else | 562 | } else |
534 | syncRemote( temp, false ); | 563 | syncRemote( temp, false ); |
535 | 564 | ||
536 | } | 565 | } |
537 | } | 566 | } |
538 | timer.start(); | 567 | timer.start(); |
539 | mParent->topLevelWidget()->setCaption(i18n("Multiple sync in progress ... please wait!") ); | 568 | mParent->topLevelWidget()->setCaption(i18n("Multiple sync in progress ... please wait!") ); |
540 | while ( timer.elapsed () < 2000 ) { | 569 | while ( timer.elapsed () < 2000 ) { |
541 | qApp->processEvents(); | 570 | qApp->processEvents(); |
542 | #ifndef _WIN32_ | 571 | #ifndef _WIN32_ |
543 | sleep (1); | 572 | sleep (1); |
544 | #endif | 573 | #endif |
545 | } | 574 | } |
546 | 575 | ||
547 | } | 576 | } |
548 | 577 | ||
549 | } | 578 | } |
550 | delete temp; | 579 | delete temp; |
551 | return syncedProfiles; | 580 | return syncedProfiles; |
552 | } | 581 | } |
553 | 582 | ||
554 | void KSyncManager::syncRemote( KSyncProfile* prof, bool ask) | 583 | void KSyncManager::syncRemote( KSyncProfile* prof, bool ask) |
555 | { | 584 | { |
556 | QString question; | 585 | QString question; |
557 | if ( ask ) { | 586 | if ( ask ) { |
558 | question = i18n("Do you really want\nto remote sync\nwith profile \n")+ prof->getName()+" ?\n"; | 587 | question = i18n("Do you really want\nto remote sync\nwith profile \n")+ prof->getName()+" ?\n"; |
559 | if ( QMessageBox::information( mParent, i18n("Sync"), | 588 | if ( QMessageBox::information( mParent, i18n("Sync"), |
560 | question, | 589 | question, |
561 | i18n("Yes"), i18n("No"), | 590 | i18n("Yes"), i18n("No"), |
562 | 0, 0 ) != 0 ) | 591 | 0, 0 ) != 0 ) |
563 | return; | 592 | return; |
564 | } | 593 | } |
565 | 594 | ||
566 | QString preCommand; | 595 | QString preCommand; |
567 | QString localTempFile; | 596 | QString localTempFile; |
568 | QString postCommand; | 597 | QString postCommand; |
569 | 598 | ||
570 | switch(mTargetApp) | 599 | switch(mTargetApp) |
571 | { | 600 | { |
572 | case (KAPI): | 601 | case (KAPI): |
573 | preCommand = prof->getPreSyncCommandAB(); | 602 | preCommand = prof->getPreSyncCommandAB(); |
574 | postCommand = prof->getPostSyncCommandAB(); | 603 | postCommand = prof->getPostSyncCommandAB(); |
575 | localTempFile = prof->getLocalTempFileAB(); | 604 | localTempFile = prof->getLocalTempFileAB(); |
576 | break; | 605 | break; |
577 | case (KOPI): | 606 | case (KOPI): |
578 | preCommand = prof->getPreSyncCommand(); | 607 | preCommand = prof->getPreSyncCommand(); |
579 | postCommand = prof->getPostSyncCommand(); | 608 | postCommand = prof->getPostSyncCommand(); |
580 | localTempFile = prof->getLocalTempFile(); | 609 | localTempFile = prof->getLocalTempFile(); |
581 | break; | 610 | break; |
582 | case (PWMPI): | 611 | case (PWMPI): |
583 | preCommand = prof->getPreSyncCommandPWM(); | 612 | preCommand = prof->getPreSyncCommandPWM(); |
584 | postCommand = prof->getPostSyncCommandPWM(); | 613 | postCommand = prof->getPostSyncCommandPWM(); |
585 | localTempFile = prof->getLocalTempFilePWM(); | 614 | localTempFile = prof->getLocalTempFilePWM(); |
586 | break; | 615 | break; |
587 | default: | 616 | default: |
588 | qDebug("KSyncManager::syncRemote: invalid apptype selected"); | 617 | qDebug("KSyncManager::syncRemote: invalid apptype selected"); |
589 | break; | 618 | break; |
590 | } | 619 | } |
591 | 620 | ||
592 | 621 | ||
593 | int fi; | 622 | int fi; |
594 | if ( (fi = preCommand.find("$PWD$")) > 0 ) { | 623 | if ( (fi = preCommand.find("$PWD$")) > 0 ) { |
595 | QString pwd = getPassword(); | 624 | QString pwd = getPassword(); |
596 | preCommand = preCommand.left( fi )+ pwd + preCommand.mid( fi+5 ); | 625 | preCommand = preCommand.left( fi )+ pwd + preCommand.mid( fi+5 ); |
597 | 626 | ||
598 | } | 627 | } |
599 | int maxlen = 30; | 628 | int maxlen = 30; |
600 | if ( QApplication::desktop()->width() > 320 ) | 629 | if ( QApplication::desktop()->width() > 320 ) |
601 | maxlen += 25; | 630 | maxlen += 25; |
602 | mParent->topLevelWidget()->setCaption ( i18n( "Copy remote file to local machine..." ) ); | 631 | mParent->topLevelWidget()->setCaption ( i18n( "Copy remote file to local machine..." ) ); |
603 | int fileSize = 0; | 632 | int fileSize = 0; |
604 | int result = system ( preCommand ); | 633 | int result = system ( preCommand ); |
605 | // 0 : okay | 634 | // 0 : okay |
606 | // 256: no such file or dir | 635 | // 256: no such file or dir |
607 | // | 636 | // |
608 | qDebug("Sync: Remote copy result(0 = okay): %d ",result ); | 637 | qDebug("Sync: Remote copy result(0 = okay): %d ",result ); |
609 | if ( result != 0 ) { | 638 | if ( result != 0 ) { |
610 | unsigned int len = maxlen; | 639 | unsigned int len = maxlen; |
611 | while ( len < preCommand.length() ) { | 640 | while ( len < preCommand.length() ) { |
612 | preCommand.insert( len , "\n" ); | 641 | preCommand.insert( len , "\n" ); |
613 | len += maxlen +2; | 642 | len += maxlen +2; |
614 | } | 643 | } |
615 | 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) ; | 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) ; |
616 | QMessageBox::information( mParent, i18n("Sync - ERROR"), | 645 | QMessageBox::information( mParent, i18n("Sync - ERROR"), |
617 | question, | 646 | question, |
618 | i18n("Okay!")) ; | 647 | i18n("Okay!")) ; |
619 | mParent->topLevelWidget()->setCaption ("KDE-Pim"); | 648 | mParent->topLevelWidget()->setCaption ("KDE-Pim"); |
620 | return; | 649 | return; |
621 | } | 650 | } |
622 | mParent->topLevelWidget()->setCaption ( i18n( "Copying succeed." ) ); | 651 | mParent->topLevelWidget()->setCaption ( i18n( "Copying succeed." ) ); |
623 | //qDebug(" file **%s** ",prof->getLocalTempFile().latin1() ); | 652 | //qDebug(" file **%s** ",prof->getLocalTempFile().latin1() ); |
624 | 653 | ||
625 | if ( syncWithFile( localTempFile, true ) ) { | 654 | if ( syncWithFile( localTempFile, true ) ) { |
626 | 655 | ||
627 | if ( mWriteBackFile ) { | 656 | if ( mWriteBackFile ) { |
628 | int fi; | 657 | int fi; |
629 | if ( (fi = postCommand.find("$PWD$")) > 0 ) { | 658 | if ( (fi = postCommand.find("$PWD$")) > 0 ) { |
630 | QString pwd = getPassword(); | 659 | QString pwd = getPassword(); |
631 | postCommand = postCommand.left( fi )+ pwd + postCommand.mid( fi+5 ); | 660 | postCommand = postCommand.left( fi )+ pwd + postCommand.mid( fi+5 ); |
632 | 661 | ||
633 | } | 662 | } |
634 | mParent->topLevelWidget()->setCaption ( i18n( "Writing back file ..." ) ); | 663 | mParent->topLevelWidget()->setCaption ( i18n( "Writing back file ..." ) ); |
635 | result = system ( postCommand ); | 664 | result = system ( postCommand ); |
636 | qDebug("Sync:Writing back file result: %d ", result); | 665 | qDebug("Sync:Writing back file result: %d ", result); |
637 | if ( result != 0 ) { | 666 | if ( result != 0 ) { |
638 | mParent->topLevelWidget()->setCaption ( i18n( "Writing back file result: " )+QString::number( result ) ); | 667 | mParent->topLevelWidget()->setCaption ( i18n( "Writing back file result: " )+QString::number( result ) ); |
639 | return; | 668 | return; |
640 | } else { | 669 | } else { |
641 | mParent->topLevelWidget()->setCaption ( i18n( "Syncronization sucessfully completed" ) ); | 670 | mParent->topLevelWidget()->setCaption ( i18n( "Syncronization sucessfully completed" ) ); |
642 | } | 671 | } |
643 | } | 672 | } |
644 | } | 673 | } |
645 | return; | 674 | return; |
646 | } | 675 | } |
647 | void KSyncManager::edit_pisync_options() | 676 | void KSyncManager::edit_pisync_options() |
648 | { | 677 | { |
649 | QDialog dia( mParent, "dia", true ); | 678 | QDialog dia( mParent, "dia", true ); |
650 | dia.setCaption( i18n("Pi-Sync options for device: " ) +mCurrentSyncDevice ); | 679 | dia.setCaption( i18n("Pi-Sync options for device: " ) +mCurrentSyncDevice ); |
651 | QVBoxLayout lay ( &dia ); | 680 | QVBoxLayout lay ( &dia ); |
652 | lay.setSpacing( 5 ); | 681 | lay.setSpacing( 5 ); |
653 | lay.setMargin( 3 ); | 682 | lay.setMargin( 3 ); |
654 | QLabel lab1 ( i18n("Password for remote access:"), &dia); | 683 | QLabel lab1 ( i18n("Password for remote access:"), &dia); |
655 | lay.addWidget( &lab1 ); | 684 | lay.addWidget( &lab1 ); |
656 | QLineEdit le1 (&dia ); | 685 | QLineEdit le1 (&dia ); |
657 | lay.addWidget( &le1 ); | 686 | lay.addWidget( &le1 ); |
658 | QLabel lab2 ( i18n("Remote IP address:"), &dia); | 687 | QLabel lab2 ( i18n("Remote IP address:"), &dia); |
659 | lay.addWidget( &lab2 ); | 688 | lay.addWidget( &lab2 ); |
660 | QLineEdit le2 (&dia ); | 689 | QLineEdit le2 (&dia ); |
661 | lay.addWidget( &le2 ); | 690 | lay.addWidget( &le2 ); |
662 | QLabel lab3 ( i18n("Remote port number:"), &dia); | 691 | QLabel lab3 ( i18n("Remote port number:"), &dia); |
663 | lay.addWidget( &lab3 ); | 692 | lay.addWidget( &lab3 ); |
664 | QLineEdit le3 (&dia ); | 693 | QLineEdit le3 (&dia ); |
665 | lay.addWidget( &le3 ); | 694 | lay.addWidget( &le3 ); |
666 | QPushButton pb ( "OK", &dia); | 695 | QPushButton pb ( "OK", &dia); |
667 | lay.addWidget( &pb ); | 696 | lay.addWidget( &pb ); |
668 | connect(&pb, SIGNAL( clicked() ), &dia, SLOT ( accept() ) ); | 697 | connect(&pb, SIGNAL( clicked() ), &dia, SLOT ( accept() ) ); |
669 | le1.setText( mPassWordPiSync ); | 698 | le1.setText( mPassWordPiSync ); |
670 | le2.setText( mActiveSyncIP ); | 699 | le2.setText( mActiveSyncIP ); |
671 | le3.setText( mActiveSyncPort ); | 700 | le3.setText( mActiveSyncPort ); |
672 | if ( dia.exec() ) { | 701 | if ( dia.exec() ) { |
673 | mPassWordPiSync = le1.text(); | 702 | mPassWordPiSync = le1.text(); |
674 | mActiveSyncPort = le3.text(); | 703 | mActiveSyncPort = le3.text(); |
675 | mActiveSyncIP = le2.text(); | 704 | mActiveSyncIP = le2.text(); |
676 | } | 705 | } |
677 | 706 | ||
678 | } | 707 | } |
679 | void KSyncManager::edit_sync_options() | 708 | void KSyncManager::edit_sync_options() |
680 | { | 709 | { |
681 | 710 | ||
682 | QDialog dia( mParent, "dia", true ); | 711 | QDialog dia( mParent, "dia", true ); |
683 | dia.setCaption( i18n("Device: " ) +mCurrentSyncDevice ); | 712 | dia.setCaption( i18n("Device: " ) +mCurrentSyncDevice ); |
684 | QButtonGroup gr ( 1, Qt::Horizontal, i18n("Sync preferences"), &dia); | 713 | QButtonGroup gr ( 1, Qt::Horizontal, i18n("Sync preferences"), &dia); |
685 | QVBoxLayout lay ( &dia ); | 714 | QVBoxLayout lay ( &dia ); |
686 | lay.setSpacing( 2 ); | 715 | lay.setSpacing( 2 ); |
687 | lay.setMargin( 3 ); | 716 | lay.setMargin( 3 ); |
688 | lay.addWidget(&gr); | 717 | lay.addWidget(&gr); |
689 | QRadioButton loc ( i18n("Take local entry on conflict"), &gr ); | 718 | QRadioButton loc ( i18n("Take local entry on conflict"), &gr ); |
690 | QRadioButton rem ( i18n("Take remote entry on conflict"), &gr ); | 719 | QRadioButton rem ( i18n("Take remote entry on conflict"), &gr ); |
691 | QRadioButton newest( i18n("Take newest entry on conflict"), &gr ); | 720 | QRadioButton newest( i18n("Take newest entry on conflict"), &gr ); |
692 | QRadioButton ask( i18n("Ask for every entry on conflict"), &gr ); | 721 | QRadioButton ask( i18n("Ask for every entry on conflict"), &gr ); |
693 | QRadioButton f_loc( i18n("Force: Take local entry always"), &gr ); | 722 | QRadioButton f_loc( i18n("Force: Take local entry always"), &gr ); |
694 | QRadioButton f_rem( i18n("Force: Take remote entry always"), &gr ); | 723 | QRadioButton f_rem( i18n("Force: Take remote entry always"), &gr ); |
695 | //QRadioButton both( i18n("Take both on conflict"), &gr ); | 724 | //QRadioButton both( i18n("Take both on conflict"), &gr ); |
696 | QPushButton pb ( "OK", &dia); | 725 | QPushButton pb ( "OK", &dia); |
697 | lay.addWidget( &pb ); | 726 | lay.addWidget( &pb ); |
698 | connect(&pb, SIGNAL( clicked() ), &dia, SLOT ( accept() ) ); | 727 | connect(&pb, SIGNAL( clicked() ), &dia, SLOT ( accept() ) ); |
699 | switch ( mSyncAlgoPrefs ) { | 728 | switch ( mSyncAlgoPrefs ) { |
700 | case 0: | 729 | case 0: |
701 | loc.setChecked( true); | 730 | loc.setChecked( true); |
702 | break; | 731 | break; |
703 | case 1: | 732 | case 1: |
704 | rem.setChecked( true ); | 733 | rem.setChecked( true ); |
705 | break; | 734 | break; |
706 | case 2: | 735 | case 2: |
707 | newest.setChecked( true); | 736 | newest.setChecked( true); |
708 | break; | 737 | break; |
709 | case 3: | 738 | case 3: |
710 | ask.setChecked( true); | 739 | ask.setChecked( true); |
711 | break; | 740 | break; |
712 | case 4: | 741 | case 4: |
713 | f_loc.setChecked( true); | 742 | f_loc.setChecked( true); |
714 | break; | 743 | break; |
715 | case 5: | 744 | case 5: |
716 | f_rem.setChecked( true); | 745 | f_rem.setChecked( true); |
717 | break; | 746 | break; |
718 | case 6: | 747 | case 6: |
719 | // both.setChecked( true); | 748 | // both.setChecked( true); |
720 | break; | 749 | break; |
721 | default: | 750 | default: |
722 | break; | 751 | break; |
723 | } | 752 | } |
724 | if ( dia.exec() ) { | 753 | if ( dia.exec() ) { |
725 | mSyncAlgoPrefs = rem.isChecked()*1+newest.isChecked()*2+ ask.isChecked()*3+ f_loc.isChecked()*4+ f_rem.isChecked()*5;//+ both.isChecked()*6 ; | 754 | mSyncAlgoPrefs = rem.isChecked()*1+newest.isChecked()*2+ ask.isChecked()*3+ f_loc.isChecked()*4+ f_rem.isChecked()*5;//+ both.isChecked()*6 ; |
726 | } | 755 | } |
727 | 756 | ||
728 | 757 | ||
729 | } | 758 | } |
730 | 759 | ||
731 | QString KSyncManager::getPassword( ) | 760 | QString KSyncManager::getPassword( ) |
732 | { | 761 | { |
733 | QString retfile = ""; | 762 | QString retfile = ""; |
734 | QDialog dia ( mParent, "input-dialog", true ); | 763 | QDialog dia ( mParent, "input-dialog", true ); |
735 | QLineEdit lab ( &dia ); | 764 | QLineEdit lab ( &dia ); |
736 | lab.setEchoMode( QLineEdit::Password ); | 765 | lab.setEchoMode( QLineEdit::Password ); |
737 | QVBoxLayout lay( &dia ); | 766 | QVBoxLayout lay( &dia ); |
738 | lay.setMargin(7); | 767 | lay.setMargin(7); |
739 | lay.setSpacing(7); | 768 | lay.setSpacing(7); |
740 | lay.addWidget( &lab); | 769 | lay.addWidget( &lab); |
741 | dia.setFixedSize( 230,50 ); | 770 | dia.setFixedSize( 230,50 ); |
742 | dia.setCaption( i18n("Enter password") ); | 771 | dia.setCaption( i18n("Enter password") ); |
743 | QPushButton pb ( "OK", &dia); | 772 | QPushButton pb ( "OK", &dia); |
744 | lay.addWidget( &pb ); | 773 | lay.addWidget( &pb ); |
745 | connect(&pb, SIGNAL( clicked() ), &dia, SLOT ( accept() ) ); | 774 | connect(&pb, SIGNAL( clicked() ), &dia, SLOT ( accept() ) ); |
746 | dia.show(); | 775 | dia.show(); |
747 | int res = dia.exec(); | 776 | int res = dia.exec(); |
748 | if ( res ) | 777 | if ( res ) |
749 | retfile = lab.text(); | 778 | retfile = lab.text(); |
750 | dia.hide(); | 779 | dia.hide(); |
751 | qApp->processEvents(); | 780 | qApp->processEvents(); |
752 | return retfile; | 781 | return retfile; |
753 | 782 | ||
754 | } | 783 | } |
755 | 784 | ||
756 | 785 | ||
757 | void KSyncManager::confSync() | 786 | void KSyncManager::confSync() |
758 | { | 787 | { |
759 | static KSyncPrefsDialog* sp = 0; | 788 | static KSyncPrefsDialog* sp = 0; |
760 | if ( ! sp ) { | 789 | if ( ! sp ) { |
761 | sp = new KSyncPrefsDialog( mParent, "syncprefs", true ); | 790 | sp = new KSyncPrefsDialog( mParent, "syncprefs", true ); |
762 | } | 791 | } |
763 | sp->usrReadConfig(); | 792 | sp->usrReadConfig(); |
764 | #ifndef DESKTOP_VERSION | 793 | #ifndef DESKTOP_VERSION |
765 | sp->showMaximized(); | 794 | sp->showMaximized(); |
766 | #else | 795 | #else |
767 | sp->show(); | 796 | sp->show(); |
768 | #endif | 797 | #endif |
769 | sp->exec(); | 798 | sp->exec(); |
770 | mSyncProfileNames = sp->getSyncProfileNames(); | 799 | mSyncProfileNames = sp->getSyncProfileNames(); |
771 | mLocalMachineName = sp->getLocalMachineName (); | 800 | mLocalMachineName = sp->getLocalMachineName (); |
772 | QTimer::singleShot ( 1, this, SLOT ( fillSyncMenu() ) ); | 801 | QTimer::singleShot ( 1, this, SLOT ( fillSyncMenu() ) ); |
773 | } | 802 | } |
774 | void KSyncManager::syncKDE() | 803 | void KSyncManager::syncKDE() |
775 | { | 804 | { |
776 | emit save(); | 805 | emit save(); |
777 | switch(mTargetApp) | 806 | switch(mTargetApp) |
778 | { | 807 | { |
779 | case (KAPI): | 808 | case (KAPI): |
780 | 809 | ||
781 | break; | 810 | break; |
782 | case (KOPI): | 811 | case (KOPI): |
783 | { | 812 | { |
784 | #ifdef DESKTOP_VERSION | 813 | #ifdef DESKTOP_VERSION |
785 | QString command = qApp->applicationDirPath () + "/kdecaldump"; | 814 | QString command = qApp->applicationDirPath () + "/kdecaldump"; |
786 | #else | 815 | #else |
787 | QString command = "kdecaldump"; | 816 | QString command = "kdecaldump"; |
788 | #endif | 817 | #endif |
789 | if ( ! QFile::exists ( command ) ) | 818 | if ( ! QFile::exists ( command ) ) |
790 | command = "kdecaldump"; | 819 | command = "kdecaldump"; |
791 | QString fileName = QDir::homeDirPath ()+"/.kdecalendardump.ics"; | 820 | QString fileName = QDir::homeDirPath ()+"/.kdecalendardump.ics"; |
792 | system ( command.latin1()); | 821 | system ( command.latin1()); |
793 | if ( syncWithFile( fileName,true ) ) { | 822 | if ( syncWithFile( fileName,true ) ) { |
794 | if ( mWriteBackFile ) { | 823 | if ( mWriteBackFile ) { |
795 | command += " --read"; | 824 | command += " --read"; |
796 | system ( command.latin1()); | 825 | system ( command.latin1()); |
797 | } | 826 | } |
798 | } | 827 | } |
799 | 828 | ||
800 | } | 829 | } |
801 | break; | 830 | break; |
802 | case (PWMPI): | 831 | case (PWMPI): |
803 | 832 | ||
804 | break; | 833 | break; |
805 | default: | 834 | default: |
806 | qDebug("KSyncManager::slotSyncMenu: invalid apptype selected"); | 835 | qDebug("KSyncManager::slotSyncMenu: invalid apptype selected"); |
807 | break; | 836 | break; |
808 | 837 | ||
809 | } | 838 | } |
810 | } | 839 | } |
811 | 840 | ||
812 | void KSyncManager::syncSharp() | 841 | void KSyncManager::syncSharp() |
813 | { | 842 | { |
814 | 843 | ||
815 | if ( ! syncExternalApplication("sharp") ) | 844 | if ( ! syncExternalApplication("sharp") ) |
816 | qDebug("ERROR sync sharp "); | 845 | qDebug("ERROR sync sharp "); |
817 | } | 846 | } |
818 | 847 | ||
819 | bool KSyncManager::syncExternalApplication(QString resource) | 848 | bool KSyncManager::syncExternalApplication(QString resource) |
820 | { | 849 | { |
821 | 850 | ||
822 | emit save(); | 851 | emit save(); |
823 | 852 | ||
824 | if ( mAskForPreferences ) | 853 | if ( mAskForPreferences ) |
825 | edit_sync_options(); | 854 | edit_sync_options(); |
826 | 855 | ||
827 | qDebug("Sync extern %s", resource.latin1()); | 856 | qDebug("Sync extern %s", resource.latin1()); |