From 57aa217e8eff5aa6a15cfd4aafe514ec62d57acd Mon Sep 17 00:00:00 2001 From: christian Date: Mon, 12 Jul 2010 21:06:20 +0200 Subject: [PATCH] add toolbar --- src/main.cpp | 9 ++-- src/mainwindow.cpp | 70 +++++++++++++++++++++++++++---- src/mainwindow.h | 118 +++++++++++----------------------------------------- src/vncview.cpp | 23 +++++++++- src/vncview.h | 1 + 5 files changed, 110 insertions(+), 111 deletions(-) diff --git a/src/main.cpp b/src/main.cpp index ad5ea07..75bd4b1 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -29,6 +29,9 @@ int main(int argc, char *argv[]) { + QCoreApplication::setOrganizationName("Presence VNC"); + QCoreApplication::setApplicationName("Presence VNC"); + QApplication app(argc, argv); QString url; @@ -41,12 +44,6 @@ int main(int argc, char *argv[]) url = arguments.at(1); if(arguments.count() > 2) quality = arguments.at(2).toInt(); - } else { - url = QInputDialog::getText(0, "Connect to Host", "VNC Server:"); - if(url.isEmpty()) { //dialog dismissed or nothing entered - return 1; - } - url = "vnc://" + url; } MainWindow main(url, quality); main.show(); diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp index 157a1b1..d0846f2 100644 --- a/src/mainwindow.cpp +++ b/src/mainwindow.cpp @@ -1,7 +1,7 @@ - #include "mainwindow.h" #include "vncview.h" +#include #include #include @@ -10,19 +10,33 @@ #include MainWindow::MainWindow(QString url, int quality): - QScrollArea(0) + QMainWindow(0), + vnc_view(0), + scroll_area(new QScrollArea(0)) { swipe_start = QPoint(0,0); setAttribute(Qt::WA_Maemo5StackedWindow); + //set up toolbar + toolbar = new QToolBar(0); + toolbar->addAction("Esc", this, SLOT(sendEsc())); + toolbar->addAction("Tab", this, SLOT(sendTab())); + addToolBar(toolbar); + //set up menu QMenuBar *menu = new QMenuBar(this); QAction *connect_action = new QAction("Connect", this); disconnect_action = new QAction("Disconnect", this); + menu->addAction(connect_action); + menu->addAction(disconnect_action); scaling = new QAction("Rescale Remote Screen", this); scaling->setCheckable(true); scaling->setChecked(true); menu->addAction(scaling); + QAction *show_toolbar = new QAction("Show Toolbar", this); + show_toolbar->setCheckable(true); + show_toolbar->setChecked(true); + menu->addAction(show_toolbar); QAction *about_action = new QAction("About", this); menu->addAction(about_action); @@ -35,6 +49,10 @@ MainWindow::MainWindow(QString url, int quality): this, SLOT(connectDialog())); connect(disconnect_action, SIGNAL(triggered()), this, SLOT(disconnectFromHost())); + connect(show_toolbar, SIGNAL(toggled(bool)), + toolbar, SLOT(setVisible(bool))); + + setCentralWidget(scroll_area); grabZoomKeys(true); setAttribute(Qt::WA_Maemo5AutoOrientation, true); @@ -47,7 +65,9 @@ MainWindow::MainWindow(QString url, int quality): vnc_view = new VncView(0, url, RemoteView::Quality(quality)); connect(scaling, SIGNAL(toggled(bool)), vnc_view, SLOT(enableScaling(bool))); - setWidget(vnc_view); + connect(vnc_view, SIGNAL(statusChanged(RemoteView::RemoteStatus)), + this, SLOT(statusChanged(RemoteView::RemoteStatus))); + scroll_area->setWidget(vnc_view); vnc_view->start(); } } @@ -67,7 +87,7 @@ void MainWindow::grabZoomKeys(bool grab) void MainWindow::closeEvent(QCloseEvent*) { hide(); grabZoomKeys(false); - vnc_view->startQuitting(); + disconnectFromHost(); } void MainWindow::about() { @@ -108,31 +128,63 @@ virtual bool event(QEvent *event) { void MainWindow::connectDialog() { - QString url = QInputDialog::getText(this, "Connect to Host", "VNC Server:"); + QSettings settings; + QString url = QInputDialog::getText(this, "Connect to Host", "VNC Server:", QLineEdit::Normal, settings.value("last_hostname", "").toString()); if(url.isEmpty()) { //dialog dismissed or nothing entered return; } + settings.setValue("last_hostname", url); url = "vnc://" + url; disconnectFromHost(); vnc_view = new VncView(0, url, RemoteView::Quality(2)); //TODO: get quality in dialog - setWidget(vnc_view); + scroll_area->setWidget(vnc_view); connect(scaling, SIGNAL(toggled(bool)), vnc_view, SLOT(enableScaling(bool))); + connect(vnc_view, SIGNAL(statusChanged(RemoteView::RemoteStatus)), + this, SLOT(statusChanged(RemoteView::RemoteStatus))); vnc_view->start(); disconnect_action->setEnabled(true); } void MainWindow::disconnectFromHost() { + if(!vnc_view) + return; + vnc_view->startQuitting(); - setWidget(0); + scroll_area->setWidget(0); - disconnect(scaling, SIGNAL(toggled(bool)), - vnc_view, SLOT(enableScaling(bool))); + vnc_view->disconnect(); //remove all connections delete vnc_view; vnc_view = 0; disconnect_action->setEnabled(false); } + +void MainWindow::statusChanged(RemoteView::RemoteStatus status) +{ + static RemoteView::RemoteStatus old_status = RemoteView::Disconnected; + + switch(status) { + case RemoteView::Connecting: + setAttribute(Qt::WA_Maemo5ShowProgressIndicator, true); + break; + case RemoteView::Connected: + setAttribute(Qt::WA_Maemo5ShowProgressIndicator, false); + break; + case RemoteView::Disconnecting: + if(old_status != RemoteView::Disconnected) { //Disconnecting also occurs while connecting, so check last state + QMaemo5InformationBox::information(this, "Connection lost"); + } + break; + case RemoteView::Disconnected: + if(old_status == RemoteView::Disconnecting) { + scroll_area->setWidget(0); //remove widget + } + break; + } + + old_status = status; +} diff --git a/src/mainwindow.h b/src/mainwindow.h index 1b5cdbf..6111a72 100644 --- a/src/mainwindow.h +++ b/src/mainwindow.h @@ -1,105 +1,35 @@ +#ifndef MAINWINDOW_H +#define MAINWINDOW_H #include -#include - +#include "remoteview.h" #include "vncview.h" -#include -#include - -#include - -class MainWindow : public QScrollArea { +class MainWindow : public QMainWindow { Q_OBJECT +public: + MainWindow(QString url, int quality); +public slots: + void connectDialog(); + void disconnectFromHost(); + void about(); + void statusChanged(RemoteView::RemoteStatus status); +protected: + //virtual bool event(QEvent *event); + void closeEvent(QCloseEvent*); private: + void grabZoomKeys(bool grab); VncView *vnc_view; - QWidget *menu; + QScrollArea *scroll_area; + //QWidget *menu; + QToolBar *toolbar; QPoint swipe_start; + QAction *scaling; + QAction *disconnect_action; -public: - MainWindow(QString url, int quality) : QScrollArea(0) { - swipe_start = QPoint(0,0); - setAttribute(Qt::WA_Maemo5StackedWindow); - - vnc_view = new VncView(0, url, RemoteView::Quality(quality)); - setWidget(vnc_view); - - //set up menu - QMenuBar *menu = new QMenuBar(this); - QAction *scaling = new QAction("Rescale Remote Screen", this); - scaling->setCheckable(true); - scaling->setChecked(true); - menu->addAction(scaling); - QAction *about_action = new QAction("About", this); - menu->addAction(about_action); - - //menu->setAttribute(Qt::WA_Maemo5StackedWindow); - //menu->hide(); - - connect(scaling, SIGNAL(toggled(bool)), - vnc_view, SLOT(enableScaling(bool))); - connect(about_action, SIGNAL(triggered()), - this, SLOT(about())); - - grabZoomKeys(true); - setAttribute(Qt::WA_Maemo5AutoOrientation, true); - //setAttribute(Qt::WA_Maemo5PortraitOrientation, true); - - vnc_view->start(); - } - - void grabZoomKeys(bool grab) - { - unsigned long val = (grab)?1:0; - Atom atom = XInternAtom(QX11Info::display(), "_HILDON_ZOOM_KEY_ATOM", False); - if(!atom) { - qWarning("Couldn't get zoom key atom"); - return; - } - XChangeProperty(QX11Info::display(), winId(), atom, XA_INTEGER, - 32, PropModeReplace, reinterpret_cast(&val), 1); - } - void closeEvent(QCloseEvent*) { - hide(); - grabZoomKeys(false); - vnc_view->startQuitting(); - } -public slots: - void about() { - QMessageBox::about(this, tr("About Presence VNC"), - tr("

Presence VNC 0.1 alpha

\ -A touch screen friendly VNC client\ -

©2010 Christian Pulvermacher <pulvermacher@gmx.de>

\ -

Based on KRDC, © 2007-2008 Urs Wolfer

\ -

This program is free software; License: GNU GPL 2 or later.

")); - } - -protected: -/* swipe not used, and doesn't work without scaling anyway :/ - virtual bool event(QEvent *event) { - if(event->type() == QEvent::MouseMove) { - QMouseEvent *ev = dynamic_cast(event); - if(!swipe_start.isNull()) { - QPoint diff = swipe_start - ev->pos(); - const int swipe_dist = 60; - if(diff.x() > swipe_dist and diff.y() < swipe_dist and diff.y() > -swipe_dist) { // - menu->show(); - swipe_start = QPoint(0,0); - } - } else if((width() - ev->x()) < 10) { - swipe_start = ev->pos(); - } - std::cout << "mousex: " << width() - ev->x() << "\n"; - //TODO: make scrolling over border result in wheel events? i get weird (out of range) mouse events when that happens - return true; - } else if(event->type() == QEvent::MouseButtonRelease) { - swipe_start = QPoint(0,0); - return true; - } else { -// std::cout << "event " << event->type() << "\n"; - return QScrollArea::event(event); - } - } - */ +private slots: + void sendEsc() { vnc_view->sendKey(Qt::Key_Escape); } + void sendTab() { vnc_view->sendKey(Qt::Key_Tab); } }; +#endif diff --git a/src/vncview.cpp b/src/vncview.cpp index 5023ebf..fddc7ff 100644 --- a/src/vncview.cpp +++ b/src/vncview.cpp @@ -586,14 +586,12 @@ void VncView::keyEventHandler(QKeyEvent *e) else m_buttonMask &= 0xfe; vncThread.mouseEvent(cursor_x, cursor_y, m_buttonMask); - kDebug(5011) << "left zoom"; } else if(e->key() == Qt::Key_F7) { if(pressed) m_buttonMask |= 0x04; else m_buttonMask &= 0xfb; vncThread.mouseEvent(cursor_x, cursor_y, m_buttonMask); - kDebug(5011) << "right zoom"; } else if (k) { vncThread.keyEvent(k, pressed); } @@ -640,4 +638,25 @@ void VncView::clipboardDataChanged() vncThread.clientCut(text); } +//fake key events +void VncView::sendKey(Qt::Key key) +{ + rfbKeySym k = 0; + if(key == Qt::Key_Escape) + switch(key) { + case Qt::Key_Escape: + k = 0xff1b; + break; + case Qt::Key_Tab: + k = 0xff09; + break; + default: + kDebug(5011) << "unhandled Qt::Key value " << key; + return; + } + + vncThread.keyEvent(k, true); + vncThread.keyEvent(k, false); +} + #include "moc_vncview.cpp" diff --git a/src/vncview.h b/src/vncview.h index cc2a746..1f2ac32 100644 --- a/src/vncview.h +++ b/src/vncview.h @@ -55,6 +55,7 @@ public: void setQuality(int q); void setViewOnly(bool viewOnly); void showDotCursor(DotCursorState state); + void sendKey(Qt::Key key); virtual void updateConfiguration(); -- 1.7.9.5