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