00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018 #ifdef HAVE_CONFIG_H
00019 # include "config.h"
00020 #endif
00021
00022 #include "configdb.h"
00023 #include <libmcs/mcs.h>
00024 #include <stdlib.h>
00025 #include <string.h>
00026
00027
00028 #define RCFILE_DEFAULT_SECTION_NAME "audacious"
00029
00030 static gboolean mcs_initted = FALSE;
00031 static mcs_handle_t * config_handle = NULL;
00032 static gint config_refcount = 0;
00033
00039 mcs_handle_t *
00040 cfg_db_open()
00041 {
00042 if (!mcs_initted)
00043 {
00044 mcs_init();
00045 mcs_initted = TRUE;
00046 }
00047
00048 if (! config_handle)
00049 config_handle = mcs_new (RCFILE_DEFAULT_SECTION_NAME);
00050
00051 config_refcount ++;
00052 return config_handle;
00053 }
00054
00059 void cfg_db_close (mcs_handle_t * handle)
00060 {
00061 g_return_if_fail (handle == config_handle);
00062 g_return_if_fail (config_refcount > 0);
00063 config_refcount --;
00064 }
00065
00066 void cfg_db_flush (void)
00067 {
00068 if (! config_handle)
00069 return;
00070
00071 g_return_if_fail (! config_refcount);
00072 mcs_destroy (config_handle);
00073 config_handle = NULL;
00074 }
00075
00085 gboolean
00086 cfg_db_get_string(mcs_handle_t * db,
00087 const gchar * section,
00088 const gchar * key,
00089 gchar ** value)
00090 {
00091 if (!section)
00092 section = RCFILE_DEFAULT_SECTION_NAME;
00093
00094 if (! mcs_get_string (db, section, key, value))
00095 return FALSE;
00096
00097
00098 if (! strcmp (* value, "(null)"))
00099 {
00100 * value = NULL;
00101 return FALSE;
00102 }
00103
00104 return TRUE;
00105 }
00106
00116 gboolean
00117 cfg_db_get_int(mcs_handle_t * db,
00118 const gchar * section, const gchar * key, gint * value)
00119 {
00120 if (!section)
00121 section = RCFILE_DEFAULT_SECTION_NAME;
00122
00123 return mcs_get_int(db, section, key, value);
00124 }
00125
00135 gboolean
00136 cfg_db_get_bool(mcs_handle_t * db,
00137 const gchar * section,
00138 const gchar * key,
00139 gboolean * value)
00140 {
00141 if (!section)
00142 section = RCFILE_DEFAULT_SECTION_NAME;
00143
00144 return mcs_get_bool(db, section, key, value);
00145 }
00146
00157 gboolean
00158 cfg_db_get_float(mcs_handle_t * db,
00159 const gchar * section,
00160 const gchar * key,
00161 gfloat * value)
00162 {
00163 if (!section)
00164 section = RCFILE_DEFAULT_SECTION_NAME;
00165
00166 return mcs_get_float(db, section, key, value);
00167 }
00168
00179 gboolean
00180 cfg_db_get_double(mcs_handle_t * db,
00181 const gchar * section,
00182 const gchar * key,
00183 gdouble * value)
00184 {
00185 if (!section)
00186 section = RCFILE_DEFAULT_SECTION_NAME;
00187
00188 return mcs_get_double(db, section, key, value);
00189 }
00190
00200 void
00201 cfg_db_set_string(mcs_handle_t * db,
00202 const gchar * section,
00203 const gchar * key,
00204 const gchar * value)
00205 {
00206 if (!section)
00207 section = RCFILE_DEFAULT_SECTION_NAME;
00208
00209 if (value == NULL)
00210 mcs_unset_key (db, section, key);
00211 else
00212 mcs_set_string (db, section, key, value);
00213 }
00214
00224 void
00225 cfg_db_set_int(mcs_handle_t * db,
00226 const gchar * section,
00227 const gchar * key,
00228 gint value)
00229 {
00230 if (!section)
00231 section = RCFILE_DEFAULT_SECTION_NAME;
00232
00233 mcs_set_int(db, section, key, value);
00234 }
00235
00245 void
00246 cfg_db_set_bool(mcs_handle_t * db,
00247 const gchar * section,
00248 const gchar * key,
00249 gboolean value)
00250 {
00251 if (!section)
00252 section = RCFILE_DEFAULT_SECTION_NAME;
00253
00254 mcs_set_bool(db, section, key, value);
00255 }
00256
00266 void
00267 cfg_db_set_float(mcs_handle_t * db,
00268 const gchar * section,
00269 const gchar * key,
00270 gfloat value)
00271 {
00272 if (!section)
00273 section = RCFILE_DEFAULT_SECTION_NAME;
00274
00275 mcs_set_float(db, section, key, value);
00276 }
00277
00287 void
00288 cfg_db_set_double(mcs_handle_t * db,
00289 const gchar * section,
00290 const gchar * key,
00291 gdouble value)
00292 {
00293 if (!section)
00294 section = RCFILE_DEFAULT_SECTION_NAME;
00295
00296 mcs_set_double(db, section, key, value);
00297 }
00298
00306 void
00307 cfg_db_unset_key(mcs_handle_t * db,
00308 const gchar * section,
00309 const gchar * key)
00310 {
00311 g_return_if_fail(db != NULL);
00312 g_return_if_fail(key != NULL);
00313
00314 if (!section)
00315 section = RCFILE_DEFAULT_SECTION_NAME;
00316
00317 mcs_unset_key(db, section, key);
00318 }