From edac78eadc5ddceb17b93bffa101eeffbab4437c Mon Sep 17 00:00:00 2001 From: Conor Curran Date: Wed, 30 Jun 2010 18:02:53 +0100 Subject: correct startup behaviour in place --- src/player-controller.vala | 25 +++++++++++++++++-------- 1 file changed, 17 insertions(+), 8 deletions(-) (limited to 'src/player-controller.vala') diff --git a/src/player-controller.vala b/src/player-controller.vala index 0d8dc01..dfc2659 100644 --- a/src/player-controller.vala +++ b/src/player-controller.vala @@ -27,19 +27,20 @@ public class PlayerController : GLib.Object private const int TRANSPORT = 3; private Dbusmenu.Menuitem root_menu; - private string name; - private bool is_active; + public string name { get; set;} + public bool active { get; set;} public ArrayList custom_items; private MprisController mpris_adaptor; - private string desktop_path; - - public PlayerController(Dbusmenu.Menuitem root, string client_name, bool active) + public AppInfo app_info { get; set;} + + public PlayerController(Dbusmenu.Menuitem root, string client_name, AppInfo? info = null) { this.root_menu = root; this.name = format_client_name(client_name.strip()); - this.is_active = active; this.custom_items = new ArrayList(); + this.app_info = info; self_construct(); + //app_info.launch(null, null); // Temporary scenario to handle both v1 and v2 of MPRIS. if(this.name == "Vlc"){ @@ -61,6 +62,14 @@ public class PlayerController : GLib.Object root_menu.child_delete(item); } } + + //public void switch_active(bool active){ + // this.is_active = active; + //} + + //public bool has_app_info(){ + // return (this.app_info != null); + //} private bool self_construct() { @@ -84,7 +93,7 @@ public class PlayerController : GLib.Object } return true; } - + private static string format_client_name(string client_name) { string formatted = client_name; @@ -94,5 +103,5 @@ public class PlayerController : GLib.Object } return formatted; } - + } \ No newline at end of file -- cgit v1.2.3 From 7555ea6755750dd64a6c4652b852a0bdc0d0bfeb Mon Sep 17 00:00:00 2001 From: Conor Curran Date: Tue, 6 Jul 2010 18:55:05 +0100 Subject: whole new widget to house the customised title item --- src/player-controller.vala | 97 +++++++++++++++++++++++++++++++++------------- 1 file changed, 71 insertions(+), 26 deletions(-) (limited to 'src/player-controller.vala') diff --git a/src/player-controller.vala b/src/player-controller.vala index dfc2659..dd55f3d 100644 --- a/src/player-controller.vala +++ b/src/player-controller.vala @@ -25,37 +25,79 @@ public class PlayerController : GLib.Object { public const int METADATA = 2; private const int TRANSPORT = 3; + + public static const int OFFLINE = 0; + public static const int INSTANTIATING = 1; + public static const int READY = 2; + public static const int CONNECTED = 3; + public static const int DISCONNECTED = 4; + + public int current_state = OFFLINE; + private Dbusmenu.Menuitem root_menu; public string name { get; set;} - public bool active { get; set;} public ArrayList custom_items; private MprisController mpris_adaptor; - public AppInfo app_info { get; set;} + public AppInfo? app_info { get; set;} - public PlayerController(Dbusmenu.Menuitem root, string client_name, AppInfo? info = null) + public PlayerController(Dbusmenu.Menuitem root, string client_name, int state = OFFLINE) { this.root_menu = root; this.name = format_client_name(client_name.strip()); this.custom_items = new ArrayList(); - this.app_info = info; - self_construct(); - //app_info.launch(null, null); - - // Temporary scenario to handle both v1 and v2 of MPRIS. + this.update_state(state); + construct_widgets(); + establish_mpris_connection(); + update_layout(); + } + + public void update_state(int new_state) + { + debug("update_state : new state %i", new_state); + this.current_state = new_state; + } + + public void activate() + { + debug("about to try to establish an mpris connection"); + this.establish_mpris_connection(); + this.custom_items[METADATA].property_set_bool(MENUITEM_PROP_VISIBLE, true); + } + + /* + instantiate() + The user should be able to start the app from the transport bar when in an offline state + There is a need to wait before the application is on DBus before attempting to access its mpris address + Hence only when the it has registered with us via libindicate do we attempt to kick off mpris communication + */ + public void instantiate() + { + this.app_info.launch(null, null); + this.update_state(INSTANTIATING); + } + + private void establish_mpris_connection() + { + if(this.current_state != READY){ + debug("establish_mpris_connection - Not ready to connect"); + return; + } if(this.name == "Vlc"){ this.mpris_adaptor = new MprisControllerV2(this.name, this); } else{ this.mpris_adaptor = new MprisController(this.name, this); - } - this.custom_items[TRANSPORT].set_adaptor(this.mpris_adaptor); - - // At start up if there is no metadata then hide the item. - // TODO: NOT working -> dbus menu bug ? - //((MetadataMenuitem)this.custom_items[METADATA]).check_layout(); + } + if(this.mpris_adaptor.connected() == true){ + this.custom_items[TRANSPORT].set_adaptor(this.mpris_adaptor); + this.update_state(CONNECTED); + } + else{ + this.update_state(DISCONNECTED); + } } - + public void vanish() { foreach(Dbusmenu.Menuitem item in this.custom_items){ @@ -63,21 +105,25 @@ public class PlayerController : GLib.Object } } - //public void switch_active(bool active){ - // this.is_active = active; - //} - - //public bool has_app_info(){ - // return (this.app_info != null); - //} + private void update_layout() + { + bool visibility = true; + if(this.current_state != CONNECTED){ + visibility = false; + } + this.custom_items[TRANSPORT].property_set_bool(MENUITEM_PROP_VISIBLE, visibility); + this.custom_items[METADATA].property_set_bool(MENUITEM_PROP_VISIBLE, visibility); + } + - private bool self_construct() + private void construct_widgets() { // Separator item - this.custom_items.add(PlayerItem.new_separator_item()); + this.custom_items.add(new PlayerItem(CLIENT_TYPES_SEPARATOR)); // Title item - this.custom_items.add(PlayerItem.new_title_item(this.name)); + TitleMenuitem title_menu_item = new TitleMenuitem(); + this.custom_items.add(title_menu_item); // Metadata item MetadataMenuitem metadata_item = new MetadataMenuitem(); @@ -91,7 +137,6 @@ public class PlayerController : GLib.Object foreach(PlayerItem item in this.custom_items){ root_menu.child_add_position(item, offset + this.custom_items.index_of(item)); } - return true; } private static string format_client_name(string client_name) -- cgit v1.2.3 From 410965575fa1039cbcc6c6ef7f7ef316438118ed Mon Sep 17 00:00:00 2001 From: Conor Curran Date: Wed, 7 Jul 2010 13:22:18 +0100 Subject: alot of work around the title menu stuff --- src/player-controller.vala | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) (limited to 'src/player-controller.vala') diff --git a/src/player-controller.vala b/src/player-controller.vala index dd55f3d..75c251c 100644 --- a/src/player-controller.vala +++ b/src/player-controller.vala @@ -38,7 +38,7 @@ public class PlayerController : GLib.Object private Dbusmenu.Menuitem root_menu; public string name { get; set;} public ArrayList custom_items; - private MprisController mpris_adaptor; + public MprisController mpris_adaptor; public AppInfo? app_info { get; set;} public PlayerController(Dbusmenu.Menuitem root, string client_name, int state = OFFLINE) @@ -90,7 +90,6 @@ public class PlayerController : GLib.Object this.mpris_adaptor = new MprisController(this.name, this); } if(this.mpris_adaptor.connected() == true){ - this.custom_items[TRANSPORT].set_adaptor(this.mpris_adaptor); this.update_state(CONNECTED); } else{ @@ -122,7 +121,7 @@ public class PlayerController : GLib.Object this.custom_items.add(new PlayerItem(CLIENT_TYPES_SEPARATOR)); // Title item - TitleMenuitem title_menu_item = new TitleMenuitem(); + TitleMenuitem title_menu_item = new TitleMenuitem(this, this.name); this.custom_items.add(title_menu_item); // Metadata item @@ -130,7 +129,7 @@ public class PlayerController : GLib.Object this.custom_items.add(metadata_item); // Transport item - TransportMenuitem transport_item = new TransportMenuitem(); + TransportMenuitem transport_item = new TransportMenuitem(this); this.custom_items.add(transport_item); int offset = 2; -- cgit v1.2.3 From caf13b4dccb20aff410ffc0da63c298cabbcca5f Mon Sep 17 00:00:00 2001 From: Conor Curran Date: Wed, 7 Jul 2010 13:36:56 +0100 Subject: fixed the mpris connection problems --- src/player-controller.vala | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/player-controller.vala') diff --git a/src/player-controller.vala b/src/player-controller.vala index 75c251c..88dc3a7 100644 --- a/src/player-controller.vala +++ b/src/player-controller.vala @@ -60,7 +60,6 @@ public class PlayerController : GLib.Object public void activate() { - debug("about to try to establish an mpris connection"); this.establish_mpris_connection(); this.custom_items[METADATA].property_set_bool(MENUITEM_PROP_VISIBLE, true); } @@ -95,6 +94,7 @@ public class PlayerController : GLib.Object else{ this.update_state(DISCONNECTED); } + this.update_layout(); } public void vanish() -- cgit v1.2.3 From e4f900efd1e48814a70e4351cc3d878312daef37 Mon Sep 17 00:00:00 2001 From: Conor Curran Date: Thu, 8 Jul 2010 16:12:59 +0100 Subject: event handling now plugged in crudely --- src/player-controller.vala | 1 + 1 file changed, 1 insertion(+) (limited to 'src/player-controller.vala') diff --git a/src/player-controller.vala b/src/player-controller.vala index 88dc3a7..dfbf6d3 100644 --- a/src/player-controller.vala +++ b/src/player-controller.vala @@ -110,6 +110,7 @@ public class PlayerController : GLib.Object if(this.current_state != CONNECTED){ visibility = false; } + debug("about the set the visibility on both the transport and metadata widget to %s", visibility.to_string()); this.custom_items[TRANSPORT].property_set_bool(MENUITEM_PROP_VISIBLE, visibility); this.custom_items[METADATA].property_set_bool(MENUITEM_PROP_VISIBLE, visibility); } -- cgit v1.2.3 From 0f2a6b2736713951fb4b88848e79849a8f1dc72a Mon Sep 17 00:00:00 2001 From: Conor Curran Date: Thu, 8 Jul 2010 17:47:28 +0100 Subject: constants replaced and enums and title image now fetched from the mono theme --- src/player-controller.vala | 37 ++++++++++++++++++++++--------------- 1 file changed, 22 insertions(+), 15 deletions(-) (limited to 'src/player-controller.vala') diff --git a/src/player-controller.vala b/src/player-controller.vala index dfbf6d3..3fb4750 100644 --- a/src/player-controller.vala +++ b/src/player-controller.vala @@ -26,13 +26,15 @@ public class PlayerController : GLib.Object public const int METADATA = 2; private const int TRANSPORT = 3; - public static const int OFFLINE = 0; - public static const int INSTANTIATING = 1; - public static const int READY = 2; - public static const int CONNECTED = 3; - public static const int DISCONNECTED = 4; + public enum state{ + OFFLINE, + INSTANTIATING, + READY, + CONNECTED, + DISCONNECTED + } - public int current_state = OFFLINE; + public int current_state = state.OFFLINE; private Dbusmenu.Menuitem root_menu; @@ -41,18 +43,18 @@ public class PlayerController : GLib.Object public MprisController mpris_adaptor; public AppInfo? app_info { get; set;} - public PlayerController(Dbusmenu.Menuitem root, string client_name, int state = OFFLINE) + public PlayerController(Dbusmenu.Menuitem root, string client_name, state initial_state) { this.root_menu = root; this.name = format_client_name(client_name.strip()); this.custom_items = new ArrayList(); - this.update_state(state); + this.update_state(initial_state); construct_widgets(); establish_mpris_connection(); update_layout(); } - public void update_state(int new_state) + public void update_state(state new_state) { debug("update_state : new state %i", new_state); this.current_state = new_state; @@ -72,13 +74,18 @@ public class PlayerController : GLib.Object */ public void instantiate() { - this.app_info.launch(null, null); - this.update_state(INSTANTIATING); + try{ + this.app_info.launch(null, null); + this.update_state(state.INSTANTIATING); + } + catch(GLib.Error error){ + warning("Failed to launch app %s with error message: %s", this.name, error.message); + } } private void establish_mpris_connection() { - if(this.current_state != READY){ + if(this.current_state != state.READY){ debug("establish_mpris_connection - Not ready to connect"); return; } @@ -89,10 +96,10 @@ public class PlayerController : GLib.Object this.mpris_adaptor = new MprisController(this.name, this); } if(this.mpris_adaptor.connected() == true){ - this.update_state(CONNECTED); + this.update_state(state.CONNECTED); } else{ - this.update_state(DISCONNECTED); + this.update_state(state.DISCONNECTED); } this.update_layout(); } @@ -107,7 +114,7 @@ public class PlayerController : GLib.Object private void update_layout() { bool visibility = true; - if(this.current_state != CONNECTED){ + if(this.current_state != state.CONNECTED){ visibility = false; } debug("about the set the visibility on both the transport and metadata widget to %s", visibility.to_string()); -- cgit v1.2.3