From 8fcfc1e4aeb5a5fe9ff663135e86196c66488678 Mon Sep 17 00:00:00 2001 From: Charles Kerr Date: Thu, 18 Jun 2020 15:34:11 -0500 Subject: [PATCH] feat: add 'edit-date' support to qt client (#1322) edit-date got added to the backend in 3.00, but I never finished adding it properly to the Qt client. This PR rectifies that. When a torrent is edited, the Application and DetailsDialogs will re-query the backend to update the torrent properties that are needed. --- qt/Application.cc | 1 + qt/DetailsDialog.cc | 24 +++++++++++++++++++----- qt/DetailsDialog.h | 2 +- qt/Torrent.cc | 1 + qt/Torrent.h | 5 +++++ qt/TorrentModel.cc | 13 +++++++++++++ 6 files changed, 40 insertions(+), 6 deletions(-) diff --git a/qt/Application.cc b/qt/Application.cc index 534f22b6c..d36240bee 100644 --- a/qt/Application.cc +++ b/qt/Application.cc @@ -285,6 +285,7 @@ Application::Application(int& argc, char** argv) : connect(model_, &TorrentModel::torrentsAdded, this, &Application::onTorrentsAdded); connect(model_, &TorrentModel::torrentsCompleted, this, &Application::onTorrentsCompleted); + connect(model_, &TorrentModel::torrentsEdited, this, &Application::onTorrentsEdited); connect(model_, &TorrentModel::torrentsNeedInfo, this, &Application::onTorrentsNeedInfo); connect(prefs_, &Prefs::changed, this, &Application::refreshPref); connect(session_, &Session::sourceChanged, this, &Application::onSessionSourceChanged); diff --git a/qt/DetailsDialog.cc b/qt/DetailsDialog.cc index 0d3d9a45d..6d3989467 100644 --- a/qt/DetailsDialog.cc +++ b/qt/DetailsDialog.cc @@ -6,9 +6,8 @@ * */ -#include // std::any_of +#include #include -#include /* INT_MAX */ #include #include @@ -231,6 +230,7 @@ DetailsDialog::DetailsDialog(Session& session, Prefs& prefs, TorrentModel const& } connect(&model_, &TorrentModel::torrentsChanged, this, &DetailsDialog::onTorrentsChanged); + connect(&model_, &TorrentModel::torrentsEdited, this, &DetailsDialog::onTorrentsEdited); connect(&prefs_, &Prefs::changed, this, &DetailsDialog::refreshPref); connect(&timer_, &QTimer::timeout, this, &DetailsDialog::onTimer); @@ -306,10 +306,24 @@ void DetailsDialog::getNewData() } } -void DetailsDialog::onTorrentEdited(torrent_ids_t const& /*ids*/) +void DetailsDialog::onTorrentsEdited(torrent_ids_t const& ids) { - // FIXME - // refreshDetailInfo({ tor.id() }); + // std::set_intersection requires sorted inputs + auto a = std::vector{ ids.begin(), ids.end() }; + std::sort(std::begin(a), std::end(a)); + auto b = std::vector{ ids_.begin(), ids_.end() }; + std::sort(std::begin(b), std::end(b)); + + // are any of the edited torrents on display here? + torrent_ids_t interesting_ids; + std::set_intersection(std::begin(a), std::end(a), + std::begin(b), std::end(b), + std::inserter(interesting_ids, std::begin(interesting_ids))); + + if (!interesting_ids.empty()) + { + session_.refreshDetailInfo(interesting_ids); + } } void DetailsDialog::onTorrentsChanged(torrent_ids_t const& ids) diff --git a/qt/DetailsDialog.h b/qt/DetailsDialog.h index f20a3256d..0c1da2ba4 100644 --- a/qt/DetailsDialog.h +++ b/qt/DetailsDialog.h @@ -61,7 +61,7 @@ private slots: void refreshPref(int key); void onTimer(); - void onTorrentEdited(torrent_ids_t const& ids); + void onTorrentsEdited(torrent_ids_t const& ids); void onTorrentsChanged(torrent_ids_t const& ids); // Tracker tab diff --git a/qt/Torrent.cc b/qt/Torrent.cc index 9e9101b4a..1680dbaa0 100644 --- a/qt/Torrent.cc +++ b/qt/Torrent.cc @@ -40,6 +40,7 @@ Torrent::KeyList const Torrent::MainInfoKeys{ // changing fields needed by the main window Torrent::KeyList const Torrent::MainStatKeys{ TR_KEY_downloadedEver, + TR_KEY_editDate, TR_KEY_error, TR_KEY_errorString, TR_KEY_eta, diff --git a/qt/Torrent.h b/qt/Torrent.h index e6012cce2..ad708fb40 100644 --- a/qt/Torrent.h +++ b/qt/Torrent.h @@ -295,6 +295,11 @@ public: return date_created_; } + time_t dateEdited() const + { + return edit_date_; + } + time_t manualAnnounceTime() const { return manual_announce_time_; diff --git a/qt/TorrentModel.cc b/qt/TorrentModel.cc index 02e734bfd..dc635f6c4 100644 --- a/qt/TorrentModel.cc +++ b/qt/TorrentModel.cc @@ -157,6 +157,7 @@ void TorrentModel::updateTorrents(tr_variant* torrents, bool is_complete_list) auto added = torrent_ids_t{}; auto changed = torrent_ids_t{}; auto completed = torrent_ids_t{}; + auto edited = torrent_ids_t{}; auto instantiated = torrents_t{}; auto needinfo = torrent_ids_t{}; auto processed = torrents_t{}; @@ -261,11 +262,18 @@ void TorrentModel::updateTorrents(tr_variant* torrents, bool is_complete_list) left_until_done = tor->leftUntilDone(); } + auto const old_edit_date = tor->dateEdited(); + if (tor->update(keys.data(), values.data(), keys.size())) { changed.insert(id); } + if (old_edit_date != tor->dateEdited()) + { + edited.insert(id); + } + if (is_new && !tor->hasName()) { needinfo.insert(id); @@ -292,6 +300,11 @@ void TorrentModel::updateTorrents(tr_variant* torrents, bool is_complete_list) rowsAdd(instantiated); } + if (!edited.empty()) + { + emit torrentsEdited(edited); + } + if (!changed.empty()) { rowsEmitChanged(changed);