From fb230423f6813eccaea29bc912e695732efb2ce1 Mon Sep 17 00:00:00 2001 From: fourtf Date: Tue, 26 Jun 2018 17:47:44 +0200 Subject: [PATCH] fixed rename --- src/common/ConcurrentMap.hpp | 97 +++++++++++++++++++++++++++++++++ src/providers/twitch/Pubsub.cpp | 34 ++++++------ src/widgets/BaseWindow.cpp | 1 - 3 files changed, 114 insertions(+), 18 deletions(-) create mode 100644 src/common/ConcurrentMap.hpp diff --git a/src/common/ConcurrentMap.hpp b/src/common/ConcurrentMap.hpp new file mode 100644 index 000000000..2db2d9f58 --- /dev/null +++ b/src/common/ConcurrentMap.hpp @@ -0,0 +1,97 @@ +#pragma once + +#include +#include +#include + +#include +#include +#include + +namespace chatterino { + +template +class ConcurrentMap +{ +public: + ConcurrentMap() = default; + + bool tryGet(const TKey &name, TValue &value) const + { + QMutexLocker lock(&this->mutex); + + auto a = this->data.find(name); + if (a == this->data.end()) { + return false; + } + + value = a.value(); + + return true; + } + + TValue getOrAdd(const TKey &name, std::function addLambda) + { + QMutexLocker lock(&this->mutex); + + auto a = this->data.find(name); + if (a == this->data.end()) { + TValue value = addLambda(); + this->data.insert(name, value); + return value; + } + + return a.value(); + } + + TValue &operator[](const TKey &name) + { + QMutexLocker lock(&this->mutex); + + return this->data[name]; + } + + void clear() + { + QMutexLocker lock(&this->mutex); + + this->data.clear(); + } + + void insert(const TKey &name, const TValue &value) + { + QMutexLocker lock(&this->mutex); + + this->data.insert(name, value); + } + + void each(std::function func) const + { + QMutexLocker lock(&this->mutex); + + QMapIterator it(this->data); + + while (it.hasNext()) { + it.next(); + func(it.key(), it.value()); + } + } + + void each(std::function func) + { + QMutexLocker lock(&this->mutex); + + QMutableMapIterator it(this->data); + + while (it.hasNext()) { + it.next(); + func(it.key(), it.value()); + } + } + +private: + mutable QMutex mutex; + QMap data; +}; + +} // namespace chatterino diff --git a/src/providers/twitch/Pubsub.cpp b/src/providers/twitch/Pubsub.cpp index 5398e059d..1302fb78e 100644 --- a/src/providers/twitch/Pubsub.cpp +++ b/src/providers/twitch/Pubsub.cpp @@ -179,7 +179,7 @@ PubSub::PubSub() this->moderationActionHandlers["clear"] = [this](const auto &data, const auto &roomID) { ClearChatAction action(data, roomID); - this->sig.moderation.chatCleared.invoke(action); + this->signals_.moderation.chatCleared.invoke(action); }; this->moderationActionHandlers["slowoff"] = [this](const auto &data, const auto &roomID) { @@ -188,7 +188,7 @@ PubSub::PubSub() action.mode = ModeChangedAction::Mode::Slow; action.state = ModeChangedAction::State::Off; - this->sig.moderation.modeChanged.invoke(action); + this->signals_.moderation.modeChanged.invoke(action); }; this->moderationActionHandlers["slow"] = [this](const auto &data, const auto &roomID) { @@ -225,7 +225,7 @@ PubSub::PubSub() action.duration = QString(durationArg.GetString()).toUInt(&ok, 10); - this->sig.moderation.modeChanged.invoke(action); + this->signals_.moderation.modeChanged.invoke(action); }; this->moderationActionHandlers["r9kbetaoff"] = [this](const auto &data, const auto &roomID) { @@ -234,7 +234,7 @@ PubSub::PubSub() action.mode = ModeChangedAction::Mode::R9K; action.state = ModeChangedAction::State::Off; - this->sig.moderation.modeChanged.invoke(action); + this->signals_.moderation.modeChanged.invoke(action); }; this->moderationActionHandlers["r9kbeta"] = [this](const auto &data, const auto &roomID) { @@ -243,7 +243,7 @@ PubSub::PubSub() action.mode = ModeChangedAction::Mode::R9K; action.state = ModeChangedAction::State::On; - this->sig.moderation.modeChanged.invoke(action); + this->signals_.moderation.modeChanged.invoke(action); }; this->moderationActionHandlers["subscribersoff"] = [this](const auto &data, @@ -253,7 +253,7 @@ PubSub::PubSub() action.mode = ModeChangedAction::Mode::SubscribersOnly; action.state = ModeChangedAction::State::Off; - this->sig.moderation.modeChanged.invoke(action); + this->signals_.moderation.modeChanged.invoke(action); }; this->moderationActionHandlers["subscribers"] = [this](const auto &data, const auto &roomID) { @@ -262,7 +262,7 @@ PubSub::PubSub() action.mode = ModeChangedAction::Mode::SubscribersOnly; action.state = ModeChangedAction::State::On; - this->sig.moderation.modeChanged.invoke(action); + this->signals_.moderation.modeChanged.invoke(action); }; this->moderationActionHandlers["emoteonlyoff"] = [this](const auto &data, const auto &roomID) { @@ -271,7 +271,7 @@ PubSub::PubSub() action.mode = ModeChangedAction::Mode::EmoteOnly; action.state = ModeChangedAction::State::Off; - this->sig.moderation.modeChanged.invoke(action); + this->signals_.moderation.modeChanged.invoke(action); }; this->moderationActionHandlers["emoteonly"] = [this](const auto &data, const auto &roomID) { @@ -280,7 +280,7 @@ PubSub::PubSub() action.mode = ModeChangedAction::Mode::EmoteOnly; action.state = ModeChangedAction::State::On; - this->sig.moderation.modeChanged.invoke(action); + this->signals_.moderation.modeChanged.invoke(action); }; this->moderationActionHandlers["unmod"] = [this](const auto &data, const auto &roomID) { @@ -304,7 +304,7 @@ PubSub::PubSub() action.modded = false; - this->sig.moderation.moderationStateChanged.invoke(action); + this->signals_.moderation.moderationStateChanged.invoke(action); }; this->moderationActionHandlers["mod"] = [this](const auto &data, const auto &roomID) { @@ -328,7 +328,7 @@ PubSub::PubSub() action.modded = true; - this->sig.moderation.moderationStateChanged.invoke(action); + this->signals_.moderation.moderationStateChanged.invoke(action); }; this->moderationActionHandlers["timeout"] = [this](const auto &data, const auto &roomID) { @@ -361,7 +361,7 @@ PubSub::PubSub() } } - this->sig.moderation.userBanned.invoke(action); + this->signals_.moderation.userBanned.invoke(action); } catch (const std::runtime_error &ex) { Log("Error parsing moderation action: {}", ex.what()); } @@ -390,7 +390,7 @@ PubSub::PubSub() } } - this->sig.moderation.userBanned.invoke(action); + this->signals_.moderation.userBanned.invoke(action); } catch (const std::runtime_error &ex) { Log("Error parsing moderation action: {}", ex.what()); } @@ -415,7 +415,7 @@ PubSub::PubSub() return; } - this->sig.moderation.userUnbanned.invoke(action); + this->signals_.moderation.userUnbanned.invoke(action); } catch (const std::runtime_error &ex) { Log("Error parsing moderation action: {}", ex.what()); } @@ -440,7 +440,7 @@ PubSub::PubSub() return; } - this->sig.moderation.userUnbanned.invoke(action); + this->signals_.moderation.userUnbanned.invoke(action); } catch (const std::runtime_error &ex) { Log("Error parsing moderation action: {}", ex.what()); } @@ -725,9 +725,9 @@ void PubSub::handleMessageResponse(const rapidjson::Value &outerData) } if (whisperType == "whisper_received") { - this->sig.whisper.received.invoke(msg); + this->signals_.whisper.received.invoke(msg); } else if (whisperType == "whisper_sent") { - this->sig.whisper.sent.invoke(msg); + this->signals_.whisper.sent.invoke(msg); } else if (whisperType == "thread") { // Handle thread? } else { diff --git a/src/widgets/BaseWindow.cpp b/src/widgets/BaseWindow.cpp index 1d4f7a4da..252f724af 100644 --- a/src/widgets/BaseWindow.cpp +++ b/src/widgets/BaseWindow.cpp @@ -5,7 +5,6 @@ #include "debug/Log.hpp" #include "singletons/SettingsManager.hpp" #include "singletons/WindowManager.hpp" -#include "util/NativeEventHelper.hpp" #include "util/PostToThread.hpp" #include "util/WindowsHelper.hpp" #include "widgets/Label.hpp"