Plugin settings (weather & lunch) #74
@@ -9,7 +9,7 @@
|
||||
#include "mainwindow.h"
|
||||
|
||||
#include "weatherwidget.h"
|
||||
#include "weathersettings.h"
|
||||
#include "weathersettingswidget.h"
|
||||
|
||||
WeatherPlugin::WeatherPlugin(QObject *parent) :
|
||||
ZeiterfassungPlugin(parent)
|
||||
@@ -38,5 +38,5 @@ void WeatherPlugin::attachTo(MainWindow &mainWindow)
|
||||
|
||||
SettingsWidget *WeatherPlugin::settingsWidget(ZeiterfassungSettings &settings, QWidget *parent) const
|
||||
{
|
||||
return new WeatherSettings(settings, parent);
|
||||
return new WeatherSettingsWidget(settings, parent);
|
||||
}
|
||||
|
@@ -18,10 +18,12 @@ DEFINES += QT_DEPRECATED_WARNINGS QT_DISABLE_DEPRECATED_BEFORE=0x060000 QT_MESSA
|
||||
|
||||
HEADERS += weatherplugin.h \
|
||||
weathersettings.h \
|
||||
weathersettingswidget.h \
|
||||
weatherwidget.h
|
||||
|
||||
SOURCES += weatherplugin.cpp \
|
||||
weathersettings.cpp \
|
||||
weathersettingswidget.cpp \
|
||||
weatherwidget.cpp
|
||||
|
||||
FORMS +=
|
||||
|
@@ -1,31 +1,21 @@
|
||||
#include "weathersettings.h"
|
||||
|
||||
#include <QFormLayout>
|
||||
#include <QLineEdit>
|
||||
#include <QDebug>
|
||||
#include "zeiterfassungsettings.h"
|
||||
|
||||
WeatherSettings::WeatherSettings(ZeiterfassungSettings &settings, QWidget *parent) :
|
||||
SettingsWidget(parent),
|
||||
WeatherSettings::WeatherSettings(ZeiterfassungSettings &settings) :
|
||||
m_settings(settings)
|
||||
{
|
||||
auto layout = new QFormLayout(this);
|
||||
layout->setMargin(0);
|
||||
|
||||
m_lineEdit = new QLineEdit(this);
|
||||
layout->addRow(tr("Weather API:"), m_lineEdit);
|
||||
|
||||
setLayout(layout);
|
||||
}
|
||||
|
||||
bool WeatherSettings::isValid(QString &message) const
|
||||
QUrl WeatherSettings::url() const
|
||||
{
|
||||
Q_UNUSED(message)
|
||||
|
||||
qDebug() << "called";
|
||||
return true;
|
||||
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::apply()
|
||||
void WeatherSettings::setUrl(const QUrl &url)
|
||||
{
|
||||
qDebug() << "called";
|
||||
m_settings.setValue(QStringLiteral("WeatherPlugin/url"), url);
|
||||
}
|
||||
|
@@ -1,27 +1,20 @@
|
||||
#ifndef WEATHERSETTINGS_H
|
||||
#define WEATHERSETTINGS_H
|
||||
|
||||
#include <QWidget>
|
||||
|
||||
#include "settingswidget.h"
|
||||
#include <QUrl>
|
||||
|
||||
class ZeiterfassungSettings;
|
||||
|
||||
class WeatherSettings : public SettingsWidget
|
||||
class WeatherSettings
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
explicit WeatherSettings(ZeiterfassungSettings &settings, QWidget *parent = Q_NULLPTR);
|
||||
WeatherSettings(ZeiterfassungSettings &settings);
|
||||
|
||||
bool isValid(QString &message) const Q_DECL_OVERRIDE;
|
||||
|
||||
public Q_SLOTS:
|
||||
void apply() Q_DECL_OVERRIDE;
|
||||
QUrl url() const;
|
||||
void setUrl(const QUrl &url);
|
||||
|
||||
private:
|
||||
ZeiterfassungSettings &m_settings;
|
||||
|
||||
QLineEdit *m_lineEdit;
|
||||
};
|
||||
|
||||
#endif // WEATHERSETTINGS_H
|
||||
|
31
plugins/weatherplugin/weathersettingswidget.cpp
Normal file
31
plugins/weatherplugin/weathersettingswidget.cpp
Normal file
@@ -0,0 +1,31 @@
|
||||
#include "weathersettingswidget.h"
|
||||
|
||||
#include <QFormLayout>
|
||||
#include <QLineEdit>
|
||||
#include <QDebug>
|
||||
|
||||
WeatherSettingsWidget::WeatherSettingsWidget(ZeiterfassungSettings &settings, QWidget *parent) :
|
||||
SettingsWidget(parent),
|
||||
m_settings(settings)
|
||||
{
|
||||
auto layout = new QFormLayout(this);
|
||||
layout->setMargin(0);
|
||||
|
||||
m_lineEdit = new QLineEdit(this);
|
||||
layout->addRow(tr("Weather API:"), m_lineEdit);
|
||||
|
||||
setLayout(layout);
|
||||
}
|
||||
|
||||
bool WeatherSettingsWidget::isValid(QString &message) const
|
||||
{
|
||||
Q_UNUSED(message)
|
||||
|
||||
qDebug() << "called";
|
||||
return true;
|
||||
}
|
||||
|
||||
void WeatherSettingsWidget::apply()
|
||||
{
|
||||
qDebug() << "called";
|
||||
}
|
29
plugins/weatherplugin/weathersettingswidget.h
Normal file
29
plugins/weatherplugin/weathersettingswidget.h
Normal file
@@ -0,0 +1,29 @@
|
||||
#ifndef WEATHERSETTINGS_H
|
||||
#define WEATHERSETTINGS_H
|
||||
|
||||
#include <QWidget>
|
||||
|
||||
#include "settingswidget.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:
|
||||
ZeiterfassungSettings &m_settings;
|
||||
|
||||
QLineEdit *m_lineEdit;
|
||||
};
|
||||
|
||||
#endif // WEATHERSETTINGS_H
|
@@ -14,6 +14,8 @@
|
||||
#include "zeiterfassungsettings.h"
|
||||
#include "zeiterfassungapi.h"
|
||||
|
||||
#include "weathersettings.h"
|
||||
|
||||
WeatherWidget::WeatherWidget(MainWindow &mainWindow) :
|
||||
QLabel(&mainWindow),
|
||||
m_mainWindow(mainWindow)
|
||||
@@ -30,10 +32,9 @@ void WeatherWidget::refresh()
|
||||
{
|
||||
setText(tr("Loading..."));
|
||||
|
||||
auto url = m_mainWindow.settings().value(QStringLiteral("WeatherPlugin/url"),
|
||||
QStringLiteral("http://api.openweathermap.org/data/2.5/weather?q=Graz,AT&units=metric&APPID=40f6c892c6162680c6c9235169dc9f83")).toString();
|
||||
auto url = WeatherSettings(m_mainWindow.settings()).url();
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user