diff --git a/src/common/Channel.cpp b/src/common/Channel.cpp index 9ee3370f8..2a86d38fa 100644 --- a/src/common/Channel.cpp +++ b/src/common/Channel.cpp @@ -20,31 +20,27 @@ namespace chatterino { Channel::Channel(const QString &_name, Type _type) : name(_name) , completionModel(this->name) - , type(_type) + , type_(_type) { - this->clearCompletionModelTimer = new QTimer; - QObject::connect(this->clearCompletionModelTimer, &QTimer::timeout, [this]() { + QObject::connect(&this->clearCompletionModelTimer, &QTimer::timeout, [this]() { this->completionModel.ClearExpiredStrings(); // }); - this->clearCompletionModelTimer->start(60 * 1000); + this->clearCompletionModelTimer.start(60 * 1000); } Channel::~Channel() { this->destroyed.invoke(); - - this->clearCompletionModelTimer->stop(); - this->clearCompletionModelTimer->deleteLater(); } Channel::Type Channel::getType() const { - return this->type; + return this->type_; } bool Channel::isTwitchChannel() const { - return this->type >= Twitch && this->type < TwitchEnd; + return this->type_ >= Type::Twitch && this->type_ < Type::TwitchEnd; } bool Channel::isEmpty() const @@ -54,7 +50,7 @@ bool Channel::isEmpty() const LimitedQueueSnapshot Channel::getMessageSnapshot() { - return this->messages.getSnapshot(); + return this->messages_.getSnapshot(); } void Channel::addMessage(MessagePtr message) @@ -73,7 +69,7 @@ void Channel::addMessage(MessagePtr message) app->logging->addMessage(this->name, message); } - if (this->messages.pushBack(message, deleted)) { + if (this->messages_.pushBack(message, deleted)) { this->messageRemovedFromStart.invoke(deleted); } @@ -163,7 +159,7 @@ void Channel::disableAllMessages() void Channel::addMessagesAtStart(std::vector &_messages) { - std::vector addedMessages = this->messages.pushFront(_messages); + std::vector addedMessages = this->messages_.pushFront(_messages); if (addedMessages.size() != 0) { this->messagesAddedAtStart.invoke(addedMessages); @@ -172,7 +168,7 @@ void Channel::addMessagesAtStart(std::vector &_messages) void Channel::replaceMessage(MessagePtr message, MessagePtr replacement) { - int index = this->messages.replaceItem(message, replacement); + int index = this->messages_.replaceItem(message, replacement); if (index >= 0) { this->messageReplaced.invoke((size_t)index, replacement); @@ -211,7 +207,7 @@ bool Channel::hasModRights() const std::shared_ptr Channel::getEmpty() { - static std::shared_ptr channel(new Channel("", None)); + static std::shared_ptr channel(new Channel("", Type::None)); return channel; } diff --git a/src/common/Channel.hpp b/src/common/Channel.hpp index a56349345..ef8a53abd 100644 --- a/src/common/Channel.hpp +++ b/src/common/Channel.hpp @@ -17,10 +17,8 @@ struct Message; class Channel : public std::enable_shared_from_this { - QTimer *clearCompletionModelTimer; - public: - enum Type { + enum class Type { None, Direct, Twitch, @@ -31,7 +29,7 @@ public: Misc }; - explicit Channel(const QString &_name, Type type); + explicit Channel(const QString &_name, Type type_); virtual ~Channel(); pajlada::Signals::Signal sendMessageSignal; @@ -48,7 +46,7 @@ public: LimitedQueueSnapshot getMessageSnapshot(); void addMessage(MessagePtr message); - void addMessagesAtStart(std::vector &messages); + void addMessagesAtStart(std::vector &messages_); void addOrReplaceTimeout(MessagePtr message); void disableAllMessages(); void replaceMessage(MessagePtr message, MessagePtr replacement); @@ -71,8 +69,9 @@ protected: virtual void onConnected(); private: - LimitedQueue messages; - Type type; + LimitedQueue messages_; + Type type_; + QTimer clearCompletionModelTimer_; }; using ChannelPtr = std::shared_ptr; @@ -92,40 +91,41 @@ class IndirectChannel } }; - std::shared_ptr data; - public: - IndirectChannel(ChannelPtr channel, Channel::Type type = Channel::Direct) - : data(new Data(channel, type)) + IndirectChannel(ChannelPtr channel, Channel::Type type = Channel::Type::Direct) + : data_(new Data(channel, type)) { } ChannelPtr get() { - return data->channel; + return data_->channel; } void update(ChannelPtr ptr) { - assert(this->data->type != Channel::Direct); + assert(this->data_->type != Channel::Type::Direct); - this->data->channel = ptr; - this->data->changed.invoke(); + this->data_->channel = ptr; + this->data_->changed.invoke(); } pajlada::Signals::NoArgSignal &getChannelChanged() { - return this->data->changed; + return this->data_->changed; } Channel::Type getType() { - if (this->data->type == Channel::Direct) { + if (this->data_->type == Channel::Type::Direct) { return this->get()->getType(); } else { - return this->data->type; + return this->data_->type; } } + +private: + std::shared_ptr data_; }; } // namespace chatterino diff --git a/src/providers/twitch/TwitchChannel.cpp b/src/providers/twitch/TwitchChannel.cpp index 11ad3f645..cbde1f526 100644 --- a/src/providers/twitch/TwitchChannel.cpp +++ b/src/providers/twitch/TwitchChannel.cpp @@ -17,7 +17,7 @@ namespace chatterino { TwitchChannel::TwitchChannel(const QString &channelName, Communi::IrcConnection *_readConnection) - : Channel(channelName, Channel::Twitch) + : Channel(channelName, Channel::Type::Twitch) , bttvChannelEmotes(new EmoteMap) , ffzChannelEmotes(new EmoteMap) , subscriptionURL("https://www.twitch.tv/subs/" + name) diff --git a/src/providers/twitch/TwitchServer.cpp b/src/providers/twitch/TwitchServer.cpp index 986981648..159f5414e 100644 --- a/src/providers/twitch/TwitchServer.cpp +++ b/src/providers/twitch/TwitchServer.cpp @@ -19,9 +19,9 @@ using namespace std::chrono_literals; namespace chatterino { TwitchServer::TwitchServer() - : whispersChannel(new Channel("/whispers", Channel::TwitchWhispers)) - , mentionsChannel(new Channel("/mentions", Channel::TwitchMentions)) - , watchingChannel(Channel::getEmpty(), Channel::TwitchWatching) + : whispersChannel(new Channel("/whispers", Channel::Type::TwitchWhispers)) + , mentionsChannel(new Channel("/mentions", Channel::Type::TwitchMentions)) + , watchingChannel(Channel::getEmpty(), Channel::Type::TwitchWatching) { qDebug() << "init TwitchServer"; } diff --git a/src/singletons/WindowManager.cpp b/src/singletons/WindowManager.cpp index c4ea544ee..bfd30dc08 100644 --- a/src/singletons/WindowManager.cpp +++ b/src/singletons/WindowManager.cpp @@ -417,17 +417,17 @@ void WindowManager::encodeChannel(IndirectChannel channel, QJsonObject &obj) assertInGuiThread(); switch (channel.getType()) { - case Channel::Twitch: { + case Channel::Type::Twitch: { obj.insert("type", "twitch"); obj.insert("name", channel.get()->name); } break; - case Channel::TwitchMentions: { + case Channel::Type::TwitchMentions: { obj.insert("type", "mentions"); } break; - case Channel::TwitchWatching: { + case Channel::Type::TwitchWatching: { obj.insert("type", "watching"); } break; - case Channel::TwitchWhispers: { + case Channel::Type::TwitchWhispers: { obj.insert("type", "whispers"); } break; } diff --git a/src/widgets/AttachedWindow.cpp b/src/widgets/AttachedWindow.cpp index 65e0a681c..6fdf93680 100644 --- a/src/widgets/AttachedWindow.cpp +++ b/src/widgets/AttachedWindow.cpp @@ -84,7 +84,7 @@ AttachedWindow *AttachedWindow::get(void *target, const GetArgs &args) } if (show) { - window->updateWindowRect_(window->target_); + window->updateWindowRect(window->target_); window->show(); } @@ -107,10 +107,10 @@ void AttachedWindow::setChannel(ChannelPtr channel) void AttachedWindow::showEvent(QShowEvent *) { - this->attachToHwnd_(this->target_); + this->attachToHwnd(this->target_); } -void AttachedWindow::attachToHwnd_(void *_attachedPtr) +void AttachedWindow::attachToHwnd(void *_attachedPtr) { #ifdef USEWINSDK if (this->attached_) { @@ -145,13 +145,13 @@ void AttachedWindow::attachToHwnd_(void *_attachedPtr) this->validProcessName_ = true; } - this->updateWindowRect_(attached); + this->updateWindowRect(attached); }); this->timer_.start(); #endif } -void AttachedWindow::updateWindowRect_(void *_attachedPtr) +void AttachedWindow::updateWindowRect(void *_attachedPtr) { #ifdef USEWINSDK auto hwnd = HWND(this->winId()); diff --git a/src/widgets/AttachedWindow.hpp b/src/widgets/AttachedWindow.hpp index d35303a61..58f82c3b7 100644 --- a/src/widgets/AttachedWindow.hpp +++ b/src/widgets/AttachedWindow.hpp @@ -47,8 +47,8 @@ private: Split *split; } ui_; - void attachToHwnd_(void *attached); - void updateWindowRect_(void *attached); + void attachToHwnd(void *attached); + void updateWindowRect(void *attached); struct Item { void *hwnd; diff --git a/src/widgets/dialogs/EmotePopup.cpp b/src/widgets/dialogs/EmotePopup.cpp index 8c79b3c29..3f6d464bd 100644 --- a/src/widgets/dialogs/EmotePopup.cpp +++ b/src/widgets/dialogs/EmotePopup.cpp @@ -54,7 +54,7 @@ void EmotePopup::loadChannel(ChannelPtr _channel) return; } - ChannelPtr emoteChannel(new Channel("", Channel::None)); + ChannelPtr emoteChannel(new Channel("", Channel::Type::None)); auto addEmotes = [&](EmoteMap &map, const QString &title, const QString &emoteDesc) { // TITLE @@ -134,7 +134,7 @@ void EmotePopup::loadEmojis() { auto &emojis = getApp()->emotes->emojis.emojis; - ChannelPtr emojiChannel(new Channel("", Channel::None)); + ChannelPtr emojiChannel(new Channel("", Channel::Type::None)); // title MessageBuilder builder1; diff --git a/src/widgets/dialogs/LogsPopup.cpp b/src/widgets/dialogs/LogsPopup.cpp index f9f65f09b..4c8b01349 100644 --- a/src/widgets/dialogs/LogsPopup.cpp +++ b/src/widgets/dialogs/LogsPopup.cpp @@ -39,7 +39,7 @@ void LogsPopup::setInfo(ChannelPtr channel, QString userName) void LogsPopup::setMessages(std::vector &messages) { - ChannelPtr logsChannel(new Channel("logs", Channel::Misc)); + ChannelPtr logsChannel(new Channel("logs", Channel::Type::Misc)); logsChannel->addMessagesAtStart(messages); this->channelView_->setChannel(logsChannel); @@ -68,7 +68,7 @@ void LogsPopup::getLogviewerLogs() req.getJSON([this, channelName](QJsonObject &data) { std::vector messages; - ChannelPtr logsChannel(new Channel("logs", Channel::None)); + ChannelPtr logsChannel(new Channel("logs", Channel::Type::None)); QJsonValue before = data.value("before"); diff --git a/src/widgets/dialogs/NotificationPopup.cpp b/src/widgets/dialogs/NotificationPopup.cpp index 2970a4fd0..ad67dcb8c 100644 --- a/src/widgets/dialogs/NotificationPopup.cpp +++ b/src/widgets/dialogs/NotificationPopup.cpp @@ -10,7 +10,7 @@ namespace chatterino { NotificationPopup::NotificationPopup() : BaseWindow((QWidget *)nullptr, BaseWindow::Frameless) - , channel(std::make_shared("notifications", Channel::None)) + , channel(std::make_shared("notifications", Channel::Type::None)) { this->channelView = new ChannelView(this); diff --git a/src/widgets/dialogs/SelectChannelDialog.cpp b/src/widgets/dialogs/SelectChannelDialog.cpp index 9007eaf9d..87d85b577 100644 --- a/src/widgets/dialogs/SelectChannelDialog.cpp +++ b/src/widgets/dialogs/SelectChannelDialog.cpp @@ -151,20 +151,20 @@ void SelectChannelDialog::setSelectedChannel(IndirectChannel _channel) this->selectedChannel = channel; switch (_channel.getType()) { - case Channel::Twitch: { + case Channel::Type::Twitch: { this->ui_.notebook->selectIndex(TAB_TWITCH); this->ui_.twitch.channel->setFocus(); this->ui_.twitch.channelName->setText(channel->name); } break; - case Channel::TwitchWatching: { + case Channel::Type::TwitchWatching: { this->ui_.notebook->selectIndex(TAB_TWITCH); this->ui_.twitch.watching->setFocus(); } break; - case Channel::TwitchMentions: { + case Channel::Type::TwitchMentions: { this->ui_.notebook->selectIndex(TAB_TWITCH); this->ui_.twitch.mentions->setFocus(); } break; - case Channel::TwitchWhispers: { + case Channel::Type::TwitchWhispers: { this->ui_.notebook->selectIndex(TAB_TWITCH); this->ui_.twitch.whispers->setFocus(); } break; diff --git a/src/widgets/helper/SearchPopup.cpp b/src/widgets/helper/SearchPopup.cpp index 9ddd333ec..facf2796d 100644 --- a/src/widgets/helper/SearchPopup.cpp +++ b/src/widgets/helper/SearchPopup.cpp @@ -71,7 +71,7 @@ void SearchPopup::performSearch() { QString text = searchInput->text(); - ChannelPtr channel(new Channel("search", Channel::None)); + ChannelPtr channel(new Channel("search", Channel::Type::None)); for (size_t i = 0; i < this->snapshot.getLength(); i++) { MessagePtr message = this->snapshot[i]; diff --git a/src/widgets/settingspages/LookPage.cpp b/src/widgets/settingspages/LookPage.cpp index 54619f22b..bcdeb0ad7 100644 --- a/src/widgets/settingspages/LookPage.cpp +++ b/src/widgets/settingspages/LookPage.cpp @@ -272,7 +272,7 @@ void LookPage::addLastReadMessageIndicatorPatternSelector(LayoutCreatorname; - if (indirectChannel.getType() == Channel::TwitchWatching) { + if (indirectChannel.getType() == Channel::Type::TwitchWatching) { title = "watching: " + (title.isEmpty() ? "none" : title); }