diff options
Diffstat (limited to 'src/trg-destination-combo.c')
-rw-r--r-- | src/trg-destination-combo.c | 41 |
1 files changed, 26 insertions, 15 deletions
diff --git a/src/trg-destination-combo.c b/src/trg-destination-combo.c index 9dc4b87..7c7dedd 100644 --- a/src/trg-destination-combo.c +++ b/src/trg-destination-combo.c @@ -32,7 +32,7 @@ G_DEFINE_TYPE(TrgDestinationCombo, trg_destination_combo, typedef struct _TrgDestinationComboPrivate TrgDestinationComboPrivate; struct _TrgDestinationComboPrivate { - trg_client *client; + TrgClient *client; }; enum { @@ -71,6 +71,21 @@ trg_destination_combo_set_property(GObject * object, guint property_id, } } +static gboolean g_slist_str_set_add(GSList ** list, const gchar * string, gint pos) +{ + GSList *li; + for (li = *list; li; li = g_slist_next(li)) + if (!g_strcmp0((gchar *) li->data, string)) + return FALSE; + + if (pos < 0) + *list = g_slist_insert_sorted(*list, (gpointer)string, (GCompareFunc)g_strcmp0); + else + *list = g_slist_insert(*list, (gpointer)string, pos); + + return TRUE; +} + static GObject *trg_destination_combo_constructor(GType type, guint n_construct_properties, @@ -84,10 +99,10 @@ static GObject *trg_destination_combo_constructor(GType type, TrgDestinationComboPrivate *priv = TRG_DESTINATION_COMBO_GET_PRIVATE(object); - trg_client *client = priv->client; + TrgClient *client = priv->client; const gchar *defaultDownDir = - json_object_get_string_member(client->session, SGET_DOWNLOAD_DIR); + json_object_get_string_member(trg_client_get_session(client), SGET_DOWNLOAD_DIR); GtkListStore *comboModel = gtk_list_store_new(1, G_TYPE_STRING); @@ -101,10 +116,8 @@ static GObject *trg_destination_combo_constructor(GType type, GtkTreePath *path; JsonObject *t; - g_slist_str_set_add(&dirs, defaultDownDir); - - g_mutex_lock(client->updateMutex); - torrentItemRefs = g_hash_table_get_values(client->torrentTable); + 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)) { rr = (GtkTreeRowReference *) li->data; model = gtk_tree_row_reference_get_model(rr); @@ -117,29 +130,28 @@ static GObject *trg_destination_combo_constructor(GType type, 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); - + if (dd && g_strcmp0(dd, defaultDownDir)) + g_slist_str_set_add(&dirs, dd, -1); } gtk_tree_path_free(path); } } g_list_free(torrentItemRefs); - g_mutex_unlock(client->updateMutex); + g_slist_str_set_add(&dirs, defaultDownDir, 0); for (sli = dirs; sli != NULL; sli = g_slist_next(sli)) gtk_list_store_insert_with_values(comboModel, NULL, INT_MAX, 0, (gchar *) sli->data, -1); - g_str_slist_free(dirs); + 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); - /* cleanup */ g_object_unref(comboModel); return object; @@ -166,14 +178,13 @@ trg_destination_combo_class_init(TrgDestinationComboClass * klass) G_PARAM_STATIC_NAME | G_PARAM_STATIC_NICK | G_PARAM_STATIC_BLURB)); - } static void trg_destination_combo_init(TrgDestinationCombo * self) { } -GtkWidget *trg_destination_combo_new(trg_client * client) +GtkWidget *trg_destination_combo_new(TrgClient * client) { return GTK_WIDGET(g_object_new(TRG_TYPE_DESTINATION_COMBO, "trg-client", client, NULL)); |