summaryrefslogtreecommitdiff
path: root/noncore/comm/keypebble/kvnc.cpp
Unidiff
Diffstat (limited to 'noncore/comm/keypebble/kvnc.cpp') (more/less context) (show whitespace changes)
-rw-r--r--noncore/comm/keypebble/kvnc.cpp191
1 files changed, 191 insertions, 0 deletions
diff --git a/noncore/comm/keypebble/kvnc.cpp b/noncore/comm/keypebble/kvnc.cpp
new file mode 100644
index 0000000..bb18999
--- a/dev/null
+++ b/noncore/comm/keypebble/kvnc.cpp
@@ -0,0 +1,191 @@
1#include <qiconset.h>
2#include <qdialog.h>
3#include <qpixmap.h>
4#include <qdom.h>
5#include <qaction.h>
6#include <qpe/qpemenubar.h>
7#include <qstatusbar.h>
8#include <qpopupmenu.h>
9#include <qpushbutton.h>
10#include <qpe/qpetoolbar.h>
11#include <qtimer.h>
12#include <qmessagebox.h>
13#include <qpe/qpeapplication.h>
14#include <qpe/global.h>
15#include <assert.h>
16
17#include "kvnc.h"
18#include "krfbcanvas.h"
19#include "kvncoptionsdlg.h"
20#include "krfbconnection.h"
21
22
23/* XPM */
24static char * menu_xpm[] = {
25"12 12 5 1",
26 " c None",
27 ".c #000000",
28 "+c #FFFDAD",
29 "@c #FFFF00",
30 "#c #E5E100",
31" ",
32" ",
33" ......... ",
34" .+++++++. ",
35" .+@@@@#. ",
36" .+@@@#. ",
37" .+@@#. ",
38" .+@#. ",
39" .+#. ",
40" .+. ",
41" .. ",
42" "};
43
44const int StatusTextId = 0;
45
46KVNC::KVNC( const char *name ) : QMainWindow( 0, name )
47{
48 setCaption( tr("VNC Viewer") );
49 fullscreen = false;
50
51 canvas = new KRFBCanvas( this, "canvas" );
52 setCentralWidget( canvas );
53
54 connect( canvas->connection(), SIGNAL(statusChanged(const QString &)),
55 this, SLOT(statusMessage(const QString &)) );
56 connect( canvas->connection(), SIGNAL(error(const QString &)),
57 this, SLOT(error(const QString &)) );
58 connect( canvas->connection(), SIGNAL(connected()), this, SLOT(connected()) );
59 connect( canvas->connection(), SIGNAL(loggedIn()), this, SLOT(loggedIn()) );
60 connect( canvas->connection(), SIGNAL(disconnected()), this, SLOT(disconnected()) );
61
62 setupActions();
63
64 cornerButton = new QPushButton( this );
65 cornerButton->setPixmap( QPixmap( (const char**)menu_xpm ) );
66 connect( cornerButton, SIGNAL(pressed()), this, SLOT(showMenu()) );
67 canvas->setCornerWidget( cornerButton );
68
69 QTimer::singleShot( 0, canvas, SLOT(openConnection()) );
70}
71
72KVNC::~KVNC()
73{
74
75}
76
77void KVNC::openURL( const QUrl &url )
78{
79 canvas->openURL( url );
80}
81
82void KVNC::setupActions()
83{
84 cornerMenu = new QPopupMenu( this );
85
86 fullScreenAction = new QAction( tr("Full Screen"), QString::null, 0, 0 );
87 connect( fullScreenAction, SIGNAL(activated()),
88 this, SLOT( toggleFullScreen() ) );
89 fullScreenAction->addTo( cornerMenu );
90 fullScreenAction->setEnabled( false );
91
92 optionsAction = new QAction( tr("Settings"), QString::null, 0, 0 );
93 connect( optionsAction, SIGNAL(activated()), this, SLOT( showOptions() ) );
94 optionsAction->addTo( cornerMenu );
95
96 connectAction = new QAction( tr("Connect..."), QString::null, 0, 0 );
97 connect( connectAction, SIGNAL(activated()),
98 canvas, SLOT( openConnection() ) );
99 connectAction->addTo( cornerMenu );
100
101 disconnectAction = new QAction( tr("Disconnect"), QString::null, 0, 0 );
102 connect( disconnectAction, SIGNAL(activated()),
103 this, SLOT( closeConnection() ) );
104 disconnectAction->addTo( cornerMenu );
105 disconnectAction->setEnabled( false );
106}
107
108void KVNC::toggleFullScreen()
109{
110 if ( fullscreen ) {
111 canvas->releaseKeyboard();
112 canvas->reparent( this, 0, QPoint(0,0), false );
113 canvas->setFrameStyle( QFrame::Panel | QFrame::Sunken );
114 setCentralWidget( canvas );
115 canvas->show();
116 fullScreenAction->setText( tr("Full Screen") );
117 } else {
118 canvas->setFrameStyle( QFrame::NoFrame );
119 canvas->reparent( 0,WStyle_Tool | WStyle_Customize | WStyle_StaysOnTop,
120 QPoint(0,0),false);
121 canvas->resize(qApp->desktop()->width(), qApp->desktop()->height());
122 canvas->raise();
123 canvas->setFocus();
124 canvas->grabKeyboard();
125 canvas->show();
126
127 fullScreenAction->setText( tr("Stop Full Screen") );
128 }
129
130 fullscreen = !fullscreen;
131}
132
133void KVNC::closeConnection()
134{
135 if ( fullscreen )
136 toggleFullScreen();
137 canvas->closeConnection();
138}
139
140void KVNC::showMenu()
141{
142 QPoint pt = mapToGlobal(cornerButton->pos());
143 QSize s = cornerMenu->sizeHint();
144 pt.ry() -= s.height();
145 pt.rx() -= s.width();
146 cornerMenu->popup( pt );
147}
148
149void KVNC::connected()
150{
151 static QString msg = tr( "Connected to remote host" );
152 statusMessage( msg );
153 connectAction->setEnabled( false );
154 disconnectAction->setEnabled( true );
155 fullScreenAction->setEnabled( true );
156}
157
158void KVNC::loggedIn()
159{
160 static QString msg = tr( "Logged in to remote host" );
161 statusMessage( msg );
162}
163
164void KVNC::disconnected()
165{
166 static QString msg = tr( "Connection closed" );
167 statusMessage( msg );
168 connectAction->setEnabled( true );
169 disconnectAction->setEnabled( false );
170 fullScreenAction->setEnabled( false );
171}
172
173void KVNC::statusMessage( const QString &m )
174{
175 Global::statusMessage( m );
176}
177
178void KVNC::error( const QString &msg )
179{
180 statusMessage( msg );
181 QMessageBox::warning( this, tr("VNC Viewer"), msg );
182}
183
184void KVNC::showOptions()
185{
186 KVNCOptionsDlg *wdg = new KVNCOptionsDlg( canvas->connection()->options(), this );
187 wdg->showMaximized();
188 wdg->exec();
189 delete wdg;
190}
191