summaryrefslogtreecommitdiffabout
path: root/libkdepim/ksyncmanager.cpp
Side-by-side diff
Diffstat (limited to 'libkdepim/ksyncmanager.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r--libkdepim/ksyncmanager.cpp45
1 files changed, 28 insertions, 17 deletions
diff --git a/libkdepim/ksyncmanager.cpp b/libkdepim/ksyncmanager.cpp
index df5a0d9..1f5f4c7 100644
--- a/libkdepim/ksyncmanager.cpp
+++ b/libkdepim/ksyncmanager.cpp
@@ -1049,26 +1049,25 @@ void KSyncManager::syncPi()
bool ok;
Q_UINT16 port = mActiveSyncPort.toUInt(&ok);
if ( ! ok ) {
mParent->topLevelWidget()->setCaption( i18n("Sorry, no valid port.Syncing cancelled.") );
return;
}
- KCommandSocket* commandSocket = new KCommandSocket( mPassWordPiSync, port, mActiveSyncIP, this );
+ KCommandSocket* commandSocket = new KCommandSocket( mPassWordPiSync, port, mActiveSyncIP, this, mParent->topLevelWidget() );
connect( commandSocket, SIGNAL(commandFinished( KCommandSocket*, int )), this, SLOT(deleteCommandSocket(KCommandSocket*, int)) );
- mParent->topLevelWidget()->setCaption( i18n("Sending request for remote file ...") );
commandSocket->readFile( syncFileName() );
}
void KSyncManager::deleteCommandSocket(KCommandSocket*s, int state)
{
//enum { success, errorW, errorR, quiet };
if ( state == KCommandSocket::errorR ||state == KCommandSocket::errorTO ) {
mParent->topLevelWidget()->setCaption( i18n("ERROR: Receiving remote file failed.") );
delete s;
if ( state == KCommandSocket::errorR ) {
- KCommandSocket* commandSocket = new KCommandSocket( mPassWordPiSync, mActiveSyncPort.toUInt(), mActiveSyncIP, this );
+ KCommandSocket* commandSocket = new KCommandSocket( mPassWordPiSync, mActiveSyncPort.toUInt(), mActiveSyncIP, this, mParent->topLevelWidget());
connect( commandSocket, SIGNAL(commandFinished( KCommandSocket*, int)), this, SLOT(deleteCommandSocket(KCommandSocket*, int )) );
commandSocket->sendStop();
}
mPisyncFinished = true;
return;
@@ -1093,13 +1092,13 @@ void KSyncManager::readFileFromSocket()
mParent->topLevelWidget()->setCaption( i18n("Remote file saved to temp file.") );
if ( ! syncWithFile( fileName , true ) ) {
mParent->topLevelWidget()->setCaption( i18n("Syncing failed.") );
mPisyncFinished = true;
return;
}
- KCommandSocket* commandSocket = new KCommandSocket( mPassWordPiSync, mActiveSyncPort.toUInt(), mActiveSyncIP, this );
+ KCommandSocket* commandSocket = new KCommandSocket( mPassWordPiSync, mActiveSyncPort.toUInt(), mActiveSyncIP, this, mParent->topLevelWidget() );
connect( commandSocket, SIGNAL(commandFinished( KCommandSocket*, int)), this, SLOT(deleteCommandSocket(KCommandSocket*, int )) );
if ( mWriteBackFile )
commandSocket->writeFile( fileName );
else {
commandSocket->sendStop();
mParent->topLevelWidget()->setCaption( i18n("Pi-Sync succesful!") );
@@ -1260,13 +1259,13 @@ void KServerSocket::send_file()
QTextStream ts( &file );
ts.setEncoding( QTextStream::Latin1 );
QTextStream os( mSocket );
os.setEncoding( QTextStream::Latin1 );
while ( ! ts.atEnd() ) {
- os << ts.readLine() << "\r\n";
+ os << ts.readLine() << "\r\n\r\n";
}
//os << ts.read();
file.close();
mSyncActionDialog->setCaption( i18n("Waiting for synced file...") );
mSocket->close();
if ( mSocket->state() == QSocket::Idle )
@@ -1326,40 +1325,52 @@ void KServerSocket::readBackFileFromSocket()
delete mSyncActionDialog;
mSyncActionDialog = 0;
blockRC = false;
}
-KCommandSocket::KCommandSocket ( QString password, Q_UINT16 port, QString host, QObject * parent, const char * name ): QObject( parent, name )
+KCommandSocket::KCommandSocket ( QString password, Q_UINT16 port, QString host, QObject * parent, QWidget * cap, const char * name ): QObject( parent, name )
{
mPassWord = password;
mSocket = 0;
+ mFirst = false;
mPort = port;
mHost = host;
-
+ tlw = cap;
mRetVal = quiet;
mTimerSocket = new QTimer ( this );
connect( mTimerSocket, SIGNAL ( timeout () ), this, SLOT ( deleteSocket() ) );
}
+void KCommandSocket::sendFileRequest()
+{
+ if ( tlw )
+ tlw->setCaption( i18n("Connected! Sending request for remote file ...") );
+ mTimerSocket->start( 300000 );
+ QTextStream os( mSocket );
+ os.setEncoding( QTextStream::Latin1 );
+
+ QString curDt = " " +KGlobal::locale()->formatDateTime(QDateTime::currentDateTime().addSecs(-1),true, true,KLocale::ISODate );
+ os << "GET " << mPassWord << curDt <<"\r\n\r\n";
+}
+
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()) );
+ connect( mSocket, SIGNAL(connected ()), this, SLOT(sendFileRequest() ));
}
mFileString = "";
mFileName = fn;
mFirst = true;
+ if ( tlw )
+ tlw->setCaption( i18n("Trying to connect to remote...") );
mSocket->connectToHost( mHost, mPort );
- QTextStream os( mSocket );
- os.setEncoding( QTextStream::Latin1 );
-
- QString curDt = " " +KGlobal::locale()->formatDateTime(QDateTime::currentDateTime().addSecs(-1),true, true,KLocale::ISODate );
- os << "GET " << mPassWord << curDt <<"\r\n";
- mTimerSocket->start( 300000 );
+ qDebug("KSS: Waiting for connection");
+ mTimerSocket->start( 20000 );
}
void KCommandSocket::writeFile( QString fileName )
{
if ( !mSocket ) {
mSocket = new QSocket( this );
@@ -1380,15 +1391,15 @@ void KCommandSocket::writeFileToSocket()
return ;
}
QTextStream ts2( &file2 );
ts2.setEncoding( QTextStream::Latin1 );
QTextStream os2( mSocket );
os2.setEncoding( QTextStream::Latin1 );
- os2 << "PUT " << mPassWord << "\r\n";;
+ os2 << "PUT " << mPassWord << "\r\n\r\n";;
while ( ! ts2.atEnd() ) {
- os2 << ts2.readLine() << "\r\n";
+ os2 << ts2.readLine() << "\r\n\r\n";
}
mRetVal= successW;
file2.close();
mSocket->close();
if ( mSocket->state() == QSocket::Idle )
QTimer::singleShot( 10, this , SLOT ( deleteSocket()));
@@ -1399,13 +1410,13 @@ void KCommandSocket::sendStop()
mSocket = new QSocket( this );
connect( mSocket, SIGNAL(delayedCloseFinished ()), this, SLOT(deleteSocket()) );
}
mSocket->connectToHost( mHost, mPort );
QTextStream os2( mSocket );
os2.setEncoding( QTextStream::Latin1 );
- os2 << "STOP\r\n";
+ os2 << "STOP\r\n\r\n";
mSocket->close();
if ( mSocket->state() == QSocket::Idle )
QTimer::singleShot( 10, this , SLOT ( deleteSocket()));
}
void KCommandSocket::startReadFileFromSocket()
@@ -1469,13 +1480,13 @@ void KCommandSocket::deleteSocket()
mSocket->close();
//if ( mSocket->state() == QSocket::Idle )
// deleteSocket();
delete mSocket;
mSocket = 0;
}
- KMessageBox::error( 0, i18n("Connection to remote\nhost timed out!\nDid you forgot to enable\nsyncing on remote host? "));
+ KMessageBox::error( 0, i18n("Connection to remote\nhost timed out!\nDid you forgot to enable\nsyncing on remote host?"));
emit commandFinished( this, mRetVal );
return;
}
//qDebug("KCommandSocket::deleteSocket() %d", mRetVal );
if ( mSocket)
delete mSocket;