summaryrefslogtreecommitdiffabout
path: root/libkdepim/ksyncmanager.cpp
authorzautrix <zautrix>2004-10-07 09:56:31 (UTC)
committer zautrix <zautrix>2004-10-07 09:56:31 (UTC)
commitedd36b813763c304b104f276437c2c60ee9bd1f1 (patch) (unidiff)
treeda3a9f6fbd905fe876131af5025690806ce60704 /libkdepim/ksyncmanager.cpp
parent9345818e9c291130691288e4b065190259eb4e01 (diff)
downloadkdepimpi-edd36b813763c304b104f276437c2c60ee9bd1f1.zip
kdepimpi-edd36b813763c304b104f276437c2c60ee9bd1f1.tar.gz
kdepimpi-edd36b813763c304b104f276437c2c60ee9bd1f1.tar.bz2
sync fixes
Diffstat (limited to 'libkdepim/ksyncmanager.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r--libkdepim/ksyncmanager.cpp5
1 files changed, 3 insertions, 2 deletions
diff --git a/libkdepim/ksyncmanager.cpp b/libkdepim/ksyncmanager.cpp
index 5d48884..ea543dd 100644
--- a/libkdepim/ksyncmanager.cpp
+++ b/libkdepim/ksyncmanager.cpp
@@ -150,257 +150,258 @@ void KSyncManager::slotSyncMenu( int action )
150 } 150 }
151 if ( action == 2 ) { 151 if ( action == 2 ) {
152 enableQuick(); 152 enableQuick();
153 QTimer::singleShot ( 1, this, SLOT ( fillSyncMenu() ) ); 153 QTimer::singleShot ( 1, this, SLOT ( fillSyncMenu() ) );
154 return; 154 return;
155 } 155 }
156 if ( action == 3 ) { 156 if ( action == 3 ) {
157 delete mServerSocket; 157 delete mServerSocket;
158 mServerSocket = 0; 158 mServerSocket = 0;
159 QTimer::singleShot ( 1, this, SLOT ( fillSyncMenu() ) ); 159 QTimer::singleShot ( 1, this, SLOT ( fillSyncMenu() ) );
160 return; 160 return;
161 } 161 }
162 162
163 if (blockSave()) 163 if (blockSave())
164 return; 164 return;
165 165
166 setBlockSave(true); 166 setBlockSave(true);
167 167
168 mCurrentSyncProfile = action - 1000 ; 168 mCurrentSyncProfile = action - 1000 ;
169 mCurrentSyncDevice = mSyncProfileNames[mCurrentSyncProfile] ; 169 mCurrentSyncDevice = mSyncProfileNames[mCurrentSyncProfile] ;
170 mCurrentSyncName = mLocalMachineName ; 170 mCurrentSyncName = mLocalMachineName ;
171 KConfig config ( locateLocal( "config","ksyncprofilesrc" ) ); 171 KConfig config ( locateLocal( "config","ksyncprofilesrc" ) );
172 KSyncProfile* temp = new KSyncProfile (); 172 KSyncProfile* temp = new KSyncProfile ();
173 temp->setName(mSyncProfileNames[mCurrentSyncProfile]); 173 temp->setName(mSyncProfileNames[mCurrentSyncProfile]);
174 temp->readConfig(&config); 174 temp->readConfig(&config);
175 mAskForPreferences = temp->getAskForPreferences(); 175 mAskForPreferences = temp->getAskForPreferences();
176 mSyncAlgoPrefs = temp->getSyncPrefs(); 176 mSyncAlgoPrefs = temp->getSyncPrefs();
177 mWriteBackFile = temp->getWriteBackFile(); 177 mWriteBackFile = temp->getWriteBackFile();
178 mWriteBackExistingOnly = temp->getWriteBackExisting(); 178 mWriteBackExistingOnly = temp->getWriteBackExisting();
179 mWriteBackInFuture = 0; 179 mWriteBackInFuture = 0;
180 if ( temp->getWriteBackFuture() ) 180 if ( temp->getWriteBackFuture() )
181 mWriteBackInFuture = temp->getWriteBackFutureWeeks( ); 181 mWriteBackInFuture = temp->getWriteBackFutureWeeks( );
182 mShowSyncSummary = temp->getShowSummaryAfterSync(); 182 mShowSyncSummary = temp->getShowSummaryAfterSync();
183 if ( action == 1000 ) { 183 if ( action == 1000 ) {
184 syncSharp(); 184 syncSharp();
185 185
186 } else if ( action == 1001 ) { 186 } else if ( action == 1001 ) {
187 syncLocalFile(); 187 syncLocalFile();
188 188
189 } else if ( action == 1002 ) { 189 } else if ( action == 1002 ) {
190 quickSyncLocalFile(); 190 quickSyncLocalFile();
191 191
192 } else if ( action >= 1003 ) { 192 } else if ( action >= 1003 ) {
193 if ( temp->getIsLocalFileSync() ) { 193 if ( temp->getIsLocalFileSync() ) {
194 switch(mTargetApp) 194 switch(mTargetApp)
195 { 195 {
196 case (KAPI): 196 case (KAPI):
197 if ( syncWithFile( temp->getRemoteFileNameAB( ), false ) ) 197 if ( syncWithFile( temp->getRemoteFileNameAB( ), false ) )
198 mLastSyncedLocalFile = temp->getRemoteFileNameAB(); 198 mLastSyncedLocalFile = temp->getRemoteFileNameAB();
199 break; 199 break;
200 case (KOPI): 200 case (KOPI):
201 if ( syncWithFile( temp->getRemoteFileName( ), false ) ) 201 if ( syncWithFile( temp->getRemoteFileName( ), false ) )
202 mLastSyncedLocalFile = temp->getRemoteFileName(); 202 mLastSyncedLocalFile = temp->getRemoteFileName();
203 break; 203 break;
204 case (PWMPI): 204 case (PWMPI):
205 if ( syncWithFile( temp->getRemoteFileNamePWM( ), false ) ) 205 if ( syncWithFile( temp->getRemoteFileNamePWM( ), false ) )
206 mLastSyncedLocalFile = temp->getRemoteFileNamePWM(); 206 mLastSyncedLocalFile = temp->getRemoteFileNamePWM();
207 break; 207 break;
208 default: 208 default:
209 qDebug("KSyncManager::slotSyncMenu: invalid apptype selected"); 209 qDebug("KSyncManager::slotSyncMenu: invalid apptype selected");
210 break; 210 break;
211 211
212 } 212 }
213 } else { 213 } else {
214 if ( temp->getIsPhoneSync() ) { 214 if ( temp->getIsPhoneSync() ) {
215 mPhoneDevice = temp->getPhoneDevice( ) ; 215 mPhoneDevice = temp->getPhoneDevice( ) ;
216 mPhoneConnection = temp->getPhoneConnection( ); 216 mPhoneConnection = temp->getPhoneConnection( );
217 mPhoneModel = temp->getPhoneModel( ); 217 mPhoneModel = temp->getPhoneModel( );
218 syncPhone(); 218 syncPhone();
219 } else if ( temp->getIsPiSync() ) { 219 } else if ( temp->getIsPiSync() ) {
220 mPassWordPiSync = temp->getRemotePw(); 220 mPassWordPiSync = temp->getRemotePw();
221 mActiveSyncPort = temp->getRemotePort(); 221 mActiveSyncPort = temp->getRemotePort();
222 mActiveSyncIP = temp->getRemoteIP(); 222 mActiveSyncIP = temp->getRemoteIP();
223 syncPi(); 223 syncPi();
224 } 224 }
225 syncRemote( temp ); 225 syncRemote( temp );
226 226
227 } 227 }
228 } 228 }
229 delete temp; 229 delete temp;
230 setBlockSave(false); 230 setBlockSave(false);
231} 231}
232void KSyncManager::enableQuick() 232void KSyncManager::enableQuick()
233{ 233{
234 QDialog dia ( 0, "input-dialog", true ); 234 QDialog dia ( 0, "input-dialog", true );
235 QLineEdit lab ( &dia ); 235 QLineEdit lab ( &dia );
236 QVBoxLayout lay( &dia ); 236 QVBoxLayout lay( &dia );
237 lab.setText( mPrefs->mPassiveSyncPort ); 237 lab.setText( mPrefs->mPassiveSyncPort );
238 lay.setMargin(7); 238 lay.setMargin(7);
239 lay.setSpacing(7); 239 lay.setSpacing(7);
240 int po = 9197+mTargetApp; 240 int po = 9197+mTargetApp;
241 QLabel label ( i18n("Port number (Default: %1)").arg(po), &dia ); 241 QLabel label ( i18n("Port number (Default: %1)").arg(po), &dia );
242 lay.addWidget( &label); 242 lay.addWidget( &label);
243 lay.addWidget( &lab); 243 lay.addWidget( &lab);
244 244
245 QLineEdit lepw ( &dia ); 245 QLineEdit lepw ( &dia );
246 lepw.setText( mPrefs->mPassiveSyncPw ); 246 lepw.setText( mPrefs->mPassiveSyncPw );
247 QLabel label2 ( i18n("Password to enable\naccess from remote:"), &dia ); 247 QLabel label2 ( i18n("Password to enable\naccess from remote:"), &dia );
248 lay.addWidget( &label2); 248 lay.addWidget( &label2);
249 lay.addWidget( &lepw); 249 lay.addWidget( &lepw);
250 dia.setFixedSize( 230,80 ); 250 dia.setFixedSize( 230,80 );
251 dia.setCaption( i18n("Enter port for Pi-Sync") ); 251 dia.setCaption( i18n("Enter port for Pi-Sync") );
252 QPushButton pb ( "OK", &dia); 252 QPushButton pb ( "OK", &dia);
253 lay.addWidget( &pb ); 253 lay.addWidget( &pb );
254 connect(&pb, SIGNAL( clicked() ), &dia, SLOT ( accept() ) ); 254 connect(&pb, SIGNAL( clicked() ), &dia, SLOT ( accept() ) );
255 dia.show(); 255 dia.show();
256 if ( ! dia.exec() ) 256 if ( ! dia.exec() )
257 return; 257 return;
258 dia.hide(); 258 dia.hide();
259 qApp->processEvents(); 259 qApp->processEvents();
260 mPrefs->mPassiveSyncPw = lepw.text(); 260 mPrefs->mPassiveSyncPw = lepw.text();
261 mPrefs->mPassiveSyncPort = lab.text(); 261 mPrefs->mPassiveSyncPort = lab.text();
262 bool ok; 262 bool ok;
263 Q_UINT16 port = mPrefs->mPassiveSyncPort.toUInt(&ok); 263 Q_UINT16 port = mPrefs->mPassiveSyncPort.toUInt(&ok);
264 if ( ! ok ) { 264 if ( ! ok ) {
265 KMessageBox::information( 0, i18n("No valid port")); 265 KMessageBox::information( 0, i18n("No valid port"));
266 return; 266 return;
267 } 267 }
268 //qDebug("port %d ", port); 268 //qDebug("port %d ", port);
269 mServerSocket = new KServerSocket ( mPrefs->mPassiveSyncPw, port ,1 ); 269 mServerSocket = new KServerSocket ( mPrefs->mPassiveSyncPw, port ,1 );
270 mServerSocket->setFileName( defaultFileName() ); 270 mServerSocket->setFileName( defaultFileName() );
271 //qDebug("connected "); 271 //qDebug("connected ");
272 if ( !mServerSocket->ok() ) { 272 if ( !mServerSocket->ok() ) {
273 KMessageBox::information( 0, i18n("Failed to bind or\nlisten to the port!")); 273 KMessageBox::information( 0, i18n("Failed to bind or\nlisten to the port!"));
274 delete mServerSocket; 274 delete mServerSocket;
275 mServerSocket = 0; 275 mServerSocket = 0;
276 return; 276 return;
277 } 277 }
278 connect( mServerSocket, SIGNAL ( saveFile() ),this, SIGNAL ( save() ) ); 278 //connect( mServerSocket, SIGNAL ( saveFile() ),this, SIGNAL ( save() ) );
279 connect( mServerSocket, SIGNAL ( request_file() ),this, SIGNAL ( request_file() ) );
279 connect( mServerSocket, SIGNAL ( file_received( bool ) ), this, SIGNAL ( getFile( bool ) ) ); 280 connect( mServerSocket, SIGNAL ( file_received( bool ) ), this, SIGNAL ( getFile( bool ) ) );
280} 281}
281 282
282void KSyncManager::syncLocalFile() 283void KSyncManager::syncLocalFile()
283{ 284{
284 285
285 QString fn =mLastSyncedLocalFile; 286 QString fn =mLastSyncedLocalFile;
286 QString ext; 287 QString ext;
287 288
288 switch(mTargetApp) 289 switch(mTargetApp)
289 { 290 {
290 case (KAPI): 291 case (KAPI):
291 ext = "(*.vcf)"; 292 ext = "(*.vcf)";
292 break; 293 break;
293 case (KOPI): 294 case (KOPI):
294 ext = "(*.ics/*.vcs)"; 295 ext = "(*.ics/*.vcs)";
295 break; 296 break;
296 case (PWMPI): 297 case (PWMPI):
297 ext = "(*.pwm)"; 298 ext = "(*.pwm)";
298 break; 299 break;
299 default: 300 default:
300 qDebug("KSyncManager::syncLocalFile: invalid apptype selected"); 301 qDebug("KSyncManager::syncLocalFile: invalid apptype selected");
301 break; 302 break;
302 303
303 } 304 }
304 305
305 fn =KFileDialog:: getOpenFileName( fn, i18n("Sync filename"+ext), mParent ); 306 fn =KFileDialog:: getOpenFileName( fn, i18n("Sync filename"+ext), mParent );
306 if ( fn == "" ) 307 if ( fn == "" )
307 return; 308 return;
308 if ( syncWithFile( fn, false ) ) { 309 if ( syncWithFile( fn, false ) ) {
309 qDebug("syncLocalFile() successful "); 310 qDebug("syncLocalFile() successful ");
310 } 311 }
311 312
312} 313}
313bool KSyncManager::syncWithFile( QString fn , bool quick ) 314bool KSyncManager::syncWithFile( QString fn , bool quick )
314{ 315{
315 bool ret = false; 316 bool ret = false;
316 QFileInfo info; 317 QFileInfo info;
317 info.setFile( fn ); 318 info.setFile( fn );
318 QString mess; 319 QString mess;
319 bool loadbup = true; 320 bool loadbup = true;
320 if ( !info. exists() ) { 321 if ( !info. exists() ) {
321 mess = i18n( "Sync file \n...%1\ndoes not exist!\nNothing synced!\n").arg(fn.right( 30) ); 322 mess = i18n( "Sync file \n...%1\ndoes not exist!\nNothing synced!\n").arg(fn.right( 30) );
322 int result = QMessageBox::warning( mParent, i18n("Warning!"), 323 int result = QMessageBox::warning( mParent, i18n("Warning!"),
323 mess ); 324 mess );
324 return ret; 325 return ret;
325 } 326 }
326 int result = 0; 327 int result = 0;
327 if ( !quick ) { 328 if ( !quick ) {
328 mess = i18n("Sync with file \n...%1\nfrom:\n%2\n").arg(fn.right( 25)).arg(KGlobal::locale()->formatDateTime(info.lastModified (), true, false )); 329 mess = i18n("Sync with file \n...%1\nfrom:\n%2\n").arg(fn.right( 25)).arg(KGlobal::locale()->formatDateTime(info.lastModified (), true, false ));
329 result = QMessageBox::warning( mParent, i18n("Warning!"), 330 result = QMessageBox::warning( mParent, i18n("Warning!"),
330 mess, 331 mess,
331 i18n("Sync"), i18n("Cancel"), 0, 332 i18n("Sync"), i18n("Cancel"), 0,
332 0, 1 ); 333 0, 1 );
333 if ( result ) 334 if ( result )
334 return false; 335 return false;
335 } 336 }
336 if ( mAskForPreferences ) 337 if ( mAskForPreferences )
337 edit_sync_options(); 338 edit_sync_options();
338 if ( result == 0 ) { 339 if ( result == 0 ) {
339 //qDebug("Now sycing ... "); 340 //qDebug("Now sycing ... ");
340 if ( ret = mImplementation->sync( this, fn, mSyncAlgoPrefs ) ) 341 if ( ret = mImplementation->sync( this, fn, mSyncAlgoPrefs ) )
341 mParent->setCaption( i18n("Synchronization successful") ); 342 mParent->setCaption( i18n("Synchronization successful") );
342 else 343 else
343 mParent->setCaption( i18n("Sync cancelled or failed. Nothing synced.") ); 344 mParent->setCaption( i18n("Sync cancelled or failed. Nothing synced.") );
344 if ( ! quick ) 345 if ( ! quick )
345 mLastSyncedLocalFile = fn; 346 mLastSyncedLocalFile = fn;
346 } 347 }
347 return ret; 348 return ret;
348} 349}
349void KSyncManager::quickSyncLocalFile() 350void KSyncManager::quickSyncLocalFile()
350{ 351{
351 352
352 if ( syncWithFile( mLastSyncedLocalFile, false ) ) { 353 if ( syncWithFile( mLastSyncedLocalFile, false ) ) {
353 qDebug("quick syncLocalFile() successful "); 354 qDebug("quick syncLocalFile() successful ");
354 355
355 } 356 }
356} 357}
357void KSyncManager::multiSync( bool askforPrefs ) 358void KSyncManager::multiSync( bool askforPrefs )
358{ 359{
359 if (blockSave()) 360 if (blockSave())
360 return; 361 return;
361 setBlockSave(true); 362 setBlockSave(true);
362 QString question = i18n("Do you really want\nto multiple sync\nwith all checked profiles?\nSyncing takes some\ntime - all profiles\nare synced twice!"); 363 QString question = i18n("Do you really want\nto multiple sync\nwith all checked profiles?\nSyncing takes some\ntime - all profiles\nare synced twice!");
363 if ( QMessageBox::information( mParent, i18n("Sync"), 364 if ( QMessageBox::information( mParent, i18n("Sync"),
364 question, 365 question,
365 i18n("Yes"), i18n("No"), 366 i18n("Yes"), i18n("No"),
366 0, 0 ) != 0 ) { 367 0, 0 ) != 0 ) {
367 setBlockSave(false); 368 setBlockSave(false);
368 mParent->setCaption(i18n("Aborted! Nothing synced!")); 369 mParent->setCaption(i18n("Aborted! Nothing synced!"));
369 return; 370 return;
370 } 371 }
371 mCurrentSyncDevice = i18n("Multiple profiles") ; 372 mCurrentSyncDevice = i18n("Multiple profiles") ;
372 mSyncAlgoPrefs = mRingSyncAlgoPrefs; 373 mSyncAlgoPrefs = mRingSyncAlgoPrefs;
373 if ( askforPrefs ) { 374 if ( askforPrefs ) {
374 edit_sync_options(); 375 edit_sync_options();
375 mRingSyncAlgoPrefs = mSyncAlgoPrefs; 376 mRingSyncAlgoPrefs = mSyncAlgoPrefs;
376 } 377 }
377 mParent->setCaption(i18n("Multiple sync started.") ); 378 mParent->setCaption(i18n("Multiple sync started.") );
378 qApp->processEvents(); 379 qApp->processEvents();
379 int num = ringSync() ; 380 int num = ringSync() ;
380 if ( num > 1 ) 381 if ( num > 1 )
381 ringSync(); 382 ringSync();
382 setBlockSave(false); 383 setBlockSave(false);
383 if ( num ) 384 if ( num )
384 emit save(); 385 emit save();
385 if ( num ) 386 if ( num )
386 mParent->setCaption(i18n("%1 profiles synced. Multiple sync completed!").arg(num) ); 387 mParent->setCaption(i18n("%1 profiles synced. Multiple sync completed!").arg(num) );
387 else 388 else
388 mParent->setCaption(i18n("Nothing synced! No profiles defined for multisync!")); 389 mParent->setCaption(i18n("Nothing synced! No profiles defined for multisync!"));
389 return; 390 return;
390} 391}
391int KSyncManager::ringSync() 392int KSyncManager::ringSync()
392{ 393{
393 int syncedProfiles = 0; 394 int syncedProfiles = 0;
394 unsigned int i; 395 unsigned int i;
395 QTime timer; 396 QTime timer;
396 KConfig config ( locateLocal( "config","ksyncprofilesrc" ) ); 397 KConfig config ( locateLocal( "config","ksyncprofilesrc" ) );
397 QStringList syncProfileNames = mSyncProfileNames; 398 QStringList syncProfileNames = mSyncProfileNames;
398 KSyncProfile* temp = new KSyncProfile (); 399 KSyncProfile* temp = new KSyncProfile ();
399 mAskForPreferences = false; 400 mAskForPreferences = false;
400 for ( i = 0; i < syncProfileNames.count(); ++i ) { 401 for ( i = 0; i < syncProfileNames.count(); ++i ) {
401 mCurrentSyncProfile = i; 402 mCurrentSyncProfile = i;
402 temp->setName(syncProfileNames[mCurrentSyncProfile]); 403 temp->setName(syncProfileNames[mCurrentSyncProfile]);
403 temp->readConfig(&config); 404 temp->readConfig(&config);
404 405
405 QString includeInRingSync; 406 QString includeInRingSync;
406 switch(mTargetApp) 407 switch(mTargetApp)
@@ -803,257 +804,257 @@ void KSyncManager::readFileFromSocket()
803 mParent->setCaption( i18n("Remote file saved to temp file.") ); 804 mParent->setCaption( i18n("Remote file saved to temp file.") );
804 if ( ! syncWithFile( fileName , true ) ) { 805 if ( ! syncWithFile( fileName , true ) ) {
805 mParent->setCaption( i18n("Syncing failed.") ); 806 mParent->setCaption( i18n("Syncing failed.") );
806 qDebug("Syncing failed "); 807 qDebug("Syncing failed ");
807 return; 808 return;
808 } 809 }
809 KCommandSocket* commandSocket = new KCommandSocket( mPassWordPiSync, mActiveSyncPort.toUInt(), mActiveSyncIP, this ); 810 KCommandSocket* commandSocket = new KCommandSocket( mPassWordPiSync, mActiveSyncPort.toUInt(), mActiveSyncIP, this );
810 connect( commandSocket, SIGNAL(commandFinished( KCommandSocket*, int)), this, SLOT(deleteCommandSocket(KCommandSocket*, int )) ); 811 connect( commandSocket, SIGNAL(commandFinished( KCommandSocket*, int)), this, SLOT(deleteCommandSocket(KCommandSocket*, int )) );
811 if ( mWriteBackFile ) 812 if ( mWriteBackFile )
812 commandSocket->writeFile( fileName ); 813 commandSocket->writeFile( fileName );
813 else { 814 else {
814 commandSocket->sendStop(); 815 commandSocket->sendStop();
815 mParent->setCaption( i18n("Pi-Sync succesful!") ); 816 mParent->setCaption( i18n("Pi-Sync succesful!") );
816 } 817 }
817} 818}
818 819
819 820
820 821
821 822
822 823
823 824
824 825
825 826
826 827
827 828
828 829
829 830
830 831
831 832
832 833
833 834
834 835
835 836
836 837
837 838
838 839
839 840
840 841
841KServerSocket:: KServerSocket ( QString pw, Q_UINT16 port, int backlog, QObject * parent, const char * name ) : QServerSocket( port, backlog, parent, name ) 842KServerSocket:: KServerSocket ( QString pw, Q_UINT16 port, int backlog, QObject * parent, const char * name ) : QServerSocket( port, backlog, parent, name )
842{ 843{
843 mPassWord = pw; 844 mPassWord = pw;
844 mSocket = 0; 845 mSocket = 0;
845 mSyncActionDialog = 0; 846 mSyncActionDialog = 0;
846 blockRC = false; 847 blockRC = false;
847}; 848};
848 849
849void KServerSocket::newConnection ( int socket ) 850void KServerSocket::newConnection ( int socket )
850{ 851{
851 // qDebug("KServerSocket:New connection %d ", socket); 852 // qDebug("KServerSocket:New connection %d ", socket);
852 if ( mSocket ) { 853 if ( mSocket ) {
853 qDebug("KServerSocket::newConnection Socket deleted! "); 854 qDebug("KServerSocket::newConnection Socket deleted! ");
854 delete mSocket; 855 delete mSocket;
855 mSocket = 0; 856 mSocket = 0;
856 } 857 }
857 mSocket = new QSocket( this ); 858 mSocket = new QSocket( this );
858 connect( mSocket , SIGNAL(readyRead()), this, SLOT(readClient()) ); 859 connect( mSocket , SIGNAL(readyRead()), this, SLOT(readClient()) );
859 connect( mSocket , SIGNAL(delayedCloseFinished()), this, SLOT(discardClient()) ); 860 connect( mSocket , SIGNAL(delayedCloseFinished()), this, SLOT(discardClient()) );
860 mSocket->setSocket( socket ); 861 mSocket->setSocket( socket );
861} 862}
862 863
863void KServerSocket::discardClient() 864void KServerSocket::discardClient()
864{ 865{
865 //qDebug(" KServerSocket::discardClient()"); 866 //qDebug(" KServerSocket::discardClient()");
866 if ( mSocket ) { 867 if ( mSocket ) {
867 delete mSocket; 868 delete mSocket;
868 mSocket = 0; 869 mSocket = 0;
869 } 870 }
870 //emit endConnect(); 871 //emit endConnect();
871} 872}
872void KServerSocket::readClient() 873void KServerSocket::readClient()
873{ 874{
874 if ( blockRC ) 875 if ( blockRC )
875 return; 876 return;
876 if ( mSocket == 0 ) { 877 if ( mSocket == 0 ) {
877 qDebug("ERROR::KServerSocket::readClient(): mSocket == 0 "); 878 qDebug("ERROR::KServerSocket::readClient(): mSocket == 0 ");
878 return; 879 return;
879 } 880 }
880 qDebug("KServerSocket readClient()"); 881 qDebug("KServerSocket readClient()");
881 if ( mSocket->canReadLine() ) { 882 if ( mSocket->canReadLine() ) {
882 QString line = mSocket->readLine(); 883 QString line = mSocket->readLine();
883 qDebug("KServerSocket readline: %s ", line.latin1()); 884 qDebug("KServerSocket readline: %s ", line.latin1());
884 QStringList tokens = QStringList::split( QRegExp("[ \r\n][ \r\n]*"), line ); 885 QStringList tokens = QStringList::split( QRegExp("[ \r\n][ \r\n]*"), line );
885 if ( tokens[0] == "GET" ) { 886 if ( tokens[0] == "GET" ) {
886 if ( tokens[1] == mPassWord ) 887 if ( tokens[1] == mPassWord )
887 //emit sendFile( mSocket ); 888 //emit sendFile( mSocket );
888 send_file(); 889 send_file();
889 else { 890 else {
890 KMessageBox::information( 0, i18n("ERROR:\nGot send file request\nwith invalid password")); 891 KMessageBox::information( 0, i18n("ERROR:\nGot send file request\nwith invalid password"));
891 qDebug("password %s, invalid password %s ",mPassWord.latin1(), tokens[1].latin1() ); 892 qDebug("password %s, invalid password %s ",mPassWord.latin1(), tokens[1].latin1() );
892 } 893 }
893 } 894 }
894 if ( tokens[0] == "PUT" ) { 895 if ( tokens[0] == "PUT" ) {
895 if ( tokens[1] == mPassWord ) { 896 if ( tokens[1] == mPassWord ) {
896 //emit getFile( mSocket ); 897 //emit getFile( mSocket );
897 blockRC = true; 898 blockRC = true;
898 get_file(); 899 get_file();
899 } 900 }
900 else { 901 else {
901 KMessageBox::information( 0, i18n("ERROR:\nGot receive file request\nwith invalid password")); 902 KMessageBox::information( 0, i18n("ERROR:\nGot receive file request\nwith invalid password"));
902 qDebug("password %s, invalid password %s ",mPassWord.latin1(), tokens[1].latin1() ); 903 qDebug("password %s, invalid password %s ",mPassWord.latin1(), tokens[1].latin1() );
903 } 904 }
904 } 905 }
905 if ( tokens[0] == "STOP" ) { 906 if ( tokens[0] == "STOP" ) {
906 //emit endConnect(); 907 //emit endConnect();
907 end_connect(); 908 end_connect();
908 } 909 }
909 } 910 }
910} 911}
911void KServerSocket::end_connect() 912void KServerSocket::end_connect()
912{ 913{
913 delete mSyncActionDialog; 914 delete mSyncActionDialog;
914 mSyncActionDialog = 0; 915 mSyncActionDialog = 0;
915} 916}
916void KServerSocket::send_file() 917void KServerSocket::send_file()
917{ 918{
918 //qDebug("MainWindow::sendFile(QSocket* s) "); 919 //qDebug("MainWindow::sendFile(QSocket* s) ");
919 if ( mSyncActionDialog ) 920 if ( mSyncActionDialog )
920 delete mSyncActionDialog; 921 delete mSyncActionDialog;
921 mSyncActionDialog = new QDialog ( 0, "input-dialog", true ); 922 mSyncActionDialog = new QDialog ( 0, "input-dialog", true );
922 mSyncActionDialog->setCaption(i18n("Received sync request")); 923 mSyncActionDialog->setCaption(i18n("Received sync request"));
923 QLabel* label = new QLabel( i18n("Synchronizing from remote ...\n\nDo not use this application!\n\nIf syncing fails\nyou can close this dialog."), mSyncActionDialog ); 924 QLabel* label = new QLabel( i18n("Synchronizing from remote ...\n\nDo not use this application!\n\nIf syncing fails\nyou can close this dialog."), mSyncActionDialog );
924 QVBoxLayout* lay = new QVBoxLayout( mSyncActionDialog ); 925 QVBoxLayout* lay = new QVBoxLayout( mSyncActionDialog );
925 lay->addWidget( label); 926 lay->addWidget( label);
926 lay->setMargin(7); 927 lay->setMargin(7);
927 lay->setSpacing(7); 928 lay->setSpacing(7);
928 mSyncActionDialog->setFixedSize( 230, 120); 929 mSyncActionDialog->setFixedSize( 230, 120);
929 mSyncActionDialog->show(); 930 mSyncActionDialog->show();
930 qDebug("KSS::saving ... "); 931 qDebug("KSS::saving ... ");
931 emit saveFile(); 932 emit request_file();
932 qApp->processEvents(); 933 qApp->processEvents();
933 QString fileName = mFileName; 934 QString fileName = mFileName;
934 QFile file( fileName ); 935 QFile file( fileName );
935 if (!file.open( IO_ReadOnly ) ) { 936 if (!file.open( IO_ReadOnly ) ) {
936 delete mSyncActionDialog; 937 delete mSyncActionDialog;
937 mSyncActionDialog = 0; 938 mSyncActionDialog = 0;
938 qDebug("KSS::error open file "); 939 qDebug("KSS::error open file ");
939 mSocket->close(); 940 mSocket->close();
940 if ( mSocket->state() == QSocket::Idle ) 941 if ( mSocket->state() == QSocket::Idle )
941 QTimer::singleShot( 10, this , SLOT ( discardClient())); 942 QTimer::singleShot( 10, this , SLOT ( discardClient()));
942 return ; 943 return ;
943 944
944 } 945 }
945 mSyncActionDialog->setCaption( i18n("Sending file...") ); 946 mSyncActionDialog->setCaption( i18n("Sending file...") );
946 QTextStream ts( &file ); 947 QTextStream ts( &file );
947 ts.setCodec( QTextCodec::codecForName("utf8") ); 948 ts.setCodec( QTextCodec::codecForName("utf8") );
948 QTextStream os( mSocket ); 949 QTextStream os( mSocket );
949 os.setCodec( QTextCodec::codecForName("utf8") ); 950 os.setCodec( QTextCodec::codecForName("utf8") );
950 //os.setEncoding( QTextStream::UnicodeUTF8 ); 951 //os.setEncoding( QTextStream::UnicodeUTF8 );
951 while ( ! ts.atEnd() ) { 952 while ( ! ts.atEnd() ) {
952 os << ts.readLine() << "\n"; 953 os << ts.readLine() << "\n";
953 } 954 }
954 //os << ts.read(); 955 //os << ts.read();
955 file.close(); 956 file.close();
956 mSyncActionDialog->setCaption( i18n("Waiting for synced file...") ); 957 mSyncActionDialog->setCaption( i18n("Waiting for synced file...") );
957 mSocket->close(); 958 mSocket->close();
958 if ( mSocket->state() == QSocket::Idle ) 959 if ( mSocket->state() == QSocket::Idle )
959 QTimer::singleShot( 10, this , SLOT ( discardClient())); 960 QTimer::singleShot( 10, this , SLOT ( discardClient()));
960} 961}
961void KServerSocket::get_file() 962void KServerSocket::get_file()
962{ 963{
963 mSyncActionDialog->setCaption( i18n("Receiving synced file...") ); 964 mSyncActionDialog->setCaption( i18n("Receiving synced file...") );
964 965
965 piTime.start(); 966 piTime.start();
966 piFileString = ""; 967 piFileString = "";
967 QTimer::singleShot( 1, this , SLOT (readBackFileFromSocket( ) )); 968 QTimer::singleShot( 1, this , SLOT (readBackFileFromSocket( ) ));
968} 969}
969 970
970 971
971void KServerSocket::readBackFileFromSocket() 972void KServerSocket::readBackFileFromSocket()
972{ 973{
973 //qDebug("readBackFileFromSocket() %d ", piTime.elapsed ()); 974 //qDebug("readBackFileFromSocket() %d ", piTime.elapsed ());
974 while ( mSocket->canReadLine () ) { 975 while ( mSocket->canReadLine () ) {
975 piTime.restart(); 976 piTime.restart();
976 QString line = mSocket->readLine (); 977 QString line = mSocket->readLine ();
977 piFileString += line; 978 piFileString += line;
978 //qDebug("readline: %s ", line.latin1()); 979 //qDebug("readline: %s ", line.latin1());
979 mSyncActionDialog->setCaption( i18n("Received %1 bytes").arg( piFileString.length() ) ); 980 mSyncActionDialog->setCaption( i18n("Received %1 bytes").arg( piFileString.length() ) );
980 981
981 } 982 }
982 if ( piTime.elapsed () < 3000 ) { 983 if ( piTime.elapsed () < 3000 ) {
983 // wait for more 984 // wait for more
984 //qDebug("waitformore "); 985 //qDebug("waitformore ");
985 QTimer::singleShot( 100, this , SLOT (readBackFileFromSocket( ) )); 986 QTimer::singleShot( 100, this , SLOT (readBackFileFromSocket( ) ));
986 return; 987 return;
987 } 988 }
988 QString fileName = mFileName; 989 QString fileName = mFileName;
989 QFile file ( fileName ); 990 QFile file ( fileName );
990 if (!file.open( IO_WriteOnly ) ) { 991 if (!file.open( IO_WriteOnly ) ) {
991 delete mSyncActionDialog; 992 delete mSyncActionDialog;
992 mSyncActionDialog = 0; 993 mSyncActionDialog = 0;
993 qDebug("error open cal file "); 994 qDebug("error open cal file ");
994 piFileString = ""; 995 piFileString = "";
995 emit file_received( false ); 996 emit file_received( false );
996 blockRC = false; 997 blockRC = false;
997 return ; 998 return ;
998 999
999 } 1000 }
1000 1001
1001 // mView->setLoadedFileVersion(QDateTime::currentDateTime().addSecs( -1)); 1002 // mView->setLoadedFileVersion(QDateTime::currentDateTime().addSecs( -1));
1002 QTextStream ts ( &file ); 1003 QTextStream ts ( &file );
1003 ts.setCodec( QTextCodec::codecForName("utf8") ); 1004 ts.setCodec( QTextCodec::codecForName("utf8") );
1004 mSyncActionDialog->setCaption( i18n("Writing file to disk...") ); 1005 mSyncActionDialog->setCaption( i18n("Writing file to disk...") );
1005 ts << piFileString; 1006 ts << piFileString;
1006 mSocket->close(); 1007 mSocket->close();
1007 if ( mSocket->state() == QSocket::Idle ) 1008 if ( mSocket->state() == QSocket::Idle )
1008 QTimer::singleShot( 10, this , SLOT ( discardClient())); 1009 QTimer::singleShot( 10, this , SLOT ( discardClient()));
1009 file.close(); 1010 file.close();
1010 delete mSyncActionDialog; 1011 delete mSyncActionDialog;
1011 mSyncActionDialog = 0; 1012 mSyncActionDialog = 0;
1012 piFileString = ""; 1013 piFileString = "";
1013 blockRC = false; 1014 blockRC = false;
1014 emit file_received( true ); 1015 emit file_received( true );
1015 1016
1016} 1017}
1017 1018
1018KCommandSocket::KCommandSocket ( QString password, Q_UINT16 port, QString host, QObject * parent, const char * name ): QObject( parent, name ) 1019KCommandSocket::KCommandSocket ( QString password, Q_UINT16 port, QString host, QObject * parent, const char * name ): QObject( parent, name )
1019{ 1020{
1020 mPassWord = password; 1021 mPassWord = password;
1021 mSocket = 0; 1022 mSocket = 0;
1022 mPort = port; 1023 mPort = port;
1023 mHost = host; 1024 mHost = host;
1024 1025
1025 mRetVal = quiet; 1026 mRetVal = quiet;
1026 mTimerSocket = new QTimer ( this ); 1027 mTimerSocket = new QTimer ( this );
1027 connect( mTimerSocket, SIGNAL ( timeout () ), this, SLOT ( deleteSocket() ) ); 1028 connect( mTimerSocket, SIGNAL ( timeout () ), this, SLOT ( deleteSocket() ) );
1028} 1029}
1029void KCommandSocket::readFile( QString fn ) 1030void KCommandSocket::readFile( QString fn )
1030{ 1031{
1031 if ( !mSocket ) { 1032 if ( !mSocket ) {
1032 mSocket = new QSocket( this ); 1033 mSocket = new QSocket( this );
1033 connect( mSocket, SIGNAL(readyRead()), this, SLOT(startReadFileFromSocket()) ); 1034 connect( mSocket, SIGNAL(readyRead()), this, SLOT(startReadFileFromSocket()) );
1034 connect( mSocket, SIGNAL(delayedCloseFinished ()), this, SLOT(deleteSocket()) ); 1035 connect( mSocket, SIGNAL(delayedCloseFinished ()), this, SLOT(deleteSocket()) );
1035 } 1036 }
1036 mFileString = ""; 1037 mFileString = "";
1037 mFileName = fn; 1038 mFileName = fn;
1038 mFirst = true; 1039 mFirst = true;
1039 mSocket->connectToHost( mHost, mPort ); 1040 mSocket->connectToHost( mHost, mPort );
1040 QTextStream os( mSocket ); 1041 QTextStream os( mSocket );
1041 os.setEncoding( QTextStream::UnicodeUTF8 ); 1042 os.setEncoding( QTextStream::UnicodeUTF8 );
1042 os << "GET " << mPassWord << "\r\n"; 1043 os << "GET " << mPassWord << "\r\n";
1043 mTimerSocket->start( 10000 ); 1044 mTimerSocket->start( 10000 );
1044} 1045}
1045 1046
1046void KCommandSocket::writeFile( QString fileName ) 1047void KCommandSocket::writeFile( QString fileName )
1047{ 1048{
1048 if ( !mSocket ) { 1049 if ( !mSocket ) {
1049 mSocket = new QSocket( this ); 1050 mSocket = new QSocket( this );
1050 connect( mSocket, SIGNAL(delayedCloseFinished ()), this, SLOT(deleteSocket()) ); 1051 connect( mSocket, SIGNAL(delayedCloseFinished ()), this, SLOT(deleteSocket()) );
1051 connect( mSocket, SIGNAL(connected ()), this, SLOT(writeFileToSocket()) ); 1052 connect( mSocket, SIGNAL(connected ()), this, SLOT(writeFileToSocket()) );
1052 } 1053 }
1053 mFileName = fileName ; 1054 mFileName = fileName ;
1054 mSocket->connectToHost( mHost, mPort ); 1055 mSocket->connectToHost( mHost, mPort );
1055} 1056}
1056void KCommandSocket::writeFileToSocket() 1057void KCommandSocket::writeFileToSocket()
1057{ 1058{
1058 QFile file2( mFileName ); 1059 QFile file2( mFileName );
1059 if (!file2.open( IO_ReadOnly ) ) { 1060 if (!file2.open( IO_ReadOnly ) ) {