2004-10-19 18:45:41 +00:00
|
|
|
/* gtkiconcache.c
|
|
|
|
* Copyright (C) 2004 Anders Carlsson <andersca@gnome.org>
|
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Library 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
|
|
|
|
* Library General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Library General Public
|
2012-02-27 13:01:10 +00:00
|
|
|
* License along with this library. If not, see <http://www.gnu.org/licenses/>.
|
2004-10-19 18:45:41 +00:00
|
|
|
*/
|
|
|
|
|
2008-06-22 14:28:52 +00:00
|
|
|
#include "config.h"
|
2005-06-27 04:49:03 +00:00
|
|
|
|
2004-10-19 18:45:41 +00:00
|
|
|
#include "gtkdebug.h"
|
|
|
|
#include "gtkiconcache.h"
|
2007-05-01 20:00:17 +00:00
|
|
|
#include "gtkiconcachevalidator.h"
|
2006-09-10 06:39:16 +00:00
|
|
|
|
2004-12-12 21:09:13 +00:00
|
|
|
#include <glib/gstdio.h>
|
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
|
|
|
#include <gdk-pixbuf/gdk-pixdata.h>
|
2004-10-19 18:45:41 +00:00
|
|
|
|
|
|
|
#ifdef HAVE_UNISTD_H
|
|
|
|
#include <unistd.h>
|
|
|
|
#endif
|
2005-07-03 15:47:42 +00:00
|
|
|
#ifdef G_OS_WIN32
|
|
|
|
#include <io.h>
|
|
|
|
#endif
|
2004-10-19 18:45:41 +00:00
|
|
|
#include <fcntl.h>
|
2005-06-27 04:49:03 +00:00
|
|
|
#include <sys/types.h>
|
|
|
|
#include <sys/stat.h>
|
2004-10-19 18:45:41 +00:00
|
|
|
#include <string.h>
|
|
|
|
|
2005-06-27 04:49:03 +00:00
|
|
|
|
2004-12-12 21:09:13 +00:00
|
|
|
#ifndef _O_BINARY
|
|
|
|
#define _O_BINARY 0
|
|
|
|
#endif
|
|
|
|
|
2004-10-19 18:45:41 +00:00
|
|
|
#define MAJOR_VERSION 1
|
|
|
|
#define MINOR_VERSION 0
|
|
|
|
|
|
|
|
#define GET_UINT16(cache, offset) (GUINT16_FROM_BE (*(guint16 *)((cache) + (offset))))
|
|
|
|
#define GET_UINT32(cache, offset) (GUINT32_FROM_BE (*(guint32 *)((cache) + (offset))))
|
|
|
|
|
2007-12-03 17:44:27 +00:00
|
|
|
|
2004-10-19 18:45:41 +00:00
|
|
|
struct _GtkIconCache {
|
|
|
|
gint ref_count;
|
|
|
|
|
2005-06-27 04:49:03 +00:00
|
|
|
GMappedFile *map;
|
2004-10-19 18:45:41 +00:00
|
|
|
gchar *buffer;
|
2007-12-03 17:44:27 +00:00
|
|
|
|
|
|
|
guint32 last_chain_offset;
|
2004-10-19 18:45:41 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
GtkIconCache *
|
|
|
|
_gtk_icon_cache_ref (GtkIconCache *cache)
|
|
|
|
{
|
2007-05-01 20:00:17 +00:00
|
|
|
cache->ref_count++;
|
2004-10-19 18:45:41 +00:00
|
|
|
return cache;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
_gtk_icon_cache_unref (GtkIconCache *cache)
|
|
|
|
{
|
|
|
|
cache->ref_count --;
|
|
|
|
|
|
|
|
if (cache->ref_count == 0)
|
|
|
|
{
|
|
|
|
GTK_NOTE (ICONTHEME,
|
|
|
|
g_print ("unmapping icon cache\n"));
|
2005-06-27 04:49:03 +00:00
|
|
|
|
2005-11-04 15:43:40 +00:00
|
|
|
if (cache->map)
|
2009-06-18 19:11:57 +00:00
|
|
|
g_mapped_file_unref (cache->map);
|
2004-10-19 18:45:41 +00:00
|
|
|
g_free (cache);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
GtkIconCache *
|
|
|
|
_gtk_icon_cache_new_for_path (const gchar *path)
|
|
|
|
{
|
2004-10-21 19:01:29 +00:00
|
|
|
GtkIconCache *cache = NULL;
|
2005-06-27 04:49:03 +00:00
|
|
|
GMappedFile *map;
|
2004-12-12 21:09:13 +00:00
|
|
|
|
2004-10-19 18:45:41 +00:00
|
|
|
gchar *cache_filename;
|
2004-12-12 21:09:13 +00:00
|
|
|
gint fd = -1;
|
2011-10-03 15:25:33 +00:00
|
|
|
GStatBuf st;
|
|
|
|
GStatBuf path_st;
|
2004-10-19 18:45:41 +00:00
|
|
|
|
2005-06-23 17:05:17 +00:00
|
|
|
/* Check if we have a cache file */
|
2004-10-19 18:45:41 +00:00
|
|
|
cache_filename = g_build_filename (path, "icon-theme.cache", NULL);
|
|
|
|
|
|
|
|
GTK_NOTE (ICONTHEME,
|
|
|
|
g_print ("look for cache in %s\n", path));
|
|
|
|
|
2004-12-12 21:09:13 +00:00
|
|
|
if (g_stat (path, &path_st) < 0)
|
|
|
|
goto done;
|
|
|
|
|
|
|
|
/* Open the file and map it into memory */
|
|
|
|
fd = g_open (cache_filename, O_RDONLY|_O_BINARY, 0);
|
2004-10-19 18:45:41 +00:00
|
|
|
|
|
|
|
if (fd < 0)
|
2005-06-27 04:49:03 +00:00
|
|
|
goto done;
|
2011-10-03 15:25:33 +00:00
|
|
|
|
|
|
|
#ifdef G_OS_WIN32
|
2011-10-12 03:39:06 +00:00
|
|
|
|
|
|
|
/* Bug 660730: _fstat32 is only defined in msvcrt80.dll+/VS 2005+ */
|
|
|
|
/* or possibly in the msvcrt.dll linked to by the Windows DDK */
|
|
|
|
/* (will need to check on the Windows DDK part later) */
|
2016-01-14 12:51:26 +00:00
|
|
|
#if ((_MSC_VER >= 1400 || __MSVCRT_VERSION__ >= 0x0800) || defined (__MINGW64_VERSION_MAJOR)) && !defined(_WIN64)
|
2011-10-03 15:25:33 +00:00
|
|
|
#undef fstat /* Just in case */
|
|
|
|
#define fstat _fstat32
|
2011-10-12 03:39:06 +00:00
|
|
|
#endif
|
2011-10-03 15:25:33 +00:00
|
|
|
#endif
|
|
|
|
|
2004-10-21 05:19:27 +00:00
|
|
|
if (fstat (fd, &st) < 0 || st.st_size < 4)
|
2004-10-19 18:45:41 +00:00
|
|
|
goto done;
|
|
|
|
|
|
|
|
/* Verify cache is uptodate */
|
|
|
|
if (st.st_mtime < path_st.st_mtime)
|
|
|
|
{
|
2015-09-09 02:48:44 +00:00
|
|
|
GTK_NOTE (ICONTHEME, g_print ("cache outdated\n"));
|
2004-10-19 18:45:41 +00:00
|
|
|
goto done;
|
|
|
|
}
|
|
|
|
|
2005-06-27 04:49:03 +00:00
|
|
|
map = g_mapped_file_new (cache_filename, FALSE, NULL);
|
2004-10-19 18:45:41 +00:00
|
|
|
|
2005-06-27 04:49:03 +00:00
|
|
|
if (!map)
|
2004-10-19 18:45:41 +00:00
|
|
|
goto done;
|
|
|
|
|
2007-09-14 02:11:01 +00:00
|
|
|
#ifdef G_ENABLE_DEBUG
|
2015-09-09 02:48:44 +00:00
|
|
|
if (GTK_DEBUG_CHECK (ICONTHEME))
|
2004-10-19 18:45:41 +00:00
|
|
|
{
|
2011-10-03 16:03:57 +00:00
|
|
|
CacheInfo info;
|
|
|
|
|
|
|
|
info.cache = g_mapped_file_get_contents (map);
|
|
|
|
info.cache_size = g_mapped_file_get_length (map);
|
|
|
|
info.n_directories = 0;
|
|
|
|
info.flags = CHECK_OFFSETS|CHECK_STRINGS;
|
|
|
|
|
2007-09-14 02:11:01 +00:00
|
|
|
if (!_gtk_icon_cache_validate (&info))
|
|
|
|
{
|
2009-06-18 19:11:57 +00:00
|
|
|
g_mapped_file_unref (map);
|
2007-09-14 02:11:01 +00:00
|
|
|
g_warning ("Icon cache '%s' is invalid\n", cache_filename);
|
2005-06-27 04:49:03 +00:00
|
|
|
|
2007-09-14 02:11:01 +00:00
|
|
|
goto done;
|
|
|
|
}
|
2004-10-19 18:45:41 +00:00
|
|
|
}
|
2007-09-14 02:11:01 +00:00
|
|
|
#endif
|
|
|
|
|
2007-05-01 20:00:17 +00:00
|
|
|
GTK_NOTE (ICONTHEME, g_print ("found cache for %s\n", path));
|
2004-10-19 18:45:41 +00:00
|
|
|
|
|
|
|
cache = g_new0 (GtkIconCache, 1);
|
|
|
|
cache->ref_count = 1;
|
2005-06-27 04:49:03 +00:00
|
|
|
cache->map = map;
|
2007-05-01 20:00:17 +00:00
|
|
|
cache->buffer = g_mapped_file_get_contents (map);
|
2005-06-27 04:49:03 +00:00
|
|
|
|
2004-10-19 18:45:41 +00:00
|
|
|
done:
|
2004-10-21 05:19:27 +00:00
|
|
|
g_free (cache_filename);
|
2005-06-27 04:49:03 +00:00
|
|
|
if (fd >= 0)
|
2004-12-12 21:09:13 +00:00
|
|
|
close (fd);
|
2004-10-19 18:45:41 +00:00
|
|
|
|
|
|
|
return cache;
|
|
|
|
}
|
|
|
|
|
2005-11-04 15:43:40 +00:00
|
|
|
GtkIconCache *
|
|
|
|
_gtk_icon_cache_new (const gchar *data)
|
|
|
|
{
|
|
|
|
GtkIconCache *cache;
|
|
|
|
|
|
|
|
cache = g_new0 (GtkIconCache, 1);
|
|
|
|
cache->ref_count = 1;
|
|
|
|
cache->map = NULL;
|
|
|
|
cache->buffer = (gchar *)data;
|
|
|
|
|
|
|
|
return cache;
|
|
|
|
}
|
|
|
|
|
|
|
|
static gint
|
2004-10-19 18:45:41 +00:00
|
|
|
get_directory_index (GtkIconCache *cache,
|
|
|
|
const gchar *directory)
|
|
|
|
{
|
|
|
|
guint32 dir_list_offset;
|
2005-11-04 15:43:40 +00:00
|
|
|
gint n_dirs;
|
|
|
|
gint i;
|
2004-10-19 18:45:41 +00:00
|
|
|
|
|
|
|
dir_list_offset = GET_UINT32 (cache->buffer, 8);
|
|
|
|
|
|
|
|
n_dirs = GET_UINT32 (cache->buffer, dir_list_offset);
|
|
|
|
|
|
|
|
for (i = 0; i < n_dirs; i++)
|
|
|
|
{
|
|
|
|
guint32 name_offset = GET_UINT32 (cache->buffer, dir_list_offset + 4 + 4 * i);
|
|
|
|
gchar *name = cache->buffer + name_offset;
|
|
|
|
if (strcmp (name, directory) == 0)
|
|
|
|
return i;
|
|
|
|
}
|
|
|
|
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2007-12-03 17:44:27 +00:00
|
|
|
gint
|
|
|
|
_gtk_icon_cache_get_directory_index (GtkIconCache *cache,
|
|
|
|
const gchar *directory)
|
2004-10-19 18:45:41 +00:00
|
|
|
{
|
2007-12-03 17:44:27 +00:00
|
|
|
return get_directory_index (cache, directory);
|
2004-10-19 18:45:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static guint
|
|
|
|
icon_name_hash (gconstpointer key)
|
|
|
|
{
|
2005-04-09 02:12:34 +00:00
|
|
|
const signed char *p = key;
|
|
|
|
guint32 h = *p;
|
2004-10-19 18:45:41 +00:00
|
|
|
|
|
|
|
if (h)
|
|
|
|
for (p += 1; *p != '\0'; p++)
|
|
|
|
h = (h << 5) - h + *p;
|
|
|
|
|
|
|
|
return h;
|
|
|
|
}
|
|
|
|
|
2005-03-20 07:01:23 +00:00
|
|
|
static gint
|
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
|
|
|
find_image_offset (GtkIconCache *cache,
|
|
|
|
const gchar *icon_name,
|
2007-12-03 17:44:27 +00:00
|
|
|
gint directory_index)
|
2004-10-19 18:45:41 +00:00
|
|
|
{
|
|
|
|
guint32 hash_offset;
|
|
|
|
guint32 n_buckets;
|
|
|
|
guint32 chain_offset;
|
2007-12-03 17:44:27 +00:00
|
|
|
int hash;
|
2004-10-19 18:45:41 +00:00
|
|
|
guint32 image_list_offset, n_images;
|
|
|
|
int i;
|
2007-12-03 17:44:27 +00:00
|
|
|
|
2013-11-28 19:56:11 +00:00
|
|
|
if (!icon_name)
|
|
|
|
return 0;
|
|
|
|
|
2007-12-03 17:44:27 +00:00
|
|
|
chain_offset = cache->last_chain_offset;
|
|
|
|
if (chain_offset)
|
|
|
|
{
|
|
|
|
guint32 name_offset = GET_UINT32 (cache->buffer, chain_offset + 4);
|
|
|
|
gchar *name = cache->buffer + name_offset;
|
|
|
|
|
|
|
|
if (strcmp (name, icon_name) == 0)
|
|
|
|
goto find_dir;
|
|
|
|
}
|
|
|
|
|
2004-10-19 18:45:41 +00:00
|
|
|
hash_offset = GET_UINT32 (cache->buffer, 4);
|
|
|
|
n_buckets = GET_UINT32 (cache->buffer, hash_offset);
|
|
|
|
hash = icon_name_hash (icon_name) % n_buckets;
|
|
|
|
|
|
|
|
chain_offset = GET_UINT32 (cache->buffer, hash_offset + 4 + 4 * hash);
|
|
|
|
while (chain_offset != 0xffffffff)
|
|
|
|
{
|
|
|
|
guint32 name_offset = GET_UINT32 (cache->buffer, chain_offset + 4);
|
|
|
|
gchar *name = cache->buffer + name_offset;
|
|
|
|
|
|
|
|
if (strcmp (name, icon_name) == 0)
|
2007-12-03 17:44:27 +00:00
|
|
|
{
|
|
|
|
cache->last_chain_offset = chain_offset;
|
|
|
|
goto find_dir;
|
2004-10-19 18:45:41 +00:00
|
|
|
}
|
2007-12-03 17:44:27 +00:00
|
|
|
|
2004-10-19 18:45:41 +00:00
|
|
|
chain_offset = GET_UINT32 (cache->buffer, chain_offset);
|
|
|
|
}
|
|
|
|
|
2007-12-03 17:44:27 +00:00
|
|
|
cache->last_chain_offset = 0;
|
|
|
|
return 0;
|
2004-10-19 18:45:41 +00:00
|
|
|
|
2007-12-03 17:44:27 +00:00
|
|
|
find_dir:
|
2004-10-19 18:45:41 +00:00
|
|
|
/* We've found an icon list, now check if we have the right icon in it */
|
|
|
|
image_list_offset = GET_UINT32 (cache->buffer, chain_offset + 8);
|
|
|
|
n_images = GET_UINT32 (cache->buffer, image_list_offset);
|
|
|
|
|
|
|
|
for (i = 0; i < n_images; i++)
|
|
|
|
{
|
|
|
|
if (GET_UINT16 (cache->buffer, image_list_offset + 4 + 8 * i) ==
|
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
|
|
|
directory_index)
|
|
|
|
return image_list_offset + 4 + 8 * i;
|
2004-10-19 18:45:41 +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
|
|
|
|
2004-10-19 18:45:41 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
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
|
|
|
gint
|
|
|
|
_gtk_icon_cache_get_icon_flags (GtkIconCache *cache,
|
|
|
|
const gchar *icon_name,
|
2007-12-03 17:44:27 +00:00
|
|
|
gint directory_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
|
|
|
{
|
|
|
|
guint32 image_offset;
|
|
|
|
|
2007-12-03 17:44:27 +00:00
|
|
|
image_offset = find_image_offset (cache, icon_name, directory_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
|
|
|
|
|
|
|
if (!image_offset)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
return GET_UINT16 (cache->buffer, image_offset + 2);
|
|
|
|
}
|
|
|
|
|
2014-06-20 16:11:22 +00:00
|
|
|
gboolean
|
|
|
|
_gtk_icon_cache_has_icons (GtkIconCache *cache,
|
|
|
|
const gchar *directory)
|
|
|
|
{
|
|
|
|
int directory_index;
|
|
|
|
guint32 hash_offset, n_buckets;
|
|
|
|
guint32 chain_offset;
|
|
|
|
guint32 image_list_offset, n_images;
|
|
|
|
int i, j;
|
|
|
|
|
|
|
|
directory_index = get_directory_index (cache, directory);
|
|
|
|
|
|
|
|
if (directory_index == -1)
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
hash_offset = GET_UINT32 (cache->buffer, 4);
|
|
|
|
n_buckets = GET_UINT32 (cache->buffer, hash_offset);
|
|
|
|
|
|
|
|
for (i = 0; i < n_buckets; i++)
|
|
|
|
{
|
|
|
|
chain_offset = GET_UINT32 (cache->buffer, hash_offset + 4 + 4 * i);
|
|
|
|
while (chain_offset != 0xffffffff)
|
|
|
|
{
|
|
|
|
image_list_offset = GET_UINT32 (cache->buffer, chain_offset + 8);
|
|
|
|
n_images = GET_UINT32 (cache->buffer, image_list_offset);
|
|
|
|
|
|
|
|
for (j = 0; j < n_images; j++)
|
|
|
|
{
|
|
|
|
if (GET_UINT16 (cache->buffer, image_list_offset + 4 + 8 * j) ==
|
|
|
|
directory_index)
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
chain_offset = GET_UINT32 (cache->buffer, chain_offset);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2004-10-19 18:45:41 +00:00
|
|
|
void
|
|
|
|
_gtk_icon_cache_add_icons (GtkIconCache *cache,
|
|
|
|
const gchar *directory,
|
|
|
|
GHashTable *hash_table)
|
|
|
|
{
|
|
|
|
int directory_index;
|
|
|
|
guint32 hash_offset, n_buckets;
|
|
|
|
guint32 chain_offset;
|
|
|
|
guint32 image_list_offset, n_images;
|
|
|
|
int i, j;
|
|
|
|
|
|
|
|
directory_index = get_directory_index (cache, directory);
|
|
|
|
|
|
|
|
if (directory_index == -1)
|
|
|
|
return;
|
|
|
|
|
|
|
|
hash_offset = GET_UINT32 (cache->buffer, 4);
|
|
|
|
n_buckets = GET_UINT32 (cache->buffer, hash_offset);
|
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
|
|
|
|
2004-10-19 18:45:41 +00:00
|
|
|
for (i = 0; i < n_buckets; i++)
|
|
|
|
{
|
|
|
|
chain_offset = GET_UINT32 (cache->buffer, hash_offset + 4 + 4 * i);
|
|
|
|
while (chain_offset != 0xffffffff)
|
|
|
|
{
|
|
|
|
guint32 name_offset = GET_UINT32 (cache->buffer, chain_offset + 4);
|
|
|
|
gchar *name = cache->buffer + name_offset;
|
|
|
|
|
|
|
|
image_list_offset = GET_UINT32 (cache->buffer, chain_offset + 8);
|
|
|
|
n_images = GET_UINT32 (cache->buffer, image_list_offset);
|
|
|
|
|
|
|
|
for (j = 0; j < n_images; j++)
|
|
|
|
{
|
|
|
|
if (GET_UINT16 (cache->buffer, image_list_offset + 4 + 8 * j) ==
|
|
|
|
directory_index)
|
|
|
|
g_hash_table_insert (hash_table, name, NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
chain_offset = GET_UINT32 (cache->buffer, chain_offset);
|
|
|
|
}
|
2004-10-21 18:44:08 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
gboolean
|
|
|
|
_gtk_icon_cache_has_icon (GtkIconCache *cache,
|
|
|
|
const gchar *icon_name)
|
|
|
|
{
|
|
|
|
guint32 hash_offset;
|
|
|
|
guint32 n_buckets;
|
|
|
|
guint32 chain_offset;
|
|
|
|
gint hash;
|
2004-10-19 18:45:41 +00:00
|
|
|
|
2004-10-21 18:44:08 +00:00
|
|
|
hash_offset = GET_UINT32 (cache->buffer, 4);
|
|
|
|
n_buckets = GET_UINT32 (cache->buffer, hash_offset);
|
|
|
|
|
|
|
|
hash = icon_name_hash (icon_name) % n_buckets;
|
|
|
|
|
|
|
|
chain_offset = GET_UINT32 (cache->buffer, hash_offset + 4 + 4 * hash);
|
|
|
|
while (chain_offset != 0xffffffff)
|
|
|
|
{
|
|
|
|
guint32 name_offset = GET_UINT32 (cache->buffer, chain_offset + 4);
|
|
|
|
gchar *name = cache->buffer + name_offset;
|
|
|
|
|
|
|
|
if (strcmp (name, icon_name) == 0)
|
|
|
|
return TRUE;
|
|
|
|
|
|
|
|
chain_offset = GET_UINT32 (cache->buffer, chain_offset);
|
|
|
|
}
|
|
|
|
|
|
|
|
return FALSE;
|
2004-10-19 18:45:41 +00:00
|
|
|
}
|
2005-08-22 16:38:46 +00:00
|
|
|
|
2005-11-04 15:43:40 +00:00
|
|
|
gboolean
|
|
|
|
_gtk_icon_cache_has_icon_in_directory (GtkIconCache *cache,
|
|
|
|
const gchar *icon_name,
|
|
|
|
const gchar *directory)
|
|
|
|
{
|
|
|
|
guint32 hash_offset;
|
|
|
|
guint32 n_buckets;
|
|
|
|
guint32 chain_offset;
|
|
|
|
gint hash;
|
|
|
|
gboolean found_icon = FALSE;
|
|
|
|
gint directory_index;
|
|
|
|
|
|
|
|
directory_index = get_directory_index (cache, directory);
|
|
|
|
|
|
|
|
if (directory_index == -1)
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
hash_offset = GET_UINT32 (cache->buffer, 4);
|
|
|
|
n_buckets = GET_UINT32 (cache->buffer, hash_offset);
|
|
|
|
|
|
|
|
hash = icon_name_hash (icon_name) % n_buckets;
|
|
|
|
|
|
|
|
chain_offset = GET_UINT32 (cache->buffer, hash_offset + 4 + 4 * hash);
|
|
|
|
while (chain_offset != 0xffffffff)
|
|
|
|
{
|
|
|
|
guint32 name_offset = GET_UINT32 (cache->buffer, chain_offset + 4);
|
|
|
|
gchar *name = cache->buffer + name_offset;
|
|
|
|
|
|
|
|
if (strcmp (name, icon_name) == 0)
|
|
|
|
{
|
|
|
|
found_icon = TRUE;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
chain_offset = GET_UINT32 (cache->buffer, chain_offset);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (found_icon)
|
|
|
|
{
|
|
|
|
guint32 image_list_offset = GET_UINT32 (cache->buffer, chain_offset + 8);
|
|
|
|
guint32 n_images = GET_UINT32 (cache->buffer, image_list_offset);
|
|
|
|
guint32 image_offset = image_list_offset + 4;
|
|
|
|
gint i;
|
|
|
|
for (i = 0; i < n_images; i++)
|
|
|
|
{
|
|
|
|
guint16 index = GET_UINT16 (cache->buffer, image_offset);
|
|
|
|
|
|
|
|
if (index == directory_index)
|
|
|
|
return TRUE;
|
|
|
|
image_offset += 8;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2005-08-22 16:38:46 +00:00
|
|
|
static void
|
|
|
|
pixbuf_destroy_cb (guchar *pixels,
|
|
|
|
gpointer data)
|
|
|
|
{
|
|
|
|
GtkIconCache *cache = data;
|
|
|
|
|
|
|
|
_gtk_icon_cache_unref (cache);
|
|
|
|
}
|
|
|
|
|
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
|
|
|
GdkPixbuf *
|
|
|
|
_gtk_icon_cache_get_icon (GtkIconCache *cache,
|
|
|
|
const gchar *icon_name,
|
2007-12-03 17:44:27 +00:00
|
|
|
gint directory_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
|
|
|
{
|
|
|
|
guint32 offset, image_data_offset, pixel_data_offset;
|
|
|
|
guint32 length, type;
|
|
|
|
GdkPixbuf *pixbuf;
|
|
|
|
GdkPixdata pixdata;
|
|
|
|
GError *error = NULL;
|
|
|
|
|
2007-12-03 17:44:27 +00:00
|
|
|
offset = find_image_offset (cache, icon_name, directory_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
|
|
|
|
2012-01-12 11:14:02 +00:00
|
|
|
if (!offset)
|
|
|
|
return NULL;
|
|
|
|
|
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
|
|
|
image_data_offset = GET_UINT32 (cache->buffer, offset + 4);
|
|
|
|
|
|
|
|
if (!image_data_offset)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
pixel_data_offset = GET_UINT32 (cache->buffer, image_data_offset);
|
|
|
|
|
|
|
|
type = GET_UINT32 (cache->buffer, pixel_data_offset);
|
|
|
|
|
|
|
|
if (type != 0)
|
|
|
|
{
|
|
|
|
GTK_NOTE (ICONTHEME,
|
2006-10-08 05:07:55 +00:00
|
|
|
g_print ("invalid pixel data type %u\n", type));
|
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
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
length = GET_UINT32 (cache->buffer, pixel_data_offset + 4);
|
|
|
|
|
2014-10-27 11:05:22 +00:00
|
|
|
G_GNUC_BEGIN_IGNORE_DEPRECATIONS
|
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 (!gdk_pixdata_deserialize (&pixdata, length,
|
2007-05-01 20:00:17 +00:00
|
|
|
(guchar *)(cache->buffer + pixel_data_offset + 8),
|
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
|
|
|
&error))
|
|
|
|
{
|
|
|
|
GTK_NOTE (ICONTHEME,
|
|
|
|
g_print ("could not deserialize data: %s\n", error->message));
|
|
|
|
g_error_free (error);
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
2014-10-27 11:05:22 +00:00
|
|
|
G_GNUC_END_IGNORE_DEPRECATIONS
|
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-22 16:38:46 +00:00
|
|
|
pixbuf = gdk_pixbuf_new_from_data (pixdata.pixel_data, GDK_COLORSPACE_RGB,
|
|
|
|
(pixdata.pixdata_type & GDK_PIXDATA_COLOR_TYPE_MASK) == GDK_PIXDATA_COLOR_TYPE_RGBA,
|
|
|
|
8, pixdata.width, pixdata.height, pixdata.rowstride,
|
|
|
|
(GdkPixbufDestroyNotify)pixbuf_destroy_cb,
|
|
|
|
cache);
|
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 (!pixbuf)
|
|
|
|
{
|
|
|
|
GTK_NOTE (ICONTHEME,
|
|
|
|
g_print ("could not convert pixdata to pixbuf: %s\n", error->message));
|
|
|
|
g_error_free (error);
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2005-08-22 16:38:46 +00:00
|
|
|
_gtk_icon_cache_ref (cache);
|
|
|
|
|
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
|
|
|
return pixbuf;
|
|
|
|
}
|
|
|
|
|