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"
27 static void g_themed_icon_icon_iface_init (GIconIface *iface);
31 GObject parent_instance;
36 struct _GThemedIconClass
38 GObjectClass parent_class;
41 G_DEFINE_TYPE_WITH_CODE (GThemedIcon, g_themed_icon, G_TYPE_OBJECT,
42 G_IMPLEMENT_INTERFACE (G_TYPE_ICON,
43 g_themed_icon_icon_iface_init))
46 g_themed_icon_finalize (GObject *object)
50 themed = G_THEMED_ICON (object);
52 g_strfreev (themed->names);
54 if (G_OBJECT_CLASS (g_themed_icon_parent_class)->finalize)
55 (*G_OBJECT_CLASS (g_themed_icon_parent_class)->finalize) (object);
59 g_themed_icon_class_init (GThemedIconClass *klass)
61 GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
63 gobject_class->finalize = g_themed_icon_finalize;
67 g_themed_icon_init (GThemedIcon *themed)
75 * Returns: a new #GIcon.
78 g_themed_icon_new (const char *iconname)
82 g_return_val_if_fail (iconname != NULL, NULL);
84 themed = g_object_new (G_TYPE_THEMED_ICON, NULL);
85 themed->names = g_new (char *, 2);
86 themed->names[0] = g_strdup (iconname);
87 themed->names[1] = NULL;
89 return G_ICON (themed);
93 * g_themed_icon_new_from_names:
97 * Returns: a new #GIcon.
100 g_themed_icon_new_from_names (char **iconnames, int len)
105 g_return_val_if_fail (iconnames != NULL, NULL);
107 themed = g_object_new (G_TYPE_THEMED_ICON, NULL);
109 themed->names = g_strdupv (iconnames);
112 themed->names = g_new (char *, len + 1);
113 for (i = 0; i < len; i++)
114 themed->names[i] = g_strdup (iconnames[i]);
115 themed->names[i] = NULL;
119 return G_ICON (themed);
123 * g_themed_icon_get_names:
129 g_themed_icon_get_names (GThemedIcon *icon)
131 g_return_val_if_fail (G_IS_THEMED_ICON (icon), NULL);
132 return (const char * const *)icon->names;
136 g_themed_icon_hash (GIcon *icon)
138 GThemedIcon *themed = G_THEMED_ICON (icon);
144 for (i = 0; themed->names[i] != NULL; i++)
145 hash ^= g_str_hash (themed->names[i]);
151 g_themed_icon_equal (GIcon *icon1,
154 GThemedIcon *themed1 = G_THEMED_ICON (icon1);
155 GThemedIcon *themed2 = G_THEMED_ICON (icon2);
158 for (i = 0; themed1->names[i] != NULL && themed2->names[i] != NULL; i++)
160 if (!g_str_equal (themed1->names[i], themed2->names[i]))
164 return themed1->names[i] == NULL && themed2->names[i] == NULL;
168 g_themed_icon_icon_iface_init (GIconIface *iface)
170 iface->hash = g_themed_icon_hash;
171 iface->equal = g_themed_icon_equal;