Mercurial > audlegacy-plugins
annotate src/skins/ui_equalizer.c @ 2668:a1431a900f28
introduce ui_skinned_button_set_inside
author | Tomasz Mon <desowin@gmail.com> |
---|---|
date | Fri, 30 May 2008 21:02:12 +0200 |
parents | ba91ea50f214 |
children | 438597b1f669 |
rev | line source |
---|---|
2606 | 1 /* Audacious - Cross-platform multimedia player |
2 * Copyright (C) 2005-2007 Audacious development team. | |
3 * | |
4 * Based on BMP: | |
5 * Copyright (C) 2003-2004 BMP development team. | |
6 * | |
7 * Based on XMMS: | |
8 * Copyright (C) 1998-2003 XMMS development team. | |
9 * | |
10 * This program is free software; you can redistribute it and/or modify | |
11 * it under the terms of the GNU General Public License as published by | |
12 * the Free Software Foundation; under version 3 of the License. | |
13 * | |
14 * This program is distributed in the hope that it will be useful, | |
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
17 * GNU General Public License for more details. | |
18 * | |
19 * You should have received a copy of the GNU General Public License | |
20 * along with this program. If not, see <http://www.gnu.org/licenses>. | |
21 * | |
22 * The Audacious team does not consider modular code linking to | |
23 * Audacious or using our public API to be a derived work. | |
24 */ | |
25 | |
26 /*#define AUD_DEBUG*/ | |
27 | |
28 #ifdef HAVE_CONFIG_H | |
29 # include "config.h" | |
30 #endif | |
31 | |
32 #include "ui_equalizer.h" | |
33 | |
34 #include <glib.h> | |
35 #include <glib/gi18n.h> | |
36 #include <gtk/gtk.h> | |
37 #include <stdio.h> | |
38 #include <math.h> | |
39 #include <string.h> | |
40 | |
41 #include "platform/smartinclude.h" | |
42 #include "ui_skin.h" | |
43 #include "ui_manager.h" | |
44 #include "actions-equalizer.h" | |
45 #include "util.h" | |
46 #include "ui_main.h" | |
47 #include <audacious/plugin.h> | |
48 | |
49 #include "images/audacious_eq.xpm" | |
50 | |
51 #include "ui_dock.h" | |
52 #include "ui_skinned_window.h" | |
53 #include "ui_skinned_button.h" | |
54 #include "ui_skinned_horizontal_slider.h" | |
55 #include "ui_skinned_equalizer_slider.h" | |
56 #include "ui_skinned_equalizer_graph.h" | |
57 #include "skins_cfg.h" | |
58 | |
59 enum PresetViewCols { | |
60 PRESET_VIEW_COL_NAME, | |
61 PRESET_VIEW_N_COLS | |
62 }; | |
63 | |
64 struct _EqualizerPreset { | |
65 gchar *name; | |
66 gfloat preamp, bands[10]; | |
67 }; | |
68 | |
69 typedef struct _EqualizerPreset EqualizerPreset; | |
70 | |
71 | |
72 GtkWidget *equalizerwin; | |
73 GtkWidget *equalizerwin_graph; | |
74 | |
75 static GtkWidget *equalizerwin_load_window = NULL; | |
76 static GtkWidget *equalizerwin_load_auto_window = NULL; | |
77 static GtkWidget *equalizerwin_save_window = NULL; | |
78 static GtkWidget *equalizerwin_save_entry = NULL; | |
79 static GtkWidget *equalizerwin_save_auto_window = NULL; | |
80 static GtkWidget *equalizerwin_save_auto_entry = NULL; | |
81 static GtkWidget *equalizerwin_delete_window = NULL; | |
82 static GtkWidget *equalizerwin_delete_auto_window = NULL; | |
83 | |
84 static GtkWidget *equalizerwin_on, *equalizerwin_auto; | |
85 | |
86 static GtkWidget *equalizerwin_close, *equalizerwin_presets, *equalizerwin_shade; | |
87 static GtkWidget *equalizerwin_preamp,*equalizerwin_bands[10]; | |
88 static GtkWidget *equalizerwin_volume, *equalizerwin_balance; | |
89 | |
90 static GList *equalizer_presets = NULL, *equalizer_auto_presets = NULL; | |
91 | |
92 EqualizerPreset * | |
93 equalizer_preset_new(const gchar * name) | |
94 { | |
95 EqualizerPreset *preset = g_new0(EqualizerPreset, 1); | |
96 preset->name = g_strdup(name); | |
97 return preset; | |
98 } | |
99 | |
100 void | |
101 equalizer_preset_free(EqualizerPreset * preset) | |
102 { | |
103 if (!preset) | |
104 return; | |
105 | |
106 g_free(preset->name); | |
107 g_free(preset); | |
108 } | |
109 | |
110 void | |
111 equalizerwin_set_scaled(gboolean ds) | |
112 { | |
113 gint height; | |
114 | |
115 if (config.equalizer_shaded) | |
116 height = 14; | |
117 else | |
118 height = 116; | |
119 | |
120 if (config.scaled) { | |
121 dock_window_resize(GTK_WINDOW(equalizerwin), 275 * config.scale_factor, | |
122 height * config.scale_factor, 275 * config.scale_factor, height * config.scale_factor); | |
123 } else { | |
124 dock_window_resize(GTK_WINDOW(equalizerwin), 275, height, 275, height); | |
125 } | |
126 | |
127 GList *iter; | |
128 for (iter = GTK_FIXED (SKINNED_WINDOW(equalizerwin)->fixed)->children; iter; iter = g_list_next (iter)) { | |
129 GtkFixedChild *child_data = (GtkFixedChild *) iter->data; | |
130 GtkWidget *child = child_data->widget; | |
131 g_signal_emit_by_name(child, "toggle-scaled"); | |
132 } | |
133 gtk_widget_shape_combine_mask(equalizerwin, skin_get_mask(aud_active_skin, SKIN_MASK_EQ + config.equalizer_shaded), 0, 0); | |
134 } | |
135 | |
136 void | |
137 equalizerwin_set_shade_menu_cb(gboolean shaded) | |
138 { | |
139 config.equalizer_shaded = shaded; | |
140 | |
141 if (shaded) { | |
142 dock_shade(get_dock_window_list(), GTK_WINDOW(equalizerwin), | |
143 14 * EQUALIZER_SCALE_FACTOR); | |
144 ui_skinned_set_push_button_data(equalizerwin_shade, -1, 3, -1, 47); | |
145 ui_skinned_button_set_skin_index1(equalizerwin_shade, SKIN_EQ_EX); | |
146 ui_skinned_set_push_button_data(equalizerwin_close, 11, 38, 11, 47); | |
147 ui_skinned_button_set_skin_index(equalizerwin_close, SKIN_EQ_EX); | |
148 gtk_widget_show(equalizerwin_volume); | |
149 gtk_widget_show(equalizerwin_balance); | |
150 } | |
151 else { | |
152 dock_shade(get_dock_window_list(), GTK_WINDOW(equalizerwin), | |
153 116 * EQUALIZER_SCALE_FACTOR); | |
154 ui_skinned_set_push_button_data(equalizerwin_shade, -1, 137, -1, 38); | |
155 ui_skinned_button_set_skin_index1(equalizerwin_shade, SKIN_EQMAIN); | |
156 ui_skinned_set_push_button_data(equalizerwin_close, 0, 116, 0, 125); | |
157 ui_skinned_button_set_skin_index(equalizerwin_close, SKIN_EQMAIN); | |
158 gtk_widget_hide(equalizerwin_volume); | |
159 gtk_widget_hide(equalizerwin_balance); | |
160 } | |
161 | |
162 gtk_widget_shape_combine_mask(equalizerwin, skin_get_mask(aud_active_skin, SKIN_MASK_EQ + config.equalizer_shaded), 0, 0); | |
163 } | |
164 | |
165 static void | |
166 equalizerwin_set_shade(gboolean shaded) | |
167 { | |
168 GtkAction *action = gtk_action_group_get_action( | |
169 toggleaction_group_others , "roll up equalizer" ); | |
170 gtk_toggle_action_set_active( GTK_TOGGLE_ACTION(action) , shaded ); | |
171 } | |
172 | |
173 static void | |
174 equalizerwin_shade_toggle(void) | |
175 { | |
176 equalizerwin_set_shade(!config.equalizer_shaded); | |
177 } | |
178 | |
179 void | |
180 equalizerwin_eq_changed(void) | |
181 { | |
182 gint i; | |
183 | |
184 aud_cfg->equalizer_preamp = ui_skinned_equalizer_slider_get_position(equalizerwin_preamp); | |
185 for (i = 0; i < 10; i++) | |
186 aud_cfg->equalizer_bands[i] = ui_skinned_equalizer_slider_get_position(equalizerwin_bands[i]); | |
2641 | 187 |
188 aud_hook_call("equalizer changed", NULL); | |
2606 | 189 gtk_widget_queue_draw(equalizerwin_graph); |
190 } | |
191 | |
192 static void | |
193 equalizerwin_on_pushed(void) | |
194 { | |
195 aud_cfg->equalizer_active = UI_SKINNED_BUTTON(equalizerwin_on)->inside; | |
196 equalizerwin_eq_changed(); | |
197 } | |
198 | |
199 static void | |
200 equalizerwin_presets_pushed(void) | |
201 { | |
202 GdkModifierType modmask; | |
203 gint x, y; | |
204 | |
205 gdk_window_get_pointer(NULL, &x, &y, &modmask); | |
206 ui_manager_popup_menu_show(GTK_MENU(equalizerwin_presets_menu), x, y, 1, GDK_CURRENT_TIME); | |
207 } | |
208 | |
209 static void | |
210 equalizerwin_auto_pushed(void) | |
211 { | |
212 aud_cfg->equalizer_autoload = UI_SKINNED_BUTTON(equalizerwin_auto)->inside; | |
213 } | |
214 | |
215 gboolean | |
216 equalizerwin_press(GtkWidget * widget, GdkEventButton * event, | |
217 gpointer callback_data) | |
218 { | |
219 if (event->button == 1 && event->type == GDK_2BUTTON_PRESS | |
220 && event->y < 14) { | |
221 equalizerwin_set_shade(!config.equalizer_shaded); | |
222 if (dock_is_moving(GTK_WINDOW(equalizerwin))) | |
223 dock_move_release(GTK_WINDOW(equalizerwin)); | |
224 return TRUE; | |
225 } | |
226 if (event->button == 3) { | |
227 /* | |
228 * Pop up the main menu a few pixels down to avoid | |
229 * anything to be selected initially. | |
230 */ | |
231 ui_manager_popup_menu_show(GTK_MENU(mainwin_general_menu), event->x_root, | |
232 event->y_root + 2, 3, event->time); | |
233 return TRUE; | |
234 } | |
235 | |
236 return FALSE; | |
237 } | |
238 | |
239 static gboolean | |
240 equalizerwin_keypress(GtkWidget * widget, | |
241 GdkEventKey * event, | |
242 gpointer data) | |
243 { | |
244 #if 0 | |
245 if (event->keyval == GDK_Tab && event->state & GDK_CONTROL_MASK) { | |
246 if (config.playlist_visible) | |
247 gtk_window_present(GTK_WINDOW(playlistwin)); | |
248 else if (config.player_visible) | |
249 gtk_window_present(GTK_WINDOW(mainwin)); | |
250 return TRUE; | |
251 } | |
252 #endif | |
253 if (!config.equalizer_shaded) { | |
254 gtk_widget_event(mainwin, (GdkEvent *) event); | |
255 return TRUE; | |
256 } | |
257 | |
258 switch (event->keyval) { | |
259 case GDK_Left: | |
260 case GDK_KP_Left: | |
261 mainwin_set_balance_diff(-4); | |
262 break; | |
263 case GDK_Right: | |
264 case GDK_KP_Right: | |
265 mainwin_set_balance_diff(4); | |
266 break; | |
267 default: | |
268 gtk_widget_event(mainwin, (GdkEvent *) event); | |
269 break; | |
270 } | |
271 | |
272 return FALSE; | |
273 } | |
274 | |
275 static void | |
276 equalizerwin_close_cb(void) | |
277 { | |
278 equalizerwin_show(FALSE); | |
279 } | |
280 | |
281 static gboolean | |
282 equalizerwin_delete(GtkWidget * widget, | |
283 gpointer data) | |
284 { | |
285 equalizerwin_show(FALSE); | |
286 return TRUE; | |
287 } | |
288 | |
289 static GList * | |
290 equalizerwin_read_presets(const gchar * basename) | |
291 { | |
292 #if 0 | |
293 gchar *filename, *name; | |
294 RcFile *rcfile; | |
295 GList *list = NULL; | |
296 gint i, p = 0; | |
297 EqualizerPreset *preset; | |
298 | |
299 /* START mod: add check for the default presets locate in system path ({prefix}/share/audacious) | |
300 by Massimo Cavalleri (submax) */ | |
301 | |
302 filename = g_build_filename(aud_paths[BMP_PATH_USER_DIR], basename, NULL); | |
303 | |
304 if ((rcfile = aud_rcfile_open(filename)) == NULL) { | |
305 g_free(filename); | |
306 // DATA_DIR = "{prefix}/share/audacious" ; example is "/usr/share/audacious" | |
307 filename = g_build_filename(DATA_DIR, basename, NULL); | |
308 if ((rcfile = aud_rcfile_open(filename)) == NULL) { | |
309 g_free(filename); | |
310 return NULL; | |
311 } | |
312 } | |
313 | |
314 // END mod | |
315 | |
316 g_free(filename); | |
317 | |
318 for (;;) { | |
319 gchar section[21]; | |
320 | |
321 g_snprintf(section, sizeof(section), "Preset%d", p++); | |
322 if (aud_rcfile_read_string(rcfile, "Presets", section, &name)) { | |
323 preset = g_new0(EqualizerPreset, 1); | |
324 preset->name = name; | |
325 aud_rcfile_read_float(rcfile, name, "Preamp", &preset->preamp); | |
326 for (i = 0; i < 10; i++) { | |
327 gchar band[7]; | |
328 g_snprintf(band, sizeof(band), "Band%d", i); | |
329 aud_rcfile_read_float(rcfile, name, band, &preset->bands[i]); | |
330 } | |
331 list = g_list_prepend(list, preset); | |
332 } | |
333 else | |
334 break; | |
335 } | |
336 list = g_list_reverse(list); | |
337 aud_rcfile_free(rcfile); | |
338 return list; | |
339 #endif | |
340 } | |
341 | |
342 gint | |
343 equalizerwin_volume_frame_cb(gint pos) | |
344 { | |
345 if (equalizerwin_volume) { | |
346 gint x; | |
347 if (pos < 32) | |
348 x = 1; | |
349 else if (pos < 63) | |
350 x = 4; | |
351 else | |
352 x = 7; | |
353 | |
354 UI_SKINNED_HORIZONTAL_SLIDER(equalizerwin_volume)->knob_nx = x; | |
355 UI_SKINNED_HORIZONTAL_SLIDER(equalizerwin_volume)->knob_px = x; | |
356 } | |
357 return 1; | |
358 } | |
359 | |
360 static void | |
361 equalizerwin_volume_motion_cb(GtkWidget *widget, gint pos) | |
362 { | |
363 gint v = (gint) rint(pos * 100 / 94.0); | |
364 mainwin_adjust_volume_motion(v); | |
365 mainwin_set_volume_slider(v); | |
366 } | |
367 | |
368 static void | |
369 equalizerwin_volume_release_cb(GtkWidget *widget, gint pos) | |
370 { | |
371 mainwin_adjust_volume_release(); | |
372 } | |
373 | |
374 static gint | |
375 equalizerwin_balance_frame_cb(gint pos) | |
376 { | |
377 if (equalizerwin_balance) { | |
378 gint x; | |
379 if (pos < 13) | |
380 x = 11; | |
381 else if (pos < 26) | |
382 x = 14; | |
383 else | |
384 x = 17; | |
385 | |
386 UI_SKINNED_HORIZONTAL_SLIDER(equalizerwin_balance)->knob_nx = x; | |
387 UI_SKINNED_HORIZONTAL_SLIDER(equalizerwin_balance)->knob_px = x; | |
388 } | |
389 | |
390 return 1; | |
391 } | |
392 | |
393 static void | |
394 equalizerwin_balance_motion_cb(GtkWidget *widget, gint pos) | |
395 { | |
396 gint b; | |
397 pos = MIN(pos, 38); /* The skin uses a even number of pixels | |
398 for the balance-slider *sigh* */ | |
399 b = (gint) rint((pos - 19) * 100 / 19.0); | |
400 mainwin_adjust_balance_motion(b); | |
401 mainwin_set_balance_slider(b); | |
402 } | |
403 | |
404 static void | |
405 equalizerwin_balance_release_cb(GtkWidget *widget, gint pos) | |
406 { | |
407 mainwin_adjust_balance_release(); | |
408 } | |
409 | |
410 void | |
411 equalizerwin_set_balance_slider(gint percent) | |
412 { | |
413 ui_skinned_horizontal_slider_set_position(equalizerwin_balance, | |
414 (gint) rint((percent * 19 / 100.0) + 19)); | |
415 } | |
416 | |
417 void | |
418 equalizerwin_set_volume_slider(gint percent) | |
419 { | |
420 ui_skinned_horizontal_slider_set_position(equalizerwin_volume, | |
421 (gint) rint(percent * 94 / 100.0)); | |
422 } | |
423 | |
424 static void | |
425 equalizerwin_create_widgets(void) | |
426 { | |
427 gint i; | |
428 | |
429 equalizerwin_on = ui_skinned_button_new(); | |
430 ui_skinned_toggle_button_setup(equalizerwin_on, SKINNED_WINDOW(equalizerwin)->fixed, | |
431 14, 18, 25, 12, 10, 119, 128, 119, 69, 119, 187, 119, SKIN_EQMAIN); | |
432 g_signal_connect(equalizerwin_on, "clicked", equalizerwin_on_pushed, NULL); | |
2668
a1431a900f28
introduce ui_skinned_button_set_inside
Tomasz Mon <desowin@gmail.com>
parents:
2641
diff
changeset
|
433 ui_skinned_button_set_inside(equalizerwin_on, aud_cfg->equalizer_active); |
2606 | 434 |
435 equalizerwin_auto = ui_skinned_button_new(); | |
436 ui_skinned_toggle_button_setup(equalizerwin_auto, SKINNED_WINDOW(equalizerwin)->fixed, | |
437 39, 18, 33, 12, 35, 119, 153, 119, 94, 119, 212, 119, SKIN_EQMAIN); | |
438 g_signal_connect(equalizerwin_auto, "clicked", equalizerwin_auto_pushed, NULL); | |
2668
a1431a900f28
introduce ui_skinned_button_set_inside
Tomasz Mon <desowin@gmail.com>
parents:
2641
diff
changeset
|
439 ui_skinned_button_set_inside(equalizerwin_auto, aud_cfg->equalizer_autoload); |
2606 | 440 |
441 equalizerwin_presets = ui_skinned_button_new(); | |
442 ui_skinned_push_button_setup(equalizerwin_presets, SKINNED_WINDOW(equalizerwin)->fixed, | |
443 217, 18, 44, 12, 224, 164, 224, 176, SKIN_EQMAIN); | |
444 g_signal_connect(equalizerwin_presets, "clicked", equalizerwin_presets_pushed, NULL ); | |
445 | |
446 equalizerwin_close = ui_skinned_button_new(); | |
447 ui_skinned_push_button_setup(equalizerwin_close, SKINNED_WINDOW(equalizerwin)->fixed, | |
448 264, 3, 9, 9, 0, 116, 0, 125, SKIN_EQMAIN); | |
449 g_signal_connect(equalizerwin_close, "clicked", equalizerwin_close_cb, NULL ); | |
450 | |
451 equalizerwin_shade = ui_skinned_button_new(); | |
452 ui_skinned_push_button_setup(equalizerwin_shade, SKINNED_WINDOW(equalizerwin)->fixed, | |
453 254, 3, 9, 9, 254, 137, 1, 38, SKIN_EQMAIN); | |
454 ui_skinned_button_set_skin_index2(equalizerwin_shade, SKIN_EQ_EX); | |
455 g_signal_connect(equalizerwin_shade, "clicked", equalizerwin_shade_toggle, NULL ); | |
456 | |
457 equalizerwin_graph = ui_skinned_equalizer_graph_new(SKINNED_WINDOW(equalizerwin)->fixed, 86, 17); | |
458 | |
459 equalizerwin_preamp = ui_skinned_equalizer_slider_new(SKINNED_WINDOW(equalizerwin)->fixed, 21, 38); | |
460 ui_skinned_equalizer_slider_set_position(equalizerwin_preamp, aud_cfg->equalizer_preamp); | |
461 | |
462 for (i = 0; i < 10; i++) { | |
463 equalizerwin_bands[i] = | |
464 ui_skinned_equalizer_slider_new(SKINNED_WINDOW(equalizerwin)->fixed, 78 + (i * 18), 38); | |
465 ui_skinned_equalizer_slider_set_position(equalizerwin_bands[i], aud_cfg->equalizer_bands[i]); | |
466 } | |
467 | |
468 equalizerwin_volume = | |
469 ui_skinned_horizontal_slider_new(SKINNED_WINDOW(equalizerwin)->fixed, | |
470 61, 4, 97, 8, 1, 30, 1, 30, 3, 7, 4, 61, 0, 94, | |
471 equalizerwin_volume_frame_cb, SKIN_EQ_EX); | |
472 g_signal_connect(equalizerwin_volume, "motion", G_CALLBACK(equalizerwin_volume_motion_cb), NULL); | |
473 g_signal_connect(equalizerwin_volume, "release", G_CALLBACK(equalizerwin_volume_release_cb), NULL); | |
474 | |
475 | |
476 equalizerwin_balance = | |
477 ui_skinned_horizontal_slider_new(SKINNED_WINDOW(equalizerwin)->fixed, | |
478 164, 4, 42, 8, 11, 30, 11, 30, 3, 7, 4, 164, 0, 39, | |
479 equalizerwin_balance_frame_cb, SKIN_EQ_EX); | |
480 g_signal_connect(equalizerwin_balance, "motion", G_CALLBACK(equalizerwin_balance_motion_cb), NULL); | |
481 g_signal_connect(equalizerwin_balance, "release", G_CALLBACK(equalizerwin_balance_release_cb), NULL); | |
482 } | |
483 | |
484 | |
485 static void | |
486 equalizerwin_create_window(void) | |
487 { | |
488 GdkPixbuf *icon; | |
489 gint width, height; | |
490 | |
491 width = 275; | |
492 height = config.equalizer_shaded ? 14 : 116; | |
493 | |
494 equalizerwin = ui_skinned_window_new("equalizer"); | |
495 gtk_window_set_title(GTK_WINDOW(equalizerwin), _("Audacious Equalizer")); | |
496 gtk_window_set_role(GTK_WINDOW(equalizerwin), "equalizer"); | |
497 gtk_window_set_resizable(GTK_WINDOW(equalizerwin), FALSE); | |
498 | |
499 if (config.scaled && config.eq_scaled_linked) { | |
500 width *= config.scale_factor; | |
501 height *= config.scale_factor; | |
502 } | |
503 | |
504 gtk_widget_set_size_request(equalizerwin, width, height); | |
505 | |
506 /* this will hide only mainwin. it's annoying! yaz */ | |
507 gtk_window_set_transient_for(GTK_WINDOW(equalizerwin), | |
508 GTK_WINDOW(mainwin)); | |
509 gtk_window_set_skip_taskbar_hint(GTK_WINDOW(equalizerwin), TRUE); | |
510 | |
511 icon = gdk_pixbuf_new_from_xpm_data((const gchar **) audacious_eq_icon); | |
512 gtk_window_set_icon(GTK_WINDOW(equalizerwin), icon); | |
513 g_object_unref(icon); | |
514 | |
515 gtk_widget_set_app_paintable(equalizerwin, TRUE); | |
516 | |
517 if (config.equalizer_x != -1 && config.save_window_position) | |
518 gtk_window_move(GTK_WINDOW(equalizerwin), | |
519 config.equalizer_x, config.equalizer_y); | |
520 | |
521 g_signal_connect(equalizerwin, "delete_event", | |
522 G_CALLBACK(equalizerwin_delete), NULL); | |
523 g_signal_connect(equalizerwin, "button_press_event", | |
524 G_CALLBACK(equalizerwin_press), NULL); | |
525 g_signal_connect(equalizerwin, "key_press_event", | |
526 G_CALLBACK(equalizerwin_keypress), NULL); | |
527 } | |
528 | |
529 void | |
530 equalizerwin_create(void) | |
531 { | |
532 equalizer_presets = equalizerwin_read_presets("eq.preset"); | |
533 equalizer_auto_presets = equalizerwin_read_presets("eq.auto_preset"); | |
534 | |
535 equalizerwin_create_window(); | |
536 | |
537 gtk_window_add_accel_group( GTK_WINDOW(equalizerwin) , ui_manager_get_accel_group() ); | |
538 | |
539 equalizerwin_create_widgets(); | |
540 } | |
541 | |
542 | |
543 void | |
544 equalizerwin_show(gboolean show) | |
545 { | |
546 GtkAction *action = gtk_action_group_get_action( | |
547 toggleaction_group_others , "show equalizer" ); | |
548 gtk_toggle_action_set_active( GTK_TOGGLE_ACTION(action) , show ); | |
549 | |
550 if (show) | |
551 equalizerwin_real_show(); | |
552 else | |
553 equalizerwin_real_hide(); | |
554 } | |
555 | |
556 void | |
557 equalizerwin_real_show(void) | |
558 { | |
559 gtk_window_move(GTK_WINDOW(equalizerwin), config.equalizer_x, config.equalizer_y); | |
560 if (config.scaled && config.eq_scaled_linked) | |
561 gtk_widget_set_size_request(equalizerwin, 275 * config.scale_factor, | |
562 ((config.equalizer_shaded ? 14 : 116) * config.scale_factor)); | |
563 else | |
564 gtk_widget_set_size_request(equalizerwin, 275, | |
565 (config.equalizer_shaded ? 14 : 116)); | |
566 config.equalizer_visible = TRUE; | |
2668
a1431a900f28
introduce ui_skinned_button_set_inside
Tomasz Mon <desowin@gmail.com>
parents:
2641
diff
changeset
|
567 ui_skinned_button_set_inside(mainwin_eq, TRUE); |
2606 | 568 gtk_widget_show_all(equalizerwin); |
569 | |
570 if (!config.equalizer_shaded) { | |
571 gtk_widget_hide(equalizerwin_volume); | |
572 gtk_widget_hide(equalizerwin_balance); | |
573 } | |
574 else { | |
575 ui_skinned_set_push_button_data(equalizerwin_shade, -1, 3, -1, 47); | |
576 ui_skinned_button_set_skin_index1(equalizerwin_shade, SKIN_EQ_EX); | |
577 ui_skinned_set_push_button_data(equalizerwin_close, 11, 38, 11, 47); | |
578 ui_skinned_button_set_skin_index(equalizerwin_close, SKIN_EQ_EX); | |
579 } | |
580 | |
581 gtk_window_present(GTK_WINDOW(equalizerwin)); | |
582 } | |
583 | |
584 void | |
585 equalizerwin_real_hide(void) | |
586 { | |
587 /* | |
588 * This function should only be called from the | |
589 * main menu signal handler | |
590 */ | |
591 gtk_widget_hide(equalizerwin); | |
592 config.equalizer_visible = FALSE; | |
2668
a1431a900f28
introduce ui_skinned_button_set_inside
Tomasz Mon <desowin@gmail.com>
parents:
2641
diff
changeset
|
593 ui_skinned_button_set_inside(mainwin_eq, FALSE); |
2606 | 594 gtk_widget_queue_draw(mainwin_eq); |
595 } | |
596 | |
597 static EqualizerPreset * | |
598 equalizerwin_find_preset(GList * list, const gchar * name) | |
599 { | |
600 GList *node = list; | |
601 EqualizerPreset *preset; | |
602 | |
603 while (node) { | |
604 preset = node->data; | |
605 if (!strcasecmp(preset->name, name)) | |
606 return preset; | |
607 node = g_list_next(node); | |
608 } | |
609 return NULL; | |
610 } | |
611 | |
612 static void | |
613 equalizerwin_write_preset_file(GList * list, const gchar * basename) | |
614 { | |
615 #if 0 | |
616 gchar *filename, *tmp; | |
617 gint i, p; | |
618 EqualizerPreset *preset; | |
619 RcFile *rcfile; | |
620 GList *node; | |
621 | |
622 rcfile = aud_rcfile_new(); | |
623 p = 0; | |
624 for (node = list; node; node = g_list_next(node)) { | |
625 preset = node->data; | |
626 tmp = g_strdup_printf("Preset%d", p++); | |
627 aud_rcfile_write_string(rcfile, "Presets", tmp, preset->name); | |
628 g_free(tmp); | |
629 aud_rcfile_write_float(rcfile, preset->name, "Preamp", | |
630 preset->preamp); | |
631 for (i = 0; i < 10; i++) { | |
632 tmp = g_strdup_printf("Band%d\n", i); | |
633 aud_rcfile_write_float(rcfile, preset->name, tmp, | |
634 preset->bands[i]); | |
635 g_free(tmp); | |
636 } | |
637 } | |
638 | |
639 filename = g_build_filename(aud_paths[BMP_PATH_USER_DIR], basename, NULL); | |
640 aud_rcfile_write(rcfile, filename); | |
641 aud_rcfile_free(rcfile); | |
642 g_free(filename); | |
643 #endif | |
644 } | |
645 | |
646 static gboolean | |
647 equalizerwin_load_preset(GList * list, const gchar * name) | |
648 { | |
649 EqualizerPreset *preset; | |
650 gint i; | |
651 | |
652 if ((preset = equalizerwin_find_preset(list, name)) != NULL) { | |
653 ui_skinned_equalizer_slider_set_position(equalizerwin_preamp, preset->preamp); | |
654 for (i = 0; i < 10; i++) | |
655 ui_skinned_equalizer_slider_set_position(equalizerwin_bands[i], preset->bands[i]); | |
656 equalizerwin_eq_changed(); | |
657 return TRUE; | |
658 } | |
659 return FALSE; | |
660 } | |
661 | |
662 static GList * | |
663 equalizerwin_save_preset(GList * list, const gchar * name, | |
664 const gchar * filename) | |
665 { | |
666 gint i; | |
667 EqualizerPreset *preset; | |
668 | |
669 if (!(preset = equalizerwin_find_preset(list, name))) { | |
670 preset = g_new0(EqualizerPreset, 1); | |
671 preset->name = g_strdup(name); | |
672 list = g_list_append(list, preset); | |
673 } | |
674 | |
675 preset->preamp = ui_skinned_equalizer_slider_get_position(equalizerwin_preamp); | |
676 for (i = 0; i < 10; i++) | |
677 preset->bands[i] = ui_skinned_equalizer_slider_get_position(equalizerwin_bands[i]); | |
678 | |
679 equalizerwin_write_preset_file(list, filename); | |
680 | |
681 return list; | |
682 } | |
683 | |
684 static GList * | |
685 equalizerwin_delete_preset(GList * list, gchar * name, gchar * filename) | |
686 { | |
687 EqualizerPreset *preset; | |
688 GList *node; | |
689 | |
690 if (!(preset = equalizerwin_find_preset(list, name))) | |
691 return list; | |
692 | |
693 if (!(node = g_list_find(list, preset))) | |
694 return list; | |
695 | |
696 list = g_list_remove_link(list, node); | |
697 equalizer_preset_free(preset); | |
698 g_list_free_1(node); | |
699 | |
700 equalizerwin_write_preset_file(list, filename); | |
701 | |
702 return list; | |
703 } | |
704 | |
705 static void | |
706 equalizerwin_delete_selected_presets(GtkTreeView *view, gchar *filename) | |
707 { | |
708 gchar *text; | |
709 | |
710 GtkTreeSelection *selection = gtk_tree_view_get_selection(view); | |
711 GtkTreeModel *model = gtk_tree_view_get_model(view); | |
712 | |
713 /* | |
714 * first we are making a list of the selected rows, then we convert this | |
715 * list into a list of GtkTreeRowReferences, so that when you delete an | |
716 * item you can still access the other items | |
717 * finally we iterate through all GtkTreeRowReferences, convert them to | |
718 * GtkTreeIters and delete those one after the other | |
719 */ | |
720 | |
721 GList *list = gtk_tree_selection_get_selected_rows(selection, &model); | |
722 GList *rrefs = NULL; | |
723 GList *litr; | |
724 | |
725 for (litr = list; litr; litr = litr->next) | |
726 { | |
727 GtkTreePath *path = litr->data; | |
728 rrefs = g_list_append(rrefs, gtk_tree_row_reference_new(model, path)); | |
729 } | |
730 | |
731 for (litr = rrefs; litr; litr = litr->next) | |
732 { | |
733 GtkTreeRowReference *ref = litr->data; | |
734 GtkTreePath *path = gtk_tree_row_reference_get_path(ref); | |
735 GtkTreeIter iter; | |
736 gtk_tree_model_get_iter(model, &iter, path); | |
737 | |
738 gtk_tree_model_get(model, &iter, 0, &text, -1); | |
739 | |
740 if (!strcmp(filename, "eq.preset")) | |
741 equalizer_presets = equalizerwin_delete_preset(equalizer_presets, text, filename); | |
742 else if (!strcmp(filename, "eq.auto_preset")) | |
743 equalizer_auto_presets = equalizerwin_delete_preset(equalizer_auto_presets, text, filename); | |
744 | |
745 gtk_list_store_remove(GTK_LIST_STORE(model), &iter); | |
746 } | |
747 } | |
748 | |
749 static GList * | |
750 import_winamp_eqf(VFSFile * file) | |
751 { | |
752 #if 0 | |
753 gchar header[31]; | |
754 gchar bands[11]; | |
755 gint i = 0; | |
756 EqualizerPreset *preset = NULL; | |
757 GList *list = NULL; | |
758 GtkWidget *dialog; | |
759 gchar *realfn; | |
760 gchar preset_name[0xb4]; | |
761 | |
762 vfs_fread(header, 1, 31, file); | |
763 if (strncmp(header, "Winamp EQ library file v1.1", 27)) goto error; | |
764 | |
765 AUDDBG("The EQF header is OK\n"); | |
766 | |
767 if (vfs_fseek(file, 0x1f, SEEK_SET) == -1) goto error; | |
768 | |
769 while (vfs_fread(preset_name, 1, 0xb4, file) == 0xb4) { | |
770 AUDDBG("The preset name is '%s'\n", preset_name); | |
771 vfs_fseek(file, 0x4d, SEEK_CUR); /* unknown crap --asphyx */ | |
772 if (vfs_fread(bands, 1, 11, file) != 11) break; | |
773 | |
774 preset = equalizer_preset_new(preset_name); | |
775 /*this was divided by 63, but shouldn't it be 64? --majeru*/ | |
776 preset->preamp = EQUALIZER_MAX_GAIN - ((bands[10] * EQUALIZER_MAX_GAIN * 2) / 64.0); | |
777 | |
778 for (i = 0; i < 10; i++) | |
779 preset->bands[i] = EQUALIZER_MAX_GAIN - ((bands[i] * EQUALIZER_MAX_GAIN * 2) / 64.0); | |
780 | |
781 list = g_list_prepend(list, preset); | |
782 } | |
783 | |
784 list = g_list_reverse(list); | |
785 if (list == NULL) goto error; | |
786 | |
787 return list; | |
788 | |
789 error: | |
790 realfn = g_filename_from_uri(file->uri, NULL, NULL); | |
791 dialog = gtk_message_dialog_new (GTK_WINDOW(mainwin), | |
792 GTK_DIALOG_DESTROY_WITH_PARENT, | |
793 GTK_MESSAGE_ERROR, | |
794 GTK_BUTTONS_CLOSE, | |
795 _("Error importing Winamp EQF file '%s'"), | |
796 realfn); | |
797 gtk_dialog_run (GTK_DIALOG (dialog)); | |
798 gtk_widget_destroy (dialog); | |
799 g_free(realfn); | |
800 return NULL; | |
801 #endif | |
802 } | |
803 | |
804 static void | |
805 free_cb (gpointer data, gpointer user_data) | |
806 { | |
807 equalizer_preset_free((EqualizerPreset*)data); | |
808 } | |
809 | |
810 static void | |
811 equalizerwin_read_winamp_eqf(VFSFile * file) | |
812 { | |
813 GList *presets; | |
814 gint i; | |
815 | |
816 if ((presets = import_winamp_eqf(file)) == NULL) | |
817 return; | |
818 | |
819 /* just get the first preset --asphyx */ | |
820 EqualizerPreset *preset = (EqualizerPreset*)presets->data; | |
821 ui_skinned_equalizer_slider_set_position(equalizerwin_preamp, | |
822 preset->preamp); | |
823 | |
824 for (i = 0; i < 10; i++) | |
825 ui_skinned_equalizer_slider_set_position(equalizerwin_bands[i], | |
826 preset->bands[i]); | |
827 | |
828 g_list_foreach(presets, free_cb, NULL); | |
829 g_list_free(presets); | |
830 | |
831 equalizerwin_eq_changed(); | |
832 } | |
833 #if 0 | |
834 static void | |
835 equalizerwin_read_aud_preset(RcFile * rcfile) | |
836 { | |
837 gfloat val; | |
838 gint i; | |
839 | |
840 if (aud_rcfile_read_float(rcfile, "Equalizer preset", "Preamp", &val)) | |
841 ui_skinned_equalizer_slider_set_position(equalizerwin_preamp, val); | |
842 for (i = 0; i < 10; i++) { | |
843 gchar tmp[7]; | |
844 g_snprintf(tmp, sizeof(tmp), "Band%d", i); | |
845 if (aud_rcfile_read_float(rcfile, "Equalizer preset", tmp, &val)) | |
846 ui_skinned_equalizer_slider_set_position(equalizerwin_bands[i], val); | |
847 } | |
848 equalizerwin_eq_changed(); | |
849 } | |
850 #endif | |
851 | |
852 static void | |
853 equalizerwin_save_ok(GtkWidget * widget, gpointer data) | |
854 { | |
855 const gchar *text; | |
856 | |
857 text = gtk_entry_get_text(GTK_ENTRY(equalizerwin_save_entry)); | |
858 if (strlen(text) != 0) | |
859 equalizer_presets = | |
860 equalizerwin_save_preset(equalizer_presets, text, "eq.preset"); | |
861 gtk_widget_destroy(equalizerwin_save_window); | |
862 } | |
863 | |
864 static void | |
865 equalizerwin_save_select(GtkTreeView *treeview, GtkTreePath *path, | |
866 GtkTreeViewColumn *col, gpointer data) | |
867 { | |
868 gchar *text; | |
869 | |
870 GtkTreeSelection *selection = gtk_tree_view_get_selection(treeview); | |
871 GtkTreeModel *model; | |
872 GtkTreeIter iter; | |
873 | |
874 if (selection) | |
875 { | |
876 if (gtk_tree_selection_get_selected(selection, &model, &iter)) | |
877 { | |
878 gtk_tree_model_get(model, &iter, 0, &text, -1); | |
879 gtk_entry_set_text(GTK_ENTRY(equalizerwin_save_entry), text); | |
880 equalizerwin_save_ok(NULL, NULL); | |
881 | |
882 g_free(text); | |
883 } | |
884 } | |
885 } | |
886 | |
887 static void | |
888 equalizerwin_load_ok(GtkWidget *widget, gpointer data) | |
889 { | |
890 gchar *text; | |
891 | |
892 GtkTreeView* view = GTK_TREE_VIEW(data); | |
893 GtkTreeSelection *selection = gtk_tree_view_get_selection(view); | |
894 GtkTreeModel *model; | |
895 GtkTreeIter iter; | |
896 | |
897 if (selection) | |
898 { | |
899 if (gtk_tree_selection_get_selected(selection, &model, &iter)) | |
900 { | |
901 gtk_tree_model_get(model, &iter, 0, &text, -1); | |
902 equalizerwin_load_preset(equalizer_presets, text); | |
903 | |
904 g_free(text); | |
905 } | |
906 } | |
907 gtk_widget_destroy(equalizerwin_load_window); | |
908 } | |
909 | |
910 static void | |
911 equalizerwin_load_select(GtkTreeView *treeview, GtkTreePath *path, | |
912 GtkTreeViewColumn *col, gpointer data) | |
913 { | |
914 equalizerwin_load_ok(NULL, treeview); | |
915 } | |
916 | |
917 static void | |
918 equalizerwin_delete_delete(GtkWidget *widget, gpointer data) | |
919 { | |
920 equalizerwin_delete_selected_presets(GTK_TREE_VIEW(data), "eq.preset"); | |
921 } | |
922 | |
923 static void | |
924 equalizerwin_save_auto_ok(GtkWidget *widget, gpointer data) | |
925 { | |
926 const gchar *text; | |
927 | |
928 text = gtk_entry_get_text(GTK_ENTRY(equalizerwin_save_auto_entry)); | |
929 if (strlen(text) != 0) | |
930 equalizer_auto_presets = | |
931 equalizerwin_save_preset(equalizer_auto_presets, text, | |
932 "eq.auto_preset"); | |
933 gtk_widget_destroy(equalizerwin_save_auto_window); | |
934 } | |
935 | |
936 static void | |
937 equalizerwin_save_auto_select(GtkTreeView *treeview, GtkTreePath *path, | |
938 GtkTreeViewColumn *col, gpointer data) | |
939 { | |
940 gchar *text; | |
941 | |
942 GtkTreeSelection *selection = gtk_tree_view_get_selection(treeview); | |
943 GtkTreeModel *model; | |
944 GtkTreeIter iter; | |
945 | |
946 if (selection) | |
947 { | |
948 if (gtk_tree_selection_get_selected(selection, &model, &iter)) | |
949 { | |
950 gtk_tree_model_get(model, &iter, 0, &text, -1); | |
951 gtk_entry_set_text(GTK_ENTRY(equalizerwin_save_auto_entry), text); | |
952 equalizerwin_save_auto_ok(NULL, NULL); | |
953 | |
954 g_free(text); | |
955 } | |
956 } | |
957 } | |
958 | |
959 static void | |
960 equalizerwin_load_auto_ok(GtkWidget *widget, gpointer data) | |
961 { | |
962 gchar *text; | |
963 | |
964 GtkTreeView *view = GTK_TREE_VIEW(data); | |
965 GtkTreeSelection *selection = gtk_tree_view_get_selection(view); | |
966 GtkTreeModel *model; | |
967 GtkTreeIter iter; | |
968 | |
969 if (selection) | |
970 { | |
971 if (gtk_tree_selection_get_selected(selection, &model, &iter)) | |
972 { | |
973 gtk_tree_model_get(model, &iter, 0, &text, -1); | |
974 equalizerwin_load_preset(equalizer_auto_presets, text); | |
975 | |
976 g_free(text); | |
977 } | |
978 } | |
979 gtk_widget_destroy(equalizerwin_load_auto_window); | |
980 } | |
981 | |
982 static void | |
983 equalizerwin_load_auto_select(GtkTreeView *treeview, GtkTreePath *path, | |
984 GtkTreeViewColumn *col, gpointer data) | |
985 { | |
986 equalizerwin_load_auto_ok(NULL, treeview); | |
987 } | |
988 | |
989 static void | |
990 equalizerwin_delete_auto_delete(GtkWidget *widget, gpointer data) | |
991 { | |
992 equalizerwin_delete_selected_presets(GTK_TREE_VIEW(data), "eq.auto_preset"); | |
993 } | |
994 | |
995 | |
996 static void | |
997 load_preset_file(const gchar *filename) | |
998 { | |
999 #if 0 | |
1000 RcFile *rcfile; | |
1001 | |
1002 if ((rcfile = aud_rcfile_open(filename)) != NULL) { | |
1003 equalizerwin_read_aud_preset(rcfile); | |
1004 aud_rcfile_free(rcfile); | |
1005 } | |
1006 #endif | |
1007 } | |
1008 | |
1009 static VFSFile * | |
1010 open_vfs_file(const gchar *filename, const gchar *mode) | |
1011 { | |
1012 VFSFile *file; | |
1013 GtkWidget *dialog; | |
1014 | |
1015 if (!(file = vfs_fopen(filename, mode))) { | |
1016 dialog = gtk_message_dialog_new (GTK_WINDOW (mainwin), | |
1017 GTK_DIALOG_DESTROY_WITH_PARENT, | |
1018 GTK_MESSAGE_ERROR, | |
1019 GTK_BUTTONS_CLOSE, | |
1020 "Error loading file '%s'", | |
1021 filename); | |
1022 gtk_dialog_run (GTK_DIALOG (dialog)); | |
1023 gtk_widget_destroy (dialog); | |
1024 } | |
1025 | |
1026 return file; | |
1027 } | |
1028 | |
1029 static void | |
1030 load_winamp_file(const gchar * filename) | |
1031 { | |
1032 #if 0 | |
1033 VFSFile *file; | |
1034 | |
1035 if (!(file = open_vfs_file(filename, "rb"))) | |
1036 return; | |
1037 | |
1038 equalizerwin_read_winamp_eqf(file); | |
1039 vfs_fclose(file); | |
1040 #endif | |
1041 } | |
1042 | |
1043 static void | |
1044 import_winamp_file(const gchar * filename) | |
1045 { | |
1046 #if 0 | |
1047 VFSFile *file; | |
1048 GList *list; | |
1049 | |
1050 if (!(file = open_vfs_file(filename, "rb")) || | |
1051 !(list = import_winamp_eqf(file))) | |
1052 return; | |
1053 | |
1054 equalizer_presets = g_list_concat(equalizer_presets, list); | |
1055 equalizerwin_write_preset_file(equalizer_presets, "eq.preset"); | |
1056 | |
1057 vfs_fclose(file); | |
1058 #endif | |
1059 } | |
1060 | |
1061 static void | |
1062 save_preset_file(const gchar * filename) | |
1063 { | |
1064 #if 0 | |
1065 RcFile *rcfile; | |
1066 gint i; | |
1067 | |
1068 rcfile = aud_rcfile_new(); | |
1069 aud_rcfile_write_float(rcfile, "Equalizer preset", "Preamp", | |
1070 ui_skinned_equalizer_slider_get_position(equalizerwin_preamp)); | |
1071 | |
1072 for (i = 0; i < 10; i++) { | |
1073 gchar tmp[7]; | |
1074 g_snprintf(tmp, sizeof(tmp), "Band%d", i); | |
1075 aud_rcfile_write_float(rcfile, "Equalizer preset", tmp, | |
1076 ui_skinned_equalizer_slider_get_position(equalizerwin_bands[i])); | |
1077 } | |
1078 | |
1079 aud_rcfile_write(rcfile, filename); | |
1080 aud_rcfile_free(rcfile); | |
1081 #endif | |
1082 } | |
1083 | |
1084 static void | |
1085 save_winamp_file(const gchar * filename) | |
1086 { | |
1087 #if 0 | |
1088 VFSFile *file; | |
1089 | |
1090 gchar name[257]; | |
1091 gint i; | |
1092 guchar bands[11]; | |
1093 | |
1094 if (!(file = open_vfs_file(filename, "wb"))) | |
1095 return; | |
1096 | |
1097 vfs_fwrite("Winamp EQ library file v1.1\x1a!--", 1, 31, file); | |
1098 | |
1099 memset(name, 0, 257); | |
1100 g_strlcpy(name, "Entry1", 257); | |
1101 vfs_fwrite(name, 1, 257, file); | |
1102 | |
1103 for (i = 0; i < 10; i++) | |
1104 bands[i] = 63 - (((ui_skinned_equalizer_slider_get_position(equalizerwin_bands[i]) + EQUALIZER_MAX_GAIN) * 63) / EQUALIZER_MAX_GAIN / 2); | |
1105 bands[10] = 63 - (((ui_skinned_equalizer_slider_get_position(equalizerwin_preamp) + EQUALIZER_MAX_GAIN) * 63) / EQUALIZER_MAX_GAIN / 2); | |
1106 vfs_fwrite(bands, 1, 11, file); | |
1107 | |
1108 vfs_fclose(file); | |
1109 #endif | |
1110 } | |
1111 | |
1112 static GtkWidget * | |
1113 equalizerwin_create_list_window(GList *preset_list, | |
1114 const gchar *title, | |
1115 GtkWidget **window, | |
1116 GtkSelectionMode sel_mode, | |
1117 GtkWidget **entry, | |
1118 const gchar *action_name, | |
1119 GCallback action_func, | |
1120 GCallback select_row_func) | |
1121 { | |
1122 GtkWidget *vbox, *scrolled_window, *bbox, *view; | |
1123 GtkWidget *button_cancel, *button_action; | |
1124 GList *node; | |
1125 | |
1126 GtkListStore *store; | |
1127 GtkTreeIter iter; | |
1128 GtkTreeModel *model; | |
1129 GtkCellRenderer *renderer; | |
1130 GtkTreeSelection *selection; | |
1131 GtkTreeSortable *sortable; | |
1132 | |
1133 | |
1134 | |
1135 *window = gtk_window_new(GTK_WINDOW_TOPLEVEL); | |
1136 gtk_window_set_title(GTK_WINDOW(*window), title); | |
1137 gtk_window_set_type_hint(GTK_WINDOW(*window), GDK_WINDOW_TYPE_HINT_DIALOG); | |
1138 gtk_window_set_default_size(GTK_WINDOW(*window), 350, 300); | |
1139 gtk_window_set_position(GTK_WINDOW(*window), GTK_WIN_POS_CENTER); | |
1140 gtk_container_set_border_width(GTK_CONTAINER(*window), 10); | |
1141 gtk_window_set_transient_for(GTK_WINDOW(*window), | |
1142 GTK_WINDOW(equalizerwin)); | |
1143 g_signal_connect(*window, "destroy", | |
1144 G_CALLBACK(gtk_widget_destroyed), window); | |
1145 | |
1146 vbox = gtk_vbox_new(FALSE, 10); | |
1147 gtk_container_add(GTK_CONTAINER(*window), vbox); | |
1148 | |
1149 scrolled_window = gtk_scrolled_window_new(NULL, NULL); | |
1150 gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(scrolled_window), | |
1151 GTK_POLICY_AUTOMATIC, GTK_POLICY_ALWAYS); | |
1152 | |
1153 | |
1154 /* fill the store with the names of all available presets */ | |
1155 store = gtk_list_store_new(1, G_TYPE_STRING); | |
1156 for (node = preset_list; node; node = g_list_next(node)) | |
1157 { | |
1158 gtk_list_store_append(store, &iter); | |
1159 gtk_list_store_set(store, &iter, | |
1160 0, ((EqualizerPreset*)node->data)->name, | |
1161 -1); | |
1162 } | |
1163 model = GTK_TREE_MODEL(store); | |
1164 | |
1165 | |
1166 sortable = GTK_TREE_SORTABLE(store); | |
1167 gtk_tree_sortable_set_sort_column_id(sortable, 0, GTK_SORT_ASCENDING); | |
1168 | |
1169 | |
1170 view = gtk_tree_view_new(); | |
1171 renderer = gtk_cell_renderer_text_new(); | |
1172 gtk_tree_view_insert_column_with_attributes(GTK_TREE_VIEW(view), -1, | |
1173 _("Presets"), renderer, | |
1174 "text", 0, NULL); | |
1175 gtk_tree_view_set_model(GTK_TREE_VIEW(view), model); | |
1176 g_object_unref(model); | |
1177 | |
1178 selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(view)); | |
1179 gtk_tree_selection_set_mode(selection, sel_mode); | |
1180 | |
1181 | |
1182 | |
1183 | |
1184 gtk_container_add(GTK_CONTAINER(scrolled_window), view); | |
1185 gtk_box_pack_start(GTK_BOX(vbox), scrolled_window, TRUE, TRUE, 0); | |
1186 | |
1187 if (entry) { | |
1188 *entry = gtk_entry_new(); | |
1189 g_signal_connect(*entry, "activate", action_func, NULL); | |
1190 gtk_box_pack_start(GTK_BOX(vbox), *entry, FALSE, FALSE, 0); | |
1191 } | |
1192 | |
1193 bbox = gtk_hbutton_box_new(); | |
1194 gtk_button_box_set_layout(GTK_BUTTON_BOX(bbox), GTK_BUTTONBOX_END); | |
1195 gtk_button_box_set_spacing(GTK_BUTTON_BOX(bbox), 5); | |
1196 gtk_box_pack_start(GTK_BOX(vbox), bbox, FALSE, FALSE, 0); | |
1197 | |
1198 button_cancel = gtk_button_new_from_stock(GTK_STOCK_CANCEL); | |
1199 g_signal_connect_swapped(button_cancel, "clicked", | |
1200 G_CALLBACK(gtk_widget_destroy), | |
1201 GTK_OBJECT(*window)); | |
1202 gtk_box_pack_start(GTK_BOX(bbox), button_cancel, TRUE, TRUE, 0); | |
1203 | |
1204 button_action = gtk_button_new_from_stock(action_name); | |
1205 g_signal_connect(button_action, "clicked", G_CALLBACK(action_func), view); | |
1206 GTK_WIDGET_SET_FLAGS(button_action, GTK_CAN_DEFAULT); | |
1207 | |
1208 if (select_row_func) | |
1209 g_signal_connect(view, "row-activated", G_CALLBACK(select_row_func), NULL); | |
1210 | |
1211 | |
1212 gtk_box_pack_start(GTK_BOX(bbox), button_action, TRUE, TRUE, 0); | |
1213 | |
1214 gtk_widget_grab_default(button_action); | |
1215 | |
1216 | |
1217 gtk_widget_show_all(*window); | |
1218 | |
1219 return *window; | |
1220 } | |
1221 | |
1222 void | |
1223 equalizerwin_load_auto_preset(const gchar * filename) | |
1224 { | |
1225 #if 0 | |
1226 gchar *presetfilename, *directory; | |
1227 RcFile *rcfile; | |
1228 | |
1229 g_return_if_fail(filename != NULL); | |
1230 | |
1231 if (!aud_cfg->equalizer_autoload) | |
1232 return; | |
1233 | |
1234 presetfilename = g_strconcat(filename, ".", aud_cfg->eqpreset_extension, NULL); | |
1235 | |
1236 /* First try to find a per file preset file */ | |
1237 if (strlen(aud_cfg->eqpreset_extension) > 0 && | |
1238 (rcfile = aud_rcfile_open(presetfilename)) != NULL) { | |
1239 g_free(presetfilename); | |
1240 equalizerwin_read_aud_preset(rcfile); | |
1241 aud_rcfile_free(rcfile); | |
1242 return; | |
1243 } | |
1244 | |
1245 g_free(presetfilename); | |
1246 | |
1247 directory = g_path_get_dirname(filename); | |
1248 presetfilename = g_build_filename(directory, aud_cfg->eqpreset_default_file, | |
1249 NULL); | |
1250 g_free(directory); | |
1251 | |
1252 /* Try to find a per directory preset file */ | |
1253 if (strlen(aud_cfg->eqpreset_default_file) > 0 && | |
1254 (rcfile = aud_rcfile_open(presetfilename)) != NULL) { | |
1255 equalizerwin_read_aud_preset(rcfile); | |
1256 aud_rcfile_free(rcfile); | |
1257 } | |
1258 else if (!equalizerwin_load_preset | |
1259 (equalizer_auto_presets, g_basename(filename))) { | |
1260 /* Fall back to the oldstyle auto presets */ | |
1261 equalizerwin_load_preset(equalizer_presets, "Default"); | |
1262 } | |
1263 | |
1264 g_free(presetfilename); | |
1265 #endif | |
1266 } | |
1267 | |
1268 void | |
1269 equalizerwin_set_preamp(gfloat preamp) | |
1270 { | |
1271 ui_skinned_equalizer_slider_set_position(equalizerwin_preamp, preamp); | |
1272 equalizerwin_eq_changed(); | |
1273 } | |
1274 | |
1275 void | |
1276 equalizerwin_set_band(gint band, gfloat value) | |
1277 { | |
1278 g_return_if_fail(band >= 0 && band < 10); | |
1279 ui_skinned_equalizer_slider_set_position(equalizerwin_bands[band], value); | |
1280 } | |
1281 | |
1282 gfloat | |
1283 equalizerwin_get_preamp(void) | |
1284 { | |
1285 return ui_skinned_equalizer_slider_get_position(equalizerwin_preamp); | |
1286 } | |
1287 | |
1288 gfloat | |
1289 equalizerwin_get_band(gint band) | |
1290 { | |
1291 g_return_val_if_fail(band >= 0 && band < 10, 0.0); | |
1292 return ui_skinned_equalizer_slider_get_position(equalizerwin_bands[band]); | |
1293 } | |
1294 | |
1295 void | |
1296 action_equ_load_preset(void) | |
1297 { | |
1298 if (equalizerwin_load_window) { | |
1299 gtk_window_present(GTK_WINDOW(equalizerwin_load_window)); | |
1300 return; | |
1301 } | |
1302 | |
1303 equalizerwin_create_list_window(equalizer_presets, | |
1304 Q_("Load preset"), | |
1305 &equalizerwin_load_window, | |
1306 GTK_SELECTION_SINGLE, NULL, | |
1307 GTK_STOCK_OK, | |
1308 G_CALLBACK(equalizerwin_load_ok), | |
1309 G_CALLBACK(equalizerwin_load_select)); | |
1310 } | |
1311 | |
1312 void | |
1313 action_equ_load_auto_preset(void) | |
1314 { | |
1315 if (equalizerwin_load_auto_window) { | |
1316 gtk_window_present(GTK_WINDOW(equalizerwin_load_auto_window)); | |
1317 return; | |
1318 } | |
1319 | |
1320 equalizerwin_create_list_window(equalizer_auto_presets, | |
1321 Q_("Load auto-preset"), | |
1322 &equalizerwin_load_auto_window, | |
1323 GTK_SELECTION_SINGLE, NULL, | |
1324 GTK_STOCK_OK, | |
1325 G_CALLBACK(equalizerwin_load_auto_ok), | |
1326 G_CALLBACK(equalizerwin_load_auto_select)); | |
1327 } | |
1328 | |
1329 void | |
1330 action_equ_load_default_preset(void) | |
1331 { | |
1332 equalizerwin_load_preset(equalizer_presets, "Default"); | |
1333 } | |
1334 | |
1335 void | |
1336 action_equ_zero_preset(void) | |
1337 { | |
1338 gint i; | |
1339 | |
1340 ui_skinned_equalizer_slider_set_position(equalizerwin_preamp, 0); | |
1341 for (i = 0; i < 10; i++) | |
1342 ui_skinned_equalizer_slider_set_position(equalizerwin_bands[i], 0); | |
1343 | |
1344 equalizerwin_eq_changed(); | |
1345 } | |
1346 | |
1347 void | |
1348 action_equ_load_preset_file(void) | |
1349 { | |
1350 GtkWidget *dialog; | |
1351 gchar *file_uri; | |
1352 | |
1353 dialog = make_filebrowser(Q_("Load equalizer preset"), FALSE); | |
1354 if (gtk_dialog_run(GTK_DIALOG(dialog)) == GTK_RESPONSE_ACCEPT) | |
1355 { | |
1356 file_uri = gtk_file_chooser_get_uri(GTK_FILE_CHOOSER(dialog)); | |
1357 load_preset_file(file_uri); | |
1358 g_free(file_uri); | |
1359 } | |
1360 gtk_widget_destroy(dialog); | |
1361 } | |
1362 | |
1363 void | |
1364 action_equ_load_preset_eqf(void) | |
1365 { | |
1366 GtkWidget *dialog; | |
1367 gchar *file_uri; | |
1368 | |
1369 dialog = make_filebrowser(Q_("Load equalizer preset"), FALSE); | |
1370 if (gtk_dialog_run(GTK_DIALOG(dialog)) == GTK_RESPONSE_ACCEPT) | |
1371 { | |
1372 file_uri = gtk_file_chooser_get_uri(GTK_FILE_CHOOSER(dialog)); | |
1373 load_winamp_file(file_uri); | |
1374 g_free(file_uri); | |
1375 } | |
1376 gtk_widget_destroy(dialog); | |
1377 } | |
1378 | |
1379 void | |
1380 action_equ_import_winamp_presets(void) | |
1381 { | |
1382 GtkWidget *dialog; | |
1383 gchar *file_uri; | |
1384 | |
1385 dialog = make_filebrowser(Q_("Load equalizer preset"), FALSE); | |
1386 if (gtk_dialog_run(GTK_DIALOG(dialog)) == GTK_RESPONSE_ACCEPT) | |
1387 { | |
1388 file_uri = gtk_file_chooser_get_uri(GTK_FILE_CHOOSER(dialog)); | |
1389 import_winamp_file(file_uri); | |
1390 g_free(file_uri); | |
1391 } | |
1392 gtk_widget_destroy(dialog); | |
1393 } | |
1394 | |
1395 void | |
1396 action_equ_save_preset(void) | |
1397 { | |
1398 if (equalizerwin_save_window) { | |
1399 gtk_window_present(GTK_WINDOW(equalizerwin_save_window)); | |
1400 return; | |
1401 } | |
1402 | |
1403 equalizerwin_create_list_window(equalizer_presets, | |
1404 Q_("Save preset"), | |
1405 &equalizerwin_save_window, | |
1406 GTK_SELECTION_SINGLE, | |
1407 &equalizerwin_save_entry, | |
1408 GTK_STOCK_OK, | |
1409 G_CALLBACK(equalizerwin_save_ok), | |
1410 G_CALLBACK(equalizerwin_save_select)); | |
1411 } | |
1412 | |
1413 void | |
1414 action_equ_save_auto_preset(void) | |
1415 { | |
1416 gchar *name; | |
1417 Playlist *playlist = aud_playlist_get_active(); | |
1418 | |
1419 if (equalizerwin_save_auto_window) | |
1420 gtk_window_present(GTK_WINDOW(equalizerwin_save_auto_window)); | |
1421 else | |
1422 equalizerwin_create_list_window(equalizer_auto_presets, | |
1423 Q_("Save auto-preset"), | |
1424 &equalizerwin_save_auto_window, | |
1425 GTK_SELECTION_SINGLE, | |
1426 &equalizerwin_save_auto_entry, | |
1427 GTK_STOCK_OK, | |
1428 G_CALLBACK(equalizerwin_save_auto_ok), | |
1429 G_CALLBACK(equalizerwin_save_auto_select)); | |
1430 | |
1431 name = aud_playlist_get_filename(playlist, aud_playlist_get_position(playlist)); | |
1432 if (name) { | |
1433 gtk_entry_set_text(GTK_ENTRY(equalizerwin_save_auto_entry), | |
1434 g_basename(name)); | |
1435 g_free(name); | |
1436 } | |
1437 } | |
1438 | |
1439 void | |
1440 action_equ_save_default_preset(void) | |
1441 { | |
1442 equalizer_presets = | |
1443 equalizerwin_save_preset(equalizer_presets, Q_("Default"), "eq.preset"); | |
1444 } | |
1445 | |
1446 void | |
1447 action_equ_save_preset_file(void) | |
1448 { | |
1449 GtkWidget *dialog; | |
1450 gchar *file_uri; | |
1451 gchar *songname; | |
1452 Playlist *playlist = aud_playlist_get_active(); | |
1453 | |
1454 dialog = make_filebrowser(Q_("Save equalizer preset"), TRUE); | |
1455 if (gtk_dialog_run(GTK_DIALOG(dialog)) == GTK_RESPONSE_ACCEPT) | |
1456 { | |
1457 file_uri = gtk_file_chooser_get_uri(GTK_FILE_CHOOSER(dialog)); | |
1458 save_preset_file(file_uri); | |
1459 g_free(file_uri); | |
1460 } | |
1461 | |
1462 songname = aud_playlist_get_filename(playlist, aud_playlist_get_position(playlist)); | |
1463 if (songname) { | |
1464 gchar *eqname = g_strdup_printf("%s.%s", songname, | |
1465 aud_cfg->eqpreset_extension); | |
1466 g_free(songname); | |
1467 gtk_file_chooser_set_filename(GTK_FILE_CHOOSER(dialog), | |
1468 eqname); | |
1469 g_free(eqname); | |
1470 } | |
1471 | |
1472 gtk_widget_destroy(dialog); | |
1473 } | |
1474 | |
1475 void | |
1476 action_equ_save_preset_eqf(void) | |
1477 { | |
1478 GtkWidget *dialog; | |
1479 gchar *file_uri; | |
1480 | |
1481 dialog = make_filebrowser(Q_("Save equalizer preset"), TRUE); | |
1482 if (gtk_dialog_run(GTK_DIALOG(dialog)) == GTK_RESPONSE_ACCEPT) | |
1483 { | |
1484 file_uri = gtk_file_chooser_get_uri(GTK_FILE_CHOOSER(dialog)); | |
1485 save_winamp_file(file_uri); | |
1486 g_free(file_uri); | |
1487 } | |
1488 gtk_widget_destroy(dialog); | |
1489 } | |
1490 | |
1491 void | |
1492 action_equ_delete_preset(void) | |
1493 { | |
1494 if (equalizerwin_delete_window) { | |
1495 gtk_window_present(GTK_WINDOW(equalizerwin_delete_window)); | |
1496 return; | |
1497 } | |
1498 | |
1499 equalizerwin_create_list_window(equalizer_presets, | |
1500 Q_("Delete preset"), | |
1501 &equalizerwin_delete_window, | |
1502 GTK_SELECTION_EXTENDED, NULL, | |
1503 GTK_STOCK_DELETE, | |
1504 G_CALLBACK(equalizerwin_delete_delete), | |
1505 NULL); | |
1506 } | |
1507 | |
1508 void | |
1509 action_equ_delete_auto_preset(void) | |
1510 { | |
1511 if (equalizerwin_delete_auto_window) { | |
1512 gtk_window_present(GTK_WINDOW(equalizerwin_delete_auto_window)); | |
1513 return; | |
1514 } | |
1515 | |
1516 equalizerwin_create_list_window(equalizer_auto_presets, | |
1517 Q_("Delete auto-preset"), | |
1518 &equalizerwin_delete_auto_window, | |
1519 GTK_SELECTION_EXTENDED, NULL, | |
1520 GTK_STOCK_DELETE, | |
1521 G_CALLBACK(equalizerwin_delete_auto_delete), | |
1522 NULL); | |
1523 } | |
1524 | |
1525 void | |
1526 equalizer_activate(gboolean active) | |
1527 { | |
1528 aud_cfg->equalizer_active = active; | |
2668
a1431a900f28
introduce ui_skinned_button_set_inside
Tomasz Mon <desowin@gmail.com>
parents:
2641
diff
changeset
|
1529 ui_skinned_button_set_inside(equalizerwin_on, active); |
2606 | 1530 |
1531 equalizerwin_eq_changed(); | |
1532 } |