-rw-r--r-- | libkdepim/ksyncmanager.cpp | 2 |
1 files changed, 1 insertions, 1 deletions
diff --git a/libkdepim/ksyncmanager.cpp b/libkdepim/ksyncmanager.cpp index 7c53948..6f68d84 100644 --- a/libkdepim/ksyncmanager.cpp +++ b/libkdepim/ksyncmanager.cpp | |||
@@ -1,1472 +1,1472 @@ | |||
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 | QDateTime KSyncManager::mRequestedSyncEvent; | 58 | QDateTime KSyncManager::mRequestedSyncEvent; |
59 | 59 | ||
60 | 60 | ||
61 | KSyncManager::KSyncManager(QWidget* parent, KSyncInterface* implementation, TargetApp ta, KPimPrefs* prefs, QPopupMenu* syncmenu) | 61 | KSyncManager::KSyncManager(QWidget* parent, KSyncInterface* implementation, TargetApp ta, KPimPrefs* prefs, QPopupMenu* syncmenu) |
62 | : QObject(), mParent(parent), mImplementation(implementation), mTargetApp(ta), mPrefs(prefs ),mSyncMenu(syncmenu) | 62 | : QObject(), mParent(parent), mImplementation(implementation), mTargetApp(ta), mPrefs(prefs ),mSyncMenu(syncmenu) |
63 | { | 63 | { |
64 | mServerSocket = 0; | 64 | mServerSocket = 0; |
65 | bar = new QProgressBar ( 1, 0 ); | 65 | bar = new QProgressBar ( 1, 0 ); |
66 | bar->setCaption (""); | 66 | bar->setCaption (""); |
67 | 67 | ||
68 | int w = 300; | 68 | int w = 300; |
69 | if ( QApplication::desktop()->width() < 320 ) | 69 | if ( QApplication::desktop()->width() < 320 ) |
70 | w = 220; | 70 | w = 220; |
71 | int h = bar->sizeHint().height() ; | 71 | int h = bar->sizeHint().height() ; |
72 | int dw = QApplication::desktop()->width(); | 72 | int dw = QApplication::desktop()->width(); |
73 | int dh = QApplication::desktop()->height(); | 73 | int dh = QApplication::desktop()->height(); |
74 | bar->setGeometry( (dw-w)/2, (dh - h )/2 ,w,h ); | 74 | bar->setGeometry( (dw-w)/2, (dh - h )/2 ,w,h ); |
75 | if ( mPrefs->mPassiveSyncAutoStart ) | 75 | if ( mPrefs->mPassiveSyncAutoStart ) |
76 | enableQuick( false ); | 76 | enableQuick( false ); |
77 | 77 | ||
78 | } | 78 | } |
79 | 79 | ||
80 | KSyncManager::~KSyncManager() | 80 | KSyncManager::~KSyncManager() |
81 | { | 81 | { |
82 | delete bar; | 82 | delete bar; |
83 | } | 83 | } |
84 | 84 | ||
85 | 85 | ||
86 | void KSyncManager::fillSyncMenu() | 86 | void KSyncManager::fillSyncMenu() |
87 | { | 87 | { |
88 | if ( mSyncMenu->count() ) | 88 | if ( mSyncMenu->count() ) |
89 | mSyncMenu->clear(); | 89 | mSyncMenu->clear(); |
90 | 90 | ||
91 | mSyncMenu->insertItem( i18n("Configure..."), 0 ); | 91 | mSyncMenu->insertItem( i18n("Configure..."), 0 ); |
92 | mSyncMenu->insertSeparator(); | 92 | mSyncMenu->insertSeparator(); |
93 | QPopupMenu *clearMenu = new QPopupMenu ( mSyncMenu ); | 93 | QPopupMenu *clearMenu = new QPopupMenu ( mSyncMenu ); |
94 | mSyncMenu->insertItem( i18n("Remove sync info"),clearMenu, 5000 ); | 94 | mSyncMenu->insertItem( i18n("Remove sync info"),clearMenu, 5000 ); |
95 | clearMenu->insertItem( i18n("For all profiles"), 1 ); | 95 | clearMenu->insertItem( i18n("For all profiles"), 1 ); |
96 | clearMenu->insertSeparator(); | 96 | clearMenu->insertSeparator(); |
97 | connect ( clearMenu, SIGNAL( activated ( int ) ), this, SLOT (slotClearMenu( int ) ) ); | 97 | connect ( clearMenu, SIGNAL( activated ( int ) ), this, SLOT (slotClearMenu( int ) ) ); |
98 | mSyncMenu->insertSeparator(); | 98 | mSyncMenu->insertSeparator(); |
99 | if ( mServerSocket == 0 ) { | 99 | if ( mServerSocket == 0 ) { |
100 | mSyncMenu->insertItem( i18n("Enable Pi-Sync"), 2 ); | 100 | mSyncMenu->insertItem( i18n("Enable Pi-Sync"), 2 ); |
101 | } else { | 101 | } else { |
102 | mSyncMenu->insertItem( i18n("Disable Pi-Sync"), 3 ); | 102 | mSyncMenu->insertItem( i18n("Disable Pi-Sync"), 3 ); |
103 | } | 103 | } |
104 | mSyncMenu->insertSeparator(); | 104 | mSyncMenu->insertSeparator(); |
105 | mSyncMenu->insertItem( i18n("Multiple sync"), 1 ); | 105 | mSyncMenu->insertItem( i18n("Multiple sync"), 1 ); |
106 | mSyncMenu->insertSeparator(); | 106 | mSyncMenu->insertSeparator(); |
107 | KConfig config ( locateLocal( "config","ksyncprofilesrc" ) ); | 107 | KConfig config ( locateLocal( "config","ksyncprofilesrc" ) ); |
108 | config.setGroup("General"); | 108 | config.setGroup("General"); |
109 | QStringList prof = config.readListEntry("SyncProfileNames"); | 109 | QStringList prof = config.readListEntry("SyncProfileNames"); |
110 | mLocalMachineName = config.readEntry("LocalMachineName","undefined"); | 110 | mLocalMachineName = config.readEntry("LocalMachineName","undefined"); |
111 | if ( prof.count() < 2 ) { | 111 | if ( prof.count() < 2 ) { |
112 | prof.clear(); | 112 | prof.clear(); |
113 | QString externalName; | 113 | QString externalName; |
114 | #ifdef DESKTOP_VERSION | 114 | #ifdef DESKTOP_VERSION |
115 | #ifdef _WIN32_ | 115 | #ifdef _WIN32_ |
116 | externalName = "OutLook(not_implemented)"; | 116 | externalName = "OutLook(not_implemented)"; |
117 | #else | 117 | #else |
118 | externalName = "KDE_Desktop"; | 118 | externalName = "KDE_Desktop"; |
119 | #endif | 119 | #endif |
120 | #else | 120 | #else |
121 | externalName = "Sharp_DTM"; | 121 | externalName = "Sharp_DTM"; |
122 | #endif | 122 | #endif |
123 | prof << externalName; | 123 | prof << externalName; |
124 | prof << i18n("Local_file"); | 124 | prof << i18n("Local_file"); |
125 | prof << i18n("Last_file"); | 125 | prof << i18n("Last_file"); |
126 | KSyncProfile* temp = new KSyncProfile (); | 126 | KSyncProfile* temp = new KSyncProfile (); |
127 | temp->setName( prof[0] ); | 127 | temp->setName( prof[0] ); |
128 | temp->writeConfig(&config); | 128 | temp->writeConfig(&config); |
129 | temp->setName( prof[1] ); | 129 | temp->setName( prof[1] ); |
130 | temp->writeConfig(&config); | 130 | temp->writeConfig(&config); |
131 | temp->setName( prof[2] ); | 131 | temp->setName( prof[2] ); |
132 | temp->writeConfig(&config); | 132 | temp->writeConfig(&config); |
133 | config.setGroup("General"); | 133 | config.setGroup("General"); |
134 | config.writeEntry("SyncProfileNames",prof); | 134 | config.writeEntry("SyncProfileNames",prof); |
135 | config.writeEntry("ExternSyncProfiles",externalName); | 135 | config.writeEntry("ExternSyncProfiles",externalName); |
136 | config.sync(); | 136 | config.sync(); |
137 | delete temp; | 137 | delete temp; |
138 | } | 138 | } |
139 | mExternSyncProfiles = config.readListEntry("ExternSyncProfiles"); | 139 | mExternSyncProfiles = config.readListEntry("ExternSyncProfiles"); |
140 | mSyncProfileNames = prof; | 140 | mSyncProfileNames = prof; |
141 | unsigned int i; | 141 | unsigned int i; |
142 | for ( i = 0; i < prof.count(); ++i ) { | 142 | for ( i = 0; i < prof.count(); ++i ) { |
143 | mSyncMenu->insertItem( prof[i], 1000+i ); | 143 | mSyncMenu->insertItem( prof[i], 1000+i ); |
144 | clearMenu->insertItem( prof[i], 1000+i ); | 144 | clearMenu->insertItem( prof[i], 1000+i ); |
145 | if ( i == 2 ) | 145 | if ( i == 2 ) |
146 | mSyncMenu->insertSeparator(); | 146 | mSyncMenu->insertSeparator(); |
147 | } | 147 | } |
148 | QDir app_dir; | 148 | QDir app_dir; |
149 | //US do not display SharpDTM if app is pwmpi, or no sharpfiles available | 149 | //US do not display SharpDTM if app is pwmpi, or no sharpfiles available |
150 | if ( mTargetApp == PWMPI) { | 150 | if ( mTargetApp == PWMPI) { |
151 | mSyncMenu->removeItem( 1000 ); | 151 | mSyncMenu->removeItem( 1000 ); |
152 | clearMenu->removeItem( 1000 ); | 152 | clearMenu->removeItem( 1000 ); |
153 | } | 153 | } |
154 | #ifndef DESKTOP_VERSION | 154 | #ifndef DESKTOP_VERSION |
155 | else if (!app_dir.exists(QDir::homeDirPath()+"/Applications/dtm" ) ) { | 155 | else if (!app_dir.exists(QDir::homeDirPath()+"/Applications/dtm" ) ) { |
156 | mSyncMenu->removeItem( 1000 ); | 156 | mSyncMenu->removeItem( 1000 ); |
157 | clearMenu->removeItem( 1000 ); | 157 | clearMenu->removeItem( 1000 ); |
158 | } | 158 | } |
159 | #endif | 159 | #endif |
160 | mSyncMenu->removeItem( 1002 ); | 160 | mSyncMenu->removeItem( 1002 ); |
161 | clearMenu->removeItem( 1002 ); | 161 | clearMenu->removeItem( 1002 ); |
162 | } | 162 | } |
163 | void KSyncManager::slotClearMenu( int action ) | 163 | void KSyncManager::slotClearMenu( int action ) |
164 | { | 164 | { |
165 | QString syncDevice; | 165 | QString syncDevice; |
166 | if ( action > 999 ) { | 166 | if ( action > 999 ) { |
167 | syncDevice = mSyncProfileNames[action - 1000] ; | 167 | syncDevice = mSyncProfileNames[action - 1000] ; |
168 | } | 168 | } |
169 | 169 | ||
170 | 170 | ||
171 | 171 | ||
172 | int result = 0; | 172 | int result = 0; |
173 | QString sd; | 173 | QString sd; |
174 | if ( syncDevice.isEmpty() ) | 174 | if ( syncDevice.isEmpty() ) |
175 | sd = i18n("Do you want to\nclear all sync info\nof all profiles?"); | 175 | sd = i18n("Do you want to\nclear all sync info\nof all profiles?"); |
176 | else | 176 | else |
177 | sd = i18n("Do you want to\nclear the sync\ninfo of profile\n%1?\n"). arg( syncDevice ); | 177 | sd = i18n("Do you want to\nclear the sync\ninfo of profile\n%1?\n"). arg( syncDevice ); |
178 | 178 | ||
179 | result = QMessageBox::warning( mParent, i18n("Warning!"),sd,i18n("OK"), i18n("Cancel"), 0, | 179 | result = QMessageBox::warning( mParent, i18n("Warning!"),sd,i18n("OK"), i18n("Cancel"), 0, |
180 | 0, 1 ); | 180 | 0, 1 ); |
181 | if ( result ) | 181 | if ( result ) |
182 | return; | 182 | return; |
183 | mImplementation->removeSyncInfo( syncDevice ); | 183 | mImplementation->removeSyncInfo( syncDevice ); |
184 | } | 184 | } |
185 | void KSyncManager::slotSyncMenu( int action ) | 185 | void KSyncManager::slotSyncMenu( int action ) |
186 | { | 186 | { |
187 | qDebug("syncaction %d ", action); | 187 | qDebug("syncaction %d ", action); |
188 | if ( action == 5000 ) | 188 | if ( action == 5000 ) |
189 | return; | 189 | return; |
190 | mSyncWithDesktop = false; | 190 | mSyncWithDesktop = false; |
191 | if ( action == 0 ) { | 191 | if ( action == 0 ) { |
192 | 192 | ||
193 | // seems to be a Qt2 event handling bug | 193 | // seems to be a Qt2 event handling bug |
194 | // syncmenu.clear causes a segfault at first time | 194 | // syncmenu.clear causes a segfault at first time |
195 | // when we call it after the main event loop, it is ok | 195 | // when we call it after the main event loop, it is ok |
196 | // same behaviour when calling OM/Pi via QCOP for the first time | 196 | // same behaviour when calling OM/Pi via QCOP for the first time |
197 | QTimer::singleShot ( 1, this, SLOT ( confSync() ) ); | 197 | QTimer::singleShot ( 1, this, SLOT ( confSync() ) ); |
198 | //confSync(); | 198 | //confSync(); |
199 | 199 | ||
200 | return; | 200 | return; |
201 | } | 201 | } |
202 | if ( action == 1 ) { | 202 | if ( action == 1 ) { |
203 | multiSync( true ); | 203 | multiSync( true ); |
204 | return; | 204 | return; |
205 | } | 205 | } |
206 | if ( action == 2 ) { | 206 | if ( action == 2 ) { |
207 | enableQuick(); | 207 | enableQuick(); |
208 | QTimer::singleShot ( 1, this, SLOT ( fillSyncMenu() ) ); | 208 | QTimer::singleShot ( 1, this, SLOT ( fillSyncMenu() ) ); |
209 | return; | 209 | return; |
210 | } | 210 | } |
211 | if ( action == 3 ) { | 211 | if ( action == 3 ) { |
212 | delete mServerSocket; | 212 | delete mServerSocket; |
213 | mServerSocket = 0; | 213 | mServerSocket = 0; |
214 | QTimer::singleShot ( 1, this, SLOT ( fillSyncMenu() ) ); | 214 | QTimer::singleShot ( 1, this, SLOT ( fillSyncMenu() ) ); |
215 | return; | 215 | return; |
216 | } | 216 | } |
217 | 217 | ||
218 | if (blockSave()) | 218 | if (blockSave()) |
219 | return; | 219 | return; |
220 | 220 | ||
221 | setBlockSave(true); | 221 | setBlockSave(true); |
222 | bool silent = false; | 222 | bool silent = false; |
223 | if ( action == 999 ) { | 223 | if ( action == 999 ) { |
224 | //special mode for silent syncing | 224 | //special mode for silent syncing |
225 | action = 1000; | 225 | action = 1000; |
226 | silent = true; | 226 | silent = true; |
227 | } | 227 | } |
228 | 228 | ||
229 | mCurrentSyncProfile = action - 1000 ; | 229 | mCurrentSyncProfile = action - 1000 ; |
230 | mCurrentSyncDevice = mSyncProfileNames[mCurrentSyncProfile] ; | 230 | mCurrentSyncDevice = mSyncProfileNames[mCurrentSyncProfile] ; |
231 | mCurrentSyncName = mLocalMachineName ; | 231 | mCurrentSyncName = mLocalMachineName ; |
232 | KConfig config ( locateLocal( "config","ksyncprofilesrc" ) ); | 232 | KConfig config ( locateLocal( "config","ksyncprofilesrc" ) ); |
233 | KSyncProfile* temp = new KSyncProfile (); | 233 | KSyncProfile* temp = new KSyncProfile (); |
234 | temp->setName(mSyncProfileNames[mCurrentSyncProfile]); | 234 | temp->setName(mSyncProfileNames[mCurrentSyncProfile]); |
235 | temp->readConfig(&config); | 235 | temp->readConfig(&config); |
236 | if (silent) { | 236 | if (silent) { |
237 | mAskForPreferences = false; | 237 | mAskForPreferences = false; |
238 | mShowSyncSummary = false; | 238 | mShowSyncSummary = false; |
239 | mWriteBackFile = true; | 239 | mWriteBackFile = true; |
240 | mSyncAlgoPrefs = 2;// take newest | 240 | mSyncAlgoPrefs = 2;// take newest |
241 | } | 241 | } |
242 | else { | 242 | else { |
243 | mAskForPreferences = temp->getAskForPreferences(); | 243 | mAskForPreferences = temp->getAskForPreferences(); |
244 | mShowSyncSummary = temp->getShowSummaryAfterSync(); | 244 | mShowSyncSummary = temp->getShowSummaryAfterSync(); |
245 | mWriteBackFile = temp->getWriteBackFile(); | 245 | mWriteBackFile = temp->getWriteBackFile(); |
246 | mSyncAlgoPrefs = temp->getSyncPrefs(); | 246 | mSyncAlgoPrefs = temp->getSyncPrefs(); |
247 | } | 247 | } |
248 | mWriteBackExistingOnly = temp->getWriteBackExisting(); | 248 | mWriteBackExistingOnly = temp->getWriteBackExisting(); |
249 | mIsKapiFile = temp->getIsKapiFile(); | 249 | mIsKapiFile = temp->getIsKapiFile(); |
250 | mWriteBackInFuture = 0; | 250 | mWriteBackInFuture = 0; |
251 | if ( temp->getWriteBackFuture() ) | 251 | if ( temp->getWriteBackFuture() ) |
252 | mWriteBackInFuture = temp->getWriteBackFutureWeeks( ); | 252 | mWriteBackInFuture = temp->getWriteBackFutureWeeks( ); |
253 | 253 | ||
254 | if ( action == 1000 ) { | 254 | if ( action == 1000 ) { |
255 | mIsKapiFile = false; | 255 | mIsKapiFile = false; |
256 | #ifdef DESKTOP_VERSION | 256 | #ifdef DESKTOP_VERSION |
257 | syncKDE(); | 257 | syncKDE(); |
258 | #else | 258 | #else |
259 | syncSharp(); | 259 | syncSharp(); |
260 | #endif | 260 | #endif |
261 | 261 | ||
262 | } else if ( action == 1001 ) { | 262 | } else if ( action == 1001 ) { |
263 | syncLocalFile(); | 263 | syncLocalFile(); |
264 | 264 | ||
265 | } else if ( action == 1002 ) { | 265 | } else if ( action == 1002 ) { |
266 | mWriteBackFile = false; | 266 | mWriteBackFile = false; |
267 | mAskForPreferences = false; | 267 | mAskForPreferences = false; |
268 | mShowSyncSummary = false; | 268 | mShowSyncSummary = false; |
269 | mSyncAlgoPrefs = 3; | 269 | mSyncAlgoPrefs = 3; |
270 | quickSyncLocalFile(); | 270 | quickSyncLocalFile(); |
271 | 271 | ||
272 | } else if ( action >= 1003 ) { | 272 | } else if ( action >= 1003 ) { |
273 | if ( temp->getIsLocalFileSync() ) { | 273 | if ( temp->getIsLocalFileSync() ) { |
274 | switch(mTargetApp) | 274 | switch(mTargetApp) |
275 | { | 275 | { |
276 | case (KAPI): | 276 | case (KAPI): |
277 | if ( syncWithFile( temp->getRemoteFileNameAB( ), false ) ) | 277 | if ( syncWithFile( temp->getRemoteFileNameAB( ), false ) ) |
278 | mPrefs->mLastSyncedLocalFile = temp->getRemoteFileNameAB(); | 278 | mPrefs->mLastSyncedLocalFile = temp->getRemoteFileNameAB(); |
279 | break; | 279 | break; |
280 | case (KOPI): | 280 | case (KOPI): |
281 | if ( syncWithFile( temp->getRemoteFileName( ), false ) ) | 281 | if ( syncWithFile( temp->getRemoteFileName( ), false ) ) |
282 | mPrefs->mLastSyncedLocalFile = temp->getRemoteFileName(); | 282 | mPrefs->mLastSyncedLocalFile = temp->getRemoteFileName(); |
283 | break; | 283 | break; |
284 | case (PWMPI): | 284 | case (PWMPI): |
285 | if ( syncWithFile( temp->getRemoteFileNamePWM( ), false ) ) | 285 | if ( syncWithFile( temp->getRemoteFileNamePWM( ), false ) ) |
286 | mPrefs->mLastSyncedLocalFile = temp->getRemoteFileNamePWM(); | 286 | mPrefs->mLastSyncedLocalFile = temp->getRemoteFileNamePWM(); |
287 | break; | 287 | break; |
288 | default: | 288 | default: |
289 | qDebug("KSyncManager::slotSyncMenu: invalid apptype selected"); | 289 | qDebug("KSyncManager::slotSyncMenu: invalid apptype selected"); |
290 | break; | 290 | break; |
291 | 291 | ||
292 | } | 292 | } |
293 | } else { | 293 | } else { |
294 | if ( temp->getIsPhoneSync() ) { | 294 | if ( temp->getIsPhoneSync() ) { |
295 | mPhoneDevice = temp->getPhoneDevice( ) ; | 295 | mPhoneDevice = temp->getPhoneDevice( ) ; |
296 | mPhoneConnection = temp->getPhoneConnection( ); | 296 | mPhoneConnection = temp->getPhoneConnection( ); |
297 | mPhoneModel = temp->getPhoneModel( ); | 297 | mPhoneModel = temp->getPhoneModel( ); |
298 | syncPhone(); | 298 | syncPhone(); |
299 | } else if ( temp->getIsPiSync() ) { | 299 | } else if ( temp->getIsPiSync() ) { |
300 | if ( mTargetApp == KAPI ) { | 300 | if ( mTargetApp == KAPI ) { |
301 | mPassWordPiSync = temp->getRemotePwAB(); | 301 | mPassWordPiSync = temp->getRemotePwAB(); |
302 | mActiveSyncPort = temp->getRemotePortAB(); | 302 | mActiveSyncPort = temp->getRemotePortAB(); |
303 | mActiveSyncIP = temp->getRemoteIPAB(); | 303 | mActiveSyncIP = temp->getRemoteIPAB(); |
304 | } else if ( mTargetApp == KOPI ) { | 304 | } else if ( mTargetApp == KOPI ) { |
305 | mPassWordPiSync = temp->getRemotePw(); | 305 | mPassWordPiSync = temp->getRemotePw(); |
306 | mActiveSyncPort = temp->getRemotePort(); | 306 | mActiveSyncPort = temp->getRemotePort(); |
307 | mActiveSyncIP = temp->getRemoteIP(); | 307 | mActiveSyncIP = temp->getRemoteIP(); |
308 | } else { | 308 | } else { |
309 | mPassWordPiSync = temp->getRemotePwPWM(); | 309 | mPassWordPiSync = temp->getRemotePwPWM(); |
310 | mActiveSyncPort = temp->getRemotePortPWM(); | 310 | mActiveSyncPort = temp->getRemotePortPWM(); |
311 | mActiveSyncIP = temp->getRemoteIPPWM(); | 311 | mActiveSyncIP = temp->getRemoteIPPWM(); |
312 | } | 312 | } |
313 | syncPi(); | 313 | syncPi(); |
314 | while ( !mPisyncFinished ) { | 314 | while ( !mPisyncFinished ) { |
315 | //qDebug("waiting "); | 315 | //qDebug("waiting "); |
316 | qApp->processEvents(); | 316 | qApp->processEvents(); |
317 | } | 317 | } |
318 | } else | 318 | } else |
319 | syncRemote( temp ); | 319 | syncRemote( temp ); |
320 | 320 | ||
321 | } | 321 | } |
322 | } | 322 | } |
323 | delete temp; | 323 | delete temp; |
324 | setBlockSave(false); | 324 | setBlockSave(false); |
325 | } | 325 | } |
326 | 326 | ||
327 | void KSyncManager::enableQuick( bool ask ) | 327 | void KSyncManager::enableQuick( bool ask ) |
328 | { | 328 | { |
329 | bool autoStart; | 329 | bool autoStart; |
330 | bool changed = false; | 330 | bool changed = false; |
331 | if ( ask ) { | 331 | if ( ask ) { |
332 | QDialog dia ( 0, "input-dialog", true ); | 332 | QDialog dia ( 0, "input-dialog", true ); |
333 | QLineEdit lab ( &dia ); | 333 | QLineEdit lab ( &dia ); |
334 | QVBoxLayout lay( &dia ); | 334 | QVBoxLayout lay( &dia ); |
335 | lab.setText( mPrefs->mPassiveSyncPort ); | 335 | lab.setText( mPrefs->mPassiveSyncPort ); |
336 | lay.setMargin(7); | 336 | lay.setMargin(7); |
337 | lay.setSpacing(7); | 337 | lay.setSpacing(7); |
338 | int po = 9197+mTargetApp; | 338 | int po = 9197+mTargetApp; |
339 | QLabel label ( i18n("Port number (Default: %1)").arg(po), &dia ); | 339 | QLabel label ( i18n("Port number (Default: %1)").arg(po), &dia ); |
340 | lay.addWidget( &label); | 340 | lay.addWidget( &label); |
341 | lay.addWidget( &lab); | 341 | lay.addWidget( &lab); |
342 | 342 | ||
343 | QLineEdit lepw ( &dia ); | 343 | QLineEdit lepw ( &dia ); |
344 | lepw.setText( mPrefs->mPassiveSyncPw ); | 344 | lepw.setText( mPrefs->mPassiveSyncPw ); |
345 | QLabel label2 ( i18n("Password to enable\naccess from remote:"), &dia ); | 345 | QLabel label2 ( i18n("Password to enable\naccess from remote:"), &dia ); |
346 | lay.addWidget( &label2); | 346 | lay.addWidget( &label2); |
347 | lay.addWidget( &lepw); | 347 | lay.addWidget( &lepw); |
348 | QCheckBox autostart(i18n("Automatically start\nat application startup"), &dia ); | 348 | QCheckBox autostart(i18n("Automatically start\nat application startup"), &dia ); |
349 | lay.addWidget( &autostart); | 349 | lay.addWidget( &autostart); |
350 | autostart.setChecked( mPrefs->mPassiveSyncAutoStart ); | 350 | autostart.setChecked( mPrefs->mPassiveSyncAutoStart ); |
351 | #ifdef DESKTOP_VERSION | 351 | #ifdef DESKTOP_VERSION |
352 | #ifdef _WIN32_ | 352 | #ifdef _WIN32_ |
353 | QCheckBox syncdesktop( i18n("Automatically sync with Outlook\nwhen receiving sync request"),&dia ); | 353 | QCheckBox syncdesktop( i18n("Automatically sync with Outlook\nwhen receiving sync request"),&dia ); |
354 | syncdesktop.hide();// not implemented! | 354 | syncdesktop.hide();// not implemented! |
355 | #else | 355 | #else |
356 | QCheckBox syncdesktop( i18n("Automatically sync with KDE-Desktop\nwhen receiving sync request"),&dia ); | 356 | QCheckBox syncdesktop( i18n("Automatically sync with KDE-Desktop\nwhen receiving sync request"),&dia ); |
357 | #endif | 357 | #endif |
358 | lay.addWidget( &syncdesktop); | 358 | lay.addWidget( &syncdesktop); |
359 | #else | 359 | #else |
360 | mPrefs->mPassiveSyncWithDesktop = false; | 360 | mPrefs->mPassiveSyncWithDesktop = false; |
361 | QCheckBox syncdesktop( i18n("Automatically sync\nwith KDE-Desktop"),&dia ); | 361 | QCheckBox syncdesktop( i18n("Automatically sync\nwith KDE-Desktop"),&dia ); |
362 | syncdesktop.hide(); | 362 | syncdesktop.hide(); |
363 | #endif | 363 | #endif |
364 | syncdesktop.setChecked( mPrefs->mPassiveSyncWithDesktop ); | 364 | syncdesktop.setChecked( mPrefs->mPassiveSyncWithDesktop ); |
365 | 365 | ||
366 | dia.setFixedSize( 230,120 ); | 366 | dia.setFixedSize( 230,120 ); |
367 | dia.setCaption( i18n("Enter port for Pi-Sync") ); | 367 | dia.setCaption( i18n("Enter port for Pi-Sync") ); |
368 | QPushButton pb ( "OK", &dia); | 368 | QPushButton pb ( "OK", &dia); |
369 | lay.addWidget( &pb ); | 369 | lay.addWidget( &pb ); |
370 | connect(&pb, SIGNAL( clicked() ), &dia, SLOT ( accept() ) ); | 370 | connect(&pb, SIGNAL( clicked() ), &dia, SLOT ( accept() ) ); |
371 | dia.show(); | 371 | dia.show(); |
372 | if ( ! dia.exec() ) | 372 | if ( ! dia.exec() ) |
373 | return; | 373 | return; |
374 | dia.hide(); | 374 | dia.hide(); |
375 | qApp->processEvents(); | 375 | qApp->processEvents(); |
376 | if ( mPrefs->mPassiveSyncPw != lepw.text() ) { | 376 | if ( mPrefs->mPassiveSyncPw != lepw.text() ) { |
377 | changed = true; | 377 | changed = true; |
378 | mPrefs->mPassiveSyncPw = lepw.text(); | 378 | mPrefs->mPassiveSyncPw = lepw.text(); |
379 | } | 379 | } |
380 | if ( mPrefs->mPassiveSyncPort != lab.text() ) { | 380 | if ( mPrefs->mPassiveSyncPort != lab.text() ) { |
381 | mPrefs->mPassiveSyncPort = lab.text(); | 381 | mPrefs->mPassiveSyncPort = lab.text(); |
382 | changed = true; | 382 | changed = true; |
383 | } | 383 | } |
384 | autoStart = autostart.isChecked(); | 384 | autoStart = autostart.isChecked(); |
385 | if (mPrefs->mPassiveSyncWithDesktop != syncdesktop.isChecked() ) { | 385 | if (mPrefs->mPassiveSyncWithDesktop != syncdesktop.isChecked() ) { |
386 | changed = true; | 386 | changed = true; |
387 | mPrefs->mPassiveSyncWithDesktop = syncdesktop.isChecked(); | 387 | mPrefs->mPassiveSyncWithDesktop = syncdesktop.isChecked(); |
388 | } | 388 | } |
389 | } | 389 | } |
390 | else | 390 | else |
391 | autoStart = mPrefs->mPassiveSyncAutoStart; | 391 | autoStart = mPrefs->mPassiveSyncAutoStart; |
392 | if ( autoStart != mPrefs->mPassiveSyncAutoStart ) | 392 | if ( autoStart != mPrefs->mPassiveSyncAutoStart ) |
393 | changed = true; | 393 | changed = true; |
394 | bool ok; | 394 | bool ok; |
395 | mPrefs->mPassiveSyncAutoStart = false; | 395 | mPrefs->mPassiveSyncAutoStart = false; |
396 | Q_UINT16 port = mPrefs->mPassiveSyncPort.toUInt(&ok); | 396 | Q_UINT16 port = mPrefs->mPassiveSyncPort.toUInt(&ok); |
397 | if ( ! ok ) { | 397 | if ( ! ok ) { |
398 | KMessageBox::information( 0, i18n("No valid port")); | 398 | KMessageBox::information( 0, i18n("No valid port")); |
399 | return; | 399 | return; |
400 | } | 400 | } |
401 | //qDebug("port %d ", port); | 401 | //qDebug("port %d ", port); |
402 | mServerSocket = new KServerSocket ( mPrefs->mPassiveSyncPw, port ,1 ); | 402 | mServerSocket = new KServerSocket ( mPrefs->mPassiveSyncPw, port ,1 ); |
403 | mServerSocket->setFileName( defaultFileName() );//bbb | 403 | mServerSocket->setFileName( defaultFileName() );//bbb |
404 | //qDebug("connected "); | 404 | //qDebug("connected "); |
405 | if ( !mServerSocket->ok() ) { | 405 | if ( !mServerSocket->ok() ) { |
406 | KMessageBox::information( 0, i18n("Failed to bind or\nlisten to the port!")); | 406 | KMessageBox::information( 0, i18n("Failed to bind or\nlisten to the port!")); |
407 | delete mServerSocket; | 407 | delete mServerSocket; |
408 | mServerSocket = 0; | 408 | mServerSocket = 0; |
409 | return; | 409 | return; |
410 | } | 410 | } |
411 | mPrefs->mPassiveSyncAutoStart = autoStart; | 411 | mPrefs->mPassiveSyncAutoStart = autoStart; |
412 | if ( changed ) { | 412 | if ( changed ) { |
413 | mPrefs->writeConfig(); | 413 | mPrefs->writeConfig(); |
414 | } | 414 | } |
415 | connect( mServerSocket, SIGNAL ( request_file() ),this, SIGNAL ( request_file() ) ); | 415 | connect( mServerSocket, SIGNAL ( request_file() ),this, SIGNAL ( request_file() ) ); |
416 | connect( mServerSocket, SIGNAL ( file_received( bool ) ), this, SIGNAL ( getFile( bool ) ) ); | 416 | connect( mServerSocket, SIGNAL ( file_received( bool ) ), this, SIGNAL ( getFile( bool ) ) ); |
417 | } | 417 | } |
418 | 418 | ||
419 | void KSyncManager::syncLocalFile() | 419 | void KSyncManager::syncLocalFile() |
420 | { | 420 | { |
421 | 421 | ||
422 | QString fn =mPrefs->mLastSyncedLocalFile; | 422 | QString fn =mPrefs->mLastSyncedLocalFile; |
423 | QString ext; | 423 | QString ext; |
424 | 424 | ||
425 | switch(mTargetApp) | 425 | switch(mTargetApp) |
426 | { | 426 | { |
427 | case (KAPI): | 427 | case (KAPI): |
428 | ext = "(*.vcf)"; | 428 | ext = "(*.vcf)"; |
429 | break; | 429 | break; |
430 | case (KOPI): | 430 | case (KOPI): |
431 | ext = "(*.ics/*.vcs)"; | 431 | ext = "(*.ics/*.vcs)"; |
432 | break; | 432 | break; |
433 | case (PWMPI): | 433 | case (PWMPI): |
434 | ext = "(*.pwm)"; | 434 | ext = "(*.pwm)"; |
435 | break; | 435 | break; |
436 | default: | 436 | default: |
437 | qDebug("KSyncManager::syncLocalFile: invalid apptype selected"); | 437 | qDebug("KSyncManager::syncLocalFile: invalid apptype selected"); |
438 | break; | 438 | break; |
439 | 439 | ||
440 | } | 440 | } |
441 | 441 | ||
442 | fn =KFileDialog:: getOpenFileName( fn, i18n("Sync filename"+ext), mParent ); | 442 | fn =KFileDialog:: getOpenFileName( fn, i18n("Sync filename"+ext), mParent ); |
443 | if ( fn == "" ) | 443 | if ( fn == "" ) |
444 | return; | 444 | return; |
445 | if ( syncWithFile( fn, false ) ) { | 445 | if ( syncWithFile( fn, false ) ) { |
446 | qDebug("syncLocalFile() successful "); | 446 | qDebug("syncLocalFile() successful "); |
447 | } | 447 | } |
448 | 448 | ||
449 | } | 449 | } |
450 | 450 | ||
451 | bool KSyncManager::syncWithFile( QString fn , bool quick ) | 451 | bool KSyncManager::syncWithFile( QString fn , bool quick ) |
452 | { | 452 | { |
453 | bool ret = false; | 453 | bool ret = false; |
454 | QFileInfo info; | 454 | QFileInfo info; |
455 | info.setFile( fn ); | 455 | info.setFile( fn ); |
456 | QString mess; | 456 | QString mess; |
457 | bool loadbup = true; | 457 | bool loadbup = true; |
458 | if ( !info. exists() ) { | 458 | if ( !info. exists() ) { |
459 | mess = i18n( "Sync file \n...%1\ndoes not exist!\nNothing synced!\n").arg(fn.right( 30) ); | 459 | mess = i18n( "Sync file \n...%1\ndoes not exist!\nNothing synced!\n").arg(fn.right( 30) ); |
460 | int result = QMessageBox::warning( mParent, i18n("Warning!"), | 460 | int result = QMessageBox::warning( mParent, i18n("Warning!"), |
461 | mess ); | 461 | mess ); |
462 | return ret; | 462 | return ret; |
463 | } | 463 | } |
464 | int result = 0; | 464 | int result = 0; |
465 | if ( !quick ) { | 465 | if ( !quick ) { |
466 | mess = i18n("Sync with file \n...%1\nfrom:\n%2\n").arg(fn.right( 25)).arg(KGlobal::locale()->formatDateTime(info.lastModified (), true, false )); | 466 | mess = i18n("Sync with file \n...%1\nfrom:\n%2\n").arg(fn.right( 25)).arg(KGlobal::locale()->formatDateTime(info.lastModified (), true, false )); |
467 | result = QMessageBox::warning( mParent, i18n("Warning!"), | 467 | result = QMessageBox::warning( mParent, i18n("Warning!"), |
468 | mess, | 468 | mess, |
469 | i18n("Sync"), i18n("Cancel"), 0, | 469 | i18n("Sync"), i18n("Cancel"), 0, |
470 | 0, 1 ); | 470 | 0, 1 ); |
471 | if ( result ) | 471 | if ( result ) |
472 | return false; | 472 | return false; |
473 | } | 473 | } |
474 | if ( mAskForPreferences ) | 474 | if ( mAskForPreferences ) |
475 | if ( !edit_sync_options()) { | 475 | if ( !edit_sync_options()) { |
476 | mParent->topLevelWidget()->setCaption( i18n("Syncing aborted. Nothing synced.") ); | 476 | mParent->topLevelWidget()->setCaption( i18n("Syncing aborted. Nothing synced.") ); |
477 | return false; | 477 | return false; |
478 | } | 478 | } |
479 | if ( result == 0 ) { | 479 | if ( result == 0 ) { |
480 | //qDebug("Now sycing ... "); | 480 | //qDebug("Now sycing ... "); |
481 | if ( ret = mImplementation->sync( this, fn, mSyncAlgoPrefs ) ) | 481 | if ( ret = mImplementation->sync( this, fn, mSyncAlgoPrefs ) ) |
482 | mParent->topLevelWidget()->setCaption( i18n("Synchronization successful") ); | 482 | mParent->topLevelWidget()->setCaption( i18n("Synchronization successful") ); |
483 | else | 483 | else |
484 | mParent->topLevelWidget()->setCaption( i18n("Sync cancelled or failed.") ); | 484 | mParent->topLevelWidget()->setCaption( i18n("Sync cancelled or failed.") ); |
485 | if ( ! quick ) | 485 | if ( ! quick ) |
486 | mPrefs->mLastSyncedLocalFile = fn; | 486 | mPrefs->mLastSyncedLocalFile = fn; |
487 | } | 487 | } |
488 | return ret; | 488 | return ret; |
489 | } | 489 | } |
490 | 490 | ||
491 | void KSyncManager::quickSyncLocalFile() | 491 | void KSyncManager::quickSyncLocalFile() |
492 | { | 492 | { |
493 | 493 | ||
494 | if ( syncWithFile( mPrefs->mLastSyncedLocalFile, true ) ) { | 494 | if ( syncWithFile( mPrefs->mLastSyncedLocalFile, true ) ) { |
495 | qDebug("quick syncLocalFile() successful "); | 495 | qDebug("quick syncLocalFile() successful "); |
496 | 496 | ||
497 | } | 497 | } |
498 | } | 498 | } |
499 | 499 | ||
500 | void KSyncManager::multiSync( bool askforPrefs ) | 500 | void KSyncManager::multiSync( bool askforPrefs ) |
501 | { | 501 | { |
502 | if (blockSave()) | 502 | if (blockSave()) |
503 | return; | 503 | return; |
504 | setBlockSave(true); | 504 | setBlockSave(true); |
505 | QString question = i18n("Do you really want\nto multiple sync\nwith all checked profiles?\nSyncing takes some\ntime - all profiles\nare synced twice!"); | 505 | QString question = i18n("Do you really want\nto multiple sync\nwith all checked profiles?\nSyncing takes some\ntime - all profiles\nare synced twice!"); |
506 | if ( QMessageBox::information( mParent, i18n("KDE-Pim Sync"), | 506 | if ( QMessageBox::information( mParent, i18n("KDE-Pim Sync"), |
507 | question, | 507 | question, |
508 | i18n("Yes"), i18n("No"), | 508 | i18n("Yes"), i18n("No"), |
509 | 0, 0 ) != 0 ) { | 509 | 0, 0 ) != 0 ) { |
510 | setBlockSave(false); | 510 | setBlockSave(false); |
511 | mParent->topLevelWidget()->setCaption(i18n("Aborted! Nothing synced!")); | 511 | mParent->topLevelWidget()->setCaption(i18n("Aborted! Nothing synced!")); |
512 | return; | 512 | return; |
513 | } | 513 | } |
514 | mCurrentSyncDevice = i18n("Multiple profiles") ; | 514 | mCurrentSyncDevice = i18n("Multiple profiles") ; |
515 | mSyncAlgoPrefs = mPrefs->mRingSyncAlgoPrefs; | 515 | mSyncAlgoPrefs = mPrefs->mRingSyncAlgoPrefs; |
516 | if ( askforPrefs ) { | 516 | if ( askforPrefs ) { |
517 | if ( !edit_sync_options()) { | 517 | if ( !edit_sync_options()) { |
518 | mParent->topLevelWidget()->setCaption( i18n("Syncing aborted.") ); | 518 | mParent->topLevelWidget()->setCaption( i18n("Syncing aborted.") ); |
519 | return; | 519 | return; |
520 | } | 520 | } |
521 | mPrefs->mRingSyncAlgoPrefs = mSyncAlgoPrefs; | 521 | mPrefs->mRingSyncAlgoPrefs = mSyncAlgoPrefs; |
522 | } | 522 | } |
523 | mParent->topLevelWidget()->setCaption(i18n("Multiple sync started.") ); | 523 | mParent->topLevelWidget()->setCaption(i18n("Multiple sync started.") ); |
524 | qApp->processEvents(); | 524 | qApp->processEvents(); |
525 | int num = ringSync() ; | 525 | int num = ringSync() ; |
526 | if ( num > 1 ) | 526 | if ( num > 1 ) |
527 | ringSync(); | 527 | ringSync(); |
528 | setBlockSave(false); | 528 | setBlockSave(false); |
529 | if ( num ) | 529 | if ( num ) |
530 | emit save(); | 530 | emit save(); |
531 | if ( num ) | 531 | if ( num ) |
532 | mParent->topLevelWidget()->setCaption(i18n("%1 profiles synced. Multiple sync complete!").arg(num) ); | 532 | mParent->topLevelWidget()->setCaption(i18n("%1 profiles synced. Multiple sync complete!").arg(num) ); |
533 | else | 533 | else |
534 | mParent->topLevelWidget()->setCaption(i18n("Nothing synced! No profiles defined for multisync!")); | 534 | mParent->topLevelWidget()->setCaption(i18n("Nothing synced! No profiles defined for multisync!")); |
535 | return; | 535 | return; |
536 | } | 536 | } |
537 | 537 | ||
538 | int KSyncManager::ringSync() | 538 | int KSyncManager::ringSync() |
539 | { | 539 | { |
540 | 540 | ||
541 | int syncedProfiles = 0; | 541 | int syncedProfiles = 0; |
542 | unsigned int i; | 542 | unsigned int i; |
543 | QTime timer; | 543 | QTime timer; |
544 | KConfig config ( locateLocal( "config","ksyncprofilesrc" ) ); | 544 | KConfig config ( locateLocal( "config","ksyncprofilesrc" ) ); |
545 | QStringList syncProfileNames = mSyncProfileNames; | 545 | QStringList syncProfileNames = mSyncProfileNames; |
546 | KSyncProfile* temp = new KSyncProfile (); | 546 | KSyncProfile* temp = new KSyncProfile (); |
547 | mAskForPreferences = false; | 547 | mAskForPreferences = false; |
548 | for ( i = 0; i < syncProfileNames.count(); ++i ) { | 548 | for ( i = 0; i < syncProfileNames.count(); ++i ) { |
549 | mCurrentSyncProfile = i; | 549 | mCurrentSyncProfile = i; |
550 | temp->setName(syncProfileNames[mCurrentSyncProfile]); | 550 | temp->setName(syncProfileNames[mCurrentSyncProfile]); |
551 | temp->readConfig(&config); | 551 | temp->readConfig(&config); |
552 | 552 | ||
553 | bool includeInRingSync; | 553 | bool includeInRingSync; |
554 | switch(mTargetApp) | 554 | switch(mTargetApp) |
555 | { | 555 | { |
556 | case (KAPI): | 556 | case (KAPI): |
557 | includeInRingSync = temp->getIncludeInRingSyncAB(); | 557 | includeInRingSync = temp->getIncludeInRingSyncAB(); |
558 | break; | 558 | break; |
559 | case (KOPI): | 559 | case (KOPI): |
560 | includeInRingSync = temp->getIncludeInRingSync(); | 560 | includeInRingSync = temp->getIncludeInRingSync(); |
561 | break; | 561 | break; |
562 | case (PWMPI): | 562 | case (PWMPI): |
563 | includeInRingSync = temp->getIncludeInRingSyncPWM(); | 563 | includeInRingSync = temp->getIncludeInRingSyncPWM(); |
564 | break; | 564 | break; |
565 | default: | 565 | default: |
566 | qDebug("KSyncManager::ringSync: invalid apptype selected"); | 566 | qDebug("KSyncManager::ringSync: invalid apptype selected"); |
567 | break; | 567 | break; |
568 | 568 | ||
569 | } | 569 | } |
570 | 570 | ||
571 | 571 | ||
572 | if ( includeInRingSync && ( i < 1 || i > 2 )) { | 572 | if ( includeInRingSync && ( i < 1 || i > 2 )) { |
573 | mParent->topLevelWidget()->setCaption(i18n("Profile ")+syncProfileNames[mCurrentSyncProfile]+ i18n(" is synced ... ")); | 573 | mParent->topLevelWidget()->setCaption(i18n("Profile ")+syncProfileNames[mCurrentSyncProfile]+ i18n(" is synced ... ")); |
574 | ++syncedProfiles; | 574 | ++syncedProfiles; |
575 | mSyncWithDesktop = false; | 575 | mSyncWithDesktop = false; |
576 | // mAskForPreferences = temp->getAskForPreferences(); | 576 | // mAskForPreferences = temp->getAskForPreferences(); |
577 | mWriteBackFile = temp->getWriteBackFile(); | 577 | mWriteBackFile = temp->getWriteBackFile(); |
578 | mWriteBackExistingOnly = temp->getWriteBackExisting(); | 578 | mWriteBackExistingOnly = temp->getWriteBackExisting(); |
579 | mIsKapiFile = temp->getIsKapiFile(); | 579 | mIsKapiFile = temp->getIsKapiFile(); |
580 | mWriteBackInFuture = 0; | 580 | mWriteBackInFuture = 0; |
581 | if ( temp->getWriteBackFuture() ) | 581 | if ( temp->getWriteBackFuture() ) |
582 | mWriteBackInFuture = temp->getWriteBackFutureWeeks( ); | 582 | mWriteBackInFuture = temp->getWriteBackFutureWeeks( ); |
583 | mShowSyncSummary = false; | 583 | mShowSyncSummary = false; |
584 | mCurrentSyncDevice = syncProfileNames[i] ; | 584 | mCurrentSyncDevice = syncProfileNames[i] ; |
585 | mCurrentSyncName = mLocalMachineName; | 585 | mCurrentSyncName = mLocalMachineName; |
586 | if ( i == 0 ) { | 586 | if ( i == 0 ) { |
587 | mIsKapiFile = false; | 587 | mIsKapiFile = false; |
588 | #ifdef DESKTOP_VERSION | 588 | #ifdef DESKTOP_VERSION |
589 | syncKDE(); | 589 | syncKDE(); |
590 | #else | 590 | #else |
591 | syncSharp(); | 591 | syncSharp(); |
592 | #endif | 592 | #endif |
593 | } else { | 593 | } else { |
594 | if ( temp->getIsLocalFileSync() ) { | 594 | if ( temp->getIsLocalFileSync() ) { |
595 | switch(mTargetApp) | 595 | switch(mTargetApp) |
596 | { | 596 | { |
597 | case (KAPI): | 597 | case (KAPI): |
598 | if ( syncWithFile( temp->getRemoteFileNameAB( ), false ) ) | 598 | if ( syncWithFile( temp->getRemoteFileNameAB( ), false ) ) |
599 | mPrefs->mLastSyncedLocalFile = temp->getRemoteFileNameAB(); | 599 | mPrefs->mLastSyncedLocalFile = temp->getRemoteFileNameAB(); |
600 | break; | 600 | break; |
601 | case (KOPI): | 601 | case (KOPI): |
602 | if ( syncWithFile( temp->getRemoteFileName( ), false ) ) | 602 | if ( syncWithFile( temp->getRemoteFileName( ), false ) ) |
603 | mPrefs->mLastSyncedLocalFile = temp->getRemoteFileName(); | 603 | mPrefs->mLastSyncedLocalFile = temp->getRemoteFileName(); |
604 | break; | 604 | break; |
605 | case (PWMPI): | 605 | case (PWMPI): |
606 | if ( syncWithFile( temp->getRemoteFileNamePWM( ), false ) ) | 606 | if ( syncWithFile( temp->getRemoteFileNamePWM( ), false ) ) |
607 | mPrefs->mLastSyncedLocalFile = temp->getRemoteFileNamePWM(); | 607 | mPrefs->mLastSyncedLocalFile = temp->getRemoteFileNamePWM(); |
608 | break; | 608 | break; |
609 | default: | 609 | default: |
610 | qDebug("KSyncManager::slotSyncMenu: invalid apptype selected"); | 610 | qDebug("KSyncManager::slotSyncMenu: invalid apptype selected"); |
611 | break; | 611 | break; |
612 | } | 612 | } |
613 | } else { | 613 | } else { |
614 | if ( temp->getIsPhoneSync() ) { | 614 | if ( temp->getIsPhoneSync() ) { |
615 | mPhoneDevice = temp->getPhoneDevice( ) ; | 615 | mPhoneDevice = temp->getPhoneDevice( ) ; |
616 | mPhoneConnection = temp->getPhoneConnection( ); | 616 | mPhoneConnection = temp->getPhoneConnection( ); |
617 | mPhoneModel = temp->getPhoneModel( ); | 617 | mPhoneModel = temp->getPhoneModel( ); |
618 | syncPhone(); | 618 | syncPhone(); |
619 | } else if ( temp->getIsPiSync() ) { | 619 | } else if ( temp->getIsPiSync() ) { |
620 | if ( mTargetApp == KAPI ) { | 620 | if ( mTargetApp == KAPI ) { |
621 | mPassWordPiSync = temp->getRemotePwAB(); | 621 | mPassWordPiSync = temp->getRemotePwAB(); |
622 | mActiveSyncPort = temp->getRemotePortAB(); | 622 | mActiveSyncPort = temp->getRemotePortAB(); |
623 | mActiveSyncIP = temp->getRemoteIPAB(); | 623 | mActiveSyncIP = temp->getRemoteIPAB(); |
624 | } else if ( mTargetApp == KOPI ) { | 624 | } else if ( mTargetApp == KOPI ) { |
625 | mPassWordPiSync = temp->getRemotePw(); | 625 | mPassWordPiSync = temp->getRemotePw(); |
626 | mActiveSyncPort = temp->getRemotePort(); | 626 | mActiveSyncPort = temp->getRemotePort(); |
627 | mActiveSyncIP = temp->getRemoteIP(); | 627 | mActiveSyncIP = temp->getRemoteIP(); |
628 | } else { | 628 | } else { |
629 | mPassWordPiSync = temp->getRemotePwPWM(); | 629 | mPassWordPiSync = temp->getRemotePwPWM(); |
630 | mActiveSyncPort = temp->getRemotePortPWM(); | 630 | mActiveSyncPort = temp->getRemotePortPWM(); |
631 | mActiveSyncIP = temp->getRemoteIPPWM(); | 631 | mActiveSyncIP = temp->getRemoteIPPWM(); |
632 | } | 632 | } |
633 | syncPi(); | 633 | syncPi(); |
634 | while ( !mPisyncFinished ) { | 634 | while ( !mPisyncFinished ) { |
635 | //qDebug("waiting "); | 635 | //qDebug("waiting "); |
636 | qApp->processEvents(); | 636 | qApp->processEvents(); |
637 | } | 637 | } |
638 | timer.start(); | 638 | timer.start(); |
639 | while ( timer.elapsed () < 2000 ) { | 639 | while ( timer.elapsed () < 2000 ) { |
640 | qApp->processEvents(); | 640 | qApp->processEvents(); |
641 | } | 641 | } |
642 | } else | 642 | } else |
643 | syncRemote( temp, false ); | 643 | syncRemote( temp, false ); |
644 | 644 | ||
645 | } | 645 | } |
646 | } | 646 | } |
647 | timer.start(); | 647 | timer.start(); |
648 | mParent->topLevelWidget()->setCaption(i18n("Multiple sync in progress ... please wait!") ); | 648 | mParent->topLevelWidget()->setCaption(i18n("Multiple sync in progress ... please wait!") ); |
649 | while ( timer.elapsed () < 2000 ) { | 649 | while ( timer.elapsed () < 2000 ) { |
650 | qApp->processEvents(); | 650 | qApp->processEvents(); |
651 | #ifndef _WIN32_ | 651 | #ifndef _WIN32_ |
652 | sleep (1); | 652 | sleep (1); |
653 | #endif | 653 | #endif |
654 | } | 654 | } |
655 | 655 | ||
656 | } | 656 | } |
657 | 657 | ||
658 | } | 658 | } |
659 | delete temp; | 659 | delete temp; |
660 | return syncedProfiles; | 660 | return syncedProfiles; |
661 | } | 661 | } |
662 | 662 | ||
663 | void KSyncManager::syncRemote( KSyncProfile* prof, bool ask) | 663 | void KSyncManager::syncRemote( KSyncProfile* prof, bool ask) |
664 | { | 664 | { |
665 | QString question; | 665 | QString question; |
666 | if ( ask ) { | 666 | if ( ask ) { |
667 | question = i18n("Do you really want\nto remote sync\nwith profile \n")+ prof->getName()+" ?\n"; | 667 | question = i18n("Do you really want\nto remote sync\nwith profile \n")+ prof->getName()+" ?\n"; |
668 | if ( QMessageBox::information( mParent, i18n("Sync"), | 668 | if ( QMessageBox::information( mParent, i18n("Sync"), |
669 | question, | 669 | question, |
670 | i18n("Yes"), i18n("No"), | 670 | i18n("Yes"), i18n("No"), |
671 | 0, 0 ) != 0 ) | 671 | 0, 0 ) != 0 ) |
672 | return; | 672 | return; |
673 | } | 673 | } |
674 | 674 | ||
675 | QString preCommand; | 675 | QString preCommand; |
676 | QString localTempFile; | 676 | QString localTempFile; |
677 | QString postCommand; | 677 | QString postCommand; |
678 | 678 | ||
679 | switch(mTargetApp) | 679 | switch(mTargetApp) |
680 | { | 680 | { |
681 | case (KAPI): | 681 | case (KAPI): |
682 | preCommand = prof->getPreSyncCommandAB(); | 682 | preCommand = prof->getPreSyncCommandAB(); |
683 | postCommand = prof->getPostSyncCommandAB(); | 683 | postCommand = prof->getPostSyncCommandAB(); |
684 | localTempFile = prof->getLocalTempFileAB(); | 684 | localTempFile = prof->getLocalTempFileAB(); |
685 | break; | 685 | break; |
686 | case (KOPI): | 686 | case (KOPI): |
687 | preCommand = prof->getPreSyncCommand(); | 687 | preCommand = prof->getPreSyncCommand(); |
688 | postCommand = prof->getPostSyncCommand(); | 688 | postCommand = prof->getPostSyncCommand(); |
689 | localTempFile = prof->getLocalTempFile(); | 689 | localTempFile = prof->getLocalTempFile(); |
690 | break; | 690 | break; |
691 | case (PWMPI): | 691 | case (PWMPI): |
692 | preCommand = prof->getPreSyncCommandPWM(); | 692 | preCommand = prof->getPreSyncCommandPWM(); |
693 | postCommand = prof->getPostSyncCommandPWM(); | 693 | postCommand = prof->getPostSyncCommandPWM(); |
694 | localTempFile = prof->getLocalTempFilePWM(); | 694 | localTempFile = prof->getLocalTempFilePWM(); |
695 | break; | 695 | break; |
696 | default: | 696 | default: |
697 | qDebug("KSyncManager::syncRemote: invalid apptype selected"); | 697 | qDebug("KSyncManager::syncRemote: invalid apptype selected"); |
698 | break; | 698 | break; |
699 | } | 699 | } |
700 | 700 | ||
701 | 701 | ||
702 | int fi; | 702 | int fi; |
703 | if ( (fi = preCommand.find("$PWD$")) > 0 ) { | 703 | if ( (fi = preCommand.find("$PWD$")) > 0 ) { |
704 | QString pwd = getPassword(); | 704 | QString pwd = getPassword(); |
705 | preCommand = preCommand.left( fi )+ pwd + preCommand.mid( fi+5 ); | 705 | preCommand = preCommand.left( fi )+ pwd + preCommand.mid( fi+5 ); |
706 | 706 | ||
707 | } | 707 | } |
708 | int maxlen = 30; | 708 | int maxlen = 30; |
709 | if ( QApplication::desktop()->width() > 320 ) | 709 | if ( QApplication::desktop()->width() > 320 ) |
710 | maxlen += 25; | 710 | maxlen += 25; |
711 | mParent->topLevelWidget()->setCaption ( i18n( "Copy remote file to local machine..." ) ); | 711 | mParent->topLevelWidget()->setCaption ( i18n( "Copy remote file to local machine..." ) ); |
712 | int fileSize = 0; | 712 | int fileSize = 0; |
713 | int result = system ( preCommand ); | 713 | int result = system ( preCommand ); |
714 | // 0 : okay | 714 | // 0 : okay |
715 | // 256: no such file or dir | 715 | // 256: no such file or dir |
716 | // | 716 | // |
717 | qDebug("Sync: Remote copy result(0 = okay): %d ",result ); | 717 | qDebug("Sync: Remote copy result(0 = okay): %d ",result ); |
718 | if ( result != 0 ) { | 718 | if ( result != 0 ) { |
719 | unsigned int len = maxlen; | 719 | unsigned int len = maxlen; |
720 | while ( len < preCommand.length() ) { | 720 | while ( len < preCommand.length() ) { |
721 | preCommand.insert( len , "\n" ); | 721 | preCommand.insert( len , "\n" ); |
722 | len += maxlen +2; | 722 | len += maxlen +2; |
723 | } | 723 | } |
724 | 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) ; | 724 | 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) ; |
725 | QMessageBox::information( mParent, i18n("Sync - ERROR"), | 725 | QMessageBox::information( mParent, i18n("Sync - ERROR"), |
726 | question, | 726 | question, |
727 | i18n("Okay!")) ; | 727 | i18n("Okay!")) ; |
728 | mParent->topLevelWidget()->setCaption ("KDE-Pim"); | 728 | mParent->topLevelWidget()->setCaption ("KDE-Pim"); |
729 | return; | 729 | return; |
730 | } | 730 | } |
731 | mParent->topLevelWidget()->setCaption ( i18n( "Copying succeed." ) ); | 731 | mParent->topLevelWidget()->setCaption ( i18n( "Copying succeed." ) ); |
732 | //qDebug(" file **%s** ",prof->getLocalTempFile().latin1() ); | 732 | //qDebug(" file **%s** ",prof->getLocalTempFile().latin1() ); |
733 | 733 | ||
734 | if ( syncWithFile( localTempFile, true ) ) { | 734 | if ( syncWithFile( localTempFile, true ) ) { |
735 | 735 | ||
736 | if ( mWriteBackFile ) { | 736 | if ( mWriteBackFile ) { |
737 | int fi; | 737 | int fi; |
738 | if ( (fi = postCommand.find("$PWD$")) > 0 ) { | 738 | if ( (fi = postCommand.find("$PWD$")) > 0 ) { |
739 | QString pwd = getPassword(); | 739 | QString pwd = getPassword(); |
740 | postCommand = postCommand.left( fi )+ pwd + postCommand.mid( fi+5 ); | 740 | postCommand = postCommand.left( fi )+ pwd + postCommand.mid( fi+5 ); |
741 | 741 | ||
742 | } | 742 | } |
743 | mParent->topLevelWidget()->setCaption ( i18n( "Writing back file ..." ) ); | 743 | mParent->topLevelWidget()->setCaption ( i18n( "Writing back file ..." ) ); |
744 | result = system ( postCommand ); | 744 | result = system ( postCommand ); |
745 | qDebug("Sync:Writing back file result: %d ", result); | 745 | qDebug("Sync:Writing back file result: %d ", result); |
746 | if ( result != 0 ) { | 746 | if ( result != 0 ) { |
747 | mParent->topLevelWidget()->setCaption ( i18n( "Writing back file result: " )+QString::number( result ) ); | 747 | mParent->topLevelWidget()->setCaption ( i18n( "Writing back file result: " )+QString::number( result ) ); |
748 | return; | 748 | return; |
749 | } else { | 749 | } else { |
750 | mParent->topLevelWidget()->setCaption ( i18n( "Syncronization sucessfully completed" ) ); | 750 | mParent->topLevelWidget()->setCaption ( i18n( "Syncronization sucessfully completed" ) ); |
751 | } | 751 | } |
752 | } | 752 | } |
753 | } | 753 | } |
754 | return; | 754 | return; |
755 | } | 755 | } |
756 | bool KSyncManager::edit_pisync_options() | 756 | bool KSyncManager::edit_pisync_options() |
757 | { | 757 | { |
758 | QDialog dia( mParent, "dia", true ); | 758 | QDialog dia( mParent, "dia", true ); |
759 | dia.setCaption( i18n("Pi-Sync options for device: " ) +mCurrentSyncDevice ); | 759 | dia.setCaption( i18n("Pi-Sync options for device: " ) +mCurrentSyncDevice ); |
760 | QVBoxLayout lay ( &dia ); | 760 | QVBoxLayout lay ( &dia ); |
761 | lay.setSpacing( 5 ); | 761 | lay.setSpacing( 5 ); |
762 | lay.setMargin( 3 ); | 762 | lay.setMargin( 3 ); |
763 | QLabel lab1 ( i18n("Password for remote access:"), &dia); | 763 | QLabel lab1 ( i18n("Password for remote access:"), &dia); |
764 | lay.addWidget( &lab1 ); | 764 | lay.addWidget( &lab1 ); |
765 | QLineEdit le1 (&dia ); | 765 | QLineEdit le1 (&dia ); |
766 | lay.addWidget( &le1 ); | 766 | lay.addWidget( &le1 ); |
767 | QLabel lab2 ( i18n("Remote IP address:"), &dia); | 767 | QLabel lab2 ( i18n("Remote IP address:"), &dia); |
768 | lay.addWidget( &lab2 ); | 768 | lay.addWidget( &lab2 ); |
769 | QLineEdit le2 (&dia ); | 769 | QLineEdit le2 (&dia ); |
770 | lay.addWidget( &le2 ); | 770 | lay.addWidget( &le2 ); |
771 | QLabel lab3 ( i18n("Remote port number:"), &dia); | 771 | QLabel lab3 ( i18n("Remote port number:"), &dia); |
772 | lay.addWidget( &lab3 ); | 772 | lay.addWidget( &lab3 ); |
773 | QLineEdit le3 (&dia ); | 773 | QLineEdit le3 (&dia ); |
774 | lay.addWidget( &le3 ); | 774 | lay.addWidget( &le3 ); |
775 | QPushButton pb ( "OK", &dia); | 775 | QPushButton pb ( "OK", &dia); |
776 | lay.addWidget( &pb ); | 776 | lay.addWidget( &pb ); |
777 | connect(&pb, SIGNAL( clicked() ), &dia, SLOT ( accept() ) ); | 777 | connect(&pb, SIGNAL( clicked() ), &dia, SLOT ( accept() ) ); |
778 | le1.setText( mPassWordPiSync ); | 778 | le1.setText( mPassWordPiSync ); |
779 | le2.setText( mActiveSyncIP ); | 779 | le2.setText( mActiveSyncIP ); |
780 | le3.setText( mActiveSyncPort ); | 780 | le3.setText( mActiveSyncPort ); |
781 | if ( dia.exec() ) { | 781 | if ( dia.exec() ) { |
782 | mPassWordPiSync = le1.text(); | 782 | mPassWordPiSync = le1.text(); |
783 | mActiveSyncPort = le3.text(); | 783 | mActiveSyncPort = le3.text(); |
784 | mActiveSyncIP = le2.text(); | 784 | mActiveSyncIP = le2.text(); |
785 | return true; | 785 | return true; |
786 | } | 786 | } |
787 | return false; | 787 | return false; |
788 | } | 788 | } |
789 | bool KSyncManager::edit_sync_options() | 789 | bool KSyncManager::edit_sync_options() |
790 | { | 790 | { |
791 | 791 | ||
792 | QDialog dia( mParent, "dia", true ); | 792 | QDialog dia( mParent, "dia", true ); |
793 | dia.setCaption( i18n("Device: " ) +mCurrentSyncDevice ); | 793 | dia.setCaption( i18n("Device: " ) +mCurrentSyncDevice ); |
794 | QButtonGroup gr ( 1, Qt::Horizontal, i18n("Sync preferences"), &dia); | 794 | QButtonGroup gr ( 1, Qt::Horizontal, i18n("Sync preferences"), &dia); |
795 | QVBoxLayout lay ( &dia ); | 795 | QVBoxLayout lay ( &dia ); |
796 | lay.setSpacing( 2 ); | 796 | lay.setSpacing( 2 ); |
797 | lay.setMargin( 3 ); | 797 | lay.setMargin( 3 ); |
798 | lay.addWidget(&gr); | 798 | lay.addWidget(&gr); |
799 | QRadioButton loc ( i18n("Take local entry on conflict"), &gr ); | 799 | QRadioButton loc ( i18n("Take local entry on conflict"), &gr ); |
800 | QRadioButton rem ( i18n("Take remote entry on conflict"), &gr ); | 800 | QRadioButton rem ( i18n("Take remote entry on conflict"), &gr ); |
801 | QRadioButton newest( i18n("Take newest entry on conflict"), &gr ); | 801 | QRadioButton newest( i18n("Take newest entry on conflict"), &gr ); |
802 | QRadioButton ask( i18n("Ask for every entry on conflict"), &gr ); | 802 | QRadioButton ask( i18n("Ask for every entry on conflict"), &gr ); |
803 | QRadioButton f_loc( i18n("Force: Take local entry always"), &gr ); | 803 | QRadioButton f_loc( i18n("Force: Take local entry always"), &gr ); |
804 | QRadioButton f_rem( i18n("Force: Take remote entry always"), &gr ); | 804 | QRadioButton f_rem( i18n("Force: Take remote entry always"), &gr ); |
805 | //QRadioButton both( i18n("Take both on conflict"), &gr ); | 805 | //QRadioButton both( i18n("Take both on conflict"), &gr ); |
806 | QPushButton pb ( "OK", &dia); | 806 | QPushButton pb ( "OK", &dia); |
807 | lay.addWidget( &pb ); | 807 | lay.addWidget( &pb ); |
808 | connect(&pb, SIGNAL( clicked() ), &dia, SLOT ( accept() ) ); | 808 | connect(&pb, SIGNAL( clicked() ), &dia, SLOT ( accept() ) ); |
809 | switch ( mSyncAlgoPrefs ) { | 809 | switch ( mSyncAlgoPrefs ) { |
810 | case 0: | 810 | case 0: |
811 | loc.setChecked( true); | 811 | loc.setChecked( true); |
812 | break; | 812 | break; |
813 | case 1: | 813 | case 1: |
814 | rem.setChecked( true ); | 814 | rem.setChecked( true ); |
815 | break; | 815 | break; |
816 | case 2: | 816 | case 2: |
817 | newest.setChecked( true); | 817 | newest.setChecked( true); |
818 | break; | 818 | break; |
819 | case 3: | 819 | case 3: |
820 | ask.setChecked( true); | 820 | ask.setChecked( true); |
821 | break; | 821 | break; |
822 | case 4: | 822 | case 4: |
823 | f_loc.setChecked( true); | 823 | f_loc.setChecked( true); |
824 | break; | 824 | break; |
825 | case 5: | 825 | case 5: |
826 | f_rem.setChecked( true); | 826 | f_rem.setChecked( true); |
827 | break; | 827 | break; |
828 | case 6: | 828 | case 6: |
829 | // both.setChecked( true); | 829 | // both.setChecked( true); |
830 | break; | 830 | break; |
831 | default: | 831 | default: |
832 | break; | 832 | break; |
833 | } | 833 | } |
834 | if ( dia.exec() ) { | 834 | if ( dia.exec() ) { |
835 | mSyncAlgoPrefs = rem.isChecked()*1+newest.isChecked()*2+ ask.isChecked()*3+ f_loc.isChecked()*4+ f_rem.isChecked()*5;//+ both.isChecked()*6 ; | 835 | mSyncAlgoPrefs = rem.isChecked()*1+newest.isChecked()*2+ ask.isChecked()*3+ f_loc.isChecked()*4+ f_rem.isChecked()*5;//+ both.isChecked()*6 ; |
836 | return true; | 836 | return true; |
837 | } | 837 | } |
838 | return false; | 838 | return false; |
839 | } | 839 | } |
840 | 840 | ||
841 | QString KSyncManager::getPassword( ) | 841 | QString KSyncManager::getPassword( ) |
842 | { | 842 | { |
843 | QString retfile = ""; | 843 | QString retfile = ""; |
844 | QDialog dia ( mParent, "input-dialog", true ); | 844 | QDialog dia ( mParent, "input-dialog", true ); |
845 | QLineEdit lab ( &dia ); | 845 | QLineEdit lab ( &dia ); |
846 | lab.setEchoMode( QLineEdit::Password ); | 846 | lab.setEchoMode( QLineEdit::Password ); |
847 | QVBoxLayout lay( &dia ); | 847 | QVBoxLayout lay( &dia ); |
848 | lay.setMargin(7); | 848 | lay.setMargin(7); |
849 | lay.setSpacing(7); | 849 | lay.setSpacing(7); |
850 | lay.addWidget( &lab); | 850 | lay.addWidget( &lab); |
851 | dia.setFixedSize( 230,50 ); | 851 | dia.setFixedSize( 230,50 ); |
852 | dia.setCaption( i18n("Enter password") ); | 852 | dia.setCaption( i18n("Enter password") ); |
853 | QPushButton pb ( "OK", &dia); | 853 | QPushButton pb ( "OK", &dia); |
854 | lay.addWidget( &pb ); | 854 | lay.addWidget( &pb ); |
855 | connect(&pb, SIGNAL( clicked() ), &dia, SLOT ( accept() ) ); | 855 | connect(&pb, SIGNAL( clicked() ), &dia, SLOT ( accept() ) ); |
856 | dia.show(); | 856 | dia.show(); |
857 | int res = dia.exec(); | 857 | int res = dia.exec(); |
858 | if ( res ) | 858 | if ( res ) |
859 | retfile = lab.text(); | 859 | retfile = lab.text(); |
860 | dia.hide(); | 860 | dia.hide(); |
861 | qApp->processEvents(); | 861 | qApp->processEvents(); |
862 | return retfile; | 862 | return retfile; |
863 | 863 | ||
864 | } | 864 | } |
865 | 865 | ||
866 | 866 | ||
867 | void KSyncManager::confSync() | 867 | void KSyncManager::confSync() |
868 | { | 868 | { |
869 | static KSyncPrefsDialog* sp = 0; | 869 | static KSyncPrefsDialog* sp = 0; |
870 | if ( ! sp ) { | 870 | if ( ! sp ) { |
871 | sp = new KSyncPrefsDialog( mParent, "syncprefs", true ); | 871 | sp = new KSyncPrefsDialog( mParent, "syncprefs", true ); |
872 | } | 872 | } |
873 | sp->usrReadConfig(); | 873 | sp->usrReadConfig(); |
874 | #ifndef DESKTOP_VERSION | 874 | #ifndef DESKTOP_VERSION |
875 | sp->showMaximized(); | 875 | sp->showMaximized(); |
876 | #else | 876 | #else |
877 | sp->show(); | 877 | sp->show(); |
878 | #endif | 878 | #endif |
879 | sp->exec(); | 879 | sp->exec(); |
880 | QStringList oldSyncProfileNames = mSyncProfileNames; | 880 | QStringList oldSyncProfileNames = mSyncProfileNames; |
881 | mSyncProfileNames = sp->getSyncProfileNames(); | 881 | mSyncProfileNames = sp->getSyncProfileNames(); |
882 | mLocalMachineName = sp->getLocalMachineName (); | 882 | mLocalMachineName = sp->getLocalMachineName (); |
883 | int ii; | 883 | int ii; |
884 | for ( ii = 0; ii < oldSyncProfileNames.count(); ++ii ) { | 884 | for ( ii = 0; ii < oldSyncProfileNames.count(); ++ii ) { |
885 | if ( ! mSyncProfileNames.contains( oldSyncProfileNames[ii] ) ) | 885 | if ( ! mSyncProfileNames.contains( oldSyncProfileNames[ii] ) ) |
886 | mImplementation->removeSyncInfo( oldSyncProfileNames[ii] ); | 886 | mImplementation->removeSyncInfo( oldSyncProfileNames[ii] ); |
887 | } | 887 | } |
888 | QTimer::singleShot ( 1, this, SLOT ( fillSyncMenu() ) ); | 888 | QTimer::singleShot ( 1, this, SLOT ( fillSyncMenu() ) ); |
889 | } | 889 | } |
890 | void KSyncManager::syncKDE() | 890 | void KSyncManager::syncKDE() |
891 | { | 891 | { |
892 | mSyncWithDesktop = true; | 892 | mSyncWithDesktop = true; |
893 | emit save(); | 893 | emit save(); |
894 | switch(mTargetApp) | 894 | switch(mTargetApp) |
895 | { | 895 | { |
896 | case (KAPI): | 896 | case (KAPI): |
897 | { | 897 | { |
898 | #ifdef DESKTOP_VERSION | 898 | #ifdef DESKTOP_VERSION |
899 | QString command = qApp->applicationDirPath () + "/kdeabdump"; | 899 | QString command = qApp->applicationDirPath () + "/kdeabdump"; |
900 | #else | 900 | #else |
901 | QString command = "kdeabdump"; | 901 | QString command = "kdeabdump"; |
902 | #endif | 902 | #endif |
903 | if ( ! QFile::exists ( command ) ) | 903 | if ( ! QFile::exists ( command ) ) |
904 | command = "kdeabdump"; | 904 | command = "kdeabdump"; |
905 | QString fileName = QDir::homeDirPath ()+"/.kdeaddressbookdump.vcf"; | 905 | QString fileName = QDir::homeDirPath ()+"/.kdeaddressbookdump.vcf"; |
906 | system ( command.latin1()); | 906 | system ( command.latin1()); |
907 | if ( syncWithFile( fileName,true ) ) { | 907 | if ( syncWithFile( fileName,true ) ) { |
908 | if ( mWriteBackFile ) { | 908 | if ( mWriteBackFile ) { |
909 | command += " --read"; | 909 | command += " --read"; |
910 | system ( command.latin1()); | 910 | system ( command.latin1()); |
911 | } | 911 | } |
912 | } | 912 | } |
913 | 913 | ||
914 | } | 914 | } |
915 | break; | 915 | break; |
916 | case (KOPI): | 916 | case (KOPI): |
917 | { | 917 | { |
918 | #ifdef DESKTOP_VERSION | 918 | #ifdef DESKTOP_VERSION |
919 | QString command = qApp->applicationDirPath () + "/kdecaldump"; | 919 | QString command = qApp->applicationDirPath () + "/kdecaldump"; |
920 | #else | 920 | #else |
921 | QString command = "kdecaldump"; | 921 | QString command = "kdecaldump"; |
922 | #endif | 922 | #endif |
923 | if ( ! QFile::exists ( command ) ) | 923 | if ( ! QFile::exists ( command ) ) |
924 | command = "kdecaldump"; | 924 | command = "kdecaldump"; |
925 | QString fileName = QDir::homeDirPath ()+"/.kdecalendardump.ics"; | 925 | QString fileName = QDir::homeDirPath ()+"/.kdecalendardump.ics"; |
926 | system ( command.latin1()); | 926 | system ( command.latin1()); |
927 | if ( syncWithFile( fileName,true ) ) { | 927 | if ( syncWithFile( fileName,true ) ) { |
928 | if ( mWriteBackFile ) { | 928 | if ( mWriteBackFile ) { |
929 | command += " --read"; | 929 | command += " --read"; |
930 | system ( command.latin1()); | 930 | system ( command.latin1()); |
931 | } | 931 | } |
932 | } | 932 | } |
933 | 933 | ||
934 | } | 934 | } |
935 | break; | 935 | break; |
936 | case (PWMPI): | 936 | case (PWMPI): |
937 | 937 | ||
938 | break; | 938 | break; |
939 | default: | 939 | default: |
940 | qDebug("KSyncManager::slotSyncMenu: invalid apptype selected"); | 940 | qDebug("KSyncManager::slotSyncMenu: invalid apptype selected"); |
941 | break; | 941 | break; |
942 | 942 | ||
943 | } | 943 | } |
944 | } | 944 | } |
945 | 945 | ||
946 | void KSyncManager::syncSharp() | 946 | void KSyncManager::syncSharp() |
947 | { | 947 | { |
948 | 948 | ||
949 | if ( ! syncExternalApplication("sharp") ) | 949 | if ( ! syncExternalApplication("sharp") ) |
950 | qDebug("ERROR sync sharp "); | 950 | qDebug("ERROR sync sharp "); |
951 | } | 951 | } |
952 | 952 | ||
953 | bool KSyncManager::syncExternalApplication(QString resource) | 953 | bool KSyncManager::syncExternalApplication(QString resource) |
954 | { | 954 | { |
955 | 955 | ||
956 | emit save(); | 956 | emit save(); |
957 | 957 | ||
958 | if ( mAskForPreferences ) | 958 | if ( mAskForPreferences ) |
959 | if ( !edit_sync_options()) { | 959 | if ( !edit_sync_options()) { |
960 | mParent->topLevelWidget()->setCaption( i18n("Syncing aborted. Nothing synced.") ); | 960 | mParent->topLevelWidget()->setCaption( i18n("Syncing aborted. Nothing synced.") ); |
961 | return false; | 961 | return false; |
962 | } | 962 | } |
963 | 963 | ||
964 | qDebug("Sync extern %s", resource.latin1()); | 964 | qDebug("Sync extern %s", resource.latin1()); |
965 | 965 | ||
966 | bool syncOK = mImplementation->syncExternal(this, resource); | 966 | bool syncOK = mImplementation->syncExternal(this, resource); |
967 | 967 | ||
968 | return syncOK; | 968 | return syncOK; |
969 | 969 | ||
970 | } | 970 | } |
971 | 971 | ||
972 | void KSyncManager::syncPhone() | 972 | void KSyncManager::syncPhone() |
973 | { | 973 | { |
974 | 974 | ||
975 | syncExternalApplication("phone"); | 975 | syncExternalApplication("phone"); |
976 | 976 | ||
977 | } | 977 | } |
978 | 978 | ||
979 | void KSyncManager::showProgressBar(int percentage, QString caption, int total) | 979 | void KSyncManager::showProgressBar(int percentage, QString caption, int total) |
980 | { | 980 | { |
981 | if (!bar->isVisible()) | 981 | if (!bar->isVisible()) |
982 | { | 982 | { |
983 | bar->setCaption (caption); | 983 | bar->setCaption (caption); |
984 | bar->setTotalSteps ( total ) ; | 984 | bar->setTotalSteps ( total ) ; |
985 | 985 | ||
986 | bar->show(); | 986 | bar->show(); |
987 | } | 987 | } |
988 | 988 | ||
989 | bar->setProgress( percentage ); | 989 | bar->setProgress( percentage ); |
990 | } | 990 | } |
991 | 991 | ||
992 | void KSyncManager::hideProgressBar() | 992 | void KSyncManager::hideProgressBar() |
993 | { | 993 | { |
994 | bar->hide(); | 994 | bar->hide(); |
995 | } | 995 | } |
996 | 996 | ||
997 | bool KSyncManager::isProgressBarCanceled() | 997 | bool KSyncManager::isProgressBarCanceled() |
998 | { | 998 | { |
999 | return !bar->isVisible(); | 999 | return !bar->isVisible(); |
1000 | } | 1000 | } |
1001 | 1001 | ||
1002 | QString KSyncManager::syncFileName() | 1002 | QString KSyncManager::syncFileName() |
1003 | { | 1003 | { |
1004 | 1004 | ||
1005 | QString fn = "tempfile"; | 1005 | QString fn = "tempfile"; |
1006 | switch(mTargetApp) | 1006 | switch(mTargetApp) |
1007 | { | 1007 | { |
1008 | case (KAPI): | 1008 | case (KAPI): |
1009 | fn = "tempsyncab.vcf"; | 1009 | fn = "tempsyncab.vcf"; |
1010 | break; | 1010 | break; |
1011 | case (KOPI): | 1011 | case (KOPI): |
1012 | fn = "tempsynccal.ics"; | 1012 | fn = "tempsynccal.ics"; |
1013 | break; | 1013 | break; |
1014 | case (PWMPI): | 1014 | case (PWMPI): |
1015 | fn = "tempsyncpw.pwm"; | 1015 | fn = "tempsyncpw.pwm"; |
1016 | break; | 1016 | break; |
1017 | default: | 1017 | default: |
1018 | break; | 1018 | break; |
1019 | } | 1019 | } |
1020 | #ifdef _WIN32_ | 1020 | #ifdef _WIN32_ |
1021 | return locateLocal( "tmp", fn ); | 1021 | return locateLocal( "tmp", fn ); |
1022 | #else | 1022 | #else |
1023 | return (QString( "/tmp/" )+ fn ); | 1023 | return (QString( "/tmp/" )+ fn ); |
1024 | #endif | 1024 | #endif |
1025 | } | 1025 | } |
1026 | 1026 | ||
1027 | void KSyncManager::syncPi() | 1027 | void KSyncManager::syncPi() |
1028 | { | 1028 | { |
1029 | mIsKapiFile = true; | 1029 | mIsKapiFile = true; |
1030 | mPisyncFinished = false; | 1030 | mPisyncFinished = false; |
1031 | qApp->processEvents(); | 1031 | qApp->processEvents(); |
1032 | if ( mAskForPreferences ) | 1032 | if ( mAskForPreferences ) |
1033 | if ( !edit_pisync_options()) { | 1033 | if ( !edit_pisync_options()) { |
1034 | mParent->topLevelWidget()->setCaption( i18n("Syncing aborted. Nothing synced.") ); | 1034 | mParent->topLevelWidget()->setCaption( i18n("Syncing aborted. Nothing synced.") ); |
1035 | return; | 1035 | return; |
1036 | } | 1036 | } |
1037 | bool ok; | 1037 | bool ok; |
1038 | Q_UINT16 port = mActiveSyncPort.toUInt(&ok); | 1038 | Q_UINT16 port = mActiveSyncPort.toUInt(&ok); |
1039 | if ( ! ok ) { | 1039 | if ( ! ok ) { |
1040 | mParent->topLevelWidget()->setCaption( i18n("Sorry, no valid port.Syncing cancelled.") ); | 1040 | mParent->topLevelWidget()->setCaption( i18n("Sorry, no valid port.Syncing cancelled.") ); |
1041 | return; | 1041 | return; |
1042 | } | 1042 | } |
1043 | KCommandSocket* commandSocket = new KCommandSocket( mPassWordPiSync, port, mActiveSyncIP, this ); | 1043 | KCommandSocket* commandSocket = new KCommandSocket( mPassWordPiSync, port, mActiveSyncIP, this ); |
1044 | connect( commandSocket, SIGNAL(commandFinished( KCommandSocket*, int )), this, SLOT(deleteCommandSocket(KCommandSocket*, int)) ); | 1044 | connect( commandSocket, SIGNAL(commandFinished( KCommandSocket*, int )), this, SLOT(deleteCommandSocket(KCommandSocket*, int)) ); |
1045 | mParent->topLevelWidget()->setCaption( i18n("Sending request for remote file ...") ); | 1045 | mParent->topLevelWidget()->setCaption( i18n("Sending request for remote file ...") ); |
1046 | commandSocket->readFile( syncFileName() ); | 1046 | commandSocket->readFile( syncFileName() ); |
1047 | } | 1047 | } |
1048 | 1048 | ||
1049 | void KSyncManager::deleteCommandSocket(KCommandSocket*s, int state) | 1049 | void KSyncManager::deleteCommandSocket(KCommandSocket*s, int state) |
1050 | { | 1050 | { |
1051 | //enum { success, errorW, errorR, quiet }; | 1051 | //enum { success, errorW, errorR, quiet }; |
1052 | if ( state == KCommandSocket::errorR ||state == KCommandSocket::errorTO ) { | 1052 | if ( state == KCommandSocket::errorR ||state == KCommandSocket::errorTO ) { |
1053 | mParent->topLevelWidget()->setCaption( i18n("ERROR: Receiving remote file failed.") ); | 1053 | mParent->topLevelWidget()->setCaption( i18n("ERROR: Receiving remote file failed.") ); |
1054 | delete s; | 1054 | delete s; |
1055 | if ( state == KCommandSocket::errorR ) { | 1055 | if ( state == KCommandSocket::errorR ) { |
1056 | KCommandSocket* commandSocket = new KCommandSocket( mPassWordPiSync, mActiveSyncPort.toUInt(), mActiveSyncIP, this ); | 1056 | KCommandSocket* commandSocket = new KCommandSocket( mPassWordPiSync, mActiveSyncPort.toUInt(), mActiveSyncIP, this ); |
1057 | connect( commandSocket, SIGNAL(commandFinished( KCommandSocket*, int)), this, SLOT(deleteCommandSocket(KCommandSocket*, int )) ); | 1057 | connect( commandSocket, SIGNAL(commandFinished( KCommandSocket*, int)), this, SLOT(deleteCommandSocket(KCommandSocket*, int )) ); |
1058 | commandSocket->sendStop(); | 1058 | commandSocket->sendStop(); |
1059 | } | 1059 | } |
1060 | mPisyncFinished = true; | 1060 | mPisyncFinished = true; |
1061 | return; | 1061 | return; |
1062 | 1062 | ||
1063 | } else if ( state == KCommandSocket::errorW ) { | 1063 | } else if ( state == KCommandSocket::errorW ) { |
1064 | mParent->topLevelWidget()->setCaption( i18n("ERROR:Writing back file failed.") ); | 1064 | mParent->topLevelWidget()->setCaption( i18n("ERROR:Writing back file failed.") ); |
1065 | mPisyncFinished = true; | 1065 | mPisyncFinished = true; |
1066 | 1066 | ||
1067 | } else if ( state == KCommandSocket::successR ) { | 1067 | } else if ( state == KCommandSocket::successR ) { |
1068 | QTimer::singleShot( 1, this , SLOT ( readFileFromSocket())); | 1068 | QTimer::singleShot( 1, this , SLOT ( readFileFromSocket())); |
1069 | 1069 | ||
1070 | } else if ( state == KCommandSocket::successW ) { | 1070 | } else if ( state == KCommandSocket::successW ) { |
1071 | mParent->topLevelWidget()->setCaption( i18n("Pi-Sync succesful!") ); | 1071 | mParent->topLevelWidget()->setCaption( i18n("Pi-Sync succesful!") ); |
1072 | mPisyncFinished = true; | 1072 | mPisyncFinished = true; |
1073 | } | 1073 | } |
1074 | 1074 | ||
1075 | delete s; | 1075 | delete s; |
1076 | } | 1076 | } |
1077 | 1077 | ||
1078 | void KSyncManager::readFileFromSocket() | 1078 | void KSyncManager::readFileFromSocket() |
1079 | { | 1079 | { |
1080 | QString fileName = syncFileName(); | 1080 | QString fileName = syncFileName(); |
1081 | mParent->topLevelWidget()->setCaption( i18n("Remote file saved to temp file.") ); | 1081 | mParent->topLevelWidget()->setCaption( i18n("Remote file saved to temp file.") ); |
1082 | if ( ! syncWithFile( fileName , true ) ) { | 1082 | if ( ! syncWithFile( fileName , true ) ) { |
1083 | mParent->topLevelWidget()->setCaption( i18n("Syncing failed.") ); | 1083 | mParent->topLevelWidget()->setCaption( i18n("Syncing failed.") ); |
1084 | mPisyncFinished = true; | 1084 | mPisyncFinished = true; |
1085 | return; | 1085 | return; |
1086 | } | 1086 | } |
1087 | KCommandSocket* commandSocket = new KCommandSocket( mPassWordPiSync, mActiveSyncPort.toUInt(), mActiveSyncIP, this ); | 1087 | KCommandSocket* commandSocket = new KCommandSocket( mPassWordPiSync, mActiveSyncPort.toUInt(), mActiveSyncIP, this ); |
1088 | connect( commandSocket, SIGNAL(commandFinished( KCommandSocket*, int)), this, SLOT(deleteCommandSocket(KCommandSocket*, int )) ); | 1088 | connect( commandSocket, SIGNAL(commandFinished( KCommandSocket*, int)), this, SLOT(deleteCommandSocket(KCommandSocket*, int )) ); |
1089 | if ( mWriteBackFile ) | 1089 | if ( mWriteBackFile ) |
1090 | commandSocket->writeFile( fileName ); | 1090 | commandSocket->writeFile( fileName ); |
1091 | else { | 1091 | else { |
1092 | commandSocket->sendStop(); | 1092 | commandSocket->sendStop(); |
1093 | mParent->topLevelWidget()->setCaption( i18n("Pi-Sync succesful!") ); | 1093 | mParent->topLevelWidget()->setCaption( i18n("Pi-Sync succesful!") ); |
1094 | mPisyncFinished = true; | 1094 | mPisyncFinished = true; |
1095 | } | 1095 | } |
1096 | } | 1096 | } |
1097 | 1097 | ||
1098 | KServerSocket:: KServerSocket ( QString pw, Q_UINT16 port, int backlog, QObject * parent, const char * name ) : QServerSocket( port, backlog, parent, name ) | 1098 | KServerSocket:: KServerSocket ( QString pw, Q_UINT16 port, int backlog, QObject * parent, const char * name ) : QServerSocket( port, backlog, parent, name ) |
1099 | { | 1099 | { |
1100 | mPassWord = pw; | 1100 | mPassWord = pw; |
1101 | mSocket = 0; | 1101 | mSocket = 0; |
1102 | mSyncActionDialog = 0; | 1102 | mSyncActionDialog = 0; |
1103 | blockRC = false; | 1103 | blockRC = false; |
1104 | }; | 1104 | }; |
1105 | 1105 | ||
1106 | void KServerSocket::newConnection ( int socket ) | 1106 | void KServerSocket::newConnection ( int socket ) |
1107 | { | 1107 | { |
1108 | // qDebug("KServerSocket:New connection %d ", socket); | 1108 | // qDebug("KServerSocket:New connection %d ", socket); |
1109 | if ( mSocket ) { | 1109 | if ( mSocket ) { |
1110 | qDebug("KServerSocket::newConnection Socket deleted! "); | 1110 | qDebug("KServerSocket::newConnection Socket deleted! "); |
1111 | delete mSocket; | 1111 | delete mSocket; |
1112 | mSocket = 0; | 1112 | mSocket = 0; |
1113 | } | 1113 | } |
1114 | mSocket = new QSocket( this ); | 1114 | mSocket = new QSocket( this ); |
1115 | connect( mSocket , SIGNAL(readyRead()), this, SLOT(readClient()) ); | 1115 | connect( mSocket , SIGNAL(readyRead()), this, SLOT(readClient()) ); |
1116 | connect( mSocket , SIGNAL(delayedCloseFinished()), this, SLOT(discardClient()) ); | 1116 | connect( mSocket , SIGNAL(delayedCloseFinished()), this, SLOT(discardClient()) ); |
1117 | mSocket->setSocket( socket ); | 1117 | mSocket->setSocket( socket ); |
1118 | } | 1118 | } |
1119 | 1119 | ||
1120 | void KServerSocket::discardClient() | 1120 | void KServerSocket::discardClient() |
1121 | { | 1121 | { |
1122 | //qDebug(" KServerSocket::discardClient()"); | 1122 | //qDebug(" KServerSocket::discardClient()"); |
1123 | if ( mSocket ) { | 1123 | if ( mSocket ) { |
1124 | delete mSocket; | 1124 | delete mSocket; |
1125 | mSocket = 0; | 1125 | mSocket = 0; |
1126 | } | 1126 | } |
1127 | //emit endConnect(); | 1127 | //emit endConnect(); |
1128 | } | 1128 | } |
1129 | void KServerSocket::readClient() | 1129 | void KServerSocket::readClient() |
1130 | { | 1130 | { |
1131 | if ( blockRC ) | 1131 | if ( blockRC ) |
1132 | return; | 1132 | return; |
1133 | if ( mSocket == 0 ) { | 1133 | if ( mSocket == 0 ) { |
1134 | qDebug("ERROR::KServerSocket::readClient(): mSocket == 0 "); | 1134 | qDebug("ERROR::KServerSocket::readClient(): mSocket == 0 "); |
1135 | return; | 1135 | return; |
1136 | } | 1136 | } |
1137 | //qDebug("KServerSocket::readClient()"); | 1137 | //qDebug("KServerSocket::readClient()"); |
1138 | if ( mSocket->canReadLine() ) { | 1138 | if ( mSocket->canReadLine() ) { |
1139 | QString line = mSocket->readLine(); | 1139 | QString line = mSocket->readLine(); |
1140 | //qDebug("KServerSocket readline: %s ", line.latin1()); | 1140 | //qDebug("KServerSocket readline: %s ", line.latin1()); |
1141 | QStringList tokens = QStringList::split( QRegExp("[ \r\n][ \r\n]*"), line ); | 1141 | QStringList tokens = QStringList::split( QRegExp("[ \r\n][ \r\n]*"), line ); |
1142 | if ( tokens[0] == "GET" ) { | 1142 | if ( tokens[0] == "GET" ) { |
1143 | if ( tokens[1] == mPassWord ) { | 1143 | if ( tokens[1] == mPassWord ) { |
1144 | //emit sendFile( mSocket ); | 1144 | //emit sendFile( mSocket ); |
1145 | bool ok = false; | 1145 | bool ok = false; |
1146 | QDateTime dt = KGlobal::locale()->readDateTime( tokens[2], KLocale::ISODate, &ok); | 1146 | QDateTime dt = KGlobal::locale()->readDateTime( tokens[2], KLocale::ISODate, &ok); |
1147 | if ( ok ) { | 1147 | if ( ok ) { |
1148 | KSyncManager::mRequestedSyncEvent = dt; | 1148 | KSyncManager::mRequestedSyncEvent = dt; |
1149 | } | 1149 | } |
1150 | else | 1150 | else |
1151 | KSyncManager::mRequestedSyncEvent = QDateTime(); | 1151 | KSyncManager::mRequestedSyncEvent = QDateTime(); |
1152 | send_file(); | 1152 | send_file(); |
1153 | } | 1153 | } |
1154 | else { | 1154 | else { |
1155 | KMessageBox::error( 0, i18n("Got send file request\nwith invalid password")); | 1155 | KMessageBox::error( 0, i18n("Got send file request\nwith invalid password")); |
1156 | //qDebug("password %s, invalid password %s ",mPassWord.latin1(), tokens[1].latin1() ); | 1156 | //qDebug("password %s, invalid password %s ",mPassWord.latin1(), tokens[1].latin1() ); |
1157 | } | 1157 | } |
1158 | } | 1158 | } |
1159 | if ( tokens[0] == "PUT" ) { | 1159 | if ( tokens[0] == "PUT" ) { |
1160 | if ( tokens[1] == mPassWord ) { | 1160 | if ( tokens[1] == mPassWord ) { |
1161 | //emit getFile( mSocket ); | 1161 | //emit getFile( mSocket ); |
1162 | blockRC = true; | 1162 | blockRC = true; |
1163 | get_file(); | 1163 | get_file(); |
1164 | } | 1164 | } |
1165 | else { | 1165 | else { |
1166 | KMessageBox::error( 0, i18n("Got receive file request\nwith invalid password")); | 1166 | KMessageBox::error( 0, i18n("Got receive file request\nwith invalid password")); |
1167 | //qDebug("password %s, invalid password %s ",mPassWord.latin1(), tokens[1].latin1() ); | 1167 | //qDebug("password %s, invalid password %s ",mPassWord.latin1(), tokens[1].latin1() ); |
1168 | } | 1168 | } |
1169 | } | 1169 | } |
1170 | if ( tokens[0] == "STOP" ) { | 1170 | if ( tokens[0] == "STOP" ) { |
1171 | //emit endConnect(); | 1171 | //emit endConnect(); |
1172 | end_connect(); | 1172 | end_connect(); |
1173 | } | 1173 | } |
1174 | } | 1174 | } |
1175 | } | 1175 | } |
1176 | void KServerSocket::end_connect() | 1176 | void KServerSocket::end_connect() |
1177 | { | 1177 | { |
1178 | delete mSyncActionDialog; | 1178 | delete mSyncActionDialog; |
1179 | mSyncActionDialog = 0; | 1179 | mSyncActionDialog = 0; |
1180 | } | 1180 | } |
1181 | void KServerSocket::send_file() | 1181 | void KServerSocket::send_file() |
1182 | { | 1182 | { |
1183 | //qDebug("MainWindow::sendFile(QSocket* s) "); | 1183 | //qDebug("MainWindow::sendFile(QSocket* s) "); |
1184 | if ( mSyncActionDialog ) | 1184 | if ( mSyncActionDialog ) |
1185 | delete mSyncActionDialog; | 1185 | delete mSyncActionDialog; |
1186 | mSyncActionDialog = new QDialog ( 0, "input-dialog", true ); | 1186 | mSyncActionDialog = new QDialog ( 0, "input-dialog", true ); |
1187 | mSyncActionDialog->setCaption(i18n("Received sync request")); | 1187 | mSyncActionDialog->setCaption(i18n("Received sync request")); |
1188 | QLabel* label = new QLabel( i18n("Synchronizing from remote ...\n\nDo not use this application!\n\nIf syncing fails\nyou can close this dialog."), mSyncActionDialog ); | 1188 | QLabel* label = new QLabel( i18n("Synchronizing from remote ...\n\nDo not use this application!\n\nIf syncing fails\nyou can close this dialog."), mSyncActionDialog ); |
1189 | label->setAlignment ( Qt::AlignHCenter ); | 1189 | label->setAlignment ( Qt::AlignHCenter ); |
1190 | QVBoxLayout* lay = new QVBoxLayout( mSyncActionDialog ); | 1190 | QVBoxLayout* lay = new QVBoxLayout( mSyncActionDialog ); |
1191 | lay->addWidget( label); | 1191 | lay->addWidget( label); |
1192 | lay->setMargin(7); | 1192 | lay->setMargin(7); |
1193 | lay->setSpacing(7); | 1193 | lay->setSpacing(7); |
1194 | if ( KSyncManager::mRequestedSyncEvent.isValid() ) { | 1194 | if ( KSyncManager::mRequestedSyncEvent.isValid() ) { |
1195 | int secs = QDateTime::currentDateTime().secsTo( KSyncManager::mRequestedSyncEvent ); | 1195 | int secs = QDateTime::currentDateTime().secsTo( KSyncManager::mRequestedSyncEvent ); |
1196 | if ( secs < 0 ) | 1196 | if ( secs < 0 ) |
1197 | secs = secs * (-1); | 1197 | secs = secs * (-1); |
1198 | if ( secs > 30 ) | 1198 | if ( secs > 30 ) |
1199 | //if ( true ) | 1199 | //if ( true ) |
1200 | { | 1200 | { |
1201 | QString warning = i18n("Clock skew of\nsyncing devices\nis %1 seconds!").arg( secs ); | 1201 | QString warning = i18n("Clock skew of\nsyncing devices\nis %1 seconds!").arg( secs ); |
1202 | QLabel* label = new QLabel( warning, mSyncActionDialog ); | 1202 | QLabel* label = new QLabel( warning, mSyncActionDialog ); |
1203 | label->setAlignment ( Qt::AlignHCenter ); | 1203 | label->setAlignment ( Qt::AlignHCenter ); |
1204 | lay->addWidget( label); | 1204 | lay->addWidget( label); |
1205 | if ( secs > 180 ) | 1205 | if ( secs > 180 ) |
1206 | { | 1206 | { |
1207 | if ( secs > 300 ) { | 1207 | if ( secs > 300 ) { |
1208 | if ( KMessageBox::Cancel == KMessageBox::warningContinueCancel(0, i18n("The clocks of the syncing\ndevices have a difference\n of more than 5 minutes.\nPlease adjust your clocks.\n<b>You may get wrong syncing results!<\b>\nPlease confirm synchronization!"), i18n("High clock skew!"),i18n("Synchronize!"))) { | 1208 | if ( KMessageBox::Cancel == KMessageBox::warningContinueCancel(0, i18n("The clocks of the syncing\ndevices have a difference\n of more than 5 minutes.\nPlease adjust your clocks.\n<b>You may get wrong syncing results!<\b>\nPlease confirm synchronization!"), i18n("High clock skew!"),i18n("Synchronize!"))) { |
1209 | qDebug("cancelled "); | 1209 | qDebug("cancelled "); |
1210 | return ; | 1210 | return ; |
1211 | } | 1211 | } |
1212 | } | 1212 | } |
1213 | QFont f = label->font(); | 1213 | QFont f = label->font(); |
1214 | f.setPointSize ( f.pointSize() *2 ); | 1214 | f.setPointSize ( f.pointSize() *2 ); |
1215 | f. setBold (true ); | 1215 | f. setBold (true ); |
1216 | QLabel* label = new QLabel( warning, mSyncActionDialog ); | 1216 | QLabel* label = new QLabel( warning, mSyncActionDialog ); |
1217 | label->setFont( f ); | 1217 | label->setFont( f ); |
1218 | warning = i18n("ADJUST\nYOUR\nCLOCKS!"); | 1218 | warning = i18n("ADJUST\nYOUR\nCLOCKS!"); |
1219 | label->setText( warning ); | 1219 | label->setText( warning ); |
1220 | label->setAlignment ( Qt::AlignHCenter ); | 1220 | label->setAlignment ( Qt::AlignHCenter ); |
1221 | lay->addWidget( label); | 1221 | lay->addWidget( label); |
1222 | mSyncActionDialog->setFixedSize( 230, 300); | 1222 | mSyncActionDialog->setFixedSize( 230, 300); |
1223 | } else { | 1223 | } else { |
1224 | mSyncActionDialog->setFixedSize( 230, 200); | 1224 | mSyncActionDialog->setFixedSize( 230, 200); |
1225 | } | 1225 | } |
1226 | } else { | 1226 | } else { |
1227 | mSyncActionDialog->setFixedSize( 230, 120); | 1227 | mSyncActionDialog->setFixedSize( 230, 120); |
1228 | } | 1228 | } |
1229 | } else | 1229 | } else |
1230 | mSyncActionDialog->setFixedSize( 230, 120); | 1230 | mSyncActionDialog->setFixedSize( 230, 120); |
1231 | mSyncActionDialog->show(); | 1231 | mSyncActionDialog->show(); |
1232 | mSyncActionDialog->raise(); | 1232 | mSyncActionDialog->raise(); |
1233 | emit request_file(); | 1233 | emit request_file(); |
1234 | qApp->processEvents(); | 1234 | qApp->processEvents(); |
1235 | QString fileName = mFileName; | 1235 | QString fileName = mFileName; |
1236 | QFile file( fileName ); | 1236 | QFile file( fileName ); |
1237 | if (!file.open( IO_ReadOnly ) ) { | 1237 | if (!file.open( IO_ReadOnly ) ) { |
1238 | delete mSyncActionDialog; | 1238 | delete mSyncActionDialog; |
1239 | mSyncActionDialog = 0; | 1239 | mSyncActionDialog = 0; |
1240 | qDebug("KSS::error open sync file: %s ", fileName.latin1()); | 1240 | qDebug("KSS::error open sync file: %s ", fileName.latin1()); |
1241 | mSocket->close(); | 1241 | mSocket->close(); |
1242 | if ( mSocket->state() == QSocket::Idle ) | 1242 | if ( mSocket->state() == QSocket::Idle ) |
1243 | QTimer::singleShot( 10, this , SLOT ( discardClient())); | 1243 | QTimer::singleShot( 10, this , SLOT ( discardClient())); |
1244 | return ; | 1244 | return ; |
1245 | 1245 | ||
1246 | } | 1246 | } |
1247 | mSyncActionDialog->setCaption( i18n("Sending file...") ); | 1247 | mSyncActionDialog->setCaption( i18n("Sending file...") ); |
1248 | QTextStream ts( &file ); | 1248 | QTextStream ts( &file ); |
1249 | ts.setEncoding( QTextStream::Latin1 ); | 1249 | ts.setEncoding( QTextStream::Latin1 ); |
1250 | 1250 | ||
1251 | QTextStream os( mSocket ); | 1251 | QTextStream os( mSocket ); |
1252 | os.setEncoding( QTextStream::Latin1 ); | 1252 | os.setEncoding( QTextStream::Latin1 ); |
1253 | while ( ! ts.atEnd() ) { | 1253 | while ( ! ts.atEnd() ) { |
1254 | os << ts.readLine() << "\r\n"; | 1254 | os << ts.readLine() << "\r\n"; |
1255 | } | 1255 | } |
1256 | //os << ts.read(); | 1256 | //os << ts.read(); |
1257 | file.close(); | 1257 | file.close(); |
1258 | mSyncActionDialog->setCaption( i18n("Waiting for synced file...") ); | 1258 | mSyncActionDialog->setCaption( i18n("Waiting for synced file...") ); |
1259 | mSocket->close(); | 1259 | mSocket->close(); |
1260 | if ( mSocket->state() == QSocket::Idle ) | 1260 | if ( mSocket->state() == QSocket::Idle ) |
1261 | QTimer::singleShot( 10, this , SLOT ( discardClient())); | 1261 | QTimer::singleShot( 10, this , SLOT ( discardClient())); |
1262 | } | 1262 | } |
1263 | void KServerSocket::get_file() | 1263 | void KServerSocket::get_file() |
1264 | { | 1264 | { |
1265 | mSyncActionDialog->setCaption( i18n("Receiving synced file...") ); | 1265 | mSyncActionDialog->setCaption( i18n("Receiving synced file...") ); |
1266 | 1266 | ||
1267 | piTime.start(); | 1267 | piTime.start(); |
1268 | piFileString = ""; | 1268 | piFileString = ""; |
1269 | QTimer::singleShot( 1, this , SLOT (readBackFileFromSocket( ) )); | 1269 | QTimer::singleShot( 1, this , SLOT (readBackFileFromSocket( ) )); |
1270 | } | 1270 | } |
1271 | 1271 | ||
1272 | 1272 | ||
1273 | void KServerSocket::readBackFileFromSocket() | 1273 | void KServerSocket::readBackFileFromSocket() |
1274 | { | 1274 | { |
1275 | //qDebug("readBackFileFromSocket() %d ", piTime.elapsed ()); | 1275 | //qDebug("readBackFileFromSocket() %d ", piTime.elapsed ()); |
1276 | while ( mSocket->canReadLine () ) { | 1276 | while ( mSocket->canReadLine () ) { |
1277 | piTime.restart(); | 1277 | piTime.restart(); |
1278 | QString line = mSocket->readLine (); | 1278 | QString line = mSocket->readLine (); |
1279 | piFileString += line; | 1279 | piFileString += line; |
1280 | //qDebug("readline: %s ", line.latin1()); | 1280 | //qDebug("readline: %s ", line.latin1()); |
1281 | mSyncActionDialog->setCaption( i18n("Received %1 bytes").arg( piFileString.length() ) ); | 1281 | mSyncActionDialog->setCaption( i18n("Received %1 bytes").arg( piFileString.length() ) ); |
1282 | 1282 | ||
1283 | } | 1283 | } |
1284 | if ( piTime.elapsed () < 3000 ) { | 1284 | if ( piTime.elapsed () < 3000 ) { |
1285 | // wait for more | 1285 | // wait for more |
1286 | //qDebug("waitformore "); | 1286 | //qDebug("waitformore "); |
1287 | QTimer::singleShot( 100, this , SLOT (readBackFileFromSocket( ) )); | 1287 | QTimer::singleShot( 100, this , SLOT (readBackFileFromSocket( ) )); |
1288 | return; | 1288 | return; |
1289 | } | 1289 | } |
1290 | QString fileName = mFileName; | 1290 | QString fileName = mFileName; |
1291 | QFile file ( fileName ); | 1291 | QFile file ( fileName ); |
1292 | if (!file.open( IO_WriteOnly ) ) { | 1292 | if (!file.open( IO_WriteOnly ) ) { |
1293 | delete mSyncActionDialog; | 1293 | delete mSyncActionDialog; |
1294 | mSyncActionDialog = 0; | 1294 | mSyncActionDialog = 0; |
1295 | qDebug("KSS:Error open read back file "); | 1295 | qDebug("KSS:Error open read back file "); |
1296 | piFileString = ""; | 1296 | piFileString = ""; |
1297 | emit file_received( false ); | 1297 | emit file_received( false ); |
1298 | blockRC = false; | 1298 | blockRC = false; |
1299 | return ; | 1299 | return ; |
1300 | 1300 | ||
1301 | } | 1301 | } |
1302 | 1302 | ||
1303 | // mView->setLoadedFileVersion(QDateTime::currentDateTime().addSecs( -1)); | 1303 | // mView->setLoadedFileVersion(QDateTime::currentDateTime().addSecs( -1)); |
1304 | QTextStream ts ( &file ); | 1304 | QTextStream ts ( &file ); |
1305 | ts.setEncoding( QTextStream::Latin1 ); | 1305 | ts.setEncoding( QTextStream::Latin1 ); |
1306 | mSyncActionDialog->setCaption( i18n("Writing file to disk...") ); | 1306 | mSyncActionDialog->setCaption( i18n("Writing file to disk...") ); |
1307 | ts << piFileString; | 1307 | ts << piFileString; |
1308 | mSocket->close(); | 1308 | mSocket->close(); |
1309 | if ( mSocket->state() == QSocket::Idle ) | 1309 | if ( mSocket->state() == QSocket::Idle ) |
1310 | QTimer::singleShot( 10, this , SLOT ( discardClient())); | 1310 | QTimer::singleShot( 10, this , SLOT ( discardClient())); |
1311 | file.close(); | 1311 | file.close(); |
1312 | piFileString = ""; | 1312 | piFileString = ""; |
1313 | emit file_received( true ); | 1313 | emit file_received( true ); |
1314 | delete mSyncActionDialog; | 1314 | delete mSyncActionDialog; |
1315 | mSyncActionDialog = 0; | 1315 | mSyncActionDialog = 0; |
1316 | blockRC = false; | 1316 | blockRC = false; |
1317 | 1317 | ||
1318 | } | 1318 | } |
1319 | 1319 | ||
1320 | KCommandSocket::KCommandSocket ( QString password, Q_UINT16 port, QString host, QObject * parent, const char * name ): QObject( parent, name ) | 1320 | KCommandSocket::KCommandSocket ( QString password, Q_UINT16 port, QString host, QObject * parent, const char * name ): QObject( parent, name ) |
1321 | { | 1321 | { |
1322 | mPassWord = password; | 1322 | mPassWord = password; |
1323 | mSocket = 0; | 1323 | mSocket = 0; |
1324 | mPort = port; | 1324 | mPort = port; |
1325 | mHost = host; | 1325 | mHost = host; |
1326 | 1326 | ||
1327 | mRetVal = quiet; | 1327 | mRetVal = quiet; |
1328 | mTimerSocket = new QTimer ( this ); | 1328 | mTimerSocket = new QTimer ( this ); |
1329 | connect( mTimerSocket, SIGNAL ( timeout () ), this, SLOT ( deleteSocket() ) ); | 1329 | connect( mTimerSocket, SIGNAL ( timeout () ), this, SLOT ( deleteSocket() ) ); |
1330 | } | 1330 | } |
1331 | void KCommandSocket::readFile( QString fn ) | 1331 | void KCommandSocket::readFile( QString fn ) |
1332 | { | 1332 | { |
1333 | if ( !mSocket ) { | 1333 | if ( !mSocket ) { |
1334 | mSocket = new QSocket( this ); | 1334 | mSocket = new QSocket( this ); |
1335 | connect( mSocket, SIGNAL(readyRead()), this, SLOT(startReadFileFromSocket()) ); | 1335 | connect( mSocket, SIGNAL(readyRead()), this, SLOT(startReadFileFromSocket()) ); |
1336 | connect( mSocket, SIGNAL(delayedCloseFinished ()), this, SLOT(deleteSocket()) ); | 1336 | connect( mSocket, SIGNAL(delayedCloseFinished ()), this, SLOT(deleteSocket()) ); |
1337 | } | 1337 | } |
1338 | mFileString = ""; | 1338 | mFileString = ""; |
1339 | mFileName = fn; | 1339 | mFileName = fn; |
1340 | mFirst = true; | 1340 | mFirst = true; |
1341 | mSocket->connectToHost( mHost, mPort ); | 1341 | mSocket->connectToHost( mHost, mPort ); |
1342 | QTextStream os( mSocket ); | 1342 | QTextStream os( mSocket ); |
1343 | os.setEncoding( QTextStream::Latin1 ); | 1343 | os.setEncoding( QTextStream::Latin1 ); |
1344 | 1344 | ||
1345 | QString curDt = " " +KGlobal::locale()->formatDateTime(QDateTime::currentDateTime().addSecs(-1),true, true,KLocale::ISODate ); | 1345 | QString curDt = " " +KGlobal::locale()->formatDateTime(QDateTime::currentDateTime().addSecs(-1),true, true,KLocale::ISODate ); |
1346 | os << "GET " << mPassWord << curDt <<"\r\n"; | 1346 | os << "GET " << mPassWord << curDt <<"\r\n"; |
1347 | mTimerSocket->start( 20000 ); | 1347 | mTimerSocket->start( 300000 ); |
1348 | } | 1348 | } |
1349 | 1349 | ||
1350 | void KCommandSocket::writeFile( QString fileName ) | 1350 | void KCommandSocket::writeFile( QString fileName ) |
1351 | { | 1351 | { |
1352 | if ( !mSocket ) { | 1352 | if ( !mSocket ) { |
1353 | mSocket = new QSocket( this ); | 1353 | mSocket = new QSocket( this ); |
1354 | connect( mSocket, SIGNAL(delayedCloseFinished ()), this, SLOT(deleteSocket()) ); | 1354 | connect( mSocket, SIGNAL(delayedCloseFinished ()), this, SLOT(deleteSocket()) ); |
1355 | connect( mSocket, SIGNAL(connected ()), this, SLOT(writeFileToSocket()) ); | 1355 | connect( mSocket, SIGNAL(connected ()), this, SLOT(writeFileToSocket()) ); |
1356 | } | 1356 | } |
1357 | mFileName = fileName ; | 1357 | mFileName = fileName ; |
1358 | mSocket->connectToHost( mHost, mPort ); | 1358 | mSocket->connectToHost( mHost, mPort ); |
1359 | } | 1359 | } |
1360 | void KCommandSocket::writeFileToSocket() | 1360 | void KCommandSocket::writeFileToSocket() |
1361 | { | 1361 | { |
1362 | QFile file2( mFileName ); | 1362 | QFile file2( mFileName ); |
1363 | if (!file2.open( IO_ReadOnly ) ) { | 1363 | if (!file2.open( IO_ReadOnly ) ) { |
1364 | mRetVal= errorW; | 1364 | mRetVal= errorW; |
1365 | mSocket->close(); | 1365 | mSocket->close(); |
1366 | if ( mSocket->state() == QSocket::Idle ) | 1366 | if ( mSocket->state() == QSocket::Idle ) |
1367 | QTimer::singleShot( 10, this , SLOT ( deleteSocket())); | 1367 | QTimer::singleShot( 10, this , SLOT ( deleteSocket())); |
1368 | return ; | 1368 | return ; |
1369 | } | 1369 | } |
1370 | QTextStream ts2( &file2 ); | 1370 | QTextStream ts2( &file2 ); |
1371 | ts2.setEncoding( QTextStream::Latin1 ); | 1371 | ts2.setEncoding( QTextStream::Latin1 ); |
1372 | QTextStream os2( mSocket ); | 1372 | QTextStream os2( mSocket ); |
1373 | os2.setEncoding( QTextStream::Latin1 ); | 1373 | os2.setEncoding( QTextStream::Latin1 ); |
1374 | os2 << "PUT " << mPassWord << "\r\n";; | 1374 | os2 << "PUT " << mPassWord << "\r\n";; |
1375 | while ( ! ts2.atEnd() ) { | 1375 | while ( ! ts2.atEnd() ) { |
1376 | os2 << ts2.readLine() << "\r\n"; | 1376 | os2 << ts2.readLine() << "\r\n"; |
1377 | } | 1377 | } |
1378 | mRetVal= successW; | 1378 | mRetVal= successW; |
1379 | file2.close(); | 1379 | file2.close(); |
1380 | mSocket->close(); | 1380 | mSocket->close(); |
1381 | if ( mSocket->state() == QSocket::Idle ) | 1381 | if ( mSocket->state() == QSocket::Idle ) |
1382 | QTimer::singleShot( 10, this , SLOT ( deleteSocket())); | 1382 | QTimer::singleShot( 10, this , SLOT ( deleteSocket())); |
1383 | } | 1383 | } |
1384 | void KCommandSocket::sendStop() | 1384 | void KCommandSocket::sendStop() |
1385 | { | 1385 | { |
1386 | if ( !mSocket ) { | 1386 | if ( !mSocket ) { |
1387 | mSocket = new QSocket( this ); | 1387 | mSocket = new QSocket( this ); |
1388 | connect( mSocket, SIGNAL(delayedCloseFinished ()), this, SLOT(deleteSocket()) ); | 1388 | connect( mSocket, SIGNAL(delayedCloseFinished ()), this, SLOT(deleteSocket()) ); |
1389 | } | 1389 | } |
1390 | mSocket->connectToHost( mHost, mPort ); | 1390 | mSocket->connectToHost( mHost, mPort ); |
1391 | QTextStream os2( mSocket ); | 1391 | QTextStream os2( mSocket ); |
1392 | os2.setEncoding( QTextStream::Latin1 ); | 1392 | os2.setEncoding( QTextStream::Latin1 ); |
1393 | os2 << "STOP\r\n"; | 1393 | os2 << "STOP\r\n"; |
1394 | mSocket->close(); | 1394 | mSocket->close(); |
1395 | if ( mSocket->state() == QSocket::Idle ) | 1395 | if ( mSocket->state() == QSocket::Idle ) |
1396 | QTimer::singleShot( 10, this , SLOT ( deleteSocket())); | 1396 | QTimer::singleShot( 10, this , SLOT ( deleteSocket())); |
1397 | } | 1397 | } |
1398 | 1398 | ||
1399 | void KCommandSocket::startReadFileFromSocket() | 1399 | void KCommandSocket::startReadFileFromSocket() |
1400 | { | 1400 | { |
1401 | if ( ! mFirst ) | 1401 | if ( ! mFirst ) |
1402 | return; | 1402 | return; |
1403 | mFirst = false; | 1403 | mFirst = false; |
1404 | mTimerSocket->stop(); | 1404 | mTimerSocket->stop(); |
1405 | mFileString = ""; | 1405 | mFileString = ""; |
1406 | mTime.start(); | 1406 | mTime.start(); |
1407 | QTimer::singleShot( 1, this , SLOT (readFileFromSocket( ) )); | 1407 | QTimer::singleShot( 1, this , SLOT (readFileFromSocket( ) )); |
1408 | 1408 | ||
1409 | } | 1409 | } |
1410 | void KCommandSocket::readFileFromSocket() | 1410 | void KCommandSocket::readFileFromSocket() |
1411 | { | 1411 | { |
1412 | //qDebug("readBackFileFromSocket() %d ", mTime.elapsed ()); | 1412 | //qDebug("readBackFileFromSocket() %d ", mTime.elapsed ()); |
1413 | while ( mSocket->canReadLine () ) { | 1413 | while ( mSocket->canReadLine () ) { |
1414 | mTime.restart(); | 1414 | mTime.restart(); |
1415 | QString line = mSocket->readLine (); | 1415 | QString line = mSocket->readLine (); |
1416 | mFileString += line; | 1416 | mFileString += line; |
1417 | //qDebug("readline: %s ", line.latin1()); | 1417 | //qDebug("readline: %s ", line.latin1()); |
1418 | } | 1418 | } |
1419 | if ( mTime.elapsed () < 3000 ) { | 1419 | if ( mTime.elapsed () < 3000 ) { |
1420 | // wait for more | 1420 | // wait for more |
1421 | //qDebug("waitformore "); | 1421 | //qDebug("waitformore "); |
1422 | QTimer::singleShot( 100, this , SLOT (readFileFromSocket( ) )); | 1422 | QTimer::singleShot( 100, this , SLOT (readFileFromSocket( ) )); |
1423 | return; | 1423 | return; |
1424 | } | 1424 | } |
1425 | QString fileName = mFileName; | 1425 | QString fileName = mFileName; |
1426 | QFile file ( fileName ); | 1426 | QFile file ( fileName ); |
1427 | if (!file.open( IO_WriteOnly ) ) { | 1427 | if (!file.open( IO_WriteOnly ) ) { |
1428 | mFileString = ""; | 1428 | mFileString = ""; |
1429 | mRetVal = errorR; | 1429 | mRetVal = errorR; |
1430 | qDebug("KSS:Error open temp sync file for writing: %s",fileName.latin1() ); | 1430 | qDebug("KSS:Error open temp sync file for writing: %s",fileName.latin1() ); |
1431 | deleteSocket(); | 1431 | deleteSocket(); |
1432 | return ; | 1432 | return ; |
1433 | 1433 | ||
1434 | } | 1434 | } |
1435 | // mView->setLoadedFileVersion(QDateTime::currentDateTime().addSecs( -1)); | 1435 | // mView->setLoadedFileVersion(QDateTime::currentDateTime().addSecs( -1)); |
1436 | QTextStream ts ( &file ); | 1436 | QTextStream ts ( &file ); |
1437 | ts.setEncoding( QTextStream::Latin1 ); | 1437 | ts.setEncoding( QTextStream::Latin1 ); |
1438 | ts << mFileString; | 1438 | ts << mFileString; |
1439 | file.close(); | 1439 | file.close(); |
1440 | mFileString = ""; | 1440 | mFileString = ""; |
1441 | mRetVal = successR; | 1441 | mRetVal = successR; |
1442 | mSocket->close(); | 1442 | mSocket->close(); |
1443 | // if state is not idle, deleteSocket(); is called via | 1443 | // if state is not idle, deleteSocket(); is called via |
1444 | // connect( mSocket, SIGNAL(delayedCloseFinished ()), this, SLOT(deleteSocket()) ); | 1444 | // connect( mSocket, SIGNAL(delayedCloseFinished ()), this, SLOT(deleteSocket()) ); |
1445 | if ( mSocket->state() == QSocket::Idle ) | 1445 | if ( mSocket->state() == QSocket::Idle ) |
1446 | deleteSocket(); | 1446 | deleteSocket(); |
1447 | } | 1447 | } |
1448 | 1448 | ||
1449 | void KCommandSocket::deleteSocket() | 1449 | void KCommandSocket::deleteSocket() |
1450 | { | 1450 | { |
1451 | //qDebug("KCommandSocket::deleteSocket() "); | 1451 | //qDebug("KCommandSocket::deleteSocket() "); |
1452 | if ( mTimerSocket->isActive () ) { | 1452 | if ( mTimerSocket->isActive () ) { |
1453 | mTimerSocket->stop(); | 1453 | mTimerSocket->stop(); |
1454 | mRetVal = errorTO; | 1454 | mRetVal = errorTO; |
1455 | qDebug("Connection to remote host timed out"); | 1455 | qDebug("Connection to remote host timed out"); |
1456 | if ( mSocket ) { | 1456 | if ( mSocket ) { |
1457 | mSocket->close(); | 1457 | mSocket->close(); |
1458 | //if ( mSocket->state() == QSocket::Idle ) | 1458 | //if ( mSocket->state() == QSocket::Idle ) |
1459 | // deleteSocket(); | 1459 | // deleteSocket(); |
1460 | delete mSocket; | 1460 | delete mSocket; |
1461 | mSocket = 0; | 1461 | mSocket = 0; |
1462 | } | 1462 | } |
1463 | KMessageBox::error( 0, i18n("Connection to remote\nhost timed out!\nDid you forgot to enable\nsyncing on remote host? ")); | 1463 | KMessageBox::error( 0, i18n("Connection to remote\nhost timed out!\nDid you forgot to enable\nsyncing on remote host? ")); |
1464 | emit commandFinished( this, mRetVal ); | 1464 | emit commandFinished( this, mRetVal ); |
1465 | return; | 1465 | return; |
1466 | } | 1466 | } |
1467 | //qDebug("KCommandSocket::deleteSocket() %d", mRetVal ); | 1467 | //qDebug("KCommandSocket::deleteSocket() %d", mRetVal ); |
1468 | if ( mSocket) | 1468 | if ( mSocket) |
1469 | delete mSocket; | 1469 | delete mSocket; |
1470 | mSocket = 0; | 1470 | mSocket = 0; |
1471 | emit commandFinished( this, mRetVal ); | 1471 | emit commandFinished( this, mRetVal ); |
1472 | } | 1472 | } |