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