From 98c55dde34ae7ed062ae22712b998ef4787b14ee Mon Sep 17 00:00:00 2001 From: Conor Curran Date: Thu, 24 Jun 2010 14:09:49 +0100 Subject: record of played application being stored correctly in keyfile --- configure.ac | 4 ++-- src/Makefile.am | 2 +- src/familiar-players-db.vala | 9 +++++++-- src/music-player-bridge.vala | 40 ++++++++++++++++++++++------------------ src/player-item.vala | 19 +++++++++++++++++-- 5 files changed, 49 insertions(+), 25 deletions(-) diff --git a/configure.ac b/configure.ac index e55123e..781e815 100644 --- a/configure.ac +++ b/configure.ac @@ -1,10 +1,10 @@ -AC_INIT(indicator-sound, 0.3.1, conor.curran@canonical.com) +AC_INIT(indicator-sound, 0.3.2, conor.curran@canonical.com) AC_PREREQ(2.53) AM_CONFIG_HEADER(config.h) -AM_INIT_AUTOMAKE(indicator-sound, 0.3.1) +AM_INIT_AUTOMAKE(indicator-sound, 0.3.2) AM_MAINTAINER_MODE diff --git a/src/Makefile.am b/src/Makefile.am index 685ef71..e64d13d 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -64,8 +64,8 @@ music_bridge_VALAFLAGS = \ --ccode \ -H music-player-bridge.h -d . \ --library music-bridge \ + --vapidir=$(top_srcdir)/vapi/ \ --vapidir=./ \ - --vapidir=../vapi/ \ --thread \ --pkg gee-1.0 \ --pkg Indicate-0.2 \ diff --git a/src/familiar-players-db.vala b/src/familiar-players-db.vala index 5ed209b..3d7da1f 100644 --- a/src/familiar-players-db.vala +++ b/src/familiar-players-db.vala @@ -100,7 +100,6 @@ public class FamiliarPlayersDB : GLib.Object { KeyFile keyfile = new KeyFile(); string[] desktops = {}; - //Set keys = this.players_DB.keys; foreach(string key in this.players_DB.keys){ desktops += key; } @@ -133,7 +132,7 @@ public class FamiliarPlayersDB : GLib.Object return true; } - public void db_add(string desktop) + public void insert(string desktop) { if(already_familiar(desktop) == false){ if(this.write_id != 0){ @@ -149,4 +148,10 @@ public class FamiliarPlayersDB : GLib.Object { return this.players_DB.get(desktop); } + + public Gee.Set records() + { + return this.players_DB.keys; + } + } \ No newline at end of file diff --git a/src/music-player-bridge.vala b/src/music-player-bridge.vala index fb63866..02333a6 100644 --- a/src/music-player-bridge.vala +++ b/src/music-player-bridge.vala @@ -32,6 +32,7 @@ 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,30 +43,20 @@ public class MusicPlayerBridge : GLib.Object listener.server_count_changed.connect(on_server_count_changed); } - public void set_root_menu_item(Dbusmenu.Menuitem menu) - { - root_menu = menu; - } - -//static void -//desktop_cb (IndicateListener * listener, IndicateListenerServer * server, gchar * value, gpointer data) - - public void desktop_info_callback(Indicate.Listener listener, - Indicate.ListenerServer server, - owned string value, void* data) - { - + private void try_to_add_inactive_familiar_clients(){ + //foreach(string app in this.playersDB.records()){ + // + //} } 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; - string client_name = type.split(".")[1]; - listener_get_server_property_cb cb = (listener_get_server_property_cb)desktop_info_callback; - this.listener.server_get_desktop(object, cb); - + 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); @@ -93,7 +84,20 @@ public class MusicPlayerBridge : GLib.Object return false; } - public void on_server_count_changed(Indicate.ListenerServer object, uint i) + 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); + } + + public void set_root_menu_item(Dbusmenu.Menuitem menu) + { + root_menu = menu; + } + + public void on_server_count_changed(Indicate.ListenerServer object, uint i) { debug("MusicPlayerBridge-> on_server_count_changed with value %u", i); } diff --git a/src/player-item.vala b/src/player-item.vala index 09b0e6b..d1cf08c 100644 --- a/src/player-item.vala +++ b/src/player-item.vala @@ -28,17 +28,32 @@ public class PlayerItem : Dbusmenu.Menuitem { } + 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"); + return; + } foreach(string property in attributes){ 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); - if (v.holds (typeof (string))){ + debug("with value : %s", v.get_string()); this.property_set(property, this.sanitize_string(v.get_string())); } else if (v.holds (typeof (int))){ -- cgit v1.2.3