GnomeIconTheme API patch
- From: Jeroen Zwartepoorte <jeroen xs4all nl>
- To: gnome-devtools gnome org
- Cc: gustavo giraldez gmx net
- Subject: GnomeIconTheme API patch
- Date: 27 Dec 2002 14:29:05 +0100
Hi Gustavo,
How are you?
I've written patches for gdl, gnome-build and the document-manager in
anjuta2 to use the new GnomeIconTheme API in libgnomeui. This API
standardizes how mimetype and folder icons can be retrieved.
Attached is a patch to gdl that modifies gdl-icons.[ch] to use the new
API. It also put all the methods in a new class (GdlIcons) with a
dispose handler so everything is cleaned up. Parameters are the icon
size (use for looking up icons) and the icon zoom (what scale do you
want the actual icon in). For now, only 24 (size) and 16.0 (zoom) are
used.
OK to commit the patch to gdl? If so, i'll commit patches to gnome-build
and anjuta2 to use the new API.
Thanks,
--
Jeroen Zwartepoorte <jeroen xs4all nl>
? icons.patch
Index: ChangeLog
===================================================================
RCS file: /cvs/gnome/gdl/ChangeLog,v
retrieving revision 1.85
diff -u -r1.85 ChangeLog
--- ChangeLog 23 Dec 2002 01:35:22 -0000 1.85
+++ ChangeLog 27 Dec 2002 13:21:49 -0000
@@ -1,3 +1,16 @@
+2002-12-27 Jeroen Zwartepoorte <jeroen xs4all nl>
+
+ * gdl/gdl-icons.c: (gdl_icons_get_property),
+ (gdl_icons_set_property), (gdl_icons_dispose),
+ (gdl_icons_class_init), (gdl_icons_instance_init), (gdl_icons_new),
+ (gdl_icons_get_folder_icon), (gdl_icons_get_uri_icon),
+ (gdl_icons_get_mime_icon): Use the new GnomeIconTheme API.
+ * gdl/gdl-icons.h: New GdlIcons class with dispose handler for cleanup.
+ * symbol-browser-control/symbol-browser.c:
+ (gsb_tree_node_set_pixbuf), (get_image_for_type_key),
+ (gnome_symbol_browser_init), (gnome_symbol_browser_finalize):
+ Uses the new gdl-icons API.
+
2002-12-23 Miloslav Trmac <mitr volny cz>
* configure.in (ALL_LINGUAS): Added Czech (cs).
Index: gdl/gdl-icons.c
===================================================================
RCS file: /cvs/gnome/gdl/gdl/gdl-icons.c,v
retrieving revision 1.4
diff -u -r1.4 gdl-icons.c
--- gdl/gdl-icons.c 9 Jun 2002 11:14:14 -0000 1.4
+++ gdl/gdl-icons.c 27 Dec 2002 13:21:49 -0000
@@ -18,427 +18,256 @@
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
* Boston, MA 02111-1307, USA.
*
+ * Authors: Dave Camp, Jeroen Zwartepoorte
*/
-#include <libgnomevfs/gnome-vfs-types.h>
-#include <libgnomevfs/gnome-vfs-uri.h>
-#include <libgnomevfs/gnome-vfs-mime-utils.h>
-#include <libgnomevfs/gnome-vfs-mime-handlers.h>
-#include <libgnomevfs/gnome-vfs-utils.h>
-#include <libgnomevfs/gnome-vfs-ops.h>
-#include <librsvg/rsvg.h>
-
#include <string.h>
-
-#include "program.xpm"
-#include "shared.xpm"
-#include "static.xpm"
-
-#include <math.h>
-
-#include "default-icon.h"
-
-#include <gconf/gconf-client.h>
-
+#include <libgnome/gnome-i18n.h>
+#include <libgnome/gnome-macros.h>
+#include <libgnomeui/gnome-icon-lookup.h>
+#include <libgnomevfs/gnome-vfs-ops.h>
#include "gdl-icons.h"
-#define ICON_SIZE 15
-#define LOAD_SIZE 24
-
-static const char *icon_file_name_suffixes[] =
-{
- ".svg",
- ".png",
- ".jpg",
+enum {
+ PROP_BOGUS,
+ PROP_ICON_SIZE,
+ PROP_ICON_ZOOM
};
-static char *theme_dir = NULL;
-GHashTable *pixbufs_by_name = NULL;
-GConfClient *gconf_client = NULL;
+struct _GdlIconsPrivate {
+ int icon_size;
+ double icon_zoom;
-static GdkPixbuf *
-scale_icon (GdkPixbuf *unscaled)
-{
- double ratio;
- GdkPixbuf *pixbuf;
- if (gdk_pixbuf_get_height (unscaled) == 0) {
- g_warning ("invalid pixmap: height of 0.\n");
- return NULL;
- }
- ratio = (double)gdk_pixbuf_get_width (unscaled) / (double) gdk_pixbuf_get_height (unscaled);
- pixbuf = gdk_pixbuf_scale_simple (unscaled,
- floor ((15 * ratio) + 0.5), 15,
- GDK_INTERP_BILINEAR);
- g_object_unref (G_OBJECT (unscaled));
- return pixbuf;
-
-}
-
-static char *
-make_icon_name_from_mime_type (const char *mime_type)
-{
- char *icon_name = g_strdup_printf ("gnome-%s", mime_type);
- char *p;
-
- for (p = icon_name; *p != '\0'; p++) {
- if (*p == '/') *p = '-';
- }
-
- return icon_name;
-}
+ GnomeIconTheme *icon_theme;
+ GHashTable *icons;
+};
-static char *
-remove_icon_file_name_suffix (const char *icon_name)
-{
- int i;
- const char *suffix;
- int len;
+GNOME_CLASS_BOILERPLATE (GdlIcons, gdl_icons, GObject, G_TYPE_OBJECT);
- if (!icon_name) {
- return NULL;
+static void
+gdl_icons_get_property (GObject *object,
+ guint prop_id,
+ GValue *value,
+ GParamSpec *pspec)
+{
+ GdlIcons *icons = GDL_ICONS (object);
+
+ switch (prop_id) {
+ case PROP_ICON_SIZE:
+ g_value_set_int (value, icons->priv->icon_size);
+ break;
+ case PROP_ICON_ZOOM:
+ g_value_set_double (value, icons->priv->icon_zoom);
+ break;
+ default:
+ G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
}
-
- len = strlen (icon_name);
-
- for (i = 0; i < G_N_ELEMENTS (icon_file_name_suffixes); i++) {
- suffix = icon_file_name_suffixes[i];
- if (!strcmp (icon_name + (len - strlen (suffix)),
- suffix)) {
- return g_strndup (icon_name, len - strlen (suffix));
- }
- }
- return g_strdup (icon_name);
}
-static char *
-get_mime_type_icon_without_suffix (const char *mime_type)
-{
- return remove_icon_file_name_suffix (gnome_vfs_mime_get_icon (mime_type));
-}
-
-static char *
-get_icon_name_for_file (GnomeVFSFileInfo *info)
-{
- char *name;
- switch (info->type) {
- case GNOME_VFS_FILE_TYPE_DIRECTORY:
- return g_strdup ("i-directory");
- case GNOME_VFS_FILE_TYPE_FIFO:
- return g_strdup ("i-fifo");
- case GNOME_VFS_FILE_TYPE_SOCKET:
- return g_strdup ("i-sock");
- case GNOME_VFS_FILE_TYPE_CHARACTER_DEVICE:
- return g_strdup ("i-chardev");
- case GNOME_VFS_FILE_TYPE_BLOCK_DEVICE:
- return g_strdup ("i-blockdev");
- case GNOME_VFS_FILE_TYPE_SYMBOLIC_LINK:
- /* Non-broken symbolic links return the target's type. */
- return g_strdup ("i-symlink");
- case GNOME_VFS_FILE_TYPE_REGULAR:
- case GNOME_VFS_FILE_TYPE_UNKNOWN:
- default:
- name = get_mime_type_icon_without_suffix (info->mime_type);
- if (!name) {
- name = make_icon_name_from_mime_type (info->mime_type);
- }
- if (!name) {
- name = g_strdup ("i-regular");
- }
- return name;
- }
-}
-
-static char *
-get_theme_dir (const char *theme_name)
-{
- char *path;
-
- path = g_strdup_printf (NAUTILUS_THEMEDIR "/%s",
- theme_name);
-
- if (!g_file_test (path, G_FILE_TEST_IS_DIR)) {
- g_free (path);
- path = g_strdup_printf ("%s/.nautilus/themes/%s",
- g_get_home_dir (), theme_name);
- }
-
- if (!g_file_test (path, G_FILE_TEST_IS_DIR)) {
- g_free (path);
- path = NULL;
+static void
+gdl_icons_set_property (GObject *object,
+ guint prop_id,
+ const GValue *value,
+ GParamSpec *pspec)
+{
+ GdlIcons *icons = GDL_ICONS (object);
+
+ switch (prop_id) {
+ case PROP_ICON_SIZE:
+ icons->priv->icon_size = g_value_get_int (value);
+ g_hash_table_destroy (icons->priv->icons);
+ icons->priv->icons = g_hash_table_new_full (g_str_hash, g_str_equal,
+ (GDestroyNotify)g_free,
+ (GDestroyNotify)gdk_pixbuf_unref);
+ break;
+ case PROP_ICON_ZOOM:
+ icons->priv->icon_zoom = g_value_get_double (value);
+ g_hash_table_destroy (icons->priv->icons);
+ icons->priv->icons = g_hash_table_new_full (g_str_hash, g_str_equal,
+ (GDestroyNotify)g_free,
+ (GDestroyNotify)gdk_pixbuf_unref);
+ break;
+ default:
+ break;
}
-
- return path;
}
static void
-initialize_special ()
+gdl_icons_dispose (GObject *object)
{
- GdkPixbuf *pixbuf;
-
- pixbuf = scale_icon (gdk_pixbuf_new_from_xpm_data ((const char**)program_xpm));
- g_hash_table_insert (pixbufs_by_name, g_strdup ("program"), pixbuf);
- pixbuf = scale_icon (gdk_pixbuf_new_from_xpm_data ((const char**)shared_xpm));
- g_hash_table_insert (pixbufs_by_name, g_strdup ("shared_lib"), pixbuf);
- pixbuf = scale_icon (gdk_pixbuf_new_from_xpm_data ((const char**)static_xpm));
- g_hash_table_insert (pixbufs_by_name, g_strdup ("static_lib"), pixbuf);
-}
+ GdlIcons *icons = GDL_ICONS (object);
+ GdlIconsPrivate *priv = icons->priv;
-static void
-reload_theme (const char *theme_name)
-{
- if (theme_dir) {
- g_free (theme_dir);
- theme_dir = NULL;
- }
-
- if (pixbufs_by_name) {
- g_hash_table_destroy (pixbufs_by_name);
- }
-
- pixbufs_by_name = g_hash_table_new_full (g_str_hash,
- g_str_equal,
- (GDestroyNotify)g_free,
- (GDestroyNotify)g_object_unref);
-
- if (gconf_client == NULL) {
- gconf_client = gconf_client_get_default ();
- }
+ if (priv) {
+ g_object_unref (priv->icon_theme);
+ g_hash_table_destroy (priv->icons);
- if (theme_name == NULL) {
- char *name = gconf_client_get_string (gconf_client,
- "/desktop/gnome/file_views/icon_theme",
- NULL);
- if (name) {
- theme_dir = get_theme_dir (name);
- g_free (name);
- } else {
- theme_dir = get_theme_dir ("default");
- }
- } else {
- theme_dir = get_theme_dir (theme_name);
+ g_free (priv);
+ icons->priv = NULL;
}
+}
- initialize_special ();
-
-}
-
-static char *
-get_themed_icon_file_path (const char *theme_dir,
- const char *icon_name,
- unsigned size)
+static void
+gdl_icons_class_init (GdlIconsClass *klass)
{
- char *themed_icon_name, *path = NULL;
- int i;
+ GObjectClass *object_class = (GObjectClass *) klass;
- if (icon_name[0] == '/') {
- themed_icon_name = g_strdup (icon_name);
- } else {
- themed_icon_name = g_strconcat (theme_dir, "/",
- icon_name, NULL);
- }
+ parent_class = g_type_class_peek_parent (klass);
- for (i = 0; i < G_N_ELEMENTS (icon_file_name_suffixes); i++) {
- if (strcmp (icon_file_name_suffixes[i], ".svg") != 0
- && size != -1) {
- path = g_strdup_printf ("%s-%u%s",
- themed_icon_name,
- size,
- icon_file_name_suffixes[i]);
- } else {
- path = g_strdup_printf ("%s%s",
- themed_icon_name,
- icon_file_name_suffixes[i]);
- }
-
- if (g_file_test (path, G_FILE_TEST_EXISTS)) {
- break;
- }
-
- g_free (path);
- path = NULL;
- }
- g_free (themed_icon_name);
-
- return path;
+ object_class->dispose = gdl_icons_dispose;
+ object_class->get_property = gdl_icons_get_property;
+ object_class->set_property = gdl_icons_set_property;
+
+ g_object_class_install_property (object_class, PROP_ICON_SIZE,
+ g_param_spec_int ("icon-size",
+ _("Icon size"),
+ _("Icon size"),
+ 12, 192, 24,
+ G_PARAM_READWRITE));
+ g_object_class_install_property (object_class, PROP_ICON_ZOOM,
+ g_param_spec_double ("icon-zoom",
+ _("Icon zoom"),
+ _("Icon zoom"),
+ 1.0, 256.0, 24.0,
+ G_PARAM_READWRITE));
}
-
-static char *
-find_themed_icon_filename (const char *theme_dir, const char *name)
+static void
+gdl_icons_instance_init (GdlIcons *icons)
{
- char *path;
- char *name_with_modifier = g_strdup_printf ("%s-aa", name);
-
- path = get_themed_icon_file_path (theme_dir, name_with_modifier,
- LOAD_SIZE);
- if (path != NULL) {
- g_free (name_with_modifier);
- return path;
- }
+ GdlIconsPrivate *priv;
- path = get_themed_icon_file_path (theme_dir, name, LOAD_SIZE);
- if (path != NULL) {
- g_free (name_with_modifier);
- return path;
- }
+ priv = g_new0 (GdlIconsPrivate, 1);
+ icons->priv = priv;
- path = get_themed_icon_file_path (theme_dir, name_with_modifier, -1);
- if (path != NULL) {
- g_free (name_with_modifier);
- return path;
- }
-
- path = get_themed_icon_file_path (theme_dir, name, -1);
- if (path != NULL) {
- g_free (name_with_modifier);
- return path;
- }
-
- g_free (name_with_modifier);
- return NULL;
+ priv->icon_theme = gnome_icon_theme_new ();
+ priv->icons = g_hash_table_new_full (g_str_hash, g_str_equal,
+ (GDestroyNotify)g_free,
+ (GDestroyNotify)gdk_pixbuf_unref);
}
-static char *
-get_icon_filename (const char *icon_name)
+GdlIcons *
+gdl_icons_new (int icon_size,
+ double icon_zoom)
{
- char *path = find_themed_icon_filename (theme_dir, icon_name);
- if (!path) {
- path = find_themed_icon_filename (GNOME_VFS_ICONDIR,
- icon_name);
- }
- if (!path) {
- path = find_themed_icon_filename (theme_dir, "i-regular");
- }
- if (!path) {
- path = find_themed_icon_filename (GNOME_VFS_ICONDIR,
- "i-regular");
- }
-
- return path;
+ return GDL_ICONS (g_object_new (GDL_TYPE_ICONS,
+ "icon-size", icon_size,
+ "icon-zoom", icon_zoom,
+ NULL));
}
-static gboolean
-path_is_svg (const char *path)
+GdkPixbuf *
+gdl_icons_get_folder_icon (GdlIcons *icons)
{
- char *uri;
- GnomeVFSFileInfo *file_info;
- gboolean is_svg;
-
- /* Sync. file I/O is OK here because this is used only for installed
- * icons, not for the general case which could include icons on devices
- * other than the local hard disk.
- */
-
- uri = gnome_vfs_get_uri_from_local_path (path);
- file_info = gnome_vfs_file_info_new ();
- gnome_vfs_get_file_info (uri, file_info,
- GNOME_VFS_FILE_INFO_GET_MIME_TYPE
- | GNOME_VFS_FILE_INFO_FOLLOW_LINKS);
- g_free (uri);
- is_svg = strcmp (file_info->mime_type, "image/svg") == 0;
- gnome_vfs_file_info_unref (file_info);
+ g_return_val_if_fail (icons != NULL, NULL);
+ g_return_val_if_fail (GDL_IS_ICONS (icons), NULL);
- return is_svg;
+ return gdl_icons_get_mime_icon (icons, "application/directory-normal");
}
-#define NAUTILUS_ICON_SIZE_STANDARD 48
-
-static GdkPixbuf *
-pixbuf_for_name (const char *name)
+GdkPixbuf *
+gdl_icons_get_uri_icon (GdlIcons *icons,
+ const char *uri)
{
- GdkPixbuf *pixbuf = NULL;
- char *path;
+ GnomeVFSFileInfo *info;
+ GdkPixbuf *pixbuf;
- if (!theme_dir) {
- reload_theme (NULL);
- }
+ g_return_val_if_fail (icons != NULL, NULL);
+ g_return_val_if_fail (GDL_IS_ICONS (icons), NULL);
+ g_return_val_if_fail (uri != NULL, NULL);
- pixbuf = g_hash_table_lookup (pixbufs_by_name, name);
- if (pixbuf) {
- return g_object_ref (pixbuf);
- }
-
- path = get_icon_filename (name);
-
- if (path) {
- if (path_is_svg (path)) {
- double zoom = (double)ICON_SIZE / NAUTILUS_ICON_SIZE_STANDARD;
- pixbuf = scale_icon (rsvg_pixbuf_from_file_at_zoom (path, zoom, zoom, NULL));
- } else {
- pixbuf = scale_icon (gdk_pixbuf_new_from_file (path, NULL));
- }
- g_free (path);
- }
-
- if (!pixbuf) {
- pixbuf = gdk_pixbuf_new_from_data (default_icon,
- GDK_COLORSPACE_RGB,
- TRUE,
- 8,
- default_icon_width,
- default_icon_height,
- default_icon_width * 4, /* stride */
- NULL, /* don't destroy data */
- NULL);
- pixbuf = scale_icon (pixbuf);
- }
- g_hash_table_insert (pixbufs_by_name, g_strdup (name), pixbuf);
-
- g_object_ref (pixbuf);
+ info = gnome_vfs_file_info_new ();
+ gnome_vfs_get_file_info (uri, info,
+ GNOME_VFS_FILE_INFO_FOLLOW_LINKS |
+ GNOME_VFS_FILE_INFO_GET_MIME_TYPE |
+ GNOME_VFS_FILE_INFO_FORCE_FAST_MIME_TYPE);
+ if (info->mime_type)
+ pixbuf = gdl_icons_get_mime_icon (icons, info->mime_type);
+ else
+ pixbuf = gdl_icons_get_mime_icon (icons, "gnome-fs-regular");
+ gnome_vfs_file_info_unref (info);
return pixbuf;
}
GdkPixbuf *
-gdl_icon_for_mime (const char *mime_type)
+gdl_icons_get_mime_icon (GdlIcons *icons,
+ const char *mime_type)
{
- char *name;
- GdkPixbuf *ret;
- name = get_mime_type_icon_without_suffix (mime_type);
- if (!name) {
- name = make_icon_name_from_mime_type (mime_type);
- }
- if (!name) {
- name = g_strdup ("i-regular");
- }
- ret = pixbuf_for_name (name);
- g_free (name);
+ GdkPixbuf *pixbuf;
+ char *icon_name;
+ char *icon_path;
- return ret;
-}
+ g_return_val_if_fail (icons != NULL, NULL);
+ g_return_val_if_fail (GDL_IS_ICONS (icons), NULL);
+ g_return_val_if_fail (mime_type != NULL, NULL);
-GdkPixbuf *
-gdl_icon_for_uri (const char *uri)
-{
- GnomeVFSFileInfo *info;
- char *name;
- GdkPixbuf *pixbuf = NULL;
-
- info = gnome_vfs_file_info_new ();
+ pixbuf = g_hash_table_lookup (icons->priv->icons, mime_type);
+ if (pixbuf != NULL) {
+ g_object_ref (G_OBJECT (pixbuf));
+ return pixbuf;
+ }
- gnome_vfs_get_file_info (uri, info,
- GNOME_VFS_FILE_INFO_FOLLOW_LINKS | GNOME_VFS_FILE_INFO_GET_MIME_TYPE | GNOME_VFS_FILE_INFO_FORCE_FAST_MIME_TYPE);
+ if (!strcmp (mime_type, "application/directory-normal")) {
+ icon_name = g_strdup ("gnome-fs-directory");
+ } else {
+ icon_name = gnome_icon_lookup (icons->priv->icon_theme,
+ NULL,
+ NULL,
+ NULL,
+ NULL,
+ mime_type,
+ GNOME_ICON_LOOKUP_FLAGS_NONE,
+ NULL);
+ }
- name = get_icon_name_for_file (info);
-
- pixbuf = pixbuf_for_name (name);
- g_free (name);
+ if (!icon_name) {
+ /* Return regular icon if one doesn't exist for mime type. */
+ return gdl_icons_get_mime_icon (icons, "gnome-fs-regular");
+ } else {
+ icon_path = gnome_icon_theme_lookup_icon (icons->priv->icon_theme,
+ icon_name,
+ icons->priv->icon_size,
+ NULL,
+ NULL);
+
+ if (!icon_path) {
+ /* Return regular icon if one doesn't exist. */
+ return gdl_icons_get_mime_icon (icons, "gnome-fs-regular");
+ } else {
+ pixbuf = gdk_pixbuf_new_from_file (icon_path, NULL);
+ if (pixbuf != NULL) {
+ GdkPixbuf *scaled;
+ int new_w, new_h;
+ int w, h;
+ double factor;
+
+ w = gdk_pixbuf_get_width (pixbuf);
+ h = gdk_pixbuf_get_height (pixbuf);
+
+ factor = MIN (icons->priv->icon_zoom / w,
+ icons->priv->icon_zoom / h);
+ new_w = MAX ((int) (factor * w), 1);
+ new_h = MAX ((int) (factor * h), 1);
+
+ scaled = gdk_pixbuf_scale_simple (pixbuf,
+ new_w,
+ new_h,
+ GDK_INTERP_BILINEAR);
+ g_object_unref (pixbuf);
+ pixbuf = scaled;
+ } else {
+ /* Return regular icon if pixbuf doesn't exist. */
+ return gdl_icons_get_mime_icon (icons, "gnome-fs-regular");
+ }
+ }
+ }
- gnome_vfs_file_info_unref (info);
-
- return pixbuf;
-}
+ g_hash_table_insert (icons->priv->icons, g_strdup (mime_type), pixbuf);
+ g_object_ref (pixbuf);
-GdkPixbuf *
-gdl_icon_for_folder (void)
-{
- return pixbuf_for_name ("i-directory");
-}
+ g_free (icon_path);
+ g_free (icon_name);
-GdkPixbuf *
-gdl_icon_for_special (const char *name)
-{
- return pixbuf_for_name (name);
+ return pixbuf;
}
-
-
Index: gdl/gdl-icons.h
===================================================================
RCS file: /cvs/gnome/gdl/gdl/gdl-icons.h,v
retrieving revision 1.1
diff -u -r1.1 gdl-icons.h
--- gdl/gdl-icons.h 10 Mar 2002 20:52:00 -0000 1.1
+++ gdl/gdl-icons.h 27 Dec 2002 13:21:49 -0000
@@ -19,28 +19,47 @@
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
* Boston, MA 02111-1307, USA.
*
- * Authors: JP Rosevear, Dave Camp
+ * Authors: JP Rosevear, Dave Camp, Jeroen Zwartepoorte
*/
#ifndef _GDL_ICONS_H_
#define _GDL_ICONS_H_
-#include <glib.h>
+#include <glib-object.h>
#include <gdk-pixbuf/gdk-pixbuf.h>
G_BEGIN_DECLS
-GdkPixbuf *gdl_icon_for_folder (void);
-GdkPixbuf *gdl_icon_for_uri (const char *uri);
-GdkPixbuf *gdl_icon_for_special (const char *name);
-GdkPixbuf *gdl_icon_for_mime (const char *mime_type);
+#define GDL_TYPE_ICONS (gdl_icons_get_type ())
+#define GDL_ICONS(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GDL_TYPE_ICONS, GdlIcons))
+#define GDL_ICONS_CLASS(obj) (G_TYPE_CHECK_CLASS_CAST ((klass), GDL_TYPE_ICONS, GdlIconsClass))
+#define GDL_IS_ICONS(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GDL_TYPE_ICONS))
+#define GDL_IS_ICONS_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((obj), GDL_TYPE_ICONS))
+
+typedef struct _GdlIcons GdlIcons;
+typedef struct _GdlIconsPrivate GdlIconsPrivate;
+typedef struct _GdlIconsClass GdlIconsClass;
+
+struct _GdlIcons {
+ GObject parent;
+
+ GdlIconsPrivate *priv;
+};
+
+struct _GdlIconsClass {
+ GObjectClass parent_class;
+};
+
+GType gdl_icons_get_type (void);
+GdlIcons *gdl_icons_new (int icon_size,
+ double icon_zoom);
+
+GdkPixbuf *gdl_icons_get_folder_icon (GdlIcons *icons);
+GdkPixbuf *gdl_icons_get_uri_icon (GdlIcons *icons,
+ const char *uri);
+GdkPixbuf *gdl_icons_get_mime_icon (GdlIcons *icons,
+ const char *mime_type);
G_END_DECLS
#endif /* _GDL_ICONS_H_ */
-
-
-
-
-
-
Index: symbol-browser-control/symbol-browser.c
===================================================================
RCS file: /cvs/gnome/gdl/symbol-browser-control/symbol-browser.c,v
retrieving revision 1.5
diff -u -r1.5 symbol-browser.c
--- symbol-browser-control/symbol-browser.c 14 Apr 2002 13:57:26 -0000 1.5
+++ symbol-browser-control/symbol-browser.c 27 Dec 2002 13:21:51 -0000
@@ -96,6 +96,8 @@
BonoboListener *listener;
BonoboEventSource *event_source;
+
+ GdlIcons *icons;
};
typedef enum {
@@ -118,7 +120,8 @@
static void gnome_symbol_browser_finalize (GObject *obj);
-static GdkPixbuf *get_image_for_type_key (gchar *type_name);
+static GdkPixbuf *get_image_for_type_key (GnomeSymbolBrowser *gsb,
+ gchar *type_name);
static gchar *get_tag_type_name (TMTagType type);
static gchar *get_tag_type_name_key (TMSymbol *symbol);
static gboolean gsb_goto_tag (GnomeSymbolBrowser* gsb, const gchar* qual_name);
@@ -327,15 +330,15 @@
switch (node->type) {
case GSB_TREE_FOLDER:
- pixbuf = get_image_for_type_key ("Folders");
+ pixbuf = get_image_for_type_key (GNOME_SYMBOL_BROWSER (data), "Folders");
break;
case GSB_TREE_ROOT:
type_key = get_tag_type_name_key(node->symbol);
- pixbuf = get_image_for_type_key (type_key);
+ pixbuf = get_image_for_type_key (GNOME_SYMBOL_BROWSER (data), type_key);
break;
case GSB_TREE_SYMBOL:
type_key = get_tag_type_name_key(node->symbol);
- pixbuf = get_image_for_type_key (type_key);
+ pixbuf = get_image_for_type_key (GNOME_SYMBOL_BROWSER (data), type_key);
break;
}
@@ -443,7 +446,8 @@
* Utility Functions
* ---------------------------------------------------------------------- */
static GdkPixbuf *
-get_image_for_type_key (gchar *type_name_key)
+get_image_for_type_key (GnomeSymbolBrowser *gsb,
+ gchar *type_name_key)
{
static GHashTable *icons = NULL;
GdkPixbuf *pixbuf;
@@ -452,10 +456,9 @@
icons = g_hash_table_new (g_str_hash, g_str_equal);
- pixbuf = gdl_icon_for_folder ();
+ pixbuf = gdl_icons_get_folder_icon (gsb->priv->icons);
+ g_object_ref (pixbuf);
g_hash_table_insert (icons, g_strdup ("Tags"), pixbuf);
-
- pixbuf = gdl_icon_for_folder ();
g_hash_table_insert (icons, g_strdup ("Folders"), pixbuf);
pixbuf = gdk_pixbuf_new_from_xpm_data ((const char**)sv_unknown_xpm);
@@ -838,7 +841,7 @@
gtk_tree_view_column_set_cell_data_func (column,
renderer,
gsb_tree_node_set_pixbuf,
- NULL,
+ sb,
NULL);
renderer = gtk_cell_renderer_text_new ();
@@ -846,7 +849,7 @@
gtk_tree_view_column_set_cell_data_func (column,
renderer,
gsb_tree_node_set_text,
- NULL,
+ sb,
NULL);
gtk_tree_view_append_column (GTK_TREE_VIEW (priv->tree), column);
@@ -870,6 +873,7 @@
priv->project = NULL;
priv->tm_file = NULL;
priv->event_source = bonobo_event_source_new ();
+ priv->icons = gdl_icons_new (24, 16.0);
}
static void
@@ -886,7 +890,8 @@
g_hash_table_destroy (gsb->priv->symbol_hash);
gtk_widget_unref(gsb->priv->symbol_combo);
-
+ g_object_unref (gsb->priv->icons);
+
g_free (gsb->priv);
G_OBJECT_CLASS (parent_class)->finalize (object);
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]