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