31 #define DEFAULT_SECTION "audacious"
36 "advance_on_delete",
"FALSE",
37 "clear_playlist",
"TRUE",
38 "open_to_temporary",
"TRUE",
39 "resume_playback_on_startup",
"FALSE",
40 "show_interface",
"TRUE",
43 "eqpreset_default_file",
"",
44 "eqpreset_extension",
"",
45 "equalizer_active",
"FALSE",
46 "equalizer_autoload",
"FALSE",
47 "equalizer_bands",
"0,0,0,0,0,0,0,0,0,0",
48 "equalizer_preamp",
"0",
51 "cover_name_exclude",
"back",
52 "cover_name_include",
"album,cover,front,folder",
53 "filepopup_delay",
"5",
54 "filepopup_showprogressbar",
"TRUE",
55 "recurse_for_cover",
"FALSE",
56 "recurse_for_cover_depth",
"0",
57 "show_filepopup_for_tuple",
"TRUE",
58 "use_file_cover",
"FALSE",
62 "use_proxy_auth",
"FALSE",
66 "enable_replay_gain",
"TRUE",
67 "enable_clipping_prevention",
"TRUE",
68 "output_bit_depth",
"16",
69 "output_buffer_size",
"500",
70 "replay_gain_album",
"FALSE",
71 "replay_gain_preamp",
"0",
72 "soft_clipping",
"FALSE",
73 "software_volume_control",
"FALSE",
74 "sw_volume_left",
"100",
75 "sw_volume_right",
"100",
78 "no_playlist_advance",
"FALSE",
81 "stop_after_current_song",
"FALSE",
85 "convert_backslash",
"TRUE",
87 "convert_backslash",
"FALSE",
89 "generic_title_format",
"${?artist:${artist} - }${?album:${album} - }${title}",
90 "leading_zero",
"FALSE",
91 "metadata_on_play",
"FALSE",
92 "show_numbers_in_pl",
"FALSE",
96 static pthread_mutex_t
mutex = PTHREAD_MUTEX_INITIALIZER;
104 pthread_mutex_lock (&
mutex);
106 defaults = g_hash_table_new_full (g_str_hash, g_str_equal, g_free,
107 (GDestroyNotify) g_hash_table_destroy);
111 if (g_file_test (path, G_FILE_TEST_EXISTS))
114 if (! g_key_file_load_from_file (
keyfile, path, 0, & error))
116 fprintf (stderr,
"Error loading config: %s\n", error->message);
117 g_error_free (error);
123 pthread_mutex_unlock (&
mutex);
131 pthread_mutex_lock (&
mutex);
135 pthread_mutex_unlock (&
mutex);
143 if (! g_file_set_contents (path, data, -1, & error))
145 fprintf (stderr,
"Error saving config: %s\n", error->message);
146 g_error_free (error);
153 pthread_mutex_unlock (&
mutex);
159 pthread_mutex_lock (&
mutex);
166 pthread_mutex_unlock (&
mutex);
172 pthread_mutex_lock (&
mutex);
177 if (g_key_file_has_group (
keyfile, section))
183 pthread_mutex_unlock (&
mutex);
189 pthread_mutex_lock (&
mutex);
194 GHashTable *
table = g_hash_table_lookup (
defaults, section);
197 table = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, (GDestroyNotify)
str_unref);
198 g_hash_table_replace (
defaults, g_strdup (section), table);
203 const char *
name = * entries ++;
204 const char * value = * entries ++;
205 if (! name || ! value)
208 g_hash_table_replace (table, g_strdup (name),
str_get (value));
211 pthread_mutex_unlock (&
mutex);
216 GHashTable *
table = g_hash_table_lookup (
defaults, section);
217 const char * def = table ? g_hash_table_lookup (table, name) :
NULL;
218 return def ? def :
"";
224 g_return_if_fail (name && value);
225 pthread_mutex_lock (&
mutex);
233 if (! strcmp (value, def))
235 if (g_key_file_has_key (
keyfile, section, name,
NULL))
237 g_key_file_remove_key (
keyfile, section, name,
NULL);
243 char * old = g_key_file_has_key (
keyfile, section, name,
NULL) ?
246 if (! old || strcmp (value, old))
248 g_key_file_set_value (
keyfile, section, name, value);
261 char *
event = g_strdup_printf (
"set %s", name);
267 pthread_mutex_unlock (&
mutex);
273 g_return_val_if_fail (name, g_strdup (
""));
274 pthread_mutex_lock (&
mutex);
279 char * value = g_key_file_has_key (
keyfile, section, name,
NULL) ?
285 pthread_mutex_unlock (&
mutex);
291 set_string (section, name, value ?
"TRUE" :
"FALSE");
297 bool_t value = ! strcmp (
string,
"TRUE");
305 g_return_if_fail (
string);
322 g_return_if_fail (
string);
EXPORT bool_t string_to_int(const char *string, int *addr)
static const char * get_default(const char *section, const char *name)
void config_clear_section(const char *section)
EXPORT bool_t string_to_double(const char *string, double *addr)
char * get_string(const char *section, const char *name)
double get_double(const char *section, const char *name)
static GKeyFile * keyfile
void set_string(const char *section, const char *name, const char *value)
static GHashTable * table
void set_bool(const char *section, const char *name, bool_t value)
void config_set_defaults(const char *section, const char *const *entries)
static const char *const core_defaults[]
static pthread_mutex_t mutex
void set_int(const char *section, const char *name, int value)
EXPORT char * int_to_string(int val)
void set_double(const char *section, const char *name, double value)
void config_cleanup(void)
bool_t get_bool(const char *section, const char *name)
void str_unref(char *str)
const char * get_path(int id)
EXPORT char * double_to_string(double val)
#define event_queue(n, d)
static GHashTable * defaults
int get_int(const char *section, const char *name)
char * str_get(const char *str)