From 3444fed0accfc41d314843f4587206d7347e5632 Mon Sep 17 00:00:00 2001 From: Anthony Bilinski Date: Sun, 13 Mar 2022 03:56:17 -0700 Subject: [PATCH] refactor(GUI): Remove GUI setEnabled, call on Widget directly Nexus is the only caller and has access to Widget. Because only Nexus calls it, and Nexus runs on GUI thread, remove check and queued connection. --- src/nexus.cpp | 4 ++-- src/widget/gui.cpp | 22 ---------------------- src/widget/gui.h | 2 -- 3 files changed, 2 insertions(+), 26 deletions(-) diff --git a/src/nexus.cpp b/src/nexus.cpp index 4347ed9b2..b077ce8e3 100644 --- a/src/nexus.cpp +++ b/src/nexus.cpp @@ -245,7 +245,7 @@ void Nexus::showMainGUI() // There are small instants on startup during which no // profile is loaded but the GUI could still receive events, // e.g. between two modal windows. Disable the GUI to prevent that. - GUI::setEnabled(false); + widget->setEnabled(false); // Connections connect(profile, &Profile::selfAvatarChanged, widget, &Widget::onSelfAvatarLoaded); @@ -259,7 +259,7 @@ void Nexus::showMainGUI() profile->startCore(); - GUI::setEnabled(true); + widget->setEnabled(true); } /** diff --git a/src/widget/gui.cpp b/src/widget/gui.cpp index 8417b76c5..0397386e9 100644 --- a/src/widget/gui.cpp +++ b/src/widget/gui.cpp @@ -61,21 +61,6 @@ GUI& GUI::getInstance() // Implementation of the public clean interface -/** - * @brief Will enable or disable the GUI. - * @note A disabled GUI can't be interacted with by the user. - * @param state Enable/disable GUI. - */ -void GUI::setEnabled(bool state) -{ - if (QThread::currentThread() == qApp->thread()) { - getInstance()._setEnabled(state); - } else { - QMetaObject::invokeMethod(&getInstance(), "_setEnabled", Qt::BlockingQueuedConnection, - Q_ARG(bool, state)); - } -} - /** * @brief Change the title of the main window. * @param title Titile to set. @@ -209,13 +194,6 @@ bool GUI::askQuestion(const QString& title, const QString& msg, const QString& b // Private implementations -void GUI::_setEnabled(bool state) -{ - Widget* w = Nexus::getDesktopGUI(); - if (w) - w->setEnabled(state); -} - void GUI::_setWindowTitle(const QString& title) { QWidget* w = getMainWidget(); diff --git a/src/widget/gui.h b/src/widget/gui.h index a6ce6ee35..38364de56 100644 --- a/src/widget/gui.h +++ b/src/widget/gui.h @@ -30,7 +30,6 @@ class GUI : public QObject public: static GUI& getInstance(); static QWidget* getMainWidget(); - static void setEnabled(bool state); static void setWindowTitle(const QString& title); static void reloadTheme(); static void showInfo(const QString& title, const QString& msg); @@ -48,7 +47,6 @@ private: private slots: // Private implementation, those must be called from the GUI thread - void _setEnabled(bool state); void _setWindowTitle(const QString& title); void _showInfo(const QString& title, const QString& msg); void _showWarning(const QString& title, const QString& msg);