2003-07-02 22:44:09 +00:00
|
|
|
/* GtkIconTheme - a loader for icon themes
|
|
|
|
* gtk-icon-theme.c Copyright (C) 2002, 2003 Red Hat, Inc.
|
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Lesser General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
2012-02-27 13:01:10 +00:00
|
|
|
* License along with this library. If not, see <http://www.gnu.org/licenses/>.
|
2003-07-02 22:44:09 +00:00
|
|
|
*/
|
|
|
|
|
2003-07-20 15:50:14 +00:00
|
|
|
#include "config.h"
|
|
|
|
|
2003-07-02 22:44:09 +00:00
|
|
|
#include <sys/types.h>
|
|
|
|
#include <sys/stat.h>
|
2003-07-20 15:50:14 +00:00
|
|
|
#ifdef HAVE_UNISTD_H
|
2003-07-02 22:44:09 +00:00
|
|
|
#include <unistd.h>
|
2003-07-20 15:50:14 +00:00
|
|
|
#endif
|
2003-07-02 22:44:09 +00:00
|
|
|
#include <string.h>
|
|
|
|
#include <stdlib.h>
|
2012-11-26 12:52:05 +00:00
|
|
|
#include <math.h>
|
2003-07-02 22:44:09 +00:00
|
|
|
#include <glib.h>
|
2004-12-12 21:09:13 +00:00
|
|
|
#include <glib/gstdio.h>
|
2003-07-02 22:44:09 +00:00
|
|
|
|
2003-07-20 15:50:14 +00:00
|
|
|
#ifdef G_OS_WIN32
|
|
|
|
#ifndef S_ISDIR
|
|
|
|
#define S_ISDIR(mode) ((mode)&_S_IFDIR)
|
|
|
|
#endif
|
2008-06-16 13:27:46 +00:00
|
|
|
#define WIN32_MEAN_AND_LEAN
|
|
|
|
#include <windows.h>
|
|
|
|
#include "win32/gdkwin32.h"
|
2003-07-20 15:50:14 +00:00
|
|
|
#endif /* G_OS_WIN32 */
|
|
|
|
|
2003-07-02 22:44:09 +00:00
|
|
|
#include "gtkicontheme.h"
|
2010-09-18 23:57:32 +00:00
|
|
|
#include "gtkdebug.h"
|
2013-07-20 00:29:11 +00:00
|
|
|
#include "deprecated/gtkiconfactory.h"
|
2004-10-19 18:45:41 +00:00
|
|
|
#include "gtkiconcache.h"
|
2005-11-04 15:43:40 +00:00
|
|
|
#include "gtkbuiltincache.h"
|
2003-07-02 22:44:09 +00:00
|
|
|
#include "gtkintl.h"
|
2006-08-15 17:44:09 +00:00
|
|
|
#include "gtkmain.h"
|
2011-01-05 21:30:57 +00:00
|
|
|
#include "gtknumerableiconprivate.h"
|
2003-07-02 22:44:09 +00:00
|
|
|
#include "gtksettings.h"
|
2003-07-20 15:50:14 +00:00
|
|
|
#include "gtkprivate.h"
|
2011-11-08 13:15:30 +00:00
|
|
|
|
|
|
|
#undef GDK_DEPRECATED
|
|
|
|
#undef GDK_DEPRECATED_FOR
|
|
|
|
#define GDK_DEPRECATED
|
|
|
|
#define GDK_DEPRECATED_FOR(f)
|
|
|
|
|
2011-11-02 05:15:21 +00:00
|
|
|
#include "deprecated/gtkstyle.h"
|
2004-08-09 16:59:53 +00:00
|
|
|
|
2013-05-10 16:06:00 +00:00
|
|
|
/* this is in case round() is not provided by the compiler,
|
|
|
|
* such as in the case of C89 compilers, like MSVC
|
|
|
|
*/
|
|
|
|
#include "fallback-c89.c"
|
2011-04-14 21:07:29 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* SECTION:gtkicontheme
|
|
|
|
* @Short_description: Looking up icons by name
|
|
|
|
* @Title: GtkIconTheme
|
|
|
|
*
|
|
|
|
* #GtkIconTheme provides a facility for looking up icons by name
|
|
|
|
* and size. The main reason for using a name rather than simply
|
|
|
|
* providing a filename is to allow different icons to be used
|
|
|
|
* depending on what <firstterm>icon theme</firstterm> is selected
|
|
|
|
* by the user. The operation of icon themes on Linux and Unix
|
|
|
|
* follows the <ulink
|
|
|
|
* url="http://www.freedesktop.org/Standards/icon-theme-spec">Icon
|
|
|
|
* Theme Specification</ulink>. There is a default icon theme,
|
|
|
|
* named <literal>hicolor</literal> where applications should install
|
|
|
|
* their icons, but more additional application themes can be
|
|
|
|
* installed as operating system vendors and users choose.
|
|
|
|
*
|
|
|
|
* Named icons are similar to the <xref linkend="gtk3-Themeable-Stock-Images"/>
|
|
|
|
* facility, and the distinction between the two may be a bit confusing.
|
|
|
|
* A few things to keep in mind:
|
|
|
|
* <itemizedlist>
|
|
|
|
* <listitem>
|
|
|
|
* Stock images usually are used in conjunction with
|
|
|
|
* <xref linkend="gtk3-Stock-Items"/>, such as %GTK_STOCK_OK or
|
|
|
|
* %GTK_STOCK_OPEN. Named icons are easier to set up and therefore
|
|
|
|
* are more useful for new icons that an application wants to
|
|
|
|
* add, such as application icons or window icons.
|
|
|
|
* </listitem>
|
|
|
|
* <listitem>
|
|
|
|
* Stock images can only be loaded at the symbolic sizes defined
|
|
|
|
* by the #GtkIconSize enumeration, or by custom sizes defined
|
|
|
|
* by gtk_icon_size_register(), while named icons are more flexible
|
|
|
|
* and any pixel size can be specified.
|
|
|
|
* </listitem>
|
|
|
|
* <listitem>
|
|
|
|
* Because stock images are closely tied to stock items, and thus
|
|
|
|
* to actions in the user interface, stock images may come in
|
|
|
|
* multiple variants for different widget states or writing
|
|
|
|
* directions.
|
|
|
|
* </listitem>
|
|
|
|
* </itemizedlist>
|
|
|
|
* A good rule of thumb is that if there is a stock image for what
|
|
|
|
* you want to use, use it, otherwise use a named icon. It turns
|
|
|
|
* out that internally stock images are generally defined in
|
|
|
|
* terms of one or more named icons. (An example of the
|
|
|
|
* more than one case is icons that depend on writing direction;
|
|
|
|
* %GTK_STOCK_GO_FORWARD uses the two themed icons
|
|
|
|
* "gtk-stock-go-forward-ltr" and "gtk-stock-go-forward-rtl".)
|
|
|
|
*
|
|
|
|
* In many cases, named themes are used indirectly, via #GtkImage
|
|
|
|
* or stock items, rather than directly, but looking up icons
|
|
|
|
* directly is also simple. The #GtkIconTheme object acts
|
|
|
|
* as a database of all the icons in the current theme. You
|
2012-02-29 17:19:55 +00:00
|
|
|
* can create new #GtkIconTheme objects, but it's much more
|
2011-04-14 21:07:29 +00:00
|
|
|
* efficient to use the standard icon theme for the #GdkScreen
|
|
|
|
* so that the icon information is shared with other people
|
|
|
|
* looking up icons. In the case where the default screen is
|
|
|
|
* being used, looking up an icon can be as simple as:
|
|
|
|
* <informalexample>
|
|
|
|
* <programlisting>
|
|
|
|
* GError *error = NULL;
|
|
|
|
* GtkIconTheme *icon_theme;
|
|
|
|
* GdkPixbuf *pixbuf;
|
|
|
|
*
|
|
|
|
* icon_theme = gtk_icon_theme_get_default ();
|
|
|
|
* pixbuf = gtk_icon_theme_load_icon (icon_theme,
|
|
|
|
* "my-icon-name", // icon name
|
|
|
|
* 48, // size
|
|
|
|
* 0, // flags
|
|
|
|
* &error);
|
|
|
|
* if (!pixbuf)
|
|
|
|
* {
|
|
|
|
* g_warning ("Couldn't load icon: %s", error->message);
|
|
|
|
* g_error_free (error);
|
|
|
|
* }
|
|
|
|
* else
|
|
|
|
* {
|
|
|
|
* // Use the pixbuf
|
|
|
|
* g_object_unref (pixbuf);
|
|
|
|
* }
|
|
|
|
* </programlisting>
|
|
|
|
* </informalexample>
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
2003-07-02 22:44:09 +00:00
|
|
|
#define DEFAULT_THEME_NAME "hicolor"
|
|
|
|
|
|
|
|
typedef enum
|
|
|
|
{
|
|
|
|
ICON_THEME_DIR_FIXED,
|
|
|
|
ICON_THEME_DIR_SCALABLE,
|
|
|
|
ICON_THEME_DIR_THRESHOLD,
|
|
|
|
ICON_THEME_DIR_UNTHEMED
|
|
|
|
} IconThemeDirType;
|
|
|
|
|
|
|
|
/* In reverse search order: */
|
|
|
|
typedef enum
|
|
|
|
{
|
|
|
|
ICON_SUFFIX_NONE = 0,
|
|
|
|
ICON_SUFFIX_XPM = 1 << 0,
|
|
|
|
ICON_SUFFIX_SVG = 1 << 1,
|
2004-10-19 18:45:41 +00:00
|
|
|
ICON_SUFFIX_PNG = 1 << 2,
|
|
|
|
HAS_ICON_FILE = 1 << 3
|
2003-07-02 22:44:09 +00:00
|
|
|
} IconSuffix;
|
|
|
|
|
2012-11-26 12:49:49 +00:00
|
|
|
#define INFO_CACHE_LRU_SIZE 32
|
|
|
|
#if 0
|
|
|
|
#define DEBUG_CACHE(args) g_print args
|
|
|
|
#else
|
|
|
|
#define DEBUG_CACHE(args)
|
|
|
|
#endif
|
2003-07-02 22:44:09 +00:00
|
|
|
|
|
|
|
struct _GtkIconThemePrivate
|
|
|
|
{
|
2012-11-26 12:49:49 +00:00
|
|
|
GHashTable *info_cache;
|
|
|
|
GList *info_cache_lru;
|
|
|
|
|
2011-04-12 16:33:04 +00:00
|
|
|
gchar *current_theme;
|
|
|
|
gchar **search_path;
|
|
|
|
gint search_path_len;
|
|
|
|
|
2006-03-31 05:17:56 +00:00
|
|
|
guint custom_theme : 1;
|
2003-07-02 22:44:09 +00:00
|
|
|
guint is_screen_singleton : 1;
|
|
|
|
guint pixbuf_supports_svg : 1;
|
2006-03-31 05:17:56 +00:00
|
|
|
guint themes_valid : 1;
|
2007-03-15 18:40:16 +00:00
|
|
|
guint loading_themes : 1;
|
2003-07-02 22:44:09 +00:00
|
|
|
|
|
|
|
/* A list of all the themes needed to look up icons.
|
|
|
|
* In search order, without duplicates
|
|
|
|
*/
|
|
|
|
GList *themes;
|
|
|
|
GHashTable *unthemed_icons;
|
2011-04-12 16:33:04 +00:00
|
|
|
|
2003-07-02 22:44:09 +00:00
|
|
|
/* Note: The keys of this hashtable are owned by the
|
|
|
|
* themedir and unthemed hashtables.
|
|
|
|
*/
|
|
|
|
GHashTable *all_icons;
|
|
|
|
|
|
|
|
/* GdkScreen for the icon theme (may be NULL)
|
|
|
|
*/
|
|
|
|
GdkScreen *screen;
|
2011-04-12 16:33:04 +00:00
|
|
|
|
2003-07-02 22:44:09 +00:00
|
|
|
/* time when we last stat:ed for theme changes */
|
2011-04-12 16:33:04 +00:00
|
|
|
glong last_stat_time;
|
2003-07-02 22:44:09 +00:00
|
|
|
GList *dir_mtimes;
|
2005-08-12 18:39:17 +00:00
|
|
|
|
2013-06-19 09:06:20 +00:00
|
|
|
gulong theme_changed_idle;
|
2003-07-02 22:44:09 +00:00
|
|
|
};
|
|
|
|
|
2012-11-26 12:49:49 +00:00
|
|
|
typedef struct {
|
|
|
|
gchar **icon_names;
|
|
|
|
gint size;
|
2013-05-10 16:06:00 +00:00
|
|
|
gint scale;
|
2012-11-26 12:49:49 +00:00
|
|
|
GtkIconLookupFlags flags;
|
|
|
|
} IconInfoKey;
|
|
|
|
|
2012-11-26 12:52:05 +00:00
|
|
|
typedef struct _SymbolicPixbufCache SymbolicPixbufCache;
|
|
|
|
|
|
|
|
struct _SymbolicPixbufCache {
|
|
|
|
GdkPixbuf *pixbuf;
|
|
|
|
GdkPixbuf *proxy_pixbuf;
|
|
|
|
GdkRGBA fg;
|
|
|
|
GdkRGBA success_color;
|
|
|
|
GdkRGBA warning_color;
|
|
|
|
GdkRGBA error_color;
|
|
|
|
SymbolicPixbufCache *next;
|
|
|
|
};
|
|
|
|
|
2013-02-13 14:05:02 +00:00
|
|
|
struct _GtkIconInfoClass
|
|
|
|
{
|
|
|
|
GObjectClass parent_class;
|
|
|
|
};
|
|
|
|
|
2003-07-02 22:44:09 +00:00
|
|
|
struct _GtkIconInfo
|
|
|
|
{
|
2013-02-13 14:05:02 +00:00
|
|
|
GObject parent_instance;
|
|
|
|
|
2003-07-02 22:44:09 +00:00
|
|
|
/* Information about the source
|
|
|
|
*/
|
2012-11-26 12:49:49 +00:00
|
|
|
IconInfoKey key;
|
|
|
|
GtkIconTheme *in_cache;
|
|
|
|
|
2003-07-02 22:44:09 +00:00
|
|
|
gchar *filename;
|
2012-10-28 19:01:30 +00:00
|
|
|
GFile *icon_file;
|
2008-05-29 14:33:49 +00:00
|
|
|
GLoadableIcon *loadable;
|
2008-07-28 16:15:14 +00:00
|
|
|
GSList *emblem_infos;
|
2008-05-29 14:33:49 +00:00
|
|
|
|
Update spec.
2005-03-15 Anders Carlsson <andersca@imendio.com>
* docs/iconcache.txt:
Update spec.
* gtk/gtkiconcache.c: (find_image_offset),
(_gtk_icon_cache_get_icon_flags), (_gtk_icon_cache_add_icons),
(_gtk_icon_cache_get_icon), (_gtk_icon_cache_get_icon_data):
* gtk/gtkiconcache.h:
Update to be able to fetch pixbuf data and icon metadata.
* gtk/gtkicontheme.c: (theme_lookup_icon), (gtk_icon_info_free),
(icon_info_ensure_scale_and_pixbuf):
Use new cache functions.
* gtk/updateiconcache.c: (foreach_remove_func), (load_icon_data),
(maybe_cache_image_data), (scan_directory), (write_pixdata),
(get_image_meta_data_size), (get_image_pixel_data_size),
(get_image_data_size), (get_single_node_size), (get_bucket_size),
(write_bucket), (main):
Update to write pixbuf data as well as information from .icon
files.
2005-03-15 13:18:25 +00:00
|
|
|
/* Cache pixbuf (if there is any) */
|
|
|
|
GdkPixbuf *cache_pixbuf;
|
|
|
|
|
2003-07-02 22:44:09 +00:00
|
|
|
GtkIconData *data;
|
2011-04-12 16:33:04 +00:00
|
|
|
|
2003-07-02 22:44:09 +00:00
|
|
|
/* Information about the directory where
|
|
|
|
* the source was found
|
|
|
|
*/
|
|
|
|
IconThemeDirType dir_type;
|
|
|
|
gint dir_size;
|
2013-05-10 16:06:00 +00:00
|
|
|
gint dir_scale;
|
2013-09-23 10:42:30 +00:00
|
|
|
gdouble unscaled_scale;
|
2003-07-02 22:44:09 +00:00
|
|
|
gint threshold;
|
|
|
|
|
|
|
|
/* Parameters influencing the scaled icon
|
|
|
|
*/
|
|
|
|
gint desired_size;
|
2013-05-10 16:06:00 +00:00
|
|
|
gint desired_scale;
|
2008-05-29 14:33:49 +00:00
|
|
|
guint raw_coordinates : 1;
|
|
|
|
guint forced_size : 1;
|
2011-04-12 16:33:04 +00:00
|
|
|
guint emblems_applied : 1;
|
|
|
|
|
2003-07-02 22:44:09 +00:00
|
|
|
/* Cached information if we go ahead and try to load
|
|
|
|
* the icon.
|
|
|
|
*/
|
|
|
|
GdkPixbuf *pixbuf;
|
2012-11-26 12:49:49 +00:00
|
|
|
GdkPixbuf *proxy_pixbuf;
|
2003-07-02 22:44:09 +00:00
|
|
|
GError *load_error;
|
|
|
|
gdouble scale;
|
2012-06-06 16:16:05 +00:00
|
|
|
|
2012-11-26 12:52:05 +00:00
|
|
|
SymbolicPixbufCache *symbolic_pixbuf_cache;
|
|
|
|
|
2012-06-06 16:16:05 +00:00
|
|
|
GtkRequisition *symbolic_pixbuf_size;
|
2003-07-02 22:44:09 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
typedef struct
|
|
|
|
{
|
|
|
|
char *name;
|
|
|
|
char *display_name;
|
|
|
|
char *comment;
|
|
|
|
char *example;
|
|
|
|
|
|
|
|
/* In search order */
|
|
|
|
GList *dirs;
|
|
|
|
} IconTheme;
|
|
|
|
|
|
|
|
typedef struct
|
|
|
|
{
|
|
|
|
IconThemeDirType type;
|
|
|
|
GQuark context;
|
|
|
|
|
|
|
|
int size;
|
|
|
|
int min_size;
|
|
|
|
int max_size;
|
|
|
|
int threshold;
|
2013-05-10 16:06:00 +00:00
|
|
|
int scale;
|
2003-07-02 22:44:09 +00:00
|
|
|
|
|
|
|
char *dir;
|
2004-10-19 18:45:41 +00:00
|
|
|
char *subdir;
|
2007-12-03 17:44:27 +00:00
|
|
|
int subdir_index;
|
2004-10-19 18:45:41 +00:00
|
|
|
|
|
|
|
GtkIconCache *cache;
|
2003-07-02 22:44:09 +00:00
|
|
|
|
|
|
|
GHashTable *icons;
|
|
|
|
GHashTable *icon_data;
|
|
|
|
} IconThemeDir;
|
|
|
|
|
|
|
|
typedef struct
|
|
|
|
{
|
|
|
|
char *svg_filename;
|
|
|
|
char *no_svg_filename;
|
|
|
|
} UnthemedIcon;
|
|
|
|
|
|
|
|
typedef struct
|
|
|
|
{
|
|
|
|
gint size;
|
|
|
|
GdkPixbuf *pixbuf;
|
|
|
|
} BuiltinIcon;
|
|
|
|
|
|
|
|
typedef struct
|
|
|
|
{
|
|
|
|
char *dir;
|
|
|
|
time_t mtime; /* 0 == not existing or not a dir */
|
2005-04-06 03:34:38 +00:00
|
|
|
|
|
|
|
GtkIconCache *cache;
|
2003-07-02 22:44:09 +00:00
|
|
|
} IconThemeDirMtime;
|
|
|
|
|
|
|
|
static void gtk_icon_theme_finalize (GObject *object);
|
|
|
|
static void theme_dir_destroy (IconThemeDir *dir);
|
|
|
|
|
|
|
|
static void theme_destroy (IconTheme *theme);
|
|
|
|
static GtkIconInfo *theme_lookup_icon (IconTheme *theme,
|
|
|
|
const char *icon_name,
|
|
|
|
int size,
|
2013-05-10 16:06:00 +00:00
|
|
|
gint scale,
|
2003-07-02 22:44:09 +00:00
|
|
|
gboolean allow_svg,
|
|
|
|
gboolean use_default_icons);
|
|
|
|
static void theme_list_icons (IconTheme *theme,
|
|
|
|
GHashTable *icons,
|
|
|
|
GQuark context);
|
2007-03-21 19:31:01 +00:00
|
|
|
static void theme_list_contexts (IconTheme *theme,
|
|
|
|
GHashTable *contexts);
|
2003-07-02 22:44:09 +00:00
|
|
|
static void theme_subdir_load (GtkIconTheme *icon_theme,
|
|
|
|
IconTheme *theme,
|
2004-10-24 05:48:16 +00:00
|
|
|
GKeyFile *theme_file,
|
2003-07-02 22:44:09 +00:00
|
|
|
char *subdir);
|
|
|
|
static void do_theme_change (GtkIconTheme *icon_theme);
|
|
|
|
|
2007-03-15 18:40:16 +00:00
|
|
|
static void blow_themes (GtkIconTheme *icon_themes);
|
|
|
|
static gboolean rescan_themes (GtkIconTheme *icon_themes);
|
2003-07-02 22:44:09 +00:00
|
|
|
|
2013-02-14 12:32:30 +00:00
|
|
|
static GtkIconData *icon_data_dup (GtkIconData *icon_data);
|
2013-06-19 07:32:38 +00:00
|
|
|
static GtkIconData *icon_data_ref (GtkIconData *icon_data);
|
|
|
|
static void icon_data_unref (GtkIconData *icon_data);
|
2005-08-19 04:39:30 +00:00
|
|
|
static void load_icon_data (IconThemeDir *dir,
|
|
|
|
const char *path,
|
|
|
|
const char *name);
|
2004-10-19 18:45:41 +00:00
|
|
|
|
|
|
|
static IconSuffix theme_dir_get_icon_suffix (IconThemeDir *dir,
|
|
|
|
const gchar *icon_name,
|
|
|
|
gboolean *has_icon_file);
|
|
|
|
|
2003-07-02 22:44:09 +00:00
|
|
|
|
2013-09-23 10:37:36 +00:00
|
|
|
static GtkIconInfo *icon_info_new (IconThemeDirType type, int dir_size, int dir_scale);
|
2003-07-02 22:44:09 +00:00
|
|
|
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,
|
2005-11-04 15:43:40 +00:00
|
|
|
gint size,
|
2013-05-10 16:06:00 +00:00
|
|
|
gint scale,
|
|
|
|
gint *min_difference_p);
|
2012-11-26 12:49:49 +00:00
|
|
|
static void remove_from_lru_cache (GtkIconTheme *icon_theme,
|
|
|
|
GtkIconInfo *icon_info);
|
2003-07-02 22:44:09 +00:00
|
|
|
|
|
|
|
static guint signal_changed = 0;
|
|
|
|
|
|
|
|
static GHashTable *icon_theme_builtin_icons;
|
|
|
|
|
2005-11-04 15:43:40 +00:00
|
|
|
/* also used in gtkiconfactory.c */
|
|
|
|
GtkIconCache *_builtin_cache = NULL;
|
|
|
|
static GList *builtin_dirs = NULL;
|
|
|
|
|
2012-11-26 12:49:49 +00:00
|
|
|
static guint
|
|
|
|
icon_info_key_hash (gconstpointer _key)
|
|
|
|
{
|
|
|
|
const IconInfoKey *key = _key;
|
|
|
|
guint h = 0;
|
|
|
|
int i;
|
|
|
|
for (i = 0; key->icon_names[i] != NULL; i++)
|
|
|
|
h ^= g_str_hash (key->icon_names[i]);
|
|
|
|
|
|
|
|
h ^= key->size * 0x10001;
|
2013-05-10 16:06:00 +00:00
|
|
|
h ^= key->scale * 0x1000010;
|
|
|
|
h ^= key->flags * 0x100000100;
|
2012-11-26 12:49:49 +00:00
|
|
|
|
|
|
|
return h;
|
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
|
|
|
icon_info_key_equal (gconstpointer _a,
|
|
|
|
gconstpointer _b)
|
|
|
|
{
|
|
|
|
const IconInfoKey *a = _a;
|
|
|
|
const IconInfoKey *b = _b;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
if (a->size != b->size)
|
|
|
|
return FALSE;
|
|
|
|
|
2013-05-10 16:06:00 +00:00
|
|
|
if (a->scale != b->scale)
|
|
|
|
return FALSE;
|
|
|
|
|
2012-11-26 12:49:49 +00:00
|
|
|
if (a->flags != b->flags)
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
for (i = 0;
|
|
|
|
a->icon_names[i] != NULL &&
|
|
|
|
b->icon_names[i] != NULL; i++)
|
|
|
|
{
|
|
|
|
if (strcmp (a->icon_names[i], b->icon_names[i]) != 0)
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
return a->icon_names[i] == NULL && b->icon_names[i] == NULL;
|
|
|
|
}
|
|
|
|
|
2013-06-27 19:02:52 +00:00
|
|
|
G_DEFINE_TYPE_WITH_PRIVATE (GtkIconTheme, gtk_icon_theme, G_TYPE_OBJECT)
|
2003-07-02 22:44:09 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* gtk_icon_theme_new:
|
|
|
|
*
|
|
|
|
* Creates a new icon theme object. Icon theme objects are used
|
|
|
|
* to lookup up an icon by name in a particular icon theme.
|
|
|
|
* Usually, you'll want to use gtk_icon_theme_get_default()
|
|
|
|
* or gtk_icon_theme_get_for_screen() rather than creating
|
|
|
|
* a new icon theme object for scratch.
|
|
|
|
*
|
|
|
|
* Return value: the newly created #GtkIconTheme object.
|
2003-11-08 00:51:10 +00:00
|
|
|
*
|
|
|
|
* Since: 2.4
|
2003-07-02 22:44:09 +00:00
|
|
|
**/
|
|
|
|
GtkIconTheme *
|
|
|
|
gtk_icon_theme_new (void)
|
|
|
|
{
|
|
|
|
return g_object_new (GTK_TYPE_ICON_THEME, NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* gtk_icon_theme_get_default:
|
|
|
|
*
|
|
|
|
* Gets the icon theme for the default screen. See
|
|
|
|
* gtk_icon_theme_get_for_screen().
|
2009-12-10 10:23:40 +00:00
|
|
|
*
|
|
|
|
* Return value: (transfer none): A unique #GtkIconTheme associated with
|
2003-07-02 22:44:09 +00:00
|
|
|
* the default screen. This icon theme is associated with
|
|
|
|
* the screen and can be used as long as the screen
|
2005-07-13 04:53:49 +00:00
|
|
|
* is open. Do not ref or unref it.
|
2003-11-08 00:51:10 +00:00
|
|
|
*
|
|
|
|
* Since: 2.4
|
2003-07-02 22:44:09 +00:00
|
|
|
**/
|
|
|
|
GtkIconTheme *
|
|
|
|
gtk_icon_theme_get_default (void)
|
|
|
|
{
|
|
|
|
return gtk_icon_theme_get_for_screen (gdk_screen_get_default ());
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* gtk_icon_theme_get_for_screen:
|
|
|
|
* @screen: a #GdkScreen
|
|
|
|
*
|
|
|
|
* Gets the icon theme object associated with @screen; if this
|
|
|
|
* function has not previously been called for the given
|
|
|
|
* screen, a new icon theme object will be created and
|
|
|
|
* associated with the screen. Icon theme objects are
|
|
|
|
* fairly expensive to create, so using this function
|
|
|
|
* is usually a better choice than calling than gtk_icon_theme_new()
|
|
|
|
* and setting the screen yourself; by using this function
|
|
|
|
* a single icon theme object will be shared between users.
|
2009-12-10 10:23:40 +00:00
|
|
|
*
|
|
|
|
* Return value: (transfer none): A unique #GtkIconTheme associated with
|
2003-07-02 22:44:09 +00:00
|
|
|
* the given screen. This icon theme is associated with
|
|
|
|
* the screen and can be used as long as the screen
|
2005-07-13 04:53:49 +00:00
|
|
|
* is open. Do not ref or unref it.
|
2003-11-08 00:51:10 +00:00
|
|
|
*
|
|
|
|
* Since: 2.4
|
2003-07-02 22:44:09 +00:00
|
|
|
**/
|
|
|
|
GtkIconTheme *
|
|
|
|
gtk_icon_theme_get_for_screen (GdkScreen *screen)
|
|
|
|
{
|
|
|
|
GtkIconTheme *icon_theme;
|
|
|
|
|
|
|
|
g_return_val_if_fail (GDK_IS_SCREEN (screen), NULL);
|
|
|
|
|
|
|
|
icon_theme = g_object_get_data (G_OBJECT (screen), "gtk-icon-theme");
|
|
|
|
if (!icon_theme)
|
|
|
|
{
|
|
|
|
GtkIconThemePrivate *priv;
|
|
|
|
|
|
|
|
icon_theme = gtk_icon_theme_new ();
|
|
|
|
gtk_icon_theme_set_screen (icon_theme, screen);
|
|
|
|
|
|
|
|
priv = icon_theme->priv;
|
|
|
|
priv->is_screen_singleton = TRUE;
|
|
|
|
|
2005-09-01 05:11:46 +00:00
|
|
|
g_object_set_data (G_OBJECT (screen), I_("gtk-icon-theme"), icon_theme);
|
2003-07-02 22:44:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return icon_theme;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gtk_icon_theme_class_init (GtkIconThemeClass *klass)
|
|
|
|
{
|
|
|
|
GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
|
|
|
|
|
|
|
|
gobject_class->finalize = gtk_icon_theme_finalize;
|
|
|
|
|
|
|
|
/**
|
2012-04-13 00:07:28 +00:00
|
|
|
* GtkIconTheme::changed:
|
2003-07-02 22:44:09 +00:00
|
|
|
* @icon_theme: the icon theme
|
|
|
|
*
|
|
|
|
* Emitted when the current icon theme is switched or GTK+ detects
|
|
|
|
* that a change has occurred in the contents of the current
|
|
|
|
* icon theme.
|
|
|
|
**/
|
2005-09-01 05:11:46 +00:00
|
|
|
signal_changed = g_signal_new (I_("changed"),
|
2003-07-02 22:44:09 +00:00
|
|
|
G_TYPE_FROM_CLASS (klass),
|
|
|
|
G_SIGNAL_RUN_LAST,
|
|
|
|
G_STRUCT_OFFSET (GtkIconThemeClass, changed),
|
|
|
|
NULL, NULL,
|
|
|
|
g_cclosure_marshal_VOID__VOID,
|
|
|
|
G_TYPE_NONE, 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* Callback when the display that the icon theme is attached to
|
|
|
|
* is closed; unset the screen, and if it's the unique theme
|
|
|
|
* for the screen, drop the reference
|
|
|
|
*/
|
|
|
|
static void
|
|
|
|
display_closed (GdkDisplay *display,
|
|
|
|
gboolean is_error,
|
|
|
|
GtkIconTheme *icon_theme)
|
|
|
|
{
|
|
|
|
GtkIconThemePrivate *priv = icon_theme->priv;
|
|
|
|
GdkScreen *screen = priv->screen;
|
|
|
|
gboolean was_screen_singleton = priv->is_screen_singleton;
|
|
|
|
|
|
|
|
if (was_screen_singleton)
|
|
|
|
{
|
2005-09-01 05:11:46 +00:00
|
|
|
g_object_set_data (G_OBJECT (screen), I_("gtk-icon-theme"), NULL);
|
2003-07-02 22:44:09 +00:00
|
|
|
priv->is_screen_singleton = FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
gtk_icon_theme_set_screen (icon_theme, NULL);
|
|
|
|
|
|
|
|
if (was_screen_singleton)
|
|
|
|
{
|
|
|
|
g_object_unref (icon_theme);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
update_current_theme (GtkIconTheme *icon_theme)
|
|
|
|
{
|
2007-03-06 18:26:41 +00:00
|
|
|
#define theme_changed(_old, _new) \
|
|
|
|
((_old && !_new) || (!_old && _new) || \
|
|
|
|
(_old && _new && strcmp (_old, _new) != 0))
|
2003-07-02 22:44:09 +00:00
|
|
|
GtkIconThemePrivate *priv = icon_theme->priv;
|
|
|
|
|
|
|
|
if (!priv->custom_theme)
|
|
|
|
{
|
|
|
|
gchar *theme = NULL;
|
2006-01-11 06:20:17 +00:00
|
|
|
gboolean changed = FALSE;
|
2003-07-02 22:44:09 +00:00
|
|
|
|
|
|
|
if (priv->screen)
|
|
|
|
{
|
|
|
|
GtkSettings *settings = gtk_settings_get_for_screen (priv->screen);
|
2013-06-26 16:47:43 +00:00
|
|
|
g_object_get (settings, "gtk-icon-theme-name", &theme, NULL);
|
2003-07-02 22:44:09 +00:00
|
|
|
}
|
|
|
|
|
2007-03-06 18:26:41 +00:00
|
|
|
if (theme_changed (priv->current_theme, theme))
|
2003-07-02 22:44:09 +00:00
|
|
|
{
|
|
|
|
g_free (priv->current_theme);
|
|
|
|
priv->current_theme = theme;
|
2006-01-11 06:20:17 +00:00
|
|
|
changed = TRUE;
|
2003-07-02 22:44:09 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
g_free (theme);
|
2006-01-11 06:20:17 +00:00
|
|
|
|
|
|
|
if (changed)
|
|
|
|
do_theme_change (icon_theme);
|
2003-07-02 22:44:09 +00:00
|
|
|
}
|
2007-03-06 18:26:41 +00:00
|
|
|
#undef theme_changed
|
2003-07-02 22:44:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Callback when the icon theme GtkSetting changes
|
|
|
|
*/
|
|
|
|
static void
|
|
|
|
theme_changed (GtkSettings *settings,
|
|
|
|
GParamSpec *pspec,
|
|
|
|
GtkIconTheme *icon_theme)
|
|
|
|
{
|
|
|
|
update_current_theme (icon_theme);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
unset_screen (GtkIconTheme *icon_theme)
|
|
|
|
{
|
|
|
|
GtkIconThemePrivate *priv = icon_theme->priv;
|
|
|
|
GtkSettings *settings;
|
|
|
|
GdkDisplay *display;
|
|
|
|
|
|
|
|
if (priv->screen)
|
|
|
|
{
|
|
|
|
settings = gtk_settings_get_for_screen (priv->screen);
|
|
|
|
display = gdk_screen_get_display (priv->screen);
|
|
|
|
|
|
|
|
g_signal_handlers_disconnect_by_func (display,
|
|
|
|
(gpointer) display_closed,
|
|
|
|
icon_theme);
|
|
|
|
g_signal_handlers_disconnect_by_func (settings,
|
|
|
|
(gpointer) theme_changed,
|
|
|
|
icon_theme);
|
|
|
|
|
|
|
|
priv->screen = NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* gtk_icon_theme_set_screen:
|
|
|
|
* @icon_theme: a #GtkIconTheme
|
|
|
|
* @screen: a #GdkScreen
|
|
|
|
*
|
|
|
|
* Sets the screen for an icon theme; the screen is used
|
|
|
|
* to track the user's currently configured icon theme,
|
|
|
|
* which might be different for different screens.
|
2003-11-08 00:51:10 +00:00
|
|
|
*
|
|
|
|
* Since: 2.4
|
2003-07-02 22:44:09 +00:00
|
|
|
**/
|
|
|
|
void
|
|
|
|
gtk_icon_theme_set_screen (GtkIconTheme *icon_theme,
|
|
|
|
GdkScreen *screen)
|
|
|
|
{
|
|
|
|
GtkIconThemePrivate *priv;
|
|
|
|
GtkSettings *settings;
|
|
|
|
GdkDisplay *display;
|
|
|
|
|
|
|
|
g_return_if_fail (GTK_ICON_THEME (icon_theme));
|
|
|
|
g_return_if_fail (screen == NULL || GDK_IS_SCREEN (screen));
|
|
|
|
|
|
|
|
priv = icon_theme->priv;
|
|
|
|
|
|
|
|
unset_screen (icon_theme);
|
|
|
|
|
|
|
|
if (screen)
|
|
|
|
{
|
|
|
|
display = gdk_screen_get_display (screen);
|
|
|
|
settings = gtk_settings_get_for_screen (screen);
|
|
|
|
|
|
|
|
priv->screen = screen;
|
|
|
|
|
|
|
|
g_signal_connect (display, "closed",
|
|
|
|
G_CALLBACK (display_closed), icon_theme);
|
|
|
|
g_signal_connect (settings, "notify::gtk-icon-theme-name",
|
|
|
|
G_CALLBACK (theme_changed), icon_theme);
|
|
|
|
}
|
|
|
|
|
|
|
|
update_current_theme (icon_theme);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Checks whether a loader for SVG files has been registered
|
|
|
|
* with GdkPixbuf.
|
|
|
|
*/
|
|
|
|
static gboolean
|
2004-10-28 15:00:05 +00:00
|
|
|
pixbuf_supports_svg (void)
|
2003-07-02 22:44:09 +00:00
|
|
|
{
|
2006-10-15 22:58:08 +00:00
|
|
|
GSList *formats;
|
2003-07-02 22:44:09 +00:00
|
|
|
GSList *tmp_list;
|
2006-04-04 04:14:17 +00:00
|
|
|
static gint found_svg = -1;
|
2003-07-02 22:44:09 +00:00
|
|
|
|
2006-04-04 04:14:17 +00:00
|
|
|
if (found_svg != -1)
|
2004-10-19 18:45:41 +00:00
|
|
|
return found_svg;
|
2006-10-15 22:58:08 +00:00
|
|
|
|
|
|
|
formats = gdk_pixbuf_get_formats ();
|
|
|
|
|
2006-04-04 04:14:17 +00:00
|
|
|
found_svg = FALSE;
|
2003-07-02 22:44:09 +00:00
|
|
|
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);
|
|
|
|
gchar **mime_type;
|
|
|
|
|
|
|
|
for (mime_type = mime_types; *mime_type && !found_svg; mime_type++)
|
|
|
|
{
|
|
|
|
if (strcmp (*mime_type, "image/svg") == 0)
|
|
|
|
found_svg = TRUE;
|
|
|
|
}
|
|
|
|
|
2003-07-11 20:36:25 +00:00
|
|
|
g_strfreev (mime_types);
|
2003-07-02 22:44:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
g_slist_free (formats);
|
2004-10-19 18:45:41 +00:00
|
|
|
|
2003-07-02 22:44:09 +00:00
|
|
|
return found_svg;
|
|
|
|
}
|
|
|
|
|
2012-11-26 12:49:49 +00:00
|
|
|
/* The icon info was removed from the icon_info_hash hash table */
|
|
|
|
static void
|
|
|
|
icon_info_uncached (GtkIconInfo *icon_info)
|
|
|
|
{
|
|
|
|
GtkIconTheme *icon_theme = icon_info->in_cache;
|
|
|
|
|
|
|
|
DEBUG_CACHE (("removing %p (%s %d 0x%x) from cache (icon_them: %p) (cache size %d)\n",
|
|
|
|
icon_info,
|
|
|
|
g_strjoinv (",", icon_info->key.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_info->in_cache = NULL;
|
|
|
|
|
|
|
|
if (icon_theme != NULL)
|
|
|
|
remove_from_lru_cache (icon_theme, icon_info);
|
|
|
|
}
|
|
|
|
|
2003-07-02 22:44:09 +00:00
|
|
|
static void
|
|
|
|
gtk_icon_theme_init (GtkIconTheme *icon_theme)
|
|
|
|
{
|
|
|
|
GtkIconThemePrivate *priv;
|
2004-08-18 15:45:13 +00:00
|
|
|
const gchar * const *xdg_data_dirs;
|
2004-08-17 19:51:11 +00:00
|
|
|
int i, j;
|
2010-06-22 14:42:00 +00:00
|
|
|
|
2013-06-27 19:02:52 +00:00
|
|
|
priv = gtk_icon_theme_get_instance_private (icon_theme);
|
2003-07-02 22:44:09 +00:00
|
|
|
icon_theme->priv = priv;
|
|
|
|
|
2012-11-26 12:49:49 +00:00
|
|
|
priv->info_cache = g_hash_table_new_full (icon_info_key_hash, icon_info_key_equal, NULL,
|
|
|
|
(GDestroyNotify)icon_info_uncached);
|
|
|
|
|
2003-07-02 22:44:09 +00:00
|
|
|
priv->custom_theme = FALSE;
|
2004-08-17 19:51:11 +00:00
|
|
|
|
|
|
|
xdg_data_dirs = g_get_system_data_dirs ();
|
|
|
|
for (i = 0; xdg_data_dirs[i]; i++) ;
|
|
|
|
|
2005-02-02 04:31:21 +00:00
|
|
|
priv->search_path_len = 2 * i + 2;
|
2004-08-17 19:51:11 +00:00
|
|
|
|
|
|
|
priv->search_path = g_new (char *, priv->search_path_len);
|
|
|
|
|
|
|
|
i = 0;
|
|
|
|
priv->search_path[i++] = g_build_filename (g_get_user_data_dir (), "icons", NULL);
|
2012-04-27 16:39:17 +00:00
|
|
|
priv->search_path[i++] = g_build_filename (g_get_home_dir (), ".icons", NULL);
|
2003-07-02 22:44:09 +00:00
|
|
|
|
2004-08-17 19:51:11 +00:00
|
|
|
for (j = 0; xdg_data_dirs[j]; j++)
|
|
|
|
priv->search_path[i++] = g_build_filename (xdg_data_dirs[j], "icons", NULL);
|
2003-07-02 22:44:09 +00:00
|
|
|
|
2005-02-02 04:31:21 +00:00
|
|
|
for (j = 0; xdg_data_dirs[j]; j++)
|
|
|
|
priv->search_path[i++] = g_build_filename (xdg_data_dirs[j], "pixmaps", NULL);
|
2003-07-02 22:44:09 +00:00
|
|
|
|
|
|
|
priv->themes_valid = FALSE;
|
|
|
|
priv->themes = NULL;
|
|
|
|
priv->unthemed_icons = NULL;
|
2004-10-19 18:45:41 +00:00
|
|
|
|
2003-07-02 22:44:09 +00:00
|
|
|
priv->pixbuf_supports_svg = pixbuf_supports_svg ();
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
free_dir_mtime (IconThemeDirMtime *dir_mtime)
|
|
|
|
{
|
2005-04-06 03:34:38 +00:00
|
|
|
if (dir_mtime->cache)
|
|
|
|
_gtk_icon_cache_unref (dir_mtime->cache);
|
|
|
|
|
2003-07-02 22:44:09 +00:00
|
|
|
g_free (dir_mtime->dir);
|
2006-07-07 05:24:00 +00:00
|
|
|
g_slice_free (IconThemeDirMtime, dir_mtime);
|
2005-04-06 03:34:38 +00:00
|
|
|
|
2003-07-02 22:44:09 +00:00
|
|
|
}
|
|
|
|
|
2005-08-12 18:39:17 +00:00
|
|
|
static gboolean
|
2013-06-19 09:06:20 +00:00
|
|
|
theme_changed_idle (gpointer user_data)
|
2005-08-12 18:39:17 +00:00
|
|
|
{
|
|
|
|
GtkIconTheme *icon_theme;
|
|
|
|
GtkIconThemePrivate *priv;
|
|
|
|
|
|
|
|
icon_theme = GTK_ICON_THEME (user_data);
|
|
|
|
priv = icon_theme->priv;
|
|
|
|
|
2013-06-19 09:06:20 +00:00
|
|
|
g_signal_emit (icon_theme, signal_changed, 0);
|
|
|
|
|
2005-08-12 18:39:17 +00:00
|
|
|
if (priv->screen && priv->is_screen_singleton)
|
2010-12-03 13:08:33 +00:00
|
|
|
gtk_style_context_reset_widgets (priv->screen);
|
2005-08-12 18:39:17 +00:00
|
|
|
|
2013-06-19 09:06:20 +00:00
|
|
|
priv->theme_changed_idle = 0;
|
2005-08-12 18:39:17 +00:00
|
|
|
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2013-06-19 09:06:20 +00:00
|
|
|
static void
|
|
|
|
queue_theme_changed (GtkIconTheme *icon_theme)
|
|
|
|
{
|
|
|
|
GtkIconThemePrivate *priv = icon_theme->priv;
|
|
|
|
|
|
|
|
if (!priv->theme_changed_idle)
|
|
|
|
priv->theme_changed_idle =
|
|
|
|
gdk_threads_add_idle_full (GTK_PRIORITY_RESIZE - 2,
|
|
|
|
theme_changed_idle, icon_theme, NULL);
|
|
|
|
}
|
|
|
|
|
2003-07-02 22:44:09 +00:00
|
|
|
static void
|
|
|
|
do_theme_change (GtkIconTheme *icon_theme)
|
|
|
|
{
|
|
|
|
GtkIconThemePrivate *priv = icon_theme->priv;
|
2007-03-06 18:26:41 +00:00
|
|
|
|
2012-11-26 12:49:49 +00:00
|
|
|
g_hash_table_remove_all (priv->info_cache);
|
|
|
|
|
2007-03-06 18:26:41 +00:00
|
|
|
if (!priv->themes_valid)
|
|
|
|
return;
|
2013-06-19 09:06:20 +00:00
|
|
|
|
2004-10-19 18:45:41 +00:00
|
|
|
GTK_NOTE (ICONTHEME,
|
|
|
|
g_print ("change to icon theme \"%s\"\n", priv->current_theme));
|
2003-07-02 22:44:09 +00:00
|
|
|
blow_themes (icon_theme);
|
2005-08-12 18:39:17 +00:00
|
|
|
|
2013-06-19 09:06:20 +00:00
|
|
|
queue_theme_changed (icon_theme);
|
|
|
|
|
2003-07-02 22:44:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
blow_themes (GtkIconTheme *icon_theme)
|
|
|
|
{
|
|
|
|
GtkIconThemePrivate *priv = icon_theme->priv;
|
|
|
|
|
|
|
|
if (priv->themes_valid)
|
|
|
|
{
|
|
|
|
g_hash_table_destroy (priv->all_icons);
|
2012-01-02 03:20:59 +00:00
|
|
|
g_list_free_full (priv->themes, (GDestroyNotify) theme_destroy);
|
|
|
|
g_list_free_full (priv->dir_mtimes, (GDestroyNotify) free_dir_mtime);
|
2003-07-02 22:44:09 +00:00
|
|
|
g_hash_table_destroy (priv->unthemed_icons);
|
|
|
|
}
|
|
|
|
priv->themes = NULL;
|
|
|
|
priv->unthemed_icons = NULL;
|
|
|
|
priv->dir_mtimes = NULL;
|
|
|
|
priv->all_icons = NULL;
|
|
|
|
priv->themes_valid = FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gtk_icon_theme_finalize (GObject *object)
|
|
|
|
{
|
|
|
|
GtkIconTheme *icon_theme;
|
|
|
|
GtkIconThemePrivate *priv;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
icon_theme = GTK_ICON_THEME (object);
|
|
|
|
priv = icon_theme->priv;
|
|
|
|
|
2012-11-26 12:49:49 +00:00
|
|
|
g_hash_table_destroy (priv->info_cache);
|
|
|
|
g_assert (priv->info_cache_lru == NULL);
|
|
|
|
|
2013-06-19 09:06:20 +00:00
|
|
|
if (priv->theme_changed_idle)
|
2005-08-12 18:39:17 +00:00
|
|
|
{
|
2013-06-19 09:06:20 +00:00
|
|
|
g_source_remove (priv->theme_changed_idle);
|
|
|
|
priv->theme_changed_idle = 0;
|
2005-08-12 18:39:17 +00:00
|
|
|
}
|
|
|
|
|
2003-07-02 22:44:09 +00:00
|
|
|
unset_screen (icon_theme);
|
|
|
|
|
|
|
|
g_free (priv->current_theme);
|
|
|
|
priv->current_theme = NULL;
|
|
|
|
|
2006-06-07 04:16:52 +00:00
|
|
|
for (i = 0; i < priv->search_path_len; i++)
|
2003-07-02 22:44:09 +00:00
|
|
|
g_free (priv->search_path[i]);
|
|
|
|
|
|
|
|
g_free (priv->search_path);
|
|
|
|
priv->search_path = NULL;
|
|
|
|
|
|
|
|
blow_themes (icon_theme);
|
2004-02-22 02:06:49 +00:00
|
|
|
|
2006-05-02 23:56:43 +00:00
|
|
|
G_OBJECT_CLASS (gtk_icon_theme_parent_class)->finalize (object);
|
2003-07-02 22:44:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* gtk_icon_theme_set_search_path:
|
|
|
|
* @icon_theme: a #GtkIconTheme
|
2011-01-18 09:10:30 +00:00
|
|
|
* @path: (array length=n_elements) (element-type filename): array of
|
|
|
|
* directories that are searched for icon themes
|
2003-07-02 22:44:09 +00:00
|
|
|
* @n_elements: number of elements in @path.
|
|
|
|
*
|
|
|
|
* Sets the search path for the icon theme object. When looking
|
|
|
|
* for an icon theme, GTK+ will search for a subdirectory of
|
|
|
|
* one or more of the directories in @path with the same name
|
|
|
|
* as the icon theme. (Themes from multiple of the path elements
|
|
|
|
* are combined to allow themes to be extended by adding icons
|
|
|
|
* in the user's home directory.)
|
|
|
|
*
|
|
|
|
* In addition if an icon found isn't found either in the current
|
|
|
|
* icon theme or the default icon theme, and an image file with
|
|
|
|
* the right name is found directly in one of the elements of
|
|
|
|
* @path, then that image will be used for the icon name.
|
|
|
|
* (This is legacy feature, and new icons should be put
|
2013-10-16 01:19:17 +00:00
|
|
|
* into the default icon theme, which is called hicolor,
|
2004-01-20 16:32:54 +00:00
|
|
|
* rather than directly on the icon path.)
|
2003-11-08 00:51:10 +00:00
|
|
|
*
|
|
|
|
* Since: 2.4
|
2003-07-02 22:44:09 +00:00
|
|
|
**/
|
|
|
|
void
|
|
|
|
gtk_icon_theme_set_search_path (GtkIconTheme *icon_theme,
|
|
|
|
const gchar *path[],
|
|
|
|
gint n_elements)
|
|
|
|
{
|
|
|
|
GtkIconThemePrivate *priv;
|
|
|
|
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]);
|
|
|
|
|
|
|
|
g_free (priv->search_path);
|
|
|
|
|
|
|
|
priv->search_path = g_new (gchar *, n_elements);
|
|
|
|
priv->search_path_len = n_elements;
|
2006-06-07 04:16:52 +00:00
|
|
|
|
2003-07-02 22:44:09 +00:00
|
|
|
for (i = 0; i < priv->search_path_len; i++)
|
|
|
|
priv->search_path[i] = g_strdup (path[i]);
|
|
|
|
|
|
|
|
do_theme_change (icon_theme);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* gtk_icon_theme_get_search_path:
|
|
|
|
* @icon_theme: a #GtkIconTheme
|
2011-01-18 05:42:31 +00:00
|
|
|
* @path: (allow-none) (array length=n_elements) (element-type filename) (out):
|
2011-02-09 04:14:46 +00:00
|
|
|
* location to store a list of icon theme path directories or %NULL.
|
|
|
|
* The stored value should be freed with g_strfreev().
|
|
|
|
* @n_elements: location to store number of elements in @path, or %NULL
|
|
|
|
*
|
2003-07-02 22:44:09 +00:00
|
|
|
* Gets the current search path. See gtk_icon_theme_set_search_path().
|
2003-11-08 00:51:10 +00:00
|
|
|
*
|
|
|
|
* Since: 2.4
|
2011-02-09 04:14:46 +00:00
|
|
|
*/
|
2003-07-02 22:44:09 +00:00
|
|
|
void
|
2011-02-09 04:14:46 +00:00
|
|
|
gtk_icon_theme_get_search_path (GtkIconTheme *icon_theme,
|
|
|
|
gchar **path[],
|
|
|
|
gint *n_elements)
|
2003-07-02 22:44:09 +00:00
|
|
|
{
|
|
|
|
GtkIconThemePrivate *priv;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
g_return_if_fail (GTK_IS_ICON_THEME (icon_theme));
|
|
|
|
|
|
|
|
priv = icon_theme->priv;
|
|
|
|
|
|
|
|
if (n_elements)
|
|
|
|
*n_elements = priv->search_path_len;
|
|
|
|
|
|
|
|
if (path)
|
|
|
|
{
|
|
|
|
*path = g_new (gchar *, priv->search_path_len + 1);
|
|
|
|
for (i = 0; i < priv->search_path_len; i++)
|
2004-02-12 23:06:30 +00:00
|
|
|
(*path)[i] = g_strdup (priv->search_path[i]);
|
2003-07-02 22:44:09 +00:00
|
|
|
(*path)[i] = NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* gtk_icon_theme_append_search_path:
|
|
|
|
* @icon_theme: a #GtkIconTheme
|
2011-01-18 05:42:31 +00:00
|
|
|
* @path: (type filename): directory name to append to the icon path
|
2003-07-02 22:44:09 +00:00
|
|
|
*
|
2004-11-10 02:03:36 +00:00
|
|
|
* Appends a directory to the search path.
|
|
|
|
* See gtk_icon_theme_set_search_path().
|
2003-11-08 00:51:10 +00:00
|
|
|
*
|
|
|
|
* Since: 2.4
|
2003-07-02 22:44:09 +00:00
|
|
|
**/
|
|
|
|
void
|
|
|
|
gtk_icon_theme_append_search_path (GtkIconTheme *icon_theme,
|
|
|
|
const gchar *path)
|
|
|
|
{
|
|
|
|
GtkIconThemePrivate *priv;
|
|
|
|
|
|
|
|
g_return_if_fail (GTK_IS_ICON_THEME (icon_theme));
|
|
|
|
g_return_if_fail (path != NULL);
|
|
|
|
|
|
|
|
priv = icon_theme->priv;
|
|
|
|
|
|
|
|
priv->search_path_len++;
|
2006-06-07 04:16:52 +00:00
|
|
|
|
2003-07-02 22:44:09 +00:00
|
|
|
priv->search_path = g_renew (gchar *, priv->search_path, priv->search_path_len);
|
|
|
|
priv->search_path[priv->search_path_len-1] = g_strdup (path);
|
|
|
|
|
|
|
|
do_theme_change (icon_theme);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* gtk_icon_theme_prepend_search_path:
|
|
|
|
* @icon_theme: a #GtkIconTheme
|
2011-01-18 05:42:31 +00:00
|
|
|
* @path: (type filename): directory name to prepend to the icon path
|
2003-07-02 22:44:09 +00:00
|
|
|
*
|
2004-11-10 02:03:36 +00:00
|
|
|
* Prepends a directory to the search path.
|
|
|
|
* See gtk_icon_theme_set_search_path().
|
2003-11-08 00:51:10 +00:00
|
|
|
*
|
|
|
|
* Since: 2.4
|
2003-07-02 22:44:09 +00:00
|
|
|
**/
|
|
|
|
void
|
|
|
|
gtk_icon_theme_prepend_search_path (GtkIconTheme *icon_theme,
|
|
|
|
const gchar *path)
|
|
|
|
{
|
|
|
|
GtkIconThemePrivate *priv;
|
|
|
|
int 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);
|
|
|
|
|
2004-02-11 16:28:22 +00:00
|
|
|
for (i = priv->search_path_len - 1; i > 0; i--)
|
|
|
|
priv->search_path[i] = priv->search_path[i - 1];
|
2003-07-02 22:44:09 +00:00
|
|
|
|
|
|
|
priv->search_path[0] = g_strdup (path);
|
|
|
|
|
|
|
|
do_theme_change (icon_theme);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* gtk_icon_theme_set_custom_theme:
|
|
|
|
* @icon_theme: a #GtkIconTheme
|
2011-01-18 08:25:47 +00:00
|
|
|
* @theme_name: (allow-none): name of icon theme to use instead of
|
|
|
|
* configured theme, or %NULL to unset a previously set custom theme
|
2003-07-02 22:44:09 +00:00
|
|
|
*
|
|
|
|
* 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()
|
2005-03-12 03:38:31 +00:00
|
|
|
* and gtk_icon_theme_get_for_screen().
|
2003-11-08 00:51:10 +00:00
|
|
|
*
|
|
|
|
* Since: 2.4
|
2003-07-02 22:44:09 +00:00
|
|
|
**/
|
|
|
|
void
|
|
|
|
gtk_icon_theme_set_custom_theme (GtkIconTheme *icon_theme,
|
|
|
|
const gchar *theme_name)
|
|
|
|
{
|
|
|
|
GtkIconThemePrivate *priv;
|
|
|
|
|
|
|
|
g_return_if_fail (GTK_IS_ICON_THEME (icon_theme));
|
|
|
|
|
|
|
|
priv = icon_theme->priv;
|
|
|
|
|
|
|
|
g_return_if_fail (!priv->is_screen_singleton);
|
|
|
|
|
|
|
|
if (theme_name != NULL)
|
|
|
|
{
|
|
|
|
priv->custom_theme = TRUE;
|
2007-03-06 18:26:41 +00:00
|
|
|
if (!priv->current_theme || strcmp (theme_name, priv->current_theme) != 0)
|
2003-07-02 22:44:09 +00:00
|
|
|
{
|
|
|
|
g_free (priv->current_theme);
|
|
|
|
priv->current_theme = g_strdup (theme_name);
|
|
|
|
|
|
|
|
do_theme_change (icon_theme);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2007-03-06 18:26:41 +00:00
|
|
|
if (priv->custom_theme)
|
|
|
|
{
|
|
|
|
priv->custom_theme = FALSE;
|
2003-07-02 22:44:09 +00:00
|
|
|
|
2007-03-06 18:26:41 +00:00
|
|
|
update_current_theme (icon_theme);
|
|
|
|
}
|
2003-07-02 22:44:09 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
insert_theme (GtkIconTheme *icon_theme, const char *theme_name)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
GList *l;
|
|
|
|
char **dirs;
|
2013-08-19 13:42:30 +00:00
|
|
|
char **scaled_dirs;
|
2003-07-02 22:44:09 +00:00
|
|
|
char **themes;
|
|
|
|
GtkIconThemePrivate *priv;
|
2006-10-08 05:07:55 +00:00
|
|
|
IconTheme *theme = NULL;
|
2003-07-02 22:44:09 +00:00
|
|
|
char *path;
|
2004-10-24 05:48:16 +00:00
|
|
|
GKeyFile *theme_file;
|
|
|
|
GError *error = NULL;
|
2003-07-02 22:44:09 +00:00
|
|
|
IconThemeDirMtime *dir_mtime;
|
2011-10-03 15:25:33 +00:00
|
|
|
GStatBuf stat_buf;
|
2003-07-02 22:44:09 +00:00
|
|
|
|
|
|
|
priv = icon_theme->priv;
|
2004-10-19 18:45:41 +00:00
|
|
|
|
2003-07-02 22:44:09 +00:00
|
|
|
for (l = priv->themes; l != NULL; l = l->next)
|
|
|
|
{
|
|
|
|
theme = l->data;
|
|
|
|
if (strcmp (theme->name, theme_name) == 0)
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (i = 0; i < priv->search_path_len; i++)
|
|
|
|
{
|
|
|
|
path = g_build_filename (priv->search_path[i],
|
|
|
|
theme_name,
|
|
|
|
NULL);
|
2006-07-07 05:24:00 +00:00
|
|
|
dir_mtime = g_slice_new (IconThemeDirMtime);
|
2005-04-06 03:34:38 +00:00
|
|
|
dir_mtime->cache = NULL;
|
2003-07-02 22:44:09 +00:00
|
|
|
dir_mtime->dir = path;
|
2004-12-12 21:09:13 +00:00
|
|
|
if (g_stat (path, &stat_buf) == 0 && S_ISDIR (stat_buf.st_mode))
|
2003-07-02 22:44:09 +00:00
|
|
|
dir_mtime->mtime = stat_buf.st_mtime;
|
|
|
|
else
|
|
|
|
dir_mtime->mtime = 0;
|
|
|
|
|
|
|
|
priv->dir_mtimes = g_list_prepend (priv->dir_mtimes, dir_mtime);
|
|
|
|
}
|
2004-11-02 02:07:30 +00:00
|
|
|
priv->dir_mtimes = g_list_reverse (priv->dir_mtimes);
|
2003-07-02 22:44:09 +00:00
|
|
|
|
|
|
|
theme_file = NULL;
|
2004-10-24 05:48:16 +00:00
|
|
|
for (i = 0; i < priv->search_path_len && !theme_file; i++)
|
2003-07-02 22:44:09 +00:00
|
|
|
{
|
|
|
|
path = g_build_filename (priv->search_path[i],
|
|
|
|
theme_name,
|
|
|
|
"index.theme",
|
|
|
|
NULL);
|
2004-10-24 05:48:16 +00:00
|
|
|
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;
|
|
|
|
}
|
2003-07-02 22:44:09 +00:00
|
|
|
}
|
|
|
|
g_free (path);
|
|
|
|
}
|
|
|
|
|
2005-11-12 06:59:49 +00:00
|
|
|
if (theme_file || strcmp (theme_name, DEFAULT_THEME_NAME) == 0)
|
|
|
|
{
|
|
|
|
theme = g_new0 (IconTheme, 1);
|
|
|
|
theme->name = g_strdup (theme_name);
|
|
|
|
priv->themes = g_list_prepend (priv->themes, theme);
|
|
|
|
}
|
|
|
|
|
2003-07-02 22:44:09 +00:00
|
|
|
if (theme_file == NULL)
|
|
|
|
return;
|
2005-11-12 06:59:49 +00:00
|
|
|
|
2004-10-24 05:48:16 +00:00
|
|
|
theme->display_name =
|
|
|
|
g_key_file_get_locale_string (theme_file, "Icon Theme", "Name", NULL, NULL);
|
|
|
|
if (!theme->display_name)
|
2005-11-12 06:59:49 +00:00
|
|
|
g_warning ("Theme file for %s has no name\n", theme_name);
|
2003-07-02 22:44:09 +00:00
|
|
|
|
2004-10-24 05:48:16 +00:00
|
|
|
dirs = g_key_file_get_string_list (theme_file, "Icon Theme", "Directories", NULL, NULL);
|
|
|
|
if (!dirs)
|
2006-04-12 04:22:51 +00:00
|
|
|
{
|
|
|
|
g_warning ("Theme file for %s has no directories\n", theme_name);
|
2006-12-02 19:48:22 +00:00
|
|
|
priv->themes = g_list_remove (priv->themes, theme);
|
|
|
|
g_free (theme->name);
|
2006-04-12 04:22:51 +00:00
|
|
|
g_free (theme->display_name);
|
|
|
|
g_free (theme);
|
|
|
|
g_key_file_free (theme_file);
|
|
|
|
return;
|
|
|
|
}
|
2013-08-19 13:42:30 +00:00
|
|
|
|
|
|
|
scaled_dirs = g_key_file_get_string_list (theme_file, "Icon Theme", "ScaledDirectories", NULL, NULL);
|
|
|
|
|
2004-10-24 05:48:16 +00:00
|
|
|
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);
|
2003-07-02 22:44:09 +00:00
|
|
|
|
|
|
|
theme->dirs = NULL;
|
2006-04-12 04:22:51 +00:00
|
|
|
for (i = 0; dirs[i] != NULL; i++)
|
|
|
|
theme_subdir_load (icon_theme, theme, theme_file, dirs[i]);
|
|
|
|
|
2013-08-19 13:42:30 +00:00
|
|
|
if (scaled_dirs)
|
|
|
|
{
|
|
|
|
for (i = 0; scaled_dirs[i] != NULL; i++)
|
|
|
|
theme_subdir_load (icon_theme, theme, theme_file, scaled_dirs[i]);
|
|
|
|
}
|
2006-04-12 04:22:51 +00:00
|
|
|
g_strfreev (dirs);
|
2013-08-19 13:42:30 +00:00
|
|
|
g_strfreev (scaled_dirs);
|
2006-04-12 04:22:51 +00:00
|
|
|
|
2003-07-02 22:44:09 +00:00
|
|
|
theme->dirs = g_list_reverse (theme->dirs);
|
|
|
|
|
2004-10-24 05:48:16 +00:00
|
|
|
themes = g_key_file_get_string_list (theme_file,
|
2003-07-02 22:44:09 +00:00
|
|
|
"Icon Theme",
|
|
|
|
"Inherits",
|
2004-10-24 05:48:16 +00:00
|
|
|
NULL,
|
|
|
|
NULL);
|
|
|
|
if (themes)
|
2003-07-02 22:44:09 +00:00
|
|
|
{
|
|
|
|
for (i = 0; themes[i] != NULL; i++)
|
|
|
|
insert_theme (icon_theme, themes[i]);
|
|
|
|
|
|
|
|
g_strfreev (themes);
|
|
|
|
}
|
|
|
|
|
2004-10-24 05:48:16 +00:00
|
|
|
g_key_file_free (theme_file);
|
2003-07-02 22:44:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
free_unthemed_icon (UnthemedIcon *unthemed_icon)
|
|
|
|
{
|
2007-03-09 21:57:37 +00:00
|
|
|
g_free (unthemed_icon->svg_filename);
|
|
|
|
g_free (unthemed_icon->no_svg_filename);
|
2006-03-31 05:17:56 +00:00
|
|
|
g_slice_free (UnthemedIcon, unthemed_icon);
|
2003-07-02 22:44:09 +00:00
|
|
|
}
|
|
|
|
|
2006-04-18 13:58:30 +00:00
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
2003-07-02 22:44:09 +00:00
|
|
|
static void
|
|
|
|
load_themes (GtkIconTheme *icon_theme)
|
|
|
|
{
|
|
|
|
GtkIconThemePrivate *priv;
|
|
|
|
GDir *gdir;
|
|
|
|
int base;
|
2006-04-18 13:58:30 +00:00
|
|
|
char *dir;
|
2003-07-02 22:44:09 +00:00
|
|
|
const char *file;
|
|
|
|
UnthemedIcon *unthemed_icon;
|
|
|
|
IconSuffix old_suffix, new_suffix;
|
2003-07-20 15:50:14 +00:00
|
|
|
GTimeVal tv;
|
2005-07-13 14:07:10 +00:00
|
|
|
IconThemeDirMtime *dir_mtime;
|
2011-10-03 15:25:33 +00:00
|
|
|
GStatBuf stat_buf;
|
2003-07-02 22:44:09 +00:00
|
|
|
|
|
|
|
priv = icon_theme->priv;
|
|
|
|
|
|
|
|
priv->all_icons = g_hash_table_new (g_str_hash, g_str_equal);
|
|
|
|
|
2007-03-06 18:26:41 +00:00
|
|
|
if (priv->current_theme)
|
|
|
|
insert_theme (icon_theme, priv->current_theme);
|
2006-01-11 06:20:17 +00:00
|
|
|
|
2013-10-21 16:58:29 +00:00
|
|
|
/* Always look in the gnome and hicolor icon themes.
|
|
|
|
* Looking in hicolor is mandated by the spec, looking
|
|
|
|
* in gnome is a pragmatic solution to prevent missing
|
|
|
|
* icons in GTK+ applications when run under, e.g. KDE.
|
|
|
|
*/
|
|
|
|
insert_theme (icon_theme, "gnome");
|
2003-07-02 22:44:09 +00:00
|
|
|
insert_theme (icon_theme, DEFAULT_THEME_NAME);
|
|
|
|
priv->themes = g_list_reverse (priv->themes);
|
2004-10-19 18:45:41 +00:00
|
|
|
|
|
|
|
|
2003-07-02 22:44:09 +00:00
|
|
|
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];
|
2004-10-19 18:45:41 +00:00
|
|
|
|
2006-07-07 05:24:00 +00:00
|
|
|
dir_mtime = g_slice_new (IconThemeDirMtime);
|
2005-07-13 14:07:10 +00:00
|
|
|
priv->dir_mtimes = g_list_append (priv->dir_mtimes, dir_mtime);
|
2006-03-31 05:17:56 +00:00
|
|
|
|
2007-01-02 04:19:28 +00:00
|
|
|
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);
|
2005-07-13 14:07:10 +00:00
|
|
|
if (dir_mtime->cache != NULL)
|
|
|
|
continue;
|
2004-10-19 18:45:41 +00:00
|
|
|
|
2003-07-02 22:44:09 +00:00
|
|
|
gdir = g_dir_open (dir, 0, NULL);
|
|
|
|
if (gdir == NULL)
|
|
|
|
continue;
|
2006-03-31 05:17:56 +00:00
|
|
|
|
2003-07-02 22:44:09 +00:00
|
|
|
while ((file = g_dir_read_name (gdir)))
|
|
|
|
{
|
|
|
|
new_suffix = suffix_from_name (file);
|
2006-03-31 05:17:56 +00:00
|
|
|
|
2003-07-02 22:44:09 +00:00
|
|
|
if (new_suffix != ICON_SUFFIX_NONE)
|
|
|
|
{
|
2006-04-18 13:58:30 +00:00
|
|
|
char *abs_file;
|
|
|
|
char *base_name;
|
|
|
|
|
2003-07-02 22:44:09 +00:00
|
|
|
abs_file = g_build_filename (dir, file, NULL);
|
2006-04-18 13:58:30 +00:00
|
|
|
base_name = strip_suffix (file);
|
|
|
|
|
2003-07-02 22:44:09 +00:00
|
|
|
if ((unthemed_icon = g_hash_table_lookup (priv->unthemed_icons,
|
|
|
|
base_name)))
|
|
|
|
{
|
|
|
|
if (new_suffix == ICON_SUFFIX_SVG)
|
|
|
|
{
|
2004-04-19 22:01:57 +00:00
|
|
|
if (unthemed_icon->svg_filename)
|
2003-07-02 22:44:09 +00:00
|
|
|
g_free (abs_file);
|
|
|
|
else
|
|
|
|
unthemed_icon->svg_filename = abs_file;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (unthemed_icon->no_svg_filename)
|
|
|
|
{
|
|
|
|
old_suffix = suffix_from_name (unthemed_icon->no_svg_filename);
|
|
|
|
if (new_suffix > old_suffix)
|
|
|
|
{
|
|
|
|
g_free (unthemed_icon->no_svg_filename);
|
|
|
|
unthemed_icon->no_svg_filename = abs_file;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
g_free (abs_file);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
unthemed_icon->no_svg_filename = abs_file;
|
|
|
|
}
|
|
|
|
|
|
|
|
g_free (base_name);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2006-03-31 05:17:56 +00:00
|
|
|
unthemed_icon = g_slice_new0 (UnthemedIcon);
|
2003-07-02 22:44:09 +00:00
|
|
|
|
|
|
|
if (new_suffix == ICON_SUFFIX_SVG)
|
|
|
|
unthemed_icon->svg_filename = abs_file;
|
|
|
|
else
|
2004-04-19 22:01:57 +00:00
|
|
|
unthemed_icon->no_svg_filename = abs_file;
|
2004-10-19 18:45:41 +00:00
|
|
|
|
2011-05-05 14:13:13 +00:00
|
|
|
/* takes ownership of base_name */
|
|
|
|
g_hash_table_replace (priv->unthemed_icons,
|
|
|
|
base_name,
|
|
|
|
unthemed_icon);
|
2003-07-02 22:44:09 +00:00
|
|
|
g_hash_table_insert (priv->all_icons,
|
|
|
|
base_name, NULL);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
g_dir_close (gdir);
|
|
|
|
}
|
|
|
|
|
|
|
|
priv->themes_valid = TRUE;
|
|
|
|
|
2003-07-20 15:50:14 +00:00
|
|
|
g_get_current_time(&tv);
|
2003-07-02 22:44:09 +00:00
|
|
|
priv->last_stat_time = tv.tv_sec;
|
|
|
|
}
|
|
|
|
|
2006-07-20 18:07:21 +00:00
|
|
|
void
|
2005-11-12 06:59:49 +00:00
|
|
|
_gtk_icon_theme_ensure_builtin_cache (void)
|
|
|
|
{
|
|
|
|
static gboolean initialized = FALSE;
|
|
|
|
IconThemeDir *dir;
|
2006-06-07 04:16:52 +00:00
|
|
|
static IconThemeDir dirs[5] =
|
|
|
|
{
|
2013-05-10 16:06:00 +00:00
|
|
|
{ ICON_THEME_DIR_THRESHOLD, 0, 16, 16, 16, 2, 1, NULL, "16", -1, NULL, NULL, NULL },
|
|
|
|
{ ICON_THEME_DIR_THRESHOLD, 0, 20, 20, 20, 2, 1, NULL, "20", -1, NULL, NULL, NULL },
|
|
|
|
{ ICON_THEME_DIR_THRESHOLD, 0, 24, 24, 24, 2, 1, NULL, "24", -1, NULL, NULL, NULL },
|
|
|
|
{ ICON_THEME_DIR_THRESHOLD, 0, 32, 32, 32, 2, 1, NULL, "32", -1, NULL, NULL, NULL },
|
|
|
|
{ ICON_THEME_DIR_THRESHOLD, 0, 48, 48, 48, 2, 1, NULL, "48", -1, NULL, NULL, NULL }
|
2006-06-07 04:16:52 +00:00
|
|
|
};
|
2005-11-12 06:59:49 +00:00
|
|
|
gint i;
|
|
|
|
|
|
|
|
if (!initialized)
|
|
|
|
{
|
|
|
|
initialized = TRUE;
|
|
|
|
|
|
|
|
_builtin_cache = _gtk_icon_cache_new ((gchar *)builtin_icons);
|
|
|
|
|
2006-06-07 04:16:52 +00:00
|
|
|
for (i = 0; i < G_N_ELEMENTS (dirs); i++)
|
2005-11-12 06:59:49 +00:00
|
|
|
{
|
2006-06-07 04:16:52 +00:00
|
|
|
dir = &(dirs[i]);
|
2005-11-12 06:59:49 +00:00
|
|
|
dir->cache = _gtk_icon_cache_ref (_builtin_cache);
|
2007-12-03 17:44:27 +00:00
|
|
|
dir->subdir_index = _gtk_icon_cache_get_directory_index (dir->cache, dir->subdir);
|
2005-11-12 06:59:49 +00:00
|
|
|
|
|
|
|
builtin_dirs = g_list_append (builtin_dirs, dir);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2003-07-02 22:44:09 +00:00
|
|
|
static void
|
|
|
|
ensure_valid_themes (GtkIconTheme *icon_theme)
|
|
|
|
{
|
|
|
|
GtkIconThemePrivate *priv = icon_theme->priv;
|
2003-07-20 15:50:14 +00:00
|
|
|
GTimeVal tv;
|
2005-12-12 17:39:50 +00:00
|
|
|
gboolean was_valid = priv->themes_valid;
|
2005-08-22 20:12:15 +00:00
|
|
|
|
2007-03-15 18:40:16 +00:00
|
|
|
if (priv->loading_themes)
|
|
|
|
return;
|
|
|
|
priv->loading_themes = TRUE;
|
|
|
|
|
2005-11-12 06:59:49 +00:00
|
|
|
_gtk_icon_theme_ensure_builtin_cache ();
|
|
|
|
|
2003-07-02 22:44:09 +00:00
|
|
|
if (priv->themes_valid)
|
|
|
|
{
|
2004-10-20 17:23:02 +00:00
|
|
|
g_get_current_time (&tv);
|
2003-07-02 22:44:09 +00:00
|
|
|
|
2007-03-15 18:40:16 +00:00
|
|
|
if (ABS (tv.tv_sec - priv->last_stat_time) > 5 &&
|
|
|
|
rescan_themes (icon_theme))
|
2013-06-19 07:35:24 +00:00
|
|
|
{
|
|
|
|
g_hash_table_remove_all (priv->info_cache);
|
|
|
|
blow_themes (icon_theme);
|
|
|
|
}
|
2003-07-02 22:44:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (!priv->themes_valid)
|
2005-08-22 20:12:15 +00:00
|
|
|
{
|
|
|
|
load_themes (icon_theme);
|
|
|
|
|
2007-03-15 18:40:16 +00:00
|
|
|
if (was_valid)
|
2013-06-19 09:06:20 +00:00
|
|
|
queue_theme_changed (icon_theme);
|
2005-08-22 20:12:15 +00:00
|
|
|
}
|
2007-03-15 18:40:16 +00:00
|
|
|
|
|
|
|
priv->loading_themes = FALSE;
|
2003-07-02 22:44:09 +00:00
|
|
|
}
|
|
|
|
|
2012-11-26 12:49:49 +00:00
|
|
|
/* The LRU cache is a short list of IconInfos that are kept
|
|
|
|
alive even though their IconInfo would otherwise have
|
|
|
|
been freed, so that we can avoid reloading these
|
|
|
|
constantly.
|
|
|
|
We put infos on the lru list when nothing otherwise
|
|
|
|
references the info. So, when we get a cache hit
|
|
|
|
we remove it from the list, and when the proxy
|
|
|
|
pixmap is released we put it on the list.
|
|
|
|
*/
|
|
|
|
|
|
|
|
static void
|
|
|
|
ensure_lru_cache_space (GtkIconTheme *icon_theme)
|
|
|
|
{
|
|
|
|
GtkIconThemePrivate *priv = icon_theme->priv;
|
|
|
|
GList *l;
|
|
|
|
|
|
|
|
/* Remove last item if LRU full */
|
|
|
|
l = g_list_nth (priv->info_cache_lru, INFO_CACHE_LRU_SIZE - 1);
|
|
|
|
if (l)
|
|
|
|
{
|
|
|
|
GtkIconInfo *icon_info = l->data;
|
|
|
|
|
|
|
|
DEBUG_CACHE (("removing (due to out of space) %p (%s %d 0x%x) from LRU cache (cache size %d)\n",
|
|
|
|
icon_info,
|
|
|
|
g_strjoinv (",", icon_info->key.icon_names),
|
|
|
|
icon_info->key.size, icon_info->key.flags,
|
|
|
|
g_list_length (priv->info_cache_lru)));
|
|
|
|
|
|
|
|
priv->info_cache_lru = g_list_delete_link (priv->info_cache_lru, l);
|
2013-02-16 00:35:44 +00:00
|
|
|
g_object_unref (icon_info);
|
2012-11-26 12:49:49 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
add_to_lru_cache (GtkIconTheme *icon_theme,
|
|
|
|
GtkIconInfo *icon_info)
|
|
|
|
{
|
|
|
|
GtkIconThemePrivate *priv = icon_theme->priv;
|
|
|
|
|
|
|
|
DEBUG_CACHE (("adding %p (%s %d 0x%x) to LRU cache (cache size %d)\n",
|
|
|
|
icon_info,
|
|
|
|
g_strjoinv (",", icon_info->key.icon_names),
|
|
|
|
icon_info->key.size, icon_info->key.flags,
|
|
|
|
g_list_length (priv->info_cache_lru)));
|
|
|
|
|
|
|
|
g_assert (g_list_find (priv->info_cache_lru, icon_info) == NULL);
|
|
|
|
|
|
|
|
ensure_lru_cache_space (icon_theme);
|
|
|
|
/* prepend new info to LRU */
|
|
|
|
priv->info_cache_lru = g_list_prepend (priv->info_cache_lru,
|
2013-02-16 00:35:44 +00:00
|
|
|
g_object_ref (icon_info));
|
2012-11-26 12:49:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
ensure_in_lru_cache (GtkIconTheme *icon_theme,
|
|
|
|
GtkIconInfo *icon_info)
|
|
|
|
{
|
|
|
|
GtkIconThemePrivate *priv = icon_theme->priv;
|
|
|
|
GList *l;
|
|
|
|
|
|
|
|
l = g_list_find (priv->info_cache_lru, icon_info);
|
|
|
|
if (l)
|
|
|
|
{
|
|
|
|
/* Move to front of LRU if already in it */
|
|
|
|
priv->info_cache_lru = g_list_remove_link (priv->info_cache_lru, l);
|
|
|
|
priv->info_cache_lru = g_list_concat (l, priv->info_cache_lru);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
add_to_lru_cache (icon_theme, icon_info);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
remove_from_lru_cache (GtkIconTheme *icon_theme,
|
|
|
|
GtkIconInfo *icon_info)
|
|
|
|
{
|
|
|
|
GtkIconThemePrivate *priv = icon_theme->priv;
|
|
|
|
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",
|
|
|
|
icon_info,
|
|
|
|
g_strjoinv (",", icon_info->key.icon_names),
|
|
|
|
icon_info->key.size, icon_info->key.flags,
|
|
|
|
g_list_length (priv->info_cache_lru)));
|
|
|
|
|
|
|
|
priv->info_cache_lru = g_list_remove (priv->info_cache_lru, icon_info);
|
2013-02-16 00:35:44 +00:00
|
|
|
g_object_unref (icon_info);
|
2012-11-26 12:49:49 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-11-26 12:52:05 +00:00
|
|
|
static SymbolicPixbufCache *
|
|
|
|
symbolic_pixbuf_cache_new (GdkPixbuf *pixbuf,
|
|
|
|
const GdkRGBA *fg,
|
|
|
|
const GdkRGBA *success_color,
|
|
|
|
const GdkRGBA *warning_color,
|
|
|
|
const GdkRGBA *error_color,
|
|
|
|
SymbolicPixbufCache *next)
|
|
|
|
{
|
|
|
|
SymbolicPixbufCache *cache;
|
|
|
|
|
|
|
|
cache = g_new0 (SymbolicPixbufCache, 1);
|
|
|
|
cache->pixbuf = g_object_ref (pixbuf);
|
|
|
|
if (fg)
|
|
|
|
cache->fg = *fg;
|
|
|
|
if (success_color)
|
|
|
|
cache->success_color = *success_color;
|
|
|
|
if (warning_color)
|
|
|
|
cache->warning_color = *warning_color;
|
|
|
|
if (error_color)
|
|
|
|
cache->error_color = *error_color;
|
|
|
|
cache->next = next;
|
|
|
|
return cache;
|
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
|
|
|
rgba_matches (const GdkRGBA *a, const GdkRGBA *b)
|
|
|
|
{
|
|
|
|
GdkRGBA transparent = { 0 };
|
|
|
|
|
|
|
|
/* For matching we treat unset colors as transparent rather
|
|
|
|
than default, which works as well, because transparent
|
|
|
|
will never be used for real symbolic icon colors */
|
|
|
|
if (a == NULL)
|
|
|
|
a = &transparent;
|
|
|
|
|
|
|
|
return
|
|
|
|
fabs(a->red - b->red) < 0.0001 &&
|
|
|
|
fabs(a->green - b->green) < 0.0001 &&
|
|
|
|
fabs(a->blue - b->blue) < 0.0001 &&
|
|
|
|
fabs(a->alpha - b->alpha) < 0.0001;
|
|
|
|
}
|
|
|
|
|
|
|
|
static SymbolicPixbufCache *
|
|
|
|
symbolic_pixbuf_cache_matches (SymbolicPixbufCache *cache,
|
|
|
|
const GdkRGBA *fg,
|
|
|
|
const GdkRGBA *success_color,
|
|
|
|
const GdkRGBA *warning_color,
|
|
|
|
const GdkRGBA *error_color)
|
|
|
|
{
|
|
|
|
while (cache != NULL)
|
|
|
|
{
|
|
|
|
if (rgba_matches (fg, &cache->fg) &&
|
|
|
|
rgba_matches (success_color, &cache->success_color) &&
|
|
|
|
rgba_matches (warning_color, &cache->warning_color) &&
|
|
|
|
rgba_matches (error_color, &cache->error_color))
|
|
|
|
return cache;
|
|
|
|
|
|
|
|
cache = cache->next;
|
|
|
|
}
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
symbolic_pixbuf_cache_free (SymbolicPixbufCache *cache)
|
|
|
|
{
|
|
|
|
SymbolicPixbufCache *next;
|
|
|
|
|
|
|
|
while (cache != NULL)
|
|
|
|
{
|
2012-11-30 15:18:14 +00:00
|
|
|
next = cache->next;
|
2012-11-26 12:52:05 +00:00
|
|
|
g_object_unref (cache->pixbuf);
|
|
|
|
g_free (cache);
|
|
|
|
|
|
|
|
cache = next;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-05-18 20:19:12 +00:00
|
|
|
static GtkIconInfo *
|
|
|
|
choose_icon (GtkIconTheme *icon_theme,
|
|
|
|
const gchar *icon_names[],
|
|
|
|
gint size,
|
2013-05-10 16:06:00 +00:00
|
|
|
gint scale,
|
2007-05-18 20:19:12 +00:00
|
|
|
GtkIconLookupFlags flags)
|
2003-07-02 22:44:09 +00:00
|
|
|
{
|
|
|
|
GtkIconThemePrivate *priv;
|
|
|
|
GList *l;
|
|
|
|
GtkIconInfo *icon_info = NULL;
|
2013-09-23 10:42:30 +00:00
|
|
|
GtkIconInfo *unscaled_icon_info;
|
2007-06-03 20:44:10 +00:00
|
|
|
UnthemedIcon *unthemed_icon = NULL;
|
2013-09-23 10:42:30 +00:00
|
|
|
const char *icon_name = NULL;
|
2003-07-02 22:44:09 +00:00
|
|
|
gboolean allow_svg;
|
|
|
|
gboolean use_builtin;
|
2013-09-23 10:42:30 +00:00
|
|
|
IconTheme *theme = NULL;
|
2007-05-18 20:19:12 +00:00
|
|
|
gint i;
|
2012-11-26 12:49:49 +00:00
|
|
|
IconInfoKey key;
|
2004-10-20 17:23:02 +00:00
|
|
|
|
2003-07-02 22:44:09 +00:00
|
|
|
priv = icon_theme->priv;
|
|
|
|
|
2012-11-26 12:49:49 +00:00
|
|
|
ensure_valid_themes (icon_theme);
|
|
|
|
|
|
|
|
key.icon_names = (char **)icon_names;
|
|
|
|
key.size = size;
|
2013-05-10 16:06:00 +00:00
|
|
|
key.scale = scale;
|
2012-11-26 12:49:49 +00:00
|
|
|
key.flags = flags;
|
|
|
|
|
|
|
|
icon_info = g_hash_table_lookup (priv->info_cache, &key);
|
|
|
|
if (icon_info != NULL)
|
|
|
|
{
|
|
|
|
DEBUG_CACHE (("cache hit %p (%s %d 0x%x) (cache size %d)\n",
|
|
|
|
icon_info,
|
|
|
|
g_strjoinv (",", icon_info->key.icon_names),
|
|
|
|
icon_info->key.size, icon_info->key.flags,
|
|
|
|
g_hash_table_size (priv->info_cache)));
|
|
|
|
|
2013-02-16 00:35:44 +00:00
|
|
|
icon_info = g_object_ref (icon_info);
|
2012-11-26 12:49:49 +00:00
|
|
|
remove_from_lru_cache (icon_theme, icon_info);
|
|
|
|
|
|
|
|
return icon_info;
|
|
|
|
}
|
|
|
|
|
2003-07-02 22:44:09 +00:00
|
|
|
if (flags & GTK_ICON_LOOKUP_NO_SVG)
|
|
|
|
allow_svg = FALSE;
|
|
|
|
else if (flags & GTK_ICON_LOOKUP_FORCE_SVG)
|
|
|
|
allow_svg = TRUE;
|
|
|
|
else
|
|
|
|
allow_svg = priv->pixbuf_supports_svg;
|
|
|
|
|
2007-04-19 04:14:39 +00:00
|
|
|
use_builtin = flags & GTK_ICON_LOOKUP_USE_BUILTIN;
|
2003-07-02 22:44:09 +00:00
|
|
|
|
2012-04-25 01:47:33 +00:00
|
|
|
/* for symbolic icons, do a search in all registered themes first;
|
|
|
|
* a theme that inherits them from a parent theme might provide
|
|
|
|
* an alternative highcolor version, but still expect the symbolic icon
|
|
|
|
* to show up instead.
|
|
|
|
*/
|
|
|
|
if (icon_names[0] &&
|
|
|
|
g_str_has_suffix (icon_names[0], "-symbolic"))
|
|
|
|
{
|
|
|
|
for (l = priv->themes; l; l = l->next)
|
|
|
|
{
|
2013-09-23 10:42:30 +00:00
|
|
|
theme = l->data;
|
|
|
|
icon_name = icon_names[0];
|
|
|
|
icon_info = theme_lookup_icon (theme, icon_name, size, scale, allow_svg, use_builtin);
|
2012-04-25 01:47:33 +00:00
|
|
|
if (icon_info)
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2005-11-12 06:59:49 +00:00
|
|
|
for (l = priv->themes; l; l = l->next)
|
2003-07-02 22:44:09 +00:00
|
|
|
{
|
2013-09-23 10:42:30 +00:00
|
|
|
theme = l->data;
|
|
|
|
|
2007-05-18 20:19:12 +00:00
|
|
|
for (i = 0; icon_names[i]; i++)
|
2007-04-19 04:14:39 +00:00
|
|
|
{
|
2013-09-23 10:42:30 +00:00
|
|
|
icon_name = icon_names[i];
|
|
|
|
icon_info = theme_lookup_icon (theme, icon_name, size, scale, allow_svg, use_builtin);
|
2007-05-18 20:19:12 +00:00
|
|
|
if (icon_info)
|
|
|
|
goto out;
|
2007-04-19 04:14:39 +00:00
|
|
|
}
|
2007-05-18 20:19:12 +00:00
|
|
|
}
|
2007-04-19 04:14:39 +00:00
|
|
|
|
2013-09-23 10:42:30 +00:00
|
|
|
theme = NULL;
|
|
|
|
|
2007-05-18 20:19:12 +00:00
|
|
|
for (i = 0; icon_names[i]; i++)
|
|
|
|
{
|
|
|
|
unthemed_icon = g_hash_table_lookup (priv->unthemed_icons, icon_names[i]);
|
|
|
|
if (unthemed_icon)
|
|
|
|
break;
|
2003-07-02 22:44:09 +00:00
|
|
|
}
|
2008-06-16 13:27:46 +00:00
|
|
|
#ifdef G_OS_WIN32
|
|
|
|
/* Still not found an icon, check if reference to a Win32 resource */
|
|
|
|
if (!unthemed_icon)
|
|
|
|
{
|
|
|
|
gchar **resources;
|
|
|
|
HICON hIcon = NULL;
|
|
|
|
|
|
|
|
resources = g_strsplit (icon_names[0], ",", 0);
|
|
|
|
if (resources[0])
|
|
|
|
{
|
|
|
|
wchar_t *wfile = g_utf8_to_utf16 (resources[0], -1, NULL, NULL, NULL);
|
|
|
|
ExtractIconExW (wfile, resources[1] ? atoi (resources[1]) : 0, &hIcon, NULL, 1);
|
|
|
|
g_free (wfile);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (hIcon)
|
|
|
|
{
|
2013-09-23 10:37:36 +00:00
|
|
|
icon_info = icon_info_new (ICON_THEME_DIR_UNTHEMED, size, 1);
|
2013-08-21 13:54:09 +00:00
|
|
|
icon_info->cache_pixbuf = gdk_win32_icon_to_pixbuf_libgtk_only (hIcon, NULL, NULL);
|
2008-06-16 13:27:46 +00:00
|
|
|
DestroyIcon (hIcon);
|
|
|
|
}
|
|
|
|
g_strfreev (resources);
|
|
|
|
}
|
|
|
|
#endif
|
2003-07-02 22:44:09 +00:00
|
|
|
|
|
|
|
if (unthemed_icon)
|
|
|
|
{
|
2013-09-23 10:37:36 +00:00
|
|
|
icon_info = icon_info_new (ICON_THEME_DIR_UNTHEMED, size, 1);
|
2003-07-02 22:44:09 +00:00
|
|
|
|
|
|
|
/* A SVG icon, when allowed, beats out a XPM icon, but not
|
|
|
|
* a PNG icon
|
|
|
|
*/
|
|
|
|
if (allow_svg &&
|
|
|
|
unthemed_icon->svg_filename &&
|
|
|
|
(!unthemed_icon->no_svg_filename ||
|
|
|
|
suffix_from_name (unthemed_icon->no_svg_filename) != ICON_SUFFIX_PNG))
|
|
|
|
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);
|
|
|
|
|
2012-10-28 19:01:30 +00:00
|
|
|
icon_info->icon_file = g_file_new_for_path (icon_info->filename);
|
2003-07-02 22:44:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
out:
|
2012-11-26 12:49:49 +00:00
|
|
|
if (icon_info)
|
2008-05-29 14:33:49 +00:00
|
|
|
{
|
|
|
|
icon_info->desired_size = size;
|
2013-05-10 16:06:00 +00:00
|
|
|
icon_info->desired_scale = scale;
|
2008-05-29 14:33:49 +00:00
|
|
|
icon_info->forced_size = (flags & GTK_ICON_LOOKUP_FORCE_SIZE) != 0;
|
2012-11-26 12:49:49 +00:00
|
|
|
|
2013-09-23 10:42:30 +00:00
|
|
|
/* In case we're not scaling the icon we want to reuse the exact same size
|
|
|
|
* as a scale==1 lookup would be, rather than not scaling at all and
|
|
|
|
* causing a different layout */
|
|
|
|
icon_info->unscaled_scale = 1.0;
|
|
|
|
if (scale != 1 && !icon_info->forced_size && theme != NULL)
|
|
|
|
{
|
|
|
|
unscaled_icon_info = theme_lookup_icon (theme, icon_name, size, 1, allow_svg, use_builtin);
|
|
|
|
if (unscaled_icon_info)
|
|
|
|
{
|
|
|
|
icon_info->unscaled_scale =
|
|
|
|
(gdouble) unscaled_icon_info->dir_size * scale / (icon_info->dir_size * icon_info->dir_scale);
|
|
|
|
g_object_unref (unscaled_icon_info);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-11-26 12:49:49 +00:00
|
|
|
icon_info->key.icon_names = g_strdupv ((char **)icon_names);
|
|
|
|
icon_info->key.size = size;
|
2013-05-10 16:06:00 +00:00
|
|
|
icon_info->key.scale = scale;
|
2012-11-26 12:49:49 +00:00
|
|
|
icon_info->key.flags = flags;
|
|
|
|
icon_info->in_cache = icon_theme;
|
|
|
|
DEBUG_CACHE (("adding %p (%s %d 0x%x) to cache (cache size %d)\n",
|
|
|
|
icon_info,
|
|
|
|
g_strjoinv (",", icon_info->key.icon_names),
|
|
|
|
icon_info->key.size, icon_info->key.flags,
|
|
|
|
g_hash_table_size (priv->info_cache)));
|
|
|
|
g_hash_table_insert (priv->info_cache, &icon_info->key, icon_info);
|
2008-05-29 14:33:49 +00:00
|
|
|
}
|
2004-01-20 16:32:54 +00:00
|
|
|
else
|
|
|
|
{
|
|
|
|
static gboolean check_for_default_theme = TRUE;
|
|
|
|
char *default_theme_path;
|
|
|
|
gboolean found = FALSE;
|
|
|
|
unsigned i;
|
|
|
|
|
|
|
|
if (check_for_default_theme)
|
|
|
|
{
|
|
|
|
check_for_default_theme = FALSE;
|
|
|
|
|
|
|
|
for (i = 0; !found && i < priv->search_path_len; i++)
|
|
|
|
{
|
|
|
|
default_theme_path = g_build_filename (priv->search_path[i],
|
|
|
|
DEFAULT_THEME_NAME,
|
|
|
|
"index.theme",
|
|
|
|
NULL);
|
|
|
|
found = g_file_test (default_theme_path, G_FILE_TEST_IS_REGULAR);
|
|
|
|
g_free (default_theme_path);
|
|
|
|
}
|
2008-06-16 13:27:46 +00:00
|
|
|
|
2004-01-20 16:32:54 +00:00
|
|
|
if (!found)
|
|
|
|
{
|
2011-04-29 14:32:56 +00:00
|
|
|
g_warning ("Could not find the icon '%s'. The '%s' theme\n"
|
|
|
|
"was not found either, perhaps you need to install it.\n"
|
|
|
|
"You can get a copy from:\n"
|
|
|
|
"\t%s",
|
2007-05-18 20:19:12 +00:00
|
|
|
icon_names[0], DEFAULT_THEME_NAME, "http://icon-theme.freedesktop.org/releases");
|
2004-01-20 16:32:54 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2003-07-02 22:44:09 +00:00
|
|
|
|
|
|
|
return icon_info;
|
|
|
|
}
|
|
|
|
|
2007-05-18 20:19:12 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* gtk_icon_theme_lookup_icon:
|
|
|
|
* @icon_theme: a #GtkIconTheme
|
|
|
|
* @icon_name: the name of the icon to lookup
|
|
|
|
* @size: desired icon size
|
|
|
|
* @flags: flags modifying the behavior of the icon lookup
|
|
|
|
*
|
2014-01-27 22:04:46 +00:00
|
|
|
* Looks up a named icon and returns a #GtkIconInfo containing
|
2007-05-18 20:19:12 +00:00
|
|
|
* information such as the filename of the icon. The icon
|
|
|
|
* can then be rendered into a pixbuf using
|
|
|
|
* gtk_icon_info_load_icon(). (gtk_icon_theme_load_icon()
|
|
|
|
* combines these two steps if all you need is the pixbuf.)
|
|
|
|
*
|
2013-02-15 10:07:51 +00:00
|
|
|
* Return value: (transfer full): a #GtkIconInfo object containing information
|
|
|
|
* about the icon, or %NULL if the icon wasn't found.
|
2007-05-18 20:19:12 +00:00
|
|
|
*
|
|
|
|
* Since: 2.4
|
|
|
|
*/
|
|
|
|
GtkIconInfo *
|
|
|
|
gtk_icon_theme_lookup_icon (GtkIconTheme *icon_theme,
|
|
|
|
const gchar *icon_name,
|
|
|
|
gint size,
|
|
|
|
GtkIconLookupFlags flags)
|
2013-05-10 16:06:00 +00:00
|
|
|
{
|
|
|
|
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_NOTE (ICONTHEME,
|
|
|
|
g_print ("gtk_icon_theme_lookup_icon %s\n", icon_name));
|
|
|
|
|
|
|
|
return gtk_icon_theme_lookup_icon_for_scale (icon_theme, icon_name,
|
|
|
|
size, 1, flags);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* gtk_icon_theme_lookup_icon_for_scale:
|
|
|
|
* @icon_theme: a #GtkIconTheme
|
|
|
|
* @icon_name: the name of the icon to lookup
|
|
|
|
* @size: desired icon size
|
|
|
|
* @scale: the desired scale
|
|
|
|
* @flags: flags modifying the behavior of the icon lookup
|
|
|
|
*
|
|
|
|
* Looks up a named icon for a particular window scale and returns a
|
2014-01-27 22:04:46 +00:00
|
|
|
* #GtkIconInfo containing information such as the filename of the
|
2013-05-10 16:06:00 +00:00
|
|
|
* icon. The icon can then be rendered into a pixbuf using
|
|
|
|
* gtk_icon_info_load_icon(). (gtk_icon_theme_load_icon() combines
|
|
|
|
* these two steps if all you need is the pixbuf.)
|
|
|
|
*
|
|
|
|
* Return value: (transfer full): a #GtkIconInfo object containing
|
|
|
|
* information about the icon, or %NULL if the icon wasn't found.
|
|
|
|
*
|
|
|
|
* Since: 3.10
|
|
|
|
*/
|
|
|
|
GtkIconInfo *
|
|
|
|
gtk_icon_theme_lookup_icon_for_scale (GtkIconTheme *icon_theme,
|
|
|
|
const gchar *icon_name,
|
|
|
|
gint size,
|
|
|
|
gint scale,
|
|
|
|
GtkIconLookupFlags flags)
|
2007-05-18 20:19:12 +00:00
|
|
|
{
|
|
|
|
GtkIconInfo *info;
|
|
|
|
|
|
|
|
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);
|
2013-05-10 16:06:00 +00:00
|
|
|
g_return_val_if_fail (scale >= 1, NULL);
|
2007-05-18 20:19:12 +00:00
|
|
|
|
|
|
|
GTK_NOTE (ICONTHEME,
|
|
|
|
g_print ("gtk_icon_theme_lookup_icon %s\n", icon_name));
|
|
|
|
|
|
|
|
if (flags & GTK_ICON_LOOKUP_GENERIC_FALLBACK)
|
|
|
|
{
|
2013-08-13 13:41:08 +00:00
|
|
|
gchar **names, **nonsymbolic_names;
|
2007-05-18 20:19:12 +00:00
|
|
|
gint dashes, i;
|
2013-08-13 13:41:08 +00:00
|
|
|
gchar *p, *nonsymbolic_icon_name;
|
|
|
|
gboolean is_symbolic;
|
|
|
|
|
|
|
|
is_symbolic = g_str_has_suffix (icon_name, "-symbolic");
|
|
|
|
if (is_symbolic)
|
|
|
|
nonsymbolic_icon_name = g_strndup (icon_name, strlen (icon_name) - 9);
|
|
|
|
else
|
|
|
|
nonsymbolic_icon_name = g_strdup (icon_name);
|
2007-05-18 20:19:12 +00:00
|
|
|
|
|
|
|
dashes = 0;
|
2013-08-13 13:41:08 +00:00
|
|
|
for (p = (gchar *) nonsymbolic_icon_name; *p; p++)
|
2007-05-18 20:19:12 +00:00
|
|
|
if (*p == '-')
|
|
|
|
dashes++;
|
|
|
|
|
2013-08-13 13:41:08 +00:00
|
|
|
nonsymbolic_names = g_new (gchar *, dashes + 2);
|
|
|
|
nonsymbolic_names[0] = nonsymbolic_icon_name;
|
|
|
|
|
2007-05-18 20:19:12 +00:00
|
|
|
for (i = 1; i <= dashes; i++)
|
|
|
|
{
|
2013-08-13 13:41:08 +00:00
|
|
|
nonsymbolic_names[i] = g_strdup (nonsymbolic_names[i - 1]);
|
|
|
|
p = strrchr (nonsymbolic_names[i], '-');
|
2007-05-18 20:19:12 +00:00
|
|
|
*p = '\0';
|
|
|
|
}
|
2013-08-13 13:41:08 +00:00
|
|
|
nonsymbolic_names[dashes + 1] = NULL;
|
|
|
|
|
|
|
|
if (is_symbolic)
|
|
|
|
{
|
2013-10-16 01:19:17 +00:00
|
|
|
names = g_new (gchar *, 2 * dashes + 3);
|
2013-08-13 13:41:08 +00:00
|
|
|
for (i = 0; nonsymbolic_names[i] != NULL; i++)
|
2013-10-16 01:19:17 +00:00
|
|
|
{
|
|
|
|
names[i] = g_strconcat (nonsymbolic_names[i], "-symbolic", NULL);
|
|
|
|
names[dashes + 1 + i] = nonsymbolic_names[i];
|
|
|
|
}
|
2013-08-13 13:41:08 +00:00
|
|
|
|
2013-10-16 01:19:17 +00:00
|
|
|
names[dashes + 1 + i] = NULL;
|
|
|
|
g_free (nonsymbolic_names);
|
2013-08-13 13:41:08 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
names = nonsymbolic_names;
|
|
|
|
}
|
|
|
|
|
2013-05-10 16:06:00 +00:00
|
|
|
info = choose_icon (icon_theme, (const gchar **) names, size, scale, flags);
|
2013-10-16 01:19:17 +00:00
|
|
|
|
2007-05-18 20:19:12 +00:00
|
|
|
g_strfreev (names);
|
|
|
|
}
|
2013-10-16 01:19:17 +00:00
|
|
|
else
|
2007-05-18 20:19:12 +00:00
|
|
|
{
|
2008-01-09 17:02:50 +00:00
|
|
|
const gchar *names[2];
|
2013-10-16 01:19:17 +00:00
|
|
|
|
2007-05-18 20:19:12 +00:00
|
|
|
names[0] = icon_name;
|
|
|
|
names[1] = NULL;
|
|
|
|
|
2013-05-10 16:06:00 +00:00
|
|
|
info = choose_icon (icon_theme, names, size, scale, flags);
|
2007-05-18 20:19:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return info;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* gtk_icon_theme_choose_icon:
|
|
|
|
* @icon_theme: a #GtkIconTheme
|
2011-01-18 09:10:30 +00:00
|
|
|
* @icon_names: (array zero-terminated=1): %NULL-terminated array of
|
|
|
|
* icon names to lookup
|
2007-05-18 20:19:12 +00:00
|
|
|
* @size: desired icon size
|
|
|
|
* @flags: flags modifying the behavior of the icon lookup
|
|
|
|
*
|
2014-01-27 22:04:46 +00:00
|
|
|
* Looks up a named icon and returns a #GtkIconInfo containing
|
2007-05-18 20:19:12 +00:00
|
|
|
* information such as the filename of the icon. The icon
|
|
|
|
* can then be rendered into a pixbuf using
|
|
|
|
* gtk_icon_info_load_icon(). (gtk_icon_theme_load_icon()
|
|
|
|
* combines these two steps if all you need is the pixbuf.)
|
|
|
|
*
|
|
|
|
* If @icon_names contains more than one name, this function
|
|
|
|
* tries them all in the given order before falling back to
|
|
|
|
* inherited icon themes.
|
|
|
|
*
|
2013-02-15 10:07:51 +00:00
|
|
|
* Return value: (transfer full): a #GtkIconInfo object containing information
|
|
|
|
* about the icon, or %NULL if the icon wasn't found.
|
2007-05-18 20:19:12 +00:00
|
|
|
*
|
|
|
|
* Since: 2.12
|
|
|
|
*/
|
|
|
|
GtkIconInfo *
|
|
|
|
gtk_icon_theme_choose_icon (GtkIconTheme *icon_theme,
|
|
|
|
const gchar *icon_names[],
|
|
|
|
gint size,
|
|
|
|
GtkIconLookupFlags flags)
|
|
|
|
{
|
|
|
|
g_return_val_if_fail (GTK_IS_ICON_THEME (icon_theme), NULL);
|
|
|
|
g_return_val_if_fail (icon_names != NULL, NULL);
|
|
|
|
g_return_val_if_fail ((flags & GTK_ICON_LOOKUP_NO_SVG) == 0 ||
|
|
|
|
(flags & GTK_ICON_LOOKUP_FORCE_SVG) == 0, NULL);
|
|
|
|
|
2013-05-10 16:06:00 +00:00
|
|
|
return choose_icon (icon_theme, icon_names, size, 1, flags);
|
2007-05-18 20:19:12 +00:00
|
|
|
}
|
|
|
|
|
2013-05-10 16:06:00 +00:00
|
|
|
/**
|
|
|
|
* gtk_icon_theme_choose_icon_for_scale:
|
|
|
|
* @icon_theme: a #GtkIconTheme
|
|
|
|
* @icon_names: (array zero-terminated=1): %NULL-terminated array of
|
|
|
|
* icon names to lookup
|
|
|
|
* @size: desired icon size
|
|
|
|
* @scale: desired scale
|
|
|
|
* @flags: flags modifying the behavior of the icon lookup
|
|
|
|
*
|
|
|
|
* Looks up a named icon for a particular window scale and returns a
|
2014-01-27 22:04:46 +00:00
|
|
|
* #GtkIconInfo containing information such as the filename of the
|
2013-05-10 16:06:00 +00:00
|
|
|
* icon. The icon can then be rendered into a pixbuf using
|
|
|
|
* gtk_icon_info_load_icon(). (gtk_icon_theme_load_icon() combines
|
|
|
|
* these two steps if all you need is the pixbuf.)
|
|
|
|
*
|
|
|
|
* If @icon_names contains more than one name, this function
|
|
|
|
* tries them all in the given order before falling back to
|
|
|
|
* inherited icon themes.
|
|
|
|
*
|
|
|
|
* Return value: (transfer full): a #GtkIconInfo object containing information
|
|
|
|
* about the icon, or %NULL if the icon wasn't found.
|
|
|
|
*
|
|
|
|
* Since: 3.10
|
|
|
|
*/
|
|
|
|
GtkIconInfo *
|
|
|
|
gtk_icon_theme_choose_icon_for_scale (GtkIconTheme *icon_theme,
|
|
|
|
const gchar *icon_names[],
|
|
|
|
gint size,
|
|
|
|
gint scale,
|
|
|
|
GtkIconLookupFlags flags)
|
|
|
|
{
|
|
|
|
g_return_val_if_fail (GTK_IS_ICON_THEME (icon_theme), NULL);
|
|
|
|
g_return_val_if_fail (icon_names != NULL, NULL);
|
|
|
|
g_return_val_if_fail ((flags & GTK_ICON_LOOKUP_NO_SVG) == 0 ||
|
|
|
|
(flags & GTK_ICON_LOOKUP_FORCE_SVG) == 0, NULL);
|
|
|
|
g_return_val_if_fail (scale >= 1, NULL);
|
|
|
|
|
|
|
|
return choose_icon (icon_theme, icon_names, size, scale, flags);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2003-07-02 22:44:09 +00:00
|
|
|
/* Error quark */
|
|
|
|
GQuark
|
|
|
|
gtk_icon_theme_error_quark (void)
|
|
|
|
{
|
2006-04-04 03:25:16 +00:00
|
|
|
return g_quark_from_static_string ("gtk-icon-theme-error-quark");
|
2003-07-02 22:44:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* gtk_icon_theme_load_icon:
|
|
|
|
* @icon_theme: a #GtkIconTheme
|
|
|
|
* @icon_name: the name of the icon to lookup
|
|
|
|
* @size: the desired icon size. The resulting icon may not be
|
2010-09-21 04:18:11 +00:00
|
|
|
* exactly this size; see gtk_icon_info_load_icon().
|
2003-07-02 22:44:09 +00:00
|
|
|
* @flags: flags modifying the behavior of the icon lookup
|
2010-09-21 04:18:11 +00:00
|
|
|
* @error: (allow-none): Location to store error information on failure,
|
|
|
|
* or %NULL.
|
|
|
|
*
|
2003-07-02 22:44:09 +00:00
|
|
|
* Looks up an icon in an icon theme, scales it to the given size
|
|
|
|
* 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().
|
2005-08-22 16:38:46 +00:00
|
|
|
*
|
|
|
|
* Note that you probably want to listen for icon theme changes and
|
2010-09-21 04:18:11 +00:00
|
|
|
* update the icon. This is usually done by connecting to the
|
2005-08-22 16:38:46 +00:00
|
|
|
* 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
|
2010-09-21 04:18:11 +00:00
|
|
|
* returned by this function. Otherwise GTK+ may need to keep the old
|
2005-08-22 16:38:46 +00:00
|
|
|
* icon theme loaded, which would be a waste of memory.
|
2010-09-21 04:18:11 +00:00
|
|
|
*
|
|
|
|
* Return value: (transfer full): the rendered icon; this may be a
|
|
|
|
* newly created icon or a new reference to an internal icon, so
|
|
|
|
* you must not modify the icon. Use g_object_unref() to release
|
|
|
|
* your reference to the icon. %NULL if the icon isn't found.
|
2003-11-08 00:51:10 +00:00
|
|
|
*
|
|
|
|
* Since: 2.4
|
2003-07-02 22:44:09 +00:00
|
|
|
**/
|
|
|
|
GdkPixbuf *
|
|
|
|
gtk_icon_theme_load_icon (GtkIconTheme *icon_theme,
|
|
|
|
const gchar *icon_name,
|
|
|
|
gint size,
|
|
|
|
GtkIconLookupFlags flags,
|
|
|
|
GError **error)
|
2013-05-10 16:06:00 +00:00
|
|
|
{
|
|
|
|
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);
|
|
|
|
g_return_val_if_fail (error == NULL || *error == NULL, NULL);
|
|
|
|
|
|
|
|
return gtk_icon_theme_load_icon_for_scale (icon_theme, icon_name,
|
|
|
|
size, 1, flags, error);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* gtk_icon_theme_load_icon_for_scale:
|
|
|
|
* @icon_theme: a #GtkIconTheme
|
|
|
|
* @icon_name: the name of the icon to lookup
|
|
|
|
* @size: the desired icon size. The resulting icon may not be
|
|
|
|
* exactly this size; see gtk_icon_info_load_icon().
|
|
|
|
* @scale: desired scale
|
|
|
|
* @flags: flags modifying the behavior of the icon lookup
|
|
|
|
* @error: (allow-none): Location to store error information on failure,
|
|
|
|
* or %NULL.
|
|
|
|
*
|
|
|
|
* Looks up an icon in an icon theme for a particular window scale,
|
|
|
|
* scales it to the given size 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: (transfer full): the rendered icon; this may be a
|
|
|
|
* newly created icon or a new reference to an internal icon, so
|
|
|
|
* you must not modify the icon. Use g_object_unref() to release
|
|
|
|
* your reference to the icon. %NULL if the icon isn't found.
|
|
|
|
*
|
|
|
|
* Since: 3.10
|
|
|
|
**/
|
|
|
|
GdkPixbuf *
|
|
|
|
gtk_icon_theme_load_icon_for_scale (GtkIconTheme *icon_theme,
|
|
|
|
const gchar *icon_name,
|
|
|
|
gint size,
|
|
|
|
gint scale,
|
|
|
|
GtkIconLookupFlags flags,
|
|
|
|
GError **error)
|
2003-07-02 22:44:09 +00:00
|
|
|
{
|
|
|
|
GtkIconInfo *icon_info;
|
|
|
|
GdkPixbuf *pixbuf = NULL;
|
|
|
|
|
|
|
|
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);
|
|
|
|
g_return_val_if_fail (error == NULL || *error == NULL, NULL);
|
2013-05-10 16:06:00 +00:00
|
|
|
g_return_val_if_fail (scale >= 1, NULL);
|
|
|
|
|
|
|
|
icon_info = gtk_icon_theme_lookup_icon_for_scale (icon_theme, icon_name, size, scale,
|
|
|
|
flags | GTK_ICON_LOOKUP_USE_BUILTIN);
|
2003-07-02 22:44:09 +00:00
|
|
|
if (!icon_info)
|
|
|
|
{
|
|
|
|
g_set_error (error, GTK_ICON_THEME_ERROR, GTK_ICON_THEME_NOT_FOUND,
|
|
|
|
_("Icon '%s' not present in theme"), icon_name);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
pixbuf = gtk_icon_info_load_icon (icon_info, error);
|
2013-02-16 00:35:44 +00:00
|
|
|
g_object_unref (icon_info);
|
2003-07-02 22:44:09 +00:00
|
|
|
|
|
|
|
return pixbuf;
|
|
|
|
}
|
|
|
|
|
2013-06-26 14:26:43 +00:00
|
|
|
/**
|
|
|
|
* gtk_icon_theme_load_surface:
|
|
|
|
* @icon_theme: a #GtkIconTheme
|
|
|
|
* @icon_name: the name of the icon to lookup
|
|
|
|
* @size: the desired icon size. The resulting icon may not be
|
|
|
|
* exactly this size; see gtk_icon_info_load_icon().
|
|
|
|
* @scale: desired scale
|
|
|
|
* @for_window: (allow-none): #GdkWindow to optimize drawing for, or %NULL
|
|
|
|
* @flags: flags modifying the behavior of the icon lookup
|
|
|
|
* @error: (allow-none): Location to store error information on failure,
|
|
|
|
* or %NULL.
|
|
|
|
*
|
|
|
|
* Looks up an icon in an icon theme for a particular window scale,
|
|
|
|
* scales it to the given size and renders it into a cairo surface. 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_surface().
|
|
|
|
*
|
|
|
|
* 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.
|
|
|
|
*
|
|
|
|
* Return value: (transfer full): the rendered icon; this may be a
|
|
|
|
* newly created icon or a new reference to an internal icon, so
|
|
|
|
* you must not modify the icon. Use cairo_surface_destroy() to release
|
|
|
|
* your reference to the icon. %NULL if the icon isn't found.
|
|
|
|
*
|
|
|
|
* Since: 3.10
|
|
|
|
**/
|
|
|
|
cairo_surface_t *
|
|
|
|
gtk_icon_theme_load_surface (GtkIconTheme *icon_theme,
|
|
|
|
const gchar *icon_name,
|
|
|
|
gint size,
|
|
|
|
gint scale,
|
|
|
|
GdkWindow *for_window,
|
|
|
|
GtkIconLookupFlags flags,
|
|
|
|
GError **error)
|
|
|
|
{
|
|
|
|
GtkIconInfo *icon_info;
|
|
|
|
cairo_surface_t *surface = NULL;
|
|
|
|
|
|
|
|
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);
|
|
|
|
g_return_val_if_fail (error == NULL || *error == NULL, NULL);
|
|
|
|
g_return_val_if_fail (scale >= 1, NULL);
|
|
|
|
|
|
|
|
icon_info = gtk_icon_theme_lookup_icon_for_scale (icon_theme, icon_name, size, scale,
|
|
|
|
flags | GTK_ICON_LOOKUP_USE_BUILTIN);
|
|
|
|
if (!icon_info)
|
|
|
|
{
|
|
|
|
g_set_error (error, GTK_ICON_THEME_ERROR, GTK_ICON_THEME_NOT_FOUND,
|
|
|
|
_("Icon '%s' not present in theme"), icon_name);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
surface = gtk_icon_info_load_surface (icon_info, for_window, error);
|
|
|
|
g_object_unref (icon_info);
|
|
|
|
|
|
|
|
return surface;
|
|
|
|
}
|
|
|
|
|
2003-07-02 22:44:09 +00:00
|
|
|
/**
|
|
|
|
* gtk_icon_theme_has_icon:
|
|
|
|
* @icon_theme: a #GtkIconTheme
|
|
|
|
* @icon_name: the name of an icon
|
|
|
|
*
|
|
|
|
* Checks whether an icon theme includes an icon
|
|
|
|
* for a particular name.
|
|
|
|
*
|
|
|
|
* Return value: %TRUE if @icon_theme includes an
|
|
|
|
* icon for @icon_name.
|
2003-11-08 00:51:10 +00:00
|
|
|
*
|
|
|
|
* Since: 2.4
|
2003-07-02 22:44:09 +00:00
|
|
|
**/
|
|
|
|
gboolean
|
|
|
|
gtk_icon_theme_has_icon (GtkIconTheme *icon_theme,
|
|
|
|
const char *icon_name)
|
|
|
|
{
|
|
|
|
GtkIconThemePrivate *priv;
|
2004-10-21 18:44:08 +00:00
|
|
|
GList *l;
|
2003-07-02 22:44:09 +00:00
|
|
|
|
|
|
|
g_return_val_if_fail (GTK_IS_ICON_THEME (icon_theme), FALSE);
|
2009-01-22 15:15:40 +00:00
|
|
|
g_return_val_if_fail (icon_name != NULL, FALSE);
|
|
|
|
|
2003-07-02 22:44:09 +00:00
|
|
|
priv = icon_theme->priv;
|
|
|
|
|
|
|
|
ensure_valid_themes (icon_theme);
|
|
|
|
|
2005-04-06 03:34:38 +00:00
|
|
|
for (l = priv->dir_mtimes; l; l = l->next)
|
2004-10-21 18:44:08 +00:00
|
|
|
{
|
2005-04-06 03:34:38 +00:00
|
|
|
IconThemeDirMtime *dir_mtime = l->data;
|
|
|
|
GtkIconCache *cache = dir_mtime->cache;
|
|
|
|
|
|
|
|
if (cache && _gtk_icon_cache_has_icon (cache, icon_name))
|
2004-10-21 18:44:08 +00:00
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2003-07-02 22:44:09 +00:00
|
|
|
if (g_hash_table_lookup_extended (priv->all_icons,
|
|
|
|
icon_name, NULL, NULL))
|
|
|
|
return TRUE;
|
2003-12-07 22:53:22 +00:00
|
|
|
|
2005-11-04 15:43:40 +00:00
|
|
|
if (_builtin_cache &&
|
|
|
|
_gtk_icon_cache_has_icon (_builtin_cache, icon_name))
|
|
|
|
return TRUE;
|
|
|
|
|
2003-12-07 22:53:22 +00:00
|
|
|
if (icon_theme_builtin_icons &&
|
|
|
|
g_hash_table_lookup_extended (icon_theme_builtin_icons,
|
2003-07-02 22:44:09 +00:00
|
|
|
icon_name, NULL, NULL))
|
|
|
|
return TRUE;
|
|
|
|
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2004-07-17 03:55:07 +00:00
|
|
|
static void
|
|
|
|
add_size (gpointer key,
|
|
|
|
gpointer value,
|
|
|
|
gpointer user_data)
|
|
|
|
{
|
|
|
|
gint **res_p = user_data;
|
|
|
|
|
|
|
|
**res_p = GPOINTER_TO_INT (key);
|
|
|
|
|
2004-08-03 18:51:26 +00:00
|
|
|
(*res_p)++;
|
2004-07-17 03:55:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 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.
|
|
|
|
*
|
2011-01-18 09:10:30 +00:00
|
|
|
* Return value: (array zero-terminated=1): 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.
|
2004-07-17 03:55:07 +00:00
|
|
|
*
|
|
|
|
* Since: 2.6
|
|
|
|
**/
|
|
|
|
gint *
|
|
|
|
gtk_icon_theme_get_icon_sizes (GtkIconTheme *icon_theme,
|
|
|
|
const char *icon_name)
|
|
|
|
{
|
2005-11-12 06:59:49 +00:00
|
|
|
GList *l, *d, *icons;
|
2004-07-17 03:55:07 +00:00
|
|
|
GHashTable *sizes;
|
2004-08-16 18:38:55 +00:00
|
|
|
gint *result, *r;
|
2005-11-12 06:59:49 +00:00
|
|
|
guint suffix;
|
2004-07-17 03:55:07 +00:00
|
|
|
GtkIconThemePrivate *priv;
|
|
|
|
|
2004-10-28 15:00:05 +00:00
|
|
|
g_return_val_if_fail (GTK_IS_ICON_THEME (icon_theme), NULL);
|
2004-07-17 03:55:07 +00:00
|
|
|
|
|
|
|
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;
|
2004-10-19 18:45:41 +00:00
|
|
|
|
2007-12-03 17:44:27 +00:00
|
|
|
if (dir->type != ICON_THEME_DIR_SCALABLE && g_hash_table_lookup_extended (sizes, GINT_TO_POINTER (dir->size), NULL, NULL))
|
|
|
|
continue;
|
|
|
|
|
2004-10-19 18:45:41 +00:00
|
|
|
suffix = theme_dir_get_icon_suffix (dir, icon_name, NULL);
|
2004-07-17 03:55:07 +00:00
|
|
|
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);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2005-11-12 06:59:49 +00:00
|
|
|
for (d = builtin_dirs; d; d = d->next)
|
|
|
|
{
|
|
|
|
IconThemeDir *dir = d->data;
|
|
|
|
|
2007-12-03 17:44:27 +00:00
|
|
|
if (dir->type != ICON_THEME_DIR_SCALABLE && g_hash_table_lookup_extended (sizes, GINT_TO_POINTER (dir->size), NULL, NULL))
|
|
|
|
continue;
|
|
|
|
|
2005-11-12 06:59:49 +00:00
|
|
|
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);
|
|
|
|
|
2005-11-14 18:49:41 +00:00
|
|
|
while (icons)
|
|
|
|
{
|
|
|
|
BuiltinIcon *icon = icons->data;
|
2005-11-12 06:59:49 +00:00
|
|
|
|
2005-11-14 18:49:41 +00:00
|
|
|
g_hash_table_insert (sizes, GINT_TO_POINTER (icon->size), NULL);
|
|
|
|
icons = icons->next;
|
|
|
|
}
|
2005-11-12 06:59:49 +00:00
|
|
|
}
|
|
|
|
|
2004-08-16 18:38:55 +00:00
|
|
|
r = result = g_new0 (gint, g_hash_table_size (sizes) + 1);
|
2004-07-17 03:55:07 +00:00
|
|
|
|
2004-08-16 18:38:55 +00:00
|
|
|
g_hash_table_foreach (sizes, add_size, &r);
|
2004-07-17 03:55:07 +00:00
|
|
|
g_hash_table_destroy (sizes);
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
2003-07-02 22:44:09 +00:00
|
|
|
|
|
|
|
static void
|
|
|
|
add_key_to_hash (gpointer key,
|
|
|
|
gpointer value,
|
|
|
|
gpointer user_data)
|
|
|
|
{
|
|
|
|
GHashTable *hash = user_data;
|
|
|
|
|
|
|
|
g_hash_table_insert (hash, key, NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
add_key_to_list (gpointer key,
|
|
|
|
gpointer value,
|
|
|
|
gpointer user_data)
|
|
|
|
{
|
|
|
|
GList **list = user_data;
|
|
|
|
|
|
|
|
*list = g_list_prepend (*list, g_strdup (key));
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* gtk_icon_theme_list_icons:
|
|
|
|
* @icon_theme: a #GtkIconTheme
|
2011-01-18 08:25:47 +00:00
|
|
|
* @context: (allow-none): a string identifying a particular type of
|
|
|
|
* icon, or %NULL to list all icons.
|
2003-07-02 22:44:09 +00:00
|
|
|
*
|
|
|
|
* 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,
|
2006-02-13 02:31:28 +00:00
|
|
|
* but will typically include such values as "Applications" and
|
|
|
|
* "MimeTypes".
|
2009-12-10 10:23:40 +00:00
|
|
|
*
|
2011-01-18 09:14:33 +00:00
|
|
|
* Return value: (element-type utf8) (transfer full): a #GList list
|
|
|
|
* holding the names of all the icons in the theme. You must first
|
|
|
|
* free each element in the list with g_free(), then free the list
|
|
|
|
* itself with g_list_free().
|
2003-11-08 00:51:10 +00:00
|
|
|
*
|
|
|
|
* Since: 2.4
|
2003-07-02 22:44:09 +00:00
|
|
|
**/
|
|
|
|
GList *
|
|
|
|
gtk_icon_theme_list_icons (GtkIconTheme *icon_theme,
|
|
|
|
const char *context)
|
|
|
|
{
|
|
|
|
GtkIconThemePrivate *priv;
|
|
|
|
GHashTable *icons;
|
|
|
|
GList *list, *l;
|
|
|
|
GQuark context_quark;
|
|
|
|
|
|
|
|
priv = icon_theme->priv;
|
|
|
|
|
|
|
|
ensure_valid_themes (icon_theme);
|
|
|
|
|
|
|
|
if (context)
|
|
|
|
{
|
|
|
|
context_quark = g_quark_try_string (context);
|
|
|
|
|
|
|
|
if (!context_quark)
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
context_quark = 0;
|
|
|
|
|
|
|
|
icons = g_hash_table_new (g_str_hash, g_str_equal);
|
|
|
|
|
|
|
|
l = priv->themes;
|
|
|
|
while (l != NULL)
|
|
|
|
{
|
|
|
|
theme_list_icons (l->data, icons, context_quark);
|
|
|
|
l = l->next;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (context_quark == 0)
|
|
|
|
g_hash_table_foreach (priv->unthemed_icons,
|
|
|
|
add_key_to_hash,
|
|
|
|
icons);
|
|
|
|
|
2004-10-28 15:00:05 +00:00
|
|
|
list = NULL;
|
2003-07-02 22:44:09 +00:00
|
|
|
|
|
|
|
g_hash_table_foreach (icons,
|
|
|
|
add_key_to_list,
|
|
|
|
&list);
|
|
|
|
|
|
|
|
g_hash_table_destroy (icons);
|
|
|
|
|
|
|
|
return list;
|
|
|
|
}
|
|
|
|
|
2007-03-21 19:31:01 +00:00
|
|
|
/**
|
|
|
|
* gtk_icon_theme_list_contexts:
|
|
|
|
* @icon_theme: a #GtkIconTheme
|
|
|
|
*
|
|
|
|
* Gets the list of contexts available within the current
|
|
|
|
* hierarchy of icon themes
|
|
|
|
*
|
2011-01-18 09:12:38 +00:00
|
|
|
* Return value: (element-type utf8) (transfer full): a #GList list
|
|
|
|
* holding the names of all the contexts in the theme. You must first
|
|
|
|
* free each element in the list with g_free(), then free the list
|
|
|
|
* itself with g_list_free().
|
2007-03-21 19:31:01 +00:00
|
|
|
*
|
|
|
|
* Since: 2.12
|
|
|
|
**/
|
|
|
|
GList *
|
|
|
|
gtk_icon_theme_list_contexts (GtkIconTheme *icon_theme)
|
|
|
|
{
|
|
|
|
GtkIconThemePrivate *priv;
|
|
|
|
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);
|
|
|
|
|
|
|
|
l = priv->themes;
|
|
|
|
while (l != NULL)
|
|
|
|
{
|
|
|
|
theme_list_contexts (l->data, contexts);
|
|
|
|
l = l->next;
|
|
|
|
}
|
|
|
|
|
|
|
|
list = NULL;
|
|
|
|
|
|
|
|
g_hash_table_foreach (contexts,
|
|
|
|
add_key_to_list,
|
|
|
|
&list);
|
|
|
|
|
|
|
|
g_hash_table_destroy (contexts);
|
|
|
|
|
|
|
|
return list;
|
|
|
|
}
|
|
|
|
|
2003-07-02 22:44:09 +00:00
|
|
|
/**
|
|
|
|
* gtk_icon_theme_get_example_icon_name:
|
|
|
|
* @icon_theme: a #GtkIconTheme
|
|
|
|
*
|
|
|
|
* Gets the name of an icon that is representative of the
|
|
|
|
* current theme (for instance, to use when presenting
|
|
|
|
* a list of themes to the user.)
|
|
|
|
*
|
|
|
|
* Return value: the name of an example icon or %NULL.
|
|
|
|
* Free with g_free().
|
2003-11-08 00:51:10 +00:00
|
|
|
*
|
|
|
|
* Since: 2.4
|
2003-07-02 22:44:09 +00:00
|
|
|
**/
|
|
|
|
char *
|
|
|
|
gtk_icon_theme_get_example_icon_name (GtkIconTheme *icon_theme)
|
|
|
|
{
|
|
|
|
GtkIconThemePrivate *priv;
|
|
|
|
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;
|
|
|
|
while (l != NULL)
|
|
|
|
{
|
|
|
|
theme = l->data;
|
|
|
|
if (theme->example)
|
|
|
|
return g_strdup (theme->example);
|
|
|
|
|
|
|
|
l = l->next;
|
|
|
|
}
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2007-03-15 18:40:16 +00:00
|
|
|
|
|
|
|
static gboolean
|
|
|
|
rescan_themes (GtkIconTheme *icon_theme)
|
2003-07-02 22:44:09 +00:00
|
|
|
{
|
|
|
|
GtkIconThemePrivate *priv;
|
|
|
|
IconThemeDirMtime *dir_mtime;
|
|
|
|
GList *d;
|
|
|
|
int stat_res;
|
2011-10-03 15:25:33 +00:00
|
|
|
GStatBuf stat_buf;
|
2003-07-20 15:50:14 +00:00
|
|
|
GTimeVal tv;
|
2003-07-02 22:44:09 +00:00
|
|
|
|
|
|
|
priv = icon_theme->priv;
|
2007-03-15 18:40:16 +00:00
|
|
|
|
2003-07-02 22:44:09 +00:00
|
|
|
for (d = priv->dir_mtimes; d != NULL; d = d->next)
|
|
|
|
{
|
|
|
|
dir_mtime = d->data;
|
|
|
|
|
2004-12-12 21:09:13 +00:00
|
|
|
stat_res = g_stat (dir_mtime->dir, &stat_buf);
|
2003-07-02 22:44:09 +00:00
|
|
|
|
|
|
|
/* dir mtime didn't change */
|
2007-03-15 18:40:16 +00:00
|
|
|
if (stat_res == 0 &&
|
2003-07-02 22:44:09 +00:00
|
|
|
S_ISDIR (stat_buf.st_mode) &&
|
|
|
|
dir_mtime->mtime == stat_buf.st_mtime)
|
|
|
|
continue;
|
|
|
|
/* didn't exist before, and still doesn't */
|
|
|
|
if (dir_mtime->mtime == 0 &&
|
|
|
|
(stat_res != 0 || !S_ISDIR (stat_buf.st_mode)))
|
|
|
|
continue;
|
2007-03-15 18:40:16 +00:00
|
|
|
|
2003-07-02 22:44:09 +00:00
|
|
|
return TRUE;
|
|
|
|
}
|
2007-03-15 18:40:16 +00:00
|
|
|
|
2003-07-20 15:50:14 +00:00
|
|
|
g_get_current_time (&tv);
|
2003-07-02 22:44:09 +00:00
|
|
|
priv->last_stat_time = tv.tv_sec;
|
|
|
|
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2007-03-15 18:40:16 +00:00
|
|
|
/**
|
|
|
|
* gtk_icon_theme_rescan_if_needed:
|
|
|
|
* @icon_theme: a #GtkIconTheme
|
|
|
|
*
|
|
|
|
* Checks to see if the icon theme has changed; if it has, any
|
|
|
|
* currently cached information is discarded and will be reloaded
|
|
|
|
* next time @icon_theme is accessed.
|
|
|
|
*
|
|
|
|
* Return value: %TRUE if the icon theme has changed and needed
|
|
|
|
* to be reloaded.
|
|
|
|
*
|
|
|
|
* Since: 2.4
|
|
|
|
**/
|
|
|
|
gboolean
|
|
|
|
gtk_icon_theme_rescan_if_needed (GtkIconTheme *icon_theme)
|
|
|
|
{
|
|
|
|
gboolean retval;
|
|
|
|
|
|
|
|
g_return_val_if_fail (GTK_IS_ICON_THEME (icon_theme), FALSE);
|
|
|
|
|
|
|
|
retval = rescan_themes (icon_theme);
|
|
|
|
if (retval)
|
|
|
|
do_theme_change (icon_theme);
|
|
|
|
|
|
|
|
return retval;
|
|
|
|
}
|
|
|
|
|
2003-07-02 22:44:09 +00:00
|
|
|
static void
|
|
|
|
theme_destroy (IconTheme *theme)
|
|
|
|
{
|
|
|
|
g_free (theme->display_name);
|
|
|
|
g_free (theme->comment);
|
|
|
|
g_free (theme->name);
|
|
|
|
g_free (theme->example);
|
|
|
|
|
2012-01-02 03:20:59 +00:00
|
|
|
g_list_free_full (theme->dirs, (GDestroyNotify) theme_dir_destroy);
|
2004-10-19 18:45:41 +00:00
|
|
|
|
2003-07-02 22:44:09 +00:00
|
|
|
g_free (theme);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
theme_dir_destroy (IconThemeDir *dir)
|
|
|
|
{
|
2004-10-19 18:45:41 +00:00
|
|
|
if (dir->cache)
|
|
|
|
_gtk_icon_cache_unref (dir->cache);
|
|
|
|
else
|
|
|
|
g_hash_table_destroy (dir->icons);
|
|
|
|
|
2003-07-02 22:44:09 +00:00
|
|
|
if (dir->icon_data)
|
|
|
|
g_hash_table_destroy (dir->icon_data);
|
|
|
|
g_free (dir->dir);
|
2004-10-19 18:45:41 +00:00
|
|
|
g_free (dir->subdir);
|
2003-07-02 22:44:09 +00:00
|
|
|
g_free (dir);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
2013-05-10 16:06:00 +00:00
|
|
|
theme_dir_size_difference (IconThemeDir *dir,
|
|
|
|
int size,
|
|
|
|
gint scale)
|
2003-07-02 22:44:09 +00:00
|
|
|
{
|
2013-05-10 16:06:00 +00:00
|
|
|
int scaled_size, scaled_dir_size;
|
2003-07-02 22:44:09 +00:00
|
|
|
int min, max;
|
2013-05-10 16:06:00 +00:00
|
|
|
|
|
|
|
scaled_size = size * scale;
|
|
|
|
scaled_dir_size = dir->size * dir->scale;
|
|
|
|
|
2003-07-02 22:44:09 +00:00
|
|
|
switch (dir->type)
|
|
|
|
{
|
|
|
|
case ICON_THEME_DIR_FIXED:
|
2013-05-10 16:06:00 +00:00
|
|
|
return abs (scaled_size - scaled_dir_size);
|
2003-07-02 22:44:09 +00:00
|
|
|
break;
|
|
|
|
case ICON_THEME_DIR_SCALABLE:
|
2013-05-10 16:06:00 +00:00
|
|
|
if (scaled_size < (dir->min_size * dir->scale))
|
|
|
|
return (dir->min_size * dir->scale) - scaled_size;
|
|
|
|
if (size > (dir->max_size * dir->scale))
|
|
|
|
return scaled_size - (dir->max_size * dir->scale);
|
2003-07-02 22:44:09 +00:00
|
|
|
return 0;
|
|
|
|
break;
|
|
|
|
case ICON_THEME_DIR_THRESHOLD:
|
2013-05-10 16:06:00 +00:00
|
|
|
min = (dir->size - dir->threshold) * dir->scale;
|
|
|
|
max = (dir->size + dir->threshold) * dir->scale;
|
|
|
|
if (scaled_size < min)
|
|
|
|
return min - scaled_size;
|
|
|
|
if (scaled_size > max)
|
|
|
|
return scaled_size - max;
|
2003-07-02 22:44:09 +00:00
|
|
|
return 0;
|
|
|
|
break;
|
|
|
|
case ICON_THEME_DIR_UNTHEMED:
|
|
|
|
g_assert_not_reached ();
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
g_assert_not_reached ();
|
|
|
|
return 1000;
|
|
|
|
}
|
|
|
|
|
|
|
|
static const char *
|
|
|
|
string_from_suffix (IconSuffix suffix)
|
|
|
|
{
|
|
|
|
switch (suffix)
|
|
|
|
{
|
|
|
|
case ICON_SUFFIX_XPM:
|
|
|
|
return ".xpm";
|
|
|
|
case ICON_SUFFIX_SVG:
|
|
|
|
return ".svg";
|
|
|
|
case ICON_SUFFIX_PNG:
|
|
|
|
return ".png";
|
|
|
|
default:
|
|
|
|
g_assert_not_reached();
|
|
|
|
}
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static IconSuffix
|
|
|
|
suffix_from_name (const char *name)
|
|
|
|
{
|
|
|
|
IconSuffix retval;
|
|
|
|
|
|
|
|
if (g_str_has_suffix (name, ".png"))
|
|
|
|
retval = ICON_SUFFIX_PNG;
|
|
|
|
else if (g_str_has_suffix (name, ".svg"))
|
|
|
|
retval = ICON_SUFFIX_SVG;
|
|
|
|
else if (g_str_has_suffix (name, ".xpm"))
|
|
|
|
retval = ICON_SUFFIX_XPM;
|
|
|
|
else
|
|
|
|
retval = ICON_SUFFIX_NONE;
|
|
|
|
|
|
|
|
return retval;
|
|
|
|
}
|
|
|
|
|
|
|
|
static IconSuffix
|
|
|
|
best_suffix (IconSuffix suffix,
|
|
|
|
gboolean allow_svg)
|
|
|
|
{
|
|
|
|
if ((suffix & ICON_SUFFIX_PNG) != 0)
|
|
|
|
return ICON_SUFFIX_PNG;
|
|
|
|
else if (allow_svg && ((suffix & ICON_SUFFIX_SVG) != 0))
|
|
|
|
return ICON_SUFFIX_SVG;
|
|
|
|
else if ((suffix & ICON_SUFFIX_XPM) != 0)
|
|
|
|
return ICON_SUFFIX_XPM;
|
|
|
|
else
|
|
|
|
return ICON_SUFFIX_NONE;
|
|
|
|
}
|
|
|
|
|
2004-10-19 18:45:41 +00:00
|
|
|
|
|
|
|
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,
|
2007-12-03 17:44:27 +00:00
|
|
|
dir->subdir_index);
|
2004-10-19 18:45:41 +00:00
|
|
|
|
|
|
|
if (has_icon_file)
|
2004-10-21 18:44:08 +00:00
|
|
|
*has_icon_file = suffix & HAS_ICON_FILE;
|
|
|
|
|
|
|
|
suffix = suffix & ~HAS_ICON_FILE;
|
2004-10-19 18:45:41 +00:00
|
|
|
}
|
|
|
|
else
|
2005-08-26 16:29:40 +00:00
|
|
|
suffix = GPOINTER_TO_UINT (g_hash_table_lookup (dir->icons, icon_name));
|
2004-10-19 18:45:41 +00:00
|
|
|
|
2005-08-15 19:36:32 +00:00
|
|
|
GTK_NOTE (ICONTHEME,
|
2006-10-08 05:07:55 +00:00
|
|
|
g_print ("get_icon_suffix%s %u\n", dir->cache ? " (cached)" : "", suffix));
|
2005-08-15 13:28:22 +00:00
|
|
|
|
2004-10-19 18:45:41 +00:00
|
|
|
return suffix;
|
|
|
|
}
|
|
|
|
|
2013-05-10 16:06:00 +00:00
|
|
|
/* returns TRUE if dir_a is a better match */
|
|
|
|
static gboolean
|
|
|
|
compare_dir_matches (IconThemeDir *dir_a, int difference_a,
|
|
|
|
IconThemeDir *dir_b, int difference_b,
|
|
|
|
int requested_size, int requested_scale)
|
|
|
|
{
|
|
|
|
int diff_a;
|
|
|
|
int diff_b;
|
|
|
|
|
|
|
|
if (difference_a == 0)
|
|
|
|
{
|
|
|
|
if (difference_b != 0)
|
|
|
|
return TRUE;
|
|
|
|
|
|
|
|
/* a and b both exact matches */
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/* If scaling, *always* prefer downscaling */
|
|
|
|
if (dir_a->size >= requested_size &&
|
|
|
|
dir_b->size < requested_size)
|
|
|
|
return TRUE;
|
|
|
|
|
|
|
|
if (dir_a->size < requested_size &&
|
|
|
|
dir_b->size >= requested_size)
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
/* Otherwise prefer the closest match */
|
|
|
|
|
|
|
|
if (difference_a < difference_b)
|
|
|
|
return TRUE;
|
|
|
|
|
|
|
|
if (difference_a > difference_b)
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
/* same pixel difference */
|
|
|
|
}
|
|
|
|
|
|
|
|
if (dir_a->scale == requested_scale &&
|
|
|
|
dir_b->scale != requested_scale)
|
|
|
|
return TRUE;
|
|
|
|
|
|
|
|
if (dir_a->scale != requested_scale &&
|
|
|
|
dir_b->scale == requested_scale)
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
/* a and b both match the scale */
|
|
|
|
|
|
|
|
if (dir_a->type != ICON_THEME_DIR_SCALABLE &&
|
|
|
|
dir_b->type == ICON_THEME_DIR_SCALABLE)
|
|
|
|
return TRUE;
|
|
|
|
|
|
|
|
if (dir_a->type == ICON_THEME_DIR_SCALABLE &&
|
|
|
|
dir_b->type != ICON_THEME_DIR_SCALABLE)
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
/* a and b both are scalable */
|
|
|
|
|
|
|
|
diff_a = abs (requested_size * requested_scale - dir_a->size * dir_a->scale);
|
|
|
|
diff_b = abs (requested_size * requested_scale - dir_b->size * dir_b->scale);
|
|
|
|
|
|
|
|
return diff_a <= diff_b;
|
|
|
|
}
|
|
|
|
|
2003-07-02 22:44:09 +00:00
|
|
|
static GtkIconInfo *
|
|
|
|
theme_lookup_icon (IconTheme *theme,
|
|
|
|
const char *icon_name,
|
|
|
|
int size,
|
2013-05-10 16:06:00 +00:00
|
|
|
gint scale,
|
2003-07-02 22:44:09 +00:00
|
|
|
gboolean allow_svg,
|
|
|
|
gboolean use_builtin)
|
|
|
|
{
|
2005-11-04 15:43:40 +00:00
|
|
|
GList *dirs, *l;
|
2003-07-02 22:44:09 +00:00
|
|
|
IconThemeDir *dir, *min_dir;
|
|
|
|
char *file;
|
|
|
|
int min_difference, difference;
|
2003-07-03 01:02:04 +00:00
|
|
|
BuiltinIcon *closest_builtin = NULL;
|
2003-07-02 22:44:09 +00:00
|
|
|
IconSuffix suffix;
|
|
|
|
|
|
|
|
min_difference = G_MAXINT;
|
|
|
|
min_dir = NULL;
|
|
|
|
|
|
|
|
/* Builtin icons are logically part of the default theme and
|
|
|
|
* are searched before other subdirectories of the default theme.
|
|
|
|
*/
|
2007-12-03 17:44:27 +00:00
|
|
|
if (use_builtin && strcmp (theme->name, DEFAULT_THEME_NAME) == 0)
|
2003-07-02 22:44:09 +00:00
|
|
|
{
|
2005-11-04 15:43:40 +00:00
|
|
|
closest_builtin = find_builtin_icon (icon_name,
|
2013-05-10 16:06:00 +00:00
|
|
|
size, scale,
|
|
|
|
&min_difference);
|
2003-07-02 22:44:09 +00:00
|
|
|
|
|
|
|
if (min_difference == 0)
|
|
|
|
return icon_info_new_builtin (closest_builtin);
|
2005-11-04 15:43:40 +00:00
|
|
|
|
|
|
|
dirs = builtin_dirs;
|
2003-07-02 22:44:09 +00:00
|
|
|
}
|
2005-11-04 15:43:40 +00:00
|
|
|
else
|
|
|
|
dirs = theme->dirs;
|
2003-07-02 22:44:09 +00:00
|
|
|
|
2005-11-04 15:43:40 +00:00
|
|
|
l = dirs;
|
2003-07-02 22:44:09 +00:00
|
|
|
while (l != NULL)
|
|
|
|
{
|
|
|
|
dir = l->data;
|
|
|
|
|
2007-12-03 17:44:27 +00:00
|
|
|
GTK_NOTE (ICONTHEME,
|
2005-08-15 19:36:32 +00:00
|
|
|
g_print ("theme_lookup_icon dir %s\n", dir->dir));
|
2004-10-19 18:45:41 +00:00
|
|
|
suffix = theme_dir_get_icon_suffix (dir, icon_name, NULL);
|
2004-10-20 17:23:02 +00:00
|
|
|
if (best_suffix (suffix, allow_svg) != ICON_SUFFIX_NONE)
|
2003-07-02 22:44:09 +00:00
|
|
|
{
|
2013-05-10 16:06:00 +00:00
|
|
|
difference = theme_dir_size_difference (dir, size, scale);
|
|
|
|
if (min_dir == NULL ||
|
|
|
|
compare_dir_matches (dir, difference,
|
|
|
|
min_dir, min_difference,
|
|
|
|
size, scale))
|
2003-07-02 22:44:09 +00:00
|
|
|
{
|
2013-05-10 16:06:00 +00:00
|
|
|
min_dir = dir;
|
|
|
|
min_difference = difference;
|
2003-07-02 22:44:09 +00:00
|
|
|
}
|
2007-01-15 02:56:33 +00:00
|
|
|
}
|
2003-07-02 22:44:09 +00:00
|
|
|
|
|
|
|
l = l->next;
|
2005-11-04 15:43:40 +00:00
|
|
|
|
|
|
|
if (l == NULL && dirs == builtin_dirs)
|
|
|
|
{
|
|
|
|
dirs = theme->dirs;
|
|
|
|
l = dirs;
|
|
|
|
}
|
2003-07-02 22:44:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (min_dir)
|
|
|
|
{
|
2013-09-23 10:37:36 +00:00
|
|
|
GtkIconInfo *icon_info = icon_info_new (min_dir->type, min_dir->size, min_dir->scale);
|
2005-08-26 16:29:40 +00:00
|
|
|
gboolean has_icon_file = FALSE;
|
2013-09-23 10:37:36 +00:00
|
|
|
|
|
|
|
icon_info->threshold = min_dir->threshold;
|
|
|
|
|
2004-10-19 18:45:41 +00:00
|
|
|
suffix = theme_dir_get_icon_suffix (min_dir, icon_name, &has_icon_file);
|
2003-07-02 22:44:09 +00:00
|
|
|
suffix = best_suffix (suffix, allow_svg);
|
|
|
|
g_assert (suffix != ICON_SUFFIX_NONE);
|
2013-09-23 10:37:36 +00:00
|
|
|
|
2007-04-25 18:01:44 +00:00
|
|
|
if (min_dir->dir)
|
|
|
|
{
|
|
|
|
file = g_strconcat (icon_name, string_from_suffix (suffix), NULL);
|
|
|
|
icon_info->filename = g_build_filename (min_dir->dir, file, NULL);
|
2012-10-28 19:01:30 +00:00
|
|
|
icon_info->icon_file = g_file_new_for_path (icon_info->filename);
|
2007-04-25 18:01:44 +00:00
|
|
|
g_free (file);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
icon_info->filename = NULL;
|
2012-10-28 19:01:30 +00:00
|
|
|
icon_info->icon_file = NULL;
|
2007-04-25 18:01:44 +00:00
|
|
|
}
|
2013-06-19 07:32:38 +00:00
|
|
|
|
2005-03-01 14:59:04 +00:00
|
|
|
if (min_dir->icon_data != NULL)
|
2013-06-19 07:32:38 +00:00
|
|
|
icon_info->data = icon_data_ref (g_hash_table_lookup (min_dir->icon_data, icon_name));
|
Update spec.
2005-03-15 Anders Carlsson <andersca@imendio.com>
* docs/iconcache.txt:
Update spec.
* gtk/gtkiconcache.c: (find_image_offset),
(_gtk_icon_cache_get_icon_flags), (_gtk_icon_cache_add_icons),
(_gtk_icon_cache_get_icon), (_gtk_icon_cache_get_icon_data):
* gtk/gtkiconcache.h:
Update to be able to fetch pixbuf data and icon metadata.
* gtk/gtkicontheme.c: (theme_lookup_icon), (gtk_icon_info_free),
(icon_info_ensure_scale_and_pixbuf):
Use new cache functions.
* gtk/updateiconcache.c: (foreach_remove_func), (load_icon_data),
(maybe_cache_image_data), (scan_directory), (write_pixdata),
(get_image_meta_data_size), (get_image_pixel_data_size),
(get_image_data_size), (get_single_node_size), (get_bucket_size),
(write_bucket), (main):
Update to write pixbuf data as well as information from .icon
files.
2005-03-15 13:18:25 +00:00
|
|
|
|
2005-08-19 04:39:30 +00:00
|
|
|
if (icon_info->data == NULL && min_dir->cache != NULL)
|
|
|
|
{
|
2007-12-03 17:44:27 +00:00
|
|
|
icon_info->data = _gtk_icon_cache_get_icon_data (min_dir->cache, icon_name, min_dir->subdir_index);
|
2005-08-19 04:39:30 +00:00
|
|
|
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,
|
2013-06-19 07:32:38 +00:00
|
|
|
g_free, (GDestroyNotify)icon_data_unref);
|
2005-08-19 04:39:30 +00:00
|
|
|
|
2013-06-19 07:32:38 +00:00
|
|
|
g_hash_table_replace (min_dir->icon_data, g_strdup (icon_name), icon_data_ref (icon_info->data));
|
2005-08-19 04:39:30 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (icon_info->data == NULL && has_icon_file)
|
2004-10-19 18:45:41 +00:00
|
|
|
{
|
|
|
|
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))
|
|
|
|
{
|
2005-08-19 04:39:30 +00:00
|
|
|
if (min_dir->icon_data == NULL)
|
2004-10-19 18:45:41 +00:00
|
|
|
min_dir->icon_data = g_hash_table_new_full (g_str_hash, g_str_equal,
|
2013-06-19 07:32:38 +00:00
|
|
|
g_free, (GDestroyNotify)icon_data_unref);
|
2004-10-19 18:45:41 +00:00
|
|
|
load_icon_data (min_dir, icon_file_path, icon_file_name);
|
2005-03-01 14:59:04 +00:00
|
|
|
|
2013-06-19 07:32:38 +00:00
|
|
|
icon_info->data = icon_data_ref (g_hash_table_lookup (min_dir->icon_data, icon_name));
|
2004-10-19 18:45:41 +00:00
|
|
|
}
|
|
|
|
g_free (icon_file_name);
|
|
|
|
g_free (icon_file_path);
|
|
|
|
}
|
2003-07-02 22:44:09 +00:00
|
|
|
|
Update spec.
2005-03-15 Anders Carlsson <andersca@imendio.com>
* docs/iconcache.txt:
Update spec.
* gtk/gtkiconcache.c: (find_image_offset),
(_gtk_icon_cache_get_icon_flags), (_gtk_icon_cache_add_icons),
(_gtk_icon_cache_get_icon), (_gtk_icon_cache_get_icon_data):
* gtk/gtkiconcache.h:
Update to be able to fetch pixbuf data and icon metadata.
* gtk/gtkicontheme.c: (theme_lookup_icon), (gtk_icon_info_free),
(icon_info_ensure_scale_and_pixbuf):
Use new cache functions.
* gtk/updateiconcache.c: (foreach_remove_func), (load_icon_data),
(maybe_cache_image_data), (scan_directory), (write_pixdata),
(get_image_meta_data_size), (get_image_pixel_data_size),
(get_image_data_size), (get_single_node_size), (get_bucket_size),
(write_bucket), (main):
Update to write pixbuf data as well as information from .icon
files.
2005-03-15 13:18:25 +00:00
|
|
|
if (min_dir->cache)
|
|
|
|
{
|
|
|
|
icon_info->cache_pixbuf = _gtk_icon_cache_get_icon (min_dir->cache, icon_name,
|
2007-12-03 17:44:27 +00:00
|
|
|
min_dir->subdir_index);
|
Update spec.
2005-03-15 Anders Carlsson <andersca@imendio.com>
* docs/iconcache.txt:
Update spec.
* gtk/gtkiconcache.c: (find_image_offset),
(_gtk_icon_cache_get_icon_flags), (_gtk_icon_cache_add_icons),
(_gtk_icon_cache_get_icon), (_gtk_icon_cache_get_icon_data):
* gtk/gtkiconcache.h:
Update to be able to fetch pixbuf data and icon metadata.
* gtk/gtkicontheme.c: (theme_lookup_icon), (gtk_icon_info_free),
(icon_info_ensure_scale_and_pixbuf):
Use new cache functions.
* gtk/updateiconcache.c: (foreach_remove_func), (load_icon_data),
(maybe_cache_image_data), (scan_directory), (write_pixdata),
(get_image_meta_data_size), (get_image_pixel_data_size),
(get_image_data_size), (get_single_node_size), (get_bucket_size),
(write_bucket), (main):
Update to write pixbuf data as well as information from .icon
files.
2005-03-15 13:18:25 +00:00
|
|
|
}
|
|
|
|
|
2003-07-02 22:44:09 +00:00
|
|
|
return icon_info;
|
|
|
|
}
|
2007-01-15 02:56:33 +00:00
|
|
|
|
|
|
|
if (closest_builtin)
|
|
|
|
return icon_info_new_builtin (closest_builtin);
|
|
|
|
|
2003-07-02 22:44:09 +00:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2006-02-13 02:31:28 +00:00
|
|
|
theme_list_icons (IconTheme *theme,
|
|
|
|
GHashTable *icons,
|
|
|
|
GQuark context)
|
2003-07-02 22:44:09 +00:00
|
|
|
{
|
|
|
|
GList *l = theme->dirs;
|
|
|
|
IconThemeDir *dir;
|
|
|
|
|
|
|
|
while (l != NULL)
|
|
|
|
{
|
|
|
|
dir = l->data;
|
|
|
|
|
|
|
|
if (context == dir->context ||
|
|
|
|
context == 0)
|
2004-10-19 18:45:41 +00:00
|
|
|
{
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
}
|
2003-07-02 22:44:09 +00:00
|
|
|
l = l->next;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-03-21 19:31:01 +00:00
|
|
|
static void
|
|
|
|
theme_list_contexts (IconTheme *theme,
|
|
|
|
GHashTable *contexts)
|
|
|
|
{
|
|
|
|
GList *l = theme->dirs;
|
|
|
|
IconThemeDir *dir;
|
|
|
|
const char *context;
|
|
|
|
|
|
|
|
while (l != NULL)
|
|
|
|
{
|
|
|
|
dir = l->data;
|
|
|
|
|
|
|
|
context = g_quark_to_string (dir->context);
|
2008-01-09 17:02:50 +00:00
|
|
|
g_hash_table_replace (contexts, (gpointer) context, NULL);
|
2007-03-21 19:31:01 +00:00
|
|
|
|
|
|
|
l = l->next;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2003-07-02 22:44:09 +00:00
|
|
|
static void
|
|
|
|
load_icon_data (IconThemeDir *dir, const char *path, const char *name)
|
|
|
|
{
|
2004-10-24 05:48:16 +00:00
|
|
|
GKeyFile *icon_file;
|
2003-07-02 22:44:09 +00:00
|
|
|
char *base_name;
|
|
|
|
char **split;
|
2004-10-24 05:48:16 +00:00
|
|
|
gsize length;
|
2003-07-02 22:44:09 +00:00
|
|
|
char *str;
|
|
|
|
char *split_point;
|
|
|
|
int i;
|
2004-10-24 05:48:16 +00:00
|
|
|
gint *ivalues;
|
|
|
|
GError *error = NULL;
|
2003-07-02 22:44:09 +00:00
|
|
|
GtkIconData *data;
|
|
|
|
|
2004-10-24 05:48:16 +00:00
|
|
|
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);
|
2006-03-31 05:17:56 +00:00
|
|
|
g_key_file_free (icon_file);
|
2004-10-24 05:48:16 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
else
|
2003-07-02 22:44:09 +00:00
|
|
|
{
|
2006-07-07 05:24:00 +00:00
|
|
|
base_name = strip_suffix (name);
|
2013-06-19 07:32:38 +00:00
|
|
|
|
2006-03-31 05:17:56 +00:00
|
|
|
data = g_slice_new0 (GtkIconData);
|
2013-06-19 07:32:38 +00:00
|
|
|
data->ref = 1;
|
|
|
|
|
2011-05-05 14:13:13 +00:00
|
|
|
/* takes ownership of base_name */
|
2004-10-24 05:48:16 +00:00
|
|
|
g_hash_table_replace (dir->icon_data, base_name, data);
|
2003-07-02 22:44:09 +00:00
|
|
|
|
2004-10-24 05:48:16 +00:00
|
|
|
ivalues = g_key_file_get_integer_list (icon_file,
|
|
|
|
"Icon Data", "EmbeddedTextRectangle",
|
|
|
|
&length, NULL);
|
|
|
|
if (ivalues)
|
2003-07-02 22:44:09 +00:00
|
|
|
{
|
2004-10-24 05:48:16 +00:00
|
|
|
if (length == 4)
|
2003-07-02 22:44:09 +00:00
|
|
|
{
|
2004-10-24 05:48:16 +00:00
|
|
|
data->has_embedded_rect = TRUE;
|
|
|
|
data->x0 = ivalues[0];
|
|
|
|
data->y0 = ivalues[1];
|
|
|
|
data->x1 = ivalues[2];
|
|
|
|
data->y1 = ivalues[3];
|
2003-07-02 22:44:09 +00:00
|
|
|
}
|
2004-10-24 05:48:16 +00:00
|
|
|
|
|
|
|
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);
|
2006-03-31 05:17:56 +00:00
|
|
|
data->attach_points = g_new (GdkPoint, data->n_attach_points);
|
2003-07-02 22:44:09 +00:00
|
|
|
|
2004-10-24 05:48:16 +00:00
|
|
|
i = 0;
|
|
|
|
while (split[i] != NULL && i < data->n_attach_points)
|
2003-07-02 22:44:09 +00:00
|
|
|
{
|
2004-10-24 05:48:16 +00:00
|
|
|
split_point = strchr (split[i], ',');
|
|
|
|
if (split_point)
|
2003-07-02 22:44:09 +00:00
|
|
|
{
|
2004-10-24 05:48:16 +00:00
|
|
|
*split_point = 0;
|
|
|
|
split_point++;
|
|
|
|
data->attach_points[i].x = atoi (split[i]);
|
|
|
|
data->attach_points[i].y = atoi (split_point);
|
2003-07-02 22:44:09 +00:00
|
|
|
}
|
2004-10-24 05:48:16 +00:00
|
|
|
i++;
|
2003-07-02 22:44:09 +00:00
|
|
|
}
|
|
|
|
|
2004-10-24 05:48:16 +00:00
|
|
|
g_strfreev (split);
|
|
|
|
g_free (str);
|
2003-07-02 22:44:09 +00:00
|
|
|
}
|
2004-10-24 05:48:16 +00:00
|
|
|
|
|
|
|
data->display_name = g_key_file_get_locale_string (icon_file,
|
|
|
|
"Icon Data", "DisplayName",
|
|
|
|
NULL, NULL);
|
|
|
|
g_key_file_free (icon_file);
|
2003-07-02 22:44:09 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
scan_directory (GtkIconThemePrivate *icon_theme,
|
|
|
|
IconThemeDir *dir, char *full_dir)
|
|
|
|
{
|
|
|
|
GDir *gdir;
|
|
|
|
const char *name;
|
2004-10-19 18:45:41 +00:00
|
|
|
|
|
|
|
GTK_NOTE (ICONTHEME,
|
|
|
|
g_print ("scanning directory %s\n", full_dir));
|
2003-07-02 22:44:09 +00:00
|
|
|
dir->icons = g_hash_table_new_full (g_str_hash, g_str_equal,
|
|
|
|
g_free, NULL);
|
|
|
|
|
|
|
|
gdir = g_dir_open (full_dir, 0, NULL);
|
|
|
|
|
|
|
|
if (gdir == NULL)
|
|
|
|
return;
|
|
|
|
|
|
|
|
while ((name = g_dir_read_name (gdir)))
|
|
|
|
{
|
2006-04-18 13:58:30 +00:00
|
|
|
char *path;
|
|
|
|
char *base_name;
|
|
|
|
IconSuffix suffix, hash_suffix;
|
|
|
|
|
2003-07-02 22:44:09 +00:00
|
|
|
if (g_str_has_suffix (name, ".icon"))
|
|
|
|
{
|
|
|
|
if (dir->icon_data == NULL)
|
|
|
|
dir->icon_data = g_hash_table_new_full (g_str_hash, g_str_equal,
|
2013-06-19 07:32:38 +00:00
|
|
|
g_free, (GDestroyNotify)icon_data_unref);
|
2003-07-02 22:44:09 +00:00
|
|
|
|
|
|
|
path = g_build_filename (full_dir, name, NULL);
|
|
|
|
if (g_file_test (path, G_FILE_TEST_IS_REGULAR))
|
|
|
|
load_icon_data (dir, path, name);
|
|
|
|
|
|
|
|
g_free (path);
|
|
|
|
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
suffix = suffix_from_name (name);
|
|
|
|
if (suffix == ICON_SUFFIX_NONE)
|
|
|
|
continue;
|
2006-04-18 13:58:30 +00:00
|
|
|
|
|
|
|
base_name = strip_suffix (name);
|
|
|
|
|
2003-07-02 22:44:09 +00:00
|
|
|
hash_suffix = GPOINTER_TO_INT (g_hash_table_lookup (dir->icons, base_name));
|
2007-04-24 14:55:52 +00:00
|
|
|
g_hash_table_replace (icon_theme->all_icons, base_name, NULL);
|
2011-05-05 14:13:13 +00:00
|
|
|
/* takes ownership of base_name */
|
2007-02-26 14:09:21 +00:00
|
|
|
g_hash_table_replace (dir->icons, base_name, GUINT_TO_POINTER (hash_suffix| suffix));
|
2003-07-02 22:44:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
g_dir_close (gdir);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
theme_subdir_load (GtkIconTheme *icon_theme,
|
2004-10-24 05:48:16 +00:00
|
|
|
IconTheme *theme,
|
|
|
|
GKeyFile *theme_file,
|
|
|
|
char *subdir)
|
2003-07-02 22:44:09 +00:00
|
|
|
{
|
2004-11-02 02:07:30 +00:00
|
|
|
GList *d;
|
2003-07-02 22:44:09 +00:00
|
|
|
char *type_string;
|
|
|
|
IconThemeDir *dir;
|
|
|
|
IconThemeDirType type;
|
|
|
|
char *context_string;
|
|
|
|
GQuark context;
|
|
|
|
int size;
|
|
|
|
int min_size;
|
|
|
|
int max_size;
|
|
|
|
int threshold;
|
|
|
|
char *full_dir;
|
2004-10-24 05:48:16 +00:00
|
|
|
GError *error = NULL;
|
2004-11-02 02:07:30 +00:00
|
|
|
IconThemeDirMtime *dir_mtime;
|
2013-05-10 16:06:00 +00:00
|
|
|
int scale;
|
2003-07-02 22:44:09 +00:00
|
|
|
|
2004-10-24 05:48:16 +00:00
|
|
|
size = g_key_file_get_integer (theme_file, subdir, "Size", &error);
|
|
|
|
if (error)
|
2003-07-02 22:44:09 +00:00
|
|
|
{
|
2004-10-24 05:48:16 +00:00
|
|
|
g_error_free (error);
|
|
|
|
g_warning ("Theme directory %s of theme %s has no size field\n",
|
|
|
|
subdir, theme->name);
|
2003-07-02 22:44:09 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
type = ICON_THEME_DIR_THRESHOLD;
|
2004-10-24 05:48:16 +00:00
|
|
|
type_string = g_key_file_get_string (theme_file, subdir, "Type", NULL);
|
|
|
|
if (type_string)
|
2003-07-02 22:44:09 +00:00
|
|
|
{
|
|
|
|
if (strcmp (type_string, "Fixed") == 0)
|
|
|
|
type = ICON_THEME_DIR_FIXED;
|
|
|
|
else if (strcmp (type_string, "Scalable") == 0)
|
|
|
|
type = ICON_THEME_DIR_SCALABLE;
|
|
|
|
else if (strcmp (type_string, "Threshold") == 0)
|
|
|
|
type = ICON_THEME_DIR_THRESHOLD;
|
|
|
|
|
|
|
|
g_free (type_string);
|
|
|
|
}
|
|
|
|
|
|
|
|
context = 0;
|
2004-10-24 05:48:16 +00:00
|
|
|
context_string = g_key_file_get_string (theme_file, subdir, "Context", NULL);
|
|
|
|
if (context_string)
|
2003-07-02 22:44:09 +00:00
|
|
|
{
|
|
|
|
context = g_quark_from_string (context_string);
|
|
|
|
g_free (context_string);
|
|
|
|
}
|
|
|
|
|
2011-06-01 00:29:53 +00:00
|
|
|
if (g_key_file_has_key (theme_file, subdir, "MaxSize", NULL))
|
|
|
|
max_size = g_key_file_get_integer (theme_file, subdir, "MaxSize", NULL);
|
|
|
|
else
|
|
|
|
max_size = size;
|
2004-10-24 05:48:16 +00:00
|
|
|
|
2011-06-01 00:29:53 +00:00
|
|
|
if (g_key_file_has_key (theme_file, subdir, "MinSize", NULL))
|
|
|
|
min_size = g_key_file_get_integer (theme_file, subdir, "MinSize", NULL);
|
|
|
|
else
|
|
|
|
min_size = size;
|
2003-07-02 22:44:09 +00:00
|
|
|
|
2011-06-01 00:29:53 +00:00
|
|
|
if (g_key_file_has_key (theme_file, subdir, "Threshold", NULL))
|
|
|
|
threshold = g_key_file_get_integer (theme_file, subdir, "Threshold", NULL);
|
|
|
|
else
|
|
|
|
threshold = 2;
|
2004-11-02 02:07:30 +00:00
|
|
|
|
2013-08-19 13:41:49 +00:00
|
|
|
if (g_key_file_has_key (theme_file, subdir, "Scale", NULL))
|
|
|
|
scale = g_key_file_get_integer (theme_file, subdir, "Scale", NULL);
|
2013-05-10 16:06:00 +00:00
|
|
|
else
|
|
|
|
scale = 1;
|
|
|
|
|
2004-11-02 02:07:30 +00:00
|
|
|
for (d = icon_theme->priv->dir_mtimes; d; d = d->next)
|
2003-07-02 22:44:09 +00:00
|
|
|
{
|
2004-11-02 02:07:30 +00:00
|
|
|
dir_mtime = (IconThemeDirMtime *)d->data;
|
|
|
|
|
|
|
|
if (dir_mtime->mtime == 0)
|
|
|
|
continue; /* directory doesn't exist */
|
2004-10-19 18:45:41 +00:00
|
|
|
|
2004-11-02 02:07:30 +00:00
|
|
|
full_dir = g_build_filename (dir_mtime->dir, subdir, NULL);
|
2004-10-19 18:45:41 +00:00
|
|
|
|
|
|
|
/* First, see if we have a cache for the directory */
|
2005-04-06 03:34:38 +00:00
|
|
|
if (dir_mtime->cache != NULL || g_file_test (full_dir, G_FILE_TEST_IS_DIR))
|
2003-07-02 22:44:09 +00:00
|
|
|
{
|
2005-04-06 03:34:38 +00:00
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
2003-07-02 22:44:09 +00:00
|
|
|
dir = g_new (IconThemeDir, 1);
|
|
|
|
dir->type = type;
|
|
|
|
dir->context = context;
|
|
|
|
dir->size = size;
|
|
|
|
dir->min_size = min_size;
|
|
|
|
dir->max_size = max_size;
|
|
|
|
dir->threshold = threshold;
|
|
|
|
dir->dir = full_dir;
|
|
|
|
dir->icon_data = NULL;
|
2004-10-19 18:45:41 +00:00
|
|
|
dir->subdir = g_strdup (subdir);
|
2013-05-10 16:06:00 +00:00
|
|
|
dir->scale = scale;
|
|
|
|
|
2005-04-06 03:34:38 +00:00
|
|
|
if (dir_mtime->cache != NULL)
|
2007-12-03 17:44:27 +00:00
|
|
|
{
|
|
|
|
dir->cache = _gtk_icon_cache_ref (dir_mtime->cache);
|
|
|
|
dir->subdir_index = _gtk_icon_cache_get_directory_index (dir->cache, dir->subdir);
|
|
|
|
}
|
2004-10-19 18:45:41 +00:00
|
|
|
else
|
|
|
|
{
|
|
|
|
dir->cache = NULL;
|
2007-12-03 17:44:27 +00:00
|
|
|
dir->subdir_index = -1;
|
2004-10-19 18:45:41 +00:00
|
|
|
scan_directory (icon_theme->priv, dir, full_dir);
|
|
|
|
}
|
2003-07-02 22:44:09 +00:00
|
|
|
|
2004-06-02 02:48:50 +00:00
|
|
|
theme->dirs = g_list_prepend (theme->dirs, dir);
|
2003-07-02 22:44:09 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
g_free (full_dir);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-06-19 07:32:38 +00:00
|
|
|
static GtkIconData *
|
|
|
|
icon_data_ref (GtkIconData *icon_data)
|
|
|
|
{
|
|
|
|
if (icon_data)
|
|
|
|
icon_data->ref++;
|
|
|
|
return icon_data;
|
|
|
|
}
|
|
|
|
|
2003-07-02 22:44:09 +00:00
|
|
|
static void
|
2013-06-19 07:32:38 +00:00
|
|
|
icon_data_unref (GtkIconData *icon_data)
|
2003-07-02 22:44:09 +00:00
|
|
|
{
|
2013-06-19 07:32:38 +00:00
|
|
|
if (icon_data)
|
|
|
|
{
|
|
|
|
icon_data->ref--;
|
|
|
|
if (icon_data->ref == 0)
|
|
|
|
{
|
|
|
|
g_free (icon_data->attach_points);
|
|
|
|
g_free (icon_data->display_name);
|
|
|
|
g_slice_free (GtkIconData, icon_data);
|
|
|
|
}
|
|
|
|
}
|
2003-07-02 22:44:09 +00:00
|
|
|
}
|
|
|
|
|
2013-02-14 12:32:30 +00:00
|
|
|
static GtkIconData *
|
|
|
|
icon_data_dup (GtkIconData *icon_data)
|
|
|
|
{
|
|
|
|
GtkIconData *dup = NULL;
|
|
|
|
if (icon_data)
|
|
|
|
{
|
|
|
|
dup = g_slice_new0 (GtkIconData);
|
2013-06-19 07:32:38 +00:00
|
|
|
dup->ref = 1;
|
2013-02-14 12:32:30 +00:00
|
|
|
*dup = *icon_data;
|
|
|
|
if (dup->n_attach_points > 0)
|
|
|
|
{
|
|
|
|
dup->attach_points = g_memdup (dup->attach_points,
|
|
|
|
sizeof (GdkPoint) * dup->n_attach_points);
|
|
|
|
}
|
|
|
|
dup->display_name = g_strdup (dup->display_name);
|
|
|
|
}
|
|
|
|
|
|
|
|
return dup;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2003-07-02 22:44:09 +00:00
|
|
|
/*
|
|
|
|
* GtkIconInfo
|
|
|
|
*/
|
|
|
|
|
2013-02-13 14:05:02 +00:00
|
|
|
static void gtk_icon_info_class_init (GtkIconInfoClass *klass);
|
2003-07-02 22:44:09 +00:00
|
|
|
|
2013-02-13 14:05:02 +00:00
|
|
|
G_DEFINE_TYPE (GtkIconInfo, gtk_icon_info, G_TYPE_OBJECT)
|
2003-07-02 22:44:09 +00:00
|
|
|
|
2013-02-13 14:05:02 +00:00
|
|
|
static void
|
|
|
|
gtk_icon_info_init (GtkIconInfo *icon_info)
|
|
|
|
{
|
2003-07-02 22:44:09 +00:00
|
|
|
icon_info->scale = -1.;
|
2013-02-13 14:05:02 +00:00
|
|
|
}
|
2003-07-02 22:44:09 +00:00
|
|
|
|
2013-02-13 14:05:02 +00:00
|
|
|
static GtkIconInfo *
|
2013-09-23 10:37:36 +00:00
|
|
|
icon_info_new (IconThemeDirType type, int dir_size, int dir_scale)
|
2013-02-13 14:05:02 +00:00
|
|
|
{
|
2013-09-23 10:37:36 +00:00
|
|
|
GtkIconInfo *icon_info;
|
|
|
|
|
|
|
|
icon_info = g_object_new (GTK_TYPE_ICON_INFO, NULL);
|
|
|
|
|
|
|
|
icon_info->dir_type = type;
|
|
|
|
icon_info->dir_size = dir_size;
|
|
|
|
icon_info->dir_scale = dir_scale;
|
2013-09-23 10:42:30 +00:00
|
|
|
icon_info->unscaled_scale = 1.0;
|
2013-09-23 10:37:36 +00:00
|
|
|
|
|
|
|
return icon_info;
|
2003-07-02 22:44:09 +00:00
|
|
|
}
|
|
|
|
|
2013-02-14 12:32:30 +00:00
|
|
|
/* This only copies whatever is needed to load the pixbuf, so that we can do
|
|
|
|
* a load in a thread without affecting the original IconInfo from the thread.
|
|
|
|
*/
|
|
|
|
static GtkIconInfo *
|
|
|
|
icon_info_dup (GtkIconInfo *icon_info)
|
|
|
|
{
|
|
|
|
GtkIconInfo *dup;
|
|
|
|
GSList *l;
|
|
|
|
|
2013-09-23 10:37:36 +00:00
|
|
|
dup = icon_info_new (icon_info->dir_type, icon_info->dir_size, icon_info->dir_scale);
|
2013-02-14 12:32:30 +00:00
|
|
|
|
|
|
|
dup->filename = g_strdup (icon_info->filename);
|
|
|
|
if (icon_info->icon_file)
|
|
|
|
dup->icon_file = g_object_ref (icon_info->icon_file);
|
|
|
|
if (icon_info->loadable)
|
|
|
|
dup->loadable = g_object_ref (icon_info->loadable);
|
2013-03-04 20:33:04 +00:00
|
|
|
if (icon_info->pixbuf)
|
|
|
|
dup->pixbuf = g_object_ref (icon_info->pixbuf);
|
2013-02-14 12:32:30 +00:00
|
|
|
|
|
|
|
for (l = icon_info->emblem_infos; l != NULL; l = l->next)
|
|
|
|
{
|
|
|
|
dup->emblem_infos =
|
|
|
|
g_slist_append (dup->emblem_infos,
|
|
|
|
icon_info_dup (l->data));
|
|
|
|
}
|
|
|
|
|
|
|
|
if (icon_info->cache_pixbuf)
|
|
|
|
dup->cache_pixbuf = g_object_ref (icon_info->cache_pixbuf);
|
|
|
|
|
|
|
|
dup->data = icon_data_dup (icon_info->data);
|
2013-09-23 10:42:30 +00:00
|
|
|
dup->unscaled_scale = icon_info->unscaled_scale;
|
2013-02-14 12:32:30 +00:00
|
|
|
dup->threshold = icon_info->threshold;
|
|
|
|
dup->desired_size = icon_info->desired_size;
|
2013-05-10 16:06:00 +00:00
|
|
|
dup->desired_scale = icon_info->desired_scale;
|
2013-02-14 12:32:30 +00:00
|
|
|
dup->raw_coordinates = icon_info->raw_coordinates;
|
|
|
|
dup->forced_size = icon_info->forced_size;
|
|
|
|
dup->emblems_applied = icon_info->emblems_applied;
|
|
|
|
|
|
|
|
return dup;
|
|
|
|
}
|
|
|
|
|
2003-07-02 22:44:09 +00:00
|
|
|
static GtkIconInfo *
|
|
|
|
icon_info_new_builtin (BuiltinIcon *icon)
|
|
|
|
{
|
2013-09-23 10:37:36 +00:00
|
|
|
GtkIconInfo *icon_info = icon_info_new (ICON_THEME_DIR_THRESHOLD, icon->size, 1);
|
2003-07-02 22:44:09 +00:00
|
|
|
|
2005-11-04 15:43:40 +00:00
|
|
|
icon_info->cache_pixbuf = g_object_ref (icon->pixbuf);
|
2003-07-02 22:44:09 +00:00
|
|
|
icon_info->threshold = 2;
|
2008-05-29 14:33:49 +00:00
|
|
|
|
2003-07-02 22:44:09 +00:00
|
|
|
return icon_info;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2013-02-16 00:48:48 +00:00
|
|
|
* gtk_icon_info_copy: (skip)
|
2003-07-02 22:44:09 +00:00
|
|
|
* @icon_info: a #GtkIconInfo
|
|
|
|
*
|
|
|
|
* Make a copy of a #GtkIconInfo.
|
|
|
|
*
|
|
|
|
* Return value: the new GtkIconInfo
|
2003-11-08 00:51:10 +00:00
|
|
|
*
|
|
|
|
* Since: 2.4
|
2013-02-15 10:07:51 +00:00
|
|
|
*
|
|
|
|
* Deprecated: 3.8: Use g_object_ref()
|
2003-07-02 22:44:09 +00:00
|
|
|
**/
|
|
|
|
GtkIconInfo *
|
|
|
|
gtk_icon_info_copy (GtkIconInfo *icon_info)
|
|
|
|
{
|
|
|
|
|
|
|
|
g_return_val_if_fail (icon_info != NULL, NULL);
|
|
|
|
|
2013-02-13 14:05:02 +00:00
|
|
|
return g_object_ref (icon_info);
|
2003-07-02 22:44:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2013-02-16 00:48:48 +00:00
|
|
|
* gtk_icon_info_free: (skip)
|
2003-07-02 22:44:09 +00:00
|
|
|
* @icon_info: a #GtkIconInfo
|
|
|
|
*
|
|
|
|
* Free a #GtkIconInfo and associated information
|
2003-11-08 00:51:10 +00:00
|
|
|
*
|
|
|
|
* Since: 2.4
|
2013-02-15 10:07:51 +00:00
|
|
|
*
|
|
|
|
* Deprecated: 3.8: Use g_object_unref()
|
2003-07-02 22:44:09 +00:00
|
|
|
**/
|
|
|
|
void
|
|
|
|
gtk_icon_info_free (GtkIconInfo *icon_info)
|
|
|
|
{
|
|
|
|
g_return_if_fail (icon_info != NULL);
|
|
|
|
|
2013-02-13 14:05:02 +00:00
|
|
|
g_object_unref (icon_info);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gtk_icon_info_finalize (GObject *object)
|
|
|
|
{
|
|
|
|
GtkIconInfo *icon_info = (GtkIconInfo *) object;
|
2012-11-26 12:49:49 +00:00
|
|
|
|
|
|
|
if (icon_info->in_cache)
|
|
|
|
g_hash_table_remove (icon_info->in_cache->priv->info_cache, &icon_info->key);
|
|
|
|
|
|
|
|
g_strfreev (icon_info->key.icon_names);
|
|
|
|
|
2007-03-09 21:57:37 +00:00
|
|
|
g_free (icon_info->filename);
|
2012-10-28 19:01:30 +00:00
|
|
|
g_clear_object (&icon_info->icon_file);
|
|
|
|
|
2013-10-02 12:28:00 +00:00
|
|
|
g_clear_object (&icon_info->loadable);
|
2013-02-16 00:35:44 +00:00
|
|
|
g_slist_free_full (icon_info->emblem_infos, (GDestroyNotify) g_object_unref);
|
2013-10-02 12:28:00 +00:00
|
|
|
g_clear_object (&icon_info->pixbuf);
|
2013-10-02 12:30:14 +00:00
|
|
|
g_clear_object (&icon_info->proxy_pixbuf);
|
2013-10-02 12:28:00 +00:00
|
|
|
g_clear_object (&icon_info->cache_pixbuf);
|
2013-10-02 12:30:14 +00:00
|
|
|
g_clear_error (&icon_info->load_error);
|
2013-10-02 12:28:00 +00:00
|
|
|
g_clear_pointer (&icon_info->symbolic_pixbuf_size, gtk_requisition_free);
|
2013-06-19 07:32:38 +00:00
|
|
|
icon_data_unref (icon_info->data);
|
2005-08-19 04:39:30 +00:00
|
|
|
|
2012-11-26 12:52:05 +00:00
|
|
|
symbolic_pixbuf_cache_free (icon_info->symbolic_pixbuf_cache);
|
|
|
|
|
2013-02-13 14:05:02 +00:00
|
|
|
G_OBJECT_CLASS (gtk_icon_info_parent_class)->finalize (object);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gtk_icon_info_class_init (GtkIconInfoClass *klass)
|
|
|
|
{
|
|
|
|
GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
|
|
|
|
|
|
|
|
gobject_class->finalize = gtk_icon_info_finalize;
|
2003-07-02 22:44:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* gtk_icon_info_get_base_size:
|
|
|
|
* @icon_info: a #GtkIconInfo
|
|
|
|
*
|
|
|
|
* Gets the base size for the icon. The base size
|
|
|
|
* is a size for the icon that was specified by
|
|
|
|
* the icon theme creator. This may be different
|
|
|
|
* than the actual size of image; an example of
|
|
|
|
* this is small emblem icons that can be attached
|
|
|
|
* to a larger icon. These icons will be given
|
|
|
|
* the same base size as the larger icons to which
|
|
|
|
* they are attached.
|
2013-05-10 16:06:00 +00:00
|
|
|
*
|
|
|
|
* Note that for scaled icons the base size does
|
|
|
|
* not include the base scale.
|
|
|
|
*
|
2003-07-02 22:44:09 +00:00
|
|
|
* Return value: the base size, or 0, if no base
|
|
|
|
* size is known for the icon.
|
2003-11-08 00:51:10 +00:00
|
|
|
*
|
|
|
|
* Since: 2.4
|
2003-07-02 22:44:09 +00:00
|
|
|
**/
|
|
|
|
gint
|
|
|
|
gtk_icon_info_get_base_size (GtkIconInfo *icon_info)
|
|
|
|
{
|
|
|
|
g_return_val_if_fail (icon_info != NULL, 0);
|
|
|
|
|
|
|
|
return icon_info->dir_size;
|
|
|
|
}
|
|
|
|
|
2013-05-10 16:06:00 +00:00
|
|
|
/**
|
|
|
|
* gtk_icon_info_get_base_scale:
|
|
|
|
* @icon_info: a #GtkIconInfo
|
|
|
|
*
|
|
|
|
* Gets the base scale for the icon. The base scale is a scale for the
|
|
|
|
* icon that was specified by the icon theme creator. For instance an
|
|
|
|
* icon drawn for a high-dpi screen with window-scale 2 for a base
|
|
|
|
* size of 32 will be 64 pixels tall and have a base_scale of 2.
|
|
|
|
*
|
|
|
|
* Return value: the base scale.
|
|
|
|
*
|
|
|
|
* Since: 3.10
|
|
|
|
**/
|
|
|
|
gint
|
|
|
|
gtk_icon_info_get_base_scale (GtkIconInfo *icon_info)
|
|
|
|
{
|
|
|
|
g_return_val_if_fail (icon_info != NULL, 0);
|
|
|
|
|
|
|
|
return icon_info->dir_scale;
|
|
|
|
}
|
|
|
|
|
2003-07-02 22:44:09 +00:00
|
|
|
/**
|
|
|
|
* gtk_icon_info_get_filename:
|
|
|
|
* @icon_info: a #GtkIconInfo
|
|
|
|
*
|
|
|
|
* Gets the filename for the icon. If the
|
|
|
|
* %GTK_ICON_LOOKUP_USE_BUILTIN flag was passed
|
|
|
|
* to gtk_icon_theme_lookup_icon(), there may be
|
|
|
|
* no filename if a builtin icon is returned; in this
|
|
|
|
* case, you should use gtk_icon_info_get_builtin_pixbuf().
|
|
|
|
*
|
2011-01-18 05:42:31 +00:00
|
|
|
* Return value: (type filename): the filename for the icon, or %NULL
|
|
|
|
* if gtk_icon_info_get_builtin_pixbuf() should be used instead. The
|
|
|
|
* return value is owned by GTK+ and should not be modified or freed.
|
2003-11-08 00:51:10 +00:00
|
|
|
*
|
|
|
|
* Since: 2.4
|
2003-07-02 22:44:09 +00:00
|
|
|
**/
|
2011-06-06 18:13:44 +00:00
|
|
|
const gchar *
|
2003-07-02 22:44:09 +00:00
|
|
|
gtk_icon_info_get_filename (GtkIconInfo *icon_info)
|
|
|
|
{
|
|
|
|
g_return_val_if_fail (icon_info != NULL, NULL);
|
|
|
|
|
|
|
|
return icon_info->filename;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* gtk_icon_info_get_builtin_pixbuf:
|
2014-01-27 22:04:46 +00:00
|
|
|
* @icon_info: a #GtkIconInfo
|
2003-07-02 22:44:09 +00:00
|
|
|
*
|
|
|
|
* Gets the built-in image for this icon, if any. To allow
|
|
|
|
* GTK+ to use built in icon images, you must pass the
|
|
|
|
* %GTK_ICON_LOOKUP_USE_BUILTIN to
|
|
|
|
* gtk_icon_theme_lookup_icon().
|
2009-12-10 10:23:40 +00:00
|
|
|
*
|
|
|
|
* Return value: (transfer none): the built-in image pixbuf, or %NULL. No
|
2003-07-02 22:44:09 +00:00
|
|
|
* extra reference is added to the returned pixbuf, so if
|
|
|
|
* you want to keep it around, you must use g_object_ref().
|
|
|
|
* The returned image must not be modified.
|
2003-11-08 00:51:10 +00:00
|
|
|
*
|
|
|
|
* Since: 2.4
|
2003-07-02 22:44:09 +00:00
|
|
|
**/
|
|
|
|
GdkPixbuf *
|
|
|
|
gtk_icon_info_get_builtin_pixbuf (GtkIconInfo *icon_info)
|
|
|
|
{
|
|
|
|
g_return_val_if_fail (icon_info != NULL, NULL);
|
|
|
|
|
2005-11-04 15:43:40 +00:00
|
|
|
if (icon_info->filename)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
return icon_info->cache_pixbuf;
|
2003-07-02 22:44:09 +00:00
|
|
|
}
|
|
|
|
|
2013-12-15 02:41:49 +00:00
|
|
|
/**
|
|
|
|
* gtk_icon_info_is_symbolic:
|
2014-01-27 22:04:46 +00:00
|
|
|
* @icon_info: a #GtkIconInfo
|
2013-12-15 02:41:49 +00:00
|
|
|
*
|
|
|
|
* Checks if the icon is symbolic or not. This currently uses only
|
|
|
|
* the file name and not the file contents for determining this.
|
|
|
|
* This behaviour may change in the future.
|
|
|
|
*
|
|
|
|
* Return value: %TRUE if the icon is symbolic, %FALSE otherwise.
|
|
|
|
*
|
|
|
|
* Since: 3.12
|
|
|
|
**/
|
|
|
|
gboolean
|
|
|
|
gtk_icon_info_is_symbolic (GtkIconInfo *icon_info)
|
|
|
|
{
|
|
|
|
gchar *icon_uri;
|
|
|
|
gboolean is_symbolic;
|
|
|
|
|
|
|
|
g_return_val_if_fail (GTK_IS_ICON_INFO (icon_info), FALSE);
|
|
|
|
|
|
|
|
icon_uri = NULL;
|
|
|
|
if (icon_info->icon_file)
|
|
|
|
icon_uri = g_file_get_uri (icon_info->icon_file);
|
|
|
|
|
|
|
|
is_symbolic = (icon_uri != NULL) && (g_str_has_suffix (icon_uri, "-symbolic.svg"));
|
|
|
|
g_free (icon_uri);
|
|
|
|
|
|
|
|
return is_symbolic;
|
|
|
|
}
|
|
|
|
|
2008-07-28 16:15:14 +00:00
|
|
|
static gboolean icon_info_ensure_scale_and_pixbuf (GtkIconInfo*, gboolean);
|
|
|
|
|
|
|
|
/* Combine the icon with all emblems, the first emblem is placed
|
|
|
|
* in the southeast corner. Scale emblems to be at most 3/4 of the
|
|
|
|
* size of the icon itself.
|
|
|
|
*/
|
|
|
|
static void
|
|
|
|
apply_emblems (GtkIconInfo *info)
|
|
|
|
{
|
2008-10-20 16:55:00 +00:00
|
|
|
GdkPixbuf *icon = NULL;
|
2008-08-07 10:07:49 +00:00
|
|
|
gint w, h, pos;
|
2008-07-28 16:15:14 +00:00
|
|
|
GSList *l;
|
|
|
|
|
2008-10-20 16:55:00 +00:00
|
|
|
if (info->emblem_infos == NULL)
|
|
|
|
return;
|
|
|
|
|
2010-11-05 09:33:16 +00:00
|
|
|
if (info->emblems_applied)
|
|
|
|
return;
|
|
|
|
|
2008-10-20 16:55:00 +00:00
|
|
|
w = gdk_pixbuf_get_width (info->pixbuf);
|
|
|
|
h = gdk_pixbuf_get_height (info->pixbuf);
|
2008-07-28 16:15:14 +00:00
|
|
|
|
|
|
|
for (l = info->emblem_infos, pos = 0; l; l = l->next, pos++)
|
|
|
|
{
|
|
|
|
GtkIconInfo *emblem_info = l->data;
|
2008-08-07 10:07:49 +00:00
|
|
|
|
|
|
|
if (icon_info_ensure_scale_and_pixbuf (emblem_info, FALSE))
|
2008-07-28 16:15:14 +00:00
|
|
|
{
|
2008-08-07 10:07:49 +00:00
|
|
|
GdkPixbuf *emblem = emblem_info->pixbuf;
|
|
|
|
gint ew, eh;
|
|
|
|
gint x = 0, y = 0; /* silence compiler */
|
|
|
|
gdouble scale;
|
|
|
|
|
|
|
|
ew = gdk_pixbuf_get_width (emblem);
|
|
|
|
eh = gdk_pixbuf_get_height (emblem);
|
|
|
|
if (ew >= w)
|
|
|
|
{
|
|
|
|
scale = 0.75;
|
|
|
|
ew = ew * 0.75;
|
|
|
|
eh = eh * 0.75;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
scale = 1.0;
|
|
|
|
|
|
|
|
switch (pos % 4)
|
|
|
|
{
|
|
|
|
case 0:
|
|
|
|
x = w - ew;
|
|
|
|
y = h - eh;
|
|
|
|
break;
|
|
|
|
case 1:
|
|
|
|
x = w - ew;
|
|
|
|
y = 0;
|
|
|
|
break;
|
|
|
|
case 2:
|
|
|
|
x = 0;
|
|
|
|
y = h - eh;
|
|
|
|
break;
|
|
|
|
case 3:
|
|
|
|
x = 0;
|
|
|
|
y = 0;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2008-10-20 16:55:00 +00:00
|
|
|
if (icon == NULL)
|
|
|
|
{
|
|
|
|
icon = gdk_pixbuf_copy (info->pixbuf);
|
|
|
|
if (icon == NULL)
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2008-08-07 10:07:49 +00:00
|
|
|
gdk_pixbuf_composite (emblem, icon, x, y, ew, eh, x, y,
|
2008-07-28 16:15:14 +00:00
|
|
|
scale, scale, GDK_INTERP_BILINEAR, 255);
|
2008-08-07 10:07:49 +00:00
|
|
|
}
|
2008-07-28 16:15:14 +00:00
|
|
|
}
|
2008-10-20 16:55:00 +00:00
|
|
|
|
|
|
|
if (icon)
|
|
|
|
{
|
|
|
|
g_object_unref (info->pixbuf);
|
|
|
|
info->pixbuf = icon;
|
|
|
|
}
|
2010-11-05 09:33:16 +00:00
|
|
|
|
|
|
|
info->emblems_applied = TRUE;
|
2008-07-28 16:15:14 +00:00
|
|
|
}
|
|
|
|
|
2013-02-14 12:32:30 +00:00
|
|
|
/* If this returns TRUE, its safe to call
|
|
|
|
icon_info_ensure_scale_and_pixbuf without blocking */
|
|
|
|
static gboolean
|
|
|
|
icon_info_get_pixbuf_ready (GtkIconInfo *icon_info)
|
|
|
|
{
|
|
|
|
if (icon_info->pixbuf &&
|
|
|
|
(icon_info->emblem_infos == NULL || icon_info->emblems_applied))
|
|
|
|
return TRUE;
|
|
|
|
|
|
|
|
if (icon_info->load_error)
|
|
|
|
return TRUE;
|
|
|
|
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2008-05-29 14:33:49 +00:00
|
|
|
/* This function contains the complicated logic for deciding
|
2003-07-02 22:44:09 +00:00
|
|
|
* on the size at which to load the icon and loading it at
|
|
|
|
* that size.
|
|
|
|
*/
|
|
|
|
static gboolean
|
2008-05-29 14:33:49 +00:00
|
|
|
icon_info_ensure_scale_and_pixbuf (GtkIconInfo *icon_info,
|
|
|
|
gboolean scale_only)
|
2003-07-02 22:44:09 +00:00
|
|
|
{
|
|
|
|
int image_width, image_height;
|
2013-05-10 16:06:00 +00:00
|
|
|
int scaled_desired_size;
|
2003-07-02 22:44:09 +00:00
|
|
|
GdkPixbuf *source_pixbuf;
|
2008-05-29 14:33:49 +00:00
|
|
|
gboolean is_svg;
|
2003-07-02 22:44:09 +00:00
|
|
|
|
|
|
|
/* First check if we already succeeded have the necessary
|
|
|
|
* information (or failed earlier)
|
|
|
|
*/
|
|
|
|
if (scale_only && icon_info->scale >= 0)
|
|
|
|
return TRUE;
|
|
|
|
|
|
|
|
if (icon_info->pixbuf)
|
2010-11-05 09:33:16 +00:00
|
|
|
{
|
|
|
|
apply_emblems (icon_info);
|
|
|
|
return TRUE;
|
|
|
|
}
|
2003-07-02 22:44:09 +00:00
|
|
|
|
|
|
|
if (icon_info->load_error)
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
/* SVG icons are a special case - we just immediately scale them
|
|
|
|
* to the desired size
|
|
|
|
*/
|
2012-10-28 19:01:30 +00:00
|
|
|
if (icon_info->icon_file && !icon_info->loadable)
|
|
|
|
icon_info->loadable = G_LOADABLE_ICON (g_file_icon_new (icon_info->icon_file));
|
2008-05-29 14:33:49 +00:00
|
|
|
|
2013-05-10 16:06:00 +00:00
|
|
|
scaled_desired_size = icon_info->desired_size * icon_info->desired_scale;
|
|
|
|
|
2008-05-29 14:33:49 +00:00
|
|
|
is_svg = FALSE;
|
|
|
|
if (G_IS_FILE_ICON (icon_info->loadable))
|
|
|
|
{
|
|
|
|
GFile *file;
|
|
|
|
GFileInfo *file_info;
|
|
|
|
const gchar *content_type;
|
|
|
|
|
|
|
|
file = g_file_icon_get_file (G_FILE_ICON (icon_info->loadable));
|
|
|
|
file_info = g_file_query_info (file,
|
|
|
|
G_FILE_ATTRIBUTE_STANDARD_CONTENT_TYPE,
|
|
|
|
G_FILE_QUERY_INFO_NONE,
|
|
|
|
NULL, NULL);
|
|
|
|
if (file_info)
|
|
|
|
{
|
|
|
|
content_type = g_file_info_get_content_type (file_info);
|
|
|
|
|
|
|
|
if (content_type && strcmp (content_type, "image/svg+xml") == 0)
|
|
|
|
is_svg = TRUE;
|
|
|
|
|
|
|
|
g_object_unref (file_info);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (is_svg)
|
2003-07-02 22:44:09 +00:00
|
|
|
{
|
2008-05-29 14:33:49 +00:00
|
|
|
GInputStream *stream;
|
|
|
|
|
2013-05-10 16:06:00 +00:00
|
|
|
icon_info->scale = scaled_desired_size / 1000.;
|
2003-07-02 22:44:09 +00:00
|
|
|
|
|
|
|
if (scale_only)
|
|
|
|
return TRUE;
|
2013-05-10 16:06:00 +00:00
|
|
|
|
|
|
|
/* TODO: We should have a load_at_scale */
|
2008-05-29 14:33:49 +00:00
|
|
|
stream = g_loadable_icon_load (icon_info->loadable,
|
2013-05-10 16:06:00 +00:00
|
|
|
scaled_desired_size,
|
2008-05-29 14:33:49 +00:00
|
|
|
NULL, NULL,
|
|
|
|
&icon_info->load_error);
|
|
|
|
if (stream)
|
|
|
|
{
|
|
|
|
icon_info->pixbuf = gdk_pixbuf_new_from_stream_at_scale (stream,
|
2013-05-10 16:06:00 +00:00
|
|
|
scaled_desired_size,
|
|
|
|
scaled_desired_size,
|
2008-05-29 14:33:49 +00:00
|
|
|
TRUE,
|
|
|
|
NULL,
|
|
|
|
&icon_info->load_error);
|
|
|
|
g_object_unref (stream);
|
|
|
|
}
|
2003-07-02 22:44:09 +00:00
|
|
|
|
2008-07-28 16:15:14 +00:00
|
|
|
if (!icon_info->pixbuf)
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
apply_emblems (icon_info);
|
|
|
|
|
|
|
|
return TRUE;
|
2003-07-02 22:44:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* In many cases, the scale can be determined without actual access
|
|
|
|
* to the icon file. This is generally true when we have a size
|
|
|
|
* for the directory where the icon is; the image size doesn't
|
|
|
|
* matter in that case.
|
|
|
|
*/
|
2008-05-29 14:33:49 +00:00
|
|
|
if (icon_info->forced_size)
|
|
|
|
icon_info->scale = -1;
|
|
|
|
else if (icon_info->dir_type == ICON_THEME_DIR_FIXED)
|
2013-09-23 10:42:30 +00:00
|
|
|
icon_info->scale = icon_info->unscaled_scale;
|
2003-07-02 22:44:09 +00:00
|
|
|
else if (icon_info->dir_type == ICON_THEME_DIR_THRESHOLD)
|
|
|
|
{
|
2013-05-10 16:06:00 +00:00
|
|
|
if (scaled_desired_size >= (icon_info->dir_size - icon_info->threshold) * icon_info->dir_scale &&
|
|
|
|
scaled_desired_size <= (icon_info->dir_size + icon_info->threshold) * icon_info->dir_scale)
|
2013-09-23 10:42:30 +00:00
|
|
|
icon_info->scale = icon_info->unscaled_scale;
|
2003-07-02 22:44:09 +00:00
|
|
|
else if (icon_info->dir_size > 0)
|
2013-05-10 16:06:00 +00:00
|
|
|
icon_info->scale =(gdouble) scaled_desired_size / (icon_info->dir_size * icon_info->dir_scale);
|
2003-07-02 22:44:09 +00:00
|
|
|
}
|
|
|
|
else if (icon_info->dir_type == ICON_THEME_DIR_SCALABLE)
|
|
|
|
{
|
|
|
|
if (icon_info->dir_size > 0)
|
2013-05-10 16:06:00 +00:00
|
|
|
icon_info->scale = (gdouble) scaled_desired_size / (icon_info->dir_size * icon_info->dir_scale);
|
2003-07-02 22:44:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (icon_info->scale >= 0. && scale_only)
|
|
|
|
return TRUE;
|
|
|
|
|
|
|
|
/* At this point, we need to actually get the icon; either from the
|
2007-03-23 14:06:52 +00:00
|
|
|
* builtin image or by loading the file
|
2003-07-02 22:44:09 +00:00
|
|
|
*/
|
2008-05-29 14:33:49 +00:00
|
|
|
source_pixbuf = NULL;
|
2005-11-04 15:43:40 +00:00
|
|
|
if (icon_info->cache_pixbuf)
|
Update spec.
2005-03-15 Anders Carlsson <andersca@imendio.com>
* docs/iconcache.txt:
Update spec.
* gtk/gtkiconcache.c: (find_image_offset),
(_gtk_icon_cache_get_icon_flags), (_gtk_icon_cache_add_icons),
(_gtk_icon_cache_get_icon), (_gtk_icon_cache_get_icon_data):
* gtk/gtkiconcache.h:
Update to be able to fetch pixbuf data and icon metadata.
* gtk/gtkicontheme.c: (theme_lookup_icon), (gtk_icon_info_free),
(icon_info_ensure_scale_and_pixbuf):
Use new cache functions.
* gtk/updateiconcache.c: (foreach_remove_func), (load_icon_data),
(maybe_cache_image_data), (scan_directory), (write_pixdata),
(get_image_meta_data_size), (get_image_pixel_data_size),
(get_image_data_size), (get_single_node_size), (get_bucket_size),
(write_bucket), (main):
Update to write pixbuf data as well as information from .icon
files.
2005-03-15 13:18:25 +00:00
|
|
|
source_pixbuf = g_object_ref (icon_info->cache_pixbuf);
|
2003-07-02 22:44:09 +00:00
|
|
|
else
|
|
|
|
{
|
2008-05-29 14:33:49 +00:00
|
|
|
GInputStream *stream;
|
Update spec.
2005-03-15 Anders Carlsson <andersca@imendio.com>
* docs/iconcache.txt:
Update spec.
* gtk/gtkiconcache.c: (find_image_offset),
(_gtk_icon_cache_get_icon_flags), (_gtk_icon_cache_add_icons),
(_gtk_icon_cache_get_icon), (_gtk_icon_cache_get_icon_data):
* gtk/gtkiconcache.h:
Update to be able to fetch pixbuf data and icon metadata.
* gtk/gtkicontheme.c: (theme_lookup_icon), (gtk_icon_info_free),
(icon_info_ensure_scale_and_pixbuf):
Use new cache functions.
* gtk/updateiconcache.c: (foreach_remove_func), (load_icon_data),
(maybe_cache_image_data), (scan_directory), (write_pixdata),
(get_image_meta_data_size), (get_image_pixel_data_size),
(get_image_data_size), (get_single_node_size), (get_bucket_size),
(write_bucket), (main):
Update to write pixbuf data as well as information from .icon
files.
2005-03-15 13:18:25 +00:00
|
|
|
|
2013-05-10 16:06:00 +00:00
|
|
|
/* TODO: We should have a load_at_scale */
|
2008-05-29 14:33:49 +00:00
|
|
|
stream = g_loadable_icon_load (icon_info->loadable,
|
2013-05-10 16:06:00 +00:00
|
|
|
scaled_desired_size,
|
2008-05-29 14:33:49 +00:00
|
|
|
NULL, NULL,
|
|
|
|
&icon_info->load_error);
|
|
|
|
if (stream)
|
|
|
|
{
|
|
|
|
source_pixbuf = gdk_pixbuf_new_from_stream (stream,
|
|
|
|
NULL,
|
|
|
|
&icon_info->load_error);
|
|
|
|
g_object_unref (stream);
|
|
|
|
}
|
2003-07-02 22:44:09 +00:00
|
|
|
}
|
|
|
|
|
2008-05-29 14:33:49 +00:00
|
|
|
if (!source_pixbuf)
|
|
|
|
return FALSE;
|
|
|
|
|
2003-07-02 22:44:09 +00:00
|
|
|
/* Do scale calculations that depend on the image size
|
|
|
|
*/
|
|
|
|
image_width = gdk_pixbuf_get_width (source_pixbuf);
|
|
|
|
image_height = gdk_pixbuf_get_height (source_pixbuf);
|
|
|
|
|
|
|
|
if (icon_info->scale < 0.0)
|
|
|
|
{
|
|
|
|
gint image_size = MAX (image_width, image_height);
|
|
|
|
if (image_size > 0)
|
2013-05-10 16:06:00 +00:00
|
|
|
icon_info->scale = (gdouble)scaled_desired_size / (gdouble)image_size;
|
2003-07-02 22:44:09 +00:00
|
|
|
else
|
|
|
|
icon_info->scale = 1.0;
|
|
|
|
|
2008-05-29 14:33:49 +00:00
|
|
|
if (icon_info->dir_type == ICON_THEME_DIR_UNTHEMED &&
|
|
|
|
!icon_info->forced_size)
|
2004-10-05 17:06:00 +00:00
|
|
|
icon_info->scale = MIN (icon_info->scale, 1.0);
|
2003-07-02 22:44:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* We don't short-circuit out here for scale_only, since, now
|
|
|
|
* we've loaded the icon, we might as well go ahead and finish
|
|
|
|
* the job. This is a bit of a waste when we scale here
|
|
|
|
* and never get the final pixbuf; at the cost of a bit of
|
|
|
|
* extra complexity, we could keep the source pixbuf around
|
2007-03-23 14:06:52 +00:00
|
|
|
* but not actually scale it until needed.
|
2003-07-02 22:44:09 +00:00
|
|
|
*/
|
|
|
|
if (icon_info->scale == 1.0)
|
|
|
|
icon_info->pixbuf = source_pixbuf;
|
|
|
|
else
|
|
|
|
{
|
|
|
|
icon_info->pixbuf = gdk_pixbuf_scale_simple (source_pixbuf,
|
|
|
|
0.5 + image_width * icon_info->scale,
|
|
|
|
0.5 + image_height * icon_info->scale,
|
|
|
|
GDK_INTERP_BILINEAR);
|
|
|
|
g_object_unref (source_pixbuf);
|
|
|
|
}
|
|
|
|
|
2008-07-28 16:15:14 +00:00
|
|
|
apply_emblems (icon_info);
|
|
|
|
|
2003-07-02 22:44:09 +00:00
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2012-11-26 12:49:49 +00:00
|
|
|
static void
|
|
|
|
proxy_pixbuf_destroy (guchar *pixels, gpointer data)
|
|
|
|
{
|
|
|
|
GtkIconInfo *icon_info = data;
|
|
|
|
GtkIconTheme *icon_theme = icon_info->in_cache;
|
|
|
|
|
|
|
|
g_assert (icon_info->proxy_pixbuf != NULL);
|
|
|
|
icon_info->proxy_pixbuf = NULL;
|
|
|
|
|
|
|
|
/* Keep it alive a bit longer */
|
|
|
|
if (icon_theme != NULL)
|
|
|
|
ensure_in_lru_cache (icon_theme, icon_info);
|
|
|
|
|
2013-02-16 00:35:44 +00:00
|
|
|
g_object_unref (icon_info);
|
2012-11-26 12:49:49 +00:00
|
|
|
}
|
|
|
|
|
2003-07-02 22:44:09 +00:00
|
|
|
/**
|
|
|
|
* gtk_icon_info_load_icon:
|
2014-01-27 22:04:46 +00:00
|
|
|
* @icon_info: a #GtkIconInfo from gtk_icon_theme_lookup_icon()
|
2010-09-21 04:18:11 +00:00
|
|
|
* @error: (allow-none): location to store error information on failure,
|
|
|
|
* or %NULL.
|
|
|
|
*
|
2003-07-02 22:44:09 +00:00
|
|
|
* Renders an icon previously looked up in an icon theme using
|
|
|
|
* gtk_icon_theme_lookup_icon(); the size will be based on the size
|
2004-07-17 03:55:07 +00:00
|
|
|
* passed to gtk_icon_theme_lookup_icon(). Note that the resulting
|
2003-07-02 22:44:09 +00:00
|
|
|
* 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
|
2004-10-05 03:18:22 +00:00
|
|
|
* requested size or for which the source image would have to be scaled
|
2008-05-29 14:33:49 +00:00
|
|
|
* up too far. (This maintains sharpness.). This behaviour can be changed
|
|
|
|
* by passing the %GTK_ICON_LOOKUP_FORCE_SIZE flag when obtaining
|
|
|
|
* the #GtkIconInfo. If this flag has been specified, the pixbuf
|
2010-09-21 04:18:11 +00:00
|
|
|
* returned by this function will be scaled to the exact size.
|
|
|
|
*
|
|
|
|
* Return value: (transfer full): the rendered icon; this may be a newly
|
|
|
|
* created icon or a new reference to an internal icon, so you must
|
|
|
|
* not modify the icon. Use g_object_unref() to release your reference
|
|
|
|
* to the icon.
|
2003-11-08 00:51:10 +00:00
|
|
|
*
|
|
|
|
* Since: 2.4
|
2003-07-02 22:44:09 +00:00
|
|
|
**/
|
|
|
|
GdkPixbuf *
|
|
|
|
gtk_icon_info_load_icon (GtkIconInfo *icon_info,
|
|
|
|
GError **error)
|
|
|
|
{
|
|
|
|
g_return_val_if_fail (icon_info != NULL, NULL);
|
|
|
|
g_return_val_if_fail (error == NULL || *error == NULL, NULL);
|
|
|
|
|
2007-05-25 15:31:28 +00:00
|
|
|
if (!icon_info_ensure_scale_and_pixbuf (icon_info, FALSE))
|
2003-07-02 22:44:09 +00:00
|
|
|
{
|
2007-05-25 15:31:28 +00:00
|
|
|
if (icon_info->load_error)
|
2013-10-15 12:04:25 +00:00
|
|
|
{
|
2013-10-16 01:29:06 +00:00
|
|
|
if (error)
|
2013-10-15 12:04:25 +00:00
|
|
|
*error = g_error_copy (icon_info->load_error);
|
|
|
|
}
|
2007-05-25 15:31:28 +00:00
|
|
|
else
|
2013-10-15 12:04:25 +00:00
|
|
|
{
|
|
|
|
g_set_error_literal (error,
|
|
|
|
GTK_ICON_THEME_ERROR,
|
|
|
|
GTK_ICON_THEME_NOT_FOUND,
|
|
|
|
_("Failed to load icon"));
|
|
|
|
}
|
2007-05-25 15:31:28 +00:00
|
|
|
|
2007-07-18 07:30:34 +00:00
|
|
|
return NULL;
|
2003-07-02 22:44:09 +00:00
|
|
|
}
|
|
|
|
|
2012-11-26 12:49:49 +00:00
|
|
|
/* Instead of returning the pixbuf directly we
|
|
|
|
return a proxy to it that we don't own (but that
|
|
|
|
shares the data with the one we own). This way
|
|
|
|
we can know when it is freed and ensure the
|
|
|
|
IconInfo is alive (and thus cached) while
|
|
|
|
the pixbuf is still alive. */
|
|
|
|
|
|
|
|
if (icon_info->proxy_pixbuf != NULL)
|
|
|
|
return g_object_ref (icon_info->proxy_pixbuf);
|
|
|
|
|
|
|
|
icon_info->proxy_pixbuf =
|
|
|
|
gdk_pixbuf_new_from_data (gdk_pixbuf_get_pixels (icon_info->pixbuf),
|
|
|
|
gdk_pixbuf_get_colorspace (icon_info->pixbuf),
|
|
|
|
gdk_pixbuf_get_has_alpha (icon_info->pixbuf),
|
|
|
|
gdk_pixbuf_get_bits_per_sample (icon_info->pixbuf),
|
|
|
|
gdk_pixbuf_get_width (icon_info->pixbuf),
|
|
|
|
gdk_pixbuf_get_height (icon_info->pixbuf),
|
|
|
|
gdk_pixbuf_get_rowstride (icon_info->pixbuf),
|
|
|
|
proxy_pixbuf_destroy,
|
2013-02-16 00:35:44 +00:00
|
|
|
g_object_ref (icon_info));
|
2012-11-26 12:49:49 +00:00
|
|
|
|
|
|
|
return icon_info->proxy_pixbuf;
|
2003-07-02 22:44:09 +00:00
|
|
|
}
|
|
|
|
|
2013-06-26 14:26:43 +00:00
|
|
|
/**
|
|
|
|
* gtk_icon_info_load_surface:
|
2014-01-27 22:04:46 +00:00
|
|
|
* @icon_info: a #GtkIconInfo from gtk_icon_theme_lookup_icon()
|
2013-06-26 14:26:43 +00:00
|
|
|
* @for_window: (allow-none): #GdkWindow to optimize drawing for, or %NULL
|
|
|
|
* @error: (allow-none): 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
|
|
|
|
* passed to gtk_icon_theme_lookup_icon(). Note that the resulting
|
|
|
|
* surface 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 or for which the source image would have to be scaled
|
|
|
|
* up too far. (This maintains sharpness.). This behaviour can be changed
|
|
|
|
* by passing the %GTK_ICON_LOOKUP_FORCE_SIZE flag when obtaining
|
|
|
|
* the #GtkIconInfo. If this flag has been specified, the pixbuf
|
|
|
|
* returned by this function will be scaled to the exact size.
|
|
|
|
*
|
|
|
|
* Return value: (transfer full): the rendered icon; this may be a newly
|
|
|
|
* created icon or a new reference to an internal icon, so you must
|
|
|
|
* not modify the icon. Use cairo_surface_destroy() to release your reference
|
|
|
|
* to the icon.
|
|
|
|
*
|
|
|
|
* Since: 3.10
|
|
|
|
**/
|
|
|
|
cairo_surface_t *
|
|
|
|
gtk_icon_info_load_surface (GtkIconInfo *icon_info,
|
|
|
|
GdkWindow *for_window,
|
|
|
|
GError **error)
|
|
|
|
{
|
|
|
|
GdkPixbuf *pixbuf;
|
|
|
|
cairo_surface_t *surface;
|
|
|
|
|
|
|
|
g_return_val_if_fail (icon_info != NULL, NULL);
|
|
|
|
g_return_val_if_fail (error == NULL || *error == NULL, NULL);
|
|
|
|
|
|
|
|
pixbuf = gtk_icon_info_load_icon (icon_info, error);
|
|
|
|
|
|
|
|
if (pixbuf == NULL)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
surface = gdk_cairo_surface_create_from_pixbuf (pixbuf, icon_info->desired_scale, for_window);
|
|
|
|
g_object_unref (pixbuf);
|
|
|
|
|
|
|
|
return surface;
|
|
|
|
}
|
|
|
|
|
2013-02-14 12:32:30 +00:00
|
|
|
static void
|
|
|
|
load_icon_thread (GTask *task,
|
|
|
|
gpointer source_object,
|
|
|
|
gpointer task_data,
|
|
|
|
GCancellable *cancellable)
|
|
|
|
{
|
|
|
|
GtkIconInfo *dup = task_data;
|
|
|
|
|
|
|
|
icon_info_ensure_scale_and_pixbuf (dup, FALSE);
|
|
|
|
g_task_return_pointer (task, NULL, NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* gtk_icon_info_load_icon_async:
|
2014-01-27 22:04:46 +00:00
|
|
|
* @icon_info: a #GtkIconInfo from gtk_icon_theme_lookup_icon()
|
2013-02-14 12:32:30 +00:00
|
|
|
* @cancellable: (allow-none): optional #GCancellable object,
|
|
|
|
* %NULL to ignore
|
|
|
|
* @callback: (scope async): a #GAsyncReadyCallback to call when the
|
|
|
|
* request is satisfied
|
|
|
|
* @user_data: (closure): the data to pass to callback function
|
|
|
|
*
|
|
|
|
* Asynchronously load, render and scale an icon previously looked up
|
|
|
|
* from the icon theme using gtk_icon_theme_lookup_icon().
|
|
|
|
*
|
|
|
|
* For more details, see gtk_icon_info_load_icon() which is the synchronous
|
|
|
|
* version of this call.
|
|
|
|
*
|
|
|
|
* Since: 3.8
|
|
|
|
**/
|
|
|
|
void
|
|
|
|
gtk_icon_info_load_icon_async (GtkIconInfo *icon_info,
|
|
|
|
GCancellable *cancellable,
|
|
|
|
GAsyncReadyCallback callback,
|
|
|
|
gpointer user_data)
|
|
|
|
{
|
|
|
|
GTask *task;
|
|
|
|
GdkPixbuf *pixbuf;
|
|
|
|
GtkIconInfo *dup;
|
|
|
|
GError *error = NULL;
|
|
|
|
|
|
|
|
task = g_task_new (icon_info, cancellable, callback, user_data);
|
|
|
|
|
|
|
|
if (icon_info_get_pixbuf_ready (icon_info))
|
|
|
|
{
|
|
|
|
pixbuf = gtk_icon_info_load_icon (icon_info, &error);
|
|
|
|
if (pixbuf == NULL)
|
|
|
|
g_task_return_error (task, error);
|
|
|
|
else
|
|
|
|
g_task_return_pointer (task, pixbuf, g_object_unref);
|
|
|
|
g_object_unref (task);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
dup = icon_info_dup (icon_info);
|
|
|
|
g_task_set_task_data (task, dup, g_object_unref);
|
|
|
|
g_task_run_in_thread (task, load_icon_thread);
|
|
|
|
g_object_unref (task);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* gtk_icon_info_load_icon_finish:
|
2014-01-27 22:04:46 +00:00
|
|
|
* @icon_info: a #GtkIconInfo from gtk_icon_theme_lookup_icon()
|
2013-02-14 12:32:30 +00:00
|
|
|
* @res: a #GAsyncResult
|
|
|
|
* @error: (allow-none): location to store error information on failure,
|
|
|
|
* or %NULL.
|
|
|
|
*
|
|
|
|
* Finishes an async icon load, see gtk_icon_info_load_icon_async().
|
|
|
|
*
|
|
|
|
* Return value: (transfer full): the rendered icon; this may be a newly
|
|
|
|
* created icon or a new reference to an internal icon, so you must
|
|
|
|
* not modify the icon. Use g_object_unref() to release your reference
|
|
|
|
* to the icon.
|
|
|
|
*
|
|
|
|
* Since: 3.8
|
|
|
|
**/
|
|
|
|
GdkPixbuf *
|
|
|
|
gtk_icon_info_load_icon_finish (GtkIconInfo *icon_info,
|
|
|
|
GAsyncResult *result,
|
|
|
|
GError **error)
|
|
|
|
{
|
|
|
|
GTask *task = G_TASK (result);
|
|
|
|
GtkIconInfo *dup;
|
|
|
|
|
|
|
|
g_return_val_if_fail (g_task_is_valid (result, icon_info), NULL);
|
|
|
|
|
|
|
|
dup = g_task_get_task_data (task);
|
|
|
|
if (dup == NULL || g_task_had_error (task))
|
|
|
|
return g_task_propagate_pointer (task, error);
|
|
|
|
|
|
|
|
/* We ran the thread and it was not cancelled */
|
|
|
|
|
|
|
|
/* Check if someone else updated the icon_info in between */
|
|
|
|
if (!icon_info_get_pixbuf_ready (icon_info))
|
|
|
|
{
|
|
|
|
/* If not, copy results from dup back to icon_info */
|
|
|
|
|
|
|
|
icon_info->emblems_applied = dup->emblems_applied;
|
|
|
|
icon_info->scale = dup->scale;
|
|
|
|
g_clear_object (&icon_info->pixbuf);
|
|
|
|
if (dup->pixbuf)
|
|
|
|
icon_info->pixbuf = g_object_ref (dup->pixbuf);
|
|
|
|
g_clear_error (&icon_info->load_error);
|
|
|
|
if (dup->load_error)
|
|
|
|
icon_info->load_error = g_error_copy (dup->load_error);
|
|
|
|
}
|
|
|
|
|
|
|
|
g_assert (icon_info_get_pixbuf_ready (icon_info));
|
|
|
|
|
|
|
|
/* This is now guaranteed to not block */
|
|
|
|
return gtk_icon_info_load_icon (icon_info, error);
|
|
|
|
}
|
|
|
|
|
2010-04-26 10:55:34 +00:00
|
|
|
static gchar *
|
|
|
|
gdk_color_to_css (GdkColor *color)
|
|
|
|
{
|
|
|
|
return g_strdup_printf ("rgb(%d,%d,%d)",
|
|
|
|
color->red >> 8,
|
|
|
|
color->green >> 8,
|
|
|
|
color->blue >> 8);
|
|
|
|
}
|
|
|
|
|
2012-11-26 12:52:05 +00:00
|
|
|
static void
|
|
|
|
proxy_symbolic_pixbuf_destroy (guchar *pixels, gpointer data)
|
|
|
|
{
|
|
|
|
GtkIconInfo *icon_info = data;
|
|
|
|
GtkIconTheme *icon_theme = icon_info->in_cache;
|
|
|
|
SymbolicPixbufCache *symbolic_cache;
|
|
|
|
|
|
|
|
for (symbolic_cache = icon_info->symbolic_pixbuf_cache;
|
|
|
|
symbolic_cache != NULL;
|
|
|
|
symbolic_cache = symbolic_cache->next)
|
|
|
|
{
|
|
|
|
if (symbolic_cache->proxy_pixbuf != NULL &&
|
|
|
|
gdk_pixbuf_get_pixels (symbolic_cache->proxy_pixbuf) == pixels)
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
g_assert (symbolic_cache != NULL);
|
|
|
|
g_assert (symbolic_cache->proxy_pixbuf != NULL);
|
|
|
|
|
|
|
|
symbolic_cache->proxy_pixbuf = NULL;
|
|
|
|
|
|
|
|
/* Keep it alive a bit longer */
|
|
|
|
if (icon_theme != NULL)
|
|
|
|
ensure_in_lru_cache (icon_theme, icon_info);
|
|
|
|
|
2013-02-16 00:35:44 +00:00
|
|
|
g_object_unref (icon_info);
|
2012-11-26 12:52:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static GdkPixbuf *
|
|
|
|
symbolic_cache_get_proxy (SymbolicPixbufCache *symbolic_cache,
|
|
|
|
GtkIconInfo *icon_info)
|
|
|
|
{
|
|
|
|
if (symbolic_cache->proxy_pixbuf)
|
|
|
|
return g_object_ref (symbolic_cache->proxy_pixbuf);
|
|
|
|
|
|
|
|
symbolic_cache->proxy_pixbuf =
|
|
|
|
gdk_pixbuf_new_from_data (gdk_pixbuf_get_pixels (symbolic_cache->pixbuf),
|
|
|
|
gdk_pixbuf_get_colorspace (symbolic_cache->pixbuf),
|
|
|
|
gdk_pixbuf_get_has_alpha (symbolic_cache->pixbuf),
|
|
|
|
gdk_pixbuf_get_bits_per_sample (symbolic_cache->pixbuf),
|
|
|
|
gdk_pixbuf_get_width (symbolic_cache->pixbuf),
|
|
|
|
gdk_pixbuf_get_height (symbolic_cache->pixbuf),
|
|
|
|
gdk_pixbuf_get_rowstride (symbolic_cache->pixbuf),
|
|
|
|
proxy_symbolic_pixbuf_destroy,
|
2013-02-16 00:35:44 +00:00
|
|
|
g_object_ref (icon_info));
|
2012-11-26 12:52:05 +00:00
|
|
|
|
|
|
|
return symbolic_cache->proxy_pixbuf;
|
|
|
|
}
|
|
|
|
|
2010-10-22 12:21:34 +00:00
|
|
|
static GdkPixbuf *
|
|
|
|
_gtk_icon_info_load_symbolic_internal (GtkIconInfo *icon_info,
|
2012-11-26 12:52:05 +00:00
|
|
|
const GdkRGBA *fg,
|
|
|
|
const GdkRGBA *success_color,
|
|
|
|
const GdkRGBA *warning_color,
|
|
|
|
const GdkRGBA *error_color,
|
2013-02-14 15:01:04 +00:00
|
|
|
gboolean use_cache,
|
|
|
|
GError **error)
|
2010-10-22 12:21:34 +00:00
|
|
|
{
|
|
|
|
GInputStream *stream;
|
|
|
|
GdkPixbuf *pixbuf;
|
2012-11-26 12:52:05 +00:00
|
|
|
gchar *css_fg;
|
|
|
|
gchar *css_success;
|
|
|
|
gchar *css_warning;
|
|
|
|
gchar *css_error;
|
2010-10-22 12:21:34 +00:00
|
|
|
gchar *data;
|
2013-08-16 22:57:21 +00:00
|
|
|
gchar *width, *height;
|
|
|
|
gchar *file_data, *escaped_file_data;
|
|
|
|
gsize file_len;
|
2012-11-26 12:52:05 +00:00
|
|
|
SymbolicPixbufCache *symbolic_cache;
|
|
|
|
|
2013-02-14 15:01:04 +00:00
|
|
|
if (use_cache)
|
|
|
|
{
|
|
|
|
symbolic_cache = symbolic_pixbuf_cache_matches (icon_info->symbolic_pixbuf_cache,
|
|
|
|
fg, success_color, warning_color, error_color);
|
|
|
|
if (symbolic_cache)
|
|
|
|
return symbolic_cache_get_proxy (symbolic_cache, icon_info);
|
|
|
|
}
|
2010-10-27 16:47:08 +00:00
|
|
|
|
|
|
|
/* css_fg can't possibly have failed, otherwise
|
|
|
|
* that would mean we have a broken style */
|
2012-11-26 12:52:05 +00:00
|
|
|
g_return_val_if_fail (fg != NULL, NULL);
|
2010-10-27 16:47:08 +00:00
|
|
|
|
2013-10-05 19:31:33 +00:00
|
|
|
css_fg = gdk_rgba_to_string (fg);
|
2012-11-26 12:52:05 +00:00
|
|
|
|
|
|
|
css_success = css_warning = css_error = NULL;
|
|
|
|
|
|
|
|
if (warning_color)
|
2013-10-05 19:31:33 +00:00
|
|
|
css_warning = gdk_rgba_to_string (warning_color);
|
2012-11-26 12:52:05 +00:00
|
|
|
|
|
|
|
if (error_color)
|
2013-10-05 19:31:33 +00:00
|
|
|
css_error = gdk_rgba_to_string (error_color);
|
2012-11-26 12:52:05 +00:00
|
|
|
|
|
|
|
if (success_color)
|
2013-10-05 19:31:33 +00:00
|
|
|
css_success = gdk_rgba_to_string (success_color);
|
2010-10-27 16:47:08 +00:00
|
|
|
|
|
|
|
if (!css_success)
|
|
|
|
{
|
|
|
|
GdkColor success_default_color = { 0, 0x4e00, 0x9a00, 0x0600 };
|
2012-11-26 12:52:05 +00:00
|
|
|
css_success = gdk_color_to_css (&success_default_color);
|
2010-10-27 16:47:08 +00:00
|
|
|
}
|
|
|
|
if (!css_warning)
|
|
|
|
{
|
|
|
|
GdkColor warning_default_color = { 0, 0xf500, 0x7900, 0x3e00 };
|
2012-11-26 12:52:05 +00:00
|
|
|
css_warning = gdk_color_to_css (&warning_default_color);
|
2010-10-27 16:47:08 +00:00
|
|
|
}
|
|
|
|
if (!css_error)
|
|
|
|
{
|
|
|
|
GdkColor error_default_color = { 0, 0xcc00, 0x0000, 0x0000 };
|
2012-11-26 12:52:05 +00:00
|
|
|
css_error = gdk_color_to_css (&error_default_color);
|
2010-10-27 16:47:08 +00:00
|
|
|
}
|
|
|
|
|
2013-10-16 00:00:57 +00:00
|
|
|
if (!g_file_load_contents (icon_info->icon_file, NULL, &file_data, &file_len, NULL, error))
|
2013-08-16 22:57:21 +00:00
|
|
|
return NULL;
|
|
|
|
|
2012-06-06 16:16:05 +00:00
|
|
|
if (!icon_info->symbolic_pixbuf_size)
|
|
|
|
{
|
|
|
|
/* Fetch size from the original icon */
|
2013-08-16 22:57:21 +00:00
|
|
|
stream = g_memory_input_stream_new_from_data (file_data, file_len, NULL);
|
2012-10-28 19:01:30 +00:00
|
|
|
pixbuf = gdk_pixbuf_new_from_stream (stream, NULL, error);
|
|
|
|
g_object_unref (stream);
|
2012-06-06 16:16:05 +00:00
|
|
|
|
|
|
|
if (!pixbuf)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
icon_info->symbolic_pixbuf_size = gtk_requisition_new ();
|
|
|
|
icon_info->symbolic_pixbuf_size->width = gdk_pixbuf_get_width (pixbuf);
|
|
|
|
icon_info->symbolic_pixbuf_size->height = gdk_pixbuf_get_height (pixbuf);
|
|
|
|
g_object_unref (pixbuf);
|
|
|
|
}
|
|
|
|
|
|
|
|
width = g_strdup_printf ("%d", icon_info->symbolic_pixbuf_size->width);
|
|
|
|
height = g_strdup_printf ("%d", icon_info->symbolic_pixbuf_size->height);
|
2013-08-16 22:57:21 +00:00
|
|
|
|
|
|
|
escaped_file_data = g_markup_escape_text (file_data, file_len);
|
|
|
|
g_free (file_data);
|
2010-10-22 12:21:34 +00:00
|
|
|
|
|
|
|
data = g_strconcat ("<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"no\"?>\n"
|
|
|
|
"<svg version=\"1.1\"\n"
|
|
|
|
" xmlns=\"http://www.w3.org/2000/svg\"\n"
|
|
|
|
" xmlns:xi=\"http://www.w3.org/2001/XInclude\"\n"
|
2012-06-06 16:16:05 +00:00
|
|
|
" width=\"", width, "\"\n"
|
|
|
|
" height=\"", height, "\">\n"
|
2010-10-22 12:21:34 +00:00
|
|
|
" <style type=\"text/css\">\n"
|
|
|
|
" rect,path {\n"
|
|
|
|
" fill: ", css_fg," !important;\n"
|
|
|
|
" }\n"
|
|
|
|
" .warning {\n"
|
2012-11-26 12:52:05 +00:00
|
|
|
" fill: ", css_warning, " !important;\n"
|
2010-10-22 12:21:34 +00:00
|
|
|
" }\n"
|
|
|
|
" .error {\n"
|
2012-11-26 12:52:05 +00:00
|
|
|
" fill: ", css_error ," !important;\n"
|
2010-10-22 12:21:34 +00:00
|
|
|
" }\n"
|
|
|
|
" .success {\n"
|
2012-11-26 12:52:05 +00:00
|
|
|
" fill: ", css_success, " !important;\n"
|
2010-10-22 12:21:34 +00:00
|
|
|
" }\n"
|
|
|
|
" </style>\n"
|
2013-08-16 22:57:21 +00:00
|
|
|
" <xi:include href=\"data:text/xml,", escaped_file_data, "\"/>\n"
|
2010-10-22 12:21:34 +00:00
|
|
|
"</svg>",
|
|
|
|
NULL);
|
2013-08-16 22:57:21 +00:00
|
|
|
g_free (escaped_file_data);
|
2012-11-26 12:52:05 +00:00
|
|
|
g_free (css_fg);
|
|
|
|
g_free (css_warning);
|
|
|
|
g_free (css_error);
|
|
|
|
g_free (css_success);
|
2012-06-06 16:16:05 +00:00
|
|
|
g_free (width);
|
|
|
|
g_free (height);
|
2010-10-22 12:21:34 +00:00
|
|
|
|
|
|
|
stream = g_memory_input_stream_new_from_data (data, -1, g_free);
|
|
|
|
pixbuf = gdk_pixbuf_new_from_stream_at_scale (stream,
|
2013-05-10 16:06:00 +00:00
|
|
|
icon_info->desired_size * icon_info->desired_scale,
|
|
|
|
icon_info->desired_size * icon_info->desired_scale,
|
2010-10-22 12:21:34 +00:00
|
|
|
TRUE,
|
|
|
|
NULL,
|
|
|
|
error);
|
|
|
|
g_object_unref (stream);
|
|
|
|
|
2012-11-26 12:52:05 +00:00
|
|
|
if (pixbuf != NULL)
|
|
|
|
{
|
2013-02-14 15:01:04 +00:00
|
|
|
if (use_cache)
|
|
|
|
{
|
|
|
|
icon_info->symbolic_pixbuf_cache =
|
|
|
|
symbolic_pixbuf_cache_new (pixbuf, fg, success_color, warning_color, error_color,
|
|
|
|
icon_info->symbolic_pixbuf_cache);
|
|
|
|
g_object_unref (pixbuf);
|
|
|
|
return symbolic_cache_get_proxy (icon_info->symbolic_pixbuf_cache, icon_info);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
return pixbuf;
|
2012-11-26 12:52:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return NULL;
|
2010-10-22 12:21:34 +00:00
|
|
|
}
|
|
|
|
|
2010-04-26 10:55:34 +00:00
|
|
|
/**
|
|
|
|
* gtk_icon_info_load_symbolic:
|
2010-05-25 13:47:20 +00:00
|
|
|
* @icon_info: a #GtkIconInfo
|
2010-10-22 12:21:34 +00:00
|
|
|
* @fg: a #GdkRGBA representing the foreground color of the icon
|
|
|
|
* @success_color: (allow-none): a #GdkRGBA representing the warning color
|
2010-05-01 03:33:59 +00:00
|
|
|
* of the icon or %NULL to use the default color
|
2010-10-22 12:21:34 +00:00
|
|
|
* @warning_color: (allow-none): a #GdkRGBA representing the warning color
|
2010-05-01 03:33:59 +00:00
|
|
|
* of the icon or %NULL to use the default color
|
2010-10-22 12:21:34 +00:00
|
|
|
* @error_color: (allow-none): a #GdkRGBA representing the error color
|
2010-05-01 03:33:59 +00:00
|
|
|
* of the icon or %NULL to use the default color (allow-none)
|
2011-01-18 09:10:30 +00:00
|
|
|
* @was_symbolic: (out) (allow-none): a #gboolean, returns whether the
|
|
|
|
* loaded icon was a symbolic one and whether the @fg color was
|
|
|
|
* applied to it.
|
2010-05-01 03:33:59 +00:00
|
|
|
* @error: (allow-none): location to store error information on failure,
|
|
|
|
* or %NULL.
|
2010-04-26 10:55:34 +00:00
|
|
|
*
|
|
|
|
* Loads an icon, modifying it to match the system colours for the foreground,
|
2010-05-01 03:33:59 +00:00
|
|
|
* success, warning and error colors provided. If the icon is not a symbolic
|
|
|
|
* one, the function will return the result from gtk_icon_info_load_icon().
|
2010-04-26 10:55:34 +00:00
|
|
|
*
|
|
|
|
* This allows loading symbolic icons that will match the system theme.
|
|
|
|
*
|
|
|
|
* Unless you are implementing a widget, you will want to use
|
|
|
|
* g_themed_icon_new_with_default_fallbacks() to load the icon.
|
|
|
|
*
|
|
|
|
* As implementation details, the icon loaded needs to be of SVG type,
|
2010-05-01 03:33:59 +00:00
|
|
|
* contain the "symbolic" term as the last component of the icon name,
|
|
|
|
* and use the 'fg', 'success', 'warning' and 'error' CSS styles in the
|
|
|
|
* SVG file itself.
|
|
|
|
*
|
2010-04-28 16:40:29 +00:00
|
|
|
* See the <ulink url="http://www.freedesktop.org/wiki/SymbolicIcons">Symbolic Icons spec</ulink>
|
2010-04-26 10:55:34 +00:00
|
|
|
* for more information about symbolic icons.
|
|
|
|
*
|
2010-09-21 04:18:11 +00:00
|
|
|
* Return value: (transfer full): a #GdkPixbuf representing the loaded icon
|
2010-04-26 10:55:34 +00:00
|
|
|
*
|
2010-05-01 03:33:59 +00:00
|
|
|
* Since: 3.0
|
2010-04-26 10:55:34 +00:00
|
|
|
**/
|
|
|
|
GdkPixbuf *
|
2011-02-10 12:58:07 +00:00
|
|
|
gtk_icon_info_load_symbolic (GtkIconInfo *icon_info,
|
|
|
|
const GdkRGBA *fg,
|
|
|
|
const GdkRGBA *success_color,
|
|
|
|
const GdkRGBA *warning_color,
|
|
|
|
const GdkRGBA *error_color,
|
|
|
|
gboolean *was_symbolic,
|
|
|
|
GError **error)
|
2010-04-26 10:55:34 +00:00
|
|
|
{
|
2012-10-28 19:01:30 +00:00
|
|
|
gboolean is_symbolic;
|
2010-04-26 10:55:34 +00:00
|
|
|
|
2012-11-09 10:55:44 +00:00
|
|
|
g_return_val_if_fail (icon_info != NULL, NULL);
|
2010-04-26 10:55:34 +00:00
|
|
|
g_return_val_if_fail (fg != NULL, NULL);
|
|
|
|
|
2013-12-15 02:41:49 +00:00
|
|
|
is_symbolic = gtk_icon_info_is_symbolic (icon_info);
|
2010-04-26 10:55:34 +00:00
|
|
|
|
|
|
|
if (was_symbolic)
|
2012-10-28 19:01:30 +00:00
|
|
|
*was_symbolic = is_symbolic;
|
|
|
|
|
|
|
|
if (!is_symbolic)
|
|
|
|
return gtk_icon_info_load_icon (icon_info, error);
|
2010-04-26 10:55:34 +00:00
|
|
|
|
2012-11-26 12:52:05 +00:00
|
|
|
return _gtk_icon_info_load_symbolic_internal (icon_info,
|
|
|
|
fg, success_color,
|
|
|
|
warning_color, error_color,
|
2013-02-14 15:01:04 +00:00
|
|
|
TRUE,
|
2012-11-26 12:52:05 +00:00
|
|
|
error);
|
2010-04-26 10:55:34 +00:00
|
|
|
}
|
|
|
|
|
2010-11-24 19:40:31 +00:00
|
|
|
/**
|
|
|
|
* gtk_icon_info_load_symbolic_for_context:
|
|
|
|
* @icon_info: a #GtkIconInfo
|
2010-12-17 19:51:53 +00:00
|
|
|
* @context: a #GtkStyleContext
|
2011-01-18 09:10:30 +00:00
|
|
|
* @was_symbolic: (out) (allow-none): a #gboolean, returns whether the
|
|
|
|
* loaded icon was a symbolic one and whether the @fg color was
|
|
|
|
* applied to it.
|
2010-11-24 19:40:31 +00:00
|
|
|
* @error: (allow-none): location to store error information on failure,
|
|
|
|
* or %NULL.
|
|
|
|
*
|
|
|
|
* Loads an icon, modifying it to match the system colors for the foreground,
|
|
|
|
* success, warning and error colors provided. If the icon is not a symbolic
|
|
|
|
* one, the function will return the result from gtk_icon_info_load_icon().
|
2011-01-14 02:37:33 +00:00
|
|
|
* This function uses the regular foreground color and the symbolic colors
|
|
|
|
* with the names "success_color", "warning_color" and "error_color" from
|
|
|
|
* the context.
|
2010-11-24 19:40:31 +00:00
|
|
|
*
|
|
|
|
* This allows loading symbolic icons that will match the system theme.
|
|
|
|
*
|
|
|
|
* See gtk_icon_info_load_symbolic() for more details.
|
|
|
|
*
|
|
|
|
* Return value: (transfer full): a #GdkPixbuf representing the loaded icon
|
|
|
|
*
|
|
|
|
* Since: 3.0
|
|
|
|
**/
|
|
|
|
GdkPixbuf *
|
|
|
|
gtk_icon_info_load_symbolic_for_context (GtkIconInfo *icon_info,
|
|
|
|
GtkStyleContext *context,
|
|
|
|
gboolean *was_symbolic,
|
|
|
|
GError **error)
|
|
|
|
{
|
2010-11-25 00:57:10 +00:00
|
|
|
GdkRGBA *color = NULL;
|
2012-11-26 12:52:05 +00:00
|
|
|
GdkRGBA fg;
|
|
|
|
GdkRGBA *fgp;
|
|
|
|
GdkRGBA success_color;
|
|
|
|
GdkRGBA *success_colorp;
|
|
|
|
GdkRGBA warning_color;
|
|
|
|
GdkRGBA *warning_colorp;
|
|
|
|
GdkRGBA error_color;
|
|
|
|
GdkRGBA *error_colorp;
|
2010-11-25 02:28:42 +00:00
|
|
|
GtkStateFlags state;
|
2012-10-28 19:01:30 +00:00
|
|
|
gboolean is_symbolic;
|
2010-11-24 19:40:31 +00:00
|
|
|
|
2012-11-09 10:55:44 +00:00
|
|
|
g_return_val_if_fail (icon_info != NULL, NULL);
|
|
|
|
g_return_val_if_fail (context != NULL, NULL);
|
|
|
|
|
2013-12-15 02:41:49 +00:00
|
|
|
is_symbolic = gtk_icon_info_is_symbolic (icon_info);
|
2010-11-24 19:40:31 +00:00
|
|
|
|
|
|
|
if (was_symbolic)
|
2012-10-28 19:01:30 +00:00
|
|
|
*was_symbolic = is_symbolic;
|
|
|
|
|
|
|
|
if (!is_symbolic)
|
|
|
|
return gtk_icon_info_load_icon (icon_info, error);
|
2010-11-24 19:40:31 +00:00
|
|
|
|
2012-11-26 12:52:05 +00:00
|
|
|
fgp = success_colorp = warning_colorp = error_colorp = NULL;
|
|
|
|
|
2010-11-25 02:28:42 +00:00
|
|
|
state = gtk_style_context_get_state (context);
|
|
|
|
gtk_style_context_get (context, state, "color", &color, NULL);
|
|
|
|
if (color)
|
2010-11-24 19:40:31 +00:00
|
|
|
{
|
2012-11-26 12:52:05 +00:00
|
|
|
fg = *color;
|
|
|
|
fgp = &fg;
|
2010-11-24 19:40:31 +00:00
|
|
|
gdk_rgba_free (color);
|
|
|
|
}
|
|
|
|
|
2012-11-26 12:52:05 +00:00
|
|
|
if (gtk_style_context_lookup_color (context, "success_color", &success_color))
|
|
|
|
success_colorp = &success_color;
|
2010-11-24 19:40:31 +00:00
|
|
|
|
2012-11-26 12:52:05 +00:00
|
|
|
if (gtk_style_context_lookup_color (context, "warning_color", &warning_color))
|
|
|
|
warning_colorp = &warning_color;
|
2010-11-24 19:40:31 +00:00
|
|
|
|
2012-11-26 12:52:05 +00:00
|
|
|
if (gtk_style_context_lookup_color (context, "error_color", &error_color))
|
|
|
|
error_colorp = &error_color;
|
2010-11-24 19:40:31 +00:00
|
|
|
|
2012-11-26 12:52:05 +00:00
|
|
|
return _gtk_icon_info_load_symbolic_internal (icon_info,
|
|
|
|
fgp, success_colorp,
|
|
|
|
warning_colorp, error_colorp,
|
2013-02-14 15:01:04 +00:00
|
|
|
TRUE,
|
2012-11-26 12:52:05 +00:00
|
|
|
error);
|
|
|
|
}
|
2010-11-24 19:40:31 +00:00
|
|
|
|
2013-02-14 15:01:04 +00:00
|
|
|
typedef struct {
|
|
|
|
gboolean is_symbolic;
|
|
|
|
GtkIconInfo *dup;
|
|
|
|
GdkRGBA fg;
|
|
|
|
gboolean fg_set;
|
|
|
|
GdkRGBA success_color;
|
|
|
|
gboolean success_color_set;
|
|
|
|
GdkRGBA warning_color;
|
|
|
|
gboolean warning_color_set;
|
|
|
|
GdkRGBA error_color;
|
|
|
|
gboolean error_color_set;
|
|
|
|
} AsyncSymbolicData;
|
|
|
|
|
|
|
|
static void
|
|
|
|
async_symbolic_data_free (AsyncSymbolicData *data)
|
|
|
|
{
|
|
|
|
if (data->dup)
|
|
|
|
g_object_unref (data->dup);
|
|
|
|
g_slice_free (AsyncSymbolicData, data);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
async_load_no_symbolic_cb (GObject *source_object,
|
|
|
|
GAsyncResult *res,
|
|
|
|
gpointer user_data)
|
|
|
|
{
|
|
|
|
GtkIconInfo *icon_info = GTK_ICON_INFO (source_object);
|
|
|
|
GTask *task = user_data;
|
|
|
|
GError *error = NULL;
|
|
|
|
GdkPixbuf *pixbuf;
|
|
|
|
|
|
|
|
pixbuf = gtk_icon_info_load_icon_finish (icon_info, res, &error);
|
|
|
|
if (pixbuf == NULL)
|
|
|
|
g_task_return_error (task, error);
|
|
|
|
else
|
|
|
|
g_task_return_pointer (task, pixbuf, g_object_unref);
|
|
|
|
g_object_unref (task);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
load_symbolic_icon_thread (GTask *task,
|
|
|
|
gpointer source_object,
|
|
|
|
gpointer task_data,
|
|
|
|
GCancellable *cancellable)
|
|
|
|
{
|
|
|
|
AsyncSymbolicData *data = task_data;
|
|
|
|
GError *error;
|
|
|
|
GdkPixbuf *pixbuf;
|
|
|
|
|
|
|
|
error = NULL;
|
|
|
|
pixbuf =
|
|
|
|
_gtk_icon_info_load_symbolic_internal (data->dup,
|
|
|
|
data->fg_set ? &data->fg : NULL,
|
|
|
|
data->success_color_set ? &data->success_color : NULL,
|
|
|
|
data->warning_color_set ? &data->warning_color : NULL,
|
|
|
|
data->error_color_set ? &data->error_color : NULL,
|
|
|
|
FALSE,
|
|
|
|
&error);
|
|
|
|
if (pixbuf == NULL)
|
|
|
|
g_task_return_error (task, error);
|
|
|
|
else
|
|
|
|
g_task_return_pointer (task, pixbuf, g_object_unref);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* gtk_icon_info_load_symbolic_async:
|
2014-01-27 22:04:46 +00:00
|
|
|
* @icon_info: a #GtkIconInfo from gtk_icon_theme_lookup_icon()
|
2013-02-14 15:01:04 +00:00
|
|
|
* @fg: a #GdkRGBA representing the foreground color of the icon
|
|
|
|
* @success_color: (allow-none): a #GdkRGBA representing the warning color
|
|
|
|
* of the icon or %NULL to use the default color
|
|
|
|
* @warning_color: (allow-none): a #GdkRGBA representing the warning color
|
|
|
|
* of the icon or %NULL to use the default color
|
|
|
|
* @error_color: (allow-none): a #GdkRGBA representing the error color
|
|
|
|
* of the icon or %NULL to use the default color (allow-none)
|
|
|
|
* @cancellable: (allow-none): optional #GCancellable object,
|
|
|
|
* %NULL to ignore
|
|
|
|
* @callback: (scope async): a #GAsyncReadyCallback to call when the
|
|
|
|
* request is satisfied
|
|
|
|
* @user_data: (closure): the data to pass to callback function
|
|
|
|
*
|
|
|
|
* Asynchronously load, render and scale a symbolic icon previously looked up
|
|
|
|
* from the icon theme using gtk_icon_theme_lookup_icon().
|
|
|
|
*
|
|
|
|
* For more details, see gtk_icon_info_load_symbolic() which is the synchronous
|
|
|
|
* version of this call.
|
|
|
|
*
|
|
|
|
* Since: 3.8
|
|
|
|
**/
|
|
|
|
void
|
|
|
|
gtk_icon_info_load_symbolic_async (GtkIconInfo *icon_info,
|
|
|
|
const GdkRGBA *fg,
|
|
|
|
const GdkRGBA *success_color,
|
|
|
|
const GdkRGBA *warning_color,
|
|
|
|
const GdkRGBA *error_color,
|
|
|
|
GCancellable *cancellable,
|
|
|
|
GAsyncReadyCallback callback,
|
|
|
|
gpointer user_data)
|
|
|
|
{
|
|
|
|
GTask *task;
|
|
|
|
AsyncSymbolicData *data;
|
|
|
|
SymbolicPixbufCache *symbolic_cache;
|
|
|
|
GdkPixbuf *pixbuf;
|
|
|
|
|
|
|
|
g_return_if_fail (icon_info != NULL);
|
|
|
|
g_return_if_fail (fg != NULL);
|
|
|
|
|
|
|
|
task = g_task_new (icon_info, cancellable, callback, user_data);
|
|
|
|
|
|
|
|
data = g_slice_new0 (AsyncSymbolicData);
|
|
|
|
g_task_set_task_data (task, data, (GDestroyNotify) async_symbolic_data_free);
|
|
|
|
|
2013-12-15 02:41:49 +00:00
|
|
|
data->is_symbolic = gtk_icon_info_is_symbolic (icon_info);
|
2013-02-14 15:01:04 +00:00
|
|
|
|
|
|
|
if (!data->is_symbolic)
|
|
|
|
{
|
|
|
|
gtk_icon_info_load_icon_async (icon_info, cancellable, async_load_no_symbolic_cb, g_object_ref (task));
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
symbolic_cache = symbolic_pixbuf_cache_matches (icon_info->symbolic_pixbuf_cache,
|
|
|
|
fg, success_color, warning_color, error_color);
|
|
|
|
if (symbolic_cache)
|
|
|
|
{
|
|
|
|
pixbuf = symbolic_cache_get_proxy (symbolic_cache, icon_info);
|
|
|
|
g_task_return_pointer (task, pixbuf, g_object_unref);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (fg)
|
|
|
|
{
|
|
|
|
data->fg = *fg;
|
|
|
|
data->fg_set = TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (success_color)
|
|
|
|
{
|
|
|
|
data->success_color = *success_color;
|
|
|
|
data->success_color_set = TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (warning_color)
|
|
|
|
{
|
|
|
|
data->warning_color = *warning_color;
|
|
|
|
data->warning_color_set = TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (error_color)
|
|
|
|
{
|
|
|
|
data->error_color = *error_color;
|
|
|
|
data->error_color_set = TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
data->dup = icon_info_dup (icon_info);
|
|
|
|
g_task_run_in_thread (task, load_symbolic_icon_thread);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
g_object_unref (task);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* gtk_icon_info_load_symbolic_finish:
|
2014-01-27 22:04:46 +00:00
|
|
|
* @icon_info: a #GtkIconInfo from gtk_icon_theme_lookup_icon()
|
2013-02-14 15:01:04 +00:00
|
|
|
* @res: a #GAsyncResult
|
|
|
|
* @was_symbolic: (out) (allow-none): a #gboolean, returns whether the
|
|
|
|
* loaded icon was a symbolic one and whether the @fg color was
|
|
|
|
* applied to it.
|
|
|
|
* @error: (allow-none): location to store error information on failure,
|
|
|
|
* or %NULL.
|
|
|
|
*
|
|
|
|
* Finishes an async icon load, see gtk_icon_info_load_symbolic_async().
|
|
|
|
*
|
|
|
|
* Return value: (transfer full): the rendered icon; this may be a newly
|
|
|
|
* created icon or a new reference to an internal icon, so you must
|
|
|
|
* not modify the icon. Use g_object_unref() to release your reference
|
|
|
|
* to the icon.
|
|
|
|
*
|
|
|
|
* Since: 3.8
|
|
|
|
**/
|
|
|
|
GdkPixbuf *
|
|
|
|
gtk_icon_info_load_symbolic_finish (GtkIconInfo *icon_info,
|
|
|
|
GAsyncResult *result,
|
|
|
|
gboolean *was_symbolic,
|
|
|
|
GError **error)
|
|
|
|
{
|
|
|
|
GTask *task = G_TASK (result);
|
|
|
|
AsyncSymbolicData *data = g_task_get_task_data (task);
|
|
|
|
SymbolicPixbufCache *symbolic_cache;
|
|
|
|
GdkPixbuf *pixbuf;
|
|
|
|
|
|
|
|
if (was_symbolic)
|
|
|
|
*was_symbolic = data->is_symbolic;
|
|
|
|
|
|
|
|
if (data->dup && !g_task_had_error (task))
|
|
|
|
{
|
|
|
|
pixbuf = g_task_propagate_pointer (task, NULL);
|
|
|
|
|
|
|
|
g_assert (pixbuf != NULL); /* we checked for !had_error above */
|
|
|
|
|
|
|
|
symbolic_cache = symbolic_pixbuf_cache_matches (icon_info->symbolic_pixbuf_cache,
|
|
|
|
data->fg_set ? &data->fg : NULL,
|
|
|
|
data->success_color_set ? &data->success_color : NULL,
|
|
|
|
data->warning_color_set ? &data->warning_color : NULL,
|
|
|
|
data->error_color_set ? &data->error_color : NULL);
|
|
|
|
|
|
|
|
if (symbolic_cache == NULL)
|
|
|
|
{
|
|
|
|
symbolic_cache = icon_info->symbolic_pixbuf_cache =
|
|
|
|
symbolic_pixbuf_cache_new (pixbuf,
|
|
|
|
data->fg_set ? &data->fg : NULL,
|
|
|
|
data->success_color_set ? &data->success_color : NULL,
|
|
|
|
data->warning_color_set ? &data->warning_color : NULL,
|
|
|
|
data->error_color_set ? &data->error_color : NULL,
|
|
|
|
icon_info->symbolic_pixbuf_cache);
|
|
|
|
}
|
|
|
|
|
|
|
|
g_object_unref (pixbuf);
|
|
|
|
|
|
|
|
return symbolic_cache_get_proxy (symbolic_cache, icon_info);
|
|
|
|
}
|
|
|
|
|
|
|
|
return g_task_propagate_pointer (task, error);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2013-02-15 10:07:51 +00:00
|
|
|
* gtk_icon_info_load_symbolic_for_context_async:
|
2014-01-27 22:04:46 +00:00
|
|
|
* @icon_info: a #GtkIconInfo from gtk_icon_theme_lookup_icon()
|
2013-02-14 15:01:04 +00:00
|
|
|
* @context: a #GtkStyleContext
|
|
|
|
* @cancellable: (allow-none): optional #GCancellable object,
|
|
|
|
* %NULL to ignore
|
|
|
|
* @callback: (scope async): a #GAsyncReadyCallback to call when the
|
|
|
|
* request is satisfied
|
|
|
|
* @user_data: (closure): the data to pass to callback function
|
|
|
|
*
|
|
|
|
* Asynchronously load, render and scale a symbolic icon previously looked up
|
|
|
|
* from the icon theme using gtk_icon_theme_lookup_icon().
|
|
|
|
*
|
|
|
|
* For more details, see gtk_icon_info_load_symbolic_for_context() which is the synchronous
|
|
|
|
* version of this call.
|
|
|
|
*
|
|
|
|
* Since: 3.8
|
|
|
|
**/
|
|
|
|
void
|
|
|
|
gtk_icon_info_load_symbolic_for_context_async (GtkIconInfo *icon_info,
|
|
|
|
GtkStyleContext *context,
|
|
|
|
GCancellable *cancellable,
|
|
|
|
GAsyncReadyCallback callback,
|
|
|
|
gpointer user_data)
|
|
|
|
{
|
|
|
|
GdkRGBA *color = NULL;
|
|
|
|
GdkRGBA fg;
|
|
|
|
GdkRGBA *fgp;
|
|
|
|
GdkRGBA success_color;
|
|
|
|
GdkRGBA *success_colorp;
|
|
|
|
GdkRGBA warning_color;
|
|
|
|
GdkRGBA *warning_colorp;
|
|
|
|
GdkRGBA error_color;
|
|
|
|
GdkRGBA *error_colorp;
|
|
|
|
GtkStateFlags state;
|
|
|
|
|
|
|
|
g_return_if_fail (icon_info != NULL);
|
|
|
|
g_return_if_fail (context != NULL);
|
|
|
|
|
|
|
|
fgp = success_colorp = warning_colorp = error_colorp = NULL;
|
|
|
|
|
|
|
|
state = gtk_style_context_get_state (context);
|
|
|
|
gtk_style_context_get (context, state, "color", &color, NULL);
|
|
|
|
if (color)
|
|
|
|
{
|
|
|
|
fg = *color;
|
|
|
|
fgp = &fg;
|
|
|
|
gdk_rgba_free (color);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (gtk_style_context_lookup_color (context, "success_color", &success_color))
|
|
|
|
success_colorp = &success_color;
|
|
|
|
|
|
|
|
if (gtk_style_context_lookup_color (context, "warning_color", &warning_color))
|
|
|
|
warning_colorp = &warning_color;
|
|
|
|
|
|
|
|
if (gtk_style_context_lookup_color (context, "error_color", &error_color))
|
|
|
|
error_colorp = &error_color;
|
|
|
|
|
|
|
|
gtk_icon_info_load_symbolic_async (icon_info,
|
|
|
|
fgp, success_colorp,
|
|
|
|
warning_colorp, error_colorp,
|
|
|
|
cancellable, callback, user_data);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* gtk_icon_info_load_symbolic_for_context_finish:
|
2014-01-27 22:04:46 +00:00
|
|
|
* @icon_info: a #GtkIconInfo from gtk_icon_theme_lookup_icon()
|
2013-02-14 15:01:04 +00:00
|
|
|
* @res: a #GAsyncResult
|
|
|
|
* @was_symbolic: (out) (allow-none): a #gboolean, returns whether the
|
|
|
|
* loaded icon was a symbolic one and whether the @fg color was
|
|
|
|
* applied to it.
|
|
|
|
* @error: (allow-none): location to store error information on failure,
|
|
|
|
* or %NULL.
|
|
|
|
*
|
|
|
|
* Finishes an async icon load, see gtk_icon_info_load_symbolic_for_context_async().
|
|
|
|
*
|
|
|
|
* Return value: (transfer full): the rendered icon; this may be a newly
|
|
|
|
* created icon or a new reference to an internal icon, so you must
|
|
|
|
* not modify the icon. Use g_object_unref() to release your reference
|
|
|
|
* to the icon.
|
|
|
|
*
|
|
|
|
* Since: 3.8
|
|
|
|
**/
|
|
|
|
GdkPixbuf *
|
|
|
|
gtk_icon_info_load_symbolic_for_context_finish (GtkIconInfo *icon_info,
|
|
|
|
GAsyncResult *result,
|
|
|
|
gboolean *was_symbolic,
|
|
|
|
GError **error)
|
|
|
|
{
|
|
|
|
return gtk_icon_info_load_symbolic_finish (icon_info, result, was_symbolic, error);
|
|
|
|
}
|
|
|
|
|
2012-11-26 12:52:05 +00:00
|
|
|
static GdkRGBA *
|
|
|
|
color_to_rgba (GdkColor *color, GdkRGBA *rgba)
|
|
|
|
{
|
|
|
|
rgba->red = color->red / 65535.0;
|
|
|
|
rgba->green = color->green / 65535.0;
|
|
|
|
rgba->blue = color->blue / 65535.0;
|
|
|
|
rgba->alpha = 1.0;
|
|
|
|
return rgba;
|
2010-11-24 19:40:31 +00:00
|
|
|
}
|
|
|
|
|
2010-06-15 03:46:46 +00:00
|
|
|
/**
|
|
|
|
* gtk_icon_info_load_symbolic_for_style:
|
|
|
|
* @icon_info: a #GtkIconInfo
|
|
|
|
* @style: a #GtkStyle to take the colors from
|
|
|
|
* @state: the widget state to use for colors
|
2011-01-18 09:10:30 +00:00
|
|
|
* @was_symbolic: (out) (allow-none): a #gboolean, returns whether the
|
|
|
|
* loaded icon was a symbolic one and whether the @fg color was
|
|
|
|
* applied to it.
|
2010-06-15 03:46:46 +00:00
|
|
|
* @error: (allow-none): location to store error information on failure,
|
|
|
|
* or %NULL.
|
|
|
|
*
|
|
|
|
* Loads an icon, modifying it to match the system colours for the foreground,
|
|
|
|
* success, warning and error colors provided. If the icon is not a symbolic
|
|
|
|
* one, the function will return the result from gtk_icon_info_load_icon().
|
|
|
|
*
|
|
|
|
* This allows loading symbolic icons that will match the system theme.
|
|
|
|
*
|
|
|
|
* See gtk_icon_info_load_symbolic() for more details.
|
|
|
|
*
|
2010-09-21 04:18:11 +00:00
|
|
|
* Return value: (transfer full): a #GdkPixbuf representing the loaded icon
|
2010-06-15 03:46:46 +00:00
|
|
|
*
|
|
|
|
* Since: 3.0
|
2010-11-25 00:57:10 +00:00
|
|
|
*
|
|
|
|
* Deprecated: 3.0: Use gtk_icon_info_load_symbolic_for_context() instead
|
2010-06-15 03:46:46 +00:00
|
|
|
**/
|
|
|
|
GdkPixbuf *
|
|
|
|
gtk_icon_info_load_symbolic_for_style (GtkIconInfo *icon_info,
|
|
|
|
GtkStyle *style,
|
|
|
|
GtkStateType state,
|
|
|
|
gboolean *was_symbolic,
|
|
|
|
GError **error)
|
|
|
|
{
|
2012-11-26 12:52:05 +00:00
|
|
|
GdkColor color;
|
|
|
|
GdkRGBA fg;
|
|
|
|
GdkRGBA success_color;
|
|
|
|
GdkRGBA *success_colorp;
|
|
|
|
GdkRGBA warning_color;
|
|
|
|
GdkRGBA *warning_colorp;
|
|
|
|
GdkRGBA error_color;
|
|
|
|
GdkRGBA *error_colorp;
|
2012-10-28 19:01:30 +00:00
|
|
|
gboolean is_symbolic;
|
2010-10-22 12:21:34 +00:00
|
|
|
|
2012-11-09 10:55:44 +00:00
|
|
|
g_return_val_if_fail (icon_info != NULL, NULL);
|
|
|
|
g_return_val_if_fail (style != NULL, NULL);
|
|
|
|
|
2013-12-15 02:41:49 +00:00
|
|
|
is_symbolic = gtk_icon_info_is_symbolic (icon_info);
|
2010-10-22 12:21:34 +00:00
|
|
|
|
|
|
|
if (was_symbolic)
|
2012-10-28 19:01:30 +00:00
|
|
|
*was_symbolic = is_symbolic;
|
|
|
|
|
|
|
|
if (!is_symbolic)
|
|
|
|
return gtk_icon_info_load_icon (icon_info, error);
|
2010-06-15 03:46:46 +00:00
|
|
|
|
2012-11-26 12:52:05 +00:00
|
|
|
color_to_rgba (&style->fg[state], &fg);
|
2010-10-27 16:47:08 +00:00
|
|
|
|
2012-11-26 12:52:05 +00:00
|
|
|
success_colorp = warning_colorp = error_colorp = NULL;
|
2010-10-27 16:47:08 +00:00
|
|
|
|
2012-11-26 12:52:05 +00:00
|
|
|
if (gtk_style_lookup_color (style, "success_color", &color))
|
|
|
|
success_colorp = color_to_rgba (&color, &success_color);
|
2010-06-15 03:46:46 +00:00
|
|
|
|
2012-11-26 12:52:05 +00:00
|
|
|
if (gtk_style_lookup_color (style, "warning_color", &color))
|
|
|
|
warning_colorp = color_to_rgba (&color, &warning_color);
|
2010-10-22 12:21:34 +00:00
|
|
|
|
2012-11-26 12:52:05 +00:00
|
|
|
if (gtk_style_lookup_color (style, "error_color", &color))
|
|
|
|
error_colorp = color_to_rgba (&color, &error_color);
|
2010-10-22 12:21:34 +00:00
|
|
|
|
2012-11-26 12:52:05 +00:00
|
|
|
return _gtk_icon_info_load_symbolic_internal (icon_info,
|
|
|
|
&fg, success_colorp,
|
|
|
|
warning_colorp, error_colorp,
|
2013-02-14 15:01:04 +00:00
|
|
|
TRUE,
|
2012-11-26 12:52:05 +00:00
|
|
|
error);
|
2010-06-15 03:46:46 +00:00
|
|
|
}
|
|
|
|
|
2003-07-02 22:44:09 +00:00
|
|
|
/**
|
|
|
|
* gtk_icon_info_set_raw_coordinates:
|
|
|
|
* @icon_info: a #GtkIconInfo
|
|
|
|
* @raw_coordinates: whether the coordinates of embedded rectangles
|
|
|
|
* and attached points should be returned in their original
|
|
|
|
* (unscaled) form.
|
|
|
|
*
|
|
|
|
* Sets whether the coordinates returned by gtk_icon_info_get_embedded_rect()
|
|
|
|
* and gtk_icon_info_get_attach_points() should be returned in their
|
|
|
|
* original form as specified in the icon theme, instead of scaled
|
|
|
|
* appropriately for the pixbuf returned by gtk_icon_info_load_icon().
|
|
|
|
*
|
|
|
|
* Raw coordinates are somewhat strange; they are specified to be with
|
|
|
|
* respect to the unscaled pixmap for PNG and XPM icons, but for SVG
|
|
|
|
* icons, they are in a 1000x1000 coordinate space that is scaled
|
|
|
|
* to the final size of the icon. You can determine if the icon is an SVG
|
|
|
|
* icon by using gtk_icon_info_get_filename(), and seeing if it is non-%NULL
|
|
|
|
* and ends in '.svg'.
|
|
|
|
*
|
|
|
|
* This function is provided primarily to allow compatibility wrappers
|
|
|
|
* for older API's, and is not expected to be useful for applications.
|
2003-11-08 00:51:10 +00:00
|
|
|
*
|
|
|
|
* Since: 2.4
|
2003-07-02 22:44:09 +00:00
|
|
|
**/
|
|
|
|
void
|
|
|
|
gtk_icon_info_set_raw_coordinates (GtkIconInfo *icon_info,
|
|
|
|
gboolean raw_coordinates)
|
|
|
|
{
|
|
|
|
g_return_if_fail (icon_info != NULL);
|
|
|
|
|
|
|
|
icon_info->raw_coordinates = raw_coordinates != FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Scale coordinates from the icon data prior to returning
|
|
|
|
* them to the user.
|
|
|
|
*/
|
|
|
|
static gboolean
|
|
|
|
icon_info_scale_point (GtkIconInfo *icon_info,
|
|
|
|
gint x,
|
|
|
|
gint y,
|
|
|
|
gint *x_out,
|
|
|
|
gint *y_out)
|
|
|
|
{
|
|
|
|
if (icon_info->raw_coordinates)
|
|
|
|
{
|
|
|
|
*x_out = x;
|
|
|
|
*y_out = y;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (!icon_info_ensure_scale_and_pixbuf (icon_info, TRUE))
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
*x_out = 0.5 + x * icon_info->scale;
|
|
|
|
*y_out = 0.5 + y * icon_info->scale;
|
|
|
|
}
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* gtk_icon_info_get_embedded_rect:
|
|
|
|
* @icon_info: a #GtkIconInfo
|
2011-01-18 09:10:30 +00:00
|
|
|
* @rectangle: (out): #GdkRectangle in which to store embedded
|
2003-07-02 22:44:09 +00:00
|
|
|
* rectangle coordinates; coordinates are only stored
|
|
|
|
* when this function returns %TRUE.
|
|
|
|
*
|
|
|
|
* Gets the coordinates of a rectangle within the icon
|
|
|
|
* that can be used for display of information such
|
|
|
|
* as a preview of the contents of a text file.
|
|
|
|
* See gtk_icon_info_set_raw_coordinates() for further
|
|
|
|
* information about the coordinate system.
|
|
|
|
*
|
|
|
|
* Return value: %TRUE if the icon has an embedded rectangle
|
2003-11-08 00:51:10 +00:00
|
|
|
*
|
|
|
|
* Since: 2.4
|
2003-07-02 22:44:09 +00:00
|
|
|
**/
|
|
|
|
gboolean
|
|
|
|
gtk_icon_info_get_embedded_rect (GtkIconInfo *icon_info,
|
|
|
|
GdkRectangle *rectangle)
|
|
|
|
{
|
|
|
|
g_return_val_if_fail (icon_info != NULL, FALSE);
|
|
|
|
|
|
|
|
if (icon_info->data && icon_info->data->has_embedded_rect &&
|
|
|
|
icon_info_ensure_scale_and_pixbuf (icon_info, TRUE))
|
|
|
|
{
|
|
|
|
gint scaled_x0, scaled_y0;
|
|
|
|
gint scaled_x1, scaled_y1;
|
|
|
|
|
|
|
|
if (rectangle)
|
|
|
|
{
|
|
|
|
icon_info_scale_point (icon_info,
|
|
|
|
icon_info->data->x0, icon_info->data->y0,
|
|
|
|
&scaled_x0, &scaled_y0);
|
|
|
|
icon_info_scale_point (icon_info,
|
2003-12-18 16:08:01 +00:00
|
|
|
icon_info->data->x1, icon_info->data->y1,
|
2003-07-02 22:44:09 +00:00
|
|
|
&scaled_x1, &scaled_y1);
|
|
|
|
|
|
|
|
rectangle->x = scaled_x0;
|
|
|
|
rectangle->y = scaled_y0;
|
|
|
|
rectangle->width = scaled_x1 - rectangle->x;
|
|
|
|
rectangle->height = scaled_y1 - rectangle->y;
|
|
|
|
}
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* gtk_icon_info_get_attach_points:
|
|
|
|
* @icon_info: a #GtkIconInfo
|
2010-09-29 14:44:10 +00:00
|
|
|
* @points: (allow-none) (array length=n_points) (out): location to store pointer to an array of points, or %NULL
|
2003-07-02 22:44:09 +00:00
|
|
|
* free the array of points with g_free().
|
2010-02-19 16:53:17 +00:00
|
|
|
* @n_points: (allow-none): location to store the number of points in @points, or %NULL
|
2003-07-02 22:44:09 +00:00
|
|
|
*
|
|
|
|
* Fetches the set of attach points for an icon. An attach point
|
|
|
|
* is a location in the icon that can be used as anchor points for attaching
|
|
|
|
* emblems or overlays to the icon.
|
|
|
|
*
|
|
|
|
* Return value: %TRUE if there are any attach points for the icon.
|
2003-11-08 00:51:10 +00:00
|
|
|
*
|
|
|
|
* Since: 2.4
|
2003-07-02 22:44:09 +00:00
|
|
|
**/
|
|
|
|
gboolean
|
|
|
|
gtk_icon_info_get_attach_points (GtkIconInfo *icon_info,
|
|
|
|
GdkPoint **points,
|
|
|
|
gint *n_points)
|
|
|
|
{
|
|
|
|
g_return_val_if_fail (icon_info != NULL, FALSE);
|
|
|
|
|
|
|
|
if (icon_info->data && icon_info->data->n_attach_points &&
|
|
|
|
icon_info_ensure_scale_and_pixbuf (icon_info, TRUE))
|
|
|
|
{
|
|
|
|
if (points)
|
|
|
|
{
|
|
|
|
gint i;
|
|
|
|
|
|
|
|
*points = g_new (GdkPoint, icon_info->data->n_attach_points);
|
|
|
|
for (i = 0; i < icon_info->data->n_attach_points; i++)
|
|
|
|
icon_info_scale_point (icon_info,
|
|
|
|
icon_info->data->attach_points[i].x,
|
|
|
|
icon_info->data->attach_points[i].y,
|
|
|
|
&(*points)[i].x,
|
|
|
|
&(*points)[i].y);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (n_points)
|
|
|
|
*n_points = icon_info->data->n_attach_points;
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (points)
|
|
|
|
*points = NULL;
|
|
|
|
if (n_points)
|
|
|
|
*n_points = 0;
|
|
|
|
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* gtk_icon_info_get_display_name:
|
|
|
|
* @icon_info: a #GtkIconInfo
|
|
|
|
*
|
|
|
|
* Gets the display name for an icon. A display name is a
|
|
|
|
* string to be used in place of the icon name in a user
|
|
|
|
* visible context like a list of icons.
|
|
|
|
*
|
|
|
|
* Return value: the display name for the icon or %NULL, if
|
|
|
|
* the icon doesn't have a specified display name. This value
|
|
|
|
* is owned @icon_info and must not be modified or free.
|
2003-11-08 00:51:10 +00:00
|
|
|
*
|
|
|
|
* Since: 2.4
|
2003-07-02 22:44:09 +00:00
|
|
|
**/
|
2011-06-06 18:13:44 +00:00
|
|
|
const gchar *
|
2006-03-31 05:17:56 +00:00
|
|
|
gtk_icon_info_get_display_name (GtkIconInfo *icon_info)
|
2003-07-02 22:44:09 +00:00
|
|
|
{
|
|
|
|
g_return_val_if_fail (icon_info != NULL, NULL);
|
|
|
|
|
|
|
|
if (icon_info->data)
|
|
|
|
return icon_info->data->display_name;
|
|
|
|
else
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Builtin icons
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* gtk_icon_theme_add_builtin_icon:
|
|
|
|
* @icon_name: the name of the icon to register
|
|
|
|
* @size: the size at which to register the icon (different
|
|
|
|
* images can be registered for the same icon name
|
|
|
|
* at different sizes.)
|
|
|
|
* @pixbuf: #GdkPixbuf that contains the image to use
|
|
|
|
* for @icon_name.
|
|
|
|
*
|
|
|
|
* Registers a built-in icon for icon theme lookups. The idea
|
|
|
|
* of built-in icons is to allow an application or library
|
|
|
|
* that uses themed icons to function requiring files to
|
|
|
|
* be present in the file system. For instance, the default
|
|
|
|
* images for all of GTK+'s stock icons are registered
|
|
|
|
* as built-icons.
|
|
|
|
*
|
|
|
|
* In general, if you use gtk_icon_theme_add_builtin_icon()
|
|
|
|
* you should also install the icon in the icon theme, so
|
|
|
|
* that the icon is generally available.
|
|
|
|
*
|
|
|
|
* This function will generally be used with pixbufs loaded
|
2004-11-10 02:03:36 +00:00
|
|
|
* via gdk_pixbuf_new_from_inline().
|
2003-11-08 00:51:10 +00:00
|
|
|
*
|
|
|
|
* Since: 2.4
|
2003-07-02 22:44:09 +00:00
|
|
|
**/
|
|
|
|
void
|
|
|
|
gtk_icon_theme_add_builtin_icon (const gchar *icon_name,
|
|
|
|
gint size,
|
|
|
|
GdkPixbuf *pixbuf)
|
|
|
|
{
|
|
|
|
BuiltinIcon *default_icon;
|
|
|
|
GSList *icons;
|
|
|
|
gpointer key;
|
|
|
|
|
|
|
|
g_return_if_fail (icon_name != NULL);
|
|
|
|
g_return_if_fail (GDK_IS_PIXBUF (pixbuf));
|
|
|
|
|
|
|
|
if (!icon_theme_builtin_icons)
|
|
|
|
icon_theme_builtin_icons = g_hash_table_new (g_str_hash, g_str_equal);
|
|
|
|
|
|
|
|
icons = g_hash_table_lookup (icon_theme_builtin_icons, icon_name);
|
|
|
|
if (!icons)
|
|
|
|
key = g_strdup (icon_name);
|
|
|
|
else
|
|
|
|
key = (gpointer)icon_name; /* Won't get stored */
|
|
|
|
|
|
|
|
default_icon = g_new (BuiltinIcon, 1);
|
|
|
|
default_icon->size = size;
|
|
|
|
default_icon->pixbuf = g_object_ref (pixbuf);
|
|
|
|
icons = g_slist_prepend (icons, default_icon);
|
|
|
|
|
|
|
|
/* Replaces value, leaves key untouched
|
|
|
|
*/
|
|
|
|
g_hash_table_insert (icon_theme_builtin_icons, key, icons);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Look up a builtin icon; the min_difference_p and
|
|
|
|
* has_larger_p out parameters allow us to combine
|
|
|
|
* this lookup with searching through the actual directories
|
|
|
|
* of the "hicolor" icon theme. See theme_lookup_icon()
|
|
|
|
* for how they are used.
|
|
|
|
*/
|
|
|
|
static BuiltinIcon *
|
|
|
|
find_builtin_icon (const gchar *icon_name,
|
|
|
|
gint size,
|
2013-05-10 16:06:00 +00:00
|
|
|
gint scale,
|
|
|
|
gint *min_difference_p)
|
2003-07-02 22:44:09 +00:00
|
|
|
{
|
|
|
|
GSList *icons = NULL;
|
|
|
|
gint min_difference = G_MAXINT;
|
|
|
|
gboolean has_larger = FALSE;
|
|
|
|
BuiltinIcon *min_icon = NULL;
|
|
|
|
|
|
|
|
if (!icon_theme_builtin_icons)
|
|
|
|
return NULL;
|
|
|
|
|
2013-05-10 16:06:00 +00:00
|
|
|
size *= scale;
|
|
|
|
|
2003-07-02 22:44:09 +00:00
|
|
|
icons = g_hash_table_lookup (icon_theme_builtin_icons, icon_name);
|
|
|
|
|
|
|
|
while (icons)
|
|
|
|
{
|
|
|
|
BuiltinIcon *default_icon = icons->data;
|
|
|
|
int min, max, difference;
|
|
|
|
gboolean smaller;
|
|
|
|
|
|
|
|
min = default_icon->size - 2;
|
|
|
|
max = default_icon->size + 2;
|
|
|
|
smaller = size < min;
|
|
|
|
if (size < min)
|
|
|
|
difference = min - size;
|
2003-12-08 22:55:03 +00:00
|
|
|
else if (size > max)
|
2003-07-02 22:44:09 +00:00
|
|
|
difference = size - max;
|
|
|
|
else
|
|
|
|
difference = 0;
|
|
|
|
|
|
|
|
if (difference == 0)
|
|
|
|
{
|
|
|
|
min_icon = default_icon;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!has_larger)
|
|
|
|
{
|
|
|
|
if (difference < min_difference || smaller)
|
|
|
|
{
|
|
|
|
min_difference = difference;
|
|
|
|
min_icon = default_icon;
|
|
|
|
has_larger = smaller;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (difference < min_difference && smaller)
|
|
|
|
{
|
|
|
|
min_difference = difference;
|
|
|
|
min_icon = default_icon;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
icons = icons->next;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (min_difference_p)
|
|
|
|
*min_difference_p = min_difference;
|
|
|
|
|
|
|
|
return min_icon;
|
|
|
|
}
|
2004-12-12 21:09:13 +00:00
|
|
|
|
2008-05-29 14:33:49 +00:00
|
|
|
/**
|
|
|
|
* gtk_icon_theme_lookup_by_gicon:
|
|
|
|
* @icon_theme: a #GtkIconTheme
|
|
|
|
* @icon: the #GIcon to look up
|
|
|
|
* @size: desired icon size
|
|
|
|
* @flags: flags modifying the behavior of the icon lookup
|
|
|
|
*
|
2014-01-27 22:04:46 +00:00
|
|
|
* Looks up an icon and returns a #GtkIconInfo containing
|
2008-05-29 14:33:49 +00:00
|
|
|
* information such as the filename of the icon.
|
|
|
|
* The icon can then be rendered into a pixbuf using
|
2008-06-15 22:56:47 +00:00
|
|
|
* gtk_icon_info_load_icon().
|
2008-05-29 14:33:49 +00:00
|
|
|
*
|
2014-01-27 22:04:46 +00:00
|
|
|
* Return value: (transfer full): a #GtkIconInfo containing
|
2008-05-29 14:33:49 +00:00
|
|
|
* information about the icon, or %NULL if the icon
|
2013-02-16 00:35:44 +00:00
|
|
|
* wasn't found. Unref with g_object_unref()
|
2008-05-29 14:33:49 +00:00
|
|
|
*
|
|
|
|
* Since: 2.14
|
|
|
|
*/
|
|
|
|
GtkIconInfo *
|
|
|
|
gtk_icon_theme_lookup_by_gicon (GtkIconTheme *icon_theme,
|
|
|
|
GIcon *icon,
|
|
|
|
gint size,
|
|
|
|
GtkIconLookupFlags flags)
|
2013-05-10 16:06:00 +00:00
|
|
|
{
|
|
|
|
return gtk_icon_theme_lookup_by_gicon_for_scale (icon_theme, icon,
|
|
|
|
size, 1, flags);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* gtk_icon_theme_lookup_by_gicon_for_scale:
|
|
|
|
* @icon_theme: a #GtkIconTheme
|
|
|
|
* @icon: the #GIcon to look up
|
|
|
|
* @size: desired icon size
|
|
|
|
* @scale: the desired scale
|
|
|
|
* @flags: flags modifying the behavior of the icon lookup
|
|
|
|
*
|
2014-01-27 22:04:46 +00:00
|
|
|
* Looks up an icon and returns a #GtkIconInfo containing
|
2013-05-10 16:06:00 +00:00
|
|
|
* information such as the filename of the icon.
|
|
|
|
* The icon can then be rendered into a pixbuf using
|
2014-01-21 22:38:52 +00:00
|
|
|
* gtk_icon_info_load_icon().
|
2013-05-10 16:06:00 +00:00
|
|
|
*
|
2014-01-27 22:04:46 +00:00
|
|
|
* Return value: (transfer full): a #GtkIconInfo containing
|
2013-09-17 05:28:39 +00:00
|
|
|
* information about the icon, or %NULL if the icon
|
2013-05-10 16:06:00 +00:00
|
|
|
* wasn't found. Unref with g_object_unref()
|
|
|
|
*
|
2013-07-26 20:16:12 +00:00
|
|
|
* Since: 3.10
|
2013-05-10 16:06:00 +00:00
|
|
|
*/
|
|
|
|
GtkIconInfo *
|
|
|
|
gtk_icon_theme_lookup_by_gicon_for_scale (GtkIconTheme *icon_theme,
|
|
|
|
GIcon *icon,
|
|
|
|
gint size,
|
|
|
|
gint scale,
|
|
|
|
GtkIconLookupFlags flags)
|
2008-05-29 14:33:49 +00:00
|
|
|
{
|
|
|
|
GtkIconInfo *info;
|
|
|
|
|
|
|
|
g_return_val_if_fail (GTK_IS_ICON_THEME (icon_theme), NULL);
|
|
|
|
g_return_val_if_fail (G_IS_ICON (icon), NULL);
|
|
|
|
|
2013-08-01 21:06:00 +00:00
|
|
|
if (GDK_IS_PIXBUF (icon))
|
|
|
|
{
|
|
|
|
GdkPixbuf *pixbuf;
|
|
|
|
|
|
|
|
pixbuf = GDK_PIXBUF (icon);
|
|
|
|
|
|
|
|
if ((flags & GTK_ICON_LOOKUP_FORCE_SIZE) != 0)
|
|
|
|
{
|
|
|
|
gint width, height, max;
|
|
|
|
gdouble pixbuf_scale;
|
|
|
|
GdkPixbuf *scaled;
|
|
|
|
|
|
|
|
width = gdk_pixbuf_get_width (pixbuf);
|
|
|
|
height = gdk_pixbuf_get_height (pixbuf);
|
|
|
|
max = MAX (width, height);
|
|
|
|
pixbuf_scale = (gdouble) size * scale / (gdouble) max;
|
|
|
|
|
|
|
|
scaled = gdk_pixbuf_scale_simple (pixbuf,
|
|
|
|
0.5 + width * pixbuf_scale,
|
|
|
|
0.5 + height * pixbuf_scale,
|
|
|
|
GDK_INTERP_BILINEAR);
|
|
|
|
|
|
|
|
info = gtk_icon_info_new_for_pixbuf (icon_theme, scaled);
|
|
|
|
|
|
|
|
g_object_unref (scaled);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
info = gtk_icon_info_new_for_pixbuf (icon_theme, pixbuf);
|
|
|
|
}
|
|
|
|
|
|
|
|
return info;
|
|
|
|
}
|
|
|
|
else if (G_IS_LOADABLE_ICON (icon))
|
2008-05-29 14:33:49 +00:00
|
|
|
{
|
2013-09-23 10:37:36 +00:00
|
|
|
info = icon_info_new (ICON_THEME_DIR_UNTHEMED, size, 1);
|
2008-05-29 14:33:49 +00:00
|
|
|
info->loadable = G_LOADABLE_ICON (g_object_ref (icon));
|
|
|
|
|
2012-05-19 05:13:14 +00:00
|
|
|
if (G_IS_FILE_ICON (icon))
|
|
|
|
{
|
|
|
|
GFile *file = g_file_icon_get_file (G_FILE_ICON (icon));
|
|
|
|
if (file != NULL)
|
2012-10-28 19:01:30 +00:00
|
|
|
{
|
|
|
|
info->icon_file = g_object_ref (file);
|
|
|
|
info->filename = g_file_get_path (file);
|
|
|
|
}
|
2012-05-19 05:13:14 +00:00
|
|
|
}
|
|
|
|
|
2008-05-29 14:33:49 +00:00
|
|
|
info->desired_size = size;
|
2013-05-10 16:06:00 +00:00
|
|
|
info->desired_scale = scale;
|
2008-05-29 14:33:49 +00:00
|
|
|
info->threshold = 2;
|
|
|
|
info->forced_size = (flags & GTK_ICON_LOOKUP_FORCE_SIZE) != 0;
|
|
|
|
|
|
|
|
return info;
|
|
|
|
}
|
|
|
|
else if (G_IS_THEMED_ICON (icon))
|
|
|
|
{
|
|
|
|
const gchar **names;
|
|
|
|
|
|
|
|
names = (const gchar **)g_themed_icon_get_names (G_THEMED_ICON (icon));
|
2013-05-10 16:06:00 +00:00
|
|
|
info = gtk_icon_theme_choose_icon_for_scale (icon_theme, names, size, scale, flags);
|
2008-05-29 14:33:49 +00:00
|
|
|
|
|
|
|
return info;
|
|
|
|
}
|
2008-07-28 16:15:14 +00:00
|
|
|
else if (G_IS_EMBLEMED_ICON (icon))
|
|
|
|
{
|
|
|
|
GIcon *base, *emblem;
|
2008-08-04 16:36:28 +00:00
|
|
|
GList *list, *l;
|
2013-03-01 22:45:43 +00:00
|
|
|
GtkIconInfo *base_info, *emblem_info;
|
2008-07-28 16:15:14 +00:00
|
|
|
|
2011-01-05 21:30:57 +00:00
|
|
|
if (GTK_IS_NUMERABLE_ICON (icon))
|
|
|
|
_gtk_numerable_icon_set_background_icon_size (GTK_NUMERABLE_ICON (icon), size / 2);
|
|
|
|
|
2008-07-28 16:15:14 +00:00
|
|
|
base = g_emblemed_icon_get_icon (G_EMBLEMED_ICON (icon));
|
2013-05-10 16:06:00 +00:00
|
|
|
base_info = gtk_icon_theme_lookup_by_gicon_for_scale (icon_theme, base, size, scale, flags);
|
2013-03-01 22:45:43 +00:00
|
|
|
if (base_info)
|
2008-07-28 16:15:14 +00:00
|
|
|
{
|
2013-03-01 22:45:43 +00:00
|
|
|
info = icon_info_dup (base_info);
|
|
|
|
g_object_unref (base_info);
|
|
|
|
|
2008-08-04 16:36:28 +00:00
|
|
|
list = g_emblemed_icon_get_emblems (G_EMBLEMED_ICON (icon));
|
|
|
|
for (l = list; l; l = l->next)
|
|
|
|
{
|
|
|
|
emblem = g_emblem_get_icon (G_EMBLEM (l->data));
|
2010-11-05 09:34:15 +00:00
|
|
|
/* always force size for emblems */
|
2013-05-10 16:06:00 +00:00
|
|
|
emblem_info = gtk_icon_theme_lookup_by_gicon_for_scale (icon_theme, emblem, size / 2, scale, flags | GTK_ICON_LOOKUP_FORCE_SIZE);
|
2008-08-04 16:36:28 +00:00
|
|
|
if (emblem_info)
|
|
|
|
info->emblem_infos = g_slist_prepend (info->emblem_infos, emblem_info);
|
|
|
|
}
|
2008-07-28 16:15:14 +00:00
|
|
|
|
2013-03-04 20:33:04 +00:00
|
|
|
return info;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
return NULL;
|
2008-07-28 16:15:14 +00:00
|
|
|
}
|
2008-05-29 14:33:49 +00:00
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* gtk_icon_info_new_for_pixbuf:
|
|
|
|
* @icon_theme: a #GtkIconTheme
|
|
|
|
* @pixbuf: the pixbuf to wrap in a #GtkIconInfo
|
|
|
|
*
|
2009-08-07 03:44:00 +00:00
|
|
|
* Creates a #GtkIconInfo for a #GdkPixbuf.
|
2008-05-29 14:33:49 +00:00
|
|
|
*
|
2013-02-15 10:07:51 +00:00
|
|
|
* Return value: (transfer full): a #GtkIconInfo
|
2008-05-29 14:33:49 +00:00
|
|
|
*
|
|
|
|
* Since: 2.14
|
|
|
|
*/
|
|
|
|
GtkIconInfo *
|
|
|
|
gtk_icon_info_new_for_pixbuf (GtkIconTheme *icon_theme,
|
|
|
|
GdkPixbuf *pixbuf)
|
|
|
|
{
|
|
|
|
GtkIconInfo *info;
|
|
|
|
|
|
|
|
g_return_val_if_fail (GTK_IS_ICON_THEME (icon_theme), NULL);
|
|
|
|
g_return_val_if_fail (GDK_IS_PIXBUF (pixbuf), NULL);
|
|
|
|
|
2013-09-23 10:37:36 +00:00
|
|
|
info = icon_info_new (ICON_THEME_DIR_UNTHEMED, 0, 1);
|
2008-05-29 14:33:49 +00:00
|
|
|
info->pixbuf = g_object_ref (pixbuf);
|
|
|
|
info->scale = 1.0;
|
|
|
|
|
|
|
|
return info;
|
|
|
|
}
|