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