mirror of
https://github.com/Chatterino/chatterino2.git
synced 2024-11-13 19:49:51 +01:00
Clean up account switcher stuff
Update settings library version Fixes #9
This commit is contained in:
parent
be3c85d72d
commit
86a9f194f9
|
@ -1 +1 @@
|
|||
Subproject commit 7ef4704596cbcf37784ffd51e28a1203298654e9
|
||||
Subproject commit d730ef73fe0427994a819593e29e71e8fd96ea0a
|
|
@ -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("<br />"));
|
||||
messageBox.setStandardButtons(QMessageBox::Ok);
|
||||
messageBox.exec();
|
||||
return;
|
||||
}
|
||||
|
||||
QMessageBox messageBox;
|
||||
messageBox.setIcon(QMessageBox::Information);
|
||||
messageBox.setText("Successfully logged in with user <b>" + qS(username) + "</b>!");
|
||||
pajlada::Settings::Setting<std::string>::set("/accounts/uid" + userID + "/username", username);
|
||||
pajlada::Settings::Setting<std::string>::set("/accounts/uid" + userID + "/userID", userID);
|
||||
pajlada::Settings::Setting<std::string>::set("/accounts/uid" + userID + "/clientID", clientID);
|
||||
pajlada::Settings::Setting<std::string>::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.<br />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<std::string>::set("/accounts/uid" + userID + "/username",
|
||||
username);
|
||||
pajlada::Settings::Setting<std::string>::set("/accounts/uid" + userID + "/userID",
|
||||
userID);
|
||||
pajlada::Settings::Setting<std::string>::set("/accounts/uid" + userID + "/clientID",
|
||||
clientID);
|
||||
pajlada::Settings::Setting<std::string>::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<std::string>::set("/accounts/uid" + userID + "/username",
|
||||
username);
|
||||
pajlada::Settings::Setting<std::string>::set("/accounts/uid" + userID + "/userID", userID);
|
||||
pajlada::Settings::Setting<std::string>::set("/accounts/uid" + userID + "/clientID",
|
||||
clientID);
|
||||
pajlada::Settings::Setting<std::string>::set("/accounts/uid" + userID + "/oauthToken",
|
||||
oauthToken);
|
||||
LogInWithCredentials(userID, username, clientID, oauthToken);
|
||||
});
|
||||
|
||||
/// Lower button row
|
||||
|
|
|
@ -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);
|
||||
});
|
||||
|
||||
|
|
Loading…
Reference in a new issue