From 8d49647baebd4bd2391216b81ce63fa5b3aa6ff6 Mon Sep 17 00:00:00 2001 From: 0xFEEDC0DE64 <0xFEEDC0DE64@gmail.com> Date: Sun, 10 Dec 2017 14:42:40 +0100 Subject: [PATCH] Removed EventLoopWithStatus --- eventloopwithstatus.cpp | 24 --------------- eventloopwithstatus.h | 24 --------------- main.cpp | 68 +++++++++++++++++++++++++---------------- mainwindow.cpp | 1 - zeiterfassung.pro | 2 -- 5 files changed, 41 insertions(+), 78 deletions(-) delete mode 100644 eventloopwithstatus.cpp delete mode 100644 eventloopwithstatus.h diff --git a/eventloopwithstatus.cpp b/eventloopwithstatus.cpp deleted file mode 100644 index ea70956..0000000 --- a/eventloopwithstatus.cpp +++ /dev/null @@ -1,24 +0,0 @@ -#include "eventloopwithstatus.h" - -EventLoopWithStatus::EventLoopWithStatus(QObject *parent) : - QEventLoop(parent) -{ - -} - -bool EventLoopWithStatus::success() const -{ - return m_success; -} - -const QString &EventLoopWithStatus::message() const -{ - return m_message; -} - -void EventLoopWithStatus::quitWithStatus(bool success, const QString &message) -{ - m_success = success; - m_message = message; - quit(); -} diff --git a/eventloopwithstatus.h b/eventloopwithstatus.h deleted file mode 100644 index ecdcbb0..0000000 --- a/eventloopwithstatus.h +++ /dev/null @@ -1,24 +0,0 @@ -#ifndef EVENTLOOPWITHSTATUS_H -#define EVENTLOOPWITHSTATUS_H - -#include - -class EventLoopWithStatus : public QEventLoop -{ - Q_OBJECT - -public: - EventLoopWithStatus(QObject *parent = Q_NULLPTR); - - bool success() const; - const QString &message() const; - -public Q_SLOTS: - void quitWithStatus(bool success, const QString &message); - -private: - bool m_success; - QString m_message; -}; - -#endif // EVENTLOOPWITHSTATUS_H diff --git a/main.cpp b/main.cpp index ca5fac1..4dcf66c 100755 --- a/main.cpp +++ b/main.cpp @@ -1,5 +1,6 @@ #include #include +#include #include #include #include @@ -11,9 +12,11 @@ #include "zeiterfassungsettings.h" #include "dialogs/languageselectiondialog.h" #include "zeiterfassungapi.h" -#include "eventloopwithstatus.h" #include "dialogs/authenticationdialog.h" #include "mainwindow.h" +#include "replies/loginpagereply.h" +#include "replies/loginreply.h" +#include "replies/userinforeply.h" bool loadAndInstallTranslator(QTranslator &translator, const QLocale &locale, @@ -98,18 +101,20 @@ int main(int argc, char *argv[]) ZeiterfassungApi erfassung(settings.url(), &app); { - EventLoopWithStatus eventLoop; - QObject::connect(&erfassung, &ZeiterfassungApi::loginPageFinished, &eventLoop, &EventLoopWithStatus::quitWithStatus); - again1: - erfassung.doLoginPage(); - eventLoop.exec(); + auto reply = erfassung.doLoginPage(); - if(!eventLoop.success()) + { + QEventLoop eventLoop; + QObject::connect(reply, &ZeiterfassungReply::finished, &eventLoop, &QEventLoop::quit); + eventLoop.exec(); + } + + if(!reply->success()) { bool ok; QMessageBox::warning(&splashScreen, QCoreApplication::translate("main", "Could not access Zeiterfassung!"), - QCoreApplication::translate("main", "Could not access Zeiterfassung!") % "\n\n" % eventLoop.message()); + QCoreApplication::translate("main", "Could not access Zeiterfassung!") % "\n\n" % reply->message()); auto url = QInputDialog::getText(&splashScreen, QCoreApplication::translate("main", "Base url"), QCoreApplication::translate("main", "Please enter the base url to the Zeiterfassung:"), @@ -118,8 +123,12 @@ int main(int argc, char *argv[]) return -1; settings.setUrl(url); erfassung.setUrl(url); + + reply->deleteLater(); goto again1; } + + reply->deleteLater(); } splashScreen.showMessage(QCoreApplication::translate("main", "Authenticating...")); @@ -134,17 +143,19 @@ int main(int argc, char *argv[]) } { - EventLoopWithStatus eventLoop; - QObject::connect(&erfassung, &ZeiterfassungApi::loginFinished, &eventLoop, &EventLoopWithStatus::quitWithStatus); - again2: - erfassung.doLogin(settings.username(), settings.password()); - eventLoop.exec(); + auto reply = erfassung.doLogin(settings.username(), settings.password()); - if(!eventLoop.success()) + { + QEventLoop eventLoop; + QObject::connect(reply, &ZeiterfassungReply::finished, &eventLoop, &QEventLoop::quit); + eventLoop.exec(); + } + + if(!reply->success()) { QMessageBox::warning(&splashScreen, QCoreApplication::translate("main", "Could not authenticate with Zeiterfassung!"), - QCoreApplication::translate("main", "Could not authenticate with Zeiterfassung!") % "\n\n" % eventLoop.message()); + QCoreApplication::translate("main", "Could not authenticate with Zeiterfassung!") % "\n\n" % reply->message()); AuthenticationDialog dialog(&splashScreen); dialog.setUsername(settings.username()); @@ -154,8 +165,11 @@ int main(int argc, char *argv[]) settings.setUsername(dialog.username()); settings.setPassword(dialog.password()); + reply->deleteLater(); goto again2; } + + reply->deleteLater(); } splashScreen.showMessage(QCoreApplication::translate("main", "Getting user information...")); @@ -163,25 +177,25 @@ int main(int argc, char *argv[]) ZeiterfassungApi::UserInfo userInfo; { - EventLoopWithStatus eventLoop; - QObject::connect(&erfassung, &ZeiterfassungApi::userInfoFinished, - [&](bool success, const QString &message, const ZeiterfassungApi::UserInfo &_userInfo) { - Q_UNUSED(message) - if(success) - userInfo = _userInfo; - }); - QObject::connect(&erfassung, &ZeiterfassungApi::userInfoFinished, &eventLoop, &EventLoopWithStatus::quitWithStatus); + auto reply = erfassung.doUserInfo(); - erfassung.doUserInfo(); - eventLoop.exec(); + { + QEventLoop eventLoop; + QObject::connect(reply, &ZeiterfassungReply::finished, &eventLoop, &QEventLoop::quit); + eventLoop.exec(); + } - if(!eventLoop.success()) + if(!reply->success()) { QMessageBox::warning(&splashScreen, QCoreApplication::translate("main", "Could not get user information!"), - QCoreApplication::translate("main", "Could not get user information!") % "\n\n" % eventLoop.message()); + QCoreApplication::translate("main", "Could not get user information!") % "\n\n" % reply->message()); + reply->deleteLater(); return -1; } + + userInfo = reply->userInfo(); + reply->deleteLater(); } MainWindow mainWindow(settings, erfassung, userInfo); diff --git a/mainwindow.cpp b/mainwindow.cpp index 434d314..6510ddc 100644 --- a/mainwindow.cpp +++ b/mainwindow.cpp @@ -18,7 +18,6 @@ #include "zeiterfassungsettings.h" #include "stripfactory.h" #include "stripswidget.h" -#include "eventloopwithstatus.h" #include "dialogs/aboutmedialog.h" #include "dialogs/bookingdialog.h" #include "dialogs/timeassignmentdialog.h" diff --git a/zeiterfassung.pro b/zeiterfassung.pro index f64a385..d73aefd 100755 --- a/zeiterfassung.pro +++ b/zeiterfassung.pro @@ -20,7 +20,6 @@ SOURCES += main.cpp \ mainwindow.cpp \ dialogs/aboutmedialog.cpp \ dialogs/authenticationdialog.cpp \ - eventloopwithstatus.cpp \ zeiterfassungsettings.cpp \ dialogs/settingsdialog.cpp \ dialogs/languageselectiondialog.cpp \ @@ -52,7 +51,6 @@ HEADERS += \ mainwindow.h \ dialogs/aboutmedialog.h \ dialogs/authenticationdialog.h \ - eventloopwithstatus.h \ zeiterfassungsettings.h \ dialogs/settingsdialog.h \ dialogs/languageselectiondialog.h \