1 /* GIO - GLib Input, Output and Streaming Library
3 * Copyright (C) 2006-2007 Red Hat, Inc.
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Lesser General Public
7 * License as published by the Free Software Foundation; either
8 * version 2 of the License, or (at your option) any later version.
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Lesser General Public License for more details.
15 * You should have received a copy of the GNU Lesser General
16 * Public License along with this library; if not, write to the
17 * Free Software Foundation, Inc., 59 Temple Place, Suite 330,
18 * Boston, MA 02111-1307, USA.
20 * Author: Alexander Larsson <alexl@redhat.com>
25 #include "gthemedicon.h"
31 * @short_description: Icon theming support
32 * @see_also: #GIcon, #GLoadableIcon
34 * #GThemedIcon is an implementation of #GIcon that supports icon themes.
35 * #GThemedIcon contains a list of all of the icons present in an icon
36 * theme, so that icons can be looked up quickly. #GThemedIcon does
37 * not provide actual pixmaps for icons, just the icon names.
40 static void g_themed_icon_icon_iface_init (GIconIface *iface);
44 GObject parent_instance;
49 struct _GThemedIconClass
51 GObjectClass parent_class;
54 G_DEFINE_TYPE_WITH_CODE (GThemedIcon, g_themed_icon, G_TYPE_OBJECT,
55 G_IMPLEMENT_INTERFACE (G_TYPE_ICON,
56 g_themed_icon_icon_iface_init))
59 g_themed_icon_finalize (GObject *object)
63 themed = G_THEMED_ICON (object);
65 g_strfreev (themed->names);
67 if (G_OBJECT_CLASS (g_themed_icon_parent_class)->finalize)
68 (*G_OBJECT_CLASS (g_themed_icon_parent_class)->finalize) (object);
72 g_themed_icon_class_init (GThemedIconClass *klass)
74 GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
76 gobject_class->finalize = g_themed_icon_finalize;
80 g_themed_icon_init (GThemedIcon *themed)
86 * @iconname: a string containing an icon name.
88 * Creates a new themed icon for @iconname.
90 * Returns: a new #GThemedIcon.
93 g_themed_icon_new (const char *iconname)
97 g_return_val_if_fail (iconname != NULL, NULL);
99 themed = g_object_new (G_TYPE_THEMED_ICON, NULL);
100 themed->names = g_new (char *, 2);
101 themed->names[0] = g_strdup (iconname);
102 themed->names[1] = NULL;
104 return G_ICON (themed);
108 * g_themed_icon_new_from_names:
109 * @iconnames: an array of strings containing icon names.
110 * @len: the number of elements in the @iconnames array.
112 * Creates a new themed icon for @iconnames.
114 * Returns: a new #GThemedIcon.
117 g_themed_icon_new_from_names (char **iconnames,
123 g_return_val_if_fail (iconnames != NULL, NULL);
125 themed = g_object_new (G_TYPE_THEMED_ICON, NULL);
127 themed->names = g_strdupv (iconnames);
130 themed->names = g_new (char *, len + 1);
131 for (i = 0; i < len; i++)
132 themed->names[i] = g_strdup (iconnames[i]);
133 themed->names[i] = NULL;
137 return G_ICON (themed);
141 * g_themed_icon_get_names:
142 * @icon: a #GThemedIcon.
144 * Gets the names of icons from within @icon.
146 * Returns: a list of icon names.
149 g_themed_icon_get_names (GThemedIcon *icon)
151 g_return_val_if_fail (G_IS_THEMED_ICON (icon), NULL);
152 return (const char * const *)icon->names;
156 g_themed_icon_hash (GIcon *icon)
158 GThemedIcon *themed = G_THEMED_ICON (icon);
164 for (i = 0; themed->names[i] != NULL; i++)
165 hash ^= g_str_hash (themed->names[i]);
171 g_themed_icon_equal (GIcon *icon1,
174 GThemedIcon *themed1 = G_THEMED_ICON (icon1);
175 GThemedIcon *themed2 = G_THEMED_ICON (icon2);
178 for (i = 0; themed1->names[i] != NULL && themed2->names[i] != NULL; i++)
180 if (!g_str_equal (themed1->names[i], themed2->names[i]))
184 return themed1->names[i] == NULL && themed2->names[i] == NULL;
188 g_themed_icon_icon_iface_init (GIconIface *iface)
190 iface->hash = g_themed_icon_hash;
191 iface->equal = g_themed_icon_equal;
194 #define __G_THEMED_ICON_C__
195 #include "gioaliasdef.c"