summaryrefslogtreecommitdiffstats
path: root/gtk/src/audiohandler.c
diff options
context:
space:
mode:
authorJohn Stebbins <[email protected]>2018-06-12 12:09:59 -0700
committerJohn Stebbins <[email protected]>2018-06-12 12:09:59 -0700
commit43e589346b065eae3dca53a439ef873e8a271c7a (patch)
treefe1a5f851fa9b8dd982ef5af5122f911acb056b7 /gtk/src/audiohandler.c
parent5832b176ce662dc5f1f891c9039f8fa419e1cb2c (diff)
LinGui: change language lists from GtkListBox to GtkTreeView
The GtkTreeView is more flexible and more capable. Languages can be searched for in the GtkTreeView by focusing the widget and typing what you want to find. Double clicking an item in the list will add or remove it from the "selected" languages list in audio and subtitle track selection settings.
Diffstat (limited to 'gtk/src/audiohandler.c')
-rw-r--r--gtk/src/audiohandler.c302
1 files changed, 203 insertions, 99 deletions
diff --git a/gtk/src/audiohandler.c b/gtk/src/audiohandler.c
index d4994463f..68a45ebe8 100644
--- a/gtk/src/audiohandler.c
+++ b/gtk/src/audiohandler.c
@@ -1986,70 +1986,154 @@ audio_def_setting_update(signal_user_data_t *ud, GtkWidget *widget)
}
}
+void
+audio_add_lang_iter(GtkTreeModel *tm, GtkTreeIter *iter, signal_user_data_t *ud)
+{
+ GtkTreeView * selected;
+ GtkTreeStore * selected_ts;
+ GtkTreeIter pos;
+ GtkTreePath * tp;
+ char * lang;
+ int index;
+ const iso639_lang_t * iso_lang;
+ GhbValue * glang, * alang_list;
+ GtkTreeSelection * tsel;
+
+ selected = GTK_TREE_VIEW(GHB_WIDGET(ud->builder, "audio_selected_lang"));
+ selected_ts = GTK_TREE_STORE(gtk_tree_view_get_model(selected));
+ tsel = gtk_tree_view_get_selection(selected);
+
+ // Add to UI selected language list box
+ gtk_tree_model_get(tm, iter, 0, &lang, 1, &index, -1);
+ gtk_tree_store_append(selected_ts, &pos, NULL);
+ gtk_tree_store_set(selected_ts, &pos, 0, lang, 1, index, -1);
+ g_free(lang);
+
+ // Select the item added to the selected list and make it
+ // visible in the scrolled window
+ tp = gtk_tree_model_get_path(GTK_TREE_MODEL(selected_ts), &pos);
+ gtk_tree_selection_select_iter(tsel, &pos);
+ gtk_tree_view_scroll_to_cell(selected, tp, NULL, FALSE, 0, 0);
+ gtk_tree_path_free(tp);
+
+ // Remove from UI available language list box
+ gtk_tree_store_remove(GTK_TREE_STORE(tm), iter);
+
+ // Add to preset language list
+ iso_lang = ghb_iso639_lookup_by_int(index);
+ glang = ghb_string_value_new(iso_lang->iso639_2);
+ alang_list = ghb_dict_get_value(ud->settings, "AudioLanguageList");
+ ghb_array_append(alang_list, glang);
+ ghb_clear_presets_selection(ud);
+}
+
+G_MODULE_EXPORT void
+audio_avail_lang_activated_cb(GtkTreeView *tv, GtkTreePath *tp,
+ GtkTreeViewColumn *column, signal_user_data_t *ud)
+{
+ GtkTreeIter iter;
+ GtkTreeModel * tm = gtk_tree_view_get_model(tv);
+
+ if (gtk_tree_model_get_iter(tm, &iter, tp))
+ {
+ audio_add_lang_iter(tm, &iter, ud);
+ }
+}
+
G_MODULE_EXPORT void
audio_add_lang_clicked_cb(GtkWidget *widget, signal_user_data_t *ud)
{
- GtkListBox *avail = GTK_LIST_BOX(GHB_WIDGET(ud->builder, "audio_avail_lang"));
- GtkListBox *selected = GTK_LIST_BOX(GHB_WIDGET(ud->builder, "audio_selected_lang"));
- GtkListBoxRow *row;
- GtkWidget *label;
+ GtkTreeView * avail;
+ GtkTreeModel * avail_tm;
+ GtkTreeSelection * tsel;
+ GtkTreeIter iter;
- row = gtk_list_box_get_selected_row(avail);
- if (row != NULL)
+ avail = GTK_TREE_VIEW(GHB_WIDGET(ud->builder, "audio_avail_lang"));
+ avail_tm = gtk_tree_view_get_model(avail);
+ tsel = gtk_tree_view_get_selection(avail);
+ if (gtk_tree_selection_get_selected(tsel, NULL, &iter))
{
- int idx;
- const iso639_lang_t *lang;
- GhbValue *glang, *alang_list;
+ audio_add_lang_iter(avail_tm, &iter, ud);
+ }
+}
- // Remove from UI available language list box
- label = gtk_bin_get_child(GTK_BIN(row));
- g_object_ref(G_OBJECT(label));
- gtk_widget_destroy(GTK_WIDGET(row));
- gtk_widget_show(label);
- // Add to UI selected language list box
- gtk_list_box_insert(selected, label, -1);
+void
+audio_remove_lang_iter(GtkTreeModel *tm, GtkTreeIter *iter,
+ signal_user_data_t *ud)
+{
+ GtkTreeView * avail;
+ GtkTreeStore * avail_ts;
+ GtkTreeIter pos, sibling;
+ char * lang;
+ int index;
+ GtkTreePath * tp = gtk_tree_model_get_path(tm, iter);
+ int * ind = gtk_tree_path_get_indices(tp);
+ int row = ind[0];
+ GhbValue * alang_list;
+ GtkTreeSelection * tsel;
+
+ gtk_tree_path_free(tp);
+ avail = GTK_TREE_VIEW(GHB_WIDGET(ud->builder, "audio_avail_lang"));
+ avail_ts = GTK_TREE_STORE(gtk_tree_view_get_model(avail));
+ tsel = gtk_tree_view_get_selection(avail);
- // Add to preset language list
- idx = (intptr_t)g_object_get_data(G_OBJECT(label), "lang_idx");
- lang = ghb_iso639_lookup_by_int(idx);
- glang = ghb_string_value_new(lang->iso639_2);
- alang_list = ghb_dict_get_value(ud->settings, "AudioLanguageList");
- ghb_array_append(alang_list, glang);
- ghb_clear_presets_selection(ud);
+ // Add to UI available language list box
+ gtk_tree_model_get(tm, iter, 0, &lang, 1, &index, -1);
+ if (ghb_find_lang_row(GTK_TREE_MODEL(avail_ts), &sibling, index))
+ {
+ gtk_tree_store_insert_before(avail_ts, &pos, NULL, &sibling);
}
+ else
+ {
+ gtk_tree_store_append(avail_ts, &pos, NULL);
+ }
+ gtk_tree_store_set(avail_ts, &pos, 0, lang, 1, index, -1);
+ g_free(lang);
+
+ // Select the item added to the available list and make it
+ // visible in the scrolled window
+ tp = gtk_tree_model_get_path(GTK_TREE_MODEL(avail_ts), &pos);
+ gtk_tree_selection_select_iter(tsel, &pos);
+ gtk_tree_view_scroll_to_cell(avail, tp, NULL, FALSE, 0, 0);
+ gtk_tree_path_free(tp);
+
+ // Remove from UI selected language list box
+ gtk_tree_store_remove(GTK_TREE_STORE(tm), iter);
+
+ // Remove from preset language list
+ alang_list = ghb_dict_get_value(ud->settings, "AudioLanguageList");
+ ghb_array_remove(alang_list, row);
+ ghb_clear_presets_selection(ud);
}
G_MODULE_EXPORT void
-audio_remove_lang_clicked_cb(GtkWidget *widget, signal_user_data_t *ud)
+audio_selected_lang_activated_cb(GtkTreeView *tv, GtkTreePath *tp,
+ GtkTreeViewColumn *column,
+ signal_user_data_t *ud)
{
+ GtkTreeIter iter;
+ GtkTreeModel * tm = gtk_tree_view_get_model(tv);
- GtkListBox *avail, *selected;
- GtkListBoxRow *row;
- GtkWidget *label;
-
- avail = GTK_LIST_BOX(GHB_WIDGET(ud->builder, "audio_avail_lang"));
- selected = GTK_LIST_BOX(GHB_WIDGET(ud->builder, "audio_selected_lang"));
- row = gtk_list_box_get_selected_row(selected);
- if (row != NULL)
+ if (gtk_tree_model_get_iter(tm, &iter, tp))
{
- gint index;
- GhbValue *alang_list;
-
- index = gtk_list_box_row_get_index(row);
+ audio_remove_lang_iter(tm, &iter, ud);
+ }
+}
- // Remove from UI selected language list box
- label = gtk_bin_get_child(GTK_BIN(row));
- g_object_ref(G_OBJECT(label));
- int idx = (intptr_t)g_object_get_data(G_OBJECT(label), "lang_idx");
- gtk_widget_destroy(GTK_WIDGET(row));
- gtk_widget_show(label);
- // Add to UI available language list box
- gtk_list_box_insert(avail, label, idx);
+G_MODULE_EXPORT void
+audio_remove_lang_clicked_cb(GtkWidget *widget, signal_user_data_t *ud)
+{
+ GtkTreeView * selected;
+ GtkTreeModel * selected_tm;
+ GtkTreeSelection * tsel;
+ GtkTreeIter iter;
- // Remove from preset language list
- alang_list = ghb_dict_get_value(ud->settings, "AudioLanguageList");
- ghb_array_remove(alang_list, index);
- ghb_clear_presets_selection(ud);
+ selected = GTK_TREE_VIEW(GHB_WIDGET(ud->builder, "audio_selected_lang"));
+ selected_tm = gtk_tree_view_get_model(selected);
+ tsel = gtk_tree_view_get_selection(selected);
+ if (gtk_tree_selection_get_selected(tsel, NULL, &iter))
+ {
+ audio_remove_lang_iter(selected_tm, &iter, ud);
}
}
@@ -2297,54 +2381,73 @@ audio_def_encode_setting_changed_cb(GtkWidget *widget, signal_user_data_t *ud)
ghb_clear_presets_selection(ud);
}
-GtkListBoxRow* ghb_find_lang_row(GtkListBox *list_box, int lang_idx)
+gboolean ghb_find_lang_row(GtkTreeModel *model, GtkTreeIter *iter, int lang_idx)
{
- GList *list, *link;
- GtkListBoxRow *result = NULL;
-
- list = link = gtk_container_get_children(GTK_CONTAINER(list_box));
- while (link != NULL)
+ if (gtk_tree_model_get_iter_first(model, iter))
{
- GtkListBoxRow *row = (GtkListBoxRow*)link->data;
- GtkWidget *label = gtk_bin_get_child(GTK_BIN(row));
- int idx = (intptr_t)g_object_get_data(G_OBJECT(label), "lang_idx");
- if (idx == lang_idx)
+ do
{
- result = row;
- break;
- }
- link = link->next;
- }
- g_list_free(list);
-
- return result;
-}
+ gint index;
-static void audio_def_lang_list_clear_cb(GtkWidget *row, gpointer data)
-{
- GtkListBox *avail = (GtkListBox*)data;
- GtkWidget *label = gtk_bin_get_child(GTK_BIN(row));
- g_object_ref(G_OBJECT(label));
- gtk_widget_destroy(GTK_WIDGET(row));
- gtk_widget_show(label);
- int idx = (intptr_t)g_object_get_data(G_OBJECT(label), "lang_idx");
- gtk_list_box_insert(avail, label, idx);
+ gtk_tree_model_get(model, iter, 1, &index, -1);
+ if (index >= lang_idx)
+ {
+ return TRUE;
+ }
+ } while (gtk_tree_model_iter_next(model, iter));
+ }
+ return FALSE;
}
static void
audio_def_selected_lang_list_clear(signal_user_data_t *ud)
{
- GtkListBox *avail, *selected;
- avail = GTK_LIST_BOX(GHB_WIDGET(ud->builder, "audio_avail_lang"));
- selected = GTK_LIST_BOX(GHB_WIDGET(ud->builder, "audio_selected_lang"));
- gtk_container_foreach(GTK_CONTAINER(selected),
- audio_def_lang_list_clear_cb, (gpointer)avail);
+ GtkTreeView * tv;
+ GtkTreeModel * selected_tm;
+ GtkTreeStore * avail_ts;
+ GtkTreeIter iter;
+
+ tv = GTK_TREE_VIEW(GHB_WIDGET(ud->builder, "audio_avail_lang"));
+ avail_ts = GTK_TREE_STORE(gtk_tree_view_get_model(tv));
+ tv = GTK_TREE_VIEW(GHB_WIDGET(ud->builder, "audio_selected_lang"));
+ selected_tm = gtk_tree_view_get_model(tv);
+ if (gtk_tree_model_get_iter_first(selected_tm, &iter))
+ {
+ do
+ {
+ gchar * lang;
+ gint index;
+ GtkTreeIter pos, sibling;
+
+ gtk_tree_model_get(selected_tm, &iter, 0, &lang, 1, &index, -1);
+ if (ghb_find_lang_row(GTK_TREE_MODEL(avail_ts), &sibling, index))
+ {
+ gtk_tree_store_insert_before(avail_ts, &pos, NULL, &sibling);
+ }
+ else
+ {
+ gtk_tree_store_append(avail_ts, &pos, NULL);
+ }
+ gtk_tree_store_set(avail_ts, &pos, 0, lang, 1, index, -1);
+ g_free(lang);
+ } while (gtk_tree_model_iter_next(selected_tm, &iter));
+ }
+ gtk_tree_store_clear(GTK_TREE_STORE(selected_tm));
}
static void
audio_def_lang_list_init(signal_user_data_t *ud)
{
- GhbValue *lang_list;
+ GhbValue * lang_list;
+ GtkTreeView * tv;
+ GtkTreeModel * avail;
+ GtkTreeStore * selected;
+ int ii, count;
+
+ tv = GTK_TREE_VIEW(GHB_WIDGET(ud->builder, "audio_avail_lang"));
+ avail = gtk_tree_view_get_model(tv);
+ tv = GTK_TREE_VIEW(GHB_WIDGET(ud->builder, "audio_selected_lang"));
+ selected = GTK_TREE_STORE(gtk_tree_view_get_model(tv));
// Clear selected languages.
audio_def_selected_lang_list_clear(ud);
@@ -2356,25 +2459,24 @@ audio_def_lang_list_init(signal_user_data_t *ud)
ghb_dict_set(ud->settings, "AudioLanguageList", lang_list);
}
- int ii, count;
count = ghb_array_len(lang_list);
for (ii = 0; ii < count; )
{
- GhbValue *lang_val = ghb_array_get(lang_list, ii);
- int idx = ghb_lookup_lang(lang_val);
+ GhbValue * lang_val = ghb_array_get(lang_list, ii);
+ int idx = ghb_lookup_lang(lang_val);
+ GtkTreeIter iter;
- GtkListBox *avail, *selected;
- GtkListBoxRow *row;
- avail = GTK_LIST_BOX(GHB_WIDGET(ud->builder, "audio_avail_lang"));
- selected = GTK_LIST_BOX(GHB_WIDGET(ud->builder, "audio_selected_lang"));
- row = ghb_find_lang_row(avail, idx);
- if (row)
+ if (ghb_find_lang_row(avail, &iter, idx))
{
- GtkWidget *label = gtk_bin_get_child(GTK_BIN(row));
- g_object_ref(G_OBJECT(label));
- gtk_widget_destroy(GTK_WIDGET(row));
- gtk_widget_show(label);
- gtk_list_box_insert(selected, label, -1);
+ gchar * lang;
+ gint index;
+ GtkTreeIter pos;
+
+ gtk_tree_model_get(avail, &iter, 0, &lang, 1, &index, -1);
+ gtk_tree_store_append(selected, &pos, NULL);
+ gtk_tree_store_set(selected, &pos, 0, lang, 1, index, -1);
+ g_free(lang);
+ gtk_tree_store_remove(GTK_TREE_STORE(avail), &iter);
ii++;
}
else
@@ -2427,10 +2529,12 @@ void ghb_audio_defaults_to_ui(signal_user_data_t *ud)
void ghb_init_audio_defaults_ui(signal_user_data_t *ud)
{
- GtkListBox *list_box;
+ GtkTreeView * tv;
- list_box = GTK_LIST_BOX(GHB_WIDGET(ud->builder, "audio_avail_lang"));
- ghb_init_lang_list_box(list_box);
+ tv = GTK_TREE_VIEW(GHB_WIDGET(ud->builder, "audio_avail_lang"));
+ ghb_init_lang_list(tv, ud);
+ tv = GTK_TREE_VIEW(GHB_WIDGET(ud->builder, "audio_selected_lang"));
+ ghb_init_lang_list_model(tv);
}
G_MODULE_EXPORT void