diff --git a/ircmanager.cpp b/ircmanager.cpp index de1790d1d..9c37279f2 100644 --- a/ircmanager.cpp +++ b/ircmanager.cpp @@ -28,7 +28,7 @@ IrcManager IrcManager::instance; const QString IrcManager::defaultClientId("7ue61iz46fz11y3cugd0l3tawb4taal"); IrcManager::IrcManager() - : _account(AccountManager::getInstance().getAnon()) + : _account(AccountManager::getInstance().getTwitchAnon()) , _connection() , _connectionMutex() , _connectionGeneration(0) diff --git a/usermanager.cpp b/usermanager.cpp index 49c47f5a7..964f15d6d 100644 --- a/usermanager.cpp +++ b/usermanager.cpp @@ -5,12 +5,40 @@ namespace chatterino { AccountManager AccountManager::instance; AccountManager::AccountManager() - : _anon("justinfan64537", "", "") + : _twitchAnon("justinfan64537", "", "") + , _twitchUsers() + , _twitchUsersMutex() { } -twitch::TwitchUser &AccountManager::getAnon() +twitch::TwitchUser &AccountManager::getTwitchAnon() { - return _anon; + return _twitchAnon; } + +std::vector AccountManager::getTwitchUsers() +{ + return std::vector(_twitchUsers); } + +bool AccountManager::removeTwitchUser(const QString &userName) +{ + std::lock_guard lock(_twitchUsersMutex); + + for (auto it = _twitchUsers.begin(); it != _twitchUsers.end(); it++) { + if ((*it).getUserName() == userName) { + _twitchUsers.erase(it); + return true; + } + } + + return false; +} + +void AccountManager::addTwitchUser(const twitch::TwitchUser &user) +{ + std::lock_guard lock(_twitchUsersMutex); + + _twitchUsers.push_back(user); +} +} // namespace chatterino diff --git a/usermanager.h b/usermanager.h index 0302a07a3..d2a3dedd9 100644 --- a/usermanager.h +++ b/usermanager.h @@ -3,6 +3,8 @@ #include "twitch/twitchuser.h" +#include + namespace chatterino { class AccountManager @@ -13,15 +15,21 @@ public: return instance; } - twitch::TwitchUser &getAnon(); + twitch::TwitchUser &getTwitchAnon(); + + std::vector getTwitchUsers(); + bool removeTwitchUser(const QString &userName); + void addTwitchUser(const twitch::TwitchUser &user); private: static AccountManager instance; AccountManager(); - twitch::TwitchUser _anon; + twitch::TwitchUser _twitchAnon; + std::vector _twitchUsers; + std::mutex _twitchUsersMutex; }; -} +} // namespace chatterino #endif // ACCOUNTMANAGER_H diff --git a/widgets/settingsdialog.cpp b/widgets/settingsdialog.cpp index 3510f9851..b495fbc8e 100644 --- a/widgets/settingsdialog.cpp +++ b/widgets/settingsdialog.cpp @@ -1,4 +1,6 @@ #include "widgets/settingsdialog.h" +#include "twitch/twitchuser.h" +#include "usermanager.h" #include "widgets/settingsdialogtab.h" #include "windowmanager.h" @@ -7,6 +9,7 @@ #include #include #include +#include #include #include @@ -63,6 +66,38 @@ void SettingsDialog::addTabs() QVBoxLayout *vbox; + // Accounts + vbox = new QVBoxLayout(); + + { + // add remove buttons + auto buttonBox = new QDialogButtonBox(this); + + auto addButton = new QPushButton("add", this); + auto removeButton = new QPushButton("remove", this); + + buttonBox->addButton(addButton, QDialogButtonBox::YesRole); + buttonBox->addButton(removeButton, QDialogButtonBox::NoRole); + + vbox->addWidget(buttonBox); + + // listview + auto listWidget = new QListWidget(this); + + listWidget->addItem("xD"); + listWidget->addItem("vi von"); + listWidget->addItem("monkaS"); + + for (auto &user : AccountManager::getInstance().getTwitchUsers()) { + listWidget->addItem(user.getUserName()); + } + + vbox->addWidget(listWidget); + } + + // vbox->addStretch(1); + addTab(vbox, "Accounts", ":/images/Message_16xLG.png"); + // Appearance vbox = new QVBoxLayout(); @@ -81,7 +116,7 @@ void SettingsDialog::addTabs() form->addRow("Theme:", combo); form->addRow("Theme color:", slider); form->addRow("Font:", font); - form->addRow("", compactTabs); + form->addRow("Tabbar:", compactTabs); form->addRow("", hidePreferencesButton); form->addRow("", hideUserButton); @@ -148,21 +183,26 @@ void SettingsDialog::addTabs() // Behaviour vbox = new QVBoxLayout(); - vbox->addWidget(createCheckbox("Hide input box if empty", settings.hideEmptyInput)); - vbox->addWidget( - createCheckbox("Mention users with a @ (except in commands)", settings.mentionUsersWithAt)); - vbox->addWidget(createCheckbox("Window always on top", settings.windowTopMost)); - vbox->addWidget( - createCheckbox("Show last read message indicator", settings.showLastMessageIndicator)); - { - auto v = new QVBoxLayout(); - v->addWidget(new QLabel("Mouse scroll speed")); + auto form = new QFormLayout(); + + form->addRow("Window:", createCheckbox("Window always on top", settings.windowTopMost)); + form->addRow("Messages:", createCheckbox("Mention users with a @ (except in commands)", + settings.mentionUsersWithAt)); + form->addRow("", createCheckbox("Hide input box if empty", settings.hideEmptyInput)); + form->addRow("", createCheckbox("Show last read message indicator", + settings.showLastMessageIndicator)); + + // auto v = new QVBoxLayout(); + // v->addWidget(new QLabel("Mouse scroll speed")); auto scroll = new QSlider(Qt::Horizontal); + form->addRow("Mouse scroll speed:", scroll); - v->addWidget(scroll); - v->addStretch(1); + // v->addWidget(scroll); + // v->addStretch(1); + // vbox->addLayout(v); + vbox->addLayout(form); } vbox->addStretch(1);