diff --git a/.clang-format b/.clang-format index cfbe49d3..6e5b5e5d 100644 --- a/.clang-format +++ b/.clang-format @@ -45,7 +45,7 @@ IncludeCategories: # Third party library includes - Regex: "^<([a-zA-Z_0-9-]+/)*[a-zA-Z_0-9-]+.h(pp)?>$" Priority: 3 -NamespaceIndentation: Inner +NamespaceIndentation: None PointerBindsToType: false SpacesBeforeTrailingComments: 2 Standard: Auto diff --git a/src/Application.hpp b/src/Application.hpp index fb717229..29ffe1c9 100644 --- a/src/Application.hpp +++ b/src/Application.hpp @@ -54,10 +54,10 @@ class IStreamerMode; class ITwitchUsers; class NativeMessagingServer; namespace pronouns { - class Pronouns; +class Pronouns; } // namespace pronouns namespace eventsub { - class IController; +class IController; } // namespace eventsub class IApplication diff --git a/src/RunGui.cpp b/src/RunGui.cpp index d7fee878..77b56a1d 100644 --- a/src/RunGui.cpp +++ b/src/RunGui.cpp @@ -40,209 +40,204 @@ namespace chatterino { namespace { - void installCustomPalette() - { - // borrowed from - // https://stackoverflow.com/questions/15035767/is-the-qt-5-dark-fusion-theme-available-for-windows - auto dark = QApplication::palette(); +void installCustomPalette() +{ + // borrowed from + // https://stackoverflow.com/questions/15035767/is-the-qt-5-dark-fusion-theme-available-for-windows + auto dark = QApplication::palette(); - dark.setColor(QPalette::Window, QColor(22, 22, 22)); - dark.setColor(QPalette::WindowText, Qt::white); - dark.setColor(QPalette::Text, Qt::white); - dark.setColor(QPalette::Base, QColor("#333")); - dark.setColor(QPalette::AlternateBase, QColor("#444")); - dark.setColor(QPalette::ToolTipBase, Qt::white); - dark.setColor(QPalette::ToolTipText, Qt::black); - dark.setColor(QPalette::Dark, QColor(35, 35, 35)); - dark.setColor(QPalette::Shadow, QColor(20, 20, 20)); - dark.setColor(QPalette::Button, QColor(70, 70, 70)); - dark.setColor(QPalette::ButtonText, Qt::white); - dark.setColor(QPalette::BrightText, Qt::red); - dark.setColor(QPalette::Link, QColor(42, 130, 218)); - dark.setColor(QPalette::Highlight, QColor(42, 130, 218)); - dark.setColor(QPalette::HighlightedText, Qt::white); - dark.setColor(QPalette::PlaceholderText, QColor(127, 127, 127)); + dark.setColor(QPalette::Window, QColor(22, 22, 22)); + dark.setColor(QPalette::WindowText, Qt::white); + dark.setColor(QPalette::Text, Qt::white); + dark.setColor(QPalette::Base, QColor("#333")); + dark.setColor(QPalette::AlternateBase, QColor("#444")); + dark.setColor(QPalette::ToolTipBase, Qt::white); + dark.setColor(QPalette::ToolTipText, Qt::black); + dark.setColor(QPalette::Dark, QColor(35, 35, 35)); + dark.setColor(QPalette::Shadow, QColor(20, 20, 20)); + dark.setColor(QPalette::Button, QColor(70, 70, 70)); + dark.setColor(QPalette::ButtonText, Qt::white); + dark.setColor(QPalette::BrightText, Qt::red); + dark.setColor(QPalette::Link, QColor(42, 130, 218)); + dark.setColor(QPalette::Highlight, QColor(42, 130, 218)); + dark.setColor(QPalette::HighlightedText, Qt::white); + dark.setColor(QPalette::PlaceholderText, QColor(127, 127, 127)); - dark.setColor(QPalette::Disabled, QPalette::Highlight, - QColor(80, 80, 80)); - dark.setColor(QPalette::Disabled, QPalette::HighlightedText, - QColor(127, 127, 127)); - dark.setColor(QPalette::Disabled, QPalette::ButtonText, - QColor(127, 127, 127)); - dark.setColor(QPalette::Disabled, QPalette::Text, - QColor(127, 127, 127)); - dark.setColor(QPalette::Disabled, QPalette::WindowText, - QColor(127, 127, 127)); + dark.setColor(QPalette::Disabled, QPalette::Highlight, QColor(80, 80, 80)); + dark.setColor(QPalette::Disabled, QPalette::HighlightedText, + QColor(127, 127, 127)); + dark.setColor(QPalette::Disabled, QPalette::ButtonText, + QColor(127, 127, 127)); + dark.setColor(QPalette::Disabled, QPalette::Text, QColor(127, 127, 127)); + dark.setColor(QPalette::Disabled, QPalette::WindowText, + QColor(127, 127, 127)); - QApplication::setPalette(dark); - } + QApplication::setPalette(dark); +} - void initQt() - { - // set up the QApplication flags - QApplication::setAttribute(Qt::AA_Use96Dpi, true); +void initQt() +{ + // set up the QApplication flags + QApplication::setAttribute(Qt::AA_Use96Dpi, true); #ifdef Q_OS_WIN32 - // Avoid promoting child widgets to child windows - // This causes bugs with frameless windows as not all child events - // get sent to the parent - effectively making the window immovable. - QApplication::setAttribute(Qt::AA_DontCreateNativeWidgetSiblings); + // Avoid promoting child widgets to child windows + // This causes bugs with frameless windows as not all child events + // get sent to the parent - effectively making the window immovable. + QApplication::setAttribute(Qt::AA_DontCreateNativeWidgetSiblings); #endif - QApplication::setStyle(QStyleFactory::create("Fusion")); + QApplication::setStyle(QStyleFactory::create("Fusion")); #ifndef Q_OS_MAC - QApplication::setWindowIcon(QIcon(":/icon.ico")); + QApplication::setWindowIcon(QIcon(":/icon.ico")); #endif #ifdef Q_OS_MAC - // On the Mac/Cocoa platform this attribute is enabled by default - // We override it to ensure shortcuts show in context menus on that platform - QApplication::setAttribute(Qt::AA_DontShowShortcutsInContextMenus, - false); + // On the Mac/Cocoa platform this attribute is enabled by default + // We override it to ensure shortcuts show in context menus on that platform + QApplication::setAttribute(Qt::AA_DontShowShortcutsInContextMenus, false); #endif - installCustomPalette(); - } + installCustomPalette(); +} - void showLastCrashDialog(const Args &args, const Paths &paths) +void showLastCrashDialog(const Args &args, const Paths &paths) +{ + auto *dialog = new LastRunCrashDialog(args, paths); + // Use exec() over open() to block the app from being loaded + // and to be able to set the safe mode. + dialog->exec(); +} + +void createRunningFile(const QString &path) +{ + QFile runningFile(path); + + runningFile.open(QIODevice::WriteOnly | QIODevice::Truncate); + runningFile.flush(); + runningFile.close(); +} + +void removeRunningFile(const QString &path) +{ + QFile::remove(path); +} + +std::chrono::steady_clock::time_point signalsInitTime; + +[[noreturn]] void handleSignal(int signum) +{ + using namespace std::chrono_literals; + + if (std::chrono::steady_clock::now() - signalsInitTime > 30s && + getApp()->getCrashHandler()->shouldRecover()) { - auto *dialog = new LastRunCrashDialog(args, paths); - // Use exec() over open() to block the app from being loaded - // and to be able to set the safe mode. - dialog->exec(); - } - - void createRunningFile(const QString &path) - { - QFile runningFile(path); - - runningFile.open(QIODevice::WriteOnly | QIODevice::Truncate); - runningFile.flush(); - runningFile.close(); - } - - void removeRunningFile(const QString &path) - { - QFile::remove(path); - } - - std::chrono::steady_clock::time_point signalsInitTime; - - [[noreturn]] void handleSignal(int signum) - { - using namespace std::chrono_literals; - - if (std::chrono::steady_clock::now() - signalsInitTime > 30s && - getApp()->getCrashHandler()->shouldRecover()) - { - QProcess proc; + QProcess proc; #ifdef Q_OS_MAC - // On macOS, programs are bundled into ".app" Application bundles, - // when restarting Chatterino that bundle should be opened with the "open" - // terminal command instead of directly starting the underlying executable, - // as those are 2 different things for the OS and i.e. do not use - // the same dock icon (resulting in a second Chatterino icon on restarting) - CFURLRef appUrlRef = CFBundleCopyBundleURL(CFBundleGetMainBundle()); - CFStringRef macPath = - CFURLCopyFileSystemPath(appUrlRef, kCFURLPOSIXPathStyle); - const char *pathPtr = - CFStringGetCStringPtr(macPath, CFStringGetSystemEncoding()); + // On macOS, programs are bundled into ".app" Application bundles, + // when restarting Chatterino that bundle should be opened with the "open" + // terminal command instead of directly starting the underlying executable, + // as those are 2 different things for the OS and i.e. do not use + // the same dock icon (resulting in a second Chatterino icon on restarting) + CFURLRef appUrlRef = CFBundleCopyBundleURL(CFBundleGetMainBundle()); + CFStringRef macPath = + CFURLCopyFileSystemPath(appUrlRef, kCFURLPOSIXPathStyle); + const char *pathPtr = + CFStringGetCStringPtr(macPath, CFStringGetSystemEncoding()); - proc.setProgram("open"); - proc.setArguments({pathPtr, "-n", "--args", "--crash-recovery"}); + proc.setProgram("open"); + proc.setArguments({pathPtr, "-n", "--args", "--crash-recovery"}); - CFRelease(appUrlRef); - CFRelease(macPath); + CFRelease(appUrlRef); + CFRelease(macPath); #else - proc.setProgram(QApplication::applicationFilePath()); - proc.setArguments({"--crash-recovery"}); + proc.setProgram(QApplication::applicationFilePath()); + proc.setArguments({"--crash-recovery"}); #endif - proc.startDetached(); - } - - std::_Exit(signum); + proc.startDetached(); } - // We want to restart Chatterino when it crashes and the setting is set to - // true. - void initSignalHandler() - { -#if defined(NDEBUG) && !defined(CHATTERINO_WITH_CRASHPAD) - signalsInitTime = std::chrono::steady_clock::now(); + std::_Exit(signum); +} - signal(SIGSEGV, handleSignal); +// We want to restart Chatterino when it crashes and the setting is set to +// true. +void initSignalHandler() +{ +#if defined(NDEBUG) && !defined(CHATTERINO_WITH_CRASHPAD) + signalsInitTime = std::chrono::steady_clock::now(); + + signal(SIGSEGV, handleSignal); #endif #if defined(Q_OS_UNIX) - auto *sigintHandler = new UnixSignalHandler(SIGINT); - QObject::connect(sigintHandler, &UnixSignalHandler::signalFired, [] { - qCInfo(chatterinoApp) - << "Received SIGINT, request application quit"; - QApplication::quit(); - }); - auto *sigtermHandler = new UnixSignalHandler(SIGTERM); - QObject::connect(sigtermHandler, &UnixSignalHandler::signalFired, [] { - qCInfo(chatterinoApp) - << "Received SIGTERM, request application quit"; - QApplication::quit(); - }); + auto *sigintHandler = new UnixSignalHandler(SIGINT); + QObject::connect(sigintHandler, &UnixSignalHandler::signalFired, [] { + qCInfo(chatterinoApp) << "Received SIGINT, request application quit"; + QApplication::quit(); + }); + auto *sigtermHandler = new UnixSignalHandler(SIGTERM); + QObject::connect(sigtermHandler, &UnixSignalHandler::signalFired, [] { + qCInfo(chatterinoApp) << "Received SIGTERM, request application quit"; + QApplication::quit(); + }); #endif - } +} - // We delete cache files that haven't been modified in 14 days. This strategy may be - // improved in the future. - void clearCache(const QDir &dir) +// We delete cache files that haven't been modified in 14 days. This strategy may be +// improved in the future. +void clearCache(const QDir &dir) +{ + size_t deletedCount = 0; + for (const auto &info : dir.entryInfoList(QDir::Files)) { - size_t deletedCount = 0; - for (const auto &info : dir.entryInfoList(QDir::Files)) + if (info.lastModified().addDays(14) < QDateTime::currentDateTime()) { - if (info.lastModified().addDays(14) < QDateTime::currentDateTime()) + bool res = QFile(info.absoluteFilePath()).remove(); + if (res) { - bool res = QFile(info.absoluteFilePath()).remove(); - if (res) - { - ++deletedCount; - } + ++deletedCount; } } - qCDebug(chatterinoCache) - << "Deleted" << deletedCount << "files in" << dir.path(); } + qCDebug(chatterinoCache) + << "Deleted" << deletedCount << "files in" << dir.path(); +} - // We delete all but the five most recent crashdumps. This strategy may be - // improved in the future. - void clearCrashes(QDir dir) +// We delete all but the five most recent crashdumps. This strategy may be +// improved in the future. +void clearCrashes(QDir dir) +{ + // crashpad crashdumps are stored inside the Crashes/report directory + if (!dir.cd("reports")) { - // crashpad crashdumps are stored inside the Crashes/report directory - if (!dir.cd("reports")) - { - // no reports directory exists = no files to delete - return; - } - - dir.setNameFilters({"*.dmp"}); - - size_t deletedCount = 0; - // TODO: use std::views::drop once supported by all compilers - size_t filesToSkip = 5; - for (auto &&info : dir.entryInfoList(QDir::Files, QDir::Time)) - { - if (filesToSkip > 0) - { - filesToSkip--; - continue; - } - - if (QFile(info.absoluteFilePath()).remove()) - { - deletedCount++; - } - } - qCDebug(chatterinoApp) << "Deleted" << deletedCount << "crashdumps"; + // no reports directory exists = no files to delete + return; } + + dir.setNameFilters({"*.dmp"}); + + size_t deletedCount = 0; + // TODO: use std::views::drop once supported by all compilers + size_t filesToSkip = 5; + for (auto &&info : dir.entryInfoList(QDir::Files, QDir::Time)) + { + if (filesToSkip > 0) + { + filesToSkip--; + continue; + } + + if (QFile(info.absoluteFilePath()).remove()) + { + deletedCount++; + } + } + qCDebug(chatterinoApp) << "Deleted" << deletedCount << "crashdumps"; +} } // namespace void runGui(QApplication &a, const Paths &paths, Settings &settings, diff --git a/src/common/Env.cpp b/src/common/Env.cpp index 6a7f5dac..a2d52b19 100644 --- a/src/common/Env.cpp +++ b/src/common/Env.cpp @@ -10,61 +10,61 @@ namespace chatterino { namespace { - template - void warn(const char *envName, const QString &envString, T defaultValue) - { - const auto typeName = QString::fromStdString( - std::string(type_name())); +template +void warn(const char *envName, const QString &envString, T defaultValue) +{ + const auto typeName = QString::fromStdString( + std::string(type_name())); - qCWarning(chatterinoEnv).noquote() - << QStringLiteral( - "Cannot parse value '%1' of environment variable '%2' " - "as a %3, reverting to default value '%4'") - .arg(envString) - .arg(envName) - .arg(typeName) - .arg(defaultValue); + qCWarning(chatterinoEnv).noquote() + << QStringLiteral( + "Cannot parse value '%1' of environment variable '%2' " + "as a %3, reverting to default value '%4'") + .arg(envString) + .arg(envName) + .arg(typeName) + .arg(defaultValue); +} + +std::optional readOptionalStringEnv(const char *envName) +{ + auto envString = qEnvironmentVariable(envName); + if (!envString.isEmpty()) + { + return envString; } - std::optional readOptionalStringEnv(const char *envName) + return std::nullopt; +} + +uint16_t readPortEnv(const char *envName, uint16_t defaultValue) +{ + auto envString = qEnvironmentVariable(envName); + if (!envString.isEmpty()) { - auto envString = qEnvironmentVariable(envName); - if (!envString.isEmpty()) + bool ok = false; + auto val = envString.toUShort(&ok); + if (ok) { - return envString; + return val; } - return std::nullopt; + warn(envName, envString, defaultValue); } - uint16_t readPortEnv(const char *envName, uint16_t defaultValue) + return defaultValue; +} + +bool readBoolEnv(const char *envName, bool defaultValue) +{ + auto envString = qEnvironmentVariable(envName); + if (!envString.isEmpty()) { - auto envString = qEnvironmentVariable(envName); - if (!envString.isEmpty()) - { - bool ok = false; - auto val = envString.toUShort(&ok); - if (ok) - { - return val; - } - - warn(envName, envString, defaultValue); - } - - return defaultValue; + return QVariant(envString).toBool(); } - bool readBoolEnv(const char *envName, bool defaultValue) - { - auto envString = qEnvironmentVariable(envName); - if (!envString.isEmpty()) - { - return QVariant(envString).toBool(); - } - - return defaultValue; - } + return defaultValue; +} } // namespace diff --git a/src/common/WindowDescriptors.cpp b/src/common/WindowDescriptors.cpp index 6c02d5c9..9d2e43d5 100644 --- a/src/common/WindowDescriptors.cpp +++ b/src/common/WindowDescriptors.cpp @@ -11,85 +11,85 @@ namespace chatterino { namespace { - QJsonArray loadWindowArray(const QString &settingsPath) +QJsonArray loadWindowArray(const QString &settingsPath) +{ + QFile file(settingsPath); + file.open(QIODevice::ReadOnly); + QByteArray data = file.readAll(); + QJsonDocument document = QJsonDocument::fromJson(data); + QJsonArray windows_arr = document.object().value("windows").toArray(); + return windows_arr; +} + +template +T loadNodes(const QJsonObject &obj) +{ + static_assert("loadNodes must be called with the SplitNodeDescriptor " + "or ContainerNodeDescriptor type"); +} + +template <> +SplitNodeDescriptor loadNodes(const QJsonObject &root) +{ + SplitNodeDescriptor descriptor; + + descriptor.flexH_ = root.value("flexh").toDouble(1.0); + descriptor.flexV_ = root.value("flexv").toDouble(1.0); + + auto data = root.value("data").toObject(); + + SplitDescriptor::loadFromJSON(descriptor, root, data); + + return descriptor; +} + +template <> +ContainerNodeDescriptor loadNodes(const QJsonObject &root) +{ + ContainerNodeDescriptor descriptor; + + descriptor.flexH_ = root.value("flexh").toDouble(1.0); + descriptor.flexV_ = root.value("flexv").toDouble(1.0); + + descriptor.vertical_ = root.value("type").toString() == "vertical"; + + for (QJsonValue _val : root.value("items").toArray()) { - QFile file(settingsPath); - file.open(QIODevice::ReadOnly); - QByteArray data = file.readAll(); - QJsonDocument document = QJsonDocument::fromJson(data); - QJsonArray windows_arr = document.object().value("windows").toArray(); - return windows_arr; - } + auto _obj = _val.toObject(); - template - T loadNodes(const QJsonObject &obj) - { - static_assert("loadNodes must be called with the SplitNodeDescriptor " - "or ContainerNodeDescriptor type"); - } - - template <> - SplitNodeDescriptor loadNodes(const QJsonObject &root) - { - SplitNodeDescriptor descriptor; - - descriptor.flexH_ = root.value("flexh").toDouble(1.0); - descriptor.flexV_ = root.value("flexv").toDouble(1.0); - - auto data = root.value("data").toObject(); - - SplitDescriptor::loadFromJSON(descriptor, root, data); - - return descriptor; - } - - template <> - ContainerNodeDescriptor loadNodes(const QJsonObject &root) - { - ContainerNodeDescriptor descriptor; - - descriptor.flexH_ = root.value("flexh").toDouble(1.0); - descriptor.flexV_ = root.value("flexv").toDouble(1.0); - - descriptor.vertical_ = root.value("type").toString() == "vertical"; - - for (QJsonValue _val : root.value("items").toArray()) + auto _type = _obj.value("type"); + if (_type == "split") { - auto _obj = _val.toObject(); - - auto _type = _obj.value("type"); - if (_type == "split") - { - descriptor.items_.emplace_back( - loadNodes(_obj)); - } - else - { - descriptor.items_.emplace_back( - loadNodes(_obj)); - } + descriptor.items_.emplace_back( + loadNodes(_obj)); } - - return descriptor; - } - - const QList loadFilters(QJsonValue val) - { - QList filterIds; - - if (!val.isUndefined()) + else { - const auto array = val.toArray(); - filterIds.reserve(array.size()); - for (const auto &id : array) - { - filterIds.append(QUuid::fromString(id.toString())); - } + descriptor.items_.emplace_back( + loadNodes(_obj)); } - - return filterIds; } + return descriptor; +} + +const QList loadFilters(QJsonValue val) +{ + QList filterIds; + + if (!val.isUndefined()) + { + const auto array = val.toArray(); + filterIds.reserve(array.size()); + for (const auto &id : array) + { + filterIds.append(QUuid::fromString(id.toString())); + } + } + + return filterIds; +} + } // namespace void SplitDescriptor::loadFromJSON(SplitDescriptor &descriptor, diff --git a/src/controllers/commands/builtin/twitch/ChatSettings.hpp b/src/controllers/commands/builtin/twitch/ChatSettings.hpp index 9362de12..fae5190c 100644 --- a/src/controllers/commands/builtin/twitch/ChatSettings.hpp +++ b/src/controllers/commands/builtin/twitch/ChatSettings.hpp @@ -8,20 +8,20 @@ struct CommandContext; namespace commands { - QString emoteOnly(const CommandContext &ctx); - QString emoteOnlyOff(const CommandContext &ctx); +QString emoteOnly(const CommandContext &ctx); +QString emoteOnlyOff(const CommandContext &ctx); - QString subscribers(const CommandContext &ctx); - QString subscribersOff(const CommandContext &ctx); +QString subscribers(const CommandContext &ctx); +QString subscribersOff(const CommandContext &ctx); - QString slow(const CommandContext &ctx); - QString slowOff(const CommandContext &ctx); +QString slow(const CommandContext &ctx); +QString slowOff(const CommandContext &ctx); - QString followers(const CommandContext &ctx); - QString followersOff(const CommandContext &ctx); +QString followers(const CommandContext &ctx); +QString followersOff(const CommandContext &ctx); - QString uniqueChat(const CommandContext &ctx); - QString uniqueChatOff(const CommandContext &ctx); +QString uniqueChat(const CommandContext &ctx); +QString uniqueChatOff(const CommandContext &ctx); } // namespace commands diff --git a/src/controllers/completion/CompletionModel.hpp b/src/controllers/completion/CompletionModel.hpp index f787a965..97de58fe 100644 --- a/src/controllers/completion/CompletionModel.hpp +++ b/src/controllers/completion/CompletionModel.hpp @@ -8,7 +8,7 @@ namespace chatterino { namespace completion { - class Source; +class Source; } // namespace completion /// @brief Represents the kind of completion occurring diff --git a/src/controllers/completion/sources/CommandSource.cpp b/src/controllers/completion/sources/CommandSource.cpp index 14378a62..c97d521d 100644 --- a/src/controllers/completion/sources/CommandSource.cpp +++ b/src/controllers/completion/sources/CommandSource.cpp @@ -11,23 +11,23 @@ namespace chatterino::completion { namespace { - void addCommand(const QString &command, std::vector &out) +void addCommand(const QString &command, std::vector &out) +{ + if (command.startsWith('/') || command.startsWith('.')) { - if (command.startsWith('/') || command.startsWith('.')) - { - out.push_back({ - .name = command.mid(1), - .prefix = command.at(0), - }); - } - else - { - out.push_back({ - .name = command, - .prefix = "", - }); - } + out.push_back({ + .name = command.mid(1), + .prefix = command.at(0), + }); } + else + { + out.push_back({ + .name = command, + .prefix = "", + }); + } +} } // namespace diff --git a/src/controllers/completion/sources/EmoteSource.cpp b/src/controllers/completion/sources/EmoteSource.cpp index 7d75582c..e78d9584 100644 --- a/src/controllers/completion/sources/EmoteSource.cpp +++ b/src/controllers/completion/sources/EmoteSource.cpp @@ -17,37 +17,36 @@ namespace chatterino::completion { namespace { - void addEmotes(std::vector &out, const EmoteMap &map, - const QString &providerName) +void addEmotes(std::vector &out, const EmoteMap &map, + const QString &providerName) +{ + for (auto &&emote : map) { - for (auto &&emote : map) - { - out.push_back({.emote = emote.second, - .searchName = emote.first.string, - .tabCompletionName = emote.first.string, - .displayName = emote.second->name.string, - .providerName = providerName, - .isEmoji = false}); - } + out.push_back({.emote = emote.second, + .searchName = emote.first.string, + .tabCompletionName = emote.first.string, + .displayName = emote.second->name.string, + .providerName = providerName, + .isEmoji = false}); } +} - void addEmojis(std::vector &out, - const std::vector &map) +void addEmojis(std::vector &out, const std::vector &map) +{ + for (const auto &emoji : map) { - for (const auto &emoji : map) + for (auto &&shortCode : emoji->shortCodes) { - for (auto &&shortCode : emoji->shortCodes) - { - out.push_back( - {.emote = emoji->emote, - .searchName = shortCode, - .tabCompletionName = QStringLiteral(":%1:").arg(shortCode), - .displayName = shortCode, - .providerName = "Emoji", - .isEmoji = true}); - } - }; - } + out.push_back( + {.emote = emoji->emote, + .searchName = shortCode, + .tabCompletionName = QStringLiteral(":%1:").arg(shortCode), + .displayName = shortCode, + .providerName = "Emoji", + .isEmoji = true}); + } + }; +} } // namespace diff --git a/src/controllers/completion/sources/Helpers.hpp b/src/controllers/completion/sources/Helpers.hpp index 74198f14..e44b1f73 100644 --- a/src/controllers/completion/sources/Helpers.hpp +++ b/src/controllers/completion/sources/Helpers.hpp @@ -10,14 +10,14 @@ namespace chatterino::completion { namespace { - size_t sizeWithinLimit(size_t size, size_t limit) +size_t sizeWithinLimit(size_t size, size_t limit) +{ + if (limit == 0) { - if (limit == 0) - { - return size; - } - return std::min(size, limit); + return size; } + return std::min(size, limit); +} } // namespace diff --git a/src/controllers/completion/strategies/SmartEmoteStrategy.cpp b/src/controllers/completion/strategies/SmartEmoteStrategy.cpp index a01be15b..6573df40 100644 --- a/src/controllers/completion/strategies/SmartEmoteStrategy.cpp +++ b/src/controllers/completion/strategies/SmartEmoteStrategy.cpp @@ -11,149 +11,148 @@ namespace chatterino::completion { namespace { - /** - * @brief This function calculates the "cost" of the changes that need to - * be done to the query to make it the value. - * - * By default an emote with more differences in character casing from the - * query will get a higher cost, each additional letter also increases cost. - * - * @param prioritizeUpper If set, then differences in casing don't matter, but - * instead the more lowercase letters an emote contains, the higher cost it - * will get. Additional letters also increase the cost in this mode. - * - * @return How different the emote is from query. Values in the range [-10, - * \infty]. - */ - int costOfEmote(QStringView query, QStringView emote, bool prioritizeUpper) +/** + * @brief This function calculates the "cost" of the changes that need to + * be done to the query to make it the value. + * + * By default an emote with more differences in character casing from the + * query will get a higher cost, each additional letter also increases cost. + * + * @param prioritizeUpper If set, then differences in casing don't matter, but + * instead the more lowercase letters an emote contains, the higher cost it + * will get. Additional letters also increase the cost in this mode. + * + * @return How different the emote is from query. Values in the range [-10, + * \infty]. + */ +int costOfEmote(QStringView query, QStringView emote, bool prioritizeUpper) +{ + int score = 0; + + if (prioritizeUpper) { - int score = 0; - - if (prioritizeUpper) + // We are in case 3, push 'more uppercase' emotes to the top + for (const auto i : emote) { - // We are in case 3, push 'more uppercase' emotes to the top - for (const auto i : emote) - { - score += int(!i.isUpper()); - } + score += int(!i.isUpper()); } - else - { - // Push more matching emotes to the top - int len = std::min(emote.size(), query.size()); - for (int i = 0; i < len; i++) - { - // Different casing gets a higher cost score - score += query.at(i).isUpper() ^ emote.at(i).isUpper(); - } - } - // No case differences, put this at the top - if (score == 0) - { - score = -10; - } - - auto diff = emote.size() - query.size(); - if (diff > 0) - { - // Case changes are way less changes to the user compared to adding characters - score += diff * 100; - } - return score; - }; - - // This contains the brains of emote tab completion. Updates output to sorted completions. - // Ensure that the query string is already normalized, that is doesn't have a leading ':' - // matchingFunction is used for testing if the emote should be included in the search. - void completeEmotes( - const std::vector &items, std::vector &output, - QStringView query, bool ignoreColonForCost, - const std::function - &matchingFunction) + } + else { - // Given these emotes: pajaW, PAJAW - // There are a few cases of input: - // 1. "pajaw" expect {pajaW, PAJAW} - no uppercase characters, do regular case insensitive search - // 2. "PA" expect {PAJAW} - uppercase characters, case sensitive search gives results - // 3. "Pajaw" expect {PAJAW, pajaW} - case sensitive search doesn't give results, need to use sorting - // 4. "NOTHING" expect {} - no results - // 5. "nothing" expect {} - same as 4 but first search is case insensitive + // Push more matching emotes to the top + int len = std::min(emote.size(), query.size()); + for (int i = 0; i < len; i++) + { + // Different casing gets a higher cost score + score += query.at(i).isUpper() ^ emote.at(i).isUpper(); + } + } + // No case differences, put this at the top + if (score == 0) + { + score = -10; + } - // Check if the query contains any uppercase characters - // This tells us if we're in case 1 or 5 vs all others - bool haveUpper = - std::any_of(query.begin(), query.end(), [](const QChar &c) { - return c.isUpper(); - }); + auto diff = emote.size() - query.size(); + if (diff > 0) + { + // Case changes are way less changes to the user compared to adding characters + score += diff * 100; + } + return score; +}; - // First search, for case 1 it will be case insensitive, - // for cases 2, 3 and 4 it will be case sensitive +// This contains the brains of emote tab completion. Updates output to sorted completions. +// Ensure that the query string is already normalized, that is doesn't have a leading ':' +// matchingFunction is used for testing if the emote should be included in the search. +void completeEmotes( + const std::vector &items, std::vector &output, + QStringView query, bool ignoreColonForCost, + const std::function &matchingFunction) +{ + // Given these emotes: pajaW, PAJAW + // There are a few cases of input: + // 1. "pajaw" expect {pajaW, PAJAW} - no uppercase characters, do regular case insensitive search + // 2. "PA" expect {PAJAW} - uppercase characters, case sensitive search gives results + // 3. "Pajaw" expect {PAJAW, pajaW} - case sensitive search doesn't give results, need to use sorting + // 4. "NOTHING" expect {} - no results + // 5. "nothing" expect {} - same as 4 but first search is case insensitive + + // Check if the query contains any uppercase characters + // This tells us if we're in case 1 or 5 vs all others + bool haveUpper = + std::any_of(query.begin(), query.end(), [](const QChar &c) { + return c.isUpper(); + }); + + // First search, for case 1 it will be case insensitive, + // for cases 2, 3 and 4 it will be case sensitive + for (const auto &item : items) + { + if (matchingFunction( + item, haveUpper ? Qt::CaseSensitive : Qt::CaseInsensitive)) + { + output.push_back(item); + } + } + + // if case 3: then true; false otherwise + bool prioritizeUpper = false; + + // No results from search + if (output.empty()) + { + if (!haveUpper) + { + // Optimisation: First search was case insensitive, but we found nothing + // There is nothing to be found: case 5. + return; + } + // Case sensitive search from case 2 found nothing, therefore we can + // only be in case 3 or 4. + + prioritizeUpper = true; + // Run the search again but this time without case sensitivity for (const auto &item : items) { - if (matchingFunction( - item, haveUpper ? Qt::CaseSensitive : Qt::CaseInsensitive)) + if (matchingFunction(item, Qt::CaseInsensitive)) { output.push_back(item); } } - - // if case 3: then true; false otherwise - bool prioritizeUpper = false; - - // No results from search if (output.empty()) { - if (!haveUpper) - { - // Optimisation: First search was case insensitive, but we found nothing - // There is nothing to be found: case 5. - return; - } - // Case sensitive search from case 2 found nothing, therefore we can - // only be in case 3 or 4. - - prioritizeUpper = true; - // Run the search again but this time without case sensitivity - for (const auto &item : items) - { - if (matchingFunction(item, Qt::CaseInsensitive)) - { - output.push_back(item); - } - } - if (output.empty()) - { - // The second search found nothing, so don't even try to sort: case 4 - return; - } + // The second search found nothing, so don't even try to sort: case 4 + return; } - - std::sort(output.begin(), output.end(), - [query, prioritizeUpper, ignoreColonForCost]( - const EmoteItem &a, const EmoteItem &b) -> bool { - auto tempA = a.searchName; - auto tempB = b.searchName; - if (ignoreColonForCost && tempA.startsWith(":")) - { - tempA = tempA.mid(1); - } - if (ignoreColonForCost && tempB.startsWith(":")) - { - tempB = tempB.mid(1); - } - - auto costA = costOfEmote(query, tempA, prioritizeUpper); - auto costB = costOfEmote(query, tempB, prioritizeUpper); - if (costA == costB) - { - // Case difference and length came up tied for (a, b), break the tie - return QString::compare(tempA, tempB, - Qt::CaseInsensitive) < 0; - } - - return costA < costB; - }); } + + std::sort(output.begin(), output.end(), + [query, prioritizeUpper, ignoreColonForCost]( + const EmoteItem &a, const EmoteItem &b) -> bool { + auto tempA = a.searchName; + auto tempB = b.searchName; + if (ignoreColonForCost && tempA.startsWith(":")) + { + tempA = tempA.mid(1); + } + if (ignoreColonForCost && tempB.startsWith(":")) + { + tempB = tempB.mid(1); + } + + auto costA = costOfEmote(query, tempA, prioritizeUpper); + auto costB = costOfEmote(query, tempB, prioritizeUpper); + if (costA == costB) + { + // Case difference and length came up tied for (a, b), break the tie + return QString::compare(tempA, tempB, + Qt::CaseInsensitive) < 0; + } + + return costA < costB; + }); +} } // namespace void SmartEmoteStrategy::apply(const std::vector &items, diff --git a/src/controllers/highlights/HighlightPhrase.cpp b/src/controllers/highlights/HighlightPhrase.cpp index 164de013..33f8ded1 100644 --- a/src/controllers/highlights/HighlightPhrase.cpp +++ b/src/controllers/highlights/HighlightPhrase.cpp @@ -6,8 +6,8 @@ namespace chatterino { namespace { - constexpr QStringView REGEX_START_BOUNDARY(u"(?:\\b|\\s|^)"); - constexpr QStringView REGEX_END_BOUNDARY(u"(?:\\b|\\s|$)"); +constexpr QStringView REGEX_START_BOUNDARY(u"(?:\\b|\\s|^)"); +constexpr QStringView REGEX_END_BOUNDARY(u"(?:\\b|\\s|$)"); } // namespace diff --git a/src/controllers/highlights/HighlightPhrase.hpp b/src/controllers/highlights/HighlightPhrase.hpp index ed03fbe9..8f130665 100644 --- a/src/controllers/highlights/HighlightPhrase.hpp +++ b/src/controllers/highlights/HighlightPhrase.hpp @@ -105,11 +105,11 @@ private: namespace pajlada { namespace { - chatterino::HighlightPhrase constructError() - { - return chatterino::HighlightPhrase(QString(), false, false, false, - false, false, QString(), QColor()); - } +chatterino::HighlightPhrase constructError() +{ + return chatterino::HighlightPhrase(QString(), false, false, false, false, + false, QString(), QColor()); +} } // namespace template <> diff --git a/src/messages/MessageBuilder.hpp b/src/messages/MessageBuilder.hpp index f4f6667c..c6bdb626 100644 --- a/src/messages/MessageBuilder.hpp +++ b/src/messages/MessageBuilder.hpp @@ -37,7 +37,7 @@ struct ChannelPointReward; struct TwitchEmoteOccurrence; namespace linkparser { - struct Parsed; +struct Parsed; } // namespace linkparser struct SystemMessageTag { diff --git a/src/messages/MessageElement.cpp b/src/messages/MessageElement.cpp index d5b98a73..835754b6 100644 --- a/src/messages/MessageElement.cpp +++ b/src/messages/MessageElement.cpp @@ -26,21 +26,21 @@ using namespace literals; namespace { - // Computes the bounding box for the given vector of images - QSizeF getBoundingBoxSize(const std::vector &images) +// Computes the bounding box for the given vector of images +QSizeF getBoundingBoxSize(const std::vector &images) +{ + qreal width = 0; + qreal height = 0; + for (const auto &img : images) { - qreal width = 0; - qreal height = 0; - for (const auto &img : images) - { - QSizeF s = img->size(); - width = std::max(width, s.width()); - height = std::max(height, s.height()); - } - - return {width, height}; + QSizeF s = img->size(); + width = std::max(width, s.width()); + height = std::max(height, s.height()); } + return {width, height}; +} + } // namespace MessageElement::MessageElement(MessageElementFlags flags) diff --git a/src/messages/layouts/MessageLayout.cpp b/src/messages/layouts/MessageLayout.cpp index 8831f6c8..031629e9 100644 --- a/src/messages/layouts/MessageLayout.cpp +++ b/src/messages/layouts/MessageLayout.cpp @@ -23,15 +23,15 @@ namespace chatterino { namespace { - QColor blendColors(const QColor &base, const QColor &apply) - { - const qreal &alpha = apply.alphaF(); - QColor result; - result.setRgbF(base.redF() * (1 - alpha) + apply.redF() * alpha, - base.greenF() * (1 - alpha) + apply.greenF() * alpha, - base.blueF() * (1 - alpha) + apply.blueF() * alpha); - return result; - } +QColor blendColors(const QColor &base, const QColor &apply) +{ + const qreal &alpha = apply.alphaF(); + QColor result; + result.setRgbF(base.redF() * (1 - alpha) + apply.redF() * alpha, + base.greenF() * (1 - alpha) + apply.greenF() * alpha, + base.blueF() * (1 - alpha) + apply.blueF() * alpha); + return result; +} } // namespace MessageLayout::MessageLayout(MessagePtr message) diff --git a/src/providers/bttv/BttvEmotes.hpp b/src/providers/bttv/BttvEmotes.hpp index 92e4cf37..20f7b558 100644 --- a/src/providers/bttv/BttvEmotes.hpp +++ b/src/providers/bttv/BttvEmotes.hpp @@ -24,8 +24,8 @@ struct BttvLiveUpdateEmoteRemoveMessage; namespace bttv::detail { - EmoteMap parseChannelEmotes(const QJsonObject &jsonRoot, - const QString &channelDisplayName); +EmoteMap parseChannelEmotes(const QJsonObject &jsonRoot, + const QString &channelDisplayName); } // namespace bttv::detail diff --git a/src/providers/ffz/FfzEmotes.hpp b/src/providers/ffz/FfzEmotes.hpp index f63efe36..d089e8d1 100644 --- a/src/providers/ffz/FfzEmotes.hpp +++ b/src/providers/ffz/FfzEmotes.hpp @@ -27,12 +27,10 @@ using FfzChannelBadgeMap = namespace ffz::detail { - EmoteMap parseChannelEmotes(const QJsonObject &jsonRoot); +EmoteMap parseChannelEmotes(const QJsonObject &jsonRoot); - /** - * Parse the `user_badge_ids` into a map of User IDs -> Badge IDs - */ - FfzChannelBadgeMap parseChannelBadges(const QJsonObject &badgeRoot); +/// Parse the `user_badge_ids` into a map of User IDs -> Badge IDs +FfzChannelBadgeMap parseChannelBadges(const QJsonObject &badgeRoot); } // namespace ffz::detail diff --git a/src/providers/irc/IrcConnection2.cpp b/src/providers/irc/IrcConnection2.cpp index 3f9d57c9..6e7cb63a 100644 --- a/src/providers/irc/IrcConnection2.cpp +++ b/src/providers/irc/IrcConnection2.cpp @@ -11,7 +11,7 @@ namespace chatterino { namespace { - const auto payload = "chatterino/" + CHATTERINO_VERSION; +const auto payload = "chatterino/" + CHATTERINO_VERSION; } // namespace diff --git a/src/providers/liveupdates/BasicPubSubWebsocket.hpp b/src/providers/liveupdates/BasicPubSubWebsocket.hpp index bf30c30c..a22bc152 100644 --- a/src/providers/liveupdates/BasicPubSubWebsocket.hpp +++ b/src/providers/liveupdates/BasicPubSubWebsocket.hpp @@ -28,9 +28,9 @@ struct BasicPubSubConfig : public websocketpp::config::asio_tls_client { }; namespace liveupdates { - using WebsocketClient = websocketpp::client; - using WebsocketHandle = websocketpp::connection_hdl; - using WebsocketErrorCode = websocketpp::lib::error_code; +using WebsocketClient = websocketpp::client; +using WebsocketHandle = websocketpp::connection_hdl; +using WebsocketErrorCode = websocketpp::lib::error_code; } // namespace liveupdates } // namespace chatterino diff --git a/src/providers/seventv/SeventvEmotes.hpp b/src/providers/seventv/SeventvEmotes.hpp index 29480163..955d1aed 100644 --- a/src/providers/seventv/SeventvEmotes.hpp +++ b/src/providers/seventv/SeventvEmotes.hpp @@ -21,9 +21,9 @@ namespace chatterino { class ImageSet; class Channel; namespace seventv::eventapi { - struct EmoteAddDispatch; - struct EmoteUpdateDispatch; - struct EmoteRemoveDispatch; +struct EmoteAddDispatch; +struct EmoteUpdateDispatch; +struct EmoteRemoveDispatch; } // namespace seventv::eventapi // https://github.com/SevenTV/API/blob/a84e884b5590dbb5d91a5c6b3548afabb228f385/data/model/emote-set.model.go#L29-L36 @@ -86,7 +86,7 @@ using SeventvEmoteSetFlags = FlagsEnum; namespace seventv::detail { - EmoteMap parseEmotes(const QJsonArray &emoteSetEmotes, bool isGlobal); +EmoteMap parseEmotes(const QJsonArray &emoteSetEmotes, bool isGlobal); } // namespace seventv::detail diff --git a/src/providers/seventv/SeventvEventAPI.hpp b/src/providers/seventv/SeventvEventAPI.hpp index d4b4c34f..ea6159bf 100644 --- a/src/providers/seventv/SeventvEventAPI.hpp +++ b/src/providers/seventv/SeventvEventAPI.hpp @@ -10,13 +10,13 @@ namespace chatterino { namespace seventv::eventapi { - struct Dispatch; - struct EmoteAddDispatch; - struct EmoteUpdateDispatch; - struct EmoteRemoveDispatch; - struct UserConnectionUpdateDispatch; - struct CosmeticCreateDispatch; - struct EntitlementCreateDeleteDispatch; +struct Dispatch; +struct EmoteAddDispatch; +struct EmoteUpdateDispatch; +struct EmoteRemoveDispatch; +struct UserConnectionUpdateDispatch; +struct CosmeticCreateDispatch; +struct EntitlementCreateDeleteDispatch; } // namespace seventv::eventapi class SeventvBadges; diff --git a/src/providers/twitch/TwitchChannel.cpp b/src/providers/twitch/TwitchChannel.cpp index 34393552..4a67980c 100644 --- a/src/providers/twitch/TwitchChannel.cpp +++ b/src/providers/twitch/TwitchChannel.cpp @@ -63,35 +63,34 @@ using namespace literals; namespace { #if QT_VERSION < QT_VERSION_CHECK(6, 1, 0) - const QString MAGIC_MESSAGE_SUFFIX = QString((const char *)u8" \U000E0000"); +const QString MAGIC_MESSAGE_SUFFIX = QString((const char *)u8" \U000E0000"); #else - const QString MAGIC_MESSAGE_SUFFIX = QString::fromUtf8(u8" \U000E0000"); +const QString MAGIC_MESSAGE_SUFFIX = QString::fromUtf8(u8" \U000E0000"); #endif - constexpr int CLIP_CREATION_COOLDOWN = 5000; - const QString CLIPS_LINK("https://clips.twitch.tv/%1"); - const QString CLIPS_FAILURE_CLIPS_UNAVAILABLE_TEXT( - "Failed to create a clip - clips are temporarily unavailable: %1"); - const QString CLIPS_FAILURE_CLIPS_DISABLED_TEXT( - "Failed to create a clip - the streamer has clips disabled in their " - "channel."); - const QString CLIPS_FAILURE_CLIPS_RESTRICTED_TEXT( - "Failed to create a clip - the streamer has restricted clip creation " - "to subscribers, or followers of an unknown duration."); - const QString CLIPS_FAILURE_CLIPS_RESTRICTED_CATEGORY_TEXT( - "Failed to create a clip - the streamer has disabled clips while in " - "this category."); - const QString CLIPS_FAILURE_NOT_AUTHENTICATED_TEXT( - "Failed to create a clip - you need to re-authenticate."); - const QString CLIPS_FAILURE_UNKNOWN_ERROR_TEXT( - "Failed to create a clip: %1"); - const QString LOGIN_PROMPT_TEXT("Click here to add your account again."); - const Link ACCOUNTS_LINK(Link::OpenAccountsPage, QString()); +constexpr int CLIP_CREATION_COOLDOWN = 5000; +const QString CLIPS_LINK("https://clips.twitch.tv/%1"); +const QString CLIPS_FAILURE_CLIPS_UNAVAILABLE_TEXT( + "Failed to create a clip - clips are temporarily unavailable: %1"); +const QString CLIPS_FAILURE_CLIPS_DISABLED_TEXT( + "Failed to create a clip - the streamer has clips disabled in their " + "channel."); +const QString CLIPS_FAILURE_CLIPS_RESTRICTED_TEXT( + "Failed to create a clip - the streamer has restricted clip creation " + "to subscribers, or followers of an unknown duration."); +const QString CLIPS_FAILURE_CLIPS_RESTRICTED_CATEGORY_TEXT( + "Failed to create a clip - the streamer has disabled clips while in " + "this category."); +const QString CLIPS_FAILURE_NOT_AUTHENTICATED_TEXT( + "Failed to create a clip - you need to re-authenticate."); +const QString CLIPS_FAILURE_UNKNOWN_ERROR_TEXT("Failed to create a clip: %1"); +const QString LOGIN_PROMPT_TEXT("Click here to add your account again."); +const Link ACCOUNTS_LINK(Link::OpenAccountsPage, QString()); - // Maximum number of chatters to fetch when refreshing chatters - constexpr auto MAX_CHATTERS_TO_FETCH = 5000; +// Maximum number of chatters to fetch when refreshing chatters +constexpr auto MAX_CHATTERS_TO_FETCH = 5000; - // From Twitch docs - expected size for a badge (1x) - constexpr QSize BASE_BADGE_SIZE(18, 18); +// From Twitch docs - expected size for a badge (1x) +constexpr QSize BASE_BADGE_SIZE(18, 18); } // namespace TwitchChannel::TwitchChannel(const QString &name) diff --git a/src/providers/twitch/TwitchChannel.hpp b/src/providers/twitch/TwitchChannel.hpp index 968934e0..f93f719c 100644 --- a/src/providers/twitch/TwitchChannel.hpp +++ b/src/providers/twitch/TwitchChannel.hpp @@ -45,10 +45,10 @@ struct BttvLiveUpdateEmoteRemoveMessage; class SeventvEmotes; namespace seventv::eventapi { - struct EmoteAddDispatch; - struct EmoteUpdateDispatch; - struct EmoteRemoveDispatch; - struct UserConnectionUpdateDispatch; +struct EmoteAddDispatch; +struct EmoteUpdateDispatch; +struct EmoteRemoveDispatch; +struct UserConnectionUpdateDispatch; } // namespace seventv::eventapi struct ChannelPointReward; diff --git a/src/singletons/NativeMessaging.cpp b/src/singletons/NativeMessaging.cpp index d989ae0e..24a2baf2 100644 --- a/src/singletons/NativeMessaging.cpp +++ b/src/singletons/NativeMessaging.cpp @@ -200,22 +200,22 @@ std::string &getNmQueueName(const Paths &paths) namespace nm::client { - void sendMessage(const QByteArray &array) - { - ipc::sendMessage("chatterino_gui", array); - } +void sendMessage(const QByteArray &array) +{ + ipc::sendMessage("chatterino_gui", array); +} - void writeToCout(const QByteArray &array) - { - const auto *data = array.data(); - auto size = uint32_t(array.size()); +void writeToCout(const QByteArray &array) +{ + const auto *data = array.data(); + auto size = uint32_t(array.size()); - // We're writing the raw bytes to cout. - // NOLINTNEXTLINE(cppcoreguidelines-pro-type-reinterpret-cast) - std::cout.write(reinterpret_cast(&size), 4); - std::cout.write(data, size); - std::cout.flush(); - } + // We're writing the raw bytes to cout. + // NOLINTNEXTLINE(cppcoreguidelines-pro-type-reinterpret-cast) + std::cout.write(reinterpret_cast(&size), 4); + std::cout.write(data, size); + std::cout.flush(); +} } // namespace nm::client diff --git a/src/singletons/NativeMessaging.hpp b/src/singletons/NativeMessaging.hpp index c69a9983..276210de 100644 --- a/src/singletons/NativeMessaging.hpp +++ b/src/singletons/NativeMessaging.hpp @@ -37,8 +37,8 @@ Atomic> &nmIpcError(); namespace nm::client { - void sendMessage(const QByteArray &array); - void writeToCout(const QByteArray &array); +void sendMessage(const QByteArray &array); +void writeToCout(const QByteArray &array); } // namespace nm::client diff --git a/src/util/FormatTime.cpp b/src/util/FormatTime.cpp index 13b64349..2c5d98e5 100644 --- a/src/util/FormatTime.cpp +++ b/src/util/FormatTime.cpp @@ -7,15 +7,15 @@ namespace chatterino { namespace { - void appendDuration(int count, QChar &&suffix, QString &out) +void appendDuration(int count, QChar &&suffix, QString &out) +{ + if (!out.isEmpty()) { - if (!out.isEmpty()) - { - out.append(' '); - } - out.append(QString::number(count)); - out.append(suffix); + out.append(' '); } + out.append(QString::number(count)); + out.append(suffix); +} } // namespace diff --git a/src/util/Helpers.cpp b/src/util/Helpers.cpp index 1878ce8f..abc4935c 100644 --- a/src/util/Helpers.cpp +++ b/src/util/Helpers.cpp @@ -33,105 +33,105 @@ namespace chatterino { namespace helpers::detail { - SizeType skipSpace(QStringView view, SizeType startPos) +SizeType skipSpace(QStringView view, SizeType startPos) +{ + while (startPos < view.length() && view.at(startPos).isSpace()) { - while (startPos < view.length() && view.at(startPos).isSpace()) - { - startPos++; - } - return startPos - 1; + startPos++; } + return startPos - 1; +} - bool matchesIgnorePlural(QStringView word, const QString &expected) +bool matchesIgnorePlural(QStringView word, const QString &expected) +{ + if (!word.startsWith(expected)) { - if (!word.startsWith(expected)) - { - return false; - } - if (word.length() == expected.length()) - { - return true; - } - return word.length() == expected.length() + 1 && - word.at(word.length() - 1).toLatin1() == 's'; + return false; } - - std::pair findUnitMultiplierToSec(QStringView view, - SizeType &pos) + if (word.length() == expected.length()) { - // Step 1. find end of unit - auto startIdx = pos; - auto endIdx = view.length(); - for (; pos < view.length(); pos++) - { - auto c = view.at(pos); - if (c.isSpace() || c.isDigit()) - { - endIdx = pos; - break; - } - } - pos--; + return true; + } + return word.length() == expected.length() + 1 && + word.at(word.length() - 1).toLatin1() == 's'; +} - // TODO(QT6): use sliced (more readable) - auto unit = view.mid(startIdx, endIdx - startIdx); - if (unit.isEmpty()) +std::pair findUnitMultiplierToSec(QStringView view, + SizeType &pos) +{ + // Step 1. find end of unit + auto startIdx = pos; + auto endIdx = view.length(); + for (; pos < view.length(); pos++) + { + auto c = view.at(pos); + if (c.isSpace() || c.isDigit()) { - return std::make_pair(0, false); + endIdx = pos; + break; } + } + pos--; - auto first = unit.at(0).toLatin1(); - switch (first) - { - case 's': { - if (unit.length() == 1 || - matchesIgnorePlural(unit, QStringLiteral("second"))) - { - return std::make_pair(1, true); - } - } - break; - case 'm': { - if (unit.length() == 1 || - matchesIgnorePlural(unit, QStringLiteral("minute"))) - { - return std::make_pair(60, true); - } - if ((unit.length() == 2 && unit.at(1).toLatin1() == 'o') || - matchesIgnorePlural(unit, QStringLiteral("month"))) - { - return std::make_pair(60 * 60 * 24 * 30, true); - } - } - break; - case 'h': { - if (unit.length() == 1 || - matchesIgnorePlural(unit, QStringLiteral("hour"))) - { - return std::make_pair(60 * 60, true); - } - } - break; - case 'd': { - if (unit.length() == 1 || - matchesIgnorePlural(unit, QStringLiteral("day"))) - { - return std::make_pair(60 * 60 * 24, true); - } - } - break; - case 'w': { - if (unit.length() == 1 || - matchesIgnorePlural(unit, QStringLiteral("week"))) - { - return std::make_pair(60 * 60 * 24 * 7, true); - } - } - break; - } + // TODO(QT6): use sliced (more readable) + auto unit = view.mid(startIdx, endIdx - startIdx); + if (unit.isEmpty()) + { return std::make_pair(0, false); } + auto first = unit.at(0).toLatin1(); + switch (first) + { + case 's': { + if (unit.length() == 1 || + matchesIgnorePlural(unit, QStringLiteral("second"))) + { + return std::make_pair(1, true); + } + } + break; + case 'm': { + if (unit.length() == 1 || + matchesIgnorePlural(unit, QStringLiteral("minute"))) + { + return std::make_pair(60, true); + } + if ((unit.length() == 2 && unit.at(1).toLatin1() == 'o') || + matchesIgnorePlural(unit, QStringLiteral("month"))) + { + return std::make_pair(60 * 60 * 24 * 30, true); + } + } + break; + case 'h': { + if (unit.length() == 1 || + matchesIgnorePlural(unit, QStringLiteral("hour"))) + { + return std::make_pair(60 * 60, true); + } + } + break; + case 'd': { + if (unit.length() == 1 || + matchesIgnorePlural(unit, QStringLiteral("day"))) + { + return std::make_pair(60 * 60 * 24, true); + } + } + break; + case 'w': { + if (unit.length() == 1 || + matchesIgnorePlural(unit, QStringLiteral("week"))) + { + return std::make_pair(60 * 60 * 24 * 7, true); + } + } + break; + } + return std::make_pair(0, false); +} + } // namespace helpers::detail using namespace helpers::detail; diff --git a/src/util/Helpers.hpp b/src/util/Helpers.hpp index b405d844..584ab16c 100644 --- a/src/util/Helpers.hpp +++ b/src/util/Helpers.hpp @@ -18,44 +18,44 @@ namespace chatterino { // only qualified for tests namespace helpers::detail { - using SizeType = QStringView::size_type; +using SizeType = QStringView::size_type; - /** - * Skips all spaces. - * The caller must guarantee view.at(startPos).isSpace(). - * - * @param view The string to skip spaces in. - * @param startPos The starting position (there must be a space in the view). - * @return The position of the last space. - */ - SizeType skipSpace(QStringView view, SizeType startPos); +/** + * Skips all spaces. + * The caller must guarantee view.at(startPos).isSpace(). + * + * @param view The string to skip spaces in. + * @param startPos The starting position (there must be a space in the view). + * @return The position of the last space. + */ +SizeType skipSpace(QStringView view, SizeType startPos); - /** - * Checks if `word` equals `expected` (singular) or `expected` + 's' (plural). - * - * @param word Word to test. Must not be empty. - * @param expected Singular of the expected word. - * @return true if `word` is singular or plural of `expected`. - */ - bool matchesIgnorePlural(QStringView word, const QString &expected); +/** + * Checks if `word` equals `expected` (singular) or `expected` + 's' (plural). + * + * @param word Word to test. Must not be empty. + * @param expected Singular of the expected word. + * @return true if `word` is singular or plural of `expected`. + */ +bool matchesIgnorePlural(QStringView word, const QString &expected); - /** - * Tries to find the unit starting at `pos` and returns its multiplier so - * `valueInUnit * multiplier = valueInSeconds` (e.g. 60 for minutes). - * - * Supported units are - * 'w[eek(s)]', 'd[ay(s)]', - * 'h[our(s)]', 'm[inute(s)]', 's[econd(s)]'. - * The unit must be in lowercase. - * - * @param view A view into a string - * @param pos The starting position. - * This is set to the last position of the unit - * if it's a valid unit, undefined otherwise. - * @return (multiplier, ok) - */ - std::pair findUnitMultiplierToSec(QStringView view, - SizeType &pos); +/** + * Tries to find the unit starting at `pos` and returns its multiplier so + * `valueInUnit * multiplier = valueInSeconds` (e.g. 60 for minutes). + * + * Supported units are + * 'w[eek(s)]', 'd[ay(s)]', + * 'h[our(s)]', 'm[inute(s)]', 's[econd(s)]'. + * The unit must be in lowercase. + * + * @param view A view into a string + * @param pos The starting position. + * This is set to the last position of the unit + * if it's a valid unit, undefined otherwise. + * @return (multiplier, ok) + */ +std::pair findUnitMultiplierToSec(QStringView view, + SizeType &pos); } // namespace helpers::detail diff --git a/src/util/RapidjsonHelpers.cpp b/src/util/RapidjsonHelpers.cpp index fb61219c..20111151 100644 --- a/src/util/RapidjsonHelpers.cpp +++ b/src/util/RapidjsonHelpers.cpp @@ -5,45 +5,43 @@ namespace chatterino { namespace rj { - void addMember(rapidjson::Value &obj, const char *key, - rapidjson::Value &&value, - rapidjson::Document::AllocatorType &a) +void addMember(rapidjson::Value &obj, const char *key, rapidjson::Value &&value, + rapidjson::Document::AllocatorType &a) +{ + obj.AddMember(rapidjson::Value(key, a).Move(), value, a); +} + +void addMember(rapidjson::Value &obj, const char *key, rapidjson::Value &value, + rapidjson::Document::AllocatorType &a) +{ + obj.AddMember(rapidjson::Value(key, a).Move(), value.Move(), a); +} + +QString stringify(const rapidjson::Value &value) +{ + rapidjson::StringBuffer buffer; + rapidjson::Writer writer(buffer); + value.Accept(writer); + + return buffer.GetString(); +} + +bool getSafeObject(rapidjson::Value &obj, const char *key, + rapidjson::Value &out) +{ + if (!checkJsonValue(obj, key)) { - obj.AddMember(rapidjson::Value(key, a).Move(), value, a); + return false; } - void addMember(rapidjson::Value &obj, const char *key, - rapidjson::Value &value, - rapidjson::Document::AllocatorType &a) - { - obj.AddMember(rapidjson::Value(key, a).Move(), value.Move(), a); - } + out = obj[key].Move(); + return true; +} - QString stringify(const rapidjson::Value &value) - { - rapidjson::StringBuffer buffer; - rapidjson::Writer writer(buffer); - value.Accept(writer); - - return buffer.GetString(); - } - - bool getSafeObject(rapidjson::Value &obj, const char *key, - rapidjson::Value &out) - { - if (!checkJsonValue(obj, key)) - { - return false; - } - - out = obj[key].Move(); - return true; - } - - bool checkJsonValue(const rapidjson::Value &obj, const char *key) - { - return obj.IsObject() && !obj.IsNull() && obj.HasMember(key); - } +bool checkJsonValue(const rapidjson::Value &obj, const char *key) +{ + return obj.IsObject() && !obj.IsNull() && obj.HasMember(key); +} } // namespace rj } // namespace chatterino diff --git a/src/util/RapidjsonHelpers.hpp b/src/util/RapidjsonHelpers.hpp index a14631fb..d129ad44 100644 --- a/src/util/RapidjsonHelpers.hpp +++ b/src/util/RapidjsonHelpers.hpp @@ -11,91 +11,89 @@ namespace chatterino { namespace rj { - void addMember(rapidjson::Value &obj, const char *key, - rapidjson::Value &&value, - rapidjson::Document::AllocatorType &a); - void addMember(rapidjson::Value &obj, const char *key, - rapidjson::Value &value, - rapidjson::Document::AllocatorType &a); +void addMember(rapidjson::Value &obj, const char *key, rapidjson::Value &&value, + rapidjson::Document::AllocatorType &a); +void addMember(rapidjson::Value &obj, const char *key, rapidjson::Value &value, + rapidjson::Document::AllocatorType &a); - template - void set(rapidjson::Value &obj, const char *key, const Type &value, - rapidjson::Document::AllocatorType &a) +template +void set(rapidjson::Value &obj, const char *key, const Type &value, + rapidjson::Document::AllocatorType &a) +{ + assert(obj.IsObject()); + + addMember(obj, key, pajlada::Serialize::get(value, a), a); +} + +template <> +inline void set(rapidjson::Value &obj, const char *key, + const rapidjson::Value &value, + rapidjson::Document::AllocatorType &a) +{ + assert(obj.IsObject()); + + addMember(obj, key, const_cast(value), a); +} + +template +void set(rapidjson::Document &obj, const char *key, const Type &value) +{ + assert(obj.IsObject()); + + auto &a = obj.GetAllocator(); + + addMember(obj, key, pajlada::Serialize::get(value, a), a); +} + +template <> +inline void set(rapidjson::Document &obj, const char *key, + const rapidjson::Value &value) +{ + assert(obj.IsObject()); + + auto &a = obj.GetAllocator(); + + addMember(obj, key, const_cast(value), a); +} + +template +void add(rapidjson::Value &arr, const Type &value, + rapidjson::Document::AllocatorType &a) +{ + assert(arr.IsArray()); + + arr.PushBack(pajlada::Serialize::get(value, a), a); +} + +bool checkJsonValue(const rapidjson::Value &obj, const char *key); + +template +bool getSafe(const rapidjson::Value &obj, const char *key, Type &out) +{ + if (!checkJsonValue(obj, key)) { - assert(obj.IsObject()); - - addMember(obj, key, pajlada::Serialize::get(value, a), a); + return false; } - template <> - inline void set(rapidjson::Value &obj, const char *key, - const rapidjson::Value &value, - rapidjson::Document::AllocatorType &a) - { - assert(obj.IsObject()); + bool error = false; + out = pajlada::Deserialize::get(obj[key], &error); - addMember(obj, key, const_cast(value), a); - } + return !error; +} - template - void set(rapidjson::Document &obj, const char *key, const Type &value) - { - assert(obj.IsObject()); +template +bool getSafe(const rapidjson::Value &value, Type &out) +{ + bool error = false; + out = pajlada::Deserialize::get(value, &error); - auto &a = obj.GetAllocator(); + return !error; +} - addMember(obj, key, pajlada::Serialize::get(value, a), a); - } +bool getSafeObject(rapidjson::Value &obj, const char *key, + rapidjson::Value &out); - template <> - inline void set(rapidjson::Document &obj, const char *key, - const rapidjson::Value &value) - { - assert(obj.IsObject()); - - auto &a = obj.GetAllocator(); - - addMember(obj, key, const_cast(value), a); - } - - template - void add(rapidjson::Value &arr, const Type &value, - rapidjson::Document::AllocatorType &a) - { - assert(arr.IsArray()); - - arr.PushBack(pajlada::Serialize::get(value, a), a); - } - - bool checkJsonValue(const rapidjson::Value &obj, const char *key); - - template - bool getSafe(const rapidjson::Value &obj, const char *key, Type &out) - { - if (!checkJsonValue(obj, key)) - { - return false; - } - - bool error = false; - out = pajlada::Deserialize::get(obj[key], &error); - - return !error; - } - - template - bool getSafe(const rapidjson::Value &value, Type &out) - { - bool error = false; - out = pajlada::Deserialize::get(value, &error); - - return !error; - } - - bool getSafeObject(rapidjson::Value &obj, const char *key, - rapidjson::Value &out); - - QString stringify(const rapidjson::Value &value); +QString stringify(const rapidjson::Value &value); } // namespace rj } // namespace chatterino diff --git a/src/util/RenameThread.hpp b/src/util/RenameThread.hpp index 5212c876..3fd062c4 100644 --- a/src/util/RenameThread.hpp +++ b/src/util/RenameThread.hpp @@ -11,7 +11,7 @@ namespace chatterino { #ifdef Q_OS_WIN namespace windows::detail { - void renameThread(void *hThread, const QString &name); +void renameThread(void *hThread, const QString &name); } // namespace windows::detail #endif diff --git a/src/util/Twitch.cpp b/src/util/Twitch.cpp index 3582e346..6f34502e 100644 --- a/src/util/Twitch.cpp +++ b/src/util/Twitch.cpp @@ -11,16 +11,16 @@ namespace chatterino { namespace { - const auto TWITCH_USER_LOGIN_PATTERN = R"(^[a-z0-9]\w{0,24}$)"; +const auto TWITCH_USER_LOGIN_PATTERN = R"(^[a-z0-9]\w{0,24}$)"; - // Remember to keep VALID_HELIX_COLORS up-to-date if a new color is implemented to keep naming for users consistent - const std::unordered_map HELIX_COLOR_REPLACEMENTS{ - {"blueviolet", "blue_violet"}, {"cadetblue", "cadet_blue"}, - {"dodgerblue", "dodger_blue"}, {"goldenrod", "golden_rod"}, - {"hotpink", "hot_pink"}, {"orangered", "orange_red"}, - {"seagreen", "sea_green"}, {"springgreen", "spring_green"}, - {"yellowgreen", "yellow_green"}, - }; +// Remember to keep VALID_HELIX_COLORS up-to-date if a new color is implemented to keep naming for users consistent +const std::unordered_map HELIX_COLOR_REPLACEMENTS{ + {"blueviolet", "blue_violet"}, {"cadetblue", "cadet_blue"}, + {"dodgerblue", "dodger_blue"}, {"goldenrod", "golden_rod"}, + {"hotpink", "hot_pink"}, {"orangered", "orange_red"}, + {"seagreen", "sea_green"}, {"springgreen", "spring_green"}, + {"yellowgreen", "yellow_green"}, +}; } // namespace diff --git a/src/widgets/DraggablePopup.cpp b/src/widgets/DraggablePopup.cpp index bc842ed3..5dd85651 100644 --- a/src/widgets/DraggablePopup.cpp +++ b/src/widgets/DraggablePopup.cpp @@ -13,23 +13,23 @@ namespace chatterino { namespace { #ifdef Q_OS_LINUX - FlagsEnum popupFlags{ - BaseWindow::Dialog, - BaseWindow::EnableCustomFrame, - }; - FlagsEnum popupFlagsCloseAutomatically{ - BaseWindow::Dialog, - BaseWindow::EnableCustomFrame, - }; +FlagsEnum popupFlags{ + BaseWindow::Dialog, + BaseWindow::EnableCustomFrame, +}; +FlagsEnum popupFlagsCloseAutomatically{ + BaseWindow::Dialog, + BaseWindow::EnableCustomFrame, +}; #else - FlagsEnum popupFlags{ - BaseWindow::EnableCustomFrame, - }; - FlagsEnum popupFlagsCloseAutomatically{ - BaseWindow::EnableCustomFrame, - BaseWindow::Frameless, - BaseWindow::FramelessDraggable, - }; +FlagsEnum popupFlags{ + BaseWindow::EnableCustomFrame, +}; +FlagsEnum popupFlagsCloseAutomatically{ + BaseWindow::EnableCustomFrame, + BaseWindow::Frameless, + BaseWindow::FramelessDraggable, +}; #endif } // namespace diff --git a/src/widgets/dialogs/ChannelFilterEditorDialog.cpp b/src/widgets/dialogs/ChannelFilterEditorDialog.cpp index 5d7d89af..6a56f740 100644 --- a/src/widgets/dialogs/ChannelFilterEditorDialog.cpp +++ b/src/widgets/dialogs/ChannelFilterEditorDialog.cpp @@ -8,14 +8,13 @@ namespace chatterino { namespace { - const QStringList friendlyBinaryOps = { - "and", "or", "+", "-", "*", "/", - "%", "equals", "not equals", "<", ">", "<=", - ">=", "contains", "starts with", "ends with", "(nothing)"}; - const QStringList realBinaryOps = { - "&&", "||", "+", "-", "*", "/", - "%", "==", "!=", "<", ">", "<=", - ">=", "contains", "startswith", "endswith", ""}; +const QStringList friendlyBinaryOps = { + "and", "or", "+", "-", "*", "/", + "%", "equals", "not equals", "<", ">", "<=", + ">=", "contains", "starts with", "ends with", "(nothing)"}; +const QStringList realBinaryOps = { + "&&", "||", "+", "-", "*", "/", "%", "==", "!=", + "<", ">", "<=", ">=", "contains", "startswith", "endswith", ""}; } // namespace ChannelFilterEditorDialog::ChannelFilterEditorDialog(QWidget *parent) diff --git a/src/widgets/dialogs/LoginDialog.cpp b/src/widgets/dialogs/LoginDialog.cpp index b60afd43..e13fe26b 100644 --- a/src/widgets/dialogs/LoginDialog.cpp +++ b/src/widgets/dialogs/LoginDialog.cpp @@ -25,53 +25,51 @@ namespace chatterino { namespace { - bool logInWithCredentials(QWidget *parent, const QString &userID, - const QString &username, const QString &clientID, - const QString &oauthToken) +bool logInWithCredentials(QWidget *parent, const QString &userID, + const QString &username, const QString &clientID, + const QString &oauthToken) +{ + QStringList errors; + + if (userID.isEmpty()) { - QStringList errors; - - if (userID.isEmpty()) - { - errors.append("Missing user ID"); - } - if (username.isEmpty()) - { - errors.append("Missing username"); - } - if (clientID.isEmpty()) - { - errors.append("Missing Client ID"); - } - if (oauthToken.isEmpty()) - { - errors.append("Missing OAuth Token"); - } - - if (errors.length() > 0) - { - QMessageBox messageBox(parent); - messageBox.setWindowTitle("Invalid account credentials"); - messageBox.setIcon(QMessageBox::Critical); - messageBox.setText(errors.join("
")); - messageBox.exec(); - return false; - } - - std::string basePath = "/accounts/uid" + userID.toStdString(); - pajlada::Settings::Setting::set(basePath + "/username", - username); - pajlada::Settings::Setting::set(basePath + "/userID", userID); - pajlada::Settings::Setting::set(basePath + "/clientID", - clientID); - pajlada::Settings::Setting::set(basePath + "/oauthToken", - oauthToken); - - getApp()->getAccounts()->twitch.reloadUsers(); - getApp()->getAccounts()->twitch.currentUsername = username; - getSettings()->requestSave(); - return true; + errors.append("Missing user ID"); } + if (username.isEmpty()) + { + errors.append("Missing username"); + } + if (clientID.isEmpty()) + { + errors.append("Missing Client ID"); + } + if (oauthToken.isEmpty()) + { + errors.append("Missing OAuth Token"); + } + + if (errors.length() > 0) + { + QMessageBox messageBox(parent); + messageBox.setWindowTitle("Invalid account credentials"); + messageBox.setIcon(QMessageBox::Critical); + messageBox.setText(errors.join("
")); + messageBox.exec(); + return false; + } + + std::string basePath = "/accounts/uid" + userID.toStdString(); + pajlada::Settings::Setting::set(basePath + "/username", username); + pajlada::Settings::Setting::set(basePath + "/userID", userID); + pajlada::Settings::Setting::set(basePath + "/clientID", clientID); + pajlada::Settings::Setting::set(basePath + "/oauthToken", + oauthToken); + + getApp()->getAccounts()->twitch.reloadUsers(); + getApp()->getAccounts()->twitch.currentUsername = username; + getSettings()->requestSave(); + return true; +} } // namespace diff --git a/src/widgets/helper/NotebookTab.cpp b/src/widgets/helper/NotebookTab.cpp index 9c839c88..f9261f55 100644 --- a/src/widgets/helper/NotebookTab.cpp +++ b/src/widgets/helper/NotebookTab.cpp @@ -33,52 +33,52 @@ namespace chatterino { namespace { - // Translates the given rectangle by an amount in the direction to appear like the tab is selected. - // For example, if location is Top, the rectangle will be translated in the negative Y direction, - // or "up" on the screen, by amount. - void translateRectForLocation(QRect &rect, NotebookTabLocation location, - int amount) +// Translates the given rectangle by an amount in the direction to appear like the tab is selected. +// For example, if location is Top, the rectangle will be translated in the negative Y direction, +// or "up" on the screen, by amount. +void translateRectForLocation(QRect &rect, NotebookTabLocation location, + int amount) +{ + switch (location) { - switch (location) - { - case NotebookTabLocation::Top: - rect.translate(0, -amount); - break; - case NotebookTabLocation::Left: - rect.translate(-amount, 0); - break; - case NotebookTabLocation::Right: - rect.translate(amount, 0); - break; - case NotebookTabLocation::Bottom: - rect.translate(0, amount); - break; - } + case NotebookTabLocation::Top: + rect.translate(0, -amount); + break; + case NotebookTabLocation::Left: + rect.translate(-amount, 0); + break; + case NotebookTabLocation::Right: + rect.translate(amount, 0); + break; + case NotebookTabLocation::Bottom: + rect.translate(0, amount); + break; } +} - float getCompactDivider(TabStyle tabStyle) +float getCompactDivider(TabStyle tabStyle) +{ + switch (tabStyle) { - switch (tabStyle) - { - case TabStyle::Compact: - return 1.5; - case TabStyle::Normal: - default: - return 1.0; - } + case TabStyle::Compact: + return 1.5; + case TabStyle::Normal: + default: + return 1.0; } +} - float getCompactReducer(TabStyle tabStyle) +float getCompactReducer(TabStyle tabStyle) +{ + switch (tabStyle) { - switch (tabStyle) - { - case TabStyle::Compact: - return 4.0; - case TabStyle::Normal: - default: - return 0.0; - } + case TabStyle::Compact: + return 4.0; + case TabStyle::Normal: + default: + return 0.0; } +} } // namespace NotebookTab::NotebookTab(Notebook *notebook) diff --git a/src/widgets/settingspages/HighlightingPage.cpp b/src/widgets/settingspages/HighlightingPage.cpp index a6459d9b..70504b5a 100644 --- a/src/widgets/settingspages/HighlightingPage.cpp +++ b/src/widgets/settingspages/HighlightingPage.cpp @@ -27,19 +27,19 @@ namespace chatterino { namespace { - // Add additional badges for highlights here - QList availableBadges = { - {"Broadcaster", "broadcaster"}, - {"Admin", "admin"}, - {"Staff", "staff"}, - {"Moderator", "moderator"}, - {"Verified", "partner"}, - {"VIP", "vip"}, - {"Founder", "founder"}, - {"Subscriber", "subscriber"}, - {"Predicted Blue", "predictions/blue-1,predictions/blue-2"}, - {"Predicted Pink", "predictions/pink-2,predictions/pink-1"}, - }; +// Add additional badges for highlights here +QList availableBadges = { + {"Broadcaster", "broadcaster"}, + {"Admin", "admin"}, + {"Staff", "staff"}, + {"Moderator", "moderator"}, + {"Verified", "partner"}, + {"VIP", "vip"}, + {"Founder", "founder"}, + {"Subscriber", "subscriber"}, + {"Predicted Blue", "predictions/blue-1,predictions/blue-2"}, + {"Predicted Pink", "predictions/pink-2,predictions/pink-1"}, +}; } // namespace HighlightingPage::HighlightingPage() diff --git a/src/widgets/splits/Split.cpp b/src/widgets/splits/Split.cpp index eabe7a5c..b83b81aa 100644 --- a/src/widgets/splits/Split.cpp +++ b/src/widgets/splits/Split.cpp @@ -183,28 +183,28 @@ QString formatChattersError(HelixGetChattersError error, const QString &message) namespace chatterino { namespace { - void showTutorialVideo(QWidget *parent, const QString &source, - const QString &title, const QString &description) - { - auto *window = new BasePopup( - { - BaseWindow::EnableCustomFrame, - BaseWindow::BoundsCheckOnShow, - }, - parent); - window->setWindowTitle("Chatterino - " + title); - window->setAttribute(Qt::WA_DeleteOnClose); - auto *layout = new QVBoxLayout(); - layout->addWidget(new QLabel(description)); - auto *label = new QLabel(window); - layout->addWidget(label); - auto *movie = new QMovie(label); - movie->setFileName(source); - label->setMovie(movie); - movie->start(); - window->getLayoutContainer()->setLayout(layout); - window->show(); - } +void showTutorialVideo(QWidget *parent, const QString &source, + const QString &title, const QString &description) +{ + auto *window = new BasePopup( + { + BaseWindow::EnableCustomFrame, + BaseWindow::BoundsCheckOnShow, + }, + parent); + window->setWindowTitle("Chatterino - " + title); + window->setAttribute(Qt::WA_DeleteOnClose); + auto *layout = new QVBoxLayout(); + layout->addWidget(new QLabel(description)); + auto *label = new QLabel(window); + layout->addWidget(label); + auto *movie = new QMovie(label); + movie->setFileName(source); + label->setMovie(movie); + movie->start(); + window->getLayoutContainer()->setLayout(layout); + window->show(); +} } // namespace pajlada::Signals::Signal Split::modifierStatusChanged;