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