From 81d9af3fc3f1d3784e623ede592e6d91032353ad Mon Sep 17 00:00:00 2001 From: Conor Curran Date: Thu, 24 Jun 2010 17:23:39 +0100 Subject: moving towards offline application launching --- src/Makefile.am | 3 ++- src/familiar-players-db.vala | 9 +++------ src/metadata-menu-item.vala | 11 +++++++++++ src/music-player-bridge.vala | 35 +++++++++++++++++++++++++++++------ src/player-controller.vala | 14 ++++++-------- src/player-item.vala | 31 ++++++++++++++++++------------- src/sound-service.c | 4 ++-- src/transport-menu-item.vala | 5 +++++ 8 files changed, 76 insertions(+), 36 deletions(-) diff --git a/src/Makefile.am b/src/Makefile.am index e64d13d..8805ff9 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -71,7 +71,8 @@ music_bridge_VALAFLAGS = \ --pkg Indicate-0.2 \ --pkg Dbusmenu-Glib-0.2 \ --pkg common-defs \ - --pkg dbus-glib-1 + --pkg dbus-glib-1 \ + --pkg gio-unix-2.0 $(MAINTAINER_VALAFLAGS) diff --git a/src/familiar-players-db.vala b/src/familiar-players-db.vala index 3d7da1f..88bc01f 100644 --- a/src/familiar-players-db.vala +++ b/src/familiar-players-db.vala @@ -78,15 +78,12 @@ public class FamiliarPlayersDB : GLib.Object return false; } - private bool load_data_from_key_file() - { + private bool load_data_from_key_file(){ try{ string[] desktops = this.key_file.get_string_list(GROUP_NAME, KEY_NAME); - - int i = 0; - while (desktops[i] != null) { - this.players_DB.set(desktops[i], true); + foreach(string s in desktops){ + this.players_DB.set(s, true); } return true; } diff --git a/src/metadata-menu-item.vala b/src/metadata-menu-item.vala index f62cd46..541fbf4 100644 --- a/src/metadata-menu-item.vala +++ b/src/metadata-menu-item.vala @@ -37,5 +37,16 @@ public class MetadataMenuitem : PlayerItem attrs.add(MENUITEM_ARTURL); return attrs; } + + public override void check_layout(){ + this.property_set_bool(MENUITEM_PROP_VISIBLE, this.populated()); + debug("check layout for the metadata = %s", this.populated().to_string()); + } + + public bool populated() + { + return (this.property_get(MENUITEM_TEXT_TITLE) != null && + this.property_get(MENUITEM_TEXT_TITLE) != ""); + } } \ No newline at end of file diff --git a/src/music-player-bridge.vala b/src/music-player-bridge.vala index 02333a6..6fc9032 100644 --- a/src/music-player-bridge.vala +++ b/src/music-player-bridge.vala @@ -20,6 +20,7 @@ with this program. If not, see . using Indicate; using Dbusmenu; using Gee; +using GLib; public class MusicPlayerBridge : GLib.Object { @@ -32,7 +33,6 @@ public class MusicPlayerBridge : GLib.Object public MusicPlayerBridge() { playersDB = new FamiliarPlayersDB(); - try_to_add_inactive_familiar_clients(); registered_clients = new HashMap (); listener = Listener.ref_default(); listener.indicator_added.connect(on_indicator_added); @@ -42,11 +42,33 @@ 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(){ - //foreach(string app in this.playersDB.records()){ - // - //} + // 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); + string[] bits = app.split("/"); + + 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_name); + string desc = info.get_display_name(); + debug("description from app %s", desc); + count += 1; + } + catch(Error er){ + warning("desktop path in cache is not formatted as we have anticipated"); + } + } + break; + } } public void on_server_added(Indicate.ListenerServer object, string type) @@ -94,7 +116,8 @@ public class MusicPlayerBridge : GLib.Object public void set_root_menu_item(Dbusmenu.Menuitem menu) { - root_menu = menu; + this.root_menu = menu; + //try_to_add_inactive_familiar_clients(); } public void on_server_count_changed(Indicate.ListenerServer object, uint i) diff --git a/src/player-controller.vala b/src/player-controller.vala index 862bb29..0d8dc01 100644 --- a/src/player-controller.vala +++ b/src/player-controller.vala @@ -31,7 +31,8 @@ public class PlayerController : GLib.Object private bool is_active; public ArrayList custom_items; private MprisController mpris_adaptor; - + private string desktop_path; + public PlayerController(Dbusmenu.Menuitem root, string client_name, bool active) { this.root_menu = root; @@ -48,6 +49,10 @@ public class PlayerController : GLib.Object 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(); } public void vanish() @@ -80,13 +85,6 @@ public class PlayerController : GLib.Object return true; } - //public void update_playing_info(HashMap data) - //{ - // debug("PlayerController - update_playing_info"); - // MetadataMenuitem item = this.custom_items[METADATA] as MetadataMenuitem; - // item.update(data, MetadataMenuitem.attributes_format()); - //} - private static string format_client_name(string client_name) { string formatted = client_name; diff --git a/src/player-item.vala b/src/player-item.vala index d1cf08c..7fcf912 100644 --- a/src/player-item.vala +++ b/src/player-item.vala @@ -27,24 +27,12 @@ public class PlayerItem : Dbusmenu.Menuitem public PlayerItem() { } - - private static bool ensure_valid_updates(HashTable data, HashSet attributes) - { - if(data == null){ - return false; - } - if(data.size() < attributes.size){ - warning("update hash was too small for the target"); - return false; - } - return true; - } public void update(HashTable data, HashSet attributes) { debug("PlayerItem::update()"); if(ensure_valid_updates(data, attributes) == false){ - debug("PlayerItem::Update -> update hash is not what we were expecting"); + debug("PlayerItem::Update -> The hashtable update does not contain what we were expecting - just leave it!"); return; } foreach(string property in attributes){ @@ -64,6 +52,8 @@ public class PlayerItem : Dbusmenu.Menuitem this.property_set_bool(property, v.get_boolean()); } } + // TODO: not working + //this.check_layout(); } public void set_adaptor(MprisController adaptor) @@ -71,6 +61,17 @@ public class PlayerItem : Dbusmenu.Menuitem this.mpris_adaptor = adaptor; } + private static bool ensure_valid_updates(HashTable data, HashSet attributes) + { + if(data == null){ + return false; + } + if(data.size() < attributes.size){ + warning("update hash was too small for the target"); + return false; + } + return true; + } public static string sanitize_string(string st) { @@ -100,5 +101,9 @@ public class PlayerItem : Dbusmenu.Menuitem separator.property_set(MENUITEM_PROP_TYPE, CLIENT_TYPES_SEPARATOR); return separator; } + + public virtual void check_layout(){ + warning("this should not be hit"); + } } diff --git a/src/sound-service.c b/src/sound-service.c index ea04e4b..bcdac07 100644 --- a/src/sound-service.c +++ b/src/sound-service.c @@ -45,8 +45,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; } diff --git a/src/transport-menu-item.vala b/src/transport-menu-item.vala index 39a0cab..264e153 100644 --- a/src/transport-menu-item.vala +++ b/src/transport-menu-item.vala @@ -41,6 +41,11 @@ public class TransportMenuitem : PlayerItem this.mpris_adaptor.toggle_playback(input_value.get_boolean()); } + public override void check_layout(){ + // nothing to be done for this item - always active + } + + public static HashSet attributes_format() { HashSet attrs = new HashSet(); -- cgit v1.2.3