1
0
mirror of https://github.com/qTox/qTox.git synced 2024-03-22 14:00:36 +08:00

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
This commit is contained in:
jenli669 2019-10-16 19:49:30 +02:00 committed by Anthony Bilinski
parent a44cce65be
commit b4bc09345c
No known key found for this signature in database
GPG Key ID: 2AA8E0DA1B31FB3C
4 changed files with 11 additions and 17 deletions

View File

@ -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;
}
}

View File

@ -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;
}

View File

@ -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();

View File

@ -21,9 +21,9 @@
#ifndef LOGINSCREEN_H
#define LOGINSCREEN_H
#include <QDialog>
#include <QShortcut>
#include <QToolButton>
#include <QDialog>
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();