fix: replace defines with constexpr/const and use more absolute paths for includes (#5527)

bye bye nuuls
This commit is contained in:
nerix
2024-08-03 12:00:58 +02:00
committed by GitHub
parent 5ee5abf5b2
commit aed55ac1ba
83 changed files with 386 additions and 380 deletions
+87 -85
View File
@@ -38,101 +38,104 @@
#include <QNetworkAccessManager>
#include <QNetworkReply>
#include <QPointer>
#include <QStringBuilder>
const QString TEXT_FOLLOWERS("Followers: %1");
const QString TEXT_CREATED("Created: %1");
const QString TEXT_TITLE("%1's Usercard - #%2");
#define TEXT_USER_ID "ID: "
#define TEXT_UNAVAILABLE "(not available)"
namespace chatterino {
namespace {
Label *addCopyableLabel(LayoutCreator<QHBoxLayout> box, const char *tooltip,
Button **copyButton = nullptr)
constexpr QStringView TEXT_FOLLOWERS = u"Followers: %1";
constexpr QStringView TEXT_CREATED = u"Created: %1";
constexpr QStringView TEXT_TITLE = u"%1's Usercard - #%2";
constexpr QStringView TEXT_USER_ID = u"ID: ";
constexpr QStringView TEXT_UNAVAILABLE = u"(not available)";
using namespace chatterino;
Label *addCopyableLabel(LayoutCreator<QHBoxLayout> box, const char *tooltip,
Button **copyButton = nullptr)
{
auto label = box.emplace<Label>();
auto button = box.emplace<Button>();
if (copyButton != nullptr)
{
auto label = box.emplace<Label>();
auto button = box.emplace<Button>();
if (copyButton != nullptr)
{
button.assign(copyButton);
}
button->setPixmap(getApp()->getThemes()->buttons.copy);
button->setScaleIndependantSize(18, 18);
button->setDim(Button::Dim::Lots);
button->setToolTip(tooltip);
QObject::connect(
button.getElement(), &Button::leftClicked,
[label = label.getElement()] {
auto copyText = label->property("copy-text").toString();
button.assign(copyButton);
}
button->setPixmap(getApp()->getThemes()->buttons.copy);
button->setScaleIndependantSize(18, 18);
button->setDim(Button::Dim::Lots);
button->setToolTip(tooltip);
QObject::connect(
button.getElement(), &Button::leftClicked,
[label = label.getElement()] {
auto copyText = label->property("copy-text").toString();
crossPlatformCopy(copyText.isEmpty() ? label->getText()
: copyText);
});
crossPlatformCopy(copyText.isEmpty() ? label->getText() : copyText);
});
return label.getElement();
};
return label.getElement();
};
bool checkMessageUserName(const QString &userName, MessagePtr message)
bool checkMessageUserName(const QString &userName, MessagePtr message)
{
if (message->flags.has(MessageFlag::Whisper))
{
if (message->flags.has(MessageFlag::Whisper))
{
return false;
}
bool isSubscription = message->flags.has(MessageFlag::Subscription) &&
message->loginName.isEmpty() &&
message->messageText.split(" ").at(0).compare(
userName, Qt::CaseInsensitive) == 0;
bool isModAction =
message->timeoutUser.compare(userName, Qt::CaseInsensitive) == 0;
bool isSelectedUser =
message->loginName.compare(userName, Qt::CaseInsensitive) == 0;
return (isSubscription || isModAction || isSelectedUser);
return false;
}
ChannelPtr filterMessages(const QString &userName, ChannelPtr channel)
bool isSubscription = message->flags.has(MessageFlag::Subscription) &&
message->loginName.isEmpty() &&
message->messageText.split(" ").at(0).compare(
userName, Qt::CaseInsensitive) == 0;
bool isModAction =
message->timeoutUser.compare(userName, Qt::CaseInsensitive) == 0;
bool isSelectedUser =
message->loginName.compare(userName, Qt::CaseInsensitive) == 0;
return (isSubscription || isModAction || isSelectedUser);
}
ChannelPtr filterMessages(const QString &userName, ChannelPtr channel)
{
LimitedQueueSnapshot<MessagePtr> snapshot = channel->getMessageSnapshot();
ChannelPtr channelPtr;
if (channel->isTwitchChannel())
{
LimitedQueueSnapshot<MessagePtr> snapshot =
channel->getMessageSnapshot();
ChannelPtr channelPtr;
if (channel->isTwitchChannel())
{
channelPtr = std::make_shared<TwitchChannel>(channel->getName());
}
else
{
channelPtr = std::make_shared<Channel>(channel->getName(),
Channel::Type::None);
}
for (size_t i = 0; i < snapshot.size(); i++)
{
MessagePtr message = snapshot[i];
if (checkMessageUserName(userName, message))
{
channelPtr->addMessage(message, MessageContext::Repost);
}
}
return channelPtr;
};
const auto borderColor = QColor(255, 255, 255, 80);
int calculateTimeoutDuration(TimeoutButton timeout)
{
static const QMap<QString, int> durations{
{"s", 1}, {"m", 60}, {"h", 3600}, {"d", 86400}, {"w", 604800},
};
return timeout.second * durations[timeout.first];
channelPtr = std::make_shared<TwitchChannel>(channel->getName());
}
else
{
channelPtr =
std::make_shared<Channel>(channel->getName(), Channel::Type::None);
}
for (size_t i = 0; i < snapshot.size(); i++)
{
MessagePtr message = snapshot[i];
if (checkMessageUserName(userName, message))
{
channelPtr->addMessage(message, MessageContext::Repost);
}
}
return channelPtr;
};
const auto borderColor = QColor(255, 255, 255, 80);
int calculateTimeoutDuration(TimeoutButton timeout)
{
static const QMap<QString, int> durations{
{"s", 1}, {"m", 60}, {"h", 3600}, {"d", 86400}, {"w", 604800},
};
return timeout.second * durations[timeout.first];
}
} // namespace
namespace chatterino {
UserInfoPopup::UserInfoPopup(bool closeAutomatically, Split *split)
: DraggablePopup(closeAutomatically, split)
, split_(split)
@@ -813,10 +816,9 @@ void UserInfoPopup::updateUserData()
this->ui_.nameLabel->setText(this->userName_);
this->ui_.userIDLabel->setText(QString("ID ") +
QString(TEXT_UNAVAILABLE));
this->ui_.userIDLabel->setText(u"ID " % TEXT_UNAVAILABLE);
this->ui_.userIDLabel->setProperty("copy-text",
QString(TEXT_UNAVAILABLE));
TEXT_UNAVAILABLE.toString());
};
const auto onUserFetched = [this, hack,
currentUser](const HelixUser &user) {
@@ -855,7 +857,7 @@ void UserInfoPopup::updateUserData()
user.displayName, this->underlyingChannel_->getName()));
this->ui_.createdDateLabel->setText(
TEXT_CREATED.arg(user.createdAt.section("T", 0, 0)));
this->ui_.userIDLabel->setText(TEXT_USER_ID + user.id);
this->ui_.userIDLabel->setText(TEXT_USER_ID % user.id);
this->ui_.userIDLabel->setProperty("copy-text", user.id);
if (getApp()->getStreamerMode()->isEnabled() &&