#include "gtkiconcache.h"
#include "gtkbuiltincache.h"
#include "gtkintl.h"
+#include "gtkmain.h"
#include "gtksettings.h"
#include "gtkprivate.h"
#include "gtkalias.h"
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 *dir_mtimes;
gulong reset_styles_idle;
-
- gboolean check_reload;
};
struct _GtkIconInfo
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);
gint *min_difference_p,
gboolean *has_larger_p);
-static GObjectClass *parent_class = NULL;
-
static guint signal_changed = 0;
static GHashTable *icon_theme_builtin_icons;
GtkIconCache *_builtin_cache = NULL;
static GList *builtin_dirs = NULL;
-
-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, I_("GtkIconTheme"), &info, 0);
- }
-
- return type;
-}
+G_DEFINE_TYPE (GtkIconTheme, gtk_icon_theme, G_TYPE_OBJECT)
/**
* gtk_icon_theme_new:
{
GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
- parent_class = g_type_class_peek_parent (klass);
-
gobject_class->finalize = gtk_icon_theme_finalize;
/**
{
GSList *formats = gdk_pixbuf_get_formats ();
GSList *tmp_list;
- static gboolean found_svg = FALSE;
- static gboolean value_known = FALSE;
+ static gint found_svg = -1;
- if (value_known)
+ if (found_svg != -1)
return found_svg;
-
+
+ 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);
- value_known = TRUE;
return found_svg;
}
_gtk_icon_cache_unref (dir_mtime->cache);
g_free (dir_mtime->dir);
- g_free (dir_mtime);
+ g_slice_free (IconThemeDirMtime, dir_mtime);
}
if (!priv->reset_styles_idle)
priv->reset_styles_idle =
- g_idle_add (reset_styles_idle, icon_theme);
+ g_idle_add_full (GTK_PRIORITY_RESIZE - 2,
+ reset_styles_idle, icon_theme, NULL);
}
static void
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);
blow_themes (icon_theme);
- G_OBJECT_CLASS (parent_class)->finalize (object);
+ 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]);
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);
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 (g_stat (path, &stat_buf) == 0 && S_ISDIR (stat_buf.st_mode))
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);
+ {
+ g_warning ("Theme file for %s has no directories\n", theme_name);
+ g_free (theme->display_name);
+ g_free (theme);
+ g_key_file_free (theme_file);
+ return;
+ }
theme->comment =
g_key_file_get_locale_string (theme_file,
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);
themes = g_key_file_get_string_list (theme_file,
g_free (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;
{
dir = icon_theme->priv->search_path[base];
- dir_mtime = g_new (IconThemeDirMtime, 1);
+ dir_mtime = g_slice_new (IconThemeDirMtime);
dir_mtime->cache = _gtk_icon_cache_new_for_path (dir);
dir_mtime->dir = g_strdup (dir);
if (g_stat (dir, &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_append (priv->dir_mtimes, dir_mtime);
-
+
if (dir_mtime->cache != NULL)
continue;
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)))
}
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;
priv->last_stat_time = tv.tv_sec;
}
-static void
+void
_gtk_icon_theme_ensure_builtin_cache (void)
{
static gboolean initialized = FALSE;
IconThemeDir *dir;
- gint sizes[5] = { 16, 20, 24, 32, 48 };
- gint n_sizes = G_N_ELEMENTS (sizes);
+ 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)
_builtin_cache = _gtk_icon_cache_new ((gchar *)builtin_icons);
- for (i = 0; i < n_sizes; i++)
+ for (i = 0; i < G_N_ELEMENTS (dirs); i++)
{
- dir = g_new (IconThemeDir, 1);
- dir->type = ICON_THEME_DIR_THRESHOLD;
- dir->context = 0;
- dir->size = sizes[i];
- dir->min_size = sizes[i];
- dir->max_size = sizes[i];
- dir->threshold = 2;
- dir->dir = NULL;
- dir->icon_data = NULL;
- dir->subdir = g_strdup_printf ("%d", sizes[i]);
+ dir = &(dirs[i]);
dir->cache = _gtk_icon_cache_ref (_builtin_cache);
builtin_dirs = g_list_append (builtin_dirs, dir);
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");
}
/**
char *base_name;
char **split;
gsize length;
- char *dot;
char *str;
char *split_point;
int i;
if (error)
{
g_error_free (error);
+ g_key_file_free (icon_file);
return;
}
else
{
- base_name = g_strdup (name);
- dot = strrchr (base_name, '.');
- *dot = 0;
+ base_name = strip_suffix (name);
- data = g_new0 (GtkIconData, 1);
+ data = g_slice_new0 (GtkIconData);
g_hash_table_replace (dir->icon_data, base_name, data);
ivalues = g_key_file_get_integer_list (icon_file,
split = g_strsplit (str, "|", -1);
data->n_attach_points = g_strv_length (split);
- data->attach_points = g_malloc (sizeof (GdkPoint) * data->n_attach_points);
+ data->attach_points = g_new (GdkPoint, data->n_attach_points);
i = 0;
while (split[i] != NULL && i < data->n_attach_points)
{
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));
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);
{
g_free (icon_data->attach_points);
g_free (icon_data->display_name);
- g_free (icon_data);
+ g_slice_free (GtkIconData, icon_data);
}
/*
(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->scale = -1.;
g_return_val_if_fail (icon_info != NULL, NULL);
- copy = g_memdup (icon_info, sizeof (GtkIconInfo));
+ copy = memcpy (g_slice_new (GtkIconInfo), icon_info, sizeof (GtkIconInfo));
if (copy->cache_pixbuf)
g_object_ref (copy->cache_pixbuf);
if (copy->pixbuf)
if (icon_info->cache_pixbuf)
g_object_unref (icon_info->cache_pixbuf);
- g_free (icon_info);
+ g_slice_free (GtkIconInfo, icon_info);
}
/**
* 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);