summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGravatar Alan Fitton <ajf@eth0.org.uk>2011-09-08 18:45:12 +0000
committerGravatar Alan Fitton <ajf@eth0.org.uk>2011-09-08 18:45:12 +0000
commite8cf7cb598d2dcb8cba29ccbe89eaa8509b16e63 (patch)
treedd7fac7bc589320a5f6c3592e19a86f2444f72dc
parentdc3a89ca0755edce2031d8e283d17bce18190da1 (diff)
issue 71 - remove trailing slashes from directory names in combo box and state selector to avoid duplicates.
-rw-r--r--src/trg-destination-combo.c29
-rw-r--r--src/trg-state-selector.c4
-rw-r--r--src/util.c15
-rw-r--r--src/util.h1
4 files changed, 36 insertions, 13 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;
}
diff --git a/src/trg-state-selector.c b/src/trg-state-selector.c
index eefb8db..6a2d37a 100644
--- a/src/trg-state-selector.c
+++ b/src/trg-state-selector.c
@@ -306,7 +306,9 @@ void trg_state_selector_update(TrgStateSelector * s) {
}
if (priv->showDirs) {
- const gchar *dir = torrent_get_download_dir(t);
+ gchar *dir = g_strdup(torrent_get_download_dir(t));
+ rm_trailing_slashes(dir);
+
result = g_hash_table_lookup(priv->directories, dir);
if (result) {
trg_state_selector_update_serial(model,
diff --git a/src/util.c b/src/util.c
index 4bcfc1b..b961d3c 100644
--- a/src/util.c
+++ b/src/util.c
@@ -342,3 +342,18 @@ evutil_vsnprintf(char *buf, size_t buflen, const char *format, va_list ap)
return r;
#endif
}
+
+void rm_trailing_slashes(gchar *str)
+{
+ int i, len;
+ if ((len = strlen(str)) < 1)
+ return;
+
+ for (i = strlen(str)-1; str[i]; i--)
+ {
+ if (str[i] == '/')
+ str[i] = '\0';
+ else
+ return;
+ }
+}
diff --git a/src/util.h b/src/util.h
index 3b0d695..2084d86 100644
--- a/src/util.h
+++ b/src/util.h
@@ -65,5 +65,6 @@ size_t tr_strlcpy(char *dst, const void *src, size_t siz);
double tr_truncd(double x, int decimal_places);
int evutil_vsnprintf(char *buf, size_t buflen, const char *format,
va_list ap);
+void rm_trailing_slashes(gchar *str);
#endif /* UTIL_H_ */