Clean up account switcher stuff

Update settings library version

Fixes #9
This commit is contained in:
Rasmus Karlsson 2017-12-20 00:39:33 +01:00
parent be3c85d72d
commit 86a9f194f9
3 changed files with 53 additions and 37 deletions

@ -1 +1 @@
Subproject commit 7ef4704596cbcf37784ffd51e28a1203298654e9 Subproject commit d730ef73fe0427994a819593e29e71e8fd96ea0a

View file

@ -12,6 +12,51 @@
namespace chatterino { namespace chatterino {
namespace widgets { 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() BasicLoginWidget::BasicLoginWidget()
{ {
this->setLayout(&this->ui.layout); this->setLayout(&this->ui.layout);
@ -57,31 +102,7 @@ BasicLoginWidget::BasicLoginWidget()
} }
} }
if (oauthToken.empty() || clientID.empty() || username.empty() || userID.empty()) { LogInWithCredentials(userID, username, clientID, oauthToken);
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();
}
}); });
} }
@ -135,14 +156,7 @@ AdvancedLoginWidget::AdvancedLoginWidget()
std::string clientID = this->ui.clientIDInput.text().toStdString(); std::string clientID = this->ui.clientIDInput.text().toStdString();
std::string oauthToken = this->ui.oauthTokenInput.text().toStdString(); std::string oauthToken = this->ui.oauthTokenInput.text().toStdString();
qDebug() << "Success! mr"; LogInWithCredentials(userID, username, clientID, oauthToken);
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);
}); });
/// Lower button row /// Lower button row

View file

@ -113,11 +113,13 @@ QVBoxLayout *SettingsDialog::createAccountsTab()
auto buttonBox = new QDialogButtonBox(this); auto buttonBox = new QDialogButtonBox(this);
auto addButton = new QPushButton("Add", this); auto addButton = new QPushButton("Add", this);
addButton->setToolTip("Log in with a new account");
auto removeButton = new QPushButton("Remove", this); auto removeButton = new QPushButton("Remove", this);
removeButton->setToolTip("Remove selected account");
connect(addButton, &QPushButton::clicked, []() { connect(addButton, &QPushButton::clicked, []() {
// TODO: fix memory leak :bbaper: static auto loginWidget = new LoginWidget();
auto loginWidget = new LoginWidget();
loginWidget->show(); loginWidget->show();
}); });
@ -129,12 +131,12 @@ QVBoxLayout *SettingsDialog::createAccountsTab()
this->ui.accountSwitchWidget = new AccountSwitchWidget(this); this->ui.accountSwitchWidget = new AccountSwitchWidget(this);
connect(removeButton, &QPushButton::clicked, [this]() { connect(removeButton, &QPushButton::clicked, [this]() {
qDebug() << "TODO: Implement"; //
auto selectedUser = this->ui.accountSwitchWidget->currentItem()->text(); auto selectedUser = this->ui.accountSwitchWidget->currentItem()->text();
if (selectedUser == ANONYMOUS_USERNAME_LABEL) { if (selectedUser == ANONYMOUS_USERNAME_LABEL) {
// Do nothing // Do nothing
return; return;
} }
AccountManager::getInstance().Twitch.removeUser(selectedUser); AccountManager::getInstance().Twitch.removeUser(selectedUser);
}); });