1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
|
/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 8; tab-width: 8 -*- */
/*
* GData Client
* Copyright (C) Philip Withnall 2009–2010 <philip@tecnocode.co.uk>
* Copyright (C) Richard Schwarting 2009 <aquarichy@gmail.com>
*
* GData Client is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* GData Client is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with GData Client. If not, see <http://www.gnu.org/licenses/>.
*/
/**
* SECTION:gdata-picasaweb-user
* @short_description: GData PicasaWeb User object
* @stability: Unstable
* @include: gdata/services/picasaweb/gdata-picasaweb-user.h
*
* #GDataPicasaWebUser is a subclass of #GDataEntry to represent properties for a PicasaWeb user. It adds a couple of
* properties which are specific to the Google PicasaWeb API.
*
* Since: 0.6.0
**/
#include <glib.h>
#include <libxml/parser.h>
#include "gdata-picasaweb-user.h"
#include "gdata-feed.h"
#include "gdata-private.h"
static void gdata_picasaweb_user_finalize (GObject *object);
static void gdata_picasaweb_user_get_property (GObject *object, guint property_id, GValue *value, GParamSpec *pspec);
static gboolean parse_xml (GDataParsable *parsable, xmlDoc *doc, xmlNode *node, gpointer user_data, GError **error);
static void get_namespaces (GDataParsable *parsable, GHashTable *namespaces);
struct _GDataPicasaWebUserPrivate {
gchar *user;
gchar *nickname;
gint64 quota_limit;
gint64 quota_current;
gint max_photos_per_album;
gchar *thumbnail_uri;
};
enum {
PROP_USER = 1,
PROP_NICKNAME,
PROP_QUOTA_LIMIT,
PROP_QUOTA_CURRENT,
PROP_MAX_PHOTOS_PER_ALBUM,
PROP_THUMBNAIL_URI
};
G_DEFINE_TYPE (GDataPicasaWebUser, gdata_picasaweb_user, GDATA_TYPE_ENTRY)
static void
gdata_picasaweb_user_class_init (GDataPicasaWebUserClass *klass)
{
GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
GDataParsableClass *parsable_class = GDATA_PARSABLE_CLASS (klass);
g_type_class_add_private (klass, sizeof (GDataPicasaWebUserPrivate));
gobject_class->get_property = gdata_picasaweb_user_get_property;
gobject_class->finalize = gdata_picasaweb_user_finalize;
parsable_class->parse_xml = parse_xml;
parsable_class->get_namespaces = get_namespaces;
/**
* GDataPicasaWebUser:user:
*
* The username of the user, as seen in feed URLs.
* http://code.google.com/apis/picasaweb/reference.html#gphoto_user
*
* Since: 0.6.0
**/
g_object_class_install_property (gobject_class, PROP_USER,
g_param_spec_string ("user",
"User", "The username of the user.",
NULL,
G_PARAM_READABLE | G_PARAM_STATIC_STRINGS));
/**
* GDataPicasaWebUser:nickname:
*
* The user's nickname. This is a user-specified value that should be used when referring to the user by name.
* http://code.google.com/apis/picasaweb/reference.html#gphoto_nickname
*
* Since: 0.6.0
**/
g_object_class_install_property (gobject_class, PROP_NICKNAME,
g_param_spec_string ("nickname",
"Nickname", "The user's nickname.",
NULL,
G_PARAM_READABLE | G_PARAM_STATIC_STRINGS));
/**
* GDataPicasaWebUser:quota-limit:
*
* The total amount of space, in bytes, available to the user.
* http://code.google.com/apis/picasaweb/reference.html#gphoto_quotalimit
*
* Since: 0.6.0
**/
g_object_class_install_property (gobject_class, PROP_QUOTA_LIMIT,
g_param_spec_int64 ("quota-limit",
"Quota Limit", "The total amount of space, in bytes, available to the user.",
-1, G_MAXINT64, -1,
G_PARAM_READABLE | G_PARAM_STATIC_STRINGS));
/**
* GDataPicasaWebUser:quota-current:
*
* The current amount of space, in bytes, already used by the user.
* http://code.google.com/apis/picasaweb/reference.html#gphoto_quotacurrent
*
* Since: 0.6.0
**/
g_object_class_install_property (gobject_class, PROP_QUOTA_CURRENT,
g_param_spec_int64 ("quota-current",
"Quota Current", "The current amount of space, in bytes, already used by the user.",
-1, G_MAXINT64, -1,
G_PARAM_READABLE | G_PARAM_STATIC_STRINGS));
/**
* GDataPicasaWebUser:max-photos-per-album:
*
* The maximum number of photos allowed in an album.
* http://code.google.com/apis/picasaweb/reference.html#gphoto_maxPhotosPerAlbum
*
* Since: 0.6.0
**/
g_object_class_install_property (gobject_class, PROP_MAX_PHOTOS_PER_ALBUM,
g_param_spec_int ("max-photos-per-album",
"Max Photos Per Album", "The maximum number of photos allowed in an album.",
-1, G_MAXINT, -1,
G_PARAM_READABLE | G_PARAM_STATIC_STRINGS));
/**
* GDataPicasaWebUser:thumbnail-uri:
*
* The URI of a thumbnail-sized portrait of the user.
* http://code.google.com/apis/picasaweb/reference.html#gphoto_thumbnail
*
* Since: 0.6.0
**/
g_object_class_install_property (gobject_class, PROP_THUMBNAIL_URI,
g_param_spec_string ("thumbnail-uri",
"Thumbnail URI", "The URI of a thumbnail-sized portrait of the user.",
NULL,
G_PARAM_READABLE | G_PARAM_STATIC_STRINGS));
}
static void
gdata_picasaweb_user_init (GDataPicasaWebUser *self)
{
self->priv = G_TYPE_INSTANCE_GET_PRIVATE (self, GDATA_TYPE_PICASAWEB_USER, GDataPicasaWebUserPrivate);
/* Initialise the properties whose values we can theoretically not know */
self->priv->quota_limit = self->priv->quota_current = self->priv->max_photos_per_album = -1;
}
static void
gdata_picasaweb_user_finalize (GObject *object)
{
GDataPicasaWebUserPrivate *priv = GDATA_PICASAWEB_USER (object)->priv;
g_free (priv->user);
g_free (priv->nickname);
g_free (priv->thumbnail_uri);
/* Chain up to the parent class */
G_OBJECT_CLASS (gdata_picasaweb_user_parent_class)->finalize (object);
}
static void
gdata_picasaweb_user_get_property (GObject *object, guint property_id, GValue *value, GParamSpec *pspec)
{
GDataPicasaWebUserPrivate *priv = GDATA_PICASAWEB_USER (object)->priv;
switch (property_id) {
case PROP_USER:
g_value_set_string (value, priv->user);
break;
case PROP_NICKNAME:
g_value_set_string (value, priv->nickname);
break;
case PROP_QUOTA_LIMIT:
g_value_set_int64 (value, priv->quota_limit);
break;
case PROP_QUOTA_CURRENT:
g_value_set_int64 (value, priv->quota_current);
break;
case PROP_MAX_PHOTOS_PER_ALBUM:
g_value_set_int (value, priv->max_photos_per_album);
break;
case PROP_THUMBNAIL_URI:
g_value_set_string (value, priv->thumbnail_uri);
break;
default:
/* We don't have any other property... */
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
break;
}
}
static gboolean
parse_xml (GDataParsable *parsable, xmlDoc *doc, xmlNode *node, gpointer user_data, GError **error)
{
gboolean success;
GDataPicasaWebUser *self = GDATA_PICASAWEB_USER (parsable);
if (gdata_parser_is_namespace (node, "http://schemas.google.com/photos/2007") == FALSE)
return GDATA_PARSABLE_CLASS (gdata_picasaweb_user_parent_class)->parse_xml (parsable, doc, node, user_data, error);
if (gdata_parser_string_from_element (node, "user", P_REQUIRED | P_NON_EMPTY, &(self->priv->user), &success, error) == TRUE ||
gdata_parser_string_from_element (node, "nickname", P_REQUIRED | P_NON_EMPTY, &(self->priv->nickname), &success, error) == TRUE ||
gdata_parser_string_from_element (node, "thumbnail", P_REQUIRED | P_NON_EMPTY, &(self->priv->thumbnail_uri), &success, error) == TRUE) {
return success;
} else if (xmlStrcmp (node->name, (xmlChar*) "quotacurrent") == 0) {
/* gphoto:quota-current */
xmlChar *quota_current = xmlNodeListGetString (doc, node->children, TRUE);
self->priv->quota_current = g_ascii_strtoll ((const gchar*) quota_current, NULL, 10);
xmlFree (quota_current);
} else if (xmlStrcmp (node->name, (xmlChar*) "quotalimit") == 0) {
/* gphoto:quota-limit */
xmlChar *quota_limit = xmlNodeListGetString (doc, node->children, TRUE);
self->priv->quota_limit = g_ascii_strtoll ((const gchar*) quota_limit, NULL, 10);
xmlFree (quota_limit);
} else if (xmlStrcmp (node->name, (xmlChar*) "maxPhotosPerAlbum") == 0) {
/* gphoto:max-photos-per-album */
xmlChar *max_photos_per_album = xmlNodeListGetString (doc, node->children, TRUE);
self->priv->max_photos_per_album = strtol ((char*) max_photos_per_album, NULL, 10);
xmlFree (max_photos_per_album);
} else if (xmlStrcmp (node->name, (xmlChar*) "x-allowDownloads") == 0) { /* RHSTODO: see if this comes with the user */
/* gphoto:allowDownloads */
/* TODO: Not part of public API so we're capturing and ignoring for now. See bgo #589858. */
} else if (xmlStrcmp (node->name, (xmlChar*) "x-allowPrints") == 0) { /* RHSTODO: see if this comes with the user */
/* gphoto:allowPrints */
/* TODO: Not part of public API so we're capturing and ignoring for now. See bgo #589858. */
} else {
return GDATA_PARSABLE_CLASS (gdata_picasaweb_user_parent_class)->parse_xml (parsable, doc, node, user_data, error);
}
return TRUE;
}
static void
get_namespaces (GDataParsable *parsable, GHashTable *namespaces)
{
/* Chain up to the parent class */
GDATA_PARSABLE_CLASS (gdata_picasaweb_user_parent_class)->get_namespaces (parsable, namespaces);
g_hash_table_insert (namespaces, (gchar*) "gphoto", (gchar*) "http://schemas.google.com/photos/2007");
}
/**
* gdata_picasaweb_user_get_user:
* @self: a #GDataPicasaWebUser
*
* Gets the #GDataPicasaWebUser:user property.
*
* Return value: the feed's user, or %NULL
*
* Since: 0.6.0
**/
const gchar *
gdata_picasaweb_user_get_user (GDataPicasaWebUser *self)
{
g_return_val_if_fail (GDATA_IS_PICASAWEB_USER (self), NULL);
return self->priv->user;
}
/**
* gdata_picasaweb_user_get_nickname:
* @self: a #GDataPicasaWebUser
*
* Gets the #GDataPicasaWebUser:nickname property.
*
* Return value: the nickname of the feed's user's nickname, or %NULL
*
* Since: 0.6.0
**/
const gchar *
gdata_picasaweb_user_get_nickname (GDataPicasaWebUser *self)
{
g_return_val_if_fail (GDATA_IS_PICASAWEB_USER (self), NULL);
return self->priv->nickname;
}
/**
* gdata_picasaweb_user_get_quota_limit:
* @self: a #GDataPicasaWebUser
*
* Gets the #GDataPicasaWebUser:quota-limit property. Note that
* this information is not available when accessing feeds which we
* haven't authenticated, and %0 is returned.
*
* Return value: the maximum capacity in bytes for this feed's account, or %-1
*
* Since: 0.6.0
**/
gint64
gdata_picasaweb_user_get_quota_limit (GDataPicasaWebUser *self)
{
g_return_val_if_fail (GDATA_IS_PICASAWEB_USER (self), -1);
return self->priv->quota_limit;
}
/**
* gdata_picasaweb_user_get_quota_current:
* @self: a #GDataPicasaWebUser
*
* Gets the #GDataPicasaWebUser:quota-current property. Note that
* this information is not available when accessing feeds which we
* haven't authenticated, and %0 is returned.
*
* Return value: the current number of bytes in use by this feed's account, or %-1
*
* Since: 0.6.0
**/
gint64
gdata_picasaweb_user_get_quota_current (GDataPicasaWebUser *self)
{
g_return_val_if_fail (GDATA_IS_PICASAWEB_USER (self), -1);
return self->priv->quota_current;
}
/**
* gdata_picasaweb_user_get_max_photos_per_album:
* @self: a #GDataPicasaWebUser
*
* Gets the #GDataPicasaWebUser:max-photos-per-album property. Note that
* this information is not available when accessing feeds which we
* haven't authenticated, and %0 is returned.
*
* Return value: the maximum number of photos an album for this account can hold, or %-1
*
* Since: 0.6.0
**/
gint
gdata_picasaweb_user_get_max_photos_per_album (GDataPicasaWebUser *self)
{
g_return_val_if_fail (GDATA_IS_PICASAWEB_USER (self), -1);
return self->priv->max_photos_per_album;
}
/**
* gdata_picasaweb_user_get_thumbnail_uri:
* @self: a #GDataPicasaWebUser
*
* Gets the #GDataPicasaWebUser:thumbnail-uri property.
*
* Return value: the URI for the thumbnail of the account, or %NULL
*
* Since: 0.6.0
**/
const gchar *
gdata_picasaweb_user_get_thumbnail_uri (GDataPicasaWebUser *self)
{
g_return_val_if_fail (GDATA_IS_PICASAWEB_USER (self), NULL);
return self->priv->thumbnail_uri;
}
/* TODO: in the future, see if we can change things like the user's nickname and thumbnail/avatar */
|