From 4d9c1fa538254e065a1607de9e16dba126b55dd5 Mon Sep 17 00:00:00 2001 From: Conor Curran Date: Wed, 1 Dec 2010 20:20:00 +0000 Subject: dbus-glib removed from vala deps, initial gdbus port underway --- src/Makefile.am | 3 +- src/mpris2-controller.vala | 73 ++++++++++++++++++++++---------------------- src/music-player-bridge.vala | 12 +++----- src/player-controller.vala | 3 -- 4 files changed, 42 insertions(+), 49 deletions(-) diff --git a/src/Makefile.am b/src/Makefile.am index b23e9c1..1362187 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -74,10 +74,9 @@ music_bridge_VALAFLAGS = \ --vapidir=./ \ --thread \ --pkg gee-1.0 \ - --pkg Indicate-0.2 \ --pkg Dbusmenu-Glib-0.2 \ --pkg common-defs \ - --pkg dbus-glib-1 \ + --pkg gio-2.0 \ --pkg gio-unix-2.0 \ --pkg gdk-pixbuf-2.0 diff --git a/src/mpris2-controller.vala b/src/mpris2-controller.vala index f440c13..0be018a 100644 --- a/src/mpris2-controller.vala +++ b/src/mpris2-controller.vala @@ -16,11 +16,11 @@ 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 DBus; +//using DBus; using Dbusmenu; [DBus (name = "org.mpris.MediaPlayer2")] -public interface MprisRoot : DBus.Object { +public interface MprisRoot : Object { // properties public abstract bool HasTracklist{owned get; set;} public abstract bool CanQuit{owned get; set;} @@ -28,11 +28,11 @@ public interface MprisRoot : DBus.Object { public abstract string Identity{owned get; set;} public abstract string DesktopEntry{owned get; set;} // methods - public abstract async void Quit() throws DBus.Error; - public abstract async void Raise() throws DBus.Error; + public abstract async void Quit() throws IOError; + public abstract async void Raise() throws IOError; } -[DBus (name = "org.mpris.MediaPlayer2.Player")] +/*[DBus (name = "org.mpris.MediaPlayer2.Player")] public interface MprisPlayer : DBus.Object { // properties @@ -54,7 +54,7 @@ public interface FreeDesktopProperties : DBus.Object{ Value?> changed_properties, string[] invalid); } - +*/ /* This class will entirely replace mpris-controller.vala hence why there is no point in trying to get encorporate both into the same object model. @@ -63,9 +63,10 @@ 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 PlayerController owner {get; construct;} - public FreeDesktopProperties properties_interface {get; construct;} + /*public MprisPlayer player {get; construct;} + public FreeDesktopProperties properties_interface {get; construct;}*/ + + public PlayerController owner {get; construct;} public Mpris2Controller(PlayerController ctrl) { @@ -74,23 +75,22 @@ public class Mpris2Controller : GLib.Object construct{ try { - var connection = DBus.Bus.get (DBus.BusType.SESSION); - this.mpris2_root = (MprisRoot) connection.get_object (root_interface.concat(".").concat(this.owner.mpris_name), - "/org/mpris/MediaPlayer2", - root_interface); - this.player = (MprisPlayer) connection.get_object (root_interface.concat(".").concat(this.owner.mpris_name), + + this.mpris2_root = Bus.get_proxy_sync (BusType.SESSION, root_interface.concat(".").concat(this.owner.mpris_name), + "/org/mpris/MediaPlayer2"); + /*this.player = (MprisPlayer) connection.get_object (root_interface.concat(".").concat(this.owner.mpris_name), "/org/mpris/MediaPlayer2", root_interface.concat(".Player")); this.properties_interface = (FreeDesktopProperties) connection.get_object("org.freedesktop.Properties.PropertiesChanged", "/org/mpris/MediaPlayer2"); - this.properties_interface.PropertiesChanged += property_changed_cb; + this.properties_interface.PropertiesChanged += property_changed_cb;*/ - } catch (DBus.Error e) { + } catch (IOError e) { error("Problems connecting to the session bus - %s", e.message); } } - public void property_changed_cb(string interface_source, HashTable changed_properties, string[] invalid ) + /*public void property_changed_cb(string interface_source, HashTable changed_properties, string[] invalid ) { debug("properties-changed for interface %s and owner %s", interface_source, this.owner.mpris_name); @@ -115,11 +115,11 @@ public class Mpris2Controller : GLib.Object metadata.property_set_bool(MENUITEM_PROP_VISIBLE, metadata.populated(MetadataMenuitem.attributes_format())); } - } + }*/ - private GLib.HashTable clean_metadata() + private GLib.HashTable? clean_metadata() { - GLib.HashTable changed_updates = this.player.Metadata; + /*GLib.HashTable changed_updates = this.player.Metadata; Value? artist_v = this.player.Metadata.lookup("xesam:artist"); if(artist_v != null){ string[] artists = (string[])this.player.Metadata.lookup("xesam:artist"); @@ -133,9 +133,11 @@ public class Mpris2Controller : GLib.Object changed_updates.replace("mpris:length", duration/1000000); } return changed_updates; + */ + return null; } - private TransportMenuitem.state determine_play_state(string status){ + private TransportMenuitem.state determine_play_state(string? status){ if(status != null && status == "Playing"){ return TransportMenuitem.state.PLAYING; } @@ -145,22 +147,22 @@ public class Mpris2Controller : GLib.Object public void initial_update() { TransportMenuitem.state update; - if(this.player.PlaybackStatus == null){ + /*if(this.player.PlaybackStatus == null){ update = TransportMenuitem.state.PAUSED; - } - else{ - update = determine_play_state(this.player.PlaybackStatus); - } - (this.owner.custom_items[PlayerController.widget_order.TRANSPORT] as TransportMenuitem).change_play_state(update); - GLib.HashTable cleaned_metadata = this.clean_metadata(); - this.owner.custom_items[PlayerController.widget_order.METADATA].update(cleaned_metadata, - MetadataMenuitem.attributes_format()); + }*/ + + update = determine_play_state(null); + + (this.owner.custom_items[PlayerController.widget_order.TRANSPORT] as TransportMenuitem).change_play_state(TransportMenuitem.state.PAUSED); + GLib.HashTable? cleaned_metadata = this.clean_metadata(); + //this.owner.custom_items[PlayerController.widget_order.METADATA].update(cleaned_metadata, + // MetadataMenuitem.attributes_format()); } public void transport_update(TransportMenuitem.action command) { debug("transport_event input = %i", (int)command); - if(command == TransportMenuitem.action.PLAY_PAUSE){ + /*if(command == TransportMenuitem.action.PLAY_PAUSE){ this.player.PlayPause.begin(); } else if(command == TransportMenuitem.action.PREVIOUS){ @@ -168,26 +170,23 @@ public class Mpris2Controller : GLib.Object } else if(command == TransportMenuitem.action.NEXT){ this.player.Next.begin(); - } + }*/ } public bool connected() { - return (this.player != null && this.mpris2_root != null); + return false; } public bool was_successfull(){ - if(this.mpris2_root == null || this.player == null){ return false; - } - return true; } public void expose() { if(this.connected() == true){ - this.mpris2_root.Raise.begin(); + //this.mpris2_root.Raise.begin(); } } } diff --git a/src/music-player-bridge.vala b/src/music-player-bridge.vala index f13c2f4..3fc7efa 100644 --- a/src/music-player-bridge.vala +++ b/src/music-player-bridge.vala @@ -17,14 +17,12 @@ You should have received a copy of the GNU General Public License along with this program. If not, see . */ -using Indicate; using Dbusmenu; using Gee; using GLib; public class MusicPlayerBridge : GLib.Object { - private Listener listener; private Dbusmenu.Menuitem root_menu; private HashMap registered_clients; private FamiliarPlayersDB playersDB; @@ -33,9 +31,6 @@ public class MusicPlayerBridge : GLib.Object { playersDB = new FamiliarPlayersDB(); registered_clients = new HashMap (); - listener = Listener.ref_default(); - listener.server_added.connect(on_server_added); - listener.server_removed.connect(on_server_removed); } private void try_to_add_inactive_familiar_clients(){ @@ -76,7 +71,7 @@ public class MusicPlayerBridge : GLib.Object } } - public void on_server_added(Indicate.ListenerServer object, string type) + /*public void on_server_added(Indicate.ListenerServer object, string type) { debug("MusicPlayerBridge -> on_server_added with value %s", type); if(server_is_not_of_interest(type)) return; @@ -139,7 +134,7 @@ public class MusicPlayerBridge : GLib.Object return true; } return false; - } + }*/ public void set_root_menu_item(Dbusmenu.Menuitem menu) { @@ -158,6 +153,9 @@ public class MusicPlayerBridge : GLib.Object return app_info; } + /** + TODO: clean up + **/ private static string? determine_key(owned string path) { var tokens = path.split("/"); diff --git a/src/player-controller.vala b/src/player-controller.vala index e2ae4d7..46add60 100644 --- a/src/player-controller.vala +++ b/src/player-controller.vala @@ -178,9 +178,6 @@ public class PlayerController : GLib.Object return result; } - // Temporarily we will need to handle to different mpris implemenations - // Do it for now - a couple of weeks should see this messy carry on out of - // the codebase. public void determine_state() { if(this.mpris_bridge.connected() == true){ -- cgit v1.2.3 From b28241622081791ec4589d83a53078c768d4dea2 Mon Sep 17 00:00:00 2001 From: Conor Curran Date: Thu, 2 Dec 2010 19:35:49 +0000 Subject: moving in the right direction, registration happening on dbus watching --- src/Makefile.am | 2 ++ src/mpris2-controller.vala | 54 ++++++++----------------------- src/mpris2-interfaces.vala | 46 +++++++++++++++++++++++++++ src/mpris2-watcher.vala | 76 ++++++++++++++++++++++++++++++++++++++++++++ src/music-player-bridge.vala | 74 +++++++++++++++++------------------------- src/player-controller.vala | 2 +- src/sound-service.c | 4 +-- 7 files changed, 171 insertions(+), 87 deletions(-) create mode 100644 src/mpris2-interfaces.vala create mode 100644 src/mpris2-watcher.vala diff --git a/src/Makefile.am b/src/Makefile.am index 1362187..1c381f5 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -60,6 +60,8 @@ music_bridge_VALASOURCES = \ metadata-menu-item.vala \ title-menu-item.vala \ player-controller.vala \ + mpris2-interfaces.vala \ + mpris2-watcher.vala \ mpris2-controller.vala \ player-item.vala \ familiar-players-db.vala \ diff --git a/src/mpris2-controller.vala b/src/mpris2-controller.vala index 0be018a..c382e97 100644 --- a/src/mpris2-controller.vala +++ b/src/mpris2-controller.vala @@ -19,42 +19,15 @@ with this program. If not, see . //using DBus; using Dbusmenu; -[DBus (name = "org.mpris.MediaPlayer2")] -public interface MprisRoot : Object { - // properties - public abstract bool HasTracklist{owned get; set;} - public abstract bool CanQuit{owned get; set;} - public abstract bool CanRaise{owned get; set;} - public abstract string Identity{owned get; set;} - public abstract string DesktopEntry{owned get; set;} - // methods - public abstract async void Quit() throws IOError; - public abstract async void Raise() throws IOError; -} - -/*[DBus (name = "org.mpris.MediaPlayer2.Player")] -public interface MprisPlayer : DBus.Object { - - // properties - public abstract HashTable Metadata{owned get; set;} - public abstract int32 Position{owned get; set;} - public abstract string PlaybackStatus{owned get; set;} - // methods - public abstract async void PlayPause() throws DBus.Error; - public abstract async void Next() throws DBus.Error; - public abstract async void Previous() throws DBus.Error; - // signals - public signal void Seeked(int64 new_position); -} -[DBus (name = "org.freedesktop.DBus.Properties")] -public interface FreeDesktopProperties : DBus.Object{ +/*[DBus (name = "org.freedesktop.DBus.Properties")] + public interface FreeDesktopProperties : DBus.Object{ // signals public signal void PropertiesChanged(string source, HashTable changed_properties, string[] invalid); } -*/ + /* This class will entirely replace mpris-controller.vala hence why there is no point in trying to get encorporate both into the same object model. @@ -63,8 +36,8 @@ 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 FreeDesktopProperties properties_interface {get; construct;}*/ + public MprisPlayer player {get; construct;} + //public FreeDesktopProperties properties_interface {get; construct;} public PlayerController owner {get; construct;} @@ -75,12 +48,13 @@ public class Mpris2Controller : GLib.Object construct{ try { - - this.mpris2_root = Bus.get_proxy_sync (BusType.SESSION, root_interface.concat(".").concat(this.owner.mpris_name), - "/org/mpris/MediaPlayer2"); - /*this.player = (MprisPlayer) connection.get_object (root_interface.concat(".").concat(this.owner.mpris_name), - "/org/mpris/MediaPlayer2", - root_interface.concat(".Player")); + this.mpris2_root = Bus.get_proxy_sync ( BusType.SESSION, + root_interface.concat(".").concat(this.owner.mpris_name), + "/org/mpris/MediaPlayer2"); + this.player = Bus.get_proxy_sync ( BusType.SESSION, + root_interface.concat(".").concat(this.owner.mpris_name), + "/org/mpris/MediaPlayer2" ); + /* this.properties_interface = (FreeDesktopProperties) connection.get_object("org.freedesktop.Properties.PropertiesChanged", "/org/mpris/MediaPlayer2"); this.properties_interface.PropertiesChanged += property_changed_cb;*/ @@ -162,7 +136,7 @@ public class Mpris2Controller : GLib.Object public void transport_update(TransportMenuitem.action command) { debug("transport_event input = %i", (int)command); - /*if(command == TransportMenuitem.action.PLAY_PAUSE){ + if(command == TransportMenuitem.action.PLAY_PAUSE){ this.player.PlayPause.begin(); } else if(command == TransportMenuitem.action.PREVIOUS){ @@ -170,7 +144,7 @@ public class Mpris2Controller : GLib.Object } else if(command == TransportMenuitem.action.NEXT){ this.player.Next.begin(); - }*/ + } } public bool connected() diff --git a/src/mpris2-interfaces.vala b/src/mpris2-interfaces.vala new file mode 100644 index 0000000..ef62aba --- /dev/null +++ b/src/mpris2-interfaces.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 . +*/ + + +[DBus (name = "org.mpris.MediaPlayer2")] +public interface MprisRoot : Object { + // properties + public abstract bool HasTracklist{owned get; set;} + public abstract bool CanQuit{owned get; set;} + public abstract bool CanRaise{owned get; set;} + public abstract string Identity{owned get; set;} + public abstract string DesktopEntry{owned get; set;} + // methods + public abstract async void Quit() throws IOError; + public abstract async void Raise() throws IOError; +} + +[DBus (name = "org.mpris.MediaPlayer2.Player")] +public interface MprisPlayer : Object { + // properties + public abstract HashTable Metadata{owned get; set;} + public abstract int32 Position{owned get; set;} + public abstract string PlaybackStatus{owned get; set;} + // methods + public abstract async void PlayPause() throws IOError; + public abstract async void Next() throws IOError; + public abstract async void Previous() throws IOError; + // signals + public signal void Seeked(int64 new_position); +} diff --git a/src/mpris2-watcher.vala b/src/mpris2-watcher.vala new file mode 100644 index 0000000..55212ec --- /dev/null +++ b/src/mpris2-watcher.vala @@ -0,0 +1,76 @@ +/* +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 . +*/ + +// TODO: Until match rules are properly supported in vala we need to explicitly +// watch for each client inorder to facilitate proper registration. + +public class Mpris2Watcher : GLib.Object +{ + public MusicPlayerBridge the_bridge {get; construct;} + const string BANSHEE_BUS_NAME = "org.mpris.MediaPlayer2.banshee"; + private MprisRoot mpris2_root; + private DBusConnection connection; + + public Mpris2Watcher ( MusicPlayerBridge bridge ) + { + GLib.Object(the_bridge: bridge); + } + + construct{ + try { + this.connection = Bus.get_sync ( BusType.SESSION ); + GLib.BusNameAppearedCallback banshee_change_cb = (GLib.BusNameAppearedCallback)banshee_appeared; + GLib.BusNameVanishedCallback banshee_gone_cb = (GLib.BusNameVanishedCallback)banshee_disappeared; + Bus.watch_name_on_connection ( this.connection, + BANSHEE_BUS_NAME, + BusNameWatcherFlags.AUTO_START, + banshee_change_cb, + banshee_gone_cb ); + } + catch ( IOError e ){ + warning( "Mpris2watcher could not set up a watch for mpris clients appearing on the bus: %s", + e.message ); + } + } + + private void banshee_appeared ( GLib.DBusConnection connection, + string name, + string name_owner ) + { + try { + this.mpris2_root = Bus.get_proxy_sync ( BusType.SESSION, + BANSHEE_BUS_NAME, + "/org/mpris/MediaPlayer2" ); + this.the_bridge.client_has_become_available ( this.mpris2_root.DesktopEntry ); + debug ( "On Name Appeared - name %s, name_owner %s", this.mpris2_root.DesktopEntry, name_owner ); + } + catch ( IOError e ){ + warning( "Mpris2watcher could not instantiate an mpris root for banshee: %s", + e.message ); + } + } + + private void banshee_disappeared ( GLib.DBusConnection connection, + string name, + string name_owner ) + { + debug ( "On Name Disappeared - name %s, name_owner %s", name, name_owner ); + } + +} \ No newline at end of file diff --git a/src/music-player-bridge.vala b/src/music-player-bridge.vala index 3fc7efa..8d7998e 100644 --- a/src/music-player-bridge.vala +++ b/src/music-player-bridge.vala @@ -26,13 +26,14 @@ public class MusicPlayerBridge : GLib.Object private Dbusmenu.Menuitem root_menu; private HashMap registered_clients; private FamiliarPlayersDB playersDB; - + private Mpris2Watcher watcher; + private const string DESKTOP_PREFIX = "/usr/share/applications/"; public MusicPlayerBridge() { playersDB = new FamiliarPlayersDB(); registered_clients = new HashMap (); } - + private void try_to_add_inactive_familiar_clients(){ foreach(string app in this.playersDB.records()){ if(app == null){ @@ -79,41 +80,39 @@ public class MusicPlayerBridge : GLib.Object listener_get_server_property_cb cb = (listener_get_server_property_cb)desktop_info_callback; this.listener.server_get_desktop(object, cb, this); } - } + }*/ - private void desktop_info_callback ( Indicate.ListenerServer server, - owned string path, - void* data ) - { - MusicPlayerBridge bridge = data as MusicPlayerBridge; - AppInfo? app_info = create_app_info(path); + public void client_has_become_available ( string desktop_file_name ) + { + string path = DESKTOP_PREFIX.concat ( desktop_file_name.concat( ".desktop" ) ); + AppInfo? app_info = create_app_info ( path ); if ( app_info == null ){ warning ( "Could not create app_info for path %s \n Getting out of here ", path); return; } - var mpris_key = determine_key(path); + var mpris_key = determine_key ( desktop_file_name ); - if(bridge.playersDB.already_familiar(path) == false){ - debug("New client has registered that we have seen before: %s", path); - bridge.playersDB.insert(path); - PlayerController ctrl = new PlayerController ( bridge.root_menu, + if ( this.playersDB.already_familiar ( path ) == false ){ + debug("New client has registered that we have not seen before: %s", desktop_file_name ); + this.playersDB.insert ( path ); + PlayerController ctrl = new PlayerController ( this.root_menu, app_info, mpris_key, playersDB.fetch_icon_name(path), - bridge.calculate_menu_position(), + this.calculate_menu_position(), PlayerController.state.READY ); - bridge.registered_clients.set(mpris_key, ctrl); - debug("successfully created appinfo and instance from path and set it on the respective instance"); + this.registered_clients.set ( mpris_key, ctrl ); + debug ( "successfully created appinfo and instance from path and set it on the respective instance" ); } else{ - bridge.registered_clients[mpris_key].update_state(PlayerController.state.READY); - bridge.registered_clients[mpris_key].activate(); + this.registered_clients[mpris_key].update_state ( PlayerController.state.READY ); + this.registered_clients[mpris_key].activate ( ); debug("Ignoring desktop file path callback because the db cache file has it already: %s \n", path); } } - public void on_server_removed(Indicate.ListenerServer object, string type) + /*public void on_server_removed(Indicate.ListenerServer object, string type) { debug("MusicPlayerBridge -> on_server_removed with value %s", type); if(server_is_not_of_interest(type)) return; @@ -125,44 +124,31 @@ public class MusicPlayerBridge : GLib.Object debug("Successively offlined client %s", tmp[tmp.length - 1]); } } - } - - private bool server_is_not_of_interest(string type){ - if (type == null) return true; - if (type.contains("music") == false) { - debug("server is of no interest, it is not an music server"); - return true; - } - return false; }*/ + public void set_root_menu_item(Dbusmenu.Menuitem menu) { this.root_menu = menu; - try_to_add_inactive_familiar_clients(); + this.try_to_add_inactive_familiar_clients(); + this.watcher = new Mpris2Watcher (this) ; } - public static AppInfo? create_app_info(string path) + public static AppInfo? create_app_info ( string path ) { - DesktopAppInfo info = new DesktopAppInfo.from_filename(path); - if(path == null){ - warning("Could not create a desktopappinfo instance from app: %s", path); + DesktopAppInfo info = new DesktopAppInfo.from_filename ( path ) ; + if ( path == null || info == null ){ + warning ( "Could not create a desktopappinfo instance from app: %s", path ); return null; } - GLib.AppInfo app_info = info as GLib.AppInfo; + GLib.AppInfo app_info = info as GLib.AppInfo; return app_info; } - /** - TODO: clean up - **/ - private static string? determine_key(owned string path) + private static string? determine_key(owned string name) { - var tokens = path.split("/"); - if ( tokens.length < 2) return null; - var filename = tokens[tokens.length - 1]; - var result = filename.split(".")[0]; - var temp = result.split("-"); + string result = name; + var temp = name.split("-"); if (temp.length > 1){ result = temp[0]; } diff --git a/src/player-controller.vala b/src/player-controller.vala index 46add60..3c9b0ff 100644 --- a/src/player-controller.vala +++ b/src/player-controller.vala @@ -114,7 +114,7 @@ public class PlayerController : GLib.Object public void vanish() { foreach(Dbusmenu.Menuitem item in this.custom_items){ - root_menu.child_delete(item); + root_menu.child_delete(item); } } 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; } -- cgit v1.2.3 From d113aa188ab72d8ca3efe22ad7f336f753fb4e48 Mon Sep 17 00:00:00 2001 From: Conor Curran Date: Fri, 3 Dec 2010 13:58:30 +0000 Subject: used a signal instead of passing in ref, still vala bug is biting --- src/mpris2-watcher.vala | 36 +++++++----- src/music-player-bridge.vala | 129 ++++++++++++++++++++++--------------------- 2 files changed, 88 insertions(+), 77 deletions(-) diff --git a/src/mpris2-watcher.vala b/src/mpris2-watcher.vala index 55212ec..ed7388f 100644 --- a/src/mpris2-watcher.vala +++ b/src/mpris2-watcher.vala @@ -22,17 +22,15 @@ with this program. If not, see . public class Mpris2Watcher : GLib.Object { - public MusicPlayerBridge the_bridge {get; construct;} const string BANSHEE_BUS_NAME = "org.mpris.MediaPlayer2.banshee"; - private MprisRoot mpris2_root; private DBusConnection connection; - - public Mpris2Watcher ( MusicPlayerBridge bridge ) + public signal void clientappeared ( string desktop_name ); + + public Mpris2Watcher () { - GLib.Object(the_bridge: bridge); } - - construct{ + construct + { try { this.connection = Bus.get_sync ( BusType.SESSION ); GLib.BusNameAppearedCallback banshee_change_cb = (GLib.BusNameAppearedCallback)banshee_appeared; @@ -46,19 +44,23 @@ public class Mpris2Watcher : GLib.Object catch ( IOError e ){ warning( "Mpris2watcher could not set up a watch for mpris clients appearing on the bus: %s", e.message ); - } + } } private void banshee_appeared ( GLib.DBusConnection connection, string name, - string name_owner ) + string name_owner) { try { - this.mpris2_root = Bus.get_proxy_sync ( BusType.SESSION, - BANSHEE_BUS_NAME, - "/org/mpris/MediaPlayer2" ); - this.the_bridge.client_has_become_available ( this.mpris2_root.DesktopEntry ); - debug ( "On Name Appeared - name %s, name_owner %s", this.mpris2_root.DesktopEntry, name_owner ); + MprisRoot mpris2_root = Bus.get_proxy_sync ( BusType.SESSION, + BANSHEE_BUS_NAME, + "/org/mpris/MediaPlayer2" ); + //this.the_bridge.client_has_become_available ( mpris2_root.DesktopEntry ); + debug ( "On Name Appeared - name %s, name_owner %s", + mpris2_root.DesktopEntry, + name_owner ); + debug ( "this pointer in banshee appeared callback %i", (int)this); + this.clientappeared ( "mpris2_root.DesktopEntry" ); } catch ( IOError e ){ warning( "Mpris2watcher could not instantiate an mpris root for banshee: %s", @@ -66,6 +68,12 @@ public class Mpris2Watcher : GLib.Object } } + public void test_signal_emission() + { + this.clientappeared ( "test signal emission" ); + debug ( "this pointer in test-signal-emission %i", (int)this); + } + private void banshee_disappeared ( GLib.DBusConnection connection, string name, string name_owner ) diff --git a/src/music-player-bridge.vala b/src/music-player-bridge.vala index 8d7998e..73469a4 100644 --- a/src/music-player-bridge.vala +++ b/src/music-player-bridge.vala @@ -24,54 +24,55 @@ using GLib; public class MusicPlayerBridge : GLib.Object { private Dbusmenu.Menuitem root_menu; - private HashMap registered_clients; - private FamiliarPlayersDB playersDB; + private HashMap registered_clients; + private FamiliarPlayersDB playersDB; private Mpris2Watcher watcher; private const string DESKTOP_PREFIX = "/usr/share/applications/"; + public MusicPlayerBridge() { - playersDB = new FamiliarPlayersDB(); - registered_clients = new HashMap (); + playersDB = new FamiliarPlayersDB(); + registered_clients = new HashMap (); } - private void try_to_add_inactive_familiar_clients(){ - foreach(string app in this.playersDB.records()){ - if(app == null){ - warning("App string in keyfile is null therefore moving on to next player"); - continue; - } + private void try_to_add_inactive_familiar_clients(){ + foreach(string app in this.playersDB.records()){ + if(app == null){ + warning("App string in keyfile is null therefore moving on to next player"); + continue; + } + + debug("attempting to make an app info from %s", app); - debug("attempting to make an app info from %s", app); - - DesktopAppInfo info = new DesktopAppInfo.from_filename(app); + DesktopAppInfo info = new DesktopAppInfo.from_filename(app); if(info == null){ - warning("Could not create a desktopappinfo instance from app,: %s , moving on to the next client", app); - continue; - } + warning("Could not create a desktopappinfo instance from app,: %s , moving on to the next client", app); + continue; + } - GLib.AppInfo app_info = info as GLib.AppInfo; + GLib.AppInfo app_info = info as GLib.AppInfo; var mpris_key = determine_key(app); - PlayerController ctrl = new PlayerController(this.root_menu, - app_info, + PlayerController ctrl = new PlayerController(this.root_menu, + app_info, mpris_key, playersDB.fetch_icon_name(app), - calculate_menu_position(), - PlayerController.state.OFFLINE); - this.registered_clients.set(mpris_key, ctrl); - } - } + calculate_menu_position(), + PlayerController.state.OFFLINE); + this.registered_clients.set(mpris_key, ctrl); + } + } - private int calculate_menu_position() - { - if(this.registered_clients.size == 0){ - return 2; - } - else{ - return (2 + (this.registered_clients.size * PlayerController.WIDGET_QUANTITY)); - } - } - + private int calculate_menu_position() + { + if(this.registered_clients.size == 0){ + return 2; + } + else{ + return (2 + (this.registered_clients.size * PlayerController.WIDGET_QUANTITY)); + } + } + /*public void on_server_added(Indicate.ListenerServer object, string type) { debug("MusicPlayerBridge -> on_server_added with value %s", type); @@ -84,8 +85,9 @@ public class MusicPlayerBridge : GLib.Object public void client_has_become_available ( string desktop_file_name ) { + debug ( "client_has_become_available %s", desktop_file_name ); string path = DESKTOP_PREFIX.concat ( desktop_file_name.concat( ".desktop" ) ); - AppInfo? app_info = create_app_info ( path ); + AppInfo? app_info = create_app_info ( path ); if ( app_info == null ){ warning ( "Could not create app_info for path %s \n Getting out of here ", path); return; @@ -93,24 +95,24 @@ public class MusicPlayerBridge : GLib.Object var mpris_key = determine_key ( desktop_file_name ); - if ( this.playersDB.already_familiar ( path ) == false ){ - debug("New client has registered that we have not seen before: %s", desktop_file_name ); - this.playersDB.insert ( path ); - PlayerController ctrl = new PlayerController ( this.root_menu, - app_info, + if ( this.playersDB.already_familiar ( path ) == false ){ + debug("New client has registered that we have not seen before: %s", desktop_file_name ); + this.playersDB.insert ( path ); + PlayerController ctrl = new PlayerController ( this.root_menu, + app_info, mpris_key, playersDB.fetch_icon_name(path), - this.calculate_menu_position(), - PlayerController.state.READY ); + this.calculate_menu_position(), + PlayerController.state.READY ); this.registered_clients.set ( mpris_key, ctrl ); debug ( "successfully created appinfo and instance from path and set it on the respective instance" ); - } - else{ - this.registered_clients[mpris_key].update_state ( PlayerController.state.READY ); - this.registered_clients[mpris_key].activate ( ); - debug("Ignoring desktop file path callback because the db cache file has it already: %s \n", path); - } - } + } + else{ + this.registered_clients[mpris_key].update_state ( PlayerController.state.READY ); + this.registered_clients[mpris_key].activate ( ); + debug("Ignoring desktop file path callback because the db cache file has it already: %s \n", path); + } + } /*public void on_server_removed(Indicate.ListenerServer object, string type) { @@ -126,24 +128,25 @@ public class MusicPlayerBridge : GLib.Object } }*/ - public void set_root_menu_item(Dbusmenu.Menuitem menu) { - this.root_menu = menu; - this.try_to_add_inactive_familiar_clients(); - this.watcher = new Mpris2Watcher (this) ; + this.root_menu = menu; + this.try_to_add_inactive_familiar_clients(); + this.watcher = new Mpris2Watcher (); + this.watcher.clientappeared += this.client_has_become_available; + this.watcher.test_signal_emission(); } - public static AppInfo? create_app_info ( string path ) - { - DesktopAppInfo info = new DesktopAppInfo.from_filename ( path ) ; - if ( path == null || info == null ){ - warning ( "Could not create a desktopappinfo instance from app: %s", path ); - return null; - } - GLib.AppInfo app_info = info as GLib.AppInfo; - return app_info; - } + public static AppInfo? create_app_info ( string path ) + { + DesktopAppInfo info = new DesktopAppInfo.from_filename ( path ) ; + if ( path == null || info == null ){ + warning ( "Could not create a desktopappinfo instance from app: %s", path ); + return null; + } + GLib.AppInfo app_info = info as GLib.AppInfo; + return app_info; + } private static string? determine_key(owned string name) { -- cgit v1.2.3 From 5aada20653702ce8996abd7d25c9bce0a59b65ff Mon Sep 17 00:00:00 2001 From: Conor Curran Date: Fri, 3 Dec 2010 15:05:07 +0000 Subject: used a signal instead of passing in ref, still vala bug is biting --- src/mpris2-watcher.vala | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/mpris2-watcher.vala b/src/mpris2-watcher.vala index ed7388f..775d9b6 100644 --- a/src/mpris2-watcher.vala +++ b/src/mpris2-watcher.vala @@ -47,7 +47,7 @@ public class Mpris2Watcher : GLib.Object } } - private void banshee_appeared ( GLib.DBusConnection connection, + public void banshee_appeared ( GLib.DBusConnection connection, string name, string name_owner) { -- cgit v1.2.3 From 91aa96835684880832c8e535798ebeb6dcca4039 Mon Sep 17 00:00:00 2001 From: Conor Curran Date: Fri, 3 Dec 2010 20:03:21 +0000 Subject: new registration process complete and seemingly healthy --- src/mpris2-watcher.vala | 92 ++++++++++++++++++++++---------------------- src/music-player-bridge.vala | 4 +- 2 files changed, 48 insertions(+), 48 deletions(-) diff --git a/src/mpris2-watcher.vala b/src/mpris2-watcher.vala index 775d9b6..7e41b5f 100644 --- a/src/mpris2-watcher.vala +++ b/src/mpris2-watcher.vala @@ -17,68 +17,68 @@ You should have received a copy of the GNU General Public License along with this program. If not, see . */ -// TODO: Until match rules are properly supported in vala we need to explicitly -// watch for each client inorder to facilitate proper registration. +[DBus (name = "org.freedesktop.DBus")] +public interface FreeDesktopObject: Object { + public abstract signal void name_owner_changed (string name, + string old_owner, + string new_owner); +} public class Mpris2Watcher : GLib.Object { - const string BANSHEE_BUS_NAME = "org.mpris.MediaPlayer2.banshee"; - private DBusConnection connection; - public signal void clientappeared ( string desktop_name ); + private const string FREEDESKTOP_SERVICE = "org.freedesktop.DBus"; + private const string FREEDESKTOP_OBJECT = "/org/freedesktop/DBus"; + private const string MPRIS_PREFIX = "org.mpris.MediaPlayer2."; + private const string MPRIS_MEDIA_PLAYER_PATH = "/org/mpris/MediaPlayer2"; + + FreeDesktopObject fdesktop_obj; + + public signal void client_appeared ( string desktop_name ); + public signal void client_disappeared ( string desktop_name ); public Mpris2Watcher () { } + construct { try { - this.connection = Bus.get_sync ( BusType.SESSION ); - GLib.BusNameAppearedCallback banshee_change_cb = (GLib.BusNameAppearedCallback)banshee_appeared; - GLib.BusNameVanishedCallback banshee_gone_cb = (GLib.BusNameVanishedCallback)banshee_disappeared; - Bus.watch_name_on_connection ( this.connection, - BANSHEE_BUS_NAME, - BusNameWatcherFlags.AUTO_START, - banshee_change_cb, - banshee_gone_cb ); + this.fdesktop_obj = Bus.get_proxy_sync ( BusType.SESSION, + FREEDESKTOP_SERVICE, + FREEDESKTOP_OBJECT, + DBusProxyFlags.DO_NOT_LOAD_PROPERTIES ); + this.fdesktop_obj.name_owner_changed.connect (this.name_changes_detected); } catch ( IOError e ){ warning( "Mpris2watcher could not set up a watch for mpris clients appearing on the bus: %s", - e.message ); + e.message ); } } - public void banshee_appeared ( GLib.DBusConnection connection, - string name, - string name_owner) - { - try { - MprisRoot mpris2_root = Bus.get_proxy_sync ( BusType.SESSION, - BANSHEE_BUS_NAME, - "/org/mpris/MediaPlayer2" ); - //this.the_bridge.client_has_become_available ( mpris2_root.DesktopEntry ); - debug ( "On Name Appeared - name %s, name_owner %s", - mpris2_root.DesktopEntry, - name_owner ); - debug ( "this pointer in banshee appeared callback %i", (int)this); - this.clientappeared ( "mpris2_root.DesktopEntry" ); + private void name_changes_detected ( FreeDesktopObject dbus_obj, + string name, + string previous_owner, + string current_owner ) { + MprisRoot mpris2_root; + if ( name.has_prefix (MPRIS_PREFIX) ){ + try { + mpris2_root = Bus.get_proxy_sync ( BusType.SESSION, + name, + MPRIS_MEDIA_PLAYER_PATH ); + } + catch (IOError e){ + warning( "Mpris2watcher could not create a root interface: %s", + e.message ); + return; + } + if (previous_owner != "" && current_owner == "") { + debug ("Service '%s' going down", name); + client_disappeared (mpris2_root.DesktopEntry); + } + else if (previous_owner == "" && current_owner != "") { + debug ("Service '%s' has appeared", name); + client_appeared (mpris2_root.DesktopEntry); + } } - catch ( IOError e ){ - warning( "Mpris2watcher could not instantiate an mpris root for banshee: %s", - e.message ); - } } - - public void test_signal_emission() - { - this.clientappeared ( "test signal emission" ); - debug ( "this pointer in test-signal-emission %i", (int)this); - } - - private void banshee_disappeared ( GLib.DBusConnection connection, - string name, - string name_owner ) - { - debug ( "On Name Disappeared - name %s, name_owner %s", name, name_owner ); - } - } \ No newline at end of file diff --git a/src/music-player-bridge.vala b/src/music-player-bridge.vala index 73469a4..8124021 100644 --- a/src/music-player-bridge.vala +++ b/src/music-player-bridge.vala @@ -133,8 +133,8 @@ public class MusicPlayerBridge : GLib.Object this.root_menu = menu; this.try_to_add_inactive_familiar_clients(); this.watcher = new Mpris2Watcher (); - this.watcher.clientappeared += this.client_has_become_available; - this.watcher.test_signal_emission(); + this.watcher.client_appeared += this.client_has_become_available; + //this.watcher.client_appeared += this.client_has_become_available; } public static AppInfo? create_app_info ( string path ) -- cgit v1.2.3 From 65127a75569ae72173423510dedbc639f71cd9ba Mon Sep 17 00:00:00 2001 From: Conor Curran Date: Mon, 6 Dec 2010 13:22:26 +0000 Subject: registration working now but menuitems are unresponsive, now to move over to the new dbusmenu --- src/music-player-bridge.vala | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/src/music-player-bridge.vala b/src/music-player-bridge.vala index 8124021..c905c12 100644 --- a/src/music-player-bridge.vala +++ b/src/music-player-bridge.vala @@ -52,7 +52,7 @@ public class MusicPlayerBridge : GLib.Object } GLib.AppInfo app_info = info as GLib.AppInfo; - var mpris_key = determine_key(app); + var mpris_key = determine_key ( app ); PlayerController ctrl = new PlayerController(this.root_menu, app_info, mpris_key, @@ -93,7 +93,7 @@ public class MusicPlayerBridge : GLib.Object return; } - var mpris_key = determine_key ( desktop_file_name ); + var mpris_key = determine_key ( path ); if ( this.playersDB.already_familiar ( path ) == false ){ debug("New client has registered that we have not seen before: %s", desktop_file_name ); @@ -148,10 +148,13 @@ public class MusicPlayerBridge : GLib.Object return app_info; } - private static string? determine_key(owned string name) + private static string? determine_key(owned string path) { - string result = name; - var temp = name.split("-"); + var tokens = path.split("/"); + if ( tokens.length < 2) return null; + var filename = tokens[tokens.length - 1]; + var result = filename.split(".")[0]; + var temp = result.split("-"); if (temp.length > 1){ result = temp[0]; } -- cgit v1.2.3 From aef17a4810d3480b64b20dd6aebd8b12e104778a Mon Sep 17 00:00:00 2001 From: Conor Curran Date: Mon, 6 Dec 2010 15:33:58 +0000 Subject: registration working perfectly and operational all over gdbus --- src/mpris2-controller.vala | 207 +++++++++++++++++++++---------------------- src/mpris2-watcher.vala | 8 +- src/music-player-bridge.vala | 34 ++++--- 3 files changed, 124 insertions(+), 125 deletions(-) diff --git a/src/mpris2-controller.vala b/src/mpris2-controller.vala index c382e97..ff19598 100644 --- a/src/mpris2-controller.vala +++ b/src/mpris2-controller.vala @@ -20,11 +20,9 @@ with this program. If not, see . using Dbusmenu; -/*[DBus (name = "org.freedesktop.DBus.Properties")] - public interface FreeDesktopProperties : DBus.Object{ - // signals - public signal void PropertiesChanged(string source, HashTable changed_properties, +[DBus (name = "org.freedesktop.DBus.Properties")] + public interface FreeDesktopProperties : Object{ + public signal void PropertiesChanged(string source, HashTable changed_properties, string[] invalid); } @@ -33,136 +31,131 @@ using Dbusmenu; point in trying to get encorporate both into the same object model. */ 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 FreeDesktopProperties properties_interface {get; construct;} +{ + public static const string root_interface = "org.mpris.MediaPlayer2" ; + public MprisRoot mpris2_root {get; construct;} + public MprisPlayer player {get; construct;} + public FreeDesktopProperties properties_interface {get; construct;} public PlayerController owner {get; construct;} - - public Mpris2Controller(PlayerController ctrl) - { - GLib.Object(owner: ctrl); - } - - construct{ + + public Mpris2Controller(PlayerController ctrl) + { + GLib.Object(owner: ctrl); + } + + construct{ try { - this.mpris2_root = Bus.get_proxy_sync ( BusType.SESSION, + this.mpris2_root = Bus.get_proxy_sync ( BusType.SESSION, root_interface.concat(".").concat(this.owner.mpris_name), - "/org/mpris/MediaPlayer2"); - this.player = Bus.get_proxy_sync ( BusType.SESSION, + "/org/mpris/MediaPlayer2"); + this.player = Bus.get_proxy_sync ( BusType.SESSION, root_interface.concat(".").concat(this.owner.mpris_name), - "/org/mpris/MediaPlayer2" ); - /* - this.properties_interface = (FreeDesktopProperties) connection.get_object("org.freedesktop.Properties.PropertiesChanged", - "/org/mpris/MediaPlayer2"); - this.properties_interface.PropertiesChanged += property_changed_cb;*/ + "/org/mpris/MediaPlayer2" ); - } catch (IOError e) { - error("Problems connecting to the session bus - %s", e.message); - } - } - - /*public void property_changed_cb(string interface_source, HashTable changed_properties, string[] invalid ) - { - debug("properties-changed for interface %s and owner %s", interface_source, this.owner.mpris_name); - - if(changed_properties == null || interface_source.has_prefix(this.root_interface) == false ){ - warning("Property-changed hash is null or this is an interface that doesn't concerns us"); - return; - } - Value? play_v = changed_properties.lookup("PlaybackStatus"); - if(play_v != null){ - string state = this.player.PlaybackStatus; - TransportMenuitem.state p = (TransportMenuitem.state)this.determine_play_state(state); - (this.owner.custom_items[PlayerController.widget_order.TRANSPORT] as TransportMenuitem).change_play_state(p); - } - - Value? meta_v = changed_properties.lookup("Metadata"); - if(meta_v != null){ - GLib.HashTable changed_updates = clean_metadata(); + this.properties_interface = Bus.get_proxy_sync ( BusType.SESSION, + "org.freedesktop.Properties.PropertiesChanged", + "/org/mpris/MediaPlayer2" ); + this.properties_interface.PropertiesChanged += property_changed_cb; + } + catch (IOError e) { + error("Problems connecting to the session bus - %s", e.message); + } + } + + public void property_changed_cb ( string interface_source, + HashTable changed_properties, + string[] invalid ) + { + debug("properties-changed for interface %s and owner %s", interface_source, this.owner.mpris_name); + if(changed_properties == null || interface_source.has_prefix(this.root_interface) == false ){ + warning("Property-changed hash is null or this is an interface that doesn't concerns us"); + return; + } + Variant? play_v = changed_properties.lookup("PlaybackStatus"); + if(play_v != null){ + string state = this.player.PlaybackStatus; + TransportMenuitem.state p = (TransportMenuitem.state)this.determine_play_state(state); + (this.owner.custom_items[PlayerController.widget_order.TRANSPORT] as TransportMenuitem).change_play_state(p); + } + Variant? meta_v = changed_properties.lookup("Metadata"); + if(meta_v != null){ + GLib.HashTable changed_updates = clean_metadata(); PlayerItem metadata = this.owner.custom_items[PlayerController.widget_order.METADATA]; - metadata.reset(MetadataMenuitem.attributes_format()); - metadata.update(changed_updates, - MetadataMenuitem.attributes_format()); - metadata.property_set_bool(MENUITEM_PROP_VISIBLE, - metadata.populated(MetadataMenuitem.attributes_format())); + metadata.reset( MetadataMenuitem.attributes_format()); + metadata.update ( changed_updates, + MetadataMenuitem.attributes_format()); + metadata.property_set_bool ( MENUITEM_PROP_VISIBLE, + metadata.populated(MetadataMenuitem.attributes_format())); } - }*/ + } - private GLib.HashTable? clean_metadata() + private GLib.HashTable? clean_metadata() { - /*GLib.HashTable changed_updates = this.player.Metadata; - Value? artist_v = this.player.Metadata.lookup("xesam:artist"); + GLib.HashTable changed_updates = this.player.Metadata; + Variant? artist_v = this.player.Metadata.lookup("xesam:artist"); if(artist_v != null){ 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); } - Value? length_v = this.player.Metadata.lookup("mpris:length"); + Variant? length_v = this.player.Metadata.lookup("mpris:length"); if(length_v != null){ int64 duration = this.player.Metadata.lookup("mpris:length").get_int64(); changed_updates.replace("mpris:length", duration/1000000); } return changed_updates; - */ - return null; - } - - private TransportMenuitem.state determine_play_state(string? status){ - if(status != null && status == "Playing"){ - return TransportMenuitem.state.PLAYING; - } - return TransportMenuitem.state.PAUSED; + //return null; } - public void initial_update() - { - TransportMenuitem.state update; - /*if(this.player.PlaybackStatus == null){ - update = TransportMenuitem.state.PAUSED; - }*/ + private TransportMenuitem.state determine_play_state(string? status){ + if(status != null && status == "Playing"){ + return TransportMenuitem.state.PLAYING; + } + return TransportMenuitem.state.PAUSED; + } + + public void initial_update() + { + TransportMenuitem.state update; + if(this.player.PlaybackStatus == null){ + update = TransportMenuitem.state.PAUSED; + } update = determine_play_state(null); - + (this.owner.custom_items[PlayerController.widget_order.TRANSPORT] as TransportMenuitem).change_play_state(TransportMenuitem.state.PAUSED); - GLib.HashTable? cleaned_metadata = this.clean_metadata(); - //this.owner.custom_items[PlayerController.widget_order.METADATA].update(cleaned_metadata, - // MetadataMenuitem.attributes_format()); - } - - public void transport_update(TransportMenuitem.action command) - { - debug("transport_event input = %i", (int)command); - if(command == TransportMenuitem.action.PLAY_PAUSE){ - this.player.PlayPause.begin(); - } - else if(command == TransportMenuitem.action.PREVIOUS){ - this.player.Previous.begin(); - } - else if(command == TransportMenuitem.action.NEXT){ - this.player.Next.begin(); - } - } - - public bool connected() - { - return false; - } + GLib.HashTable? cleaned_metadata = this.clean_metadata(); + this.owner.custom_items[PlayerController.widget_order.METADATA].update(cleaned_metadata, + MetadataMenuitem.attributes_format()); + } + + public void transport_update(TransportMenuitem.action command) + { + debug("transport_event input = %i", (int)command); + if(command == TransportMenuitem.action.PLAY_PAUSE){ + this.player.PlayPause.begin(); + } + else if(command == TransportMenuitem.action.PREVIOUS){ + this.player.Previous.begin(); + } + else if(command == TransportMenuitem.action.NEXT){ + this.player.Next.begin(); + } + } - - public bool was_successfull(){ - return false; - } + public bool connected() + { + return (this.player != null && this.mpris2_root != null); + } - public void expose() - { - if(this.connected() == true){ - //this.mpris2_root.Raise.begin(); - } - } + public void expose() + { + if(this.connected() == true){ + this.mpris2_root.Raise.begin(); + } + } } diff --git a/src/mpris2-watcher.vala b/src/mpris2-watcher.vala index 7e41b5f..1cf8baa 100644 --- a/src/mpris2-watcher.vala +++ b/src/mpris2-watcher.vala @@ -34,7 +34,7 @@ public class Mpris2Watcher : GLib.Object FreeDesktopObject fdesktop_obj; public signal void client_appeared ( string desktop_name ); - public signal void client_disappeared ( string desktop_name ); + public signal void client_disappeared ( string mpris_root_interface ); public Mpris2Watcher () { @@ -72,11 +72,11 @@ public class Mpris2Watcher : GLib.Object return; } if (previous_owner != "" && current_owner == "") { - debug ("Service '%s' going down", name); - client_disappeared (mpris2_root.DesktopEntry); + debug ("Client '%s' gone down", name); + client_disappeared (name); } else if (previous_owner == "" && current_owner != "") { - debug ("Service '%s' has appeared", name); + debug ("Client '%s' has appeared", name); client_appeared (mpris2_root.DesktopEntry); } } diff --git a/src/music-player-bridge.vala b/src/music-player-bridge.vala index c905c12..d1c2334 100644 --- a/src/music-player-bridge.vala +++ b/src/music-player-bridge.vala @@ -114,19 +114,18 @@ public class MusicPlayerBridge : GLib.Object } } - /*public void on_server_removed(Indicate.ListenerServer object, string type) + public void client_has_vanished ( string mpris_root_interface ) { - debug("MusicPlayerBridge -> on_server_removed with value %s", type); - if(server_is_not_of_interest(type)) return; - if (root_menu != null){ - var tmp = type.split("."); - debug("attempt to remove %s", tmp[tmp.length-1]); - if(tmp.length > 0){ - registered_clients[tmp[tmp.length - 1]].hibernate(); - debug("Successively offlined client %s", tmp[tmp.length - 1]); + debug("MusicPlayerBridge -> on_server_removed with value %s", mpris_root_interface); + if (root_menu != null){ + debug("attempt to remove %s", mpris_root_interface); + var mpris_key = determine_key ( mpris_root_interface ); + if ( mpris_key != null ){ + registered_clients[mpris_key].hibernate(); + debug("Successively offlined client %s", mpris_key); } - } - }*/ + } + } public void set_root_menu_item(Dbusmenu.Menuitem menu) { @@ -134,7 +133,7 @@ public class MusicPlayerBridge : GLib.Object this.try_to_add_inactive_familiar_clients(); this.watcher = new Mpris2Watcher (); this.watcher.client_appeared += this.client_has_become_available; - //this.watcher.client_appeared += this.client_has_become_available; + this.watcher.client_disappeared += this.client_has_vanished; } public static AppInfo? create_app_info ( string path ) @@ -150,8 +149,15 @@ public class MusicPlayerBridge : GLib.Object private static string? determine_key(owned string path) { - var tokens = path.split("/"); - if ( tokens.length < 2) return null; + var tokens = path.split( "/" ); + if ( tokens.length < 2 ){ + // try to split on "." + tokens = path.split("."); + if ( tokens.length < 2 ){ + // don't know what this is + return null; + } + } var filename = tokens[tokens.length - 1]; var result = filename.split(".")[0]; var temp = result.split("-"); -- cgit v1.2.3 From 1d73614b6c2789d11c7e63efcd22634015aff737 Mon Sep 17 00:00:00 2001 From: Conor Curran Date: Mon, 6 Dec 2010 15:36:19 +0000 Subject: tidy up for merge --- src/mpris2-controller.vala | 7 +------ src/sound-service.c | 5 ++--- 2 files changed, 3 insertions(+), 9 deletions(-) diff --git a/src/mpris2-controller.vala b/src/mpris2-controller.vala index ff19598..3adaad6 100644 --- a/src/mpris2-controller.vala +++ b/src/mpris2-controller.vala @@ -16,7 +16,6 @@ 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 DBus; using Dbusmenu; @@ -106,7 +105,6 @@ public class Mpris2Controller : GLib.Object changed_updates.replace("mpris:length", duration/1000000); } return changed_updates; - //return null; } private TransportMenuitem.state determine_play_state(string? status){ @@ -156,7 +154,4 @@ public class Mpris2Controller : GLib.Object this.mpris2_root.Raise.begin(); } } -} - - - +} \ No newline at end of file diff --git a/src/sound-service.c b/src/sound-service.c index 51f5f37..98f1881 100644 --- a/src/sound-service.c +++ b/src/sound-service.c @@ -40,9 +40,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; } -- cgit v1.2.3 From 4061f2bed3ed22262305c19e534f1007f7febbe9 Mon Sep 17 00:00:00 2001 From: Conor Curran Date: Mon, 6 Dec 2010 17:31:10 +0000 Subject: string updates working properly now --- src/mpris2-controller.vala | 4 ++-- src/player-item.vala | 20 ++++++++++---------- 2 files changed, 12 insertions(+), 12 deletions(-) diff --git a/src/mpris2-controller.vala b/src/mpris2-controller.vala index 3adaad6..87f0307 100644 --- a/src/mpris2-controller.vala +++ b/src/mpris2-controller.vala @@ -94,10 +94,10 @@ public class Mpris2Controller : GLib.Object GLib.HashTable changed_updates = this.player.Metadata; Variant? artist_v = this.player.Metadata.lookup("xesam:artist"); if(artist_v != null){ - string[] artists = (string[])this.player.Metadata.lookup("xesam:artist"); + 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); + debug("artist : %s", (string)changed_updates.lookup("xesam:artist")); } Variant? length_v = this.player.Metadata.lookup("mpris:length"); if(length_v != null){ diff --git a/src/player-item.vala b/src/player-item.vala index 51471d1..54d0d89 100644 --- a/src/player-item.vala +++ b/src/player-item.vala @@ -48,7 +48,7 @@ public class PlayerItem : Dbusmenu.Menuitem * and attmepts to update the appropriate props on the object. * Album art is handled separately to deal with remote and local file paths. */ - public void update(HashTable data, HashSet attributes) + public void update(HashTable data, HashSet attributes) { debug("PlayerItem::update()"); if(data == null){ @@ -60,29 +60,29 @@ public class PlayerItem : Dbusmenu.Menuitem string[] input_keys = property.split("-"); string search_key = input_keys[input_keys.length-1 : input_keys.length][0]; debug("search key = %s", search_key); - Value? v = data.lookup(search_key); + Variant? v = data.lookup(search_key); - if (v.holds (typeof (string))){ + if (v.is_of_type ( VariantType.STRING )){ string update = v.get_string().strip(); debug("with value : %s", update); 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; + metadata.fetch_art ( update, property ); + continue; } this.property_set(property, update); } - else if (v.holds (typeof (int))){ - debug("with value : %i", v.get_int()); - this.property_set_int(property, v.get_int()); + else if (v.is_of_type (VariantType.INT32 )){ + debug("with value : %i", v.get_int32()); + this.property_set_int(property, v.get_int32()); } - else if (v.holds (typeof (int64))){ + else if (v.is_of_type (VariantType.INT64 )){ debug("with value : %i", (int)v.get_int64()); this.property_set_int(property, (int)v.get_int64()); } - else if(v.holds (typeof (bool))){ + else if(v.is_of_type ( VariantType.BOOLEAN )){ debug("with value : %s", v.get_boolean().to_string()); this.property_set_bool(property, v.get_boolean()); } -- cgit v1.2.3