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
|
||||
|
||||
using namespace std::literals;
|
||||
using libtransmission::Watchdir;
|
||||
|
||||
static char constexpr MyName[] = "transmission-daemon";
|
||||
|
@ -199,7 +200,7 @@ static std::string getConfigDir(int argc, char const* const* argv)
|
|||
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 is_torrent = tr_strvEndsWith(lowercase, ".torrent"sv);
|
||||
|
@ -921,7 +922,7 @@ EXIT_EARLY:
|
|||
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);
|
||||
printMessage(logfile_, TR_LOG_ERROR, MyName, errmsg, __FILE__, __LINE__);
|
||||
|
|
|
@ -15,8 +15,6 @@
|
|||
#include <libtransmission/file.h>
|
||||
#include <libtransmission/log.h>
|
||||
|
||||
using namespace std::literals;
|
||||
|
||||
class tr_daemon
|
||||
{
|
||||
public:
|
||||
|
@ -35,7 +33,7 @@ public:
|
|||
|
||||
bool spawn(bool foreground, int* exit_code, tr_error** error);
|
||||
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);
|
||||
void periodic_update();
|
||||
void reconfigure();
|
||||
|
@ -53,8 +51,8 @@ private:
|
|||
char const* log_file_name_ = nullptr;
|
||||
struct event_base* ev_base_ = nullptr;
|
||||
tr_sys_file_t logfile_ = TR_BAD_SYS_FILE;
|
||||
tr_quark key_pidfile_ = tr_quark_new("pidfile"sv);
|
||||
tr_quark key_watch_dir_force_generic_ = tr_quark_new("watch-dir-force-generic"sv);
|
||||
tr_quark key_pidfile_ = tr_quark_new("pidfile");
|
||||
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 reopen_log_file(char const* filename);
|
||||
|
|
|
@ -21,13 +21,12 @@
|
|||
#include "Utils.h" // std::hash<QString>
|
||||
|
||||
class AddData;
|
||||
class MainWindow;
|
||||
class Prefs;
|
||||
class Session;
|
||||
class Torrent;
|
||||
class TorrentModel;
|
||||
class MainWindow;
|
||||
class WatchDir;
|
||||
class Torrent;
|
||||
|
||||
class Application : public QApplication
|
||||
{
|
||||
|
|
|
@ -156,9 +156,8 @@ void FileTreeView::keyPressEvent(QKeyEvent* event)
|
|||
|
||||
void FileTreeView::mouseDoubleClickEvent(QMouseEvent* event)
|
||||
{
|
||||
auto const index = currentIndex();
|
||||
|
||||
if (!index.isValid() || index.column() == FileTreeModel::COL_WANTED || index.column() == FileTreeModel::COL_PRIORITY)
|
||||
if (auto const index = currentIndex();
|
||||
!index.isValid() || index.column() == FileTreeModel::COL_WANTED || index.column() == FileTreeModel::COL_PRIORITY)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
@ -173,9 +172,7 @@ void FileTreeView::mouseDoubleClickEvent(QMouseEvent* event)
|
|||
|
||||
void FileTreeView::contextMenuEvent(QContextMenuEvent* event)
|
||||
{
|
||||
QModelIndex const root_index = model_->index(0, 0);
|
||||
|
||||
if (!root_index.isValid())
|
||||
if (auto const root_index = model_->index(0, 0); !root_index.isValid())
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
|
|
@ -224,7 +224,7 @@ QIcon IconCache::getThemeIcon(
|
|||
QString const& fallbackName,
|
||||
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);
|
||||
|
||||
|
@ -235,7 +235,7 @@ QIcon IconCache::getThemeIcon(
|
|||
|
||||
if (icon.isNull() && fallbackPixmap.has_value())
|
||||
{
|
||||
icon = qApp->style()->standardIcon(*fallbackPixmap, nullptr);
|
||||
icon = QApplication::style()->standardIcon(*fallbackPixmap, nullptr);
|
||||
}
|
||||
|
||||
return icon;
|
||||
|
|
|
@ -285,8 +285,7 @@ void RpcClient::localRequestFinished(TrVariantPtr response)
|
|||
|
||||
int64_t RpcClient::parseResponseTag(tr_variant& response) const
|
||||
{
|
||||
auto const tag = dictFind<int>(&response, TR_KEY_tag);
|
||||
return tag ? *tag : -1;
|
||||
return dictFind<int>(&response, TR_KEY_tag).value_or(-1);
|
||||
}
|
||||
|
||||
RpcResponse RpcClient::parseResponseData(tr_variant& response) const
|
||||
|
|
|
@ -82,8 +82,8 @@ private:
|
|||
|
||||
void sendNetworkRequest(TrVariantPtr json, QFutureInterface<RpcResponse> const& promise);
|
||||
void sendLocalRequest(TrVariantPtr json, QFutureInterface<RpcResponse> const& promise, int64_t tag);
|
||||
int64_t parseResponseTag(tr_variant& response) const;
|
||||
RpcResponse parseResponseData(tr_variant& response) const;
|
||||
[[nodiscard]] int64_t parseResponseTag(tr_variant& response) const;
|
||||
[[nodiscard]] RpcResponse parseResponseData(tr_variant& response) const;
|
||||
|
||||
static void localSessionCallback(tr_session* s, tr_variant* response, void* vself) noexcept;
|
||||
|
||||
|
|
|
@ -7,12 +7,8 @@
|
|||
|
||||
#include "RpcQueue.h"
|
||||
|
||||
// NOLINTNEXTLINE(cppcoreguidelines-avoid-non-const-global-variables)
|
||||
RpcQueue::Tag RpcQueue::next_tag = {};
|
||||
|
||||
RpcQueue::RpcQueue(QObject* parent)
|
||||
: QObject(parent)
|
||||
, tag_(next_tag++)
|
||||
{
|
||||
connect(&future_watcher_, &QFutureWatcher<RpcResponse>::finished, this, &RpcQueue::stepFinished);
|
||||
}
|
||||
|
|
|
@ -146,8 +146,9 @@ private:
|
|||
return promise.future();
|
||||
}
|
||||
|
||||
Tag const tag_;
|
||||
static Tag next_tag;
|
||||
static inline Tag next_tag = {};
|
||||
|
||||
Tag const tag_ = next_tag++;
|
||||
bool tolerate_errors_ = {};
|
||||
QFutureInterface<RpcResponse> promise_;
|
||||
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); },
|
||||
[](RpcResponse const& r)
|
||||
{
|
||||
auto str = dictFind<QString>(r.args.get(), TR_KEY_path);
|
||||
auto const path = str ? *str : QStringLiteral("(unknown)");
|
||||
str = dictFind<QString>(r.args.get(), TR_KEY_name);
|
||||
auto const name = str ? *str : QStringLiteral("(unknown)");
|
||||
auto const path = dictFind<QString>(r.args.get(), TR_KEY_path).value_or(QStringLiteral("(unknown)"));
|
||||
auto const name = dictFind<QString>(r.args.get(), TR_KEY_name).value_or(QStringLiteral("(unknown)"));
|
||||
|
||||
auto* d = new QMessageBox(
|
||||
QMessageBox::Information,
|
||||
|
|
|
@ -26,7 +26,7 @@ public:
|
|||
|
||||
protected:
|
||||
// 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:
|
||||
bool show_backups_ = {};
|
||||
|
|
|
@ -24,10 +24,7 @@ struct Peer;
|
|||
struct TorrentFile;
|
||||
struct TrackerStat;
|
||||
|
||||
namespace trqt
|
||||
{
|
||||
|
||||
namespace variant_helpers
|
||||
namespace trqt::variant_helpers
|
||||
{
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
} // namespace variant_helpers
|
||||
|
||||
} // namespace trqt
|
||||
} // namespace trqt::variant_helpers
|
||||
|
|
|
@ -172,7 +172,7 @@ static std::string replaceSubstr(std::string_view str, std::string_view oldval,
|
|||
{
|
||||
auto const pos = str.find(oldval);
|
||||
ret += str.substr(0, pos);
|
||||
if (pos == str.npos)
|
||||
if (pos == std::string_view::npos)
|
||||
{
|
||||
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)
|
||||
{
|
||||
auto sv = std::string_view{};
|
||||
if (tr_variantGetStrView(node, &sv) && sv == url)
|
||||
if (auto sv = std::string_view{}; tr_variantGetStrView(node, &sv) && sv == url)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
|
|
@ -907,11 +907,11 @@ static std::string getStatusString(tr_variant* t)
|
|||
}
|
||||
}
|
||||
|
||||
static char const* bandwidthPriorityNames[] = {
|
||||
"Low",
|
||||
"Normal",
|
||||
"High",
|
||||
"Invalid",
|
||||
static auto constexpr bandwidth_priority_names = std::array<std::string_view, 4>{
|
||||
"Low"sv,
|
||||
"Normal"sv,
|
||||
"High"sv,
|
||||
"Invalid"sv,
|
||||
};
|
||||
|
||||
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))
|
||||
{
|
||||
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");
|
||||
|
|
Loading…
Reference in New Issue