Implemented LunchMealDialog
This commit is contained in:
@@ -1,17 +1,51 @@
|
|||||||
#include "lunchmealdialog.h"
|
#include "lunchmealdialog.h"
|
||||||
#include "ui_lunchmealdialog.h"
|
#include "ui_lunchmealdialog.h"
|
||||||
|
|
||||||
|
#include <QDate>
|
||||||
|
#include <QNetworkAccessManager>
|
||||||
|
#include <QNetworkRequest>
|
||||||
|
#include <QUrl>
|
||||||
|
|
||||||
#include "stripswidget.h"
|
#include "stripswidget.h"
|
||||||
#include "mainwindow.h"
|
#include "mainwindow.h"
|
||||||
|
#include "zeiterfassungsettings.h"
|
||||||
|
#include "zeiterfassungapi.h"
|
||||||
|
|
||||||
LunchMealDialog::LunchMealDialog(StripsWidget &stripsWidget) :
|
LunchMealDialog::LunchMealDialog(StripsWidget &stripsWidget) :
|
||||||
QDialog(&stripsWidget.mainWindow()),
|
QDialog(&stripsWidget.mainWindow()),
|
||||||
ui(new Ui::LunchMealDialog)
|
ui(new Ui::LunchMealDialog)
|
||||||
{
|
{
|
||||||
ui->setupUi(this);
|
ui->setupUi(this);
|
||||||
|
|
||||||
|
ui->labelTitle->setText(tr("Lunch meal for %0").arg(stripsWidget.date().toString(tr("dd.MM.yyyy"))));
|
||||||
|
|
||||||
|
const auto &settings = stripsWidget.mainWindow().settings();
|
||||||
|
|
||||||
|
auto url = settings.value(QStringLiteral("LunchMealPlugin/url"),
|
||||||
|
QStringLiteral("https://brunner.ninja/lunch/%0.txt")).toString()
|
||||||
|
.arg(stripsWidget.date().toString(settings.value(QStringLiteral("LunchMealPlugin/dateFormat"),
|
||||||
|
QStringLiteral("yyyy-MM-dd")).toString()));
|
||||||
|
m_reply = std::unique_ptr<QNetworkReply>(stripsWidget.mainWindow().erfassung().manager()->get(QNetworkRequest(QUrl(url))));
|
||||||
|
connect(m_reply.get(), &QNetworkReply::finished, this, &LunchMealDialog::finished);
|
||||||
}
|
}
|
||||||
|
|
||||||
LunchMealDialog::~LunchMealDialog()
|
LunchMealDialog::~LunchMealDialog()
|
||||||
{
|
{
|
||||||
delete ui;
|
delete ui;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void LunchMealDialog::finished()
|
||||||
|
{
|
||||||
|
if(m_reply->error() != QNetworkReply::NoError)
|
||||||
|
{
|
||||||
|
ui->labelLunchMeal->setText(QStringLiteral("<span style=\"color: red;\">%0</span>\n\n%1")
|
||||||
|
.arg(m_reply->errorString())
|
||||||
|
.arg(QString(m_reply->readAll())));
|
||||||
|
goto after;
|
||||||
|
}
|
||||||
|
|
||||||
|
ui->labelLunchMeal->setText(m_reply->readAll());
|
||||||
|
|
||||||
|
after:
|
||||||
|
m_reply = Q_NULLPTR;
|
||||||
|
}
|
||||||
|
@@ -1,7 +1,10 @@
|
|||||||
#ifndef LUNCHMEALDIALOG_H
|
#ifndef LUNCHMEALDIALOG_H
|
||||||
#define LUNCHMEALDIALOG_H
|
#define LUNCHMEALDIALOG_H
|
||||||
|
|
||||||
|
#include <memory>
|
||||||
|
|
||||||
#include <QDialog>
|
#include <QDialog>
|
||||||
|
#include <QNetworkReply>
|
||||||
|
|
||||||
class StripsWidget;
|
class StripsWidget;
|
||||||
|
|
||||||
@@ -15,8 +18,12 @@ public:
|
|||||||
explicit LunchMealDialog(StripsWidget &stripsWidget);
|
explicit LunchMealDialog(StripsWidget &stripsWidget);
|
||||||
~LunchMealDialog();
|
~LunchMealDialog();
|
||||||
|
|
||||||
|
private Q_SLOTS:
|
||||||
|
void finished();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Ui::LunchMealDialog *ui;
|
Ui::LunchMealDialog *ui;
|
||||||
|
std::unique_ptr<QNetworkReply> m_reply;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // LUNCHMEALDIALOG_H
|
#endif // LUNCHMEALDIALOG_H
|
||||||
|
@@ -31,7 +31,7 @@
|
|||||||
<item>
|
<item>
|
||||||
<widget class="QLabel" name="labelLunchMeal">
|
<widget class="QLabel" name="labelLunchMeal">
|
||||||
<property name="text">
|
<property name="text">
|
||||||
<string notr="true">TextLabel</string>
|
<string>Loading...</string>
|
||||||
</property>
|
</property>
|
||||||
<property name="alignment">
|
<property name="alignment">
|
||||||
<set>Qt::AlignLeading|Qt::AlignLeft|Qt::AlignTop</set>
|
<set>Qt::AlignLeading|Qt::AlignLeft|Qt::AlignTop</set>
|
||||||
|
Reference in New Issue
Block a user