summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/trg-torrent-add-dialog.c27
-rw-r--r--src/util.c19
-rw-r--r--src/util.h1
3 files changed, 41 insertions, 6 deletions
diff --git a/src/trg-torrent-add-dialog.c b/src/trg-torrent-add-dialog.c
index 46bb30c..446f41e 100644
--- a/src/trg-torrent-add-dialog.c
+++ b/src/trg-torrent-add-dialog.c
@@ -37,6 +37,7 @@
#include "trg-cell-renderer-size.h"
#include "trg-preferences.h"
#include "requests.h"
+#include "torrent.h"
#include "json.h"
#include "dispatch.h"
#include "protocol-constants.h"
@@ -186,11 +187,31 @@ static gchar *trg_destination_folder_get(GtkComboBox * box)
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();
- gtk_combo_box_append_text(GTK_COMBO_BOX(combo),
- json_object_get_string_member
- (client->session, SGET_DOWNLOAD_DIR));
+ int i;
+ GSList *dirs = NULL;
+ GSList *li;
+
+ 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);
+ }
+ }
+ 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);
+
gtk_combo_box_set_active(GTK_COMBO_BOX(combo), 0);
+ g_str_slist_free(dirs);
+
return combo;
}
diff --git a/src/util.c b/src/util.c
index be83f7a..572df3a 100644
--- a/src/util.c
+++ b/src/util.c
@@ -99,15 +99,28 @@ gint gconf_client_get_int_or_default(GConfClient * gconf, const gchar *key, int
return ret;
}
+gboolean g_slist_str_set_add(GSList **list, const gchar *string)
+{
+ GSList *li;
+ for (li = *list; li != NULL; li = g_slist_next(li))
+ if (!g_strcmp0((gchar*)li->data, string))
+ return FALSE;
+
+ *list = g_slist_append(*list, g_strdup(string));
+ return TRUE;
+}
+
gboolean gconf_client_get_bool_or_true(GConfClient * gconf, gchar * key)
{
GError *error = NULL;
- gboolean value = gconf_client_get_bool(gconf, key, &error);
+ GConfValue *value = gconf_client_get_without_default(gconf, key, &error);
+ gboolean ret = TRUE;
if (error) {
g_error_free(error);
- return TRUE;
+ } else if (value) {
+ ret = gconf_value_get_bool(value);
}
- return value;
+ return ret;
}
const gchar *make_error_message(JsonObject * response, int status)
diff --git a/src/util.h b/src/util.h
index 4fc09a4..3903d9f 100644
--- a/src/util.h
+++ b/src/util.h
@@ -39,6 +39,7 @@
#define GIGABYTE_FACTOR ( 1024.0 * 1024.0 * 1024.0 )
void add_file_id_to_array(JsonObject * args, gchar * key, gint index);
+gboolean g_slist_str_set_add(GSList **list, const gchar *string);
void g_str_slist_free(GSList * list);
GRegex *trg_uri_host_regex_new(void);
gchar *trg_gregex_get_first(GRegex * rx, const gchar * uri);