diff options
author | Conor Curran <conor.curran@canonical.com> | 2010-08-24 16:22:35 +0100 |
---|---|---|
committer | Conor Curran <conor.curran@canonical.com> | 2010-08-24 16:22:35 +0100 |
commit | feed9f62a8779febde16e4f4461967a2b2a33e72 (patch) | |
tree | 16819d94976992c79ca5ff79225f545eebc0b126 /src | |
parent | 92d628cf6bff2644d6ccafd9f5d8d31d7659a242 (diff) | |
download | ayatana-indicator-sound-feed9f62a8779febde16e4f4461967a2b2a33e72.tar.gz ayatana-indicator-sound-feed9f62a8779febde16e4f4461967a2b2a33e72.tar.bz2 ayatana-indicator-sound-feed9f62a8779febde16e4f4461967a2b2a33e72.zip |
mpris 2 metadata map changes implementated
Diffstat (limited to 'src')
-rw-r--r-- | src/common-defs.h | 10 | ||||
-rw-r--r-- | src/metadata-menu-item.vala | 14 | ||||
-rw-r--r-- | src/metadata-widget.c | 9 | ||||
-rw-r--r-- | src/mpris2-controller.vala | 53 | ||||
-rw-r--r-- | src/player-item.vala | 8 | ||||
-rw-r--r-- | src/scrub-menu-item.vala | 2 |
6 files changed, 59 insertions, 37 deletions
diff --git a/src/common-defs.h b/src/common-defs.h index e3b4552..e554c11 100644 --- a/src/common-defs.h +++ b/src/common-defs.h @@ -34,16 +34,16 @@ with this program. If not, see <http://www.gnu.org/licenses/>. #define DBUSMENU_TRANSPORT_MENUITEM_PLAY_STATE "x-canonical-sound-menu-player-transport-state" #define DBUSMENU_METADATA_MENUITEM_TYPE "x-canonical-sound-menu-player-metadata-type" -#define DBUSMENU_METADATA_MENUITEM_ARTIST "x-canonical-sound-menu-player-metadata-artist" -#define DBUSMENU_METADATA_MENUITEM_TITLE "x-canonical-sound-menu-player-metadata-title" -#define DBUSMENU_METADATA_MENUITEM_ALBUM "x-canonical-sound-menu-player-metadata-album" -#define DBUSMENU_METADATA_MENUITEM_ARTURL "x-canonical-sound-menu-player-metadata-arturl" +#define DBUSMENU_METADATA_MENUITEM_ARTIST "x-canonical-sound-menu-player-metadata-xesam:artist" +#define DBUSMENU_METADATA_MENUITEM_TITLE "x-canonical-sound-menu-player-metadata-xesam:title" +#define DBUSMENU_METADATA_MENUITEM_ALBUM "x-canonical-sound-menu-player-metadata-xesam:album" +#define DBUSMENU_METADATA_MENUITEM_ARTURL "x-canonical-sound-menu-player-metadata-mpris:artUrl" #define DBUSMENU_TITLE_MENUITEM_TYPE "x-canonical-sound-menu-player-title-type" #define DBUSMENU_TITLE_MENUITEM_NAME "x-canonical-sound-menu-player-title-name" #define DBUSMENU_SCRUB_MENUITEM_TYPE "x-canonical-sound-menu-player-scrub-type" -#define DBUSMENU_SCRUB_MENUITEM_DURATION "x-canonical-sound-menu-player-scrub-time" +#define DBUSMENU_SCRUB_MENUITEM_DURATION "x-canonical-sound-menu-player-scrub-mpris:length" #define DBUSMENU_SCRUB_MENUITEM_POSITION "x-canonical-sound-menu-player-scrub-position" #define DBUSMENU_SCRUB_MENUITEM_PLAY_STATE "x-canonical-sound-menu-player-scrub-play-state" diff --git a/src/metadata-menu-item.vala b/src/metadata-menu-item.vala index 3818b1c..b13196f 100644 --- a/src/metadata-menu-item.vala +++ b/src/metadata-menu-item.vala @@ -29,6 +29,20 @@ public class MetadataMenuitem : PlayerItem reset(attributes_format()); } + public bool needs_reset(GLib.HashTable<string, Value?> updates) + { + if(this.property_exist(MENUITEM_ARTURL) == false){ + return true; + } + if(this.property_get_int(MENUITEM_ARTURL) == EMPTY){ + return true; + } + if(strcmp(updates.lookup("xesam:artist").get_string() ,this.property_get(MENUITEM_ARTURL)) != 0){ + return true; + } + return false; + } + public static HashSet<string> attributes_format() { HashSet<string> attrs = new HashSet<string>(); diff --git a/src/metadata-widget.c b/src/metadata-widget.c index eec98b0..aeef670 100644 --- a/src/metadata-widget.c +++ b/src/metadata-widget.c @@ -236,8 +236,8 @@ metadata_image_expose (GtkWidget *metadata, GdkEventExpose *event, gpointer user pango_cairo_show_layout(cr, layout); g_object_unref(layout); - g_object_unref(p_context); - g_string_free (string); + g_object_unref(pcontext); + g_string_free (string, TRUE); cairo_destroy (cr); return TRUE; @@ -260,6 +260,9 @@ metadata_widget_button_press_event (GtkWidget *menuitem, gtk_clipboard_set_text (board, contents, -1); gtk_clipboard_store (board); g_free(contents); + g_free(title); + g_free(artist); + g_free(album); return FALSE; } @@ -295,7 +298,7 @@ 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_dup_string(value)); + g_string_overwrite(priv->image_path, 0, g_value_get_string (value)); metadata_widget_update_album_art(mitem); } } diff --git a/src/mpris2-controller.vala b/src/mpris2-controller.vala index 6fa140e..d5152c2 100644 --- a/src/mpris2-controller.vala +++ b/src/mpris2-controller.vala @@ -19,6 +19,7 @@ with this program. If not, see <http://www.gnu.org/licenses/>. */ using DBus; + [DBus (name = "org.mpris.MediaPlayer2")] public interface MprisRoot : DBus.Object { // properties @@ -89,7 +90,7 @@ public class Mpris2Controller : GLib.Object this.properties_interface.PropertiesChanged += property_changed_cb; } catch (DBus.Error e) { - error("Problems connecting to the session bus - %s", e.message); + error("Problems connecting to the session bus - %s", e.message); } } @@ -118,30 +119,34 @@ public class Mpris2Controller : GLib.Object Value? meta_v = changed_properties.lookup("Metadata"); if(meta_v != null){ - debug("metadata is not empty"); - debug("artist : %s", this.player.Metadata.lookup("artist").get_string()); - debug("arturl: %s", this.player.Metadata.lookup("arturl").get_string()); - /*try{ - debug("arturl : %s", this.player.Metadata.lookup("arturl").get_string()); - } - catch(GLib.Error e){ - warning("NO ART URL"); - }*/ + GLib.HashTable<string, Value?> changed_updates = clean_metadata(); + + MetadataMenuitem meta = this.owner.custom_items[PlayerController.widget_order.METADATA] as MetadataMenuitem; + meta.reset(MetadataMenuitem.attributes_format()); - this.owner.custom_items[PlayerController.widget_order.METADATA].reset(MetadataMenuitem.attributes_format()); - debug("After the reset the arturl = %i", this.owner.custom_items[PlayerController.widget_order.METADATA].property_get_int("x-canonical-sound-menu-player-metadata-arturl")); - this.owner.custom_items[PlayerController.widget_order.METADATA].update(this.player.Metadata, + this.owner.custom_items[PlayerController.widget_order.METADATA].update(changed_updates, MetadataMenuitem.attributes_format()); this.owner.custom_items[PlayerController.widget_order.SCRUB].reset(ScrubMenuitem.attributes_format()); - if((int)this.player.Metadata.lookup("artist").get_string().len() > 0 || - (int)this.player.Metadata.lookup("title").get_string().len() > 0){ - this.owner.custom_items[PlayerController.widget_order.SCRUB].update(this.player.Metadata, - ScrubMenuitem.attributes_format()); - } + this.owner.custom_items[PlayerController.widget_order.SCRUB].update(changed_updates, + ScrubMenuitem.attributes_format()); + (this.owner.custom_items[PlayerController.widget_order.SCRUB] as ScrubMenuitem).update_playstate(this.determine_play_state(this.player.PlaybackStatus)); } } + + private GLib.HashTable<string, Value?> clean_metadata() + { + GLib.HashTable<string, Value?> changed_updates = this.player.Metadata; + string[] artists = (string[])this.player.Metadata.lookup("xesam:artist"); + string display_artists = string.joinv(", ", artists); + changed_updates.replace("xesam:artist", display_artists); + debug("artist : %s", display_artists); + int64 duration = this.player.Metadata.lookup("mpris:length").get_int64(); + changed_updates.replace("mpris:length", duration/1000000); + return changed_updates; + } + private int determine_play_state(string status){ if(status == null) @@ -166,9 +171,10 @@ public class Mpris2Controller : GLib.Object debug("initial update - play state %i", status); (this.owner.custom_items[PlayerController.widget_order.TRANSPORT] as TransportMenuitem).change_play_state(status); - this.owner.custom_items[PlayerController.widget_order.METADATA].update(this.player.Metadata, + var cleaned_metadata = this.clean_metadata(); + this.owner.custom_items[PlayerController.widget_order.METADATA].update(cleaned_metadata, MetadataMenuitem.attributes_format()); - this.owner.custom_items[PlayerController.widget_order.SCRUB].update(this.player.Metadata, + this.owner.custom_items[PlayerController.widget_order.SCRUB].update(cleaned_metadata, ScrubMenuitem.attributes_format()); } @@ -211,19 +217,18 @@ public class Mpris2Controller : GLib.Object public void set_position(double position) { debug("Set position with pos (0-100) %f", position); - HashTable<string, Value?> data = this.player.Metadata; - Value? time_value = data.lookup("time"); + Value? time_value = this.player.Metadata.lookup("mpris:length"); if(time_value == null){ warning("Can't fetch the duration of the track therefore cant set the position"); return; } // work in microseconds (scale up by 10 TTP-of 6) - uint32 total_time = time_value.get_uint() * 1000000; + int64 total_time = time_value.get_int64(); debug("total time of track = %i", (int)total_time); double new_time_position = total_time * (position/100.0); debug("new position = %f", (new_time_position)); - Value? v = this.player.Metadata.lookup("trackid"); + Value? v = this.player.Metadata.lookup("mpris:trackid"); if(v != null){ if(v.holds (typeof (string))){ DBus.ObjectPath path = new ObjectPath(v.get_string()); diff --git a/src/player-item.vala b/src/player-item.vala index e5d8bfc..fab1f85 100644 --- a/src/player-item.vala +++ b/src/player-item.vala @@ -60,7 +60,7 @@ public class PlayerItem : Dbusmenu.Menuitem string update = v.get_string().strip(); debug("with value : %s", update); // Special case for the arturl URI's. - if(property.contains("arturl")){ + if(property.contains("mpris:artUrl")){ try{ update = Filename.from_uri(update.strip()); } @@ -74,9 +74,9 @@ public class PlayerItem : Dbusmenu.Menuitem debug("with value : %i", v.get_int()); this.property_set_int(property, v.get_int()); } - else if (v.holds (typeof (uint))){ - debug("with value : %i", (int)v.get_uint()); - this.property_set_int(property, (int)v.get_uint()); + else if (v.holds (typeof (int64))){ + debug("with value : %i", (int)v.get_int64()); + this.property_set_int(property, (int)v.get_int64()); } else if(v.holds (typeof (bool))){ debug("with value : %s", v.get_boolean().to_string()); diff --git a/src/scrub-menu-item.vala b/src/scrub-menu-item.vala index 7368a0c..d7b60a0 100644 --- a/src/scrub-menu-item.vala +++ b/src/scrub-menu-item.vala @@ -42,7 +42,7 @@ public class ScrubMenuitem : PlayerItem public void update_playstate(int state) { - this.property_set_int(MENUITEM_PLAY_STATE, state); + this.property_set_int(MENUITEM_PLAY_STATE, state); } public static HashSet<string> attributes_format() |