aafa5034a95ff6e0352769f0c478c80ab162b50a
[platform/upstream/glib.git] / gio / gicon.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 #include "gicon.h"
25
26 #include "glibintl.h"
27
28 #include "gioalias.h"
29
30 /**
31  * SECTION:gicon
32  * @short_description: Interface for icons
33  * @include: gio/gio.h
34  *
35  * #GIcon is a very minimal interface for icons. It provides functions 
36  * for checking the equality of two icons and hashing of icons.
37  * 
38  * #GIcon does not provide the actual pixmap for the icon as this is out 
39  * of GIO's scope, however implementations of #GIcon may contain the name 
40  * of an icon (see #GThemedIcon), or the path to an icon (see #GLoadableIcon). 
41  * 
42  * To obtain a hash of a #GIcon, see g_icon_hash().
43  * 
44  * To check if two #GIcons are equal, see g_icon_equal().
45  **/
46
47 static void g_icon_base_init (gpointer g_class);
48 static void g_icon_class_init (gpointer g_class,
49                                gpointer class_data);
50
51 GType
52 g_icon_get_type (void)
53 {
54   static volatile gsize g_define_type_id__volatile = 0;
55
56   if (g_once_init_enter (&g_define_type_id__volatile))
57     {
58       const GTypeInfo icon_info =
59       {
60         sizeof (GIconIface), /* class_size */
61         g_icon_base_init,   /* base_init */
62         NULL,           /* base_finalize */
63         g_icon_class_init,
64         NULL,           /* class_finalize */
65         NULL,           /* class_data */
66         0,
67         0,              /* n_preallocs */
68         NULL
69       };
70       GType g_define_type_id =
71         g_type_register_static (G_TYPE_INTERFACE, I_("GIcon"),
72                                 &icon_info, 0);
73
74       g_type_interface_add_prerequisite (g_define_type_id, G_TYPE_OBJECT);
75
76       g_once_init_leave (&g_define_type_id__volatile, g_define_type_id);
77     }
78
79   return g_define_type_id__volatile;
80 }
81
82 static void
83 g_icon_class_init (gpointer g_class,
84                    gpointer class_data)
85 {
86 }
87
88 static void
89 g_icon_base_init (gpointer g_class)
90 {
91 }
92
93 /**
94  * g_icon_hash:
95  * @icon: #gconstpointer to an icon object.
96  * 
97  * Gets a hash for an icon.
98  * 
99  * Returns: a #guint containing a hash for the @icon, suitable for 
100  * use in a #GHashTable or similar data structure.
101  **/
102 guint
103 g_icon_hash (gconstpointer icon)
104 {
105   GIconIface *iface;
106
107   g_return_val_if_fail (G_IS_ICON (icon), 0);
108
109   iface = G_ICON_GET_IFACE (icon);
110
111   return (* iface->hash) ((GIcon *)icon);
112 }
113
114 /**
115  * g_icon_equal:
116  * @icon1: pointer to the first #GIcon.
117  * @icon2: pointer to the second #GIcon.
118  * 
119  * Checks if two icons are equal.
120  * 
121  * Returns: %TRUE if @icon1 is equal to @icon2. %FALSE otherwise.
122  **/
123 gboolean
124 g_icon_equal (GIcon *icon1,
125               GIcon *icon2)
126 {
127   GIconIface *iface;
128
129   if (icon1 == NULL && icon2 == NULL)
130     return TRUE;
131
132   if (icon1 == NULL || icon2 == NULL)
133     return FALSE;
134   
135   if (G_TYPE_FROM_INSTANCE (icon1) != G_TYPE_FROM_INSTANCE (icon2))
136     return FALSE;
137
138   iface = G_ICON_GET_IFACE (icon1);
139   
140   return (* iface->equal) (icon1, icon2);
141 }
142
143 #define __G_ICON_C__
144 #include "gioaliasdef.c"