1 /* GtkIconTheme - a loader for icon themes
2 * gtk-icon-theme.c Copyright (C) 2002, 2003 Red Hat, Inc.
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2 of the License, or (at your option) any later version.
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library; if not, write to the
16 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
17 * Boston, MA 02111-1307, USA.
22 #include <sys/types.h>
30 #include <glib/gstdio.h>
34 #define S_ISDIR(mode) ((mode)&_S_IFDIR)
36 #endif /* G_OS_WIN32 */
38 #include "gtkicontheme.h"
39 #include "gtkiconfactory.h"
40 #include "gtkiconcache.h"
41 #include "gtkbuiltincache.h"
43 #include "gtksettings.h"
44 #include "gtkprivate.h"
47 #define DEFAULT_THEME_NAME "hicolor"
52 ICON_THEME_DIR_SCALABLE,
53 ICON_THEME_DIR_THRESHOLD,
54 ICON_THEME_DIR_UNTHEMED
57 /* In reverse search order: */
61 ICON_SUFFIX_XPM = 1 << 0,
62 ICON_SUFFIX_SVG = 1 << 1,
63 ICON_SUFFIX_PNG = 1 << 2,
64 HAS_ICON_FILE = 1 << 3
68 struct _GtkIconThemePrivate
70 guint custom_theme : 1;
71 guint is_screen_singleton : 1;
72 guint pixbuf_supports_svg : 1;
78 gboolean themes_valid;
79 /* A list of all the themes needed to look up icons.
80 * In search order, without duplicates
83 GHashTable *unthemed_icons;
85 /* Note: The keys of this hashtable are owned by the
86 * themedir and unthemed hashtables.
88 GHashTable *all_icons;
90 /* GdkScreen for the icon theme (may be NULL)
94 /* time when we last stat:ed for theme changes */
98 gulong reset_styles_idle;
100 gboolean check_reload;
105 /* Information about the source
109 /* System codepage version of filename, for DLL ABI backward
110 * compatibility functions.
114 /* Cache pixbuf (if there is any) */
115 GdkPixbuf *cache_pixbuf;
119 /* Information about the directory where
120 * the source was found
122 IconThemeDirType dir_type;
126 /* Parameters influencing the scaled icon
129 gboolean raw_coordinates;
131 /* Cached information if we go ahead and try to load
146 /* In search order */
152 IconThemeDirType type;
166 GHashTable *icon_data;
172 char *no_svg_filename;
184 time_t mtime; /* 0 == not existing or not a dir */
189 static void gtk_icon_theme_class_init (GtkIconThemeClass *klass);
190 static void gtk_icon_theme_init (GtkIconTheme *icon_theme);
191 static void gtk_icon_theme_finalize (GObject *object);
192 static void theme_dir_destroy (IconThemeDir *dir);
194 static void theme_destroy (IconTheme *theme);
195 static GtkIconInfo *theme_lookup_icon (IconTheme *theme,
196 const char *icon_name,
199 gboolean use_default_icons);
200 static void theme_list_icons (IconTheme *theme,
203 static void theme_subdir_load (GtkIconTheme *icon_theme,
205 GKeyFile *theme_file,
207 static void do_theme_change (GtkIconTheme *icon_theme);
209 static void blow_themes (GtkIconTheme *icon_themes);
211 static void icon_data_free (GtkIconData *icon_data);
212 static void load_icon_data (IconThemeDir *dir,
216 static IconSuffix theme_dir_get_icon_suffix (IconThemeDir *dir,
217 const gchar *icon_name,
218 gboolean *has_icon_file);
221 static GtkIconInfo *icon_info_new (void);
222 static GtkIconInfo *icon_info_new_builtin (BuiltinIcon *icon);
224 static IconSuffix suffix_from_name (const char *name);
226 static BuiltinIcon *find_builtin_icon (const gchar *icon_name,
228 gint *min_difference_p,
229 gboolean *has_larger_p);
231 static GObjectClass *parent_class = NULL;
233 static guint signal_changed = 0;
235 static GHashTable *icon_theme_builtin_icons;
237 /* also used in gtkiconfactory.c */
238 GtkIconCache *_builtin_cache = NULL;
239 static GList *builtin_dirs = NULL;
243 gtk_icon_theme_get_type (void)
245 static GType type = 0;
249 static const GTypeInfo info =
251 sizeof (GtkIconThemeClass),
252 NULL, /* base_init */
253 NULL, /* base_finalize */
254 (GClassInitFunc) gtk_icon_theme_class_init,
255 NULL, /* class_finalize */
256 NULL, /* class_data */
257 sizeof (GtkIconTheme),
259 (GInstanceInitFunc) gtk_icon_theme_init,
262 type = g_type_register_static (G_TYPE_OBJECT, I_("GtkIconTheme"), &info, 0);
269 * gtk_icon_theme_new:
271 * Creates a new icon theme object. Icon theme objects are used
272 * to lookup up an icon by name in a particular icon theme.
273 * Usually, you'll want to use gtk_icon_theme_get_default()
274 * or gtk_icon_theme_get_for_screen() rather than creating
275 * a new icon theme object for scratch.
277 * Return value: the newly created #GtkIconTheme object.
282 gtk_icon_theme_new (void)
284 return g_object_new (GTK_TYPE_ICON_THEME, NULL);
288 * gtk_icon_theme_get_default:
290 * Gets the icon theme for the default screen. See
291 * gtk_icon_theme_get_for_screen().
293 * Return value: A unique #GtkIconTheme associated with
294 * the default screen. This icon theme is associated with
295 * the screen and can be used as long as the screen
296 * is open. Do not ref or unref it.
301 gtk_icon_theme_get_default (void)
303 return gtk_icon_theme_get_for_screen (gdk_screen_get_default ());
307 * gtk_icon_theme_get_for_screen:
308 * @screen: a #GdkScreen
310 * Gets the icon theme object associated with @screen; if this
311 * function has not previously been called for the given
312 * screen, a new icon theme object will be created and
313 * associated with the screen. Icon theme objects are
314 * fairly expensive to create, so using this function
315 * is usually a better choice than calling than gtk_icon_theme_new()
316 * and setting the screen yourself; by using this function
317 * a single icon theme object will be shared between users.
319 * Return value: A unique #GtkIconTheme associated with
320 * the given screen. This icon theme is associated with
321 * the screen and can be used as long as the screen
322 * is open. Do not ref or unref it.
327 gtk_icon_theme_get_for_screen (GdkScreen *screen)
329 GtkIconTheme *icon_theme;
331 g_return_val_if_fail (GDK_IS_SCREEN (screen), NULL);
332 g_return_val_if_fail (!screen->closed, NULL);
334 icon_theme = g_object_get_data (G_OBJECT (screen), "gtk-icon-theme");
337 GtkIconThemePrivate *priv;
339 icon_theme = gtk_icon_theme_new ();
340 gtk_icon_theme_set_screen (icon_theme, screen);
342 priv = icon_theme->priv;
343 priv->is_screen_singleton = TRUE;
345 g_object_set_data (G_OBJECT (screen), I_("gtk-icon-theme"), icon_theme);
352 gtk_icon_theme_class_init (GtkIconThemeClass *klass)
354 GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
356 parent_class = g_type_class_peek_parent (klass);
358 gobject_class->finalize = gtk_icon_theme_finalize;
361 * GtkIconTheme::changed
362 * @icon_theme: the icon theme
364 * Emitted when the current icon theme is switched or GTK+ detects
365 * that a change has occurred in the contents of the current
368 signal_changed = g_signal_new (I_("changed"),
369 G_TYPE_FROM_CLASS (klass),
371 G_STRUCT_OFFSET (GtkIconThemeClass, changed),
373 g_cclosure_marshal_VOID__VOID,
376 g_type_class_add_private (klass, sizeof (GtkIconThemePrivate));
380 /* Callback when the display that the icon theme is attached to
381 * is closed; unset the screen, and if it's the unique theme
382 * for the screen, drop the reference
385 display_closed (GdkDisplay *display,
387 GtkIconTheme *icon_theme)
389 GtkIconThemePrivate *priv = icon_theme->priv;
390 GdkScreen *screen = priv->screen;
391 gboolean was_screen_singleton = priv->is_screen_singleton;
393 if (was_screen_singleton)
395 g_object_set_data (G_OBJECT (screen), I_("gtk-icon-theme"), NULL);
396 priv->is_screen_singleton = FALSE;
399 gtk_icon_theme_set_screen (icon_theme, NULL);
401 if (was_screen_singleton)
403 g_object_unref (icon_theme);
408 update_current_theme (GtkIconTheme *icon_theme)
410 GtkIconThemePrivate *priv = icon_theme->priv;
412 if (!priv->custom_theme)
418 GtkSettings *settings = gtk_settings_get_for_screen (priv->screen);
419 g_object_get (settings, "gtk-icon-theme-name", &theme, NULL);
423 theme = g_strdup (DEFAULT_THEME_NAME);
425 if (strcmp (priv->current_theme, theme) != 0)
427 g_free (priv->current_theme);
428 priv->current_theme = theme;
430 do_theme_change (icon_theme);
437 /* Callback when the icon theme GtkSetting changes
440 theme_changed (GtkSettings *settings,
442 GtkIconTheme *icon_theme)
444 update_current_theme (icon_theme);
448 unset_screen (GtkIconTheme *icon_theme)
450 GtkIconThemePrivate *priv = icon_theme->priv;
451 GtkSettings *settings;
456 settings = gtk_settings_get_for_screen (priv->screen);
457 display = gdk_screen_get_display (priv->screen);
459 g_signal_handlers_disconnect_by_func (display,
460 (gpointer) display_closed,
462 g_signal_handlers_disconnect_by_func (settings,
463 (gpointer) theme_changed,
471 * gtk_icon_theme_set_screen:
472 * @icon_theme: a #GtkIconTheme
473 * @screen: a #GdkScreen
475 * Sets the screen for an icon theme; the screen is used
476 * to track the user's currently configured icon theme,
477 * which might be different for different screens.
482 gtk_icon_theme_set_screen (GtkIconTheme *icon_theme,
485 GtkIconThemePrivate *priv;
486 GtkSettings *settings;
489 g_return_if_fail (GTK_ICON_THEME (icon_theme));
490 g_return_if_fail (screen == NULL || GDK_IS_SCREEN (screen));
492 priv = icon_theme->priv;
494 unset_screen (icon_theme);
498 display = gdk_screen_get_display (screen);
499 settings = gtk_settings_get_for_screen (screen);
501 priv->screen = screen;
503 g_signal_connect (display, "closed",
504 G_CALLBACK (display_closed), icon_theme);
505 g_signal_connect (settings, "notify::gtk-icon-theme-name",
506 G_CALLBACK (theme_changed), icon_theme);
509 update_current_theme (icon_theme);
512 /* Checks whether a loader for SVG files has been registered
516 pixbuf_supports_svg (void)
518 GSList *formats = gdk_pixbuf_get_formats ();
520 static gboolean found_svg = FALSE;
521 static gboolean value_known = FALSE;
526 for (tmp_list = formats; tmp_list && !found_svg; tmp_list = tmp_list->next)
528 gchar **mime_types = gdk_pixbuf_format_get_mime_types (tmp_list->data);
531 for (mime_type = mime_types; *mime_type && !found_svg; mime_type++)
533 if (strcmp (*mime_type, "image/svg") == 0)
537 g_strfreev (mime_types);
540 g_slist_free (formats);
547 gtk_icon_theme_init (GtkIconTheme *icon_theme)
549 GtkIconThemePrivate *priv;
550 const gchar * const *xdg_data_dirs;
553 priv = g_type_instance_get_private ((GTypeInstance *)icon_theme,
554 GTK_TYPE_ICON_THEME);
555 icon_theme->priv = priv;
557 priv->custom_theme = FALSE;
558 priv->current_theme = g_strdup (DEFAULT_THEME_NAME);
560 xdg_data_dirs = g_get_system_data_dirs ();
561 for (i = 0; xdg_data_dirs[i]; i++) ;
563 priv->search_path_len = 2 * i + 2;
565 priv->search_path = g_new (char *, priv->search_path_len);
568 priv->search_path[i++] = g_build_filename (g_get_home_dir (), ".icons", NULL);
569 priv->search_path[i++] = g_build_filename (g_get_user_data_dir (), "icons", NULL);
571 for (j = 0; xdg_data_dirs[j]; j++)
572 priv->search_path[i++] = g_build_filename (xdg_data_dirs[j], "icons", NULL);
574 for (j = 0; xdg_data_dirs[j]; j++)
575 priv->search_path[i++] = g_build_filename (xdg_data_dirs[j], "pixmaps", NULL);
577 priv->themes_valid = FALSE;
579 priv->unthemed_icons = NULL;
581 priv->pixbuf_supports_svg = pixbuf_supports_svg ();
585 free_dir_mtime (IconThemeDirMtime *dir_mtime)
587 if (dir_mtime->cache)
588 _gtk_icon_cache_unref (dir_mtime->cache);
590 g_free (dir_mtime->dir);
596 reset_styles_idle (gpointer user_data)
598 GtkIconTheme *icon_theme;
599 GtkIconThemePrivate *priv;
601 GDK_THREADS_ENTER ();
603 icon_theme = GTK_ICON_THEME (user_data);
604 priv = icon_theme->priv;
606 if (priv->screen && priv->is_screen_singleton)
608 GtkSettings *settings = gtk_settings_get_for_screen (priv->screen);
609 gtk_rc_reset_styles (settings);
612 priv->reset_styles_idle = 0;
614 GDK_THREADS_LEAVE ();
620 do_theme_change (GtkIconTheme *icon_theme)
622 GtkIconThemePrivate *priv = icon_theme->priv;
625 g_print ("change to icon theme \"%s\"\n", priv->current_theme));
626 blow_themes (icon_theme);
627 g_signal_emit (icon_theme, signal_changed, 0);
629 if (!priv->reset_styles_idle)
630 priv->reset_styles_idle =
631 g_idle_add (reset_styles_idle, icon_theme);
635 blow_themes (GtkIconTheme *icon_theme)
637 GtkIconThemePrivate *priv = icon_theme->priv;
639 if (priv->themes_valid)
641 g_hash_table_destroy (priv->all_icons);
642 g_list_foreach (priv->themes, (GFunc)theme_destroy, NULL);
643 g_list_free (priv->themes);
644 g_list_foreach (priv->dir_mtimes, (GFunc)free_dir_mtime, NULL);
645 g_list_free (priv->dir_mtimes);
646 g_hash_table_destroy (priv->unthemed_icons);
649 priv->unthemed_icons = NULL;
650 priv->dir_mtimes = NULL;
651 priv->all_icons = NULL;
652 priv->themes_valid = FALSE;
656 gtk_icon_theme_finalize (GObject *object)
658 GtkIconTheme *icon_theme;
659 GtkIconThemePrivate *priv;
662 icon_theme = GTK_ICON_THEME (object);
663 priv = icon_theme->priv;
665 if (priv->reset_styles_idle)
667 g_source_remove (priv->reset_styles_idle);
668 priv->reset_styles_idle = 0;
671 unset_screen (icon_theme);
673 g_free (priv->current_theme);
674 priv->current_theme = NULL;
676 for (i=0; i < priv->search_path_len; i++)
677 g_free (priv->search_path[i]);
679 g_free (priv->search_path);
680 priv->search_path = NULL;
682 blow_themes (icon_theme);
684 G_OBJECT_CLASS (parent_class)->finalize (object);
688 * gtk_icon_theme_set_search_path:
689 * @icon_theme: a #GtkIconTheme
690 * @path: array of directories that are searched for icon themes
691 * @n_elements: number of elements in @path.
693 * Sets the search path for the icon theme object. When looking
694 * for an icon theme, GTK+ will search for a subdirectory of
695 * one or more of the directories in @path with the same name
696 * as the icon theme. (Themes from multiple of the path elements
697 * are combined to allow themes to be extended by adding icons
698 * in the user's home directory.)
700 * In addition if an icon found isn't found either in the current
701 * icon theme or the default icon theme, and an image file with
702 * the right name is found directly in one of the elements of
703 * @path, then that image will be used for the icon name.
704 * (This is legacy feature, and new icons should be put
705 * into the default icon theme, which is called DEFAULT_THEME_NAME,
706 * rather than directly on the icon path.)
711 gtk_icon_theme_set_search_path (GtkIconTheme *icon_theme,
715 GtkIconThemePrivate *priv;
718 g_return_if_fail (GTK_IS_ICON_THEME (icon_theme));
720 priv = icon_theme->priv;
721 for (i = 0; i < priv->search_path_len; i++)
722 g_free (priv->search_path[i]);
724 g_free (priv->search_path);
726 priv->search_path = g_new (gchar *, n_elements);
727 priv->search_path_len = n_elements;
728 for (i = 0; i < priv->search_path_len; i++)
729 priv->search_path[i] = g_strdup (path[i]);
731 do_theme_change (icon_theme);
736 * gtk_icon_theme_get_search_path:
737 * @icon_theme: a #GtkIconTheme
738 * @path: location to store a list of icon theme path directories or %NULL
739 * The stored value should be freed with g_strfreev().
740 * @n_elements: location to store number of elements
743 * Gets the current search path. See gtk_icon_theme_set_search_path().
748 gtk_icon_theme_get_search_path (GtkIconTheme *icon_theme,
752 GtkIconThemePrivate *priv;
755 g_return_if_fail (GTK_IS_ICON_THEME (icon_theme));
757 priv = icon_theme->priv;
760 *n_elements = priv->search_path_len;
764 *path = g_new (gchar *, priv->search_path_len + 1);
765 for (i = 0; i < priv->search_path_len; i++)
766 (*path)[i] = g_strdup (priv->search_path[i]);
772 * gtk_icon_theme_append_search_path:
773 * @icon_theme: a #GtkIconTheme
774 * @path: directory name to append to the icon path
776 * Appends a directory to the search path.
777 * See gtk_icon_theme_set_search_path().
782 gtk_icon_theme_append_search_path (GtkIconTheme *icon_theme,
785 GtkIconThemePrivate *priv;
787 g_return_if_fail (GTK_IS_ICON_THEME (icon_theme));
788 g_return_if_fail (path != NULL);
790 priv = icon_theme->priv;
792 priv->search_path_len++;
793 priv->search_path = g_renew (gchar *, priv->search_path, priv->search_path_len);
794 priv->search_path[priv->search_path_len-1] = g_strdup (path);
796 do_theme_change (icon_theme);
800 * gtk_icon_theme_prepend_search_path:
801 * @icon_theme: a #GtkIconTheme
802 * @path: directory name to prepend to the icon path
804 * Prepends a directory to the search path.
805 * See gtk_icon_theme_set_search_path().
810 gtk_icon_theme_prepend_search_path (GtkIconTheme *icon_theme,
813 GtkIconThemePrivate *priv;
816 g_return_if_fail (GTK_IS_ICON_THEME (icon_theme));
817 g_return_if_fail (path != NULL);
819 priv = icon_theme->priv;
821 priv->search_path_len++;
822 priv->search_path = g_renew (gchar *, priv->search_path, priv->search_path_len);
824 for (i = priv->search_path_len - 1; i > 0; i--)
825 priv->search_path[i] = priv->search_path[i - 1];
827 priv->search_path[0] = g_strdup (path);
829 do_theme_change (icon_theme);
833 * gtk_icon_theme_set_custom_theme:
834 * @icon_theme: a #GtkIconTheme
835 * @theme_name: name of icon theme to use instead of configured theme,
836 * or %NULL to unset a previously set custom theme
838 * Sets the name of the icon theme that the #GtkIconTheme object uses
839 * overriding system configuration. This function cannot be called
840 * on the icon theme objects returned from gtk_icon_theme_get_default()
841 * and gtk_icon_theme_get_for_screen().
846 gtk_icon_theme_set_custom_theme (GtkIconTheme *icon_theme,
847 const gchar *theme_name)
849 GtkIconThemePrivate *priv;
851 g_return_if_fail (GTK_IS_ICON_THEME (icon_theme));
853 priv = icon_theme->priv;
855 g_return_if_fail (!priv->is_screen_singleton);
857 if (theme_name != NULL)
859 priv->custom_theme = TRUE;
860 if (strcmp (theme_name, priv->current_theme) != 0)
862 g_free (priv->current_theme);
863 priv->current_theme = g_strdup (theme_name);
865 do_theme_change (icon_theme);
870 priv->custom_theme = FALSE;
872 update_current_theme (icon_theme);
877 insert_theme (GtkIconTheme *icon_theme, const char *theme_name)
883 GtkIconThemePrivate *priv;
886 GKeyFile *theme_file;
887 GError *error = NULL;
888 IconThemeDirMtime *dir_mtime;
889 struct stat stat_buf;
891 priv = icon_theme->priv;
893 for (l = priv->themes; l != NULL; l = l->next)
896 if (strcmp (theme->name, theme_name) == 0)
900 for (i = 0; i < priv->search_path_len; i++)
902 path = g_build_filename (priv->search_path[i],
905 dir_mtime = g_new (IconThemeDirMtime, 1);
906 dir_mtime->cache = NULL;
907 dir_mtime->dir = path;
908 if (g_stat (path, &stat_buf) == 0 && S_ISDIR (stat_buf.st_mode))
909 dir_mtime->mtime = stat_buf.st_mtime;
911 dir_mtime->mtime = 0;
913 priv->dir_mtimes = g_list_prepend (priv->dir_mtimes, dir_mtime);
915 priv->dir_mtimes = g_list_reverse (priv->dir_mtimes);
918 for (i = 0; i < priv->search_path_len && !theme_file; i++)
920 path = g_build_filename (priv->search_path[i],
924 if (g_file_test (path, G_FILE_TEST_IS_REGULAR))
926 theme_file = g_key_file_new ();
927 g_key_file_set_list_separator (theme_file, ',');
928 g_key_file_load_from_file (theme_file, path, 0, &error);
931 g_key_file_free (theme_file);
933 g_error_free (error);
940 if (theme_file == NULL)
943 theme = g_new (IconTheme, 1);
944 theme->display_name =
945 g_key_file_get_locale_string (theme_file, "Icon Theme", "Name", NULL, NULL);
946 if (!theme->display_name)
948 g_warning ("Theme file for %s has no name\n", theme_name);
950 g_key_file_free (theme_file);
954 dirs = g_key_file_get_string_list (theme_file, "Icon Theme", "Directories", NULL, NULL);
957 g_warning ("Theme file for %s has no directories\n", theme_name);
958 g_free (theme->display_name);
960 g_key_file_free (theme_file);
964 theme->name = g_strdup (theme_name);
966 g_key_file_get_locale_string (theme_file,
967 "Icon Theme", "Comment",
970 g_key_file_get_string (theme_file,
971 "Icon Theme", "Example",
975 for (i = 0; dirs[i] != NULL; i++)
976 theme_subdir_load (icon_theme, theme, theme_file, dirs[i]);
980 theme->dirs = g_list_reverse (theme->dirs);
982 /* Prepend the finished theme */
983 priv->themes = g_list_prepend (priv->themes, theme);
985 themes = g_key_file_get_string_list (theme_file,
992 for (i = 0; themes[i] != NULL; i++)
993 insert_theme (icon_theme, themes[i]);
998 g_key_file_free (theme_file);
1002 free_unthemed_icon (UnthemedIcon *unthemed_icon)
1004 if (unthemed_icon->svg_filename)
1005 g_free (unthemed_icon->svg_filename);
1006 if (unthemed_icon->no_svg_filename)
1007 g_free (unthemed_icon->no_svg_filename);
1008 g_free (unthemed_icon);
1012 load_themes (GtkIconTheme *icon_theme)
1014 GtkIconThemePrivate *priv;
1017 char *dir, *base_name, *dot;
1020 UnthemedIcon *unthemed_icon;
1021 IconSuffix old_suffix, new_suffix;
1023 IconThemeDirMtime *dir_mtime;
1024 struct stat stat_buf;
1026 priv = icon_theme->priv;
1028 priv->all_icons = g_hash_table_new (g_str_hash, g_str_equal);
1030 insert_theme (icon_theme, priv->current_theme);
1032 /* Always look in the "default" icon theme */
1033 insert_theme (icon_theme, DEFAULT_THEME_NAME);
1034 priv->themes = g_list_reverse (priv->themes);
1037 priv->unthemed_icons = g_hash_table_new_full (g_str_hash, g_str_equal,
1038 g_free, (GDestroyNotify)free_unthemed_icon);
1040 for (base = 0; base < icon_theme->priv->search_path_len; base++)
1042 dir = icon_theme->priv->search_path[base];
1044 dir_mtime = g_new (IconThemeDirMtime, 1);
1045 dir_mtime->cache = _gtk_icon_cache_new_for_path (dir);
1046 dir_mtime->dir = g_strdup (dir);
1047 if (g_stat (dir, &stat_buf) == 0 && S_ISDIR (stat_buf.st_mode))
1048 dir_mtime->mtime = stat_buf.st_mtime;
1050 dir_mtime->mtime = 0;
1052 priv->dir_mtimes = g_list_append (priv->dir_mtimes, dir_mtime);
1054 if (dir_mtime->cache != NULL)
1057 gdir = g_dir_open (dir, 0, NULL);
1062 while ((file = g_dir_read_name (gdir)))
1064 new_suffix = suffix_from_name (file);
1066 if (new_suffix != ICON_SUFFIX_NONE)
1068 abs_file = g_build_filename (dir, file, NULL);
1070 base_name = g_strdup (file);
1072 dot = strrchr (base_name, '.');
1076 if ((unthemed_icon = g_hash_table_lookup (priv->unthemed_icons,
1079 if (new_suffix == ICON_SUFFIX_SVG)
1081 if (unthemed_icon->svg_filename)
1084 unthemed_icon->svg_filename = abs_file;
1088 if (unthemed_icon->no_svg_filename)
1090 old_suffix = suffix_from_name (unthemed_icon->no_svg_filename);
1091 if (new_suffix > old_suffix)
1093 g_free (unthemed_icon->no_svg_filename);
1094 unthemed_icon->no_svg_filename = abs_file;
1100 unthemed_icon->no_svg_filename = abs_file;
1107 unthemed_icon = g_new0 (UnthemedIcon, 1);
1109 if (new_suffix == ICON_SUFFIX_SVG)
1110 unthemed_icon->svg_filename = abs_file;
1112 unthemed_icon->no_svg_filename = abs_file;
1114 g_hash_table_insert (priv->unthemed_icons,
1117 g_hash_table_insert (priv->all_icons,
1125 priv->themes_valid = TRUE;
1127 g_get_current_time(&tv);
1128 priv->last_stat_time = tv.tv_sec;
1132 ensure_valid_themes (GtkIconTheme *icon_theme)
1134 GtkIconThemePrivate *priv = icon_theme->priv;
1137 if (priv->themes_valid)
1139 g_get_current_time (&tv);
1141 if (ABS (tv.tv_sec - priv->last_stat_time) > 5)
1142 gtk_icon_theme_rescan_if_needed (icon_theme);
1145 if (!priv->themes_valid)
1147 load_themes (icon_theme);
1149 if (!priv->check_reload && priv->screen)
1151 static GdkAtom atom_iconthemes = GDK_NONE;
1152 GdkEvent *event = gdk_event_new (GDK_CLIENT_EVENT);
1155 if (!atom_iconthemes)
1156 atom_iconthemes = gdk_atom_intern_static_string ("_GTK_LOAD_ICONTHEMES");
1158 for (i = 0; i < 5; i++)
1159 event->client.data.l[i] = 0;
1160 event->client.data_format = 32;
1161 event->client.message_type = atom_iconthemes;
1163 gdk_screen_broadcast_client_message (priv->screen, event);
1169 * gtk_icon_theme_lookup_icon:
1170 * @icon_theme: a #GtkIconTheme
1171 * @icon_name: the name of the icon to lookup
1172 * @size: desired icon size
1173 * @flags: flags modifying the behavior of the icon lookup
1175 * Looks up a named icon and returns a structure containing
1176 * information such as the filename of the icon. The icon
1177 * can then be rendered into a pixbuf using
1178 * gtk_icon_info_load_icon(). (gtk_icon_theme_load_icon()
1179 * combines these two steps if all you need is the pixbuf.)
1181 * Return value: a #GtkIconInfo structure containing information
1182 * about the icon, or %NULL if the icon wasn't found. Free with
1183 * gtk_icon_info_free()
1188 gtk_icon_theme_lookup_icon (GtkIconTheme *icon_theme,
1189 const gchar *icon_name,
1191 GtkIconLookupFlags flags)
1193 GtkIconThemePrivate *priv;
1195 GtkIconInfo *icon_info = NULL;
1196 UnthemedIcon *unthemed_icon;
1198 gboolean use_builtin;
1199 gboolean found_default;
1201 g_return_val_if_fail (GTK_IS_ICON_THEME (icon_theme), NULL);
1202 g_return_val_if_fail (icon_name != NULL, NULL);
1203 g_return_val_if_fail ((flags & GTK_ICON_LOOKUP_NO_SVG) == 0 ||
1204 (flags & GTK_ICON_LOOKUP_FORCE_SVG) == 0, NULL);
1206 priv = icon_theme->priv;
1208 GTK_NOTE (ICONTHEME,
1209 g_print ("gtk_icon_theme_lookup_icon %s\n", icon_name));
1210 if (flags & GTK_ICON_LOOKUP_NO_SVG)
1212 else if (flags & GTK_ICON_LOOKUP_FORCE_SVG)
1215 allow_svg = priv->pixbuf_supports_svg;
1217 use_builtin = (flags & GTK_ICON_LOOKUP_USE_BUILTIN);
1219 ensure_valid_themes (icon_theme);
1221 found_default = FALSE;
1225 IconTheme *theme = l->data;
1227 if (strcmp (theme->name, DEFAULT_THEME_NAME) == 0)
1228 found_default = TRUE;
1230 icon_info = theme_lookup_icon (theme, icon_name, size, allow_svg, use_builtin);
1237 g_assert (found_default);
1239 unthemed_icon = g_hash_table_lookup (priv->unthemed_icons, icon_name);
1242 icon_info = icon_info_new ();
1244 /* A SVG icon, when allowed, beats out a XPM icon, but not
1248 unthemed_icon->svg_filename &&
1249 (!unthemed_icon->no_svg_filename ||
1250 suffix_from_name (unthemed_icon->no_svg_filename) != ICON_SUFFIX_PNG))
1251 icon_info->filename = g_strdup (unthemed_icon->svg_filename);
1252 else if (unthemed_icon->no_svg_filename)
1253 icon_info->filename = g_strdup (unthemed_icon->no_svg_filename);
1255 icon_info->cp_filename = g_locale_from_utf8 (icon_info->filename,
1256 -1, NULL, NULL, NULL);
1259 icon_info->dir_type = ICON_THEME_DIR_UNTHEMED;
1264 icon_info->desired_size = size;
1267 static gboolean check_for_default_theme = TRUE;
1268 char *default_theme_path;
1269 gboolean found = FALSE;
1272 if (check_for_default_theme)
1274 check_for_default_theme = FALSE;
1276 for (i = 0; !found && i < priv->search_path_len; i++)
1278 default_theme_path = g_build_filename (priv->search_path[i],
1282 found = g_file_test (default_theme_path, G_FILE_TEST_IS_REGULAR);
1283 g_free (default_theme_path);
1287 g_warning (_("Could not find the icon '%s'. The '%s' theme\n"
1288 "was not found either, perhaps you need to install it.\n"
1289 "You can get a copy from:\n"
1291 icon_name, DEFAULT_THEME_NAME, "http://icon-theme.freedesktop.org/releases");
1301 gtk_icon_theme_error_quark (void)
1303 static GQuark q = 0;
1305 q = g_quark_from_static_string ("gtk-icon-theme-error-quark");
1311 * gtk_icon_theme_load_icon:
1312 * @icon_theme: a #GtkIconTheme
1313 * @icon_name: the name of the icon to lookup
1314 * @size: the desired icon size. The resulting icon may not be
1315 * exactly this size; see gtk_icon_info_load_icon().
1316 * @flags: flags modifying the behavior of the icon lookup
1317 * @error: Location to store error information on failure, or %NULL.
1319 * Looks up an icon in an icon theme, scales it to the given size
1320 * and renders it into a pixbuf. This is a convenience function;
1321 * if more details about the icon are needed, use
1322 * gtk_icon_theme_lookup_icon() followed by gtk_icon_info_load_icon().
1324 * Note that you probably want to listen for icon theme changes and
1325 * update the icon. This is usually done by connecting to the
1326 * GtkWidget::style-set signal. If for some reason you do not want to
1327 * update the icon when the icon theme changes, you should consider
1328 * using gdk_pixbuf_copy() to make a private copy of the pixbuf
1329 * returned by this function. Otherwise GTK+ may need to keep the old
1330 * icon theme loaded, which would be a waste of memory.
1332 * Return value: the rendered icon; this may be a newly created icon
1333 * or a new reference to an internal icon, so you must not modify
1334 * the icon. Use g_object_unref() to release your reference to the
1335 * icon. %NULL if the icon isn't found.
1340 gtk_icon_theme_load_icon (GtkIconTheme *icon_theme,
1341 const gchar *icon_name,
1343 GtkIconLookupFlags flags,
1346 GtkIconInfo *icon_info;
1347 GdkPixbuf *pixbuf = NULL;
1349 g_return_val_if_fail (GTK_IS_ICON_THEME (icon_theme), NULL);
1350 g_return_val_if_fail (icon_name != NULL, NULL);
1351 g_return_val_if_fail ((flags & GTK_ICON_LOOKUP_NO_SVG) == 0 ||
1352 (flags & GTK_ICON_LOOKUP_FORCE_SVG) == 0, NULL);
1353 g_return_val_if_fail (error == NULL || *error == NULL, NULL);
1355 icon_info = gtk_icon_theme_lookup_icon (icon_theme, icon_name, size,
1356 flags | GTK_ICON_LOOKUP_USE_BUILTIN);
1359 g_set_error (error, GTK_ICON_THEME_ERROR, GTK_ICON_THEME_NOT_FOUND,
1360 _("Icon '%s' not present in theme"), icon_name);
1364 pixbuf = gtk_icon_info_load_icon (icon_info, error);
1365 gtk_icon_info_free (icon_info);
1371 * gtk_icon_theme_has_icon:
1372 * @icon_theme: a #GtkIconTheme
1373 * @icon_name: the name of an icon
1375 * Checks whether an icon theme includes an icon
1376 * for a particular name.
1378 * Return value: %TRUE if @icon_theme includes an
1379 * icon for @icon_name.
1384 gtk_icon_theme_has_icon (GtkIconTheme *icon_theme,
1385 const char *icon_name)
1387 GtkIconThemePrivate *priv;
1390 g_return_val_if_fail (GTK_IS_ICON_THEME (icon_theme), FALSE);
1392 priv = icon_theme->priv;
1394 ensure_valid_themes (icon_theme);
1396 for (l = priv->dir_mtimes; l; l = l->next)
1398 IconThemeDirMtime *dir_mtime = l->data;
1399 GtkIconCache *cache = dir_mtime->cache;
1401 if (cache && _gtk_icon_cache_has_icon (cache, icon_name))
1405 if (g_hash_table_lookup_extended (priv->all_icons,
1406 icon_name, NULL, NULL))
1409 if (_builtin_cache &&
1410 _gtk_icon_cache_has_icon (_builtin_cache, icon_name))
1413 if (icon_theme_builtin_icons &&
1414 g_hash_table_lookup_extended (icon_theme_builtin_icons,
1415 icon_name, NULL, NULL))
1422 add_size (gpointer key,
1426 gint **res_p = user_data;
1428 **res_p = GPOINTER_TO_INT (key);
1434 * gtk_icon_theme_get_icon_sizes:
1435 * @icon_theme: a #GtkIconTheme
1436 * @icon_name: the name of an icon
1438 * Returns an array of integers describing the sizes at which
1439 * the icon is available without scaling. A size of -1 means
1440 * that the icon is available in a scalable format. The array
1441 * is zero-terminated.
1443 * Return value: An newly allocated array describing the sizes at
1444 * which the icon is available. The array should be freed with g_free()
1445 * when it is no longer needed.
1450 gtk_icon_theme_get_icon_sizes (GtkIconTheme *icon_theme,
1451 const char *icon_name)
1458 GtkIconThemePrivate *priv;
1460 g_return_val_if_fail (GTK_IS_ICON_THEME (icon_theme), NULL);
1462 priv = icon_theme->priv;
1464 ensure_valid_themes (icon_theme);
1466 sizes = g_hash_table_new (g_direct_hash, g_direct_equal);
1468 for (l = priv->themes; l; l = l->next)
1470 IconTheme *theme = l->data;
1471 for (d = theme->dirs; d; d = d->next)
1473 IconThemeDir *dir = d->data;
1475 suffix = theme_dir_get_icon_suffix (dir, icon_name, NULL);
1476 if (suffix != ICON_SUFFIX_NONE)
1478 if (suffix == ICON_SUFFIX_SVG)
1479 g_hash_table_insert (sizes, GINT_TO_POINTER (-1), NULL);
1481 g_hash_table_insert (sizes, GINT_TO_POINTER (dir->size), NULL);
1486 r = result = g_new0 (gint, g_hash_table_size (sizes) + 1);
1488 g_hash_table_foreach (sizes, add_size, &r);
1489 g_hash_table_destroy (sizes);
1495 add_key_to_hash (gpointer key,
1499 GHashTable *hash = user_data;
1501 g_hash_table_insert (hash, key, NULL);
1505 add_key_to_list (gpointer key,
1509 GList **list = user_data;
1511 *list = g_list_prepend (*list, g_strdup (key));
1515 * gtk_icon_theme_list_icons:
1516 * @icon_theme: a #GtkIconTheme
1517 * @context: a string identifying a particular type of icon,
1518 * or %NULL to list all icons.
1520 * Lists the icons in the current icon theme. Only a subset
1521 * of the icons can be listed by providing a context string.
1522 * The set of values for the context string is system dependent,
1523 * but will typically include such values as 'apps' and
1526 * Return value: a #GList list holding the names of all the
1527 * icons in the theme. You must first free each element
1528 * in the list with g_free(), then free the list itself
1529 * with g_list_free().
1534 gtk_icon_theme_list_icons (GtkIconTheme *icon_theme,
1535 const char *context)
1537 GtkIconThemePrivate *priv;
1540 GQuark context_quark;
1542 priv = icon_theme->priv;
1544 ensure_valid_themes (icon_theme);
1548 context_quark = g_quark_try_string (context);
1556 icons = g_hash_table_new (g_str_hash, g_str_equal);
1561 theme_list_icons (l->data, icons, context_quark);
1565 if (context_quark == 0)
1566 g_hash_table_foreach (priv->unthemed_icons,
1572 g_hash_table_foreach (icons,
1576 g_hash_table_destroy (icons);
1582 * gtk_icon_theme_get_example_icon_name:
1583 * @icon_theme: a #GtkIconTheme
1585 * Gets the name of an icon that is representative of the
1586 * current theme (for instance, to use when presenting
1587 * a list of themes to the user.)
1589 * Return value: the name of an example icon or %NULL.
1590 * Free with g_free().
1595 gtk_icon_theme_get_example_icon_name (GtkIconTheme *icon_theme)
1597 GtkIconThemePrivate *priv;
1601 g_return_val_if_fail (GTK_IS_ICON_THEME (icon_theme), NULL);
1603 priv = icon_theme->priv;
1605 ensure_valid_themes (icon_theme);
1612 return g_strdup (theme->example);
1621 * gtk_icon_theme_rescan_if_needed:
1622 * @icon_theme: a #GtkIconTheme
1624 * Checks to see if the icon theme has changed; if it has, any
1625 * currently cached information is discarded and will be reloaded
1626 * next time @icon_theme is accessed.
1628 * Return value: %TRUE if the icon theme has changed and needed
1634 gtk_icon_theme_rescan_if_needed (GtkIconTheme *icon_theme)
1636 GtkIconThemePrivate *priv;
1637 IconThemeDirMtime *dir_mtime;
1640 struct stat stat_buf;
1643 g_return_val_if_fail (GTK_IS_ICON_THEME (icon_theme), FALSE);
1645 priv = icon_theme->priv;
1647 for (d = priv->dir_mtimes; d != NULL; d = d->next)
1649 dir_mtime = d->data;
1651 stat_res = g_stat (dir_mtime->dir, &stat_buf);
1653 /* dir mtime didn't change */
1654 if (stat_res == 0 &&
1655 S_ISDIR (stat_buf.st_mode) &&
1656 dir_mtime->mtime == stat_buf.st_mtime)
1658 /* didn't exist before, and still doesn't */
1659 if (dir_mtime->mtime == 0 &&
1660 (stat_res != 0 || !S_ISDIR (stat_buf.st_mode)))
1663 do_theme_change (icon_theme);
1667 g_get_current_time (&tv);
1668 priv->last_stat_time = tv.tv_sec;
1674 theme_destroy (IconTheme *theme)
1676 g_free (theme->display_name);
1677 g_free (theme->comment);
1678 g_free (theme->name);
1679 g_free (theme->example);
1681 g_list_foreach (theme->dirs, (GFunc)theme_dir_destroy, NULL);
1682 g_list_free (theme->dirs);
1688 theme_dir_destroy (IconThemeDir *dir)
1691 _gtk_icon_cache_unref (dir->cache);
1693 g_hash_table_destroy (dir->icons);
1696 g_hash_table_destroy (dir->icon_data);
1698 g_free (dir->subdir);
1703 theme_dir_size_difference (IconThemeDir *dir, int size, gboolean *smaller)
1708 case ICON_THEME_DIR_FIXED:
1709 *smaller = size < dir->size;
1710 return abs (size - dir->size);
1712 case ICON_THEME_DIR_SCALABLE:
1713 *smaller = size < dir->min_size;
1714 if (size < dir->min_size)
1715 return dir->min_size - size;
1716 if (size > dir->max_size)
1717 return size - dir->max_size;
1720 case ICON_THEME_DIR_THRESHOLD:
1721 min = dir->size - dir->threshold;
1722 max = dir->size + dir->threshold;
1723 *smaller = size < min;
1730 case ICON_THEME_DIR_UNTHEMED:
1731 g_assert_not_reached ();
1734 g_assert_not_reached ();
1739 string_from_suffix (IconSuffix suffix)
1743 case ICON_SUFFIX_XPM:
1745 case ICON_SUFFIX_SVG:
1747 case ICON_SUFFIX_PNG:
1750 g_assert_not_reached();
1756 suffix_from_name (const char *name)
1760 if (g_str_has_suffix (name, ".png"))
1761 retval = ICON_SUFFIX_PNG;
1762 else if (g_str_has_suffix (name, ".svg"))
1763 retval = ICON_SUFFIX_SVG;
1764 else if (g_str_has_suffix (name, ".xpm"))
1765 retval = ICON_SUFFIX_XPM;
1767 retval = ICON_SUFFIX_NONE;
1773 best_suffix (IconSuffix suffix,
1776 if ((suffix & ICON_SUFFIX_PNG) != 0)
1777 return ICON_SUFFIX_PNG;
1778 else if (allow_svg && ((suffix & ICON_SUFFIX_SVG) != 0))
1779 return ICON_SUFFIX_SVG;
1780 else if ((suffix & ICON_SUFFIX_XPM) != 0)
1781 return ICON_SUFFIX_XPM;
1783 return ICON_SUFFIX_NONE;
1788 theme_dir_get_icon_suffix (IconThemeDir *dir,
1789 const gchar *icon_name,
1790 gboolean *has_icon_file)
1796 suffix = (IconSuffix)_gtk_icon_cache_get_icon_flags (dir->cache,
1801 *has_icon_file = suffix & HAS_ICON_FILE;
1803 suffix = suffix & ~HAS_ICON_FILE;
1806 suffix = GPOINTER_TO_UINT (g_hash_table_lookup (dir->icons, icon_name));
1808 GTK_NOTE (ICONTHEME,
1809 g_print ("get_icon_suffix%s %d\n", dir->cache ? " (cached)" : "", suffix));
1815 _gtk_icon_theme_ensure_builtin_cache (void)
1817 static gboolean initialized = FALSE;
1819 gint sizes[5] = { 16, 20, 24, 32, 48 };
1820 gint n_sizes = G_N_ELEMENTS (sizes);
1827 _builtin_cache = _gtk_icon_cache_new ((gchar *)builtin_icons);
1829 for (i = 0; i < n_sizes; i++)
1831 dir = g_new (IconThemeDir, 1);
1832 dir->type = ICON_THEME_DIR_THRESHOLD;
1834 dir->size = sizes[i];
1835 dir->min_size = sizes[i];
1836 dir->max_size = sizes[i];
1839 dir->icon_data = NULL;
1840 dir->subdir = g_strdup_printf ("%d", sizes[i]);
1841 dir->cache = _gtk_icon_cache_ref (_builtin_cache);
1843 builtin_dirs = g_list_append (builtin_dirs, dir);
1848 static GtkIconInfo *
1849 theme_lookup_icon (IconTheme *theme,
1850 const char *icon_name,
1853 gboolean use_builtin)
1856 IconThemeDir *dir, *min_dir;
1858 int min_difference, difference;
1859 BuiltinIcon *closest_builtin = NULL;
1860 gboolean smaller, has_larger;
1863 min_difference = G_MAXINT;
1867 /* Builtin icons are logically part of the default theme and
1868 * are searched before other subdirectories of the default theme.
1870 _gtk_icon_theme_ensure_builtin_cache ();
1872 if (strcmp (theme->name, DEFAULT_THEME_NAME) == 0 && use_builtin)
1874 closest_builtin = find_builtin_icon (icon_name,
1879 if (min_difference == 0)
1880 return icon_info_new_builtin (closest_builtin);
1882 dirs = builtin_dirs;
1892 GTK_NOTE (ICONTHEME,
1893 g_print ("theme_lookup_icon dir %s\n", dir->dir));
1894 suffix = theme_dir_get_icon_suffix (dir, icon_name, NULL);
1895 if (best_suffix (suffix, allow_svg) != ICON_SUFFIX_NONE)
1897 difference = theme_dir_size_difference (dir, size, &smaller);
1899 if (difference == 0)
1907 if (difference < min_difference || smaller)
1909 min_difference = difference;
1911 closest_builtin = NULL;
1912 has_larger = smaller;
1917 if (difference < min_difference && smaller)
1919 min_difference = difference;
1921 closest_builtin = NULL;
1929 if (l == NULL && dirs == builtin_dirs)
1936 if (closest_builtin)
1937 return icon_info_new_builtin (closest_builtin);
1941 GtkIconInfo *icon_info = icon_info_new ();
1942 gboolean has_icon_file = FALSE;
1944 suffix = theme_dir_get_icon_suffix (min_dir, icon_name, &has_icon_file);
1945 suffix = best_suffix (suffix, allow_svg);
1946 g_assert (suffix != ICON_SUFFIX_NONE);
1948 file = g_strconcat (icon_name, string_from_suffix (suffix), NULL);
1949 icon_info->filename = g_build_filename (min_dir->dir, file, NULL);
1952 icon_info->cp_filename = g_locale_from_utf8 (icon_info->filename,
1953 -1, NULL, NULL, NULL);
1956 if (min_dir->icon_data != NULL)
1957 icon_info->data = g_hash_table_lookup (min_dir->icon_data, icon_name);
1959 if (icon_info->data == NULL && min_dir->cache != NULL)
1961 icon_info->data = _gtk_icon_cache_get_icon_data (min_dir->cache, icon_name, min_dir->subdir);
1962 if (icon_info->data)
1964 if (min_dir->icon_data == NULL)
1965 min_dir->icon_data = g_hash_table_new_full (g_str_hash, g_str_equal,
1966 g_free, (GDestroyNotify)icon_data_free);
1968 g_hash_table_replace (min_dir->icon_data, g_strdup (icon_name), icon_info->data);
1972 if (icon_info->data == NULL && has_icon_file)
1974 gchar *icon_file_name, *icon_file_path;
1976 icon_file_name = g_strconcat (icon_name, ".icon", NULL);
1977 icon_file_path = g_build_filename (min_dir->dir, icon_file_name, NULL);
1979 if (g_file_test (icon_file_path, G_FILE_TEST_IS_REGULAR))
1981 if (min_dir->icon_data == NULL)
1982 min_dir->icon_data = g_hash_table_new_full (g_str_hash, g_str_equal,
1983 g_free, (GDestroyNotify)icon_data_free);
1984 load_icon_data (min_dir, icon_file_path, icon_file_name);
1986 icon_info->data = g_hash_table_lookup (min_dir->icon_data, icon_name);
1988 g_free (icon_file_name);
1989 g_free (icon_file_path);
1994 icon_info->cache_pixbuf = _gtk_icon_cache_get_icon (min_dir->cache, icon_name,
1998 icon_info->dir_type = min_dir->type;
1999 icon_info->dir_size = min_dir->size;
2000 icon_info->threshold = min_dir->threshold;
2009 theme_list_icons (IconTheme *theme, GHashTable *icons,
2012 GList *l = theme->dirs;
2019 if (context == dir->context ||
2024 _gtk_icon_cache_add_icons (dir->cache,
2031 g_hash_table_foreach (dir->icons,
2041 load_icon_data (IconThemeDir *dir, const char *path, const char *name)
2043 GKeyFile *icon_file;
2052 GError *error = NULL;
2056 icon_file = g_key_file_new ();
2057 g_key_file_set_list_separator (icon_file, ',');
2058 g_key_file_load_from_file (icon_file, path, 0, &error);
2061 g_error_free (error);
2066 base_name = g_strdup (name);
2067 dot = strrchr (base_name, '.');
2070 data = g_new0 (GtkIconData, 1);
2071 g_hash_table_replace (dir->icon_data, base_name, data);
2073 ivalues = g_key_file_get_integer_list (icon_file,
2074 "Icon Data", "EmbeddedTextRectangle",
2080 data->has_embedded_rect = TRUE;
2081 data->x0 = ivalues[0];
2082 data->y0 = ivalues[1];
2083 data->x1 = ivalues[2];
2084 data->y1 = ivalues[3];
2090 str = g_key_file_get_string (icon_file, "Icon Data", "AttachPoints", NULL);
2093 split = g_strsplit (str, "|", -1);
2095 data->n_attach_points = g_strv_length (split);
2096 data->attach_points = g_malloc (sizeof (GdkPoint) * data->n_attach_points);
2099 while (split[i] != NULL && i < data->n_attach_points)
2101 split_point = strchr (split[i], ',');
2106 data->attach_points[i].x = atoi (split[i]);
2107 data->attach_points[i].y = atoi (split_point);
2116 data->display_name = g_key_file_get_locale_string (icon_file,
2117 "Icon Data", "DisplayName",
2119 g_key_file_free (icon_file);
2124 scan_directory (GtkIconThemePrivate *icon_theme,
2125 IconThemeDir *dir, char *full_dir)
2129 char *base_name, *dot;
2131 IconSuffix suffix, hash_suffix;
2133 GTK_NOTE (ICONTHEME,
2134 g_print ("scanning directory %s\n", full_dir));
2135 dir->icons = g_hash_table_new_full (g_str_hash, g_str_equal,
2138 gdir = g_dir_open (full_dir, 0, NULL);
2143 while ((name = g_dir_read_name (gdir)))
2145 if (g_str_has_suffix (name, ".icon"))
2147 if (dir->icon_data == NULL)
2148 dir->icon_data = g_hash_table_new_full (g_str_hash, g_str_equal,
2149 g_free, (GDestroyNotify)icon_data_free);
2151 path = g_build_filename (full_dir, name, NULL);
2152 if (g_file_test (path, G_FILE_TEST_IS_REGULAR))
2153 load_icon_data (dir, path, name);
2160 suffix = suffix_from_name (name);
2161 if (suffix == ICON_SUFFIX_NONE)
2164 base_name = g_strdup (name);
2165 dot = strrchr (base_name, '.');
2168 hash_suffix = GPOINTER_TO_INT (g_hash_table_lookup (dir->icons, base_name));
2169 g_hash_table_replace (dir->icons, base_name, GUINT_TO_POINTER (hash_suffix| suffix));
2170 g_hash_table_insert (icon_theme->all_icons, base_name, NULL);
2177 theme_subdir_load (GtkIconTheme *icon_theme,
2179 GKeyFile *theme_file,
2185 IconThemeDirType type;
2186 char *context_string;
2193 GError *error = NULL;
2194 IconThemeDirMtime *dir_mtime;
2196 size = g_key_file_get_integer (theme_file, subdir, "Size", &error);
2199 g_error_free (error);
2200 g_warning ("Theme directory %s of theme %s has no size field\n",
2201 subdir, theme->name);
2205 type = ICON_THEME_DIR_THRESHOLD;
2206 type_string = g_key_file_get_string (theme_file, subdir, "Type", NULL);
2209 if (strcmp (type_string, "Fixed") == 0)
2210 type = ICON_THEME_DIR_FIXED;
2211 else if (strcmp (type_string, "Scalable") == 0)
2212 type = ICON_THEME_DIR_SCALABLE;
2213 else if (strcmp (type_string, "Threshold") == 0)
2214 type = ICON_THEME_DIR_THRESHOLD;
2216 g_free (type_string);
2220 context_string = g_key_file_get_string (theme_file, subdir, "Context", NULL);
2223 context = g_quark_from_string (context_string);
2224 g_free (context_string);
2227 max_size = g_key_file_get_integer (theme_file, subdir, "MaxSize", &error);
2232 g_error_free (error);
2236 min_size = g_key_file_get_integer (theme_file, subdir, "MinSize", &error);
2241 g_error_free (error);
2245 threshold = g_key_file_get_integer (theme_file, subdir, "Threshold", &error);
2250 g_error_free (error);
2254 for (d = icon_theme->priv->dir_mtimes; d; d = d->next)
2256 dir_mtime = (IconThemeDirMtime *)d->data;
2258 if (dir_mtime->mtime == 0)
2259 continue; /* directory doesn't exist */
2261 full_dir = g_build_filename (dir_mtime->dir, subdir, NULL);
2263 /* First, see if we have a cache for the directory */
2264 if (dir_mtime->cache != NULL || g_file_test (full_dir, G_FILE_TEST_IS_DIR))
2266 if (dir_mtime->cache == NULL)
2268 /* This will return NULL if the cache doesn't exist or is outdated */
2269 dir_mtime->cache = _gtk_icon_cache_new_for_path (dir_mtime->dir);
2272 dir = g_new (IconThemeDir, 1);
2274 dir->context = context;
2276 dir->min_size = min_size;
2277 dir->max_size = max_size;
2278 dir->threshold = threshold;
2279 dir->dir = full_dir;
2280 dir->icon_data = NULL;
2281 dir->subdir = g_strdup (subdir);
2282 if (dir_mtime->cache != NULL)
2283 dir->cache = _gtk_icon_cache_ref (dir_mtime->cache);
2287 scan_directory (icon_theme->priv, dir, full_dir);
2290 theme->dirs = g_list_prepend (theme->dirs, dir);
2298 icon_data_free (GtkIconData *icon_data)
2300 g_free (icon_data->attach_points);
2301 g_free (icon_data->display_name);
2309 gtk_icon_info_get_type (void)
2311 static GType our_type = 0;
2314 our_type = g_boxed_type_register_static (I_("GtkIconInfo"),
2315 (GBoxedCopyFunc) gtk_icon_info_copy,
2316 (GBoxedFreeFunc) gtk_icon_info_free);
2321 static GtkIconInfo *
2322 icon_info_new (void)
2324 GtkIconInfo *icon_info = g_new0 (GtkIconInfo, 1);
2326 icon_info->scale = -1.;
2331 static GtkIconInfo *
2332 icon_info_new_builtin (BuiltinIcon *icon)
2334 GtkIconInfo *icon_info = icon_info_new ();
2336 icon_info->cache_pixbuf = g_object_ref (icon->pixbuf);
2337 icon_info->dir_type = ICON_THEME_DIR_THRESHOLD;
2338 icon_info->dir_size = icon->size;
2339 icon_info->threshold = 2;
2345 * gtk_icon_info_copy:
2346 * @icon_info: a #GtkIconInfo
2348 * Make a copy of a #GtkIconInfo.
2350 * Return value: the new GtkIconInfo
2355 gtk_icon_info_copy (GtkIconInfo *icon_info)
2359 g_return_val_if_fail (icon_info != NULL, NULL);
2361 copy = g_memdup (icon_info, sizeof (GtkIconInfo));
2362 if (copy->cache_pixbuf)
2363 g_object_ref (copy->cache_pixbuf);
2365 g_object_ref (copy->pixbuf);
2366 if (copy->load_error)
2367 copy->load_error = g_error_copy (copy->load_error);
2369 copy->filename = g_strdup (copy->filename);
2371 if (copy->cp_filename)
2372 copy->cp_filename = g_strdup (copy->cp_filename);
2379 * gtk_icon_info_free:
2380 * @icon_info: a #GtkIconInfo
2382 * Free a #GtkIconInfo and associated information
2387 gtk_icon_info_free (GtkIconInfo *icon_info)
2389 g_return_if_fail (icon_info != NULL);
2391 if (icon_info->filename)
2392 g_free (icon_info->filename);
2394 if (icon_info->cp_filename)
2395 g_free (icon_info->cp_filename);
2397 if (icon_info->pixbuf)
2398 g_object_unref (icon_info->pixbuf);
2399 if (icon_info->cache_pixbuf)
2400 g_object_unref (icon_info->cache_pixbuf);
2406 * gtk_icon_info_get_base_size:
2407 * @icon_info: a #GtkIconInfo
2409 * Gets the base size for the icon. The base size
2410 * is a size for the icon that was specified by
2411 * the icon theme creator. This may be different
2412 * than the actual size of image; an example of
2413 * this is small emblem icons that can be attached
2414 * to a larger icon. These icons will be given
2415 * the same base size as the larger icons to which
2416 * they are attached.
2418 * Return value: the base size, or 0, if no base
2419 * size is known for the icon.
2424 gtk_icon_info_get_base_size (GtkIconInfo *icon_info)
2426 g_return_val_if_fail (icon_info != NULL, 0);
2428 return icon_info->dir_size;
2432 * gtk_icon_info_get_filename:
2433 * @icon_info: a #GtkIconInfo
2435 * Gets the filename for the icon. If the
2436 * %GTK_ICON_LOOKUP_USE_BUILTIN flag was passed
2437 * to gtk_icon_theme_lookup_icon(), there may be
2438 * no filename if a builtin icon is returned; in this
2439 * case, you should use gtk_icon_info_get_builtin_pixbuf().
2441 * Return value: the filename for the icon, or %NULL
2442 * if gtk_icon_info_get_builtin_pixbuf() should
2443 * be used instead. The return value is owned by
2444 * GTK+ and should not be modified or freed.
2448 G_CONST_RETURN gchar *
2449 gtk_icon_info_get_filename (GtkIconInfo *icon_info)
2451 g_return_val_if_fail (icon_info != NULL, NULL);
2453 return icon_info->filename;
2457 * gtk_icon_info_get_builtin_pixbuf:
2458 * @icon_info: a #GtkIconInfo structure
2460 * Gets the built-in image for this icon, if any. To allow
2461 * GTK+ to use built in icon images, you must pass the
2462 * %GTK_ICON_LOOKUP_USE_BUILTIN to
2463 * gtk_icon_theme_lookup_icon().
2465 * Return value: the built-in image pixbuf, or %NULL. No
2466 * extra reference is added to the returned pixbuf, so if
2467 * you want to keep it around, you must use g_object_ref().
2468 * The returned image must not be modified.
2473 gtk_icon_info_get_builtin_pixbuf (GtkIconInfo *icon_info)
2475 g_return_val_if_fail (icon_info != NULL, NULL);
2477 if (icon_info->filename)
2480 return icon_info->cache_pixbuf;
2484 load_svg_at_size (const gchar *filename,
2488 GdkPixbuf *pixbuf = NULL;
2489 GdkPixbufLoader *loader = NULL;
2490 gchar *contents = NULL;
2493 if (!g_file_get_contents (filename,
2494 &contents, &length, error))
2497 loader = gdk_pixbuf_loader_new_with_type ("svg", error);
2501 gdk_pixbuf_loader_set_size (loader, size, size);
2503 if (!gdk_pixbuf_loader_write (loader, contents, length, error))
2505 gdk_pixbuf_loader_close (loader, NULL);
2509 if (!gdk_pixbuf_loader_close (loader, error))
2512 pixbuf = g_object_ref (gdk_pixbuf_loader_get_pixbuf (loader));
2516 g_object_unref (loader);
2523 /* This function contains the complicatd logic for deciding
2524 * on the size at which to load the icon and loading it at
2528 icon_info_ensure_scale_and_pixbuf (GtkIconInfo *icon_info,
2529 gboolean scale_only)
2531 int image_width, image_height;
2532 GdkPixbuf *source_pixbuf;
2534 /* First check if we already succeeded have the necessary
2535 * information (or failed earlier)
2537 if (scale_only && icon_info->scale >= 0)
2540 if (icon_info->pixbuf)
2543 if (icon_info->load_error)
2546 /* SVG icons are a special case - we just immediately scale them
2547 * to the desired size
2549 if (icon_info->filename && g_str_has_suffix (icon_info->filename, ".svg"))
2551 icon_info->scale = icon_info->desired_size / 1000.;
2556 icon_info->pixbuf = load_svg_at_size (icon_info->filename,
2557 icon_info->desired_size,
2558 &icon_info->load_error);
2560 return icon_info->pixbuf != NULL;
2563 /* In many cases, the scale can be determined without actual access
2564 * to the icon file. This is generally true when we have a size
2565 * for the directory where the icon is; the image size doesn't
2566 * matter in that case.
2568 if (icon_info->dir_type == ICON_THEME_DIR_FIXED)
2569 icon_info->scale = 1.0;
2570 else if (icon_info->dir_type == ICON_THEME_DIR_THRESHOLD)
2572 if (icon_info->desired_size >= icon_info->dir_size - icon_info->threshold &&
2573 icon_info->desired_size <= icon_info->dir_size + icon_info->threshold)
2574 icon_info->scale = 1.0;
2575 else if (icon_info->dir_size > 0)
2576 icon_info->scale =(gdouble) icon_info->desired_size / icon_info->dir_size;
2578 else if (icon_info->dir_type == ICON_THEME_DIR_SCALABLE)
2580 if (icon_info->dir_size > 0)
2581 icon_info->scale = (gdouble) icon_info->desired_size / icon_info->dir_size;
2584 if (icon_info->scale >= 0. && scale_only)
2587 /* At this point, we need to actually get the icon; either from the
2588 * builting image or by loading the file
2590 if (icon_info->cache_pixbuf)
2591 source_pixbuf = g_object_ref (icon_info->cache_pixbuf);
2595 source_pixbuf = gdk_pixbuf_new_from_file (icon_info->filename,
2596 &icon_info->load_error);
2601 /* Do scale calculations that depend on the image size
2603 image_width = gdk_pixbuf_get_width (source_pixbuf);
2604 image_height = gdk_pixbuf_get_height (source_pixbuf);
2606 if (icon_info->scale < 0.0)
2608 gint image_size = MAX (image_width, image_height);
2610 icon_info->scale = icon_info->desired_size / (gdouble)image_size;
2612 icon_info->scale = 1.0;
2614 if (icon_info->dir_type == ICON_THEME_DIR_UNTHEMED)
2615 icon_info->scale = MIN (icon_info->scale, 1.0);
2618 /* We don't short-circuit out here for scale_only, since, now
2619 * we've loaded the icon, we might as well go ahead and finish
2620 * the job. This is a bit of a waste when we scale here
2621 * and never get the final pixbuf; at the cost of a bit of
2622 * extra complexity, we could keep the source pixbuf around
2623 * but not actually scale it until neede.
2626 if (icon_info->scale == 1.0)
2627 icon_info->pixbuf = source_pixbuf;
2630 icon_info->pixbuf = gdk_pixbuf_scale_simple (source_pixbuf,
2631 0.5 + image_width * icon_info->scale,
2632 0.5 + image_height * icon_info->scale,
2633 GDK_INTERP_BILINEAR);
2634 g_object_unref (source_pixbuf);
2641 * gtk_icon_info_load_icon:
2642 * @icon_info: a #GtkIconInfo structure from gtk_icon_theme_lookup_icon()
2643 * @error: location to store error information on failure, or %NULL.
2645 * Renders an icon previously looked up in an icon theme using
2646 * gtk_icon_theme_lookup_icon(); the size will be based on the size
2647 * passed to gtk_icon_theme_lookup_icon(). Note that the resulting
2648 * pixbuf may not be exactly this size; an icon theme may have icons
2649 * that differ slightly from their nominal sizes, and in addition GTK+
2650 * will avoid scaling icons that it considers sufficiently close to the
2651 * requested size or for which the source image would have to be scaled
2652 * up too far. (This maintains sharpness.)
2654 * Return value: the rendered icon; this may be a newly created icon
2655 * or a new reference to an internal icon, so you must not modify
2656 * the icon. Use g_object_unref() to release your reference to the
2662 gtk_icon_info_load_icon (GtkIconInfo *icon_info,
2665 g_return_val_if_fail (icon_info != NULL, NULL);
2667 g_return_val_if_fail (icon_info != NULL, NULL);
2668 g_return_val_if_fail (error == NULL || *error == NULL, NULL);
2670 icon_info_ensure_scale_and_pixbuf (icon_info, FALSE);
2672 if (icon_info->load_error)
2674 g_propagate_error (error, icon_info->load_error);
2678 return g_object_ref (icon_info->pixbuf);
2682 * gtk_icon_info_set_raw_coordinates:
2683 * @icon_info: a #GtkIconInfo
2684 * @raw_coordinates: whether the coordinates of embedded rectangles
2685 * and attached points should be returned in their original
2688 * Sets whether the coordinates returned by gtk_icon_info_get_embedded_rect()
2689 * and gtk_icon_info_get_attach_points() should be returned in their
2690 * original form as specified in the icon theme, instead of scaled
2691 * appropriately for the pixbuf returned by gtk_icon_info_load_icon().
2693 * Raw coordinates are somewhat strange; they are specified to be with
2694 * respect to the unscaled pixmap for PNG and XPM icons, but for SVG
2695 * icons, they are in a 1000x1000 coordinate space that is scaled
2696 * to the final size of the icon. You can determine if the icon is an SVG
2697 * icon by using gtk_icon_info_get_filename(), and seeing if it is non-%NULL
2698 * and ends in '.svg'.
2700 * This function is provided primarily to allow compatibility wrappers
2701 * for older API's, and is not expected to be useful for applications.
2706 gtk_icon_info_set_raw_coordinates (GtkIconInfo *icon_info,
2707 gboolean raw_coordinates)
2709 g_return_if_fail (icon_info != NULL);
2711 icon_info->raw_coordinates = raw_coordinates != FALSE;
2714 /* Scale coordinates from the icon data prior to returning
2718 icon_info_scale_point (GtkIconInfo *icon_info,
2724 if (icon_info->raw_coordinates)
2731 if (!icon_info_ensure_scale_and_pixbuf (icon_info, TRUE))
2734 *x_out = 0.5 + x * icon_info->scale;
2735 *y_out = 0.5 + y * icon_info->scale;
2742 * gtk_icon_info_get_embedded_rect:
2743 * @icon_info: a #GtkIconInfo
2744 * @rectangle: #GdkRectangle in which to store embedded
2745 * rectangle coordinates; coordinates are only stored
2746 * when this function returns %TRUE.
2748 * Gets the coordinates of a rectangle within the icon
2749 * that can be used for display of information such
2750 * as a preview of the contents of a text file.
2751 * See gtk_icon_info_set_raw_coordinates() for further
2752 * information about the coordinate system.
2754 * Return value: %TRUE if the icon has an embedded rectangle
2759 gtk_icon_info_get_embedded_rect (GtkIconInfo *icon_info,
2760 GdkRectangle *rectangle)
2762 g_return_val_if_fail (icon_info != NULL, FALSE);
2764 if (icon_info->data && icon_info->data->has_embedded_rect &&
2765 icon_info_ensure_scale_and_pixbuf (icon_info, TRUE))
2767 gint scaled_x0, scaled_y0;
2768 gint scaled_x1, scaled_y1;
2772 icon_info_scale_point (icon_info,
2773 icon_info->data->x0, icon_info->data->y0,
2774 &scaled_x0, &scaled_y0);
2775 icon_info_scale_point (icon_info,
2776 icon_info->data->x1, icon_info->data->y1,
2777 &scaled_x1, &scaled_y1);
2779 rectangle->x = scaled_x0;
2780 rectangle->y = scaled_y0;
2781 rectangle->width = scaled_x1 - rectangle->x;
2782 rectangle->height = scaled_y1 - rectangle->y;
2792 * gtk_icon_info_get_attach_points:
2793 * @icon_info: a #GtkIconInfo
2794 * @points: location to store pointer to an array of points, or %NULL
2795 * free the array of points with g_free().
2796 * @n_points: location to store the number of points in @points, or %NULL
2798 * Fetches the set of attach points for an icon. An attach point
2799 * is a location in the icon that can be used as anchor points for attaching
2800 * emblems or overlays to the icon.
2802 * Return value: %TRUE if there are any attach points for the icon.
2807 gtk_icon_info_get_attach_points (GtkIconInfo *icon_info,
2811 g_return_val_if_fail (icon_info != NULL, FALSE);
2813 if (icon_info->data && icon_info->data->n_attach_points &&
2814 icon_info_ensure_scale_and_pixbuf (icon_info, TRUE))
2820 *points = g_new (GdkPoint, icon_info->data->n_attach_points);
2821 for (i = 0; i < icon_info->data->n_attach_points; i++)
2822 icon_info_scale_point (icon_info,
2823 icon_info->data->attach_points[i].x,
2824 icon_info->data->attach_points[i].y,
2830 *n_points = icon_info->data->n_attach_points;
2846 * gtk_icon_info_get_display_name:
2847 * @icon_info: a #GtkIconInfo
2849 * Gets the display name for an icon. A display name is a
2850 * string to be used in place of the icon name in a user
2851 * visible context like a list of icons.
2853 * Return value: the display name for the icon or %NULL, if
2854 * the icon doesn't have a specified display name. This value
2855 * is owned @icon_info and must not be modified or free.
2859 G_CONST_RETURN gchar *
2860 gtk_icon_info_get_display_name (GtkIconInfo *icon_info)
2862 g_return_val_if_fail (icon_info != NULL, NULL);
2864 if (icon_info->data)
2865 return icon_info->data->display_name;
2876 * gtk_icon_theme_add_builtin_icon:
2877 * @icon_name: the name of the icon to register
2878 * @size: the size at which to register the icon (different
2879 * images can be registered for the same icon name
2880 * at different sizes.)
2881 * @pixbuf: #GdkPixbuf that contains the image to use
2884 * Registers a built-in icon for icon theme lookups. The idea
2885 * of built-in icons is to allow an application or library
2886 * that uses themed icons to function requiring files to
2887 * be present in the file system. For instance, the default
2888 * images for all of GTK+'s stock icons are registered
2891 * In general, if you use gtk_icon_theme_add_builtin_icon()
2892 * you should also install the icon in the icon theme, so
2893 * that the icon is generally available.
2895 * This function will generally be used with pixbufs loaded
2896 * via gdk_pixbuf_new_from_inline().
2901 gtk_icon_theme_add_builtin_icon (const gchar *icon_name,
2905 BuiltinIcon *default_icon;
2909 g_return_if_fail (icon_name != NULL);
2910 g_return_if_fail (GDK_IS_PIXBUF (pixbuf));
2912 if (!icon_theme_builtin_icons)
2913 icon_theme_builtin_icons = g_hash_table_new (g_str_hash, g_str_equal);
2915 icons = g_hash_table_lookup (icon_theme_builtin_icons, icon_name);
2917 key = g_strdup (icon_name);
2919 key = (gpointer)icon_name; /* Won't get stored */
2921 default_icon = g_new (BuiltinIcon, 1);
2922 default_icon->size = size;
2923 default_icon->pixbuf = g_object_ref (pixbuf);
2924 icons = g_slist_prepend (icons, default_icon);
2926 /* Replaces value, leaves key untouched
2928 g_hash_table_insert (icon_theme_builtin_icons, key, icons);
2931 /* Look up a builtin icon; the min_difference_p and
2932 * has_larger_p out parameters allow us to combine
2933 * this lookup with searching through the actual directories
2934 * of the "hicolor" icon theme. See theme_lookup_icon()
2935 * for how they are used.
2937 static BuiltinIcon *
2938 find_builtin_icon (const gchar *icon_name,
2940 gint *min_difference_p,
2941 gboolean *has_larger_p)
2943 GSList *icons = NULL;
2944 gint min_difference = G_MAXINT;
2945 gboolean has_larger = FALSE;
2946 BuiltinIcon *min_icon = NULL;
2948 _gtk_icon_factory_ensure_default_icons ();
2950 if (!icon_theme_builtin_icons)
2953 icons = g_hash_table_lookup (icon_theme_builtin_icons, icon_name);
2957 BuiltinIcon *default_icon = icons->data;
2958 int min, max, difference;
2961 min = default_icon->size - 2;
2962 max = default_icon->size + 2;
2963 smaller = size < min;
2965 difference = min - size;
2966 else if (size > max)
2967 difference = size - max;
2971 if (difference == 0)
2973 min_icon = default_icon;
2979 if (difference < min_difference || smaller)
2981 min_difference = difference;
2982 min_icon = default_icon;
2983 has_larger = smaller;
2988 if (difference < min_difference && smaller)
2990 min_difference = difference;
2991 min_icon = default_icon;
2995 icons = icons->next;
2998 if (min_difference_p)
2999 *min_difference_p = min_difference;
3001 *has_larger_p = has_larger;
3007 _gtk_icon_theme_check_reload (GdkDisplay *display)
3011 GtkIconTheme *icon_theme;
3013 n_screens = gdk_display_get_n_screens (display);
3015 for (i = 0; i < n_screens; i++)
3017 screen = gdk_display_get_screen (display, i);
3019 icon_theme = g_object_get_data (G_OBJECT (screen), "gtk-icon-theme");
3022 icon_theme->priv->check_reload = TRUE;
3023 ensure_valid_themes (icon_theme);
3024 icon_theme->priv->check_reload = FALSE;
3031 /* DLL ABI stability backward compatibility versions */
3033 #undef gtk_icon_theme_set_search_path
3036 gtk_icon_theme_set_search_path (GtkIconTheme *icon_theme,
3037 const gchar *path[],
3040 const gchar **utf8_path;
3043 utf8_path = g_new (const gchar *, n_elements);
3045 for (i = 0; i < n_elements; i++)
3046 utf8_path[i] = g_locale_to_utf8 (path[i], -1, NULL, NULL, NULL);
3048 gtk_icon_theme_set_search_path_utf8 (icon_theme, utf8_path, n_elements);
3050 for (i = 0; i < n_elements; i++)
3051 g_free ((gchar *) utf8_path[i]);
3056 #undef gtk_icon_theme_get_search_path
3059 gtk_icon_theme_get_search_path (GtkIconTheme *icon_theme,
3065 gtk_icon_theme_get_search_path_utf8 (icon_theme, path, &n);
3072 for (i = 0; i < n; i++)
3074 gchar *tem = (*path)[i];
3076 (*path)[i] = g_locale_from_utf8 ((*path)[i], -1, NULL, NULL, NULL);
3082 #undef gtk_icon_theme_append_search_path
3085 gtk_icon_theme_append_search_path (GtkIconTheme *icon_theme,
3088 gchar *utf8_path = g_locale_from_utf8 (path, -1, NULL, NULL, NULL);
3090 gtk_icon_theme_append_search_path_utf8 (icon_theme, utf8_path);
3095 #undef gtk_icon_theme_prepend_search_path
3098 gtk_icon_theme_prepend_search_path (GtkIconTheme *icon_theme,
3101 gchar *utf8_path = g_locale_from_utf8 (path, -1, NULL, NULL, NULL);
3103 gtk_icon_theme_prepend_search_path_utf8 (icon_theme, utf8_path);
3108 #undef gtk_icon_info_get_filename
3110 G_CONST_RETURN gchar *
3111 gtk_icon_info_get_filename (GtkIconInfo *icon_info)
3113 g_return_val_if_fail (icon_info != NULL, NULL);
3115 return icon_info->cp_filename;
3120 #define __GTK_ICON_THEME_C__
3121 #include "gtkaliasdef.c"