diff --git a/daemon/daemon.cc b/daemon/daemon.cc index bdd4e5833..c73a6096a 100644 --- a/daemon/daemon.cc +++ b/daemon/daemon.cc @@ -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__); diff --git a/daemon/daemon.h b/daemon/daemon.h index 375535910..49291f456 100644 --- a/daemon/daemon.h +++ b/daemon/daemon.h @@ -15,8 +15,6 @@ #include #include -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); diff --git a/qt/Application.h b/qt/Application.h index e0d475027..5e052769f 100644 --- a/qt/Application.h +++ b/qt/Application.h @@ -21,13 +21,12 @@ #include "Utils.h" // std::hash class AddData; +class MainWindow; class Prefs; class Session; class Torrent; class TorrentModel; -class MainWindow; class WatchDir; -class Torrent; class Application : public QApplication { diff --git a/qt/FileTreeView.cc b/qt/FileTreeView.cc index 082b0b1f1..a41cd8299 100644 --- a/qt/FileTreeView.cc +++ b/qt/FileTreeView.cc @@ -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; } diff --git a/qt/IconCache.cc b/qt/IconCache.cc index c7fe695bb..471db1494 100644 --- a/qt/IconCache.cc +++ b/qt/IconCache.cc @@ -224,7 +224,7 @@ QIcon IconCache::getThemeIcon( QString const& fallbackName, std::optional 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; diff --git a/qt/RpcClient.cc b/qt/RpcClient.cc index 9de81b160..ab70a4a5b 100644 --- a/qt/RpcClient.cc +++ b/qt/RpcClient.cc @@ -285,8 +285,7 @@ void RpcClient::localRequestFinished(TrVariantPtr response) int64_t RpcClient::parseResponseTag(tr_variant& response) const { - auto const tag = dictFind(&response, TR_KEY_tag); - return tag ? *tag : -1; + return dictFind(&response, TR_KEY_tag).value_or(-1); } RpcResponse RpcClient::parseResponseData(tr_variant& response) const diff --git a/qt/RpcClient.h b/qt/RpcClient.h index 14bd4088d..de003164c 100644 --- a/qt/RpcClient.h +++ b/qt/RpcClient.h @@ -82,8 +82,8 @@ private: void sendNetworkRequest(TrVariantPtr json, QFutureInterface const& promise); void sendLocalRequest(TrVariantPtr json, QFutureInterface 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; diff --git a/qt/RpcQueue.cc b/qt/RpcQueue.cc index 6ca68d329..3f7c0c3cf 100644 --- a/qt/RpcQueue.cc +++ b/qt/RpcQueue.cc @@ -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::finished, this, &RpcQueue::stepFinished); } diff --git a/qt/RpcQueue.h b/qt/RpcQueue.h index b35456413..a0d57988f 100644 --- a/qt/RpcQueue.h +++ b/qt/RpcQueue.h @@ -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 promise_; QQueue> queue_; diff --git a/qt/Session.cc b/qt/Session.cc index 98f090bda..fa61a6e6e 100644 --- a/qt/Session.cc +++ b/qt/Session.cc @@ -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(r.args.get(), TR_KEY_path); - auto const path = str ? *str : QStringLiteral("(unknown)"); - str = dictFind(r.args.get(), TR_KEY_name); - auto const name = str ? *str : QStringLiteral("(unknown)"); + auto const path = dictFind(r.args.get(), TR_KEY_path).value_or(QStringLiteral("(unknown)")); + auto const name = dictFind(r.args.get(), TR_KEY_name).value_or(QStringLiteral("(unknown)")); auto* d = new QMessageBox( QMessageBox::Information, diff --git a/qt/TrackerModelFilter.h b/qt/TrackerModelFilter.h index 7d4f1badc..8a571ea1b 100644 --- a/qt/TrackerModelFilter.h +++ b/qt/TrackerModelFilter.h @@ -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_ = {}; diff --git a/qt/VariantHelpers.h b/qt/VariantHelpers.h index 58fc86c61..035af3769 100644 --- a/qt/VariantHelpers.h +++ b/qt/VariantHelpers.h @@ -24,10 +24,7 @@ struct Peer; struct TorrentFile; struct TrackerStat; -namespace trqt -{ - -namespace variant_helpers +namespace trqt::variant_helpers { template>* = 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 diff --git a/utils/edit.cc b/utils/edit.cc index 25ac3d91e..b261ae8e5 100644 --- a/utils/edit.cc +++ b/utils/edit.cc @@ -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; } diff --git a/utils/remote.cc b/utils/remote.cc index 612351199..4f144930b 100644 --- a/utils/remote.cc +++ b/utils/remote.cc @@ -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{ + "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");