summaryrefslogtreecommitdiff
path: root/src/trg-torrent-add-dialog.c
diff options
context:
space:
mode:
authorGravatar Alan Fitton <ajf@eth0.org.uk>2011-04-12 10:54:29 +0000
committerGravatar Alan Fitton <ajf@eth0.org.uk>2011-04-12 10:54:29 +0000
commit42eddac0e9f0216175fef223fd9b1023ed502a6e (patch)
tree7fd853c8fdabc678bc1df0f4eb5160420347ac8e /src/trg-torrent-add-dialog.c
parentf4a194f08d0c48641f5394cd07be61931a432241 (diff)
some quite significant changes to only receive/update recently-active torrents, if enabled. also use a hash table and tree row references for lookup. hopefully performance will be much better for people with large number of torrents.
Diffstat (limited to 'src/trg-torrent-add-dialog.c')
-rw-r--r--src/trg-torrent-add-dialog.c34
1 files changed, 24 insertions, 10 deletions
diff --git a/src/trg-torrent-add-dialog.c b/src/trg-torrent-add-dialog.c
index 446f41e..06b1c9b 100644
--- a/src/trg-torrent-add-dialog.c
+++ b/src/trg-torrent-add-dialog.c
@@ -189,25 +189,39 @@ static GtkWidget *trg_destination_folder_new(trg_client * client)
{
const gchar *defaultDownDir = json_object_get_string_member(client->session, SGET_DOWNLOAD_DIR);
GtkWidget *combo = gtk_combo_box_entry_new_text();
- int i;
GSList *dirs = NULL;
- GSList *li;
+ GSList *sli;
+ GList *li;
+ GList *torrentItemRefs;
g_slist_str_set_add(&dirs, defaultDownDir);
g_mutex_lock(client->updateMutex);
- for (i = 0; i < json_array_get_length(client->torrents); i++) {
- JsonObject *t = json_node_get_object(json_array_get_element(client->torrents, i));
- const gchar *dd = torrent_get_download_dir(t);
- if (dd) {
- g_printf("dd: %s\n", dd);
- g_slist_str_set_add(&dirs, dd);
+ torrentItemRefs = g_hash_table_get_values(client->torrentTable);
+ for (li = torrentItemRefs; li; li = g_list_next(li)) {
+ GtkTreeRowReference *rr = (GtkTreeRowReference*)li->data;
+ GtkTreeModel *model = gtk_tree_row_reference_get_model(rr);
+ GtkTreePath *path = gtk_tree_row_reference_get_path(rr);
+ JsonObject *t = NULL;
+
+ if (path) {
+ GtkTreeIter iter;
+ if (gtk_tree_model_get_iter(model, &iter, path)) {
+ const gchar *dd;
+ gtk_tree_model_get(model, &iter, TORRENT_COLUMN_JSON, &t, -1);
+ dd = torrent_get_download_dir(t);
+ if (dd)
+ g_slist_str_set_add(&dirs, dd);
+
+ }
+ gtk_tree_path_free(path);
}
}
+ g_list_free(torrentItemRefs);
g_mutex_unlock(client->updateMutex);
- for (li = dirs; li != NULL; li = g_slist_next(li))
- gtk_combo_box_append_text(GTK_COMBO_BOX(combo), (gchar*)li->data);
+ for (sli = dirs; sli != NULL; sli = g_slist_next(sli))
+ gtk_combo_box_append_text(GTK_COMBO_BOX(combo), (gchar*)sli->data);
gtk_combo_box_set_active(GTK_COMBO_BOX(combo), 0);
g_str_slist_free(dirs);