author | kergoth <kergoth> | 2002-01-25 22:14:26 (UTC) |
---|---|---|
committer | kergoth <kergoth> | 2002-01-25 22:14:26 (UTC) |
commit | 15318cad33835e4e2dc620d033e43cd930676cdd (patch) (unidiff) | |
tree | c2fa0399a2c47fda8e2cd0092c73a809d17f68eb /noncore/comm/keypebble/krfbcanvas.cpp | |
download | opie-15318cad33835e4e2dc620d033e43cd930676cdd.zip opie-15318cad33835e4e2dc620d033e43cd930676cdd.tar.gz opie-15318cad33835e4e2dc620d033e43cd930676cdd.tar.bz2 |
Initial revision
Diffstat (limited to 'noncore/comm/keypebble/krfbcanvas.cpp') (more/less context) (show whitespace changes)
-rw-r--r-- | noncore/comm/keypebble/krfbcanvas.cpp | 169 |
1 files changed, 169 insertions, 0 deletions
diff --git a/noncore/comm/keypebble/krfbcanvas.cpp b/noncore/comm/keypebble/krfbcanvas.cpp new file mode 100644 index 0000000..f74ab7b --- a/dev/null +++ b/noncore/comm/keypebble/krfbcanvas.cpp | |||
@@ -0,0 +1,169 @@ | |||
1 | #include "kvncconnectdlg.h" | ||
2 | #include "krfbconnection.h" | ||
3 | #include "krfbcanvas.h" | ||
4 | #include "krfboptions.h" | ||
5 | #include "krfbbuffer.h" | ||
6 | |||
7 | #include <qpe/config.h> | ||
8 | |||
9 | #include <qapplication.h> | ||
10 | #include <qclipboard.h> | ||
11 | #include <qaction.h> | ||
12 | #include <qpixmap.h> | ||
13 | #include <qapplication.h> | ||
14 | #include <qmainwindow.h> | ||
15 | #include <qiconset.h> | ||
16 | |||
17 | KRFBCanvas::KRFBCanvas( QWidget *parent, const char *name ) | ||
18 | : QScrollView( parent, name ) | ||
19 | { | ||
20 | connection_ = new KRFBConnection(); | ||
21 | connect( connection_, SIGNAL( passwordRequired( KRFBConnection * ) ), | ||
22 | this, SLOT( passwordRequired( KRFBConnection * ) ) ); | ||
23 | connect( connection_, SIGNAL( loggedIn() ), | ||
24 | this, SLOT( loggedIn() ) ); | ||
25 | |||
26 | loggedIn_ = false; | ||
27 | |||
28 | viewport()->setFocusPolicy( QWidget::StrongFocus ); | ||
29 | viewport()->setFocus(); | ||
30 | } | ||
31 | |||
32 | KRFBCanvas::~KRFBCanvas() | ||
33 | { | ||
34 | } | ||
35 | |||
36 | void KRFBCanvas::openConnection() | ||
37 | { | ||
38 | KVNCConnectDlg dlg( connection_, this, "connect dialog" ); | ||
39 | if ( dlg.exec() ) { | ||
40 | QCString host = dlg.hostname().latin1(); | ||
41 | password = dlg.password(); | ||
42 | connection_->connectTo( host, dlg.display() ); | ||
43 | } | ||
44 | } | ||
45 | |||
46 | void KRFBCanvas::openURL( const QUrl &url ) | ||
47 | { | ||
48 | if ( loggedIn_ ) { | ||
49 | qWarning( "openURL invoked when logged in\n" ); | ||
50 | return; | ||
51 | } | ||
52 | |||
53 | QCString host = url.host().latin1(); | ||
54 | int display = url.port(); | ||
55 | if ( url.hasPassword() ) | ||
56 | connection_->setPassword( url.password().latin1() ); | ||
57 | |||
58 | connection_->connectTo( host, display ); | ||
59 | } | ||
60 | |||
61 | void KRFBCanvas::closeConnection() | ||
62 | { | ||
63 | loggedIn_ = false; | ||
64 | connection_->disconnect(); | ||
65 | |||
66 | viewport()->setMouseTracking( false ); | ||
67 | viewport()->setBackgroundMode( PaletteDark ); | ||
68 | setBackgroundMode( PaletteDark ); | ||
69 | update(); | ||
70 | } | ||
71 | |||
72 | void KRFBCanvas::passwordRequired( KRFBConnection *con ) | ||
73 | { | ||
74 | con->setPassword( password.latin1() ); | ||
75 | } | ||
76 | |||
77 | void KRFBCanvas::bell() | ||
78 | { | ||
79 | if ( connection_->options()->deIconify ) { | ||
80 | topLevelWidget()->raise(); | ||
81 | topLevelWidget()->show(); | ||
82 | } | ||
83 | } | ||
84 | |||
85 | void KRFBCanvas::loggedIn() | ||
86 | { | ||
87 | qWarning( "Ok, we're logged in" ); | ||
88 | |||
89 | // | ||
90 | // Get ready for action | ||
91 | // | ||
92 | loggedIn_ = true; | ||
93 | viewport()->setMouseTracking( true ); | ||
94 | viewport()->setBackgroundMode( NoBackground ); | ||
95 | setBackgroundMode( NoBackground ); | ||
96 | |||
97 | // Start using the buffer | ||
98 | connect( connection_->buffer(), SIGNAL( sizeChanged( int, int ) ), | ||
99 | this, SLOT( resizeContents(int,int) ) ); | ||
100 | connect( connection_->buffer(), SIGNAL( updated( int, int, int, int ) ), | ||
101 | this, SLOT( viewportUpdate(int,int,int,int) ) ); | ||
102 | connect( connection_->buffer(), SIGNAL( bell() ), | ||
103 | this, SLOT( bell() ) ); | ||
104 | connect( qApp->clipboard(), SIGNAL( dataChanged() ), | ||
105 | this, SLOT( clipboardChanged() ) ); | ||
106 | } | ||
107 | |||
108 | void KRFBCanvas::viewportPaintEvent( QPaintEvent *e ) | ||
109 | { | ||
110 | QRect r = e->rect(); | ||
111 | |||
112 | if ( loggedIn_ ) { | ||
113 | bitBlt( viewport(), r.x(), r.y(), | ||
114 | connection_->buffer()->pixmap(), | ||
115 | r.x() + contentsX(), r.y() + contentsY(), | ||
116 | r.width(), r.height() ); | ||
117 | } | ||
118 | else { | ||
119 | QScrollView::viewportPaintEvent( e ); | ||
120 | } | ||
121 | } | ||
122 | |||
123 | void KRFBCanvas::viewportUpdate( int x, int y, int w, int h ) | ||
124 | { | ||
125 | updateContents( x, y, w, h ); | ||
126 | } | ||
127 | |||
128 | void KRFBCanvas::contentsMousePressEvent( QMouseEvent *e ) | ||
129 | { | ||
130 | if ( loggedIn_ ) | ||
131 | connection_->buffer()->mouseEvent( e ); | ||
132 | } | ||
133 | |||
134 | void KRFBCanvas::contentsMouseReleaseEvent( QMouseEvent *e ) | ||
135 | { | ||
136 | if ( loggedIn_ ) | ||
137 | connection_->buffer()->mouseEvent( e ); | ||
138 | } | ||
139 | |||
140 | void KRFBCanvas::contentsMouseMoveEvent( QMouseEvent *e ) | ||
141 | { | ||
142 | if ( loggedIn_ ) | ||
143 | connection_->buffer()->mouseEvent( e ); | ||
144 | } | ||
145 | |||
146 | void KRFBCanvas::keyPressEvent( QKeyEvent *e ) | ||
147 | { | ||
148 | if ( loggedIn_ ) | ||
149 | connection_->buffer()->keyPressEvent( e ); | ||
150 | } | ||
151 | |||
152 | void KRFBCanvas::keyReleaseEvent( QKeyEvent *e ) | ||
153 | { | ||
154 | if ( loggedIn_ ) | ||
155 | connection_->buffer()->keyReleaseEvent( e ); | ||
156 | } | ||
157 | |||
158 | void KRFBCanvas::refresh() | ||
159 | { | ||
160 | if ( loggedIn_ ) | ||
161 | connection_->refresh(); | ||
162 | } | ||
163 | |||
164 | void KRFBCanvas::clipboardChanged() | ||
165 | { | ||
166 | if ( loggedIn_ ) { | ||
167 | connection_->sendCutText( qApp->clipboard()->text() ); | ||
168 | } | ||
169 | } | ||