hythmbox-2.98/podcast/rb-podcast-entry-types.c

No issues found

  1 /* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*-
  2  *
  3  *  Copyright (C) 2010  Jonathan Matthew  <jonathan@d14n.org>
  4  *
  5  *  This program is free software; you can redistribute it and/or modify
  6  *  it under the terms of the GNU General Public License as published by
  7  *  the Free Software Foundation; either version 2 of the License, or
  8  *  (at your option) any later version.
  9  *
 10  *  The Rhythmbox authors hereby grant permission for non-GPL compatible
 11  *  GStreamer plugins to be used and distributed together with GStreamer
 12  *  and Rhythmbox. This permission is above and beyond the permissions granted
 13  *  by the GPL license by which Rhythmbox is covered. If you modify this code
 14  *  you may extend this exception to your version of the code, but you are not
 15  *  obligated to do so. If you do not wish to do so, delete this exception
 16  *  statement from your version.
 17  *
 18  *  This program is distributed in the hope that it will be useful,
 19  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 20  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 21  *  GNU General Public License for more details.
 22  *
 23  *  You should have received a copy of the GNU General Public License
 24  *  along with this program; if not, write to the Free Software
 25  *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301  USA.
 26  *
 27  */
 28 
 29 #include "config.h"
 30 
 31 #include "rb-podcast-entry-types.h"
 32 #include "rhythmdb-private.h"		/* for RhythmDBPodcastFields, which should move in here somehow */
 33 #include "rhythmdb.h"
 34 #include "rb-util.h"
 35 
 36 static RhythmDBEntryType *podcast_post_entry_type = NULL;
 37 static RhythmDBEntryType *podcast_feed_entry_type = NULL;
 38 static RhythmDBEntryType *podcast_search_entry_type = NULL;
 39 
 40 /* podcast post entry type class */
 41 
 42 typedef struct _RhythmDBEntryType RBPodcastPostEntryType;
 43 typedef struct _RhythmDBEntryTypeClass RBPodcastPostEntryTypeClass;
 44 
 45 static void rb_podcast_post_entry_type_class_init (RBPodcastPostEntryTypeClass *klass);
 46 static void rb_podcast_post_entry_type_init (RBPodcastPostEntryType *etype);
 47 GType rb_podcast_post_entry_type_get_type (void);
 48 
 49 G_DEFINE_TYPE (RBPodcastPostEntryType, rb_podcast_post_entry_type, RHYTHMDB_TYPE_ENTRY_TYPE);
 50 
 51 /* podcast feed entry type class */
 52 
 53 typedef struct _RhythmDBEntryType RBPodcastFeedEntryType;
 54 typedef struct _RhythmDBEntryTypeClass RBPodcastFeedEntryTypeClass;
 55 
 56 static void rb_podcast_feed_entry_type_class_init (RBPodcastFeedEntryTypeClass *klass);
 57 static void rb_podcast_feed_entry_type_init (RBPodcastFeedEntryType *etype);
 58 GType rb_podcast_feed_entry_type_get_type (void);
 59 
 60 G_DEFINE_TYPE (RBPodcastFeedEntryType, rb_podcast_feed_entry_type, RHYTHMDB_TYPE_ENTRY_TYPE);
 61 
 62 /* podcast search entry type class */
 63 
 64 typedef struct _RhythmDBEntryType RBPodcastSearchEntryType;
 65 typedef struct _RhythmDBEntryTypeClass RBPodcastSearchEntryTypeClass;
 66 
 67 static void rb_podcast_search_entry_type_class_init (RBPodcastSearchEntryTypeClass *klass);
 68 static void rb_podcast_search_entry_type_init (RBPodcastSearchEntryType *etype);
 69 GType rb_podcast_search_entry_type_get_type (void);
 70 
 71 G_DEFINE_TYPE (RBPodcastSearchEntryType, rb_podcast_search_entry_type, RHYTHMDB_TYPE_ENTRY_TYPE);
 72 
 73 static void
 74 podcast_post_create (RhythmDBEntryType *entry_type, RhythmDBEntry *entry)
 75 {
 76 	RhythmDBPodcastFields *podcast = RHYTHMDB_ENTRY_GET_TYPE_DATA (entry, RhythmDBPodcastFields);
 77 	RBRefString *empty = rb_refstring_new ("");
 78 	podcast->description = rb_refstring_ref (empty);
 79 	podcast->subtitle = rb_refstring_ref (empty);
 80 	podcast->summary = rb_refstring_ref (empty);
 81 	podcast->lang = rb_refstring_ref (empty);
 82 	podcast->copyright = rb_refstring_ref (empty);
 83 	podcast->image = rb_refstring_ref (empty);
 84 	rb_refstring_unref (empty);
 85 }
 86 
 87 static void
 88 podcast_data_destroy (RhythmDBEntryType *entry_type, RhythmDBEntry *entry)
 89 {
 90 	RhythmDBPodcastFields *podcast = RHYTHMDB_ENTRY_GET_TYPE_DATA (entry, RhythmDBPodcastFields);
 91 	rb_refstring_unref (podcast->description);
 92 	rb_refstring_unref (podcast->subtitle);
 93 	rb_refstring_unref (podcast->summary);
 94 	rb_refstring_unref (podcast->lang);
 95 	rb_refstring_unref (podcast->copyright);
 96 	rb_refstring_unref (podcast->image);
 97 }
 98 
 99 /**
100  * rb_podcast_get_post_entry_type:
101  *
102  * Returns the #RhythmDBEntryType for podcast posts
103  *
104  * Return value: (transfer none): the entry type for podcast posts
105  */
106 RhythmDBEntryType *
107 rb_podcast_get_post_entry_type (void)
108 {
109 	return podcast_post_entry_type;
110 }
111 
112 static void
113 rb_podcast_post_entry_type_class_init (RBPodcastPostEntryTypeClass *klass)
114 {
115 	RhythmDBEntryTypeClass *etype_class = RHYTHMDB_ENTRY_TYPE_CLASS (klass);
116 
117 	etype_class->entry_created = podcast_post_create;
118 	etype_class->destroy_entry = podcast_data_destroy;
119 	etype_class->can_sync_metadata = (RhythmDBEntryTypeBooleanFunc) rb_true_function;
120 	etype_class->sync_metadata = (RhythmDBEntryTypeSyncFunc) rb_null_function;
121 }
122 
123 static void
124 rb_podcast_post_entry_type_init (RBPodcastPostEntryType *etype)
125 {
126 }
127 
128 /**
129  * rhythmdb_get_feed_entry_type:
130  *
131  * Returns the #RhythmDBEntryType for podcast feeds 
132  *
133  * Return value: (transfer none): the entry type for podcast feeds
134  */
135 RhythmDBEntryType *
136 rb_podcast_get_feed_entry_type (void)
137 {
138 	return podcast_feed_entry_type;
139 }
140 
141 static void
142 rb_podcast_feed_entry_type_class_init (RBPodcastFeedEntryTypeClass *klass)
143 {
144 	RhythmDBEntryTypeClass *etype_class = RHYTHMDB_ENTRY_TYPE_CLASS (klass);
145 
146 	etype_class->entry_created = podcast_post_create;
147 	etype_class->destroy_entry = podcast_data_destroy;
148 	etype_class->get_playback_uri = (RhythmDBEntryTypeStringFunc) rb_null_function;
149 	etype_class->can_sync_metadata = (RhythmDBEntryTypeBooleanFunc) rb_true_function;
150 	etype_class->sync_metadata = (RhythmDBEntryTypeSyncFunc) rb_null_function;
151 }
152 
153 static void
154 rb_podcast_feed_entry_type_init (RBPodcastFeedEntryType *etype)
155 {
156 }
157 
158 /**
159  * rhythmdb_get_search_entry_type:
160  *
161  * Returns the #RhythmDBEntryType for search result podcast episodes
162  *
163  * Return value: (transfer none): the entry type for search result podcast episodes
164  */
165 RhythmDBEntryType *
166 rb_podcast_get_search_entry_type (void)
167 {
168 	return podcast_search_entry_type;
169 }
170 
171 static void
172 rb_podcast_search_entry_type_class_init (RBPodcastSearchEntryTypeClass *klass)
173 {
174 	RhythmDBEntryTypeClass *etype_class = RHYTHMDB_ENTRY_TYPE_CLASS (klass);
175 
176 	etype_class->entry_created = podcast_post_create;
177 	etype_class->destroy_entry = podcast_data_destroy;
178 	etype_class->can_sync_metadata = (RhythmDBEntryTypeBooleanFunc) rb_true_function;
179 	etype_class->sync_metadata = (RhythmDBEntryTypeSyncFunc) rb_null_function;
180 }
181 
182 static void
183 rb_podcast_search_entry_type_init (RBPodcastSearchEntryType *etype)
184 {
185 }
186 
187 
188 void
189 rb_podcast_register_entry_types (RhythmDB *db)
190 {
191 	g_assert (podcast_post_entry_type == NULL);
192 	g_assert (podcast_feed_entry_type == NULL);
193 
194 	podcast_post_entry_type = g_object_new (rb_podcast_post_entry_type_get_type (),
195 						"db", db,
196 						"name", "podcast-post",
197 						"save-to-disk", TRUE,
198 						"category", RHYTHMDB_ENTRY_NORMAL,
199 						"type-data-size", sizeof (RhythmDBPodcastFields),
200 						NULL);
201 	rhythmdb_register_entry_type (db, podcast_post_entry_type);
202 
203 	podcast_feed_entry_type = g_object_new (rb_podcast_feed_entry_type_get_type (),
204 						"db", db,
205 						"name", "podcast-feed",
206 						"save-to-disk", TRUE,
207 						"category", RHYTHMDB_ENTRY_CONTAINER,
208 						"type-data-size", sizeof (RhythmDBPodcastFields),
209 						NULL);
210 	rhythmdb_register_entry_type (db, podcast_feed_entry_type);
211 
212 	podcast_search_entry_type = g_object_new (rb_podcast_search_entry_type_get_type (),
213 						"db", db,
214 						"name", "podcast-search",
215 						"save-to-disk", FALSE,
216 						"category", RHYTHMDB_ENTRY_NORMAL,
217 						"type-data-size", sizeof (RhythmDBPodcastFields),
218 						NULL);
219 	rhythmdb_register_entry_type (db, podcast_search_entry_type);
220 }