fix: sonarcloud warnings (#4180)
This commit is contained in:
parent
d0639b5f0c
commit
22c14c9266
|
@ -51,6 +51,7 @@ static void sd_notifyf(int /*status*/, char const* /*fmt*/, ...)
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
using namespace std::literals;
|
||||||
using libtransmission::Watchdir;
|
using libtransmission::Watchdir;
|
||||||
|
|
||||||
static char constexpr MyName[] = "transmission-daemon";
|
static char constexpr MyName[] = "transmission-daemon";
|
||||||
|
@ -199,7 +200,7 @@ static std::string getConfigDir(int argc, char const* const* argv)
|
||||||
return tr_getDefaultConfigDir(MyName);
|
return tr_getDefaultConfigDir(MyName);
|
||||||
}
|
}
|
||||||
|
|
||||||
static auto onFileAdded(tr_session* session, std::string_view dirname, std::string_view basename)
|
static auto onFileAdded(tr_session const* session, std::string_view dirname, std::string_view basename)
|
||||||
{
|
{
|
||||||
auto const lowercase = tr_strlower(basename);
|
auto const lowercase = tr_strlower(basename);
|
||||||
auto const is_torrent = tr_strvEndsWith(lowercase, ".torrent"sv);
|
auto const is_torrent = tr_strvEndsWith(lowercase, ".torrent"sv);
|
||||||
|
@ -921,7 +922,7 @@ EXIT_EARLY:
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
void tr_daemon::handle_error(tr_error* error)
|
void tr_daemon::handle_error(tr_error* error) const
|
||||||
{
|
{
|
||||||
auto const errmsg = fmt::format(FMT_STRING("Couldn't daemonize: {:s} ({:d})"), error->message, error->code);
|
auto const errmsg = fmt::format(FMT_STRING("Couldn't daemonize: {:s} ({:d})"), error->message, error->code);
|
||||||
printMessage(logfile_, TR_LOG_ERROR, MyName, errmsg, __FILE__, __LINE__);
|
printMessage(logfile_, TR_LOG_ERROR, MyName, errmsg, __FILE__, __LINE__);
|
||||||
|
|
|
@ -15,8 +15,6 @@
|
||||||
#include <libtransmission/file.h>
|
#include <libtransmission/file.h>
|
||||||
#include <libtransmission/log.h>
|
#include <libtransmission/log.h>
|
||||||
|
|
||||||
using namespace std::literals;
|
|
||||||
|
|
||||||
class tr_daemon
|
class tr_daemon
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
@ -35,7 +33,7 @@ public:
|
||||||
|
|
||||||
bool spawn(bool foreground, int* exit_code, tr_error** error);
|
bool spawn(bool foreground, int* exit_code, tr_error** error);
|
||||||
bool init(int argc, char* argv[], bool* foreground, int* ret);
|
bool init(int argc, char* argv[], bool* foreground, int* ret);
|
||||||
void handle_error(tr_error*);
|
void handle_error(tr_error*) const;
|
||||||
int start(bool foreground);
|
int start(bool foreground);
|
||||||
void periodic_update();
|
void periodic_update();
|
||||||
void reconfigure();
|
void reconfigure();
|
||||||
|
@ -53,8 +51,8 @@ private:
|
||||||
char const* log_file_name_ = nullptr;
|
char const* log_file_name_ = nullptr;
|
||||||
struct event_base* ev_base_ = nullptr;
|
struct event_base* ev_base_ = nullptr;
|
||||||
tr_sys_file_t logfile_ = TR_BAD_SYS_FILE;
|
tr_sys_file_t logfile_ = TR_BAD_SYS_FILE;
|
||||||
tr_quark key_pidfile_ = tr_quark_new("pidfile"sv);
|
tr_quark key_pidfile_ = tr_quark_new("pidfile");
|
||||||
tr_quark key_watch_dir_force_generic_ = tr_quark_new("watch-dir-force-generic"sv);
|
tr_quark key_watch_dir_force_generic_ = tr_quark_new("watch-dir-force-generic");
|
||||||
|
|
||||||
bool parse_args(int argc, char const** argv, bool* dump_settings, bool* foreground, int* exit_code);
|
bool parse_args(int argc, char const** argv, bool* dump_settings, bool* foreground, int* exit_code);
|
||||||
bool reopen_log_file(char const* filename);
|
bool reopen_log_file(char const* filename);
|
||||||
|
|
|
@ -21,13 +21,12 @@
|
||||||
#include "Utils.h" // std::hash<QString>
|
#include "Utils.h" // std::hash<QString>
|
||||||
|
|
||||||
class AddData;
|
class AddData;
|
||||||
|
class MainWindow;
|
||||||
class Prefs;
|
class Prefs;
|
||||||
class Session;
|
class Session;
|
||||||
class Torrent;
|
class Torrent;
|
||||||
class TorrentModel;
|
class TorrentModel;
|
||||||
class MainWindow;
|
|
||||||
class WatchDir;
|
class WatchDir;
|
||||||
class Torrent;
|
|
||||||
|
|
||||||
class Application : public QApplication
|
class Application : public QApplication
|
||||||
{
|
{
|
||||||
|
|
|
@ -156,9 +156,8 @@ void FileTreeView::keyPressEvent(QKeyEvent* event)
|
||||||
|
|
||||||
void FileTreeView::mouseDoubleClickEvent(QMouseEvent* event)
|
void FileTreeView::mouseDoubleClickEvent(QMouseEvent* event)
|
||||||
{
|
{
|
||||||
auto const index = currentIndex();
|
if (auto const index = currentIndex();
|
||||||
|
!index.isValid() || index.column() == FileTreeModel::COL_WANTED || index.column() == FileTreeModel::COL_PRIORITY)
|
||||||
if (!index.isValid() || index.column() == FileTreeModel::COL_WANTED || index.column() == FileTreeModel::COL_PRIORITY)
|
|
||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -173,9 +172,7 @@ void FileTreeView::mouseDoubleClickEvent(QMouseEvent* event)
|
||||||
|
|
||||||
void FileTreeView::contextMenuEvent(QContextMenuEvent* event)
|
void FileTreeView::contextMenuEvent(QContextMenuEvent* event)
|
||||||
{
|
{
|
||||||
QModelIndex const root_index = model_->index(0, 0);
|
if (auto const root_index = model_->index(0, 0); !root_index.isValid())
|
||||||
|
|
||||||
if (!root_index.isValid())
|
|
||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
|
@ -224,7 +224,7 @@ QIcon IconCache::getThemeIcon(
|
||||||
QString const& fallbackName,
|
QString const& fallbackName,
|
||||||
std::optional<QStyle::StandardPixmap> const& fallbackPixmap) const
|
std::optional<QStyle::StandardPixmap> const& fallbackPixmap) const
|
||||||
{
|
{
|
||||||
auto const rtl_suffix = qApp->layoutDirection() == Qt::RightToLeft ? QStringLiteral("-rtl") : QString();
|
auto const rtl_suffix = QApplication::layoutDirection() == Qt::RightToLeft ? QStringLiteral("-rtl") : QString();
|
||||||
|
|
||||||
auto icon = QIcon::fromTheme(name + rtl_suffix);
|
auto icon = QIcon::fromTheme(name + rtl_suffix);
|
||||||
|
|
||||||
|
@ -235,7 +235,7 @@ QIcon IconCache::getThemeIcon(
|
||||||
|
|
||||||
if (icon.isNull() && fallbackPixmap.has_value())
|
if (icon.isNull() && fallbackPixmap.has_value())
|
||||||
{
|
{
|
||||||
icon = qApp->style()->standardIcon(*fallbackPixmap, nullptr);
|
icon = QApplication::style()->standardIcon(*fallbackPixmap, nullptr);
|
||||||
}
|
}
|
||||||
|
|
||||||
return icon;
|
return icon;
|
||||||
|
|
|
@ -285,8 +285,7 @@ void RpcClient::localRequestFinished(TrVariantPtr response)
|
||||||
|
|
||||||
int64_t RpcClient::parseResponseTag(tr_variant& response) const
|
int64_t RpcClient::parseResponseTag(tr_variant& response) const
|
||||||
{
|
{
|
||||||
auto const tag = dictFind<int>(&response, TR_KEY_tag);
|
return dictFind<int>(&response, TR_KEY_tag).value_or(-1);
|
||||||
return tag ? *tag : -1;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
RpcResponse RpcClient::parseResponseData(tr_variant& response) const
|
RpcResponse RpcClient::parseResponseData(tr_variant& response) const
|
||||||
|
|
|
@ -82,8 +82,8 @@ private:
|
||||||
|
|
||||||
void sendNetworkRequest(TrVariantPtr json, QFutureInterface<RpcResponse> const& promise);
|
void sendNetworkRequest(TrVariantPtr json, QFutureInterface<RpcResponse> const& promise);
|
||||||
void sendLocalRequest(TrVariantPtr json, QFutureInterface<RpcResponse> const& promise, int64_t tag);
|
void sendLocalRequest(TrVariantPtr json, QFutureInterface<RpcResponse> const& promise, int64_t tag);
|
||||||
int64_t parseResponseTag(tr_variant& response) const;
|
[[nodiscard]] int64_t parseResponseTag(tr_variant& response) const;
|
||||||
RpcResponse parseResponseData(tr_variant& response) const;
|
[[nodiscard]] RpcResponse parseResponseData(tr_variant& response) const;
|
||||||
|
|
||||||
static void localSessionCallback(tr_session* s, tr_variant* response, void* vself) noexcept;
|
static void localSessionCallback(tr_session* s, tr_variant* response, void* vself) noexcept;
|
||||||
|
|
||||||
|
|
|
@ -7,12 +7,8 @@
|
||||||
|
|
||||||
#include "RpcQueue.h"
|
#include "RpcQueue.h"
|
||||||
|
|
||||||
// NOLINTNEXTLINE(cppcoreguidelines-avoid-non-const-global-variables)
|
|
||||||
RpcQueue::Tag RpcQueue::next_tag = {};
|
|
||||||
|
|
||||||
RpcQueue::RpcQueue(QObject* parent)
|
RpcQueue::RpcQueue(QObject* parent)
|
||||||
: QObject(parent)
|
: QObject(parent)
|
||||||
, tag_(next_tag++)
|
|
||||||
{
|
{
|
||||||
connect(&future_watcher_, &QFutureWatcher<RpcResponse>::finished, this, &RpcQueue::stepFinished);
|
connect(&future_watcher_, &QFutureWatcher<RpcResponse>::finished, this, &RpcQueue::stepFinished);
|
||||||
}
|
}
|
||||||
|
|
|
@ -146,8 +146,9 @@ private:
|
||||||
return promise.future();
|
return promise.future();
|
||||||
}
|
}
|
||||||
|
|
||||||
Tag const tag_;
|
static inline Tag next_tag = {};
|
||||||
static Tag next_tag;
|
|
||||||
|
Tag const tag_ = next_tag++;
|
||||||
bool tolerate_errors_ = {};
|
bool tolerate_errors_ = {};
|
||||||
QFutureInterface<RpcResponse> promise_;
|
QFutureInterface<RpcResponse> promise_;
|
||||||
QQueue<QPair<QueuedFunction, ErrorHandlerFunction>> queue_;
|
QQueue<QPair<QueuedFunction, ErrorHandlerFunction>> queue_;
|
||||||
|
|
|
@ -486,10 +486,8 @@ void Session::torrentRenamePath(torrent_ids_t const& torrent_ids, QString const&
|
||||||
[this, &args]() { return exec("torrent-rename-path", &args); },
|
[this, &args]() { return exec("torrent-rename-path", &args); },
|
||||||
[](RpcResponse const& r)
|
[](RpcResponse const& r)
|
||||||
{
|
{
|
||||||
auto str = dictFind<QString>(r.args.get(), TR_KEY_path);
|
auto const path = dictFind<QString>(r.args.get(), TR_KEY_path).value_or(QStringLiteral("(unknown)"));
|
||||||
auto const path = str ? *str : QStringLiteral("(unknown)");
|
auto const name = dictFind<QString>(r.args.get(), TR_KEY_name).value_or(QStringLiteral("(unknown)"));
|
||||||
str = dictFind<QString>(r.args.get(), TR_KEY_name);
|
|
||||||
auto const name = str ? *str : QStringLiteral("(unknown)");
|
|
||||||
|
|
||||||
auto* d = new QMessageBox(
|
auto* d = new QMessageBox(
|
||||||
QMessageBox::Information,
|
QMessageBox::Information,
|
||||||
|
|
|
@ -26,7 +26,7 @@ public:
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
// QSortFilterProxyModel
|
// QSortFilterProxyModel
|
||||||
virtual bool filterAcceptsRow(int source_row, QModelIndex const& source_parent) const override;
|
bool filterAcceptsRow(int source_row, QModelIndex const& source_parent) const override;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
bool show_backups_ = {};
|
bool show_backups_ = {};
|
||||||
|
|
|
@ -24,10 +24,7 @@ struct Peer;
|
||||||
struct TorrentFile;
|
struct TorrentFile;
|
||||||
struct TrackerStat;
|
struct TrackerStat;
|
||||||
|
|
||||||
namespace trqt
|
namespace trqt::variant_helpers
|
||||||
{
|
|
||||||
|
|
||||||
namespace variant_helpers
|
|
||||||
{
|
{
|
||||||
|
|
||||||
template<typename T, typename std::enable_if_t<std::is_same_v<T, bool>>* = nullptr>
|
template<typename T, typename std::enable_if_t<std::is_same_v<T, bool>>* = nullptr>
|
||||||
|
@ -223,6 +220,4 @@ void dictAdd(tr_variant* dict, tr_quark key, T const& value)
|
||||||
variantInit(tr_variantDictAdd(dict, key), value);
|
variantInit(tr_variantDictAdd(dict, key), value);
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace variant_helpers
|
} // namespace trqt::variant_helpers
|
||||||
|
|
||||||
} // namespace trqt
|
|
||||||
|
|
|
@ -172,7 +172,7 @@ static std::string replaceSubstr(std::string_view str, std::string_view oldval,
|
||||||
{
|
{
|
||||||
auto const pos = str.find(oldval);
|
auto const pos = str.find(oldval);
|
||||||
ret += str.substr(0, pos);
|
ret += str.substr(0, pos);
|
||||||
if (pos == str.npos)
|
if (pos == std::string_view::npos)
|
||||||
{
|
{
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -240,8 +240,7 @@ static bool announce_list_has_url(tr_variant* announce_list, char const* url)
|
||||||
|
|
||||||
while ((node = tr_variantListChild(tier, nodeCount)) != nullptr)
|
while ((node = tr_variantListChild(tier, nodeCount)) != nullptr)
|
||||||
{
|
{
|
||||||
auto sv = std::string_view{};
|
if (auto sv = std::string_view{}; tr_variantGetStrView(node, &sv) && sv == url)
|
||||||
if (tr_variantGetStrView(node, &sv) && sv == url)
|
|
||||||
{
|
{
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
|
@ -907,11 +907,11 @@ static std::string getStatusString(tr_variant* t)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static char const* bandwidthPriorityNames[] = {
|
static auto constexpr bandwidth_priority_names = std::array<std::string_view, 4>{
|
||||||
"Low",
|
"Low"sv,
|
||||||
"Normal",
|
"Normal"sv,
|
||||||
"High",
|
"High"sv,
|
||||||
"Invalid",
|
"Invalid"sv,
|
||||||
};
|
};
|
||||||
|
|
||||||
static char* format_date(char* buf, size_t buflen, time_t now)
|
static char* format_date(char* buf, size_t buflen, time_t now)
|
||||||
|
@ -1241,7 +1241,7 @@ static void printDetails(tr_variant* top)
|
||||||
|
|
||||||
if (tr_variantDictFindInt(t, TR_KEY_bandwidthPriority, &i))
|
if (tr_variantDictFindInt(t, TR_KEY_bandwidthPriority, &i))
|
||||||
{
|
{
|
||||||
fmt::print(" Bandwidth Priority: {:s}\n", bandwidthPriorityNames[(i + 1) & 3]);
|
fmt::print(" Bandwidth Priority: {:s}\n", bandwidth_priority_names[(i + 1) & 3]);
|
||||||
}
|
}
|
||||||
|
|
||||||
fmt::print("\n");
|
fmt::print("\n");
|
||||||
|
|
Loading…
Reference in New Issue