-rw-r--r-- | libkdepim/ksyncmanager.cpp | 16 |
1 files changed, 14 insertions, 2 deletions
diff --git a/libkdepim/ksyncmanager.cpp b/libkdepim/ksyncmanager.cpp index feb184b..e09050e 100644 --- a/libkdepim/ksyncmanager.cpp +++ b/libkdepim/ksyncmanager.cpp | |||
@@ -1,441 +1,444 @@ | |||
1 | /* | 1 | /* |
2 | This file is part of KDE-Pim/Pi. | 2 | This file is part of KDE-Pim/Pi. |
3 | Copyright (c) 2004 Ulf Schenk | 3 | Copyright (c) 2004 Ulf Schenk |
4 | 4 | ||
5 | This library is free software; you can redistribute it and/or | 5 | This library is free software; you can redistribute it and/or |
6 | modify it under the terms of the GNU Library General Public | 6 | modify it under the terms of the GNU Library General Public |
7 | License as published by the Free Software Foundation; either | 7 | License as published by the Free Software Foundation; either |
8 | version 2 of the License, or (at your option) any later version. | 8 | version 2 of the License, or (at your option) any later version. |
9 | 9 | ||
10 | This library is distributed in the hope that it will be useful, | 10 | This library is distributed in the hope that it will be useful, |
11 | but WITHOUT ANY WARRANTY; without even the implied warranty of | 11 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
13 | Library General Public License for more details. | 13 | Library General Public License for more details. |
14 | 14 | ||
15 | You should have received a copy of the GNU Library General Public License | 15 | You should have received a copy of the GNU Library General Public License |
16 | along with this library; see the file COPYING.LIB. If not, write to | 16 | along with this library; see the file COPYING.LIB. If not, write to |
17 | the Free Software Foundation, Inc., 59 Temple Place - Suite 330, | 17 | the Free Software Foundation, Inc., 59 Temple Place - Suite 330, |
18 | Boston, MA 02111-1307, USA. | 18 | Boston, MA 02111-1307, USA. |
19 | */ | 19 | */ |
20 | 20 | ||
21 | // $Id$ | 21 | // $Id$ |
22 | 22 | ||
23 | #include "ksyncmanager.h" | 23 | #include "ksyncmanager.h" |
24 | 24 | ||
25 | #include <stdlib.h> | 25 | #include <stdlib.h> |
26 | 26 | ||
27 | #ifndef _WIN32_ | 27 | #ifndef _WIN32_ |
28 | #include <unistd.h> | 28 | #include <unistd.h> |
29 | #endif | 29 | #endif |
30 | 30 | ||
31 | 31 | ||
32 | #include "ksyncprofile.h" | 32 | #include "ksyncprofile.h" |
33 | #include "ksyncprefsdialog.h" | 33 | #include "ksyncprefsdialog.h" |
34 | #include "kpimprefs.h" | 34 | #include "kpimprefs.h" |
35 | #include <kmessagebox.h> | 35 | #include <kmessagebox.h> |
36 | 36 | ||
37 | #include <qdir.h> | 37 | #include <qdir.h> |
38 | #include <qprogressbar.h> | 38 | #include <qprogressbar.h> |
39 | #include <qpopupmenu.h> | 39 | #include <qpopupmenu.h> |
40 | #include <qpushbutton.h> | 40 | #include <qpushbutton.h> |
41 | #include <qradiobutton.h> | 41 | #include <qradiobutton.h> |
42 | #include <qbuttongroup.h> | 42 | #include <qbuttongroup.h> |
43 | #include <qtimer.h> | 43 | #include <qtimer.h> |
44 | #include <qmessagebox.h> | 44 | #include <qmessagebox.h> |
45 | #include <qapplication.h> | 45 | #include <qapplication.h> |
46 | #include <qlineedit.h> | 46 | #include <qlineedit.h> |
47 | #include <qdialog.h> | 47 | #include <qdialog.h> |
48 | #include <qlayout.h> | 48 | #include <qlayout.h> |
49 | #include <qtextcodec.h> | 49 | #include <qtextcodec.h> |
50 | #include <qlabel.h> | 50 | #include <qlabel.h> |
51 | #include <qcheckbox.h> | 51 | #include <qcheckbox.h> |
52 | 52 | ||
53 | #include <klocale.h> | 53 | #include <klocale.h> |
54 | #include <kglobal.h> | 54 | #include <kglobal.h> |
55 | #include <kconfig.h> | 55 | #include <kconfig.h> |
56 | #include <kfiledialog.h> | 56 | #include <kfiledialog.h> |
57 | 57 | ||
58 | QDateTime KSyncManager::mRequestedSyncEvent; | ||
59 | |||
60 | |||
58 | KSyncManager::KSyncManager(QWidget* parent, KSyncInterface* implementation, TargetApp ta, KPimPrefs* prefs, QPopupMenu* syncmenu) | 61 | KSyncManager::KSyncManager(QWidget* parent, KSyncInterface* implementation, TargetApp ta, KPimPrefs* prefs, QPopupMenu* syncmenu) |
59 | : QObject(), mParent(parent), mImplementation(implementation), mTargetApp(ta), mPrefs(prefs ),mSyncMenu(syncmenu) | 62 | : QObject(), mParent(parent), mImplementation(implementation), mTargetApp(ta), mPrefs(prefs ),mSyncMenu(syncmenu) |
60 | { | 63 | { |
61 | mServerSocket = 0; | 64 | mServerSocket = 0; |
62 | bar = new QProgressBar ( 1, 0 ); | 65 | bar = new QProgressBar ( 1, 0 ); |
63 | bar->setCaption (""); | 66 | bar->setCaption (""); |
64 | 67 | ||
65 | int w = 300; | 68 | int w = 300; |
66 | if ( QApplication::desktop()->width() < 320 ) | 69 | if ( QApplication::desktop()->width() < 320 ) |
67 | w = 220; | 70 | w = 220; |
68 | int h = bar->sizeHint().height() ; | 71 | int h = bar->sizeHint().height() ; |
69 | int dw = QApplication::desktop()->width(); | 72 | int dw = QApplication::desktop()->width(); |
70 | int dh = QApplication::desktop()->height(); | 73 | int dh = QApplication::desktop()->height(); |
71 | bar->setGeometry( (dw-w)/2, (dh - h )/2 ,w,h ); | 74 | bar->setGeometry( (dw-w)/2, (dh - h )/2 ,w,h ); |
72 | if ( mPrefs->mPassiveSyncAutoStart ) | 75 | if ( mPrefs->mPassiveSyncAutoStart ) |
73 | enableQuick( false ); | 76 | enableQuick( false ); |
74 | 77 | ||
75 | } | 78 | } |
76 | 79 | ||
77 | KSyncManager::~KSyncManager() | 80 | KSyncManager::~KSyncManager() |
78 | { | 81 | { |
79 | delete bar; | 82 | delete bar; |
80 | } | 83 | } |
81 | 84 | ||
82 | 85 | ||
83 | void KSyncManager::fillSyncMenu() | 86 | void KSyncManager::fillSyncMenu() |
84 | { | 87 | { |
85 | if ( mSyncMenu->count() ) | 88 | if ( mSyncMenu->count() ) |
86 | mSyncMenu->clear(); | 89 | mSyncMenu->clear(); |
87 | 90 | ||
88 | mSyncMenu->insertItem( i18n("Configure..."), 0 ); | 91 | mSyncMenu->insertItem( i18n("Configure..."), 0 ); |
89 | mSyncMenu->insertSeparator(); | 92 | mSyncMenu->insertSeparator(); |
90 | QPopupMenu *clearMenu = new QPopupMenu ( mSyncMenu ); | 93 | QPopupMenu *clearMenu = new QPopupMenu ( mSyncMenu ); |
91 | mSyncMenu->insertItem( i18n("Remove sync info"),clearMenu, 5000 ); | 94 | mSyncMenu->insertItem( i18n("Remove sync info"),clearMenu, 5000 ); |
92 | clearMenu->insertItem( i18n("For all profiles"), 1 ); | 95 | clearMenu->insertItem( i18n("For all profiles"), 1 ); |
93 | clearMenu->insertSeparator(); | 96 | clearMenu->insertSeparator(); |
94 | connect ( clearMenu, SIGNAL( activated ( int ) ), this, SLOT (slotClearMenu( int ) ) ); | 97 | connect ( clearMenu, SIGNAL( activated ( int ) ), this, SLOT (slotClearMenu( int ) ) ); |
95 | mSyncMenu->insertSeparator(); | 98 | mSyncMenu->insertSeparator(); |
96 | if ( mServerSocket == 0 ) { | 99 | if ( mServerSocket == 0 ) { |
97 | mSyncMenu->insertItem( i18n("Enable Pi-Sync"), 2 ); | 100 | mSyncMenu->insertItem( i18n("Enable Pi-Sync"), 2 ); |
98 | } else { | 101 | } else { |
99 | mSyncMenu->insertItem( i18n("Disable Pi-Sync"), 3 ); | 102 | mSyncMenu->insertItem( i18n("Disable Pi-Sync"), 3 ); |
100 | } | 103 | } |
101 | mSyncMenu->insertSeparator(); | 104 | mSyncMenu->insertSeparator(); |
102 | mSyncMenu->insertItem( i18n("Multiple sync"), 1 ); | 105 | mSyncMenu->insertItem( i18n("Multiple sync"), 1 ); |
103 | mSyncMenu->insertSeparator(); | 106 | mSyncMenu->insertSeparator(); |
104 | KConfig config ( locateLocal( "config","ksyncprofilesrc" ) ); | 107 | KConfig config ( locateLocal( "config","ksyncprofilesrc" ) ); |
105 | config.setGroup("General"); | 108 | config.setGroup("General"); |
106 | QStringList prof = config.readListEntry("SyncProfileNames"); | 109 | QStringList prof = config.readListEntry("SyncProfileNames"); |
107 | mLocalMachineName = config.readEntry("LocalMachineName","undefined"); | 110 | mLocalMachineName = config.readEntry("LocalMachineName","undefined"); |
108 | if ( prof.count() < 2 ) { | 111 | if ( prof.count() < 2 ) { |
109 | prof.clear(); | 112 | prof.clear(); |
110 | QString externalName; | 113 | QString externalName; |
111 | #ifdef DESKTOP_VERSION | 114 | #ifdef DESKTOP_VERSION |
112 | #ifdef _WIN32_ | 115 | #ifdef _WIN32_ |
113 | externalName = "OutLook(not_implemented)"; | 116 | externalName = "OutLook(not_implemented)"; |
114 | #else | 117 | #else |
115 | externalName = "KDE_Desktop"; | 118 | externalName = "KDE_Desktop"; |
116 | #endif | 119 | #endif |
117 | #else | 120 | #else |
118 | externalName = "Sharp_DTM"; | 121 | externalName = "Sharp_DTM"; |
119 | #endif | 122 | #endif |
120 | prof << externalName; | 123 | prof << externalName; |
121 | prof << i18n("Local_file"); | 124 | prof << i18n("Local_file"); |
122 | prof << i18n("Last_file"); | 125 | prof << i18n("Last_file"); |
123 | KSyncProfile* temp = new KSyncProfile (); | 126 | KSyncProfile* temp = new KSyncProfile (); |
124 | temp->setName( prof[0] ); | 127 | temp->setName( prof[0] ); |
125 | temp->writeConfig(&config); | 128 | temp->writeConfig(&config); |
126 | temp->setName( prof[1] ); | 129 | temp->setName( prof[1] ); |
127 | temp->writeConfig(&config); | 130 | temp->writeConfig(&config); |
128 | temp->setName( prof[2] ); | 131 | temp->setName( prof[2] ); |
129 | temp->writeConfig(&config); | 132 | temp->writeConfig(&config); |
130 | config.setGroup("General"); | 133 | config.setGroup("General"); |
131 | config.writeEntry("SyncProfileNames",prof); | 134 | config.writeEntry("SyncProfileNames",prof); |
132 | config.writeEntry("ExternSyncProfiles",externalName); | 135 | config.writeEntry("ExternSyncProfiles",externalName); |
133 | config.sync(); | 136 | config.sync(); |
134 | delete temp; | 137 | delete temp; |
135 | } | 138 | } |
136 | mExternSyncProfiles = config.readListEntry("ExternSyncProfiles"); | 139 | mExternSyncProfiles = config.readListEntry("ExternSyncProfiles"); |
137 | mSyncProfileNames = prof; | 140 | mSyncProfileNames = prof; |
138 | unsigned int i; | 141 | unsigned int i; |
139 | for ( i = 0; i < prof.count(); ++i ) { | 142 | for ( i = 0; i < prof.count(); ++i ) { |
140 | mSyncMenu->insertItem( prof[i], 1000+i ); | 143 | mSyncMenu->insertItem( prof[i], 1000+i ); |
141 | clearMenu->insertItem( prof[i], 1000+i ); | 144 | clearMenu->insertItem( prof[i], 1000+i ); |
142 | if ( i == 2 ) | 145 | if ( i == 2 ) |
143 | mSyncMenu->insertSeparator(); | 146 | mSyncMenu->insertSeparator(); |
144 | } | 147 | } |
145 | QDir app_dir; | 148 | QDir app_dir; |
146 | //US do not display SharpDTM if app is pwmpi, or no sharpfiles available | 149 | //US do not display SharpDTM if app is pwmpi, or no sharpfiles available |
147 | if ( mTargetApp == PWMPI) { | 150 | if ( mTargetApp == PWMPI) { |
148 | mSyncMenu->removeItem( 1000 ); | 151 | mSyncMenu->removeItem( 1000 ); |
149 | clearMenu->removeItem( 1000 ); | 152 | clearMenu->removeItem( 1000 ); |
150 | } | 153 | } |
151 | #ifndef DESKTOP_VERSION | 154 | #ifndef DESKTOP_VERSION |
152 | else if (!app_dir.exists(QDir::homeDirPath()+"/Applications/dtm" ) ) { | 155 | else if (!app_dir.exists(QDir::homeDirPath()+"/Applications/dtm" ) ) { |
153 | mSyncMenu->removeItem( 1000 ); | 156 | mSyncMenu->removeItem( 1000 ); |
154 | clearMenu->removeItem( 1000 ); | 157 | clearMenu->removeItem( 1000 ); |
155 | } | 158 | } |
156 | #endif | 159 | #endif |
157 | mSyncMenu->removeItem( 1002 ); | 160 | mSyncMenu->removeItem( 1002 ); |
158 | clearMenu->removeItem( 1002 ); | 161 | clearMenu->removeItem( 1002 ); |
159 | } | 162 | } |
160 | void KSyncManager::slotClearMenu( int action ) | 163 | void KSyncManager::slotClearMenu( int action ) |
161 | { | 164 | { |
162 | QString syncDevice; | 165 | QString syncDevice; |
163 | if ( action > 999 ) { | 166 | if ( action > 999 ) { |
164 | syncDevice = mSyncProfileNames[action - 1000] ; | 167 | syncDevice = mSyncProfileNames[action - 1000] ; |
165 | } | 168 | } |
166 | 169 | ||
167 | 170 | ||
168 | 171 | ||
169 | int result = 0; | 172 | int result = 0; |
170 | QString sd; | 173 | QString sd; |
171 | if ( syncDevice.isEmpty() ) | 174 | if ( syncDevice.isEmpty() ) |
172 | sd = i18n("Do you want to\nclear all sync info\nof all profiles?"); | 175 | sd = i18n("Do you want to\nclear all sync info\nof all profiles?"); |
173 | else | 176 | else |
174 | sd = i18n("Do you want to\nclear the sync\ninfo of profile\n%1?\n"). arg( syncDevice ); | 177 | sd = i18n("Do you want to\nclear the sync\ninfo of profile\n%1?\n"). arg( syncDevice ); |
175 | 178 | ||
176 | result = QMessageBox::warning( mParent, i18n("Warning!"),sd,i18n("OK"), i18n("Cancel"), 0, | 179 | result = QMessageBox::warning( mParent, i18n("Warning!"),sd,i18n("OK"), i18n("Cancel"), 0, |
177 | 0, 1 ); | 180 | 0, 1 ); |
178 | if ( result ) | 181 | if ( result ) |
179 | return; | 182 | return; |
180 | mImplementation->removeSyncInfo( syncDevice ); | 183 | mImplementation->removeSyncInfo( syncDevice ); |
181 | } | 184 | } |
182 | void KSyncManager::slotSyncMenu( int action ) | 185 | void KSyncManager::slotSyncMenu( int action ) |
183 | { | 186 | { |
184 | qDebug("syncaction %d ", action); | 187 | qDebug("syncaction %d ", action); |
185 | if ( action == 5000 ) | 188 | if ( action == 5000 ) |
186 | return; | 189 | return; |
187 | if ( action == 0 ) { | 190 | if ( action == 0 ) { |
188 | 191 | ||
189 | // seems to be a Qt2 event handling bug | 192 | // seems to be a Qt2 event handling bug |
190 | // syncmenu.clear causes a segfault at first time | 193 | // syncmenu.clear causes a segfault at first time |
191 | // when we call it after the main event loop, it is ok | 194 | // when we call it after the main event loop, it is ok |
192 | // same behaviour when calling OM/Pi via QCOP for the first time | 195 | // same behaviour when calling OM/Pi via QCOP for the first time |
193 | QTimer::singleShot ( 1, this, SLOT ( confSync() ) ); | 196 | QTimer::singleShot ( 1, this, SLOT ( confSync() ) ); |
194 | //confSync(); | 197 | //confSync(); |
195 | 198 | ||
196 | return; | 199 | return; |
197 | } | 200 | } |
198 | if ( action == 1 ) { | 201 | if ( action == 1 ) { |
199 | multiSync( true ); | 202 | multiSync( true ); |
200 | return; | 203 | return; |
201 | } | 204 | } |
202 | if ( action == 2 ) { | 205 | if ( action == 2 ) { |
203 | enableQuick(); | 206 | enableQuick(); |
204 | QTimer::singleShot ( 1, this, SLOT ( fillSyncMenu() ) ); | 207 | QTimer::singleShot ( 1, this, SLOT ( fillSyncMenu() ) ); |
205 | return; | 208 | return; |
206 | } | 209 | } |
207 | if ( action == 3 ) { | 210 | if ( action == 3 ) { |
208 | delete mServerSocket; | 211 | delete mServerSocket; |
209 | mServerSocket = 0; | 212 | mServerSocket = 0; |
210 | QTimer::singleShot ( 1, this, SLOT ( fillSyncMenu() ) ); | 213 | QTimer::singleShot ( 1, this, SLOT ( fillSyncMenu() ) ); |
211 | return; | 214 | return; |
212 | } | 215 | } |
213 | 216 | ||
214 | if (blockSave()) | 217 | if (blockSave()) |
215 | return; | 218 | return; |
216 | 219 | ||
217 | setBlockSave(true); | 220 | setBlockSave(true); |
218 | bool silent = false; | 221 | bool silent = false; |
219 | if ( action == 999 ) { | 222 | if ( action == 999 ) { |
220 | //special mode for silent syncing | 223 | //special mode for silent syncing |
221 | action = 1000; | 224 | action = 1000; |
222 | silent = true; | 225 | silent = true; |
223 | } | 226 | } |
224 | 227 | ||
225 | mCurrentSyncProfile = action - 1000 ; | 228 | mCurrentSyncProfile = action - 1000 ; |
226 | mCurrentSyncDevice = mSyncProfileNames[mCurrentSyncProfile] ; | 229 | mCurrentSyncDevice = mSyncProfileNames[mCurrentSyncProfile] ; |
227 | mCurrentSyncName = mLocalMachineName ; | 230 | mCurrentSyncName = mLocalMachineName ; |
228 | KConfig config ( locateLocal( "config","ksyncprofilesrc" ) ); | 231 | KConfig config ( locateLocal( "config","ksyncprofilesrc" ) ); |
229 | KSyncProfile* temp = new KSyncProfile (); | 232 | KSyncProfile* temp = new KSyncProfile (); |
230 | temp->setName(mSyncProfileNames[mCurrentSyncProfile]); | 233 | temp->setName(mSyncProfileNames[mCurrentSyncProfile]); |
231 | temp->readConfig(&config); | 234 | temp->readConfig(&config); |
232 | if (silent) { | 235 | if (silent) { |
233 | mAskForPreferences = false; | 236 | mAskForPreferences = false; |
234 | mShowSyncSummary = false; | 237 | mShowSyncSummary = false; |
235 | mWriteBackFile = true; | 238 | mWriteBackFile = true; |
236 | mSyncAlgoPrefs = 2;// take newest | 239 | mSyncAlgoPrefs = 2;// take newest |
237 | } | 240 | } |
238 | else { | 241 | else { |
239 | mAskForPreferences = temp->getAskForPreferences(); | 242 | mAskForPreferences = temp->getAskForPreferences(); |
240 | mShowSyncSummary = temp->getShowSummaryAfterSync(); | 243 | mShowSyncSummary = temp->getShowSummaryAfterSync(); |
241 | mWriteBackFile = temp->getWriteBackFile(); | 244 | mWriteBackFile = temp->getWriteBackFile(); |
242 | mSyncAlgoPrefs = temp->getSyncPrefs(); | 245 | mSyncAlgoPrefs = temp->getSyncPrefs(); |
243 | } | 246 | } |
244 | mWriteBackExistingOnly = temp->getWriteBackExisting(); | 247 | mWriteBackExistingOnly = temp->getWriteBackExisting(); |
245 | mIsKapiFile = temp->getIsKapiFile(); | 248 | mIsKapiFile = temp->getIsKapiFile(); |
246 | mWriteBackInFuture = 0; | 249 | mWriteBackInFuture = 0; |
247 | if ( temp->getWriteBackFuture() ) | 250 | if ( temp->getWriteBackFuture() ) |
248 | mWriteBackInFuture = temp->getWriteBackFutureWeeks( ); | 251 | mWriteBackInFuture = temp->getWriteBackFutureWeeks( ); |
249 | 252 | ||
250 | if ( action == 1000 ) { | 253 | if ( action == 1000 ) { |
251 | #ifdef DESKTOP_VERSION | 254 | #ifdef DESKTOP_VERSION |
252 | syncKDE(); | 255 | syncKDE(); |
253 | #else | 256 | #else |
254 | syncSharp(); | 257 | syncSharp(); |
255 | #endif | 258 | #endif |
256 | 259 | ||
257 | } else if ( action == 1001 ) { | 260 | } else if ( action == 1001 ) { |
258 | syncLocalFile(); | 261 | syncLocalFile(); |
259 | 262 | ||
260 | } else if ( action == 1002 ) { | 263 | } else if ( action == 1002 ) { |
261 | mWriteBackFile = false; | 264 | mWriteBackFile = false; |
262 | mAskForPreferences = false; | 265 | mAskForPreferences = false; |
263 | mShowSyncSummary = false; | 266 | mShowSyncSummary = false; |
264 | mSyncAlgoPrefs = 3; | 267 | mSyncAlgoPrefs = 3; |
265 | quickSyncLocalFile(); | 268 | quickSyncLocalFile(); |
266 | 269 | ||
267 | } else if ( action >= 1003 ) { | 270 | } else if ( action >= 1003 ) { |
268 | if ( temp->getIsLocalFileSync() ) { | 271 | if ( temp->getIsLocalFileSync() ) { |
269 | switch(mTargetApp) | 272 | switch(mTargetApp) |
270 | { | 273 | { |
271 | case (KAPI): | 274 | case (KAPI): |
272 | if ( syncWithFile( temp->getRemoteFileNameAB( ), false ) ) | 275 | if ( syncWithFile( temp->getRemoteFileNameAB( ), false ) ) |
273 | mPrefs->mLastSyncedLocalFile = temp->getRemoteFileNameAB(); | 276 | mPrefs->mLastSyncedLocalFile = temp->getRemoteFileNameAB(); |
274 | break; | 277 | break; |
275 | case (KOPI): | 278 | case (KOPI): |
276 | if ( syncWithFile( temp->getRemoteFileName( ), false ) ) | 279 | if ( syncWithFile( temp->getRemoteFileName( ), false ) ) |
277 | mPrefs->mLastSyncedLocalFile = temp->getRemoteFileName(); | 280 | mPrefs->mLastSyncedLocalFile = temp->getRemoteFileName(); |
278 | break; | 281 | break; |
279 | case (PWMPI): | 282 | case (PWMPI): |
280 | if ( syncWithFile( temp->getRemoteFileNamePWM( ), false ) ) | 283 | if ( syncWithFile( temp->getRemoteFileNamePWM( ), false ) ) |
281 | mPrefs->mLastSyncedLocalFile = temp->getRemoteFileNamePWM(); | 284 | mPrefs->mLastSyncedLocalFile = temp->getRemoteFileNamePWM(); |
282 | break; | 285 | break; |
283 | default: | 286 | default: |
284 | qDebug("KSyncManager::slotSyncMenu: invalid apptype selected"); | 287 | qDebug("KSyncManager::slotSyncMenu: invalid apptype selected"); |
285 | break; | 288 | break; |
286 | 289 | ||
287 | } | 290 | } |
288 | } else { | 291 | } else { |
289 | if ( temp->getIsPhoneSync() ) { | 292 | if ( temp->getIsPhoneSync() ) { |
290 | mPhoneDevice = temp->getPhoneDevice( ) ; | 293 | mPhoneDevice = temp->getPhoneDevice( ) ; |
291 | mPhoneConnection = temp->getPhoneConnection( ); | 294 | mPhoneConnection = temp->getPhoneConnection( ); |
292 | mPhoneModel = temp->getPhoneModel( ); | 295 | mPhoneModel = temp->getPhoneModel( ); |
293 | syncPhone(); | 296 | syncPhone(); |
294 | } else if ( temp->getIsPiSync() ) { | 297 | } else if ( temp->getIsPiSync() ) { |
295 | if ( mTargetApp == KAPI ) { | 298 | if ( mTargetApp == KAPI ) { |
296 | mPassWordPiSync = temp->getRemotePwAB(); | 299 | mPassWordPiSync = temp->getRemotePwAB(); |
297 | mActiveSyncPort = temp->getRemotePortAB(); | 300 | mActiveSyncPort = temp->getRemotePortAB(); |
298 | mActiveSyncIP = temp->getRemoteIPAB(); | 301 | mActiveSyncIP = temp->getRemoteIPAB(); |
299 | } else if ( mTargetApp == KOPI ) { | 302 | } else if ( mTargetApp == KOPI ) { |
300 | mPassWordPiSync = temp->getRemotePw(); | 303 | mPassWordPiSync = temp->getRemotePw(); |
301 | mActiveSyncPort = temp->getRemotePort(); | 304 | mActiveSyncPort = temp->getRemotePort(); |
302 | mActiveSyncIP = temp->getRemoteIP(); | 305 | mActiveSyncIP = temp->getRemoteIP(); |
303 | } else { | 306 | } else { |
304 | mPassWordPiSync = temp->getRemotePwPWM(); | 307 | mPassWordPiSync = temp->getRemotePwPWM(); |
305 | mActiveSyncPort = temp->getRemotePortPWM(); | 308 | mActiveSyncPort = temp->getRemotePortPWM(); |
306 | mActiveSyncIP = temp->getRemoteIPPWM(); | 309 | mActiveSyncIP = temp->getRemoteIPPWM(); |
307 | } | 310 | } |
308 | syncPi(); | 311 | syncPi(); |
309 | while ( !mPisyncFinished ) { | 312 | while ( !mPisyncFinished ) { |
310 | //qDebug("waiting "); | 313 | //qDebug("waiting "); |
311 | qApp->processEvents(); | 314 | qApp->processEvents(); |
312 | } | 315 | } |
313 | } else | 316 | } else |
314 | syncRemote( temp ); | 317 | syncRemote( temp ); |
315 | 318 | ||
316 | } | 319 | } |
317 | } | 320 | } |
318 | delete temp; | 321 | delete temp; |
319 | setBlockSave(false); | 322 | setBlockSave(false); |
320 | } | 323 | } |
321 | 324 | ||
322 | void KSyncManager::enableQuick( bool ask ) | 325 | void KSyncManager::enableQuick( bool ask ) |
323 | { | 326 | { |
324 | bool autoStart; | 327 | bool autoStart; |
325 | bool changed = false; | 328 | bool changed = false; |
326 | if ( ask ) { | 329 | if ( ask ) { |
327 | QDialog dia ( 0, "input-dialog", true ); | 330 | QDialog dia ( 0, "input-dialog", true ); |
328 | QLineEdit lab ( &dia ); | 331 | QLineEdit lab ( &dia ); |
329 | QVBoxLayout lay( &dia ); | 332 | QVBoxLayout lay( &dia ); |
330 | lab.setText( mPrefs->mPassiveSyncPort ); | 333 | lab.setText( mPrefs->mPassiveSyncPort ); |
331 | lay.setMargin(7); | 334 | lay.setMargin(7); |
332 | lay.setSpacing(7); | 335 | lay.setSpacing(7); |
333 | int po = 9197+mTargetApp; | 336 | int po = 9197+mTargetApp; |
334 | QLabel label ( i18n("Port number (Default: %1)").arg(po), &dia ); | 337 | QLabel label ( i18n("Port number (Default: %1)").arg(po), &dia ); |
335 | lay.addWidget( &label); | 338 | lay.addWidget( &label); |
336 | lay.addWidget( &lab); | 339 | lay.addWidget( &lab); |
337 | 340 | ||
338 | QLineEdit lepw ( &dia ); | 341 | QLineEdit lepw ( &dia ); |
339 | lepw.setText( mPrefs->mPassiveSyncPw ); | 342 | lepw.setText( mPrefs->mPassiveSyncPw ); |
340 | QLabel label2 ( i18n("Password to enable\naccess from remote:"), &dia ); | 343 | QLabel label2 ( i18n("Password to enable\naccess from remote:"), &dia ); |
341 | lay.addWidget( &label2); | 344 | lay.addWidget( &label2); |
342 | lay.addWidget( &lepw); | 345 | lay.addWidget( &lepw); |
343 | QCheckBox autostart(i18n("Automatically start\nat application startup"), &dia ); | 346 | QCheckBox autostart(i18n("Automatically start\nat application startup"), &dia ); |
344 | lay.addWidget( &autostart); | 347 | lay.addWidget( &autostart); |
345 | autostart.setChecked( mPrefs->mPassiveSyncAutoStart ); | 348 | autostart.setChecked( mPrefs->mPassiveSyncAutoStart ); |
346 | #ifdef DESKTOP_VERSION | 349 | #ifdef DESKTOP_VERSION |
347 | #ifdef _WIN32_ | 350 | #ifdef _WIN32_ |
348 | QCheckBox syncdesktop( i18n("Automatically sync with Outlook\nwhen receiving sync request"),&dia ); | 351 | QCheckBox syncdesktop( i18n("Automatically sync with Outlook\nwhen receiving sync request"),&dia ); |
349 | #else | 352 | #else |
350 | QCheckBox syncdesktop( i18n("Automatically sync with KDE-Desktop\nwhen receiving sync request"),&dia ); | 353 | QCheckBox syncdesktop( i18n("Automatically sync with KDE-Desktop\nwhen receiving sync request"),&dia ); |
351 | #endif | 354 | #endif |
352 | lay.addWidget( &syncdesktop); | 355 | lay.addWidget( &syncdesktop); |
353 | #else | 356 | #else |
354 | mPrefs->mPassiveSyncWithDesktop = false; | 357 | mPrefs->mPassiveSyncWithDesktop = false; |
355 | QCheckBox syncdesktop( i18n("Automatically sync\nwith KDE-Desktop"),&dia ); | 358 | QCheckBox syncdesktop( i18n("Automatically sync\nwith KDE-Desktop"),&dia ); |
356 | syncdesktop.hide(); | 359 | syncdesktop.hide(); |
357 | #endif | 360 | #endif |
358 | syncdesktop.setChecked( mPrefs->mPassiveSyncWithDesktop ); | 361 | syncdesktop.setChecked( mPrefs->mPassiveSyncWithDesktop ); |
359 | 362 | ||
360 | dia.setFixedSize( 230,120 ); | 363 | dia.setFixedSize( 230,120 ); |
361 | dia.setCaption( i18n("Enter port for Pi-Sync") ); | 364 | dia.setCaption( i18n("Enter port for Pi-Sync") ); |
362 | QPushButton pb ( "OK", &dia); | 365 | QPushButton pb ( "OK", &dia); |
363 | lay.addWidget( &pb ); | 366 | lay.addWidget( &pb ); |
364 | connect(&pb, SIGNAL( clicked() ), &dia, SLOT ( accept() ) ); | 367 | connect(&pb, SIGNAL( clicked() ), &dia, SLOT ( accept() ) ); |
365 | dia.show(); | 368 | dia.show(); |
366 | if ( ! dia.exec() ) | 369 | if ( ! dia.exec() ) |
367 | return; | 370 | return; |
368 | dia.hide(); | 371 | dia.hide(); |
369 | qApp->processEvents(); | 372 | qApp->processEvents(); |
370 | if ( mPrefs->mPassiveSyncPw != lepw.text() ) { | 373 | if ( mPrefs->mPassiveSyncPw != lepw.text() ) { |
371 | changed = true; | 374 | changed = true; |
372 | mPrefs->mPassiveSyncPw = lepw.text(); | 375 | mPrefs->mPassiveSyncPw = lepw.text(); |
373 | } | 376 | } |
374 | if ( mPrefs->mPassiveSyncPort != lab.text() ) { | 377 | if ( mPrefs->mPassiveSyncPort != lab.text() ) { |
375 | mPrefs->mPassiveSyncPort = lab.text(); | 378 | mPrefs->mPassiveSyncPort = lab.text(); |
376 | changed = true; | 379 | changed = true; |
377 | } | 380 | } |
378 | autoStart = autostart.isChecked(); | 381 | autoStart = autostart.isChecked(); |
379 | if (mPrefs->mPassiveSyncWithDesktop != syncdesktop.isChecked() ) { | 382 | if (mPrefs->mPassiveSyncWithDesktop != syncdesktop.isChecked() ) { |
380 | changed = true; | 383 | changed = true; |
381 | mPrefs->mPassiveSyncWithDesktop = syncdesktop.isChecked(); | 384 | mPrefs->mPassiveSyncWithDesktop = syncdesktop.isChecked(); |
382 | } | 385 | } |
383 | } | 386 | } |
384 | else | 387 | else |
385 | autoStart = mPrefs->mPassiveSyncAutoStart; | 388 | autoStart = mPrefs->mPassiveSyncAutoStart; |
386 | if ( autoStart != mPrefs->mPassiveSyncAutoStart ) | 389 | if ( autoStart != mPrefs->mPassiveSyncAutoStart ) |
387 | changed = true; | 390 | changed = true; |
388 | bool ok; | 391 | bool ok; |
389 | mPrefs->mPassiveSyncAutoStart = false; | 392 | mPrefs->mPassiveSyncAutoStart = false; |
390 | Q_UINT16 port = mPrefs->mPassiveSyncPort.toUInt(&ok); | 393 | Q_UINT16 port = mPrefs->mPassiveSyncPort.toUInt(&ok); |
391 | if ( ! ok ) { | 394 | if ( ! ok ) { |
392 | KMessageBox::information( 0, i18n("No valid port")); | 395 | KMessageBox::information( 0, i18n("No valid port")); |
393 | return; | 396 | return; |
394 | } | 397 | } |
395 | //qDebug("port %d ", port); | 398 | //qDebug("port %d ", port); |
396 | mServerSocket = new KServerSocket ( mPrefs->mPassiveSyncPw, port ,1 ); | 399 | mServerSocket = new KServerSocket ( mPrefs->mPassiveSyncPw, port ,1 ); |
397 | mServerSocket->setFileName( defaultFileName() ); | 400 | mServerSocket->setFileName( defaultFileName() ); |
398 | //qDebug("connected "); | 401 | //qDebug("connected "); |
399 | if ( !mServerSocket->ok() ) { | 402 | if ( !mServerSocket->ok() ) { |
400 | KMessageBox::information( 0, i18n("Failed to bind or\nlisten to the port!")); | 403 | KMessageBox::information( 0, i18n("Failed to bind or\nlisten to the port!")); |
401 | delete mServerSocket; | 404 | delete mServerSocket; |
402 | mServerSocket = 0; | 405 | mServerSocket = 0; |
403 | return; | 406 | return; |
404 | } | 407 | } |
405 | mPrefs->mPassiveSyncAutoStart = autoStart; | 408 | mPrefs->mPassiveSyncAutoStart = autoStart; |
406 | if ( changed ) { | 409 | if ( changed ) { |
407 | mPrefs->writeConfig(); | 410 | mPrefs->writeConfig(); |
408 | } | 411 | } |
409 | connect( mServerSocket, SIGNAL ( request_file() ),this, SIGNAL ( request_file() ) ); | 412 | connect( mServerSocket, SIGNAL ( request_file() ),this, SIGNAL ( request_file() ) ); |
410 | connect( mServerSocket, SIGNAL ( file_received( bool ) ), this, SIGNAL ( getFile( bool ) ) ); | 413 | connect( mServerSocket, SIGNAL ( file_received( bool ) ), this, SIGNAL ( getFile( bool ) ) ); |
411 | } | 414 | } |
412 | 415 | ||
413 | void KSyncManager::syncLocalFile() | 416 | void KSyncManager::syncLocalFile() |
414 | { | 417 | { |
415 | 418 | ||
416 | QString fn =mPrefs->mLastSyncedLocalFile; | 419 | QString fn =mPrefs->mLastSyncedLocalFile; |
417 | QString ext; | 420 | QString ext; |
418 | 421 | ||
419 | switch(mTargetApp) | 422 | switch(mTargetApp) |
420 | { | 423 | { |
421 | case (KAPI): | 424 | case (KAPI): |
422 | ext = "(*.vcf)"; | 425 | ext = "(*.vcf)"; |
423 | break; | 426 | break; |
424 | case (KOPI): | 427 | case (KOPI): |
425 | ext = "(*.ics/*.vcs)"; | 428 | ext = "(*.ics/*.vcs)"; |
426 | break; | 429 | break; |
427 | case (PWMPI): | 430 | case (PWMPI): |
428 | ext = "(*.pwm)"; | 431 | ext = "(*.pwm)"; |
429 | break; | 432 | break; |
430 | default: | 433 | default: |
431 | qDebug("KSyncManager::syncLocalFile: invalid apptype selected"); | 434 | qDebug("KSyncManager::syncLocalFile: invalid apptype selected"); |
432 | break; | 435 | break; |
433 | 436 | ||
434 | } | 437 | } |
435 | 438 | ||
436 | fn =KFileDialog:: getOpenFileName( fn, i18n("Sync filename"+ext), mParent ); | 439 | fn =KFileDialog:: getOpenFileName( fn, i18n("Sync filename"+ext), mParent ); |
437 | if ( fn == "" ) | 440 | if ( fn == "" ) |
438 | return; | 441 | return; |
439 | if ( syncWithFile( fn, false ) ) { | 442 | if ( syncWithFile( fn, false ) ) { |
440 | qDebug("syncLocalFile() successful "); | 443 | qDebug("syncLocalFile() successful "); |
441 | } | 444 | } |
@@ -730,667 +733,676 @@ void KSyncManager::syncRemote( KSyncProfile* prof, bool ask) | |||
730 | postCommand = postCommand.left( fi )+ pwd + postCommand.mid( fi+5 ); | 733 | postCommand = postCommand.left( fi )+ pwd + postCommand.mid( fi+5 ); |
731 | 734 | ||
732 | } | 735 | } |
733 | mParent->topLevelWidget()->setCaption ( i18n( "Writing back file ..." ) ); | 736 | mParent->topLevelWidget()->setCaption ( i18n( "Writing back file ..." ) ); |
734 | result = system ( postCommand ); | 737 | result = system ( postCommand ); |
735 | qDebug("Sync:Writing back file result: %d ", result); | 738 | qDebug("Sync:Writing back file result: %d ", result); |
736 | if ( result != 0 ) { | 739 | if ( result != 0 ) { |
737 | mParent->topLevelWidget()->setCaption ( i18n( "Writing back file result: " )+QString::number( result ) ); | 740 | mParent->topLevelWidget()->setCaption ( i18n( "Writing back file result: " )+QString::number( result ) ); |
738 | return; | 741 | return; |
739 | } else { | 742 | } else { |
740 | mParent->topLevelWidget()->setCaption ( i18n( "Syncronization sucessfully completed" ) ); | 743 | mParent->topLevelWidget()->setCaption ( i18n( "Syncronization sucessfully completed" ) ); |
741 | } | 744 | } |
742 | } | 745 | } |
743 | } | 746 | } |
744 | return; | 747 | return; |
745 | } | 748 | } |
746 | bool KSyncManager::edit_pisync_options() | 749 | bool KSyncManager::edit_pisync_options() |
747 | { | 750 | { |
748 | QDialog dia( mParent, "dia", true ); | 751 | QDialog dia( mParent, "dia", true ); |
749 | dia.setCaption( i18n("Pi-Sync options for device: " ) +mCurrentSyncDevice ); | 752 | dia.setCaption( i18n("Pi-Sync options for device: " ) +mCurrentSyncDevice ); |
750 | QVBoxLayout lay ( &dia ); | 753 | QVBoxLayout lay ( &dia ); |
751 | lay.setSpacing( 5 ); | 754 | lay.setSpacing( 5 ); |
752 | lay.setMargin( 3 ); | 755 | lay.setMargin( 3 ); |
753 | QLabel lab1 ( i18n("Password for remote access:"), &dia); | 756 | QLabel lab1 ( i18n("Password for remote access:"), &dia); |
754 | lay.addWidget( &lab1 ); | 757 | lay.addWidget( &lab1 ); |
755 | QLineEdit le1 (&dia ); | 758 | QLineEdit le1 (&dia ); |
756 | lay.addWidget( &le1 ); | 759 | lay.addWidget( &le1 ); |
757 | QLabel lab2 ( i18n("Remote IP address:"), &dia); | 760 | QLabel lab2 ( i18n("Remote IP address:"), &dia); |
758 | lay.addWidget( &lab2 ); | 761 | lay.addWidget( &lab2 ); |
759 | QLineEdit le2 (&dia ); | 762 | QLineEdit le2 (&dia ); |
760 | lay.addWidget( &le2 ); | 763 | lay.addWidget( &le2 ); |
761 | QLabel lab3 ( i18n("Remote port number:"), &dia); | 764 | QLabel lab3 ( i18n("Remote port number:"), &dia); |
762 | lay.addWidget( &lab3 ); | 765 | lay.addWidget( &lab3 ); |
763 | QLineEdit le3 (&dia ); | 766 | QLineEdit le3 (&dia ); |
764 | lay.addWidget( &le3 ); | 767 | lay.addWidget( &le3 ); |
765 | QPushButton pb ( "OK", &dia); | 768 | QPushButton pb ( "OK", &dia); |
766 | lay.addWidget( &pb ); | 769 | lay.addWidget( &pb ); |
767 | connect(&pb, SIGNAL( clicked() ), &dia, SLOT ( accept() ) ); | 770 | connect(&pb, SIGNAL( clicked() ), &dia, SLOT ( accept() ) ); |
768 | le1.setText( mPassWordPiSync ); | 771 | le1.setText( mPassWordPiSync ); |
769 | le2.setText( mActiveSyncIP ); | 772 | le2.setText( mActiveSyncIP ); |
770 | le3.setText( mActiveSyncPort ); | 773 | le3.setText( mActiveSyncPort ); |
771 | if ( dia.exec() ) { | 774 | if ( dia.exec() ) { |
772 | mPassWordPiSync = le1.text(); | 775 | mPassWordPiSync = le1.text(); |
773 | mActiveSyncPort = le3.text(); | 776 | mActiveSyncPort = le3.text(); |
774 | mActiveSyncIP = le2.text(); | 777 | mActiveSyncIP = le2.text(); |
775 | return true; | 778 | return true; |
776 | } | 779 | } |
777 | return false; | 780 | return false; |
778 | } | 781 | } |
779 | bool KSyncManager::edit_sync_options() | 782 | bool KSyncManager::edit_sync_options() |
780 | { | 783 | { |
781 | 784 | ||
782 | QDialog dia( mParent, "dia", true ); | 785 | QDialog dia( mParent, "dia", true ); |
783 | dia.setCaption( i18n("Device: " ) +mCurrentSyncDevice ); | 786 | dia.setCaption( i18n("Device: " ) +mCurrentSyncDevice ); |
784 | QButtonGroup gr ( 1, Qt::Horizontal, i18n("Sync preferences"), &dia); | 787 | QButtonGroup gr ( 1, Qt::Horizontal, i18n("Sync preferences"), &dia); |
785 | QVBoxLayout lay ( &dia ); | 788 | QVBoxLayout lay ( &dia ); |
786 | lay.setSpacing( 2 ); | 789 | lay.setSpacing( 2 ); |
787 | lay.setMargin( 3 ); | 790 | lay.setMargin( 3 ); |
788 | lay.addWidget(&gr); | 791 | lay.addWidget(&gr); |
789 | QRadioButton loc ( i18n("Take local entry on conflict"), &gr ); | 792 | QRadioButton loc ( i18n("Take local entry on conflict"), &gr ); |
790 | QRadioButton rem ( i18n("Take remote entry on conflict"), &gr ); | 793 | QRadioButton rem ( i18n("Take remote entry on conflict"), &gr ); |
791 | QRadioButton newest( i18n("Take newest entry on conflict"), &gr ); | 794 | QRadioButton newest( i18n("Take newest entry on conflict"), &gr ); |
792 | QRadioButton ask( i18n("Ask for every entry on conflict"), &gr ); | 795 | QRadioButton ask( i18n("Ask for every entry on conflict"), &gr ); |
793 | QRadioButton f_loc( i18n("Force: Take local entry always"), &gr ); | 796 | QRadioButton f_loc( i18n("Force: Take local entry always"), &gr ); |
794 | QRadioButton f_rem( i18n("Force: Take remote entry always"), &gr ); | 797 | QRadioButton f_rem( i18n("Force: Take remote entry always"), &gr ); |
795 | //QRadioButton both( i18n("Take both on conflict"), &gr ); | 798 | //QRadioButton both( i18n("Take both on conflict"), &gr ); |
796 | QPushButton pb ( "OK", &dia); | 799 | QPushButton pb ( "OK", &dia); |
797 | lay.addWidget( &pb ); | 800 | lay.addWidget( &pb ); |
798 | connect(&pb, SIGNAL( clicked() ), &dia, SLOT ( accept() ) ); | 801 | connect(&pb, SIGNAL( clicked() ), &dia, SLOT ( accept() ) ); |
799 | switch ( mSyncAlgoPrefs ) { | 802 | switch ( mSyncAlgoPrefs ) { |
800 | case 0: | 803 | case 0: |
801 | loc.setChecked( true); | 804 | loc.setChecked( true); |
802 | break; | 805 | break; |
803 | case 1: | 806 | case 1: |
804 | rem.setChecked( true ); | 807 | rem.setChecked( true ); |
805 | break; | 808 | break; |
806 | case 2: | 809 | case 2: |
807 | newest.setChecked( true); | 810 | newest.setChecked( true); |
808 | break; | 811 | break; |
809 | case 3: | 812 | case 3: |
810 | ask.setChecked( true); | 813 | ask.setChecked( true); |
811 | break; | 814 | break; |
812 | case 4: | 815 | case 4: |
813 | f_loc.setChecked( true); | 816 | f_loc.setChecked( true); |
814 | break; | 817 | break; |
815 | case 5: | 818 | case 5: |
816 | f_rem.setChecked( true); | 819 | f_rem.setChecked( true); |
817 | break; | 820 | break; |
818 | case 6: | 821 | case 6: |
819 | // both.setChecked( true); | 822 | // both.setChecked( true); |
820 | break; | 823 | break; |
821 | default: | 824 | default: |
822 | break; | 825 | break; |
823 | } | 826 | } |
824 | if ( dia.exec() ) { | 827 | if ( dia.exec() ) { |
825 | mSyncAlgoPrefs = rem.isChecked()*1+newest.isChecked()*2+ ask.isChecked()*3+ f_loc.isChecked()*4+ f_rem.isChecked()*5;//+ both.isChecked()*6 ; | 828 | mSyncAlgoPrefs = rem.isChecked()*1+newest.isChecked()*2+ ask.isChecked()*3+ f_loc.isChecked()*4+ f_rem.isChecked()*5;//+ both.isChecked()*6 ; |
826 | return true; | 829 | return true; |
827 | } | 830 | } |
828 | return false; | 831 | return false; |
829 | } | 832 | } |
830 | 833 | ||
831 | QString KSyncManager::getPassword( ) | 834 | QString KSyncManager::getPassword( ) |
832 | { | 835 | { |
833 | QString retfile = ""; | 836 | QString retfile = ""; |
834 | QDialog dia ( mParent, "input-dialog", true ); | 837 | QDialog dia ( mParent, "input-dialog", true ); |
835 | QLineEdit lab ( &dia ); | 838 | QLineEdit lab ( &dia ); |
836 | lab.setEchoMode( QLineEdit::Password ); | 839 | lab.setEchoMode( QLineEdit::Password ); |
837 | QVBoxLayout lay( &dia ); | 840 | QVBoxLayout lay( &dia ); |
838 | lay.setMargin(7); | 841 | lay.setMargin(7); |
839 | lay.setSpacing(7); | 842 | lay.setSpacing(7); |
840 | lay.addWidget( &lab); | 843 | lay.addWidget( &lab); |
841 | dia.setFixedSize( 230,50 ); | 844 | dia.setFixedSize( 230,50 ); |
842 | dia.setCaption( i18n("Enter password") ); | 845 | dia.setCaption( i18n("Enter password") ); |
843 | QPushButton pb ( "OK", &dia); | 846 | QPushButton pb ( "OK", &dia); |
844 | lay.addWidget( &pb ); | 847 | lay.addWidget( &pb ); |
845 | connect(&pb, SIGNAL( clicked() ), &dia, SLOT ( accept() ) ); | 848 | connect(&pb, SIGNAL( clicked() ), &dia, SLOT ( accept() ) ); |
846 | dia.show(); | 849 | dia.show(); |
847 | int res = dia.exec(); | 850 | int res = dia.exec(); |
848 | if ( res ) | 851 | if ( res ) |
849 | retfile = lab.text(); | 852 | retfile = lab.text(); |
850 | dia.hide(); | 853 | dia.hide(); |
851 | qApp->processEvents(); | 854 | qApp->processEvents(); |
852 | return retfile; | 855 | return retfile; |
853 | 856 | ||
854 | } | 857 | } |
855 | 858 | ||
856 | 859 | ||
857 | void KSyncManager::confSync() | 860 | void KSyncManager::confSync() |
858 | { | 861 | { |
859 | static KSyncPrefsDialog* sp = 0; | 862 | static KSyncPrefsDialog* sp = 0; |
860 | if ( ! sp ) { | 863 | if ( ! sp ) { |
861 | sp = new KSyncPrefsDialog( mParent, "syncprefs", true ); | 864 | sp = new KSyncPrefsDialog( mParent, "syncprefs", true ); |
862 | } | 865 | } |
863 | sp->usrReadConfig(); | 866 | sp->usrReadConfig(); |
864 | #ifndef DESKTOP_VERSION | 867 | #ifndef DESKTOP_VERSION |
865 | sp->showMaximized(); | 868 | sp->showMaximized(); |
866 | #else | 869 | #else |
867 | sp->show(); | 870 | sp->show(); |
868 | #endif | 871 | #endif |
869 | sp->exec(); | 872 | sp->exec(); |
870 | QStringList oldSyncProfileNames = mSyncProfileNames; | 873 | QStringList oldSyncProfileNames = mSyncProfileNames; |
871 | mSyncProfileNames = sp->getSyncProfileNames(); | 874 | mSyncProfileNames = sp->getSyncProfileNames(); |
872 | mLocalMachineName = sp->getLocalMachineName (); | 875 | mLocalMachineName = sp->getLocalMachineName (); |
873 | int ii; | 876 | int ii; |
874 | for ( ii = 0; ii < oldSyncProfileNames.count(); ++ii ) { | 877 | for ( ii = 0; ii < oldSyncProfileNames.count(); ++ii ) { |
875 | if ( ! mSyncProfileNames.contains( oldSyncProfileNames[ii] ) ) | 878 | if ( ! mSyncProfileNames.contains( oldSyncProfileNames[ii] ) ) |
876 | mImplementation->removeSyncInfo( oldSyncProfileNames[ii] ); | 879 | mImplementation->removeSyncInfo( oldSyncProfileNames[ii] ); |
877 | } | 880 | } |
878 | QTimer::singleShot ( 1, this, SLOT ( fillSyncMenu() ) ); | 881 | QTimer::singleShot ( 1, this, SLOT ( fillSyncMenu() ) ); |
879 | } | 882 | } |
880 | void KSyncManager::syncKDE() | 883 | void KSyncManager::syncKDE() |
881 | { | 884 | { |
882 | emit save(); | 885 | emit save(); |
883 | switch(mTargetApp) | 886 | switch(mTargetApp) |
884 | { | 887 | { |
885 | case (KAPI): | 888 | case (KAPI): |
886 | 889 | ||
887 | break; | 890 | break; |
888 | case (KOPI): | 891 | case (KOPI): |
889 | { | 892 | { |
890 | #ifdef DESKTOP_VERSION | 893 | #ifdef DESKTOP_VERSION |
891 | QString command = qApp->applicationDirPath () + "/kdecaldump"; | 894 | QString command = qApp->applicationDirPath () + "/kdecaldump"; |
892 | #else | 895 | #else |
893 | QString command = "kdecaldump"; | 896 | QString command = "kdecaldump"; |
894 | #endif | 897 | #endif |
895 | if ( ! QFile::exists ( command ) ) | 898 | if ( ! QFile::exists ( command ) ) |
896 | command = "kdecaldump"; | 899 | command = "kdecaldump"; |
897 | QString fileName = QDir::homeDirPath ()+"/.kdecalendardump.ics"; | 900 | QString fileName = QDir::homeDirPath ()+"/.kdecalendardump.ics"; |
898 | system ( command.latin1()); | 901 | system ( command.latin1()); |
899 | if ( syncWithFile( fileName,true ) ) { | 902 | if ( syncWithFile( fileName,true ) ) { |
900 | if ( mWriteBackFile ) { | 903 | if ( mWriteBackFile ) { |
901 | command += " --read"; | 904 | command += " --read"; |
902 | system ( command.latin1()); | 905 | system ( command.latin1()); |
903 | } | 906 | } |
904 | } | 907 | } |
905 | 908 | ||
906 | } | 909 | } |
907 | break; | 910 | break; |
908 | case (PWMPI): | 911 | case (PWMPI): |
909 | 912 | ||
910 | break; | 913 | break; |
911 | default: | 914 | default: |
912 | qDebug("KSyncManager::slotSyncMenu: invalid apptype selected"); | 915 | qDebug("KSyncManager::slotSyncMenu: invalid apptype selected"); |
913 | break; | 916 | break; |
914 | 917 | ||
915 | } | 918 | } |
916 | } | 919 | } |
917 | 920 | ||
918 | void KSyncManager::syncSharp() | 921 | void KSyncManager::syncSharp() |
919 | { | 922 | { |
920 | 923 | ||
921 | if ( ! syncExternalApplication("sharp") ) | 924 | if ( ! syncExternalApplication("sharp") ) |
922 | qDebug("ERROR sync sharp "); | 925 | qDebug("ERROR sync sharp "); |
923 | } | 926 | } |
924 | 927 | ||
925 | bool KSyncManager::syncExternalApplication(QString resource) | 928 | bool KSyncManager::syncExternalApplication(QString resource) |
926 | { | 929 | { |
927 | 930 | ||
928 | emit save(); | 931 | emit save(); |
929 | 932 | ||
930 | if ( mAskForPreferences ) | 933 | if ( mAskForPreferences ) |
931 | if ( !edit_sync_options()) { | 934 | if ( !edit_sync_options()) { |
932 | mParent->topLevelWidget()->setCaption( i18n("Syncing aborted. Nothing synced.") ); | 935 | mParent->topLevelWidget()->setCaption( i18n("Syncing aborted. Nothing synced.") ); |
933 | return false; | 936 | return false; |
934 | } | 937 | } |
935 | 938 | ||
936 | qDebug("Sync extern %s", resource.latin1()); | 939 | qDebug("Sync extern %s", resource.latin1()); |
937 | 940 | ||
938 | bool syncOK = mImplementation->syncExternal(this, resource); | 941 | bool syncOK = mImplementation->syncExternal(this, resource); |
939 | 942 | ||
940 | return syncOK; | 943 | return syncOK; |
941 | 944 | ||
942 | } | 945 | } |
943 | 946 | ||
944 | void KSyncManager::syncPhone() | 947 | void KSyncManager::syncPhone() |
945 | { | 948 | { |
946 | 949 | ||
947 | syncExternalApplication("phone"); | 950 | syncExternalApplication("phone"); |
948 | 951 | ||
949 | } | 952 | } |
950 | 953 | ||
951 | void KSyncManager::showProgressBar(int percentage, QString caption, int total) | 954 | void KSyncManager::showProgressBar(int percentage, QString caption, int total) |
952 | { | 955 | { |
953 | if (!bar->isVisible()) | 956 | if (!bar->isVisible()) |
954 | { | 957 | { |
955 | bar->setCaption (caption); | 958 | bar->setCaption (caption); |
956 | bar->setTotalSteps ( total ) ; | 959 | bar->setTotalSteps ( total ) ; |
957 | 960 | ||
958 | bar->show(); | 961 | bar->show(); |
959 | } | 962 | } |
960 | 963 | ||
961 | bar->setProgress( percentage ); | 964 | bar->setProgress( percentage ); |
962 | } | 965 | } |
963 | 966 | ||
964 | void KSyncManager::hideProgressBar() | 967 | void KSyncManager::hideProgressBar() |
965 | { | 968 | { |
966 | bar->hide(); | 969 | bar->hide(); |
967 | } | 970 | } |
968 | 971 | ||
969 | bool KSyncManager::isProgressBarCanceled() | 972 | bool KSyncManager::isProgressBarCanceled() |
970 | { | 973 | { |
971 | return !bar->isVisible(); | 974 | return !bar->isVisible(); |
972 | } | 975 | } |
973 | 976 | ||
974 | QString KSyncManager::syncFileName() | 977 | QString KSyncManager::syncFileName() |
975 | { | 978 | { |
976 | 979 | ||
977 | QString fn = "tempfile"; | 980 | QString fn = "tempfile"; |
978 | switch(mTargetApp) | 981 | switch(mTargetApp) |
979 | { | 982 | { |
980 | case (KAPI): | 983 | case (KAPI): |
981 | fn = "tempsyncab.vcf"; | 984 | fn = "tempsyncab.vcf"; |
982 | break; | 985 | break; |
983 | case (KOPI): | 986 | case (KOPI): |
984 | fn = "tempsynccal.ics"; | 987 | fn = "tempsynccal.ics"; |
985 | break; | 988 | break; |
986 | case (PWMPI): | 989 | case (PWMPI): |
987 | fn = "tempsyncpw.pwm"; | 990 | fn = "tempsyncpw.pwm"; |
988 | break; | 991 | break; |
989 | default: | 992 | default: |
990 | break; | 993 | break; |
991 | } | 994 | } |
992 | #ifdef _WIN32_ | 995 | #ifdef _WIN32_ |
993 | return locateLocal( "tmp", fn ); | 996 | return locateLocal( "tmp", fn ); |
994 | #else | 997 | #else |
995 | return (QString( "/tmp/" )+ fn ); | 998 | return (QString( "/tmp/" )+ fn ); |
996 | #endif | 999 | #endif |
997 | } | 1000 | } |
998 | 1001 | ||
999 | void KSyncManager::syncPi() | 1002 | void KSyncManager::syncPi() |
1000 | { | 1003 | { |
1001 | mPisyncFinished = false; | 1004 | mPisyncFinished = false; |
1002 | qApp->processEvents(); | 1005 | qApp->processEvents(); |
1003 | if ( mAskForPreferences ) | 1006 | if ( mAskForPreferences ) |
1004 | if ( !edit_pisync_options()) { | 1007 | if ( !edit_pisync_options()) { |
1005 | mParent->topLevelWidget()->setCaption( i18n("Syncing aborted. Nothing synced.") ); | 1008 | mParent->topLevelWidget()->setCaption( i18n("Syncing aborted. Nothing synced.") ); |
1006 | return; | 1009 | return; |
1007 | } | 1010 | } |
1008 | bool ok; | 1011 | bool ok; |
1009 | Q_UINT16 port = mActiveSyncPort.toUInt(&ok); | 1012 | Q_UINT16 port = mActiveSyncPort.toUInt(&ok); |
1010 | if ( ! ok ) { | 1013 | if ( ! ok ) { |
1011 | mParent->topLevelWidget()->setCaption( i18n("Sorry, no valid port.Syncing cancelled.") ); | 1014 | mParent->topLevelWidget()->setCaption( i18n("Sorry, no valid port.Syncing cancelled.") ); |
1012 | return; | 1015 | return; |
1013 | } | 1016 | } |
1014 | KCommandSocket* commandSocket = new KCommandSocket( mPassWordPiSync, port, mActiveSyncIP, this ); | 1017 | KCommandSocket* commandSocket = new KCommandSocket( mPassWordPiSync, port, mActiveSyncIP, this ); |
1015 | connect( commandSocket, SIGNAL(commandFinished( KCommandSocket*, int )), this, SLOT(deleteCommandSocket(KCommandSocket*, int)) ); | 1018 | connect( commandSocket, SIGNAL(commandFinished( KCommandSocket*, int )), this, SLOT(deleteCommandSocket(KCommandSocket*, int)) ); |
1016 | mParent->topLevelWidget()->setCaption( i18n("Sending request for remote file ...") ); | 1019 | mParent->topLevelWidget()->setCaption( i18n("Sending request for remote file ...") ); |
1017 | commandSocket->readFile( syncFileName() ); | 1020 | commandSocket->readFile( syncFileName() ); |
1018 | } | 1021 | } |
1019 | 1022 | ||
1020 | void KSyncManager::deleteCommandSocket(KCommandSocket*s, int state) | 1023 | void KSyncManager::deleteCommandSocket(KCommandSocket*s, int state) |
1021 | { | 1024 | { |
1022 | //enum { success, errorW, errorR, quiet }; | 1025 | //enum { success, errorW, errorR, quiet }; |
1023 | if ( state == KCommandSocket::errorR ||state == KCommandSocket::errorTO ) { | 1026 | if ( state == KCommandSocket::errorR ||state == KCommandSocket::errorTO ) { |
1024 | mParent->topLevelWidget()->setCaption( i18n("ERROR: Receiving remote file failed.") ); | 1027 | mParent->topLevelWidget()->setCaption( i18n("ERROR: Receiving remote file failed.") ); |
1025 | delete s; | 1028 | delete s; |
1026 | if ( state == KCommandSocket::errorR ) { | 1029 | if ( state == KCommandSocket::errorR ) { |
1027 | KCommandSocket* commandSocket = new KCommandSocket( mPassWordPiSync, mActiveSyncPort.toUInt(), mActiveSyncIP, this ); | 1030 | KCommandSocket* commandSocket = new KCommandSocket( mPassWordPiSync, mActiveSyncPort.toUInt(), mActiveSyncIP, this ); |
1028 | connect( commandSocket, SIGNAL(commandFinished( KCommandSocket*, int)), this, SLOT(deleteCommandSocket(KCommandSocket*, int )) ); | 1031 | connect( commandSocket, SIGNAL(commandFinished( KCommandSocket*, int)), this, SLOT(deleteCommandSocket(KCommandSocket*, int )) ); |
1029 | commandSocket->sendStop(); | 1032 | commandSocket->sendStop(); |
1030 | } | 1033 | } |
1031 | mPisyncFinished = true; | 1034 | mPisyncFinished = true; |
1032 | return; | 1035 | return; |
1033 | 1036 | ||
1034 | } else if ( state == KCommandSocket::errorW ) { | 1037 | } else if ( state == KCommandSocket::errorW ) { |
1035 | mParent->topLevelWidget()->setCaption( i18n("ERROR:Writing back file failed.") ); | 1038 | mParent->topLevelWidget()->setCaption( i18n("ERROR:Writing back file failed.") ); |
1036 | mPisyncFinished = true; | 1039 | mPisyncFinished = true; |
1037 | 1040 | ||
1038 | } else if ( state == KCommandSocket::successR ) { | 1041 | } else if ( state == KCommandSocket::successR ) { |
1039 | QTimer::singleShot( 1, this , SLOT ( readFileFromSocket())); | 1042 | QTimer::singleShot( 1, this , SLOT ( readFileFromSocket())); |
1040 | 1043 | ||
1041 | } else if ( state == KCommandSocket::successW ) { | 1044 | } else if ( state == KCommandSocket::successW ) { |
1042 | mParent->topLevelWidget()->setCaption( i18n("Pi-Sync succesful!") ); | 1045 | mParent->topLevelWidget()->setCaption( i18n("Pi-Sync succesful!") ); |
1043 | mPisyncFinished = true; | 1046 | mPisyncFinished = true; |
1044 | } | 1047 | } |
1045 | 1048 | ||
1046 | delete s; | 1049 | delete s; |
1047 | } | 1050 | } |
1048 | 1051 | ||
1049 | void KSyncManager::readFileFromSocket() | 1052 | void KSyncManager::readFileFromSocket() |
1050 | { | 1053 | { |
1051 | QString fileName = syncFileName(); | 1054 | QString fileName = syncFileName(); |
1052 | mParent->topLevelWidget()->setCaption( i18n("Remote file saved to temp file.") ); | 1055 | mParent->topLevelWidget()->setCaption( i18n("Remote file saved to temp file.") ); |
1053 | if ( ! syncWithFile( fileName , true ) ) { | 1056 | if ( ! syncWithFile( fileName , true ) ) { |
1054 | mParent->topLevelWidget()->setCaption( i18n("Syncing failed.") ); | 1057 | mParent->topLevelWidget()->setCaption( i18n("Syncing failed.") ); |
1055 | mPisyncFinished = true; | 1058 | mPisyncFinished = true; |
1056 | return; | 1059 | return; |
1057 | } | 1060 | } |
1058 | KCommandSocket* commandSocket = new KCommandSocket( mPassWordPiSync, mActiveSyncPort.toUInt(), mActiveSyncIP, this ); | 1061 | KCommandSocket* commandSocket = new KCommandSocket( mPassWordPiSync, mActiveSyncPort.toUInt(), mActiveSyncIP, this ); |
1059 | connect( commandSocket, SIGNAL(commandFinished( KCommandSocket*, int)), this, SLOT(deleteCommandSocket(KCommandSocket*, int )) ); | 1062 | connect( commandSocket, SIGNAL(commandFinished( KCommandSocket*, int)), this, SLOT(deleteCommandSocket(KCommandSocket*, int )) ); |
1060 | if ( mWriteBackFile ) | 1063 | if ( mWriteBackFile ) |
1061 | commandSocket->writeFile( fileName ); | 1064 | commandSocket->writeFile( fileName ); |
1062 | else { | 1065 | else { |
1063 | commandSocket->sendStop(); | 1066 | commandSocket->sendStop(); |
1064 | mParent->topLevelWidget()->setCaption( i18n("Pi-Sync succesful!") ); | 1067 | mParent->topLevelWidget()->setCaption( i18n("Pi-Sync succesful!") ); |
1065 | mPisyncFinished = true; | 1068 | mPisyncFinished = true; |
1066 | } | 1069 | } |
1067 | } | 1070 | } |
1068 | 1071 | ||
1069 | KServerSocket:: KServerSocket ( QString pw, Q_UINT16 port, int backlog, QObject * parent, const char * name ) : QServerSocket( port, backlog, parent, name ) | 1072 | KServerSocket:: KServerSocket ( QString pw, Q_UINT16 port, int backlog, QObject * parent, const char * name ) : QServerSocket( port, backlog, parent, name ) |
1070 | { | 1073 | { |
1071 | mPassWord = pw; | 1074 | mPassWord = pw; |
1072 | mSocket = 0; | 1075 | mSocket = 0; |
1073 | mSyncActionDialog = 0; | 1076 | mSyncActionDialog = 0; |
1074 | blockRC = false; | 1077 | blockRC = false; |
1075 | }; | 1078 | }; |
1076 | 1079 | ||
1077 | void KServerSocket::newConnection ( int socket ) | 1080 | void KServerSocket::newConnection ( int socket ) |
1078 | { | 1081 | { |
1079 | // qDebug("KServerSocket:New connection %d ", socket); | 1082 | // qDebug("KServerSocket:New connection %d ", socket); |
1080 | if ( mSocket ) { | 1083 | if ( mSocket ) { |
1081 | qDebug("KServerSocket::newConnection Socket deleted! "); | 1084 | qDebug("KServerSocket::newConnection Socket deleted! "); |
1082 | delete mSocket; | 1085 | delete mSocket; |
1083 | mSocket = 0; | 1086 | mSocket = 0; |
1084 | } | 1087 | } |
1085 | mSocket = new QSocket( this ); | 1088 | mSocket = new QSocket( this ); |
1086 | connect( mSocket , SIGNAL(readyRead()), this, SLOT(readClient()) ); | 1089 | connect( mSocket , SIGNAL(readyRead()), this, SLOT(readClient()) ); |
1087 | connect( mSocket , SIGNAL(delayedCloseFinished()), this, SLOT(discardClient()) ); | 1090 | connect( mSocket , SIGNAL(delayedCloseFinished()), this, SLOT(discardClient()) ); |
1088 | mSocket->setSocket( socket ); | 1091 | mSocket->setSocket( socket ); |
1089 | } | 1092 | } |
1090 | 1093 | ||
1091 | void KServerSocket::discardClient() | 1094 | void KServerSocket::discardClient() |
1092 | { | 1095 | { |
1093 | //qDebug(" KServerSocket::discardClient()"); | 1096 | //qDebug(" KServerSocket::discardClient()"); |
1094 | if ( mSocket ) { | 1097 | if ( mSocket ) { |
1095 | delete mSocket; | 1098 | delete mSocket; |
1096 | mSocket = 0; | 1099 | mSocket = 0; |
1097 | } | 1100 | } |
1098 | //emit endConnect(); | 1101 | //emit endConnect(); |
1099 | } | 1102 | } |
1100 | void KServerSocket::readClient() | 1103 | void KServerSocket::readClient() |
1101 | { | 1104 | { |
1102 | if ( blockRC ) | 1105 | if ( blockRC ) |
1103 | return; | 1106 | return; |
1104 | if ( mSocket == 0 ) { | 1107 | if ( mSocket == 0 ) { |
1105 | qDebug("ERROR::KServerSocket::readClient(): mSocket == 0 "); | 1108 | qDebug("ERROR::KServerSocket::readClient(): mSocket == 0 "); |
1106 | return; | 1109 | return; |
1107 | } | 1110 | } |
1108 | //qDebug("KServerSocket::readClient()"); | 1111 | //qDebug("KServerSocket::readClient()"); |
1109 | if ( mSocket->canReadLine() ) { | 1112 | if ( mSocket->canReadLine() ) { |
1110 | QString line = mSocket->readLine(); | 1113 | QString line = mSocket->readLine(); |
1111 | //qDebug("KServerSocket readline: %s ", line.latin1()); | 1114 | //qDebug("KServerSocket readline: %s ", line.latin1()); |
1112 | QStringList tokens = QStringList::split( QRegExp("[ \r\n][ \r\n]*"), line ); | 1115 | QStringList tokens = QStringList::split( QRegExp("[ \r\n][ \r\n]*"), line ); |
1113 | if ( tokens[0] == "GET" ) { | 1116 | if ( tokens[0] == "GET" ) { |
1114 | if ( tokens[1] == mPassWord ) | 1117 | if ( tokens[1] == mPassWord ) { |
1115 | //emit sendFile( mSocket ); | 1118 | //emit sendFile( mSocket ); |
1119 | bool ok = false; | ||
1120 | QDateTime dt = KGlobal::locale()->readDateTime( tokens[2], KLocale::ISODate, &ok); | ||
1121 | if ( ok ) | ||
1122 | KSyncManager::mRequestedSyncEvent = dt; | ||
1123 | else | ||
1124 | KSyncManager::mRequestedSyncEvent = QDateTime(); | ||
1116 | send_file(); | 1125 | send_file(); |
1126 | } | ||
1117 | else { | 1127 | else { |
1118 | KMessageBox::error( 0, i18n("Got send file request\nwith invalid password")); | 1128 | KMessageBox::error( 0, i18n("Got send file request\nwith invalid password")); |
1119 | //qDebug("password %s, invalid password %s ",mPassWord.latin1(), tokens[1].latin1() ); | 1129 | //qDebug("password %s, invalid password %s ",mPassWord.latin1(), tokens[1].latin1() ); |
1120 | } | 1130 | } |
1121 | } | 1131 | } |
1122 | if ( tokens[0] == "PUT" ) { | 1132 | if ( tokens[0] == "PUT" ) { |
1123 | if ( tokens[1] == mPassWord ) { | 1133 | if ( tokens[1] == mPassWord ) { |
1124 | //emit getFile( mSocket ); | 1134 | //emit getFile( mSocket ); |
1125 | blockRC = true; | 1135 | blockRC = true; |
1126 | get_file(); | 1136 | get_file(); |
1127 | } | 1137 | } |
1128 | else { | 1138 | else { |
1129 | KMessageBox::error( 0, i18n("Got receive file request\nwith invalid password")); | 1139 | KMessageBox::error( 0, i18n("Got receive file request\nwith invalid password")); |
1130 | //qDebug("password %s, invalid password %s ",mPassWord.latin1(), tokens[1].latin1() ); | 1140 | //qDebug("password %s, invalid password %s ",mPassWord.latin1(), tokens[1].latin1() ); |
1131 | } | 1141 | } |
1132 | } | 1142 | } |
1133 | if ( tokens[0] == "STOP" ) { | 1143 | if ( tokens[0] == "STOP" ) { |
1134 | //emit endConnect(); | 1144 | //emit endConnect(); |
1135 | end_connect(); | 1145 | end_connect(); |
1136 | } | 1146 | } |
1137 | } | 1147 | } |
1138 | } | 1148 | } |
1139 | void KServerSocket::end_connect() | 1149 | void KServerSocket::end_connect() |
1140 | { | 1150 | { |
1141 | delete mSyncActionDialog; | 1151 | delete mSyncActionDialog; |
1142 | mSyncActionDialog = 0; | 1152 | mSyncActionDialog = 0; |
1143 | } | 1153 | } |
1144 | void KServerSocket::send_file() | 1154 | void KServerSocket::send_file() |
1145 | { | 1155 | { |
1146 | //qDebug("MainWindow::sendFile(QSocket* s) "); | 1156 | //qDebug("MainWindow::sendFile(QSocket* s) "); |
1147 | if ( mSyncActionDialog ) | 1157 | if ( mSyncActionDialog ) |
1148 | delete mSyncActionDialog; | 1158 | delete mSyncActionDialog; |
1149 | mSyncActionDialog = new QDialog ( 0, "input-dialog", true ); | 1159 | mSyncActionDialog = new QDialog ( 0, "input-dialog", true ); |
1150 | mSyncActionDialog->setCaption(i18n("Received sync request")); | 1160 | mSyncActionDialog->setCaption(i18n("Received sync request")); |
1151 | QLabel* label = new QLabel( i18n("Synchronizing from remote ...\n\nDo not use this application!\n\nIf syncing fails\nyou can close this dialog."), mSyncActionDialog ); | 1161 | QLabel* label = new QLabel( i18n("Synchronizing from remote ...\n\nDo not use this application!\n\nIf syncing fails\nyou can close this dialog."), mSyncActionDialog ); |
1152 | QVBoxLayout* lay = new QVBoxLayout( mSyncActionDialog ); | 1162 | QVBoxLayout* lay = new QVBoxLayout( mSyncActionDialog ); |
1153 | lay->addWidget( label); | 1163 | lay->addWidget( label); |
1154 | lay->setMargin(7); | 1164 | lay->setMargin(7); |
1155 | lay->setSpacing(7); | 1165 | lay->setSpacing(7); |
1156 | mSyncActionDialog->setFixedSize( 230, 120); | 1166 | mSyncActionDialog->setFixedSize( 230, 120); |
1157 | mSyncActionDialog->show(); | 1167 | mSyncActionDialog->show(); |
1158 | mSyncActionDialog->raise(); | 1168 | mSyncActionDialog->raise(); |
1159 | emit request_file(); | 1169 | emit request_file(); |
1160 | qApp->processEvents(); | 1170 | qApp->processEvents(); |
1161 | QString fileName = mFileName; | 1171 | QString fileName = mFileName; |
1162 | QFile file( fileName ); | 1172 | QFile file( fileName ); |
1163 | if (!file.open( IO_ReadOnly ) ) { | 1173 | if (!file.open( IO_ReadOnly ) ) { |
1164 | delete mSyncActionDialog; | 1174 | delete mSyncActionDialog; |
1165 | mSyncActionDialog = 0; | 1175 | mSyncActionDialog = 0; |
1166 | qDebug("KSS::error open file "); | 1176 | qDebug("KSS::error open file "); |
1167 | mSocket->close(); | 1177 | mSocket->close(); |
1168 | if ( mSocket->state() == QSocket::Idle ) | 1178 | if ( mSocket->state() == QSocket::Idle ) |
1169 | QTimer::singleShot( 10, this , SLOT ( discardClient())); | 1179 | QTimer::singleShot( 10, this , SLOT ( discardClient())); |
1170 | return ; | 1180 | return ; |
1171 | 1181 | ||
1172 | } | 1182 | } |
1173 | mSyncActionDialog->setCaption( i18n("Sending file...") ); | 1183 | mSyncActionDialog->setCaption( i18n("Sending file...") ); |
1174 | QTextStream ts( &file ); | 1184 | QTextStream ts( &file ); |
1175 | ts.setEncoding( QTextStream::Latin1 ); | 1185 | ts.setEncoding( QTextStream::Latin1 ); |
1176 | 1186 | ||
1177 | QTextStream os( mSocket ); | 1187 | QTextStream os( mSocket ); |
1178 | os.setEncoding( QTextStream::Latin1 ); | 1188 | os.setEncoding( QTextStream::Latin1 ); |
1179 | while ( ! ts.atEnd() ) { | 1189 | while ( ! ts.atEnd() ) { |
1180 | os << ts.readLine() << "\r\n"; | 1190 | os << ts.readLine() << "\r\n"; |
1181 | } | 1191 | } |
1182 | //os << ts.read(); | 1192 | //os << ts.read(); |
1183 | file.close(); | 1193 | file.close(); |
1184 | mSyncActionDialog->setCaption( i18n("Waiting for synced file...") ); | 1194 | mSyncActionDialog->setCaption( i18n("Waiting for synced file...") ); |
1185 | mSocket->close(); | 1195 | mSocket->close(); |
1186 | if ( mSocket->state() == QSocket::Idle ) | 1196 | if ( mSocket->state() == QSocket::Idle ) |
1187 | QTimer::singleShot( 10, this , SLOT ( discardClient())); | 1197 | QTimer::singleShot( 10, this , SLOT ( discardClient())); |
1188 | } | 1198 | } |
1189 | void KServerSocket::get_file() | 1199 | void KServerSocket::get_file() |
1190 | { | 1200 | { |
1191 | mSyncActionDialog->setCaption( i18n("Receiving synced file...") ); | 1201 | mSyncActionDialog->setCaption( i18n("Receiving synced file...") ); |
1192 | 1202 | ||
1193 | piTime.start(); | 1203 | piTime.start(); |
1194 | piFileString = ""; | 1204 | piFileString = ""; |
1195 | QTimer::singleShot( 1, this , SLOT (readBackFileFromSocket( ) )); | 1205 | QTimer::singleShot( 1, this , SLOT (readBackFileFromSocket( ) )); |
1196 | } | 1206 | } |
1197 | 1207 | ||
1198 | 1208 | ||
1199 | void KServerSocket::readBackFileFromSocket() | 1209 | void KServerSocket::readBackFileFromSocket() |
1200 | { | 1210 | { |
1201 | //qDebug("readBackFileFromSocket() %d ", piTime.elapsed ()); | 1211 | //qDebug("readBackFileFromSocket() %d ", piTime.elapsed ()); |
1202 | while ( mSocket->canReadLine () ) { | 1212 | while ( mSocket->canReadLine () ) { |
1203 | piTime.restart(); | 1213 | piTime.restart(); |
1204 | QString line = mSocket->readLine (); | 1214 | QString line = mSocket->readLine (); |
1205 | piFileString += line; | 1215 | piFileString += line; |
1206 | //qDebug("readline: %s ", line.latin1()); | 1216 | //qDebug("readline: %s ", line.latin1()); |
1207 | mSyncActionDialog->setCaption( i18n("Received %1 bytes").arg( piFileString.length() ) ); | 1217 | mSyncActionDialog->setCaption( i18n("Received %1 bytes").arg( piFileString.length() ) ); |
1208 | 1218 | ||
1209 | } | 1219 | } |
1210 | if ( piTime.elapsed () < 3000 ) { | 1220 | if ( piTime.elapsed () < 3000 ) { |
1211 | // wait for more | 1221 | // wait for more |
1212 | //qDebug("waitformore "); | 1222 | //qDebug("waitformore "); |
1213 | QTimer::singleShot( 100, this , SLOT (readBackFileFromSocket( ) )); | 1223 | QTimer::singleShot( 100, this , SLOT (readBackFileFromSocket( ) )); |
1214 | return; | 1224 | return; |
1215 | } | 1225 | } |
1216 | QString fileName = mFileName; | 1226 | QString fileName = mFileName; |
1217 | QFile file ( fileName ); | 1227 | QFile file ( fileName ); |
1218 | if (!file.open( IO_WriteOnly ) ) { | 1228 | if (!file.open( IO_WriteOnly ) ) { |
1219 | delete mSyncActionDialog; | 1229 | delete mSyncActionDialog; |
1220 | mSyncActionDialog = 0; | 1230 | mSyncActionDialog = 0; |
1221 | qDebug("KSS:Error open read back file "); | 1231 | qDebug("KSS:Error open read back file "); |
1222 | piFileString = ""; | 1232 | piFileString = ""; |
1223 | emit file_received( false ); | 1233 | emit file_received( false ); |
1224 | blockRC = false; | 1234 | blockRC = false; |
1225 | return ; | 1235 | return ; |
1226 | 1236 | ||
1227 | } | 1237 | } |
1228 | 1238 | ||
1229 | // mView->setLoadedFileVersion(QDateTime::currentDateTime().addSecs( -1)); | 1239 | // mView->setLoadedFileVersion(QDateTime::currentDateTime().addSecs( -1)); |
1230 | QTextStream ts ( &file ); | 1240 | QTextStream ts ( &file ); |
1231 | ts.setEncoding( QTextStream::Latin1 ); | 1241 | ts.setEncoding( QTextStream::Latin1 ); |
1232 | mSyncActionDialog->setCaption( i18n("Writing file to disk...") ); | 1242 | mSyncActionDialog->setCaption( i18n("Writing file to disk...") ); |
1233 | ts << piFileString; | 1243 | ts << piFileString; |
1234 | mSocket->close(); | 1244 | mSocket->close(); |
1235 | if ( mSocket->state() == QSocket::Idle ) | 1245 | if ( mSocket->state() == QSocket::Idle ) |
1236 | QTimer::singleShot( 10, this , SLOT ( discardClient())); | 1246 | QTimer::singleShot( 10, this , SLOT ( discardClient())); |
1237 | file.close(); | 1247 | file.close(); |
1238 | piFileString = ""; | 1248 | piFileString = ""; |
1239 | emit file_received( true ); | 1249 | emit file_received( true ); |
1240 | delete mSyncActionDialog; | 1250 | delete mSyncActionDialog; |
1241 | mSyncActionDialog = 0; | 1251 | mSyncActionDialog = 0; |
1242 | blockRC = false; | 1252 | blockRC = false; |
1243 | 1253 | ||
1244 | } | 1254 | } |
1245 | 1255 | ||
1246 | KCommandSocket::KCommandSocket ( QString password, Q_UINT16 port, QString host, QObject * parent, const char * name ): QObject( parent, name ) | 1256 | KCommandSocket::KCommandSocket ( QString password, Q_UINT16 port, QString host, QObject * parent, const char * name ): QObject( parent, name ) |
1247 | { | 1257 | { |
1248 | mPassWord = password; | 1258 | mPassWord = password; |
1249 | mSocket = 0; | 1259 | mSocket = 0; |
1250 | mPort = port; | 1260 | mPort = port; |
1251 | mHost = host; | 1261 | mHost = host; |
1252 | 1262 | ||
1253 | mRetVal = quiet; | 1263 | mRetVal = quiet; |
1254 | mTimerSocket = new QTimer ( this ); | 1264 | mTimerSocket = new QTimer ( this ); |
1255 | connect( mTimerSocket, SIGNAL ( timeout () ), this, SLOT ( deleteSocket() ) ); | 1265 | connect( mTimerSocket, SIGNAL ( timeout () ), this, SLOT ( deleteSocket() ) ); |
1256 | } | 1266 | } |
1257 | void KCommandSocket::readFile( QString fn ) | 1267 | void KCommandSocket::readFile( QString fn ) |
1258 | { | 1268 | { |
1259 | if ( !mSocket ) { | 1269 | if ( !mSocket ) { |
1260 | mSocket = new QSocket( this ); | 1270 | mSocket = new QSocket( this ); |
1261 | connect( mSocket, SIGNAL(readyRead()), this, SLOT(startReadFileFromSocket()) ); | 1271 | connect( mSocket, SIGNAL(readyRead()), this, SLOT(startReadFileFromSocket()) ); |
1262 | connect( mSocket, SIGNAL(delayedCloseFinished ()), this, SLOT(deleteSocket()) ); | 1272 | connect( mSocket, SIGNAL(delayedCloseFinished ()), this, SLOT(deleteSocket()) ); |
1263 | } | 1273 | } |
1264 | mFileString = ""; | 1274 | mFileString = ""; |
1265 | mFileName = fn; | 1275 | mFileName = fn; |
1266 | mFirst = true; | 1276 | mFirst = true; |
1267 | mSocket->connectToHost( mHost, mPort ); | 1277 | mSocket->connectToHost( mHost, mPort ); |
1268 | QTextStream os( mSocket ); | 1278 | QTextStream os( mSocket ); |
1269 | os.setEncoding( QTextStream::Latin1 ); | 1279 | os.setEncoding( QTextStream::Latin1 ); |
1270 | os << "GET " << mPassWord << "\r\n"; | 1280 | |
1281 | QString curDt = KGlobal::locale()->formatDateTime(QDateTime::currentDateTime().addSecs(-1),true, true,KLocale::ISODate ); | ||
1282 | os << "GET " << mPassWord << curDt <<"\r\n"; | ||
1271 | mTimerSocket->start( 20000 ); | 1283 | mTimerSocket->start( 20000 ); |
1272 | } | 1284 | } |
1273 | 1285 | ||
1274 | void KCommandSocket::writeFile( QString fileName ) | 1286 | void KCommandSocket::writeFile( QString fileName ) |
1275 | { | 1287 | { |
1276 | if ( !mSocket ) { | 1288 | if ( !mSocket ) { |
1277 | mSocket = new QSocket( this ); | 1289 | mSocket = new QSocket( this ); |
1278 | connect( mSocket, SIGNAL(delayedCloseFinished ()), this, SLOT(deleteSocket()) ); | 1290 | connect( mSocket, SIGNAL(delayedCloseFinished ()), this, SLOT(deleteSocket()) ); |
1279 | connect( mSocket, SIGNAL(connected ()), this, SLOT(writeFileToSocket()) ); | 1291 | connect( mSocket, SIGNAL(connected ()), this, SLOT(writeFileToSocket()) ); |
1280 | } | 1292 | } |
1281 | mFileName = fileName ; | 1293 | mFileName = fileName ; |
1282 | mSocket->connectToHost( mHost, mPort ); | 1294 | mSocket->connectToHost( mHost, mPort ); |
1283 | } | 1295 | } |
1284 | void KCommandSocket::writeFileToSocket() | 1296 | void KCommandSocket::writeFileToSocket() |
1285 | { | 1297 | { |
1286 | QFile file2( mFileName ); | 1298 | QFile file2( mFileName ); |
1287 | if (!file2.open( IO_ReadOnly ) ) { | 1299 | if (!file2.open( IO_ReadOnly ) ) { |
1288 | mRetVal= errorW; | 1300 | mRetVal= errorW; |
1289 | mSocket->close(); | 1301 | mSocket->close(); |
1290 | if ( mSocket->state() == QSocket::Idle ) | 1302 | if ( mSocket->state() == QSocket::Idle ) |
1291 | QTimer::singleShot( 10, this , SLOT ( deleteSocket())); | 1303 | QTimer::singleShot( 10, this , SLOT ( deleteSocket())); |
1292 | return ; | 1304 | return ; |
1293 | } | 1305 | } |
1294 | QTextStream ts2( &file2 ); | 1306 | QTextStream ts2( &file2 ); |
1295 | ts2.setEncoding( QTextStream::Latin1 ); | 1307 | ts2.setEncoding( QTextStream::Latin1 ); |
1296 | QTextStream os2( mSocket ); | 1308 | QTextStream os2( mSocket ); |
1297 | os2.setEncoding( QTextStream::Latin1 ); | 1309 | os2.setEncoding( QTextStream::Latin1 ); |
1298 | os2 << "PUT " << mPassWord << "\r\n";; | 1310 | os2 << "PUT " << mPassWord << "\r\n";; |
1299 | while ( ! ts2.atEnd() ) { | 1311 | while ( ! ts2.atEnd() ) { |
1300 | os2 << ts2.readLine() << "\r\n"; | 1312 | os2 << ts2.readLine() << "\r\n"; |
1301 | } | 1313 | } |
1302 | mRetVal= successW; | 1314 | mRetVal= successW; |
1303 | file2.close(); | 1315 | file2.close(); |
1304 | mSocket->close(); | 1316 | mSocket->close(); |
1305 | if ( mSocket->state() == QSocket::Idle ) | 1317 | if ( mSocket->state() == QSocket::Idle ) |
1306 | QTimer::singleShot( 10, this , SLOT ( deleteSocket())); | 1318 | QTimer::singleShot( 10, this , SLOT ( deleteSocket())); |
1307 | } | 1319 | } |
1308 | void KCommandSocket::sendStop() | 1320 | void KCommandSocket::sendStop() |
1309 | { | 1321 | { |
1310 | if ( !mSocket ) { | 1322 | if ( !mSocket ) { |
1311 | mSocket = new QSocket( this ); | 1323 | mSocket = new QSocket( this ); |
1312 | connect( mSocket, SIGNAL(delayedCloseFinished ()), this, SLOT(deleteSocket()) ); | 1324 | connect( mSocket, SIGNAL(delayedCloseFinished ()), this, SLOT(deleteSocket()) ); |
1313 | } | 1325 | } |
1314 | mSocket->connectToHost( mHost, mPort ); | 1326 | mSocket->connectToHost( mHost, mPort ); |
1315 | QTextStream os2( mSocket ); | 1327 | QTextStream os2( mSocket ); |
1316 | os2.setEncoding( QTextStream::Latin1 ); | 1328 | os2.setEncoding( QTextStream::Latin1 ); |
1317 | os2 << "STOP\r\n"; | 1329 | os2 << "STOP\r\n"; |
1318 | mSocket->close(); | 1330 | mSocket->close(); |
1319 | if ( mSocket->state() == QSocket::Idle ) | 1331 | if ( mSocket->state() == QSocket::Idle ) |
1320 | QTimer::singleShot( 10, this , SLOT ( deleteSocket())); | 1332 | QTimer::singleShot( 10, this , SLOT ( deleteSocket())); |
1321 | } | 1333 | } |
1322 | 1334 | ||
1323 | void KCommandSocket::startReadFileFromSocket() | 1335 | void KCommandSocket::startReadFileFromSocket() |
1324 | { | 1336 | { |
1325 | if ( ! mFirst ) | 1337 | if ( ! mFirst ) |
1326 | return; | 1338 | return; |
1327 | mFirst = false; | 1339 | mFirst = false; |
1328 | mTimerSocket->stop(); | 1340 | mTimerSocket->stop(); |
1329 | mFileString = ""; | 1341 | mFileString = ""; |
1330 | mTime.start(); | 1342 | mTime.start(); |
1331 | QTimer::singleShot( 1, this , SLOT (readFileFromSocket( ) )); | 1343 | QTimer::singleShot( 1, this , SLOT (readFileFromSocket( ) )); |
1332 | 1344 | ||
1333 | } | 1345 | } |
1334 | void KCommandSocket::readFileFromSocket() | 1346 | void KCommandSocket::readFileFromSocket() |
1335 | { | 1347 | { |
1336 | //qDebug("readBackFileFromSocket() %d ", mTime.elapsed ()); | 1348 | //qDebug("readBackFileFromSocket() %d ", mTime.elapsed ()); |
1337 | while ( mSocket->canReadLine () ) { | 1349 | while ( mSocket->canReadLine () ) { |
1338 | mTime.restart(); | 1350 | mTime.restart(); |
1339 | QString line = mSocket->readLine (); | 1351 | QString line = mSocket->readLine (); |
1340 | mFileString += line; | 1352 | mFileString += line; |
1341 | //qDebug("readline: %s ", line.latin1()); | 1353 | //qDebug("readline: %s ", line.latin1()); |
1342 | } | 1354 | } |
1343 | if ( mTime.elapsed () < 3000 ) { | 1355 | if ( mTime.elapsed () < 3000 ) { |
1344 | // wait for more | 1356 | // wait for more |
1345 | //qDebug("waitformore "); | 1357 | //qDebug("waitformore "); |
1346 | QTimer::singleShot( 100, this , SLOT (readFileFromSocket( ) )); | 1358 | QTimer::singleShot( 100, this , SLOT (readFileFromSocket( ) )); |
1347 | return; | 1359 | return; |
1348 | } | 1360 | } |
1349 | QString fileName = mFileName; | 1361 | QString fileName = mFileName; |
1350 | QFile file ( fileName ); | 1362 | QFile file ( fileName ); |
1351 | if (!file.open( IO_WriteOnly ) ) { | 1363 | if (!file.open( IO_WriteOnly ) ) { |
1352 | mFileString = ""; | 1364 | mFileString = ""; |
1353 | mRetVal = errorR; | 1365 | mRetVal = errorR; |
1354 | qDebug("KSS:Error open temp sync file for writing: %s",fileName.latin1() ); | 1366 | qDebug("KSS:Error open temp sync file for writing: %s",fileName.latin1() ); |
1355 | deleteSocket(); | 1367 | deleteSocket(); |
1356 | return ; | 1368 | return ; |
1357 | 1369 | ||
1358 | } | 1370 | } |
1359 | // mView->setLoadedFileVersion(QDateTime::currentDateTime().addSecs( -1)); | 1371 | // mView->setLoadedFileVersion(QDateTime::currentDateTime().addSecs( -1)); |
1360 | QTextStream ts ( &file ); | 1372 | QTextStream ts ( &file ); |
1361 | ts.setEncoding( QTextStream::Latin1 ); | 1373 | ts.setEncoding( QTextStream::Latin1 ); |
1362 | ts << mFileString; | 1374 | ts << mFileString; |
1363 | file.close(); | 1375 | file.close(); |
1364 | mFileString = ""; | 1376 | mFileString = ""; |
1365 | mRetVal = successR; | 1377 | mRetVal = successR; |
1366 | mSocket->close(); | 1378 | mSocket->close(); |
1367 | // if state is not idle, deleteSocket(); is called via | 1379 | // if state is not idle, deleteSocket(); is called via |
1368 | // connect( mSocket, SIGNAL(delayedCloseFinished ()), this, SLOT(deleteSocket()) ); | 1380 | // connect( mSocket, SIGNAL(delayedCloseFinished ()), this, SLOT(deleteSocket()) ); |
1369 | if ( mSocket->state() == QSocket::Idle ) | 1381 | if ( mSocket->state() == QSocket::Idle ) |
1370 | deleteSocket(); | 1382 | deleteSocket(); |
1371 | } | 1383 | } |
1372 | 1384 | ||
1373 | void KCommandSocket::deleteSocket() | 1385 | void KCommandSocket::deleteSocket() |
1374 | { | 1386 | { |
1375 | //qDebug("KCommandSocket::deleteSocket() "); | 1387 | //qDebug("KCommandSocket::deleteSocket() "); |
1376 | if ( mTimerSocket->isActive () ) { | 1388 | if ( mTimerSocket->isActive () ) { |
1377 | mTimerSocket->stop(); | 1389 | mTimerSocket->stop(); |
1378 | mRetVal = errorTO; | 1390 | mRetVal = errorTO; |
1379 | qDebug("Connection to remote host timed out"); | 1391 | qDebug("Connection to remote host timed out"); |
1380 | if ( mSocket ) { | 1392 | if ( mSocket ) { |
1381 | mSocket->close(); | 1393 | mSocket->close(); |
1382 | //if ( mSocket->state() == QSocket::Idle ) | 1394 | //if ( mSocket->state() == QSocket::Idle ) |
1383 | // deleteSocket(); | 1395 | // deleteSocket(); |
1384 | delete mSocket; | 1396 | delete mSocket; |
1385 | mSocket = 0; | 1397 | mSocket = 0; |
1386 | } | 1398 | } |
1387 | KMessageBox::error( 0, i18n("Connection to remote\nhost timed out!\nDid you forgot to enable\nsyncing on remote host? ")); | 1399 | KMessageBox::error( 0, i18n("Connection to remote\nhost timed out!\nDid you forgot to enable\nsyncing on remote host? ")); |
1388 | emit commandFinished( this, mRetVal ); | 1400 | emit commandFinished( this, mRetVal ); |
1389 | return; | 1401 | return; |
1390 | } | 1402 | } |
1391 | //qDebug("KCommandSocket::deleteSocket() %d", mRetVal ); | 1403 | //qDebug("KCommandSocket::deleteSocket() %d", mRetVal ); |
1392 | if ( mSocket) | 1404 | if ( mSocket) |
1393 | delete mSocket; | 1405 | delete mSocket; |
1394 | mSocket = 0; | 1406 | mSocket = 0; |
1395 | emit commandFinished( this, mRetVal ); | 1407 | emit commandFinished( this, mRetVal ); |
1396 | } | 1408 | } |