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
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
|
/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 8; tab-width: 8 -*- */
/*
* GData Client
* Copyright (C) Philip Withnall 2008-2009 <philip@tecnocode.co.uk>
*
* 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-entry
* @short_description: GData entry object
* @stability: Unstable
* @include: gdata/gdata-entry.h
*
* #GDataEntry represents a single object on the online service, such as a playlist, video or calendar event. It is a snapshot of the
* state of that object at the time of querying the service, so modifications made to a #GDataEntry will not be automatically or
* magically propagated to the server.
**/
#include <config.h>
#include <glib.h>
#include <glib/gi18n-lib.h>
#include <libxml/parser.h>
#include <string.h>
#include "gdata-entry.h"
#include "gdata-types.h"
#include "gdata-service.h"
#include "gdata-private.h"
#include "atom/gdata-category.h"
#include "atom/gdata-link.h"
#include "atom/gdata-author.h"
static void gdata_entry_dispose (GObject *object);
static void gdata_entry_finalize (GObject *object);
static void gdata_entry_get_property (GObject *object, guint property_id, GValue *value, GParamSpec *pspec);
static void gdata_entry_set_property (GObject *object, guint property_id, const GValue *value, GParamSpec *pspec);
static gboolean pre_parse_xml (GDataParsable *parsable, xmlDoc *doc, xmlNode *root_node, gpointer user_data, GError **error);
static gboolean parse_xml (GDataParsable *parsable, xmlDoc *doc, xmlNode *node, gpointer user_data, GError **error);
static gboolean post_parse_xml (GDataParsable *parsable, gpointer user_data, GError **error);
static void pre_get_xml (GDataParsable *parsable, GString *xml_string);
static void get_xml (GDataParsable *parsable, GString *xml_string);
static void get_namespaces (GDataParsable *parsable, GHashTable *namespaces);
struct _GDataEntryPrivate {
gchar *title;
gchar *id;
gchar *etag;
GTimeVal updated;
GTimeVal published;
GList *categories; /* GDataCategory */
gchar *content;
GList *links; /* GDataLink */
GList *authors; /* GDataAuthor */
};
enum {
PROP_TITLE = 1,
PROP_ETAG,
PROP_ID,
PROP_UPDATED,
PROP_PUBLISHED,
PROP_CONTENT,
PROP_IS_INSERTED
};
G_DEFINE_TYPE (GDataEntry, gdata_entry, GDATA_TYPE_PARSABLE)
#define GDATA_ENTRY_GET_PRIVATE(obj) (G_TYPE_INSTANCE_GET_PRIVATE ((obj), GDATA_TYPE_ENTRY, GDataEntryPrivate))
static void
gdata_entry_class_init (GDataEntryClass *klass)
{
GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
GDataParsableClass *parsable_class = GDATA_PARSABLE_CLASS (klass);
g_type_class_add_private (klass, sizeof (GDataEntryPrivate));
gobject_class->set_property = gdata_entry_set_property;
gobject_class->get_property = gdata_entry_get_property;
gobject_class->dispose = gdata_entry_dispose;
gobject_class->finalize = gdata_entry_finalize;
parsable_class->pre_parse_xml = pre_parse_xml;
parsable_class->parse_xml = parse_xml;
parsable_class->post_parse_xml = post_parse_xml;
parsable_class->pre_get_xml = pre_get_xml;
parsable_class->get_xml = get_xml;
parsable_class->get_namespaces = get_namespaces;
g_object_class_install_property (gobject_class, PROP_TITLE,
g_param_spec_string ("title",
"Title", "The title for this entry.",
NULL,
G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
g_object_class_install_property (gobject_class, PROP_ID,
g_param_spec_string ("id",
"ID", "The ID for this entry.",
NULL,
G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY | G_PARAM_STATIC_STRINGS));
/* Since: 0.2.0 */
g_object_class_install_property (gobject_class, PROP_ETAG,
g_param_spec_string ("etag",
"ETag", "The ETag for this entry.",
NULL,
G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY | G_PARAM_STATIC_STRINGS));
g_object_class_install_property (gobject_class, PROP_UPDATED,
g_param_spec_boxed ("updated",
"Updated", "The last update time for this entry.",
GDATA_TYPE_G_TIME_VAL,
G_PARAM_READABLE | G_PARAM_STATIC_STRINGS));
g_object_class_install_property (gobject_class, PROP_PUBLISHED,
g_param_spec_boxed ("published",
"Published", "The time this entry was published.",
GDATA_TYPE_G_TIME_VAL,
G_PARAM_READABLE | G_PARAM_STATIC_STRINGS));
g_object_class_install_property (gobject_class, PROP_CONTENT,
g_param_spec_string ("content",
"Content", "The textual content of this entry.",
NULL,
G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
g_object_class_install_property (gobject_class, PROP_IS_INSERTED,
g_param_spec_boolean ("is-inserted",
"Inserted?", "Whether the entry has been inserted on the server.",
FALSE,
G_PARAM_READABLE | G_PARAM_STATIC_STRINGS));
}
static void
gdata_entry_init (GDataEntry *self)
{
self->priv = G_TYPE_INSTANCE_GET_PRIVATE (self, GDATA_TYPE_ENTRY, GDataEntryPrivate);
}
static void
gdata_entry_dispose (GObject *object)
{
GDataEntryPrivate *priv = GDATA_ENTRY (object)->priv;
if (priv->categories != NULL) {
g_list_foreach (priv->categories, (GFunc) g_object_unref, NULL);
g_list_free (priv->categories);
}
priv->categories = NULL;
if (priv->links != NULL) {
g_list_foreach (priv->links, (GFunc) g_object_unref, NULL);
g_list_free (priv->links);
}
priv->links = NULL;
if (priv->authors != NULL) {
g_list_foreach (priv->authors, (GFunc) g_object_unref, NULL);
g_list_free (priv->authors);
}
priv->authors = NULL;
/* Chain up to the parent class */
G_OBJECT_CLASS (gdata_entry_parent_class)->dispose (object);
}
static void
gdata_entry_finalize (GObject *object)
{
GDataEntryPrivate *priv = GDATA_ENTRY_GET_PRIVATE (object);
g_free (priv->title);
xmlFree (priv->id);
xmlFree (priv->etag);
g_free (priv->content);
/* Chain up to the parent class */
G_OBJECT_CLASS (gdata_entry_parent_class)->finalize (object);
}
static void
gdata_entry_get_property (GObject *object, guint property_id, GValue *value, GParamSpec *pspec)
{
GDataEntryPrivate *priv = GDATA_ENTRY_GET_PRIVATE (object);
switch (property_id) {
case PROP_TITLE:
g_value_set_string (value, priv->title);
break;
case PROP_ID:
g_value_set_string (value, priv->id);
break;
case PROP_ETAG:
g_value_set_string (value, priv->etag);
break;
case PROP_UPDATED:
g_value_set_boxed (value, &(priv->updated));
break;
case PROP_PUBLISHED:
g_value_set_boxed (value, &(priv->published));
break;
case PROP_CONTENT:
g_value_set_string (value, priv->content);
break;
case PROP_IS_INSERTED:
g_value_set_boolean (value, gdata_entry_is_inserted (GDATA_ENTRY (object)));
break;
default:
/* We don't have any other property... */
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
break;
}
}
static void
gdata_entry_set_property (GObject *object, guint property_id, const GValue *value, GParamSpec *pspec)
{
GDataEntry *self = GDATA_ENTRY (object);
switch (property_id) {
case PROP_ID:
/* Construct only */
self->priv->id = g_value_dup_string (value);
break;
case PROP_ETAG:
/* Construct only */
self->priv->etag = g_value_dup_string (value);
break;
case PROP_TITLE:
gdata_entry_set_title (self, g_value_get_string (value));
break;
case PROP_CONTENT:
gdata_entry_set_content (self, g_value_get_string (value));
break;
default:
/* We don't have any other property... */
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
break;
}
}
static gboolean
pre_parse_xml (GDataParsable *parsable, xmlDoc *doc, xmlNode *root_node, gpointer user_data, GError **error)
{
g_return_val_if_fail (GDATA_IS_ENTRY (parsable), FALSE);
g_return_val_if_fail (doc != NULL, FALSE);
g_return_val_if_fail (root_node != NULL, FALSE);
/* Extract the ETag */
GDATA_ENTRY (parsable)->priv->etag = (gchar*) xmlGetProp (root_node, (xmlChar*) "etag");
return TRUE;
}
static gboolean
parse_xml (GDataParsable *parsable, xmlDoc *doc, xmlNode *node, gpointer user_data, GError **error)
{
GDataEntry *self;
g_return_val_if_fail (GDATA_IS_ENTRY (parsable), FALSE);
g_return_val_if_fail (doc != NULL, FALSE);
g_return_val_if_fail (node != NULL, FALSE);
self = GDATA_ENTRY (parsable);
if (xmlStrcmp (node->name, (xmlChar*) "title") == 0) {
/* atom:title */
xmlChar *title = xmlNodeListGetString (doc, node->children, TRUE);
/* Title can be empty */
if (title == NULL)
gdata_entry_set_title (self, "");
else
gdata_entry_set_title (self, (gchar*) title);
xmlFree (title);
} else if (xmlStrcmp (node->name, (xmlChar*) "id") == 0) {
/* atom:id */
xmlFree (self->priv->id);
self->priv->id = (gchar*) xmlNodeListGetString (doc, node->children, TRUE);
} else if (xmlStrcmp (node->name, (xmlChar*) "updated") == 0) {
/* atom:updated */
xmlChar *updated;
updated = xmlNodeListGetString (doc, node->children, TRUE);
if (g_time_val_from_iso8601 ((gchar*) updated, &(self->priv->updated)) == FALSE) {
/* Error */
gdata_parser_error_not_iso8601_format (node, (gchar*) updated, error);
xmlFree (updated);
return FALSE;
}
xmlFree (updated);
} else if (xmlStrcmp (node->name, (xmlChar*) "published") == 0) {
/* atom:published */
xmlChar *published;
published = xmlNodeListGetString (doc, node->children, TRUE);
if (g_time_val_from_iso8601 ((gchar*) published, &(self->priv->published)) == FALSE) {
/* Error */
gdata_parser_error_not_iso8601_format (node, (gchar*) published, error);
xmlFree (published);
return FALSE;
}
xmlFree (published);
} else if (xmlStrcmp (node->name, (xmlChar*) "category") == 0) {
/* atom:category */
GDataCategory *category = GDATA_CATEGORY (_gdata_parsable_new_from_xml_node (GDATA_TYPE_CATEGORY, "category", doc, node, NULL, error));
if (category == NULL)
return FALSE;
self->priv->categories = g_list_prepend (self->priv->categories, category);
} else if (xmlStrcmp (node->name, (xmlChar*) "content") == 0) {
/* atom:content */
xmlChar *content = xmlNodeListGetString (doc, node->children, TRUE);
if (content == NULL)
content = xmlGetProp (node, (xmlChar*) "src");
gdata_entry_set_content (self, (gchar*) content);
xmlFree (content);
} else if (xmlStrcmp (node->name, (xmlChar*) "link") == 0) {
/* atom:link */
GDataLink *link = GDATA_LINK (_gdata_parsable_new_from_xml_node (GDATA_TYPE_LINK, "link", doc, node, NULL, error));
if (link == NULL)
return FALSE;
self->priv->links = g_list_prepend (self->priv->links, link);
} else if (xmlStrcmp (node->name, (xmlChar*) "author") == 0) {
/* atom:author */
GDataAuthor *author = GDATA_AUTHOR (_gdata_parsable_new_from_xml_node (GDATA_TYPE_AUTHOR, "author", doc, node, NULL, error));
if (author == NULL)
return FALSE;
self->priv->authors = g_list_prepend (self->priv->authors, author);
} else if (GDATA_PARSABLE_CLASS (gdata_entry_parent_class)->parse_xml (parsable, doc, node, user_data, error) == FALSE) {
/* Error! */
return FALSE;
}
return TRUE;
}
static gboolean
post_parse_xml (GDataParsable *parsable, gpointer user_data, GError **error)
{
GDataEntryPrivate *priv = GDATA_ENTRY (parsable)->priv;
/* Check for missing required elements */
/* Can't uncomment it, as things like access rules break the Atom standard */
/*if (priv->title == NULL)
return gdata_parser_error_required_element_missing ("title", "entry", error);
if (priv->id == NULL)
return gdata_parser_error_required_element_missing ("id", "entry", error);
if (priv->updated.tv_sec == 0 && priv->updated.tv_usec == 0)
return gdata_parser_error_required_element_missing ("updated", "entry", error);*/
/* Reverse our lists of stuff */
priv->categories = g_list_reverse (priv->categories);
priv->links = g_list_reverse (priv->links);
priv->authors = g_list_reverse (priv->authors);
return TRUE;
}
GDataEntry *
_gdata_entry_new_from_xml (GType entry_type, const gchar *xml, gint length, GError **error)
{
g_return_val_if_fail (xml != NULL, NULL);
g_return_val_if_fail (g_type_is_a (entry_type, GDATA_TYPE_ENTRY) == TRUE, FALSE);
return GDATA_ENTRY (_gdata_parsable_new_from_xml (entry_type, "entry", xml, length, NULL, error));
}
static void
pre_get_xml (GDataParsable *parsable, GString *xml_string)
{
GDataEntryPrivate *priv = GDATA_ENTRY (parsable)->priv;
/* Add the entry's ETag, if available */
if (priv->etag != NULL)
g_string_append_printf (xml_string, " gd:etag='%s'", priv->etag);
}
static void
get_xml (GDataParsable *parsable, GString *xml_string)
{
GDataEntryPrivate *priv = GDATA_ENTRY (parsable)->priv;
gchar *title;
GList *categories, *links, *authors;
title = g_markup_escape_text (priv->title, -1);
g_string_append_printf (xml_string, "<title type='text'>%s</title>", title);
g_free (title);
if (priv->id != NULL)
g_string_append_printf (xml_string, "<id>%s</id>", priv->id);
if (priv->updated.tv_sec != 0 || priv->updated.tv_usec != 0) {
gchar *updated = g_time_val_to_iso8601 (&(priv->updated));
g_string_append_printf (xml_string, "<updated>%s</updated>", updated);
g_free (updated);
}
if (priv->published.tv_sec != 0 || priv->published.tv_usec != 0) {
gchar *published = g_time_val_to_iso8601 (&(priv->published));
g_string_append_printf (xml_string, "<published>%s</published>", published);
g_free (published);
}
if (priv->content != NULL) {
gchar *content = g_markup_escape_text (priv->content, -1);
g_string_append_printf (xml_string, "<content type='text'>%s</content>", content);
g_free (content);
}
for (categories = priv->categories; categories != NULL; categories = categories->next)
g_string_append (xml_string, _gdata_parsable_get_xml (GDATA_PARSABLE (categories->data), "category", FALSE));
for (links = priv->links; links != NULL; links = links->next)
g_string_append (xml_string, _gdata_parsable_get_xml (GDATA_PARSABLE (links->data), "link", FALSE));
for (authors = priv->authors; authors != NULL; authors = authors->next)
g_string_append (xml_string, _gdata_parsable_get_xml (GDATA_PARSABLE (authors->data), "author", FALSE));
}
static void
get_namespaces (GDataParsable *parsable, GHashTable *namespaces)
{
g_hash_table_insert (namespaces, (gchar*) "gd", (gchar*) "http://schemas.google.com/g/2005");
}
/**
* gdata_entry_new:
* @id: the entry's ID, or %NULL
*
* Creates a new #GDataEntry with the given ID and default properties.
*
* Return value: a new #GDataEntry; unref with g_object_unref()
**/
GDataEntry *
gdata_entry_new (const gchar *id)
{
return g_object_new (GDATA_TYPE_ENTRY, "id", id, NULL);
}
/**
* gdata_entry_new_from_xml:
* @xml: the XML for just the entry, with full namespace declarations
* @length: the length of @xml, or -1
* @error: a #GError, or %NULL
*
* Creates a new #GDataEntry from the provided @xml.
*
* If @length is -1, @xml will be assumed to be nul-terminated.
*
* If an error occurs during parsing, a suitable error from #GDataParserError will be returned.
*
* Return value: a new #GDataEntry, or %NULL
**/
GDataEntry *
gdata_entry_new_from_xml (const gchar *xml, gint length, GError **error)
{
return GDATA_ENTRY (_gdata_parsable_new_from_xml (GDATA_TYPE_ENTRY, "entry", xml, length, NULL, error));
}
/**
* gdata_entry_get_title:
* @self: a #GDataEntry
*
* Returns the title of the entry.
*
* Return value: the entry's title
**/
const gchar *
gdata_entry_get_title (GDataEntry *self)
{
g_return_val_if_fail (GDATA_IS_ENTRY (self), NULL);
return self->priv->title;
}
/**
* gdata_entry_set_title:
* @self: a #GDataEntry
* @title: the new entry title, or %NULL
*
* Sets the title of the entry.
**/
void
gdata_entry_set_title (GDataEntry *self, const gchar *title)
{
g_return_if_fail (GDATA_IS_ENTRY (self));
g_free (self->priv->title);
self->priv->title = g_strdup (title);
g_object_notify (G_OBJECT (self), "title");
}
/**
* gdata_entry_get_id:
* @self: a #GDataEntry
*
* Returns the URN ID of the entry; a unique and permanent identifier for the object the entry represents.
*
* Return value: the entry's ID
**/
const gchar *
gdata_entry_get_id (GDataEntry *self)
{
g_return_val_if_fail (GDATA_IS_ENTRY (self), NULL);
return self->priv->id;
}
/**
* gdata_entry_get_etag:
* @self: a #GDataEntry
*
* Returns the ETag of the entry; a unique identifier for each version of the entry. For more information, see the
* <ulink type="http" url="http://code.google.com/apis/gdata/docs/2.0/reference.html#ResourceVersioning">online documentation</ulink>.
*
* Return value: the entry's ETag
*
* Since: 0.2.0
**/
const gchar *
gdata_entry_get_etag (GDataEntry *self)
{
g_return_val_if_fail (GDATA_IS_ENTRY (self), NULL);
return self->priv->etag;
}
/**
* gdata_entry_get_updated:
* @self: a #GDataEntry
* @updated: a #GTimeVal
*
* Puts the time the entry was last updated into @updated.
**/
void
gdata_entry_get_updated (GDataEntry *self, GTimeVal *updated)
{
g_return_if_fail (GDATA_IS_ENTRY (self));
g_return_if_fail (updated != NULL);
*updated = self->priv->updated;
}
/**
* gdata_entry_get_published:
* @self: a #GDataEntry
* @published: a #GTimeVal
*
* Puts the time the entry was originally published into @published.
**/
void
gdata_entry_get_published (GDataEntry *self, GTimeVal *published)
{
g_return_if_fail (GDATA_IS_ENTRY (self));
g_return_if_fail (published != NULL);
*published = self->priv->published;
}
/**
* gdata_entry_add_category:
* @self: a #GDataEntry
* @category: a #GDataCategory to add
*
* Adds @category to the list of categories in the given #GDataEntry, and increments its reference count.
*
* Duplicate categories will not be added to the list.
**/
void
gdata_entry_add_category (GDataEntry *self, GDataCategory *category)
{
g_return_if_fail (GDATA_IS_ENTRY (self));
g_return_if_fail (GDATA_IS_CATEGORY (category));
if (g_list_find_custom (self->priv->categories, category, (GCompareFunc) gdata_category_compare) == NULL)
self->priv->categories = g_list_prepend (self->priv->categories, g_object_ref (category));
}
/**
* gdata_entry_get_categories:
* @self: a #GDataEntry
*
* Gets a list of the #GDataCategory<!-- -->s containing this entry.
*
* Return value: a #GList of #GDataCategory<!-- -->s
*
* Since: 0.2.0
**/
GList *
gdata_entry_get_categories (GDataEntry *self)
{
g_return_val_if_fail (GDATA_IS_ENTRY (self), NULL);
return self->priv->categories;
}
/**
* gdata_entry_get_content:
* @self: a #GDataEntry
*
* Returns the textual content in this entry.
*
* Return value: the entry's content, or %NULL
**/
const gchar *
gdata_entry_get_content (GDataEntry *self)
{
g_return_val_if_fail (GDATA_IS_ENTRY (self), NULL);
return self->priv->content;
}
/**
* gdata_entry_set_content:
* @self: a #GDataEntry
* @content: the new content for the entry
*
* Sets the entry's content to @content.
**/
void
gdata_entry_set_content (GDataEntry *self, const gchar *content)
{
g_return_if_fail (GDATA_IS_ENTRY (self));
g_free (self->priv->content);
self->priv->content = g_strdup (content);
g_object_notify (G_OBJECT (self), "content");
}
/**
* gdata_entry_add_link:
* @self: a #GDataEntry
* @link: a #GDataLink to add
*
* Adds @link to the list of links in the given #GDataEntry and increments its reference count.
*
* Duplicate links will not be added to the list.
**/
void
gdata_entry_add_link (GDataEntry *self, GDataLink *link)
{
/* TODO: More link API */
g_return_if_fail (GDATA_IS_ENTRY (self));
g_return_if_fail (GDATA_IS_LINK (link));
if (g_list_find_custom (self->priv->links, link, (GCompareFunc) gdata_link_compare) == NULL)
self->priv->links = g_list_prepend (self->priv->links, g_object_ref (link));
}
static gint
link_compare_cb (const GDataLink *link, const gchar *rel)
{
return strcmp (gdata_link_get_relation_type ((GDataLink*) link), rel);
}
/**
* gdata_entry_look_up_link:
* @self: a #GDataEntry
* @rel: the value of the <structfield>rel</structfield> attribute of the desired link
*
* Looks up a link by <structfield>rel</structfield> value from the list of links in the entry.
*
* Return value: a #GDataLink, or %NULL if one was not found
*
* Since: 0.1.1
**/
GDataLink *
gdata_entry_look_up_link (GDataEntry *self, const gchar *rel)
{
GList *element;
g_return_val_if_fail (GDATA_IS_ENTRY (self), NULL);
g_return_val_if_fail (rel != NULL, NULL);
element = g_list_find_custom (self->priv->links, rel, (GCompareFunc) link_compare_cb);
if (element == NULL)
return NULL;
return GDATA_LINK (element->data);
}
/**
* gdata_entry_add_author:
* @self: a #GDataEntry
* @author: a #GDataAuthor to add
*
* Adds @author to the list of authors in the given #GDataEntry and increments its reference count.
*
* Duplicate authors will not be added to the list.
**/
void
gdata_entry_add_author (GDataEntry *self, GDataAuthor *author)
{
/* TODO: More author API */
g_return_if_fail (GDATA_IS_ENTRY (self));
g_return_if_fail (author != NULL);
if (g_list_find_custom (self->priv->authors, author, (GCompareFunc) gdata_author_compare) == NULL)
self->priv->authors = g_list_prepend (self->priv->authors, g_object_ref (author));
}
/**
* gdata_entry_is_inserted:
* @self: a #GDataEntry
*
* Returns whether the entry is marked as having been inserted on (uploaded to) the server already.
*
* Return value: %TRUE if the entry has been inserted already, %FALSE otherwise
**/
gboolean
gdata_entry_is_inserted (GDataEntry *self)
{
g_return_val_if_fail (GDATA_IS_ENTRY (self), FALSE);
if (self->priv->id != NULL &&
self->priv->links != NULL &&
(self->priv->updated.tv_sec != 0 || self->priv->updated.tv_usec != 0))
return TRUE;
return FALSE;
}
/**
* gdata_entry_get_xml:
* @self: a #GDataEntry
*
* Builds an XML representation of the #GDataEntry in its current state, such that it could be inserted on the server.
* The XML is guaranteed to have all its namespaces declared properly in a self-contained fashion. The root element is
* guaranteed to be <literal><entry></literal>.
*
* Return value: the entry's XML; free with g_free()
**/
gchar *
gdata_entry_get_xml (GDataEntry *self)
{
return _gdata_parsable_get_xml (GDATA_PARSABLE (self), "entry", TRUE);
}
|