Merge lp:~victored/beat-box/equalizer-fixes into lp:beat-box
- equalizer-fixes
- Merge into trunk
Status: | Merged | ||||
---|---|---|---|---|---|
Merged at revision: | 375 | ||||
Proposed branch: | lp:~victored/beat-box/equalizer-fixes | ||||
Merge into: | lp:beat-box | ||||
Diff against target: |
814 lines (+248/-150) 6 files modified
schemas/org.gnome.beatbox.gschema.xml (+4/-4) src/Dialogs/EqualizerWindow.vala (+158/-75) src/Dialogs/PresetNameWindow.vala (+15/-6) src/LibraryManager.vala (+15/-12) src/Settings.vala (+5/-17) src/Widgets/PresetList.vala (+51/-36) |
||||
To merge this branch: | bzr merge lp:~victored/beat-box/equalizer-fixes | ||||
Related bugs: |
|
||||
Related blueprints: |
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
Scott Ringwelski | Approve | ||
Review via email: mp+84419@code.launchpad.net |
Commit message
Description of the change
Some extra improvements to the equalizer:
* Make the switch insensitive while adding a new preset
* Validate the text in new-preset-entry and NewPresetWindow
* Don't let new-preset-entry lose keyboard focus
* NewPresetWindow is now transient for EqualizerWindow instead of LibraryWindow.
* Set the last preset in the ComboBox if NewPresetWindow is closed not using 'DONE'.
* Settings: make getSelectedPreset() and setSelectedPreset() handle only the name of the current preset.
* Corrected values for "Full Treble". This was causing an improper behavior.
* Make the new-preset-entry match the size of the ComboBox
* Code cleanup
* Error validation (avoid some potential segfaults)
* Apply the automatic preset correctly
* Ensure the proper saving of custom presets
- They're saved and applied even if the window is closed during the process.
* Minor code fixes
* Remove the close button from the equalizer-window (as long as the window manager supports it). Currently, this works only under GNOME-Shell and Unity-2D.
The code is mature enough for merging into trunk.
Sergey "Shnatsel" Davidoff (shnatsel) wrote : | # |
Victor Martinez (victored) wrote : | # |
Thanks Sergey!
Scott Ringwelski (sgringwe) wrote : | # |
I am merging the changes, however:
1. In lm.change_
2. ... that's it!
So, what i'm going to do is merge and then I will add a simple check for that myself, since it's easier that way.
Great work again!
Victor Martinez (victored) wrote : | # |
My bad! Thanks a lot for fixing that error!
BTW, the on_close() function on EqualizerWindows is potentially dangerous. Maybe some sleep time should be added whenever the scales are in transition in order to avoid the failed-assertion messages. There are no other errors [I'm aware of] aside from that.
Preview Diff
1 | === modified file 'schemas/org.gnome.beatbox.gschema.xml' |
2 | --- schemas/org.gnome.beatbox.gschema.xml 2011-11-22 03:08:33 +0000 |
3 | +++ schemas/org.gnome.beatbox.gschema.xml 2011-12-05 01:21:23 +0000 |
4 | @@ -107,18 +107,18 @@ |
5 | </key> |
6 | <key type="s" name="selected-preset"> |
7 | <default>''</default> |
8 | - <summary>Contains information regarding the user-selected preset</summary> |
9 | + <summary>Contains the name of the user-selected preset</summary> |
10 | <description>Contains information regarding the user-selected preset</description> |
11 | </key> |
12 | <key type="s" name="custom-presets"> |
13 | <default>''</default> |
14 | <summary>Custom Equalizer Presets</summary> |
15 | - <description>Contains the list of presets added by the user</description> |
16 | + <description>Contains the list of presets added by the user. Gain values are between -80 and 80</description> |
17 | </key> |
18 | <key type="s" name="default-presets"> |
19 | - <default>'Flat,0,0,0,0,0,0,0,0,0,0/Classical,0,0,0,0,0,0,-40,-40,-40,-50/Club,0,0,20,30,30,30,20,0,0,0/Dance,50,35,10,0,0,-30,-40,-40,0,0/Full Bass,70,70,70,40,20,-45,-50,-55,-55,-55/Full Treble,-50,-50,-50,-25,15,55,80,80,80,85/Full Bass + Treble,35,30,0,-40,-25,10,45,55,60,60/Laptop/Headphones,25,50,25,-20,0,-30,-40,-40,0,0/Large Hall,50,50,30,30,0,-25,-25,-25,0,0/Live,-25,0,20,25,30,30,20,15,15,10/Party,35,35,0,0,0,0,0,0,35,35/Pop,-10,25,35,40,25,-5,-15,-15,-10,-10/Reggae,0,0,-5,-30,0,-35,-35,0,0,0/Rock,40,25,-30,-40,-20,20,45,55,55,55/Soft,25,10,-5,-15,-5,20,45,50,55,60/Ska,-15,-25,-25,-5,20,30,45,50,55,50/Soft Rock,20,20,10,-5,-25,-30,-20,-5,15,45/Techno,40,30,0,-30,-25,0,40,50,50,45/'</default> |
20 | + <default>'Flat,0,0,0,0,0,0,0,0,0,0/Classical,0,0,0,0,0,0,-40,-40,-40,-50/Club,0,0,20,30,30,30,20,0,0,0/Dance,50,35,10,0,0,-30,-40,-40,0,0/Full Bass,70,70,70,40,20,-45,-50,-55,-55,-55/Full Treble,-50,-50,-50,-25,15,55,80,80,80,80/Full Bass + Treble,35,30,0,-40,-25,10,45,55,60,60/Laptop/Headphones,25,50,25,-20,0,-30,-40,-40,0,0/Large Hall,50,50,30,30,0,-25,-25,-25,0,0/Live,-25,0,20,25,30,30,20,15,15,10/Party,35,35,0,0,0,0,0,0,35,35/Pop,-10,25,35,40,25,-5,-15,-15,-10,-10/Reggae,0,0,-5,-30,0,-35,-35,0,0,0/Rock,40,25,-30,-40,-20,20,45,55,55,55/Soft,25,10,-5,-15,-5,20,45,50,55,60/Ska,-15,-25,-25,-5,20,30,45,50,55,50/Soft Rock,20,20,10,-5,-25,-30,-20,-5,15,45/Techno,40,30,0,-30,-25,0,40,50,50,45/'</default> |
21 | <summary>Default Equalizer Presets</summary> |
22 | - <description>Contains the list of default presets</description> |
23 | + <description>Contains the list of default presets. Gain values are between -80 and 80</description> |
24 | </key> |
25 | <key type="b" name="auto-switch-preset"> |
26 | <default>true</default> |
27 | |
28 | === modified file 'src/Dialogs/EqualizerWindow.vala' |
29 | --- src/Dialogs/EqualizerWindow.vala 2011-12-01 04:39:30 +0000 |
30 | +++ src/Dialogs/EqualizerWindow.vala 2011-12-05 01:21:23 +0000 |
31 | @@ -1,7 +1,7 @@ |
32 | /*- |
33 | * Copyright (c) 2011 Scott Ringwelski <sgringwe@mtu.edu> |
34 | * |
35 | - * Originally Written by Scott Ringwelski and Victor Eduardo for BeatBox Music Player |
36 | + * Originally Written by Scott Ringwelski and Victor Eduardo for |
37 | * BeatBox Music Player: http://www.launchpad.net/beat-box |
38 | * |
39 | * This library is free software; you can redistribute it and/or |
40 | @@ -37,8 +37,7 @@ |
41 | bool initialized; |
42 | bool automatic_chosen; |
43 | bool adding_preset; |
44 | - |
45 | - private string new_preset_name; |
46 | + bool closing; |
47 | |
48 | List<VScale> scale_list; |
49 | List<Label> label_list; |
50 | @@ -46,6 +45,8 @@ |
51 | bool in_transition; |
52 | Gee.ArrayList<int> target_levels; |
53 | |
54 | + private string new_preset_name; |
55 | + |
56 | public EqualizerWindow (LibraryManager lm, LibraryWindow lw) { |
57 | |
58 | this.lm = lm; |
59 | @@ -53,9 +54,10 @@ |
60 | |
61 | scale_list = new List<VScale>(); |
62 | label_list = new List<Label>(); |
63 | + target_levels = new Gee.ArrayList<int>(); |
64 | + closing = false; |
65 | adding_preset = false; |
66 | initialized = false; |
67 | - target_levels = new Gee.ArrayList<int>(); |
68 | automatic_chosen = false; |
69 | |
70 | build_ui(); |
71 | @@ -70,12 +72,10 @@ |
72 | eq_switch.set_active(lm.settings.getEqualizerEnabled()); |
73 | on_eq_switch_toggled(); |
74 | |
75 | - if (lm.settings.getAutoSwitchPreset()) { |
76 | - preset_combo.selectAutomaticPreset(); |
77 | - on_automatic_chosen(); |
78 | - } |
79 | - |
80 | initialized = true; |
81 | + |
82 | + if (lm.settings.getAutoSwitchPreset()) |
83 | + preset_combo.selectAutomaticPreset(); |
84 | } |
85 | |
86 | void build_ui () { |
87 | @@ -85,17 +85,17 @@ |
88 | window_position = WindowPosition.CENTER; |
89 | type_hint = Gdk.WindowTypeHint.DIALOG; |
90 | set_transient_for(lw); |
91 | - |
92 | set_size_request(440, 224); |
93 | resizable = false; |
94 | + set_deletable(false); |
95 | |
96 | set_icon(render_icon(Gtk.Stock.PREFERENCES, IconSize.DIALOG, null)); |
97 | |
98 | var outer_box = new HBox(false, 10); |
99 | var inner_box = new VBox(false, 0); |
100 | var scales = new HBox(false, 0); |
101 | - bottom_toolbar = new Toolbar(); |
102 | |
103 | + bottom_toolbar = new Toolbar(); |
104 | eq_switch = new Switch(); |
105 | preset_combo = new PresetList(lm, lw); |
106 | |
107 | @@ -132,7 +132,7 @@ |
108 | |
109 | } |
110 | |
111 | - preset_combo.set_size_request(150, -1); |
112 | + preset_combo.set_size_request(170, -1); |
113 | |
114 | var eq_switch_item = new ToolItem(); |
115 | eq_switch_item.add(eq_switch); |
116 | @@ -141,7 +141,7 @@ |
117 | side_list.add(preset_combo); |
118 | |
119 | new_preset_entry = new Entry(); |
120 | - new_preset_entry.set_size_request(150, -1); |
121 | + new_preset_entry.set_size_request(170, -1); |
122 | new_preset_entry.set_icon_from_stock(Gtk.EntryIconPosition.SECONDARY, Gtk.Stock.OK); |
123 | new_preset_entry.set_icon_tooltip_text(Gtk.EntryIconPosition.SECONDARY, "Save this preset"); |
124 | |
125 | @@ -150,10 +150,11 @@ |
126 | |
127 | var space_item = new ToolItem(); |
128 | space_item.set_expand(true); |
129 | - |
130 | + |
131 | var close_button = new Button.with_label("Close"); |
132 | var close_button_item = new ToolItem(); |
133 | - close_button_item.set_expand(true); |
134 | + close_button.set_size_request(120, -1); |
135 | + close_button_item.set_expand(false); |
136 | close_button_item.add(close_button); |
137 | |
138 | bottom_toolbar.insert(eq_switch_item, 0); |
139 | @@ -172,18 +173,25 @@ |
140 | |
141 | eq_switch.notify["active"].connect(on_eq_switch_toggled); |
142 | preset_combo.automatic_preset_chosen.connect(on_automatic_chosen); |
143 | - preset_combo.add_preset_chosen.connect(addPresetClicked); |
144 | - preset_combo.delete_preset_chosen.connect(removePresetClicked); |
145 | - preset_combo.preset_selected.connect(presetSelected); |
146 | + preset_combo.add_preset_chosen.connect(add_preset_clicked); |
147 | + preset_combo.delete_preset_chosen.connect(remove_preset_clicked); |
148 | + preset_combo.preset_selected.connect (preset_selected); |
149 | new_preset_entry.activate.connect (add_new_preset); |
150 | new_preset_entry.icon_press.connect (new_preset_entry_icon_pressed); |
151 | + new_preset_entry.focus_out_event.connect (on_entry_focus_out); |
152 | |
153 | - close_button.clicked.connect(on_close); |
154 | - destroy.connect(on_close); |
155 | + close_button.clicked.connect(on_close_button_clicked); |
156 | + destroy.connect(on_quit); |
157 | |
158 | show_all(); |
159 | } |
160 | |
161 | + bool on_entry_focus_out () { |
162 | + if(!closing) |
163 | + new_preset_entry.grab_focus(); |
164 | + return true; |
165 | + } |
166 | + |
167 | static Gtk.Alignment wrap_alignment (Gtk.Widget widget, int top, int right, int bottom, int left) { |
168 | |
169 | var alignment = new Gtk.Alignment(0.0f, 0.0f, 1.0f, 1.0f); |
170 | @@ -246,11 +254,12 @@ |
171 | foreach (EqualizerPreset preset in custom_presets) { |
172 | preset_combo.addPreset(preset); |
173 | } |
174 | + |
175 | + preset_combo.default_presets_changed = false; |
176 | } |
177 | |
178 | - void presetSelected(EqualizerPreset p) { |
179 | + void preset_selected (EqualizerPreset p) { |
180 | automatic_chosen = false; |
181 | - |
182 | set_sliders_sensitivity (true); |
183 | target_levels.clear(); |
184 | |
185 | @@ -258,17 +267,21 @@ |
186 | target_levels.add(i); |
187 | } |
188 | |
189 | - if (!initialized) { |
190 | + set_target_levels (); |
191 | + |
192 | + if (!in_transition && !closing) { |
193 | + in_transition = true; |
194 | + Timeout.add(20, transition_scales); |
195 | + } |
196 | + } |
197 | + |
198 | + void set_target_levels () { |
199 | + if (!initialized || closing) { |
200 | for (int index = 0; index < 10; ++index) { |
201 | scale_list.nth_data(index).set_value(target_levels.get(index)); |
202 | } |
203 | return; |
204 | } |
205 | - |
206 | - if (!in_transition) { |
207 | - in_transition = true; |
208 | - Timeout.add(20, transition_scales); |
209 | - } |
210 | } |
211 | |
212 | bool transition_scales () { |
213 | @@ -280,7 +293,7 @@ |
214 | double targetLvl = target_levels.get(index); |
215 | double difference = targetLvl - currLvl; |
216 | |
217 | - if (Math.fabs(difference) <= 1) |
218 | + if (closing || Math.fabs(difference) <= 1) |
219 | scale_list.nth_data(index).set_value(targetLvl); |
220 | else { |
221 | scale_list.nth_data(index).set_value(scale_list.nth_data(index).get_value() + (difference / 8.0)); |
222 | @@ -311,39 +324,19 @@ |
223 | |
224 | adding_preset = true; |
225 | |
226 | - bool preset_already_exists = false; |
227 | - var current_presets = preset_combo.getPresets(); |
228 | - |
229 | bottom_toolbar.remove(side_list); |
230 | bottom_toolbar.insert(new_preset_field, 1); |
231 | |
232 | - string current_preset_name = preset_combo.getSelectedPreset().name; |
233 | - string new_preset_name = " "; |
234 | - int i = 1; |
235 | - |
236 | - do |
237 | - { |
238 | - new_preset_name = current_preset_name + " (Custom" + ((preset_already_exists)? " " + i.to_string() : "") + ")"; |
239 | - |
240 | - preset_already_exists = false; |
241 | - |
242 | - foreach(EqualizerPreset preset in current_presets) { |
243 | - if(new_preset_name == preset.name) { |
244 | - preset_already_exists = true; |
245 | - break; |
246 | - } |
247 | - } |
248 | - |
249 | - i++; |
250 | - |
251 | - } while (preset_already_exists); |
252 | + new_preset_name = create_new_preset_name(true); |
253 | |
254 | new_preset_entry.set_text(new_preset_name); |
255 | + eq_switch.sensitive = false; |
256 | bottom_toolbar.show_all(); |
257 | new_preset_entry.grab_focus(); |
258 | } |
259 | |
260 | void new_preset_entry_icon_pressed (EntryIconPosition pos, Gdk.Event event) { |
261 | + |
262 | if(pos != Gtk.EntryIconPosition.SECONDARY && !adding_preset) |
263 | return; |
264 | |
265 | @@ -351,12 +344,13 @@ |
266 | } |
267 | |
268 | void add_new_preset() { |
269 | + |
270 | if(!adding_preset) |
271 | return; |
272 | |
273 | var new_name = new_preset_entry.get_text(); |
274 | |
275 | - if(new_name != null) |
276 | + if(verify_preset_name(new_name)) |
277 | new_preset_name = new_name; |
278 | |
279 | int i = 0; |
280 | @@ -373,31 +367,118 @@ |
281 | bottom_toolbar.remove(new_preset_field); |
282 | bottom_toolbar.insert(side_list, 1); |
283 | bottom_toolbar.show_all(); |
284 | - |
285 | + eq_switch.sensitive = true; |
286 | adding_preset = false; |
287 | } |
288 | |
289 | - void addPresetClicked () { |
290 | - PresetNameWindow pnw = new PresetNameWindow(lw, new EqualizerPreset.basic("Custom Preset")); |
291 | - pnw.preset_saved.connect(presetNameWindowSaved); |
292 | - } |
293 | - |
294 | - void presetNameWindowSaved (EqualizerPreset p) { |
295 | + string create_new_preset_name (bool from_current) { |
296 | + |
297 | + int i = 0; |
298 | + bool is_valid = false; |
299 | + |
300 | + string current_preset_name = (from_current)? preset_combo.getSelectedPreset().name : ""; |
301 | + string preset_name = "Custom Preset"; |
302 | + |
303 | + do |
304 | + { |
305 | + preset_name = (from_current)? current_preset_name + " (" : ""; |
306 | + preset_name += "Custom" + ((from_current)? "" : " Preset"); |
307 | + preset_name += ((!is_valid && i > 0)? " " + i.to_string() : ""); |
308 | + preset_name += (from_current)? ")" : ""; |
309 | + |
310 | + i++; |
311 | + |
312 | + is_valid = verify_preset_name(preset_name); |
313 | + } while (!is_valid); |
314 | + |
315 | + return preset_name; |
316 | + } |
317 | + |
318 | + public bool verify_preset_name(string name) { |
319 | + |
320 | + /* This function verifies the name of a new preset. |
321 | + It will return 'true' whenever: |
322 | + - The name is not null |
323 | + - The name doesn't consist [enterely] of white space. |
324 | + - The name is not already in the list. |
325 | + */ |
326 | + |
327 | + int white_space = 0; |
328 | + int str_length = name.length; |
329 | + bool preset_already_exists = false; |
330 | + |
331 | + if(str_length < 1) |
332 | + return false; |
333 | + |
334 | + for(int i = 0; i < str_length; ++i) { |
335 | + if(name[i] == ' ' || name[i] == '\t') |
336 | + white_space++; |
337 | + } |
338 | + |
339 | + if(white_space == str_length) |
340 | + return false; |
341 | + |
342 | + var current_presets = preset_combo.getPresets(); |
343 | + |
344 | + preset_already_exists = false; |
345 | + |
346 | + foreach(EqualizerPreset preset in current_presets) { |
347 | + if(name == preset.name) { |
348 | + preset_already_exists = true; |
349 | + break; |
350 | + } |
351 | + } |
352 | + |
353 | + return !preset_already_exists; |
354 | + } |
355 | + |
356 | + void add_preset_clicked () { |
357 | + string name = create_new_preset_name(false); |
358 | + PresetNameWindow pnw = new PresetNameWindow(this, new EqualizerPreset.basic(name)); |
359 | + pnw.preset_saved.connect(preset_name_window_saved); |
360 | + pnw.action_canceled.connect(select_last_used_preset); |
361 | + } |
362 | + |
363 | + void select_last_used_preset () { |
364 | + var last_preset = preset_combo.last_selected_preset; |
365 | + |
366 | + if(!automatic_chosen && last_preset != null) |
367 | + preset_combo.selectPreset(last_preset.name); |
368 | + else |
369 | + preset_combo.selectAutomaticPreset(); |
370 | + } |
371 | + |
372 | + void preset_name_window_saved (EqualizerPreset p) { |
373 | preset_combo.addPreset(p); |
374 | } |
375 | |
376 | - void removePresetClicked () { |
377 | - |
378 | - preset_combo.removeCurrentPreset(); |
379 | + void remove_preset_clicked () { |
380 | + if(!automatic_chosen) |
381 | + preset_combo.removeCurrentPreset(); |
382 | } |
383 | |
384 | - void on_close () { |
385 | + void on_close_button_clicked () { |
386 | + closing = true; |
387 | + |
388 | + if(adding_preset) |
389 | + add_new_preset(); |
390 | + |
391 | if(!in_transition) |
392 | close_equalizer(); |
393 | else |
394 | Timeout.add(20, close_equalizer); |
395 | } |
396 | - |
397 | + |
398 | + void on_quit () { |
399 | + |
400 | + if(!in_transition) |
401 | + on_close_button_clicked(); |
402 | + else { |
403 | + set_target_levels (); |
404 | + close_equalizer (); |
405 | + } |
406 | + } |
407 | + |
408 | bool close_equalizer () { |
409 | |
410 | if(in_transition) |
411 | @@ -405,27 +486,29 @@ |
412 | |
413 | lm.settings.setEqualizerEnabled(eq_switch.get_active()); |
414 | |
415 | - if(preset_combo.getSelectedPreset() != null) { |
416 | + if(preset_combo.getSelectedPreset() != null) |
417 | lm.settings.setSelectedPreset(preset_combo.getSelectedPreset()); |
418 | - } |
419 | |
420 | var defaultPresets = new Gee.LinkedList<EqualizerPreset>(); |
421 | var customPresets = new Gee.LinkedList<EqualizerPreset>(); |
422 | |
423 | - foreach(EqualizerPreset preset in preset_combo.getPresets()) { |
424 | - if(preset.is_default == true) |
425 | - defaultPresets.add(preset); |
426 | + foreach (EqualizerPreset preset in preset_combo.getPresets()) { |
427 | + if (preset.is_default == true) |
428 | + defaultPresets.add (preset); |
429 | else |
430 | - customPresets.add(preset); |
431 | + customPresets.add (preset); |
432 | } |
433 | |
434 | - lm.settings.setPresets(defaultPresets, null); |
435 | - lm.settings.setPresets(customPresets, "custom-presets"); |
436 | - |
437 | - lm.settings.setAutoSwitchPreset(automatic_chosen); |
438 | + if(preset_combo.default_presets_changed) |
439 | + lm.settings.setPresets (defaultPresets, null); |
440 | + |
441 | + lm.settings.setPresets (customPresets, lm.settings.CUSTOM_PRESETS); |
442 | + |
443 | + lm.settings.setAutoSwitchPreset (automatic_chosen); |
444 | |
445 | destroy(); |
446 | |
447 | return false; |
448 | } |
449 | } |
450 | + |
451 | |
452 | === modified file 'src/Dialogs/PresetNameWindow.vala' |
453 | --- src/Dialogs/PresetNameWindow.vala 2011-11-30 22:17:03 +0000 |
454 | +++ src/Dialogs/PresetNameWindow.vala 2011-12-05 01:21:23 +0000 |
455 | @@ -20,14 +20,12 @@ |
456 | * Boston, MA 02111-1307, USA. |
457 | */ |
458 | |
459 | -/* Merely a place holder for multiple pieces of information regarding |
460 | - * the current song playing. Mostly here because of dependence. */ |
461 | - |
462 | using Gtk; |
463 | |
464 | public class BeatBox.PresetNameWindow : Window { |
465 | public EqualizerPreset _original; |
466 | |
467 | + EqualizerWindow ew; |
468 | VBox content; |
469 | HBox padding; |
470 | |
471 | @@ -35,14 +33,17 @@ |
472 | public Button _save; |
473 | |
474 | public signal void preset_saved(EqualizerPreset p); |
475 | + public signal void action_canceled(); |
476 | |
477 | - public PresetNameWindow(LibraryWindow lw, EqualizerPreset original) { |
478 | + public PresetNameWindow(EqualizerWindow ew, EqualizerPreset original) { |
479 | title = ""; |
480 | |
481 | + this.ew = ew; |
482 | + |
483 | this.window_position = WindowPosition.CENTER; |
484 | this.type_hint = Gdk.WindowTypeHint.DIALOG; |
485 | this.set_modal(true); |
486 | - this.set_transient_for(lw); |
487 | + this.set_transient_for(ew); |
488 | this.destroy_with_parent = true; |
489 | resizable = false; |
490 | set_size_request(200, -1); |
491 | @@ -80,6 +81,7 @@ |
492 | |
493 | _save.clicked.connect(saveClicked); |
494 | _name.activate.connect(nameActivate); |
495 | + this.destroy.connect(on_action_canceled); |
496 | } |
497 | |
498 | public static Gtk.Alignment wrap_alignment (Gtk.Widget widget, int top, int right, int bottom, int left) { |
499 | @@ -94,7 +96,9 @@ |
500 | } |
501 | |
502 | public virtual void saveClicked() { |
503 | - _original.name = _name.text; |
504 | + if(ew.verify_preset_name(_name.text)) |
505 | + _original.name = _name.text; |
506 | + |
507 | preset_saved(_original); |
508 | |
509 | this.destroy(); |
510 | @@ -103,4 +107,9 @@ |
511 | public virtual void nameActivate() { |
512 | saveClicked(); |
513 | } |
514 | + |
515 | + public virtual void on_action_canceled() { |
516 | + action_canceled(); |
517 | + this.destroy(); |
518 | + } |
519 | } |
520 | |
521 | === modified file 'src/LibraryManager.vala' |
522 | --- src/LibraryManager.vala 2011-12-03 21:19:37 +0000 |
523 | +++ src/LibraryManager.vala 2011-12-05 01:21:23 +0000 |
524 | @@ -222,11 +222,7 @@ |
525 | |
526 | // set the equalizer |
527 | if(settings.getEqualizerEnabled() && !settings.getAutoSwitchPreset()) { |
528 | - EqualizerPreset p = settings.getSelectedPreset(); |
529 | - if(p != null) { |
530 | - for(int i = 0; i < 10; ++i) |
531 | - player.setEqualizerGain(i, p.getGain(i)); |
532 | - } |
533 | + set_selected_equalizer_preset (); |
534 | } |
535 | |
536 | dm = new DeviceManager(this); |
537 | @@ -1291,13 +1287,7 @@ |
538 | } |
539 | |
540 | if(!matched_genre) { |
541 | - var p = settings.getSelectedPreset(); |
542 | - |
543 | - if(p == null) |
544 | - return null; |
545 | - |
546 | - for(int i = 0; i < 10; ++i) |
547 | - player.setEqualizerGain(i, p.getGain(i)); |
548 | + set_selected_equalizer_preset (); |
549 | } |
550 | } |
551 | |
552 | @@ -1495,6 +1485,19 @@ |
553 | progress_cancel_clicked(); |
554 | } |
555 | |
556 | + public void set_selected_equalizer_preset () { |
557 | + string selected_preset = settings.getSelectedPreset(); |
558 | + if(selected_preset != null) { |
559 | + foreach (EqualizerPreset p in settings.getPresets(null)) { |
560 | + if(p.name == selected_preset) { |
561 | + for(int i = 0; i < 10; ++i) |
562 | + player.setEqualizerGain(i, p.getGain(i)); |
563 | + break; |
564 | + } |
565 | + } |
566 | + } |
567 | + } |
568 | + |
569 | public Gdk.Pixbuf? get_album_art(int id) { |
570 | Song s = _songs.get(id); |
571 | |
572 | |
573 | === modified file 'src/Settings.vala' |
574 | --- src/Settings.vala 2011-11-22 03:08:33 +0000 |
575 | +++ src/Settings.vala 2011-12-05 01:21:23 +0000 |
576 | @@ -306,18 +306,12 @@ |
577 | return getBool(EQUALIZER_ENABLED, false); |
578 | } |
579 | |
580 | - public EqualizerPreset? getSelectedPreset() { |
581 | - string[] vals = getString(SELECTED_PRESET, "").split(",", 0); |
582 | + public string? getSelectedPreset() { |
583 | + string rv = getString(SELECTED_PRESET, ""); |
584 | |
585 | - if(vals.length == 0 || vals[0] == null) |
586 | + if(rv != null && rv.length == 0) |
587 | return null; |
588 | - |
589 | - var rv = new EqualizerPreset.basic(vals[0]); |
590 | - |
591 | - for(int i = 1; i < vals.length; ++i) { |
592 | - rv.setGain(i-1, int.parse(vals[i])); |
593 | - } |
594 | - |
595 | + |
596 | return rv; |
597 | } |
598 | |
599 | @@ -458,13 +452,7 @@ |
600 | } |
601 | |
602 | public void setSelectedPreset(EqualizerPreset preset) { |
603 | - string toSave = preset.name; |
604 | - |
605 | - foreach(int gain in preset.gains) { |
606 | - toSave += "," + gain.to_string(); |
607 | - } |
608 | - |
609 | - setString(SELECTED_PRESET, toSave); |
610 | + setString(SELECTED_PRESET, (preset != null)? preset.name : ""); |
611 | } |
612 | |
613 | public void setPresets(Gee.Collection<EqualizerPreset> presets, string? type) { |
614 | |
615 | === modified file 'src/Widgets/PresetList.vala' |
616 | --- src/Widgets/PresetList.vala 2011-11-30 22:17:03 +0000 |
617 | +++ src/Widgets/PresetList.vala 2011-12-05 01:21:23 +0000 |
618 | @@ -5,9 +5,11 @@ |
619 | LibraryWindow lw; |
620 | ListStore store; |
621 | |
622 | - private int ndefaultpresets = 0; |
623 | - private int ncustompresets = 0; |
624 | + private int ndefaultpresets; |
625 | + private int ncustompresets; |
626 | |
627 | + private bool default_presets_modified; |
628 | + |
629 | private bool modifying_list; |
630 | |
631 | public int preset_list_size { |
632 | @@ -15,9 +17,17 @@ |
633 | return ndefaultpresets + ncustompresets; |
634 | } |
635 | } |
636 | - |
637 | - EqualizerPreset currentPreset; |
638 | - |
639 | + |
640 | + public bool default_presets_changed { |
641 | + get { |
642 | + return default_presets_modified; |
643 | + } set { |
644 | + default_presets_modified = value; |
645 | + } |
646 | + } |
647 | + |
648 | + public EqualizerPreset last_selected_preset; |
649 | + |
650 | public signal void preset_selected(EqualizerPreset p); |
651 | public signal void automatic_preset_chosen(); |
652 | public signal void add_preset_chosen(); |
653 | @@ -27,6 +37,8 @@ |
654 | this.lm = lm; |
655 | this.lw = lw; |
656 | |
657 | + ndefaultpresets = 0; |
658 | + ncustompresets = 0; |
659 | modifying_list = false; |
660 | |
661 | buildUI(); |
662 | @@ -74,7 +86,7 @@ |
663 | store.set(iter, 0, null, 1, "Add New..."); |
664 | } |
665 | |
666 | - if((ndefaultpresets + ncustompresets) > 0) { |
667 | + if(this.preset_list_size > 0) { |
668 | store.append(out iter); |
669 | store.set(iter, 0, null, 1, "Delete Current"); |
670 | } |
671 | @@ -87,26 +99,23 @@ |
672 | modifying_list = true; |
673 | TreeIter iter; |
674 | |
675 | - if((ndefaultpresets + ncustompresets) < 1) { |
676 | - |
677 | - clearList(); |
678 | - |
679 | - if(ep.is_default) |
680 | - ndefaultpresets++; |
681 | - else |
682 | - ncustompresets++; |
683 | - |
684 | - addTopOptions(); |
685 | - } |
686 | - else if(ep.is_default) |
687 | + if(ep.is_default) { |
688 | ndefaultpresets++; |
689 | - else |
690 | + default_presets_modified = true; |
691 | + } else { |
692 | ncustompresets++; |
693 | + } |
694 | + |
695 | + if((this.preset_list_size - 1) < 1) { |
696 | + clearList(); |
697 | + addTopOptions(); |
698 | + } |
699 | |
700 | store.append(out iter); |
701 | store.set(iter, 0, ep, 1, ep.name); |
702 | |
703 | modifying_list = false; |
704 | + |
705 | // TODO: Sort item |
706 | |
707 | set_active_iter(iter); |
708 | @@ -115,7 +124,7 @@ |
709 | public void removeCurrentPreset() { |
710 | modifying_list = true; |
711 | |
712 | - if(currentPreset == null || (ndefaultpresets + ncustompresets) < 1) { |
713 | + if(last_selected_preset == null || this.preset_list_size < 1) { |
714 | return; |
715 | } |
716 | |
717 | @@ -124,20 +133,23 @@ |
718 | GLib.Object o; |
719 | store.get(iter, 0, out o); |
720 | |
721 | - if(o != null && o is EqualizerPreset && ((EqualizerPreset)o) == currentPreset) { |
722 | - if(((EqualizerPreset)o).is_default) |
723 | + if(o != null && o is EqualizerPreset && ((EqualizerPreset)o) == last_selected_preset) { |
724 | + if (((EqualizerPreset)o).is_default) { |
725 | ndefaultpresets--; |
726 | - else |
727 | + default_presets_modified = true; |
728 | + } else { |
729 | ncustompresets--; |
730 | + } |
731 | |
732 | store.remove(iter); |
733 | } |
734 | } |
735 | |
736 | - if((ndefaultpresets + ncustompresets) < 1) { |
737 | + if(this.preset_list_size < 1) { |
738 | clearList(); |
739 | addTopOptions(); |
740 | } |
741 | + |
742 | modifying_list = false; |
743 | set_active(0); |
744 | } |
745 | @@ -154,7 +166,7 @@ |
746 | |
747 | if(o != null && o is EqualizerPreset) { |
748 | set_title(((EqualizerPreset)o).name); |
749 | - currentPreset = (EqualizerPreset)o; |
750 | + last_selected_preset = (EqualizerPreset)o; |
751 | preset_selected((EqualizerPreset)o); |
752 | } |
753 | else { // is Automatic, Add Preset or Delete Current |
754 | @@ -166,7 +178,7 @@ |
755 | } |
756 | else { |
757 | delete_preset_chosen(); |
758 | - selectPreset(currentPreset); |
759 | + selectPreset(last_selected_preset.name); |
760 | } |
761 | } |
762 | } |
763 | @@ -175,34 +187,36 @@ |
764 | set_active(0); |
765 | } |
766 | |
767 | - public void selectPreset(EqualizerPreset? p) { |
768 | - if(p == null) { |
769 | + public void selectPreset(string? preset_name) { |
770 | + if(preset_name == null || preset_name.length < 1) { |
771 | set_active(0); |
772 | } |
773 | - |
774 | + |
775 | TreeIter iter; |
776 | for(int i = 0; store.get_iter_from_string(out iter, i.to_string()); ++i) { |
777 | GLib.Object o; |
778 | store.get(iter, 0, out o); |
779 | - |
780 | - if(o != null && o is EqualizerPreset && ((EqualizerPreset)o).name == p.name) { |
781 | + |
782 | + if(o != null && o is EqualizerPreset && ((EqualizerPreset)o).name == preset_name) { |
783 | set_active_iter(iter); |
784 | - |
785 | return; |
786 | } |
787 | } |
788 | - |
789 | + |
790 | set_active(0); |
791 | } |
792 | |
793 | - public EqualizerPreset getSelectedPreset() { |
794 | + public EqualizerPreset? getSelectedPreset() { |
795 | TreeIter it; |
796 | get_active_iter(out it); |
797 | |
798 | GLib.Object o; |
799 | store.get(it, 0, out o); |
800 | - |
801 | - return (EqualizerPreset)o; |
802 | + |
803 | + if(o != null && o is EqualizerPreset) |
804 | + return (EqualizerPreset)o; |
805 | + else |
806 | + return null; |
807 | } |
808 | |
809 | public Gee.Collection<EqualizerPreset> getPresets() { |
810 | @@ -220,3 +234,4 @@ |
811 | return rv; |
812 | } |
813 | } |
814 | + |
Wow, this is impressive!