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