diff --git a/src/const.hpp b/src/const.hpp index 925e0b5a0..bfb155477 100644 --- a/src/const.hpp +++ b/src/const.hpp @@ -4,13 +4,14 @@ namespace chatterino { -static const QString ANONYMOUS_USERNAME_LABEL(" - anonymous - "); +static const char *ANONYMOUS_USERNAME_LABEL = " - anonymous - "; namespace providers { namespace twitch { -static const QString ANONYMOUS_USERNAME("justinfan64537"); -} +static const char *ANONYMOUS_USERNAME = "justinfan64537"; + +} // namespace twitch } // namespace providers } // namespace chatterino diff --git a/src/emojis.hpp b/src/emojis.hpp index e74fc4438..b845003dc 100644 --- a/src/emojis.hpp +++ b/src/emojis.hpp @@ -1,16 +1,11 @@ #pragma once -#include "messages/image.hpp" -#include "util/concurrentmap.hpp" - -#include #include -#include - namespace chatterino { struct EmojiData { + // actual byte-representation of the emoji (i.e. \154075\156150 which is :male:) QString value; // what's used in the emoji-one url diff --git a/src/providers/twitch/twitchaccount.cpp b/src/providers/twitch/twitchaccount.cpp index 5e11adbb3..fc7ea45c1 100644 --- a/src/providers/twitch/twitchaccount.cpp +++ b/src/providers/twitch/twitchaccount.cpp @@ -1,15 +1,15 @@ #include "providers/twitch/twitchaccount.hpp" #include "const.hpp" -#include "util/urlfetch.hpp" namespace chatterino { namespace providers { namespace twitch { + TwitchAccount::TwitchAccount(const QString &_username, const QString &_oauthToken, const QString &_oauthClient) - : userName(_username) - , oauthClient(_oauthClient) + : oauthClient(_oauthClient) , oauthToken(_oauthToken) + , userName(_username) , _isAnon(_username == ANONYMOUS_USERNAME) { } @@ -65,6 +65,7 @@ bool TwitchAccount::isAnon() const { return this->_isAnon; } + } // namespace twitch } // namespace providers } // namespace chatterino diff --git a/src/providers/twitch/twitchaccount.hpp b/src/providers/twitch/twitchaccount.hpp index f33d713ae..6e3fdb8ad 100644 --- a/src/providers/twitch/twitchaccount.hpp +++ b/src/providers/twitch/twitchaccount.hpp @@ -6,6 +6,7 @@ namespace chatterino { namespace providers { namespace twitch { + class TwitchAccount { public: @@ -37,6 +38,7 @@ private: QString userName; const bool _isAnon; }; + } // namespace twitch } // namespace providers } // namespace chatterino diff --git a/src/providers/twitch/twitchchannel.cpp b/src/providers/twitch/twitchchannel.cpp index 45b22e69f..82537aed1 100644 --- a/src/providers/twitch/twitchchannel.cpp +++ b/src/providers/twitch/twitchchannel.cpp @@ -25,7 +25,7 @@ TwitchChannel::TwitchChannel(const QString &channelName, Communi::IrcConnection , channelURL("https://twitch.tv/" + name) , popoutPlayerURL("https://player.twitch.tv/?channel=" + name) , mod(false) - , readConnecetion(_readConnection) + , readConnection(_readConnection) { debug::Log("[TwitchChannel:{}] Opened", this->name); @@ -285,7 +285,7 @@ void TwitchChannel::fetchRecentMessages() auto channel = dynamic_cast(shared.get()); assert(channel != nullptr); - static auto readConnection = channel->readConnecetion; + static auto readConnection = channel->readConnection; QJsonArray msgArray = obj.value("messages").toArray(); if (msgArray.empty()) { diff --git a/src/providers/twitch/twitchchannel.hpp b/src/providers/twitch/twitchchannel.hpp index 3389dea1f..949c5a552 100644 --- a/src/providers/twitch/twitchchannel.hpp +++ b/src/providers/twitch/twitchchannel.hpp @@ -95,7 +95,7 @@ private: QByteArray messageSuffix; QString lastSentMessage; - Communi::IrcConnection *readConnecetion; + Communi::IrcConnection *readConnection; friend class TwitchServer; diff --git a/src/singletons/emotemanager.cpp b/src/singletons/emotemanager.cpp index 945761883..482697703 100644 --- a/src/singletons/emotemanager.cpp +++ b/src/singletons/emotemanager.cpp @@ -26,7 +26,7 @@ namespace singletons { namespace { -static QString GetTwitchEmoteLink(long id, const QString &emoteScale) +QString GetTwitchEmoteLink(long id, const QString &emoteScale) { QString value = TWITCH_EMOTE_TEMPLATE; @@ -35,14 +35,14 @@ static QString GetTwitchEmoteLink(long id, const QString &emoteScale) return value.replace("{id}", QString::number(id)).replace("{scale}", emoteScale); } -static QString GetBTTVEmoteLink(QString urlTemplate, const QString &id, const QString &emoteScale) +QString GetBTTVEmoteLink(QString urlTemplate, const QString &id, const QString &emoteScale) { urlTemplate.detach(); return urlTemplate.replace("{{id}}", id).replace("{{image}}", emoteScale); } -static QString GetFFZEmoteLink(const QJsonObject &urls, const QString &emoteScale) +QString GetFFZEmoteLink(const QJsonObject &urls, const QString &emoteScale) { auto emote = urls.value(emoteScale); if (emote.isUndefined()) { @@ -54,8 +54,7 @@ static QString GetFFZEmoteLink(const QJsonObject &urls, const QString &emoteScal return "http:" + emote.toString(); } -static void FillInFFZEmoteData(const QJsonObject &urls, const QString &code, - util::EmoteData &emoteData) +void FillInFFZEmoteData(const QJsonObject &urls, const QString &code, util::EmoteData &emoteData) { QString url1x = GetFFZEmoteLink(urls, "1"); QString url2x = GetFFZEmoteLink(urls, "2"); @@ -366,9 +365,8 @@ void EmoteManager::parseEmojis(std::vector> if (charactersFromLastParsedEmoji > 0) { // Add characters inbetween emojis - parsedWords.push_back(std::tuple( - util::EmoteData(), - text.mid(lastParsedEmojiEndIndex, charactersFromLastParsedEmoji))); + parsedWords.emplace_back(util::EmoteData(), text.mid(lastParsedEmojiEndIndex, + charactersFromLastParsedEmoji)); } QString url = "https://cdnjs.cloudflare.com/ajax/libs/" @@ -376,7 +374,7 @@ void EmoteManager::parseEmojis(std::vector> matchedEmoji.code + ".png"; // Create or fetch cached emoji image - auto emojiImage = this->emojis.getOrAdd(matchedEmoji.code, [this, &url] { + auto emojiImage = this->emojis.getOrAdd(matchedEmoji.code, [&url] { return util::EmoteData(new Image(url, 0.35, "?????????", "???????????????")); // }); @@ -390,8 +388,7 @@ void EmoteManager::parseEmojis(std::vector> if (lastParsedEmojiEndIndex < text.length()) { // Add remaining characters - parsedWords.push_back(std::tuple( - util::EmoteData(), text.mid(lastParsedEmojiEndIndex))); + parsedWords.emplace_back(util::EmoteData(), text.mid(lastParsedEmojiEndIndex)); } } @@ -546,7 +543,7 @@ util::EmoteData EmoteManager::getTwitchEmoteById(long id, const QString &emoteNa QString _emoteName = emoteName; _emoteName.replace("<", "<"); - return _twitchEmoteFromCache.getOrAdd(id, [this, &emoteName, &_emoteName, &id] { + return _twitchEmoteFromCache.getOrAdd(id, [&emoteName, &_emoteName, &id] { util::EmoteData newEmoteData; newEmoteData.image1x = new Image(GetTwitchEmoteLink(id, "1.0"), 1, emoteName, _emoteName + "
Twitch Emote 1x"); @@ -593,3 +590,61 @@ boost::signals2::signal &EmoteManager::getGifUpdateSignal() } // namespace singletons } // namespace chatterino + +#if 0 +namespace chatterino { + +void EmojiTest() +{ + auto &emoteManager = singletons::EmoteManager::getInstance(); + + emoteManager.loadEmojis(); + + { + std::vector> dummy; + + // couple_mm 1f468-2764-1f468 + // "\154075\156150❤\154075\156150" + // [0] 55357 0xd83d QChar + // [1] 56424 0xdc68 QChar + // [2] '❤' 10084 0x2764 QChar + // [3] 55357 0xd83d QChar + // [4] 56424 0xdc68 QChar + QString text = "👨❤👨"; + + emoteManager.parseEmojis(dummy, text); + + assert(dummy.size() == 1); + } + + { + std::vector> dummy; + + // "✍\154074\157777" + // [0] '✍' 9997 0x270d QChar + // [1] 55356 0xd83c QChar + // [2] 57343 0xdfff QChar + QString text = "✍🏿"; + + emoteManager.parseEmojis(dummy, text); + + assert(dummy.size() == 1); + + assert(std::get<0>(dummy[0]).isValid()); + } + + { + std::vector> dummy; + + QString text = "✍"; + + emoteManager.parseEmojis(dummy, text); + + assert(dummy.size() == 1); + + assert(std::get<0>(dummy[0]).isValid()); + } +} + +} // namespace chatterino +#endif diff --git a/src/util/concurrentmap.hpp b/src/util/concurrentmap.hpp index 183d726d2..41b0ece33 100644 --- a/src/util/concurrentmap.hpp +++ b/src/util/concurrentmap.hpp @@ -15,9 +15,7 @@ template class ConcurrentMap { public: - ConcurrentMap() - { - } + ConcurrentMap() = default; bool tryGet(const TKey &name, TValue &value) const { @@ -84,5 +82,6 @@ private: mutable QMutex mutex; QMap data; }; + +} // namespace util } // namespace chatterino -} diff --git a/src/util/distancebetweenpoints.hpp b/src/util/distancebetweenpoints.hpp index 2c7fd49fc..098aab1a6 100644 --- a/src/util/distancebetweenpoints.hpp +++ b/src/util/distancebetweenpoints.hpp @@ -1,6 +1,8 @@ #pragma once -#include +#include + +#include namespace chatterino { namespace util { diff --git a/src/util/emotemap.hpp b/src/util/emotemap.hpp index 56c5823d2..d787a7459 100644 --- a/src/util/emotemap.hpp +++ b/src/util/emotemap.hpp @@ -9,9 +9,7 @@ namespace chatterino { namespace util { struct EmoteData { - EmoteData() - { - } + EmoteData() = default; EmoteData(messages::Image *_image) : image1x(_image) @@ -29,7 +27,7 @@ struct EmoteData { messages::Image *image3x = nullptr; }; -typedef ConcurrentMap EmoteMap; +using EmoteMap = ConcurrentMap; } // namespace util } // namespace chatterino diff --git a/src/util/irchelpers.hpp b/src/util/irchelpers.hpp index 9462680b8..9bf215022 100644 --- a/src/util/irchelpers.hpp +++ b/src/util/irchelpers.hpp @@ -4,7 +4,8 @@ namespace chatterino { namespace util { -QString ParseTagString(const QString &input) + +inline QString ParseTagString(const QString &input) { QString output = input; output.detach(); @@ -49,9 +50,10 @@ QString ParseTagString(const QString &input) if (changed) { return output.replace("\0", ""); - } else { - return output; } + + return output; } -} + +} // namespace util } // namespace chatterino diff --git a/src/util/networkmanager.hpp b/src/util/networkmanager.hpp index 309c0ec63..7cf9dcfe8 100644 --- a/src/util/networkmanager.hpp +++ b/src/util/networkmanager.hpp @@ -51,11 +51,11 @@ public: worker->moveToThread(&NetworkManager::workerThread); QObject::connect( &requester, &NetworkRequester::requestUrl, worker, - [ worker, onFinished = std::move(onFinished), request = std::move(request) ]() { + [worker, onFinished = std::move(onFinished), request = std::move(request)]() { QNetworkReply *reply = NetworkManager::NaM.get(request); QObject::connect(reply, &QNetworkReply::finished, - [ worker, reply, onFinished = std::move(onFinished) ]() { + [worker, reply, onFinished = std::move(onFinished)]() { onFinished(reply); delete worker; }); @@ -111,11 +111,11 @@ public: worker->moveToThread(&NetworkManager::workerThread); QObject::connect( &requester, &NetworkRequester::requestUrl, worker, - [ worker, data, onFinished = std::move(onFinished), request = std::move(request) ]() { + [worker, data, onFinished = std::move(onFinished), request = std::move(request)]() { QNetworkReply *reply = NetworkManager::NaM.put(request, *data); QObject::connect(reply, &QNetworkReply::finished, - [ worker, reply, onFinished = std::move(onFinished) ]() { + [worker, reply, onFinished = std::move(onFinished)]() { onFinished(reply); delete worker; }); @@ -133,11 +133,11 @@ public: worker->moveToThread(&NetworkManager::workerThread); QObject::connect( &requester, &NetworkRequester::requestUrl, worker, - [ onFinished = std::move(onFinished), request = std::move(request), worker ]() { + [onFinished = std::move(onFinished), request = std::move(request), worker]() { QNetworkReply *reply = NetworkManager::NaM.put(request, ""); QObject::connect(reply, &QNetworkReply::finished, - [ onFinished = std::move(onFinished), reply, worker ]() { + [onFinished = std::move(onFinished), reply, worker]() { onFinished(reply); delete worker; }); @@ -155,11 +155,11 @@ public: worker->moveToThread(&NetworkManager::workerThread); QObject::connect( &requester, &NetworkRequester::requestUrl, worker, - [ onFinished = std::move(onFinished), request = std::move(request), worker ]() { + [onFinished = std::move(onFinished), request = std::move(request), worker]() { QNetworkReply *reply = NetworkManager::NaM.deleteResource(request); QObject::connect(reply, &QNetworkReply::finished, - [ onFinished = std::move(onFinished), reply, worker ]() { + [onFinished = std::move(onFinished), reply, worker]() { onFinished(reply); delete worker; }); diff --git a/src/widgets/basewidget.cpp b/src/widgets/basewidget.cpp index b915abbcb..6680134e6 100644 --- a/src/widgets/basewidget.cpp +++ b/src/widgets/basewidget.cpp @@ -33,9 +33,9 @@ float BaseWidget::getScale() const if (baseWidget == nullptr) { return 1.f; - } else { - return baseWidget->scale; } + + return baseWidget->scale; } QSize BaseWidget::getScaleIndependantSize() const @@ -98,7 +98,7 @@ void BaseWidget::childEvent(QChildEvent *event) if (event->added()) { BaseWidget *widget = dynamic_cast(event->child()); - if (widget) { + if (widget != nullptr) { this->widgets.push_back(widget); } } else if (event->removed()) { diff --git a/src/widgets/helper/titlebarbutton.cpp b/src/widgets/helper/titlebarbutton.cpp index 1d3f45aa4..d3b2cd34d 100644 --- a/src/widgets/helper/titlebarbutton.cpp +++ b/src/widgets/helper/titlebarbutton.cpp @@ -2,6 +2,7 @@ namespace chatterino { namespace widgets { + TitleBarButton::TitleBarButton() : RippleEffectButton(nullptr) { @@ -114,5 +115,6 @@ void TitleBarButton::paintEvent(QPaintEvent *) this->fancyPaint(painter); } + } // namespace widgets } // namespace chatterino diff --git a/src/widgets/helper/titlebarbutton.hpp b/src/widgets/helper/titlebarbutton.hpp index cdc13026f..418e9143b 100644 --- a/src/widgets/helper/titlebarbutton.hpp +++ b/src/widgets/helper/titlebarbutton.hpp @@ -4,6 +4,7 @@ namespace chatterino { namespace widgets { + class TitleBarButton : public RippleEffectButton { public: @@ -15,10 +16,11 @@ public: void setButtonStyle(Style style); protected: - virtual void paintEvent(QPaintEvent *) override; + void paintEvent(QPaintEvent *) override; private: Style style; }; + } // namespace widgets } // namespace chatterino diff --git a/src/widgets/split.cpp b/src/widgets/split.cpp index 19550d75a..f738f0eae 100644 --- a/src/widgets/split.cpp +++ b/src/widgets/split.cpp @@ -18,17 +18,12 @@ #include #include -#include #include #include #include -#include -#include #include #include #include -#include -#include #include #include @@ -540,5 +535,6 @@ void Split::drag() SplitContainer::isDraggingSplit = false; } } + } // namespace widgets } // namespace chatterino diff --git a/src/widgets/split.hpp b/src/widgets/split.hpp index 5f38a1969..ce5f193eb 100644 --- a/src/widgets/split.hpp +++ b/src/widgets/split.hpp @@ -19,7 +19,6 @@ #include namespace chatterino { - namespace widgets { class SplitContainer; @@ -45,7 +44,7 @@ class Split : public BaseWidget public: Split(SplitContainer *parent, const std::string &_uuid); - virtual ~Split(); + ~Split() override; pajlada::Settings::Setting channelName; boost::signals2::signal channelChanged; @@ -75,11 +74,11 @@ public: void drag(); protected: - virtual void paintEvent(QPaintEvent *) override; - virtual void mouseMoveEvent(QMouseEvent *) override; - virtual void mousePressEvent(QMouseEvent *event) override; - virtual void keyPressEvent(QKeyEvent *) override; - virtual void keyReleaseEvent(QKeyEvent *) override; + void paintEvent(QPaintEvent *) override; + void mouseMoveEvent(QMouseEvent *) override; + void mousePressEvent(QMouseEvent *event) override; + void keyPressEvent(QKeyEvent *) override; + void keyReleaseEvent(QKeyEvent *) override; private: SplitContainer &parentPage;