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