Merge lp:~elementary-pantheon/wingpanel-indicator-sound/get_icon into lp:~wingpanel-devs/wingpanel-indicator-sound/trunk

Proposed by Danielle Foré
Status: Merged
Approved by: Danielle Foré
Approved revision: 136
Merged at revision: 136
Proposed branch: lp:~elementary-pantheon/wingpanel-indicator-sound/get_icon
Merge into: lp:~wingpanel-devs/wingpanel-indicator-sound/trunk
Diff against target: 206 lines (+40/-65)
1 file modified
src/Indicator.vala (+40/-65)
To merge this branch: bzr merge lp:~elementary-pantheon/wingpanel-indicator-sound/get_icon
Reviewer Review Type Date Requested Status
Zisu Andrei (community) Approve
Review via email: mp+313654@code.launchpad.net

Commit message

Indicator.vala:
* Fix whitespace
* Don't use this
* Don't have 3 different places where we define icons for volume levels

To post a comment you must log in.
Revision history for this message
Zisu Andrei (matzipan) wrote :

LGTM. Code runs alright too.

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'src/Indicator.vala'
--- src/Indicator.vala 2016-11-05 19:13:01 +0000
+++ src/Indicator.vala 2016-12-20 20:54:56 +0000
@@ -16,26 +16,16 @@
16 */16 */
1717
18public class Sound.Indicator : Wingpanel.Indicator {18public class Sound.Indicator : Wingpanel.Indicator {
19
20 private Wingpanel.Widgets.OverlayIcon panel_icon;
21
22 private Gtk.Grid main_grid;19 private Gtk.Grid main_grid;
23
24 private Widgets.Scale volume_scale;20 private Widgets.Scale volume_scale;
25
26 private Widgets.Scale mic_scale;21 private Widgets.Scale mic_scale;
2722 private Wingpanel.Widgets.OverlayIcon panel_icon;
28 private Wingpanel.Widgets.Button settings_button;23 private Wingpanel.Widgets.Button settings_button;
29
30 private Services.VolumeControlPulse volume_control;
31
32 private Wingpanel.Widgets.Separator first_seperator;24 private Wingpanel.Widgets.Separator first_seperator;
33
34 private Wingpanel.Widgets.Separator mic_seperator;25 private Wingpanel.Widgets.Separator mic_seperator;
35
36 private Notify.Notification notification;26 private Notify.Notification notification;
37
38 private Services.Settings settings;27 private Services.Settings settings;
28 private Services.VolumeControlPulse volume_control;
3929
40 bool open = false;30 bool open = false;
41 bool mute_blocks_sound = false;31 bool mute_blocks_sound = false;
@@ -50,19 +40,23 @@
50 Object (code_name: Wingpanel.Indicator.SOUND,40 Object (code_name: Wingpanel.Indicator.SOUND,
51 display_name: _("Indicator Sound"),41 display_name: _("Indicator Sound"),
52 description:_("The sound indicator"));42 description:_("The sound indicator"));
53 this.visible = true;43
54 this.volume_control = new Services.VolumeControlPulse ();44 visible = true;
55 this.volume_control.notify["volume"].connect (on_volume_change);45
56 this.volume_control.notify["mic-volume"].connect (on_mic_volume_change);46 volume_control = new Services.VolumeControlPulse ();
57 this.volume_control.notify["mute"].connect (on_mute_change);47 volume_control.notify["volume"].connect (on_volume_change);
58 this.volume_control.notify["micMute"].connect (on_mic_mute_change);48 volume_control.notify["mic-volume"].connect (on_mic_volume_change);
59 this.volume_control.notify["is-playing"].connect(on_is_playing_change);49 volume_control.notify["mute"].connect (on_mute_change);
60 this.volume_control.notify["is-listening"].connect(update_mic_visibility);50 volume_control.notify["micMute"].connect (on_mic_mute_change);
51 volume_control.notify["is-playing"].connect(on_is_playing_change);
52 volume_control.notify["is-listening"].connect(update_mic_visibility);
53
61 Notify.init ("wingpanel-indicator-sound");54 Notify.init ("wingpanel-indicator-sound");
62 this.notification = new Notify.Notification ("indicator-sound", "", "");55
63 this.notification.set_hint ("x-canonical-private-synchronous", new Variant.string ("indicator-sound"));56 notification = new Notify.Notification ("indicator-sound", "", "");
6457 notification.set_hint ("x-canonical-private-synchronous", new Variant.string ("indicator-sound"));
65 this.settings = new Services.Settings ();58
59 settings = new Services.Settings ();
66 settings.notify["max-volume"].connect (set_max_volume);60 settings.notify["max-volume"].connect (set_max_volume);
67 }61 }
6862
@@ -83,8 +77,10 @@
83 panel_icon.scroll_event.connect (on_icon_scroll_event);77 panel_icon.scroll_event.connect (on_icon_scroll_event);
8478
85 var locale = Intl.setlocale (LocaleCategory.MESSAGES, null);79 var locale = Intl.setlocale (LocaleCategory.MESSAGES, null);
80
86 volume_scale = new Widgets.Scale ("audio-volume-high-symbolic", true, 0.0, max_volume, 0.01);81 volume_scale = new Widgets.Scale ("audio-volume-high-symbolic", true, 0.0, max_volume, 0.01);
87 mic_scale = new Widgets.Scale ("audio-input-microphone-symbolic", true, 0.0, 1.0, 0.01);82 mic_scale = new Widgets.Scale ("audio-input-microphone-symbolic", true, 0.0, 1.0, 0.01);
83
88 ca_context = CanberraGtk.context_get ();84 ca_context = CanberraGtk.context_get ();
89 ca_context.change_props (Canberra.PROP_APPLICATION_NAME, "indicator-sound",85 ca_context.change_props (Canberra.PROP_APPLICATION_NAME, "indicator-sound",
90 Canberra.PROP_APPLICATION_ID, "wingpanel-indicator-sound",86 Canberra.PROP_APPLICATION_ID, "wingpanel-indicator-sound",
@@ -116,7 +112,7 @@
116 private void on_volume_change () {112 private void on_volume_change () {
117 var volume = volume_control.volume.volume / this.max_volume;113 var volume = volume_control.volume.volume / this.max_volume;
118 volume_scale.get_scale ().set_value (volume);114 volume_scale.get_scale ().set_value (volume);
119 update_panel_icon (volume);115 panel_icon.set_main_icon_name (get_volume_icon (volume));
120 }116 }
121117
122 private void on_mic_volume_change () {118 private void on_mic_volume_change () {
@@ -126,12 +122,14 @@
126122
127 private void on_mute_change () {123 private void on_mute_change () {
128 volume_scale.get_switch ().active = !volume_control.mute;124 volume_scale.get_switch ().active = !volume_control.mute;
125
126 string volume_icon = get_volume_icon (volume_control.volume.volume);
127 panel_icon.set_main_icon_name (volume_icon);
128
129 if (volume_control.mute) {129 if (volume_control.mute) {
130 update_panel_icon (volume_control.volume.volume);
131 volume_scale.set_icon ("audio-volume-muted-symbolic");130 volume_scale.set_icon ("audio-volume-muted-symbolic");
132 } else {131 } else {
133 update_panel_icon (volume_control.volume.volume);132 volume_scale.set_icon (volume_icon);
134 update_volume_icon ();
135 }133 }
136 }134 }
137135
@@ -155,12 +153,12 @@
155 this.sound_was_blocked_timeout_id = Timeout.add_seconds (5, () => {153 this.sound_was_blocked_timeout_id = Timeout.add_seconds (5, () => {
156 this.mute_blocks_sound = false;154 this.mute_blocks_sound = false;
157 this.sound_was_blocked_timeout_id = 0;155 this.sound_was_blocked_timeout_id = 0;
158 this.update_panel_icon (volume_control.volume.volume);156 panel_icon.set_main_icon_name (get_volume_icon (volume_control.volume.volume));
159 return false;157 return false;
160 });158 });
161 }159 }
162160
163 this.update_panel_icon (volume_control.volume.volume);161 panel_icon.set_main_icon_name (get_volume_icon (volume_control.volume.volume));
164 }162 }
165163
166 private bool on_icon_scroll_event (Gdk.EventScroll e) {164 private bool on_icon_scroll_event (Gdk.EventScroll e) {
@@ -179,16 +177,8 @@
179 this.volume_control.volume = vol;177 this.volume_control.volume = vol;
180178
181 if (open == false && this.notification != null && v >= -0.05 && v <= (this.max_volume + 0.05)) {179 if (open == false && this.notification != null && v >= -0.05 && v <= (this.max_volume + 0.05)) {
182 string icon;180
183 if (v <= 0.0) {181 string icon = get_volume_icon (v);
184 icon = "audio-volume-muted-symbolic";
185 } else if (v <= 0.3) {
186 icon = "audio-volume-low-symbolic";
187 } else if (v <= 0.7) {
188 icon = "audio-volume-medium-symbolic";
189 } else {
190 icon = "audio-volume-high-symbolic";
191 }
192182
193 this.notification.update ("indicator-sound", "", icon);183 this.notification.update ("indicator-sound", "", icon);
194 this.notification.set_hint ("value", new Variant.int32 (184 this.notification.set_hint ("value", new Variant.int32 (
@@ -219,31 +209,16 @@
219 }209 }
220 }210 }
221211
222 private void update_panel_icon (double volume) {212 private string get_volume_icon (double volume) {
223 if (volume <= 0 || this.volume_control.mute) {213 if (volume <= 0 || this.volume_control.mute) {
224 panel_icon.set_main_icon_name (this.mute_blocks_sound ? "audio-volume-muted-blocking-symbolic" : "audio-volume-muted-symbolic");214 return this.mute_blocks_sound ? "audio-volume-muted-blocking-symbolic" : "audio-volume-muted-symbolic";
225 } else if (volume <= 0.3) {215 } else if (volume <= 0.3) {
226 panel_icon.set_main_icon_name ("audio-volume-low-symbolic");216 return "audio-volume-low-symbolic";
227 } else if (volume <= 0.7) {217 } else if (volume <= 0.7) {
228 panel_icon.set_main_icon_name ("audio-volume-medium-symbolic");218 return "audio-volume-medium-symbolic";
229 } else {219 } else {
230 panel_icon.set_main_icon_name ("audio-volume-high-symbolic");220 return "audio-volume-high-symbolic";
231 }221 }
232 }
233
234 private void update_volume_icon () {
235 string icon;
236 var v = volume_scale.get_scale ().get_value ();
237 if (v <= 0.0) {
238 icon = "audio-volume-muted-symbolic";
239 } else if (v <= 0.3) {
240 icon = "audio-volume-low-symbolic";
241 } else if (v <= 0.7) {
242 icon = "audio-volume-medium-symbolic";
243 } else {
244 icon = "audio-volume-high-symbolic";
245 }
246 volume_scale.set_icon (icon);
247 }222 }
248223
249 private void on_volume_switch_change () {224 private void on_volume_switch_change () {
@@ -263,7 +238,7 @@
263 }238 }
264239
265 public override Gtk.Widget get_display_widget () {240 public override Gtk.Widget get_display_widget () {
266 update_panel_icon (volume_control.volume.volume);241 panel_icon.set_main_icon_name (get_volume_icon (volume_control.volume.volume));
267 return panel_icon;242 return panel_icon;
268 }243 }
269244
@@ -298,7 +273,7 @@
298 vol.volume = v.clamp (0.0, this.max_volume);273 vol.volume = v.clamp (0.0, this.max_volume);
299 vol.reason = Services.VolumeControl.VolumeReasons.USER_KEYPRESS;274 vol.reason = Services.VolumeControl.VolumeReasons.USER_KEYPRESS;
300 this.volume_control.volume = vol;275 this.volume_control.volume = vol;
301 update_volume_icon ();276 volume_scale.set_icon (get_volume_icon (volume_scale.get_scale ().get_value ()));
302 });277 });
303278
304 volume_scale.get_scale ().set_value (volume_control.volume.volume);279 volume_scale.get_scale ().set_value (volume_control.volume.volume);
@@ -326,7 +301,7 @@
326 return true;301 return true;
327 });302 });
328303
329 update_volume_icon ();304 volume_scale.set_icon (get_volume_icon (volume_scale.get_scale ().get_value ()));
330 set_max_volume ();305 set_max_volume ();
331306
332 main_grid.attach (volume_scale, 0, position++, 1, 1);307 main_grid.attach (volume_scale, 0, position++, 1, 1);

Subscribers

People subscribed via source and target branches

to all changes: