From 6decac6613fef21869784df0d83a0b7c7d1c2008 Mon Sep 17 00:00:00 2001 From: Simon Rettberg Date: Fri, 28 Oct 2016 16:14:07 +0200 Subject: [client] Allow ESC key to cancel projection in hybrid mode --- src/client/clientapp/clientapp.cpp | 2 +- src/client/clientapp/clientapp.h | 9 ++++++--- src/client/net/serverconnection.cpp | 17 +++++++++++++++-- src/client/net/serverconnection.h | 11 +++++++++++ src/client/toolbar/toolbar.cpp | 31 ++++++++++++++++++++++--------- src/client/toolbar/toolbar.h | 1 + src/client/vnc/vncwindow.cpp | 18 +++++++++++++++++- src/client/vnc/vncwindow.h | 1 + 8 files changed, 74 insertions(+), 16 deletions(-) diff --git a/src/client/clientapp/clientapp.cpp b/src/client/clientapp/clientapp.cpp index 5528c65..7711556 100644 --- a/src/client/clientapp/clientapp.cpp +++ b/src/client/clientapp/clientapp.cpp @@ -5,7 +5,7 @@ #include "../net/serverconnection.h" ClientApp::ClientApp(int& argc, char** argv) - : QApplication(argc, argv), _connectionMode(ConnectionMode::None), _examMode(false), _isManagerPc(false) + : QApplication(argc, argv), _connectionMode(ConnectionMode::None), _examMode(false), _connection(NULL), _isManagerPc(false) { /* some values */ setOrganizationName("openslx"); diff --git a/src/client/clientapp/clientapp.h b/src/client/clientapp/clientapp.h index 8a7fd83..dbfbc32 100644 --- a/src/client/clientapp/clientapp.h +++ b/src/client/clientapp/clientapp.h @@ -1,5 +1,7 @@ -#include #include "../util/util.h" +#include "../net/serverconnection.h" + +#include #include #include @@ -11,7 +13,6 @@ class Toolbar; class ConnectWindow; -class ServerConnection; /* this class is supposed to (after complete refactoring) to encapsulate all * state of the application. At the moment, the state is distributed within @@ -55,7 +56,9 @@ public: ConnectWindow* connectWindow() const { return _connectWindow; } - const bool isManagerPc() const { return _isManagerPc; } + const bool isConfiguredAsManager() const { return _isManagerPc; } + + const bool isConnectedToLocalManager() const { return _connection != NULL && _connection->isLocalConnection(); } private slots: diff --git a/src/client/net/serverconnection.cpp b/src/client/net/serverconnection.cpp index 448b200..46f2538 100644 --- a/src/client/net/serverconnection.cpp +++ b/src/client/net/serverconnection.cpp @@ -262,15 +262,28 @@ void ServerConnection::handleMsg() } } else if (id == _LOCK) { const bool enable = (_fromServer.getFieldString("ENABLE").toInt() != 0); - if (enable) + if (enable && !clientApp->isConnectedToLocalManager()) { _blank->lock(_fromServer.getFieldString("MESSAGE")); - else + } else { _blank->unlock(); + } } else if (id == _ATTENTION) { emit attentionChanged(_fromServer.getFieldString(_ENABLE) == __TRUE); } } +void ServerConnection::checkLocalConnection() +{ + if (_socket == NULL) { + return; + } + if (_socket->peerAddress() == _socket->localAddress()) { + _isLocalConnection = 1; + } else { + _isLocalConnection = 0; + } +} + /* * Override */ diff --git a/src/client/net/serverconnection.h b/src/client/net/serverconnection.h index c36b238..17fa20a 100644 --- a/src/client/net/serverconnection.h +++ b/src/client/net/serverconnection.h @@ -18,6 +18,7 @@ private: int _jpegQuality; int _authed; bool _autoConnect; + int _isLocalConnection; qint64 _lastData; NetworkMessage _fromServer, _toServer; @@ -29,6 +30,8 @@ private: void handleMsg(); + void checkLocalConnection(); + public: ServerConnection(const QString& host, const quint16 port, const QByteArray& sessionName, const QByteArray& certHash, bool autoConnect); void disconnectFromServer(); @@ -42,6 +45,14 @@ public: { return _socket->peerAddress().toString(); } + + bool isLocalConnection() { + if (_isLocalConnection == -1) { + checkLocalConnection(); + } + return _isLocalConnection == 1; + } + void sendMessage(NetworkMessage& message); void sendAttention(bool on); diff --git a/src/client/toolbar/toolbar.cpp b/src/client/toolbar/toolbar.cpp index d6bcf22..8af15f4 100644 --- a/src/client/toolbar/toolbar.cpp +++ b/src/client/toolbar/toolbar.cpp @@ -103,17 +103,13 @@ void Toolbar::init() // Connect the signals connect(clientApp->connectWindow(), SIGNAL(disconnect()), this, SLOT(onDoDisconnect())); connect(clientApp->connectWindow(), SIGNAL(connected(ServerConnection*)), this, SLOT(onConnected(ServerConnection*))); + connect(_ui->btnManager, SIGNAL(toggled(bool)), this, SLOT(onBtnManager())); + connect(_ui->btnAttention, SIGNAL(toggled(bool)), this, SLOT(onBtnAttention())); /* Setup menu */ initMenu(); - /* setup manager button */ - if (clientApp->isManagerPc()) { - connect(_ui->btnManager, SIGNAL(toggled(bool)), this, SLOT(onBtnManager())); - } else { - setFixedWidth(width() - _ui->btnManager->width()); - _ui->btnManager->setVisible(false); - } + updateButtonVisibility(); /* setup lock desktop button*/ bool showLock = clientApp->getSettings()->value("showLockDesktopButton").toBool(); @@ -126,8 +122,6 @@ void Toolbar::init() /* hide attention button while disconnected */ _ui->btnAttention->setVisible(false); - - connect(_ui->btnAttention, SIGNAL(toggled(bool)), this, SLOT(onBtnAttention())); _ui->btnAttention->setMaximumWidth(30); /* Connect the signals from vnc server */ @@ -188,6 +182,23 @@ void Toolbar::initMenu() connect(_acnQuit, SIGNAL(triggered()), this, SLOT(exit())); } +void Toolbar::updateButtonVisibility() +{ + // "Toggle to manager view" (switch between desktop 1 and 2) + bool showManagerToggle = clientApp->isConfiguredAsManager() || clientApp->isConnectedToLocalManager(); + if (showManagerToggle == _ui->btnManager->isHidden()) { + // Visibility should change + if (showManagerToggle) { + connect(_ui->btnManager, SIGNAL(toggled(bool)), this, SLOT(onBtnManager())); + setFixedWidth(width() + _ui->btnManager->width()); + } else { + disconnect(_ui->btnManager, SIGNAL(toggled(bool)), this, SLOT(onBtnManager())); + setFixedWidth(width() - _ui->btnManager->width()); + } + _ui->btnManager->setVisible(showManagerToggle); + } +} + /***************************************************************************//** * Destructor of the Toolbar. Destroys the widget. All this widget's children * are deleted first. @@ -358,6 +369,7 @@ void Toolbar::onDisconnected(ServerConnection* connection) _ui->btnAttention->setVisible(false); onBtnAttention(); _hideTimer.start(); + QTimer::singleShot(1, this, SLOT(updateButtonVisibility())); } /***************************************************************************//** @@ -376,6 +388,7 @@ void Toolbar::onConnected(ServerConnection* connection) _ui->lblStatus->setText(tr("Online")); /* connected, show button */ _ui->btnAttention->setVisible(true); + QTimer::singleShot(1, this, SLOT(updateButtonVisibility())); // connect(connection, SIGNAL(disconnected(ServerConnection*)), this, SLOT(onDisconnected(ServerConnection*))); connect(connection, SIGNAL(openVnc(const QString&, int, const QString&, bool, bool, const QString&, const int, const QByteArray&)), diff --git a/src/client/toolbar/toolbar.h b/src/client/toolbar/toolbar.h index a84286f..1804d0a 100644 --- a/src/client/toolbar/toolbar.h +++ b/src/client/toolbar/toolbar.h @@ -77,6 +77,7 @@ private slots: void showAboutDialog(); void showInformationDialog(); void enableLockBtn(); + void updateButtonVisibility(); }; #endif /* PVSCLIENTGUI_H_ */ diff --git a/src/client/vnc/vncwindow.cpp b/src/client/vnc/vncwindow.cpp index 818b22f..8cd7534 100644 --- a/src/client/vnc/vncwindow.cpp +++ b/src/client/vnc/vncwindow.cpp @@ -17,6 +17,7 @@ #include "vncwindow.h" #include "vncthread.h" +#include "../clientapp/clientapp.h" VncWindow::VncWindow(QWidget *parent) : QWidget(parent), _vncWorker(NULL), _viewOnly(true), _clientId(0), _redrawTimer(0), _tcpTimeoutTimer(0) @@ -109,7 +110,10 @@ void VncWindow::open(const QString& host, int port, const QString& passwd, bool _remoteThumb.loadFromData(rawThumb); if (fullscreen) { - setWindowFlags(Qt::WindowStaysOnTopHint); + setWindowFlags(Qt::WindowStaysOnTopHint); // | Qt::X11BypassWindowManagerHint); <- better, but window won't get any keyboard input + QDesktopWidget *desktop = QApplication::desktop(); + QRect size = desktop->screenGeometry(this); + resize(size.size()); showFullScreen(); activateWindow(); raise(); @@ -258,3 +262,15 @@ void VncWindow::resizeEvent(QResizeEvent* event) this->repaint(); } +/** + * Called when user releases a pressed key and the window has focus + */ +void VncWindow::keyReleaseEvent(QKeyEvent* event) +{ + if (event->modifiers() == 0 && event->key() == Qt::Key_Escape && !clientApp->isConnectedToLocalManager()) { + this->close(); + } else { + QWidget::keyReleaseEvent(event); + } +} + diff --git a/src/client/vnc/vncwindow.h b/src/client/vnc/vncwindow.h index 2b91c0e..2cb9ad0 100644 --- a/src/client/vnc/vncwindow.h +++ b/src/client/vnc/vncwindow.h @@ -43,6 +43,7 @@ protected: void resizeEvent(QResizeEvent* event); void closeEvent(QCloseEvent *e); void timerEvent(QTimerEvent *event); + void keyReleaseEvent(QKeyEvent *event); private: VncThread *_vncWorker; -- cgit v1.2.3-55-g7522