diff options
author | Conor Curran <conor.curran@canonical.com> | 2010-08-12 13:21:57 +0100 |
---|---|---|
committer | Conor Curran <conor.curran@canonical.com> | 2010-08-12 13:21:57 +0100 |
commit | 72ffb2c3c096cf0e7ece12c93bfeff5b651fed13 (patch) | |
tree | 908307c96ede45783599351124f03a464fb844fc | |
parent | 44d47d0c4d334ba3cd2b8d9bd34893ba8c3dedf9 (diff) | |
download | ayatana-indicator-sound-72ffb2c3c096cf0e7ece12c93bfeff5b651fed13.tar.gz ayatana-indicator-sound-72ffb2c3c096cf0e7ece12c93bfeff5b651fed13.tar.bz2 ayatana-indicator-sound-72ffb2c3c096cf0e7ece12c93bfeff5b651fed13.zip |
abstracted the mpris handling to accomodate the messy integration issues
-rw-r--r-- | src/Makefile.am | 1 | ||||
-rw-r--r-- | src/mpris-bridge.vala | 60 | ||||
-rw-r--r-- | src/mpris-controller.vala | 1 | ||||
-rw-r--r-- | src/mpris2-controller.vala | 44 | ||||
-rw-r--r-- | src/player-controller.vala | 66 | ||||
-rw-r--r-- | src/scrub-menu-item.vala | 2 | ||||
-rw-r--r-- | src/transport-menu-item.vala | 2 |
7 files changed, 101 insertions, 75 deletions
diff --git a/src/Makefile.am b/src/Makefile.am index 0e22fe4..5d073c7 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -65,6 +65,7 @@ music_bridge_VALASOURCES = \ scrub-menu-item.vala \ title-menu-item.vala \ player-controller.vala \ + mpris-bridge.vala \ mpris-controller.vala \ mpris2-controller.vala \ player-item.vala \ diff --git a/src/mpris-bridge.vala b/src/mpris-bridge.vala new file mode 100644 index 0000000..682069c --- /dev/null +++ b/src/mpris-bridge.vala @@ -0,0 +1,60 @@ +public class MprisBridge : GLib.Object +{ + private MprisController mpris1_controller; + private Mpris2Controller mpris2_controller; + private enum mode{ + MPRIS_1, + MPRIS_2 + } + private mode mode_in_use; + + public MprisBridge(PlayerController ctrl) + { + this.mpris2_controller == new Mpris2Controller(ctrl); + if(this.mpris2_controller.was_successfull() == true){ + mode_in_use == mode.MPRIS_2; + this.mpris1_controller == null; + this.mpris2_controller.initial_update(); + } + else{ + delete this.mpris2_controller; + this.mpris2_controller == null; + mode_in_use == mode.MPRIS_1; + this.mpris1_controller = new Mpris1Controller(ctrl); + } + } + + // The handling of both mpris controllers can be abstracted further + // once the mpris2 is implemented. This will allow for one instance + // variable to point at the active controller. For now handle both ... + public bool connected() + { + if(this.mode_in_use == mode.MPRIS_1){ + return this.mpris1_controller.connected(); + } + else if(this.mode_in_use == mode.MPRIS_2){ + return this.mpris2_controller.connected(); + } + return false; + } + + public void transport_update(TransportMenuitem.action update) + { + if(this.mode_in_use == mode.MPRIS_1){ + this.mpris1_controller.transport_event(update); + } + else if(this.mode_in_use == mode.MPRIS_2){ + this.mpris2_controller.transport_event(update); + } + } + + public void set_track_position(double pos) + { + if(this.mode_in_use == mode.MPRIS_1){ + this.mpris1_controller.set_position(pos); + } + else if(this.mode_in_use == mode.MPRIS_2){ + this.mpris2_controller.set_position(pos); + } + } +}
\ No newline at end of file diff --git a/src/mpris-controller.vala b/src/mpris-controller.vala index c70c6d5..db71c70 100644 --- a/src/mpris-controller.vala +++ b/src/mpris-controller.vala @@ -63,7 +63,6 @@ public class MprisController : GLib.Object MetadataMenuitem.attributes_format()); this.owner.custom_items[PlayerController.widget_order.SCRUB].update(this.mpris_player.GetMetadata(), ScrubMenuitem.attributes_format()); - // temporary fix ScrubMenuitem scrub = this.owner.custom_items[PlayerController.widget_order.SCRUB] as ScrubMenuitem; scrub.update_position(this.mpris_player.PositionGet()); } diff --git a/src/mpris2-controller.vala b/src/mpris2-controller.vala index 20cfc9e..6c1b71a 100644 --- a/src/mpris2-controller.vala +++ b/src/mpris2-controller.vala @@ -58,30 +58,46 @@ public class Mpris2Controller : GLib.Object public Mpris2Controller(PlayerController ctrl) { - Object(owner: ctrl); + Object(owner: ctrl); + this.mpris2_root = null; + this.mpris2_player = null; } construct{ try { - debug("going to create this mpris 2 controller"); + debug("Going to try and create an mpris 2 controller"); this.connection = DBus.Bus.get (DBus.BusType.SESSION); } catch (Error e) { error("Problems connecting to the session bus - %s", e.message); - } - this.mpris2_root = this.connection.get_object ("org.mpris.mediaplayers.".concat(this.owner.name.down()), - "/org/mpris/MediaPlayer", - "org.mpris.MediaPlayer"); - - this.mpris2_player = (MprisPlayer)this.connection.get_object ("org.mpris.mediaplayers.".concat(this.owner.name.down()) , - "/org/mpris/MediaPlayer/Player", - "org.mpris.MediaPlayer.Player"); - this.mpris2_player.TrackChanged += onTrackChanged; - this.mpris2_player.StatusChanged += onStatusChanged; - initial_update(); + } + + try { + this.mpris2_root = this.connection.get_object ("org.mpris.mediaplayers.".concat(this.owner.name.down()), + "/org/mpris/MediaPlayer", + "org.mpris.MediaPlayer"); + this.mpris2_player = (MprisPlayer)this.connection.get_object ("org.mpris.mediaplayers.".concat(this.owner.name.down()) , + "/org/mpris/MediaPlayer/Player", + "org.mpris.MediaPlayer.Player"); + } + catch(Error e){ + error("Problems connecting to + } + } + + public bool was_successfull(){ + if(this.mpris2_root == null || + this.mpris2_player == null) + { + return false; + } + return true; } - private void initial_update() + public void initial_update() { + this.mpris2_player.TrackChanged += onTrackChanged; + this.mpris2_player.StatusChanged += onStatusChanged; + bool r = (bool)this.mpris2_player.Status.Shuffle_State; int32 p = (int32)this.mpris2_player.Status.Playback_State; diff --git a/src/player-controller.vala b/src/player-controller.vala index 33a5b1a..bccf586 100644 --- a/src/player-controller.vala +++ b/src/player-controller.vala @@ -43,14 +43,11 @@ public class PlayerController : GLib.Object } public int current_state = state.OFFLINE; - - + private Dbusmenu.Menuitem root_menu; public string name { get; set;} public ArrayList<PlayerItem> custom_items; - public Mpris2Controller mpris2_adaptor; - public MprisController mpris_adaptor; - public bool mpris2; + public MprisBridge mpris_bridge; public AppInfo? app_info { get; set;} public int menu_offset { get; set;} @@ -77,7 +74,6 @@ public class PlayerController : GLib.Object public void activate() { this.establish_mpris_connection(); - //this.custom_items[widget_order.METADATA].property_set_bool(MENUITEM_PROP_VISIBLE, true); } /* @@ -104,14 +100,7 @@ public class PlayerController : GLib.Object debug("establish_mpris_connection - Not ready to connect"); return; } - if(this.name == "Vlc"){ - debug("establishing a vlc mpris controller"); - this.mpris2_adaptor = new Mpris2Controller(this); - this.mpris2 = true; - } - else{ - this.mpris_adaptor = new MprisController(this); - } + this.mpris_bridge = new MprisBridge(); this.determine_state(); } @@ -144,19 +133,12 @@ public class PlayerController : GLib.Object false); return; } - debug("update layout - metadata %s", this.custom_items[widget_order.METADATA].populated(MetadataMenuitem.attributes_format()).to_string()); this.custom_items[widget_order.METADATA].property_set_bool(MENUITEM_PROP_VISIBLE, - this.custom_items[widget_order.METADATA].populated(MetadataMenuitem.attributes_format())); - //debug("metadata id %i", this.custom_items[widget_order.METADATA].id); - - debug("update layout - scrub %s", this.custom_items[widget_order.SCRUB].populated(ScrubMenuitem.attributes_format()).to_string()); + this.custom_items[widget_order.METADATA].populated(MetadataMenuitem.attributes_format())); this.custom_items[widget_order.SCRUB].property_set_bool(MENUITEM_PROP_VISIBLE, this.custom_items[widget_order.SCRUB].populated(ScrubMenuitem.attributes_format())); - - this.custom_items[widget_order.TRANSPORT].property_set_bool(MENUITEM_PROP_VISIBLE, true); - this.custom_items[widget_order.PLAYLIST].property_set_bool(MENUITEM_PROP_VISIBLE, true); } @@ -223,45 +205,13 @@ public class PlayerController : GLib.Object // 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 set_track_position(double pos) - { - if(this.mpris2 == true){ - this.mpris2_adaptor.set_position(pos); - } - else{ - this.mpris_adaptor.set_position(pos); - } - } - - public void transport_update(TransportMenuitem.action update) - { - if(this.mpris2 == true){ - this.mpris2_adaptor.transport_event(update); - } - else{ - this.mpris_adaptor.transport_event(update); - } - } - public void determine_state() { - if(this.mpris2 == true){ - if(this.mpris2_adaptor.connected() == true){ - debug("yup I'm connected"); - this.update_state(state.CONNECTED); - } - else{ - this.update_state(state.DISCONNECTED); - } + if(this.mpris_bridge.connected() == true){ + this.update_state(state.CONNECTED); } else{ - if(this.mpris_adaptor.connected() == true){ - debug("yup I'm connected"); - this.update_state(state.CONNECTED); - } - else{ - this.update_state(state.DISCONNECTED); - } - } + this.update_state(state.DISCONNECTED); + } } }
\ No newline at end of file diff --git a/src/scrub-menu-item.vala b/src/scrub-menu-item.vala index e220612..7368a0c 100644 --- a/src/scrub-menu-item.vala +++ b/src/scrub-menu-item.vala @@ -32,7 +32,7 @@ public class ScrubMenuitem : PlayerItem public override void handle_event(string name, GLib.Value input_value, uint timestamp) { debug("handle_event for owner %s with value: %f", this.owner.name, input_value.get_double()); - this.owner.set_track_position(input_value.get_double()); + this.owner.mpris_bridge.set_track_position(input_value.get_double()); } public void update_position(int32 new_position) diff --git a/src/transport-menu-item.vala b/src/transport-menu-item.vala index 45c2692..8bdd2c8 100644 --- a/src/transport-menu-item.vala +++ b/src/transport-menu-item.vala @@ -45,7 +45,7 @@ public class TransportMenuitem : PlayerItem int input = input_value.get_int(); debug("handle_event with value %s", input.to_string()); debug("transport owner name = %s", this.owner.name); - this.owner.transport_update((action)input); + this.owner.mpris_bridge.transport_update((action)input); } public static HashSet<string> attributes_format() |