diff options
-rw-r--r-- | configure.ac | 4 | ||||
-rw-r--r-- | po/POTFILES.in | 4 | ||||
-rw-r--r-- | src/indicator-sound.c | 42 | ||||
-rw-r--r-- | src/mpris2-controller.vala | 25 | ||||
-rw-r--r-- | src/mpris2-interfaces.vala | 8 | ||||
-rw-r--r-- | src/mpris2-watcher.vala | 2 | ||||
-rw-r--r-- | src/music-player-bridge.vala | 15 | ||||
-rw-r--r-- | src/mute-menu-item.c | 30 | ||||
-rw-r--r-- | src/mute-menu-item.h | 4 | ||||
-rw-r--r-- | src/player-controller.vala | 28 | ||||
-rw-r--r-- | src/playlists-menu-item.vala | 2 | ||||
-rw-r--r-- | src/pulse-manager.c | 2 | ||||
-rw-r--r-- | src/pulse-manager.h | 2 | ||||
-rw-r--r-- | src/settings-manager.vala | 23 | ||||
-rw-r--r-- | src/slider-menu-item.c | 9 | ||||
-rw-r--r-- | src/sound-service-dbus.c | 154 | ||||
-rw-r--r-- | src/sound-service.c | 4 | ||||
-rw-r--r-- | src/sound-service.xml | 6 | ||||
-rw-r--r-- | src/sound-state-manager.c | 3 | ||||
-rw-r--r-- | src/transport-widget.c | 105 |
20 files changed, 298 insertions, 174 deletions
diff --git a/configure.ac b/configure.ac index dfc78ab..d677e7c 100644 --- a/configure.ac +++ b/configure.ac @@ -1,10 +1,10 @@ -AC_INIT(indicator-sound, 0.5.6, conor.curran@canonical.com) +AC_INIT(indicator-sound, 0.5.8, conor.curran@canonical.com) AC_PREREQ(2.53) AM_CONFIG_HEADER(config.h) -AM_INIT_AUTOMAKE(indicator-sound, 0.5.6) +AM_INIT_AUTOMAKE(indicator-sound, 0.5.8) AM_MAINTAINER_MODE diff --git a/po/POTFILES.in b/po/POTFILES.in index 423ff8e..9cceace 100644 --- a/po/POTFILES.in +++ b/po/POTFILES.in @@ -1,3 +1,3 @@ [encoding: UTF-8] -data/indicator-sound.schemas.in -src/dbus-menu-manager.c +src/mute-menu-item.c +src/sound-service-dbus.c diff --git a/src/indicator-sound.c b/src/indicator-sound.c index 88ef27d..6678750 100644 --- a/src/indicator-sound.c +++ b/src/indicator-sound.c @@ -86,19 +86,22 @@ static gboolean key_release_cb(GtkWidget* widget, GdkEventKey* event, gpointer d //custom widget realisation methods static gboolean new_volume_slider_widget (DbusmenuMenuitem * newitem, DbusmenuMenuitem * parent, - DbusmenuClient * client); + DbusmenuClient * client, + gpointer user_data); static gboolean new_transport_widget (DbusmenuMenuitem * newitem, DbusmenuMenuitem * parent, - DbusmenuClient * client); + DbusmenuClient * client, + gpointer user_data); static gboolean new_metadata_widget (DbusmenuMenuitem * newitem, DbusmenuMenuitem * parent, - DbusmenuClient * client); + DbusmenuClient * client, + gpointer user_data); static gboolean new_title_widget (DbusmenuMenuitem * newitem, DbusmenuMenuitem * parent, - DbusmenuClient * client); + DbusmenuClient * client, + gpointer user_data); // DBUS communication - static GDBusNodeInfo *node_info = NULL; static GDBusInterfaceInfo *interface_info = NULL; static void create_connection_to_service (GObject *source_object, @@ -204,10 +207,18 @@ get_menu (IndicatorObject * io) DbusmenuGtkClient *client = dbusmenu_gtkmenu_get_client(menu); g_object_set_data (G_OBJECT (client), "indicator", io); - dbusmenu_client_add_type_handler(DBUSMENU_CLIENT(client), DBUSMENU_VOLUME_MENUITEM_TYPE, new_volume_slider_widget); - dbusmenu_client_add_type_handler(DBUSMENU_CLIENT(client), DBUSMENU_TRANSPORT_MENUITEM_TYPE, new_transport_widget); - dbusmenu_client_add_type_handler(DBUSMENU_CLIENT(client), DBUSMENU_METADATA_MENUITEM_TYPE, new_metadata_widget); - dbusmenu_client_add_type_handler(DBUSMENU_CLIENT(client), DBUSMENU_TITLE_MENUITEM_TYPE, new_title_widget); + dbusmenu_client_add_type_handler (DBUSMENU_CLIENT(client), + DBUSMENU_VOLUME_MENUITEM_TYPE, + new_volume_slider_widget); + dbusmenu_client_add_type_handler (DBUSMENU_CLIENT(client), + DBUSMENU_TRANSPORT_MENUITEM_TYPE, + new_transport_widget); + dbusmenu_client_add_type_handler (DBUSMENU_CLIENT(client), + DBUSMENU_METADATA_MENUITEM_TYPE, + new_metadata_widget); + dbusmenu_client_add_type_handler (DBUSMENU_CLIENT(client), + DBUSMENU_TITLE_MENUITEM_TYPE, + new_title_widget); // Note: Not ideal but all key handling needs to be managed here and then // delegated to the appropriate widget. g_signal_connect (menu, "key-press-event", G_CALLBACK(key_press_cb), io); @@ -324,7 +335,6 @@ static void create_connection_to_service (GObject *source_object, g_error_free(error); return; } - g_debug ("Connection to dbus seemed to work fine from the indicator side"); sound_state_manager_connect_to_dbus (priv->state_manager, priv->dbus_proxy); @@ -333,7 +343,8 @@ static void create_connection_to_service (GObject *source_object, static gboolean new_transport_widget (DbusmenuMenuitem * newitem, DbusmenuMenuitem * parent, - DbusmenuClient * client) + DbusmenuClient * client, + gpointer user_data) { g_debug("indicator-sound: new_transport_bar() called "); @@ -361,7 +372,8 @@ new_transport_widget (DbusmenuMenuitem * newitem, static gboolean new_metadata_widget (DbusmenuMenuitem * newitem, DbusmenuMenuitem * parent, - DbusmenuClient * client) + DbusmenuClient * client, + gpointer user_data) { g_debug("indicator-sound: new_metadata_widget"); @@ -382,7 +394,8 @@ new_metadata_widget (DbusmenuMenuitem * newitem, static gboolean new_title_widget(DbusmenuMenuitem * newitem, DbusmenuMenuitem * parent, - DbusmenuClient * client) + DbusmenuClient * client, + gpointer user_data) { g_return_val_if_fail(DBUSMENU_IS_MENUITEM(newitem), FALSE); g_return_val_if_fail(DBUSMENU_IS_GTKCLIENT(client), FALSE); @@ -405,7 +418,8 @@ new_title_widget(DbusmenuMenuitem * newitem, static gboolean new_volume_slider_widget(DbusmenuMenuitem * newitem, DbusmenuMenuitem * parent, - DbusmenuClient * client) + DbusmenuClient * client, + gpointer user_data) { g_debug("indicator-sound: new_volume_slider_widget"); diff --git a/src/mpris2-controller.vala b/src/mpris2-controller.vala index a7b3de1..03571e6 100644 --- a/src/mpris2-controller.vala +++ b/src/mpris2-controller.vala @@ -95,12 +95,12 @@ public class Mpris2Controller : GLib.Object } Variant? playlist_count_v = changed_properties.lookup("PlaylistCount"); if ( playlist_count_v != null && this.owner.use_playlists == true ){ - this.fetch_playlists(); + this.fetch_playlists.begin(); this.fetch_active_playlist(); } Variant? playlist_orderings_v = changed_properties.lookup("Orderings"); if ( playlist_orderings_v != null && this.owner.use_playlists == true ){ - this.fetch_playlists(); + this.fetch_playlists.begin(); this.fetch_active_playlist(); } } @@ -156,7 +156,7 @@ public class Mpris2Controller : GLib.Object MetadataMenuitem.attributes_format()); if ( this.owner.use_playlists == true ){ - this.fetch_playlists(); + this.fetch_playlists.begin(); this.fetch_active_playlist(); } } @@ -188,12 +188,21 @@ public class Mpris2Controller : GLib.Object } } - public void fetch_playlists() + public async void fetch_playlists() { - PlaylistDetails[] current_playlists = this.playlists.GetPlaylists(0, - 10, - "Alphabetical", - false); + PlaylistDetails[] current_playlists = null; + + try{ + current_playlists = yield this.playlists.GetPlaylists (0, + 10, + "Alphabetical", + false); + } + catch (IOError e){ + debug("Could not fetch playlists because %s", e.message); + return; + } + if( current_playlists != null ){ debug( "Size of the playlist array = %i", current_playlists.length ); PlaylistsMenuitem playlists_item = this.owner.custom_items[PlayerController.widget_order.PLAYLISTS] as PlaylistsMenuitem; diff --git a/src/mpris2-interfaces.vala b/src/mpris2-interfaces.vala index 9d0b8c9..0a0909f 100644 --- a/src/mpris2-interfaces.vala +++ b/src/mpris2-interfaces.vala @@ -68,8 +68,8 @@ public interface MprisPlaylists : Object { //methods public abstract async void ActivatePlaylist(ObjectPath playlist_id) throws IOError; - public abstract PlaylistDetails[] GetPlaylists ( uint32 index, - uint32 max_count, - string order, - bool reverse_order ) throws IOError; + public abstract async PlaylistDetails[] GetPlaylists ( uint32 index, + uint32 max_count, + string order, + bool reverse_order ) throws IOError; }
\ No newline at end of file diff --git a/src/mpris2-watcher.vala b/src/mpris2-watcher.vala index c20b04b..0b37506 100644 --- a/src/mpris2-watcher.vala +++ b/src/mpris2-watcher.vala @@ -50,7 +50,7 @@ public class Mpris2Watcher : GLib.Object // At startup check to see if there are clients up that we are interested in // More relevant for development and daemon's like mpd. - private async void check_for_active_clients() + public async void check_for_active_clients() { string[] interfaces; try{ diff --git a/src/music-player-bridge.vala b/src/music-player-bridge.vala index 7587684..c6c9913 100644 --- a/src/music-player-bridge.vala +++ b/src/music-player-bridge.vala @@ -41,6 +41,17 @@ public class MusicPlayerBridge : GLib.Object private void on_blacklist_update ( string[] blacklist ) { debug("some blacklist update"); + + foreach(var s in blacklist){ + string key = this.determine_key (s); + if (this.registered_clients.has_key (key)){ + debug ("Apparently %s is now blacklisted - remove thy self", key); + this.registered_clients[key].remove_from_menu(); + this.registered_clients.unset (key); + } + } + // double check present players to ensure dynamic removal/addition + this.watcher.check_for_active_clients.begin(); } private void try_to_add_inactive_familiar_clients() @@ -141,8 +152,8 @@ public class MusicPlayerBridge : GLib.Object 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; + this.watcher.client_appeared.connect (this.client_has_become_available); + this.watcher.client_disappeared.connect (this.client_has_vanished); } private static AppInfo? create_app_info ( string desktop ) diff --git a/src/mute-menu-item.c b/src/mute-menu-item.c index 2f40177..f7f3824 100644 --- a/src/mute-menu-item.c +++ b/src/mute-menu-item.c @@ -43,7 +43,8 @@ static void mute_menu_item_set_global_mute_from_ui (gpointer user_data); G_DEFINE_TYPE (MuteMenuItem, mute_menu_item, G_TYPE_OBJECT); -static void mute_menu_item_class_init (MuteMenuItemClass *klass) +static void +mute_menu_item_class_init (MuteMenuItemClass *klass) { GObjectClass *object_class = G_OBJECT_CLASS (klass); @@ -55,7 +56,8 @@ static void mute_menu_item_class_init (MuteMenuItemClass *klass) return; } -static void mute_menu_item_init (MuteMenuItem *self) +static void +mute_menu_item_init (MuteMenuItem *self) { g_debug("Building new Mute Menu Item"); MuteMenuItemPrivate* priv = MUTE_MENU_ITEM_GET_PRIVATE(self); @@ -68,7 +70,8 @@ static void mute_menu_item_init (MuteMenuItem *self) return; } -static void mute_menu_item_dispose (GObject *object) +static void +mute_menu_item_dispose (GObject *object) { G_OBJECT_CLASS (mute_menu_item_parent_class)->dispose (object); return; @@ -93,8 +96,8 @@ mute_menu_item_set_global_mute_from_ui (gpointer user_data) toggle_global_mute (new_value); } - -void mute_menu_item_update(MuteMenuItem* item, gboolean value_update) +void +mute_menu_item_update (MuteMenuItem* item, gboolean value_update) { MuteMenuItemPrivate* priv = MUTE_MENU_ITEM_GET_PRIVATE (item); @@ -106,7 +109,8 @@ void mute_menu_item_update(MuteMenuItem* item, gboolean value_update) value_update == FALSE ? _("Mute") : _("Unmute")); } -void mute_menu_item_enable(MuteMenuItem* item, gboolean active) +void +mute_menu_item_enable (MuteMenuItem* item, gboolean active) { MuteMenuItemPrivate* priv = MUTE_MENU_ITEM_GET_PRIVATE (item); @@ -115,13 +119,23 @@ void mute_menu_item_enable(MuteMenuItem* item, gboolean active) active); } -DbusmenuMenuitem* mute_menu_item_get_button (MuteMenuItem* item) +DbusmenuMenuitem* +mute_menu_item_get_button (MuteMenuItem* item) { MuteMenuItemPrivate* priv = MUTE_MENU_ITEM_GET_PRIVATE (item); return priv->button; } -MuteMenuItem* mute_menu_item_new (gboolean initial_update, gboolean enabled) +gboolean +mute_menu_item_is_muted (MuteMenuItem* item) +{ + MuteMenuItemPrivate* priv = MUTE_MENU_ITEM_GET_PRIVATE (item); + return dbusmenu_menuitem_property_get_bool (priv->button, + DBUSMENU_MUTE_MENUITEM_VALUE); +} + +MuteMenuItem* +mute_menu_item_new (gboolean initial_update, gboolean enabled) { MuteMenuItem *self = g_object_new (MUTE_MENU_ITEM_TYPE, NULL); mute_menu_item_update (self, initial_update); diff --git a/src/mute-menu-item.h b/src/mute-menu-item.h index 8240441..81a4b33 100644 --- a/src/mute-menu-item.h +++ b/src/mute-menu-item.h @@ -50,10 +50,10 @@ MuteMenuItem* mute_menu_item_new (); void mute_menu_item_update (MuteMenuItem* item, gboolean update); void mute_menu_item_enable (MuteMenuItem* item, gboolean active); +gboolean mute_menu_item_is_muted (MuteMenuItem* item); DbusmenuMenuitem* mute_menu_item_get_button (MuteMenuItem* item); G_END_DECLS -#endif - +#endif
\ No newline at end of file diff --git a/src/player-controller.vala b/src/player-controller.vala index adefb65..3ce121e 100644 --- a/src/player-controller.vala +++ b/src/player-controller.vala @@ -119,10 +119,14 @@ public class PlayerController : GLib.Object this.determine_state(); } - public void vanish() + public void remove_from_menu() { - foreach(Dbusmenu.Menuitem item in this.custom_items){ - root_menu.child_delete(item); + foreach(PlayerItem item in this.custom_items){ + this.root_menu.child_delete(item); + } + if (this.use_playlists == true){ + PlaylistsMenuitem playlists_menuitem = this.custom_items[widget_order.PLAYLISTS] as PlaylistsMenuitem; + this.root_menu.child_delete (playlists_menuitem.root_item); } } @@ -180,7 +184,7 @@ public class PlayerController : GLib.Object foreach(PlayerItem item in this.custom_items){ if (this.custom_items.index_of(item) != 4) { - root_menu.child_add_position(item, this.menu_offset + this.custom_items.index_of(item)); + root_menu.child_add_position(item, this.menu_offset + this.custom_items.index_of(item)); } else{ PlaylistsMenuitem playlists_menuitem = item as PlaylistsMenuitem; @@ -188,21 +192,7 @@ public class PlayerController : GLib.Object } } } - - private static string format_player_name(owned string app_info_name) - { - string result = app_info_name.down().strip(); - var tokens = result.split(" "); - if(tokens.length > 1){ - result = tokens[0]; - } - if(result.length > 1){ - result = result.up(1).concat(result.slice(1, result.length)); - } - debug("PlayerController->format_player_name - : %s", result); - return result; - } - + private void determine_state() { if(this.mpris_bridge.connected() == true){ diff --git a/src/playlists-menu-item.vala b/src/playlists-menu-item.vala index 024839c..b8c6e7d 100644 --- a/src/playlists-menu-item.vala +++ b/src/playlists-menu-item.vala @@ -50,7 +50,7 @@ public class PlaylistsMenuitem : PlayerItem this.root_item.child_append( menuitem ); } } - + private bool already_observed (PlaylistDetails new_detail) { foreach ( PlaylistDetails detail in this.current_playlists.values ){ diff --git a/src/pulse-manager.c b/src/pulse-manager.c index ca008a7..457992b 100644 --- a/src/pulse-manager.c +++ b/src/pulse-manager.c @@ -183,7 +183,7 @@ static gboolean determine_sink_availability() return available; } -static gboolean default_sink_is_muted() +gboolean default_sink_is_muted() { if (DEFAULT_SINK_INDEX < 0) return FALSE; diff --git a/src/pulse-manager.h b/src/pulse-manager.h index dfe1256..5895aeb 100644 --- a/src/pulse-manager.h +++ b/src/pulse-manager.h @@ -40,6 +40,6 @@ void establish_pulse_activities(SoundServiceDbus *service); void set_sink_volume(gdouble percent); void toggle_global_mute(gboolean mute_value); void close_pulse_activites(); - +gboolean default_sink_is_muted(); #endif diff --git a/src/settings-manager.vala b/src/settings-manager.vala index 380e442..057a47b 100644 --- a/src/settings-manager.vala +++ b/src/settings-manager.vala @@ -52,7 +52,7 @@ public class SettingsManager : GLib.Object this.settings.reset("interested-media-players"); } - public void add_interested(string app_desktop_name) + public void add_interested (string app_desktop_name) { var already_interested = this.settings.get_strv ("interested-media-players"); foreach (var s in already_interested){ @@ -67,5 +67,24 @@ public class SettingsManager : GLib.Object private void on_blacklist_event() { this.blacklist_updates(this.settings.get_strv ("blacklisted-media-players")); - } + } + + // Convenient debug method inorder to provide visability over + // the contents of both interested and blacklisted containers in its gsettings + private void reveal_contents() + { + var already_interested = this.settings.get_strv ("interested-media-players"); + foreach (var s in already_interested) + { + debug ("client %s is in interested array", s); + } + var blacklisted = this.settings.get_strv ("blacklisted-media-players"); + foreach (var s in blacklisted) + { + debug ("client %s is in blacklisted array", s); + } + + debug ("interested array size = %i", already_interested.length); + debug ("blacklisted array size = %i", blacklisted.length); + } } diff --git a/src/slider-menu-item.c b/src/slider-menu-item.c index 64db277..a20bb00 100644 --- a/src/slider-menu-item.c +++ b/src/slider-menu-item.c @@ -81,12 +81,8 @@ handle_event (DbusmenuMenuitem * mi, GVariant * value, guint timestamp) { - /*g_debug ( "handle-event in the slider at the backend, input is of type %s", - g_variant_get_type_string(value));*/ - GVariant* input = NULL; input = value; - // Please note: Subject to change in future DBusmenu revisions if (g_variant_is_of_type(value, G_VARIANT_TYPE_VARIANT) == TRUE) { input = g_variant_get_variant(value); } @@ -94,6 +90,11 @@ handle_event (DbusmenuMenuitem * mi, gboolean volume_input = g_variant_get_double(input); if (value != NULL){ set_sink_volume(volume_input); + // TODO -when the ACTIVESINK instance exists this will be handled nicely + // PA MANAGER will be refactored first. + if (default_sink_is_muted () == TRUE){ + toggle_global_mute (FALSE); + } } } diff --git a/src/sound-service-dbus.c b/src/sound-service-dbus.c index b444a91..7f5afdc 100644 --- a/src/sound-service-dbus.c +++ b/src/sound-service-dbus.c @@ -35,6 +35,7 @@ #include "pulse-manager.h" #include "slider-menu-item.h" #include "mute-menu-item.h" +#include "pulse-manager.h" // DBUS methods static void bus_method_call (GDBusConnection * connection, @@ -84,6 +85,10 @@ static void sound_service_dbus_determine_state (SoundServiceDbus* self, gboolean availability, gboolean mute, gdouble volume); +static gboolean sound_service_dbus_blacklist_player (SoundServiceDbus* self, + gchar* player_name, + gboolean blacklist); + G_DEFINE_TYPE (SoundServiceDbus, sound_service_dbus, G_TYPE_OBJECT); @@ -153,7 +158,8 @@ sound_service_dbus_init (SoundServiceDbus *self) } } -DbusmenuMenuitem* sound_service_dbus_create_root_item (SoundServiceDbus* self) +DbusmenuMenuitem* +sound_service_dbus_create_root_item (SoundServiceDbus* self) { SoundServiceDbusPrivate * priv = SOUND_SERVICE_DBUS_GET_PRIVATE(self); priv->root_menuitem = dbusmenu_menuitem_new(); @@ -165,10 +171,11 @@ DbusmenuMenuitem* sound_service_dbus_create_root_item (SoundServiceDbus* self) return priv->root_menuitem; } -static void sound_service_dbus_build_sound_menu ( SoundServiceDbus* self, - gboolean mute_update, - gboolean availability, - gdouble volume ) +static void +sound_service_dbus_build_sound_menu ( SoundServiceDbus* self, + gboolean mute_update, + gboolean availability, + gdouble volume ) { SoundServiceDbusPrivate * priv = SOUND_SERVICE_DBUS_GET_PRIVATE(self); @@ -209,8 +216,9 @@ static void sound_service_dbus_build_sound_menu ( SoundServiceDbus* self, show_sound_settings_dialog: Bring up the gnome volume preferences dialog **/ -static void show_sound_settings_dialog (DbusmenuMenuitem *mi, - gpointer user_data) +static void +show_sound_settings_dialog (DbusmenuMenuitem *mi, + gpointer user_data) { GError * error = NULL; if (!g_spawn_command_line_async("gnome-volume-control --page=applications", &error) && @@ -221,10 +229,11 @@ static void show_sound_settings_dialog (DbusmenuMenuitem *mi, } } -void sound_service_dbus_update_pa_state ( SoundServiceDbus* self, - gboolean availability, - gboolean mute_update, - gdouble volume ) +void +sound_service_dbus_update_pa_state ( SoundServiceDbus* self, + gboolean availability, + gboolean mute_update, + gdouble volume ) { g_debug("update pa state with availability of %i, mute value of %i and a volume percent is %f", availability, mute_update, volume); SoundServiceDbusPrivate * priv = SOUND_SERVICE_DBUS_GET_PRIVATE(self); @@ -265,8 +274,11 @@ sound_service_dbus_finalize (GObject *object) return; } -void sound_service_dbus_update_volume(SoundServiceDbus* self, - gdouble volume) +// UNTIL PA-MANAGER IS REFACTORED AND THE ACTIVESINK CLASS IS CREATED LEAVE +// THE UI ELEMENTS SEPARATELY HANDLED LIKE THIS. +void +sound_service_dbus_update_volume (SoundServiceDbus* self, + gdouble volume) { SoundServiceDbusPrivate *priv = SOUND_SERVICE_DBUS_GET_PRIVATE (self); slider_menu_item_update (priv->volume_slider_menuitem, volume); @@ -274,8 +286,9 @@ void sound_service_dbus_update_volume(SoundServiceDbus* self, sound_service_dbus_get_state_from_volume (self)); } -void sound_service_dbus_update_sink_mute(SoundServiceDbus* self, - gboolean mute_update) +void +sound_service_dbus_update_sink_mute (SoundServiceDbus* self, + gboolean mute_update) { SoundServiceDbusPrivate *priv = SOUND_SERVICE_DBUS_GET_PRIVATE (self); mute_menu_item_update (priv->mute_menuitem, mute_update); @@ -286,7 +299,9 @@ void sound_service_dbus_update_sink_mute(SoundServiceDbus* self, sound_service_dbus_update_sound_state (self, state); } -static SoundState sound_service_dbus_get_state_from_volume (SoundServiceDbus* self) +/*------- State calculators ------------------*/ +static SoundState +sound_service_dbus_get_state_from_volume (SoundServiceDbus* self) { SoundServiceDbusPrivate *priv = SOUND_SERVICE_DBUS_GET_PRIVATE (self); GVariant* v = dbusmenu_menuitem_property_get_variant (DBUSMENU_MENUITEM(priv->volume_slider_menuitem), @@ -310,10 +325,11 @@ static SoundState sound_service_dbus_get_state_from_volume (SoundServiceDbus* se return state; } -static void sound_service_dbus_determine_state (SoundServiceDbus* self, - gboolean availability, - gboolean mute, - gdouble volume) +static void +sound_service_dbus_determine_state (SoundServiceDbus* self, + gboolean availability, + gboolean mute, + gdouble volume) { SoundState update; if (availability == FALSE) { @@ -333,15 +349,15 @@ static void sound_service_dbus_determine_state (SoundServiceDbus* self, // TODO: this will be a bit messy until the pa_manager is sorted. // And we figure out all of the edge cases. -void sound_service_dbus_update_sound_state (SoundServiceDbus* self, - SoundState new_state) +void +sound_service_dbus_update_sound_state (SoundServiceDbus* self, + SoundState new_state) { SoundServiceDbusPrivate *priv = SOUND_SERVICE_DBUS_GET_PRIVATE (self); SoundState update = new_state; // Ensure that after it has become available update the state with the current volume level if (new_state == AVAILABLE && - dbusmenu_menuitem_property_get_bool ( DBUSMENU_MENUITEM(priv->mute_menuitem), - DBUSMENU_MUTE_MENUITEM_VALUE) == FALSE ){ + mute_menu_item_is_muted (priv->mute_menuitem) == FALSE){ update = sound_service_dbus_get_state_from_volume (self); } if (update != BLOCKED){ @@ -388,12 +404,102 @@ bus_method_call (GDBusConnection * connection, g_debug("Get state - %i", priv->current_sound_state ); retval = g_variant_new ( "(i)", priv->current_sound_state); } + else if (g_strcmp0(method, "BlacklistMediaPlayer") == 0) { + gboolean blacklist; + gchar* player_name; + g_variant_get (params, "(sb)", &player_name, &blacklist); + + g_debug ("BlacklistMediaPlayer - bool %i", blacklist); + g_debug ("BlacklistMediaPlayer - name %s", player_name); + gboolean result = sound_service_dbus_blacklist_player (service, + player_name, + blacklist); + retval = g_variant_new ("(b)", result); + } else { g_warning("Calling method '%s' on the sound service but it's unknown", method); } g_dbus_method_invocation_return_value (invocation, retval); } +static gboolean sound_service_dbus_blacklist_player (SoundServiceDbus* self, + gchar* player_name, + gboolean blacklist) +{ + gboolean result = FALSE; + GSettings* our_settings = NULL; + our_settings = g_settings_new ("com.canonical.indicators.sound"); + GVariant* the_black_list = g_settings_get_value (our_settings, + "blacklisted-media-players"); + GVariantIter iter; + gchar *str; + // Firstly prep new array which will be set on the key. + GVariantBuilder builder; + + g_variant_iter_init (&iter, the_black_list); + g_variant_builder_init(&builder, G_VARIANT_TYPE_STRING_ARRAY); + + while (g_variant_iter_loop (&iter, "s", &str)){ + g_variant_builder_add (&builder, "s", str); + } + g_variant_iter_init (&iter, the_black_list); + + if (blacklist == TRUE){ + while (g_variant_iter_loop (&iter, "s", &str)){ + g_print ("first pass to check if %s is present\n", str); + if (g_strcmp0 (player_name, str) == 0){ + // Return if its already there + g_debug ("we have this already blacklisted, no need to do anything"); + g_variant_builder_clear (&builder); + g_object_unref (our_settings); + g_object_unref (the_black_list); + return result; + } + } + // Otherwise blacklist it ! + g_debug ("about to blacklist %s", player_name); + g_variant_builder_add (&builder, "s", player_name); + } + else{ + gboolean present = FALSE; + g_variant_iter_init (&iter, the_black_list); + g_debug ("attempting to UN-blacklist %s", player_name); + + while (g_variant_iter_loop (&iter, "s", &str)){ + if (g_strcmp0 (player_name, str) == 0){ + present = TRUE; + } + } + // It was not there anyway, return false + if (present == FALSE){ + g_debug ("it was not blacklisted ?, no need to do anything"); + g_variant_builder_clear (&builder); + g_object_unref (our_settings); + g_object_unref (the_black_list); + return result; + } + + // Otherwise free the builder and reconstruct ensuring no duplicates. + g_variant_builder_clear (&builder); + g_variant_builder_init (&builder, G_VARIANT_TYPE_STRING_ARRAY); + + g_variant_iter_init (&iter, the_black_list); + + while (g_variant_iter_loop (&iter, "s", &str)){ + if (g_strcmp0 (player_name, str) != 0){ + g_variant_builder_add (&builder, "s", str); + } + } + } + GVariant* value = g_variant_builder_end (&builder); + result = g_settings_set_value (our_settings, + "blacklisted-media-players", + value); + g_object_unref (our_settings); + g_object_unref (the_black_list); + + return result; +} diff --git a/src/sound-service.c b/src/sound-service.c index 2cb33d3..c1bb9b4 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; } diff --git a/src/sound-service.xml b/src/sound-service.xml index 07c9c3d..81ebc2d 100644 --- a/src/sound-service.xml +++ b/src/sound-service.xml @@ -2,11 +2,13 @@ <node name="/com/canonical/indicators/sound"> <interface name="com.canonical.indicators.sound"> <method name = "BlacklistMediaPlayer"> - <annotation name="org.freedesktop.DBus.GLib.CSymbol" value="sound_service_dbus_blacklist_media_player"/> + <annotation name="org.freedesktop.DBus.GLib.Async" value="true"/> <arg type='s' name='player_desktop_name' direction="in"/> + <arg type='b' name='blacklist' direction="in"/> + <arg type='b' name='result' direction="out"/> </method> <method name = "GetSoundState"> - <annotation name="org.freedesktop.DBus.GLib.CSymbol" value="sound_service_dbus_get_sink_state"/> + <annotation name="org.freedesktop.DBus.GLib.Async" value="true"/> <arg type='i' name='current_state' direction="out"/> </method> <signal name="SoundStateUpdate"> diff --git a/src/sound-state-manager.c b/src/sound-state-manager.c index 2ea9b1a..e8865d8 100644 --- a/src/sound-state-manager.c +++ b/src/sound-state-manager.c @@ -193,7 +193,6 @@ sound_state_manager_connect_to_dbus (SoundStateManager* self, GDBusProxy* proxy) { SoundStateManagerPrivate* priv = SOUND_STATE_MANAGER_GET_PRIVATE(self); priv->dbus_proxy = proxy; - g_debug (" here about to register for signal callback on %s", g_dbus_proxy_get_name (priv->dbus_proxy)); g_signal_connect (priv->dbus_proxy, "g-signal", G_CALLBACK (sound_state_signal_cb), self); @@ -223,7 +222,7 @@ sound_state_manager_get_state_cb (GObject *object, &error ); if (error != NULL) { - g_debug("get_sound_state call failed: %s", error->message); + g_warning("get_sound_state call failed: %s", error->message); g_error_free(error); return; } diff --git a/src/transport-widget.c b/src/transport-widget.c index a276a31..7c96684 100644 --- a/src/transport-widget.c +++ b/src/transport-widget.c @@ -129,10 +129,10 @@ static void transport_widget_toggle_play_pause ( TransportWidget* button, TransportWidgetState update); static void transport_widget_select (GtkItem* menu, gpointer Userdata); static void transport_widget_deselect (GtkItem* menu, gpointer Userdata); +static TransportWidgetEvent transport_widget_collision_detection (gint x, gint y); /// Init functions ////////////////////////////////////////////////////////// - static void transport_widget_class_init (TransportWidgetClass *klass) { @@ -289,11 +289,7 @@ transport_widget_motion_notify_event (GtkWidget *menuitem, event); priv->motion_event = result; - cairo_t *cr; - cr = gdk_cairo_create (menuitem->window); - draw ( menuitem, cr ); - cairo_destroy ( cr ); - + gtk_widget_queue_draw (menuitem); return TRUE; } @@ -305,30 +301,23 @@ transport_widget_leave_notify_event (GtkWidget *menuitem, TransportWidgetPrivate* priv = TRANSPORT_WIDGET_GET_PRIVATE ( TRANSPORT_WIDGET(menuitem) ); priv->motion_event = TRANSPORT_NADA; - cairo_t *cr; - cr = gdk_cairo_create (menuitem->window); - draw ( menuitem, cr ); - cairo_destroy ( cr ); - + priv->current_command = TRANSPORT_NADA; + gtk_widget_queue_draw (GTK_WIDGET(menuitem)); + return TRUE; } -/* keyevents */ static gboolean transport_widget_button_press_event (GtkWidget *menuitem, - GdkEventButton *event) + GdkEventButton *event) { g_return_val_if_fail ( IS_TRANSPORT_WIDGET(menuitem), FALSE ); TransportWidgetPrivate* priv = TRANSPORT_WIDGET_GET_PRIVATE ( TRANSPORT_WIDGET(menuitem) ); TransportWidgetEvent result = transport_widget_determine_button_event ( TRANSPORT_WIDGET(menuitem), event); - if(result != TRANSPORT_NADA){ priv->current_command = result; - cairo_t *cr; - cr = gdk_cairo_create (menuitem->window); - draw ( menuitem, cr ); - cairo_destroy ( cr ); + gtk_widget_queue_draw (GTK_WIDGET(menuitem)); } return TRUE; } @@ -337,14 +326,12 @@ static gboolean transport_widget_button_release_event (GtkWidget *menuitem, GdkEventButton *event) { - //g_debug("TransportWidget::menu_release_event"); g_return_val_if_fail(IS_TRANSPORT_WIDGET(menuitem), FALSE); TransportWidget* transport = TRANSPORT_WIDGET(menuitem); TransportWidgetPrivate * priv = TRANSPORT_WIDGET_GET_PRIVATE ( transport ); TransportWidgetEvent result = transport_widget_determine_button_event ( transport, event ); - if(result != TRANSPORT_NADA){ - //g_debug("TransportWidget::menu_press_event - going to send value %i", (int)result); + if (result != TRANSPORT_NADA && priv->current_command == result){ GVariant* new_transport_state = g_variant_new_int32 ((int)result); dbusmenu_menuitem_handle_event ( priv->twin_item, "Transport state change", @@ -380,17 +367,8 @@ transport_widget_react_to_key_press_event ( TransportWidget* transport, TransportWidgetPrivate * priv = TRANSPORT_WIDGET_GET_PRIVATE ( transport ); priv->current_command = transport_event; priv->key_event = transport_event; -/* printf("transport_widget_react_to_key_press_event: before drawing\n");*/ gtk_widget_realize ( GTK_WIDGET(transport) ); - - printf ( "transport widget - react to key press event -> is the window null: %i", - gtk_widget_get_window (GTK_WIDGET (transport) ) == NULL ); - cairo_t *cr; - - printf("transport_widget_react_to_key_press_event: before drawing\n"); - cr = gdk_cairo_create ( GTK_WIDGET(transport)->window ); - draw ( GTK_WIDGET(transport), cr ); - cairo_destroy (cr); + gtk_widget_queue_draw (GTK_WIDGET(transport) ); } } @@ -400,7 +378,6 @@ transport_widget_react_to_key_release_event ( TransportWidget* transport, { if(transport_event != TRANSPORT_NADA){ TransportWidgetPrivate * priv = TRANSPORT_WIDGET_GET_PRIVATE ( transport ); - //g_debug("TransportWidget::menu_press_event - going to send value %i", (int)result); GVariant* new_transport_event = g_variant_new_int32((int)transport_event); dbusmenu_menuitem_handle_event ( priv->twin_item, "Transport state change", @@ -416,53 +393,41 @@ transport_widget_focus_update ( TransportWidget* transport, gboolean focus ) { TransportWidgetPrivate * priv = TRANSPORT_WIDGET_GET_PRIVATE ( transport ); priv->has_focus = focus; - g_debug("new focus update = %i", focus); } static TransportWidgetEvent transport_widget_determine_button_event( TransportWidget* button, GdkEventButton* event ) { - //g_debug("event x coordinate = %f", event->x); - //g_debug("event y coordinate = %f", event->y); - TransportWidgetEvent button_event = TRANSPORT_NADA; - // For now very simple rectangular collision detection - if(event->x > 67 && event->x < 112 - && event->y > 12 && event->y < 40){ - button_event = TRANSPORT_PREVIOUS; - } - else if(event->x > 111 && event->x < 153 - && event->y > 5 && event->y < 47){ - button_event = TRANSPORT_PLAY_PAUSE; - } - else if(event->x > 152 && event->x < 197 - && event->y > 12 && event->y < 40){ - button_event = TRANSPORT_NEXT; - } - return button_event; + return transport_widget_collision_detection (event->x, event->y); } static TransportWidgetEvent transport_widget_determine_motion_event( TransportWidget* button, GdkEventMotion* event ) { -/* g_debug("event x coordinate = %f", event->x);*/ -/* g_debug("event y coordinate = %f", event->y);*/ - TransportWidgetEvent motion_event = TRANSPORT_NADA; - // For now very simple rectangular collision detection - if(event->x > 67 && event->x < 112 - && event->y > 12 && event->y < 40){ - motion_event = TRANSPORT_PREVIOUS; + return transport_widget_collision_detection (event->x, event->y); +} + +static TransportWidgetEvent +transport_widget_collision_detection ( gint x, + gint y ) +{ + TransportWidgetEvent event = TRANSPORT_NADA; + + if (x > 67 && x < 112 + && y > 12 && y < 40){ + event = TRANSPORT_PREVIOUS; } - else if(event->x > 111 && event->x < 153 - && event->y > 5 && event->y < 47){ - motion_event = TRANSPORT_PLAY_PAUSE; + else if (x > 111 && x < 153 + && y > 5 && y < 47){ + event = TRANSPORT_PLAY_PAUSE; } - else if(event->x > 152 && event->x < 197 - && event->y > 12 && event->y < 40){ - motion_event = TRANSPORT_NEXT; - } - return motion_event; + else if (x > 152 && x < 197 + && y > 12 && y < 40){ + event = TRANSPORT_NEXT; + } + return event; } static void @@ -471,17 +436,11 @@ transport_widget_react_to_button_release ( TransportWidget* button, { g_return_if_fail(IS_TRANSPORT_WIDGET(button)); TransportWidgetPrivate* priv = TRANSPORT_WIDGET_GET_PRIVATE(button); - if(priv->current_command != TRANSPORT_NADA && - command != TRANSPORT_NADA){ - priv->current_command = command; - } - cairo_t *cr; - cr = gdk_cairo_create ( GTK_WIDGET(button)->window ); priv->current_command = TRANSPORT_NADA; priv->key_event = TRANSPORT_NADA; - draw ( GTK_WIDGET(button), cr ); - cairo_destroy (cr); + + gtk_widget_queue_draw (GTK_WIDGET(button)); } /// internal helper functions ////////////////////////////////////////////////// |