Merge lp:~victored/noise/equalizer-popover into lp:~elementary-apps/noise/trunk
- equalizer-popover
- Merge into trunk
Status: | Merged | ||||
---|---|---|---|---|---|
Approved by: | Danielle Foré | ||||
Approved revision: | 1565 | ||||
Merged at revision: | 1565 | ||||
Proposed branch: | lp:~victored/noise/equalizer-popover | ||||
Merge into: | lp:~elementary-apps/noise/trunk | ||||
Diff against target: |
797 lines (+270/-329) 4 files modified
src/CMakeLists.txt (+1/-1) src/LibraryWindow.vala (+5/-0) src/Widgets/EqualizerPopover.vala (+261/-296) src/Widgets/StatusBar.vala (+3/-32) |
||||
To merge this branch: | bzr merge lp:~victored/noise/equalizer-popover | ||||
Related bugs: |
|
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
Corentin Noël | Approve | ||
Victor Martinez (community) | Abstain | ||
Review via email: mp+211217@code.launchpad.net |
Commit message
Move equalizer controls into Gtk.Popover. lp:1284825
Description of the change
Move equalizer controls into Gtk.Popover. lp:1284825
- Refactor code to follow current code style, with the exception of tabs-vs-spaces to avoid creating a larger code diff.
- Use only Gee data structures (has refcount advantages).
- Use Gtk.MenuButton in statusbar for automated popover handling (needs a modal popover to work properly).
- Stop using Gtk.Adjustment and Gtk.Box, replacing them by Gtk.Grid.
- Reduce code redundancy.
- Remove unnecessary widgets.
Needs GTK+ 3.12 and Vala 0.24
Victor Martinez (victored) wrote : | # |
Please note that this branch doesn't bump gtk and vala requirements, as Corentin's branch already does that and will be merged before this one. lp:~tintou/noise/fix-interface
Victor Martinez (victored) wrote : | # |
The UI is not supposed to change significantly, so feel free to point out any interface issues.
Danielle Foré (danrabbit) wrote : | # |
Victor, apart from the 1 char issue you pointed out this seems to work great!
I'm not sure if you think this should occur in another branch, but I think it would be a nice touch to change the green "check" icon to "document-
Victor Martinez (victored) wrote : | # |
I've changed the icon. It looks way better!
Victor Martinez (victored) wrote : | # |
Please note that the style class "bottom-toolbar" was dropped
Victor Martinez (victored) wrote : | # |
All fixed. Please review now.
Victor Martinez (victored) : | # |
Danielle Foré (danrabbit) wrote : | # |
Looks great Victor! Seems to work perfectly for me. No focus issues.
- 1564. By Victor Martinez
-
merge equalizer popover
- 1565. By Victor Martinez
-
Fix crash with GTK+ 3.11.9
A upstream change in how Gtk.Popover handles focus made the equalizer close too early after saving a preset. This happened because we were removing the current focus entry from the popover, which in the end resulted in a segmentation fault.
Cody Garver (codygarver) wrote : | # |
When the equalizer is turned off and you click on the preset dropdown, it closes the popover
Victor Martinez (victored) wrote : | # |
You're right Cody. That seems to happen when clicking insensitive widgets within the popover.
We could report that as a bug against Gtk.Popover.
Corentin Noël (tintou) wrote : | # |
For the code, it's all good, but I would like to have the button appearance fixed in the theme...
Preview Diff
1 | === modified file 'src/CMakeLists.txt' |
2 | --- src/CMakeLists.txt 2014-03-07 15:52:49 +0000 |
3 | +++ src/CMakeLists.txt 2014-03-23 22:17:56 +0000 |
4 | @@ -27,6 +27,7 @@ |
5 | Widgets/SpaceWidget.vala |
6 | Widgets/FixedBin.vala |
7 | Widgets/ViewSelector.vala |
8 | + Widgets/EqualizerPopover.vala |
9 | Widgets/FastView/TileView/ImageUtils.vala |
10 | Widgets/FastView/TileView/TileRenderer.vala |
11 | Widgets/FastView/TileView/TileView.vala |
12 | @@ -63,7 +64,6 @@ |
13 | Views/ListView/Lists/CellDataFunctionHelper.vala |
14 | Views/ListView/Lists/GenericList.vala |
15 | Views/ListView/Lists/MusicListView.vala |
16 | - Dialogs/EqualizerWindow.vala |
17 | Dialogs/SmartPlaylistEditor.vala |
18 | Dialogs/PreferencesWindow.vala |
19 | Dialogs/InstallGstreamerPluginsDialog.vala |
20 | |
21 | === modified file 'src/LibraryWindow.vala' |
22 | --- src/LibraryWindow.vala 2014-03-16 21:06:57 +0000 |
23 | +++ src/LibraryWindow.vala 2014-03-23 22:17:56 +0000 |
24 | @@ -153,6 +153,11 @@ |
25 | } |
26 | |
27 | public override bool key_press_event (Gdk.EventKey event) { |
28 | + // when typing in an editable widget, such as Gtk.Entry, don't block the event |
29 | + var focus_widget = get_focus (); |
30 | + if (focus_widget != null && focus_widget is Gtk.Editable) |
31 | + return base.key_press_event (event); |
32 | + |
33 | var modifiers = Gtk.accelerator_get_default_mod_mask (); |
34 | bool modifiers_active = (event.state & modifiers) != 0; |
35 | |
36 | |
37 | === renamed file 'src/Dialogs/EqualizerWindow.vala' => 'src/Widgets/EqualizerPopover.vala' |
38 | --- src/Dialogs/EqualizerWindow.vala 2014-02-02 11:47:19 +0000 |
39 | +++ src/Widgets/EqualizerPopover.vala 2014-03-23 22:17:56 +0000 |
40 | @@ -1,5 +1,6 @@ |
41 | /*- |
42 | - * Copyright (c) 2011-2012 Scott Ringwelski <sgringwe@mtu.edu> |
43 | + * Copyright (c) 2011-2012 Scott Ringwelski <sgringwe@mtu.edu> |
44 | + * Copyright (c) 2014 Noise Developers (http://launchpad.net/noise) |
45 | * |
46 | * Originally Written by Scott Ringwelski and Victor Eduardo for |
47 | * BeatBox Music Player: http://www.launchpad.net/beat-box |
48 | @@ -20,307 +21,309 @@ |
49 | * Boston, MA 02111-1307, USA. |
50 | */ |
51 | |
52 | -using Gtk; |
53 | - |
54 | -public class Noise.EqualizerWindow : Gtk.Window { |
55 | - |
56 | - private Switch eq_switch; |
57 | +public class Noise.EqualizerPopover : Gtk.Popover { |
58 | + private Gtk.Switch eq_switch; |
59 | + private Gtk.Entry new_preset_entry; |
60 | + private Gtk.Grid side_list; |
61 | + private Gtk.Grid scale_container; |
62 | private PresetList preset_combo; |
63 | - private Entry new_preset_entry; |
64 | - private Toolbar bottom_toolbar; |
65 | - private ToolItem side_list; |
66 | - private ToolItem new_preset_field; |
67 | - private Button close_button; |
68 | - |
69 | - private bool apply_changes; |
70 | - private bool initialized; |
71 | - private bool adding_preset; |
72 | + private Gee.List<Gtk.Scale> scales; |
73 | + private Gee.List<int> target_levels; |
74 | + private Settings.Equalizer equalizer_settings; |
75 | + private string new_preset_name; |
76 | + private bool apply_changes = false; |
77 | + private bool initialized = false; |
78 | + private bool adding_preset = false; |
79 | + private bool in_transition = false; |
80 | + private bool closing = false; |
81 | |
82 | private const int ANIMATION_TIMEOUT = 20; |
83 | |
84 | - private List<Scale> scale_list; |
85 | - private List<Label> label_list; |
86 | - |
87 | - private bool in_transition; |
88 | - private Gee.ArrayList<int> target_levels; |
89 | - |
90 | - private string new_preset_name; |
91 | - private Settings.Equalizer equalizer_settings; |
92 | - |
93 | - public EqualizerWindow () { |
94 | - scale_list = new List<Gtk.Scale>(); |
95 | - label_list = new List<Label>(); |
96 | - target_levels = new Gee.ArrayList<int>(); |
97 | - |
98 | - adding_preset = false; |
99 | - initialized = false; |
100 | - apply_changes = false; |
101 | - |
102 | - build_ui(); |
103 | - load_presets(); |
104 | + private const string[] DECIBELS = { |
105 | + "60", "170", "310", "600", "1k", "3k", "6k", "12k", "14k", "16k" |
106 | + }; |
107 | + |
108 | + public EqualizerPopover () { |
109 | + scales = new Gee.ArrayList<Gtk.Scale> (); |
110 | + target_levels = new Gee.ArrayList<int> (); |
111 | + |
112 | + equalizer_settings = Settings.Equalizer.get_default (); |
113 | + |
114 | + build_ui (); |
115 | + load_presets (); |
116 | |
117 | initialized = true; |
118 | |
119 | - equalizer_settings = Settings.Equalizer.get_default (); |
120 | if (equalizer_settings.auto_switch_preset) { |
121 | - preset_combo.selectAutomaticPreset(); |
122 | + preset_combo.selectAutomaticPreset (); |
123 | } else { |
124 | var preset = equalizer_settings.selected_preset; |
125 | if (preset != null) |
126 | - preset_combo.selectPreset(preset); |
127 | + preset_combo.selectPreset (preset); |
128 | } |
129 | |
130 | on_eq_switch_toggled (); |
131 | apply_changes = true; |
132 | } |
133 | |
134 | - void build_ui () { |
135 | - set_title(_("Equalizer")); |
136 | - |
137 | - window_position = WindowPosition.CENTER; |
138 | - type_hint = Gdk.WindowTypeHint.DIALOG; |
139 | - set_transient_for (App.main_window); |
140 | - set_size_request(440, 224); |
141 | - resizable = false; |
142 | - set_deletable(false); |
143 | - |
144 | - set_icon(render_icon ("preferences-system", IconSize.DIALOG, null)); |
145 | - |
146 | - var outer_box = new Gtk.Box (Gtk.Orientation.HORIZONTAL, 10); |
147 | - var inner_box = new Gtk.Box (Gtk.Orientation.VERTICAL, 0); |
148 | - var scales = new Gtk.Box (Gtk.Orientation.HORIZONTAL, 0); |
149 | - |
150 | - bottom_toolbar = new Toolbar(); |
151 | - eq_switch = new Switch(); |
152 | - preset_combo = new PresetList(); |
153 | - |
154 | - eq_switch.set_active(equalizer_settings.equalizer_enabled); |
155 | - |
156 | - string[] decibels = {"60", "170", "310", "600", "1k", "3k", "6k", "12k", "14k", "16k"}; |
157 | - //string[] decibels = {"32", "64", "125", "250", "500", "1k", "2k", "4k", "8k", "16k"}; |
158 | - |
159 | - for (int index = 0; index < 10; ++index) { |
160 | - var holder = new Gtk.Box(Gtk.Orientation.VERTICAL, 0); |
161 | - var v = new Gtk.Scale.with_range(Gtk.Orientation.VERTICAL, -80, 80, 1); |
162 | - v.add_mark(0, PositionType.LEFT, null); |
163 | - v.draw_value = false; |
164 | - v.inverted = true; |
165 | - |
166 | - var label = new Label(decibels[index]); |
167 | - |
168 | - holder.pack_start(v, true, true, 0); |
169 | - holder.pack_end(UI.wrap_alignment (label, 4, 0, 0, 0), false, false, 0); |
170 | - |
171 | - scales.pack_start(holder, true, true, 6); |
172 | - scale_list.append(v); |
173 | - label_list.append(label); |
174 | - |
175 | - v.value_changed.connect( () => { |
176 | - if(apply_changes && initialized && !preset_combo.automatic_chosen) { |
177 | - App.player.player.set_equalizer_gain(scale_list.index(v), (int)scale_list.nth_data(scale_list.index(v)).get_value()); |
178 | - |
179 | - if(!in_transition) { |
180 | - if (!preset_combo.getSelectedPreset().is_default) |
181 | - preset_combo.getSelectedPreset().setGain(scale_list.index(v), (int)scale_list.nth_data(scale_list.index(v)).get_value()); |
182 | + public override void closed () { |
183 | + closing = true; |
184 | + |
185 | + if (in_transition) |
186 | + set_target_levels (); |
187 | + else if (adding_preset) |
188 | + add_new_preset (); |
189 | + |
190 | + save_presets (); |
191 | + |
192 | + var selected_preset = preset_combo.getSelectedPreset (); |
193 | + equalizer_settings.selected_preset = selected_preset != null ? selected_preset.name : ""; |
194 | + equalizer_settings.auto_switch_preset = preset_combo.automatic_chosen; |
195 | + |
196 | + closing = false; |
197 | + } |
198 | + |
199 | + public bool verify_preset_name (string preset_name) { |
200 | + if (preset_name == null || String.is_white_space (preset_name)) |
201 | + return false; |
202 | + |
203 | + foreach (var preset in preset_combo.getPresets ()) { |
204 | + if (preset_name == preset.name) |
205 | + return false; |
206 | + } |
207 | + |
208 | + return true; |
209 | + } |
210 | + |
211 | + private void build_ui () { |
212 | + set_size_request (-1, 240); |
213 | + |
214 | + scale_container = new Gtk.Grid (); |
215 | + scale_container.column_spacing = 12; |
216 | + scale_container.margin = 18; |
217 | + scale_container.margin_bottom = 0; |
218 | + |
219 | + foreach (string decibel in DECIBELS) { |
220 | + var scale = new Gtk.Scale.with_range (Gtk.Orientation.VERTICAL, -80, 80, 1); |
221 | + scale.add_mark (0, Gtk.PositionType.LEFT, null); |
222 | + scale.draw_value = false; |
223 | + scale.inverted = true; |
224 | + |
225 | + var tag = new Gtk.Label (decibel); |
226 | + |
227 | + scale.halign = tag.halign = Gtk.Align.CENTER; |
228 | + scale.expand = true; |
229 | + tag.hexpand = true; |
230 | + |
231 | + var holder = new Gtk.Grid (); |
232 | + holder.orientation = Gtk.Orientation.VERTICAL; |
233 | + holder.expand = true; |
234 | + holder.row_spacing = 4; |
235 | + holder.add (scale); |
236 | + holder.add (tag); |
237 | + |
238 | + scale_container.add (holder); |
239 | + scales.add (scale); |
240 | + |
241 | + scale.value_changed.connect (() => { |
242 | + if (initialized && apply_changes && !preset_combo.automatic_chosen) { |
243 | + int index = scales.index_of (scale); |
244 | + int val = (int) scale.get_value (); |
245 | + apply_equalizer_gain (index, val); |
246 | + |
247 | + if (!in_transition) { |
248 | + var selected_preset = preset_combo.getSelectedPreset (); |
249 | + |
250 | + if (selected_preset.is_default) |
251 | + on_default_preset_modified (); |
252 | else |
253 | - on_default_preset_modified(); |
254 | + selected_preset.setGain (index, val); |
255 | } |
256 | } |
257 | }); |
258 | - |
259 | } |
260 | |
261 | - preset_combo.set_size_request(165, -1); |
262 | - |
263 | - var eq_switch_item = new ToolItem(); |
264 | - eq_switch_item.add(eq_switch); |
265 | - |
266 | - side_list = new ToolItem(); |
267 | - side_list.add(preset_combo); |
268 | - |
269 | - new_preset_entry = new Entry(); |
270 | - |
271 | - var entry_icon = Icons.render_icon ("dialog-apply", IconSize.MENU); |
272 | - new_preset_entry.set_icon_from_pixbuf(Gtk.EntryIconPosition.SECONDARY, entry_icon); |
273 | - new_preset_entry.set_icon_tooltip_text(Gtk.EntryIconPosition.SECONDARY, _("Save preset")); |
274 | - |
275 | - new_preset_field = new ToolItem(); |
276 | - new_preset_field.add(new_preset_entry); |
277 | - |
278 | - var space_item = new ToolItem(); |
279 | - space_item.set_expand(true); |
280 | - |
281 | - close_button = new Button.with_label (_("Close")); |
282 | - var close_button_item = new ToolItem(); |
283 | - close_button.set_size_request(120, -1); |
284 | - close_button_item.set_expand(false); |
285 | - close_button_item.add(close_button); |
286 | - |
287 | - // Set spacing stuff |
288 | - eq_switch.valign = preset_combo.valign = close_button.valign = new_preset_entry.valign = Gtk.Align.CENTER; |
289 | + eq_switch = new Gtk.Switch (); |
290 | + eq_switch.set_active (equalizer_settings.equalizer_enabled); |
291 | + |
292 | + preset_combo = new PresetList (); |
293 | + preset_combo.set_size_request (165, -1); |
294 | + |
295 | + side_list = new Gtk.Grid (); |
296 | + side_list.add (preset_combo); |
297 | + |
298 | + new_preset_entry = new Gtk.Entry (); |
299 | + new_preset_entry.secondary_icon_name = "document-save-symbolic"; |
300 | + new_preset_entry.secondary_icon_tooltip_text = _("Save preset"); |
301 | + |
302 | + eq_switch.valign = preset_combo.valign = new_preset_entry.valign = Gtk.Align.CENTER; |
303 | |
304 | // Sync size between entry and combobox |
305 | - preset_combo.size_allocate.connect ( (alloc) => { |
306 | + preset_combo.size_allocate.connect ((alloc) => { |
307 | new_preset_entry.set_size_request (alloc.width, alloc.height); |
308 | + new_preset_entry.queue_resize (); |
309 | }); |
310 | |
311 | - bottom_toolbar.insert(eq_switch_item, 0); |
312 | - bottom_toolbar.insert(side_list, 1); |
313 | - bottom_toolbar.insert(space_item, 2); |
314 | - bottom_toolbar.insert(close_button_item, 3); |
315 | - |
316 | - // Set the egtk bottom toolbar style. |
317 | - bottom_toolbar.get_style_context().add_class("bottom-toolbar"); |
318 | - |
319 | - inner_box.pack_end(UI.wrap_alignment (bottom_toolbar, 0, 0, 0, 0), false, false, 0); |
320 | - inner_box.pack_start(UI.wrap_alignment (scales, 0, 12, 0, 12), true, true, 10); |
321 | - |
322 | - outer_box.pack_start(inner_box); |
323 | - add(outer_box); |
324 | - |
325 | - eq_switch.notify["active"].connect(on_eq_switch_toggled); |
326 | - preset_combo.automatic_preset_chosen.connect(on_automatic_chosen); |
327 | - preset_combo.delete_preset_chosen.connect(remove_preset_clicked); |
328 | + var bottom_controls = new Gtk.Grid (); |
329 | + bottom_controls.margin = 12; |
330 | + bottom_controls.margin_top = 0; |
331 | + bottom_controls.add (eq_switch); |
332 | + bottom_controls.add (side_list); |
333 | + |
334 | + var layout = new Gtk.Grid (); |
335 | + layout.orientation = Gtk.Orientation.VERTICAL; |
336 | + layout.row_spacing = 12; |
337 | + |
338 | + layout.add (scale_container); |
339 | + layout.add (new Gtk.Separator (Gtk.Orientation.HORIZONTAL)); |
340 | + layout.add (bottom_controls); |
341 | + layout.show_all (); |
342 | + |
343 | + add (layout); |
344 | + |
345 | + eq_switch.notify["active"].connect (on_eq_switch_toggled); |
346 | + preset_combo.automatic_preset_chosen.connect (on_automatic_chosen); |
347 | + preset_combo.delete_preset_chosen.connect (remove_preset_clicked); |
348 | preset_combo.preset_selected.connect (preset_selected); |
349 | new_preset_entry.activate.connect (add_new_preset); |
350 | new_preset_entry.icon_press.connect (new_preset_entry_icon_pressed); |
351 | new_preset_entry.focus_out_event.connect (on_entry_focus_out); |
352 | - |
353 | - close_button.clicked.connect ( () => destroy () ); |
354 | - destroy.connect(on_quit); |
355 | - |
356 | - show_all(); |
357 | - } |
358 | - |
359 | - bool on_entry_focus_out () { |
360 | - if (!in_destruction ()) |
361 | - new_preset_entry.grab_focus(); |
362 | + } |
363 | + |
364 | + private void apply_equalizer_gain (int index, int val) { |
365 | + App.player.player.set_equalizer_gain (index, val); |
366 | + } |
367 | + |
368 | + private void apply_automatic_gains () { |
369 | + App.player.change_gains_thread (); |
370 | + } |
371 | + |
372 | + private bool on_entry_focus_out () { |
373 | + if (!closing) |
374 | + new_preset_entry.grab_focus (); |
375 | + |
376 | return false; |
377 | } |
378 | |
379 | - void set_sliders_sensitivity (bool sensitivity) { |
380 | - foreach (var scale in scale_list) { |
381 | - label_list.nth_data(scale_list.index(scale)).sensitive = sensitivity; |
382 | - scale.sensitive = sensitivity; |
383 | - } |
384 | + private void set_sliders_sensitivity (bool sensitivity) { |
385 | + scale_container.sensitive = sensitivity; |
386 | } |
387 | |
388 | - void on_eq_switch_toggled () { |
389 | + private void on_eq_switch_toggled () { |
390 | in_transition = false; |
391 | |
392 | - bool eq_active = eq_switch.get_active(); |
393 | + bool eq_active = eq_switch.active; |
394 | preset_combo.sensitive = eq_active; |
395 | set_sliders_sensitivity (eq_active); |
396 | equalizer_settings.equalizer_enabled = eq_active; |
397 | |
398 | if (eq_active) { |
399 | - if(!preset_combo.automatic_chosen) { |
400 | - EqualizerPreset? selected_preset = preset_combo.getSelectedPreset(); |
401 | + if (preset_combo.automatic_chosen) { |
402 | + preset_combo.selectAutomaticPreset (); |
403 | + } else { |
404 | + var selected_preset = preset_combo.getSelectedPreset (); |
405 | |
406 | if (selected_preset != null) { |
407 | - for(int i = 0; i < 10; ++i) |
408 | - App.player.player.set_equalizer_gain(i, selected_preset.getGain(i)); |
409 | + for (int i = 0; i < scales.size; ++i) |
410 | + apply_equalizer_gain (i, selected_preset.getGain (i)); |
411 | } |
412 | } |
413 | - else { |
414 | - preset_combo.selectAutomaticPreset(); |
415 | - } |
416 | - } |
417 | - else { |
418 | - for (int i = 0; i < 10; ++i) |
419 | - App.player.player.set_equalizer_gain(i, 0); |
420 | + } else { |
421 | + for (int i = 0; i < scales.size; ++i) |
422 | + apply_equalizer_gain (i, 0); |
423 | } |
424 | } |
425 | |
426 | - void load_presets () { |
427 | + private void load_presets () { |
428 | foreach (var preset in Equalizer.get_default_presets ()) { |
429 | preset.is_default = true; |
430 | - preset_combo.addPreset(preset); |
431 | + preset_combo.addPreset (preset); |
432 | } |
433 | |
434 | - foreach (var preset in equalizer_settings.getPresets ()) { |
435 | - preset_combo.addPreset(preset); |
436 | - } |
437 | + foreach (var preset in equalizer_settings.getPresets ()) |
438 | + preset_combo.addPreset (preset); |
439 | } |
440 | |
441 | - void save_presets () { |
442 | - string[] val = new string[0]; |
443 | + private void save_presets () { |
444 | + var val = new string[0]; |
445 | |
446 | foreach (var preset in preset_combo.getPresets ()) { |
447 | - if (preset.is_default) |
448 | - continue; |
449 | - val += preset.to_string (); |
450 | + if (!preset.is_default) |
451 | + val += preset.to_string (); |
452 | } |
453 | |
454 | equalizer_settings.custom_presets = val; |
455 | } |
456 | |
457 | - void preset_selected (EqualizerPreset p) { |
458 | - |
459 | + private void preset_selected (EqualizerPreset p) { |
460 | if (!initialized) |
461 | return; |
462 | |
463 | set_sliders_sensitivity (true); |
464 | - target_levels.clear(); |
465 | - |
466 | - foreach (int i in p.gains) { |
467 | - target_levels.add(i); |
468 | - } |
469 | - |
470 | - if (in_destruction () || (initialized && !apply_changes) || adding_preset) { |
471 | + target_levels.clear (); |
472 | + |
473 | + foreach (int i in p.gains) |
474 | + target_levels.add (i); |
475 | + |
476 | + if (closing || (initialized && !apply_changes) || adding_preset) { |
477 | set_target_levels (); |
478 | - } |
479 | - else if (!in_transition) { |
480 | + } else if (!in_transition) { |
481 | in_transition = true; |
482 | - Timeout.add(ANIMATION_TIMEOUT, transition_scales); |
483 | + Timeout.add (ANIMATION_TIMEOUT, transition_scales); |
484 | } |
485 | } |
486 | |
487 | - void set_target_levels () { |
488 | + private void set_target_levels () { |
489 | in_transition = false; |
490 | |
491 | - for (int index = 0; index < 10; ++index) |
492 | - scale_list.nth_data(index).set_value(target_levels.get(index)); |
493 | + for (int index = 0; index < scales.size; ++index) { |
494 | + var scale = scales.get (index); |
495 | + scale.set_value (target_levels.get (index)); |
496 | + } |
497 | } |
498 | |
499 | - bool transition_scales () { |
500 | + private bool transition_scales () { |
501 | if (!in_transition) |
502 | return false; |
503 | |
504 | bool is_finished = true; |
505 | |
506 | - for (int index = 0; index < 10; ++index) { |
507 | - double currLvl = scale_list.nth_data(index).get_value(); |
508 | - double targetLvl = target_levels.get(index); |
509 | - double difference = targetLvl - currLvl; |
510 | - |
511 | - if (in_destruction () || Math.fabs(difference) <= 1) { |
512 | - scale_list.nth_data(index).set_value(targetLvl); |
513 | + for (int index = 0; index < scales.size; ++index) { |
514 | + var scale = scales.get (index); |
515 | + double current_level = scale.get_value (); |
516 | + double target_level = target_levels.get (index); |
517 | + double difference = target_level - current_level; |
518 | + |
519 | + if (closing || Math.fabs (difference) <= 1) { |
520 | + scale.set_value (target_level); |
521 | + |
522 | // if switching from the automatic mode, apply the changes correctly |
523 | - if (!preset_combo.automatic_chosen && targetLvl == 0) |
524 | - App.player.player.set_equalizer_gain (index, 0); |
525 | - } |
526 | - else { |
527 | - scale_list.nth_data(index).set_value(scale_list.nth_data(index).get_value() + (difference / 8.0)); |
528 | + if (!preset_combo.automatic_chosen && target_level == 0) |
529 | + apply_equalizer_gain (index, 0); |
530 | + } else { |
531 | + scale.set_value (scale.get_value () + (difference / 8.0)); |
532 | is_finished = false; |
533 | } |
534 | } |
535 | |
536 | if (is_finished) { |
537 | in_transition = false; |
538 | - return false; // stop |
539 | + |
540 | + // all done. stop |
541 | + return false; |
542 | } |
543 | |
544 | - return true; // keep going |
545 | + // keep going |
546 | + return true; |
547 | } |
548 | |
549 | - void on_automatic_chosen () { |
550 | + private void on_automatic_chosen () { |
551 | equalizer_settings.auto_switch_preset = preset_combo.automatic_chosen; |
552 | |
553 | - target_levels.clear(); |
554 | + target_levels.clear (); |
555 | |
556 | - for (int i = 0; i < 10; ++i) |
557 | - target_levels.add(0); |
558 | + for (int i = 0; i < scales.size; ++i) |
559 | + target_levels.add (0); |
560 | |
561 | set_sliders_sensitivity (false); |
562 | |
563 | @@ -328,89 +331,79 @@ |
564 | in_transition = true; |
565 | Timeout.add (ANIMATION_TIMEOUT, transition_scales); |
566 | save_presets (); |
567 | - App.player.change_gains_thread (); |
568 | - } |
569 | - else { |
570 | + apply_automatic_gains (); |
571 | + } else { |
572 | set_target_levels (); |
573 | } |
574 | } |
575 | |
576 | - void on_default_preset_modified () { |
577 | - |
578 | - if(adding_preset || in_destruction ()) |
579 | + private void on_default_preset_modified () { |
580 | + if (adding_preset || closing) |
581 | return; |
582 | |
583 | adding_preset = true; |
584 | |
585 | - close_button.sensitive = !adding_preset; |
586 | - |
587 | - bottom_toolbar.remove(side_list); |
588 | - bottom_toolbar.insert(new_preset_field, 1); |
589 | - |
590 | - new_preset_name = create_new_preset_name(true); |
591 | - |
592 | - new_preset_entry.set_text(new_preset_name); |
593 | + side_list.remove (preset_combo); |
594 | + side_list.add (new_preset_entry); |
595 | + side_list.show_all (); |
596 | + |
597 | + new_preset_name = create_new_preset_name (true); |
598 | + |
599 | + new_preset_entry.set_text (new_preset_name); |
600 | eq_switch.sensitive = false; |
601 | - bottom_toolbar.show_all(); |
602 | - new_preset_entry.grab_focus(); |
603 | - } |
604 | - |
605 | - void new_preset_entry_icon_pressed (EntryIconPosition pos, Gdk.Event event) { |
606 | - |
607 | - if(pos != Gtk.EntryIconPosition.SECONDARY && !adding_preset) |
608 | - return; |
609 | - |
610 | - add_new_preset(); |
611 | - } |
612 | - |
613 | - void add_new_preset() { |
614 | - |
615 | - if(!adding_preset) |
616 | - return; |
617 | - |
618 | - var new_name = new_preset_entry.get_text(); |
619 | - |
620 | - if(verify_preset_name(new_name)) |
621 | + new_preset_entry.grab_focus (); |
622 | + } |
623 | + |
624 | + private void new_preset_entry_icon_pressed (Gtk.EntryIconPosition pos, Gdk.Event event) { |
625 | + if (pos != Gtk.EntryIconPosition.SECONDARY && !adding_preset) |
626 | + return; |
627 | + |
628 | + add_new_preset (); |
629 | + } |
630 | + |
631 | + private void add_new_preset () { |
632 | + if (!adding_preset) |
633 | + return; |
634 | + |
635 | + var new_name = new_preset_entry.get_text (); |
636 | + |
637 | + if (verify_preset_name (new_name)) |
638 | new_preset_name = new_name; |
639 | |
640 | - int i = 0; |
641 | - int[] gains = new int[10]; |
642 | - |
643 | - foreach(Scale scale in scale_list) { |
644 | - gains[i] = (int)scale_list.nth_data(scale_list.index(scale)).get_value(); |
645 | - i++; |
646 | - } |
647 | - |
648 | - var new_preset = new EqualizerPreset.with_gains(new_preset_name, gains); |
649 | - preset_combo.addPreset(new_preset); |
650 | - |
651 | - bottom_toolbar.remove(new_preset_field); |
652 | - bottom_toolbar.insert(side_list, 1); |
653 | - bottom_toolbar.show_all(); |
654 | + int[] gains = new int[scales.size]; |
655 | + |
656 | + for (int i = 0; i < scales.size; i++) |
657 | + gains[i] = (int) scales.get (i).get_value (); |
658 | + |
659 | + var new_preset = new EqualizerPreset.with_gains (new_preset_name, gains); |
660 | + preset_combo.addPreset (new_preset); |
661 | + |
662 | + side_list.add (preset_combo); |
663 | + side_list.set_focus_child (preset_combo); |
664 | + side_list.remove (new_preset_entry); |
665 | + side_list.show_all (); |
666 | + |
667 | eq_switch.sensitive = true; |
668 | adding_preset = false; |
669 | - close_button.sensitive = !adding_preset; |
670 | } |
671 | |
672 | - string create_new_preset_name (bool from_current) { |
673 | + private string create_new_preset_name (bool from_current) { |
674 | + string current_preset_name = from_current ? preset_combo.getSelectedPreset ().name : ""; |
675 | + string preset_name = ""; |
676 | |
677 | - int i = 0; |
678 | bool is_valid = false; |
679 | - |
680 | - string current_preset_name = (from_current)? preset_combo.getSelectedPreset().name : ""; |
681 | - string preset_name = "..."; |
682 | - |
683 | - do |
684 | - { |
685 | + int i = 0; |
686 | + |
687 | + do { |
688 | debug ("preset name %s is invalid. Looping", preset_name); |
689 | + |
690 | // We have to be explicit in order to make this translatable |
691 | if (from_current) { |
692 | if (i < 1) |
693 | preset_name = _("%s (Custom)").printf (current_preset_name); |
694 | else |
695 | preset_name = _("%s (Custom %i)").printf (current_preset_name, i); |
696 | - } |
697 | - else { |
698 | + } else { |
699 | if (i < 1) |
700 | preset_name = _("Custom Preset"); |
701 | else |
702 | @@ -418,41 +411,13 @@ |
703 | } |
704 | |
705 | i++; |
706 | - is_valid = verify_preset_name(preset_name); |
707 | - |
708 | + is_valid = verify_preset_name (preset_name); |
709 | } while (!is_valid); |
710 | |
711 | return preset_name; |
712 | } |
713 | |
714 | - public bool verify_preset_name (string preset_name) { |
715 | - if (preset_name == null) |
716 | - return false; |
717 | - |
718 | - if (String.is_white_space (preset_name)) |
719 | - return false; |
720 | - |
721 | - foreach (var preset in preset_combo.getPresets ()) { |
722 | - if (preset_name == preset.name) |
723 | - return false; |
724 | - } |
725 | - |
726 | - return true; |
727 | - } |
728 | - |
729 | - |
730 | - void remove_preset_clicked () { |
731 | - preset_combo.removeCurrentPreset(); |
732 | - } |
733 | - |
734 | - void on_quit () { |
735 | - if (in_transition) |
736 | - set_target_levels (); |
737 | - else if (adding_preset) |
738 | - add_new_preset (); |
739 | - |
740 | - save_presets (); |
741 | - equalizer_settings.selected_preset = (preset_combo.getSelectedPreset() != null)? preset_combo.getSelectedPreset().name : ""; |
742 | - equalizer_settings.auto_switch_preset = preset_combo.automatic_chosen; |
743 | + private void remove_preset_clicked () { |
744 | + preset_combo.removeCurrentPreset (); |
745 | } |
746 | } |
747 | \ No newline at end of file |
748 | |
749 | === modified file 'src/Widgets/StatusBar.vala' |
750 | --- src/Widgets/StatusBar.vala 2014-03-14 16:05:56 +0000 |
751 | +++ src/Widgets/StatusBar.vala 2014-03-23 22:17:56 +0000 |
752 | @@ -179,42 +179,13 @@ |
753 | #endif |
754 | } |
755 | |
756 | - |
757 | - private class EqualizerChooser : SimpleOptionChooser { |
758 | - |
759 | - private Gtk.Window? equalizer_window = null; |
760 | - |
761 | + private class EqualizerChooser : Gtk.MenuButton { |
762 | public EqualizerChooser () { |
763 | - var eq_show_image = Icons.EQ_SYMBOLIC.render_image (Gtk.IconSize.MENU); |
764 | - var eq_hide_image = Icons.EQ_SYMBOLIC.render_image (Gtk.IconSize.MENU); |
765 | - |
766 | - appendItem (_("Hide"), eq_show_image, _("Show Equalizer")); |
767 | - appendItem (_("Show"), eq_hide_image, _("Hide Equalizer")); |
768 | - |
769 | - setOption (0); |
770 | - |
771 | - option_changed.connect (eq_option_chooser_clicked); |
772 | - } |
773 | - |
774 | - private void eq_option_chooser_clicked () { |
775 | - int val = current_option; |
776 | - |
777 | - if (equalizer_window == null && val == 1) { |
778 | - equalizer_window = new EqualizerWindow (); |
779 | - equalizer_window.show_all (); |
780 | - equalizer_window.destroy.connect ( () => { |
781 | - // revert the option to "Hide equalizer" after the window is destroyed |
782 | - setOption (0); |
783 | - }); |
784 | - } |
785 | - else if (val == 0 && equalizer_window != null) { |
786 | - equalizer_window.destroy (); |
787 | - equalizer_window = null; |
788 | - } |
789 | + popover = new EqualizerPopover (); |
790 | + add (Icons.EQ_SYMBOLIC.render_image (Gtk.IconSize.MENU)); |
791 | } |
792 | } |
793 | |
794 | - |
795 | private class InfoPanelChooser : SimpleOptionChooser { |
796 | |
797 | public InfoPanelChooser () { |
Allow typing a name into the preset-name entry. Currently there are issues with focus and only one character is recognized.