diff options
author | Alan Fitton <ajf@eth0.org.uk> | 2011-09-08 18:45:12 +0000 |
---|---|---|
committer | Alan Fitton <ajf@eth0.org.uk> | 2011-09-08 18:45:12 +0000 |
commit | e8cf7cb598d2dcb8cba29ccbe89eaa8509b16e63 (patch) | |
tree | dd7fac7bc589320a5f6c3592e19a86f2444f72dc /src/trg-destination-combo.c | |
parent | dc3a89ca0755edce2031d8e283d17bce18190da1 (diff) |
issue 71 - remove trailing slashes from directory names in combo box and state selector to avoid duplicates.
Diffstat (limited to 'src/trg-destination-combo.c')
-rw-r--r-- | src/trg-destination-combo.c | 29 |
1 files changed, 17 insertions, 12 deletions
diff --git a/src/trg-destination-combo.c b/src/trg-destination-combo.c index 7c7dedd..c1f3758 100644 --- a/src/trg-destination-combo.c +++ b/src/trg-destination-combo.c @@ -96,16 +96,10 @@ static GObject *trg_destination_combo_constructor(GType type, (trg_destination_combo_parent_class)->constructor(type, n_construct_properties, construct_params); - TrgDestinationComboPrivate *priv = TRG_DESTINATION_COMBO_GET_PRIVATE(object); - TrgClient *client = priv->client; - - const gchar *defaultDownDir = - json_object_get_string_member(trg_client_get_session(client), SGET_DOWNLOAD_DIR); - - GtkListStore *comboModel = gtk_list_store_new(1, G_TYPE_STRING); + TrgClient *client = priv->client; GSList *dirs = NULL; GSList *sli; GList *li; @@ -114,8 +108,15 @@ static GObject *trg_destination_combo_constructor(GType type, GtkTreeRowReference *rr; GtkTreeModel *model; GtkTreePath *path; + GtkListStore *comboModel; JsonObject *t; + gchar *defaultDownDir = + g_strdup(session_get_download_dir(trg_client_get_session(client))); + rm_trailing_slashes(defaultDownDir); + + comboModel = gtk_list_store_new(1, G_TYPE_STRING); + trg_client_updatelock(client); torrentItemRefs = g_hash_table_get_values(trg_client_get_torrent_table(client)); for (li = torrentItemRefs; li; li = g_list_next(li)) { @@ -125,18 +126,23 @@ static GObject *trg_destination_combo_constructor(GType type, if (path) { GtkTreeIter iter; + if (gtk_tree_model_get_iter(model, &iter, path)) { - const gchar *dd; + gchar *dd; gtk_tree_model_get(model, &iter, TORRENT_COLUMN_JSON, &t, -1); - dd = torrent_get_download_dir(t); + dd = g_strdup(torrent_get_download_dir(t)); + rm_trailing_slashes(dd); if (dd && g_strcmp0(dd, defaultDownDir)) g_slist_str_set_add(&dirs, dd, -1); } + gtk_tree_path_free(path); } } + trg_client_updateunlock(client); + g_list_free(torrentItemRefs); g_slist_str_set_add(&dirs, defaultDownDir, 0); @@ -144,15 +150,14 @@ static GObject *trg_destination_combo_constructor(GType type, gtk_list_store_insert_with_values(comboModel, NULL, INT_MAX, 0, (gchar *) sli->data, -1); - trg_client_updateunlock(client); - g_slist_free(dirs); - gtk_combo_box_set_model(GTK_COMBO_BOX(object), GTK_TREE_MODEL(comboModel)); gtk_combo_box_entry_set_text_column(GTK_COMBO_BOX_ENTRY(object), 0); g_object_unref(comboModel); + g_slist_foreach(dirs, (GFunc)g_free, NULL); + g_slist_free(dirs); return object; } |