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