Skip to content

Commit

Permalink
fix: replace defines with constexpr/const and use more absolute paths…
Browse files Browse the repository at this point in the history
… for includes (#5527)

bye bye nuuls
  • Loading branch information
Nerixyz authored Aug 3, 2024
1 parent 5ee5abf commit aed55ac
Show file tree
Hide file tree
Showing 83 changed files with 376 additions and 370 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@
- Dev: The running Qt version is now shown in the about page if it differs from the compiled version. (#5501)
- Dev: `FlagsEnum` is now `constexpr`. (#5510)
- Dev: Documented and added tests to RTL handling. (#5473)
- Dev: Refactored a few `#define`s into `const(expr)` and cleaned includes. (#5527)

## 2.5.1

Expand Down
2 changes: 1 addition & 1 deletion src/common/ChannelChatters.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#include "ChannelChatters.hpp"
#include "common/ChannelChatters.hpp"

#include "common/Channel.hpp"
#include "messages/Message.hpp"
Expand Down
33 changes: 13 additions & 20 deletions src/common/Common.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,39 +5,32 @@
#include <QWidget>

#include <memory>
#include <optional>
#include <string>

#define LINK_CHATTERINO_WIKI "https://wiki.chatterino.com"
#define LINK_CHATTERINO_DISCORD "https://discord.gg/7Y5AYhAK4z"
#define LINK_CHATTERINO_SOURCE "https://github.com/Chatterino/chatterino2"

namespace chatterino {

const inline auto TWITCH_PLAYER_URL =
QStringLiteral("https://player.twitch.tv/?channel=%1&parent=twitch.tv");
constexpr QStringView LINK_CHATTERINO_WIKI = u"https://wiki.chatterino.com";
constexpr QStringView LINK_CHATTERINO_DISCORD =
u"https://discord.gg/7Y5AYhAK4z";
constexpr QStringView LINK_CHATTERINO_SOURCE =
u"https://github.com/Chatterino/chatterino2";

constexpr QStringView TWITCH_PLAYER_URL =
u"https://player.twitch.tv/?channel=%1&parent=twitch.tv";

enum class HighlightState {
None,
Highlighted,
NewMessage,
};

const Qt::KeyboardModifiers showSplitOverlayModifiers =
constexpr Qt::KeyboardModifiers SHOW_SPLIT_OVERLAY_MODIFIERS =
Qt::ControlModifier | Qt::AltModifier;
const Qt::KeyboardModifiers showAddSplitRegions =
constexpr Qt::KeyboardModifiers SHOW_ADD_SPLIT_REGIONS =
Qt::ControlModifier | Qt::AltModifier;
const Qt::KeyboardModifiers showResizeHandlesModifiers = Qt::ControlModifier;

#ifndef ATTR_UNUSED
# ifdef Q_OS_WIN
# define ATTR_UNUSED
# else
# define ATTR_UNUSED __attribute__((unused))
# endif
#endif
constexpr Qt::KeyboardModifiers SHOW_RESIZE_HANDLES_MODIFIERS =
Qt::ControlModifier;

static const char *ANONYMOUS_USERNAME_LABEL ATTR_UNUSED = " - anonymous - ";
constexpr const char *ANONYMOUS_USERNAME_LABEL = " - anonymous - ";

template <typename T>
std::weak_ptr<T> weakOf(T *element)
Expand Down
19 changes: 10 additions & 9 deletions src/common/Credentials.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
#include <QJsonDocument>
#include <QJsonObject>
#include <QSaveFile>
#include <QStringBuilder>

#include <variant>

Expand All @@ -26,16 +27,16 @@
# endif
#endif

#define FORMAT_NAME \
([&] { \
assert(!provider.contains(":")); \
return QString("chatterino:%1:%2").arg(provider).arg(name_); \
})()

namespace {

using namespace chatterino;

QString formatName(const QString &provider, const QString &name)
{
assert(!provider.contains(":"));
return u"chatterino:" % provider % u':' % name;
}

bool useKeyring()
{
#ifdef NO_QTKEYCHAIN
Expand Down Expand Up @@ -184,7 +185,7 @@ void Credentials::get(const QString &provider, const QString &name_,
{
assertInGuiThread();

auto name = FORMAT_NAME;
auto name = formatName(provider, name_);

if (useKeyring())
{
Expand Down Expand Up @@ -219,7 +220,7 @@ void Credentials::set(const QString &provider, const QString &name_,
/// On linux, we try to use a keychain but show a message to disable it when it fails.
/// XXX: add said message

auto name = FORMAT_NAME;
auto name = formatName(provider, name_);

if (useKeyring())
{
Expand All @@ -242,7 +243,7 @@ void Credentials::erase(const QString &provider, const QString &name_)
{
assertInGuiThread();

auto name = FORMAT_NAME;
auto name = formatName(provider, name_);

if (useKeyring())
{
Expand Down
2 changes: 1 addition & 1 deletion src/common/Modes.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#include "Modes.hpp"
#include "common/Modes.hpp"

#include "util/CombinePath.hpp"

Expand Down
19 changes: 3 additions & 16 deletions src/common/Version.hpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
#pragma once

#include <QString>
#include <QtGlobal>

namespace chatterino {

/**
* Valid version formats, in order of latest to oldest
Expand All @@ -24,21 +25,7 @@
* - 2.4.0-alpha.2
* - 2.4.0-alpha
**/
#define CHATTERINO_VERSION "2.5.1"

#if defined(Q_OS_WIN)
# define CHATTERINO_OS "win"
#elif defined(Q_OS_MACOS)
# define CHATTERINO_OS "macos"
#elif defined(Q_OS_LINUX)
# define CHATTERINO_OS "linux"
#elif defined(Q_OS_FREEBSD)
# define CHATTERINO_OS "freebsd"
#else
# define CHATTERINO_OS "unknown"
#endif

namespace chatterino {
inline const QString CHATTERINO_VERSION = QStringLiteral("2.5.1");

class Version
{
Expand Down
2 changes: 1 addition & 1 deletion src/controllers/accounts/Account.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#include "Account.hpp"
#include "controllers/accounts/Account.hpp"

#include <tuple>

Expand Down
2 changes: 1 addition & 1 deletion src/controllers/accounts/AccountModel.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#include "AccountModel.hpp"
#include "controllers/accounts/AccountModel.hpp"

#include "controllers/accounts/Account.hpp"
#include "util/StandardItemHelper.hpp"
Expand Down
2 changes: 1 addition & 1 deletion src/controllers/commands/Command.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#include "Command.hpp"
#include "controllers/commands/Command.hpp"

namespace chatterino {

Expand Down
2 changes: 1 addition & 1 deletion src/controllers/highlights/HighlightBadge.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#include "HighlightBadge.hpp"
#include "controllers/highlights/HighlightBadge.hpp"

#include "messages/SharedMessageBuilder.hpp"
#include "providers/twitch/TwitchBadge.hpp"
Expand Down
2 changes: 1 addition & 1 deletion src/controllers/notifications/NotificationModel.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#include "NotificationModel.hpp"
#include "controllers/notifications/NotificationModel.hpp"

#include "Application.hpp"
#include "singletons/Settings.hpp"
Expand Down
2 changes: 1 addition & 1 deletion src/controllers/pings/MutedChannelModel.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#include "MutedChannelModel.hpp"
#include "controllers/pings/MutedChannelModel.hpp"

#include "Application.hpp"
#include "singletons/Settings.hpp"
Expand Down
2 changes: 1 addition & 1 deletion src/debug/Benchmark.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#include "Benchmark.hpp"
#include "debug/Benchmark.hpp"

#include "common/QLogging.hpp"

Expand Down
2 changes: 1 addition & 1 deletion src/messages/Emote.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#include "Emote.hpp"
#include "messages/Emote.hpp"

#include <unordered_map>

Expand Down
2 changes: 1 addition & 1 deletion src/messages/MessageBuilder.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#include "MessageBuilder.hpp"
#include "messages/MessageBuilder.hpp"

#include "Application.hpp"
#include "common/IrcColors.hpp"
Expand Down
2 changes: 1 addition & 1 deletion src/messages/MessageColor.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#include "MessageColor.hpp"
#include "messages/MessageColor.hpp"

#include "singletons/Theme.hpp"

Expand Down
6 changes: 0 additions & 6 deletions src/messages/layouts/MessageLayout.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,6 @@
#include <QtGlobal>
#include <QThread>

#define MARGIN_LEFT (int)(8 * this->scale)
#define MARGIN_RIGHT (int)(8 * this->scale)
#define MARGIN_TOP (int)(4 * this->scale)
#define MARGIN_BOTTOM (int)(4 * this->scale)
#define COMPACT_EMOTES_OFFSET 6

namespace chatterino {

namespace {
Expand Down
21 changes: 13 additions & 8 deletions src/messages/layouts/MessageLayoutContainer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,17 @@

#include <optional>

#define COMPACT_EMOTES_OFFSET 4
#define MAX_UNCOLLAPSED_LINES \
(getSettings()->collpseMessagesMinLines.getValue())

namespace {

constexpr const QMargins MARGIN{8, 4, 8, 4};
using namespace chatterino;

constexpr QMargins MARGIN{8, 4, 8, 4};
constexpr int COMPACT_EMOTES_OFFSET = 4;

int maxUncollapsedLines()
{
return getSettings()->collpseMessagesMinLines.getValue();
}

} // namespace

Expand Down Expand Up @@ -208,7 +212,7 @@ void MessageLayoutContainer::breakLine()
this->lineStart_ = this->elements_.size();
// this->currentX = (int)(this->scale * 8);

if (this->canCollapse() && this->line_ + 1 >= MAX_UNCOLLAPSED_LINES)
if (this->canCollapse() && this->line_ + 1 >= maxUncollapsedLines())
{
this->canAddMessages_ = false;
return;
Expand Down Expand Up @@ -568,8 +572,9 @@ int MessageLayoutContainer::remainingWidth() const
{
return (this->width_ - int(MARGIN.left() * this->scale_) -
int(MARGIN.right() * this->scale_) -
(this->line_ + 1 == MAX_UNCOLLAPSED_LINES ? this->dotdotdotWidth_
: 0)) -
(static_cast<int>(this->line_ + 1) == maxUncollapsedLines()
? this->dotdotdotWidth_
: 0)) -
this->currentX_;
}

Expand Down
2 changes: 1 addition & 1 deletion src/messages/search/RegexPredicate.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#include "RegexPredicate.hpp"
#include "messages/search/RegexPredicate.hpp"

#include "messages/Message.hpp"

Expand Down
2 changes: 1 addition & 1 deletion src/messages/search/RegexPredicate.hpp
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
#pragma once

#include "messages/search/MessagePredicate.hpp"
#include "QRegularExpression"

#include <QRegularExpression>
#include <QString>

namespace chatterino {
Expand Down
2 changes: 1 addition & 1 deletion src/providers/IvrApi.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#include "IvrApi.hpp"
#include "providers/IvrApi.hpp"

#include "common/network/NetworkResult.hpp"
#include "common/QLogging.hpp"
Expand Down
4 changes: 1 addition & 3 deletions src/providers/IvrApi.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -64,9 +64,7 @@ struct IvrEmote {
: code(root.value("code").toString())
, id(root.value("id").toString())
, setId(root.value("setID").toString())
, url(QString(TWITCH_EMOTE_TEMPLATE)
.replace("{id}", this->id)
.replace("{scale}", "3.0"))
, url(TWITCH_EMOTE_TEMPLATE.arg(this->id, u"3.0"))
, emoteType(root.value("type").toString())
, imageType(root.value("assetType").toString())
{
Expand Down
2 changes: 1 addition & 1 deletion src/providers/irc/AbstractIrcServer.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#include "AbstractIrcServer.hpp"
#include "providers/irc/AbstractIrcServer.hpp"

#include "common/Channel.hpp"
#include "common/QLogging.hpp"
Expand Down
2 changes: 1 addition & 1 deletion src/providers/irc/Irc2.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#include "Irc2.hpp"
#include "providers/irc/Irc2.hpp"

#include "Application.hpp"
#include "common/Credentials.hpp"
Expand Down
2 changes: 1 addition & 1 deletion src/providers/irc/IrcAccount.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#include "IrcAccount.hpp"
#include "providers/irc/IrcAccount.hpp"

// namespace chatterino {
//
Expand Down
2 changes: 1 addition & 1 deletion src/providers/irc/IrcChannel2.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#include "IrcChannel2.hpp"
#include "providers/irc/IrcChannel2.hpp"

#include "common/Channel.hpp"
#include "debug/AssertInGuiThread.hpp"
Expand Down
2 changes: 1 addition & 1 deletion src/providers/irc/IrcCommands.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#include "IrcCommands.hpp"
#include "providers/irc/IrcCommands.hpp"

#include "messages/MessageBuilder.hpp"
#include "providers/irc/IrcChannel2.hpp"
Expand Down
4 changes: 2 additions & 2 deletions src/providers/irc/IrcConnection2.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#include "IrcConnection2.hpp"
#include "providers/irc/IrcConnection2.hpp"

#include "common/QLogging.hpp"
#include "common/Version.hpp"
Expand All @@ -11,7 +11,7 @@ namespace chatterino {

namespace {

const auto payload = QString("chatterino/" CHATTERINO_VERSION);
const auto payload = "chatterino/" + CHATTERINO_VERSION;

} // namespace

Expand Down
2 changes: 1 addition & 1 deletion src/providers/irc/IrcServer.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#include "IrcServer.hpp"
#include "providers/irc/IrcServer.hpp"

#include "Application.hpp"
#include "common/QLogging.hpp"
Expand Down
Loading

0 comments on commit aed55ac

Please sign in to comment.