diff --git a/plugins/advancedviewplugin/advanvedviewdialog.cpp b/plugins/advancedviewplugin/advanvedviewdialog.cpp index bcc77a9..9a5f2de 100644 --- a/plugins/advancedviewplugin/advanvedviewdialog.cpp +++ b/plugins/advancedviewplugin/advanvedviewdialog.cpp @@ -3,7 +3,6 @@ #include #include -#include #include #include @@ -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(); @@ -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/zeiterfassung/main.cpp b/zeiterfassung/main.cpp index f06aea9..788078b 100755 --- a/zeiterfassung/main.cpp +++ b/zeiterfassung/main.cpp @@ -1,6 +1,5 @@ #include #include -#include #include #include #include @@ -175,11 +174,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 +217,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 +248,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()) { diff --git a/zeiterfassunglib/mainwindow.cpp b/zeiterfassunglib/mainwindow.cpp index 6c3e90d..a298dbc 100644 --- a/zeiterfassunglib/mainwindow.cpp +++ b/zeiterfassunglib/mainwindow.cpp @@ -7,7 +7,6 @@ #include #include #include -#include #include #include #include @@ -247,11 +246,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 +272,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 +291,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()) { @@ -350,11 +337,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 +352,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()) { 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();