-rw-r--r-- | korganizer/mainwindow.cpp | 23 |
1 files changed, 14 insertions, 9 deletions
diff --git a/korganizer/mainwindow.cpp b/korganizer/mainwindow.cpp index fe7e6d3..b7176a1 100644 --- a/korganizer/mainwindow.cpp +++ b/korganizer/mainwindow.cpp | |||
@@ -2481,123 +2481,128 @@ void KServerSocket::readBackFileFromSocket() | |||
2481 | } | 2481 | } |
2482 | 2482 | ||
2483 | // mView->setLoadedFileVersion(QDateTime::currentDateTime().addSecs( -1)); | 2483 | // mView->setLoadedFileVersion(QDateTime::currentDateTime().addSecs( -1)); |
2484 | QTextStream ts ( &file ); | 2484 | QTextStream ts ( &file ); |
2485 | ts.setCodec( QTextCodec::codecForName("utf8") ); | 2485 | ts.setCodec( QTextCodec::codecForName("utf8") ); |
2486 | mSyncActionDialog->setCaption( i18n("Writing file to disk...") ); | 2486 | mSyncActionDialog->setCaption( i18n("Writing file to disk...") ); |
2487 | ts << piFileString; | 2487 | ts << piFileString; |
2488 | mSocket->close(); | 2488 | mSocket->close(); |
2489 | if ( mSocket->state() == QSocket::Idle ) | 2489 | if ( mSocket->state() == QSocket::Idle ) |
2490 | QTimer::singleShot( 10, this , SLOT ( discardClient())); | 2490 | QTimer::singleShot( 10, this , SLOT ( discardClient())); |
2491 | file.close(); | 2491 | file.close(); |
2492 | delete mSyncActionDialog; | 2492 | delete mSyncActionDialog; |
2493 | mSyncActionDialog = 0; | 2493 | mSyncActionDialog = 0; |
2494 | piFileString = ""; | 2494 | piFileString = ""; |
2495 | emit file_received( true ); | 2495 | emit file_received( true ); |
2496 | 2496 | ||
2497 | } | 2497 | } |
2498 | 2498 | ||
2499 | KCommandSocket::KCommandSocket ( QString password, Q_UINT16 port, QString host, QObject * parent, const char * name ): QObject( parent, name ) | 2499 | KCommandSocket::KCommandSocket ( QString password, Q_UINT16 port, QString host, QObject * parent, const char * name ): QObject( parent, name ) |
2500 | { | 2500 | { |
2501 | mPassWord = password; | 2501 | mPassWord = password; |
2502 | mSocket = 0; | 2502 | mSocket = 0; |
2503 | mPort = port; | 2503 | mPort = port; |
2504 | mHost = host; | 2504 | mHost = host; |
2505 | 2505 | ||
2506 | mRetVal = false; | 2506 | mRetVal = false; |
2507 | mTimerSocket = new QTimer ( this ); | 2507 | mTimerSocket = new QTimer ( this ); |
2508 | connect( mTimerSocket, SIGNAL ( timeout () ), this, SLOT ( deleteSocket() ) ); | 2508 | connect( mTimerSocket, SIGNAL ( timeout () ), this, SLOT ( deleteSocket() ) ); |
2509 | } | 2509 | } |
2510 | void KCommandSocket::readFile( QString fn ) | 2510 | void KCommandSocket::readFile( QString fn ) |
2511 | { | 2511 | { |
2512 | if ( !mSocket ) { | 2512 | if ( !mSocket ) { |
2513 | mSocket = new QSocket( this ); | 2513 | mSocket = new QSocket( this ); |
2514 | connect( mSocket, SIGNAL(readyRead()), this, SLOT(startReadFileFromSocket()) ); | 2514 | connect( mSocket, SIGNAL(readyRead()), this, SLOT(startReadFileFromSocket()) ); |
2515 | connect( mSocket, SIGNAL(delayedCloseFinished ()), this, SLOT(deleteSocket()) ); | 2515 | connect( mSocket, SIGNAL(delayedCloseFinished ()), this, SLOT(deleteSocket()) ); |
2516 | } | 2516 | } |
2517 | mFileString = ""; | 2517 | mFileString = ""; |
2518 | mFileName = fn; | 2518 | mFileName = fn; |
2519 | mFirst = true; | 2519 | mFirst = true; |
2520 | mSocket->connectToHost( mHost, mPort ); | 2520 | mSocket->connectToHost( mHost, mPort ); |
2521 | QTextStream os( mSocket ); | 2521 | QTextStream os( mSocket ); |
2522 | os.setEncoding( QTextStream::UnicodeUTF8 ); | 2522 | os.setEncoding( QTextStream::UnicodeUTF8 ); |
2523 | os << "GET " << mPassWord << "\r\n"; | 2523 | os << "GET " << mPassWord << "\r\n"; |
2524 | mTimerSocket->start( 10000 ); | 2524 | mTimerSocket->start( 10000 ); |
2525 | } | 2525 | } |
2526 | 2526 | ||
2527 | void KCommandSocket::writeFile( QString fileName ) | 2527 | void KCommandSocket::writeFile( QString fileName ) |
2528 | { | 2528 | { |
2529 | QFile file2( fileName ); | ||
2530 | if (!file2.open( IO_ReadOnly ) ) { | ||
2531 | mRetVal= false; | ||
2532 | deleteSocket(); | ||
2533 | return ; | ||
2534 | |||
2535 | } | ||
2536 | if ( !mSocket ) { | 2529 | if ( !mSocket ) { |
2537 | mSocket = new QSocket( this ); | 2530 | mSocket = new QSocket( this ); |
2538 | connect( mSocket, SIGNAL(delayedCloseFinished ()), this, SLOT(deleteSocket()) ); | 2531 | connect( mSocket, SIGNAL(delayedCloseFinished ()), this, SLOT(deleteSocket()) ); |
2532 | connect( mSocket, SIGNAL(connected ()), this, SLOT(writeFileToSocket()) ); | ||
2539 | } | 2533 | } |
2534 | mFileName = fileName ; | ||
2540 | mSocket->connectToHost( mHost, mPort ); | 2535 | mSocket->connectToHost( mHost, mPort ); |
2536 | } | ||
2537 | void KCommandSocket::writeFileToSocket() | ||
2538 | { | ||
2539 | QFile file2( mFileName ); | ||
2540 | if (!file2.open( IO_ReadOnly ) ) { | ||
2541 | mRetVal= false; | ||
2542 | mSocket->close(); | ||
2543 | if ( mSocket->state() == QSocket::Idle ) | ||
2544 | QTimer::singleShot( 10, this , SLOT ( deleteSocket())); | ||
2545 | return ; | ||
2546 | } | ||
2541 | QTextStream ts2( &file2 ); | 2547 | QTextStream ts2( &file2 ); |
2542 | ts2.setCodec( QTextCodec::codecForName("utf8") ); | 2548 | ts2.setCodec( QTextCodec::codecForName("utf8") ); |
2543 | QTextStream os2( mSocket ); | 2549 | QTextStream os2( mSocket ); |
2544 | os2.setCodec( QTextCodec::codecForName("utf8") ); | 2550 | os2.setCodec( QTextCodec::codecForName("utf8") ); |
2545 | os2 << "PUT " << mPassWord << "\r\n";; | 2551 | os2 << "PUT " << mPassWord << "\r\n";; |
2546 | while ( ! ts2.atEnd() ) { | 2552 | while ( ! ts2.atEnd() ) { |
2547 | os2 << ts2.readLine() << "\n"; | 2553 | os2 << ts2.readLine() << "\n"; |
2548 | } | 2554 | } |
2549 | mRetVal= true; | 2555 | mRetVal= true; |
2556 | file2.close(); | ||
2550 | mSocket->close(); | 2557 | mSocket->close(); |
2551 | if ( mSocket->state() == QSocket::Idle ) | 2558 | if ( mSocket->state() == QSocket::Idle ) |
2552 | QTimer::singleShot( 10, this , SLOT ( deleteSocket())); | 2559 | QTimer::singleShot( 10, this , SLOT ( deleteSocket())); |
2553 | file2.close(); | ||
2554 | } | 2560 | } |
2555 | |||
2556 | void KCommandSocket::sendStop() | 2561 | void KCommandSocket::sendStop() |
2557 | { | 2562 | { |
2558 | if ( !mSocket ) { | 2563 | if ( !mSocket ) { |
2559 | mSocket = new QSocket( this ); | 2564 | mSocket = new QSocket( this ); |
2560 | connect( mSocket, SIGNAL(delayedCloseFinished ()), this, SLOT(deleteSocket()) ); | 2565 | connect( mSocket, SIGNAL(delayedCloseFinished ()), this, SLOT(deleteSocket()) ); |
2561 | } | 2566 | } |
2562 | mSocket->connectToHost( mHost, mPort ); | 2567 | mSocket->connectToHost( mHost, mPort ); |
2563 | QTextStream os2( mSocket ); | 2568 | QTextStream os2( mSocket ); |
2564 | os2.setCodec( QTextCodec::codecForName("utf8") ); | 2569 | os2.setCodec( QTextCodec::codecForName("utf8") ); |
2565 | os2 << "STOP\r\n"; | 2570 | os2 << "STOP\r\n"; |
2566 | mRetVal= true; | 2571 | mRetVal= true; |
2567 | mSocket->close(); | 2572 | mSocket->close(); |
2568 | if ( mSocket->state() == QSocket::Idle ) | 2573 | if ( mSocket->state() == QSocket::Idle ) |
2569 | QTimer::singleShot( 10, this , SLOT ( deleteSocket())); | 2574 | QTimer::singleShot( 10, this , SLOT ( deleteSocket())); |
2570 | } | 2575 | } |
2571 | 2576 | ||
2572 | void KCommandSocket::startReadFileFromSocket() | 2577 | void KCommandSocket::startReadFileFromSocket() |
2573 | { | 2578 | { |
2574 | if ( ! mFirst ) | 2579 | if ( ! mFirst ) |
2575 | return; | 2580 | return; |
2576 | mFirst = false; | 2581 | mFirst = false; |
2577 | mTimerSocket->stop(); | 2582 | mTimerSocket->stop(); |
2578 | mFileString = ""; | 2583 | mFileString = ""; |
2579 | mTime.start(); | 2584 | mTime.start(); |
2580 | QTimer::singleShot( 1, this , SLOT (readFileFromSocket( ) )); | 2585 | QTimer::singleShot( 1, this , SLOT (readFileFromSocket( ) )); |
2581 | 2586 | ||
2582 | } | 2587 | } |
2583 | void KCommandSocket::readFileFromSocket() | 2588 | void KCommandSocket::readFileFromSocket() |
2584 | { | 2589 | { |
2585 | //qDebug("readBackFileFromSocket() %d ", mTime.elapsed ()); | 2590 | //qDebug("readBackFileFromSocket() %d ", mTime.elapsed ()); |
2586 | while ( mSocket->canReadLine () ) { | 2591 | while ( mSocket->canReadLine () ) { |
2587 | mTime.restart(); | 2592 | mTime.restart(); |
2588 | QString line = mSocket->readLine (); | 2593 | QString line = mSocket->readLine (); |
2589 | mFileString += line; | 2594 | mFileString += line; |
2590 | //qDebug("readline: %s ", line.latin1()); | 2595 | //qDebug("readline: %s ", line.latin1()); |
2591 | } | 2596 | } |
2592 | if ( mTime.elapsed () < 3000 ) { | 2597 | if ( mTime.elapsed () < 3000 ) { |
2593 | // wait for more | 2598 | // wait for more |
2594 | //qDebug("waitformore "); | 2599 | //qDebug("waitformore "); |
2595 | QTimer::singleShot( 100, this , SLOT (readFileFromSocket( ) )); | 2600 | QTimer::singleShot( 100, this , SLOT (readFileFromSocket( ) )); |
2596 | return; | 2601 | return; |
2597 | } | 2602 | } |
2598 | QString fileName = mFileName; | 2603 | QString fileName = mFileName; |
2599 | QFile file ( fileName ); | 2604 | QFile file ( fileName ); |
2600 | if (!file.open( IO_WriteOnly ) ) { | 2605 | if (!file.open( IO_WriteOnly ) ) { |
2601 | mFileString = ""; | 2606 | mFileString = ""; |
2602 | mRetVal = false; | 2607 | mRetVal = false; |
2603 | qDebug("Error open temp calender file for writing: %s",fileName.latin1() ); | 2608 | qDebug("Error open temp calender file for writing: %s",fileName.latin1() ); |