1
0
Fork 0
mirror of https://github.com/transmission/transmission synced 2024-12-21 23:32:35 +00:00

qt: add dynamic RPC keys (#6599)

* add dynamic main stat keys

* make dynamic rpc calls more generic
This commit is contained in:
Nick 2024-04-01 16:02:17 +02:00 committed by GitHub
parent 87862e506d
commit fb79a2d399
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 26 additions and 9 deletions

View file

@ -516,9 +516,9 @@ void Session::torrentRenamePath(torrent_ids_t const& torrent_ids, QString const&
q->run();
}
std::vector<std::string_view> const& Session::getKeyNames(TorrentProperties props)
std::set<std::string_view> const& Session::getKeyNames(TorrentProperties props)
{
std::vector<std::string_view>& names = names_[props];
std::set<std::string_view>& names = names_[props];
if (names.empty())
{
@ -609,7 +609,7 @@ std::vector<std::string_view> const& Session::getKeyNames(TorrentProperties prop
auto const append = [&names](tr_quark key)
{
names.emplace_back(tr_quark_get_string_view(key));
names.emplace(tr_quark_get_string_view(key));
};
switch (props)
@ -642,10 +642,6 @@ std::vector<std::string_view> const& Session::getKeyNames(TorrentProperties prop
// must be in every torrent req
append(TR_KEY_id);
// sort and remove dupes
std::sort(names.begin(), names.end());
names.erase(std::unique(names.begin(), names.end()), names.end());
}
return names;

View file

@ -9,6 +9,7 @@
#include <cstdint> // int64_t
#include <map>
#include <optional>
#include <set>
#include <string_view>
#include <vector>
@ -133,6 +134,26 @@ public:
Rename
};
void addKeyName(TorrentProperties props, tr_quark const key)
{
// populate names cache with default values
if (names_[props].empty())
{
getKeyNames(props);
}
names_[props].emplace(tr_quark_get_string_view(key));
}
void removeKeyName(TorrentProperties props, tr_quark const key)
{
// do not remove id because it must be in every torrent req
if (key != TR_KEY_id)
{
names_[props].erase(tr_quark_get_string_view(key));
}
}
public slots:
void addTorrent(AddData add_me);
void launchWebInterface() const;
@ -173,7 +194,7 @@ private:
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<std::string_view> const& getKeyNames(TorrentProperties props);
std::set<std::string_view> const& getKeyNames(TorrentProperties props);
static void updateStats(tr_variant* args_dict, tr_session_stats* stats);
@ -182,7 +203,7 @@ private:
QString const config_dir_;
Prefs& prefs_;
std::map<TorrentProperties, std::vector<std::string_view>> names_;
std::map<TorrentProperties, std::set<std::string_view>> names_;
int64_t blocklist_size_ = -1;
std::array<bool, NUM_PORT_TEST_IP_PROTOCOL> port_test_pending_ = {};