static void
trg_torrent_model_count_peers(TrgTorrentModel * model,
                              GtkTreeIter * iter, JsonObject * t)
{
    GList *trackersList =
        json_array_get_elements(torrent_get_tracker_stats(t));
    gint64 seeders = 0;
    gint64 leechers = 0;
    gint64 downloads = 0;
    GList *li;

    for (li = trackersList; li; li = g_list_next(li)) {
        JsonObject *tracker = json_node_get_object((JsonNode *) li->data);

        seeders += tracker_stats_get_seeder_count(tracker);
        leechers += tracker_stats_get_leecher_count(tracker);
        downloads += tracker_stats_get_download_count(tracker);
    }

    g_list_free(trackersList);

    gtk_list_store_set(GTK_LIST_STORE(model), iter, TORRENT_COLUMN_SEEDS,
                       seeders, TORRENT_COLUMN_LEECHERS, leechers,
                       TORRENT_COLUMN_DOWNLOADS, downloads, -1);
}
Example #2
0
gboolean torrent_has_tracker(JsonObject * t, GRegex * rx, gchar * search)
{
    GList *trackers;
    GList *li;
    gboolean ret = FALSE;

    trackers = json_array_get_elements(torrent_get_tracker_stats(t));

    for (li = trackers; li; li = g_list_next(li)) {
        JsonObject *tracker = json_node_get_object((JsonNode *) li->data);
        const gchar *trackerAnnounce = tracker_stats_get_announce(tracker);
        gchar *trackerAnnounceHost =
            trg_gregex_get_first(rx, trackerAnnounce);
        int cmpResult = g_strcmp0(trackerAnnounceHost, search);
        g_free(trackerAnnounceHost);
        if (!cmpResult) {
            ret = TRUE;
            break;
        }
    }

    g_list_free(trackers);

    return ret;
}
void
trg_trackers_model_update(TrgTrackersModel * model,
                          gint64 updateSerial, JsonObject * t, gint mode)
{
    TrgTrackersModelPrivate *priv = TRG_TRACKERS_MODEL_GET_PRIVATE(model);

    GtkTreeIter trackIter;
    JsonObject *tracker;
    gint64 trackerId;
    GList *trackers, *li;
    const gchar *announce;
    const gchar *scrape;

    if (mode == TORRENT_GET_MODE_FIRST) {
        gtk_list_store_clear(GTK_LIST_STORE(model));
        priv->torrentId = torrent_get_id(t);
        priv->accept = TRUE;
    } else if (!priv->accept) {
        return;
    }

    trackers = json_array_get_elements(torrent_get_tracker_stats(t));

    for (li = trackers; li; li = g_list_next(li)) {
        tracker = json_node_get_object((JsonNode *) li->data);
        trackerId = tracker_stats_get_id(tracker);
        announce = tracker_stats_get_announce(tracker);
        scrape = tracker_stats_get_scrape(tracker);

        if (mode == TORRENT_GET_MODE_FIRST
            || find_existing_model_item(GTK_TREE_MODEL(model),
                                        TRACKERCOL_ID, trackerId,
                                        &trackIter) == FALSE)
            gtk_list_store_append(GTK_LIST_STORE(model), &trackIter);

#ifdef DEBUG
        gtk_list_store_set(GTK_LIST_STORE(model), &trackIter,
                           TRACKERCOL_ICON, GTK_STOCK_NETWORK, -1);
        gtk_list_store_set(GTK_LIST_STORE(model), &trackIter,
                           TRACKERCOL_TIER,
                           tracker_stats_get_tier(tracker), -1);
        gtk_list_store_set(GTK_LIST_STORE(model), &trackIter,
                           TRACKERCOL_ANNOUNCE, announce, -1);
        gtk_list_store_set(GTK_LIST_STORE(model), &trackIter,
                           TRACKERCOL_SCRAPE, scrape, -1);
        gtk_list_store_set(GTK_LIST_STORE(model), &trackIter,
                           TRACKERCOL_ID, trackerId, -1);
        gtk_list_store_set(GTK_LIST_STORE(model), &trackIter,
                           TRACKERCOL_UPDATESERIAL, updateSerial, -1);
        gtk_list_store_set(GTK_LIST_STORE(model), &trackIter,
                           TRACKERCOL_LAST_ANNOUNCE_RESULT,
                           tracker_stats_get_announce_result(tracker), -1);
        gtk_list_store_set(GTK_LIST_STORE(model), &trackIter,
                           TRACKERCOL_LAST_ANNOUNCE_TIME,
                           tracker_stats_get_last_announce_time(tracker),
                           -1);
        gtk_list_store_set(GTK_LIST_STORE(model), &trackIter,
                           TRACKERCOL_LAST_SCRAPE_TIME,
                           tracker_stats_get_last_scrape_time(tracker),
                           -1);
        gtk_list_store_set(GTK_LIST_STORE(model), &trackIter,
                           TRACKERCOL_HOST,
                           tracker_stats_get_host(tracker), -1);
        gtk_list_store_set(GTK_LIST_STORE(model), &trackIter,
                           TRACKERCOL_LAST_ANNOUNCE_PEER_COUNT,
                           tracker_stats_get_last_announce_peer_count
                           (tracker), -1);
        gtk_list_store_set(GTK_LIST_STORE(model), &trackIter,
                           TRACKERCOL_LEECHERCOUNT,
                           tracker_stats_get_leecher_count(tracker), -1);
        gtk_list_store_set(GTK_LIST_STORE(model), &trackIter,
                           TRACKERCOL_SEEDERCOUNT,
                           tracker_stats_get_seeder_count(tracker), -1);
#else
        gtk_list_store_set(GTK_LIST_STORE(model), &trackIter,
                           TRACKERCOL_ICON, GTK_STOCK_NETWORK,
                           TRACKERCOL_ID, trackerId,
                           TRACKERCOL_UPDATESERIAL, updateSerial,
                           TRACKERCOL_TIER,
                           tracker_stats_get_tier(tracker),
                           TRACKERCOL_ANNOUNCE, announce,
                           TRACKERCOL_SCRAPE, scrape, TRACKERCOL_HOST,
                           tracker_stats_get_host(tracker),
                           TRACKERCOL_LAST_ANNOUNCE_RESULT,
                           tracker_stats_get_announce_result(tracker),
                           TRACKERCOL_LAST_ANNOUNCE_TIME,
                           tracker_stats_get_last_announce_time(tracker),
                           TRACKERCOL_LAST_SCRAPE_TIME,
                           tracker_stats_get_last_scrape_time(tracker),
                           TRACKERCOL_LAST_ANNOUNCE_PEER_COUNT,
                           tracker_stats_get_last_announce_peer_count
                           (tracker), TRACKERCOL_LEECHERCOUNT,
                           tracker_stats_get_leecher_count(tracker),
                           TRACKERCOL_SEEDERCOUNT,
                           tracker_stats_get_seeder_count(tracker), -1);
#endif
    }

    g_list_free(trackers);
    trg_model_remove_removed(GTK_LIST_STORE(model),
                             TRACKERCOL_UPDATESERIAL, updateSerial);
}