From a82774543cb207f8198ccd9e6685170032b38de4 Mon Sep 17 00:00:00 2001 From: Rasmus Karlsson Date: Sat, 12 Aug 2017 15:58:46 +0200 Subject: [PATCH] Fix warnings/reformat some code --- chatterino.pro | 2 -- src/application.cpp | 18 +----------------- src/application.hpp | 2 -- src/channel.hpp | 8 ++++---- src/channelmanager.cpp | 5 +++-- src/emotemanager.cpp | 5 +---- src/emotemanager.hpp | 4 +--- src/messagefactory.cpp | 20 -------------------- src/messagefactory.hpp | 26 -------------------------- src/messages/message.cpp | 2 +- src/messages/messageref.hpp | 2 ++ src/twitch/twitchmessagebuilder.hpp | 1 - src/widgets/chatwidget.cpp | 12 ++++++------ src/widgets/chatwidget.hpp | 5 +++-- src/widgets/logindialog.cpp | 4 ++-- src/widgets/settingsdialog.cpp | 6 ++---- 16 files changed, 26 insertions(+), 96 deletions(-) delete mode 100644 src/messagefactory.cpp delete mode 100644 src/messagefactory.hpp diff --git a/chatterino.pro b/chatterino.pro index f99a7c2d6..24231d39c 100644 --- a/chatterino.pro +++ b/chatterino.pro @@ -92,7 +92,6 @@ SOURCES += \ src/twitch/twitchuser.cpp \ src/ircaccount.cpp \ src/widgets/accountpopup.cpp \ - src/messagefactory.cpp \ src/widgets/basewidget.cpp \ src/widgets/resizingtextedit.cpp \ src/completionmanager.cpp \ @@ -155,7 +154,6 @@ HEADERS += \ src/ircaccount.hpp \ src/widgets/accountpopup.hpp \ src/util/distancebetweenpoints.hpp \ - src/messagefactory.hpp \ src/widgets/basewidget.hpp \ src/completionmanager.hpp diff --git a/src/application.cpp b/src/application.cpp index 841a4b5ac..46f0c9577 100644 --- a/src/application.cpp +++ b/src/application.cpp @@ -13,11 +13,10 @@ Application::Application() : completionManager(this->emoteManager) , windowManager(this->channelManager, this->colorScheme, this->completionManager) , colorScheme(this->windowManager) - , emoteManager(this->windowManager, this->resources) + , emoteManager(this->windowManager) , resources(this->emoteManager, this->windowManager) , channelManager(this->windowManager, this->emoteManager, this->ircManager) , ircManager(this->channelManager, this->resources, this->emoteManager, this->windowManager) - , messageFactory(this->resources, this->emoteManager, this->windowManager) { // TODO(pajlada): Get rid of all singletons logging::init(); @@ -34,21 +33,6 @@ Application::Application() SettingsManager::getInstance().updateWordTypeMask(); this->windowManager.load(); - - this->ircManager.onPrivateMessage.connect([=](Communi::IrcPrivateMessage *message) { - QString channelName = message->target().mid(1); - - auto channel = this->channelManager.getChannel(channelName); - - if (channel == nullptr) { - // The message doesn't have a channel we listen to - return; - } - - messages::MessageParseArgs args; - - this->messageFactory.buildMessage(message, *channel.get(), args); - }); } Application::~Application() diff --git a/src/application.hpp b/src/application.hpp index 0c79f0107..2c294c2e5 100644 --- a/src/application.hpp +++ b/src/application.hpp @@ -5,7 +5,6 @@ #include "completionmanager.hpp" #include "emotemanager.hpp" #include "ircmanager.hpp" -#include "messagefactory.hpp" #include "resources.hpp" #include "windowmanager.hpp" @@ -28,7 +27,6 @@ public: Resources resources; ChannelManager channelManager; IrcManager ircManager; - MessageFactory messageFactory; }; } // namespace chatterino diff --git a/src/channel.hpp b/src/channel.hpp index 225b1bf0f..ec3e88766 100644 --- a/src/channel.hpp +++ b/src/channel.hpp @@ -24,6 +24,10 @@ class IrcManager; class Channel { + WindowManager &windowManager; + EmoteManager &emoteManager; + IrcManager &ircManager; + public: explicit Channel(WindowManager &_windowManager, EmoteManager &_emoteManager, IrcManager &_ircManager, const QString &channelName, bool isSpecial = false); @@ -51,10 +55,6 @@ public: const QString name; private: - WindowManager &windowManager; - EmoteManager &emoteManager; - IrcManager &ircManager; - // variables messages::LimitedQueue _messages; diff --git a/src/channelmanager.cpp b/src/channelmanager.cpp index 3a3dc5e67..8b16649ee 100644 --- a/src/channelmanager.cpp +++ b/src/channelmanager.cpp @@ -111,15 +111,16 @@ void ChannelManager::removeChannel(const QString &channel) const std::string &ChannelManager::getUserID(const std::string &username) { + /* TODO: Implement auto it = this->usernameToID.find(username); - /* if (it != std::end(this->usernameToID)) { return *it; } */ - return "xd"; + static std::string temporary = "xd"; + return temporary; } } // namespace chatterino diff --git a/src/emotemanager.cpp b/src/emotemanager.cpp index 12eebf6cb..2d57b9ecd 100644 --- a/src/emotemanager.cpp +++ b/src/emotemanager.cpp @@ -1,6 +1,5 @@ #include "emotemanager.hpp" #include "common.hpp" -#include "resources.hpp" #include "util/urlfetch.hpp" #include "windowmanager.hpp" @@ -21,12 +20,10 @@ using namespace chatterino::messages; namespace chatterino { -EmoteManager::EmoteManager(WindowManager &_windowManager, Resources &_resources) +EmoteManager::EmoteManager(WindowManager &_windowManager) : windowManager(_windowManager) - , resources(_resources) , findShortCodesRegex(":([-+\\w]+):") { - // Note: Do not use this->resources in ctor pajlada::Settings::Setting roomID( "/accounts/current/roomID", "", pajlada::Settings::SettingOption::DoNotWriteToJSON); diff --git a/src/emotemanager.hpp b/src/emotemanager.hpp index 0d276a449..ce135fe62 100644 --- a/src/emotemanager.hpp +++ b/src/emotemanager.hpp @@ -18,7 +18,6 @@ namespace chatterino { class WindowManager; -class Resources; struct EmoteData { EmoteData() @@ -38,7 +37,7 @@ class EmoteManager public: using EmoteMap = ConcurrentMap; - EmoteManager(WindowManager &_windowManager, Resources &_resources); + explicit EmoteManager(WindowManager &_windowManager); void loadGlobalEmotes(); @@ -73,7 +72,6 @@ public: private: WindowManager &windowManager; - Resources &resources; /// Emojis QRegularExpression findShortCodesRegex; diff --git a/src/messagefactory.cpp b/src/messagefactory.cpp deleted file mode 100644 index 30ec947f7..000000000 --- a/src/messagefactory.cpp +++ /dev/null @@ -1,20 +0,0 @@ -#include "messagefactory.hpp" - -namespace chatterino { - -MessageFactory::MessageFactory(Resources &_resources, EmoteManager &_emoteManager, - WindowManager &_windowManager) - : resources(_resources) - , emoteManager(_emoteManager) - , windowManager(_windowManager) -{ -} - -messages::SharedMessage MessageFactory::buildMessage(Communi::IrcPrivateMessage *message, - Channel &channel, - const messages::MessageParseArgs &args) -{ - return nullptr; -} - -} // namespace chatterino diff --git a/src/messagefactory.hpp b/src/messagefactory.hpp deleted file mode 100644 index a72e3320e..000000000 --- a/src/messagefactory.hpp +++ /dev/null @@ -1,26 +0,0 @@ -#pragma once - -#include "messages/message.hpp" - -namespace chatterino { - -class Resources; -class EmoteManager; -class WindowManager; - -class MessageFactory -{ -public: - explicit MessageFactory(Resources &_resources, EmoteManager &_emoteManager, - WindowManager &_windowManager); - - messages::SharedMessage buildMessage(Communi::IrcPrivateMessage *message, Channel &channel, - const messages::MessageParseArgs &args); - -private: - Resources &resources; - EmoteManager &emoteManager; - WindowManager &windowManager; -}; - -} // namespace chatterino diff --git a/src/messages/message.cpp b/src/messages/message.cpp index 6b3797c9a..3d680bad5 100644 --- a/src/messages/message.cpp +++ b/src/messages/message.cpp @@ -31,8 +31,8 @@ Message::Message(const QString &text) Message::Message(const QString &text, const std::vector &words, const bool &highlight) : text(text) - , words(words) , highlightTab(highlight) + , words(words) { } diff --git a/src/messages/messageref.hpp b/src/messages/messageref.hpp index dae426241..eba5c13e3 100644 --- a/src/messages/messageref.hpp +++ b/src/messages/messageref.hpp @@ -41,7 +41,9 @@ private: int _currentLayoutWidth = -1; int _fontGeneration = -1; + /* TODO(pajlada): Re-implement int _emoteGeneration = -1; + */ Word::Type _currentWordTypes = Word::None; // methods diff --git a/src/twitch/twitchmessagebuilder.hpp b/src/twitch/twitchmessagebuilder.hpp index 9b21f93e5..33cb3763b 100644 --- a/src/twitch/twitchmessagebuilder.hpp +++ b/src/twitch/twitchmessagebuilder.hpp @@ -53,7 +53,6 @@ private: std::string roomID; QColor usernameColor; - bool highlight; void parseMessageID(); void parseRoomID(); diff --git a/src/widgets/chatwidget.cpp b/src/widgets/chatwidget.cpp index 533656213..89923021a 100644 --- a/src/widgets/chatwidget.cpp +++ b/src/widgets/chatwidget.cpp @@ -6,13 +6,13 @@ #include "widgets/textinputdialog.hpp" #include +#include #include #include #include +#include #include #include -#include -#include #include #include @@ -40,12 +40,12 @@ ChatWidget::ChatWidget(ChannelManager &_channelManager, NotebookPage *parent) : BaseWidget(parent) , channelManager(_channelManager) , completionManager(parent->completionManager) + , channelName("/chatWidgets/" + std::to_string(index++) + "/channelName") , channel(_channelManager.emptyChannel) , vbox(this) , header(this) , view(this) , input(this) - , channelName("/chatWidgets/" + std::to_string(index++) + "/channelName") { this->vbox.setSpacing(0); this->vbox.setMargin(1); @@ -288,9 +288,9 @@ void ChatWidget::doOpenStreamlink() // TODO(Confuseh): Add quality switcher if (fileinfo.exists() && fileinfo.isExecutable()) { // works on leenux, idk whether it would work on whindows or mehOS - QProcess::startDetached(path, - QStringList({"twitch.tv/" + QString::fromStdString(this->channelName.getValue()), - "best"})); + QProcess::startDetached( + path, QStringList({"twitch.tv/" + QString::fromStdString(this->channelName.getValue()), + "best"})); } } diff --git a/src/widgets/chatwidget.hpp b/src/widgets/chatwidget.hpp index 99f20a188..e05288f1a 100644 --- a/src/widgets/chatwidget.hpp +++ b/src/widgets/chatwidget.hpp @@ -56,14 +56,15 @@ public: void giveFocus(Qt::FocusReason reason); bool hasFocus() const; - pajlada::Settings::Setting channelName; - protected: virtual void paintEvent(QPaintEvent *) override; public: ChannelManager &channelManager; CompletionManager &completionManager; + + pajlada::Settings::Setting channelName; + private: void setChannel(std::shared_ptr newChannel); void detachChannel(); diff --git a/src/widgets/logindialog.cpp b/src/widgets/logindialog.cpp index a8dbbcd30..ebc63b356 100644 --- a/src/widgets/logindialog.cpp +++ b/src/widgets/logindialog.cpp @@ -31,13 +31,13 @@ LoginWidget::LoginWidget() this->close(); // }); - connect(&this->ui.loginButton, &QPushButton::clicked, [this]() { + connect(&this->ui.loginButton, &QPushButton::clicked, []() { printf("open login in browser\n"); QDesktopServices::openUrl(QUrl("https://pajlada.se/chatterino/#chatterino")); }); - connect(&this->ui.pasteCodeButton, &QPushButton::clicked, [this]() { + connect(&this->ui.pasteCodeButton, &QPushButton::clicked, []() { QClipboard *clipboard = QGuiApplication::clipboard(); QString clipboardString = clipboard->text(); QStringList parameters = clipboardString.split(';'); diff --git a/src/widgets/settingsdialog.cpp b/src/widgets/settingsdialog.cpp index 0ba012e5e..df20d408a 100644 --- a/src/widgets/settingsdialog.cpp +++ b/src/widgets/settingsdialog.cpp @@ -168,7 +168,7 @@ void SettingsDialog::addTabs() auto fontManager = FontManager::getInstance(); QFontDialog dialog(fontManager.getFont(FontManager::Medium)); - dialog.connect(&dialog, &QFontDialog::fontSelected, [&dialog](const QFont &font) { + dialog.connect(&dialog, &QFontDialog::fontSelected, [](const QFont &font) { auto fontManager = FontManager::getInstance(); fontManager.currentFontFamily = font.family().toStdString(); fontManager.currentFontSize = font.pointSize(); @@ -590,9 +590,7 @@ QLineEdit *SettingsDialog::createLineEdit(pajlada::Settings::Setting