From 83839973d9a463296b8b19a310912ef40c1ac7d8 Mon Sep 17 00:00:00 2001 From: Michal Ratajsky Date: Mon, 10 Nov 2014 00:31:00 +0100 Subject: Improve GvcComboBox and related code The combo box now includes an own reference to MateMixerSwitch. This simplifies GvcMixerDialog and makes the code more readable. This change also includes a fix for oversized profile switch label and asynchronous updates of profile names in the HW tab. --- mate-volume-control/gvc-combo-box.c | 304 ++++++++++++++++++++------------- mate-volume-control/gvc-combo-box.h | 22 +-- mate-volume-control/gvc-mixer-dialog.c | 276 +++++------------------------- 3 files changed, 239 insertions(+), 363 deletions(-) (limited to 'mate-volume-control') diff --git a/mate-volume-control/gvc-combo-box.c b/mate-volume-control/gvc-combo-box.c index b2a273f..25c4639 100644 --- a/mate-volume-control/gvc-combo-box.c +++ b/mate-volume-control/gvc-combo-box.c @@ -32,16 +32,14 @@ struct _GvcComboBoxPrivate { - GtkWidget *drop_box; - GtkWidget *start_box; - GtkWidget *end_box; - GtkWidget *label; - GtkWidget *button; - GtkTreeModel *model; - GtkWidget *combobox; - gboolean set_called; - GtkSizeGroup *size_group; - gboolean symmetric; + GtkWidget *drop_box; + GtkWidget *start_box; + GtkWidget *end_box; + GtkWidget *label; + GtkWidget *button; + GtkTreeModel *model; + GtkWidget *combobox; + MateMixerSwitch *swtch; }; enum { @@ -51,7 +49,7 @@ enum { }; enum { - CHANGED, + CHANGING, BUTTON_CLICKED, LAST_SIGNAL }; @@ -60,6 +58,7 @@ static guint signals[LAST_SIGNAL] = { 0, }; enum { PROP_0, + PROP_SWITCH, PROP_LABEL, PROP_SHOW_BUTTON, PROP_BUTTON_LABEL, @@ -78,6 +77,14 @@ G_DEFINE_TYPE (GvcComboBox, gvc_combo_box, GTK_TYPE_BOX) G_DEFINE_TYPE (GvcComboBox, gvc_combo_box, GTK_TYPE_HBOX) #endif +MateMixerSwitch * +gvc_combo_box_get_switch (GvcComboBox *combobox) +{ + g_return_val_if_fail (GVC_IS_COMBO_BOX (combobox), NULL); + + return combobox->priv->swtch; +} + void gvc_combo_box_set_size_group (GvcComboBox *combobox, GtkSizeGroup *group, @@ -86,18 +93,89 @@ gvc_combo_box_set_size_group (GvcComboBox *combobox, g_return_if_fail (GVC_IS_COMBO_BOX (combobox)); g_return_if_fail (GTK_IS_SIZE_GROUP (group)); - combobox->priv->size_group = group; - combobox->priv->symmetric = symmetric; + if (group != NULL) { + gtk_size_group_add_widget (group, combobox->priv->start_box); + if (symmetric == TRUE) + gtk_size_group_add_widget (group, combobox->priv->end_box); + } + gtk_widget_queue_draw (GTK_WIDGET (combobox)); +} - if (combobox->priv->size_group != NULL) { - gtk_size_group_add_widget (combobox->priv->size_group, - combobox->priv->start_box); +static void +on_switch_active_option_notify (MateMixerSwitch *swtch, + GParamSpec *pspec, + GvcComboBox *combobox) +{ + GtkTreeIter iter; + MateMixerSwitchOption *active; + gboolean cont; + const gchar *name; + + active = mate_mixer_switch_get_active_option (swtch); + if G_UNLIKELY (active == NULL) { + g_warn_if_reached (); + return; + } + + /* Select the newly activated switch option in the combo box */ + name = mate_mixer_switch_option_get_name (active); + cont = gtk_tree_model_get_iter_first (combobox->priv->model, &iter); + while (cont == TRUE) { + gchar *current; - if (combobox->priv->symmetric) - gtk_size_group_add_widget (combobox->priv->size_group, - combobox->priv->end_box); + gtk_tree_model_get (combobox->priv->model, &iter, + COL_NAME, ¤t, + -1); + if (g_strcmp0 (name, current) == 0) { + gtk_combo_box_set_active_iter (GTK_COMBO_BOX (combobox->priv->combobox), &iter); + g_free (current); + return; + } + g_free (current); + + cont = gtk_tree_model_iter_next (combobox->priv->model, &iter); } - gtk_widget_queue_draw (GTK_WIDGET (combobox)); + g_warning ("Could not find switch option '%s' in combo box", name); +} + +static void +gvc_combo_box_set_switch (GvcComboBox *combobox, MateMixerSwitch *swtch) +{ + MateMixerSwitchOption *active; + const GList *options; + + g_return_if_fail (GVC_IS_COMBO_BOX (combobox)); + g_return_if_fail (MATE_MIXER_IS_SWITCH (swtch)); + + combobox->priv->swtch = g_object_ref (swtch); + + active = mate_mixer_switch_get_active_option (swtch); + options = mate_mixer_switch_list_options (swtch); + while (options != NULL) { + GtkTreeIter iter; + MateMixerSwitchOption *option = MATE_MIXER_SWITCH_OPTION (options->data); + + gtk_list_store_insert_with_values (GTK_LIST_STORE (combobox->priv->model), + &iter, + G_MAXINT, + COL_NAME, + mate_mixer_switch_option_get_name (option), + COL_HUMAN_NAME, + mate_mixer_switch_option_get_label (option), + -1); + + /* Select the currently active option of the switch */ + if (option == active) { + gtk_combo_box_set_active_iter (GTK_COMBO_BOX (combobox->priv->combobox), + &iter); + } + options = options->next; + } + + g_signal_connect (G_OBJECT (swtch), + "notify::active-option", + G_CALLBACK (on_switch_active_option_notify), + combobox); } static void @@ -109,6 +187,9 @@ gvc_combo_box_set_property (GObject *object, GvcComboBox *self = GVC_COMBO_BOX (object); switch (prop_id) { + case PROP_SWITCH: + gvc_combo_box_set_switch (self, g_value_get_object (value)); + break; case PROP_LABEL: gtk_label_set_text_with_mnemonic (GTK_LABEL (self->priv->label), g_value_get_string (value)); break; @@ -133,6 +214,9 @@ gvc_combo_box_get_property (GObject *object, GvcComboBox *self = GVC_COMBO_BOX (object); switch (prop_id) { + case PROP_SWITCH: + g_value_set_object (value, self->priv->swtch); + break; case PROP_LABEL: g_value_set_string (value, gtk_label_get_text (GTK_LABEL (self->priv->label))); break; @@ -157,37 +241,54 @@ gvc_combo_box_class_init (GvcComboBoxClass *klass) object_class->set_property = gvc_combo_box_set_property; object_class->get_property = gvc_combo_box_get_property; + properties[PROP_SWITCH] = + g_param_spec_object ("switch", + "switch", + "The MateMixerSwitch", + MATE_MIXER_TYPE_SWITCH, + G_PARAM_READWRITE | + G_PARAM_CONSTRUCT_ONLY | + G_PARAM_STATIC_STRINGS); + properties[PROP_LABEL] = g_param_spec_string ("label", "label", "The combo box label", _("_Profile:"), - G_PARAM_READWRITE | G_PARAM_CONSTRUCT); + G_PARAM_READWRITE | + G_PARAM_CONSTRUCT | + G_PARAM_STATIC_STRINGS); properties[PROP_SHOW_BUTTON] = g_param_spec_boolean ("show-button", "show-button", "Whether to show the button", FALSE, - G_PARAM_READWRITE | G_PARAM_CONSTRUCT); + G_PARAM_READWRITE | + G_PARAM_CONSTRUCT | + G_PARAM_STATIC_STRINGS); properties[PROP_BUTTON_LABEL] = g_param_spec_string ("button-label", "button-label", "The button's label", "", - G_PARAM_READWRITE | G_PARAM_CONSTRUCT); + G_PARAM_READWRITE | + G_PARAM_CONSTRUCT | + G_PARAM_STATIC_STRINGS); g_object_class_install_properties (object_class, N_PROPERTIES, properties); - signals[CHANGED] = - g_signal_new ("changed", + signals[CHANGING] = + g_signal_new ("changing", G_TYPE_FROM_CLASS (klass), G_SIGNAL_RUN_LAST, - G_STRUCT_OFFSET (GvcComboBoxClass, changed), + G_STRUCT_OFFSET (GvcComboBoxClass, changing), NULL, NULL, - g_cclosure_marshal_VOID__STRING, - G_TYPE_NONE, 1, G_TYPE_STRING); + g_cclosure_marshal_VOID__VOID, + G_TYPE_NONE, + 1, + MATE_MIXER_TYPE_SWITCH_OPTION); signals[BUTTON_CLICKED] = g_signal_new ("button-clicked", @@ -196,84 +297,46 @@ gvc_combo_box_class_init (GvcComboBoxClass *klass) G_STRUCT_OFFSET (GvcComboBoxClass, button_clicked), NULL, NULL, g_cclosure_marshal_VOID__VOID, - G_TYPE_NONE, 0, G_TYPE_NONE); + G_TYPE_NONE, + 0, + G_TYPE_NONE); g_type_class_add_private (klass, sizeof (GvcComboBoxPrivate)); } -void -gvc_combo_box_set_options (GvcComboBox *combobox, const GList *options) -{ - const GList *l; - - g_return_if_fail (GVC_IS_COMBO_BOX (combobox)); - g_return_if_fail (combobox->priv->set_called == FALSE); - - for (l = options; l != NULL; l = l->next) { - MateMixerSwitchOption *option = MATE_MIXER_SWITCH_OPTION (l->data); - - gtk_list_store_insert_with_values (GTK_LIST_STORE (combobox->priv->model), - NULL, - G_MAXINT, - COL_NAME, - mate_mixer_switch_option_get_name (option), - COL_HUMAN_NAME, - mate_mixer_switch_option_get_label (option), - -1); - } - combobox->priv->set_called = TRUE; -} - -void -gvc_combo_box_set_active (GvcComboBox *combobox, const gchar *id) -{ - GtkTreeIter iter; - gboolean cont; - - g_return_if_fail (GVC_IS_COMBO_BOX (combobox)); - g_return_if_fail (id != NULL); - - cont = gtk_tree_model_get_iter_first (combobox->priv->model, &iter); - while (cont != FALSE) { - gchar *name; - - gtk_tree_model_get (combobox->priv->model, &iter, - COL_NAME, &name, - -1); - if (g_strcmp0 (name, id) == 0) { - gtk_combo_box_set_active_iter (GTK_COMBO_BOX (combobox->priv->combobox), &iter); - g_free (name); - return; - } - g_free (name); - - gtk_tree_model_iter_next (combobox->priv->model, &iter); - } - g_warning ("Could not find id '%s' in combo box", id); -} - static void on_combo_box_changed (GtkComboBox *widget, GvcComboBox *combobox) { - GtkTreeIter iter; - gchar *profile; + GtkTreeIter iter; + gchar *name; + MateMixerSwitchOption *option; - if (gtk_combo_box_get_active_iter (GTK_COMBO_BOX (widget), &iter) == FALSE) { - g_warning ("Could not find an active profile or port"); + if G_UNLIKELY (gtk_combo_box_get_active_iter (GTK_COMBO_BOX (widget), &iter) == FALSE) return; - } gtk_tree_model_get (combobox->priv->model, &iter, - COL_NAME, &profile, + COL_NAME, &name, -1); - g_signal_emit (combobox, signals[CHANGED], 0, profile); - g_free (profile); + option = mate_mixer_switch_get_option (combobox->priv->swtch, name); + if G_UNLIKELY (option == NULL) { + g_warn_if_reached (); + g_free (name); + return; + } + + /* Inform that we are about to change the active option of the switch */ + g_signal_emit (combobox, signals[CHANGING], 0, option); + + mate_mixer_switch_set_active_option (combobox->priv->swtch, option); + g_free (name); } static void on_combo_box_button_clicked (GtkButton *button, GvcComboBox *combobox) { + /* The meaning of the button is defined by the owner, so only notify + * when it is clicked on */ g_signal_emit (combobox, signals[BUTTON_CLICKED], 0); } @@ -283,30 +346,21 @@ gvc_combo_box_init (GvcComboBox *combobox) GtkWidget *frame; GtkCellRenderer *renderer; + frame = gtk_frame_new (NULL); + gtk_frame_set_shadow_type (GTK_FRAME (frame), GTK_SHADOW_NONE); + combobox->priv = GVC_COMBO_BOX_GET_PRIVATE (combobox); combobox->priv->model = GTK_TREE_MODEL (gtk_list_store_new (NUM_COLS, G_TYPE_STRING, G_TYPE_STRING)); - combobox->priv->label = gtk_label_new (NULL); - - gtk_misc_set_alignment (GTK_MISC (combobox->priv->label), 0.0, 0.5); - /* Frame */ - frame = gtk_frame_new (NULL); - gtk_frame_set_shadow_type (GTK_FRAME (frame), GTK_SHADOW_NONE); - gtk_box_pack_start (GTK_BOX (combobox), frame, TRUE, TRUE, 0); + combobox->priv->combobox = gtk_combo_box_new_with_model (combobox->priv->model); -#if GTK_CHECK_VERSION (3, 0, 0) - combobox->priv->drop_box = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 6); - combobox->priv->start_box = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 6); - combobox->priv->end_box = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 6); -#else - combobox->priv->drop_box = gtk_hbox_new (FALSE, 6); - combobox->priv->start_box = gtk_hbox_new (FALSE, 6); - combobox->priv->end_box = gtk_hbox_new (FALSE, 6); -#endif - combobox->priv->combobox = gtk_combo_box_new_with_model (combobox->priv->model); + combobox->priv->label = gtk_label_new (NULL); + gtk_misc_set_alignment (GTK_MISC (combobox->priv->label), 0.0, 0.5); + gtk_label_set_mnemonic_widget (GTK_LABEL (combobox->priv->label), + combobox->priv->combobox); renderer = gtk_cell_renderer_text_new (); gtk_cell_layout_pack_start (GTK_CELL_LAYOUT (combobox->priv->combobox), @@ -318,6 +372,10 @@ gvc_combo_box_init (GvcComboBox *combobox) COL_HUMAN_NAME); #if GTK_CHECK_VERSION (3, 0, 0) + combobox->priv->drop_box = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 6); + combobox->priv->start_box = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 6); + combobox->priv->end_box = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 6); + /* Make sure the combo box does not get too long on long profile names */ g_object_set (G_OBJECT (renderer), "ellipsize", @@ -325,8 +383,16 @@ gvc_combo_box_init (GvcComboBox *combobox) NULL); gtk_combo_box_set_popup_fixed_width (GTK_COMBO_BOX (combobox->priv->combobox), FALSE); +#else + combobox->priv->drop_box = gtk_hbox_new (FALSE, 6); + combobox->priv->start_box = gtk_hbox_new (FALSE, 6); + combobox->priv->end_box = gtk_hbox_new (FALSE, 6); #endif + gtk_box_pack_start (GTK_BOX (combobox), + frame, + TRUE, TRUE, 0); + gtk_box_pack_start (GTK_BOX (combobox->priv->drop_box), combobox->priv->start_box, FALSE, FALSE, 0); @@ -346,22 +412,7 @@ gvc_combo_box_init (GvcComboBox *combobox) combobox->priv->end_box, FALSE, FALSE, 0); - gtk_widget_set_no_show_all (combobox->priv->button, TRUE); - - if (combobox->priv->size_group != NULL) { - gtk_size_group_add_widget (combobox->priv->size_group, - combobox->priv->start_box); - - if (combobox->priv->symmetric) - gtk_size_group_add_widget (combobox->priv->size_group, - combobox->priv->end_box); - } - - gtk_label_set_mnemonic_widget (GTK_LABEL (combobox->priv->label), - combobox->priv->combobox); - gtk_container_add (GTK_CONTAINER (frame), combobox->priv->drop_box); - gtk_widget_show_all (frame); g_signal_connect (G_OBJECT (combobox->priv->combobox), "changed", @@ -371,6 +422,9 @@ gvc_combo_box_init (GvcComboBox *combobox) "clicked", G_CALLBACK (on_combo_box_button_clicked), combobox); + + gtk_widget_set_no_show_all (combobox->priv->button, TRUE); + gtk_widget_show_all (frame); } static void @@ -380,15 +434,23 @@ gvc_combo_box_dispose (GObject *object) combobox = GVC_COMBO_BOX (object); + if G_LIKELY (combobox->priv->swtch != NULL) { + g_signal_handlers_disconnect_by_func (G_OBJECT (combobox->priv->swtch), + G_CALLBACK (on_switch_active_option_notify), + combobox); + g_clear_object (&combobox->priv->swtch); + } + g_clear_object (&combobox->priv->model); G_OBJECT_CLASS (gvc_combo_box_parent_class)->dispose (object); } GtkWidget * -gvc_combo_box_new (const gchar *label) +gvc_combo_box_new (MateMixerSwitch *swtch, const gchar *label) { return g_object_new (GVC_TYPE_COMBO_BOX, + "switch", swtch, "label", label, #if GTK_CHECK_VERSION (3, 0, 0) "orientation", GTK_ORIENTATION_HORIZONTAL, diff --git a/mate-volume-control/gvc-combo-box.h b/mate-volume-control/gvc-combo-box.h index 9a2f425..0767704 100644 --- a/mate-volume-control/gvc-combo-box.h +++ b/mate-volume-control/gvc-combo-box.h @@ -26,6 +26,8 @@ #include #include +#include + G_BEGIN_DECLS #define GVC_TYPE_COMBO_BOX (gvc_combo_box_get_type ()) @@ -56,23 +58,21 @@ struct _GvcComboBoxClass #else GtkHBoxClass parent_class; #endif - void (* changed) (GvcComboBox *combobox, - const gchar *name); - void (* button_clicked) (GvcComboBox *combobox); + void (* changing) (GvcComboBox *combobox, + MateMixerSwitchOption *option); + void (* button_clicked) (GvcComboBox *combobox); }; GType gvc_combo_box_get_type (void) G_GNUC_CONST; -GtkWidget * gvc_combo_box_new (const gchar *label); +GtkWidget * gvc_combo_box_new (MateMixerSwitch *swtch, + const gchar *label); -void gvc_combo_box_set_size_group (GvcComboBox *combobox, - GtkSizeGroup *group, - gboolean symmetric); +MateMixerSwitch * gvc_combo_box_get_switch (GvcComboBox *combobox); -void gvc_combo_box_set_options (GvcComboBox *combobox, - const GList *options); -void gvc_combo_box_set_active (GvcComboBox *combobox, - const gchar *id); +void gvc_combo_box_set_size_group (GvcComboBox *combobox, + GtkSizeGroup *group, + gboolean symmetric); G_END_DECLS diff --git a/mate-volume-control/gvc-mixer-dialog.c b/mate-volume-control/gvc-mixer-dialog.c index 938c57a..92a72a7 100644 --- a/mate-volume-control/gvc-mixer-dialog.c +++ b/mate-volume-control/gvc-mixer-dialog.c @@ -250,70 +250,6 @@ update_default_tree_item (GvcMixerDialog *dialog, } while (gtk_tree_model_iter_next (model, &iter)); } -static void -on_combobox_option_changed (GvcComboBox *combo, - const gchar *name, - GvcMixerDialog *dialog) -{ - MateMixerSwitch *swtch; - MateMixerSwitchOption *option; - const GList *options; - - swtch = g_object_get_data (G_OBJECT (combo), "switch"); - if (G_UNLIKELY (swtch == NULL)) { - g_warn_if_reached (); - return; - } - - options = mate_mixer_switch_list_options (swtch); - while (options != NULL) { - option = MATE_MIXER_SWITCH_OPTION (options->data); - - if (g_strcmp0 (mate_mixer_switch_option_get_name (option), name) == 0) - break; - - option = NULL; - options = options->next; - } - - if (G_UNLIKELY (option == NULL)) { - g_warn_if_reached (); - return; - } - - mate_mixer_switch_set_active_option (swtch, option); -} - -static GtkWidget * -create_port_combo_box (GvcMixerDialog *dialog, - MateMixerSwitch *swtch, - const gchar *name, - const GList *items, - const gchar *active) -{ - GtkWidget *combobox; - - combobox = gvc_combo_box_new (name); - - gvc_combo_box_set_options (GVC_COMBO_BOX (combobox), items); - gvc_combo_box_set_active (GVC_COMBO_BOX (combobox), active); - - gvc_combo_box_set_size_group (GVC_COMBO_BOX (combobox), - dialog->priv->size_group, - FALSE); - - g_object_set_data_full (G_OBJECT (combobox), - "switch", - g_object_ref (swtch), - g_object_unref); - - g_signal_connect (G_OBJECT (combobox), - "changed", - G_CALLBACK (on_combobox_option_changed), - dialog); - return combobox; -} - static void update_output_settings (GvcMixerDialog *dialog) { @@ -418,21 +354,12 @@ update_output_settings (GvcMixerDialog *dialog) /* Enable the port selector if the stream has one */ port_switch = find_stream_port_switch (stream); if (port_switch != NULL) { - const GList *options; - const gchar *active_name = NULL; - MateMixerSwitchOption *active; - - options = mate_mixer_switch_list_options (port_switch); - active = mate_mixer_switch_get_active_option (port_switch); - if (active != NULL) - active_name = mate_mixer_switch_option_get_name (active); - dialog->priv->output_port_combo = - create_port_combo_box (dialog, - port_switch, - _("Co_nnector:"), - options, - active_name); + gvc_combo_box_new (port_switch, _("Co_nnector:")); + + gvc_combo_box_set_size_group (GVC_COMBO_BOX (dialog->priv->output_port_combo), + dialog->priv->size_group, + FALSE); gtk_box_pack_start (GTK_BOX (dialog->priv->output_settings_box), dialog->priv->output_port_combo, @@ -576,21 +503,12 @@ update_input_settings (GvcMixerDialog *dialog) /* Enable the port selector if the stream has one */ port_switch = find_stream_port_switch (stream); if (port_switch != NULL) { - const GList *options; - const gchar *active_name = NULL; - MateMixerSwitchOption *active; - - options = mate_mixer_switch_list_options (port_switch); - active = mate_mixer_switch_get_active_option (port_switch); - if (active != NULL) - active_name = mate_mixer_switch_option_get_name (active); - dialog->priv->input_port_combo = - create_port_combo_box (dialog, - port_switch, - _("Co_nnector:"), - options, - active_name); + gvc_combo_box_new (port_switch, _("Co_nnector:")); + + gvc_combo_box_set_size_group (GVC_COMBO_BOX (dialog->priv->input_port_combo), + dialog->priv->size_group, + FALSE); gtk_box_pack_start (GTK_BOX (dialog->priv->input_settings_box), dialog->priv->input_port_combo, @@ -700,55 +618,6 @@ on_context_default_input_stream_notify (MateMixerContext *context, set_input_stream (dialog, stream); } -static GvcComboBox * -find_combo_box_by_switch (GvcMixerDialog *dialog, MateMixerSwitch *swtch) -{ - MateMixerSwitch *combo_switch; - - if (dialog->priv->output_port_combo != NULL) { - combo_switch = g_object_get_data (G_OBJECT (dialog->priv->output_port_combo), - "switch"); - if (combo_switch == swtch) - return GVC_COMBO_BOX (dialog->priv->output_port_combo); - } - - if (dialog->priv->input_port_combo != NULL) { - combo_switch = g_object_get_data (G_OBJECT (dialog->priv->input_port_combo), - "switch"); - if (combo_switch == swtch) - return GVC_COMBO_BOX (dialog->priv->input_port_combo); - } - return NULL; -} - -static void -on_switch_option_notify (MateMixerSwitch *swtch, - GParamSpec *pspec, - GvcMixerDialog *dialog) -{ - GvcComboBox *combobox; - MateMixerSwitchOption *port; - - combobox = find_combo_box_by_switch (dialog, swtch); - if (G_UNLIKELY (combobox == NULL)) { - g_warn_if_reached (); - return; - } - - g_signal_handlers_block_by_func (G_OBJECT (combobox), - on_combobox_option_changed, - dialog); - - port = mate_mixer_switch_get_active_option (swtch); - if (G_LIKELY (port != NULL)) - gvc_combo_box_set_active (GVC_COMBO_BOX (combobox), - mate_mixer_switch_option_get_name (port)); - - g_signal_handlers_unblock_by_func (G_OBJECT (combobox), - on_combobox_option_changed, - dialog); -} - static GtkWidget * create_bar (GvcMixerDialog *dialog, gboolean use_size_group, gboolean symmetric) { @@ -777,19 +646,9 @@ bar_set_stream (GvcMixerDialog *dialog, { MateMixerStreamControl *control = NULL; - if (stream != NULL) { - MateMixerSwitch *port_switch; - + if (stream != NULL) control = mate_mixer_stream_get_default_control (stream); - port_switch = find_stream_port_switch (stream); - if (port_switch != NULL) - g_signal_connect (G_OBJECT (port_switch), - "notify::active-option", - G_CALLBACK (on_switch_option_notify), - dialog); - } - bar_set_stream_control (dialog, bar, control); } @@ -1365,30 +1224,15 @@ update_device_info (GvcMixerDialog *dialog, MateMixerDevice *device) } static void -on_device_profile_notify (MateMixerSwitch *swtch, - GParamSpec *pspec, - GvcMixerDialog *dialog) +on_device_profile_active_option_notify (MateMixerDeviceSwitch *swtch, + GParamSpec *pspec, + GvcMixerDialog *dialog) { - MateMixerSwitchOption *active; - - g_signal_handlers_block_by_func (G_OBJECT (dialog->priv->hw_profile_combo), - G_CALLBACK (on_combobox_option_changed), - dialog); - - active = mate_mixer_switch_get_active_option (swtch); - if (G_LIKELY (active != NULL)) { - const gchar *name = mate_mixer_switch_option_get_name (active); - - gvc_combo_box_set_active (GVC_COMBO_BOX (dialog->priv->hw_profile_combo), - name); - } + MateMixerDevice *device; - g_signal_handlers_unblock_by_func (G_OBJECT (dialog->priv->hw_profile_combo), - G_CALLBACK (on_combobox_option_changed), - dialog); + device = mate_mixer_device_switch_get_device (swtch); - // XXX find device - // update_device_info (dialog, device); + update_device_info (dialog, device); } static void @@ -1424,9 +1268,9 @@ add_device (GvcMixerDialog *dialog, MateMixerDevice *device) if (G_LIKELY (active != NULL)) profile_label = mate_mixer_switch_option_get_label (active); - g_signal_connect (G_OBJECT (device), + g_signal_connect (G_OBJECT (profile_switch), "notify::active-option", - G_CALLBACK (on_device_profile_notify), + G_CALLBACK (on_device_profile_active_option_notify), dialog); } @@ -1702,6 +1546,15 @@ create_stream_treeview (GvcMixerDialog *dialog, GCallback on_toggled) return treeview; } +static void +on_device_profile_changing (GvcComboBox *combobox, + MateMixerSwitchOption *option, + GvcMixerDialog *dialog) +{ + g_debug ("Changing device profile"); + // TODO +} + static void on_test_speakers_clicked (GvcComboBox *widget, GvcMixerDialog *dialog) { @@ -1748,46 +1601,6 @@ on_test_speakers_clicked (GvcComboBox *widget, GvcMixerDialog *dialog) gtk_widget_destroy (d); } -static GtkWidget * -create_profile_combo_box (GvcMixerDialog *dialog, - MateMixerSwitch *swtch, - const gchar *name, - const GList *items, - const gchar *active) -{ - GtkWidget *combobox; - - combobox = gvc_combo_box_new (name); - - gvc_combo_box_set_options (GVC_COMBO_BOX (combobox), items); - gvc_combo_box_set_active (GVC_COMBO_BOX (combobox), active); - - gvc_combo_box_set_size_group (GVC_COMBO_BOX (combobox), - dialog->priv->size_group, - FALSE); - - g_object_set (G_OBJECT (combobox), - "button-label", _("Test Speakers"), - NULL); - - g_object_set_data_full (G_OBJECT (combobox), - "switch", - g_object_ref (swtch), - g_object_unref); - - g_signal_connect (G_OBJECT (combobox), - "changed", - G_CALLBACK (on_combobox_option_changed), - dialog); - - g_signal_connect (G_OBJECT (combobox), - "button-clicked", - G_CALLBACK (on_test_speakers_clicked), - dialog); - - return combobox; -} - static void on_device_selection_changed (GtkTreeSelection *selection, GvcMixerDialog *dialog) { @@ -1824,26 +1637,27 @@ on_device_selection_changed (GtkTreeSelection *selection, GvcMixerDialog *dialog /* Profile/speaker test combo */ profile_switch = find_device_profile_switch (device); if (profile_switch != NULL) { - const GList *options; - const gchar *active_name = NULL; - MateMixerSwitchOption *active; + dialog->priv->hw_profile_combo = + gvc_combo_box_new (profile_switch, _("_Profile:")); - options = mate_mixer_switch_list_options (profile_switch); - active = mate_mixer_switch_get_active_option (profile_switch); - if (active != NULL) - active_name = mate_mixer_switch_option_get_name (active); + g_object_set (G_OBJECT (dialog->priv->hw_profile_combo), + "button-label", _("Test Speakers"), + NULL); - dialog->priv->hw_profile_combo = - create_profile_combo_box (dialog, - profile_switch, - _("_Profile:"), - options, - active_name); + g_signal_connect (G_OBJECT (dialog->priv->hw_profile_combo), + "changing", + G_CALLBACK (on_device_profile_changing), + dialog); + + g_signal_connect (G_OBJECT (dialog->priv->hw_profile_combo), + "button-clicked", + G_CALLBACK (on_test_speakers_clicked), + dialog); g_object_set_data_full (G_OBJECT (dialog->priv->hw_profile_combo), - "device", - g_object_ref (device), - g_object_unref); + "device", + g_object_ref (device), + g_object_unref); gtk_box_pack_start (GTK_BOX (dialog->priv->hw_settings_box), dialog->priv->hw_profile_combo, -- cgit v1.2.1