Fixes unknown meaning in GAppLaunchContext docs. Clarify asynchronous ops.
[platform/upstream/glib.git] / gio / gthemedicon.c
1 /* GIO - GLib Input, Output and Streaming Library
2  * 
3  * Copyright (C) 2006-2007 Red Hat, Inc.
4  *
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.
9  *
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.
14  *
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.
19  *
20  * Author: Alexander Larsson <alexl@redhat.com>
21  */
22
23 #include <config.h>
24
25 #include "gthemedicon.h"
26
27 #include "gioalias.h"
28
29 /**
30  * SECTION:gthemedicon
31  * @short_description: icon theming support
32  * @see_also: #GIcon, #GLoadableIcon
33  *
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.
38  **/
39
40 static void g_themed_icon_icon_iface_init (GIconIface       *iface);
41
42 struct _GThemedIcon
43 {
44   GObject parent_instance;
45   
46   char **names;
47 };
48
49 struct _GThemedIconClass
50 {
51   GObjectClass parent_class;
52 };
53
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))
57   
58 static void
59 g_themed_icon_finalize (GObject *object)
60 {
61   GThemedIcon *themed;
62
63   themed = G_THEMED_ICON (object);
64
65   g_strfreev (themed->names);
66   
67   if (G_OBJECT_CLASS (g_themed_icon_parent_class)->finalize)
68     (*G_OBJECT_CLASS (g_themed_icon_parent_class)->finalize) (object);
69 }
70
71 static void
72 g_themed_icon_class_init (GThemedIconClass *klass)
73 {
74   GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
75   
76   gobject_class->finalize = g_themed_icon_finalize;
77 }
78
79 static void
80 g_themed_icon_init (GThemedIcon *themed)
81 {
82 }
83
84 /**
85  * g_themed_icon_new:
86  * @iconname: a string containing an icon name.
87  * 
88  * Creates a new themed icon for @iconname.
89  * 
90  * Returns: a new #GThemedIcon.
91  **/
92 GIcon *
93 g_themed_icon_new (const char *iconname)
94 {
95   GThemedIcon *themed;
96
97   g_return_val_if_fail (iconname != NULL, NULL);
98
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;
103   
104   return G_ICON (themed);
105 }
106
107 /**
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.
111  * 
112  * Creates a new themed icon for @iconnames.
113  * 
114  * Returns: a new #GThemedIcon.
115  **/
116 GIcon *
117 g_themed_icon_new_from_names (char **iconnames, int len)
118 {
119   GThemedIcon *themed;
120   int i;
121
122   g_return_val_if_fail (iconnames != NULL, NULL);
123   
124   themed = g_object_new (G_TYPE_THEMED_ICON, NULL);
125   if (len == -1)
126     themed->names = g_strdupv (iconnames);
127   else
128     {
129       themed->names = g_new (char *, len + 1);
130       for (i = 0; i < len; i++)
131         themed->names[i] = g_strdup (iconnames[i]);
132       themed->names[i] = NULL;
133     }
134   
135   
136   return G_ICON (themed);
137 }
138
139 /**
140  * g_themed_icon_get_names:
141  * @icon: a #GThemedIcon.
142  * 
143  * Gets the names of icons from within @icon.
144  * 
145  * Returns: a list of icon names.
146  **/
147 const char * const *
148 g_themed_icon_get_names (GThemedIcon *icon)
149 {
150   g_return_val_if_fail (G_IS_THEMED_ICON (icon), NULL);
151   return (const char * const *)icon->names;
152 }
153
154 static guint
155 g_themed_icon_hash (GIcon *icon)
156 {
157   GThemedIcon *themed = G_THEMED_ICON (icon);
158   guint hash;
159   int i;
160
161   hash = 0;
162
163   for (i = 0; themed->names[i] != NULL; i++)
164     hash ^= g_str_hash (themed->names[i]);
165   
166   return hash;
167 }
168
169 static gboolean
170 g_themed_icon_equal (GIcon *icon1,
171                     GIcon *icon2)
172 {
173   GThemedIcon *themed1 = G_THEMED_ICON (icon1);
174   GThemedIcon *themed2 = G_THEMED_ICON (icon2);
175   int i;
176
177   for (i = 0; themed1->names[i] != NULL && themed2->names[i] != NULL; i++)
178     {
179       if (!g_str_equal (themed1->names[i], themed2->names[i]))
180         return FALSE;
181     }
182
183   return themed1->names[i] == NULL && themed2->names[i] == NULL;
184 }
185
186 static void
187 g_themed_icon_icon_iface_init (GIconIface *iface)
188 {
189   iface->hash = g_themed_icon_hash;
190   iface->equal = g_themed_icon_equal;
191 }
192
193 #define __G_THEMED_ICON_C__
194 #include "gioaliasdef.c"