2008-02-10 22:25:42 +00:00
|
|
|
/*
|
2021-10-18 20:22:31 +00:00
|
|
|
* This file Copyright (C) 2007-2021 Mnemosyne LLC
|
2007-06-06 00:30:13 +00:00
|
|
|
*
|
2014-01-21 03:10:30 +00:00
|
|
|
* It may be used under the GNU GPL versions 2 or 3
|
2014-01-19 01:09:44 +00:00
|
|
|
* or any future license endorsed by Mnemosyne LLC.
|
2008-09-23 19:11:04 +00:00
|
|
|
*
|
2008-02-10 22:25:42 +00:00
|
|
|
*/
|
2007-06-06 00:30:13 +00:00
|
|
|
|
2021-10-18 20:22:31 +00:00
|
|
|
#include <algorithm>
|
2013-08-24 17:53:45 +00:00
|
|
|
#include <limits.h> /* INT_MAX */
|
2021-10-18 20:22:31 +00:00
|
|
|
#include <sstream>
|
2007-06-06 00:30:13 +00:00
|
|
|
#include <stddef.h>
|
2017-04-21 07:40:57 +00:00
|
|
|
#include <stdio.h> /* sscanf() */
|
|
|
|
#include <stdlib.h> /* abort() */
|
2021-10-20 02:30:50 +00:00
|
|
|
#include <string_view>
|
2021-10-18 20:22:31 +00:00
|
|
|
#include <unordered_map>
|
|
|
|
|
|
|
|
#include <glibmm/i18n.h>
|
2007-06-18 03:40:41 +00:00
|
|
|
|
2007-07-18 23:04:26 +00:00
|
|
|
#include <libtransmission/transmission.h>
|
2009-04-24 12:05:53 +00:00
|
|
|
#include <libtransmission/utils.h> /* tr_free */
|
2007-06-18 03:40:41 +00:00
|
|
|
|
|
|
|
#include "actions.h"
|
2010-12-22 06:11:49 +00:00
|
|
|
#include "conf.h"
|
2008-02-19 03:57:03 +00:00
|
|
|
#include "details.h"
|
2017-04-21 07:40:57 +00:00
|
|
|
#include "favicon.h" /* gtr_get_favicon() */
|
2008-02-10 22:25:42 +00:00
|
|
|
#include "file-list.h"
|
2007-06-06 00:30:13 +00:00
|
|
|
#include "hig.h"
|
2021-10-18 20:22:31 +00:00
|
|
|
#include "tr-core.h"
|
2009-09-25 21:05:59 +00:00
|
|
|
#include "tr-prefs.h"
|
2007-06-06 00:30:13 +00:00
|
|
|
#include "util.h"
|
|
|
|
|
2021-10-20 02:30:50 +00:00
|
|
|
using namespace std::literals;
|
|
|
|
|
2021-10-18 20:22:31 +00:00
|
|
|
namespace
|
2009-02-13 18:23:56 +00:00
|
|
|
{
|
2021-10-18 20:22:31 +00:00
|
|
|
|
|
|
|
auto const TORRENT_ID_KEY = Glib::Quark("tr-torrent-id-key");
|
|
|
|
auto const TEXT_BUFFER_KEY = Glib::Quark("tr-text-buffer-key");
|
|
|
|
auto const URL_ENTRY_KEY = Glib::Quark("tr-url-entry-key");
|
|
|
|
|
|
|
|
} // namespace
|
|
|
|
|
|
|
|
class DetailsDialog::Impl
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
Impl(DetailsDialog& dialog, Glib::RefPtr<TrCore> const& core);
|
|
|
|
~Impl();
|
|
|
|
|
|
|
|
void set_torrents(std::vector<int> const& torrent_ids);
|
|
|
|
|
|
|
|
private:
|
|
|
|
Gtk::Widget* info_page_new();
|
|
|
|
Gtk::Widget* peer_page_new();
|
|
|
|
Gtk::Widget* tracker_page_new();
|
|
|
|
Gtk::Widget* options_page_new();
|
|
|
|
|
|
|
|
void on_details_window_size_allocated(Gtk::Allocation& alloc);
|
|
|
|
|
|
|
|
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 on_add_tracker_response(int response, Gtk::Dialog* dialog);
|
|
|
|
void on_edit_trackers_response(int response, Gtk::Dialog* dialog);
|
|
|
|
|
|
|
|
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 refresh();
|
|
|
|
|
|
|
|
void refreshInfo(std::vector<tr_torrent*> const& torrents);
|
|
|
|
void refreshPeers(std::vector<tr_torrent*> const& torrents);
|
|
|
|
void refreshTracker(std::vector<tr_torrent*> const& torrents);
|
|
|
|
void refreshOptions(std::vector<tr_torrent*> const& torrents);
|
|
|
|
|
|
|
|
void refreshPeerList(std::vector<tr_torrent*> const& torrents);
|
|
|
|
void refreshWebseedList(std::vector<tr_torrent*> const& torrents);
|
|
|
|
|
|
|
|
int tracker_list_get_current_torrent_id() const;
|
|
|
|
tr_torrent* tracker_list_get_current_torrent() const;
|
|
|
|
|
|
|
|
std::vector<tr_torrent*> getTorrents() const;
|
|
|
|
|
|
|
|
private:
|
|
|
|
DetailsDialog& dialog_;
|
|
|
|
|
|
|
|
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_;
|
|
|
|
|
|
|
|
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;
|
|
|
|
|
|
|
|
std::vector<int> ids_;
|
|
|
|
Glib::RefPtr<TrCore> const core_;
|
|
|
|
sigc::connection periodic_refresh_tag_;
|
2008-06-10 02:36:52 +00:00
|
|
|
};
|
|
|
|
|
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
|
|
|
|
{
|
|
|
|
|
|
|
|
void set_togglebutton_if_different(Gtk::ToggleButton* 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();
|
|
|
|
gtr_priority_combo_set_value(*bandwidth_combo_, baseline);
|
|
|
|
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-10-20 02:30:50 +00:00
|
|
|
tr_variantDictAddStr(&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
|
|
|
|
2021-10-18 20:22:31 +00:00
|
|
|
core_->exec(&top);
|
2017-04-19 12:04:45 +00:00
|
|
|
tr_variantFree(&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-10-20 02:30:50 +00:00
|
|
|
tr_variantDictAddStr(&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
|
|
|
}
|
|
|
|
|
2021-10-18 20:22:31 +00:00
|
|
|
core_->exec(&top);
|
2017-04-19 12:04:45 +00:00
|
|
|
tr_variantFree(&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-10-20 02:30:50 +00:00
|
|
|
tr_variantDictAddStr(&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
|
|
|
}
|
|
|
|
|
2021-10-18 20:22:31 +00:00
|
|
|
core_->exec(&top);
|
2017-04-19 12:04:45 +00:00
|
|
|
tr_variantFree(&top);
|
2007-06-06 00:30:13 +00:00
|
|
|
}
|
|
|
|
|
2021-10-18 20:22:31 +00:00
|
|
|
Gtk::Widget* DetailsDialog::Impl::options_page_new()
|
2017-04-19 12:04:45 +00:00
|
|
|
{
|
|
|
|
guint row;
|
|
|
|
|
|
|
|
row = 0;
|
2021-10-18 20:22:31 +00:00
|
|
|
auto* t = Gtk::make_managed<HigWorkarea>();
|
|
|
|
t->add_section_title(row, _("Speed"));
|
|
|
|
|
|
|
|
honor_limits_check_ = t->add_wide_checkbutton(row, _("Honor global _limits"), 0);
|
|
|
|
honor_limits_check_tag_ = honor_limits_check_->signal_toggled().connect(
|
|
|
|
[this]() { torrent_set_bool(TR_KEY_honorsSessionLimits, honor_limits_check_->get_active()); });
|
|
|
|
|
|
|
|
down_limited_check_ = Gtk::make_managed<Gtk::CheckButton>(
|
|
|
|
gtr_sprintf(_("Limit _download speed (%s):"), _(speed_K_str)),
|
|
|
|
true);
|
|
|
|
down_limited_check_->set_active(false);
|
|
|
|
down_limited_check_tag_ = down_limited_check_->signal_toggled().connect(
|
|
|
|
[this]() { torrent_set_bool(TR_KEY_downloadLimited, down_limited_check_->get_active()); });
|
|
|
|
|
|
|
|
down_limit_spin_ = Gtk::make_managed<Gtk::SpinButton>(Gtk::Adjustment::create(0, 0, INT_MAX, 5));
|
|
|
|
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()); });
|
|
|
|
t->add_row_w(row, *down_limited_check_, *down_limit_spin_);
|
|
|
|
|
|
|
|
up_limited_check_ = Gtk::make_managed<Gtk::CheckButton>(gtr_sprintf(_("Limit _upload speed (%s):"), _(speed_K_str)), true);
|
|
|
|
up_limited_check_tag_ = up_limited_check_->signal_toggled().connect(
|
|
|
|
[this]() { torrent_set_bool(TR_KEY_uploadLimited, up_limited_check_->get_active()); });
|
|
|
|
|
|
|
|
up_limit_sping_ = Gtk::make_managed<Gtk::SpinButton>(Gtk::Adjustment::create(0, 0, INT_MAX, 5));
|
|
|
|
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()); });
|
|
|
|
t->add_row_w(row, *up_limited_check_, *up_limit_sping_);
|
|
|
|
|
|
|
|
bandwidth_combo_ = gtr_priority_combo_new();
|
|
|
|
bandwidth_combo_tag_ = bandwidth_combo_->signal_changed().connect(
|
|
|
|
[this]() { torrent_set_int(TR_KEY_bandwidthPriority, gtr_priority_combo_get_value(*bandwidth_combo_)); });
|
|
|
|
t->add_row(row, _("Torrent _priority:"), *bandwidth_combo_);
|
|
|
|
|
|
|
|
t->add_section_divider(row);
|
|
|
|
t->add_section_title(row, _("Seeding Limits"));
|
|
|
|
|
|
|
|
auto* h1 = Gtk::make_managed<Gtk::Box>(Gtk::ORIENTATION_HORIZONTAL, GUI_PAD);
|
|
|
|
ratio_combo_ = gtr_combo_box_new_enum({
|
|
|
|
{ _("Use global settings"), TR_RATIOLIMIT_GLOBAL },
|
|
|
|
{ _("Seed regardless of ratio"), TR_RATIOLIMIT_UNLIMITED },
|
|
|
|
{ _("Stop seeding at ratio:"), TR_RATIOLIMIT_SINGLE },
|
|
|
|
});
|
|
|
|
ratio_combo_tag_ = ratio_combo_->signal_changed().connect(
|
|
|
|
[this]()
|
|
|
|
{
|
|
|
|
torrent_set_int(TR_KEY_seedRatioMode, gtr_combo_box_get_active_enum(*ratio_combo_));
|
|
|
|
refresh();
|
|
|
|
});
|
|
|
|
h1->pack_start(*ratio_combo_, true, true, 0);
|
|
|
|
ratio_spin_ = Gtk::make_managed<Gtk::SpinButton>(Gtk::Adjustment::create(0, 0, 1000, .05));
|
|
|
|
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()); });
|
|
|
|
h1->pack_start(*ratio_spin_, false, false, 0);
|
|
|
|
t->add_row(row, _("_Ratio:"), *h1);
|
|
|
|
|
|
|
|
auto* h2 = Gtk::make_managed<Gtk::Box>(Gtk::ORIENTATION_HORIZONTAL, GUI_PAD);
|
|
|
|
idle_combo_ = gtr_combo_box_new_enum({
|
|
|
|
{ _("Use global settings"), TR_IDLELIMIT_GLOBAL },
|
|
|
|
{ _("Seed regardless of activity"), TR_IDLELIMIT_UNLIMITED },
|
|
|
|
{ _("Stop seeding if idle for N minutes:"), TR_IDLELIMIT_SINGLE },
|
|
|
|
});
|
|
|
|
idle_combo_tag_ = idle_combo_->signal_changed().connect(
|
|
|
|
[this]()
|
|
|
|
{
|
|
|
|
torrent_set_int(TR_KEY_seedIdleMode, gtr_combo_box_get_active_enum(*idle_combo_));
|
|
|
|
refresh();
|
|
|
|
});
|
|
|
|
h2->pack_start(*idle_combo_, true, true, 0);
|
|
|
|
idle_spin_ = Gtk::make_managed<Gtk::SpinButton>(Gtk::Adjustment::create(1, 1, 40320, 5));
|
|
|
|
idle_spin_tag_ = idle_spin_->signal_value_changed().connect(
|
|
|
|
[this]() { torrent_set_int(TR_KEY_seedIdleLimit, idle_spin_->get_value_as_int()); });
|
|
|
|
h2->pack_start(*idle_spin_, false, false, 0);
|
|
|
|
t->add_row(row, _("_Idle:"), *h2);
|
|
|
|
|
|
|
|
t->add_section_divider(row);
|
|
|
|
t->add_section_title(row, _("Peer Connections"));
|
|
|
|
|
|
|
|
max_peers_spin_ = Gtk::make_managed<Gtk::SpinButton>(Gtk::Adjustment::create(1, 1, 3000, 5));
|
|
|
|
t->add_row(row, _("_Maximum peers:"), *max_peers_spin_, max_peers_spin_);
|
|
|
|
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()); });
|
2017-04-19 12:04:45 +00:00
|
|
|
|
|
|
|
return t;
|
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");
|
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
|
|
|
}
|
|
|
|
|
2021-10-18 20:22:31 +00:00
|
|
|
Glib::ustring get_short_date_string(time_t t)
|
2010-05-28 19:43:37 +00:00
|
|
|
{
|
2017-04-19 12:04:45 +00:00
|
|
|
char buf[64];
|
|
|
|
struct tm tm;
|
2010-11-08 19:16:03 +00:00
|
|
|
|
2017-04-30 16:25:26 +00:00
|
|
|
if (t == 0)
|
2017-04-19 12:04:45 +00:00
|
|
|
{
|
2021-10-18 20:22:31 +00:00
|
|
|
return _("N/A");
|
2017-04-19 12:04:45 +00:00
|
|
|
}
|
2010-11-08 19:16:03 +00:00
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
tr_localtime_r(&t, &tm);
|
|
|
|
strftime(buf, sizeof(buf), "%d %b %Y", &tm);
|
2021-10-18 20:22:31 +00:00
|
|
|
return Glib::locale_to_utf8(buf);
|
2020-08-11 18:11:55 +00:00
|
|
|
}
|
2010-05-28 19:43:37 +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
|
|
|
{
|
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;
|
|
|
|
std::vector<tr_info const*> 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
|
|
|
{
|
2021-10-18 20:22:31 +00:00
|
|
|
stats.push_back(tr_torrentStatCached(torrent));
|
|
|
|
infos.push_back(tr_torrentInfo(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-10-18 20:22:31 +00:00
|
|
|
bool const baseline = infos.front()->isPrivate;
|
|
|
|
bool const is_uniform = std::all_of(
|
|
|
|
infos.begin(),
|
|
|
|
infos.end(),
|
|
|
|
[baseline](auto const* info) { return info->isPrivate == 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
|
|
|
|
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
|
|
|
{
|
2021-10-18 20:22:31 +00:00
|
|
|
auto const creator = Glib::ustring(infos.front()->creator != nullptr ? infos.front()->creator : "");
|
|
|
|
time_t const date = infos.front()->dateCreated;
|
|
|
|
auto const datestr = get_short_date_string(date);
|
|
|
|
bool const mixed_creator = std::any_of(
|
|
|
|
infos.begin(),
|
|
|
|
infos.end(),
|
|
|
|
[&creator](auto const* info) { return creator != (info->creator != nullptr ? info->creator : ""); });
|
|
|
|
bool const mixed_date = std::any_of(
|
|
|
|
infos.begin(),
|
|
|
|
infos.end(),
|
|
|
|
[date](auto const* info) { return date != info->dateCreated; });
|
|
|
|
|
|
|
|
bool const empty_creator = creator.empty();
|
|
|
|
bool const empty_date = date == 0;
|
2015-04-22 21:04:49 +00:00
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
if (mixed_date || mixed_creator)
|
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
|
|
|
}
|
2017-04-19 12:04:45 +00:00
|
|
|
else if (empty_date && empty_creator)
|
2015-04-22 21:04:49 +00:00
|
|
|
{
|
2017-04-19 12:04:45 +00:00
|
|
|
str = _("N/A");
|
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
|
|
|
{
|
2017-04-19 12:04:45 +00:00
|
|
|
if (empty_date && !empty_creator)
|
|
|
|
{
|
2021-10-18 20:22:31 +00:00
|
|
|
str = gtr_sprintf(_("Created by %1$s"), creator);
|
2017-04-19 12:04:45 +00:00
|
|
|
}
|
|
|
|
else if (empty_creator && !empty_date)
|
|
|
|
{
|
2021-10-18 20:22:31 +00:00
|
|
|
str = gtr_sprintf(_("Created on %1$s"), datestr);
|
2017-04-19 12:04:45 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2021-10-18 20:22:31 +00:00
|
|
|
str = gtr_sprintf(_("Created by %1$s on %2$s"), creator, datestr);
|
2017-04-19 12:04:45 +00:00
|
|
|
}
|
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-10-18 20:22:31 +00:00
|
|
|
auto const baseline = Glib::ustring(infos.front()->comment != nullptr ? infos.front()->comment : "");
|
|
|
|
bool const is_uniform = std::all_of(
|
|
|
|
infos.begin(),
|
|
|
|
infos.end(),
|
|
|
|
[&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
|
|
|
|
{
|
2021-10-18 20:22:31 +00:00
|
|
|
str = tr_strltime(time(nullptr) - 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
|
|
|
{
|
2021-10-18 20:22:31 +00:00
|
|
|
int const baseline = stats.front()->eta;
|
|
|
|
bool const is_uniform = std::all_of(
|
|
|
|
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
|
|
|
|
{
|
2021-10-18 20:22:31 +00:00
|
|
|
str = tr_strltime(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 */
|
|
|
|
{
|
|
|
|
uint64_t size = 0;
|
|
|
|
int pieces = 0;
|
|
|
|
int32_t pieceSize = 0;
|
|
|
|
|
2021-10-18 20:22:31 +00:00
|
|
|
for (auto const* const info : infos)
|
2017-04-19 12:04:45 +00:00
|
|
|
{
|
2021-10-18 20:22:31 +00:00
|
|
|
size += info->totalSize;
|
|
|
|
pieces += info->pieceCount;
|
2017-04-19 12:04:45 +00:00
|
|
|
|
2017-04-30 16:25:26 +00:00
|
|
|
if (pieceSize == 0)
|
2017-04-19 12:04:45 +00:00
|
|
|
{
|
2021-10-18 20:22:31 +00:00
|
|
|
pieceSize = info->pieceSize;
|
2017-04-19 12:04:45 +00:00
|
|
|
}
|
2021-10-18 20:22:31 +00:00
|
|
|
else if (pieceSize != (int)info->pieceSize)
|
2017-04-19 12:04:45 +00:00
|
|
|
{
|
|
|
|
pieceSize = -1;
|
|
|
|
}
|
|
|
|
}
|
2013-01-04 19:45:39 +00:00
|
|
|
|
2021-10-18 20:22:31 +00:00
|
|
|
auto const sizebuf = tr_strlsize(size);
|
2013-01-04 19:45:39 +00:00
|
|
|
|
2017-04-30 16:25:26 +00:00
|
|
|
if (size == 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 if (pieceSize >= 0)
|
|
|
|
{
|
|
|
|
char piecebuf[128];
|
|
|
|
tr_formatter_mem_B(piecebuf, pieceSize, sizeof(piecebuf));
|
2021-10-18 20:22:31 +00:00
|
|
|
str = gtr_sprintf(
|
2021-08-15 09:41:48 +00:00
|
|
|
ngettext("%1$s (%2$'d piece @ %3$s)", "%1$s (%2$'d pieces @ %3$s)", pieces),
|
|
|
|
sizebuf,
|
|
|
|
pieces,
|
|
|
|
piecebuf);
|
2017-04-19 12:04:45 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2021-10-18 20:22:31 +00:00
|
|
|
str = gtr_sprintf(ngettext("%1$s (%2$'d piece)", "%1$s (%2$'d pieces)", pieces), sizebuf, pieces);
|
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
|
|
|
|
2021-10-18 20:22:31 +00:00
|
|
|
auto const avail = tr_strlpercent(d);
|
|
|
|
auto const buf2 = tr_strlpercent(ratio);
|
|
|
|
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
|
|
|
{
|
2021-10-18 20:22:31 +00:00
|
|
|
str = gtr_sprintf(_("%1$s (%2$s%%)"), total, 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
|
|
|
{
|
2021-10-18 20:22:31 +00:00
|
|
|
str = gtr_sprintf(_("%1$s (%2$s%% of %3$s%% Available)"), total, buf2, avail);
|
2017-04-19 12:04:45 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2021-10-18 20:22:31 +00:00
|
|
|
str = gtr_sprintf(_("%1$s (%2$s%% of %3$s%% Available); %4$s Unverified"), total, buf2, avail, 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
|
|
|
|
|
|
|
/* 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
|
|
|
{
|
2017-05-01 15:46:41 +00:00
|
|
|
uint64_t d = 0;
|
|
|
|
uint64_t f = 0;
|
2009-08-10 20:04:08 +00:00
|
|
|
|
2021-10-18 20:22:31 +00:00
|
|
|
for (auto const* const st : stats)
|
2013-01-04 19:45:39 +00:00
|
|
|
{
|
2021-10-18 20:22:31 +00:00
|
|
|
d += st->downloadedEver;
|
|
|
|
f += st->corruptEver;
|
2009-04-24 01:37:04 +00:00
|
|
|
}
|
2013-01-04 19:45:39 +00:00
|
|
|
|
2021-10-18 20:22:31 +00:00
|
|
|
auto const dbuf = tr_strlsize(d);
|
|
|
|
auto const fbuf = tr_strlsize(f);
|
2013-01-04 19:45:39 +00:00
|
|
|
|
2017-04-30 16:25:26 +00:00
|
|
|
if (f != 0)
|
2017-04-19 12:04:45 +00:00
|
|
|
{
|
2021-10-18 20:22:31 +00:00
|
|
|
str = gtr_sprintf(_("%1$s (+%2$s corrupt)"), dbuf, fbuf);
|
2017-04-19 12:04:45 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2021-10-18 20:22:31 +00:00
|
|
|
str = dbuf;
|
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
|
|
|
{
|
2017-04-19 12:04:45 +00:00
|
|
|
uint64_t up = 0;
|
|
|
|
uint64_t down = 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
|
|
|
{
|
2021-10-18 20:22:31 +00:00
|
|
|
up += st->uploadedEver;
|
|
|
|
down += st->downloadedEver;
|
2013-01-04 19:45:39 +00:00
|
|
|
}
|
|
|
|
|
2021-10-18 20:22:31 +00:00
|
|
|
str = gtr_sprintf(_("%s (Ratio: %s)"), tr_strlsize(up), tr_strlratio(tr_getRatio(up, down)));
|
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-10-18 20:22:31 +00:00
|
|
|
str = infos.front()->hashString;
|
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
|
|
|
}
|
2017-04-19 12:04:45 +00:00
|
|
|
else
|
2013-01-04 19:45:39 +00:00
|
|
|
{
|
2021-10-06 16:32:17 +00:00
|
|
|
time_t const period = time(nullptr) - latest;
|
2017-04-19 12:04:45 +00:00
|
|
|
|
|
|
|
if (period < 5)
|
2013-01-04 19:45:39 +00:00
|
|
|
{
|
2021-10-18 20:22:31 +00:00
|
|
|
str = _("Active now");
|
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-10-18 20:22:31 +00:00
|
|
|
str = gtr_sprintf(_("%1$s ago"), tr_strltime(period));
|
2013-01-04 19:45:39 +00:00
|
|
|
}
|
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
|
|
|
}
|
|
|
|
|
2021-10-18 20:22:31 +00:00
|
|
|
Gtk::Widget* DetailsDialog::Impl::info_page_new()
|
2007-06-06 00:30:13 +00:00
|
|
|
{
|
2017-04-19 12:04:45 +00:00
|
|
|
guint row = 0;
|
2021-10-18 20:22:31 +00:00
|
|
|
auto* t = Gtk::make_managed<HigWorkarea>();
|
2013-01-04 19:45:39 +00:00
|
|
|
|
2021-10-18 20:22:31 +00:00
|
|
|
t->add_section_title(row, _("Activity"));
|
2013-01-04 19:45:39 +00:00
|
|
|
|
|
|
|
/* size */
|
2021-10-18 20:22:31 +00:00
|
|
|
size_lb_ = Gtk::make_managed<Gtk::Label>();
|
|
|
|
size_lb_->set_single_line_mode(true);
|
|
|
|
t->add_row(row, _("Torrent size:"), *size_lb_);
|
2013-01-04 19:45:39 +00:00
|
|
|
|
|
|
|
/* have */
|
2021-10-18 20:22:31 +00:00
|
|
|
have_lb_ = Gtk::make_managed<Gtk::Label>();
|
|
|
|
have_lb_->set_single_line_mode(true);
|
|
|
|
t->add_row(row, _("Have:"), *have_lb_);
|
2013-01-04 19:45:39 +00:00
|
|
|
|
|
|
|
/* uploaded */
|
2021-10-18 20:22:31 +00:00
|
|
|
ul_lb_ = Gtk::make_managed<Gtk::Label>();
|
|
|
|
ul_lb_->set_single_line_mode(true);
|
|
|
|
t->add_row(row, _("Uploaded:"), *ul_lb_);
|
2013-01-04 19:45:39 +00:00
|
|
|
|
2014-01-20 23:56:06 +00:00
|
|
|
/* downloaded */
|
2021-10-18 20:22:31 +00:00
|
|
|
dl_lb_ = Gtk::make_managed<Gtk::Label>();
|
|
|
|
dl_lb_->set_single_line_mode(true);
|
|
|
|
t->add_row(row, _("Downloaded:"), *dl_lb_);
|
2014-01-20 23:56:06 +00:00
|
|
|
|
2013-01-04 19:45:39 +00:00
|
|
|
/* state */
|
2021-10-18 20:22:31 +00:00
|
|
|
state_lb_ = Gtk::make_managed<Gtk::Label>();
|
|
|
|
state_lb_->set_single_line_mode(true);
|
|
|
|
t->add_row(row, _("State:"), *state_lb_);
|
2013-01-04 19:45:39 +00:00
|
|
|
|
|
|
|
/* running for */
|
2021-10-18 20:22:31 +00:00
|
|
|
date_started_lb_ = Gtk::make_managed<Gtk::Label>();
|
|
|
|
date_started_lb_->set_single_line_mode(true);
|
|
|
|
t->add_row(row, _("Running time:"), *date_started_lb_);
|
2013-01-04 19:45:39 +00:00
|
|
|
|
|
|
|
/* eta */
|
2021-10-18 20:22:31 +00:00
|
|
|
eta_lb_ = Gtk::make_managed<Gtk::Label>();
|
|
|
|
eta_lb_->set_single_line_mode(true);
|
|
|
|
t->add_row(row, _("Remaining time:"), *eta_lb_);
|
2013-01-04 19:45:39 +00:00
|
|
|
|
|
|
|
/* last activity */
|
2021-10-18 20:22:31 +00:00
|
|
|
last_activity_lb_ = Gtk::make_managed<Gtk::Label>();
|
|
|
|
last_activity_lb_->set_single_line_mode(true);
|
|
|
|
t->add_row(row, _("Last activity:"), *last_activity_lb_);
|
2013-01-04 19:45:39 +00:00
|
|
|
|
|
|
|
/* error */
|
2021-10-18 20:22:31 +00:00
|
|
|
error_lb_ = Gtk::make_managed<Gtk::Label>();
|
|
|
|
error_lb_->set_selectable(true);
|
|
|
|
error_lb_->set_ellipsize(Pango::ELLIPSIZE_END);
|
|
|
|
t->add_row(row, _("Error:"), *error_lb_);
|
2013-01-04 19:45:39 +00:00
|
|
|
|
2021-10-18 20:22:31 +00:00
|
|
|
t->add_section_divider(row);
|
|
|
|
t->add_section_title(row, _("Details"));
|
2013-01-04 19:45:39 +00:00
|
|
|
|
|
|
|
/* destination */
|
2021-10-18 20:22:31 +00:00
|
|
|
destination_lb_ = Gtk::make_managed<Gtk::Label>();
|
|
|
|
destination_lb_->set_selectable(true);
|
|
|
|
destination_lb_->set_ellipsize(Pango::ELLIPSIZE_END);
|
|
|
|
t->add_row(row, _("Location:"), *destination_lb_);
|
2013-01-04 19:45:39 +00:00
|
|
|
|
|
|
|
/* hash */
|
2021-10-18 20:22:31 +00:00
|
|
|
hash_lb_ = Gtk::make_managed<Gtk::Label>();
|
|
|
|
hash_lb_->set_selectable(true);
|
|
|
|
hash_lb_->set_ellipsize(Pango::ELLIPSIZE_END);
|
|
|
|
t->add_row(row, _("Hash:"), *hash_lb_);
|
2013-01-04 19:45:39 +00:00
|
|
|
|
|
|
|
/* privacy */
|
2021-10-18 20:22:31 +00:00
|
|
|
privacy_lb_ = Gtk::make_managed<Gtk::Label>();
|
|
|
|
privacy_lb_->set_single_line_mode(true);
|
|
|
|
t->add_row(row, _("Privacy:"), *privacy_lb_);
|
2013-01-04 19:45:39 +00:00
|
|
|
|
|
|
|
/* origins */
|
2021-10-18 20:22:31 +00:00
|
|
|
origin_lb_ = Gtk::make_managed<Gtk::Label>();
|
|
|
|
origin_lb_->set_selectable(true);
|
|
|
|
origin_lb_->set_ellipsize(Pango::ELLIPSIZE_END);
|
|
|
|
t->add_row(row, _("Origin:"), *origin_lb_);
|
2013-01-04 19:45:39 +00:00
|
|
|
|
|
|
|
/* comment */
|
2021-10-18 20:22:31 +00:00
|
|
|
comment_buffer_ = Gtk::TextBuffer::create();
|
|
|
|
auto* tw = Gtk::make_managed<Gtk::TextView>(comment_buffer_);
|
|
|
|
tw->set_wrap_mode(Gtk::WRAP_WORD);
|
|
|
|
tw->set_editable(false);
|
|
|
|
auto* sw = Gtk::make_managed<Gtk::ScrolledWindow>();
|
|
|
|
sw->set_size_request(350, 36);
|
|
|
|
sw->set_policy(Gtk::POLICY_AUTOMATIC, Gtk::POLICY_AUTOMATIC);
|
|
|
|
sw->add(*tw);
|
|
|
|
auto* fr = Gtk::make_managed<Gtk::Frame>();
|
|
|
|
fr->set_shadow_type(Gtk::SHADOW_IN);
|
|
|
|
fr->add(*sw);
|
|
|
|
auto* w = t->add_tall_row(row, _("Comment:"), *fr);
|
|
|
|
w->set_halign(Gtk::ALIGN_START);
|
|
|
|
w->set_valign(Gtk::ALIGN_START);
|
|
|
|
|
|
|
|
t->add_section_divider(row);
|
2017-04-19 12:04:45 +00:00
|
|
|
return t;
|
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:
|
|
|
|
WebseedModelColumns()
|
2009-02-13 18:23:56 +00:00
|
|
|
{
|
2021-10-18 20:22:31 +00:00
|
|
|
add(key);
|
|
|
|
add(was_updated);
|
|
|
|
add(url);
|
|
|
|
add(download_rate_double);
|
|
|
|
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;
|
|
|
|
Gtk::TreeModelColumn<double> download_rate_double;
|
|
|
|
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:
|
|
|
|
PeerModelColumns()
|
|
|
|
{
|
|
|
|
add(key);
|
|
|
|
add(was_updated);
|
|
|
|
add(address);
|
|
|
|
add(address_collated);
|
|
|
|
add(download_rate_double);
|
|
|
|
add(download_rate_string);
|
|
|
|
add(upload_rate_double);
|
|
|
|
add(upload_rate_string);
|
|
|
|
add(client);
|
|
|
|
add(progress);
|
|
|
|
add(upload_request_count_int);
|
|
|
|
add(upload_request_count_string);
|
|
|
|
add(download_request_count_int);
|
|
|
|
add(download_request_count_string);
|
|
|
|
add(blocks_downloaded_count_int);
|
|
|
|
add(blocks_downloaded_count_string);
|
|
|
|
add(blocks_uploaded_count_int);
|
|
|
|
add(blocks_uploaded_count_string);
|
|
|
|
add(reqs_cancelled_by_client_count_int);
|
|
|
|
add(reqs_cancelled_by_client_count_string);
|
|
|
|
add(reqs_cancelled_by_peer_count_int);
|
|
|
|
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;
|
|
|
|
Gtk::TreeModelColumn<double> download_rate_double;
|
|
|
|
Gtk::TreeModelColumn<Glib::ustring> download_rate_string;
|
|
|
|
Gtk::TreeModelColumn<double> upload_rate_double;
|
|
|
|
Gtk::TreeModelColumn<Glib::ustring> upload_rate_string;
|
|
|
|
Gtk::TreeModelColumn<Glib::ustring> client;
|
|
|
|
Gtk::TreeModelColumn<int> progress;
|
|
|
|
Gtk::TreeModelColumn<int> upload_request_count_int;
|
|
|
|
Gtk::TreeModelColumn<Glib::ustring> upload_request_count_string;
|
|
|
|
Gtk::TreeModelColumn<int> download_request_count_int;
|
|
|
|
Gtk::TreeModelColumn<Glib::ustring> download_request_count_string;
|
|
|
|
Gtk::TreeModelColumn<int> blocks_downloaded_count_int;
|
|
|
|
Gtk::TreeModelColumn<Glib::ustring> blocks_downloaded_count_string;
|
|
|
|
Gtk::TreeModelColumn<int> blocks_uploaded_count_int;
|
|
|
|
Gtk::TreeModelColumn<Glib::ustring> blocks_uploaded_count_string;
|
|
|
|
Gtk::TreeModelColumn<int> reqs_cancelled_by_client_count_int;
|
|
|
|
Gtk::TreeModelColumn<Glib::ustring> reqs_cancelled_by_client_count_string;
|
|
|
|
Gtk::TreeModelColumn<int> reqs_cancelled_by_peer_count_int;
|
|
|
|
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
|
|
|
|
2021-10-18 20:22:31 +00:00
|
|
|
void initPeerRow(Gtk::TreeIter const& iter, std::string const& key, std::string const& torrentName, 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 = "";
|
|
|
|
}
|
|
|
|
|
2020-10-31 21:23:43 +00:00
|
|
|
int q[4];
|
2021-10-18 20:22:31 +00:00
|
|
|
Glib::ustring collated_name;
|
2017-04-19 12:04:45 +00:00
|
|
|
if (sscanf(peer->addr, "%d.%d.%d.%d", q, q + 1, q + 2, q + 3) != 4)
|
|
|
|
{
|
2021-10-18 20:22:31 +00:00
|
|
|
collated_name = peer->addr;
|
2017-04-19 12:04:45 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2021-10-18 20:22:31 +00:00
|
|
|
collated_name = gtr_sprintf("%03d.%03d.%03d.%03d", q[0], q[1], q[2], q[3]);
|
2017-04-19 12:04:45 +00:00
|
|
|
}
|
|
|
|
|
2021-10-18 20:22:31 +00:00
|
|
|
(*iter)[peer_cols.address] = peer->addr;
|
|
|
|
(*iter)[peer_cols.address_collated] = collated_name;
|
|
|
|
(*iter)[peer_cols.client] = client;
|
|
|
|
(*iter)[peer_cols.encryption_stock_id] = peer->isEncrypted ? "transmission-lock" : "";
|
|
|
|
(*iter)[peer_cols.key] = key;
|
|
|
|
(*iter)[peer_cols.torrent_name] = torrentName;
|
2007-06-06 00:30:13 +00:00
|
|
|
}
|
|
|
|
|
2021-10-18 20:22:31 +00:00
|
|
|
void refreshPeerRow(Gtk::TreeIter const& iter, tr_peer_stat const* peer)
|
2017-04-19 12:04:45 +00:00
|
|
|
{
|
|
|
|
char up_speed[64] = { '\0' };
|
|
|
|
char down_speed[64] = { '\0' };
|
2021-10-18 20:22:31 +00:00
|
|
|
std::string up_count;
|
|
|
|
std::string down_count;
|
|
|
|
std::string blocks_to_peer;
|
|
|
|
std::string blocks_to_client;
|
|
|
|
std::string cancelled_by_peer;
|
|
|
|
std::string cancelled_by_client;
|
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
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
if (peer->rateToPeer_KBps > 0.01)
|
|
|
|
{
|
|
|
|
tr_formatter_speed_KBps(up_speed, peer->rateToPeer_KBps, sizeof(up_speed));
|
|
|
|
}
|
|
|
|
|
|
|
|
if (peer->rateToClient_KBps > 0)
|
|
|
|
{
|
|
|
|
tr_formatter_speed_KBps(down_speed, peer->rateToClient_KBps, sizeof(down_speed));
|
|
|
|
}
|
|
|
|
|
|
|
|
if (peer->pendingReqsToPeer > 0)
|
|
|
|
{
|
2021-10-18 20:22:31 +00:00
|
|
|
down_count = std::to_string(peer->pendingReqsToPeer);
|
2017-04-19 12:04:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (peer->pendingReqsToClient > 0)
|
|
|
|
{
|
2021-10-18 20:22:31 +00:00
|
|
|
up_count = std::to_string(peer->pendingReqsToClient);
|
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);
|
|
|
|
}
|
|
|
|
|
|
|
|
(*iter)[peer_cols.progress] = (int)(100.0 * peer->progress);
|
|
|
|
(*iter)[peer_cols.upload_request_count_int] = peer->pendingReqsToClient;
|
|
|
|
(*iter)[peer_cols.upload_request_count_string] = up_count;
|
|
|
|
(*iter)[peer_cols.download_request_count_int] = peer->pendingReqsToPeer;
|
|
|
|
(*iter)[peer_cols.download_request_count_string] = down_count;
|
|
|
|
(*iter)[peer_cols.download_rate_double] = peer->rateToClient_KBps;
|
|
|
|
(*iter)[peer_cols.download_rate_string] = down_speed;
|
|
|
|
(*iter)[peer_cols.upload_rate_double] = peer->rateToPeer_KBps;
|
|
|
|
(*iter)[peer_cols.upload_rate_string] = up_speed;
|
|
|
|
(*iter)[peer_cols.flags] = peer->flagStr;
|
|
|
|
(*iter)[peer_cols.was_updated] = true;
|
|
|
|
(*iter)[peer_cols.blocks_downloaded_count_int] = (int)peer->blocksToClient;
|
|
|
|
(*iter)[peer_cols.blocks_downloaded_count_string] = blocks_to_client;
|
|
|
|
(*iter)[peer_cols.blocks_uploaded_count_int] = (int)peer->blocksToPeer;
|
|
|
|
(*iter)[peer_cols.blocks_uploaded_count_string] = blocks_to_peer;
|
|
|
|
(*iter)[peer_cols.reqs_cancelled_by_client_count_int] = (int)peer->cancelsToPeer;
|
|
|
|
(*iter)[peer_cols.reqs_cancelled_by_client_count_string] = cancelled_by_client;
|
|
|
|
(*iter)[peer_cols.reqs_cancelled_by_peer_count_int] = (int)peer->cancelsToClient;
|
|
|
|
(*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_;
|
|
|
|
auto& 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;
|
|
|
|
std::vector<int> 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
|
|
|
{
|
2021-10-18 20:22:31 +00:00
|
|
|
int count = 0;
|
|
|
|
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 */
|
2021-10-18 20:22:31 +00:00
|
|
|
for (auto const& 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
|
|
|
|
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
|
|
|
|
2017-05-13 22:38:31 +00:00
|
|
|
for (int 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];
|
|
|
|
auto const key = gtr_sprintf("%d.%s", tr_torrentId(tor), s->addr);
|
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);
|
|
|
|
hash.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
|
|
|
|
2017-05-13 22:38:31 +00:00
|
|
|
for (int 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];
|
|
|
|
auto const key = gtr_sprintf("%d.%s", tr_torrentId(tor), s->addr);
|
|
|
|
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
|
|
|
{
|
2017-04-19 12:04:45 +00:00
|
|
|
int total = 0;
|
2021-10-18 20:22:31 +00:00
|
|
|
auto& hash = webseed_hash_;
|
|
|
|
auto& store = webseed_store_;
|
2013-01-04 19:45:39 +00:00
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
/* step 1: mark all webseeds as not-updated */
|
2021-10-18 20:22:31 +00:00
|
|
|
for (auto const& 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-10-18 20:22:31 +00:00
|
|
|
auto const* inf = tr_torrentInfo(tor);
|
2013-01-04 19:45:39 +00:00
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
total += inf->webseedCount;
|
2013-01-04 19:45:39 +00:00
|
|
|
|
2017-05-13 22:38:31 +00:00
|
|
|
for (unsigned int j = 0; j < inf->webseedCount; ++j)
|
2013-01-04 19:45:39 +00:00
|
|
|
{
|
2017-04-20 16:02:19 +00:00
|
|
|
char const* url = inf->webseeds[j];
|
2021-10-18 20:22:31 +00:00
|
|
|
auto const key = gtr_sprintf("%d.%s", tr_torrentId(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;
|
|
|
|
hash.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-10-18 20:22:31 +00:00
|
|
|
auto const* inf = tr_torrentInfo(tor);
|
2017-04-19 12:04:45 +00:00
|
|
|
double* speeds_KBps = tr_torrentWebSpeeds_KBps(tor);
|
2013-01-04 19:45:39 +00:00
|
|
|
|
2017-05-13 22:38:31 +00:00
|
|
|
for (unsigned int j = 0; j < inf->webseedCount; ++j)
|
2013-01-04 19:45:39 +00:00
|
|
|
{
|
2020-11-08 19:54:40 +00:00
|
|
|
char const* const url = inf->webseeds[j];
|
2021-10-18 20:22:31 +00:00
|
|
|
auto const key = gtr_sprintf("%d.%s", tr_torrentId(tor), url);
|
|
|
|
auto const iter = store->get_iter(hash.at(key).get_path());
|
2017-04-19 12:04:45 +00:00
|
|
|
|
2020-11-08 19:54:40 +00:00
|
|
|
char buf[128] = { 0 };
|
2017-04-19 12:04:45 +00:00
|
|
|
if (speeds_KBps[j] > 0)
|
|
|
|
{
|
|
|
|
tr_formatter_speed_KBps(buf, speeds_KBps[j], sizeof(buf));
|
|
|
|
}
|
2013-01-04 19:45:39 +00:00
|
|
|
|
2021-10-18 20:22:31 +00:00
|
|
|
(*iter)[webseed_cols.download_rate_double] = speeds_KBps[j];
|
|
|
|
(*iter)[webseed_cols.download_rate_string] = buf;
|
|
|
|
(*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
|
|
|
tr_free(speeds_KBps);
|
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-10-18 20:22:31 +00:00
|
|
|
webseed_view_->set_visible(total > 0);
|
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
|
|
|
|
2021-10-18 20:22:31 +00:00
|
|
|
for (auto 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;
|
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;
|
|
|
|
Gtk::TreeViewColumn* c;
|
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);
|
2017-04-19 12:04:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (more)
|
|
|
|
{
|
2021-10-18 20:22:31 +00:00
|
|
|
view_columns.push_back(&peer_cols.blocks_downloaded_count_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.blocks_uploaded_count_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.reqs_cancelled_by_client_count_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.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>();
|
|
|
|
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);
|
|
|
|
c->add_attribute(r->property_stock_id(), *col);
|
|
|
|
c->set_sizing(Gtk::TREE_VIEW_COLUMN_FIXED);
|
|
|
|
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);
|
|
|
|
sort_col = &peer_cols.download_request_count_int;
|
|
|
|
}
|
|
|
|
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);
|
|
|
|
sort_col = &peer_cols.upload_request_count_int;
|
|
|
|
}
|
|
|
|
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);
|
|
|
|
sort_col = &peer_cols.blocks_downloaded_count_int;
|
|
|
|
}
|
|
|
|
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);
|
|
|
|
sort_col = &peer_cols.blocks_uploaded_count_int;
|
|
|
|
}
|
|
|
|
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);
|
|
|
|
sort_col = &peer_cols.reqs_cancelled_by_client_count_int;
|
|
|
|
}
|
|
|
|
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);
|
|
|
|
sort_col = &peer_cols.reqs_cancelled_by_peer_count_int;
|
|
|
|
}
|
|
|
|
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);
|
|
|
|
sort_col = &peer_cols.download_rate_double;
|
|
|
|
}
|
|
|
|
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);
|
|
|
|
sort_col = &peer_cols.upload_rate_double;
|
|
|
|
}
|
|
|
|
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
|
|
|
|
{
|
2017-04-19 12:04:45 +00:00
|
|
|
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
|
|
|
}
|
|
|
|
|
2021-10-18 20:22:31 +00:00
|
|
|
Gtk::Widget* DetailsDialog::Impl::peer_page_new()
|
2017-04-19 12:04:45 +00:00
|
|
|
{
|
|
|
|
/* webseeds */
|
|
|
|
|
2021-10-18 20:22:31 +00:00
|
|
|
webseed_store_ = Gtk::ListStore::create(webseed_cols);
|
|
|
|
auto* v = Gtk::make_managed<Gtk::TreeView>(webseed_store_);
|
|
|
|
v->signal_button_release_event().connect([v](GdkEventButton* event) { return on_tree_view_button_released(v, event); });
|
|
|
|
|
|
|
|
{
|
|
|
|
auto* r = Gtk::make_managed<Gtk::CellRendererText>();
|
|
|
|
r->property_ellipsize() = Pango::ELLIPSIZE_END;
|
|
|
|
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);
|
|
|
|
c->set_sort_column(webseed_cols.download_rate_double);
|
|
|
|
v->append_column(*c);
|
|
|
|
}
|
|
|
|
|
|
|
|
webseed_view_ = Gtk::make_managed<Gtk::ScrolledWindow>();
|
|
|
|
webseed_view_->set_policy(Gtk::POLICY_AUTOMATIC, Gtk::POLICY_AUTOMATIC);
|
|
|
|
webseed_view_->set_shadow_type(Gtk::SHADOW_IN);
|
|
|
|
webseed_view_->add(*v);
|
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_);
|
|
|
|
m->set_sort_column(peer_cols.progress, Gtk::SORT_DESCENDING);
|
|
|
|
peer_view_ = Gtk::make_managed<Gtk::TreeView>(m);
|
|
|
|
peer_view_->set_rules_hint(true);
|
|
|
|
peer_view_->set_has_tooltip(true);
|
|
|
|
|
|
|
|
peer_view_->signal_query_tooltip().connect(sigc::mem_fun(this, &Impl::onPeerViewQueryTooltip));
|
|
|
|
peer_view_->signal_button_release_event().connect([this](GdkEventButton* event)
|
|
|
|
{ return on_tree_view_button_released(peer_view_, event); });
|
|
|
|
|
|
|
|
setPeerViewColumns(peer_view_);
|
|
|
|
|
|
|
|
auto* sw = Gtk::make_managed<Gtk::ScrolledWindow>();
|
|
|
|
sw->set_policy(Gtk::POLICY_AUTOMATIC, Gtk::POLICY_AUTOMATIC);
|
|
|
|
sw->set_shadow_type(Gtk::SHADOW_IN);
|
|
|
|
sw->add(*peer_view_);
|
|
|
|
|
|
|
|
auto* vbox = Gtk::make_managed<Gtk::Box>(Gtk::ORIENTATION_VERTICAL, GUI_PAD);
|
|
|
|
vbox->set_border_width(GUI_PAD_BIG);
|
|
|
|
|
|
|
|
auto* v2 = Gtk::make_managed<Gtk::Paned>(Gtk::ORIENTATION_VERTICAL);
|
|
|
|
v2->add(*webseed_view_);
|
|
|
|
v2->add(*sw);
|
|
|
|
vbox->pack_start(*v2, true, true);
|
|
|
|
|
|
|
|
more_peer_details_check_ = Gtk::make_managed<Gtk::CheckButton>(_("Show _more details"), true);
|
|
|
|
more_peer_details_check_->set_active(gtr_pref_flag_get(TR_KEY_show_extra_peer_details));
|
|
|
|
more_peer_details_check_->signal_toggled().connect(sigc::mem_fun(this, &Impl::onMorePeerInfoToggled));
|
|
|
|
vbox->pack_start(*more_peer_details_check_, false, false);
|
|
|
|
|
|
|
|
return vbox;
|
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
|
|
|
|
{
|
|
|
|
|
|
|
|
char const err_markup_begin[] = "<span color=\"red\">";
|
|
|
|
char const err_markup_end[] = "</span>";
|
|
|
|
char const timeout_markup_begin[] = "<span color=\"#246\">";
|
|
|
|
char const timeout_markup_end[] = "</span>";
|
|
|
|
char const success_markup_begin[] = "<span color=\"#080\">";
|
|
|
|
char const success_markup_end[] = "</span>";
|
2020-11-08 19:54:40 +00:00
|
|
|
|
|
|
|
// if it's been longer than a minute, don't bother showing the seconds
|
2021-10-18 20:22:31 +00:00
|
|
|
Glib::ustring tr_strltime_rounded(time_t t)
|
2009-04-24 01:37:04 +00:00
|
|
|
{
|
2017-04-19 12:04:45 +00:00
|
|
|
if (t > 60)
|
|
|
|
{
|
|
|
|
t -= (t % 60);
|
|
|
|
}
|
|
|
|
|
2021-10-18 20:22:31 +00:00
|
|
|
return tr_strltime(t);
|
2009-09-25 21:05:59 +00:00
|
|
|
}
|
2009-03-04 19:52:57 +00:00
|
|
|
|
2021-10-18 20:22:31 +00:00
|
|
|
void appendAnnounceInfo(tr_tracker_stat const* const st, time_t const now, std::ostream& gstr)
|
2017-04-19 12:04:45 +00:00
|
|
|
{
|
2020-11-08 19:54:40 +00:00
|
|
|
if (st->hasAnnounced && st->announceState != TR_TRACKER_INACTIVE)
|
2017-04-19 12:04:45 +00:00
|
|
|
{
|
2021-10-18 20:22:31 +00:00
|
|
|
gstr << '\n';
|
|
|
|
auto const timebuf = tr_strltime_rounded(now - st->lastAnnounceTime);
|
2017-04-19 12:04:45 +00:00
|
|
|
|
2020-11-08 19:54:40 +00:00
|
|
|
if (st->lastAnnounceSucceeded)
|
|
|
|
{
|
2021-10-18 20:22:31 +00:00
|
|
|
gstr << gtr_sprintf(
|
2021-08-15 09:41:48 +00:00
|
|
|
_("Got a list of %1$s%2$'d peers%3$s %4$s ago"),
|
|
|
|
success_markup_begin,
|
|
|
|
st->lastAnnouncePeerCount,
|
|
|
|
success_markup_end,
|
|
|
|
timebuf);
|
2020-11-08 19:54:40 +00:00
|
|
|
}
|
|
|
|
else if (st->lastAnnounceTimedOut)
|
2017-04-19 12:04:45 +00:00
|
|
|
{
|
2021-10-18 20:22:31 +00:00
|
|
|
gstr << gtr_sprintf(
|
2021-08-15 09:41:48 +00:00
|
|
|
_("Peer list request %1$stimed out%2$s %3$s ago; will retry"),
|
|
|
|
timeout_markup_begin,
|
|
|
|
timeout_markup_end,
|
|
|
|
timebuf);
|
2017-04-19 12:04:45 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2021-10-18 20:22:31 +00:00
|
|
|
gstr << gtr_sprintf(
|
2021-08-15 09:41:48 +00:00
|
|
|
_("Got an error %1$s\"%2$s\"%3$s %4$s ago"),
|
|
|
|
err_markup_begin,
|
|
|
|
st->lastAnnounceResult,
|
|
|
|
err_markup_end,
|
|
|
|
timebuf);
|
2017-04-19 12:04:45 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-11-08 19:54:40 +00:00
|
|
|
switch (st->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';
|
|
|
|
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';
|
|
|
|
gstr << gtr_sprintf(_("Asking for more peers in %s"), tr_strltime_rounded(st->nextAnnounceTime - now));
|
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';
|
|
|
|
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';
|
|
|
|
gstr << gtr_sprintf(
|
|
|
|
_("Asking for more peers now… <small>%s</small>"),
|
|
|
|
tr_strltime_rounded(now - st->lastAnnounceStartTime));
|
2020-11-08 19:54:40 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2013-01-04 19:45:39 +00:00
|
|
|
|
2021-10-18 20:22:31 +00:00
|
|
|
void appendScrapeInfo(tr_tracker_stat const* const st, time_t const now, std::ostream& gstr)
|
2020-11-08 19:54:40 +00:00
|
|
|
{
|
|
|
|
if (st->hasScraped)
|
|
|
|
{
|
2021-10-18 20:22:31 +00:00
|
|
|
gstr << '\n';
|
|
|
|
auto const timebuf = tr_strltime_rounded(now - st->lastScrapeTime);
|
2009-10-10 00:17:00 +00:00
|
|
|
|
2020-11-08 19:54:40 +00:00
|
|
|
if (st->lastScrapeSucceeded)
|
2009-10-10 00:17:00 +00:00
|
|
|
{
|
2021-10-18 20:22:31 +00:00
|
|
|
gstr << gtr_sprintf(
|
2021-08-15 09:41:48 +00:00
|
|
|
_("Tracker had %s%'d seeders and %'d leechers%s %s ago"),
|
|
|
|
success_markup_begin,
|
|
|
|
st->seederCount,
|
|
|
|
st->leecherCount,
|
|
|
|
success_markup_end,
|
|
|
|
timebuf);
|
2020-11-08 19:54:40 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2021-10-18 20:22:31 +00:00
|
|
|
gstr << gtr_sprintf(
|
2021-08-15 09:41:48 +00:00
|
|
|
_("Got a scrape error \"%s%s%s\" %s ago"),
|
|
|
|
err_markup_begin,
|
|
|
|
st->lastScrapeResult,
|
|
|
|
err_markup_end,
|
|
|
|
timebuf);
|
2020-11-08 19:54:40 +00:00
|
|
|
}
|
|
|
|
}
|
2017-04-19 12:04:45 +00:00
|
|
|
|
2020-11-08 19:54:40 +00:00
|
|
|
switch (st->scrapeState)
|
|
|
|
{
|
|
|
|
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';
|
|
|
|
gstr << gtr_sprintf(_("Asking for peer counts in %s"), tr_strltime_rounded(st->nextScrapeTime - now));
|
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';
|
|
|
|
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';
|
|
|
|
gstr << gtr_sprintf(
|
|
|
|
_("Asking for peer counts now… <small>%s</small>"),
|
|
|
|
tr_strltime_rounded(now - st->lastScrapeStartTime));
|
2020-11-08 19:54:40 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2013-01-04 19:45:39 +00:00
|
|
|
|
2021-10-18 20:22:31 +00:00
|
|
|
void buildTrackerSummary(std::ostream& gstr, std::string const& key, tr_tracker_stat const* st, bool showScrape)
|
2020-11-08 19:54:40 +00:00
|
|
|
{
|
|
|
|
// hostname
|
2021-10-18 20:22:31 +00:00
|
|
|
gstr << (st->isBackup ? "<i>" : "<b>");
|
|
|
|
gstr << Glib::Markup::escape_text(!key.empty() ? gtr_sprintf("%s - %s", st->host, key) : st->host);
|
|
|
|
gstr << (st->isBackup ? "</i>" : "</b>");
|
2020-11-08 19:54:40 +00:00
|
|
|
|
|
|
|
if (!st->isBackup)
|
|
|
|
{
|
2021-10-06 16:32:17 +00:00
|
|
|
time_t const now = time(nullptr);
|
2020-11-08 19:54:40 +00:00
|
|
|
|
|
|
|
appendAnnounceInfo(st, now, gstr);
|
|
|
|
|
|
|
|
if (showScrape)
|
|
|
|
{
|
|
|
|
appendScrapeInfo(st, now, 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:
|
|
|
|
TrackerModelColumns()
|
|
|
|
{
|
|
|
|
add(torrent_id);
|
|
|
|
add(text);
|
|
|
|
add(is_backup);
|
|
|
|
add(tracker_id);
|
|
|
|
add(favicon);
|
|
|
|
add(was_updated);
|
|
|
|
add(key);
|
|
|
|
}
|
|
|
|
|
|
|
|
Gtk::TreeModelColumn<int> torrent_id;
|
|
|
|
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
|
|
|
}
|
|
|
|
|
2021-10-18 20:22:31 +00:00
|
|
|
int DetailsDialog::Impl::tracker_list_get_current_torrent_id() const
|
2010-03-10 19:16:25 +00:00
|
|
|
{
|
2017-04-19 12:04:45 +00:00
|
|
|
int torrent_id = -1;
|
2011-01-14 21:57:20 +00:00
|
|
|
|
2017-04-19 12:04:45 +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
|
|
|
{
|
2021-10-18 20:22:31 +00:00
|
|
|
torrent_id = ids_.front();
|
2017-04-19 12:04:45 +00:00
|
|
|
}
|
2011-01-14 21:57:20 +00:00
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
/* otherwise, use the selected tracker's torrent */
|
|
|
|
if (torrent_id < 0)
|
2013-01-04 19:45:39 +00:00
|
|
|
{
|
2021-10-18 20:22:31 +00:00
|
|
|
auto const sel = tracker_view_->get_selection();
|
2017-04-19 12:04:45 +00:00
|
|
|
|
2021-10-18 20:22:31 +00:00
|
|
|
if (auto const iter = sel->get_selected(); iter)
|
2017-04-19 12:04:45 +00:00
|
|
|
{
|
2021-10-18 20:22:31 +00:00
|
|
|
torrent_id = iter->get_value(tracker_cols.torrent_id);
|
2017-04-19 12:04:45 +00:00
|
|
|
}
|
2010-03-10 19:16:25 +00:00
|
|
|
}
|
2011-01-14 21:57:20 +00:00
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
return torrent_id;
|
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
|
|
|
{
|
2021-10-18 20:22:31 +00:00
|
|
|
int const torrent_id = tracker_list_get_current_torrent_id();
|
|
|
|
return core_->find_torrent(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
|
|
|
{
|
|
|
|
|
2021-10-18 20:22:31 +00:00
|
|
|
void favicon_ready_cb(Glib::RefPtr<Gdk::Pixbuf> const& pixbuf, Gtk::TreeRowReference& reference)
|
|
|
|
{
|
2021-10-06 16:32:17 +00:00
|
|
|
if (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
|
|
|
{
|
2021-10-18 20:22:31 +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_;
|
|
|
|
auto& store = tracker_store_;
|
|
|
|
auto* session = core_->get_session();
|
|
|
|
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-10-18 20:22:31 +00:00
|
|
|
std::vector<int> statCount;
|
|
|
|
std::vector<tr_tracker_stat*> stats;
|
2013-01-04 19:45:39 +00:00
|
|
|
|
2021-10-18 20:22:31 +00:00
|
|
|
statCount.reserve(torrents.size());
|
|
|
|
stats.reserve(torrents.size());
|
|
|
|
for (auto const* torrent : torrents)
|
2017-04-19 12:04:45 +00:00
|
|
|
{
|
2021-10-18 20:22:31 +00:00
|
|
|
int count = 0;
|
|
|
|
stats.push_back(tr_torrentTrackers(torrent, &count));
|
|
|
|
statCount.push_back(count);
|
2017-04-19 12:04:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* step 2: mark all the trackers in the list as not-updated */
|
2021-10-18 20:22:31 +00:00
|
|
|
for (auto const& 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
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
/* step 3: add any new trackers */
|
2021-10-18 20:22:31 +00:00
|
|
|
for (size_t i = 0; i < statCount.size(); ++i)
|
2011-04-12 10:51:52 +00:00
|
|
|
{
|
2021-10-18 20:22:31 +00:00
|
|
|
int const jn = statCount.at(i);
|
2013-01-04 19:45:39 +00:00
|
|
|
|
2017-05-13 22:38:31 +00:00
|
|
|
for (int j = 0; j < jn; ++j)
|
2011-04-12 10:51:52 +00:00
|
|
|
{
|
2021-10-18 20:22:31 +00:00
|
|
|
tr_torrent const* tor = torrents.at(i);
|
|
|
|
tr_tracker_stat const* st = &stats.at(i)[j];
|
2017-04-20 16:02:19 +00:00
|
|
|
int const torrent_id = tr_torrentId(tor);
|
2017-04-19 12:04:45 +00:00
|
|
|
|
|
|
|
/* build the key to find the row */
|
2021-10-18 20:22:31 +00:00
|
|
|
gstr.str({});
|
|
|
|
gstr << torrent_id << '\t' << st->tier << '\t' << st->announce;
|
2013-01-04 19:45:39 +00:00
|
|
|
|
2021-10-18 20:22:31 +00:00
|
|
|
if (hash.find(gstr.str()) == hash.end())
|
2017-04-19 12:04:45 +00:00
|
|
|
{
|
2021-10-18 20:22:31 +00:00
|
|
|
auto const iter = store->append();
|
|
|
|
(*iter)[tracker_cols.torrent_id] = torrent_id;
|
|
|
|
(*iter)[tracker_cols.tracker_id] = st->id;
|
|
|
|
(*iter)[tracker_cols.key] = gstr.str();
|
|
|
|
|
|
|
|
auto const p = store->get_path(iter);
|
|
|
|
hash.emplace(gstr.str(), Gtk::TreeRowReference(store, p));
|
|
|
|
gtr_get_favicon_from_url(
|
|
|
|
session,
|
|
|
|
st->announce,
|
|
|
|
[ref = Gtk::TreeRowReference(store, p)](auto const& pixbuf) mutable { favicon_ready_cb(pixbuf, ref); });
|
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 4: update the 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
|
|
|
tr_torrent const* tor = torrents.at(i);
|
|
|
|
auto const summary_name = std::string(torrents.size() > 1 ? tr_torrentName(tor) : "");
|
2013-01-04 19:45:39 +00:00
|
|
|
|
2021-10-18 20:22:31 +00:00
|
|
|
for (int j = 0; j < statCount.at(i); ++j)
|
2017-04-19 12:04:45 +00:00
|
|
|
{
|
2021-10-18 20:22:31 +00:00
|
|
|
tr_tracker_stat const* st = &stats.at(i)[j];
|
2017-04-19 12:04:45 +00:00
|
|
|
|
|
|
|
/* build the key to find the row */
|
2021-10-18 20:22:31 +00:00
|
|
|
gstr.str({});
|
|
|
|
gstr << tr_torrentId(tor) << '\t' << st->tier << '\t' << st->announce;
|
|
|
|
auto const iter = store->get_iter(hash.at(gstr.str()).get_path());
|
2017-04-19 12:04:45 +00:00
|
|
|
|
|
|
|
/* update the row */
|
2021-10-18 20:22:31 +00:00
|
|
|
gstr.str({});
|
2017-04-19 12:04:45 +00:00
|
|
|
buildTrackerSummary(gstr, summary_name, st, showScrape);
|
2021-10-18 20:22:31 +00:00
|
|
|
(*iter)[tracker_cols.text] = gstr.str();
|
|
|
|
(*iter)[tracker_cols.is_backup] = st->isBackup;
|
|
|
|
(*iter)[tracker_cols.tracker_id] = st->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
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-10-18 20:22:31 +00:00
|
|
|
edit_trackers_button_->set_sensitive(tracker_list_get_current_torrent_id() >= 0);
|
2008-02-21 07:29:39 +00:00
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
/* cleanup */
|
2021-10-18 20:22:31 +00:00
|
|
|
for (size_t i = 0; i < stats.size(); ++i)
|
2017-04-19 12:04:45 +00:00
|
|
|
{
|
|
|
|
tr_torrentTrackersFree(stats[i], statCount[i]);
|
|
|
|
}
|
2009-04-24 01:37:04 +00:00
|
|
|
}
|
2008-02-21 07:29:39 +00:00
|
|
|
|
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
|
|
|
|
2021-10-18 20:22:31 +00:00
|
|
|
void DetailsDialog::Impl::on_edit_trackers_response(int response, Gtk::Dialog* dialog)
|
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
|
|
|
|
2021-10-18 20:22:31 +00:00
|
|
|
if (response == Gtk::RESPONSE_ACCEPT)
|
2009-09-26 00:48:07 +00:00
|
|
|
{
|
2021-10-18 20:22:31 +00:00
|
|
|
int const torrent_id = GPOINTER_TO_INT(dialog->get_data(TORRENT_ID_KEY));
|
|
|
|
auto* const text_buffer = static_cast<Gtk::TextBuffer*>(dialog->get_data(TEXT_BUFFER_KEY));
|
|
|
|
tr_torrent* const tor = core_->find_torrent(torrent_id);
|
2013-01-04 19:45:39 +00:00
|
|
|
|
2021-10-06 16:32:17 +00:00
|
|
|
if (tor != nullptr)
|
2009-10-10 19:24:46 +00:00
|
|
|
{
|
2017-04-19 12:04:45 +00:00
|
|
|
/* build the array of trackers */
|
2021-10-18 20:22:31 +00:00
|
|
|
auto const tracker_text = text_buffer->get_text(false);
|
|
|
|
std::istringstream tracker_strings(tracker_text);
|
|
|
|
|
|
|
|
std::vector<tr_tracker_info> trackers;
|
|
|
|
std::list<std::string> announce_urls;
|
2020-11-08 19:54:40 +00:00
|
|
|
int tier = 0;
|
2017-04-19 12:04:45 +00:00
|
|
|
|
2021-10-18 20:22:31 +00:00
|
|
|
std::string str;
|
|
|
|
while (std::getline(tracker_strings, str))
|
2017-04-19 12:04:45 +00:00
|
|
|
{
|
2021-10-18 20:22:31 +00:00
|
|
|
if (str.empty())
|
2013-01-04 19:45:39 +00:00
|
|
|
{
|
2017-04-19 12:04:45 +00:00
|
|
|
++tier;
|
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
|
|
|
announce_urls.push_front(str);
|
|
|
|
trackers.push_back(tr_tracker_info{ tier, announce_urls.front().data(), nullptr, 0 });
|
2011-01-14 21:57:20 +00:00
|
|
|
}
|
|
|
|
}
|
2009-09-26 00:48:07 +00:00
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
/* update the torrent */
|
2021-10-18 20:22:31 +00:00
|
|
|
if (tr_torrentSetAnnounceList(tor, trackers.data(), trackers.size()))
|
2013-01-04 19:45:39 +00:00
|
|
|
{
|
2021-10-18 20:22:31 +00:00
|
|
|
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
|
|
|
{
|
2021-10-18 20:22:31 +00:00
|
|
|
Gtk::MessageDialog
|
|
|
|
w(*dialog, _("List contains invalid URLs"), false, Gtk::MESSAGE_ERROR, Gtk::BUTTONS_CLOSE, true);
|
|
|
|
w.set_secondary_text(_("Please correct the errors and try again."));
|
|
|
|
w.run();
|
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)
|
|
|
|
{
|
2021-10-18 20:22:31 +00:00
|
|
|
delete dialog;
|
2017-04-19 12:04:45 +00:00
|
|
|
}
|
2009-09-26 00:48:07 +00:00
|
|
|
}
|
|
|
|
|
2021-10-18 20:22:31 +00:00
|
|
|
namespace
|
|
|
|
{
|
|
|
|
|
|
|
|
std::string get_editable_tracker_list(tr_torrent const* tor)
|
2011-01-14 21:57:20 +00:00
|
|
|
{
|
2021-10-18 20:22:31 +00:00
|
|
|
std::ostringstream gstr;
|
2017-04-19 12:04:45 +00:00
|
|
|
int tier = 0;
|
2017-04-20 16:02:19 +00:00
|
|
|
tr_info const* inf = tr_torrentInfo(tor);
|
2013-01-04 19:45:39 +00:00
|
|
|
|
2017-05-13 22:38:31 +00:00
|
|
|
for (unsigned int i = 0; i < inf->trackerCount; ++i)
|
2013-01-04 19:45:39 +00:00
|
|
|
{
|
2017-04-20 16:02:19 +00:00
|
|
|
tr_tracker_info const* t = &inf->trackers[i];
|
2013-01-04 19:45:39 +00:00
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
if (tier != t->tier)
|
2013-01-04 19:45:39 +00:00
|
|
|
{
|
2017-04-19 12:04:45 +00:00
|
|
|
tier = t->tier;
|
2021-10-18 20:22:31 +00:00
|
|
|
gstr << '\n';
|
2011-01-14 21:57:20 +00:00
|
|
|
}
|
2013-01-04 19:45:39 +00:00
|
|
|
|
2021-10-18 20:22:31 +00:00
|
|
|
gstr << t->announce << '\n';
|
2011-01-14 21:57:20 +00:00
|
|
|
}
|
2013-01-04 19:45:39 +00:00
|
|
|
|
2021-10-18 20:22:31 +00:00
|
|
|
auto str = gstr.str();
|
|
|
|
if (!str.empty())
|
2013-01-04 19:45:39 +00:00
|
|
|
{
|
2021-10-18 20:22:31 +00:00
|
|
|
str.resize(str.size() - 1);
|
2017-04-19 12:04:45 +00:00
|
|
|
}
|
2021-10-18 20:22:31 +00:00
|
|
|
|
|
|
|
return str;
|
2017-04-19 12:04:45 +00:00
|
|
|
}
|
2013-01-04 19:45:39 +00:00
|
|
|
|
2021-10-18 20:22:31 +00:00
|
|
|
} // namespace
|
|
|
|
|
|
|
|
void DetailsDialog::Impl::on_edit_trackers()
|
2017-04-19 12:04:45 +00:00
|
|
|
{
|
2021-10-18 20:22:31 +00:00
|
|
|
tr_torrent const* tor = tracker_list_get_current_torrent();
|
2017-04-19 12:04:45 +00:00
|
|
|
|
2021-10-06 16:32:17 +00:00
|
|
|
if (tor != nullptr)
|
2017-04-19 12:04:45 +00:00
|
|
|
{
|
|
|
|
guint row;
|
2017-04-20 16:02:19 +00:00
|
|
|
int const torrent_id = tr_torrentId(tor);
|
2017-04-19 12:04:45 +00:00
|
|
|
|
2021-10-18 20:22:31 +00:00
|
|
|
auto* d = new Gtk::Dialog(
|
|
|
|
gtr_sprintf(_("%s - Edit Trackers"), tr_torrentName(tor)),
|
|
|
|
dialog_,
|
|
|
|
Gtk::DIALOG_MODAL | Gtk::DIALOG_DESTROY_WITH_PARENT);
|
|
|
|
d->add_button(_("_Cancel"), Gtk::RESPONSE_CANCEL);
|
|
|
|
d->add_button(_("_Save"), Gtk::RESPONSE_ACCEPT);
|
|
|
|
d->signal_response().connect([this, d](int response) { on_edit_trackers_response(response, d); });
|
2017-04-19 12:04:45 +00:00
|
|
|
|
|
|
|
row = 0;
|
2021-10-18 20:22:31 +00:00
|
|
|
auto* t = Gtk::make_managed<HigWorkarea>();
|
|
|
|
t->add_section_title(row, _("Tracker Announce URLs"));
|
2017-04-19 12:04:45 +00:00
|
|
|
|
2021-10-18 20:22:31 +00:00
|
|
|
auto* l = Gtk::make_managed<Gtk::Label>();
|
|
|
|
l->set_markup(
|
2021-08-15 09:41:48 +00:00
|
|
|
_("To add a backup URL, add it on the line after the primary URL.\n"
|
|
|
|
"To add another primary URL, add it after a blank line."));
|
2021-10-18 20:22:31 +00:00
|
|
|
l->set_justify(Gtk::JUSTIFY_LEFT);
|
|
|
|
l->set_halign(Gtk::ALIGN_START);
|
|
|
|
l->set_valign(Gtk::ALIGN_CENTER);
|
|
|
|
t->add_wide_control(row, *l);
|
|
|
|
|
|
|
|
auto* w = Gtk::make_managed<Gtk::TextView>();
|
|
|
|
w->get_buffer()->set_text(get_editable_tracker_list(tor));
|
|
|
|
auto* fr = Gtk::make_managed<Gtk::Frame>();
|
|
|
|
fr->set_shadow_type(Gtk::SHADOW_IN);
|
|
|
|
auto* sw = Gtk::make_managed<Gtk::ScrolledWindow>();
|
|
|
|
sw->set_policy(Gtk::POLICY_AUTOMATIC, Gtk::POLICY_AUTOMATIC);
|
|
|
|
sw->add(*w);
|
|
|
|
fr->add(*sw);
|
|
|
|
fr->set_size_request(500U, 166U);
|
|
|
|
t->add_wide_tall_control(row, *fr);
|
|
|
|
|
|
|
|
gtr_dialog_set_content(*d, *t);
|
|
|
|
|
|
|
|
d->set_data(TORRENT_ID_KEY, GINT_TO_POINTER(torrent_id));
|
|
|
|
d->set_data(TEXT_BUFFER_KEY, gtr_get_ptr(w->get_buffer()));
|
|
|
|
|
|
|
|
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();
|
|
|
|
auto* 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
|
|
|
}
|
|
|
|
|
2021-10-18 20:22:31 +00:00
|
|
|
void DetailsDialog::Impl::on_add_tracker_response(int response, Gtk::Dialog* dialog)
|
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
|
|
|
|
2021-10-18 20:22:31 +00:00
|
|
|
if (response == Gtk::RESPONSE_ACCEPT)
|
2011-01-14 21:57:20 +00:00
|
|
|
{
|
2021-10-18 20:22:31 +00:00
|
|
|
auto* e = static_cast<Gtk::Entry*>(dialog->get_data(URL_ENTRY_KEY));
|
|
|
|
int const torrent_id = GPOINTER_TO_INT(dialog->get_data(TORRENT_ID_KEY));
|
|
|
|
auto const url = gtr_str_strip(e->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;
|
|
|
|
tr_variant* args;
|
|
|
|
tr_variant* trackers;
|
2015-07-13 00:32:48 +00:00
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
tr_variantInitDict(&top, 2);
|
2021-10-20 02:30:50 +00:00
|
|
|
tr_variantDictAddStr(&top, TR_KEY_method, "torrent-set"sv);
|
2017-04-19 12:04:45 +00:00
|
|
|
args = tr_variantDictAddDict(&top, TR_KEY_arguments, 2);
|
|
|
|
tr_variantDictAddInt(args, TR_KEY_id, torrent_id);
|
|
|
|
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
|
|
|
|
2021-10-18 20:22:31 +00:00
|
|
|
core_->exec(&top);
|
|
|
|
refresh();
|
2015-07-13 00:32:48 +00:00
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
tr_variantFree(&top);
|
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
|
|
|
{
|
2021-10-18 20:22:31 +00:00
|
|
|
gtr_unrecognized_url_dialog(*dialog, url);
|
|
|
|
destroy = false;
|
2011-01-14 21:57:20 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
if (destroy)
|
|
|
|
{
|
2021-10-18 20:22:31 +00:00
|
|
|
delete dialog;
|
2017-04-19 12:04:45 +00:00
|
|
|
}
|
2011-01-14 21:57:20 +00:00
|
|
|
}
|
|
|
|
|
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
|
|
|
{
|
2021-10-18 20:22:31 +00:00
|
|
|
tr_torrent const* tor = tracker_list_get_current_torrent();
|
2017-04-19 12:04:45 +00:00
|
|
|
|
2021-10-06 16:32:17 +00:00
|
|
|
if (tor != nullptr)
|
2017-04-19 12:04:45 +00:00
|
|
|
{
|
|
|
|
guint row;
|
2021-10-18 20:22:31 +00:00
|
|
|
|
|
|
|
auto* w = new Gtk::Dialog(
|
|
|
|
gtr_sprintf(_("%s - Add Tracker"), tr_torrentName(tor)),
|
|
|
|
dialog_,
|
|
|
|
Gtk::DIALOG_DESTROY_WITH_PARENT);
|
|
|
|
w->add_button(_("_Cancel"), Gtk::RESPONSE_CANCEL);
|
|
|
|
w->add_button(_("_Add"), Gtk::RESPONSE_ACCEPT);
|
|
|
|
w->signal_response().connect([this, w](int response) { on_add_tracker_response(response, w); });
|
2017-04-19 12:04:45 +00:00
|
|
|
|
|
|
|
row = 0;
|
2021-10-18 20:22:31 +00:00
|
|
|
auto* t = Gtk::make_managed<HigWorkarea>();
|
|
|
|
t->add_section_title(row, _("Tracker"));
|
|
|
|
auto* e = Gtk::make_managed<Gtk::Entry>();
|
|
|
|
e->set_size_request(400, -1);
|
|
|
|
gtr_paste_clipboard_url_into_entry(*e);
|
|
|
|
w->set_data(URL_ENTRY_KEY, e);
|
|
|
|
w->set_data(TORRENT_ID_KEY, GINT_TO_POINTER(tr_torrentId(tor)));
|
|
|
|
t->add_row(row, _("_Announce URL:"), *e);
|
|
|
|
gtr_dialog_set_content(*w, *t);
|
|
|
|
|
|
|
|
w->show_all();
|
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;
|
|
|
|
tr_variant* args;
|
|
|
|
tr_variant* trackers;
|
2015-07-13 00:32:48 +00:00
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
tr_variantInitDict(&top, 2);
|
2021-10-20 02:30:50 +00:00
|
|
|
tr_variantDictAddStr(&top, TR_KEY_method, "torrent-set"sv);
|
2017-04-19 12:04:45 +00:00
|
|
|
args = tr_variantDictAddDict(&top, TR_KEY_arguments, 2);
|
|
|
|
tr_variantDictAddInt(args, TR_KEY_id, torrent_id);
|
|
|
|
trackers = tr_variantDictAddList(args, TR_KEY_trackerRemove, 1);
|
|
|
|
tr_variantListAddInt(trackers, tracker_id);
|
2015-07-13 00:32:48 +00:00
|
|
|
|
2021-10-18 20:22:31 +00:00
|
|
|
core_->exec(&top);
|
|
|
|
refresh();
|
2015-07-13 00:32:48 +00:00
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
tr_variantFree(&top);
|
2011-01-14 21:57:20 +00:00
|
|
|
}
|
2009-09-25 21:05:59 +00:00
|
|
|
}
|
2008-02-21 07:29:39 +00:00
|
|
|
|
2021-10-18 20:22:31 +00:00
|
|
|
Gtk::Widget* DetailsDialog::Impl::tracker_page_new()
|
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
|
|
|
auto* vbox = Gtk::make_managed<Gtk::Box>(Gtk::ORIENTATION_VERTICAL, GUI_PAD);
|
|
|
|
vbox->set_border_width(GUI_PAD_BIG);
|
|
|
|
|
|
|
|
tracker_store_ = Gtk::ListStore::create(tracker_cols);
|
|
|
|
|
|
|
|
trackers_filtered_ = Gtk::TreeModelFilter::create(tracker_store_);
|
|
|
|
trackers_filtered_->set_visible_func(sigc::mem_fun(this, &Impl::trackerVisibleFunc));
|
|
|
|
|
|
|
|
auto* hbox = Gtk::make_managed<Gtk::Box>(Gtk::ORIENTATION_HORIZONTAL, GUI_PAD_BIG);
|
|
|
|
|
|
|
|
tracker_view_ = Gtk::make_managed<Gtk::TreeView>(trackers_filtered_);
|
|
|
|
tracker_view_->set_headers_visible(false);
|
|
|
|
tracker_view_->signal_button_press_event().connect([this](GdkEventButton* event)
|
|
|
|
{ return on_tree_view_button_pressed(tracker_view_, event); });
|
|
|
|
tracker_view_->signal_button_release_event().connect([this](GdkEventButton* event)
|
|
|
|
{ return on_tree_view_button_released(tracker_view_, event); });
|
|
|
|
|
|
|
|
auto sel = tracker_view_->get_selection();
|
|
|
|
sel->signal_changed().connect(sigc::mem_fun(this, &Impl::on_tracker_list_selection_changed));
|
|
|
|
|
|
|
|
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>();
|
|
|
|
r->property_ellipsize() = Pango::ELLIPSIZE_END;
|
|
|
|
r->property_xpad() = GUI_PAD_SMALL;
|
|
|
|
r->property_ypad() = pad;
|
|
|
|
c->pack_start(*r, true);
|
|
|
|
c->add_attribute(r->property_markup(), tracker_cols.text);
|
|
|
|
}
|
|
|
|
|
|
|
|
auto* sw = Gtk::make_managed<Gtk::ScrolledWindow>();
|
|
|
|
sw->set_policy(Gtk::POLICY_AUTOMATIC, Gtk::POLICY_AUTOMATIC);
|
|
|
|
sw->add(*tracker_view_);
|
|
|
|
auto* w = Gtk::make_managed<Gtk::Frame>();
|
|
|
|
w->set_shadow_type(Gtk::SHADOW_IN);
|
|
|
|
w->add(*sw);
|
|
|
|
|
|
|
|
hbox->pack_start(*w, true, true);
|
|
|
|
|
|
|
|
auto* v = Gtk::make_managed<Gtk::Box>(Gtk::ORIENTATION_VERTICAL, GUI_PAD);
|
|
|
|
|
|
|
|
add_tracker_button_ = Gtk::make_managed<Gtk::Button>(_("_Add"), true);
|
|
|
|
add_tracker_button_->signal_clicked().connect(sigc::mem_fun(this, &Impl::on_tracker_list_add_button_clicked));
|
|
|
|
v->pack_start(*add_tracker_button_, false, false);
|
|
|
|
|
|
|
|
edit_trackers_button_ = Gtk::make_managed<Gtk::Button>(_("_Edit"), true);
|
|
|
|
edit_trackers_button_->signal_clicked().connect(sigc::mem_fun(this, &Impl::on_edit_trackers));
|
|
|
|
v->pack_start(*edit_trackers_button_, false, false);
|
|
|
|
|
|
|
|
remove_tracker_button_ = Gtk::make_managed<Gtk::Button>(_("_Remove"), true);
|
|
|
|
remove_tracker_button_->signal_clicked().connect(sigc::mem_fun(this, &Impl::on_tracker_list_remove_button_clicked));
|
|
|
|
v->pack_start(*remove_tracker_button_, false, false);
|
|
|
|
|
|
|
|
hbox->pack_start(*v, false, false);
|
|
|
|
|
|
|
|
vbox->pack_start(*hbox, true, true);
|
|
|
|
|
|
|
|
scrape_check_ = Gtk::make_managed<Gtk::CheckButton>(_("Show _more details"), true);
|
|
|
|
scrape_check_->set_active(gtr_pref_flag_get(TR_KEY_show_tracker_scrapes));
|
|
|
|
scrape_check_->signal_toggled().connect(sigc::mem_fun(this, &Impl::onScrapeToggled));
|
|
|
|
vbox->pack_start(*scrape_check_, false, false);
|
|
|
|
|
|
|
|
all_check_ = Gtk::make_managed<Gtk::CheckButton>(_("Show _backup trackers"), true);
|
|
|
|
all_check_->set_active(gtr_pref_flag_get(TR_KEY_show_backup_trackers));
|
|
|
|
all_check_->signal_toggled().connect(sigc::mem_fun(this, &Impl::onBackupToggled));
|
|
|
|
vbox->pack_start(*all_check_, false, false);
|
2013-01-04 19:45:39 +00:00
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
return vbox;
|
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);
|
|
|
|
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
|
|
|
{
|
2021-10-18 20:22:31 +00:00
|
|
|
dialog_.response(Gtk::RESPONSE_CLOSE);
|
2017-04-19 12:04:45 +00:00
|
|
|
}
|
2007-06-06 00:30:13 +00:00
|
|
|
}
|
|
|
|
|
2021-10-18 20:22:31 +00:00
|
|
|
void DetailsDialog::Impl::on_details_window_size_allocated(Gtk::Allocation& /*alloc*/)
|
2007-06-06 00:30:13 +00:00
|
|
|
{
|
2020-11-01 21:47:57 +00:00
|
|
|
int w = 0;
|
|
|
|
int h = 0;
|
2021-10-18 20:22:31 +00:00
|
|
|
dialog_.get_size(w, h);
|
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-10-18 20:22:31 +00:00
|
|
|
std::unique_ptr<DetailsDialog> DetailsDialog::create(Gtk::Window& parent, Glib::RefPtr<TrCore> const& core)
|
2017-04-19 12:04:45 +00:00
|
|
|
{
|
2021-10-18 20:22:31 +00:00
|
|
|
return std::unique_ptr<DetailsDialog>(new DetailsDialog(parent, core));
|
|
|
|
}
|
2017-04-19 12:04:45 +00:00
|
|
|
|
2021-10-18 20:22:31 +00:00
|
|
|
DetailsDialog::DetailsDialog(Gtk::Window& parent, Glib::RefPtr<TrCore> const& core)
|
|
|
|
: Gtk::Dialog({}, parent)
|
|
|
|
, impl_(std::make_unique<Impl>(*this, core))
|
|
|
|
{
|
|
|
|
}
|
2017-04-19 12:04:45 +00:00
|
|
|
|
2021-10-18 20:22:31 +00:00
|
|
|
DetailsDialog::~DetailsDialog() = default;
|
|
|
|
|
|
|
|
DetailsDialog::Impl::Impl(DetailsDialog& dialog, Glib::RefPtr<TrCore> const& core)
|
|
|
|
: dialog_(dialog)
|
|
|
|
, core_(core)
|
|
|
|
{
|
2017-04-19 12:04:45 +00:00
|
|
|
/* create the dialog */
|
2021-10-18 20:22:31 +00:00
|
|
|
dialog_.add_button(_("_Close"), Gtk::RESPONSE_CLOSE);
|
|
|
|
dialog_.set_role("tr-info");
|
2020-04-27 21:34:02 +00:00
|
|
|
|
|
|
|
/* return saved window size */
|
2021-10-18 20:22:31 +00:00
|
|
|
dialog_.resize((int)gtr_pref_int_get(TR_KEY_details_window_width), (int)gtr_pref_int_get(TR_KEY_details_window_height));
|
|
|
|
dialog_.signal_size_allocate().connect(sigc::mem_fun(this, &Impl::on_details_window_size_allocated));
|
|
|
|
|
|
|
|
dialog_.signal_response().connect(sigc::hide<0>(sigc::mem_fun(dialog_, &DetailsDialog::hide)));
|
|
|
|
dialog_.set_border_width(GUI_PAD);
|
|
|
|
|
|
|
|
auto* n = Gtk::make_managed<Gtk::Notebook>();
|
|
|
|
n->set_border_width(GUI_PAD);
|
|
|
|
|
|
|
|
n->append_page(*info_page_new(), _("Information"));
|
|
|
|
n->append_page(*peer_page_new(), _("Peers"));
|
|
|
|
n->append_page(*tracker_page_new(), _("Trackers"));
|
|
|
|
|
|
|
|
auto* v = Gtk::make_managed<Gtk::Box>(Gtk::ORIENTATION_VERTICAL);
|
|
|
|
file_list_ = Gtk::make_managed<FileList>(core, 0);
|
|
|
|
file_label_ = Gtk::make_managed<Gtk::Label>(_("File listing not available for combined torrent properties"));
|
|
|
|
v->pack_start(*file_list_, true, true, 0);
|
|
|
|
v->pack_start(*file_label_, true, true, 0);
|
|
|
|
v->set_border_width(GUI_PAD_BIG);
|
|
|
|
n->append_page(*v, _("Files"));
|
|
|
|
|
|
|
|
n->append_page(*options_page_new(), _("Options"));
|
|
|
|
|
|
|
|
gtr_dialog_set_content(dialog_, *n);
|
|
|
|
periodic_refresh_tag_ = Glib::signal_timeout().connect_seconds(
|
|
|
|
[this]() { return refresh(), true; },
|
|
|
|
SECONDARY_WINDOW_REFRESH_INTERVAL_SECONDS);
|
|
|
|
}
|
|
|
|
|
|
|
|
void DetailsDialog::set_torrents(std::vector<int> const& ids)
|
|
|
|
{
|
|
|
|
impl_->set_torrents(ids);
|
2007-06-06 00:30:13 +00:00
|
|
|
}
|
2008-09-23 19:11:04 +00:00
|
|
|
|
2021-10-18 20:22:31 +00:00
|
|
|
void DetailsDialog::Impl::set_torrents(std::vector<int> const& ids)
|
2009-04-24 01:37:04 +00:00
|
|
|
{
|
2021-10-18 20:22:31 +00:00
|
|
|
Glib::ustring title;
|
|
|
|
int 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);
|
|
|
|
auto const* inf = tr_torrentInfo(tor);
|
|
|
|
title = gtr_sprintf(_("%s Properties"), inf->name);
|
2013-01-04 19:45:39 +00:00
|
|
|
|
2021-10-18 20:22:31 +00:00
|
|
|
file_list_->set_torrent(id);
|
|
|
|
file_list_->show();
|
|
|
|
file_label_->hide();
|
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
|
|
|
{
|
2021-10-18 20:22:31 +00:00
|
|
|
file_list_->clear();
|
|
|
|
file_list_->hide();
|
|
|
|
file_label_->show();
|
|
|
|
title = gtr_sprintf(_("%'d Torrent Properties"), 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
|
|
|
}
|