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