From 551ae682b54e727c225ac980a56dd8fb427520e2 Mon Sep 17 00:00:00 2001 From: Bryan Schumaker Date: Wed, 1 Feb 2012 08:32:43 -0500 Subject: [PATCH] ocarina: Provide a UI for using ALSA You can either turn it on or off, and then you can select an output device from a dropdown list. Signed-off-by: Bryan Schumaker --- include/ocarina/settings.h | 1 + ocarina/settings/general.cpp | 67 +++++++++++++++++++++++++++++++++++ ocarina/settings/settings.cpp | 1 + 3 files changed, 69 insertions(+) create mode 100644 ocarina/settings/general.cpp diff --git a/include/ocarina/settings.h b/include/ocarina/settings.h index 11f69703..32cc4e0e 100644 --- a/include/ocarina/settings.h +++ b/include/ocarina/settings.h @@ -9,6 +9,7 @@ using namespace std; void settings_init(); void add_settings_page(string, GtkWidget *); +void general_settings_init(); void library_settings_init(); void library_settings_refresh(); diff --git a/ocarina/settings/general.cpp b/ocarina/settings/general.cpp new file mode 100644 index 00000000..3af14d58 --- /dev/null +++ b/ocarina/settings/general.cpp @@ -0,0 +1,67 @@ +// Copyright (c) 2012 Bryan Schumaker +#include +#include + +#include + +static GtkWidget *alsa_devices = NULL; +static unsigned int num_alsa_devices = 0; + +static void set_alsa_devices(bool using_alsa) +{ + list *devices; + list::iterator it; + + for (unsigned int i = 0; i < num_alsa_devices; i++) + gtk_combo_box_text_remove(GTK_COMBO_BOX_TEXT(alsa_devices), 0); + num_alsa_devices = 0; + + if (using_alsa == true) { + devices = libsaria::audio::get_alsa_devices(); + for (it = devices->begin(); it != devices->end(); it++) + gtk_combo_box_text_append_text(GTK_COMBO_BOX_TEXT(alsa_devices), it->c_str()); + num_alsa_devices = devices->size(); + } +} + +static void change_alsa_device(GtkComboBox *combo, gpointer data) +{ + string device = gtk_combo_box_text_get_active_text(GTK_COMBO_BOX_TEXT(alsa_devices)); + libsaria::audio::set_device(device); +} + +static void toggle_alsa(GtkWidget *button, gpointer data) +{ + bool active = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(button)); + libsaria::audio::use_alsa(active); + gtk_widget_set_sensitive(alsa_devices, active); + set_alsa_devices(active); +} + +static void add_alsa_settings(GtkWidget *general) +{ + bool using_alsa = libsaria::audio::using_alsa(); + GtkWidget *alsa = gtk_hbox_new(FALSE, 0); + GtkWidget *button = gtk_check_button_new_with_label("Use ALSA"); + alsa_devices = gtk_combo_box_text_new(); + + gtk_widget_set_sensitive(alsa_devices, using_alsa); + set_alsa_devices(using_alsa); + + gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(button), using_alsa); + GTK_CONNECT(button, "toggled", toggle_alsa, NULL); + GTK_CONNECT(alsa_devices, "changed", change_alsa_device, NULL); + + box_pack_start(alsa, button, FALSE, FALSE, 0); + box_pack_start(alsa, alsa_devices, TRUE, TRUE, 0); + box_pack_start(general, alsa, FALSE, FALSE, 0); +} + +void general_settings_init() +{ + GtkWidget *general_settings = gtk_vbox_new(FALSE, 0); + + add_alsa_settings(general_settings); + gtk_widget_show_all(general_settings); + add_settings_page("General", general_settings); +} diff --git a/ocarina/settings/settings.cpp b/ocarina/settings/settings.cpp index cb471718..3f57d2e1 100644 --- a/ocarina/settings/settings.cpp +++ b/ocarina/settings/settings.cpp @@ -15,6 +15,7 @@ void settings_init() gtk_widget_show(settings_tabs); add_page(image, settings_tabs, false); + general_settings_init(); library_settings_init(); }