fix: don't indent inner namespaces (#6235)

This commit is contained in:
pajlada
2025-05-25 12:28:14 +02:00
committed by GitHub
parent 84c0b39fde
commit 8acca1c241
39 changed files with 934 additions and 951 deletions
+1 -1
View File
@@ -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
+2 -2
View File
@@ -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
+39 -44
View File
@@ -40,8 +40,8 @@
namespace chatterino {
namespace {
void installCustomPalette()
{
void installCustomPalette()
{
// borrowed from
// https://stackoverflow.com/questions/15035767/is-the-qt-5-dark-fusion-theme-available-for-windows
auto dark = QApplication::palette();
@@ -63,22 +63,20 @@ namespace {
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::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::Text, QColor(127, 127, 127));
dark.setColor(QPalette::Disabled, QPalette::WindowText,
QColor(127, 127, 127));
QApplication::setPalette(dark);
}
}
void initQt()
{
void initQt()
{
// set up the QApplication flags
QApplication::setAttribute(Qt::AA_Use96Dpi, true);
@@ -98,39 +96,38 @@ namespace {
#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);
QApplication::setAttribute(Qt::AA_DontShowShortcutsInContextMenus, false);
#endif
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)
{
void createRunningFile(const QString &path)
{
QFile runningFile(path);
runningFile.open(QIODevice::WriteOnly | QIODevice::Truncate);
runningFile.flush();
runningFile.close();
}
}
void removeRunningFile(const QString &path)
{
void removeRunningFile(const QString &path)
{
QFile::remove(path);
}
}
std::chrono::steady_clock::time_point signalsInitTime;
std::chrono::steady_clock::time_point signalsInitTime;
[[noreturn]] void handleSignal(int signum)
{
[[noreturn]] void handleSignal(int signum)
{
using namespace std::chrono_literals;
if (std::chrono::steady_clock::now() - signalsInitTime > 30s &&
@@ -164,12 +161,12 @@ namespace {
}
std::_Exit(signum);
}
}
// We want to restart Chatterino when it crashes and the setting is set to
// true.
void initSignalHandler()
{
// 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();
@@ -179,23 +176,21 @@ namespace {
#if defined(Q_OS_UNIX)
auto *sigintHandler = new UnixSignalHandler(SIGINT);
QObject::connect(sigintHandler, &UnixSignalHandler::signalFired, [] {
qCInfo(chatterinoApp)
<< "Received SIGINT, request application quit";
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";
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))
{
@@ -210,12 +205,12 @@ namespace {
}
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"))
{
@@ -242,7 +237,7 @@ namespace {
}
}
qCDebug(chatterinoApp) << "Deleted" << deletedCount << "crashdumps";
}
}
} // namespace
void runGui(QApplication &a, const Paths &paths, Settings &settings,
+13 -13
View File
@@ -10,9 +10,9 @@ namespace chatterino {
namespace {
template <typename T>
void warn(const char *envName, const QString &envString, T defaultValue)
{
template <typename T>
void warn(const char *envName, const QString &envString, T defaultValue)
{
const auto typeName = QString::fromStdString(
std::string(type_name<decltype(defaultValue)>()));
@@ -24,10 +24,10 @@ namespace {
.arg(envName)
.arg(typeName)
.arg(defaultValue);
}
}
std::optional<QString> readOptionalStringEnv(const char *envName)
{
std::optional<QString> readOptionalStringEnv(const char *envName)
{
auto envString = qEnvironmentVariable(envName);
if (!envString.isEmpty())
{
@@ -35,10 +35,10 @@ namespace {
}
return std::nullopt;
}
}
uint16_t readPortEnv(const char *envName, uint16_t defaultValue)
{
uint16_t readPortEnv(const char *envName, uint16_t defaultValue)
{
auto envString = qEnvironmentVariable(envName);
if (!envString.isEmpty())
{
@@ -53,10 +53,10 @@ namespace {
}
return defaultValue;
}
}
bool readBoolEnv(const char *envName, bool defaultValue)
{
bool readBoolEnv(const char *envName, bool defaultValue)
{
auto envString = qEnvironmentVariable(envName);
if (!envString.isEmpty())
{
@@ -64,7 +64,7 @@ namespace {
}
return defaultValue;
}
}
} // namespace
+18 -18
View File
@@ -11,26 +11,26 @@ 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 <typename T>
T loadNodes(const QJsonObject &obj)
{
template <typename T>
T loadNodes(const QJsonObject &obj)
{
static_assert("loadNodes must be called with the SplitNodeDescriptor "
"or ContainerNodeDescriptor type");
}
}
template <>
SplitNodeDescriptor loadNodes(const QJsonObject &root)
{
template <>
SplitNodeDescriptor loadNodes(const QJsonObject &root)
{
SplitNodeDescriptor descriptor;
descriptor.flexH_ = root.value("flexh").toDouble(1.0);
@@ -41,11 +41,11 @@ namespace {
SplitDescriptor::loadFromJSON(descriptor, root, data);
return descriptor;
}
}
template <>
ContainerNodeDescriptor loadNodes(const QJsonObject &root)
{
template <>
ContainerNodeDescriptor loadNodes(const QJsonObject &root)
{
ContainerNodeDescriptor descriptor;
descriptor.flexH_ = root.value("flexh").toDouble(1.0);
@@ -71,10 +71,10 @@ namespace {
}
return descriptor;
}
}
const QList<QUuid> loadFilters(QJsonValue val)
{
const QList<QUuid> loadFilters(QJsonValue val)
{
QList<QUuid> filterIds;
if (!val.isUndefined())
@@ -88,7 +88,7 @@ namespace {
}
return filterIds;
}
}
} // namespace
@@ -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
@@ -8,7 +8,7 @@
namespace chatterino {
namespace completion {
class Source;
class Source;
} // namespace completion
/// @brief Represents the kind of completion occurring
@@ -11,8 +11,8 @@ namespace chatterino::completion {
namespace {
void addCommand(const QString &command, std::vector<CommandItem> &out)
{
void addCommand(const QString &command, std::vector<CommandItem> &out)
{
if (command.startsWith('/') || command.startsWith('.'))
{
out.push_back({
@@ -27,7 +27,7 @@ namespace {
.prefix = "",
});
}
}
}
} // namespace
@@ -17,9 +17,9 @@ namespace chatterino::completion {
namespace {
void addEmotes(std::vector<EmoteItem> &out, const EmoteMap &map,
void addEmotes(std::vector<EmoteItem> &out, const EmoteMap &map,
const QString &providerName)
{
{
for (auto &&emote : map)
{
out.push_back({.emote = emote.second,
@@ -29,11 +29,10 @@ namespace {
.providerName = providerName,
.isEmoji = false});
}
}
}
void addEmojis(std::vector<EmoteItem> &out,
const std::vector<EmojiPtr> &map)
{
void addEmojis(std::vector<EmoteItem> &out, const std::vector<EmojiPtr> &map)
{
for (const auto &emoji : map)
{
for (auto &&shortCode : emoji->shortCodes)
@@ -47,7 +46,7 @@ namespace {
.isEmoji = true});
}
};
}
}
} // namespace
@@ -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)
{
return size;
}
return std::min(size, limit);
}
}
} // namespace
@@ -11,7 +11,7 @@
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.
*
@@ -25,8 +25,8 @@ namespace {
* @return How different the emote is from query. Values in the range [-10,
* \infty].
*/
int costOfEmote(QStringView query, QStringView emote, bool prioritizeUpper)
{
int costOfEmote(QStringView query, QStringView emote, bool prioritizeUpper)
{
int score = 0;
if (prioritizeUpper)
@@ -60,17 +60,16 @@ namespace {
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(
// 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<EmoteItem> &items, std::vector<EmoteItem> &output,
QStringView query, bool ignoreColonForCost,
const std::function<bool(EmoteItem, Qt::CaseSensitivity)>
&matchingFunction)
{
const std::function<bool(EmoteItem, Qt::CaseSensitivity)> &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
@@ -153,7 +152,7 @@ namespace {
return costA < costB;
});
}
}
} // namespace
void SmartEmoteStrategy::apply(const std::vector<EmoteItem> &items,
@@ -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
@@ -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 <>
+1 -1
View File
@@ -37,7 +37,7 @@ struct ChannelPointReward;
struct TwitchEmoteOccurrence;
namespace linkparser {
struct Parsed;
struct Parsed;
} // namespace linkparser
struct SystemMessageTag {
+4 -4
View File
@@ -26,9 +26,9 @@ using namespace literals;
namespace {
// Computes the bounding box for the given vector of images
QSizeF getBoundingBoxSize(const std::vector<ImagePtr> &images)
{
// Computes the bounding box for the given vector of images
QSizeF getBoundingBoxSize(const std::vector<ImagePtr> &images)
{
qreal width = 0;
qreal height = 0;
for (const auto &img : images)
@@ -39,7 +39,7 @@ namespace {
}
return {width, height};
}
}
} // namespace
+3 -3
View File
@@ -23,15 +23,15 @@ namespace chatterino {
namespace {
QColor blendColors(const QColor &base, const QColor &apply)
{
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)
+1 -1
View File
@@ -24,7 +24,7 @@ struct BttvLiveUpdateEmoteRemoveMessage;
namespace bttv::detail {
EmoteMap parseChannelEmotes(const QJsonObject &jsonRoot,
EmoteMap parseChannelEmotes(const QJsonObject &jsonRoot,
const QString &channelDisplayName);
} // namespace bttv::detail
+3 -5
View File
@@ -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
+1 -1
View File
@@ -11,7 +11,7 @@ namespace chatterino {
namespace {
const auto payload = "chatterino/" + CHATTERINO_VERSION;
const auto payload = "chatterino/" + CHATTERINO_VERSION;
} // namespace
@@ -28,9 +28,9 @@ struct BasicPubSubConfig : public websocketpp::config::asio_tls_client {
};
namespace liveupdates {
using WebsocketClient = websocketpp::client<chatterino::BasicPubSubConfig>;
using WebsocketHandle = websocketpp::connection_hdl;
using WebsocketErrorCode = websocketpp::lib::error_code;
using WebsocketClient = websocketpp::client<chatterino::BasicPubSubConfig>;
using WebsocketHandle = websocketpp::connection_hdl;
using WebsocketErrorCode = websocketpp::lib::error_code;
} // namespace liveupdates
} // namespace chatterino
+4 -4
View File
@@ -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<SeventvEmoteSetFlag>;
namespace seventv::detail {
EmoteMap parseEmotes(const QJsonArray &emoteSetEmotes, bool isGlobal);
EmoteMap parseEmotes(const QJsonArray &emoteSetEmotes, bool isGlobal);
} // namespace seventv::detail
+7 -7
View File
@@ -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;
+16 -17
View File
@@ -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(
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(
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(
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(
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(
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());
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)
+4 -4
View File
@@ -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;
+6 -6
View File
@@ -200,13 +200,13 @@ std::string &getNmQueueName(const Paths &paths)
namespace nm::client {
void sendMessage(const QByteArray &array)
{
void sendMessage(const QByteArray &array)
{
ipc::sendMessage("chatterino_gui", array);
}
}
void writeToCout(const QByteArray &array)
{
void writeToCout(const QByteArray &array)
{
const auto *data = array.data();
auto size = uint32_t(array.size());
@@ -215,7 +215,7 @@ namespace nm::client {
std::cout.write(reinterpret_cast<char *>(&size), 4);
std::cout.write(data, size);
std::cout.flush();
}
}
} // namespace nm::client
+2 -2
View File
@@ -37,8 +37,8 @@ Atomic<std::optional<QString>> &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
+3 -3
View File
@@ -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())
{
out.append(' ');
}
out.append(QString::number(count));
out.append(suffix);
}
}
} // namespace
+9 -9
View File
@@ -33,17 +33,17 @@ 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())
{
startPos++;
}
return startPos - 1;
}
}
bool matchesIgnorePlural(QStringView word, const QString &expected)
{
bool matchesIgnorePlural(QStringView word, const QString &expected)
{
if (!word.startsWith(expected))
{
return false;
@@ -54,11 +54,11 @@ namespace helpers::detail {
}
return word.length() == expected.length() + 1 &&
word.at(word.length() - 1).toLatin1() == 's';
}
}
std::pair<uint64_t, bool> findUnitMultiplierToSec(QStringView view,
std::pair<uint64_t, bool> findUnitMultiplierToSec(QStringView view,
SizeType &pos)
{
{
// Step 1. find end of unit
auto startIdx = pos;
auto endIdx = view.length();
@@ -130,7 +130,7 @@ namespace helpers::detail {
break;
}
return std::make_pair(0, false);
}
}
} // namespace helpers::detail
using namespace helpers::detail;
+7 -7
View File
@@ -18,9 +18,9 @@ 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().
*
@@ -28,18 +28,18 @@ namespace helpers::detail {
* @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);
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);
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).
*
@@ -54,7 +54,7 @@ namespace helpers::detail {
* if it's a valid unit, undefined otherwise.
* @return (multiplier, ok)
*/
std::pair<uint64_t, bool> findUnitMultiplierToSec(QStringView view,
std::pair<uint64_t, bool> findUnitMultiplierToSec(QStringView view,
SizeType &pos);
} // namespace helpers::detail
+15 -17
View File
@@ -5,32 +5,30 @@
namespace chatterino {
namespace rj {
void addMember(rapidjson::Value &obj, const char *key,
rapidjson::Value &&value,
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,
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)
{
QString stringify(const rapidjson::Value &value)
{
rapidjson::StringBuffer buffer;
rapidjson::Writer<rapidjson::StringBuffer> writer(buffer);
value.Accept(writer);
return buffer.GetString();
}
}
bool getSafeObject(rapidjson::Value &obj, const char *key,
bool getSafeObject(rapidjson::Value &obj, const char *key,
rapidjson::Value &out)
{
{
if (!checkJsonValue(obj, key))
{
return false;
@@ -38,12 +36,12 @@ namespace rj {
out = obj[key].Move();
return true;
}
}
bool checkJsonValue(const rapidjson::Value &obj, const char *key)
{
bool checkJsonValue(const rapidjson::Value &obj, const char *key)
{
return obj.IsObject() && !obj.IsNull() && obj.HasMember(key);
}
}
} // namespace rj
} // namespace chatterino
+33 -35
View File
@@ -11,67 +11,65 @@
namespace chatterino {
namespace rj {
void addMember(rapidjson::Value &obj, const char *key,
rapidjson::Value &&value,
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,
void addMember(rapidjson::Value &obj, const char *key, rapidjson::Value &value,
rapidjson::Document::AllocatorType &a);
template <typename Type>
void set(rapidjson::Value &obj, const char *key, const Type &value,
template <typename Type>
void set(rapidjson::Value &obj, const char *key, const Type &value,
rapidjson::Document::AllocatorType &a)
{
{
assert(obj.IsObject());
addMember(obj, key, pajlada::Serialize<Type>::get(value, a), a);
}
}
template <>
inline void set(rapidjson::Value &obj, const char *key,
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<rapidjson::Value &>(value), a);
}
}
template <typename Type>
void set(rapidjson::Document &obj, const char *key, const Type &value)
{
template <typename Type>
void set(rapidjson::Document &obj, const char *key, const Type &value)
{
assert(obj.IsObject());
auto &a = obj.GetAllocator();
addMember(obj, key, pajlada::Serialize<Type>::get(value, a), a);
}
}
template <>
inline void set(rapidjson::Document &obj, const char *key,
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<rapidjson::Value &>(value), a);
}
}
template <typename Type>
void add(rapidjson::Value &arr, const Type &value,
template <typename Type>
void add(rapidjson::Value &arr, const Type &value,
rapidjson::Document::AllocatorType &a)
{
{
assert(arr.IsArray());
arr.PushBack(pajlada::Serialize<Type>::get(value, a), a);
}
}
bool checkJsonValue(const rapidjson::Value &obj, const char *key);
bool checkJsonValue(const rapidjson::Value &obj, const char *key);
template <typename Type>
bool getSafe(const rapidjson::Value &obj, const char *key, Type &out)
{
template <typename Type>
bool getSafe(const rapidjson::Value &obj, const char *key, Type &out)
{
if (!checkJsonValue(obj, key))
{
return false;
@@ -81,21 +79,21 @@ namespace rj {
out = pajlada::Deserialize<Type>::get(obj[key], &error);
return !error;
}
}
template <typename Type>
bool getSafe(const rapidjson::Value &value, Type &out)
{
template <typename Type>
bool getSafe(const rapidjson::Value &value, Type &out)
{
bool error = false;
out = pajlada::Deserialize<Type>::get(value, &error);
return !error;
}
}
bool getSafeObject(rapidjson::Value &obj, const char *key,
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
+1 -1
View File
@@ -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
+4 -4
View File
@@ -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<QString, QString> HELIX_COLOR_REPLACEMENTS{
// 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<QString, QString> 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
+8 -8
View File
@@ -13,23 +13,23 @@ namespace chatterino {
namespace {
#ifdef Q_OS_LINUX
FlagsEnum<BaseWindow::Flags> popupFlags{
FlagsEnum<BaseWindow::Flags> popupFlags{
BaseWindow::Dialog,
BaseWindow::EnableCustomFrame,
};
FlagsEnum<BaseWindow::Flags> popupFlagsCloseAutomatically{
};
FlagsEnum<BaseWindow::Flags> popupFlagsCloseAutomatically{
BaseWindow::Dialog,
BaseWindow::EnableCustomFrame,
};
};
#else
FlagsEnum<BaseWindow::Flags> popupFlags{
FlagsEnum<BaseWindow::Flags> popupFlags{
BaseWindow::EnableCustomFrame,
};
FlagsEnum<BaseWindow::Flags> popupFlagsCloseAutomatically{
};
FlagsEnum<BaseWindow::Flags> popupFlagsCloseAutomatically{
BaseWindow::EnableCustomFrame,
BaseWindow::Frameless,
BaseWindow::FramelessDraggable,
};
};
#endif
} // namespace
@@ -8,14 +8,13 @@
namespace chatterino {
namespace {
const QStringList friendlyBinaryOps = {
const QStringList friendlyBinaryOps = {
"and", "or", "+", "-", "*", "/",
"%", "equals", "not equals", "<", ">", "<=",
">=", "contains", "starts with", "ends with", "(nothing)"};
const QStringList realBinaryOps = {
"&&", "||", "+", "-", "*", "/",
"%", "==", "!=", "<", ">", "<=",
">=", "contains", "startswith", "endswith", ""};
const QStringList realBinaryOps = {
"&&", "||", "+", "-", "*", "/", "%", "==", "!=",
"<", ">", "<=", ">=", "contains", "startswith", "endswith", ""};
} // namespace
ChannelFilterEditorDialog::ChannelFilterEditorDialog(QWidget *parent)
+5 -7
View File
@@ -25,10 +25,10 @@ namespace chatterino {
namespace {
bool logInWithCredentials(QWidget *parent, const QString &userID,
bool logInWithCredentials(QWidget *parent, const QString &userID,
const QString &username, const QString &clientID,
const QString &oauthToken)
{
{
QStringList errors;
if (userID.isEmpty())
@@ -59,11 +59,9 @@ namespace {
}
std::string basePath = "/accounts/uid" + userID.toStdString();
pajlada::Settings::Setting<QString>::set(basePath + "/username",
username);
pajlada::Settings::Setting<QString>::set(basePath + "/username", username);
pajlada::Settings::Setting<QString>::set(basePath + "/userID", userID);
pajlada::Settings::Setting<QString>::set(basePath + "/clientID",
clientID);
pajlada::Settings::Setting<QString>::set(basePath + "/clientID", clientID);
pajlada::Settings::Setting<QString>::set(basePath + "/oauthToken",
oauthToken);
@@ -71,7 +69,7 @@ namespace {
getApp()->getAccounts()->twitch.currentUsername = username;
getSettings()->requestSave();
return true;
}
}
} // namespace
+12 -12
View File
@@ -33,12 +33,12 @@
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,
// 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)
{
case NotebookTabLocation::Top:
@@ -54,10 +54,10 @@ namespace {
rect.translate(0, amount);
break;
}
}
}
float getCompactDivider(TabStyle tabStyle)
{
float getCompactDivider(TabStyle tabStyle)
{
switch (tabStyle)
{
case TabStyle::Compact:
@@ -66,10 +66,10 @@ namespace {
default:
return 1.0;
}
}
}
float getCompactReducer(TabStyle tabStyle)
{
float getCompactReducer(TabStyle tabStyle)
{
switch (tabStyle)
{
case TabStyle::Compact:
@@ -78,7 +78,7 @@ namespace {
default:
return 0.0;
}
}
}
} // namespace
NotebookTab::NotebookTab(Notebook *notebook)
@@ -27,8 +27,8 @@
namespace chatterino {
namespace {
// Add additional badges for highlights here
QList<DisplayBadge> availableBadges = {
// Add additional badges for highlights here
QList<DisplayBadge> availableBadges = {
{"Broadcaster", "broadcaster"},
{"Admin", "admin"},
{"Staff", "staff"},
@@ -39,7 +39,7 @@ namespace {
{"Subscriber", "subscriber"},
{"Predicted Blue", "predictions/blue-1,predictions/blue-2"},
{"Predicted Pink", "predictions/pink-2,predictions/pink-1"},
};
};
} // namespace
HighlightingPage::HighlightingPage()
+3 -3
View File
@@ -183,9 +183,9 @@ QString formatChattersError(HelixGetChattersError error, const QString &message)
namespace chatterino {
namespace {
void showTutorialVideo(QWidget *parent, const QString &source,
void showTutorialVideo(QWidget *parent, const QString &source,
const QString &title, const QString &description)
{
{
auto *window = new BasePopup(
{
BaseWindow::EnableCustomFrame,
@@ -204,7 +204,7 @@ namespace {
movie->start();
window->getLayoutContainer()->setLayout(layout);
window->show();
}
}
} // namespace
pajlada::Signals::Signal<Qt::KeyboardModifiers> Split::modifierStatusChanged;