aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorcharles kerr <charlesk@canonical.com>2015-12-31 15:10:46 -0600
committercharles kerr <charlesk@canonical.com>2015-12-31 15:10:46 -0600
commit836e3a59e44ef0b24d42117ac3fa1324e6195a24 (patch)
treefc71221780c4a03e24fe7b653892fa259e983d03 /src
parentcdec72148f56ca1d897e91e23c7f8eec7b0ba148 (diff)
downloadayatana-indicator-sound-836e3a59e44ef0b24d42117ac3fa1324e6195a24.tar.gz
ayatana-indicator-sound-836e3a59e44ef0b24d42117ac3fa1324e6195a24.tar.bz2
ayatana-indicator-sound-836e3a59e44ef0b24d42117ac3fa1324e6195a24.zip
in icon picking code, fold redundant cases together
Diffstat (limited to 'src')
-rw-r--r--src/info-notification.vala84
-rw-r--r--src/service.vala155
2 files changed, 54 insertions, 185 deletions
diff --git a/src/info-notification.vala b/src/info-notification.vala
index 861cbee..2ce8ef6 100644
--- a/src/info-notification.vala
+++ b/src/info-notification.vala
@@ -49,68 +49,55 @@ public class IndicatorSound.InfoNotification: Notification
}
private static unowned string get_notification_label (VolumeControl.ActiveOutput active_output) {
- unowned string volume_label = "";
switch (active_output) {
case VolumeControl.ActiveOutput.SPEAKERS:
- volume_label = _("Speakers");
- break;
+ return _("Speakers");
case VolumeControl.ActiveOutput.HEADPHONES:
- volume_label = _("Headphones");
- break;
+ return _("Headphones");
case VolumeControl.ActiveOutput.BLUETOOTH_HEADPHONES:
- volume_label = _("Bluetooth headphones");
- break;
+ return _("Bluetooth headphones");
case VolumeControl.ActiveOutput.BLUETOOTH_SPEAKER:
- volume_label = _("Bluetooth speaker");
- break;
+ return _("Bluetooth speaker");
case VolumeControl.ActiveOutput.USB_SPEAKER:
- volume_label = _("Usb speaker");
- break;
+ return _("Usb speaker");
case VolumeControl.ActiveOutput.USB_HEADPHONES:
- volume_label = _("Usb headphones");
- break;
+ return _("Usb headphones");
case VolumeControl.ActiveOutput.HDMI_SPEAKER:
- volume_label = _("HDMI speaker");
- break;
+ return _("HDMI speaker");
case VolumeControl.ActiveOutput.HDMI_HEADPHONES:
- volume_label = _("HDMI headphones");
- break;
+ return _("HDMI headphones");
+ default:
+ return "";
}
-
- return volume_label;
}
private static unowned string get_volume_notification_icon (VolumeControl.ActiveOutput active_output,
double volume,
bool is_high_volume) {
- unowned string icon = "";
- if (is_high_volume) {
- switch (active_output) {
- case VolumeControl.ActiveOutput.SPEAKERS:
- case VolumeControl.ActiveOutput.HEADPHONES:
- case VolumeControl.ActiveOutput.BLUETOOTH_HEADPHONES:
- case VolumeControl.ActiveOutput.BLUETOOTH_SPEAKER:
- case VolumeControl.ActiveOutput.USB_SPEAKER:
- case VolumeControl.ActiveOutput.USB_HEADPHONES:
- case VolumeControl.ActiveOutput.HDMI_SPEAKER:
- case VolumeControl.ActiveOutput.HDMI_HEADPHONES:
- icon = "audio-volume-high";
- break;
- }
- } else {
- icon = get_volume_icon (active_output, volume);
- }
+ if (!is_high_volume)
+ return get_volume_icon (active_output, volume);
- return icon;
+ switch (active_output) {
+ case VolumeControl.ActiveOutput.SPEAKERS:
+ case VolumeControl.ActiveOutput.HEADPHONES:
+ case VolumeControl.ActiveOutput.BLUETOOTH_HEADPHONES:
+ case VolumeControl.ActiveOutput.BLUETOOTH_SPEAKER:
+ case VolumeControl.ActiveOutput.USB_SPEAKER:
+ case VolumeControl.ActiveOutput.USB_HEADPHONES:
+ case VolumeControl.ActiveOutput.HDMI_SPEAKER:
+ case VolumeControl.ActiveOutput.HDMI_HEADPHONES:
+ return "audio-volume-high";
+
+ default:
+ return "";
+ }
}
private static unowned string get_volume_icon (VolumeControl.ActiveOutput active_output,
double volume)
{
- unowned string icon = "";
-
switch (active_output) {
case VolumeControl.ActiveOutput.SPEAKERS:
case VolumeControl.ActiveOutput.HEADPHONES:
@@ -121,17 +108,16 @@ public class IndicatorSound.InfoNotification: Notification
case VolumeControl.ActiveOutput.HDMI_SPEAKER:
case VolumeControl.ActiveOutput.HDMI_HEADPHONES:
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";
- break;
+ return "audio-volume-muted";
+ if (volume <= 0.3)
+ return "audio-volume-low";
+ if (volume <= 0.7)
+ return "audio-volume-medium";
+ return "audio-volume-high";
+
+ default:
+ return "";
}
-
- return icon;
}
}
diff --git a/src/service.vala b/src/service.vala
index c81c62b..29b8670 100644
--- a/src/service.vala
+++ b/src/service.vala
@@ -276,165 +276,48 @@ public class IndicatorSound.Service: Object {
private bool block_info_notifications = false;
- private static unowned string get_volume_root_icon_by_volume (double volume, VolumeControl.ActiveOutput active_output)
- {
- unowned string icon = "";
- switch (active_output)
- {
+ private static unowned string get_volume_root_icon_by_volume (double volume, VolumeControl.ActiveOutput active_output) {
+ switch (active_output) {
case VolumeControl.ActiveOutput.SPEAKERS:
- if (volume <= 0.0)
- 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";
- break;
case VolumeControl.ActiveOutput.HEADPHONES:
- if (volume <= 0.0)
- 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";
- break;
case VolumeControl.ActiveOutput.BLUETOOTH_HEADPHONES:
- if (volume <= 0.0)
- 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";
- break;
case VolumeControl.ActiveOutput.BLUETOOTH_SPEAKER:
- if (volume <= 0.0)
- 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";
- break;
case VolumeControl.ActiveOutput.USB_SPEAKER:
- if (volume <= 0.0)
- 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";
- break;
case VolumeControl.ActiveOutput.USB_HEADPHONES:
- if (volume <= 0.0)
- 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";
- break;
case VolumeControl.ActiveOutput.HDMI_SPEAKER:
- if (volume <= 0.0)
- 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";
- break;
case VolumeControl.ActiveOutput.HDMI_HEADPHONES:
if (volume <= 0.0)
- 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";
- break;
+ return "audio-volume-muted-panel";
+ if (volume <= 0.3)
+ return "audio-volume-low-panel";
+ if (volume <= 0.7)
+ return "audio-volume-medium-panel";
+ return "audio-volume-high-panel";
+
+ default:
+ return "";
}
- return icon;
}
private unowned string get_volume_root_icon (double volume, bool mute, VolumeControl.ActiveOutput active_output) {
- unowned string icon = "";
- switch (active_output)
- {
+ switch (active_output) {
case VolumeControl.ActiveOutput.SPEAKERS:
- 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
- icon = get_volume_root_icon_by_volume (volume, active_output);
- break;
case VolumeControl.ActiveOutput.HEADPHONES:
- 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
- icon = get_volume_root_icon_by_volume (volume, active_output);
- break;
case VolumeControl.ActiveOutput.BLUETOOTH_HEADPHONES:
- 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
- icon = get_volume_root_icon_by_volume (volume, active_output);
- break;
case VolumeControl.ActiveOutput.BLUETOOTH_SPEAKER:
- 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
- icon = get_volume_root_icon_by_volume (volume, active_output);
- break;
case VolumeControl.ActiveOutput.USB_SPEAKER:
- 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
- icon = get_volume_root_icon_by_volume (volume, active_output);
- break;
case VolumeControl.ActiveOutput.USB_HEADPHONES:
- 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
- icon = get_volume_root_icon_by_volume (volume, active_output);
- break;
case VolumeControl.ActiveOutput.HDMI_SPEAKER:
- 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
- icon = get_volume_root_icon_by_volume (volume, active_output);
- break;
case VolumeControl.ActiveOutput.HDMI_HEADPHONES:
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
- icon = get_volume_root_icon_by_volume (volume, active_output);
- break;
+ return this.mute_blocks_sound ? "audio-volume-muted-blocking-panel" : "audio-volume-muted-panel";
+ if (this.accounts_service != null && this.accounts_service.silentMode)
+ return "audio-volume-muted-panel";
+ return get_volume_root_icon_by_volume (volume, active_output);
+
+ default:
+ return "";
}
- return icon;
}
private void update_notification () {