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