aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorConor Curran <conor.curran@canonical.com>2010-06-24 18:16:23 +0100
committerConor Curran <conor.curran@canonical.com>2010-06-24 18:16:23 +0100
commit0336970086fb3bbd00b3a906e9879f4a50ae015c (patch)
tree5a567be23e2f1dcf6bfdbda4d8b461fd8314e41c /src
parent49db751d456ee144f7c7910278b35613dc90db8a (diff)
parent1d721c275ba6962d60f47b184849db7bd2a5290a (diff)
downloadayatana-indicator-sound-0336970086fb3bbd00b3a906e9879f4a50ae015c.tar.gz
ayatana-indicator-sound-0336970086fb3bbd00b3a906e9879f4a50ae015c.tar.bz2
ayatana-indicator-sound-0336970086fb3bbd00b3a906e9879f4a50ae015c.zip
merge the familiar players db work
Diffstat (limited to 'src')
-rw-r--r--src/Makefile.am8
-rw-r--r--src/familiar-players-db.vala154
-rw-r--r--src/metadata-menu-item.vala11
-rw-r--r--src/music-player-bridge.vala90
-rw-r--r--src/player-controller.vala14
-rw-r--r--src/player-item.vala26
-rw-r--r--src/transport-menu-item.vala5
7 files changed, 269 insertions, 39 deletions
diff --git a/src/Makefile.am b/src/Makefile.am
index 8e7bc94..b33107d 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -57,20 +57,22 @@ music_bridge_VALASOURCES = \
player-controller.vala \
mpris-controller-v2.vala \
mpris-controller.vala \
- player-item.vala
+ player-item.vala \
+ familiar-players-db.vala
music_bridge_VALAFLAGS = \
--ccode \
-H music-player-bridge.h -d . \
- --vapidir=./ \
--vapidir=$(top_srcdir)/vapi/ \
+ --vapidir=./ \
--thread \
--pkg gee-1.0 \
--pkg Indicate-0.2 \
--pkg Dbusmenu-Glib-0.2 \
--pkg common-defs \
--pkg dbus-glib-1 \
- $(MAINTAINER_VALAFLAGS)
+ --pkg gio-unix-2.0
+ $(MAINTAINER_VALAFLAGS)
music_bridge_APIFILES = \
music-player-bridge.h
diff --git a/src/familiar-players-db.vala b/src/familiar-players-db.vala
new file mode 100644
index 0000000..88bc01f
--- /dev/null
+++ b/src/familiar-players-db.vala
@@ -0,0 +1,154 @@
+/*
+Copyright 2010 Canonical Ltd.
+
+Authors:
+ Conor Curran <conor.curran@canonical.com>
+
+This program is free software: you can redistribute it and/or modify it
+under the terms of the GNU General Public License version 3, as published
+by the Free Software Foundation.
+
+This program is distributed in the hope that it will be useful, but
+WITHOUT ANY WARRANTY; without even the implied warranties of
+MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR
+PURPOSE. See the GNU General Public License for more details.
+
+You should have received a copy of the GNU General Public License along
+with this program. If not, see <http://www.gnu.org/licenses/>.
+*/
+
+using Gee;
+using GLib.Path;
+using GLib.DirUtils;
+using GLib.FileUtils;
+using GLib.Timeout;
+using GLib.Environment;
+
+// TODO: more refactoring needed here
+public class FamiliarPlayersDB : GLib.Object
+{
+ private const string GROUP_NAME = "Seen Database";
+ private const string KEY_NAME = "DesktopFiles";
+ private HashMap<string, bool> players_DB;
+ private string file_name;
+ private string dir_name;
+ private KeyFile key_file;
+ private uint write_id;
+
+ public FamiliarPlayersDB()
+ {
+ this.write_id = 0;
+ this.players_DB = new HashMap<string, bool>();
+ this.dir_name = build_filename(get_user_cache_dir(), "indicators", "sound");
+ this.file_name = build_filename(this.dir_name, "familiar-players-db.keyfile");
+ if(create_key_file() && check_for_keys() && load_data_from_key_file()){
+ debug("keyfiles in place and ready for action");
+ }
+ else{
+ this.key_file = null;
+ warning("FamiliarPlayersDB:: problems loading key file - can't go any further");
+ }
+ }
+
+ private bool create_key_file(){
+ if (test(this.file_name, GLib.FileTest.EXISTS)) {
+ this.key_file = new KeyFile();
+ try{
+ if (this.key_file.load_from_file(this.file_name, KeyFileFlags.NONE) == true) {
+ return true;
+ }
+ }
+ catch(FileError e){
+ warning("FamiliarPlayersDB - error trying to load KeyFile");
+ }
+ }
+ return false;
+ }
+
+ private bool check_for_keys(){
+ try{
+ if(this.key_file.has_key(GROUP_NAME, KEY_NAME) == true){
+ return true;
+ }
+ }
+ catch(KeyFileError e){
+ return false;
+ }
+ warning("Seen DB '%s' does not have key '%s' in group '%s'", this.file_name, KEY_NAME, GROUP_NAME);
+ return false;
+ }
+
+ private bool load_data_from_key_file(){
+ try{
+ string[] desktops = this.key_file.get_string_list(GROUP_NAME,
+ KEY_NAME);
+ foreach(string s in desktops){
+ this.players_DB.set(s, true);
+ }
+ return true;
+ }
+ catch(FileError error){
+ warning("Error loading the Desktop string list");
+ return false;
+ }
+ }
+
+ private bool write_db()
+ {
+ KeyFile keyfile = new KeyFile();
+ string[] desktops = {};
+ foreach(string key in this.players_DB.keys){
+ desktops += key;
+ }
+ keyfile.set_string_list(GROUP_NAME,
+ KEY_NAME,
+ desktops);
+ size_t data_length;
+ string data = null;
+ try{
+ data = keyfile.to_data(out data_length);
+ }
+ catch(Error e){
+ warning("Problems dumping keyfile to a string");
+ return false;
+ }
+
+ if(create_with_parents(this.dir_name, 0700) != 0){
+ warning("Unable to make directory: %s", this.dir_name);
+ return false;
+ }
+
+ try{
+ if(set_contents(this.file_name, data, (ssize_t)data_length) == false){
+ warning("Unable to write out file '%s'", this.file_name);
+ }
+ }
+ catch(FileError err){
+ warning("Unable to write out file '%s'", this.file_name);
+ }
+ return true;
+ }
+
+ public void insert(string desktop)
+ {
+ if(already_familiar(desktop) == false){
+ if(this.write_id != 0){
+ Source.remove(this.write_id);
+ this.write_id = 0;
+ }
+ this.write_id = Timeout.add_seconds(60, write_db);
+ this.players_DB.set(desktop.dup(), true);
+ }
+ }
+
+ public bool already_familiar(string desktop)
+ {
+ return this.players_DB.get(desktop);
+ }
+
+ public Gee.Set<string> records()
+ {
+ return this.players_DB.keys;
+ }
+
+} \ No newline at end of file
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 b03ecbd..6fc9032 100644
--- a/src/music-player-bridge.vala
+++ b/src/music-player-bridge.vala
@@ -1,5 +1,4 @@
/*
-This service primarily controls PulseAudio and is driven by the sound indicator menu on the panel.
Copyright 2010 Canonical Ltd.
Authors:
@@ -21,6 +20,7 @@ with this program. If not, see <http://www.gnu.org/licenses/>.
using Indicate;
using Dbusmenu;
using Gee;
+using GLib;
public class MusicPlayerBridge : GLib.Object
{
@@ -28,9 +28,11 @@ public class MusicPlayerBridge : GLib.Object
private Listener listener;
private Dbusmenu.Menuitem root_menu;
private HashMap<string, PlayerController> registered_clients;
+ private FamiliarPlayersDB playersDB;
public MusicPlayerBridge()
{
+ playersDB = new FamiliarPlayersDB();
registered_clients = new HashMap<string, PlayerController> ();
listener = Listener.ref_default();
listener.indicator_added.connect(on_indicator_added);
@@ -40,33 +42,43 @@ public class MusicPlayerBridge : GLib.Object
listener.server_removed.connect(on_server_removed);
listener.server_count_changed.connect(on_server_count_changed);
}
-
- public void set_root_menu_item(Dbusmenu.Menuitem menu)
- {
- root_menu = menu;
- }
-
- public void on_indicator_added(Indicate.ListenerServer object, Indicate.ListenerIndicator p0)
- {
- debug("MusicPlayerBridge-> on_indicator_added");
- }
-
- public void on_indicator_removed(Indicate.ListenerServer object, Indicate.ListenerIndicator p0)
- {
- debug("MusicPlayerBridge -> on_indicator_removed");
- }
-
- public void on_indicator_modified(Indicate.ListenerServer object, Indicate.ListenerIndicator p0, string s)
- {
- debug("MusicPlayerBridge -> indicator_modified with vale %s", s );
- }
-
- public void on_server_added(Indicate.ListenerServer object, string type)
+ // 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);
+ 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)
{
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);
@@ -94,10 +106,38 @@ 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)
+ {
+ this.root_menu = menu;
+ //try_to_add_inactive_familiar_clients();
+ }
+
+ public void on_server_count_changed(Indicate.ListenerServer object, uint i)
{
debug("MusicPlayerBridge-> on_server_count_changed with value %u", i);
}
+ public void on_indicator_added(Indicate.ListenerServer object, Indicate.ListenerIndicator p0)
+ {
+ debug("MusicPlayerBridge-> on_indicator_added");
+ }
+
+ public void on_indicator_removed(Indicate.ListenerServer object, Indicate.ListenerIndicator p0)
+ {
+ debug("MusicPlayerBridge -> on_indicator_removed");
+ }
+
+ public void on_indicator_modified(Indicate.ListenerServer object, Indicate.ListenerIndicator p0, string s)
+ {
+ debug("MusicPlayerBridge -> indicator_modified with vale %s", s );
+ }
}
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<PlayerItem> 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<string, string> 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 09b0e6b..7fcf912 100644
--- a/src/player-item.vala
+++ b/src/player-item.vala
@@ -27,18 +27,21 @@ public class PlayerItem : Dbusmenu.Menuitem
public PlayerItem()
{
}
-
+
public void update(HashTable<string, Value?> data, HashSet<string> attributes)
{
debug("PlayerItem::update()");
+ if(ensure_valid_updates(data, attributes) == false){
+ debug("PlayerItem::Update -> The hashtable update does not contain what we were expecting - just leave it!");
+ 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))){
@@ -49,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)
@@ -56,6 +61,17 @@ public class PlayerItem : Dbusmenu.Menuitem
this.mpris_adaptor = adaptor;
}
+ private static bool ensure_valid_updates(HashTable<string, Value?> data, HashSet<string> 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)
{
@@ -85,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/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<string> attributes_format()
{
HashSet<string> attrs = new HashSet<string>();