diff options
author | Matthias Clasen <mclasen@redhat.com> | 2005-11-04 15:43:40 +0000 |
---|---|---|
committer | Matthias Clasen <matthiasc@src.gnome.org> | 2005-11-04 15:43:40 +0000 |
commit | b983d1c6a7833ce85fe53eee0d7b15bd03aad585 (patch) | |
tree | 093dd7272edec179393defc86c8ee11ca6c08f89 /gtk/updateiconcache.c | |
parent | 99633ce5358189eec090d9a72655b777396762b0 (diff) | |
download | gtk+-b983d1c6a7833ce85fe53eee0d7b15bd03aad585.tar.gz |
Store builtin stock icons in an icon cache, instead of populating a hash
2005-11-04 Matthias Clasen <mclasen@redhat.com>
Store builtin stock icons in an icon cache, instead of
populating a hash table with pixbufs at startup, to save both
memory and startup time.
* gtk/stock-icons/*: Reorganize the icons in a directory structure
suitable for gtk-update-icon-cache, and rename them to match the
stock ids.
* gtk/gtkiconcache.[hc]: Support non-mmapped icon caches, and
add _gtk_icon_cache_has_icon_in_directory().
* gtk/updateiconcache.c: Support a --source <VARIABLE> argument
to store the contents of the icon cache in a C header.
* gtk/gtkbuiltincache.h: Generated private header which contains
the icon cache for the builtin icons.
* gtk/gtkicontheme.c: Create a GtkIconCache for the builtin
icons, and use that in addition to the hash table whenever
builtin icons are searched.
* gtk/gtkiconfactory.c: Add GTK_ICON_SOURCE_STATIC_ICON_NAME and
use it for static stock ids.
(get_default_icons): Don't add the builtin
icons to the icon theme, just register the stock ids.
(render_fallback_image): Take the fallback image out of the
builtin icon cache.
* gtk/Makefile.am: Remove stock-icons from SUBDIRS and add
the necessary machinery to rebuild gtkbuiltincache.h.
Diffstat (limited to 'gtk/updateiconcache.c')
-rw-r--r-- | gtk/updateiconcache.c | 64 |
1 files changed, 64 insertions, 0 deletions
diff --git a/gtk/updateiconcache.c b/gtk/updateiconcache.c index f3385b0547..31906f9524 100644 --- a/gtk/updateiconcache.c +++ b/gtk/updateiconcache.c @@ -42,6 +42,7 @@ static gboolean force_update = FALSE; static gboolean ignore_theme_index = FALSE; static gboolean quiet = FALSE; static gboolean index_only = FALSE; +static gchar *var_name = "-"; #define CACHE_NAME "icon-theme.cache" @@ -1207,10 +1208,70 @@ build_cache (const gchar *path) g_printerr ("Cache file created successfully.\n"); } +void +write_csource (const gchar *path) +{ + gchar *cache_path; + gchar *data; + guint8 d; + gsize len; + gint pos; + gint i; + + cache_path = g_build_filename (path, CACHE_NAME, NULL); + if (!g_file_get_contents (cache_path, &data, &len, NULL)) + exit (1); + + g_printf ("#ifdef __SUNPRO_C\n"); + g_printf ("#pragma align 4 (%s)\n", var_name); + g_printf ("#endif\n"); + + g_printf ("#ifdef __GNUC__\n"); + g_printf ("static const guint8 %s[] __attribute__ ((__aligned__ (4))) = \n", var_name); + g_printf ("#else\n"); + g_printf ("static const guint8 %s[] = \n", var_name); + g_printf ("#endif\n"); + g_printf ("{ ""\n \""); + + pos = 3; + for (i = 0; i < len; i++) + { + d = data[i]; + if (pos > 70) + { + g_printf ("\"\n \""); + pos = 3; + } + if (d < 33 || d > 126 || d == '?') + { + g_printf ("\\%.3o", d); + pos += 4; + continue; + } + if (d == '\\') + { + g_printf ("\\\\"); + pos += 2; + } + else if (d == '"') + { + g_printf ("\\\""); + pos += 2; + } + else + { + g_printf ("%c", d); + pos += 1; + } + } + g_printf ("\"};\n"); +} + static GOptionEntry args[] = { { "force", 'f', 0, G_OPTION_ARG_NONE, &force_update, "Overwrite an existing cache, even if uptodate", NULL }, { "ignore-theme-index", 't', 0, G_OPTION_ARG_NONE, &ignore_theme_index, "Don't check for the existence of index.theme", NULL }, { "index-only", 'i', 0, G_OPTION_ARG_NONE, &index_only, "Don't include image data in the cache", NULL }, + { "source", 'c', 0, G_OPTION_ARG_STRING, &var_name, "Output a C header file", "NAME" }, { "quiet", 'q', 0, G_OPTION_ARG_NONE, &quiet, "Turn off verbose output", NULL }, { NULL } }; @@ -1247,5 +1308,8 @@ main (int argc, char **argv) g_type_init (); build_cache (path); + if (strcmp (var_name, "-") != 0) + write_csource (path); + return 0; } |