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.cpp97
1 files changed, 50 insertions, 47 deletions
diff --git a/libkdepim/ksyncmanager.cpp b/libkdepim/ksyncmanager.cpp
index 5708dfc..c844627 100644
--- a/libkdepim/ksyncmanager.cpp
+++ b/libkdepim/ksyncmanager.cpp
@@ -14,103 +14,106 @@
You should have received a copy of the GNU Library General Public License
along with this library; see the file COPYING.LIB. If not, write to
the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
Boston, MA 02111-1307, USA.
*/
// $Id$
#include "ksyncmanager.h"
#include <stdlib.h>
#ifndef _WIN32_
#include <unistd.h>
#endif
#include "ksyncprofile.h"
#include "ksyncprefsdialog.h"
#include "kpimprefs.h"
#include <kmessagebox.h>
#include <qdir.h>
-#include <qprogressbar.h>
-#include <qpopupmenu.h>
+#include <q3progressbar.h>
+#include <q3popupmenu.h>
#include <qpushbutton.h>
#include <qradiobutton.h>
-#include <qbuttongroup.h>
+#include <q3buttongroup.h>
#include <qtimer.h>
#include <qmessagebox.h>
#include <qapplication.h>
#include <qlineedit.h>
#include <qdialog.h>
#include <qlayout.h>
#include <qtextcodec.h>
#include <qlabel.h>
#include <qcheckbox.h>
#include <qapplication.h>
+#include <QDesktopWidget>
+//Added by qt3to4:
+#include <Q3VBoxLayout>
#include <klocale.h>
#include <kglobal.h>
#include <kconfig.h>
#include <kfiledialog.h>
QDateTime KSyncManager::mRequestedSyncEvent;
-KSyncManager::KSyncManager(QWidget* parent, KSyncInterface* implementation, TargetApp ta, KPimPrefs* prefs, QPopupMenu* syncmenu)
+KSyncManager::KSyncManager(QWidget* parent, KSyncInterface* implementation, TargetApp ta, KPimPrefs* prefs, Q3PopupMenu* syncmenu)
: QObject(), mPrefs(prefs ), mParent(parent),mImplementation(implementation), mTargetApp(ta), mSyncMenu(syncmenu)
{
mServerSocket = 0;
- bar = new QProgressBar ( 1, 0 );
+ bar = new Q3ProgressBar ( 1, 0 );
bar->setCaption ("");
mWriteBackInPast = 2;
}
KSyncManager::~KSyncManager()
{
delete bar;
}
void KSyncManager::setDefaultFileName( QString s)
{
mDefFileName = s ;
if ( mPrefs->mPassiveSyncAutoStart )
enableQuick( false );
}
void KSyncManager::fillSyncMenu()
{
if ( mSyncMenu->count() )
mSyncMenu->clear();
mSyncMenu->insertItem( i18n("Configure..."), 0 );
mSyncMenu->insertSeparator();
- QPopupMenu *clearMenu = new QPopupMenu ( mSyncMenu );
+ Q3PopupMenu *clearMenu = new Q3PopupMenu ( mSyncMenu );
mSyncMenu->insertItem( i18n("Remove sync info"),clearMenu, 5000 );
clearMenu->insertItem( i18n("For all profiles"), 1 );
clearMenu->insertSeparator();
connect ( clearMenu, SIGNAL( activated ( int ) ), this, SLOT (slotClearMenu( int ) ) );
mSyncMenu->insertSeparator();
if ( mServerSocket == 0 ) {
mSyncMenu->insertItem( i18n("Enable Pi-Sync"), 2 );
} else {
mSyncMenu->insertItem( i18n("Disable Pi-Sync"), 3 );
}
mSyncMenu->insertSeparator();
mSyncMenu->insertItem( i18n("Multiple sync"), 1 );
mSyncMenu->insertSeparator();
KConfig config ( locateLocal( "config","ksyncprofilesrc" ) );
config.setGroup("General");
QStringList prof = config.readListEntry("SyncProfileNames");
mLocalMachineName = config.readEntry("LocalMachineName","undefined");
if ( prof.count() < 2 ) {
prof.clear();
QString externalName;
#ifdef DESKTOP_VERSION
#ifdef _WIN32_
externalName = "OutLook";
#else
@@ -334,49 +337,49 @@ void KSyncManager::slotSyncMenu( int action )
mActiveSyncPort = temp->getRemotePortPWM();
mActiveSyncIP = temp->getRemoteIPPWM();
}
syncPi();
while ( !mPisyncFinished ) {
//qDebug("waiting ");
qApp->processEvents();
}
} else
syncRemote( temp );
}
}
delete temp;
setBlockSave(false);
}
void KSyncManager::enableQuick( bool ask )
{
bool autoStart;
bool changed = false;
if ( ask ) {
QDialog dia ( 0, "input-dialog", true );
QLineEdit lab ( &dia );
- QVBoxLayout lay( &dia );
+ Q3VBoxLayout lay( &dia );
lab.setText( mPrefs->mPassiveSyncPort );
lay.setMargin(7);
lay.setSpacing(7);
int po = 9197+mTargetApp;
QLabel label ( i18n("Port number (Default: %1)\nValid range from 1 to 65535").arg(po), &dia );
lay.addWidget( &label);
lay.addWidget( &lab);
QLineEdit lepw ( &dia );
lepw.setText( mPrefs->mPassiveSyncPw );
QLabel label2 ( i18n("Password to enable\naccess from remote:"), &dia );
lay.addWidget( &label2);
lay.addWidget( &lepw);
QCheckBox autostart(i18n("Automatically start\nat application startup"), &dia );
lay.addWidget( &autostart);
autostart.setChecked( mPrefs->mPassiveSyncAutoStart );
#ifdef DESKTOP_VERSION
#ifdef _WIN32_
QCheckBox syncdesktop( i18n("Automatically sync with Outlook\nwhen receiving sync request"),&dia );
syncdesktop.hide();// not implemented!
#else
QCheckBox syncdesktop( i18n("Automatically sync with KDE-Desktop\nwhen receiving sync request"),&dia );
#endif
lay.addWidget( &syncdesktop);
@@ -783,84 +786,84 @@ void KSyncManager::syncRemote( KSyncProfile* prof, bool ask)
if ( mWriteBackFile ) {
int fi;
if ( (fi = postCommand.find("$PWD$")) > 0 ) {
QString pwd = getPassword();
postCommand = postCommand.left( fi )+ pwd + postCommand.mid( fi+5 );
}
mParent->topLevelWidget()->setCaption ( i18n( "Writing back file ..." ) );
result = system ( postCommand );
qDebug("KSM::Sync:Writing back file result: %d ", result);
if ( result != 0 ) {
mParent->topLevelWidget()->setCaption ( i18n( "Writing back file result: " )+QString::number( result ) );
return;
} else {
mParent->topLevelWidget()->setCaption ( i18n( "Syncronization sucessfully completed" ) );
}
}
}
return;
}
bool KSyncManager::edit_pisync_options()
{
QDialog dia( mParent, "dia", true );
dia.setCaption( i18n("Pi-Sync options for device: " ) +mCurrentSyncDevice );
- QVBoxLayout lay ( &dia );
+ Q3VBoxLayout lay ( &dia );
lay.setSpacing( 5 );
lay.setMargin( 3 );
QLabel lab1 ( i18n("Password for remote access:"), &dia);
lay.addWidget( &lab1 );
QLineEdit le1 (&dia );
lay.addWidget( &le1 );
QLabel lab2 ( i18n("Remote IP address:"), &dia);
lay.addWidget( &lab2 );
QLineEdit le2 (&dia );
lay.addWidget( &le2 );
QLabel lab3 ( i18n("Remote port number:\n(May be: 1 - 65535)"), &dia);
lay.addWidget( &lab3 );
QLineEdit le3 (&dia );
lay.addWidget( &le3 );
QPushButton pb ( "OK", &dia);
lay.addWidget( &pb );
connect(&pb, SIGNAL( clicked() ), &dia, SLOT ( accept() ) );
le1.setText( mPassWordPiSync );
le2.setText( mActiveSyncIP );
le3.setText( mActiveSyncPort );
if ( dia.exec() ) {
mPassWordPiSync = le1.text();
mActiveSyncPort = le3.text();
mActiveSyncIP = le2.text();
return true;
}
return false;
}
bool KSyncManager::edit_sync_options()
{
QDialog dia( mParent, "dia", true );
dia.setCaption( i18n("Device: " ) +mCurrentSyncDevice );
- QButtonGroup gr ( 1, Qt::Horizontal, i18n("Sync preferences"), &dia);
- QVBoxLayout lay ( &dia );
+ Q3ButtonGroup gr ( 1, Qt::Horizontal, i18n("Sync preferences"), &dia);
+ Q3VBoxLayout lay ( &dia );
lay.setSpacing( 2 );
lay.setMargin( 3 );
lay.addWidget(&gr);
QRadioButton loc ( i18n("Take local entry on conflict"), &gr );
QRadioButton rem ( i18n("Take remote entry on conflict"), &gr );
QRadioButton newest( i18n("Take newest entry on conflict"), &gr );
QRadioButton ask( i18n("Ask for every entry on conflict"), &gr );
QRadioButton f_loc( i18n("Force: Take local entry always"), &gr );
QRadioButton f_rem( i18n("Force: Take remote entry always"), &gr );
//QRadioButton both( i18n("Take both on conflict"), &gr );
QPushButton pb ( "OK", &dia);
lay.addWidget( &pb );
connect(&pb, SIGNAL( clicked() ), &dia, SLOT ( accept() ) );
switch ( mSyncAlgoPrefs ) {
case 0:
loc.setChecked( true);
break;
case 1:
rem.setChecked( true );
break;
case 2:
newest.setChecked( true);
break;
case 3:
@@ -870,49 +873,49 @@ bool KSyncManager::edit_sync_options()
f_loc.setChecked( true);
break;
case 5:
f_rem.setChecked( true);
break;
case 6:
// both.setChecked( true);
break;
default:
break;
}
if ( dia.exec() ) {
mSyncAlgoPrefs = rem.isChecked()*1+newest.isChecked()*2+ ask.isChecked()*3+ f_loc.isChecked()*4+ f_rem.isChecked()*5;//+ both.isChecked()*6 ;
return true;
}
return false;
}
QString KSyncManager::getPassword( )
{
QString retfile = "";
QDialog dia ( mParent, "input-dialog", true );
QLineEdit lab ( &dia );
lab.setEchoMode( QLineEdit::Password );
- QVBoxLayout lay( &dia );
+ Q3VBoxLayout lay( &dia );
lay.setMargin(7);
lay.setSpacing(7);
lay.addWidget( &lab);
dia.setFixedSize( 230,50 );
dia.setCaption( i18n("Enter password") );
QPushButton pb ( "OK", &dia);
lay.addWidget( &pb );
connect(&pb, SIGNAL( clicked() ), &dia, SLOT ( accept() ) );
dia.show();
int res = dia.exec();
if ( res )
retfile = lab.text();
dia.hide();
qApp->processEvents();
return retfile;
}
void KSyncManager::confSync()
{
static KSyncPrefsDialog* sp = 0;
if ( ! sp ) {
sp = new KSyncPrefsDialog( mParent, "syncprefs", true );
@@ -1313,87 +1316,87 @@ void KSyncManager::deleteCommandSocket(KCommandSocket*s, int state)
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( mCurrentResourceRemote,mPassWordPiSync, mActiveSyncPort.toUInt(), mActiveSyncIP, this, mParent->topLevelWidget() );
connect( commandSocket, SIGNAL(commandFinished( KCommandSocket*, int)), this, SLOT(deleteCommandSocket(KCommandSocket*, int )) );
if ( mWriteBackFile && syncOK ) {
mParent->topLevelWidget()->setCaption( i18n("Sending back file ...") );
commandSocket->writeFile( fileName );
}
else {
commandSocket->sendStop();
if ( syncOK )
mParent->topLevelWidget()->setCaption( i18n("Pi-Sync succesful!") );
mPisyncFinished = true;
}
}
-KServerSocket:: KServerSocket ( QString pw, Q_UINT16 port, int backlog, QObject * parent, const char * name ) : QServerSocket( port, backlog, parent, name )
+KServerSocket:: KServerSocket ( QString pw, Q_UINT16 port, int backlog, QObject * parent, const char * name ) : Q3ServerSocket( port, backlog, parent, name )
{
mPendingConnect = 0;
mPassWord = pw;
mSocket = 0;
mSyncActionDialog = 0;
blockRC = false;
mErrorMessage = 0;
}
void KServerSocket::waitForSocketFinish()
{
if ( mSocket ) {
//qDebug("KSS:: waiting for finish operation");
QTimer::singleShot( 250, this , SLOT ( waitForSocketFinish()));
return;
}
- mSocket = new QSocket( this );
+ mSocket = new Q3Socket( this );
connect( mSocket , SIGNAL(readyRead()), this, SLOT(readClient()) );
connect( mSocket , SIGNAL(delayedCloseFinished()), this, SLOT(discardClient()) );
mSocket->setSocket( mPendingConnect );
mPendingConnect = 0;
}
void KServerSocket::newConnection ( int socket )
{
// qDebug("KServerSocket:New connection %d ", socket);
if ( mPendingConnect ) {
qDebug("KSS::Error : new Connection");
return;
}
if ( mSocket ) {
mPendingConnect = socket;
QTimer::singleShot( 250, this , SLOT ( waitForSocketFinish()));
return;
qDebug("KSS::newConnection Socket deleted! ");
delete mSocket;
mSocket = 0;
}
mPendingConnect = 0;
- mSocket = new QSocket( this );
+ mSocket = new Q3Socket( this );
connect( mSocket , SIGNAL(readyRead()), this, SLOT(readClient()) );
connect( mSocket , SIGNAL(delayedCloseFinished()), this, SLOT(discardClient()) );
mSocket->setSocket( socket );
}
void KServerSocket::discardClient()
{
QTimer::singleShot( 10, this , SLOT ( deleteSocket()));
}
void KServerSocket::deleteSocket()
{
//qDebug("KSS::deleteSocket");
if ( mSocket ) {
delete mSocket;
mSocket = 0;
}
if ( mErrorMessage )
QTimer::singleShot( 10, this , SLOT ( displayErrorMessage()));
}
void KServerSocket::readClient()
{
if ( blockRC )
return;
if ( mSocket == 0 ) {
@@ -1441,71 +1444,71 @@ void KServerSocket::readClient()
mErrorMessage = 2;
error_connect("ERROR_PW\r\n\r\n");
end_connect();
}
}
if ( tokens[0] == "STOP" ) {
//emit endConnect();
end_connect();
}
}
}
void KServerSocket::displayErrorMessage()
{
if ( mErrorMessage == 1 ) {
KMessageBox::error( 0, i18n("Got send file request\nwith invalid password"), i18n("Pi-Sync Error"));
mErrorMessage = 0;
}
else if ( mErrorMessage == 2 ) {
KMessageBox::error( 0, i18n("Got receive file request\nwith invalid password"), i18n("Pi-Sync Error"));
mErrorMessage = 0;
}
}
void KServerSocket::error_connect( QString errmess )
{
- QTextStream os( mSocket );
- os.setEncoding( QTextStream::Latin1 );
+ Q3TextStream os( mSocket );
+ os.setEncoding( Q3TextStream::Latin1 );
os << errmess ;
mSocket->close();
- if ( mSocket->state() == QSocket::Idle ) {
+ if ( mSocket->state() == Q3Socket::Idle ) {
QTimer::singleShot( 0, this , SLOT ( discardClient()));
}
}
void KServerSocket::end_connect()
{
delete mSyncActionDialog;
mSyncActionDialog = 0;
}
void KServerSocket::send_file()
{
//qDebug("MainWindow::sendFile(QSocket* s) ");
if ( mSyncActionDialog )
delete mSyncActionDialog;
mSyncActionDialog = new QDialog ( 0, "input-dialog", true );
mSyncActionDialog->setCaption(i18n("Received sync request"));
QLabel* label = new QLabel( i18n("Synchronizing from remote ...\n\nDo not use this application!\n\nIf syncing fails\nyou can close this dialog."), mSyncActionDialog );
label->setAlignment ( Qt::AlignHCenter );
- QVBoxLayout* lay = new QVBoxLayout( mSyncActionDialog );
+ Q3VBoxLayout* lay = new Q3VBoxLayout( mSyncActionDialog );
lay->addWidget( label);
lay->setMargin(7);
lay->setSpacing(7);
if ( KSyncManager::mRequestedSyncEvent.isValid() ) {
int secs = QDateTime::currentDateTime().secsTo( KSyncManager::mRequestedSyncEvent );
//secs = 333;
if ( secs < 0 )
secs = secs * (-1);
if ( secs > 30 )
//if ( true )
{
QString warning = i18n("Clock skew of\nsyncing devices\nis %1 seconds!").arg( secs );
QLabel* label = new QLabel( warning, mSyncActionDialog );
label->setAlignment ( Qt::AlignHCenter );
lay->addWidget( label);
if ( secs > 180 )
{
if ( secs > 300 ) {
if ( KMessageBox::Cancel == KMessageBox::warningContinueCancel(0, i18n("The clocks of the syncing\ndevices have a difference\nof more than 5 minutes.\nPlease adjust your clocks.\nYou may get wrong syncing results!\nPlease confirm synchronization!"), i18n("High clock skew!"),i18n("Synchronize!"))) {
qDebug("KSS::Sync cancelled ,cs");
mErrorMessage = 0;
end_connect();
error_connect("ERROR_CA\r\n\r\n");
return ;
@@ -1515,276 +1518,276 @@ void KServerSocket::send_file()
f.setPointSize ( f.pointSize() *2 );
f. setBold (true );
QLabel* label = new QLabel( warning, mSyncActionDialog );
label->setFont( f );
warning = i18n("ADJUST\nYOUR\nCLOCKS!");
label->setText( warning );
label->setAlignment ( Qt::AlignHCenter );
lay->addWidget( label);
mSyncActionDialog->setFixedSize( 230, 300);
} else {
mSyncActionDialog->setFixedSize( 230, 200);
}
} else {
mSyncActionDialog->setFixedSize( 230, 120);
}
} else
mSyncActionDialog->setFixedSize( 230, 120);
mSyncActionDialog->show();
mSyncActionDialog->raise();
emit request_file(mResource);
//emit request_file();
qApp->processEvents();
QString fileName = mFileName;
QFile file( fileName );
- if (!file.open( IO_ReadOnly ) ) {
+ if (!file.open( QIODevice::ReadOnly ) ) {
mErrorMessage = 0;
end_connect();
error_connect("ERROR_FI\r\n\r\n");
return ;
}
mSyncActionDialog->setCaption( i18n("Sending file...") );
- QTextStream ts( &file );
- ts.setEncoding( QTextStream::Latin1 );
+ Q3TextStream ts( &file );
+ ts.setEncoding( Q3TextStream::Latin1 );
- QTextStream os( mSocket );
- os.setEncoding( QTextStream::Latin1 );
+ Q3TextStream os( mSocket );
+ os.setEncoding( Q3TextStream::Latin1 );
while ( ! ts.atEnd() ) {
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 )
+ if ( mSocket->state() == Q3Socket::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;
//qDebug("readline: %s ", line.latin1());
mSyncActionDialog->setCaption( i18n("Received %1 bytes").arg( piFileString.length() ) );
}
if ( piTime.elapsed () < 3000 ) {
// wait for more
//qDebug("waitformore ");
QTimer::singleShot( 100, this , SLOT (readBackFileFromSocket( ) ));
return;
}
QString fileName = mFileName;
QFile file ( fileName );
- if (!file.open( IO_WriteOnly ) ) {
+ if (!file.open( QIODevice::WriteOnly ) ) {
delete mSyncActionDialog;
mSyncActionDialog = 0;
qDebug("KSS:Error open read back file ");
piFileString = "";
emit file_received( false, mResource);
emit file_received( false);
blockRC = false;
return ;
}
// mView->setLoadedFileVersion(QDateTime::currentDateTime().addSecs( -1));
- QTextStream ts ( &file );
- ts.setEncoding( QTextStream::Latin1 );
+ Q3TextStream ts ( &file );
+ ts.setEncoding( Q3TextStream::Latin1 );
mSyncActionDialog->setCaption( i18n("Writing file to disk...") );
ts << piFileString;
mSocket->close();
- if ( mSocket->state() == QSocket::Idle )
+ if ( mSocket->state() == Q3Socket::Idle )
QTimer::singleShot( 10, this , SLOT ( discardClient()));
file.close();
piFileString = "";
emit file_received( true, mResource );
emit file_received( true);
delete mSyncActionDialog;
mSyncActionDialog = 0;
blockRC = false;
}
KCommandSocket::KCommandSocket ( QString remres, QString password, Q_UINT16 port, QString host, QObject * parent, QWidget * cap, const char * name ): QObject( parent, name )
{
mRemoteResource = remres;
if ( mRemoteResource.isEmpty() )
mRemoteResource = "ALL";
else
mRemoteResource.replace (QRegExp (" "),"_" );
mPassWord = password;
mSocket = 0;
mFirst = false;
mFirstLine = true;
mPort = port;
mHost = host;
tlw = cap;
mRetVal = quiet;
mTimerSocket = new QTimer ( this );
connect( mTimerSocket, SIGNAL ( timeout () ), this, SLOT ( updateConnectDialog() ) );
mConnectProgress.setCaption( i18n("Pi-Sync") );
connect( &mConnectProgress, SIGNAL ( cancelled () ), this, SLOT ( deleteSocket() ) );
mConnectCount = -1;
}
void KCommandSocket::sendFileRequest()
{
if ( tlw )
tlw->setCaption( i18n("Connected! Sending request for remote file ...") );
mConnectProgress.hide();
mConnectCount = 300;mConnectMax = 300;
mConnectProgress.setCaption( i18n("Pi-Sync: Connected!") );
mConnectProgress.setLabelText( i18n("Waiting for remote file...") );
mTimerSocket->start( 100, true );
- QTextStream os( mSocket );
- os.setEncoding( QTextStream::Latin1 );
+ Q3TextStream os( mSocket );
+ os.setEncoding( Q3TextStream::Latin1 );
QString curDt = " " +KGlobal::locale()->formatDateTime(QDateTime::currentDateTime().addSecs(-1),true, true,KLocale::ISODate );
os << "GET " << mPassWord << curDt << " " << mRemoteResource << "\r\n\r\n";
}
void KCommandSocket::readFile( QString fn )
{
if ( !mSocket ) {
- mSocket = new QSocket( this );
+ mSocket = new Q3Socket( this );
//qDebug("KCS: read file - new socket");
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...") );
mConnectCount = 30;mConnectMax = 30;
mTimerSocket->start( 1000, true );
mSocket->connectToHost( mHost, mPort );
//qDebug("KCS: Waiting for connection");
}
void KCommandSocket::updateConnectDialog()
{
if ( mConnectCount == mConnectMax ) {
//qDebug("MAXX %d", mConnectMax);
mConnectProgress.setTotalSteps ( 30 );
mConnectProgress.show();
mConnectProgress.setLabelText( i18n("Trying to connect to remote...") );
}
//qDebug("updateConnectDialog() %d", mConnectCount);
mConnectProgress.raise();
mConnectProgress.setProgress( (mConnectMax - mConnectCount)%30 );
--mConnectCount;
if ( mConnectCount > 0 )
mTimerSocket->start( 1000, true );
else
deleteSocket();
}
void KCommandSocket::writeFile( QString fileName )
{
if ( !mSocket ) {
- mSocket = new QSocket( this );
+ mSocket = new Q3Socket( this );
connect( mSocket, SIGNAL(delayedCloseFinished ()), this, SLOT(deleteSocket()) );
connect( mSocket, SIGNAL(connected ()), this, SLOT(writeFileToSocket()) );
}
mFileName = fileName ;
mConnectCount = 30;mConnectMax = 30;
mTimerSocket->start( 1000, true );
mSocket->connectToHost( mHost, mPort );
}
void KCommandSocket::writeFileToSocket()
{
mTimerSocket->stop();
QFile file2( mFileName );
- if (!file2.open( IO_ReadOnly ) ) {
+ if (!file2.open( QIODevice::ReadOnly ) ) {
mConnectProgress.hide();
mConnectCount = -1;
mRetVal= errorW;
mSocket->close();
- if ( mSocket->state() == QSocket::Idle )
+ if ( mSocket->state() == Q3Socket::Idle )
QTimer::singleShot( 10, this , SLOT ( deleteSocket()));
return ;
}
mConnectProgress.setTotalSteps ( file2.size() );
mConnectProgress.show();
int count = 0;
mConnectProgress.setLabelText( i18n("Sending back synced file...") );
mConnectProgress.setProgress( count );
mConnectProgress.blockSignals( true );
- QTextStream ts2( &file2 );
- ts2.setEncoding( QTextStream::Latin1 );
- QTextStream os2( mSocket );
- os2.setEncoding( QTextStream::Latin1 );
+ Q3TextStream ts2( &file2 );
+ ts2.setEncoding( Q3TextStream::Latin1 );
+ Q3TextStream os2( mSocket );
+ os2.setEncoding( Q3TextStream::Latin1 );
os2 << "PUT " << mPassWord << " " << mRemoteResource << "\r\n\r\n";;
int byteCount = 0;
int byteMax = file2.size()/53;
while ( ! ts2.atEnd() ) {
qApp->processEvents();
if ( byteCount > byteMax ) {
byteCount = 0;
mConnectProgress.setProgress( count );
}
QString temp = ts2.readLine();
count += temp.length();
byteCount += temp.length();
os2 << temp << "\r\n";
}
file2.close();
mConnectProgress.hide();
mConnectCount = -1;
os2 << "\r\n";
mRetVal= successW;
mSocket->close();
- if ( mSocket->state() == QSocket::Idle )
+ if ( mSocket->state() == Q3Socket::Idle )
QTimer::singleShot( 10, this , SLOT ( deleteSocket()));
mConnectProgress.blockSignals( false );
}
void KCommandSocket::sendStop()
{
if ( !mSocket ) {
- mSocket = new QSocket( this );
+ mSocket = new Q3Socket( this );
connect( mSocket, SIGNAL(delayedCloseFinished ()), this, SLOT(deleteSocket()) );
}
mSocket->connectToHost( mHost, mPort );
- QTextStream os2( mSocket );
- os2.setEncoding( QTextStream::Latin1 );
+ Q3TextStream os2( mSocket );
+ os2.setEncoding( Q3TextStream::Latin1 );
os2 << "STOP\r\n\r\n";
mSocket->close();
- if ( mSocket->state() == QSocket::Idle )
+ if ( mSocket->state() == Q3Socket::Idle )
QTimer::singleShot( 10, this , SLOT ( deleteSocket()));
}
void KCommandSocket::startReadFileFromSocket()
{
if ( ! mFirst )
return;
mConnectProgress.setLabelText( i18n("Receiving file from remote...") );
mFirst = false;
mFileString = "";
mTime.start();
mFirstLine = true;
QTimer::singleShot( 1, this , SLOT (readFileFromSocket( ) ));
}
void KCommandSocket::readFileFromSocket()
{
//qDebug("readBackFileFromSocket() %d ", mTime.elapsed ());
while ( mSocket->canReadLine () ) {
mTime.restart();
QString line = mSocket->readLine ();
if ( mFirstLine ) {
mFirstLine = false;
if ( line.left( 6 ) == "ERROR_" ) {
@@ -1808,67 +1811,67 @@ void KCommandSocket::readFileFromSocket()
if ( line.left( 8 ) == "ERROR_ED" ) {
mRetVal = errorED;
deleteSocket();
return ;
}
mRetVal = errorUN;
deleteSocket();
return ;
}
}
mFileString += line;
//qDebug("readline: %s ", line.latin1());
}
if ( mTime.elapsed () < 3000 ) {
// wait for more
//qDebug("waitformore ");
QTimer::singleShot( 100, this , SLOT (readFileFromSocket( ) ));
return;
}
mTimerSocket->stop();
mConnectCount = -1;
mConnectProgress.hide();
QString fileName = mFileName;
QFile file ( fileName );
- if (!file.open( IO_WriteOnly ) ) {
+ if (!file.open( QIODevice::WriteOnly ) ) {
mFileString = "";
mRetVal = errorR;
qDebug("KSS:Error open temp sync file for writing: %s",fileName.latin1() );
deleteSocket();
return ;
}
// mView->setLoadedFileVersion(QDateTime::currentDateTime().addSecs( -1));
- QTextStream ts ( &file );
- ts.setEncoding( QTextStream::Latin1 );
+ Q3TextStream ts ( &file );
+ ts.setEncoding( Q3TextStream::Latin1 );
ts << mFileString;
file.close();
mFileString = "";
mRetVal = successR;
mSocket->close();
// if state is not idle, deleteSocket(); is called via
// connect( mSocket, SIGNAL(delayedCloseFinished ()), this, SLOT(deleteSocket()) );
- if ( mSocket->state() == QSocket::Idle )
+ if ( mSocket->state() == Q3Socket::Idle )
deleteSocket();
}
void KCommandSocket::deleteSocket()
{
//qDebug("KCommandSocket::deleteSocket() ");
mConnectProgress.hide();
if ( mConnectCount >= 0 ) {
mTimerSocket->stop();
mRetVal = errorTO;
qDebug("KCS::Connection to remote host timed out");
if ( mSocket ) {
mSocket->close();
//if ( mSocket->state() == QSocket::Idle )
// deleteSocket();
delete mSocket;
mSocket = 0;
}
if ( mConnectCount == 0 )
KMessageBox::error( 0, i18n("Connection to remote\nhost timed out!\nDid you forgot to enable\nsyncing on remote host?"));
else if ( tlw )
tlw->setCaption( i18n("Connection to remote host cancelled!") );
emit commandFinished( this, mRetVal );