From 2d1c2058a7384a6dc0d4c1b900e223b6905df4c6 Mon Sep 17 00:00:00 2001 From: Conor Curran Date: Tue, 29 Jun 2010 21:52:56 +0100 Subject: launching apps now working --- src/music-player-bridge.vala | 35 ++++++++++++++++++++++++++--------- 1 file changed, 26 insertions(+), 9 deletions(-) (limited to 'src/music-player-bridge.vala') diff --git a/src/music-player-bridge.vala b/src/music-player-bridge.vala index 6fc9032..07eef2a 100644 --- a/src/music-player-bridge.vala +++ b/src/music-player-bridge.vala @@ -42,15 +42,22 @@ public class MusicPlayerBridge : GLib.Object listener.server_removed.connect(on_server_removed); listener.server_count_changed.connect(on_server_count_changed); } - // Alpha 2 not in use ... yet. + private void try_to_add_inactive_familiar_clients(){ // for now just use one of the entries. int count = 0; foreach(string app in this.playersDB.records()){ if(count == 0){ debug("we have found %s", app); + if(app == null){ + debug("moving on to next player"); + continue; + } string[] bits = app.split("/"); - + if(bits.length < 2){ + continue; + } + debug("trying to dig deeper %s", app); try{ string app_name = bits[bits.length -1].split(".")[0]; debug("we have found %s", app_name); @@ -58,9 +65,11 @@ public class MusicPlayerBridge : GLib.Object app_name, false); this.registered_clients.set(app_name, ctrl); - DesktopAppInfo info = new DesktopAppInfo.from_filename(app_name); - string desc = info.get_display_name(); - debug("description from app %s", desc); + DesktopAppInfo info = new DesktopAppInfo.from_filename(app); + GLib.AppInfo app_info = info as GLib.AppInfo; + + debug("Display name = %s", app_info.get_display_name()); + app_info.launch(null, null); count += 1; } catch(Error er){ @@ -93,7 +102,8 @@ public class MusicPlayerBridge : GLib.Object if (root_menu != null && client_name != null){ registered_clients[client_name].vanish(); registered_clients.remove(client_name); - debug("Successively removed menu_item for client %s from registered_clients", client_name); + debug("Successively removed menu_item for client %s from registered_clients", + client_name); } } @@ -109,15 +119,22 @@ public class MusicPlayerBridge : GLib.Object private void desktop_info_callback(Indicate.ListenerServer server, owned string path, void* data) { - debug("we got a desktop file path hopefully: %s", path); MusicPlayerBridge bridge = data as MusicPlayerBridge; - bridge.playersDB.insert(path); + // Not the most secure validation + // TODO revisit validation mechanism + if(path.contains("/")){ + debug("About to store desktop file path: %s", path); + bridge.playersDB.insert(path); + } + else{ + debug("Ignoring desktop file path: %s", path); + } } public void set_root_menu_item(Dbusmenu.Menuitem menu) { this.root_menu = menu; - //try_to_add_inactive_familiar_clients(); + try_to_add_inactive_familiar_clients(); } public void on_server_count_changed(Indicate.ListenerServer object, uint i) -- cgit v1.2.3 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/music-player-bridge.vala | 74 ++++++++++++++++++++++++++++---------------- 1 file changed, 48 insertions(+), 26 deletions(-) (limited to 'src/music-player-bridge.vala') diff --git a/src/music-player-bridge.vala b/src/music-player-bridge.vala index 07eef2a..84bf3df 100644 --- a/src/music-player-bridge.vala +++ b/src/music-player-bridge.vala @@ -44,32 +44,26 @@ public class MusicPlayerBridge : GLib.Object } private void try_to_add_inactive_familiar_clients(){ - // for now just use one of the entries. int count = 0; foreach(string app in this.playersDB.records()){ if(count == 0){ - debug("we have found %s", app); if(app == null){ - debug("moving on to next player"); + warning("App string in keyfile is null therefore moving on to next player"); continue; } - string[] bits = app.split("/"); - if(bits.length < 2){ - continue; - } - debug("trying to dig deeper %s", app); try{ - string app_name = bits[bits.length -1].split(".")[0]; - debug("we have found %s", app_name); - PlayerController ctrl = new PlayerController(this.root_menu, - app_name, - false); - this.registered_clients.set(app_name, ctrl); DesktopAppInfo info = new DesktopAppInfo.from_filename(app); + if(info == null){ + warning("Could not create a desktopappinfo instance from app: %s", app); + continue; + } GLib.AppInfo app_info = info as GLib.AppInfo; - - debug("Display name = %s", app_info.get_display_name()); - app_info.launch(null, null); + PlayerController ctrl = new PlayerController(this.root_menu, + app_info.get_name(), + app_info); + ctrl.set("active", false); + this.registered_clients.set(app_info.get_name().down().strip(), ctrl); + debug("Created a player controller for %s which was found in the cache file", app_info.get_name().down().strip()); count += 1; } catch(Error er){ @@ -84,13 +78,24 @@ public class MusicPlayerBridge : GLib.Object { debug("MusicPlayerBridge -> on_server_added with value %s", type); if(server_is_not_of_interest(type)) return; - string client_name = type.split(".")[1]; + string client_name = type.split(".")[1]; if (root_menu != null && client_name != null){ - listener_get_server_property_cb cb = (listener_get_server_property_cb)desktop_info_callback; - this.listener.server_get_desktop(object, cb, this); - PlayerController ctrl = new PlayerController(root_menu, client_name, true); - registered_clients.set(client_name, ctrl); - debug("client of name %s has successfully registered with us", client_name); + // If we have an instance already for this player, ensure it is switched to active + if(this.registered_clients.keys.contains(client_name)){ + debug("It figured out that it already has an instance for this player already"); + this.registered_clients[client_name].set("active", true); + } + //else init a new one + else{ + PlayerController ctrl = new PlayerController(root_menu, client_name); + registered_clients.set(client_name, ctrl); + debug("New Client of name %s has successfully registered with us", client_name); + } + // irregardless check that it has a desktop file if not kick off a request for it + if(this.registered_clients[client_name].app_info == null){ + listener_get_server_property_cb cb = (listener_get_server_property_cb)desktop_info_callback; + this.listener.server_get_desktop(object, cb, this); + } } } @@ -122,12 +127,18 @@ public class MusicPlayerBridge : GLib.Object MusicPlayerBridge bridge = data as MusicPlayerBridge; // Not the most secure validation // TODO revisit validation mechanism - if(path.contains("/")){ - debug("About to store desktop file path: %s", path); + if(path.contains("/") && bridge.playersDB.already_familiar(path) == false){ + debug("About to store desktop file path: %s", path); bridge.playersDB.insert(path); + AppInfo? app_info = create_app_info(path); + if(app_info != null){ + PlayerController ctrl = bridge.registered_clients[app_info.get_name().down().strip()]; + ctrl.set("app_info", app_info); + debug("successfully created appinfo from path and set it on the respective instance"); + } } else{ - debug("Ignoring desktop file path: %s", path); + debug("Ignoring desktop file path because its either invalid of the db cache file has it already: %s", path); } } @@ -156,6 +167,17 @@ public class MusicPlayerBridge : GLib.Object debug("MusicPlayerBridge -> indicator_modified with vale %s", s ); } + 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); + return null; + } + GLib.AppInfo app_info = info as GLib.AppInfo; + return app_info; + } + } -- 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/music-player-bridge.vala | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) (limited to 'src/music-player-bridge.vala') diff --git a/src/music-player-bridge.vala b/src/music-player-bridge.vala index 84bf3df..77341a4 100644 --- a/src/music-player-bridge.vala +++ b/src/music-player-bridge.vala @@ -44,6 +44,7 @@ public class MusicPlayerBridge : GLib.Object } private void try_to_add_inactive_familiar_clients(){ + // TODO handle multple players - just working with one right now int count = 0; foreach(string app in this.playersDB.records()){ if(count == 0){ @@ -59,9 +60,9 @@ public class MusicPlayerBridge : GLib.Object } GLib.AppInfo app_info = info as GLib.AppInfo; PlayerController ctrl = new PlayerController(this.root_menu, - app_info.get_name(), - app_info); - ctrl.set("active", false); + app_info.get_name(), + PlayerController.OFFLINE); + ctrl.set("app_info", app_info); this.registered_clients.set(app_info.get_name().down().strip(), ctrl); debug("Created a player controller for %s which was found in the cache file", app_info.get_name().down().strip()); count += 1; @@ -83,11 +84,11 @@ public class MusicPlayerBridge : GLib.Object // If we have an instance already for this player, ensure it is switched to active if(this.registered_clients.keys.contains(client_name)){ debug("It figured out that it already has an instance for this player already"); - this.registered_clients[client_name].set("active", true); + this.registered_clients[client_name].activate(); } //else init a new one else{ - PlayerController ctrl = new PlayerController(root_menu, client_name); + PlayerController ctrl = new PlayerController(root_menu, client_name, PlayerController.READY); registered_clients.set(client_name, ctrl); debug("New Client of name %s has successfully registered with us", client_name); } @@ -125,14 +126,12 @@ public class MusicPlayerBridge : GLib.Object owned string path, void* data) { MusicPlayerBridge bridge = data as MusicPlayerBridge; - // Not the most secure validation - // TODO revisit validation mechanism if(path.contains("/") && bridge.playersDB.already_familiar(path) == false){ debug("About to store desktop file path: %s", path); bridge.playersDB.insert(path); AppInfo? app_info = create_app_info(path); if(app_info != null){ - PlayerController ctrl = bridge.registered_clients[app_info.get_name().down().strip()]; + PlayerController ctrl = bridge.registered_clients[app_info.get_name().down().strip()]; ctrl.set("app_info", app_info); debug("successfully created appinfo from path and set it on the respective instance"); } @@ -169,7 +168,7 @@ public class MusicPlayerBridge : GLib.Object public static AppInfo? create_app_info(string path) { - DesktopAppInfo info = new DesktopAppInfo.from_filename(path); + DesktopAppInfo info = new DesktopAppInfo.from_filename(path); if(path == null){ warning("Could not create a desktopappinfo instance from app: %s", path); return null; -- 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/music-player-bridge.vala | 1 + 1 file changed, 1 insertion(+) (limited to 'src/music-player-bridge.vala') diff --git a/src/music-player-bridge.vala b/src/music-player-bridge.vala index 77341a4..46723cb 100644 --- a/src/music-player-bridge.vala +++ b/src/music-player-bridge.vala @@ -84,6 +84,7 @@ public class MusicPlayerBridge : GLib.Object // If we have an instance already for this player, ensure it is switched to active if(this.registered_clients.keys.contains(client_name)){ debug("It figured out that it already has an instance for this player already"); + this.registered_clients[client_name].update_state(PlayerController.READY); this.registered_clients[client_name].activate(); } //else init a new one -- 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/music-player-bridge.vala | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'src/music-player-bridge.vala') diff --git a/src/music-player-bridge.vala b/src/music-player-bridge.vala index 46723cb..d771192 100644 --- a/src/music-player-bridge.vala +++ b/src/music-player-bridge.vala @@ -61,7 +61,7 @@ public class MusicPlayerBridge : GLib.Object GLib.AppInfo app_info = info as GLib.AppInfo; PlayerController ctrl = new PlayerController(this.root_menu, app_info.get_name(), - PlayerController.OFFLINE); + PlayerController.state.OFFLINE); ctrl.set("app_info", app_info); this.registered_clients.set(app_info.get_name().down().strip(), ctrl); debug("Created a player controller for %s which was found in the cache file", app_info.get_name().down().strip()); @@ -84,12 +84,12 @@ public class MusicPlayerBridge : GLib.Object // If we have an instance already for this player, ensure it is switched to active if(this.registered_clients.keys.contains(client_name)){ debug("It figured out that it already has an instance for this player already"); - this.registered_clients[client_name].update_state(PlayerController.READY); + this.registered_clients[client_name].update_state(PlayerController.state.READY); this.registered_clients[client_name].activate(); } //else init a new one else{ - PlayerController ctrl = new PlayerController(root_menu, client_name, PlayerController.READY); + PlayerController ctrl = new PlayerController(root_menu, client_name, PlayerController.state.READY); registered_clients.set(client_name, ctrl); debug("New Client of name %s has successfully registered with us", client_name); } -- cgit v1.2.3