Perform initial refactoring work

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
This commit is contained in:
Rasmus Karlsson
2018-04-27 22:11:19 +02:00
parent 32b6417a55
commit ae26b835b6
78 changed files with 850 additions and 773 deletions
+12 -8
View File
@@ -1,4 +1,6 @@
#include "accountswitchwidget.hpp"
#include "application.hpp"
#include "const.hpp"
#include "singletons/accountmanager.hpp"
@@ -8,22 +10,22 @@ namespace widgets {
AccountSwitchWidget::AccountSwitchWidget(QWidget *parent)
: QListWidget(parent)
{
singletons::AccountManager &accountManager = singletons::AccountManager::getInstance();
auto app = getApp();
this->addItem(ANONYMOUS_USERNAME_LABEL);
for (const auto &userName : accountManager.Twitch.getUsernames()) {
for (const auto &userName : app->accounts->Twitch.getUsernames()) {
this->addItem(userName);
}
accountManager.Twitch.userListUpdated.connect([this, &accountManager]() {
app->accounts->Twitch.userListUpdated.connect([=]() {
this->blockSignals(true);
this->clear();
this->addItem(ANONYMOUS_USERNAME_LABEL);
for (const auto &userName : accountManager.Twitch.getUsernames()) {
for (const auto &userName : app->accounts->Twitch.getUsernames()) {
this->addItem(userName);
}
@@ -34,13 +36,13 @@ AccountSwitchWidget::AccountSwitchWidget(QWidget *parent)
this->refreshSelection();
QObject::connect(this, &QListWidget::clicked, [this, &accountManager] {
QObject::connect(this, &QListWidget::clicked, [=] {
if (!this->selectedItems().isEmpty()) {
QString newUsername = this->currentItem()->text();
if (newUsername.compare(ANONYMOUS_USERNAME_LABEL, Qt::CaseInsensitive) == 0) {
accountManager.Twitch.currentUsername = "";
app->accounts->Twitch.currentUsername = "";
} else {
accountManager.Twitch.currentUsername = newUsername.toStdString();
app->accounts->Twitch.currentUsername = newUsername.toStdString();
}
}
});
@@ -57,7 +59,9 @@ void AccountSwitchWidget::refreshSelection()
// Select the currently logged in user
if (this->count() > 0) {
auto currentUser = singletons::AccountManager::getInstance().Twitch.getCurrent();
auto app = getApp();
auto currentUser = app->accounts->Twitch.getCurrent();
if (currentUser->isAnon()) {
this->setCurrentRow(0);