Mercurial > audlegacy
changeset 2535:97a305e550cf trunk
[svn] - make libmcs a forced requirement
- remove legacy configdb engines
- remove RcFile class (use g_keyfile instead)
author | nenolod |
---|---|
date | Sat, 17 Feb 2007 00:59:50 -0800 |
parents | c3d5ac206052 |
children | b06d60a5cb15 |
files | ChangeLog configure.ac mk/rules.mk.in src/audacious/build_stamp.c src/libaudacious/Makefile src/libaudacious/configdb.c src/libaudacious/configdb_gconf.c src/libaudacious/configdb_libmcs.c src/libaudacious/configdb_rcfile.c src/libaudacious/rcfile.c src/libaudacious/rcfile.h |
diffstat | 11 files changed, 210 insertions(+), 1376 deletions(-) [+] |
line wrap: on
line diff
--- a/ChangeLog Fri Feb 16 18:28:07 2007 -0800 +++ b/ChangeLog Sat Feb 17 00:59:50 2007 -0800 @@ -1,3 +1,11 @@ +2007-02-17 02:28:07 +0000 William Pitcock <nenolod@sacredspiral.co.uk> + revision [4078] + - fix a typo + + trunk/src/audacious/vfs.c | 2 +- + 1 file changed, 1 insertion(+), 1 deletion(-) + + 2007-02-17 02:27:31 +0000 William Pitcock <nenolod@sacredspiral.co.uk> revision [4076] - don't return a bogus vtable for an unregistered URI scheme
--- a/configure.ac Fri Feb 16 18:28:07 2007 -0800 +++ b/configure.ac Sat Feb 17 00:59:50 2007 -0800 @@ -276,21 +276,13 @@ [enable_mcs="no"] ) -if test "$enable_mcs" = "yes"; then - PKG_CHECK_MODULES(LIBMCS, [libmcs >= 0.1], - [ - AC_DEFINE(HAVE_MCS, , [Define if building with libmcs support]) - ADD_PC_REQUIRES([libmcs >= 0.1]) - ], - [AC_MSG_ERROR([Cannot find libmcs])] - ) -fi - -if test "$enable_mcs" = "yes"; then - CONFIGDB_BACKEND="libmcs" -fi - -AC_SUBST(CONFIGDB_BACKEND) +PKG_CHECK_MODULES(LIBMCS, [libmcs >= 0.1], + [ + AC_DEFINE(HAVE_MCS, , [Define if building with libmcs support]) + ADD_PC_REQUIRES([libmcs >= 0.1]) + ], + [AC_MSG_ERROR([Cannot find libmcs])] +) AC_CHECK_HEADERS(unistd.h) AC_CHECK_HEADERS(fcntl.h)
--- a/mk/rules.mk.in Fri Feb 16 18:28:07 2007 -0800 +++ b/mk/rules.mk.in Sat Feb 17 00:59:50 2007 -0800 @@ -312,7 +312,6 @@ target_vendor ?= @target_vendor@ WAV_SNDFILE ?= @WAV_SNDFILE@ VFS_BACKEND ?= @VFS_BACKEND@ -CONFIGDB_BACKEND ?= @CONFIGDB_BACKEND@ CURL_CFLAGS ?= @CURL_CFLAGS@ CURL_LIBS ?= @CURL_LIBS@ MUSICBRAINZ_LIBS ?= @MUSICBRAINZ_LIBS@
--- a/src/audacious/build_stamp.c Fri Feb 16 18:28:07 2007 -0800 +++ b/src/audacious/build_stamp.c Sat Feb 17 00:59:50 2007 -0800 @@ -1,2 +1,2 @@ #include <glib.h> -const gchar *svn_stamp = "20070217-4076"; +const gchar *svn_stamp = "20070217-4078";
--- a/src/libaudacious/Makefile Fri Feb 16 18:28:07 2007 -0800 +++ b/src/libaudacious/Makefile Sat Feb 17 00:59:50 2007 -0800 @@ -19,11 +19,8 @@ -I.. -I../.. \ -I../intl -CONF_SRC = configdb_$(CONFIGDB_BACKEND).c - SOURCES = \ - $(CONF_SRC) \ - rcfile.c \ + configdb.c \ beepctrl.c OBJECTS = ${SOURCES:.c=.o}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/libaudacious/configdb.c Sat Feb 17 00:59:50 2007 -0800 @@ -0,0 +1,193 @@ +/* This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ + +#ifdef HAVE_CONFIG_H +# include "config.h" +#endif + +#include "configdb.h" + +#include <stdlib.h> +#include <string.h> + +#include <libmcs/mcs.h> + + +#define RCFILE_DEFAULT_SECTION_NAME "audacious" + +static gboolean mcs_initted = FALSE; + +struct _ConfigDb +{ + mcs_handle_t *handle; +}; + + +ConfigDb * +bmp_cfg_db_open() +{ + ConfigDb *db; + + db = g_new(ConfigDb, 1); + + if (!mcs_initted) + { + mcs_init(); + mcs_initted = TRUE; + } + + db->handle = mcs_new(RCFILE_DEFAULT_SECTION_NAME); + + return db; +} + +void +bmp_cfg_db_close(ConfigDb * db) +{ + mcs_destroy(db->handle); + g_free(db); +} + +gboolean +bmp_cfg_db_get_string(ConfigDb * db, + const gchar * section, + const gchar * key, + gchar ** value) +{ + if (!section) + section = RCFILE_DEFAULT_SECTION_NAME; + + return mcs_get_string(db->handle, section, key, value); +} + +gboolean +bmp_cfg_db_get_int(ConfigDb * db, + const gchar * section, const gchar * key, gint * value) +{ + if (!section) + section = RCFILE_DEFAULT_SECTION_NAME; + + return mcs_get_int(db->handle, section, key, value); +} + +gboolean +bmp_cfg_db_get_bool(ConfigDb * db, + const gchar * section, + const gchar * key, + gboolean * value) +{ + if (!section) + section = RCFILE_DEFAULT_SECTION_NAME; + + return mcs_get_bool(db->handle, section, key, value); +} + +gboolean +bmp_cfg_db_get_float(ConfigDb * db, + const gchar * section, + const gchar * key, + gfloat * value) +{ + if (!section) + section = RCFILE_DEFAULT_SECTION_NAME; + + return mcs_get_float(db->handle, section, key, value); +} + +gboolean +bmp_cfg_db_get_double(ConfigDb * db, + const gchar * section, + const gchar * key, + gdouble * value) +{ + if (!section) + section = RCFILE_DEFAULT_SECTION_NAME; + + return mcs_get_double(db->handle, section, key, value); +} + +void +bmp_cfg_db_set_string(ConfigDb * db, + const gchar * section, + const gchar * key, + const gchar * value) +{ + if (!section) + section = RCFILE_DEFAULT_SECTION_NAME; + + mcs_set_string(db->handle, section, key, value); +} + +void +bmp_cfg_db_set_int(ConfigDb * db, + const gchar * section, + const gchar * key, + gint value) +{ + if (!section) + section = RCFILE_DEFAULT_SECTION_NAME; + + mcs_set_int(db->handle, section, key, value); +} + +void +bmp_cfg_db_set_bool(ConfigDb * db, + const gchar * section, + const gchar * key, + gboolean value) +{ + if (!section) + section = RCFILE_DEFAULT_SECTION_NAME; + + mcs_set_bool(db->handle, section, key, value); +} + +void +bmp_cfg_db_set_float(ConfigDb * db, + const gchar * section, + const gchar * key, + gfloat value) +{ + if (!section) + section = RCFILE_DEFAULT_SECTION_NAME; + + mcs_set_float(db->handle, section, key, value); +} + +void +bmp_cfg_db_set_double(ConfigDb * db, + const gchar * section, + const gchar * key, + gdouble value) +{ + if (!section) + section = RCFILE_DEFAULT_SECTION_NAME; + + mcs_set_double(db->handle, section, key, value); +} + +void +bmp_cfg_db_unset_key(ConfigDb * db, + const gchar * section, + const gchar * key) +{ + g_return_if_fail(db != NULL); + g_return_if_fail(key != NULL); + + if (!section) + section = RCFILE_DEFAULT_SECTION_NAME; + + mcs_unset_key(db->handle, section, key); +}
--- a/src/libaudacious/configdb_gconf.c Fri Feb 16 18:28:07 2007 -0800 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,276 +0,0 @@ -/* This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ - -#include "configdb.h" - -#include <string.h> -#include <gconf/gconf-client.h> - -#define BMP_CONFIG_BASE_PATH "/apps/audacious" - -struct _ConfigDb { - GConfClient *client; -}; - -ConfigDb * -bmp_cfg_db_open() -{ - ConfigDb *db; - - g_type_init(); - - db = g_new(ConfigDb, 1); - - db->client = gconf_client_get_default(); - - return db; -} - -void -bmp_cfg_db_close(ConfigDb * db) -{ - g_return_if_fail(db != NULL); - - g_object_unref(db->client); - g_free(db); -} - -static gchar * -build_keypath(const gchar * section, - const gchar * key) -{ - if (section == NULL) { - return g_strconcat(BMP_CONFIG_BASE_PATH, "/", key, NULL); - } - else { - return g_strconcat(BMP_CONFIG_BASE_PATH, "/", section, "/", - key, NULL); - } -} - -static gboolean -bmp_cfg_db_get_value(ConfigDb * db, - const gchar * section, - const gchar * key, - GConfValue ** value) -{ - gchar *path; - - g_return_val_if_fail(db != NULL, FALSE); - g_return_val_if_fail(key != NULL, FALSE); - g_return_val_if_fail(value != NULL, FALSE); - - path = build_keypath(section, key); - *value = gconf_client_get(db->client, path, NULL); - g_free(path); - - return (*value != NULL) ? TRUE : FALSE; -} - -static void -bmp_cfg_db_set_value(ConfigDb * db, - const gchar * section, - const gchar * key, - GConfValue * value) -{ - gchar *path; - - g_return_if_fail(db != NULL); - g_return_if_fail(key != NULL); - g_return_if_fail(value != NULL); - - path = build_keypath(section, key); - gconf_client_set(db->client, path, value, NULL); - g_free(path); -} - -gboolean -bmp_cfg_db_get_string(ConfigDb * db, - const gchar * section, - const gchar * key, - gchar ** value) -{ - GConfValue *cval; - - if (!bmp_cfg_db_get_value(db, section, key, &cval)) - return FALSE; - if (cval->type != GCONF_VALUE_STRING) - return FALSE; - *value = strdup(gconf_value_get_string(cval)); - gconf_value_free(cval); - - return TRUE; -} - -gboolean -bmp_cfg_db_get_int(ConfigDb * db, - const gchar * section, - const gchar * key, - gint * value) -{ - GConfValue *cval; - - if (!bmp_cfg_db_get_value(db, section, key, &cval)) - return FALSE; - if (cval->type != GCONF_VALUE_INT) - return FALSE; - *value = gconf_value_get_int(cval); - gconf_value_free(cval); - - return TRUE; -} - -gboolean -bmp_cfg_db_get_bool(ConfigDb * db, - const gchar * section, - const gchar * key, - gboolean * value) -{ - GConfValue *cval; - - if (!bmp_cfg_db_get_value(db, section, key, &cval)) - return FALSE; - if (cval->type != GCONF_VALUE_BOOL) - return FALSE; - *value = gconf_value_get_bool(cval); - gconf_value_free(cval); - - return TRUE; -} - -gboolean -bmp_cfg_db_get_float(ConfigDb * db, - const gchar * section, - const gchar * key, - gfloat * value) -{ - GConfValue *cval; - - if (!bmp_cfg_db_get_value(db, section, key, &cval)) - return FALSE; - if (cval->type != GCONF_VALUE_FLOAT) - return FALSE; - *value = gconf_value_get_float(cval); - gconf_value_free(cval); - - return TRUE; -} - -gboolean -bmp_cfg_db_get_double(ConfigDb * db, - const gchar * section, - const gchar * key, - gdouble * value) -{ - GConfValue *cval; - - if (!bmp_cfg_db_get_value(db, section, key, &cval)) - return FALSE; - if (cval->type != GCONF_VALUE_FLOAT) - return FALSE; - *value = gconf_value_get_float(cval); - gconf_value_free(cval); - - return TRUE; -} - -void -bmp_cfg_db_set_string(ConfigDb * db, - const gchar * section, - const gchar * key, - const gchar * value) -{ - GConfValue *cval; - - if (value == NULL) { - bmp_cfg_db_unset_key(db, section, key); - } else { - cval = gconf_value_new(GCONF_VALUE_STRING); - gconf_value_set_string(cval, value); - bmp_cfg_db_set_value(db, section, key, cval); - gconf_value_free(cval); - } -} - -void -bmp_cfg_db_set_int(ConfigDb * db, - const gchar * section, - const gchar * key, - gint value) -{ - GConfValue *cval; - - cval = gconf_value_new(GCONF_VALUE_INT); - gconf_value_set_int(cval, value); - bmp_cfg_db_set_value(db, section, key, cval); - gconf_value_free(cval); -} - -void -bmp_cfg_db_set_bool(ConfigDb * db, - const gchar * section, - const gchar * key, - gboolean value) -{ - GConfValue *cval; - - cval = gconf_value_new(GCONF_VALUE_BOOL); - gconf_value_set_bool(cval, value); - bmp_cfg_db_set_value(db, section, key, cval); - gconf_value_free(cval); -} - -void -bmp_cfg_db_set_float(ConfigDb * db, - const gchar * section, - const gchar * key, - gfloat value) -{ - GConfValue *cval; - - cval = gconf_value_new(GCONF_VALUE_FLOAT); - gconf_value_set_float(cval, value); - bmp_cfg_db_set_value(db, section, key, cval); - gconf_value_free(cval); -} - -void -bmp_cfg_db_set_double(ConfigDb * db, - const gchar * section, - const gchar * key, - gdouble value) -{ - GConfValue *cval; - - cval = gconf_value_new(GCONF_VALUE_FLOAT); - gconf_value_set_float(cval, value); - bmp_cfg_db_set_value(db, section, key, cval); - gconf_value_free(cval); -} - -void -bmp_cfg_db_unset_key(ConfigDb * db, - const gchar * section, - const gchar * key) -{ - gchar *path; - - g_return_if_fail(db != NULL); - g_return_if_fail(key != NULL); - - path = build_keypath(section, key); - gconf_client_unset(db->client, path, NULL); - g_free(path); -}
--- a/src/libaudacious/configdb_libmcs.c Fri Feb 16 18:28:07 2007 -0800 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,193 +0,0 @@ -/* This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ - -#ifdef HAVE_CONFIG_H -# include "config.h" -#endif - -#include "configdb.h" - -#include <stdlib.h> -#include <string.h> - -#include <libmcs/mcs.h> - - -#define RCFILE_DEFAULT_SECTION_NAME "audacious" - -static gboolean mcs_initted = FALSE; - -struct _ConfigDb -{ - mcs_handle_t *handle; -}; - - -ConfigDb * -bmp_cfg_db_open() -{ - ConfigDb *db; - - db = g_new(ConfigDb, 1); - - if (!mcs_initted) - { - mcs_init(); - mcs_initted = TRUE; - } - - db->handle = mcs_new(RCFILE_DEFAULT_SECTION_NAME); - - return db; -} - -void -bmp_cfg_db_close(ConfigDb * db) -{ - mcs_destroy(db->handle); - g_free(db); -} - -gboolean -bmp_cfg_db_get_string(ConfigDb * db, - const gchar * section, - const gchar * key, - gchar ** value) -{ - if (!section) - section = RCFILE_DEFAULT_SECTION_NAME; - - return mcs_get_string(db->handle, section, key, value); -} - -gboolean -bmp_cfg_db_get_int(ConfigDb * db, - const gchar * section, const gchar * key, gint * value) -{ - if (!section) - section = RCFILE_DEFAULT_SECTION_NAME; - - return mcs_get_int(db->handle, section, key, value); -} - -gboolean -bmp_cfg_db_get_bool(ConfigDb * db, - const gchar * section, - const gchar * key, - gboolean * value) -{ - if (!section) - section = RCFILE_DEFAULT_SECTION_NAME; - - return mcs_get_bool(db->handle, section, key, value); -} - -gboolean -bmp_cfg_db_get_float(ConfigDb * db, - const gchar * section, - const gchar * key, - gfloat * value) -{ - if (!section) - section = RCFILE_DEFAULT_SECTION_NAME; - - return mcs_get_float(db->handle, section, key, value); -} - -gboolean -bmp_cfg_db_get_double(ConfigDb * db, - const gchar * section, - const gchar * key, - gdouble * value) -{ - if (!section) - section = RCFILE_DEFAULT_SECTION_NAME; - - return mcs_get_double(db->handle, section, key, value); -} - -void -bmp_cfg_db_set_string(ConfigDb * db, - const gchar * section, - const gchar * key, - const gchar * value) -{ - if (!section) - section = RCFILE_DEFAULT_SECTION_NAME; - - mcs_set_string(db->handle, section, key, value); -} - -void -bmp_cfg_db_set_int(ConfigDb * db, - const gchar * section, - const gchar * key, - gint value) -{ - if (!section) - section = RCFILE_DEFAULT_SECTION_NAME; - - mcs_set_int(db->handle, section, key, value); -} - -void -bmp_cfg_db_set_bool(ConfigDb * db, - const gchar * section, - const gchar * key, - gboolean value) -{ - if (!section) - section = RCFILE_DEFAULT_SECTION_NAME; - - mcs_set_bool(db->handle, section, key, value); -} - -void -bmp_cfg_db_set_float(ConfigDb * db, - const gchar * section, - const gchar * key, - gfloat value) -{ - if (!section) - section = RCFILE_DEFAULT_SECTION_NAME; - - mcs_set_float(db->handle, section, key, value); -} - -void -bmp_cfg_db_set_double(ConfigDb * db, - const gchar * section, - const gchar * key, - gdouble value) -{ - if (!section) - section = RCFILE_DEFAULT_SECTION_NAME; - - mcs_set_double(db->handle, section, key, value); -} - -void -bmp_cfg_db_unset_key(ConfigDb * db, - const gchar * section, - const gchar * key) -{ - g_return_if_fail(db != NULL); - g_return_if_fail(key != NULL); - - if (!section) - section = RCFILE_DEFAULT_SECTION_NAME; - - mcs_unset_key(db->handle, section, key); -}
--- a/src/libaudacious/configdb_rcfile.c Fri Feb 16 18:28:07 2007 -0800 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,227 +0,0 @@ -/* This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ - -#ifdef HAVE_CONFIG_H -# include "config.h" -#endif - -#include "configdb.h" - -#include <stdlib.h> -#include <string.h> -#include "rcfile.h" - - -#define RCFILE_DEFAULT_SECTION_NAME "audacious" - - -struct _ConfigDb -{ - RcFile *file; - gchar *filename; - gboolean dirty; -}; - - -ConfigDb * -bmp_cfg_db_open() -{ - ConfigDb *db; - char *tmp; - - db = g_new(ConfigDb, 1); - - if ((tmp = getenv("XDG_CONFIG_HOME")) == NULL) - db->filename = g_build_filename(g_get_home_dir(), ".config", - "audacious", "config", NULL); - else - db->filename = g_build_filename(tmp, "audacious", "config", NULL); - - db->file = bmp_rcfile_open(db->filename); - -#ifdef DOTAUDACIOUS_COMPAT - if (!db->file) { - tmp = g_build_filename(g_get_home_dir(), BMP_RCPATH, "config", NULL); - if ((db->file = bmp_rcfile_open(tmp))) { - g_free(db->filename); - db->filename = tmp; - } - } -#endif - - if (!db->file) { -#ifdef DOTAUDACIOUS_COMPAT - g_free(tmp); -#endif - db->file = bmp_rcfile_new(); - } - - db->dirty = FALSE; - - return db; -} - -void -bmp_cfg_db_close(ConfigDb * db) -{ - if (db->dirty) - bmp_rcfile_write(db->file, db->filename); - bmp_rcfile_free(db->file); - g_free(db->filename); -} - -gboolean -bmp_cfg_db_get_string(ConfigDb * db, - const gchar * section, - const gchar * key, - gchar ** value) -{ - if (!section) - section = RCFILE_DEFAULT_SECTION_NAME; - - return bmp_rcfile_read_string(db->file, section, key, value); -} - -gboolean -bmp_cfg_db_get_int(ConfigDb * db, - const gchar * section, const gchar * key, gint * value) -{ - if (!section) - section = RCFILE_DEFAULT_SECTION_NAME; - - return bmp_rcfile_read_int(db->file, section, key, value); -} - -gboolean -bmp_cfg_db_get_bool(ConfigDb * db, - const gchar * section, - const gchar * key, - gboolean * value) -{ - if (!section) - section = RCFILE_DEFAULT_SECTION_NAME; - - return bmp_rcfile_read_bool(db->file, section, key, value); -} - -gboolean -bmp_cfg_db_get_float(ConfigDb * db, - const gchar * section, - const gchar * key, - gfloat * value) -{ - if (!section) - section = RCFILE_DEFAULT_SECTION_NAME; - - return bmp_rcfile_read_float(db->file, section, key, value); -} - -gboolean -bmp_cfg_db_get_double(ConfigDb * db, - const gchar * section, - const gchar * key, - gdouble * value) -{ - if (!section) - section = RCFILE_DEFAULT_SECTION_NAME; - - return bmp_rcfile_read_double(db->file, section, key, value); -} - -void -bmp_cfg_db_set_string(ConfigDb * db, - const gchar * section, - const gchar * key, - const gchar * value) -{ - db->dirty = TRUE; - - if (!section) - section = RCFILE_DEFAULT_SECTION_NAME; - - bmp_rcfile_write_string(db->file, section, key, value); -} - -void -bmp_cfg_db_set_int(ConfigDb * db, - const gchar * section, - const gchar * key, - gint value) -{ - db->dirty = TRUE; - - if (!section) - section = RCFILE_DEFAULT_SECTION_NAME; - - bmp_rcfile_write_int(db->file, section, key, value); -} - -void -bmp_cfg_db_set_bool(ConfigDb * db, - const gchar * section, - const gchar * key, - gboolean value) -{ - db->dirty = TRUE; - - if (!section) - section = RCFILE_DEFAULT_SECTION_NAME; - - bmp_rcfile_write_boolean(db->file, section, key, value); -} - -void -bmp_cfg_db_set_float(ConfigDb * db, - const gchar * section, - const gchar * key, - gfloat value) -{ - db->dirty = TRUE; - - if (!section) - section = RCFILE_DEFAULT_SECTION_NAME; - - bmp_rcfile_write_float(db->file, section, key, value); -} - -void -bmp_cfg_db_set_double(ConfigDb * db, - const gchar * section, - const gchar * key, - gdouble value) -{ - db->dirty = TRUE; - - if (!section) - section = RCFILE_DEFAULT_SECTION_NAME; - - bmp_rcfile_write_double(db->file, section, key, value); -} - -void -bmp_cfg_db_unset_key(ConfigDb * db, - const gchar * section, - const gchar * key) -{ - db->dirty = TRUE; - - g_return_if_fail(db != NULL); - g_return_if_fail(key != NULL); - - if (!section) - section = RCFILE_DEFAULT_SECTION_NAME; - - bmp_rcfile_remove_key(db->file, section, key); -}
--- a/src/libaudacious/rcfile.c Fri Feb 16 18:28:07 2007 -0800 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,565 +0,0 @@ -/* Audacious - * Copyright (c) 2005-2007 Audacious team - * - * BMP - * Copyright (c) 2003-2005 BMP team - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; under version 2 of the License. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ - -#include "rcfile.h" - -#include <stdio.h> -#include <string.h> -#include <stdlib.h> -#include <locale.h> - -#include <unistd.h> -#include <sys/stat.h> - - -static RcSection *bmp_rcfile_create_section(RcFile * file, - const gchar * name); -static RcLine *bmp_rcfile_create_string(RcSection * section, - const gchar * key, - const gchar * value); -static RcSection *bmp_rcfile_find_section(RcFile * file, const gchar * name); -static RcLine *bmp_rcfile_find_string(RcSection * section, const gchar * key); - -/** - * bmp_rcfile_new: - * - * #RcFile object factory. - * - * Return value: A #RcFile object. - **/ -RcFile * -bmp_rcfile_new(void) -{ - return g_new0(RcFile, 1); -} - -/** - * bmp_rcfile_free: - * @file: A #RcFile object to destroy. - * - * #RcFile object destructor. - **/ -void -bmp_rcfile_free(RcFile * file) -{ - RcSection *section; - RcLine *line; - GList *section_list, *line_list; - - if (file == NULL) - return; - - section_list = file->sections; - while (section_list) { - section = (RcSection *) section_list->data; - g_free(section->name); - - line_list = section->lines; - while (line_list) { - line = (RcLine *) line_list->data; - g_free(line->key); - g_free(line->value); - g_free(line); - line_list = g_list_next(line_list); - } - g_list_free(section->lines); - g_free(section); - - section_list = g_list_next(section_list); - } - g_list_free(file->sections); - g_free(file); -} - -/** - * bmp_rcfile_open: - * @filename: Path to rcfile to open. - * - * Opens an rcfile and returns an #RcFile object representing it. - * - * Return value: An #RcFile object representing the rcfile given. - **/ -RcFile * -bmp_rcfile_open(const gchar * filename) -{ - RcFile *file; - - gchar *buffer, **lines, *tmp; - gint i; - RcSection *section = NULL; - - g_return_val_if_fail(filename != NULL, FALSE); - g_return_val_if_fail(strlen(filename) > 0, FALSE); - - if (!g_file_get_contents(filename, &buffer, NULL, NULL)) - return NULL; - - file = bmp_rcfile_new(); - lines = g_strsplit(buffer, "\n", 0); - g_free(buffer); - i = 0; - while (lines[i]) { - if (lines[i][0] == '[') { - if ((tmp = strchr(lines[i], ']'))) { - *tmp = '\0'; - section = bmp_rcfile_create_section(file, &lines[i][1]); - } - } - else if (lines[i][0] != '#' && section) { - if ((tmp = strchr(lines[i], '='))) { - gchar **frags; - frags = g_strsplit(lines[i], "=", 2); - if (strlen(frags[1]) > 0) { - bmp_rcfile_create_string(section, frags[0], frags[1]); - }; - g_strfreev(frags); - } - } - i++; - } - g_strfreev(lines); - return file; -} - -/** - * bmp_rcfile_write: - * @file: A #RcFile object to write to disk. - * @filename: A path to write the #RcFile object's data to. - * - * Writes the contents of a #RcFile object to disk. - * - * Return value: TRUE on success, FALSE otherwise. - **/ -gboolean -bmp_rcfile_write(RcFile * file, const gchar * filename) -{ - FILE *fp; - GList *section_list, *line_list; - RcSection *section; - RcLine *line; - - g_return_val_if_fail(file != NULL, FALSE); - g_return_val_if_fail(filename != NULL, FALSE); - - if (!(fp = fopen(filename, "w"))) - return FALSE; - - section_list = file->sections; - while (section_list) { - section = (RcSection *) section_list->data; - if (section->lines) { - fprintf(fp, "[%s]\n", section->name); - line_list = section->lines; - while (line_list) { - line = (RcLine *) line_list->data; - fprintf(fp, "%s=%s\n", line->key, line->value); - line_list = g_list_next(line_list); - } - fprintf(fp, "\n"); - } - section_list = g_list_next(section_list); - } - fclose(fp); - return TRUE; -} - -/** - * bmp_rcfile_read_string: - * @file: A #RcFile object to write to disk. - * @section: The section of the RcFile to look in. - * @key: The name of the identifier to look up. - * @value: A pointer to a memory location to place the data. - * - * Looks up a value in an RcFile and places it in %value. - * - * Return value: TRUE on success, FALSE otherwise. - **/ -gboolean -bmp_rcfile_read_string(RcFile * file, const gchar * section, - const gchar * key, gchar ** value) -{ - RcSection *sect; - RcLine *line; - - g_return_val_if_fail(file != NULL, FALSE); - g_return_val_if_fail(section != NULL, FALSE); - g_return_val_if_fail(key != NULL, FALSE); - g_return_val_if_fail(value != NULL, FALSE); - - if (!(sect = bmp_rcfile_find_section(file, section))) - return FALSE; - if (!(line = bmp_rcfile_find_string(sect, key))) - return FALSE; - *value = g_strdup(line->value); - return TRUE; -} - -/** - * bmp_rcfile_read_int: - * @file: A #RcFile object to write to disk. - * @section: The section of the RcFile to look in. - * @key: The name of the identifier to look up. - * @value: A pointer to a memory location to place the data. - * - * Looks up a value in an RcFile and places it in %value. - * - * Return value: TRUE on success, FALSE otherwise. - **/ -gboolean -bmp_rcfile_read_int(RcFile * file, const gchar * section, - const gchar * key, gint * value) -{ - gchar *str; - - g_return_val_if_fail(file != NULL, FALSE); - g_return_val_if_fail(section != NULL, FALSE); - g_return_val_if_fail(key != NULL, FALSE); - g_return_val_if_fail(value != NULL, FALSE); - - if (!bmp_rcfile_read_string(file, section, key, &str)) - return FALSE; - *value = atoi(str); - g_free(str); - - return TRUE; -} - -/** - * bmp_rcfile_read_bool: - * @file: A #RcFile object to write to disk. - * @section: The section of the RcFile to look in. - * @key: The name of the identifier to look up. - * @value: A pointer to a memory location to place the data. - * - * Looks up a value in an RcFile and places it in %value. - * - * Return value: TRUE on success, FALSE otherwise. - **/ -gboolean -bmp_rcfile_read_bool(RcFile * file, const gchar * section, - const gchar * key, gboolean * value) -{ - gchar *str; - - g_return_val_if_fail(file != NULL, FALSE); - g_return_val_if_fail(section != NULL, FALSE); - g_return_val_if_fail(key != NULL, FALSE); - g_return_val_if_fail(value != NULL, FALSE); - - if (!bmp_rcfile_read_string(file, section, key, &str)) - return FALSE; - if (!strcasecmp(str, "TRUE")) - *value = TRUE; - else - *value = FALSE; - g_free(str); - return TRUE; -} - -/** - * bmp_rcfile_read_float: - * @file: A #RcFile object to write to disk. - * @section: The section of the RcFile to look in. - * @key: The name of the identifier to look up. - * @value: A pointer to a memory location to place the data. - * - * Looks up a value in an RcFile and places it in %value. - * - * Return value: TRUE on success, FALSE otherwise. - **/ -gboolean -bmp_rcfile_read_float(RcFile * file, const gchar * section, - const gchar * key, gfloat * value) -{ - gchar *str, *locale; - - g_return_val_if_fail(file != NULL, FALSE); - g_return_val_if_fail(section != NULL, FALSE); - g_return_val_if_fail(key != NULL, FALSE); - g_return_val_if_fail(value != NULL, FALSE); - - if (!bmp_rcfile_read_string(file, section, key, &str)) - return FALSE; - - locale = g_strdup(setlocale(LC_NUMERIC, NULL)); - setlocale(LC_NUMERIC, "C"); - *value = strtod(str, NULL); - setlocale(LC_NUMERIC, locale); - g_free(locale); - g_free(str); - - return TRUE; -} - -/** - * bmp_rcfile_read_double: - * @file: A #RcFile object to write to disk. - * @section: The section of the RcFile to look in. - * @key: The name of the identifier to look up. - * @value: A pointer to a memory location to place the data. - * - * Looks up a value in an RcFile and places it in %value. - * - * Return value: TRUE on success, FALSE otherwise. - **/ -gboolean -bmp_rcfile_read_double(RcFile * file, const gchar * section, - const gchar * key, gdouble * value) -{ - gchar *str, *locale; - - g_return_val_if_fail(file != NULL, FALSE); - g_return_val_if_fail(section != NULL, FALSE); - g_return_val_if_fail(key != NULL, FALSE); - g_return_val_if_fail(value != NULL, FALSE); - - if (!bmp_rcfile_read_string(file, section, key, &str)) - return FALSE; - - locale = g_strdup(setlocale(LC_NUMERIC, NULL)); - setlocale(LC_NUMERIC, "C"); - *value = strtod(str, NULL); - setlocale(LC_NUMERIC, locale); - g_free(locale); - g_free(str); - - return TRUE; -} - -/** - * bmp_rcfile_write_string: - * @file: A #RcFile object to write to disk. - * @section: The section of the RcFile to set the key in. - * @key: The name of the identifier to set. - * @value: The value to set for that identifier. - * - * Sets a value in an RcFile for %key. - **/ -void -bmp_rcfile_write_string(RcFile * file, const gchar * section, - const gchar * key, const gchar * value) -{ - RcSection *sect; - RcLine *line; - - g_return_if_fail(file != NULL); - g_return_if_fail(section != NULL); - g_return_if_fail(key != NULL); - g_return_if_fail(value != NULL); - - sect = bmp_rcfile_find_section(file, section); - if (!sect) - sect = bmp_rcfile_create_section(file, section); - if ((line = bmp_rcfile_find_string(sect, key))) { - g_free(line->value); - line->value = g_strstrip(g_strdup(value)); - } - else - bmp_rcfile_create_string(sect, key, value); -} - -/** - * bmp_rcfile_write_int: - * @file: A #RcFile object to write to disk. - * @section: The section of the RcFile to set the key in. - * @key: The name of the identifier to set. - * @value: The value to set for that identifier. - * - * Sets a value in an RcFile for %key. - **/ -void -bmp_rcfile_write_int(RcFile * file, const gchar * section, - const gchar * key, gint value) -{ - gchar *strvalue; - - g_return_if_fail(file != NULL); - g_return_if_fail(section != NULL); - g_return_if_fail(key != NULL); - - strvalue = g_strdup_printf("%d", value); - bmp_rcfile_write_string(file, section, key, strvalue); - g_free(strvalue); -} - -/** - * bmp_rcfile_write_boolean: - * @file: A #RcFile object to write to disk. - * @section: The section of the RcFile to set the key in. - * @key: The name of the identifier to set. - * @value: The value to set for that identifier. - * - * Sets a value in an RcFile for %key. - **/ -void -bmp_rcfile_write_boolean(RcFile * file, const gchar * section, - const gchar * key, gboolean value) -{ - g_return_if_fail(file != NULL); - g_return_if_fail(section != NULL); - g_return_if_fail(key != NULL); - - if (value) - bmp_rcfile_write_string(file, section, key, "TRUE"); - else - bmp_rcfile_write_string(file, section, key, "FALSE"); -} - -/** - * bmp_rcfile_write_float: - * @file: A #RcFile object to write to disk. - * @section: The section of the RcFile to set the key in. - * @key: The name of the identifier to set. - * @value: The value to set for that identifier. - * - * Sets a value in an RcFile for %key. - **/ -void -bmp_rcfile_write_float(RcFile * file, const gchar * section, - const gchar * key, gfloat value) -{ - gchar *strvalue, *locale; - - g_return_if_fail(file != NULL); - g_return_if_fail(section != NULL); - g_return_if_fail(key != NULL); - - locale = g_strdup(setlocale(LC_NUMERIC, NULL)); - setlocale(LC_NUMERIC, "C"); - strvalue = g_strdup_printf("%g", value); - setlocale(LC_NUMERIC, locale); - bmp_rcfile_write_string(file, section, key, strvalue); - g_free(locale); - g_free(strvalue); -} - -/** - * bmp_rcfile_write_double: - * @file: A #RcFile object to write to disk. - * @section: The section of the RcFile to set the key in. - * @key: The name of the identifier to set. - * @value: The value to set for that identifier. - * - * Sets a value in an RcFile for %key. - **/ -void -bmp_rcfile_write_double(RcFile * file, const gchar * section, - const gchar * key, gdouble value) -{ - gchar *strvalue, *locale; - - g_return_if_fail(file != NULL); - g_return_if_fail(section != NULL); - g_return_if_fail(key != NULL); - - locale = g_strdup(setlocale(LC_NUMERIC, NULL)); - setlocale(LC_NUMERIC, "C"); - strvalue = g_strdup_printf("%g", value); - setlocale(LC_NUMERIC, locale); - bmp_rcfile_write_string(file, section, key, strvalue); - g_free(locale); - g_free(strvalue); -} - -/** - * bmp_rcfile_remove_key: - * @file: A #RcFile object to write to disk. - * @section: The section of the RcFile to set the key in. - * @key: The name of the identifier to remove. - * - * Removes %key from an #RcFile object. - **/ -void -bmp_rcfile_remove_key(RcFile * file, const gchar * section, const gchar * key) -{ - RcSection *sect; - RcLine *line; - - g_return_if_fail(file != NULL); - g_return_if_fail(section != NULL); - g_return_if_fail(key != NULL); - - if ((sect = bmp_rcfile_find_section(file, section)) != NULL) { - if ((line = bmp_rcfile_find_string(sect, key)) != NULL) { - g_free(line->key); - g_free(line->value); - g_free(line); - sect->lines = g_list_remove(sect->lines, line); - } - } -} - -static RcSection * -bmp_rcfile_create_section(RcFile * file, const gchar * name) -{ - RcSection *section; - - section = g_new0(RcSection, 1); - section->name = g_strdup(name); - file->sections = g_list_append(file->sections, section); - - return section; -} - -static RcLine * -bmp_rcfile_create_string(RcSection * section, - const gchar * key, const gchar * value) -{ - RcLine *line; - - line = g_new0(RcLine, 1); - line->key = g_strstrip(g_strdup(key)); - line->value = g_strstrip(g_strdup(value)); - section->lines = g_list_append(section->lines, line); - - return line; -} - -static RcSection * -bmp_rcfile_find_section(RcFile * file, const gchar * name) -{ - RcSection *section; - GList *list; - - list = file->sections; - while (list) { - section = (RcSection *) list->data; - if (!strcasecmp(section->name, name)) - return section; - list = g_list_next(list); - } - return NULL; -} - -static RcLine * -bmp_rcfile_find_string(RcSection * section, const gchar * key) -{ - RcLine *line; - GList *list; - - list = section->lines; - while (list) { - line = (RcLine *) list->data; - if (!strcasecmp(line->key, key)) - return line; - list = g_list_next(list); - } - return NULL; -}
--- a/src/libaudacious/rcfile.h Fri Feb 16 18:28:07 2007 -0800 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,94 +0,0 @@ -/* Audacious - Cross-platform multimedia player - * Copyright (C) 2005-2007 Audacious development team - * - * Based on XMMS: - * Copyright (C) 1998-2000 Peter Alm, Mikael Alm, Olle Hallnas, Thomas Nilsson and 4Front Technologies - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; under version 2 of the License. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ -#ifndef RCFILE_H -#define RCFILE_H - -#include <glib.h> - -/** - * RcLine: - * @key: A key for the key->value mapping. - * @value: A value for the key->value mapping. - * - * RcLine objects contain key->value mappings. - **/ -typedef struct { - gchar *key; - gchar *value; -} RcLine; - -/** - * RcSection: - * @name: The name for the #RcSection. - * @lines: A list of key->value mappings for the #RcSection. - * - * RcSection objects contain collections of key->value mappings. - **/ -typedef struct { - gchar *name; - GList *lines; -} RcSection; - -/** - * RcFile: - * @sections: A list of sections. - * - * An RcFile object contains a collection of key->value mappings organized by section. - **/ -typedef struct { - GList *sections; -} RcFile; - -G_BEGIN_DECLS - -RcFile *bmp_rcfile_new(void); -void bmp_rcfile_free(RcFile * file); - -RcFile *bmp_rcfile_open(const gchar * filename); -gboolean bmp_rcfile_write(RcFile * file, const gchar * filename); - -gboolean bmp_rcfile_read_string(RcFile * file, const gchar * section, - const gchar * key, gchar ** value); -gboolean bmp_rcfile_read_int(RcFile * file, const gchar * section, - const gchar * key, gint * value); -gboolean bmp_rcfile_read_bool(RcFile * file, const gchar * section, - const gchar * key, gboolean * value); -gboolean bmp_rcfile_read_float(RcFile * file, const gchar * section, - const gchar * key, gfloat * value); -gboolean bmp_rcfile_read_double(RcFile * file, const gchar * section, - const gchar * key, gdouble * value); - -void bmp_rcfile_write_string(RcFile * file, const gchar * section, - const gchar * key, const gchar * value); -void bmp_rcfile_write_int(RcFile * file, const gchar * section, - const gchar * key, gint value); -void bmp_rcfile_write_boolean(RcFile * file, const gchar * section, - const gchar * key, gboolean value); -void bmp_rcfile_write_float(RcFile * file, const gchar * section, - const gchar * key, gfloat value); -void bmp_rcfile_write_double(RcFile * file, const gchar * section, - const gchar * key, gdouble value); - -void bmp_rcfile_remove_key(RcFile * file, const gchar * section, - const gchar * key); - -G_END_DECLS - -#endif // RCFILE_H