summaryrefslogtreecommitdiffabout
path: root/libkdepim/ksyncmanager.cpp
authorzautrix <zautrix>2005-02-09 19:31:50 (UTC)
committer zautrix <zautrix>2005-02-09 19:31:50 (UTC)
commita9eff860d8399a198a9fdc04e09ed369097fc745 (patch) (unidiff)
treec953f38ef75bed96bdedd61b1b4bf369e08cddee /libkdepim/ksyncmanager.cpp
parent22d5db839c9741cb2e988e84bbb367617934ebd9 (diff)
downloadkdepimpi-a9eff860d8399a198a9fdc04e09ed369097fc745.zip
kdepimpi-a9eff860d8399a198a9fdc04e09ed369097fc745.tar.gz
kdepimpi-a9eff860d8399a198a9fdc04e09ed369097fc745.tar.bz2
fixes
Diffstat (limited to 'libkdepim/ksyncmanager.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r--libkdepim/ksyncmanager.cpp13
1 files changed, 8 insertions, 5 deletions
diff --git a/libkdepim/ksyncmanager.cpp b/libkdepim/ksyncmanager.cpp
index 9177f63..c8d0e0d 100644
--- a/libkdepim/ksyncmanager.cpp
+++ b/libkdepim/ksyncmanager.cpp
@@ -1,212 +1,216 @@
1/* 1/*
2 This file is part of KDE-Pim/Pi. 2 This file is part of KDE-Pim/Pi.
3 Copyright (c) 2004 Ulf Schenk 3 Copyright (c) 2004 Ulf Schenk
4 4
5 This library is free software; you can redistribute it and/or 5 This library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Library General Public 6 modify it under the terms of the GNU Library General Public
7 License as published by the Free Software Foundation; either 7 License as published by the Free Software Foundation; either
8 version 2 of the License, or (at your option) any later version. 8 version 2 of the License, or (at your option) any later version.
9 9
10 This library is distributed in the hope that it will be useful, 10 This library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of 11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Library General Public License for more details. 13 Library General Public License for more details.
14 14
15 You should have received a copy of the GNU Library General Public License 15 You should have received a copy of the GNU Library General Public License
16 along with this library; see the file COPYING.LIB. If not, write to 16 along with this library; see the file COPYING.LIB. If not, write to
17 the Free Software Foundation, Inc., 59 Temple Place - Suite 330, 17 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18 Boston, MA 02111-1307, USA. 18 Boston, MA 02111-1307, USA.
19*/ 19*/
20 20
21// $Id$ 21// $Id$
22 22
23#include "ksyncmanager.h" 23#include "ksyncmanager.h"
24 24
25#include <stdlib.h> 25#include <stdlib.h>
26 26
27#ifndef _WIN32_ 27#ifndef _WIN32_
28#include <unistd.h> 28#include <unistd.h>
29#endif 29#endif
30 30
31 31
32#include "ksyncprofile.h" 32#include "ksyncprofile.h"
33#include "ksyncprefsdialog.h" 33#include "ksyncprefsdialog.h"
34#include "kpimprefs.h" 34#include "kpimprefs.h"
35#include <kmessagebox.h> 35#include <kmessagebox.h>
36 36
37#include <qdir.h> 37#include <qdir.h>
38#include <qprogressbar.h> 38#include <qprogressbar.h>
39#include <qpopupmenu.h> 39#include <qpopupmenu.h>
40#include <qpushbutton.h> 40#include <qpushbutton.h>
41#include <qradiobutton.h> 41#include <qradiobutton.h>
42#include <qbuttongroup.h> 42#include <qbuttongroup.h>
43#include <qtimer.h> 43#include <qtimer.h>
44#include <qmessagebox.h> 44#include <qmessagebox.h>
45#include <qapplication.h> 45#include <qapplication.h>
46#include <qlineedit.h> 46#include <qlineedit.h>
47#include <qdialog.h> 47#include <qdialog.h>
48#include <qlayout.h> 48#include <qlayout.h>
49#include <qtextcodec.h> 49#include <qtextcodec.h>
50#include <qlabel.h> 50#include <qlabel.h>
51#include <qcheckbox.h> 51#include <qcheckbox.h>
52 52
53#include <klocale.h> 53#include <klocale.h>
54#include <kglobal.h> 54#include <kglobal.h>
55#include <kconfig.h> 55#include <kconfig.h>
56#include <kfiledialog.h> 56#include <kfiledialog.h>
57 57
58QDateTime KSyncManager::mRequestedSyncEvent; 58QDateTime KSyncManager::mRequestedSyncEvent;
59 59
60 60
61KSyncManager::KSyncManager(QWidget* parent, KSyncInterface* implementation, TargetApp ta, KPimPrefs* prefs, QPopupMenu* syncmenu) 61KSyncManager::KSyncManager(QWidget* parent, KSyncInterface* implementation, TargetApp ta, KPimPrefs* prefs, QPopupMenu* syncmenu)
62 : QObject(), mPrefs(prefs ), mParent(parent),mImplementation(implementation), mTargetApp(ta), mSyncMenu(syncmenu) 62 : QObject(), mPrefs(prefs ), mParent(parent),mImplementation(implementation), mTargetApp(ta), mSyncMenu(syncmenu)
63{ 63{
64 mServerSocket = 0; 64 mServerSocket = 0;
65 bar = new QProgressBar ( 1, 0 ); 65 bar = new QProgressBar ( 1, 0 );
66 bar->setCaption (""); 66 bar->setCaption ("");
67 mWriteBackInPast = 2; 67 mWriteBackInPast = 2;
68 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 )
76 enableQuick( false );
77 75
78} 76}
79 77
80KSyncManager::~KSyncManager() 78KSyncManager::~KSyncManager()
81{ 79{
82 delete bar; 80 delete bar;
83} 81}
84 82
83void KSyncManager::setDefaultFileName( QString s)
84{
85 mDefFileName = s ;
86 if ( mPrefs->mPassiveSyncAutoStart )
87 enableQuick( false );
88}
85 89
86void KSyncManager::fillSyncMenu() 90void KSyncManager::fillSyncMenu()
87{ 91{
88 if ( mSyncMenu->count() ) 92 if ( mSyncMenu->count() )
89 mSyncMenu->clear(); 93 mSyncMenu->clear();
90 94
91 mSyncMenu->insertItem( i18n("Configure..."), 0 ); 95 mSyncMenu->insertItem( i18n("Configure..."), 0 );
92 mSyncMenu->insertSeparator(); 96 mSyncMenu->insertSeparator();
93 QPopupMenu *clearMenu = new QPopupMenu ( mSyncMenu ); 97 QPopupMenu *clearMenu = new QPopupMenu ( mSyncMenu );
94 mSyncMenu->insertItem( i18n("Remove sync info"),clearMenu, 5000 ); 98 mSyncMenu->insertItem( i18n("Remove sync info"),clearMenu, 5000 );
95 clearMenu->insertItem( i18n("For all profiles"), 1 ); 99 clearMenu->insertItem( i18n("For all profiles"), 1 );
96 clearMenu->insertSeparator(); 100 clearMenu->insertSeparator();
97 connect ( clearMenu, SIGNAL( activated ( int ) ), this, SLOT (slotClearMenu( int ) ) ); 101 connect ( clearMenu, SIGNAL( activated ( int ) ), this, SLOT (slotClearMenu( int ) ) );
98 mSyncMenu->insertSeparator(); 102 mSyncMenu->insertSeparator();
99 if ( mServerSocket == 0 ) { 103 if ( mServerSocket == 0 ) {
100 mSyncMenu->insertItem( i18n("Enable Pi-Sync"), 2 ); 104 mSyncMenu->insertItem( i18n("Enable Pi-Sync"), 2 );
101 } else { 105 } else {
102 mSyncMenu->insertItem( i18n("Disable Pi-Sync"), 3 ); 106 mSyncMenu->insertItem( i18n("Disable Pi-Sync"), 3 );
103 } 107 }
104 mSyncMenu->insertSeparator(); 108 mSyncMenu->insertSeparator();
105 mSyncMenu->insertItem( i18n("Multiple sync"), 1 ); 109 mSyncMenu->insertItem( i18n("Multiple sync"), 1 );
106 mSyncMenu->insertSeparator(); 110 mSyncMenu->insertSeparator();
107 KConfig config ( locateLocal( "config","ksyncprofilesrc" ) ); 111 KConfig config ( locateLocal( "config","ksyncprofilesrc" ) );
108 config.setGroup("General"); 112 config.setGroup("General");
109 QStringList prof = config.readListEntry("SyncProfileNames"); 113 QStringList prof = config.readListEntry("SyncProfileNames");
110 mLocalMachineName = config.readEntry("LocalMachineName","undefined"); 114 mLocalMachineName = config.readEntry("LocalMachineName","undefined");
111 if ( prof.count() < 2 ) { 115 if ( prof.count() < 2 ) {
112 prof.clear(); 116 prof.clear();
113 QString externalName; 117 QString externalName;
114#ifdef DESKTOP_VERSION 118#ifdef DESKTOP_VERSION
115#ifdef _WIN32_ 119#ifdef _WIN32_
116 externalName = "OutLook(not_implemented)"; 120 externalName = "OutLook(not_implemented)";
117#else 121#else
118 externalName = "KDE_Desktop"; 122 externalName = "KDE_Desktop";
119#endif 123#endif
120#else 124#else
121 externalName = "Sharp_DTM"; 125 externalName = "Sharp_DTM";
122#endif 126#endif
123 prof << externalName; 127 prof << externalName;
124 prof << i18n("Local_file"); 128 prof << i18n("Local_file");
125 prof << i18n("Last_file"); 129 prof << i18n("Last_file");
126 KSyncProfile* temp = new KSyncProfile (); 130 KSyncProfile* temp = new KSyncProfile ();
127 temp->setName( prof[0] ); 131 temp->setName( prof[0] );
128 temp->writeConfig(&config); 132 temp->writeConfig(&config);
129 temp->setName( prof[1] ); 133 temp->setName( prof[1] );
130 temp->writeConfig(&config); 134 temp->writeConfig(&config);
131 temp->setName( prof[2] ); 135 temp->setName( prof[2] );
132 temp->writeConfig(&config); 136 temp->writeConfig(&config);
133 config.setGroup("General"); 137 config.setGroup("General");
134 config.writeEntry("SyncProfileNames",prof); 138 config.writeEntry("SyncProfileNames",prof);
135 config.writeEntry("ExternSyncProfiles",externalName); 139 config.writeEntry("ExternSyncProfiles",externalName);
136 config.sync(); 140 config.sync();
137 delete temp; 141 delete temp;
138 } 142 }
139 mExternSyncProfiles = config.readListEntry("ExternSyncProfiles"); 143 mExternSyncProfiles = config.readListEntry("ExternSyncProfiles");
140 mSyncProfileNames = prof; 144 mSyncProfileNames = prof;
141 unsigned int i; 145 unsigned int i;
142 for ( i = 0; i < prof.count(); ++i ) { 146 for ( i = 0; i < prof.count(); ++i ) {
143 mSyncMenu->insertItem( prof[i], 1000+i ); 147 mSyncMenu->insertItem( prof[i], 1000+i );
144 clearMenu->insertItem( prof[i], 1000+i ); 148 clearMenu->insertItem( prof[i], 1000+i );
145 if ( i == 2 ) 149 if ( i == 2 )
146 mSyncMenu->insertSeparator(); 150 mSyncMenu->insertSeparator();
147 } 151 }
148 QDir app_dir; 152 QDir app_dir;
149 //US do not display SharpDTM if app is pwmpi, or no sharpfiles available 153 //US do not display SharpDTM if app is pwmpi, or no sharpfiles available
150 if ( mTargetApp == PWMPI) { 154 if ( mTargetApp == PWMPI) {
151 mSyncMenu->removeItem( 1000 ); 155 mSyncMenu->removeItem( 1000 );
152 clearMenu->removeItem( 1000 ); 156 clearMenu->removeItem( 1000 );
153 } 157 }
154#ifndef DESKTOP_VERSION 158#ifndef DESKTOP_VERSION
155 else if (!app_dir.exists(QDir::homeDirPath()+"/Applications/dtm" ) ) { 159 else if (!app_dir.exists(QDir::homeDirPath()+"/Applications/dtm" ) ) {
156 mSyncMenu->removeItem( 1000 ); 160 mSyncMenu->removeItem( 1000 );
157 clearMenu->removeItem( 1000 ); 161 clearMenu->removeItem( 1000 );
158 } 162 }
159#endif 163#endif
160 mSyncMenu->removeItem( 1002 ); 164 mSyncMenu->removeItem( 1002 );
161 clearMenu->removeItem( 1002 ); 165 clearMenu->removeItem( 1002 );
162} 166}
163void KSyncManager::slotClearMenu( int action ) 167void KSyncManager::slotClearMenu( int action )
164{ 168{
165 QString syncDevice; 169 QString syncDevice;
166 if ( action > 999 ) { 170 if ( action > 999 ) {
167 syncDevice = mSyncProfileNames[action - 1000] ; 171 syncDevice = mSyncProfileNames[action - 1000] ;
168 } 172 }
169 173
170 174
171 175
172 int result = 0; 176 int result = 0;
173 QString sd; 177 QString sd;
174 if ( syncDevice.isEmpty() ) 178 if ( syncDevice.isEmpty() )
175 sd = i18n("Do you want to\nclear all sync info\nof all profiles?"); 179 sd = i18n("Do you want to\nclear all sync info\nof all profiles?");
176 else 180 else
177 sd = i18n("Do you want to\nclear the sync\ninfo of profile\n%1?\n"). arg( syncDevice ); 181 sd = i18n("Do you want to\nclear the sync\ninfo of profile\n%1?\n"). arg( syncDevice );
178 182
179 result = QMessageBox::warning( mParent, i18n("Warning!"),sd,i18n("OK"), i18n("Cancel"), 0, 183 result = QMessageBox::warning( mParent, i18n("Warning!"),sd,i18n("OK"), i18n("Cancel"), 0,
180 0, 1 ); 184 0, 1 );
181 if ( result ) 185 if ( result )
182 return; 186 return;
183 mImplementation->removeSyncInfo( syncDevice ); 187 mImplementation->removeSyncInfo( syncDevice );
184} 188}
185void KSyncManager::slotSyncMenu( int action ) 189void KSyncManager::slotSyncMenu( int action )
186{ 190{
187 qDebug("KSM::syncaction %d ", action); 191 qDebug("KSM::syncaction %d ", action);
188 if ( action == 5000 ) 192 if ( action == 5000 )
189 return; 193 return;
190 mSyncWithDesktop = false; 194 mSyncWithDesktop = false;
191 if ( action == 0 ) { 195 if ( action == 0 ) {
192 196
193 // seems to be a Qt2 event handling bug 197 // seems to be a Qt2 event handling bug
194 // syncmenu.clear causes a segfault at first time 198 // syncmenu.clear causes a segfault at first time
195 // when we call it after the main event loop, it is ok 199 // 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 200 // same behaviour when calling OM/Pi via QCOP for the first time
197 QTimer::singleShot ( 1, this, SLOT ( confSync() ) ); 201 QTimer::singleShot ( 1, this, SLOT ( confSync() ) );
198 //confSync(); 202 //confSync();
199 203
200 return; 204 return;
201 } 205 }
202 if ( action == 1 ) { 206 if ( action == 1 ) {
203 multiSync( true ); 207 multiSync( true );
204 return; 208 return;
205 } 209 }
206 if ( action == 2 ) { 210 if ( action == 2 ) {
207 enableQuick(); 211 enableQuick();
208 QTimer::singleShot ( 1, this, SLOT ( fillSyncMenu() ) ); 212 QTimer::singleShot ( 1, this, SLOT ( fillSyncMenu() ) );
209 return; 213 return;
210 } 214 }
211 if ( action == 3 ) { 215 if ( action == 3 ) {
212 delete mServerSocket; 216 delete mServerSocket;
@@ -287,257 +291,256 @@ void KSyncManager::slotSyncMenu( int action )
287 if ( syncWithFile( temp->getRemoteFileName( ), false ) ) 291 if ( syncWithFile( temp->getRemoteFileName( ), false ) )
288 mPrefs->mLastSyncedLocalFile = temp->getRemoteFileName(); 292 mPrefs->mLastSyncedLocalFile = temp->getRemoteFileName();
289 break; 293 break;
290 case (PWMPI): 294 case (PWMPI):
291 if ( syncWithFile( temp->getRemoteFileNamePWM( ), false ) ) 295 if ( syncWithFile( temp->getRemoteFileNamePWM( ), false ) )
292 mPrefs->mLastSyncedLocalFile = temp->getRemoteFileNamePWM(); 296 mPrefs->mLastSyncedLocalFile = temp->getRemoteFileNamePWM();
293 break; 297 break;
294 default: 298 default:
295 qDebug("KSM::slotSyncMenu: invalid apptype selected"); 299 qDebug("KSM::slotSyncMenu: invalid apptype selected");
296 break; 300 break;
297 301
298 } 302 }
299 } else { 303 } else {
300 if ( temp->getIsPhoneSync() ) { 304 if ( temp->getIsPhoneSync() ) {
301 mPhoneDevice = temp->getPhoneDevice( ) ; 305 mPhoneDevice = temp->getPhoneDevice( ) ;
302 mPhoneConnection = temp->getPhoneConnection( ); 306 mPhoneConnection = temp->getPhoneConnection( );
303 mPhoneModel = temp->getPhoneModel( ); 307 mPhoneModel = temp->getPhoneModel( );
304 syncPhone(); 308 syncPhone();
305 } else if ( temp->getIsPiSync() ) { 309 } else if ( temp->getIsPiSync() ) {
306 if ( mTargetApp == KAPI ) { 310 if ( mTargetApp == KAPI ) {
307 mPassWordPiSync = temp->getRemotePwAB(); 311 mPassWordPiSync = temp->getRemotePwAB();
308 mActiveSyncPort = temp->getRemotePortAB(); 312 mActiveSyncPort = temp->getRemotePortAB();
309 mActiveSyncIP = temp->getRemoteIPAB(); 313 mActiveSyncIP = temp->getRemoteIPAB();
310 } else if ( mTargetApp == KOPI ) { 314 } else if ( mTargetApp == KOPI ) {
311 mPassWordPiSync = temp->getRemotePw(); 315 mPassWordPiSync = temp->getRemotePw();
312 mActiveSyncPort = temp->getRemotePort(); 316 mActiveSyncPort = temp->getRemotePort();
313 mActiveSyncIP = temp->getRemoteIP(); 317 mActiveSyncIP = temp->getRemoteIP();
314 } else { 318 } else {
315 mPassWordPiSync = temp->getRemotePwPWM(); 319 mPassWordPiSync = temp->getRemotePwPWM();
316 mActiveSyncPort = temp->getRemotePortPWM(); 320 mActiveSyncPort = temp->getRemotePortPWM();
317 mActiveSyncIP = temp->getRemoteIPPWM(); 321 mActiveSyncIP = temp->getRemoteIPPWM();
318 } 322 }
319 syncPi(); 323 syncPi();
320 while ( !mPisyncFinished ) { 324 while ( !mPisyncFinished ) {
321 //qDebug("waiting "); 325 //qDebug("waiting ");
322 qApp->processEvents(); 326 qApp->processEvents();
323 } 327 }
324 } else 328 } else
325 syncRemote( temp ); 329 syncRemote( temp );
326 330
327 } 331 }
328 } 332 }
329 delete temp; 333 delete temp;
330 setBlockSave(false); 334 setBlockSave(false);
331} 335}
332 336
333void KSyncManager::enableQuick( bool ask ) 337void KSyncManager::enableQuick( bool ask )
334{ 338{
335 bool autoStart; 339 bool autoStart;
336 bool changed = false; 340 bool changed = false;
337 if ( ask ) { 341 if ( ask ) {
338 QDialog dia ( 0, "input-dialog", true ); 342 QDialog dia ( 0, "input-dialog", true );
339 QLineEdit lab ( &dia ); 343 QLineEdit lab ( &dia );
340 QVBoxLayout lay( &dia ); 344 QVBoxLayout lay( &dia );
341 lab.setText( mPrefs->mPassiveSyncPort ); 345 lab.setText( mPrefs->mPassiveSyncPort );
342 lay.setMargin(7); 346 lay.setMargin(7);
343 lay.setSpacing(7); 347 lay.setSpacing(7);
344 int po = 9197+mTargetApp; 348 int po = 9197+mTargetApp;
345 QLabel label ( i18n("Port number (Default: %1)").arg(po), &dia ); 349 QLabel label ( i18n("Port number (Default: %1)").arg(po), &dia );
346 lay.addWidget( &label); 350 lay.addWidget( &label);
347 lay.addWidget( &lab); 351 lay.addWidget( &lab);
348 352
349 QLineEdit lepw ( &dia ); 353 QLineEdit lepw ( &dia );
350 lepw.setText( mPrefs->mPassiveSyncPw ); 354 lepw.setText( mPrefs->mPassiveSyncPw );
351 QLabel label2 ( i18n("Password to enable\naccess from remote:"), &dia ); 355 QLabel label2 ( i18n("Password to enable\naccess from remote:"), &dia );
352 lay.addWidget( &label2); 356 lay.addWidget( &label2);
353 lay.addWidget( &lepw); 357 lay.addWidget( &lepw);
354 QCheckBox autostart(i18n("Automatically start\nat application startup"), &dia ); 358 QCheckBox autostart(i18n("Automatically start\nat application startup"), &dia );
355 lay.addWidget( &autostart); 359 lay.addWidget( &autostart);
356 autostart.setChecked( mPrefs->mPassiveSyncAutoStart ); 360 autostart.setChecked( mPrefs->mPassiveSyncAutoStart );
357#ifdef DESKTOP_VERSION 361#ifdef DESKTOP_VERSION
358#ifdef _WIN32_ 362#ifdef _WIN32_
359 QCheckBox syncdesktop( i18n("Automatically sync with Outlook\nwhen receiving sync request"),&dia ); 363 QCheckBox syncdesktop( i18n("Automatically sync with Outlook\nwhen receiving sync request"),&dia );
360 syncdesktop.hide();// not implemented! 364 syncdesktop.hide();// not implemented!
361#else 365#else
362 QCheckBox syncdesktop( i18n("Automatically sync with KDE-Desktop\nwhen receiving sync request"),&dia ); 366 QCheckBox syncdesktop( i18n("Automatically sync with KDE-Desktop\nwhen receiving sync request"),&dia );
363#endif 367#endif
364 lay.addWidget( &syncdesktop); 368 lay.addWidget( &syncdesktop);
365#else 369#else
366 mPrefs->mPassiveSyncWithDesktop = false; 370 mPrefs->mPassiveSyncWithDesktop = false;
367 QCheckBox syncdesktop( i18n("Automatically sync\nwith KDE-Desktop"),&dia ); 371 QCheckBox syncdesktop( i18n("Automatically sync\nwith KDE-Desktop"),&dia );
368 syncdesktop.hide(); 372 syncdesktop.hide();
369#endif 373#endif
370 syncdesktop.setChecked( mPrefs->mPassiveSyncWithDesktop ); 374 syncdesktop.setChecked( mPrefs->mPassiveSyncWithDesktop );
371 375
372 QPushButton pb ( "OK", &dia); 376 QPushButton pb ( "OK", &dia);
373 lay.addWidget( &pb ); 377 lay.addWidget( &pb );
374 connect(&pb, SIGNAL( clicked() ), &dia, SLOT ( accept() ) ); 378 connect(&pb, SIGNAL( clicked() ), &dia, SLOT ( accept() ) );
375 dia.resize( 230,120 ); 379 dia.resize( 230,120 );
376 dia.setCaption( i18n("Enter port for Pi-Sync") ); 380 dia.setCaption( i18n("Enter port for Pi-Sync") );
377 dia.show(); 381 dia.show();
378#ifndef DESKTOP_VERSION 382#ifndef DESKTOP_VERSION
379 int dw = QApplication::desktop()->width(); 383 int dw = QApplication::desktop()->width();
380 int dh = QApplication::desktop()->height(); 384 int dh = QApplication::desktop()->height();
381 dia.move( (dw-dia.width())/2, (dh - dia.height() )/2 ); 385 dia.move( (dw-dia.width())/2, (dh - dia.height() )/2 );
382#endif 386#endif
383 if ( ! dia.exec() ) 387 if ( ! dia.exec() )
384 return; 388 return;
385 dia.hide(); 389 dia.hide();
386 qApp->processEvents(); 390 qApp->processEvents();
387 if ( mPrefs->mPassiveSyncPw != lepw.text() ) { 391 if ( mPrefs->mPassiveSyncPw != lepw.text() ) {
388 changed = true; 392 changed = true;
389 mPrefs->mPassiveSyncPw = lepw.text(); 393 mPrefs->mPassiveSyncPw = lepw.text();
390 } 394 }
391 if ( mPrefs->mPassiveSyncPort != lab.text() ) { 395 if ( mPrefs->mPassiveSyncPort != lab.text() ) {
392 mPrefs->mPassiveSyncPort = lab.text(); 396 mPrefs->mPassiveSyncPort = lab.text();
393 changed = true; 397 changed = true;
394 } 398 }
395 autoStart = autostart.isChecked(); 399 autoStart = autostart.isChecked();
396 if (mPrefs->mPassiveSyncWithDesktop != syncdesktop.isChecked() ) { 400 if (mPrefs->mPassiveSyncWithDesktop != syncdesktop.isChecked() ) {
397 changed = true; 401 changed = true;
398 mPrefs->mPassiveSyncWithDesktop = syncdesktop.isChecked(); 402 mPrefs->mPassiveSyncWithDesktop = syncdesktop.isChecked();
399 } 403 }
400 } 404 }
401 else 405 else
402 autoStart = mPrefs->mPassiveSyncAutoStart; 406 autoStart = mPrefs->mPassiveSyncAutoStart;
403 if ( autoStart != mPrefs->mPassiveSyncAutoStart ) 407 if ( autoStart != mPrefs->mPassiveSyncAutoStart )
404 changed = true; 408 changed = true;
405 bool ok; 409 bool ok;
406 mPrefs->mPassiveSyncAutoStart = false; 410 mPrefs->mPassiveSyncAutoStart = false;
407 Q_UINT16 port = mPrefs->mPassiveSyncPort.toUInt(&ok); 411 Q_UINT16 port = mPrefs->mPassiveSyncPort.toUInt(&ok);
408 if ( ! ok ) { 412 if ( ! ok ) {
409 KMessageBox::information( 0, i18n("No valid port")); 413 KMessageBox::information( 0, i18n("No valid port"));
410 return; 414 return;
411 } 415 }
412 //qDebug("port %d ", port); 416 //qDebug("port %d ", port);
413 mServerSocket = new KServerSocket ( mPrefs->mPassiveSyncPw, port ,1 ); 417 mServerSocket = new KServerSocket ( mPrefs->mPassiveSyncPw, port ,1 );
414 mServerSocket->setFileName( defaultFileName() );//bbb 418 mServerSocket->setFileName( defaultFileName() );//bbb
415 //qDebug("connected ");
416 if ( !mServerSocket->ok() ) { 419 if ( !mServerSocket->ok() ) {
417 KMessageBox::information( 0, i18n("Failed to bind or\nlisten to the port!")); 420 KMessageBox::information( 0, i18n("Failed to bind or\nlisten to the port!"));
418 delete mServerSocket; 421 delete mServerSocket;
419 mServerSocket = 0; 422 mServerSocket = 0;
420 return; 423 return;
421 } 424 }
422 mPrefs->mPassiveSyncAutoStart = autoStart; 425 mPrefs->mPassiveSyncAutoStart = autoStart;
423 if ( changed ) { 426 if ( changed ) {
424 mPrefs->writeConfig(); 427 mPrefs->writeConfig();
425 } 428 }
426 connect( mServerSocket, SIGNAL ( request_file() ),this, SIGNAL ( request_file() ) ); 429 connect( mServerSocket, SIGNAL ( request_file() ),this, SIGNAL ( request_file() ) );
427 connect( mServerSocket, SIGNAL ( file_received( bool ) ), this, SIGNAL ( getFile( bool ) ) ); 430 connect( mServerSocket, SIGNAL ( file_received( bool ) ), this, SIGNAL ( getFile( bool ) ) );
428} 431}
429 432
430void KSyncManager::syncLocalFile() 433void KSyncManager::syncLocalFile()
431{ 434{
432 435
433 QString fn =mPrefs->mLastSyncedLocalFile; 436 QString fn =mPrefs->mLastSyncedLocalFile;
434 QString ext; 437 QString ext;
435 438
436 switch(mTargetApp) 439 switch(mTargetApp)
437 { 440 {
438 case (KAPI): 441 case (KAPI):
439 ext = "(*.vcf)"; 442 ext = "(*.vcf)";
440 break; 443 break;
441 case (KOPI): 444 case (KOPI):
442 ext = "(*.ics/*.vcs)"; 445 ext = "(*.ics/*.vcs)";
443 break; 446 break;
444 case (PWMPI): 447 case (PWMPI):
445 ext = "(*.pwm)"; 448 ext = "(*.pwm)";
446 break; 449 break;
447 default: 450 default:
448 qDebug("KSM::syncLocalFile: invalid apptype selected"); 451 qDebug("KSM::syncLocalFile: invalid apptype selected");
449 break; 452 break;
450 453
451 } 454 }
452 455
453 fn =KFileDialog:: getOpenFileName( fn, i18n("Sync filename"+ext), mParent ); 456 fn =KFileDialog:: getOpenFileName( fn, i18n("Sync filename"+ext), mParent );
454 if ( fn == "" ) 457 if ( fn == "" )
455 return; 458 return;
456 if ( syncWithFile( fn, false ) ) { 459 if ( syncWithFile( fn, false ) ) {
457 qDebug("KSM::syncLocalFile() successful "); 460 qDebug("KSM::syncLocalFile() successful ");
458 } 461 }
459 462
460} 463}
461 464
462bool KSyncManager::syncWithFile( QString fn , bool quick ) 465bool KSyncManager::syncWithFile( QString fn , bool quick )
463{ 466{
464 bool ret = false; 467 bool ret = false;
465 QFileInfo info; 468 QFileInfo info;
466 info.setFile( fn ); 469 info.setFile( fn );
467 QString mess; 470 QString mess;
468 if ( !info. exists() ) { 471 if ( !info. exists() ) {
469 mess = i18n( "Sync file \n...%1\ndoes not exist!\nNothing synced!\n").arg(fn.right( 30) ); 472 mess = i18n( "Sync file \n...%1\ndoes not exist!\nNothing synced!\n").arg(fn.right( 30) );
470 QMessageBox::warning( mParent, i18n("Warning!"), 473 QMessageBox::warning( mParent, i18n("Warning!"),
471 mess ); 474 mess );
472 return ret; 475 return ret;
473 } 476 }
474 int result = 0; 477 int result = 0;
475 if ( !quick ) { 478 if ( !quick ) {
476 mess = i18n("Sync with file \n...%1\nfrom:\n%2\n").arg(fn.right( 25)).arg(KGlobal::locale()->formatDateTime(info.lastModified (), true, false )); 479 mess = i18n("Sync with file \n...%1\nfrom:\n%2\n").arg(fn.right( 25)).arg(KGlobal::locale()->formatDateTime(info.lastModified (), true, false ));
477 result = QMessageBox::warning( mParent, i18n("Warning!"), 480 result = QMessageBox::warning( mParent, i18n("Warning!"),
478 mess, 481 mess,
479 i18n("Sync"), i18n("Cancel"), 0, 482 i18n("Sync"), i18n("Cancel"), 0,
480 0, 1 ); 483 0, 1 );
481 if ( result ) 484 if ( result )
482 return false; 485 return false;
483 } 486 }
484 if ( mAskForPreferences ) 487 if ( mAskForPreferences )
485 if ( !edit_sync_options()) { 488 if ( !edit_sync_options()) {
486 mParent->topLevelWidget()->setCaption( i18n("Syncing aborted. Nothing synced.") ); 489 mParent->topLevelWidget()->setCaption( i18n("Syncing aborted. Nothing synced.") );
487 return false; 490 return false;
488 } 491 }
489 if ( result == 0 ) { 492 if ( result == 0 ) {
490 //qDebug("Now sycing ... "); 493 //qDebug("Now sycing ... ");
491 if ( ret = mImplementation->sync( this, fn, mSyncAlgoPrefs ) ) 494 if ( ret = mImplementation->sync( this, fn, mSyncAlgoPrefs ) )
492 mParent->topLevelWidget()->setCaption( i18n("Synchronization successful") ); 495 mParent->topLevelWidget()->setCaption( i18n("Synchronization successful") );
493 else 496 else
494 mParent->topLevelWidget()->setCaption( i18n("Sync cancelled or failed.") ); 497 mParent->topLevelWidget()->setCaption( i18n("Sync cancelled or failed.") );
495 if ( ! quick ) 498 if ( ! quick )
496 mPrefs->mLastSyncedLocalFile = fn; 499 mPrefs->mLastSyncedLocalFile = fn;
497 } 500 }
498 return ret; 501 return ret;
499} 502}
500 503
501void KSyncManager::quickSyncLocalFile() 504void KSyncManager::quickSyncLocalFile()
502{ 505{
503 506
504 if ( syncWithFile( mPrefs->mLastSyncedLocalFile, true ) ) { 507 if ( syncWithFile( mPrefs->mLastSyncedLocalFile, true ) ) {
505 qDebug("KSM::quick syncLocalFile() successful "); 508 qDebug("KSM::quick syncLocalFile() successful ");
506 509
507 } 510 }
508} 511}
509 512
510void KSyncManager::multiSync( bool askforPrefs ) 513void KSyncManager::multiSync( bool askforPrefs )
511{ 514{
512 if (blockSave()) 515 if (blockSave())
513 return; 516 return;
514 setBlockSave(true); 517 setBlockSave(true);
515 QString question = i18n("Do you really want\nto multiple sync\nwith all checked profiles?\nSyncing takes some\ntime - all profiles\nare synced twice!"); 518 QString question = i18n("Do you really want\nto multiple sync\nwith all checked profiles?\nSyncing takes some\ntime - all profiles\nare synced twice!");
516 if ( QMessageBox::information( mParent, i18n("KDE-Pim Sync"), 519 if ( QMessageBox::information( mParent, i18n("KDE-Pim Sync"),
517 question, 520 question,
518 i18n("Yes"), i18n("No"), 521 i18n("Yes"), i18n("No"),
519 0, 0 ) != 0 ) { 522 0, 0 ) != 0 ) {
520 setBlockSave(false); 523 setBlockSave(false);
521 mParent->topLevelWidget()->setCaption(i18n("Aborted! Nothing synced!")); 524 mParent->topLevelWidget()->setCaption(i18n("Aborted! Nothing synced!"));
522 return; 525 return;
523 } 526 }
524 mCurrentSyncDevice = i18n("Multiple profiles") ; 527 mCurrentSyncDevice = i18n("Multiple profiles") ;
525 mSyncAlgoPrefs = mPrefs->mRingSyncAlgoPrefs; 528 mSyncAlgoPrefs = mPrefs->mRingSyncAlgoPrefs;
526 if ( askforPrefs ) { 529 if ( askforPrefs ) {
527 if ( !edit_sync_options()) { 530 if ( !edit_sync_options()) {
528 mParent->topLevelWidget()->setCaption( i18n("Syncing aborted.") ); 531 mParent->topLevelWidget()->setCaption( i18n("Syncing aborted.") );
529 return; 532 return;
530 } 533 }
531 mPrefs->mRingSyncAlgoPrefs = mSyncAlgoPrefs; 534 mPrefs->mRingSyncAlgoPrefs = mSyncAlgoPrefs;
532 } 535 }
533 mParent->topLevelWidget()->setCaption(i18n("Multiple sync started.") ); 536 mParent->topLevelWidget()->setCaption(i18n("Multiple sync started.") );
534 qApp->processEvents(); 537 qApp->processEvents();
535 int num = ringSync() ; 538 int num = ringSync() ;
536 if ( num > 1 ) 539 if ( num > 1 )
537 ringSync(); 540 ringSync();
538 setBlockSave(false); 541 setBlockSave(false);
539 if ( num ) 542 if ( num )
540 emit save(); 543 emit save();
541 if ( num ) 544 if ( num )
542 mParent->topLevelWidget()->setCaption(i18n("%1 profiles synced. Multiple sync complete!").arg(num) ); 545 mParent->topLevelWidget()->setCaption(i18n("%1 profiles synced. Multiple sync complete!").arg(num) );
543 else 546 else
@@ -992,257 +995,257 @@ void KSyncManager::syncPhone()
992 995
993} 996}
994 997
995void KSyncManager::showProgressBar(int percentage, QString caption, int total) 998void KSyncManager::showProgressBar(int percentage, QString caption, int total)
996{ 999{
997 if (!bar->isVisible()) 1000 if (!bar->isVisible())
998 { 1001 {
999 bar->setCaption (caption); 1002 bar->setCaption (caption);
1000 bar->setTotalSteps ( total ) ; 1003 bar->setTotalSteps ( total ) ;
1001 bar->show(); 1004 bar->show();
1002 } 1005 }
1003 bar->raise(); 1006 bar->raise();
1004 bar->setProgress( percentage ); 1007 bar->setProgress( percentage );
1005 qApp->processEvents(); 1008 qApp->processEvents();
1006} 1009}
1007 1010
1008void KSyncManager::hideProgressBar() 1011void KSyncManager::hideProgressBar()
1009{ 1012{
1010 bar->hide(); 1013 bar->hide();
1011 qApp->processEvents(); 1014 qApp->processEvents();
1012} 1015}
1013 1016
1014bool KSyncManager::isProgressBarCanceled() 1017bool KSyncManager::isProgressBarCanceled()
1015{ 1018{
1016 return !bar->isVisible(); 1019 return !bar->isVisible();
1017} 1020}
1018 1021
1019QString KSyncManager::syncFileName() 1022QString KSyncManager::syncFileName()
1020{ 1023{
1021 1024
1022 QString fn = "tempfile"; 1025 QString fn = "tempfile";
1023 switch(mTargetApp) 1026 switch(mTargetApp)
1024 { 1027 {
1025 case (KAPI): 1028 case (KAPI):
1026 fn = "tempsyncab.vcf"; 1029 fn = "tempsyncab.vcf";
1027 break; 1030 break;
1028 case (KOPI): 1031 case (KOPI):
1029 fn = "tempsynccal.ics"; 1032 fn = "tempsynccal.ics";
1030 break; 1033 break;
1031 case (PWMPI): 1034 case (PWMPI):
1032 fn = "tempsyncpw.pwm"; 1035 fn = "tempsyncpw.pwm";
1033 break; 1036 break;
1034 default: 1037 default:
1035 break; 1038 break;
1036 } 1039 }
1037#ifdef _WIN32_ 1040#ifdef _WIN32_
1038 return locateLocal( "tmp", fn ); 1041 return locateLocal( "tmp", fn );
1039#else 1042#else
1040 return (QString( "/tmp/" )+ fn ); 1043 return (QString( "/tmp/" )+ fn );
1041#endif 1044#endif
1042} 1045}
1043 1046
1044void KSyncManager::syncPi() 1047void KSyncManager::syncPi()
1045{ 1048{
1046 mIsKapiFile = true; 1049 mIsKapiFile = true;
1047 mPisyncFinished = false; 1050 mPisyncFinished = false;
1048 qApp->processEvents(); 1051 qApp->processEvents();
1049 if ( mAskForPreferences ) 1052 if ( mAskForPreferences )
1050 if ( !edit_pisync_options()) { 1053 if ( !edit_pisync_options()) {
1051 mParent->topLevelWidget()->setCaption( i18n("Syncing aborted. Nothing synced.") ); 1054 mParent->topLevelWidget()->setCaption( i18n("Syncing aborted. Nothing synced.") );
1052 return; 1055 return;
1053 } 1056 }
1054 bool ok; 1057 bool ok;
1055 Q_UINT16 port = mActiveSyncPort.toUInt(&ok); 1058 Q_UINT16 port = mActiveSyncPort.toUInt(&ok);
1056 if ( ! ok ) { 1059 if ( ! ok ) {
1057 mParent->topLevelWidget()->setCaption( i18n("Sorry, no valid port.Syncing cancelled.") ); 1060 mParent->topLevelWidget()->setCaption( i18n("Sorry, no valid port.Syncing cancelled.") );
1058 return; 1061 return;
1059 } 1062 }
1060 KCommandSocket* commandSocket = new KCommandSocket( mPassWordPiSync, port, mActiveSyncIP, this, mParent->topLevelWidget() ); 1063 KCommandSocket* commandSocket = new KCommandSocket( mPassWordPiSync, port, mActiveSyncIP, this, mParent->topLevelWidget() );
1061 connect( commandSocket, SIGNAL(commandFinished( KCommandSocket*, int )), this, SLOT(deleteCommandSocket(KCommandSocket*, int)) ); 1064 connect( commandSocket, SIGNAL(commandFinished( KCommandSocket*, int )), this, SLOT(deleteCommandSocket(KCommandSocket*, int)) );
1062 commandSocket->readFile( syncFileName() ); 1065 commandSocket->readFile( syncFileName() );
1063} 1066}
1064 1067
1065void KSyncManager::deleteCommandSocket(KCommandSocket*s, int state) 1068void KSyncManager::deleteCommandSocket(KCommandSocket*s, int state)
1066{ 1069{
1067 //enum { success, errorW, errorR, quiet }; 1070 //enum { success, errorW, errorR, quiet };
1068 if ( state == KCommandSocket::errorR ||state == KCommandSocket::errorTO ) { 1071 if ( state == KCommandSocket::errorR ||state == KCommandSocket::errorTO ) {
1069 mParent->topLevelWidget()->setCaption( i18n("ERROR: Receiving remote file failed.") ); 1072 mParent->topLevelWidget()->setCaption( i18n("ERROR: Receiving remote file failed.") );
1070 delete s; 1073 delete s;
1071 if ( state == KCommandSocket::errorR ) { 1074 if ( state == KCommandSocket::errorR ) {
1072 KCommandSocket* commandSocket = new KCommandSocket( mPassWordPiSync, mActiveSyncPort.toUInt(), mActiveSyncIP, this, mParent->topLevelWidget()); 1075 KCommandSocket* commandSocket = new KCommandSocket( mPassWordPiSync, mActiveSyncPort.toUInt(), mActiveSyncIP, this, mParent->topLevelWidget());
1073 connect( commandSocket, SIGNAL(commandFinished( KCommandSocket*, int)), this, SLOT(deleteCommandSocket(KCommandSocket*, int )) ); 1076 connect( commandSocket, SIGNAL(commandFinished( KCommandSocket*, int)), this, SLOT(deleteCommandSocket(KCommandSocket*, int )) );
1074 commandSocket->sendStop(); 1077 commandSocket->sendStop();
1075 } 1078 }
1076 mPisyncFinished = true; 1079 mPisyncFinished = true;
1077 return; 1080 return;
1078 1081
1079 } else if ( state == KCommandSocket::errorW ) { 1082 } else if ( state == KCommandSocket::errorW ) {
1080 mParent->topLevelWidget()->setCaption( i18n("ERROR:Writing back file failed.") ); 1083 mParent->topLevelWidget()->setCaption( i18n("ERROR:Writing back file failed.") );
1081 mPisyncFinished = true; 1084 mPisyncFinished = true;
1082 1085
1083 } else if ( state == KCommandSocket::successR ) { 1086 } else if ( state == KCommandSocket::successR ) {
1084 QTimer::singleShot( 1, this , SLOT ( readFileFromSocket())); 1087 QTimer::singleShot( 1, this , SLOT ( readFileFromSocket()));
1085 1088
1086 } else if ( state == KCommandSocket::successW ) { 1089 } else if ( state == KCommandSocket::successW ) {
1087 mParent->topLevelWidget()->setCaption( i18n("Pi-Sync succesful!") ); 1090 mParent->topLevelWidget()->setCaption( i18n("Pi-Sync succesful!") );
1088 mPisyncFinished = true; 1091 mPisyncFinished = true;
1089 } 1092 }
1090 1093
1091 delete s; 1094 delete s;
1092} 1095}
1093 1096
1094void KSyncManager::readFileFromSocket() 1097void KSyncManager::readFileFromSocket()
1095{ 1098{
1096 QString fileName = syncFileName(); 1099 QString fileName = syncFileName();
1097 mParent->topLevelWidget()->setCaption( i18n("Remote file saved to temp file.") ); 1100 mParent->topLevelWidget()->setCaption( i18n("Remote file saved to temp file.") );
1098 if ( ! syncWithFile( fileName , true ) ) { 1101 if ( ! syncWithFile( fileName , true ) ) {
1099 mParent->topLevelWidget()->setCaption( i18n("Syncing failed.") ); 1102 mParent->topLevelWidget()->setCaption( i18n("Syncing failed.") );
1100 mPisyncFinished = true; 1103 mPisyncFinished = true;
1101 return; 1104 return;
1102 } 1105 }
1103 KCommandSocket* commandSocket = new KCommandSocket( mPassWordPiSync, mActiveSyncPort.toUInt(), mActiveSyncIP, this, mParent->topLevelWidget() ); 1106 KCommandSocket* commandSocket = new KCommandSocket( mPassWordPiSync, mActiveSyncPort.toUInt(), mActiveSyncIP, this, mParent->topLevelWidget() );
1104 connect( commandSocket, SIGNAL(commandFinished( KCommandSocket*, int)), this, SLOT(deleteCommandSocket(KCommandSocket*, int )) ); 1107 connect( commandSocket, SIGNAL(commandFinished( KCommandSocket*, int)), this, SLOT(deleteCommandSocket(KCommandSocket*, int )) );
1105 if ( mWriteBackFile ) 1108 if ( mWriteBackFile )
1106 commandSocket->writeFile( fileName ); 1109 commandSocket->writeFile( fileName );
1107 else { 1110 else {
1108 commandSocket->sendStop(); 1111 commandSocket->sendStop();
1109 mParent->topLevelWidget()->setCaption( i18n("Pi-Sync succesful!") ); 1112 mParent->topLevelWidget()->setCaption( i18n("Pi-Sync succesful!") );
1110 mPisyncFinished = true; 1113 mPisyncFinished = true;
1111 } 1114 }
1112} 1115}
1113 1116
1114KServerSocket:: KServerSocket ( QString pw, Q_UINT16 port, int backlog, QObject * parent, const char * name ) : QServerSocket( port, backlog, parent, name ) 1117KServerSocket:: KServerSocket ( QString pw, Q_UINT16 port, int backlog, QObject * parent, const char * name ) : QServerSocket( port, backlog, parent, name )
1115{ 1118{
1116 mPassWord = pw; 1119 mPassWord = pw;
1117 mSocket = 0; 1120 mSocket = 0;
1118 mSyncActionDialog = 0; 1121 mSyncActionDialog = 0;
1119 blockRC = false; 1122 blockRC = false;
1120}; 1123}
1121 1124
1122void KServerSocket::newConnection ( int socket ) 1125void KServerSocket::newConnection ( int socket )
1123{ 1126{
1124 // qDebug("KServerSocket:New connection %d ", socket); 1127 // qDebug("KServerSocket:New connection %d ", socket);
1125 if ( mSocket ) { 1128 if ( mSocket ) {
1126 qDebug("KSS::newConnection Socket deleted! "); 1129 qDebug("KSS::newConnection Socket deleted! ");
1127 delete mSocket; 1130 delete mSocket;
1128 mSocket = 0; 1131 mSocket = 0;
1129 } 1132 }
1130 mSocket = new QSocket( this ); 1133 mSocket = new QSocket( this );
1131 connect( mSocket , SIGNAL(readyRead()), this, SLOT(readClient()) ); 1134 connect( mSocket , SIGNAL(readyRead()), this, SLOT(readClient()) );
1132 connect( mSocket , SIGNAL(delayedCloseFinished()), this, SLOT(discardClient()) ); 1135 connect( mSocket , SIGNAL(delayedCloseFinished()), this, SLOT(discardClient()) );
1133 mSocket->setSocket( socket ); 1136 mSocket->setSocket( socket );
1134} 1137}
1135 1138
1136void KServerSocket::discardClient() 1139void KServerSocket::discardClient()
1137{ 1140{
1138 //qDebug(" KServerSocket::discardClient()"); 1141 //qDebug(" KServerSocket::discardClient()");
1139 if ( mSocket ) { 1142 if ( mSocket ) {
1140 delete mSocket; 1143 delete mSocket;
1141 mSocket = 0; 1144 mSocket = 0;
1142 } 1145 }
1143 //emit endConnect(); 1146 //emit endConnect();
1144} 1147}
1145void KServerSocket::readClient() 1148void KServerSocket::readClient()
1146{ 1149{
1147 if ( blockRC ) 1150 if ( blockRC )
1148 return; 1151 return;
1149 if ( mSocket == 0 ) { 1152 if ( mSocket == 0 ) {
1150 qDebug("ERROR::KSS::readClient(): mSocket == 0 "); 1153 qDebug("ERROR::KSS::readClient(): mSocket == 0 ");
1151 return; 1154 return;
1152 } 1155 }
1153 //qDebug("KServerSocket::readClient()"); 1156 //qDebug("KServerSocket::readClient()");
1154 if ( mSocket->canReadLine() ) { 1157 if ( mSocket->canReadLine() ) {
1155 QString line = mSocket->readLine(); 1158 QString line = mSocket->readLine();
1156 //qDebug("KServerSocket readline: %s ", line.latin1()); 1159 //qDebug("KServerSocket readline: %s ", line.latin1());
1157 QStringList tokens = QStringList::split( QRegExp("[ \r\n][ \r\n]*"), line ); 1160 QStringList tokens = QStringList::split( QRegExp("[ \r\n][ \r\n]*"), line );
1158 if ( tokens[0] == "GET" ) { 1161 if ( tokens[0] == "GET" ) {
1159 if ( tokens[1] == mPassWord ) { 1162 if ( tokens[1] == mPassWord ) {
1160 //emit sendFile( mSocket ); 1163 //emit sendFile( mSocket );
1161 bool ok = false; 1164 bool ok = false;
1162 QDateTime dt = KGlobal::locale()->readDateTime( tokens[2], KLocale::ISODate, &ok); 1165 QDateTime dt = KGlobal::locale()->readDateTime( tokens[2], KLocale::ISODate, &ok);
1163 if ( ok ) { 1166 if ( ok ) {
1164 KSyncManager::mRequestedSyncEvent = dt; 1167 KSyncManager::mRequestedSyncEvent = dt;
1165 } 1168 }
1166 else 1169 else
1167 KSyncManager::mRequestedSyncEvent = QDateTime(); 1170 KSyncManager::mRequestedSyncEvent = QDateTime();
1168 send_file(); 1171 send_file();
1169 } 1172 }
1170 else { 1173 else {
1171 KMessageBox::error( 0, i18n("Got send file request\nwith invalid password")); 1174 KMessageBox::error( 0, i18n("Got send file request\nwith invalid password"));
1172 //qDebug("password %s, invalid password %s ",mPassWord.latin1(), tokens[1].latin1() ); 1175 //qDebug("password %s, invalid password %s ",mPassWord.latin1(), tokens[1].latin1() );
1173 } 1176 }
1174 } 1177 }
1175 if ( tokens[0] == "PUT" ) { 1178 if ( tokens[0] == "PUT" ) {
1176 if ( tokens[1] == mPassWord ) { 1179 if ( tokens[1] == mPassWord ) {
1177 //emit getFile( mSocket ); 1180 //emit getFile( mSocket );
1178 blockRC = true; 1181 blockRC = true;
1179 get_file(); 1182 get_file();
1180 } 1183 }
1181 else { 1184 else {
1182 KMessageBox::error( 0, i18n("Got receive file request\nwith invalid password")); 1185 KMessageBox::error( 0, i18n("Got receive file request\nwith invalid password"));
1183 //qDebug("password %s, invalid password %s ",mPassWord.latin1(), tokens[1].latin1() ); 1186 //qDebug("password %s, invalid password %s ",mPassWord.latin1(), tokens[1].latin1() );
1184 } 1187 }
1185 } 1188 }
1186 if ( tokens[0] == "STOP" ) { 1189 if ( tokens[0] == "STOP" ) {
1187 //emit endConnect(); 1190 //emit endConnect();
1188 end_connect(); 1191 end_connect();
1189 } 1192 }
1190 } 1193 }
1191} 1194}
1192void KServerSocket::end_connect() 1195void KServerSocket::end_connect()
1193{ 1196{
1194 delete mSyncActionDialog; 1197 delete mSyncActionDialog;
1195 mSyncActionDialog = 0; 1198 mSyncActionDialog = 0;
1196} 1199}
1197void KServerSocket::send_file() 1200void KServerSocket::send_file()
1198{ 1201{
1199 //qDebug("MainWindow::sendFile(QSocket* s) "); 1202 //qDebug("MainWindow::sendFile(QSocket* s) ");
1200 if ( mSyncActionDialog ) 1203 if ( mSyncActionDialog )
1201 delete mSyncActionDialog; 1204 delete mSyncActionDialog;
1202 mSyncActionDialog = new QDialog ( 0, "input-dialog", true ); 1205 mSyncActionDialog = new QDialog ( 0, "input-dialog", true );
1203 mSyncActionDialog->setCaption(i18n("Received sync request")); 1206 mSyncActionDialog->setCaption(i18n("Received sync request"));
1204 QLabel* label = new QLabel( i18n("Synchronizing from remote ...\n\nDo not use this application!\n\nIf syncing fails\nyou can close this dialog."), mSyncActionDialog ); 1207 QLabel* label = new QLabel( i18n("Synchronizing from remote ...\n\nDo not use this application!\n\nIf syncing fails\nyou can close this dialog."), mSyncActionDialog );
1205 label->setAlignment ( Qt::AlignHCenter ); 1208 label->setAlignment ( Qt::AlignHCenter );
1206 QVBoxLayout* lay = new QVBoxLayout( mSyncActionDialog ); 1209 QVBoxLayout* lay = new QVBoxLayout( mSyncActionDialog );
1207 lay->addWidget( label); 1210 lay->addWidget( label);
1208 lay->setMargin(7); 1211 lay->setMargin(7);
1209 lay->setSpacing(7); 1212 lay->setSpacing(7);
1210 if ( KSyncManager::mRequestedSyncEvent.isValid() ) { 1213 if ( KSyncManager::mRequestedSyncEvent.isValid() ) {
1211 int secs = QDateTime::currentDateTime().secsTo( KSyncManager::mRequestedSyncEvent ); 1214 int secs = QDateTime::currentDateTime().secsTo( KSyncManager::mRequestedSyncEvent );
1212 if ( secs < 0 ) 1215 if ( secs < 0 )
1213 secs = secs * (-1); 1216 secs = secs * (-1);
1214 if ( secs > 30 ) 1217 if ( secs > 30 )
1215 //if ( true ) 1218 //if ( true )
1216 { 1219 {
1217 QString warning = i18n("Clock skew of\nsyncing devices\nis %1 seconds!").arg( secs ); 1220 QString warning = i18n("Clock skew of\nsyncing devices\nis %1 seconds!").arg( secs );
1218 QLabel* label = new QLabel( warning, mSyncActionDialog ); 1221 QLabel* label = new QLabel( warning, mSyncActionDialog );
1219 label->setAlignment ( Qt::AlignHCenter ); 1222 label->setAlignment ( Qt::AlignHCenter );
1220 lay->addWidget( label); 1223 lay->addWidget( label);
1221 if ( secs > 180 ) 1224 if ( secs > 180 )
1222 { 1225 {
1223 if ( secs > 300 ) { 1226 if ( secs > 300 ) {
1224 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!"))) { 1227 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!"))) {
1225 qDebug("KSS::Sync cancelled ,cs"); 1228 qDebug("KSS::Sync cancelled ,cs");
1226 return ; 1229 return ;
1227 } 1230 }
1228 } 1231 }
1229 QFont f = label->font(); 1232 QFont f = label->font();
1230 f.setPointSize ( f.pointSize() *2 ); 1233 f.setPointSize ( f.pointSize() *2 );
1231 f. setBold (true ); 1234 f. setBold (true );
1232 QLabel* label = new QLabel( warning, mSyncActionDialog ); 1235 QLabel* label = new QLabel( warning, mSyncActionDialog );
1233 label->setFont( f ); 1236 label->setFont( f );
1234 warning = i18n("ADJUST\nYOUR\nCLOCKS!"); 1237 warning = i18n("ADJUST\nYOUR\nCLOCKS!");
1235 label->setText( warning ); 1238 label->setText( warning );
1236 label->setAlignment ( Qt::AlignHCenter ); 1239 label->setAlignment ( Qt::AlignHCenter );
1237 lay->addWidget( label); 1240 lay->addWidget( label);
1238 mSyncActionDialog->setFixedSize( 230, 300); 1241 mSyncActionDialog->setFixedSize( 230, 300);
1239 } else { 1242 } else {
1240 mSyncActionDialog->setFixedSize( 230, 200); 1243 mSyncActionDialog->setFixedSize( 230, 200);
1241 } 1244 }
1242 } else { 1245 } else {
1243 mSyncActionDialog->setFixedSize( 230, 120); 1246 mSyncActionDialog->setFixedSize( 230, 120);
1244 } 1247 }
1245 } else 1248 } else
1246 mSyncActionDialog->setFixedSize( 230, 120); 1249 mSyncActionDialog->setFixedSize( 230, 120);
1247 mSyncActionDialog->show(); 1250 mSyncActionDialog->show();
1248 mSyncActionDialog->raise(); 1251 mSyncActionDialog->raise();