comparison src/audacious/main.c @ 4352:ac1f6d211223

Split BmpConfig from main.c and main.h; move around some other stuff too
author mf0102 <0102@gmx.at>
date Sun, 16 Mar 2008 22:23:59 +0100
parents 8071e599916d
children 3aeb45aeeaed
comparison
equal deleted inserted replaced
4351:fe9e9300150d 4352:ac1f6d211223
60 #endif 60 #endif
61 61
62 #include "auddrct.h" 62 #include "auddrct.h"
63 #include "build_stamp.h" 63 #include "build_stamp.h"
64 #include "dnd.h" 64 #include "dnd.h"
65 #include "effect.h"
66 #include "general.h"
67 #include "hints.h" 65 #include "hints.h"
68 #include "input.h" 66 #include "input.h"
69 #include "logger.h" 67 #include "logger.h"
70 #include "output.h" 68 #include "output.h"
71 #include "playback.h" 69 #include "playback.h"
77 #include "ui_fileinfo.h" 75 #include "ui_fileinfo.h"
78 #include "ui_main.h" 76 #include "ui_main.h"
79 #include "ui_manager.h" 77 #include "ui_manager.h"
80 #include "ui_playlist.h" 78 #include "ui_playlist.h"
81 #include "ui_preferences.h" 79 #include "ui_preferences.h"
82 #include "ui_skinned_window.h"
83 #include "ui_skinselector.h" 80 #include "ui_skinselector.h"
84 #include "util.h" 81 #include "util.h"
85 #include "visualization.h"
86 82
87 #include "libSAD.h" 83 #include "libSAD.h"
88 #include "eggsmclient.h" 84 #include "eggsmclient.h"
89 #include "eggdesktopfile.h" 85 #include "eggdesktopfile.h"
90 86
112 108
113 AudCmdLineOpt options; 109 AudCmdLineOpt options;
114 110
115 BmpConfig cfg; 111 BmpConfig cfg;
116 112
117 BmpConfig bmp_default_config = {
118 MAINWIN_DEFAULT_POS_X, /* mainwin x position */
119 MAINWIN_DEFAULT_POS_Y, /* mainwin y position */
120 EQUALIZER_DEFAULT_POS_X, /* equalizer x position */
121 EQUALIZER_DEFAULT_POS_Y, /* equalizer y position */
122 PLAYLISTWIN_DEFAULT_POS_X, /* playlistwin x position */
123 PLAYLISTWIN_DEFAULT_POS_Y, /* playlistwin y position */
124 PLAYLISTWIN_DEFAULT_WIDTH, /* playlistwin width */
125 PLAYLISTWIN_DEFAULT_HEIGHT, /* playlistwin height */
126 10, /* snap distance */
127 FALSE, /* real-time priority */
128 FALSE, FALSE, /* shuffle, repeat */
129 FALSE, /* scaling */
130 TRUE, /* autoscroll */
131 TRUE, /* analyzer peaks */
132 FALSE, /* equalizer autoload */
133 FALSE, /* easy move */
134 FALSE, /* equalizer active */
135 FALSE, /* playlistwin visible */
136 FALSE, /* equalizer visible */
137 TRUE, /* player visible */
138 FALSE, /* player shaded */
139 FALSE, /* playlistwin shaded */
140 FALSE, /* equalizer shaded */
141 FALSE, /* allow multiple instances */
142 TRUE, /* always show cb */
143 TRUE, TRUE, TRUE, /* convert '_', %20 and '\' */
144 TRUE, /* show numbers in playlist */
145 TRUE, /* snap windows */
146 TRUE, /* save window positions */
147 TRUE, /* dim titlebar */
148 FALSE, /* get playlist info on load */
149 TRUE, /* get playlist info on demand */
150 TRUE, /* equalizer scale linked */
151 FALSE, /* sort jump to file */
152 FALSE, /* use effect plugins */
153 FALSE, /* always on top */
154 FALSE, /* sticky */
155 FALSE, /* no playlist advance */
156 FALSE, /* stop after current song */
157 TRUE, /* refresh file list */
158 TRUE, /* UNUSED (smooth title scrolling) */
159 TRUE, /* use playlist metadata */
160 TRUE, /* deprecated */
161 TRUE, /* warn about windows visibility */
162 FALSE, /* use \ as directory delimiter */
163 FALSE, /* random skin on play */
164 FALSE, /* use fontsets */
165 TRUE, /* use bitmap font for mainwin */
166 TRUE, /* use custom cursors */
167 TRUE, /* close dialog on open */
168 TRUE, /* close dialog on add */
169 0.0, /* equalizer preamp */
170 {0.0, 0.0, 0.0, 0.0, 0.0, /* equalizer bands */
171 0.0, 0.0, 0.0, 0.0, 0.0},
172 1.2, /* GUI scale factor, hardcoded for testing purposes --majeru */
173 NULL, /* skin */
174 NULL, /* output plugin */
175 NULL, /* file selector path */
176 NULL, /* playlist path */
177 NULL, /* playlist font */
178 NULL, /* mainwin font */
179 NULL, /* disabled input plugins */
180 NULL, /* enabled general plugins */
181 NULL, /* enabled visualization plugins */
182 NULL, /* enabled effect plugins */
183 NULL, /* enabled discovery plugins */
184 NULL, /* equalizer preset default file */
185 NULL, /* equalizer preset extension */
186 NULL, /* URL history */
187 0, /* timer mode */
188 VIS_ANALYZER, /* visualizer type */
189 ANALYZER_NORMAL, /* analyzer mode */
190 ANALYZER_BARS, /* analyzer type */
191 SCOPE_DOT, /* scope mode */
192 VOICEPRINT_NORMAL, /* voiceprint mode */
193 VU_SMOOTH, /* VU mode */
194 REFRESH_FULL, /* visualizer refresh rate */
195 FALLOFF_FAST, /* analyzer fall off rate */
196 FALLOFF_SLOW, /* peaks fall off rate */
197 0, /* playlist position */
198 2, /* pause between songs time */
199 FALSE, /* pause between songs */
200 FALSE, /* show window decorations */
201 8, /* mouse wheel scroll step */
202 FALSE, /* playlist transparent */
203 2, /* 3rd preset (ARTIST - ALBUM - TITLE) */
204 NULL, /* title format */
205 FALSE, /* software volume control enabled */
206 TRUE, /* UNUSED (XMMS compatibility mode) */
207 TRUE, /* extra eq filtering */
208 3, /* scroll pl by */
209 FALSE, /* resume playback on startup */
210 -1, /* resume playback on startup time */
211 TRUE, /* show seperators in pl */
212 NULL, /* chardet_detector */
213 NULL, /* chardet_fallback */
214 500, /* audio buffer size */
215 TRUE, /* whether or not to postpone format detection on initial add */
216 TRUE, /* show filepopup for tuple */
217 NULL, /* words identifying covers */
218 NULL, /* words that might not show up in cover names */
219 FALSE,
220 0,
221 NULL, /* default session uri base (non-NULL = custom session uri base) */
222 150, /* short side length of the picture in the filepopup */
223 20, /* delay until the filepopup comes up */
224 FALSE, /* use filename.jpg for coverart */
225 FALSE, /* use XMMS-style file selection */
226 TRUE, /* use extension probing */
227 255, 255, 255, /* colorize r, g, b */
228 FALSE, /* internal: whether or not to terminate */
229 TRUE, /* whether show progress bar in filepopup or not */
230 TRUE, /* close jtf dialog on jump */
231 TRUE, /* use back and forth scroll */
232 FALSE, /* use software volume control */
233 .warn_about_broken_gtk_engines = TRUE, /* warn about broken gtk themes */
234 FALSE, /* disable inline themes */
235 TRUE, /* remember jtf text entry */
236 16, /* output bit depth */
237 TRUE, /* enable replay gain */
238 TRUE, /* enable clipping prevention */
239 TRUE, /* track mode */
240 FALSE, /* album mode */
241 FALSE, /* enable adaptive scaler */
242 0.0, /* preamp */
243 -9.0, /* default gain */
244 #ifdef USE_SRC
245 FALSE, /* enable resampling */
246 48000, /* samplerate */
247 SRC_SINC_BEST_QUALITY, /* default interpolation method */
248 #endif
249 FALSE, /* bypass dsp */
250 };
251
252 typedef struct bmp_cfg_boolent_t {
253 char const *be_vname;
254 gboolean *be_vloc;
255 gboolean be_wrt;
256 } bmp_cfg_boolent;
257
258 typedef struct bmp_cfg_nument_t {
259 char const *ie_vname;
260 gint *ie_vloc;
261 gboolean ie_wrt;
262 } bmp_cfg_nument;
263
264 typedef struct bmp_cfg_strent_t {
265 char const *se_vname;
266 char **se_vloc;
267 gboolean se_wrt;
268 } bmp_cfg_strent;
269
270 const gchar *bmp_titlestring_presets[] = { 113 const gchar *bmp_titlestring_presets[] = {
271 "${title}", 114 "${title}",
272 "${?artist:${artist} - }${title}", 115 "${?artist:${artist} - }${title}",
273 "${?artist:${artist} - }${?album:${album} - }${title}", 116 "${?artist:${artist} - }${?album:${album} - }${title}",
274 "${?artist:${artist} - }${?album:${album} - }${?track-number:${track-number}. }${title}", 117 "${?artist:${artist} - }${?album:${album} - }${?track-number:${track-number}. }${title}",
293 N_("Universal") 136 N_("Universal")
294 #endif 137 #endif
295 }; 138 };
296 139
297 const guint n_chardet_detector_presets = G_N_ELEMENTS(chardet_detector_presets); 140 const guint n_chardet_detector_presets = G_N_ELEMENTS(chardet_detector_presets);
298
299 static bmp_cfg_boolent bmp_boolents[] = {
300 {"allow_multiple_instances", &cfg.allow_multiple_instances, TRUE},
301 {"use_realtime", &cfg.use_realtime, TRUE},
302 {"always_show_cb", &cfg.always_show_cb, TRUE},
303 {"convert_underscore", &cfg.convert_underscore, TRUE},
304 {"convert_twenty", &cfg.convert_twenty, TRUE},
305 {"convert_slash", &cfg.convert_slash, TRUE },
306 {"show_numbers_in_pl", &cfg.show_numbers_in_pl, TRUE},
307 {"show_separator_in_pl", &cfg.show_separator_in_pl, TRUE},
308 {"snap_windows", &cfg.snap_windows, TRUE},
309 {"save_window_positions", &cfg.save_window_position, TRUE},
310 {"dim_titlebar", &cfg.dim_titlebar, TRUE},
311 {"get_info_on_load", &cfg.get_info_on_load, TRUE},
312 {"get_info_on_demand", &cfg.get_info_on_demand, TRUE},
313 {"eq_scaled_linked", &cfg.eq_scaled_linked, TRUE},
314 {"no_playlist_advance", &cfg.no_playlist_advance, TRUE},
315 {"refresh_file_list", &cfg.refresh_file_list, TRUE},
316 {"sort_jump_to_file", &cfg.sort_jump_to_file, TRUE},
317 {"use_pl_metadata", &cfg.use_pl_metadata, TRUE},
318 {"warn_about_win_visibility", &cfg.warn_about_win_visibility, TRUE},
319 {"use_backslash_as_dir_delimiter", &cfg.use_backslash_as_dir_delimiter, TRUE},
320 {"player_shaded", &cfg.player_shaded, TRUE},
321 {"player_visible", &cfg.player_visible, TRUE},
322 {"shuffle", &cfg.shuffle, TRUE},
323 {"repeat", &cfg.repeat, TRUE},
324 {"scaled", &cfg.scaled, TRUE}, /* toggles custom scale */
325 {"autoscroll_songname", &cfg.autoscroll, TRUE},
326 {"stop_after_current_song", &cfg.stopaftersong, TRUE},
327 {"playlist_shaded", &cfg.playlist_shaded, TRUE},
328 {"playlist_visible", &cfg.playlist_visible, TRUE},
329 {"use_fontsets", &cfg.use_fontsets, TRUE},
330 {"mainwin_use_bitmapfont", &cfg.mainwin_use_bitmapfont, TRUE},
331 {"equalizer_visible", &cfg.equalizer_visible, TRUE},
332 {"equalizer_active", &cfg.equalizer_active, TRUE},
333 {"equalizer_shaded", &cfg.equalizer_shaded, TRUE},
334 {"equalizer_autoload", &cfg.equalizer_autoload, TRUE},
335 {"easy_move", &cfg.easy_move, TRUE},
336 {"use_eplugins", &cfg.use_eplugins, TRUE},
337 {"always_on_top", &cfg.always_on_top, TRUE},
338 {"sticky", &cfg.sticky, TRUE},
339 {"random_skin_on_play", &cfg.random_skin_on_play, TRUE},
340 {"pause_between_songs", &cfg.pause_between_songs, TRUE},
341 {"show_wm_decorations", &cfg.show_wm_decorations, TRUE},
342 {"eq_extra_filtering", &cfg.eq_extra_filtering, TRUE},
343 {"analyzer_peaks", &cfg.analyzer_peaks, TRUE},
344 {"custom_cursors", &cfg.custom_cursors, TRUE},
345 {"close_dialog_open", &cfg.close_dialog_open, TRUE},
346 {"close_dialog_add", &cfg.close_dialog_add, TRUE},
347 {"resume_playback_on_startup", &cfg.resume_playback_on_startup, TRUE},
348 {"playlist_detect", &cfg.playlist_detect, TRUE},
349 {"show_filepopup_for_tuple", &cfg.show_filepopup_for_tuple, TRUE},
350 {"recurse_for_cover", &cfg.recurse_for_cover, TRUE},
351 {"use_file_cover", &cfg.use_file_cover, TRUE},
352 {"use_xmms_style_fileselector", &cfg.use_xmms_style_fileselector, TRUE},
353 {"use_extension_probing", &cfg.use_extension_probing, TRUE},
354 {"filepopup_showprogressbar", &cfg.filepopup_showprogressbar, TRUE},
355 {"close_jtf_dialog", &cfg.close_jtf_dialog, TRUE},
356 {"twoway_scroll", &cfg.twoway_scroll, TRUE},
357 {"software_volume_control", &cfg.software_volume_control, TRUE},
358 {"warn_about_broken_gtk_engines", &cfg.warn_about_broken_gtk_engines, TRUE},
359 {"disable_inline_gtk", &cfg.disable_inline_gtk, TRUE},
360 {"remember_jtf_entry", &cfg.remember_jtf_entry, TRUE},
361 {"enable_replay_gain", &cfg.enable_replay_gain, TRUE},
362 {"enable_clipping_prevention", &cfg.enable_clipping_prevention, TRUE},
363 {"replay_gain_track", &cfg.replay_gain_track, TRUE},
364 {"replay_gain_album", &cfg.replay_gain_album, TRUE},
365 {"enable_adaptive_scaler", &cfg.enable_adaptive_scaler, TRUE},
366 #ifdef USE_SRC
367 {"enable_src", &cfg.enable_src, TRUE},
368 #endif
369 {"bypass_dsp", &cfg.bypass_dsp, TRUE},
370 };
371
372 static gint ncfgbent = G_N_ELEMENTS(bmp_boolents);
373
374 static bmp_cfg_nument bmp_numents[] = {
375 {"player_x", &cfg.player_x, TRUE},
376 {"player_y", &cfg.player_y, TRUE},
377 {"timer_mode", &cfg.timer_mode, TRUE},
378 {"vis_type", &cfg.vis_type, TRUE},
379 {"analyzer_mode", &cfg.analyzer_mode, TRUE},
380 {"analyzer_type", &cfg.analyzer_type, TRUE},
381 {"scope_mode", &cfg.scope_mode, TRUE},
382 {"vu_mode", &cfg.vu_mode, TRUE},
383 {"voiceprint_mode", &cfg.voiceprint_mode, TRUE},
384 {"vis_refresh_rate", &cfg.vis_refresh, TRUE},
385 {"analyzer_falloff", &cfg.analyzer_falloff, TRUE},
386 {"peaks_falloff", &cfg.peaks_falloff, TRUE},
387 {"playlist_x", &cfg.playlist_x, TRUE},
388 {"playlist_y", &cfg.playlist_y, TRUE},
389 {"playlist_width", &cfg.playlist_width, TRUE},
390 {"playlist_height", &cfg.playlist_height, TRUE},
391 {"playlist_position", &cfg.playlist_position, TRUE},
392 {"equalizer_x", &cfg.equalizer_x, TRUE},
393 {"equalizer_y", &cfg.equalizer_y, TRUE},
394 {"snap_distance", &cfg.snap_distance, TRUE},
395 {"pause_between_songs_time", &cfg.pause_between_songs_time, TRUE},
396 {"mouse_wheel_change", &cfg.mouse_change, TRUE},
397 {"scroll_pl_by", &cfg.scroll_pl_by, TRUE},
398 {"titlestring_preset", &cfg.titlestring_preset, TRUE},
399 {"resume_playback_on_startup_time", &cfg.resume_playback_on_startup_time, TRUE},
400 {"output_buffer_size", &cfg.output_buffer_size, TRUE},
401 {"recurse_for_cover_depth", &cfg.recurse_for_cover_depth, TRUE},
402 {"filepopup_pixelsize", &cfg.filepopup_pixelsize, TRUE},
403 {"filepopup_delay", &cfg.filepopup_delay, TRUE},
404 {"colorize_r", &cfg.colorize_r, TRUE},
405 {"colorize_g", &cfg.colorize_g, TRUE},
406 {"colorize_b", &cfg.colorize_b, TRUE},
407 {"output_bit_depth", &cfg.output_bit_depth, TRUE},
408 #ifdef USE_SRC
409 {"src_rate", &cfg.src_rate, TRUE},
410 {"src_type", &cfg.src_type, TRUE},
411 #endif
412 };
413
414 static gint ncfgient = G_N_ELEMENTS(bmp_numents);
415
416 static bmp_cfg_strent bmp_strents[] = {
417 {"playlist_font", &cfg.playlist_font, TRUE},
418 {"mainwin_font", &cfg.mainwin_font, TRUE},
419 {"eqpreset_default_file", &cfg.eqpreset_default_file, TRUE},
420 {"eqpreset_extension", &cfg.eqpreset_extension, TRUE},
421 {"skin", &cfg.skin, FALSE},
422 {"output_plugin", &cfg.outputplugin, FALSE},
423 {"disabled_iplugins", &cfg.disabled_iplugins, TRUE},
424 {"enabled_gplugins", &cfg.enabled_gplugins, FALSE},
425 {"enabled_vplugins", &cfg.enabled_vplugins, FALSE},
426 {"enabled_eplugins", &cfg.enabled_eplugins, FALSE},
427 {"filesel_path", &cfg.filesel_path, FALSE},
428 {"playlist_path", &cfg.playlist_path, FALSE},
429 {"generic_title_format", &cfg.gentitle_format, TRUE},
430 {"chardet_detector", &cfg.chardet_detector, TRUE},
431 {"chardet_fallback", &cfg.chardet_fallback, TRUE},
432 {"cover_name_include", &cfg.cover_name_include, TRUE},
433 {"cover_name_exclude", &cfg.cover_name_exclude, TRUE},
434 {"session_uri_base", &cfg.session_uri_base, TRUE}
435 };
436
437 static gint ncfgsent = G_N_ELEMENTS(bmp_strents);
438
439 gchar *bmp_paths[BMP_PATH_COUNT] = {}; 141 gchar *bmp_paths[BMP_PATH_COUNT] = {};
440 142
441 GList *dock_window_list = NULL; 143 GList *dock_window_list = NULL;
442 144
443 /* XXX: case-sensitivity is bad for lazy nenolods. :( -nenolod */
444 static gchar *pl_candidates[] = {
445 PLUGIN_FILENAME("ALSA"),
446 PLUGIN_FILENAME("coreaudio"),
447 PLUGIN_FILENAME("OSS"),
448 PLUGIN_FILENAME("sun"),
449 PLUGIN_FILENAME("ESD"),
450 PLUGIN_FILENAME("pulse_audio"),
451 PLUGIN_FILENAME("disk_writer"),
452 NULL
453 };
454 145
455 GCond *cond_scan; 146 GCond *cond_scan;
456 GMutex *mutex_scan; 147 GMutex *mutex_scan;
457 #ifdef USE_DBUS 148 #ifdef USE_DBUS
458 MprisPlayer *mpris; 149 MprisPlayer *mpris;
502 193
503 if (titlestring_preset < n_titlestring_presets) 194 if (titlestring_preset < n_titlestring_presets)
504 return bmp_titlestring_presets[titlestring_preset]; 195 return bmp_titlestring_presets[titlestring_preset];
505 196
506 return cfg.gentitle_format; 197 return cfg.gentitle_format;
507 }
508
509 void
510 make_directory(const gchar * path, mode_t mode)
511 {
512 if (g_mkdir_with_parents(path, mode) == 0)
513 return;
514
515 g_printerr(_("Could not create directory (%s): %s\n"), path,
516 g_strerror(errno));
517 } 198 }
518 199
519 static void 200 static void
520 bmp_make_user_dir(void) 201 bmp_make_user_dir(void)
521 { 202 {
594 g_free(xdg_cache_home); 275 g_free(xdg_cache_home);
595 276
596 g_atexit(bmp_free_paths); 277 g_atexit(bmp_free_paths);
597 } 278 }
598 279
599 void
600 bmp_config_free(void)
601 {
602 gint i;
603 for (i = 0; i < ncfgsent; ++i) {
604 if ( *(bmp_strents[i].se_vloc) != NULL )
605 {
606 g_free( *(bmp_strents[i].se_vloc) );
607 *(bmp_strents[i].se_vloc) = NULL;
608 }
609 }
610 }
611
612 void
613 bmp_config_load(void)
614 {
615 ConfigDb *db;
616 gint i, length;
617
618 memcpy(&cfg, &bmp_default_config, sizeof(BmpConfig));
619
620 db = cfg_db_open();
621 for (i = 0; i < ncfgbent; ++i) {
622 cfg_db_get_bool(db, NULL,
623 bmp_boolents[i].be_vname,
624 bmp_boolents[i].be_vloc);
625 }
626
627 for (i = 0; i < ncfgient; ++i) {
628 cfg_db_get_int(db, NULL,
629 bmp_numents[i].ie_vname,
630 bmp_numents[i].ie_vloc);
631 }
632
633 for (i = 0; i < ncfgsent; ++i) {
634 cfg_db_get_string(db, NULL,
635 bmp_strents[i].se_vname,
636 bmp_strents[i].se_vloc);
637 }
638
639 /* Preset */
640 cfg_db_get_float(db, NULL, "equalizer_preamp", &cfg.equalizer_preamp);
641 for (i = 0; i < 10; i++) {
642 gchar eqtext[18];
643
644 g_snprintf(eqtext, sizeof(eqtext), "equalizer_band%d", i);
645 cfg_db_get_float(db, NULL, eqtext, &cfg.equalizer_bands[i]);
646 }
647
648 /* custom scale factor */
649 cfg_db_get_float(db, NULL, "scale_factor", &cfg.scale_factor);
650
651 /* History */
652 if (cfg_db_get_int(db, NULL, "url_history_length", &length)) {
653 for (i = 1; i <= length; i++) {
654 gchar str[19], *tmp;
655
656 g_snprintf(str, sizeof(str), "url_history%d", i);
657 if (cfg_db_get_string(db, NULL, str, &tmp))
658 cfg.url_history = g_list_append(cfg.url_history, tmp);
659 }
660 }
661
662 /* RG settings */
663 cfg_db_get_float(db, NULL, "replay_gain_preamp", &cfg.replay_gain_preamp);
664 cfg_db_get_float(db, NULL, "default_gain", &cfg.default_gain);
665
666 cfg_db_close(db);
667
668
669 if (cfg.playlist_font && strlen(cfg.playlist_font) == 0) {
670 g_free(cfg.playlist_font);
671 cfg.playlist_font = NULL;
672 }
673
674 if (cfg.mainwin_font && strlen(cfg.mainwin_font) == 0) {
675 g_free(cfg.mainwin_font);
676 cfg.mainwin_font = NULL;
677 }
678
679 if (!cfg.playlist_font)
680 cfg.playlist_font = g_strdup(PLAYLISTWIN_DEFAULT_FONT);
681
682 if (!cfg.mainwin_font)
683 cfg.mainwin_font = g_strdup(MAINWIN_DEFAULT_FONT);
684
685 if (!cfg.gentitle_format)
686 cfg.gentitle_format = g_strdup("${?artist:${artist} - }${?album:${album} - }${title}");
687
688 if (!cfg.outputplugin) {
689 gint iter;
690 gchar *pl_path = g_build_filename(PLUGIN_DIR, plugin_dir_list[0], NULL);
691
692 for (iter = 0; pl_candidates[iter] != NULL && cfg.outputplugin == NULL; iter++)
693 {
694 cfg.outputplugin = find_file_recursively(pl_path, pl_candidates[iter]);
695 }
696
697 g_free(pl_path);
698 }
699
700 if (!cfg.eqpreset_default_file)
701 cfg.eqpreset_default_file = g_strdup(EQUALIZER_DEFAULT_DIR_PRESET);
702
703 if (!cfg.eqpreset_extension)
704 cfg.eqpreset_extension = g_strdup(EQUALIZER_DEFAULT_PRESET_EXT);
705
706 if (!cfg.chardet_detector)
707 cfg.chardet_detector = g_strdup("");
708
709 if (!cfg.chardet_fallback)
710 cfg.chardet_fallback = g_strdup("");
711
712 if (!cfg.cover_name_include)
713 cfg.cover_name_include = g_strdup("");
714
715 if (!cfg.cover_name_exclude)
716 cfg.cover_name_exclude = g_strdup("back");
717
718 if (!cfg.session_uri_base)
719 cfg.session_uri_base = g_strdup("");
720
721 /* at least one of these should be true */
722 if ((!cfg.get_info_on_demand) && (!cfg.get_info_on_load))
723 cfg.get_info_on_demand = TRUE;
724
725 /* playlist width and height can't be smaller than minimum */
726 cfg.playlist_width = MAX(cfg.playlist_width, PLAYLISTWIN_MIN_WIDTH);
727 cfg.playlist_height = MAX(cfg.playlist_height, PLAYLISTWIN_MIN_HEIGHT);
728 }
729
730 static gboolean
731 save_extra_playlist(const gchar * path, const gchar * basename,
732 gpointer savedlist)
733 {
734 GList *playlists, *iter;
735 GList **saved;
736 Playlist *playlist;
737 int found;
738 gchar *filename;
739
740 playlists = playlist_get_playlists();
741 saved = (GList **) savedlist;
742
743 found = 0;
744 for (iter = playlists; iter; iter = iter->next) {
745 playlist = (Playlist *) iter->data;
746 if (g_list_find(*saved, playlist)) continue;
747 filename = playlist_filename_get(playlist);
748 if (!filename) continue;
749 if (strcmp(filename, path) == 0) {
750 /* Save playlist */
751 playlist_save(playlist, path);
752 *saved = g_list_prepend(*saved, playlist);
753 found = 1;
754 g_free(filename);
755 break;
756 }
757 g_free(filename);
758 }
759
760 if(!found) {
761 /* Remove playlist */
762 unlink(path);
763 }
764
765 return FALSE; /* process other playlists */
766 }
767
768 static void
769 save_other_playlists(GList *saved)
770 {
771 GList *playlists, *iter;
772 Playlist *playlist;
773 gchar *pos, *ext, *basename, *filename, *newbasename;
774 int i, num, isdigits;
775
776 playlists = playlist_get_playlists();
777 for(iter = playlists; iter; iter = iter->next) {
778 playlist = (Playlist *) iter->data;
779 if (g_list_find(saved, playlist)) continue;
780 filename = playlist_filename_get(playlist);
781 if (!filename || !filename[0]
782 || g_file_test(filename, G_FILE_TEST_IS_DIR)) {
783 /* default basename */
784 #ifdef HAVE_XSPF_PLAYLIST
785 basename = g_strdup("playlist_01.xspf");
786 #else
787 basename = g_strdup("playlist_01.m3u");
788 #endif
789 } else {
790 basename = g_path_get_basename(filename);
791 }
792 g_free(filename);
793 if ((pos = strrchr(basename, '.'))) {
794 *pos = '\0';
795 }
796 #ifdef HAVE_XSPF_PLAYLIST
797 ext = ".xspf";
798 #else
799 ext = ".m3u";
800 #endif
801 num = -1;
802 if ((pos = strrchr(basename, '_'))) {
803 isdigits = 0;
804 for (i=1; pos[i]; i++) {
805 if (!g_ascii_isdigit(pos[i])) {
806 isdigits = 0;
807 break;
808 }
809 isdigits = 1;
810 }
811 if (isdigits) {
812 num = atoi(pos+1) + 1;
813 *pos = '\0';
814 }
815 }
816 /* attempt to generate unique filename */
817 filename = NULL;
818 do {
819 g_free(filename);
820 if (num < 0) {
821 /* try saving without number first */
822 newbasename = g_strdup_printf("%s%s", basename, ext);
823 num = 1;
824 } else {
825 newbasename = g_strdup_printf("%s_%02d%s", basename, num, ext);
826 num++;
827 if (num < 0) {
828 g_warning("Playlist number in filename overflowed."
829 " Not saving playlist.\n");
830 goto cleanup;
831 }
832 }
833 filename = g_build_filename(bmp_paths[BMP_PATH_PLAYLISTS_DIR],
834 newbasename, NULL);
835 g_free(newbasename);
836 } while (g_file_test(filename, G_FILE_TEST_EXISTS));
837
838 playlist_save(playlist, filename);
839 cleanup:
840 g_free(filename);
841 g_free(basename);
842 }
843 }
844
845 void
846 bmp_config_save(void)
847 {
848 GList *node;
849 gchar *str;
850 gint i, cur_pb_time;
851 ConfigDb *db;
852 GList *saved;
853 Playlist *playlist = playlist_get_active();
854
855 cfg.disabled_iplugins = input_stringify_disabled_list();
856
857
858 db = cfg_db_open();
859
860 for (i = 0; i < ncfgbent; ++i)
861 if (bmp_boolents[i].be_wrt)
862 cfg_db_set_bool(db, NULL,
863 bmp_boolents[i].be_vname,
864 *bmp_boolents[i].be_vloc);
865
866 for (i = 0; i < ncfgient; ++i)
867 if (bmp_numents[i].ie_wrt)
868 cfg_db_set_int(db, NULL,
869 bmp_numents[i].ie_vname,
870 *bmp_numents[i].ie_vloc);
871
872 /* This is a bit lame .. it'll end up being written twice,
873 * could do with being done a bit neater. -larne */
874 cfg_db_set_int(db, NULL, "playlist_position",
875 playlist_get_position(playlist));
876
877 /* FIXME: we're looking up SkinnedWindow::x &c ourselves here.
878 * this isn't exactly right. -nenolod
879 */
880 if ( SKINNED_WINDOW(playlistwin)->x != -1 &&
881 SKINNED_WINDOW(playlistwin)->y != -1 )
882 {
883 cfg_db_set_int(db, NULL, "playlist_x",
884 SKINNED_WINDOW(playlistwin)->x);
885 cfg_db_set_int(db, NULL, "playlist_y",
886 SKINNED_WINDOW(playlistwin)->y);
887 }
888
889 if ( SKINNED_WINDOW(mainwin)->x != -1 &&
890 SKINNED_WINDOW(mainwin)->y != -1 )
891 {
892 cfg_db_set_int(db, NULL, "player_x",
893 SKINNED_WINDOW(mainwin)->x);
894 cfg_db_set_int(db, NULL, "player_y",
895 SKINNED_WINDOW(mainwin)->y);
896 }
897
898 if ( SKINNED_WINDOW(equalizerwin)->x != -1 &&
899 SKINNED_WINDOW(equalizerwin)->y != -1 )
900 {
901 cfg_db_set_int(db, NULL, "equalizer_x",
902 SKINNED_WINDOW(equalizerwin)->x);
903 cfg_db_set_int(db, NULL, "equalizer_y",
904 SKINNED_WINDOW(equalizerwin)->y);
905 }
906
907 cfg_db_set_bool(db, NULL, "mainwin_use_bitmapfont",
908 cfg.mainwin_use_bitmapfont);
909
910 for (i = 0; i < ncfgsent; ++i) {
911 if (bmp_strents[i].se_wrt)
912 cfg_db_set_string(db, NULL,
913 bmp_strents[i].se_vname,
914 *bmp_strents[i].se_vloc);
915 }
916
917 cfg_db_set_float(db, NULL, "equalizer_preamp", cfg.equalizer_preamp);
918
919 /* RG settings */
920 cfg_db_set_float(db, NULL, "replay_gain_preamp", cfg.replay_gain_preamp);
921 cfg_db_set_float(db, NULL, "default_gain", cfg.default_gain);
922
923 for (i = 0; i < 10; i++) {
924 str = g_strdup_printf("equalizer_band%d", i);
925 cfg_db_set_float(db, NULL, str, cfg.equalizer_bands[i]);
926 g_free(str);
927 }
928
929 cfg_db_set_float(db, NULL, "scale_factor", cfg.scale_factor);
930
931 if (bmp_active_skin != NULL)
932 {
933 if (bmp_active_skin->path)
934 cfg_db_set_string(db, NULL, "skin", bmp_active_skin->path);
935 else
936 cfg_db_unset_key(db, NULL, "skin");
937 }
938
939 if (get_current_output_plugin())
940 cfg_db_set_string(db, NULL, "output_plugin",
941 get_current_output_plugin()->filename);
942 else
943 cfg_db_unset_key(db, NULL, "output_plugin");
944
945 str = general_stringify_enabled_list();
946 if (str) {
947 cfg_db_set_string(db, NULL, "enabled_gplugins", str);
948 g_free(str);
949 }
950 else
951 cfg_db_unset_key(db, NULL, "enabled_gplugins");
952
953 str = vis_stringify_enabled_list();
954 if (str) {
955 cfg_db_set_string(db, NULL, "enabled_vplugins", str);
956 g_free(str);
957 }
958 else
959 cfg_db_unset_key(db, NULL, "enabled_vplugins");
960
961 str = effect_stringify_enabled_list();
962 if (str) {
963 cfg_db_set_string(db, NULL, "enabled_eplugins", str);
964 g_free(str);
965 }
966 else
967 cfg_db_unset_key(db, NULL, "enabled_eplugins");
968
969 if (cfg.filesel_path)
970 cfg_db_set_string(db, NULL, "filesel_path", cfg.filesel_path);
971
972 if (cfg.playlist_path)
973 cfg_db_set_string(db, NULL, "playlist_path", cfg.playlist_path);
974
975 cfg_db_set_int(db, NULL, "url_history_length",
976 g_list_length(cfg.url_history));
977
978 for (node = cfg.url_history, i = 1; node; node = g_list_next(node), i++) {
979 str = g_strdup_printf("url_history%d", i);
980 cfg_db_set_string(db, NULL, str, node->data);
981 g_free(str);
982 }
983
984 if (playback_get_playing()) {
985 cur_pb_time = playback_get_time();
986 } else
987 cur_pb_time = -1;
988 cfg.resume_playback_on_startup_time = cur_pb_time;
989 cfg_db_set_int(db, NULL, "resume_playback_on_startup_time",
990 cfg.resume_playback_on_startup_time);
991
992 cfg_db_close(db);
993
994 playlist_save(playlist, bmp_paths[BMP_PATH_PLAYLIST_FILE]);
995
996 /* Save extra playlists that were loaded from PLAYLISTS_DIR */
997 saved = NULL;
998 saved = g_list_prepend(saved, playlist); /* don't save default again */
999 if(!dir_foreach(bmp_paths[BMP_PATH_PLAYLISTS_DIR], save_extra_playlist,
1000 &saved, NULL)) {
1001 g_warning("Could not save extra playlists\n");
1002 }
1003
1004 /* Save other playlists to PLAYLISTS_DIR */
1005 save_other_playlists(saved);
1006 g_list_free(saved);
1007 }
1008 280
1009 static void 281 static void
1010 bmp_set_default_icon(void) 282 bmp_set_default_icon(void)
1011 { 283 {
1012 GdkPixbuf *icon; 284 GdkPixbuf *icon;