diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/trg-client.c | 3 | ||||
-rw-r--r-- | src/trg-files-model.c | 17 | ||||
-rw-r--r-- | src/trg-peers-model.c | 31 | ||||
-rw-r--r-- | src/trg-state-selector.c | 22 | ||||
-rw-r--r-- | src/trg-torrent-graph.c | 2 | ||||
-rw-r--r-- | src/trg-torrent-model.c | 15 | ||||
-rw-r--r-- | src/trg-trackers-model.c | 17 |
7 files changed, 55 insertions, 52 deletions
diff --git a/src/trg-client.c b/src/trg-client.c index d14d36f..f79adbf 100644 --- a/src/trg-client.c +++ b/src/trg-client.c @@ -41,9 +41,8 @@ gboolean trg_client_supports_tracker_edit(trg_client * tc) trg_client *trg_init_client() { - trg_client *client; + trg_client *client = g_new0(trg_client, 1); - client = g_new0(trg_client, 1); client->gconf = gconf_client_get_default(); client->updateMutex = g_mutex_new(); client->activeOnlyUpdate = diff --git a/src/trg-files-model.c b/src/trg-files-model.c index 66feec6..0327962 100644 --- a/src/trg-files-model.c +++ b/src/trg-files-model.c @@ -35,7 +35,6 @@ typedef struct _TrgFilesModelPrivate TrgFilesModelPrivate; struct _TrgFilesModelPrivate { gint64 torrentId; - JsonArray *files; JsonArray *wanted; JsonArray *priorities; gboolean accept; @@ -113,7 +112,7 @@ gboolean trg_files_model_update_foreach(GtkListStore * model, GtkTreePath * path G_GNUC_UNUSED, GtkTreeIter * iter, - gpointer data G_GNUC_UNUSED) + GList *files) { TrgFilesModelPrivate *priv = TRG_FILES_MODEL_GET_PRIVATE(model); JsonObject *file; @@ -121,7 +120,7 @@ trg_files_model_update_foreach(GtkListStore * model, gtk_tree_model_get(GTK_TREE_MODEL(model), iter, FILESCOL_ID, &id, -1); - file = json_node_get_object(json_array_get_element(priv->files, id)); + file = json_node_get_object(g_list_nth_data(files, id)); trg_files_model_iter_update(TRG_FILES_MODEL(model), iter, file, priv->wanted, priv->priorities, id); @@ -133,19 +132,19 @@ trg_files_model_update(TrgFilesModel * model, gint64 updateSerial, JsonObject * t, gint mode) { TrgFilesModelPrivate *priv = TRG_FILES_MODEL_GET_PRIVATE(model); - GList *li; + GList *filesList, *li; gint j = 0; priv->torrentId = torrent_get_id(t); priv->priorities = torrent_get_priorities(t); priv->wanted = torrent_get_wanted(t); - priv->files = torrent_get_files(t); + + filesList = json_array_get_elements(torrent_get_files(t)); if (mode == TORRENT_GET_MODE_FIRST) { gtk_list_store_clear(GTK_LIST_STORE(model)); priv->accept = TRUE; - for (li = json_array_get_elements(priv->files); li; - li = g_list_next(li)) { + for (li = filesList; li; li = g_list_next(li)) { JsonObject *file = json_node_get_object((JsonNode *) li->data); GtkTreeIter filesIter; trg_files_model_iter_new(model, &filesIter, file, j); @@ -157,8 +156,10 @@ trg_files_model_update(TrgFilesModel * model, gint64 updateSerial, } else { gtk_tree_model_foreach(GTK_TREE_MODEL(model), (GtkTreeModelForeachFunc) - trg_files_model_update_foreach, NULL); + trg_files_model_update_foreach, filesList); } + + g_list_free(filesList); } gint64 trg_files_model_get_torrent_id(TrgFilesModel * model) diff --git a/src/trg-peers-model.c b/src/trg-peers-model.c index 566685b..b80b05a 100644 --- a/src/trg-peers-model.c +++ b/src/trg-peers-model.c @@ -61,11 +61,9 @@ find_existing_peer_item_foreachfunc(GtkTreeModel * model, GtkTreePath * path G_GNUC_UNUSED, GtkTreeIter * iter, gpointer data) { - struct peerAndIter *pi; - gchar *ip; - - pi = (struct peerAndIter *) data; + struct peerAndIter *pi = (struct peerAndIter *)data; + gchar *ip; gtk_tree_model_get(model, iter, PEERSCOL_IP, &ip, -1); if (g_strcmp0(ip, pi->ip) == 0) { pi->iter = *iter; @@ -132,7 +130,7 @@ void trg_peers_model_update(TrgPeersModel * model, gint64 updateSerial, JsonArray *peers; GtkTreeIter peerIter; - GList *li; + GList *li, *peersList; gboolean isNew; peers = torrent_get_peers(t); @@ -140,7 +138,8 @@ void trg_peers_model_update(TrgPeersModel * model, gint64 updateSerial, if (mode == TORRENT_GET_MODE_FIRST) gtk_list_store_clear(GTK_LIST_STORE(model)); - for (li = json_array_get_elements(peers); li; li = g_list_next(li)) { + peersList = json_array_get_elements(peers); + for (li = peersList; li; li = g_list_next(li)) { JsonObject *peer = json_node_get_object((JsonNode *) li->data); const gchar *address = NULL, *flagStr; #ifdef HAVE_GEOIP @@ -153,7 +152,7 @@ void trg_peers_model_update(TrgPeersModel * model, gint64 updateSerial, address = peer_get_address(peer); #ifdef HAVE_GEOIP - if (priv->geoip != NULL) + if (priv->geoip) country = GeoIP_country_name_by_addr(priv->geoip, address); #endif gtk_list_store_set(GTK_LIST_STORE(model), &peerIter, @@ -161,7 +160,7 @@ void trg_peers_model_update(TrgPeersModel * model, gint64 updateSerial, PEERSCOL_IP, address, #ifdef HAVE_GEOIP PEERSCOL_COUNTRY, - country != NULL ? country : "", + country ? country : "", #endif PEERSCOL_CLIENT, peer_get_client_name(peer), -1); @@ -183,15 +182,13 @@ void trg_peers_model_update(TrgPeersModel * model, gint64 updateSerial, PEERSCOL_UPDATESERIAL, updateSerial, -1); if (isNew == TRUE) { - GtkTreePath *path; - GtkTreeRowReference *treeRef; + GtkTreePath *path = + gtk_tree_model_get_path(GTK_TREE_MODEL(model), &peerIter); + GtkTreeRowReference *treeRef = + gtk_tree_row_reference_new(GTK_TREE_MODEL(model), path); GInetAddress *inetAddr; GResolver *resolver; - path = - gtk_tree_model_get_path(GTK_TREE_MODEL(model), &peerIter); - treeRef = - gtk_tree_row_reference_new(GTK_TREE_MODEL(model), path); gtk_tree_path_free(path); inetAddr = g_inet_address_new_from_string(address); @@ -204,6 +201,8 @@ void trg_peers_model_update(TrgPeersModel * model, gint64 updateSerial, } } + g_list_free(peersList); + if (mode != TORRENT_GET_MODE_FIRST) trg_model_remove_removed(GTK_LIST_STORE(model), PEERSCOL_UPDATESERIAL, updateSerial); @@ -244,7 +243,5 @@ static void trg_peers_model_init(TrgPeersModel * self) TrgPeersModel *trg_peers_model_new() { - GObject *obj = g_object_new(TRG_TYPE_PEERS_MODEL, NULL); - - return TRG_PEERS_MODEL(obj); + return g_object_new(TRG_TYPE_PEERS_MODEL, NULL); } diff --git a/src/trg-state-selector.c b/src/trg-state-selector.c index 7ffe12c..816d7a1 100644 --- a/src/trg-state-selector.c +++ b/src/trg-state-selector.c @@ -216,21 +216,23 @@ void trg_state_selector_update(TrgStateSelector * s) TrgStateSelectorPrivate *priv = TRG_STATE_SELECTOR_GET_PRIVATE(s); GtkTreeModel *model = gtk_tree_view_get_model(GTK_TREE_VIEW(s)); trg_client *client = priv->client; - GtkTreeIter iter; - GList *trackerItem, *li; GList *torrentItemRefs = g_hash_table_get_values(client->torrentTable); - + GtkTreeIter iter; + GList *trackersList, *trackerItem, *li; + GtkTreeRowReference *rr; + GtkTreePath *path; + GtkTreeModel *torrentModel; + gpointer result; struct cruft_remove_args cruft; if (!client->session) return; for (li = torrentItemRefs; li; li = g_list_next(li)) { - GtkTreeRowReference *rr = (GtkTreeRowReference *) li->data; - GtkTreePath *path = gtk_tree_row_reference_get_path(rr); - GtkTreeModel *torrentModel = gtk_tree_row_reference_get_model(rr); JsonObject *t = NULL; - gpointer result; + rr = (GtkTreeRowReference *) li->data; + path = gtk_tree_row_reference_get_path(rr); + torrentModel = gtk_tree_row_reference_get_model(rr); if (path) { GtkTreeIter iter; @@ -245,9 +247,8 @@ void trg_state_selector_update(TrgStateSelector * s) continue; if (priv->showTrackers) { - JsonArray *trackers = torrent_get_trackers(t); - - for (trackerItem = json_array_get_elements(trackers); + trackersList = json_array_get_elements(torrent_get_trackers(t)); + for (trackerItem = trackersList; trackerItem; trackerItem = g_list_next(trackerItem)) { JsonObject *tracker = json_node_get_object((JsonNode *) trackerItem->data); @@ -284,6 +285,7 @@ void trg_state_selector_update(TrgStateSelector * s) quick_tree_ref_new(model, &iter)); } } + g_list_free(trackersList); } if (priv->showDirs) { diff --git a/src/trg-torrent-graph.c b/src/trg-torrent-graph.c index fd38cae..3f599ae 100644 --- a/src/trg-torrent-graph.c +++ b/src/trg-torrent-graph.c @@ -394,7 +394,7 @@ static void trg_torrent_graph_update_net(TrgTorrentGraph * g) fp[0] = 1.0f * priv->out / priv->max; fp[1] = 1.0f * priv->in / priv->max; - trg_strlspeed(speed, (gint64) (priv->out / 1024)); + trg_strlspeed(speed, (gint64) (priv->out / KILOBYTE_FACTOR)); labelMarkup = g_markup_printf_escaped("<span font_size=\"small\" color=\"" GRAPH_OUT_COLOR "\">%s: %s</span>", diff --git a/src/trg-torrent-model.c b/src/trg-torrent-model.c index c9a8f36..c32e585 100644 --- a/src/trg-torrent-model.c +++ b/src/trg-torrent-model.c @@ -101,16 +101,14 @@ static void trg_torrent_model_count_peers(TrgTorrentModel * model, GtkTreeIter * iter, JsonObject * t) { - JsonArray *peers; + GList *peersList = json_array_get_elements(torrent_get_peers(t)); gint seeders, leechers; GList *li; - peers = torrent_get_peers(t); - seeders = 0; leechers = 0; - for (li = json_array_get_elements(peers); li; li = g_list_next(li)) { + for (li = peersList; li; li = g_list_next(li)) { JsonObject *peer = json_node_get_object((JsonNode *) li->data); if (peer_get_is_downloading_from(peer)) @@ -120,6 +118,8 @@ static void trg_torrent_model_count_peers(TrgTorrentModel * model, leechers++; } + g_list_free(peersList); + gtk_list_store_set(GTK_LIST_STORE(model), iter, TORRENT_COLUMN_SEEDS, seeders, TORRENT_COLUMN_LEECHERS, leechers, -1); @@ -391,6 +391,7 @@ void trg_torrent_model_update(TrgTorrentModel * model, trg_client * tc, { TrgTorrentModelPrivate *priv = TRG_TORRENT_MODEL_GET_PRIVATE(model); + GList *torrentList; JsonObject *args, *t; GList *li; gint64 id; @@ -403,9 +404,9 @@ void trg_torrent_model_update(TrgTorrentModel * model, trg_client * tc, gboolean addRemove = FALSE; args = get_arguments(response); + torrentList = json_array_get_elements(get_torrents(args)); - for (li = json_array_get_elements(get_torrents(args)); li; - li = g_list_next(li)) { + for (li = torrentList; li; li = g_list_next(li)) { t = json_node_get_object((JsonNode *) li->data); id = torrent_get_id(t); @@ -443,6 +444,8 @@ void trg_torrent_model_update(TrgTorrentModel * model, trg_client * tc, } } + g_list_free(torrentList); + if (mode == TORRENT_GET_MODE_UPDATE) { GList *hitlist = trg_torrent_model_find_removed(GTK_TREE_MODEL(model), diff --git a/src/trg-trackers-model.c b/src/trg-trackers-model.c index d17f29f..28f7ea1 100644 --- a/src/trg-trackers-model.c +++ b/src/trg-trackers-model.c @@ -54,8 +54,10 @@ void trg_trackers_model_update(TrgTrackersModel * model, { TrgTrackersModelPrivate *priv = TRG_TRACKERS_MODEL_GET_PRIVATE(model); - JsonArray *trackers; - GList *li; + GtkTreeIter trackIter; + JsonObject *tracker; + gint64 trackerId; + GList *trackers, *li; const gchar *announce; const gchar *scrape; @@ -67,13 +69,11 @@ void trg_trackers_model_update(TrgTrackersModel * model, return; } - trackers = torrent_get_trackers(t); - - for (li = json_array_get_elements(trackers); li; li = g_list_next(li)) { - GtkTreeIter trackIter; - JsonObject *tracker = json_node_get_object((JsonNode *) li->data); - gint64 trackerId = tracker_get_id(tracker); + trackers = json_array_get_elements(torrent_get_trackers(t)); + for (li = trackers; li; li = g_list_next(li)) { + tracker = json_node_get_object((JsonNode *) li->data); + trackerId = tracker_get_id(tracker); announce = tracker_get_announce(tracker); scrape = tracker_get_scrape(tracker); @@ -108,6 +108,7 @@ void trg_trackers_model_update(TrgTrackersModel * model, #endif } + g_list_free(trackers); trg_model_remove_removed(GTK_LIST_STORE(model), TRACKERCOL_UPDATESERIAL, updateSerial); } |