From 89416530f15453cf647397739261e2169016843c Mon Sep 17 00:00:00 2001 From: Simon Rettberg Date: Fri, 31 Aug 2018 15:14:30 +0200 Subject: [client] Switch back to first desktop when hiding manager toggle button When the "toggle to manager" button was visible and is about to be hidden, we assume that we were running in hybrid mode (manager on second desktop) and the manager was closed. To prevent the user from staring at an empty dektop where the manager once redided, switch to desktop 1 so they'll be reunited with their beloved VM session. --- src/client/toolbar/toolbar.cpp | 23 ++++++++++++++--------- src/client/toolbar/toolbar.h | 7 ++++++- 2 files changed, 20 insertions(+), 10 deletions(-) diff --git a/src/client/toolbar/toolbar.cpp b/src/client/toolbar/toolbar.cpp index ddb55f1..a3e2c31 100644 --- a/src/client/toolbar/toolbar.cpp +++ b/src/client/toolbar/toolbar.cpp @@ -106,8 +106,10 @@ 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())); + connect(_ui->btnManager, &QPushButton::toggled, [=](bool pressed) { + this->toggleDesktop(pressed ? Desktop::Manager : Desktop::Primary); + }); /* Setup menu */ initMenu(); @@ -198,11 +200,14 @@ void Toolbar::updateButtonVisibility() if (showManagerToggle == _ui->btnManager->isHidden()) { // Visibility should change if (showManagerToggle) { - connect(_ui->btnManager, SIGNAL(toggled(bool)), this, SLOT(onBtnManager())); + _ui->btnManager->blockSignals(false); setFixedWidth(width() + _ui->btnManager->width()); } else { - disconnect(_ui->btnManager, SIGNAL(toggled(bool)), this, SLOT(onBtnManager())); + // Hide "toggle manager" -- assume manager was closed, switch to first desktop where the VM should be running + _ui->btnManager->blockSignals(true); + _ui->btnManager->setChecked(false); setFixedWidth(width() - _ui->btnManager->width()); + toggleDesktop(Desktop::Primary); } _ui->btnManager->setVisible(showManagerToggle); } @@ -497,14 +502,16 @@ void Toolbar::onBtnAttention() } /** call script to switch to workspace of the manager */ -void Toolbar::onBtnManager() +void Toolbar::toggleDesktop(Desktop d) { QProcess switchP; - const bool on = _ui->btnManager->isChecked(); - if (on) { + if (d == Desktop::Manager) { switchP.start("/bin/sh", QStringList() << "/opt/openslx/pvs2/switchToManager.sh"); - } else { + } else if (d == Desktop::Primary) { switchP.start("/bin/sh", QStringList() << "/opt/openslx/pvs2/switchBack.sh"); + } else { + qDebug() << "Invalid toggleDesktop call"; + return; } switchP.waitForFinished(); } @@ -513,7 +520,6 @@ void Toolbar::onBtnLockDesktop() { if (this->lockDesktopP.state() == QProcess::NotRunning) { _ui->btnLockDesktop->setEnabled(false); - _ui->btnManager->setEnabled(false); this->lockDesktopP.start("/bin/sh", QStringList() << "/opt/openslx/pvs2/lockDesktop.sh"); QTimer::singleShot(2 * 1000, this, SLOT(enableLockBtn())); @@ -526,7 +532,6 @@ void Toolbar::onBtnLockDesktop() void Toolbar::enableLockBtn() { _ui->btnLockDesktop->setEnabled(true); - _ui->btnManager->setEnabled(true); } void Toolbar::setToolbarPosition(const QRect &availableGeometry) diff --git a/src/client/toolbar/toolbar.h b/src/client/toolbar/toolbar.h index a8e929f..fd1d993 100644 --- a/src/client/toolbar/toolbar.h +++ b/src/client/toolbar/toolbar.h @@ -27,6 +27,11 @@ namespace Ui class Toolbar; } +enum class Desktop { + Primary, + Manager, +}; + class Toolbar : public QWidget { Q_OBJECT @@ -61,6 +66,7 @@ private: QString identifyMgrIP(); void init(); void initMenu(); + void toggleDesktop(Desktop d); QProcess lockDesktopP; @@ -70,7 +76,6 @@ private slots: void onConnected(ServerConnection* connection); void onServerAttentionChanged(const bool on); void onDoDisconnect(); - void onBtnManager(); void onBtnLockDesktop(); void onBtnAttention(); void exit(); -- cgit v1.2.3-55-g7522