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