diff --git a/libxfce4mixer/xfce-mixer-preferences.c b/libxfce4mixer/xfce-mixer-preferences.c index 04aef50..e088983 100644 --- a/libxfce4mixer/xfce-mixer-preferences.c +++ b/libxfce4mixer/xfce-mixer-preferences.c @@ -37,7 +37,8 @@ enum PROP_0, PROP_WINDOW_WIDTH, PROP_WINDOW_HEIGHT, - PROP_SOUND_CARD, + PROP_ACTIVE_CARD, + PROP_ACTIVE_TRACK, N_PROPERTIES, }; @@ -139,10 +140,18 @@ xfce_mixer_preferences_class_init (XfceMixerPreferencesClass *klass) G_PARAM_READABLE | G_PARAM_WRITABLE)); g_object_class_install_property (gobject_class, - PROP_SOUND_CARD, - g_param_spec_string ("sound-card", - "sound-card", - "sound-card", + PROP_ACTIVE_CARD, + g_param_spec_string ("active-card", + "active-card", + "active-card", + NULL, + G_PARAM_READABLE | G_PARAM_WRITABLE)); + + g_object_class_install_property (gobject_class, + PROP_ACTIVE_TRACK, + g_param_spec_string ("active-track", + "active-track", + "active-track", NULL, G_PARAM_READABLE | G_PARAM_WRITABLE)); } @@ -157,7 +166,8 @@ xfce_mixer_preferences_init (XfceMixerPreferences *preferences) xfconf_g_property_bind (preferences->channel, "/window-width", G_TYPE_INT, G_OBJECT (preferences), "window-width"); xfconf_g_property_bind (preferences->channel, "/window-height", G_TYPE_INT, G_OBJECT (preferences), "window-height"); - xfconf_g_property_bind (preferences->channel, "/sound-card", G_TYPE_STRING, G_OBJECT (preferences), "sound-card"); + xfconf_g_property_bind (preferences->channel, "/active-card", G_TYPE_STRING, G_OBJECT (preferences), "active-card"); + xfconf_g_property_bind (preferences->channel, "/active-track", G_TYPE_STRING, G_OBJECT (preferences), "active-track"); xfce_mixer_preferences_load (preferences); } diff --git a/panel-plugin/Makefile.am b/panel-plugin/Makefile.am index dcf97d6..11aeb78 100644 --- a/panel-plugin/Makefile.am +++ b/panel-plugin/Makefile.am @@ -25,6 +25,7 @@ xfce4_mixer_plugin_CFLAGS = \ $(GTK_CFLAGS) \ $(LIBXFCE4UTIL_CFLAGS) \ $(LIBXFCEGUI4_CFLAGS) \ + $(XFCONF_CFLAGS) \ $(LIBXFCE4PANEL_CFLAGS) \ $(GST_PLUGINS_BASE_CFLAGS) @@ -38,6 +39,7 @@ xfce4_mixer_plugin_LDFLAGS = \ $(GTK_LIBS) \ $(LIBXFCE4UTIL_LIBS) \ $(LIBXFCEGUI4_LIBS) \ + $(XFCONF_LIBS) \ $(LIBXFCE4PANEL_LIBS) \ $(GST_PLUGINS_BASE_LIBS) \ -lgstaudio-0.10 \ diff --git a/panel-plugin/xfce-mixer-plugin.c b/panel-plugin/xfce-mixer-plugin.c index b5a65c4..4d63dc8 100644 --- a/panel-plugin/xfce-mixer-plugin.c +++ b/panel-plugin/xfce-mixer-plugin.c @@ -34,6 +34,7 @@ #include #include #include +#include #include "libxfce4mixer/libxfce4mixer.h" @@ -58,6 +59,9 @@ struct _XfceMixerPlugin /* Tooltips structure */ GtkTooltips *tooltips; + /* Xfconf channel for card and track name */ + XfconfChannel *channel; + /* Sound card being used */ GstElement *card; @@ -104,6 +108,11 @@ static void xfce_mixer_plugin_bus_message (GstBus *b GstMessage *message, XfceMixerPlugin *mixer_plugin); #endif +static void xfce_mixer_plugin_config_changed (XfceMixerPlugin *mixer_plugin, + gchar *property, + GValue *value, + XfconfChannel *channel); + static void xfce_mixer_plugin_set_card (XfceMixerPlugin *mixer_plugin, GstElement *card); static void xfce_mixer_plugin_set_track (XfceMixerPlugin *mixer_plugin, @@ -122,6 +131,7 @@ static XfceMixerPlugin* xfce_mixer_plugin_new (XfcePanelPlugin *plugin) { XfceMixerPlugin *mixer_plugin; + GError *error = NULL; /* Allocate memory for the plugin structure */ mixer_plugin = panel_slice_new0 (XfceMixerPlugin); @@ -129,6 +139,21 @@ xfce_mixer_plugin_new (XfcePanelPlugin *plugin) /* Store pointer to the panel plugin */ mixer_plugin->plugin = plugin; + /* Initialize Xfconf */ + if (G_UNLIKELY (!xfconf_init (&error))) + { + if (G_LIKELY (error != NULL)) + { + g_print (_("Failed to initialize xfconf: %s"), error->message); + g_error_free (error); + } + + exit (EXIT_FAILURE); + } + + /* Get the Xfconf channel */ + mixer_plugin->channel = xfconf_channel_get ("xfce4-mixer"); + /* Initialize some of the plugin variables */ mixer_plugin->card = NULL; mixer_plugin->track = NULL; @@ -170,7 +195,7 @@ static void xfce_mixer_plugin_free (XfceMixerPlugin *mixer_plugin, XfcePanelPlugin *plugin) { - /* Free card and track names */ + /* Free command and track label */ g_free (mixer_plugin->command); g_free (mixer_plugin->track_label); @@ -219,6 +244,9 @@ xfce_mixer_plugin_construct (XfcePanelPlugin *plugin) /* Read config file */ xfce_mixer_plugin_read_config (mixer_plugin); + /* Connect to card and track changes */ + g_signal_connect_swapped (mixer_plugin->channel, "property-changed", G_CALLBACK (xfce_mixer_plugin_config_changed), mixer_plugin); + /* Update the plugin if it was already set up */ if (G_LIKELY (GST_IS_MIXER (mixer_plugin->card) && GST_IS_MIXER_TRACK (mixer_plugin->track))) xfce_mixer_plugin_update_track (mixer_plugin); @@ -402,19 +430,15 @@ xfce_mixer_plugin_configure (XfceMixerPlugin *mixer_plugin) else { /* Create and run the config dialog */ - dialog = xfce_plugin_dialog_new (mixer_plugin->card, mixer_plugin->track, mixer_plugin->command); + dialog = xfce_plugin_dialog_new (mixer_plugin->command); gtk_dialog_run (GTK_DIALOG (dialog)); /* Determine which card and mixer track were selected */ - xfce_plugin_dialog_get_data (XFCE_PLUGIN_DIALOG (dialog), &card, &track, &command); + xfce_plugin_dialog_get_data (XFCE_PLUGIN_DIALOG (dialog), &command); /* Check if they are valid */ - if (G_LIKELY (GST_IS_MIXER (card) && GST_IS_MIXER_TRACK (track))) + if (G_LIKELY (GST_IS_MIXER (mixer_plugin->card) && GST_IS_MIXER_TRACK (mixer_plugin->track))) { - /* Set card and track of the plugin */ - xfce_mixer_plugin_set_card (mixer_plugin, card); - xfce_mixer_plugin_set_track (mixer_plugin, track); - /* Update the volume button */ xfce_mixer_plugin_update_track (mixer_plugin); } @@ -444,8 +468,8 @@ xfce_mixer_plugin_read_config (XfceMixerPlugin *mixer_plugin) XfceRc *rc; GstElement *card; GstMixerTrack *track; - const gchar *card_name = NULL; - const gchar *track_name = NULL; + gchar *card_name = NULL; + gchar *track_name = NULL; const gchar *command = DEFAULT_COMMAND; gchar *filename; @@ -468,23 +492,36 @@ xfce_mixer_plugin_read_config (XfceMixerPlugin *mixer_plugin) if (G_LIKELY (rc != NULL)) { /* Read config values */ - card_name = xfce_rc_read_entry (rc, "card", card_name); - track_name = xfce_rc_read_entry (rc, "track", track_name); command = xfce_rc_read_entry (rc, "command", command); - /* Get card and track */ - card = xfce_mixer_get_card (card_name); - track = xfce_mixer_get_track (card, track_name); - /* Update plugin values */ - xfce_mixer_plugin_set_card (mixer_plugin, card); - xfce_mixer_plugin_set_track (mixer_plugin, track); xfce_mixer_plugin_set_command (mixer_plugin, command); /* Close rc handle */ xfce_rc_close (rc); } + /* Fetch card and track names from Xfconf */ + card_name = xfconf_channel_get_string (mixer_plugin->channel, "/active-card", NULL); + track_name = xfconf_channel_get_string (mixer_plugin->channel, "/active-track", NULL); + + /* Get card and update plugin's card */ + if (card_name) + { + card = xfce_mixer_get_card (card_name); + g_free (card_name); + xfce_mixer_plugin_set_card (mixer_plugin, card); + } + + + /* Get track and update plugin's track */ + if (track_name) + { + track = xfce_mixer_get_track (card, track_name); + g_free (track_name); + xfce_mixer_plugin_set_track (mixer_plugin, track); + } + /* Free filename string */ g_free (filename); } @@ -512,8 +549,6 @@ xfce_mixer_plugin_write_config (XfceMixerPlugin *mixer_plugin) if (G_LIKELY (rc != NULL)) { /* Write plugin values to the config file */ - xfce_rc_write_entry (rc, "card", xfce_mixer_get_card_internal_name (mixer_plugin->card)); - xfce_rc_write_entry (rc, "track", mixer_plugin->track_label); xfce_rc_write_entry (rc, "command", mixer_plugin->command); /* Close the rc handle */ @@ -633,6 +668,32 @@ xfce_mixer_plugin_bus_message (GstBus *bus, static void +xfce_mixer_plugin_config_changed (XfceMixerPlugin *mixer_plugin, + gchar *property, + GValue *value, + XfconfChannel *channel) +{ + gchar *label; + + g_return_if_fail (mixer_plugin != NULL); + + if (g_strcmp0 (property, "/active-card") == 0) + { + label = xfconf_channel_get_string (channel, "/active-card", NULL); + if (label) + xfce_mixer_plugin_set_card (mixer_plugin, xfce_mixer_get_card (label)); + } + else if (g_strcmp0 (property, "/active-track") == 0) + { + label = xfconf_channel_get_string (channel, "/active-track", NULL); + if (label) + xfce_mixer_plugin_set_track (mixer_plugin, xfce_mixer_get_track (mixer_plugin->card, label)); + } +} + + + +static void xfce_mixer_plugin_set_card (XfceMixerPlugin *mixer_plugin, GstElement *card) { diff --git a/panel-plugin/xfce-plugin-dialog.c b/panel-plugin/xfce-plugin-dialog.c index 3c7edbf..c789e1a 100644 --- a/panel-plugin/xfce-plugin-dialog.c +++ b/panel-plugin/xfce-plugin-dialog.c @@ -40,17 +40,7 @@ static void xfce_plugin_dialog_init (XfcePluginDialog *di static void xfce_plugin_dialog_dispose (GObject *object); static void xfce_plugin_dialog_finalize (GObject *object); static void xfce_plugin_dialog_create_contents (XfcePluginDialog *dialog, - GstElement *card_name, - GstMixerTrack *track_name, const gchar *command); -static void xfce_plugin_dialog_soundcard_changed (XfceMixerCardCombo *combo, - GstElement *card, - XfcePluginDialog *dialog); -static void xfce_plugin_dialog_update_tracks (XfcePluginDialog *dialog, - GstElement *card); -static void xfce_plugin_dialog_track_changed (XfceMixerTrackCombo *combo, - GstMixerTrack *track, - XfcePluginDialog *dialog); static void xfce_plugin_dialog_command_button_clicked (XfcePluginDialog *dialog); @@ -64,8 +54,6 @@ struct _XfcePluginDialog { XfceTitledDialog __parent__; - GtkWidget *card_combo; - GtkWidget *track_combo; GtkWidget *command_entry; }; @@ -146,79 +134,32 @@ xfce_plugin_dialog_finalize (GObject *object) GtkWidget* -xfce_plugin_dialog_new (GstElement *active_card, - GstMixerTrack *active_track, - const gchar *command) +xfce_plugin_dialog_new (const gchar *command) { XfcePluginDialog *dialog; dialog = XFCE_PLUGIN_DIALOG (g_object_new (TYPE_XFCE_PLUGIN_DIALOG, NULL)); - xfce_plugin_dialog_create_contents (dialog, active_card, active_track, command); + xfce_plugin_dialog_create_contents (dialog, command); return GTK_WIDGET (dialog); } -static void -xfce_plugin_dialog_soundcard_changed (XfceMixerCardCombo *combo, - GstElement *card, - XfcePluginDialog *dialog) -{ - xfce_plugin_dialog_update_tracks (dialog, card); -} - - - -static void -xfce_plugin_dialog_update_tracks (XfcePluginDialog *dialog, - GstElement *card) -{ - xfce_mixer_track_combo_set_soundcard (XFCE_MIXER_TRACK_COMBO (dialog->track_combo), card); -} - - - void xfce_plugin_dialog_get_data (XfcePluginDialog *dialog, - GstElement **card, - GstMixerTrack **track, gchar **command) { - GstElement *active_card; - GstMixerTrack *active_track; - g_return_if_fail (IS_XFCE_PLUGIN_DIALOG (dialog)); - active_card = xfce_mixer_card_combo_get_active_card (XFCE_MIXER_CARD_COMBO (dialog->card_combo)); - - if (G_LIKELY (GST_IS_MIXER (active_card))) - *card = active_card; - - active_track = xfce_mixer_track_combo_get_active_track (XFCE_MIXER_TRACK_COMBO (dialog->track_combo)); - - if (G_LIKELY (GST_IS_MIXER_TRACK (active_track))) - *track = active_track; - *command = g_strdup (gtk_entry_get_text (GTK_ENTRY (dialog->command_entry))); } -static void -xfce_plugin_dialog_track_changed (XfceMixerTrackCombo *combo, - GstMixerTrack *track, - XfcePluginDialog *dialog) -{ -} - - - static void xfce_plugin_dialog_create_contents (XfcePluginDialog *dialog, - GstElement *active_card, - GstMixerTrack *active_track, const gchar *command) { GtkWidget *alignment; @@ -226,8 +167,6 @@ xfce_plugin_dialog_create_contents (XfcePluginDialog *dialog, GtkWidget *hbox; GtkWidget *button; GtkWidget *label; - GtkWidget *card_frame; - GtkWidget *track_frame; gchar *title; gtk_window_set_icon_name (GTK_WINDOW (dialog), "multimedia-volume-control"); @@ -244,41 +183,6 @@ xfce_plugin_dialog_create_contents (XfcePluginDialog *dialog, gtk_container_add (GTK_CONTAINER (GTK_DIALOG (dialog)->vbox), vbox); gtk_widget_show (vbox); - label = gtk_label_new (NULL); - title = g_strdup_printf ("%s", _("Sound card")); - gtk_label_set_markup (GTK_LABEL (label), title); - gtk_misc_set_alignment (GTK_MISC (label), 0.0, 0.5); - gtk_box_pack_start (GTK_BOX (vbox), label, FALSE, FALSE, 0); - gtk_widget_show (label); - g_free (title); - - alignment = gtk_alignment_new (0.0, 0.0, 1, 1); - gtk_alignment_set_padding (GTK_ALIGNMENT (alignment), 0, 6, 12, 0); - gtk_box_pack_start (GTK_BOX (vbox), alignment, FALSE, TRUE, 0); - gtk_widget_show (alignment); - - dialog->card_combo = xfce_mixer_card_combo_new (active_card); - g_signal_connect (G_OBJECT (dialog->card_combo), "soundcard-changed", G_CALLBACK (xfce_plugin_dialog_soundcard_changed), dialog); - gtk_container_add (GTK_CONTAINER (alignment), dialog->card_combo); - gtk_widget_show (dialog->card_combo); - - label = gtk_label_new (NULL); - title = g_strdup_printf ("%s", _("Mixer track")); - gtk_label_set_markup (GTK_LABEL (label), title); - gtk_misc_set_alignment (GTK_MISC (label), 0.0, 0.5); - gtk_box_pack_start (GTK_BOX (vbox), label, FALSE, FALSE, 0); - gtk_widget_show (label); - g_free (title); - - alignment = gtk_alignment_new (0.0, 0.0, 1, 1); - gtk_alignment_set_padding (GTK_ALIGNMENT (alignment), 0, 6, 12, 0); - gtk_box_pack_start (GTK_BOX (vbox), alignment, FALSE, TRUE, 0); - gtk_widget_show (alignment); - - dialog->track_combo = xfce_mixer_track_combo_new (active_card, active_track); - g_signal_connect (G_OBJECT (dialog->track_combo), "track-changed", G_CALLBACK (xfce_plugin_dialog_track_changed), dialog); - gtk_container_add (GTK_CONTAINER (alignment), dialog->track_combo); - gtk_widget_show (dialog->track_combo); label = gtk_label_new (NULL); title = g_strdup_printf ("%s", _("Left-click command")); diff --git a/panel-plugin/xfce-plugin-dialog.h b/panel-plugin/xfce-plugin-dialog.h index 31b079d..24901bb 100644 --- a/panel-plugin/xfce-plugin-dialog.h +++ b/panel-plugin/xfce-plugin-dialog.h @@ -40,13 +40,9 @@ typedef struct _XfcePluginDialog XfcePluginDialog; GType xfce_plugin_dialog_get_type (void) G_GNUC_CONST; -GtkWidget *xfce_plugin_dialog_new (GstElement *active_card, - GstMixerTrack *active_track, - const gchar *command); +GtkWidget *xfce_plugin_dialog_new (const gchar *command); void xfce_plugin_dialog_get_data (XfcePluginDialog *dialog, - GstElement **card, - GstMixerTrack **track, gchar **command); G_END_DECLS; diff --git a/xfce4-mixer/xfce-mixer-window.c b/xfce4-mixer/xfce-mixer-window.c index d08505d..0bcab45 100644 --- a/xfce4-mixer/xfce-mixer-window.c +++ b/xfce4-mixer/xfce-mixer-window.c @@ -44,6 +44,9 @@ static void xfce_mixer_window_finalize (GObject * static void xfce_mixer_window_soundcard_changed (XfceMixerCardCombo *combo, GstElement *card, XfceMixerWindow *window); +static void xfce_mixer_window_maintrack_changed (XfceMixerTrackCombo *combo, + GstMixerTrack *track, + XfceMixerWindow *window); static void xfce_mixer_window_action_select_controls (GtkAction *action, XfceMixerWindow *window); static void xfce_mixer_window_close (GtkAction *action, @@ -69,6 +72,7 @@ struct _XfceMixerWindow GtkActionGroup *action_group; GtkWidget *soundcard_combo; + GtkWidget *maintrack_combo; /* Active mixer control set */ GtkWidget *mixer_frame; @@ -154,6 +158,7 @@ xfce_mixer_window_init (XfceMixerWindow *window) GtkWidget *hbox; GtkWidget *bbox; gchar *active_card = NULL; + gchar *active_track = NULL; gchar *title; gint width; gint height; @@ -161,7 +166,7 @@ xfce_mixer_window_init (XfceMixerWindow *window) window->preferences = xfce_mixer_preferences_get (); - g_object_get (window->preferences, "window-width", &width, "window-height", &height, "sound-card", &active_card, NULL); + g_object_get (window->preferences, "window-width", &width, "window-height", &height, "active-card", &active_card, "active-track", &active_track, NULL); /* Configure the main window */ gtk_window_set_icon_name (GTK_WINDOW (window), "multimedia-volume-control"); @@ -221,6 +226,24 @@ xfce_mixer_window_init (XfceMixerWindow *window) gtk_container_add (GTK_CONTAINER (hbox), window->soundcard_combo); gtk_widget_show (window->soundcard_combo); + hbox = gtk_hbox_new (FALSE, 12); + gtk_container_set_border_width (GTK_CONTAINER (hbox), 6); + gtk_box_pack_start (GTK_BOX (vbox), hbox, FALSE, TRUE, 0); + gtk_widget_show (hbox); + + label = gtk_label_new (NULL); + title = g_strdup_printf ("%s", _("Main track:")); + gtk_label_set_markup (GTK_LABEL (label), title); + g_free (title); + gtk_box_pack_start (GTK_BOX (hbox), label, FALSE, FALSE, 0); + gtk_widget_show (label); + + window->maintrack_combo = xfce_mixer_track_combo_new (xfce_mixer_get_card (active_card), + xfce_mixer_get_track (xfce_mixer_get_card (active_card), active_track)); + g_signal_connect (G_OBJECT (window->maintrack_combo), "track-changed", G_CALLBACK (xfce_mixer_window_maintrack_changed), window); + gtk_container_add (GTK_CONTAINER (hbox), window->maintrack_combo); + gtk_widget_show (window->maintrack_combo); + window->mixer_frame = gtk_frame_new (NULL); gtk_frame_set_shadow_type (GTK_FRAME (window->mixer_frame), GTK_SHADOW_NONE); gtk_container_set_border_width (GTK_CONTAINER (window->mixer_frame), 6); @@ -252,6 +275,7 @@ xfce_mixer_window_init (XfceMixerWindow *window) xfce_mixer_window_update_contents (window); g_free (active_card); + g_free (active_track); } @@ -317,8 +341,24 @@ xfce_mixer_window_soundcard_changed (XfceMixerCardCombo *combo, /* Make the "Select Controls..." button sensitive */ gtk_widget_set_sensitive (window->select_controls_button, TRUE); + /* Tell the track combo about the card change */ + xfce_mixer_track_combo_set_soundcard (XFCE_MIXER_TRACK_COMBO (window->maintrack_combo), card); + /* Remember the card for next time */ - g_object_set (G_OBJECT (window->preferences), "sound-card", xfce_mixer_get_card_internal_name (card), NULL); + g_object_set (G_OBJECT (window->preferences), "active-card", xfce_mixer_get_card_internal_name (card), NULL); +} + + + +static void xfce_mixer_window_maintrack_changed (XfceMixerTrackCombo *combo, + GstMixerTrack *track, + XfceMixerWindow *window) +{ + gchar *track_name; + + /* Remember the track for next time */ + g_object_get (G_OBJECT (track), "label", &track_name, NULL); + g_object_set (G_OBJECT (window->preferences), "active-track", track_name, NULL); }