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