From a7fd579fd1bc6eb02433ccd72e9f54dca2615675 Mon Sep 17 00:00:00 2001 From: Xavi Garcia Mena Date: Tue, 29 Sep 2015 14:13:45 +0200 Subject: Adding the code to change the icons and label when a bluetooth headset is connected --- src/service.vala | 93 ++++++++++++++++++++++++++++++++++++++++---------------- 1 file changed, 67 insertions(+), 26 deletions(-) (limited to 'src/service.vala') diff --git a/src/service.vala b/src/service.vala index a08edf3..6215c85 100644 --- a/src/service.vala +++ b/src/service.vala @@ -52,6 +52,7 @@ public class IndicatorSound.Service: Object { this.notify["visible"].connect ( () => this.update_root_icon () ); this.volume_control = volume; + this.volume_control.bluetooth_headset_status_changed.connect (this.update_root_icon); this.accounts_service = accounts; /* If we're on the greeter, don't export */ @@ -90,6 +91,10 @@ public class IndicatorSound.Service: Object { this.volume_control.bind_property ("high-volume", menu, "show-high-volume-warning", BindingFlags.SYNC_CREATE); }); + this.menus.@foreach ( (profile, menu) => { + this.volume_control.bluetooth_headset_status_changed.connect (menu.update_volume_slider); + }); + this.sync_preferred_players (); this.settings.changed["interested-media-players"].connect ( () => { this.sync_preferred_players (); @@ -245,17 +250,7 @@ public class IndicatorSound.Service: Object { void update_root_icon () { double volume = this.volume_control.volume.volume; - string icon; - if (this.volume_control.mute || volume <= 0.0) - icon = this.mute_blocks_sound ? "audio-volume-muted-blocking-panel" : "audio-volume-muted-panel"; - else if (this.accounts_service != null && this.accounts_service.silentMode) - icon = "audio-volume-muted-panel"; - else if (volume <= 0.3) - icon = "audio-volume-low-panel"; - else if (volume <= 0.7) - icon = "audio-volume-medium-panel"; - else - icon = "audio-volume-high-panel"; + string icon = get_volume_root_icon (volume, this.volume_control.mute, volume_control.active_bluetooth_headphone); string accessible_name; if (this.volume_control.mute) { @@ -282,6 +277,66 @@ public class IndicatorSound.Service: Object { private bool notify_server_supports_sync = false; private bool block_info_notifications = false; + private string get_volume_notification_icon (double volume, bool loud, bool is_bluetooth_headset_active) { + string icon = ""; + if (is_bluetooth_headset_active) { + if (loud) { + icon = "audio-volume-high"; + } else { + if (volume <= 0.0) + icon = "audio-volume-muted"; + else if (volume <= 0.3) + icon = "audio-volume-low"; + else if (volume <= 0.7) + icon = "audio-volume-medium"; + else + icon = "audio-volume-high"; + } + } else { + if (loud) { + icon = "audio-volume-high"; + } else { + if (volume <= 0.0) + icon = "audio-volume-muted"; + else if (volume <= 0.3) + icon = "audio-volume-low"; + else if (volume <= 0.7) + icon = "audio-volume-medium"; + else + icon = "audio-volume-high"; + } + } + return icon; + } + + private string get_volume_root_icon (double volume, bool mute, bool is_bluetooth_headset_active) { + string icon; + if (is_bluetooth_headset_active) { + if (mute || volume <= 0.0) + icon = this.mute_blocks_sound ? "audio-volume-muted-blocking-panel" : "audio-volume-muted-panel"; + else if (this.accounts_service != null && this.accounts_service.silentMode) + icon = "audio-volume-muted-panel"; + else if (volume <= 0.3) + icon = "audio-volume-low-panel"; + else if (volume <= 0.7) + icon = "audio-volume-medium-panel"; + else + icon = "audio-volume-high-panel"; + } else { + if (mute || volume <= 0.0) + icon = this.mute_blocks_sound ? "audio-volume-muted-blocking-panel" : "audio-volume-muted-panel"; + else if (this.accounts_service != null && this.accounts_service.silentMode) + icon = "audio-volume-muted-panel"; + else if (volume <= 0.3) + icon = "audio-volume-low-panel"; + else if (volume <= 0.7) + icon = "audio-volume-medium-panel"; + else + icon = "audio-volume-high-panel"; + } + return icon; + } + private void update_notification () { if (!notify_server_caps_checked) { @@ -328,21 +383,7 @@ public class IndicatorSound.Service: Object { : ""; /* Choose an icon */ - unowned string icon; - if (loud) { - icon = "audio-volume-high"; - } else { - var volume = volume_control.volume.volume; - - if (volume <= 0.0) - icon = "audio-volume-muted"; - else if (volume <= 0.3) - icon = "audio-volume-low"; - else if (volume <= 0.7) - icon = "audio-volume-medium"; - else - icon = "audio-volume-high"; - } + string icon = get_volume_notification_icon (volume_control.volume.volume, loud, volume_control.active_bluetooth_headphone); /* Reset the notification */ var n = this.info_notification; -- cgit v1.2.3