[rhythmbox] podcast: add entry type for podcast search results



commit 55c369409c5d87e2e797a4ab69ac3f2cada49a1c
Author: Jonathan Matthew <jonathan d14n org>
Date:   Sat May 26 13:52:14 2012 +1000

    podcast: add entry type for podcast search results
    
    This will be used to represent episodes in podcasts in search results.
    Entries of this type are not saved to disk, and don't do tricky things
    with mount points vs locations, but otherwise they're like episode entries.

 podcast/rb-podcast-entry-types.c |   64 +++++++++++++++++++++++-----
 podcast/rb-podcast-entry-types.h |    2 +
 podcast/rb-podcast-manager.c     |   86 +++++++++++++++++++++-----------------
 podcast/rb-podcast-manager.h     |    4 ++
 rhythmdb/rhythmdb.c              |    9 +++-
 5 files changed, 112 insertions(+), 53 deletions(-)
---
diff --git a/podcast/rb-podcast-entry-types.c b/podcast/rb-podcast-entry-types.c
index 8fc0cc6..4666ac2 100644
--- a/podcast/rb-podcast-entry-types.c
+++ b/podcast/rb-podcast-entry-types.c
@@ -35,6 +35,7 @@
 
 static RhythmDBEntryType *podcast_post_entry_type = NULL;
 static RhythmDBEntryType *podcast_feed_entry_type = NULL;
+static RhythmDBEntryType *podcast_search_entry_type = NULL;
 
 /* podcast post entry type class */
 
@@ -58,14 +59,16 @@ GType rb_podcast_feed_entry_type_get_type (void);
 
 G_DEFINE_TYPE (RBPodcastFeedEntryType, rb_podcast_feed_entry_type, RHYTHMDB_TYPE_ENTRY_TYPE);
 
-static char *
-podcast_get_playback_uri (RhythmDBEntryType *entry_type, RhythmDBEntry *entry)
-{
-	if (rhythmdb_entry_get_string (entry, RHYTHMDB_PROP_MOUNTPOINT) != NULL) {
-		return rhythmdb_entry_dup_string (entry, RHYTHMDB_PROP_LOCATION);
-	}
-	return NULL;
-}
+/* podcast search entry type class */
+
+typedef struct _RhythmDBEntryType RBPodcastSearchEntryType;
+typedef struct _RhythmDBEntryTypeClass RBPodcastSearchEntryTypeClass;
+
+static void rb_podcast_search_entry_type_class_init (RBPodcastSearchEntryTypeClass *klass);
+static void rb_podcast_search_entry_type_init (RBPodcastSearchEntryType *etype);
+GType rb_podcast_search_entry_type_get_type (void);
+
+G_DEFINE_TYPE (RBPodcastSearchEntryType, rb_podcast_search_entry_type, RHYTHMDB_TYPE_ENTRY_TYPE);
 
 static void
 podcast_post_create (RhythmDBEntryType *entry_type, RhythmDBEntry *entry)
@@ -113,7 +116,6 @@ rb_podcast_post_entry_type_class_init (RBPodcastPostEntryTypeClass *klass)
 
 	etype_class->entry_created = podcast_post_create;
 	etype_class->destroy_entry = podcast_data_destroy;
-	etype_class->get_playback_uri = podcast_get_playback_uri;
 	etype_class->can_sync_metadata = (RhythmDBEntryTypeBooleanFunc) rb_true_function;
 	etype_class->sync_metadata = (RhythmDBEntryTypeSyncFunc) rb_null_function;
 }
@@ -124,11 +126,11 @@ rb_podcast_post_entry_type_init (RBPodcastPostEntryType *etype)
 }
 
 /**
- * rhythmdb_get_ignore_entry_type:
+ * rhythmdb_get_feed_entry_type:
  *
- * Returns the #RhythmDBEntryType for ignored files
+ * Returns the #RhythmDBEntryType for podcast feeds 
  *
- * Return value: (transfer none): the entry type for ignored files
+ * Return value: (transfer none): the entry type for podcast feeds
  */
 RhythmDBEntryType *
 rb_podcast_get_feed_entry_type (void)
@@ -153,6 +155,35 @@ rb_podcast_feed_entry_type_init (RBPodcastFeedEntryType *etype)
 {
 }
 
+/**
+ * rhythmdb_get_search_entry_type:
+ *
+ * Returns the #RhythmDBEntryType for search result podcast episodes
+ *
+ * Return value: (transfer none): the entry type for search result podcast episodes
+ */
+RhythmDBEntryType *
+rb_podcast_get_search_entry_type (void)
+{
+	return podcast_search_entry_type;
+}
+
+static void
+rb_podcast_search_entry_type_class_init (RBPodcastSearchEntryTypeClass *klass)
+{
+	RhythmDBEntryTypeClass *etype_class = RHYTHMDB_ENTRY_TYPE_CLASS (klass);
+
+	etype_class->entry_created = podcast_post_create;
+	etype_class->destroy_entry = podcast_data_destroy;
+	etype_class->can_sync_metadata = (RhythmDBEntryTypeBooleanFunc) rb_true_function;
+	etype_class->sync_metadata = (RhythmDBEntryTypeSyncFunc) rb_null_function;
+}
+
+static void
+rb_podcast_search_entry_type_init (RBPodcastSearchEntryType *etype)
+{
+}
+
 
 void
 rb_podcast_register_entry_types (RhythmDB *db)
@@ -177,4 +208,13 @@ rb_podcast_register_entry_types (RhythmDB *db)
 						"type-data-size", sizeof (RhythmDBPodcastFields),
 						NULL);
 	rhythmdb_register_entry_type (db, podcast_feed_entry_type);
+
+	podcast_search_entry_type = g_object_new (rb_podcast_search_entry_type_get_type (),
+						"db", db,
+						"name", "podcast-search",
+						"save-to-disk", FALSE,
+						"category", RHYTHMDB_ENTRY_NORMAL,
+						"type-data-size", sizeof (RhythmDBPodcastFields),
+						NULL);
+	rhythmdb_register_entry_type (db, podcast_search_entry_type);
 }
diff --git a/podcast/rb-podcast-entry-types.h b/podcast/rb-podcast-entry-types.h
index 86d1b7d..b61906e 100644
--- a/podcast/rb-podcast-entry-types.h
+++ b/podcast/rb-podcast-entry-types.h
@@ -35,8 +35,10 @@ G_BEGIN_DECLS
 
 RhythmDBEntryType *rb_podcast_get_post_entry_type  (void);
 RhythmDBEntryType *rb_podcast_get_feed_entry_type  (void);
+RhythmDBEntryType *rb_podcast_get_search_entry_type  (void);
 #define RHYTHMDB_ENTRY_TYPE_PODCAST_POST (rb_podcast_get_post_entry_type ())
 #define RHYTHMDB_ENTRY_TYPE_PODCAST_FEED (rb_podcast_get_feed_entry_type ())
+#define RHYTHMDB_ENTRY_TYPE_PODCAST_SEARCH (rb_podcast_get_search_entry_type ())
 
 void			rb_podcast_register_entry_types		(RhythmDB *db);
 
diff --git a/podcast/rb-podcast-manager.c b/podcast/rb-podcast-manager.c
index 72b8b87..55758c2 100644
--- a/podcast/rb-podcast-manager.c
+++ b/podcast/rb-podcast-manager.c
@@ -155,7 +155,6 @@ static void rb_podcast_manager_save_metadata		(RBPodcastManager *pd,
 static void rb_podcast_manager_db_entry_added_cb 	(RBPodcastManager *pd,
 							 RhythmDBEntry *entry);
 static gboolean rb_podcast_manager_next_file 		(RBPodcastManager * pd);
-static void rb_podcast_manager_insert_feed 		(RBPodcastManager *pd, RBPodcastChannel *data);
 static void rb_podcast_manager_handle_feed_error	(RBPodcastManager *mgr,
 							 const char *url,
 							 GError *error,
@@ -1098,7 +1097,7 @@ rb_podcast_manager_parse_complete_cb (RBPodcastManagerParseResult *result)
 						      result->error,
 						      (result->automatic == FALSE));
 	} else {
-		rb_podcast_manager_insert_feed (result->pd, result->channel);
+		rb_podcast_manager_add_parsed_feed (result->pd, result->channel);
 	}
 
 	GDK_THREADS_LEAVE ();
@@ -1187,21 +1186,21 @@ rb_podcast_manager_thread_parse_feed (RBPodcastThreadInfo *info)
 
 RhythmDBEntry *
 rb_podcast_manager_add_post (RhythmDB *db,
-			      const char *name,
-			      const char *title,
-			      const char *subtitle,
-			      const char *generator,
-			      const char *uri,
-			      const char *description,
-			      gulong date,
-			      gulong duration,
-			      guint64 filesize)
+			     gboolean search_result,
+			     const char *name,
+			     const char *title,
+			     const char *subtitle,
+			     const char *generator,
+			     const char *uri,
+			     const char *description,
+			     gulong date,
+			     gulong duration,
+			     guint64 filesize)
 {
 	RhythmDBEntry *entry;
+	RhythmDBEntryType *entry_type;
 	GValue val = {0,};
 	GTimeVal time;
-	RhythmDBQueryModel *mountpoint_entries;
-	GtkTreeIter iter;
 
 	if (!uri || !name || !title || !g_utf8_validate(uri, -1, NULL)) {
 		return NULL;
@@ -1210,33 +1209,43 @@ rb_podcast_manager_add_post (RhythmDB *db,
 	if (entry)
 		return NULL;
 
-	/*
-	 * Does the uri exist as the mount-point?
-	 * This check is necessary since after an entry's file is downloaded,
-	 * the location stored in the db changes to the local file path
-	 * instead of the uri. The uri moves to the mount-point attribute.
-	 * Consequently, without this check, every downloaded entry will be
-	 * re-added to the db.
-	 */
-	mountpoint_entries = rhythmdb_query_model_new_empty (db);
-	g_object_set (mountpoint_entries, "show-hidden", TRUE, NULL);
-	rhythmdb_do_full_query (db, RHYTHMDB_QUERY_RESULTS (mountpoint_entries),
-		RHYTHMDB_QUERY_PROP_EQUALS,
-		RHYTHMDB_PROP_TYPE,
-		RHYTHMDB_ENTRY_TYPE_PODCAST_POST,
-		RHYTHMDB_QUERY_PROP_EQUALS,
-		RHYTHMDB_PROP_MOUNTPOINT,
-		uri,
-		RHYTHMDB_QUERY_END);
-
-	if (gtk_tree_model_get_iter_first (GTK_TREE_MODEL (mountpoint_entries), &iter)) {
+	if (search_result == FALSE) {
+		RhythmDBQueryModel *mountpoint_entries;
+		GtkTreeIter iter;
+
+		/*
+		 * Does the uri exist as the mount-point?
+		 * This check is necessary since after an entry's file is downloaded,
+		 * the location stored in the db changes to the local file path
+		 * instead of the uri. The uri moves to the mount-point attribute.
+		 * Consequently, without this check, every downloaded entry will be
+		 * re-added to the db.
+		 */
+		mountpoint_entries = rhythmdb_query_model_new_empty (db);
+		g_object_set (mountpoint_entries, "show-hidden", TRUE, NULL);
+		rhythmdb_do_full_query (db, RHYTHMDB_QUERY_RESULTS (mountpoint_entries),
+			RHYTHMDB_QUERY_PROP_EQUALS,
+			RHYTHMDB_PROP_TYPE,
+			RHYTHMDB_ENTRY_TYPE_PODCAST_POST,
+			RHYTHMDB_QUERY_PROP_EQUALS,
+			RHYTHMDB_PROP_MOUNTPOINT,
+			uri,
+			RHYTHMDB_QUERY_END);
+
+		if (gtk_tree_model_get_iter_first (GTK_TREE_MODEL (mountpoint_entries), &iter)) {
+			g_object_unref (mountpoint_entries);
+			return NULL;
+		}
 		g_object_unref (mountpoint_entries);
-		return NULL;
 	}
-	g_object_unref (mountpoint_entries);
+
+	if (search_result)
+		entry_type = RHYTHMDB_ENTRY_TYPE_PODCAST_SEARCH;
+	else
+		entry_type = RHYTHMDB_ENTRY_TYPE_PODCAST_POST;
 
 	entry = rhythmdb_entry_new (db,
-				    RHYTHMDB_ENTRY_TYPE_PODCAST_POST,
+				    entry_type,
 				    uri);
 	if (entry == NULL)
 		return NULL;
@@ -1918,8 +1927,8 @@ rb_podcast_manager_insert_feed_url (RBPodcastManager *pd, const char *url)
 	g_value_unset (&last_update_val);
 }
 
-static void
-rb_podcast_manager_insert_feed (RBPodcastManager *pd, RBPodcastChannel *data)
+void
+rb_podcast_manager_add_parsed_feed (RBPodcastManager *pd, RBPodcastChannel *data)
 {
 	GValue description_val = { 0, };
 	GValue title_val = { 0, };
@@ -2084,6 +2093,7 @@ rb_podcast_manager_insert_feed (RBPodcastManager *pd, RBPodcastChannel *data)
 
 		post_entry =
 		    rb_podcast_manager_add_post (db,
+			    FALSE,
 			    title,
 			    (gchar *) item->title,
 			    (gchar *) data->url,
diff --git a/podcast/rb-podcast-manager.h b/podcast/rb-podcast-manager.h
index 5fcf8ef..6d0f3a0 100644
--- a/podcast/rb-podcast-manager.h
+++ b/podcast/rb-podcast-manager.h
@@ -27,7 +27,9 @@
  */
 
 #include <glib.h>
+
 #include <rhythmdb/rhythmdb.h>
+#include <podcast/rb-podcast-parse.h>
 
 #ifndef RB_PODCAST_MANAGER_H
 #define RB_PODCAST_MANAGER_H
@@ -76,10 +78,12 @@ gboolean                rb_podcast_manager_remove_feed 		(RBPodcastManager *pd,
 gchar *                 rb_podcast_manager_get_podcast_dir	(RBPodcastManager *pd);
 
 gboolean                rb_podcast_manager_subscribe_feed    	(RBPodcastManager *pd, const gchar* url, gboolean automatic);
+void			rb_podcast_manager_add_parsed_feed	(RBPodcastManager *pd, RBPodcastChannel *feed);
 void			rb_podcast_manager_insert_feed_url	(RBPodcastManager *pd, const char *url);
 void            	rb_podcast_manager_unsubscribe_feed    	(RhythmDB *db, const gchar* url);
 void			rb_podcast_manager_shutdown 		(RBPodcastManager *pd);
 RhythmDBEntry *         rb_podcast_manager_add_post  	  	(RhythmDB *db,
+								 gboolean search_result,
                                			         	 const char *name,
 	                                                 	 const char *title,
 	                                                 	 const char *subtitle,
diff --git a/rhythmdb/rhythmdb.c b/rhythmdb/rhythmdb.c
index 5a49a2a..dfa9d96 100644
--- a/rhythmdb/rhythmdb.c
+++ b/rhythmdb/rhythmdb.c
@@ -3359,7 +3359,8 @@ rhythmdb_entry_set_internal (RhythmDB *db,
 
 	if (!handled) {
 		if (entry->type == RHYTHMDB_ENTRY_TYPE_PODCAST_FEED ||
-		    entry->type == RHYTHMDB_ENTRY_TYPE_PODCAST_POST)
+		    entry->type == RHYTHMDB_ENTRY_TYPE_PODCAST_POST ||
+		    entry->type == RHYTHMDB_ENTRY_TYPE_PODCAST_SEARCH)
 			podcast = RHYTHMDB_ENTRY_GET_TYPE_DATA (entry, RhythmDBPodcastFields);
 
 		switch (propid) {
@@ -4751,7 +4752,8 @@ rhythmdb_entry_get_string (RhythmDBEntry *entry,
 	g_return_val_if_fail (entry->refcount > 0, NULL);
 
 	if (entry->type == RHYTHMDB_ENTRY_TYPE_PODCAST_FEED ||
-	    entry->type == RHYTHMDB_ENTRY_TYPE_PODCAST_POST)
+	    entry->type == RHYTHMDB_ENTRY_TYPE_PODCAST_POST ||
+	    entry->type == RHYTHMDB_ENTRY_TYPE_PODCAST_SEARCH)
 		podcast = RHYTHMDB_ENTRY_GET_TYPE_DATA (entry, RhythmDBPodcastFields);
 
 	rhythmdb_entry_sync_mirrored (entry, propid);
@@ -5047,7 +5049,8 @@ rhythmdb_entry_get_ulong (RhythmDBEntry *entry,
 	g_return_val_if_fail (entry != NULL, 0);
 
 	if (entry->type == RHYTHMDB_ENTRY_TYPE_PODCAST_FEED ||
-	    entry->type == RHYTHMDB_ENTRY_TYPE_PODCAST_POST)
+	    entry->type == RHYTHMDB_ENTRY_TYPE_PODCAST_POST ||
+	    entry->type == RHYTHMDB_ENTRY_TYPE_PODCAST_SEARCH)
 		podcast = RHYTHMDB_ENTRY_GET_TYPE_DATA (entry, RhythmDBPodcastFields);
 
 	switch (propid) {



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]