Plugin settings (weather & lunch) #74
@@ -10,6 +10,7 @@
|
|||||||
#include "stripswidget.h"
|
#include "stripswidget.h"
|
||||||
|
|
||||||
#include "lunchmealwidget.h"
|
#include "lunchmealwidget.h"
|
||||||
|
#include "lunchmealsettingswidget.h"
|
||||||
|
|
||||||
LunchMealPlugin::LunchMealPlugin(QObject *parent) :
|
LunchMealPlugin::LunchMealPlugin(QObject *parent) :
|
||||||
ZeiterfassungPlugin(parent)
|
ZeiterfassungPlugin(parent)
|
||||||
@@ -36,3 +37,8 @@ void LunchMealPlugin::attachTo(MainWindow &mainWindow)
|
|||||||
for(auto stripsWidget : mainWindow.stripsWidgets())
|
for(auto stripsWidget : mainWindow.stripsWidgets())
|
||||||
stripsWidget->headerLayout()->addWidget(new LunchMealWidget(*stripsWidget));
|
stripsWidget->headerLayout()->addWidget(new LunchMealWidget(*stripsWidget));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
SettingsWidget *LunchMealPlugin::settingsWidget(ZeiterfassungSettings &settings, QWidget *parent) const
|
||||||
|
{
|
||||||
|
return new LunchMealSettingsWidget(settings, parent);
|
||||||
|
}
|
||||||
|
@@ -19,6 +19,8 @@ public:
|
|||||||
// ZeiterfassungPlugin interface
|
// ZeiterfassungPlugin interface
|
||||||
void attachTo(MainWindow &mainWindow) Q_DECL_OVERRIDE;
|
void attachTo(MainWindow &mainWindow) Q_DECL_OVERRIDE;
|
||||||
|
|
||||||
|
virtual SettingsWidget *settingsWidget(ZeiterfassungSettings &settings, QWidget *parent = Q_NULLPTR) const Q_DECL_OVERRIDE;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
QTranslator m_translator;
|
QTranslator m_translator;
|
||||||
};
|
};
|
||||||
|
@@ -17,10 +17,14 @@ DEPENDPATH += $$PWD/$${PROJECT_ROOT}/zeiterfassungcorelib $$PWD/$${PROJECT_ROOT}
|
|||||||
DEFINES += QT_DEPRECATED_WARNINGS QT_DISABLE_DEPRECATED_BEFORE=0x060000 QT_MESSAGELOGCONTEXT
|
DEFINES += QT_DEPRECATED_WARNINGS QT_DISABLE_DEPRECATED_BEFORE=0x060000 QT_MESSAGELOGCONTEXT
|
||||||
|
|
||||||
HEADERS += lunchmealdialog.h \
|
HEADERS += lunchmealdialog.h \
|
||||||
|
lunchmealsettings.h \
|
||||||
|
lunchmealsettingswidget.h \
|
||||||
lunchmealplugin.h \
|
lunchmealplugin.h \
|
||||||
lunchmealwidget.h
|
lunchmealwidget.h
|
||||||
|
|
||||||
SOURCES += lunchmealdialog.cpp \
|
SOURCES += lunchmealdialog.cpp \
|
||||||
|
lunchmealsettings.cpp \
|
||||||
|
lunchmealsettingswidget.cpp \
|
||||||
lunchmealplugin.cpp \
|
lunchmealplugin.cpp \
|
||||||
lunchmealwidget.cpp
|
lunchmealwidget.cpp
|
||||||
|
|
||||||
|
31
plugins/lunchmealplugin/lunchmealsettings.cpp
Normal file
31
plugins/lunchmealplugin/lunchmealsettings.cpp
Normal file
@@ -0,0 +1,31 @@
|
|||||||
|
#include "lunchmealsettings.h"
|
||||||
|
|
||||||
|
#include "zeiterfassungsettings.h"
|
||||||
|
|
||||||
|
LunchMealSettings::LunchMealSettings(ZeiterfassungSettings &settings) :
|
||||||
|
m_settings(settings)
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
QUrl LunchMealSettings::url() const
|
||||||
|
{
|
||||||
|
return m_settings.value(QStringLiteral("LunchMealPlugin/url"),
|
||||||
|
QUrl(QStringLiteral("https://brunner.ninja/lunch/%0.txt")))
|
||||||
|
.toUrl();
|
||||||
|
}
|
||||||
|
|
||||||
|
void LunchMealSettings::setUrl(const QUrl &url)
|
||||||
|
{
|
||||||
|
m_settings.setValue(QStringLiteral("LunchMealPlugin/url"), url);
|
||||||
|
}
|
||||||
|
|
||||||
|
QString LunchMealSettings::dateFormat() const
|
||||||
|
{
|
||||||
|
return m_settings.value(QStringLiteral("LunchMealPlugin/dateFormat"), QStringLiteral("yyyy-MM-dd")).toString();
|
||||||
|
}
|
||||||
|
|
||||||
|
void LunchMealSettings::setDateFormat(const QString &dateFormat)
|
||||||
|
{
|
||||||
|
m_settings.setValue(QStringLiteral("LunchMealPlugin/dateFormat"), dateFormat);
|
||||||
|
}
|
23
plugins/lunchmealplugin/lunchmealsettings.h
Normal file
23
plugins/lunchmealplugin/lunchmealsettings.h
Normal file
@@ -0,0 +1,23 @@
|
|||||||
|
#ifndef LUNCHMEALSETTINGS_H
|
||||||
|
#define LUNCHMEALSETTINGS_H
|
||||||
|
|
||||||
|
#include <QUrl>
|
||||||
|
|
||||||
|
class ZeiterfassungSettings;
|
||||||
|
|
||||||
|
class LunchMealSettings
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
LunchMealSettings(ZeiterfassungSettings &settings);
|
||||||
|
|
||||||
|
QUrl url() const;
|
||||||
|
void setUrl(const QUrl &url);
|
||||||
|
|
||||||
|
QString dateFormat() const;
|
||||||
|
void setDateFormat(const QString &dateFormat);
|
||||||
|
|
||||||
|
private:
|
||||||
|
ZeiterfassungSettings &m_settings;
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif // LUNCHMEALSETTINGS_H
|
39
plugins/lunchmealplugin/lunchmealsettingswidget.cpp
Normal file
39
plugins/lunchmealplugin/lunchmealsettingswidget.cpp
Normal file
@@ -0,0 +1,39 @@
|
|||||||
|
#include "lunchmealsettingswidget.h"
|
||||||
|
|
||||||
|
#include <QFormLayout>
|
||||||
|
#include <QLineEdit>
|
||||||
|
|
||||||
|
LunchMealSettingsWidget::LunchMealSettingsWidget(ZeiterfassungSettings &settings, QWidget *parent) :
|
||||||
|
SettingsWidget(parent),
|
||||||
|
m_settings(settings)
|
||||||
|
{
|
||||||
|
auto layout = new QFormLayout(this);
|
||||||
|
layout->setMargin(0);
|
||||||
|
|
||||||
|
m_lineEditUrl = new QLineEdit(m_settings.url().toString(), this);
|
||||||
|
layout->addRow(tr("Lunch meal API:"), m_lineEditUrl);
|
||||||
|
|
||||||
|
m_lineEditDateFormat = new QLineEdit(m_settings.dateFormat(), this);
|
||||||
|
layout->addRow(tr("Lunch meal date format:"), m_lineEditDateFormat);
|
||||||
|
|
||||||
|
setLayout(layout);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool LunchMealSettingsWidget::isValid(QString &message) const
|
||||||
|
{
|
||||||
|
auto valid = QUrl::fromUserInput(m_lineEditUrl->text()).isValid();
|
||||||
|
|
||||||
|
if(!valid)
|
||||||
|
message = tr("The lunch meal api url is invalid!");
|
||||||
|
|
||||||
|
return valid;
|
||||||
|
}
|
||||||
|
|
||||||
|
void LunchMealSettingsWidget::apply()
|
||||||
|
{
|
||||||
|
auto url = QUrl::fromUserInput(m_lineEditUrl->text());
|
||||||
|
if(m_settings.url() != url)
|
||||||
|
m_settings.setUrl(url);
|
||||||
|
|
||||||
|
m_settings.setDateFormat(m_lineEditDateFormat->text());
|
||||||
|
}
|
29
plugins/lunchmealplugin/lunchmealsettingswidget.h
Normal file
29
plugins/lunchmealplugin/lunchmealsettingswidget.h
Normal file
@@ -0,0 +1,29 @@
|
|||||||
|
#ifndef LUNCHMEALSETTINGSWIDGET_H
|
||||||
|
#define LUNCHMEALSETTINGSWIDGET_H
|
||||||
|
|
||||||
|
#include "settingswidget.h"
|
||||||
|
|
||||||
|
#include "lunchmealsettings.h"
|
||||||
|
|
||||||
|
class QLineEdit;
|
||||||
|
|
||||||
|
class LunchMealSettingsWidget : public SettingsWidget
|
||||||
|
{
|
||||||
|
Q_OBJECT
|
||||||
|
|
||||||
|
public:
|
||||||
|
explicit LunchMealSettingsWidget(ZeiterfassungSettings &settings, QWidget *parent = Q_NULLPTR);
|
||||||
|
|
||||||
|
virtual bool isValid(QString &message) const Q_DECL_OVERRIDE;
|
||||||
|
|
||||||
|
public Q_SLOTS:
|
||||||
|
virtual void apply() Q_DECL_OVERRIDE;
|
||||||
|
|
||||||
|
private:
|
||||||
|
LunchMealSettings m_settings;
|
||||||
|
|
||||||
|
QLineEdit *m_lineEditUrl;
|
||||||
|
QLineEdit *m_lineEditDateFormat;
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif // LUNCHMEALSETTINGSWIDGET_H
|
@@ -9,10 +9,10 @@
|
|||||||
|
|
||||||
#include "stripswidget.h"
|
#include "stripswidget.h"
|
||||||
#include "mainwindow.h"
|
#include "mainwindow.h"
|
||||||
#include "zeiterfassungsettings.h"
|
|
||||||
#include "zeiterfassungapi.h"
|
#include "zeiterfassungapi.h"
|
||||||
|
|
||||||
#include "lunchmealdialog.h"
|
#include "lunchmealdialog.h"
|
||||||
|
#include "lunchmealsettings.h"
|
||||||
|
|
||||||
LunchMealWidget::LunchMealWidget(StripsWidget &stripsWidget) :
|
LunchMealWidget::LunchMealWidget(StripsWidget &stripsWidget) :
|
||||||
QToolButton(&stripsWidget),
|
QToolButton(&stripsWidget),
|
||||||
@@ -38,11 +38,9 @@ void LunchMealWidget::dateChanged(const QDate &date)
|
|||||||
setEnabled(false);
|
setEnabled(false);
|
||||||
setVisible(false);
|
setVisible(false);
|
||||||
|
|
||||||
const auto &settings = m_stripsWidget.mainWindow().settings();
|
LunchMealSettings settings(m_stripsWidget.mainWindow().settings());
|
||||||
|
|
||||||
auto url = settings.value(QStringLiteral("LunchMealPlugin/url"),
|
auto url = settings.url().toString().arg(date.toString(settings.dateFormat()));
|
||||||
QStringLiteral("https://brunner.ninja/lunch/%0.txt")).toString()
|
|
||||||
.arg(date.toString(settings.value(QStringLiteral("LunchMealPlugin/dateFormat"), QStringLiteral("yyyy-MM-dd")).toString()));
|
|
||||||
m_reply = std::unique_ptr<QNetworkReply>(m_stripsWidget.mainWindow().erfassung().manager()->get(QNetworkRequest(QUrl(url))));
|
m_reply = std::unique_ptr<QNetworkReply>(m_stripsWidget.mainWindow().erfassung().manager()->get(QNetworkRequest(QUrl(url))));
|
||||||
connect(m_reply.get(), &QNetworkReply::finished, this, &LunchMealWidget::finished);
|
connect(m_reply.get(), &QNetworkReply::finished, this, &LunchMealWidget::finished);
|
||||||
}
|
}
|
||||||
|
@@ -9,6 +9,7 @@
|
|||||||
#include "mainwindow.h"
|
#include "mainwindow.h"
|
||||||
|
|
||||||
#include "weatherwidget.h"
|
#include "weatherwidget.h"
|
||||||
|
#include "weathersettingswidget.h"
|
||||||
|
|
||||||
WeatherPlugin::WeatherPlugin(QObject *parent) :
|
WeatherPlugin::WeatherPlugin(QObject *parent) :
|
||||||
ZeiterfassungPlugin(parent)
|
ZeiterfassungPlugin(parent)
|
||||||
@@ -34,3 +35,8 @@ void WeatherPlugin::attachTo(MainWindow &mainWindow)
|
|||||||
{
|
{
|
||||||
mainWindow.statusBar()->addWidget(new WeatherWidget(mainWindow));
|
mainWindow.statusBar()->addWidget(new WeatherWidget(mainWindow));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
SettingsWidget *WeatherPlugin::settingsWidget(ZeiterfassungSettings &settings, QWidget *parent) const
|
||||||
|
{
|
||||||
|
return new WeatherSettingsWidget(settings, parent);
|
||||||
|
}
|
||||||
|
@@ -5,6 +5,9 @@
|
|||||||
|
|
||||||
#include "zeiterfassungplugin.h"
|
#include "zeiterfassungplugin.h"
|
||||||
|
|
||||||
|
class SettingsWidget;
|
||||||
|
class ZeiterfassungSettings;
|
||||||
|
|
||||||
class Q_DECL_EXPORT WeatherPlugin : public ZeiterfassungPlugin
|
class Q_DECL_EXPORT WeatherPlugin : public ZeiterfassungPlugin
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
@@ -17,6 +20,8 @@ public:
|
|||||||
// ZeiterfassungPlugin interface
|
// ZeiterfassungPlugin interface
|
||||||
void attachTo(MainWindow &mainWindow) Q_DECL_OVERRIDE;
|
void attachTo(MainWindow &mainWindow) Q_DECL_OVERRIDE;
|
||||||
|
|
||||||
|
SettingsWidget *settingsWidget(ZeiterfassungSettings &settings, QWidget *parent = Q_NULLPTR) const Q_DECL_OVERRIDE;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
QTranslator m_translator;
|
QTranslator m_translator;
|
||||||
};
|
};
|
||||||
|
@@ -17,9 +17,13 @@ DEPENDPATH += $$PWD/$${PROJECT_ROOT}/zeiterfassungcorelib $$PWD/$${PROJECT_ROOT}
|
|||||||
DEFINES += QT_DEPRECATED_WARNINGS QT_DISABLE_DEPRECATED_BEFORE=0x060000 QT_MESSAGELOGCONTEXT
|
DEFINES += QT_DEPRECATED_WARNINGS QT_DISABLE_DEPRECATED_BEFORE=0x060000 QT_MESSAGELOGCONTEXT
|
||||||
|
|
||||||
HEADERS += weatherplugin.h \
|
HEADERS += weatherplugin.h \
|
||||||
|
weathersettings.h \
|
||||||
|
weathersettingswidget.h \
|
||||||
weatherwidget.h
|
weatherwidget.h
|
||||||
|
|
||||||
SOURCES += weatherplugin.cpp \
|
SOURCES += weatherplugin.cpp \
|
||||||
|
weathersettings.cpp \
|
||||||
|
weathersettingswidget.cpp \
|
||||||
weatherwidget.cpp
|
weatherwidget.cpp
|
||||||
|
|
||||||
FORMS +=
|
FORMS +=
|
||||||
|
21
plugins/weatherplugin/weathersettings.cpp
Normal file
21
plugins/weatherplugin/weathersettings.cpp
Normal file
@@ -0,0 +1,21 @@
|
|||||||
|
#include "weathersettings.h"
|
||||||
|
|
||||||
|
#include "zeiterfassungsettings.h"
|
||||||
|
|
||||||
|
WeatherSettings::WeatherSettings(ZeiterfassungSettings &settings) :
|
||||||
|
m_settings(settings)
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
QUrl WeatherSettings::url() const
|
||||||
|
{
|
||||||
|
return m_settings.value(QStringLiteral("WeatherPlugin/url"),
|
||||||
|
QUrl(QStringLiteral("http://api.openweathermap.org/data/2.5/weather?q=Graz,AT&units=metric&APPID=40f6c892c6162680c6c9235169dc9f83")))
|
||||||
|
.toUrl();
|
||||||
|
}
|
||||||
|
|
||||||
|
void WeatherSettings::setUrl(const QUrl &url)
|
||||||
|
{
|
||||||
|
m_settings.setValue(QStringLiteral("WeatherPlugin/url"), url);
|
||||||
|
}
|
20
plugins/weatherplugin/weathersettings.h
Normal file
20
plugins/weatherplugin/weathersettings.h
Normal file
@@ -0,0 +1,20 @@
|
|||||||
|
#ifndef WEATHERSETTINGS_H
|
||||||
|
#define WEATHERSETTINGS_H
|
||||||
|
|
||||||
|
#include <QUrl>
|
||||||
|
|
||||||
|
class ZeiterfassungSettings;
|
||||||
|
|
||||||
|
class WeatherSettings
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
WeatherSettings(ZeiterfassungSettings &settings);
|
||||||
|
|
||||||
|
QUrl url() const;
|
||||||
|
void setUrl(const QUrl &url);
|
||||||
|
|
||||||
|
private:
|
||||||
|
ZeiterfassungSettings &m_settings;
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif // WEATHERSETTINGS_H
|
34
plugins/weatherplugin/weathersettingswidget.cpp
Normal file
34
plugins/weatherplugin/weathersettingswidget.cpp
Normal file
@@ -0,0 +1,34 @@
|
|||||||
|
#include "weathersettingswidget.h"
|
||||||
|
|
||||||
|
#include <QFormLayout>
|
||||||
|
#include <QLineEdit>
|
||||||
|
|
||||||
|
WeatherSettingsWidget::WeatherSettingsWidget(ZeiterfassungSettings &settings, QWidget *parent) :
|
||||||
|
SettingsWidget(parent),
|
||||||
|
m_settings(settings)
|
||||||
|
{
|
||||||
|
auto layout = new QFormLayout(this);
|
||||||
|
layout->setMargin(0);
|
||||||
|
|
||||||
|
m_lineEdit = new QLineEdit(m_settings.url().toString(), this);
|
||||||
|
layout->addRow(tr("Weather API:"), m_lineEdit);
|
||||||
|
|
||||||
|
setLayout(layout);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool WeatherSettingsWidget::isValid(QString &message) const
|
||||||
|
{
|
||||||
|
auto valid = QUrl::fromUserInput(m_lineEdit->text()).isValid();
|
||||||
|
|
||||||
|
if(!valid)
|
||||||
|
message = tr("The weather api url is invalid!");
|
||||||
|
|
||||||
|
return valid;
|
||||||
|
}
|
||||||
|
|
||||||
|
void WeatherSettingsWidget::apply()
|
||||||
|
{
|
||||||
|
auto url = QUrl::fromUserInput(m_lineEdit->text());
|
||||||
|
if(m_settings.url() != url)
|
||||||
|
m_settings.setUrl(url);
|
||||||
|
}
|
31
plugins/weatherplugin/weathersettingswidget.h
Normal file
31
plugins/weatherplugin/weathersettingswidget.h
Normal file
@@ -0,0 +1,31 @@
|
|||||||
|
#ifndef WEATHERSETTINGSWIDGET_H
|
||||||
|
#define WEATHERSETTINGSWIDGET_H
|
||||||
|
|
||||||
|
#include <QWidget>
|
||||||
|
|
||||||
|
#include "settingswidget.h"
|
||||||
|
|
||||||
|
#include "weathersettings.h"
|
||||||
|
|
||||||
|
class QLineEdit;
|
||||||
|
|
||||||
|
class ZeiterfassungSettings;
|
||||||
|
|
||||||
|
class WeatherSettingsWidget : public SettingsWidget
|
||||||
|
{
|
||||||
|
Q_OBJECT
|
||||||
|
public:
|
||||||
|
explicit WeatherSettingsWidget(ZeiterfassungSettings &settings, QWidget *parent = Q_NULLPTR);
|
||||||
|
|
||||||
|
bool isValid(QString &message) const Q_DECL_OVERRIDE;
|
||||||
|
|
||||||
|
public Q_SLOTS:
|
||||||
|
void apply() Q_DECL_OVERRIDE;
|
||||||
|
|
||||||
|
private:
|
||||||
|
WeatherSettings m_settings;
|
||||||
|
|
||||||
|
QLineEdit *m_lineEdit;
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif // WEATHERSETTINGSWIDGET_H
|
@@ -14,6 +14,8 @@
|
|||||||
#include "zeiterfassungsettings.h"
|
#include "zeiterfassungsettings.h"
|
||||||
#include "zeiterfassungapi.h"
|
#include "zeiterfassungapi.h"
|
||||||
|
|
||||||
|
#include "weathersettings.h"
|
||||||
|
|
||||||
WeatherWidget::WeatherWidget(MainWindow &mainWindow) :
|
WeatherWidget::WeatherWidget(MainWindow &mainWindow) :
|
||||||
QLabel(&mainWindow),
|
QLabel(&mainWindow),
|
||||||
m_mainWindow(mainWindow)
|
m_mainWindow(mainWindow)
|
||||||
@@ -30,10 +32,9 @@ void WeatherWidget::refresh()
|
|||||||
{
|
{
|
||||||
setText(tr("Loading..."));
|
setText(tr("Loading..."));
|
||||||
|
|
||||||
auto url = m_mainWindow.settings().value(QStringLiteral("WeatherPlugin/url"),
|
auto url = WeatherSettings(m_mainWindow.settings()).url();
|
||||||
QStringLiteral("http://api.openweathermap.org/data/2.5/weather?q=Graz,AT&units=metric&APPID=40f6c892c6162680c6c9235169dc9f83")).toString();
|
|
||||||
|
|
||||||
m_reply = std::unique_ptr<QNetworkReply>(m_mainWindow.erfassung().manager()->get(QNetworkRequest(QUrl(url))));
|
m_reply = std::unique_ptr<QNetworkReply>(m_mainWindow.erfassung().manager()->get(QNetworkRequest(url)));
|
||||||
connect(m_reply.get(), &QNetworkReply::finished, this, &WeatherWidget::finished);
|
connect(m_reply.get(), &QNetworkReply::finished, this, &WeatherWidget::finished);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -34,7 +34,7 @@ struct {
|
|||||||
QTranslator zeiterfassungguilibTranslator;
|
QTranslator zeiterfassungguilibTranslator;
|
||||||
} translators;
|
} translators;
|
||||||
|
|
||||||
QVector<std::shared_ptr<QPluginLoader> > pluginLoaders;
|
QSet<ZeiterfassungPlugin*> plugins;
|
||||||
|
|
||||||
bool loadAndInstallTranslator(QTranslator &translator, const QString &filename)
|
bool loadAndInstallTranslator(QTranslator &translator, const QString &filename)
|
||||||
{
|
{
|
||||||
@@ -280,17 +280,23 @@ bool loadPlugins(QSplashScreen &splashScreen)
|
|||||||
continue; // to skip windows junk files
|
continue; // to skip windows junk files
|
||||||
}
|
}
|
||||||
|
|
||||||
auto pluginLoader = std::make_shared<QPluginLoader>(fileInfo.filePath());
|
QPluginLoader pluginLoader(fileInfo.filePath());
|
||||||
if(!pluginLoader->load())
|
if(!pluginLoader.load())
|
||||||
{
|
{
|
||||||
QMessageBox::warning(&splashScreen, QCoreApplication::translate("main", "Could not load plugin %0!"),
|
QMessageBox::warning(&splashScreen, QCoreApplication::translate("main", "Could not load plugin %0!"),
|
||||||
QCoreApplication::translate("main", "Could not load plugin %0!").arg(fileInfo.fileName()) %
|
QCoreApplication::translate("main", "Could not load plugin %0!").arg(fileInfo.fileName()) %
|
||||||
"\n\n" % pluginLoader->errorString());
|
"\n\n" % pluginLoader.errorString());
|
||||||
ok = false;
|
ok = false;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
pluginLoaders.append(pluginLoader);
|
if(auto plugin = qobject_cast<ZeiterfassungPlugin*>(pluginLoader.instance()))
|
||||||
|
plugins.insert(plugin);
|
||||||
|
else
|
||||||
|
QMessageBox::warning(&splashScreen, QCoreApplication::translate("main", "Plugin not valid %0!"),
|
||||||
|
QCoreApplication::translate("main", "Plugin not valid %0!").arg(pluginLoader.fileName()) %
|
||||||
|
"\n\n" % pluginLoader.errorString());
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return ok;
|
return ok;
|
||||||
@@ -350,16 +356,11 @@ int main(int argc, char *argv[])
|
|||||||
|
|
||||||
loadPlugins(splashScreen);
|
loadPlugins(splashScreen);
|
||||||
|
|
||||||
MainWindow mainWindow(settings, erfassung, userInfo, stripFactory);
|
MainWindow mainWindow(settings, erfassung, userInfo, stripFactory, plugins);
|
||||||
splashScreen.finish(&mainWindow);
|
splashScreen.finish(&mainWindow);
|
||||||
|
|
||||||
for(auto &pluginLoader : pluginLoaders)
|
for(auto &plugin : plugins)
|
||||||
if(auto plugin = qobject_cast<ZeiterfassungPlugin*>(pluginLoader->instance()))
|
|
||||||
plugin->attachTo(mainWindow);
|
plugin->attachTo(mainWindow);
|
||||||
else
|
|
||||||
QMessageBox::warning(&splashScreen, QCoreApplication::translate("main", "Plugin not valid %0!"),
|
|
||||||
QCoreApplication::translate("main", "Plugin not valid %0!").arg(pluginLoader->fileName()) %
|
|
||||||
"\n\n" % pluginLoader->errorString());
|
|
||||||
|
|
||||||
mainWindow.show();
|
mainWindow.show();
|
||||||
|
|
||||||
|
@@ -5,12 +5,15 @@
|
|||||||
#include <QStringBuilder>
|
#include <QStringBuilder>
|
||||||
#include <QDir>
|
#include <QDir>
|
||||||
#include <QApplication>
|
#include <QApplication>
|
||||||
|
#include <QSet>
|
||||||
#include <QFile>
|
#include <QFile>
|
||||||
#include <QTextStream>
|
#include <QTextStream>
|
||||||
|
|
||||||
#include "zeiterfassungsettings.h"
|
#include "zeiterfassungsettings.h"
|
||||||
|
#include "zeiterfassungplugin.h"
|
||||||
|
#include "settingswidget.h"
|
||||||
|
|
||||||
SettingsDialog::SettingsDialog(ZeiterfassungSettings &settings, QWidget *parent) :
|
SettingsDialog::SettingsDialog(ZeiterfassungSettings &settings, const QSet<ZeiterfassungPlugin*> &plugins, QWidget *parent) :
|
||||||
ZeiterfassungDialog(parent),
|
ZeiterfassungDialog(parent),
|
||||||
ui(new Ui::SettingsDialog),
|
ui(new Ui::SettingsDialog),
|
||||||
m_settings(settings)
|
m_settings(settings)
|
||||||
@@ -21,7 +24,7 @@ SettingsDialog::SettingsDialog(ZeiterfassungSettings &settings, QWidget *parent)
|
|||||||
ui->comboBoxLanguage->addItem(tr("German"), QLocale::German);
|
ui->comboBoxLanguage->addItem(tr("German"), QLocale::German);
|
||||||
|
|
||||||
{
|
{
|
||||||
auto index = ui->comboBoxLanguage->findData(settings.language());
|
auto index = ui->comboBoxLanguage->findData(m_settings.language());
|
||||||
if(index == -1)
|
if(index == -1)
|
||||||
QMessageBox::warning(this, tr("Invalid settings!"), tr("Invalid settings!") % "\n\n" % tr("Unknown language!"));
|
QMessageBox::warning(this, tr("Invalid settings!"), tr("Invalid settings!") % "\n\n" % tr("Unknown language!"));
|
||||||
ui->comboBoxLanguage->setCurrentIndex(index);
|
ui->comboBoxLanguage->setCurrentIndex(index);
|
||||||
@@ -32,14 +35,24 @@ SettingsDialog::SettingsDialog(ZeiterfassungSettings &settings, QWidget *parent)
|
|||||||
for(const auto &entry : QDir(QDir(QCoreApplication::applicationDirPath()).absoluteFilePath(QStringLiteral("themes"))).entryInfoList(QStringList { QStringLiteral("*.qss") }, QDir::Files))
|
for(const auto &entry : QDir(QDir(QCoreApplication::applicationDirPath()).absoluteFilePath(QStringLiteral("themes"))).entryInfoList(QStringList { QStringLiteral("*.qss") }, QDir::Files))
|
||||||
ui->comboBoxTheme->addItem(entry.baseName(), entry.baseName());
|
ui->comboBoxTheme->addItem(entry.baseName(), entry.baseName());
|
||||||
|
|
||||||
if(!settings.theme().isEmpty())
|
if(!m_settings.theme().isEmpty())
|
||||||
{
|
{
|
||||||
auto index = ui->comboBoxTheme->findData(settings.theme());
|
auto index = ui->comboBoxTheme->findData(m_settings.theme());
|
||||||
if(index == -1)
|
if(index == -1)
|
||||||
QMessageBox::warning(this, tr("Invalid settings!"), tr("Invalid settings!") % "\n\n" % tr("Unknown theme!"));
|
QMessageBox::warning(this, tr("Invalid settings!"), tr("Invalid settings!") % "\n\n" % tr("Unknown theme!"));
|
||||||
ui->comboBoxTheme->setCurrentIndex(index);
|
ui->comboBoxTheme->setCurrentIndex(index);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
for(const auto plugin : plugins)
|
||||||
|
{
|
||||||
|
auto widget = plugin->settingsWidget(m_settings, this);
|
||||||
|
if(!widget)
|
||||||
|
continue;
|
||||||
|
|
||||||
|
ui->verticalLayout->addWidget(widget);
|
||||||
|
m_settingsWidgets.append(widget);
|
||||||
|
}
|
||||||
|
|
||||||
connect(ui->buttonBox, &QDialogButtonBox::accepted, this, &SettingsDialog::submit);
|
connect(ui->buttonBox, &QDialogButtonBox::accepted, this, &SettingsDialog::submit);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -50,8 +63,6 @@ SettingsDialog::~SettingsDialog()
|
|||||||
|
|
||||||
void SettingsDialog::submit()
|
void SettingsDialog::submit()
|
||||||
{
|
{
|
||||||
auto warning = false;
|
|
||||||
|
|
||||||
if(ui->comboBoxLanguage->currentIndex() == -1 ||
|
if(ui->comboBoxLanguage->currentIndex() == -1 ||
|
||||||
ui->comboBoxTheme->currentIndex() == -1)
|
ui->comboBoxTheme->currentIndex() == -1)
|
||||||
{
|
{
|
||||||
@@ -59,10 +70,21 @@ void SettingsDialog::submit()
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
for(const auto widget : m_settingsWidgets)
|
||||||
|
{
|
||||||
|
QString message;
|
||||||
|
if(!widget->isValid(message))
|
||||||
|
{
|
||||||
|
QMessageBox::warning(this, tr("Invalid settings!"), tr("Invalid settings!") % "\n\n" % message);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if(ui->comboBoxLanguage->currentData().value<QLocale::Language>() != m_settings.language())
|
if(ui->comboBoxLanguage->currentData().value<QLocale::Language>() != m_settings.language())
|
||||||
{
|
{
|
||||||
m_settings.setLanguage(ui->comboBoxLanguage->currentData().value<QLocale::Language>());
|
m_settings.setLanguage(ui->comboBoxLanguage->currentData().value<QLocale::Language>());
|
||||||
warning = true;
|
//TODO #73 Allow changing of the language without restart
|
||||||
|
QMessageBox::information(this, tr("Restart required!"), tr("To apply the new settings a restart is required!"));
|
||||||
}
|
}
|
||||||
|
|
||||||
auto theme = ui->comboBoxTheme->currentData().toString();
|
auto theme = ui->comboBoxTheme->currentData().toString();
|
||||||
@@ -95,8 +117,8 @@ void SettingsDialog::submit()
|
|||||||
m_settings.setTheme(theme);
|
m_settings.setTheme(theme);
|
||||||
}
|
}
|
||||||
|
|
||||||
if(warning)
|
for(const auto widget : m_settingsWidgets)
|
||||||
QMessageBox::information(this, tr("Restart required!"), tr("To apply the new settings a restart is required!"));
|
widget->apply();
|
||||||
|
|
||||||
accept();
|
accept();
|
||||||
}
|
}
|
||||||
|
@@ -3,15 +3,17 @@
|
|||||||
#include "zeiterfassungguilib_global.h"
|
#include "zeiterfassungguilib_global.h"
|
||||||
#include "zeiterfassungdialog.h"
|
#include "zeiterfassungdialog.h"
|
||||||
|
|
||||||
class ZeiterfassungSettings;
|
|
||||||
namespace Ui { class SettingsDialog; }
|
namespace Ui { class SettingsDialog; }
|
||||||
|
class ZeiterfassungSettings;
|
||||||
|
class ZeiterfassungPlugin;
|
||||||
|
class SettingsWidget;
|
||||||
|
|
||||||
class ZEITERFASSUNGGUILIBSHARED_EXPORT SettingsDialog : public ZeiterfassungDialog
|
class ZEITERFASSUNGGUILIBSHARED_EXPORT SettingsDialog : public ZeiterfassungDialog
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
|
||||||
public:
|
public:
|
||||||
explicit SettingsDialog(ZeiterfassungSettings &settings, QWidget *parent = Q_NULLPTR);
|
explicit SettingsDialog(ZeiterfassungSettings &settings, const QSet<ZeiterfassungPlugin*> &plugins, QWidget *parent = Q_NULLPTR);
|
||||||
~SettingsDialog();
|
~SettingsDialog();
|
||||||
|
|
||||||
private Q_SLOTS:
|
private Q_SLOTS:
|
||||||
@@ -20,4 +22,5 @@ private Q_SLOTS:
|
|||||||
private:
|
private:
|
||||||
Ui::SettingsDialog *ui;
|
Ui::SettingsDialog *ui;
|
||||||
ZeiterfassungSettings &m_settings;
|
ZeiterfassungSettings &m_settings;
|
||||||
|
QVector<SettingsWidget*> m_settingsWidgets;
|
||||||
};
|
};
|
||||||
|
@@ -6,8 +6,8 @@
|
|||||||
<rect>
|
<rect>
|
||||||
<x>0</x>
|
<x>0</x>
|
||||||
<y>0</y>
|
<y>0</y>
|
||||||
<width>647</width>
|
<width>340</width>
|
||||||
<height>162</height>
|
<height>164</height>
|
||||||
</rect>
|
</rect>
|
||||||
</property>
|
</property>
|
||||||
<property name="maximumSize">
|
<property name="maximumSize">
|
||||||
@@ -19,7 +19,7 @@
|
|||||||
<property name="windowTitle">
|
<property name="windowTitle">
|
||||||
<string>Settings</string>
|
<string>Settings</string>
|
||||||
</property>
|
</property>
|
||||||
<layout class="QVBoxLayout" name="verticalLayout" stretch="0,1,0">
|
<layout class="QVBoxLayout" stretch="0,0,0,0">
|
||||||
<item>
|
<item>
|
||||||
<widget class="QLabel" name="labelTitle">
|
<widget class="QLabel" name="labelTitle">
|
||||||
<property name="font">
|
<property name="font">
|
||||||
@@ -33,7 +33,9 @@
|
|||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
<item>
|
<item>
|
||||||
<layout class="QFormLayout" name="formLayout">
|
<layout class="QVBoxLayout" name="verticalLayout">
|
||||||
|
<item>
|
||||||
|
<layout class="QFormLayout">
|
||||||
<item row="0" column="0">
|
<item row="0" column="0">
|
||||||
<widget class="QLabel" name="labelLanguage">
|
<widget class="QLabel" name="labelLanguage">
|
||||||
<property name="text">
|
<property name="text">
|
||||||
@@ -62,6 +64,21 @@
|
|||||||
</item>
|
</item>
|
||||||
</layout>
|
</layout>
|
||||||
</item>
|
</item>
|
||||||
|
</layout>
|
||||||
|
</item>
|
||||||
|
<item>
|
||||||
|
<spacer name="verticalSpacer">
|
||||||
|
<property name="orientation">
|
||||||
|
<enum>Qt::Vertical</enum>
|
||||||
|
</property>
|
||||||
|
<property name="sizeHint" stdset="0">
|
||||||
|
<size>
|
||||||
|
<width>20</width>
|
||||||
|
<height>40</height>
|
||||||
|
</size>
|
||||||
|
</property>
|
||||||
|
</spacer>
|
||||||
|
</item>
|
||||||
<item>
|
<item>
|
||||||
<widget class="QDialogButtonBox" name="buttonBox">
|
<widget class="QDialogButtonBox" name="buttonBox">
|
||||||
<property name="orientation">
|
<property name="orientation">
|
||||||
|
@@ -28,13 +28,14 @@
|
|||||||
#include "replies/updatetimeassignmentreply.h"
|
#include "replies/updatetimeassignmentreply.h"
|
||||||
|
|
||||||
MainWindow::MainWindow(ZeiterfassungSettings &settings, ZeiterfassungApi &erfassung, const GetUserInfoReply::UserInfo &userInfo,
|
MainWindow::MainWindow(ZeiterfassungSettings &settings, ZeiterfassungApi &erfassung, const GetUserInfoReply::UserInfo &userInfo,
|
||||||
StripFactory &stripFactory, QWidget *parent) :
|
StripFactory &stripFactory, const QSet<ZeiterfassungPlugin*> &plugins, QWidget *parent) :
|
||||||
QMainWindow(parent),
|
QMainWindow(parent),
|
||||||
ui(new Ui::MainWindow),
|
ui(new Ui::MainWindow),
|
||||||
m_settings(settings),
|
m_settings(settings),
|
||||||
m_erfassung(erfassung),
|
m_erfassung(erfassung),
|
||||||
m_userInfo(userInfo),
|
m_userInfo(userInfo),
|
||||||
m_stripFactory(stripFactory),
|
m_stripFactory(stripFactory),
|
||||||
|
m_plugins(plugins),
|
||||||
m_currentStripWidget(Q_NULLPTR),
|
m_currentStripWidget(Q_NULLPTR),
|
||||||
m_timerId(-1)
|
m_timerId(-1)
|
||||||
{
|
{
|
||||||
@@ -49,7 +50,7 @@ MainWindow::MainWindow(ZeiterfassungSettings &settings, ZeiterfassungApi &erfass
|
|||||||
ui->actionRefresh->setShortcut(QKeySequence::Refresh);
|
ui->actionRefresh->setShortcut(QKeySequence::Refresh);
|
||||||
connect(ui->actionRefresh, &QAction::triggered, this, &MainWindow::refreshEverything);
|
connect(ui->actionRefresh, &QAction::triggered, this, &MainWindow::refreshEverything);
|
||||||
|
|
||||||
connect(ui->actionSettings, &QAction::triggered, this, [this](){ SettingsDialog(m_settings, this).exec(); });
|
connect(ui->actionSettings, &QAction::triggered, this, [this](){ SettingsDialog(m_settings, m_plugins, this).exec(); });
|
||||||
|
|
||||||
ui->actionHelp->setShortcut(QKeySequence::HelpContents);
|
ui->actionHelp->setShortcut(QKeySequence::HelpContents);
|
||||||
|
|
||||||
|
@@ -18,6 +18,7 @@ class QBoxLayout;
|
|||||||
namespace Ui { class MainWindow; }
|
namespace Ui { class MainWindow; }
|
||||||
class ZeiterfassungSettings;
|
class ZeiterfassungSettings;
|
||||||
class StripFactory;
|
class StripFactory;
|
||||||
|
class ZeiterfassungPlugin;
|
||||||
class StripsWidget;
|
class StripsWidget;
|
||||||
|
|
||||||
class ZEITERFASSUNGGUILIBSHARED_EXPORT MainWindow : public QMainWindow
|
class ZEITERFASSUNGGUILIBSHARED_EXPORT MainWindow : public QMainWindow
|
||||||
@@ -26,7 +27,7 @@ class ZEITERFASSUNGGUILIBSHARED_EXPORT MainWindow : public QMainWindow
|
|||||||
|
|
||||||
public:
|
public:
|
||||||
explicit MainWindow(ZeiterfassungSettings &settings, ZeiterfassungApi &erfassung, const GetUserInfoReply::UserInfo &userInfo,
|
explicit MainWindow(ZeiterfassungSettings &settings, ZeiterfassungApi &erfassung, const GetUserInfoReply::UserInfo &userInfo,
|
||||||
StripFactory &stripFactory, QWidget *parent = Q_NULLPTR);
|
StripFactory &stripFactory, const QSet<ZeiterfassungPlugin*> &plugins, QWidget *parent = Q_NULLPTR);
|
||||||
~MainWindow();
|
~MainWindow();
|
||||||
|
|
||||||
QMenu *menuFile() const;
|
QMenu *menuFile() const;
|
||||||
@@ -73,6 +74,7 @@ private:
|
|||||||
ZeiterfassungApi &m_erfassung;
|
ZeiterfassungApi &m_erfassung;
|
||||||
const GetUserInfoReply::UserInfo &m_userInfo;
|
const GetUserInfoReply::UserInfo &m_userInfo;
|
||||||
StripFactory &m_stripFactory;
|
StripFactory &m_stripFactory;
|
||||||
|
const QSet<ZeiterfassungPlugin*> &m_plugins;
|
||||||
|
|
||||||
std::unique_ptr<GetProjectsReply> m_getProjectsReply;
|
std::unique_ptr<GetProjectsReply> m_getProjectsReply;
|
||||||
|
|
||||||
|
6
zeiterfassungguilib/settingswidget.cpp
Normal file
6
zeiterfassungguilib/settingswidget.cpp
Normal file
@@ -0,0 +1,6 @@
|
|||||||
|
#include "settingswidget.h"
|
||||||
|
|
||||||
|
SettingsWidget::SettingsWidget(QWidget *parent) :
|
||||||
|
QWidget(parent)
|
||||||
|
{
|
||||||
|
}
|
21
zeiterfassungguilib/settingswidget.h
Normal file
21
zeiterfassungguilib/settingswidget.h
Normal file
@@ -0,0 +1,21 @@
|
|||||||
|
#ifndef SETTINGSWIDGET_H
|
||||||
|
#define SETTINGSWIDGET_H
|
||||||
|
|
||||||
|
#include <QObject>
|
||||||
|
#include <QWidget>
|
||||||
|
|
||||||
|
#include "zeiterfassungguilib_global.h"
|
||||||
|
|
||||||
|
class ZEITERFASSUNGGUILIBSHARED_EXPORT SettingsWidget : public QWidget
|
||||||
|
{
|
||||||
|
Q_OBJECT
|
||||||
|
public:
|
||||||
|
explicit SettingsWidget(QWidget *parent = Q_NULLPTR);
|
||||||
|
|
||||||
|
virtual bool isValid(QString &message) const { Q_UNUSED(message) return true; }
|
||||||
|
|
||||||
|
public Q_SLOTS:
|
||||||
|
virtual void apply() { }
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif // SETTINGSWIDGET_H
|
@@ -18,6 +18,7 @@ DEFINES += QT_DEPRECATED_WARNINGS QT_DISABLE_DEPRECATED_BEFORE=0x060000 QT_MESSA
|
|||||||
DEFINES += ZEITERFASSUNGGUILIB_LIBRARY
|
DEFINES += ZEITERFASSUNGGUILIB_LIBRARY
|
||||||
|
|
||||||
SOURCES += mainwindow.cpp \
|
SOURCES += mainwindow.cpp \
|
||||||
|
settingswidget.cpp \
|
||||||
stripfactory.cpp \
|
stripfactory.cpp \
|
||||||
stripswidget.cpp \
|
stripswidget.cpp \
|
||||||
zeiterfassungdialog.cpp \
|
zeiterfassungdialog.cpp \
|
||||||
@@ -27,6 +28,7 @@ SOURCES += mainwindow.cpp \
|
|||||||
dialogs/settingsdialog.cpp
|
dialogs/settingsdialog.cpp
|
||||||
|
|
||||||
HEADERS += mainwindow.h \
|
HEADERS += mainwindow.h \
|
||||||
|
settingswidget.h \
|
||||||
stripfactory.h \
|
stripfactory.h \
|
||||||
stripswidget.h \
|
stripswidget.h \
|
||||||
zeiterfassungguilib_global.h \
|
zeiterfassungguilib_global.h \
|
||||||
|
@@ -3,5 +3,11 @@
|
|||||||
ZeiterfassungPlugin::ZeiterfassungPlugin(QObject *parent) :
|
ZeiterfassungPlugin::ZeiterfassungPlugin(QObject *parent) :
|
||||||
QObject(parent)
|
QObject(parent)
|
||||||
{
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
SettingsWidget *ZeiterfassungPlugin::settingsWidget(ZeiterfassungSettings &settings, QWidget *parent) const
|
||||||
|
{
|
||||||
|
Q_UNUSED(settings)
|
||||||
|
Q_UNUSED(parent)
|
||||||
|
return Q_NULLPTR;
|
||||||
}
|
}
|
||||||
|
@@ -6,6 +6,8 @@
|
|||||||
|
|
||||||
class MainWindow;
|
class MainWindow;
|
||||||
class StripsWidget;
|
class StripsWidget;
|
||||||
|
class SettingsWidget;
|
||||||
|
class ZeiterfassungSettings;
|
||||||
|
|
||||||
class ZEITERFASSUNGGUILIBSHARED_EXPORT ZeiterfassungPlugin : public QObject
|
class ZEITERFASSUNGGUILIBSHARED_EXPORT ZeiterfassungPlugin : public QObject
|
||||||
{
|
{
|
||||||
@@ -15,6 +17,8 @@ public:
|
|||||||
explicit ZeiterfassungPlugin(QObject *parent = Q_NULLPTR);
|
explicit ZeiterfassungPlugin(QObject *parent = Q_NULLPTR);
|
||||||
|
|
||||||
virtual void attachTo(MainWindow &mainWindow) { Q_UNUSED(mainWindow) }
|
virtual void attachTo(MainWindow &mainWindow) { Q_UNUSED(mainWindow) }
|
||||||
|
|
||||||
|
virtual SettingsWidget *settingsWidget(ZeiterfassungSettings &settings, QWidget *parent = Q_NULLPTR) const;
|
||||||
};
|
};
|
||||||
|
|
||||||
Q_DECLARE_INTERFACE(ZeiterfassungPlugin, "dbsoftware.zeiterfassung.plugin/1.0")
|
Q_DECLARE_INTERFACE(ZeiterfassungPlugin, "dbsoftware.zeiterfassung.plugin/1.0")
|
||||||
|
Reference in New Issue
Block a user