2023-11-01 21:11:11 +00:00
|
|
|
// This file Copyright © Mnemosyne LLC.
|
2022-02-07 16:25:02 +00:00
|
|
|
// It may be used under GPLv2 (SPDX: GPL-2.0-only), GPLv3 (SPDX: GPL-3.0-only),
|
2022-01-20 18:27:56 +00:00
|
|
|
// or any future license endorsed by Mnemosyne LLC.
|
|
|
|
// License text can be found in the licenses/ folder.
|
2007-06-06 00:30:13 +00:00
|
|
|
|
2022-12-26 21:13:21 +00:00
|
|
|
#include "DetailsDialog.h"
|
|
|
|
|
|
|
|
#include "Actions.h"
|
|
|
|
#include "FileList.h"
|
2022-12-29 02:42:20 +00:00
|
|
|
#include "GtkCompat.h"
|
2022-12-26 21:13:21 +00:00
|
|
|
#include "HigWorkarea.h" // GUI_PAD, GUI_PAD_BIG, GUI_PAD_SMALL
|
|
|
|
#include "Prefs.h"
|
|
|
|
#include "PrefsDialog.h"
|
|
|
|
#include "Session.h"
|
|
|
|
#include "Utils.h"
|
|
|
|
|
2023-11-14 23:23:51 +00:00
|
|
|
#include <libtransmission/values.h>
|
2022-12-26 21:13:21 +00:00
|
|
|
#include <libtransmission/web-utils.h>
|
|
|
|
|
2022-12-27 01:43:20 +00:00
|
|
|
#include <gdkmm/pixbuf.h>
|
2022-12-26 21:13:21 +00:00
|
|
|
#include <glibmm/i18n.h>
|
2022-12-27 01:43:20 +00:00
|
|
|
#include <glibmm/main.h>
|
|
|
|
#include <glibmm/markup.h>
|
|
|
|
#include <glibmm/quark.h>
|
|
|
|
#include <glibmm/ustring.h>
|
|
|
|
#include <gtkmm/adjustment.h>
|
|
|
|
#include <gtkmm/button.h>
|
|
|
|
#include <gtkmm/cellrendererpixbuf.h>
|
|
|
|
#include <gtkmm/cellrendererprogress.h>
|
|
|
|
#include <gtkmm/cellrenderertext.h>
|
|
|
|
#include <gtkmm/checkbutton.h>
|
|
|
|
#include <gtkmm/combobox.h>
|
|
|
|
#include <gtkmm/entry.h>
|
|
|
|
#include <gtkmm/label.h>
|
|
|
|
#include <gtkmm/liststore.h>
|
|
|
|
#include <gtkmm/messagedialog.h>
|
|
|
|
#include <gtkmm/notebook.h>
|
|
|
|
#include <gtkmm/scrolledwindow.h>
|
|
|
|
#include <gtkmm/spinbutton.h>
|
|
|
|
#include <gtkmm/textbuffer.h>
|
|
|
|
#include <gtkmm/textview.h>
|
|
|
|
#include <gtkmm/tooltip.h>
|
|
|
|
#include <gtkmm/treemodel.h>
|
|
|
|
#include <gtkmm/treemodelfilter.h>
|
|
|
|
#include <gtkmm/treemodelsort.h>
|
|
|
|
#include <gtkmm/treerowreference.h>
|
|
|
|
#include <gtkmm/treeview.h>
|
2022-12-26 21:13:21 +00:00
|
|
|
|
|
|
|
#include <fmt/chrono.h>
|
|
|
|
#include <fmt/core.h>
|
2022-11-09 16:58:36 +00:00
|
|
|
|
2021-10-18 20:22:31 +00:00
|
|
|
#include <algorithm>
|
2021-11-15 18:53:32 +00:00
|
|
|
#include <array>
|
2022-11-10 19:35:31 +00:00
|
|
|
#include <cstddef>
|
|
|
|
#include <cstdlib> // abort()
|
2024-01-03 04:14:43 +00:00
|
|
|
#include <iterator>
|
2022-11-10 19:35:31 +00:00
|
|
|
#include <limits>
|
2022-08-17 16:08:36 +00:00
|
|
|
#include <memory>
|
2022-03-17 18:41:48 +00:00
|
|
|
#include <numeric>
|
2021-10-18 20:22:31 +00:00
|
|
|
#include <sstream>
|
2022-01-13 02:13:58 +00:00
|
|
|
#include <string>
|
2021-10-20 02:30:50 +00:00
|
|
|
#include <string_view>
|
2021-10-18 20:22:31 +00:00
|
|
|
#include <unordered_map>
|
|
|
|
|
2022-12-26 21:13:21 +00:00
|
|
|
#ifdef _WIN32
|
|
|
|
#include <winsock2.h>
|
|
|
|
#include <ws2tcpip.h>
|
|
|
|
#else
|
|
|
|
#include <arpa/inet.h>
|
2023-07-07 15:22:27 +00:00
|
|
|
#include <sys/socket.h>
|
2022-12-26 21:13:21 +00:00
|
|
|
#endif
|
2007-06-06 00:30:13 +00:00
|
|
|
|
2021-10-20 02:30:50 +00:00
|
|
|
using namespace std::literals;
|
|
|
|
|
2023-11-14 23:23:51 +00:00
|
|
|
using namespace libtransmission::Values;
|
|
|
|
|
2021-10-18 20:22:31 +00:00
|
|
|
class DetailsDialog::Impl
|
|
|
|
{
|
|
|
|
public:
|
2022-09-07 22:25:04 +00:00
|
|
|
Impl(DetailsDialog& dialog, Glib::RefPtr<Gtk::Builder> const& builder, Glib::RefPtr<Session> const& core);
|
2021-10-18 20:22:31 +00:00
|
|
|
~Impl();
|
|
|
|
|
2021-12-14 08:43:27 +00:00
|
|
|
TR_DISABLE_COPY_MOVE(Impl)
|
|
|
|
|
2022-06-17 15:43:04 +00:00
|
|
|
void set_torrents(std::vector<tr_torrent_id_t> const& torrent_ids);
|
2022-09-07 22:25:04 +00:00
|
|
|
void refresh();
|
2021-10-18 20:22:31 +00:00
|
|
|
|
|
|
|
private:
|
2022-09-07 22:25:04 +00:00
|
|
|
void info_page_init(Glib::RefPtr<Gtk::Builder> const& builder);
|
|
|
|
void peer_page_init(Glib::RefPtr<Gtk::Builder> const& builder);
|
|
|
|
void tracker_page_init(Glib::RefPtr<Gtk::Builder> const& builder);
|
|
|
|
void options_page_init(Glib::RefPtr<Gtk::Builder> const& builder);
|
2021-10-18 20:22:31 +00:00
|
|
|
|
2022-10-08 22:50:03 +00:00
|
|
|
void on_details_window_size_allocated();
|
2021-10-18 20:22:31 +00:00
|
|
|
|
|
|
|
bool onPeerViewQueryTooltip(int x, int y, bool keyboard_tip, Glib::RefPtr<Gtk::Tooltip> const& tooltip);
|
|
|
|
void onMorePeerInfoToggled();
|
|
|
|
|
|
|
|
bool trackerVisibleFunc(Gtk::TreeModel::const_iterator const& iter);
|
|
|
|
void on_tracker_list_selection_changed();
|
|
|
|
|
|
|
|
void on_tracker_list_add_button_clicked();
|
|
|
|
void on_edit_trackers();
|
|
|
|
void on_tracker_list_remove_button_clicked();
|
|
|
|
void onScrapeToggled();
|
|
|
|
void onBackupToggled();
|
|
|
|
|
|
|
|
void torrent_set_bool(tr_quark key, bool value);
|
|
|
|
void torrent_set_int(tr_quark key, int value);
|
|
|
|
void torrent_set_real(tr_quark key, double value);
|
|
|
|
|
|
|
|
void refreshInfo(std::vector<tr_torrent*> const& torrents);
|
|
|
|
void refreshPeers(std::vector<tr_torrent*> const& torrents);
|
|
|
|
void refreshTracker(std::vector<tr_torrent*> const& torrents);
|
2022-10-22 09:42:38 +00:00
|
|
|
void refreshFiles(std::vector<tr_torrent*> const& torrents);
|
2021-10-18 20:22:31 +00:00
|
|
|
void refreshOptions(std::vector<tr_torrent*> const& torrents);
|
|
|
|
|
|
|
|
void refreshPeerList(std::vector<tr_torrent*> const& torrents);
|
|
|
|
void refreshWebseedList(std::vector<tr_torrent*> const& torrents);
|
|
|
|
|
2022-06-17 15:43:04 +00:00
|
|
|
tr_torrent_id_t tracker_list_get_current_torrent_id() const;
|
2021-10-18 20:22:31 +00:00
|
|
|
tr_torrent* tracker_list_get_current_torrent() const;
|
|
|
|
|
|
|
|
std::vector<tr_torrent*> getTorrents() const;
|
|
|
|
|
|
|
|
private:
|
|
|
|
DetailsDialog& dialog_;
|
2022-09-07 22:25:04 +00:00
|
|
|
Glib::RefPtr<Session> const core_;
|
2021-10-18 20:22:31 +00:00
|
|
|
|
|
|
|
Gtk::CheckButton* honor_limits_check_ = nullptr;
|
|
|
|
Gtk::CheckButton* up_limited_check_ = nullptr;
|
|
|
|
Gtk::SpinButton* up_limit_sping_ = nullptr;
|
|
|
|
Gtk::CheckButton* down_limited_check_ = nullptr;
|
|
|
|
Gtk::SpinButton* down_limit_spin_ = nullptr;
|
|
|
|
Gtk::ComboBox* bandwidth_combo_ = nullptr;
|
|
|
|
|
|
|
|
Gtk::ComboBox* ratio_combo_ = nullptr;
|
|
|
|
Gtk::SpinButton* ratio_spin_ = nullptr;
|
|
|
|
Gtk::ComboBox* idle_combo_ = nullptr;
|
|
|
|
Gtk::SpinButton* idle_spin_ = nullptr;
|
|
|
|
Gtk::SpinButton* max_peers_spin_ = nullptr;
|
|
|
|
|
|
|
|
sigc::connection honor_limits_check_tag_;
|
|
|
|
sigc::connection up_limited_check_tag_;
|
|
|
|
sigc::connection down_limited_check_tag_;
|
|
|
|
sigc::connection down_limit_spin_tag_;
|
|
|
|
sigc::connection up_limit_spin_tag_;
|
|
|
|
sigc::connection bandwidth_combo_tag_;
|
|
|
|
sigc::connection ratio_combo_tag_;
|
|
|
|
sigc::connection ratio_spin_tag_;
|
|
|
|
sigc::connection idle_combo_tag_;
|
|
|
|
sigc::connection idle_spin_tag_;
|
|
|
|
sigc::connection max_peers_spin_tag_;
|
|
|
|
|
2022-05-23 16:09:21 +00:00
|
|
|
Gtk::Label* added_lb_ = nullptr;
|
2021-10-18 20:22:31 +00:00
|
|
|
Gtk::Label* size_lb_ = nullptr;
|
|
|
|
Gtk::Label* state_lb_ = nullptr;
|
|
|
|
Gtk::Label* have_lb_ = nullptr;
|
|
|
|
Gtk::Label* dl_lb_ = nullptr;
|
|
|
|
Gtk::Label* ul_lb_ = nullptr;
|
|
|
|
Gtk::Label* error_lb_ = nullptr;
|
|
|
|
Gtk::Label* date_started_lb_ = nullptr;
|
|
|
|
Gtk::Label* eta_lb_ = nullptr;
|
|
|
|
Gtk::Label* last_activity_lb_ = nullptr;
|
|
|
|
|
|
|
|
Gtk::Label* hash_lb_ = nullptr;
|
|
|
|
Gtk::Label* privacy_lb_ = nullptr;
|
|
|
|
Gtk::Label* origin_lb_ = nullptr;
|
|
|
|
Gtk::Label* destination_lb_ = nullptr;
|
|
|
|
Glib::RefPtr<Gtk::TextBuffer> comment_buffer_;
|
|
|
|
|
|
|
|
std::unordered_map<std::string, Gtk::TreeRowReference> peer_hash_;
|
|
|
|
std::unordered_map<std::string, Gtk::TreeRowReference> webseed_hash_;
|
|
|
|
Glib::RefPtr<Gtk::ListStore> peer_store_;
|
|
|
|
Glib::RefPtr<Gtk::ListStore> webseed_store_;
|
|
|
|
Gtk::ScrolledWindow* webseed_view_ = nullptr;
|
|
|
|
Gtk::TreeView* peer_view_ = nullptr;
|
|
|
|
Gtk::CheckButton* more_peer_details_check_ = nullptr;
|
|
|
|
|
|
|
|
Glib::RefPtr<Gtk::ListStore> tracker_store_;
|
|
|
|
std::unordered_map<std::string, Gtk::TreeRowReference> tracker_hash_;
|
|
|
|
Glib::RefPtr<Gtk::TreeModelFilter> trackers_filtered_;
|
|
|
|
Gtk::Button* add_tracker_button_ = nullptr;
|
|
|
|
Gtk::Button* edit_trackers_button_ = nullptr;
|
|
|
|
Gtk::Button* remove_tracker_button_ = nullptr;
|
|
|
|
Gtk::TreeView* tracker_view_ = nullptr;
|
|
|
|
Gtk::CheckButton* scrape_check_ = nullptr;
|
|
|
|
Gtk::CheckButton* all_check_ = nullptr;
|
|
|
|
|
|
|
|
FileList* file_list_ = nullptr;
|
|
|
|
Gtk::Label* file_label_ = nullptr;
|
|
|
|
|
2022-06-17 15:43:04 +00:00
|
|
|
std::vector<tr_torrent_id_t> ids_;
|
2021-10-18 20:22:31 +00:00
|
|
|
sigc::connection periodic_refresh_tag_;
|
2021-10-24 15:55:51 +00:00
|
|
|
|
|
|
|
Glib::Quark const TORRENT_ID_KEY = Glib::Quark("tr-torrent-id-key");
|
|
|
|
Glib::Quark const TEXT_BUFFER_KEY = Glib::Quark("tr-text-buffer-key");
|
|
|
|
Glib::Quark const URL_ENTRY_KEY = Glib::Quark("tr-url-entry-key");
|
2022-01-25 05:16:33 +00:00
|
|
|
|
|
|
|
static guint last_page_;
|
2008-06-10 02:36:52 +00:00
|
|
|
};
|
|
|
|
|
2022-01-25 05:16:33 +00:00
|
|
|
guint DetailsDialog::Impl::last_page_ = 0;
|
|
|
|
|
2021-10-18 20:22:31 +00:00
|
|
|
std::vector<tr_torrent*> DetailsDialog::Impl::getTorrents() const
|
2008-06-10 02:36:52 +00:00
|
|
|
{
|
2021-10-18 20:22:31 +00:00
|
|
|
std::vector<tr_torrent*> torrents;
|
|
|
|
torrents.reserve(ids_.size());
|
2009-06-15 00:01:38 +00:00
|
|
|
|
2021-10-18 20:22:31 +00:00
|
|
|
for (auto const id : ids_)
|
2017-04-19 12:04:45 +00:00
|
|
|
{
|
2021-10-18 20:22:31 +00:00
|
|
|
if (auto* torrent = core_->find_torrent(id); torrent != nullptr)
|
2017-04-19 12:04:45 +00:00
|
|
|
{
|
2021-10-18 20:22:31 +00:00
|
|
|
torrents.push_back(torrent);
|
2017-04-19 12:04:45 +00:00
|
|
|
}
|
|
|
|
}
|
2009-04-24 01:37:04 +00:00
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
return torrents;
|
2009-04-24 01:37:04 +00:00
|
|
|
}
|
2008-06-10 02:36:52 +00:00
|
|
|
|
2009-04-24 01:37:04 +00:00
|
|
|
/****
|
|
|
|
*****
|
|
|
|
***** OPTIONS TAB
|
|
|
|
*****
|
|
|
|
****/
|
|
|
|
|
2021-10-18 20:22:31 +00:00
|
|
|
namespace
|
|
|
|
{
|
|
|
|
|
2022-10-08 22:50:03 +00:00
|
|
|
void set_togglebutton_if_different(Gtk::CheckButton* toggle, sigc::connection& tag, bool value)
|
2008-06-10 02:36:52 +00:00
|
|
|
{
|
2021-10-18 20:22:31 +00:00
|
|
|
bool const currentValue = toggle->get_active();
|
2013-01-04 19:45:39 +00:00
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
if (currentValue != value)
|
2008-06-10 02:36:52 +00:00
|
|
|
{
|
2021-10-18 20:22:31 +00:00
|
|
|
tag.block();
|
|
|
|
toggle->set_active(value);
|
|
|
|
tag.unblock();
|
2008-06-10 02:36:52 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-10-18 20:22:31 +00:00
|
|
|
void set_int_spin_if_different(Gtk::SpinButton* spin, sigc::connection& tag, int value)
|
2007-06-06 00:30:13 +00:00
|
|
|
{
|
2021-10-18 20:22:31 +00:00
|
|
|
int const currentValue = spin->get_value_as_int();
|
2013-01-04 19:45:39 +00:00
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
if (currentValue != value)
|
2009-04-24 01:37:04 +00:00
|
|
|
{
|
2021-10-18 20:22:31 +00:00
|
|
|
tag.block();
|
|
|
|
spin->set_value(value);
|
|
|
|
tag.unblock();
|
2009-04-24 01:37:04 +00:00
|
|
|
}
|
|
|
|
}
|
2007-06-06 00:30:13 +00:00
|
|
|
|
2021-10-18 20:22:31 +00:00
|
|
|
void set_double_spin_if_different(Gtk::SpinButton* spin, sigc::connection& tag, double value)
|
2007-06-06 00:30:13 +00:00
|
|
|
{
|
2021-10-18 20:22:31 +00:00
|
|
|
double const currentValue = spin->get_value();
|
2013-01-04 19:45:39 +00:00
|
|
|
|
2017-04-30 16:25:26 +00:00
|
|
|
if ((int)(currentValue * 100) != (int)(value * 100))
|
2009-04-24 01:37:04 +00:00
|
|
|
{
|
2021-10-18 20:22:31 +00:00
|
|
|
tag.block();
|
|
|
|
spin->set_value(value);
|
|
|
|
tag.unblock();
|
2009-04-24 01:37:04 +00:00
|
|
|
}
|
|
|
|
}
|
2007-06-06 00:30:13 +00:00
|
|
|
|
2021-10-18 20:22:31 +00:00
|
|
|
void unset_combo(Gtk::ComboBox* combobox, sigc::connection& tag)
|
2007-06-06 00:30:13 +00:00
|
|
|
{
|
2021-10-18 20:22:31 +00:00
|
|
|
tag.block();
|
|
|
|
combobox->set_active(-1);
|
|
|
|
tag.unblock();
|
2007-06-06 00:30:13 +00:00
|
|
|
}
|
|
|
|
|
2021-10-18 20:22:31 +00:00
|
|
|
} // namespace
|
|
|
|
|
|
|
|
void DetailsDialog::Impl::refreshOptions(std::vector<tr_torrent*> const& torrents)
|
2007-06-06 00:30:13 +00:00
|
|
|
{
|
2017-04-19 12:04:45 +00:00
|
|
|
/***
|
|
|
|
**** Options Page
|
|
|
|
***/
|
2013-01-04 19:45:39 +00:00
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
/* honor_limits_check */
|
2021-10-18 20:22:31 +00:00
|
|
|
if (!torrents.empty())
|
2013-01-04 19:45:39 +00:00
|
|
|
{
|
2021-10-18 20:22:31 +00:00
|
|
|
bool const baseline = tr_torrentUsesSessionLimits(torrents.front());
|
|
|
|
bool const is_uniform = std::all_of(
|
|
|
|
torrents.begin(),
|
|
|
|
torrents.end(),
|
|
|
|
[baseline](auto const* torrent) { return baseline == tr_torrentUsesSessionLimits(torrent); });
|
2013-01-04 19:45:39 +00:00
|
|
|
|
2017-05-13 22:38:31 +00:00
|
|
|
if (is_uniform)
|
2017-04-19 12:04:45 +00:00
|
|
|
{
|
2021-10-18 20:22:31 +00:00
|
|
|
set_togglebutton_if_different(honor_limits_check_, honor_limits_check_tag_, baseline);
|
2017-04-19 12:04:45 +00:00
|
|
|
}
|
2013-01-04 19:45:39 +00:00
|
|
|
}
|
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
/* down_limited_check */
|
2021-10-18 20:22:31 +00:00
|
|
|
if (!torrents.empty())
|
2013-01-04 19:45:39 +00:00
|
|
|
{
|
2021-10-18 20:22:31 +00:00
|
|
|
bool const baseline = tr_torrentUsesSpeedLimit(torrents.front(), TR_DOWN);
|
|
|
|
bool const is_uniform = std::all_of(
|
|
|
|
torrents.begin(),
|
|
|
|
torrents.end(),
|
|
|
|
[baseline](auto const* torrent) { return baseline == tr_torrentUsesSpeedLimit(torrent, TR_DOWN); });
|
2013-01-04 19:45:39 +00:00
|
|
|
|
2017-05-13 22:38:31 +00:00
|
|
|
if (is_uniform)
|
2017-04-19 12:04:45 +00:00
|
|
|
{
|
2021-10-18 20:22:31 +00:00
|
|
|
set_togglebutton_if_different(down_limited_check_, down_limited_check_tag_, baseline);
|
2017-04-19 12:04:45 +00:00
|
|
|
}
|
2013-01-04 19:45:39 +00:00
|
|
|
}
|
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
/* down_limit_spin */
|
2021-10-18 20:22:31 +00:00
|
|
|
if (!torrents.empty())
|
2013-01-04 19:45:39 +00:00
|
|
|
{
|
2021-10-18 20:22:31 +00:00
|
|
|
auto const baseline = tr_torrentGetSpeedLimit_KBps(torrents.front(), TR_DOWN);
|
|
|
|
bool const is_uniform = std::all_of(
|
|
|
|
torrents.begin(),
|
|
|
|
torrents.end(),
|
|
|
|
[baseline](auto const* torrent) { return baseline == tr_torrentGetSpeedLimit_KBps(torrent, TR_DOWN); });
|
2013-01-04 19:45:39 +00:00
|
|
|
|
2017-05-13 22:38:31 +00:00
|
|
|
if (is_uniform)
|
2017-04-19 12:04:45 +00:00
|
|
|
{
|
2021-10-18 20:22:31 +00:00
|
|
|
set_int_spin_if_different(down_limit_spin_, down_limit_spin_tag_, baseline);
|
2017-04-19 12:04:45 +00:00
|
|
|
}
|
2013-01-04 19:45:39 +00:00
|
|
|
}
|
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
/* up_limited_check */
|
2021-10-18 20:22:31 +00:00
|
|
|
if (!torrents.empty())
|
2013-01-04 19:45:39 +00:00
|
|
|
{
|
2021-10-18 20:22:31 +00:00
|
|
|
bool const baseline = tr_torrentUsesSpeedLimit(torrents.front(), TR_UP);
|
|
|
|
bool const is_uniform = std::all_of(
|
|
|
|
torrents.begin(),
|
|
|
|
torrents.end(),
|
|
|
|
[baseline](auto const* torrent) { return baseline == tr_torrentUsesSpeedLimit(torrent, TR_UP); });
|
2013-01-04 19:45:39 +00:00
|
|
|
|
2017-05-13 22:38:31 +00:00
|
|
|
if (is_uniform)
|
2017-04-19 12:04:45 +00:00
|
|
|
{
|
2021-10-18 20:22:31 +00:00
|
|
|
set_togglebutton_if_different(up_limited_check_, up_limited_check_tag_, baseline);
|
2017-04-19 12:04:45 +00:00
|
|
|
}
|
2013-01-04 19:45:39 +00:00
|
|
|
}
|
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
/* up_limit_sping */
|
2021-10-18 20:22:31 +00:00
|
|
|
if (!torrents.empty())
|
2013-01-04 19:45:39 +00:00
|
|
|
{
|
2021-10-18 20:22:31 +00:00
|
|
|
auto const baseline = tr_torrentGetSpeedLimit_KBps(torrents.front(), TR_UP);
|
|
|
|
bool const is_uniform = std::all_of(
|
|
|
|
torrents.begin(),
|
|
|
|
torrents.end(),
|
|
|
|
[baseline](auto const* torrent) { return baseline == tr_torrentGetSpeedLimit_KBps(torrent, TR_UP); });
|
2013-01-04 19:45:39 +00:00
|
|
|
|
2017-05-13 22:38:31 +00:00
|
|
|
if (is_uniform)
|
2017-04-19 12:04:45 +00:00
|
|
|
{
|
2021-10-18 20:22:31 +00:00
|
|
|
set_int_spin_if_different(up_limit_sping_, up_limit_spin_tag_, baseline);
|
2017-04-19 12:04:45 +00:00
|
|
|
}
|
2013-01-04 19:45:39 +00:00
|
|
|
}
|
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
/* bandwidth_combo */
|
2021-10-18 20:22:31 +00:00
|
|
|
if (!torrents.empty())
|
2013-01-04 19:45:39 +00:00
|
|
|
{
|
2021-10-18 20:22:31 +00:00
|
|
|
auto const baseline = tr_torrentGetPriority(torrents.front());
|
|
|
|
bool const is_uniform = std::all_of(
|
|
|
|
torrents.begin(),
|
|
|
|
torrents.end(),
|
|
|
|
[baseline](auto const* torrent) { return baseline == tr_torrentGetPriority(torrent); });
|
2013-01-04 19:45:39 +00:00
|
|
|
|
2017-05-13 22:38:31 +00:00
|
|
|
if (is_uniform)
|
2013-01-04 19:45:39 +00:00
|
|
|
{
|
2021-10-18 20:22:31 +00:00
|
|
|
bandwidth_combo_tag_.block();
|
2023-01-21 12:06:20 +00:00
|
|
|
gtr_combo_box_set_active_enum(*bandwidth_combo_, baseline);
|
2021-10-18 20:22:31 +00:00
|
|
|
bandwidth_combo_tag_.unblock();
|
2010-02-02 07:51:45 +00:00
|
|
|
}
|
2017-04-19 12:04:45 +00:00
|
|
|
else
|
2013-01-04 19:45:39 +00:00
|
|
|
{
|
2021-10-18 20:22:31 +00:00
|
|
|
unset_combo(bandwidth_combo_, bandwidth_combo_tag_);
|
2009-04-24 01:37:04 +00:00
|
|
|
}
|
|
|
|
}
|
2013-01-04 19:45:39 +00:00
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
/* ratio_combo */
|
2021-10-18 20:22:31 +00:00
|
|
|
if (!torrents.empty())
|
2013-01-04 19:45:39 +00:00
|
|
|
{
|
2021-10-18 20:22:31 +00:00
|
|
|
auto const baseline = tr_torrentGetRatioMode(torrents.front());
|
|
|
|
bool const is_uniform = std::all_of(
|
|
|
|
torrents.begin(),
|
|
|
|
torrents.end(),
|
|
|
|
[baseline](auto const* torrent) { return baseline == tr_torrentGetRatioMode(torrent); });
|
2013-01-04 19:45:39 +00:00
|
|
|
|
2017-05-13 22:38:31 +00:00
|
|
|
if (is_uniform)
|
2013-01-04 19:45:39 +00:00
|
|
|
{
|
2021-10-18 20:22:31 +00:00
|
|
|
ratio_combo_tag_.block();
|
|
|
|
gtr_combo_box_set_active_enum(*ratio_combo_, baseline);
|
|
|
|
gtr_widget_set_visible(*ratio_spin_, baseline == TR_RATIOLIMIT_SINGLE);
|
|
|
|
ratio_combo_tag_.unblock();
|
2010-07-24 02:57:39 +00:00
|
|
|
}
|
|
|
|
}
|
2013-01-04 19:45:39 +00:00
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
/* ratio_spin */
|
2021-10-18 20:22:31 +00:00
|
|
|
if (!torrents.empty())
|
2013-01-04 19:45:39 +00:00
|
|
|
{
|
2021-10-18 20:22:31 +00:00
|
|
|
auto const baseline = tr_torrentGetRatioLimit(torrents.front());
|
|
|
|
set_double_spin_if_different(ratio_spin_, ratio_spin_tag_, baseline);
|
2010-07-24 02:57:39 +00:00
|
|
|
}
|
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
/* idle_combo */
|
2021-10-18 20:22:31 +00:00
|
|
|
if (!torrents.empty())
|
2013-01-04 19:45:39 +00:00
|
|
|
{
|
2021-10-18 20:22:31 +00:00
|
|
|
auto const baseline = tr_torrentGetIdleMode(torrents.front());
|
|
|
|
bool const is_uniform = std::all_of(
|
|
|
|
torrents.begin(),
|
|
|
|
torrents.end(),
|
|
|
|
[baseline](auto const* torrent) { return baseline == tr_torrentGetIdleMode(torrent); });
|
2013-01-04 19:45:39 +00:00
|
|
|
|
2017-05-13 22:38:31 +00:00
|
|
|
if (is_uniform)
|
2013-01-04 19:45:39 +00:00
|
|
|
{
|
2021-10-18 20:22:31 +00:00
|
|
|
idle_combo_tag_.block();
|
|
|
|
gtr_combo_box_set_active_enum(*idle_combo_, baseline);
|
|
|
|
gtr_widget_set_visible(*idle_spin_, baseline == TR_IDLELIMIT_SINGLE);
|
|
|
|
idle_combo_tag_.unblock();
|
2013-01-04 19:45:39 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
/* idle_spin */
|
2021-10-18 20:22:31 +00:00
|
|
|
if (!torrents.empty())
|
2013-01-04 19:45:39 +00:00
|
|
|
{
|
2021-10-18 20:22:31 +00:00
|
|
|
auto const baseline = tr_torrentGetIdleLimit(torrents.front());
|
|
|
|
set_int_spin_if_different(idle_spin_, idle_spin_tag_, baseline);
|
2013-01-04 19:45:39 +00:00
|
|
|
}
|
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
/* max_peers_spin */
|
2021-10-18 20:22:31 +00:00
|
|
|
if (!torrents.empty())
|
2013-01-04 19:45:39 +00:00
|
|
|
{
|
2021-10-18 20:22:31 +00:00
|
|
|
auto const baseline = tr_torrentGetPeerLimit(torrents.front());
|
|
|
|
set_int_spin_if_different(max_peers_spin_, max_peers_spin_tag_, baseline);
|
2008-09-23 19:11:04 +00:00
|
|
|
}
|
2007-06-06 00:30:13 +00:00
|
|
|
}
|
|
|
|
|
2021-10-18 20:22:31 +00:00
|
|
|
void DetailsDialog::Impl::torrent_set_bool(tr_quark key, bool value)
|
2007-06-06 00:30:13 +00:00
|
|
|
{
|
2017-05-01 15:46:41 +00:00
|
|
|
tr_variant top;
|
2017-04-19 12:04:45 +00:00
|
|
|
|
|
|
|
tr_variantInitDict(&top, 2);
|
2021-11-18 05:37:35 +00:00
|
|
|
tr_variantDictAddStrView(&top, TR_KEY_method, "torrent-set"sv);
|
2020-11-05 22:46:21 +00:00
|
|
|
tr_variant* const args = tr_variantDictAddDict(&top, TR_KEY_arguments, 2);
|
2017-04-19 12:04:45 +00:00
|
|
|
tr_variantDictAddBool(args, key, value);
|
2021-10-18 20:22:31 +00:00
|
|
|
tr_variant* const ids = tr_variantDictAddList(args, TR_KEY_ids, ids_.size());
|
2009-04-24 01:37:04 +00:00
|
|
|
|
2021-10-18 20:22:31 +00:00
|
|
|
for (auto const id : ids_)
|
2017-04-19 12:04:45 +00:00
|
|
|
{
|
2021-10-18 20:22:31 +00:00
|
|
|
tr_variantListAddInt(ids, id);
|
2017-04-19 12:04:45 +00:00
|
|
|
}
|
2009-04-24 01:37:04 +00:00
|
|
|
|
2024-01-03 04:14:43 +00:00
|
|
|
core_->exec(top);
|
2007-06-06 00:30:13 +00:00
|
|
|
}
|
|
|
|
|
2021-10-18 20:22:31 +00:00
|
|
|
void DetailsDialog::Impl::torrent_set_int(tr_quark key, int value)
|
2007-09-20 16:32:01 +00:00
|
|
|
{
|
2017-05-01 15:46:41 +00:00
|
|
|
tr_variant top;
|
2009-04-24 01:37:04 +00:00
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
tr_variantInitDict(&top, 2);
|
2021-11-18 05:37:35 +00:00
|
|
|
tr_variantDictAddStrView(&top, TR_KEY_method, "torrent-set"sv);
|
2020-11-05 22:46:21 +00:00
|
|
|
tr_variant* const args = tr_variantDictAddDict(&top, TR_KEY_arguments, 2);
|
2017-04-19 12:04:45 +00:00
|
|
|
tr_variantDictAddInt(args, key, value);
|
2021-10-18 20:22:31 +00:00
|
|
|
tr_variant* const ids = tr_variantDictAddList(args, TR_KEY_ids, ids_.size());
|
2009-04-24 01:37:04 +00:00
|
|
|
|
2021-10-18 20:22:31 +00:00
|
|
|
for (auto const id : ids_)
|
2017-04-19 12:04:45 +00:00
|
|
|
{
|
2021-10-18 20:22:31 +00:00
|
|
|
tr_variantListAddInt(ids, id);
|
2017-04-19 12:04:45 +00:00
|
|
|
}
|
|
|
|
|
2024-01-03 04:14:43 +00:00
|
|
|
core_->exec(top);
|
2007-09-20 16:32:01 +00:00
|
|
|
}
|
|
|
|
|
2021-10-18 20:22:31 +00:00
|
|
|
void DetailsDialog::Impl::torrent_set_real(tr_quark key, double value)
|
2007-06-06 00:30:13 +00:00
|
|
|
{
|
2017-05-01 15:46:41 +00:00
|
|
|
tr_variant top;
|
2009-04-24 01:37:04 +00:00
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
tr_variantInitDict(&top, 2);
|
2021-11-18 05:37:35 +00:00
|
|
|
tr_variantDictAddStrView(&top, TR_KEY_method, "torrent-set"sv);
|
2020-11-05 22:46:21 +00:00
|
|
|
tr_variant* const args = tr_variantDictAddDict(&top, TR_KEY_arguments, 2);
|
2017-04-19 12:04:45 +00:00
|
|
|
tr_variantDictAddReal(args, key, value);
|
2021-10-18 20:22:31 +00:00
|
|
|
tr_variant* const ids = tr_variantDictAddList(args, TR_KEY_ids, ids_.size());
|
2009-04-24 01:37:04 +00:00
|
|
|
|
2021-10-18 20:22:31 +00:00
|
|
|
for (auto const id : ids_)
|
2017-04-19 12:04:45 +00:00
|
|
|
{
|
2021-10-18 20:22:31 +00:00
|
|
|
tr_variantListAddInt(ids, id);
|
2017-04-19 12:04:45 +00:00
|
|
|
}
|
|
|
|
|
2024-01-03 04:14:43 +00:00
|
|
|
core_->exec(top);
|
2007-06-06 00:30:13 +00:00
|
|
|
}
|
|
|
|
|
2022-09-07 22:25:04 +00:00
|
|
|
void DetailsDialog::Impl::options_page_init(Glib::RefPtr<Gtk::Builder> const& /*builder*/)
|
2017-04-19 12:04:45 +00:00
|
|
|
{
|
2023-11-16 04:15:40 +00:00
|
|
|
auto const speed_units_kbyps_str = Speed::units().display_name(Speed::Units::KByps);
|
|
|
|
|
2021-10-18 20:22:31 +00:00
|
|
|
honor_limits_check_tag_ = honor_limits_check_->signal_toggled().connect(
|
|
|
|
[this]() { torrent_set_bool(TR_KEY_honorsSessionLimits, honor_limits_check_->get_active()); });
|
|
|
|
|
2023-11-16 04:15:40 +00:00
|
|
|
down_limited_check_->set_label(
|
|
|
|
fmt::format(fmt::runtime(down_limited_check_->get_label().raw()), fmt::arg("speed_units", speed_units_kbyps_str)));
|
2021-10-18 20:22:31 +00:00
|
|
|
down_limited_check_tag_ = down_limited_check_->signal_toggled().connect(
|
|
|
|
[this]() { torrent_set_bool(TR_KEY_downloadLimited, down_limited_check_->get_active()); });
|
|
|
|
|
2022-11-10 19:35:31 +00:00
|
|
|
down_limit_spin_->set_adjustment(Gtk::Adjustment::create(0, 0, std::numeric_limits<int>::max(), 5));
|
2021-10-18 20:22:31 +00:00
|
|
|
down_limit_spin_tag_ = down_limit_spin_->signal_value_changed().connect(
|
|
|
|
[this]() { torrent_set_int(TR_KEY_downloadLimit, down_limit_spin_->get_value_as_int()); });
|
|
|
|
|
2023-11-16 04:15:40 +00:00
|
|
|
up_limited_check_->set_label(
|
|
|
|
fmt::format(fmt::runtime(up_limited_check_->get_label().raw()), fmt::arg("speed_units", speed_units_kbyps_str)));
|
2021-10-18 20:22:31 +00:00
|
|
|
up_limited_check_tag_ = up_limited_check_->signal_toggled().connect(
|
|
|
|
[this]() { torrent_set_bool(TR_KEY_uploadLimited, up_limited_check_->get_active()); });
|
|
|
|
|
2022-11-10 19:35:31 +00:00
|
|
|
up_limit_sping_->set_adjustment(Gtk::Adjustment::create(0, 0, std::numeric_limits<int>::max(), 5));
|
2021-10-18 20:22:31 +00:00
|
|
|
up_limit_spin_tag_ = up_limit_sping_->signal_value_changed().connect(
|
|
|
|
[this]() { torrent_set_int(TR_KEY_uploadLimit, up_limit_sping_->get_value_as_int()); });
|
|
|
|
|
2022-09-07 22:25:04 +00:00
|
|
|
gtr_priority_combo_init(*bandwidth_combo_);
|
2021-10-18 20:22:31 +00:00
|
|
|
bandwidth_combo_tag_ = bandwidth_combo_->signal_changed().connect(
|
2023-01-21 12:06:20 +00:00
|
|
|
[this]() { torrent_set_int(TR_KEY_bandwidthPriority, gtr_combo_box_get_active_enum(*bandwidth_combo_)); });
|
2021-10-18 20:22:31 +00:00
|
|
|
|
2022-09-07 22:25:04 +00:00
|
|
|
gtr_combo_box_set_enum(
|
|
|
|
*ratio_combo_,
|
|
|
|
{
|
|
|
|
{ _("Use global settings"), TR_RATIOLIMIT_GLOBAL },
|
|
|
|
{ _("Seed regardless of ratio"), TR_RATIOLIMIT_UNLIMITED },
|
|
|
|
{ _("Stop seeding at ratio:"), TR_RATIOLIMIT_SINGLE },
|
|
|
|
});
|
2021-10-18 20:22:31 +00:00
|
|
|
ratio_combo_tag_ = ratio_combo_->signal_changed().connect(
|
|
|
|
[this]()
|
|
|
|
{
|
|
|
|
torrent_set_int(TR_KEY_seedRatioMode, gtr_combo_box_get_active_enum(*ratio_combo_));
|
|
|
|
refresh();
|
|
|
|
});
|
2022-09-07 22:25:04 +00:00
|
|
|
ratio_spin_->set_adjustment(Gtk::Adjustment::create(0, 0, 1000, .05));
|
2021-10-18 20:22:31 +00:00
|
|
|
ratio_spin_->set_width_chars(7);
|
|
|
|
ratio_spin_tag_ = ratio_spin_->signal_value_changed().connect(
|
|
|
|
[this]() { torrent_set_real(TR_KEY_seedRatioLimit, ratio_spin_->get_value()); });
|
2022-09-07 22:25:04 +00:00
|
|
|
|
|
|
|
gtr_combo_box_set_enum(
|
|
|
|
*idle_combo_,
|
|
|
|
{
|
|
|
|
{ _("Use global settings"), TR_IDLELIMIT_GLOBAL },
|
|
|
|
{ _("Seed regardless of activity"), TR_IDLELIMIT_UNLIMITED },
|
|
|
|
{ _("Stop seeding if idle for N minutes:"), TR_IDLELIMIT_SINGLE },
|
|
|
|
});
|
2021-10-18 20:22:31 +00:00
|
|
|
idle_combo_tag_ = idle_combo_->signal_changed().connect(
|
|
|
|
[this]()
|
|
|
|
{
|
|
|
|
torrent_set_int(TR_KEY_seedIdleMode, gtr_combo_box_get_active_enum(*idle_combo_));
|
|
|
|
refresh();
|
|
|
|
});
|
2022-09-07 22:25:04 +00:00
|
|
|
idle_spin_->set_adjustment(Gtk::Adjustment::create(1, 1, 40320, 5));
|
2021-10-18 20:22:31 +00:00
|
|
|
idle_spin_tag_ = idle_spin_->signal_value_changed().connect(
|
|
|
|
[this]() { torrent_set_int(TR_KEY_seedIdleLimit, idle_spin_->get_value_as_int()); });
|
|
|
|
|
2022-09-07 22:25:04 +00:00
|
|
|
max_peers_spin_->set_adjustment(Gtk::Adjustment::create(1, 1, 3000, 5));
|
2021-10-18 20:22:31 +00:00
|
|
|
max_peers_spin_tag_ = max_peers_spin_->signal_value_changed().connect(
|
|
|
|
[this]() { torrent_set_int(TR_KEY_peer_limit, max_peers_spin_->get_value_as_int()); });
|
2007-06-06 00:30:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/****
|
2009-04-24 01:37:04 +00:00
|
|
|
*****
|
2009-06-23 00:24:37 +00:00
|
|
|
***** INFO TAB
|
2009-04-24 01:37:04 +00:00
|
|
|
*****
|
2007-06-06 00:30:13 +00:00
|
|
|
****/
|
|
|
|
|
2021-10-18 20:22:31 +00:00
|
|
|
namespace
|
|
|
|
{
|
|
|
|
|
|
|
|
Glib::ustring activityString(int activity, bool finished)
|
2008-05-23 20:04:41 +00:00
|
|
|
{
|
2017-04-19 12:04:45 +00:00
|
|
|
switch (activity)
|
2008-09-23 19:11:04 +00:00
|
|
|
{
|
2017-04-19 12:04:45 +00:00
|
|
|
case TR_STATUS_CHECK_WAIT:
|
|
|
|
return _("Queued for verification");
|
|
|
|
|
|
|
|
case TR_STATUS_CHECK:
|
|
|
|
return _("Verifying local data");
|
|
|
|
|
|
|
|
case TR_STATUS_DOWNLOAD_WAIT:
|
|
|
|
return _("Queued for download");
|
|
|
|
|
|
|
|
case TR_STATUS_DOWNLOAD:
|
|
|
|
return C_("Verb", "Downloading");
|
|
|
|
|
|
|
|
case TR_STATUS_SEED_WAIT:
|
|
|
|
return _("Queued for seeding");
|
|
|
|
|
|
|
|
case TR_STATUS_SEED:
|
|
|
|
return C_("Verb", "Seeding");
|
|
|
|
|
|
|
|
case TR_STATUS_STOPPED:
|
|
|
|
return finished ? _("Finished") : _("Paused");
|
2021-12-14 08:43:27 +00:00
|
|
|
|
|
|
|
default:
|
|
|
|
g_assert_not_reached();
|
2008-05-23 20:04:41 +00:00
|
|
|
}
|
2009-04-24 01:37:04 +00:00
|
|
|
|
2021-10-18 20:22:31 +00:00
|
|
|
return {};
|
2008-05-23 20:04:41 +00:00
|
|
|
}
|
|
|
|
|
2012-12-05 17:29:46 +00:00
|
|
|
/* Only call gtk_text_buffer_set_text () if the new text differs from the old.
|
2010-02-19 14:49:03 +00:00
|
|
|
* This way if the user has text selected, refreshing won't deselect it */
|
2021-10-18 20:22:31 +00:00
|
|
|
void gtr_text_buffer_set_text(Glib::RefPtr<Gtk::TextBuffer> const& b, Glib::ustring const& str)
|
2010-02-19 14:49:03 +00:00
|
|
|
{
|
2021-10-18 20:22:31 +00:00
|
|
|
if (b->get_text() != str)
|
2017-04-19 12:04:45 +00:00
|
|
|
{
|
2021-10-18 20:22:31 +00:00
|
|
|
b->set_text(str);
|
2017-04-19 12:04:45 +00:00
|
|
|
}
|
2010-02-19 14:49:03 +00:00
|
|
|
}
|
|
|
|
|
2022-04-22 19:56:54 +00:00
|
|
|
[[nodiscard]] std::string get_date_string(time_t t)
|
2010-05-28 19:43:37 +00:00
|
|
|
{
|
2024-01-06 20:05:18 +00:00
|
|
|
return t == 0 ? _("N/A") : fmt::format("{:%x}", fmt::localtime(t));
|
2020-08-11 18:11:55 +00:00
|
|
|
}
|
2010-05-28 19:43:37 +00:00
|
|
|
|
2022-05-23 16:09:21 +00:00
|
|
|
[[nodiscard]] std::string get_date_time_string(time_t t)
|
|
|
|
{
|
2024-01-06 20:05:18 +00:00
|
|
|
return t == 0 ? _("N/A") : fmt::format("{:%c}", fmt::localtime(t));
|
2022-05-23 16:09:21 +00:00
|
|
|
}
|
|
|
|
|
2021-10-18 20:22:31 +00:00
|
|
|
} // namespace
|
|
|
|
|
|
|
|
void DetailsDialog::Impl::refreshInfo(std::vector<tr_torrent*> const& torrents)
|
2007-06-06 00:30:13 +00:00
|
|
|
{
|
2022-06-15 02:56:27 +00:00
|
|
|
auto const now = time(nullptr);
|
2021-10-18 20:22:31 +00:00
|
|
|
Glib::ustring str;
|
|
|
|
Glib::ustring const mixed = _("Mixed");
|
|
|
|
Glib::ustring const no_torrent = _("No Torrents Selected");
|
|
|
|
Glib::ustring stateString;
|
2017-04-19 12:04:45 +00:00
|
|
|
uint64_t sizeWhenDone = 0;
|
2021-10-18 20:22:31 +00:00
|
|
|
std::vector<tr_stat const*> stats;
|
2021-12-14 21:59:44 +00:00
|
|
|
std::vector<tr_torrent_view> infos;
|
2013-01-04 19:45:39 +00:00
|
|
|
|
2021-10-18 20:22:31 +00:00
|
|
|
stats.reserve(torrents.size());
|
|
|
|
infos.reserve(torrents.size());
|
|
|
|
for (auto* const torrent : torrents)
|
2013-01-04 19:45:39 +00:00
|
|
|
{
|
2023-10-02 19:07:28 +00:00
|
|
|
stats.push_back(tr_torrentStat(torrent));
|
2021-12-14 21:59:44 +00:00
|
|
|
infos.push_back(tr_torrentView(torrent));
|
2013-01-04 19:45:39 +00:00
|
|
|
}
|
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
/* privacy_lb */
|
2021-10-18 20:22:31 +00:00
|
|
|
if (infos.empty())
|
2013-01-04 19:45:39 +00:00
|
|
|
{
|
2017-04-19 12:04:45 +00:00
|
|
|
str = no_torrent;
|
2013-01-04 19:45:39 +00:00
|
|
|
}
|
2017-04-19 12:04:45 +00:00
|
|
|
else
|
2013-01-04 19:45:39 +00:00
|
|
|
{
|
2021-12-14 21:59:44 +00:00
|
|
|
bool const baseline = infos.front().is_private;
|
2021-10-18 20:22:31 +00:00
|
|
|
bool const is_uniform = std::all_of(
|
|
|
|
infos.begin(),
|
|
|
|
infos.end(),
|
2021-12-14 21:59:44 +00:00
|
|
|
[baseline](auto const& info) { return info.is_private == baseline; });
|
2013-01-04 19:45:39 +00:00
|
|
|
|
2017-05-13 22:38:31 +00:00
|
|
|
if (is_uniform)
|
2017-04-19 12:04:45 +00:00
|
|
|
{
|
2017-05-13 22:38:31 +00:00
|
|
|
str = baseline ? _("Private to this tracker -- DHT and PEX disabled") : _("Public torrent");
|
2017-04-19 12:04:45 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2017-05-13 22:38:31 +00:00
|
|
|
str = mixed;
|
2017-04-19 12:04:45 +00:00
|
|
|
}
|
2009-06-23 00:24:37 +00:00
|
|
|
}
|
|
|
|
|
2021-10-18 20:22:31 +00:00
|
|
|
privacy_lb_->set_text(str);
|
2009-06-23 00:24:37 +00:00
|
|
|
|
2022-05-23 16:09:21 +00:00
|
|
|
/* added_lb */
|
|
|
|
if (stats.empty())
|
|
|
|
{
|
|
|
|
str = no_torrent;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
auto const baseline = stats.front()->addedDate;
|
|
|
|
bool const is_uniform = std::all_of(
|
|
|
|
stats.begin(),
|
|
|
|
stats.end(),
|
|
|
|
[baseline](auto const* stat) { return stat->addedDate == baseline; });
|
|
|
|
|
|
|
|
if (is_uniform)
|
|
|
|
{
|
|
|
|
str = get_date_time_string(baseline);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
str = mixed;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
added_lb_->set_text(str);
|
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
/* origin_lb */
|
2021-10-18 20:22:31 +00:00
|
|
|
if (infos.empty())
|
2013-01-04 19:45:39 +00:00
|
|
|
{
|
2017-04-19 12:04:45 +00:00
|
|
|
str = no_torrent;
|
2013-01-04 19:45:39 +00:00
|
|
|
}
|
2017-04-19 12:04:45 +00:00
|
|
|
else
|
2013-01-04 19:45:39 +00:00
|
|
|
{
|
2023-06-30 14:49:58 +00:00
|
|
|
auto const creator = tr_strv_strip(infos.front().creator != nullptr ? infos.front().creator : "");
|
2021-12-14 21:59:44 +00:00
|
|
|
auto const date = infos.front().date_created;
|
2022-03-21 14:15:48 +00:00
|
|
|
auto const datestr = get_date_string(date);
|
2021-10-18 20:22:31 +00:00
|
|
|
bool const mixed_creator = std::any_of(
|
|
|
|
infos.begin(),
|
|
|
|
infos.end(),
|
2021-12-14 21:59:44 +00:00
|
|
|
[&creator](auto const& info) { return creator != (info.creator != nullptr ? info.creator : ""); });
|
2021-10-18 20:22:31 +00:00
|
|
|
bool const mixed_date = std::any_of(
|
|
|
|
infos.begin(),
|
|
|
|
infos.end(),
|
2021-12-14 21:59:44 +00:00
|
|
|
[date](auto const& info) { return date != info.date_created; });
|
2021-10-18 20:22:31 +00:00
|
|
|
|
2022-03-21 14:15:48 +00:00
|
|
|
bool const empty_creator = std::empty(creator);
|
2021-10-18 20:22:31 +00:00
|
|
|
bool const empty_date = date == 0;
|
2015-04-22 21:04:49 +00:00
|
|
|
|
2022-03-21 14:15:48 +00:00
|
|
|
if (mixed_creator || mixed_date)
|
2013-01-04 19:45:39 +00:00
|
|
|
{
|
2017-04-19 12:04:45 +00:00
|
|
|
str = mixed;
|
2013-01-04 19:45:39 +00:00
|
|
|
}
|
2022-03-21 14:15:48 +00:00
|
|
|
else if (!empty_creator && !empty_date)
|
2015-04-22 21:04:49 +00:00
|
|
|
{
|
2022-03-21 14:15:48 +00:00
|
|
|
str = fmt::format(_("Created by {creator} on {date}"), fmt::arg("creator", creator), fmt::arg("date", datestr));
|
|
|
|
}
|
|
|
|
else if (!empty_creator)
|
|
|
|
{
|
|
|
|
str = fmt::format(_("Created by {creator}"), fmt::arg("creator", creator));
|
|
|
|
}
|
|
|
|
else if (!empty_date)
|
|
|
|
{
|
|
|
|
str = fmt::format(_("Created on {date}"), fmt::arg("date", datestr));
|
2015-04-22 21:04:49 +00:00
|
|
|
}
|
2017-04-19 12:04:45 +00:00
|
|
|
else
|
2013-01-04 19:45:39 +00:00
|
|
|
{
|
2022-03-21 14:15:48 +00:00
|
|
|
str = _("N/A");
|
2009-08-04 03:10:35 +00:00
|
|
|
}
|
2009-06-23 00:24:37 +00:00
|
|
|
}
|
2017-04-19 12:04:45 +00:00
|
|
|
|
2021-10-18 20:22:31 +00:00
|
|
|
origin_lb_->set_text(str);
|
2009-06-23 00:24:37 +00:00
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
/* comment_buffer */
|
2021-10-18 20:22:31 +00:00
|
|
|
if (infos.empty())
|
2013-01-04 19:45:39 +00:00
|
|
|
{
|
2021-10-18 20:22:31 +00:00
|
|
|
str.clear();
|
2009-06-23 00:24:37 +00:00
|
|
|
}
|
2017-04-19 12:04:45 +00:00
|
|
|
else
|
2013-01-04 19:45:39 +00:00
|
|
|
{
|
2021-12-14 21:59:44 +00:00
|
|
|
auto const baseline = Glib::ustring(infos.front().comment != nullptr ? infos.front().comment : "");
|
2021-10-18 20:22:31 +00:00
|
|
|
bool const is_uniform = std::all_of(
|
|
|
|
infos.begin(),
|
|
|
|
infos.end(),
|
2021-12-14 21:59:44 +00:00
|
|
|
[&baseline](auto const& info) { return baseline == (info.comment != nullptr ? info.comment : ""); });
|
2009-06-23 00:24:37 +00:00
|
|
|
|
2017-05-13 22:38:31 +00:00
|
|
|
str = is_uniform ? baseline : mixed;
|
2009-10-10 20:42:23 +00:00
|
|
|
}
|
2013-01-04 19:45:39 +00:00
|
|
|
|
2021-10-18 20:22:31 +00:00
|
|
|
gtr_text_buffer_set_text(comment_buffer_, str);
|
2017-04-19 12:04:45 +00:00
|
|
|
|
|
|
|
/* destination_lb */
|
2021-10-18 20:22:31 +00:00
|
|
|
if (torrents.empty())
|
2013-01-04 19:45:39 +00:00
|
|
|
{
|
2017-04-19 12:04:45 +00:00
|
|
|
str = no_torrent;
|
2013-01-04 19:45:39 +00:00
|
|
|
}
|
2017-04-19 12:04:45 +00:00
|
|
|
else
|
2013-01-04 19:45:39 +00:00
|
|
|
{
|
2021-10-18 20:22:31 +00:00
|
|
|
auto const baseline = Glib::ustring(tr_torrentGetDownloadDir(torrents.front()));
|
|
|
|
bool const is_uniform = std::all_of(
|
|
|
|
torrents.begin(),
|
|
|
|
torrents.end(),
|
|
|
|
[&baseline](auto const* torrent) { return baseline == tr_torrentGetDownloadDir(torrent); });
|
2009-10-10 20:42:23 +00:00
|
|
|
|
2017-05-13 22:38:31 +00:00
|
|
|
str = is_uniform ? baseline : mixed;
|
2013-01-04 19:45:39 +00:00
|
|
|
}
|
|
|
|
|
2021-10-18 20:22:31 +00:00
|
|
|
destination_lb_->set_text(str);
|
2017-04-19 12:04:45 +00:00
|
|
|
|
|
|
|
/* state_lb */
|
2021-10-18 20:22:31 +00:00
|
|
|
if (stats.empty())
|
2009-06-23 00:24:37 +00:00
|
|
|
{
|
2017-04-19 12:04:45 +00:00
|
|
|
str = no_torrent;
|
2013-01-04 19:45:39 +00:00
|
|
|
}
|
2017-04-19 12:04:45 +00:00
|
|
|
else
|
2013-01-04 19:45:39 +00:00
|
|
|
{
|
2021-10-18 20:22:31 +00:00
|
|
|
auto const activity = stats.front()->activity;
|
|
|
|
bool const is_uniform = std::all_of(
|
|
|
|
stats.begin(),
|
|
|
|
stats.end(),
|
|
|
|
[activity](auto const* st) { return activity == st->activity; });
|
|
|
|
bool const allFinished = std::all_of(stats.begin(), stats.end(), [](auto const* st) { return st->finished; });
|
2013-01-04 19:45:39 +00:00
|
|
|
|
2017-05-13 22:38:31 +00:00
|
|
|
str = is_uniform ? activityString(activity, allFinished) : mixed;
|
2013-01-04 19:45:39 +00:00
|
|
|
}
|
2017-04-19 12:04:45 +00:00
|
|
|
|
|
|
|
stateString = str;
|
2021-10-18 20:22:31 +00:00
|
|
|
state_lb_->set_text(str);
|
2013-01-04 19:45:39 +00:00
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
/* date started */
|
2021-10-18 20:22:31 +00:00
|
|
|
if (stats.empty())
|
2013-01-04 19:45:39 +00:00
|
|
|
{
|
2017-04-19 12:04:45 +00:00
|
|
|
str = no_torrent;
|
2013-01-04 19:45:39 +00:00
|
|
|
}
|
2017-04-19 12:04:45 +00:00
|
|
|
else
|
2013-01-04 19:45:39 +00:00
|
|
|
{
|
2021-10-18 20:22:31 +00:00
|
|
|
time_t const baseline = stats.front()->startDate;
|
|
|
|
bool const is_uniform = std::all_of(
|
|
|
|
stats.begin(),
|
|
|
|
stats.end(),
|
|
|
|
[baseline](auto const* st) { return baseline == st->startDate; });
|
2013-01-04 19:45:39 +00:00
|
|
|
|
2017-05-13 22:38:31 +00:00
|
|
|
if (!is_uniform)
|
2017-04-19 12:04:45 +00:00
|
|
|
{
|
|
|
|
str = mixed;
|
|
|
|
}
|
2017-04-30 16:25:26 +00:00
|
|
|
else if (baseline <= 0 || stats[0]->activity == TR_STATUS_STOPPED)
|
2017-04-19 12:04:45 +00:00
|
|
|
{
|
|
|
|
str = stateString;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2023-02-15 12:19:57 +00:00
|
|
|
str = tr_format_time(now - baseline);
|
2017-04-19 12:04:45 +00:00
|
|
|
}
|
2013-01-04 19:45:39 +00:00
|
|
|
}
|
2017-04-19 12:04:45 +00:00
|
|
|
|
2021-10-18 20:22:31 +00:00
|
|
|
date_started_lb_->set_text(str);
|
2013-01-04 19:45:39 +00:00
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
/* eta */
|
2021-10-18 20:22:31 +00:00
|
|
|
if (stats.empty())
|
2013-01-04 19:45:39 +00:00
|
|
|
{
|
2017-04-19 12:04:45 +00:00
|
|
|
str = no_torrent;
|
2009-04-24 01:37:04 +00:00
|
|
|
}
|
2017-04-19 12:04:45 +00:00
|
|
|
else
|
2013-01-04 19:45:39 +00:00
|
|
|
{
|
2022-11-23 15:14:05 +00:00
|
|
|
auto const baseline = stats.front()->eta;
|
|
|
|
auto const is_uniform = std::all_of(
|
2021-10-18 20:22:31 +00:00
|
|
|
stats.begin(),
|
|
|
|
stats.end(),
|
|
|
|
[baseline](auto const* st) { return baseline == st->eta; });
|
2013-01-04 19:45:39 +00:00
|
|
|
|
2017-05-13 22:38:31 +00:00
|
|
|
if (!is_uniform)
|
2017-04-19 12:04:45 +00:00
|
|
|
{
|
|
|
|
str = mixed;
|
|
|
|
}
|
|
|
|
else if (baseline < 0)
|
|
|
|
{
|
|
|
|
str = _("Unknown");
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2022-11-23 15:14:05 +00:00
|
|
|
str = tr_format_time_left(baseline);
|
2017-04-19 12:04:45 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-10-18 20:22:31 +00:00
|
|
|
eta_lb_->set_text(str);
|
2017-04-19 12:04:45 +00:00
|
|
|
|
|
|
|
/* size_lb */
|
|
|
|
{
|
2022-04-07 13:23:04 +00:00
|
|
|
auto const piece_count = std::accumulate(
|
|
|
|
std::begin(infos),
|
|
|
|
std::end(infos),
|
|
|
|
uint64_t{},
|
|
|
|
[](auto sum, auto const& info) { return sum + info.n_pieces; });
|
2013-01-04 19:45:39 +00:00
|
|
|
|
2022-04-07 13:23:04 +00:00
|
|
|
if (piece_count == 0)
|
2017-04-19 12:04:45 +00:00
|
|
|
{
|
2021-10-18 20:22:31 +00:00
|
|
|
str.clear();
|
2017-04-19 12:04:45 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2022-04-07 13:23:04 +00:00
|
|
|
auto const total_size = std::accumulate(
|
|
|
|
std::begin(infos),
|
|
|
|
std::end(infos),
|
|
|
|
uint64_t{},
|
|
|
|
[](auto sum, auto const& info) { return sum + info.total_size; });
|
|
|
|
|
|
|
|
auto const file_count = std::accumulate(
|
|
|
|
std::begin(torrents),
|
|
|
|
std::end(torrents),
|
|
|
|
std::size_t{},
|
|
|
|
[](auto sum, auto const* tor) { return sum + tr_torrentFileCount(tor); });
|
|
|
|
|
2022-03-21 14:15:48 +00:00
|
|
|
str = fmt::format(
|
2022-04-07 13:23:04 +00:00
|
|
|
ngettext("{total_size} in {file_count:L} file", "{total_size} in {file_count:L} files", file_count),
|
|
|
|
fmt::arg("total_size", tr_strlsize(total_size)),
|
|
|
|
fmt::arg("file_count", file_count));
|
|
|
|
|
|
|
|
auto const piece_size = std::empty(infos) ? uint32_t{} : infos.front().piece_size;
|
|
|
|
auto const piece_size_is_uniform = std::all_of(
|
|
|
|
std::begin(infos),
|
|
|
|
std::end(infos),
|
|
|
|
[piece_size](auto const& info) { return info.piece_size == piece_size; });
|
|
|
|
|
|
|
|
if (piece_size_is_uniform)
|
|
|
|
{
|
|
|
|
str += ' ';
|
|
|
|
str += fmt::format(
|
|
|
|
ngettext(
|
|
|
|
"({piece_count} BitTorrent piece @ {piece_size})",
|
|
|
|
"({piece_count} BitTorrent pieces @ {piece_size})",
|
|
|
|
piece_count),
|
|
|
|
fmt::arg("piece_count", piece_count),
|
2023-11-14 23:23:51 +00:00
|
|
|
fmt::arg("piece_size", Memory{ piece_size, Memory::Units::Bytes }.to_string()));
|
2022-04-07 13:23:04 +00:00
|
|
|
}
|
2017-04-19 12:04:45 +00:00
|
|
|
}
|
|
|
|
|
2021-10-18 20:22:31 +00:00
|
|
|
size_lb_->set_text(str);
|
2017-04-19 12:04:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* have_lb */
|
2021-10-18 20:22:31 +00:00
|
|
|
if (stats.empty())
|
2013-01-04 19:45:39 +00:00
|
|
|
{
|
2017-04-19 12:04:45 +00:00
|
|
|
str = no_torrent;
|
2013-01-04 19:45:39 +00:00
|
|
|
}
|
2017-04-19 12:04:45 +00:00
|
|
|
else
|
2013-01-04 19:45:39 +00:00
|
|
|
{
|
2017-04-19 12:04:45 +00:00
|
|
|
uint64_t leftUntilDone = 0;
|
|
|
|
uint64_t haveUnchecked = 0;
|
|
|
|
uint64_t haveValid = 0;
|
|
|
|
uint64_t available = 0;
|
2013-01-04 19:45:39 +00:00
|
|
|
|
2021-10-18 20:22:31 +00:00
|
|
|
for (auto const* const st : stats)
|
2013-01-04 19:45:39 +00:00
|
|
|
{
|
2017-04-19 12:04:45 +00:00
|
|
|
haveUnchecked += st->haveUnchecked;
|
|
|
|
haveValid += st->haveValid;
|
|
|
|
sizeWhenDone += st->sizeWhenDone;
|
|
|
|
leftUntilDone += st->leftUntilDone;
|
2020-04-26 05:07:40 +00:00
|
|
|
available += st->sizeWhenDone - st->leftUntilDone + st->haveUnchecked + st->desiredAvailable;
|
2009-06-23 00:24:37 +00:00
|
|
|
}
|
2013-01-04 19:45:39 +00:00
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
{
|
2017-05-01 15:47:49 +00:00
|
|
|
double const d = sizeWhenDone != 0 ? (100.0 * available) / sizeWhenDone : 0;
|
|
|
|
double const ratio = 100.0 * (sizeWhenDone != 0 ? (haveValid + haveUnchecked) / (double)sizeWhenDone : 1);
|
2013-01-04 19:45:39 +00:00
|
|
|
|
2022-04-01 16:29:05 +00:00
|
|
|
auto const avail = tr_strpercent(d);
|
|
|
|
auto const buf2 = tr_strpercent(ratio);
|
2021-10-18 20:22:31 +00:00
|
|
|
auto const total = tr_strlsize(haveUnchecked + haveValid);
|
|
|
|
auto const unver = tr_strlsize(haveUnchecked);
|
2013-01-04 19:45:39 +00:00
|
|
|
|
2017-04-30 16:25:26 +00:00
|
|
|
if (haveUnchecked == 0 && leftUntilDone == 0)
|
2017-04-19 12:04:45 +00:00
|
|
|
{
|
2022-03-21 14:15:48 +00:00
|
|
|
str = fmt::format(
|
|
|
|
_("{current_size} ({percent_done}%)"),
|
|
|
|
fmt::arg("current_size", total),
|
|
|
|
fmt::arg("percent_done", buf2));
|
2017-04-19 12:04:45 +00:00
|
|
|
}
|
2017-04-30 16:25:26 +00:00
|
|
|
else if (haveUnchecked == 0)
|
2017-04-19 12:04:45 +00:00
|
|
|
{
|
2022-03-21 14:15:48 +00:00
|
|
|
str = fmt::format(
|
2022-06-08 06:04:17 +00:00
|
|
|
// xgettext:no-c-format
|
2022-04-16 00:56:16 +00:00
|
|
|
_("{current_size} ({percent_done}% of {percent_available}% available)"),
|
2022-03-21 14:15:48 +00:00
|
|
|
fmt::arg("current_size", total),
|
|
|
|
fmt::arg("percent_done", buf2),
|
|
|
|
fmt::arg("percent_available", avail));
|
2017-04-19 12:04:45 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2022-03-21 14:15:48 +00:00
|
|
|
str = fmt::format(
|
2022-06-08 06:04:17 +00:00
|
|
|
// xgettext:no-c-format
|
2022-03-21 14:15:48 +00:00
|
|
|
_("{current_size} ({percent_done}% of {percent_available}% available; {unverified_size} unverified)"),
|
|
|
|
fmt::arg("current_size", total),
|
|
|
|
fmt::arg("percent_done", buf2),
|
|
|
|
fmt::arg("percent_available", avail),
|
|
|
|
fmt::arg("unverified_size", unver));
|
2017-04-19 12:04:45 +00:00
|
|
|
}
|
|
|
|
}
|
2009-04-24 01:37:04 +00:00
|
|
|
}
|
2007-06-06 00:30:13 +00:00
|
|
|
|
2021-10-18 20:22:31 +00:00
|
|
|
have_lb_->set_text(str);
|
2017-04-19 12:04:45 +00:00
|
|
|
|
2022-03-21 14:15:48 +00:00
|
|
|
// dl_lb
|
2021-10-18 20:22:31 +00:00
|
|
|
if (stats.empty())
|
2013-01-04 19:45:39 +00:00
|
|
|
{
|
2017-04-19 12:04:45 +00:00
|
|
|
str = no_torrent;
|
2013-01-04 19:45:39 +00:00
|
|
|
}
|
2017-04-19 12:04:45 +00:00
|
|
|
else
|
2013-01-04 19:45:39 +00:00
|
|
|
{
|
2022-03-21 14:15:48 +00:00
|
|
|
auto const downloaded_str = tr_strlsize(std::accumulate(
|
|
|
|
std::begin(stats),
|
|
|
|
std::end(stats),
|
|
|
|
uint64_t{ 0 },
|
|
|
|
[](auto sum, auto const* st) { return sum + st->downloadedEver; }));
|
2013-01-04 19:45:39 +00:00
|
|
|
|
2022-03-21 14:15:48 +00:00
|
|
|
auto const failed = std::accumulate(
|
|
|
|
std::begin(stats),
|
|
|
|
std::end(stats),
|
|
|
|
uint64_t{ 0 },
|
|
|
|
[](auto sum, auto const* st) { return sum + st->corruptEver; });
|
2013-01-04 19:45:39 +00:00
|
|
|
|
2022-03-21 14:15:48 +00:00
|
|
|
if (failed != 0)
|
2017-04-19 12:04:45 +00:00
|
|
|
{
|
2022-03-21 14:15:48 +00:00
|
|
|
str = fmt::format(
|
|
|
|
_("{downloaded_size} (+{discarded_size} discarded after failed checksum)"),
|
|
|
|
fmt::arg("downloaded_size", downloaded_str),
|
|
|
|
fmt::arg("discarded_size", tr_strlsize(failed)));
|
2017-04-19 12:04:45 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2022-03-21 14:15:48 +00:00
|
|
|
str = downloaded_str;
|
2017-04-19 12:04:45 +00:00
|
|
|
}
|
2009-04-24 01:37:04 +00:00
|
|
|
}
|
2007-06-06 00:30:13 +00:00
|
|
|
|
2021-10-18 20:22:31 +00:00
|
|
|
dl_lb_->set_text(str);
|
2013-01-04 19:45:39 +00:00
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
/* ul_lb */
|
2021-10-18 20:22:31 +00:00
|
|
|
if (stats.empty())
|
2013-01-04 19:45:39 +00:00
|
|
|
{
|
2017-04-19 12:04:45 +00:00
|
|
|
str = no_torrent;
|
2013-01-04 19:45:39 +00:00
|
|
|
}
|
2017-04-19 12:04:45 +00:00
|
|
|
else
|
2013-01-04 19:45:39 +00:00
|
|
|
{
|
2022-03-17 18:41:48 +00:00
|
|
|
auto const uploaded = std::accumulate(
|
|
|
|
std::begin(stats),
|
|
|
|
std::end(stats),
|
|
|
|
uint64_t{},
|
|
|
|
[](auto sum, auto const* st) { return sum + st->uploadedEver; });
|
|
|
|
auto const denominator = std::accumulate(
|
|
|
|
std::begin(stats),
|
|
|
|
std::end(stats),
|
|
|
|
uint64_t{},
|
|
|
|
[](auto sum, auto const* st) { return sum + st->sizeWhenDone; });
|
2022-03-21 14:15:48 +00:00
|
|
|
str = fmt::format(
|
|
|
|
_("{uploaded_size} (Ratio: {ratio})"),
|
|
|
|
fmt::arg("uploaded_size", tr_strlsize(uploaded)),
|
|
|
|
fmt::arg("ratio", tr_strlratio(tr_getRatio(uploaded, denominator))));
|
2013-01-04 19:45:39 +00:00
|
|
|
}
|
|
|
|
|
2021-10-18 20:22:31 +00:00
|
|
|
ul_lb_->set_text(str);
|
2013-01-04 19:45:39 +00:00
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
/* hash_lb */
|
2021-10-18 20:22:31 +00:00
|
|
|
if (infos.empty())
|
2017-04-19 12:04:45 +00:00
|
|
|
{
|
|
|
|
str = no_torrent;
|
|
|
|
}
|
2021-10-18 20:22:31 +00:00
|
|
|
else if (infos.size() == 1)
|
2013-01-04 19:45:39 +00:00
|
|
|
{
|
2021-12-14 21:59:44 +00:00
|
|
|
str = infos.front().hash_string;
|
2013-01-04 19:45:39 +00:00
|
|
|
}
|
2017-04-19 12:04:45 +00:00
|
|
|
else
|
2013-01-04 19:45:39 +00:00
|
|
|
{
|
2017-04-19 12:04:45 +00:00
|
|
|
str = mixed;
|
|
|
|
}
|
2013-01-04 19:45:39 +00:00
|
|
|
|
2021-10-18 20:22:31 +00:00
|
|
|
hash_lb_->set_text(str);
|
2013-01-04 19:45:39 +00:00
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
/* error */
|
2021-10-18 20:22:31 +00:00
|
|
|
if (stats.empty())
|
2017-04-19 12:04:45 +00:00
|
|
|
{
|
|
|
|
str = no_torrent;
|
2013-01-04 19:45:39 +00:00
|
|
|
}
|
2017-04-19 12:04:45 +00:00
|
|
|
else
|
|
|
|
{
|
2021-10-18 20:22:31 +00:00
|
|
|
auto const baseline = Glib::ustring(stats.front()->errorString);
|
|
|
|
bool const is_uniform = std::all_of(
|
|
|
|
stats.begin(),
|
|
|
|
stats.end(),
|
|
|
|
[&baseline](auto const* st) { return baseline == st->errorString; });
|
2017-04-19 12:04:45 +00:00
|
|
|
|
2017-05-13 22:38:31 +00:00
|
|
|
str = is_uniform ? baseline : mixed;
|
2017-04-19 12:04:45 +00:00
|
|
|
}
|
|
|
|
|
2021-10-18 20:22:31 +00:00
|
|
|
if (str.empty())
|
2017-04-19 12:04:45 +00:00
|
|
|
{
|
|
|
|
str = _("No errors");
|
|
|
|
}
|
|
|
|
|
2021-10-18 20:22:31 +00:00
|
|
|
error_lb_->set_text(str);
|
2013-01-04 19:45:39 +00:00
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
/* activity date */
|
2021-10-18 20:22:31 +00:00
|
|
|
if (stats.empty())
|
2013-01-04 19:45:39 +00:00
|
|
|
{
|
2017-04-19 12:04:45 +00:00
|
|
|
str = no_torrent;
|
2013-01-04 19:45:39 +00:00
|
|
|
}
|
2017-04-19 12:04:45 +00:00
|
|
|
else
|
2013-01-04 19:45:39 +00:00
|
|
|
{
|
2021-10-18 20:22:31 +00:00
|
|
|
time_t const latest = (*std::max_element(
|
|
|
|
stats.begin(),
|
|
|
|
stats.end(),
|
|
|
|
[](auto const* lhs, auto const* rhs) { return lhs->activityDate < rhs->activityDate; }))
|
|
|
|
->activityDate;
|
2013-01-04 19:45:39 +00:00
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
if (latest <= 0)
|
2013-01-04 19:45:39 +00:00
|
|
|
{
|
2017-04-19 12:04:45 +00:00
|
|
|
str = _("Never");
|
2013-01-04 19:45:39 +00:00
|
|
|
}
|
2022-06-15 02:56:27 +00:00
|
|
|
else if ((now - latest) < 5)
|
|
|
|
{
|
|
|
|
str = _("Active now");
|
|
|
|
}
|
2017-04-19 12:04:45 +00:00
|
|
|
else
|
2013-01-04 19:45:39 +00:00
|
|
|
{
|
2022-06-15 02:56:27 +00:00
|
|
|
str = tr_format_time_relative(now, latest);
|
2009-06-23 00:24:37 +00:00
|
|
|
}
|
2009-04-24 01:37:04 +00:00
|
|
|
}
|
2008-09-23 19:11:04 +00:00
|
|
|
|
2021-10-18 20:22:31 +00:00
|
|
|
last_activity_lb_->set_text(str);
|
2007-06-06 00:30:13 +00:00
|
|
|
}
|
|
|
|
|
2022-09-07 22:25:04 +00:00
|
|
|
void DetailsDialog::Impl::info_page_init(Glib::RefPtr<Gtk::Builder> const& builder)
|
2007-06-06 00:30:13 +00:00
|
|
|
{
|
2021-10-18 20:22:31 +00:00
|
|
|
comment_buffer_ = Gtk::TextBuffer::create();
|
2022-09-07 22:25:04 +00:00
|
|
|
auto* tw = gtr_get_widget<Gtk::TextView>(builder, "comment_value_view");
|
|
|
|
tw->set_buffer(comment_buffer_);
|
2007-06-06 00:30:13 +00:00
|
|
|
}
|
|
|
|
|
2009-04-24 01:37:04 +00:00
|
|
|
/****
|
|
|
|
*****
|
|
|
|
***** PEERS TAB
|
|
|
|
*****
|
|
|
|
****/
|
2009-02-13 18:23:56 +00:00
|
|
|
|
2021-10-18 20:22:31 +00:00
|
|
|
namespace
|
2009-02-13 18:23:56 +00:00
|
|
|
{
|
2009-04-24 01:37:04 +00:00
|
|
|
|
2021-10-18 20:22:31 +00:00
|
|
|
class WebseedModelColumns : public Gtk::TreeModelColumnRecord
|
2009-04-24 01:37:04 +00:00
|
|
|
{
|
2021-10-18 20:22:31 +00:00
|
|
|
public:
|
2022-11-15 00:53:12 +00:00
|
|
|
WebseedModelColumns() noexcept
|
2009-02-13 18:23:56 +00:00
|
|
|
{
|
2021-10-18 20:22:31 +00:00
|
|
|
add(key);
|
|
|
|
add(was_updated);
|
|
|
|
add(url);
|
2023-11-16 04:15:40 +00:00
|
|
|
add(download_rate_speed);
|
2021-10-18 20:22:31 +00:00
|
|
|
add(download_rate_string);
|
2009-02-13 18:23:56 +00:00
|
|
|
}
|
|
|
|
|
2021-10-18 20:22:31 +00:00
|
|
|
Gtk::TreeModelColumn<std::string> key;
|
|
|
|
Gtk::TreeModelColumn<bool> was_updated;
|
|
|
|
Gtk::TreeModelColumn<Glib::ustring> url;
|
2023-11-16 04:15:40 +00:00
|
|
|
Gtk::TreeModelColumn<Speed> download_rate_speed;
|
2021-10-18 20:22:31 +00:00
|
|
|
Gtk::TreeModelColumn<Glib::ustring> download_rate_string;
|
2009-04-24 01:37:04 +00:00
|
|
|
};
|
|
|
|
|
2021-10-18 20:22:31 +00:00
|
|
|
WebseedModelColumns const webseed_cols;
|
|
|
|
|
|
|
|
class PeerModelColumns : public Gtk::TreeModelColumnRecord
|
|
|
|
{
|
|
|
|
public:
|
2022-11-15 00:53:12 +00:00
|
|
|
PeerModelColumns() noexcept
|
2021-10-18 20:22:31 +00:00
|
|
|
{
|
|
|
|
add(key);
|
|
|
|
add(was_updated);
|
|
|
|
add(address);
|
|
|
|
add(address_collated);
|
2023-11-16 04:15:40 +00:00
|
|
|
add(download_rate_speed);
|
2021-10-18 20:22:31 +00:00
|
|
|
add(download_rate_string);
|
2023-11-16 04:15:40 +00:00
|
|
|
add(upload_rate_speed);
|
2021-10-18 20:22:31 +00:00
|
|
|
add(upload_rate_string);
|
|
|
|
add(client);
|
|
|
|
add(progress);
|
2022-11-23 19:47:04 +00:00
|
|
|
add(upload_request_count_number);
|
2021-10-18 20:22:31 +00:00
|
|
|
add(upload_request_count_string);
|
2022-11-23 19:47:04 +00:00
|
|
|
add(download_request_count_number);
|
2021-10-18 20:22:31 +00:00
|
|
|
add(download_request_count_string);
|
2022-11-23 19:47:04 +00:00
|
|
|
add(blocks_downloaded_count_number);
|
2021-10-18 20:22:31 +00:00
|
|
|
add(blocks_downloaded_count_string);
|
2022-11-23 19:47:04 +00:00
|
|
|
add(blocks_uploaded_count_number);
|
2021-10-18 20:22:31 +00:00
|
|
|
add(blocks_uploaded_count_string);
|
2022-11-23 19:47:04 +00:00
|
|
|
add(reqs_cancelled_by_client_count_number);
|
2021-10-18 20:22:31 +00:00
|
|
|
add(reqs_cancelled_by_client_count_string);
|
2022-11-23 19:47:04 +00:00
|
|
|
add(reqs_cancelled_by_peer_count_number);
|
2021-10-18 20:22:31 +00:00
|
|
|
add(reqs_cancelled_by_peer_count_string);
|
|
|
|
add(encryption_stock_id);
|
|
|
|
add(flags);
|
|
|
|
add(torrent_name);
|
|
|
|
}
|
|
|
|
|
|
|
|
Gtk::TreeModelColumn<std::string> key;
|
|
|
|
Gtk::TreeModelColumn<bool> was_updated;
|
|
|
|
Gtk::TreeModelColumn<Glib::ustring> address;
|
|
|
|
Gtk::TreeModelColumn<Glib::ustring> address_collated;
|
2023-11-16 04:15:40 +00:00
|
|
|
Gtk::TreeModelColumn<Speed> download_rate_speed;
|
2021-10-18 20:22:31 +00:00
|
|
|
Gtk::TreeModelColumn<Glib::ustring> download_rate_string;
|
2023-11-16 04:15:40 +00:00
|
|
|
Gtk::TreeModelColumn<Speed> upload_rate_speed;
|
2021-10-18 20:22:31 +00:00
|
|
|
Gtk::TreeModelColumn<Glib::ustring> upload_rate_string;
|
|
|
|
Gtk::TreeModelColumn<Glib::ustring> client;
|
|
|
|
Gtk::TreeModelColumn<int> progress;
|
2022-11-23 19:47:04 +00:00
|
|
|
Gtk::TreeModelColumn<decltype(tr_peer_stat::activeReqsToClient)> upload_request_count_number;
|
2021-10-18 20:22:31 +00:00
|
|
|
Gtk::TreeModelColumn<Glib::ustring> upload_request_count_string;
|
2022-11-23 19:47:04 +00:00
|
|
|
Gtk::TreeModelColumn<decltype(tr_peer_stat::activeReqsToPeer)> download_request_count_number;
|
2021-10-18 20:22:31 +00:00
|
|
|
Gtk::TreeModelColumn<Glib::ustring> download_request_count_string;
|
2022-11-23 19:47:04 +00:00
|
|
|
Gtk::TreeModelColumn<decltype(tr_peer_stat::blocksToClient)> blocks_downloaded_count_number;
|
2021-10-18 20:22:31 +00:00
|
|
|
Gtk::TreeModelColumn<Glib::ustring> blocks_downloaded_count_string;
|
2022-11-23 19:47:04 +00:00
|
|
|
Gtk::TreeModelColumn<decltype(tr_peer_stat::blocksToPeer)> blocks_uploaded_count_number;
|
2021-10-18 20:22:31 +00:00
|
|
|
Gtk::TreeModelColumn<Glib::ustring> blocks_uploaded_count_string;
|
2022-11-23 19:47:04 +00:00
|
|
|
Gtk::TreeModelColumn<decltype(tr_peer_stat::cancelsToPeer)> reqs_cancelled_by_client_count_number;
|
2021-10-18 20:22:31 +00:00
|
|
|
Gtk::TreeModelColumn<Glib::ustring> reqs_cancelled_by_client_count_string;
|
2022-11-23 19:47:04 +00:00
|
|
|
Gtk::TreeModelColumn<decltype(tr_peer_stat::cancelsToClient)> reqs_cancelled_by_peer_count_number;
|
2021-10-18 20:22:31 +00:00
|
|
|
Gtk::TreeModelColumn<Glib::ustring> reqs_cancelled_by_peer_count_string;
|
|
|
|
Gtk::TreeModelColumn<Glib::ustring> encryption_stock_id;
|
|
|
|
Gtk::TreeModelColumn<Glib::ustring> flags;
|
|
|
|
Gtk::TreeModelColumn<Glib::ustring> torrent_name;
|
|
|
|
};
|
2009-04-24 01:37:04 +00:00
|
|
|
|
2021-10-18 20:22:31 +00:00
|
|
|
PeerModelColumns const peer_cols;
|
2009-04-24 01:37:04 +00:00
|
|
|
|
2022-10-08 22:50:03 +00:00
|
|
|
void initPeerRow(
|
|
|
|
Gtk::TreeModel::iterator const& iter,
|
|
|
|
std::string_view key,
|
|
|
|
std::string_view torrent_name,
|
|
|
|
tr_peer_stat const* peer)
|
2017-04-19 12:04:45 +00:00
|
|
|
{
|
2021-10-06 16:32:17 +00:00
|
|
|
g_return_if_fail(peer != nullptr);
|
2017-04-19 12:04:45 +00:00
|
|
|
|
2020-10-31 21:23:43 +00:00
|
|
|
char const* client = peer->client;
|
2021-10-06 16:32:17 +00:00
|
|
|
if (client == nullptr || g_strcmp0(client, "Unknown Client") == 0)
|
2017-04-19 12:04:45 +00:00
|
|
|
{
|
|
|
|
client = "";
|
|
|
|
}
|
|
|
|
|
2022-11-09 16:58:36 +00:00
|
|
|
auto peer_addr4 = in_addr();
|
2022-11-13 17:36:16 +00:00
|
|
|
// NOLINTNEXTLINE(cppcoreguidelines-pro-type-reinterpret-cast)
|
|
|
|
auto const* const peer_addr4_octets = reinterpret_cast<uint8_t const*>(&peer_addr4.s_addr);
|
|
|
|
auto const collated_name = inet_pton(AF_INET, std::data(peer->addr), &peer_addr4) != 1 ?
|
|
|
|
std::data(peer->addr) :
|
2022-11-09 16:58:36 +00:00
|
|
|
fmt::format(
|
|
|
|
"{:03}",
|
|
|
|
fmt::join(
|
2022-11-13 17:36:16 +00:00
|
|
|
peer_addr4_octets,
|
|
|
|
// NOLINTNEXTLINE(cppcoreguidelines-pro-bounds-pointer-arithmetic)
|
|
|
|
peer_addr4_octets + sizeof(peer_addr4.s_addr), // TODO(C++20): Use std::span
|
2022-11-09 16:58:36 +00:00
|
|
|
"."));
|
2017-04-19 12:04:45 +00:00
|
|
|
|
2022-11-13 17:36:16 +00:00
|
|
|
(*iter)[peer_cols.address] = std::data(peer->addr);
|
2021-10-18 20:22:31 +00:00
|
|
|
(*iter)[peer_cols.address_collated] = collated_name;
|
|
|
|
(*iter)[peer_cols.client] = client;
|
2021-11-12 09:12:50 +00:00
|
|
|
(*iter)[peer_cols.encryption_stock_id] = peer->isEncrypted ? "lock" : "";
|
2023-02-13 17:16:15 +00:00
|
|
|
(*iter)[peer_cols.key] = std::string(key);
|
|
|
|
(*iter)[peer_cols.torrent_name] = std::string(torrent_name);
|
2007-06-06 00:30:13 +00:00
|
|
|
}
|
|
|
|
|
2022-10-08 22:50:03 +00:00
|
|
|
void refreshPeerRow(Gtk::TreeModel::iterator const& iter, tr_peer_stat const* peer)
|
2017-04-19 12:04:45 +00:00
|
|
|
{
|
2021-10-06 16:32:17 +00:00
|
|
|
g_return_if_fail(peer != nullptr);
|
2020-11-01 21:47:57 +00:00
|
|
|
|
2023-11-16 04:15:40 +00:00
|
|
|
auto const down_speed = Speed{ peer->rateToClient_KBps, Speed::Units::KByps };
|
|
|
|
auto const up_speed = Speed{ peer->rateToPeer_KBps, Speed::Units::KByps };
|
|
|
|
|
|
|
|
auto blocks_to_client = std::string{};
|
|
|
|
auto blocks_to_peer = std::string{};
|
|
|
|
auto cancelled_by_client = std::string{};
|
|
|
|
auto cancelled_by_peer = std::string{};
|
|
|
|
auto down_count = std::string{};
|
|
|
|
auto down_speed_string = std::string{};
|
|
|
|
auto up_count = std::string{};
|
|
|
|
auto up_speed_string = std::string{};
|
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
if (peer->rateToPeer_KBps > 0.01)
|
|
|
|
{
|
2023-11-16 04:15:40 +00:00
|
|
|
up_speed_string = up_speed.to_string();
|
2017-04-19 12:04:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (peer->rateToClient_KBps > 0)
|
|
|
|
{
|
2023-11-16 04:15:40 +00:00
|
|
|
down_speed_string = down_speed.to_string();
|
2017-04-19 12:04:45 +00:00
|
|
|
}
|
|
|
|
|
2022-06-29 01:48:39 +00:00
|
|
|
if (peer->activeReqsToPeer > 0)
|
2017-04-19 12:04:45 +00:00
|
|
|
{
|
2022-06-29 01:48:39 +00:00
|
|
|
down_count = std::to_string(peer->activeReqsToPeer);
|
2017-04-19 12:04:45 +00:00
|
|
|
}
|
|
|
|
|
2022-06-29 01:48:39 +00:00
|
|
|
if (peer->activeReqsToClient > 0)
|
2017-04-19 12:04:45 +00:00
|
|
|
{
|
2022-06-29 01:48:39 +00:00
|
|
|
up_count = std::to_string(peer->activeReqsToClient);
|
2017-04-19 12:04:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (peer->blocksToPeer > 0)
|
|
|
|
{
|
2021-10-18 20:22:31 +00:00
|
|
|
blocks_to_peer = std::to_string(peer->blocksToPeer);
|
2017-04-19 12:04:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (peer->blocksToClient > 0)
|
|
|
|
{
|
2021-10-18 20:22:31 +00:00
|
|
|
blocks_to_client = std::to_string(peer->blocksToClient);
|
2017-04-19 12:04:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (peer->cancelsToPeer > 0)
|
|
|
|
{
|
2021-10-18 20:22:31 +00:00
|
|
|
cancelled_by_client = std::to_string(peer->cancelsToPeer);
|
2017-04-19 12:04:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (peer->cancelsToClient > 0)
|
|
|
|
{
|
2021-10-18 20:22:31 +00:00
|
|
|
cancelled_by_peer = std::to_string(peer->cancelsToClient);
|
|
|
|
}
|
|
|
|
|
2022-11-23 19:47:04 +00:00
|
|
|
(*iter)[peer_cols.progress] = static_cast<int>(100.0 * peer->progress);
|
|
|
|
(*iter)[peer_cols.upload_request_count_number] = peer->activeReqsToClient;
|
2021-10-18 20:22:31 +00:00
|
|
|
(*iter)[peer_cols.upload_request_count_string] = up_count;
|
2022-11-23 19:47:04 +00:00
|
|
|
(*iter)[peer_cols.download_request_count_number] = peer->activeReqsToPeer;
|
2021-10-18 20:22:31 +00:00
|
|
|
(*iter)[peer_cols.download_request_count_string] = down_count;
|
2023-11-16 04:15:40 +00:00
|
|
|
(*iter)[peer_cols.download_rate_speed] = down_speed;
|
|
|
|
(*iter)[peer_cols.download_rate_string] = down_speed_string;
|
|
|
|
(*iter)[peer_cols.upload_rate_speed] = up_speed;
|
|
|
|
(*iter)[peer_cols.upload_rate_string] = up_speed_string;
|
2022-11-13 17:36:16 +00:00
|
|
|
(*iter)[peer_cols.flags] = std::data(peer->flagStr);
|
2021-10-18 20:22:31 +00:00
|
|
|
(*iter)[peer_cols.was_updated] = true;
|
2022-11-23 19:47:04 +00:00
|
|
|
(*iter)[peer_cols.blocks_downloaded_count_number] = peer->blocksToClient;
|
2021-10-18 20:22:31 +00:00
|
|
|
(*iter)[peer_cols.blocks_downloaded_count_string] = blocks_to_client;
|
2022-11-23 19:47:04 +00:00
|
|
|
(*iter)[peer_cols.blocks_uploaded_count_number] = peer->blocksToPeer;
|
2021-10-18 20:22:31 +00:00
|
|
|
(*iter)[peer_cols.blocks_uploaded_count_string] = blocks_to_peer;
|
2022-11-23 19:47:04 +00:00
|
|
|
(*iter)[peer_cols.reqs_cancelled_by_client_count_number] = peer->cancelsToPeer;
|
2021-10-18 20:22:31 +00:00
|
|
|
(*iter)[peer_cols.reqs_cancelled_by_client_count_string] = cancelled_by_client;
|
2022-11-23 19:47:04 +00:00
|
|
|
(*iter)[peer_cols.reqs_cancelled_by_peer_count_number] = peer->cancelsToClient;
|
2021-10-18 20:22:31 +00:00
|
|
|
(*iter)[peer_cols.reqs_cancelled_by_peer_count_string] = cancelled_by_peer;
|
2007-06-06 00:30:13 +00:00
|
|
|
}
|
2008-09-23 19:11:04 +00:00
|
|
|
|
2021-10-18 20:22:31 +00:00
|
|
|
} // namespace
|
|
|
|
|
|
|
|
void DetailsDialog::Impl::refreshPeerList(std::vector<tr_torrent*> const& torrents)
|
2007-06-06 00:30:13 +00:00
|
|
|
{
|
2021-10-18 20:22:31 +00:00
|
|
|
auto& hash = peer_hash_;
|
2022-04-02 22:42:51 +00:00
|
|
|
auto const& store = peer_store_;
|
2013-01-04 19:45:39 +00:00
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
/* step 1: get all the peers */
|
2021-10-18 20:22:31 +00:00
|
|
|
std::vector<tr_peer_stat*> peers;
|
2022-10-25 16:14:42 +00:00
|
|
|
std::vector<size_t> peerCount;
|
2017-04-19 12:04:45 +00:00
|
|
|
|
2021-10-18 20:22:31 +00:00
|
|
|
peers.reserve(torrents.size());
|
|
|
|
peerCount.reserve(torrents.size());
|
|
|
|
for (auto const* const torrent : torrents)
|
2017-04-19 12:04:45 +00:00
|
|
|
{
|
2022-10-25 16:14:42 +00:00
|
|
|
size_t count = 0;
|
2021-10-18 20:22:31 +00:00
|
|
|
peers.push_back(tr_torrentPeers(torrent, &count));
|
|
|
|
peerCount.push_back(count);
|
2017-04-19 12:04:45 +00:00
|
|
|
}
|
2013-01-04 19:45:39 +00:00
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
/* step 2: mark all the peers in the list as not-updated */
|
2022-10-08 22:50:03 +00:00
|
|
|
for (auto& row : store->children())
|
2013-01-04 19:45:39 +00:00
|
|
|
{
|
2021-10-18 20:22:31 +00:00
|
|
|
row[peer_cols.was_updated] = false;
|
2017-04-19 12:04:45 +00:00
|
|
|
}
|
2013-01-04 19:45:39 +00:00
|
|
|
|
2022-03-21 14:15:48 +00:00
|
|
|
auto make_key = [](tr_torrent const* tor, tr_peer_stat const* ps)
|
|
|
|
{
|
2024-01-06 20:05:18 +00:00
|
|
|
return fmt::format("{:d}.{:s}", tr_torrentId(tor), ps->addr);
|
2022-03-21 14:15:48 +00:00
|
|
|
};
|
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
/* step 3: add any new peers */
|
2021-10-18 20:22:31 +00:00
|
|
|
for (size_t i = 0; i < torrents.size(); ++i)
|
2017-04-19 12:04:45 +00:00
|
|
|
{
|
2021-10-18 20:22:31 +00:00
|
|
|
auto const* tor = torrents.at(i);
|
2017-04-19 12:04:45 +00:00
|
|
|
|
2022-10-25 16:14:42 +00:00
|
|
|
for (size_t j = 0; j < peerCount[i]; ++j)
|
2013-01-04 19:45:39 +00:00
|
|
|
{
|
2021-10-18 20:22:31 +00:00
|
|
|
auto const* s = &peers.at(i)[j];
|
2022-03-21 14:15:48 +00:00
|
|
|
auto const key = make_key(tor, s);
|
2017-04-19 12:04:45 +00:00
|
|
|
|
2021-10-18 20:22:31 +00:00
|
|
|
if (hash.find(key) == hash.end())
|
2013-01-04 19:45:39 +00:00
|
|
|
{
|
2021-10-18 20:22:31 +00:00
|
|
|
auto const iter = store->append();
|
|
|
|
initPeerRow(iter, key, tr_torrentName(tor), s);
|
2022-01-17 18:39:50 +00:00
|
|
|
hash.try_emplace(key, Gtk::TreeRowReference(store, store->get_path(iter)));
|
2009-04-24 01:37:04 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
/* step 4: update the peers */
|
2021-10-18 20:22:31 +00:00
|
|
|
for (size_t i = 0; i < torrents.size(); ++i)
|
2013-01-04 19:45:39 +00:00
|
|
|
{
|
2021-10-18 20:22:31 +00:00
|
|
|
auto const* tor = torrents.at(i);
|
2013-01-04 19:45:39 +00:00
|
|
|
|
2022-10-26 16:20:10 +00:00
|
|
|
for (size_t j = 0; j < peerCount[i]; ++j)
|
2013-01-04 19:45:39 +00:00
|
|
|
{
|
2021-10-18 20:22:31 +00:00
|
|
|
auto const* s = &peers.at(i)[j];
|
2022-03-21 14:15:48 +00:00
|
|
|
auto const key = make_key(tor, s);
|
2021-10-18 20:22:31 +00:00
|
|
|
refreshPeerRow(store->get_iter(hash.at(key).get_path()), s);
|
2009-04-24 01:37:04 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
/* step 5: remove peers that have disappeared */
|
2021-10-18 20:22:31 +00:00
|
|
|
if (auto iter = store->children().begin(); iter)
|
2013-01-04 19:45:39 +00:00
|
|
|
{
|
2021-10-18 20:22:31 +00:00
|
|
|
while (iter)
|
2013-01-04 19:45:39 +00:00
|
|
|
{
|
2021-10-18 20:22:31 +00:00
|
|
|
if (iter->get_value(peer_cols.was_updated))
|
2013-01-04 19:45:39 +00:00
|
|
|
{
|
2021-10-18 20:22:31 +00:00
|
|
|
++iter;
|
2013-01-04 19:45:39 +00:00
|
|
|
}
|
2017-04-19 12:04:45 +00:00
|
|
|
else
|
2013-01-04 19:45:39 +00:00
|
|
|
{
|
2021-10-18 20:22:31 +00:00
|
|
|
auto const key = iter->get_value(peer_cols.key);
|
|
|
|
hash.erase(key);
|
|
|
|
iter = store->erase(iter);
|
2009-04-24 01:37:04 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
/* step 6: cleanup */
|
2021-10-18 20:22:31 +00:00
|
|
|
for (size_t i = 0; i < peers.size(); ++i)
|
2017-04-19 12:04:45 +00:00
|
|
|
{
|
|
|
|
tr_torrentPeersFree(peers[i], peerCount[i]);
|
|
|
|
}
|
2007-06-06 00:30:13 +00:00
|
|
|
}
|
|
|
|
|
2021-10-18 20:22:31 +00:00
|
|
|
void DetailsDialog::Impl::refreshWebseedList(std::vector<tr_torrent*> const& torrents)
|
2009-02-13 18:23:56 +00:00
|
|
|
{
|
2021-12-07 18:11:28 +00:00
|
|
|
auto has_any_webseeds = bool{ false };
|
2021-10-18 20:22:31 +00:00
|
|
|
auto& hash = webseed_hash_;
|
2022-04-02 22:42:51 +00:00
|
|
|
auto const& store = webseed_store_;
|
2013-01-04 19:45:39 +00:00
|
|
|
|
2022-03-21 14:15:48 +00:00
|
|
|
auto make_key = [](tr_torrent const* tor, char const* url)
|
|
|
|
{
|
2024-01-06 20:05:18 +00:00
|
|
|
return fmt::format("{:d}.{:s}", tr_torrentId(tor), url);
|
2022-03-21 14:15:48 +00:00
|
|
|
};
|
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
/* step 1: mark all webseeds as not-updated */
|
2022-10-08 22:50:03 +00:00
|
|
|
for (auto& row : store->children())
|
2017-04-19 12:04:45 +00:00
|
|
|
{
|
2021-10-18 20:22:31 +00:00
|
|
|
row[webseed_cols.was_updated] = false;
|
2017-04-19 12:04:45 +00:00
|
|
|
}
|
2013-01-04 19:45:39 +00:00
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
/* step 2: add any new webseeds */
|
2021-10-18 20:22:31 +00:00
|
|
|
for (auto const* const tor : torrents)
|
2013-01-04 19:45:39 +00:00
|
|
|
{
|
2021-12-07 18:11:28 +00:00
|
|
|
for (size_t j = 0, n = tr_torrentWebseedCount(tor); j < n; ++j)
|
2013-01-04 19:45:39 +00:00
|
|
|
{
|
2021-12-07 18:11:28 +00:00
|
|
|
has_any_webseeds = true;
|
|
|
|
|
|
|
|
auto const* const url = tr_torrentWebseed(tor, j).url;
|
2022-03-21 14:15:48 +00:00
|
|
|
auto const key = make_key(tor, url);
|
2017-04-19 12:04:45 +00:00
|
|
|
|
2021-10-18 20:22:31 +00:00
|
|
|
if (hash.find(key) == hash.end())
|
2013-01-04 19:45:39 +00:00
|
|
|
{
|
2021-10-18 20:22:31 +00:00
|
|
|
auto const iter = store->append();
|
|
|
|
(*iter)[webseed_cols.url] = url;
|
|
|
|
(*iter)[webseed_cols.key] = key;
|
2022-01-17 18:39:50 +00:00
|
|
|
hash.try_emplace(key, Gtk::TreeRowReference(store, store->get_path(iter)));
|
2009-04-24 01:37:04 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
/* step 3: update the webseeds */
|
2021-10-18 20:22:31 +00:00
|
|
|
for (auto const* const tor : torrents)
|
2013-01-04 19:45:39 +00:00
|
|
|
{
|
2021-12-07 18:11:28 +00:00
|
|
|
for (size_t j = 0, n = tr_torrentWebseedCount(tor); j < n; ++j)
|
2013-01-04 19:45:39 +00:00
|
|
|
{
|
2021-12-07 18:11:28 +00:00
|
|
|
auto const webseed = tr_torrentWebseed(tor, j);
|
2022-03-21 14:15:48 +00:00
|
|
|
auto const key = make_key(tor, webseed.url);
|
2021-10-18 20:22:31 +00:00
|
|
|
auto const iter = store->get_iter(hash.at(key).get_path());
|
2017-04-19 12:04:45 +00:00
|
|
|
|
2023-11-16 04:15:40 +00:00
|
|
|
auto const speed = Speed{ webseed.download_bytes_per_second, Speed::Units::Byps };
|
|
|
|
auto const speed_string = webseed.is_downloading ? speed.to_string() : std::string{};
|
2013-01-04 19:45:39 +00:00
|
|
|
|
2023-11-16 04:15:40 +00:00
|
|
|
(*iter)[webseed_cols.download_rate_speed] = speed;
|
|
|
|
(*iter)[webseed_cols.download_rate_string] = speed_string;
|
2021-10-18 20:22:31 +00:00
|
|
|
(*iter)[webseed_cols.was_updated] = true;
|
2009-04-24 01:37:04 +00:00
|
|
|
}
|
2013-01-04 19:45:39 +00:00
|
|
|
}
|
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
/* step 4: remove webseeds that have disappeared */
|
2021-10-18 20:22:31 +00:00
|
|
|
if (auto iter = store->children().begin(); iter)
|
2013-01-04 19:45:39 +00:00
|
|
|
{
|
2021-10-18 20:22:31 +00:00
|
|
|
while (iter)
|
2013-01-04 19:45:39 +00:00
|
|
|
{
|
2021-10-18 20:22:31 +00:00
|
|
|
if (iter->get_value(webseed_cols.was_updated))
|
2013-01-04 19:45:39 +00:00
|
|
|
{
|
2021-10-18 20:22:31 +00:00
|
|
|
++iter;
|
2013-01-04 19:45:39 +00:00
|
|
|
}
|
2017-04-19 12:04:45 +00:00
|
|
|
else
|
2013-01-04 19:45:39 +00:00
|
|
|
{
|
2021-10-18 20:22:31 +00:00
|
|
|
auto const key = iter->get_value(webseed_cols.key);
|
|
|
|
hash.erase(key);
|
|
|
|
iter = store->erase(iter);
|
2009-04-24 01:37:04 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
/* most of the time there are no webseeds...
|
|
|
|
don't waste space showing an empty list */
|
2021-12-07 18:11:28 +00:00
|
|
|
webseed_view_->set_visible(has_any_webseeds);
|
2009-02-13 18:23:56 +00:00
|
|
|
}
|
|
|
|
|
2021-10-18 20:22:31 +00:00
|
|
|
void DetailsDialog::Impl::refreshPeers(std::vector<tr_torrent*> const& torrents)
|
2009-04-24 01:37:04 +00:00
|
|
|
{
|
2021-10-18 20:22:31 +00:00
|
|
|
refreshPeerList(torrents);
|
|
|
|
refreshWebseedList(torrents);
|
2009-04-24 01:37:04 +00:00
|
|
|
}
|
|
|
|
|
2021-10-18 20:22:31 +00:00
|
|
|
bool DetailsDialog::Impl::onPeerViewQueryTooltip(int x, int y, bool keyboard_tip, Glib::RefPtr<Gtk::Tooltip> const& tooltip)
|
2017-04-19 12:04:45 +00:00
|
|
|
{
|
2021-10-18 20:22:31 +00:00
|
|
|
Gtk::TreeModel::iterator iter;
|
|
|
|
bool show_tip = false;
|
2017-04-19 12:04:45 +00:00
|
|
|
|
2021-10-18 20:22:31 +00:00
|
|
|
if (peer_view_->get_tooltip_context_iter(x, y, keyboard_tip, iter))
|
2017-04-19 12:04:45 +00:00
|
|
|
{
|
2021-10-18 20:22:31 +00:00
|
|
|
auto const name = iter->get_value(peer_cols.torrent_name);
|
|
|
|
auto const addr = iter->get_value(peer_cols.address);
|
|
|
|
auto const flagstr = iter->get_value(peer_cols.flags);
|
2017-04-19 12:04:45 +00:00
|
|
|
|
2021-10-18 20:22:31 +00:00
|
|
|
std::ostringstream gstr;
|
|
|
|
gstr << "<b>" << Glib::Markup::escape_text(name) << "</b>\n" << addr << "\n \n";
|
2017-04-19 12:04:45 +00:00
|
|
|
|
2022-01-16 14:48:01 +00:00
|
|
|
for (char const ch : flagstr)
|
2017-04-19 12:04:45 +00:00
|
|
|
{
|
2021-10-06 16:32:17 +00:00
|
|
|
char const* s = nullptr;
|
2017-04-19 12:04:45 +00:00
|
|
|
|
2021-10-18 20:22:31 +00:00
|
|
|
switch (ch)
|
2009-04-24 12:05:53 +00:00
|
|
|
{
|
2017-04-19 12:04:45 +00:00
|
|
|
case 'O':
|
|
|
|
s = _("Optimistic unchoke");
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 'D':
|
|
|
|
s = _("Downloading from this peer");
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 'd':
|
|
|
|
s = _("We would download from this peer if they would let us");
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 'U':
|
|
|
|
s = _("Uploading to peer");
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 'u':
|
|
|
|
s = _("We would upload to this peer if they asked");
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 'K':
|
|
|
|
s = _("Peer has unchoked us, but we're not interested");
|
|
|
|
break;
|
|
|
|
|
|
|
|
case '?':
|
|
|
|
s = _("We unchoked this peer, but they're not interested");
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 'E':
|
|
|
|
s = _("Encrypted connection");
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 'X':
|
|
|
|
s = _("Peer was found through Peer Exchange (PEX)");
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 'H':
|
|
|
|
s = _("Peer was found through DHT");
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 'I':
|
|
|
|
s = _("Peer is an incoming connection");
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 'T':
|
|
|
|
s = _("Peer is connected over µTP");
|
|
|
|
break;
|
2021-12-14 08:43:27 +00:00
|
|
|
|
|
|
|
default:
|
|
|
|
g_assert_not_reached();
|
2009-04-24 12:05:53 +00:00
|
|
|
}
|
2013-01-04 19:45:39 +00:00
|
|
|
|
2021-10-06 16:32:17 +00:00
|
|
|
if (s != nullptr)
|
2017-04-19 12:04:45 +00:00
|
|
|
{
|
2021-10-18 20:22:31 +00:00
|
|
|
gstr << ch << ": " << s << '\n';
|
2017-04-19 12:04:45 +00:00
|
|
|
}
|
2009-04-24 12:05:53 +00:00
|
|
|
}
|
2011-05-28 00:12:59 +00:00
|
|
|
|
2021-10-18 20:22:31 +00:00
|
|
|
auto str = gstr.str();
|
|
|
|
if (!str.empty()) /* remove the last linefeed */
|
2017-04-19 12:04:45 +00:00
|
|
|
{
|
2021-10-18 20:22:31 +00:00
|
|
|
str.resize(str.size() - 1);
|
2017-04-19 12:04:45 +00:00
|
|
|
}
|
2013-01-04 19:45:39 +00:00
|
|
|
|
2021-10-18 20:22:31 +00:00
|
|
|
tooltip->set_markup(str);
|
2011-05-28 00:12:59 +00:00
|
|
|
|
2021-10-18 20:22:31 +00:00
|
|
|
show_tip = true;
|
2009-04-24 12:05:53 +00:00
|
|
|
}
|
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
return show_tip;
|
2009-04-24 12:05:53 +00:00
|
|
|
}
|
|
|
|
|
2021-10-18 20:22:31 +00:00
|
|
|
namespace
|
|
|
|
{
|
|
|
|
|
|
|
|
void setPeerViewColumns(Gtk::TreeView* peer_view)
|
2017-04-19 12:04:45 +00:00
|
|
|
{
|
2021-10-18 20:22:31 +00:00
|
|
|
std::vector<Gtk::TreeModelColumnBase const*> view_columns;
|
2022-11-13 17:36:16 +00:00
|
|
|
Gtk::TreeViewColumn* c = nullptr;
|
2017-04-20 16:02:19 +00:00
|
|
|
bool const more = gtr_pref_flag_get(TR_KEY_show_extra_peer_details);
|
2017-04-19 12:04:45 +00:00
|
|
|
|
2021-10-18 20:22:31 +00:00
|
|
|
view_columns.push_back(&peer_cols.encryption_stock_id);
|
|
|
|
view_columns.push_back(&peer_cols.upload_rate_string);
|
2017-04-19 12:04:45 +00:00
|
|
|
|
|
|
|
if (more)
|
|
|
|
{
|
2021-10-18 20:22:31 +00:00
|
|
|
view_columns.push_back(&peer_cols.upload_request_count_string);
|
2017-04-19 12:04:45 +00:00
|
|
|
}
|
|
|
|
|
2021-10-18 20:22:31 +00:00
|
|
|
view_columns.push_back(&peer_cols.download_rate_string);
|
2017-04-19 12:04:45 +00:00
|
|
|
|
|
|
|
if (more)
|
|
|
|
{
|
2021-10-18 20:22:31 +00:00
|
|
|
view_columns.push_back(&peer_cols.download_request_count_string);
|
|
|
|
view_columns.push_back(&peer_cols.blocks_downloaded_count_string);
|
|
|
|
view_columns.push_back(&peer_cols.blocks_uploaded_count_string);
|
|
|
|
view_columns.push_back(&peer_cols.reqs_cancelled_by_client_count_string);
|
|
|
|
view_columns.push_back(&peer_cols.reqs_cancelled_by_peer_count_string);
|
2017-04-19 12:04:45 +00:00
|
|
|
}
|
|
|
|
|
2021-10-18 20:22:31 +00:00
|
|
|
view_columns.push_back(&peer_cols.progress);
|
|
|
|
view_columns.push_back(&peer_cols.flags);
|
|
|
|
view_columns.push_back(&peer_cols.address);
|
|
|
|
view_columns.push_back(&peer_cols.client);
|
2017-04-19 12:04:45 +00:00
|
|
|
|
|
|
|
/* remove any existing columns */
|
2021-10-18 20:22:31 +00:00
|
|
|
peer_view->remove_all_columns();
|
|
|
|
|
|
|
|
for (auto const* const col : view_columns)
|
|
|
|
{
|
|
|
|
auto const* sort_col = col;
|
|
|
|
|
|
|
|
if (*col == peer_cols.address)
|
|
|
|
{
|
|
|
|
auto* r = Gtk::make_managed<Gtk::CellRendererText>();
|
|
|
|
c = Gtk::make_managed<Gtk::TreeViewColumn>(_("Address"), *r);
|
|
|
|
c->add_attribute(r->property_text(), *col);
|
|
|
|
sort_col = &peer_cols.address_collated;
|
|
|
|
}
|
|
|
|
else if (*col == peer_cols.progress)
|
|
|
|
{
|
|
|
|
auto* r = Gtk::make_managed<Gtk::CellRendererProgress>();
|
2022-03-21 14:15:48 +00:00
|
|
|
// % is percent done
|
2021-10-18 20:22:31 +00:00
|
|
|
c = Gtk::make_managed<Gtk::TreeViewColumn>(_("%"), *r);
|
|
|
|
c->add_attribute(r->property_text(), *col);
|
|
|
|
}
|
|
|
|
else if (*col == peer_cols.encryption_stock_id)
|
|
|
|
{
|
|
|
|
auto* r = Gtk::make_managed<Gtk::CellRendererPixbuf>();
|
|
|
|
r->property_xalign() = 0.0F;
|
|
|
|
r->property_yalign() = 0.5F;
|
|
|
|
c = Gtk::make_managed<Gtk::TreeViewColumn>(Glib::ustring(), *r);
|
2021-11-12 09:12:50 +00:00
|
|
|
c->add_attribute(r->property_icon_name(), *col);
|
2022-09-10 13:19:54 +00:00
|
|
|
c->set_sizing(TR_GTK_TREE_VIEW_COLUMN_SIZING(FIXED));
|
2021-10-18 20:22:31 +00:00
|
|
|
c->set_fixed_width(20);
|
|
|
|
}
|
|
|
|
else if (*col == peer_cols.download_request_count_string)
|
|
|
|
{
|
|
|
|
auto* r = Gtk::make_managed<Gtk::CellRendererText>();
|
|
|
|
c = Gtk::make_managed<Gtk::TreeViewColumn>(_("Dn Reqs"), *r);
|
|
|
|
c->add_attribute(r->property_text(), *col);
|
2022-11-23 19:47:04 +00:00
|
|
|
sort_col = &peer_cols.download_request_count_number;
|
2021-10-18 20:22:31 +00:00
|
|
|
}
|
|
|
|
else if (*col == peer_cols.upload_request_count_string)
|
|
|
|
{
|
|
|
|
auto* r = Gtk::make_managed<Gtk::CellRendererText>();
|
|
|
|
c = Gtk::make_managed<Gtk::TreeViewColumn>(_("Up Reqs"), *r);
|
|
|
|
c->add_attribute(r->property_text(), *col);
|
2022-11-23 19:47:04 +00:00
|
|
|
sort_col = &peer_cols.upload_request_count_number;
|
2021-10-18 20:22:31 +00:00
|
|
|
}
|
|
|
|
else if (*col == peer_cols.blocks_downloaded_count_string)
|
|
|
|
{
|
|
|
|
auto* r = Gtk::make_managed<Gtk::CellRendererText>();
|
|
|
|
c = Gtk::make_managed<Gtk::TreeViewColumn>(_("Dn Blocks"), *r);
|
|
|
|
c->add_attribute(r->property_text(), *col);
|
2022-11-23 19:47:04 +00:00
|
|
|
sort_col = &peer_cols.blocks_downloaded_count_number;
|
2021-10-18 20:22:31 +00:00
|
|
|
}
|
|
|
|
else if (*col == peer_cols.blocks_uploaded_count_string)
|
|
|
|
{
|
|
|
|
auto* r = Gtk::make_managed<Gtk::CellRendererText>();
|
|
|
|
c = Gtk::make_managed<Gtk::TreeViewColumn>(_("Up Blocks"), *r);
|
|
|
|
c->add_attribute(r->property_text(), *col);
|
2022-11-23 19:47:04 +00:00
|
|
|
sort_col = &peer_cols.blocks_uploaded_count_number;
|
2021-10-18 20:22:31 +00:00
|
|
|
}
|
|
|
|
else if (*col == peer_cols.reqs_cancelled_by_client_count_string)
|
|
|
|
{
|
|
|
|
auto* r = Gtk::make_managed<Gtk::CellRendererText>();
|
|
|
|
c = Gtk::make_managed<Gtk::TreeViewColumn>(_("We Cancelled"), *r);
|
|
|
|
c->add_attribute(r->property_text(), *col);
|
2022-11-23 19:47:04 +00:00
|
|
|
sort_col = &peer_cols.reqs_cancelled_by_client_count_number;
|
2021-10-18 20:22:31 +00:00
|
|
|
}
|
|
|
|
else if (*col == peer_cols.reqs_cancelled_by_peer_count_string)
|
|
|
|
{
|
|
|
|
auto* r = Gtk::make_managed<Gtk::CellRendererText>();
|
|
|
|
c = Gtk::make_managed<Gtk::TreeViewColumn>(_("They Cancelled"), *r);
|
|
|
|
c->add_attribute(r->property_text(), *col);
|
2022-11-23 19:47:04 +00:00
|
|
|
sort_col = &peer_cols.reqs_cancelled_by_peer_count_number;
|
2021-10-18 20:22:31 +00:00
|
|
|
}
|
|
|
|
else if (*col == peer_cols.download_rate_string)
|
|
|
|
{
|
|
|
|
auto* r = Gtk::make_managed<Gtk::CellRendererText>();
|
|
|
|
r->property_xalign() = 1.0F;
|
|
|
|
c = Gtk::make_managed<Gtk::TreeViewColumn>(_("Down"), *r);
|
|
|
|
c->add_attribute(r->property_text(), *col);
|
2023-11-16 04:15:40 +00:00
|
|
|
sort_col = &peer_cols.download_rate_speed;
|
2021-10-18 20:22:31 +00:00
|
|
|
}
|
|
|
|
else if (*col == peer_cols.upload_rate_string)
|
|
|
|
{
|
|
|
|
auto* r = Gtk::make_managed<Gtk::CellRendererText>();
|
|
|
|
r->property_xalign() = 1.0F;
|
|
|
|
c = Gtk::make_managed<Gtk::TreeViewColumn>(_("Up"), *r);
|
|
|
|
c->add_attribute(r->property_text(), *col);
|
2023-11-16 04:15:40 +00:00
|
|
|
sort_col = &peer_cols.upload_rate_speed;
|
2021-10-18 20:22:31 +00:00
|
|
|
}
|
|
|
|
else if (*col == peer_cols.client)
|
|
|
|
{
|
|
|
|
auto* r = Gtk::make_managed<Gtk::CellRendererText>();
|
|
|
|
c = Gtk::make_managed<Gtk::TreeViewColumn>(_("Client"), *r);
|
|
|
|
c->add_attribute(r->property_text(), *col);
|
|
|
|
}
|
|
|
|
else if (*col == peer_cols.flags)
|
|
|
|
{
|
|
|
|
auto* r = Gtk::make_managed<Gtk::CellRendererText>();
|
|
|
|
c = Gtk::make_managed<Gtk::TreeViewColumn>(_("Flags"), *r);
|
|
|
|
c->add_attribute(r->property_text(), *col);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2022-11-10 19:35:31 +00:00
|
|
|
std::abort();
|
2009-12-16 18:20:01 +00:00
|
|
|
}
|
|
|
|
|
2021-10-18 20:22:31 +00:00
|
|
|
c->set_resizable(false);
|
|
|
|
c->set_sort_column(*sort_col);
|
|
|
|
peer_view->append_column(*c);
|
2009-12-16 18:20:01 +00:00
|
|
|
}
|
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
/* the 'expander' column has a 10-pixel margin on the left
|
|
|
|
that doesn't look quite correct in any of these columns...
|
|
|
|
so create a non-visible column and assign it as the
|
|
|
|
'expander column. */
|
2021-10-18 20:22:31 +00:00
|
|
|
c = Gtk::make_managed<Gtk::TreeViewColumn>();
|
|
|
|
c->set_visible(false);
|
|
|
|
peer_view->append_column(*c);
|
|
|
|
peer_view->set_expander_column(*c);
|
2009-12-16 18:20:01 +00:00
|
|
|
}
|
|
|
|
|
2021-10-18 20:22:31 +00:00
|
|
|
} // namespace
|
|
|
|
|
|
|
|
void DetailsDialog::Impl::onMorePeerInfoToggled()
|
2009-12-16 18:20:01 +00:00
|
|
|
{
|
2017-04-20 16:02:19 +00:00
|
|
|
tr_quark const key = TR_KEY_show_extra_peer_details;
|
2021-10-18 20:22:31 +00:00
|
|
|
bool const value = more_peer_details_check_->get_active();
|
|
|
|
core_->set_pref(key, value);
|
|
|
|
setPeerViewColumns(peer_view_);
|
2009-12-16 18:20:01 +00:00
|
|
|
}
|
|
|
|
|
2022-09-07 22:25:04 +00:00
|
|
|
void DetailsDialog::Impl::peer_page_init(Glib::RefPtr<Gtk::Builder> const& builder)
|
2017-04-19 12:04:45 +00:00
|
|
|
{
|
|
|
|
/* webseeds */
|
|
|
|
|
2021-10-18 20:22:31 +00:00
|
|
|
webseed_store_ = Gtk::ListStore::create(webseed_cols);
|
2022-09-07 22:25:04 +00:00
|
|
|
auto* v = gtr_get_widget<Gtk::TreeView>(builder, "webseeds_view");
|
|
|
|
v->set_model(webseed_store_);
|
2023-08-06 03:26:29 +00:00
|
|
|
setup_item_view_button_event_handling(
|
2022-10-08 22:50:03 +00:00
|
|
|
*v,
|
|
|
|
{},
|
2023-08-06 03:26:29 +00:00
|
|
|
[v](double view_x, double view_y) { return on_item_view_button_released(*v, view_x, view_y); });
|
2021-10-18 20:22:31 +00:00
|
|
|
|
|
|
|
{
|
|
|
|
auto* r = Gtk::make_managed<Gtk::CellRendererText>();
|
2022-09-10 13:19:54 +00:00
|
|
|
r->property_ellipsize() = TR_PANGO_ELLIPSIZE_MODE(END);
|
2021-10-18 20:22:31 +00:00
|
|
|
auto* c = Gtk::make_managed<Gtk::TreeViewColumn>(_("Web Seeds"), *r);
|
|
|
|
c->add_attribute(r->property_text(), webseed_cols.url);
|
|
|
|
c->set_expand(true);
|
|
|
|
c->set_sort_column(webseed_cols.url);
|
|
|
|
v->append_column(*c);
|
|
|
|
}
|
|
|
|
|
|
|
|
{
|
|
|
|
auto* r = Gtk::make_managed<Gtk::CellRendererText>();
|
|
|
|
auto* c = Gtk::make_managed<Gtk::TreeViewColumn>(_("Down"), *r);
|
|
|
|
c->add_attribute(r->property_text(), webseed_cols.download_rate_string);
|
2023-11-16 04:15:40 +00:00
|
|
|
c->set_sort_column(webseed_cols.download_rate_speed);
|
2021-10-18 20:22:31 +00:00
|
|
|
v->append_column(*c);
|
|
|
|
}
|
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
/* peers */
|
|
|
|
|
2021-10-18 20:22:31 +00:00
|
|
|
peer_store_ = Gtk::ListStore::create(peer_cols);
|
|
|
|
auto m = Gtk::TreeModelSort::create(peer_store_);
|
2022-09-10 13:19:54 +00:00
|
|
|
m->set_sort_column(peer_cols.progress, TR_GTK_SORT_TYPE(DESCENDING));
|
2021-10-18 20:22:31 +00:00
|
|
|
|
2022-09-07 22:25:04 +00:00
|
|
|
peer_view_->set_model(m);
|
|
|
|
peer_view_->set_has_tooltip(true);
|
2022-10-08 22:50:03 +00:00
|
|
|
peer_view_->signal_query_tooltip().connect(sigc::mem_fun(*this, &Impl::onPeerViewQueryTooltip), false);
|
2023-08-06 03:26:29 +00:00
|
|
|
setup_item_view_button_event_handling(
|
2022-10-08 22:50:03 +00:00
|
|
|
*peer_view_,
|
|
|
|
{},
|
2023-08-06 03:26:29 +00:00
|
|
|
[this](double view_x, double view_y) { return on_item_view_button_released(*peer_view_, view_x, view_y); });
|
2021-10-18 20:22:31 +00:00
|
|
|
|
|
|
|
setPeerViewColumns(peer_view_);
|
|
|
|
|
|
|
|
more_peer_details_check_->set_active(gtr_pref_flag_get(TR_KEY_show_extra_peer_details));
|
2021-11-12 09:12:50 +00:00
|
|
|
more_peer_details_check_->signal_toggled().connect(sigc::mem_fun(*this, &Impl::onMorePeerInfoToggled));
|
2009-04-19 17:00:28 +00:00
|
|
|
}
|
|
|
|
|
2009-04-24 01:37:04 +00:00
|
|
|
/****
|
2011-01-14 21:57:20 +00:00
|
|
|
*****
|
2009-04-24 01:37:04 +00:00
|
|
|
***** TRACKER
|
2011-01-14 21:57:20 +00:00
|
|
|
*****
|
2009-04-24 01:37:04 +00:00
|
|
|
****/
|
|
|
|
|
2021-10-18 20:22:31 +00:00
|
|
|
namespace
|
|
|
|
{
|
|
|
|
|
2022-11-10 19:35:31 +00:00
|
|
|
auto constexpr ErrMarkupBegin = "<span color='red'>"sv;
|
2022-03-21 14:15:48 +00:00
|
|
|
auto constexpr ErrMarkupEnd = "</span>"sv;
|
2022-11-10 19:35:31 +00:00
|
|
|
auto constexpr TimeoutMarkupBegin = "<span color='#246'>"sv;
|
2022-03-21 14:15:48 +00:00
|
|
|
auto constexpr TimeoutMarkupEnd = "</span>"sv;
|
2022-11-10 19:35:31 +00:00
|
|
|
auto constexpr SuccessMarkupBegin = "<span color='#080'>"sv;
|
2022-03-21 14:15:48 +00:00
|
|
|
auto constexpr SuccessMarkupEnd = "</span>"sv;
|
2020-11-08 19:54:40 +00:00
|
|
|
|
2021-11-15 18:53:32 +00:00
|
|
|
std::array<std::string_view, 3> const text_dir_mark = { ""sv, "\u200E"sv, "\u200F"sv };
|
|
|
|
|
2021-12-08 16:55:52 +00:00
|
|
|
void appendAnnounceInfo(tr_tracker_view const& tracker, time_t const now, Gtk::TextDirection direction, std::ostream& gstr)
|
2017-04-19 12:04:45 +00:00
|
|
|
{
|
2022-11-13 17:36:16 +00:00
|
|
|
auto const dir_mark = text_dir_mark.at(static_cast<int>(direction));
|
2022-10-08 22:50:03 +00:00
|
|
|
|
2021-12-08 16:55:52 +00:00
|
|
|
if (tracker.hasAnnounced && tracker.announceState != TR_TRACKER_INACTIVE)
|
2017-04-19 12:04:45 +00:00
|
|
|
{
|
2021-10-18 20:22:31 +00:00
|
|
|
gstr << '\n';
|
2022-10-08 22:50:03 +00:00
|
|
|
gstr << dir_mark;
|
2022-06-15 02:56:27 +00:00
|
|
|
auto const time_span_ago = tr_format_time_relative(now, tracker.lastAnnounceTime);
|
2017-04-19 12:04:45 +00:00
|
|
|
|
2021-12-08 16:55:52 +00:00
|
|
|
if (tracker.lastAnnounceSucceeded)
|
2020-11-08 19:54:40 +00:00
|
|
|
{
|
2022-03-21 14:15:48 +00:00
|
|
|
gstr << fmt::format(
|
|
|
|
// {markup_begin} and {markup_end} should surround the peer text
|
|
|
|
ngettext(
|
2022-06-15 02:56:27 +00:00
|
|
|
"Got a list of {markup_begin}{peer_count} peer{markup_end} {time_span_ago}",
|
|
|
|
"Got a list of {markup_begin}{peer_count} peers{markup_end} {time_span_ago}",
|
2022-03-21 14:15:48 +00:00
|
|
|
tracker.lastAnnouncePeerCount),
|
|
|
|
fmt::arg("markup_begin", SuccessMarkupBegin),
|
|
|
|
fmt::arg("peer_count", tracker.lastAnnouncePeerCount),
|
|
|
|
fmt::arg("markup_end", SuccessMarkupEnd),
|
2022-06-15 02:56:27 +00:00
|
|
|
fmt::arg("time_span_ago", time_span_ago));
|
2020-11-08 19:54:40 +00:00
|
|
|
}
|
2021-12-08 16:55:52 +00:00
|
|
|
else if (tracker.lastAnnounceTimedOut)
|
2017-04-19 12:04:45 +00:00
|
|
|
{
|
2022-03-21 14:15:48 +00:00
|
|
|
gstr << fmt::format(
|
|
|
|
// {markup_begin} and {markup_end} should surround the time_span
|
2022-06-15 02:56:27 +00:00
|
|
|
_("Peer list request {markup_begin}timed out {time_span_ago}{markup_end}; will retry"),
|
2022-03-21 14:15:48 +00:00
|
|
|
fmt::arg("markup_begin", TimeoutMarkupBegin),
|
2022-06-15 02:56:27 +00:00
|
|
|
fmt::arg("time_span_ago", time_span_ago),
|
2022-03-21 14:15:48 +00:00
|
|
|
fmt::arg("markup_end", TimeoutMarkupEnd));
|
2017-04-19 12:04:45 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2022-03-21 14:15:48 +00:00
|
|
|
gstr << fmt::format(
|
|
|
|
// {markup_begin} and {markup_end} should surround the error
|
2022-06-15 02:56:27 +00:00
|
|
|
_("Got an error '{markup_begin}{error}{markup_end}' {time_span_ago}"),
|
2022-03-21 14:15:48 +00:00
|
|
|
fmt::arg("markup_begin", ErrMarkupBegin),
|
2022-11-13 17:36:16 +00:00
|
|
|
fmt::arg("error", Glib::Markup::escape_text(std::data(tracker.lastAnnounceResult))),
|
2022-03-21 14:15:48 +00:00
|
|
|
fmt::arg("markup_end", ErrMarkupEnd),
|
2022-06-15 02:56:27 +00:00
|
|
|
fmt::arg("time_span_ago", time_span_ago));
|
2017-04-19 12:04:45 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-12-08 16:55:52 +00:00
|
|
|
switch (tracker.announceState)
|
2017-04-19 12:04:45 +00:00
|
|
|
{
|
2020-11-08 19:54:40 +00:00
|
|
|
case TR_TRACKER_INACTIVE:
|
2021-10-18 20:22:31 +00:00
|
|
|
gstr << '\n';
|
2022-10-08 22:50:03 +00:00
|
|
|
gstr << dir_mark;
|
2021-10-18 20:22:31 +00:00
|
|
|
gstr << _("No updates scheduled");
|
2020-11-08 19:54:40 +00:00
|
|
|
break;
|
2017-04-19 12:04:45 +00:00
|
|
|
|
2020-11-08 19:54:40 +00:00
|
|
|
case TR_TRACKER_WAITING:
|
2021-10-18 20:22:31 +00:00
|
|
|
gstr << '\n';
|
2022-10-08 22:50:03 +00:00
|
|
|
gstr << dir_mark;
|
2022-03-21 14:15:48 +00:00
|
|
|
gstr << fmt::format(
|
2022-06-15 02:56:27 +00:00
|
|
|
_("Asking for more peers {time_span_from_now}"),
|
|
|
|
fmt::arg("time_span_from_now", tr_format_time_relative(now, tracker.nextAnnounceTime)));
|
2020-11-08 19:54:40 +00:00
|
|
|
break;
|
2017-04-19 12:04:45 +00:00
|
|
|
|
2020-11-08 19:54:40 +00:00
|
|
|
case TR_TRACKER_QUEUED:
|
2021-10-18 20:22:31 +00:00
|
|
|
gstr << '\n';
|
2022-10-08 22:50:03 +00:00
|
|
|
gstr << dir_mark;
|
2021-10-18 20:22:31 +00:00
|
|
|
gstr << _("Queued to ask for more peers");
|
2020-11-08 19:54:40 +00:00
|
|
|
break;
|
2013-01-04 19:45:39 +00:00
|
|
|
|
2020-11-08 19:54:40 +00:00
|
|
|
case TR_TRACKER_ACTIVE:
|
2021-10-18 20:22:31 +00:00
|
|
|
gstr << '\n';
|
2022-10-08 22:50:03 +00:00
|
|
|
gstr << dir_mark;
|
2022-03-21 14:15:48 +00:00
|
|
|
gstr << fmt::format(
|
2022-06-15 02:56:27 +00:00
|
|
|
// {markup_begin} and {markup_end} should surround time_span_ago
|
|
|
|
_("Asked for more peers {markup_begin}{time_span_ago}{markup_end}"),
|
2022-03-21 14:15:48 +00:00
|
|
|
fmt::arg("markup_begin", "<small>"),
|
2022-06-15 02:56:27 +00:00
|
|
|
fmt::arg("time_span_ago", tr_format_time_relative(now, tracker.lastAnnounceStartTime)),
|
2022-03-21 14:15:48 +00:00
|
|
|
fmt::arg("markup_end", "</small>"));
|
2020-11-08 19:54:40 +00:00
|
|
|
break;
|
2021-12-14 08:43:27 +00:00
|
|
|
|
|
|
|
default:
|
|
|
|
g_assert_not_reached();
|
2020-11-08 19:54:40 +00:00
|
|
|
}
|
|
|
|
}
|
2013-01-04 19:45:39 +00:00
|
|
|
|
2021-12-08 16:55:52 +00:00
|
|
|
void appendScrapeInfo(tr_tracker_view const& tracker, time_t const now, Gtk::TextDirection direction, std::ostream& gstr)
|
2020-11-08 19:54:40 +00:00
|
|
|
{
|
2022-11-13 17:36:16 +00:00
|
|
|
auto const dir_mark = text_dir_mark.at(static_cast<int>(direction));
|
2022-10-08 22:50:03 +00:00
|
|
|
|
2021-12-08 16:55:52 +00:00
|
|
|
if (tracker.hasScraped)
|
2020-11-08 19:54:40 +00:00
|
|
|
{
|
2021-10-18 20:22:31 +00:00
|
|
|
gstr << '\n';
|
2022-10-08 22:50:03 +00:00
|
|
|
gstr << dir_mark;
|
2022-06-15 02:56:27 +00:00
|
|
|
auto const time_span_ago = tr_format_time_relative(now, tracker.lastScrapeTime);
|
2009-10-10 00:17:00 +00:00
|
|
|
|
2021-12-08 16:55:52 +00:00
|
|
|
if (tracker.lastScrapeSucceeded)
|
2009-10-10 00:17:00 +00:00
|
|
|
{
|
2022-03-21 14:15:48 +00:00
|
|
|
gstr << fmt::format(
|
|
|
|
// {markup_begin} and {markup_end} should surround the seeder/leecher text
|
2022-06-15 02:56:27 +00:00
|
|
|
_("Tracker had {markup_begin}{seeder_count} {seeder_or_seeders} and {leecher_count} {leecher_or_leechers}{markup_end} {time_span_ago}"),
|
2022-03-21 14:15:48 +00:00
|
|
|
fmt::arg("seeder_count", tracker.seederCount),
|
|
|
|
fmt::arg("seeder_or_seeders", ngettext("seeder", "seeders", tracker.seederCount)),
|
|
|
|
fmt::arg("leecher_count", tracker.leecherCount),
|
|
|
|
fmt::arg("leecher_or_leechers", ngettext("leecher", "leechers", tracker.leecherCount)),
|
2022-06-15 02:56:27 +00:00
|
|
|
fmt::arg("time_span_ago", time_span_ago),
|
2022-03-21 14:15:48 +00:00
|
|
|
fmt::arg("markup_begin", SuccessMarkupBegin),
|
|
|
|
fmt::arg("markup_end", SuccessMarkupEnd));
|
2020-11-08 19:54:40 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2022-03-21 14:15:48 +00:00
|
|
|
gstr << fmt::format(
|
|
|
|
// {markup_begin} and {markup_end} should surround the error text
|
2022-06-15 02:56:27 +00:00
|
|
|
_("Got a scrape error '{markup_begin}{error}{markup_end}' {time_span_ago}"),
|
2022-11-13 17:36:16 +00:00
|
|
|
fmt::arg("error", Glib::Markup::escape_text(std::data(tracker.lastScrapeResult))),
|
2022-06-15 02:56:27 +00:00
|
|
|
fmt::arg("time_span_ago", time_span_ago),
|
2022-03-21 14:15:48 +00:00
|
|
|
fmt::arg("markup_begin", ErrMarkupBegin),
|
|
|
|
fmt::arg("markup_end", ErrMarkupEnd));
|
2020-11-08 19:54:40 +00:00
|
|
|
}
|
|
|
|
}
|
2017-04-19 12:04:45 +00:00
|
|
|
|
2021-12-08 16:55:52 +00:00
|
|
|
switch (tracker.scrapeState)
|
2020-11-08 19:54:40 +00:00
|
|
|
{
|
|
|
|
case TR_TRACKER_INACTIVE:
|
|
|
|
break;
|
2009-10-10 00:17:00 +00:00
|
|
|
|
2020-11-08 19:54:40 +00:00
|
|
|
case TR_TRACKER_WAITING:
|
2021-10-18 20:22:31 +00:00
|
|
|
gstr << '\n';
|
2022-10-08 22:50:03 +00:00
|
|
|
gstr << dir_mark;
|
2022-03-21 14:15:48 +00:00
|
|
|
gstr << fmt::format(
|
2022-06-15 02:56:27 +00:00
|
|
|
_("Asking for peer counts in {time_span_from_now}"),
|
|
|
|
fmt::arg("time_span_from_now", tr_format_time_relative(now, tracker.nextScrapeTime)));
|
2020-11-08 19:54:40 +00:00
|
|
|
break;
|
2013-01-04 19:45:39 +00:00
|
|
|
|
2020-11-08 19:54:40 +00:00
|
|
|
case TR_TRACKER_QUEUED:
|
2021-10-18 20:22:31 +00:00
|
|
|
gstr << '\n';
|
2022-10-08 22:50:03 +00:00
|
|
|
gstr << dir_mark;
|
2021-10-18 20:22:31 +00:00
|
|
|
gstr << _("Queued to ask for peer counts");
|
2020-11-08 19:54:40 +00:00
|
|
|
break;
|
2013-01-04 19:45:39 +00:00
|
|
|
|
2020-11-08 19:54:40 +00:00
|
|
|
case TR_TRACKER_ACTIVE:
|
2021-10-18 20:22:31 +00:00
|
|
|
gstr << '\n';
|
2022-10-08 22:50:03 +00:00
|
|
|
gstr << dir_mark;
|
2022-03-21 14:15:48 +00:00
|
|
|
gstr << fmt::format(
|
2022-06-15 02:56:27 +00:00
|
|
|
_("Asked for peer counts {markup_begin}{time_span_ago}{markup_end}"),
|
2022-03-21 14:15:48 +00:00
|
|
|
fmt::arg("markup_begin", "<small>"),
|
2022-06-15 02:56:27 +00:00
|
|
|
fmt::arg("time_span_ago", tr_format_time_relative(now, tracker.lastScrapeStartTime)),
|
2022-03-21 14:15:48 +00:00
|
|
|
fmt::arg("markup_end", "</small>"));
|
2020-11-08 19:54:40 +00:00
|
|
|
break;
|
2021-12-14 08:43:27 +00:00
|
|
|
|
|
|
|
default:
|
|
|
|
g_assert_not_reached();
|
2020-11-08 19:54:40 +00:00
|
|
|
}
|
|
|
|
}
|
2013-01-04 19:45:39 +00:00
|
|
|
|
2021-11-15 18:53:32 +00:00
|
|
|
void buildTrackerSummary(
|
|
|
|
std::ostream& gstr,
|
|
|
|
std::string const& key,
|
2021-12-08 16:55:52 +00:00
|
|
|
tr_tracker_view const& tracker,
|
2021-11-15 18:53:32 +00:00
|
|
|
bool showScrape,
|
|
|
|
Gtk::TextDirection direction)
|
2020-11-08 19:54:40 +00:00
|
|
|
{
|
|
|
|
// hostname
|
2022-11-13 17:36:16 +00:00
|
|
|
gstr << text_dir_mark.at(static_cast<int>(direction));
|
2021-12-08 16:55:52 +00:00
|
|
|
gstr << (tracker.isBackup ? "<i>" : "<b>");
|
2023-05-09 01:28:10 +00:00
|
|
|
gstr << Glib::Markup::escape_text(
|
2024-01-06 20:05:18 +00:00
|
|
|
!key.empty() ? fmt::format("{:s} - {:s}", tracker.host_and_port, key) : tracker.host_and_port);
|
2021-12-08 16:55:52 +00:00
|
|
|
gstr << (tracker.isBackup ? "</i>" : "</b>");
|
2020-11-08 19:54:40 +00:00
|
|
|
|
2021-12-08 16:55:52 +00:00
|
|
|
if (!tracker.isBackup)
|
2020-11-08 19:54:40 +00:00
|
|
|
{
|
2021-10-06 16:32:17 +00:00
|
|
|
time_t const now = time(nullptr);
|
2020-11-08 19:54:40 +00:00
|
|
|
|
2021-12-08 16:55:52 +00:00
|
|
|
appendAnnounceInfo(tracker, now, direction, gstr);
|
2020-11-08 19:54:40 +00:00
|
|
|
|
|
|
|
if (showScrape)
|
|
|
|
{
|
2021-12-08 16:55:52 +00:00
|
|
|
appendScrapeInfo(tracker, now, direction, gstr);
|
2009-10-10 00:17:00 +00:00
|
|
|
}
|
2009-04-24 01:37:04 +00:00
|
|
|
}
|
2009-09-25 21:05:59 +00:00
|
|
|
}
|
2007-12-22 00:06:38 +00:00
|
|
|
|
2021-10-18 20:22:31 +00:00
|
|
|
class TrackerModelColumns : public Gtk::TreeModelColumnRecord
|
2009-09-25 21:05:59 +00:00
|
|
|
{
|
2021-10-18 20:22:31 +00:00
|
|
|
public:
|
2022-11-15 00:53:12 +00:00
|
|
|
TrackerModelColumns() noexcept
|
2021-10-18 20:22:31 +00:00
|
|
|
{
|
|
|
|
add(torrent_id);
|
|
|
|
add(text);
|
|
|
|
add(is_backup);
|
|
|
|
add(tracker_id);
|
|
|
|
add(favicon);
|
|
|
|
add(was_updated);
|
|
|
|
add(key);
|
|
|
|
}
|
|
|
|
|
2022-06-17 15:43:04 +00:00
|
|
|
Gtk::TreeModelColumn<tr_torrent_id_t> torrent_id;
|
2021-10-18 20:22:31 +00:00
|
|
|
Gtk::TreeModelColumn<Glib::ustring> text;
|
|
|
|
Gtk::TreeModelColumn<bool> is_backup;
|
|
|
|
Gtk::TreeModelColumn<int> tracker_id;
|
|
|
|
Gtk::TreeModelColumn<Glib::RefPtr<Gdk::Pixbuf>> favicon;
|
|
|
|
Gtk::TreeModelColumn<bool> was_updated;
|
|
|
|
Gtk::TreeModelColumn<std::string> key;
|
2009-09-25 21:05:59 +00:00
|
|
|
};
|
2007-06-06 00:30:13 +00:00
|
|
|
|
2021-10-18 20:22:31 +00:00
|
|
|
TrackerModelColumns const tracker_cols;
|
2008-02-21 07:29:39 +00:00
|
|
|
|
2021-10-18 20:22:31 +00:00
|
|
|
} // namespace
|
|
|
|
|
|
|
|
bool DetailsDialog::Impl::trackerVisibleFunc(Gtk::TreeModel::const_iterator const& iter)
|
|
|
|
{
|
2017-04-19 12:04:45 +00:00
|
|
|
/* show all */
|
2021-10-18 20:22:31 +00:00
|
|
|
if (all_check_->get_active())
|
2017-04-19 12:04:45 +00:00
|
|
|
{
|
2021-10-18 20:22:31 +00:00
|
|
|
return true;
|
2017-04-19 12:04:45 +00:00
|
|
|
}
|
2008-02-21 07:29:39 +00:00
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
/* don't show the backups... */
|
2021-10-18 20:22:31 +00:00
|
|
|
return !iter->get_value(tracker_cols.is_backup);
|
2009-09-25 21:05:59 +00:00
|
|
|
}
|
|
|
|
|
2022-06-17 15:43:04 +00:00
|
|
|
tr_torrent_id_t DetailsDialog::Impl::tracker_list_get_current_torrent_id() const
|
2010-03-10 19:16:25 +00:00
|
|
|
{
|
2022-06-17 15:43:04 +00:00
|
|
|
// if there's only one torrent in the dialog, always use it
|
2021-10-18 20:22:31 +00:00
|
|
|
if (ids_.size() == 1)
|
2017-04-19 12:04:45 +00:00
|
|
|
{
|
2022-06-17 15:43:04 +00:00
|
|
|
return ids_.front();
|
2017-04-19 12:04:45 +00:00
|
|
|
}
|
2011-01-14 21:57:20 +00:00
|
|
|
|
2022-06-17 15:43:04 +00:00
|
|
|
// otherwise, use the selected tracker's torrent
|
|
|
|
auto const sel = tracker_view_->get_selection();
|
|
|
|
if (auto const iter = sel->get_selected(); iter)
|
2013-01-04 19:45:39 +00:00
|
|
|
{
|
2022-06-17 15:43:04 +00:00
|
|
|
return iter->get_value(tracker_cols.torrent_id);
|
2010-03-10 19:16:25 +00:00
|
|
|
}
|
2011-01-14 21:57:20 +00:00
|
|
|
|
2022-06-17 15:43:04 +00:00
|
|
|
return -1;
|
2010-03-10 19:16:25 +00:00
|
|
|
}
|
|
|
|
|
2021-10-18 20:22:31 +00:00
|
|
|
tr_torrent* DetailsDialog::Impl::tracker_list_get_current_torrent() const
|
2011-01-14 21:57:20 +00:00
|
|
|
{
|
2022-06-17 15:43:04 +00:00
|
|
|
return core_->find_torrent(tracker_list_get_current_torrent_id());
|
2011-01-14 21:57:20 +00:00
|
|
|
}
|
2009-10-04 02:32:38 +00:00
|
|
|
|
2021-10-18 20:22:31 +00:00
|
|
|
namespace
|
2010-04-23 01:46:02 +00:00
|
|
|
{
|
|
|
|
|
2023-04-23 02:11:16 +00:00
|
|
|
void favicon_ready_cb(Glib::RefPtr<Gdk::Pixbuf> const* pixbuf, Gtk::TreeRowReference& reference)
|
2021-10-18 20:22:31 +00:00
|
|
|
{
|
2023-04-23 02:11:16 +00:00
|
|
|
if (pixbuf != nullptr && *pixbuf != nullptr)
|
2010-04-23 01:46:02 +00:00
|
|
|
{
|
2021-10-18 20:22:31 +00:00
|
|
|
auto const path = reference.get_path();
|
|
|
|
auto const model = reference.get_model();
|
2010-04-23 01:46:02 +00:00
|
|
|
|
2021-10-18 20:22:31 +00:00
|
|
|
if (auto const iter = model->get_iter(path); iter)
|
2017-04-19 12:04:45 +00:00
|
|
|
{
|
2023-04-23 02:11:16 +00:00
|
|
|
(*iter)[tracker_cols.favicon] = *pixbuf;
|
2017-04-19 12:04:45 +00:00
|
|
|
}
|
2010-04-23 01:46:02 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-10-18 20:22:31 +00:00
|
|
|
} // namespace
|
|
|
|
|
|
|
|
void DetailsDialog::Impl::refreshTracker(std::vector<tr_torrent*> const& torrents)
|
2017-04-19 12:04:45 +00:00
|
|
|
{
|
2021-10-18 20:22:31 +00:00
|
|
|
std::ostringstream gstr;
|
|
|
|
auto& hash = tracker_hash_;
|
2022-04-02 22:42:51 +00:00
|
|
|
auto const& store = tracker_store_;
|
2021-10-18 20:22:31 +00:00
|
|
|
bool const showScrape = scrape_check_->get_active();
|
2013-01-04 19:45:39 +00:00
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
/* step 1: get all the trackers */
|
2021-12-08 16:55:52 +00:00
|
|
|
auto trackers = std::multimap<tr_torrent const*, tr_tracker_view>{};
|
|
|
|
for (auto const* tor : torrents)
|
2017-04-19 12:04:45 +00:00
|
|
|
{
|
2021-12-08 16:55:52 +00:00
|
|
|
for (size_t i = 0, n = tr_torrentTrackerCount(tor); i < n; ++i)
|
|
|
|
{
|
|
|
|
trackers.emplace(tor, tr_torrentTracker(tor, i));
|
|
|
|
}
|
2017-04-19 12:04:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* step 2: mark all the trackers in the list as not-updated */
|
2022-10-08 22:50:03 +00:00
|
|
|
for (auto& row : store->children())
|
2017-04-19 12:04:45 +00:00
|
|
|
{
|
2021-10-18 20:22:31 +00:00
|
|
|
row[tracker_cols.was_updated] = false;
|
2009-09-25 21:05:59 +00:00
|
|
|
}
|
2008-06-01 01:40:32 +00:00
|
|
|
|
2021-12-08 16:55:52 +00:00
|
|
|
/* step 3: add / update trackers */
|
|
|
|
for (auto const& [tor, tracker] : trackers)
|
2011-04-12 10:51:52 +00:00
|
|
|
{
|
2021-12-08 16:55:52 +00:00
|
|
|
auto const torrent_id = tr_torrentId(tor);
|
2013-01-04 19:45:39 +00:00
|
|
|
|
2021-12-08 16:55:52 +00:00
|
|
|
// build the key to find the row
|
|
|
|
gstr.str({});
|
|
|
|
gstr << torrent_id << '\t' << tracker.tier << '\t' << tracker.announce;
|
|
|
|
if (hash.find(gstr.str()) == hash.end())
|
2011-04-12 10:51:52 +00:00
|
|
|
{
|
2021-12-08 16:55:52 +00:00
|
|
|
// if we didn't have that row, add it
|
|
|
|
auto const iter = store->append();
|
|
|
|
(*iter)[tracker_cols.torrent_id] = torrent_id;
|
|
|
|
(*iter)[tracker_cols.tracker_id] = tracker.id;
|
|
|
|
(*iter)[tracker_cols.key] = gstr.str();
|
2017-04-19 12:04:45 +00:00
|
|
|
|
2021-12-08 16:55:52 +00:00
|
|
|
auto const p = store->get_path(iter);
|
2022-01-17 18:39:50 +00:00
|
|
|
hash.try_emplace(gstr.str(), Gtk::TreeRowReference(store, p));
|
2023-04-23 02:11:16 +00:00
|
|
|
core_->favicon_cache().load(
|
2021-12-08 16:55:52 +00:00
|
|
|
tracker.announce,
|
2023-04-23 02:11:16 +00:00
|
|
|
[ref = Gtk::TreeRowReference(store, p)](auto const* pixbuf_refptr) mutable
|
|
|
|
{ favicon_ready_cb(pixbuf_refptr, ref); });
|
2017-04-19 12:04:45 +00:00
|
|
|
}
|
|
|
|
}
|
2013-01-04 19:45:39 +00:00
|
|
|
|
2021-12-08 16:55:52 +00:00
|
|
|
/* step 4: update the rows */
|
|
|
|
auto const summary_name = std::string(std::size(torrents) == 1 ? tr_torrentName(torrents.front()) : "");
|
|
|
|
for (auto const& [tor, tracker] : trackers)
|
2017-04-19 12:04:45 +00:00
|
|
|
{
|
2021-12-08 16:55:52 +00:00
|
|
|
auto const torrent_id = tr_torrentId(tor);
|
2017-04-19 12:04:45 +00:00
|
|
|
|
2021-12-08 16:55:52 +00:00
|
|
|
// build the key to find the row
|
|
|
|
gstr.str({});
|
|
|
|
gstr << torrent_id << '\t' << tracker.tier << '\t' << tracker.announce;
|
|
|
|
auto const iter = store->get_iter(hash.at(gstr.str()).get_path());
|
2017-04-19 12:04:45 +00:00
|
|
|
|
2021-12-08 16:55:52 +00:00
|
|
|
// update the row
|
|
|
|
gstr.str({});
|
|
|
|
buildTrackerSummary(gstr, summary_name, tracker, showScrape, dialog_.get_direction());
|
|
|
|
(*iter)[tracker_cols.text] = gstr.str();
|
|
|
|
(*iter)[tracker_cols.is_backup] = tracker.isBackup;
|
|
|
|
(*iter)[tracker_cols.tracker_id] = tracker.id;
|
|
|
|
(*iter)[tracker_cols.was_updated] = true;
|
2009-09-25 21:05:59 +00:00
|
|
|
}
|
2011-01-14 21:57:20 +00:00
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
/* step 5: remove trackers that have disappeared */
|
2021-10-18 20:22:31 +00:00
|
|
|
if (auto iter = store->children().begin(); iter)
|
2013-01-04 19:45:39 +00:00
|
|
|
{
|
2021-10-18 20:22:31 +00:00
|
|
|
while (iter)
|
2013-01-04 19:45:39 +00:00
|
|
|
{
|
2021-10-18 20:22:31 +00:00
|
|
|
if (iter->get_value(tracker_cols.was_updated))
|
2013-01-04 19:45:39 +00:00
|
|
|
{
|
2021-10-18 20:22:31 +00:00
|
|
|
++iter;
|
2013-01-04 19:45:39 +00:00
|
|
|
}
|
2017-04-19 12:04:45 +00:00
|
|
|
else
|
2013-01-04 19:45:39 +00:00
|
|
|
{
|
2021-10-18 20:22:31 +00:00
|
|
|
auto const key = iter->get_value(tracker_cols.key);
|
|
|
|
hash.erase(key);
|
|
|
|
iter = store->erase(iter);
|
2011-01-14 21:57:20 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-06-17 15:43:04 +00:00
|
|
|
edit_trackers_button_->set_sensitive(tracker_list_get_current_torrent_id() > 0);
|
2009-04-24 01:37:04 +00:00
|
|
|
}
|
2008-02-21 07:29:39 +00:00
|
|
|
|
2022-10-22 09:42:38 +00:00
|
|
|
void DetailsDialog::Impl::refreshFiles(std::vector<tr_torrent*> const& torrents)
|
|
|
|
{
|
|
|
|
if (torrents.size() == 1)
|
|
|
|
{
|
|
|
|
file_list_->set_torrent(tr_torrentId(torrents.front()));
|
|
|
|
file_list_->show();
|
|
|
|
file_label_->hide();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
file_list_->clear();
|
|
|
|
file_list_->hide();
|
|
|
|
file_label_->show();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-10-18 20:22:31 +00:00
|
|
|
void DetailsDialog::Impl::onScrapeToggled()
|
2009-09-25 21:05:59 +00:00
|
|
|
{
|
2017-04-20 16:02:19 +00:00
|
|
|
tr_quark const key = TR_KEY_show_tracker_scrapes;
|
2021-10-18 20:22:31 +00:00
|
|
|
bool const value = scrape_check_->get_active();
|
|
|
|
core_->set_pref(key, value);
|
|
|
|
refresh();
|
2009-09-25 21:05:59 +00:00
|
|
|
}
|
2008-02-21 07:29:39 +00:00
|
|
|
|
2021-10-18 20:22:31 +00:00
|
|
|
void DetailsDialog::Impl::onBackupToggled()
|
2009-09-25 21:05:59 +00:00
|
|
|
{
|
2017-04-20 16:02:19 +00:00
|
|
|
tr_quark const key = TR_KEY_show_backup_trackers;
|
2021-10-18 20:22:31 +00:00
|
|
|
bool const value = all_check_->get_active();
|
|
|
|
core_->set_pref(key, value);
|
|
|
|
refresh();
|
2009-09-25 21:05:59 +00:00
|
|
|
}
|
2008-02-21 07:29:39 +00:00
|
|
|
|
2022-09-07 22:25:04 +00:00
|
|
|
namespace
|
|
|
|
{
|
|
|
|
|
|
|
|
class EditTrackersDialog : public Gtk::Dialog
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
EditTrackersDialog(
|
|
|
|
BaseObjectType* cast_item,
|
|
|
|
Glib::RefPtr<Gtk::Builder> const& builder,
|
|
|
|
DetailsDialog& parent,
|
2022-11-10 19:35:31 +00:00
|
|
|
Glib::RefPtr<Session> const& core,
|
2022-09-07 22:25:04 +00:00
|
|
|
tr_torrent const* torrent);
|
2022-11-13 17:36:16 +00:00
|
|
|
~EditTrackersDialog() override = default;
|
2022-09-07 22:25:04 +00:00
|
|
|
|
|
|
|
TR_DISABLE_COPY_MOVE(EditTrackersDialog)
|
|
|
|
|
2022-11-10 19:35:31 +00:00
|
|
|
static std::unique_ptr<EditTrackersDialog> create(
|
|
|
|
DetailsDialog& parent,
|
|
|
|
Glib::RefPtr<Session> const& core,
|
|
|
|
tr_torrent const* tor);
|
2022-09-07 22:25:04 +00:00
|
|
|
|
|
|
|
private:
|
2022-09-09 12:34:28 +00:00
|
|
|
void on_response(int response) override;
|
2022-09-07 22:25:04 +00:00
|
|
|
|
|
|
|
private:
|
|
|
|
DetailsDialog& parent_;
|
|
|
|
Glib::RefPtr<Session> const core_;
|
|
|
|
tr_torrent_id_t const torrent_id_;
|
|
|
|
Gtk::TextView* const urls_view_;
|
|
|
|
};
|
|
|
|
|
|
|
|
EditTrackersDialog::EditTrackersDialog(
|
|
|
|
BaseObjectType* cast_item,
|
|
|
|
Glib::RefPtr<Gtk::Builder> const& builder,
|
|
|
|
DetailsDialog& parent,
|
2022-11-10 19:35:31 +00:00
|
|
|
Glib::RefPtr<Session> const& core,
|
2022-09-07 22:25:04 +00:00
|
|
|
tr_torrent const* torrent)
|
|
|
|
: Gtk::Dialog(cast_item)
|
|
|
|
, parent_(parent)
|
|
|
|
, core_(core)
|
|
|
|
, torrent_id_(tr_torrentId(torrent))
|
|
|
|
, urls_view_(gtr_get_widget<Gtk::TextView>(builder, "urls_view"))
|
|
|
|
{
|
|
|
|
set_title(fmt::format(_("{torrent_name} - Edit Trackers"), fmt::arg("torrent_name", tr_torrentName(torrent))));
|
|
|
|
set_transient_for(parent);
|
|
|
|
|
|
|
|
urls_view_->get_buffer()->set_text(tr_torrentGetTrackerList(torrent));
|
|
|
|
}
|
|
|
|
|
|
|
|
std::unique_ptr<EditTrackersDialog> EditTrackersDialog::create(
|
|
|
|
DetailsDialog& parent,
|
2022-11-10 19:35:31 +00:00
|
|
|
Glib::RefPtr<Session> const& core,
|
2022-09-07 22:25:04 +00:00
|
|
|
tr_torrent const* torrent)
|
|
|
|
{
|
|
|
|
auto const builder = Gtk::Builder::create_from_resource(gtr_get_full_resource_path("EditTrackersDialog.ui"));
|
|
|
|
return std::unique_ptr<EditTrackersDialog>(
|
|
|
|
gtr_get_widget_derived<EditTrackersDialog>(builder, "EditTrackersDialog", parent, core, torrent));
|
|
|
|
}
|
|
|
|
|
|
|
|
void EditTrackersDialog::on_response(int response)
|
2009-09-26 00:48:07 +00:00
|
|
|
{
|
2021-10-18 20:22:31 +00:00
|
|
|
bool do_destroy = true;
|
2009-09-26 00:48:07 +00:00
|
|
|
|
2022-09-10 13:19:54 +00:00
|
|
|
if (response == TR_GTK_RESPONSE_TYPE(ACCEPT))
|
2009-09-26 00:48:07 +00:00
|
|
|
{
|
2022-09-07 22:25:04 +00:00
|
|
|
auto const text_buffer = urls_view_->get_buffer();
|
2013-01-04 19:45:39 +00:00
|
|
|
|
2022-09-07 22:25:04 +00:00
|
|
|
if (auto* const tor = core_->find_torrent(torrent_id_); tor != nullptr)
|
2009-10-10 19:24:46 +00:00
|
|
|
{
|
2022-02-18 17:52:01 +00:00
|
|
|
if (tr_torrentSetTrackerList(tor, text_buffer->get_text(false).c_str()))
|
2013-01-04 19:45:39 +00:00
|
|
|
{
|
2022-09-07 22:25:04 +00:00
|
|
|
parent_.refresh();
|
2013-01-04 19:45:39 +00:00
|
|
|
}
|
2017-04-19 12:04:45 +00:00
|
|
|
else
|
2013-01-04 19:45:39 +00:00
|
|
|
{
|
2022-09-10 18:15:01 +00:00
|
|
|
auto w = std::make_shared<Gtk::MessageDialog>(
|
2022-09-10 13:19:54 +00:00
|
|
|
*this,
|
|
|
|
_("List contains invalid URLs"),
|
|
|
|
false,
|
|
|
|
TR_GTK_MESSAGE_TYPE(ERROR),
|
|
|
|
TR_GTK_BUTTONS_TYPE(CLOSE),
|
|
|
|
true);
|
2022-09-10 18:15:01 +00:00
|
|
|
w->set_secondary_text(_("Please correct the errors and try again."));
|
|
|
|
w->signal_response().connect([w](int /*response*/) mutable { w.reset(); });
|
|
|
|
w->show();
|
2009-09-26 00:48:07 +00:00
|
|
|
|
2021-10-18 20:22:31 +00:00
|
|
|
do_destroy = false;
|
|
|
|
}
|
2011-01-14 21:57:20 +00:00
|
|
|
}
|
2010-03-10 19:16:25 +00:00
|
|
|
}
|
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
if (do_destroy)
|
|
|
|
{
|
2022-10-08 22:50:03 +00:00
|
|
|
close();
|
2017-04-19 12:04:45 +00:00
|
|
|
}
|
2009-09-26 00:48:07 +00:00
|
|
|
}
|
|
|
|
|
2022-09-07 22:25:04 +00:00
|
|
|
} // namespace
|
|
|
|
|
2021-10-18 20:22:31 +00:00
|
|
|
void DetailsDialog::Impl::on_edit_trackers()
|
2017-04-19 12:04:45 +00:00
|
|
|
{
|
2022-09-07 22:25:04 +00:00
|
|
|
if (auto const* const tor = tracker_list_get_current_torrent(); tor != nullptr)
|
2017-04-19 12:04:45 +00:00
|
|
|
{
|
2022-09-07 22:25:04 +00:00
|
|
|
auto d = std::shared_ptr<EditTrackersDialog>(EditTrackersDialog::create(dialog_, core_, tor));
|
2022-10-08 22:50:03 +00:00
|
|
|
gtr_window_on_close(*d, [d]() mutable { d.reset(); });
|
2021-10-18 20:22:31 +00:00
|
|
|
d->show();
|
2011-01-14 21:57:20 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-10-18 20:22:31 +00:00
|
|
|
void DetailsDialog::Impl::on_tracker_list_selection_changed()
|
2011-01-14 21:57:20 +00:00
|
|
|
{
|
2021-10-18 20:22:31 +00:00
|
|
|
int const n = tracker_view_->get_selection()->count_selected_rows();
|
2022-04-02 22:42:51 +00:00
|
|
|
auto const* const tor = tracker_list_get_current_torrent();
|
2011-01-14 21:57:20 +00:00
|
|
|
|
2021-10-18 20:22:31 +00:00
|
|
|
remove_tracker_button_->set_sensitive(n > 0);
|
|
|
|
add_tracker_button_->set_sensitive(tor != nullptr);
|
|
|
|
edit_trackers_button_->set_sensitive(tor != nullptr);
|
2011-01-14 21:57:20 +00:00
|
|
|
}
|
|
|
|
|
2022-09-07 22:25:04 +00:00
|
|
|
namespace
|
|
|
|
{
|
|
|
|
|
|
|
|
class AddTrackerDialog : public Gtk::Dialog
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
AddTrackerDialog(
|
|
|
|
BaseObjectType* cast_item,
|
|
|
|
Glib::RefPtr<Gtk::Builder> const& builder,
|
|
|
|
DetailsDialog& parent,
|
2022-11-10 19:35:31 +00:00
|
|
|
Glib::RefPtr<Session> const& core,
|
2022-09-07 22:25:04 +00:00
|
|
|
tr_torrent const* torrent);
|
2022-11-13 17:36:16 +00:00
|
|
|
~AddTrackerDialog() override = default;
|
2022-09-07 22:25:04 +00:00
|
|
|
|
|
|
|
TR_DISABLE_COPY_MOVE(AddTrackerDialog)
|
|
|
|
|
2022-11-10 19:35:31 +00:00
|
|
|
static std::unique_ptr<AddTrackerDialog> create(
|
|
|
|
DetailsDialog& parent,
|
|
|
|
Glib::RefPtr<Session> const& core,
|
|
|
|
tr_torrent const* tor);
|
2022-09-07 22:25:04 +00:00
|
|
|
|
|
|
|
private:
|
2022-09-09 12:34:28 +00:00
|
|
|
void on_response(int response) override;
|
2022-09-07 22:25:04 +00:00
|
|
|
|
|
|
|
private:
|
|
|
|
DetailsDialog& parent_;
|
|
|
|
Glib::RefPtr<Session> const core_;
|
|
|
|
tr_torrent_id_t const torrent_id_;
|
|
|
|
Gtk::Entry* const url_entry_;
|
|
|
|
};
|
|
|
|
|
|
|
|
AddTrackerDialog::AddTrackerDialog(
|
|
|
|
BaseObjectType* cast_item,
|
|
|
|
Glib::RefPtr<Gtk::Builder> const& builder,
|
|
|
|
DetailsDialog& parent,
|
2022-11-10 19:35:31 +00:00
|
|
|
Glib::RefPtr<Session> const& core,
|
2022-09-07 22:25:04 +00:00
|
|
|
tr_torrent const* torrent)
|
|
|
|
: Gtk::Dialog(cast_item)
|
|
|
|
, parent_(parent)
|
|
|
|
, core_(core)
|
|
|
|
, torrent_id_(tr_torrentId(torrent))
|
|
|
|
, url_entry_(gtr_get_widget<Gtk::Entry>(builder, "url_entry"))
|
|
|
|
{
|
|
|
|
set_title(fmt::format(_("{torrent_name} - Add Tracker"), fmt::arg("torrent_name", tr_torrentName(torrent))));
|
|
|
|
set_transient_for(parent);
|
|
|
|
|
|
|
|
gtr_paste_clipboard_url_into_entry(*url_entry_);
|
|
|
|
}
|
|
|
|
|
|
|
|
std::unique_ptr<AddTrackerDialog> AddTrackerDialog::create(
|
|
|
|
DetailsDialog& parent,
|
2022-11-10 19:35:31 +00:00
|
|
|
Glib::RefPtr<Session> const& core,
|
2022-09-07 22:25:04 +00:00
|
|
|
tr_torrent const* torrent)
|
|
|
|
{
|
|
|
|
auto const builder = Gtk::Builder::create_from_resource(gtr_get_full_resource_path("AddTrackerDialog.ui"));
|
|
|
|
return std::unique_ptr<AddTrackerDialog>(
|
|
|
|
gtr_get_widget_derived<AddTrackerDialog>(builder, "AddTrackerDialog", parent, core, torrent));
|
|
|
|
}
|
|
|
|
|
|
|
|
void AddTrackerDialog::on_response(int response)
|
2011-01-14 21:57:20 +00:00
|
|
|
{
|
2021-10-18 20:22:31 +00:00
|
|
|
bool destroy = true;
|
2011-01-14 21:57:20 +00:00
|
|
|
|
2022-09-10 13:19:54 +00:00
|
|
|
if (response == TR_GTK_RESPONSE_TYPE(ACCEPT))
|
2011-01-14 21:57:20 +00:00
|
|
|
{
|
2022-09-07 22:25:04 +00:00
|
|
|
auto const url = gtr_str_strip(url_entry_->get_text());
|
2011-01-14 21:57:20 +00:00
|
|
|
|
2021-10-18 20:22:31 +00:00
|
|
|
if (!url.empty())
|
2011-01-14 21:57:20 +00:00
|
|
|
{
|
2021-10-18 20:22:31 +00:00
|
|
|
if (tr_urlIsValidTracker(url.c_str()))
|
2011-01-14 21:57:20 +00:00
|
|
|
{
|
2017-05-01 15:46:41 +00:00
|
|
|
tr_variant top;
|
2015-07-13 00:32:48 +00:00
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
tr_variantInitDict(&top, 2);
|
2021-11-18 05:37:35 +00:00
|
|
|
tr_variantDictAddStrView(&top, TR_KEY_method, "torrent-set"sv);
|
2022-11-13 17:36:16 +00:00
|
|
|
auto* const args = tr_variantDictAddDict(&top, TR_KEY_arguments, 2);
|
2022-09-07 22:25:04 +00:00
|
|
|
tr_variantDictAddInt(args, TR_KEY_id, torrent_id_);
|
2022-11-13 17:36:16 +00:00
|
|
|
auto* const trackers = tr_variantDictAddList(args, TR_KEY_trackerAdd, 1);
|
2021-10-20 02:30:50 +00:00
|
|
|
tr_variantListAddStr(trackers, url.raw());
|
2015-07-13 00:32:48 +00:00
|
|
|
|
2024-01-03 04:14:43 +00:00
|
|
|
core_->exec(top);
|
2022-09-07 22:25:04 +00:00
|
|
|
parent_.refresh();
|
2011-01-14 21:57:20 +00:00
|
|
|
}
|
2017-04-19 12:04:45 +00:00
|
|
|
else
|
2011-01-14 21:57:20 +00:00
|
|
|
{
|
2022-09-07 22:25:04 +00:00
|
|
|
gtr_unrecognized_url_dialog(*this, url);
|
2021-10-18 20:22:31 +00:00
|
|
|
destroy = false;
|
2011-01-14 21:57:20 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
if (destroy)
|
|
|
|
{
|
2022-10-08 22:50:03 +00:00
|
|
|
close();
|
2017-04-19 12:04:45 +00:00
|
|
|
}
|
2011-01-14 21:57:20 +00:00
|
|
|
}
|
|
|
|
|
2022-09-07 22:25:04 +00:00
|
|
|
} // namespace
|
|
|
|
|
2021-10-18 20:22:31 +00:00
|
|
|
void DetailsDialog::Impl::on_tracker_list_add_button_clicked()
|
2017-04-19 12:04:45 +00:00
|
|
|
{
|
2022-09-07 22:25:04 +00:00
|
|
|
if (auto const* const tor = tracker_list_get_current_torrent(); tor != nullptr)
|
2017-04-19 12:04:45 +00:00
|
|
|
{
|
2022-09-07 22:25:04 +00:00
|
|
|
auto d = std::shared_ptr<AddTrackerDialog>(AddTrackerDialog::create(dialog_, core_, tor));
|
2022-10-08 22:50:03 +00:00
|
|
|
gtr_window_on_close(*d, [d]() mutable { d.reset(); });
|
2022-09-07 22:25:04 +00:00
|
|
|
d->show();
|
2011-01-14 21:57:20 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-10-18 20:22:31 +00:00
|
|
|
void DetailsDialog::Impl::on_tracker_list_remove_button_clicked()
|
2011-01-14 21:57:20 +00:00
|
|
|
{
|
2021-10-18 20:22:31 +00:00
|
|
|
auto* v = tracker_view_;
|
|
|
|
auto sel = v->get_selection();
|
2020-08-18 10:36:10 +00:00
|
|
|
|
2021-10-18 20:22:31 +00:00
|
|
|
if (auto const iter = sel->get_selected(); iter)
|
2013-01-04 19:45:39 +00:00
|
|
|
{
|
2021-10-18 20:22:31 +00:00
|
|
|
auto const torrent_id = iter->get_value(tracker_cols.torrent_id);
|
|
|
|
auto const tracker_id = iter->get_value(tracker_cols.tracker_id);
|
2017-05-01 15:46:41 +00:00
|
|
|
tr_variant top;
|
2015-07-13 00:32:48 +00:00
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
tr_variantInitDict(&top, 2);
|
2021-11-18 05:37:35 +00:00
|
|
|
tr_variantDictAddStrView(&top, TR_KEY_method, "torrent-set"sv);
|
2022-11-13 17:36:16 +00:00
|
|
|
auto* const args = tr_variantDictAddDict(&top, TR_KEY_arguments, 2);
|
2017-04-19 12:04:45 +00:00
|
|
|
tr_variantDictAddInt(args, TR_KEY_id, torrent_id);
|
2022-11-13 17:36:16 +00:00
|
|
|
auto* const trackers = tr_variantDictAddList(args, TR_KEY_trackerRemove, 1);
|
2017-04-19 12:04:45 +00:00
|
|
|
tr_variantListAddInt(trackers, tracker_id);
|
2015-07-13 00:32:48 +00:00
|
|
|
|
2024-01-03 04:14:43 +00:00
|
|
|
core_->exec(top);
|
2021-10-18 20:22:31 +00:00
|
|
|
refresh();
|
2011-01-14 21:57:20 +00:00
|
|
|
}
|
2009-09-25 21:05:59 +00:00
|
|
|
}
|
2008-02-21 07:29:39 +00:00
|
|
|
|
2022-09-07 22:25:04 +00:00
|
|
|
void DetailsDialog::Impl::tracker_page_init(Glib::RefPtr<Gtk::Builder> const& /*builder*/)
|
2017-04-19 12:04:45 +00:00
|
|
|
{
|
2017-04-20 16:02:19 +00:00
|
|
|
int const pad = (GUI_PAD + GUI_PAD_BIG) / 2;
|
2017-04-19 12:04:45 +00:00
|
|
|
|
2021-10-18 20:22:31 +00:00
|
|
|
tracker_store_ = Gtk::ListStore::create(tracker_cols);
|
|
|
|
|
|
|
|
trackers_filtered_ = Gtk::TreeModelFilter::create(tracker_store_);
|
2021-11-12 09:12:50 +00:00
|
|
|
trackers_filtered_->set_visible_func(sigc::mem_fun(*this, &Impl::trackerVisibleFunc));
|
2021-10-18 20:22:31 +00:00
|
|
|
|
2022-09-07 22:25:04 +00:00
|
|
|
tracker_view_->set_model(trackers_filtered_);
|
2023-08-06 03:26:29 +00:00
|
|
|
setup_item_view_button_event_handling(
|
2022-10-08 22:50:03 +00:00
|
|
|
*tracker_view_,
|
|
|
|
[this](guint /*button*/, TrGdkModifierType /*state*/, double view_x, double view_y, bool context_menu_requested)
|
2023-08-06 03:26:29 +00:00
|
|
|
{ return on_item_view_button_pressed(*tracker_view_, view_x, view_y, context_menu_requested); },
|
|
|
|
[this](double view_x, double view_y) { return on_item_view_button_released(*tracker_view_, view_x, view_y); });
|
2021-10-18 20:22:31 +00:00
|
|
|
|
|
|
|
auto sel = tracker_view_->get_selection();
|
2021-11-12 09:12:50 +00:00
|
|
|
sel->signal_changed().connect(sigc::mem_fun(*this, &Impl::on_tracker_list_selection_changed));
|
2021-10-18 20:22:31 +00:00
|
|
|
|
|
|
|
auto* c = Gtk::make_managed<Gtk::TreeViewColumn>();
|
|
|
|
c->set_title(_("Trackers"));
|
|
|
|
tracker_view_->append_column(*c);
|
|
|
|
|
|
|
|
{
|
|
|
|
auto* r = Gtk::make_managed<Gtk::CellRendererPixbuf>();
|
|
|
|
r->property_width() = 20 + (GUI_PAD_SMALL * 2);
|
|
|
|
r->property_xpad() = GUI_PAD_SMALL;
|
|
|
|
r->property_ypad() = pad;
|
|
|
|
r->property_yalign() = 0.0F;
|
|
|
|
c->pack_start(*r, false);
|
|
|
|
c->add_attribute(r->property_pixbuf(), tracker_cols.favicon);
|
|
|
|
}
|
|
|
|
|
|
|
|
{
|
|
|
|
auto* r = Gtk::make_managed<Gtk::CellRendererText>();
|
2022-09-10 13:19:54 +00:00
|
|
|
r->property_ellipsize() = TR_PANGO_ELLIPSIZE_MODE(END);
|
2021-10-18 20:22:31 +00:00
|
|
|
r->property_xpad() = GUI_PAD_SMALL;
|
|
|
|
r->property_ypad() = pad;
|
|
|
|
c->pack_start(*r, true);
|
|
|
|
c->add_attribute(r->property_markup(), tracker_cols.text);
|
|
|
|
}
|
|
|
|
|
2021-11-12 09:12:50 +00:00
|
|
|
add_tracker_button_->signal_clicked().connect(sigc::mem_fun(*this, &Impl::on_tracker_list_add_button_clicked));
|
|
|
|
edit_trackers_button_->signal_clicked().connect(sigc::mem_fun(*this, &Impl::on_edit_trackers));
|
|
|
|
remove_tracker_button_->signal_clicked().connect(sigc::mem_fun(*this, &Impl::on_tracker_list_remove_button_clicked));
|
2021-10-18 20:22:31 +00:00
|
|
|
|
|
|
|
scrape_check_->set_active(gtr_pref_flag_get(TR_KEY_show_tracker_scrapes));
|
2021-11-12 09:12:50 +00:00
|
|
|
scrape_check_->signal_toggled().connect(sigc::mem_fun(*this, &Impl::onScrapeToggled));
|
2021-10-18 20:22:31 +00:00
|
|
|
|
|
|
|
all_check_->set_active(gtr_pref_flag_get(TR_KEY_show_backup_trackers));
|
2021-11-12 09:12:50 +00:00
|
|
|
all_check_->signal_toggled().connect(sigc::mem_fun(*this, &Impl::onBackupToggled));
|
2008-02-21 07:29:39 +00:00
|
|
|
}
|
|
|
|
|
2007-06-06 00:30:13 +00:00
|
|
|
/****
|
|
|
|
***** DIALOG
|
|
|
|
****/
|
|
|
|
|
2021-10-18 20:22:31 +00:00
|
|
|
void DetailsDialog::Impl::refresh()
|
2007-06-06 00:30:13 +00:00
|
|
|
{
|
2021-10-18 20:22:31 +00:00
|
|
|
auto const torrents = getTorrents();
|
2009-04-24 01:37:04 +00:00
|
|
|
|
2021-10-18 20:22:31 +00:00
|
|
|
refreshInfo(torrents);
|
|
|
|
refreshPeers(torrents);
|
|
|
|
refreshTracker(torrents);
|
2022-10-22 09:42:38 +00:00
|
|
|
refreshFiles(torrents);
|
2021-10-18 20:22:31 +00:00
|
|
|
refreshOptions(torrents);
|
2009-04-24 01:37:04 +00:00
|
|
|
|
2021-10-18 20:22:31 +00:00
|
|
|
if (torrents.empty())
|
2017-04-19 12:04:45 +00:00
|
|
|
{
|
2022-09-10 13:19:54 +00:00
|
|
|
dialog_.response(TR_GTK_RESPONSE_TYPE(CLOSE));
|
2017-04-19 12:04:45 +00:00
|
|
|
}
|
2007-06-06 00:30:13 +00:00
|
|
|
}
|
|
|
|
|
2022-10-08 22:50:03 +00:00
|
|
|
void DetailsDialog::Impl::on_details_window_size_allocated()
|
2007-06-06 00:30:13 +00:00
|
|
|
{
|
2020-11-01 21:47:57 +00:00
|
|
|
int w = 0;
|
|
|
|
int h = 0;
|
2022-10-08 22:50:03 +00:00
|
|
|
#if GTKMM_CHECK_VERSION(4, 0, 0)
|
|
|
|
dialog_.get_default_size(w, h);
|
|
|
|
#else
|
2021-10-18 20:22:31 +00:00
|
|
|
dialog_.get_size(w, h);
|
2022-10-08 22:50:03 +00:00
|
|
|
#endif
|
2020-04-27 21:34:02 +00:00
|
|
|
gtr_pref_int_set(TR_KEY_details_window_width, w);
|
|
|
|
gtr_pref_int_set(TR_KEY_details_window_height, h);
|
|
|
|
}
|
|
|
|
|
2021-10-18 20:22:31 +00:00
|
|
|
DetailsDialog::Impl::~Impl()
|
2017-04-19 12:04:45 +00:00
|
|
|
{
|
2021-10-18 20:22:31 +00:00
|
|
|
periodic_refresh_tag_.disconnect();
|
2007-06-06 00:30:13 +00:00
|
|
|
}
|
|
|
|
|
2021-11-01 00:11:23 +00:00
|
|
|
std::unique_ptr<DetailsDialog> DetailsDialog::create(Gtk::Window& parent, Glib::RefPtr<Session> const& core)
|
2017-04-19 12:04:45 +00:00
|
|
|
{
|
2022-09-07 22:25:04 +00:00
|
|
|
auto const builder = Gtk::Builder::create_from_resource(gtr_get_full_resource_path("DetailsDialog.ui"));
|
|
|
|
return std::unique_ptr<DetailsDialog>(gtr_get_widget_derived<DetailsDialog>(builder, "DetailsDialog", parent, core));
|
2021-10-18 20:22:31 +00:00
|
|
|
}
|
2017-04-19 12:04:45 +00:00
|
|
|
|
2022-09-07 22:25:04 +00:00
|
|
|
DetailsDialog::DetailsDialog(
|
|
|
|
BaseObjectType* cast_item,
|
|
|
|
Glib::RefPtr<Gtk::Builder> const& builder,
|
|
|
|
Gtk::Window& parent,
|
|
|
|
Glib::RefPtr<Session> const& core)
|
|
|
|
: Gtk::Dialog(cast_item)
|
|
|
|
, impl_(std::make_unique<Impl>(*this, builder, core))
|
2021-10-18 20:22:31 +00:00
|
|
|
{
|
2022-09-07 22:25:04 +00:00
|
|
|
set_transient_for(parent);
|
2021-10-18 20:22:31 +00:00
|
|
|
}
|
2017-04-19 12:04:45 +00:00
|
|
|
|
2021-10-18 20:22:31 +00:00
|
|
|
DetailsDialog::~DetailsDialog() = default;
|
|
|
|
|
2022-09-07 22:25:04 +00:00
|
|
|
DetailsDialog::Impl::Impl(DetailsDialog& dialog, Glib::RefPtr<Gtk::Builder> const& builder, Glib::RefPtr<Session> const& core)
|
2021-10-18 20:22:31 +00:00
|
|
|
: dialog_(dialog)
|
|
|
|
, core_(core)
|
2022-09-07 22:25:04 +00:00
|
|
|
, honor_limits_check_(gtr_get_widget<Gtk::CheckButton>(builder, "honor_limits_check"))
|
|
|
|
, up_limited_check_(gtr_get_widget<Gtk::CheckButton>(builder, "upload_limit_check"))
|
|
|
|
, up_limit_sping_(gtr_get_widget<Gtk::SpinButton>(builder, "upload_limit_spin"))
|
|
|
|
, down_limited_check_(gtr_get_widget<Gtk::CheckButton>(builder, "download_limit_check"))
|
|
|
|
, down_limit_spin_(gtr_get_widget<Gtk::SpinButton>(builder, "download_limit_spin"))
|
|
|
|
, bandwidth_combo_(gtr_get_widget<Gtk::ComboBox>(builder, "priority_combo"))
|
|
|
|
, ratio_combo_(gtr_get_widget<Gtk::ComboBox>(builder, "ratio_limit_combo"))
|
|
|
|
, ratio_spin_(gtr_get_widget<Gtk::SpinButton>(builder, "ratio_limit_spin"))
|
|
|
|
, idle_combo_(gtr_get_widget<Gtk::ComboBox>(builder, "idle_limit_combo"))
|
|
|
|
, idle_spin_(gtr_get_widget<Gtk::SpinButton>(builder, "idle_limit_spin"))
|
|
|
|
, max_peers_spin_(gtr_get_widget<Gtk::SpinButton>(builder, "max_peers_spin"))
|
|
|
|
, added_lb_(gtr_get_widget<Gtk::Label>(builder, "added_value_label"))
|
|
|
|
, size_lb_(gtr_get_widget<Gtk::Label>(builder, "torrent_size_value_label"))
|
|
|
|
, state_lb_(gtr_get_widget<Gtk::Label>(builder, "state_value_label"))
|
|
|
|
, have_lb_(gtr_get_widget<Gtk::Label>(builder, "have_value_label"))
|
|
|
|
, dl_lb_(gtr_get_widget<Gtk::Label>(builder, "downloaded_value_label"))
|
|
|
|
, ul_lb_(gtr_get_widget<Gtk::Label>(builder, "uploaded_value_label"))
|
|
|
|
, error_lb_(gtr_get_widget<Gtk::Label>(builder, "error_value_label"))
|
|
|
|
, date_started_lb_(gtr_get_widget<Gtk::Label>(builder, "running_time_value_label"))
|
|
|
|
, eta_lb_(gtr_get_widget<Gtk::Label>(builder, "remaining_time_value_label"))
|
|
|
|
, last_activity_lb_(gtr_get_widget<Gtk::Label>(builder, "last_activity_value_label"))
|
|
|
|
, hash_lb_(gtr_get_widget<Gtk::Label>(builder, "hash_value_label"))
|
|
|
|
, privacy_lb_(gtr_get_widget<Gtk::Label>(builder, "privacy_value_label"))
|
|
|
|
, origin_lb_(gtr_get_widget<Gtk::Label>(builder, "origin_value_label"))
|
|
|
|
, destination_lb_(gtr_get_widget<Gtk::Label>(builder, "location_value_label"))
|
|
|
|
, webseed_view_(gtr_get_widget<Gtk::ScrolledWindow>(builder, "webseeds_view_scroll"))
|
|
|
|
, peer_view_(gtr_get_widget<Gtk::TreeView>(builder, "peers_view"))
|
|
|
|
, more_peer_details_check_(gtr_get_widget<Gtk::CheckButton>(builder, "more_peer_details_check"))
|
|
|
|
, add_tracker_button_(gtr_get_widget<Gtk::Button>(builder, "add_tracker_button"))
|
|
|
|
, edit_trackers_button_(gtr_get_widget<Gtk::Button>(builder, "edit_tracker_button"))
|
|
|
|
, remove_tracker_button_(gtr_get_widget<Gtk::Button>(builder, "remove_tracker_button"))
|
|
|
|
, tracker_view_(gtr_get_widget<Gtk::TreeView>(builder, "trackers_view"))
|
|
|
|
, scrape_check_(gtr_get_widget<Gtk::CheckButton>(builder, "more_tracker_details_check"))
|
|
|
|
, all_check_(gtr_get_widget<Gtk::CheckButton>(builder, "backup_trackers_check"))
|
|
|
|
, file_list_(gtr_get_widget_derived<FileList>(builder, "files_view_scroll", "files_view", core, 0))
|
|
|
|
, file_label_(gtr_get_widget<Gtk::Label>(builder, "files_label"))
|
2021-10-18 20:22:31 +00:00
|
|
|
{
|
2020-04-27 21:34:02 +00:00
|
|
|
/* return saved window size */
|
2022-10-08 22:50:03 +00:00
|
|
|
auto const width = (int)gtr_pref_int_get(TR_KEY_details_window_width);
|
|
|
|
auto const height = (int)gtr_pref_int_get(TR_KEY_details_window_height);
|
|
|
|
#if GTKMM_CHECK_VERSION(4, 0, 0)
|
|
|
|
dialog_.set_default_size(width, height);
|
|
|
|
dialog_.property_default_width().signal_changed().connect(sigc::mem_fun(*this, &Impl::on_details_window_size_allocated));
|
|
|
|
dialog_.property_default_height().signal_changed().connect(sigc::mem_fun(*this, &Impl::on_details_window_size_allocated));
|
|
|
|
#else
|
|
|
|
dialog_.resize(width, height);
|
|
|
|
dialog_.signal_size_allocate().connect(sigc::hide<0>(sigc::mem_fun(*this, &Impl::on_details_window_size_allocated)));
|
|
|
|
#endif
|
|
|
|
|
|
|
|
dialog_.signal_response().connect(sigc::hide<0>(sigc::mem_fun(dialog_, &DetailsDialog::close)));
|
2021-10-18 20:22:31 +00:00
|
|
|
|
2022-09-07 22:25:04 +00:00
|
|
|
info_page_init(builder);
|
|
|
|
peer_page_init(builder);
|
|
|
|
tracker_page_init(builder);
|
|
|
|
options_page_init(builder);
|
2021-10-18 20:22:31 +00:00
|
|
|
|
|
|
|
periodic_refresh_tag_ = Glib::signal_timeout().connect_seconds(
|
|
|
|
[this]() { return refresh(), true; },
|
|
|
|
SECONDARY_WINDOW_REFRESH_INTERVAL_SECONDS);
|
2022-01-25 05:16:33 +00:00
|
|
|
|
2022-09-07 22:25:04 +00:00
|
|
|
auto* const n = gtr_get_widget<Gtk::Notebook>(builder, "dialog_pages");
|
2022-01-25 05:16:33 +00:00
|
|
|
n->set_current_page(last_page_);
|
2022-12-16 17:40:28 +00:00
|
|
|
n->signal_switch_page().connect([](Gtk::Widget* /*page*/, guint page_number) { last_page_ = page_number; });
|
2021-10-18 20:22:31 +00:00
|
|
|
}
|
|
|
|
|
2022-06-17 15:43:04 +00:00
|
|
|
void DetailsDialog::set_torrents(std::vector<tr_torrent_id_t> const& ids)
|
2021-10-18 20:22:31 +00:00
|
|
|
{
|
|
|
|
impl_->set_torrents(ids);
|
2007-06-06 00:30:13 +00:00
|
|
|
}
|
2008-09-23 19:11:04 +00:00
|
|
|
|
2022-09-07 22:25:04 +00:00
|
|
|
void DetailsDialog::refresh()
|
|
|
|
{
|
|
|
|
impl_->refresh();
|
|
|
|
}
|
|
|
|
|
2022-06-17 15:43:04 +00:00
|
|
|
void DetailsDialog::Impl::set_torrents(std::vector<tr_torrent_id_t> const& ids)
|
2009-04-24 01:37:04 +00:00
|
|
|
{
|
2021-10-18 20:22:31 +00:00
|
|
|
Glib::ustring title;
|
2022-06-17 15:43:04 +00:00
|
|
|
auto const len = ids.size();
|
2009-04-24 01:37:04 +00:00
|
|
|
|
2021-10-18 20:22:31 +00:00
|
|
|
ids_ = ids;
|
2009-04-24 01:37:04 +00:00
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
if (len == 1)
|
2009-04-24 12:05:53 +00:00
|
|
|
{
|
2021-10-18 20:22:31 +00:00
|
|
|
int const id = ids.front();
|
|
|
|
auto const* tor = core_->find_torrent(id);
|
2022-03-21 14:15:48 +00:00
|
|
|
title = fmt::format(_("{torrent_name} Properties"), fmt::arg("torrent_name", tr_torrentName(tor)));
|
2009-04-24 12:05:53 +00:00
|
|
|
}
|
2017-04-19 12:04:45 +00:00
|
|
|
else
|
2013-01-04 19:45:39 +00:00
|
|
|
{
|
2022-03-21 14:15:48 +00:00
|
|
|
title = fmt::format(
|
2022-04-07 13:23:04 +00:00
|
|
|
ngettext("Properties - {torrent_count:L} Torrent", "Properties - {torrent_count:L} Torrents", len),
|
|
|
|
fmt::arg("torrent_count", len));
|
2009-04-24 01:37:04 +00:00
|
|
|
}
|
|
|
|
|
2021-10-18 20:22:31 +00:00
|
|
|
dialog_.set_title(title);
|
2009-04-24 12:05:53 +00:00
|
|
|
|
2021-10-18 20:22:31 +00:00
|
|
|
refresh();
|
2009-04-24 01:37:04 +00:00
|
|
|
}
|