-rw-r--r-- | korganizer/mainwindow.cpp | 52 |
1 files changed, 35 insertions, 17 deletions
diff --git a/korganizer/mainwindow.cpp b/korganizer/mainwindow.cpp index 460bbdc..f4ac0d6 100644 --- a/korganizer/mainwindow.cpp +++ b/korganizer/mainwindow.cpp @@ -1985,78 +1985,78 @@ void MainWindow::getFile(QSocket* socket) delete mSyncActionDialog; mSyncActionDialog = 0; qDebug("error open cal file "); return ; } mView->setLoadedFileVersion(QDateTime::currentDateTime().addSecs( -1)); QTextStream ts( &file ); ts.setCodec( QTextCodec::codecForName("utf8") ); bool first = true; while ( socket->canReadLine () || first ) { first = false; while ( socket->canReadLine () ) { qDebug("avail %d ", socket->bytesAvailable () ); ts << socket->readLine (); } QTime ti; ti.start(); while ( ti.elapsed () < 5000 && !socket->canReadLine () ) { qDebug("waiting1a %d %d ",ti.elapsed (), socket->bytesAvailable () ); //qApp->processEvents(); qDebug("waiting1b %d ",ti.elapsed () ); if ( !socket->canReadLine () ) { - qDebug("waiting1c %d ",ti.elapsed () ); + qDebug("waiting1c %d ",ti.elapsed () ); usleep( 100000); } //socket->waitForMore ( 100 ); } ts << socket->readLine (); #if 0 #ifdef DESKTOP_VERSION socket->waitForMore ( 5000 ); #else // socket->waitForMore ( 5000 ); // seems to be broken in qt2 bool stop = false; QTime ti; ti.start(); while ( ti.elapsed < 5000 && !stop ) { qApp->processEvents(); if ( socket->canReadLine () ) stop = true ; else { usleep( 100000 ); } } #endif #endif } setCaption( i18n("File received - reloading calendar...") ); - file.close(); socket->close(); + file.close(); mView->watchSavedFile(); mView->openCalendar( defaultFileName() ); setCaption( i18n("Easy-Pi-Sync successful!") ); delete mSyncActionDialog; mSyncActionDialog = 0; } void MainWindow::endConnect() { setCaption( i18n("No file received - syncing successful") ); delete mSyncActionDialog; mSyncActionDialog = 0; } void MainWindow::performQuick() { setCaption( i18n("Please input connection settings") ); QString retfile = ""; QDialog dia ( this, "input-dialog", true ); QLineEdit lab ( &dia ); QVBoxLayout lay( &dia ); QLabel label ( i18n("IP address\n(Example: 192.168.0.40)"), &dia ); lay.addWidget( &label); lab.setText( KOPrefs::instance()->mActiveSyncIP ); @@ -2093,139 +2093,142 @@ void MainWindow::performQuickQuick() bool ok; Q_UINT16 port = KOPrefs::instance()->mActiveSyncPort.toUInt(&ok); if ( ! ok ) { setCaption( i18n("Sorry, no valid port.Syncing cancelled.") ); return; } if ( !mCommandSocket ) { mCommandSocket = new QSocket( this ); // delete mCommandSocket; //mCommandSocket = new QSocket( this ); connect( mCommandSocket, SIGNAL(readyRead()), this, SLOT(readFileFromSocket()) ); } QString host = KOPrefs::instance()->mActiveSyncIP; mCommandSocket->connectToHost( host, port ); QTextStream os( mCommandSocket ); os.setEncoding( QTextStream::UnicodeUTF8 ); os << "GET\r\n"; setCaption( i18n("Sending request for remote file ...") ); } void MainWindow::readFileFromSocket() { setCaption( i18n("Receiving remote file ...") ); qDebug("MainWindow::readFileFromSocket() "); -QString fileName; + QString fileName; #ifdef _WIN32_ fileName = defaultFileName() +"sync"; #else fileName = "/tmp/kopitempfile.ics"; #endif QFile file( fileName ); if (!file.open( IO_WriteOnly ) ) { setCaption( i18n("Error: Cannot open temp file for write.") ); - qDebug("Error open calender file for writing: %s",fileName.latin1() ); + qDebug("Error open temp calender file for writing: %s",fileName.latin1() ); return ; } //QTextStream os2( mCommandSocket ); //os2.setEncoding( QTextStream::UnicodeUTF8 ); QTextStream ts( &file ); ts.setCodec( QTextCodec::codecForName("utf8") ); bool first = true; while ( mCommandSocket->canReadLine () || first) { first = false; while ( mCommandSocket->canReadLine () ) { ts << mCommandSocket->readLine (); } QTime ti; ti.start(); while ( ti.elapsed () < 5000 && !mCommandSocket->canReadLine () ) { qApp->processEvents(); qDebug("waiting2 %d ",ti.elapsed () ); if ( !mCommandSocket->canReadLine () ) mCommandSocket->waitForMore ( 100 ); } //mCommandSocket->waitForMore ( 5000 ); } file.close(); mCommandSocket->close(); + // pending: deleting after signal SIGNAL(delayedCloseFinished()) //delete mCommandSocket; setCaption( i18n("Remote file saved to temp file.") ); //mCommandSocket = 0; mCurrentSyncProfile = 2 ; // last file mView->setSyncDevice(KOPrefs::instance()->mSyncProfileNames[mCurrentSyncProfile] ); mView->setSyncName( KOPrefs::instance()->mLocalMachineName ); KConfig config ( locateLocal( "config","ksyncprofilesrc" ) ); KSyncProfile* temp = new KSyncProfile (); temp->setName(KOPrefs::instance()->mSyncProfileNames[mCurrentSyncProfile]); temp->readConfig(&config); KOPrefs::instance()->mAskForPreferences = temp->getAskForPreferences(); KOPrefs::instance()->mSyncAlgoPrefs = temp->getSyncPrefs(); KOPrefs::instance()->mWriteBackFile = temp->getWriteBackFile(); KOPrefs::instance()->mWriteBackExistingOnly = temp->getWriteBackExisting(); KOPrefs::instance()->mWriteBackInFuture = 0; if ( temp->getWriteBackFuture() ) KOPrefs::instance()->mWriteBackInFuture = temp->getWriteBackFutureWeeks( ); KOPrefs::instance()->mShowSyncSummary = temp->getShowSummaryAfterSync(); setCaption( i18n("Remote file saved to temp file.") ); if ( ! syncWithFile( fileName , true ) ) { setCaption( i18n("Syncing failed.") ); qDebug("Syncing failed "); return; } if ( !mCommandSocketFinish ) { mCommandSocketFinish = new QSocket( this ); } mCommandSocketFinish->connectToHost( KOPrefs::instance()->mActiveSyncIP, KOPrefs::instance()->mActiveSyncPort.toUInt() ); + // pending connect signals connected () and error to new slots QString host = KOPrefs::instance()->mActiveSyncIP; QFile file2( fileName ); if (!file2.open( IO_ReadOnly ) ) { setCaption( i18n("Error: Cannot open temp file for read.") ); qDebug("error open cal file "); return ; } setCaption( i18n("Sending back synced file...") ); QTextStream ts2( &file2 ); ts2.setCodec( QTextCodec::codecForName("utf8") ); QTextStream os2( mCommandSocketFinish ); os2.setCodec( QTextCodec::codecForName("utf8") ); //os.setEncoding( QTextStream::UnicodeUTF8 ); if ( KOPrefs::instance()->mWriteBackFile ) { os2 << "PUT\r\n"; while ( ! ts2.atEnd() ) { - os2 << ts2.readLine() << "\n"; + os2 << ts2.readLine() << "\n"; } } else { os2 << "STOP\r\n"; } mCommandSocketFinish->close(); file.close(); + // pending: deleting after signal SIGNAL(delayedCloseFinished()) //delete ( mCommandSocket); //mCommandSocket = 0; qDebug("Syncing succesful! "); setCaption( i18n("Easy-Pi-Sync succesful!") ); } void MainWindow::syncLocalFile() { QString fn =KOPrefs::instance()->mLastSyncedLocalFile; fn =KFileDialog:: getOpenFileName( fn, i18n("Sync filename(*.ics/*.vcs)"), this ); if ( fn == "" ) return; //mView->setSyncDevice("local-file" ); if ( syncWithFile( fn, false ) ) { // Event* e = mView->getLastSyncEvent(); // e->setReadOnly( false ); // e->setLocation( i18n("Local file: ")+ KOPrefs::instance()->mLastSyncedLocalFile); // e->setReadOnly( true ); } @@ -2470,72 +2473,87 @@ void MainWindow::syncSharp() slotModifiedChanged( true ); } void MainWindow::syncPhone() { if ( mCalendarModifiedFlag ) save(); mView->syncPhone(); slotModifiedChanged( true ); } void MainWindow::printSel( ) { mView->viewManager()->agendaView()->agenda()->printSelection(); } void MainWindow::printCal() { mView->print();//mCp->showDialog(); } -KServerSocket:: KServerSocket ( Q_UINT16 port, int backlog, QObject * parent, const char * name ) : QServerSocket( port, backlog, parent, name ){;}; +KServerSocket:: KServerSocket ( Q_UINT16 port, int backlog, QObject * parent, const char * name ) : QServerSocket( port, backlog, parent, name ) +{ + + mSocket = 0; +}; void KServerSocket::newConnection ( int socket ) { qDebug("KServerSocket:New connection %d ", socket); - QSocket* s = new QSocket( this ); - connect( s, SIGNAL(readyRead()), this, SLOT(readClient()) ); - connect( s, SIGNAL(delayedCloseFinished()), this, SLOT(discardClient()) ); - s->setSocket( socket ); + if ( mSocket ) { + qDebug("KServerSocket::newConnection Socket deleted! "); + delete mSocket; + mSocket = 0; + } + mSocket = new QSocket( this ); + connect( mSocket , SIGNAL(readyRead()), this, SLOT(readClient()) ); + connect( mSocket , SIGNAL(delayedCloseFinished()), this, SLOT(discardClient()) ); + mSocket->setSocket( socket ); } void KServerSocket::discardClient() { qDebug(" KServerSocket::discardClient()"); - QSocket* socket = (QSocket*)sender(); - delete socket; + if ( mSocket ) { + qDebug("delete "); + delete mSocket; + mSocket = 0; + } //emit endConnect(); } void KServerSocket::readClient() { + if ( mSocket == 0 ) { + qDebug("ERROR::KServerSocket::readClient(): mSocket == 0 "); + return; + } qDebug("KServerSocket readClient()"); - QSocket* socket = (QSocket*)sender(); - if ( socket->canReadLine() ) { - QStringList tokens = QStringList::split( QRegExp("[ \r\n][ \r\n]*"), socket->readLine() ); + if ( mSocket->canReadLine() ) { + QStringList tokens = QStringList::split( QRegExp("[ \r\n][ \r\n]*"), mSocket->readLine() ); qDebug("KServerSocket socket->canReadLine()"); if ( tokens[0] == "GET" ) { - emit sendFile( socket ); + emit sendFile( mSocket ); } if ( tokens[0] == "PUT" ) { - emit getFile( socket ); + emit getFile( mSocket ); } if ( tokens[0] == "STOP" ) { emit endConnect(); } } } |