From d1c1d79453138e50fccd4cab3255b975af0a0c7b Mon Sep 17 00:00:00 2001 From: XinyuHou Date: Wed, 4 Feb 2015 17:30:06 +0000 Subject: [PATCH] changed login window to dialog #4168 --- src/gui/main/gui.pro | 10 +- src/gui/main/res/LoginDialogBase.ui | 167 +++++++++ src/gui/main/res/LoginWindow.h | 22 -- src/gui/main/res/LoginWindowBase.ui | 149 -------- src/gui/main/res/image/about.png | Bin 4941 -> 2267 bytes src/gui/main/src/AppConfig.h | 2 +- src/gui/main/src/LoginAuth.cpp | 18 +- src/gui/main/src/LoginAuth.h | 10 +- .../src/{LoginWindow.cpp => LoginDialog.cpp} | 350 +++++++++--------- src/gui/main/src/LoginDialog.h | 49 +++ src/gui/main/src/LoginWindow.h | 67 ---- src/gui/main/src/main.cpp | 6 +- 12 files changed, 411 insertions(+), 439 deletions(-) create mode 100644 src/gui/main/res/LoginDialogBase.ui delete mode 100644 src/gui/main/res/LoginWindow.h delete mode 100644 src/gui/main/res/LoginWindowBase.ui rename src/gui/main/src/{LoginWindow.cpp => LoginDialog.cpp} (65%) create mode 100644 src/gui/main/src/LoginDialog.h delete mode 100644 src/gui/main/src/LoginWindow.h diff --git a/src/gui/main/gui.pro b/src/gui/main/gui.pro index da083775..635b2344 100644 --- a/src/gui/main/gui.pro +++ b/src/gui/main/gui.pro @@ -15,7 +15,7 @@ FORMS += res/MainWindowBase.ui \ res/SettingsDialogBase.ui \ res/SetupWizardBase.ui \ res/AddClientDialogBase.ui \ - res/LoginWindowBase.ui + res/LoginDialogBase.ui SOURCES += src/main.cpp \ src/MainWindow.cpp \ src/AboutDialog.cpp \ @@ -52,8 +52,8 @@ SOURCES += src/main.cpp \ src/DataDownloader.cpp \ src/AddClientDialog.cpp \ src/CommandProcess.cpp \ - src/LoginWindow.cpp \ - src/LoginAuth.cpp + src/LoginAuth.cpp \ + src/LoginDialog.cpp HEADERS += src/MainWindow.h \ src/AboutDialog.h \ src/ServerConfig.h \ @@ -90,10 +90,10 @@ HEADERS += src/MainWindow.h \ src/DataDownloader.h \ src/AddClientDialog.h \ src/CommandProcess.h \ - src/LoginWindow.h \ src/LoginAuth.h \ src/EditionType.h \ - src/LoginResult.h + src/LoginResult.h \ + src/LoginDialog.h RESOURCES += res/Synergy.qrc RC_FILE = res/win/Synergy.rc macx { diff --git a/src/gui/main/res/LoginDialogBase.ui b/src/gui/main/res/LoginDialogBase.ui new file mode 100644 index 00000000..48ba3db4 --- /dev/null +++ b/src/gui/main/res/LoginDialogBase.ui @@ -0,0 +1,167 @@ + + + LoginDialog + + + + 0 + 0 + 359 + 175 + + + + + 0 + 0 + + + + Synergy + + + + + + + + + :/res/image/about.png + + + + + + + Qt::Vertical + + + QSizePolicy::Minimum + + + + 20 + 20 + + + + + + + + 20 + + + 10 + + + 0 + + + 0 + + + + + Email: + + + + + + + + 200 + 0 + + + + + + + + Password: + + + + + + + + 200 + 0 + + + + QLineEdit::Password + + + + + + + + + Qt::Vertical + + + QSizePolicy::Minimum + + + + 20 + 10 + + + + + + + + + + <a href="https://synergy-project.org/account/reset/">Forgot password</a> + + + true + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + + 0 + 0 + + + + Login + + + Return + + + + + + + + + + + + diff --git a/src/gui/main/res/LoginWindow.h b/src/gui/main/res/LoginWindow.h deleted file mode 100644 index 2f1cb636..00000000 --- a/src/gui/main/res/LoginWindow.h +++ /dev/null @@ -1,22 +0,0 @@ -#ifndef LOGINWINDOW_H -#define LOGINWINDOW_H - -#include - -#include "ui_LoginWindowBase.h" - -class LoginWindow : public QMainWindow, public Ui::LoginWindowBase -{ - Q_OBJECT -public: - LoginWindow(QWidget *parent = 0); - ~LoginWindow(); - -protected: - void changeEvent(QEvent *e); - -private: - Ui::LoginWindow *ui; -}; - -#endif // LOGINWINDOW_H diff --git a/src/gui/main/res/LoginWindowBase.ui b/src/gui/main/res/LoginWindowBase.ui deleted file mode 100644 index 4b58e1b1..00000000 --- a/src/gui/main/res/LoginWindowBase.ui +++ /dev/null @@ -1,149 +0,0 @@ - - - LoginWindow - - - - 0 - 0 - 400 - 200 - - - - Synergy - - - - - - - 10 - - - - - - - - :/res/image/about.png - - - - - - - - - 20 - - - 20 - - - - - Email: - - - - - - - - 0 - 0 - - - - - - - - Password: - - - - - - - Qt::ImhHiddenText - - - QLineEdit::Password - - - - - - - - - 20 - - - 20 - - - - - <a href="http://synergy-project.org/">Register</a> - - - true - - - - - - - - 0 - 0 - - - - Login - - - Return - - - - - - - - 0 - 0 - - - - Cancel - - - Esc - - - - - - - - - - - 0 - 0 - 400 - 21 - - - - - - - - - - diff --git a/src/gui/main/res/image/about.png b/src/gui/main/res/image/about.png index 4630bd32a5d36f7588a3d8b4bbf9b8706e80adec..23e58c9b4fb64e618fc7d4f1f402c6733d050c1e 100644 GIT binary patch delta 2254 zcmV;<2r>7~CfgAqiBL{Q4GJ0x0000DNk~Le0001t0000j2nGNE0DORhb&(+_e+Yd^ zL_t(|+U#6CY$HV!UPoyWP8lJ%jZT6FbhZQy=;U1;f--go#VKn#XcG4z+k)P410CMz z3h3gLAW$4#3yM#4NGN*+LP&_)s}L2u=X;YpCiA!Jwa-3wq>+>T^SqgFzW2R1v#xk^ zl)ImN@54s`wE?w8Rg~$Yzkl!ifB46@yX^QG9{=sjc=;?UcZIh5!RVL6e=^ANTy$AU zj{9mQXx0=k1ePf0bN5lu=DfFBf@aMCGbdPP4DvE(5ez&=OPG&oIz(8q7TPI=@QMP4qM`E)_s7U0Dv;<3foG6GL{9)PVL4Q* z2^iOC2;EH^fRa0R0>J5ce@}8cE~O2iiOb<08N=$ z&Ko5WyV$@ob3;WpfR+S04wvpZTqA>JN{l#_BCt_8^z(()`z|`7e+W0E0ZmMimN8TZ zHfkE!r6z%;1uRmBifmGc|LZKoFT?e`fT1l4whoNv5xB0x*0bkqb`9q^m<|CX{{bMm zpwbP^SvEbl73Kb-8-jus7zCN-zygYS++s&)B@)KIa9buJOzb7I8>SM*;y$>hNq`ov z{fq>5V$fT7PeXSPe_Vs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- a/src/gui/main/src/AppConfig.h +++ b/src/gui/main/src/AppConfig.h @@ -47,7 +47,7 @@ class AppConfig friend class SettingsDialog; friend class MainWindow; friend class SetupWizard; - friend class LoginWindow; + friend class LoginDialog; public: AppConfig(QSettings* settings); diff --git a/src/gui/main/src/LoginAuth.cpp b/src/gui/main/src/LoginAuth.cpp index a45ffc93..0b91d2c3 100644 --- a/src/gui/main/src/LoginAuth.cpp +++ b/src/gui/main/src/LoginAuth.cpp @@ -17,7 +17,7 @@ #include "LoginAuth.h" -#include "LoginWindow.h" +#include "LoginDialog.h" #include "AppConfig.h" #include "QUtility.h" #include "LoginResult.h" @@ -28,16 +28,16 @@ #include #include -void LoginAuth::checkUserType() +void LoginAuth::checkEditionType() { int edition = Unknown; - int result = doCheckUserType(edition); - m_pLoginWindow->setLoginResult(result); - m_pLoginWindow->setEditionType(edition); + int result = doCheckEditionType(edition); + m_pLoginDialog->setLoginResult(result); + m_pLoginDialog->setEditionType(edition); emit finished(); } -int LoginAuth::doCheckUserType(int& edition) +int LoginAuth::doCheckEditionType(int& edition) { QString responseJson; @@ -47,7 +47,7 @@ int LoginAuth::doCheckUserType(int& edition) } catch (std::exception& e) { - m_pLoginWindow->setError(e.what()); + m_pLoginDialog->setError(e.what()); return ExceptionError; } @@ -72,12 +72,12 @@ int LoginAuth::doCheckUserType(int& edition) // replace "\n" with real new lines. QString error = errorRegex.cap(1).replace("\\n", "\n"); - m_pLoginWindow->setError(error); + m_pLoginDialog->setError(error); return Error; } } - m_pLoginWindow->setError(responseJson); + m_pLoginDialog->setError(responseJson); return ServerResponseError; } diff --git a/src/gui/main/src/LoginAuth.h b/src/gui/main/src/LoginAuth.h index 560c284e..272472a8 100644 --- a/src/gui/main/src/LoginAuth.h +++ b/src/gui/main/src/LoginAuth.h @@ -21,7 +21,7 @@ #include #include -class LoginWindow; +class LoginDialog; class AppConfig; class LoginAuth : public QObject @@ -29,13 +29,13 @@ class LoginAuth : public QObject Q_OBJECT public: - int doCheckUserType(int& edition); + int doCheckEditionType(int& edition); void setEmail(QString email) { m_Email = email; } void setPassword(QString password) { m_Password = password; } - void setLoginWindow(LoginWindow* w) { m_pLoginWindow = w; } + void setLoginDialog(LoginDialog* d) { m_pLoginDialog = d; } public slots: - void checkUserType(); + void checkEditionType(); signals: void finished(); @@ -46,7 +46,7 @@ private: private: QString m_Email; QString m_Password; - LoginWindow* m_pLoginWindow; + LoginDialog* m_pLoginDialog; }; #endif // LOGINAUTH_H diff --git a/src/gui/main/src/LoginWindow.cpp b/src/gui/main/src/LoginDialog.cpp similarity index 65% rename from src/gui/main/src/LoginWindow.cpp rename to src/gui/main/src/LoginDialog.cpp index ef2c28e2..5cf2007c 100644 --- a/src/gui/main/src/LoginWindow.cpp +++ b/src/gui/main/src/LoginDialog.cpp @@ -1,178 +1,172 @@ -/* - * synergy -- mouse and keyboard sharing utility - * Copyright (C) 2015 Synergy Si Ltd. - * - * This package is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * found in the file COPYING that should have accompanied this file. - * - * This package is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -#include "LoginWindow.h" -#include "ui_LoginWindowBase.h" - -#include "MainWindow.h" -#include "SetupWizard.h" -#include "LoginAuth.h" -#include "LoginResult.h" -#include "EditionType.h" -#include "QUtility.h" - -#include -#include -#include - -LoginWindow::LoginWindow( - MainWindow* mainWindow, - SetupWizard* setupWizard, - bool wizardShouldRun, - QWidget *parent) : - QMainWindow(parent), - m_pMainWindow(mainWindow), - m_pSetupWizard(setupWizard), - m_WizardShouldRun(wizardShouldRun), - m_pLoginAuth(NULL), - m_LoginResult(Ok), - m_EditionType(Unknown), - m_AppConfig(m_pMainWindow->appConfig()) -{ - setupUi(this); - - m_pLineEditEmail->setText(m_AppConfig.userEmail()); -} - -LoginWindow::~LoginWindow() -{ - if (m_pLoginAuth != NULL) { - delete m_pLoginAuth; - } -} - -void LoginWindow::showNext() -{ - if (m_LoginResult == ExceptionError) { - QMessageBox::critical( - this, - tr("Error"), - tr("Sorry, an error occured while trying to sign in. " - "Please contact the help desk, and provide the " - "following details.\n\n%1").arg(m_Error)); - } - else if (m_LoginResult == InvalidEmailPassword) { - QMessageBox::critical( - this, - tr("Error"), - tr("Login failed, invalid email or password.")); - } - else if (m_LoginResult == Error) { - QMessageBox::critical( - this, - tr("Error"), - tr("Login failed, an error occurred.\n\n%1").arg(m_Error)); - } - else if (m_LoginResult == ServerResponseError) { - QMessageBox::critical( - this, - "Error", - tr("Login failed, an error occurred.\n\nServer response:\n\n%1") - .arg(m_Error)); - } - else { - hide(); - if (m_WizardShouldRun) { - m_pSetupWizard->show(); - } - else { - m_pMainWindow->setEditionType(m_EditionType); - if (!m_pLineEditEmail->text().isEmpty()) { - m_AppConfig.setUserEmail(m_pLineEditEmail->text()); - - if (m_EditionType != Unknown) { - QString mac = getFirstMacAddress(); - QString hashSrc = m_pLineEditEmail->text() + mac; - QString hashResult = hash(hashSrc); - m_AppConfig.setUserToken(hashResult); - m_AppConfig.setEditionType(m_EditionType); - } - } - m_pMainWindow->show(); - } - } - - delete m_pLoginAuth; - m_pLoginAuth = NULL; - m_LoginResult = Ok; - m_EditionType = Unknown; - m_pPushButtonLogin->setEnabled(true); - m_pPushButtonLogin->setDefault(true); -} - -bool LoginWindow::validEmailPassword() -{ - if (m_pLineEditEmail->text().isEmpty() || - m_pLineEditPassword->text().isEmpty()) { - QMessageBox::warning( - this, - "Warning", - tr("Please fill in your email and password.")); - return false; - } - - return true; -} - -void LoginWindow::changeEvent(QEvent *e) -{ - QMainWindow::changeEvent(e); - switch (e->type()) { - case QEvent::LanguageChange: - retranslateUi(this); - break; - default: - break; - } -} -void LoginWindow::closeEvent(QCloseEvent *event) -{ - event->accept(); - showNext(); -} - -void LoginWindow::on_m_pPushButtonLogin_clicked() -{ - if (validEmailPassword()) { - if (m_pLoginAuth == NULL) { - m_pLoginAuth = new LoginAuth(); - m_pLoginAuth->setLoginWindow(this); - } - - m_pPushButtonLogin->setEnabled(false); - - QString email = m_pLineEditEmail->text(); - QString password = m_pLineEditPassword->text(); - m_pLoginAuth->setEmail(email); - m_pLoginAuth->setPassword(password); - - QThread* thread = new QThread; - connect(m_pLoginAuth, SIGNAL(finished()), this, SLOT(showNext())); - connect(m_pLoginAuth, SIGNAL(finished()), thread, SLOT(quit())); - connect(thread, SIGNAL(finished()), thread, SLOT(deleteLater())); - - m_pLoginAuth->moveToThread(thread); - thread->start(); - - QMetaObject::invokeMethod(m_pLoginAuth, "checkUserType", Qt::QueuedConnection); - } -} - -void LoginWindow::on_m_pPushButtonCancel_clicked() -{ - showNext(); -} +#include "LoginDialog.h" + +#include "MainWindow.h" +#include "SetupWizard.h" +#include "LoginAuth.h" +#include "LoginResult.h" +#include "EditionType.h" +#include "QUtility.h" + +#include +#include +#include +#include +#include + +static const char registerUrl[] = "http://synergy-project.org"; + +LoginDialog::LoginDialog( + MainWindow* mainWindow, + SetupWizard* setupWizard, + bool wizardShouldRun, + QWidget *parent) : + QDialog(parent), + m_pMainWindow(mainWindow), + m_pSetupWizard(setupWizard), + m_WizardShouldRun(wizardShouldRun), + m_pLoginAuth(NULL), + m_LoginResult(Ok), + m_EditionType(Unknown), + m_AppConfig(m_pMainWindow->appConfig()) +{ + setupUi(this); + setFixedSize(size()); + m_pLineEditEmail->setText(m_AppConfig.userEmail()); +} + +LoginDialog::~LoginDialog() +{ + if (m_pLoginAuth != NULL) { + delete m_pLoginAuth; + } +} + +void LoginDialog::showNext() +{ + if (m_LoginResult == ExceptionError) { + QMessageBox::critical( + this, + tr("Error"), + tr("Sorry, an error occured while trying to sign in. " + "Please contact the help desk, and provide the " + "following details.\n\n%1").arg(m_Error)); + } + else if (m_LoginResult == InvalidEmailPassword) { + QMessageBox::warning( + this, + tr("Warning"), + tr("Login failed, invalid email or password.")); + } + else if (m_LoginResult == Error) { + QMessageBox::critical( + this, + tr("Error"), + tr("Login failed, an error occurred.\n\n%1").arg(m_Error)); + } + else if (m_LoginResult == ServerResponseError) { + QMessageBox::critical( + this, + "Error", + tr("Login failed, an error occurred.\n\nServer response:\n\n%1") + .arg(m_Error)); + } + else { + hide(); + if (m_WizardShouldRun) { + m_pSetupWizard->show(); + } + else { + m_pMainWindow->setEditionType(m_EditionType); + if (!m_pLineEditEmail->text().isEmpty()) { + m_AppConfig.setUserEmail(m_pLineEditEmail->text()); + + if (m_EditionType != Unknown) { + QString mac = getFirstMacAddress(); + QString hashSrc = m_pLineEditEmail->text() + mac; + QString hashResult = hash(hashSrc); + //m_AppConfig.setUserToken(hashResult); + //m_AppConfig.setEditionType(m_EditionType); + } + } + m_pMainWindow->show(); + } + } + + delete m_pLoginAuth; + m_pLoginAuth = NULL; + m_LoginResult = Ok; + m_EditionType = Unknown; + m_pPushButtonLogin->setEnabled(true); + m_pPushButtonLogin->setDefault(true); + m_pLineEditEmail->setEnabled(true); + m_pLineEditPassword->setEnabled(true); +} + +bool LoginDialog::validEmailPassword() +{ + if (m_pLineEditEmail->text().isEmpty() || + m_pLineEditPassword->text().isEmpty()) { + QMessageBox::warning( + this, + "Warning", + tr("Please fill in your email and password.")); + return false; + } + + return true; +} + +void LoginDialog::changeEvent(QEvent *e) +{ + QDialog::changeEvent(e); + switch (e->type()) { + case QEvent::LanguageChange: + retranslateUi(this); + break; + default: + break; + } +} + +void LoginDialog::closeEvent(QCloseEvent *event) +{ + event->accept(); + showNext(); +} + +void LoginDialog::on_m_pPushButtonLogin_clicked() +{ + if (validEmailPassword()) { + if (m_pLoginAuth == NULL) { + m_pLoginAuth = new LoginAuth(); + m_pLoginAuth->setLoginDialog(this); + } + + m_pPushButtonLogin->setEnabled(false); + m_pLineEditEmail->setEnabled(false); + m_pLineEditPassword->setEnabled(false); + + QString email = m_pLineEditEmail->text(); + QString password = m_pLineEditPassword->text(); + m_pLoginAuth->setEmail(email); + m_pLoginAuth->setPassword(password); + + QThread* thread = new QThread; + connect(m_pLoginAuth, SIGNAL(finished()), this, SLOT(showNext())); + connect(m_pLoginAuth, SIGNAL(finished()), thread, SLOT(quit())); + connect(thread, SIGNAL(finished()), thread, SLOT(deleteLater())); + + m_pLoginAuth->moveToThread(thread); + thread->start(); + + QMetaObject::invokeMethod(m_pLoginAuth, "checkEditionType", Qt::QueuedConnection); + } +} + +void LoginDialog::keyPressEvent(QKeyEvent* e) { + if(e->key() != Qt::Key_Escape) + QDialog::keyPressEvent(e); + else { + close(); + } +} diff --git a/src/gui/main/src/LoginDialog.h b/src/gui/main/src/LoginDialog.h new file mode 100644 index 00000000..3ca831e6 --- /dev/null +++ b/src/gui/main/src/LoginDialog.h @@ -0,0 +1,49 @@ +#ifndef LOGINDIALOG_H +#define LOGINDIALOG_H + +#include "ui_LoginDialogBase.h" + +#include + +class MainWindow; +class SetupWizard; +class LoginAuth; +class AppConfig; + +class LoginDialog : public QDialog, public Ui::LoginDialog { + Q_OBJECT +public: + LoginDialog(MainWindow* mainWindow, + SetupWizard* setupWizard, + bool wizardShouldRun, + QWidget *parent = 0); + ~LoginDialog(); + + void setLoginResult(int result) { m_LoginResult = result; } + void setEditionType(int type) { m_EditionType = type; } + void setError(QString error) { m_Error = error; } + +protected: + void changeEvent(QEvent *e); + void closeEvent(QCloseEvent *event); + void keyPressEvent(QKeyEvent *e); + +private slots: + void on_m_pPushButtonLogin_clicked(); + void showNext(); + +private: + bool validEmailPassword(); + +private: + MainWindow* m_pMainWindow; + SetupWizard* m_pSetupWizard; + bool m_WizardShouldRun; + LoginAuth* m_pLoginAuth; + int m_LoginResult; + int m_EditionType; + QString m_Error; + AppConfig& m_AppConfig; +}; + +#endif // LOGINDIALOG_H diff --git a/src/gui/main/src/LoginWindow.h b/src/gui/main/src/LoginWindow.h deleted file mode 100644 index e0e6d464..00000000 --- a/src/gui/main/src/LoginWindow.h +++ /dev/null @@ -1,67 +0,0 @@ -/* - * synergy -- mouse and keyboard sharing utility - * Copyright (C) 2015 Synergy Si Ltd. - * - * This package is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * found in the file COPYING that should have accompanied this file. - * - * This package is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -#ifndef LOGINWINDOW_H -#define LOGINWINDOW_H - -#include - -#include "ui_LoginWindowBase.h" - -class MainWindow; -class SetupWizard; -class LoginAuth; -class AppConfig; - -class LoginWindow : public QMainWindow, public Ui::LoginWindow -{ - Q_OBJECT -public: - LoginWindow(MainWindow* mainWindow, - SetupWizard* setupWizard, - bool wizardShouldRun, - QWidget *parent = 0); - ~LoginWindow(); - - void setLoginResult(int result) { m_LoginResult = result; } - void setEditionType(int type) { m_EditionType = type; } - void setError(QString error) { m_Error = error; } - -protected: - void changeEvent(QEvent *e); - void closeEvent(QCloseEvent *event); - -private slots: - void on_m_pPushButtonCancel_clicked(); - void on_m_pPushButtonLogin_clicked(); - void showNext(); - -private: - bool validEmailPassword(); -private: - MainWindow* m_pMainWindow; - SetupWizard* m_pSetupWizard; - bool m_WizardShouldRun; - LoginAuth* m_pLoginAuth; - int m_LoginResult; - int m_EditionType; - QString m_Error; - AppConfig& m_AppConfig; - -}; - -#endif // LOGINWINDOW_H diff --git a/src/gui/main/src/main.cpp b/src/gui/main/src/main.cpp index 48141299..7f5f572f 100644 --- a/src/gui/main/src/main.cpp +++ b/src/gui/main/src/main.cpp @@ -23,7 +23,7 @@ #include "MainWindow.h" #include "AppConfig.h" #include "SetupWizard.h" -#include "LoginWindow.h" +#include "LoginDialog.h" #include "QUtility.h" #include "LoginResult.h" @@ -95,7 +95,7 @@ int main(int argc, char* argv[]) MainWindow mainWindow(settings, appConfig); SetupWizard setupWizard(mainWindow, true); - LoginWindow loginWindow( + LoginDialog loginDialog( &mainWindow, &setupWizard, appConfig.wizardShouldRun()); @@ -109,7 +109,7 @@ int main(int argc, char* argv[]) mainWindow.show(); } else { - loginWindow.show(); + loginDialog.show(); } return app.exec();