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
1=== modified file 'src/Indicator.vala'
2--- src/Indicator.vala 2016-11-05 19:13:01 +0000
3+++ src/Indicator.vala 2016-12-20 20:54:56 +0000
4@@ -16,26 +16,16 @@
5 */
6
7 public class Sound.Indicator : Wingpanel.Indicator {
8-
9- private Wingpanel.Widgets.OverlayIcon panel_icon;
10-
11 private Gtk.Grid main_grid;
12-
13 private Widgets.Scale volume_scale;
14-
15 private Widgets.Scale mic_scale;
16-
17+ private Wingpanel.Widgets.OverlayIcon panel_icon;
18 private Wingpanel.Widgets.Button settings_button;
19-
20- private Services.VolumeControlPulse volume_control;
21-
22 private Wingpanel.Widgets.Separator first_seperator;
23-
24 private Wingpanel.Widgets.Separator mic_seperator;
25-
26 private Notify.Notification notification;
27-
28 private Services.Settings settings;
29+ private Services.VolumeControlPulse volume_control;
30
31 bool open = false;
32 bool mute_blocks_sound = false;
33@@ -50,19 +40,23 @@
34 Object (code_name: Wingpanel.Indicator.SOUND,
35 display_name: _("Indicator Sound"),
36 description:_("The sound indicator"));
37- this.visible = true;
38- this.volume_control = new Services.VolumeControlPulse ();
39- this.volume_control.notify["volume"].connect (on_volume_change);
40- this.volume_control.notify["mic-volume"].connect (on_mic_volume_change);
41- this.volume_control.notify["mute"].connect (on_mute_change);
42- this.volume_control.notify["micMute"].connect (on_mic_mute_change);
43- this.volume_control.notify["is-playing"].connect(on_is_playing_change);
44- this.volume_control.notify["is-listening"].connect(update_mic_visibility);
45+
46+ visible = true;
47+
48+ volume_control = new Services.VolumeControlPulse ();
49+ volume_control.notify["volume"].connect (on_volume_change);
50+ volume_control.notify["mic-volume"].connect (on_mic_volume_change);
51+ volume_control.notify["mute"].connect (on_mute_change);
52+ volume_control.notify["micMute"].connect (on_mic_mute_change);
53+ volume_control.notify["is-playing"].connect(on_is_playing_change);
54+ volume_control.notify["is-listening"].connect(update_mic_visibility);
55+
56 Notify.init ("wingpanel-indicator-sound");
57- this.notification = new Notify.Notification ("indicator-sound", "", "");
58- this.notification.set_hint ("x-canonical-private-synchronous", new Variant.string ("indicator-sound"));
59-
60- this.settings = new Services.Settings ();
61+
62+ notification = new Notify.Notification ("indicator-sound", "", "");
63+ notification.set_hint ("x-canonical-private-synchronous", new Variant.string ("indicator-sound"));
64+
65+ settings = new Services.Settings ();
66 settings.notify["max-volume"].connect (set_max_volume);
67 }
68
69@@ -83,8 +77,10 @@
70 panel_icon.scroll_event.connect (on_icon_scroll_event);
71
72 var locale = Intl.setlocale (LocaleCategory.MESSAGES, null);
73+
74 volume_scale = new Widgets.Scale ("audio-volume-high-symbolic", true, 0.0, max_volume, 0.01);
75 mic_scale = new Widgets.Scale ("audio-input-microphone-symbolic", true, 0.0, 1.0, 0.01);
76+
77 ca_context = CanberraGtk.context_get ();
78 ca_context.change_props (Canberra.PROP_APPLICATION_NAME, "indicator-sound",
79 Canberra.PROP_APPLICATION_ID, "wingpanel-indicator-sound",
80@@ -116,7 +112,7 @@
81 private void on_volume_change () {
82 var volume = volume_control.volume.volume / this.max_volume;
83 volume_scale.get_scale ().set_value (volume);
84- update_panel_icon (volume);
85+ panel_icon.set_main_icon_name (get_volume_icon (volume));
86 }
87
88 private void on_mic_volume_change () {
89@@ -126,12 +122,14 @@
90
91 private void on_mute_change () {
92 volume_scale.get_switch ().active = !volume_control.mute;
93+
94+ string volume_icon = get_volume_icon (volume_control.volume.volume);
95+ panel_icon.set_main_icon_name (volume_icon);
96+
97 if (volume_control.mute) {
98- update_panel_icon (volume_control.volume.volume);
99 volume_scale.set_icon ("audio-volume-muted-symbolic");
100 } else {
101- update_panel_icon (volume_control.volume.volume);
102- update_volume_icon ();
103+ volume_scale.set_icon (volume_icon);
104 }
105 }
106
107@@ -155,12 +153,12 @@
108 this.sound_was_blocked_timeout_id = Timeout.add_seconds (5, () => {
109 this.mute_blocks_sound = false;
110 this.sound_was_blocked_timeout_id = 0;
111- this.update_panel_icon (volume_control.volume.volume);
112+ panel_icon.set_main_icon_name (get_volume_icon (volume_control.volume.volume));
113 return false;
114 });
115 }
116
117- this.update_panel_icon (volume_control.volume.volume);
118+ panel_icon.set_main_icon_name (get_volume_icon (volume_control.volume.volume));
119 }
120
121 private bool on_icon_scroll_event (Gdk.EventScroll e) {
122@@ -179,16 +177,8 @@
123 this.volume_control.volume = vol;
124
125 if (open == false && this.notification != null && v >= -0.05 && v <= (this.max_volume + 0.05)) {
126- string icon;
127- if (v <= 0.0) {
128- icon = "audio-volume-muted-symbolic";
129- } else if (v <= 0.3) {
130- icon = "audio-volume-low-symbolic";
131- } else if (v <= 0.7) {
132- icon = "audio-volume-medium-symbolic";
133- } else {
134- icon = "audio-volume-high-symbolic";
135- }
136+
137+ string icon = get_volume_icon (v);
138
139 this.notification.update ("indicator-sound", "", icon);
140 this.notification.set_hint ("value", new Variant.int32 (
141@@ -219,31 +209,16 @@
142 }
143 }
144
145- private void update_panel_icon (double volume) {
146+ private string get_volume_icon (double volume) {
147 if (volume <= 0 || this.volume_control.mute) {
148- panel_icon.set_main_icon_name (this.mute_blocks_sound ? "audio-volume-muted-blocking-symbolic" : "audio-volume-muted-symbolic");
149+ return this.mute_blocks_sound ? "audio-volume-muted-blocking-symbolic" : "audio-volume-muted-symbolic";
150 } else if (volume <= 0.3) {
151- panel_icon.set_main_icon_name ("audio-volume-low-symbolic");
152+ return "audio-volume-low-symbolic";
153 } else if (volume <= 0.7) {
154- panel_icon.set_main_icon_name ("audio-volume-medium-symbolic");
155- } else {
156- panel_icon.set_main_icon_name ("audio-volume-high-symbolic");
157- }
158- }
159-
160- private void update_volume_icon () {
161- string icon;
162- var v = volume_scale.get_scale ().get_value ();
163- if (v <= 0.0) {
164- icon = "audio-volume-muted-symbolic";
165- } else if (v <= 0.3) {
166- icon = "audio-volume-low-symbolic";
167- } else if (v <= 0.7) {
168- icon = "audio-volume-medium-symbolic";
169- } else {
170- icon = "audio-volume-high-symbolic";
171- }
172- volume_scale.set_icon (icon);
173+ return "audio-volume-medium-symbolic";
174+ } else {
175+ return "audio-volume-high-symbolic";
176+ }
177 }
178
179 private void on_volume_switch_change () {
180@@ -263,7 +238,7 @@
181 }
182
183 public override Gtk.Widget get_display_widget () {
184- update_panel_icon (volume_control.volume.volume);
185+ panel_icon.set_main_icon_name (get_volume_icon (volume_control.volume.volume));
186 return panel_icon;
187 }
188
189@@ -298,7 +273,7 @@
190 vol.volume = v.clamp (0.0, this.max_volume);
191 vol.reason = Services.VolumeControl.VolumeReasons.USER_KEYPRESS;
192 this.volume_control.volume = vol;
193- update_volume_icon ();
194+ volume_scale.set_icon (get_volume_icon (volume_scale.get_scale ().get_value ()));
195 });
196
197 volume_scale.get_scale ().set_value (volume_control.volume.volume);
198@@ -326,7 +301,7 @@
199 return true;
200 });
201
202- update_volume_icon ();
203+ volume_scale.set_icon (get_volume_icon (volume_scale.get_scale ().get_value ()));
204 set_max_volume ();
205
206 main_grid.attach (volume_scale, 0, position++, 1, 1);

Subscribers

People subscribed via source and target branches

to all changes: