diff options
author | Alan Fitton <ajf@eth0.org.uk> | 2011-02-08 10:14:46 +0000 |
---|---|---|
committer | Alan Fitton <ajf@eth0.org.uk> | 2011-02-08 10:14:46 +0000 |
commit | 2a1c6fc96ff03c84723ca1fb7d3a48e0cd3df115 (patch) | |
tree | dd4eec987c7dcb2b7f0c361831c697c95901f4c9 | |
parent | 3938a1340d62d6e207b117e0bc84ddb4f62cf6c8 (diff) |
if the torrent selection changes as a result of an update, was possible that it would select another item which has no JSON but isn't removed from the model yet. use updateSerial and updateMutex to ignore these.
-rw-r--r-- | src/trg-main-window.c | 15 | ||||
-rw-r--r-- | src/trg-peers-model.c | 16 | ||||
-rw-r--r-- | src/trg-torrent-props-dialog.c | 2 | ||||
-rw-r--r-- | src/trg-torrent-tree-view.c | 20 | ||||
-rw-r--r-- | src/trg-torrent-tree-view.h | 2 |
5 files changed, 37 insertions, 18 deletions
diff --git a/src/trg-main-window.c b/src/trg-main-window.c index 3f8e9fd..fe650c0 100644 --- a/src/trg-main-window.c +++ b/src/trg-main-window.c @@ -172,7 +172,7 @@ static gboolean update_selected_torrent_notebook(TrgMainWindow * win, priv = TRG_MAIN_WINDOW_GET_PRIVATE(win); newFirstSelected = - get_first_selected(priv->torrentTreeView, &iter, &json); + get_first_selected(priv->client, priv->torrentTreeView, &iter, &json); if (priv->selectedTorrentId >= 0 && (priv->selectedTorrentId != newFirstSelected @@ -574,20 +574,20 @@ static void remove_cb(GtkWidget * w G_GNUC_UNUSED, gpointer data) { TrgMainWindowPrivate *priv; GtkTreeSelection *selection; + JsonArray *ids; priv = TRG_MAIN_WINDOW_GET_PRIVATE(data); selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(priv->torrentTreeView)); - + ids = build_json_id_array(priv->torrentTreeView); if (confirm_action_dialog (GTK_WINDOW(data), selection, "<big><b>Remove torrent \"%s\"?</b></big>", "<big><b>Remove %d torrents?</b></big>", GTK_STOCK_REMOVE) == GTK_RESPONSE_ACCEPT) dispatch_async(priv->client, - torrent_remove(build_json_id_array - (priv->torrentTreeView), + torrent_remove(ids, FALSE), on_generic_interactive_action, data); } @@ -596,11 +596,13 @@ static void delete_cb(GtkWidget * w G_GNUC_UNUSED, gpointer data) { TrgMainWindowPrivate *priv; GtkTreeSelection *selection; + JsonArray *ids; priv = TRG_MAIN_WINDOW_GET_PRIVATE(data); selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(priv->torrentTreeView)); + ids = build_json_id_array(priv->torrentTreeView); if (confirm_action_dialog (GTK_WINDOW(data), selection, @@ -608,8 +610,7 @@ static void delete_cb(GtkWidget * w G_GNUC_UNUSED, gpointer data) "<big><b>Remove and delete %d torrents?</b></big>", GTK_STOCK_DELETE) == GTK_RESPONSE_ACCEPT) dispatch_async(priv->client, - torrent_remove(build_json_id_array - (priv->torrentTreeView), + torrent_remove(ids, TRUE), on_generic_interactive_action, data); } @@ -1122,6 +1123,8 @@ static gboolean torrent_tv_key_press_event(GtkWidget * w, delete_cb(w, data); else remove_cb(w, data); + } else if (key->keyval == GDK_Return) { + open_props_cb(w, data); } return FALSE; } diff --git a/src/trg-peers-model.c b/src/trg-peers-model.c index 9119678..d2e0191 100644 --- a/src/trg-peers-model.c +++ b/src/trg-peers-model.c @@ -43,16 +43,18 @@ G_DEFINE_TYPE(TrgPeersModel, trg_peers_model, GTK_TYPE_LIST_STORE) typedef struct _TrgPeersModelPrivate TrgPeersModelPrivate; -struct _TrgPeersModelPrivate { #ifdef HAVE_GEOIP +struct _TrgPeersModelPrivate { GeoIP *geoip; -#endif }; +#endif static void trg_peers_model_class_init(TrgPeersModelClass * klass G_GNUC_UNUSED) { +#ifdef HAVE_GEOIP g_type_class_add_private (klass, sizeof (TrgPeersModelPrivate)); +#endif } gboolean @@ -126,7 +128,9 @@ static void resolved_dns_cb(GObject * source_object, void trg_peers_model_update(TrgPeersModel * model, gint64 updateSerial, JsonObject * t, gboolean first) { +#ifdef HAVE_GEOIP TrgPeersModelPrivate *priv = TRG_PEERS_MODEL_GET_PRIVATE(model); +#endif JsonArray *peers; GtkTreeIter peerIter; @@ -141,7 +145,7 @@ void trg_peers_model_update(TrgPeersModel * model, gint64 updateSerial, for (j = 0; j < json_array_get_length(peers); j++) { JsonObject *peer; const gchar *address=NULL, *flagStr; -#if HAVE_GEOIP +#ifdef HAVE_GEOIP const gchar *country = NULL; #endif peer = json_node_get_object(json_array_get_element(peers, j)); @@ -151,7 +155,7 @@ void trg_peers_model_update(TrgPeersModel * model, gint64 updateSerial, gtk_list_store_append(GTK_LIST_STORE(model), &peerIter); address = peer_get_address(peer); -#if HAVE_GEOIP +#ifdef HAVE_GEOIP if (priv->geoip != NULL) country = GeoIP_country_name_by_addr(priv->geoip, address); #endif @@ -210,7 +214,9 @@ void trg_peers_model_update(TrgPeersModel * model, gint64 updateSerial, static void trg_peers_model_init(TrgPeersModel * self) { - TrgPeersModelPrivate *priv = TRG_PEERS_MODEL_GET_PRIVATE(self); +#ifdef HAVE_GEOIP + TrgPeersModelPrivate *priv = TRG_PEERS_MODEL_GET_PRIVATE(self); +#endif GType column_types[PEERSCOL_COLUMNS]; diff --git a/src/trg-torrent-props-dialog.c b/src/trg-torrent-props-dialog.c index 100b876..d45fe66 100644 --- a/src/trg-torrent-props-dialog.c +++ b/src/trg-torrent-props-dialog.c @@ -265,7 +265,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->tv, &iter, &json); + get_first_selected(priv->client, priv->tv, &iter, &json); priv->targetIds = build_json_id_array(priv->tv); if (rowCount > 1) { diff --git a/src/trg-torrent-tree-view.c b/src/trg-torrent-tree-view.c index 9fc0a41..43a49db 100644 --- a/src/trg-torrent-tree-view.c +++ b/src/trg-torrent-tree-view.c @@ -60,14 +60,15 @@ static void trg_torrent_tree_view_init(TrgTorrentTreeView * tv) TORRENT_COLUMN_RATIO, -1); } -gint get_first_selected(TrgTorrentTreeView * view, GtkTreeIter * iter, +gint get_first_selected(trg_client *client, TrgTorrentTreeView * view, GtkTreeIter * iter, JsonObject ** json) { GtkTreeModel *model; GtkTreeSelection *selection; GList *selectionList; GList *firstNode; - gint id = -1; + gint64 id = -1; + gint64 updateSerial = -1; model = gtk_tree_view_get_model(GTK_TREE_VIEW(view)); @@ -76,9 +77,18 @@ gint get_first_selected(TrgTorrentTreeView * view, GtkTreeIter * iter, if ((firstNode = g_list_first(selectionList)) != NULL) { if (gtk_tree_model_get_iter(model, iter, firstNode->data) == TRUE) { - gtk_tree_model_get(model, iter, + gboolean locked; + gtk_tree_model_get(model, iter, TORRENT_COLUMN_JSON, json, - TORRENT_COLUMN_ID, &id, -1); + TORRENT_COLUMN_ID, &id, + TORRENT_COLUMN_UPDATESERIAL, &updateSerial, -1); + + locked = g_mutex_trylock(client->updateMutex); + if (locked) + g_mutex_unlock(client->updateMutex); + + if (updateSerial < (locked ? client->updateSerial-1 : client->updateSerial)) + id = -1; } } @@ -94,7 +104,7 @@ trg_torrent_model_get_json_id_array_foreach(GtkTreeModel * model, gpointer data) { JsonArray *output = (JsonArray *) data; - gint id; + gint64 id; gtk_tree_model_get(model, iter, TORRENT_COLUMN_ID, &id, -1); json_array_add_int_element(output, id); } diff --git a/src/trg-torrent-tree-view.h b/src/trg-torrent-tree-view.h index 48f7265..6e642af 100644 --- a/src/trg-torrent-tree-view.h +++ b/src/trg-torrent-tree-view.h @@ -51,7 +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(TrgTorrentTreeView * view, GtkTreeIter * iter, +gint get_first_selected(trg_client *client, TrgTorrentTreeView * view, GtkTreeIter * iter, JsonObject ** json); G_END_DECLS |