00001 #include "krfbconnection.h"
00002 #include "krfbcanvas.h"
00003 #include "krfbbuffer.h"
00004
00005
00006 #include <opie2/odebug.h>
00007 #include <qpe/qpeapplication.h>
00008 using namespace Opie::Core;
00009
00010
00011 #include <qclipboard.h>
00012
00013 KRFBCanvas::KRFBCanvas( QWidget *parent, const char *name )
00014 : QScrollView( parent, name )
00015 {
00016 connection_ = new KRFBConnection();
00017 connect( connection_, SIGNAL( loggedIn() ),
00018 this, SLOT( loggedIn() ) );
00019
00020 loggedIn_ = false;
00021
00022
00023
00024 viewport()->setFocusPolicy( QWidget::StrongFocus );
00025 viewport()->setFocus();
00026
00027 nextRightClick=0;
00028 nextDoubleClick=0;
00029 }
00030
00031 KRFBCanvas::~KRFBCanvas()
00032 {
00033 }
00034
00035
00036 void KRFBCanvas::openConnection(KRFBServer server)
00037 {
00038
00039
00040 QCString host = server.hostname.latin1();
00041 password=server.password;
00042 connection_->connectTo( server);
00043 }
00044
00045
00046 void KRFBCanvas::openURL( const QUrl &url )
00047 {
00048 if ( loggedIn_ ) {
00049 owarn << "openURL invoked when logged in\n" << oendl;
00050 return;
00051 }
00052
00053 QCString host = url.host().latin1();
00054 int display = url.port();
00055 Q_UNUSED( host )
00056 Q_UNUSED( display )
00057
00058
00059 }
00060
00061 void KRFBCanvas::closeConnection()
00062 {
00063 loggedIn_ = false;
00064 connection_->disconnect();
00065
00066 viewport()->setMouseTracking( false );
00067 viewport()->setBackgroundMode( PaletteDark );
00068 setBackgroundMode( PaletteDark );
00069 update();
00070 }
00071
00072
00073 void KRFBCanvas::bell()
00074 {
00075 if ( connection_->options()->deIconify ) {
00076 topLevelWidget()->raise();
00077 topLevelWidget()->show();
00078 }
00079 }
00080
00081 void KRFBCanvas::loggedIn()
00082 {
00083 owarn << "Ok, we're logged in" << oendl;
00084
00085
00086
00087
00088 loggedIn_ = true;
00089 viewport()->setMouseTracking( true );
00090 viewport()->setBackgroundMode( NoBackground );
00091 setBackgroundMode( NoBackground );
00092
00093
00094 connect( connection_->buffer(), SIGNAL( sizeChanged(int,int) ),
00095 this, SLOT( resizeContents(int,int) ) );
00096 connect( connection_->buffer(), SIGNAL( updated(int,int,int,int) ),
00097 this, SLOT( viewportUpdate(int,int,int,int) ) );
00098 connect( connection_->buffer(), SIGNAL( bell() ),
00099 this, SLOT( bell() ) );
00100 connect( qApp->clipboard(), SIGNAL( dataChanged() ),
00101 this, SLOT( clipboardChanged() ) );
00102 }
00103
00104 void KRFBCanvas::viewportPaintEvent( QPaintEvent *e )
00105 {
00106 QRect r = e->rect();
00107
00108 if ( loggedIn_ ) {
00109 QPixmap p;
00110
00111 bitBlt( viewport(), r.x(), r.y(),
00112 connection_->buffer()->pixmap(),
00113 r.x() + contentsX(), r.y() + contentsY(),
00114 r.width(), r.height() );
00115 }
00116 else {
00117 QScrollView::viewportPaintEvent( e );
00118 }
00119 }
00120
00121 void KRFBCanvas::viewportUpdate( int x, int y, int w, int h )
00122 {
00123 updateContents( x, y, w, h );
00124 }
00125
00126 void KRFBCanvas::contentsMousePressEvent( QMouseEvent *e )
00127 {
00128
00129 if (nextDoubleClick) {
00130 connection_->buffer()->mouseEvent( &QMouseEvent(QEvent::MouseButtonPress, e->pos(),LeftButton,LeftButton));
00131 connection_->buffer()->mouseEvent( &QMouseEvent(QEvent::MouseButtonRelease, e->pos(),LeftButton,0));
00132 connection_->buffer()->mouseEvent( &QMouseEvent(QEvent::MouseButtonRelease, e->pos(),LeftButton,0));
00133 connection_->buffer()->mouseEvent( &QMouseEvent(QEvent::MouseButtonPress, e->pos(),NoButton,NoButton));
00134 connection_->buffer()->mouseEvent( &QMouseEvent(QEvent::MouseButtonRelease, e->pos(),NoButton,0));
00135 } if (nextRightClick) {
00136 connection_->buffer()->mouseEvent( &QMouseEvent(QEvent::MouseButtonPress, e->pos(),RightButton,RightButton));
00137 connection_->buffer()->mouseEvent( &QMouseEvent(QEvent::MouseButtonRelease, e->pos(),RightButton,0));
00138 connection_->buffer()->mouseEvent( &QMouseEvent(QEvent::MouseButtonPress, e->pos(),NoButton,NoButton));
00139 connection_->buffer()->mouseEvent( &QMouseEvent(QEvent::MouseButtonRelease, e->pos(),NoButton,0));
00140 } else if ( loggedIn_ )
00141 connection_->buffer()->mouseEvent( e );
00142
00143 }
00144
00145 void KRFBCanvas::contentsMouseReleaseEvent( QMouseEvent *e )
00146 {
00147 if ( loggedIn_ && !nextRightClick && !nextDoubleClick) {
00148 connection_->buffer()->mouseEvent( e );
00149 }
00150
00151 nextRightClick=0;
00152 nextDoubleClick=0;
00153 }
00154
00155 void KRFBCanvas::contentsMouseMoveEvent( QMouseEvent *e )
00156 {
00157 if ( loggedIn_ )
00158 connection_->buffer()->mouseEvent( e );
00159 }
00160
00161 void KRFBCanvas::keyPressEvent( QKeyEvent *e )
00162 {
00163 if ( loggedIn_ )
00164 connection_->buffer()->keyPressEvent( e );
00165 }
00166
00167 void KRFBCanvas::keyReleaseEvent( QKeyEvent *e )
00168 {
00169 if ( loggedIn_ )
00170 connection_->buffer()->keyReleaseEvent( e );
00171 }
00172
00173 void KRFBCanvas::refresh()
00174 {
00175 if ( loggedIn_ )
00176 connection_->refresh();
00177 }
00178
00179 void KRFBCanvas::clipboardChanged()
00180 {
00181 if ( loggedIn_ ) {
00182 connection_->sendCutText( qApp->clipboard()->text() );
00183 }
00184 }
00185 void KRFBCanvas::sendCtlAltDel( void)
00186 {
00187
00188 if ( loggedIn_ ) {
00189 connection_->buffer()->keyPressEvent( &QKeyEvent(QEvent::KeyPress,Qt::Key_Control, 0,0));
00190 connection_->buffer()->keyPressEvent( &QKeyEvent(QEvent::KeyPress,Qt::Key_Alt, 0,0));
00191 connection_->buffer()->keyPressEvent( &QKeyEvent(QEvent::KeyPress,Qt::Key_Delete, 0,0));
00192 connection_->buffer()->keyPressEvent( &QKeyEvent(QEvent::KeyRelease,Qt::Key_Control, 0,0));
00193 connection_->buffer()->keyPressEvent( &QKeyEvent(QEvent::KeyRelease,Qt::Key_Alt, 0,0));
00194 connection_->buffer()->keyPressEvent( &QKeyEvent(QEvent::KeyRelease,Qt::Key_Delete, 0,0));
00195 }
00196 }
00197
00198 void KRFBCanvas::markDoubleClick( void)
00199 {
00200 nextRightClick=1;
00201 }
00202
00203 void KRFBCanvas::markRightClick( void)
00204 {
00205 nextRightClick=1;
00206 }