diff --git a/reportswidget.cpp b/reportswidget.cpp index 30eba00..c846811 100644 --- a/reportswidget.cpp +++ b/reportswidget.cpp @@ -1,5 +1,6 @@ #include "reportswidget.h" +// Qt includes #include #include #include @@ -11,7 +12,13 @@ #include #include +// dbcorelib includes +#include "utils/timeutils.h" + +// zeiterfassungguilib includes #include "mainwindow.h" + +// zeiterfassungnetworklib includes #include "zeiterfassungapi.h" ReportsWidget::ReportsWidget(MainWindow &mainWindow) : @@ -47,7 +54,7 @@ void ReportsWidget::dateChanged(const QDate &date) return; } - auto monthBegin = QDate(date.year(), date.month(), 1); + const auto monthBegin = beginOfMonth(date); if(monthBegin != m_date) { m_date = monthBegin; @@ -65,6 +72,7 @@ void ReportsWidget::refresh() setText(tr("Balance: %0, Holidays: %1").arg(tr("???")).arg(tr("???"))); + m_content.clear(); m_actionRefreshReport->setEnabled(false); m_actionOpenReport->setEnabled(false); @@ -74,21 +82,15 @@ void ReportsWidget::refresh() void ReportsWidget::finished() { - if(!m_reply->success()) + if(m_reply->success()) { - m_date = QDate(); - QMessageBox::warning(this, tr("Could not load report!"), tr("Could not load report!") % "\n\n" % m_reply->message()); - goto after; - } - - { - auto content = m_reply->content(); + m_content = m_reply->content(); QString balance; { - static QRegularExpression regex(QStringLiteral("Gleitzeit +([0-9]+\\:[0-9]+\\-?) +([0-9]+\\:[0-9]+\\-?)")); - auto match = regex.match(content); + static const QRegularExpression regex(QStringLiteral("Gleitzeit +([0-9]+\\:[0-9]+\\-?) +([0-9]+\\:[0-9]+\\-?)")); + const auto match = regex.match(m_content); if(match.hasMatch()) { balance = match.captured(2); @@ -108,8 +110,8 @@ void ReportsWidget::finished() QString holidays; { - static QRegularExpression regex(QStringLiteral("Urlaubsanspruch +(\\-?[0-9]+\\.[0-9]+) +(\\-?[0-9]+\\.[0-9]+)")); - auto match = regex.match(content); + static const QRegularExpression regex(QStringLiteral("Urlaubsanspruch +(\\-?[0-9]+\\.[0-9]+) +(\\-?[0-9]+\\.[0-9]+)")); + const auto match = regex.match(m_content); if(match.hasMatch()) holidays = match.captured(2); else @@ -120,31 +122,33 @@ void ReportsWidget::finished() } setText(tr("Balance: %0, Holidays: %1").arg(balance).arg(holidays)); - - { - QTemporaryFile file(QDir::temp().absoluteFilePath(QStringLiteral("reportXXXXXX.pdf"))); - file.setAutoRemove(false); - if(!file.open()) - { - QMessageBox::warning(this, tr("Could not write report!"), tr("Could not write report!") % "\n\n" % file.errorString()); - goto after; - } - - file.write(content); - - m_url = QUrl::fromLocalFile(file.fileName()); - } + m_actionOpenReport->setEnabled(true); } + else + QMessageBox::warning(this, tr("Could not load report!"), tr("Could not load report!") % "\n\n" % m_reply->message()); - m_actionOpenReport->setEnabled(true); - - after: m_actionRefreshReport->setEnabled(true); m_reply = Q_NULLPTR; } void ReportsWidget::openReport() { - if(!QDesktopServices::openUrl(m_url)) + QUrl url; + + { + QTemporaryFile file(QDir::temp().absoluteFilePath(QStringLiteral("reportXXXXXX.pdf"))); + file.setAutoRemove(false); + if(!file.open()) + { + QMessageBox::warning(this, tr("Could not write report!"), tr("Could not write report!") % "\n\n" % file.errorString()); + return; + } + + file.write(m_content); + + url = QUrl::fromLocalFile(file.fileName()); + } + + if(!QDesktopServices::openUrl(url)) QMessageBox::warning(this, tr("Could not launch your default PDF viewer!"), tr("Could not launch your default PDF viewer!")); } diff --git a/reportswidget.h b/reportswidget.h index 46ad7d9..a256b71 100644 --- a/reportswidget.h +++ b/reportswidget.h @@ -2,7 +2,7 @@ #include #include -#include +#include #include "replies/getreportreply.h" @@ -30,7 +30,7 @@ private: QAction *m_actionRefreshReport; QDate m_date; - QUrl m_url; + QByteArray m_content; std::unique_ptr m_reply; }; diff --git a/translations/reportsplugin_de.ts b/translations/reportsplugin_de.ts index 14f8202..2cf555e 100644 --- a/translations/reportsplugin_de.ts +++ b/translations/reportsplugin_de.ts @@ -4,44 +4,44 @@ ReportsWidget - + Refresh report Auswertung aktualisieren - + Open report Auswertung öffnen - + ??? ??? - - + + Balance: %0, Holidays: %1 Gleitzeit: %0, Urlaub: %1 - + Could not load report! Konnte Auswertung nicht laden! - - + + n/a n/v - + Could not write report! Konnte Auswertung nicht abspeichern! - + Could not launch your default PDF viewer! Konnte Standard-PDF-Viewer nicht öffnen! diff --git a/translations/reportsplugin_en.ts b/translations/reportsplugin_en.ts index ffb6a03..c820a5a 100644 --- a/translations/reportsplugin_en.ts +++ b/translations/reportsplugin_en.ts @@ -4,44 +4,44 @@ ReportsWidget - + Refresh report - + Open report - + ??? - - + + Balance: %0, Holidays: %1 - + Could not load report! - - + + n/a - + Could not write report! - + Could not launch your default PDF viewer!