Audacious $Id:Doxyfile42802007-03-2104:39:00Znenolod$
audconfig.c
Go to the documentation of this file.
00001 /*  Audacious - Cross-platform multimedia player
00002  *  Copyright (C) 2005-2010  Audacious development team.
00003  *
00004  *  Based on BMP:
00005  *  Copyright (C) 2003-2004  BMP development team.
00006  *
00007  *  Based on XMMS:
00008  *  Copyright (C) 1998-2003  XMMS development team.
00009  *
00010  *  This program is free software; you can redistribute it and/or modify
00011  *  it under the terms of the GNU General Public License as published by
00012  *  the Free Software Foundation; under version 3 of the License.
00013  *
00014  *  This program is distributed in the hope that it will be useful,
00015  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
00016  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00017  *  GNU General Public License for more details.
00018  *
00019  *  You should have received a copy of the GNU General Public License
00020  *  along with this program.  If not, see <http://www.gnu.org/licenses>.
00021  *
00022  *  The Audacious team does not consider modular code linking to
00023  *  Audacious or using our public API to be a derived work.
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     .playlist_visible = FALSE,
00039     .equalizer_visible = FALSE,
00040     .player_visible = TRUE,
00041     .show_numbers_in_pl = TRUE,
00042     .leading_zero = TRUE,
00043     .no_playlist_advance = FALSE,
00044     .advance_on_delete = FALSE,
00045     .clear_playlist = TRUE,
00046     .open_to_temporary = FALSE,
00047     .stopaftersong = FALSE,
00048     .close_dialog_open = TRUE,
00049     .equalizer_preamp = 0.0,
00050     .equalizer_bands = {0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0},
00051     .filesel_path = NULL,
00052     .playlist_path = NULL,
00053     .eqpreset_default_file = NULL,
00054     .eqpreset_extension = NULL,
00055     .url_history = NULL,
00056     .resume_playback_on_startup = FALSE,
00057     .resume_state = 0,
00058     .resume_playback_on_startup_time = 0,
00059     .chardet_detector = NULL,
00060     .chardet_fallback = NULL,
00061     .chardet_fallback_s = NULL,
00062     .output_buffer_size = 500,
00063     .show_filepopup_for_tuple = TRUE,
00064     .cover_name_include = NULL,        /* words identifying covers */
00065     .cover_name_exclude = NULL,        /* words that might not show up in cover names */
00066     .recurse_for_cover = FALSE,
00067     .recurse_for_cover_depth = 0,
00068     .filepopup_pixelsize = 150,        /* short side length of the picture in the filepopup */
00069     .filepopup_delay = 5,              /* delay until the filepopup comes up (1/10 seconds) */
00070     .use_file_cover = FALSE,           /* use filename.jpg for coverart */
00071     .filepopup_showprogressbar = TRUE,
00072     .close_jtf_dialog = TRUE,          /* close jtf dialog on jump */
00073     .software_volume_control = FALSE,
00074     .remember_jtf_entry = TRUE,
00075     .output_bit_depth = 16,
00076     .enable_replay_gain = TRUE,
00077     .enable_clipping_prevention = TRUE,
00078     .replay_gain_track = TRUE,         /* track mode */
00079     .replay_gain_album = FALSE,        /* album mode */
00080     .replay_gain_preamp = 0,
00081     .default_gain = 0,
00082     .sw_volume_left = 100, .sw_volume_right = 100,
00083 
00084     /* libaudgui stuff */
00085     .no_confirm_playlist_delete = FALSE,
00086     .playlist_manager_x = 0,
00087     .playlist_manager_y = 0,
00088     .playlist_manager_width = 0,
00089     .playlist_manager_height = 0,
00090     .playlist_manager_close_on_activate = FALSE,
00091 
00092     /* not saved */
00093     .verbose = FALSE,
00094 };
00095 
00096 typedef struct aud_cfg_boolent_t {
00097     char const *be_vname;
00098     gboolean *be_vloc;
00099     gboolean be_wrt;
00100 } aud_cfg_boolent;
00101 
00102 typedef struct aud_cfg_nument_t {
00103     char const *ie_vname;
00104     gint *ie_vloc;
00105     gboolean ie_wrt;
00106 } aud_cfg_nument;
00107 
00108 typedef struct aud_cfg_strent_t {
00109     char const *se_vname;
00110     char **se_vloc;
00111     gboolean se_wrt;
00112 } aud_cfg_strent;
00113 
00114 static aud_cfg_boolent aud_boolents[] = {
00115     {"show_numbers_in_pl", &cfg.show_numbers_in_pl, TRUE},
00116     {"leading_zero", & cfg.leading_zero, TRUE},
00117     {"no_playlist_advance", &cfg.no_playlist_advance, TRUE},
00118     {"advance_on_delete", & cfg.advance_on_delete, TRUE},
00119     {"clear_playlist", & cfg.clear_playlist, TRUE},
00120     {"open_to_temporary", & cfg.open_to_temporary, TRUE},
00121     {"player_visible", &cfg.player_visible, TRUE},
00122     {"shuffle", &cfg.shuffle, TRUE},
00123     {"repeat", &cfg.repeat, TRUE},
00124     {"stop_after_current_song", &cfg.stopaftersong, TRUE},
00125     {"playlist_visible", &cfg.playlist_visible, TRUE},
00126     {"equalizer_visible", &cfg.equalizer_visible, TRUE},
00127     {"equalizer_active", &cfg.equalizer_active, TRUE},
00128     {"equalizer_autoload", &cfg.equalizer_autoload, TRUE},
00129     {"close_dialog_open", &cfg.close_dialog_open, TRUE},
00130     {"resume_playback_on_startup", &cfg.resume_playback_on_startup, TRUE},
00131     {"show_filepopup_for_tuple", &cfg.show_filepopup_for_tuple, TRUE},
00132     {"recurse_for_cover", &cfg.recurse_for_cover, TRUE},
00133     {"use_file_cover", &cfg.use_file_cover, TRUE},
00134     {"filepopup_showprogressbar", &cfg.filepopup_showprogressbar, TRUE},
00135     {"close_jtf_dialog", &cfg.close_jtf_dialog, TRUE},
00136     {"software_volume_control", &cfg.software_volume_control, TRUE},
00137     {"remember_jtf_entry", &cfg.remember_jtf_entry, TRUE},
00138     {"enable_replay_gain", &cfg.enable_replay_gain, TRUE},
00139     {"enable_clipping_prevention", &cfg.enable_clipping_prevention, TRUE},
00140     {"replay_gain_track", &cfg.replay_gain_track, TRUE},
00141     {"replay_gain_album", &cfg.replay_gain_album, TRUE},
00142     {"no_confirm_playlist_delete", &cfg.no_confirm_playlist_delete, TRUE},
00143     {"playlist_manager_close_on_activate",
00144      & cfg.playlist_manager_close_on_activate, TRUE},
00145 };
00146 
00147 static gint ncfgbent = G_N_ELEMENTS(aud_boolents);
00148 
00149 static aud_cfg_nument aud_numents[] = {
00150     {"titlestring_preset", &cfg.titlestring_preset, TRUE},
00151     {"resume_state", & cfg.resume_state, TRUE},
00152     {"resume_playback_on_startup_time", &cfg.resume_playback_on_startup_time, TRUE},
00153     {"output_buffer_size", &cfg.output_buffer_size, TRUE},
00154     {"recurse_for_cover_depth", &cfg.recurse_for_cover_depth, TRUE},
00155     {"filepopup_pixelsize", &cfg.filepopup_pixelsize, TRUE},
00156     {"filepopup_delay", &cfg.filepopup_delay, TRUE},
00157     {"output_bit_depth", &cfg.output_bit_depth, TRUE},
00158     {"sw_volume_left", & cfg.sw_volume_left, TRUE},
00159     {"sw_volume_right", & cfg.sw_volume_right, TRUE},
00160     {"playlist_manager_x", & cfg.playlist_manager_x, TRUE},
00161     {"playlist_manager_y", & cfg.playlist_manager_y, TRUE},
00162     {"playlist_manager_width", & cfg.playlist_manager_width, TRUE},
00163     {"playlist_manager_height", & cfg.playlist_manager_height, TRUE},
00164 };
00165 
00166 static gint ncfgient = G_N_ELEMENTS(aud_numents);
00167 
00168 static aud_cfg_strent aud_strents[] = {
00169     {"eqpreset_default_file", &cfg.eqpreset_default_file, TRUE},
00170     {"eqpreset_extension", &cfg.eqpreset_extension, TRUE},
00171     {"filesel_path", &cfg.filesel_path, FALSE},
00172     {"playlist_path", &cfg.playlist_path, FALSE},
00173     {"generic_title_format", &cfg.gentitle_format, TRUE},
00174     {"chardet_detector", &cfg.chardet_detector, TRUE},
00175     {"chardet_fallback", &cfg.chardet_fallback, TRUE},
00176     {"cover_name_include", &cfg.cover_name_include, TRUE},
00177     {"cover_name_exclude", &cfg.cover_name_exclude, TRUE},
00178 };
00179 
00180 static gint ncfgsent = G_N_ELEMENTS(aud_strents);
00181 
00182 void aud_config_chardet_update(void)
00183 {
00184     if (cfg.chardet_fallback_s != NULL)
00185         g_strfreev(cfg.chardet_fallback_s);
00186     cfg.chardet_fallback_s = g_strsplit_set(cfg.chardet_fallback, " ,:;|/", 0);
00187 }
00188 
00189 
00190 void
00191 aud_config_load(void)
00192 {
00193     mcs_handle_t *db;
00194     gint i, length;
00195 
00196     if (! (db = cfg_db_open ()))
00197         return;
00198 
00199     for (i = 0; i < ncfgbent; ++i) {
00200         cfg_db_get_bool(db, NULL,
00201                             aud_boolents[i].be_vname,
00202                             aud_boolents[i].be_vloc);
00203     }
00204 
00205     for (i = 0; i < ncfgient; ++i) {
00206         cfg_db_get_int(db, NULL,
00207                            aud_numents[i].ie_vname,
00208                            aud_numents[i].ie_vloc);
00209     }
00210 
00211     for (i = 0; i < ncfgsent; ++i) {
00212         cfg_db_get_string(db, NULL,
00213                               aud_strents[i].se_vname,
00214                               aud_strents[i].se_vloc);
00215     }
00216 
00217     /* Preset */
00218     cfg_db_get_float(db, NULL, "equalizer_preamp", &cfg.equalizer_preamp);
00219     for (i = 0; i < AUD_EQUALIZER_NBANDS; i++) {
00220         gchar eqtext[32];
00221 
00222         g_snprintf(eqtext, sizeof(eqtext), "equalizer_band%d", i);
00223         cfg_db_get_float(db, NULL, eqtext, &cfg.equalizer_bands[i]);
00224     }
00225 
00226     /* History */
00227     if (cfg_db_get_int(db, NULL, "url_history_length", &length)) {
00228         for (i = 1; i <= length; i++) {
00229             gchar str[19], *tmp;
00230 
00231             g_snprintf(str, sizeof(str), "url_history%d", i);
00232             if (cfg_db_get_string(db, NULL, str, &tmp))
00233                 cfg.url_history = g_list_append(cfg.url_history, tmp);
00234         }
00235     }
00236 
00237     /* RG settings */
00238     cfg_db_get_float(db, NULL, "replay_gain_preamp", &cfg.replay_gain_preamp);
00239     cfg_db_get_float(db, NULL, "default_gain", &cfg.default_gain);
00240 
00241     cfg_db_close(db);
00242 
00243     if (!cfg.gentitle_format)
00244         cfg.gentitle_format = g_strdup("${?artist:${artist} - }${?album:${album} - }${title}");
00245 
00246     if (!cfg.chardet_detector)
00247         cfg.chardet_detector = g_strdup("");
00248 
00249     if (!cfg.chardet_fallback)
00250         cfg.chardet_fallback = g_strdup("");
00251 
00252     aud_config_chardet_update();
00253 
00254     if (!cfg.cover_name_include)
00255         cfg.cover_name_include = g_strdup("album,folder");
00256 
00257     if (!cfg.cover_name_exclude)
00258         cfg.cover_name_exclude = g_strdup("back");
00259 }
00260 
00261 void
00262 aud_config_save(void)
00263 {
00264     GList *node;
00265     gchar *str;
00266     gint i;
00267     mcs_handle_t *db;
00268 
00269     hook_call ("config save", NULL);
00270 
00271     cfg.resume_state = playback_get_playing () ? (playback_get_paused () ? 2 :
00272      1) : 0;
00273     cfg.resume_playback_on_startup_time = playback_get_playing () ?
00274      playback_get_time () : 0;
00275 
00276     if (! (db = cfg_db_open ()))
00277         return;
00278 
00279     for (i = 0; i < ncfgbent; ++i)
00280         if (aud_boolents[i].be_wrt)
00281             cfg_db_set_bool(db, NULL,
00282                                 aud_boolents[i].be_vname,
00283                                 *aud_boolents[i].be_vloc);
00284 
00285     for (i = 0; i < ncfgient; ++i)
00286         if (aud_numents[i].ie_wrt)
00287             cfg_db_set_int(db, NULL,
00288                                aud_numents[i].ie_vname,
00289                                *aud_numents[i].ie_vloc);
00290 
00291     for (i = 0; i < ncfgsent; ++i) {
00292         if (aud_strents[i].se_wrt)
00293             cfg_db_set_string(db, NULL,
00294                                   aud_strents[i].se_vname,
00295                                   *aud_strents[i].se_vloc);
00296     }
00297 
00298     cfg_db_set_float(db, NULL, "equalizer_preamp", cfg.equalizer_preamp);
00299 
00300     /* RG settings */
00301     cfg_db_set_float(db, NULL, "replay_gain_preamp", cfg.replay_gain_preamp);
00302     cfg_db_set_float(db, NULL, "default_gain",       cfg.default_gain);
00303 
00304     for (i = 0; i < 10; i++) {
00305         str = g_strdup_printf("equalizer_band%d", i);
00306         cfg_db_set_float(db, NULL, str, cfg.equalizer_bands[i]);
00307         g_free(str);
00308     }
00309 
00310     if (cfg.filesel_path)
00311         cfg_db_set_string(db, NULL, "filesel_path", cfg.filesel_path);
00312 
00313     if (cfg.playlist_path)
00314         cfg_db_set_string(db, NULL, "playlist_path", cfg.playlist_path);
00315 
00316     cfg_db_set_int(db, NULL, "url_history_length",
00317                        g_list_length(cfg.url_history));
00318 
00319     for (node = cfg.url_history, i = 1; node; node = g_list_next(node), i++) {
00320         str = g_strdup_printf("url_history%d", i);
00321         cfg_db_set_string(db, NULL, str, node->data);
00322         g_free(str);
00323     }
00324 
00325     cfg_db_close(db);
00326 }