diff options
-rw-r--r-- | src/trg-main-window.c | 124 | ||||
-rw-r--r-- | src/trg-main-window.h | 2 | ||||
-rw-r--r-- | src/trg-torrent-model.c | 42 | ||||
-rw-r--r-- | src/trg-torrent-model.h | 2 | ||||
-rw-r--r-- | src/trg-torrent-move-dialog.c | 5 | ||||
-rw-r--r-- | src/trg-torrent-props-dialog.c | 9 | ||||
-rw-r--r-- | src/trg-torrent-tree-view.c | 29 | ||||
-rw-r--r-- | src/trg-torrent-tree-view.h | 3 |
8 files changed, 117 insertions, 99 deletions
diff --git a/src/trg-main-window.c b/src/trg-main-window.c index 3d038aa..96aeaa9 100644 --- a/src/trg-main-window.c +++ b/src/trg-main-window.c @@ -69,8 +69,8 @@ #include "trg-remote-prefs-dialog.h" #include "trg-preferences-dialog.h" -static gboolean update_selected_torrent_notebook(TrgMainWindow * win, - gint mode); +static void update_selected_torrent_notebook(TrgMainWindow * win, + gint mode, gint64 id); static void torrent_event_notification(TrgTorrentModel * model, gchar * icon, gchar * desc, gint tmout, gchar * prefKey, @@ -127,10 +127,6 @@ static void on_torrent_get_update(JsonObject * response, int status, static void on_torrent_get_interactive(JsonObject * response, int status, gpointer data); static gboolean trg_update_torrents_timerfunc(gpointer data); -static void trg_main_window_update_notebook_displays(TrgMainWindow * win, - JsonObject * t, - GtkTreeIter * iter, - gint mode); static void open_about_cb(GtkWidget * w, GtkWindow * parent); static gboolean trg_torrent_tree_view_visible_func(GtkTreeModel * model, GtkTreeIter * iter, @@ -142,7 +138,7 @@ static TrgTorrentTreeView static gboolean trg_dialog_error_handler(TrgMainWindow * win, JsonObject * response, int status); -static gboolean torrent_selection_changed(GtkWidget * w, gpointer data); +static gboolean torrent_selection_changed(GtkTreeSelection * selection, gpointer data); static void trg_main_window_torrent_scrub(TrgMainWindow * win); static void entry_filter_changed_cb(GtkWidget * w, gpointer data); static void torrent_state_selection_changed(TrgStateSelector * selector, @@ -244,31 +240,44 @@ static void trg_main_window_init(TrgMainWindow * self G_GNUC_UNUSED) { } -static gboolean update_selected_torrent_notebook(TrgMainWindow * win, - gint mode) +GtkTreeModel *trg_main_window_get_torrent_model(TrgMainWindow *win) { - TrgMainWindowPrivate *priv; - GtkTreeIter iter; - gint newFirstSelected; - JsonObject *json = NULL; + TrgMainWindowPrivate *priv = TRG_MAIN_WINDOW_GET_PRIVATE(win); + return GTK_TREE_MODEL(priv->torrentModel); +} - priv = TRG_MAIN_WINDOW_GET_PRIVATE(win); - newFirstSelected = - get_first_selected(priv->client, priv->torrentTreeView, &iter, - &json); +gint trg_mw_get_selected_torrent_id(TrgMainWindow *win) +{ + TrgMainWindowPrivate *priv = TRG_MAIN_WINDOW_GET_PRIVATE(win); + return priv->selectedTorrentId; +} - if (priv->selectedTorrentId >= 0 - && (priv->selectedTorrentId != newFirstSelected - || newFirstSelected < 0)) { - trg_main_window_torrent_scrub(win); - } +static void update_selected_torrent_notebook(TrgMainWindow * win, + gint mode, gint64 id) +{ + TrgMainWindowPrivate *priv = TRG_MAIN_WINDOW_GET_PRIVATE(win); + trg_client *client = priv->client; + JsonObject *t; + GtkTreeIter iter; - if ((priv->selectedTorrentId = newFirstSelected) >= 0) { - trg_main_window_update_notebook_displays(win, json, &iter, mode); - return TRUE; + if (id >= 0 && id != priv->selectedTorrentId && get_torrent_data(client->torrentTable, id, &t, &iter)) { + trg_toolbar_torrent_actions_sensitive(priv->toolBar, TRUE); + trg_menu_bar_torrent_actions_sensitive(priv->menuBar, TRUE); + trg_general_panel_update(priv->genDetails, t, &iter); + trg_trackers_model_update(priv->trackersModel, client->updateSerial, t, + mode); + trg_files_model_update(priv->filesModel, client->updateSerial, t, + mode); + trg_peers_model_update(priv->peersModel, client->updateSerial, t, + mode); + + } else if (id < 0) { + trg_main_window_torrent_scrub(win); + trg_toolbar_torrent_actions_sensitive(priv->toolBar, FALSE); + trg_menu_bar_torrent_actions_sensitive(priv->menuBar, FALSE); } - return FALSE; + priv->selectedTorrentId = id; } static void torrent_event_notification(TrgTorrentModel * model, @@ -768,7 +777,7 @@ GtkWidget *trg_main_window_notebook_new(TrgMainWindow * win) gtk_widget_set_size_request(notebook, -1, 175); - priv->genDetails = trg_general_panel_new(priv->sortedTorrentModel); + priv->genDetails = trg_general_panel_new(GTK_TREE_MODEL(priv->torrentModel)); gtk_notebook_append_page(GTK_NOTEBOOK(notebook), GTK_WIDGET(priv->genDetails), gtk_label_new(_("General"))); @@ -933,7 +942,7 @@ on_torrent_get(JsonObject * response, int mode, int status, gpointer data) trg_torrent_model_update(priv->torrentModel, priv->client, response, &stats, mode); - update_selected_torrent_notebook(TRG_MAIN_WINDOW(data), mode); + update_selected_torrent_notebook(TRG_MAIN_WINDOW(data), mode, priv->selectedTorrentId); trg_status_bar_update(priv->statusBar, &stats, client); @@ -988,23 +997,6 @@ static gboolean trg_update_torrents_timerfunc(gpointer data) return FALSE; } -static void -trg_main_window_update_notebook_displays(TrgMainWindow * win, - JsonObject * t, - GtkTreeIter * iter, gint mode) -{ - TrgMainWindowPrivate *priv = TRG_MAIN_WINDOW_GET_PRIVATE(win); - trg_client *client = priv->client; - - trg_general_panel_update(priv->genDetails, t, iter); - trg_trackers_model_update(priv->trackersModel, client->updateSerial, t, - mode); - trg_files_model_update(priv->filesModel, client->updateSerial, t, - mode); - trg_peers_model_update(priv->peersModel, client->updateSerial, t, - mode); -} - static void open_about_cb(GtkWidget * w G_GNUC_UNUSED, GtkWindow * parent) { GtkWidget *aboutDialog = trg_about_window_new(parent); @@ -1122,19 +1114,34 @@ trg_dialog_error_handler(TrgMainWindow * win, JsonObject * response, } static gboolean -torrent_selection_changed(GtkWidget * w G_GNUC_UNUSED, gpointer data) +torrent_selection_changed(GtkTreeSelection * selection, gpointer data) { - TrgMainWindowPrivate *priv = TRG_MAIN_WINDOW_GET_PRIVATE(data); TrgMainWindow *win = TRG_MAIN_WINDOW(data); - gboolean isSelected = - update_selected_torrent_notebook(win, TORRENT_GET_MODE_FIRST); + TrgMainWindowPrivate *priv = TRG_MAIN_WINDOW_GET_PRIVATE(data); + GList *selectionList; + GList *firstNode; + gint64 id; - trg_toolbar_torrent_actions_sensitive(priv->toolBar, isSelected); - trg_menu_bar_torrent_actions_sensitive(priv->menuBar, isSelected); + if (trg_torrent_model_is_remove_in_progress(priv->torrentModel)) + return FALSE; + + selectionList = gtk_tree_selection_get_selected_rows(selection, NULL); + firstNode = g_list_first(selectionList); + id = -1; + + if (firstNode) { + GtkTreeIter iter; + if (gtk_tree_model_get_iter + (priv->sortedTorrentModel, &iter, (GtkTreePath *) firstNode->data)) { + gtk_tree_model_get(GTK_TREE_MODEL(priv->sortedTorrentModel), &iter, + TORRENT_COLUMN_ID, &id, -1); + } + } + + g_list_foreach(selectionList, (GFunc) gtk_tree_path_free, NULL); + g_list_free(selectionList); - if (!isSelected) - trg_trackers_model_set_no_selection(TRG_TRACKERS_MODEL - (priv->trackersModel)); + update_selected_torrent_notebook(win, TORRENT_GET_MODE_FIRST, id); return TRUE; } @@ -1177,6 +1184,8 @@ void trg_main_window_torrent_scrub(TrgMainWindow * win) gtk_list_store_clear(GTK_LIST_STORE(priv->trackersModel)); gtk_list_store_clear(GTK_LIST_STORE(priv->peersModel)); trg_general_panel_clear(priv->genDetails); + trg_trackers_model_set_no_selection(TRG_TRACKERS_MODEL + (priv->trackersModel)); } static void entry_filter_changed_cb(GtkWidget * w, gpointer data) @@ -1436,17 +1445,16 @@ static GtkWidget *limit_menu_new(TrgMainWindow * win, gchar * title, JsonArray * ids) { TrgMainWindowPrivate *priv = TRG_MAIN_WINDOW_GET_PRIVATE(win); - + trg_client *client = priv->client; JsonObject *current = NULL; GtkTreeIter iter; GtkWidget *toplevel, *menu, *item; gint64 limit; if (ids) - get_first_selected(priv->client, priv->torrentTreeView, &iter, - ¤t); + get_torrent_data(client->torrentTable, priv->selectedTorrentId, ¤t, &iter); else - current = priv->client->session; + current = client->session; limit = json_object_get_boolean_member(current, enabledKey) ? json_object_get_int_member(current, speedKey) : -1; diff --git a/src/trg-main-window.h b/src/trg-main-window.h index 564dc24..1c3eda8 100644 --- a/src/trg-main-window.h +++ b/src/trg-main-window.h @@ -68,6 +68,8 @@ void trg_main_window_remove_status_icon(TrgMainWindow * win); void trg_main_window_add_graph(TrgMainWindow * win, gboolean show); void trg_main_window_remove_graph(TrgMainWindow * win); TrgStateSelector *trg_main_window_get_state_selector(TrgMainWindow * win); +gint trg_mw_get_selected_torrent_id(TrgMainWindow *win); +GtkTreeModel *trg_main_window_get_torrent_model(TrgMainWindow *win); G_END_DECLS #endif /* MAIN_WINDOW_H_ */ diff --git a/src/trg-torrent-model.c b/src/trg-torrent-model.c index c32e585..4c8add8 100644 --- a/src/trg-torrent-model.c +++ b/src/trg-torrent-model.c @@ -37,6 +37,8 @@ enum { TMODEL_SIGNAL_COUNT }; +#define PROP_REMOVE_IN_PROGRESS "remove-in-progress" + static guint signals[TMODEL_SIGNAL_COUNT] = { 0 }; G_DEFINE_TYPE(TrgTorrentModel, trg_torrent_model, GTK_TYPE_LIST_STORE) @@ -94,7 +96,6 @@ static void trg_torrent_model_class_init(TrgTorrentModelClass * klass) G_STRUCT_OFFSET(TrgTorrentModelClass, torrent_removed), NULL, NULL, g_cclosure_marshal_VOID__VOID, G_TYPE_NONE, 0); - } static void trg_torrent_model_count_peers(TrgTorrentModel * model, @@ -132,8 +133,14 @@ static void trg_torrent_model_ref_free(gpointer data) GtkTreePath *path = gtk_tree_row_reference_get_path(rr); if (path) { GtkTreeIter iter; - if (gtk_tree_model_get_iter(model, &iter, path)) + JsonObject *json; + if (gtk_tree_model_get_iter(model, &iter, path)) { + gtk_tree_model_get(model, &iter, TORRENT_COLUMN_JSON, &json, -1); + json_object_unref(json); + g_object_set_data(G_OBJECT(model), PROP_REMOVE_IN_PROGRESS, GINT_TO_POINTER(TRUE)); gtk_list_store_remove(GTK_LIST_STORE(model), &iter); + g_object_set_data(G_OBJECT(model), PROP_REMOVE_IN_PROGRESS, GINT_TO_POINTER(FALSE)); + } gtk_tree_path_free(path); } @@ -173,6 +180,13 @@ static void trg_torrent_model_init(TrgTorrentModel * self) g_hash_table_new_full(g_int64_hash, g_int64_equal, (GDestroyNotify) g_free, trg_torrent_model_ref_free); + + g_object_set_data(G_OBJECT(self), PROP_REMOVE_IN_PROGRESS, GINT_TO_POINTER(FALSE)); +} + +gboolean trg_torrent_model_is_remove_in_progress(TrgTorrentModel *model) +{ + return (gboolean)GPOINTER_TO_INT(g_object_get_data(G_OBJECT(model), PROP_REMOVE_IN_PROGRESS)); } static guint32 torrent_get_flags(JsonObject * t, gint64 status) @@ -384,6 +398,30 @@ GList *trg_torrent_model_find_removed(GtkTreeModel * model, return args.toRemove; } +gboolean get_torrent_data(GHashTable *table, gint64 id, JsonObject **t, GtkTreeIter *out_iter) +{ + gpointer result = g_hash_table_lookup(table, &id); + gboolean found = FALSE; + + if (result) { + GtkTreeRowReference *rr = (GtkTreeRowReference*)result; + GtkTreePath *path = gtk_tree_row_reference_get_path(rr); + GtkTreeIter iter; + if (path) { + GtkTreeModel *model = gtk_tree_row_reference_get_model(rr); + gtk_tree_model_get_iter(model, &iter, path); + if (out_iter) + *out_iter = iter; + if (t) + gtk_tree_model_get(model, &iter, TORRENT_COLUMN_JSON, t, -1); + found = TRUE; + gtk_tree_path_free(path); + } + } + + return found; +} + void trg_torrent_model_update(TrgTorrentModel * model, trg_client * tc, JsonObject * response, trg_torrent_model_update_stats * stats, diff --git a/src/trg-torrent-model.h b/src/trg-torrent-model.h index 7b6d7dc..4f13e9d 100644 --- a/src/trg-torrent-model.h +++ b/src/trg-torrent-model.h @@ -17,7 +17,6 @@ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. */ - #ifndef TRG_TORRENT_MODEL_H_ #define TRG_TORRENT_MODEL_H_ @@ -76,6 +75,7 @@ void trg_torrent_model_update(TrgTorrentModel * model, trg_client * tc, gint mode); GHashTable *get_torrent_table(TrgTorrentModel * model); +gboolean trg_torrent_model_is_remove_in_progress(TrgTorrentModel *model); enum { TORRENT_COLUMN_ICON, diff --git a/src/trg-torrent-move-dialog.c b/src/trg-torrent-move-dialog.c index 6b2c4a0..f850672 100644 --- a/src/trg-torrent-move-dialog.c +++ b/src/trg-torrent-move-dialog.c @@ -144,8 +144,9 @@ TrgTorrentMoveDialog *trg_torrent_move_dialog_new(TrgMainWindow * win, JsonObject *json; gchar *name; const gchar *current_location; - get_first_selected(client, ttv, &iter, &json); - gtk_tree_model_get(gtk_tree_view_get_model(GTK_TREE_VIEW(ttv)), + + get_torrent_data(client->torrentTable, trg_mw_get_selected_torrent_id(win), &json, &iter); + gtk_tree_model_get(trg_main_window_get_torrent_model(priv->win), &iter, TORRENT_COLUMN_NAME, &name, -1); current_location = torrent_get_download_dir(json); gtk_combo_box_append_text(GTK_COMBO_BOX(priv->location_combo), diff --git a/src/trg-torrent-props-dialog.c b/src/trg-torrent-props-dialog.c index bf9f096..622a89f 100644 --- a/src/trg-torrent-props-dialog.c +++ b/src/trg-torrent-props-dialog.c @@ -51,7 +51,7 @@ typedef struct _TrgTorrentPropsDialogPrivate TrgTorrentPropsDialogPrivate; struct _TrgTorrentPropsDialogPrivate { TrgTorrentTreeView *tv; trg_client *client; - GtkWindow *parent; + TrgMainWindow *parent; JsonArray *targetIds; GtkWidget *bandwidthPriorityCombo; @@ -258,7 +258,6 @@ static GObject *trg_torrent_props_dialog_constructor(GType type, GObject *object; TrgTorrentPropsDialogPrivate *priv; JsonObject *json; - GtkTreeIter iter; GtkTreeSelection *selection; gint rowCount; GtkWidget *notebook; @@ -272,7 +271,7 @@ static GObject *trg_torrent_props_dialog_constructor(GType type, selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(priv->tv)); rowCount = gtk_tree_selection_count_selected_rows(selection); - get_first_selected(priv->client, priv->tv, &iter, &json); + get_torrent_data(priv->client->torrentTable, trg_mw_get_selected_torrent_id(priv->parent), &json, NULL); priv->targetIds = build_json_id_array(priv->tv); if (rowCount > 1) { @@ -285,7 +284,7 @@ static GObject *trg_torrent_props_dialog_constructor(GType type, gtk_window_set_title(GTK_WINDOW(object), torrent_get_name(json)); } - gtk_window_set_transient_for(GTK_WINDOW(object), priv->parent); + gtk_window_set_transient_for(GTK_WINDOW(object), GTK_WINDOW(priv->parent)); gtk_window_set_destroy_with_parent(GTK_WINDOW(object), TRUE); gtk_dialog_add_button(GTK_DIALOG(object), GTK_STOCK_CLOSE, @@ -349,7 +348,7 @@ trg_torrent_props_dialog_class_init(TrgTorrentPropsDialogClass * klass) PROP_PARENT_WINDOW, g_param_spec_object ("parent-window", "Parent window", - "Parent window", GTK_TYPE_WINDOW, + "Parent window", TRG_TYPE_MAIN_WINDOW, G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY | G_PARAM_STATIC_NAME | diff --git a/src/trg-torrent-tree-view.c b/src/trg-torrent-tree-view.c index 5c22fd4..1aa3e56 100644 --- a/src/trg-torrent-tree-view.c +++ b/src/trg-torrent-tree-view.c @@ -67,35 +67,6 @@ static void trg_torrent_tree_view_init(TrgTorrentTreeView * tv) TORRENT_COLUMN_NAME); } -gint get_first_selected(trg_client * client, TrgTorrentTreeView * view, - GtkTreeIter * iter, JsonObject ** json) -{ - GtkTreeModel *model; - GtkTreeSelection *selection; - GList *selectionList; - GList *firstNode; - gint64 id = -1; - - model = gtk_tree_view_get_model(GTK_TREE_VIEW(view)); - - selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(view)); - selectionList = gtk_tree_selection_get_selected_rows(selection, NULL); - - if ((firstNode = g_list_first(selectionList)) != NULL) { - if (gtk_tree_model_get_iter - (model, iter, (GtkTreePath *) firstNode->data)) { - gtk_tree_model_get(model, iter, TORRENT_COLUMN_JSON, json, - TORRENT_COLUMN_ID, &id, -1); - - } - } - - g_list_foreach(selectionList, (GFunc) gtk_tree_path_free, NULL); - g_list_free(selectionList); - - return id; -} - static void trg_torrent_model_get_json_id_array_foreach(GtkTreeModel * model, GtkTreePath * diff --git a/src/trg-torrent-tree-view.h b/src/trg-torrent-tree-view.h index bb6aa8e..382d50e 100644 --- a/src/trg-torrent-tree-view.h +++ b/src/trg-torrent-tree-view.h @@ -51,8 +51,7 @@ GType trg_torrent_tree_view_get_type(void); TrgTorrentTreeView *trg_torrent_tree_view_new(GtkTreeModel * model); JsonArray *build_json_id_array(TrgTorrentTreeView * tv); -gint get_first_selected(trg_client * client, TrgTorrentTreeView * view, - GtkTreeIter * iter, JsonObject ** json); +gboolean get_torrent_data(GHashTable *table, gint64 id, JsonObject **t, GtkTreeIter *out_iter); G_END_DECLS #endif /* _TRG_TORRENT_TREE_VIEW_H_ */ |