[gimp] app: try to guess a reasonable icon for devices



commit 1cc77abdf9dfe8e9ecd6b3d7f292915935268d50
Author: Michael Natterer <mitch gimp org>
Date:   Sat Feb 13 16:21:26 2010 +0100

    app: try to guess a reasonable icon for devices

 app/widgets/gimpdeviceinfo.c |   64 ++++++++++++++++++++++++++++++++++++++----
 1 files changed, 58 insertions(+), 6 deletions(-)
---
diff --git a/app/widgets/gimpdeviceinfo.c b/app/widgets/gimpdeviceinfo.c
index 10ef9cf..f91afcc 100644
--- a/app/widgets/gimpdeviceinfo.c
+++ b/app/widgets/gimpdeviceinfo.c
@@ -22,6 +22,7 @@
 #include <gtk/gtk.h>
 
 #include "libgimpconfig/gimpconfig.h"
+#include "libgimpwidgets/gimpwidgets.h"
 
 #include "widgets-types.h"
 
@@ -68,6 +69,8 @@ static void      gimp_device_info_get_property (GObject               *object,
                                                 GValue                *value,
                                                 GParamSpec            *pspec);
 
+static void      gimp_device_info_guess_icon   (GimpDeviceInfo        *info);
+
 
 G_DEFINE_TYPE (GimpDeviceInfo, gimp_device_info, GIMP_TYPE_CONTEXT)
 
@@ -79,8 +82,9 @@ static guint device_info_signals[LAST_SIGNAL] = { 0 };
 static void
 gimp_device_info_class_init (GimpDeviceInfoClass *klass)
 {
-  GObjectClass *object_class = G_OBJECT_CLASS (klass);
-  GParamSpec   *param_spec;
+  GObjectClass      *object_class   = G_OBJECT_CLASS (klass);
+  GimpViewableClass *viewable_class = GIMP_VIEWABLE_CLASS (klass);
+  GParamSpec        *param_spec;
 
   device_info_signals[CHANGED] =
     g_signal_new ("changed",
@@ -91,10 +95,12 @@ gimp_device_info_class_init (GimpDeviceInfoClass *klass)
                   gimp_marshal_VOID__VOID,
                   G_TYPE_NONE, 0);
 
-  object_class->constructor  = gimp_device_info_constructor;
-  object_class->finalize     = gimp_device_info_finalize;
-  object_class->set_property = gimp_device_info_set_property;
-  object_class->get_property = gimp_device_info_get_property;
+  object_class->constructor        = gimp_device_info_constructor;
+  object_class->finalize           = gimp_device_info_finalize;
+  object_class->set_property       = gimp_device_info_set_property;
+  object_class->get_property       = gimp_device_info_get_property;
+
+  viewable_class->default_stock_id = GIMP_STOCK_DEVICE_STATUS; /* FIXME */
 
   g_object_class_install_property (object_class, PROP_DEVICE,
                                    g_param_spec_object ("device",
@@ -151,6 +157,10 @@ gimp_device_info_init (GimpDeviceInfo *device_info)
   device_info->axes     = NULL;
   device_info->n_keys   = 0;
   device_info->keys     = NULL;
+
+  g_signal_connect (device_info, "notify::name",
+                    G_CALLBACK (gimp_device_info_guess_icon),
+                    NULL);
 }
 
 static GObject *
@@ -432,6 +442,48 @@ gimp_device_info_get_property (GObject    *object,
     }
 }
 
+static void
+gimp_device_info_guess_icon (GimpDeviceInfo *info)
+{
+  GimpViewable *viewable = GIMP_VIEWABLE (info);
+
+  if (gimp_object_get_name (viewable) &&
+      ! strcmp (gimp_viewable_get_stock_id (viewable),
+                GIMP_VIEWABLE_GET_CLASS (viewable)->default_stock_id))
+    {
+      const gchar *stock_id = NULL;
+      gchar       *down     = g_ascii_strdown (gimp_object_get_name (viewable),
+                                               -1);
+
+      if (strstr (down, "eraser"))
+        {
+          stock_id = GIMP_STOCK_TOOL_ERASER;
+        }
+      else if (strstr (down, "pen"))
+        {
+          stock_id = GIMP_STOCK_TOOL_PAINTBRUSH;
+        }
+      else if (strstr (down, "airbrush"))
+        {
+          stock_id = GIMP_STOCK_TOOL_AIRBRUSH;
+        }
+      else if (strstr (down, "cursor")   ||
+               strstr (down, "mouse")    ||
+               strstr (down, "pointer")  ||
+               strstr (down, "touchpad") ||
+               strstr (down, "trackpoint"))
+        {
+          stock_id = GIMP_STOCK_CURSOR;
+        }
+
+      g_free (down);
+
+      if (stock_id)
+        gimp_viewable_set_stock_id (viewable, stock_id);
+    }
+}
+
+
 
 /*  public functions  */
 



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