Added LunchMealSettingsWrapper
This commit is contained in:
@@ -18,11 +18,13 @@ DEFINES += QT_DEPRECATED_WARNINGS QT_DISABLE_DEPRECATED_BEFORE=0x060000 QT_MESSA
|
|||||||
|
|
||||||
HEADERS += lunchmealdialog.h \
|
HEADERS += lunchmealdialog.h \
|
||||||
lunchmealplugin.h \
|
lunchmealplugin.h \
|
||||||
lunchmealwidget.h
|
lunchmealwidget.h \
|
||||||
|
lunchmealsettings.h
|
||||||
|
|
||||||
SOURCES += lunchmealdialog.cpp \
|
SOURCES += lunchmealdialog.cpp \
|
||||||
lunchmealplugin.cpp \
|
lunchmealplugin.cpp \
|
||||||
lunchmealwidget.cpp
|
lunchmealwidget.cpp \
|
||||||
|
lunchmealsettings.cpp
|
||||||
|
|
||||||
FORMS += lunchmealdialog.ui
|
FORMS += lunchmealdialog.ui
|
||||||
|
|
||||||
|
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
|
@@ -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);
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user