summaryrefslogtreecommitdiff
path: root/extern/rss-glib/rss-item.c
blob: 0f8466130ed27ff9b6dbcc1064dd49f7321435ca (plain)
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
736
737
738
/* rss-item.c
 * 
 * This file is part of RSS-GLib.
 * Copyright (C) 2008  Christian Hergert <chris@dronelabs.com>
 *
 * This library 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 3 of the License, or
 * (at your option) any later version.
 *
 * This library 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 this library.  If not, see <http://www.gnu.org/licenses/>.
 *
 * Author:
 *   Christian Hergert  <chris@dronelabs.com>
 */

/**
 * SECTION:rss-item
 * @short_description: a RSS entry representation
 *
 * #RssItem is the representation of an individual item parsed from a
 * #RssDocument.  This would mean an individual article, or note within
 * the source feed.
 */

#include "rss-item.h"
#include "rss-item-private.h"

G_DEFINE_TYPE (RssItem, rss_item, G_TYPE_OBJECT);

enum {
	PROP_0,

	PROP_TITLE,
	PROP_LINK,
	PROP_DESCRIPTION,
	PROP_COPYRIGHT,
	PROP_AUTHOR,
	PROP_AUTHOR_URI,
	PROP_AUTHOR_EMAIL,
	PROP_CONTRIBUTOR,
	PROP_CONTRIBUTOR_URI,
	PROP_CONTRIBUTOR_EMAIL,
	PROP_COMMENTS,
	PROP_PUB_DATE,
	PROP_GUID,
	PROP_SOURCE,
	PROP_SOURCE_URL
};

static void
rss_item_get_property (GObject    *object,
                       guint       property_id,
                       GValue     *value,
                       GParamSpec *pspec)
{
	RssItemPrivate *priv = RSS_ITEM (object)->priv;

	switch (property_id) {
	case PROP_TITLE:
		g_value_set_string (value, priv->title);
		break;
	case PROP_LINK:
		g_value_set_string (value, priv->link);
		break;
	case PROP_DESCRIPTION:
		g_value_set_string (value, priv->description);
		break;
	case PROP_COPYRIGHT:
		g_value_set_string (value, priv->copyright);
		break;
	case PROP_AUTHOR:
		g_value_set_string (value, priv->author);
		break;
	case PROP_AUTHOR_URI:
		g_value_set_string (value, priv->author_uri);
		break;
	case PROP_AUTHOR_EMAIL:
		g_value_set_string (value, priv->author_email);
		break;
	case PROP_CONTRIBUTOR:
		g_value_set_string (value, priv->contributor);
		break;
	case PROP_CONTRIBUTOR_URI:
		g_value_set_string (value, priv->contributor_uri);
		break;
	case PROP_CONTRIBUTOR_EMAIL:
		g_value_set_string (value, priv->contributor_email);
		break;
	case PROP_COMMENTS:
		g_value_set_string (value, priv->comments);
		break;
	case PROP_PUB_DATE:
		g_value_set_string (value, priv->pub_date);
		break;
	case PROP_GUID:
		g_value_set_string (value, priv->guid);
		break;
	case PROP_SOURCE:
		g_value_set_string (value, priv->source);
		break;
	case PROP_SOURCE_URL:
		g_value_set_string (value, priv->source_url);
		break;

	default:
		G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
	}
}

static void
rss_item_set_property (GObject      *object,
                       guint         property_id,
                       const GValue *value,
                       GParamSpec   *pspec)
{
	RssItemPrivate *priv = RSS_ITEM (object)->priv;

	switch (property_id) {
	case PROP_TITLE:
		g_free (priv->title);
		priv->title = g_value_dup_string (value);
		break;
	case PROP_LINK:
		g_free (priv->link);
		priv->link = g_value_dup_string (value);
		break;
	case PROP_DESCRIPTION:
		g_free (priv->description);
		priv->description = g_value_dup_string (value);
		break;
	case PROP_COPYRIGHT:
		g_free (priv->copyright);
		priv->copyright = g_value_dup_string (value);
		break;
	case PROP_AUTHOR:
		g_free (priv->author);
		priv->author = g_value_dup_string (value);
		break;
	case PROP_AUTHOR_URI:
		g_free (priv->author_uri);
		priv->author_uri = g_value_dup_string (value);
		break;
	case PROP_AUTHOR_EMAIL:
		g_free (priv->author_email);
		priv->author_email = g_value_dup_string (value);
		break;
	case PROP_CONTRIBUTOR:
		g_free (priv->contributor);
		priv->contributor = g_value_dup_string (value);
		break;
	case PROP_CONTRIBUTOR_URI:
		g_free (priv->contributor_uri);
		priv->contributor_uri = g_value_dup_string (value);
		break;
	case PROP_CONTRIBUTOR_EMAIL:
		g_free (priv->contributor_email);
		priv->contributor_email = g_value_dup_string (value);
		break;
	case PROP_COMMENTS:
		g_free (priv->comments);
		priv->comments = g_value_dup_string (value);
		break;
	case PROP_PUB_DATE:
		g_free (priv->pub_date);
		priv->pub_date = g_value_dup_string (value);
		break;
	case PROP_GUID:
		g_free (priv->guid);
		priv->guid = g_value_dup_string (value);
		break;
	case PROP_SOURCE:
		g_free (priv->source);
		priv->source = g_value_dup_string (value);
		break;
	case PROP_SOURCE_URL:
		g_free (priv->source_url);
		priv->source_url = g_value_dup_string (value);
		break;

	default:
		G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
	}
}

static void
rss_item_finalize (GObject *object)
{
	RssItemPrivate *priv = RSS_ITEM (object)->priv;

	g_free (priv->guid);
	g_free (priv->title);
	g_free (priv->link);
	g_free (priv->description);
	g_free (priv->copyright);
	g_free (priv->author);
	g_free (priv->author_uri);
	g_free (priv->author_email);
	g_free (priv->contributor);
	g_free (priv->contributor_uri);
	g_free (priv->contributor_email);
	g_free (priv->comments);
	g_free (priv->pub_date);
	g_free (priv->source);
	g_free (priv->source_url);
  
	g_list_foreach (priv->categories, (GFunc) g_free, NULL);
	g_list_free (priv->categories);

	G_OBJECT_CLASS (rss_item_parent_class)->finalize (object);
}

static void
rss_item_class_init (RssItemClass *klass)
{
	GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
	GParamSpec *pspec;

	g_type_class_add_private (klass, sizeof (RssItemPrivate));

	gobject_class->get_property = rss_item_get_property;
	gobject_class->set_property = rss_item_set_property;
	gobject_class->finalize = rss_item_finalize;

	/**
	 * RssItem:title:
	 *
	 * The title of the item.
	 */
	pspec = g_param_spec_string ("title",
	                             "Title",
	                             "Title of the item",
	                             NULL,
	                             G_PARAM_READWRITE);
	g_object_class_install_property (gobject_class,
	                                 PROP_TITLE,
	                                 pspec);

	/**
	 * RssItem:link:
	 *
	 * The link to the upstream source of the item.
	 */
	pspec = g_param_spec_string ("link",
	                             "Link",
	                             "Link to the upstream source",
	                             NULL,
	                             G_PARAM_READWRITE);
	g_object_class_install_property (gobject_class,
                                     PROP_LINK,
                                     pspec);

	/**
	 * RssItem:description:
	 *
	 * The description of the item.  This is often where the actual
	 * content for the item is stored.
	 */
	pspec = g_param_spec_string ("description",
	                             "Description",
	                             "Description of the item",
	                             NULL,
	                             G_PARAM_READWRITE);
	g_object_class_install_property (gobject_class,
                                     PROP_DESCRIPTION,
                                     pspec);

	/**
	 * RssItem:copyright:
	 *
	 * Any associated copyright that may exist for the content.
	 */
	pspec = g_param_spec_string ("copyright",
	                             "Copyright",
	                             "Any associated copyright for "
	                             "the content",
	                             NULL,
	                             G_PARAM_READWRITE);
	g_object_class_install_property (gobject_class,
                                     PROP_COPYRIGHT,
                                     pspec);

	/**
	 * RssItem:author:
	 *
	 * The author's name.
	 */
	pspec = g_param_spec_string ("author",
	                             "Author",
	                             "The name of the author",
	                             NULL,
	                             G_PARAM_READWRITE);
	g_object_class_install_property (gobject_class,
                                     PROP_AUTHOR,
                                     pspec);

	/**
	 * RssItem:author-uri:
	 *
	 * The authors uri, often a website.
	 */
	pspec = g_param_spec_string ("author-uri",
	                             "Author URI",
	                             "The URI of the author",
	                             NULL,
	                             G_PARAM_READWRITE);
	g_object_class_install_property (gobject_class,
                                     PROP_AUTHOR_URI,
                                     pspec);

	/**
	 * RssItem:author-email:
	 *
	 * The authors email.
	 */
	pspec = g_param_spec_string ("author-email",
	                             "Author Email",
	                             "The email address of the author",
	                             NULL,
	                             G_PARAM_READWRITE);
	g_object_class_install_property (gobject_class,
                                     PROP_AUTHOR_EMAIL,
                                     pspec);

	/**
	 * RssItem:contributor:
	 *
	 * The contributors name.
	 */
	pspec = g_param_spec_string ("contributor",
	                             "Contributor",
	                             "The name of the contributor",
	                             NULL,
	                             G_PARAM_READWRITE);
	g_object_class_install_property (gobject_class,
                                     PROP_CONTRIBUTOR,
                                     pspec);

	/**
	 * RssItem:contributor-uri:
	 *
	 * The contributors uri, often a website.
	 */
	pspec = g_param_spec_string ("contributor-uri",
	                             "Contributor URI",
	                             "The URI of the contributor",
	                             NULL,
	                             G_PARAM_READWRITE);
	g_object_class_install_property (gobject_class,
                                     PROP_CONTRIBUTOR_URI,
                                     pspec);

	/**
	 * RssItem:contributor-email:
	 *
	 * The contributors email.
	 */
	pspec = g_param_spec_string ("contributor-email",
	                             "Contributor Email",
	                             "The email of the contributor",
	                             NULL,
	                             G_PARAM_READWRITE);
	g_object_class_install_property (gobject_class,
                                     PROP_CONTRIBUTOR_EMAIL,
                                     pspec);

	/**
	 * RssItem:comments:
	 *
	 * Any comments that may have been associated with the item.
	 */
	pspec = g_param_spec_string ("comments",
	                             "Comments",
	                             "Any comment associated to the item",
	                             NULL,
	                             G_PARAM_READWRITE);
	g_object_class_install_property (gobject_class,
                                     PROP_COMMENTS,
                                     pspec);

	/**
	 * RssItem:pub-date:
	 *
	 * The string representation of the publish date.
	 */
	pspec = g_param_spec_string ("pub-date",
	                             "Publication Date",
	                             "The date of publication",
	                             NULL,
	                             G_PARAM_READWRITE);
	g_object_class_install_property (gobject_class,
                                     PROP_PUB_DATE,
                                     pspec);

	/**
	 * RssItem:guid:
	 *
	 * The guid of the item. Many feed engines will use the url here
	 * plus some tag metadata.
	 */
	pspec = g_param_spec_string ("guid",
	                             "GUID",
	                             "The guid of the item",
	                             NULL,
	                             G_PARAM_READWRITE);
	g_object_class_install_property (gobject_class,
                                     PROP_GUID,
                                     pspec);

	/**
	 * RssItem:source:
	 *
	 * The name of the source of the item.
	 */
	pspec = g_param_spec_string ("source",
	                             "Source",
	                             "Source of the item",
	                             NULL,
	                             G_PARAM_READWRITE);
	g_object_class_install_property (gobject_class,
                                     PROP_SOURCE,
                                     pspec);

	/**
	 * RssItem:source-url:
	 *
	 * The url of the source of the item.
	 */
	pspec = g_param_spec_string ("source-url",
	                             "Source URL",
	                             "URL of the source",
	                             NULL,
	                             G_PARAM_READWRITE);
	g_object_class_install_property (gobject_class,
                                     PROP_SOURCE_URL,
                                     pspec);
}

static void
rss_item_init (RssItem *self)
{
	self->priv = G_TYPE_INSTANCE_GET_PRIVATE (self, RSS_TYPE_ITEM, RssItemPrivate);
}

/**
 * rss_item_new:
 *
 * Creates a new #RssItem.  This isn't incredibly useful yet as we do not
 * have an RssGenerator written.  However, that will come eventuall and
 * make creating feeds much simpler.
 *
 * Returns: a new #RssItem which should be unref'd with g_object_unref().
 */
RssItem*
rss_item_new (void)
{
	return g_object_new (RSS_TYPE_ITEM, NULL);
}

/**
 * rss_item_get_guid:
 * @self: a #RssItem
 *
 * Retrieves the #RssItem:guid field.
 *
 * Return value: the value of the field. The returned string is
 *   owned by the #RssItem and should never be modified or freed.
 */
const gchar *
rss_item_get_guid (RssItem *self)
{
	g_return_val_if_fail (RSS_IS_ITEM (self), NULL);

	return self->priv->guid;
}

/**
 * rss_item_get_title:
 * @self: a #RssItem
 *
 * Retrieves the #RssItem:title field.
 *
 * Return value: the value of the field. The returned string is
 *   owned by the #RssItem and should never be modified or freed.
 */
const gchar *
rss_item_get_title (RssItem *self)
{
	g_return_val_if_fail (RSS_IS_ITEM (self), NULL);

	return self->priv->title;
}

/**
 * rss_item_get_link:
 * @self: a #RssItem
 *
 * Retrieves the #RssItem:link field.
 *
 * Return value: the value of the field. The returned string is
 *   owned by the #RssItem and should never be modified or freed.
 */
const gchar *
rss_item_get_link (RssItem *self)
{
        g_return_val_if_fail (RSS_IS_ITEM (self), NULL);

        return self->priv->link;
}

/**
 * rss_item_get_description:
 * @self: a #RssItem
 *
 * Retrieves the #RssItem:description field.
 *
 * Return value: the value of the field. The returned string is
 *   owned by the #RssItem and should never be modified or freed.
 */
const gchar *
rss_item_get_description (RssItem *self)
{
	g_return_val_if_fail (RSS_IS_ITEM (self), NULL);

	return self->priv->description;
}

/**
 * rss_item_get_copyright:
 * @self: a #RssItem
 *
 * Retrieves the #RssItem:copyright field.
 *
 * Return value: the value of the field. The returned string is
 *   owned by the #RssItem and should never be modified or freed.
 */
const gchar *
rss_item_get_copyright (RssItem *self)
{
	g_return_val_if_fail (RSS_IS_ITEM (self), NULL);

	return self->priv->copyright;
}

/**
 * rss_item_get_author_name:
 * @self: a #RssItem
 *
 * Retrieves the #RssItem:author field.
 *
 * Return value: the value of the field. The returned string is
 *   owned by the #RssItem and should never be modified or freed.
 */
const gchar *
rss_item_get_author_name (RssItem *self)
{
	g_return_val_if_fail (RSS_IS_ITEM (self), NULL);

	return self->priv->author;
}

/**
 * rss_item_get_author_uri:
 * @self: a #RssItem
 *
 * Retrieves the #RssItem:author-uri field.
 *
 * Return value: the value of the field. The returned string is
 *   owned by the #RssItem and should never be modified or freed.
 */
const gchar *
rss_item_get_author_uri (RssItem *self)
{
	g_return_val_if_fail (RSS_IS_ITEM (self), NULL);

	return self->priv->author_uri;
}

/**
 * rss_item_get_author_email:
 * @self: a #RssItem
 *
 * Retrieves the #RssItem:author-email field.
 *
 * Return value: the value of the field. The returned string is
 *   owned by the #RssItem and should never be modified or freed.
 */
const gchar *
rss_item_get_author_email (RssItem *self)
{
	g_return_val_if_fail (RSS_IS_ITEM (self), NULL);

	return self->priv->author_email;
}

/**
 * rss_item_get_contributor_name:
 * @self: a #RssItem
 *
 * Retrieves the #RssItem:contributor field.
 *
 * Return value: the value of the field. The returned string is
 *   owned by the #RssItem and should never be modified or freed.
 */
const gchar *
rss_item_get_contributor_name (RssItem *self)
{
	g_return_val_if_fail (RSS_IS_ITEM (self), NULL);

	return self->priv->contributor;
}

/**
 * rss_item_get_contributor_uri:
 * @self: a #RssItem
 *
 * Retrieves the #RssItem:contributor-uri field.
 *
 * Return value: the value of the field. The returned string is
 *   owned by the #RssItem and should never be modified or freed.
 */
const gchar *
rss_item_get_contributor_uri (RssItem *self)
{
	g_return_val_if_fail (RSS_IS_ITEM (self), NULL);

	return self->priv->contributor_uri;
}

/**
 * rss_item_get_contributor_email:
 * @self: a #RssItem
 *
 * Retrieves the #RssItem:contributor-email field.
 *
 * Return value: the value of the field. The returned string is
 *   owned by the #RssItem and should never be modified or freed.
 */
const gchar *
rss_item_get_contributor_email (RssItem *self)
{
	g_return_val_if_fail (RSS_IS_ITEM (self), NULL);

	return self->priv->contributor_email;
}

/**
 * rss_item_get_comments:
 * @self: a #RssItem
 *
 * Retrieves the #RssItem:comments field.
 *
 * Return value: the value of the field. The returned string is
 *   owned by the #RssItem and should never be modified or freed.
 */
const gchar *
rss_item_get_comments (RssItem *self)
{
	g_return_val_if_fail (RSS_IS_ITEM (self), NULL);

	return self->priv->comments;
}

/**
 * rss_item_get_pub_date:
 * @self: a #RssItem
 *
 * Retrieves the #RssItem:pub-date field.
 *
 * Return value: the value of the field. The returned string is
 *   owned by the #RssItem and should never be modified or freed.
 */
const gchar *
rss_item_get_pub_date (RssItem *self)
{
	g_return_val_if_fail (RSS_IS_ITEM (self), NULL);

	return self->priv->pub_date;
}

/**
 * rss_item_get_source:
 * @self: a #RssItem
 *
 * Retrieves the #RssItem:source field.
 *
 * Return value: the value of the field. The returned string is
 *   owned by the #RssItem and should never be modified or freed.
 */
const gchar *
rss_item_get_source (RssItem *self)
{
	g_return_val_if_fail (RSS_IS_ITEM (self), NULL);

	return self->priv->source;
}

/**
 * rss_item_get_source_url:
 * @self: a #RssItem
 *
 * Retrieves the #RssItem:source-url field.
 *
 * Return value: the value of the field. The returned string is
 *   owned by the #RssItem and should never be modified or freed.
 */
const gchar *
rss_item_get_source_url (RssItem *self)
{
	g_return_val_if_fail (RSS_IS_ITEM (self), NULL);

	return self->priv->source_url;
}

/**
 * rss_item_get_categories:
 * @self: a #RssItem
 *
 * Returns a copy of the list of categories for the #RssItem. The data
 * in the linked list are pointers to strings (char*).  They are owned
 * by the #RssItem and should not be modified.  Use g_strdup() to copy
 * the individual strings.
 *
 * Returns: a new #GList which should be freed with g_list_free().
 */
GList*
rss_item_get_categories (RssItem *self)
{
	g_return_val_if_fail (RSS_IS_ITEM (self), NULL);

	return g_list_copy (self->priv->categories);
}