diff options
Diffstat (limited to 'src/widget.cpp')
-rw-r--r-- | src/widget.cpp | 62 |
1 files changed, 59 insertions, 3 deletions
diff --git a/src/widget.cpp b/src/widget.cpp index d0f0312..bc4869f 100644 --- a/src/widget.cpp +++ b/src/widget.cpp @@ -1,14 +1,20 @@ #include "widget.h" +#include "main.h" +#include "xx.h" +#include "bus.h" #include "ui_widget.h" #include "timeoutdialog.h" -#include "x.h" -#include "main.h" #include <QDebug> #include <QtWidgets/QAction> #include <QAbstractItemView> #include <QScreen> #include <QThread> +#include <QMessageBox> + +/* + * Helper and static stuff + */ class ScreenWidget : public QWidget { @@ -62,7 +68,10 @@ static void addBoldListener(QComboBox *combo) }); } -//______________________________________________________________________________ +/* + * Main widget + */ + Widget::Widget(QWidget *parent) : QWidget(parent), _ui(new Ui::Widget), @@ -128,6 +137,36 @@ Widget::Widget(QWidget *parent) : connect(qApp, &QGuiApplication::screenRemoved, [this](const QScreen *scrn) { _qtScreens.removeAll(scrn); }); + _ui->btnExit->setVisible(CommandLine::backgroundMode()); + if (CommandLine::backgroundMode()) { + // Listener + if (!Bus::inst()->registerListener()) { + qDebug() << "WARNING: CANNOT CONNECT TO DBUS FOR LISTENING"; + // TODO: GUI feedback + } else { + // Worked fine + // Timer + QTimer *t = new QTimer(this); + t->setSingleShot(true); + connect(t, &QTimer::timeout, [=]() { + if (this->isHidden()) { + ScreenSetup::inst()->initModes(); + this->show(); + } else { + // TODO: Flash button + } + }); + // GUI popup logic + connect(Bus::inst(), &Bus::serviceConnected, [=]() { + qDebug() << "\\o/ Received DBus connect notification \\o/"; + if (this->isHidden()) { + t->start(1500); + } else { + // TODO: Flash button + } + }); + } + } } //______________________________________________________________________________ @@ -516,6 +555,23 @@ void Widget::connectButtons() { ScreenSetup::inst()->updateScreenResources(); initControls(); }); + // Close + connect(_ui->btnClose, &QPushButton::clicked, [=](bool) { + if (CommandLine::backgroundMode()) { + this->hide(); + } else { + qApp->exit(0); + } + }); + // Exit + connect(_ui->btnExit, &QPushButton::clicked, [=](bool) { + if (QMessageBox::question(this, tr("Confirm"), + tr("This terminates the GUI.\n" + "It will not pop up again if further screens are connected.\n" + "Are you sure?")) == QMessageBox::Yes) { + qApp->exit(0); + } + }); } |