[rhythmbox] grilo: store thumbnail for playing tracks in extdb, if available



commit e6efd040a00773dac32376112c11af4e71eecb2e
Author: Jonathan Matthew <jonathan d14n org>
Date:   Sat Dec 17 22:48:38 2011 +1000

    grilo: store thumbnail for playing tracks in extdb, if available

 plugins/grilo/Makefile.am       |    1 +
 plugins/grilo/rb-grilo-plugin.c |  111 ++++++++++----------------------------
 2 files changed, 30 insertions(+), 82 deletions(-)
---
diff --git a/plugins/grilo/Makefile.am b/plugins/grilo/Makefile.am
index ca29c46..2776eba 100644
--- a/plugins/grilo/Makefile.am
+++ b/plugins/grilo/Makefile.am
@@ -24,6 +24,7 @@ INCLUDES = 						\
 	-I$(top_srcdir)/sources                    	\
 	-I$(top_srcdir)/plugins				\
 	-I$(top_srcdir)/shell				\
+	-I$(top_srcdir)/metadata			\
 	-DPIXMAP_DIR=\""$(datadir)/pixmaps"\"		\
 	-DSHARE_DIR=\"$(pkgdatadir)\"                   \
 	-DDATADIR=\""$(datadir)"\"			\
diff --git a/plugins/grilo/rb-grilo-plugin.c b/plugins/grilo/rb-grilo-plugin.c
index 49e3b69..75c990a 100644
--- a/plugins/grilo/rb-grilo-plugin.c
+++ b/plugins/grilo/rb-grilo-plugin.c
@@ -41,6 +41,7 @@
 #include "rb-shell-player.h"
 #include "rb-grilo-source.h"
 #include "rb-display-page-group.h"
+#include "rb-ext-db.h"
 
 #define RB_TYPE_GRILO_PLUGIN		(rb_grilo_plugin_get_type ())
 #define RB_GRILO_PLUGIN(o)		(G_TYPE_CHECK_INSTANCE_CAST ((o), RB_TYPE_GRILO_PLUGIN, RBGriloPlugin))
@@ -66,9 +67,9 @@ typedef struct
 
 	GrlPluginRegistry *registry;
 	GHashTable *sources;
-	RhythmDB *db;
 	RBShellPlayer *shell_player;
 	gulong emit_cover_art_id;
+	RBExtDB *art_store;
 } RBGriloPlugin;
 
 typedef struct
@@ -132,85 +133,37 @@ grilo_source_added_cb (GrlPluginRegistry *registry, GrlMediaPlugin *grilo_plugin
 	g_object_unref (shell);
 }
 
-static const char *
-get_cover_art_uri (RhythmDBEntry *entry)
+static void
+playing_song_changed_cb (RBShellPlayer *player, RhythmDBEntry *entry, RBGriloPlugin *plugin)
 {
+	const char *uri;
 	RhythmDBEntryType *entry_type;
 	RBGriloEntryData *data;
 
+	if (entry == NULL)
+		return;
+
 	entry_type = rhythmdb_entry_get_entry_type (entry);
 	if (RB_IS_GRILO_ENTRY_TYPE (entry_type) == FALSE) {
-		return NULL;
+		return;
 	}
 
 	data = RHYTHMDB_ENTRY_GET_TYPE_DATA (entry, RBGriloEntryData);
-	return grl_data_get_string (data->grilo_data, GRL_METADATA_KEY_THUMBNAIL);
-}
-
-static GValue *
-cover_art_uri_request_cb (RhythmDB *db, RhythmDBEntry *entry, RBGriloPlugin *plugin)
-{
-	const char *uri;
-
-	uri = get_cover_art_uri (entry);
-	if (uri != NULL) {
-		GValue *value = g_new0 (GValue, 1);
-		g_value_init (value, G_TYPE_STRING);
-		rb_debug ("cover art uri: %s", uri);
-		g_value_set_string (value, uri);
-		return value;
-	} else {
-		return NULL;
-	}
-}
-
-static void
-extra_metadata_gather_cb (RhythmDB *db, RhythmDBEntry *entry, RBStringValueMap *map, RBGriloPlugin *plugin)
-{
-	const char *uri;
-
-	uri = get_cover_art_uri (entry);
+	uri = grl_data_get_string (data->grilo_data, GRL_METADATA_KEY_THUMBNAIL);
 	if (uri != NULL) {
-		GValue v = {0,};
-		g_value_init (&v, G_TYPE_STRING);
-		rb_debug ("cover art uri: %s", uri);
-		rb_string_value_map_set (map, "rb:coverArt-uri", &v);
-		g_value_unset (&v);
-	}
-}
-
-static gboolean
-emit_cover_art_cb (RBGriloPlugin *plugin)
-{
-	const char *uri;
-	RhythmDBEntry *entry;
-	GValue v = {0,};
-
-	entry = rb_shell_player_get_playing_entry (plugin->shell_player);
-	uri = get_cover_art_uri (entry);
-	rb_debug ("emitting cover art uri: %s", uri);
-
-	g_value_init (&v, G_TYPE_STRING);
-	g_value_set_string (&v, uri);
-	rhythmdb_emit_entry_extra_metadata_notify (plugin->db, entry, "rb:coverArt-uri", &v);
-	g_value_unset (&v);
-
-	plugin->emit_cover_art_id = 0;
-	return FALSE;
-}
-
-static void
-playing_song_changed_cb (RBShellPlayer *player, RhythmDBEntry *entry, RBGriloPlugin *plugin)
-{
-	if (entry == NULL || get_cover_art_uri (entry) == NULL) {
-		if (plugin->emit_cover_art_id != 0) {
-			g_source_remove (plugin->emit_cover_art_id);
-			plugin->emit_cover_art_id = 0;
-		}
-	} else {
-		if (plugin->emit_cover_art_id == 0) {
-			plugin->emit_cover_art_id = g_idle_add ((GSourceFunc)emit_cover_art_cb, plugin);
-		}
+		RBExtDBKey *key;
+
+		key = rb_ext_db_key_create ("album", rhythmdb_entry_get_string (entry, RHYTHMDB_PROP_ALBUM));
+		rb_ext_db_key_add_field (key,
+					 "artist",
+					 RB_EXT_DB_FIELD_OPTIONAL,
+					 rhythmdb_entry_get_string (entry, RHYTHMDB_PROP_ARTIST));
+
+		rb_ext_db_store_uri (plugin->art_store,
+				     key,
+				     RB_EXT_DB_SOURCE_SEARCH,
+				     uri);
+		rb_ext_db_key_free (key);
 	}
 }
 
@@ -235,16 +188,12 @@ impl_activate (PeasActivatable *plugin)
 	}
 
 	g_object_get (plugin, "object", &shell, NULL);
-	g_object_get (shell,
-		      "db", &pi->db,
-		      "shell-player", &pi->shell_player,
-		      NULL);
+	g_object_get (shell, "shell-player", &pi->shell_player, NULL);
 	g_object_unref (shell);
 
-	g_signal_connect (pi->db, "entry-extra-metadata-request::" RHYTHMDB_PROP_COVER_ART_URI, G_CALLBACK (cover_art_uri_request_cb), pi);
-	g_signal_connect (pi->db, "entry-extra-metadata-gather" , G_CALLBACK (extra_metadata_gather_cb), pi);
-
 	g_signal_connect (pi->shell_player, "playing-song-changed", G_CALLBACK (playing_song_changed_cb), pi);
+
+	pi->art_store = rb_ext_db_new ("album-art");
 }
 
 static void
@@ -271,11 +220,6 @@ impl_deactivate	(PeasActivatable *bplugin)
 	g_object_unref (plugin->registry);
 	plugin->registry = NULL;
 
-	g_signal_handlers_disconnect_by_func (plugin->db, G_CALLBACK (cover_art_uri_request_cb), plugin);
-	g_signal_handlers_disconnect_by_func (plugin->db, G_CALLBACK (extra_metadata_gather_cb), plugin);
-	g_object_unref (plugin->db);
-	plugin->db = NULL;
-
 	if (plugin->emit_cover_art_id != 0) {
 		g_source_remove (plugin->emit_cover_art_id);
 		plugin->emit_cover_art_id = 0;
@@ -283,6 +227,9 @@ impl_deactivate	(PeasActivatable *bplugin)
 	g_signal_handlers_disconnect_by_func (plugin->shell_player, G_CALLBACK (playing_song_changed_cb), plugin);
 	g_object_unref (plugin->shell_player);
 	plugin->shell_player = NULL;
+
+	g_object_unref (plugin->art_store);
+	plugin->art_store = NULL;
 }
 
 G_MODULE_EXPORT void



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