[Xfce4-commits] [apps/xfce4-volumed-pulse] 02/62: 0.1.3 release

noreply at xfce.org noreply at xfce.org
Thu Sep 8 10:32:24 CEST 2016


This is an automated email from the git hooks/post-receive script.

ochosi pushed a commit to branch master
in repository apps/xfce4-volumed-pulse.

commit 67075a321368eef8a7ccf943e1575bd5fb44dcbf
Author: Steve Dodier <sidnioulz at gmail.com>
Date:   Thu Sep 3 12:11:36 2009 +0200

    0.1.3 release
---
 AUTHORS              |   7 +-
 ChangeLog            |   4 +
 src/main.c           |  30 ++++----
 src/xvd_data_types.h |   4 +
 src/xvd_keys.c       |  44 ++++++-----
 src/xvd_mixer.c      | 213 ++++++++++++++++++++++++++++++++-------------------
 src/xvd_mixer.h      |  13 ++--
 src/xvd_notify.c     |  31 +++++---
 src/xvd_xfconf.c     | 184 +++++++++++++++++++++++++++++++++-----------
 src/xvd_xfconf.h     |  19 +++--
 10 files changed, 371 insertions(+), 178 deletions(-)

diff --git a/AUTHORS b/AUTHORS
index b419229..a312018 100644
--- a/AUTHORS
+++ b/AUTHORS
@@ -1 +1,6 @@
-Steve Dodier <sidnioulz at gmail.com>
+=== Authors
+	Steve Dodier <sidnioulz at gmail.com>
+
+=== Contributions
+ * xvd_mixer.c
+ 	Jannis Pohlmann <jannis at xfce.org>
diff --git a/ChangeLog b/ChangeLog
index 3f24215..501e7d4 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,7 @@
+2009-09-03  Steve Dodier <sidnioulz at gmail.com>
+
+	* Reworking the whole xfconf / mixer code to make it more solid
+
 2009-08-23  Steve Dodier <sidnioulz at gmail.com>
 
 	* Making sure that nothing wrong is done if the card exists but is trackless
diff --git a/src/main.c b/src/main.c
index 0b73438..5b47911 100644
--- a/src/main.c
+++ b/src/main.c
@@ -80,6 +80,8 @@ xvd_shutdown()
 	xvd_clean_track (Inst);
 	xvd_keys_release (Inst);
 	xvd_xfconf_shutdown (Inst);
+	
+	//TODO xvd_instance_free
 }
 
 static void 
@@ -88,10 +90,14 @@ xvd_instance_init(XvdInstance *i)
 	i->mixers = NULL;
 	i->card = NULL;
 	i->card_name = NULL;
+	i->nameless_cards_count = 0;
 	i->track = NULL;
 	i->track_label = NULL;
 	i->error = NULL;
 	i->chan = NULL;
+	i->xfconf_card_name = NULL;
+	i->xfconf_track_label = NULL;
+	i->previously_set_track_label = NULL;
 	i->bus = NULL;
 	i->bus_id = 0;
 	i->loop = NULL;
@@ -125,10 +131,8 @@ main(gint argc, gchar **argv)
 	xvd_xfconf_init (Inst);
 	
 	/* Get card/track from xfconf */
-	Inst->card_name = xvd_get_xfconf_card (Inst);
-	
-	if (NULL == Inst->card_name) {
-		g_warning ("There seems to be no active card defined in the xfce mixer.\n");
+	if (!xvd_xfconf_get_card (Inst)) {
+		g_debug ("Main: There seems to be no active card defined in xfconf.\n");
 	}
 	
 	/* Mixer init */
@@ -137,15 +141,14 @@ main(gint argc, gchar **argv)
 	xvd_mixer_init_bus (Inst);
 	#endif
 	
-	// A mutex for the track might help in very unlikely cases.
-	xvd_get_xfconf_card_from_mixer (Inst);
+	// A mutex for the track might help in very unlikely cases. //TODO
+	xvd_get_card_from_mixer (Inst, Inst->xfconf_card_name, NULL);
 	
-	gchar *tmp_track = xvd_get_xfconf_track (Inst);
-	xvd_get_xfconf_track_from_mixer (Inst, tmp_track);
-	g_free (tmp_track);
+	xvd_xfconf_get_track (Inst);
+	xvd_get_track_from_mixer (Inst, Inst->xfconf_track_label, NULL);
 	
 	xvd_mixer_init_volume (Inst);
-	xvd_load_xfconf_vol_step (Inst);
+	xvd_xfconf_get_vol_step (Inst);
 	
 	/* Libnotify init and idle till ready for the main loop */
 	g_set_application_name (XVD_APPNAME);
@@ -153,10 +156,9 @@ main(gint argc, gchar **argv)
 	xvd_notify_init (Inst, XVD_APPNAME);
 	#endif
 	
-	while (Inst->xvd_init_error) {
-		sleep (1);
-	}
-	
+/*	while (Inst->xvd_init_error) {*/
+/*		sleep (1);*/
+/*	}*/ //superseded ? XXX
 	
 	Inst->loop = g_main_loop_new (NULL, FALSE);
 	g_main_loop_run (Inst->loop);
diff --git a/src/xvd_data_types.h b/src/xvd_data_types.h
index c660576..3ec8c4c 100644
--- a/src/xvd_data_types.h
+++ b/src/xvd_data_types.h
@@ -45,6 +45,7 @@ typedef struct {
 	GList     			*mixers;
 	GstElement      	*card;
 	gchar				*card_name;
+	gint				nameless_cards_count;
 	
 	/* Tracks for the card */
 	GstMixerTrack   	*track;
@@ -53,6 +54,9 @@ typedef struct {
 	/* Xfconf vars */
 	GError     			*error;
 	XfconfChannel		*chan;
+	gchar				*xfconf_card_name;
+	gchar           	*xfconf_track_label;
+	gchar				*previously_set_track_label;
 
 	/* Gstreamer bus vars */
 	GstBus				*bus;
diff --git a/src/xvd_keys.c b/src/xvd_keys.c
index e2d3597..7401bf4 100644
--- a/src/xvd_keys.c
+++ b/src/xvd_keys.c
@@ -34,6 +34,9 @@ _xvd_keys_is_symbol(xcb_keycode_t elem,
 	gint i = 0;
 	gboolean belongs = FALSE;
 	
+	if (list == NULL)
+		return FALSE;
+	
 	while (list[i] != XCB_NO_SYMBOL) {
 		belongs |= (elem == list[i]);
 		i++;
@@ -59,39 +62,42 @@ _xvd_keys_handle_events(GIOChannel *source,
 					kpe = (xcb_key_press_event_t *)ev;
 					
 					if (_xvd_keys_is_symbol(kpe->detail, Inst->keyRaise)) {
-						xvd_mixer_change_volume (Inst, Inst->vol_step);
-						#ifdef HAVE_LIBNOTIFY
-						if (!Inst->muted) {
+						if (xvd_mixer_change_volume (Inst, Inst->vol_step)) {
+							#ifdef HAVE_LIBNOTIFY
+/*							if (!Inst->muted) {*/
 							if (Inst->current_vol == 100)
 								xvd_notify_overshoot_notification (Inst);
 							else
 								xvd_notify_volume_notification (Inst);
+/*							}*/
+							#endif
 						}
-						#endif
 					}
 
 					else if (_xvd_keys_is_symbol(kpe->detail, Inst->keyLower)) {
-						xvd_mixer_change_volume (Inst, (Inst->vol_step * -1));
-						#ifdef HAVE_LIBNOTIFY
-						if (!Inst->muted) {
+						if (xvd_mixer_change_volume (Inst, (Inst->vol_step * -1))) {
+							#ifdef HAVE_LIBNOTIFY
+/*							if (!Inst->muted) {*/
 							if (Inst->current_vol == 0)
 								xvd_notify_undershoot_notification (Inst);
 							else
 								xvd_notify_volume_notification (Inst);
+/*							}*/
+							#endif
 						}
-						#endif
 					}
 
 					else if (_xvd_keys_is_symbol(kpe->detail, Inst->keyMute)) {
-						xvd_mixer_toggle_mute (Inst);
-						#ifdef HAVE_LIBNOTIFY
-						if (Inst->muted)
-							xvd_notify_notification (Inst, "notification-audio-volume-muted", 0);
-						else {
-							xvd_mixer_init_volume (Inst);
-							xvd_notify_volume_notification (Inst);
+						if (xvd_mixer_toggle_mute (Inst)) {
+							#ifdef HAVE_LIBNOTIFY
+							if (Inst->muted)
+								xvd_notify_notification (Inst, "notification-audio-volume-muted", 0);
+							else {
+								xvd_mixer_init_volume (Inst);
+								xvd_notify_volume_notification (Inst);
+							}
+							#endif
 						}
-						#endif
 					}
 					break;
 				
@@ -216,9 +222,11 @@ xvd_keys_init(XvdInstance *Inst)
 void 
 xvd_keys_release (XvdInstance *Inst)
 {
-	xcb_key_symbols_free (Inst->kss);
 	g_free (Inst->keyRaise);
 	g_free (Inst->keyLower);
 	g_free (Inst->keyMute);
-	xcb_disconnect (Inst->conn);
+	if (Inst->kss)
+		xcb_key_symbols_free (Inst->kss);
+	if (Inst->conn)
+		xcb_disconnect (Inst->conn);
 }
diff --git a/src/xvd_mixer.c b/src/xvd_mixer.c
index 47a6cfd..787f337 100644
--- a/src/xvd_mixer.c
+++ b/src/xvd_mixer.c
@@ -1,7 +1,9 @@
 /*
  *  xfce4-volumed - Volume management daemon for XFCE 4
  *
- *  Copyright © 2009 Steve Dodier <sidnioulz at gmail.com>
+ *  Copyright © 2009
+ *		Steve Dodier <sidnioulz at gmail.com>
+ *		Jannis Pohlmann <jannis at xfce.org>
  *
  *  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
@@ -39,6 +41,7 @@ _xvd_mixer_filter_mixer (GstMixer *tmp_mixer,
 	gchar             *name;
 	gchar             *p;
 	gint               length;
+	gint              *counter = user_data;
 
 	/* Get long name of the mixer element */
 	factory = gst_element_get_factory (GST_ELEMENT (tmp_mixer));
@@ -49,7 +52,7 @@ _xvd_mixer_filter_mixer (GstMixer *tmp_mixer,
 	
 	/* Fall back to default name if neccessary */
 	if (G_LIKELY (device_name == NULL))
-		device_name = g_strdup ("Unknown Volume Control 0");
+		device_name = g_strdup_printf ("Unknown Volume Control %d", (*counter)++);
 
 	/* Build display name */
 	name = g_strdup_printf ("%s (%s)", device_name, long_name);
@@ -98,13 +101,15 @@ _xvd_mixer_bus_message (GstBus *bus, GstMessage *message,
 	{
 		gst_mixer_message_parse_mute_toggled (message, &msg_track, &Inst->muted);
 		g_object_get (msg_track, "label", &label, NULL);
-		if (g_strcmp0 (Inst->track_label, label) != 0)
+		if (g_utf8_collate (Inst->track_label, label) != 0)
 			return;
+#ifdef HAVE_LIBNOTIFY
 		if (Inst->muted)
 			xvd_notify_notification (Inst, "notification-audio-volume-muted", 0);
 		else {
 			xvd_mixer_init_volume (Inst);
 			xvd_notify_volume_notification (Inst);
+#endif
 		}
 		g_free (label);
 	}
@@ -112,18 +117,17 @@ _xvd_mixer_bus_message (GstBus *bus, GstMessage *message,
 	{
 		gst_mixer_message_parse_volume_changed (message, &msg_track, &volumes, &num_channels);
 		g_object_get (msg_track, "label", &label, NULL);
-		if (g_strcmp0 (Inst->track_label, label) != 0)
+		if (g_utf8_collate (Inst->track_label, label) != 0)
 			return;
 		xvd_calculate_avg_volume (Inst, volumes, num_channels);
-		if (!Inst->muted)
-			xvd_notify_volume_notification (Inst);
+#ifdef HAVE_LIBNOTIFY
+		xvd_notify_volume_notification (Inst);
+#endif
 		g_free (label);
 	}
 	else if (type == GST_MIXER_MESSAGE_MIXER_CHANGED) {
 		// This kind of message shouldn't happen on an hardware card
-		#ifndef NDEBUG
-		g_print ("GST_MIXER_MESSAGE_MIXER_CHANGED event\n");
-		#endif
+		g_debug ("GST_MIXER_MESSAGE_MIXER_CHANGED event\n");
 	}
 }
 #endif
@@ -132,7 +136,7 @@ void
 xvd_mixer_init(XvdInstance *Inst)
 {
 	/* Get list of all available mixer devices */
-	Inst->mixers = gst_audio_default_registry_mixer_filter (_xvd_mixer_filter_mixer, FALSE, Inst);
+	Inst->mixers = gst_audio_default_registry_mixer_filter (_xvd_mixer_filter_mixer, FALSE, &(Inst->nameless_cards_count));
 }
 
 #ifdef HAVE_LIBNOTIFY
@@ -149,7 +153,7 @@ xvd_mixer_init_bus(XvdInstance *Inst)
 void 
 xvd_mixer_init_volume(XvdInstance *Inst)
 {
-		if ((Inst->card) && (Inst->track)) {
+	if ((Inst->card) && (Inst->track)) {
 		gint *volumes = g_malloc (sizeof (gint) * Inst->track->num_channels);
 		gst_mixer_get_volume (GST_MIXER (Inst->card), Inst->track, volumes);
 		xvd_calculate_avg_volume (Inst, volumes, Inst->track->num_channels);
@@ -158,101 +162,149 @@ xvd_mixer_init_volume(XvdInstance *Inst)
 }
 
 void 
-xvd_get_xfconf_card_from_mixer(XvdInstance *Inst)
+xvd_get_card_from_mixer(XvdInstance *Inst, 
+						const gchar *wanted_card,
+						const gchar *preferred_fallback)
 {
 	GList      *iter;
-	gchar      *xvdgc_card_name;
-	
-	Inst->card = NULL;
+	gchar      *tmp_card_name = NULL, *first_name = NULL;
+	GstElement *fallback_card = NULL, *first_card = NULL;
 
+	// Cleaning the current card	
+	Inst->card = NULL;
+	xvd_clean_card_name (Inst);
+	
+	// We try to find the card the user wants
 	for (iter = g_list_first (Inst->mixers); iter != NULL; iter = g_list_next (iter)) {
-		xvdgc_card_name = g_object_get_data (G_OBJECT (iter->data), "xfce-mixer-internal-name");
-
-		if (G_UNLIKELY (g_utf8_collate (Inst->card_name, xvdgc_card_name) == 0)) {
+		tmp_card_name = g_object_get_data (G_OBJECT (iter->data), "xfce-mixer-internal-name");
+		
+		if ((wanted_card != NULL) && (G_UNLIKELY (g_utf8_collate (wanted_card, tmp_card_name) == 0))) {
 		  Inst->card = iter->data;
 		  break;
 		}
+
+		// If the fallback card label is set, we save the fallback card in case the wanted one isn't found
+		if ((preferred_fallback != NULL) && (G_UNLIKELY (g_utf8_collate (preferred_fallback, tmp_card_name) == 0))) {
+		  fallback_card = iter->data;
+		}
+		
+		// If no card is asked by the user, or if the asked card(s) couldn't be found, use the first one available
+		if (first_name == NULL) {
+			first_card = iter->data;
+			first_name = g_strdup (tmp_card_name);
+			if ((wanted_card == NULL) && (preferred_fallback == NULL))
+				break;
+		}
 	}
 	
-	if (NULL == Inst->card) {
-		if (Inst->card_name) {
-			xvd_clean_card_name (Inst);
-			g_warning ("The card set in xfconf could not be found.\n");
-		}
-		iter = g_list_first (Inst->mixers);
-		if ((NULL == iter) || (NULL == iter->data)) {
-			Inst->card = NULL;
-			Inst->card_name = NULL;
-			Inst->xvd_init_error = TRUE;
-			g_warning ("Gstreamer didn't return any sound card. Init error, going idle.\n");
-			return;
+	// We now check if the card was set or if we should use fallback / first instead
+	if (NULL != Inst->card) {
+		g_debug ("The card %s was found on the card and set as the current card.\n", wanted_card);
+	}
+	else if (NULL != fallback_card) {
+		g_debug ("The wanted card could not be found, using the fallback one instead.\n");
+		Inst->card_name = g_strdup (preferred_fallback);
+		Inst->card = fallback_card;
+	}
+	else if (NULL != first_card) {
+		if (wanted_card != NULL) {
+			g_debug ("The wanted card could not be found, using the first one instead.\n");
 		}
 		else {
-			xvdgc_card_name = g_object_get_data (G_OBJECT (iter->data), "xfce-mixer-internal-name");
-			Inst->card_name = g_strdup (xvdgc_card_name);
-			Inst->card = iter->data;
-			xvd_xfconf_set_card(Inst, Inst->card_name);
-			g_warning ("The xfconf property %s has been defaulted to %s.\n", XFCONF_MIXER_ACTIVECARD, Inst->card_name);
+			g_debug ("Setting the first card in the xfconf property since there was no card set.\n");
+			xvd_xfconf_set_card (Inst, first_name);
 		}
+		Inst->card_name = g_strdup (first_name);
+		Inst->card = first_card;
+	}
+	else {
+		g_debug ("Error: there is no sound card on this machine.\n");
+		Inst->xvd_init_error = TRUE;
+		return;
 	}
 	
+	g_free (first_name);
+
 	#ifdef HAVE_LIBNOTIFY
+	gst_object_unref (Inst->bus);
 	gst_element_set_bus (Inst->card, Inst->bus);
 	#endif
 }
 
 void 
-xvd_get_xfconf_track_from_mixer(XvdInstance *Inst, 
-								const gchar *xfconf_val)
+xvd_get_track_from_mixer(XvdInstance *Inst, 
+							const gchar *wanted_track,
+							const gchar *preferred_fallback)
 {
 	const GList   *iter;
 	gchar         *tmp_label = NULL, *master_label = NULL, *first_label = NULL;
-	GstMixerTrack *master_track = NULL, *first_track = NULL;
+	GstMixerTrack *fallback_track = NULL, *master_track = NULL, *first_track = NULL;
+	
+	// We clean the current track before setting another one
+	xvd_clean_track (Inst);
+	Inst->track = NULL;
 	
-	if (Inst->card_name) {
+	// We're going to go through the available tracks
+	if (Inst->card) {
 		for (iter = gst_mixer_list_tracks (GST_MIXER (Inst->card)); iter != NULL; iter = g_list_next (iter)) {
 			g_object_get (GST_MIXER_TRACK (iter->data), "label", &tmp_label, NULL);
 			
-			if (first_label == NULL) {
-				first_track = iter->data;
-				first_label = g_strdup (tmp_label);
-			}
-			
-			if (master_label == NULL) {
-				if (TRUE == GST_MIXER_TRACK_HAS_FLAG ((GstMixerTrack *)iter->data, GST_MIXER_TRACK_MASTER)) {
-					master_track = iter->data;
-					master_label = g_strdup (tmp_label);
-				}
-			}
-			
-			if ((xfconf_val != NULL) && (g_utf8_collate (tmp_label, xfconf_val) == 0)) {
+			// If the wanted track is requested and found
+			if ((wanted_track != NULL) && (g_utf8_collate (tmp_label, wanted_track) == 0)) {
 				Inst->track_label = g_strdup (tmp_label);
 				Inst->track = iter->data;
 				g_free (tmp_label);
 				break;
 			}
+			
+			// If the fallback track label is set, we save the fallback track in case the wanted one isn't found
+			if ((preferred_fallback != NULL) && (g_utf8_collate (tmp_label, preferred_fallback) == 0)) {
+				fallback_track = iter->data;
+			}
+			
+			// If we spot a Master track in the card, we save it in case the xfconf / fallback ones can't be found
+			if ((master_label == NULL) && (TRUE == GST_MIXER_TRACK_HAS_FLAG ((GstMixerTrack *)iter->data, GST_MIXER_TRACK_MASTER))) {
+				master_track = iter->data;
+				master_label = g_strdup (tmp_label);
+			}
+			
+			// We save the first track of the card in case there is no xfconf / fallback / master track
+			if (first_label == NULL) {
+				first_track = iter->data;
+				first_label = g_strdup (tmp_label);
+			}
+			
 			g_free (tmp_label);
 		}
 	}
+	else {
+		g_debug ("Error: there is no sound card to search tracks from.\n");
+		Inst->xvd_init_error = TRUE;
+		return;
+	}
 	
-	if (NULL == Inst->track_label) {
-		g_warning ("There is no xfconf track, trying the first Master track of the card.\n");
-		if (NULL == master_label) {
-			g_warning ("There is no Master track either, trying the first track of the card.\n");
-			if (NULL == first_label) {
-				g_warning ("The card doesn't have any track (or there is no card). Xvd init error, going to idle.\n");
-				Inst->xvd_init_error = TRUE;
-				return;
-			}
-			else {
-				Inst->track_label = g_strdup (first_label);
-				Inst->track = first_track;
-			}
-		}
-		else {
-			Inst->track_label = g_strdup (master_label);
-			Inst->track = master_track;
-		}
+	if (NULL != Inst->track) {
+		g_debug ("The track %s was found on the card and set as the current track.\n", wanted_track);
+	}
+	else if (NULL != fallback_track) {
+		g_debug ("The wanted track could not be found, using the fallback one instead.\n");
+		Inst->track_label = g_strdup (preferred_fallback);
+		Inst->track = fallback_track;
+	}
+	else if (NULL != master_track) {
+		g_debug ("The wanted track could not be found, using the first Master one instead.\n");
+		Inst->track_label = g_strdup (master_label);
+		Inst->track = master_track;
+	}
+	else if (NULL != first_track) {
+		g_debug ("The wanted track could not be found, using the first one instead.\n");
+		Inst->track_label = g_strdup (first_label);
+		Inst->track = first_track;
+	}
+	else {
+		g_debug ("Error: the current sound card doesn't have any track.\n");
+		Inst->xvd_init_error = TRUE;
+		return;
 	}
 	
 	g_free (first_label);
@@ -260,9 +312,7 @@ xvd_get_xfconf_track_from_mixer(XvdInstance *Inst,
 	
 	if (Inst->xvd_init_error) {
 		Inst->xvd_init_error = FALSE;
-		#ifndef NDEBUG
-		g_print ("The daemon apparently recovered from a card/track initialisation error.\n");
-		#endif
+		g_debug ("The daemon apparently recovered from a card/track initialisation error.\n");
 	}
 }
 
@@ -290,9 +340,8 @@ xvd_clean_cards(XvdInstance *Inst)
 void
 xvd_clean_mixer_bus(XvdInstance *Inst)
 {
-	g_signal_handler_disconnect (Inst->bus, Inst->bus_id);
-
 	gst_bus_remove_signal_watch (Inst->bus);
+	g_signal_handler_disconnect (Inst->bus, Inst->bus_id);
 	gst_object_unref (Inst->bus);
 }
 #endif
@@ -301,7 +350,6 @@ void
 xvd_clean_track(XvdInstance *Inst)
 {
 	g_free (Inst->track_label);
-/*	Inst->track_label = NULL;*/
 }
 
 
@@ -323,11 +371,11 @@ xvd_calculate_avg_volume(XvdInstance *Inst,
 	}
 }
 
-void 
+gboolean 
 xvd_mixer_change_volume(XvdInstance *Inst, 
 						gint step)
 {
-	if ((Inst->card_name) && (Inst->track)) {
+	if ((Inst->card) && (Inst->track)) {
 		gint i;
 		gint *volumes = g_malloc (sizeof (gint) * Inst->track->num_channels);
 		
@@ -347,14 +395,19 @@ xvd_mixer_change_volume(XvdInstance *Inst,
 		
 		gst_mixer_set_volume (GST_MIXER (Inst->card), Inst->track, volumes);
 		g_free (volumes);
+		
+		return TRUE;
 	}
+	return FALSE;
 }
 
-void 
+gboolean 
 xvd_mixer_toggle_mute(XvdInstance *Inst)
 {
-	if ((Inst->card_name) && (Inst->track)) {
+	if ((Inst->card) && (Inst->track)) {
 		gst_mixer_set_mute (GST_MIXER (Inst->card), Inst->track, !(GST_MIXER_TRACK_HAS_FLAG (Inst->track, GST_MIXER_TRACK_MUTE)));
 		Inst->muted = (GST_MIXER_TRACK_HAS_FLAG (Inst->track, GST_MIXER_TRACK_MUTE));
+		return TRUE;
 	}
+	return FALSE;
 }
diff --git a/src/xvd_mixer.h b/src/xvd_mixer.h
index c518c28..6d22177 100644
--- a/src/xvd_mixer.h
+++ b/src/xvd_mixer.h
@@ -40,11 +40,14 @@ void
 xvd_mixer_init_volume(XvdInstance *Inst);
 
 void 
-xvd_get_xfconf_card_from_mixer(XvdInstance *Inst);
+xvd_get_card_from_mixer(XvdInstance *Inst, 
+						const gchar *wanted_card,
+						const gchar *preferred_fallback);
 
 void 
-xvd_get_xfconf_track_from_mixer(XvdInstance *Inst, 
-								const gchar *xfconf_val);
+xvd_get_track_from_mixer(XvdInstance *Inst, 
+							const gchar *wanted_track,
+							const gchar *preferred_fallback);
 
 void 
 xvd_clean_card_name(XvdInstance *Inst);
@@ -65,11 +68,11 @@ xvd_calculate_avg_volume(XvdInstance *Inst,
 						 gint *volumes, 
 						 gint num_channels);
 
-void 
+gboolean  
 xvd_mixer_change_volume(XvdInstance *Inst, 
 						gint step);
 
-void 
+gboolean 
 xvd_mixer_toggle_mute(XvdInstance *Inst);
 
 #endif
diff --git a/src/xvd_notify.c b/src/xvd_notify.c
index 651cd4a..f47f1ea 100644
--- a/src/xvd_notify.c
+++ b/src/xvd_notify.c
@@ -30,13 +30,26 @@ xvd_notify_notification(XvdInstance *Inst,
 						gint value)
 {
 	if (Inst->notifyosd) {
-		NotifyNotification* notification;
-
+		NotifyNotification* notification	= NULL;
+		gchar* body							= NULL;
+		
+		if ((icon != NULL) && (g_strcmp0(icon, "notification-audio-volume-muted") == 0)) {
+			// TRANSLATORS: this is the body of the ATK interface of the volume notifications. Just before this, there is the 'Volume' word (as a notification title). If it would look too weird in your locale, translate this string as 'The volume is muted' instead.
+			body = g_strdup ("is muted");
+		}
+		else {
+			// TRANSLATORS: %d is the volume displayed as a percent, and %c is replaced by '%'. If it doesn't fit in your locale feel free to file a bug.
+			body = g_strdup_printf ("is at %d%c", value, '%');
+		}
+		
 		notification = notify_notification_new (
 					"Volume",
-					NULL,
+					body,
 					icon,
 					NULL);
+		
+		g_free (body);
+		
 		notify_notification_set_hint_int32 (notification,
 							"value",
 							value);
@@ -57,25 +70,25 @@ void
 xvd_notify_volume_notification(XvdInstance *Inst)
 {
 	if (Inst->current_vol == 0)
-		xvd_notify_notification (Inst, "notification-audio-volume-off", 0);
+		xvd_notify_notification (Inst, (Inst->muted) ? "notification-audio-volume-muted" : "notification-audio-volume-off", 0);
 	else if (Inst->current_vol < 34)
-		xvd_notify_notification (Inst, "notification-audio-volume-low", Inst->current_vol);
+		xvd_notify_notification (Inst, (Inst->muted) ? "notification-audio-volume-muted" : "notification-audio-volume-low", Inst->current_vol);
 	else if (Inst->current_vol < 67)
-		xvd_notify_notification (Inst, "notification-audio-volume-medium", Inst->current_vol);
+		xvd_notify_notification (Inst, (Inst->muted) ? "notification-audio-volume-muted" : "notification-audio-volume-medium", Inst->current_vol);
 	else
-		xvd_notify_notification (Inst, "notification-audio-volume-high", Inst->current_vol);
+		xvd_notify_notification (Inst, (Inst->muted) ? "notification-audio-volume-muted" : "notification-audio-volume-high", Inst->current_vol);
 }
 
 void
 xvd_notify_overshoot_notification(XvdInstance *Inst)
 {
-	xvd_notify_notification (Inst, "notification-audio-volume-high", 101);
+	xvd_notify_notification (Inst, (Inst->muted) ? "notification-audio-volume-muted" : "notification-audio-volume-high", 101);
 }
 
 void
 xvd_notify_undershoot_notification(XvdInstance *Inst)
 {
-	xvd_notify_notification (Inst, "notification-audio-volume-off", -1);
+	xvd_notify_notification (Inst, (Inst->muted) ? "notification-audio-volume-muted" : "notification-audio-volume-off", -1);
 }
 
 void 
diff --git a/src/xvd_xfconf.c b/src/xvd_xfconf.c
index a75a83b..52d0757 100644
--- a/src/xvd_xfconf.c
+++ b/src/xvd_xfconf.c
@@ -23,44 +23,114 @@
 static void
 _xvd_xfconf_reinit_card(XvdInstance *Inst)
 {
-	xvd_clean_card_name(Inst);
-	Inst->card_name = xvd_get_xfconf_card (Inst);
-	if (NULL == Inst->card_name) {
-		g_warning ("The new active card defined in the xfce mixer seems to be wrong.\n");
-		Inst->xvd_init_error = TRUE;
+	gchar *previous_card = NULL;
+	
+	if (!xvd_xfconf_get_card (Inst)) {
+		// If we fail to get an xfconf card, we save the current one in xfconf
+		if (Inst->card_name != NULL) {
+			xvd_xfconf_set_card (Inst, Inst->card_name);
+			Inst->xfconf_card_name = g_strdup (Inst->card_name);
+		}
+		// If the current card is NULL too, we do nothing
+		return;
+	}
+	
+	// If the card set in xfconf is the same as the currently used one, we do nothing
+	if ((Inst->card_name != NULL) && (g_utf8_collate (Inst->xfconf_card_name, Inst->card_name) == 0)) {
+		return;
+	}
+	
+	// We now clean the current track and try to replace it with the one set in xfconf
+	previous_card = g_strdup (Inst->card_name);
+	xvd_clean_card_name (Inst);
+	xvd_get_card_from_mixer (Inst, Inst->xfconf_card_name, previous_card);
+	
+	// At this stage the track grabbed is wrong, but we expect the user to also update the track key
+	
+	// We check if the card has been correctly set
+	if ((Inst->card_name == NULL) || (g_utf8_collate (Inst->xfconf_card_name, Inst->card_name) != 0)) {
+		g_debug ("The card chosen in xfconf could not be set, another one was set instead\nChosen: %s\nSet: %s\n",
+														Inst->xfconf_card_name,
+														Inst->card_name);
+		// If not, we save the valid card in xfconf instead of the user chosen
+		// TODO we should actually refresh the mixers prior to finding the new card
+		xvd_xfconf_set_card (Inst, Inst->card_name);
+		g_free (Inst->xfconf_card_name);
+		Inst->xfconf_card_name = g_strdup (Inst->card_name);
+	}
+	
+	g_free (previous_card);
+	
+	// If an xfconf track has failed to be applied before, it's probably that the user chosed his new track before the card to which it belongs.
+	// So we check if the track belongs to our new card.
+	if (Inst->previously_set_track_label) {
+		xvd_get_track_from_mixer (Inst, Inst->previously_set_track_label, Inst->track_label);
+		if (g_utf8_collate (Inst->previously_set_track_label, Inst->track_label) == 0) {
+			xvd_xfconf_set_track (Inst, Inst->previously_set_track_label);
+			g_free (Inst->previously_set_track_label);
+			g_debug ("The previously set xfconf track was a track from the newly set sound card.\n");
+		}
 	}
+	// Else, we can still try to see if the current track applies
 	else {
-		
-		xvd_get_xfconf_card_from_mixer (Inst);
-		#ifndef NDEBUG
-		g_print ("New card : %s \n", Inst->card_name);
-		#endif
+		xvd_get_track_from_mixer (Inst, Inst->track_label, NULL);
 	}
+
+	g_debug ("Xfconf reinit: the card is now %s, the track (probably wrong) is %s and the volume is %d\n", Inst->card_name, Inst->track_label, Inst->current_vol);
 }
 
 static void
 _xvd_xfconf_reinit_track(XvdInstance *Inst)
 {
-	xvd_clean_track (Inst);
+	gchar *previous_track = NULL;
+	
+	if (!xvd_xfconf_get_track (Inst)) {
+		// If we fail to get an xfconf track, we save the current one in xfconf
+		if (Inst->track_label != NULL) {
+			xvd_xfconf_set_track (Inst, Inst->track_label);
+			Inst->xfconf_track_label = g_strdup (Inst->track_label);
+		}
+		// If the current track is NULL too, we do nothing
+		return;
+	}
+	
+	// If the track set in xfconf is the same as the currently used one, we do nothing
+	if ((Inst->track_label != NULL) && (g_utf8_collate (Inst->xfconf_track_label, Inst->track_label) == 0)) {
+		return;
+	}
 	
-	gchar *tmp_track = xvd_get_xfconf_track (Inst);
-	xvd_get_xfconf_track_from_mixer (Inst, tmp_track);
-	g_free (tmp_track);
+	// We now clean the current track and try to replace it with the one set in xfconf
+	previous_track = g_strdup (Inst->track_label);
+	xvd_clean_track (Inst);
+	xvd_get_track_from_mixer (Inst, Inst->xfconf_track_label, previous_track);
 
+	// We check if the track has been correctly set
+	if ((Inst->track_label == NULL) || (g_utf8_collate (Inst->xfconf_track_label, Inst->track_label) != 0)) {
+		// If not, we save the valid track in xfconf instead of the user chosen
+		Inst->previously_set_track_label = g_strdup (Inst->xfconf_track_label);
+		g_debug ("The track chosen in xfconf (%s) doesn't exist in the current card. It'll be tried again after a sound card change.\nNow using %s.\n",
+					Inst->xfconf_track_label,
+					Inst->track_label);
+		xvd_xfconf_set_track (Inst, Inst->track_label);
+		g_free (Inst->xfconf_track_label);
+		Inst->xfconf_track_label = g_strdup (Inst->track_label);
+	}
+	else {
+		g_free (Inst->previously_set_track_label);
+	}
+	
 	xvd_mixer_init_volume (Inst);
-	#ifndef NDEBUG
-	g_print ("New track : %s with volume %d\n", Inst->track_label, Inst->current_vol);
-	#endif
+	g_free (previous_track);
+
+	g_debug ("Xfconf reinit: the track is now %s and the volume is %d\n", Inst->track_label, Inst->current_vol);
 }
 
 
 static void
 _xvd_xfconf_reinit_vol_step(XvdInstance *Inst)
 {
-		xvd_load_xfconf_vol_step (Inst);
-		#ifndef NDEBUG
-		g_print ("New volume step : %u\n", Inst->vol_step);
-		#endif
+		xvd_xfconf_get_vol_step (Inst);
+		g_debug ("Xfconf reinit: volume step is now %u\n", Inst->vol_step);
 }
 
 static void 
@@ -70,9 +140,7 @@ _xvd_xfconf_handle_changes(XfconfChannel  *re_channel,
 						   gpointer  	  *ptr)
 {
 	XvdInstance *Inst = (XvdInstance *)ptr;
-	#ifndef NDEBUG
-	g_print ("Xfconf event on %s\n", re_property_name);
-	#endif
+	g_debug ("Xfconf event on %s\n", re_property_name);
 	
 	if (g_strcmp0 (re_property_name, XFCONF_MIXER_ACTIVECARD) == 0) {
 		_xvd_xfconf_reinit_card(Inst);
@@ -99,40 +167,76 @@ xvd_xfconf_init(XvdInstance *Inst)
 	g_signal_connect (G_OBJECT (Inst->chan), "property-changed", G_CALLBACK (_xvd_xfconf_handle_changes), Inst);
 }
 
-gchar *
-xvd_get_xfconf_card(XvdInstance *Inst)
+gboolean 
+xvd_xfconf_get_card(XvdInstance *Inst)
 {
+	if (Inst->xfconf_card_name) {
+		g_debug ("%s\n", "Cleaning the current card name stored in xfconf");
+		g_free (Inst->xfconf_card_name);
+	}
+	
 	if (FALSE == xfconf_channel_has_property (Inst->chan, XFCONF_MIXER_ACTIVECARD)) {
 		// Transition purpose - we dont watch changes on the legacy property afterwards
 		if (FALSE == xfconf_channel_has_property (Inst->chan, XFCONF_MIXER_ACTIVECARD_LEGACY)) {
-			g_warning ("%s\n", "Error while trying to retrieve the mixer channel's active card");
-			return NULL;
+			g_debug ("%s\n", "There is no card name stored in xfconf");
+			return FALSE;
 		}
 		else {
-			g_warning ("%s\n", "Using the legacy xfconf property for the active card");
-			gchar *legacy_value = xfconf_channel_get_string (Inst->chan, XFCONF_MIXER_ACTIVECARD_LEGACY, NULL);
-			xvd_xfconf_set_card (Inst, legacy_value);
-			return legacy_value;
+			g_debug ("%s\n", "Using the legacy xfconf property for the card name, and saving its value into the new xfconf property");
+			Inst->xfconf_card_name = xfconf_channel_get_string (Inst->chan, XFCONF_MIXER_ACTIVECARD_LEGACY, NULL);
+			xvd_xfconf_set_card (Inst, Inst->xfconf_card_name);
+			g_debug ("%s %s\n", "Xfconf card name:", Inst->xfconf_card_name);
+			return Inst->xfconf_card_name != NULL;
 		}
 	}
 	
-	return xfconf_channel_get_string (Inst->chan, XFCONF_MIXER_ACTIVECARD, NULL);
+	Inst->xfconf_card_name = xfconf_channel_get_string (Inst->chan, XFCONF_MIXER_ACTIVECARD, NULL);
+	return Inst->xfconf_card_name != NULL;
+}
+
+void 
+xvd_xfconf_set_card(XvdInstance *Inst, gchar *value)
+{
+	g_debug ("%s %s\n", "Setting the xfconf card name to", Inst->xfconf_card_name);
+	xfconf_channel_set_string (Inst->chan, XFCONF_MIXER_ACTIVECARD, value);
+}
+
+gboolean
+xvd_xfconf_get_track(XvdInstance *Inst)
+{
+	if (Inst->xfconf_track_label) {
+		g_debug ("%s\n", "Cleaning the current track label stored in xfconf");
+		g_free (Inst->xfconf_track_label);
+	}
+	
+	Inst->xfconf_track_label = xfconf_channel_get_string (Inst->chan, XFCONF_MIXER_ACTIVETRACK, NULL);
+	if (Inst->xfconf_track_label != NULL) {
+		g_debug ("%s %s\n", "Xfconf track label:", Inst->xfconf_track_label);
+		return TRUE;
+	}
+	else {
+		g_debug ("%s\n", "There is no track label stored in xfconf");
+		return FALSE;
+	}
 }
 
-gchar *
-xvd_get_xfconf_track(XvdInstance *Inst)
+void 
+xvd_xfconf_set_track(XvdInstance *Inst, gchar *value)
 {
-	return xfconf_channel_get_string (Inst->chan, XFCONF_MIXER_ACTIVETRACK, NULL);
+	g_debug("%s %s\n", "Setting the xfconf card name to", Inst->xfconf_card_name);
+	xfconf_channel_set_string (Inst->chan, XFCONF_MIXER_ACTIVETRACK, value);
 }
 
 void 
-xvd_load_xfconf_vol_step(XvdInstance *Inst)
+xvd_xfconf_get_vol_step(XvdInstance *Inst)
 {
 	Inst->vol_step = xfconf_channel_get_uint (Inst->chan, XFCONF_MIXER_VOL_STEP, -1);
 	if ((Inst->vol_step < 0) || (Inst->vol_step > 100)) {
+		g_debug ("%s\n", "The volume step xfconf property is out of range, setting back to default");
 		Inst->vol_step = VOL_STEP_DEFAULT_VAL;
 		xfconf_channel_set_uint (Inst->chan, XFCONF_MIXER_VOL_STEP, VOL_STEP_DEFAULT_VAL);
 	}
+	g_debug("%s %u\n", "Xfconf volume step:", Inst->vol_step);
 }
 
 void 
@@ -140,9 +244,3 @@ xvd_xfconf_shutdown(XvdInstance *Inst)
 {
 	xfconf_shutdown ();
 }
-
-void 
-xvd_xfconf_set_card(XvdInstance *Inst, gchar *value)
-{
-	xfconf_channel_set_string (Inst->chan, XFCONF_MIXER_ACTIVECARD, value);
-}
diff --git a/src/xvd_xfconf.h b/src/xvd_xfconf.h
index 5212b42..e68bba3 100644
--- a/src/xvd_xfconf.h
+++ b/src/xvd_xfconf.h
@@ -27,19 +27,22 @@
 void 
 xvd_xfconf_init(XvdInstance *Inst);
 
-gchar *
-xvd_get_xfconf_card(XvdInstance *Inst);
-
-gchar *
-xvd_get_xfconf_track(XvdInstance *Inst);
+gboolean 
+xvd_xfconf_get_card(XvdInstance *Inst);
 
 void 
-xvd_load_xfconf_vol_step(XvdInstance *Inst);
+xvd_xfconf_set_card(XvdInstance *Inst, gchar *value);
+
+gboolean
+xvd_xfconf_get_track(XvdInstance *Inst);
 
 void 
-xvd_xfconf_shutdown(XvdInstance *Inst);
+xvd_xfconf_set_track(XvdInstance *Inst, gchar *value);
+
+void   
+xvd_xfconf_get_vol_step(XvdInstance *Inst);
 
 void 
-xvd_xfconf_set_card(XvdInstance *Inst, gchar *value);
+xvd_xfconf_shutdown(XvdInstance *Inst);
 
 #endif

-- 
To stop receiving notification emails like this one, please contact
the administrator of this repository.


More information about the Xfce4-commits mailing list