some more refactoring
This commit is contained in:
+21
-18
@@ -115,30 +115,33 @@ public:
|
|||||||
this->itemsChanged_();
|
this->itemsChanged_();
|
||||||
}
|
}
|
||||||
|
|
||||||
// compatability
|
const std::vector<T> &raw() const
|
||||||
[[deprecated]] int insertItem(const T &item, int proposedIndex = -1,
|
|
||||||
void *caller = nullptr)
|
|
||||||
{
|
|
||||||
return this->insert(item, proposedIndex, caller);
|
|
||||||
}
|
|
||||||
|
|
||||||
[[deprecated]] int appendItem(const T &item, void *caller = nullptr)
|
|
||||||
{
|
|
||||||
return this->append(item, caller);
|
|
||||||
}
|
|
||||||
|
|
||||||
[[deprecated]] void removeItem(int index, void *caller = nullptr)
|
|
||||||
{
|
|
||||||
this->removeAt(index, caller);
|
|
||||||
}
|
|
||||||
|
|
||||||
[[deprecated]] const std::vector<T> &getVector() const
|
|
||||||
{
|
{
|
||||||
assertInGuiThread();
|
assertInGuiThread();
|
||||||
|
|
||||||
return this->items_;
|
return this->items_;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// compatability
|
||||||
|
[[deprecated("use insert")]] int insertItem(const T &item,
|
||||||
|
int proposedIndex = -1,
|
||||||
|
void *caller = nullptr)
|
||||||
|
{
|
||||||
|
return this->insert(item, proposedIndex, caller);
|
||||||
|
}
|
||||||
|
|
||||||
|
[[deprecated("use append")]] int appendItem(const T &item,
|
||||||
|
void *caller = nullptr)
|
||||||
|
{
|
||||||
|
return this->append(item, caller);
|
||||||
|
}
|
||||||
|
|
||||||
|
[[deprecated("use removeAt")]] void removeItem(int index,
|
||||||
|
void *caller = nullptr)
|
||||||
|
{
|
||||||
|
this->removeAt(index, caller);
|
||||||
|
}
|
||||||
|
|
||||||
[[deprecated]] std::vector<T> cloneVector()
|
[[deprecated]] std::vector<T> cloneVector()
|
||||||
{
|
{
|
||||||
return *this->readOnly();
|
return *this->readOnly();
|
||||||
|
|||||||
@@ -52,7 +52,7 @@ public:
|
|||||||
};
|
};
|
||||||
|
|
||||||
int i = 0;
|
int i = 0;
|
||||||
for (const TVectorItem &item : vec->getVector())
|
for (const TVectorItem &item : vec->raw())
|
||||||
{
|
{
|
||||||
SignalVectorItemArgs<TVectorItem> args{item, i++, 0};
|
SignalVectorItemArgs<TVectorItem> args{item, i++, 0};
|
||||||
|
|
||||||
@@ -272,15 +272,15 @@ public:
|
|||||||
int from = data->data("chatterino_row_id").toInt();
|
int from = data->data("chatterino_row_id").toInt();
|
||||||
int to = parent.row();
|
int to = parent.row();
|
||||||
|
|
||||||
if (from < 0 || from > this->vector_->getVector().size() ||
|
if (from < 0 || from > this->vector_->raw().size() ||
|
||||||
to < 0 || to > this->vector_->getVector().size())
|
to < 0 || to > this->vector_->raw().size())
|
||||||
{
|
{
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (from != to)
|
if (from != to)
|
||||||
{
|
{
|
||||||
auto item = this->vector_->getVector()[from];
|
auto item = this->vector_->raw()[from];
|
||||||
this->vector_->removeItem(from);
|
this->vector_->removeItem(from);
|
||||||
this->vector_->insertItem(item, to);
|
this->vector_->insertItem(item, to);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -16,7 +16,7 @@ AccountController::AccountController()
|
|||||||
this->twitch.accounts.itemRemoved.connect([this](const auto &args) {
|
this->twitch.accounts.itemRemoved.connect([this](const auto &args) {
|
||||||
if (args.caller != this)
|
if (args.caller != this)
|
||||||
{
|
{
|
||||||
auto &accs = this->twitch.accounts.getVector();
|
auto &accs = this->twitch.accounts.raw();
|
||||||
auto it = std::find(accs.begin(), accs.end(), args.item);
|
auto it = std::find(accs.begin(), accs.end(), args.item);
|
||||||
assert(it != accs.end());
|
assert(it != accs.end());
|
||||||
|
|
||||||
|
|||||||
@@ -212,7 +212,7 @@ void CommandController::initialize(Settings &, Paths &paths)
|
|||||||
// Update the setting when the vector of commands has been updated (most
|
// Update the setting when the vector of commands has been updated (most
|
||||||
// likely from the settings dialog)
|
// likely from the settings dialog)
|
||||||
this->items_.delayedItemsChanged.connect([this] { //
|
this->items_.delayedItemsChanged.connect([this] { //
|
||||||
this->commandsSetting_->setValue(this->items_.getVector());
|
this->commandsSetting_->setValue(this->items_.raw());
|
||||||
});
|
});
|
||||||
|
|
||||||
// Load commands from commands.json
|
// Load commands from commands.json
|
||||||
|
|||||||
@@ -12,38 +12,30 @@ HighlightController::HighlightController()
|
|||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
template <typename T>
|
||||||
|
inline void persist(SignalVector<T> &vec, const std::string &name)
|
||||||
|
{
|
||||||
|
auto setting = std::make_unique<ChatterinoSetting<std::vector<T>>>(name);
|
||||||
|
|
||||||
|
for (auto &&item : setting->getValue())
|
||||||
|
vec.append(item);
|
||||||
|
|
||||||
|
vec.delayedItemsChanged.connect([setting = setting.get(), vec = &vec] {
|
||||||
|
setting->setValue(vec->raw());
|
||||||
|
});
|
||||||
|
|
||||||
|
// TODO
|
||||||
|
setting.release();
|
||||||
|
}
|
||||||
|
|
||||||
void HighlightController::initialize(Settings &settings, Paths &paths)
|
void HighlightController::initialize(Settings &settings, Paths &paths)
|
||||||
{
|
{
|
||||||
assert(!this->initialized_);
|
assert(!this->initialized_);
|
||||||
this->initialized_ = true;
|
this->initialized_ = true;
|
||||||
|
|
||||||
for (const HighlightPhrase &phrase : this->highlightsSetting_.getValue())
|
persist(this->phrases, "/highlighting/highlights");
|
||||||
{
|
persist(this->blacklistedUsers, "/highlighting/blacklist");
|
||||||
this->phrases.appendItem(phrase);
|
persist(this->highlightedUsers, "/highlighting/users");
|
||||||
}
|
|
||||||
|
|
||||||
this->phrases.delayedItemsChanged.connect([this] { //
|
|
||||||
this->highlightsSetting_.setValue(this->phrases.getVector());
|
|
||||||
});
|
|
||||||
|
|
||||||
for (const HighlightBlacklistUser &blacklistedUser :
|
|
||||||
this->blacklistSetting_.getValue())
|
|
||||||
{
|
|
||||||
this->blacklistedUsers.appendItem(blacklistedUser);
|
|
||||||
}
|
|
||||||
|
|
||||||
this->blacklistedUsers.delayedItemsChanged.connect([this] {
|
|
||||||
this->blacklistSetting_.setValue(this->blacklistedUsers.getVector());
|
|
||||||
});
|
|
||||||
|
|
||||||
for (const HighlightPhrase &user : this->userSetting_.getValue())
|
|
||||||
{
|
|
||||||
this->highlightedUsers.appendItem(user);
|
|
||||||
}
|
|
||||||
|
|
||||||
this->highlightedUsers.delayedItemsChanged.connect([this] { //
|
|
||||||
this->userSetting_.setValue(this->highlightedUsers.getVector());
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
HighlightModel *HighlightController::createModel(QObject *parent)
|
HighlightModel *HighlightController::createModel(QObject *parent)
|
||||||
|
|||||||
@@ -40,13 +40,6 @@ public:
|
|||||||
|
|
||||||
private:
|
private:
|
||||||
bool initialized_ = false;
|
bool initialized_ = false;
|
||||||
|
|
||||||
ChatterinoSetting<std::vector<HighlightPhrase>> highlightsSetting_ = {
|
|
||||||
"/highlighting/highlights"};
|
|
||||||
ChatterinoSetting<std::vector<HighlightBlacklistUser>> blacklistSetting_ = {
|
|
||||||
"/highlighting/blacklist"};
|
|
||||||
ChatterinoSetting<std::vector<HighlightPhrase>> userSetting_ = {
|
|
||||||
"/highlighting/users"};
|
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace chatterino
|
} // namespace chatterino
|
||||||
|
|||||||
@@ -18,7 +18,7 @@ void IgnoreController::initialize(Settings &, Paths &)
|
|||||||
}
|
}
|
||||||
|
|
||||||
this->phrases.delayedItemsChanged.connect([this] { //
|
this->phrases.delayedItemsChanged.connect([this] { //
|
||||||
this->ignoresSetting_.setValue(this->phrases.getVector());
|
this->ignoresSetting_.setValue(this->phrases.raw());
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -27,7 +27,7 @@ void ModerationActions::initialize(Settings &settings, Paths &paths)
|
|||||||
}
|
}
|
||||||
|
|
||||||
this->items.delayedItemsChanged.connect([this] { //
|
this->items.delayedItemsChanged.connect([this] { //
|
||||||
this->setting_->setValue(this->items.getVector());
|
this->setting_->setValue(this->items.raw());
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -31,7 +31,7 @@ void NotificationController::initialize(Settings &settings, Paths &paths)
|
|||||||
|
|
||||||
this->channelMap[Platform::Twitch].delayedItemsChanged.connect([this] { //
|
this->channelMap[Platform::Twitch].delayedItemsChanged.connect([this] { //
|
||||||
this->twitchSetting_.setValue(
|
this->twitchSetting_.setValue(
|
||||||
this->channelMap[Platform::Twitch].getVector());
|
this->channelMap[Platform::Twitch].raw());
|
||||||
});
|
});
|
||||||
/*
|
/*
|
||||||
for (const QString &channelName : this->mixerSetting_.getValue()) {
|
for (const QString &channelName : this->mixerSetting_.getValue()) {
|
||||||
@@ -88,9 +88,9 @@ void NotificationController::removeChannelNotification(
|
|||||||
const QString &channelName, Platform p)
|
const QString &channelName, Platform p)
|
||||||
{
|
{
|
||||||
for (std::vector<int>::size_type i = 0;
|
for (std::vector<int>::size_type i = 0;
|
||||||
i != channelMap[p].getVector().size(); i++)
|
i != channelMap[p].raw().size(); i++)
|
||||||
{
|
{
|
||||||
if (channelMap[p].getVector()[i].toLower() == channelName.toLower())
|
if (channelMap[p].raw()[i].toLower() == channelName.toLower())
|
||||||
{
|
{
|
||||||
channelMap[p].removeItem(i);
|
channelMap[p].removeItem(i);
|
||||||
i--;
|
i--;
|
||||||
@@ -128,14 +128,14 @@ NotificationModel *NotificationController::createModel(QObject *parent,
|
|||||||
void NotificationController::fetchFakeChannels()
|
void NotificationController::fetchFakeChannels()
|
||||||
{
|
{
|
||||||
for (std::vector<int>::size_type i = 0;
|
for (std::vector<int>::size_type i = 0;
|
||||||
i != channelMap[Platform::Twitch].getVector().size(); i++)
|
i != channelMap[Platform::Twitch].raw().size(); i++)
|
||||||
{
|
{
|
||||||
auto chan = getApp()->twitch.server->getChannelOrEmpty(
|
auto chan = getApp()->twitch.server->getChannelOrEmpty(
|
||||||
channelMap[Platform::Twitch].getVector()[i]);
|
channelMap[Platform::Twitch].raw()[i]);
|
||||||
if (chan->isEmpty())
|
if (chan->isEmpty())
|
||||||
{
|
{
|
||||||
getFakeTwitchChannelLiveStatus(
|
getFakeTwitchChannelLiveStatus(
|
||||||
channelMap[Platform::Twitch].getVector()[i]);
|
channelMap[Platform::Twitch].raw()[i]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -12,7 +12,7 @@ void PingController::initialize(Settings &settings, Paths &paths)
|
|||||||
}
|
}
|
||||||
|
|
||||||
this->channelVector.delayedItemsChanged.connect([this] { //
|
this->channelVector.delayedItemsChanged.connect([this] { //
|
||||||
this->pingSetting_.setValue(this->channelVector.getVector());
|
this->pingSetting_.setValue(this->channelVector.raw());
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -43,9 +43,9 @@ void PingController::muteChannel(const QString &channelName)
|
|||||||
void PingController::unmuteChannel(const QString &channelName)
|
void PingController::unmuteChannel(const QString &channelName)
|
||||||
{
|
{
|
||||||
for (std::vector<int>::size_type i = 0;
|
for (std::vector<int>::size_type i = 0;
|
||||||
i != channelVector.getVector().size(); i++)
|
i != channelVector.raw().size(); i++)
|
||||||
{
|
{
|
||||||
if (channelVector.getVector()[i].toLower() == channelName.toLower())
|
if (channelVector.raw()[i].toLower() == channelName.toLower())
|
||||||
{
|
{
|
||||||
channelVector.removeItem(i);
|
channelVector.removeItem(i);
|
||||||
i--;
|
i--;
|
||||||
|
|||||||
@@ -160,13 +160,12 @@ SelectChannelDialog::SelectChannelDialog(QWidget *parent)
|
|||||||
view->getTableView(), &QTableView::doubleClicked,
|
view->getTableView(), &QTableView::doubleClicked,
|
||||||
[](const QModelIndex &index) {
|
[](const QModelIndex &index) {
|
||||||
auto editor = new IrcConnectionEditor(
|
auto editor = new IrcConnectionEditor(
|
||||||
Irc::instance()
|
Irc::instance().connections.raw()[size_t(index.row())]);
|
||||||
.connections.getVector()[size_t(index.row())]);
|
|
||||||
|
|
||||||
if (editor->exec() == QDialog::Accepted)
|
if (editor->exec() == QDialog::Accepted)
|
||||||
{
|
{
|
||||||
auto data = editor->data();
|
auto data = editor->data();
|
||||||
auto &&conns = Irc::instance().connections.getVector();
|
auto &&conns = Irc::instance().connections.raw();
|
||||||
int i = 0;
|
int i = 0;
|
||||||
for (auto &&conn : conns)
|
for (auto &&conn : conns)
|
||||||
{
|
{
|
||||||
@@ -348,7 +347,7 @@ IndirectChannel SelectChannelDialog::getSelectedChannel() const
|
|||||||
->currentIndex()
|
->currentIndex()
|
||||||
.row();
|
.row();
|
||||||
|
|
||||||
auto &&vector = Irc::instance().connections.getVector();
|
auto &&vector = Irc::instance().connections.raw();
|
||||||
|
|
||||||
if (row >= 0 && row < int(vector.size()))
|
if (row >= 0 && row < int(vector.size()))
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -343,7 +343,7 @@ void UserInfoPopup::installEvents()
|
|||||||
else
|
else
|
||||||
{
|
{
|
||||||
const auto &vector =
|
const auto &vector =
|
||||||
getApp()->highlights->blacklistedUsers.getVector();
|
getApp()->highlights->blacklistedUsers.raw();
|
||||||
|
|
||||||
for (int i = 0; i < vector.size(); i++)
|
for (int i = 0; i < vector.size(); i++)
|
||||||
{
|
{
|
||||||
@@ -456,7 +456,7 @@ void UserInfoPopup::updateUserData()
|
|||||||
|
|
||||||
// get ignoreHighlights state
|
// get ignoreHighlights state
|
||||||
bool isIgnoringHighlights = false;
|
bool isIgnoringHighlights = false;
|
||||||
const auto &vector = getApp()->highlights->blacklistedUsers.getVector();
|
const auto &vector = getApp()->highlights->blacklistedUsers.raw();
|
||||||
for (int i = 0; i < vector.size(); i++)
|
for (int i = 0; i < vector.size(); i++)
|
||||||
{
|
{
|
||||||
if (this->userName_ == vector[i].getPattern())
|
if (this->userName_ == vector[i].getPattern())
|
||||||
|
|||||||
Reference in New Issue
Block a user