window: single instance handling + /reload command
This commit is contained in:
parent
84170a935d
commit
51b0337ceb
36
window.cpp
36
window.cpp
@ -13,7 +13,6 @@
|
|||||||
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
|
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
|
||||||
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||||
*/
|
*/
|
||||||
#include "window.h"
|
|
||||||
#include <QProcess>
|
#include <QProcess>
|
||||||
#include <QProcessEnvironment>
|
#include <QProcessEnvironment>
|
||||||
#include <QDirIterator>
|
#include <QDirIterator>
|
||||||
@ -26,11 +25,13 @@
|
|||||||
#include <QFileIconProvider>
|
#include <QFileIconProvider>
|
||||||
#include <QMenu>
|
#include <QMenu>
|
||||||
#include <QClipboard>
|
#include <QClipboard>
|
||||||
Window::Window(const QVector<EntryConfig> &configs)
|
#include "window.h"
|
||||||
|
#include "configprovider.h"
|
||||||
|
Window::Window(ConfigProvider &configProvider)
|
||||||
{
|
{
|
||||||
this->userEntryButtons = generateEntryButtons(configs);
|
this->configProvider = &configProvider;
|
||||||
createGui();
|
createGui();
|
||||||
populateGrid(this->userEntryButtons);
|
initFromConfig();
|
||||||
this->lineEdit->installEventFilter(this);
|
this->lineEdit->installEventFilter(this);
|
||||||
QFont font;
|
QFont font;
|
||||||
font.setPointSize(48);
|
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)
|
void Window::showCalculationResultContextMenu(const QPoint &point)
|
||||||
{
|
{
|
||||||
@ -100,7 +106,15 @@ void Window::populateGrid(const QVector<EntryPushButton *> &list)
|
|||||||
void Window::buttonClick(const EntryPushButton &config)
|
void Window::buttonClick(const EntryPushButton &config)
|
||||||
{
|
{
|
||||||
QProcess::startDetached(config.getCommand(), config.getArguments());
|
QProcess::startDetached(config.getCommand(), config.getArguments());
|
||||||
qApp->quit();
|
if(configProvider->singleInstanceMode())
|
||||||
|
{
|
||||||
|
this->lineEdit->setText("");
|
||||||
|
hide();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
qApp->quit();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
QStringList Window::generatePATHSuggestions(const QString &text)
|
QStringList Window::generatePATHSuggestions(const QString &text)
|
||||||
@ -154,7 +168,6 @@ void Window::clearGrid()
|
|||||||
auto item = grid->itemAt(0)->widget();
|
auto item = grid->itemAt(0)->widget();
|
||||||
grid->removeWidget(item);
|
grid->removeWidget(item);
|
||||||
item->setVisible(false);
|
item->setVisible(false);
|
||||||
|
|
||||||
}
|
}
|
||||||
buttonsInGrid.clear();
|
buttonsInGrid.clear();
|
||||||
}
|
}
|
||||||
@ -202,6 +215,7 @@ void Window::lineEditTextChanged(QString text)
|
|||||||
addCalcResult(input);
|
addCalcResult(input);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
filterGridFor(text);
|
filterGridFor(text);
|
||||||
@ -338,6 +352,14 @@ EntryPushButton * Window::createEntryButton(const EntryConfig &entry)
|
|||||||
|
|
||||||
void Window::lineEditReturnPressed()
|
void Window::lineEditReturnPressed()
|
||||||
{
|
{
|
||||||
|
if(this->lineEdit->text() == "/reload")
|
||||||
|
{
|
||||||
|
initFromConfig();
|
||||||
|
this->lineEdit->setText("");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
if(buttonsInGrid.length() > 0 && this->lineEdit->text().length() > 0 )
|
if(buttonsInGrid.length() > 0 && this->lineEdit->text().length() > 0 )
|
||||||
{
|
{
|
||||||
buttonClick(*buttonsInGrid[0]);
|
buttonClick(*buttonsInGrid[0]);
|
||||||
|
5
window.h
5
window.h
@ -33,11 +33,13 @@
|
|||||||
#include "config.h"
|
#include "config.h"
|
||||||
#include "entrypushbutton.h"
|
#include "entrypushbutton.h"
|
||||||
#include "calculationengine.h"
|
#include "calculationengine.h"
|
||||||
|
#include "configprovider.h"
|
||||||
|
|
||||||
class Window : public QWidget
|
class Window : public QWidget
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
private:
|
private:
|
||||||
|
ConfigProvider *configProvider;
|
||||||
CalculationEngine calcEngine;
|
CalculationEngine calcEngine;
|
||||||
QString calculationresult;
|
QString calculationresult;
|
||||||
QVector<EntryPushButton*> userEntryButtons;
|
QVector<EntryPushButton*> userEntryButtons;
|
||||||
@ -47,6 +49,7 @@ class Window : public QWidget
|
|||||||
QString currentCalculationResult;
|
QString currentCalculationResult;
|
||||||
QString queuedFileSearch;
|
QString queuedFileSearch;
|
||||||
QString queuedContentSearch;
|
QString queuedContentSearch;
|
||||||
|
void initFromConfig();
|
||||||
void createGui();
|
void createGui();
|
||||||
void filterGridFor(QString filter);
|
void filterGridFor(QString filter);
|
||||||
void populateGrid(const QVector<EntryPushButton *> &list);
|
void populateGrid(const QVector<EntryPushButton *> &list);
|
||||||
@ -67,7 +70,7 @@ class Window : public QWidget
|
|||||||
void lineEditReturnPressed();
|
void lineEditReturnPressed();
|
||||||
void showCalculationResultContextMenu(const QPoint &point);
|
void showCalculationResultContextMenu(const QPoint &point);
|
||||||
public:
|
public:
|
||||||
Window(const QVector<EntryConfig> &userEntryButtons);
|
Window(ConfigProvider &configProvider);
|
||||||
void setSystemConfig(const QVector<EntryConfig> &config);
|
void setSystemConfig(const QVector<EntryConfig> &config);
|
||||||
bool eventFilter(QObject *obj, QEvent *event);
|
bool eventFilter(QObject *obj, QEvent *event);
|
||||||
~Window();
|
~Window();
|
||||||
|
Loading…
Reference in New Issue
Block a user