diff --git a/libtransmission/.clang-tidy b/libtransmission/.clang-tidy index 7b0ead67d..0c8c212e9 100644 --- a/libtransmission/.clang-tidy +++ b/libtransmission/.clang-tidy @@ -8,14 +8,10 @@ Checks: > -bugprone-narrowing-conversions, cert-*, -cert-err58-cpp, - clang-analyzer-core.*, - clang-analyzer-cplusplus.*, - clang-analyzer-deadcode.*, - clang-analyzer-nullability.*, - clang-analyzer-optin.cplusplus.*, - clang-analyzer-security.*, - clang-analyzer-valist.*, + clang-analyzer-*, + cppcoreguidelines-avoid-const-or-ref-data-members, cppcoreguidelines-init-variables, + cppcoreguidelines-interfaces-global-init, cppcoreguidelines-prefer-member-initializer, cppcoreguidelines-slicing, cppcoreguidelines-special-member-functions, diff --git a/libtransmission/file-posix.cc b/libtransmission/file-posix.cc index 88b2d153c..68fafb239 100644 --- a/libtransmission/file-posix.cc +++ b/libtransmission/file-posix.cc @@ -781,7 +781,7 @@ bool tr_sys_file_flush(tr_sys_file_t handle, tr_error** error) { TR_ASSERT(handle != TR_BAD_SYS_FILE); - bool const ret = (isatty(handle) ? true : (fsync(handle) != -1)); + bool const ret = (isatty(handle) != 0) || (fsync(handle) != -1); if (!ret) { diff --git a/qt/.clang-tidy b/qt/.clang-tidy index bb0b7af3c..867a46fcd 100644 --- a/qt/.clang-tidy +++ b/qt/.clang-tidy @@ -6,35 +6,22 @@ Checks: > -bugprone-branch-clone, -bugprone-easily-swappable-parameters, -bugprone-narrowing-conversions, - -bugprone-unchecked-optional-access, cert-*, - clang-analyzer-optin*, - -clang-diagnostic-c++98*, - -clang-diagnostic-double-promotion, - -clang-diagnostic-exit-time-destructors, - -clang-diagnostic-global-constructors, - -clang-diagnostic-shorten-64-to-32, - -clang-diagnostic-sign-compare, - -clang-diagnostic-sign-conversion, + clang-analyzer-*, cppcoreguidelines-*, -cppcoreguidelines-avoid-magic-numbers, -cppcoreguidelines-macro-usage, -cppcoreguidelines-narrowing-conversions, -cppcoreguidelines-non-private-member-variables-in-classes, -cppcoreguidelines-owning-memory, - -cppcoreguidelines-prefer-member-initializer, - -cppcoreguidelines-pro-bounds-array-to-pointer-decay, -cppcoreguidelines-pro-bounds-constant-array-index, -cppcoreguidelines-pro-bounds-pointer-arithmetic, -cppcoreguidelines-pro-type-const-cast, google-readability-*, - -google-readability-casting, google-runtime-operator, hicpp-*, -hicpp-multiway-paths-covered, - -hicpp-no-array-decay, -hicpp-signed-bitwise, - -hicpp-special-member-functions, misc-*, -misc-no-recursion, -misc-non-private-member-variables-in-classes, @@ -46,9 +33,8 @@ Checks: > -readability-function-cognitive-complexity, -readability-identifier-length, -readability-implicit-bool-conversion, - -readability-inconsistent-declaration-parameter-name, -readability-magic-numbers, - -readability-redundant-access-specifiers + -readability-redundant-access-specifiers, # keep: 'private' vs 'private slots' CheckOptions: - { key: readability-identifier-naming.ClassCase, value: CamelCase } diff --git a/qt/AddData.cc b/qt/AddData.cc index 7c1caf851..34f25384d 100644 --- a/qt/AddData.cc +++ b/qt/AddData.cc @@ -22,7 +22,7 @@ namespace QString getNameFromMetainfo(QByteArray const& benc) { auto metainfo = tr_torrent_metainfo{}; - if (!metainfo.parseBenc({ benc.constData(), size_t(benc.size()) })) + if (!metainfo.parseBenc({ benc.constData(), static_cast(benc.size()) })) { return {}; } diff --git a/qt/Application.cc b/qt/Application.cc index ef1b39e60..704c1e7c2 100644 --- a/qt/Application.cc +++ b/qt/Application.cc @@ -405,16 +405,16 @@ void Application::quitLater() const QTimer::singleShot(0, this, SLOT(quit())); } -void Application::onTorrentsEdited(torrent_ids_t const& ids) const +void Application::onTorrentsEdited(torrent_ids_t const& torrent_ids) const { // the backend's tr_info has changed, so reload those fields - session_->initTorrents(ids); + session_->initTorrents(torrent_ids); } -QStringList Application::getNames(torrent_ids_t const& ids) const +QStringList Application::getNames(torrent_ids_t const& torrent_ids) const { QStringList names; - for (auto const& id : ids) + for (auto const& id : torrent_ids) { names.push_back(model_->getTorrentFromId(id)->name()); } @@ -423,23 +423,25 @@ QStringList Application::getNames(torrent_ids_t const& ids) const return names; } -void Application::onTorrentsAdded(torrent_ids_t const& ids) const +void Application::onTorrentsAdded(torrent_ids_t const& torrent_ids) const { - if (prefs_->getBool(Prefs::SHOW_NOTIFICATION_ON_ADD)) + if (!prefs_->getBool(Prefs::SHOW_NOTIFICATION_ON_ADD)) { - for (auto id : ids) - { - notifyTorrentAdded(model_->getTorrentFromId(id)); - } + return; + } + + for (auto id : torrent_ids) + { + notifyTorrentAdded(model_->getTorrentFromId(id)); } } -void Application::onTorrentsCompleted(torrent_ids_t const& ids) const +void Application::onTorrentsCompleted(torrent_ids_t const& torrent_ids) const { if (prefs_->getBool(Prefs::SHOW_NOTIFICATION_ON_COMPLETE)) { - auto const title = tr("Torrent Completed", nullptr, static_cast(ids.size())); - auto const body = getNames(ids).join(QStringLiteral("\n")); + auto const title = tr("Torrent Completed", nullptr, static_cast(std::size(torrent_ids))); + auto const body = getNames(torrent_ids).join(QStringLiteral("\n")); notifyApp(title, body); } @@ -455,11 +457,11 @@ void Application::onTorrentsCompleted(torrent_ids_t const& ids) const } } -void Application::onTorrentsNeedInfo(torrent_ids_t const& ids) const +void Application::onTorrentsNeedInfo(torrent_ids_t const& torrent_ids) const { - if (!ids.empty()) + if (!torrent_ids.empty()) { - session_->initTorrents(ids); + session_->initTorrents(torrent_ids); } } diff --git a/qt/Application.h b/qt/Application.h index 67b2481f5..e0d475027 100644 --- a/qt/Application.h +++ b/qt/Application.h @@ -54,10 +54,10 @@ public slots: private slots: void consentGiven(int result) const; void onSessionSourceChanged() const; - void onTorrentsAdded(torrent_ids_t const& torrents) const; - void onTorrentsCompleted(torrent_ids_t const& torrents) const; - void onTorrentsEdited(torrent_ids_t const& torrents) const; - void onTorrentsNeedInfo(torrent_ids_t const& torrents) const; + void onTorrentsAdded(torrent_ids_t const& torrent_ids) const; + void onTorrentsCompleted(torrent_ids_t const& torrent_ids) const; + void onTorrentsEdited(torrent_ids_t const& torrent_ids) const; + void onTorrentsNeedInfo(torrent_ids_t const& torrent_ids) const; void refreshPref(int key) const; void refreshTorrents(); void saveGeometry() const; diff --git a/qt/DetailsDialog.cc b/qt/DetailsDialog.cc index b01c50058..3e93ef726 100644 --- a/qt/DetailsDialog.cc +++ b/qt/DetailsDialog.cc @@ -71,7 +71,7 @@ public: } signals: - void trackerListEdited(QString trackerList); + void trackerListEdited(QString /*tracker_list*/); private slots: void onButtonBoxClicked(QAbstractButton* button) @@ -664,7 +664,7 @@ void DetailsDialog::refreshUI() } else { - auto const seconds = int(std::difftime(now, baseline)); + auto const seconds = static_cast(std::difftime(now, baseline)); string = fmt.timeToString(seconds); } } @@ -725,7 +725,7 @@ void DetailsDialog::refreshUI() } } - auto const seconds = int(std::difftime(now, latest)); + auto const seconds = static_cast(std::difftime(now, latest)); if (seconds < 0) { @@ -1037,8 +1037,8 @@ void DetailsDialog::refreshUI() setIfIdle(ui_.bandwidthPriorityCombo, i); - setIfIdle(ui_.singleDownSpin, int(baseline.downloadLimit().getKBps())); - setIfIdle(ui_.singleUpSpin, int(baseline.uploadLimit().getKBps())); + setIfIdle(ui_.singleDownSpin, static_cast(baseline.downloadLimit().getKBps())); + setIfIdle(ui_.singleUpSpin, static_cast(baseline.uploadLimit().getKBps())); setIfIdle(ui_.peerLimitSpin, baseline.peerLimit()); } @@ -1198,7 +1198,9 @@ void DetailsDialog::refreshUI() item->setText(COL_UP, peer.rate_to_peer.isZero() ? QString() : fmt.speedToString(peer.rate_to_peer)); item->setText(COL_DOWN, peer.rate_to_client.isZero() ? QString() : fmt.speedToString(peer.rate_to_client)); - item->setText(COL_PERCENT, peer.progress > 0 ? QStringLiteral("%1%").arg(int(peer.progress * 100.0)) : QString()); + item->setText( + COL_PERCENT, + peer.progress > 0 ? QStringLiteral("%1%").arg(static_cast(peer.progress * 100.0)) : QString()); item->setText(COL_STATUS, code); item->setToolTip(COL_STATUS, code_tip); @@ -1572,9 +1574,9 @@ void DetailsDialog::onFileWantedChanged(QSet const& indices, bool wanted) torrentSet(key, indices.values()); } -void DetailsDialog::onPathEdited(QString const& oldpath, QString const& newname) +void DetailsDialog::onPathEdited(QString const& old_path, QString const& new_name) { - session_.torrentRenamePath(ids_, oldpath, newname); + session_.torrentRenamePath(ids_, old_path, new_name); } void DetailsDialog::onOpenRequested(QString const& path) const diff --git a/qt/FileTreeDelegate.cc b/qt/FileTreeDelegate.cc index 6174db162..94182f2b7 100644 --- a/qt/FileTreeDelegate.cc +++ b/qt/FileTreeDelegate.cc @@ -56,7 +56,7 @@ void FileTreeDelegate::paint(QPainter* painter, QStyleOptionViewItem const& opti p.maximum = 100; p.textAlignment = Qt::AlignCenter; p.textVisible = true; - p.progress = int(100.0 * index.data().toDouble()); + p.progress = static_cast(100.0 * index.data().toDouble()); p.text = QStringLiteral("%1%").arg(p.progress); style->drawControl(QStyle::CE_ProgressBar, &p, painter); } diff --git a/qt/FileTreeItem.cc b/qt/FileTreeItem.cc index b5eea8a3a..82affff39 100644 --- a/qt/FileTreeItem.cc +++ b/qt/FileTreeItem.cc @@ -337,11 +337,11 @@ int FileTreeItem::priority() const return i; } -void FileTreeItem::setSubtreePriority(int i, QSet& ids) +void FileTreeItem::setSubtreePriority(int priority, QSet& ids) { - if (priority_ != i) + if (priority_ != priority) { - priority_ = i; + priority_ = priority; if (file_index_ >= 0) { @@ -351,7 +351,7 @@ void FileTreeItem::setSubtreePriority(int i, QSet& ids) for (FileTreeItem* const child : children_) { - child->setSubtreePriority(i, ids); + child->setSubtreePriority(priority, ids); } } diff --git a/qt/FileTreeModel.cc b/qt/FileTreeModel.cc index 787bb5405..f7433e2e8 100644 --- a/qt/FileTreeModel.cc +++ b/qt/FileTreeModel.cc @@ -173,13 +173,13 @@ Qt::ItemFlags FileTreeModel::flags(QModelIndex const& index) const return { i }; } -bool FileTreeModel::setData(QModelIndex const& index, QVariant const& newname, int role) +bool FileTreeModel::setData(QModelIndex const& index, QVariant const& value, int role) { if (role == Qt::EditRole) { FileTreeItem const* item = itemFromIndex(index); - emit pathEdited(item->path(), newname.toString()); + emit pathEdited(item->path(), value.toString()); } return false; // don't update the view until the session confirms the change diff --git a/qt/FileTreeModel.h b/qt/FileTreeModel.h index a7077935a..8fdad1a02 100644 --- a/qt/FileTreeModel.h +++ b/qt/FileTreeModel.h @@ -54,7 +54,7 @@ public: int priority, uint64_t size, uint64_t have, - bool torrent_changed); + bool update_fields); bool openFile(QModelIndex const& index); @@ -69,7 +69,7 @@ public: // QAbstractItemModel QVariant data(QModelIndex const& index, int role = Qt::DisplayRole) const override; Qt::ItemFlags flags(QModelIndex const& index) const override; - QVariant headerData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const override; + QVariant headerData(int column, Qt::Orientation orientation, int role = Qt::DisplayRole) const override; QModelIndex index(int row, int column, QModelIndex const& parent = {}) const override; QModelIndex parent(QModelIndex const& child) const override; int rowCount(QModelIndex const& parent = {}) const override; diff --git a/qt/FileTreeView.h b/qt/FileTreeView.h index e8cc68dc2..c37d4d0e5 100644 --- a/qt/FileTreeView.h +++ b/qt/FileTreeView.h @@ -28,7 +28,7 @@ public: FileTreeView(QWidget* parent = nullptr, bool editable = true); void clear(); - void update(FileList const& files, bool update_properties = true); + void update(FileList const& files, bool update_fields = true); void setEditable(bool editable); diff --git a/qt/FilterBar.cc b/qt/FilterBar.cc index 05ed7488f..3408be8aa 100644 --- a/qt/FilterBar.cc +++ b/qt/FilterBar.cc @@ -99,7 +99,7 @@ QString getCountString(size_t n) } Torrent::fields_t constexpr TrackerFields = { - uint64_t(1) << Torrent::TRACKER_STATS, + static_cast(1) << Torrent::TRACKER_STATS, }; auto constexpr ActivityFields = FilterMode::TorrentFields; @@ -127,7 +127,7 @@ void FilterBar::refreshTrackers() // update the "All" row auto const num_trackers = torrents_per_sitename.size(); auto* item = tracker_model_->item(ROW_TOTALS); - item->setData(int(num_trackers), FilterBarComboBox::CountRole); + item->setData(static_cast(num_trackers), FilterBarComboBox::CountRole); item->setData(getCountString(num_trackers), FilterBarComboBox::CountStringRole); auto update_tracker_item = [](QStandardItem* i, auto const& it) @@ -140,7 +140,7 @@ void FilterBar::refreshTrackers() i->setData(display_name, TRACKER_ROLE); i->setData(getCountString(static_cast(count)), FilterBarComboBox::CountStringRole); i->setData(icon, Qt::DecorationRole); - i->setData(int(count), FilterBarComboBox::CountRole); + i->setData(static_cast(count), FilterBarComboBox::CountRole); return i; }; @@ -221,16 +221,13 @@ FilterBar::FilterBar(Prefs& prefs, TorrentModel const& torrents, TorrentFilter c count_label_ = new QLabel(tr("Show:"), this); h->addWidget(count_label_); - activity_combo_ = createActivityCombo(); h->addWidget(activity_combo_); - tracker_model_ = new QStandardItemModel(this); tracker_combo_ = createTrackerCombo(tracker_model_); h->addWidget(tracker_combo_); h->addStretch(); - line_edit_ = new QLineEdit(this); line_edit_->setClearButtonEnabled(true); line_edit_->setPlaceholderText(tr("Search...")); line_edit_->setMaximumWidth(250); @@ -249,7 +246,7 @@ FilterBar::FilterBar(Prefs& prefs, TorrentModel const& torrents, TorrentFilter c connect(&trApp->faviconCache(), &FaviconCache::pixmapReady, this, &FilterBar::recountTrackersSoon); recountAllSoon(); - is_bootstrapping_ = false; + is_bootstrapping_ = false; // NOLINT cppcoreguidelines-prefer-member-initializer // initialize our state for (int const key : { Prefs::FILTER_MODE, Prefs::FILTER_TRACKERS }) @@ -354,9 +351,9 @@ void FilterBar::onActivityIndexChanged(int i) **** ***/ -void FilterBar::recountSoon(Pending const& pending) +void FilterBar::recountSoon(Pending const& fields) { - pending_ |= pending; + pending_ |= fields; if (!recount_timer_.isActive()) { diff --git a/qt/FilterBar.h b/qt/FilterBar.h index 9e29c6860..241602309 100644 --- a/qt/FilterBar.h +++ b/qt/FilterBar.h @@ -8,6 +8,8 @@ #include #include +#include +#include #include #include @@ -18,8 +20,6 @@ #include "Typedefs.h" class QLabel; -class QLineEdit; -class QStandardItemModel; class QString; class FilterBarComboBox; @@ -58,12 +58,12 @@ private: TorrentFilter const& filter_; std::map sitename_counts_; - FilterBarComboBox* activity_combo_ = {}; + FilterBarComboBox* const activity_combo_ = createActivityCombo(); FilterBarComboBox* tracker_combo_ = {}; QLabel* count_label_ = {}; - QStandardItemModel* tracker_model_ = {}; + QStandardItemModel* const tracker_model_ = new QStandardItemModel{ this }; QTimer recount_timer_; - QLineEdit* line_edit_ = {}; + QLineEdit* const line_edit_ = new QLineEdit{ this }; Pending pending_ = {}; bool is_bootstrapping_ = {}; diff --git a/qt/FreeSpaceLabel.h b/qt/FreeSpaceLabel.h index 7c175d240..e435f32b6 100644 --- a/qt/FreeSpaceLabel.h +++ b/qt/FreeSpaceLabel.h @@ -27,7 +27,7 @@ public: explicit FreeSpaceLabel(QWidget* parent = nullptr); void setSession(Session& session); - void setPath(QString const& folder); + void setPath(QString const& path); private slots: void onTimer(); diff --git a/qt/MainWindow.h b/qt/MainWindow.h index df84a840a..b079564a0 100644 --- a/qt/MainWindow.h +++ b/qt/MainWindow.h @@ -125,7 +125,7 @@ private slots: private: QIcon addEmblem(QIcon icon, QStringList const& emblem_names) const; - torrent_ids_t getSelectedTorrents(bool withMetadataOnly = false) const; + torrent_ids_t getSelectedTorrents(bool with_metadata_only = false) const; void updateNetworkIcon(); QMenu* createOptionsMenu(); diff --git a/qt/PrefsDialog.h b/qt/PrefsDialog.h index 042a10e6b..da907316a 100644 --- a/qt/PrefsDialog.h +++ b/qt/PrefsDialog.h @@ -29,7 +29,7 @@ public: PrefsDialog(Session&, Prefs&, QWidget* parent = nullptr); private slots: - void focusChanged(QWidget* old, QWidget* now); + void focusChanged(QWidget* old, QWidget* cur); void checkBoxToggled(bool checked); void spinBoxEditingFinished(); void timeEditingFinished(); diff --git a/qt/RpcClient.cc b/qt/RpcClient.cc index 81fa6f39f..9de81b160 100644 --- a/qt/RpcClient.cc +++ b/qt/RpcClient.cc @@ -283,23 +283,23 @@ void RpcClient::localRequestFinished(TrVariantPtr response) promise.reportFinished(&result); } -int64_t RpcClient::parseResponseTag(tr_variant& json) const +int64_t RpcClient::parseResponseTag(tr_variant& response) const { - auto const tag = dictFind(&json, TR_KEY_tag); + auto const tag = dictFind(&response, TR_KEY_tag); return tag ? *tag : -1; } -RpcResponse RpcClient::parseResponseData(tr_variant& json) const +RpcResponse RpcClient::parseResponseData(tr_variant& response) const { RpcResponse ret; - if (auto const result = dictFind(&json, TR_KEY_result); result) + if (auto const result = dictFind(&response, TR_KEY_result); result) { ret.result = *result; ret.success = *result == QStringLiteral("success"); } - if (tr_variant* args = nullptr; tr_variantDictFindDict(&json, TR_KEY_arguments, &args)) + if (tr_variant* args = nullptr; tr_variantDictFindDict(&response, TR_KEY_arguments, &args)) { ret.args = createVariant(); *ret.args = *args; diff --git a/qt/Session.cc b/qt/Session.cc index 9db5abc25..3d1950578 100644 --- a/qt/Session.cc +++ b/qt/Session.cc @@ -288,10 +288,6 @@ Session::Session(QString config_dir, Prefs& prefs) : config_dir_(std::move(config_dir)) , prefs_(prefs) { - stats_ = {}; - stats_.ratio = TR_RATIO_NA; - cumulative_stats_ = stats_; - connect(&prefs_, &Prefs::changed, this, &Session::updatePref); connect(&rpc_, &RpcClient::httpAuthenticationRequired, this, &Session::httpAuthenticationRequired); connect(&rpc_, &RpcClient::dataReadProgress, this, &Session::dataReadProgress); @@ -383,17 +379,17 @@ bool Session::isLocal() const **** ***/ -void Session::addOptionalIds(tr_variant* args, torrent_ids_t const& ids) const +void Session::addOptionalIds(tr_variant* args_dict, torrent_ids_t const& torrent_ids) const { auto constexpr RecentlyActiveKey = std::string_view{ "recently-active" }; - if (&ids == &RecentlyActiveIDs) + if (&torrent_ids == &RecentlyActiveIDs) { - dictAdd(args, TR_KEY_ids, RecentlyActiveKey); + dictAdd(args_dict, TR_KEY_ids, RecentlyActiveKey); } - else if (!ids.empty()) + else if (!std::empty(torrent_ids)) { - dictAdd(args, TR_KEY_ids, ids); + dictAdd(args_dict, TR_KEY_ids, torrent_ids); } } @@ -410,76 +406,76 @@ Session::Tag Session::torrentSetImpl(tr_variant* args) return tag; } -Session::Tag Session::torrentSet(torrent_ids_t const& ids, tr_quark const key, double value) +Session::Tag Session::torrentSet(torrent_ids_t const& torrent_ids, tr_quark const key, double value) { tr_variant args; tr_variantInitDict(&args, 2); - addOptionalIds(&args, ids); + addOptionalIds(&args, torrent_ids); dictAdd(&args, key, value); return torrentSetImpl(&args); } -Session::Tag Session::torrentSet(torrent_ids_t const& ids, tr_quark const key, int value) +Session::Tag Session::torrentSet(torrent_ids_t const& torrent_ids, tr_quark const key, int value) { tr_variant args; tr_variantInitDict(&args, 2); - addOptionalIds(&args, ids); + addOptionalIds(&args, torrent_ids); dictAdd(&args, key, value); return torrentSetImpl(&args); } -Session::Tag Session::torrentSet(torrent_ids_t const& ids, tr_quark const key, bool value) +Session::Tag Session::torrentSet(torrent_ids_t const& torrent_ids, tr_quark const key, bool value) { tr_variant args; tr_variantInitDict(&args, 2); - addOptionalIds(&args, ids); + addOptionalIds(&args, torrent_ids); dictAdd(&args, key, value); return torrentSetImpl(&args); } -Session::Tag Session::torrentSet(torrent_ids_t const& ids, tr_quark const key, QString const& value) +Session::Tag Session::torrentSet(torrent_ids_t const& torrent_ids, tr_quark const key, QString const& value) { tr_variant args; tr_variantInitDict(&args, 2); - addOptionalIds(&args, ids); + addOptionalIds(&args, torrent_ids); dictAdd(&args, key, value); return torrentSetImpl(&args); } -Session::Tag Session::torrentSet(torrent_ids_t const& ids, tr_quark const key, QStringList const& value) +Session::Tag Session::torrentSet(torrent_ids_t const& torrent_ids, tr_quark const key, QStringList const& value) { tr_variant args; tr_variantInitDict(&args, 2); - addOptionalIds(&args, ids); + addOptionalIds(&args, torrent_ids); dictAdd(&args, key, value); return torrentSetImpl(&args); } -Session::Tag Session::torrentSet(torrent_ids_t const& ids, tr_quark const key, QList const& value) +Session::Tag Session::torrentSet(torrent_ids_t const& torrent_ids, tr_quark const key, QList const& value) { tr_variant args; tr_variantInitDict(&args, 2); - addOptionalIds(&args, ids); + addOptionalIds(&args, torrent_ids); dictAdd(&args, key, value); return torrentSetImpl(&args); } -void Session::torrentSetLocation(torrent_ids_t const& ids, QString const& location, bool do_move) +void Session::torrentSetLocation(torrent_ids_t const& torrent_ids, QString const& path, bool do_move) { tr_variant args; tr_variantInitDict(&args, 3); - addOptionalIds(&args, ids); - dictAdd(&args, TR_KEY_location, location); + addOptionalIds(&args, torrent_ids); + dictAdd(&args, TR_KEY_location, path); dictAdd(&args, TR_KEY_move, do_move); exec(TR_KEY_torrent_set_location, &args); } -void Session::torrentRenamePath(torrent_ids_t const& ids, QString const& oldpath, QString const& newname) +void Session::torrentRenamePath(torrent_ids_t const& torrent_ids, QString const& oldpath, QString const& newname) { tr_variant args; tr_variantInitDict(&args, 2); - addOptionalIds(&args, ids); + addOptionalIds(&args, torrent_ids); dictAdd(&args, TR_KEY_path, oldpath); dictAdd(&args, TR_KEY_name, newname); @@ -507,7 +503,7 @@ void Session::torrentRenamePath(torrent_ids_t const& ids, QString const& oldpath d->show(); }); - q->add([this, ids](RpcResponse const& /*r*/) { refreshTorrents(ids, TorrentProperties::Rename); }); + q->add([this, torrent_ids](RpcResponse const& /*r*/) { refreshTorrents(torrent_ids, TorrentProperties::Rename); }); q->run(); } @@ -645,7 +641,7 @@ std::vector const& Session::getKeyNames(TorrentProperties prop return names; } -void Session::refreshTorrents(torrent_ids_t const& ids, TorrentProperties props) +void Session::refreshTorrents(torrent_ids_t const& torrent_ids, TorrentProperties props) { auto constexpr Table = std::string_view{ "table" }; @@ -653,13 +649,13 @@ void Session::refreshTorrents(torrent_ids_t const& ids, TorrentProperties props) tr_variantInitDict(&args, 3); dictAdd(&args, TR_KEY_format, Table); dictAdd(&args, TR_KEY_fields, getKeyNames(props)); - addOptionalIds(&args, ids); + addOptionalIds(&args, torrent_ids); auto* q = new RpcQueue(); q->add([this, &args]() { return exec(TR_KEY_torrent_get, &args); }); - bool const all_torrents = ids.empty(); + bool const all_torrents = std::empty(torrent_ids); q->add( [this, all_torrents](RpcResponse const& r) @@ -690,17 +686,17 @@ void Session::refreshExtraStats(torrent_ids_t const& ids) refreshTorrents(ids, TorrentProperties::DetailStat); } -void Session::sendTorrentRequest(std::string_view request, torrent_ids_t const& ids) +void Session::sendTorrentRequest(std::string_view request, torrent_ids_t const& torrent_ids) { tr_variant args; tr_variantInitDict(&args, 1); - addOptionalIds(&args, ids); + addOptionalIds(&args, torrent_ids); auto* q = new RpcQueue(); q->add([this, request, &args]() { return exec(request, &args); }); - q->add([this, ids]() { refreshTorrents(ids, TorrentProperties::MainStats); }); + q->add([this, torrent_ids]() { refreshTorrents(torrent_ids, TorrentProperties::MainStats); }); q->run(); } @@ -812,29 +808,29 @@ RpcResponseFuture Session::exec(std::string_view method, tr_variant* args) return rpc_.exec(method, args); } -void Session::updateStats(tr_variant* d, tr_session_stats* stats) +void Session::updateStats(tr_variant* args_dict, tr_session_stats* stats) { - if (auto const value = dictFind(d, TR_KEY_uploadedBytes); value) + if (auto const value = dictFind(args_dict, TR_KEY_uploadedBytes); value) { stats->uploadedBytes = *value; } - if (auto const value = dictFind(d, TR_KEY_downloadedBytes); value) + if (auto const value = dictFind(args_dict, TR_KEY_downloadedBytes); value) { stats->downloadedBytes = *value; } - if (auto const value = dictFind(d, TR_KEY_filesAdded); value) + if (auto const value = dictFind(args_dict, TR_KEY_filesAdded); value) { stats->filesAdded = *value; } - if (auto const value = dictFind(d, TR_KEY_sessionCount); value) + if (auto const value = dictFind(args_dict, TR_KEY_sessionCount); value) { stats->sessionCount = *value; } - if (auto const value = dictFind(d, TR_KEY_secondsActive); value) + if (auto const value = dictFind(args_dict, TR_KEY_secondsActive); value) { stats->secondsActive = *value; } @@ -857,13 +853,13 @@ void Session::updateStats(tr_variant* dict) emit statsUpdated(); } -void Session::updateInfo(tr_variant* d) +void Session::updateInfo(tr_variant* args_dict) { disconnect(&prefs_, &Prefs::changed, this, &Session::updatePref); for (int i = Prefs::FIRST_CORE_PREF; i <= Prefs::LAST_CORE_PREF; ++i) { - tr_variant const* b(tr_variantDictFind(d, prefs_.getKey(i))); + tr_variant const* b(tr_variantDictFind(args_dict, prefs_.getKey(i))); if (b == nullptr) { @@ -932,12 +928,12 @@ void Session::updateInfo(tr_variant* d) } } - if (auto const b = dictFind(d, TR_KEY_seedRatioLimited); b) + if (auto const b = dictFind(args_dict, TR_KEY_seedRatioLimited); b) { prefs_.set(Prefs::RATIO_ENABLED, *b); } - if (auto const x = dictFind(d, TR_KEY_seedRatioLimit); x) + if (auto const x = dictFind(args_dict, TR_KEY_seedRatioLimit); x) { prefs_.set(Prefs::RATIO, *x); } @@ -954,17 +950,17 @@ void Session::updateInfo(tr_variant* d) prefs_.set(Prefs::RPC_WHITELIST, QString::fromUtf8(tr_sessionGetRPCWhitelist(session_))); } - if (auto const size = dictFind(d, TR_KEY_blocklist_size); size && *size != blocklistSize()) + if (auto const size = dictFind(args_dict, TR_KEY_blocklist_size); size && *size != blocklistSize()) { setBlocklistSize(*size); } - if (auto const str = dictFind(d, TR_KEY_version); str) + if (auto const str = dictFind(args_dict, TR_KEY_version); str) { session_version_ = *str; } - if (auto const str = dictFind(d, TR_KEY_session_id); str) + if (auto const str = dictFind(args_dict, TR_KEY_session_id); str) { session_id_ = *str; is_definitely_local_session_ = tr_session_id::isLocal(session_id_.toUtf8().constData()); @@ -986,30 +982,30 @@ void Session::setBlocklistSize(int64_t i) emit blocklistUpdated(i); } -void Session::addTorrent(AddData add_me, tr_variant* args, bool trash_original) +void Session::addTorrent(AddData add_me, tr_variant* args_dict, bool trash_original) { - assert(tr_variantDictFind(args, TR_KEY_filename) == nullptr); - assert(tr_variantDictFind(args, TR_KEY_metainfo) == nullptr); + assert(tr_variantDictFind(args_dict, TR_KEY_filename) == nullptr); + assert(tr_variantDictFind(args_dict, TR_KEY_metainfo) == nullptr); - if (tr_variantDictFind(args, TR_KEY_paused) == nullptr) + if (tr_variantDictFind(args_dict, TR_KEY_paused) == nullptr) { - dictAdd(args, TR_KEY_paused, !prefs_.getBool(Prefs::START)); + dictAdd(args_dict, TR_KEY_paused, !prefs_.getBool(Prefs::START)); } switch (add_me.type) { case AddData::MAGNET: - dictAdd(args, TR_KEY_filename, add_me.magnet); + dictAdd(args_dict, TR_KEY_filename, add_me.magnet); break; case AddData::URL: - dictAdd(args, TR_KEY_filename, add_me.url.toString()); + dictAdd(args_dict, TR_KEY_filename, add_me.url.toString()); break; case AddData::FILENAME: [[fallthrough]]; case AddData::METAINFO: - dictAdd(args, TR_KEY_metainfo, add_me.toBase64()); + dictAdd(args_dict, TR_KEY_metainfo, add_me.toBase64()); break; default: @@ -1020,7 +1016,7 @@ void Session::addTorrent(AddData add_me, tr_variant* args, bool trash_original) auto* q = new RpcQueue(); q->add( - [this, args]() { return exec("torrent-add", args); }, + [this, args_dict]() { return exec("torrent-add", args_dict); }, [add_me](RpcResponse const& r) { auto* d = new QMessageBox( diff --git a/qt/Session.h b/qt/Session.h index cb4a50e68..edc4fdee7 100644 --- a/qt/Session.h +++ b/qt/Session.h @@ -84,27 +84,27 @@ public: RpcResponseFuture exec(std::string_view method, tr_variant* args); using Tag = RpcQueue::Tag; - Tag torrentSet(torrent_ids_t const& ids, tr_quark const key, bool val); - Tag torrentSet(torrent_ids_t const& ids, tr_quark const key, int val); - Tag torrentSet(torrent_ids_t const& ids, tr_quark const key, double val); - Tag torrentSet(torrent_ids_t const& ids, tr_quark const key, QString const& val); - Tag torrentSet(torrent_ids_t const& ids, tr_quark const key, QList const& val); - Tag torrentSet(torrent_ids_t const& ids, tr_quark const key, QStringList const& val); + Tag torrentSet(torrent_ids_t const& torrent_ids, tr_quark const key, bool val); + Tag torrentSet(torrent_ids_t const& torrent_ids, tr_quark const key, int val); + Tag torrentSet(torrent_ids_t const& torrent_ids, tr_quark const key, double val); + Tag torrentSet(torrent_ids_t const& torrent_ids, tr_quark const key, QString const& val); + Tag torrentSet(torrent_ids_t const& torrent_ids, tr_quark const key, QList const& val); + Tag torrentSet(torrent_ids_t const& torrent_ids, tr_quark const key, QStringList const& val); - void torrentSetLocation(torrent_ids_t const& ids, QString const& path, bool do_move); - void torrentRenamePath(torrent_ids_t const& ids, QString const& oldpath, QString const& newname); - void addTorrent(AddData addme, tr_variant* top, bool trash_original); + void torrentSetLocation(torrent_ids_t const& torrent_ids, QString const& path, bool do_move); + void torrentRenamePath(torrent_ids_t const& torrent_ids, QString const& oldpath, QString const& newname); + void addTorrent(AddData add_me, tr_variant* args_dict, bool trash_original); void initTorrents(torrent_ids_t const& ids = {}); - void pauseTorrents(torrent_ids_t const& torrentIds = {}); - void startTorrents(torrent_ids_t const& torrentIds = {}); - void startTorrentsNow(torrent_ids_t const& torrentIds = {}); + void pauseTorrents(torrent_ids_t const& torrent_ids = {}); + void startTorrents(torrent_ids_t const& torrent_ids = {}); + void startTorrentsNow(torrent_ids_t const& torrent_ids = {}); void refreshDetailInfo(torrent_ids_t const& torrent_ids); void refreshActiveTorrents(); void refreshAllTorrents(); void addNewlyCreatedTorrent(QString const& filename, QString const& local_path); void verifyTorrents(torrent_ids_t const& torrent_ids); void reannounceTorrents(torrent_ids_t const& torrent_ids); - void refreshExtraStats(torrent_ids_t const& ids); + void refreshExtraStats(torrent_ids_t const& torrent_ids); enum class TorrentProperties { @@ -117,7 +117,7 @@ public: }; public slots: - void addTorrent(AddData addme); + void addTorrent(AddData add_me); void launchWebInterface() const; void queueMoveBottom(torrent_ids_t const& torrentIds = {}); void queueMoveDown(torrent_ids_t const& torrentIds = {}); @@ -148,19 +148,19 @@ private slots: private: void start(); - void updateStats(tr_variant* args); - void updateInfo(tr_variant* args); + void updateStats(tr_variant* args_dict); + void updateInfo(tr_variant* args_dict); Tag torrentSetImpl(tr_variant* args); - void sessionSet(tr_quark const key, QVariant const& variant); + void sessionSet(tr_quark const key, QVariant const& value); void pumpRequests(); void sendTorrentRequest(std::string_view request, torrent_ids_t const& torrent_ids); void refreshTorrents(torrent_ids_t const& ids, TorrentProperties props); std::vector const& getKeyNames(TorrentProperties props); - static void updateStats(tr_variant* d, tr_session_stats* stats); + static void updateStats(tr_variant* args_dict, tr_session_stats* stats); - void addOptionalIds(tr_variant* args, torrent_ids_t const& ids) const; + void addOptionalIds(tr_variant* args_dict, torrent_ids_t const& torrent_ids) const; QString const config_dir_; Prefs& prefs_; @@ -170,8 +170,8 @@ private: int64_t blocklist_size_ = -1; tr_session* session_ = {}; QStringList idle_json_; - tr_session_stats stats_ = {}; - tr_session_stats cumulative_stats_ = {}; + tr_session_stats stats_ = EmptyStats; + tr_session_stats cumulative_stats_ = EmptyStats; QString session_version_; QString session_id_; bool is_definitely_local_session_ = true; @@ -180,4 +180,6 @@ private: std::map duplicates_; QTimer duplicates_timer_; + + static auto constexpr EmptyStats = tr_session_stats{ TR_RATIO_NA, 0, 0, 0, 0, 0 }; }; diff --git a/qt/SqueezeLabel.cc b/qt/SqueezeLabel.cc index 1bdf3bef0..49bcd54db 100644 --- a/qt/SqueezeLabel.cc +++ b/qt/SqueezeLabel.cc @@ -55,11 +55,11 @@ SqueezeLabel::SqueezeLabel(QWidget* parent) { } -void SqueezeLabel::paintEvent(QPaintEvent* paintEvent) +void SqueezeLabel::paintEvent(QPaintEvent* paint_event) { if (hasFocus() && (textInteractionFlags() & (Qt::TextSelectableByKeyboard | Qt::TextSelectableByMouse)) != 0) { - return QLabel::paintEvent(paintEvent); + return QLabel::paintEvent(paint_event); } QPainter painter(this); diff --git a/qt/TorrentDelegate.cc b/qt/TorrentDelegate.cc index 8e901200f..f9edba389 100644 --- a/qt/TorrentDelegate.cc +++ b/qt/TorrentDelegate.cc @@ -398,7 +398,7 @@ QString TorrentDelegate::statusString(Torrent const& tor) QSize TorrentDelegate::sizeHint(QStyleOptionViewItem const& option, Torrent const& tor) const { - auto const m = QSize(margin(*QApplication::style())); + auto const m = margin(*QApplication::style()); auto const layout = ItemLayout( tor.name(), progressString(tor), diff --git a/qt/TorrentDelegateMin.cc b/qt/TorrentDelegateMin.cc index d2f020a5d..6d9b92155 100644 --- a/qt/TorrentDelegateMin.cc +++ b/qt/TorrentDelegateMin.cc @@ -108,7 +108,7 @@ ItemLayout::ItemLayout( int const icon_size = style->pixelMetric(QStyle::PM_SmallIconSize); auto const name_fm = QFontMetrics(name_font); - auto const name_size = QSize(name_fm.size(0, name_text_)); + auto const name_size = name_fm.size(0, name_text_); status_font.setPointSize(static_cast(status_font.pointSize() * 0.85)); QFontMetrics const status_fm(status_font); @@ -148,8 +148,8 @@ ItemLayout::ItemLayout( QSize TorrentDelegateMin::sizeHint(QStyleOptionViewItem const& option, Torrent const& tor) const { - auto const is_magnet = bool(!tor.hasMetadata()); - auto const m = QSize(margin(*QApplication::style())); + auto const is_magnet = !tor.hasMetadata(); + auto const m = margin(*QApplication::style()); auto const layout = ItemLayout( is_magnet ? progressString(tor) : tor.name(), shortStatusString(tor), diff --git a/qt/TorrentModel.cc b/qt/TorrentModel.cc index 9074e53c4..0ff978a67 100644 --- a/qt/TorrentModel.cc +++ b/qt/TorrentModel.cc @@ -118,14 +118,14 @@ QVariant TorrentModel::data(QModelIndex const& index, int role) const **** ***/ -void TorrentModel::removeTorrents(tr_variant* list) +void TorrentModel::removeTorrents(tr_variant* torrent_list) { - torrents_t torrents; - torrents.reserve(tr_variantListSize(list)); + auto torrents = torrents_t{}; + torrents.reserve(tr_variantListSize(torrent_list)); int i = 0; tr_variant const* child = nullptr; - while ((child = tr_variantListChild(list, i++)) != nullptr) + while ((child = tr_variantListChild(torrent_list, i++)) != nullptr) { if (auto const id = getValue(child); id) { @@ -142,7 +142,7 @@ void TorrentModel::removeTorrents(tr_variant* list) } } -void TorrentModel::updateTorrents(tr_variant* torrents, bool is_complete_list) +void TorrentModel::updateTorrents(tr_variant* torrent_list, bool is_complete_list) { auto const old = is_complete_list ? torrents_ : torrents_t{}; auto added = torrent_ids_t{}; @@ -163,7 +163,7 @@ void TorrentModel::updateTorrents(tr_variant* torrents, bool is_complete_list) }; // build a list of the property keys - tr_variant* const first_child = tr_variantListChild(torrents, 0); + tr_variant* const first_child = tr_variantListChild(torrent_list, 0); bool const table = tr_variantIsList(first_child); std::vector keys; if (table) @@ -202,9 +202,9 @@ void TorrentModel::updateTorrents(tr_variant* torrents, bool is_complete_list) std::vector values; values.reserve(keys.size()); size_t tor_index = table ? 1 : 0; - processed.reserve(tr_variantListSize(torrents)); + processed.reserve(tr_variantListSize(torrent_list)); tr_variant* v = nullptr; - while ((v = tr_variantListChild(torrents, tor_index++))) + while ((v = tr_variantListChild(torrent_list, tor_index++))) { // Build an array of values values.clear(); diff --git a/qt/VariantHelpers.cc b/qt/VariantHelpers.cc index 0e127b0ab..ef6b036a9 100644 --- a/qt/VariantHelpers.cc +++ b/qt/VariantHelpers.cc @@ -31,10 +31,10 @@ bool change(double& setme, double const& value) return changed; } -bool change(Speed& setme, tr_variant const* variant) +bool change(Speed& setme, tr_variant const* value) { - auto const value = getValue(variant); - return value && change(setme, Speed::fromBps(*value)); + auto const bytes_per_second = getValue(value); + return bytes_per_second && change(setme, Speed::fromBps(*bytes_per_second)); } bool change(TorrentHash& setme, tr_variant const* value)