aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/metadata-menu-item.vala132
-rw-r--r--src/metadata-widget.c2
-rw-r--r--src/player-item.vala61
-rw-r--r--src/sound-service.c4
4 files changed, 137 insertions, 62 deletions
diff --git a/src/metadata-menu-item.vala b/src/metadata-menu-item.vala
index 6e7230b..941fafd 100644
--- a/src/metadata-menu-item.vala
+++ b/src/metadata-menu-item.vala
@@ -19,15 +19,144 @@ with this program. If not, see <http://www.gnu.org/licenses/>.
using Gee;
using DbusmenuMetadata;
+using Gdk;
public class MetadataMenuitem : PlayerItem
{
+ public const string ALBUM_ART_DIR_SUFFIX = "/sound-menu-album-art";
+ public static string album_art_cache_dir;
+ private static FetchFile fetcher;
+ private string previous_temp_album_art_path;
+
public MetadataMenuitem()
{
Object(item_type: MENUITEM_TYPE);
reset(attributes_format());
}
+
+ construct{
+ MetadataMenuitem.clean_album_art_temp_dir();
+ this.previous_temp_album_art_path = null;
+ this.album_art_cache_dir = MetadataMenuitem.create_album_art_temp_dir();
+ }
+
+ private static void clean_album_art_temp_dir()
+ {
+ string path = Environment.get_user_special_dir(UserDirectory.PICTURES).dup().concat(ALBUM_ART_DIR_SUFFIX);
+
+ GLib.File? album_art_dir = GLib.File.new_for_uri(path);
+
+ if(album_art_dir == null || album_art_dir.query_exists(null) == false){
+ warning("here %s %s", (album_art_dir.query_exists(null) == false).to_string(), path);
+ return;
+ }
+
+ if(delete_album_art_contents(album_art_dir) == true)
+ {
+ if(DirUtils.remove(path) == -1){
+ warning("could not remove the temp album art directory %s", path);
+ }
+ }
+ }
+
+ private static string? create_album_art_temp_dir()
+ {
+ string path = Environment.get_user_special_dir(UserDirectory.PICTURES).dup().concat(ALBUM_ART_DIR_SUFFIX);
+ if(DirUtils.create(path, 0700) == -1){
+ warning("could not create a temp dir for remote album art - that means we are not going to bother with remote art");
+ return null;
+ }
+ return path;
+ }
+
+ private static bool delete_album_art_contents (GLib.File dir)
+ {
+ bool result = true;
+ try {
+ var e = dir.enumerate_children (FILE_ATTRIBUTE_STANDARD_NAME + "," + FILE_ATTRIBUTE_STANDARD_TYPE ,
+ FileQueryInfoFlags.NOFOLLOW_SYMLINKS,
+ null);
+ while (true)
+ {
+ var file = e.next_file (null);
+ if (file == null)
+ break;
+
+ var child = dir.get_child (file.get_name ());
+
+ try {
+ child.delete (null);
+ } catch (Error error_) {
+ warning (@"Unable to delete file '$(child.get_basename ()): $(error_.message)");
+ result = false;
+ }
+ }
+ } catch (Error error) {
+ warning (@"Unable to read files from directory '$(dir.get_basename ())': %s",
+ error.message);
+ result = false;
+ }
+ return result;
+ }
+
+ 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;
+ }
+ // If we didn't manage to create the temp dir
+ // don't bother with remote
+ debug("fetch_art -remotely %s", this.album_art_cache_dir);
+
+ if(this.album_art_cache_dir == null){
+ return;
+ }
+ // green light to 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 = this.album_art_cache_dir.concat("/XXXXXX");
+ int r = FileUtils.mkstemp(path);
+ if(r != -1){
+ icon.save (path, loader.get_format().get_name());
+ this.property_set(property, path);
+ if(this.previous_temp_album_art_path != null){
+ FileUtils.remove(this.previous_temp_album_art_path);
+ }
+ this.previous_temp_album_art_path = path;
+ }
+ }
+ catch(GLib.Error e){
+ warning("Problem creating file from bytearray fetched from the interweb - error: %s",
+ e.message);
+ }
+ }
public static HashSet<string> attributes_format()
{
@@ -37,6 +166,5 @@ public class MetadataMenuitem : PlayerItem
attrs.add(MENUITEM_ALBUM);
attrs.add(MENUITEM_ARTURL);
return attrs;
- }
-
+ }
}
diff --git a/src/metadata-widget.c b/src/metadata-widget.c
index 1d50779..dc6aaa6 100644
--- a/src/metadata-widget.c
+++ b/src/metadata-widget.c
@@ -187,10 +187,8 @@ metadata_image_expose (GtkWidget *metadata, GdkEventExpose *event, gpointer user
g_return_val_if_fail(IS_METADATA_WIDGET(user_data), FALSE);
MetadataWidget* widget = METADATA_WIDGET(user_data);
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_debug("and we are in");
GdkPixbuf* pixbuf;
pixbuf = gdk_pixbuf_new_from_file(priv->image_path->str, NULL);
g_debug("metadata_load_new_image -> pixbuf from %s",
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);
- }
- }
-
}
diff --git a/src/sound-service.c b/src/sound-service.c
index f19379d..51f5f37 100644
--- a/src/sound-service.c
+++ b/src/sound-service.c
@@ -41,8 +41,8 @@ service_shutdown (IndicatorService *service, gpointer user_data)
if (mainloop != NULL) {
g_debug("Service shutdown !");
//TODO: uncomment for release !!
- close_pulse_activites();
- g_main_loop_quit(mainloop);
+ //close_pulse_activites();
+ //g_main_loop_quit(mainloop);
}
return;
}