[Xfce4-commits] <xfce4-mixer:gber/improvements> Make the panel plugin use sensible default settings
Guido Berhoerster
noreply at xfce.org
Fri Sep 21 17:18:10 CEST 2012
Updating branch refs/heads/gber/improvements
to 26d23803f3b14abe109210432d808cff0b93eb5c (commit)
from b924d03fefb339aee39062bc266f347ac0bfe69c (commit)
commit 26d23803f3b14abe109210432d808cff0b93eb5c
Author: Guido Berhoerster <guido+xfce at berhoerster.name>
Date: Fri Sep 21 12:00:36 2012 +0200
Make the panel plugin use sensible default settings
Make the panel plugin use sensible default settings (first card, master track)
in the absence of an existing configuration instead of starting in an invalid
state and forcing the user to configure it (bug #5716, bug #6624, bug #7125).
NEWS | 3 ++
libxfce4mixer/libxfce4mixer.c | 52 ++++++++++++++++++++++++++++++++
libxfce4mixer/libxfce4mixer.h | 2 +
libxfce4mixer/xfce-mixer-track-combo.c | 7 ++--
panel-plugin/xfce-mixer-plugin.c | 49 +++++++++++++++++++++++++-----
5 files changed, 101 insertions(+), 12 deletions(-)
diff --git a/NEWS b/NEWS
index d63333f..5035212 100644
--- a/NEWS
+++ b/NEWS
@@ -9,6 +9,9 @@
- Update the icons on theme change (bug #3498).
- Support xfce4-panel 4.10 with its deskbar mode (bug #8350).
- Use xfconf for the panel plugin configuration.
+- Make the panel plugin use sensible default settings (first card, master
+ track) in the absence of an existing configuration (bug #5716, bug #6624,
+ bug #7125).
4.8.0
diff --git a/libxfce4mixer/libxfce4mixer.c b/libxfce4mixer/libxfce4mixer.c
index b7ad3b7..86ea5db 100644
--- a/libxfce4mixer/libxfce4mixer.c
+++ b/libxfce4mixer/libxfce4mixer.c
@@ -128,6 +128,23 @@ xfce_mixer_get_card (const gchar *name)
+GstElement *
+xfce_mixer_get_default_card (void)
+{
+ GList *cards;
+ GstElement *card = NULL;
+
+ cards = xfce_mixer_get_cards ();
+
+ /* Try to get the first card */
+ if (g_list_length (cards) > 0)
+ card = g_list_first (cards)->data;
+
+ return card;
+}
+
+
+
const gchar *
xfce_mixer_get_card_display_name (GstElement *card)
{
@@ -189,6 +206,41 @@ xfce_mixer_get_track (GstElement *card,
+GstMixerTrack *
+xfce_mixer_get_default_track (GstElement *card)
+{
+ GstMixerTrack *track = NULL;
+ const GList *iter;
+ GstMixerTrack *track_tmp;
+ const GList *tracks;
+
+ g_return_val_if_fail (GST_IS_MIXER (card), NULL);
+
+ /* Try to get the master track */
+ for (iter = gst_mixer_list_tracks (GST_MIXER (card)); iter != NULL; iter = g_list_next (iter))
+ {
+ track_tmp = GST_MIXER_TRACK (iter->data);
+
+ if (GST_MIXER_TRACK_HAS_FLAG (track_tmp, GST_MIXER_TRACK_MASTER))
+ {
+ track = track_tmp;
+ break;
+ }
+ }
+
+ /* If there is no master track, try to get the first track */
+ if (!GST_IS_MIXER_TRACK (track))
+ {
+ tracks = gst_mixer_list_tracks (GST_MIXER (card));
+ if (g_list_length (tracks) > 0)
+ track = g_list_first (tracks)->data;
+ }
+
+ return track;
+}
+
+
+
#ifdef HAVE_GST_MIXER_NOTIFICATION
guint
xfce_mixer_bus_connect (GCallback callback,
diff --git a/libxfce4mixer/libxfce4mixer.h b/libxfce4mixer/libxfce4mixer.h
index a68ff6d..93365dd 100644
--- a/libxfce4mixer/libxfce4mixer.h
+++ b/libxfce4mixer/libxfce4mixer.h
@@ -38,11 +38,13 @@ void xfce_mixer_shutdown (void);
GList *xfce_mixer_get_cards (void);
GstElement *xfce_mixer_get_card (const gchar *name);
+GstElement *xfce_mixer_get_default_card (void);
const gchar *xfce_mixer_get_card_internal_name (GstElement *card);
const gchar *xfce_mixer_get_card_display_name (GstElement *card);
void xfce_mixer_select_card (GstElement *card);
GstMixerTrack *xfce_mixer_get_track (GstElement *card,
const gchar *track_name);
+GstMixerTrack *xfce_mixer_get_default_track (GstElement *card);
#ifdef HAVE_GST_MIXER_NOTIFICATION
guint xfce_mixer_bus_connect (GCallback callback,
diff --git a/libxfce4mixer/xfce-mixer-track-combo.c b/libxfce4mixer/xfce-mixer-track-combo.c
index f99a0ef..4c19acf 100644
--- a/libxfce4mixer/xfce-mixer-track-combo.c
+++ b/libxfce4mixer/xfce-mixer-track-combo.c
@@ -192,7 +192,6 @@ xfce_mixer_track_combo_set_soundcard (XfceMixerTrackCombo *combo,
XfceMixerTrackType type;
GtkTreeIter tree_iter;
const GList *iter;
- GList *cards;
gchar *label;
gint counter;
gint active_index = 0;
@@ -205,10 +204,10 @@ xfce_mixer_track_combo_set_soundcard (XfceMixerTrackCombo *combo,
combo->card = card;
else
{
- cards = xfce_mixer_get_cards ();
+ card = xfce_mixer_get_default_card ();
- if (G_LIKELY (g_list_length (cards) > 0))
- combo->card = g_list_first (cards)->data;
+ if (GST_IS_MIXER (card))
+ combo->card = card;
}
/* Try to re-use the current track */
diff --git a/panel-plugin/xfce-mixer-plugin.c b/panel-plugin/xfce-mixer-plugin.c
index 9e57f2d..de64a92 100644
--- a/panel-plugin/xfce-mixer-plugin.c
+++ b/panel-plugin/xfce-mixer-plugin.c
@@ -233,11 +233,21 @@ xfce_mixer_plugin_construct (XfcePanelPlugin *plugin)
/* Only occupy a single row in deskbar mode */
xfce_panel_plugin_set_small (XFCE_PANEL_PLUGIN (mixer_plugin), TRUE);
- /* Set up xfconf property bindings */
+ /* Set up xfconf channel */
mixer_plugin->plugin_channel = xfconf_channel_new_with_property_base (xfce_panel_get_channel_name (), xfce_panel_plugin_get_property_base (plugin));
+
+ /* Try to set properties to defaults */
+ g_object_set (G_OBJECT (mixer_plugin), "sound-card", NULL, "command", NULL, NULL);
+
+ /* Set up xfconf property bindings */
xfconf_g_property_bind (mixer_plugin->plugin_channel, "/sound-card", G_TYPE_STRING, mixer_plugin, "sound-card");
xfconf_g_property_bind (mixer_plugin->plugin_channel, "/track", G_TYPE_STRING, mixer_plugin, "track");
xfconf_g_property_bind (mixer_plugin->plugin_channel, "/command", G_TYPE_STRING, mixer_plugin, "command");
+
+ /* Make sure the properties are in xfconf */
+ g_object_notify (G_OBJECT (mixer_plugin), "sound-card");
+ g_object_notify (G_OBJECT (mixer_plugin), "track");
+ g_object_notify (G_OBJECT (mixer_plugin), "command");
}
@@ -251,8 +261,7 @@ xfce_mixer_plugin_set_property (GObject *object,
XfceMixerPlugin *mixer_plugin = XFCE_MIXER_PLUGIN (object);
const gchar *card_name;
GstElement *card = NULL;
- const gchar *track_label;
- gchar *new_track_label;
+ gchar *track_label = NULL;
GstMixerTrack *track = NULL;
switch(prop_id)
@@ -269,6 +278,16 @@ xfce_mixer_plugin_set_property (GObject *object,
if (card_name != NULL)
card = xfce_mixer_get_card (card_name);
+ /* If the given card name is invalid resort to the default */
+ if (!GST_IS_MIXER (card))
+ {
+ card = xfce_mixer_get_default_card ();
+ if GST_IS_MIXER (card)
+ card_name = xfce_mixer_get_card_internal_name (card);
+ else
+ card_name = NULL;
+ }
+
if (GST_IS_MIXER (card))
{
mixer_plugin->card = card;
@@ -277,18 +296,18 @@ xfce_mixer_plugin_set_property (GObject *object,
#ifdef HAVE_GST_MIXER_NOTIFICATION
mixer_plugin->message_handler_id = xfce_mixer_bus_connect (G_CALLBACK (xfce_mixer_plugin_bus_message), mixer_plugin);
#endif
- new_track_label = xfconf_channel_get_string (mixer_plugin->plugin_channel, "/track", NULL);
+ track_label = xfconf_channel_get_string (mixer_plugin->plugin_channel, "/track", NULL);
}
else
{
- new_track_label = NULL;
+ track_label = NULL;
#ifdef HAVE_GST_MIXER_NOTIFICATION
xfce_mixer_bus_disconnect (mixer_plugin->message_handler_id);
#endif
}
- g_object_set (object, "track", new_track_label, NULL);
+ g_object_set (object, "track", track_label, NULL);
- g_free (new_track_label);
+ g_free (track_label);
g_object_thaw_notify (object);
break;
@@ -299,21 +318,35 @@ xfce_mixer_plugin_set_property (GObject *object,
if (GST_IS_MIXER (mixer_plugin->card))
{
- track_label = g_value_get_string (value);
+ track_label = g_value_dup_string (value);
if (track_label != NULL)
track = xfce_mixer_get_track (mixer_plugin->card, track_label);
+ /* If the given track label is invalid resort to the default */
+ if (!GST_IS_MIXER_TRACK (track))
+ {
+ g_free (track_label);
+ track = xfce_mixer_get_default_track (mixer_plugin->card);
+ if (GST_IS_MIXER_TRACK (track))
+ g_object_get (track, "label", &track_label, NULL);
+ else
+ track_label = NULL;
+ }
+
if (GST_IS_MIXER_TRACK (track))
{
mixer_plugin->track = track;
mixer_plugin->track_label = g_strdup (track_label);
}
+
+ g_free (track_label);
}
xfce_mixer_plugin_update_track (mixer_plugin);
break;
case PROP_COMMAND:
g_free (mixer_plugin->command);
+
mixer_plugin->command = g_value_dup_string (value);
if (mixer_plugin->command == NULL)
mixer_plugin->command = g_strdup (XFCE_MIXER_PLUGIN_DEFAULT_COMMAND);
More information about the Xfce4-commits
mailing list