mirror of
https://github.com/transmission/transmission.git
synced 2026-02-14 23:19:34 +00:00
fix: clang-tidy warnings in Qt client (#7981)
* fix: readability-identifier-naming
* fix: misc-unused-using-decls
* fix: google-readability-braces-around-statements,hicpp-braces-around-statements,readability-braces-around-statements
* fix: cert-err58-cpp
* fix: bugprone-unchecked-optional-access
* Revert "fix: cert-err58-cpp"
This reverts commit 6e6d97228f.
* fix: better to keep QStringLiteral; disable spurious cert-err58-cpp warning
This commit is contained in:
@@ -42,13 +42,14 @@
|
||||
namespace
|
||||
{
|
||||
|
||||
// NOLINTBEGIN(cert-err58-cpp)
|
||||
auto const ConfigName = QStringLiteral("transmission");
|
||||
|
||||
#ifdef QT_DBUS_LIB
|
||||
auto const FDONotificationsServiceName = QStringLiteral("org.freedesktop.Notifications");
|
||||
auto const FDONotificationsPath = QStringLiteral("/org/freedesktop/Notifications");
|
||||
auto const FDONotificationsInterfaceName = QStringLiteral("org.freedesktop.Notifications");
|
||||
#endif
|
||||
// NOLINTEND(cert-err58-cpp)
|
||||
|
||||
auto constexpr StatsRefreshIntervalMsec = 3000;
|
||||
auto constexpr SessionRefreshIntervalMsec = 3000;
|
||||
|
||||
@@ -50,9 +50,9 @@ QString Formatter::storage_to_string(int64_t const bytes)
|
||||
QString Formatter::ratio_to_string(double ratio)
|
||||
{
|
||||
static auto constexpr Infinity = "\xE2\x88\x9E"sv;
|
||||
static auto const none = tr("None").toStdString();
|
||||
static auto const None = tr("None").toStdString();
|
||||
|
||||
return QString::fromStdString(tr_strratio(ratio, none, Infinity));
|
||||
return QString::fromStdString(tr_strratio(ratio, None, Infinity));
|
||||
}
|
||||
|
||||
QString Formatter::time_to_string(int seconds)
|
||||
|
||||
@@ -916,16 +916,16 @@ void MainWindow::refreshIcons()
|
||||
|
||||
// network icons
|
||||
|
||||
auto networkPixmap = [](icons::Type type)
|
||||
auto network_pixmap = [](icons::Type type)
|
||||
{
|
||||
auto constexpr Size = QSize{ 16, 16 };
|
||||
return icons::icon(type).pixmap(Size);
|
||||
};
|
||||
pixmap_network_idle_ = networkPixmap(icons::Type::NetworkIdle);
|
||||
pixmap_network_receive_ = networkPixmap(icons::Type::NetworkReceive);
|
||||
pixmap_network_transmit_ = networkPixmap(icons::Type::NetworkTransmit);
|
||||
pixmap_network_transmit_receive_ = networkPixmap(icons::Type::NetworkTransmitReceive);
|
||||
pixmap_network_error_ = networkPixmap(icons::Type::NetworkError);
|
||||
pixmap_network_idle_ = network_pixmap(icons::Type::NetworkIdle);
|
||||
pixmap_network_receive_ = network_pixmap(icons::Type::NetworkReceive);
|
||||
pixmap_network_transmit_ = network_pixmap(icons::Type::NetworkTransmit);
|
||||
pixmap_network_transmit_receive_ = network_pixmap(icons::Type::NetworkTransmitReceive);
|
||||
pixmap_network_error_ = network_pixmap(icons::Type::NetworkError);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -1602,7 +1602,9 @@ bool MainWindow::event(QEvent* e)
|
||||
|
||||
case QEvent::Clipboard:
|
||||
if (auto_add_clipboard_links_)
|
||||
{
|
||||
addTorrentFromClipboard();
|
||||
}
|
||||
break;
|
||||
|
||||
case QEvent::PaletteChange:
|
||||
|
||||
@@ -31,9 +31,11 @@ namespace
|
||||
{
|
||||
|
||||
// https://learn.microsoft.com/en-us/windows/apps/design/style/segoe-ui-symbol-font
|
||||
// NOLINTNEXTLINE(cert-err58-cpp)
|
||||
auto const Win10IconFamily = QStringLiteral("Segoe MDL2 Assets");
|
||||
|
||||
// https://learn.microsoft.com/en-us/windows/apps/design/style/segoe-fluent-icons-font
|
||||
// NOLINTNEXTLINE(cert-err58-cpp)
|
||||
auto const Win11IconFamily = QStringLiteral("Segoe Fluent Icons");
|
||||
|
||||
// Define these two macros to force a specific icon icon during development.
|
||||
@@ -52,10 +54,14 @@ QString getWindowsFontFamily()
|
||||
return DEV_FORCE_FONT_FAMILY;
|
||||
#else
|
||||
if (QOperatingSystemVersion::current() >= QOperatingSystemVersion(QOperatingSystemVersion::Windows, 11))
|
||||
{
|
||||
return Win11IconFamily;
|
||||
}
|
||||
|
||||
if (QOperatingSystemVersion::current() >= QOperatingSystemVersion(QOperatingSystemVersion::Windows, 10))
|
||||
{
|
||||
return Win10IconFamily;
|
||||
}
|
||||
|
||||
return {};
|
||||
#endif
|
||||
@@ -72,7 +78,9 @@ QPixmap makeIconFromCodepoint(QString const family, QChar const codepoint, int c
|
||||
{
|
||||
auto font = QFont{ family };
|
||||
if (!QFontMetrics{ font }.inFont(codepoint))
|
||||
{
|
||||
return {};
|
||||
}
|
||||
|
||||
font.setPixelSize(pixel_size);
|
||||
|
||||
@@ -439,10 +447,16 @@ QIcon icon(Type const type, QStyle const* const style)
|
||||
auto icon = QIcon{};
|
||||
auto const name = QString::fromUtf8(std::data(key), std::size(key));
|
||||
for (int const pixel_size : pixel_sizes)
|
||||
{
|
||||
if (auto const pixmap = loadSFSymbol(name, pixel_size); !pixmap.isNull())
|
||||
{
|
||||
icon.addPixmap(pixmap);
|
||||
}
|
||||
}
|
||||
if (!icon.isNull())
|
||||
{
|
||||
return icon;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
@@ -453,10 +467,16 @@ QIcon icon(Type const type, QStyle const* const style)
|
||||
auto icon = QIcon{};
|
||||
auto const ch = QChar{ key };
|
||||
for (int const pixel_size : pixel_sizes)
|
||||
{
|
||||
if (auto pixmap = makeIconFromCodepoint(family, ch, pixel_size); !pixmap.isNull())
|
||||
{
|
||||
icon.addPixmap(pixmap);
|
||||
}
|
||||
}
|
||||
if (!icon.isNull())
|
||||
{
|
||||
return icon;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -465,22 +485,28 @@ QIcon icon(Type const type, QStyle const* const style)
|
||||
auto const name = QString::fromUtf8(std::data(key), std::size(key));
|
||||
|
||||
if (auto icon = QIcon::fromTheme(name); !icon.isNull())
|
||||
{
|
||||
return icon;
|
||||
}
|
||||
if (auto icon = QIcon::fromTheme(name + QStringLiteral("-symbolic")); !icon.isNull())
|
||||
{
|
||||
return icon;
|
||||
}
|
||||
}
|
||||
|
||||
if (info.fallback)
|
||||
{
|
||||
return style->standardIcon(*info.fallback);
|
||||
}
|
||||
|
||||
return {};
|
||||
}
|
||||
|
||||
[[nodiscard]] bool shouldBeShownInMenu(Type type)
|
||||
{
|
||||
static bool const force_icons = !qgetenv("TR_SHOW_MENU_ICONS").isEmpty();
|
||||
static bool const is_gnome = qgetenv("XDG_CURRENT_DESKTOP").contains("GNOME");
|
||||
return force_icons || !is_gnome || getInfo(type).ok_in_gnome_menus;
|
||||
static bool const ForceIcons = !qgetenv("TR_SHOW_MENU_ICONS").isEmpty();
|
||||
static bool const IsGnome = qgetenv("XDG_CURRENT_DESKTOP").contains("GNOME");
|
||||
return ForceIcons || !IsGnome || getInfo(type).ok_in_gnome_menus;
|
||||
}
|
||||
|
||||
} // namespace icons
|
||||
|
||||
@@ -25,9 +25,7 @@
|
||||
|
||||
#include "VariantHelpers.h"
|
||||
|
||||
using ::trqt::variant_helpers::dictAdd;
|
||||
using ::trqt::variant_helpers::dictFind;
|
||||
using ::trqt::variant_helpers::variantInit;
|
||||
namespace api_compat = libtransmission::api_compat;
|
||||
|
||||
namespace
|
||||
@@ -70,7 +68,6 @@ void RpcClient::stop()
|
||||
session_ = nullptr;
|
||||
session_id_.clear();
|
||||
url_.clear();
|
||||
request_.reset();
|
||||
network_style_ = DefaultNetworkStyle;
|
||||
|
||||
if (nam_ != nullptr)
|
||||
@@ -89,7 +86,6 @@ void RpcClient::start(QUrl const& url)
|
||||
{
|
||||
url_ = url;
|
||||
url_is_loopback_ = QHostAddress{ url_.host() }.isLoopback();
|
||||
request_.reset();
|
||||
}
|
||||
|
||||
RpcResponseFuture RpcClient::exec(tr_quark const method, tr_variant* args)
|
||||
@@ -119,41 +115,36 @@ RpcResponseFuture RpcClient::exec(tr_quark const method, tr_variant* args)
|
||||
|
||||
void RpcClient::sendNetworkRequest(QByteArray const& body, QFutureInterface<RpcResponse> const& promise)
|
||||
{
|
||||
if (!request_)
|
||||
auto req = QNetworkRequest{};
|
||||
QNetworkRequest request;
|
||||
request.setUrl(url_);
|
||||
request.setRawHeader("User-Agent", "Transmisson/" SHORT_VERSION_STRING);
|
||||
if (!session_id_.isEmpty())
|
||||
{
|
||||
QNetworkRequest request;
|
||||
request.setUrl(url_);
|
||||
request.setRawHeader(
|
||||
"User-Agent",
|
||||
(QApplication::applicationName() + QLatin1Char('/') + QString::fromUtf8(LONG_VERSION_STRING)).toUtf8());
|
||||
request.setRawHeader("Content-Type", "application/json; charset=UTF-8");
|
||||
if (!session_id_.isEmpty())
|
||||
{
|
||||
request.setRawHeader(TR_RPC_SESSION_ID_HEADER, session_id_.toUtf8());
|
||||
}
|
||||
|
||||
request_ = request;
|
||||
request.setRawHeader(TR_RPC_SESSION_ID_HEADER, session_id_);
|
||||
}
|
||||
|
||||
QNetworkReply* reply = networkAccessManager()->post(*request_, body);
|
||||
reply->setProperty(RequestBodyKey, body);
|
||||
reply->setProperty(RequestFutureinterfacePropertyKey, QVariant::fromValue(promise));
|
||||
|
||||
connect(reply, &QNetworkReply::downloadProgress, this, &RpcClient::dataReadProgress);
|
||||
connect(reply, &QNetworkReply::uploadProgress, this, &RpcClient::dataSendProgress);
|
||||
|
||||
if (verbose_)
|
||||
{
|
||||
qInfo() << "sending POST " << qPrintable(url_.path());
|
||||
|
||||
for (QByteArray const& b : request_->rawHeaderList())
|
||||
for (QByteArray const& name : req.rawHeaderList())
|
||||
{
|
||||
qInfo() << b.constData() << ": " << request_->rawHeader(b).constData();
|
||||
qInfo() << name.constData() << ": " << req.rawHeader(name).constData();
|
||||
}
|
||||
|
||||
qInfo() << "Body:";
|
||||
qInfo() << body.constData();
|
||||
}
|
||||
|
||||
if (QNetworkReply* reply = networkAccessManager()->post(req, body))
|
||||
{
|
||||
reply->setProperty(RequestBodyKey, body);
|
||||
reply->setProperty(RequestFutureinterfacePropertyKey, QVariant::fromValue(promise));
|
||||
|
||||
connect(reply, &QNetworkReply::downloadProgress, this, &RpcClient::dataReadProgress);
|
||||
connect(reply, &QNetworkReply::uploadProgress, this, &RpcClient::dataSendProgress);
|
||||
}
|
||||
}
|
||||
|
||||
void RpcClient::sendLocalRequest(tr_variant const& req, QFutureInterface<RpcResponse> const& promise, int64_t const id)
|
||||
@@ -252,9 +243,7 @@ void RpcClient::networkRequestFinished(QNetworkReply* reply)
|
||||
static_cast<int>(network_style_));
|
||||
}
|
||||
|
||||
session_id_ = QString::fromUtf8(reply->rawHeader(TR_RPC_SESSION_ID_HEADER));
|
||||
request_.reset();
|
||||
|
||||
session_id_ = reply->rawHeader(TR_RPC_SESSION_ID_HEADER);
|
||||
sendNetworkRequest(reply->property(RequestBodyKey).toByteArray(), promise);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -96,11 +96,9 @@ private:
|
||||
// TODO: change this default in 5.0.0-beta.1
|
||||
static auto constexpr DefaultNetworkStyle = libtransmission::api_compat::Style::Tr4;
|
||||
|
||||
std::optional<QNetworkRequest> request_;
|
||||
|
||||
libtransmission::api_compat::Style network_style_ = DefaultNetworkStyle;
|
||||
tr_session* session_ = {};
|
||||
QString session_id_;
|
||||
QByteArray session_id_;
|
||||
QUrl url_;
|
||||
QNetworkAccessManager* nam_ = {};
|
||||
std::unordered_map<int64_t, QFutureInterface<RpcResponse>> local_requests_;
|
||||
|
||||
@@ -233,7 +233,7 @@ void variantInit(tr_variant* init_me, std::string_view value)
|
||||
|
||||
namespace
|
||||
{
|
||||
bool to_int(tr_variant const& src, int* tgt)
|
||||
bool toInt(tr_variant const& src, int* tgt)
|
||||
{
|
||||
if (auto const val = src.value_if<int64_t>())
|
||||
{
|
||||
@@ -249,7 +249,7 @@ bool to_int(tr_variant const& src, int* tgt)
|
||||
return false;
|
||||
}
|
||||
|
||||
tr_variant from_int(int const& val)
|
||||
tr_variant fromInt(int const& val)
|
||||
{
|
||||
return static_cast<int64_t>(val);
|
||||
}
|
||||
@@ -263,7 +263,7 @@ void register_qt_converters()
|
||||
[]
|
||||
{
|
||||
using namespace libtransmission::serializer;
|
||||
Converters::add(to_int, from_int);
|
||||
Converters::add(toInt, fromInt);
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user