[glade] * gladeui/glade-widget-adaptor.c: Added logic to re-composite the widget icon with a deprecation



commit fe035f65ddc2e54878917515a4fec7a85b8da6de
Author: Tristan Van Berkom <tristan van berkom gmail com>
Date:   Thu Mar 10 01:21:11 2011 +0900

    	* gladeui/glade-widget-adaptor.c: Added logic to re-composite the widget icon
    	  with a deprecation overlay pixbuf if a widget is deprecated.
    
    	* data/icons/Makefile.am, icons: Added deprecation overlay graphics
    	  contributed by Florent Thévenet.

 ChangeLog                       |   16 +++++--
 data/icons/Makefile.am          |    6 ++-
 data/icons/deprecated-16x16.png |  Bin 0 -> 437 bytes
 data/icons/deprecated-22x22.png |  Bin 0 -> 671 bytes
 gladeui/glade-palette.c         |    9 +---
 gladeui/glade-widget-adaptor.c  |  100 +++++++++++++++++++++++++++++++++++++++
 6 files changed, 119 insertions(+), 12 deletions(-)
---
diff --git a/ChangeLog b/ChangeLog
index 5c82e51..7530f18 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,9 +1,17 @@
+2011-03-09  Tristan Van Berkom <tristanvb openismus com>
+
+	* gladeui/glade-widget-adaptor.c: Added logic to re-composite the widget icon
+	  with a deprecation overlay pixbuf if a widget is deprecated.
+
+	* data/icons/Makefile.am, icons: Added deprecation overlay graphics
+	  contributed by Florent Thévenet.
+
 2011-03-09  Juan Pablo Ugarte <juanpablougarte gmail com>
 
-  * gladeui/glade-project.[ch]
-    o Fixed function declaration and indentation
-    o Call glade_project_notify_row_has_child() after deleting the object from the model
-      otherwise the GladeProject views do not update properly.
+	* gladeui/glade-project.[ch]
+	  o Fixed function declaration and indentation
+	  o Call glade_project_notify_row_has_child() after deleting the object from the model
+	    otherwise the GladeProject views do not update properly.
 
 2011-03-09  Tristan Van Berkom <tristanvb openismus com>
 
diff --git a/data/icons/Makefile.am b/data/icons/Makefile.am
index 7122c17..c660de3 100644
--- a/data/icons/Makefile.am
+++ b/data/icons/Makefile.am
@@ -17,7 +17,11 @@ update-icon-cache:
 
 
 pixmapsdir = $(pkgdatadir)/pixmaps
-pixmaps_DATA = selector.png devhelp.png plus.png atk.png drag-resize.png fixed-bg.png placeholder.png
+pixmaps_DATA = selector.png devhelp.png \
+	plus.png atk.png drag-resize.png \
+	fixed-bg.png placeholder.png \
+	deprecated-16x16.png \
+	deprecated-22x22.png
 
 
 EXTRA_DIST = $(pixmaps_DATA) glade.ico
diff --git a/data/icons/deprecated-16x16.png b/data/icons/deprecated-16x16.png
new file mode 100644
index 0000000..d5cc47a
Binary files /dev/null and b/data/icons/deprecated-16x16.png differ
diff --git a/data/icons/deprecated-22x22.png b/data/icons/deprecated-22x22.png
new file mode 100644
index 0000000..26456e6
Binary files /dev/null and b/data/icons/deprecated-22x22.png differ
diff --git a/gladeui/glade-palette.c b/gladeui/glade-palette.c
index 1f5efa9..e9396fe 100644
--- a/gladeui/glade-palette.c
+++ b/gladeui/glade-palette.c
@@ -121,13 +121,8 @@ palette_item_refresh_cb (GladePalette *palette,
       gtk_widget_set_sensitive (GTK_WIDGET (item),
                                 !(support & GLADE_SUPPORT_MISMATCH));
 
-      if (support & GLADE_SUPPORT_DEPRECATED)
-        /* XXX Todo, draw a cross overlaying the widget icon */
-        gtk_tool_button_set_stock_id (GTK_TOOL_BUTTON (item),
-                                      GTK_STOCK_DIALOG_WARNING);
-      else
-        gtk_tool_button_set_icon_name (GTK_TOOL_BUTTON (item),
-                                       glade_widget_adaptor_get_icon_name (adaptor));
+      gtk_tool_button_set_icon_name (GTK_TOOL_BUTTON (item),
+				     glade_widget_adaptor_get_icon_name (adaptor));
 
       /* prepend widget title */
       text = g_strdup_printf ("%s: %s", glade_widget_adaptor_get_title (adaptor), warning);
diff --git a/gladeui/glade-widget-adaptor.c b/gladeui/glade-widget-adaptor.c
index f9a8aee..1bbff3c 100644
--- a/gladeui/glade-widget-adaptor.c
+++ b/gladeui/glade-widget-adaptor.c
@@ -2327,6 +2327,97 @@ generate_type (const char *name, const char *parent_name)
   return retval;
 }
 
+static gchar *
+generate_deprecated_icon (const gchar *icon_name)
+{
+  static GdkPixbuf *deprecated_pixbuf[2] = { NULL, NULL };
+  GError        *error = NULL;
+  GdkPixbuf     *orig_pixbuf[2];
+  gchar         *deprecated;
+
+  if (strncmp (icon_name, "deprecated-", strlen ("deprecated-")) == 0)
+    return g_strdup (icon_name);
+
+  /* Get deprecated graphics */
+  if (!deprecated_pixbuf[0])
+    {
+      gchar *filename;
+
+      filename = g_build_filename (glade_app_get_pixmaps_dir (), "deprecated-16x16.png", NULL);
+
+      if ((deprecated_pixbuf[0] = gdk_pixbuf_new_from_file (filename, &error)) == NULL)
+	{
+	  g_warning ("Unable to render deprecated icon: %s", error->message);
+	  error = (g_error_free (error), NULL);
+	}
+      g_free (filename);
+
+      filename = g_build_filename (glade_app_get_pixmaps_dir (), "deprecated-22x22.png", NULL);
+
+      if ((deprecated_pixbuf[1] = gdk_pixbuf_new_from_file (filename, &error)) == NULL)
+	{
+	  g_warning ("Unable to render deprecated icon: %s", error->message);
+	  error = (g_error_free (error), NULL);
+	}
+      g_free (filename);
+    }
+
+  if (!deprecated_pixbuf[0] || !deprecated_pixbuf[1])
+      return NULL;
+
+  /* Load pixbuf's for the current icons */
+  if ((orig_pixbuf[0] = 
+       gtk_icon_theme_load_icon (gtk_icon_theme_get_default (),
+				 icon_name, 16, 0, &error)) == NULL)
+    {
+      g_warning ("Unable to render icon %s at size 16: %s", icon_name, error->message);
+      error = (g_error_free (error), NULL);
+    }
+  else
+    {
+      GdkPixbuf *tmp = gdk_pixbuf_copy (orig_pixbuf[0]);
+      g_object_unref (orig_pixbuf[0]);
+      orig_pixbuf[0] = tmp;
+    }
+
+  if ((orig_pixbuf[1] = 
+       gtk_icon_theme_load_icon (gtk_icon_theme_get_default (),
+				 icon_name, 22, 0, &error)) == NULL)
+    {
+      g_warning ("Unable to render icon %s at size 22: %s", icon_name, error->message);
+      error = (g_error_free (error), NULL);
+    }
+  else
+    {
+      GdkPixbuf *tmp = gdk_pixbuf_copy (orig_pixbuf[1]);
+      g_object_unref (orig_pixbuf[1]);
+      orig_pixbuf[1] = tmp;
+    }
+
+  deprecated = g_strdup_printf ("deprecated-%s", icon_name);
+
+  if (!gtk_icon_theme_has_icon (gtk_icon_theme_get_default (), deprecated))
+    {
+      if (orig_pixbuf[0])
+	gdk_pixbuf_composite (deprecated_pixbuf[0], orig_pixbuf[0],
+				0, 0, 16, 16, 0, 0, 1, 1, GDK_INTERP_NEAREST, 255);
+
+      if (orig_pixbuf[1])
+	gdk_pixbuf_composite (deprecated_pixbuf[1], orig_pixbuf[1],
+				0, 0, 22, 22, 0, 0, 1, 1, GDK_INTERP_NEAREST, 255);
+
+      gtk_icon_theme_add_builtin_icon (deprecated, 16, orig_pixbuf[0]);
+      gtk_icon_theme_add_builtin_icon (deprecated, 22, orig_pixbuf[1]);
+    }
+
+  if (orig_pixbuf[0])
+    g_object_unref (orig_pixbuf[0]);
+
+  if (orig_pixbuf[1])
+    g_object_unref (orig_pixbuf[1]);
+
+  return deprecated;
+}
 
 /**
  * glade_widget_adaptor_from_catalog:
@@ -2553,6 +2644,15 @@ glade_widget_adaptor_from_catalog (GladeCatalog * catalog,
   gwa_extend_with_node (adaptor, class_node, module,
                         glade_catalog_get_domain (catalog));
 
+
+  if (GWA_DEPRECATED (adaptor))
+    {
+      gchar *deprecated_icon = generate_deprecated_icon (adaptor->priv->icon_name);
+
+      g_free (adaptor->priv->icon_name);
+      adaptor->priv->icon_name = deprecated_icon;
+    }
+
   /* Set default weight on properties */
   for (parent_type = adaptor->priv->type;
        parent_type != 0; parent_type = g_type_parent (parent_type))



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