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 4630bd32..23e58c9b 100644 Binary files a/src/gui/main/res/image/about.png and b/src/gui/main/res/image/about.png differ diff --git a/src/gui/main/src/AppConfig.h b/src/gui/main/src/AppConfig.h index d14ca8ac..642f6d12 100644 --- 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();