summaryrefslogtreecommitdiffabout
path: root/korganizer
Side-by-side diff
Diffstat (limited to 'korganizer') (more/less context) (ignore whitespace changes)
-rw-r--r--korganizer/mainwindow.cpp178
-rw-r--r--korganizer/mainwindow.h34
2 files changed, 142 insertions, 70 deletions
diff --git a/korganizer/mainwindow.cpp b/korganizer/mainwindow.cpp
index 10cb2a2..e4b7869 100644
--- a/korganizer/mainwindow.cpp
+++ b/korganizer/mainwindow.cpp
@@ -68,14 +68,12 @@ using namespace KCal;
int globalFlagBlockStartup;
MainWindow::MainWindow( QWidget *parent, const char *name, QString msg) :
QMainWindow( parent, name )
{
mPassWordPiSync = "abc";
- mTimerCommandSocket = new QTimer ( this );
- connect( mTimerCommandSocket, SIGNAL ( timeout () ), this, SLOT ( deleteCommandSocket() ) );
#ifdef DESKTOP_VERSION
setFont( QFont("Arial"), 14 );
#endif
mCommandSocket = 0;
mCommandSocketFinish = 0;
mSyncActionDialog = 0;
@@ -2100,95 +2098,55 @@ 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()) );
- connect( mCommandSocket, SIGNAL(delayedCloseFinished ()), this, SLOT(deleteCommandSocket()) );
- }
- QString host = KOPrefs::instance()->mActiveSyncIP;
- mCommandSocket->connectToHost( host, port );
- QTextStream os( mCommandSocket );
- os.setEncoding( QTextStream::UnicodeUTF8 );
- os << "GET " << mPassWordPiSync << "\r\n";
+ mCommandSocket = new KCommandSocket( mPassWordPiSync, port, KOPrefs::instance()->mActiveSyncIP, this );
+ connect( mCommandSocket, SIGNAL(commandFinished( bool )), this, SLOT(deleteCommandSocket(bool)) );
setCaption( i18n("Sending request for remote file ...") );
- mTimerCommandSocket->start( 10000 );
-
+ QString fileName;
+#ifdef _WIN32_
+ fileName = defaultFileName() +"sync";
+#else
+ fileName = "/tmp/kopitempfile.ics";
+#endif
+ mCommandSocket->readFile( fileName );
}
-void MainWindow::deleteCommandSocket()
+void MainWindow::deleteCommandSocket( bool success)
{
- if ( !mCommandSocket)
+ if ( ! success ) {
+ setCaption( i18n("ERROR:Receiving remote file failed.") );
+ // pending : send stop
return;
- if ( mTimerCommandSocket->isActive () ) {
- KMessageBox::information( 0, i18n("ERROR:\nConnection to remote host timed out "));
- mTimerCommandSocket->stop();
+
}
- //KMessageBox::information( 0, i18n("MainWindow::deleteCommandSocket "));
- qDebug("MainWindow::deletemCommandSocket() ");
- delete mCommandSocket;
- mCommandSocket = 0;
+ QTimer::singleShot( 1, this , SLOT ( readFileFromSocket()));
+ delete mCommandSocket;
}
void MainWindow::deleteCommandSocketFinish()
{
if ( ! mCommandSocketFinish)
return;
// KMessageBox::information( 0, i18n("MainWindow::deleteCommandSocketFinish() "));
qDebug("MainWindow::deletemCommandSocketFinish() ");
delete mCommandSocketFinish;
mCommandSocketFinish = 0;
}
void MainWindow::readFileFromSocket()
{
- mTimerCommandSocket->stop();
+ // mTimerCommandSocket->stop();
setCaption( i18n("Receiving remote file ...") );
qDebug("MainWindow::readFileFromSocket() ");
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 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 () < 3000 && !mCommandSocket->canReadLine () ) {
- qApp->processEvents();
- qDebug("waiting2 %d ",ti.elapsed () );
- if ( !mCommandSocket->canReadLine () )
- mCommandSocket->waitForMore ( 100 );
- }
- //mCommandSocket->waitForMore ( 5000 );
- }
- file.close();
- mCommandSocket->close();
- if ( mCommandSocket->state() == QSocket::Idle )
- deleteCommandSocket();
- // 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" ) );
@@ -2214,13 +2172,12 @@ void MainWindow::readFileFromSocket()
if ( !mCommandSocketFinish ) {
mCommandSocketFinish = new QSocket( this );
connect( mCommandSocketFinish, SIGNAL(delayedCloseFinished ()), this, SLOT(deleteCommandSocketFinish()) );
}
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 ;
@@ -2240,13 +2197,13 @@ void MainWindow::readFileFromSocket()
} else {
os2 << "STOP\r\n";
}
mCommandSocketFinish->close();
if ( mCommandSocketFinish->state() == QSocket::Idle )
QTimer::singleShot( 10, this , SLOT ( deleteCommandSocketFinish()));
- file.close();
+ file2.close();
qDebug("Syncing succesful! ");
setCaption( i18n("Pi-Sync succesful!") );
// KMessageBox::information( 0, i18n(" Pi-Sync succesful! "));
}
@@ -2588,17 +2545,104 @@ void KServerSocket::readClient()
if ( tokens[0] == "STOP" ) {
emit endConnect();
}
}
}
+KCommandSocket::KCommandSocket ( QString password, Q_UINT16 port, QString host, QObject * parent, const char * name ): QObject( parent, name )
+{
+ mPassWord = password;
+ mSocket = 0;
+ mPort = port;
+ mHost = host;
+ mRetVal = false;
+ mTimerSocket = new QTimer ( this );
+ connect( mTimerSocket, SIGNAL ( timeout () ), this, SLOT ( deleteSocket() ) );
+}
+void KCommandSocket::readFile( QString fn )
+{
+ if ( !mSocket ) {
+ mSocket = new QSocket( this );
+ connect( mSocket, SIGNAL(readyRead()), this, SLOT(startReadFileFromSocket()) );
+ connect( mSocket, SIGNAL(delayedCloseFinished ()), this, SLOT(deleteSocket()) );
+ }
+ mFileString = "";
+ mFileName = fn;
+ mFirst = true;
+ mSocket->connectToHost( mHost, mPort );
+ QTextStream os( mSocket );
+ os.setEncoding( QTextStream::UnicodeUTF8 );
+ os << "GET " << mPassWord << "\r\n";
+ mTimerSocket->start( 10000 );
+}
+void KCommandSocket::writeFile( QString )
+{
+}
+void KCommandSocket::startReadFileFromSocket()
+{
+ if ( ! mFirst )
+ return;
+ mFirst = false;
+ mTimerSocket->stop();
+ mFileString = "";
+ mTime.start();
+ QTimer::singleShot( 1, this , SLOT (readFileFromSocket( ) ));
+}
+void KCommandSocket::readFileFromSocket()
+{
+ qDebug("readBackFileFromSocket() %d ", mTime.elapsed ());
+ while ( mSocket->canReadLine () ) {
+ mTime.restart();
+ QString line = mSocket->readLine ();
+ mFileString += line;
+ qDebug("readline: %s ", line.latin1());
+ }
+ if ( mTime.elapsed () < 3000 ) {
+ // wait for more
+ qDebug("waitformore ");
+ QTimer::singleShot( 100, this , SLOT (readFileFromSocket( ) ));
+ return;
+ }
+ QString fileName = mFileName;
+ QFile file ( fileName );
+ if (!file.open( IO_WriteOnly ) ) {
+ mFileString = "";
+ mRetVal = false;
+ qDebug("Error open temp calender file for writing: %s",fileName.latin1() );
+ deleteSocket();
+ return ;
+
+ }
+ // mView->setLoadedFileVersion(QDateTime::currentDateTime().addSecs( -1));
+ QTextStream ts ( &file );
+ ts.setCodec( QTextCodec::codecForName("utf8") );
+ qDebug("finish ");
+ ts << mFileString;
+ file.close();
+ mFileString = "";
+ mRetVal = true;
+ mSocket->close();
+ // if state is not idle, deleteSocket(); is called via
+ // connect( mSocket, SIGNAL(delayedCloseFinished ()), this, SLOT(deleteSocket()) );
+ if ( mSocket->state() == QSocket::Idle )
+ deleteSocket();
+}
-
-
-
-
-
+void KCommandSocket::deleteSocket()
+{
+ if ( !mSocket)
+ return;
+ if ( mTimerSocket->isActive () ) {
+ mTimerSocket->stop();
+ KMessageBox::information( 0, i18n("ERROR:\nConnection to remote host timed out "));
+ mRetVal = false;
+ }
+ qDebug("KCommandSocket::deleteSocket() %d", mRetVal);
+ delete mSocket;
+ mSocket = 0;
+ emit commandFinished( mRetVal );
+}
diff --git a/korganizer/mainwindow.h b/korganizer/mainwindow.h
index d217578..11a816c 100644
--- a/korganizer/mainwindow.h
+++ b/korganizer/mainwindow.h
@@ -43,12 +43,40 @@ private slots:
void readClient();
private :
QSocket* mSocket;
QString mPassWord;
};
+class KCommandSocket : public QObject
+{
+ Q_OBJECT
+
+public:
+ KCommandSocket ( QString password, Q_UINT16 port, QString host, QObject * parent=0, const char * name=0 );
+ void readFile( QString );
+ void writeFile( QString );
+
+
+signals:
+ void commandFinished( bool );
+private slots:
+ void startReadFileFromSocket();
+ void readFileFromSocket();
+ void deleteSocket();
+ private :
+ QSocket* mSocket;
+ QString mPassWord;
+ Q_UINT16 mPort;
+ QString mHost;
+ QString mFileName;
+ QTimer* mTimerSocket;
+ bool mRetVal;
+ QTime mTime;
+ QString mFileString;
+ bool mFirst;
+};
namespace KCal {
class CalendarLocal;
}
using namespace KCal;
@@ -118,24 +146,24 @@ class MainWindow : public QMainWindow
void enableIncidenceActions( bool );
private slots:
QSocket* piSocket;
QString piFileString;
QTime piTime;
- void deleteCommandSocket();
+ void deleteCommandSocket(bool);
void deleteCommandSocketFinish();
void fillSyncMenu();
void sendFile(QSocket* s);
void getFile(QSocket* socket);
void readFileFromSocket();
void readBackFileFromSocket();
void endConnect();
private:
- QTimer* mTimerCommandSocket;
+ //QTimer* mTimerCommandSocket;
QString mPassWordPiSync;
- QSocket* mCommandSocket;
+ KCommandSocket* mCommandSocket;
QSocket* mCommandSocketFinish;
KServerSocket * mServerSocket;
bool mClosed;
void saveOnClose();
int mCurrentSyncProfile;
void enableQuick();