mirror of
https://github.com/Chatterino/chatterino2.git
synced 2024-11-13 19:49:51 +01:00
Added "Anonymous" (aka not logged in) as an option for the account chooser
This commit is contained in:
parent
bf39851776
commit
5c6411b50b
|
@ -83,12 +83,14 @@ AccountManager::AccountManager()
|
||||||
if (user) {
|
if (user) {
|
||||||
debug::Log("[AccountManager:currentUsernameChanged] User successfully updated to {}",
|
debug::Log("[AccountManager:currentUsernameChanged] User successfully updated to {}",
|
||||||
newUsername);
|
newUsername);
|
||||||
// XXX: Should we set the user regardless if the username is found or not?
|
|
||||||
// I can see the logic in setting it to nullptr if the `currentUsername` value has been
|
|
||||||
// set to "" or an invalid username
|
|
||||||
this->Twitch.currentUser = user;
|
this->Twitch.currentUser = user;
|
||||||
this->Twitch.userChanged.invoke();
|
} else {
|
||||||
|
debug::Log(
|
||||||
|
"[AccountManager:currentUsernameChanged] User successfully updated to anonymous");
|
||||||
|
this->Twitch.currentUser = this->Twitch.anonymousUser;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
this->Twitch.userChanged.invoke();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -124,10 +126,14 @@ void AccountManager::load()
|
||||||
|
|
||||||
auto currentUser = this->Twitch.findUserByUsername(
|
auto currentUser = this->Twitch.findUserByUsername(
|
||||||
QString::fromStdString(this->Twitch.currentUsername.getValue()));
|
QString::fromStdString(this->Twitch.currentUsername.getValue()));
|
||||||
|
|
||||||
if (currentUser) {
|
if (currentUser) {
|
||||||
this->Twitch.currentUser = currentUser;
|
this->Twitch.currentUser = currentUser;
|
||||||
this->Twitch.userChanged.invoke();
|
} else {
|
||||||
|
this->Twitch.currentUser = this->Twitch.anonymousUser;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
this->Twitch.userChanged.invoke();
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace chatterino
|
} // namespace chatterino
|
||||||
|
|
|
@ -129,28 +129,42 @@ QVBoxLayout *SettingsDialog::createAccountsTab()
|
||||||
// listview
|
// listview
|
||||||
auto listWidget = new QListWidget(this);
|
auto listWidget = new QListWidget(this);
|
||||||
|
|
||||||
|
static QString anonUsername(" - anonymous - ");
|
||||||
|
|
||||||
|
listWidget->addItem(anonUsername);
|
||||||
|
|
||||||
for (const auto &userName : AccountManager::getInstance().Twitch.getUsernames()) {
|
for (const auto &userName : AccountManager::getInstance().Twitch.getUsernames()) {
|
||||||
listWidget->addItem(userName);
|
listWidget->addItem(userName);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Select the currently logged in user
|
// Select the currently logged in user
|
||||||
if (listWidget->count() > 0) {
|
if (listWidget->count() > 0) {
|
||||||
const QString ¤tUsername =
|
auto currentUser = AccountManager::getInstance().Twitch.getCurrent();
|
||||||
AccountManager::getInstance().Twitch.getCurrent()->getUserName();
|
|
||||||
|
if (currentUser->isAnon()) {
|
||||||
|
listWidget->setCurrentRow(0);
|
||||||
|
} else {
|
||||||
|
const QString ¤tUsername = currentUser->getUserName();
|
||||||
for (int i = 0; i < listWidget->count(); ++i) {
|
for (int i = 0; i < listWidget->count(); ++i) {
|
||||||
QString itemText = listWidget->item(i)->text();
|
QString itemText = listWidget->item(i)->text();
|
||||||
|
|
||||||
if (itemText.compare(currentUsername, Qt::CaseInsensitive) == 0) {
|
if (itemText.compare(currentUsername, Qt::CaseInsensitive) == 0) {
|
||||||
listWidget->setCurrentRow(i);
|
listWidget->setCurrentRow(i);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
QObject::connect(listWidget, &QListWidget::clicked, this, [&, listWidget] {
|
QObject::connect(listWidget, &QListWidget::clicked, this, [&, listWidget] {
|
||||||
if (!listWidget->selectedItems().isEmpty()) {
|
if (!listWidget->selectedItems().isEmpty()) {
|
||||||
QString newUsername = listWidget->currentItem()->text();
|
QString newUsername = listWidget->currentItem()->text();
|
||||||
|
if (newUsername.compare(anonUsername, Qt::CaseInsensitive) == 0) {
|
||||||
|
AccountManager::getInstance().Twitch.currentUsername = "";
|
||||||
|
} else {
|
||||||
AccountManager::getInstance().Twitch.currentUsername = newUsername.toStdString();
|
AccountManager::getInstance().Twitch.currentUsername = newUsername.toStdString();
|
||||||
}
|
}
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
layout->addWidget(listWidget);
|
layout->addWidget(listWidget);
|
||||||
|
|
Loading…
Reference in a new issue