diff --git a/plugins/advancedviewplugin/advanvedviewdialog.cpp b/plugins/advancedviewplugin/advancedviewdialog.cpp similarity index 84% rename from plugins/advancedviewplugin/advanvedviewdialog.cpp rename to plugins/advancedviewplugin/advancedviewdialog.cpp index bcc77a9..cc3680f 100644 --- a/plugins/advancedviewplugin/advanvedviewdialog.cpp +++ b/plugins/advancedviewplugin/advancedviewdialog.cpp @@ -1,9 +1,8 @@ -#include "advanvedviewdialog.h" -#include "ui_advanvedviewdialog.h" +#include "advancedviewdialog.h" +#include "ui_advancedviewdialog.h" #include #include -#include #include #include @@ -22,9 +21,9 @@ #include "models/bookingsmodel.h" #include "models/timeassignmentsmodel.h" -AdvanvedViewDialog::AdvanvedViewDialog(StripsWidget &stripsWidget) : +AdvancedViewDialog::AdvancedViewDialog(StripsWidget &stripsWidget) : QDialog(&stripsWidget.mainWindow()), - ui(new Ui::AdvanvedViewDialog), + ui(new Ui::AdvancedViewDialog), m_stripsWidget(stripsWidget), m_bookingsModel(new BookingsModel(stripsWidget, this)), m_timeAssignmentsModel(new TimeAssignmentsModel(stripsWidget, this)) @@ -34,20 +33,20 @@ AdvanvedViewDialog::AdvanvedViewDialog(StripsWidget &stripsWidget) : ui->bookingsView->setModel(m_bookingsModel); ui->bookingsView->setEnabled(m_bookingsModel->enabled()); connect(m_bookingsModel, &BookingsModel::enabledChanged, ui->bookingsView, &QWidget::setEnabled); - connect(ui->bookingsView, &QWidget::customContextMenuRequested, this, &AdvanvedViewDialog::contextMenuBooking); + connect(ui->bookingsView, &QWidget::customContextMenuRequested, this, &AdvancedViewDialog::contextMenuBooking); ui->timeAssignmentsView->setModel(m_timeAssignmentsModel); ui->timeAssignmentsView->setEnabled(m_timeAssignmentsModel->enabled()); connect(m_timeAssignmentsModel, &TimeAssignmentsModel::enabledChanged, ui->timeAssignmentsView, &QWidget::setEnabled); - connect(ui->timeAssignmentsView, &QWidget::customContextMenuRequested, this, &AdvanvedViewDialog::contextMenuTimeAssignment); + connect(ui->timeAssignmentsView, &QWidget::customContextMenuRequested, this, &AdvancedViewDialog::contextMenuTimeAssignment); } -AdvanvedViewDialog::~AdvanvedViewDialog() +AdvancedViewDialog::~AdvancedViewDialog() { delete ui; } -void AdvanvedViewDialog::contextMenuBooking(const QPoint &pos) +void AdvancedViewDialog::contextMenuBooking(const QPoint &pos) { auto index = ui->bookingsView->indexAt(pos); @@ -73,11 +72,7 @@ void AdvanvedViewDialog::contextMenuBooking(const QPoint &pos) dialog.getText() ); - { - QEventLoop eventLoop; - connect(reply.get(), &ZeiterfassungReply::finished, &eventLoop, &QEventLoop::quit); - eventLoop.exec(); - } + reply->waitForFinished(); if(reply->success()) { @@ -123,11 +118,7 @@ void AdvanvedViewDialog::contextMenuBooking(const QPoint &pos) dialog.getText() ); - { - QEventLoop eventLoop; - connect(reply.get(), &ZeiterfassungReply::finished, &eventLoop, &QEventLoop::quit); - eventLoop.exec(); - } + reply->waitForFinished(); if(reply->success()) { @@ -150,11 +141,7 @@ void AdvanvedViewDialog::contextMenuBooking(const QPoint &pos) { auto reply = m_stripsWidget.mainWindow().erfassung().doDeleteBooking(booking.id); - { - QEventLoop eventLoop; - connect(reply.get(), &ZeiterfassungReply::finished, &eventLoop, &QEventLoop::quit); - eventLoop.exec(); - } + reply->waitForFinished(); if(reply->success()) m_stripsWidget.refreshBookings(); @@ -165,7 +152,7 @@ void AdvanvedViewDialog::contextMenuBooking(const QPoint &pos) } } -void AdvanvedViewDialog::contextMenuTimeAssignment(const QPoint &pos) +void AdvancedViewDialog::contextMenuTimeAssignment(const QPoint &pos) { auto index = ui->timeAssignmentsView->indexAt(pos); @@ -193,11 +180,7 @@ void AdvanvedViewDialog::contextMenuTimeAssignment(const QPoint &pos) dialog.getText() ); - { - QEventLoop eventLoop; - connect(reply.get(), &ZeiterfassungReply::finished, &eventLoop, &QEventLoop::quit); - eventLoop.exec(); - } + reply->waitForFinished(); if(reply->success()) { @@ -248,11 +231,7 @@ void AdvanvedViewDialog::contextMenuTimeAssignment(const QPoint &pos) dialog.getText() ); - { - QEventLoop eventLoop; - connect(reply.get(), &ZeiterfassungReply::finished, &eventLoop, &QEventLoop::quit); - eventLoop.exec(); - } + reply->waitForFinished(); if(reply->success()) { @@ -275,11 +254,7 @@ void AdvanvedViewDialog::contextMenuTimeAssignment(const QPoint &pos) { auto reply = m_stripsWidget.mainWindow().erfassung().doDeleteTimeAssignment(timeAssignment.id); - { - QEventLoop eventLoop; - connect(reply.get(), &ZeiterfassungReply::finished, &eventLoop, &QEventLoop::quit); - eventLoop.exec(); - } + reply->waitForFinished(); if(reply->success()) { diff --git a/plugins/advancedviewplugin/advanvedviewdialog.h b/plugins/advancedviewplugin/advancedviewdialog.h similarity index 55% rename from plugins/advancedviewplugin/advanvedviewdialog.h rename to plugins/advancedviewplugin/advancedviewdialog.h index 4423716..b35068b 100644 --- a/plugins/advancedviewplugin/advanvedviewdialog.h +++ b/plugins/advancedviewplugin/advancedviewdialog.h @@ -1,27 +1,27 @@ -#ifndef ADVANVEDVIEWDIALOG_H -#define ADVANVEDVIEWDIALOG_H +#ifndef ADVANCEDVIEWDIALOG_H +#define ADVANCEDVIEWDIALOG_H #include -namespace Ui { class AdvanvedViewDialog; } +namespace Ui { class AdvancedViewDialog; } class StripsWidget; class BookingsModel; class TimeAssignmentsModel; -class AdvanvedViewDialog : public QDialog +class AdvancedViewDialog : public QDialog { Q_OBJECT public: - explicit AdvanvedViewDialog(StripsWidget &stripsWidget); - ~AdvanvedViewDialog(); + explicit AdvancedViewDialog(StripsWidget &stripsWidget); + ~AdvancedViewDialog(); private Q_SLOTS: void contextMenuBooking(const QPoint &pos); void contextMenuTimeAssignment(const QPoint &pos); private: - Ui::AdvanvedViewDialog *ui; + Ui::AdvancedViewDialog *ui; StripsWidget &m_stripsWidget; @@ -29,4 +29,4 @@ private: TimeAssignmentsModel *m_timeAssignmentsModel; }; -#endif // ADVANVEDVIEWDIALOG_H +#endif // ADVANCEDVIEWDIALOG_H diff --git a/plugins/advancedviewplugin/advanvedviewdialog.ui b/plugins/advancedviewplugin/advancedviewdialog.ui similarity index 91% rename from plugins/advancedviewplugin/advanvedviewdialog.ui rename to plugins/advancedviewplugin/advancedviewdialog.ui index 0ad8f3f..0d87750 100644 --- a/plugins/advancedviewplugin/advanvedviewdialog.ui +++ b/plugins/advancedviewplugin/advancedviewdialog.ui @@ -1,7 +1,7 @@ - AdvanvedViewDialog - + AdvancedViewDialog + 0 @@ -48,7 +48,7 @@ buttonBox accepted() - AdvanvedViewDialog + AdvancedViewDialog accept() @@ -64,7 +64,7 @@ buttonBox rejected() - AdvanvedViewDialog + AdvancedViewDialog reject() diff --git a/plugins/advancedviewplugin/advancedviewplugin.cpp b/plugins/advancedviewplugin/advancedviewplugin.cpp index e4124ba..3b3f308 100644 --- a/plugins/advancedviewplugin/advancedviewplugin.cpp +++ b/plugins/advancedviewplugin/advancedviewplugin.cpp @@ -1,15 +1,34 @@ #include "advancedviewplugin.h" +#include +#include +#include +#include #include #include "mainwindow.h" #include "stripswidget.h" + #include "advancedviewwidget.h" AdvancedViewPlugin::AdvancedViewPlugin(QObject *parent) : ZeiterfassungPlugin(parent) { - Q_INIT_RESOURCE(advancedviewplugin_resources); + qDebug() << "called"; + + static auto dir = QDir(QCoreApplication::applicationDirPath()).absoluteFilePath(QStringLiteral("translations")); + + if(m_translator.load(QLocale(), QStringLiteral("advancedviewplugin"), QStringLiteral("_"), dir)) + { + if(!QCoreApplication::installTranslator(&m_translator)) + { + qWarning() << "could not install translation advancedviewplugin"; + } + } + else + { + qWarning() << "could not load translation advancedviewplugin"; + } } void AdvancedViewPlugin::attachTo(MainWindow &mainWindow) diff --git a/plugins/advancedviewplugin/advancedviewplugin.h b/plugins/advancedviewplugin/advancedviewplugin.h index e4a08e8..73a4052 100644 --- a/plugins/advancedviewplugin/advancedviewplugin.h +++ b/plugins/advancedviewplugin/advancedviewplugin.h @@ -2,6 +2,7 @@ #define ADVANCEDVIEWPLUGIN_H #include +#include #include "zeiterfassungplugin.h" @@ -17,7 +18,10 @@ public: explicit AdvancedViewPlugin(QObject *parent = Q_NULLPTR); // ZeiterfassungPlugin interface - void attachTo(MainWindow &mainWindow); + void attachTo(MainWindow &mainWindow) Q_DECL_OVERRIDE; + +private: + QTranslator m_translator; }; #endif // ADVANCEDVIEWPLUGIN_H diff --git a/plugins/advancedviewplugin/advancedviewplugin.pro b/plugins/advancedviewplugin/advancedviewplugin.pro index a4436d6..3f522ca 100644 --- a/plugins/advancedviewplugin/advancedviewplugin.pro +++ b/plugins/advancedviewplugin/advancedviewplugin.pro @@ -14,7 +14,7 @@ DEPENDPATH += $$PWD/../../zeiterfassunglib DEFINES += QT_DEPRECATED_WARNINGS QT_DISABLE_DEPRECATED_BEFORE=0x060000 QT_MESSAGELOGCONTEXT -HEADERS += advanvedviewdialog.h \ +HEADERS += advancedviewdialog.h \ advancedviewplugin.h \ advancedviewwidget.h \ dialogs/bookingdialog.h \ @@ -22,7 +22,7 @@ HEADERS += advanvedviewdialog.h \ models/bookingsmodel.h \ models/timeassignmentsmodel.h -SOURCES += advanvedviewdialog.cpp \ +SOURCES += advancedviewdialog.cpp \ advancedviewplugin.cpp \ advancedviewwidget.cpp \ dialogs/bookingdialog.cpp \ @@ -30,12 +30,20 @@ SOURCES += advanvedviewdialog.cpp \ models/bookingsmodel.cpp \ models/timeassignmentsmodel.cpp -FORMS += advanvedviewdialog.ui \ +FORMS += advancedviewdialog.ui \ dialogs/bookingdialog.ui \ dialogs/timeassignmentdialog.ui RESOURCES += advancedviewplugin_resources.qrc -TRANSLATIONS += +TRANSLATIONS += translations/advancedviewplugin_en.ts \ + translations/advancedviewplugin_de.ts OTHER_FILES += advancedviewplugin.json + +include(../../lrelease.pri) + +COMPILED_TRANSLATIONS += $${OUT_PWD}/translations/advancedviewplugin_en.qm \ + $${OUT_PWD}/translations/advancedviewplugin_de.qm + +include(../copy_translations.pri) diff --git a/plugins/advancedviewplugin/advancedviewplugin_resources.qrc b/plugins/advancedviewplugin/advancedviewplugin_resources.qrc index c0cfae7..6b72660 100644 --- a/plugins/advancedviewplugin/advancedviewplugin_resources.qrc +++ b/plugins/advancedviewplugin/advancedviewplugin_resources.qrc @@ -1,5 +1,5 @@ - + images/advanced-view.png diff --git a/plugins/advancedviewplugin/advancedviewwidget.cpp b/plugins/advancedviewplugin/advancedviewwidget.cpp index a48699c..1c9c56d 100644 --- a/plugins/advancedviewplugin/advancedviewwidget.cpp +++ b/plugins/advancedviewplugin/advancedviewwidget.cpp @@ -3,13 +3,14 @@ #include #include "stripswidget.h" -#include "advanvedviewdialog.h" +#include "advancedviewdialog.h" AdvancedViewWidget::AdvancedViewWidget(StripsWidget &stripsWidget) : - QPushButton(&stripsWidget), + QToolButton(&stripsWidget), m_stripsWidget(stripsWidget) { - setIcon(QIcon(QStringLiteral(":/zeiterfassunglib/plugins/advancedviewplugin/images/advanced-view.png"))); + setIcon(QIcon(QStringLiteral(":/zeiterfassung/plugins/advancedviewplugin/images/advanced-view.png"))); + setText(tr("Advanced view")); connect(&stripsWidget, &StripsWidget::dateChanged, this, &AdvancedViewWidget::dateChanged); dateChanged(stripsWidget.date()); @@ -24,6 +25,6 @@ void AdvancedViewWidget::dateChanged(const QDate &date) void AdvancedViewWidget::pressedSlot() { - AdvanvedViewDialog dialog(m_stripsWidget); + AdvancedViewDialog dialog(m_stripsWidget); dialog.exec(); } diff --git a/plugins/advancedviewplugin/advancedviewwidget.h b/plugins/advancedviewplugin/advancedviewwidget.h index cb3bcd9..52bff81 100644 --- a/plugins/advancedviewplugin/advancedviewwidget.h +++ b/plugins/advancedviewplugin/advancedviewwidget.h @@ -1,11 +1,11 @@ #ifndef ADVANCEDVIEWWIDGET_H #define ADVANCEDVIEWWIDGET_H -#include +#include class StripsWidget; -class AdvancedViewWidget : public QPushButton +class AdvancedViewWidget : public QToolButton { Q_OBJECT diff --git a/plugins/advancedviewplugin/dialogs/bookingdialog.h b/plugins/advancedviewplugin/dialogs/bookingdialog.h index 67a95e7..4a308f2 100644 --- a/plugins/advancedviewplugin/dialogs/bookingdialog.h +++ b/plugins/advancedviewplugin/dialogs/bookingdialog.h @@ -4,11 +4,9 @@ #include #include -#include "zeiterfassunglib_global.h" - namespace Ui { class BookingDialog; } -class ZEITERFASSUNGLIBSHARED_EXPORT BookingDialog : public QDialog +class BookingDialog : public QDialog { Q_OBJECT diff --git a/plugins/advancedviewplugin/dialogs/timeassignmentdialog.h b/plugins/advancedviewplugin/dialogs/timeassignmentdialog.h index 160b057..a8d253c 100644 --- a/plugins/advancedviewplugin/dialogs/timeassignmentdialog.h +++ b/plugins/advancedviewplugin/dialogs/timeassignmentdialog.h @@ -4,15 +4,13 @@ #include #include -#include "zeiterfassunglib_global.h" - template class QMap; class ZeiterfassungSettings; namespace Ui { class TimeAssignmentDialog; } -class ZEITERFASSUNGLIBSHARED_EXPORT TimeAssignmentDialog : public QDialog +class TimeAssignmentDialog : public QDialog { Q_OBJECT diff --git a/plugins/advancedviewplugin/models/bookingsmodel.cpp b/plugins/advancedviewplugin/models/bookingsmodel.cpp index 14ece31..4c59657 100644 --- a/plugins/advancedviewplugin/models/bookingsmodel.cpp +++ b/plugins/advancedviewplugin/models/bookingsmodel.cpp @@ -7,7 +7,7 @@ BookingsModel::BookingsModel(StripsWidget &stripsWidget, QObject *parent) : m_stripsWidget(stripsWidget) { connect(&stripsWidget, &StripsWidget::bookingsChanged, this, &BookingsModel::bookingsChanged); - connect(&stripsWidget, &StripsWidget::refreshingBookingsChanged, [=](bool refreshing){ enabledChanged(!refreshing); }); + connect(&stripsWidget, &StripsWidget::refreshingBookingsChanged, this, &BookingsModel::refreshingChanged); } StripsWidget &BookingsModel::stripsWidget() const @@ -86,3 +86,8 @@ void BookingsModel::bookingsChanged() beginResetModel(); endResetModel(); } + +void BookingsModel::refreshingChanged(bool refreshing) +{ + Q_EMIT enabledChanged(!refreshing); +} diff --git a/plugins/advancedviewplugin/models/bookingsmodel.h b/plugins/advancedviewplugin/models/bookingsmodel.h index 0c02b3e..ced2306 100644 --- a/plugins/advancedviewplugin/models/bookingsmodel.h +++ b/plugins/advancedviewplugin/models/bookingsmodel.h @@ -4,12 +4,11 @@ #include #include -#include "zeiterfassunglib_global.h" #include "zeiterfassungapi.h" class StripsWidget; -class ZEITERFASSUNGLIBSHARED_EXPORT BookingsModel : public QAbstractListModel +class BookingsModel : public QAbstractListModel { Q_OBJECT Q_PROPERTY(bool enabled READ enabled NOTIFY enabledChanged) @@ -32,6 +31,7 @@ Q_SIGNALS: private Q_SLOTS: void bookingsChanged(); + void refreshingChanged(bool refreshing); private: StripsWidget &m_stripsWidget; diff --git a/plugins/advancedviewplugin/models/timeassignmentsmodel.cpp b/plugins/advancedviewplugin/models/timeassignmentsmodel.cpp index b33930b..73a1a70 100644 --- a/plugins/advancedviewplugin/models/timeassignmentsmodel.cpp +++ b/plugins/advancedviewplugin/models/timeassignmentsmodel.cpp @@ -7,7 +7,7 @@ TimeAssignmentsModel::TimeAssignmentsModel(StripsWidget &stripsWidget, QObject * m_stripsWidget(stripsWidget) { connect(&stripsWidget, &StripsWidget::timeAssignmentsChanged, this, &TimeAssignmentsModel::timeAssignmentsChanged); - connect(&stripsWidget, &StripsWidget::refreshingTimeAssignmentsChanged, [=](bool refreshing){ enabledChanged(!refreshing); }); + connect(&stripsWidget, &StripsWidget::refreshingTimeAssignmentsChanged, this, &TimeAssignmentsModel::refreshingChanged); } StripsWidget &TimeAssignmentsModel::stripsWidget() const @@ -90,3 +90,8 @@ void TimeAssignmentsModel::timeAssignmentsChanged() beginResetModel(); endResetModel(); } + +void TimeAssignmentsModel::refreshingChanged(bool refreshing) +{ + Q_EMIT enabledChanged(!refreshing); +} diff --git a/plugins/advancedviewplugin/models/timeassignmentsmodel.h b/plugins/advancedviewplugin/models/timeassignmentsmodel.h index b4bb8f3..05ffc55 100644 --- a/plugins/advancedviewplugin/models/timeassignmentsmodel.h +++ b/plugins/advancedviewplugin/models/timeassignmentsmodel.h @@ -4,12 +4,11 @@ #include #include -#include "zeiterfassunglib_global.h" #include "zeiterfassungapi.h" class StripsWidget; -class ZEITERFASSUNGLIBSHARED_EXPORT TimeAssignmentsModel : public QAbstractListModel +class TimeAssignmentsModel : public QAbstractListModel { Q_OBJECT Q_PROPERTY(bool enabled READ enabled NOTIFY enabledChanged) diff --git a/plugins/advancedviewplugin/translations/advancedviewplugin_de.ts b/plugins/advancedviewplugin/translations/advancedviewplugin_de.ts new file mode 100644 index 0000000..b68cae8 --- /dev/null +++ b/plugins/advancedviewplugin/translations/advancedviewplugin_de.ts @@ -0,0 +1,240 @@ + + + + + AdvancedViewDialog + + + Advanced view + Erweiterte Anzeige + + + + Create booking + Buchung erstellen + + + + Refresh bookings + Buchungen aktualisieren + + + + Could not create booking! + Konnte Buchung nicht erstellen! + + + + Edit booking + Buchung bearbeiten + + + + Delete booking + Buchung löschen + + + + Could not edit booking! + Konnte Buchung nicht bearbeiten! + + + + Do you really want to delete the booking? + Möchten Sie die Buchung wirklich löschen? + + + + Could not delete booking! + Konnte Buchung nicht löschen! + + + + Create time assignment + Kontierung erstellen + + + + Refresh time assignments + Kontierungen aktualisieren + + + + Could not create time assignment! + Konnte Kontierung nicht erstellen! + + + + Edit time assignment + Kontierung bearbeiten + + + + Delete time assignment + Kontierung löschen + + + + Could not edit time assignment! + Konnte Kontierung nicht bearbeiten! + + + + Do you really want to delete the time assignment? + Möchten Sie die Kontierung wirklich löschen? + + + + Could not delete time assignment! + Konnte Kontierung nicht löschen! + + + + AdvancedViewWidget + + + Advanced view + Erweiterte Anzeige + + + + BookingDialog + + + + Booking + Buchung + + + + Time: + Zeit: + + + + Timespan: + Zeitspanne: + + + + Type: + Typ: + + + + Text: + Text: + + + + BookingsModel + + + ID + ID + + + + Time + Zeit + + + + Timespan + Zeitspanne + + + + Type + Typ + + + + Text + Text + + + + TimeAssignmentDialog + + + + Time assignment + Kontierung + + + + Time: + Zeit: + + + + Timespan: + Zeitspanne: + + + + Project: + Projekt: + + + + Subproject: + Subprojekt: + + + + Workpackage: + Arbeitspaket: + + + + Text: + Text: + + + + + %0 (%1) + %0 (%1) + + + + TimeAssignmentsModel + + + ID + ID + + + + Time + Zeit + + + + Timespan + Zeitspanne + + + + Project + Projekt + + + + Subproject + Subprojekt + + + + Workpackage + Arbeitspaket + + + + Text + Text + + + diff --git a/plugins/advancedviewplugin/translations/advancedviewplugin_en.ts b/plugins/advancedviewplugin/translations/advancedviewplugin_en.ts new file mode 100644 index 0000000..80acdaf --- /dev/null +++ b/plugins/advancedviewplugin/translations/advancedviewplugin_en.ts @@ -0,0 +1,240 @@ + + + + + AdvancedViewDialog + + + Advanced view + + + + + Create booking + + + + + Refresh bookings + + + + + Could not create booking! + + + + + Edit booking + + + + + Delete booking + + + + + Could not edit booking! + + + + + Do you really want to delete the booking? + + + + + Could not delete booking! + + + + + Create time assignment + + + + + Refresh time assignments + + + + + Could not create time assignment! + + + + + Edit time assignment + + + + + Delete time assignment + + + + + Could not edit time assignment! + + + + + Do you really want to delete the time assignment? + + + + + Could not delete time assignment! + + + + + AdvancedViewWidget + + + Advanced view + + + + + BookingDialog + + + + Booking + + + + + Time: + + + + + Timespan: + + + + + Type: + + + + + Text: + + + + + BookingsModel + + + ID + + + + + Time + + + + + Timespan + + + + + Type + + + + + Text + + + + + TimeAssignmentDialog + + + + Time assignment + + + + + Time: + + + + + Timespan: + + + + + Project: + + + + + Subproject: + + + + + Workpackage: + + + + + Text: + + + + + + %0 (%1) + + + + + TimeAssignmentsModel + + + ID + + + + + Time + + + + + Timespan + + + + + Project + + + + + Subproject + + + + + Workpackage + + + + + Text + + + + diff --git a/plugins/copy_translations.pri b/plugins/copy_translations.pri new file mode 100644 index 0000000..966c686 --- /dev/null +++ b/plugins/copy_translations.pri @@ -0,0 +1,6 @@ +copy_compiled_translations.input = COMPILED_TRANSLATIONS +copy_compiled_translations.output = $${OUT_PWD}/../../bin/translations/${QMAKE_FILE_BASE}${QMAKE_FILE_EXT} +copy_compiled_translations.commands = $$QMAKE_COPY ${QMAKE_FILE_IN} ${QMAKE_FILE_OUT} +copy_compiled_translations.CONFIG += no_link +QMAKE_EXTRA_COMPILERS += copy_compiled_translations +PRE_TARGETDEPS += compiler_copy_compiled_translations_make_all diff --git a/plugins/lunchmealplugin/images/lunch-meal.png b/plugins/lunchmealplugin/images/lunch-meal.png new file mode 100644 index 0000000..7c83e54 Binary files /dev/null and b/plugins/lunchmealplugin/images/lunch-meal.png differ diff --git a/plugins/lunchmealplugin/lunchmealdialog.cpp b/plugins/lunchmealplugin/lunchmealdialog.cpp new file mode 100644 index 0000000..a61dd57 --- /dev/null +++ b/plugins/lunchmealplugin/lunchmealdialog.cpp @@ -0,0 +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 new file mode 100644 index 0000000..9345fcf --- /dev/null +++ b/plugins/lunchmealplugin/lunchmealdialog.h @@ -0,0 +1,29 @@ +#ifndef LUNCHMEALDIALOG_H +#define LUNCHMEALDIALOG_H + +#include + +#include +#include + +class StripsWidget; + +namespace Ui { class LunchMealDialog; } + +class LunchMealDialog : public QDialog +{ + Q_OBJECT + +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 new file mode 100644 index 0000000..ab5ffa7 --- /dev/null +++ b/plugins/lunchmealplugin/lunchmealdialog.ui @@ -0,0 +1,88 @@ + + + LunchMealDialog + + + + 0 + 0 + 400 + 300 + + + + Lunch meal + + + + + + + 16 + 75 + true + + + + Lunch meal for + + + + + + + Loading... + + + Qt::AlignLeading|Qt::AlignLeft|Qt::AlignTop + + + + + + + Qt::Horizontal + + + QDialogButtonBox::Close + + + + + + + + + buttonBox + accepted() + LunchMealDialog + accept() + + + 248 + 254 + + + 157 + 274 + + + + + buttonBox + rejected() + LunchMealDialog + reject() + + + 316 + 260 + + + 286 + 274 + + + + + diff --git a/plugins/lunchmealplugin/lunchmealplugin.cpp b/plugins/lunchmealplugin/lunchmealplugin.cpp index e1b1b92..0379d21 100644 --- a/plugins/lunchmealplugin/lunchmealplugin.cpp +++ b/plugins/lunchmealplugin/lunchmealplugin.cpp @@ -1,9 +1,38 @@ #include "lunchmealplugin.h" #include +#include +#include +#include +#include + +#include "mainwindow.h" +#include "stripswidget.h" + +#include "lunchmealwidget.h" LunchMealPlugin::LunchMealPlugin(QObject *parent) : ZeiterfassungPlugin(parent) { + qDebug() << "called"; + static auto dir = QDir(QCoreApplication::applicationDirPath()).absoluteFilePath(QStringLiteral("translations")); + + if(m_translator.load(QLocale(), QStringLiteral("lunchmealplugin"), QStringLiteral("_"), dir)) + { + if(!QCoreApplication::installTranslator(&m_translator)) + { + qWarning() << "could not install translation lunchmealplugin"; + } + } + else + { + qWarning() << "could not load translation lunchmealplugin"; + } +} + +void LunchMealPlugin::attachTo(MainWindow &mainWindow) +{ + for(auto stripsWidget : mainWindow.stripsWidgets()) + stripsWidget->headerLayout()->addWidget(new LunchMealWidget(*stripsWidget)); } diff --git a/plugins/lunchmealplugin/lunchmealplugin.h b/plugins/lunchmealplugin/lunchmealplugin.h index c5626a8..f2a0f7c 100644 --- a/plugins/lunchmealplugin/lunchmealplugin.h +++ b/plugins/lunchmealplugin/lunchmealplugin.h @@ -2,9 +2,12 @@ #define LUNCHMEALPLUGIN_H #include +#include #include "zeiterfassungplugin.h" +class MainWindow; + class Q_DECL_EXPORT LunchMealPlugin : public ZeiterfassungPlugin { Q_OBJECT @@ -15,6 +18,10 @@ public: explicit LunchMealPlugin(QObject *parent = Q_NULLPTR); // ZeiterfassungPlugin interface + void attachTo(MainWindow &mainWindow) Q_DECL_OVERRIDE; + +private: + QTranslator m_translator; }; #endif // LUNCHMEALPLUGIN_H diff --git a/plugins/lunchmealplugin/lunchmealplugin.pro b/plugins/lunchmealplugin/lunchmealplugin.pro index d0dd373..c3debe5 100644 --- a/plugins/lunchmealplugin/lunchmealplugin.pro +++ b/plugins/lunchmealplugin/lunchmealplugin.pro @@ -14,8 +14,26 @@ DEPENDPATH += $$PWD/../../zeiterfassunglib DEFINES += QT_DEPRECATED_WARNINGS QT_DISABLE_DEPRECATED_BEFORE=0x060000 QT_MESSAGELOGCONTEXT -HEADERS += lunchmealplugin.h +HEADERS += lunchmealplugin.h \ + lunchmealwidget.h \ + lunchmealdialog.h -SOURCES += lunchmealplugin.cpp +SOURCES += lunchmealplugin.cpp \ + lunchmealwidget.cpp \ + lunchmealdialog.cpp + +FORMS += lunchmealdialog.ui + +RESOURCES += lunchmealplugin_resources.qrc + +TRANSLATIONS += translations/lunchmealplugin_en.ts \ + translations/lunchmealplugin_de.ts OTHER_FILES += lunchmealplugin.json + +include(../../lrelease.pri) + +COMPILED_TRANSLATIONS += $${OUT_PWD}/translations/lunchmealplugin_en.qm \ + $${OUT_PWD}/translations/lunchmealplugin_de.qm + +include(../copy_translations.pri) diff --git a/plugins/lunchmealplugin/lunchmealplugin_resources.qrc b/plugins/lunchmealplugin/lunchmealplugin_resources.qrc new file mode 100644 index 0000000..ca3c14e --- /dev/null +++ b/plugins/lunchmealplugin/lunchmealplugin_resources.qrc @@ -0,0 +1,5 @@ + + + images/lunch-meal.png + + diff --git a/plugins/lunchmealplugin/lunchmealwidget.cpp b/plugins/lunchmealplugin/lunchmealwidget.cpp new file mode 100644 index 0000000..eacaaf6 --- /dev/null +++ b/plugins/lunchmealplugin/lunchmealwidget.cpp @@ -0,0 +1,25 @@ +#include "lunchmealwidget.h" + +#include + +#include "stripswidget.h" +#include "mainwindow.h" +#include "zeiterfassungapi.h" + +#include "lunchmealdialog.h" + +LunchMealWidget::LunchMealWidget(StripsWidget &stripsWidget) : + QToolButton(&stripsWidget), + m_stripsWidget(stripsWidget) +{ + setIcon(QIcon(QStringLiteral(":/zeiterfassung/plugins/lunchmealplugin/images/lunch-meal.png"))); + setText(tr("Lunch meal")); + + connect(this, &QAbstractButton::pressed, this, &LunchMealWidget::pressedSlot); +} + +void LunchMealWidget::pressedSlot() +{ + LunchMealDialog dialog(m_stripsWidget); + dialog.exec(); +} diff --git a/plugins/lunchmealplugin/lunchmealwidget.h b/plugins/lunchmealplugin/lunchmealwidget.h new file mode 100644 index 0000000..a609ab9 --- /dev/null +++ b/plugins/lunchmealplugin/lunchmealwidget.h @@ -0,0 +1,21 @@ +#ifndef LUNCHMEALWIDGET_H +#define LUNCHMEALWIDGET_H + +#include + +class StripsWidget; + +class LunchMealWidget : public QToolButton +{ + Q_OBJECT +public: + explicit LunchMealWidget(StripsWidget &stripsWidget); + +private Q_SLOTS: + void pressedSlot(); + +private: + StripsWidget &m_stripsWidget; +}; + +#endif // LUNCHMEALWIDGET_H diff --git a/plugins/lunchmealplugin/translations/lunchmealplugin_de.ts b/plugins/lunchmealplugin/translations/lunchmealplugin_de.ts new file mode 100644 index 0000000..0a13bcc --- /dev/null +++ b/plugins/lunchmealplugin/translations/lunchmealplugin_de.ts @@ -0,0 +1,35 @@ + + + + + LunchMealDialog + + + Lunch meal + Mittagsmenü + + + + Loading... + Lade... + + + + Lunch meal for %0 + Mittagsmenü vom %0 + + + + dd.MM.yyyy + dd.MM.yyyy + + + + LunchMealWidget + + + Lunch meal + Mittagsmenü + + + diff --git a/plugins/lunchmealplugin/translations/lunchmealplugin_en.ts b/plugins/lunchmealplugin/translations/lunchmealplugin_en.ts new file mode 100644 index 0000000..ac807ce --- /dev/null +++ b/plugins/lunchmealplugin/translations/lunchmealplugin_en.ts @@ -0,0 +1,35 @@ + + + + + LunchMealDialog + + + Lunch meal + + + + + Loading... + + + + + Lunch meal for %0 + + + + + dd.MM.yyyy + + + + + LunchMealWidget + + + Lunch meal + + + + diff --git a/plugins/plugins.pro b/plugins/plugins.pro index e062acc..f8c26c3 100644 --- a/plugins/plugins.pro +++ b/plugins/plugins.pro @@ -3,4 +3,6 @@ TEMPLATE = subdirs SUBDIRS += advancedviewplugin \ lunchmealplugin \ presenceplugin \ + reportsplugin \ + updaterplugin \ weatherplugin diff --git a/plugins/presenceplugin/images/refresh.png b/plugins/presenceplugin/images/refresh.png new file mode 100644 index 0000000..f3585b7 Binary files /dev/null and b/plugins/presenceplugin/images/refresh.png differ diff --git a/plugins/presenceplugin/presenceplugin.cpp b/plugins/presenceplugin/presenceplugin.cpp index 0560bb6..3e5e64d 100644 --- a/plugins/presenceplugin/presenceplugin.cpp +++ b/plugins/presenceplugin/presenceplugin.cpp @@ -1,14 +1,30 @@ #include "presenceplugin.h" #include +#include +#include +#include -#include "mainwindow.h" #include "presencewidget.h" PresencePlugin::PresencePlugin(QObject *parent) : ZeiterfassungPlugin(parent) { qDebug() << "called"; + + static auto dir = QDir(QCoreApplication::applicationDirPath()).absoluteFilePath(QStringLiteral("translations")); + + if(m_translator.load(QLocale(), QStringLiteral("presenceplugin"), QStringLiteral("_"), dir)) + { + if(!QCoreApplication::installTranslator(&m_translator)) + { + qWarning() << "could not install translation presenceplugin"; + } + } + else + { + qWarning() << "could not load translation presenceplugin"; + } } void PresencePlugin::attachTo(MainWindow &mainWindow) diff --git a/plugins/presenceplugin/presenceplugin.h b/plugins/presenceplugin/presenceplugin.h index 362c0f1..2fc9f87 100644 --- a/plugins/presenceplugin/presenceplugin.h +++ b/plugins/presenceplugin/presenceplugin.h @@ -2,6 +2,7 @@ #define PRESENCEPLUGIN_H #include +#include #include "zeiterfassungplugin.h" @@ -17,7 +18,10 @@ public: explicit PresencePlugin(QObject *parent = Q_NULLPTR); // ZeiterfassungPlugin interface - void attachTo(MainWindow &mainWindow); + void attachTo(MainWindow &mainWindow) Q_DECL_OVERRIDE; + +private: + QTranslator m_translator; }; #endif // PRESENCEPLUGIN_H diff --git a/plugins/presenceplugin/presenceplugin.pro b/plugins/presenceplugin/presenceplugin.pro index 7767bfe..e3e1d82 100644 --- a/plugins/presenceplugin/presenceplugin.pro +++ b/plugins/presenceplugin/presenceplugin.pro @@ -15,9 +15,23 @@ DEPENDPATH += $$PWD/../../zeiterfassunglib DEFINES += QT_DEPRECATED_WARNINGS QT_DISABLE_DEPRECATED_BEFORE=0x060000 QT_MESSAGELOGCONTEXT HEADERS += presenceplugin.h \ - presencewidget.h + presencewidget.h SOURCES += presenceplugin.cpp \ - presencewidget.cpp + presencewidget.cpp + +FORMS += + +RESOURCES += presenceplugin_resources.qrc + +TRANSLATIONS += translations/presenceplugin_en.ts \ + translations/presenceplugin_de.ts OTHER_FILES += presenceplugin.json + +include(../../lrelease.pri) + +COMPILED_TRANSLATIONS += $${OUT_PWD}/translations/presenceplugin_en.qm \ + $${OUT_PWD}/translations/presenceplugin_de.qm + +include(../copy_translations.pri) diff --git a/plugins/presenceplugin/presenceplugin_resources.qrc b/plugins/presenceplugin/presenceplugin_resources.qrc new file mode 100644 index 0000000..9eca07d --- /dev/null +++ b/plugins/presenceplugin/presenceplugin_resources.qrc @@ -0,0 +1,5 @@ + + + images/refresh.png + + diff --git a/plugins/presenceplugin/presencewidget.cpp b/plugins/presenceplugin/presencewidget.cpp index 05d6223..cbcbca6 100644 --- a/plugins/presenceplugin/presencewidget.cpp +++ b/plugins/presenceplugin/presencewidget.cpp @@ -2,6 +2,7 @@ #include #include +#include #include #include #include @@ -13,6 +14,8 @@ PresenceWidget::PresenceWidget(MainWindow &mainWindow) : QWidget(&mainWindow), m_mainWindow(mainWindow) { + connect(&m_mainWindow, &MainWindow::refreshEverything, this, &PresenceWidget::refresh); + m_labelAvailable = new QLabel(this); m_labelAvailable->setFrameShape(QFrame::Panel); m_labelAvailable->setFrameShadow(QFrame::Sunken); @@ -23,25 +26,24 @@ PresenceWidget::PresenceWidget(MainWindow &mainWindow) : m_labelNotAvailable->setFrameShadow(QFrame::Sunken); m_mainWindow.statusBar()->addWidget(m_labelNotAvailable); + m_action = m_mainWindow.menuView()->addAction(QIcon(QStringLiteral(":zeiterfassung/plugins/presenceplugin/images/refresh.png")), + tr("Refresh presence"), this, &PresenceWidget::refresh); + auto timer = new QTimer(this); timer->setInterval(60000); - connect(timer, &QTimer::timeout, this, &PresenceWidget::timeout); + connect(timer, &QTimer::timeout, this, &PresenceWidget::refresh); timer->start(); - timeout(); + refresh(); } -void PresenceWidget::timeout() +void PresenceWidget::refresh() { - if(m_reply) - { - qWarning() << "last request not finished yet!"; - return; - } - m_labelAvailable->setText(tr("%0: %1").arg(tr("Available")).arg(tr("???"))); m_labelNotAvailable->setText(tr("%0: %1").arg(tr("Not available")).arg(tr("???"))); + m_action->setEnabled(false); + m_reply = m_mainWindow.erfassung().doGetPresenceStatus(); connect(m_reply.get(), &ZeiterfassungReply::finished, this, &PresenceWidget::finished); } @@ -73,5 +75,6 @@ void PresenceWidget::finished() } after: + m_action->setEnabled(true); m_reply = Q_NULLPTR; } diff --git a/plugins/presenceplugin/presencewidget.h b/plugins/presenceplugin/presencewidget.h index 2c1e578..ce7f6dc 100644 --- a/plugins/presenceplugin/presencewidget.h +++ b/plugins/presenceplugin/presencewidget.h @@ -6,17 +6,19 @@ #include "replies/getpresencestatusreply.h" class QLabel; +class QAction; class MainWindow; class PresenceWidget : public QWidget { Q_OBJECT + public: explicit PresenceWidget(MainWindow &mainWindow); private Q_SLOTS: - void timeout(); + void refresh(); void finished(); private: @@ -25,6 +27,8 @@ private: QLabel *m_labelAvailable; QLabel *m_labelNotAvailable; + QAction *m_action; + std::unique_ptr m_reply; }; diff --git a/plugins/presenceplugin/translations/presenceplugin_de.ts b/plugins/presenceplugin/translations/presenceplugin_de.ts new file mode 100644 index 0000000..6f9be17 --- /dev/null +++ b/plugins/presenceplugin/translations/presenceplugin_de.ts @@ -0,0 +1,44 @@ + + + + + PresenceWidget + + + Refresh presence + Verfügbarkeit aktualisieren + + + + + + + %0: %1 + %0: %1 + + + + + Available + Verfügbar + + + + + ??? + ??? + + + + + Not available + Nicht verfügbar + + + + + Could not get presence status! + Konnte Verfügbarkeit nicht laden! + + + diff --git a/plugins/presenceplugin/translations/presenceplugin_en.ts b/plugins/presenceplugin/translations/presenceplugin_en.ts new file mode 100644 index 0000000..924bcb5 --- /dev/null +++ b/plugins/presenceplugin/translations/presenceplugin_en.ts @@ -0,0 +1,44 @@ + + + + + PresenceWidget + + + Refresh presence + + + + + + + + %0: %1 + + + + + + Available + + + + + + ??? + + + + + + Not available + + + + + + Could not get presence status! + + + + 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 new file mode 100644 index 0000000..ce4dec0 --- /dev/null +++ b/plugins/reportsplugin/reportsplugin.cpp @@ -0,0 +1,33 @@ +#include "reportsplugin.h" + +#include +#include +#include +#include + +#include "reportswidget.h" + +ReportsPlugin::ReportsPlugin(QObject *parent) : + ZeiterfassungPlugin(parent) +{ + qDebug() << "called"; + + static auto dir = QDir(QCoreApplication::applicationDirPath()).absoluteFilePath(QStringLiteral("translations")); + + if(m_translator.load(QLocale(), QStringLiteral("reportsplugin"), QStringLiteral("_"), dir)) + { + if(!QCoreApplication::installTranslator(&m_translator)) + { + qWarning() << "could not install translation reportsplugin"; + } + } + else + { + qWarning() << "could not load translation reportsplugin"; + } +} + +void ReportsPlugin::attachTo(MainWindow &mainWindow) +{ + new ReportsWidget(mainWindow); +} diff --git a/plugins/reportsplugin/reportsplugin.h b/plugins/reportsplugin/reportsplugin.h new file mode 100644 index 0000000..469ac83 --- /dev/null +++ b/plugins/reportsplugin/reportsplugin.h @@ -0,0 +1,27 @@ +#ifndef REPORTSPLUGIN_H +#define REPORTSPLUGIN_H + +#include +#include + +#include "zeiterfassungplugin.h" + +class MainWindow; + +class Q_DECL_EXPORT ReportsPlugin : public ZeiterfassungPlugin +{ + Q_OBJECT + Q_PLUGIN_METADATA(IID "dbsoftware.zeiterfassung.plugin/1.0" FILE "reportsplugin.json") + Q_INTERFACES(ZeiterfassungPlugin) + +public: + explicit ReportsPlugin(QObject *parent = Q_NULLPTR); + + // ZeiterfassungPlugin interface + void attachTo(MainWindow &mainWindow) Q_DECL_OVERRIDE; + +private: + QTranslator m_translator; +}; + +#endif // REPORTSPLUGIN_H diff --git a/plugins/reportsplugin/reportsplugin.json b/plugins/reportsplugin/reportsplugin.json new file mode 100644 index 0000000..e69de29 diff --git a/plugins/reportsplugin/reportsplugin.pro b/plugins/reportsplugin/reportsplugin.pro new file mode 100644 index 0000000..e5fcadf --- /dev/null +++ b/plugins/reportsplugin/reportsplugin.pro @@ -0,0 +1,37 @@ +QT += core network gui widgets + +TARGET = reportsplugin +TEMPLATE = lib + +CONFIG += shared c++14 + +DESTDIR = $${OUT_PWD}/../../bin/plugins/zeiterfassung + +LIBS += -L$$OUT_PWD/../../lib -lzeiterfassunglib + +INCLUDEPATH += $$PWD/../../zeiterfassunglib +DEPENDPATH += $$PWD/../../zeiterfassunglib + +DEFINES += QT_DEPRECATED_WARNINGS QT_DISABLE_DEPRECATED_BEFORE=0x060000 QT_MESSAGELOGCONTEXT + +HEADERS += reportsplugin.h \ + reportswidget.h + +SOURCES += reportsplugin.cpp \ + reportswidget.cpp + +FORMS += + +RESOURCES += reportsplugin_resources.qrc + +TRANSLATIONS += translations/reportsplugin_en.ts \ + translations/reportsplugin_de.ts + +OTHER_FILES += reportsplugin.json + +include(../../lrelease.pri) + +COMPILED_TRANSLATIONS += $${OUT_PWD}/translations/reportsplugin_en.qm \ + $${OUT_PWD}/translations/reportsplugin_de.qm + +include(../copy_translations.pri) 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..1aded66 --- /dev/null +++ b/plugins/reportsplugin/reportswidget.cpp @@ -0,0 +1,148 @@ +#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) +{ + connect(&m_mainWindow, &MainWindow::dateChanged, this, &ReportsWidget::dateChanged); + connect(&m_mainWindow, &MainWindow::refreshEverything, this, &ReportsWidget::refresh); + + 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().doGetReport(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->content(); + + { + 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("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); + + 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..9adcfe7 --- /dev/null +++ b/plugins/reportsplugin/reportswidget.h @@ -0,0 +1,43 @@ +#ifndef REPORTSWIDGET_H +#define REPORTSWIDGET_H + +#include +#include +#include + +#include "replies/getreportreply.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/plugins/reportsplugin/translations/reportsplugin_de.ts b/plugins/reportsplugin/translations/reportsplugin_de.ts new file mode 100644 index 0000000..fdca085 --- /dev/null +++ b/plugins/reportsplugin/translations/reportsplugin_de.ts @@ -0,0 +1,73 @@ + + + + + ReportsWidget + + + Refresh report + Auswertung aktualisieren + + + + Open report + Auswertung öffnen + + + + + + + + + %0: %1 + %0: %1 + + + + + + Balance + Gleitzeit + + + + + ??? + ??? + + + + + + Holidays + Urlaub + + + + Could not load report! + Konnte Auswertung nicht laden! + + + + %0h + %0h + + + + + 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/plugins/reportsplugin/translations/reportsplugin_en.ts b/plugins/reportsplugin/translations/reportsplugin_en.ts new file mode 100644 index 0000000..03ce2d6 --- /dev/null +++ b/plugins/reportsplugin/translations/reportsplugin_en.ts @@ -0,0 +1,73 @@ + + + + + ReportsWidget + + + Refresh report + + + + + Open report + + + + + + + + + + %0: %1 + + + + + + + Balance + + + + + + ??? + + + + + + + Holidays + + + + + Could not load report! + + + + + %0h + + + + + + n/a + + + + + Could not write report! + + + + + Could not launch your default PDF viewer! + + + + diff --git a/plugins/updaterplugin/translations/updaterplugin_de.ts b/plugins/updaterplugin/translations/updaterplugin_de.ts new file mode 100644 index 0000000..0fd56e0 --- /dev/null +++ b/plugins/updaterplugin/translations/updaterplugin_de.ts @@ -0,0 +1,28 @@ + + + + + UpdaterDialog + + + + New update available! + Neues Update verfügbar! + + + + There is a new release available to download! + Ein neues Release steht zum Download bereit! + + + + Dont show today anymore + Heute nicht mehr anzeigen + + + + Could not open default webbrowser! + Konnte Standard-Browser nicht öffnen! + + + diff --git a/plugins/updaterplugin/translations/updaterplugin_en.ts b/plugins/updaterplugin/translations/updaterplugin_en.ts new file mode 100644 index 0000000..fd1099e --- /dev/null +++ b/plugins/updaterplugin/translations/updaterplugin_en.ts @@ -0,0 +1,28 @@ + + + + + UpdaterDialog + + + + New update available! + + + + + There is a new release available to download! + + + + + Dont show today anymore + + + + + Could not open default webbrowser! + + + + diff --git a/zeiterfassunglib/dialogs/updatedialog.cpp b/plugins/updaterplugin/updaterdialog.cpp similarity index 59% rename from zeiterfassunglib/dialogs/updatedialog.cpp rename to plugins/updaterplugin/updaterdialog.cpp index e47fc81..55f5bdb 100644 --- a/zeiterfassunglib/dialogs/updatedialog.cpp +++ b/plugins/updaterplugin/updaterdialog.cpp @@ -1,5 +1,5 @@ -#include "updatedialog.h" -#include "ui_updatedialog.h" +#include "updaterdialog.h" +#include "ui_updaterdialog.h" #include #include @@ -14,34 +14,53 @@ #include #include +#include "mainwindow.h" #include "zeiterfassungsettings.h" +#include "zeiterfassungapi.h" -UpdateDialog::UpdateDialog(ZeiterfassungSettings &settings, QNetworkAccessManager *manager, QWidget *parent) : - QDialog(parent), - ui(new Ui::UpdateDialog), - m_settings(settings) +UpdaterDialog::UpdaterDialog(MainWindow &mainWindow) : + QDialog(&mainWindow), + ui(new Ui::UpdaterDialog), + m_mainWindow(mainWindow) { ui->setupUi(this); setAttribute(Qt::WA_DeleteOnClose); - connect(ui->buttonBox, &QDialogButtonBox::accepted, this, &UpdateDialog::submit); - connect(ui->buttonBox, &QDialogButtonBox::rejected, this, [=](){ - if(ui->checkBoxDontShow->isChecked()) - m_settings.setLastUpdateCheck(QDate::currentDate()); - reject(); - }); + connect(ui->buttonBox, &QDialogButtonBox::accepted, this, &UpdaterDialog::acceptedSlot); + connect(ui->buttonBox, &QDialogButtonBox::rejected, this, &UpdaterDialog::rejectedSlot); - m_reply = manager->get(QNetworkRequest(QUrl(QStringLiteral("https://api.github.com/repos/0xFEEDC0DE64/QtZeiterfassung/releases")))); - connect(m_reply, &QNetworkReply::finished, this, &UpdateDialog::finished); + auto url = m_mainWindow.settings().value(QStringLiteral("UpdaterPlugin/url"), + QUrl(QStringLiteral("https://api.github.com/repos/0xFEEDC0DE64/QtZeiterfassung/releases"))).toUrl(); + m_reply = m_mainWindow.erfassung().manager()->get(QNetworkRequest(url)); + connect(m_reply, &QNetworkReply::finished, this, &UpdaterDialog::finished); } -UpdateDialog::~UpdateDialog() +UpdaterDialog::~UpdaterDialog() { delete ui; } -void UpdateDialog::finished() +void UpdaterDialog::acceptedSlot() +{ + if(ui->checkBoxDontShow->isChecked()) + m_mainWindow.settings().setValue(QStringLiteral("UpdaterPlugin/lastUpdateCheck"), QDate::currentDate()); + + if(!QDesktopServices::openUrl(m_url)) + QMessageBox::warning(this, tr("Could not open default webbrowser!"), tr("Could not open default webbrowser!")); + + accept(); +} + +void UpdaterDialog::rejectedSlot() +{ + if(ui->checkBoxDontShow->isChecked()) + m_mainWindow.settings().setValue(QStringLiteral("UpdaterPlugin/lastUpdateCheck"), QDate::currentDate()); + + reject(); +} + +void UpdaterDialog::finished() { if(m_reply->error() != QNetworkReply::NoError) { @@ -83,18 +102,7 @@ void UpdateDialog::finished() } } - m_settings.setLastUpdateCheck(QDate::currentDate()); + m_mainWindow.settings().setValue(QStringLiteral("UpdaterPlugin/lastUpdateCheck"), QDate::currentDate()); deleteLater(); } - -void UpdateDialog::submit() -{ - if(ui->checkBoxDontShow->isChecked()) - m_settings.setLastUpdateCheck(QDate::currentDate()); - - if(!QDesktopServices::openUrl(m_url)) - QMessageBox::warning(this, tr("Could not open default webbrowser!"), tr("Could not open default webbrowser!")); - - accept(); -} diff --git a/plugins/updaterplugin/updaterdialog.h b/plugins/updaterplugin/updaterdialog.h new file mode 100644 index 0000000..c714506 --- /dev/null +++ b/plugins/updaterplugin/updaterdialog.h @@ -0,0 +1,33 @@ +#ifndef UPDATERDIALOG_H +#define UPDATERDIALOG_H + +#include +#include + +class QNetworkReply; + +namespace Ui { class UpdaterDialog; } +class MainWindow; + +class UpdaterDialog : public QDialog +{ + Q_OBJECT + +public: + explicit UpdaterDialog(MainWindow &parent); + ~UpdaterDialog(); + +private Q_SLOTS: + void acceptedSlot(); + void rejectedSlot(); + void finished(); + +private: + Ui::UpdaterDialog *ui; + MainWindow &m_mainWindow; + QNetworkReply *m_reply; + + QUrl m_url; +}; + +#endif // UPDATERDIALOG_H diff --git a/zeiterfassunglib/dialogs/updatedialog.ui b/plugins/updaterplugin/updaterdialog.ui similarity index 96% rename from zeiterfassunglib/dialogs/updatedialog.ui rename to plugins/updaterplugin/updaterdialog.ui index c0841db..8d8f8d3 100644 --- a/zeiterfassunglib/dialogs/updatedialog.ui +++ b/plugins/updaterplugin/updaterdialog.ui @@ -1,7 +1,7 @@ - UpdateDialog - + UpdaterDialog + 0 diff --git a/plugins/updaterplugin/updaterplugin.cpp b/plugins/updaterplugin/updaterplugin.cpp new file mode 100644 index 0000000..c38ace3 --- /dev/null +++ b/plugins/updaterplugin/updaterplugin.cpp @@ -0,0 +1,39 @@ +#include "updaterplugin.h" + +#include +#include +#include +#include + +#include "mainwindow.h" +#include "zeiterfassungsettings.h" +#include "zeiterfassungapi.h" + +#include "updaterdialog.h" + +UpdaterPlugin::UpdaterPlugin(QObject *parent) : + ZeiterfassungPlugin(parent) +{ + qDebug() << "called"; + + static auto dir = QDir(QCoreApplication::applicationDirPath()).absoluteFilePath(QStringLiteral("translations")); + + if(m_translator.load(QLocale(), QStringLiteral("updaterplugin"), QStringLiteral("_"), dir)) + { + if(!QCoreApplication::installTranslator(&m_translator)) + { + qWarning() << "could not install translation updaterplugin"; + } + } + else + { + qWarning() << "could not load translation updaterplugin"; + } +} + +void UpdaterPlugin::attachTo(MainWindow &mainWindow) +{ + if(mainWindow.settings().value(QStringLiteral("UpdaterPlugin/lastUpdateCheck")).toDate().isNull() || + mainWindow.settings().value(QStringLiteral("UpdaterPlugin/lastUpdateCheck")).toDate() < QDate::currentDate()) + new UpdaterDialog(mainWindow); +} diff --git a/plugins/updaterplugin/updaterplugin.h b/plugins/updaterplugin/updaterplugin.h new file mode 100644 index 0000000..51311b2 --- /dev/null +++ b/plugins/updaterplugin/updaterplugin.h @@ -0,0 +1,27 @@ +#ifndef UPDATERPLUGIN_H +#define UPDATERPLUGIN_H + +#include +#include + +#include "zeiterfassungplugin.h" + +class MainWindow; + +class Q_DECL_EXPORT UpdaterPlugin : public ZeiterfassungPlugin +{ + Q_OBJECT + Q_PLUGIN_METADATA(IID "dbsoftware.zeiterfassung.plugin/1.0" FILE "updaterplugin.json") + Q_INTERFACES(ZeiterfassungPlugin) + +public: + explicit UpdaterPlugin(QObject *parent = Q_NULLPTR); + + // ZeiterfassungPlugin interface + void attachTo(MainWindow &mainWindow) Q_DECL_OVERRIDE; + +private: + QTranslator m_translator; +}; + +#endif // UPDATERPLUGIN_H diff --git a/plugins/updaterplugin/updaterplugin.json b/plugins/updaterplugin/updaterplugin.json new file mode 100644 index 0000000..e69de29 diff --git a/plugins/updaterplugin/updaterplugin.pro b/plugins/updaterplugin/updaterplugin.pro new file mode 100644 index 0000000..0e6f1ce --- /dev/null +++ b/plugins/updaterplugin/updaterplugin.pro @@ -0,0 +1,37 @@ +QT += core network gui widgets + +TARGET = updaterplugin +TEMPLATE = lib + +CONFIG += shared c++14 + +DESTDIR = $${OUT_PWD}/../../bin/plugins/zeiterfassung + +LIBS += -L$$OUT_PWD/../../lib -lzeiterfassunglib + +INCLUDEPATH += $$PWD/../../zeiterfassunglib +DEPENDPATH += $$PWD/../../zeiterfassunglib + +DEFINES += QT_DEPRECATED_WARNINGS QT_DISABLE_DEPRECATED_BEFORE=0x060000 QT_MESSAGELOGCONTEXT + +HEADERS += updaterdialog.h \ + updaterplugin.h + +SOURCES += updaterdialog.cpp \ + updaterplugin.cpp + +FORMS += updaterdialog.ui + +RESOURCES += + +TRANSLATIONS += translations/updaterplugin_en.ts \ + translations/updaterplugin_de.ts + +OTHER_FILES += updaterplugin.json + +include(../../lrelease.pri) + +COMPILED_TRANSLATIONS += $${OUT_PWD}/translations/updaterplugin_en.qm \ + $${OUT_PWD}/translations/updaterplugin_de.qm + +include(../copy_translations.pri) diff --git a/plugins/weatherplugin/translations/weatherplugin_de.ts b/plugins/weatherplugin/translations/weatherplugin_de.ts new file mode 100644 index 0000000..40f7555 --- /dev/null +++ b/plugins/weatherplugin/translations/weatherplugin_de.ts @@ -0,0 +1,32 @@ + + + + + WeatherWidget + + + Loading... + Lade... + + + + Request failed + Anfrage fehlgeschlagen + + + + Parsing failed + Parsen fehlgeschlagen + + + + Not an json obj + Kein json obj + + + + %0 (%1°C) + %0 (%1°C) + + + diff --git a/plugins/weatherplugin/translations/weatherplugin_en.ts b/plugins/weatherplugin/translations/weatherplugin_en.ts new file mode 100644 index 0000000..c4bb548 --- /dev/null +++ b/plugins/weatherplugin/translations/weatherplugin_en.ts @@ -0,0 +1,32 @@ + + + + + WeatherWidget + + + Loading... + + + + + Request failed + + + + + Parsing failed + + + + + Not an json obj + + + + + %0 (%1°C) + + + + diff --git a/plugins/weatherplugin/weatherplugin.cpp b/plugins/weatherplugin/weatherplugin.cpp index 0be043f..b308b11 100644 --- a/plugins/weatherplugin/weatherplugin.cpp +++ b/plugins/weatherplugin/weatherplugin.cpp @@ -1,9 +1,36 @@ #include "weatherplugin.h" #include +#include +#include +#include +#include + +#include "mainwindow.h" + +#include "weatherwidget.h" WeatherPlugin::WeatherPlugin(QObject *parent) : ZeiterfassungPlugin(parent) { + qDebug() << "called"; + static auto dir = QDir(QCoreApplication::applicationDirPath()).absoluteFilePath(QStringLiteral("translations")); + + if(m_translator.load(QLocale(), QStringLiteral("weatherplugin"), QStringLiteral("_"), dir)) + { + if(!QCoreApplication::installTranslator(&m_translator)) + { + qWarning() << "could not install translation weatherplugin"; + } + } + else + { + qWarning() << "could not load translation weatherplugin"; + } +} + +void WeatherPlugin::attachTo(MainWindow &mainWindow) +{ + mainWindow.statusBar()->addWidget(new WeatherWidget(mainWindow)); } diff --git a/plugins/weatherplugin/weatherplugin.h b/plugins/weatherplugin/weatherplugin.h index f8abc9b..c4dc84f 100644 --- a/plugins/weatherplugin/weatherplugin.h +++ b/plugins/weatherplugin/weatherplugin.h @@ -2,6 +2,7 @@ #define WEATHERPLUGIN_H #include +#include #include "zeiterfassungplugin.h" @@ -15,6 +16,10 @@ public: explicit WeatherPlugin(QObject *parent = Q_NULLPTR); // ZeiterfassungPlugin interface + void attachTo(MainWindow &mainWindow) Q_DECL_OVERRIDE; + +private: + QTranslator m_translator; }; #endif // WEATHERPLUGIN_H diff --git a/plugins/weatherplugin/weatherplugin.pro b/plugins/weatherplugin/weatherplugin.pro index b67c6dd..43118e3 100644 --- a/plugins/weatherplugin/weatherplugin.pro +++ b/plugins/weatherplugin/weatherplugin.pro @@ -14,8 +14,24 @@ DEPENDPATH += $$PWD/../../zeiterfassunglib DEFINES += QT_DEPRECATED_WARNINGS QT_DISABLE_DEPRECATED_BEFORE=0x060000 QT_MESSAGELOGCONTEXT -HEADERS += weatherplugin.h +HEADERS += weatherplugin.h \ + weatherwidget.h -SOURCES += weatherplugin.cpp +SOURCES += weatherplugin.cpp \ + weatherwidget.cpp + +FORMS += + +RESOURCES += + +TRANSLATIONS += translations/weatherplugin_en.ts \ + translations/weatherplugin_de.ts OTHER_FILES += weatherplugin.json + +include(../../lrelease.pri) + +COMPILED_TRANSLATIONS += $${OUT_PWD}/translations/weatherplugin_en.qm \ + $${OUT_PWD}/translations/weatherplugin_de.qm + +include(../copy_translations.pri) diff --git a/plugins/weatherplugin/weatherwidget.cpp b/plugins/weatherplugin/weatherwidget.cpp new file mode 100644 index 0000000..76efa1a --- /dev/null +++ b/plugins/weatherplugin/weatherwidget.cpp @@ -0,0 +1,92 @@ +#include "weatherwidget.h" + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include "mainwindow.h" +#include "zeiterfassungsettings.h" +#include "zeiterfassungapi.h" + +WeatherWidget::WeatherWidget(MainWindow &mainWindow) : + QLabel(&mainWindow), + m_mainWindow(mainWindow) +{ + setFrameShape(QFrame::Panel); + setFrameShadow(QFrame::Sunken); + + connect(&m_mainWindow, &MainWindow::refreshEverything, this, &WeatherWidget::refresh); + + refresh(); +} + +void WeatherWidget::refresh() +{ + setText(tr("Loading...")); + + auto url = m_mainWindow.settings().value(QStringLiteral("WeatherPlugin/url"), + QStringLiteral("http://api.openweathermap.org/data/2.5/weather?q=Graz,AT&units=metric&APPID=40f6c892c6162680c6c9235169dc9f83")).toString(); + + m_reply = std::unique_ptr(m_mainWindow.erfassung().manager()->get(QNetworkRequest(QUrl(url)))); + connect(m_reply.get(), &QNetworkReply::finished, this, &WeatherWidget::finished); +} + +void WeatherWidget::finished() +{ + if(m_reply->error() != QNetworkReply::NoError) + { + qWarning() << m_reply->errorString(); + setText(tr("Request failed")); + goto after; + } + + { + QJsonParseError error; + + auto document = QJsonDocument::fromJson(m_reply->readAll(), &error); + if(error.error != QJsonParseError::NoError) + { + qWarning() << error.errorString(); + setText(tr("Parsing failed")); + goto after; + } + + if(!document.isObject()) + { + setText(tr("Not an json obj")); + goto after; + } + + auto obj = document.object(); + + if(!obj.contains(QStringLiteral("weather"))) + { + qWarning() << "no weather" << obj; + setText("No weater found"); + goto after; + } + + if(!obj.contains(QStringLiteral("main"))) + { + qWarning() << "no main" << obj; + setText("No main found"); + goto after; + } + + auto weaterObj = obj.value(QStringLiteral("weather")).toArray(); + auto mainObj = obj.value(QStringLiteral("main")).toObject(); + + setText(tr("%0 (%1°C)").arg(weaterObj.first().toObject().value(QStringLiteral("main")).toString()) + .arg(mainObj.value(QStringLiteral("temp")).toDouble())); + } + + after: + m_reply = Q_NULLPTR; +} diff --git a/plugins/weatherplugin/weatherwidget.h b/plugins/weatherplugin/weatherwidget.h new file mode 100644 index 0000000..17532c5 --- /dev/null +++ b/plugins/weatherplugin/weatherwidget.h @@ -0,0 +1,28 @@ +#ifndef WEATHERWIDGET_H +#define WEATHERWIDGET_H + +#include + +#include +#include + +class MainWindow; + +class WeatherWidget : public QLabel +{ + Q_OBJECT + +public: + explicit WeatherWidget(MainWindow &mainWindow); + +private Q_SLOTS: + void refresh(); + void finished(); + +private: + MainWindow &m_mainWindow; + + std::unique_ptr m_reply; +}; + +#endif // WEATHERWIDGET_H diff --git a/zeiterfassung/main.cpp b/zeiterfassung/main.cpp index f06aea9..6bff758 100755 --- a/zeiterfassung/main.cpp +++ b/zeiterfassung/main.cpp @@ -1,6 +1,5 @@ #include #include -#include #include #include #include @@ -35,14 +34,11 @@ struct { QVector plugins; -bool loadAndInstallTranslator(QTranslator &translator, - const QLocale &locale, - const QString &filename, - const QString &prefix = QString(), - const QString &directory = QString(), - const QString &suffix = QString()) +bool loadAndInstallTranslator(QTranslator &translator, const QString &filename) { - if(!translator.load(locale, filename, prefix, directory, suffix)) + static auto dir = QDir(QCoreApplication::applicationDirPath()).absoluteFilePath(QStringLiteral("translations")); + + if(!translator.load(QLocale(), filename, QStringLiteral("_"), dir)) { qWarning() << "could not load translation" << filename; return false; @@ -80,13 +76,11 @@ bool loadTranslations(QSplashScreen &splashScreen, ZeiterfassungSettings &settin settings.setLanguage(dialog.language()); } - QLocale locale(settings.language(), QLocale::Austria); - QLocale::setDefault(locale); + QLocale::setDefault(QLocale(settings.language(), QLocale::Austria)); - auto translationsDir = QDir(QCoreApplication::applicationDirPath()).absoluteFilePath(QStringLiteral("translations")); - loadAndInstallTranslator(translators.qtTranslator, locale, QStringLiteral("qt"), QStringLiteral("_"), translationsDir); - loadAndInstallTranslator(translators.zeiterfassungTranslator, locale, QStringLiteral("zeiterfassung"), QStringLiteral("_"), translationsDir); - loadAndInstallTranslator(translators.zeiterfassunglibTranslator, locale, QStringLiteral("zeiterfassunglib"), QStringLiteral("_"), translationsDir); + loadAndInstallTranslator(translators.qtTranslator, QStringLiteral("qt")); + loadAndInstallTranslator(translators.zeiterfassungTranslator, QStringLiteral("zeiterfassung")); + loadAndInstallTranslator(translators.zeiterfassunglibTranslator, QStringLiteral("zeiterfassunglib")); return true; } @@ -175,11 +169,7 @@ bool loadLoginPage(QSplashScreen &splashScreen, ZeiterfassungSettings &settings, again: auto reply = erfassung.doLoginPage(); - { - QEventLoop eventLoop; - QObject::connect(reply.get(), &ZeiterfassungReply::finished, &eventLoop, &QEventLoop::quit); - eventLoop.exec(); - } + reply->waitForFinished(); if(!reply->success()) { @@ -222,11 +212,7 @@ bool doAuthentication(QSplashScreen &splashScreen, ZeiterfassungSettings &settin again: auto reply = erfassung.doLogin(settings.username(), settings.password()); - { - QEventLoop eventLoop; - QObject::connect(reply.get(), &ZeiterfassungReply::finished, &eventLoop, &QEventLoop::quit); - eventLoop.exec(); - } + reply->waitForFinished(); if(!reply->success()) { @@ -257,11 +243,7 @@ bool loadUserInfo(QSplashScreen &splashScreen, ZeiterfassungApi &erfassung, GetU { auto reply = erfassung.doUserInfo(); - { - QEventLoop eventLoop; - QObject::connect(reply.get(), &ZeiterfassungReply::finished, &eventLoop, &QEventLoop::quit); - eventLoop.exec(); - } + reply->waitForFinished(); if(!reply->success()) { @@ -291,10 +273,18 @@ bool loadPlugins(QSplashScreen &splashScreen) for(const auto &fileInfo : dir.entryInfoList(QDir::Files)) { if(fileInfo.isSymLink()) + { + qWarning() << "skipping" << fileInfo.fileName() << "because symlink"; continue; // to skip unix so symlinks + } if(!QLibrary::isLibrary(fileInfo.filePath())) + { + qWarning() << "skipping" << fileInfo.fileName() << "because no QLibrary"; continue; // to skip windows junk files + } + + qDebug() << "loading" << fileInfo.fileName(); QPluginLoader loader(fileInfo.filePath()); if(!loader.load()) diff --git a/zeiterfassung/translations/zeiterfassung_de.ts b/zeiterfassung/translations/zeiterfassung_de.ts index 9206edb..777228f 100644 --- a/zeiterfassung/translations/zeiterfassung_de.ts +++ b/zeiterfassung/translations/zeiterfassung_de.ts @@ -20,113 +20,113 @@ main - + Loading settings... Lade Einstellungen... - + Loading translations... Lade Übersetzungen... - - + + Invalid language selection! Ungültige Sprachauswahl! - + You did not select a valid language! Sie haben keine gültige Sprachauswahl getroffen! - + Loading theme... Lade Aussehen... - - - - + + + + Could not load theme! Konnte Aussehen nicht laden! - + Theme file does not exist! Aussehen-Datei existiert nicht! - + Loading login page... Lade Login-Seite... - - + + Could not access Zeiterfassung! Konnte Zeiterfassung nicht erreichen! - + Base url Basis URL - + Please enter the base url to the Zeiterfassung: Bitte geben Sie die Basis URL zur Zeiterfassung ein: - + Authenticating... Authentifiziere... - - + + Could not authenticate with Zeiterfassung! Konnte nicht mit Zeiterfassung authentifizieren! - + Getting user information... Hole Benutzer Information... - - + + Could not get user information! Konnte Benutzer Information nicht holen! - - + + Could not load plugin %0! Konnte Plugin %0 nicht laden! - - + + Plugin not valid %0! Plugin %0 nicht gültig! - + Loading strip layouts... Lade Streifenlayouts... - - - - - - - - + + + + + + + + Could not load strips! Konnte Streifenlayouts nicht laden! diff --git a/zeiterfassung/translations/zeiterfassung_en.ts b/zeiterfassung/translations/zeiterfassung_en.ts index 81507c1..0229025 100644 --- a/zeiterfassung/translations/zeiterfassung_en.ts +++ b/zeiterfassung/translations/zeiterfassung_en.ts @@ -20,113 +20,113 @@ main - + Loading settings... - + Loading translations... - - + + Invalid language selection! - + You did not select a valid language! - + Loading theme... - - - - + + + + Could not load theme! - + Theme file does not exist! - + Loading login page... - - + + Could not access Zeiterfassung! - + Base url - + Please enter the base url to the Zeiterfassung: - + Authenticating... - - + + Could not authenticate with Zeiterfassung! - + Getting user information... - - + + Could not get user information! - - + + Could not load plugin %0! - - + + Plugin not valid %0! - + Loading strip layouts... - - - - - - - - + + + + + + + + Could not load strips! diff --git a/zeiterfassung/unix/start.sh b/zeiterfassung/unix/start.sh index 59aa5f8..b3c1ca6 100755 --- a/zeiterfassung/unix/start.sh +++ b/zeiterfassung/unix/start.sh @@ -1 +1,3 @@ +#!/bin/bash +cd "${0%/*}" LD_LIBRARY_PATH=../lib ./zeiterfassung diff --git a/zeiterfassunglib/dialogs/updatedialog.h b/zeiterfassunglib/dialogs/updatedialog.h deleted file mode 100644 index d2a9c08..0000000 --- a/zeiterfassunglib/dialogs/updatedialog.h +++ /dev/null @@ -1,35 +0,0 @@ -#ifndef UPDATEDIALOG_H -#define UPDATEDIALOG_H - -#include -#include - -#include "zeiterfassunglib_global.h" - -class QNetworkAccessManager; -class QNetworkReply; - -class ZeiterfassungSettings; -namespace Ui { class UpdateDialog; } - -class ZEITERFASSUNGLIBSHARED_EXPORT UpdateDialog : public QDialog -{ - Q_OBJECT - -public: - explicit UpdateDialog(ZeiterfassungSettings &settings, QNetworkAccessManager *manager, QWidget *parent = Q_NULLPTR); - ~UpdateDialog(); - -private Q_SLOTS: - void finished(); - void submit(); - -private: - Ui::UpdateDialog *ui; - ZeiterfassungSettings &m_settings; - QNetworkReply *m_reply; - - QUrl m_url; -}; - -#endif // UPDATEDIALOG_H diff --git a/zeiterfassunglib/mainwindow.cpp b/zeiterfassunglib/mainwindow.cpp index 6c3e90d..29abb46 100644 --- a/zeiterfassunglib/mainwindow.cpp +++ b/zeiterfassunglib/mainwindow.cpp @@ -7,7 +7,6 @@ #include #include #include -#include #include #include #include @@ -22,9 +21,7 @@ #include "stripswidget.h" #include "dialogs/aboutmedialog.h" #include "dialogs/settingsdialog.h" -#include "dialogs/updatedialog.h" #include "replies/getprojectsreply.h" -#include "replies/getauswertungreply.h" #include "replies/createbookingreply.h" #include "replies/createtimeassignmentreply.h" #include "replies/updatetimeassignmentreply.h" @@ -37,19 +34,10 @@ 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); - for(quint8 i = 0; i < 7; i++) - { - m_stripsWidgets[i] = new StripsWidget(*this, ui->widgetWeek); - connect(m_stripsWidgets[i], &StripsWidget::refreshingChanged, this, &MainWindow::refreshingChanged); - ui->layoutWeek->addWidget(m_stripsWidgets[i]); - } - setWindowTitle(tr("Zeiterfassung - %0 (%1)").arg(m_userInfo.text).arg(m_userInfo.email)); ui->actionQuit->setShortcut(QKeySequence::Quit); @@ -57,9 +45,7 @@ MainWindow::MainWindow(ZeiterfassungSettings &settings, ZeiterfassungApi &erfass connect(ui->actionToday, &QAction::triggered, [=](){ ui->dateEditDate->setDate(QDate::currentDate()); }); ui->actionRefresh->setShortcut(QKeySequence::Refresh); - connect(ui->actionRefresh, &QAction::triggered, this, [=](){ dateChanged(true); }); - - connect(ui->actionAuswertung, &QAction::triggered, this, &MainWindow::openAuswertung); + connect(ui->actionRefresh, &QAction::triggered, this, &MainWindow::refreshEverything); connect(ui->actionAboutMe, &QAction::triggered, [=](){ AboutMeDialog(userInfo, this).exec(); }); connect(ui->actionSettings, &QAction::triggered, [=](){ SettingsDialog(m_settings, this).exec(); }); @@ -69,7 +55,7 @@ MainWindow::MainWindow(ZeiterfassungSettings &settings, ZeiterfassungApi &erfass connect(ui->actionAboutQt, &QAction::triggered, [=](){ QMessageBox::aboutQt(this); }); ui->dateEditDate->setDate(QDate::currentDate()); - connect(ui->dateEditDate, &QDateTimeEdit::dateChanged, this, [=](){ dateChanged(false); }); + connect(ui->dateEditDate, &QDateTimeEdit::dateChanged, this, &MainWindow::dateChangedSlot); connect(ui->pushButtonPrev, &QAbstractButton::pressed, [=](){ ui->dateEditDate->setDate(ui->dateEditDate->date().addDays(-1)); }); connect(ui->pushButtonNext, &QAbstractButton::pressed, [=](){ ui->dateEditDate->setDate(ui->dateEditDate->date().addDays(1)); }); @@ -90,17 +76,14 @@ 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); + for(quint8 i = 0; i < 7; i++) + { + m_stripsWidgets[i] = new StripsWidget(*this, ui->widgetWeek); + connect(this, &MainWindow::refreshEverything, m_stripsWidgets[i], &StripsWidget::refresh); + ui->layoutWeek->addWidget(m_stripsWidgets[i]); + } - dateChanged(); - - if(settings.lastUpdateCheck().isNull() || settings.lastUpdateCheck() < QDate::currentDate()) - new UpdateDialog(settings, erfassung.manager(), this); + dateChangedSlot(ui->dateEditDate->date()); } MainWindow::~MainWindow() @@ -128,6 +111,11 @@ QMenu *MainWindow::menuAbout() const return ui->menuAbout; } +QToolBar *MainWindow::toolBar() const +{ + return ui->mainToolBar; +} + ZeiterfassungSettings &MainWindow::settings() const { return m_settings; @@ -148,6 +136,16 @@ StripFactory &MainWindow::stripFactory() const return m_stripFactory; } +QDate MainWindow::date() const +{ + return ui->dateEditDate->date(); +} + +void MainWindow::setDate(const QDate &date) +{ + ui->dateEditDate->setDate(date); +} + const QMap &MainWindow::projects() const { return m_projects; @@ -176,66 +174,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; @@ -247,11 +185,7 @@ void MainWindow::pushButtonStartPressed() timeNormalise(ui->timeEditTime->time()), QTime(0, 0), QStringLiteral("K"), QStringLiteral("")); - { - QEventLoop eventLoop; - connect(reply.get(), &ZeiterfassungReply::finished, &eventLoop, &QEventLoop::quit); - eventLoop.exec(); - } + reply->waitForFinished(); if(!reply->success()) { @@ -277,11 +211,7 @@ void MainWindow::pushButtonStartPressed() timeAssignment.project, timeAssignment.subproject, timeAssignment.workpackage, timeAssignment.text); - { - QEventLoop eventLoop; - connect(reply.get(), &ZeiterfassungReply::finished, &eventLoop, &QEventLoop::quit); - eventLoop.exec(); - } + reply->waitForFinished(); if(reply->success()) timeAssignmentTime = timeAdd(timeAssignmentTime, timespan); @@ -300,11 +230,7 @@ void MainWindow::pushButtonStartPressed() ui->comboBoxProject->currentData().toString(), ui->comboBoxSubproject->currentText(), ui->comboBoxWorkpackage->currentText(), ui->comboBoxText->currentText()); - { - QEventLoop eventLoop; - connect(reply.get(), &ZeiterfassungReply::finished, &eventLoop, &QEventLoop::quit); - eventLoop.exec(); - } + reply->waitForFinished(); if(!reply->success()) { @@ -324,8 +250,7 @@ void MainWindow::pushButtonStartPressed() if(bookingsChanged) { m_currentStripWidget->refresh(); - - refreshAuswertung(); + //refreshReport(); } else m_currentStripWidget->refreshTimeAssignments(); @@ -350,11 +275,7 @@ void MainWindow::pushButtonEndPressed() timeAssignment.project, timeAssignment.subproject, timeAssignment.workpackage, timeAssignment.text); - { - QEventLoop eventLoop; - connect(reply.get(), SIGNAL(finished()), &eventLoop, SLOT(quit())); - eventLoop.exec(); - } + reply->waitForFinished(); if(!reply->success()) { @@ -369,11 +290,7 @@ void MainWindow::pushButtonEndPressed() timeNormalise(ui->timeEditTime->time()), QTime(0, 0), QStringLiteral("G"), QStringLiteral("")); - { - QEventLoop eventLoop; - connect(reply.get(), &ZeiterfassungReply::finished, &eventLoop, &QEventLoop::quit); - eventLoop.exec(); - } + reply->waitForFinished(); if(!reply->success()) { @@ -384,7 +301,7 @@ void MainWindow::pushButtonEndPressed() } m_currentStripWidget->refresh(); - refreshAuswertung(); + //refreshReport(); ui->actionToday->setEnabled(false); ui->actionRefresh->setEnabled(false); @@ -393,18 +310,17 @@ void MainWindow::pushButtonEndPressed() ui->pushButtonNext->setEnabled(false); } -void MainWindow::dateChanged(bool force) +void MainWindow::dateChangedSlot(const QDate &date) { - auto firstDayOfWeek = ui->dateEditDate->date().addDays(-(ui->dateEditDate->date().dayOfWeek() - 1)); + auto firstDayOfWeek = date.addDays(-(ui->dateEditDate->date().dayOfWeek() - 1)); for(quint8 i = 0; i < 7; i++) { - auto date = firstDayOfWeek.addDays(i); + auto weekDay = firstDayOfWeek.addDays(i); - if(force || m_stripsWidgets[i]->date() != date) - m_stripsWidgets[i]->setDate(date); + m_stripsWidgets[i]->setDate(weekDay); - if(date == ui->dateEditDate->date() && (force || m_currentStripWidget != m_stripsWidgets[i])) + if(weekDay == date && m_currentStripWidget != m_stripsWidgets[i]) { if(m_currentStripWidget) { @@ -425,39 +341,7 @@ 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); - ui->dateEditDate->setReadOnly(true); - ui->pushButtonPrev->setEnabled(false); - ui->pushButtonNext->setEnabled(false); - } -} - -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; - } + Q_EMIT dateChanged(ui->dateEditDate->date()); } void MainWindow::minimumTimeChanged() @@ -465,24 +349,6 @@ void MainWindow::minimumTimeChanged() ui->timeEditTime->setMinimumTime(m_currentStripWidget->minimumTime()); } -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(); - }); - - ui->actionToday->setEnabled(allFinished); - ui->actionRefresh->setEnabled(allFinished); - ui->dateEditDate->setReadOnly(!allFinished); - ui->pushButtonPrev->setEnabled(allFinished); - ui->pushButtonNext->setEnabled(allFinished); - } -} - void MainWindow::startEnabledChanged() { auto startEnabled = m_currentStripWidget->startEnabled(); @@ -512,19 +378,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 c74ae2a..b9d88de 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; @@ -19,8 +20,6 @@ namespace Ui { class MainWindow; } class ZeiterfassungSettings; class StripFactory; class StripsWidget; -class BookingsModel; -class TimeAssignmentsModel; class ZEITERFASSUNGLIBSHARED_EXPORT MainWindow : public QMainWindow { @@ -35,30 +34,34 @@ 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; + void setDate(const QDate &date); + const QMap &projects() const; const std::array &stripsWidgets() const; +Q_SIGNALS: + void dateChanged(const QDate &date); + void refreshEverything(); + private Q_SLOTS: void getProjectsFinished(); - void getAuswertungFinished(); void pushButtonStartPressed(); void pushButtonEndPressed(); - void dateChanged(bool force = false); - void openAuswertung(); + void dateChangedSlot(const QDate &date); void minimumTimeChanged(); - void refreshingChanged(); void startEnabledChanged(); void endEnabledChanged(); private: - void refreshAuswertung(); void updateComboboxes(); Ui::MainWindow *ui; @@ -68,19 +71,9 @@ private: StripFactory &m_stripFactory; std::unique_ptr m_getProjectsReply; - std::unique_ptr m_getAuswertungReply; - - BookingsModel *m_bookingsModel; - TimeAssignmentsModel *m_timeAssignmentsModel; 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/replies/getauswertungreply.h b/zeiterfassunglib/replies/getauswertungreply.h deleted file mode 100644 index c39e93e..0000000 --- a/zeiterfassunglib/replies/getauswertungreply.h +++ /dev/null @@ -1,30 +0,0 @@ -#ifndef GETAUSWERTUNGREPLY_H -#define GETAUSWERTUNGREPLY_H - -#include - -#include -#include - -#include "zeiterfassunglib_global.h" -#include "zeiterfassungreply.h" - -class ZEITERFASSUNGLIBSHARED_EXPORT GetAuswertungReply : public ZeiterfassungReply -{ - Q_OBJECT - -public: - GetAuswertungReply(std::unique_ptr &&reply, ZeiterfassungApi *zeiterfassung); - - const QByteArray &auswertung() const; - -private Q_SLOTS: - void request0Finished(); - void request1Finished(); - -private: - std::unique_ptr m_reply; - QByteArray m_auswertung; -}; - -#endif // GETAUSWERTUNGREPLY_H diff --git a/zeiterfassunglib/replies/getauswertungreply.cpp b/zeiterfassunglib/replies/getreportreply.cpp similarity index 59% rename from zeiterfassunglib/replies/getauswertungreply.cpp rename to zeiterfassunglib/replies/getreportreply.cpp index 3a2e0bd..b63f91f 100644 --- a/zeiterfassunglib/replies/getauswertungreply.cpp +++ b/zeiterfassunglib/replies/getreportreply.cpp @@ -1,20 +1,20 @@ -#include "getauswertungreply.h" +#include "getreportreply.h" #include "zeiterfassungapi.h" -GetAuswertungReply::GetAuswertungReply(std::unique_ptr &&reply, ZeiterfassungApi *zeiterfassung) : +GetReportReply::GetReportReply(std::unique_ptr &&reply, ZeiterfassungApi *zeiterfassung) : ZeiterfassungReply(zeiterfassung), m_reply(std::move(reply)) { - connect(m_reply.get(), &QNetworkReply::finished, this, &GetAuswertungReply::request0Finished); + connect(m_reply.get(), &QNetworkReply::finished, this, &GetReportReply::request0Finished); } -const QByteArray &GetAuswertungReply::auswertung() const +const QByteArray &GetReportReply::content() const { - return m_auswertung; + return m_content; } -void GetAuswertungReply::request0Finished() +void GetReportReply::request0Finished() { if(m_reply->error() != QNetworkReply::NoError) { @@ -29,10 +29,10 @@ void GetAuswertungReply::request0Finished() url.setPath(QString(m_reply->readAll())); m_reply = std::unique_ptr(zeiterfassung()->manager()->get(QNetworkRequest(url))); - connect(m_reply.get(), &QNetworkReply::finished, this, &GetAuswertungReply::request1Finished); + connect(m_reply.get(), &QNetworkReply::finished, this, &GetReportReply::request1Finished); } -void GetAuswertungReply::request1Finished() +void GetReportReply::request1Finished() { if(m_reply->error() != QNetworkReply::NoError) { @@ -42,7 +42,7 @@ void GetAuswertungReply::request1Finished() } setSuccess(true); - m_auswertung = m_reply->readAll(); + m_content = m_reply->readAll(); end: m_reply = Q_NULLPTR; diff --git a/zeiterfassunglib/replies/getreportreply.h b/zeiterfassunglib/replies/getreportreply.h new file mode 100644 index 0000000..1590681 --- /dev/null +++ b/zeiterfassunglib/replies/getreportreply.h @@ -0,0 +1,30 @@ +#ifndef GETREPORTREPLY_H +#define GETREPORTREPLY_H + +#include + +#include +#include + +#include "zeiterfassunglib_global.h" +#include "zeiterfassungreply.h" + +class ZEITERFASSUNGLIBSHARED_EXPORT GetReportReply : public ZeiterfassungReply +{ + Q_OBJECT + +public: + GetReportReply(std::unique_ptr &&reply, ZeiterfassungApi *zeiterfassung); + + const QByteArray &content() const; + +private Q_SLOTS: + void request0Finished(); + void request1Finished(); + +private: + std::unique_ptr m_reply; + QByteArray m_content; +}; + +#endif // GETREPORTREPLY_H diff --git a/zeiterfassunglib/replies/zeiterfassungreply.cpp b/zeiterfassunglib/replies/zeiterfassungreply.cpp index 0e59b3a..6784956 100644 --- a/zeiterfassunglib/replies/zeiterfassungreply.cpp +++ b/zeiterfassunglib/replies/zeiterfassungreply.cpp @@ -1,5 +1,7 @@ #include "zeiterfassungreply.h" +#include + #include "zeiterfassungapi.h" ZeiterfassungReply::ZeiterfassungReply(ZeiterfassungApi *zeiterfassung) : @@ -20,6 +22,13 @@ const QString &ZeiterfassungReply::message() const return m_message; } +void ZeiterfassungReply::waitForFinished() +{ + QEventLoop eventLoop; + connect(this, &ZeiterfassungReply::finished, &eventLoop, &QEventLoop::quit); + eventLoop.exec(); +} + ZeiterfassungApi *ZeiterfassungReply::zeiterfassung() const { return m_zeiterfassung; diff --git a/zeiterfassunglib/replies/zeiterfassungreply.h b/zeiterfassunglib/replies/zeiterfassungreply.h index 6ac1b68..05187e3 100644 --- a/zeiterfassunglib/replies/zeiterfassungreply.h +++ b/zeiterfassunglib/replies/zeiterfassungreply.h @@ -17,6 +17,8 @@ public: bool success() const; const QString &message() const; + void waitForFinished(); + Q_SIGNALS: void finished(); 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 diff --git a/zeiterfassunglib/stripswidget.cpp b/zeiterfassunglib/stripswidget.cpp index 07814bc..34f41a8 100644 --- a/zeiterfassunglib/stripswidget.cpp +++ b/zeiterfassunglib/stripswidget.cpp @@ -23,8 +23,8 @@ StripsWidget::StripsWidget(MainWindow &mainWindow, QWidget *parent) : { auto layout = new QVBoxLayout(this); - m_headerLayout = new QHBoxLayout(this); - m_label = new QLabel(this); + m_headerLayout = new QHBoxLayout; + m_label = new QLabel; { auto font = m_label->font(); font.setBold(true); @@ -33,7 +33,7 @@ StripsWidget::StripsWidget(MainWindow &mainWindow, QWidget *parent) : m_headerLayout->addWidget(m_label, 1); layout->addLayout(m_headerLayout); - m_stripsLayout = new QVBoxLayout(this); + m_stripsLayout = new QVBoxLayout; layout->addLayout(m_stripsLayout); layout->addStretch(1); diff --git a/zeiterfassunglib/translations/zeiterfassunglib_de.ts b/zeiterfassunglib/translations/zeiterfassunglib_de.ts index bbace03..873a88d 100644 --- a/zeiterfassunglib/translations/zeiterfassunglib_de.ts +++ b/zeiterfassunglib/translations/zeiterfassunglib_de.ts @@ -54,63 +54,6 @@ Passwort: - - BookingDialog - - - - Booking - Buchung - - - - Time: - Zeit: - - - - Timespan: - Zeitspanne: - - - - Type: - Typ: - - - - Text: - Text: - - - - BookingsModel - - - ID - ID - - - - Time - Zeit - - - - Timespan - Zeitspanne - - - - Type - Typ - - - - Text - Text - - CreateBookingReply @@ -173,15 +116,6 @@ - - GetAuswertungReply - - - - Request error occured: %0 - - - GetBookingsReply @@ -246,6 +180,15 @@ + + GetReportReply + + + + Request error occured: %0 + + + GetTimeAssignmentsReply @@ -376,8 +319,8 @@ - - + + Start Kommen @@ -387,263 +330,117 @@ Gehen - - Optimized view - Optimierte Anzeige - - - - Advanced view - Erweiterte Anzeige - - - - Bookings - Buchungen - - - - Time assignments - Kontierungen - - - + &File &Datei - + &About &Über - + &View &Ansicht - + &Tools &Werkzeuge - + &Quit &Beenden - + About &Me Über &mich - + About &zeiterfassung Über &zeiterfassung - + About &Qt Über &Qt - + &Today &Heute - + &Refresh everything Alles &neu laden - - &Auswertung - - - - + &Settings &Einstellungen - + Help Hilfe - + Zeiterfassung - %0 (%1) Zeiterfassung - %0 (%1) - - - Could not open auswertung! - - - - - Could not open default PDF viewer! - Konnte den PDF-Anzeiger nicht öffnen! - - - + Subproject Subprojekt - + Workpackage Arbeitspaket - + Text Text - - - - - %0: %1 - %0: %1 - - - - - ??? - ??? - - - - - Balance - Saldo - - - - - Holidays - Urlaubstage - - - - + + Could not load bookings! Konnte Buchungen nicht laden! - - Could not load Auswertung! - - - - - %0h - %0h - - - - Could not delete booking! - Konnte Buchung nicht löschen! - - - - Edit booking - Buchung bearbeiten - - - - Delete booking - Buchung löschen - - - - Could not edit booking! - Konnte Buchung nicht bearbeiten! - - - - Create booking - Buchung erstellen - - - - - n/a - n/v - - - - Refresh bookings - Buchungen aktualisieren - - - - - + + Could not create booking! Konnte Buchung nicht erstellen! - - Do you really want to delete the booking? - Möchten Sie die Buchung wirklich löschen? - - - - Refresh time assignments - Kontierungen aktualisieren - - - - Edit time assignment - Kontierung bearbeiten - - - - Delete time assignment - Kontierung löschen - - - - - + + Could not edit time assignment! Konnte Kontierung nicht bearbeiten! - - Do you really want to delete the time assignment? - Möchten Sie die Kontierung wirklich löschen? - - - - Could not delete time assignment! - Konnte Kontierung nicht löschen! - - - - + + %0 (%1) %0 (%1) - - Create time assignment - Kontierung erstellen - - - - + Could not create time assignment! Konnte Kontierung nicht erstellen! - - + + Switch Wechseln @@ -729,109 +526,111 @@ StripsWidget + + Loading... Lade... - + Missing booking! Kontierung fehlend! - + Expected start booking, instead got type %0 Booking ID: %1 - - + + %0: %1 %0: %1 - + Break Pause - - - + + + %0h %0h - - - - - + + + + + HH:mm HH:mm - + Missing time assignment! Kontierung fehlend! - - - + + + Expected %0 but received %1 in time assignment. Time assignment ID: %2 - - - - - - - - - + + + + + + + + + HH:mm:ss HH:mm:ss - - + + There is another booking after an unfinished time assignment. Booking ID: %0 Time assignment ID: %1 - - - + + + There is another time assignment after an unfinished time assignment. Time assignment ID: %0 Time assignment ID: %1 - + The last time assignment is finished without end booking Time assignment ID: %0 - + Expected end booking, instead got type %0 Booking ID: %1 - + Missing time assignment! Missing: %0 Kontierung fehlend! %0 nicht kontiert - + Assigned time Kontierte Zeit @@ -846,14 +645,14 @@ Booking ID: %1 %0 (%1) - + Time assignment time longer than booking time! Time assignment: %0 Booking: %1 - + Strip rendering aborted due error. Your bookings and time assignments for this day are in an illegal state! @@ -899,94 +698,11 @@ Your bookings and time assignments for this day are in an illegal state!Ungültig - + Open Offen - - TimeAssignmentDialog - - - - Time assignment - Kontierung - - - - Time: - Zeit: - - - - Timespan: - Zeitspanne: - - - - Project: - Projekt: - - - - Subproject: - Subprojekt: - - - - Workpackage: - Arbeitspaket: - - - - Text: - Text: - - - - - %0 (%1) - %0 (%1) - - - - TimeAssignmentsModel - - - ID - ID - - - - Time - Zeit - - - - Timespan - Zeitspanne - - - - Project - Projekt - - - - Subproject - Subprojekt - - - - Workpackage - Arbeitspaket - - - - Text - Text - - UpdateBookingReply @@ -1010,30 +726,6 @@ Your bookings and time assignments for this day are in an illegal state! - - UpdateDialog - - - - New update available! - Neues Update verfügbar! - - - - There is a new release available to download! - Es ist ein neues Update verfügbar zum Download! - - - - Dont show today anymore - Heute nicht mehr anzeigen - - - - Could not open default webbrowser! - Konnte den Standard-Browser nicht öffnen! - - UpdateTimeAssignmentReply diff --git a/zeiterfassunglib/translations/zeiterfassunglib_en.ts b/zeiterfassunglib/translations/zeiterfassunglib_en.ts index c58d108..2e4ce17 100644 --- a/zeiterfassunglib/translations/zeiterfassunglib_en.ts +++ b/zeiterfassunglib/translations/zeiterfassunglib_en.ts @@ -54,63 +54,6 @@ - - BookingDialog - - - - Booking - - - - - Time: - - - - - Timespan: - - - - - Type: - - - - - Text: - - - - - BookingsModel - - - ID - - - - - Time - - - - - Timespan - - - - - Type - - - - - Text - - - CreateBookingReply @@ -173,15 +116,6 @@ - - GetAuswertungReply - - - - Request error occured: %0 - - - GetBookingsReply @@ -246,6 +180,15 @@ + + GetReportReply + + + + Request error occured: %0 + + + GetTimeAssignmentsReply @@ -376,8 +319,8 @@ - - + + Start @@ -387,263 +330,117 @@ - - Optimized view - - - - - Advanced view - - - - - Bookings - - - - - Time assignments - - - - + &File - + &About - + &View - + &Tools - + &Quit - + About &Me - + About &zeiterfassung - + About &Qt - + &Today - + &Refresh everything - - &Auswertung - - - - + &Settings - + Help - + Zeiterfassung - %0 (%1) - + Subproject - + Workpackage - + Text - - - ??? - - - - - + + Could not load bookings! - - Could not load Auswertung! - - - - - - n/a - - - - - %0h - - - - - - - - %0: %1 - - - - - - Balance - - - - - - Holidays - - - - - Create booking - - - - - Refresh bookings - - - - - - + + Could not create booking! - - Edit booking - - - - - Delete booking - - - - - Could not edit booking! - - - - - Do you really want to delete the booking? - - - - - Could not delete booking! - - - - - Create time assignment - - - - - Refresh time assignments - - - - - + Could not create time assignment! - - Edit time assignment - - - - - Delete time assignment - - - - - - + + Could not edit time assignment! - - Do you really want to delete the time assignment? - - - - - Could not delete time assignment! - - - - - - Could not open auswertung! - - - - - Could not open default PDF viewer! - - - - - + + Switch - - + + %0 (%1) @@ -729,121 +526,123 @@ StripsWidget + + Loading... - + Missing booking! - + Expected start booking, instead got type %0 Booking ID: %1 - - + + %0: %1 - + Break - - - + + + %0h - - - - - + + + + + HH:mm - + Missing time assignment! - - - + + + Expected %0 but received %1 in time assignment. Time assignment ID: %2 - - - - - - - - - + + + + + + + + + HH:mm:ss - - + + There is another booking after an unfinished time assignment. Booking ID: %0 Time assignment ID: %1 - - - + + + There is another time assignment after an unfinished time assignment. Time assignment ID: %0 Time assignment ID: %1 - + The last time assignment is finished without end booking Time assignment ID: %0 - + Expected end booking, instead got type %0 Booking ID: %1 - + Missing time assignment! Missing: %0 - + Time assignment time longer than booking time! Time assignment: %0 Booking: %1 - + Assigned time - + Strip rendering aborted due error. Your bookings and time assignments for this day are in an illegal state! @@ -899,94 +698,11 @@ Your bookings and time assignments for this day are in an illegal state! - + Open - - TimeAssignmentDialog - - - - Time assignment - - - - - Time: - - - - - Timespan: - - - - - Project: - - - - - Subproject: - - - - - Workpackage: - - - - - Text: - - - - - - %0 (%1) - - - - - TimeAssignmentsModel - - - ID - - - - - Time - - - - - Timespan - - - - - Project - - - - - Subproject - - - - - Workpackage - - - - - Text - - - UpdateBookingReply @@ -1010,30 +726,6 @@ Your bookings and time assignments for this day are in an illegal state! - - UpdateDialog - - - - New update available! - - - - - There is a new release available to download! - - - - - Dont show today anymore - - - - - Could not open default webbrowser! - - - UpdateTimeAssignmentReply diff --git a/zeiterfassunglib/zeiterfassungapi.cpp b/zeiterfassunglib/zeiterfassungapi.cpp index 84bebfa..ffdfa24 100644 --- a/zeiterfassunglib/zeiterfassungapi.cpp +++ b/zeiterfassunglib/zeiterfassungapi.cpp @@ -13,7 +13,7 @@ #include "replies/createtimeassignmentreply.h" #include "replies/deletebookingreply.h" #include "replies/deletetimeassignmentreply.h" -#include "replies/getauswertungreply.h" +#include "replies/getreportreply.h" #include "replies/getbookingsreply.h" #include "replies/getpresencestatusreply.h" #include "replies/getprojectsreply.h" @@ -55,8 +55,6 @@ std::unique_ptr ZeiterfassungApi::doLoginPage() auto reply = std::unique_ptr(m_manager->get(request)); - qDebug() << reply->parent(); - return std::make_unique(std::move(reply), this); } @@ -288,7 +286,7 @@ std::unique_ptr ZeiterfassungApi::doGetProjects(int userId, co return std::make_unique(std::move(reply), this); } -std::unique_ptr ZeiterfassungApi::doGetAuswertung(int userId, const QDate &date) +std::unique_ptr ZeiterfassungApi::doGetReport(int userId, const QDate &date) { QNetworkRequest request(QUrl(QStringLiteral("%0json/auswertung/month?persNr=%1&date=%2") .arg(m_url) @@ -298,7 +296,7 @@ std::unique_ptr ZeiterfassungApi::doGetAuswertung(int userId auto reply = std::unique_ptr(m_manager->get(request)); - return std::make_unique(std::move(reply), this); + return std::make_unique(std::move(reply), this); } std::unique_ptr ZeiterfassungApi::doGetPresenceStatus() diff --git a/zeiterfassunglib/zeiterfassungapi.h b/zeiterfassunglib/zeiterfassungapi.h index ff1f3b7..e978094 100644 --- a/zeiterfassunglib/zeiterfassungapi.h +++ b/zeiterfassunglib/zeiterfassungapi.h @@ -24,7 +24,7 @@ class CreateTimeAssignmentReply; class UpdateTimeAssignmentReply; class DeleteTimeAssignmentReply; class GetProjectsReply; -class GetAuswertungReply; +class GetReportReply; class GetPresenceStatusReply; class ZEITERFASSUNGLIBSHARED_EXPORT ZeiterfassungApi : public QObject @@ -62,7 +62,7 @@ public: std::unique_ptr doDeleteTimeAssignment(int timeAssignmentId); std::unique_ptr doGetProjects(int userId, const QDate &date); - std::unique_ptr doGetAuswertung(int userId, const QDate &date); + std::unique_ptr doGetReport(int userId, const QDate &date); std::unique_ptr doGetPresenceStatus(); private: diff --git a/zeiterfassunglib/zeiterfassunglib.pro b/zeiterfassunglib/zeiterfassunglib.pro index 62c40c9..e58e448 100644 --- a/zeiterfassunglib/zeiterfassunglib.pro +++ b/zeiterfassunglib/zeiterfassunglib.pro @@ -21,12 +21,10 @@ SOURCES += mainwindow.cpp \ dialogs/authenticationdialog.cpp \ dialogs/languageselectiondialog.cpp \ dialogs/settingsdialog.cpp \ - dialogs/updatedialog.cpp \ replies/createbookingreply.cpp \ replies/createtimeassignmentreply.cpp \ replies/deletebookingreply.cpp \ replies/deletetimeassignmentreply.cpp \ - replies/getauswertungreply.cpp \ replies/getbookingsreply.cpp \ replies/getpresencestatusreply.cpp \ replies/getprojectsreply.cpp \ @@ -36,7 +34,8 @@ SOURCES += mainwindow.cpp \ replies/updatebookingreply.cpp \ replies/updatetimeassignmentreply.cpp \ replies/zeiterfassungreply.cpp \ - replies/getuserinforeply.cpp + replies/getuserinforeply.cpp \ + replies/getreportreply.cpp HEADERS += cpp14polyfills.h \ mainwindow.h \ @@ -51,12 +50,10 @@ HEADERS += cpp14polyfills.h \ dialogs/authenticationdialog.h \ dialogs/languageselectiondialog.h \ dialogs/settingsdialog.h \ - dialogs/updatedialog.h \ replies/createbookingreply.h \ replies/createtimeassignmentreply.h \ replies/deletebookingreply.h \ replies/deletetimeassignmentreply.h \ - replies/getauswertungreply.h \ replies/getbookingsreply.h \ replies/getpresencestatusreply.h \ replies/getprojectsreply.h \ @@ -66,10 +63,10 @@ HEADERS += cpp14polyfills.h \ replies/updatebookingreply.h \ replies/updatetimeassignmentreply.h \ replies/zeiterfassungreply.h \ - replies/getuserinforeply.h + replies/getuserinforeply.h \ + replies/getreportreply.h FORMS += mainwindow.ui \ - dialogs/updatedialog.ui \ dialogs/settingsdialog.ui \ dialogs/languageselectiondialog.ui \ dialogs/authenticationdialog.ui \ diff --git a/zeiterfassunglib/zeiterfassungsettings.cpp b/zeiterfassunglib/zeiterfassungsettings.cpp index 6f98a2f..18149be 100644 --- a/zeiterfassunglib/zeiterfassungsettings.cpp +++ b/zeiterfassunglib/zeiterfassungsettings.cpp @@ -132,16 +132,6 @@ void ZeiterfassungSettings::prependText(const QString &text) prependItem(QStringLiteral("texte"), text); } -QDate ZeiterfassungSettings::lastUpdateCheck() const -{ - return value(QStringLiteral("lastUpdateCheck")).toDate(); -} - -void ZeiterfassungSettings::setLastUpdateCheck(const QDate &lastUpdateCheck) -{ - setValue(QStringLiteral("lastUpdateCheck"), lastUpdateCheck); -} - QString ZeiterfassungSettings::theme() const { return value(QStringLiteral("theme")).toString(); diff --git a/zeiterfassunglib/zeiterfassungsettings.h b/zeiterfassunglib/zeiterfassungsettings.h index 952cbdb..0a56adf 100644 --- a/zeiterfassunglib/zeiterfassungsettings.h +++ b/zeiterfassunglib/zeiterfassungsettings.h @@ -51,9 +51,6 @@ public: void setTexte(const QStringList &texte); void prependText(const QString &text); - QDate lastUpdateCheck() const; - void setLastUpdateCheck(const QDate &lastUpdateCheck); - QString theme() const; void setTheme(const QString &theme);