Plugin settings (weather & lunch) #74

Merged
0xFEEDC0DE64 merged 15 commits from plugin-settings into master 2018-03-13 08:35:57 +01:00
23 changed files with 327 additions and 67 deletions
Showing only changes of commit 245c05a045 - Show all commits

View File

@@ -18,11 +18,13 @@ DEFINES += QT_DEPRECATED_WARNINGS QT_DISABLE_DEPRECATED_BEFORE=0x060000 QT_MESSA
HEADERS += lunchmealdialog.h \
lunchmealplugin.h \
lunchmealwidget.h
lunchmealwidget.h \
lunchmealsettings.h
SOURCES += lunchmealdialog.cpp \
lunchmealplugin.cpp \
lunchmealwidget.cpp
lunchmealwidget.cpp \
lunchmealsettings.cpp
FORMS += lunchmealdialog.ui

View 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);
}

View 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

View File

@@ -9,10 +9,10 @@
#include "stripswidget.h"
#include "mainwindow.h"
#include "zeiterfassungsettings.h"
#include "zeiterfassungapi.h"
#include "lunchmealdialog.h"
#include "lunchmealsettings.h"
LunchMealWidget::LunchMealWidget(StripsWidget &stripsWidget) :
QToolButton(&stripsWidget),
@@ -38,11 +38,9 @@ void LunchMealWidget::dateChanged(const QDate &date)
setEnabled(false);
setVisible(false);
const auto &settings = m_stripsWidget.mainWindow().settings();
LunchMealSettings settings(m_stripsWidget.mainWindow().settings());
auto url = settings.value(QStringLiteral("LunchMealPlugin/url"),
QStringLiteral("https://brunner.ninja/lunch/%0.txt")).toString()
.arg(date.toString(settings.value(QStringLiteral("LunchMealPlugin/dateFormat"), QStringLiteral("yyyy-MM-dd")).toString()));
auto url = settings.url().toString().arg(date.toString(settings.dateFormat()));
m_reply = std::unique_ptr<QNetworkReply>(m_stripsWidget.mainWindow().erfassung().manager()->get(QNetworkRequest(QUrl(url))));
connect(m_reply.get(), &QNetworkReply::finished, this, &LunchMealWidget::finished);
}