diff --git a/chatterino.pro b/chatterino.pro index a611e711d..c55313f52 100644 --- a/chatterino.pro +++ b/chatterino.pro @@ -114,7 +114,6 @@ SOURCES += \ src/providers/twitch/twitchmessagebuilder.cpp \ src/providers/twitch/twitchserver.cpp \ src/providers/twitch/pubsub.cpp \ - src/singletons/accountmanager.cpp \ src/singletons/commandmanager.cpp \ src/singletons/emotemanager.cpp \ src/singletons/fontmanager.cpp \ @@ -209,7 +208,10 @@ SOURCES += \ src/widgets/helper/splitoverlay.cpp \ src/widgets/helper/dropoverlay.cpp \ src/widgets/helper/splitnode.cpp \ - src/widgets/notificationpopup.cpp + src/widgets/notificationpopup.cpp \ + src/controllers/taggedusers/taggeduserscontroller.cpp \ + src/controllers/taggedusers/taggeduser.cpp \ + src/controllers/taggedusers/taggedusersmodel.cpp HEADERS += \ src/precompiled_header.hpp \ @@ -238,7 +240,6 @@ HEADERS += \ src/providers/twitch/twitchmessagebuilder.hpp \ src/providers/twitch/twitchserver.hpp \ src/providers/twitch/pubsub.hpp \ - src/singletons/accountmanager.hpp \ src/singletons/commandmanager.hpp \ src/singletons/emotemanager.hpp \ src/singletons/fontmanager.hpp \ @@ -359,7 +360,11 @@ HEADERS += \ src/widgets/helper/dropoverlay.hpp \ src/widgets/helper/splitnode.hpp \ src/widgets/notificationpopup.hpp \ - src/util/mutexvalue.h + src/util/mutexvalue.h \ + src/controllers/taggedusers/taggeduserscontroller.hpp \ + src/controllers/taggedusers/taggeduser.hpp \ + src/providerid.hpp \ + src/controllers/taggedusers/taggedusersmodel.hpp RESOURCES += \ resources/resources.qrc diff --git a/src/application.cpp b/src/application.cpp index 36edd2039..d833ca157 100644 --- a/src/application.cpp +++ b/src/application.cpp @@ -1,11 +1,12 @@ #include "application.hpp" +#include "controllers/accounts/accountcontroller.hpp" #include "controllers/commands/commandcontroller.hpp" #include "controllers/highlights/highlightcontroller.hpp" #include "controllers/ignores/ignorecontroller.hpp" +#include "controllers/taggedusers/taggeduserscontroller.hpp" #include "providers/twitch/pubsub.hpp" #include "providers/twitch/twitchserver.hpp" -#include "singletons/accountmanager.hpp" #include "singletons/emotemanager.hpp" #include "singletons/fontmanager.hpp" #include "singletons/loggingmanager.hpp" @@ -69,7 +70,8 @@ void Application::construct() this->commands = new controllers::commands::CommandController; this->highlights = new controllers::highlights::HighlightController; this->ignores = new controllers::ignores::IgnoreController; - this->accounts = new singletons::AccountManager; + this->taggedUsers = new controllers::taggedusers::TaggedUsersController; + this->accounts = new controllers::accounts::AccountController; this->emotes = new singletons::EmoteManager; this->fonts = new singletons::FontManager; this->resources = new singletons::ResourceManager; diff --git a/src/application.hpp b/src/application.hpp index ed13a808c..ccb1ff2d2 100644 --- a/src/application.hpp +++ b/src/application.hpp @@ -26,6 +26,12 @@ class HighlightController; namespace ignores { class IgnoreController; } +namespace taggedusers { +class TaggedUsersController; +} +namespace accounts { +class AccountController; +} } // namespace controllers namespace singletons { @@ -67,7 +73,8 @@ public: controllers::commands::CommandController *commands = nullptr; controllers::highlights::HighlightController *highlights = nullptr; controllers::ignores::IgnoreController *ignores = nullptr; - singletons::AccountManager *accounts = nullptr; + controllers::taggedusers::TaggedUsersController *taggedUsers = nullptr; + controllers::accounts::AccountController *accounts = nullptr; singletons::EmoteManager *emotes = nullptr; singletons::NativeMessagingManager *nativeMessaging = nullptr; singletons::SettingManager *settings = nullptr; diff --git a/src/controllers/accounts/account.cpp b/src/controllers/accounts/account.cpp index a0dfc46b1..bbf42ed0b 100644 --- a/src/controllers/accounts/account.cpp +++ b/src/controllers/accounts/account.cpp @@ -1,10 +1,13 @@ #include "account.hpp" +#include + namespace chatterino { namespace controllers { namespace accounts { -Account::Account(const QString &category) +Account::Account(const QString &_category) + : category(_category) { } @@ -15,14 +18,10 @@ const QString &Account::getCategory() const bool Account::operator<(const Account &other) const { - if (this->category < other.category) { - return true; - } else if (this->category == other.category) { - if (this->toString() < other.toString()) { - return true; - } - } - return false; + QString a = this->toString(); + QString b = other.toString(); + + return std::tie(this->category, a) < std::tie(other.category, b); } } // namespace accounts diff --git a/src/controllers/accounts/accountcontroller.cpp b/src/controllers/accounts/accountcontroller.cpp index ce720435f..f201034fb 100644 --- a/src/controllers/accounts/accountcontroller.cpp +++ b/src/controllers/accounts/accountcontroller.cpp @@ -10,6 +10,11 @@ AccountController::AccountController() { } +void AccountController::load() +{ + this->Twitch.load(); +} + AccountModel *AccountController::createModel(QObject *parent) { AccountModel *model = new AccountModel(parent); diff --git a/src/controllers/accounts/accountcontroller.hpp b/src/controllers/accounts/accountcontroller.hpp index 242cf7679..34329a741 100644 --- a/src/controllers/accounts/accountcontroller.hpp +++ b/src/controllers/accounts/accountcontroller.hpp @@ -3,6 +3,7 @@ #include #include "controllers/accounts/account.hpp" +#include "providers/twitch/twitchaccountmanager.hpp" #include "util/sharedptrelementless.hpp" #include "util/signalvector2.hpp" @@ -19,6 +20,10 @@ public: AccountModel *createModel(QObject *parent); + void load(); + + providers::twitch::TwitchAccountManager Twitch; + private: util::SortedSignalVector, util::SharedPtrElementLess> accounts; diff --git a/src/controllers/accounts/accountmodel.cpp b/src/controllers/accounts/accountmodel.cpp index 9d527570d..88cce7ddb 100644 --- a/src/controllers/accounts/accountmodel.cpp +++ b/src/controllers/accounts/accountmodel.cpp @@ -10,9 +10,10 @@ AccountModel::AccountModel(QObject *parent) } // turn a vector item into a model row -std::shared_ptr AccountModel::getItemFromRow(std::vector &row) +std::shared_ptr AccountModel::getItemFromRow(std::vector &, + const std::shared_ptr &original) { - return nullptr; + return original; } // turns a row in the model into a vector item diff --git a/src/controllers/accounts/accountmodel.hpp b/src/controllers/accounts/accountmodel.hpp index 40b74750c..5eaa77662 100644 --- a/src/controllers/accounts/accountmodel.hpp +++ b/src/controllers/accounts/accountmodel.hpp @@ -16,7 +16,8 @@ public: protected: // turn a vector item into a model row - virtual std::shared_ptr getItemFromRow(std::vector &row) override; + virtual std::shared_ptr getItemFromRow( + std::vector &row, const std::shared_ptr &original) override; // turns a row in the model into a vector item virtual void getRowFromItem(const std::shared_ptr &item, diff --git a/src/controllers/commands/commandcontroller.cpp b/src/controllers/commands/commandcontroller.cpp index f1b299f25..dda163769 100644 --- a/src/controllers/commands/commandcontroller.cpp +++ b/src/controllers/commands/commandcontroller.cpp @@ -1,12 +1,12 @@ #include "commandcontroller.hpp" #include "application.hpp" +#include "controllers/accounts/accountcontroller.hpp" #include "controllers/commands/command.hpp" #include "controllers/commands/commandmodel.hpp" #include "messages/messagebuilder.hpp" #include "providers/twitch/twitchchannel.hpp" #include "providers/twitch/twitchserver.hpp" -#include "singletons/accountmanager.hpp" #include "singletons/pathmanager.hpp" #include "util/signalvector2.hpp" diff --git a/src/controllers/commands/commandmodel.cpp b/src/controllers/commands/commandmodel.cpp index d87ffacfc..621e9d264 100644 --- a/src/controllers/commands/commandmodel.cpp +++ b/src/controllers/commands/commandmodel.cpp @@ -11,7 +11,7 @@ CommandModel::CommandModel(QObject *parent) } // turn a vector item into a model row -Command CommandModel::getItemFromRow(std::vector &row) +Command CommandModel::getItemFromRow(std::vector &row, const Command &original) { return Command(row[0]->data(Qt::EditRole).toString(), row[1]->data(Qt::EditRole).toString()); } diff --git a/src/controllers/commands/commandmodel.hpp b/src/controllers/commands/commandmodel.hpp index 22931c5b5..7512c5761 100644 --- a/src/controllers/commands/commandmodel.hpp +++ b/src/controllers/commands/commandmodel.hpp @@ -17,7 +17,8 @@ class CommandModel : public util::SignalVectorModel protected: // turn a vector item into a model row - virtual Command getItemFromRow(std::vector &row) override; + virtual Command getItemFromRow(std::vector &row, + const Command &command) override; // turns a row in the model into a vector item virtual void getRowFromItem(const Command &item, std::vector &row) override; diff --git a/src/controllers/highlights/highlightcontroller.cpp b/src/controllers/highlights/highlightcontroller.cpp index 8c6b789da..df10341e5 100644 --- a/src/controllers/highlights/highlightcontroller.cpp +++ b/src/controllers/highlights/highlightcontroller.cpp @@ -22,7 +22,6 @@ void HighlightController::initialize() } this->phrases.delayedItemsChanged.connect([this] { // - int xd = this->phrases.getVector().size(); this->highlightsSetting.setValue(this->phrases.getVector()); }); } diff --git a/src/controllers/highlights/highlightmodel.cpp b/src/controllers/highlights/highlightmodel.cpp index 280a205c4..5dfbaf608 100644 --- a/src/controllers/highlights/highlightmodel.cpp +++ b/src/controllers/highlights/highlightmodel.cpp @@ -15,7 +15,8 @@ HighlightModel::HighlightModel(QObject *parent) } // turn a vector item into a model row -HighlightPhrase HighlightModel::getItemFromRow(std::vector &row) +HighlightPhrase HighlightModel::getItemFromRow(std::vector &row, + const HighlightPhrase &original) { // key, alert, sound, regex diff --git a/src/controllers/highlights/highlightmodel.hpp b/src/controllers/highlights/highlightmodel.hpp index f4a24fb96..84dd3feee 100644 --- a/src/controllers/highlights/highlightmodel.hpp +++ b/src/controllers/highlights/highlightmodel.hpp @@ -17,7 +17,8 @@ class HighlightModel : public util::SignalVectorModel protected: // turn a vector item into a model row - virtual HighlightPhrase getItemFromRow(std::vector &row) override; + virtual HighlightPhrase getItemFromRow(std::vector &row, + const HighlightPhrase &original) override; // turns a row in the model into a vector item virtual void getRowFromItem(const HighlightPhrase &item, diff --git a/src/controllers/ignores/ignoremodel.cpp b/src/controllers/ignores/ignoremodel.cpp index d8e59dc2c..af38db8db 100644 --- a/src/controllers/ignores/ignoremodel.cpp +++ b/src/controllers/ignores/ignoremodel.cpp @@ -15,7 +15,8 @@ IgnoreModel::IgnoreModel(QObject *parent) } // turn a vector item into a model row -IgnorePhrase IgnoreModel::getItemFromRow(std::vector &row) +IgnorePhrase IgnoreModel::getItemFromRow(std::vector &row, + const IgnorePhrase &original) { // key, regex diff --git a/src/controllers/ignores/ignoremodel.hpp b/src/controllers/ignores/ignoremodel.hpp index a0bba4ec8..3eacddfe7 100644 --- a/src/controllers/ignores/ignoremodel.hpp +++ b/src/controllers/ignores/ignoremodel.hpp @@ -17,7 +17,8 @@ class IgnoreModel : public util::SignalVectorModel protected: // turn a vector item into a model row - virtual IgnorePhrase getItemFromRow(std::vector &row) override; + virtual IgnorePhrase getItemFromRow(std::vector &row, + const IgnorePhrase &original) override; // turns a row in the model into a vector item virtual void getRowFromItem(const IgnorePhrase &item, diff --git a/src/controllers/taggedusers/taggeduser.cpp b/src/controllers/taggedusers/taggeduser.cpp new file mode 100644 index 000000000..6f50957b9 --- /dev/null +++ b/src/controllers/taggedusers/taggeduser.cpp @@ -0,0 +1,24 @@ +#include "taggeduser.hpp" + +#include + +namespace chatterino { +namespace controllers { +namespace taggedusers { + +TaggedUser::TaggedUser(ProviderId _provider, const QString &_name, const QString &_id) + : provider(_provider) + , name(_name) + , id(_id) +{ +} + +bool TaggedUser::operator<(const TaggedUser &other) const +{ + return std::tie(this->provider, this->name, this->id) < + std::tie(other.provider, other.name, other.id); +} + +} // namespace taggedusers +} // namespace controllers +} // namespace chatterino diff --git a/src/controllers/taggedusers/taggeduser.hpp b/src/controllers/taggedusers/taggeduser.hpp new file mode 100644 index 000000000..3a8d3b173 --- /dev/null +++ b/src/controllers/taggedusers/taggeduser.hpp @@ -0,0 +1,24 @@ +#pragma once + +#include +#include + +namespace chatterino { +namespace controllers { +namespace taggedusers { + +class TaggedUser +{ +public: + TaggedUser(ProviderId provider, const QString &name, const QString &id); + + bool operator<(const TaggedUser &other) const; + + ProviderId provider; + QString name; + QString id; +}; + +} // namespace taggedusers +} // namespace controllers +} // namespace chatterino diff --git a/src/controllers/taggedusers/taggeduserscontroller.cpp b/src/controllers/taggedusers/taggeduserscontroller.cpp new file mode 100644 index 000000000..98486c1fe --- /dev/null +++ b/src/controllers/taggedusers/taggeduserscontroller.cpp @@ -0,0 +1,23 @@ +#include "taggeduserscontroller.hpp" + +#include "controllers/taggedusers/taggedusersmodel.hpp" + +namespace chatterino { +namespace controllers { +namespace taggedusers { + +TaggedUsersController::TaggedUsersController() +{ +} + +TaggedUsersModel *TaggedUsersController::createModel(QObject *parent) +{ + TaggedUsersModel *model = new TaggedUsersModel(parent); + model->init(&this->users); + + return model; +} + +} // namespace taggedusers +} // namespace controllers +} // namespace chatterino diff --git a/src/controllers/taggedusers/taggeduserscontroller.hpp b/src/controllers/taggedusers/taggeduserscontroller.hpp new file mode 100644 index 000000000..85e845c84 --- /dev/null +++ b/src/controllers/taggedusers/taggeduserscontroller.hpp @@ -0,0 +1,24 @@ +#pragma once + +#include "controllers/taggedusers/taggeduser.hpp" +#include "util/signalvector2.hpp" + +namespace chatterino { +namespace controllers { +namespace taggedusers { + +class TaggedUsersModel; + +class TaggedUsersController +{ +public: + TaggedUsersController(); + + util::SortedSignalVector> users; + + TaggedUsersModel *createModel(QObject *parent = nullptr); +}; + +} // namespace taggedusers +} // namespace controllers +} // namespace chatterino diff --git a/src/controllers/taggedusers/taggedusersmodel.cpp b/src/controllers/taggedusers/taggedusersmodel.cpp new file mode 100644 index 000000000..565bdf2ef --- /dev/null +++ b/src/controllers/taggedusers/taggedusersmodel.cpp @@ -0,0 +1,66 @@ +#include "taggedusersmodel.hpp" + +#include "application.hpp" +#include "util/standarditemhelper.hpp" + +namespace chatterino { +namespace controllers { +namespace taggedusers { + +// commandmodel +TaggedUsersModel::TaggedUsersModel(QObject *parent) + : util::SignalVectorModel(1, parent) +{ +} + +// turn a vector item into a model row +TaggedUser TaggedUsersModel::getItemFromRow(std::vector &row, + const TaggedUser &original) +{ + return original; +} + +// turns a row in the model into a vector item +void TaggedUsersModel::getRowFromItem(const TaggedUser &item, std::vector &row) +{ + util::setStringItem(row[0], item.name); +} + +void TaggedUsersModel::afterInit() +{ + // std::vector row = this->createRow(); + // util::setBoolItem(row[0], getApp()->settings->enableHighlightsSelf.getValue(), true, + // false); row[0]->setData("Your username (automatic)", Qt::DisplayRole); + // util::setBoolItem(row[1], getApp()->settings->enableHighlightTaskbar.getValue(), true, + // false); util::setBoolItem(row[2], getApp()->settings->enableHighlightSound.getValue(), + // true, false); row[3]->setFlags(0); this->insertCustomRow(row, 0); +} + +// void TaggedUserModel::customRowSetData(const std::vector &row, int column, +// const QVariant &value, int role) +//{ +// switch (column) { +// case 0: { +// if (role == Qt::CheckStateRole) { +// getApp()->settings->enableHighlightsSelf.setValue(value.toBool()); +// } +// } break; +// case 1: { +// if (role == Qt::CheckStateRole) { +// getApp()->settings->enableHighlightTaskbar.setValue(value.toBool()); +// } +// } break; +// case 2: { +// if (role == Qt::CheckStateRole) { +// getApp()->settings->enableHighlightSound.setValue(value.toBool()); +// } +// } break; +// case 3: { +// // empty element +// } break; +// } +//} + +} // namespace taggedusers +} // namespace controllers +} // namespace chatterino diff --git a/src/controllers/taggedusers/taggedusersmodel.hpp b/src/controllers/taggedusers/taggedusersmodel.hpp new file mode 100644 index 000000000..6db822c24 --- /dev/null +++ b/src/controllers/taggedusers/taggedusersmodel.hpp @@ -0,0 +1,34 @@ +#pragma once + +#include "controllers/taggedusers/taggeduser.hpp" +#include "util/signalvectormodel.hpp" + +namespace chatterino { +namespace controllers { +namespace taggedusers { + +class TaggedUsersController; + +class TaggedUsersModel : public util::SignalVectorModel +{ + explicit TaggedUsersModel(QObject *parent); + +protected: + // turn a vector item into a model row + virtual TaggedUser getItemFromRow(std::vector &row, + const TaggedUser &original) override; + + // turns a row in the model into a vector item + virtual void getRowFromItem(const TaggedUser &item, std::vector &row) override; + + virtual void afterInit() override; + + // virtual void customRowSetData(const std::vector &row, int column, + // const QVariant &value, int role) override; + + friend class TaggedUsersController; +}; + +} // namespace taggedusers +} // namespace controllers +} // namespace chatterino diff --git a/src/providerid.hpp b/src/providerid.hpp new file mode 100644 index 000000000..1ec190a30 --- /dev/null +++ b/src/providerid.hpp @@ -0,0 +1,5 @@ +#pragma once + +namespace chatterino { +enum class ProviderId { Twitch }; +} diff --git a/src/providers/twitch/pubsub.cpp b/src/providers/twitch/pubsub.cpp index e8af28b00..a0a4fc96d 100644 --- a/src/providers/twitch/pubsub.cpp +++ b/src/providers/twitch/pubsub.cpp @@ -3,7 +3,6 @@ #include "debug/log.hpp" #include "providers/twitch/pubsubactions.hpp" #include "providers/twitch/pubsubhelpers.hpp" -#include "singletons/accountmanager.hpp" #include "util/rapidjson-helpers.hpp" #include diff --git a/src/providers/twitch/pubsubhelpers.cpp b/src/providers/twitch/pubsubhelpers.cpp index f27ac94de..395ae44f9 100644 --- a/src/providers/twitch/pubsubhelpers.cpp +++ b/src/providers/twitch/pubsubhelpers.cpp @@ -1,7 +1,6 @@ #include "providers/twitch/pubsubhelpers.hpp" #include "providers/twitch/pubsubactions.hpp" -#include "singletons/accountmanager.hpp" #include "util/rapidjson-helpers.hpp" namespace chatterino { diff --git a/src/providers/twitch/twitchaccountmanager.hpp b/src/providers/twitch/twitchaccountmanager.hpp index 2486ad8cc..973d3d700 100644 --- a/src/providers/twitch/twitchaccountmanager.hpp +++ b/src/providers/twitch/twitchaccountmanager.hpp @@ -15,10 +15,11 @@ // namespace chatterino { - -namespace singletons { -class AccountManager; -} // namespace singletons +namespace controllers { +namespace accounts { +class AccountController; +} +} // namespace controllers namespace providers { namespace twitch { @@ -70,7 +71,7 @@ private: std::vector> users; mutable std::mutex mutex; - friend class chatterino::singletons::AccountManager; + friend class chatterino::controllers::accounts::AccountController; }; } // namespace twitch diff --git a/src/providers/twitch/twitchchannel.cpp b/src/providers/twitch/twitchchannel.cpp index c66508a87..562dc6d31 100644 --- a/src/providers/twitch/twitchchannel.cpp +++ b/src/providers/twitch/twitchchannel.cpp @@ -5,7 +5,6 @@ #include "messages/message.hpp" #include "providers/twitch/pubsub.hpp" #include "providers/twitch/twitchmessagebuilder.hpp" -#include "singletons/accountmanager.hpp" #include "singletons/emotemanager.hpp" #include "singletons/ircmanager.hpp" #include "singletons/settingsmanager.hpp" diff --git a/src/providers/twitch/twitchmessagebuilder.cpp b/src/providers/twitch/twitchmessagebuilder.cpp index be8f2a1e8..f3da63514 100644 --- a/src/providers/twitch/twitchmessagebuilder.cpp +++ b/src/providers/twitch/twitchmessagebuilder.cpp @@ -1,11 +1,11 @@ #include "providers/twitch/twitchmessagebuilder.hpp" #include "application.hpp" +#include "controllers/accounts/accountcontroller.hpp" #include "controllers/highlights/highlightcontroller.hpp" #include "controllers/ignores/ignorecontroller.hpp" #include "debug/log.hpp" #include "providers/twitch/twitchchannel.hpp" -#include "singletons/accountmanager.hpp" #include "singletons/emotemanager.hpp" #include "singletons/ircmanager.hpp" #include "singletons/resourcemanager.hpp" diff --git a/src/providers/twitch/twitchserver.cpp b/src/providers/twitch/twitchserver.cpp index a3db8f148..14405a697 100644 --- a/src/providers/twitch/twitchserver.cpp +++ b/src/providers/twitch/twitchserver.cpp @@ -1,12 +1,12 @@ #include "twitchserver.hpp" #include "application.hpp" +#include "controllers/accounts/accountcontroller.hpp" #include "controllers/highlights/highlightcontroller.hpp" #include "providers/twitch/ircmessagehandler.hpp" #include "providers/twitch/twitchaccount.hpp" #include "providers/twitch/twitchhelpers.hpp" #include "providers/twitch/twitchmessagebuilder.hpp" -#include "singletons/accountmanager.hpp" #include "util/posttothread.hpp" #include diff --git a/src/singletons/accountmanager.cpp b/src/singletons/accountmanager.cpp deleted file mode 100644 index 65dc2a08c..000000000 --- a/src/singletons/accountmanager.cpp +++ /dev/null @@ -1,12 +0,0 @@ -#include "singletons/accountmanager.hpp" - -namespace chatterino { -namespace singletons { - -void AccountManager::load() -{ - this->Twitch.load(); -} - -} // namespace singletons -} // namespace chatterino diff --git a/src/singletons/accountmanager.hpp b/src/singletons/accountmanager.hpp deleted file mode 100644 index de7a38abb..000000000 --- a/src/singletons/accountmanager.hpp +++ /dev/null @@ -1,21 +0,0 @@ -#pragma once - -#include "providers/twitch/twitchaccountmanager.hpp" - -namespace chatterino { -namespace singletons { - -class AccountManager -{ -public: - AccountManager() = default; - - ~AccountManager() = delete; - - void load(); - - providers::twitch::TwitchAccountManager Twitch; -}; - -} // namespace singletons -} // namespace chatterino diff --git a/src/util/signalvector2.hpp b/src/util/signalvector2.hpp index 8ad90d032..9196c7acb 100644 --- a/src/util/signalvector2.hpp +++ b/src/util/signalvector2.hpp @@ -107,15 +107,14 @@ template class SortedSignalVector : public BaseSignalVector { public: - virtual int insertItem(const TVectorItem &item, int proposedIndex = -1, - void *caller = 0) override + virtual int insertItem(const TVectorItem &item, int = -1, void *caller = nullptr) override { util::assertInGuiThread(); - int index = - this->vector.insert( - std::lower_bound(this->vector.begin(), this->vector.end(), item, Compare{}), item) - - this->vector.begin(); + auto it = std::lower_bound(this->vector.begin(), this->vector.end(), item, Compare{}); + int index = it - this->vector.begin(); + this->vector.insert(it, item); + typename ReadOnlySignalVector::ItemArgs args{item, index, caller}; this->itemInserted.invoke(args); this->invokeDelayedItemsChanged(); diff --git a/src/util/signalvectormodel.hpp b/src/util/signalvectormodel.hpp index 7da0637ed..c686f6760 100644 --- a/src/util/signalvectormodel.hpp +++ b/src/util/signalvectormodel.hpp @@ -2,6 +2,7 @@ #include #include +#include #include #include @@ -43,7 +44,7 @@ public: index = this->beforeInsert(args.item, row, index); this->beginInsertRows(QModelIndex(), index, index); - this->rows.insert(this->rows.begin() + index, Row(row)); + this->rows.insert(this->rows.begin() + index, Row(row, args.item)); this->endInsertRows(); }; @@ -117,7 +118,10 @@ public: } else { int vecRow = this->getVectorIndexFromModelIndex(row); this->vector->removeItem(vecRow, this); - TVectorItem item = this->getItemFromRow(this->rows[row].items); + + assert(this->rows[row].original); + TVectorItem item = + this->getItemFromRow(this->rows[row].items, this->rows[row].original.get()); this->vector->insertItem(item, vecRow, this); } @@ -192,7 +196,8 @@ protected: } // turn a vector item into a model row - virtual TVectorItem getItemFromRow(std::vector &row) = 0; + virtual TVectorItem getItemFromRow(std::vector &row, + const TVectorItem &original) = 0; // turns a row in the model into a vector item virtual void getRowFromItem(const TVectorItem &item, std::vector &row) = 0; @@ -232,6 +237,7 @@ protected: struct Row { std::vector items; + boost::optional original; bool isCustomRow; Row(std::vector _items, bool _isCustomRow = false) @@ -239,6 +245,14 @@ protected: , isCustomRow(_isCustomRow) { } + + Row(std::vector _items, const TVectorItem &_original, + bool _isCustomRow = false) + : items(std::move(_items)) + , original(_original) + , isCustomRow(_isCustomRow) + { + } }; std::vector rows; diff --git a/src/util/urlfetch.hpp b/src/util/urlfetch.hpp index c4f1c31ba..3e88eb639 100644 --- a/src/util/urlfetch.hpp +++ b/src/util/urlfetch.hpp @@ -1,8 +1,8 @@ #pragma once +#include "controllers/accounts/accountcontroller.hpp" #include "credentials.hpp" #include "debug/log.hpp" -#include "singletons/accountmanager.hpp" #include "util/networkmanager.hpp" #include "util/networkrequest.hpp" diff --git a/src/widgets/accountpopup.cpp b/src/widgets/accountpopup.cpp index fb189c061..85cba6fbd 100644 --- a/src/widgets/accountpopup.cpp +++ b/src/widgets/accountpopup.cpp @@ -3,7 +3,6 @@ #include "application.hpp" #include "channel.hpp" #include "credentials.hpp" -#include "singletons/accountmanager.hpp" #include "singletons/settingsmanager.hpp" #include "ui_accountpopupform.h" #include "util/urlfetch.hpp" diff --git a/src/widgets/accountswitchwidget.cpp b/src/widgets/accountswitchwidget.cpp index 39485b6e9..b0bb046c4 100644 --- a/src/widgets/accountswitchwidget.cpp +++ b/src/widgets/accountswitchwidget.cpp @@ -2,7 +2,7 @@ #include "application.hpp" #include "const.hpp" -#include "singletons/accountmanager.hpp" +#include "controllers/accounts/accountcontroller.hpp" namespace chatterino { namespace widgets { diff --git a/src/widgets/emotepopup.cpp b/src/widgets/emotepopup.cpp index d3787d584..89f52ae9a 100644 --- a/src/widgets/emotepopup.cpp +++ b/src/widgets/emotepopup.cpp @@ -1,9 +1,9 @@ #include "emotepopup.hpp" #include "application.hpp" +#include "controllers/accounts/accountcontroller.hpp" #include "messages/messagebuilder.hpp" #include "providers/twitch/twitchchannel.hpp" -#include "singletons/accountmanager.hpp" #include "widgets/notebook.hpp" #include diff --git a/src/widgets/settingspages/accountspage.cpp b/src/widgets/settingspages/accountspage.cpp index a5493c814..a07134dc0 100644 --- a/src/widgets/settingspages/accountspage.cpp +++ b/src/widgets/settingspages/accountspage.cpp @@ -2,11 +2,17 @@ #include "application.hpp" #include "const.hpp" -#include "singletons/accountmanager.hpp" +#include "controllers/accounts/accountcontroller.hpp" +#include "controllers/accounts/accountmodel.hpp" #include "util/layoutcreator.hpp" +#include "widgets/helper/editablemodelview.hpp" #include "widgets/logindialog.hpp" +#include + #include +#include +#include #include namespace chatterino { @@ -16,32 +22,42 @@ namespace settingspages { AccountsPage::AccountsPage() : SettingsPage("Accounts", ":/images/accounts.svg") { + auto *app = getApp(); + util::LayoutCreator layoutCreator(this); - auto layout = layoutCreator.emplace().withoutMargin(); - auto buttons = layout.emplace(); - { - this->addButton = buttons->addButton("Add", QDialogButtonBox::YesRole); - this->removeButton = buttons->addButton("Remove", QDialogButtonBox::NoRole); - } - layout.emplace(this).assign(&this->accSwitchWidget); + helper::EditableModelView *view = + *layout.emplace(app->accounts->createModel(nullptr)); + + view->setTitles({"Name"}); + view->getTableView()->horizontalHeader()->setStretchLastSection(true); + + view->addButtonPressed.connect([] {}); + + // auto buttons = layout.emplace(); + // { + // this->addButton = buttons->addButton("Add", QDialogButtonBox::YesRole); + // this->removeButton = buttons->addButton("Remove", QDialogButtonBox::NoRole); + // } + + // layout.emplace(this).assign(&this->accSwitchWidget); // ---- - QObject::connect(this->addButton, &QPushButton::clicked, []() { - static auto loginWidget = new LoginWidget(); - loginWidget->show(); - }); + // QObject::connect(this->addButton, &QPushButton::clicked, []() { + // static auto loginWidget = new LoginWidget(); + // loginWidget->show(); + // }); - QObject::connect(this->removeButton, &QPushButton::clicked, [this] { - auto selectedUser = this->accSwitchWidget->currentItem()->text(); - if (selectedUser == ANONYMOUS_USERNAME_LABEL) { - // Do nothing - return; - } + // QObject::connect(this->removeButton, &QPushButton::clicked, [this] { + // auto selectedUser = this->accSwitchWidget->currentItem()->text(); + // if (selectedUser == ANONYMOUS_USERNAME_LABEL) { + // // Do nothing + // return; + // } - getApp()->accounts->Twitch.removeUser(selectedUser); - }); + // getApp()->accounts->Twitch.removeUser(selectedUser); + // }); } } // namespace settingspages diff --git a/src/widgets/settingspages/ignoreuserspage.cpp b/src/widgets/settingspages/ignoreuserspage.cpp index f2bb46e42..6adf533e3 100644 --- a/src/widgets/settingspages/ignoreuserspage.cpp +++ b/src/widgets/settingspages/ignoreuserspage.cpp @@ -1,9 +1,9 @@ #include "ignoreuserspage.hpp" #include "application.hpp" +#include "controllers/accounts/accountcontroller.hpp" #include "controllers/ignores/ignorecontroller.hpp" #include "controllers/ignores/ignoremodel.hpp" -#include "singletons/accountmanager.hpp" #include "singletons/settingsmanager.hpp" #include "util/layoutcreator.hpp" #include "widgets/helper/editablemodelview.hpp" diff --git a/src/widgets/settingspages/moderationpage.cpp b/src/widgets/settingspages/moderationpage.cpp index 81faa01bd..5e46e4e38 100644 --- a/src/widgets/settingspages/moderationpage.cpp +++ b/src/widgets/settingspages/moderationpage.cpp @@ -1,14 +1,20 @@ #include "moderationpage.hpp" #include "application.hpp" +#include "controllers/taggedusers/taggeduserscontroller.hpp" +#include "controllers/taggedusers/taggedusersmodel.hpp" #include "singletons/pathmanager.hpp" #include "util/layoutcreator.hpp" +#include "widgets/helper/editablemodelview.hpp" +#include #include #include +#include #include #include #include +#include #include #include @@ -32,37 +38,41 @@ ModerationPage::ModerationPage() auto app = getApp(); util::LayoutCreator layoutCreator(this); - auto layout = layoutCreator.setLayoutType(); + auto tabs = layoutCreator.emplace(); + + auto logs = tabs.appendTab(new QVBoxLayout, "Logs"); { - // Logs (copied from LoggingMananger) auto logPath = app->paths->logsFolderPath; - auto created = layout.emplace(); + auto created = logs.emplace(); created->setText("Logs are saved to " + CreateLink(logPath, true)); created->setTextFormat(Qt::RichText); created->setTextInteractionFlags(Qt::TextBrowserInteraction | Qt::LinksAccessibleByKeyboard | Qt::LinksAccessibleByKeyboard); created->setOpenExternalLinks(true); - layout.append(this->createCheckBox("Enable logging", app->settings->enableLogging)); + logs.append(this->createCheckBox("Enable logging", app->settings->enableLogging)); - layout->addStretch(1); - // Logs end + logs->addStretch(1); + } + auto modMode = tabs.appendTab(new QVBoxLayout, "Moderation mode"); + { // clang-format off - auto label = layout.emplace("Click the moderation mod button () in a channel that you moderate to enable moderator mode.
"); + auto label = modMode.emplace("Click the moderation mod button () in a channel that you moderate to enable moderator mode.
"); label->setWordWrap(true); label->setStyleSheet("color: #bbb"); // clang-format on - auto form = layout.emplace(); - { - form->addRow("Action on timed out messages (unimplemented):", - this->createComboBox({"Disable", "Hide"}, app->settings->timeoutAction)); - } + // auto form = modMode.emplace(); + // { + // form->addRow("Action on timed out messages (unimplemented):", + // this->createComboBox({"Disable", "Hide"}, + // app->settings->timeoutAction)); + // } auto modButtons = - layout.emplace("Custom moderator buttons").setLayoutType(); + modMode.emplace("Custom moderator buttons").setLayoutType(); { auto label2 = modButtons.emplace("One action per line. {user} will be replaced with the " @@ -80,6 +90,20 @@ ModerationPage::ModerationPage() app->settings->moderationActions = text->toPlainText(); }); } + + /*auto taggedUsers = tabs.appendTab(new QVBoxLayout, "Tagged users"); + { + helper::EditableModelView *view = *taggedUsers.emplace( + app->taggedUsers->createModel(nullptr)); + + view->setTitles({"Name"}); + view->getTableView()->horizontalHeader()->setStretchLastSection(true); + + view->addButtonPressed.connect([] { + getApp()->taggedUsers->users.appendItem( + controllers::taggedusers::TaggedUser(ProviderId::Twitch, "example", "xD")); + }); + }*/ } // ---- misc diff --git a/src/widgets/window.cpp b/src/widgets/window.cpp index c5f84dc64..8d99fb88a 100644 --- a/src/widgets/window.cpp +++ b/src/widgets/window.cpp @@ -1,7 +1,7 @@ #include "widgets/window.hpp" #include "application.hpp" -#include "singletons/accountmanager.hpp" +#include "controllers/accounts/accountcontroller.hpp" #include "singletons/ircmanager.hpp" #include "singletons/settingsmanager.hpp" #include "singletons/thememanager.hpp"