diff --git a/include/launchercore.h b/include/launchercore.h index abdf2f2..6b6782b 100755 --- a/include/launchercore.h +++ b/include/launchercore.h @@ -75,6 +75,7 @@ struct ProfileSettings { bool isSapphire = false; QString lobbyURL; bool rememberUsername = false, rememberPassword = false; + bool useOneTimePassword = false; GameLicense license = GameLicense::WindowsStandalone; }; diff --git a/include/launcherwindow.h b/include/launcherwindow.h index 41f1f2e..1c4c120 100644 --- a/include/launcherwindow.h +++ b/include/launcherwindow.h @@ -6,6 +6,7 @@ #include #include #include +#include #include "launchercore.h" #include "headline.h" @@ -31,6 +32,7 @@ private: bool currentlyReloadingControls = false; QGridLayout* layout; + QFormLayout* loginLayout; QLabel* bannerImageView; QTreeWidget* newsListView; diff --git a/include/settingswindow.h b/include/settingswindow.h index 1592d36..22b1a70 100644 --- a/include/settingswindow.h +++ b/include/settingswindow.h @@ -54,6 +54,7 @@ private: QLineEdit* lobbyServerURL = nullptr; QCheckBox* rememberUsernameBox = nullptr, *rememberPasswordBox = nullptr; QComboBox* gameLicenseBox = nullptr; + QCheckBox* useOneTimePassword = nullptr; // dalamud QCheckBox* enableDalamudBox = nullptr; diff --git a/src/launchercore.cpp b/src/launchercore.cpp index 62d1476..eac5712 100755 --- a/src/launchercore.cpp +++ b/src/launchercore.cpp @@ -370,6 +370,7 @@ void LauncherCore::readInitialInformation() { profile.lobbyURL = settings.value("lobbyURL", defaultSettings.lobbyURL).toString(); profile.rememberUsername = settings.value("rememberUsername", defaultSettings.rememberUsername).toBool(); profile.rememberPassword = settings.value("rememberPassword", defaultSettings.rememberPassword).toBool(); + profile.useOneTimePassword = settings.value("useOneTimePassword", defaultSettings.useOneTimePassword).toBool(); profile.license = (GameLicense)settings.value("license", (int)defaultSettings.license).toInt(); profile.useDX9 = settings.value("useDX9", defaultSettings.useDX9).toBool(); @@ -589,6 +590,7 @@ void LauncherCore::saveSettings() { settings.setValue("lobbyURL", profile.lobbyURL); settings.setValue("rememberUsername", profile.rememberUsername); settings.setValue("rememberPassword", profile.rememberPassword); + settings.setValue("useOneTimePassword", profile.useOneTimePassword); settings.setValue("license", (int)profile.license); settings.setValue("enableDalamud", profile.dalamud.enabled); diff --git a/src/launcherwindow.cpp b/src/launcherwindow.cpp index 5881ddf..cfe04d1 100644 --- a/src/launcherwindow.cpp +++ b/src/launcherwindow.cpp @@ -110,7 +110,7 @@ LauncherWindow::LauncherWindow(LauncherCore& core, QWidget* parent) : QMainWindo QDesktopServices::openUrl(url); }); - auto loginLayout = new QFormLayout(); + loginLayout = new QFormLayout(); layout->addLayout(loginLayout, 0, 1, 1, 1); profileSelect = new QComboBox(); @@ -142,13 +142,8 @@ LauncherWindow::LauncherWindow(LauncherCore& core, QWidget* parent) : QMainWindo loginLayout->addRow("Remember Password?", rememberPasswordBox); otpEdit = new QLineEdit(); - loginLayout->addRow("One-Time Password", otpEdit); - loginButton = new QPushButton("Login"); - loginLayout->addRow(loginButton); - registerButton = new QPushButton("Register"); - loginLayout->addRow(registerButton); auto emptyWidget = new QWidget(); emptyWidget->setLayout(layout); @@ -274,10 +269,6 @@ void LauncherWindow::reloadControls() { loginButton->setText("Login (Game is not installed)"); } - loginButton->setEnabled(canLogin); - registerButton->setEnabled(currentProfile().isSapphire); - otpEdit->setEnabled(!currentProfile().isSapphire); - launchOfficial->setEnabled(currentProfile().isGameInstalled()); launchSysInfo->setEnabled(currentProfile().isGameInstalled()); launchCfgBackup->setEnabled(currentProfile().isGameInstalled()); @@ -292,6 +283,30 @@ void LauncherWindow::reloadControls() { layout->removeWidget(newsListView); newsListView->hide(); + auto field = loginLayout->labelForField(otpEdit); + if(field != nullptr) + field->deleteLater(); + + loginLayout->takeRow(otpEdit); + otpEdit->hide(); + + if(currentProfile().useOneTimePassword && !currentProfile().isSapphire) { + loginLayout->addRow("One-Time Password", otpEdit); + otpEdit->show(); + } + + loginLayout->takeRow(loginButton); + loginButton->setEnabled(canLogin); + loginLayout->addRow(loginButton); + + loginLayout->takeRow(registerButton); + registerButton->hide(); + + if(currentProfile().isSapphire) { + loginLayout->addRow(registerButton); + registerButton->show(); + } + if(core.appSettings.showBanners || core.appSettings.showNewsList) { int totalRow = 0; if(core.appSettings.showBanners) { diff --git a/src/settingswindow.cpp b/src/settingswindow.cpp index 5242474..fc464e7 100644 --- a/src/settingswindow.cpp +++ b/src/settingswindow.cpp @@ -239,6 +239,16 @@ SettingsWindow::SettingsWindow(int defaultTab, LauncherWindow& window, LauncherC }); loginBoxLayout->addRow("Remember Password", rememberPasswordBox); + useOneTimePassword = new QCheckBox(); + connect(useOneTimePassword, &QCheckBox::stateChanged, [=](int) { + getCurrentProfile().useOneTimePassword = + useOneTimePassword->isChecked(); + + this->core.saveSettings(); + this->window.reloadControls(); + }); + loginBoxLayout->addRow("Use One-time Password", useOneTimePassword); + #if defined(Q_OS_MAC) || defined(Q_OS_LINUX) auto wineBox = new QGroupBox("Wine Options"); auto wineBoxLayout = new QFormLayout(); @@ -516,6 +526,7 @@ void SettingsWindow::reloadControls() { } rememberUsernameBox->setChecked(profile.rememberUsername); rememberPasswordBox->setChecked(profile.rememberPassword); + useOneTimePassword->setChecked(profile.useOneTimePassword); gameLicenseBox->setCurrentIndex((int)profile.license); // dalamud