[Xfce4-commits] <xfce4-mixer:master> Avoid the deprecated GtkTooltips API and let XfceVolumeButton handle tooltips

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


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

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

    Avoid the deprecated GtkTooltips API and let XfceVolumeButton handle tooltips

 NEWS                              |    2 +
 panel-plugin/xfce-mixer-plugin.c  |   21 +----------
 panel-plugin/xfce-volume-button.c |   72 +++++++++++++++++++++++++++++++++++++
 panel-plugin/xfce-volume-button.h |    3 ++
 4 files changed, 78 insertions(+), 20 deletions(-)

diff --git a/NEWS b/NEWS
index 01cfa15..c056db7 100644
--- a/NEWS
+++ b/NEWS
@@ -14,6 +14,8 @@
   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).
+- Avoid the deprecated GtkTooltips API and let XfceVolumeButton handle
+  tooltips.
 
 
 4.8.0
diff --git a/panel-plugin/xfce-mixer-plugin.c b/panel-plugin/xfce-mixer-plugin.c
index ef4d49f..5f367ea 100644
--- a/panel-plugin/xfce-mixer-plugin.c
+++ b/panel-plugin/xfce-mixer-plugin.c
@@ -93,9 +93,6 @@ struct _XfceMixerPlugin
   /* Parent type */
   XfcePanelPlugin __parent__;
 
-  /* Tooltips structure */
-  GtkTooltips     *tooltips;
-
   /* Sound card being used */
   GstElement      *card;
   gchar           *card_name;
@@ -199,10 +196,6 @@ xfce_mixer_plugin_init (XfceMixerPlugin *mixer_plugin)
   /* Initialize the mixer library */
   xfce_mixer_init ();
 
-  /* Allocate a tooltips structure */
-  mixer_plugin->tooltips = gtk_tooltips_new ();
-  gtk_tooltips_set_delay (mixer_plugin->tooltips, 10);
-
   /* Create container for the plugin */
   mixer_plugin->hvbox = GTK_WIDGET (xfce_hvbox_new (GTK_ORIENTATION_HORIZONTAL, FALSE, 0));
   xfce_panel_plugin_add_action_widget (XFCE_PANEL_PLUGIN (mixer_plugin), mixer_plugin->hvbox);
@@ -523,7 +516,6 @@ static void
 xfce_mixer_plugin_volume_changed (XfceMixerPlugin  *mixer_plugin,
                                   gdouble           volume)
 {
-  gchar *tip_text;
   gint  *volumes;
   gint   volume_range;
   gint   new_volume;
@@ -537,11 +529,6 @@ xfce_mixer_plugin_volume_changed (XfceMixerPlugin  *mixer_plugin,
   mixer_plugin->ignore_bus_messages = TRUE;
 #endif
 
-  /* Set tooltip (e.g. 'Master: 50%') */
-  tip_text = g_strdup_printf (_("%s: %i%%"), mixer_plugin->track_label, (gint) (volume * 100));
-  gtk_tooltips_set_tip (mixer_plugin->tooltips, mixer_plugin->button, tip_text, "test");
-  g_free (tip_text);
-
   /* Allocate array for track volumes */
   volumes = g_new (gint, mixer_plugin->track->num_channels);
 
@@ -606,7 +593,6 @@ xfce_mixer_plugin_update_track (XfceMixerPlugin *mixer_plugin)
   gint               volume_range;
   gdouble            volume;
   gint              *volumes;
-  gchar             *tip_text;
 
   g_return_if_fail (IS_XFCE_MIXER_PLUGIN (mixer_plugin));
 
@@ -614,7 +600,6 @@ xfce_mixer_plugin_update_track (XfceMixerPlugin *mixer_plugin)
   if (!GST_IS_MIXER (mixer_plugin->card) || !GST_IS_MIXER_TRACK (mixer_plugin->track))
     {
       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;
     }
 
@@ -628,11 +613,6 @@ xfce_mixer_plugin_update_track (XfceMixerPlugin *mixer_plugin)
   /* Determine maximum value as double between 0.0 and 1.0 */
   volume = ((gdouble) xfce_mixer_get_max_volume (volumes, mixer_plugin->track->num_channels) - mixer_plugin->track->min_volume) / volume_range;
 
-  /* Set tooltip (e.g. 'Master: 50%') */
-  tip_text = g_strdup_printf (_("%s: %i%%"), mixer_plugin->track_label, (gint) (volume * 100));
-  gtk_tooltips_set_tip (mixer_plugin->tooltips, mixer_plugin->button, tip_text, "test");
-  g_free (tip_text);
-
   /* Determine track type */
   track_type = xfce_mixer_track_type_new (mixer_plugin->track);
 
@@ -645,6 +625,7 @@ xfce_mixer_plugin_update_track (XfceMixerPlugin *mixer_plugin)
   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);
+  xfce_volume_button_set_track_label (XFCE_VOLUME_BUTTON (mixer_plugin->button), mixer_plugin->track_label);
 
   /* Free volume array */
   g_free (volumes);
diff --git a/panel-plugin/xfce-volume-button.c b/panel-plugin/xfce-volume-button.c
index 3b5d90e..ca2236b 100644
--- a/panel-plugin/xfce-volume-button.c
+++ b/panel-plugin/xfce-volume-button.c
@@ -46,6 +46,7 @@
 enum
 {
   PROP_0,
+  PROP_TRACK_LABEL,
   PROP_IS_CONFIGURED,
   N_PROPERTIES,
 };
@@ -137,6 +138,9 @@ struct _XfceVolumeButton
   /* Array of preloaded icons */
   GdkPixbuf **pixbufs;
 
+  /* Track label used in tooltip */
+  gchar      *track_label;
+
   /* Whether the button is configured */
   gboolean    is_configured;
 
@@ -197,6 +201,14 @@ xfce_volume_button_class_init (XfceVolumeButtonClass *klass)
   klass->mute_toggled = xfce_volume_button_mute_toggled;
 
   g_object_class_install_property (gobject_class,
+                                   PROP_TRACK_LABEL,
+                                   g_param_spec_string ("track-label",
+                                                        "track-label",
+                                                        "track-label",
+                                                        "Unknown",
+                                                        G_PARAM_READABLE | G_PARAM_WRITABLE));
+
+  g_object_class_install_property (gobject_class,
                                    PROP_IS_CONFIGURED,
                                    g_param_spec_boolean ("is-configured",
                                                          "is-configured",
@@ -232,6 +244,8 @@ xfce_volume_button_class_init (XfceVolumeButtonClass *klass)
 static void
 xfce_volume_button_init (XfceVolumeButton *button)
 {
+  button->track_label = NULL;
+
   button->is_configured = FALSE;
 
   /* By default we expect the button not to be muted */
@@ -289,6 +303,12 @@ xfce_volume_button_finalize (GObject *object)
       g_object_unref (G_OBJECT (button->pixbufs[i]));
   g_free (button->pixbufs);
 
+  if (button->track_label != NULL)
+    {
+      g_free (button->track_label);
+      button->track_label = NULL;
+    }
+
   (*G_OBJECT_CLASS (xfce_volume_button_parent_class)->finalize) (object);
 }
 
@@ -304,6 +324,12 @@ static void xfce_volume_button_set_property (GObject      *object,
 
   switch (prop_id)
     {
+      case PROP_TRACK_LABEL:
+        g_free (button->track_label);
+        button->track_label = g_value_dup_string (value);
+        if (button->is_configured)
+          xfce_volume_button_update (button);
+        break;
       case PROP_IS_CONFIGURED:
         is_configured = g_value_get_boolean (value);
         if (button->is_configured != is_configured)
@@ -329,6 +355,9 @@ static void xfce_volume_button_get_property (GObject      *object,
 
   switch (prop_id)
     {
+      case PROP_TRACK_LABEL:
+        g_value_set_string (value, button->track_label);
+        break;
       case PROP_IS_CONFIGURED:
         g_value_set_boolean (value, button->is_configured);
         break;
@@ -497,6 +526,7 @@ xfce_volume_button_update (XfceVolumeButton *button)
   gdouble    value;
   gdouble    range;
   guint      i;
+  gchar     *tip_text;
 
   g_return_if_fail (IS_XFCE_VOLUME_BUTTON (button));
 
@@ -525,6 +555,17 @@ xfce_volume_button_update (XfceVolumeButton *button)
   /* Update the button icon */
   if (G_LIKELY (pixbuf != NULL))
     xfce_panel_image_set_from_pixbuf (XFCE_PANEL_IMAGE (button->image), pixbuf);
+
+  /* Update the tooltip */
+  if (!button->is_configured)
+    gtk_widget_set_tooltip_text (GTK_WIDGET (button), _("No valid device and/or element."));
+  else
+    {
+      /* Set tooltip (e.g. 'Master: 50%') */
+      tip_text = g_strdup_printf (_("%s: %i%%"), button->track_label, (gint) value);
+      gtk_widget_set_tooltip_text (GTK_WIDGET (button), tip_text);
+      g_free (tip_text);
+    }
 }
 
 
@@ -621,6 +662,36 @@ xfce_volume_button_mute_toggled (XfceVolumeButton *button,
 
 
 void
+xfce_volume_button_set_track_label (XfceVolumeButton *button,
+                                    const gchar      *track_label)
+{
+  GValue value = G_VALUE_INIT;
+
+  g_return_if_fail (IS_XFCE_VOLUME_BUTTON (button));
+
+  g_value_init (&value, G_TYPE_STRING);
+  g_value_set_string (&value, track_label);
+  g_object_set_property (G_OBJECT (button), "track-label", &value);
+}
+
+
+
+gchar*
+xfce_volume_button_get_track_label (XfceVolumeButton *button)
+{
+  GValue value = G_VALUE_INIT;
+
+  g_return_val_if_fail (IS_XFCE_VOLUME_BUTTON (button), NULL);
+
+  g_value_init (&value, G_TYPE_STRING);
+  g_object_get_property (G_OBJECT (button), "track-label", &value);
+
+  return g_value_dup_string (&value);
+}
+
+
+
+void
 xfce_volume_button_set_is_configured (XfceVolumeButton *button,
                                       gboolean          is_configured)
 {
@@ -635,6 +706,7 @@ xfce_volume_button_set_is_configured (XfceVolumeButton *button,
 
 
 
+
 gboolean
 xfce_volume_button_get_is_configured (XfceVolumeButton *button)
 {
diff --git a/panel-plugin/xfce-volume-button.h b/panel-plugin/xfce-volume-button.h
index a92f0e7..eb10f6e 100644
--- a/panel-plugin/xfce-volume-button.h
+++ b/panel-plugin/xfce-volume-button.h
@@ -47,6 +47,9 @@ void       xfce_volume_button_set_volume        (XfceVolumeButton *button,
 void       xfce_volume_button_update            (XfceVolumeButton *button);
 void       xfce_volume_button_set_icon_size     (XfceVolumeButton *button,
                                                  gint              size);
+void       xfce_volume_button_set_track_label   (XfceVolumeButton *button,
+                                                 const gchar      *track_label);
+gchar     *xfce_volume_button_get_track_label   (XfceVolumeButton *button);
 void       xfce_volume_button_set_is_configured (XfceVolumeButton *button,
                                                  gboolean          is_configured);
 gboolean   xfce_volume_button_get_is_configured (XfceVolumeButton *button);


More information about the Xfce4-commits mailing list