Refactoring to use new entryprovider and settingsprovider classes

This commit is contained in:
Albert S. 2020-09-06 19:43:17 +02:00
parent 2824f84f9f
commit 45d7b930f8
5 changed files with 33 additions and 30 deletions

View File

@ -18,7 +18,7 @@
#include <QWidget> #include <QWidget>
#include <QPushButton> #include <QPushButton>
#include "config.h" #include "entryprovider.h"
class EntryPushButton : public QPushButton class EntryPushButton : public QPushButton
{ {
Q_OBJECT Q_OBJECT
@ -44,8 +44,8 @@ public:
void setRow(int row); void setRow(int row);
void setCol(int col); void setCol(int col);
void setShortcutKey(QString key); void setShortcutKey(QString key);
}; };
#endif // ENTRYPUSHBUTTON_H #endif // ENTRYPUSHBUTTON_H

View File

@ -19,13 +19,12 @@
#include <QtConcurrent/QtConcurrentRun> #include <QtConcurrent/QtConcurrentRun>
#include <QSettings> #include <QSettings>
#include <QLocalSocket> #include <QLocalSocket>
#include "configprovider.h" #include <QDir>
#include "settingsprovider.h"
#include "entryprovider.h"
#include "window.h" #include "window.h"
#include "singleinstanceserver.h" #include "singleinstanceserver.h"
int main(int argc, char *argv[]) int main(int argc, char *argv[])
{ {
QApplication app(argc, argv); QApplication app(argc, argv);
@ -58,7 +57,8 @@ int main(int argc, char *argv[])
QSettings settings(configDirectoryPath + "qsrun.config", QSettings::NativeFormat); QSettings settings(configDirectoryPath + "qsrun.config", QSettings::NativeFormat);
ConfigProvider configProvider(configDirectoryPath, settings); SettingsProvider settingsProvider { settings };
EntryProvider entryProvider(settingsProvider.userEntriesPaths(), settingsProvider.systemApplicationsEntriesPaths());
//TODO if setting single instance mode //TODO if setting single instance mode
QLocalSocket localSocket; QLocalSocket localSocket;
localSocket.connectToServer("/tmp/qsrun.socket"); localSocket.connectToServer("/tmp/qsrun.socket");
@ -78,7 +78,7 @@ int main(int argc, char *argv[])
{ {
qDebug() << "Failed to listen on socket!"; qDebug() << "Failed to listen on socket!";
} }
Window *w = new Window { configProvider }; Window *w = new Window { entryProvider, settingsProvider };
QObject::connect(&server, &SingleInstanceServer::receivedMaximizationRequest, [&w]{ QObject::connect(&server, &SingleInstanceServer::receivedMaximizationRequest, [&w]{
if(w != nullptr) if(w != nullptr)
{ {

View File

@ -7,19 +7,21 @@ TARGET = qsrun
INCLUDEPATH += . INCLUDEPATH += .
# Input # Input
HEADERS += config.h window.h \ HEADERS += calculationengine.h \
entrypushbutton.h \ entryprovider.h \
calculationengine.h \ entrypushbutton.h \
singleinstanceserver.h \ settingsprovider.h \
configprovider.h singleinstanceserver.h \
SOURCES += config.cpp main.cpp window.cpp \ window.h
entrypushbutton.cpp \ SOURCES += calculationengine.cpp \
calculationengine.cpp \ entryprovider.cpp \
singleinstanceserver.cpp \ entrypushbutton.cpp \
configprovider.cpp main.cpp \
settingsprovider.cpp \
singleinstanceserver.cpp \
window.cpp
QT += widgets sql network QT += widgets sql network
QT_CONFIG -= no-pkg-config QT_CONFIG -= no-pkg-config
LIBS += -lcln LIBS += -lcln
CONFIG += link_pkgconfig CONFIG += link_pkgconfig
PKGCONFIG += libqalculate PKGCONFIG += libqalculate

View File

@ -28,10 +28,11 @@
#include <QClipboard> #include <QClipboard>
#include <QScrollArea> #include <QScrollArea>
#include "window.h" #include "window.h"
#include "configprovider.h" #include "entryprovider.h"
Window::Window(ConfigProvider &configProvider) Window::Window(EntryProvider &entryProvider, SettingsProvider &configProvider)
{ {
this->configProvider = &configProvider; this->entryProvider = &entryProvider;
this->settingsProvider = &configProvider;
createGui(); createGui();
initFromConfig(); initFromConfig();
this->lineEdit->installEventFilter(this); this->lineEdit->installEventFilter(this);
@ -55,8 +56,8 @@ void Window::initFromConfig()
{ {
try try
{ {
this->userEntryButtons = generateEntryButtons(configProvider->getUserEntries()); this->userEntryButtons = generateEntryButtons(entryProvider->getUserEntries());
this->systemEntryButtons = generateEntryButtons(configProvider->getSystemEntries()); this->systemEntryButtons = generateEntryButtons(entryProvider->getSystemEntries());
} }
catch(const ConfigFormatException &e) catch(const ConfigFormatException &e)
{ {
@ -124,7 +125,7 @@ void Window::buttonClick(const EntryPushButton &config)
void Window::closeWindow() void Window::closeWindow()
{ {
if(configProvider->singleInstanceMode()) if(settingsProvider->singleInstanceMode())
{ {
this->lineEdit->setText(""); this->lineEdit->setText("");
hide(); hide();

View File

@ -30,16 +30,16 @@
#include <QThread> #include <QThread>
#include <QTreeWidget> #include <QTreeWidget>
#include <QLabel> #include <QLabel>
#include "config.h"
#include "entrypushbutton.h" #include "entrypushbutton.h"
#include "calculationengine.h" #include "calculationengine.h"
#include "configprovider.h" #include "settingsprovider.h"
class Window : public QWidget class Window : public QWidget
{ {
Q_OBJECT Q_OBJECT
private: private:
ConfigProvider *configProvider; EntryProvider *entryProvider;
SettingsProvider *settingsProvider;
CalculationEngine calcEngine; CalculationEngine calcEngine;
QString calculationresult; QString calculationresult;
QVector<EntryPushButton*> userEntryButtons; QVector<EntryPushButton*> userEntryButtons;
@ -71,7 +71,7 @@ private slots:
void lineEditReturnPressed(); void lineEditReturnPressed();
void showCalculationResultContextMenu(const QPoint &point); void showCalculationResultContextMenu(const QPoint &point);
public: public:
Window(ConfigProvider &configProvider); Window(EntryProvider &entryProvider, SettingsProvider &settingsProvider);
void setSystemConfig(const QVector<EntryConfig> &config); void setSystemConfig(const QVector<EntryConfig> &config);
bool eventFilter(QObject *obj, QEvent *event); bool eventFilter(QObject *obj, QEvent *event);
void focusInput(); void focusInput();