Diffstat (limited to 'noncore/comm/keypebble/kvnc.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r-- | noncore/comm/keypebble/kvnc.cpp | 168 |
1 files changed, 125 insertions, 43 deletions
diff --git a/noncore/comm/keypebble/kvnc.cpp b/noncore/comm/keypebble/kvnc.cpp index 43cffc5..aa46e2f 100644 --- a/noncore/comm/keypebble/kvnc.cpp +++ b/noncore/comm/keypebble/kvnc.cpp | |||
@@ -7,20 +7,33 @@ | |||
7 | #include <qstatusbar.h> | 7 | #include <qstatusbar.h> |
8 | #include <qpopupmenu.h> | 8 | #include <qpopupmenu.h> |
9 | #include <qpushbutton.h> | 9 | #include <qpushbutton.h> |
10 | #include <qpe/qpetoolbar.h> | 10 | #include <qpe/qpetoolbar.h> |
11 | #include <qtimer.h> | 11 | #include <qtimer.h> |
12 | #include <qmessagebox.h> | 12 | #include <qmessagebox.h> |
13 | #include <qspinbox.h> | ||
14 | #include <qlistbox.h> | ||
15 | #include <qlineedit.h> | ||
13 | #include <qpe/qpeapplication.h> | 16 | #include <qpe/qpeapplication.h> |
14 | #include <qpe/global.h> | 17 | #include <qpe/global.h> |
18 | #include <qpe/qpetoolbar.h> | ||
19 | #include <qpe/resource.h> | ||
20 | |||
15 | #include <assert.h> | 21 | #include <assert.h> |
16 | 22 | ||
17 | #include "kvnc.h" | 23 | #include "kvnc.h" |
18 | #include "krfbcanvas.h" | 24 | #include "krfbcanvas.h" |
19 | #include "kvncoptionsdlg.h" | ||
20 | #include "krfbconnection.h" | 25 | #include "krfbconnection.h" |
26 | #include "kvncconndlg.h" | ||
27 | #include "krfbserver.h" | ||
28 | |||
29 | static int u_id = 1; | ||
30 | static int get_unique_id() | ||
31 | { | ||
32 | return u_id++; | ||
33 | } | ||
21 | 34 | ||
22 | 35 | ||
23 | /* XPM */ | 36 | /* XPM */ |
24 | static char * menu_xpm[] = { | 37 | static char * menu_xpm[] = { |
25 | "12 12 5 1", | 38 | "12 12 5 1", |
26 | " c None", | 39 | " c None", |
@@ -45,15 +58,25 @@ const int StatusTextId = 0; | |||
45 | 58 | ||
46 | KVNC::KVNC( const char *name ) : QMainWindow( 0, name ) | 59 | KVNC::KVNC( const char *name ) : QMainWindow( 0, name ) |
47 | { | 60 | { |
48 | setCaption( tr("VNC Viewer") ); | 61 | setCaption( tr("VNC Viewer") ); |
49 | fullscreen = false; | 62 | fullscreen = false; |
50 | 63 | ||
51 | canvas = new KRFBCanvas( this, "canvas" ); | 64 | stack = new QWidgetStack( this ); |
52 | setCentralWidget( canvas ); | 65 | setCentralWidget( stack ); |
53 | 66 | ||
67 | bookmarkSelector=new KVNCBookmarkDlg(); | ||
68 | stack->addWidget(bookmarkSelector,get_unique_id()); | ||
69 | stack->raiseWidget( bookmarkSelector ); | ||
70 | |||
71 | canvas = new KRFBCanvas( stack, "canvas" ); | ||
72 | stack->addWidget(canvas,get_unique_id()); | ||
73 | setCentralWidget( stack ); | ||
74 | |||
75 | connect( bookmarkSelector->bookmarkList, SIGNAL(doubleClicked(QListBoxItem *)), | ||
76 | this, SLOT(openConnection(QListBoxItem *)) ); | ||
54 | connect( canvas->connection(), SIGNAL(statusChanged(const QString &)), | 77 | connect( canvas->connection(), SIGNAL(statusChanged(const QString &)), |
55 | this, SLOT(statusMessage(const QString &)) ); | 78 | this, SLOT(statusMessage(const QString &)) ); |
56 | connect( canvas->connection(), SIGNAL(error(const QString &)), | 79 | connect( canvas->connection(), SIGNAL(error(const QString &)), |
57 | this, SLOT(error(const QString &)) ); | 80 | this, SLOT(error(const QString &)) ); |
58 | connect( canvas->connection(), SIGNAL(connected()), this, SLOT(connected()) ); | 81 | connect( canvas->connection(), SIGNAL(connected()), this, SLOT(connected()) ); |
59 | connect( canvas->connection(), SIGNAL(loggedIn()), this, SLOT(loggedIn()) ); | 82 | connect( canvas->connection(), SIGNAL(loggedIn()), this, SLOT(loggedIn()) ); |
@@ -63,72 +86,131 @@ KVNC::KVNC( const char *name ) : QMainWindow( 0, name ) | |||
63 | 86 | ||
64 | cornerButton = new QPushButton( this ); | 87 | cornerButton = new QPushButton( this ); |
65 | cornerButton->setPixmap( QPixmap( (const char**)menu_xpm ) ); | 88 | cornerButton->setPixmap( QPixmap( (const char**)menu_xpm ) ); |
66 | connect( cornerButton, SIGNAL(pressed()), this, SLOT(showMenu()) ); | 89 | connect( cornerButton, SIGNAL(pressed()), this, SLOT(showMenu()) ); |
67 | canvas->setCornerWidget( cornerButton ); | 90 | canvas->setCornerWidget( cornerButton ); |
68 | 91 | ||
69 | QTimer::singleShot( 0, canvas, SLOT(openConnection()) ); | 92 | stack->raiseWidget( bookmarkSelector ); |
93 | |||
94 | |||
95 | QPEToolBar *bar = new QPEToolBar( this ); | ||
96 | |||
97 | QAction *n = new QAction( tr( "New Connection" ), Resource::loadPixmap( "new" ), | ||
98 | QString::null, 0, this, 0 ); | ||
99 | connect( n, SIGNAL( activated() ), | ||
100 | this, SLOT( newConnection() ) ); | ||
101 | n->addTo( bar ); | ||
102 | |||
103 | QAction *o = new QAction( tr( "Open Bookmark" ), Resource::loadPixmap( "edit" ), | ||
104 | QString::null, 0, this, 0 ); | ||
105 | connect( o, SIGNAL( activated() ), | ||
106 | this, SLOT( openConnection() ) ); | ||
107 | o->addTo( bar ); | ||
108 | |||
109 | QAction *d = new QAction( tr( "Delete Bookmark" ), Resource::loadPixmap( "trash" ), | ||
110 | QString::null, 0, this, 0 ); | ||
111 | connect( d, SIGNAL( activated() ), | ||
112 | this, SLOT( deleteBookmark() ) ); | ||
113 | d->addTo( bar ); | ||
70 | } | 114 | } |
71 | 115 | ||
72 | KVNC::~KVNC() | 116 | KVNC::~KVNC() |
73 | { | 117 | { |
118 | |||
119 | } | ||
120 | |||
121 | void KVNC::newConnection() | ||
122 | { | ||
123 | curServer=new KRFBServer; | ||
124 | |||
125 | KVNCConnDlg dlg( curServer,this); | ||
126 | dlg.showMaximized(); | ||
127 | if (dlg.exec()) { | ||
128 | if (!curServer->name.isEmpty()) | ||
129 | bookmarkSelector->addBookmark(curServer); | ||
130 | canvas->openConnection(*curServer); | ||
131 | } else | ||
132 | curServer=0; | ||
133 | } | ||
134 | |||
135 | void KVNC::openConnection( QString name) | ||
136 | { | ||
137 | curServer=bookmarkSelector->getServer(name); | ||
138 | |||
139 | if (curServer) { | ||
140 | KVNCConnDlg dlg( curServer,this); | ||
141 | dlg.showMaximized(); | ||
142 | |||
143 | if ( dlg.exec() ) { | ||
144 | canvas->openConnection(*curServer); | ||
145 | bookmarkSelector->writeBookmarks(); | ||
146 | } else | ||
147 | curServer=0; | ||
148 | } | ||
149 | } | ||
150 | |||
151 | void KVNC::openConnection( void ) | ||
152 | { | ||
153 | openConnection( bookmarkSelector->selectedBookmark()); | ||
74 | } | 154 | } |
75 | 155 | ||
76 | void KVNC::openURL( const QUrl &url ) | 156 | void KVNC::openConnection( QListBoxItem * item) |
77 | { | 157 | { |
78 | canvas->openURL( url ); | 158 | openConnection(item->text()); |
79 | } | 159 | } |
80 | 160 | ||
81 | void KVNC::setupActions() | 161 | void KVNC::setupActions() |
82 | { | 162 | { |
83 | cornerMenu = new QPopupMenu( this ); | 163 | cornerMenu = new QPopupMenu( this ); |
84 | 164 | ||
85 | fullScreenAction = new QAction( tr("Full Screen"), QString::null, 0, 0 ); | 165 | fullScreenAction = new QAction( tr("Full Screen"), QString::null, 0, 0 ); |
86 | connect( fullScreenAction, SIGNAL(activated()), | 166 | connect( fullScreenAction, SIGNAL(activated()), |
87 | this, SLOT( toggleFullScreen() ) ); | 167 | this, SLOT( toggleFullScreen() ) ); |
88 | fullScreenAction->addTo( cornerMenu ); | 168 | fullScreenAction->addTo( cornerMenu ); |
89 | fullScreenAction->setEnabled( false ); | 169 | fullScreenAction->setEnabled( false ); |
90 | 170 | ||
91 | optionsAction = new QAction( tr("Settings"), QString::null, 0, 0 ); | 171 | ctlAltDelAction = new QAction( tr("Send Contrl-Alt-Delete"), QString::null, 0, 0 ); |
92 | connect( optionsAction, SIGNAL(activated()), this, SLOT( showOptions() ) ); | 172 | connect( ctlAltDelAction, SIGNAL(activated()), |
93 | optionsAction->addTo( cornerMenu ); | 173 | canvas, SLOT( sendCtlAltDel() ) ); |
94 | 174 | ctlAltDelAction->addTo( cornerMenu ); | |
95 | connectAction = new QAction( tr("Connect..."), QString::null, 0, 0 ); | 175 | ctlAltDelAction->setEnabled( false ); |
96 | connect( connectAction, SIGNAL(activated()), | ||
97 | canvas, SLOT( openConnection() ) ); | ||
98 | connectAction->addTo( cornerMenu ); | ||
99 | 176 | ||
100 | disconnectAction = new QAction( tr("Disconnect"), QString::null, 0, 0 ); | 177 | disconnectAction = new QAction( tr("Disconnect"), QString::null, 0, 0 ); |
101 | connect( disconnectAction, SIGNAL(activated()), | 178 | connect( disconnectAction, SIGNAL(activated()), |
102 | this, SLOT( closeConnection() ) ); | 179 | this, SLOT( closeConnection() ) ); |
103 | disconnectAction->addTo( cornerMenu ); | 180 | disconnectAction->addTo( cornerMenu ); |
104 | disconnectAction->setEnabled( false ); | 181 | disconnectAction->setEnabled( false ); |
105 | } | 182 | } |
106 | 183 | ||
107 | void KVNC::toggleFullScreen() | 184 | void KVNC::toggleFullScreen() |
108 | { | 185 | { |
109 | if ( fullscreen ) { | 186 | if ( fullscreen ) { |
110 | canvas->releaseKeyboard(); | 187 | canvas->releaseKeyboard(); |
111 | canvas->reparent( this, 0, QPoint(0,0), false ); | 188 | canvas->reparent( stack, 0, QPoint(0,0), false ); |
112 | canvas->setFrameStyle( QFrame::Panel | QFrame::Sunken ); | 189 | canvas->setFrameStyle( QFrame::Panel | QFrame::Sunken ); |
113 | setCentralWidget( canvas ); | 190 | setCentralWidget( stack ); |
114 | canvas->show(); | 191 | stack->addWidget(canvas,get_unique_id()); |
115 | fullScreenAction->setText( tr("Full Screen") ); | 192 | stack->raiseWidget(canvas); |
116 | } else { | 193 | canvas->show(); |
117 | canvas->setFrameStyle( QFrame::NoFrame ); | 194 | stack->show(); |
118 | canvas->reparent( 0,WStyle_Tool | WStyle_Customize | WStyle_StaysOnTop, | 195 | fullScreenAction->setText( tr("Full Screen") ); |
119 | QPoint(0,0),false); | 196 | } else { |
120 | canvas->resize(qApp->desktop()->width(), qApp->desktop()->height()); | 197 | canvas->setFrameStyle( QFrame::NoFrame ); |
121 | canvas->raise(); | 198 | stack->removeWidget(canvas); |
122 | canvas->setFocus(); | 199 | canvas->reparent( 0,WStyle_Tool | WStyle_Customize | WStyle_StaysOnTop, |
123 | canvas->grabKeyboard(); | 200 | QPoint(0,0),false); |
124 | canvas->show(); | 201 | canvas->resize(qApp->desktop()->width(), qApp->desktop()->height()); |
125 | 202 | canvas->raise(); | |
126 | fullScreenAction->setText( tr("Stop Full Screen") ); | 203 | canvas->setFocus(); |
127 | } | 204 | canvas->grabKeyboard(); |
128 | 205 | canvas->show(); | |
206 | |||
207 | fullScreenAction->setText( tr("Stop Full Screen") ); | ||
208 | } | ||
209 | |||
210 | |||
129 | fullscreen = !fullscreen; | 211 | fullscreen = !fullscreen; |
130 | } | 212 | } |
131 | 213 | ||
132 | void KVNC::closeConnection() | 214 | void KVNC::closeConnection() |
133 | { | 215 | { |
134 | if ( fullscreen ) | 216 | if ( fullscreen ) |
@@ -146,45 +228,45 @@ void KVNC::showMenu() | |||
146 | } | 228 | } |
147 | 229 | ||
148 | void KVNC::connected() | 230 | void KVNC::connected() |
149 | { | 231 | { |
150 | static QString msg = tr( "Connected to remote host" ); | 232 | static QString msg = tr( "Connected to remote host" ); |
151 | statusMessage( msg ); | 233 | statusMessage( msg ); |
152 | connectAction->setEnabled( false ); | 234 | ctlAltDelAction->setEnabled(true); |
153 | disconnectAction->setEnabled( true ); | 235 | disconnectAction->setEnabled( true ); |
154 | fullScreenAction->setEnabled( true ); | 236 | fullScreenAction->setEnabled( true ); |
237 | stack->raiseWidget(canvas); | ||
155 | } | 238 | } |
156 | 239 | ||
157 | void KVNC::loggedIn() | 240 | void KVNC::loggedIn() |
158 | { | 241 | { |
159 | static QString msg = tr( "Logged in to remote host" ); | 242 | static QString msg = tr( "Logged in to remote host" ); |
160 | statusMessage( msg ); | 243 | statusMessage( msg ); |
161 | } | 244 | } |
162 | 245 | ||
163 | void KVNC::disconnected() | 246 | void KVNC::disconnected() |
164 | { | 247 | { |
248 | |||
249 | if ( fullscreen ) | ||
250 | toggleFullScreen(); | ||
165 | static QString msg = tr( "Connection closed" ); | 251 | static QString msg = tr( "Connection closed" ); |
166 | statusMessage( msg ); | 252 | statusMessage( msg ); |
167 | connectAction->setEnabled( true ); | 253 | ctlAltDelAction->setEnabled(false); |
168 | disconnectAction->setEnabled( false ); | 254 | disconnectAction->setEnabled( false ); |
169 | fullScreenAction->setEnabled( false ); | 255 | fullScreenAction->setEnabled( false ); |
256 | stack->raiseWidget(bookmarkSelector); | ||
170 | } | 257 | } |
171 | 258 | ||
172 | void KVNC::statusMessage( const QString &m ) | 259 | void KVNC::statusMessage( const QString &m ) |
173 | { | 260 | { |
174 | Global::statusMessage( m ); | 261 | Global::statusMessage( m ); |
175 | } | 262 | } |
176 | 263 | ||
177 | void KVNC::error( const QString &msg ) | 264 | void KVNC::error( const QString &msg ) |
178 | { | 265 | { |
179 | statusMessage( msg ); | 266 | statusMessage( msg ); |
180 | QMessageBox::warning( this, tr("VNC Viewer"), msg ); | 267 | QMessageBox::warning( this, tr("VNC Viewer"), msg ); |
181 | } | 268 | } |
182 | 269 | void KVNC::deleteBookmark(void) | |
183 | void KVNC::showOptions() | ||
184 | { | 270 | { |
185 | KVNCOptionsDlg *wdg = new KVNCOptionsDlg( canvas->connection()->options(), this ); | 271 | bookmarkSelector->deleteBookmark(bookmarkSelector->selectedBookmark()); |
186 | wdg->showMaximized(); | ||
187 | wdg->exec(); | ||
188 | delete wdg; | ||
189 | } | 272 | } |
190 | |||