-rw-r--r-- | libkdepim/ksyncmanager.cpp | 1 |
1 files changed, 1 insertions, 0 deletions
diff --git a/libkdepim/ksyncmanager.cpp b/libkdepim/ksyncmanager.cpp index 6baa2ee..5175f94 100644 --- a/libkdepim/ksyncmanager.cpp +++ b/libkdepim/ksyncmanager.cpp | |||
@@ -1,438 +1,439 @@ | |||
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 | 51 | ||
52 | #include <klocale.h> | 52 | #include <klocale.h> |
53 | #include <kglobal.h> | 53 | #include <kglobal.h> |
54 | #include <kconfig.h> | 54 | #include <kconfig.h> |
55 | #include <kfiledialog.h> | 55 | #include <kfiledialog.h> |
56 | 56 | ||
57 | KSyncManager::KSyncManager(QWidget* parent, KSyncInterface* implementation, TargetApp ta, KPimPrefs* prefs, QPopupMenu* syncmenu) | 57 | KSyncManager::KSyncManager(QWidget* parent, KSyncInterface* implementation, TargetApp ta, KPimPrefs* prefs, QPopupMenu* syncmenu) |
58 | : QObject(), mParent(parent), mImplementation(implementation), mTargetApp(ta), mPrefs(prefs ),mSyncMenu(syncmenu) | 58 | : QObject(), mParent(parent), mImplementation(implementation), mTargetApp(ta), mPrefs(prefs ),mSyncMenu(syncmenu) |
59 | { | 59 | { |
60 | mServerSocket = 0; | 60 | mServerSocket = 0; |
61 | bar = new QProgressBar ( 1, 0 ); | 61 | bar = new QProgressBar ( 1, 0 ); |
62 | bar->setCaption (""); | 62 | bar->setCaption (""); |
63 | 63 | ||
64 | int w = 300; | 64 | int w = 300; |
65 | if ( QApplication::desktop()->width() < 320 ) | 65 | if ( QApplication::desktop()->width() < 320 ) |
66 | w = 220; | 66 | w = 220; |
67 | int h = bar->sizeHint().height() ; | 67 | int h = bar->sizeHint().height() ; |
68 | int dw = QApplication::desktop()->width(); | 68 | int dw = QApplication::desktop()->width(); |
69 | int dh = QApplication::desktop()->height(); | 69 | int dh = QApplication::desktop()->height(); |
70 | bar->setGeometry( (dw-w)/2, (dh - h )/2 ,w,h ); | 70 | bar->setGeometry( (dw-w)/2, (dh - h )/2 ,w,h ); |
71 | 71 | ||
72 | } | 72 | } |
73 | 73 | ||
74 | KSyncManager::~KSyncManager() | 74 | KSyncManager::~KSyncManager() |
75 | { | 75 | { |
76 | delete bar; | 76 | delete bar; |
77 | } | 77 | } |
78 | 78 | ||
79 | 79 | ||
80 | void KSyncManager::fillSyncMenu() | 80 | void KSyncManager::fillSyncMenu() |
81 | { | 81 | { |
82 | if ( mSyncMenu->count() ) | 82 | if ( mSyncMenu->count() ) |
83 | mSyncMenu->clear(); | 83 | mSyncMenu->clear(); |
84 | 84 | ||
85 | mSyncMenu->insertItem( i18n("Configure..."), 0 ); | 85 | mSyncMenu->insertItem( i18n("Configure..."), 0 ); |
86 | mSyncMenu->insertSeparator(); | 86 | mSyncMenu->insertSeparator(); |
87 | if ( mServerSocket == 0 ) { | 87 | if ( mServerSocket == 0 ) { |
88 | mSyncMenu->insertItem( i18n("Enable Pi-Sync"), 2 ); | 88 | mSyncMenu->insertItem( i18n("Enable Pi-Sync"), 2 ); |
89 | } else { | 89 | } else { |
90 | mSyncMenu->insertItem( i18n("Disable Pi-Sync"), 3 ); | 90 | mSyncMenu->insertItem( i18n("Disable Pi-Sync"), 3 ); |
91 | } | 91 | } |
92 | mSyncMenu->insertSeparator(); | 92 | mSyncMenu->insertSeparator(); |
93 | mSyncMenu->insertItem( i18n("Multiple sync"), 1 ); | 93 | mSyncMenu->insertItem( i18n("Multiple sync"), 1 ); |
94 | mSyncMenu->insertSeparator(); | 94 | mSyncMenu->insertSeparator(); |
95 | 95 | ||
96 | KConfig config ( locateLocal( "config","ksyncprofilesrc" ) ); | 96 | KConfig config ( locateLocal( "config","ksyncprofilesrc" ) ); |
97 | config.setGroup("General"); | 97 | config.setGroup("General"); |
98 | QStringList prof = config.readListEntry("SyncProfileNames"); | 98 | QStringList prof = config.readListEntry("SyncProfileNames"); |
99 | mLocalMachineName = config.readEntry("LocalMachineName","undefined"); | 99 | mLocalMachineName = config.readEntry("LocalMachineName","undefined"); |
100 | if ( prof.count() < 2 ) { | 100 | if ( prof.count() < 2 ) { |
101 | prof.clear(); | 101 | prof.clear(); |
102 | prof << i18n("Sharp_DTM"); | 102 | prof << i18n("Sharp_DTM"); |
103 | prof << i18n("Local_file"); | 103 | prof << i18n("Local_file"); |
104 | prof << i18n("Last_file"); | 104 | prof << i18n("Last_file"); |
105 | KSyncProfile* temp = new KSyncProfile (); | 105 | KSyncProfile* temp = new KSyncProfile (); |
106 | temp->setName( prof[0] ); | 106 | temp->setName( prof[0] ); |
107 | temp->writeConfig(&config); | 107 | temp->writeConfig(&config); |
108 | temp->setName( prof[1] ); | 108 | temp->setName( prof[1] ); |
109 | temp->writeConfig(&config); | 109 | temp->writeConfig(&config); |
110 | temp->setName( prof[2] ); | 110 | temp->setName( prof[2] ); |
111 | temp->writeConfig(&config); | 111 | temp->writeConfig(&config); |
112 | config.setGroup("General"); | 112 | config.setGroup("General"); |
113 | config.writeEntry("SyncProfileNames",prof); | 113 | config.writeEntry("SyncProfileNames",prof); |
114 | config.writeEntry("ExternSyncProfiles","Sharp_DTM"); | 114 | config.writeEntry("ExternSyncProfiles","Sharp_DTM"); |
115 | config.sync(); | 115 | config.sync(); |
116 | delete temp; | 116 | delete temp; |
117 | } | 117 | } |
118 | mExternSyncProfiles = config.readListEntry("ExternSyncProfiles"); | 118 | mExternSyncProfiles = config.readListEntry("ExternSyncProfiles"); |
119 | mSyncProfileNames = prof; | 119 | mSyncProfileNames = prof; |
120 | unsigned int i; | 120 | unsigned int i; |
121 | for ( i = 0; i < prof.count(); ++i ) { | 121 | for ( i = 0; i < prof.count(); ++i ) { |
122 | mSyncMenu->insertItem( prof[i], 1000+i ); | 122 | mSyncMenu->insertItem( prof[i], 1000+i ); |
123 | if ( i == 2 ) | 123 | if ( i == 2 ) |
124 | mSyncMenu->insertSeparator(); | 124 | mSyncMenu->insertSeparator(); |
125 | } | 125 | } |
126 | QDir app_dir; | 126 | QDir app_dir; |
127 | //US do not display SharpDTM if app is pwmpi, or no sharpfiles available | 127 | //US do not display SharpDTM if app is pwmpi, or no sharpfiles available |
128 | if ( mTargetApp == PWMPI) { | 128 | if ( mTargetApp == PWMPI) { |
129 | mSyncMenu->removeItem( 1000 ); | 129 | mSyncMenu->removeItem( 1000 ); |
130 | } | 130 | } |
131 | else if (!app_dir.exists(QDir::homeDirPath()+"/Applications/dtm" ) ) { | 131 | else if (!app_dir.exists(QDir::homeDirPath()+"/Applications/dtm" ) ) { |
132 | mSyncMenu->removeItem( 1000 ); | 132 | mSyncMenu->removeItem( 1000 ); |
133 | } | 133 | } |
134 | mSyncMenu->removeItem( 1002 ); | 134 | mSyncMenu->removeItem( 1002 ); |
135 | } | 135 | } |
136 | 136 | ||
137 | void KSyncManager::slotSyncMenu( int action ) | 137 | void KSyncManager::slotSyncMenu( int action ) |
138 | { | 138 | { |
139 | //qDebug("syncaction %d ", action); | 139 | //qDebug("syncaction %d ", action); |
140 | if ( action == 0 ) { | 140 | if ( action == 0 ) { |
141 | 141 | ||
142 | // seems to be a Qt2 event handling bug | 142 | // seems to be a Qt2 event handling bug |
143 | // syncmenu.clear causes a segfault at first time | 143 | // syncmenu.clear causes a segfault at first time |
144 | // when we call it after the main event loop, it is ok | 144 | // when we call it after the main event loop, it is ok |
145 | // same behaviour when calling OM/Pi via QCOP for the first time | 145 | // same behaviour when calling OM/Pi via QCOP for the first time |
146 | QTimer::singleShot ( 1, this, SLOT ( confSync() ) ); | 146 | QTimer::singleShot ( 1, this, SLOT ( confSync() ) ); |
147 | //confSync(); | 147 | //confSync(); |
148 | 148 | ||
149 | return; | 149 | return; |
150 | } | 150 | } |
151 | if ( action == 1 ) { | 151 | if ( action == 1 ) { |
152 | multiSync( true ); | 152 | multiSync( true ); |
153 | return; | 153 | return; |
154 | } | 154 | } |
155 | if ( action == 2 ) { | 155 | if ( action == 2 ) { |
156 | enableQuick(); | 156 | enableQuick(); |
157 | QTimer::singleShot ( 1, this, SLOT ( fillSyncMenu() ) ); | 157 | QTimer::singleShot ( 1, this, SLOT ( fillSyncMenu() ) ); |
158 | return; | 158 | return; |
159 | } | 159 | } |
160 | if ( action == 3 ) { | 160 | if ( action == 3 ) { |
161 | delete mServerSocket; | 161 | delete mServerSocket; |
162 | mServerSocket = 0; | 162 | mServerSocket = 0; |
163 | QTimer::singleShot ( 1, this, SLOT ( fillSyncMenu() ) ); | 163 | QTimer::singleShot ( 1, this, SLOT ( fillSyncMenu() ) ); |
164 | return; | 164 | return; |
165 | } | 165 | } |
166 | 166 | ||
167 | if (blockSave()) | 167 | if (blockSave()) |
168 | return; | 168 | return; |
169 | 169 | ||
170 | setBlockSave(true); | 170 | setBlockSave(true); |
171 | 171 | ||
172 | mCurrentSyncProfile = action - 1000 ; | 172 | mCurrentSyncProfile = action - 1000 ; |
173 | mCurrentSyncDevice = mSyncProfileNames[mCurrentSyncProfile] ; | 173 | mCurrentSyncDevice = mSyncProfileNames[mCurrentSyncProfile] ; |
174 | mCurrentSyncName = mLocalMachineName ; | 174 | mCurrentSyncName = mLocalMachineName ; |
175 | KConfig config ( locateLocal( "config","ksyncprofilesrc" ) ); | 175 | KConfig config ( locateLocal( "config","ksyncprofilesrc" ) ); |
176 | KSyncProfile* temp = new KSyncProfile (); | 176 | KSyncProfile* temp = new KSyncProfile (); |
177 | temp->setName(mSyncProfileNames[mCurrentSyncProfile]); | 177 | temp->setName(mSyncProfileNames[mCurrentSyncProfile]); |
178 | temp->readConfig(&config); | 178 | temp->readConfig(&config); |
179 | mAskForPreferences = temp->getAskForPreferences(); | 179 | mAskForPreferences = temp->getAskForPreferences(); |
180 | mSyncAlgoPrefs = temp->getSyncPrefs(); | 180 | mSyncAlgoPrefs = temp->getSyncPrefs(); |
181 | mWriteBackFile = temp->getWriteBackFile(); | 181 | mWriteBackFile = temp->getWriteBackFile(); |
182 | mWriteBackExistingOnly = temp->getWriteBackExisting(); | 182 | mWriteBackExistingOnly = temp->getWriteBackExisting(); |
183 | mIsKapiFile = temp->getIsKapiFile(); | ||
183 | mWriteBackInFuture = 0; | 184 | mWriteBackInFuture = 0; |
184 | if ( temp->getWriteBackFuture() ) | 185 | if ( temp->getWriteBackFuture() ) |
185 | mWriteBackInFuture = temp->getWriteBackFutureWeeks( ); | 186 | mWriteBackInFuture = temp->getWriteBackFutureWeeks( ); |
186 | mShowSyncSummary = temp->getShowSummaryAfterSync(); | 187 | mShowSyncSummary = temp->getShowSummaryAfterSync(); |
187 | if ( action == 1000 ) { | 188 | if ( action == 1000 ) { |
188 | syncSharp(); | 189 | syncSharp(); |
189 | 190 | ||
190 | } else if ( action == 1001 ) { | 191 | } else if ( action == 1001 ) { |
191 | syncLocalFile(); | 192 | syncLocalFile(); |
192 | 193 | ||
193 | } else if ( action == 1002 ) { | 194 | } else if ( action == 1002 ) { |
194 | mWriteBackFile = false; | 195 | mWriteBackFile = false; |
195 | mAskForPreferences = false; | 196 | mAskForPreferences = false; |
196 | mShowSyncSummary = false; | 197 | mShowSyncSummary = false; |
197 | mSyncAlgoPrefs = 3; | 198 | mSyncAlgoPrefs = 3; |
198 | quickSyncLocalFile(); | 199 | quickSyncLocalFile(); |
199 | 200 | ||
200 | } else if ( action >= 1003 ) { | 201 | } else if ( action >= 1003 ) { |
201 | if ( temp->getIsLocalFileSync() ) { | 202 | if ( temp->getIsLocalFileSync() ) { |
202 | switch(mTargetApp) | 203 | switch(mTargetApp) |
203 | { | 204 | { |
204 | case (KAPI): | 205 | case (KAPI): |
205 | if ( syncWithFile( temp->getRemoteFileNameAB( ), false ) ) | 206 | if ( syncWithFile( temp->getRemoteFileNameAB( ), false ) ) |
206 | mPrefs->mLastSyncedLocalFile = temp->getRemoteFileNameAB(); | 207 | mPrefs->mLastSyncedLocalFile = temp->getRemoteFileNameAB(); |
207 | break; | 208 | break; |
208 | case (KOPI): | 209 | case (KOPI): |
209 | if ( syncWithFile( temp->getRemoteFileName( ), false ) ) | 210 | if ( syncWithFile( temp->getRemoteFileName( ), false ) ) |
210 | mPrefs->mLastSyncedLocalFile = temp->getRemoteFileName(); | 211 | mPrefs->mLastSyncedLocalFile = temp->getRemoteFileName(); |
211 | break; | 212 | break; |
212 | case (PWMPI): | 213 | case (PWMPI): |
213 | if ( syncWithFile( temp->getRemoteFileNamePWM( ), false ) ) | 214 | if ( syncWithFile( temp->getRemoteFileNamePWM( ), false ) ) |
214 | mPrefs->mLastSyncedLocalFile = temp->getRemoteFileNamePWM(); | 215 | mPrefs->mLastSyncedLocalFile = temp->getRemoteFileNamePWM(); |
215 | break; | 216 | break; |
216 | default: | 217 | default: |
217 | qDebug("KSyncManager::slotSyncMenu: invalid apptype selected"); | 218 | qDebug("KSyncManager::slotSyncMenu: invalid apptype selected"); |
218 | break; | 219 | break; |
219 | 220 | ||
220 | } | 221 | } |
221 | } else { | 222 | } else { |
222 | if ( temp->getIsPhoneSync() ) { | 223 | if ( temp->getIsPhoneSync() ) { |
223 | mPhoneDevice = temp->getPhoneDevice( ) ; | 224 | mPhoneDevice = temp->getPhoneDevice( ) ; |
224 | mPhoneConnection = temp->getPhoneConnection( ); | 225 | mPhoneConnection = temp->getPhoneConnection( ); |
225 | mPhoneModel = temp->getPhoneModel( ); | 226 | mPhoneModel = temp->getPhoneModel( ); |
226 | syncPhone(); | 227 | syncPhone(); |
227 | } else if ( temp->getIsPiSync() ) { | 228 | } else if ( temp->getIsPiSync() ) { |
228 | if ( mTargetApp == KAPI ) { | 229 | if ( mTargetApp == KAPI ) { |
229 | mPassWordPiSync = temp->getRemotePwAB(); | 230 | mPassWordPiSync = temp->getRemotePwAB(); |
230 | mActiveSyncPort = temp->getRemotePortAB(); | 231 | mActiveSyncPort = temp->getRemotePortAB(); |
231 | mActiveSyncIP = temp->getRemoteIPAB(); | 232 | mActiveSyncIP = temp->getRemoteIPAB(); |
232 | } else if ( mTargetApp == KOPI ) { | 233 | } else if ( mTargetApp == KOPI ) { |
233 | mPassWordPiSync = temp->getRemotePw(); | 234 | mPassWordPiSync = temp->getRemotePw(); |
234 | mActiveSyncPort = temp->getRemotePort(); | 235 | mActiveSyncPort = temp->getRemotePort(); |
235 | mActiveSyncIP = temp->getRemoteIP(); | 236 | mActiveSyncIP = temp->getRemoteIP(); |
236 | } else { | 237 | } else { |
237 | mPassWordPiSync = temp->getRemotePwPWM(); | 238 | mPassWordPiSync = temp->getRemotePwPWM(); |
238 | mActiveSyncPort = temp->getRemotePortPWM(); | 239 | mActiveSyncPort = temp->getRemotePortPWM(); |
239 | mActiveSyncIP = temp->getRemoteIPPWM(); | 240 | mActiveSyncIP = temp->getRemoteIPPWM(); |
240 | } | 241 | } |
241 | syncPi(); | 242 | syncPi(); |
242 | } else | 243 | } else |
243 | syncRemote( temp ); | 244 | syncRemote( temp ); |
244 | 245 | ||
245 | } | 246 | } |
246 | } | 247 | } |
247 | delete temp; | 248 | delete temp; |
248 | setBlockSave(false); | 249 | setBlockSave(false); |
249 | } | 250 | } |
250 | 251 | ||
251 | void KSyncManager::enableQuick() | 252 | void KSyncManager::enableQuick() |
252 | { | 253 | { |
253 | QDialog dia ( 0, "input-dialog", true ); | 254 | QDialog dia ( 0, "input-dialog", true ); |
254 | QLineEdit lab ( &dia ); | 255 | QLineEdit lab ( &dia ); |
255 | QVBoxLayout lay( &dia ); | 256 | QVBoxLayout lay( &dia ); |
256 | lab.setText( mPrefs->mPassiveSyncPort ); | 257 | lab.setText( mPrefs->mPassiveSyncPort ); |
257 | lay.setMargin(7); | 258 | lay.setMargin(7); |
258 | lay.setSpacing(7); | 259 | lay.setSpacing(7); |
259 | int po = 9197+mTargetApp; | 260 | int po = 9197+mTargetApp; |
260 | QLabel label ( i18n("Port number (Default: %1)").arg(po), &dia ); | 261 | QLabel label ( i18n("Port number (Default: %1)").arg(po), &dia ); |
261 | lay.addWidget( &label); | 262 | lay.addWidget( &label); |
262 | lay.addWidget( &lab); | 263 | lay.addWidget( &lab); |
263 | 264 | ||
264 | QLineEdit lepw ( &dia ); | 265 | QLineEdit lepw ( &dia ); |
265 | lepw.setText( mPrefs->mPassiveSyncPw ); | 266 | lepw.setText( mPrefs->mPassiveSyncPw ); |
266 | QLabel label2 ( i18n("Password to enable\naccess from remote:"), &dia ); | 267 | QLabel label2 ( i18n("Password to enable\naccess from remote:"), &dia ); |
267 | lay.addWidget( &label2); | 268 | lay.addWidget( &label2); |
268 | lay.addWidget( &lepw); | 269 | lay.addWidget( &lepw); |
269 | dia.setFixedSize( 230,80 ); | 270 | dia.setFixedSize( 230,80 ); |
270 | dia.setCaption( i18n("Enter port for Pi-Sync") ); | 271 | dia.setCaption( i18n("Enter port for Pi-Sync") ); |
271 | QPushButton pb ( "OK", &dia); | 272 | QPushButton pb ( "OK", &dia); |
272 | lay.addWidget( &pb ); | 273 | lay.addWidget( &pb ); |
273 | connect(&pb, SIGNAL( clicked() ), &dia, SLOT ( accept() ) ); | 274 | connect(&pb, SIGNAL( clicked() ), &dia, SLOT ( accept() ) ); |
274 | dia.show(); | 275 | dia.show(); |
275 | if ( ! dia.exec() ) | 276 | if ( ! dia.exec() ) |
276 | return; | 277 | return; |
277 | dia.hide(); | 278 | dia.hide(); |
278 | qApp->processEvents(); | 279 | qApp->processEvents(); |
279 | mPrefs->mPassiveSyncPw = lepw.text(); | 280 | mPrefs->mPassiveSyncPw = lepw.text(); |
280 | mPrefs->mPassiveSyncPort = lab.text(); | 281 | mPrefs->mPassiveSyncPort = lab.text(); |
281 | bool ok; | 282 | bool ok; |
282 | Q_UINT16 port = mPrefs->mPassiveSyncPort.toUInt(&ok); | 283 | Q_UINT16 port = mPrefs->mPassiveSyncPort.toUInt(&ok); |
283 | if ( ! ok ) { | 284 | if ( ! ok ) { |
284 | KMessageBox::information( 0, i18n("No valid port")); | 285 | KMessageBox::information( 0, i18n("No valid port")); |
285 | return; | 286 | return; |
286 | } | 287 | } |
287 | //qDebug("port %d ", port); | 288 | //qDebug("port %d ", port); |
288 | mServerSocket = new KServerSocket ( mPrefs->mPassiveSyncPw, port ,1 ); | 289 | mServerSocket = new KServerSocket ( mPrefs->mPassiveSyncPw, port ,1 ); |
289 | mServerSocket->setFileName( defaultFileName() ); | 290 | mServerSocket->setFileName( defaultFileName() ); |
290 | //qDebug("connected "); | 291 | //qDebug("connected "); |
291 | if ( !mServerSocket->ok() ) { | 292 | if ( !mServerSocket->ok() ) { |
292 | KMessageBox::information( 0, i18n("Failed to bind or\nlisten to the port!")); | 293 | KMessageBox::information( 0, i18n("Failed to bind or\nlisten to the port!")); |
293 | delete mServerSocket; | 294 | delete mServerSocket; |
294 | mServerSocket = 0; | 295 | mServerSocket = 0; |
295 | return; | 296 | return; |
296 | } | 297 | } |
297 | connect( mServerSocket, SIGNAL ( request_file() ),this, SIGNAL ( request_file() ) ); | 298 | connect( mServerSocket, SIGNAL ( request_file() ),this, SIGNAL ( request_file() ) ); |
298 | connect( mServerSocket, SIGNAL ( file_received( bool ) ), this, SIGNAL ( getFile( bool ) ) ); | 299 | connect( mServerSocket, SIGNAL ( file_received( bool ) ), this, SIGNAL ( getFile( bool ) ) ); |
299 | } | 300 | } |
300 | 301 | ||
301 | void KSyncManager::syncLocalFile() | 302 | void KSyncManager::syncLocalFile() |
302 | { | 303 | { |
303 | 304 | ||
304 | QString fn =mPrefs->mLastSyncedLocalFile; | 305 | QString fn =mPrefs->mLastSyncedLocalFile; |
305 | QString ext; | 306 | QString ext; |
306 | 307 | ||
307 | switch(mTargetApp) | 308 | switch(mTargetApp) |
308 | { | 309 | { |
309 | case (KAPI): | 310 | case (KAPI): |
310 | ext = "(*.vcf)"; | 311 | ext = "(*.vcf)"; |
311 | break; | 312 | break; |
312 | case (KOPI): | 313 | case (KOPI): |
313 | ext = "(*.ics/*.vcs)"; | 314 | ext = "(*.ics/*.vcs)"; |
314 | break; | 315 | break; |
315 | case (PWMPI): | 316 | case (PWMPI): |
316 | ext = "(*.pwm)"; | 317 | ext = "(*.pwm)"; |
317 | break; | 318 | break; |
318 | default: | 319 | default: |
319 | qDebug("KSyncManager::syncLocalFile: invalid apptype selected"); | 320 | qDebug("KSyncManager::syncLocalFile: invalid apptype selected"); |
320 | break; | 321 | break; |
321 | 322 | ||
322 | } | 323 | } |
323 | 324 | ||
324 | fn =KFileDialog:: getOpenFileName( fn, i18n("Sync filename"+ext), mParent ); | 325 | fn =KFileDialog:: getOpenFileName( fn, i18n("Sync filename"+ext), mParent ); |
325 | if ( fn == "" ) | 326 | if ( fn == "" ) |
326 | return; | 327 | return; |
327 | if ( syncWithFile( fn, false ) ) { | 328 | if ( syncWithFile( fn, false ) ) { |
328 | qDebug("syncLocalFile() successful "); | 329 | qDebug("syncLocalFile() successful "); |
329 | } | 330 | } |
330 | 331 | ||
331 | } | 332 | } |
332 | 333 | ||
333 | bool KSyncManager::syncWithFile( QString fn , bool quick ) | 334 | bool KSyncManager::syncWithFile( QString fn , bool quick ) |
334 | { | 335 | { |
335 | bool ret = false; | 336 | bool ret = false; |
336 | QFileInfo info; | 337 | QFileInfo info; |
337 | info.setFile( fn ); | 338 | info.setFile( fn ); |
338 | QString mess; | 339 | QString mess; |
339 | bool loadbup = true; | 340 | bool loadbup = true; |
340 | if ( !info. exists() ) { | 341 | if ( !info. exists() ) { |
341 | mess = i18n( "Sync file \n...%1\ndoes not exist!\nNothing synced!\n").arg(fn.right( 30) ); | 342 | mess = i18n( "Sync file \n...%1\ndoes not exist!\nNothing synced!\n").arg(fn.right( 30) ); |
342 | int result = QMessageBox::warning( mParent, i18n("Warning!"), | 343 | int result = QMessageBox::warning( mParent, i18n("Warning!"), |
343 | mess ); | 344 | mess ); |
344 | return ret; | 345 | return ret; |
345 | } | 346 | } |
346 | int result = 0; | 347 | int result = 0; |
347 | if ( !quick ) { | 348 | if ( !quick ) { |
348 | mess = i18n("Sync with file \n...%1\nfrom:\n%2\n").arg(fn.right( 25)).arg(KGlobal::locale()->formatDateTime(info.lastModified (), true, false )); | 349 | mess = i18n("Sync with file \n...%1\nfrom:\n%2\n").arg(fn.right( 25)).arg(KGlobal::locale()->formatDateTime(info.lastModified (), true, false )); |
349 | result = QMessageBox::warning( mParent, i18n("Warning!"), | 350 | result = QMessageBox::warning( mParent, i18n("Warning!"), |
350 | mess, | 351 | mess, |
351 | i18n("Sync"), i18n("Cancel"), 0, | 352 | i18n("Sync"), i18n("Cancel"), 0, |
352 | 0, 1 ); | 353 | 0, 1 ); |
353 | if ( result ) | 354 | if ( result ) |
354 | return false; | 355 | return false; |
355 | } | 356 | } |
356 | if ( mAskForPreferences ) | 357 | if ( mAskForPreferences ) |
357 | edit_sync_options(); | 358 | edit_sync_options(); |
358 | if ( result == 0 ) { | 359 | if ( result == 0 ) { |
359 | //qDebug("Now sycing ... "); | 360 | //qDebug("Now sycing ... "); |
360 | if ( ret = mImplementation->sync( this, fn, mSyncAlgoPrefs ) ) | 361 | if ( ret = mImplementation->sync( this, fn, mSyncAlgoPrefs ) ) |
361 | mParent->topLevelWidget()->setCaption( i18n("Synchronization successful") ); | 362 | mParent->topLevelWidget()->setCaption( i18n("Synchronization successful") ); |
362 | else | 363 | else |
363 | mParent->topLevelWidget()->setCaption( i18n("Sync cancelled or failed. Nothing synced.") ); | 364 | mParent->topLevelWidget()->setCaption( i18n("Sync cancelled or failed. Nothing synced.") ); |
364 | if ( ! quick ) | 365 | if ( ! quick ) |
365 | mPrefs->mLastSyncedLocalFile = fn; | 366 | mPrefs->mLastSyncedLocalFile = fn; |
366 | } | 367 | } |
367 | return ret; | 368 | return ret; |
368 | } | 369 | } |
369 | 370 | ||
370 | void KSyncManager::quickSyncLocalFile() | 371 | void KSyncManager::quickSyncLocalFile() |
371 | { | 372 | { |
372 | 373 | ||
373 | if ( syncWithFile( mPrefs->mLastSyncedLocalFile, true ) ) { | 374 | if ( syncWithFile( mPrefs->mLastSyncedLocalFile, true ) ) { |
374 | qDebug("quick syncLocalFile() successful "); | 375 | qDebug("quick syncLocalFile() successful "); |
375 | 376 | ||
376 | } | 377 | } |
377 | } | 378 | } |
378 | 379 | ||
379 | void KSyncManager::multiSync( bool askforPrefs ) | 380 | void KSyncManager::multiSync( bool askforPrefs ) |
380 | { | 381 | { |
381 | if (blockSave()) | 382 | if (blockSave()) |
382 | return; | 383 | return; |
383 | setBlockSave(true); | 384 | setBlockSave(true); |
384 | QString question = i18n("Do you really want\nto multiple sync\nwith all checked profiles?\nSyncing takes some\ntime - all profiles\nare synced twice!"); | 385 | QString question = i18n("Do you really want\nto multiple sync\nwith all checked profiles?\nSyncing takes some\ntime - all profiles\nare synced twice!"); |
385 | if ( QMessageBox::information( mParent, i18n("KDE-Pim Sync"), | 386 | if ( QMessageBox::information( mParent, i18n("KDE-Pim Sync"), |
386 | question, | 387 | question, |
387 | i18n("Yes"), i18n("No"), | 388 | i18n("Yes"), i18n("No"), |
388 | 0, 0 ) != 0 ) { | 389 | 0, 0 ) != 0 ) { |
389 | setBlockSave(false); | 390 | setBlockSave(false); |
390 | mParent->topLevelWidget()->setCaption(i18n("Aborted! Nothing synced!")); | 391 | mParent->topLevelWidget()->setCaption(i18n("Aborted! Nothing synced!")); |
391 | return; | 392 | return; |
392 | } | 393 | } |
393 | mCurrentSyncDevice = i18n("Multiple profiles") ; | 394 | mCurrentSyncDevice = i18n("Multiple profiles") ; |
394 | mSyncAlgoPrefs = mPrefs->mRingSyncAlgoPrefs; | 395 | mSyncAlgoPrefs = mPrefs->mRingSyncAlgoPrefs; |
395 | if ( askforPrefs ) { | 396 | if ( askforPrefs ) { |
396 | edit_sync_options(); | 397 | edit_sync_options(); |
397 | mPrefs->mRingSyncAlgoPrefs = mSyncAlgoPrefs; | 398 | mPrefs->mRingSyncAlgoPrefs = mSyncAlgoPrefs; |
398 | } | 399 | } |
399 | mParent->topLevelWidget()->setCaption(i18n("Multiple sync started.") ); | 400 | mParent->topLevelWidget()->setCaption(i18n("Multiple sync started.") ); |
400 | qApp->processEvents(); | 401 | qApp->processEvents(); |
401 | int num = ringSync() ; | 402 | int num = ringSync() ; |
402 | if ( num > 1 ) | 403 | if ( num > 1 ) |
403 | ringSync(); | 404 | ringSync(); |
404 | setBlockSave(false); | 405 | setBlockSave(false); |
405 | if ( num ) | 406 | if ( num ) |
406 | emit save(); | 407 | emit save(); |
407 | if ( num ) | 408 | if ( num ) |
408 | mParent->topLevelWidget()->setCaption(i18n("%1 profiles synced. Multiple sync complete!").arg(num) ); | 409 | mParent->topLevelWidget()->setCaption(i18n("%1 profiles synced. Multiple sync complete!").arg(num) ); |
409 | else | 410 | else |
410 | mParent->topLevelWidget()->setCaption(i18n("Nothing synced! No profiles defined for multisync!")); | 411 | mParent->topLevelWidget()->setCaption(i18n("Nothing synced! No profiles defined for multisync!")); |
411 | return; | 412 | return; |
412 | } | 413 | } |
413 | 414 | ||
414 | int KSyncManager::ringSync() | 415 | int KSyncManager::ringSync() |
415 | { | 416 | { |
416 | int syncedProfiles = 0; | 417 | int syncedProfiles = 0; |
417 | unsigned int i; | 418 | unsigned int i; |
418 | QTime timer; | 419 | QTime timer; |
419 | KConfig config ( locateLocal( "config","ksyncprofilesrc" ) ); | 420 | KConfig config ( locateLocal( "config","ksyncprofilesrc" ) ); |
420 | QStringList syncProfileNames = mSyncProfileNames; | 421 | QStringList syncProfileNames = mSyncProfileNames; |
421 | KSyncProfile* temp = new KSyncProfile (); | 422 | KSyncProfile* temp = new KSyncProfile (); |
422 | mAskForPreferences = false; | 423 | mAskForPreferences = false; |
423 | for ( i = 0; i < syncProfileNames.count(); ++i ) { | 424 | for ( i = 0; i < syncProfileNames.count(); ++i ) { |
424 | mCurrentSyncProfile = i; | 425 | mCurrentSyncProfile = i; |
425 | temp->setName(syncProfileNames[mCurrentSyncProfile]); | 426 | temp->setName(syncProfileNames[mCurrentSyncProfile]); |
426 | temp->readConfig(&config); | 427 | temp->readConfig(&config); |
427 | 428 | ||
428 | bool includeInRingSync; | 429 | bool includeInRingSync; |
429 | switch(mTargetApp) | 430 | switch(mTargetApp) |
430 | { | 431 | { |
431 | case (KAPI): | 432 | case (KAPI): |
432 | includeInRingSync = temp->getIncludeInRingSyncAB(); | 433 | includeInRingSync = temp->getIncludeInRingSyncAB(); |
433 | break; | 434 | break; |
434 | case (KOPI): | 435 | case (KOPI): |
435 | includeInRingSync = temp->getIncludeInRingSync(); | 436 | includeInRingSync = temp->getIncludeInRingSync(); |
436 | break; | 437 | break; |
437 | case (PWMPI): | 438 | case (PWMPI): |
438 | includeInRingSync = temp->getIncludeInRingSyncPWM(); | 439 | includeInRingSync = temp->getIncludeInRingSyncPWM(); |