summaryrefslogtreecommitdiffstats
path: root/src/client/toolbar/toolbar.cpp
diff options
context:
space:
mode:
authorSimon Rettberg2018-09-06 11:32:54 +0200
committerSimon Rettberg2018-09-06 11:32:54 +0200
commitcb93788148785758be72fcb2afe2039e7a882c53 (patch)
treec2095f4ac5995d53e62bd9e247345a1b60c3bf5a /src/client/toolbar/toolbar.cpp
parent[client] Fix memory leak (diff)
downloadpvs2-cb93788148785758be72fcb2afe2039e7a882c53.tar.gz
pvs2-cb93788148785758be72fcb2afe2039e7a882c53.tar.xz
pvs2-cb93788148785758be72fcb2afe2039e7a882c53.zip
[client] New addon system for buttons and menu
Instead of integrating workspace switching and screen locking directly into PVS2, introduce an addon system to insert new functionality into the toolbar, as buttons or menu entries.
Diffstat (limited to 'src/client/toolbar/toolbar.cpp')
-rw-r--r--src/client/toolbar/toolbar.cpp110
1 files changed, 30 insertions, 80 deletions
diff --git a/src/client/toolbar/toolbar.cpp b/src/client/toolbar/toolbar.cpp
index 1640c01..bec8586 100644
--- a/src/client/toolbar/toolbar.cpp
+++ b/src/client/toolbar/toolbar.cpp
@@ -1,12 +1,3 @@
-/*
- * toolbar.cpp
- *
- * Created on: 21.01.2013
- * Author: sr
- */
-#include <QtAlgorithms>
-#include <QNetworkInterface>
-#include <QProcess>
#include "../../shared/settings.h"
#include "../net/serverconnection.h"
#include "../vnc/vncwindow.h"
@@ -14,10 +5,15 @@
#include "../util/util.h"
#include "../informationdialog/informationdialog.h"
#include "../clientapp/clientapp.h"
+#include "../addons/addons.h"
#include "toolbar.h"
#include "ui_toolbar.h"
+#include <QtAlgorithms>
+#include <QNetworkInterface>
+#include <QProcess>
+
/**
* @brief
*
@@ -107,23 +103,9 @@ void Toolbar::init()
connect(clientApp->connectWindow(), SIGNAL(disconnect()), this, SLOT(onDoDisconnect()));
connect(clientApp->connectWindow(), SIGNAL(connected(ServerConnection*)), this, SLOT(onConnected(ServerConnection*)));
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();
-
- updateButtonVisibility();
-
- /* setup lock desktop button*/
- bool showLock = clientApp->getSettings()->value("showLockDesktopButton").toBool();
- if (showLock) {
- connect(_ui->btnLockDesktop, SIGNAL(clicked()), this, SLOT(onBtnLockDesktop()));
- } else {
- setFixedWidth(width() - _ui->btnLockDesktop->width());
- _ui->btnLockDesktop->setVisible(false);
- }
+ initButtonsAndMenus();
/* hide attention button while disconnected */
_ui->btnAttention->setVisible(false);
@@ -160,8 +142,18 @@ void Toolbar::init()
* This function should be called once from the main init() function which in
* turn should only be called by the constructor.
**/
-void Toolbar::initMenu()
+void Toolbar::initButtonsAndMenus()
{
+ QList<QPushButton*> buttons;
+ QList<QAction*> menus;
+ auto settings = clientApp->getSettings();
+ AddonManager::loadFromPath(settings->value("addonConfigDir", "/opt/openslx/pvs2/addons").toString(), buttons, menus);
+ // Buttons
+ for (auto i : buttons) {
+ _ui->buttonContainer->addWidget(i);
+ i->setVisible(false);
+ }
+ // Menu
_menu = new QMenu(this);
_acnConnect = new QAction(tr("&Connect..."), this);
_acnDisconnect = new QAction(tr("&Disconnect"), this);
@@ -173,6 +165,10 @@ void Toolbar::initMenu()
_menu->addAction(_acnConnect);
_menu->addAction(_acnDisconnect);
_menu->addSeparator();
+ for (auto i : menus) {
+ _menu->addAction(i);
+ i->setVisible(false);
+ }
_menu->addAction(_acnInformation);
_menu->addAction(_acnAbout);
_menu->addSeparator();
@@ -181,7 +177,7 @@ void Toolbar::initMenu()
/* only add a "quit"-button when the configuration allows it. */
- bool allow = clientApp->getSettings()->value("allowClientQuit").toBool();
+ bool allow = settings->value("allowClientQuit").toBool();
_acnQuit->setVisible(allow);
// Connect the signals
@@ -191,26 +187,11 @@ void Toolbar::initMenu()
connect(_acnInformation, SIGNAL(triggered()), this, SLOT(showInformationDialog()));
connect(_acnAbout, SIGNAL(triggered()), this, SLOT(showAboutDialog()));
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) {
- _ui->btnManager->blockSignals(false);
- setFixedWidth(width() + _ui->btnManager->width());
- } else {
- // 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);
- }
+ // Delay until bar is visible
+ QTimer::singleShot(10, [=]() {
+ AddonManager::initControls();
+ });
}
/**
@@ -382,7 +363,7 @@ void Toolbar::onDisconnected(ServerConnection* connection)
_ui->btnAttention->setVisible(false);
onBtnAttention();
delayedHideBar();
- QTimer::singleShot(1, this, SLOT(updateButtonVisibility()));
+ AddonManager::disconnectEvent();
}
/**
@@ -401,7 +382,7 @@ void Toolbar::onConnected(ServerConnection* connection)
_ui->lblStatus->setText(tr("Online"));
/* connected, show button */
_ui->btnAttention->setVisible(true);
- QTimer::singleShot(1, this, SLOT(updateButtonVisibility()));
+ AddonManager::connectEvent(connection->isLocalConnection(), connection->getPeerAdress());
//
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&)),
@@ -501,6 +482,8 @@ void Toolbar::showInformationDialog()
InformationDialog* d = new InformationDialog();
d->exec();
d->deleteLater();
+ auto b = new QPushButton("sdfadsfgadfgadfgadg");
+ this->layout()->addWidget(b);
}
void Toolbar::onBtnAttention()
@@ -515,39 +498,6 @@ void Toolbar::onBtnAttention()
}
}
-/** call script to switch to workspace of the manager */
-void Toolbar::toggleDesktop(Desktop d)
-{
- QProcess switchP;
- if (d == Desktop::Manager) {
- switchP.start("/bin/sh", QStringList() << "/opt/openslx/pvs2/switchToManager.sh");
- } else if (d == Desktop::Primary) {
- switchP.start("/bin/sh", QStringList() << "/opt/openslx/pvs2/switchBack.sh");
- } else {
- qDebug() << "Invalid toggleDesktop call";
- return;
- }
- switchP.waitForFinished();
-}
-
-void Toolbar::onBtnLockDesktop()
-{
- if (this->lockDesktopP.state() == QProcess::NotRunning) {
- _ui->btnLockDesktop->setEnabled(false);
- this->lockDesktopP.start("/bin/sh", QStringList() << "/opt/openslx/pvs2/lockDesktop.sh");
-
- QTimer::singleShot(2 * 1000, this, SLOT(enableLockBtn()));
-
- } else {
- qDebug() << "trying to use lockDesktop-process while it is still running";
- }
-}
-
-void Toolbar::enableLockBtn()
-{
- _ui->btnLockDesktop->setEnabled(true);
-}
-
void Toolbar::setToolbarPosition(const QRect &availableGeometry)
{
const QRect primaryScreen = QGuiApplication::primaryScreen()->geometry();