1
/* GIO - GLib Input, Output and Streaming Library
3
* Copyright (C) 2008 Clemens N. Buss <cebuzz@gmail.com>
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.
28
#include "gioenumtypes.h"
34
* @short_description: An object for emblems
36
* @see_also: #GIcon, #GEmblemedIcon, #GLoadableIcon, #GThemedIcon
38
* #GEmblem is an implementation of #GIcon that supports
39
* having an emblem, which is an icon with additional properties.
40
* It can than be added to a #GEmblemedIcon.
42
* Currently, only metainformation about the emblem's origin is
43
* supported. More may be added in the future.
46
static void g_emblem_iface_init (GIconIface *iface);
50
GObject parent_instance;
58
GObjectClass parent_class;
68
G_DEFINE_TYPE_WITH_CODE (GEmblem, g_emblem, G_TYPE_OBJECT,
69
G_IMPLEMENT_INTERFACE (G_TYPE_ICON, g_emblem_iface_init))
72
g_emblem_get_property (GObject *object,
77
GEmblem *emblem = G_EMBLEM (object);
82
g_value_set_object (value, emblem->icon);
85
g_value_set_enum (value, emblem->origin);
89
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
95
g_emblem_set_property (GObject *object,
100
GEmblem *emblem = G_EMBLEM (object);
105
emblem->icon = g_value_get_object (value);
109
emblem->origin = g_value_get_enum (value);
113
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
119
g_emblem_finalize (GObject *object)
121
GEmblem *emblem = G_EMBLEM (object);
123
g_object_unref (emblem->icon);
125
(*G_OBJECT_CLASS (g_emblem_parent_class)->finalize) (object);
129
g_emblem_class_init (GEmblemClass *klass)
131
GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
133
gobject_class->finalize = g_emblem_finalize;
134
gobject_class->set_property = g_emblem_set_property;
135
gobject_class->get_property = g_emblem_get_property;
137
g_object_class_install_property (gobject_class,
139
g_param_spec_enum ("origin",
140
P_("GEmblem's origin"),
141
P_("Tells which origin the emblem is derived from"),
142
G_TYPE_EMBLEM_ORIGIN,
143
G_EMBLEM_ORIGIN_UNKNOWN,
144
G_PARAM_CONSTRUCT_ONLY | G_PARAM_READWRITE | G_PARAM_STATIC_NAME | G_PARAM_STATIC_BLURB | G_PARAM_STATIC_NICK));
146
g_object_class_install_property (gobject_class,
148
g_param_spec_object ("icon",
149
P_("The icon of the emblem"),
150
P_("The actual icon of the emblem"),
152
G_PARAM_CONSTRUCT_ONLY | G_PARAM_READWRITE | G_PARAM_STATIC_NAME | G_PARAM_STATIC_BLURB | G_PARAM_STATIC_NICK));
157
g_emblem_init (GEmblem *emblem)
163
* @icon: a GIcon containing the icon.
165
* Creates a new emblem for @icon.
167
* Returns: a new #GEmblem.
172
g_emblem_new (GIcon *icon)
176
g_return_val_if_fail (icon != NULL, NULL);
177
g_return_val_if_fail (G_IS_ICON (icon), NULL);
178
g_return_val_if_fail (!G_IS_EMBLEM (icon), NULL);
180
emblem = g_object_new (G_TYPE_EMBLEM, NULL);
181
emblem->icon = g_object_ref (icon);
182
emblem->origin = G_EMBLEM_ORIGIN_UNKNOWN;
188
* g_emblem_new_with_origin:
189
* @icon: a GIcon containing the icon.
190
* @origin: a GEmblemOrigin enum defining the emblem's origin
192
* Creates a new emblem for @icon.
194
* Returns: a new #GEmblem.
199
g_emblem_new_with_origin (GIcon *icon,
200
GEmblemOrigin origin)
204
g_return_val_if_fail (icon != NULL, NULL);
205
g_return_val_if_fail (G_IS_ICON (icon), NULL);
206
g_return_val_if_fail (!G_IS_EMBLEM (icon), NULL);
208
emblem = g_object_new (G_TYPE_EMBLEM, NULL);
209
emblem->icon = g_object_ref (icon);
210
emblem->origin = origin;
217
* @emblem: a #GEmblem from which the icon should be extracted.
219
* Gives back the icon from @emblem.
221
* Returns: a #GIcon. The returned object belongs to the emblem
222
* and should not be modified or freed.
227
g_emblem_get_icon (GEmblem *emblem)
229
g_return_val_if_fail (G_IS_EMBLEM (emblem), NULL);
236
* g_emblem_get_origin:
237
* @emblem: a #GEmblem
239
* Gets the origin of the emblem.
241
* Returns: the origin of the emblem
246
g_emblem_get_origin (GEmblem *emblem)
248
g_return_val_if_fail (G_IS_EMBLEM (emblem), G_EMBLEM_ORIGIN_UNKNOWN);
250
return emblem->origin;
254
g_emblem_hash (GIcon *icon)
256
GEmblem *emblem = G_EMBLEM (icon);
259
hash = g_icon_hash (g_emblem_get_icon (emblem));
260
hash ^= emblem->origin;
266
g_emblem_equal (GIcon *icon1,
269
GEmblem *emblem1 = G_EMBLEM (icon1);
270
GEmblem *emblem2 = G_EMBLEM (icon2);
272
return emblem1->origin == emblem2->origin &&
273
g_icon_equal (emblem1->icon, emblem2->icon);
277
g_emblem_iface_init (GIconIface *iface)
279
iface->hash = g_emblem_hash;
280
iface->equal = g_emblem_equal;
283
#define __G_EMBLEM_C__
284
#include "gioaliasdef.c"