Fixed #42
This commit is contained in:
@@ -12,7 +12,7 @@ class LogDialog : public QDialog
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
explicit LogDialog(QWidget *parent = 0);
|
||||
explicit LogDialog(QWidget *parent = Q_NULLPTR);
|
||||
~LogDialog();
|
||||
|
||||
void setModel(QAbstractItemModel *model);
|
||||
|
@@ -2,17 +2,9 @@
|
||||
#include "ui_lunchmealdialog.h"
|
||||
|
||||
#include <QDate>
|
||||
#include <QNetworkAccessManager>
|
||||
#include <QNetworkRequest>
|
||||
#include <QUrl>
|
||||
|
||||
#include "stripswidget.h"
|
||||
#include "mainwindow.h"
|
||||
#include "zeiterfassungsettings.h"
|
||||
#include "zeiterfassungapi.h"
|
||||
|
||||
LunchMealDialog::LunchMealDialog(StripsWidget &stripsWidget) :
|
||||
QDialog(&stripsWidget.mainWindow()),
|
||||
LunchMealDialog::LunchMealDialog(const QDate &date, const QString &content, QWidget *parent) :
|
||||
QDialog(parent),
|
||||
ui(new Ui::LunchMealDialog)
|
||||
{
|
||||
ui->setupUi(this);
|
||||
@@ -23,35 +15,11 @@ LunchMealDialog::LunchMealDialog(StripsWidget &stripsWidget) :
|
||||
setWindowFlags(windowFlags() & ~Qt::WindowContextHelpButtonHint);
|
||||
#endif
|
||||
|
||||
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);
|
||||
ui->labelTitle->setText(tr("Lunch meal for %0").arg(date.toString(tr("dd.MM.yyyy"))));
|
||||
ui->labelLunchMeal->setText(content);
|
||||
}
|
||||
|
||||
LunchMealDialog::~LunchMealDialog()
|
||||
{
|
||||
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,9 +1,8 @@
|
||||
#pragma once
|
||||
|
||||
#include <memory>
|
||||
|
||||
#include <QDialog>
|
||||
#include <QNetworkReply>
|
||||
|
||||
class QDate;
|
||||
|
||||
class StripsWidget;
|
||||
|
||||
@@ -14,13 +13,9 @@ class LunchMealDialog : public QDialog
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
explicit LunchMealDialog(StripsWidget &stripsWidget);
|
||||
explicit LunchMealDialog(const QDate &date, const QString &content, QWidget *parent = Q_NULLPTR);
|
||||
~LunchMealDialog();
|
||||
|
||||
private Q_SLOTS:
|
||||
void finished();
|
||||
|
||||
private:
|
||||
Ui::LunchMealDialog *ui;
|
||||
std::unique_ptr<QNetworkReply> m_reply;
|
||||
};
|
||||
|
@@ -1,9 +1,15 @@
|
||||
#include "lunchmealwidget.h"
|
||||
|
||||
#include <QIcon>
|
||||
#include <QNetworkAccessManager>
|
||||
#include <QNetworkRequest>
|
||||
#include <QUrl>
|
||||
#include <QMessageBox>
|
||||
#include <QStringBuilder>
|
||||
|
||||
#include "stripswidget.h"
|
||||
#include "mainwindow.h"
|
||||
#include "zeiterfassungsettings.h"
|
||||
#include "zeiterfassungapi.h"
|
||||
|
||||
#include "lunchmealdialog.h"
|
||||
@@ -16,10 +22,50 @@ LunchMealWidget::LunchMealWidget(StripsWidget &stripsWidget) :
|
||||
setText(tr("Lunch meal"));
|
||||
|
||||
connect(this, &QAbstractButton::pressed, this, &LunchMealWidget::pressedSlot);
|
||||
|
||||
connect(&m_stripsWidget, &StripsWidget::dateChanged, this, &LunchMealWidget::dateChanged);
|
||||
dateChanged(m_stripsWidget.date());
|
||||
}
|
||||
|
||||
void LunchMealWidget::pressedSlot()
|
||||
{
|
||||
LunchMealDialog dialog(m_stripsWidget);
|
||||
LunchMealDialog dialog(m_stripsWidget.date(), m_content, &m_stripsWidget.mainWindow());
|
||||
dialog.exec();
|
||||
}
|
||||
|
||||
void LunchMealWidget::dateChanged(const QDate &date)
|
||||
{
|
||||
qDebug() << "called";
|
||||
|
||||
setEnabled(false);
|
||||
setVisible(false);
|
||||
|
||||
const auto &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()));
|
||||
m_reply = std::unique_ptr<QNetworkReply>(m_stripsWidget.mainWindow().erfassung().manager()->get(QNetworkRequest(QUrl(url))));
|
||||
connect(m_reply.get(), &QNetworkReply::finished, this, &LunchMealWidget::finished);
|
||||
}
|
||||
|
||||
void LunchMealWidget::finished()
|
||||
{
|
||||
if(m_reply->error() != QNetworkReply::NoError &&
|
||||
m_reply->error() != QNetworkReply::ContentNotFoundError)
|
||||
{
|
||||
QMessageBox::warning(&m_stripsWidget.mainWindow(), tr("Could not load lunch meal!"),
|
||||
tr("Could not load lunch meal!") % "\n\n" % m_reply->errorString());
|
||||
goto after;
|
||||
}
|
||||
|
||||
if(m_reply->error() == QNetworkReply::NoError)
|
||||
{
|
||||
setEnabled(true);
|
||||
setVisible(true);
|
||||
m_content = m_reply->readAll();
|
||||
}
|
||||
|
||||
after:
|
||||
m_reply = Q_NULLPTR;
|
||||
}
|
||||
|
@@ -1,6 +1,9 @@
|
||||
#pragma once
|
||||
|
||||
#include <memory>
|
||||
|
||||
#include <QToolButton>
|
||||
#include <QNetworkReply>
|
||||
|
||||
class StripsWidget;
|
||||
|
||||
@@ -12,7 +15,11 @@ public:
|
||||
|
||||
private Q_SLOTS:
|
||||
void pressedSlot();
|
||||
void dateChanged(const QDate &date);
|
||||
void finished();
|
||||
|
||||
private:
|
||||
StripsWidget &m_stripsWidget;
|
||||
std::unique_ptr<QNetworkReply> m_reply;
|
||||
QString m_content;
|
||||
};
|
||||
|
Reference in New Issue
Block a user