[Xfce4-commits] <xfce4-mixer:master> Clearly indicate in the plugin when there is no valid card and/or element

Guido Berhoerster noreply at xfce.org
Thu Sep 27 16:46:09 CEST 2012


Updating branch refs/heads/master
         to bd01221ec80da339af7cba076d46aa3fdeee4053 (commit)
       from df715a44cee9f5c1ff4a6bef3427f0c8ef717823 (commit)

commit bd01221ec80da339af7cba076d46aa3fdeee4053
Author: Guido Berhoerster <guido+xfce at berhoerster.name>
Date:   Thu Sep 27 16:31:08 2012 +0200

    Clearly indicate in the plugin when there is no valid card and/or element
    
    If the panel plugin has no valid configuration, that is no valid card and/or
    element, show the muted icon and ignore mouse wheel and mute toggle events (bug
    #6625, bug #7630).

 NEWS                              |    2 +
 panel-plugin/xfce-mixer-plugin.c  |    6 +-
 panel-plugin/xfce-volume-button.c |  131 +++++++++++++++++++++++++++++++++++--
 panel-plugin/xfce-volume-button.h |   22 ++++---
 4 files changed, 143 insertions(+), 18 deletions(-)

diff --git a/NEWS b/NEWS
index 5035212..01cfa15 100644
--- a/NEWS
+++ b/NEWS
@@ -12,6 +12,8 @@
 - 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).
+- Clearly indicate in the plugin when there is no valid card and/or element
+  and ignore mouse wheel and mute toggle events (bug #6625, bug #7630).
 
 
 4.8.0
diff --git a/panel-plugin/xfce-mixer-plugin.c b/panel-plugin/xfce-mixer-plugin.c
index 1062d1b..ef4d49f 100644
--- a/panel-plugin/xfce-mixer-plugin.c
+++ b/panel-plugin/xfce-mixer-plugin.c
@@ -610,10 +610,11 @@ xfce_mixer_plugin_update_track (XfceMixerPlugin *mixer_plugin)
 
   g_return_if_fail (IS_XFCE_MIXER_PLUGIN (mixer_plugin));
 
-  /* Reset tooltip and return if the card or track is invalid */
+  /* Set the volume button to invalid state and return if the card or track is invalid */
   if (!GST_IS_MIXER (mixer_plugin->card) || !GST_IS_MIXER_TRACK (mixer_plugin->track))
     {
-      gtk_tooltips_set_tip (mixer_plugin->tooltips, mixer_plugin->button, NULL, NULL);
+      xfce_volume_button_set_is_configured (XFCE_VOLUME_BUTTON (mixer_plugin->button), FALSE);
+      gtk_tooltips_set_tip (mixer_plugin->tooltips, mixer_plugin->button, _("No valid device and/or element."), NULL);
       return;
     }
 
@@ -641,6 +642,7 @@ xfce_mixer_plugin_update_track (XfceMixerPlugin *mixer_plugin)
     muted = !GST_MIXER_TRACK_HAS_FLAG (mixer_plugin->track, GST_MIXER_TRACK_RECORD);
 
   /* Update the volume button */
+  xfce_volume_button_set_is_configured (XFCE_VOLUME_BUTTON (mixer_plugin->button), TRUE);
   xfce_volume_button_set_volume (XFCE_VOLUME_BUTTON (mixer_plugin->button), volume);
   xfce_volume_button_set_muted (XFCE_VOLUME_BUTTON (mixer_plugin->button), muted);
 
diff --git a/panel-plugin/xfce-volume-button.c b/panel-plugin/xfce-volume-button.c
index adb94a7..3b5d90e 100644
--- a/panel-plugin/xfce-volume-button.c
+++ b/panel-plugin/xfce-volume-button.c
@@ -42,6 +42,16 @@
 
 
 
+/* Properties */
+enum
+{
+  PROP_0,
+  PROP_IS_CONFIGURED,
+  N_PROPERTIES,
+};
+
+
+
 /* Signal identifiers */
 enum
 {
@@ -72,6 +82,14 @@ static void       xfce_volume_button_class_init     (XfceVolumeButtonClass *klas
 static void       xfce_volume_button_init           (XfceVolumeButton      *button);
 static void       xfce_volume_button_dispose        (GObject               *object);
 static void       xfce_volume_button_finalize       (GObject               *object);
+static void       xfce_volume_button_set_property   (GObject               *object,
+                                                     guint                  prop_id,
+                                                     const GValue          *value,
+                                                     GParamSpec            *pspec);
+static void       xfce_volume_button_get_property   (GObject               *object,
+                                                     guint                  prop_id,
+                                                     GValue                *value,
+                                                     GParamSpec            *pspec);
 #if 0
 static gboolean   xfce_volume_button_key_pressed    (GtkWidget             *widget,
                                                      GdkEventKey           *event,
@@ -119,6 +137,9 @@ struct _XfceVolumeButton
   /* Array of preloaded icons */
   GdkPixbuf **pixbufs;
 
+  /* Whether the button is configured */
+  gboolean    is_configured;
+
   /* Mute state of the button */
   gboolean    is_muted;
 };
@@ -169,10 +190,20 @@ xfce_volume_button_class_init (XfceVolumeButtonClass *klass)
   gobject_class = G_OBJECT_CLASS (klass);
   gobject_class->dispose = xfce_volume_button_dispose;
   gobject_class->finalize = xfce_volume_button_finalize;
+  gobject_class->set_property = xfce_volume_button_set_property;
+  gobject_class->get_property = xfce_volume_button_get_property;
 
   klass->volume_changed = xfce_volume_button_volume_changed;
   klass->mute_toggled = xfce_volume_button_mute_toggled;
 
+  g_object_class_install_property (gobject_class,
+                                   PROP_IS_CONFIGURED,
+                                   g_param_spec_boolean ("is-configured",
+                                                         "is-configured",
+                                                         "is-configured",
+                                                         FALSE,
+                                                         G_PARAM_READABLE | G_PARAM_WRITABLE));
+
   button_signals[VOLUME_CHANGED] = g_signal_new ("volume-changed",
                                                  G_TYPE_FROM_CLASS (klass),
                                                  G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
@@ -201,6 +232,8 @@ xfce_volume_button_class_init (XfceVolumeButtonClass *klass)
 static void
 xfce_volume_button_init (XfceVolumeButton *button)
 {
+  button->is_configured = FALSE;
+
   /* By default we expect the button not to be muted */
   button->is_muted = FALSE;
 
@@ -261,6 +294,52 @@ xfce_volume_button_finalize (GObject *object)
 
 
 
+static void xfce_volume_button_set_property (GObject      *object,
+                                             guint         prop_id,
+                                             const GValue *value,
+                                             GParamSpec   *pspec)
+{
+  XfceVolumeButton *button = XFCE_VOLUME_BUTTON (object);
+  gboolean          is_configured;
+
+  switch (prop_id)
+    {
+      case PROP_IS_CONFIGURED:
+        is_configured = g_value_get_boolean (value);
+        if (button->is_configured != is_configured)
+          {
+            button->is_configured = is_configured;
+            xfce_volume_button_update (button);
+          }
+        break;
+      default:
+        G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
+        break;
+    }
+}
+
+
+
+static void xfce_volume_button_get_property (GObject      *object,
+                                             guint         prop_id,
+                                             GValue       *value,
+                                             GParamSpec   *pspec)
+{
+  XfceVolumeButton *button = XFCE_VOLUME_BUTTON (object);
+
+  switch (prop_id)
+    {
+      case PROP_IS_CONFIGURED:
+        g_value_set_boolean (value, button->is_configured);
+        break;
+      default:
+        G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
+        break;
+    }
+}
+
+
+
 GtkWidget*
 xfce_volume_button_new (void)
 {
@@ -341,14 +420,18 @@ xfce_volume_button_button_pressed (GtkWidget        *widget,
   /* Check if the middle mouse button was pressed */
   if (event->button == 2)
     {
-      /* Determine the new mute state by negating the current state */
-      mute = !button->is_muted;
+      /* Only toggle mute if button is in configured state */
+      if (button->is_configured)
+        {
+          /* Determine the new mute state by negating the current state */
+          mute = !button->is_muted;
 
-      /* Toggle the button's mute state */
-      xfce_volume_button_set_muted (button, mute);
+          /* Toggle the button's mute state */
+          xfce_volume_button_set_muted (button, mute);
 
-      /* Notify listeners of the mute change */
-      g_signal_emit_by_name (button, "mute-toggled", mute);
+          /* Notify listeners of the mute change */
+          g_signal_emit_by_name (button, "mute-toggled", mute);
+        }
 
       /* Middle mouse button was handled, do not propagate the event any further */
       return TRUE;
@@ -371,6 +454,10 @@ xfce_volume_button_scrolled (GtkWidget        *widget,
   g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
   g_return_val_if_fail (IS_XFCE_VOLUME_BUTTON (button), FALSE);
 
+  /* Ignore scroll events if the button is not in configured state */
+  if (!button->is_configured)
+    return TRUE;
+
   /* Get current adjustment value and the step increment size */
   g_object_get (G_OBJECT (button->adjustment), "value", &value, "step-increment", &step_increment, NULL);
 
@@ -419,7 +506,7 @@ xfce_volume_button_update (XfceVolumeButton *button)
   /* Determine the difference between upper and lower bound (= volume range) */
   range = (upper - lower) / (G_N_ELEMENTS (icons) - 2);
 
-  if (G_UNLIKELY (button->is_muted || value < VOLUME_EPSILON))
+  if (G_UNLIKELY (!button->is_configured || button->is_muted || value < VOLUME_EPSILON))
     {
       /* By definition, use the first icon if the button is muted or the volume is 0 */
       pixbuf = button->pixbufs[0];
@@ -530,3 +617,33 @@ xfce_volume_button_mute_toggled (XfceVolumeButton *button,
 {
   /* Do nothing */
 }
+
+
+
+void
+xfce_volume_button_set_is_configured (XfceVolumeButton *button,
+                                      gboolean          is_configured)
+{
+  GValue value = G_VALUE_INIT;
+
+  g_return_if_fail (IS_XFCE_VOLUME_BUTTON (button));
+
+  g_value_init (&value, G_TYPE_BOOLEAN);
+  g_value_set_boolean (&value, is_configured);
+  g_object_set_property (G_OBJECT (button), "is-configured", &value);
+}
+
+
+
+gboolean
+xfce_volume_button_get_is_configured (XfceVolumeButton *button)
+{
+  GValue value = G_VALUE_INIT;
+
+  g_return_val_if_fail (IS_XFCE_VOLUME_BUTTON (button), FALSE);
+
+  g_value_init (&value, G_TYPE_BOOLEAN);
+  g_object_get_property (G_OBJECT (button), "is-configured", &value);
+
+  return g_value_get_boolean (&value);
+}
diff --git a/panel-plugin/xfce-volume-button.h b/panel-plugin/xfce-volume-button.h
index acdefa3..a92f0e7 100644
--- a/panel-plugin/xfce-volume-button.h
+++ b/panel-plugin/xfce-volume-button.h
@@ -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
@@ -35,17 +36,20 @@ typedef struct _XfceVolumeButton      XfceVolumeButton;
 #define IS_XFCE_VOLUME_BUTTON_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), TYPE_XFCE_VOLUME_BUTTON))
 #define XFCE_VOLUME_BUTTON_GET_CLASS(obj)  (G_TYPE_INSTANCE_GET_CLASS ((obj), TYPE_XFCE_VOLUME_BUTTON, XfceVolumeButtonClass))
 
-GType     xfce_volume_button_get_type       (void) G_GNUC_CONST;
+GType     xfce_volume_button_get_type           (void) G_GNUC_CONST;
 
-GtkWidget *xfce_volume_button_new           (void);
+GtkWidget *xfce_volume_button_new               (void);
 
-void       xfce_volume_button_set_muted     (XfceVolumeButton *button,
-                                             gboolean          muted);
-void       xfce_volume_button_set_volume    (XfceVolumeButton *button,
-                                             gdouble           volume);
-void       xfce_volume_button_update        (XfceVolumeButton *button);
-void       xfce_volume_button_set_icon_size (XfceVolumeButton *button,
-                                             gint              size);
+void       xfce_volume_button_set_muted         (XfceVolumeButton *button,
+                                                 gboolean          muted);
+void       xfce_volume_button_set_volume        (XfceVolumeButton *button,
+                                                 gdouble           volume);
+void       xfce_volume_button_update            (XfceVolumeButton *button);
+void       xfce_volume_button_set_icon_size     (XfceVolumeButton *button,
+                                                 gint              size);
+void       xfce_volume_button_set_is_configured (XfceVolumeButton *button,
+                                                 gboolean          is_configured);
+gboolean   xfce_volume_button_get_is_configured (XfceVolumeButton *button);
 
 G_END_DECLS;
 


More information about the Xfce4-commits mailing list