From 51b0337ceb9b8a4b74c43193bc0e605bfc71a1af Mon Sep 17 00:00:00 2001 From: Albert S Date: Mon, 3 Jun 2019 07:51:27 +0200 Subject: [PATCH] window: single instance handling + /reload command --- window.cpp | 36 +++++++++++++++++++++++++++++------- window.h | 5 ++++- 2 files changed, 33 insertions(+), 8 deletions(-) diff --git a/window.cpp b/window.cpp index 154efd7..11aa344 100644 --- a/window.cpp +++ b/window.cpp @@ -13,7 +13,6 @@ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ -#include "window.h" #include #include #include @@ -26,11 +25,13 @@ #include #include #include -Window::Window(const QVector &configs) +#include "window.h" +#include "configprovider.h" +Window::Window(ConfigProvider &configProvider) { - this->userEntryButtons = generateEntryButtons(configs); + this->configProvider = &configProvider; createGui(); - populateGrid(this->userEntryButtons); + initFromConfig(); this->lineEdit->installEventFilter(this); QFont font; font.setPointSize(48); @@ -53,7 +54,12 @@ Window::~Window() - +void Window::initFromConfig() +{ + this->userEntryButtons = generateEntryButtons(configProvider->getUserEntries()); + this->systemEntryButtons = generateEntryButtons(configProvider->getSystemEntries()); + populateGrid(this->userEntryButtons); +} void Window::showCalculationResultContextMenu(const QPoint &point) { @@ -100,7 +106,15 @@ void Window::populateGrid(const QVector &list) void Window::buttonClick(const EntryPushButton &config) { QProcess::startDetached(config.getCommand(), config.getArguments()); - qApp->quit(); + if(configProvider->singleInstanceMode()) + { + this->lineEdit->setText(""); + hide(); + } + else + { + qApp->quit(); + } } QStringList Window::generatePATHSuggestions(const QString &text) @@ -154,7 +168,6 @@ void Window::clearGrid() auto item = grid->itemAt(0)->widget(); grid->removeWidget(item); item->setVisible(false); - } buttonsInGrid.clear(); } @@ -202,6 +215,7 @@ void Window::lineEditTextChanged(QString text) addCalcResult(input); return; } + } filterGridFor(text); @@ -338,6 +352,14 @@ EntryPushButton * Window::createEntryButton(const EntryConfig &entry) void Window::lineEditReturnPressed() { + if(this->lineEdit->text() == "/reload") + { + initFromConfig(); + this->lineEdit->setText(""); + return; + } + + if(buttonsInGrid.length() > 0 && this->lineEdit->text().length() > 0 ) { buttonClick(*buttonsInGrid[0]); diff --git a/window.h b/window.h index 9b68efb..310888e 100644 --- a/window.h +++ b/window.h @@ -33,11 +33,13 @@ #include "config.h" #include "entrypushbutton.h" #include "calculationengine.h" +#include "configprovider.h" class Window : public QWidget { Q_OBJECT private: + ConfigProvider *configProvider; CalculationEngine calcEngine; QString calculationresult; QVector userEntryButtons; @@ -47,6 +49,7 @@ class Window : public QWidget QString currentCalculationResult; QString queuedFileSearch; QString queuedContentSearch; + void initFromConfig(); void createGui(); void filterGridFor(QString filter); void populateGrid(const QVector &list); @@ -67,7 +70,7 @@ class Window : public QWidget void lineEditReturnPressed(); void showCalculationResultContextMenu(const QPoint &point); public: - Window(const QVector &userEntryButtons); + Window(ConfigProvider &configProvider); void setSystemConfig(const QVector &config); bool eventFilter(QObject *obj, QEvent *event); ~Window();