mirror of
https://github.com/Chatterino/chatterino2.git
synced 2024-11-13 19:49:51 +01:00
ae26b835b6
Things that were once singletons are no longer singletons, but are instead stored in the "Application" singleton Some singletons still remain, and some renaming/renamespacing is left
86 lines
2.1 KiB
C++
86 lines
2.1 KiB
C++
#include "accountswitchwidget.hpp"
|
|
|
|
#include "application.hpp"
|
|
#include "const.hpp"
|
|
#include "singletons/accountmanager.hpp"
|
|
|
|
namespace chatterino {
|
|
namespace widgets {
|
|
|
|
AccountSwitchWidget::AccountSwitchWidget(QWidget *parent)
|
|
: QListWidget(parent)
|
|
{
|
|
auto app = getApp();
|
|
|
|
this->addItem(ANONYMOUS_USERNAME_LABEL);
|
|
|
|
for (const auto &userName : app->accounts->Twitch.getUsernames()) {
|
|
this->addItem(userName);
|
|
}
|
|
|
|
app->accounts->Twitch.userListUpdated.connect([=]() {
|
|
this->blockSignals(true);
|
|
|
|
this->clear();
|
|
|
|
this->addItem(ANONYMOUS_USERNAME_LABEL);
|
|
|
|
for (const auto &userName : app->accounts->Twitch.getUsernames()) {
|
|
this->addItem(userName);
|
|
}
|
|
|
|
this->refreshSelection();
|
|
|
|
this->blockSignals(false);
|
|
});
|
|
|
|
this->refreshSelection();
|
|
|
|
QObject::connect(this, &QListWidget::clicked, [=] {
|
|
if (!this->selectedItems().isEmpty()) {
|
|
QString newUsername = this->currentItem()->text();
|
|
if (newUsername.compare(ANONYMOUS_USERNAME_LABEL, Qt::CaseInsensitive) == 0) {
|
|
app->accounts->Twitch.currentUsername = "";
|
|
} else {
|
|
app->accounts->Twitch.currentUsername = newUsername.toStdString();
|
|
}
|
|
}
|
|
});
|
|
}
|
|
|
|
void AccountSwitchWidget::refresh()
|
|
{
|
|
this->refreshSelection();
|
|
}
|
|
|
|
void AccountSwitchWidget::refreshSelection()
|
|
{
|
|
this->blockSignals(true);
|
|
|
|
// Select the currently logged in user
|
|
if (this->count() > 0) {
|
|
auto app = getApp();
|
|
|
|
auto currentUser = app->accounts->Twitch.getCurrent();
|
|
|
|
if (currentUser->isAnon()) {
|
|
this->setCurrentRow(0);
|
|
} else {
|
|
const QString ¤tUsername = currentUser->getUserName();
|
|
for (int i = 0; i < this->count(); ++i) {
|
|
QString itemText = this->item(i)->text();
|
|
|
|
if (itemText.compare(currentUsername, Qt::CaseInsensitive) == 0) {
|
|
this->setCurrentRow(i);
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
this->blockSignals(false);
|
|
}
|
|
|
|
} // namespace widgets
|
|
} // namespace chatterino
|