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 <bjschuma@netapp.com>
This commit is contained in:
Bryan Schumaker 2012-02-01 08:32:43 -05:00
parent 01288e1a86
commit 551ae682b5
3 changed files with 69 additions and 0 deletions

View File

@ -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();

View File

@ -0,0 +1,67 @@
// Copyright (c) 2012 Bryan Schumaker
#include <ocarina/settings.h>
#include <ocarina/gtk.h>
#include <libsaria/audio.h>
static GtkWidget *alsa_devices = NULL;
static unsigned int num_alsa_devices = 0;
static void set_alsa_devices(bool using_alsa)
{
list<string> *devices;
list<string>::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);
}

View File

@ -15,6 +15,7 @@ void settings_init()
gtk_widget_show(settings_tabs);
add_page(image, settings_tabs, false);
general_settings_init();
library_settings_init();
}