From a964487e2fcd11946b5f95ab36b20cbd1bea4a57 Mon Sep 17 00:00:00 2001 From: Conor Curran Date: Thu, 9 Dec 2010 11:36:33 +0000 Subject: moving towards testing proposed playlists api --- src/Makefile.am | 1 + src/common-defs.h | 3 +++ src/mpris2-controller.vala | 34 ++++++++++++++++++++++++++++---- src/mpris2-interfaces.vala | 24 +++++++++++++++++++++++ src/player-controller.vala | 11 ++++++++--- src/playlists-menu-item.vala | 46 ++++++++++++++++++++++++++++++++++++++++++++ src/sound-service.c | 4 ++-- 7 files changed, 114 insertions(+), 9 deletions(-) create mode 100644 src/playlists-menu-item.vala (limited to 'src') diff --git a/src/Makefile.am b/src/Makefile.am index 1c381f5..214507b 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -64,6 +64,7 @@ music_bridge_VALASOURCES = \ mpris2-watcher.vala \ mpris2-controller.vala \ player-item.vala \ + playlists-menu-item.vala \ familiar-players-db.vala \ fetch-file.vala diff --git a/src/common-defs.h b/src/common-defs.h index 214f60a..8ec69e8 100644 --- a/src/common-defs.h +++ b/src/common-defs.h @@ -49,3 +49,6 @@ with this program. If not, see . #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" +#define DBUSMENU_PLAYLISTS_MENUITEM_TYPE "x-canonical-sound-menu-player-playlists-type" +#define DBUSMENU_PLAYLISTS_MENUITEM_TITLE "x-canonical-sound-menu-player-playlists-title" +#define DBUSMENU_PLAYLISTS_MENUITEM_PLAYLISTS "x-canonical-sound-menu-player-playlists-playlists" \ No newline at end of file diff --git a/src/mpris2-controller.vala b/src/mpris2-controller.vala index 59e3122..2c19606 100644 --- a/src/mpris2-controller.vala +++ b/src/mpris2-controller.vala @@ -21,8 +21,8 @@ using Dbusmenu; [DBus (name = "org.freedesktop.DBus.Properties")] public interface FreeDesktopProperties : Object{ - public signal void PropertiesChanged(string source, HashTable changed_properties, - string[] invalid); + public signal void PropertiesChanged (string source, HashTable changed_properties, + string[] invalid ); } /* @@ -34,13 +34,14 @@ public class Mpris2Controller : GLib.Object public static const string root_interface = "org.mpris.MediaPlayer2" ; public MprisRoot mpris2_root {get; construct;} public MprisPlayer player {get; construct;} + public MprisPlaylists playlists {get; construct;} public FreeDesktopProperties properties_interface {get; construct;} public PlayerController owner {get; construct;} - + public Mpris2Controller(PlayerController ctrl) { - GLib.Object(owner: ctrl); + GLib.Object(owner: ctrl); } construct{ @@ -51,6 +52,9 @@ public class Mpris2Controller : GLib.Object this.player = Bus.get_proxy_sync ( BusType.SESSION, root_interface.concat(".").concat(this.owner.mpris_name), "/org/mpris/MediaPlayer2" ); + this.playlists = Bus.get_proxy_sync ( BusType.SESSION, + root_interface.concat(".").concat(this.owner.mpris_name), + "/org/mpris/MediaPlayer2" ); this.properties_interface = Bus.get_proxy_sync ( BusType.SESSION, "org.freedesktop.Properties.PropertiesChanged", @@ -127,12 +131,14 @@ public class Mpris2Controller : GLib.Object GLib.HashTable? cleaned_metadata = this.clean_metadata(); this.owner.custom_items[PlayerController.widget_order.METADATA].update(cleaned_metadata, MetadataMenuitem.attributes_format()); + this.fetch_playlists(); } public void transport_update(TransportMenuitem.action command) { debug("transport_event input = %i", (int)command); if(command == TransportMenuitem.action.PLAY_PAUSE){ + this.fetch_playlists(); this.player.PlayPause.begin(); } else if(command == TransportMenuitem.action.PREVIOUS){ @@ -143,6 +149,26 @@ public class Mpris2Controller : GLib.Object } } + public void fetch_playlists() + { + if (this.playlists == null){ + warning("Playlists object is null"); + return; + } + PlaylistDetails[] current_playlists = this.playlists.GetPlaylists(0, 10, "Alphabetical", false); + if( current_playlists != null ){ + debug( "Size of the playlist array = %i", current_playlists.length ); + PlaylistsMenuitem playlists_item = this.owner.custom_items[PlayerController.widget_order.PLAYLISTS] as PlaylistsMenuitem; + playlists_item.update(current_playlists); + /*foreach(PlaylistDetails detail in current_playlists){ + debug( "Playlist Name = %s", detail.name); + debug( "Playlist path = %s", detail.path); + debug( "Playlist icon path = %s", detail.icon_path); + debug(" \n \n \n \n \n "); + }*/ + } + } + public bool connected() { return (this.player != null && this.mpris2_root != null); diff --git a/src/mpris2-interfaces.vala b/src/mpris2-interfaces.vala index ebea135..3f5519b 100644 --- a/src/mpris2-interfaces.vala +++ b/src/mpris2-interfaces.vala @@ -44,3 +44,27 @@ public interface MprisPlayer : Object { // signals public signal void Seeked(int64 new_position); } + + +// Playlist container +public struct PlaylistDetails{ + public ObjectPath path; + public string name; + public string icon_path; +} + +[DBus (name = "org.mpris.MediaPlayer2.Playlists")] +// TODO: API criticisms +// get playlists should be able to be async => pass in struct to be populated or pass in callback +public interface MprisPlaylists : Object { + //properties + public abstract string[] Orderings{owned get; set;} + public abstract uint32 PlaylistCount{owned get; set;} + + //methods + public abstract async void ActivatePlaylist(ObjectPath playlist_id) throws IOError; + public abstract PlaylistDetails[] GetPlaylists ( uint32 index, + uint32 max_count, + string order, + bool reverse_order ) throws IOError; +} \ No newline at end of file diff --git a/src/player-controller.vala b/src/player-controller.vala index 0b540f9..b9e275f 100644 --- a/src/player-controller.vala +++ b/src/player-controller.vala @@ -23,13 +23,14 @@ using Gee; public class PlayerController : GLib.Object { - public const int WIDGET_QUANTITY = 4; + public const int WIDGET_QUANTITY = 5; public static enum widget_order{ SEPARATOR, TITLE, METADATA, TRANSPORT, + PLAYLISTS } public enum state{ @@ -158,7 +159,11 @@ public class PlayerController : GLib.Object // Transport item TransportMenuitem transport_item = new TransportMenuitem(this); this.custom_items.add(transport_item); - + + // Playlist item + PlaylistsMenuitem playlist_menuitem = new PlaylistsMenuitem(this); + this.custom_items.add(playlist_menuitem); + foreach(PlayerItem item in this.custom_items){ root_menu.child_add_position(item, this.menu_offset + this.custom_items.index_of(item)); } @@ -184,7 +189,7 @@ public class PlayerController : GLib.Object this.update_state(state.CONNECTED); TitleMenuitem title = this.custom_items[widget_order.TITLE] as TitleMenuitem; title.toggle_active_triangle(true); - this.mpris_bridge.initial_update(); + this.mpris_bridge.initial_update(); } else{ this.update_state(state.DISCONNECTED); diff --git a/src/playlists-menu-item.vala b/src/playlists-menu-item.vala new file mode 100644 index 0000000..8106600 --- /dev/null +++ b/src/playlists-menu-item.vala @@ -0,0 +1,46 @@ +/* +Copyright 2010 Canonical Ltd. + +Authors: + Conor Curran + +This program is free software: you can redistribute it and/or modify it +under the terms of the GNU General Public License version 3, as published +by the Free Software Foundation. + +This program is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranties of +MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR +PURPOSE. See the GNU General Public License for more details. + +You should have received a copy of the GNU General Public License along +with this program. If not, see . +*/ + +using Dbusmenu; +using DbusmenuPlaylists; +using Gee; + +public class PlaylistsMenuitem : PlayerItem +{ + public PlaylistsMenuitem ( PlayerController parent ) + { + Object ( item_type: MENUITEM_TYPE, owner: parent ); + } + + public void update (PlaylistDetails[] playlists) + { + foreach ( PlaylistDetail detail in playlists ){ + + } + } + + public static HashSet attributes_format() + { + HashSet attrs = new HashSet(); + attrs.add(MENUITEM_TITLE); + attrs.add(MENUITEM_PLAYLISTS); + return attrs; + } + +} diff --git a/src/sound-service.c b/src/sound-service.c index 98f1881..defcb94 100644 --- a/src/sound-service.c +++ b/src/sound-service.c @@ -40,8 +40,8 @@ service_shutdown (IndicatorService *service, gpointer user_data) { if (mainloop != NULL) { g_debug("Service shutdown !"); - close_pulse_activites(); - g_main_loop_quit(mainloop); + //close_pulse_activites(); + //g_main_loop_quit(mainloop); } return; } -- cgit v1.2.3 From f3b321919e3390f3d3af2eea33ad71611616ce61 Mon Sep 17 00:00:00 2001 From: Conor Curran Date: Fri, 10 Dec 2010 13:02:16 +0000 Subject: playlist widget population --- src/dbus-menu-manager.c | 1 + src/mpris2-controller.vala | 8 ++++---- src/mpris2-interfaces.vala | 22 +++++++++++++++------- src/player-controller.vala | 20 +++++++++++++++----- src/player-item.vala | 4 ++-- src/playlists-menu-item.vala | 29 +++++++++++++++++++++++++---- 6 files changed, 62 insertions(+), 22 deletions(-) (limited to 'src') diff --git a/src/dbus-menu-manager.c b/src/dbus-menu-manager.c index 37e1c18..f92c324 100644 --- a/src/dbus-menu-manager.c +++ b/src/dbus-menu-manager.c @@ -214,6 +214,7 @@ static void rebuild_sound_menu(DbusmenuMenuitem *root, SoundServiceDbus *service // Sound preferences dialog DbusmenuMenuitem *settings_mi = dbusmenu_menuitem_new(); dbusmenu_menuitem_property_set(settings_mi, DBUSMENU_MENUITEM_PROP_LABEL, _("Sound Preferences...")); + //_("Sound Preferences...")); dbusmenu_menuitem_child_append(root, settings_mi); g_signal_connect(G_OBJECT(settings_mi), DBUSMENU_MENUITEM_SIGNAL_ITEM_ACTIVATED, diff --git a/src/mpris2-controller.vala b/src/mpris2-controller.vala index 2c19606..0bd5562 100644 --- a/src/mpris2-controller.vala +++ b/src/mpris2-controller.vala @@ -138,7 +138,6 @@ public class Mpris2Controller : GLib.Object { debug("transport_event input = %i", (int)command); if(command == TransportMenuitem.action.PLAY_PAUSE){ - this.fetch_playlists(); this.player.PlayPause.begin(); } else if(command == TransportMenuitem.action.PREVIOUS){ @@ -160,12 +159,13 @@ public class Mpris2Controller : GLib.Object debug( "Size of the playlist array = %i", current_playlists.length ); PlaylistsMenuitem playlists_item = this.owner.custom_items[PlayerController.widget_order.PLAYLISTS] as PlaylistsMenuitem; playlists_item.update(current_playlists); - /*foreach(PlaylistDetails detail in current_playlists){ + foreach(PlaylistDetails detail in current_playlists){ + debug(" \n \n "); debug( "Playlist Name = %s", detail.name); debug( "Playlist path = %s", detail.path); debug( "Playlist icon path = %s", detail.icon_path); - debug(" \n \n \n \n \n "); - }*/ + debug(" \n \n "); + } } } diff --git a/src/mpris2-interfaces.vala b/src/mpris2-interfaces.vala index 3f5519b..ab8ac95 100644 --- a/src/mpris2-interfaces.vala +++ b/src/mpris2-interfaces.vala @@ -1,6 +1,5 @@ /* Copyright 2010 Canonical Ltd. - Authors: Conor Curran @@ -45,7 +44,6 @@ public interface MprisPlayer : Object { public signal void Seeked(int64 new_position); } - // Playlist container public struct PlaylistDetails{ public ObjectPath path; @@ -54,8 +52,18 @@ public struct PlaylistDetails{ } [DBus (name = "org.mpris.MediaPlayer2.Playlists")] + // TODO: API criticisms -// get playlists should be able to be async => pass in struct to be populated or pass in callback +// Get_playlists should be able to be async => pass in callback pointer +// Lacking the ability to query the current playlist (should be asyncable) +// - needed to keep client and servers in sync +// => get_current_playlist -> +// Should return PlaylistDetails struct with each field nil if there is no active playlist. +// Otherwise a populated PlaylistDetails +// should be asyncable. +// => Need to be able to query get_playlist using ordered by last modified. +// => Need a signal to inform that the active playlist has changed + public interface MprisPlaylists : Object { //properties public abstract string[] Orderings{owned get; set;} @@ -63,8 +71,8 @@ public interface MprisPlaylists : Object { //methods public abstract async void ActivatePlaylist(ObjectPath playlist_id) throws IOError; - public abstract PlaylistDetails[] GetPlaylists ( uint32 index, - uint32 max_count, - string order, - bool reverse_order ) throws IOError; + public abstract PlaylistDetails[] GetPlaylists ( uint32 index, + uint32 max_count, + string order, + bool reverse_order ) throws IOError; } \ No newline at end of file diff --git a/src/player-controller.vala b/src/player-controller.vala index b9e275f..450ecd6 100644 --- a/src/player-controller.vala +++ b/src/player-controller.vala @@ -141,6 +141,10 @@ public class PlayerController : GLib.Object this.custom_items[widget_order.METADATA].populated(MetadataMenuitem.attributes_format())); this.custom_items[widget_order.TRANSPORT].property_set_bool(MENUITEM_PROP_VISIBLE, true); + this.custom_items[widget_order.PLAYLISTS].property_set_bool(MENUITEM_PROP_VISIBLE, + true); + this.custom_items[widget_order.PLAYLISTS].property_set_bool ( MENUITEM_PROP_ENABLED, + true ); } private void construct_widgets() @@ -160,12 +164,18 @@ public class PlayerController : GLib.Object TransportMenuitem transport_item = new TransportMenuitem(this); this.custom_items.add(transport_item); - // Playlist item + // Playlist item PlaylistsMenuitem playlist_menuitem = new PlaylistsMenuitem(this); this.custom_items.add(playlist_menuitem); foreach(PlayerItem item in this.custom_items){ - root_menu.child_add_position(item, this.menu_offset + this.custom_items.index_of(item)); + if (this.custom_items.index_of(item) != 4) { + root_menu.child_add_position(item, this.menu_offset + this.custom_items.index_of(item)); + } + else{ + PlaylistsMenuitem playlists_menuitem = item as PlaylistsMenuitem; + root_menu.child_add_position(playlists_menuitem.root_item, this.menu_offset + this.custom_items.index_of(item)); + } } } @@ -188,11 +198,11 @@ public class PlayerController : GLib.Object if(this.mpris_bridge.connected() == true){ this.update_state(state.CONNECTED); TitleMenuitem title = this.custom_items[widget_order.TITLE] as TitleMenuitem; - title.toggle_active_triangle(true); - this.mpris_bridge.initial_update(); + title.toggle_active_triangle(true); + this.mpris_bridge.initial_update(); } else{ this.update_state(state.DISCONNECTED); } - } + } } diff --git a/src/player-item.vala b/src/player-item.vala index c80a17d..75f673b 100644 --- a/src/player-item.vala +++ b/src/player-item.vala @@ -28,7 +28,7 @@ public class PlayerItem : Dbusmenu.Menuitem public PlayerItem(string type) { - Object(item_type: type); + Object(item_type: type); } construct { @@ -54,7 +54,7 @@ public class PlayerItem : Dbusmenu.Menuitem if(data == null){ debug("PlayerItem::Update -> The hashtable was null - just leave it!"); return; - } + } foreach(string property in attributes){ string[] input_keys = property.split("-"); diff --git a/src/playlists-menu-item.vala b/src/playlists-menu-item.vala index 8106600..4b81e48 100644 --- a/src/playlists-menu-item.vala +++ b/src/playlists-menu-item.vala @@ -23,18 +23,39 @@ using Gee; public class PlaylistsMenuitem : PlayerItem { + + public Menuitem root_item; public PlaylistsMenuitem ( PlayerController parent ) { Object ( item_type: MENUITEM_TYPE, owner: parent ); } + construct{ + this.property_set ( MENUITEM_PROP_LABEL, "Choose Playlist"); + this.root_item = new Menuitem(); + this.root_item.property_set ( MENUITEM_PROP_LABEL, "Choose Playlist" ); + } - public void update (PlaylistDetails[] playlists) + public new void update (PlaylistDetails[] playlists) { - foreach ( PlaylistDetail detail in playlists ){ - + foreach ( PlaylistDetails detail in playlists ){ + Dbusmenu.Menuitem menuitem = new Menuitem(); + menuitem.property_set (MENUITEM_PROP_LABEL, detail.name); + menuitem.property_set (MENUITEM_PROP_ICON_NAME, "source-smart-playlist"); + menuitem.property_set_bool (MENUITEM_PROP_VISIBLE, true); + menuitem.property_set_bool (MENUITEM_PROP_ENABLED, true); + + menuitem.item_activated.connect(() => { + submenu_item_activated (menuitem.id );}); + + this.root_item.child_append( menuitem ); } } - + + private void submenu_item_activated (int menu_item_id) + { + debug("item %i was activated", menu_item_id); + } + public static HashSet attributes_format() { HashSet attrs = new HashSet(); -- cgit v1.2.3 From 93190886959bfa16b835794a4a12a9a945e7777e Mon Sep 17 00:00:00 2001 From: Conor Curran Date: Fri, 10 Dec 2010 15:36:44 +0000 Subject: proposed extension proven and observations gathered --- src/mpris2-controller.vala | 14 ++++++++++++++ src/mpris2-interfaces.vala | 2 -- src/playlists-menu-item.vala | 14 +++++++++----- 3 files changed, 23 insertions(+), 7 deletions(-) (limited to 'src') diff --git a/src/mpris2-controller.vala b/src/mpris2-controller.vala index 0bd5562..94e82d5 100644 --- a/src/mpris2-controller.vala +++ b/src/mpris2-controller.vala @@ -180,4 +180,18 @@ public class Mpris2Controller : GLib.Object this.mpris2_root.Raise.begin(); } } + + public void activate_playlist (ObjectPath path) + { + if(this.playlists == null){ + warning("playlists mpris instance is null !"); + return; + } + try{ + this.playlists.ActivatePlaylist.begin(path); + } + catch(IOError e){ + debug("Could not activate playlist %s because %s", (string)path, e.message); + } + } } \ No newline at end of file diff --git a/src/mpris2-interfaces.vala b/src/mpris2-interfaces.vala index ab8ac95..160f454 100644 --- a/src/mpris2-interfaces.vala +++ b/src/mpris2-interfaces.vala @@ -55,8 +55,6 @@ public struct PlaylistDetails{ // TODO: API criticisms // Get_playlists should be able to be async => pass in callback pointer -// Lacking the ability to query the current playlist (should be asyncable) -// - needed to keep client and servers in sync // => get_current_playlist -> // Should return PlaylistDetails struct with each field nil if there is no active playlist. // Otherwise a populated PlaylistDetails diff --git a/src/playlists-menu-item.vala b/src/playlists-menu-item.vala index 4b81e48..f9d681e 100644 --- a/src/playlists-menu-item.vala +++ b/src/playlists-menu-item.vala @@ -23,14 +23,14 @@ using Gee; public class PlaylistsMenuitem : PlayerItem { - + private HashMap current_playlists; public Menuitem root_item; public PlaylistsMenuitem ( PlayerController parent ) { Object ( item_type: MENUITEM_TYPE, owner: parent ); } construct{ - this.property_set ( MENUITEM_PROP_LABEL, "Choose Playlist"); + this.current_playlists = new HashMap(); this.root_item = new Menuitem(); this.root_item.property_set ( MENUITEM_PROP_LABEL, "Choose Playlist" ); } @@ -43,17 +43,21 @@ public class PlaylistsMenuitem : PlayerItem menuitem.property_set (MENUITEM_PROP_ICON_NAME, "source-smart-playlist"); menuitem.property_set_bool (MENUITEM_PROP_VISIBLE, true); menuitem.property_set_bool (MENUITEM_PROP_ENABLED, true); - + this.current_playlists.set( menuitem.id, detail ); menuitem.item_activated.connect(() => { submenu_item_activated (menuitem.id );}); - this.root_item.child_append( menuitem ); } } private void submenu_item_activated (int menu_item_id) { - debug("item %i was activated", menu_item_id); + if(!this.current_playlists.has_key(menu_item_id)){ + warning( "item %i was activated but we don't have a corresponding playlist", + menu_item_id ); + return; + } + this.owner.mpris_bridge.activate_playlist ( this.current_playlists[menu_item_id].path ); } public static HashSet attributes_format() -- cgit v1.2.3 From 032797fd7a92bc8a4fd979ddc12cacb0918ca73b Mon Sep 17 00:00:00 2001 From: Conor Curran Date: Fri, 17 Dec 2010 12:48:03 +0000 Subject: proved active-playlist prop use-case --- src/mpris2-controller.vala | 26 +++++++++++++++++++++++--- src/mpris2-interfaces.vala | 18 +++++++----------- 2 files changed, 30 insertions(+), 14 deletions(-) (limited to 'src') diff --git a/src/mpris2-controller.vala b/src/mpris2-controller.vala index 94e82d5..d6f27ec 100644 --- a/src/mpris2-controller.vala +++ b/src/mpris2-controller.vala @@ -18,9 +18,8 @@ with this program. If not, see . */ using Dbusmenu; - [DBus (name = "org.freedesktop.DBus.Properties")] - public interface FreeDesktopProperties : Object{ +public interface FreeDesktopProperties : Object{ public signal void PropertiesChanged (string source, HashTable changed_properties, string[] invalid ); } @@ -91,6 +90,11 @@ public class Mpris2Controller : GLib.Object metadata.property_set_bool ( MENUITEM_PROP_VISIBLE, metadata.populated(MetadataMenuitem.attributes_format())); } + Variant? playlist_v = changed_properties.lookup("ActivePlaylist"); + if ( playlist_v != null ){ + debug (" WE HAVE PLAYLIST CHANGE EVENT DETECTED "); + this.fetch_active_playlist(); + } } private GLib.HashTable? clean_metadata() @@ -131,7 +135,7 @@ public class Mpris2Controller : GLib.Object GLib.HashTable? cleaned_metadata = this.clean_metadata(); this.owner.custom_items[PlayerController.widget_order.METADATA].update(cleaned_metadata, MetadataMenuitem.attributes_format()); - this.fetch_playlists(); + this.fetch_playlists(); } public void transport_update(TransportMenuitem.action command) @@ -169,6 +173,22 @@ public class Mpris2Controller : GLib.Object } } + public void fetch_active_playlist() + { + if (this.playlists == null && this.playlists.ActivePlaylist.valid == true){ + warning("Playlists object is null and we have an active playlist"); + return; + } + + PlaylistDetails active_details = this.playlists.ActivePlaylist.active_playlist; + debug(" \n \n "); + debug( "Active Playlist Name = %s", active_details.name); + debug( "Active Playlist path = %s", active_details.path); + debug( "Active Playlist icon path = %s", active_details.icon_path); + debug(" \n \n "); + } + + public bool connected() { return (this.player != null && this.mpris2_root != null); diff --git a/src/mpris2-interfaces.vala b/src/mpris2-interfaces.vala index 160f454..578b6c8 100644 --- a/src/mpris2-interfaces.vala +++ b/src/mpris2-interfaces.vala @@ -50,23 +50,19 @@ public struct PlaylistDetails{ public string name; public string icon_path; } +// Active playlist property container +public struct ActivePlaylistContainer{ + public bool valid; + public PlaylistDetails active_playlist; +} [DBus (name = "org.mpris.MediaPlayer2.Playlists")] - -// TODO: API criticisms -// Get_playlists should be able to be async => pass in callback pointer -// => get_current_playlist -> -// Should return PlaylistDetails struct with each field nil if there is no active playlist. -// Otherwise a populated PlaylistDetails -// should be asyncable. -// => Need to be able to query get_playlist using ordered by last modified. -// => Need a signal to inform that the active playlist has changed - public interface MprisPlaylists : Object { //properties public abstract string[] Orderings{owned get; set;} public abstract uint32 PlaylistCount{owned get; set;} - + public abstract ActivePlaylistContainer ActivePlaylist {owned get; set;} + //methods public abstract async void ActivatePlaylist(ObjectPath playlist_id) throws IOError; public abstract PlaylistDetails[] GetPlaylists ( uint32 index, -- cgit v1.2.3 From bc927c2284c55ca8a30146ae905a76aa08f26fa1 Mon Sep 17 00:00:00 2001 From: Conor Curran Date: Mon, 20 Dec 2010 16:55:31 +0000 Subject: implemented suggested optional playlist mechanism --- src/mpris2-controller.vala | 7 ++++--- src/mpris2-interfaces.vala | 2 -- src/player-item.vala | 2 +- 3 files changed, 5 insertions(+), 6 deletions(-) (limited to 'src') diff --git a/src/mpris2-controller.vala b/src/mpris2-controller.vala index 58a1906..4990b38 100644 --- a/src/mpris2-controller.vala +++ b/src/mpris2-controller.vala @@ -102,9 +102,10 @@ public class Mpris2Controller : GLib.Object public bool playlist_support() { - // awaiting spec updates - // return this.mpris2_root.HasPlaylists; - return true; + if (this.playlists == null) return false; + uint32? count = this.playlists.PlaylistCount; + if ( count == null || count <= 0 ) return false; + return true; } private bool ensure_correct_playback_status(){ diff --git a/src/mpris2-interfaces.vala b/src/mpris2-interfaces.vala index 4f01c4c..a731de8 100644 --- a/src/mpris2-interfaces.vala +++ b/src/mpris2-interfaces.vala @@ -21,8 +21,6 @@ with this program. If not, see . public interface MprisRoot : Object { // properties public abstract bool HasTracklist{owned get; set;} - //waiting for MPRIS approval - //public abstract bool HasPlaylist{owned get; set;} public abstract bool CanQuit{owned get; set;} public abstract bool CanRaise{owned get; set;} public abstract string Identity{owned get; set;} diff --git a/src/player-item.vala b/src/player-item.vala index 75f673b..f883a1e 100644 --- a/src/player-item.vala +++ b/src/player-item.vala @@ -28,7 +28,7 @@ public class PlayerItem : Dbusmenu.Menuitem public PlayerItem(string type) { - Object(item_type: type); + Object(item_type: type); } construct { -- cgit v1.2.3 From c8c7681e7b9e2995d29fa58c931aa09e451c4fee Mon Sep 17 00:00:00 2001 From: Conor Curran Date: Mon, 20 Dec 2010 18:02:50 +0000 Subject: playlists working --- src/mpris2-controller.vala | 2 +- src/mpris2-interfaces.vala | 1 + src/player-controller.vala | 10 ++++++---- 3 files changed, 8 insertions(+), 5 deletions(-) (limited to 'src') diff --git a/src/mpris2-controller.vala b/src/mpris2-controller.vala index 4990b38..35dc4e4 100644 --- a/src/mpris2-controller.vala +++ b/src/mpris2-controller.vala @@ -100,7 +100,7 @@ public class Mpris2Controller : GLib.Object } } - public bool playlist_support() + public bool playlists_support_exist() { if (this.playlists == null) return false; uint32? count = this.playlists.PlaylistCount; diff --git a/src/mpris2-interfaces.vala b/src/mpris2-interfaces.vala index a731de8..88610e6 100644 --- a/src/mpris2-interfaces.vala +++ b/src/mpris2-interfaces.vala @@ -50,6 +50,7 @@ public struct PlaylistDetails{ public string name; public string icon_path; } + // Active playlist property container public struct ActivePlaylistContainer{ public bool valid; diff --git a/src/player-controller.vala b/src/player-controller.vala index 24fd090..638c44d 100644 --- a/src/player-controller.vala +++ b/src/player-controller.vala @@ -131,21 +131,23 @@ public class PlayerController : GLib.Object public void update_layout() { + PlaylistsMenuitem playlists_menuitem = this.custom_items[widget_order.PLAYLISTS] as PlaylistsMenuitem; + if(this.current_state != state.CONNECTED){ this.custom_items[widget_order.TRANSPORT].property_set_bool(MENUITEM_PROP_VISIBLE, false); this.custom_items[widget_order.METADATA].property_set_bool(MENUITEM_PROP_VISIBLE, false); - this.custom_items[widget_order.PLAYLISTS].property_set_bool ( MENUITEM_PROP_ENABLED, - false ); + playlists_menuitem.root_item.property_set_bool ( MENUITEM_PROP_VISIBLE, + false ); return; } this.custom_items[widget_order.METADATA].property_set_bool(MENUITEM_PROP_VISIBLE, this.custom_items[widget_order.METADATA].populated(MetadataMenuitem.attributes_format())); this.custom_items[widget_order.TRANSPORT].property_set_bool(MENUITEM_PROP_VISIBLE, true); - this.custom_items[widget_order.PLAYLISTS].property_set_bool(MENUITEM_PROP_VISIBLE, - true); + playlists_menuitem.root_item.property_set_bool ( MENUITEM_PROP_VISIBLE, + this.mpris_bridge.playlists_support_exist() ); } private void construct_widgets() -- cgit v1.2.3 From 4843ae15f1ce4111c03b0fc24f5a8989d0619697 Mon Sep 17 00:00:00 2001 From: Conor Curran Date: Tue, 21 Dec 2010 14:53:56 +0000 Subject: playlists ready to go into trunk --- src/mpris2-controller.vala | 27 +++++++-------------------- src/music-player-bridge.vala | 2 +- src/playlists-menu-item.vala | 13 ++++++++++++- src/sound-service.c | 4 ++-- 4 files changed, 22 insertions(+), 24 deletions(-) (limited to 'src') diff --git a/src/mpris2-controller.vala b/src/mpris2-controller.vala index 35dc4e4..5f98541 100644 --- a/src/mpris2-controller.vala +++ b/src/mpris2-controller.vala @@ -97,6 +97,7 @@ public class Mpris2Controller : GLib.Object Variant? playlist_v = changed_properties.lookup("ActivePlaylist"); if ( playlist_v != null ){ this.fetch_active_playlist(); + //Timeout.add ( 200, fetch_active_playlist ); } } @@ -154,6 +155,7 @@ public class Mpris2Controller : GLib.Object this.owner.custom_items[PlayerController.widget_order.METADATA].update(cleaned_metadata, MetadataMenuitem.attributes_format()); this.fetch_playlists(); + this.fetch_active_playlist(); } public void transport_update(TransportMenuitem.action command) @@ -172,10 +174,8 @@ public class Mpris2Controller : GLib.Object public void fetch_playlists() { - if (this.playlists == null){ - warning("Playlists object is null"); - return; - } + if (this.playlists == null) return; + PlaylistDetails[] current_playlists = this.playlists.GetPlaylists(0, 10, "Alphabetical", @@ -184,30 +184,17 @@ public class Mpris2Controller : GLib.Object debug( "Size of the playlist array = %i", current_playlists.length ); PlaylistsMenuitem playlists_item = this.owner.custom_items[PlayerController.widget_order.PLAYLISTS] as PlaylistsMenuitem; playlists_item.update(current_playlists); - /*foreach(PlaylistDetails detail in current_playlists){ - debug(" \n \n "); - debug( "Playlist Name = %s", detail.name); - debug( "Playlist path = %s", detail.path); - debug( "Playlist icon path = %s", detail.icon_path); - debug(" \n \n "); - }*/ } + return; } - public void fetch_active_playlist() + private void fetch_active_playlist() { - if (this.playlists == null && this.playlists.ActivePlaylist.valid == true){ + if (this.playlists == null && this.playlists.ActivePlaylist.valid == false){ warning("Playlists object is null or we don't have an active playlist"); - return; } PlaylistsMenuitem playlists_item = this.owner.custom_items[PlayerController.widget_order.PLAYLISTS] as PlaylistsMenuitem; playlists_item.update_active_playlist ( this.playlists.ActivePlaylist.details ); - /*debug(" \n \n "); - debug( "Active Playlist Name = %s", active_details.name); - debug( "Active Playlist path = %s", active_details.path); - debug( "Active Playlist icon path = %s", active_details.icon_path); - debug(" \n \n "); - */ } diff --git a/src/music-player-bridge.vala b/src/music-player-bridge.vala index 239a40b..de8609d 100644 --- a/src/music-player-bridge.vala +++ b/src/music-player-bridge.vala @@ -76,7 +76,7 @@ public class MusicPlayerBridge : GLib.Object } } - public void client_has_become_available ( string desktop, string dbus_name ) + public void client_has_become_available ( string desktop, string dbus_name ) { if (desktop == null || desktop == ""){ warning("Client %s attempting to register without desktop entry being set on the mpris root", diff --git a/src/playlists-menu-item.vala b/src/playlists-menu-item.vala index 30ffdc7..024839c 100644 --- a/src/playlists-menu-item.vala +++ b/src/playlists-menu-item.vala @@ -38,6 +38,7 @@ public class PlaylistsMenuitem : PlayerItem public new void update (PlaylistDetails[] playlists) { foreach ( PlaylistDetails detail in playlists ){ + if (this.already_observed(detail)) continue; Dbusmenu.Menuitem menuitem = new Menuitem(); menuitem.property_set (MENUITEM_PROP_LABEL, detail.name); menuitem.property_set (MENUITEM_PROP_ICON_NAME, "source-smart-playlist"); @@ -50,9 +51,19 @@ public class PlaylistsMenuitem : PlayerItem } } + private bool already_observed (PlaylistDetails new_detail) + { + foreach ( PlaylistDetails detail in this.current_playlists.values ){ + if (new_detail.path == detail.path) return true; + } + return false; + } + public void update_active_playlist(PlaylistDetails detail) { - this.root_item.property_set ( MENUITEM_PROP_LABEL, detail.name ); + var update = detail.name; + if ( update == "" ) update = "Choose Playlist"; + this.root_item.property_set ( MENUITEM_PROP_LABEL, update ); } private void submenu_item_activated (int menu_item_id) diff --git a/src/sound-service.c b/src/sound-service.c index defcb94..98f1881 100644 --- a/src/sound-service.c +++ b/src/sound-service.c @@ -40,8 +40,8 @@ service_shutdown (IndicatorService *service, gpointer user_data) { if (mainloop != NULL) { g_debug("Service shutdown !"); - //close_pulse_activites(); - //g_main_loop_quit(mainloop); + close_pulse_activites(); + g_main_loop_quit(mainloop); } return; } -- cgit v1.2.3