-rw-r--r-- | korganizer/mainwindow.cpp | 105 | ||||
-rw-r--r-- | korganizer/mainwindow.h | 38 |
2 files changed, 101 insertions, 42 deletions
diff --git a/korganizer/mainwindow.cpp b/korganizer/mainwindow.cpp index 2e6b5c8..460bbdc 100644 --- a/korganizer/mainwindow.cpp +++ b/korganizer/mainwindow.cpp @@ -1,14 +1,15 @@ #include <stdlib.h> #include <qaction.h> #include <qpopupmenu.h> #include <qpainter.h> #include <qwhatsthis.h> +#include <qpushbutton.h> #include <qmessagebox.h> #include <qlineedit.h> #include <qtextcodec.h> #include <qfile.h> #include <qdir.h> #include <qapp.h> #include <qfileinfo.h> #include <qlabel.h> @@ -19,16 +20,17 @@ #ifndef DESKTOP_VERSION #include <qpe/global.h> #include <qpe/qpemenubar.h> #include <qpe/qpetoolbar.h> #include <qpe/resource.h> #include <qpe/qpeapplication.h> #include <qtopia/alarmserver.h> #include <qtopia/qcopenvelope_qws.h> +#include <unistd.h> // for sleep #else #include <qmenubar.h> #include <qtoolbar.h> #include <qapplication.h> //#include <resource.h> #endif #include <libkcal/calendarlocal.h> @@ -1141,22 +1143,17 @@ void MainWindow::features() displayFile( "featuresKOPI.txt",i18n("KO/Pi Features and hints") ); } void MainWindow::usertrans() { displayFile( "usertranslationHOWTO.txt",i18n("KO/Pi User translation HowTo") ); } -#if 0 -#include <libkcal/vcalformat.h> -#include <libkcal/event.h> -#include <libkcal/todo.h> -#include <libkcal/incidence.h> -#endif + void MainWindow::synchowto() { #if 0 QPtrList<Incidence> er = mCalendar->rawIncidences(); Incidence* inR = er.first(); VCalFormat vf; QString strout; while ( inR ) { @@ -1423,17 +1420,16 @@ void MainWindow::slotModifiedChanged( bool changed ) if ( !mBlockSaveFlag ) msec = (1000 * 60*KOPrefs::instance()->mAutoSaveInterval) +1000; else msec = 1000 * 600; mSaveTimer.start( msec, true ); // 1 minute qDebug("KO: Saving File in %d secs!", msec/1000); mCalendarModifiedFlag = true; } -#include <qfileinfo.h> void MainWindow::save() { if ( mBlockSaveFlag ) return; bool store = mBlockSaveFlag; mBlockSaveFlag = true; if ( mView->checkFileVersion( defaultFileName()) ) { @@ -1861,17 +1857,16 @@ void MainWindow::exportVCalendar() mes = i18n("KO/Pi:Exported to ...%1").arg(fn.right(20)) ; else mes = i18n("KO/Pi:Exported to %1").arg(fn ); setCaption(mes); } } } -#include <qpushbutton.h> QString MainWindow::getPassword( ) { QString retfile = ""; QDialog dia ( this, "input-dialog", true ); QLineEdit lab ( &dia ); lab.setEchoMode( QLineEdit::Password ); QVBoxLayout lay( &dia ); lay.setMargin(7); @@ -1996,19 +1991,52 @@ void MainWindow::getFile(QSocket* socket) 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 () ); + 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(); mView->watchSavedFile(); mView->openCalendar( defaultFileName() ); setCaption( i18n("Easy-Pi-Sync successful!") ); delete mSyncActionDialog; @@ -2104,18 +2132,26 @@ QString fileName; 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 ); + //mCommandSocket->waitForMore ( 5000 ); } file.close(); mCommandSocket->close(); //delete mCommandSocket; setCaption( i18n("Remote file saved to temp file.") ); //mCommandSocket = 0; mCurrentSyncProfile = 2 ; // last file mView->setSyncDevice(KOPrefs::instance()->mSyncProfileNames[mCurrentSyncProfile] ); @@ -2447,8 +2483,59 @@ 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 ){;}; + +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 ); +} + +void KServerSocket::discardClient() +{ + qDebug(" KServerSocket::discardClient()"); + QSocket* socket = (QSocket*)sender(); + delete socket; + //emit endConnect(); +} +void KServerSocket::readClient() +{ + qDebug("KServerSocket readClient()"); + QSocket* socket = (QSocket*)sender(); + if ( socket->canReadLine() ) { + QStringList tokens = QStringList::split( QRegExp("[ \r\n][ \r\n]*"), socket->readLine() ); + qDebug("KServerSocket socket->canReadLine()"); + if ( tokens[0] == "GET" ) { + emit sendFile( socket ); + } + if ( tokens[0] == "PUT" ) { + emit getFile( socket ); + } + if ( tokens[0] == "STOP" ) { + emit endConnect(); + } + } +} + + + + + + + + + + + + diff --git a/korganizer/mainwindow.h b/korganizer/mainwindow.h index 5985d56..7b4fd27 100644 --- a/korganizer/mainwindow.h +++ b/korganizer/mainwindow.h @@ -22,55 +22,27 @@ class QPEToolBar; #include <qsocket.h> #include <qnetworkprotocol.h> class KServerSocket : public QServerSocket { Q_OBJECT public: - KServerSocket ( Q_UINT16 port, int backlog = 0, QObject * parent=0, const char * name=0 ) : - QServerSocket( port, backlog, parent, name ){;}; - void 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 ); - } + KServerSocket ( Q_UINT16 port, int backlog = 0, QObject * parent=0, const char * name=0 ); + + void newConnection ( int socket ) ; signals: void sendFile(QSocket*); void getFile(QSocket*); void endConnect(); private slots: - void discardClient() - { - QSocket* socket = (QSocket*)sender(); - delete socket; - //emit endConnect(); - } - void readClient() - { - qDebug("readClient() "); - QSocket* socket = (QSocket*)sender(); - if ( socket->canReadLine() ) { - QStringList tokens = QStringList::split( QRegExp("[ \r\n][ \r\n]*"), socket->readLine() ); - if ( tokens[0] == "GET" ) { - emit sendFile( socket ); - } - if ( tokens[0] == "PUT" ) { - emit getFile( socket ); - } - if ( tokens[0] == "STOP" ) { - emit endConnect(); - } - } - } + void discardClient(); + void readClient(); }; namespace KCal { class CalendarLocal; } using namespace KCal; |