2008-02-10 22:25:42 +00:00
|
|
|
/*
|
2014-01-19 01:09:44 +00:00
|
|
|
* This file Copyright (C) 2007-2014 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
|
|
|
|
2013-08-24 17:53:45 +00:00
|
|
|
#include <limits.h> /* INT_MAX */
|
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() */
|
2007-06-06 00:30:13 +00:00
|
|
|
#include <glib/gi18n.h>
|
|
|
|
#include <gtk/gtk.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"
|
2009-09-25 21:05:59 +00:00
|
|
|
#include "tr-prefs.h"
|
2007-06-06 00:30:13 +00:00
|
|
|
#include "util.h"
|
|
|
|
|
2011-04-29 21:36:44 +00:00
|
|
|
static GQuark ARG_KEY = 0;
|
|
|
|
static GQuark DETAILS_KEY = 0;
|
|
|
|
static GQuark TORRENT_ID_KEY = 0;
|
|
|
|
static GQuark TEXT_BUFFER_KEY = 0;
|
|
|
|
static GQuark URL_ENTRY_KEY = 0;
|
2009-04-24 01:37:04 +00:00
|
|
|
|
|
|
|
struct DetailsImpl
|
2009-02-13 18:23:56 +00:00
|
|
|
{
|
2017-04-19 12:04:45 +00:00
|
|
|
GtkWidget* dialog;
|
|
|
|
|
|
|
|
GtkWidget* honor_limits_check;
|
|
|
|
GtkWidget* up_limited_check;
|
|
|
|
GtkWidget* up_limit_sping;
|
|
|
|
GtkWidget* down_limited_check;
|
|
|
|
GtkWidget* down_limit_spin;
|
|
|
|
GtkWidget* bandwidth_combo;
|
|
|
|
|
|
|
|
GtkWidget* ratio_combo;
|
|
|
|
GtkWidget* ratio_spin;
|
|
|
|
GtkWidget* idle_combo;
|
|
|
|
GtkWidget* idle_spin;
|
|
|
|
GtkWidget* max_peers_spin;
|
|
|
|
|
|
|
|
gulong honor_limits_check_tag;
|
|
|
|
gulong up_limited_check_tag;
|
|
|
|
gulong down_limited_check_tag;
|
|
|
|
gulong down_limit_spin_tag;
|
|
|
|
gulong up_limit_spin_tag;
|
|
|
|
gulong bandwidth_combo_tag;
|
|
|
|
gulong ratio_combo_tag;
|
|
|
|
gulong ratio_spin_tag;
|
|
|
|
gulong idle_combo_tag;
|
|
|
|
gulong idle_spin_tag;
|
|
|
|
gulong max_peers_spin_tag;
|
|
|
|
|
|
|
|
GtkWidget* size_lb;
|
|
|
|
GtkWidget* state_lb;
|
|
|
|
GtkWidget* have_lb;
|
|
|
|
GtkWidget* dl_lb;
|
|
|
|
GtkWidget* ul_lb;
|
|
|
|
GtkWidget* error_lb;
|
|
|
|
GtkWidget* date_started_lb;
|
|
|
|
GtkWidget* eta_lb;
|
|
|
|
GtkWidget* last_activity_lb;
|
|
|
|
|
|
|
|
GtkWidget* hash_lb;
|
|
|
|
GtkWidget* privacy_lb;
|
|
|
|
GtkWidget* origin_lb;
|
|
|
|
GtkWidget* destination_lb;
|
|
|
|
GtkTextBuffer* comment_buffer;
|
|
|
|
|
|
|
|
GHashTable* peer_hash;
|
|
|
|
GHashTable* webseed_hash;
|
|
|
|
GtkListStore* peer_store;
|
|
|
|
GtkListStore* webseed_store;
|
|
|
|
GtkWidget* webseed_view;
|
|
|
|
GtkWidget* peer_view;
|
|
|
|
GtkWidget* more_peer_details_check;
|
|
|
|
|
|
|
|
GtkListStore* tracker_store;
|
|
|
|
GHashTable* tracker_hash;
|
|
|
|
GtkTreeModel* trackers_filtered;
|
|
|
|
GtkWidget* add_tracker_button;
|
|
|
|
GtkWidget* edit_trackers_button;
|
|
|
|
GtkWidget* remove_tracker_button;
|
|
|
|
GtkWidget* tracker_view;
|
|
|
|
GtkWidget* scrape_check;
|
|
|
|
GtkWidget* all_check;
|
|
|
|
|
|
|
|
GtkWidget* file_list;
|
|
|
|
GtkWidget* file_label;
|
|
|
|
|
|
|
|
GSList* ids;
|
|
|
|
TrCore* core;
|
|
|
|
guint periodic_refresh_tag;
|
|
|
|
|
|
|
|
GString* gstr;
|
2008-06-10 02:36:52 +00:00
|
|
|
};
|
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
static tr_torrent** getTorrents(struct DetailsImpl* d, int* setmeCount)
|
2008-06-10 02:36:52 +00:00
|
|
|
{
|
2017-04-19 12:04:45 +00:00
|
|
|
int torrentCount = 0;
|
2017-04-20 16:02:19 +00:00
|
|
|
int const n = g_slist_length(d->ids);
|
2017-04-19 12:04:45 +00:00
|
|
|
tr_torrent** torrents = g_new(tr_torrent*, n);
|
2009-06-15 00:01:38 +00:00
|
|
|
|
2017-05-13 22:38:31 +00:00
|
|
|
for (GSList* l = d->ids; l != NULL; l = l->next)
|
2017-04-19 12:04:45 +00:00
|
|
|
{
|
2017-05-13 22:38:31 +00:00
|
|
|
if ((torrents[torrentCount] = gtr_core_find_torrent(d->core, GPOINTER_TO_INT(l->data))) != NULL)
|
2017-04-19 12:04:45 +00:00
|
|
|
{
|
|
|
|
++torrentCount;
|
|
|
|
}
|
|
|
|
}
|
2009-04-24 01:37:04 +00:00
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
*setmeCount = torrentCount;
|
|
|
|
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
|
|
|
|
*****
|
|
|
|
****/
|
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
static void set_togglebutton_if_different(GtkWidget* w, gulong tag, gboolean value)
|
2008-06-10 02:36:52 +00:00
|
|
|
{
|
2017-04-19 12:04:45 +00:00
|
|
|
GtkToggleButton* toggle = GTK_TOGGLE_BUTTON(w);
|
2017-04-20 16:02:19 +00:00
|
|
|
gboolean const currentValue = gtk_toggle_button_get_active(toggle);
|
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
|
|
|
{
|
2017-04-19 12:04:45 +00:00
|
|
|
g_signal_handler_block(toggle, tag);
|
|
|
|
gtk_toggle_button_set_active(toggle, value);
|
|
|
|
g_signal_handler_unblock(toggle, tag);
|
2008-06-10 02:36:52 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
static void set_int_spin_if_different(GtkWidget* w, gulong tag, int value)
|
2007-06-06 00:30:13 +00:00
|
|
|
{
|
2017-04-19 12:04:45 +00:00
|
|
|
GtkSpinButton* spin = GTK_SPIN_BUTTON(w);
|
2017-04-20 16:02:19 +00:00
|
|
|
int const currentValue = gtk_spin_button_get_value_as_int(spin);
|
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
|
|
|
{
|
2017-04-19 12:04:45 +00:00
|
|
|
g_signal_handler_block(spin, tag);
|
|
|
|
gtk_spin_button_set_value(spin, value);
|
|
|
|
g_signal_handler_unblock(spin, tag);
|
2009-04-24 01:37:04 +00:00
|
|
|
}
|
|
|
|
}
|
2007-06-06 00:30:13 +00:00
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
static void set_double_spin_if_different(GtkWidget* w, gulong tag, double value)
|
2007-06-06 00:30:13 +00:00
|
|
|
{
|
2017-04-19 12:04:45 +00:00
|
|
|
GtkSpinButton* spin = GTK_SPIN_BUTTON(w);
|
2017-04-20 16:02:19 +00:00
|
|
|
double const currentValue = gtk_spin_button_get_value(spin);
|
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
|
|
|
{
|
2017-04-19 12:04:45 +00:00
|
|
|
g_signal_handler_block(spin, tag);
|
|
|
|
gtk_spin_button_set_value(spin, value);
|
|
|
|
g_signal_handler_unblock(spin, tag);
|
2009-04-24 01:37:04 +00:00
|
|
|
}
|
|
|
|
}
|
2007-06-06 00:30:13 +00:00
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
static void unset_combo(GtkWidget* w, gulong tag)
|
2007-06-06 00:30:13 +00:00
|
|
|
{
|
2017-04-19 12:04:45 +00:00
|
|
|
GtkComboBox* combobox = GTK_COMBO_BOX(w);
|
2008-09-23 19:11:04 +00:00
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
g_signal_handler_block(combobox, tag);
|
|
|
|
gtk_combo_box_set_active(combobox, -1);
|
|
|
|
g_signal_handler_unblock(combobox, tag);
|
2007-06-06 00:30:13 +00:00
|
|
|
}
|
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
static void refreshOptions(struct DetailsImpl* di, tr_torrent** torrents, int n)
|
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 */
|
2017-04-30 16:25:26 +00:00
|
|
|
if (n != 0)
|
2013-01-04 19:45:39 +00:00
|
|
|
{
|
2017-04-20 16:02:19 +00:00
|
|
|
bool const baseline = tr_torrentUsesSessionLimits(torrents[0]);
|
2017-05-13 22:38:31 +00:00
|
|
|
bool is_uniform = true;
|
2013-01-04 19:45:39 +00:00
|
|
|
|
2017-05-13 22:38:31 +00:00
|
|
|
for (int i = 1; is_uniform && i < n; ++i)
|
2017-04-19 12:04:45 +00:00
|
|
|
{
|
2017-05-13 22:38:31 +00:00
|
|
|
is_uniform = baseline == tr_torrentUsesSessionLimits(torrents[i]);
|
2017-04-19 12:04:45 +00:00
|
|
|
}
|
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
|
|
|
{
|
|
|
|
set_togglebutton_if_different(di->honor_limits_check, di->honor_limits_check_tag, baseline);
|
|
|
|
}
|
2013-01-04 19:45:39 +00:00
|
|
|
}
|
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
/* down_limited_check */
|
2017-04-30 16:25:26 +00:00
|
|
|
if (n != 0)
|
2013-01-04 19:45:39 +00:00
|
|
|
{
|
2017-04-20 16:02:19 +00:00
|
|
|
bool const baseline = tr_torrentUsesSpeedLimit(torrents[0], TR_DOWN);
|
2017-05-13 22:38:31 +00:00
|
|
|
bool is_uniform = true;
|
2013-01-04 19:45:39 +00:00
|
|
|
|
2017-05-13 22:38:31 +00:00
|
|
|
for (int i = 1; is_uniform && i < n; ++i)
|
2017-04-19 12:04:45 +00:00
|
|
|
{
|
2017-05-13 22:38:31 +00:00
|
|
|
is_uniform = baseline == tr_torrentUsesSpeedLimit(torrents[i], TR_DOWN);
|
2017-04-19 12:04:45 +00:00
|
|
|
}
|
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
|
|
|
{
|
|
|
|
set_togglebutton_if_different(di->down_limited_check, di->down_limited_check_tag, baseline);
|
|
|
|
}
|
2013-01-04 19:45:39 +00:00
|
|
|
}
|
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
/* down_limit_spin */
|
2017-04-30 16:25:26 +00:00
|
|
|
if (n != 0)
|
2013-01-04 19:45:39 +00:00
|
|
|
{
|
2017-04-30 16:25:26 +00:00
|
|
|
unsigned int const baseline = tr_torrentGetSpeedLimit_KBps(torrents[0], TR_DOWN);
|
2017-05-13 22:38:31 +00:00
|
|
|
bool is_uniform = true;
|
2013-01-04 19:45:39 +00:00
|
|
|
|
2017-05-13 22:38:31 +00:00
|
|
|
for (int i = 1; is_uniform && i < n; ++i)
|
2017-04-19 12:04:45 +00:00
|
|
|
{
|
2017-05-13 22:38:31 +00:00
|
|
|
is_uniform = baseline == tr_torrentGetSpeedLimit_KBps(torrents[i], TR_DOWN);
|
2017-04-19 12:04:45 +00:00
|
|
|
}
|
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
|
|
|
{
|
|
|
|
set_int_spin_if_different(di->down_limit_spin, di->down_limit_spin_tag, baseline);
|
|
|
|
}
|
2013-01-04 19:45:39 +00:00
|
|
|
}
|
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
/* up_limited_check */
|
2017-04-30 16:25:26 +00:00
|
|
|
if (n != 0)
|
2013-01-04 19:45:39 +00:00
|
|
|
{
|
2017-04-20 16:02:19 +00:00
|
|
|
bool const baseline = tr_torrentUsesSpeedLimit(torrents[0], TR_UP);
|
2017-05-13 22:38:31 +00:00
|
|
|
bool is_uniform = true;
|
2013-01-04 19:45:39 +00:00
|
|
|
|
2017-05-13 22:38:31 +00:00
|
|
|
for (int i = 1; is_uniform && i < n; ++i)
|
2017-04-19 12:04:45 +00:00
|
|
|
{
|
2017-05-13 22:38:31 +00:00
|
|
|
is_uniform = baseline == tr_torrentUsesSpeedLimit(torrents[i], TR_UP);
|
2017-04-19 12:04:45 +00:00
|
|
|
}
|
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
|
|
|
{
|
|
|
|
set_togglebutton_if_different(di->up_limited_check, di->up_limited_check_tag, baseline);
|
|
|
|
}
|
2013-01-04 19:45:39 +00:00
|
|
|
}
|
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
/* up_limit_sping */
|
2017-04-30 16:25:26 +00:00
|
|
|
if (n != 0)
|
2013-01-04 19:45:39 +00:00
|
|
|
{
|
2017-04-20 16:02:19 +00:00
|
|
|
unsigned int const baseline = tr_torrentGetSpeedLimit_KBps(torrents[0], TR_UP);
|
2017-05-13 22:38:31 +00:00
|
|
|
bool is_uniform = true;
|
2013-01-04 19:45:39 +00:00
|
|
|
|
2017-05-13 22:38:31 +00:00
|
|
|
for (int i = 1; is_uniform && i < n; ++i)
|
2017-04-19 12:04:45 +00:00
|
|
|
{
|
2017-05-13 22:38:31 +00:00
|
|
|
is_uniform = baseline == tr_torrentGetSpeedLimit_KBps(torrents[i], TR_UP);
|
2017-04-19 12:04:45 +00:00
|
|
|
}
|
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
|
|
|
{
|
|
|
|
set_int_spin_if_different(di->up_limit_sping, di->up_limit_spin_tag, baseline);
|
|
|
|
}
|
2013-01-04 19:45:39 +00:00
|
|
|
}
|
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
/* bandwidth_combo */
|
2017-04-30 16:25:26 +00:00
|
|
|
if (n != 0)
|
2013-01-04 19:45:39 +00:00
|
|
|
{
|
2017-04-20 16:02:19 +00:00
|
|
|
int const baseline = tr_torrentGetPriority(torrents[0]);
|
2017-05-13 22:38:31 +00:00
|
|
|
bool is_uniform = true;
|
2013-01-04 19:45:39 +00:00
|
|
|
|
2017-05-13 22:38:31 +00:00
|
|
|
for (int i = 1; is_uniform && i < n; ++i)
|
2017-04-19 12:04:45 +00:00
|
|
|
{
|
2017-05-13 22:38:31 +00:00
|
|
|
is_uniform = baseline == tr_torrentGetPriority(torrents[i]);
|
2017-04-19 12:04:45 +00:00
|
|
|
}
|
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
|
|
|
{
|
2017-04-19 12:04:45 +00:00
|
|
|
GtkWidget* w = di->bandwidth_combo;
|
|
|
|
g_signal_handler_block(w, di->bandwidth_combo_tag);
|
|
|
|
gtr_priority_combo_set_value(GTK_COMBO_BOX(w), baseline);
|
|
|
|
g_signal_handler_unblock(w, di->bandwidth_combo_tag);
|
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
|
|
|
{
|
2017-04-19 12:04:45 +00:00
|
|
|
unset_combo(di->bandwidth_combo, di->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 */
|
2017-04-30 16:25:26 +00:00
|
|
|
if (n != 0)
|
2013-01-04 19:45:39 +00:00
|
|
|
{
|
2017-04-20 16:02:19 +00:00
|
|
|
int const baseline = tr_torrentGetRatioMode(torrents[0]);
|
2017-05-13 22:38:31 +00:00
|
|
|
bool is_uniform = true;
|
2013-01-04 19:45:39 +00:00
|
|
|
|
2017-05-13 22:38:31 +00:00
|
|
|
for (int i = 1; is_uniform && i < n; ++i)
|
2017-04-19 12:04:45 +00:00
|
|
|
{
|
2017-05-13 22:38:31 +00:00
|
|
|
is_uniform = baseline == (int)tr_torrentGetRatioMode(torrents[i]);
|
2017-04-19 12:04:45 +00:00
|
|
|
}
|
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
|
|
|
{
|
2017-04-19 12:04:45 +00:00
|
|
|
GtkWidget* w = di->ratio_combo;
|
|
|
|
g_signal_handler_block(w, di->ratio_combo_tag);
|
|
|
|
gtr_combo_box_set_active_enum(GTK_COMBO_BOX(w), baseline);
|
|
|
|
gtr_widget_set_visible(di->ratio_spin, baseline == TR_RATIOLIMIT_SINGLE);
|
|
|
|
g_signal_handler_unblock(w, di->ratio_combo_tag);
|
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 */
|
2017-04-30 16:25:26 +00:00
|
|
|
if (n != 0)
|
2013-01-04 19:45:39 +00:00
|
|
|
{
|
2017-04-20 16:02:19 +00:00
|
|
|
double const baseline = tr_torrentGetRatioLimit(torrents[0]);
|
2017-04-19 12:04:45 +00:00
|
|
|
set_double_spin_if_different(di->ratio_spin, di->ratio_spin_tag, baseline);
|
2010-07-24 02:57:39 +00:00
|
|
|
}
|
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
/* idle_combo */
|
2017-04-30 16:25:26 +00:00
|
|
|
if (n != 0)
|
2013-01-04 19:45:39 +00:00
|
|
|
{
|
2017-04-20 16:02:19 +00:00
|
|
|
int const baseline = tr_torrentGetIdleMode(torrents[0]);
|
2017-05-13 22:38:31 +00:00
|
|
|
bool is_uniform = true;
|
2013-01-04 19:45:39 +00:00
|
|
|
|
2017-05-13 22:38:31 +00:00
|
|
|
for (int i = 1; is_uniform && i < n; ++i)
|
2017-04-19 12:04:45 +00:00
|
|
|
{
|
2017-05-13 22:38:31 +00:00
|
|
|
is_uniform = baseline == (int)tr_torrentGetIdleMode(torrents[i]);
|
2017-04-19 12:04:45 +00:00
|
|
|
}
|
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
|
|
|
{
|
2017-04-19 12:04:45 +00:00
|
|
|
GtkWidget* w = di->idle_combo;
|
|
|
|
g_signal_handler_block(w, di->idle_combo_tag);
|
|
|
|
gtr_combo_box_set_active_enum(GTK_COMBO_BOX(w), baseline);
|
|
|
|
gtr_widget_set_visible(di->idle_spin, baseline == TR_IDLELIMIT_SINGLE);
|
|
|
|
g_signal_handler_unblock(w, di->idle_combo_tag);
|
2013-01-04 19:45:39 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
/* idle_spin */
|
2017-04-30 16:25:26 +00:00
|
|
|
if (n != 0)
|
2013-01-04 19:45:39 +00:00
|
|
|
{
|
2017-04-20 16:02:19 +00:00
|
|
|
int const baseline = tr_torrentGetIdleLimit(torrents[0]);
|
2017-04-19 12:04:45 +00:00
|
|
|
set_int_spin_if_different(di->idle_spin, di->idle_spin_tag, baseline);
|
2013-01-04 19:45:39 +00:00
|
|
|
}
|
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
/* max_peers_spin */
|
2017-04-30 16:25:26 +00:00
|
|
|
if (n != 0)
|
2013-01-04 19:45:39 +00:00
|
|
|
{
|
2017-04-20 16:02:19 +00:00
|
|
|
int const baseline = tr_torrentGetPeerLimit(torrents[0]);
|
2017-04-19 12:04:45 +00:00
|
|
|
set_int_spin_if_different(di->max_peers_spin, di->max_peers_spin_tag, baseline);
|
2008-09-23 19:11:04 +00:00
|
|
|
}
|
2007-06-06 00:30:13 +00:00
|
|
|
}
|
|
|
|
|
2017-04-20 16:02:19 +00:00
|
|
|
static void torrent_set_bool(struct DetailsImpl* di, tr_quark const key, gboolean value)
|
2007-06-06 00:30:13 +00:00
|
|
|
{
|
2017-05-01 15:46:41 +00:00
|
|
|
tr_variant top;
|
|
|
|
tr_variant* args;
|
|
|
|
tr_variant* ids;
|
2017-04-19 12:04:45 +00:00
|
|
|
|
|
|
|
tr_variantInitDict(&top, 2);
|
|
|
|
tr_variantDictAddStr(&top, TR_KEY_method, "torrent-set");
|
|
|
|
args = tr_variantDictAddDict(&top, TR_KEY_arguments, 2);
|
|
|
|
tr_variantDictAddBool(args, key, value);
|
|
|
|
ids = tr_variantDictAddList(args, TR_KEY_ids, g_slist_length(di->ids));
|
2009-04-24 01:37:04 +00:00
|
|
|
|
2017-05-13 22:38:31 +00:00
|
|
|
for (GSList* l = di->ids; l != NULL; l = l->next)
|
2017-04-19 12:04:45 +00:00
|
|
|
{
|
|
|
|
tr_variantListAddInt(ids, GPOINTER_TO_INT(l->data));
|
|
|
|
}
|
2009-04-24 01:37:04 +00:00
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
gtr_core_exec(di->core, &top);
|
|
|
|
tr_variantFree(&top);
|
2007-06-06 00:30:13 +00:00
|
|
|
}
|
|
|
|
|
2017-04-20 16:02:19 +00:00
|
|
|
static void torrent_set_int(struct DetailsImpl* di, tr_quark const key, int value)
|
2007-09-20 16:32:01 +00:00
|
|
|
{
|
2017-05-01 15:46:41 +00:00
|
|
|
tr_variant top;
|
|
|
|
tr_variant* args;
|
|
|
|
tr_variant* ids;
|
2009-04-24 01:37:04 +00:00
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
tr_variantInitDict(&top, 2);
|
|
|
|
tr_variantDictAddStr(&top, TR_KEY_method, "torrent-set");
|
|
|
|
args = tr_variantDictAddDict(&top, TR_KEY_arguments, 2);
|
|
|
|
tr_variantDictAddInt(args, key, value);
|
|
|
|
ids = tr_variantDictAddList(args, TR_KEY_ids, g_slist_length(di->ids));
|
2009-04-24 01:37:04 +00:00
|
|
|
|
2017-05-13 22:38:31 +00:00
|
|
|
for (GSList* l = di->ids; l != NULL; l = l->next)
|
2017-04-19 12:04:45 +00:00
|
|
|
{
|
|
|
|
tr_variantListAddInt(ids, GPOINTER_TO_INT(l->data));
|
|
|
|
}
|
|
|
|
|
|
|
|
gtr_core_exec(di->core, &top);
|
|
|
|
tr_variantFree(&top);
|
2007-09-20 16:32:01 +00:00
|
|
|
}
|
|
|
|
|
2017-04-20 16:02:19 +00:00
|
|
|
static void torrent_set_real(struct DetailsImpl* di, tr_quark const key, double value)
|
2007-06-06 00:30:13 +00:00
|
|
|
{
|
2017-05-01 15:46:41 +00:00
|
|
|
tr_variant top;
|
|
|
|
tr_variant* args;
|
|
|
|
tr_variant* ids;
|
2009-04-24 01:37:04 +00:00
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
tr_variantInitDict(&top, 2);
|
|
|
|
tr_variantDictAddStr(&top, TR_KEY_method, "torrent-set");
|
|
|
|
args = tr_variantDictAddDict(&top, TR_KEY_arguments, 2);
|
|
|
|
tr_variantDictAddReal(args, key, value);
|
|
|
|
ids = tr_variantDictAddList(args, TR_KEY_ids, g_slist_length(di->ids));
|
2009-04-24 01:37:04 +00:00
|
|
|
|
2017-05-13 22:38:31 +00:00
|
|
|
for (GSList* l = di->ids; l != NULL; l = l->next)
|
2017-04-19 12:04:45 +00:00
|
|
|
{
|
|
|
|
tr_variantListAddInt(ids, GPOINTER_TO_INT(l->data));
|
|
|
|
}
|
|
|
|
|
|
|
|
gtr_core_exec(di->core, &top);
|
|
|
|
tr_variantFree(&top);
|
2007-06-06 00:30:13 +00:00
|
|
|
}
|
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
static void up_speed_toggled_cb(GtkToggleButton* tb, gpointer d)
|
2007-06-06 00:30:13 +00:00
|
|
|
{
|
2017-04-19 12:04:45 +00:00
|
|
|
torrent_set_bool(d, TR_KEY_uploadLimited, gtk_toggle_button_get_active(tb));
|
2009-03-05 17:18:36 +00:00
|
|
|
}
|
2008-09-23 19:11:04 +00:00
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
static void down_speed_toggled_cb(GtkToggleButton* tb, gpointer d)
|
2009-03-05 17:18:36 +00:00
|
|
|
{
|
2017-04-19 12:04:45 +00:00
|
|
|
torrent_set_bool(d, TR_KEY_downloadLimited, gtk_toggle_button_get_active(tb));
|
2007-06-06 00:30:13 +00:00
|
|
|
}
|
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
static void global_speed_toggled_cb(GtkToggleButton* tb, gpointer d)
|
2007-06-06 00:30:13 +00:00
|
|
|
{
|
2017-04-19 12:04:45 +00:00
|
|
|
torrent_set_bool(d, TR_KEY_honorsSessionLimits, gtk_toggle_button_get_active(tb));
|
2007-06-06 00:30:13 +00:00
|
|
|
}
|
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
static void up_speed_spun_cb(GtkSpinButton* s, struct DetailsImpl* di)
|
2007-06-06 00:30:13 +00:00
|
|
|
{
|
2017-04-19 12:04:45 +00:00
|
|
|
torrent_set_int(di, TR_KEY_uploadLimit, gtk_spin_button_get_value_as_int(s));
|
2009-04-24 01:37:04 +00:00
|
|
|
}
|
2007-06-06 00:30:13 +00:00
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
static void down_speed_spun_cb(GtkSpinButton* s, struct DetailsImpl* di)
|
2009-04-24 01:37:04 +00:00
|
|
|
{
|
2017-04-19 12:04:45 +00:00
|
|
|
torrent_set_int(di, TR_KEY_downloadLimit, gtk_spin_button_get_value_as_int(s));
|
2009-04-24 01:37:04 +00:00
|
|
|
}
|
2008-09-23 19:11:04 +00:00
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
static void idle_spun_cb(GtkSpinButton* s, struct DetailsImpl* di)
|
2010-07-24 02:57:39 +00:00
|
|
|
{
|
2017-04-19 12:04:45 +00:00
|
|
|
torrent_set_int(di, TR_KEY_seedIdleLimit, gtk_spin_button_get_value_as_int(s));
|
2010-07-24 02:57:39 +00:00
|
|
|
}
|
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
static void ratio_spun_cb(GtkSpinButton* s, struct DetailsImpl* di)
|
2009-04-24 01:37:04 +00:00
|
|
|
{
|
2017-04-19 12:04:45 +00:00
|
|
|
torrent_set_real(di, TR_KEY_seedRatioLimit, gtk_spin_button_get_value(s));
|
2009-04-24 01:37:04 +00:00
|
|
|
}
|
2008-09-23 19:11:04 +00:00
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
static void max_peers_spun_cb(GtkSpinButton* s, struct DetailsImpl* di)
|
2009-04-24 01:37:04 +00:00
|
|
|
{
|
2017-04-19 12:04:45 +00:00
|
|
|
torrent_set_int(di, TR_KEY_peer_limit, gtk_spin_button_get_value(s));
|
2009-04-24 01:37:04 +00:00
|
|
|
}
|
2008-09-23 19:11:04 +00:00
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
static void onPriorityChanged(GtkComboBox* combo_box, struct DetailsImpl* di)
|
2009-04-24 01:37:04 +00:00
|
|
|
{
|
2017-04-20 16:02:19 +00:00
|
|
|
tr_priority_t const priority = gtr_priority_combo_get_value(combo_box);
|
2017-04-19 12:04:45 +00:00
|
|
|
torrent_set_int(di, TR_KEY_bandwidthPriority, priority);
|
2007-06-06 00:30:13 +00:00
|
|
|
}
|
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
static GtkWidget* new_priority_combo(struct DetailsImpl* di)
|
2008-04-12 01:36:31 +00:00
|
|
|
{
|
2017-04-19 12:04:45 +00:00
|
|
|
GtkWidget* w = gtr_priority_combo_new();
|
|
|
|
di->bandwidth_combo_tag = g_signal_connect(w, "changed", G_CALLBACK(onPriorityChanged), di);
|
|
|
|
return w;
|
2008-04-12 01:36:31 +00:00
|
|
|
}
|
2008-09-23 19:11:04 +00:00
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
static void refresh(struct DetailsImpl* di);
|
2010-07-24 02:57:39 +00:00
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
static void onComboEnumChanged(GtkComboBox* combo_box, struct DetailsImpl* di)
|
2010-07-24 02:57:39 +00:00
|
|
|
{
|
2017-04-20 16:02:19 +00:00
|
|
|
tr_quark const key = GPOINTER_TO_INT(g_object_get_qdata(G_OBJECT(combo_box), ARG_KEY));
|
2017-04-19 12:04:45 +00:00
|
|
|
torrent_set_int(di, key, gtr_combo_box_get_active_enum(combo_box));
|
|
|
|
refresh(di);
|
2010-07-24 02:57:39 +00:00
|
|
|
}
|
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
static GtkWidget* ratio_combo_new(void)
|
2012-12-05 17:29:46 +00:00
|
|
|
{
|
2017-04-19 12:04:45 +00:00
|
|
|
GtkWidget* w = gtr_combo_box_new_enum(
|
2017-04-21 07:40:57 +00:00
|
|
|
_("Use global settings"), TR_RATIOLIMIT_GLOBAL,
|
|
|
|
_("Seed regardless of ratio"), TR_RATIOLIMIT_UNLIMITED,
|
|
|
|
_("Stop seeding at ratio:"), TR_RATIOLIMIT_SINGLE,
|
|
|
|
NULL);
|
2017-04-19 12:04:45 +00:00
|
|
|
g_object_set_qdata(G_OBJECT(w), ARG_KEY, GINT_TO_POINTER(TR_KEY_seedRatioMode));
|
|
|
|
return w;
|
2010-07-24 02:57:39 +00:00
|
|
|
}
|
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
static GtkWidget* idle_combo_new(void)
|
2010-07-24 02:57:39 +00:00
|
|
|
{
|
2017-04-19 12:04:45 +00:00
|
|
|
GtkWidget* w = gtr_combo_box_new_enum(
|
2017-04-21 07:40:57 +00:00
|
|
|
_("Use global settings"), TR_IDLELIMIT_GLOBAL,
|
|
|
|
_("Seed regardless of activity"), TR_IDLELIMIT_UNLIMITED,
|
|
|
|
_("Stop seeding if idle for N minutes:"), TR_IDLELIMIT_SINGLE,
|
|
|
|
NULL);
|
2017-04-19 12:04:45 +00:00
|
|
|
g_object_set_qdata(G_OBJECT(w), ARG_KEY, GINT_TO_POINTER(TR_KEY_seedIdleMode));
|
|
|
|
return w;
|
2010-07-24 02:57:39 +00:00
|
|
|
}
|
2008-04-12 01:36:31 +00:00
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
static GtkWidget* options_page_new(struct DetailsImpl* d)
|
|
|
|
{
|
|
|
|
guint row;
|
|
|
|
gulong tag;
|
|
|
|
char buf[128];
|
2017-05-01 15:46:41 +00:00
|
|
|
GtkWidget* t;
|
|
|
|
GtkWidget* w;
|
|
|
|
GtkWidget* tb;
|
|
|
|
GtkWidget* h;
|
2017-04-19 12:04:45 +00:00
|
|
|
|
|
|
|
row = 0;
|
|
|
|
t = hig_workarea_create();
|
|
|
|
hig_workarea_add_section_title(t, &row, _("Speed"));
|
|
|
|
|
|
|
|
tb = hig_workarea_add_wide_checkbutton(t, &row, _("Honor global _limits"), 0);
|
|
|
|
d->honor_limits_check = tb;
|
|
|
|
tag = g_signal_connect(tb, "toggled", G_CALLBACK(global_speed_toggled_cb), d);
|
|
|
|
d->honor_limits_check_tag = tag;
|
|
|
|
|
|
|
|
g_snprintf(buf, sizeof(buf), _("Limit _download speed (%s):"), _(speed_K_str));
|
|
|
|
tb = gtk_check_button_new_with_mnemonic(buf);
|
|
|
|
gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(tb), FALSE);
|
|
|
|
d->down_limited_check = tb;
|
|
|
|
tag = g_signal_connect(tb, "toggled", G_CALLBACK(down_speed_toggled_cb), d);
|
|
|
|
d->down_limited_check_tag = tag;
|
|
|
|
|
|
|
|
w = gtk_spin_button_new_with_range(0, INT_MAX, 5);
|
|
|
|
tag = g_signal_connect(w, "value-changed", G_CALLBACK(down_speed_spun_cb), d);
|
|
|
|
d->down_limit_spin_tag = tag;
|
|
|
|
hig_workarea_add_row_w(t, &row, tb, w, NULL);
|
|
|
|
d->down_limit_spin = w;
|
|
|
|
|
|
|
|
g_snprintf(buf, sizeof(buf), _("Limit _upload speed (%s):"), _(speed_K_str));
|
|
|
|
tb = gtk_check_button_new_with_mnemonic(buf);
|
|
|
|
d->up_limited_check = tb;
|
|
|
|
tag = g_signal_connect(tb, "toggled", G_CALLBACK(up_speed_toggled_cb), d);
|
|
|
|
d->up_limited_check_tag = tag;
|
|
|
|
|
|
|
|
w = gtk_spin_button_new_with_range(0, INT_MAX, 5);
|
|
|
|
tag = g_signal_connect(w, "value-changed", G_CALLBACK(up_speed_spun_cb), d);
|
|
|
|
d->up_limit_spin_tag = tag;
|
|
|
|
hig_workarea_add_row_w(t, &row, tb, w, NULL);
|
|
|
|
d->up_limit_sping = w;
|
|
|
|
|
|
|
|
w = new_priority_combo(d);
|
|
|
|
hig_workarea_add_row(t, &row, _("Torrent _priority:"), w, NULL);
|
|
|
|
d->bandwidth_combo = w;
|
|
|
|
|
|
|
|
hig_workarea_add_section_divider(t, &row);
|
|
|
|
hig_workarea_add_section_title(t, &row, _("Seeding Limits"));
|
|
|
|
|
|
|
|
h = gtk_box_new(GTK_ORIENTATION_HORIZONTAL, GUI_PAD);
|
|
|
|
w = d->ratio_combo = ratio_combo_new();
|
|
|
|
d->ratio_combo_tag = g_signal_connect(w, "changed", G_CALLBACK(onComboEnumChanged), d);
|
|
|
|
gtk_box_pack_start(GTK_BOX(h), w, TRUE, TRUE, 0);
|
|
|
|
w = d->ratio_spin = gtk_spin_button_new_with_range(0, 1000, .05);
|
|
|
|
gtk_entry_set_width_chars(GTK_ENTRY(w), 7);
|
|
|
|
d->ratio_spin_tag = g_signal_connect(w, "value-changed", G_CALLBACK(ratio_spun_cb), d);
|
|
|
|
gtk_box_pack_start(GTK_BOX(h), w, FALSE, FALSE, 0);
|
|
|
|
hig_workarea_add_row(t, &row, _("_Ratio:"), h, NULL);
|
|
|
|
|
|
|
|
h = gtk_box_new(GTK_ORIENTATION_HORIZONTAL, GUI_PAD);
|
|
|
|
w = d->idle_combo = idle_combo_new();
|
|
|
|
d->idle_combo_tag = g_signal_connect(w, "changed", G_CALLBACK(onComboEnumChanged), d);
|
|
|
|
gtk_box_pack_start(GTK_BOX(h), w, TRUE, TRUE, 0);
|
2017-07-05 18:07:16 +00:00
|
|
|
w = d->idle_spin = gtk_spin_button_new_with_range(1, 40320, 5);
|
2017-04-19 12:04:45 +00:00
|
|
|
d->idle_spin_tag = g_signal_connect(w, "value-changed", G_CALLBACK(idle_spun_cb), d);
|
|
|
|
gtk_box_pack_start(GTK_BOX(h), w, FALSE, FALSE, 0);
|
|
|
|
hig_workarea_add_row(t, &row, _("_Idle:"), h, NULL);
|
|
|
|
|
|
|
|
hig_workarea_add_section_divider(t, &row);
|
|
|
|
hig_workarea_add_section_title(t, &row, _("Peer Connections"));
|
|
|
|
|
|
|
|
w = gtk_spin_button_new_with_range(1, 3000, 5);
|
|
|
|
hig_workarea_add_row(t, &row, _("_Maximum peers:"), w, w);
|
|
|
|
tag = g_signal_connect(w, "value-changed", G_CALLBACK(max_peers_spun_cb), d);
|
|
|
|
d->max_peers_spin = w;
|
|
|
|
d->max_peers_spin_tag = tag;
|
|
|
|
|
|
|
|
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
|
|
|
****/
|
|
|
|
|
2017-04-20 16:02:19 +00:00
|
|
|
static char const* 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
|
|
|
|
2017-04-19 12:04:45 +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 */
|
2017-04-20 16:02:19 +00:00
|
|
|
static void gtr_text_buffer_set_text(GtkTextBuffer* b, char const* str)
|
2010-02-19 14:49:03 +00:00
|
|
|
{
|
2017-04-19 12:04:45 +00:00
|
|
|
char* old_str;
|
2017-05-01 15:46:41 +00:00
|
|
|
GtkTextIter start;
|
|
|
|
GtkTextIter end;
|
2010-02-19 14:49:03 +00:00
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
if (str == NULL)
|
|
|
|
{
|
|
|
|
str = "";
|
|
|
|
}
|
2010-02-19 14:49:03 +00:00
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
gtk_text_buffer_get_bounds(b, &start, &end);
|
|
|
|
old_str = gtk_text_buffer_get_text(b, &start, &end, FALSE);
|
2010-02-19 14:49:03 +00:00
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
if (old_str == NULL || g_strcmp0(old_str, str) != 0)
|
|
|
|
{
|
|
|
|
gtk_text_buffer_set_text(b, str, -1);
|
|
|
|
}
|
2010-02-19 14:49:03 +00:00
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
g_free(old_str);
|
2010-02-19 14:49:03 +00:00
|
|
|
}
|
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
static char* 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
|
|
|
{
|
|
|
|
return g_strdup(_("N/A"));
|
|
|
|
}
|
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);
|
|
|
|
return g_locale_to_utf8(buf, -1, NULL, NULL, NULL);
|
2020-08-11 18:11:55 +00:00
|
|
|
}
|
2010-05-28 19:43:37 +00:00
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
static void refreshInfo(struct DetailsImpl* di, tr_torrent** torrents, int n)
|
2007-06-06 00:30:13 +00:00
|
|
|
{
|
2017-04-20 16:02:19 +00:00
|
|
|
char const* str;
|
|
|
|
char const* mixed = _("Mixed");
|
|
|
|
char const* no_torrent = _("No Torrents Selected");
|
|
|
|
char const* stateString;
|
2017-04-19 12:04:45 +00:00
|
|
|
char buf[512];
|
|
|
|
uint64_t sizeWhenDone = 0;
|
2017-04-20 16:02:19 +00:00
|
|
|
tr_stat const** stats = g_new(tr_stat const*, n);
|
|
|
|
tr_info const** infos = g_new(tr_info const*, n);
|
2013-01-04 19:45:39 +00:00
|
|
|
|
2017-05-13 22:38:31 +00:00
|
|
|
for (int i = 0; i < n; ++i)
|
2013-01-04 19:45:39 +00:00
|
|
|
{
|
2017-04-19 12:04:45 +00:00
|
|
|
stats[i] = tr_torrentStatCached(torrents[i]);
|
|
|
|
infos[i] = tr_torrentInfo(torrents[i]);
|
2013-01-04 19:45:39 +00:00
|
|
|
}
|
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
/* privacy_lb */
|
|
|
|
if (n <= 0)
|
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-20 16:02:19 +00:00
|
|
|
bool const baseline = infos[0]->isPrivate;
|
2017-05-13 22:38:31 +00:00
|
|
|
bool is_uniform = true;
|
2013-01-04 19:45:39 +00:00
|
|
|
|
2017-05-13 22:38:31 +00:00
|
|
|
for (int i = 1; is_uniform && i < n; ++i)
|
2017-04-19 12:04:45 +00:00
|
|
|
{
|
2017-05-13 22:38:31 +00:00
|
|
|
is_uniform = baseline == infos[i]->isPrivate;
|
2017-04-19 12:04:45 +00:00
|
|
|
}
|
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
|
|
|
}
|
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
gtr_label_set_text(GTK_LABEL(di->privacy_lb), str);
|
2009-06-23 00:24:37 +00:00
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
/* origin_lb */
|
|
|
|
if (n <= 0)
|
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-13 22:38:31 +00:00
|
|
|
char const* creator = infos[0]->creator != NULL ? infos[0]->creator : "";
|
2017-04-20 16:02:19 +00:00
|
|
|
time_t const date = infos[0]->dateCreated;
|
2017-04-19 12:04:45 +00:00
|
|
|
char* datestr = get_short_date_string(date);
|
|
|
|
gboolean mixed_creator = FALSE;
|
|
|
|
gboolean mixed_date = FALSE;
|
2010-05-28 19:43:37 +00:00
|
|
|
|
2017-05-13 22:38:31 +00:00
|
|
|
for (int i = 1; i < n; ++i)
|
2013-01-04 19:45:39 +00:00
|
|
|
{
|
2017-05-13 22:38:31 +00:00
|
|
|
mixed_creator |= g_strcmp0(creator, infos[i]->creator != NULL ? infos[i]->creator : "") != 0;
|
|
|
|
mixed_date |= date != infos[i]->dateCreated;
|
2009-06-23 00:24:37 +00:00
|
|
|
}
|
2013-01-04 19:45:39 +00:00
|
|
|
|
2019-07-13 08:52:44 +00:00
|
|
|
gboolean const empty_creator = tr_str_is_empty(creator);
|
2017-04-20 16:02:19 +00:00
|
|
|
gboolean 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)
|
|
|
|
{
|
|
|
|
g_snprintf(buf, sizeof(buf), _("Created by %1$s"), creator);
|
|
|
|
}
|
|
|
|
else if (empty_creator && !empty_date)
|
|
|
|
{
|
|
|
|
g_snprintf(buf, sizeof(buf), _("Created on %1$s"), datestr);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
g_snprintf(buf, sizeof(buf), _("Created by %1$s on %2$s"), creator, datestr);
|
|
|
|
}
|
|
|
|
|
|
|
|
str = buf;
|
2009-08-04 03:10:35 +00:00
|
|
|
}
|
2010-05-28 19:43:37 +00:00
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
g_free(datestr);
|
2009-06-23 00:24:37 +00:00
|
|
|
}
|
2017-04-19 12:04:45 +00:00
|
|
|
|
|
|
|
gtr_label_set_text(GTK_LABEL(di->origin_lb), str);
|
2009-06-23 00:24:37 +00:00
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
/* comment_buffer */
|
|
|
|
if (n <= 0)
|
2013-01-04 19:45:39 +00:00
|
|
|
{
|
2017-04-19 12:04:45 +00:00
|
|
|
str = "";
|
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
|
|
|
{
|
2017-05-01 15:47:49 +00:00
|
|
|
char const* baseline = infos[0]->comment != NULL ? infos[0]->comment : "";
|
2017-05-13 22:38:31 +00:00
|
|
|
bool is_uniform = true;
|
2009-06-23 00:24:37 +00:00
|
|
|
|
2017-05-13 22:38:31 +00:00
|
|
|
for (int i = 1; is_uniform && i < n; ++i)
|
2017-04-19 12:04:45 +00:00
|
|
|
{
|
2017-05-13 22:38:31 +00:00
|
|
|
is_uniform = g_strcmp0(baseline, infos[i]->comment != NULL ? infos[i]->comment : "") == 0;
|
2017-04-19 12:04:45 +00:00
|
|
|
}
|
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
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
gtr_text_buffer_set_text(di->comment_buffer, str);
|
|
|
|
|
|
|
|
/* destination_lb */
|
|
|
|
if (n <= 0)
|
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-20 16:02:19 +00:00
|
|
|
char const* baseline = tr_torrentGetDownloadDir(torrents[0]);
|
2017-05-13 22:38:31 +00:00
|
|
|
bool is_uniform = true;
|
2009-10-10 20:42:23 +00:00
|
|
|
|
2017-05-13 22:38:31 +00:00
|
|
|
for (int i = 1; is_uniform && i < n; ++i)
|
2017-04-19 12:04:45 +00:00
|
|
|
{
|
2017-05-13 22:38:31 +00:00
|
|
|
is_uniform = g_strcmp0(baseline, tr_torrentGetDownloadDir(torrents[i])) == 0;
|
2017-04-19 12:04:45 +00:00
|
|
|
}
|
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
|
|
|
}
|
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
gtr_label_set_text(GTK_LABEL(di->destination_lb), str);
|
|
|
|
|
|
|
|
/* state_lb */
|
|
|
|
if (n <= 0)
|
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
|
|
|
{
|
2017-04-20 16:02:19 +00:00
|
|
|
tr_torrent_activity const activity = stats[0]->activity;
|
2017-05-13 22:38:31 +00:00
|
|
|
bool is_uniform = true;
|
2017-04-19 12:04:45 +00:00
|
|
|
bool allFinished = stats[0]->finished;
|
2013-01-04 19:45:39 +00:00
|
|
|
|
2017-05-13 22:38:31 +00:00
|
|
|
for (int i = 1; is_uniform && i < n; ++i)
|
2010-09-17 05:43:06 +00:00
|
|
|
{
|
2017-05-13 22:38:31 +00:00
|
|
|
is_uniform = activity == stats[i]->activity;
|
2017-04-19 12:04:45 +00:00
|
|
|
|
|
|
|
if (!stats[i]->finished)
|
|
|
|
{
|
2017-04-30 16:25:26 +00:00
|
|
|
allFinished = false;
|
2017-04-19 12:04:45 +00:00
|
|
|
}
|
2009-04-24 01:37:04 +00:00
|
|
|
}
|
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;
|
|
|
|
gtr_label_set_text(GTK_LABEL(di->state_lb), str);
|
2013-01-04 19:45:39 +00:00
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
/* date started */
|
|
|
|
if (n <= 0)
|
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-20 16:02:19 +00:00
|
|
|
time_t const baseline = stats[0]->startDate;
|
2017-05-13 22:38:31 +00:00
|
|
|
bool is_uniform = true;
|
2013-01-04 19:45:39 +00:00
|
|
|
|
2017-05-13 22:38:31 +00:00
|
|
|
for (int i = 1; is_uniform && i < n; ++i)
|
2017-04-19 12:04:45 +00:00
|
|
|
{
|
2017-05-13 22:38:31 +00:00
|
|
|
is_uniform = baseline == stats[i]->startDate;
|
2017-04-19 12:04:45 +00:00
|
|
|
}
|
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
|
|
|
|
{
|
|
|
|
str = tr_strltime(buf, time(NULL) - baseline, sizeof(buf));
|
|
|
|
}
|
2013-01-04 19:45:39 +00:00
|
|
|
}
|
2017-04-19 12:04:45 +00:00
|
|
|
|
|
|
|
gtr_label_set_text(GTK_LABEL(di->date_started_lb), str);
|
2013-01-04 19:45:39 +00:00
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
/* eta */
|
|
|
|
if (n <= 0)
|
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
|
|
|
{
|
2017-04-20 16:02:19 +00:00
|
|
|
int const baseline = stats[0]->eta;
|
2017-05-13 22:38:31 +00:00
|
|
|
bool is_uniform = true;
|
2013-01-04 19:45:39 +00:00
|
|
|
|
2017-05-13 22:38:31 +00:00
|
|
|
for (int i = 1; is_uniform && i < n; ++i)
|
2017-04-19 12:04:45 +00:00
|
|
|
{
|
2017-05-13 22:38:31 +00:00
|
|
|
is_uniform = baseline == stats[i]->eta;
|
2017-04-19 12:04:45 +00:00
|
|
|
}
|
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
|
|
|
|
{
|
|
|
|
str = tr_strltime(buf, baseline, sizeof(buf));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
gtr_label_set_text(GTK_LABEL(di->eta_lb), str);
|
|
|
|
|
|
|
|
/* size_lb */
|
|
|
|
{
|
|
|
|
char sizebuf[128];
|
|
|
|
uint64_t size = 0;
|
|
|
|
int pieces = 0;
|
|
|
|
int32_t pieceSize = 0;
|
|
|
|
|
2017-05-13 22:38:31 +00:00
|
|
|
for (int i = 0; i < n; ++i)
|
2017-04-19 12:04:45 +00:00
|
|
|
{
|
|
|
|
size += infos[i]->totalSize;
|
|
|
|
pieces += infos[i]->pieceCount;
|
|
|
|
|
2017-04-30 16:25:26 +00:00
|
|
|
if (pieceSize == 0)
|
2017-04-19 12:04:45 +00:00
|
|
|
{
|
|
|
|
pieceSize = infos[i]->pieceSize;
|
|
|
|
}
|
|
|
|
else if (pieceSize != (int)infos[i]->pieceSize)
|
|
|
|
{
|
|
|
|
pieceSize = -1;
|
|
|
|
}
|
|
|
|
}
|
2013-01-04 19:45:39 +00:00
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
tr_strlsize(sizebuf, size, sizeof(sizebuf));
|
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
|
|
|
{
|
|
|
|
str = "";
|
|
|
|
}
|
|
|
|
else if (pieceSize >= 0)
|
|
|
|
{
|
|
|
|
char piecebuf[128];
|
|
|
|
tr_formatter_mem_B(piecebuf, pieceSize, sizeof(piecebuf));
|
2017-04-30 16:25:26 +00:00
|
|
|
g_snprintf(buf, sizeof(buf), 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
|
|
|
str = buf;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
g_snprintf(buf, sizeof(buf), ngettext("%1$s (%2$'d piece)", "%1$s (%2$'d pieces)", pieces), sizebuf, pieces);
|
|
|
|
str = buf;
|
|
|
|
}
|
|
|
|
|
|
|
|
gtr_label_set_text(GTK_LABEL(di->size_lb), str);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* have_lb */
|
|
|
|
if (n <= 0)
|
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
|
|
|
|
2017-05-13 22:38:31 +00:00
|
|
|
for (int i = 0; i < n; ++i)
|
2013-01-04 19:45:39 +00:00
|
|
|
{
|
2017-04-20 16:02:19 +00:00
|
|
|
tr_stat const* st = stats[i];
|
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:46:41 +00:00
|
|
|
char buf2[32];
|
|
|
|
char unver[64];
|
|
|
|
char total[64];
|
|
|
|
char avail[32];
|
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
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
tr_strlpercent(avail, d, sizeof(avail));
|
|
|
|
tr_strlpercent(buf2, ratio, sizeof(buf2));
|
|
|
|
tr_strlsize(total, haveUnchecked + haveValid, sizeof(total));
|
2017-04-21 07:40:57 +00:00
|
|
|
tr_strlsize(unver, haveUnchecked, sizeof(unver));
|
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
|
|
|
{
|
|
|
|
g_snprintf(buf, sizeof(buf), _("%1$s (%2$s%%)"), total, buf2);
|
|
|
|
}
|
2017-04-30 16:25:26 +00:00
|
|
|
else if (haveUnchecked == 0)
|
2017-04-19 12:04:45 +00:00
|
|
|
{
|
|
|
|
g_snprintf(buf, sizeof(buf), _("%1$s (%2$s%% of %3$s%% Available)"), total, buf2, avail);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2017-04-21 07:40:57 +00:00
|
|
|
g_snprintf(buf, sizeof(buf), _("%1$s (%2$s%% of %3$s%% Available); %4$s Unverified"), total, buf2, avail,
|
|
|
|
unver);
|
2017-04-19 12:04:45 +00:00
|
|
|
}
|
2013-01-04 19:45:39 +00:00
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
str = buf;
|
|
|
|
}
|
2009-04-24 01:37:04 +00:00
|
|
|
}
|
2007-06-06 00:30:13 +00:00
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
gtr_label_set_text(GTK_LABEL(di->have_lb), str);
|
|
|
|
|
|
|
|
/* dl_lb */
|
|
|
|
if (n <= 0)
|
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
|
|
|
char dbuf[64];
|
|
|
|
char fbuf[64];
|
|
|
|
uint64_t d = 0;
|
|
|
|
uint64_t f = 0;
|
2009-08-10 20:04:08 +00:00
|
|
|
|
2017-05-13 22:38:31 +00:00
|
|
|
for (int i = 0; i < n; ++i)
|
2013-01-04 19:45:39 +00:00
|
|
|
{
|
2017-04-19 12:04:45 +00:00
|
|
|
d += stats[i]->downloadedEver;
|
|
|
|
f += stats[i]->corruptEver;
|
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_strlsize(dbuf, d, sizeof(dbuf));
|
|
|
|
tr_strlsize(fbuf, f, sizeof(fbuf));
|
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
|
|
|
{
|
|
|
|
g_snprintf(buf, sizeof(buf), _("%1$s (+%2$s corrupt)"), dbuf, fbuf);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
tr_strlcpy(buf, dbuf, sizeof(buf));
|
|
|
|
}
|
|
|
|
|
|
|
|
str = buf;
|
2009-04-24 01:37:04 +00:00
|
|
|
}
|
2007-06-06 00:30:13 +00:00
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
gtr_label_set_text(GTK_LABEL(di->dl_lb), str);
|
2013-01-04 19:45:39 +00:00
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
/* ul_lb */
|
|
|
|
if (n <= 0)
|
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
|
|
|
char upstr[64];
|
|
|
|
char ratiostr[64];
|
|
|
|
uint64_t up = 0;
|
|
|
|
uint64_t down = 0;
|
2013-01-04 19:45:39 +00:00
|
|
|
|
2017-05-13 22:38:31 +00:00
|
|
|
for (int i = 0; i < n; ++i)
|
2013-01-04 19:45:39 +00:00
|
|
|
{
|
2017-04-19 12:04:45 +00:00
|
|
|
up += stats[i]->uploadedEver;
|
|
|
|
down += stats[i]->downloadedEver;
|
2013-01-04 19:45:39 +00:00
|
|
|
}
|
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
tr_strlsize(upstr, up, sizeof(upstr));
|
|
|
|
tr_strlratio(ratiostr, tr_getRatio(up, down), sizeof(ratiostr));
|
|
|
|
g_snprintf(buf, sizeof(buf), _("%s (Ratio: %s)"), upstr, ratiostr);
|
|
|
|
str = buf;
|
2013-01-04 19:45:39 +00:00
|
|
|
}
|
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
gtr_label_set_text(GTK_LABEL(di->ul_lb), str);
|
2013-01-04 19:45:39 +00:00
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
/* hash_lb */
|
|
|
|
if (n <= 0)
|
|
|
|
{
|
|
|
|
str = no_torrent;
|
|
|
|
}
|
|
|
|
else if (n == 1)
|
2013-01-04 19:45:39 +00:00
|
|
|
{
|
2017-04-19 12:04:45 +00:00
|
|
|
str = infos[0]->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
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
gtr_label_set_text(GTK_LABEL(di->hash_lb), str);
|
2013-01-04 19:45:39 +00:00
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
/* error */
|
|
|
|
if (n <= 0)
|
|
|
|
{
|
|
|
|
str = no_torrent;
|
2013-01-04 19:45:39 +00:00
|
|
|
}
|
2017-04-19 12:04:45 +00:00
|
|
|
else
|
|
|
|
{
|
2017-04-20 16:02:19 +00:00
|
|
|
char const* baseline = stats[0]->errorString;
|
2017-05-13 22:38:31 +00:00
|
|
|
bool is_uniform = true;
|
2009-11-29 08:27:55 +00:00
|
|
|
|
2017-05-13 22:38:31 +00:00
|
|
|
for (int i = 1; is_uniform && i < n; ++i)
|
2017-04-19 12:04:45 +00:00
|
|
|
{
|
2017-05-13 22:38:31 +00:00
|
|
|
is_uniform = g_strcmp0(baseline, stats[i]->errorString) == 0;
|
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
|
|
|
}
|
|
|
|
|
2019-07-13 08:52:44 +00:00
|
|
|
if (tr_str_is_empty(str))
|
2017-04-19 12:04:45 +00:00
|
|
|
{
|
|
|
|
str = _("No errors");
|
|
|
|
}
|
|
|
|
|
|
|
|
gtr_label_set_text(GTK_LABEL(di->error_lb), str);
|
2013-01-04 19:45:39 +00:00
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
/* activity date */
|
|
|
|
if (n <= 0)
|
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
|
|
|
time_t latest = 0;
|
2013-01-04 19:45:39 +00:00
|
|
|
|
2017-05-13 22:38:31 +00:00
|
|
|
for (int i = 0; i < n; ++i)
|
2017-04-19 12:04:45 +00:00
|
|
|
{
|
|
|
|
if (latest < stats[i]->activityDate)
|
|
|
|
{
|
|
|
|
latest = stats[i]->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
|
|
|
{
|
2017-04-20 16:02:19 +00:00
|
|
|
int const period = time(NULL) - latest;
|
2017-04-19 12:04:45 +00:00
|
|
|
|
|
|
|
if (period < 5)
|
2013-01-04 19:45:39 +00:00
|
|
|
{
|
2017-04-19 12:04:45 +00:00
|
|
|
tr_strlcpy(buf, _("Active now"), sizeof(buf));
|
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
|
|
|
{
|
2017-04-19 12:04:45 +00:00
|
|
|
char tbuf[128];
|
|
|
|
tr_strltime(tbuf, period, sizeof(tbuf));
|
|
|
|
g_snprintf(buf, sizeof(buf), _("%1$s ago"), tbuf);
|
2013-01-04 19:45:39 +00:00
|
|
|
}
|
2017-04-19 12:04:45 +00:00
|
|
|
|
|
|
|
str = buf;
|
2009-06-23 00:24:37 +00:00
|
|
|
}
|
2009-04-24 01:37:04 +00:00
|
|
|
}
|
2008-09-23 19:11:04 +00:00
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
gtr_label_set_text(GTK_LABEL(di->last_activity_lb), str);
|
|
|
|
|
|
|
|
g_free(stats);
|
|
|
|
g_free(infos);
|
2007-06-06 00:30:13 +00:00
|
|
|
}
|
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
static GtkWidget* info_page_new(struct DetailsImpl* di)
|
2007-06-06 00:30:13 +00:00
|
|
|
{
|
2017-04-19 12:04:45 +00:00
|
|
|
guint row = 0;
|
|
|
|
GtkTextBuffer* b;
|
2017-05-01 15:46:41 +00:00
|
|
|
GtkWidget* l;
|
|
|
|
GtkWidget* w;
|
|
|
|
GtkWidget* fr;
|
|
|
|
GtkWidget* sw;
|
2017-04-19 12:04:45 +00:00
|
|
|
GtkWidget* t = hig_workarea_create();
|
2013-01-04 19:45:39 +00:00
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
hig_workarea_add_section_title(t, &row, _("Activity"));
|
2013-01-04 19:45:39 +00:00
|
|
|
|
|
|
|
/* size */
|
2017-04-19 12:04:45 +00:00
|
|
|
l = di->size_lb = gtk_label_new(NULL);
|
|
|
|
gtk_label_set_single_line_mode(GTK_LABEL(l), TRUE);
|
|
|
|
hig_workarea_add_row(t, &row, _("Torrent size:"), l, NULL);
|
2013-01-04 19:45:39 +00:00
|
|
|
|
|
|
|
/* have */
|
2017-04-19 12:04:45 +00:00
|
|
|
l = di->have_lb = gtk_label_new(NULL);
|
|
|
|
gtk_label_set_single_line_mode(GTK_LABEL(l), TRUE);
|
|
|
|
hig_workarea_add_row(t, &row, _("Have:"), l, NULL);
|
2013-01-04 19:45:39 +00:00
|
|
|
|
|
|
|
/* uploaded */
|
2017-04-19 12:04:45 +00:00
|
|
|
l = di->ul_lb = gtk_label_new(NULL);
|
|
|
|
gtk_label_set_single_line_mode(GTK_LABEL(l), TRUE);
|
|
|
|
hig_workarea_add_row(t, &row, _("Uploaded:"), l, NULL);
|
2013-01-04 19:45:39 +00:00
|
|
|
|
2014-01-20 23:56:06 +00:00
|
|
|
/* downloaded */
|
2017-04-19 12:04:45 +00:00
|
|
|
l = di->dl_lb = gtk_label_new(NULL);
|
|
|
|
gtk_label_set_single_line_mode(GTK_LABEL(l), TRUE);
|
|
|
|
hig_workarea_add_row(t, &row, _("Downloaded:"), l, NULL);
|
2014-01-20 23:56:06 +00:00
|
|
|
|
2013-01-04 19:45:39 +00:00
|
|
|
/* state */
|
2017-04-19 12:04:45 +00:00
|
|
|
l = di->state_lb = gtk_label_new(NULL);
|
|
|
|
gtk_label_set_single_line_mode(GTK_LABEL(l), TRUE);
|
|
|
|
hig_workarea_add_row(t, &row, _("State:"), l, NULL);
|
2013-01-04 19:45:39 +00:00
|
|
|
|
|
|
|
/* running for */
|
2017-04-19 12:04:45 +00:00
|
|
|
l = di->date_started_lb = gtk_label_new(NULL);
|
|
|
|
gtk_label_set_single_line_mode(GTK_LABEL(l), TRUE);
|
|
|
|
hig_workarea_add_row(t, &row, _("Running time:"), l, NULL);
|
2013-01-04 19:45:39 +00:00
|
|
|
|
|
|
|
/* eta */
|
2017-04-19 12:04:45 +00:00
|
|
|
l = di->eta_lb = gtk_label_new(NULL);
|
|
|
|
gtk_label_set_single_line_mode(GTK_LABEL(l), TRUE);
|
|
|
|
hig_workarea_add_row(t, &row, _("Remaining time:"), l, NULL);
|
2013-01-04 19:45:39 +00:00
|
|
|
|
|
|
|
/* last activity */
|
2017-04-19 12:04:45 +00:00
|
|
|
l = di->last_activity_lb = gtk_label_new(NULL);
|
|
|
|
gtk_label_set_single_line_mode(GTK_LABEL(l), TRUE);
|
|
|
|
hig_workarea_add_row(t, &row, _("Last activity:"), l, NULL);
|
2013-01-04 19:45:39 +00:00
|
|
|
|
|
|
|
/* error */
|
2017-04-19 12:04:45 +00:00
|
|
|
l = g_object_new(GTK_TYPE_LABEL, "selectable", TRUE, "ellipsize", PANGO_ELLIPSIZE_END, NULL);
|
|
|
|
hig_workarea_add_row(t, &row, _("Error:"), l, NULL);
|
2013-01-04 19:45:39 +00:00
|
|
|
di->error_lb = l;
|
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
hig_workarea_add_section_divider(t, &row);
|
|
|
|
hig_workarea_add_section_title(t, &row, _("Details"));
|
2013-01-04 19:45:39 +00:00
|
|
|
|
|
|
|
/* destination */
|
2017-04-19 12:04:45 +00:00
|
|
|
l = g_object_new(GTK_TYPE_LABEL, "selectable", TRUE, "ellipsize", PANGO_ELLIPSIZE_END, NULL);
|
|
|
|
hig_workarea_add_row(t, &row, _("Location:"), l, NULL);
|
2013-01-04 19:45:39 +00:00
|
|
|
di->destination_lb = l;
|
|
|
|
|
|
|
|
/* hash */
|
2017-04-19 12:04:45 +00:00
|
|
|
l = g_object_new(GTK_TYPE_LABEL, "selectable", TRUE, "ellipsize", PANGO_ELLIPSIZE_END, NULL);
|
|
|
|
hig_workarea_add_row(t, &row, _("Hash:"), l, NULL);
|
2013-01-04 19:45:39 +00:00
|
|
|
di->hash_lb = l;
|
|
|
|
|
|
|
|
/* privacy */
|
2017-04-19 12:04:45 +00:00
|
|
|
l = gtk_label_new(NULL);
|
|
|
|
gtk_label_set_single_line_mode(GTK_LABEL(l), TRUE);
|
|
|
|
hig_workarea_add_row(t, &row, _("Privacy:"), l, NULL);
|
2013-01-04 19:45:39 +00:00
|
|
|
di->privacy_lb = l;
|
|
|
|
|
|
|
|
/* origins */
|
2017-04-19 12:04:45 +00:00
|
|
|
l = g_object_new(GTK_TYPE_LABEL, "selectable", TRUE, "ellipsize", PANGO_ELLIPSIZE_END, NULL);
|
|
|
|
hig_workarea_add_row(t, &row, _("Origin:"), l, NULL);
|
2013-01-04 19:45:39 +00:00
|
|
|
di->origin_lb = l;
|
|
|
|
|
|
|
|
/* comment */
|
2017-04-19 12:04:45 +00:00
|
|
|
b = di->comment_buffer = gtk_text_buffer_new(NULL);
|
|
|
|
w = gtk_text_view_new_with_buffer(b);
|
|
|
|
gtk_text_view_set_wrap_mode(GTK_TEXT_VIEW(w), GTK_WRAP_WORD);
|
|
|
|
gtk_text_view_set_editable(GTK_TEXT_VIEW(w), FALSE);
|
|
|
|
sw = gtk_scrolled_window_new(NULL, NULL);
|
|
|
|
gtk_widget_set_size_request(sw, 350, 36);
|
|
|
|
gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(sw), GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC);
|
|
|
|
gtk_container_add(GTK_CONTAINER(sw), w);
|
|
|
|
fr = gtk_frame_new(NULL);
|
|
|
|
gtk_frame_set_shadow_type(GTK_FRAME(fr), GTK_SHADOW_IN);
|
|
|
|
gtk_container_add(GTK_CONTAINER(fr), sw);
|
|
|
|
w = hig_workarea_add_tall_row(t, &row, _("Comment:"), fr, NULL);
|
2019-11-06 19:09:27 +00:00
|
|
|
g_object_set(w, "halign", GTK_ALIGN_START, "valign", GTK_ALIGN_START, NULL);
|
2017-04-19 12:04:45 +00:00
|
|
|
|
|
|
|
hig_workarea_add_section_divider(t, &row);
|
|
|
|
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
|
|
|
|
2009-04-24 01:37:04 +00:00
|
|
|
enum
|
2009-02-13 18:23:56 +00:00
|
|
|
{
|
2017-04-19 12:04:45 +00:00
|
|
|
WEBSEED_COL_KEY,
|
|
|
|
WEBSEED_COL_WAS_UPDATED,
|
|
|
|
WEBSEED_COL_URL,
|
|
|
|
WEBSEED_COL_DOWNLOAD_RATE_DOUBLE,
|
|
|
|
WEBSEED_COL_DOWNLOAD_RATE_STRING,
|
|
|
|
N_WEBSEED_COLS
|
2009-04-24 01:37:04 +00:00
|
|
|
};
|
|
|
|
|
2017-04-20 16:02:19 +00:00
|
|
|
static char const* getWebseedColumnNames(int column)
|
2009-04-24 01:37:04 +00:00
|
|
|
{
|
2017-04-19 12:04:45 +00:00
|
|
|
switch (column)
|
2009-02-13 18:23:56 +00:00
|
|
|
{
|
2017-04-19 12:04:45 +00:00
|
|
|
case WEBSEED_COL_URL:
|
|
|
|
return _("Web Seeds");
|
|
|
|
|
|
|
|
case WEBSEED_COL_DOWNLOAD_RATE_DOUBLE:
|
|
|
|
case WEBSEED_COL_DOWNLOAD_RATE_STRING:
|
|
|
|
return _("Down");
|
|
|
|
|
|
|
|
default:
|
|
|
|
return "";
|
2009-02-13 18:23:56 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
static GtkListStore* webseed_model_new(void)
|
2009-04-24 01:37:04 +00:00
|
|
|
{
|
2017-04-19 12:04:45 +00:00
|
|
|
return gtk_list_store_new(N_WEBSEED_COLS,
|
2017-04-21 07:40:57 +00:00
|
|
|
G_TYPE_STRING, /* key */
|
|
|
|
G_TYPE_BOOLEAN, /* was-updated */
|
|
|
|
G_TYPE_STRING, /* url */
|
|
|
|
G_TYPE_DOUBLE, /* download rate double */
|
|
|
|
G_TYPE_STRING); /* download rate string */
|
2009-04-24 01:37:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
enum
|
|
|
|
{
|
2017-04-19 12:04:45 +00:00
|
|
|
PEER_COL_KEY,
|
|
|
|
PEER_COL_WAS_UPDATED,
|
|
|
|
PEER_COL_ADDRESS,
|
|
|
|
PEER_COL_ADDRESS_COLLATED,
|
|
|
|
PEER_COL_DOWNLOAD_RATE_DOUBLE,
|
|
|
|
PEER_COL_DOWNLOAD_RATE_STRING,
|
|
|
|
PEER_COL_UPLOAD_RATE_DOUBLE,
|
|
|
|
PEER_COL_UPLOAD_RATE_STRING,
|
|
|
|
PEER_COL_CLIENT,
|
|
|
|
PEER_COL_PROGRESS,
|
|
|
|
PEER_COL_UPLOAD_REQUEST_COUNT_INT,
|
|
|
|
PEER_COL_UPLOAD_REQUEST_COUNT_STRING,
|
|
|
|
PEER_COL_DOWNLOAD_REQUEST_COUNT_INT,
|
|
|
|
PEER_COL_DOWNLOAD_REQUEST_COUNT_STRING,
|
|
|
|
PEER_COL_BLOCKS_DOWNLOADED_COUNT_INT,
|
|
|
|
PEER_COL_BLOCKS_DOWNLOADED_COUNT_STRING,
|
|
|
|
PEER_COL_BLOCKS_UPLOADED_COUNT_INT,
|
|
|
|
PEER_COL_BLOCKS_UPLOADED_COUNT_STRING,
|
|
|
|
PEER_COL_REQS_CANCELLED_BY_CLIENT_COUNT_INT,
|
|
|
|
PEER_COL_REQS_CANCELLED_BY_CLIENT_COUNT_STRING,
|
|
|
|
PEER_COL_REQS_CANCELLED_BY_PEER_COUNT_INT,
|
|
|
|
PEER_COL_REQS_CANCELLED_BY_PEER_COUNT_STRING,
|
|
|
|
PEER_COL_ENCRYPTION_STOCK_ID,
|
|
|
|
PEER_COL_FLAGS,
|
|
|
|
PEER_COL_TORRENT_NAME,
|
|
|
|
N_PEER_COLS
|
2009-04-24 01:37:04 +00:00
|
|
|
};
|
|
|
|
|
2017-04-20 16:02:19 +00:00
|
|
|
static char const* getPeerColumnName(int column)
|
2017-04-19 12:04:45 +00:00
|
|
|
{
|
|
|
|
switch (column)
|
|
|
|
{
|
|
|
|
case PEER_COL_ADDRESS:
|
|
|
|
return _("Address");
|
|
|
|
|
|
|
|
case PEER_COL_DOWNLOAD_RATE_STRING:
|
|
|
|
case PEER_COL_DOWNLOAD_RATE_DOUBLE:
|
|
|
|
return _("Down");
|
|
|
|
|
|
|
|
case PEER_COL_UPLOAD_RATE_STRING:
|
|
|
|
case PEER_COL_UPLOAD_RATE_DOUBLE:
|
|
|
|
return _("Up");
|
|
|
|
|
|
|
|
case PEER_COL_CLIENT:
|
|
|
|
return _("Client");
|
|
|
|
|
|
|
|
case PEER_COL_PROGRESS:
|
|
|
|
return _("%");
|
|
|
|
|
|
|
|
case PEER_COL_UPLOAD_REQUEST_COUNT_INT:
|
|
|
|
case PEER_COL_UPLOAD_REQUEST_COUNT_STRING:
|
|
|
|
return _("Up Reqs");
|
|
|
|
|
|
|
|
case PEER_COL_DOWNLOAD_REQUEST_COUNT_INT:
|
|
|
|
case PEER_COL_DOWNLOAD_REQUEST_COUNT_STRING:
|
|
|
|
return _("Dn Reqs");
|
|
|
|
|
|
|
|
case PEER_COL_BLOCKS_DOWNLOADED_COUNT_INT:
|
|
|
|
case PEER_COL_BLOCKS_DOWNLOADED_COUNT_STRING:
|
|
|
|
return _("Dn Blocks");
|
|
|
|
|
|
|
|
case PEER_COL_BLOCKS_UPLOADED_COUNT_INT:
|
|
|
|
case PEER_COL_BLOCKS_UPLOADED_COUNT_STRING:
|
|
|
|
return _("Up Blocks");
|
|
|
|
|
|
|
|
case PEER_COL_REQS_CANCELLED_BY_CLIENT_COUNT_INT:
|
|
|
|
case PEER_COL_REQS_CANCELLED_BY_CLIENT_COUNT_STRING:
|
|
|
|
return _("We Cancelled");
|
|
|
|
|
|
|
|
case PEER_COL_REQS_CANCELLED_BY_PEER_COUNT_INT:
|
|
|
|
case PEER_COL_REQS_CANCELLED_BY_PEER_COUNT_STRING:
|
|
|
|
return _("They Cancelled");
|
|
|
|
|
|
|
|
case PEER_COL_FLAGS:
|
|
|
|
return _("Flags");
|
|
|
|
|
|
|
|
default:
|
|
|
|
return "";
|
2009-04-24 01:37:04 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
static GtkListStore* peer_store_new(void)
|
|
|
|
{
|
|
|
|
return gtk_list_store_new(N_PEER_COLS,
|
2017-04-21 07:40:57 +00:00
|
|
|
G_TYPE_STRING, /* key */
|
|
|
|
G_TYPE_BOOLEAN, /* was-updated */
|
|
|
|
G_TYPE_STRING, /* address */
|
|
|
|
G_TYPE_STRING, /* collated address */
|
|
|
|
G_TYPE_DOUBLE, /* download speed int */
|
|
|
|
G_TYPE_STRING, /* download speed string */
|
|
|
|
G_TYPE_DOUBLE, /* upload speed int */
|
|
|
|
G_TYPE_STRING, /* upload speed string */
|
|
|
|
G_TYPE_STRING, /* client */
|
|
|
|
G_TYPE_INT, /* progress [0..100] */
|
|
|
|
G_TYPE_INT, /* upload request count int */
|
|
|
|
G_TYPE_STRING, /* upload request count string */
|
|
|
|
G_TYPE_INT, /* download request count int */
|
|
|
|
G_TYPE_STRING, /* download request count string */
|
|
|
|
G_TYPE_INT, /* # blocks downloaded int */
|
|
|
|
G_TYPE_STRING, /* # blocks downloaded string */
|
|
|
|
G_TYPE_INT, /* # blocks uploaded int */
|
|
|
|
G_TYPE_STRING, /* # blocks uploaded string */
|
|
|
|
G_TYPE_INT, /* # blocks cancelled by client int */
|
|
|
|
G_TYPE_STRING, /* # blocks cancelled by client string */
|
|
|
|
G_TYPE_INT, /* # blocks cancelled by peer int */
|
|
|
|
G_TYPE_STRING, /* # blocks cancelled by peer string */
|
|
|
|
G_TYPE_STRING, /* encryption stock id */
|
|
|
|
G_TYPE_STRING, /* flagString */
|
|
|
|
G_TYPE_STRING); /* torrent name */
|
2009-04-24 01:37:04 +00:00
|
|
|
}
|
|
|
|
|
2017-04-20 16:02:19 +00:00
|
|
|
static void initPeerRow(GtkListStore* store, GtkTreeIter* iter, char const* key, char const* torrentName,
|
|
|
|
tr_peer_stat const* peer)
|
2017-04-19 12:04:45 +00:00
|
|
|
{
|
2020-10-31 21:23:43 +00:00
|
|
|
g_return_if_fail(peer != NULL);
|
2017-04-19 12:04:45 +00:00
|
|
|
|
2020-10-31 21:23:43 +00:00
|
|
|
char const* client = peer->client;
|
2017-04-19 12:04:45 +00:00
|
|
|
if (client == NULL || g_strcmp0(client, "Unknown Client") == 0)
|
|
|
|
{
|
|
|
|
client = "";
|
|
|
|
}
|
|
|
|
|
2020-10-31 21:23:43 +00:00
|
|
|
int q[4];
|
|
|
|
char collated_name[128];
|
2017-04-19 12:04:45 +00:00
|
|
|
if (sscanf(peer->addr, "%d.%d.%d.%d", q, q + 1, q + 2, q + 3) != 4)
|
|
|
|
{
|
|
|
|
g_strlcpy(collated_name, peer->addr, sizeof(collated_name));
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
g_snprintf(collated_name, sizeof(collated_name), "%03d.%03d.%03d.%03d", q[0], q[1], q[2], q[3]);
|
|
|
|
}
|
|
|
|
|
|
|
|
gtk_list_store_set(store, iter,
|
|
|
|
PEER_COL_ADDRESS, peer->addr,
|
|
|
|
PEER_COL_ADDRESS_COLLATED, collated_name,
|
|
|
|
PEER_COL_CLIENT, client,
|
|
|
|
PEER_COL_ENCRYPTION_STOCK_ID, peer->isEncrypted ? "transmission-lock" : NULL,
|
|
|
|
PEER_COL_KEY, key,
|
|
|
|
PEER_COL_TORRENT_NAME, torrentName,
|
|
|
|
-1);
|
2007-06-06 00:30:13 +00:00
|
|
|
}
|
|
|
|
|
2017-04-20 16:02:19 +00:00
|
|
|
static void refreshPeerRow(GtkListStore* store, GtkTreeIter* iter, tr_peer_stat const* peer)
|
2017-04-19 12:04:45 +00:00
|
|
|
{
|
|
|
|
char up_speed[64] = { '\0' };
|
|
|
|
char down_speed[64] = { '\0' };
|
|
|
|
char up_count[64] = { '\0' };
|
|
|
|
char down_count[64] = { '\0' };
|
|
|
|
char blocks_to_peer[64] = { '\0' };
|
|
|
|
char blocks_to_client[64] = { '\0' };
|
|
|
|
char cancelled_by_peer[64] = { '\0' };
|
|
|
|
char cancelled_by_client[64] = { '\0' };
|
|
|
|
|
2020-11-01 21:47:57 +00:00
|
|
|
g_return_if_fail(peer != NULL);
|
|
|
|
|
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)
|
|
|
|
{
|
|
|
|
g_snprintf(down_count, sizeof(down_count), "%d", peer->pendingReqsToPeer);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (peer->pendingReqsToClient > 0)
|
|
|
|
{
|
|
|
|
g_snprintf(up_count, sizeof(down_count), "%d", peer->pendingReqsToClient);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (peer->blocksToPeer > 0)
|
|
|
|
{
|
2017-04-21 07:40:57 +00:00
|
|
|
g_snprintf(blocks_to_peer, sizeof(blocks_to_peer), "%" PRIu32, peer->blocksToPeer);
|
2017-04-19 12:04:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (peer->blocksToClient > 0)
|
|
|
|
{
|
2017-04-21 07:40:57 +00:00
|
|
|
g_snprintf(blocks_to_client, sizeof(blocks_to_client), "%" PRIu32, peer->blocksToClient);
|
2017-04-19 12:04:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (peer->cancelsToPeer > 0)
|
|
|
|
{
|
2017-04-21 07:40:57 +00:00
|
|
|
g_snprintf(cancelled_by_client, sizeof(cancelled_by_client), "%" PRIu32, peer->cancelsToPeer);
|
2017-04-19 12:04:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (peer->cancelsToClient > 0)
|
|
|
|
{
|
2017-04-21 07:40:57 +00:00
|
|
|
g_snprintf(cancelled_by_peer, sizeof(cancelled_by_peer), "%" PRIu32, peer->cancelsToClient);
|
2017-04-19 12:04:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
gtk_list_store_set(store, iter,
|
|
|
|
PEER_COL_PROGRESS, (int)(100.0 * peer->progress),
|
|
|
|
PEER_COL_UPLOAD_REQUEST_COUNT_INT, peer->pendingReqsToClient,
|
|
|
|
PEER_COL_UPLOAD_REQUEST_COUNT_STRING, up_count,
|
|
|
|
PEER_COL_DOWNLOAD_REQUEST_COUNT_INT, peer->pendingReqsToPeer,
|
|
|
|
PEER_COL_DOWNLOAD_REQUEST_COUNT_STRING, down_count,
|
|
|
|
PEER_COL_DOWNLOAD_RATE_DOUBLE, peer->rateToClient_KBps,
|
|
|
|
PEER_COL_DOWNLOAD_RATE_STRING, down_speed,
|
|
|
|
PEER_COL_UPLOAD_RATE_DOUBLE, peer->rateToPeer_KBps,
|
|
|
|
PEER_COL_UPLOAD_RATE_STRING, up_speed,
|
|
|
|
PEER_COL_FLAGS, peer->flagStr,
|
|
|
|
PEER_COL_WAS_UPDATED, TRUE,
|
|
|
|
PEER_COL_BLOCKS_DOWNLOADED_COUNT_INT, (int)peer->blocksToClient,
|
|
|
|
PEER_COL_BLOCKS_DOWNLOADED_COUNT_STRING, blocks_to_client,
|
|
|
|
PEER_COL_BLOCKS_UPLOADED_COUNT_INT, (int)peer->blocksToPeer,
|
|
|
|
PEER_COL_BLOCKS_UPLOADED_COUNT_STRING, blocks_to_peer,
|
|
|
|
PEER_COL_REQS_CANCELLED_BY_CLIENT_COUNT_INT, (int)peer->cancelsToPeer,
|
|
|
|
PEER_COL_REQS_CANCELLED_BY_CLIENT_COUNT_STRING, cancelled_by_client,
|
|
|
|
PEER_COL_REQS_CANCELLED_BY_PEER_COUNT_INT, (int)peer->cancelsToClient,
|
|
|
|
PEER_COL_REQS_CANCELLED_BY_PEER_COUNT_STRING, cancelled_by_peer,
|
|
|
|
-1);
|
2007-06-06 00:30:13 +00:00
|
|
|
}
|
2008-09-23 19:11:04 +00:00
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
static void refreshPeerList(struct DetailsImpl* di, tr_torrent** torrents, int n)
|
2007-06-06 00:30:13 +00:00
|
|
|
{
|
2017-04-19 12:04:45 +00:00
|
|
|
int* peerCount;
|
|
|
|
GtkTreeIter iter;
|
|
|
|
GtkTreeModel* model;
|
|
|
|
GHashTable* hash = di->peer_hash;
|
|
|
|
GtkListStore* store = di->peer_store;
|
|
|
|
struct tr_peer_stat** peers;
|
2013-01-04 19:45:39 +00:00
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
/* step 1: get all the peers */
|
|
|
|
peers = g_new(struct tr_peer_stat*, n);
|
|
|
|
peerCount = g_new(int, n);
|
|
|
|
|
2017-05-13 22:38:31 +00:00
|
|
|
for (int i = 0; i < n; ++i)
|
2017-04-19 12:04:45 +00:00
|
|
|
{
|
|
|
|
peers[i] = tr_torrentPeers(torrents[i], &peerCount[i]);
|
|
|
|
}
|
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 */
|
|
|
|
model = GTK_TREE_MODEL(store);
|
2013-01-04 19:45:39 +00:00
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
if (gtk_tree_model_iter_nth_child(model, &iter, NULL, 0))
|
2013-01-04 19:45:39 +00:00
|
|
|
{
|
2017-04-19 12:04:45 +00:00
|
|
|
do
|
|
|
|
{
|
|
|
|
gtk_list_store_set(store, &iter, PEER_COL_WAS_UPDATED, FALSE, -1);
|
|
|
|
}
|
|
|
|
while (gtk_tree_model_iter_next(model, &iter));
|
|
|
|
}
|
2013-01-04 19:45:39 +00:00
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
/* step 3: add any new peers */
|
2017-05-13 22:38:31 +00:00
|
|
|
for (int i = 0; i < n; ++i)
|
2017-04-19 12:04:45 +00:00
|
|
|
{
|
2017-04-20 16:02:19 +00:00
|
|
|
tr_torrent const* tor = torrents[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
|
|
|
{
|
2017-04-19 12:04:45 +00:00
|
|
|
char key[128];
|
2017-04-20 16:02:19 +00:00
|
|
|
tr_peer_stat const* s = &peers[i][j];
|
2013-01-04 19:45:39 +00:00
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
g_snprintf(key, sizeof(key), "%d.%s", tr_torrentId(tor), s->addr);
|
|
|
|
|
|
|
|
if (g_hash_table_lookup(hash, key) == NULL)
|
2013-01-04 19:45:39 +00:00
|
|
|
{
|
2017-04-19 12:04:45 +00:00
|
|
|
GtkTreePath* p;
|
|
|
|
gtk_list_store_append(store, &iter);
|
|
|
|
initPeerRow(store, &iter, key, tr_torrentName(tor), s);
|
|
|
|
p = gtk_tree_model_get_path(model, &iter);
|
|
|
|
g_hash_table_insert(hash, g_strdup(key), gtk_tree_row_reference_new(model, p));
|
|
|
|
gtk_tree_path_free(p);
|
2009-04-24 01:37:04 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
/* step 4: update the peers */
|
2017-05-13 22:38:31 +00:00
|
|
|
for (int i = 0; i < n; ++i)
|
2013-01-04 19:45:39 +00:00
|
|
|
{
|
2017-04-20 16:02:19 +00:00
|
|
|
tr_torrent const* tor = torrents[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
|
|
|
{
|
2017-04-19 12:04:45 +00:00
|
|
|
char key[128];
|
|
|
|
GtkTreePath* p;
|
|
|
|
GtkTreeRowReference* ref;
|
2017-04-20 16:02:19 +00:00
|
|
|
tr_peer_stat const* s = &peers[i][j];
|
2017-04-19 12:04:45 +00:00
|
|
|
|
|
|
|
g_snprintf(key, sizeof(key), "%d.%s", tr_torrentId(tor), s->addr);
|
|
|
|
ref = g_hash_table_lookup(hash, key);
|
|
|
|
p = gtk_tree_row_reference_get_path(ref);
|
|
|
|
gtk_tree_model_get_iter(model, &iter, p);
|
|
|
|
refreshPeerRow(store, &iter, s);
|
|
|
|
gtk_tree_path_free(p);
|
2009-04-24 01:37:04 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
/* step 5: remove peers that have disappeared */
|
|
|
|
model = GTK_TREE_MODEL(store);
|
|
|
|
|
|
|
|
if (gtk_tree_model_iter_nth_child(model, &iter, NULL, 0))
|
2013-01-04 19:45:39 +00:00
|
|
|
{
|
2017-04-19 12:04:45 +00:00
|
|
|
gboolean more = TRUE;
|
2013-01-04 19:45:39 +00:00
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
while (more)
|
2013-01-04 19:45:39 +00:00
|
|
|
{
|
2017-04-19 12:04:45 +00:00
|
|
|
gboolean b;
|
|
|
|
gtk_tree_model_get(model, &iter, PEER_COL_WAS_UPDATED, &b, -1);
|
|
|
|
|
|
|
|
if (b)
|
2013-01-04 19:45:39 +00:00
|
|
|
{
|
2017-04-19 12:04:45 +00:00
|
|
|
more = gtk_tree_model_iter_next(model, &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
|
|
|
{
|
2017-04-19 12:04:45 +00:00
|
|
|
char* key;
|
|
|
|
gtk_tree_model_get(model, &iter, PEER_COL_KEY, &key, -1);
|
|
|
|
g_hash_table_remove(hash, key);
|
|
|
|
more = gtk_list_store_remove(store, &iter);
|
|
|
|
g_free(key);
|
2009-04-24 01:37:04 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
/* step 6: cleanup */
|
2017-05-13 22:38:31 +00:00
|
|
|
for (int i = 0; i < n; ++i)
|
2017-04-19 12:04:45 +00:00
|
|
|
{
|
|
|
|
tr_torrentPeersFree(peers[i], peerCount[i]);
|
|
|
|
}
|
|
|
|
|
|
|
|
tr_free(peers);
|
|
|
|
tr_free(peerCount);
|
2007-06-06 00:30:13 +00:00
|
|
|
}
|
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
static void refreshWebseedList(struct DetailsImpl* di, tr_torrent** torrents, int n)
|
2009-02-13 18:23:56 +00:00
|
|
|
{
|
2017-04-19 12:04:45 +00:00
|
|
|
int total = 0;
|
|
|
|
GtkTreeIter iter;
|
|
|
|
GHashTable* hash = di->webseed_hash;
|
|
|
|
GtkListStore* store = di->webseed_store;
|
|
|
|
GtkTreeModel* model = GTK_TREE_MODEL(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 */
|
|
|
|
if (gtk_tree_model_iter_nth_child(model, &iter, NULL, 0))
|
|
|
|
{
|
|
|
|
do
|
|
|
|
{
|
|
|
|
gtk_list_store_set(store, &iter, WEBSEED_COL_WAS_UPDATED, FALSE, -1);
|
|
|
|
}
|
|
|
|
while (gtk_tree_model_iter_next(model, &iter));
|
|
|
|
}
|
2013-01-04 19:45:39 +00:00
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
/* step 2: add any new webseeds */
|
2017-05-13 22:38:31 +00:00
|
|
|
for (int i = 0; i < n; ++i)
|
2013-01-04 19:45:39 +00:00
|
|
|
{
|
2017-04-20 16:02:19 +00:00
|
|
|
tr_torrent const* tor = torrents[i];
|
|
|
|
tr_info 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-19 12:04:45 +00:00
|
|
|
char key[256];
|
2017-04-20 16:02:19 +00:00
|
|
|
char const* url = inf->webseeds[j];
|
2017-04-19 12:04:45 +00:00
|
|
|
g_snprintf(key, sizeof(key), "%d.%s", tr_torrentId(tor), url);
|
|
|
|
|
|
|
|
if (g_hash_table_lookup(hash, key) == NULL)
|
2013-01-04 19:45:39 +00:00
|
|
|
{
|
2017-04-19 12:04:45 +00:00
|
|
|
GtkTreePath* p;
|
|
|
|
gtk_list_store_append(store, &iter);
|
|
|
|
gtk_list_store_set(store, &iter,
|
|
|
|
WEBSEED_COL_URL, url,
|
|
|
|
WEBSEED_COL_KEY, key,
|
|
|
|
-1);
|
|
|
|
p = gtk_tree_model_get_path(model, &iter);
|
|
|
|
g_hash_table_insert(hash, g_strdup(key), gtk_tree_row_reference_new(model, p));
|
|
|
|
gtk_tree_path_free(p);
|
2009-04-24 01:37:04 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
/* step 3: update the webseeds */
|
2017-05-13 22:38:31 +00:00
|
|
|
for (int i = 0; i < n; ++i)
|
2013-01-04 19:45:39 +00:00
|
|
|
{
|
2017-04-19 12:04:45 +00:00
|
|
|
tr_torrent* tor = torrents[i];
|
2017-04-20 16:02:19 +00:00
|
|
|
tr_info 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
|
|
|
{
|
2017-04-19 12:04:45 +00:00
|
|
|
char buf[128];
|
|
|
|
char key[256];
|
|
|
|
GtkTreePath* p;
|
|
|
|
GtkTreeRowReference* ref;
|
2017-04-20 16:02:19 +00:00
|
|
|
char const* url = inf->webseeds[j];
|
2017-04-19 12:04:45 +00:00
|
|
|
|
|
|
|
g_snprintf(key, sizeof(key), "%d.%s", tr_torrentId(tor), url);
|
|
|
|
ref = g_hash_table_lookup(hash, key);
|
|
|
|
p = gtk_tree_row_reference_get_path(ref);
|
|
|
|
gtk_tree_model_get_iter(model, &iter, p);
|
|
|
|
|
|
|
|
if (speeds_KBps[j] > 0)
|
|
|
|
{
|
|
|
|
tr_formatter_speed_KBps(buf, speeds_KBps[j], sizeof(buf));
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
*buf = '\0';
|
|
|
|
}
|
2013-01-04 19:45:39 +00:00
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
gtk_list_store_set(store, &iter,
|
|
|
|
WEBSEED_COL_DOWNLOAD_RATE_DOUBLE, speeds_KBps[j],
|
|
|
|
WEBSEED_COL_DOWNLOAD_RATE_STRING, buf,
|
|
|
|
WEBSEED_COL_WAS_UPDATED, TRUE,
|
|
|
|
-1);
|
2013-01-04 19:45:39 +00:00
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
gtk_tree_path_free(p);
|
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 */
|
|
|
|
if (gtk_tree_model_iter_nth_child(model, &iter, NULL, 0))
|
2013-01-04 19:45:39 +00:00
|
|
|
{
|
2017-04-19 12:04:45 +00:00
|
|
|
gboolean more = TRUE;
|
|
|
|
|
|
|
|
while (more)
|
2013-01-04 19:45:39 +00:00
|
|
|
{
|
2017-04-19 12:04:45 +00:00
|
|
|
gboolean b;
|
|
|
|
gtk_tree_model_get(model, &iter, WEBSEED_COL_WAS_UPDATED, &b, -1);
|
|
|
|
|
|
|
|
if (b)
|
2013-01-04 19:45:39 +00:00
|
|
|
{
|
2017-04-19 12:04:45 +00:00
|
|
|
more = gtk_tree_model_iter_next(model, &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
|
|
|
{
|
2017-04-19 12:04:45 +00:00
|
|
|
char* key;
|
|
|
|
gtk_tree_model_get(model, &iter, WEBSEED_COL_KEY, &key, -1);
|
|
|
|
|
|
|
|
if (key != NULL)
|
|
|
|
{
|
|
|
|
g_hash_table_remove(hash, key);
|
|
|
|
}
|
|
|
|
|
|
|
|
more = gtk_list_store_remove(store, &iter);
|
|
|
|
g_free(key);
|
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 */
|
|
|
|
gtk_widget_set_visible(di->webseed_view, total > 0);
|
2009-02-13 18:23:56 +00:00
|
|
|
}
|
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
static void refreshPeers(struct DetailsImpl* di, tr_torrent** torrents, int n)
|
2009-04-24 01:37:04 +00:00
|
|
|
{
|
2017-04-19 12:04:45 +00:00
|
|
|
refreshPeerList(di, torrents, n);
|
|
|
|
refreshWebseedList(di, torrents, n);
|
2009-04-24 01:37:04 +00:00
|
|
|
}
|
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
static gboolean onPeerViewQueryTooltip(GtkWidget* widget, gint x, gint y, gboolean keyboard_tip, GtkTooltip* tooltip,
|
|
|
|
gpointer gdi)
|
|
|
|
{
|
|
|
|
GtkTreeIter iter;
|
|
|
|
GtkTreeModel* model;
|
|
|
|
gboolean show_tip = FALSE;
|
|
|
|
|
|
|
|
if (gtk_tree_view_get_tooltip_context(GTK_TREE_VIEW(widget), &x, &y, keyboard_tip, &model, NULL, &iter))
|
|
|
|
{
|
|
|
|
char* name = NULL;
|
|
|
|
char* addr = NULL;
|
|
|
|
char* markup = NULL;
|
|
|
|
char* flagstr = NULL;
|
|
|
|
struct DetailsImpl* di = gdi;
|
|
|
|
GString* gstr = di->gstr;
|
|
|
|
|
|
|
|
gtk_tree_model_get(model, &iter,
|
|
|
|
PEER_COL_TORRENT_NAME, &name,
|
|
|
|
PEER_COL_ADDRESS, &addr,
|
|
|
|
PEER_COL_FLAGS, &flagstr,
|
|
|
|
-1);
|
|
|
|
|
|
|
|
g_string_truncate(gstr, 0);
|
|
|
|
markup = g_markup_escape_text(name, -1);
|
|
|
|
g_string_append_printf(gstr, "<b>%s</b>\n%s\n \n", markup, addr);
|
|
|
|
g_free(markup);
|
|
|
|
|
2019-07-13 08:52:44 +00:00
|
|
|
for (char const* pch = flagstr; !tr_str_is_empty(pch); ++pch)
|
2017-04-19 12:04:45 +00:00
|
|
|
{
|
2017-04-20 16:02:19 +00:00
|
|
|
char const* s = NULL;
|
2017-04-19 12:04:45 +00:00
|
|
|
|
|
|
|
switch (*pch)
|
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
|
|
|
|
2017-04-30 16:25:26 +00:00
|
|
|
if (s != NULL)
|
2017-04-19 12:04:45 +00:00
|
|
|
{
|
|
|
|
g_string_append_printf(gstr, "%c: %s\n", *pch, s);
|
|
|
|
}
|
2009-04-24 12:05:53 +00:00
|
|
|
}
|
2011-05-28 00:12:59 +00:00
|
|
|
|
2017-04-30 16:25:26 +00:00
|
|
|
if (gstr->len != 0) /* remove the last linefeed */
|
2017-04-19 12:04:45 +00:00
|
|
|
{
|
|
|
|
g_string_set_size(gstr, gstr->len - 1);
|
|
|
|
}
|
2013-01-04 19:45:39 +00:00
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
gtk_tooltip_set_markup(tooltip, gstr->str);
|
2011-05-28 00:12:59 +00:00
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
g_free(flagstr);
|
|
|
|
g_free(addr);
|
|
|
|
g_free(name);
|
|
|
|
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
|
|
|
}
|
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
static void setPeerViewColumns(GtkTreeView* peer_view)
|
|
|
|
{
|
|
|
|
int n;
|
|
|
|
int view_columns[32];
|
|
|
|
GtkCellRenderer* r;
|
|
|
|
GtkTreeViewColumn* 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
|
|
|
|
|
|
|
n = 0;
|
|
|
|
view_columns[n++] = PEER_COL_ENCRYPTION_STOCK_ID;
|
|
|
|
view_columns[n++] = PEER_COL_UPLOAD_RATE_STRING;
|
|
|
|
|
|
|
|
if (more)
|
|
|
|
{
|
|
|
|
view_columns[n++] = PEER_COL_UPLOAD_REQUEST_COUNT_STRING;
|
|
|
|
}
|
|
|
|
|
|
|
|
view_columns[n++] = PEER_COL_DOWNLOAD_RATE_STRING;
|
|
|
|
|
|
|
|
if (more)
|
|
|
|
{
|
|
|
|
view_columns[n++] = PEER_COL_DOWNLOAD_REQUEST_COUNT_STRING;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (more)
|
|
|
|
{
|
|
|
|
view_columns[n++] = PEER_COL_BLOCKS_DOWNLOADED_COUNT_STRING;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (more)
|
|
|
|
{
|
|
|
|
view_columns[n++] = PEER_COL_BLOCKS_UPLOADED_COUNT_STRING;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (more)
|
|
|
|
{
|
|
|
|
view_columns[n++] = PEER_COL_REQS_CANCELLED_BY_CLIENT_COUNT_STRING;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (more)
|
|
|
|
{
|
|
|
|
view_columns[n++] = PEER_COL_REQS_CANCELLED_BY_PEER_COUNT_STRING;
|
|
|
|
}
|
|
|
|
|
|
|
|
view_columns[n++] = PEER_COL_PROGRESS;
|
|
|
|
view_columns[n++] = PEER_COL_FLAGS;
|
|
|
|
view_columns[n++] = PEER_COL_ADDRESS;
|
|
|
|
view_columns[n++] = PEER_COL_CLIENT;
|
|
|
|
|
|
|
|
/* remove any existing columns */
|
2017-04-30 16:25:26 +00:00
|
|
|
while ((c = gtk_tree_view_get_column(peer_view, 0)) != NULL)
|
2017-04-19 12:04:45 +00:00
|
|
|
{
|
|
|
|
gtk_tree_view_remove_column(peer_view, c);
|
|
|
|
}
|
|
|
|
|
2017-05-13 22:38:31 +00:00
|
|
|
for (int i = 0; i < n; ++i)
|
2017-04-19 12:04:45 +00:00
|
|
|
{
|
2017-04-20 16:02:19 +00:00
|
|
|
int const col = view_columns[i];
|
|
|
|
char const* t = getPeerColumnName(col);
|
2017-04-19 12:04:45 +00:00
|
|
|
int sort_col = col;
|
|
|
|
|
|
|
|
switch (col)
|
|
|
|
{
|
|
|
|
case PEER_COL_ADDRESS:
|
|
|
|
r = gtk_cell_renderer_text_new();
|
|
|
|
c = gtk_tree_view_column_new_with_attributes(t, r, "text", col, NULL);
|
2013-01-04 19:45:39 +00:00
|
|
|
sort_col = PEER_COL_ADDRESS_COLLATED;
|
|
|
|
break;
|
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
case PEER_COL_CLIENT:
|
|
|
|
r = gtk_cell_renderer_text_new();
|
|
|
|
c = gtk_tree_view_column_new_with_attributes(t, r, "text", col, NULL);
|
2013-01-04 19:45:39 +00:00
|
|
|
break;
|
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
case PEER_COL_PROGRESS:
|
|
|
|
r = gtk_cell_renderer_progress_new();
|
|
|
|
c = gtk_tree_view_column_new_with_attributes(t, r, "value", PEER_COL_PROGRESS, NULL);
|
2013-01-04 19:45:39 +00:00
|
|
|
break;
|
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
case PEER_COL_ENCRYPTION_STOCK_ID:
|
|
|
|
r = gtk_cell_renderer_pixbuf_new();
|
|
|
|
g_object_set(r, "xalign", (gfloat)0.0, "yalign", (gfloat)0.5, NULL);
|
|
|
|
c = gtk_tree_view_column_new_with_attributes(t, r, "stock-id", PEER_COL_ENCRYPTION_STOCK_ID, NULL);
|
|
|
|
gtk_tree_view_column_set_sizing(c, GTK_TREE_VIEW_COLUMN_FIXED);
|
|
|
|
gtk_tree_view_column_set_fixed_width(c, 20);
|
2013-01-04 19:45:39 +00:00
|
|
|
break;
|
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
case PEER_COL_DOWNLOAD_REQUEST_COUNT_STRING:
|
|
|
|
r = gtk_cell_renderer_text_new();
|
|
|
|
c = gtk_tree_view_column_new_with_attributes(t, r, "text", col, NULL);
|
2013-01-04 19:45:39 +00:00
|
|
|
sort_col = PEER_COL_DOWNLOAD_REQUEST_COUNT_INT;
|
|
|
|
break;
|
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
case PEER_COL_UPLOAD_REQUEST_COUNT_STRING:
|
|
|
|
r = gtk_cell_renderer_text_new();
|
|
|
|
c = gtk_tree_view_column_new_with_attributes(t, r, "text", col, NULL);
|
2013-01-04 19:45:39 +00:00
|
|
|
sort_col = PEER_COL_UPLOAD_REQUEST_COUNT_INT;
|
|
|
|
break;
|
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
case PEER_COL_BLOCKS_DOWNLOADED_COUNT_STRING:
|
|
|
|
r = gtk_cell_renderer_text_new();
|
|
|
|
c = gtk_tree_view_column_new_with_attributes(t, r, "text", col, NULL);
|
2013-01-04 19:45:39 +00:00
|
|
|
sort_col = PEER_COL_BLOCKS_DOWNLOADED_COUNT_INT;
|
|
|
|
break;
|
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
case PEER_COL_BLOCKS_UPLOADED_COUNT_STRING:
|
|
|
|
r = gtk_cell_renderer_text_new();
|
|
|
|
c = gtk_tree_view_column_new_with_attributes(t, r, "text", col, NULL);
|
2013-01-04 19:45:39 +00:00
|
|
|
sort_col = PEER_COL_BLOCKS_UPLOADED_COUNT_INT;
|
|
|
|
break;
|
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
case PEER_COL_REQS_CANCELLED_BY_CLIENT_COUNT_STRING:
|
|
|
|
r = gtk_cell_renderer_text_new();
|
|
|
|
c = gtk_tree_view_column_new_with_attributes(t, r, "text", col, NULL);
|
2013-01-04 19:45:39 +00:00
|
|
|
sort_col = PEER_COL_REQS_CANCELLED_BY_CLIENT_COUNT_INT;
|
|
|
|
break;
|
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
case PEER_COL_REQS_CANCELLED_BY_PEER_COUNT_STRING:
|
|
|
|
r = gtk_cell_renderer_text_new();
|
|
|
|
c = gtk_tree_view_column_new_with_attributes(t, r, "text", col, NULL);
|
2013-01-04 19:45:39 +00:00
|
|
|
sort_col = PEER_COL_REQS_CANCELLED_BY_PEER_COUNT_INT;
|
|
|
|
break;
|
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
case PEER_COL_DOWNLOAD_RATE_STRING:
|
|
|
|
r = gtk_cell_renderer_text_new();
|
2019-03-17 04:07:48 +00:00
|
|
|
g_object_set(G_OBJECT(r), "xalign", 1.0F, NULL);
|
2017-04-19 12:04:45 +00:00
|
|
|
c = gtk_tree_view_column_new_with_attributes(t, r, "text", col, NULL);
|
2013-01-04 19:45:39 +00:00
|
|
|
sort_col = PEER_COL_DOWNLOAD_RATE_DOUBLE;
|
|
|
|
break;
|
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
case PEER_COL_UPLOAD_RATE_STRING:
|
|
|
|
r = gtk_cell_renderer_text_new();
|
2019-03-17 04:07:48 +00:00
|
|
|
g_object_set(G_OBJECT(r), "xalign", 1.0F, NULL);
|
2017-04-19 12:04:45 +00:00
|
|
|
c = gtk_tree_view_column_new_with_attributes(t, r, "text", col, NULL);
|
2013-01-04 19:45:39 +00:00
|
|
|
sort_col = PEER_COL_UPLOAD_RATE_DOUBLE;
|
|
|
|
break;
|
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
case PEER_COL_FLAGS:
|
|
|
|
r = gtk_cell_renderer_text_new();
|
|
|
|
c = gtk_tree_view_column_new_with_attributes(t, r, "text", col, NULL);
|
2013-01-04 19:45:39 +00:00
|
|
|
break;
|
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
default:
|
|
|
|
abort();
|
2009-12-16 18:20:01 +00:00
|
|
|
}
|
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
gtk_tree_view_column_set_resizable(c, FALSE);
|
|
|
|
gtk_tree_view_column_set_sort_column_id(c, sort_col);
|
|
|
|
gtk_tree_view_append_column(GTK_TREE_VIEW(peer_view), 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. */
|
|
|
|
{
|
2020-08-11 18:11:55 +00:00
|
|
|
c = gtk_tree_view_column_new();
|
2017-04-19 12:04:45 +00:00
|
|
|
gtk_tree_view_column_set_visible(c, FALSE);
|
|
|
|
gtk_tree_view_append_column(GTK_TREE_VIEW(peer_view), c);
|
|
|
|
gtk_tree_view_set_expander_column(GTK_TREE_VIEW(peer_view), c);
|
|
|
|
}
|
2009-12-16 18:20:01 +00:00
|
|
|
}
|
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
static void onMorePeerInfoToggled(GtkToggleButton* button, struct DetailsImpl* di)
|
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;
|
|
|
|
gboolean const value = gtk_toggle_button_get_active(button);
|
2017-04-19 12:04:45 +00:00
|
|
|
gtr_core_set_pref_bool(di->core, key, value);
|
|
|
|
setPeerViewColumns(GTK_TREE_VIEW(di->peer_view));
|
2009-12-16 18:20:01 +00:00
|
|
|
}
|
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
static GtkWidget* peer_page_new(struct DetailsImpl* di)
|
|
|
|
{
|
|
|
|
gboolean b;
|
2017-04-20 16:02:19 +00:00
|
|
|
char const* str;
|
2017-04-19 12:04:45 +00:00
|
|
|
GtkListStore* store;
|
2017-05-01 15:46:41 +00:00
|
|
|
GtkWidget* v;
|
|
|
|
GtkWidget* w;
|
|
|
|
GtkWidget* ret;
|
|
|
|
GtkWidget* sw;
|
|
|
|
GtkWidget* vbox;
|
2017-04-19 12:04:45 +00:00
|
|
|
GtkWidget* webtree = NULL;
|
|
|
|
GtkTreeModel* m;
|
|
|
|
GtkTreeViewColumn* c;
|
2017-04-21 07:40:57 +00:00
|
|
|
GtkCellRenderer* r;
|
2017-04-19 12:04:45 +00:00
|
|
|
|
|
|
|
/* webseeds */
|
|
|
|
|
|
|
|
store = di->webseed_store = webseed_model_new();
|
|
|
|
v = gtk_tree_view_new_with_model(GTK_TREE_MODEL(store));
|
|
|
|
g_signal_connect(v, "button-release-event", G_CALLBACK(on_tree_view_button_released), NULL);
|
|
|
|
g_object_unref(store);
|
|
|
|
|
|
|
|
str = getWebseedColumnNames(WEBSEED_COL_URL);
|
|
|
|
r = gtk_cell_renderer_text_new();
|
|
|
|
g_object_set(G_OBJECT(r), "ellipsize", PANGO_ELLIPSIZE_END, NULL);
|
|
|
|
c = gtk_tree_view_column_new_with_attributes(str, r, "text", WEBSEED_COL_URL, NULL);
|
|
|
|
g_object_set(G_OBJECT(c), "expand", TRUE, NULL);
|
|
|
|
gtk_tree_view_column_set_sort_column_id(c, WEBSEED_COL_URL);
|
|
|
|
gtk_tree_view_append_column(GTK_TREE_VIEW(v), c);
|
|
|
|
|
|
|
|
str = getWebseedColumnNames(WEBSEED_COL_DOWNLOAD_RATE_STRING);
|
|
|
|
r = gtk_cell_renderer_text_new();
|
|
|
|
c = gtk_tree_view_column_new_with_attributes(str, r, "text", WEBSEED_COL_DOWNLOAD_RATE_STRING, NULL);
|
|
|
|
gtk_tree_view_column_set_sort_column_id(c, WEBSEED_COL_DOWNLOAD_RATE_DOUBLE);
|
|
|
|
gtk_tree_view_append_column(GTK_TREE_VIEW(v), c);
|
|
|
|
|
|
|
|
w = gtk_scrolled_window_new(NULL, NULL);
|
|
|
|
gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(w), GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC);
|
|
|
|
gtk_scrolled_window_set_shadow_type(GTK_SCROLLED_WINDOW(w), GTK_SHADOW_IN);
|
|
|
|
gtk_container_add(GTK_CONTAINER(w), v);
|
|
|
|
|
|
|
|
webtree = w;
|
|
|
|
di->webseed_view = w;
|
|
|
|
|
|
|
|
/* peers */
|
|
|
|
|
2017-04-21 07:40:57 +00:00
|
|
|
store = di->peer_store = peer_store_new();
|
2017-04-19 12:04:45 +00:00
|
|
|
m = gtk_tree_model_sort_new_with_model(GTK_TREE_MODEL(store));
|
|
|
|
gtk_tree_sortable_set_sort_column_id(GTK_TREE_SORTABLE(m), PEER_COL_PROGRESS, GTK_SORT_DESCENDING);
|
|
|
|
v = GTK_WIDGET(g_object_new(GTK_TYPE_TREE_VIEW, "model", m, "rules-hint", TRUE, "has-tooltip", TRUE, NULL));
|
|
|
|
di->peer_view = v;
|
|
|
|
|
|
|
|
g_signal_connect(v, "query-tooltip", G_CALLBACK(onPeerViewQueryTooltip), di);
|
|
|
|
g_object_unref(store);
|
|
|
|
g_signal_connect(v, "button-release-event", G_CALLBACK(on_tree_view_button_released), NULL);
|
|
|
|
|
|
|
|
setPeerViewColumns(GTK_TREE_VIEW(v));
|
|
|
|
|
|
|
|
w = sw = gtk_scrolled_window_new(NULL, NULL);
|
|
|
|
gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(w), GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC);
|
|
|
|
gtk_scrolled_window_set_shadow_type(GTK_SCROLLED_WINDOW(w), GTK_SHADOW_IN);
|
|
|
|
gtk_container_add(GTK_CONTAINER(w), v);
|
|
|
|
|
|
|
|
vbox = gtk_box_new(GTK_ORIENTATION_VERTICAL, GUI_PAD);
|
|
|
|
gtk_container_set_border_width(GTK_CONTAINER(vbox), GUI_PAD_BIG);
|
|
|
|
|
|
|
|
v = gtk_paned_new(GTK_ORIENTATION_VERTICAL);
|
|
|
|
gtk_paned_pack1(GTK_PANED(v), webtree, FALSE, TRUE);
|
|
|
|
gtk_paned_pack2(GTK_PANED(v), sw, TRUE, TRUE);
|
|
|
|
gtk_box_pack_start(GTK_BOX(vbox), v, TRUE, TRUE, 0);
|
|
|
|
|
|
|
|
w = gtk_check_button_new_with_mnemonic(_("Show _more details"));
|
|
|
|
di->more_peer_details_check = w;
|
|
|
|
b = gtr_pref_flag_get(TR_KEY_show_extra_peer_details);
|
|
|
|
gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(w), b);
|
|
|
|
g_signal_connect(w, "toggled", G_CALLBACK(onMorePeerInfoToggled), di);
|
|
|
|
gtk_box_pack_start(GTK_BOX(vbox), w, FALSE, FALSE, 0);
|
|
|
|
|
|
|
|
/* ip-to-GtkTreeRowReference */
|
|
|
|
di->peer_hash = g_hash_table_new_full(g_str_hash, g_str_equal, (GDestroyNotify)g_free,
|
2017-04-21 07:40:57 +00:00
|
|
|
(GDestroyNotify)gtk_tree_row_reference_free);
|
2017-04-19 12:04:45 +00:00
|
|
|
|
|
|
|
/* url-to-GtkTreeRowReference */
|
|
|
|
di->webseed_hash = g_hash_table_new_full(g_str_hash, g_str_equal, (GDestroyNotify)g_free,
|
2017-04-21 07:40:57 +00:00
|
|
|
(GDestroyNotify)gtk_tree_row_reference_free);
|
2017-04-19 12:04:45 +00:00
|
|
|
ret = vbox;
|
|
|
|
return ret;
|
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
|
|
|
****/
|
|
|
|
|
2009-09-25 21:05:59 +00:00
|
|
|
/* if it's been longer than a minute, don't bother showing the seconds */
|
2017-04-19 12:04:45 +00:00
|
|
|
static void tr_strltime_rounded(char* buf, time_t t, size_t buflen)
|
2009-04-24 01:37:04 +00:00
|
|
|
{
|
2017-04-19 12:04:45 +00:00
|
|
|
if (t > 60)
|
|
|
|
{
|
|
|
|
t -= (t % 60);
|
|
|
|
}
|
|
|
|
|
|
|
|
tr_strltime(buf, t, buflen);
|
2009-09-25 21:05:59 +00:00
|
|
|
}
|
2009-03-04 19:52:57 +00:00
|
|
|
|
2017-04-20 16:02:19 +00:00
|
|
|
static void buildTrackerSummary(GString* gstr, char const* key, tr_tracker_stat const* st, gboolean showScrape)
|
2017-04-19 12:04:45 +00:00
|
|
|
{
|
|
|
|
char* str;
|
|
|
|
char timebuf[256];
|
2017-04-20 16:02:19 +00:00
|
|
|
time_t const now = time(NULL);
|
|
|
|
char const* err_markup_begin = "<span color=\"red\">";
|
|
|
|
char const* err_markup_end = "</span>";
|
|
|
|
char const* timeout_markup_begin = "<span color=\"#224466\">";
|
|
|
|
char const* timeout_markup_end = "</span>";
|
|
|
|
char const* success_markup_begin = "<span color=\"#008B00\">";
|
|
|
|
char const* success_markup_end = "</span>";
|
2017-04-19 12:04:45 +00:00
|
|
|
|
|
|
|
/* hostname */
|
|
|
|
{
|
|
|
|
g_string_append(gstr, st->isBackup ? "<i>" : "<b>");
|
|
|
|
|
2017-04-30 16:25:26 +00:00
|
|
|
if (key != NULL)
|
2017-04-19 12:04:45 +00:00
|
|
|
{
|
|
|
|
str = g_markup_printf_escaped("%s - %s", st->host, key);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
str = g_markup_printf_escaped("%s", st->host);
|
|
|
|
}
|
|
|
|
|
|
|
|
g_string_append(gstr, str);
|
|
|
|
g_free(str);
|
|
|
|
g_string_append(gstr, st->isBackup ? "</i>" : "</b>");
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!st->isBackup)
|
|
|
|
{
|
|
|
|
if (st->hasAnnounced && st->announceState != TR_TRACKER_INACTIVE)
|
|
|
|
{
|
|
|
|
g_string_append_c(gstr, '\n');
|
|
|
|
tr_strltime_rounded(timebuf, now - st->lastAnnounceTime, sizeof(timebuf));
|
|
|
|
|
|
|
|
if (st->lastAnnounceSucceeded)
|
|
|
|
{
|
2017-04-21 07:40:57 +00:00
|
|
|
g_string_append_printf(gstr, _("Got a list of %1$s%2$'d peers%3$s %4$s ago"),
|
|
|
|
success_markup_begin, st->lastAnnouncePeerCount, success_markup_end, timebuf);
|
2017-04-19 12:04:45 +00:00
|
|
|
}
|
|
|
|
else if (st->lastAnnounceTimedOut)
|
|
|
|
{
|
2017-04-21 07:40:57 +00:00
|
|
|
g_string_append_printf(gstr, _("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
|
|
|
|
{
|
2017-04-21 07:40:57 +00:00
|
|
|
g_string_append_printf(gstr, _("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
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
switch (st->announceState)
|
|
|
|
{
|
|
|
|
case TR_TRACKER_INACTIVE:
|
|
|
|
g_string_append_c(gstr, '\n');
|
|
|
|
g_string_append(gstr, _("No updates scheduled"));
|
2013-01-04 19:45:39 +00:00
|
|
|
break;
|
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
case TR_TRACKER_WAITING:
|
|
|
|
tr_strltime_rounded(timebuf, st->nextAnnounceTime - now, sizeof(timebuf));
|
|
|
|
g_string_append_c(gstr, '\n');
|
|
|
|
g_string_append_printf(gstr, _("Asking for more peers in %s"), timebuf);
|
2013-01-04 19:45:39 +00:00
|
|
|
break;
|
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
case TR_TRACKER_QUEUED:
|
|
|
|
g_string_append_c(gstr, '\n');
|
|
|
|
g_string_append(gstr, _("Queued to ask for more peers"));
|
2013-01-04 19:45:39 +00:00
|
|
|
break;
|
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
case TR_TRACKER_ACTIVE:
|
|
|
|
tr_strltime_rounded(timebuf, now - st->lastAnnounceStartTime, sizeof(timebuf));
|
|
|
|
g_string_append_c(gstr, '\n');
|
|
|
|
g_string_append_printf(gstr, _("Asking for more peers now… <small>%s</small>"), timebuf);
|
2013-01-04 19:45:39 +00:00
|
|
|
break;
|
2009-09-25 21:05:59 +00:00
|
|
|
}
|
2009-10-10 00:17:00 +00:00
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
if (showScrape)
|
2009-10-10 00:17:00 +00:00
|
|
|
{
|
2017-04-19 12:04:45 +00:00
|
|
|
if (st->hasScraped)
|
2013-01-04 19:45:39 +00:00
|
|
|
{
|
2017-04-19 12:04:45 +00:00
|
|
|
g_string_append_c(gstr, '\n');
|
|
|
|
tr_strltime_rounded(timebuf, now - st->lastScrapeTime, sizeof(timebuf));
|
|
|
|
|
|
|
|
if (st->lastScrapeSucceeded)
|
|
|
|
{
|
2017-04-21 07:40:57 +00:00
|
|
|
g_string_append_printf(gstr, _("Tracker had %s%'d seeders and %'d leechers%s %s ago"), success_markup_begin,
|
|
|
|
st->seederCount, st->leecherCount, success_markup_end, timebuf);
|
2017-04-19 12:04:45 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2017-04-21 07:40:57 +00:00
|
|
|
g_string_append_printf(gstr, _("Got a scrape error \"%s%s%s\" %s ago"), err_markup_begin,
|
|
|
|
st->lastScrapeResult, err_markup_end, timebuf);
|
2017-04-19 12:04:45 +00:00
|
|
|
}
|
2009-10-10 00:17:00 +00:00
|
|
|
}
|
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
switch (st->scrapeState)
|
2009-10-10 00:17:00 +00:00
|
|
|
{
|
2013-01-04 19:45:39 +00:00
|
|
|
case TR_TRACKER_INACTIVE:
|
2017-04-19 12:04:45 +00:00
|
|
|
break;
|
2013-01-04 19:45:39 +00:00
|
|
|
|
|
|
|
case TR_TRACKER_WAITING:
|
2017-04-19 12:04:45 +00:00
|
|
|
g_string_append_c(gstr, '\n');
|
|
|
|
tr_strltime_rounded(timebuf, st->nextScrapeTime - now, sizeof(timebuf));
|
|
|
|
g_string_append_printf(gstr, _("Asking for peer counts in %s"), timebuf);
|
|
|
|
break;
|
2013-01-04 19:45:39 +00:00
|
|
|
|
|
|
|
case TR_TRACKER_QUEUED:
|
2017-04-19 12:04:45 +00:00
|
|
|
g_string_append_c(gstr, '\n');
|
|
|
|
g_string_append(gstr, _("Queued to ask for peer counts"));
|
|
|
|
break;
|
2013-01-04 19:45:39 +00:00
|
|
|
|
|
|
|
case TR_TRACKER_ACTIVE:
|
2017-04-19 12:04:45 +00:00
|
|
|
g_string_append_c(gstr, '\n');
|
|
|
|
tr_strltime_rounded(timebuf, now - st->lastScrapeStartTime, sizeof(timebuf));
|
|
|
|
g_string_append_printf(gstr, _("Asking for peer counts now… <small>%s</small>"), timebuf);
|
|
|
|
break;
|
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
|
|
|
|
2009-09-25 21:05:59 +00:00
|
|
|
enum
|
|
|
|
{
|
2017-04-19 12:04:45 +00:00
|
|
|
TRACKER_COL_TORRENT_ID,
|
|
|
|
TRACKER_COL_TEXT,
|
|
|
|
TRACKER_COL_IS_BACKUP,
|
|
|
|
TRACKER_COL_TRACKER_ID,
|
|
|
|
TRACKER_COL_FAVICON,
|
|
|
|
TRACKER_COL_WAS_UPDATED,
|
|
|
|
TRACKER_COL_KEY,
|
|
|
|
TRACKER_N_COLS
|
2009-09-25 21:05:59 +00:00
|
|
|
};
|
2007-06-06 00:30:13 +00:00
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
static gboolean trackerVisibleFunc(GtkTreeModel* model, GtkTreeIter* iter, gpointer data)
|
2009-09-25 21:05:59 +00:00
|
|
|
{
|
2017-04-19 12:04:45 +00:00
|
|
|
gboolean isBackup;
|
|
|
|
struct DetailsImpl* di = data;
|
2008-02-21 07:29:39 +00:00
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
/* show all */
|
|
|
|
if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(di->all_check)))
|
|
|
|
{
|
|
|
|
return TRUE;
|
|
|
|
}
|
2008-02-21 07:29:39 +00:00
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
/* don't show the backups... */
|
|
|
|
gtk_tree_model_get(model, iter, TRACKER_COL_IS_BACKUP, &isBackup, -1);
|
|
|
|
return !isBackup;
|
2009-09-25 21:05:59 +00:00
|
|
|
}
|
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
static int tracker_list_get_current_torrent_id(struct DetailsImpl* di)
|
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 */
|
2020-09-11 21:07:45 +00:00
|
|
|
if (g_slist_length(di->ids) == 1)
|
2017-04-19 12:04:45 +00:00
|
|
|
{
|
2020-09-11 21:07:45 +00:00
|
|
|
torrent_id = GPOINTER_TO_INT(di->ids->data);
|
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
|
|
|
{
|
2017-04-19 12:04:45 +00:00
|
|
|
GtkTreeIter iter;
|
|
|
|
GtkTreeModel* model;
|
|
|
|
GtkTreeSelection* sel = gtk_tree_view_get_selection(GTK_TREE_VIEW(di->tracker_view));
|
|
|
|
|
|
|
|
if (gtk_tree_selection_get_selected(sel, &model, &iter))
|
|
|
|
{
|
|
|
|
gtk_tree_model_get(model, &iter, TRACKER_COL_TORRENT_ID, &torrent_id, -1);
|
|
|
|
}
|
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
|
|
|
}
|
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
static tr_torrent* tracker_list_get_current_torrent(struct DetailsImpl* di)
|
2011-01-14 21:57:20 +00:00
|
|
|
{
|
2017-04-20 16:02:19 +00:00
|
|
|
int const torrent_id = tracker_list_get_current_torrent_id(di);
|
2017-04-19 12:04:45 +00:00
|
|
|
return gtr_core_find_torrent(di->core, torrent_id);
|
2011-01-14 21:57:20 +00:00
|
|
|
}
|
2009-10-04 02:32:38 +00:00
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
static void favicon_ready_cb(gpointer pixbuf, gpointer vreference)
|
2010-04-23 01:46:02 +00:00
|
|
|
{
|
2017-04-19 12:04:45 +00:00
|
|
|
GtkTreeIter iter;
|
|
|
|
GtkTreeRowReference* reference = vreference;
|
2010-04-23 01:46:02 +00:00
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
if (pixbuf != NULL)
|
2010-04-23 01:46:02 +00:00
|
|
|
{
|
2017-04-19 12:04:45 +00:00
|
|
|
GtkTreePath* path = gtk_tree_row_reference_get_path(reference);
|
|
|
|
GtkTreeModel* model = gtk_tree_row_reference_get_model(reference);
|
2010-04-23 01:46:02 +00:00
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
if (gtk_tree_model_get_iter(model, &iter, path))
|
|
|
|
{
|
|
|
|
gtk_list_store_set(GTK_LIST_STORE(model), &iter, TRACKER_COL_FAVICON, pixbuf, -1);
|
|
|
|
}
|
2010-04-23 01:46:02 +00:00
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
gtk_tree_path_free(path);
|
|
|
|
g_object_unref(pixbuf);
|
2010-04-23 01:46:02 +00:00
|
|
|
}
|
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
gtk_tree_row_reference_free(reference);
|
2010-04-23 01:46:02 +00:00
|
|
|
}
|
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
static void refreshTracker(struct DetailsImpl* di, tr_torrent** torrents, int n)
|
|
|
|
{
|
|
|
|
int* statCount;
|
|
|
|
tr_tracker_stat** stats;
|
|
|
|
GtkTreeIter iter;
|
|
|
|
GtkTreeModel* model;
|
2017-04-21 07:40:57 +00:00
|
|
|
GString* gstr = di->gstr; /* buffer for temporary strings */
|
2017-04-19 12:04:45 +00:00
|
|
|
GHashTable* hash = di->tracker_hash;
|
|
|
|
GtkListStore* store = di->tracker_store;
|
|
|
|
tr_session* session = gtr_core_session(di->core);
|
2017-04-20 16:02:19 +00:00
|
|
|
gboolean const showScrape = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(di->scrape_check));
|
2013-01-04 19:45:39 +00:00
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
/* step 1: get all the trackers */
|
|
|
|
statCount = g_new0(int, n);
|
|
|
|
stats = g_new0(tr_tracker_stat*, n);
|
2013-01-04 19:45:39 +00:00
|
|
|
|
2017-05-13 22:38:31 +00:00
|
|
|
for (int i = 0; i < n; ++i)
|
2017-04-19 12:04:45 +00:00
|
|
|
{
|
|
|
|
stats[i] = tr_torrentTrackers(torrents[i], &statCount[i]);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* step 2: mark all the trackers in the list as not-updated */
|
|
|
|
model = GTK_TREE_MODEL(store);
|
|
|
|
|
|
|
|
if (gtk_tree_model_iter_nth_child(model, &iter, NULL, 0))
|
|
|
|
{
|
|
|
|
do
|
|
|
|
{
|
|
|
|
gtk_list_store_set(store, &iter, TRACKER_COL_WAS_UPDATED, FALSE, -1);
|
2009-09-25 21:05:59 +00:00
|
|
|
}
|
2017-04-19 12:04:45 +00:00
|
|
|
while (gtk_tree_model_iter_next(model, &iter));
|
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 */
|
2017-05-13 22:38:31 +00:00
|
|
|
for (int i = 0; i < n; ++i)
|
2011-04-12 10:51:52 +00:00
|
|
|
{
|
2017-04-20 16:02:19 +00:00
|
|
|
int const jn = statCount[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
|
|
|
{
|
2017-04-20 16:02:19 +00:00
|
|
|
tr_torrent const* tor = torrents[i];
|
|
|
|
tr_tracker_stat const* st = &stats[i][j];
|
|
|
|
int const torrent_id = tr_torrentId(tor);
|
2017-04-19 12:04:45 +00:00
|
|
|
|
|
|
|
/* build the key to find the row */
|
|
|
|
g_string_truncate(gstr, 0);
|
|
|
|
g_string_append_printf(gstr, "%d\t%d\t%s", torrent_id, st->tier, st->announce);
|
2013-01-04 19:45:39 +00:00
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
if (g_hash_table_lookup(hash, gstr->str) == NULL)
|
|
|
|
{
|
|
|
|
GtkTreePath* p;
|
|
|
|
GtkTreeRowReference* ref;
|
|
|
|
|
|
|
|
gtk_list_store_insert_with_values(store, &iter, -1,
|
|
|
|
TRACKER_COL_TORRENT_ID, torrent_id,
|
|
|
|
TRACKER_COL_TRACKER_ID, st->id,
|
|
|
|
TRACKER_COL_KEY, gstr->str,
|
|
|
|
-1);
|
|
|
|
|
|
|
|
p = gtk_tree_model_get_path(model, &iter);
|
|
|
|
ref = gtk_tree_row_reference_new(model, p);
|
|
|
|
g_hash_table_insert(hash, g_strdup(gstr->str), ref);
|
|
|
|
ref = gtk_tree_row_reference_new(model, p);
|
|
|
|
gtr_get_favicon_from_url(session, st->announce, favicon_ready_cb, ref);
|
|
|
|
gtk_tree_path_free(p);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2013-01-04 19:45:39 +00:00
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
/* step 4: update the peers */
|
2017-05-13 22:38:31 +00:00
|
|
|
for (int i = 0; i < n; ++i)
|
2017-04-19 12:04:45 +00:00
|
|
|
{
|
2017-04-20 16:02:19 +00:00
|
|
|
tr_torrent const* tor = torrents[i];
|
|
|
|
char const* summary_name = n > 1 ? tr_torrentName(tor) : NULL;
|
2013-01-04 19:45:39 +00:00
|
|
|
|
2017-05-13 22:38:31 +00:00
|
|
|
for (int j = 0; j < statCount[i]; ++j)
|
2017-04-19 12:04:45 +00:00
|
|
|
{
|
|
|
|
GtkTreePath* p;
|
|
|
|
GtkTreeRowReference* ref;
|
2017-04-20 16:02:19 +00:00
|
|
|
tr_tracker_stat const* st = &stats[i][j];
|
2017-04-19 12:04:45 +00:00
|
|
|
|
|
|
|
/* build the key to find the row */
|
|
|
|
g_string_truncate(gstr, 0);
|
|
|
|
g_string_append_printf(gstr, "%d\t%d\t%s", tr_torrentId(tor), st->tier, st->announce);
|
|
|
|
ref = g_hash_table_lookup(hash, gstr->str);
|
|
|
|
p = gtk_tree_row_reference_get_path(ref);
|
|
|
|
gtk_tree_model_get_iter(model, &iter, p);
|
|
|
|
|
|
|
|
/* update the row */
|
|
|
|
g_string_truncate(gstr, 0);
|
|
|
|
buildTrackerSummary(gstr, summary_name, st, showScrape);
|
|
|
|
gtk_list_store_set(store, &iter,
|
|
|
|
TRACKER_COL_TEXT, gstr->str,
|
|
|
|
TRACKER_COL_IS_BACKUP, st->isBackup,
|
|
|
|
TRACKER_COL_TRACKER_ID, st->id,
|
|
|
|
TRACKER_COL_WAS_UPDATED, TRUE,
|
|
|
|
-1);
|
|
|
|
|
|
|
|
/* cleanup */
|
|
|
|
gtk_tree_path_free(p);
|
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 */
|
|
|
|
if (gtk_tree_model_iter_nth_child(model, &iter, NULL, 0))
|
2013-01-04 19:45:39 +00:00
|
|
|
{
|
2017-04-19 12:04:45 +00:00
|
|
|
gboolean more = TRUE;
|
2013-01-04 19:45:39 +00:00
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
while (more)
|
2013-01-04 19:45:39 +00:00
|
|
|
{
|
2017-04-19 12:04:45 +00:00
|
|
|
gboolean b;
|
|
|
|
gtk_tree_model_get(model, &iter, TRACKER_COL_WAS_UPDATED, &b, -1);
|
|
|
|
|
|
|
|
if (b)
|
2013-01-04 19:45:39 +00:00
|
|
|
{
|
2017-04-19 12:04:45 +00:00
|
|
|
more = gtk_tree_model_iter_next(model, &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
|
|
|
{
|
2017-04-19 12:04:45 +00:00
|
|
|
char* key;
|
|
|
|
gtk_tree_model_get(model, &iter, TRACKER_COL_KEY, &key, -1);
|
|
|
|
g_hash_table_remove(hash, key);
|
|
|
|
more = gtk_list_store_remove(store, &iter);
|
|
|
|
g_free(key);
|
2011-01-14 21:57:20 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
gtk_widget_set_sensitive(di->edit_trackers_button, tracker_list_get_current_torrent_id(di) >= 0);
|
2008-02-21 07:29:39 +00:00
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
/* cleanup */
|
2017-05-13 22:38:31 +00:00
|
|
|
for (int i = 0; i < n; ++i)
|
2017-04-19 12:04:45 +00:00
|
|
|
{
|
|
|
|
tr_torrentTrackersFree(stats[i], statCount[i]);
|
|
|
|
}
|
|
|
|
|
|
|
|
g_free(stats);
|
|
|
|
g_free(statCount);
|
2009-04-24 01:37:04 +00:00
|
|
|
}
|
2008-02-21 07:29:39 +00:00
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
static void onScrapeToggled(GtkToggleButton* button, struct DetailsImpl* di)
|
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;
|
|
|
|
gboolean const value = gtk_toggle_button_get_active(button);
|
2017-04-19 12:04:45 +00:00
|
|
|
gtr_core_set_pref_bool(di->core, key, value);
|
|
|
|
refresh(di);
|
2009-09-25 21:05:59 +00:00
|
|
|
}
|
2008-02-21 07:29:39 +00:00
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
static void onBackupToggled(GtkToggleButton* button, struct DetailsImpl* di)
|
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;
|
|
|
|
gboolean const value = gtk_toggle_button_get_active(button);
|
2017-04-19 12:04:45 +00:00
|
|
|
gtr_core_set_pref_bool(di->core, key, value);
|
|
|
|
refresh(di);
|
2009-09-25 21:05:59 +00:00
|
|
|
}
|
2008-02-21 07:29:39 +00:00
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
static void on_edit_trackers_response(GtkDialog* dialog, int response, gpointer data)
|
2009-09-26 00:48:07 +00:00
|
|
|
{
|
2017-04-19 12:04:45 +00:00
|
|
|
gboolean do_destroy = TRUE;
|
|
|
|
struct DetailsImpl* di = data;
|
2009-09-26 00:48:07 +00:00
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
if (response == GTK_RESPONSE_ACCEPT)
|
2009-09-26 00:48:07 +00:00
|
|
|
{
|
2017-05-01 15:46:41 +00:00
|
|
|
int n;
|
2017-04-19 12:04:45 +00:00
|
|
|
int tier;
|
2017-05-01 15:46:41 +00:00
|
|
|
GtkTextIter start;
|
|
|
|
GtkTextIter end;
|
2017-04-20 16:02:19 +00:00
|
|
|
int const torrent_id = GPOINTER_TO_INT(g_object_get_qdata(G_OBJECT(dialog), TORRENT_ID_KEY));
|
2017-04-19 12:04:45 +00:00
|
|
|
GtkTextBuffer* text_buffer = g_object_get_qdata(G_OBJECT(dialog), TEXT_BUFFER_KEY);
|
|
|
|
tr_torrent* tor = gtr_core_find_torrent(di->core, torrent_id);
|
2013-01-04 19:45:39 +00:00
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
if (tor != NULL)
|
2009-10-10 19:24:46 +00:00
|
|
|
{
|
2017-04-19 12:04:45 +00:00
|
|
|
tr_tracker_info* trackers;
|
|
|
|
char** tracker_strings;
|
|
|
|
char* tracker_text;
|
|
|
|
|
|
|
|
/* build the array of trackers */
|
|
|
|
gtk_text_buffer_get_bounds(text_buffer, &start, &end);
|
|
|
|
tracker_text = gtk_text_buffer_get_text(text_buffer, &start, &end, FALSE);
|
|
|
|
tracker_strings = g_strsplit(tracker_text, "\n", 0);
|
2013-01-04 19:45:39 +00:00
|
|
|
|
2017-05-13 22:38:31 +00:00
|
|
|
trackers = g_new0(tr_tracker_info, g_strv_length(tracker_strings));
|
|
|
|
n = 0;
|
|
|
|
tier = 0;
|
2017-04-19 12:04:45 +00:00
|
|
|
|
2017-05-13 22:38:31 +00:00
|
|
|
for (int i = 0; tracker_strings[i] != NULL; ++i)
|
2017-04-19 12:04:45 +00:00
|
|
|
{
|
2017-05-13 22:38:31 +00:00
|
|
|
char* const str = tracker_strings[i];
|
2017-04-19 12:04:45 +00:00
|
|
|
|
2019-07-13 08:52:44 +00:00
|
|
|
if (tr_str_is_empty(str))
|
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
|
|
|
{
|
2017-04-19 12:04:45 +00:00
|
|
|
trackers[n].tier = tier;
|
2017-05-13 22:38:31 +00:00
|
|
|
trackers[n].announce = str;
|
2017-04-19 12:04:45 +00:00
|
|
|
++n;
|
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 */
|
|
|
|
if (tr_torrentSetAnnounceList(tor, trackers, n))
|
2013-01-04 19:45:39 +00:00
|
|
|
{
|
2017-04-19 12:04:45 +00:00
|
|
|
refresh(di);
|
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
|
|
|
GtkWidget* w;
|
2017-04-20 16:02:19 +00:00
|
|
|
char const* text = _("List contains invalid URLs");
|
2017-04-21 07:40:57 +00:00
|
|
|
w = gtk_message_dialog_new(GTK_WINDOW(dialog), GTK_DIALOG_MODAL, GTK_MESSAGE_ERROR, GTK_BUTTONS_CLOSE, "%s",
|
|
|
|
text);
|
|
|
|
gtk_message_dialog_format_secondary_text(GTK_MESSAGE_DIALOG(w), "%s",
|
|
|
|
_("Please correct the errors and try again."));
|
2017-04-19 12:04:45 +00:00
|
|
|
gtk_dialog_run(GTK_DIALOG(w));
|
|
|
|
gtk_widget_destroy(w);
|
|
|
|
do_destroy = FALSE;
|
2011-01-14 21:57:20 +00:00
|
|
|
}
|
2009-09-26 00:48:07 +00:00
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
/* cleanup */
|
|
|
|
g_free(trackers);
|
|
|
|
g_strfreev(tracker_strings);
|
|
|
|
g_free(tracker_text);
|
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)
|
|
|
|
{
|
|
|
|
gtk_widget_destroy(GTK_WIDGET(dialog));
|
|
|
|
}
|
2009-09-26 00:48:07 +00:00
|
|
|
}
|
|
|
|
|
2017-04-20 16:02:19 +00:00
|
|
|
static void get_editable_tracker_list(GString* gstr, tr_torrent const* tor)
|
2011-01-14 21:57:20 +00:00
|
|
|
{
|
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;
|
|
|
|
g_string_append_c(gstr, '\n');
|
2011-01-14 21:57:20 +00:00
|
|
|
}
|
2013-01-04 19:45:39 +00:00
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
g_string_append_printf(gstr, "%s\n", t->announce);
|
2011-01-14 21:57:20 +00:00
|
|
|
}
|
2013-01-04 19:45:39 +00:00
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
if (gstr->len > 0)
|
2013-01-04 19:45:39 +00:00
|
|
|
{
|
2017-04-19 12:04:45 +00:00
|
|
|
g_string_truncate(gstr, gstr->len - 1);
|
|
|
|
}
|
|
|
|
}
|
2013-01-04 19:45:39 +00:00
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
static void on_edit_trackers(GtkButton* button, gpointer data)
|
|
|
|
{
|
|
|
|
struct DetailsImpl* di = data;
|
|
|
|
tr_torrent* tor = tracker_list_get_current_torrent(di);
|
|
|
|
|
|
|
|
if (tor != NULL)
|
|
|
|
{
|
|
|
|
guint row;
|
2017-05-01 15:46:41 +00:00
|
|
|
GtkWidget* w;
|
|
|
|
GtkWidget* d;
|
|
|
|
GtkWidget* fr;
|
|
|
|
GtkWidget* t;
|
|
|
|
GtkWidget* l;
|
|
|
|
GtkWidget* sw;
|
2017-04-19 12:04:45 +00:00
|
|
|
GtkWindow* win = GTK_WINDOW(gtk_widget_get_toplevel(GTK_WIDGET(button)));
|
2017-04-21 07:40:57 +00:00
|
|
|
GString* gstr = di->gstr; /* buffer for temporary strings */
|
2017-04-20 16:02:19 +00:00
|
|
|
int const torrent_id = tr_torrentId(tor);
|
2017-04-19 12:04:45 +00:00
|
|
|
|
|
|
|
g_string_truncate(gstr, 0);
|
|
|
|
g_string_append_printf(gstr, _("%s - Edit Trackers"), tr_torrentName(tor));
|
2020-07-27 17:49:45 +00:00
|
|
|
d = gtk_dialog_new_with_buttons(gstr->str, win, GTK_DIALOG_MODAL | GTK_DIALOG_DESTROY_WITH_PARENT,
|
|
|
|
_("_Cancel"), GTK_RESPONSE_CANCEL,
|
|
|
|
_("_Save"), GTK_RESPONSE_ACCEPT,
|
|
|
|
NULL);
|
2017-04-19 12:04:45 +00:00
|
|
|
g_signal_connect(d, "response", G_CALLBACK(on_edit_trackers_response), data);
|
|
|
|
|
|
|
|
row = 0;
|
|
|
|
t = hig_workarea_create();
|
|
|
|
hig_workarea_add_section_title(t, &row, _("Tracker Announce URLs"));
|
|
|
|
|
|
|
|
l = gtk_label_new(NULL);
|
|
|
|
gtk_label_set_markup(GTK_LABEL(l), _("To add a backup URL, add it on the line after the primary URL.\n"
|
2017-04-21 07:40:57 +00:00
|
|
|
"To add another primary URL, add it after a blank line."));
|
2017-04-19 12:04:45 +00:00
|
|
|
gtk_label_set_justify(GTK_LABEL(l), GTK_JUSTIFY_LEFT);
|
2019-11-06 19:09:27 +00:00
|
|
|
g_object_set(l, "halign", GTK_ALIGN_START, "valign", GTK_ALIGN_CENTER, NULL);
|
2017-04-19 12:04:45 +00:00
|
|
|
hig_workarea_add_wide_control(t, &row, l);
|
|
|
|
|
|
|
|
w = gtk_text_view_new();
|
|
|
|
g_string_truncate(gstr, 0);
|
|
|
|
get_editable_tracker_list(gstr, tor);
|
|
|
|
gtk_text_buffer_set_text(gtk_text_view_get_buffer(GTK_TEXT_VIEW(w)), gstr->str, -1);
|
|
|
|
fr = gtk_frame_new(NULL);
|
|
|
|
gtk_frame_set_shadow_type(GTK_FRAME(fr), GTK_SHADOW_IN);
|
|
|
|
sw = gtk_scrolled_window_new(NULL, NULL);
|
|
|
|
gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(sw), GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC);
|
|
|
|
gtk_container_add(GTK_CONTAINER(sw), w);
|
|
|
|
gtk_container_add(GTK_CONTAINER(fr), sw);
|
2019-03-17 04:07:48 +00:00
|
|
|
gtk_widget_set_size_request(fr, 500U, 166U);
|
2017-04-19 12:04:45 +00:00
|
|
|
hig_workarea_add_wide_tall_control(t, &row, fr);
|
|
|
|
|
|
|
|
gtr_dialog_set_content(GTK_DIALOG(d), t);
|
|
|
|
|
|
|
|
g_object_set_qdata(G_OBJECT(d), TORRENT_ID_KEY, GINT_TO_POINTER(torrent_id));
|
|
|
|
g_object_set_qdata(G_OBJECT(d), TEXT_BUFFER_KEY, gtk_text_view_get_buffer(GTK_TEXT_VIEW(w)));
|
|
|
|
gtk_widget_show(d);
|
2011-01-14 21:57:20 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
static void on_tracker_list_selection_changed(GtkTreeSelection* sel, gpointer gdi)
|
2011-01-14 21:57:20 +00:00
|
|
|
{
|
2017-04-19 12:04:45 +00:00
|
|
|
struct DetailsImpl* di = gdi;
|
2017-04-20 16:02:19 +00:00
|
|
|
int const n = gtk_tree_selection_count_selected_rows(sel);
|
2017-04-19 12:04:45 +00:00
|
|
|
tr_torrent* tor = tracker_list_get_current_torrent(di);
|
2011-01-14 21:57:20 +00:00
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
gtk_widget_set_sensitive(di->remove_tracker_button, n > 0);
|
|
|
|
gtk_widget_set_sensitive(di->add_tracker_button, tor != NULL);
|
|
|
|
gtk_widget_set_sensitive(di->edit_trackers_button, tor != NULL);
|
2011-01-14 21:57:20 +00:00
|
|
|
}
|
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
static void on_add_tracker_response(GtkDialog* dialog, int response, gpointer gdi)
|
2011-01-14 21:57:20 +00:00
|
|
|
{
|
2017-04-19 12:04:45 +00:00
|
|
|
gboolean destroy = TRUE;
|
2011-01-14 21:57:20 +00:00
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
if (response == GTK_RESPONSE_ACCEPT)
|
2011-01-14 21:57:20 +00:00
|
|
|
{
|
2017-04-19 12:04:45 +00:00
|
|
|
struct DetailsImpl* di = gdi;
|
|
|
|
GtkWidget* e = GTK_WIDGET(g_object_get_qdata(G_OBJECT(dialog), URL_ENTRY_KEY));
|
2017-04-20 16:02:19 +00:00
|
|
|
int const torrent_id = GPOINTER_TO_INT(g_object_get_qdata(G_OBJECT(dialog), TORRENT_ID_KEY));
|
2017-04-19 12:04:45 +00:00
|
|
|
char* url = g_strdup(gtk_entry_get_text(GTK_ENTRY(e)));
|
|
|
|
g_strstrip(url);
|
2011-01-14 21:57:20 +00:00
|
|
|
|
2019-07-13 08:52:44 +00:00
|
|
|
if (!tr_str_is_empty(url))
|
2011-01-14 21:57:20 +00:00
|
|
|
{
|
2017-04-19 12:04:45 +00:00
|
|
|
if (tr_urlIsValidTracker(url))
|
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);
|
|
|
|
tr_variantDictAddStr(&top, TR_KEY_method, "torrent-set");
|
|
|
|
args = tr_variantDictAddDict(&top, TR_KEY_arguments, 2);
|
|
|
|
tr_variantDictAddInt(args, TR_KEY_id, torrent_id);
|
|
|
|
trackers = tr_variantDictAddList(args, TR_KEY_trackerAdd, 1);
|
|
|
|
tr_variantListAddStr(trackers, url);
|
2015-07-13 00:32:48 +00:00
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
gtr_core_exec(di->core, &top);
|
|
|
|
refresh(di);
|
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
|
|
|
{
|
2017-04-19 12:04:45 +00:00
|
|
|
gtr_unrecognized_url_dialog(GTK_WIDGET(dialog), url);
|
|
|
|
destroy = FALSE;
|
2011-01-14 21:57:20 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
g_free(url);
|
2011-01-14 21:57:20 +00:00
|
|
|
}
|
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
if (destroy)
|
|
|
|
{
|
|
|
|
gtk_widget_destroy(GTK_WIDGET(dialog));
|
|
|
|
}
|
2011-01-14 21:57:20 +00:00
|
|
|
}
|
|
|
|
|
2020-08-18 10:36:10 +00:00
|
|
|
static void on_tracker_list_add_button_clicked(GtkButton* button, gpointer gdi)
|
2017-04-19 12:04:45 +00:00
|
|
|
{
|
2020-08-18 10:36:10 +00:00
|
|
|
TR_UNUSED(button);
|
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
struct DetailsImpl* di = gdi;
|
|
|
|
tr_torrent* tor = tracker_list_get_current_torrent(di);
|
|
|
|
|
|
|
|
if (tor != NULL)
|
|
|
|
{
|
|
|
|
guint row;
|
|
|
|
GtkWidget* e;
|
|
|
|
GtkWidget* t;
|
|
|
|
GtkWidget* w;
|
2017-04-21 07:40:57 +00:00
|
|
|
GString* gstr = di->gstr; /* buffer for temporary strings */
|
2017-04-19 12:04:45 +00:00
|
|
|
|
|
|
|
g_string_truncate(gstr, 0);
|
|
|
|
g_string_append_printf(gstr, _("%s - Add Tracker"), tr_torrentName(tor));
|
2020-07-27 17:49:45 +00:00
|
|
|
w = gtk_dialog_new_with_buttons(gstr->str, GTK_WINDOW(di->dialog), GTK_DIALOG_DESTROY_WITH_PARENT,
|
|
|
|
_("_Cancel"), GTK_RESPONSE_CANCEL,
|
|
|
|
_("_Add"), GTK_RESPONSE_ACCEPT,
|
|
|
|
NULL);
|
2017-04-19 12:04:45 +00:00
|
|
|
g_signal_connect(w, "response", G_CALLBACK(on_add_tracker_response), gdi);
|
|
|
|
|
|
|
|
row = 0;
|
|
|
|
t = hig_workarea_create();
|
|
|
|
hig_workarea_add_section_title(t, &row, _("Tracker"));
|
|
|
|
e = gtk_entry_new();
|
|
|
|
gtk_widget_set_size_request(e, 400, -1);
|
|
|
|
gtr_paste_clipboard_url_into_entry(e);
|
|
|
|
g_object_set_qdata(G_OBJECT(w), URL_ENTRY_KEY, e);
|
|
|
|
g_object_set_qdata(G_OBJECT(w), TORRENT_ID_KEY, GINT_TO_POINTER(tr_torrentId(tor)));
|
|
|
|
hig_workarea_add_row(t, &row, _("_Announce URL:"), e, NULL);
|
|
|
|
gtr_dialog_set_content(GTK_DIALOG(w), t);
|
|
|
|
gtk_widget_show_all(w);
|
2011-01-14 21:57:20 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-08-18 10:36:10 +00:00
|
|
|
static void on_tracker_list_remove_button_clicked(GtkButton* button, gpointer gdi)
|
2011-01-14 21:57:20 +00:00
|
|
|
{
|
2020-08-18 10:36:10 +00:00
|
|
|
TR_UNUSED(button);
|
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
GtkTreeIter iter;
|
|
|
|
GtkTreeModel* model;
|
|
|
|
struct DetailsImpl* di = gdi;
|
|
|
|
GtkTreeView* v = GTK_TREE_VIEW(di->tracker_view);
|
|
|
|
GtkTreeSelection* sel = gtk_tree_view_get_selection(v);
|
2013-01-04 19:45:39 +00:00
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
if (gtk_tree_selection_get_selected(sel, &model, &iter))
|
2013-01-04 19:45:39 +00:00
|
|
|
{
|
2017-04-19 12:04:45 +00:00
|
|
|
int torrent_id;
|
|
|
|
int 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
|
|
|
gtk_tree_model_get(model, &iter,
|
|
|
|
TRACKER_COL_TRACKER_ID, &tracker_id,
|
|
|
|
TRACKER_COL_TORRENT_ID, &torrent_id,
|
|
|
|
-1);
|
2015-07-13 00:32:48 +00:00
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
tr_variantInitDict(&top, 2);
|
|
|
|
tr_variantDictAddStr(&top, TR_KEY_method, "torrent-set");
|
|
|
|
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
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
gtr_core_exec(di->core, &top);
|
|
|
|
refresh(di);
|
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
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
static GtkWidget* tracker_page_new(struct DetailsImpl* di)
|
|
|
|
{
|
|
|
|
gboolean b;
|
|
|
|
GtkCellRenderer* r;
|
|
|
|
GtkTreeViewColumn* c;
|
|
|
|
GtkTreeSelection* sel;
|
2017-05-01 15:46:41 +00:00
|
|
|
GtkWidget* vbox;
|
|
|
|
GtkWidget* sw;
|
|
|
|
GtkWidget* w;
|
|
|
|
GtkWidget* v;
|
|
|
|
GtkWidget* hbox;
|
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
|
|
|
|
|
|
|
vbox = gtk_box_new(GTK_ORIENTATION_VERTICAL, GUI_PAD);
|
|
|
|
gtk_container_set_border_width(GTK_CONTAINER(vbox), GUI_PAD_BIG);
|
|
|
|
|
|
|
|
di->tracker_store = gtk_list_store_new(TRACKER_N_COLS,
|
2017-04-21 07:40:57 +00:00
|
|
|
G_TYPE_INT,
|
|
|
|
G_TYPE_STRING,
|
|
|
|
G_TYPE_BOOLEAN,
|
|
|
|
G_TYPE_INT,
|
|
|
|
GDK_TYPE_PIXBUF,
|
|
|
|
G_TYPE_BOOLEAN,
|
|
|
|
G_TYPE_STRING);
|
2017-04-19 12:04:45 +00:00
|
|
|
|
|
|
|
di->tracker_hash = g_hash_table_new_full(g_str_hash, g_str_equal, (GDestroyNotify)g_free,
|
2017-04-21 07:40:57 +00:00
|
|
|
(GDestroyNotify)gtk_tree_row_reference_free);
|
2017-04-19 12:04:45 +00:00
|
|
|
|
|
|
|
di->trackers_filtered = gtk_tree_model_filter_new(GTK_TREE_MODEL(di->tracker_store), NULL);
|
2017-04-30 16:25:26 +00:00
|
|
|
gtk_tree_model_filter_set_visible_func(GTK_TREE_MODEL_FILTER(di->trackers_filtered), trackerVisibleFunc, di, NULL);
|
2017-04-19 12:04:45 +00:00
|
|
|
|
|
|
|
hbox = gtk_box_new(GTK_ORIENTATION_HORIZONTAL, GUI_PAD_BIG);
|
|
|
|
|
|
|
|
v = di->tracker_view = gtk_tree_view_new_with_model(GTK_TREE_MODEL(di->trackers_filtered));
|
|
|
|
g_object_unref(di->trackers_filtered);
|
|
|
|
gtk_tree_view_set_headers_visible(GTK_TREE_VIEW(v), FALSE);
|
|
|
|
g_signal_connect(v, "button-press-event", G_CALLBACK(on_tree_view_button_pressed), NULL);
|
|
|
|
g_signal_connect(v, "button-release-event", G_CALLBACK(on_tree_view_button_released), NULL);
|
|
|
|
|
|
|
|
sel = gtk_tree_view_get_selection(GTK_TREE_VIEW(v));
|
|
|
|
g_signal_connect(sel, "changed", G_CALLBACK(on_tracker_list_selection_changed), di);
|
|
|
|
|
|
|
|
c = gtk_tree_view_column_new();
|
|
|
|
gtk_tree_view_column_set_title(c, _("Trackers"));
|
|
|
|
gtk_tree_view_append_column(GTK_TREE_VIEW(v), c);
|
|
|
|
|
|
|
|
r = gtk_cell_renderer_pixbuf_new();
|
2019-03-17 04:07:48 +00:00
|
|
|
g_object_set(r, "width", 20 + (GUI_PAD_SMALL * 2), "xpad", GUI_PAD_SMALL, "ypad", pad, "yalign", 0.0F, NULL);
|
2017-04-19 12:04:45 +00:00
|
|
|
gtk_tree_view_column_pack_start(c, r, FALSE);
|
|
|
|
gtk_tree_view_column_add_attribute(c, r, "pixbuf", TRACKER_COL_FAVICON);
|
|
|
|
|
|
|
|
r = gtk_cell_renderer_text_new();
|
|
|
|
g_object_set(G_OBJECT(r), "ellipsize", PANGO_ELLIPSIZE_END, "xpad", GUI_PAD_SMALL, "ypad", pad, NULL);
|
|
|
|
gtk_tree_view_column_pack_start(c, r, TRUE);
|
|
|
|
gtk_tree_view_column_add_attribute(c, r, "markup", TRACKER_COL_TEXT);
|
|
|
|
|
|
|
|
sw = gtk_scrolled_window_new(NULL, NULL);
|
|
|
|
gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(sw), GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC);
|
|
|
|
gtk_container_add(GTK_CONTAINER(sw), v);
|
|
|
|
w = gtk_frame_new(NULL);
|
|
|
|
gtk_frame_set_shadow_type(GTK_FRAME(w), GTK_SHADOW_IN);
|
|
|
|
gtk_container_add(GTK_CONTAINER(w), sw);
|
|
|
|
|
|
|
|
gtk_box_pack_start(GTK_BOX(hbox), w, TRUE, TRUE, 0);
|
|
|
|
|
|
|
|
v = gtk_box_new(GTK_ORIENTATION_VERTICAL, GUI_PAD);
|
|
|
|
|
|
|
|
w = gtk_button_new_with_mnemonic(_("_Add"));
|
2013-01-04 19:45:39 +00:00
|
|
|
di->add_tracker_button = w;
|
2017-04-19 12:04:45 +00:00
|
|
|
g_signal_connect(w, "clicked", G_CALLBACK(on_tracker_list_add_button_clicked), di);
|
|
|
|
gtk_box_pack_start(GTK_BOX(v), w, FALSE, FALSE, 0);
|
2013-01-04 19:45:39 +00:00
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
w = gtk_button_new_with_mnemonic(_("_Edit"));
|
|
|
|
g_signal_connect(w, "clicked", G_CALLBACK(on_edit_trackers), di);
|
2013-01-04 19:45:39 +00:00
|
|
|
di->edit_trackers_button = w;
|
2017-04-19 12:04:45 +00:00
|
|
|
gtk_box_pack_start(GTK_BOX(v), w, FALSE, FALSE, 0);
|
2013-01-04 19:45:39 +00:00
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
w = gtk_button_new_with_mnemonic(_("_Remove"));
|
2013-01-04 19:45:39 +00:00
|
|
|
di->remove_tracker_button = w;
|
2017-04-19 12:04:45 +00:00
|
|
|
g_signal_connect(w, "clicked", G_CALLBACK(on_tracker_list_remove_button_clicked), di);
|
|
|
|
gtk_box_pack_start(GTK_BOX(v), w, FALSE, FALSE, 0);
|
2013-01-04 19:45:39 +00:00
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
gtk_box_pack_start(GTK_BOX(hbox), v, FALSE, FALSE, 0);
|
2013-01-04 19:45:39 +00:00
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
gtk_box_pack_start(GTK_BOX(vbox), hbox, TRUE, TRUE, 0);
|
2013-01-04 19:45:39 +00:00
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
w = gtk_check_button_new_with_mnemonic(_("Show _more details"));
|
|
|
|
di->scrape_check = w;
|
|
|
|
b = gtr_pref_flag_get(TR_KEY_show_tracker_scrapes);
|
|
|
|
gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(w), b);
|
|
|
|
g_signal_connect(w, "toggled", G_CALLBACK(onScrapeToggled), di);
|
|
|
|
gtk_box_pack_start(GTK_BOX(vbox), w, FALSE, FALSE, 0);
|
2013-01-04 19:45:39 +00:00
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
w = gtk_check_button_new_with_mnemonic(_("Show _backup trackers"));
|
|
|
|
di->all_check = w;
|
|
|
|
b = gtr_pref_flag_get(TR_KEY_show_backup_trackers);
|
|
|
|
gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(w), b);
|
|
|
|
g_signal_connect(w, "toggled", G_CALLBACK(onBackupToggled), di);
|
|
|
|
gtk_box_pack_start(GTK_BOX(vbox), w, FALSE, FALSE, 0);
|
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
|
|
|
|
****/
|
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
static void refresh(struct DetailsImpl* di)
|
2007-06-06 00:30:13 +00:00
|
|
|
{
|
2017-04-19 12:04:45 +00:00
|
|
|
int n;
|
|
|
|
tr_torrent** torrents = getTorrents(di, &n);
|
2009-04-24 01:37:04 +00:00
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
refreshInfo(di, torrents, n);
|
|
|
|
refreshPeers(di, torrents, n);
|
|
|
|
refreshTracker(di, torrents, n);
|
|
|
|
refreshOptions(di, torrents, n);
|
2009-04-24 01:37:04 +00:00
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
if (n == 0)
|
|
|
|
{
|
|
|
|
gtk_dialog_response(GTK_DIALOG(di->dialog), GTK_RESPONSE_CLOSE);
|
|
|
|
}
|
2009-11-09 07:38:22 +00:00
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
g_free(torrents);
|
2007-06-06 00:30:13 +00:00
|
|
|
}
|
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
static gboolean periodic_refresh(gpointer data)
|
2007-06-06 00:30:13 +00:00
|
|
|
{
|
2017-04-19 12:04:45 +00:00
|
|
|
refresh(data);
|
2013-01-04 16:36:52 +00:00
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
return G_SOURCE_CONTINUE;
|
2007-06-06 00:30:13 +00:00
|
|
|
}
|
|
|
|
|
2020-08-18 10:36:10 +00:00
|
|
|
static void on_details_window_size_allocated(GtkWidget* gtk_window, GtkAllocation* alloc, gpointer gdata)
|
2020-04-27 21:34:02 +00:00
|
|
|
{
|
2020-08-18 10:36:10 +00:00
|
|
|
TR_UNUSED(alloc);
|
|
|
|
TR_UNUSED(gdata);
|
|
|
|
|
2020-11-01 21:47:57 +00:00
|
|
|
int w = 0;
|
|
|
|
int h = 0;
|
2020-04-27 21:34:02 +00:00
|
|
|
gtk_window_get_size(GTK_WINDOW(gtk_window), &w, &h);
|
|
|
|
gtr_pref_int_set(TR_KEY_details_window_width, w);
|
|
|
|
gtr_pref_int_set(TR_KEY_details_window_height, h);
|
|
|
|
}
|
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
static void details_free(gpointer gdata)
|
|
|
|
{
|
|
|
|
struct DetailsImpl* data = gdata;
|
|
|
|
g_source_remove(data->periodic_refresh_tag);
|
|
|
|
g_hash_table_destroy(data->tracker_hash);
|
|
|
|
g_hash_table_destroy(data->webseed_hash);
|
|
|
|
g_hash_table_destroy(data->peer_hash);
|
|
|
|
g_string_free(data->gstr, TRUE);
|
|
|
|
g_slist_free(data->ids);
|
|
|
|
g_free(data);
|
2007-06-06 00:30:13 +00:00
|
|
|
}
|
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
GtkWidget* gtr_torrent_details_dialog_new(GtkWindow* parent, TrCore* core)
|
|
|
|
{
|
2017-05-01 15:46:41 +00:00
|
|
|
GtkWidget* d;
|
|
|
|
GtkWidget* n;
|
|
|
|
GtkWidget* v;
|
|
|
|
GtkWidget* w;
|
|
|
|
GtkWidget* l;
|
2017-04-19 12:04:45 +00:00
|
|
|
struct DetailsImpl* di = g_new0(struct DetailsImpl, 1);
|
|
|
|
|
|
|
|
/* one-time setup */
|
|
|
|
if (ARG_KEY == 0)
|
|
|
|
{
|
|
|
|
ARG_KEY = g_quark_from_static_string("tr-arg-key");
|
|
|
|
DETAILS_KEY = g_quark_from_static_string("tr-details-data-key");
|
|
|
|
TORRENT_ID_KEY = g_quark_from_static_string("tr-torrent-id-key");
|
|
|
|
TEXT_BUFFER_KEY = g_quark_from_static_string("tr-text-buffer-key");
|
|
|
|
URL_ENTRY_KEY = g_quark_from_static_string("tr-url-entry-key");
|
|
|
|
}
|
|
|
|
|
|
|
|
/* create the dialog */
|
|
|
|
di->core = core;
|
|
|
|
di->gstr = g_string_new(NULL);
|
2020-07-27 17:49:45 +00:00
|
|
|
d = gtk_dialog_new_with_buttons(NULL, parent, 0,
|
|
|
|
_("_Close"), GTK_RESPONSE_CLOSE,
|
|
|
|
NULL);
|
2017-04-19 12:04:45 +00:00
|
|
|
di->dialog = d;
|
|
|
|
gtk_window_set_role(GTK_WINDOW(d), "tr-info");
|
2020-04-27 21:34:02 +00:00
|
|
|
|
|
|
|
/* return saved window size */
|
2020-07-30 19:45:11 +00:00
|
|
|
gtk_window_resize(GTK_WINDOW(d),
|
|
|
|
gtr_pref_int_get(TR_KEY_details_window_width),
|
|
|
|
gtr_pref_int_get(TR_KEY_details_window_height));
|
2020-04-27 21:34:02 +00:00
|
|
|
g_signal_connect(d, "size-allocate", G_CALLBACK(on_details_window_size_allocated), NULL);
|
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
g_signal_connect_swapped(d, "response", G_CALLBACK(gtk_widget_destroy), d);
|
|
|
|
gtk_container_set_border_width(GTK_CONTAINER(d), GUI_PAD);
|
|
|
|
g_object_set_qdata_full(G_OBJECT(d), DETAILS_KEY, di, details_free);
|
|
|
|
|
|
|
|
n = gtk_notebook_new();
|
|
|
|
gtk_container_set_border_width(GTK_CONTAINER(n), GUI_PAD);
|
|
|
|
|
|
|
|
w = info_page_new(di);
|
|
|
|
l = gtk_label_new(_("Information"));
|
|
|
|
gtk_notebook_append_page(GTK_NOTEBOOK(n), w, l);
|
|
|
|
|
|
|
|
w = peer_page_new(di);
|
|
|
|
l = gtk_label_new(_("Peers"));
|
2017-04-21 07:40:57 +00:00
|
|
|
gtk_notebook_append_page(GTK_NOTEBOOK(n), w, l);
|
2017-04-19 12:04:45 +00:00
|
|
|
|
|
|
|
w = tracker_page_new(di);
|
|
|
|
l = gtk_label_new(_("Trackers"));
|
|
|
|
gtk_notebook_append_page(GTK_NOTEBOOK(n), w, l);
|
|
|
|
|
|
|
|
v = gtk_box_new(GTK_ORIENTATION_VERTICAL, 0);
|
|
|
|
di->file_list = gtr_file_list_new(core, 0);
|
|
|
|
di->file_label = gtk_label_new(_("File listing not available for combined torrent properties"));
|
|
|
|
gtk_box_pack_start(GTK_BOX(v), di->file_list, TRUE, TRUE, 0);
|
|
|
|
gtk_box_pack_start(GTK_BOX(v), di->file_label, TRUE, TRUE, 0);
|
|
|
|
gtk_container_set_border_width(GTK_CONTAINER(v), GUI_PAD_BIG);
|
|
|
|
l = gtk_label_new(_("Files"));
|
|
|
|
gtk_notebook_append_page(GTK_NOTEBOOK(n), v, l);
|
|
|
|
|
|
|
|
w = options_page_new(di);
|
|
|
|
l = gtk_label_new(_("Options"));
|
|
|
|
gtk_notebook_append_page(GTK_NOTEBOOK(n), w, l);
|
|
|
|
|
|
|
|
gtr_dialog_set_content(GTK_DIALOG(d), n);
|
|
|
|
di->periodic_refresh_tag = gdk_threads_add_timeout_seconds(SECONDARY_WINDOW_REFRESH_INTERVAL_SECONDS, periodic_refresh, di);
|
|
|
|
return d;
|
2007-06-06 00:30:13 +00:00
|
|
|
}
|
2008-09-23 19:11:04 +00:00
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
void gtr_torrent_details_dialog_set_torrents(GtkWidget* w, GSList* ids)
|
2009-04-24 01:37:04 +00:00
|
|
|
{
|
2017-04-19 12:04:45 +00:00
|
|
|
char title[256];
|
2017-04-20 16:02:19 +00:00
|
|
|
int const len = g_slist_length(ids);
|
2017-04-19 12:04:45 +00:00
|
|
|
struct DetailsImpl* di = g_object_get_qdata(G_OBJECT(w), DETAILS_KEY);
|
2009-04-24 01:37:04 +00:00
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
g_slist_free(di->ids);
|
|
|
|
di->ids = g_slist_copy(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
|
|
|
{
|
2017-04-20 16:02:19 +00:00
|
|
|
int const id = GPOINTER_TO_INT(ids->data);
|
2017-04-19 12:04:45 +00:00
|
|
|
tr_torrent* tor = gtr_core_find_torrent(di->core, id);
|
2017-04-20 16:02:19 +00:00
|
|
|
tr_info const* inf = tr_torrentInfo(tor);
|
2017-04-19 12:04:45 +00:00
|
|
|
g_snprintf(title, sizeof(title), _("%s Properties"), inf->name);
|
2013-01-04 19:45:39 +00:00
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
gtr_file_list_set_torrent(di->file_list, id);
|
|
|
|
gtk_widget_show(di->file_list);
|
|
|
|
gtk_widget_hide(di->file_label);
|
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
|
|
|
{
|
2017-04-19 12:04:45 +00:00
|
|
|
gtr_file_list_clear(di->file_list);
|
|
|
|
gtk_widget_hide(di->file_list);
|
|
|
|
gtk_widget_show(di->file_label);
|
|
|
|
g_snprintf(title, sizeof(title), _("%'d Torrent Properties"), len);
|
2009-04-24 01:37:04 +00:00
|
|
|
}
|
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
gtk_window_set_title(GTK_WINDOW(w), title);
|
2009-04-24 12:05:53 +00:00
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
refresh(di);
|
2009-04-24 01:37:04 +00:00
|
|
|
}
|