[Xfce4-commits] <parole:master> Add album art functionality
Sean Davis
noreply at xfce.org
Thu Dec 12 00:18:19 CET 2013
Updating branch refs/heads/master
to d132bc7880c30ceedcb1aaf5ed1752929680d1ee (commit)
from 9276bc68d7dca3d68590bad6ae217346b59776ae (commit)
commit d132bc7880c30ceedcb1aaf5ed1752929680d1ee
Author: Sean Davis <smd.seandavis at gmail.com>
Date: Sun Nov 17 11:08:56 2013 -0500
Add album art functionality
src/misc/parole-stream.c | 53 +++++++++++++++++++++++++++++++++-
src/plugins/mpris2/mpris2-provider.c | 7 +++--
2 files changed, 56 insertions(+), 4 deletions(-)
diff --git a/src/misc/parole-stream.c b/src/misc/parole-stream.c
index dc403f9..2c22120 100644
--- a/src/misc/parole-stream.c
+++ b/src/misc/parole-stream.c
@@ -29,6 +29,7 @@
#include <string.h>
#include <glib.h>
+#include <glib/gstdio.h>
#include "parole-stream.h"
#include "parole-enum-types.h"
@@ -71,6 +72,7 @@ struct _ParoleStreamPrivate
gchar *album;
gchar *comment;
GdkPixbuf *image;
+ gchar *image_uri, *previous_image;
ParoleMediaType media_type;
};
@@ -98,7 +100,8 @@ enum
PROP_ARTIST,
PROP_YEAR,
PROP_ALBUM,
- PROP_COMMENT
+ PROP_COMMENT,
+ PROP_IMAGE_URI
};
G_DEFINE_TYPE (ParoleStream, parole_stream, G_TYPE_OBJECT)
@@ -149,6 +152,11 @@ static void parole_stream_set_property (GObject *object,
parole_stream_get_media_type_from_uri (stream, priv->uri);
break;
}
+ case PROP_IMAGE_URI:
+ {
+ PAROLE_STREAM_GET_PRIVATE (stream)->image_uri = g_value_dup_string (value);
+ break;
+ }
case PROP_SUBTITLES:
PAROLE_STREAM_DUP_GVALUE_STRING (PAROLE_STREAM_GET_PRIVATE (stream)->subtitles, value);
break;
@@ -236,6 +244,9 @@ static void parole_stream_get_property (GObject *object,
case PROP_URI:
g_value_set_string (value, PAROLE_STREAM_GET_PRIVATE (stream)->uri);
break;
+ case PROP_IMAGE_URI:
+ g_value_set_string (value, PAROLE_STREAM_GET_PRIVATE (stream)->image_uri);
+ break;
case PROP_SUBTITLES:
g_value_set_string (value, PAROLE_STREAM_GET_PRIVATE (stream)->subtitles);
break;
@@ -318,6 +329,8 @@ void
parole_stream_set_image (GObject *object, GdkPixbuf *pixbuf)
{
ParoleStream *stream;
+ gchar *filename = NULL;
+ gint fid;
stream = PAROLE_STREAM (object);
@@ -325,9 +338,24 @@ parole_stream_set_image (GObject *object, GdkPixbuf *pixbuf)
g_object_unref(G_OBJECT(PAROLE_STREAM_GET_PRIVATE (stream)->image));
if (pixbuf)
+ {
PAROLE_STREAM_GET_PRIVATE (stream)->image = gdk_pixbuf_copy(pixbuf);
+
+ /* Create a jpeg of the artwork for other components to easily access */
+ fid = g_file_open_tmp ("parole-art-XXXXXX.jpg", &filename, NULL);
+ close(fid);
+ gdk_pixbuf_save (pixbuf, filename, "jpeg", NULL, "quality", "100", NULL);
+
+ PAROLE_STREAM_GET_PRIVATE (stream)->previous_image = g_strdup(filename);
+ PAROLE_STREAM_GET_PRIVATE (stream)->image_uri = g_strdup_printf("file://%s", filename);
+ g_free(filename);
+ }
else
+ {
PAROLE_STREAM_GET_PRIVATE (stream)->image = NULL;
+ PAROLE_STREAM_GET_PRIVATE (stream)->previous_image = NULL;
+ PAROLE_STREAM_GET_PRIVATE (stream)->image_uri = NULL;
+ }
}
GdkPixbuf *
@@ -683,6 +711,21 @@ parole_stream_class_init (ParoleStreamClass *klass)
"Comment",
NULL,
G_PARAM_READWRITE));
+
+ /**
+ * ParoleStream:image_uri:
+ *
+ * URI for the currently playing album's artwork.
+ *
+ * Since: 0.6
+ **/
+ g_object_class_install_property (object_class,
+ PROP_IMAGE_URI,
+ g_param_spec_string ("image_uri",
+ "Image URI",
+ "URI for the album artwork",
+ NULL,
+ G_PARAM_READWRITE));
g_type_class_add_private (klass, sizeof (ParoleStreamPrivate));
}
@@ -729,4 +772,12 @@ void parole_stream_init_properties (ParoleStream *stream)
PAROLE_STREAM_FREE_STR_PROP (priv->year);
PAROLE_STREAM_FREE_STR_PROP (priv->album);
PAROLE_STREAM_FREE_STR_PROP (priv->comment);
+ PAROLE_STREAM_FREE_STR_PROP (priv->image_uri);
+
+ /* Remove the previous image if it exists */
+ if ( PAROLE_STREAM_GET_PRIVATE (stream)->previous_image )
+ {
+ g_remove (PAROLE_STREAM_GET_PRIVATE (stream)->previous_image);
+ }
+ PAROLE_STREAM_GET_PRIVATE (stream)->previous_image = NULL;
}
diff --git a/src/plugins/mpris2/mpris2-provider.c b/src/plugins/mpris2/mpris2-provider.c
index 465ef59..ebc34c5 100644
--- a/src/plugins/mpris2/mpris2-provider.c
+++ b/src/plugins/mpris2/mpris2-provider.c
@@ -441,7 +441,7 @@ static void handle_strings_request(GVariantBuilder *b, const gchar *tag, const g
static void handle_get_metadata (const ParoleStream *stream, GVariantBuilder *b)
{
- gchar *title, *album, *artist, *year, *comment, *stream_uri;
+ gchar *title, *album, *artist, *year, *comment, *stream_uri, *image_uri;
gint64 duration;
g_object_get (G_OBJECT (stream),
@@ -452,10 +452,13 @@ static void handle_get_metadata (const ParoleStream *stream, GVariantBuilder *b)
"comment", &comment,
"duration", &duration,
"uri", &stream_uri,
+ "image_uri", &image_uri,
NULL);
g_variant_builder_add (b, "{sv}", "mpris:trackid",
handle_get_trackid(stream));
+ g_variant_builder_add (b, "{sv}", "mpris:artUrl",
+ g_variant_new_string(image_uri));
g_variant_builder_add (b, "{sv}", "xesam:url",
g_variant_new_string(stream_uri));
g_variant_builder_add (b, "{sv}", "xesam:title",
@@ -478,8 +481,6 @@ static void handle_get_metadata (const ParoleStream *stream, GVariantBuilder *b)
g_variant_builder_add (b, "{sv}", "audio-samplerate",
g_variant_new_int32(0));
- // TODO: add mpris:artUrl
-
g_free(title);
g_free(album);
g_free(artist);
More information about the Xfce4-commits
mailing list