Diffstat (limited to 'noncore/comm/keypebble/krfbconnection.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r-- | noncore/comm/keypebble/krfbconnection.cpp | 272 |
1 files changed, 132 insertions, 140 deletions
diff --git a/noncore/comm/keypebble/krfbconnection.cpp b/noncore/comm/keypebble/krfbconnection.cpp index c51f18a..389c836 100644 --- a/noncore/comm/keypebble/krfbconnection.cpp +++ b/noncore/comm/keypebble/krfbconnection.cpp @@ -7,3 +7,3 @@ #include "krfblogin.h" -#include "krfboptions.h" +#include "krfbserver.h" #include "krfbdecoder.h" @@ -12,12 +12,12 @@ KRFBConnection::KRFBConnection( QObject *parent ) - : QObject( parent, "KRFBConnection" ) + : QObject( parent, "KRFBConnection" ) { - portBase_ = 5900; - currentState_ = Disconnected; - sock = 0; - minData_ = 0; - options_ = new KRFBOptions(); - updater = 0; - decoder_ = 0; - buffer_ = 0; + portBase_ = 5900; + currentState_ = Disconnected; + sock = 0; + minData_ = 0; + options_ = new KRFBServer(); + updater = 0; + decoder_ = 0; + buffer_ = 0; } @@ -26,27 +26,26 @@ KRFBConnection::~KRFBConnection() { - if ( ( currentState_ != Disconnected ) && ( currentState_ != Disconnecting ) && sock ) { - disconnectDone(); - } - delete options_; + if ( ( currentState_ != Disconnected ) && ( currentState_ != Disconnecting ) && sock ) { + disconnectDone(); + } + delete options_; } -void KRFBConnection::connectTo( const QCString &host, int display ) +void KRFBConnection::connectTo( KRFBServer server) { - if ( currentState_ != Disconnected ); - disconnect(); + if ( currentState_ != Disconnected ) + disconnect(); + + (*options_)=server; - this->host_= host; - this->display_ = display; + sock = new QSocket( this, "rfbSocket" ); + CHECK_PTR( sock ); - sock = new QSocket( this, "rfbSocket" ); - CHECK_PTR( sock ); + // Connect to something to notice connection or error + connect( sock, SIGNAL( error( int ) ), SLOT( gotSocketError( int ) ) ); + connect( sock, SIGNAL( connected() ), SLOT( gotSocketConnection() ) ); - // Connect to something to notice connection or error - connect( sock, SIGNAL( error( int ) ), SLOT( gotSocketError( int ) ) ); - connect( sock, SIGNAL( connected() ), SLOT( gotSocketConnection() ) ); + qWarning( "Connecting..." ); - qWarning( "Connecting..." ); - - currentState_ = Connecting; - sock->connectToHost( host_, portBase_ + display_ ); + currentState_ = Connecting; + sock->connectToHost( options_->hostname.latin1(), portBase_ + options_->display ); } @@ -55,15 +54,15 @@ void KRFBConnection::disconnect() { - qWarning( "Disconnecting from server" ); + qWarning( "Disconnecting from server" ); - if ( ( currentState_ != Disconnected ) - && ( currentState_ != Disconnecting ) - && sock ) { - currentState_ = Disconnecting; + if ( ( currentState_ != Disconnected ) + && ( currentState_ != Disconnecting ) + && sock ) { + currentState_ = Disconnecting; - connect( sock, SIGNAL( delayedCloseFinished() ), SLOT( disconnectDone() ) ); - sock->close(); + connect( sock, SIGNAL( delayedCloseFinished() ), SLOT( disconnectDone() ) ); + sock->close(); - if ( sock->state() != QSocket::Closing ) - disconnectDone(); - } + if ( sock->state() != QSocket::Closing ) + disconnectDone(); + } } @@ -72,11 +71,10 @@ void KRFBConnection::disconnectDone() { - qWarning( "KRFBConnection disconnected" ); - currentState_ = Disconnected; - delete sock; - sock = 0; - minData_ = 0; - delete updater; - delete decoder_; - delete buffer_; - emit disconnected(); + currentState_ = Disconnected; + delete sock; + sock = 0; + minData_ = 0; + delete updater; + delete decoder_; + delete buffer_; + emit disconnected(); } @@ -85,11 +83,11 @@ void KRFBConnection::gotSocketConnection() { - currentState_ = LoggingIn; + currentState_ = LoggingIn; - qWarning( "Connected, logging in..." ); + qWarning( "Connected, logging in..." ); - static QString statusMsg = tr( "Connected" ); - emit statusChanged( statusMsg ); + static QString statusMsg = tr( "Connected" ); + emit statusChanged( statusMsg ); - // Do some login stuff - login = new KRFBLogin( this ); + // Do some login stuff + login = new KRFBLogin( this ); } @@ -98,24 +96,24 @@ void KRFBConnection::gotRFBConnection() { - qWarning( "Logged into server" ); + qWarning( "Logged into server" ); - currentState_ = Connected; - emit connected(); + currentState_ = Connected; + emit connected(); - // Create the decoder and start doing stuff - decoder_ = new KRFBDecoder( this ); - CHECK_PTR( decoder_ ); + // Create the decoder and start doing stuff + decoder_ = new KRFBDecoder( this ); + CHECK_PTR( decoder_ ); - buffer_ = new KRFBBuffer( decoder_, this, "RFB Buffer" ); - CHECK_PTR( buffer_ ); - decoder_->setBuffer( buffer_ ); + buffer_ = new KRFBBuffer( decoder_, this, "RFB Buffer" ); + CHECK_PTR( buffer_ ); + decoder_->setBuffer( buffer_ ); - connect( decoder_, SIGNAL( status( const QString & ) ), - this, SIGNAL( statusChanged( const QString & ) ) ); - emit loggedIn(); + connect( decoder_, SIGNAL( status( const QString & ) ), + this, SIGNAL( statusChanged( const QString & ) ) ); + emit loggedIn(); - decoder_->start(); + decoder_->start(); - updater = new QTimer; - connect( updater, SIGNAL( timeout() ), SLOT( updateTimer() ) ); - updater->start( options_->updateRate ); + updater = new QTimer; + connect( updater, SIGNAL( timeout() ), SLOT( updateTimer() ) ); + updater->start( options_->updateRate ); } @@ -124,35 +122,35 @@ void KRFBConnection::gotSocketError( int err ) { - currentState_ = Error; - - // Do some error handling stuff - qWarning( "KRFBConnection: Socket error %d", err ); - - static QString refused = tr( "Connection Refused" ); - static QString host = tr( "Host not found" ); - static QString read = tr( "Read Error: QSocket reported an error reading\n" - "data, the remote host has probably dropped the\n" - "connection." ); - static QString confused = tr( "QSocket reported an invalid error code" ); - - QString msg; - switch ( err ) { - case QSocket::ErrConnectionRefused: - msg = refused; - break; - case QSocket::ErrHostNotFound: - msg = host; - break; - case QSocket::ErrSocketRead: - msg = read; - break; - default: - msg = confused; - }; - - QObject::disconnect( sock, SIGNAL( readyRead() ), this, SLOT( gotMoreData() ) ); - delete sock; - sock = 0; - currentState_ = Disconnected; - - emit error( msg ); + currentState_ = Error; + + // Do some error handling stuff + qWarning( "KRFBConnection: Socket error %d", err ); + + static QString refused = tr( "Connection Refused" ); + static QString host = tr( "Host not found" ); + static QString read = tr( "Read Error: QSocket reported an error reading\n" + "data, the remote host has probably dropped the\n" + "connection." ); + static QString confused = tr( "QSocket reported an invalid error code" ); + + QString msg; + switch ( err ) { + case QSocket::ErrConnectionRefused: + msg = refused; + break; + case QSocket::ErrHostNotFound: + msg = host; + break; + case QSocket::ErrSocketRead: + msg = read; + break; + default: + msg = confused; + }; + + QObject::disconnect( sock, SIGNAL( readyRead() ), this, SLOT( gotMoreData() ) ); + delete sock; + sock = 0; + currentState_ = Disconnected; + + emit error( msg ); } @@ -161,9 +159,9 @@ void KRFBConnection::gotMoreData() { - assert( minData_ > 0 ); + assert( minData_ > 0 ); - if ( sock->size() >= minData_ ) { - minData_ = 0; - QObject::disconnect( sock, SIGNAL( readyRead() ), this, SLOT( gotMoreData() ) ); - emit gotEnoughData(); - } + if ( sock->size() >= minData_ ) { + minData_ = 0; + QObject::disconnect( sock, SIGNAL( readyRead() ), this, SLOT( gotMoreData() ) ); + emit gotEnoughData(); + } } @@ -172,16 +170,15 @@ void KRFBConnection::waitForData( unsigned int sz ) { - assert( minData_ == 0 ); - assert( sz > 0 ); - assert( currentState_ != Error ); - - if ( sock->size() >= sz ) { - // qWarning( "No need to wait for data" ); - emit gotEnoughData(); - } - else { - // qWarning( "Waiting for %u bytes", sz ); - - minData_ = sz; - connect( sock, SIGNAL( readyRead() ), SLOT( gotMoreData() ) ); - } + assert( minData_ == 0 ); + assert( sz > 0 ); + assert( currentState_ != Error ); + + if ( sock->size() >= sz ) { + // qWarning( "No need to wait for data" ); + emit gotEnoughData(); + } + else { + // qWarning( "Waiting for %u bytes", sz ); + minData_ = sz; + connect( sock, SIGNAL( readyRead() ), SLOT( gotMoreData() ) ); + } } @@ -190,3 +187,3 @@ int KRFBConnection::read( void *buf, int sz ) { - return sock->readBlock( (char *) buf, sz ); + return sock->readBlock( (char *) buf, sz ); } @@ -195,3 +192,3 @@ int KRFBConnection::write( void *buf, int sz ) { - return sock->writeBlock( (const char *) buf, sz ); + return sock->writeBlock( (const char *) buf, sz ); } @@ -200,3 +197,3 @@ KRFBConnection::State KRFBConnection::state() const { - return currentState_; + return currentState_; } @@ -205,3 +202,3 @@ void KRFBConnection::setPortBase( int base ) { - portBase_ = base; + portBase_ = base; } @@ -210,8 +207,3 @@ int KRFBConnection::portBase() const { - return portBase_; -} - -void KRFBConnection::setPassword( const QCString &pass ) -{ - this->pass_ = pass; + return portBase_; } @@ -220,3 +212,3 @@ void KRFBConnection::updateTimer() { - decoder_->sendUpdateRequest( true ); + decoder_->sendUpdateRequest( true ); } @@ -225,3 +217,3 @@ void KRFBConnection::refresh() { - decoder_->sendUpdateRequest( false ); + decoder_->sendUpdateRequest( false ); } @@ -230,3 +222,3 @@ void KRFBConnection::sendCutText( const QString &text ) { - decoder_->sendCutEvent( text ); + decoder_->sendCutEvent( text ); } @@ -235,8 +227,8 @@ const QUrl &KRFBConnection::url() { - url_.setProtocol( "vnc" ); - url_.setPort( display() ); - url_.setHost( host() ); - url_.setPath( "/" ); + url_.setProtocol( "vnc" ); + url_.setPort( display() ); + url_.setHost( host() ); + url_.setPath( "/" ); - return url_; + return url_; } |