diff --git a/lib/settings b/lib/settings index 7ef470459..d730ef73f 160000 --- a/lib/settings +++ b/lib/settings @@ -1 +1 @@ -Subproject commit 7ef4704596cbcf37784ffd51e28a1203298654e9 +Subproject commit d730ef73fe0427994a819593e29e71e8fd96ea0a diff --git a/src/widgets/logindialog.cpp b/src/widgets/logindialog.cpp index c28fb9f86..4173601b5 100644 --- a/src/widgets/logindialog.cpp +++ b/src/widgets/logindialog.cpp @@ -12,6 +12,51 @@ namespace chatterino { namespace widgets { +namespace { + +void LogInWithCredentials(const std::string &userID, const std::string &username, + const std::string &clientID, const std::string &oauthToken) +{ + QStringList errors; + + if (userID.empty()) { + errors.append("Missing user ID"); + } + if (username.empty()) { + errors.append("Missing username"); + } + if (clientID.empty()) { + errors.append("Missing Client ID"); + } + if (oauthToken.empty()) { + errors.append("Missing OAuth Token"); + } + + if (errors.length() > 0) { + QMessageBox messageBox; + messageBox.setIcon(QMessageBox::Critical); + messageBox.setText(errors.join("
")); + messageBox.setStandardButtons(QMessageBox::Ok); + messageBox.exec(); + return; + } + + QMessageBox messageBox; + messageBox.setIcon(QMessageBox::Information); + messageBox.setText("Successfully logged in with user " + qS(username) + "!"); + pajlada::Settings::Setting::set("/accounts/uid" + userID + "/username", username); + pajlada::Settings::Setting::set("/accounts/uid" + userID + "/userID", userID); + pajlada::Settings::Setting::set("/accounts/uid" + userID + "/clientID", clientID); + pajlada::Settings::Setting::set("/accounts/uid" + userID + "/oauthToken", + oauthToken); + + AccountManager::getInstance().Twitch.reloadUsers(); + + messageBox.exec(); +} + +} // namespace + BasicLoginWidget::BasicLoginWidget() { this->setLayout(&this->ui.layout); @@ -57,31 +102,7 @@ BasicLoginWidget::BasicLoginWidget() } } - if (oauthToken.empty() || clientID.empty() || username.empty() || userID.empty()) { - QMessageBox messageBox; - messageBox.setText("Bad values"); - messageBox.setInformativeText("Missing values from the clipboard.
Ensure you " - "copied all text and try again."); - messageBox.setStandardButtons(QMessageBox::Ok); - messageBox.exec(); - } else { - QMessageBox messageBox; - messageBox.setText("Success!"); - messageBox.setInformativeText("Successfully added user " + qS(username) + "!"); - qDebug() << "Success! mr"; - pajlada::Settings::Setting::set("/accounts/uid" + userID + "/username", - username); - pajlada::Settings::Setting::set("/accounts/uid" + userID + "/userID", - userID); - pajlada::Settings::Setting::set("/accounts/uid" + userID + "/clientID", - clientID); - pajlada::Settings::Setting::set("/accounts/uid" + userID + "/oauthToken", - oauthToken); - - AccountManager::getInstance().Twitch.reloadUsers(); - - messageBox.exec(); - } + LogInWithCredentials(userID, username, clientID, oauthToken); }); } @@ -135,14 +156,7 @@ AdvancedLoginWidget::AdvancedLoginWidget() std::string clientID = this->ui.clientIDInput.text().toStdString(); std::string oauthToken = this->ui.oauthTokenInput.text().toStdString(); - qDebug() << "Success! mr"; - pajlada::Settings::Setting::set("/accounts/uid" + userID + "/username", - username); - pajlada::Settings::Setting::set("/accounts/uid" + userID + "/userID", userID); - pajlada::Settings::Setting::set("/accounts/uid" + userID + "/clientID", - clientID); - pajlada::Settings::Setting::set("/accounts/uid" + userID + "/oauthToken", - oauthToken); + LogInWithCredentials(userID, username, clientID, oauthToken); }); /// Lower button row diff --git a/src/widgets/settingsdialog.cpp b/src/widgets/settingsdialog.cpp index 4309a7041..7c2922a7b 100644 --- a/src/widgets/settingsdialog.cpp +++ b/src/widgets/settingsdialog.cpp @@ -113,11 +113,13 @@ QVBoxLayout *SettingsDialog::createAccountsTab() auto buttonBox = new QDialogButtonBox(this); auto addButton = new QPushButton("Add", this); + addButton->setToolTip("Log in with a new account"); + auto removeButton = new QPushButton("Remove", this); + removeButton->setToolTip("Remove selected account"); connect(addButton, &QPushButton::clicked, []() { - // TODO: fix memory leak :bbaper: - auto loginWidget = new LoginWidget(); + static auto loginWidget = new LoginWidget(); loginWidget->show(); }); @@ -129,12 +131,12 @@ QVBoxLayout *SettingsDialog::createAccountsTab() this->ui.accountSwitchWidget = new AccountSwitchWidget(this); connect(removeButton, &QPushButton::clicked, [this]() { - qDebug() << "TODO: Implement"; // auto selectedUser = this->ui.accountSwitchWidget->currentItem()->text(); if (selectedUser == ANONYMOUS_USERNAME_LABEL) { // Do nothing return; } + AccountManager::getInstance().Twitch.removeUser(selectedUser); });