[evolution] Kill Evolution's icon cache once and for all.



commit f11f1c477dfbdbe666ad5627ad44ac95bd7c816f
Author: Matthew Barnes <mbarnes redhat com>
Date:   Thu Nov 19 14:49:09 2009 -0500

    Kill Evolution's icon cache once and for all.
    
    GTK+ already does this.  Eliminates e_icon_factory_init() and
    e_icon_factory_shutdown().

 art/Makefile.am                               |    2 -
 art/broken-image-16.xpm                       |   61 -------
 art/broken-image-24.xpm                       |  169 ------------------
 calendar/gui/alarm-notify/notify-main.c       |    3 -
 configure.ac                                  |   36 +----
 doc/reference/shell/tmpl/e-icon-factory.sgml  |   14 --
 doc/reference/shell/tmpl/e-shell-content.sgml |    5 +
 doc/reference/shell/tmpl/eshell-unused.sgml   |   12 ++
 e-util/e-icon-factory.c                       |  234 ++-----------------------
 e-util/e-icon-factory.h                       |    2 -
 shell/Makefile.am                             |    1 +
 shell/main.c                                  |    7 +-
 12 files changed, 42 insertions(+), 504 deletions(-)
---
diff --git a/art/Makefile.am b/art/Makefile.am
index 1404f37..9c39dbf 100644
--- a/art/Makefile.am
+++ b/art/Makefile.am
@@ -7,8 +7,6 @@ EXTRA_DIST = 				\
 	ChangeLog			\
 	ChangeLog.pre-1-4		\
 	README				\
-	broken-image-16.xpm		\
-	broken-image-24.xpm		\
 	empty.xpm			\
 	jump.xpm			\
 	$(images_DATA)
diff --git a/calendar/gui/alarm-notify/notify-main.c b/calendar/gui/alarm-notify/notify-main.c
index e001409..71fee19 100644
--- a/calendar/gui/alarm-notify/notify-main.c
+++ b/calendar/gui/alarm-notify/notify-main.c
@@ -35,7 +35,6 @@
 #include <libedataserver/e-source.h>
 #include <libedataserverui/e-passwords.h>
 
-#include "e-util/e-icon-factory.h"
 #include "e-util/e-util-private.h"
 #include "alarm.h"
 #include "alarm-queue.h"
@@ -61,8 +60,6 @@ main (gint argc, gchar **argv)
 	if (unique_app_is_running (app))
 		goto exit;
 
-	e_icon_factory_init ();
-
 	alarm_notify_service = alarm_notify_new ();
 
 	/* FIXME Ideally we should not use camel libraries in calendar,
diff --git a/configure.ac b/configure.ac
index 56886b9..51e3e02 100644
--- a/configure.ac
+++ b/configure.ac
@@ -1394,9 +1394,6 @@ AC_SUBST(privdatadir)
 privincludedir='${includedir}'/evolution-$BASE_VERSION
 AC_SUBST(privincludedir)
 
-componentdir="$privlibdir/components"
-AC_SUBST(componentdir)
-
 moduledir="$privlibdir/modules"
 AC_SUBST(moduledir)
 
@@ -1406,12 +1403,12 @@ AC_SUBST(uidir)
 evolutionhelpdir="$privdatadir/help"
 AC_SUBST(evolutionhelpdir)
 
+icondir="$privdatadir/icons"
+AC_SUBST(icondir)
+
 imagesdir="$privdatadir/images"
 AC_SUBST(imagesdir)
 
-images16dir="$privdatadir/images/16x16"
-AC_SUBST(images16dir)
-
 if test "$os_win32" = yes; then
 	dnl On Win32 there is no "rpath" mechanism. We install the private
 	dnl shared libraries in $libdir, meaning the DLLs will actually be in
@@ -1419,37 +1416,10 @@ if test "$os_win32" = yes; then
 	dnl also means gnome_win32_get_prefixes() will be able to deduce the
 	dnl installation folder correctly.
 	privsolibdir=$libdir
-	dnl On Win32, use a relative path to the executables in .server
-	dnl files. The path is relative to the folder where the .server file
-	dnl is, i.e. $prefix/lib/bonobo/servers.
-	bindir_in_server_file=../../../bin
-	privlibexecdir_in_server_file=../../../libexec/evolution/$BASE_VERSION
-	componentdir_in_server_file=../../../lib/evolution/$BASE_VERSION/components
 else
 	privsolibdir=$privlibdir
-	bindir_in_server_file="$bindir"
-	privlibexecdir_in_server_file='${libexecdir}'/evolution/$BASE_VERSION
-	componentdir_in_server_file="$componentdir"
 fi
 AC_SUBST(privsolibdir)
-AC_SUBST(bindir_in_server_file)
-AC_SUBST(privlibexecdir_in_server_file)
-AC_SUBST(componentdir_in_server_file)
-
-dnl images18dir="$privdatadir/images/18x18"
-dnl AC_SUBST(images18dir)
-
-dnl images20dir="$privdatadir/images/20x20"
-dnl AC_SUBST(images20dir)
-
-dnl images24dir="$privdatadir/images/24x24"
-dnl AC_SUBST(images24dir)
-
-dnl images32dir="$privdatadir/images/32x32"
-dnl AC_SUBST(images32dir)
-
-images48dir="$privdatadir/images/48x48"
-AC_SUBST(images48dir)
 
 soundsdir="$privdatadir/sounds"
 AC_SUBST(soundsdir)
diff --git a/doc/reference/shell/tmpl/e-icon-factory.sgml b/doc/reference/shell/tmpl/e-icon-factory.sgml
index 66d8008..dc289c9 100644
--- a/doc/reference/shell/tmpl/e-icon-factory.sgml
+++ b/doc/reference/shell/tmpl/e-icon-factory.sgml
@@ -17,20 +17,6 @@ Icon Functions (Legacy)
 <!-- ##### SECTION Stability_Level ##### -->
 
 
-<!-- ##### FUNCTION e_icon_factory_init ##### -->
-<para>
-
-</para>
-
-
-
-<!-- ##### FUNCTION e_icon_factory_shutdown ##### -->
-<para>
-
-</para>
-
-
-
 <!-- ##### FUNCTION e_icon_factory_get_icon_filename ##### -->
 <para>
 
diff --git a/doc/reference/shell/tmpl/e-shell-content.sgml b/doc/reference/shell/tmpl/e-shell-content.sgml
index 2ffe528..fb17dd8 100644
--- a/doc/reference/shell/tmpl/e-shell-content.sgml
+++ b/doc/reference/shell/tmpl/e-shell-content.sgml
@@ -63,6 +63,11 @@ EShellContent
 
 </para>
 
+<!-- ##### ARG EShellContent:search-radio-action ##### -->
+<para>
+
+</para>
+
 <!-- ##### ARG EShellContent:search-rule ##### -->
 <para>
 
diff --git a/doc/reference/shell/tmpl/eshell-unused.sgml b/doc/reference/shell/tmpl/eshell-unused.sgml
index dd0c06f..0928b8d 100644
--- a/doc/reference/shell/tmpl/eshell-unused.sgml
+++ b/doc/reference/shell/tmpl/eshell-unused.sgml
@@ -1858,6 +1858,18 @@ intelligent
 @revision: 
 @Returns: 
 
+<!-- ##### FUNCTION e_icon_factory_init ##### -->
+<para>
+
+</para>
+
+
+<!-- ##### FUNCTION e_icon_factory_shutdown ##### -->
+<para>
+
+</para>
+
+
 <!-- ##### FUNCTION e_shell_backend_get_filename ##### -->
 <para>
 
diff --git a/e-util/e-icon-factory.c b/e-util/e-icon-factory.c
index cdbf39c..411deea 100644
--- a/e-util/e-icon-factory.c
+++ b/e-util/e-icon-factory.c
@@ -38,200 +38,16 @@
 #include "e-icon-factory.h"
 #include "e-util-private.h"
 
-#include "art/broken-image-16.xpm"
-#include "art/broken-image-24.xpm"
-
 #define d(x)
 
-typedef struct {
-	gchar *name;
-	GdkPixbuf *pixbuf;
-} Icon;
-
-static GdkPixbuf *broken16_pixbuf = NULL;
-static GdkPixbuf *broken24_pixbuf = NULL;
-
-static GHashTable *name_to_icon = NULL;
-static GtkIconTheme *icon_theme = NULL;
-static GStaticMutex mutex = G_STATIC_MUTEX_INIT;
-
-/* Note: takes ownership of the pixbufs (eg. does not ref them) */
-static Icon *
-icon_new (const gchar *name, GdkPixbuf *pixbuf)
-{
-	Icon *icon;
-
-	icon = g_slice_new (Icon);
-	icon->name = g_strdup (name);
-	icon->pixbuf = pixbuf;
-
-	return icon;
-}
-
-static void
-icon_free (Icon *icon)
-{
-	g_free (icon->name);
-	if (icon->pixbuf)
-		g_object_unref (icon->pixbuf);
-	g_slice_free (Icon, icon);
-}
-
-static Icon *
-load_icon (const gchar *icon_key, const gchar *icon_name, gint size, gint scale)
-{
-	GdkPixbuf *pixbuf, *unscaled = NULL;
-	gchar *basename, *filename = NULL;
-
-	if (g_path_is_absolute (icon_name))
-		filename = g_strdup (icon_name);
-	else {
-		GtkIconInfo *icon_info;
-
-		icon_info = gtk_icon_theme_lookup_icon (
-			icon_theme, icon_name, size, 0);
-		if (icon_info != NULL) {
-			filename = g_strdup (
-				gtk_icon_info_get_filename (icon_info));
-			gtk_icon_info_free (icon_info);
-		}
-	}
-
-	if (!filename || !(unscaled = gdk_pixbuf_new_from_file (filename, NULL))) {
-		if (scale) {
-			const gchar *dent;
-			gint width;
-			GDir *dir;
-			gchar *x;
-
-			if (!(dir = g_dir_open (EVOLUTION_ICONSDIR, 0, NULL))) {
-				goto done;
-			}
-
-			/* scan icon directories looking for an icon with a size >= the size we need. */
-			while ((dent = g_dir_read_name (dir))) {
-				if (!(dent[0] >= '1' && dent[0] <= '9'))
-					continue;
-
-				if (((width = strtol (dent, &x, 10)) < size) || *x != 'x')
-					continue;
-
-				if (((strtol (x + 1, &x, 10)) != width) || *x != '\0')
-					continue;
-
-				/* if the icon exists in this directory, we can [use/scale] it */
-				g_free (filename);
-				basename = g_strconcat (icon_name, ".png", NULL);
-				filename = g_build_filename (EVOLUTION_ICONSDIR,
-							     dent,
-							     basename,
-							     NULL);
-				g_free (basename);
-				if ((unscaled = gdk_pixbuf_new_from_file (filename, NULL)))
-					break;
-			}
-
-			g_dir_close (dir);
-		} else {
-			gchar *size_x_size;
-
-			size_x_size = g_strdup_printf ("%dx%d", size, size);
-			basename = g_strconcat (icon_name, ".png", NULL);
-			g_free (filename);
-			filename = g_build_filename (EVOLUTION_ICONSDIR,
-						     size_x_size,
-						     basename,
-						     NULL);
-			g_free (basename);
-			g_free (size_x_size);
-			unscaled = gdk_pixbuf_new_from_file (filename, NULL);
-		}
-	}
-
- done:
-
-	g_free (filename);
-	if (unscaled != NULL) {
-		if (gdk_pixbuf_get_width(unscaled) != size || gdk_pixbuf_get_height(unscaled) != size)
-		{
-			pixbuf = e_icon_factory_pixbuf_scale (unscaled, size, size);
-			g_object_unref (unscaled);
-		} else
-			pixbuf = unscaled;
-	} else {
-		pixbuf = NULL;
-	}
-
-	return icon_new (icon_key, pixbuf);
-}
-
-static void
-icon_theme_changed_cb (GtkIconTheme *icon_theme, gpointer user_data)
-{
-	g_hash_table_remove_all (name_to_icon);
-}
-
-/**
- * e_icon_factory_init:
- *
- * Initialises the icon factory.
- **/
-void
-e_icon_factory_init (void)
-{
-	gchar *path;
-
-	if (name_to_icon != NULL)
-		return;
-
-	name_to_icon = g_hash_table_new_full (
-		g_str_hash, g_str_equal,
-		(GDestroyNotify) NULL,
-		(GDestroyNotify) icon_free);
-
-	icon_theme = gtk_icon_theme_get_default ();
-	path = g_build_filename (EVOLUTION_DATADIR,
-				 "evolution",
-				 BASE_VERSION,
-				 "icons",
-				 NULL);
-	gtk_icon_theme_append_search_path (icon_theme, path);
-	g_free (path);
-	g_signal_connect (
-		icon_theme, "changed",
-		G_CALLBACK (icon_theme_changed_cb), NULL);
-
-	broken16_pixbuf = gdk_pixbuf_new_from_xpm_data (
-		(const gchar **) broken_image_16_xpm);
-	broken24_pixbuf = gdk_pixbuf_new_from_xpm_data (
-		(const gchar **) broken_image_24_xpm);
-}
-
-/**
- * e_icon_factory_shutdown:
- *
- * Shuts down the icon factory (cleans up all cached icons, etc).
- **/
-void
-e_icon_factory_shutdown (void)
-{
-	if (name_to_icon == NULL)
-		return;
-
-	g_hash_table_destroy (name_to_icon);
-	g_object_unref (broken16_pixbuf);
-	g_object_unref (broken24_pixbuf);
-	name_to_icon = NULL;
-}
-
 /**
  * e_icon_factory_get_icon_filename:
  * @icon_name: name of the icon
- * @size: size of the icon
+ * @icon_size: size of the icon
  *
- * Looks up the icon to use based on name and size.
+ * Returns the filename of the requested icon in the default icon theme.
  *
- * Returns the requested icon pixbuf.
+ * Returns: the filename of the requested icon
  **/
 gchar *
 e_icon_factory_get_icon_filename (const gchar *icon_name,
@@ -265,51 +81,35 @@ e_icon_factory_get_icon_filename (const gchar *icon_name,
  * @icon_name: name of the icon
  * @icon_size: size of the icon
  *
- * Returns the specified icon of the requested size (may perform
- * scaling to achieve this). If @icon_name is a full path, that file
- * is used directly. Otherwise it is looked up in the user's current
- * icon theme. If the icon cannot be found in the icon theme, it falls
- * back to loading the requested icon from Evolution's icon set
- * installed from the art/ srcdir. If even that fails to find the
- * requested icon, then a "broken-image" icon is returned.
+ * Loads the requested icon from the default icon theme and renders it
+ * to a pixbuf.
+ *
+ * Returns: the rendered icon
  **/
 GdkPixbuf *
 e_icon_factory_get_icon (const gchar *icon_name,
                          GtkIconSize icon_size)
 {
+	GtkIconTheme *icon_theme;
 	GdkPixbuf *pixbuf;
-	gchar *icon_key;
-	Icon *icon;
-	gint size, width, height;
+	gint width, height;
+	GError *error = NULL;
 
 	g_return_val_if_fail (icon_name != NULL, NULL);
 
+	icon_theme = gtk_icon_theme_get_default ();
+
 	if (!gtk_icon_size_lookup (icon_size, &width, &height))
 		return NULL;
 
-	size = height;
-
-	icon_key = g_alloca (strlen (icon_name) + 7);
-	sprintf (icon_key, "%dx%d/%s", size, size, icon_name);
-
-	g_static_mutex_lock (&mutex);
+	pixbuf = gtk_icon_theme_load_icon (
+		icon_theme, icon_name, height, 0, &error);
 
-	if (!(icon = g_hash_table_lookup (name_to_icon, icon_key))) {
-		icon = load_icon (icon_key, icon_name, size, TRUE);
-		g_hash_table_insert (name_to_icon, icon->name, icon);
+	if (error != NULL) {
+		g_warning ("%s", error->message);
+		g_error_free (error);
 	}
 
-	if ((pixbuf = icon->pixbuf)) {
-		g_object_ref (pixbuf);
-	} else {
-		if (size >= 24)
-			pixbuf = gdk_pixbuf_scale_simple (broken24_pixbuf, size, size, GDK_INTERP_NEAREST);
-		else
-			pixbuf = gdk_pixbuf_scale_simple (broken16_pixbuf, size, size, GDK_INTERP_NEAREST);
-	}
-
-	g_static_mutex_unlock (&mutex);
-
 	return pixbuf;
 }
 
diff --git a/e-util/e-icon-factory.h b/e-util/e-icon-factory.h
index 52ac332..9cec725 100644
--- a/e-util/e-icon-factory.h
+++ b/e-util/e-icon-factory.h
@@ -26,8 +26,6 @@
 
 #include <gtk/gtk.h>
 
-void		e_icon_factory_init		(void);
-void		e_icon_factory_shutdown		(void);
 gchar *		e_icon_factory_get_icon_filename(const gchar *icon_name,
 						 GtkIconSize icon_size);
 GdkPixbuf *	e_icon_factory_get_icon		(const gchar *icon_name,
diff --git a/shell/Makefile.am b/shell/Makefile.am
index 13ab041..541f941 100644
--- a/shell/Makefile.am
+++ b/shell/Makefile.am
@@ -111,6 +111,7 @@ evolution_CPPFLAGS =						\
 	-DEVOLUTION_DATADIR=\""$(datadir)"\"			\
 	-DEVOLUTION_GALVIEWSDIR=\""$(viewsdir)"\"		\
 	-DEVOLUTION_HELPDIR=\""$(evolutionhelpdir)"\"		\
+	-DEVOLUTION_ICONDIR=\""$(icondir)"\"			\
 	-DEVOLUTION_MODULEDIR=\""$(moduledir)"\"		\
 	-DEVOLUTION_RULEDIR=\""$(privdatadir)"\"		\
 	-DEVOLUTION_UIDIR=\""$(uidir)"\"			\
diff --git a/shell/main.c b/shell/main.c
index 2ef93d1..ab82c2e 100644
--- a/shell/main.c
+++ b/shell/main.c
@@ -55,7 +55,6 @@
 #include "e-util/e-bconf-map.h"
 #include "e-util/e-dialog-utils.h"
 #include "e-util/e-error.h"
-#include "e-util/e-icon-factory.h"
 #include "e-util/e-plugin.h"
 #include "e-util/e-plugin-ui.h"
 #include "e-util/e-profile-event.h"
@@ -475,6 +474,7 @@ extern void link_shutdown (void);
 gint
 main (gint argc, gchar **argv)
 {
+	GtkIconTheme *icon_theme;
 	GConfClient *client;
 #ifdef DEVELOPMENT
 	gboolean skip_warning_dialog;
@@ -574,9 +574,11 @@ main (gint argc, gchar **argv)
 			g_warning ("Could not set up debugging output file.");
 	}
 
-	e_icon_factory_init ();
 	e_passwords_init ();
 
+	icon_theme = gtk_icon_theme_get_default ();
+	gtk_icon_theme_append_search_path (icon_theme, EVOLUTION_ICONDIR);
+
 	gtk_window_set_default_icon_name ("evolution");
 
 	if (setup_only)
@@ -626,7 +628,6 @@ main (gint argc, gchar **argv)
 
 	gtk_accel_map_save (e_get_accels_filename ());
 
-	e_icon_factory_shutdown ();
 #ifdef G_OS_WIN32
 	link_shutdown ();
 #endif



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