[gtk+] gtk: Add symbolic property for GtkVolumeButton



commit 23c1d1cbc99f927a78fb03665c7fd74ef7801611
Author: Bastien Nocera <hadess hadess net>
Date:   Fri Dec 10 15:05:50 2010 +0000

    gtk: Add symbolic property for GtkVolumeButton
    
    When the application prefers symbolic icons, avoids
    having to reimplement the button in the software itself.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=636969

 gtk/gtkvolumebutton.c |  104 ++++++++++++++++++++++++++++++++++++++++++++----
 1 files changed, 95 insertions(+), 9 deletions(-)
---
diff --git a/gtk/gtkvolumebutton.c b/gtk/gtkvolumebutton.c
index a9c8703..639688f 100644
--- a/gtk/gtkvolumebutton.c
+++ b/gtk/gtkvolumebutton.c
@@ -47,6 +47,28 @@
 
 #define EPSILON (1e-10)
 
+const char * const icons[] =
+{
+  "audio-volume-muted",
+  "audio-volume-high",
+  "audio-volume-low",
+  "audio-volume-medium",
+  NULL
+};
+const char * const icons_symbolic[] =
+{
+  "audio-volume-muted-symbolic",
+  "audio-volume-high-symbolic",
+  "audio-volume-low-symbolic",
+  "audio-volume-medium-symbolic",
+  NULL
+};
+
+enum
+{
+  PROP_0,
+  PROP_SYMBOLIC
+};
 
 static gboolean	cb_query_tooltip (GtkWidget       *button,
                                   gint             x,
@@ -61,8 +83,79 @@ static void	cb_value_changed (GtkVolumeButton *button,
 G_DEFINE_TYPE (GtkVolumeButton, gtk_volume_button, GTK_TYPE_SCALE_BUTTON)
 
 static void
+gtk_volume_button_set_property (GObject       *object,
+				guint          prop_id,
+				const GValue  *value,
+				GParamSpec    *pspec)
+{
+  GtkScaleButton *button = GTK_SCALE_BUTTON (object);
+
+  switch (prop_id)
+    {
+    case PROP_SYMBOLIC:
+      if (g_value_get_boolean (value))
+        gtk_scale_button_set_icons (button, (const char **) icons_symbolic);
+      else
+	gtk_scale_button_set_icons (button, (const char **) icons);
+      break;
+    default:
+      G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
+      break;
+    }
+}
+
+static void
+gtk_volume_button_get_property (GObject     *object,
+			        guint        prop_id,
+			        GValue      *value,
+			        GParamSpec  *pspec)
+{
+  switch (prop_id)
+    {
+    case PROP_SYMBOLIC: {
+      char **icon_list;
+
+      g_object_get (object, "icons", &icon_list, NULL);
+      if (icon_list != NULL &&
+	  icon_list[0] != NULL &&
+      	  g_str_equal (icon_list[0], icons_symbolic[0]))
+        g_value_set_boolean (value, TRUE);
+      else
+        g_value_set_boolean (value, FALSE);
+      g_strfreev (icon_list);
+      break;
+    }
+    default:
+      G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
+      break;
+    }
+}
+
+static void
 gtk_volume_button_class_init (GtkVolumeButtonClass *klass)
 {
+  GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
+
+  gobject_class->set_property = gtk_volume_button_set_property;
+  gobject_class->get_property = gtk_volume_button_get_property;
+
+  /**
+   * GtkVolumeButton:use-symbolic:
+   *
+   * Whether to use symbolic icons as the icons. Note that
+   * if the symbolic icons are not available in your installed
+   * theme, then the normal (potentially colorful) icons will
+   * be used.
+   *
+   * Since: 3.0
+   */
+  g_object_class_install_property (gobject_class,
+                                   PROP_SYMBOLIC,
+                                   g_param_spec_boolean ("use-symbolic",
+                                                         P_("Use symbolic icons"),
+                                                         P_("Whether to use symbolic icons"),
+                                                         FALSE,
+                                                         G_PARAM_READWRITE));
 }
 
 static void
@@ -71,13 +164,6 @@ gtk_volume_button_init (GtkVolumeButton *button)
   GtkScaleButton *sbutton = GTK_SCALE_BUTTON (button);
   GtkAdjustment *adj;
   GtkWidget *minus_button, *plus_button;
-  const char *icons[] = {
-	"audio-volume-muted",
-	"audio-volume-high",
-	"audio-volume-low",
-	"audio-volume-medium",
-	NULL
-  };
 
   atk_object_set_name (gtk_widget_get_accessible (GTK_WIDGET (button)),
 		       _("Volume"));
@@ -102,14 +188,14 @@ gtk_volume_button_init (GtkVolumeButton *button)
 		       _("Increases the volume"));
   gtk_widget_set_tooltip_text (plus_button, _("Volume Up"));
 
-  gtk_scale_button_set_icons (sbutton, icons);
+  gtk_scale_button_set_icons (sbutton, (const char **) icons);
 
   adj = gtk_adjustment_new (0., 0., 1., 0.02, 0.2, 0.);
   g_object_set (G_OBJECT (button),
 		"adjustment", adj,
 		"size", GTK_ICON_SIZE_SMALL_TOOLBAR,
 		"has-tooltip", TRUE,
-	       	NULL);
+		NULL);
 
   g_signal_connect (G_OBJECT (button), "query-tooltip",
 		    G_CALLBACK (cb_query_tooltip), NULL);



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]