mirror of
https://github.com/transmission/transmission.git
synced 2025-12-24 12:28:52 +00:00
(trunk) first draft of changing the FreeSpace API to behave as https://trac.transmissionbt.com/ticket/4076#comment:25 -- libT, rpc, qt, and gtk implementations.
This commit is contained in:
@@ -94,6 +94,7 @@ struct OpenData
|
||||
GtkWidget * run_check;
|
||||
GtkWidget * trash_check;
|
||||
GtkWidget * priority_combo;
|
||||
GtkWidget * freespace_label;
|
||||
char * filename;
|
||||
char * downloadDir;
|
||||
tr_torrent * tor;
|
||||
@@ -226,6 +227,8 @@ downloadDirChanged (GtkFileChooserButton * b, gpointer gdata)
|
||||
g_free (data->downloadDir);
|
||||
data->downloadDir = g_strdup (fname);
|
||||
updateTorrent (data);
|
||||
|
||||
gtr_freespace_label_set_dir (data->freespace_label, data->downloadDir);
|
||||
}
|
||||
|
||||
g_free (fname);
|
||||
@@ -339,6 +342,13 @@ gtr_torrent_options_dialog_new (GtkWindow * parent, TrCore * core, tr_ctor * cto
|
||||
g_signal_connect (w, "selection-changed",
|
||||
G_CALLBACK (downloadDirChanged), data);
|
||||
|
||||
row++;
|
||||
l = data->freespace_label = gtr_freespace_label_new (core, data->downloadDir);
|
||||
gtk_widget_set_margin_bottom (l, GUI_PAD_BIG);
|
||||
gtk_misc_set_alignment (GTK_MISC (l), 1.0f, 0.5f);
|
||||
gtk_grid_attach (grid, l, 0, row, 2, 1);
|
||||
|
||||
|
||||
// file list row
|
||||
row++;
|
||||
w = data->file_list;
|
||||
|
||||
@@ -25,6 +25,23 @@
|
||||
#include "tr-prefs.h"
|
||||
#include "util.h"
|
||||
|
||||
/**
|
||||
***
|
||||
**/
|
||||
|
||||
struct prefs_dialog_data
|
||||
{
|
||||
TrCore * core;
|
||||
gulong core_prefs_tag;
|
||||
|
||||
GtkWidget * freespace_label;
|
||||
|
||||
GtkWidget * port_label;
|
||||
GtkWidget * port_button;
|
||||
GtkWidget * port_spin;
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
***
|
||||
**/
|
||||
@@ -256,7 +273,7 @@ target_cb (GtkWidget * tb, gpointer target)
|
||||
****/
|
||||
|
||||
static GtkWidget*
|
||||
downloadingPage (GObject * core)
|
||||
downloadingPage (GObject * core, struct prefs_dialog_data * data)
|
||||
{
|
||||
GtkWidget * t;
|
||||
GtkWidget * w;
|
||||
@@ -289,6 +306,10 @@ downloadingPage (GObject * core)
|
||||
w = new_path_chooser_button (TR_KEY_download_dir, core);
|
||||
hig_workarea_add_row (t, &row, _("Save to _Location:"), w, NULL);
|
||||
|
||||
l = data->freespace_label = gtr_freespace_label_new (TR_CORE(core), NULL);
|
||||
gtk_misc_set_alignment (GTK_MISC (l), 1.0f, 0.5f);
|
||||
hig_workarea_add_wide_control (t, &row, l);
|
||||
|
||||
hig_workarea_add_section_divider (t, &row);
|
||||
hig_workarea_add_section_title (t, &row, _("Download Queue"));
|
||||
|
||||
@@ -1242,11 +1263,49 @@ networkPage (GObject * core)
|
||||
*****
|
||||
****/
|
||||
|
||||
static void
|
||||
on_prefs_dialog_destroyed (gpointer gdata, GObject * dead_dialog G_GNUC_UNUSED)
|
||||
{
|
||||
struct prefs_dialog_data * data = gdata;
|
||||
|
||||
if (data->core_prefs_tag > 0)
|
||||
g_signal_handler_disconnect (data->core, data->core_prefs_tag);
|
||||
|
||||
g_free (data);
|
||||
}
|
||||
|
||||
static void
|
||||
on_core_prefs_changed (TrCore * core, const tr_quark key, gpointer gdata)
|
||||
{
|
||||
struct prefs_dialog_data * data = gdata;
|
||||
|
||||
#if 0
|
||||
if (key == TR_KEY_peer_port)
|
||||
{
|
||||
gtr_label_set_text (GTK_LABEL (data->port_label), _("Status unknown"));
|
||||
gtk_widget_set_sensitive (data->port_button, TRUE);
|
||||
gtk_widget_set_sensitive (data->port_spin, TRUE);
|
||||
}
|
||||
#endif
|
||||
if (key == TR_KEY_download_dir)
|
||||
{
|
||||
const char * downloadDir = tr_sessionGetDownloadDir (gtr_core_session (core));
|
||||
gtr_freespace_label_set_dir (data->freespace_label, downloadDir);
|
||||
}
|
||||
}
|
||||
|
||||
GtkWidget *
|
||||
gtr_prefs_dialog_new (GtkWindow * parent, GObject * core)
|
||||
{
|
||||
size_t i;
|
||||
GtkWidget * d;
|
||||
GtkWidget * n;
|
||||
struct prefs_dialog_data * data;
|
||||
const tr_quark prefs_quarks[] = { TR_KEY_peer_port, TR_KEY_download_dir };
|
||||
|
||||
data = g_new0 (struct prefs_dialog_data, 1);
|
||||
data->core = TR_CORE (core);
|
||||
data->core_prefs_tag = g_signal_connect (TR_CORE (core), "prefs-changed", G_CALLBACK (on_core_prefs_changed), data);
|
||||
|
||||
d = gtk_dialog_new_with_buttons (_("Transmission Preferences"),
|
||||
parent,
|
||||
@@ -1254,6 +1313,7 @@ gtr_prefs_dialog_new (GtkWindow * parent, GObject * core)
|
||||
GTK_STOCK_HELP, GTK_RESPONSE_HELP,
|
||||
GTK_STOCK_CLOSE, GTK_RESPONSE_CLOSE,
|
||||
NULL);
|
||||
g_object_weak_ref (G_OBJECT(d), on_prefs_dialog_destroyed, data);
|
||||
gtk_window_set_role (GTK_WINDOW (d), "transmission-preferences-dialog");
|
||||
gtk_container_set_border_width (GTK_CONTAINER (d), GUI_PAD);
|
||||
|
||||
@@ -1262,7 +1322,7 @@ gtr_prefs_dialog_new (GtkWindow * parent, GObject * core)
|
||||
|
||||
gtk_notebook_append_page (GTK_NOTEBOOK (n), speedPage (core),
|
||||
gtk_label_new (_("Speed")));
|
||||
gtk_notebook_append_page (GTK_NOTEBOOK (n), downloadingPage (core),
|
||||
gtk_notebook_append_page (GTK_NOTEBOOK (n), downloadingPage (core, data),
|
||||
gtk_label_new (C_("Gerund", "Downloading")));
|
||||
gtk_notebook_append_page (GTK_NOTEBOOK (n), seedingPage (core),
|
||||
gtk_label_new (C_("Gerund", "Seeding")));
|
||||
@@ -1275,6 +1335,10 @@ gtr_prefs_dialog_new (GtkWindow * parent, GObject * core)
|
||||
gtk_notebook_append_page (GTK_NOTEBOOK (n), remotePage (core),
|
||||
gtk_label_new (_("Remote")));
|
||||
|
||||
/* init from prefs keys */
|
||||
for (i=0; i<sizeof(prefs_quarks)/sizeof(prefs_quarks[0]); ++i)
|
||||
on_core_prefs_changed (TR_CORE(core), prefs_quarks[i], data);
|
||||
|
||||
g_signal_connect (d, "response", G_CALLBACK (response_cb), core);
|
||||
gtr_dialog_set_content (GTK_DIALOG (d), n);
|
||||
return d;
|
||||
|
||||
@@ -54,8 +54,6 @@ typedef struct
|
||||
GtkLabel * ul_lb;
|
||||
GtkLabel * dl_lb;
|
||||
GtkLabel * stats_lb;
|
||||
GtkLabel * freespace_lb;
|
||||
GtkWidget * freespace_icon;
|
||||
GtkWidget * alt_speed_image;
|
||||
GtkWidget * alt_speed_button;
|
||||
GtkWidget * options_menu;
|
||||
@@ -715,25 +713,6 @@ gtr_window_new (GtkApplication * app, GtkUIManager * ui_mgr, TrCore * core)
|
||||
gtk_grid_attach_next_to (grid, w, sibling, GTK_POS_RIGHT, 1, 1);
|
||||
sibling = w;
|
||||
|
||||
/* freespace */
|
||||
w = gtk_image_new_from_stock (GTK_STOCK_HARDDISK, GTK_ICON_SIZE_MENU);
|
||||
p->freespace_icon = w;
|
||||
g_object_set (G_OBJECT(w), "margin-left", GUI_PAD, NULL);
|
||||
gtk_grid_attach_next_to (grid, w, sibling, GTK_POS_RIGHT, 1, 1);
|
||||
sibling = w;
|
||||
w = gtk_label_new (NULL);
|
||||
g_object_set (G_OBJECT(w), "margin-left", GUI_PAD_BIG*2, NULL);
|
||||
p->freespace_lb = GTK_LABEL (w);
|
||||
gtk_label_set_single_line_mode (p->freespace_lb, TRUE);
|
||||
gtk_grid_attach_next_to (grid, w, sibling, GTK_POS_RIGHT, 1, 1);
|
||||
sibling = w;
|
||||
|
||||
/* spacer */
|
||||
w = gtk_alignment_new (0.0f, 0.0f, 0.0f, 0.0f);
|
||||
gtk_widget_set_hexpand (w, TRUE);
|
||||
gtk_grid_attach_next_to (grid, w, sibling, GTK_POS_RIGHT, 1, 1);
|
||||
sibling = w;
|
||||
|
||||
/* download */
|
||||
w = dl_lb = gtk_label_new (NULL);
|
||||
p->dl_lb = GTK_LABEL (w);
|
||||
@@ -814,45 +793,6 @@ gtr_window_new (GtkApplication * app, GtkUIManager * ui_mgr, TrCore * core)
|
||||
return self;
|
||||
}
|
||||
|
||||
static void
|
||||
updateFreeSpace (PrivateData * p)
|
||||
{
|
||||
GtkWidget * w;
|
||||
bool visible = false;
|
||||
|
||||
g_return_if_fail (p != NULL);
|
||||
|
||||
w = GTK_WIDGET (p->freespace_lb);
|
||||
|
||||
if (p->core != NULL)
|
||||
{
|
||||
tr_session * session = gtr_core_session (p->core);
|
||||
const int64_t n = tr_sessionGetDownloadDirFreeSpace (session);
|
||||
const char * downloadDir = tr_sessionGetDownloadDir (session);
|
||||
|
||||
visible = n >= 0;
|
||||
|
||||
if (visible)
|
||||
{
|
||||
char * str;
|
||||
char sizeStr[32];
|
||||
|
||||
tr_strlsize (sizeStr, n, sizeof(sizeStr));
|
||||
|
||||
str = g_strdup_printf (_("%s Free"), sizeStr);
|
||||
gtk_label_set_text (p->freespace_lb, str);
|
||||
g_free (str);
|
||||
|
||||
str = g_strdup_printf (_("Download folder \"%1$s\" has %2$s free"), downloadDir, sizeStr);
|
||||
gtk_widget_set_tooltip_text (w, str);
|
||||
g_free (str);
|
||||
}
|
||||
}
|
||||
|
||||
gtk_widget_set_visible (w, visible);
|
||||
gtk_widget_set_visible (p->freespace_icon, visible);
|
||||
}
|
||||
|
||||
static void
|
||||
updateStats (PrivateData * p)
|
||||
{
|
||||
@@ -958,7 +898,6 @@ gtr_window_refresh (GtkWindow * self)
|
||||
{
|
||||
updateSpeeds (p);
|
||||
updateStats (p);
|
||||
updateFreeSpace (p);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
120
gtk/util.c
120
gtk/util.c
@@ -26,6 +26,7 @@
|
||||
|
||||
#include "conf.h"
|
||||
#include "hig.h"
|
||||
#include "tr-core.h"
|
||||
#include "tr-prefs.h"
|
||||
#include "util.h"
|
||||
|
||||
@@ -631,3 +632,122 @@ gtr_label_set_text (GtkLabel * lb, const char * newstr)
|
||||
if (tr_strcmp0 (oldstr, newstr))
|
||||
gtk_label_set_text (lb, newstr);
|
||||
}
|
||||
|
||||
/***
|
||||
****
|
||||
***/
|
||||
|
||||
struct freespace_label_data
|
||||
{
|
||||
guint timer_id;
|
||||
TrCore * core;
|
||||
GtkLabel * label;
|
||||
char * dir;
|
||||
};
|
||||
|
||||
static void on_freespace_label_core_destroyed (gpointer gdata, GObject * dead_core);
|
||||
static void on_freespace_label_destroyed (gpointer gdata, GObject * dead_label);
|
||||
|
||||
static void
|
||||
freespace_label_data_free (gpointer gdata)
|
||||
{
|
||||
struct freespace_label_data * data = gdata;
|
||||
|
||||
if (data->core != NULL)
|
||||
g_object_weak_unref (G_OBJECT(data->core), on_freespace_label_core_destroyed, data);
|
||||
|
||||
if (data->label != NULL)
|
||||
g_object_weak_ref (G_OBJECT(data->label), on_freespace_label_destroyed, data);
|
||||
|
||||
g_source_remove (data->timer_id);
|
||||
g_free (data->dir);
|
||||
g_free (data);
|
||||
}
|
||||
|
||||
static GQuark
|
||||
freespace_label_data_quark (void)
|
||||
{
|
||||
static GQuark q = 0;
|
||||
|
||||
if (G_UNLIKELY(!q))
|
||||
q = g_quark_from_static_string ("data");
|
||||
|
||||
return q;
|
||||
}
|
||||
|
||||
static void
|
||||
on_freespace_label_core_destroyed (gpointer gdata, GObject * dead_core G_GNUC_UNUSED)
|
||||
{
|
||||
struct freespace_label_data * data = gdata;
|
||||
data->core = NULL;
|
||||
freespace_label_data_free (data);
|
||||
}
|
||||
|
||||
static void
|
||||
on_freespace_label_destroyed (gpointer gdata, GObject * dead_label G_GNUC_UNUSED)
|
||||
{
|
||||
struct freespace_label_data * data = gdata;
|
||||
data->label = NULL;
|
||||
freespace_label_data_free (data);
|
||||
}
|
||||
|
||||
static gboolean
|
||||
on_freespace_timer (gpointer gdata)
|
||||
{
|
||||
char text[128];
|
||||
char markup[128];
|
||||
int64_t bytes;
|
||||
tr_session * session;
|
||||
struct freespace_label_data * data = gdata;
|
||||
|
||||
session = gtr_core_session (data->core);
|
||||
bytes = tr_sessionGetDirFreeSpace (session, data->dir);
|
||||
|
||||
if (bytes < 0)
|
||||
{
|
||||
g_snprintf (text, sizeof(text), _("Error"));
|
||||
}
|
||||
else
|
||||
{
|
||||
char size[128];
|
||||
tr_strlsize (size, bytes, sizeof(size));
|
||||
g_snprintf (text, sizeof(text), _("%s free"), size);
|
||||
}
|
||||
|
||||
g_snprintf (markup, sizeof(markup), "<i>%s</i>", text);
|
||||
gtk_label_set_markup (data->label, markup);
|
||||
|
||||
return G_SOURCE_CONTINUE;
|
||||
}
|
||||
|
||||
GtkWidget *
|
||||
gtr_freespace_label_new (struct _TrCore * core, const char * dir)
|
||||
{
|
||||
struct freespace_label_data * data;
|
||||
|
||||
data = g_new0 (struct freespace_label_data, 1);
|
||||
data->timer_id = g_timeout_add_seconds (3, on_freespace_timer, data);
|
||||
data->core = core;
|
||||
data->label = GTK_LABEL (gtk_label_new (NULL));
|
||||
data->dir = g_strdup (dir);
|
||||
|
||||
/* when either the core or the label is destroyed, stop updating */
|
||||
g_object_weak_ref (G_OBJECT(core), on_freespace_label_core_destroyed, data);
|
||||
g_object_weak_ref (G_OBJECT(data->label), on_freespace_label_destroyed, data);
|
||||
|
||||
g_object_set_qdata (G_OBJECT(data->label), freespace_label_data_quark (), data);
|
||||
on_freespace_timer (data);
|
||||
return GTK_WIDGET (data->label);
|
||||
}
|
||||
|
||||
void
|
||||
gtr_freespace_label_set_dir (GtkWidget * label, const char * dir)
|
||||
{
|
||||
struct freespace_label_data * data;
|
||||
|
||||
data = g_object_get_qdata (G_OBJECT(label), freespace_label_data_quark ());
|
||||
|
||||
tr_free (data->dir);
|
||||
data->dir = g_strdup (dir);
|
||||
on_freespace_timer (data);
|
||||
}
|
||||
|
||||
10
gtk/util.h
10
gtk/util.h
@@ -109,6 +109,16 @@ void gtr_combo_box_set_active_enum (GtkComboBox *, int value);
|
||||
****
|
||||
***/
|
||||
|
||||
struct _TrCore;
|
||||
|
||||
GtkWidget * gtr_freespace_label_new (struct _TrCore * core, const char * dir);
|
||||
|
||||
void gtr_freespace_label_set_dir (GtkWidget * label, const char * dir);
|
||||
|
||||
/***
|
||||
****
|
||||
***/
|
||||
|
||||
void gtr_unrecognized_url_dialog (GtkWidget * parent, const char * url);
|
||||
|
||||
void gtr_http_failure_dialog (GtkWidget * parent, const char * url, long response_code);
|
||||
|
||||
Reference in New Issue
Block a user