[Xfce4-commits] <xfce4-mixer:master> Handle GST_MIXER_MESSAGE_OPTIONS_LIST_CHANGED messages in XfceMixerOption
Guido Berhoerster
noreply at xfce.org
Thu Sep 27 16:46:31 CEST 2012
Updating branch refs/heads/master
to a474e1e7809a8d07ee5458f73402698f7cd0d3b3 (commit)
from d4d898b1740c02c55b0dbc0ad7666607c1e7e0ae (commit)
commit a474e1e7809a8d07ee5458f73402698f7cd0d3b3
Author: Guido Berhoerster <guido+xfce at berhoerster.name>
Date: Thu Sep 27 16:31:09 2012 +0200
Handle GST_MIXER_MESSAGE_OPTIONS_LIST_CHANGED messages in XfceMixerOption
NEWS | 2 +
xfce4-mixer/xfce-mixer-option.c | 120 +++++++++++++++++++++++++++++++--------
2 files changed, 99 insertions(+), 23 deletions(-)
diff --git a/NEWS b/NEWS
index eedf761..0d0eb5b 100644
--- a/NEWS
+++ b/NEWS
@@ -46,6 +46,8 @@
Prevent read-only tracks from being selected in the panel-plugin.
- Handle mixer changed messages which indicate that the tracks of a mixer have
changed.
+- Handle options list changed messages which indicate that the available
+ options of a track have changed.
4.8.0
diff --git a/xfce4-mixer/xfce-mixer-option.c b/xfce4-mixer/xfce-mixer-option.c
index e965378..8ad8682 100644
--- a/xfce4-mixer/xfce-mixer-option.c
+++ b/xfce4-mixer/xfce-mixer-option.c
@@ -1,6 +1,7 @@
/* vi:set expandtab sw=2 sts=2: */
/*-
* Copyright (c) 2008 Jannis Pohlmann <jannis at xfce.org>
+ * Copyright (c) 2012 Guido Berhoerster <guido+xfce at berhoerster.name>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@@ -34,6 +35,10 @@
+#define OPTION_COLUMN 0
+
+
+
static void xfce_mixer_option_class_init (XfceMixerOptionClass *klass);
static void xfce_mixer_option_init (XfceMixerOption *option);
static void xfce_mixer_option_dispose (GObject *object);
@@ -41,6 +46,9 @@ static void xfce_mixer_option_finalize (GObject *object);
static void xfce_mixer_option_create_contents (XfceMixerOption *option);
static void xfce_mixer_option_changed (GtkComboBox *combo,
XfceMixerOption *option);
+static void xfce_mixer_option_bus_message (GstBus *bus,
+ GstMessage *message,
+ XfceMixerOption *option);
@@ -53,8 +61,11 @@ struct _XfceMixerOption
{
GtkHBox __parent__;
+ GtkListStore *list_store;
+
GstElement *card;
GstMixerTrack *track;
+ guint signal_handler_id;
GtkWidget *combo;
@@ -115,6 +126,8 @@ static void
xfce_mixer_option_init (XfceMixerOption *option)
{
option->ignore_signals = FALSE;
+
+ option->signal_handler_id = xfce_mixer_bus_connect (G_CALLBACK (xfce_mixer_option_bus_message), option);
}
@@ -130,6 +143,16 @@ xfce_mixer_option_dispose (GObject *object)
static void
xfce_mixer_option_finalize (GObject *object)
{
+ XfceMixerOption *option = XFCE_MIXER_OPTION (object);
+
+ if (option->signal_handler_id > 0)
+ {
+ xfce_mixer_bus_disconnect (option->signal_handler_id);
+ option->signal_handler_id = 0;
+ }
+
+ gtk_list_store_clear (option->list_store);
+ g_object_unref (option->list_store);
}
@@ -159,11 +182,14 @@ xfce_mixer_option_create_contents (XfceMixerOption *option)
{
GstMixerOptions *options;
GtkWidget *label;
- const GList *iter;
+ GtkCellRenderer *renderer;
+ const GList *options_iter;
+ GtkTreeIter tree_iter;
const gchar *active_option;
const gchar *track_label;
gchar *title;
gint i;
+ gint active_index = 0;
gtk_box_set_homogeneous (GTK_BOX (option), FALSE);
gtk_box_set_spacing (GTK_BOX (option), 12);
@@ -178,22 +204,29 @@ xfce_mixer_option_create_contents (XfceMixerOption *option)
options = GST_MIXER_OPTIONS (option->track);
active_option = gst_mixer_get_option (GST_MIXER (option->card), options);
- option->combo = gtk_combo_box_new_text ();
+ option->list_store = gtk_list_store_new (2, G_TYPE_STRING, GST_TYPE_MIXER_TRACK);
- for (iter = options->values, i = 0; iter != NULL; iter = g_list_next (iter), ++i)
+ for (options_iter = gst_mixer_options_get_values (options), i = 0; options_iter != NULL; options_iter = g_list_next (options_iter), ++i)
{
- gtk_combo_box_append_text (GTK_COMBO_BOX (option->combo), iter->data);
+ gtk_list_store_append (option->list_store, &tree_iter);
+ gtk_list_store_set (option->list_store, &tree_iter, OPTION_COLUMN, options_iter->data, -1);
- if (G_UNLIKELY (g_utf8_collate (active_option, iter->data) == 0))
- gtk_combo_box_set_active (GTK_COMBO_BOX (option->combo), i);
+ if (G_UNLIKELY (g_utf8_collate (active_option, options_iter->data) == 0))
+ active_index = i;
}
-
+
+ option->combo = gtk_combo_box_new_with_model (GTK_TREE_MODEL (option->list_store));
gtk_box_pack_start (GTK_BOX (option), option->combo, FALSE, FALSE, 0);
/* Make read-only options insensitive */
if (GST_MIXER_TRACK_HAS_FLAG (option->track, GST_MIXER_TRACK_READONLY))
gtk_widget_set_sensitive (option->combo, FALSE);
+ gtk_combo_box_set_active (GTK_COMBO_BOX (option->combo), active_index);
gtk_widget_show (option->combo);
+ renderer = gtk_cell_renderer_text_new ();
+ gtk_cell_layout_pack_start (GTK_CELL_LAYOUT (option->combo), renderer, TRUE);
+ gtk_cell_layout_add_attribute (GTK_CELL_LAYOUT (option->combo), renderer, "text", OPTION_COLUMN);
+
g_signal_connect (option->combo, "changed", G_CALLBACK (xfce_mixer_option_changed), option);
g_free (title);
@@ -226,37 +259,78 @@ void
xfce_mixer_option_update (XfceMixerOption *option)
{
GstMixerOptions *options;
- GtkTreeModel *model;
GtkTreeIter iter;
+ gboolean valid_iter;
const gchar *active_option;
- gchar *str;
+ gchar *current_option;
g_return_if_fail (IS_XFCE_MIXER_OPTION (option));
options = GST_MIXER_OPTIONS (option->track);
active_option = gst_mixer_get_option (GST_MIXER (option->card), options);
- model = gtk_combo_box_get_model (GTK_COMBO_BOX (option->combo));
+ valid_iter = gtk_tree_model_get_iter_first (GTK_TREE_MODEL (option->list_store), &iter);
+
+ while (valid_iter)
+ {
+ gtk_tree_model_get (GTK_TREE_MODEL (option->list_store), &iter, OPTION_COLUMN, ¤t_option, -1);
+
+ if (G_UNLIKELY (g_utf8_collate (current_option, active_option) == 0))
+ {
+ option->ignore_signals = TRUE;
+ gtk_combo_box_set_active_iter (GTK_COMBO_BOX (option->combo), &iter);
+ option->ignore_signals = FALSE;
+
+ g_free (current_option);
- if (gtk_tree_model_get_iter_first (model, &iter))
+ break;
+ }
+
+ g_free (current_option);
+
+ valid_iter = gtk_tree_model_iter_next (GTK_TREE_MODEL (option->list_store), &iter);
+ }
+}
+
+
+
+static void
+xfce_mixer_option_bus_message (GstBus *bus,
+ GstMessage *message,
+ XfceMixerOption *option)
+{
+ GstMixerOptions *options = NULL;
+ const gchar *active_option;
+ const GList *options_iter;
+ gint i;
+ GtkTreeIter tree_iter;
+
+ if (!GST_IS_MIXER (option->card) || !GST_IS_MIXER_TRACK (option->track) || GST_MESSAGE_SRC (message) != GST_OBJECT (option->card))
+ return;
+
+ /* Rebuild option list if the options have changed */
+ if (gst_mixer_message_get_type (message) == GST_MIXER_MESSAGE_OPTIONS_LIST_CHANGED)
{
- do
+ gst_mixer_message_parse_options_list_changed (message, &options);
+ if (GST_MIXER_TRACK (options) == option->track)
{
- gtk_tree_model_get (model, &iter, 0, &str, -1);
+ /*
+ * Remember the active option and try to restore it while updating
+ * the list of options
+ */
+ active_option = gst_mixer_get_option (GST_MIXER (option->card), options);
+
+ gtk_list_store_clear (option->list_store);
- if (G_UNLIKELY (g_utf8_collate (str, active_option) == 0))
+ for (options_iter = gst_mixer_options_get_values (options), i = 0; options_iter != NULL; options_iter = g_list_next (options_iter), ++i)
{
- option->ignore_signals = TRUE;
- gtk_combo_box_set_active_iter (GTK_COMBO_BOX (option->combo), &iter);
- option->ignore_signals = FALSE;
+ gtk_list_store_append (option->list_store, &tree_iter);
+ gtk_list_store_set (option->list_store, &tree_iter, OPTION_COLUMN, options_iter->data, -1);
- g_free (str);
-
- break;
+ if (G_UNLIKELY (g_utf8_collate (active_option, options_iter->data) == 0))
+ gtk_combo_box_set_active (GTK_COMBO_BOX (option->combo), i);
}
-
- g_free (str);
}
- while (gtk_tree_model_iter_next (model, &iter));
}
}
+
More information about the Xfce4-commits
mailing list