Mercurial > audlegacy
comparison src/audacious/audconfig.c @ 4404:7513318719a7
Pfft, we are Audacious and this is SPARTA!
author | Matti Hamalainen <ccr@tnsp.org> |
---|---|
date | Mon, 31 Mar 2008 06:06:39 +0300 |
parents | src/audacious/bmpconfig.c@335f4ac3993a |
children | 628926f505f8 |
comparison
equal
deleted
inserted
replaced
4403:848a905816f5 | 4404:7513318719a7 |
---|---|
1 /* Audacious - Cross-platform multimedia player | |
2 * Copyright (C) 2005-2008 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 #ifdef HAVE_CONFIG_H | |
27 # include "config.h" | |
28 #endif | |
29 | |
30 #ifdef USE_SRC | |
31 # include <samplerate.h> | |
32 #endif | |
33 | |
34 #include "effect.h" | |
35 #include "general.h" | |
36 #include "playback.h" | |
37 #include "pluginenum.h" | |
38 #include "skin.h" | |
39 #include "ui_equalizer.h" | |
40 #include "ui_playlist.h" | |
41 #include "ui_skinned_window.h" | |
42 #include "ui_vis.h" | |
43 #include "util.h" | |
44 #include "visualization.h" | |
45 | |
46 #include "audconfig.h" | |
47 | |
48 BmpConfig bmp_default_config = { | |
49 MAINWIN_DEFAULT_POS_X, /* mainwin x position */ | |
50 MAINWIN_DEFAULT_POS_Y, /* mainwin y position */ | |
51 EQUALIZER_DEFAULT_POS_X, /* equalizer x position */ | |
52 EQUALIZER_DEFAULT_POS_Y, /* equalizer y position */ | |
53 PLAYLISTWIN_DEFAULT_POS_X, /* playlistwin x position */ | |
54 PLAYLISTWIN_DEFAULT_POS_Y, /* playlistwin y position */ | |
55 PLAYLISTWIN_DEFAULT_WIDTH, /* playlistwin width */ | |
56 PLAYLISTWIN_DEFAULT_HEIGHT, /* playlistwin height */ | |
57 10, /* snap distance */ | |
58 FALSE, /* real-time priority */ | |
59 FALSE, FALSE, /* shuffle, repeat */ | |
60 FALSE, /* scaling */ | |
61 TRUE, /* autoscroll */ | |
62 TRUE, /* analyzer peaks */ | |
63 FALSE, /* equalizer autoload */ | |
64 FALSE, /* easy move */ | |
65 FALSE, /* equalizer active */ | |
66 FALSE, /* playlistwin visible */ | |
67 FALSE, /* equalizer visible */ | |
68 TRUE, /* player visible */ | |
69 FALSE, /* player shaded */ | |
70 FALSE, /* playlistwin shaded */ | |
71 FALSE, /* equalizer shaded */ | |
72 FALSE, /* allow multiple instances */ | |
73 TRUE, /* always show cb */ | |
74 TRUE, TRUE, TRUE, /* convert '_', %20 and '\' */ | |
75 TRUE, /* show numbers in playlist */ | |
76 TRUE, /* snap windows */ | |
77 TRUE, /* save window positions */ | |
78 TRUE, /* dim titlebar */ | |
79 FALSE, /* get playlist info on load */ | |
80 TRUE, /* get playlist info on demand */ | |
81 TRUE, /* equalizer scale linked */ | |
82 FALSE, /* sort jump to file */ | |
83 FALSE, /* use effect plugins */ | |
84 FALSE, /* always on top */ | |
85 FALSE, /* sticky */ | |
86 FALSE, /* no playlist advance */ | |
87 FALSE, /* stop after current song */ | |
88 TRUE, /* refresh file list */ | |
89 TRUE, /* UNUSED (smooth title scrolling) */ | |
90 TRUE, /* use playlist metadata */ | |
91 TRUE, /* deprecated */ | |
92 TRUE, /* warn about windows visibility */ | |
93 FALSE, /* use \ as directory delimiter */ | |
94 FALSE, /* random skin on play */ | |
95 FALSE, /* use fontsets */ | |
96 TRUE, /* use bitmap font for mainwin */ | |
97 TRUE, /* use custom cursors */ | |
98 TRUE, /* close dialog on open */ | |
99 TRUE, /* close dialog on add */ | |
100 0.0, /* equalizer preamp */ | |
101 {0.0, 0.0, 0.0, 0.0, 0.0, /* equalizer bands */ | |
102 0.0, 0.0, 0.0, 0.0, 0.0}, | |
103 1.2, /* GUI scale factor, hardcoded for testing purposes --majeru */ | |
104 NULL, /* skin */ | |
105 NULL, /* output plugin */ | |
106 NULL, /* file selector path */ | |
107 NULL, /* playlist path */ | |
108 NULL, /* playlist font */ | |
109 NULL, /* mainwin font */ | |
110 NULL, /* disabled input plugins */ | |
111 NULL, /* enabled general plugins */ | |
112 NULL, /* enabled visualization plugins */ | |
113 NULL, /* enabled effect plugins */ | |
114 NULL, /* enabled discovery plugins */ | |
115 NULL, /* equalizer preset default file */ | |
116 NULL, /* equalizer preset extension */ | |
117 NULL, /* URL history */ | |
118 0, /* timer mode */ | |
119 VIS_ANALYZER, /* visualizer type */ | |
120 ANALYZER_NORMAL, /* analyzer mode */ | |
121 ANALYZER_BARS, /* analyzer type */ | |
122 SCOPE_DOT, /* scope mode */ | |
123 VOICEPRINT_NORMAL, /* voiceprint mode */ | |
124 VU_SMOOTH, /* VU mode */ | |
125 REFRESH_FULL, /* visualizer refresh rate */ | |
126 FALLOFF_FAST, /* analyzer fall off rate */ | |
127 FALLOFF_SLOW, /* peaks fall off rate */ | |
128 0, /* playlist position */ | |
129 2, /* pause between songs time */ | |
130 FALSE, /* pause between songs */ | |
131 FALSE, /* show window decorations */ | |
132 8, /* mouse wheel scroll step */ | |
133 FALSE, /* playlist transparent */ | |
134 2, /* 3rd preset (ARTIST - ALBUM - TITLE) */ | |
135 NULL, /* title format */ | |
136 FALSE, /* software volume control enabled */ | |
137 TRUE, /* UNUSED (XMMS compatibility mode) */ | |
138 TRUE, /* extra eq filtering */ | |
139 3, /* scroll pl by */ | |
140 FALSE, /* resume playback on startup */ | |
141 -1, /* resume playback on startup time */ | |
142 TRUE, /* show seperators in pl */ | |
143 NULL, /* chardet_detector */ | |
144 NULL, /* chardet_fallback */ | |
145 500, /* audio buffer size */ | |
146 TRUE, /* whether or not to postpone format detection on initial add */ | |
147 TRUE, /* show filepopup for tuple */ | |
148 NULL, /* words identifying covers */ | |
149 NULL, /* words that might not show up in cover names */ | |
150 FALSE, | |
151 0, | |
152 NULL, /* default session uri base (non-NULL = custom session uri base) */ | |
153 150, /* short side length of the picture in the filepopup */ | |
154 20, /* delay until the filepopup comes up */ | |
155 FALSE, /* use filename.jpg for coverart */ | |
156 FALSE, /* use XMMS-style file selection */ | |
157 TRUE, /* use extension probing */ | |
158 255, 255, 255, /* colorize r, g, b */ | |
159 FALSE, /* internal: whether or not to terminate */ | |
160 TRUE, /* whether show progress bar in filepopup or not */ | |
161 TRUE, /* close jtf dialog on jump */ | |
162 TRUE, /* use back and forth scroll */ | |
163 FALSE, /* use software volume control */ | |
164 .warn_about_broken_gtk_engines = TRUE, /* warn about broken gtk themes */ | |
165 FALSE, /* disable inline themes */ | |
166 TRUE, /* remember jtf text entry */ | |
167 16, /* output bit depth */ | |
168 TRUE, /* enable replay gain */ | |
169 TRUE, /* enable clipping prevention */ | |
170 TRUE, /* track mode */ | |
171 FALSE, /* album mode */ | |
172 FALSE, /* enable adaptive scaler */ | |
173 0.0, /* preamp */ | |
174 -9.0, /* default gain */ | |
175 0x6464, /* saved volume for both channels, 0x64=100 */ | |
176 #ifdef USE_SRC | |
177 FALSE, /* enable resampling */ | |
178 48000, /* samplerate */ | |
179 SRC_SINC_BEST_QUALITY, /* default interpolation method */ | |
180 #endif | |
181 FALSE, /* bypass dsp */ | |
182 }; | |
183 | |
184 typedef struct bmp_cfg_boolent_t { | |
185 char const *be_vname; | |
186 gboolean *be_vloc; | |
187 gboolean be_wrt; | |
188 } bmp_cfg_boolent; | |
189 | |
190 typedef struct bmp_cfg_nument_t { | |
191 char const *ie_vname; | |
192 gint *ie_vloc; | |
193 gboolean ie_wrt; | |
194 } bmp_cfg_nument; | |
195 | |
196 typedef struct bmp_cfg_strent_t { | |
197 char const *se_vname; | |
198 char **se_vloc; | |
199 gboolean se_wrt; | |
200 } bmp_cfg_strent; | |
201 | |
202 | |
203 /* XXX: case-sensitivity is bad for lazy nenolods. :( -nenolod */ | |
204 static gchar *pl_candidates[] = { | |
205 PLUGIN_FILENAME("ALSA"), | |
206 PLUGIN_FILENAME("coreaudio"), | |
207 PLUGIN_FILENAME("OSS"), | |
208 PLUGIN_FILENAME("sun"), | |
209 PLUGIN_FILENAME("ESD"), | |
210 PLUGIN_FILENAME("pulse_audio"), | |
211 PLUGIN_FILENAME("disk_writer"), | |
212 NULL | |
213 }; | |
214 | |
215 | |
216 static bmp_cfg_boolent bmp_boolents[] = { | |
217 {"allow_multiple_instances", &cfg.allow_multiple_instances, TRUE}, | |
218 {"use_realtime", &cfg.use_realtime, TRUE}, | |
219 {"always_show_cb", &cfg.always_show_cb, TRUE}, | |
220 {"convert_underscore", &cfg.convert_underscore, TRUE}, | |
221 {"convert_twenty", &cfg.convert_twenty, TRUE}, | |
222 {"convert_slash", &cfg.convert_slash, TRUE }, | |
223 {"show_numbers_in_pl", &cfg.show_numbers_in_pl, TRUE}, | |
224 {"show_separator_in_pl", &cfg.show_separator_in_pl, TRUE}, | |
225 {"snap_windows", &cfg.snap_windows, TRUE}, | |
226 {"save_window_positions", &cfg.save_window_position, TRUE}, | |
227 {"dim_titlebar", &cfg.dim_titlebar, TRUE}, | |
228 {"get_info_on_load", &cfg.get_info_on_load, TRUE}, | |
229 {"get_info_on_demand", &cfg.get_info_on_demand, TRUE}, | |
230 {"eq_scaled_linked", &cfg.eq_scaled_linked, TRUE}, | |
231 {"no_playlist_advance", &cfg.no_playlist_advance, TRUE}, | |
232 {"refresh_file_list", &cfg.refresh_file_list, TRUE}, | |
233 {"sort_jump_to_file", &cfg.sort_jump_to_file, TRUE}, | |
234 {"use_pl_metadata", &cfg.use_pl_metadata, TRUE}, | |
235 {"warn_about_win_visibility", &cfg.warn_about_win_visibility, TRUE}, | |
236 {"use_backslash_as_dir_delimiter", &cfg.use_backslash_as_dir_delimiter, TRUE}, | |
237 {"player_shaded", &cfg.player_shaded, TRUE}, | |
238 {"player_visible", &cfg.player_visible, TRUE}, | |
239 {"shuffle", &cfg.shuffle, TRUE}, | |
240 {"repeat", &cfg.repeat, TRUE}, | |
241 {"scaled", &cfg.scaled, TRUE}, /* toggles custom scale */ | |
242 {"autoscroll_songname", &cfg.autoscroll, TRUE}, | |
243 {"stop_after_current_song", &cfg.stopaftersong, TRUE}, | |
244 {"playlist_shaded", &cfg.playlist_shaded, TRUE}, | |
245 {"playlist_visible", &cfg.playlist_visible, TRUE}, | |
246 {"use_fontsets", &cfg.use_fontsets, TRUE}, | |
247 {"mainwin_use_bitmapfont", &cfg.mainwin_use_bitmapfont, TRUE}, | |
248 {"equalizer_visible", &cfg.equalizer_visible, TRUE}, | |
249 {"equalizer_active", &cfg.equalizer_active, TRUE}, | |
250 {"equalizer_shaded", &cfg.equalizer_shaded, TRUE}, | |
251 {"equalizer_autoload", &cfg.equalizer_autoload, TRUE}, | |
252 {"easy_move", &cfg.easy_move, TRUE}, | |
253 {"use_eplugins", &cfg.use_eplugins, TRUE}, | |
254 {"always_on_top", &cfg.always_on_top, TRUE}, | |
255 {"sticky", &cfg.sticky, TRUE}, | |
256 {"random_skin_on_play", &cfg.random_skin_on_play, TRUE}, | |
257 {"pause_between_songs", &cfg.pause_between_songs, TRUE}, | |
258 {"show_wm_decorations", &cfg.show_wm_decorations, TRUE}, | |
259 {"eq_extra_filtering", &cfg.eq_extra_filtering, TRUE}, | |
260 {"analyzer_peaks", &cfg.analyzer_peaks, TRUE}, | |
261 {"custom_cursors", &cfg.custom_cursors, TRUE}, | |
262 {"close_dialog_open", &cfg.close_dialog_open, TRUE}, | |
263 {"close_dialog_add", &cfg.close_dialog_add, TRUE}, | |
264 {"resume_playback_on_startup", &cfg.resume_playback_on_startup, TRUE}, | |
265 {"playlist_detect", &cfg.playlist_detect, TRUE}, | |
266 {"show_filepopup_for_tuple", &cfg.show_filepopup_for_tuple, TRUE}, | |
267 {"recurse_for_cover", &cfg.recurse_for_cover, TRUE}, | |
268 {"use_file_cover", &cfg.use_file_cover, TRUE}, | |
269 {"use_xmms_style_fileselector", &cfg.use_xmms_style_fileselector, TRUE}, | |
270 {"use_extension_probing", &cfg.use_extension_probing, TRUE}, | |
271 {"filepopup_showprogressbar", &cfg.filepopup_showprogressbar, TRUE}, | |
272 {"close_jtf_dialog", &cfg.close_jtf_dialog, TRUE}, | |
273 {"twoway_scroll", &cfg.twoway_scroll, TRUE}, | |
274 {"software_volume_control", &cfg.software_volume_control, TRUE}, | |
275 {"warn_about_broken_gtk_engines", &cfg.warn_about_broken_gtk_engines, TRUE}, | |
276 {"disable_inline_gtk", &cfg.disable_inline_gtk, TRUE}, | |
277 {"remember_jtf_entry", &cfg.remember_jtf_entry, TRUE}, | |
278 {"enable_replay_gain", &cfg.enable_replay_gain, TRUE}, | |
279 {"enable_clipping_prevention", &cfg.enable_clipping_prevention, TRUE}, | |
280 {"replay_gain_track", &cfg.replay_gain_track, TRUE}, | |
281 {"replay_gain_album", &cfg.replay_gain_album, TRUE}, | |
282 {"enable_adaptive_scaler", &cfg.enable_adaptive_scaler, TRUE}, | |
283 #ifdef USE_SRC | |
284 {"enable_src", &cfg.enable_src, TRUE}, | |
285 #endif | |
286 {"bypass_dsp", &cfg.bypass_dsp, TRUE}, | |
287 }; | |
288 | |
289 static gint ncfgbent = G_N_ELEMENTS(bmp_boolents); | |
290 | |
291 static bmp_cfg_nument bmp_numents[] = { | |
292 {"player_x", &cfg.player_x, TRUE}, | |
293 {"player_y", &cfg.player_y, TRUE}, | |
294 {"timer_mode", &cfg.timer_mode, TRUE}, | |
295 {"vis_type", &cfg.vis_type, TRUE}, | |
296 {"analyzer_mode", &cfg.analyzer_mode, TRUE}, | |
297 {"analyzer_type", &cfg.analyzer_type, TRUE}, | |
298 {"scope_mode", &cfg.scope_mode, TRUE}, | |
299 {"vu_mode", &cfg.vu_mode, TRUE}, | |
300 {"voiceprint_mode", &cfg.voiceprint_mode, TRUE}, | |
301 {"vis_refresh_rate", &cfg.vis_refresh, TRUE}, | |
302 {"analyzer_falloff", &cfg.analyzer_falloff, TRUE}, | |
303 {"peaks_falloff", &cfg.peaks_falloff, TRUE}, | |
304 {"playlist_x", &cfg.playlist_x, TRUE}, | |
305 {"playlist_y", &cfg.playlist_y, TRUE}, | |
306 {"playlist_width", &cfg.playlist_width, TRUE}, | |
307 {"playlist_height", &cfg.playlist_height, TRUE}, | |
308 {"playlist_position", &cfg.playlist_position, TRUE}, | |
309 {"equalizer_x", &cfg.equalizer_x, TRUE}, | |
310 {"equalizer_y", &cfg.equalizer_y, TRUE}, | |
311 {"snap_distance", &cfg.snap_distance, TRUE}, | |
312 {"pause_between_songs_time", &cfg.pause_between_songs_time, TRUE}, | |
313 {"mouse_wheel_change", &cfg.mouse_change, TRUE}, | |
314 {"scroll_pl_by", &cfg.scroll_pl_by, TRUE}, | |
315 {"titlestring_preset", &cfg.titlestring_preset, TRUE}, | |
316 {"resume_playback_on_startup_time", &cfg.resume_playback_on_startup_time, TRUE}, | |
317 {"output_buffer_size", &cfg.output_buffer_size, TRUE}, | |
318 {"recurse_for_cover_depth", &cfg.recurse_for_cover_depth, TRUE}, | |
319 {"filepopup_pixelsize", &cfg.filepopup_pixelsize, TRUE}, | |
320 {"filepopup_delay", &cfg.filepopup_delay, TRUE}, | |
321 {"colorize_r", &cfg.colorize_r, TRUE}, | |
322 {"colorize_g", &cfg.colorize_g, TRUE}, | |
323 {"colorize_b", &cfg.colorize_b, TRUE}, | |
324 {"output_bit_depth", &cfg.output_bit_depth, TRUE}, | |
325 {"saved_volume", &cfg.saved_volume, TRUE}, | |
326 #ifdef USE_SRC | |
327 {"src_rate", &cfg.src_rate, TRUE}, | |
328 {"src_type", &cfg.src_type, TRUE}, | |
329 #endif | |
330 }; | |
331 | |
332 static gint ncfgient = G_N_ELEMENTS(bmp_numents); | |
333 | |
334 static bmp_cfg_strent bmp_strents[] = { | |
335 {"playlist_font", &cfg.playlist_font, TRUE}, | |
336 {"mainwin_font", &cfg.mainwin_font, TRUE}, | |
337 {"eqpreset_default_file", &cfg.eqpreset_default_file, TRUE}, | |
338 {"eqpreset_extension", &cfg.eqpreset_extension, TRUE}, | |
339 {"skin", &cfg.skin, FALSE}, | |
340 {"output_plugin", &cfg.outputplugin, FALSE}, | |
341 {"disabled_iplugins", &cfg.disabled_iplugins, TRUE}, | |
342 {"enabled_gplugins", &cfg.enabled_gplugins, FALSE}, | |
343 {"enabled_vplugins", &cfg.enabled_vplugins, FALSE}, | |
344 {"enabled_eplugins", &cfg.enabled_eplugins, FALSE}, | |
345 {"filesel_path", &cfg.filesel_path, FALSE}, | |
346 {"playlist_path", &cfg.playlist_path, FALSE}, | |
347 {"generic_title_format", &cfg.gentitle_format, TRUE}, | |
348 {"chardet_detector", &cfg.chardet_detector, TRUE}, | |
349 {"chardet_fallback", &cfg.chardet_fallback, TRUE}, | |
350 {"cover_name_include", &cfg.cover_name_include, TRUE}, | |
351 {"cover_name_exclude", &cfg.cover_name_exclude, TRUE}, | |
352 {"session_uri_base", &cfg.session_uri_base, TRUE} | |
353 }; | |
354 | |
355 static gint ncfgsent = G_N_ELEMENTS(bmp_strents); | |
356 | |
357 | |
358 static gboolean | |
359 save_extra_playlist(const gchar * path, const gchar * basename, | |
360 gpointer savedlist) | |
361 { | |
362 GList *playlists, *iter; | |
363 GList **saved; | |
364 Playlist *playlist; | |
365 int found; | |
366 gchar *filename; | |
367 | |
368 playlists = playlist_get_playlists(); | |
369 saved = (GList **) savedlist; | |
370 | |
371 found = 0; | |
372 for (iter = playlists; iter; iter = iter->next) { | |
373 playlist = (Playlist *) iter->data; | |
374 if (g_list_find(*saved, playlist)) continue; | |
375 filename = playlist_filename_get(playlist); | |
376 if (!filename) continue; | |
377 if (strcmp(filename, path) == 0) { | |
378 /* Save playlist */ | |
379 playlist_save(playlist, path); | |
380 *saved = g_list_prepend(*saved, playlist); | |
381 found = 1; | |
382 g_free(filename); | |
383 break; | |
384 } | |
385 g_free(filename); | |
386 } | |
387 | |
388 if(!found) { | |
389 /* Remove playlist */ | |
390 unlink(path); | |
391 } | |
392 | |
393 return FALSE; /* process other playlists */ | |
394 } | |
395 | |
396 static void | |
397 save_other_playlists(GList *saved) | |
398 { | |
399 GList *playlists, *iter; | |
400 Playlist *playlist; | |
401 gchar *pos, *ext, *basename, *filename, *newbasename; | |
402 int i, num, isdigits; | |
403 | |
404 playlists = playlist_get_playlists(); | |
405 for(iter = playlists; iter; iter = iter->next) { | |
406 playlist = (Playlist *) iter->data; | |
407 if (g_list_find(saved, playlist)) continue; | |
408 filename = playlist_filename_get(playlist); | |
409 if (!filename || !filename[0] | |
410 || g_file_test(filename, G_FILE_TEST_IS_DIR)) { | |
411 /* default basename */ | |
412 #ifdef HAVE_XSPF_PLAYLIST | |
413 basename = g_strdup("playlist_01.xspf"); | |
414 #else | |
415 basename = g_strdup("playlist_01.m3u"); | |
416 #endif | |
417 } else { | |
418 basename = g_path_get_basename(filename); | |
419 } | |
420 g_free(filename); | |
421 if ((pos = strrchr(basename, '.'))) { | |
422 *pos = '\0'; | |
423 } | |
424 #ifdef HAVE_XSPF_PLAYLIST | |
425 ext = ".xspf"; | |
426 #else | |
427 ext = ".m3u"; | |
428 #endif | |
429 num = -1; | |
430 if ((pos = strrchr(basename, '_'))) { | |
431 isdigits = 0; | |
432 for (i=1; pos[i]; i++) { | |
433 if (!g_ascii_isdigit(pos[i])) { | |
434 isdigits = 0; | |
435 break; | |
436 } | |
437 isdigits = 1; | |
438 } | |
439 if (isdigits) { | |
440 num = atoi(pos+1) + 1; | |
441 *pos = '\0'; | |
442 } | |
443 } | |
444 /* attempt to generate unique filename */ | |
445 filename = NULL; | |
446 do { | |
447 g_free(filename); | |
448 if (num < 0) { | |
449 /* try saving without number first */ | |
450 newbasename = g_strdup_printf("%s%s", basename, ext); | |
451 num = 1; | |
452 } else { | |
453 newbasename = g_strdup_printf("%s_%02d%s", basename, num, ext); | |
454 num++; | |
455 if (num < 0) { | |
456 g_warning("Playlist number in filename overflowed." | |
457 " Not saving playlist.\n"); | |
458 goto cleanup; | |
459 } | |
460 } | |
461 filename = g_build_filename(bmp_paths[BMP_PATH_PLAYLISTS_DIR], | |
462 newbasename, NULL); | |
463 g_free(newbasename); | |
464 } while (g_file_test(filename, G_FILE_TEST_EXISTS)); | |
465 | |
466 playlist_save(playlist, filename); | |
467 cleanup: | |
468 g_free(filename); | |
469 g_free(basename); | |
470 } | |
471 } | |
472 | |
473 | |
474 void | |
475 bmp_config_free(void) | |
476 { | |
477 gint i; | |
478 for (i = 0; i < ncfgsent; ++i) { | |
479 if ( *(bmp_strents[i].se_vloc) != NULL ) | |
480 { | |
481 g_free( *(bmp_strents[i].se_vloc) ); | |
482 *(bmp_strents[i].se_vloc) = NULL; | |
483 } | |
484 } | |
485 } | |
486 | |
487 void | |
488 bmp_config_load(void) | |
489 { | |
490 ConfigDb *db; | |
491 gint i, length; | |
492 | |
493 memcpy(&cfg, &bmp_default_config, sizeof(BmpConfig)); | |
494 | |
495 db = cfg_db_open(); | |
496 for (i = 0; i < ncfgbent; ++i) { | |
497 cfg_db_get_bool(db, NULL, | |
498 bmp_boolents[i].be_vname, | |
499 bmp_boolents[i].be_vloc); | |
500 } | |
501 | |
502 for (i = 0; i < ncfgient; ++i) { | |
503 cfg_db_get_int(db, NULL, | |
504 bmp_numents[i].ie_vname, | |
505 bmp_numents[i].ie_vloc); | |
506 } | |
507 | |
508 for (i = 0; i < ncfgsent; ++i) { | |
509 cfg_db_get_string(db, NULL, | |
510 bmp_strents[i].se_vname, | |
511 bmp_strents[i].se_vloc); | |
512 } | |
513 | |
514 /* Preset */ | |
515 cfg_db_get_float(db, NULL, "equalizer_preamp", &cfg.equalizer_preamp); | |
516 for (i = 0; i < 10; i++) { | |
517 gchar eqtext[18]; | |
518 | |
519 g_snprintf(eqtext, sizeof(eqtext), "equalizer_band%d", i); | |
520 cfg_db_get_float(db, NULL, eqtext, &cfg.equalizer_bands[i]); | |
521 } | |
522 | |
523 cfg_db_get_int(db,NULL, "saved_volume", &cfg.saved_volume); | |
524 | |
525 /* custom scale factor */ | |
526 cfg_db_get_float(db, NULL, "scale_factor", &cfg.scale_factor); | |
527 | |
528 /* History */ | |
529 if (cfg_db_get_int(db, NULL, "url_history_length", &length)) { | |
530 for (i = 1; i <= length; i++) { | |
531 gchar str[19], *tmp; | |
532 | |
533 g_snprintf(str, sizeof(str), "url_history%d", i); | |
534 if (cfg_db_get_string(db, NULL, str, &tmp)) | |
535 cfg.url_history = g_list_append(cfg.url_history, tmp); | |
536 } | |
537 } | |
538 | |
539 /* RG settings */ | |
540 cfg_db_get_float(db, NULL, "replay_gain_preamp", &cfg.replay_gain_preamp); | |
541 cfg_db_get_float(db, NULL, "default_gain", &cfg.default_gain); | |
542 | |
543 cfg_db_close(db); | |
544 | |
545 | |
546 if (cfg.playlist_font && strlen(cfg.playlist_font) == 0) { | |
547 g_free(cfg.playlist_font); | |
548 cfg.playlist_font = NULL; | |
549 } | |
550 | |
551 if (cfg.mainwin_font && strlen(cfg.mainwin_font) == 0) { | |
552 g_free(cfg.mainwin_font); | |
553 cfg.mainwin_font = NULL; | |
554 } | |
555 | |
556 if (!cfg.playlist_font) | |
557 cfg.playlist_font = g_strdup(MAINWIN_DEFAULT_FONT); | |
558 | |
559 if (!cfg.mainwin_font) | |
560 cfg.mainwin_font = g_strdup(PLAYLISTWIN_DEFAULT_FONT); | |
561 | |
562 if (!cfg.gentitle_format) | |
563 cfg.gentitle_format = g_strdup("${?artist:${artist} - }${?album:${album} - }${title}"); | |
564 | |
565 if (!cfg.outputplugin) { | |
566 gint iter; | |
567 gchar *pl_path = g_build_filename(PLUGIN_DIR, plugin_dir_list[0], NULL); | |
568 | |
569 for (iter = 0; pl_candidates[iter] != NULL && cfg.outputplugin == NULL; iter++) | |
570 { | |
571 cfg.outputplugin = find_file_recursively(pl_path, pl_candidates[iter]); | |
572 } | |
573 | |
574 g_free(pl_path); | |
575 } | |
576 | |
577 if (!cfg.eqpreset_default_file) | |
578 cfg.eqpreset_default_file = g_strdup(EQUALIZER_DEFAULT_DIR_PRESET); | |
579 | |
580 if (!cfg.eqpreset_extension) | |
581 cfg.eqpreset_extension = g_strdup(EQUALIZER_DEFAULT_PRESET_EXT); | |
582 | |
583 if (!cfg.chardet_detector) | |
584 cfg.chardet_detector = g_strdup(""); | |
585 | |
586 if (!cfg.chardet_fallback) | |
587 cfg.chardet_fallback = g_strdup(""); | |
588 | |
589 if (!cfg.cover_name_include) | |
590 cfg.cover_name_include = g_strdup(""); | |
591 | |
592 if (!cfg.cover_name_exclude) | |
593 cfg.cover_name_exclude = g_strdup("back"); | |
594 | |
595 if (!cfg.session_uri_base) | |
596 cfg.session_uri_base = g_strdup(""); | |
597 | |
598 /* at least one of these should be true */ | |
599 if ((!cfg.get_info_on_demand) && (!cfg.get_info_on_load)) | |
600 cfg.get_info_on_demand = TRUE; | |
601 | |
602 /* playlist width and height can't be smaller than minimum */ | |
603 cfg.playlist_width = MAX(cfg.playlist_width, PLAYLISTWIN_MIN_WIDTH); | |
604 cfg.playlist_height = MAX(cfg.playlist_height, PLAYLISTWIN_MIN_HEIGHT); | |
605 } | |
606 | |
607 void | |
608 bmp_config_save(void) | |
609 { | |
610 GList *node; | |
611 gchar *str; | |
612 gint i, cur_pb_time, vol_l, vol_r; | |
613 ConfigDb *db; | |
614 GList *saved; | |
615 Playlist *playlist = playlist_get_active(); | |
616 | |
617 cfg.disabled_iplugins = input_stringify_disabled_list(); | |
618 | |
619 | |
620 db = cfg_db_open(); | |
621 | |
622 for (i = 0; i < ncfgbent; ++i) | |
623 if (bmp_boolents[i].be_wrt) | |
624 cfg_db_set_bool(db, NULL, | |
625 bmp_boolents[i].be_vname, | |
626 *bmp_boolents[i].be_vloc); | |
627 | |
628 for (i = 0; i < ncfgient; ++i) | |
629 if (bmp_numents[i].ie_wrt) | |
630 cfg_db_set_int(db, NULL, | |
631 bmp_numents[i].ie_vname, | |
632 *bmp_numents[i].ie_vloc); | |
633 | |
634 /* This is a bit lame .. it'll end up being written twice, | |
635 * could do with being done a bit neater. -larne */ | |
636 cfg_db_set_int(db, NULL, "playlist_position", | |
637 playlist_get_position(playlist)); | |
638 | |
639 /* FIXME: we're looking up SkinnedWindow::x &c ourselves here. | |
640 * this isn't exactly right. -nenolod | |
641 */ | |
642 if ( playlistwin && | |
643 SKINNED_WINDOW(playlistwin)->x != -1 && | |
644 SKINNED_WINDOW(playlistwin)->y != -1 ) | |
645 { | |
646 cfg_db_set_int(db, NULL, "playlist_x", | |
647 SKINNED_WINDOW(playlistwin)->x); | |
648 cfg_db_set_int(db, NULL, "playlist_y", | |
649 SKINNED_WINDOW(playlistwin)->y); | |
650 } | |
651 | |
652 if ( mainwin && | |
653 SKINNED_WINDOW(mainwin)->x != -1 && | |
654 SKINNED_WINDOW(mainwin)->y != -1 ) | |
655 { | |
656 cfg_db_set_int(db, NULL, "player_x", | |
657 SKINNED_WINDOW(mainwin)->x); | |
658 cfg_db_set_int(db, NULL, "player_y", | |
659 SKINNED_WINDOW(mainwin)->y); | |
660 } | |
661 | |
662 if ( equalizerwin && | |
663 SKINNED_WINDOW(equalizerwin)->x != -1 && | |
664 SKINNED_WINDOW(equalizerwin)->y != -1 ) | |
665 { | |
666 cfg_db_set_int(db, NULL, "equalizer_x", | |
667 SKINNED_WINDOW(equalizerwin)->x); | |
668 cfg_db_set_int(db, NULL, "equalizer_y", | |
669 SKINNED_WINDOW(equalizerwin)->y); | |
670 } | |
671 | |
672 cfg_db_set_bool(db, NULL, "mainwin_use_bitmapfont", | |
673 cfg.mainwin_use_bitmapfont); | |
674 | |
675 for (i = 0; i < ncfgsent; ++i) { | |
676 if (bmp_strents[i].se_wrt) | |
677 cfg_db_set_string(db, NULL, | |
678 bmp_strents[i].se_vname, | |
679 *bmp_strents[i].se_vloc); | |
680 } | |
681 | |
682 cfg_db_set_float(db, NULL, "equalizer_preamp", cfg.equalizer_preamp); | |
683 | |
684 /* RG settings */ | |
685 cfg_db_set_float(db, NULL, "replay_gain_preamp", cfg.replay_gain_preamp); | |
686 cfg_db_set_float(db, NULL, "default_gain", cfg.default_gain); | |
687 | |
688 for (i = 0; i < 10; i++) { | |
689 str = g_strdup_printf("equalizer_band%d", i); | |
690 cfg_db_set_float(db, NULL, str, cfg.equalizer_bands[i]); | |
691 g_free(str); | |
692 } | |
693 | |
694 cfg_db_set_float(db, NULL, "scale_factor", cfg.scale_factor); | |
695 | |
696 if (bmp_active_skin != NULL) | |
697 { | |
698 if (bmp_active_skin->path) | |
699 cfg_db_set_string(db, NULL, "skin", bmp_active_skin->path); | |
700 else | |
701 cfg_db_unset_key(db, NULL, "skin"); | |
702 } | |
703 | |
704 if (get_current_output_plugin()) | |
705 cfg_db_set_string(db, NULL, "output_plugin", | |
706 get_current_output_plugin()->filename); | |
707 else | |
708 cfg_db_unset_key(db, NULL, "output_plugin"); | |
709 | |
710 str = general_stringify_enabled_list(); | |
711 if (str) { | |
712 cfg_db_set_string(db, NULL, "enabled_gplugins", str); | |
713 g_free(str); | |
714 } | |
715 else | |
716 cfg_db_unset_key(db, NULL, "enabled_gplugins"); | |
717 | |
718 str = vis_stringify_enabled_list(); | |
719 if (str) { | |
720 cfg_db_set_string(db, NULL, "enabled_vplugins", str); | |
721 g_free(str); | |
722 } | |
723 else | |
724 cfg_db_unset_key(db, NULL, "enabled_vplugins"); | |
725 | |
726 str = effect_stringify_enabled_list(); | |
727 if (str) { | |
728 cfg_db_set_string(db, NULL, "enabled_eplugins", str); | |
729 g_free(str); | |
730 } | |
731 else | |
732 cfg_db_unset_key(db, NULL, "enabled_eplugins"); | |
733 | |
734 if (cfg.filesel_path) | |
735 cfg_db_set_string(db, NULL, "filesel_path", cfg.filesel_path); | |
736 | |
737 if (cfg.playlist_path) | |
738 cfg_db_set_string(db, NULL, "playlist_path", cfg.playlist_path); | |
739 | |
740 cfg_db_set_int(db, NULL, "url_history_length", | |
741 g_list_length(cfg.url_history)); | |
742 | |
743 input_get_volume(&vol_l,&vol_r); | |
744 cfg_db_set_int(db, NULL, "saved_volume", (vol_l<<8) | vol_r ); | |
745 | |
746 for (node = cfg.url_history, i = 1; node; node = g_list_next(node), i++) { | |
747 str = g_strdup_printf("url_history%d", i); | |
748 cfg_db_set_string(db, NULL, str, node->data); | |
749 g_free(str); | |
750 } | |
751 | |
752 if (playback_get_playing()) { | |
753 cur_pb_time = playback_get_time(); | |
754 } else | |
755 cur_pb_time = -1; | |
756 cfg.resume_playback_on_startup_time = cur_pb_time; | |
757 cfg_db_set_int(db, NULL, "resume_playback_on_startup_time", | |
758 cfg.resume_playback_on_startup_time); | |
759 | |
760 cfg_db_close(db); | |
761 | |
762 playlist_save(playlist, bmp_paths[BMP_PATH_PLAYLIST_FILE]); | |
763 | |
764 /* Save extra playlists that were loaded from PLAYLISTS_DIR */ | |
765 saved = NULL; | |
766 saved = g_list_prepend(saved, playlist); /* don't save default again */ | |
767 if(!dir_foreach(bmp_paths[BMP_PATH_PLAYLISTS_DIR], save_extra_playlist, | |
768 &saved, NULL)) { | |
769 g_warning("Could not save extra playlists\n"); | |
770 } | |
771 | |
772 /* Save other playlists to PLAYLISTS_DIR */ | |
773 save_other_playlists(saved); | |
774 g_list_free(saved); | |
775 } |