~ubuntu-branches/debian/squeeze/glib2.0/squeeze

« back to all changes in this revision

Viewing changes to gio/gemblem.c

  • Committer: Bazaar Package Importer
  • Author(s): Gustavo Noronha Silva
  • Date: 2009-02-15 13:00:43 UTC
  • mfrom: (1.3.1 upstream) (69.1.10 intrepid)
  • Revision ID: james.westby@ubuntu.com-20090215130043-q47fbt3owmt42m2f
Tags: 2.18.4-2
* Release to unstable
* debian/rules:
- bump SHVER, since we are already forcing a 2.18.0 dependecy on the
  symbols introduced in the development versions
* debian/control.in:
- added Homepage and Vcs-* control fields

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* GIO - GLib Input, Output and Streaming Library
 
2
 * 
 
3
 * Copyright (C) 2008 Clemens N. Buss <cebuzz@gmail.com>
 
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
 */
 
21
 
 
22
#include <config.h>
 
23
 
 
24
#include "gicon.h"
 
25
#include "gemblem.h"
 
26
#include "glibintl.h"
 
27
#include "gioenums.h"
 
28
#include "gioenumtypes.h"
 
29
 
 
30
#include "gioalias.h"
 
31
 
 
32
/**
 
33
 * SECTION:gemblem
 
34
 * @short_description: An object for emblems
 
35
 * @include: gio/gio.h
 
36
 * @see_also: #GIcon, #GEmblemedIcon, #GLoadableIcon, #GThemedIcon
 
37
 *
 
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.
 
41
 *
 
42
 * Currently, only metainformation about the emblem's origin is 
 
43
 * supported. More may be added in the future.
 
44
 **/
 
45
 
 
46
static void g_emblem_iface_init (GIconIface *iface);
 
47
 
 
48
struct _GEmblem
 
49
{
 
50
  GObject parent_instance;
 
51
 
 
52
  GIcon *icon;
 
53
  GEmblemOrigin origin;
 
54
};
 
55
 
 
56
struct _GEmblemClass
 
57
{
 
58
  GObjectClass parent_class;
 
59
};
 
60
 
 
61
enum
 
62
{
 
63
  PROP_0_GEMBLEM,
 
64
  PROP_ICON,
 
65
  PROP_ORIGIN
 
66
};
 
67
 
 
68
G_DEFINE_TYPE_WITH_CODE (GEmblem, g_emblem, G_TYPE_OBJECT,
 
69
                         G_IMPLEMENT_INTERFACE (G_TYPE_ICON, g_emblem_iface_init))
 
70
 
 
71
static void
 
72
g_emblem_get_property (GObject    *object, 
 
73
                       guint       prop_id, 
 
74
                       GValue     *value, 
 
75
                       GParamSpec *pspec)
 
76
{
 
77
  GEmblem *emblem = G_EMBLEM (object);
 
78
        
 
79
  switch (prop_id)
 
80
    {
 
81
      case PROP_ICON:
 
82
        g_value_set_object (value, emblem->icon);
 
83
 
 
84
      case PROP_ORIGIN:
 
85
        g_value_set_enum (value, emblem->origin);
 
86
        break;
 
87
 
 
88
      default:
 
89
        G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
 
90
        break;
 
91
  }   
 
92
}
 
93
 
 
94
static void
 
95
g_emblem_set_property (GObject      *object,
 
96
                       guint         prop_id,
 
97
                       const GValue *value,
 
98
                       GParamSpec   *pspec)
 
99
{
 
100
  GEmblem *emblem = G_EMBLEM (object);
 
101
 
 
102
  switch (prop_id)
 
103
    {
 
104
      case PROP_ICON:
 
105
        emblem->icon = g_value_get_object (value);
 
106
        break;
 
107
 
 
108
      case PROP_ORIGIN:
 
109
        emblem->origin = g_value_get_enum (value);
 
110
        break;
 
111
 
 
112
      default:
 
113
        G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
 
114
        break;
 
115
    }
 
116
}
 
117
 
 
118
static void
 
119
g_emblem_finalize (GObject *object)
 
120
{
 
121
  GEmblem *emblem = G_EMBLEM (object);
 
122
 
 
123
  g_object_unref (emblem->icon);
 
124
 
 
125
  (*G_OBJECT_CLASS (g_emblem_parent_class)->finalize) (object);
 
126
}
 
127
 
 
128
static void
 
129
g_emblem_class_init (GEmblemClass *klass)
 
130
{
 
131
  GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
 
132
  
 
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;
 
136
 
 
137
  g_object_class_install_property (gobject_class, 
 
138
                                   PROP_ORIGIN,
 
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));
 
145
 
 
146
  g_object_class_install_property (gobject_class,
 
147
                                   PROP_ICON,
 
148
                                   g_param_spec_object ("icon",
 
149
                                                      P_("The icon of the emblem"),
 
150
                                                      P_("The actual icon of the emblem"),
 
151
                                                      G_TYPE_OBJECT,
 
152
                                                      G_PARAM_CONSTRUCT_ONLY | G_PARAM_READWRITE | G_PARAM_STATIC_NAME | G_PARAM_STATIC_BLURB | G_PARAM_STATIC_NICK));
 
153
 
 
154
}
 
155
 
 
156
static void
 
157
g_emblem_init (GEmblem *emblem)
 
158
{
 
159
}
 
160
 
 
161
/**
 
162
 * g_emblem_new:
 
163
 * @icon: a GIcon containing the icon.
 
164
 * 
 
165
 * Creates a new emblem for @icon.
 
166
 * 
 
167
 * Returns: a new #GEmblem.
 
168
 *
 
169
 * Since: 2.18
 
170
 **/
 
171
GEmblem *
 
172
g_emblem_new (GIcon *icon)
 
173
{
 
174
  GEmblem* emblem;
 
175
 
 
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);
 
179
 
 
180
  emblem = g_object_new (G_TYPE_EMBLEM, NULL);
 
181
  emblem->icon = g_object_ref (icon);
 
182
  emblem->origin = G_EMBLEM_ORIGIN_UNKNOWN;
 
183
 
 
184
  return emblem;
 
185
}
 
186
 
 
187
/**
 
188
 * g_emblem_new_with_origin:
 
189
 * @icon: a GIcon containing the icon.
 
190
 * @origin: a GEmblemOrigin enum defining the emblem's origin
 
191
 *
 
192
 * Creates a new emblem for @icon.
 
193
 * 
 
194
 * Returns: a new #GEmblem.
 
195
 *
 
196
 * Since: 2.18
 
197
 **/
 
198
GEmblem *
 
199
g_emblem_new_with_origin (GIcon         *icon,
 
200
                          GEmblemOrigin  origin)
 
201
{
 
202
  GEmblem* emblem;
 
203
 
 
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);
 
207
 
 
208
  emblem = g_object_new (G_TYPE_EMBLEM, NULL);
 
209
  emblem->icon = g_object_ref (icon);
 
210
  emblem->origin = origin;
 
211
 
 
212
  return emblem;
 
213
}
 
214
 
 
215
/**
 
216
 * g_emblem_get_icon:
 
217
 * @emblem: a #GEmblem from which the icon should be extracted.
 
218
 * 
 
219
 * Gives back the icon from @emblem.
 
220
 * 
 
221
 * Returns: a #GIcon. The returned object belongs to the emblem
 
222
 *    and should not be modified or freed.
 
223
 *
 
224
 * Since: 2.18
 
225
 **/
 
226
GIcon *
 
227
g_emblem_get_icon (GEmblem *emblem)
 
228
{
 
229
  g_return_val_if_fail (G_IS_EMBLEM (emblem), NULL);
 
230
 
 
231
  return emblem->icon;
 
232
}
 
233
 
 
234
 
 
235
/**
 
236
 * g_emblem_get_origin:
 
237
 * @emblem: a #GEmblem 
 
238
 * 
 
239
 * Gets the origin of the emblem.
 
240
 * 
 
241
 * Returns: the origin of the emblem
 
242
 *
 
243
 * Since: 2.18
 
244
 **/
 
245
GEmblemOrigin
 
246
g_emblem_get_origin (GEmblem *emblem)
 
247
{
 
248
  g_return_val_if_fail (G_IS_EMBLEM (emblem), G_EMBLEM_ORIGIN_UNKNOWN);
 
249
 
 
250
  return emblem->origin;
 
251
}
 
252
 
 
253
static guint
 
254
g_emblem_hash (GIcon *icon)
 
255
{
 
256
  GEmblem *emblem = G_EMBLEM (icon);
 
257
  guint hash;
 
258
 
 
259
  hash  = g_icon_hash (g_emblem_get_icon (emblem));
 
260
  hash ^= emblem->origin; 
 
261
 
 
262
  return hash;
 
263
}
 
264
 
 
265
static gboolean
 
266
g_emblem_equal (GIcon *icon1,
 
267
                GIcon *icon2)
 
268
{
 
269
  GEmblem *emblem1 = G_EMBLEM (icon1);
 
270
  GEmblem *emblem2 = G_EMBLEM (icon2);
 
271
  
 
272
  return emblem1->origin == emblem2->origin &&
 
273
         g_icon_equal (emblem1->icon, emblem2->icon);
 
274
}
 
275
 
 
276
static void
 
277
g_emblem_iface_init (GIconIface *iface)
 
278
{
 
279
  iface->hash  = g_emblem_hash;
 
280
  iface->equal = g_emblem_equal;
 
281
}
 
282
 
 
283
#define __G_EMBLEM_C__
 
284
#include "gioaliasdef.c"