summaryrefslogtreecommitdiffabout
authorzautrix <zautrix>2005-02-22 03:43:50 (UTC)
committer zautrix <zautrix>2005-02-22 03:43:50 (UTC)
commit26f4ba7e3cc59ff5c5b9b8705179626e2752451b (patch) (side-by-side diff)
tree2fd2b8ef6c9b80b4408fd885577d0dbc764dc35f
parent2097bbebc5e90e6469c24023e7796ada1762e9ed (diff)
downloadkdepimpi-26f4ba7e3cc59ff5c5b9b8705179626e2752451b.zip
kdepimpi-26f4ba7e3cc59ff5c5b9b8705179626e2752451b.tar.gz
kdepimpi-26f4ba7e3cc59ff5c5b9b8705179626e2752451b.tar.bz2
pi-sync fixes
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--libkdepim/ksyncmanager.cpp18
1 files changed, 15 insertions, 3 deletions
diff --git a/libkdepim/ksyncmanager.cpp b/libkdepim/ksyncmanager.cpp
index 02e5587..08a263c 100644
--- a/libkdepim/ksyncmanager.cpp
+++ b/libkdepim/ksyncmanager.cpp
@@ -1031,85 +1031,93 @@ QString KSyncManager::syncFileName()
case (KOPI):
fn = "tempsynccal.ics";
break;
case (PWMPI):
fn = "tempsyncpw.pwm";
break;
default:
break;
}
#ifdef _WIN32_
return locateLocal( "tmp", fn );
#else
return (QString( "/tmp/" )+ fn );
#endif
}
void KSyncManager::syncPi()
{
mIsKapiFile = true;
mPisyncFinished = false;
qApp->processEvents();
if ( mAskForPreferences )
if ( !edit_pisync_options()) {
mParent->topLevelWidget()->setCaption( i18n("Syncing aborted. Nothing synced.") );
+ mPisyncFinished = true;
return;
}
bool ok;
Q_UINT16 port = mActiveSyncPort.toUInt(&ok);
if ( ! ok ) {
mParent->topLevelWidget()->setCaption( i18n("Sorry, no valid port.Syncing cancelled.") );
+ mPisyncFinished = true;
return;
}
KCommandSocket* commandSocket = new KCommandSocket( mPassWordPiSync, port, mActiveSyncIP, this, mParent->topLevelWidget() );
connect( commandSocket, SIGNAL(commandFinished( KCommandSocket*, int )), this, SLOT(deleteCommandSocket(KCommandSocket*, int)) );
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, mParent->topLevelWidget());
connect( commandSocket, SIGNAL(commandFinished( KCommandSocket*, int)), this, SLOT(deleteCommandSocket(KCommandSocket*, int )) );
commandSocket->sendStop();
}
mPisyncFinished = true;
return;
} else if ( state == KCommandSocket::errorW ) {
mParent->topLevelWidget()->setCaption( i18n("ERROR:Writing back file failed.") );
mPisyncFinished = true;
} else if ( state == KCommandSocket::successR ) {
QTimer::singleShot( 1, this , SLOT ( readFileFromSocket()));
} else if ( state == KCommandSocket::successW ) {
mParent->topLevelWidget()->setCaption( i18n("Pi-Sync successful!") );
mPisyncFinished = true;
+ } else if ( state == KCommandSocket::quiet ){
+ qDebug("KSS: quiet ");
+ mPisyncFinished = true;
+ } else {
+ qDebug("KSS: Error: unknown state: %d ", state);
+ mPisyncFinished = true;
}
delete s;
}
void KSyncManager::readFileFromSocket()
{
QString fileName = syncFileName();
bool syncOK = true;
mParent->topLevelWidget()->setCaption( i18n("Remote file saved to temp file.") );
if ( ! syncWithFile( fileName , true ) ) {
mParent->topLevelWidget()->setCaption( i18n("Syncing failed.") );
syncOK = false;
}
KCommandSocket* commandSocket = new KCommandSocket( mPassWordPiSync, mActiveSyncPort.toUInt(), mActiveSyncIP, this, mParent->topLevelWidget() );
connect( commandSocket, SIGNAL(commandFinished( KCommandSocket*, int)), this, SLOT(deleteCommandSocket(KCommandSocket*, int )) );
if ( mWriteBackFile && syncOK )
commandSocket->writeFile( fileName );
else {
commandSocket->sendStop();
if ( syncOK )
mParent->topLevelWidget()->setCaption( i18n("Pi-Sync succesful!") );
mPisyncFinished = true;
}
@@ -1250,50 +1258,51 @@ void KServerSocket::send_file()
mSyncActionDialog->setFixedSize( 230, 120);
mSyncActionDialog->show();
mSyncActionDialog->raise();
emit request_file();
qApp->processEvents();
QString fileName = mFileName;
QFile file( fileName );
if (!file.open( IO_ReadOnly ) ) {
delete mSyncActionDialog;
mSyncActionDialog = 0;
qDebug("KSS::error open sync file: %s ", fileName.latin1());
mSocket->close();
if ( mSocket->state() == QSocket::Idle )
QTimer::singleShot( 10, this , SLOT ( discardClient()));
return ;
}
mSyncActionDialog->setCaption( i18n("Sending file...") );
QTextStream ts( &file );
ts.setEncoding( QTextStream::Latin1 );
QTextStream os( mSocket );
os.setEncoding( QTextStream::Latin1 );
while ( ! ts.atEnd() ) {
- os << ts.readLine() << "\r\n\r\n";
+ os << ts.readLine() << "\r\n";
}
+ os << "\r\n";
//os << ts.read();
file.close();
mSyncActionDialog->setCaption( i18n("Waiting for synced file...") );
mSocket->close();
if ( mSocket->state() == QSocket::Idle )
QTimer::singleShot( 10, this , SLOT ( discardClient()));
}
void KServerSocket::get_file()
{
mSyncActionDialog->setCaption( i18n("Receiving synced file...") );
piTime.start();
piFileString = "";
QTimer::singleShot( 1, this , SLOT (readBackFileFromSocket( ) ));
}
void KServerSocket::readBackFileFromSocket()
{
//qDebug("readBackFileFromSocket() %d ", piTime.elapsed ());
while ( mSocket->canReadLine () ) {
piTime.restart();
QString line = mSocket->readLine ();
piFileString += line;
@@ -1353,81 +1362,84 @@ 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...") );
+ mTimerSocket->start( 20000 );
mSocket->connectToHost( mHost, mPort );
qDebug("KSS: Waiting for connection");
- mTimerSocket->start( 20000 );
}
void KCommandSocket::writeFile( QString fileName )
{
if ( !mSocket ) {
mSocket = new QSocket( this );
connect( mSocket, SIGNAL(delayedCloseFinished ()), this, SLOT(deleteSocket()) );
connect( mSocket, SIGNAL(connected ()), this, SLOT(writeFileToSocket()) );
}
mFileName = fileName ;
+ mTimerSocket->start( 20000 );
mSocket->connectToHost( mHost, mPort );
}
void KCommandSocket::writeFileToSocket()
{
+ mTimerSocket->stop();
QFile file2( mFileName );
if (!file2.open( IO_ReadOnly ) ) {
mRetVal= errorW;
mSocket->close();
if ( mSocket->state() == QSocket::Idle )
QTimer::singleShot( 10, this , SLOT ( deleteSocket()));
return ;
}
QTextStream ts2( &file2 );
ts2.setEncoding( QTextStream::Latin1 );
QTextStream os2( mSocket );
os2.setEncoding( QTextStream::Latin1 );
os2 << "PUT " << mPassWord << "\r\n\r\n";;
while ( ! ts2.atEnd() ) {
- os2 << ts2.readLine() << "\r\n\r\n";
+ os2 << ts2.readLine() << "\r\n";
}
+ os2 << "\r\n";
mRetVal= successW;
file2.close();
mSocket->close();
if ( mSocket->state() == QSocket::Idle )
QTimer::singleShot( 10, this , SLOT ( deleteSocket()));
}
void KCommandSocket::sendStop()
{
if ( !mSocket ) {
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\r\n";
mSocket->close();
if ( mSocket->state() == QSocket::Idle )
QTimer::singleShot( 10, this , SLOT ( deleteSocket()));
}
void KCommandSocket::startReadFileFromSocket()
{
if ( ! mFirst )