aboutsummaryrefslogtreecommitdiffstats
path: root/e-util
diff options
context:
space:
mode:
authorMilan Crha <mcrha@redhat.com>2009-07-30 17:22:59 +0800
committerMatthew Barnes <mbarnes@redhat.com>2009-08-11 04:31:35 +0800
commitaa8a700dd924a83e1dcd8eb374df777fb0a83b66 (patch)
treea6571a43052aafb50ddc927c3c7d03b092d4fabd /e-util
parent7eee013e97aa3d1d28112f5b25744035941ec23c (diff)
downloadgsoc2013-evolution-aa8a700dd924a83e1dcd8eb374df777fb0a83b66.tar.gz
gsoc2013-evolution-aa8a700dd924a83e1dcd8eb374df777fb0a83b66.tar.zst
gsoc2013-evolution-aa8a700dd924a83e1dcd8eb374df777fb0a83b66.zip
Bug #300567 - Calendar drawing optimizations
Diffstat (limited to 'e-util')
-rw-r--r--e-util/e-categories-config.c72
-rw-r--r--e-util/e-categories-config.h4
2 files changed, 45 insertions, 31 deletions
diff --git a/e-util/e-categories-config.c b/e-util/e-categories-config.c
index 14c8eae189..3dc35588b0 100644
--- a/e-util/e-categories-config.c
+++ b/e-util/e-categories-config.c
@@ -27,48 +27,64 @@
#include <libedataserverui/e-categories-dialog.h>
#include "e-categories-config.h"
+static GHashTable *pixbufs_cache = NULL;
+
+static void
+categories_changed_cb (gpointer object, gpointer user_data)
+{
+ if (pixbufs_cache)
+ g_hash_table_remove_all (pixbufs_cache);
+}
+
+static void
+free_pixbuf_cb (gpointer ptr)
+{
+ GdkPixbuf *pixbuf = ptr;
+
+ if (pixbuf)
+ g_object_unref (pixbuf);
+}
+
/**
* e_categories_config_get_icon_for:
* @category: Category for which to get the icon.
- * @icon: A pointer to where the pixmap will be returned.
- * @mask: A pointer to where the mask will be returned.
+ * @pixbuf: A pointer to where the pixbuf will be returned.
*
- * Returns the icon (and associated mask) configured for the
- * given category.
+ * Returns the icon configured for the given category.
*/
gboolean
-e_categories_config_get_icon_for (const gchar *category, GdkPixmap **pixmap, GdkBitmap **mask)
+e_categories_config_get_icon_for (const gchar *category, GdkPixbuf **pixbuf)
{
- gchar *icon_file;
- GdkPixbuf *pixbuf;
- GdkBitmap *tmp_mask;
+ const gchar *icon_file;
- g_return_val_if_fail (pixmap != NULL, FALSE);
+ g_return_val_if_fail (pixbuf != NULL, FALSE);
+ g_return_val_if_fail (category != NULL, FALSE);
- icon_file = (gchar *) e_categories_get_icon_file_for (category);
- if (!icon_file) {
- *pixmap = NULL;
- if (mask != NULL)
- *mask = NULL;
- return FALSE;
+ if (!pixbufs_cache) {
+ pixbufs_cache = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, free_pixbuf_cb);
+ e_categories_register_change_listener (G_CALLBACK (categories_changed_cb), NULL);
+ } else {
+ gpointer key = NULL, value = NULL;
+
+ if (g_hash_table_lookup_extended (pixbufs_cache, category, &key, &value)) {
+ *pixbuf = value;
+ if (*pixbuf)
+ g_object_ref (*pixbuf);
+ return *pixbuf != NULL;
+ }
}
- /* load the icon in our list */
- pixbuf = gdk_pixbuf_new_from_file (icon_file, NULL);
- if (!pixbuf) {
- *pixmap = NULL;
- if (mask != NULL)
- *mask = NULL;
- return FALSE;
+ icon_file = e_categories_get_icon_file_for (category);
+ if (!icon_file) {
+ *pixbuf = NULL;
+ } else {
+ /* load the icon in our list */
+ *pixbuf = gdk_pixbuf_new_from_file (icon_file, NULL);
}
- /* render the pixbuf to the pixmap and mask passed */
- gdk_pixbuf_render_pixmap_and_mask (pixbuf, pixmap, &tmp_mask, 1);
- if (mask != NULL)
- *mask = tmp_mask;
+ g_hash_table_insert (pixbufs_cache, g_strdup (category), *pixbuf == NULL ? NULL : g_object_ref (*pixbuf));
- g_object_unref (pixbuf);
- return TRUE;
+ return *pixbuf != NULL;
}
/**
diff --git a/e-util/e-categories-config.h b/e-util/e-categories-config.h
index 81ae0161a0..82294ae6b9 100644
--- a/e-util/e-categories-config.h
+++ b/e-util/e-categories-config.h
@@ -30,9 +30,7 @@
G_BEGIN_DECLS
-gboolean e_categories_config_get_icon_for (const gchar *category,
- GdkPixmap **icon,
- GdkBitmap **mask);
+gboolean e_categories_config_get_icon_for (const gchar *category, GdkPixbuf **pixbuf);
void e_categories_config_open_dialog_for_entry (GtkEntry *entry);
G_END_DECLS