diff --git a/plugins/presenceplugin/presenceplugin.cpp b/plugins/presenceplugin/presenceplugin.cpp index 0560bb6..790c36e 100644 --- a/plugins/presenceplugin/presenceplugin.cpp +++ b/plugins/presenceplugin/presenceplugin.cpp @@ -2,7 +2,6 @@ #include -#include "mainwindow.h" #include "presencewidget.h" PresencePlugin::PresencePlugin(QObject *parent) : diff --git a/plugins/presenceplugin/presencewidget.h b/plugins/presenceplugin/presencewidget.h index b01b179..90d2433 100644 --- a/plugins/presenceplugin/presencewidget.h +++ b/plugins/presenceplugin/presencewidget.h @@ -13,6 +13,7 @@ class MainWindow; class PresenceWidget : public QWidget { Q_OBJECT + public: explicit PresenceWidget(MainWindow &mainWindow); diff --git a/plugins/reportsplugin/images/refresh.png b/plugins/reportsplugin/images/refresh.png new file mode 100644 index 0000000..f3585b7 Binary files /dev/null and b/plugins/reportsplugin/images/refresh.png differ diff --git a/zeiterfassunglib/images/auswertung.png b/plugins/reportsplugin/images/report.png similarity index 100% rename from zeiterfassunglib/images/auswertung.png rename to plugins/reportsplugin/images/report.png diff --git a/plugins/reportsplugin/reportsplugin.cpp b/plugins/reportsplugin/reportsplugin.cpp index b8ddf29..ea8d0fa 100644 --- a/plugins/reportsplugin/reportsplugin.cpp +++ b/plugins/reportsplugin/reportsplugin.cpp @@ -2,6 +2,8 @@ #include +#include "reportswidget.h" + ReportsPlugin::ReportsPlugin(QObject *parent) : ZeiterfassungPlugin(parent) { @@ -10,4 +12,5 @@ ReportsPlugin::ReportsPlugin(QObject *parent) : void ReportsPlugin::attachTo(MainWindow &mainWindow) { + new ReportsWidget(mainWindow); } diff --git a/plugins/reportsplugin/reportsplugin.pro b/plugins/reportsplugin/reportsplugin.pro index 4673528..a299f62 100644 --- a/plugins/reportsplugin/reportsplugin.pro +++ b/plugins/reportsplugin/reportsplugin.pro @@ -14,13 +14,15 @@ DEPENDPATH += $$PWD/../../zeiterfassunglib DEFINES += QT_DEPRECATED_WARNINGS QT_DISABLE_DEPRECATED_BEFORE=0x060000 QT_MESSAGELOGCONTEXT -HEADERS += reportsplugin.h +HEADERS += reportsplugin.h \ + reportswidget.h -SOURCES += reportsplugin.cpp +SOURCES += reportsplugin.cpp \ + reportswidget.cpp FORMS += -RESOURCES += +RESOURCES += reportsplugin_resources.qrc TRANSLATIONS += diff --git a/plugins/reportsplugin/reportsplugin_resources.qrc b/plugins/reportsplugin/reportsplugin_resources.qrc new file mode 100644 index 0000000..acd4367 --- /dev/null +++ b/plugins/reportsplugin/reportsplugin_resources.qrc @@ -0,0 +1,6 @@ + + + images/refresh.png + images/report.png + + diff --git a/plugins/reportsplugin/reportswidget.cpp b/plugins/reportsplugin/reportswidget.cpp new file mode 100644 index 0000000..ad045e3 --- /dev/null +++ b/plugins/reportsplugin/reportswidget.cpp @@ -0,0 +1,145 @@ +#include "reportswidget.h" + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include "mainwindow.h" +#include "zeiterfassungapi.h" + +ReportsWidget::ReportsWidget(MainWindow &mainWindow) : + QWidget(&mainWindow), + m_mainWindow(mainWindow) +{ + m_labelBalance = new QLabel(this); + m_labelBalance->setFrameShape(QFrame::Panel); + m_labelBalance->setFrameShadow(QFrame::Sunken); + m_mainWindow.statusBar()->addPermanentWidget(m_labelBalance); + + m_labelHolidays = new QLabel(this); + m_labelHolidays->setFrameShape(QFrame::Panel); + m_labelHolidays->setFrameShadow(QFrame::Sunken); + m_mainWindow.statusBar()->addPermanentWidget(m_labelHolidays); + + m_actionRefreshReport = m_mainWindow.menuView()->addAction(QIcon(QStringLiteral(":/zeiterfassung/plugins/reportsplugin/images/refresh.png")), + tr("Refresh report"), this, &ReportsWidget::refresh); + + m_actionOpenReport = m_mainWindow.menuTools()->addAction(QIcon(QStringLiteral(":/zeiterfassung/plugins/reportsplugin/images/report.png")), + tr("Open report"), this, &ReportsWidget::openReport); + m_mainWindow.toolBar()->addAction(m_actionOpenReport); + + dateChanged(m_mainWindow.date()); +} + +void ReportsWidget::dateChanged(const QDate &date) +{ + if(!date.isValid()) + { + qWarning() << "invalid date" << date; + return; + } + + auto monthBegin = QDate(date.year(), date.month(), 1); + if(monthBegin != m_date) + { + m_date = monthBegin; + refresh(); + } +} + +void ReportsWidget::refresh() +{ + if(!m_date.isValid()) + { + qWarning() << "invalid date" << m_date; + return; + } + + m_actionRefreshReport->setEnabled(false); + m_actionOpenReport->setEnabled(false); + + m_labelBalance->setText(tr("%0: %1").arg(tr("Balance")).arg(tr("???"))); + m_labelHolidays->setText(tr("%0: %1").arg(tr("Holidays")).arg(tr("???"))); + + m_reply = m_mainWindow.erfassung().doGetAuswertung(m_mainWindow.userInfo().userId, m_date); + connect(m_reply.get(), &ZeiterfassungReply::finished, this, &ReportsWidget::finished); +} + +void ReportsWidget::finished() +{ + 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->auswertung(); + + { + static QRegularExpression regex(QStringLiteral("Gleitzeit +([0-9]+\\:[0-9]+\\-?) +([0-9]+\\:[0-9]+\\-?)")); + auto match = regex.match(content); + if(match.hasMatch()) + { + auto balance = match.captured(2); + if(balance.endsWith(QChar('-'))) + { + balance.chop(1); + balance = QChar('-') % balance; + } + m_labelBalance->setText(tr("%0: %1").arg(tr("Balance")).arg(tr("%0h").arg(balance))); + } + else + { + m_labelBalance->setText(tr("%0: %1").arg(tr("Balance")).arg(tr("n/a"))); + qWarning() << "balance not found in PDF"; + } + } + + { + static QRegularExpression regex(QStringLiteral("Urlaubsanspruch +([0-9]+\\.[0-9]+\\-?) +([0-9]+\\.[0-9]+\\-?)")); + auto match = regex.match(content); + if(match.hasMatch()) + m_labelHolidays->setText(tr("%0: %1").arg(tr("Holidays")).arg(match.captured(2))); + else + { + m_labelHolidays->setText(tr("%0: %1").arg(tr("Holidays")).arg(tr("n/a"))); + qWarning() << "holidays not found in PDF"; + } + } + + { + QTemporaryFile file(QDir::temp().absoluteFilePath(QStringLiteral("auswertungXXXXXX.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); + + after: + m_actionRefreshReport->setEnabled(true); + m_reply = Q_NULLPTR; +} + +void ReportsWidget::openReport() +{ + if(!QDesktopServices::openUrl(m_url)) + QMessageBox::warning(this, tr("Could not launch your default PDF viewer!"), tr("Could not launch your default PDF viewer!")); +} diff --git a/plugins/reportsplugin/reportswidget.h b/plugins/reportsplugin/reportswidget.h new file mode 100644 index 0000000..bfe59c2 --- /dev/null +++ b/plugins/reportsplugin/reportswidget.h @@ -0,0 +1,43 @@ +#ifndef REPORTSWIDGET_H +#define REPORTSWIDGET_H + +#include +#include +#include + +#include "replies/getauswertungreply.h" + +class QLabel; +class QAction; + +class MainWindow; + +class ReportsWidget : public QWidget +{ + Q_OBJECT + +public: + explicit ReportsWidget(MainWindow &mainWindow); + +private Q_SLOTS: + void dateChanged(const QDate &date); + void refresh(); + void finished(); + void openReport(); + +private: + MainWindow &m_mainWindow; + + QLabel *m_labelBalance; + QLabel *m_labelHolidays; + + QAction *m_actionOpenReport; + QAction *m_actionRefreshReport; + + QDate m_date; + QUrl m_url; + + std::unique_ptr m_reply; +}; + +#endif // REPORTSWIDGET_H diff --git a/zeiterfassunglib/mainwindow.cpp b/zeiterfassunglib/mainwindow.cpp index 9d52cd9..b4612ed 100644 --- a/zeiterfassunglib/mainwindow.cpp +++ b/zeiterfassunglib/mainwindow.cpp @@ -22,7 +22,6 @@ #include "dialogs/aboutmedialog.h" #include "dialogs/settingsdialog.h" #include "replies/getprojectsreply.h" -#include "replies/getauswertungreply.h" #include "replies/createbookingreply.h" #include "replies/createtimeassignmentreply.h" #include "replies/updatetimeassignmentreply.h" @@ -35,8 +34,6 @@ MainWindow::MainWindow(ZeiterfassungSettings &settings, ZeiterfassungApi &erfass m_erfassung(erfassung), m_userInfo(userInfo), m_stripFactory(stripFactory), - m_getProjectsReply(Q_NULLPTR), - m_getAuswertungReply(Q_NULLPTR), m_currentStripWidget(Q_NULLPTR) { ui->setupUi(this); @@ -57,8 +54,6 @@ MainWindow::MainWindow(ZeiterfassungSettings &settings, ZeiterfassungApi &erfass ui->actionRefresh->setShortcut(QKeySequence::Refresh); connect(ui->actionRefresh, &QAction::triggered, this, [=](){ dateChanged(true); }); - connect(ui->actionAuswertung, &QAction::triggered, this, &MainWindow::openAuswertung); - connect(ui->actionAboutMe, &QAction::triggered, [=](){ AboutMeDialog(userInfo, this).exec(); }); connect(ui->actionSettings, &QAction::triggered, [=](){ SettingsDialog(m_settings, this).exec(); }); @@ -88,13 +83,6 @@ MainWindow::MainWindow(ZeiterfassungSettings &settings, ZeiterfassungApi &erfass connect(ui->pushButtonStart, &QAbstractButton::pressed, this, &MainWindow::pushButtonStartPressed); connect(ui->pushButtonEnd, &QAbstractButton::pressed, this, &MainWindow::pushButtonEndPressed); - ui->statusbar->addPermanentWidget(m_balanceLabel = new QLabel(ui->statusbar)); - m_balanceLabel->setFrameShape(QFrame::Panel); - m_balanceLabel->setFrameShadow(QFrame::Sunken); - ui->statusbar->addPermanentWidget(m_holidaysLabel = new QLabel(ui->statusbar)); - m_holidaysLabel->setFrameShape(QFrame::Panel); - m_holidaysLabel->setFrameShadow(QFrame::Sunken); - dateChanged(); } @@ -123,6 +111,11 @@ QMenu *MainWindow::menuAbout() const return ui->menuAbout; } +QToolBar *MainWindow::toolBar() const +{ + return ui->mainToolBar; +} + ZeiterfassungSettings &MainWindow::settings() const { return m_settings; @@ -143,6 +136,11 @@ StripFactory &MainWindow::stripFactory() const return m_stripFactory; } +QDate MainWindow::date() const +{ + return ui->dateEditDate->date(); +} + const QMap &MainWindow::projects() const { return m_projects; @@ -171,66 +169,6 @@ void MainWindow::getProjectsFinished() m_getProjectsReply = Q_NULLPTR; } -void MainWindow::getAuswertungFinished() -{ - if(std::none_of(std::begin(m_stripsWidgets), std::end(m_stripsWidgets), [](StripsWidget *stripsWidget){ - return stripsWidget->refreshing(); - })) - { - ui->actionToday->setEnabled(true); - ui->actionRefresh->setEnabled(true); - ui->dateEditDate->setReadOnly(false); - ui->pushButtonPrev->setEnabled(true); - ui->pushButtonNext->setEnabled(true); - } - - if(!m_getAuswertungReply->success()) - { - m_auswertungDate = QDate(); - QMessageBox::warning(this, tr("Could not load Auswertung!"), tr("Could not load Auswertung!") % "\n\n" % m_getAuswertungReply->message()); - m_getAuswertungReply = Q_NULLPTR; - return; - } - - ui->actionAuswertung->setEnabled(true); - m_auswertung = m_getAuswertungReply->auswertung(); - - auto urlaubsAnspruch = tr("n/a"); - - { - static QRegularExpression regex(QStringLiteral("Urlaubsanspruch +([0-9]+\\.[0-9]+\\-?) +([0-9]+\\.[0-9]+\\-?)")); - auto match = regex.match(m_auswertung); - if(match.hasMatch()) - urlaubsAnspruch = match.captured(2); - else - qWarning() << "Urlaubsanspruch not found"; - } - - auto gleitzeit = tr("n/a"); - - { - static QRegularExpression regex(QStringLiteral("Gleitzeit +([0-9]+\\:[0-9]+\\-?) +([0-9]+\\:[0-9]+\\-?)")); - auto match = regex.match(m_auswertung); - if(match.hasMatch()) - { - gleitzeit = match.captured(2); - if(gleitzeit.endsWith(QChar('-'))) - { - gleitzeit.chop(1); - gleitzeit = QChar('-') % gleitzeit; - } - gleitzeit = tr("%0h").arg(gleitzeit); - } - else - qWarning() << "Gleitzeit not found"; - } - - m_balanceLabel->setText(tr("%0: %1").arg(tr("Balance")).arg(gleitzeit)); - m_holidaysLabel->setText(tr("%0: %1").arg(tr("Holidays")).arg(urlaubsAnspruch)); - - m_getAuswertungReply = Q_NULLPTR; -} - void MainWindow::pushButtonStartPressed() { auto bookingsChanged = false; @@ -307,8 +245,7 @@ void MainWindow::pushButtonStartPressed() if(bookingsChanged) { m_currentStripWidget->refresh(); - - refreshAuswertung(); + //refreshAuswertung(); } else m_currentStripWidget->refreshTimeAssignments(); @@ -359,7 +296,7 @@ void MainWindow::pushButtonEndPressed() } m_currentStripWidget->refresh(); - refreshAuswertung(); + //refreshAuswertung(); ui->actionToday->setEnabled(false); ui->actionRefresh->setEnabled(false); @@ -400,12 +337,9 @@ void MainWindow::dateChanged(bool force) } } - if(force || m_auswertungDate != QDate(ui->dateEditDate->date().year(), ui->dateEditDate->date().month(), 1)) - refreshAuswertung(); - if(std::any_of(std::begin(m_stripsWidgets), std::end(m_stripsWidgets), [](StripsWidget *stripsWidget) { return stripsWidget->refreshing(); - }) || m_getAuswertungReply) + })) { ui->actionToday->setEnabled(false); ui->actionRefresh->setEnabled(false); @@ -415,26 +349,6 @@ void MainWindow::dateChanged(bool force) } } -void MainWindow::openAuswertung() -{ - QTemporaryFile file(QDir::temp().absoluteFilePath(QStringLiteral("auswertungXXXXXX.pdf"))); - file.setAutoRemove(false); - if(!file.open()) - { - QMessageBox::warning(this, tr("Could not open auswertung!"), tr("Could not open auswertung!") % "\n\n" % file.errorString()); - return; - } - - file.write(m_auswertung); - file.close(); - - if(!QDesktopServices::openUrl(QUrl::fromLocalFile(file.fileName()))) - { - QMessageBox::warning(this, tr("Could not open auswertung!"), tr("Could not open default PDF viewer!")); - return; - } -} - void MainWindow::minimumTimeChanged() { ui->timeEditTime->setMinimumTime(m_currentStripWidget->minimumTime()); @@ -442,9 +356,6 @@ void MainWindow::minimumTimeChanged() void MainWindow::refreshingChanged() { - if(m_getAuswertungReply) - return; - { auto allFinished = std::none_of(std::begin(m_stripsWidgets), std::end(m_stripsWidgets), [](StripsWidget *stripsWidget){ return stripsWidget->refreshing(); @@ -487,19 +398,6 @@ void MainWindow::endEnabledChanged() ui->pushButtonEnd->setEnabled(endEnabled); } -void MainWindow::refreshAuswertung() -{ - m_balanceLabel->setText(tr("%0: %1").arg(tr("Balance")).arg(tr("???"))); - m_holidaysLabel->setText(tr("%0: %1").arg(tr("Holidays")).arg(tr("???"))); - - ui->actionAuswertung->setEnabled(false); - m_auswertung.clear(); - - m_auswertungDate = QDate(ui->dateEditDate->date().year(), ui->dateEditDate->date().month(), 1); - m_getAuswertungReply = m_erfassung.doGetAuswertung(m_userInfo.userId, m_auswertungDate); - connect(m_getAuswertungReply.get(), &ZeiterfassungReply::finished, this, &MainWindow::getAuswertungFinished); -} - void MainWindow::updateComboboxes() { ui->comboBoxProject->clear(); diff --git a/zeiterfassunglib/mainwindow.h b/zeiterfassunglib/mainwindow.h index 6f30f71..a49ae98 100644 --- a/zeiterfassunglib/mainwindow.h +++ b/zeiterfassunglib/mainwindow.h @@ -9,9 +9,10 @@ #include "zeiterfassunglib_global.h" #include "replies/getuserinforeply.h" #include "replies/getprojectsreply.h" -#include "replies/getauswertungreply.h" #include "replies/getpresencestatusreply.h" +class QMenu; +class QToolBar; class QLabel; class QBoxLayout; @@ -33,22 +34,23 @@ public: QMenu *menuView() const; QMenu *menuTools() const; QMenu *menuAbout() const; + QToolBar *toolBar() const; ZeiterfassungSettings &settings() const; ZeiterfassungApi &erfassung() const; const GetUserInfoReply::UserInfo &userInfo() const; StripFactory &stripFactory() const; + QDate date() const; + const QMap &projects() const; const std::array &stripsWidgets() const; private Q_SLOTS: void getProjectsFinished(); - void getAuswertungFinished(); void pushButtonStartPressed(); void pushButtonEndPressed(); void dateChanged(bool force = false); - void openAuswertung(); void minimumTimeChanged(); void refreshingChanged(); @@ -56,7 +58,6 @@ private Q_SLOTS: void endEnabledChanged(); private: - void refreshAuswertung(); void updateComboboxes(); Ui::MainWindow *ui; @@ -66,16 +67,9 @@ private: StripFactory &m_stripFactory; std::unique_ptr m_getProjectsReply; - std::unique_ptr m_getAuswertungReply; QMap m_projects; - QDate m_auswertungDate; - QByteArray m_auswertung; - - QLabel *m_balanceLabel; - QLabel *m_holidaysLabel; - std::array m_stripsWidgets; StripsWidget *m_currentStripWidget; }; diff --git a/zeiterfassunglib/mainwindow.ui b/zeiterfassunglib/mainwindow.ui index 9bfdf0b..ebc7280 100644 --- a/zeiterfassunglib/mainwindow.ui +++ b/zeiterfassunglib/mainwindow.ui @@ -229,7 +229,6 @@ &Tools - @@ -245,8 +244,6 @@ - - @@ -299,15 +296,6 @@ &Refresh everything - - - - :/zeiterfassunglib/images/auswertung.png:/zeiterfassunglib/images/auswertung.png - - - &Auswertung - - diff --git a/zeiterfassunglib/resources.qrc b/zeiterfassunglib/resources.qrc index 13f4b93..252e452 100644 --- a/zeiterfassunglib/resources.qrc +++ b/zeiterfassunglib/resources.qrc @@ -1,7 +1,6 @@ images/about.png - images/auswertung.png images/authentication.png images/help.png images/icon.png