From d41aa490b2c00ffe31023b96b3daff523d4757c1 Mon Sep 17 00:00:00 2001 From: Christian Klinger Date: Wed, 18 May 2016 16:53:12 +0200 Subject: added toolbar button to switch to manager. The actual window switching logic is delegated to a pair of shell scripts. --- gui/client/toolbar.ui | 38 +++++++++++++++++++++++----------- src/client/toolbar/toolbar.cpp | 47 ++++++++++++++++++++++++++++++++++++++++++ src/client/toolbar/toolbar.h | 4 ++++ 3 files changed, 77 insertions(+), 12 deletions(-) diff --git a/gui/client/toolbar.ui b/gui/client/toolbar.ui index 0c21f70..b4ac3b2 100644 --- a/gui/client/toolbar.ui +++ b/gui/client/toolbar.ui @@ -6,7 +6,7 @@ 0 0 - 229 + 358 39 @@ -67,16 +67,7 @@ QCheckBox::indicator:checked:pressed { - - 0 - - - 0 - - - 0 - - + 0 @@ -128,7 +119,7 @@ QCheckBox::indicator:checked:pressed { - + Qt::Horizontal @@ -151,6 +142,19 @@ p, li { white-space: pre-wrap; } + + + + Qt::Horizontal + + + + 20 + 20 + + + + @@ -173,6 +177,16 @@ p, li { white-space: pre-wrap; } + + + + Switch + + + true + + + diff --git a/src/client/toolbar/toolbar.cpp b/src/client/toolbar/toolbar.cpp index 83b1a9d..1f98a8b 100644 --- a/src/client/toolbar/toolbar.cpp +++ b/src/client/toolbar/toolbar.cpp @@ -88,6 +88,8 @@ void Toolbar::init() /* Initialize the GUI */ _ui->setupUi(this); + _onWorkspace2 = false; + /* Set window properties */ setWindowFlags(Qt::WindowStaysOnTopHint | Qt::X11BypassWindowManagerHint | Qt::FramelessWindowHint); setAttribute(Qt::WA_AlwaysShowToolTips); @@ -106,6 +108,12 @@ void Toolbar::init() /* Setup menu */ initMenu(); + /* setup manager button */ + _isManagerPc = isManagerPc(); + _ui->btnManager->setVisible(_isManagerPc); + connect(_ui->btnManager, SIGNAL(clicked()), this, SLOT(onBtnManager())); + + /* Connect the signals from vnc server */ connect(VncServer::instance(), SIGNAL(started(int, QString&, QString&)), this, SLOT(onVncServerIsRunning(int))); @@ -210,6 +218,30 @@ void Toolbar::enterEvent(QEvent* e) * */ + +/* returns true when the pc of this client is also eligible to be a manager */ +bool Toolbar::isManagerPc(){ + QList myRooms; + SYSTEM_SETTINGS(conf); + QStringList roomNames = conf.value("rooms").toStringList(); + + /* go through all rooms and check if this client is a manager of the room. */ + for (auto roomName : roomNames) { + conf.beginGroup(roomName); + QString mgrIP = conf.value("mgrIP").toString(); + + foreach (const QHostAddress &address, QNetworkInterface::allAddresses()) { + QString ip = conf.value("ip").toString(); + if (address.toString() == mgrIP) { + qDebug() << "this pc could be a manager of room " << roomName << "because this address is " << address; + return true; + } + } + conf.endGroup(); + } + return false; +} + /* returns a sorted list of available rooms. * (Available means that this client is configured to be in that room) */ QList Toolbar::myRooms() { @@ -407,3 +439,18 @@ void Toolbar::showBar() const QRect primaryScreen = desktop.screenGeometry(); move(x(), primaryScreen.top()); } +void Toolbar::onBtnManager() { + /* TODO */ + qDebug() << "onBtnManager()"; + + /* call script to switch to workspace of the manager */ + QProcess switchP; + if (_onWorkspace2) { + switchP.start("/bin/sh", QStringList() << "/opt/openslx/pvs2/switchBack.sh"); + } else { + switchP.start("/bin/sh", QStringList() << "/opt/openslx/pvs2/switchToManager.sh"); + } + _ui->btnManager->setDown(_onWorkspace2); + _onWorkspace2 = !_onWorkspace2; + switchP.waitForFinished(); +} diff --git a/src/client/toolbar/toolbar.h b/src/client/toolbar/toolbar.h index 6c61508..0980beb 100644 --- a/src/client/toolbar/toolbar.h +++ b/src/client/toolbar/toolbar.h @@ -49,11 +49,14 @@ private: ServerConnection *_connection; QTimer _blinkTimer; VncWindow *_vnc; + bool _onWorkspace2; + bool _isManagerPc; const QPixmap _cam32, _beWatchedEye; void leaveEvent(QEvent* e); void enterEvent(QEvent* e); QList myRooms(); + bool isManagerPc(); QString identifyMgrIP(); void init(); void initMenu(); @@ -63,6 +66,7 @@ private slots: void onDisconnected(); void onConnected(ServerConnection* connection); void onDoDisconnect(); + void onBtnManager(); void exit(); void cameraBlink(); void showBar(); -- cgit v1.2.3-55-g7522