aboutsummaryrefslogtreecommitdiff
path: root/src/player-item.vala
diff options
context:
space:
mode:
Diffstat (limited to 'src/player-item.vala')
-rw-r--r--src/player-item.vala48
1 files changed, 22 insertions, 26 deletions
diff --git a/src/player-item.vala b/src/player-item.vala
index 82b9f07..7de6840 100644
--- a/src/player-item.vala
+++ b/src/player-item.vala
@@ -19,13 +19,15 @@ with this program. If not, see <http://www.gnu.org/licenses/>.
using Dbusmenu;
using Gee;
+using Gdk;
public class PlayerItem : Dbusmenu.Menuitem
{
public PlayerController owner {get; construct;}
public string item_type { get; construct; }
private const int EMPTY = -1;
-
+ private FetchFile fetcher;
+
public PlayerItem(string type)
{
Object(item_type: type);
@@ -62,6 +64,9 @@ public class PlayerItem : Dbusmenu.Menuitem
// 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);
+ continue;
}
else{
// The file is local, just parse the string
@@ -108,44 +113,35 @@ public class PlayerItem : Dbusmenu.Menuitem
return false;
}
- public fetch_remote_art(uri)
+ public void fetch_remote_art(string uri, string prop)
{
- this.fetcher = new FetchFile (uri);
+ 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 ();
}
-
- public string parse_art_url(string update)
- {
- if(update == null)
- return null;
- string temp_path = "/home/ronoc/Desktop/tempy.jpg";
- string local_path = "";
- string temp_name = "";
- debug("MetadataMenuitem: parse art url - result %s", local_path);
- return local_path;
+ private void on_fetcher_failed ()
+ {
+ warning("on_fetcher_failed -> could not fetch artwork");
}
-
- public extract_downloaded_file()
+
+ private void on_fetcher_completed(ByteArray update, string property)
{
+ string temp_path = "/home/ronoc/Desktop/tempy";
+ //"/tmp/indicator-sound-remote-image";
try{
PixbufLoader loader = new PixbufLoader ();
- bool write_result = loader.write (update.data, update.len());
+ loader.write (update.data, update.len);
loader.close ();
- unowned PixbufFormat format = loader.get_format();
- debug("the bloody format name is %s", format.get_name());
- debug("is the format null %s", (format == null).to_string());
Pixbuf icon = loader.get_pixbuf ();
- temp_name = loader.get_format().get_name();
- icon.save (temp_path, "jpeg");
- local_path = temp_path;
+ icon.save (temp_path, loader.get_format().get_name());
+ this.property_set(property, temp_path);
}
catch(GLib.Error e){
- warning("Problem taking file from the interweb - error: %s and name: %s",
- e.message,
- temp_name);
- }
+ warning("Problem taking file from the interweb - error: %s",
+ e.message);
+ }
+ }
}