From b4bc09345c682ef0c84521ff60cc8f58fb80b87a Mon Sep 17 00:00:00 2001 From: jenli669 Date: Wed, 16 Oct 2019 19:49:30 +0200 Subject: [PATCH] fix(loginScreen): make loginScreen return values comply with Qt standards This commit makes LoginScreen return QDialog::Rejected (0) and QDialog::Accepted (1) instead of C standard return values. This should be more robust with regards to special cases in Qt implementation. Fixes #5781 --- src/main.cpp | 4 ++-- src/nexus.cpp | 5 +++++ src/widget/loginscreen.cpp | 14 +++----------- src/widget/loginscreen.h | 5 +---- 4 files changed, 11 insertions(+), 17 deletions(-) diff --git a/src/main.cpp b/src/main.cpp index 4b368d4f3..faacbaec3 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -391,8 +391,8 @@ int main(int argc, char* argv[]) } else { nexus.setParser(&parser); int returnval = nexus.showLogin(profileName); - if (returnval != 0) { - return returnval; + if (returnval == QDialog::Rejected) { + return -1; } } diff --git a/src/nexus.cpp b/src/nexus.cpp index 5cef77d3c..7e05d6300 100644 --- a/src/nexus.cpp +++ b/src/nexus.cpp @@ -163,6 +163,11 @@ int Nexus::showLogin(const QString& profileName) // The connection order ensures profile will be ready for bootstrap for now connect(this, &Nexus::currentProfileChanged, this, &Nexus::bootstrapWithProfile); int returnval = loginScreen.exec(); + if (returnval == QDialog::Rejected) { + // Kriby: This will terminate the main application loop, necessary until we refactor + // away the split startup/return to login behavior. + qApp->quit(); + } disconnect(this, &Nexus::currentProfileChanged, this, &Nexus::bootstrapWithProfile); return returnval; } diff --git a/src/widget/loginscreen.cpp b/src/widget/loginscreen.cpp index b367a0293..ae17790b9 100644 --- a/src/widget/loginscreen.cpp +++ b/src/widget/loginscreen.cpp @@ -72,15 +72,6 @@ LoginScreen::~LoginScreen() delete ui; } -void LoginScreen::closeEvent(QCloseEvent* event) -{ - - // If we are in the bootstrap, returning -1 will give us something to exit with in main.cpp - this->setResult(-1); - // If we are in application exec, we can quit by closing it, instead. - qApp->quit(); -} - /** * @brief Resets the UI, clears all fields. */ @@ -110,10 +101,11 @@ void LoginScreen::reset(const QString& initialProfileName) void LoginScreen::onProfileLoaded() { - done(0); + done(QDialog::Accepted); } -void LoginScreen::onProfileLoadFailed() { +void LoginScreen::onProfileLoadFailed() +{ QMessageBox::critical(this, tr("Couldn't load this profile"), tr("Wrong password.")); ui->loginPassword->setFocus(); ui->loginPassword->selectAll(); diff --git a/src/widget/loginscreen.h b/src/widget/loginscreen.h index 9a0ab1381..d09bd34f7 100644 --- a/src/widget/loginscreen.h +++ b/src/widget/loginscreen.h @@ -21,9 +21,9 @@ #ifndef LOGINSCREEN_H #define LOGINSCREEN_H +#include #include #include -#include class Profile; @@ -47,9 +47,6 @@ signals: void createNewProfile(QString name, const QString& pass); void loadProfile(QString name, const QString& pass); -protected: - virtual void closeEvent(QCloseEvent* event) final override; - public slots: void onProfileLoaded(); void onProfileLoadFailed();