From 6c142d9469f8c21a47d4efb50125cf15415b280c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Timm=20B=C3=A4der?= Date: Sun, 26 May 2019 11:59:48 +0200 Subject: [PATCH] icontheme: Remove priv pointer --- gtk/gtkicontheme.c | 160 +++++++++++++++++++-------------------------- gtk/gtkicontheme.h | 4 +- 2 files changed, 69 insertions(+), 95 deletions(-) diff --git a/gtk/gtkicontheme.c b/gtk/gtkicontheme.c index 8da0f34b43..6fe378ae51 100644 --- a/gtk/gtkicontheme.c +++ b/gtk/gtkicontheme.c @@ -149,8 +149,6 @@ struct _GtkIconTheme { /*< private >*/ GObject parent_instance; - - GtkIconThemePrivate *priv; }; struct _GtkIconThemePrivate @@ -418,6 +416,16 @@ icon_info_key_equal (gconstpointer _a, G_DEFINE_TYPE_WITH_PRIVATE (GtkIconTheme, gtk_icon_theme, G_TYPE_OBJECT) +static void +gtk_icon_theme_remove_from_info_cache (GtkIconTheme *icon_theme, + GtkIconInfo *icon_info) +{ + GtkIconThemePrivate *priv = gtk_icon_theme_get_instance_private (icon_theme); + + g_hash_table_remove (priv->info_cache, &icon_info->key); +} + + /** * gtk_icon_theme_new: * @@ -485,7 +493,7 @@ gtk_icon_theme_get_for_display (GdkDisplay *display) icon_theme = gtk_icon_theme_new (); gtk_icon_theme_set_display (icon_theme, display); - priv = icon_theme->priv; + priv = gtk_icon_theme_get_instance_private (icon_theme); priv->is_display_singleton = TRUE; g_object_set_data (G_OBJECT (display), I_("gtk-icon-theme"), icon_theme); @@ -528,7 +536,7 @@ display_closed (GdkDisplay *display, gboolean is_error, GtkIconTheme *icon_theme) { - GtkIconThemePrivate *priv = icon_theme->priv; + GtkIconThemePrivate *priv = gtk_icon_theme_get_instance_private (icon_theme); gboolean was_display_singleton = priv->is_display_singleton; if (was_display_singleton) @@ -551,7 +559,7 @@ update_current_theme (GtkIconTheme *icon_theme) #define theme_changed(_old, _new) \ ((_old && !_new) || (!_old && _new) || \ (_old && _new && strcmp (_old, _new) != 0)) - GtkIconThemePrivate *priv = icon_theme->priv; + GtkIconThemePrivate *priv = gtk_icon_theme_get_instance_private (icon_theme); if (!priv->custom_theme) { @@ -592,7 +600,7 @@ theme_changed (GtkSettings *settings, static void unset_display (GtkIconTheme *icon_theme) { - GtkIconThemePrivate *priv = icon_theme->priv; + GtkIconThemePrivate *priv = gtk_icon_theme_get_instance_private (icon_theme); GtkSettings *settings; if (priv->display) @@ -623,14 +631,12 @@ void gtk_icon_theme_set_display (GtkIconTheme *icon_theme, GdkDisplay *display) { - GtkIconThemePrivate *priv; + GtkIconThemePrivate *priv = gtk_icon_theme_get_instance_private (icon_theme); GtkSettings *settings; g_return_if_fail (GTK_ICON_THEME (icon_theme)); g_return_if_fail (display == NULL || GDK_IS_DISPLAY (display)); - priv = icon_theme->priv; - unset_display (icon_theme); if (display) @@ -694,7 +700,7 @@ icon_info_uncached (GtkIconInfo *icon_info) concat_icon_names (icon_info->key.icon_names, icon_info->key.n_icon_names), icon_info->key.size, icon_info->key.flags, icon_theme, - icon_theme != NULL ? g_hash_table_size (icon_theme->priv->info_cache) : 0)); + icon_theme != NULL ? g_hash_table_size (priv->info_cache) : 0)); icon_info->in_cache = NULL; @@ -705,13 +711,10 @@ icon_info_uncached (GtkIconInfo *icon_info) static void gtk_icon_theme_init (GtkIconTheme *icon_theme) { - GtkIconThemePrivate *priv; + GtkIconThemePrivate *priv = gtk_icon_theme_get_instance_private (icon_theme); const gchar * const *xdg_data_dirs; int i, j; - priv = gtk_icon_theme_get_instance_private (icon_theme); - icon_theme->priv = priv; - priv->info_cache = g_hash_table_new_full (icon_info_key_hash, icon_info_key_equal, NULL, (GDestroyNotify)icon_info_uncached); @@ -756,11 +759,8 @@ free_dir_mtime (IconThemeDirMtime *dir_mtime) static gboolean theme_changed_idle (gpointer user_data) { - GtkIconTheme *icon_theme; - GtkIconThemePrivate *priv; - - icon_theme = GTK_ICON_THEME (user_data); - priv = icon_theme->priv; + GtkIconTheme *icon_theme = GTK_ICON_THEME (user_data); + GtkIconThemePrivate *priv = gtk_icon_theme_get_instance_private (icon_theme); g_signal_emit (icon_theme, signal_changed, 0); @@ -775,7 +775,7 @@ theme_changed_idle (gpointer user_data) static void queue_theme_changed (GtkIconTheme *icon_theme) { - GtkIconThemePrivate *priv = icon_theme->priv; + GtkIconThemePrivate *priv = gtk_icon_theme_get_instance_private (icon_theme); if (!priv->theme_changed_idle) { @@ -790,14 +790,14 @@ queue_theme_changed (GtkIconTheme *icon_theme) static void do_theme_change (GtkIconTheme *icon_theme) { - GtkIconThemePrivate *priv = icon_theme->priv; + GtkIconThemePrivate *priv = gtk_icon_theme_get_instance_private (icon_theme); g_hash_table_remove_all (priv->info_cache); if (!priv->themes_valid) return; - GTK_DISPLAY_NOTE (icon_theme->priv->display, ICONTHEME, + GTK_DISPLAY_NOTE (priv->display, ICONTHEME, g_message ("change to icon theme \"%s\"", priv->current_theme)); blow_themes (icon_theme); @@ -808,7 +808,7 @@ do_theme_change (GtkIconTheme *icon_theme) static void blow_themes (GtkIconTheme *icon_theme) { - GtkIconThemePrivate *priv = icon_theme->priv; + GtkIconThemePrivate *priv = gtk_icon_theme_get_instance_private (icon_theme); if (priv->themes_valid) { @@ -825,13 +825,10 @@ blow_themes (GtkIconTheme *icon_theme) static void gtk_icon_theme_finalize (GObject *object) { - GtkIconTheme *icon_theme; - GtkIconThemePrivate *priv; + GtkIconTheme *icon_theme = GTK_ICON_THEME (object); + GtkIconThemePrivate *priv = gtk_icon_theme_get_instance_private (icon_theme); int i; - icon_theme = GTK_ICON_THEME (object); - priv = icon_theme->priv; - g_hash_table_destroy (priv->info_cache); g_assert (priv->info_cache_lru == NULL); @@ -880,12 +877,11 @@ gtk_icon_theme_set_search_path (GtkIconTheme *icon_theme, const gchar *path[], gint n_elements) { - GtkIconThemePrivate *priv; + GtkIconThemePrivate *priv = gtk_icon_theme_get_instance_private (icon_theme); gint i; g_return_if_fail (GTK_IS_ICON_THEME (icon_theme)); - priv = icon_theme->priv; for (i = 0; i < priv->search_path_len; i++) g_free (priv->search_path[i]); @@ -915,13 +911,11 @@ gtk_icon_theme_get_search_path (GtkIconTheme *icon_theme, gchar **path[], gint *n_elements) { - GtkIconThemePrivate *priv; + GtkIconThemePrivate *priv = gtk_icon_theme_get_instance_private (icon_theme); gint i; g_return_if_fail (GTK_IS_ICON_THEME (icon_theme)); - priv = icon_theme->priv; - if (n_elements) *n_elements = priv->search_path_len; @@ -946,13 +940,11 @@ void gtk_icon_theme_append_search_path (GtkIconTheme *icon_theme, const gchar *path) { - GtkIconThemePrivate *priv; + GtkIconThemePrivate *priv = gtk_icon_theme_get_instance_private (icon_theme); g_return_if_fail (GTK_IS_ICON_THEME (icon_theme)); g_return_if_fail (path != NULL); - priv = icon_theme->priv; - priv->search_path_len++; priv->search_path = g_renew (gchar *, priv->search_path, priv->search_path_len); @@ -973,14 +965,12 @@ void gtk_icon_theme_prepend_search_path (GtkIconTheme *icon_theme, const gchar *path) { - GtkIconThemePrivate *priv; + GtkIconThemePrivate *priv = gtk_icon_theme_get_instance_private (icon_theme); gint i; g_return_if_fail (GTK_IS_ICON_THEME (icon_theme)); g_return_if_fail (path != NULL); - priv = icon_theme->priv; - priv->search_path_len++; priv->search_path = g_renew (gchar *, priv->search_path, priv->search_path_len); @@ -1013,7 +1003,7 @@ void gtk_icon_theme_add_resource_path (GtkIconTheme *icon_theme, const gchar *path) { - GtkIconThemePrivate *priv = icon_theme->priv; + GtkIconThemePrivate *priv = gtk_icon_theme_get_instance_private (icon_theme); g_return_if_fail (GTK_IS_ICON_THEME (icon_theme)); g_return_if_fail (path != NULL); @@ -1038,14 +1028,11 @@ void gtk_icon_theme_set_custom_theme (GtkIconTheme *icon_theme, const gchar *theme_name) { - GtkIconThemePrivate *priv; + GtkIconThemePrivate *priv = gtk_icon_theme_get_instance_private (icon_theme); g_return_if_fail (GTK_IS_ICON_THEME (icon_theme)); - - priv = icon_theme->priv; - g_return_if_fail (!priv->is_display_singleton); - + if (theme_name != NULL) { priv->custom_theme = TRUE; @@ -1104,20 +1091,18 @@ static void insert_theme (GtkIconTheme *icon_theme, const gchar *theme_name) { + GtkIconThemePrivate *priv = gtk_icon_theme_get_instance_private (icon_theme); gint i; GList *l; gchar **dirs; gchar **scaled_dirs; gchar **themes; - GtkIconThemePrivate *priv; IconTheme *theme = NULL; gchar *path; GKeyFile *theme_file; GError *error = NULL; IconThemeDirMtime *dir_mtime; GStatBuf stat_buf; - - priv = icon_theme->priv; for (l = priv->themes; l != NULL; l = l->next) { @@ -1271,7 +1256,7 @@ add_unthemed_icon (GtkIconTheme *icon_theme, const gchar *file, gboolean is_resource) { - GtkIconThemePrivate *priv = icon_theme->priv; + GtkIconThemePrivate *priv = gtk_icon_theme_get_instance_private (icon_theme); IconSuffix new_suffix, old_suffix; gchar *abs_file; gchar *base_name; @@ -1334,7 +1319,7 @@ add_unthemed_icon (GtkIconTheme *icon_theme, static void load_themes (GtkIconTheme *icon_theme) { - GtkIconThemePrivate *priv; + GtkIconThemePrivate *priv = gtk_icon_theme_get_instance_private (icon_theme); GDir *gdir; gint base; gchar *dir; @@ -1343,8 +1328,6 @@ load_themes (GtkIconTheme *icon_theme) IconThemeDirMtime *dir_mtime; GStatBuf stat_buf; GList *d; - - priv = icon_theme->priv; if (priv->current_theme) insert_theme (icon_theme, priv->current_theme); @@ -1365,9 +1348,9 @@ load_themes (GtkIconTheme *icon_theme) 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++) + for (base = 0; base < priv->search_path_len; base++) { - dir = icon_theme->priv->search_path[base]; + dir = priv->search_path[base]; dir_mtime = g_slice_new (IconThemeDirMtime); priv->dir_mtimes = g_list_prepend (priv->dir_mtimes, dir_mtime); @@ -1418,11 +1401,11 @@ load_themes (GtkIconTheme *icon_theme) g_get_current_time (&tv); priv->last_stat_time = tv.tv_sec; - GTK_DISPLAY_NOTE (icon_theme->priv->display, ICONTHEME, { + GTK_DISPLAY_NOTE (priv->display, ICONTHEME, { GList *l; GString *s; s = g_string_new ("Current icon themes "); - for (l = icon_theme->priv->themes; l; l = l->next) + for (l = priv->themes; l; l = l->next) { IconTheme *theme = l->data; g_string_append (s, theme->name); @@ -1436,7 +1419,7 @@ load_themes (GtkIconTheme *icon_theme) static void ensure_valid_themes (GtkIconTheme *icon_theme) { - GtkIconThemePrivate *priv = icon_theme->priv; + GtkIconThemePrivate *priv = gtk_icon_theme_get_instance_private (icon_theme); GTimeVal tv; gboolean was_valid = priv->themes_valid; @@ -1479,7 +1462,7 @@ ensure_valid_themes (GtkIconTheme *icon_theme) static void ensure_lru_cache_space (GtkIconTheme *icon_theme) { - GtkIconThemePrivate *priv = icon_theme->priv; + GtkIconThemePrivate *priv = gtk_icon_theme_get_instance_private (icon_theme); GList *l; /* Remove last item if LRU full */ @@ -1503,7 +1486,7 @@ static void add_to_lru_cache (GtkIconTheme *icon_theme, GtkIconInfo *icon_info) { - GtkIconThemePrivate *priv = icon_theme->priv; + GtkIconThemePrivate *priv = gtk_icon_theme_get_instance_private (icon_theme); DEBUG_CACHE (("adding %p (%s %d 0x%x) to LRU cache (cache size %d)\n", icon_info, @@ -1523,7 +1506,7 @@ static void ensure_in_lru_cache (GtkIconTheme *icon_theme, GtkIconInfo *icon_info) { - GtkIconThemePrivate *priv = icon_theme->priv; + GtkIconThemePrivate *priv = gtk_icon_theme_get_instance_private (icon_theme); GList *l; l = g_list_find (priv->info_cache_lru, icon_info); @@ -1541,7 +1524,7 @@ static void remove_from_lru_cache (GtkIconTheme *icon_theme, GtkIconInfo *icon_info) { - GtkIconThemePrivate *priv = icon_theme->priv; + GtkIconThemePrivate *priv = gtk_icon_theme_get_instance_private (icon_theme); if (g_list_find (priv->info_cache_lru, icon_info)) { DEBUG_CACHE (("removing %p (%s %d 0x%x) from LRU cache (cache size %d)\n", @@ -1675,7 +1658,7 @@ real_choose_icon (GtkIconTheme *icon_theme, gint scale, GtkIconLookupFlags flags) { - GtkIconThemePrivate *priv; + GtkIconThemePrivate *priv = gtk_icon_theme_get_instance_private (icon_theme); GList *l; GtkIconInfo *icon_info = NULL; GtkIconInfo *unscaled_icon_info; @@ -1686,8 +1669,6 @@ real_choose_icon (GtkIconTheme *icon_theme, gint i; IconInfoKey key; - priv = icon_theme->priv; - ensure_valid_themes (icon_theme); key.icon_names = (gchar **)icon_names; @@ -2063,12 +2044,14 @@ gtk_icon_theme_lookup_icon (GtkIconTheme *icon_theme, gint size, GtkIconLookupFlags flags) { + GtkIconThemePrivate *priv = gtk_icon_theme_get_instance_private (icon_theme); + 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); - GTK_DISPLAY_NOTE (icon_theme->priv->display, ICONTHEME, + GTK_DISPLAY_NOTE (priv->display, ICONTHEME, g_message ("looking up icon %s", icon_name)); return gtk_icon_theme_lookup_icon_for_scale (icon_theme, icon_name, @@ -2100,6 +2083,7 @@ gtk_icon_theme_lookup_icon_for_scale (GtkIconTheme *icon_theme, gint scale, GtkIconLookupFlags flags) { + GtkIconThemePrivate *priv = gtk_icon_theme_get_instance_private (icon_theme); GtkIconInfo *info; g_return_val_if_fail (GTK_IS_ICON_THEME (icon_theme), NULL); @@ -2108,7 +2092,7 @@ gtk_icon_theme_lookup_icon_for_scale (GtkIconTheme *icon_theme, (flags & GTK_ICON_LOOKUP_FORCE_SVG) == 0, NULL); g_return_val_if_fail (scale >= 1, NULL); - GTK_DISPLAY_NOTE (icon_theme->priv->display, ICONTHEME, + GTK_DISPLAY_NOTE (priv->display, ICONTHEME, g_message ("looking up icon %s for scale %d", icon_name, scale)); if (flags & GTK_ICON_LOOKUP_GENERIC_FALLBACK) @@ -2343,6 +2327,7 @@ gtk_icon_theme_load_icon_for_scale (GtkIconTheme *icon_theme, GtkIconLookupFlags flags, GError **error) { + GtkIconThemePrivate *priv = gtk_icon_theme_get_instance_private (icon_theme); GtkIconInfo *icon_info; GdkPixbuf *pixbuf = NULL; @@ -2358,7 +2343,7 @@ gtk_icon_theme_load_icon_for_scale (GtkIconTheme *icon_theme, if (!icon_info) { g_set_error (error, GTK_ICON_THEME_ERROR, GTK_ICON_THEME_NOT_FOUND, - _("Icon ā€œ%sā€ not present in theme %s"), icon_name, icon_theme->priv->current_theme); + _("Icon ā€œ%sā€ not present in theme %s"), icon_name, priv->current_theme); return NULL; } @@ -2384,14 +2369,12 @@ gboolean gtk_icon_theme_has_icon (GtkIconTheme *icon_theme, const gchar *icon_name) { - GtkIconThemePrivate *priv; + GtkIconThemePrivate *priv = gtk_icon_theme_get_instance_private (icon_theme); GList *l; g_return_val_if_fail (GTK_IS_ICON_THEME (icon_theme), FALSE); g_return_val_if_fail (icon_name != NULL, FALSE); - priv = icon_theme->priv; - ensure_valid_themes (icon_theme); for (l = priv->dir_mtimes; l; l = l->next) @@ -2443,15 +2426,13 @@ gint * gtk_icon_theme_get_icon_sizes (GtkIconTheme *icon_theme, const gchar *icon_name) { + GtkIconThemePrivate *priv = gtk_icon_theme_get_instance_private (icon_theme); GList *l, *d; GHashTable *sizes; gint *result, *r; - guint suffix; - GtkIconThemePrivate *priv; + guint suffix; g_return_val_if_fail (GTK_IS_ICON_THEME (icon_theme), NULL); - - priv = icon_theme->priv; ensure_valid_themes (icon_theme); @@ -2531,13 +2512,11 @@ GList * gtk_icon_theme_list_icons (GtkIconTheme *icon_theme, const gchar *context) { - GtkIconThemePrivate *priv; + GtkIconThemePrivate *priv = gtk_icon_theme_get_instance_private (icon_theme); GHashTable *icons; GList *list, *l; GQuark context_quark; - - priv = icon_theme->priv; - + ensure_valid_themes (icon_theme); if (context) @@ -2591,12 +2570,10 @@ gtk_icon_theme_list_icons (GtkIconTheme *icon_theme, GList * gtk_icon_theme_list_contexts (GtkIconTheme *icon_theme) { - GtkIconThemePrivate *priv; + GtkIconThemePrivate *priv = gtk_icon_theme_get_instance_private (icon_theme); GHashTable *contexts; GList *list, *l; - priv = icon_theme->priv; - ensure_valid_themes (icon_theme); contexts = g_hash_table_new (g_str_hash, g_str_equal); @@ -2633,14 +2610,12 @@ gtk_icon_theme_list_contexts (GtkIconTheme *icon_theme) gchar * gtk_icon_theme_get_example_icon_name (GtkIconTheme *icon_theme) { - GtkIconThemePrivate *priv; + GtkIconThemePrivate *priv = gtk_icon_theme_get_instance_private (icon_theme); GList *l; IconTheme *theme; g_return_val_if_fail (GTK_IS_ICON_THEME (icon_theme), NULL); - - priv = icon_theme->priv; - + ensure_valid_themes (icon_theme); l = priv->themes; @@ -2660,15 +2635,13 @@ gtk_icon_theme_get_example_icon_name (GtkIconTheme *icon_theme) static gboolean rescan_themes (GtkIconTheme *icon_theme) { - GtkIconThemePrivate *priv; + GtkIconThemePrivate *priv = gtk_icon_theme_get_instance_private (icon_theme); IconThemeDirMtime *dir_mtime; GList *d; gint stat_res; GStatBuf stat_buf; GTimeVal tv; - priv = icon_theme->priv; - for (d = priv->dir_mtimes; d != NULL; d = d->next) { dir_mtime = d->data; @@ -3200,6 +3173,7 @@ theme_subdir_load (GtkIconTheme *icon_theme, GKeyFile *theme_file, gchar *subdir) { + GtkIconThemePrivate *priv = gtk_icon_theme_get_instance_private (icon_theme); GList *d; gchar *type_string; IconThemeDir *dir; @@ -3267,7 +3241,7 @@ theme_subdir_load (GtkIconTheme *icon_theme, else scale = 1; - for (d = icon_theme->priv->dir_mtimes; d; d = d->next) + for (d = priv->dir_mtimes; d; d = d->next) { dir_mtime = (IconThemeDirMtime *)d->data; @@ -3307,7 +3281,7 @@ theme_subdir_load (GtkIconTheme *icon_theme, { dir->cache = NULL; dir->subdir_index = -1; - has_icons = scan_directory (icon_theme->priv, dir, full_dir); + has_icons = scan_directory (priv, dir, full_dir); } if (has_icons) @@ -3321,7 +3295,7 @@ theme_subdir_load (GtkIconTheme *icon_theme, if (strcmp (theme->name, FALLBACK_ICON_THEME) == 0) { - for (d = icon_theme->priv->resource_paths; d; d = d->next) + for (d = priv->resource_paths; d; d = d->next) { /* Force a trailing / here, to avoid extra copies in GResource */ full_dir = g_build_filename ((const gchar *)d->data, subdir, " ", NULL); @@ -3340,7 +3314,7 @@ theme_subdir_load (GtkIconTheme *icon_theme, dir->cache = NULL; dir->subdir_index = -1; - if (scan_resources (icon_theme->priv, dir, full_dir)) + if (scan_resources (priv, dir, full_dir)) theme->dirs = g_list_prepend (theme->dirs, dir); else theme_dir_destroy (dir); @@ -3424,7 +3398,7 @@ gtk_icon_info_finalize (GObject *object) int i; if (icon_info->in_cache) - g_hash_table_remove (icon_info->in_cache->priv->info_cache, &icon_info->key); + gtk_icon_theme_remove_from_info_cache (icon_info->in_cache, icon_info); for (i = 0; i < icon_info->key.n_icon_names; i ++) g_free (icon_info->key.icon_names[i]); diff --git a/gtk/gtkicontheme.h b/gtk/gtkicontheme.h index de0cd2308d..34a3417e19 100644 --- a/gtk/gtkicontheme.h +++ b/gtk/gtkicontheme.h @@ -65,7 +65,7 @@ typedef struct _GtkIconTheme GtkIconTheme; * text direction * @GTK_ICON_LOOKUP_DIR_RTL: Try to load a variant of the icon for right-to-left * text direction - * + * * Used to specify options for gtk_icon_theme_lookup_icon() */ typedef enum @@ -92,7 +92,7 @@ typedef enum * GtkIconThemeError: * @GTK_ICON_THEME_NOT_FOUND: The icon specified does not exist in the theme * @GTK_ICON_THEME_FAILED: An unspecified error occurred. - * + * * Error codes for GtkIconTheme operations. **/ typedef enum {