aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/common-defs.h1
-rw-r--r--src/metadata-menu-item.vala2
-rw-r--r--src/metadata-widget.c15
-rw-r--r--src/player-item.vala62
-rw-r--r--vapi/common-defs.vapi5
5 files changed, 44 insertions, 41 deletions
diff --git a/src/common-defs.h b/src/common-defs.h
index fc4e323..e554c11 100644
--- a/src/common-defs.h
+++ b/src/common-defs.h
@@ -25,7 +25,6 @@ with this program. If not, see <http://www.gnu.org/licenses/>.
#define SIGNAL_SINK_AVAILABLE_UPDATE "SinkAvailableUpdate"
#define DBUSMENU_PROPERTY_EMPTY -1
-#define DBUSMENU_PLAYER_ITEM_REMOTE_FILEPATH "/tmp/indicator-sound-downloaded-album-art"
/* DBUS Custom Items */
#define DBUSMENU_VOLUME_MENUITEM_TYPE "x-canonical-ido-volume-type"
diff --git a/src/metadata-menu-item.vala b/src/metadata-menu-item.vala
index 04284d4..6e7230b 100644
--- a/src/metadata-menu-item.vala
+++ b/src/metadata-menu-item.vala
@@ -38,5 +38,5 @@ public class MetadataMenuitem : PlayerItem
attrs.add(MENUITEM_ARTURL);
return attrs;
}
-
+
}
diff --git a/src/metadata-widget.c b/src/metadata-widget.c
index 3e01aec..a88d38c 100644
--- a/src/metadata-widget.c
+++ b/src/metadata-widget.c
@@ -36,7 +36,6 @@ struct _MetadataWidgetPrivate
GtkWidget* album_art;
GString* image_path;
GString* old_image_path;
- GString* remote_image_path;
GtkWidget* artist_label;
GtkWidget* piece_label;
GtkWidget* container_label;
@@ -105,7 +104,6 @@ metadata_widget_init (MetadataWidget *self)
priv->album_art = gtk_image_new();
priv->image_path = g_string_new(dbusmenu_menuitem_property_get(twin_item, DBUSMENU_METADATA_MENUITEM_ARTURL));
priv->old_image_path = g_string_new("");
- priv->remote_image_path = g_string_new(DBUSMENU_PLAYER_ITEM_REMOTE_FILEPATH);
g_debug("Metadata::At startup and image path = %s", priv->image_path->str);
g_signal_connect(priv->album_art, "expose-event",
@@ -190,9 +188,7 @@ metadata_image_expose (GtkWidget *metadata, GdkEventExpose *event, gpointer user
MetadataWidgetPrivate * priv = METADATA_WIDGET_GET_PRIVATE(widget);
g_debug("expose");
if(priv->image_path->len > 0){
- if(g_string_equal(priv->image_path, priv->old_image_path) == FALSE ||
- (g_string_equal(priv->image_path, priv->remote_image_path) == TRUE &&
- g_string_equal(priv->old_image_path, priv->remote_image_path) == FALSE)){
+ if(g_string_equal(priv->image_path, priv->old_image_path) == FALSE){
g_debug("and we are in");
GdkPixbuf* pixbuf;
pixbuf = gdk_pixbuf_new_from_file(priv->image_path->str, NULL);
@@ -328,11 +324,10 @@ metadata_widget_property_update(DbusmenuMenuitem* item, gchar* property,
}
else if(g_ascii_strcasecmp(DBUSMENU_METADATA_MENUITEM_ARTURL, property) == 0){
g_string_erase(priv->image_path, 0, -1);
- g_string_overwrite(priv->image_path, 0, g_value_get_string (value));
- // Basically force expose the reload the image because we have an image update
- // but we are using remote images i.e. the same file path but different images
- if(g_string_equal(priv->image_path, priv->remote_image_path) == TRUE){
- g_string_erase(priv->old_image_path, 0, -1);
+ g_string_overwrite(priv->image_path, 0, g_value_get_string (value));
+ // if its a remote image queue a redraw incase the download took too long
+ if (g_str_has_prefix(g_value_get_string (value), get_user_special_dir(GUserDirectory.PICTURES))){
+ g_debug("the image update is a download so redraw");
gtk_widget_queue_draw(GTK_WIDGET(mitem));
}
}
diff --git a/src/player-item.vala b/src/player-item.vala
index 1e16742..83b19d6 100644
--- a/src/player-item.vala
+++ b/src/player-item.vala
@@ -20,7 +20,6 @@ with this program. If not, see <http://www.gnu.org/licenses/>.
using Dbusmenu;
using Gee;
using Gdk;
-using DbusmenuPlayer;
public class PlayerItem : Dbusmenu.Menuitem
{
@@ -28,6 +27,7 @@ public class PlayerItem : Dbusmenu.Menuitem
public string item_type { get; construct; }
private const int EMPTY = -1;
private FetchFile fetcher;
+ private string previous_temp_album_art_path;
public PlayerItem(string type)
{
@@ -36,6 +36,7 @@ public class PlayerItem : Dbusmenu.Menuitem
construct {
this.property_set(MENUITEM_PROP_TYPE, item_type);
+ this.previous_temp_album_art_path = null;
}
public void reset(HashSet<string> attrs){
@@ -45,6 +46,12 @@ public class PlayerItem : Dbusmenu.Menuitem
}
}
+ /**
+ * update()
+ * Base update method for playeritems, takes the attributes and the incoming updates
+ * and attmepts to update the appropriate props on the object.
+ * Album art is handled separately to deal with remote and local file paths.
+ */
public void update(HashTable<string, Value?> data, HashSet<string> attributes)
{
debug("PlayerItem::update()");
@@ -62,25 +69,11 @@ public class PlayerItem : Dbusmenu.Menuitem
if (v.holds (typeof (string))){
string update = v.get_string().strip();
debug("with value : %s", update);
- // Special case for the arturl URI's.
if(property.contains("mpris:artUrl")){
- if(update.has_prefix("http://")){
- // This is asyncronous so handle it offline
- this.fetch_remote_art(update.strip(), property);
+ this.fetch_art(update.strip(), property);
continue;
- }
- else{
- // The file is local, just parse the string
- try{
- update = Filename.from_uri(update.strip());
- }
- catch(ConvertError e){
- warning("Problem converting URI %s to file path",
- update);
- }
- }
}
- this.property_set(property, update);
+ this.property_set(property, update);
}
else if (v.holds (typeof (int))){
debug("with value : %i", v.get_int());
@@ -95,7 +88,6 @@ public class PlayerItem : Dbusmenu.Menuitem
this.property_set_bool(property, v.get_boolean());
}
}
-
if(this.property_get_bool(MENUITEM_PROP_VISIBLE) == false){
this.property_set_bool(MENUITEM_PROP_VISIBLE, true);
}
@@ -114,14 +106,29 @@ public class PlayerItem : Dbusmenu.Menuitem
return false;
}
- public void fetch_remote_art(string uri, string prop)
- {
+ public void fetch_art(string uri, string prop)
+ {
+ File art_file = File.new_for_uri(uri);
+ if(art_file.is_native() == true){
+ string path;
+ try{
+ path = Filename.from_uri(uri.strip());
+ this.property_set(prop, path);
+ }
+ catch(ConvertError e){
+ warning("Problem converting URI %s to file path",
+ uri);
+ }
+ // eitherway return, the artwork was local
+ return;
+ }
+ // otherwise go remote
this.fetcher = new FetchFile (uri, prop);
this.fetcher.failed.connect (() => { this.on_fetcher_failed ();});
this.fetcher.completed.connect (this.on_fetcher_completed);
this.fetcher.fetch_data ();
}
-
+
private void on_fetcher_failed ()
{
warning("on_fetcher_failed -> could not fetch artwork");
@@ -134,13 +141,20 @@ public class PlayerItem : Dbusmenu.Menuitem
loader.write (update.data, update.len);
loader.close ();
Pixbuf icon = loader.get_pixbuf ();
- icon.save (ITEM_REMOTE_FILEPATH, loader.get_format().get_name());
- this.property_set(property, ITEM_REMOTE_FILEPATH);
+ string path = Environment.get_user_special_dir(UserDirectory.PICTURES).dup().concat("/indicator-sound-XXXXXX");
+ int r = FileUtils.mkstemp(path);
+ icon.save (path, loader.get_format().get_name());
+ if(this.previous_temp_album_art_path != null){
+ FileUtils.remove(this.previous_temp_album_art_path);
+ }
+ this.previous_temp_album_art_path = path;
+ this.property_set(property, path);
}
catch(GLib.Error e){
- warning("Problem fetching file from the interweb - error: %s",
+ warning("Problem creating file from bytearray fetched from the interweb - error: %s",
e.message);
}
}
+
}
diff --git a/vapi/common-defs.vapi b/vapi/common-defs.vapi
index 93f4795..84fb924 100644
--- a/vapi/common-defs.vapi
+++ b/vapi/common-defs.vapi
@@ -27,11 +27,6 @@ namespace DbusmenuMetadata{
}
[CCode (cheader_filename = "common-defs.h")]
-namespace DbusmenuPlayer{
- public const string ITEM_REMOTE_FILEPATH;
-}
-
-[CCode (cheader_filename = "common-defs.h")]
namespace DbusmenuTransport{
public const string MENUITEM_TYPE;
public const string MENUITEM_PLAY_STATE;