From 2a35f9b78b75cd95090142b891c401a46eec9bf3 Mon Sep 17 00:00:00 2001 From: Conor Curran Date: Mon, 13 Dec 2010 17:46:42 +0000 Subject: started along the road of removing the familiar db backend and replacing with the g-settings entry approach --- src/familiar-players-db.vala | 24 ------------- src/metadata-menu-item.vala | 6 ++-- src/metadata-widget.c | 10 +++--- src/mpris2-controller.vala | 12 +++---- src/mpris2-watcher.vala | 16 ++++----- src/music-player-bridge.vala | 84 +++++++++++++++++++++++++++----------------- src/player-controller.vala | 14 ++++---- src/sound-service.c | 4 +-- 8 files changed, 84 insertions(+), 86 deletions(-) diff --git a/src/familiar-players-db.vala b/src/familiar-players-db.vala index 7012b5a..96d690a 100644 --- a/src/familiar-players-db.vala +++ b/src/familiar-players-db.vala @@ -160,29 +160,5 @@ public class FamiliarPlayersDB : GLib.Object return this.players_DB.keys; } - public static string? fetch_icon_name(string desktop_path) - { - KeyFile desktop_keyfile = new KeyFile (); - try{ - desktop_keyfile.load_from_file (desktop_path, KeyFileFlags.NONE); - } - catch(GLib.FileError error){ - warning("Error loading keyfile - FileError"); - return null; - } - catch(GLib.KeyFileError error){ - warning("Error loading keyfile - KeyFileError"); - return null; - } - - try{ - return desktop_keyfile.get_string (KeyFileDesktop.GROUP, - KeyFileDesktop.KEY_ICON); - } - catch(GLib.KeyFileError error){ - warning("Error trying to fetch the icon name from the keyfile"); - return null; - } - } } \ No newline at end of file diff --git a/src/metadata-menu-item.vala b/src/metadata-menu-item.vala index e84e902..741bb9f 100644 --- a/src/metadata-menu-item.vala +++ b/src/metadata-menu-item.vala @@ -99,10 +99,10 @@ public class MetadataMenuitem : PlayerItem { File art_file = File.new_for_uri(uri); if(art_file.is_native() == true){ - string path; + string path; try{ - path = Filename.from_uri(uri.strip()); - this.property_set(prop, path); + path = Filename.from_uri ( uri.strip() ); + this.property_set ( prop, path ); } catch(ConvertError e){ warning("Problem converting URI %s to file path", diff --git a/src/metadata-widget.c b/src/metadata-widget.c index 1e2c891..191e134 100644 --- a/src/metadata-widget.c +++ b/src/metadata-widget.c @@ -194,21 +194,23 @@ metadata_image_expose (GtkWidget *metadata, GdkEventExpose *event, gpointer user if(g_string_equal(priv->image_path, priv->old_image_path) == FALSE || priv->theme_change_occured == TRUE){ priv->theme_change_occured = FALSE; - GdkPixbuf* pixbuf; - pixbuf = gdk_pixbuf_new_from_file(priv->image_path->str, NULL); + GdkPixbuf* orig_pixbuf; + orig_pixbuf = gdk_pixbuf_new_from_file(priv->image_path->str, NULL); //g_debug("metadata_load_new_image -> pixbuf from %s", // priv->image_path->str); - if(GDK_IS_PIXBUF(pixbuf) == FALSE){ + if(GDK_IS_PIXBUF(orig_pixbuf) == FALSE){ //g_debug("problem loading the downloaded image just use the placeholder instead"); draw_album_art_placeholder(metadata); return TRUE; } - pixbuf = gdk_pixbuf_scale_simple(pixbuf,60, 60, GDK_INTERP_BILINEAR); + GdkPixbuf* pixbuf; + pixbuf = gdk_pixbuf_scale_simple(orig_pixbuf,60, 60, GDK_INTERP_BILINEAR); gtk_image_set_from_pixbuf(GTK_IMAGE(priv->album_art), pixbuf); g_string_erase(priv->old_image_path, 0, -1); g_string_overwrite(priv->old_image_path, 0, priv->image_path->str); g_object_unref(pixbuf); + g_object_unref(orig_pixbuf); } return FALSE; } diff --git a/src/mpris2-controller.vala b/src/mpris2-controller.vala index 59e3122..42d08c9 100644 --- a/src/mpris2-controller.vala +++ b/src/mpris2-controller.vala @@ -31,7 +31,6 @@ using Dbusmenu; */ public class Mpris2Controller : GLib.Object { - public static const string root_interface = "org.mpris.MediaPlayer2" ; public MprisRoot mpris2_root {get; construct;} public MprisPlayer player {get; construct;} public FreeDesktopProperties properties_interface {get; construct;} @@ -46,16 +45,16 @@ public class Mpris2Controller : GLib.Object construct{ try { this.mpris2_root = Bus.get_proxy_sync ( BusType.SESSION, - root_interface.concat(".").concat(this.owner.mpris_name), + this.owner.dbus_name, "/org/mpris/MediaPlayer2"); this.player = Bus.get_proxy_sync ( BusType.SESSION, - root_interface.concat(".").concat(this.owner.mpris_name), + this.owner.dbus_name, "/org/mpris/MediaPlayer2" ); this.properties_interface = Bus.get_proxy_sync ( BusType.SESSION, "org.freedesktop.Properties.PropertiesChanged", "/org/mpris/MediaPlayer2" ); - this.properties_interface.PropertiesChanged += property_changed_cb; + this.properties_interface.PropertiesChanged.connect ( property_changed_cb ); } catch (IOError e) { error("Problems connecting to the session bus - %s", e.message); @@ -66,8 +65,9 @@ public class Mpris2Controller : GLib.Object HashTable changed_properties, string[] invalid ) { - debug("properties-changed for interface %s and owner %s", interface_source, this.owner.mpris_name); - if(changed_properties == null || interface_source.has_prefix(this.root_interface) == false ){ + debug("properties-changed for interface %s and owner %s", interface_source, this.owner.dbus_name); + if ( changed_properties == null || + interface_source.has_prefix ( Mpris2Watcher.MPRIS_PREFIX ) == false ){ warning("Property-changed hash is null or this is an interface that doesn't concerns us"); return; } diff --git a/src/mpris2-watcher.vala b/src/mpris2-watcher.vala index d154fcb..7814975 100644 --- a/src/mpris2-watcher.vala +++ b/src/mpris2-watcher.vala @@ -20,22 +20,22 @@ with this program. If not, see . [DBus (name = "org.freedesktop.DBus")] public interface FreeDesktopObject: Object { public abstract async string[] list_names() throws IOError; - public abstract signal void name_owner_changed (string name, - string old_owner, - string new_owner); + public abstract signal void name_owner_changed ( string name, + string old_owner, + string new_owner ); } public class Mpris2Watcher : GLib.Object { private const string FREEDESKTOP_SERVICE = "org.freedesktop.DBus"; private const string FREEDESKTOP_OBJECT = "/org/freedesktop/DBus"; - private const string MPRIS_PREFIX = "org.mpris.MediaPlayer2."; + public const string MPRIS_PREFIX = "org.mpris.MediaPlayer2."; private const string MPRIS_MEDIA_PLAYER_PATH = "/org/mpris/MediaPlayer2"; FreeDesktopObject fdesktop_obj; - public signal void client_appeared ( string desktop_name ); - public signal void client_disappeared ( string mpris_root_interface ); + public signal void client_appeared ( string desktop_file_name, string dbus_name ); + public signal void client_disappeared ( string dbus_name ); public Mpris2Watcher () { @@ -72,7 +72,7 @@ public class Mpris2Watcher : GLib.Object } else if (previous_owner == "" && current_owner != "") { debug ("Client '%s' has appeared", name); - client_appeared (mpris2_root.DesktopEntry); + client_appeared (mpris2_root.DesktopEntry, name); } } @@ -109,7 +109,7 @@ public class Mpris2Watcher : GLib.Object if (address.has_prefix (MPRIS_PREFIX)){ MprisRoot? mpris2_root = this.create_mpris_root(address); if (mpris2_root == null) return; - client_appeared (mpris2_root.DesktopEntry); + client_appeared (mpris2_root.DesktopEntry, address); } } } diff --git a/src/music-player-bridge.vala b/src/music-player-bridge.vala index 5133770..0d1b0e4 100644 --- a/src/music-player-bridge.vala +++ b/src/music-player-bridge.vala @@ -25,17 +25,15 @@ public class MusicPlayerBridge : GLib.Object { private Dbusmenu.Menuitem root_menu; private HashMap registered_clients; - private FamiliarPlayersDB playersDB; private Mpris2Watcher watcher; private const string DESKTOP_PREFIX = "/usr/share/applications/"; public MusicPlayerBridge() { - playersDB = new FamiliarPlayersDB(); registered_clients = new HashMap (); } - private void try_to_add_inactive_familiar_clients(){ + /*private void try_to_add_inactive_familiar_clients(){ foreach(string app in this.playersDB.records()){ if(app == null){ warning("App string in keyfile is null therefore moving on to next player"); @@ -61,7 +59,7 @@ public class MusicPlayerBridge : GLib.Object PlayerController.state.OFFLINE); this.registered_clients.set(mpris_key, ctrl); } - } + }*/ private int calculate_menu_position() { @@ -73,20 +71,15 @@ public class MusicPlayerBridge : GLib.Object } } - /*public void on_server_added(Indicate.ListenerServer object, string type) + public void client_has_become_available ( string desktop, string dbus_name ) { - debug("MusicPlayerBridge -> on_server_added with value %s", type); - if(server_is_not_of_interest(type)) return; - if ( this.root_menu != null ){ - listener_get_server_property_cb cb = (listener_get_server_property_cb)desktop_info_callback; - this.listener.server_get_desktop(object, cb, this); + if (desktop == null || desktop == ""){ + warning("Client %s attempting to register without desktop entry being set on the mpris root", + dbus_name); + return; } - }*/ - - public void client_has_become_available ( string desktop_file_name ) - { - debug ( "client_has_become_available %s", desktop_file_name ); - string path = DESKTOP_PREFIX.concat ( desktop_file_name.concat( ".desktop" ) ); + debug ( "client_has_become_available %s", desktop ); + string path = DESKTOP_PREFIX.concat ( desktop.concat( ".desktop" ) ); AppInfo? app_info = create_app_info ( path ); if ( app_info == null ){ warning ( "Could not create app_info for path %s \n Getting out of here ", path); @@ -94,25 +87,24 @@ public class MusicPlayerBridge : GLib.Object } var mpris_key = determine_key ( path ); - - if ( this.playersDB.already_familiar ( path ) == false ){ - debug("New client has registered that we have not seen before: %s", desktop_file_name ); - this.playersDB.insert ( path ); + // Are we sure clients will appear like this with the new registration method in place. + if ( this.registered_clients.has_key (mpris_key) == false ){ + debug("New client has registered that we have not seen before: %s", desktop ); PlayerController ctrl = new PlayerController ( this.root_menu, app_info, - mpris_key, - playersDB.fetch_icon_name(path), + dbus_name, + this.fetch_icon_name(path), this.calculate_menu_position(), PlayerController.state.READY ); - this.registered_clients.set ( mpris_key, ctrl ); + this.registered_clients.set ( mpris_key, ctrl ); debug ( "successfully created appinfo and instance from path and set it on the respective instance" ); - } - else{ - this.registered_clients[mpris_key].update_state ( PlayerController.state.READY ); - this.registered_clients[mpris_key].activate ( ); - debug("Ignoring desktop file path callback because the db cache file has it already: %s \n", path); - } } + else{ + this.registered_clients[mpris_key].update_state ( PlayerController.state.READY ); + this.registered_clients[mpris_key].activate ( ); + debug("Ignoring desktop file path callback because the db cache file has it already: %s \n", path); + } + } public void client_has_vanished ( string mpris_root_interface ) { @@ -127,16 +119,15 @@ public class MusicPlayerBridge : GLib.Object } } - public void set_root_menu_item(Dbusmenu.Menuitem menu) + public void set_root_menu_item ( Dbusmenu.Menuitem menu ) { this.root_menu = menu; - this.try_to_add_inactive_familiar_clients(); this.watcher = new Mpris2Watcher (); this.watcher.client_appeared += this.client_has_become_available; this.watcher.client_disappeared += this.client_has_vanished; } - public static AppInfo? create_app_info ( string path ) + private static AppInfo? create_app_info ( string path ) { DesktopAppInfo info = new DesktopAppInfo.from_filename ( path ) ; if ( path == null || info == null ){ @@ -147,6 +138,35 @@ public class MusicPlayerBridge : GLib.Object return app_info; } + private static string? fetch_icon_name(string desktop_path) + { + KeyFile desktop_keyfile = new KeyFile (); + try{ + desktop_keyfile.load_from_file (desktop_path, KeyFileFlags.NONE); + } + catch(GLib.FileError error){ + warning("Error loading keyfile - FileError"); + return null; + } + catch(GLib.KeyFileError error){ + warning("Error loading keyfile - KeyFileError"); + return null; + } + + try{ + return desktop_keyfile.get_string (KeyFileDesktop.GROUP, + KeyFileDesktop.KEY_ICON); + } + catch(GLib.KeyFileError error){ + warning("Error trying to fetch the icon name from the keyfile"); + return null; + } + } + + /* + Messy but necessary method to consolidate desktop filesnames and mpris dbus names + into the one single word string (used as the key in the players hash). + */ private static string? determine_key(owned string path) { var tokens = path.split( "/" ); diff --git a/src/player-controller.vala b/src/player-controller.vala index 0b540f9..9e00258 100644 --- a/src/player-controller.vala +++ b/src/player-controller.vala @@ -44,7 +44,7 @@ public class PlayerController : GLib.Object private Dbusmenu.Menuitem root_menu; public string name { get; set;} - public string mpris_name { get; set;} + public string dbus_name { get; set;} public ArrayList custom_items; public Mpris2Controller mpris_bridge; public AppInfo? app_info { get; set;} @@ -53,21 +53,21 @@ public class PlayerController : GLib.Object public PlayerController(Dbusmenu.Menuitem root, GLib.AppInfo app, - string mpris_name, + string dbus_name, string icon_name, int offset, state initial_state) { this.root_menu = root; this.app_info = app; + this.dbus_name = dbus_name; this.name = format_player_name(this.app_info.get_name()); - this.mpris_name = mpris_name; this.icon_name = icon_name; this.custom_items = new ArrayList(); this.current_state = initial_state; this.menu_offset = offset; - construct_widgets(); - establish_mpris_connection(); + this.construct_widgets(); + this.establish_mpris_connection(); this.update_layout(); } @@ -162,7 +162,7 @@ public class PlayerController : GLib.Object foreach(PlayerItem item in this.custom_items){ root_menu.child_add_position(item, this.menu_offset + this.custom_items.index_of(item)); } - } + } private static string format_player_name(owned string app_info_name) { @@ -173,8 +173,8 @@ public class PlayerController : GLib.Object } if(result.length > 1){ result = result.up(1).concat(result.slice(1, result.length)); - debug("PlayerController->format_player_name - : %s", result); } + debug("PlayerController->format_player_name - : %s", result); return result; } diff --git a/src/sound-service.c b/src/sound-service.c index 98f1881..defcb94 100644 --- a/src/sound-service.c +++ b/src/sound-service.c @@ -40,8 +40,8 @@ service_shutdown (IndicatorService *service, gpointer user_data) { if (mainloop != NULL) { g_debug("Service shutdown !"); - close_pulse_activites(); - g_main_loop_quit(mainloop); + //close_pulse_activites(); + //g_main_loop_quit(mainloop); } return; } -- cgit v1.2.3 From 8396e05ce716296377f2e4550e0c929dca30518e Mon Sep 17 00:00:00 2001 From: Conor Curran Date: Tue, 14 Dec 2010 16:41:10 +0000 Subject: gsettings all the way --- data/Makefile.am | 41 ++++++++----------------- data/com.canonical.indicators.sound.gschema.xml | 20 ++++++++++++ data/indicator-sound.schemas.in | 16 ---------- src/music-player-bridge.vala | 10 ++++-- 4 files changed, 40 insertions(+), 47 deletions(-) create mode 100644 data/com.canonical.indicators.sound.gschema.xml delete mode 100644 data/indicator-sound.schemas.in diff --git a/data/Makefile.am b/data/Makefile.am index aaa6ca4..730f166 100644 --- a/data/Makefile.am +++ b/data/Makefile.am @@ -5,39 +5,22 @@ service_in_files = indicator-sound.service.in dbus_services_DATA = $(service_in_files:.service.in=.service) %.service: %.service.in - sed -e "s|\@libexecdir\@|$(libexecdir)|" $< > $@ + sed -e "s|\@libexecdir\@|$(libexecdir)|" $< > $@ ############################## -# GConf Schema +# GSettings Schema ############################## -schemadir = \ - $(GCONF_SCHEMA_FILE_DIR) +gsettings_SCHEMAS = \ + com.canonical.indicators.sound.gschema.xml +@GSETTINGS_RULES@ -schema_in_files = \ - indicator-sound.schemas.in - -schema_DATA = \ - $(schema_in_files:.schemas.in=.schemas) - -@INTLTOOL_SCHEMAS_RULE@ - - -#$(dbus_services_DATA): $(service_in_files) Makefile -# sed -e "s|\@libexecdir\@|$(libexecdir)|" $< > $@ - -EXTRA_DIST = \ - $(service_in_files) \ - $(schema_in_files) +############################## -CLEANFILES = \ - $(dbus_services_DATA) \ - $(schema_DATA) +EXTRA_DIST = \ + $(service_in_files) \ + $(gsettings_SCHEMAS) -if GCONF_SCHEMAS_INSTALL -install-data-local: - GCONF_CONFIG_SOURCE=$(GCONF_SCHEMA_CONFIG_SOURCE) \ - gconftool-2 --makefile-install-rule $(schema_DATA) -else -install-data-local: -endif +CLEANFILES = \ + $(dbus_services_DATA) + \ No newline at end of file diff --git a/data/com.canonical.indicators.sound.gschema.xml b/data/com.canonical.indicators.sound.gschema.xml new file mode 100644 index 0000000..4284527 --- /dev/null +++ b/data/com.canonical.indicators.sound.gschema.xml @@ -0,0 +1,20 @@ + + + + + A list of applications blacklisted from the sound menu + + Each media player which abides by the MPRIS2 spec will automatically appear in the menu. + This array should contain the desktop file names (minus .desktop suffix) of applications which + do not want to be included in the sound menu. + + + + FALSE + Initial setting for global mute (mute all) on the menu + + On start up volume should not be muted. + + + + diff --git a/data/indicator-sound.schemas.in b/data/indicator-sound.schemas.in deleted file mode 100644 index 9ad0f39..0000000 --- a/data/indicator-sound.schemas.in +++ /dev/null @@ -1,16 +0,0 @@ - - - - - /schemas/apps/indicator-sound/volume_mute - /apps/indicator-sound/volume_mute - indicator-sound - bool - FALSE - - Volume is not muted by default - On start up volume should not be muted. - - - - diff --git a/src/music-player-bridge.vala b/src/music-player-bridge.vala index 0d1b0e4..51ecc4c 100644 --- a/src/music-player-bridge.vala +++ b/src/music-player-bridge.vala @@ -27,12 +27,18 @@ public class MusicPlayerBridge : GLib.Object private HashMap registered_clients; private Mpris2Watcher watcher; private const string DESKTOP_PREFIX = "/usr/share/applications/"; - + private Settings settings; + public MusicPlayerBridge() { - registered_clients = new HashMap (); } + construct{ + this.registered_clients = new HashMap (); + this.settings = new Settings("com.canonical.indicators.sound"); + } + + /*private void try_to_add_inactive_familiar_clients(){ foreach(string app in this.playersDB.records()){ if(app == null){ -- cgit v1.2.3 From 7ef502c18c6ccf850c83fabebfb1884c458320b4 Mon Sep 17 00:00:00 2001 From: Conor Curran Date: Tue, 14 Dec 2010 17:04:46 +0000 Subject: autofoo in order for gsettings --- data/Makefile.am | 24 +++++++++--------------- data/indicator-sound.service.in | 2 ++ 2 files changed, 11 insertions(+), 15 deletions(-) diff --git a/data/Makefile.am b/data/Makefile.am index 730f166..3f54f64 100644 --- a/data/Makefile.am +++ b/data/Makefile.am @@ -1,26 +1,20 @@ SUBDIRS = icons +gsettings_SCHEMAS = \ + com.canonical.indicators.sound.gschema.xml +@GSETTINGS_RULES@ + dbus_servicesdir = $(DBUSSERVICEDIR) -service_in_files = indicator-sound.service.in -dbus_services_DATA = $(service_in_files:.service.in=.service) +dbus_services_DATA = indicator-sound.service %.service: %.service.in sed -e "s|\@libexecdir\@|$(libexecdir)|" $< > $@ -############################## -# GSettings Schema -############################## - -gsettings_SCHEMAS = \ - com.canonical.indicators.sound.gschema.xml -@GSETTINGS_RULES@ - -############################## -EXTRA_DIST = \ - $(service_in_files) \ - $(gsettings_SCHEMAS) +EXTRA_DIST = \ + $(gsettings_SCHEMAS) \ + indicator-sound.service.in -CLEANFILES = \ +CLEANFILES = \ $(dbus_services_DATA) \ No newline at end of file diff --git a/data/indicator-sound.service.in b/data/indicator-sound.service.in index 883d31d..7a957cb 100644 --- a/data/indicator-sound.service.in +++ b/data/indicator-sound.service.in @@ -1,3 +1,5 @@ [D-BUS Service] Name=org.ayatana.indicator.sound Exec=@libexecdir@/indicator-sound-service + + -- cgit v1.2.3 From 37eb76fbc08dad63341a4deff3bcaf433e1082ab Mon Sep 17 00:00:00 2001 From: Conor Curran Date: Tue, 14 Dec 2010 17:29:49 +0000 Subject: added glib macro necessaries to configure.ac --- configure.ac | 6 ++++++ data/Makefile.am | 1 - 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/configure.ac b/configure.ac index c8ae871..ea4ab45 100644 --- a/configure.ac +++ b/configure.ac @@ -89,6 +89,12 @@ fi AC_SUBST(INDICATORDIR) AC_SUBST(INDICATORICONSDIR) +########################### +# Grab the GSettings Macros +########################### + +GLIB_GSETTINGS + ########################### # DBus Service Info ########################### diff --git a/data/Makefile.am b/data/Makefile.am index 3f54f64..6f2ac61 100644 --- a/data/Makefile.am +++ b/data/Makefile.am @@ -10,7 +10,6 @@ dbus_services_DATA = indicator-sound.service %.service: %.service.in sed -e "s|\@libexecdir\@|$(libexecdir)|" $< > $@ - EXTRA_DIST = \ $(gsettings_SCHEMAS) \ indicator-sound.service.in -- cgit v1.2.3 From 7e7fa1765dc095f441d7290f50c5a773ba531b02 Mon Sep 17 00:00:00 2001 From: Conor Curran Date: Tue, 14 Dec 2010 17:53:47 +0000 Subject: changed the name of the dbus address to be used between the indicator and service --- data/indicator-sound.service.in | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/data/indicator-sound.service.in b/data/indicator-sound.service.in index 7a957cb..8059216 100644 --- a/data/indicator-sound.service.in +++ b/data/indicator-sound.service.in @@ -1,5 +1,5 @@ [D-BUS Service] -Name=org.ayatana.indicator.sound +Name=com.canonical.indicators.sound Exec=@libexecdir@/indicator-sound-service -- cgit v1.2.3 From 02b6109a523fdf2236788628447186682a9adf1b Mon Sep 17 00:00:00 2001 From: Conor Curran Date: Tue, 14 Dec 2010 18:00:36 +0000 Subject: fixed annoying autofoo issues --- data/Makefile.am | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/data/Makefile.am b/data/Makefile.am index 6f2ac61..f33b470 100644 --- a/data/Makefile.am +++ b/data/Makefile.am @@ -8,7 +8,7 @@ dbus_servicesdir = $(DBUSSERVICEDIR) dbus_services_DATA = indicator-sound.service %.service: %.service.in - sed -e "s|\@libexecdir\@|$(libexecdir)|" $< > $@ + sed -e "s|\@libexecdir\@|$(libexecdir)|" $< > $@ EXTRA_DIST = \ $(gsettings_SCHEMAS) \ -- cgit v1.2.3 From 57e6249df95fd120eee8ed4013210d359cdeee97 Mon Sep 17 00:00:00 2001 From: Conor Curran Date: Tue, 14 Dec 2010 18:27:45 +0000 Subject: changed over dbus internal names --- src/dbus-shared-names.h | 26 ++++++-------------------- 1 file changed, 6 insertions(+), 20 deletions(-) diff --git a/src/dbus-shared-names.h b/src/dbus-shared-names.h index 3062ac5..a62238b 100644 --- a/src/dbus-shared-names.h +++ b/src/dbus-shared-names.h @@ -23,26 +23,12 @@ with this program. If not, see . #ifndef __DBUS_SHARED_NAMES_H__ -#define __DBUS_SHARED_NAMES_H__ 1 - -#define INDICATOR_STATUS_DBUS_NAME "org.ayatana.indicator.status" -#define INDICATOR_STATUS_DBUS_OBJECT "/org/ayatana/indicator/status/menu" -#define INDICATOR_STATUS_SERVICE_DBUS_OBJECT "/org/ayatana/indicator/status/service" -#define INDICATOR_STATUS_SERVICE_DBUS_INTERFACE "org.ayatana.indicator.status.service" - -#define INDICATOR_USERS_DBUS_NAME "org.ayatana.indicator.users" -#define INDICATOR_USERS_DBUS_OBJECT "/org/ayatana/indicator/users/menu" -#define INDICATOR_USERS_SERVICE_DBUS_OBJECT "/org/gnome/DisplayManager/UserManager" -#define INDICATOR_USERS_SERVICE_DBUS_INTERFACE "org.gnome.DisplayManager.UserManager" - -#define INDICATOR_SESSION_DBUS_NAME "org.ayatana.indicator.session" -#define INDICATOR_SESSION_DBUS_OBJECT "/org/ayatana/indicator/session/menu" -#define INDICATOR_SESSION_DBUS_VERSION 0 - -#define INDICATOR_SOUND_DBUS_NAME "org.ayatana.indicator.sound" -#define INDICATOR_SOUND_DBUS_OBJECT "/org/ayatana/indicator/sound/menu" -#define INDICATOR_SOUND_SERVICE_DBUS_OBJECT "/org/ayatana/indicator/sound/service" -#define INDICATOR_SOUND_SERVICE_DBUS_INTERFACE "org.ayatana.indicator.sound" +#define __DBUS_SHARED_NAMES_H__ + +#define INDICATOR_SOUND_DBUS_NAME "com.canonical.indicators.sound" +#define INDICATOR_SOUND_DBUS_OBJECT "/com/canonical/indicators/sound/menu" +#define INDICATOR_SOUND_SERVICE_DBUS_OBJECT "/com/canonical/indicators/sound/service" +#define INDICATOR_SOUND_SERVICE_DBUS_INTERFACE "com.canonical.indicators.sound" #define INDICATOR_SOUND_DBUS_VERSION 0 #endif /* __DBUS_SHARED_NAMES_H__ */ -- cgit v1.2.3 From aaf57407f00aa59df3699794496fd42a731ad7db Mon Sep 17 00:00:00 2001 From: Conor Curran Date: Wed, 15 Dec 2010 14:32:27 +0000 Subject: settings schema defined and handling code wrote --- data/com.canonical.indicators.sound.gschema.xml | 25 +++++++---- src/Makefile.am | 2 +- src/music-player-bridge.vala | 10 ++++- src/settings-manager.vala | 55 +++++++++++++++++++++++++ src/sound-service-dbus.c | 1 - 5 files changed, 81 insertions(+), 12 deletions(-) create mode 100644 src/settings-manager.vala diff --git a/data/com.canonical.indicators.sound.gschema.xml b/data/com.canonical.indicators.sound.gschema.xml index 4284527..e8e4c86 100644 --- a/data/com.canonical.indicators.sound.gschema.xml +++ b/data/com.canonical.indicators.sound.gschema.xml @@ -1,19 +1,28 @@ - - + A list of applications blacklisted from the sound menu + [] - Each media player which abides by the MPRIS2 spec will automatically appear in the menu. - This array should contain the desktop file names (minus .desktop suffix) of applications which - do not want to be included in the sound menu. + Each media player which abides by the MPRIS2 spec will automatically appear in the menu. + This array should contain the desktop file names (minus .desktop suffix) of applications which + do not want to be included in the sound menu. - - FALSE + + A list of applications which at some point have registered with the sound menu + [] + + Each media player which abides by the MPRIS2 spec will automatically appear in the menu. + This array should contain the desktop file names (minus .desktop suffix) of applications which + have at some point appeared in the menU. This allows the menu remember and display offlined applications. + + + + false Initial setting for global mute (mute all) on the menu - On start up volume should not be muted. + On start up volume should not be muted. diff --git a/src/Makefile.am b/src/Makefile.am index 1c381f5..5ef9ef0 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -64,7 +64,7 @@ music_bridge_VALASOURCES = \ mpris2-watcher.vala \ mpris2-controller.vala \ player-item.vala \ - familiar-players-db.vala \ + settings-manager.vala \ fetch-file.vala diff --git a/src/music-player-bridge.vala b/src/music-player-bridge.vala index 51ecc4c..6a45d0c 100644 --- a/src/music-player-bridge.vala +++ b/src/music-player-bridge.vala @@ -23,6 +23,7 @@ using GLib; public class MusicPlayerBridge : GLib.Object { + private SettingsManager settings_manager; private Dbusmenu.Menuitem root_menu; private HashMap registered_clients; private Mpris2Watcher watcher; @@ -35,9 +36,14 @@ public class MusicPlayerBridge : GLib.Object construct{ this.registered_clients = new HashMap (); - this.settings = new Settings("com.canonical.indicators.sound"); + this.settings_manager = new SettingsManager(); + this.settings_manager.connect.blacklist_updates (on_blacklist_update); } + private void on_black_list_updated ( string[] blacklist ) + { + debug("some blacklist update"); + } /*private void try_to_add_inactive_familiar_clients(){ foreach(string app in this.playersDB.records()){ @@ -143,7 +149,7 @@ public class MusicPlayerBridge : GLib.Object GLib.AppInfo app_info = info as GLib.AppInfo; return app_info; } - + private static string? fetch_icon_name(string desktop_path) { KeyFile desktop_keyfile = new KeyFile (); diff --git a/src/settings-manager.vala b/src/settings-manager.vala new file mode 100644 index 0000000..9068c05 --- /dev/null +++ b/src/settings-manager.vala @@ -0,0 +1,55 @@ +/* +Copyright 2010 Canonical Ltd. + +Authors: + Conor Curran + +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 . +*/ +using Gee; + +public class SettingsManager : GLib.Object +{ + private Settings settings; + public signal void blacklist_updates ( string[] new_blacklist ); + + public SettingsManager ( ){ + } + construct{ + this.settings = new Settings ("com.canonical.indicators.sound"); + settings.changed["blacklisted-media-players"].connect (on_blacklist_event); + this.fetch_entries.begin(); + } + + public string[] fetch_blacklist() + { + return this.blacklist_updates(this.settings.get_strv ("blacklisted-media-players")); + } + + public string[] fetch_interested() + { + return this.interested_updates(this.settings.get_strv ("interested-media-players")); + } + + public bool add_interested(string app_desktop_name) + { + string[] already_interested = fetch_interested(); + already_interested.append ( app_desktop_name ); + return this.settings.set_strv( already_interested ); + } + + private on_blacklist_event() + { + this.blacklist_updates(this.settings.get_strv ("blacklisted-media-players")); + } +} \ No newline at end of file diff --git a/src/sound-service-dbus.c b/src/sound-service-dbus.c index d553285..0760247 100644 --- a/src/sound-service-dbus.c +++ b/src/sound-service-dbus.c @@ -42,7 +42,6 @@ struct _SoundServiceDbusPrivate { gboolean sink_availability; }; - /* Signals */ enum { SINK_INPUT_WHILE_MUTED, -- cgit v1.2.3 From bb13f9134c42480ada8128cfbd3b19ec2d68865b Mon Sep 17 00:00:00 2001 From: Conor Curran Date: Wed, 15 Dec 2010 16:23:15 +0000 Subject: clients properly remembered using gsettings --- data/com.canonical.indicators.sound.gschema.xml | 2 +- src/music-player-bridge.vala | 62 ++++++++++++------------- src/settings-manager.vala | 12 ++--- 3 files changed, 37 insertions(+), 39 deletions(-) diff --git a/data/com.canonical.indicators.sound.gschema.xml b/data/com.canonical.indicators.sound.gschema.xml index e8e4c86..43cc645 100644 --- a/data/com.canonical.indicators.sound.gschema.xml +++ b/data/com.canonical.indicators.sound.gschema.xml @@ -1,5 +1,5 @@ - + A list of applications blacklisted from the sound menu [] diff --git a/src/music-player-bridge.vala b/src/music-player-bridge.vala index 6a45d0c..b13b7f3 100644 --- a/src/music-player-bridge.vala +++ b/src/music-player-bridge.vala @@ -37,42 +37,35 @@ public class MusicPlayerBridge : GLib.Object construct{ this.registered_clients = new HashMap (); this.settings_manager = new SettingsManager(); - this.settings_manager.connect.blacklist_updates (on_blacklist_update); + this.settings_manager.blacklist_updates.connect ( this.on_blacklist_update ); } - private void on_black_list_updated ( string[] blacklist ) + private void on_blacklist_update ( string[] blacklist ) { debug("some blacklist update"); } - - /*private void try_to_add_inactive_familiar_clients(){ - foreach(string app in this.playersDB.records()){ - if(app == null){ - warning("App string in keyfile is null therefore moving on to next player"); - continue; - } - debug("attempting to make an app info from %s", app); - - DesktopAppInfo info = new DesktopAppInfo.from_filename(app); - - if(info == null){ - warning("Could not create a desktopappinfo instance from app,: %s , moving on to the next client", app); + private void try_to_add_inactive_familiar_clients() + { + foreach ( string desktop in this.settings_manager.fetch_interested()){ + debug ( "interested client found : %s", desktop ); + string path = DESKTOP_PREFIX.concat ( desktop.concat( ".desktop" ) ); + AppInfo? app_info = create_app_info ( path ); + if ( app_info == null ){ + warning ( "Could not create app_info for path %s \n Getting out of here ", path); continue; } - - GLib.AppInfo app_info = info as GLib.AppInfo; - var mpris_key = determine_key ( app ); - PlayerController ctrl = new PlayerController(this.root_menu, - app_info, - mpris_key, - playersDB.fetch_icon_name(app), - calculate_menu_position(), - PlayerController.state.OFFLINE); - this.registered_clients.set(mpris_key, ctrl); - } - }*/ - + var mpris_key = determine_key ( path ); + PlayerController ctrl = new PlayerController ( this.root_menu, + app_info, + mpris_key, + this.fetch_icon_name(path), + calculate_menu_position(), + PlayerController.state.OFFLINE ); + this.registered_clients.set(mpris_key, ctrl); + } + } + private int calculate_menu_position() { if(this.registered_clients.size == 0){ @@ -109,12 +102,14 @@ public class MusicPlayerBridge : GLib.Object this.calculate_menu_position(), PlayerController.state.READY ); this.registered_clients.set ( mpris_key, ctrl ); - debug ( "successfully created appinfo and instance from path and set it on the respective instance" ); + debug ( "Have not seen this %s before, new controller created.", desktop ); + this.settings_manager.add_interested ( desktop ); + debug ( "application added to the interested list" ); } else{ this.registered_clients[mpris_key].update_state ( PlayerController.state.READY ); this.registered_clients[mpris_key].activate ( ); - debug("Ignoring desktop file path callback because the db cache file has it already: %s \n", path); + debug("Application has already registered - awaken the hibernation: %s \n", path); } } @@ -137,6 +132,7 @@ public class MusicPlayerBridge : GLib.Object this.watcher = new Mpris2Watcher (); this.watcher.client_appeared += this.client_has_become_available; this.watcher.client_disappeared += this.client_has_vanished; + this.try_to_add_inactive_familiar_clients(); } private static AppInfo? create_app_info ( string path ) @@ -176,8 +172,10 @@ public class MusicPlayerBridge : GLib.Object } /* - Messy but necessary method to consolidate desktop filesnames and mpris dbus names - into the one single word string (used as the key in the players hash). + Messy but necessary method to consolidate desktop filesnames and mpris dbus names + into the one single word string (used as the key in the players hash). + So this means that we can determine the key for the players_hash from the + dbus interface name or the desktop file name. */ private static string? determine_key(owned string path) { diff --git a/src/settings-manager.vala b/src/settings-manager.vala index 9068c05..05db430 100644 --- a/src/settings-manager.vala +++ b/src/settings-manager.vala @@ -28,27 +28,27 @@ public class SettingsManager : GLib.Object construct{ this.settings = new Settings ("com.canonical.indicators.sound"); settings.changed["blacklisted-media-players"].connect (on_blacklist_event); - this.fetch_entries.begin(); } public string[] fetch_blacklist() { - return this.blacklist_updates(this.settings.get_strv ("blacklisted-media-players")); + return this.settings.get_strv ("blacklisted-media-players"); } public string[] fetch_interested() { - return this.interested_updates(this.settings.get_strv ("interested-media-players")); + return this.settings.get_strv ("interested-media-players"); } public bool add_interested(string app_desktop_name) { string[] already_interested = fetch_interested(); - already_interested.append ( app_desktop_name ); - return this.settings.set_strv( already_interested ); + already_interested += (app_desktop_name); + return this.settings.set_strv( "interested-media-players", + already_interested ); } - private on_blacklist_event() + private void on_blacklist_event() { this.blacklist_updates(this.settings.get_strv ("blacklisted-media-players")); } -- cgit v1.2.3 From de3ed4111ef50b847e1ba4d6ea06e13f913ba7a0 Mon Sep 17 00:00:00 2001 From: Conor Curran Date: Thu, 16 Dec 2010 12:36:43 +0000 Subject: race condtion on playbackstatus accommodated for and dbus names changed over the new canonical naming --- data/com.canonical.indicators.sound.gschema.xml | 2 +- data/indicator-sound.service.in | 2 -- src/dbus-shared-names.h | 2 +- src/indicator-sound.c | 4 ++-- src/mpris2-controller.vala | 15 +++++++++++++-- src/music-player-bridge.vala | 10 +++++----- src/player-controller.vala | 7 ++++--- src/pulse-manager.c | 4 ++-- src/sound-service.xml | 4 ++-- 9 files changed, 30 insertions(+), 20 deletions(-) diff --git a/data/com.canonical.indicators.sound.gschema.xml b/data/com.canonical.indicators.sound.gschema.xml index 43cc645..3850f65 100644 --- a/data/com.canonical.indicators.sound.gschema.xml +++ b/data/com.canonical.indicators.sound.gschema.xml @@ -11,7 +11,7 @@ A list of applications which at some point have registered with the sound menu - [] + [ 'banshee-1' ] Each media player which abides by the MPRIS2 spec will automatically appear in the menu. This array should contain the desktop file names (minus .desktop suffix) of applications which diff --git a/data/indicator-sound.service.in b/data/indicator-sound.service.in index 8059216..a80cd03 100644 --- a/data/indicator-sound.service.in +++ b/data/indicator-sound.service.in @@ -1,5 +1,3 @@ [D-BUS Service] Name=com.canonical.indicators.sound Exec=@libexecdir@/indicator-sound-service - - diff --git a/src/dbus-shared-names.h b/src/dbus-shared-names.h index a62238b..9d1e875 100644 --- a/src/dbus-shared-names.h +++ b/src/dbus-shared-names.h @@ -23,7 +23,7 @@ with this program. If not, see . #ifndef __DBUS_SHARED_NAMES_H__ -#define __DBUS_SHARED_NAMES_H__ +#define __DBUS_SHARED_NAMES_H__ 1 #define INDICATOR_SOUND_DBUS_NAME "com.canonical.indicators.sound" #define INDICATOR_SOUND_DBUS_OBJECT "/com/canonical/indicators/sound/menu" diff --git a/src/indicator-sound.c b/src/indicator-sound.c index d5cc54c..34f5ed9 100644 --- a/src/indicator-sound.c +++ b/src/indicator-sound.c @@ -561,7 +561,7 @@ fetch_sink_availability_from_dbus(IndicatorSound* self) GError * error = NULL; gboolean * available_input; available_input = g_new0(gboolean, 1); - org_ayatana_indicator_sound_get_sink_availability(sound_dbus_proxy, available_input, &error); + com_canonical_indicators_sound_get_sink_availability(sound_dbus_proxy, available_input, &error); if (error != NULL) { g_warning("Unable to fetch AVAILABILITY at indicator start up: %s", error->message); g_error_free(error); @@ -593,7 +593,7 @@ fetch_mute_value_from_dbus() GError * error = NULL; gboolean *mute_input; mute_input = g_new0(gboolean, 1); - org_ayatana_indicator_sound_get_sink_mute(sound_dbus_proxy, mute_input, &error); + com_canonical_indicators_sound_get_sink_mute(sound_dbus_proxy, mute_input, &error); if (error != NULL) { g_warning("Unable to fetch MUTE at indicator start up: %s", error->message); g_error_free(error); diff --git a/src/mpris2-controller.vala b/src/mpris2-controller.vala index 42d08c9..7f14efe 100644 --- a/src/mpris2-controller.vala +++ b/src/mpris2-controller.vala @@ -46,7 +46,7 @@ public class Mpris2Controller : GLib.Object try { this.mpris2_root = Bus.get_proxy_sync ( BusType.SESSION, this.owner.dbus_name, - "/org/mpris/MediaPlayer2"); + "/org/mpris/MediaPlayer2" ); this.player = Bus.get_proxy_sync ( BusType.SESSION, this.owner.dbus_name, "/org/mpris/MediaPlayer2" ); @@ -73,7 +73,11 @@ public class Mpris2Controller : GLib.Object } Variant? play_v = changed_properties.lookup("PlaybackStatus"); if(play_v != null){ + // Race condition sometimes appears with the playback status + // 200ms timeout ensures we have the correct playback status at all times. string state = this.player.PlaybackStatus; + //debug("in the property update and the playback status = %s and update = %s", state, (string)play_v); + Timeout.add ( 200, ensure_correct_playback_status ); TransportMenuitem.state p = (TransportMenuitem.state)this.determine_play_state(state); (this.owner.custom_items[PlayerController.widget_order.TRANSPORT] as TransportMenuitem).change_play_state(p); } @@ -81,7 +85,7 @@ public class Mpris2Controller : GLib.Object if(meta_v != null){ GLib.HashTable changed_updates = clean_metadata(); PlayerItem metadata = this.owner.custom_items[PlayerController.widget_order.METADATA]; - metadata.reset( MetadataMenuitem.attributes_format()); + metadata.reset ( MetadataMenuitem.attributes_format()); metadata.update ( changed_updates, MetadataMenuitem.attributes_format()); metadata.property_set_bool ( MENUITEM_PROP_VISIBLE, @@ -89,6 +93,13 @@ public class Mpris2Controller : GLib.Object } } + private bool ensure_correct_playback_status(){ + debug("TEST playback status = %s", this.player.PlaybackStatus); + TransportMenuitem.state p = (TransportMenuitem.state)this.determine_play_state(this.player.PlaybackStatus); + (this.owner.custom_items[PlayerController.widget_order.TRANSPORT] as TransportMenuitem).change_play_state(p); + return false; + } + private GLib.HashTable? clean_metadata() { GLib.HashTable changed_updates = this.player.Metadata; diff --git a/src/music-player-bridge.vala b/src/music-player-bridge.vala index b13b7f3..327a775 100644 --- a/src/music-player-bridge.vala +++ b/src/music-player-bridge.vala @@ -58,11 +58,11 @@ public class MusicPlayerBridge : GLib.Object var mpris_key = determine_key ( path ); PlayerController ctrl = new PlayerController ( this.root_menu, app_info, - mpris_key, + null, this.fetch_icon_name(path), calculate_menu_position(), PlayerController.state.OFFLINE ); - this.registered_clients.set(mpris_key, ctrl); + this.registered_clients.set(mpris_key, ctrl); } } @@ -94,7 +94,7 @@ public class MusicPlayerBridge : GLib.Object var mpris_key = determine_key ( path ); // Are we sure clients will appear like this with the new registration method in place. if ( this.registered_clients.has_key (mpris_key) == false ){ - debug("New client has registered that we have not seen before: %s", desktop ); + debug("New client has registered that we have not seen before: %s", dbus_name ); PlayerController ctrl = new PlayerController ( this.root_menu, app_info, dbus_name, @@ -108,8 +108,8 @@ public class MusicPlayerBridge : GLib.Object } else{ this.registered_clients[mpris_key].update_state ( PlayerController.state.READY ); - this.registered_clients[mpris_key].activate ( ); - debug("Application has already registered - awaken the hibernation: %s \n", path); + this.registered_clients[mpris_key].activate ( dbus_name ); + debug("Application has already registered - awaken the hibernation: %s \n", dbus_name ); } } diff --git a/src/player-controller.vala b/src/player-controller.vala index 9e00258..b5c2d76 100644 --- a/src/player-controller.vala +++ b/src/player-controller.vala @@ -53,7 +53,7 @@ public class PlayerController : GLib.Object public PlayerController(Dbusmenu.Menuitem root, GLib.AppInfo app, - string dbus_name, + string? dbus_name, string icon_name, int offset, state initial_state) @@ -78,8 +78,9 @@ public class PlayerController : GLib.Object this.update_layout(); } - public void activate() + public void activate( string dbus_name ) { + this.dbus_name = dbus_name; this.establish_mpris_connection(); } @@ -103,7 +104,7 @@ public class PlayerController : GLib.Object private void establish_mpris_connection() { - if(this.current_state != state.READY){ + if(this.current_state != state.READY && this.dbus_name != null ){ debug("establish_mpris_connection - Not ready to connect"); return; } diff --git a/src/pulse-manager.c b/src/pulse-manager.c index b002094..4443044 100644 --- a/src/pulse-manager.c +++ b/src/pulse-manager.c @@ -65,7 +65,7 @@ void establish_pulse_activities(SoundServiceDbus *service) pa_main_loop = pa_glib_mainloop_new(g_main_context_default()); g_assert(pa_main_loop); pulse_context = pa_context_new(pa_glib_mainloop_get_api(pa_main_loop), - "ayatana.indicator.sound"); + "com.canonical.indicators.sound"); g_assert(pulse_context); sink_hash = g_hash_table_new_full(g_direct_hash, @@ -103,7 +103,7 @@ reconnect_to_pulse() sink_hash = NULL; } pulse_context = pa_context_new( pa_glib_mainloop_get_api( pa_main_loop ), - "ayatana.indicator.sound" ); + "com.canonical.indicators.sound" ); g_assert(pulse_context); sink_hash = g_hash_table_new_full( g_direct_hash, g_direct_equal, NULL, diff --git a/src/sound-service.xml b/src/sound-service.xml index ee19ceb..a552d52 100644 --- a/src/sound-service.xml +++ b/src/sound-service.xml @@ -1,6 +1,6 @@ - - + + -- cgit v1.2.3 From 4c9ef773092664590d8e6e4fd46d31a35122ab6a Mon Sep 17 00:00:00 2001 From: Conor Curran Date: Thu, 16 Dec 2010 12:38:34 +0000 Subject: tidy up --- src/sound-service.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/sound-service.c b/src/sound-service.c index defcb94..98f1881 100644 --- a/src/sound-service.c +++ b/src/sound-service.c @@ -40,8 +40,8 @@ service_shutdown (IndicatorService *service, gpointer user_data) { if (mainloop != NULL) { g_debug("Service shutdown !"); - //close_pulse_activites(); - //g_main_loop_quit(mainloop); + close_pulse_activites(); + g_main_loop_quit(mainloop); } return; } -- cgit v1.2.3