#include <string.h>
#include <stdlib.h>
#include <glib.h>
+#include <glib/gstdio.h>
#ifdef G_OS_WIN32
#ifndef S_ISDIR
#endif /* G_OS_WIN32 */
#include "gtkicontheme.h"
-#include "gtkiconthemeparser.h"
+#include "gtkiconfactory.h"
+#include "gtkiconcache.h"
+#include "gtkbuiltincache.h"
#include "gtkintl.h"
+#include "gtkmain.h"
#include "gtksettings.h"
#include "gtkprivate.h"
+#include "gtkalias.h"
#define DEFAULT_THEME_NAME "hicolor"
-typedef struct _GtkIconData GtkIconData;
-
typedef enum
{
ICON_THEME_DIR_FIXED,
ICON_SUFFIX_NONE = 0,
ICON_SUFFIX_XPM = 1 << 0,
ICON_SUFFIX_SVG = 1 << 1,
- ICON_SUFFIX_PNG = 1 << 2,
+ ICON_SUFFIX_PNG = 1 << 2,
+ HAS_ICON_FILE = 1 << 3
} IconSuffix;
struct _GtkIconThemePrivate
{
- guint custom_theme : 1;
+ guint custom_theme : 1;
guint is_screen_singleton : 1;
guint pixbuf_supports_svg : 1;
+ guint themes_valid : 1;
+ guint check_reload : 1;
char *current_theme;
+ char *fallback_theme;
char **search_path;
int search_path_len;
- gboolean themes_valid;
/* A list of all the themes needed to look up icons.
* In search order, without duplicates
*/
GList *themes;
GHashTable *unthemed_icons;
-
+
/* Note: The keys of this hashtable are owned by the
* themedir and unthemed hashtables.
*/
/* time when we last stat:ed for theme changes */
long last_stat_time;
GList *dir_mtimes;
+
+ gulong reset_styles_idle;
};
struct _GtkIconInfo
{
- guint ref_count;
-
/* Information about the source
*/
gchar *filename;
- GdkPixbuf *builtin_pixbuf;
+#ifdef G_OS_WIN32
+ /* System codepage version of filename, for DLL ABI backward
+ * compatibility functions.
+ */
+ gchar *cp_filename;
+#endif
+ /* Cache pixbuf (if there is any) */
+ GdkPixbuf *cache_pixbuf;
GtkIconData *data;
GList *dirs;
} IconTheme;
-struct _GtkIconData
-{
- gboolean has_embedded_rect;
- gint x0, y0, x1, y1;
-
- GdkPoint *attach_points;
- gint n_attach_points;
-
- gchar *display_name;
-};
-
typedef struct
{
IconThemeDirType type;
int threshold;
char *dir;
+ char *subdir;
+
+ GtkIconCache *cache;
GHashTable *icons;
GHashTable *icon_data;
{
char *dir;
time_t mtime; /* 0 == not existing or not a dir */
+
+ GtkIconCache *cache;
} IconThemeDirMtime;
-static void gtk_icon_theme_class_init (GtkIconThemeClass *klass);
-static void gtk_icon_theme_init (GtkIconTheme *icon_theme);
static void gtk_icon_theme_finalize (GObject *object);
static void theme_dir_destroy (IconThemeDir *dir);
GQuark context);
static void theme_subdir_load (GtkIconTheme *icon_theme,
IconTheme *theme,
- GtkIconThemeFile *theme_file,
+ GKeyFile *theme_file,
char *subdir);
static void do_theme_change (GtkIconTheme *icon_theme);
static void blow_themes (GtkIconTheme *icon_themes);
-static void icon_data_free (GtkIconData *icon_data);
+static void icon_data_free (GtkIconData *icon_data);
+static void load_icon_data (IconThemeDir *dir,
+ const char *path,
+ const char *name);
+
+static IconSuffix theme_dir_get_icon_suffix (IconThemeDir *dir,
+ const gchar *icon_name,
+ gboolean *has_icon_file);
+
static GtkIconInfo *icon_info_new (void);
static GtkIconInfo *icon_info_new_builtin (BuiltinIcon *icon);
static IconSuffix suffix_from_name (const char *name);
static BuiltinIcon *find_builtin_icon (const gchar *icon_name,
- gint size,
+ gint size,
gint *min_difference_p,
gboolean *has_larger_p);
static GHashTable *icon_theme_builtin_icons;
-GType
-gtk_icon_theme_get_type (void)
-{
- static GType type = 0;
-
- if (type == 0)
- {
- static const GTypeInfo info =
- {
- sizeof (GtkIconThemeClass),
- NULL, /* base_init */
- NULL, /* base_finalize */
- (GClassInitFunc) gtk_icon_theme_class_init,
- NULL, /* class_finalize */
- NULL, /* class_data */
- sizeof (GtkIconTheme),
- 0, /* n_preallocs */
- (GInstanceInitFunc) gtk_icon_theme_init,
- };
-
- type = g_type_register_static (G_TYPE_OBJECT, "GtkIconTheme", &info, 0);
- }
+/* also used in gtkiconfactory.c */
+GtkIconCache *_builtin_cache = NULL;
+static GList *builtin_dirs = NULL;
- return type;
-}
+G_DEFINE_TYPE (GtkIconTheme, gtk_icon_theme, G_TYPE_OBJECT)
/**
* gtk_icon_theme_new:
* Return value: A unique #GtkIconTheme associated with
* the default screen. This icon theme is associated with
* the screen and can be used as long as the screen
- * is open.
+ * is open. Do not ref or unref it.
*
* Since: 2.4
**/
* Return value: A unique #GtkIconTheme associated with
* the given screen. This icon theme is associated with
* the screen and can be used as long as the screen
- * is open.
+ * is open. Do not ref or unref it.
*
* Since: 2.4
**/
priv = icon_theme->priv;
priv->is_screen_singleton = TRUE;
- g_object_set_data (G_OBJECT (screen), "gtk-icon-theme", icon_theme);
+ g_object_set_data (G_OBJECT (screen), I_("gtk-icon-theme"), icon_theme);
}
return icon_theme;
* that a change has occurred in the contents of the current
* icon theme.
**/
- signal_changed = g_signal_new ("changed",
+ signal_changed = g_signal_new (I_("changed"),
G_TYPE_FROM_CLASS (klass),
G_SIGNAL_RUN_LAST,
G_STRUCT_OFFSET (GtkIconThemeClass, changed),
if (was_screen_singleton)
{
- g_object_set_data (G_OBJECT (screen), "gtk-icon-theme", NULL);
+ g_object_set_data (G_OBJECT (screen), I_("gtk-icon-theme"), NULL);
priv->is_screen_singleton = FALSE;
}
if (!priv->custom_theme)
{
gchar *theme = NULL;
+ gchar *fallback_theme = NULL;
+ gboolean changed = FALSE;
if (priv->screen)
{
GtkSettings *settings = gtk_settings_get_for_screen (priv->screen);
- g_object_get (settings, "gtk-icon-theme-name", &theme, NULL);
+ g_object_get (settings,
+ "gtk-icon-theme-name", &theme,
+ "gtk-fallback-icon-theme", &fallback_theme, NULL);
}
if (!theme)
g_free (priv->current_theme);
priv->current_theme = theme;
- do_theme_change (icon_theme);
+ changed = TRUE;
}
else
g_free (theme);
+
+ if ((priv->fallback_theme && !fallback_theme) ||
+ (!priv->fallback_theme && fallback_theme) ||
+ (priv->fallback_theme && fallback_theme &&
+ strcmp (priv->fallback_theme, fallback_theme) != 0))
+ {
+ g_free (priv->fallback_theme);
+ priv->fallback_theme = fallback_theme;
+
+ changed = TRUE;
+ }
+ else
+ g_free (fallback_theme);
+
+ if (changed)
+ do_theme_change (icon_theme);
}
}
G_CALLBACK (display_closed), icon_theme);
g_signal_connect (settings, "notify::gtk-icon-theme-name",
G_CALLBACK (theme_changed), icon_theme);
+ g_signal_connect (settings, "notify::gtk-fallback-icon-theme-name",
+ G_CALLBACK (theme_changed), icon_theme);
}
update_current_theme (icon_theme);
* with GdkPixbuf.
*/
static gboolean
-pixbuf_supports_svg ()
+pixbuf_supports_svg (void)
{
- GSList *formats = gdk_pixbuf_get_formats ();
+ GSList *formats;
GSList *tmp_list;
- gboolean found_svg = FALSE;
+ static gint found_svg = -1;
+ if (found_svg != -1)
+ return found_svg;
+
+ formats = gdk_pixbuf_get_formats ();
+
+ found_svg = FALSE;
for (tmp_list = formats; tmp_list && !found_svg; tmp_list = tmp_list->next)
{
gchar **mime_types = gdk_pixbuf_format_get_mime_types (tmp_list->data);
}
g_slist_free (formats);
-
+
return found_svg;
}
gtk_icon_theme_init (GtkIconTheme *icon_theme)
{
GtkIconThemePrivate *priv;
-
+ const gchar * const *xdg_data_dirs;
+ int i, j;
+
priv = g_type_instance_get_private ((GTypeInstance *)icon_theme,
GTK_TYPE_ICON_THEME);
icon_theme->priv = priv;
priv->custom_theme = FALSE;
priv->current_theme = g_strdup (DEFAULT_THEME_NAME);
- priv->search_path = g_new (char *, 5);
+
+ xdg_data_dirs = g_get_system_data_dirs ();
+ for (i = 0; xdg_data_dirs[i]; i++) ;
+
+ priv->search_path_len = 2 * i + 2;
+
+ priv->search_path = g_new (char *, priv->search_path_len);
+
+ i = 0;
+ priv->search_path[i++] = g_build_filename (g_get_home_dir (), ".icons", NULL);
+ priv->search_path[i++] = g_build_filename (g_get_user_data_dir (), "icons", NULL);
+ for (j = 0; xdg_data_dirs[j]; j++)
+ priv->search_path[i++] = g_build_filename (xdg_data_dirs[j], "icons", NULL);
- priv->search_path[0] = g_build_filename (g_get_home_dir (),
- ".icons",
- NULL);
- priv->search_path[1] = g_build_filename (GTK_DATADIR, "pixmaps", NULL);
- priv->search_path[2] = g_build_filename (GTK_DATADIR, "icons", NULL);
- priv->search_path[3] = g_strdup ("/usr/share/icons");
- priv->search_path[4] = g_strdup ("/usr/share/pixmaps");
- priv->search_path_len = 5;
+ for (j = 0; xdg_data_dirs[j]; j++)
+ priv->search_path[i++] = g_build_filename (xdg_data_dirs[j], "pixmaps", NULL);
priv->themes_valid = FALSE;
priv->themes = NULL;
priv->unthemed_icons = NULL;
-
+
priv->pixbuf_supports_svg = pixbuf_supports_svg ();
}
static void
free_dir_mtime (IconThemeDirMtime *dir_mtime)
{
+ if (dir_mtime->cache)
+ _gtk_icon_cache_unref (dir_mtime->cache);
+
g_free (dir_mtime->dir);
- g_free (dir_mtime);
+ g_slice_free (IconThemeDirMtime, dir_mtime);
+
+}
+
+static gboolean
+reset_styles_idle (gpointer user_data)
+{
+ GtkIconTheme *icon_theme;
+ GtkIconThemePrivate *priv;
+
+ icon_theme = GTK_ICON_THEME (user_data);
+ priv = icon_theme->priv;
+
+ if (priv->screen && priv->is_screen_singleton)
+ {
+ GtkSettings *settings = gtk_settings_get_for_screen (priv->screen);
+ gtk_rc_reset_styles (settings);
+ }
+
+ priv->reset_styles_idle = 0;
+
+ return FALSE;
}
static void
{
GtkIconThemePrivate *priv = icon_theme->priv;
+ GTK_NOTE (ICONTHEME,
+ g_print ("change to icon theme \"%s\"\n", priv->current_theme));
blow_themes (icon_theme);
- g_signal_emit (G_OBJECT (icon_theme), signal_changed, 0);
-
- if (priv->screen && priv->is_screen_singleton)
- {
- GtkSettings *settings = gtk_settings_get_for_screen (priv->screen);
- _gtk_rc_reset_styles (settings);
- }
+ g_signal_emit (icon_theme, signal_changed, 0);
+
+ if (!priv->reset_styles_idle)
+ priv->reset_styles_idle =
+ gdk_threads_add_idle_full (GTK_PRIORITY_RESIZE - 2,
+ reset_styles_idle, icon_theme, NULL);
}
static void
icon_theme = GTK_ICON_THEME (object);
priv = icon_theme->priv;
+ if (priv->reset_styles_idle)
+ {
+ g_source_remove (priv->reset_styles_idle);
+ priv->reset_styles_idle = 0;
+ }
+
unset_screen (icon_theme);
g_free (priv->current_theme);
priv->current_theme = NULL;
- for (i=0; i < priv->search_path_len; i++)
+ for (i = 0; i < priv->search_path_len; i++)
g_free (priv->search_path[i]);
g_free (priv->search_path);
priv->search_path = NULL;
blow_themes (icon_theme);
+
+ G_OBJECT_CLASS (gtk_icon_theme_parent_class)->finalize (object);
}
/**
priv->search_path = g_new (gchar *, n_elements);
priv->search_path_len = n_elements;
+
for (i = 0; i < priv->search_path_len; i++)
priv->search_path[i] = g_strdup (path[i]);
{
*path = g_new (gchar *, priv->search_path_len + 1);
for (i = 0; i < priv->search_path_len; i++)
- (*path)[i] = g_strdup (priv->search_path[i] + 1);
+ (*path)[i] = g_strdup (priv->search_path[i]);
(*path)[i] = NULL;
}
}
* @icon_theme: a #GtkIconTheme
* @path: directory name to append to the icon path
*
- * Appends a directory to the search path. See gtk_icon_theme_set_search_path().
+ * Appends a directory to the search path.
+ * See gtk_icon_theme_set_search_path().
*
* Since: 2.4
**/
priv = icon_theme->priv;
priv->search_path_len++;
+
priv->search_path = g_renew (gchar *, priv->search_path, priv->search_path_len);
priv->search_path[priv->search_path_len-1] = g_strdup (path);
* @icon_theme: a #GtkIconTheme
* @path: directory name to prepend to the icon path
*
- * Prepends a directory to the search path. See gtk_icon_theme_set_search_path().
+ * Prepends a directory to the search path.
+ * See gtk_icon_theme_set_search_path().
*
* Since: 2.4
**/
priv->search_path_len++;
priv->search_path = g_renew (gchar *, priv->search_path, priv->search_path_len);
- for (i = 0; i < priv->search_path_len - 1; i++)
- priv->search_path[i+1] = priv->search_path[i];
+ for (i = priv->search_path_len - 1; i > 0; i--)
+ priv->search_path[i] = priv->search_path[i - 1];
priv->search_path[0] = g_strdup (path);
/**
* gtk_icon_theme_set_custom_theme:
* @icon_theme: a #GtkIconTheme
- * @theme_name: name of icon theme to use instead of configured theme
+ * @theme_name: name of icon theme to use instead of configured theme,
+ * or %NULL to unset a previously set custom theme
*
* Sets the name of the icon theme that the #GtkIconTheme object uses
* overriding system configuration. This function cannot be called
* on the icon theme objects returned from gtk_icon_theme_get_default()
- * and gtk_icon_theme_get_default().
+ * and gtk_icon_theme_get_for_screen().
*
* Since: 2.4
**/
char **dirs;
char **themes;
GtkIconThemePrivate *priv;
- IconTheme *theme;
+ IconTheme *theme = NULL;
char *path;
- char *contents;
- char *directories;
- char *inherits;
- GtkIconThemeFile *theme_file;
+ GKeyFile *theme_file;
+ GError *error = NULL;
IconThemeDirMtime *dir_mtime;
struct stat stat_buf;
priv = icon_theme->priv;
-
+
for (l = priv->themes; l != NULL; l = l->next)
{
theme = l->data;
path = g_build_filename (priv->search_path[i],
theme_name,
NULL);
- dir_mtime = g_new (IconThemeDirMtime, 1);
+ dir_mtime = g_slice_new (IconThemeDirMtime);
+ dir_mtime->cache = NULL;
dir_mtime->dir = path;
- if (stat (path, &stat_buf) == 0 && S_ISDIR (stat_buf.st_mode))
+ if (g_stat (path, &stat_buf) == 0 && S_ISDIR (stat_buf.st_mode))
dir_mtime->mtime = stat_buf.st_mtime;
else
dir_mtime->mtime = 0;
priv->dir_mtimes = g_list_prepend (priv->dir_mtimes, dir_mtime);
}
+ priv->dir_mtimes = g_list_reverse (priv->dir_mtimes);
theme_file = NULL;
- for (i = 0; i < priv->search_path_len; i++)
+ for (i = 0; i < priv->search_path_len && !theme_file; i++)
{
path = g_build_filename (priv->search_path[i],
theme_name,
"index.theme",
NULL);
- if (g_file_test (path, G_FILE_TEST_IS_REGULAR)) {
- if (g_file_get_contents (path, &contents, NULL, NULL)) {
- theme_file = _gtk_icon_theme_file_new_from_string (contents, NULL);
- g_free (contents);
- g_free (path);
- break;
+ if (g_file_test (path, G_FILE_TEST_IS_REGULAR))
+ {
+ theme_file = g_key_file_new ();
+ g_key_file_set_list_separator (theme_file, ',');
+ g_key_file_load_from_file (theme_file, path, 0, &error);
+ if (error)
+ {
+ g_key_file_free (theme_file);
+ theme_file = NULL;
+ g_error_free (error);
+ error = NULL;
+ }
}
- }
g_free (path);
}
- if (theme_file == NULL)
- return;
-
- theme = g_new (IconTheme, 1);
- if (!_gtk_icon_theme_file_get_locale_string (theme_file,
- "Icon Theme",
- "Name",
- &theme->display_name))
+ if (theme_file || strcmp (theme_name, DEFAULT_THEME_NAME) == 0)
{
- g_warning ("Theme file for %s has no name\n", theme_name);
- g_free (theme);
- _gtk_icon_theme_file_free (theme_file);
- return;
+ theme = g_new0 (IconTheme, 1);
+ theme->name = g_strdup (theme_name);
+ priv->themes = g_list_prepend (priv->themes, theme);
}
- if (!_gtk_icon_theme_file_get_string (theme_file,
- "Icon Theme",
- "Directories",
- &directories))
+ if (theme_file == NULL)
+ return;
+
+ theme->display_name =
+ g_key_file_get_locale_string (theme_file, "Icon Theme", "Name", NULL, NULL);
+ if (!theme->display_name)
+ g_warning ("Theme file for %s has no name\n", theme_name);
+
+ dirs = g_key_file_get_string_list (theme_file, "Icon Theme", "Directories", NULL, NULL);
+ if (!dirs)
{
g_warning ("Theme file for %s has no directories\n", theme_name);
+ priv->themes = g_list_remove (priv->themes, theme);
+ g_free (theme->name);
g_free (theme->display_name);
g_free (theme);
- _gtk_icon_theme_file_free (theme_file);
+ g_key_file_free (theme_file);
return;
}
- theme->name = g_strdup (theme_name);
- _gtk_icon_theme_file_get_locale_string (theme_file,
- "Icon Theme",
- "Comment",
- &theme->comment);
- _gtk_icon_theme_file_get_string (theme_file,
- "Icon Theme",
- "Example",
- &theme->example);
-
- dirs = g_strsplit (directories, ",", 0);
+ theme->comment =
+ g_key_file_get_locale_string (theme_file,
+ "Icon Theme", "Comment",
+ NULL, NULL);
+ theme->example =
+ g_key_file_get_string (theme_file,
+ "Icon Theme", "Example",
+ NULL);
theme->dirs = NULL;
for (i = 0; dirs[i] != NULL; i++)
- theme_subdir_load (icon_theme, theme, theme_file, dirs[i]);
-
- g_strfreev (dirs);
-
- theme->dirs = g_list_reverse (theme->dirs);
+ theme_subdir_load (icon_theme, theme, theme_file, dirs[i]);
- g_free (directories);
+ g_strfreev (dirs);
- /* Prepend the finished theme */
- priv->themes = g_list_prepend (priv->themes, theme);
+ theme->dirs = g_list_reverse (theme->dirs);
- if (_gtk_icon_theme_file_get_string (theme_file,
+ themes = g_key_file_get_string_list (theme_file,
"Icon Theme",
"Inherits",
- &inherits))
+ NULL,
+ NULL);
+ if (themes)
{
- themes = g_strsplit (inherits, ",", 0);
-
for (i = 0; themes[i] != NULL; i++)
insert_theme (icon_theme, themes[i]);
g_strfreev (themes);
-
- g_free (inherits);
}
- _gtk_icon_theme_file_free (theme_file);
+ g_key_file_free (theme_file);
}
static void
{
if (unthemed_icon->svg_filename)
g_free (unthemed_icon->svg_filename);
- if (unthemed_icon->svg_filename)
+ if (unthemed_icon->no_svg_filename)
g_free (unthemed_icon->no_svg_filename);
- g_free (unthemed_icon);
+ g_slice_free (UnthemedIcon, unthemed_icon);
+}
+
+static char *
+strip_suffix (const char *filename)
+{
+ const char *dot;
+
+ dot = strrchr (filename, '.');
+
+ if (dot == NULL)
+ return g_strdup (filename);
+
+ return g_strndup (filename, dot - filename);
}
static void
GtkIconThemePrivate *priv;
GDir *gdir;
int base;
- char *dir, *base_name, *dot;
+ char *dir;
const char *file;
- char *abs_file;
UnthemedIcon *unthemed_icon;
IconSuffix old_suffix, new_suffix;
GTimeVal tv;
+ IconThemeDirMtime *dir_mtime;
+ struct stat stat_buf;
priv = icon_theme->priv;
priv->all_icons = g_hash_table_new (g_str_hash, g_str_equal);
insert_theme (icon_theme, priv->current_theme);
-
- /* Always look in the "default" icon theme */
+
+ /* Always look in the "default" icon theme, and in a fallback theme */
+ if (priv->fallback_theme)
+ insert_theme (icon_theme, priv->fallback_theme);
insert_theme (icon_theme, DEFAULT_THEME_NAME);
priv->themes = g_list_reverse (priv->themes);
-
+
+
priv->unthemed_icons = g_hash_table_new_full (g_str_hash, g_str_equal,
g_free, (GDestroyNotify)free_unthemed_icon);
for (base = 0; base < icon_theme->priv->search_path_len; base++)
{
dir = icon_theme->priv->search_path[base];
- gdir = g_dir_open (dir, 0, NULL);
+ dir_mtime = g_slice_new (IconThemeDirMtime);
+ priv->dir_mtimes = g_list_append (priv->dir_mtimes, dir_mtime);
+
+ dir_mtime->dir = g_strdup (dir);
+ dir_mtime->mtime = 0;
+ dir_mtime->cache = NULL;
+
+ if (g_stat (dir, &stat_buf) != 0 || !S_ISDIR (stat_buf.st_mode))
+ continue;
+ dir_mtime->mtime = stat_buf.st_mtime;
+
+ dir_mtime->cache = _gtk_icon_cache_new_for_path (dir);
+ if (dir_mtime->cache != NULL)
+ continue;
+
+ gdir = g_dir_open (dir, 0, NULL);
if (gdir == NULL)
continue;
-
+
while ((file = g_dir_read_name (gdir)))
{
new_suffix = suffix_from_name (file);
-
+
if (new_suffix != ICON_SUFFIX_NONE)
{
- abs_file = g_build_filename (dir, file, NULL);
+ char *abs_file;
+ char *base_name;
- base_name = g_strdup (file);
-
- dot = strrchr (base_name, '.');
- if (dot)
- *dot = 0;
+ abs_file = g_build_filename (dir, file, NULL);
+ base_name = strip_suffix (file);
if ((unthemed_icon = g_hash_table_lookup (priv->unthemed_icons,
base_name)))
{
if (new_suffix == ICON_SUFFIX_SVG)
{
- if (unthemed_icon->no_svg_filename)
+ if (unthemed_icon->svg_filename)
g_free (abs_file);
else
unthemed_icon->svg_filename = abs_file;
}
else
{
- unthemed_icon = g_new0 (UnthemedIcon, 1);
+ unthemed_icon = g_slice_new0 (UnthemedIcon);
if (new_suffix == ICON_SUFFIX_SVG)
unthemed_icon->svg_filename = abs_file;
else
- unthemed_icon->svg_filename = abs_file;
-
+ unthemed_icon->no_svg_filename = abs_file;
+
g_hash_table_insert (priv->unthemed_icons,
base_name,
unthemed_icon);
priv->last_stat_time = tv.tv_sec;
}
+void
+_gtk_icon_theme_ensure_builtin_cache (void)
+{
+ static gboolean initialized = FALSE;
+ IconThemeDir *dir;
+ static IconThemeDir dirs[5] =
+ {
+ { ICON_THEME_DIR_THRESHOLD, 0, 16, 16, 16, 2, NULL, "16", NULL, NULL, NULL },
+ { ICON_THEME_DIR_THRESHOLD, 0, 20, 20, 20, 2, NULL, "20", NULL, NULL, NULL },
+ { ICON_THEME_DIR_THRESHOLD, 0, 24, 24, 24, 2, NULL, "24", NULL, NULL, NULL },
+ { ICON_THEME_DIR_THRESHOLD, 0, 32, 32, 32, 2, NULL, "32", NULL, NULL, NULL },
+ { ICON_THEME_DIR_THRESHOLD, 0, 48, 48, 48, 2, NULL, "48", NULL, NULL, NULL }
+ };
+ gint i;
+
+ if (!initialized)
+ {
+ initialized = TRUE;
+
+ _builtin_cache = _gtk_icon_cache_new ((gchar *)builtin_icons);
+
+ for (i = 0; i < G_N_ELEMENTS (dirs); i++)
+ {
+ dir = &(dirs[i]);
+ dir->cache = _gtk_icon_cache_ref (_builtin_cache);
+
+ builtin_dirs = g_list_append (builtin_dirs, dir);
+ }
+ }
+}
+
static void
ensure_valid_themes (GtkIconTheme *icon_theme)
{
GtkIconThemePrivate *priv = icon_theme->priv;
GTimeVal tv;
-
+ gboolean was_valid = priv->themes_valid;
+
+ _gtk_icon_theme_ensure_builtin_cache ();
+
if (priv->themes_valid)
{
- g_get_current_time(&tv);
+ g_get_current_time (&tv);
if (ABS (tv.tv_sec - priv->last_stat_time) > 5)
gtk_icon_theme_rescan_if_needed (icon_theme);
}
if (!priv->themes_valid)
- load_themes (icon_theme);
+ {
+ load_themes (icon_theme);
+
+ if (!priv->check_reload && was_valid && priv->screen)
+ {
+ static GdkAtom atom_iconthemes = GDK_NONE;
+ GdkEvent *event = gdk_event_new (GDK_CLIENT_EVENT);
+ int i;
+
+ if (!atom_iconthemes)
+ atom_iconthemes = gdk_atom_intern_static_string ("_GTK_LOAD_ICONTHEMES");
+
+ for (i = 0; i < 5; i++)
+ event->client.data.l[i] = 0;
+ event->client.data_format = 32;
+ event->client.message_type = atom_iconthemes;
+
+ gdk_screen_broadcast_client_message (priv->screen, event);
+ }
+ }
}
/**
UnthemedIcon *unthemed_icon;
gboolean allow_svg;
gboolean use_builtin;
- gboolean found_default;
g_return_val_if_fail (GTK_IS_ICON_THEME (icon_theme), NULL);
g_return_val_if_fail (icon_name != NULL, NULL);
g_return_val_if_fail ((flags & GTK_ICON_LOOKUP_NO_SVG) == 0 ||
(flags & GTK_ICON_LOOKUP_FORCE_SVG) == 0, NULL);
-
+
priv = icon_theme->priv;
+ GTK_NOTE (ICONTHEME,
+ g_print ("gtk_icon_theme_lookup_icon %s\n", icon_name));
if (flags & GTK_ICON_LOOKUP_NO_SVG)
allow_svg = FALSE;
else if (flags & GTK_ICON_LOOKUP_FORCE_SVG)
ensure_valid_themes (icon_theme);
- found_default = FALSE;
- l = priv->themes;
- while (l != NULL)
+ for (l = priv->themes; l; l = l->next)
{
- IconTheme *icon_theme = l->data;
+ IconTheme *theme = l->data;
- if (strcmp (icon_theme->name, DEFAULT_THEME_NAME) == 0)
- found_default = TRUE;
-
- icon_info = theme_lookup_icon (icon_theme, icon_name, size, allow_svg, use_builtin);
+ icon_info = theme_lookup_icon (theme, icon_name, size, allow_svg, use_builtin);
if (icon_info)
goto out;
-
- l = l->next;
}
- if (!found_default)
- {
- BuiltinIcon *builtin = find_builtin_icon (icon_name, size, NULL, NULL);
- if (builtin)
- {
- icon_info = icon_info_new_builtin (builtin);
- goto out;
- }
- }
-
unthemed_icon = g_hash_table_lookup (priv->unthemed_icons, icon_name);
if (unthemed_icon)
{
icon_info->filename = g_strdup (unthemed_icon->svg_filename);
else if (unthemed_icon->no_svg_filename)
icon_info->filename = g_strdup (unthemed_icon->no_svg_filename);
+#ifdef G_OS_WIN32
+ icon_info->cp_filename = g_locale_from_utf8 (icon_info->filename,
+ -1, NULL, NULL, NULL);
+#endif
icon_info->dir_type = ICON_THEME_DIR_UNTHEMED;
}
"was not found either, perhaps you need to install it.\n"
"You can get a copy from:\n"
"\t%s"),
- icon_name, DEFAULT_THEME_NAME, "http://freedesktop.org/Software/icon-theme/releases");
+ icon_name, DEFAULT_THEME_NAME, "http://icon-theme.freedesktop.org/releases");
}
}
}
GQuark
gtk_icon_theme_error_quark (void)
{
- static GQuark q = 0;
- if (q == 0)
- q = g_quark_from_static_string ("gtk-icon-theme-error-quark");
-
- return q;
+ return g_quark_from_static_string ("gtk-icon-theme-error-quark");
}
/**
* and renders it into a pixbuf. This is a convenience function;
* if more details about the icon are needed, use
* gtk_icon_theme_lookup_icon() followed by gtk_icon_info_load_icon().
+ *
+ * Note that you probably want to listen for icon theme changes and
+ * update the icon. This is usually done by connecting to the
+ * GtkWidget::style-set signal. If for some reason you do not want to
+ * update the icon when the icon theme changes, you should consider
+ * using gdk_pixbuf_copy() to make a private copy of the pixbuf
+ * returned by this function. Otherwise GTK+ may need to keep the old
+ * icon theme loaded, which would be a waste of memory.
*
* Return value: the rendered icon; this may be a newly created icon
* or a new reference to an internal icon, so you must not modify
const char *icon_name)
{
GtkIconThemePrivate *priv;
+ GList *l;
g_return_val_if_fail (GTK_IS_ICON_THEME (icon_theme), FALSE);
ensure_valid_themes (icon_theme);
+ for (l = priv->dir_mtimes; l; l = l->next)
+ {
+ IconThemeDirMtime *dir_mtime = l->data;
+ GtkIconCache *cache = dir_mtime->cache;
+
+ if (cache && _gtk_icon_cache_has_icon (cache, icon_name))
+ return TRUE;
+ }
+
if (g_hash_table_lookup_extended (priv->all_icons,
icon_name, NULL, NULL))
return TRUE;
+ if (_builtin_cache &&
+ _gtk_icon_cache_has_icon (_builtin_cache, icon_name))
+ return TRUE;
+
if (icon_theme_builtin_icons &&
g_hash_table_lookup_extended (icon_theme_builtin_icons,
icon_name, NULL, NULL))
return FALSE;
}
+static void
+add_size (gpointer key,
+ gpointer value,
+ gpointer user_data)
+{
+ gint **res_p = user_data;
+
+ **res_p = GPOINTER_TO_INT (key);
+
+ (*res_p)++;
+}
+
+/**
+ * gtk_icon_theme_get_icon_sizes:
+ * @icon_theme: a #GtkIconTheme
+ * @icon_name: the name of an icon
+ *
+ * Returns an array of integers describing the sizes at which
+ * the icon is available without scaling. A size of -1 means
+ * that the icon is available in a scalable format. The array
+ * is zero-terminated.
+ *
+ * Return value: An newly allocated array describing the sizes at
+ * which the icon is available. The array should be freed with g_free()
+ * when it is no longer needed.
+ *
+ * Since: 2.6
+ **/
+gint *
+gtk_icon_theme_get_icon_sizes (GtkIconTheme *icon_theme,
+ const char *icon_name)
+{
+ GList *l, *d, *icons;
+ GHashTable *sizes;
+ gint *result, *r;
+ guint suffix;
+ GtkIconThemePrivate *priv;
+
+ g_return_val_if_fail (GTK_IS_ICON_THEME (icon_theme), NULL);
+
+ priv = icon_theme->priv;
+
+ ensure_valid_themes (icon_theme);
+
+ sizes = g_hash_table_new (g_direct_hash, g_direct_equal);
+
+ for (l = priv->themes; l; l = l->next)
+ {
+ IconTheme *theme = l->data;
+ for (d = theme->dirs; d; d = d->next)
+ {
+ IconThemeDir *dir = d->data;
+
+ suffix = theme_dir_get_icon_suffix (dir, icon_name, NULL);
+ if (suffix != ICON_SUFFIX_NONE)
+ {
+ if (suffix == ICON_SUFFIX_SVG)
+ g_hash_table_insert (sizes, GINT_TO_POINTER (-1), NULL);
+ else
+ g_hash_table_insert (sizes, GINT_TO_POINTER (dir->size), NULL);
+ }
+ }
+ }
+
+ for (d = builtin_dirs; d; d = d->next)
+ {
+ IconThemeDir *dir = d->data;
+
+ suffix = theme_dir_get_icon_suffix (dir, icon_name, NULL);
+ if (suffix != ICON_SUFFIX_NONE)
+ {
+ if (suffix == ICON_SUFFIX_SVG)
+ g_hash_table_insert (sizes, GINT_TO_POINTER (-1), NULL);
+ else
+ g_hash_table_insert (sizes, GINT_TO_POINTER (dir->size), NULL);
+ }
+ }
+
+ if (icon_theme_builtin_icons)
+ {
+ icons = g_hash_table_lookup (icon_theme_builtin_icons, icon_name);
+
+ while (icons)
+ {
+ BuiltinIcon *icon = icons->data;
+
+ g_hash_table_insert (sizes, GINT_TO_POINTER (icon->size), NULL);
+ icons = icons->next;
+ }
+ }
+
+ r = result = g_new0 (gint, g_hash_table_size (sizes) + 1);
+
+ g_hash_table_foreach (sizes, add_size, &r);
+ g_hash_table_destroy (sizes);
+
+ return result;
+}
static void
add_key_to_hash (gpointer key,
* Lists the icons in the current icon theme. Only a subset
* of the icons can be listed by providing a context string.
* The set of values for the context string is system dependent,
- * but will typically include such values as 'apps' and
- * 'mimetypes'.
+ * but will typically include such values as "Applications" and
+ * "MimeTypes".
*
* Return value: a #GList list holding the names of all the
* icons in the theme. You must first free each element
add_key_to_hash,
icons);
- list = 0;
+ list = NULL;
g_hash_table_foreach (icons,
add_key_to_list,
{
dir_mtime = d->data;
- stat_res = stat (dir_mtime->dir, &stat_buf);
+ stat_res = g_stat (dir_mtime->dir, &stat_buf);
/* dir mtime didn't change */
if (stat_res == 0 &&
g_list_foreach (theme->dirs, (GFunc)theme_dir_destroy, NULL);
g_list_free (theme->dirs);
+
g_free (theme);
}
static void
theme_dir_destroy (IconThemeDir *dir)
{
- g_hash_table_destroy (dir->icons);
+ if (dir->cache)
+ _gtk_icon_cache_unref (dir->cache);
+ else
+ g_hash_table_destroy (dir->icons);
+
if (dir->icon_data)
g_hash_table_destroy (dir->icon_data);
g_free (dir->dir);
+ g_free (dir->subdir);
g_free (dir);
}
return ICON_SUFFIX_NONE;
}
+
+static IconSuffix
+theme_dir_get_icon_suffix (IconThemeDir *dir,
+ const gchar *icon_name,
+ gboolean *has_icon_file)
+{
+ IconSuffix suffix;
+
+ if (dir->cache)
+ {
+ suffix = (IconSuffix)_gtk_icon_cache_get_icon_flags (dir->cache,
+ icon_name,
+ dir->subdir);
+
+ if (has_icon_file)
+ *has_icon_file = suffix & HAS_ICON_FILE;
+
+ suffix = suffix & ~HAS_ICON_FILE;
+ }
+ else
+ suffix = GPOINTER_TO_UINT (g_hash_table_lookup (dir->icons, icon_name));
+
+ GTK_NOTE (ICONTHEME,
+ g_print ("get_icon_suffix%s %u\n", dir->cache ? " (cached)" : "", suffix));
+
+ return suffix;
+}
+
static GtkIconInfo *
theme_lookup_icon (IconTheme *theme,
const char *icon_name,
gboolean allow_svg,
gboolean use_builtin)
{
- GList *l;
+ GList *dirs, *l;
IconThemeDir *dir, *min_dir;
char *file;
int min_difference, difference;
BuiltinIcon *closest_builtin = NULL;
- gboolean smaller, has_larger;
+ gboolean smaller, has_larger, match;
IconSuffix suffix;
min_difference = G_MAXINT;
min_dir = NULL;
has_larger = FALSE;
+ match = FALSE;
/* Builtin icons are logically part of the default theme and
* are searched before other subdirectories of the default theme.
*/
if (strcmp (theme->name, DEFAULT_THEME_NAME) == 0 && use_builtin)
{
- closest_builtin = find_builtin_icon (icon_name, size,
+ closest_builtin = find_builtin_icon (icon_name,
+ size,
&min_difference,
&has_larger);
if (min_difference == 0)
return icon_info_new_builtin (closest_builtin);
+
+ dirs = builtin_dirs;
}
+ else
+ dirs = theme->dirs;
- l = theme->dirs;
+ l = dirs;
while (l != NULL)
{
dir = l->data;
- suffix = GPOINTER_TO_UINT (g_hash_table_lookup (dir->icons, icon_name));
-
- if (suffix != ICON_SUFFIX_NONE &&
- (allow_svg || suffix != ICON_SUFFIX_SVG))
+ GTK_NOTE (ICONTHEME,
+ g_print ("theme_lookup_icon dir %s\n", dir->dir));
+ suffix = theme_dir_get_icon_suffix (dir, icon_name, NULL);
+ if (best_suffix (suffix, allow_svg) != ICON_SUFFIX_NONE)
{
difference = theme_dir_size_difference (dir, size, &smaller);
if (difference == 0)
{
- min_dir = dir;
- break;
+ if (dir->type == ICON_THEME_DIR_SCALABLE)
+ {
+ /* don't pick scalable if we already found
+ * a matching non-scalable dir
+ */
+ if (!match)
+ {
+ min_dir = dir;
+ break;
+ }
+ }
+ else
+ {
+ /* for a matching non-scalable dir keep
+ * going and look for a closer match
+ */
+ difference = abs (size - dir->size);
+ if (!match || difference < min_difference)
+ {
+ match = TRUE;
+ min_difference = difference;
+ min_dir = dir;
+ }
+ if (difference == 0)
+ break;
+ }
+ }
+
+ if (!match)
+ {
+ if (!has_larger)
+ {
+ if (difference < min_difference || smaller)
+ {
+ min_difference = difference;
+ min_dir = dir;
+ has_larger = smaller;
+ }
+ }
+ else
+ {
+ if (difference < min_difference && smaller)
+ {
+ min_difference = difference;
+ min_dir = dir;
+ }
+ }
}
+ }
- if (!has_larger)
- {
- if (difference < min_difference || smaller)
- {
- min_difference = difference;
- min_dir = dir;
- closest_builtin = NULL;
- has_larger = smaller;
- }
- }
- else
- {
- if (difference < min_difference && smaller)
- {
- min_difference = difference;
- min_dir = dir;
- closest_builtin = NULL;
- }
- }
+ l = l->next;
+ if (l == NULL && dirs == builtin_dirs)
+ {
+ dirs = theme->dirs;
+ l = dirs;
}
-
- l = l->next;
}
- if (closest_builtin)
- return icon_info_new_builtin (closest_builtin);
-
if (min_dir)
{
GtkIconInfo *icon_info = icon_info_new ();
+ gboolean has_icon_file = FALSE;
- suffix = GPOINTER_TO_UINT (g_hash_table_lookup (min_dir->icons, icon_name));
+ suffix = theme_dir_get_icon_suffix (min_dir, icon_name, &has_icon_file);
suffix = best_suffix (suffix, allow_svg);
g_assert (suffix != ICON_SUFFIX_NONE);
file = g_strconcat (icon_name, string_from_suffix (suffix), NULL);
icon_info->filename = g_build_filename (min_dir->dir, file, NULL);
g_free (file);
-
+#ifdef G_OS_WIN32
+ icon_info->cp_filename = g_locale_from_utf8 (icon_info->filename,
+ -1, NULL, NULL, NULL);
+#endif
+
if (min_dir->icon_data != NULL)
icon_info->data = g_hash_table_lookup (min_dir->icon_data, icon_name);
+ if (icon_info->data == NULL && min_dir->cache != NULL)
+ {
+ icon_info->data = _gtk_icon_cache_get_icon_data (min_dir->cache, icon_name, min_dir->subdir);
+ if (icon_info->data)
+ {
+ if (min_dir->icon_data == NULL)
+ min_dir->icon_data = g_hash_table_new_full (g_str_hash, g_str_equal,
+ g_free, (GDestroyNotify)icon_data_free);
+
+ g_hash_table_replace (min_dir->icon_data, g_strdup (icon_name), icon_info->data);
+ }
+ }
+
+ if (icon_info->data == NULL && has_icon_file)
+ {
+ gchar *icon_file_name, *icon_file_path;
+
+ icon_file_name = g_strconcat (icon_name, ".icon", NULL);
+ icon_file_path = g_build_filename (min_dir->dir, icon_file_name, NULL);
+
+ if (g_file_test (icon_file_path, G_FILE_TEST_IS_REGULAR))
+ {
+ if (min_dir->icon_data == NULL)
+ min_dir->icon_data = g_hash_table_new_full (g_str_hash, g_str_equal,
+ g_free, (GDestroyNotify)icon_data_free);
+ load_icon_data (min_dir, icon_file_path, icon_file_name);
+
+ icon_info->data = g_hash_table_lookup (min_dir->icon_data, icon_name);
+ }
+ g_free (icon_file_name);
+ g_free (icon_file_path);
+ }
+
+ if (min_dir->cache)
+ {
+ icon_info->cache_pixbuf = _gtk_icon_cache_get_icon (min_dir->cache, icon_name,
+ min_dir->subdir);
+ }
+
icon_info->dir_type = min_dir->type;
icon_info->dir_size = min_dir->size;
icon_info->threshold = min_dir->threshold;
return icon_info;
}
-
+
+ if (closest_builtin)
+ return icon_info_new_builtin (closest_builtin);
+
return NULL;
}
static void
-theme_list_icons (IconTheme *theme, GHashTable *icons,
- GQuark context)
+theme_list_icons (IconTheme *theme,
+ GHashTable *icons,
+ GQuark context)
{
GList *l = theme->dirs;
IconThemeDir *dir;
if (context == dir->context ||
context == 0)
- g_hash_table_foreach (dir->icons,
- add_key_to_hash,
- icons);
-
+ {
+ if (dir->cache)
+ {
+ _gtk_icon_cache_add_icons (dir->cache,
+ dir->subdir,
+ icons);
+
+ }
+ else
+ {
+ g_hash_table_foreach (dir->icons,
+ add_key_to_hash,
+ icons);
+ }
+ }
l = l->next;
}
}
static void
load_icon_data (IconThemeDir *dir, const char *path, const char *name)
{
- GtkIconThemeFile *icon_file;
+ GKeyFile *icon_file;
char *base_name;
char **split;
- char *contents;
- char *dot;
+ gsize length;
char *str;
char *split_point;
int i;
+ gint *ivalues;
+ GError *error = NULL;
GtkIconData *data;
- if (g_file_get_contents (path, &contents, NULL, NULL))
+ icon_file = g_key_file_new ();
+ g_key_file_set_list_separator (icon_file, ',');
+ g_key_file_load_from_file (icon_file, path, 0, &error);
+ if (error)
+ {
+ g_error_free (error);
+ g_key_file_free (icon_file);
+ return;
+ }
+ else
{
- icon_file = _gtk_icon_theme_file_new_from_string (contents, NULL);
+ base_name = strip_suffix (name);
- if (icon_file)
+ data = g_slice_new0 (GtkIconData);
+ g_hash_table_replace (dir->icon_data, base_name, data);
+
+ ivalues = g_key_file_get_integer_list (icon_file,
+ "Icon Data", "EmbeddedTextRectangle",
+ &length, NULL);
+ if (ivalues)
{
- base_name = g_strdup (name);
- dot = strrchr (base_name, '.');
- *dot = 0;
-
- data = g_new0 (GtkIconData, 1);
- g_hash_table_replace (dir->icon_data, base_name, data);
-
- if (_gtk_icon_theme_file_get_string (icon_file, "Icon Data",
- "EmbeddedTextRectangle",
- &str))
+ if (length == 4)
{
- split = g_strsplit (str, ",", 4);
-
- i = 0;
- while (split[i] != NULL)
- i++;
-
- if (i==4)
- {
- data->has_embedded_rect = TRUE;
- data->x0 = atoi (split[0]);
- data->y0 = atoi (split[1]);
- data->x1 = atoi (split[2]);
- data->y1 = atoi (split[3]);
- }
-
- g_strfreev (split);
- g_free (str);
+ data->has_embedded_rect = TRUE;
+ data->x0 = ivalues[0];
+ data->y0 = ivalues[1];
+ data->x1 = ivalues[2];
+ data->y1 = ivalues[3];
}
+
+ g_free (ivalues);
+ }
+
+ str = g_key_file_get_string (icon_file, "Icon Data", "AttachPoints", NULL);
+ if (str)
+ {
+ split = g_strsplit (str, "|", -1);
+
+ data->n_attach_points = g_strv_length (split);
+ data->attach_points = g_new (GdkPoint, data->n_attach_points);
-
- if (_gtk_icon_theme_file_get_string (icon_file, "Icon Data",
- "AttachPoints",
- &str))
+ i = 0;
+ while (split[i] != NULL && i < data->n_attach_points)
{
- split = g_strsplit (str, "|", -1);
-
- i = 0;
- while (split[i] != NULL)
- i++;
-
- data->n_attach_points = i;
- data->attach_points = g_malloc (sizeof (GdkPoint) * i);
-
- i = 0;
- while (split[i] != NULL && i < data->n_attach_points)
+ split_point = strchr (split[i], ',');
+ if (split_point)
{
- split_point = strchr (split[i], ',');
- if (split_point)
- {
- *split_point = 0;
- split_point++;
- data->attach_points[i].x = atoi (split[i]);
- data->attach_points[i].y = atoi (split_point);
- }
- i++;
+ *split_point = 0;
+ split_point++;
+ data->attach_points[i].x = atoi (split[i]);
+ data->attach_points[i].y = atoi (split_point);
}
-
- g_strfreev (split);
- g_free (str);
+ i++;
}
- _gtk_icon_theme_file_get_locale_string (icon_file, "Icon Data",
- "DisplayName",
- &data->display_name);
-
- _gtk_icon_theme_file_free (icon_file);
+ g_strfreev (split);
+ g_free (str);
}
- g_free (contents);
+
+ data->display_name = g_key_file_get_locale_string (icon_file,
+ "Icon Data", "DisplayName",
+ NULL, NULL);
+ g_key_file_free (icon_file);
}
-
}
static void
{
GDir *gdir;
const char *name;
- char *base_name, *dot;
- char *path;
- IconSuffix suffix, hash_suffix;
-
+
+ GTK_NOTE (ICONTHEME,
+ g_print ("scanning directory %s\n", full_dir));
dir->icons = g_hash_table_new_full (g_str_hash, g_str_equal,
g_free, NULL);
while ((name = g_dir_read_name (gdir)))
{
+ char *path;
+ char *base_name;
+ IconSuffix suffix, hash_suffix;
+
if (g_str_has_suffix (name, ".icon"))
{
if (dir->icon_data == NULL)
suffix = suffix_from_name (name);
if (suffix == ICON_SUFFIX_NONE)
continue;
-
- base_name = g_strdup (name);
- dot = strrchr (base_name, '.');
- *dot = 0;
-
+
+ base_name = strip_suffix (name);
+
hash_suffix = GPOINTER_TO_INT (g_hash_table_lookup (dir->icons, base_name));
g_hash_table_replace (dir->icons, base_name, GUINT_TO_POINTER (hash_suffix| suffix));
g_hash_table_insert (icon_theme->all_icons, base_name, NULL);
static void
theme_subdir_load (GtkIconTheme *icon_theme,
- IconTheme *theme,
- GtkIconThemeFile *theme_file,
- char *subdir)
+ IconTheme *theme,
+ GKeyFile *theme_file,
+ char *subdir)
{
- int base;
+ GList *d;
char *type_string;
IconThemeDir *dir;
IconThemeDirType type;
int max_size;
int threshold;
char *full_dir;
+ GError *error = NULL;
+ IconThemeDirMtime *dir_mtime;
- if (!_gtk_icon_theme_file_get_integer (theme_file,
- subdir,
- "Size",
- &size))
+ size = g_key_file_get_integer (theme_file, subdir, "Size", &error);
+ if (error)
{
- g_warning ("Theme directory %s of theme %s has no size field\n", subdir, theme->name);
+ g_error_free (error);
+ g_warning ("Theme directory %s of theme %s has no size field\n",
+ subdir, theme->name);
return;
}
type = ICON_THEME_DIR_THRESHOLD;
- if (_gtk_icon_theme_file_get_string (theme_file, subdir, "Type", &type_string))
+ type_string = g_key_file_get_string (theme_file, subdir, "Type", NULL);
+ if (type_string)
{
if (strcmp (type_string, "Fixed") == 0)
type = ICON_THEME_DIR_FIXED;
}
context = 0;
- if (_gtk_icon_theme_file_get_string (theme_file, subdir, "Context", &context_string))
+ context_string = g_key_file_get_string (theme_file, subdir, "Context", NULL);
+ if (context_string)
{
context = g_quark_from_string (context_string);
g_free (context_string);
}
- if (!_gtk_icon_theme_file_get_integer (theme_file,
- subdir,
- "MaxSize",
- &max_size))
- max_size = size;
-
- if (!_gtk_icon_theme_file_get_integer (theme_file,
- subdir,
- "MinSize",
- &min_size))
- min_size = size;
+ max_size = g_key_file_get_integer (theme_file, subdir, "MaxSize", &error);
+ if (error)
+ {
+ max_size = size;
+
+ g_error_free (error);
+ error = NULL;
+ }
+
+ min_size = g_key_file_get_integer (theme_file, subdir, "MinSize", &error);
+ if (error)
+ {
+ min_size = size;
+
+ g_error_free (error);
+ error = NULL;
+ }
- if (!_gtk_icon_theme_file_get_integer (theme_file,
- subdir,
- "Threshold",
- &threshold))
- threshold = 2;
+ threshold = g_key_file_get_integer (theme_file, subdir, "Threshold", &error);
+ if (error)
+ {
+ threshold = 2;
- for (base = 0; base < icon_theme->priv->search_path_len; base++)
+ g_error_free (error);
+ error = NULL;
+ }
+
+ for (d = icon_theme->priv->dir_mtimes; d; d = d->next)
{
- full_dir = g_build_filename (icon_theme->priv->search_path[base],
- theme->name,
- subdir,
- NULL);
- if (g_file_test (full_dir, G_FILE_TEST_IS_DIR))
+ dir_mtime = (IconThemeDirMtime *)d->data;
+
+ if (dir_mtime->mtime == 0)
+ continue; /* directory doesn't exist */
+
+ full_dir = g_build_filename (dir_mtime->dir, subdir, NULL);
+
+ /* First, see if we have a cache for the directory */
+ if (dir_mtime->cache != NULL || g_file_test (full_dir, G_FILE_TEST_IS_DIR))
{
+ if (dir_mtime->cache == NULL)
+ {
+ /* This will return NULL if the cache doesn't exist or is outdated */
+ dir_mtime->cache = _gtk_icon_cache_new_for_path (dir_mtime->dir);
+ }
+
dir = g_new (IconThemeDir, 1);
dir->type = type;
dir->context = context;
dir->threshold = threshold;
dir->dir = full_dir;
dir->icon_data = NULL;
-
- scan_directory (icon_theme->priv, dir, full_dir);
+ dir->subdir = g_strdup (subdir);
+ if (dir_mtime->cache != NULL)
+ dir->cache = _gtk_icon_cache_ref (dir_mtime->cache);
+ else
+ {
+ dir->cache = NULL;
+ scan_directory (icon_theme->priv, dir, full_dir);
+ }
- theme->dirs = g_list_append (theme->dirs, dir);
+ theme->dirs = g_list_prepend (theme->dirs, dir);
}
else
g_free (full_dir);
{
g_free (icon_data->attach_points);
g_free (icon_data->display_name);
- g_free (icon_data);
+ g_slice_free (GtkIconData, icon_data);
}
/*
static GType our_type = 0;
if (our_type == 0)
- our_type = g_boxed_type_register_static ("GtkIconInfo",
+ our_type = g_boxed_type_register_static (I_("GtkIconInfo"),
(GBoxedCopyFunc) gtk_icon_info_copy,
(GBoxedFreeFunc) gtk_icon_info_free);
+
return our_type;
}
static GtkIconInfo *
icon_info_new (void)
{
- GtkIconInfo *icon_info = g_new0 (GtkIconInfo, 1);
+ GtkIconInfo *icon_info = g_slice_new0 (GtkIconInfo);
- icon_info->ref_count = 1;
icon_info->scale = -1.;
return icon_info;
{
GtkIconInfo *icon_info = icon_info_new ();
- icon_info->builtin_pixbuf = g_object_ref (icon->pixbuf);
+ icon_info->cache_pixbuf = g_object_ref (icon->pixbuf);
icon_info->dir_type = ICON_THEME_DIR_THRESHOLD;
icon_info->dir_size = icon->size;
icon_info->threshold = 2;
g_return_val_if_fail (icon_info != NULL, NULL);
- copy = g_memdup (icon_info, sizeof (GtkIconInfo));
- if (copy->builtin_pixbuf)
- g_object_ref (copy->builtin_pixbuf);
+ copy = memcpy (g_slice_new (GtkIconInfo), icon_info, sizeof (GtkIconInfo));
+ if (copy->cache_pixbuf)
+ g_object_ref (copy->cache_pixbuf);
if (copy->pixbuf)
g_object_ref (copy->pixbuf);
if (copy->load_error)
copy->load_error = g_error_copy (copy->load_error);
if (copy->filename)
copy->filename = g_strdup (copy->filename);
+#ifdef G_OS_WIN32
+ if (copy->cp_filename)
+ copy->cp_filename = g_strdup (copy->cp_filename);
+#endif
return copy;
}
if (icon_info->filename)
g_free (icon_info->filename);
- if (icon_info->builtin_pixbuf)
- g_object_unref (icon_info->builtin_pixbuf);
+#ifdef G_OS_WIN32
+ if (icon_info->cp_filename)
+ g_free (icon_info->cp_filename);
+#endif
if (icon_info->pixbuf)
g_object_unref (icon_info->pixbuf);
-
- g_free (icon_info);
+ if (icon_info->cache_pixbuf)
+ g_object_unref (icon_info->cache_pixbuf);
+
+ g_slice_free (GtkIconInfo, icon_info);
}
/**
{
g_return_val_if_fail (icon_info != NULL, NULL);
- return icon_info->builtin_pixbuf;
+ if (icon_info->filename)
+ return NULL;
+
+ return icon_info->cache_pixbuf;
}
static GdkPixbuf *
{
GdkPixbuf *pixbuf = NULL;
GdkPixbufLoader *loader = NULL;
- gchar *contents;
+ gchar *contents = NULL;
gsize length;
if (!g_file_get_contents (filename,
&contents, &length, error))
goto bail;
- loader = gdk_pixbuf_loader_new ();
+ loader = gdk_pixbuf_loader_new_with_type ("svg", error);
+ if (loader == NULL)
+ goto bail;
+
gdk_pixbuf_loader_set_size (loader, size, size);
if (!gdk_pixbuf_loader_write (loader, contents, length, error))
bail:
if (loader)
g_object_unref (loader);
+ if (contents)
+ g_free (contents);
return pixbuf;
}
/* At this point, we need to actually get the icon; either from the
* builting image or by loading the file
*/
- if (icon_info->builtin_pixbuf)
- source_pixbuf = g_object_ref (icon_info->builtin_pixbuf);
+ if (icon_info->cache_pixbuf)
+ source_pixbuf = g_object_ref (icon_info->cache_pixbuf);
else
{
+
source_pixbuf = gdk_pixbuf_new_from_file (icon_info->filename,
&icon_info->load_error);
if (!source_pixbuf)
{
gint image_size = MAX (image_width, image_height);
if (image_size > 0)
- icon_info->scale = icon_info->desired_size / image_size;
+ icon_info->scale = icon_info->desired_size / (gdouble)image_size;
else
icon_info->scale = 1.0;
if (icon_info->dir_type == ICON_THEME_DIR_UNTHEMED)
- icon_info->scale = MAX (icon_info->scale, 1.0);
+ icon_info->scale = MIN (icon_info->scale, 1.0);
}
/* We don't short-circuit out here for scale_only, since, now
/**
* gtk_icon_info_load_icon:
* @icon_info: a #GtkIconInfo structure from gtk_icon_theme_lookup_icon()
- * @error:
+ * @error: location to store error information on failure, or %NULL.
*
* Renders an icon previously looked up in an icon theme using
* gtk_icon_theme_lookup_icon(); the size will be based on the size
- * pssed to gtk_icon_theme_lookup_icon(). Note that the resulting
+ * passed to gtk_icon_theme_lookup_icon(). Note that the resulting
* pixbuf may not be exactly this size; an icon theme may have icons
* that differ slightly from their nominal sizes, and in addition GTK+
* will avoid scaling icons that it considers sufficiently close to the
- * requested size. (This maintains sharpness.)
+ * requested size or for which the source image would have to be scaled
+ * up too far. (This maintains sharpness.)
*
* Return value: the rendered icon; this may be a newly created icon
* or a new reference to an internal icon, so you must not modify
* Since: 2.4
**/
G_CONST_RETURN gchar *
-gtk_icon_info_get_display_name (GtkIconInfo *icon_info)
+gtk_icon_info_get_display_name (GtkIconInfo *icon_info)
{
g_return_val_if_fail (icon_info != NULL, NULL);
* that the icon is generally available.
*
* This function will generally be used with pixbufs loaded
- * via gdk_pixbuf_new_from_inline ().
+ * via gdk_pixbuf_new_from_inline().
*
* Since: 2.4
**/
return min_icon;
}
+
+void
+_gtk_icon_theme_check_reload (GdkDisplay *display)
+{
+ gint n_screens, i;
+ GdkScreen *screen;
+ GtkIconTheme *icon_theme;
+
+ n_screens = gdk_display_get_n_screens (display);
+
+ for (i = 0; i < n_screens; i++)
+ {
+ screen = gdk_display_get_screen (display, i);
+
+ icon_theme = g_object_get_data (G_OBJECT (screen), "gtk-icon-theme");
+ if (icon_theme)
+ {
+ icon_theme->priv->check_reload = TRUE;
+ ensure_valid_themes (icon_theme);
+ icon_theme->priv->check_reload = FALSE;
+ }
+ }
+}
+
+#ifdef G_OS_WIN32
+
+/* DLL ABI stability backward compatibility versions */
+
+#undef gtk_icon_theme_set_search_path
+
+void
+gtk_icon_theme_set_search_path (GtkIconTheme *icon_theme,
+ const gchar *path[],
+ gint n_elements)
+{
+ const gchar **utf8_path;
+ gint i;
+
+ utf8_path = g_new (const gchar *, n_elements);
+
+ for (i = 0; i < n_elements; i++)
+ utf8_path[i] = g_locale_to_utf8 (path[i], -1, NULL, NULL, NULL);
+
+ gtk_icon_theme_set_search_path_utf8 (icon_theme, utf8_path, n_elements);
+
+ for (i = 0; i < n_elements; i++)
+ g_free ((gchar *) utf8_path[i]);
+
+ g_free (utf8_path);
+}
+
+#undef gtk_icon_theme_get_search_path
+
+void
+gtk_icon_theme_get_search_path (GtkIconTheme *icon_theme,
+ gchar **path[],
+ gint *n_elements)
+{
+ gint i, n;
+
+ gtk_icon_theme_get_search_path_utf8 (icon_theme, path, &n);
+
+ if (n_elements)
+ *n_elements = n;
+
+ if (path)
+ {
+ for (i = 0; i < n; i++)
+ {
+ gchar *tem = (*path)[i];
+
+ (*path)[i] = g_locale_from_utf8 ((*path)[i], -1, NULL, NULL, NULL);
+ g_free (tem);
+ }
+ }
+}
+
+#undef gtk_icon_theme_append_search_path
+
+void
+gtk_icon_theme_append_search_path (GtkIconTheme *icon_theme,
+ const gchar *path)
+{
+ gchar *utf8_path = g_locale_from_utf8 (path, -1, NULL, NULL, NULL);
+
+ gtk_icon_theme_append_search_path_utf8 (icon_theme, utf8_path);
+
+ g_free (utf8_path);
+}
+
+#undef gtk_icon_theme_prepend_search_path
+
+void
+gtk_icon_theme_prepend_search_path (GtkIconTheme *icon_theme,
+ const gchar *path)
+{
+ gchar *utf8_path = g_locale_from_utf8 (path, -1, NULL, NULL, NULL);
+
+ gtk_icon_theme_prepend_search_path_utf8 (icon_theme, utf8_path);
+
+ g_free (utf8_path);
+}
+
+#undef gtk_icon_info_get_filename
+
+G_CONST_RETURN gchar *
+gtk_icon_info_get_filename (GtkIconInfo *icon_info)
+{
+ g_return_val_if_fail (icon_info != NULL, NULL);
+
+ return icon_info->cp_filename;
+}
+
+#endif
+
+#define __GTK_ICON_THEME_C__
+#include "gtkaliasdef.c"