diff --git a/plugins/lunchmealplugin/lunchmealdialog.cpp b/plugins/lunchmealplugin/lunchmealdialog.cpp index b4f2bc6..a61dd57 100644 --- a/plugins/lunchmealplugin/lunchmealdialog.cpp +++ b/plugins/lunchmealplugin/lunchmealdialog.cpp @@ -1,17 +1,51 @@ #include "lunchmealdialog.h" #include "ui_lunchmealdialog.h" +#include +#include +#include +#include + #include "stripswidget.h" #include "mainwindow.h" +#include "zeiterfassungsettings.h" +#include "zeiterfassungapi.h" LunchMealDialog::LunchMealDialog(StripsWidget &stripsWidget) : QDialog(&stripsWidget.mainWindow()), ui(new Ui::LunchMealDialog) { 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(stripsWidget.mainWindow().erfassung().manager()->get(QNetworkRequest(QUrl(url)))); + connect(m_reply.get(), &QNetworkReply::finished, this, &LunchMealDialog::finished); } LunchMealDialog::~LunchMealDialog() { delete ui; } + +void LunchMealDialog::finished() +{ + if(m_reply->error() != QNetworkReply::NoError) + { + ui->labelLunchMeal->setText(QStringLiteral("%0\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; +} diff --git a/plugins/lunchmealplugin/lunchmealdialog.h b/plugins/lunchmealplugin/lunchmealdialog.h index c5a2aff..9345fcf 100644 --- a/plugins/lunchmealplugin/lunchmealdialog.h +++ b/plugins/lunchmealplugin/lunchmealdialog.h @@ -1,7 +1,10 @@ #ifndef LUNCHMEALDIALOG_H #define LUNCHMEALDIALOG_H +#include + #include +#include class StripsWidget; @@ -15,8 +18,12 @@ public: explicit LunchMealDialog(StripsWidget &stripsWidget); ~LunchMealDialog(); +private Q_SLOTS: + void finished(); + private: Ui::LunchMealDialog *ui; + std::unique_ptr m_reply; }; #endif // LUNCHMEALDIALOG_H diff --git a/plugins/lunchmealplugin/lunchmealdialog.ui b/plugins/lunchmealplugin/lunchmealdialog.ui index de5ebfe..065c46b 100644 --- a/plugins/lunchmealplugin/lunchmealdialog.ui +++ b/plugins/lunchmealplugin/lunchmealdialog.ui @@ -31,7 +31,7 @@ - TextLabel + Loading... Qt::AlignLeading|Qt::AlignLeft|Qt::AlignTop