From a6482b00613192c454d7550eba9428129c969045 Mon Sep 17 00:00:00 2001 From: Bogdan Vasiliev Date: Tue, 28 Apr 2020 02:34:02 +0500 Subject: [PATCH] GTK: behavior improvements of the torrent details window (#892) * gtk: torrent details file-list default sort * gtk: save torrent details window size * gtk: torrent details window size & sort, code style * gtk: torrent details window, conf.c dict fix Co-authored-by: Charles Kerr --- gtk/conf.c | 4 +++- gtk/details.c | 14 ++++++++++++++ gtk/file-list.c | 4 ++++ libtransmission/quark.c | 2 ++ libtransmission/quark.h | 2 ++ 5 files changed, 25 insertions(+), 1 deletion(-) diff --git a/gtk/conf.c b/gtk/conf.c index c79fda5ae..5c0ca3769 100644 --- a/gtk/conf.c +++ b/gtk/conf.c @@ -74,7 +74,7 @@ static void tr_prefs_init_defaults(tr_variant* d) dir = tr_getDefaultDownloadDir(); } - tr_variantDictReserve(d, 29); + tr_variantDictReserve(d, 31); tr_variantDictAddStr(d, TR_KEY_watch_dir, dir); tr_variantDictAddBool(d, TR_KEY_watch_dir_enabled, FALSE); tr_variantDictAddBool(d, TR_KEY_user_has_given_informed_consent, FALSE); @@ -101,6 +101,8 @@ static void tr_prefs_init_defaults(tr_variant* d) tr_variantDictAddInt(d, TR_KEY_main_window_width, 300); tr_variantDictAddInt(d, TR_KEY_main_window_x, 50); tr_variantDictAddInt(d, TR_KEY_main_window_y, 50); + tr_variantDictAddInt(d, TR_KEY_details_window_height, 500); + tr_variantDictAddInt(d, TR_KEY_details_window_width, 700); tr_variantDictAddStr(d, TR_KEY_download_dir, dir); tr_variantDictAddStr(d, TR_KEY_sort_mode, "sort-by-name"); tr_variantDictAddBool(d, TR_KEY_sort_reversed, FALSE); diff --git a/gtk/details.c b/gtk/details.c index b305dda24..531f25ac8 100644 --- a/gtk/details.c +++ b/gtk/details.c @@ -2897,6 +2897,15 @@ static gboolean periodic_refresh(gpointer data) return G_SOURCE_CONTINUE; } +static void on_details_window_size_allocated(GtkWidget* gtk_window, GtkAllocation* alloc UNUSED, gpointer gdata UNUSED) +{ + GdkWindow* gdk_window = gtk_widget_get_window(gtk_window); + int w, h; + 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); +} + static void details_free(gpointer gdata) { struct DetailsImpl* data = gdata; @@ -2934,6 +2943,11 @@ GtkWidget* gtr_torrent_details_dialog_new(GtkWindow* parent, TrCore* core) d = gtk_dialog_new_with_buttons(NULL, parent, 0, GTK_STOCK_CLOSE, GTK_RESPONSE_CLOSE, NULL); di->dialog = d; gtk_window_set_role(GTK_WINDOW(d), "tr-info"); + + /* return saved window size */ + gtk_window_resize(d, gtr_pref_int_get(TR_KEY_details_window_width), gtr_pref_int_get(TR_KEY_details_window_height)); + g_signal_connect(d, "size-allocate", G_CALLBACK(on_details_window_size_allocated), NULL); + 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); diff --git a/gtk/file-list.c b/gtk/file-list.c index bfe452f11..a58a3f366 100644 --- a/gtk/file-list.c +++ b/gtk/file-list.c @@ -591,6 +591,10 @@ void gtr_file_list_set_torrent(GtkWidget* w, int torrentId) } gtk_tree_view_set_model(GTK_TREE_VIEW(data->view), data->model); + + /* set default sort by label */ + gtk_tree_sortable_set_sort_column_id(data->model, FC_LABEL, GTK_SORT_ASCENDING); + gtk_tree_view_expand_all(GTK_TREE_VIEW(data->view)); g_object_unref(data->model); } diff --git a/libtransmission/quark.c b/libtransmission/quark.c index 1a7042452..547a3e8e2 100644 --- a/libtransmission/quark.c +++ b/libtransmission/quark.c @@ -82,6 +82,8 @@ static struct tr_key_struct const my_static[] = Q("delete-local-data"), Q("desiredAvailable"), Q("destination"), + Q("details-window-height"), + Q("details-window-width"), Q("dht-enabled"), Q("display-name"), Q("dnd"), diff --git a/libtransmission/quark.h b/libtransmission/quark.h index 553df3a1c..f00c32858 100644 --- a/libtransmission/quark.h +++ b/libtransmission/quark.h @@ -82,6 +82,8 @@ enum TR_KEY_delete_local_data, TR_KEY_desiredAvailable, TR_KEY_destination, + TR_KEY_details_window_height, + TR_KEY_details_window_width, TR_KEY_dht_enabled, TR_KEY_display_name, TR_KEY_dnd,