From 812adbd27ed4f5af7a0a78c9ad62e4b9337d8c0a Mon Sep 17 00:00:00 2001 From: Lars Uebernickel Date: Fri, 19 Jul 2013 10:39:34 +0200 Subject: Specify fallback icons The *-panel suffix is only used by the ubuntu-mono icon themes. --- src/service.vala | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) (limited to 'src/service.vala') diff --git a/src/service.vala b/src/service.vala index 3d14d5e..e13c02e 100644 --- a/src/service.vala +++ b/src/service.vala @@ -62,7 +62,7 @@ public class IndicatorSound.Service { } const ActionEntry[] action_entries = { - { "root", null, null, "{ 'icon': <'audio-volume-high-panel'> }", null }, + { "root", null, null, "@a{sv} {}", null }, { "settings", activate_settings, null, null, null }, }; @@ -92,6 +92,13 @@ public class IndicatorSound.Service { } } + /* Returns a serialized version of @icon_name suited for the panel */ + static Variant serialize_themed_icon (string icon_name) + { + var icon = new ThemedIcon.with_default_fallbacks (icon_name); + return g_icon_serialize (icon); + } + static Menu create_root_menu (Menu submenu) { var root = new MenuItem (null, "indicator.root"); root.set_attribute ("x-canonical-type", "s", "com.canonical.indicator.root"); @@ -109,8 +116,8 @@ public class IndicatorSound.Service { var slider = new MenuItem (null, "indicator.volume"); slider.set_attribute ("x-canonical-type", "s", "com.canonical.unity.slider"); - slider.set_attribute_value ("min-icon", g_icon_serialize (new ThemedIcon ("audio-volume-low-zero-panel"))); - slider.set_attribute_value ("max-icon", g_icon_serialize (new ThemedIcon ("audio-volume-high-panel"))); + slider.set_attribute_value ("min-icon", serialize_themed_icon ("audio-volume-low-zero-panel")); + slider.set_attribute_value ("max-icon", serialize_themed_icon ("audio-volume-high-panel")); slider.set_attribute ("min-value", "d", 0.0); slider.set_attribute ("max-value", "d", 1.0); slider.set_attribute ("step", "d", 0.01); @@ -129,8 +136,8 @@ public class IndicatorSound.Service { if (volume_section.get_n_items () < 3) { var slider = new MenuItem (null, "indicator.mic-volume"); slider.set_attribute ("x-canonical-type", "s", "com.canonical.unity.slider"); - slider.set_attribute_value ("min-icon", g_icon_serialize (new ThemedIcon ("audio-input-microphone-low-zero-panel"))); - slider.set_attribute_value ("max-icon", g_icon_serialize (new ThemedIcon ("audio-input-microphone-high-panel"))); + slider.set_attribute_value ("min-icon", serialize_themed_icon ("audio-input-microphone-low-zero-panel")); + slider.set_attribute_value ("max-icon", serialize_themed_icon ("audio-input-microphone-high-panel")); slider.set_attribute ("min-value", "d", 0.0); slider.set_attribute ("max-value", "d", 1.0); slider.set_attribute ("step", "d", 0.01); @@ -158,7 +165,7 @@ public class IndicatorSound.Service { icon = "audio-volume-high-panel"; var root_action = this.actions.lookup ("root") as SimpleAction; - root_action.set_state (new Variant.parsed ("{ 'icon': <%s> }", icon)); + root_action.set_state (new Variant.parsed ("{ 'icon': %v }", serialize_themed_icon (icon))); } Action create_mute_action () { -- cgit v1.2.3 From c416b3463055a0167f2e1412c7442674de5e75d8 Mon Sep 17 00:00:00 2001 From: Lars Uebernickel Date: Thu, 25 Jul 2013 15:56:04 +0200 Subject: service.vala: move menu handling into sound-menu.vala This makes service.vala a lot more readable and makes way for exporting a second - slightly different - menu for the phone profile. --- src/service.vala | 131 +++---------------------------------------------------- 1 file changed, 6 insertions(+), 125 deletions(-) (limited to 'src/service.vala') diff --git a/src/service.vala b/src/service.vala index e13c02e..eeb0a30 100644 --- a/src/service.vala +++ b/src/service.vala @@ -25,7 +25,6 @@ public class IndicatorSound.Service { this.settings = new Settings ("com.canonical.indicator.sound"); this.volume_control = new VolumeControl (); - this.volume_control.notify["active-mic"].connect (active_mic_changed); this.players = new MediaPlayerList (); this.players.player_added.connect (this.player_added); @@ -37,8 +36,8 @@ public class IndicatorSound.Service { this.actions.add_action (this.create_volume_action ()); this.actions.add_action (this.create_mic_volume_action ()); - this.menu = create_menu (); - this.root_menu = create_root_menu (this.menu); + this.menu = new SoundMenu (); + this.volume_control.bind_property ("active-mic", this.menu, "show-mic-volume", BindingFlags.SYNC_CREATE); this.players.sync (settings.get_strv ("interested-media-players")); this.settings.changed["interested-media-players"].connect ( () => { @@ -68,8 +67,7 @@ public class IndicatorSound.Service { MainLoop loop; SimpleActionGroup actions; - Menu root_menu; - Menu menu; + SoundMenu menu; Settings settings; VolumeControl volume_control; MediaPlayerList players; @@ -99,57 +97,6 @@ public class IndicatorSound.Service { return g_icon_serialize (icon); } - static Menu create_root_menu (Menu submenu) { - var root = new MenuItem (null, "indicator.root"); - root.set_attribute ("x-canonical-type", "s", "com.canonical.indicator.root"); - root.set_submenu (submenu); - - var menu = new Menu (); - menu.append_item (root); - - return menu; - } - - static Menu create_menu () { - var volume_section = new Menu (); - volume_section.append (_("Mute"), "indicator.mute"); - - var slider = new MenuItem (null, "indicator.volume"); - slider.set_attribute ("x-canonical-type", "s", "com.canonical.unity.slider"); - slider.set_attribute_value ("min-icon", serialize_themed_icon ("audio-volume-low-zero-panel")); - slider.set_attribute_value ("max-icon", serialize_themed_icon ("audio-volume-high-panel")); - slider.set_attribute ("min-value", "d", 0.0); - slider.set_attribute ("max-value", "d", 1.0); - slider.set_attribute ("step", "d", 0.01); - volume_section.append_item (slider); - - var menu = new Menu (); - menu.append_section (null, volume_section); - menu.append (_("Sound Settingsā€¦"), "indicator.settings"); - - return menu; - } - - void active_mic_changed () { - var volume_section = this.menu.get_item_link (0, "section") as Menu; - if (this.volume_control.active_mic) { - if (volume_section.get_n_items () < 3) { - var slider = new MenuItem (null, "indicator.mic-volume"); - slider.set_attribute ("x-canonical-type", "s", "com.canonical.unity.slider"); - slider.set_attribute_value ("min-icon", serialize_themed_icon ("audio-input-microphone-low-zero-panel")); - slider.set_attribute_value ("max-icon", serialize_themed_icon ("audio-input-microphone-high-panel")); - slider.set_attribute ("min-value", "d", 0.0); - slider.set_attribute ("max-value", "d", 1.0); - slider.set_attribute ("step", "d", 0.01); - volume_section.append_item (slider); - } - } - else { - if (volume_section.get_n_items () > 2) - volume_section.remove (2); - } - } - void update_root_icon () { double volume = this.volume_control.get_volume (); string icon; @@ -227,7 +174,7 @@ public class IndicatorSound.Service { void bus_acquired (DBusConnection connection, string name) { try { connection.export_action_group ("/com/canonical/indicator/sound", this.actions); - connection.export_menu_model ("/com/canonical/indicator/sound/desktop", this.root_menu); + this.menu.export (connection, "/com/canonical/indicator/sound/desktop"); } catch (Error e) { critical ("%s", e.message); } @@ -273,53 +220,8 @@ public class IndicatorSound.Service { this.settings.set_value ("interested-media-players", builder.end ()); } - void update_playlists (MediaPlayer player) { - int index = find_player_section (player); - if (index < 0) - return; - - var section = this.menu.get_item_link (index, Menu.LINK_SECTION) as Menu; - - /* if a section has three items, the playlists menu is in it */ - if (section.get_n_items () == 3) - section.remove (2); - - if (!player.is_running) - return; - - var count = player.get_n_playlists (); - if (count == 0) - return; - - var playlists_section = new Menu (); - for (int i = 0; i < count; i++) { - var playlist_id = player.get_playlist_id (i); - playlists_section.append (player.get_playlist_name (i), - @"indicator.play-playlist.$(player.id)::$playlist_id"); - - } - - var submenu = new Menu (); - submenu.append_section (null, playlists_section); - section.append_submenu ("Choose Playlist", submenu); - } - void player_added (MediaPlayer player) { - var player_item = new MenuItem (player.name, "indicator." + player.id); - player_item.set_attribute ("x-canonical-type", "s", "com.canonical.unity.media-player"); - player_item.set_attribute_value ("icon", g_icon_serialize (player.icon)); - - var playback_item = new MenuItem (null, null); - playback_item.set_attribute ("x-canonical-type", "s", "com.canonical.unity.playback-item"); - playback_item.set_attribute ("x-canonical-play-action", "s", "indicator.play." + player.id); - playback_item.set_attribute ("x-canonical-next-action", "s", "indicator.next." + player.id); - playback_item.set_attribute ("x-canonical-previous-action", "s", "indicator.previous." + player.id); - - var section = new Menu (); - section.append_item (player_item); - section.append_item (playback_item); - - this.menu.insert_section (this.menu.get_n_items () -1, null, section); + this.menu.add_player (player); SimpleAction action = new SimpleAction.stateful (player.id, null, this.action_state_for_player (player)); action.activate.connect ( () => { player.launch (); }); @@ -347,28 +249,9 @@ public class IndicatorSound.Service { player.notify.connect (this.eventually_update_player_actions); - player.playlists_changed.connect (this.update_playlists); - player.notify["is-running"].connect ( () => this.update_playlists (player) ); - update_playlists (player); - this.update_preferred_players (); } - /* returns the position in this.menu of the section that's associated with @player */ - int find_player_section (MediaPlayer player) { - string action_name = @"indicator.$(player.id)"; - int n = this.menu.get_n_items () -1; - for (int i = 1; i < n; i++) { - var section = this.menu.get_item_link (i, Menu.LINK_SECTION); - string action; - section.get_item_attribute (0, "action", "s", out action); - if (action == action_name) - return i; - } - - return -1; - } - void player_removed (MediaPlayer player) { this.actions.remove (player.id); this.actions.remove ("play." + player.id); @@ -376,9 +259,7 @@ public class IndicatorSound.Service { this.actions.remove ("previous." + player.id); this.actions.remove ("play-playlist." + player.id); - int index = this.find_player_section (player); - if (index >= 0) - this.menu.remove (index); + this.menu.remove_player (player); this.update_preferred_players (); } -- cgit v1.2.3 From 997864b9fc62596e8cc238f4c4b77d780651ffb4 Mon Sep 17 00:00:00 2001 From: Lars Uebernickel Date: Thu, 25 Jul 2013 16:21:44 +0200 Subject: service.vala: store menus in a hash table, keyed by profile name --- src/service.vala | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) (limited to 'src/service.vala') diff --git a/src/service.vala b/src/service.vala index eeb0a30..c1c6306 100644 --- a/src/service.vala +++ b/src/service.vala @@ -36,8 +36,9 @@ public class IndicatorSound.Service { this.actions.add_action (this.create_volume_action ()); this.actions.add_action (this.create_mic_volume_action ()); - this.menu = new SoundMenu (); - this.volume_control.bind_property ("active-mic", this.menu, "show-mic-volume", BindingFlags.SYNC_CREATE); + this.menus = new HashTable (str_hash, str_equal); + this.menus.insert ("desktop", new SoundMenu ()); + this.volume_control.bind_property ("active-mic", this.menus.get("desktop"), "show-mic-volume", BindingFlags.SYNC_CREATE); this.players.sync (settings.get_strv ("interested-media-players")); this.settings.changed["interested-media-players"].connect ( () => { @@ -67,7 +68,7 @@ public class IndicatorSound.Service { MainLoop loop; SimpleActionGroup actions; - SoundMenu menu; + HashTable menus; Settings settings; VolumeControl volume_control; MediaPlayerList players; @@ -174,10 +175,11 @@ public class IndicatorSound.Service { void bus_acquired (DBusConnection connection, string name) { try { connection.export_action_group ("/com/canonical/indicator/sound", this.actions); - this.menu.export (connection, "/com/canonical/indicator/sound/desktop"); } catch (Error e) { critical ("%s", e.message); } + + this.menus.@foreach ( (profile, menu) => menu.export (connection, @"/com/canonical/indicator/sound/$profile")); } void name_lost (DBusConnection connection, string name) { @@ -221,7 +223,7 @@ public class IndicatorSound.Service { } void player_added (MediaPlayer player) { - this.menu.add_player (player); + this.menus.@foreach ( (profile, menu) => menu.add_player (player)); SimpleAction action = new SimpleAction.stateful (player.id, null, this.action_state_for_player (player)); action.activate.connect ( () => { player.launch (); }); @@ -259,7 +261,7 @@ public class IndicatorSound.Service { this.actions.remove ("previous." + player.id); this.actions.remove ("play-playlist." + player.id); - this.menu.remove_player (player); + this.menus.@foreach ( (profile, menu) => menu.remove_player (player)); this.update_preferred_players (); } -- cgit v1.2.3 From ce5583c3d5c8f4cf390936ef567c7088062675df Mon Sep 17 00:00:00 2001 From: Lars Uebernickel Date: Thu, 25 Jul 2013 16:38:15 +0200 Subject: Export phone menu For now, this does the same as the one on the desktop, except for starting the the phone's settings ui. --- src/service.vala | 21 +++++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) (limited to 'src/service.vala') diff --git a/src/service.vala b/src/service.vala index c1c6306..8fbd871 100644 --- a/src/service.vala +++ b/src/service.vala @@ -37,8 +37,12 @@ public class IndicatorSound.Service { this.actions.add_action (this.create_mic_volume_action ()); this.menus = new HashTable (str_hash, str_equal); - this.menus.insert ("desktop", new SoundMenu ()); - this.volume_control.bind_property ("active-mic", this.menus.get("desktop"), "show-mic-volume", BindingFlags.SYNC_CREATE); + this.menus.insert ("desktop", new SoundMenu ("indicator.desktop-settings")); + this.menus.insert ("phone", new SoundMenu ("indicator.phone-settings")); + + this.menus.@foreach ( (profile, menu) => { + this.volume_control.bind_property ("active-mic", menu, "show-mic-volume", BindingFlags.SYNC_CREATE); + }); this.players.sync (settings.get_strv ("interested-media-players")); this.settings.changed["interested-media-players"].connect ( () => { @@ -63,7 +67,8 @@ public class IndicatorSound.Service { const ActionEntry[] action_entries = { { "root", null, null, "@a{sv} {}", null }, - { "settings", activate_settings, null, null, null }, + { "desktop-settings", activate_desktop_settings, null, null, null }, + { "phone-settings", activate_phone_settings, null, null, null }, }; MainLoop loop; @@ -74,7 +79,7 @@ public class IndicatorSound.Service { MediaPlayerList players; uint player_action_update_id; - void activate_settings (SimpleAction action, Variant? param) { + void activate_desktop_settings (SimpleAction action, Variant? param) { var env = Environment.get_variable ("DESKTOP_SESSION"); string cmd; if (env == "unity") @@ -91,6 +96,14 @@ public class IndicatorSound.Service { } } + void activate_phone_settings (SimpleAction action, Variant? param) { + try { + Process.spawn_command_line_async ("system-settings sound"); + } catch (Error e) { + warning ("unable to launch sound settings: %s", e.message); + } + } + /* Returns a serialized version of @icon_name suited for the panel */ static Variant serialize_themed_icon (string icon_name) { -- cgit v1.2.3 From a67fff57b9a0c12ca90fc37905893891c99234b4 Mon Sep 17 00:00:00 2001 From: Charles Kerr Date: Thu, 8 Aug 2013 16:43:39 -0500 Subject: add accessible-name property to the ng sound indicator --- src/service.vala | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) (limited to 'src/service.vala') diff --git a/src/service.vala b/src/service.vala index 8fbd871..690fdce 100644 --- a/src/service.vala +++ b/src/service.vala @@ -125,8 +125,20 @@ public class IndicatorSound.Service { else icon = "audio-volume-high-panel"; - var root_action = this.actions.lookup ("root") as SimpleAction; - root_action.set_state (new Variant.parsed ("{ 'icon': %v }", serialize_themed_icon (icon))); + string accessible_name; + if (this.volume_control.mute) { + accessible_name = "Volume (muted)"; + } else { + int volume_int = (int)(volume * 100); + accessible_name = @"Volume ($volume_int%)"; + } + + var root_action = actions.lookup ("root") as SimpleAction; + var builder = new VariantBuilder (new VariantType ("a{sv}")); + builder.add ("{sv}", "accessible-desc", new Variant.string (accessible_name)); + builder.add ("{sv}", "icon", serialize_themed_icon (icon)); + builder.add ("{sv}", "visible", new Variant.boolean (true)); + root_action.set_state (builder.end()); } Action create_mute_action () { -- cgit v1.2.3 From 796a887cf88c1ad23ab06e89435ca1e04080aaee Mon Sep 17 00:00:00 2001 From: Pete Woods Date: Fri, 16 Aug 2013 04:13:41 +0100 Subject: Build using cmake --- src/service.vala | 3 --- 1 file changed, 3 deletions(-) (limited to 'src/service.vala') diff --git a/src/service.vala b/src/service.vala index 690fdce..ac3ba5b 100644 --- a/src/service.vala +++ b/src/service.vala @@ -17,9 +17,6 @@ * Lars Uebernickel */ -/* Icon.serialize() is not yet in gio-2.0.vapi; remove this when it is */ -extern Variant? g_icon_serialize (Icon icon); - public class IndicatorSound.Service { public Service () { this.settings = new Settings ("com.canonical.indicator.sound"); -- cgit v1.2.3 From 7009ba12b5c14eb064062b575b586e528b65ada3 Mon Sep 17 00:00:00 2001 From: Charles Kerr Date: Thu, 22 Aug 2013 11:15:09 -0500 Subject: don't use deprecated GSimpleActionGroup APIs --- src/service.vala | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) (limited to 'src/service.vala') diff --git a/src/service.vala b/src/service.vala index ac3ba5b..4d64502 100644 --- a/src/service.vala +++ b/src/service.vala @@ -28,7 +28,7 @@ public class IndicatorSound.Service { this.players.player_removed.connect (this.player_removed); this.actions = new SimpleActionGroup (); - this.actions.add_entries (action_entries, this); + this.actions.add_action_entries (action_entries, this); this.actions.add_action (this.create_mute_action ()); this.actions.add_action (this.create_volume_action ()); this.actions.add_action (this.create_mic_volume_action ()); @@ -130,7 +130,7 @@ public class IndicatorSound.Service { accessible_name = @"Volume ($volume_int%)"; } - var root_action = actions.lookup ("root") as SimpleAction; + var root_action = actions.lookup_action ("root") as SimpleAction; var builder = new VariantBuilder (new VariantType ("a{sv}")); builder.add ("{sv}", "accessible-desc", new Variant.string (accessible_name)); builder.add ("{sv}", "icon", serialize_themed_icon (icon)); @@ -158,7 +158,7 @@ public class IndicatorSound.Service { } void volume_changed (double volume) { - var volume_action = this.actions.lookup ("volume") as SimpleAction; + var volume_action = this.actions.lookup_action ("volume") as SimpleAction; volume_action.set_state (volume); this.update_root_icon (); @@ -223,7 +223,7 @@ public class IndicatorSound.Service { bool update_player_actions () { foreach (var player in this.players) { - SimpleAction? action = this.actions.lookup (player.id) as SimpleAction; + SimpleAction? action = this.actions.lookup_action (player.id) as SimpleAction; if (action != null) action.set_state (this.action_state_for_player (player)); } @@ -249,11 +249,11 @@ public class IndicatorSound.Service { SimpleAction action = new SimpleAction.stateful (player.id, null, this.action_state_for_player (player)); action.activate.connect ( () => { player.launch (); }); - this.actions.insert (action); + this.actions.add_action (action); var play_action = new SimpleAction.stateful ("play." + player.id, null, player.state); play_action.activate.connect ( () => player.play_pause () ); - this.actions.insert (play_action); + this.actions.add_action (play_action); player.notify.connect ( (object, pspec) => { if (pspec.name == "state") play_action.set_state (player.state); @@ -261,15 +261,15 @@ public class IndicatorSound.Service { var next_action = new SimpleAction ("next." + player.id, null); next_action.activate.connect ( () => player.next () ); - this.actions.insert (next_action); + this.actions.add_action (next_action); var prev_action = new SimpleAction ("previous." + player.id, null); prev_action.activate.connect ( () => player.previous () ); - this.actions.insert (prev_action); + this.actions.add_action (prev_action); var playlist_action = new SimpleAction ("play-playlist." + player.id, VariantType.STRING); playlist_action.activate.connect ( (parameter) => player.activate_playlist_by_name (parameter.get_string ()) ); - this.actions.insert (playlist_action); + this.actions.add_action (playlist_action); player.notify.connect (this.eventually_update_player_actions); @@ -277,11 +277,11 @@ public class IndicatorSound.Service { } void player_removed (MediaPlayer player) { - this.actions.remove (player.id); - this.actions.remove ("play." + player.id); - this.actions.remove ("next." + player.id); - this.actions.remove ("previous." + player.id); - this.actions.remove ("play-playlist." + player.id); + this.actions.remove_action (player.id); + this.actions.remove_action ("play." + player.id); + this.actions.remove_action ("next." + player.id); + this.actions.remove_action ("previous." + player.id); + this.actions.remove_action ("play-playlist." + player.id); this.menus.@foreach ( (profile, menu) => menu.remove_player (player)); -- cgit v1.2.3