#include "gtkiconcache.h"
#include "gtkbuiltincache.h"
#include "gtkintl.h"
+#include "gtkmain.h"
#include "gtksettings.h"
#include "gtkprivate.h"
#include "gtkalias.h"
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;
/**
_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,
NULL);
theme->dirs = NULL;
- if (dirs)
- {
- for (i = 0; dirs[i] != NULL; i++)
- theme_subdir_load (icon_theme, theme, theme_file, dirs[i]);
- g_strfreev (dirs);
- }
+ 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_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
load_themes (GtkIconTheme *icon_theme)
{
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))
if (new_suffix != ICON_SUFFIX_NONE)
{
+ char *abs_file;
+ char *base_name;
+
abs_file = g_build_filename (dir, file, NULL);
-
- base_name = g_strdup (file);
-
- dot = strrchr (base_name, '.');
- if (dot)
- *dot = 0;
-
+ base_name = strip_suffix (file);
+
if ((unthemed_icon = g_hash_table_lookup (priv->unthemed_icons,
base_name)))
{
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);
char *base_name;
char **split;
gsize length;
- char *dot;
char *str;
char *split_point;
int i;
}
else
{
- base_name = g_strdup (name);
- dot = strrchr (base_name, '.');
- *dot = 0;
+ base_name = strip_suffix (name);
data = g_slice_new0 (GtkIconData);
g_hash_table_replace (dir->icon_data, base_name, data);
{
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);