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