aboutsummaryrefslogtreecommitdiff
path: root/src/player-item.vala
diff options
context:
space:
mode:
authorConor Curran <conor.curran@canonical.com>2010-09-03 20:05:42 +0100
committerConor Curran <conor.curran@canonical.com>2010-09-03 20:05:42 +0100
commitde523f44dbe55351c8fb8375823fe872a7d362e1 (patch)
tree2f26c7d2d8fb875d89d46050d4d9a5d68d43c11c /src/player-item.vala
parenteeefcb48bf469a2268601978353790f4e449db5f (diff)
downloadayatana-indicator-sound-de523f44dbe55351c8fb8375823fe872a7d362e1.tar.gz
ayatana-indicator-sound-de523f44dbe55351c8fb8375823fe872a7d362e1.tar.bz2
ayatana-indicator-sound-de523f44dbe55351c8fb8375823fe872a7d362e1.zip
big refactor
Diffstat (limited to 'src/player-item.vala')
-rw-r--r--src/player-item.vala61
1 files changed, 5 insertions, 56 deletions
diff --git a/src/player-item.vala b/src/player-item.vala
index 83b19d6..68ae6ef 100644
--- a/src/player-item.vala
+++ b/src/player-item.vala
@@ -19,15 +19,12 @@ 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;
- private string previous_temp_album_art_path;
public PlayerItem(string type)
{
@@ -36,7 +33,6 @@ 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){
@@ -69,8 +65,11 @@ public class PlayerItem : Dbusmenu.Menuitem
if (v.holds (typeof (string))){
string update = v.get_string().strip();
debug("with value : %s", update);
- if(property.contains("mpris:artUrl")){
- this.fetch_art(update.strip(), property);
+ if(property.contains("mpris:artUrl")){
+ // We know its a metadata instance because thats the only
+ // object with the arturl prop
+ MetadataMenuitem metadata = this as MetadataMenuitem;
+ metadata.fetch_art(update.strip(), property);
continue;
}
this.property_set(property, update);
@@ -106,55 +105,5 @@ public class PlayerItem : Dbusmenu.Menuitem
return false;
}
- 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");
- }
-
- private void on_fetcher_completed(ByteArray update, string property)
- {
- try{
- PixbufLoader loader = new PixbufLoader ();
- loader.write (update.data, update.len);
- loader.close ();
- Pixbuf icon = loader.get_pixbuf ();
- 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 creating file from bytearray fetched from the interweb - error: %s",
- e.message);
- }
- }
-
}