00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026 #include <glib.h>
00027 #include <libaudcore/hook.h>
00028
00029 #include "audconfig.h"
00030 #include "configdb.h"
00031 #include "playback.h"
00032
00033 AudConfig cfg = {
00034 .shuffle = FALSE,
00035 .repeat = FALSE,
00036 .equalizer_autoload = FALSE,
00037 .equalizer_active = FALSE,
00038 .show_numbers_in_pl = TRUE,
00039 .leading_zero = TRUE,
00040 .no_playlist_advance = FALSE,
00041 .advance_on_delete = FALSE,
00042 .clear_playlist = TRUE,
00043 .open_to_temporary = FALSE,
00044 .stopaftersong = FALSE,
00045 .close_dialog_open = TRUE,
00046 .equalizer_preamp = 0.0,
00047 .equalizer_bands = {0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0},
00048 .filesel_path = NULL,
00049 .playlist_path = NULL,
00050 .eqpreset_default_file = NULL,
00051 .eqpreset_extension = NULL,
00052 .url_history = NULL,
00053 .resume_playback_on_startup = FALSE,
00054 .resume_state = 0,
00055 .resume_playback_on_startup_time = 0,
00056 .chardet_detector = NULL,
00057 .chardet_fallback = NULL,
00058 .chardet_fallback_s = NULL,
00059 .output_buffer_size = 500,
00060 .show_filepopup_for_tuple = TRUE,
00061 .cover_name_include = NULL,
00062 .cover_name_exclude = NULL,
00063 .recurse_for_cover = FALSE,
00064 .recurse_for_cover_depth = 0,
00065 .filepopup_pixelsize = 150,
00066 .filepopup_delay = 5,
00067 .use_file_cover = FALSE,
00068 .filepopup_showprogressbar = TRUE,
00069 .close_jtf_dialog = TRUE,
00070 .software_volume_control = FALSE,
00071 .remember_jtf_entry = TRUE,
00072 .output_bit_depth = 16,
00073 .enable_replay_gain = TRUE,
00074 .enable_clipping_prevention = TRUE,
00075 .replay_gain_track = TRUE,
00076 .replay_gain_album = FALSE,
00077 .replay_gain_preamp = 0,
00078 .default_gain = 0,
00079 .sw_volume_left = 100, .sw_volume_right = 100,
00080
00081
00082 .no_confirm_playlist_delete = FALSE,
00083 .playlist_manager_x = 0,
00084 .playlist_manager_y = 0,
00085 .playlist_manager_width = 0,
00086 .playlist_manager_height = 0,
00087 .playlist_manager_close_on_activate = FALSE,
00088
00089
00090 .verbose = FALSE,
00091 };
00092
00093 typedef struct aud_cfg_boolent_t {
00094 char const *be_vname;
00095 gboolean *be_vloc;
00096 gboolean be_wrt;
00097 } aud_cfg_boolent;
00098
00099 typedef struct aud_cfg_nument_t {
00100 char const *ie_vname;
00101 gint *ie_vloc;
00102 gboolean ie_wrt;
00103 } aud_cfg_nument;
00104
00105 typedef struct aud_cfg_strent_t {
00106 char const *se_vname;
00107 char **se_vloc;
00108 gboolean se_wrt;
00109 } aud_cfg_strent;
00110
00111 static aud_cfg_boolent aud_boolents[] = {
00112 {"show_numbers_in_pl", &cfg.show_numbers_in_pl, TRUE},
00113 {"leading_zero", & cfg.leading_zero, TRUE},
00114 {"no_playlist_advance", &cfg.no_playlist_advance, TRUE},
00115 {"advance_on_delete", & cfg.advance_on_delete, TRUE},
00116 {"clear_playlist", & cfg.clear_playlist, TRUE},
00117 {"open_to_temporary", & cfg.open_to_temporary, TRUE},
00118 {"shuffle", &cfg.shuffle, TRUE},
00119 {"repeat", &cfg.repeat, TRUE},
00120 {"stop_after_current_song", &cfg.stopaftersong, TRUE},
00121 {"equalizer_active", &cfg.equalizer_active, TRUE},
00122 {"equalizer_autoload", &cfg.equalizer_autoload, TRUE},
00123 {"close_dialog_open", &cfg.close_dialog_open, TRUE},
00124 {"resume_playback_on_startup", &cfg.resume_playback_on_startup, TRUE},
00125 {"show_filepopup_for_tuple", &cfg.show_filepopup_for_tuple, TRUE},
00126 {"recurse_for_cover", &cfg.recurse_for_cover, TRUE},
00127 {"use_file_cover", &cfg.use_file_cover, TRUE},
00128 {"filepopup_showprogressbar", &cfg.filepopup_showprogressbar, TRUE},
00129 {"close_jtf_dialog", &cfg.close_jtf_dialog, TRUE},
00130 {"software_volume_control", &cfg.software_volume_control, TRUE},
00131 {"remember_jtf_entry", &cfg.remember_jtf_entry, TRUE},
00132 {"enable_replay_gain", &cfg.enable_replay_gain, TRUE},
00133 {"enable_clipping_prevention", &cfg.enable_clipping_prevention, TRUE},
00134 {"replay_gain_track", &cfg.replay_gain_track, TRUE},
00135 {"replay_gain_album", &cfg.replay_gain_album, TRUE},
00136 {"no_confirm_playlist_delete", &cfg.no_confirm_playlist_delete, TRUE},
00137 {"playlist_manager_close_on_activate", & cfg.playlist_manager_close_on_activate, TRUE},
00138 {"use_proxy", & cfg.use_proxy, TRUE},
00139 {"use_proxy_auth", & cfg.use_proxy_auth, TRUE},
00140 };
00141
00142 static gint ncfgbent = G_N_ELEMENTS(aud_boolents);
00143
00144 static aud_cfg_nument aud_numents[] = {
00145 {"titlestring_preset", &cfg.titlestring_preset, TRUE},
00146 {"resume_state", & cfg.resume_state, TRUE},
00147 {"resume_playback_on_startup_time", &cfg.resume_playback_on_startup_time, TRUE},
00148 {"output_buffer_size", &cfg.output_buffer_size, TRUE},
00149 {"recurse_for_cover_depth", &cfg.recurse_for_cover_depth, TRUE},
00150 {"filepopup_pixelsize", &cfg.filepopup_pixelsize, TRUE},
00151 {"filepopup_delay", &cfg.filepopup_delay, TRUE},
00152 {"output_bit_depth", &cfg.output_bit_depth, TRUE},
00153 {"sw_volume_left", & cfg.sw_volume_left, TRUE},
00154 {"sw_volume_right", & cfg.sw_volume_right, TRUE},
00155 {"playlist_manager_x", & cfg.playlist_manager_x, TRUE},
00156 {"playlist_manager_y", & cfg.playlist_manager_y, TRUE},
00157 {"playlist_manager_width", & cfg.playlist_manager_width, TRUE},
00158 {"playlist_manager_height", & cfg.playlist_manager_height, TRUE},
00159 };
00160
00161 static gint ncfgient = G_N_ELEMENTS(aud_numents);
00162
00163 static aud_cfg_strent aud_strents[] = {
00164 {"eqpreset_default_file", &cfg.eqpreset_default_file, TRUE},
00165 {"eqpreset_extension", &cfg.eqpreset_extension, TRUE},
00166 {"filesel_path", &cfg.filesel_path, FALSE},
00167 {"playlist_path", &cfg.playlist_path, FALSE},
00168 {"generic_title_format", &cfg.gentitle_format, TRUE},
00169 {"chardet_detector", &cfg.chardet_detector, TRUE},
00170 {"chardet_fallback", &cfg.chardet_fallback, TRUE},
00171 {"cover_name_include", &cfg.cover_name_include, TRUE},
00172 {"cover_name_exclude", &cfg.cover_name_exclude, TRUE},
00173 {"proxy_host", & cfg.proxy_host, TRUE},
00174 {"proxy_port", & cfg.proxy_port, TRUE},
00175 {"proxy_user", & cfg.proxy_user, TRUE},
00176 {"proxy_pass", & cfg.proxy_pass, TRUE},
00177 };
00178
00179 static gint ncfgsent = G_N_ELEMENTS(aud_strents);
00180
00181 void aud_config_chardet_update(void)
00182 {
00183 if (cfg.chardet_fallback_s != NULL)
00184 g_strfreev(cfg.chardet_fallback_s);
00185 cfg.chardet_fallback_s = g_strsplit_set(cfg.chardet_fallback, " ,:;|/", 0);
00186 }
00187
00188
00189 void
00190 aud_config_load(void)
00191 {
00192 mcs_handle_t *db;
00193 gint i, length;
00194
00195 if (! (db = cfg_db_open ()))
00196 return;
00197
00198 for (i = 0; i < ncfgbent; ++i) {
00199 cfg_db_get_bool(db, NULL,
00200 aud_boolents[i].be_vname,
00201 aud_boolents[i].be_vloc);
00202 }
00203
00204 for (i = 0; i < ncfgient; ++i) {
00205 cfg_db_get_int(db, NULL,
00206 aud_numents[i].ie_vname,
00207 aud_numents[i].ie_vloc);
00208 }
00209
00210 for (i = 0; i < ncfgsent; ++i) {
00211 cfg_db_get_string(db, NULL,
00212 aud_strents[i].se_vname,
00213 aud_strents[i].se_vloc);
00214 }
00215
00216
00217 cfg_db_get_float(db, NULL, "equalizer_preamp", &cfg.equalizer_preamp);
00218 for (i = 0; i < AUD_EQUALIZER_NBANDS; i++) {
00219 gchar eqtext[32];
00220
00221 g_snprintf(eqtext, sizeof(eqtext), "equalizer_band%d", i);
00222 cfg_db_get_float(db, NULL, eqtext, &cfg.equalizer_bands[i]);
00223 }
00224
00225
00226 if (cfg_db_get_int(db, NULL, "url_history_length", &length)) {
00227 for (i = 1; i <= length; i++) {
00228 gchar str[19], *tmp;
00229
00230 g_snprintf(str, sizeof(str), "url_history%d", i);
00231 if (cfg_db_get_string(db, NULL, str, &tmp))
00232 cfg.url_history = g_list_append(cfg.url_history, tmp);
00233 }
00234 }
00235
00236
00237 cfg_db_get_float(db, NULL, "replay_gain_preamp", &cfg.replay_gain_preamp);
00238 cfg_db_get_float(db, NULL, "default_gain", &cfg.default_gain);
00239
00240 cfg_db_close(db);
00241
00242 if (!cfg.gentitle_format)
00243 cfg.gentitle_format = g_strdup("${?artist:${artist} - }${?album:${album} - }${title}");
00244
00245 if (!cfg.chardet_detector)
00246 cfg.chardet_detector = g_strdup("");
00247
00248 if (!cfg.chardet_fallback)
00249 cfg.chardet_fallback = g_strdup("");
00250
00251 aud_config_chardet_update();
00252
00253 if (!cfg.cover_name_include)
00254 cfg.cover_name_include = g_strdup("album,folder");
00255
00256 if (!cfg.cover_name_exclude)
00257 cfg.cover_name_exclude = g_strdup("back");
00258 }
00259
00260 void
00261 aud_config_save(void)
00262 {
00263 GList *node;
00264 gchar *str;
00265 gint i;
00266 mcs_handle_t *db;
00267
00268 hook_call ("config save", NULL);
00269
00270 cfg.resume_state = playback_get_playing () ? (playback_get_paused () ? 2 :
00271 1) : 0;
00272 cfg.resume_playback_on_startup_time = playback_get_playing () ?
00273 playback_get_time () : 0;
00274
00275 if (! (db = cfg_db_open ()))
00276 return;
00277
00278 for (i = 0; i < ncfgbent; ++i)
00279 if (aud_boolents[i].be_wrt)
00280 cfg_db_set_bool(db, NULL,
00281 aud_boolents[i].be_vname,
00282 *aud_boolents[i].be_vloc);
00283
00284 for (i = 0; i < ncfgient; ++i)
00285 if (aud_numents[i].ie_wrt)
00286 cfg_db_set_int(db, NULL,
00287 aud_numents[i].ie_vname,
00288 *aud_numents[i].ie_vloc);
00289
00290 for (i = 0; i < ncfgsent; ++i) {
00291 if (aud_strents[i].se_wrt)
00292 cfg_db_set_string(db, NULL,
00293 aud_strents[i].se_vname,
00294 *aud_strents[i].se_vloc);
00295 }
00296
00297 cfg_db_set_float(db, NULL, "equalizer_preamp", cfg.equalizer_preamp);
00298
00299
00300 cfg_db_set_float(db, NULL, "replay_gain_preamp", cfg.replay_gain_preamp);
00301 cfg_db_set_float(db, NULL, "default_gain", cfg.default_gain);
00302
00303 for (i = 0; i < 10; i++) {
00304 str = g_strdup_printf("equalizer_band%d", i);
00305 cfg_db_set_float(db, NULL, str, cfg.equalizer_bands[i]);
00306 g_free(str);
00307 }
00308
00309 if (cfg.filesel_path)
00310 cfg_db_set_string(db, NULL, "filesel_path", cfg.filesel_path);
00311
00312 if (cfg.playlist_path)
00313 cfg_db_set_string(db, NULL, "playlist_path", cfg.playlist_path);
00314
00315 cfg_db_set_int(db, NULL, "url_history_length",
00316 g_list_length(cfg.url_history));
00317
00318 for (node = cfg.url_history, i = 1; node; node = g_list_next(node), i++) {
00319 str = g_strdup_printf("url_history%d", i);
00320 cfg_db_set_string(db, NULL, str, node->data);
00321 g_free(str);
00322 }
00323
00324 cfg_db_close(db);
00325 }