summaryrefslogtreecommitdiffabout
path: root/korganizer/mainwindow.cpp
Side-by-side diff
Diffstat (limited to 'korganizer/mainwindow.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r--korganizer/mainwindow.cpp23
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()
}
// mView->setLoadedFileVersion(QDateTime::currentDateTime().addSecs( -1));
QTextStream ts ( &file );
ts.setCodec( QTextCodec::codecForName("utf8") );
mSyncActionDialog->setCaption( i18n("Writing file to disk...") );
ts << piFileString;
mSocket->close();
if ( mSocket->state() == QSocket::Idle )
QTimer::singleShot( 10, this , SLOT ( discardClient()));
file.close();
delete mSyncActionDialog;
mSyncActionDialog = 0;
piFileString = "";
emit file_received( true );
}
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 fileName )
{
- QFile file2( fileName );
- if (!file2.open( IO_ReadOnly ) ) {
- mRetVal= false;
- deleteSocket();
- return ;
-
- }
if ( !mSocket ) {
mSocket = new QSocket( this );
connect( mSocket, SIGNAL(delayedCloseFinished ()), this, SLOT(deleteSocket()) );
+ connect( mSocket, SIGNAL(connected ()), this, SLOT(writeFileToSocket()) );
}
+ mFileName = fileName ;
mSocket->connectToHost( mHost, mPort );
+}
+void KCommandSocket::writeFileToSocket()
+{
+ QFile file2( mFileName );
+ if (!file2.open( IO_ReadOnly ) ) {
+ mRetVal= false;
+ mSocket->close();
+ if ( mSocket->state() == QSocket::Idle )
+ QTimer::singleShot( 10, this , SLOT ( deleteSocket()));
+ return ;
+ }
QTextStream ts2( &file2 );
ts2.setCodec( QTextCodec::codecForName("utf8") );
QTextStream os2( mSocket );
os2.setCodec( QTextCodec::codecForName("utf8") );
os2 << "PUT " << mPassWord << "\r\n";;
while ( ! ts2.atEnd() ) {
os2 << ts2.readLine() << "\n";
}
mRetVal= true;
+ file2.close();
mSocket->close();
if ( mSocket->state() == QSocket::Idle )
QTimer::singleShot( 10, this , SLOT ( deleteSocket()));
- file2.close();
}
-
void KCommandSocket::sendStop()
{
if ( !mSocket ) {
mSocket = new QSocket( this );
connect( mSocket, SIGNAL(delayedCloseFinished ()), this, SLOT(deleteSocket()) );
}
mSocket->connectToHost( mHost, mPort );
QTextStream os2( mSocket );
os2.setCodec( QTextCodec::codecForName("utf8") );
os2 << "STOP\r\n";
mRetVal= true;
mSocket->close();
if ( mSocket->state() == QSocket::Idle )
QTimer::singleShot( 10, this , SLOT ( deleteSocket()));
}
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() );