From e0eac1c9d9a050dc44d0883f556753f6f8d1a7b6 Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Tue, 2 Dec 2014 18:55:00 -0600 Subject: Moving the notification into the service --- src/service.vala | 62 +++++++++++++++++++++++++++++++++++++++++++++++--------- 1 file changed, 52 insertions(+), 10 deletions(-) (limited to 'src/service.vala') diff --git a/src/service.vala b/src/service.vala index fd0c08d..1a9034b 100644 --- a/src/service.vala +++ b/src/service.vala @@ -19,6 +19,8 @@ public class IndicatorSound.Service: Object { public Service (MediaPlayerList playerlist) { + sync_notification = new Notify.Notification(_("Volume"), "", "audio-volume-muted"); + this.settings = new Settings ("com.canonical.indicator.sound"); this.sharedsettings = new Settings ("com.ubuntu.sound"); @@ -143,7 +145,7 @@ public class IndicatorSound.Service: Object { } /* Normalize volume, because the volume action's state is [0.0, 1.0], see create_volume_action() */ - this.actions.change_action_state ("volume", this.volume_control.get_volume () / this.max_volume); + this.actions.change_action_state ("volume", this.volume_control.volume / this.max_volume); } } @@ -168,6 +170,7 @@ public class IndicatorSound.Service: Object { bool syncing_preferred_players = false; AccountsServiceUser? accounts_service = null; bool export_to_accounts_service = false; + private Notify.Notification sync_notification; /* Maximum volume as a scaling factor between the volume action's state and the value in * this.volume_control. See create_volume_action(). @@ -179,8 +182,8 @@ public class IndicatorSound.Service: Object { void activate_scroll_action (SimpleAction action, Variant? param) { int delta = param.get_int32(); /* positive for up, negative for down */ - double v = this.volume_control.get_volume () + volume_step_percentage * delta; - this.volume_control.set_volume (v.clamp (0.0, this.max_volume)); + double v = this.volume_control.volume + volume_step_percentage * delta; + this.volume_control.volume = v.clamp (0.0, this.max_volume); /* TODO: Don't want to mess up the desktop today, but we should remove this scrolling change and merge that into volume control's notification */ @@ -238,7 +241,7 @@ public class IndicatorSound.Service: Object { } void update_root_icon () { - double volume = this.volume_control.get_volume (); + double volume = this.volume_control.volume; string icon; if (this.volume_control.mute) icon = this.mute_blocks_sound ? "audio-volume-muted-blocking-panel" : "audio-volume-muted-panel"; @@ -268,6 +271,44 @@ public class IndicatorSound.Service: Object { root_action.set_state (builder.end()); } + void update_sync_notification () { + /* Determine Label */ + string volume_label = ""; + if (volume_control.high_volume) + volume_label = _("High volume"); + + /* Choose an icon */ + string icon = "audio-volume-muted"; + if (volume_control.volume <= 0.0) + icon = "audio-volume-muted"; + else if (volume_control.volume <= 0.3) + icon = "audio-volume-low"; + else if (volume_control.volume <= 0.7) + icon = "audio-volume-medium"; + else + icon = "audio-volume-high"; + + /* Check tint */ + string tint = "false"; + if (volume_control.high_volume) + tint = "true"; + + /* Put it all into the notification */ + sync_notification.clear_hints (); + sync_notification.update (_("Volume"), volume_label, icon); + sync_notification.set_hint ("value", (int32)(volume_control.volume * 100.0)); + sync_notification.set_hint ("x-canonical-value-bar-tint", tint); + sync_notification.set_hint ("x-canonical-private-synchronous", "true"); + sync_notification.set_hint ("x-canonical-non-shaped-icon", "true"); + + /* Show it */ + try { + sync_notification.show (); + } catch (GLib.Error e) { + warning("Unable to send volume change notification: %s", e.message); + } + } + Action create_silent_mode_action () { bool silentNow = false; if (this.accounts_service != null) { @@ -349,6 +390,7 @@ public class IndicatorSound.Service: Object { volume_action.set_state (new Variant.double (volume / this.max_volume)); this.update_root_icon (); + this.update_sync_notification (); } Action create_volume_action () { @@ -359,20 +401,20 @@ public class IndicatorSound.Service: Object { * volume_control.set_volume(). */ - double volume = this.volume_control.get_volume () / this.max_volume; + double volume = this.volume_control.volume / this.max_volume; var volume_action = new SimpleAction.stateful ("volume", VariantType.INT32, new Variant.double (volume)); volume_action.change_state.connect ( (action, val) => { double v = val.get_double () * this.max_volume; - volume_control.set_volume (v.clamp (0.0, this.max_volume)); + volume_control.volume = v.clamp (0.0, this.max_volume); }); /* activating this action changes the volume by the amount given in the parameter */ volume_action.activate.connect ( (action, param) => { int delta = param.get_int32 (); - double v = volume_control.get_volume () + volume_step_percentage * delta; - volume_control.set_volume (v.clamp (0.0, this.max_volume)); + double v = volume_control.volume + volume_step_percentage * delta; + volume_control.volume = v.clamp (0.0, this.max_volume); }); this.volume_control.volume_changed.connect (volume_changed); @@ -383,10 +425,10 @@ public class IndicatorSound.Service: Object { } Action create_mic_volume_action () { - var volume_action = new SimpleAction.stateful ("mic-volume", null, new Variant.double (this.volume_control.get_mic_volume ())); + var volume_action = new SimpleAction.stateful ("mic-volume", null, new Variant.double (this.volume_control.mic_volume)); volume_action.change_state.connect ( (action, val) => { - volume_control.set_mic_volume (val.get_double ()); + volume_control.mic_volume = val.get_double (); }); this.volume_control.mic_volume_changed.connect ( (volume) => { -- cgit v1.2.3 From f6505dfead05c0e341d7ece63510e621a45e0325 Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Wed, 3 Dec 2014 09:12:01 -0600 Subject: Remove the sync notification on scroll setting --- src/service.vala | 47 +++++++++++++++-------------------------------- 1 file changed, 15 insertions(+), 32 deletions(-) (limited to 'src/service.vala') diff --git a/src/service.vala b/src/service.vala index 1a9034b..c74b2eb 100644 --- a/src/service.vala +++ b/src/service.vala @@ -72,14 +72,6 @@ public class IndicatorSound.Service: Object { this.sync_preferred_players (); }); - if (settings.get_boolean ("show-notify-osd-on-scroll")) { - List caps = Notify.get_server_caps (); - if (caps.find_custom ("x-canonical-private-synchronous", strcmp) != null) { - this.notification = new Notify.Notification ("indicator-sound", "", ""); - this.notification.set_hint ("x-canonical-private-synchronous", "indicator-sound"); - } - } - sharedsettings.bind ("allow-amplified-volume", this, "allow-amplified-volume", SettingsBindFlags.GET); } @@ -166,7 +158,6 @@ public class IndicatorSound.Service: Object { uint player_action_update_id; bool mute_blocks_sound; uint sound_was_blocked_timeout_id; - Notify.Notification notification; bool syncing_preferred_players = false; AccountsServiceUser? accounts_service = null; bool export_to_accounts_service = false; @@ -184,29 +175,6 @@ public class IndicatorSound.Service: Object { double v = this.volume_control.volume + volume_step_percentage * delta; this.volume_control.volume = v.clamp (0.0, this.max_volume); - - /* TODO: Don't want to mess up the desktop today, but we should remove this - scrolling change and merge that into volume control's notification */ - if (this.notification != null) { - string icon; - if (v <= 0.0) - icon = "notification-audio-volume-off"; - else if (v <= 0.3) - icon = "notification-audio-volume-low"; - else if (v <= 0.7) - icon = "notification-audio-volume-medium"; - else - icon = "notification-audio-volume-high"; - - this.notification.update ("indicator-sound", "", icon); - this.notification.set_hint ("value", ((int32) (100 * v / this.max_volume)).clamp (-1, 101)); - try { - this.notification.show (); - } - catch (Error e) { - warning ("unable to show notification: %s", e.message); - } - } } void activate_desktop_settings (SimpleAction action, Variant? param) { @@ -271,7 +239,22 @@ public class IndicatorSound.Service: Object { root_action.set_state (builder.end()); } + /* TODO: Update these if the notification server leaves the bus and restarts */ + private bool check_sync_notification = false; + private bool support_sync_notification = false; + void update_sync_notification () { + if (!check_sync_notification) { + List caps = Notify.get_server_caps (); + if (caps.find_custom ("x-canonical-private-synchronous", strcmp) != null) { + support_sync_notification = true; + } + check_sync_notification = true; + } + + if (!support_sync_notification) + return; + /* Determine Label */ string volume_label = ""; if (volume_control.high_volume) -- cgit v1.2.3 From 57982f343b03175c20a4b51ccb5c853588613935 Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Wed, 3 Dec 2014 09:52:32 -0600 Subject: Add an action to track whether the indicator is shown so that we can not show notifications if it is open --- src/service.vala | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'src/service.vala') diff --git a/src/service.vala b/src/service.vala index c74b2eb..48b0cbe 100644 --- a/src/service.vala +++ b/src/service.vala @@ -146,6 +146,7 @@ public class IndicatorSound.Service: Object { { "scroll", activate_scroll_action, "i", null, null }, { "desktop-settings", activate_desktop_settings, null, null, null }, { "phone-settings", activate_phone_settings, null, null, null }, + { "indicator-shown", null, null, "@b false", null }, }; MainLoop loop; @@ -255,6 +256,10 @@ public class IndicatorSound.Service: Object { if (!support_sync_notification) return; + var shown_action = actions.lookup_action ("indicator-shown") as SimpleAction; + if (shown_action != null && shown_action.get_state().get_boolean()) + return; + /* Determine Label */ string volume_label = ""; if (volume_control.high_volume) -- cgit v1.2.3 From 31cef82276a7f6b36b9128abc770d1b6b07fffe5 Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Wed, 3 Dec 2014 10:32:44 -0600 Subject: Hide notification when the menu is shown --- src/service.vala | 12 ++++++++++++ 1 file changed, 12 insertions(+) (limited to 'src/service.vala') diff --git a/src/service.vala b/src/service.vala index 48b0cbe..dbf7d35 100644 --- a/src/service.vala +++ b/src/service.vala @@ -73,6 +73,18 @@ public class IndicatorSound.Service: Object { }); sharedsettings.bind ("allow-amplified-volume", this, "allow-amplified-volume", SettingsBindFlags.GET); + + /* Hide the notification when the menu is shown */ + var shown_action = actions.lookup_action ("indicator-shown") as SimpleAction; + shown_action.change_state.connect ((state) => { + if (state.get_boolean()) { + try { + sync_notification.close(); + } catch (Error e) { + warning("Unable to close synchronous volume notification: %s", e.message); + } + } + }); } ~Service() { -- cgit v1.2.3 From 119ae3decb89f0066dd5abf53d0ab1bef49c15c8 Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Wed, 3 Dec 2014 11:43:41 -0600 Subject: Ensuring that if high volume changes we also show a notification (i.e. the headphones were plugged in) --- src/service.vala | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) (limited to 'src/service.vala') diff --git a/src/service.vala b/src/service.vala index dbf7d35..1f9b880 100644 --- a/src/service.vala +++ b/src/service.vala @@ -51,7 +51,7 @@ public class IndicatorSound.Service: Object { 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 ()); - this.actions.add_action (this.create_high_volume_actions ()); + this.actions.add_action (this.create_high_volume_action ()); this.menus = new HashTable (str_hash, str_equal); this.menus.insert ("desktop_greeter", new SoundMenu (null, SoundMenu.DisplayFlags.SHOW_MUTE | SoundMenu.DisplayFlags.HIDE_PLAYERS | SoundMenu.DisplayFlags.GREETER_PLAYERS)); @@ -440,11 +440,13 @@ public class IndicatorSound.Service: Object { return volume_action; } - Action create_high_volume_actions () { + Action create_high_volume_action () { var high_volume_action = new SimpleAction.stateful("high-volume", null, new Variant.boolean (this.volume_control.high_volume)); - this.volume_control.notify["high-volume"].connect( () => - high_volume_action.set_state(new Variant.boolean (this.volume_control.high_volume))); + this.volume_control.notify["high-volume"].connect( () => { + high_volume_action.set_state(new Variant.boolean (this.volume_control.high_volume)); + update_sync_notification(); + }); return high_volume_action; } -- cgit v1.2.3 From 66cd2203d5fcee99d3264bc6f23c8d4683c299bf Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Wed, 3 Dec 2014 16:30:23 -0600 Subject: Switch from having custom signals for volume changing to using the property change signals. --- src/service.vala | 24 +++++++++++------------- 1 file changed, 11 insertions(+), 13 deletions(-) (limited to 'src/service.vala') diff --git a/src/service.vala b/src/service.vala index 1f9b880..c7e29e7 100644 --- a/src/service.vala +++ b/src/service.vala @@ -383,16 +383,6 @@ public class IndicatorSound.Service: Object { return mute_action; } - void volume_changed (double volume) { - var volume_action = this.actions.lookup_action ("volume") as SimpleAction; - - /* Normalize volume, because the volume action's state is [0.0, 1.0], see create_volume_action() */ - volume_action.set_state (new Variant.double (volume / this.max_volume)); - - this.update_root_icon (); - this.update_sync_notification (); - } - Action create_volume_action () { /* The action's state is between be in [0.0, 1.0] instead of [0.0, * max_volume], so that we don't need to update the slider menu item @@ -417,7 +407,15 @@ public class IndicatorSound.Service: Object { volume_control.volume = v.clamp (0.0, this.max_volume); }); - this.volume_control.volume_changed.connect (volume_changed); + this.volume_control.notify["volume"].connect (() => { + var vol_action = this.actions.lookup_action ("volume") as SimpleAction; + + /* Normalize volume, because the volume action's state is [0.0, 1.0], see create_volume_action() */ + vol_action.set_state (new Variant.double (this.volume_control.volume / this.max_volume)); + + this.update_root_icon (); + this.update_sync_notification (); + }); this.volume_control.bind_property ("ready", volume_action, "enabled", BindingFlags.SYNC_CREATE); @@ -431,8 +429,8 @@ public class IndicatorSound.Service: Object { volume_control.mic_volume = val.get_double (); }); - this.volume_control.mic_volume_changed.connect ( (volume) => { - volume_action.set_state (new Variant.double (volume)); + this.volume_control.notify["mic-volume"].connect ( () => { + volume_action.set_state (new Variant.double (this.volume_control.mic_volume)); }); this.volume_control.bind_property ("ready", volume_action, "enabled", BindingFlags.SYNC_CREATE); -- cgit v1.2.3 From 30e9118a70ef2ed337ae613b6af55245da5df4f5 Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Thu, 29 Jan 2015 11:28:58 -0600 Subject: Add a watcher for the notification server going up and down. Redetect sync notifications depending on it. --- src/service.vala | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) (limited to 'src/service.vala') diff --git a/src/service.vala b/src/service.vala index c7e29e7..f4f13ab 100644 --- a/src/service.vala +++ b/src/service.vala @@ -20,6 +20,11 @@ public class IndicatorSound.Service: Object { public Service (MediaPlayerList playerlist) { sync_notification = new Notify.Notification(_("Volume"), "", "audio-volume-muted"); + this.notification_server_watch = GLib.Bus.watch_name(GLib.BusType.SESSION, + "org.freedesktop.Notifications", + GLib.BusNameWatcherFlags.NONE, + () => { check_sync_notification = false; }, + () => { check_sync_notification = false; }); this.settings = new Settings ("com.canonical.indicator.sound"); this.sharedsettings = new Settings ("com.ubuntu.sound"); @@ -92,6 +97,11 @@ public class IndicatorSound.Service: Object { Source.remove (this.sound_was_blocked_timeout_id); this.sound_was_blocked_timeout_id = 0; } + + if (this.notification_server_watch != 0) { + GLib.Bus.unwatch_name(this.notification_server_watch); + this.notification_server_watch = 0; + } } bool greeter_show_track () { @@ -175,6 +185,7 @@ public class IndicatorSound.Service: Object { AccountsServiceUser? accounts_service = null; bool export_to_accounts_service = false; private Notify.Notification sync_notification; + private uint notification_server_watch; /* Maximum volume as a scaling factor between the volume action's state and the value in * this.volume_control. See create_volume_action(). @@ -252,7 +263,6 @@ public class IndicatorSound.Service: Object { root_action.set_state (builder.end()); } - /* TODO: Update these if the notification server leaves the bus and restarts */ private bool check_sync_notification = false; private bool support_sync_notification = false; -- cgit v1.2.3