changeset 2118:36d4043b3df2 trunk

[svn] - add the starting point of some audacious C++ bindings
author nenolod
date Wed, 13 Dec 2006 22:46:29 -0800
parents 5dc1bfb0ac99
children 6d7381072a45
files ChangeLog libaudacious++/Makefile libaudacious++/configdb.cxx libaudacious++/configdb.hh
diffstat 4 files changed, 239 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/ChangeLog	Wed Dec 13 20:38:24 2006 -0800
+++ b/ChangeLog	Wed Dec 13 22:46:29 2006 -0800
@@ -1,3 +1,11 @@
+2006-12-14 04:38:24 +0000  William Pitcock <nenolod@nenolod.net>
+  revision [3239]
+  - use str_has_prefix_nocase instead of a literal compare on extension
+  
+  trunk/audacious/input.c |    2 +-
+  1 file changed, 1 insertion(+), 1 deletion(-)
+
+
 2006-12-13 08:38:32 +0000  Yoshiki Yazawa <yaz@cc.rim.or.jp>
   revision [3237]
   - ar should pick changes
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/libaudacious++/Makefile	Wed Dec 13 22:46:29 2006 -0800
@@ -0,0 +1,35 @@
+include ../mk/rules.mk
+include ../mk/init.mk
+
+PICLDFLAGS = $(LIBLDFLAGS)
+
+includedir = $(includedir)/audacious++
+
+OBJECTIVE_LIBS = libaudacious++$(SHARED_SUFFIX)
+OBJECTIVE_SONAME_SUFFIX = 1
+
+LIBADD = \
+	$(GTK_LIBS)      \
+	$(GCONF_LIBS)
+
+CXXFLAGS += $(PICFLAGS) \
+	$(GTK_CFLAGS)        \
+	$(GCONF_CFLAGS)      \
+	-D_AUDACIOUS_CORE    \
+	-I..		      \
+	-I../intl
+
+SOURCES = configdb.cxx
+
+OBJECTS = ${SOURCES:.cxx=.o}
+
+HEADERS = configdb.hh
+
+include ../mk/objective.mk
+
+install-posthook:
+	@mv ${DESTDIR}/${LIBDIR}/libaudacious++$(SHARED_SUFFIX) ${DESTDIR}/${LIBDIR}/libaudacious++$(SHARED_SUFFIX).1.0.0
+	@ln -sf ${LIBDIR}/libaudacious++$(SHARED_SUFFIX).1.0.0 \
+		${DESTDIR}/${LIBDIR}/libaudacious++$(SHARED_SUFFIX).1
+	@ln -sf ${LIBDIR}/libaudacious++$(SHARED_SUFFIX).1 \
+		${DESTDIR}/${LIBDIR}/libaudacious++$(SHARED_SUFFIX)
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/libaudacious++/configdb.cxx	Wed Dec 13 22:46:29 2006 -0800
@@ -0,0 +1,121 @@
+#include "configdb.hh"
+
+using namespace Audacious;
+
+ConfValue::~ConfValue(void)
+{
+	// make sure we don't leak any string data
+	if (this->strval != NULL)
+		g_free(this->strval);
+}
+
+std::string ConfValue::asString(void)
+{
+	return this->strval;
+}
+
+gint ConfValue::asInt(void)
+{
+	return this->intval;
+}
+
+bool ConfValue::asBool(void)
+{
+	return this->boolval;
+}
+
+gfloat ConfValue::asFloat(void)
+{
+	return this->floatval;
+}
+
+gdouble ConfValue::asDouble(void)
+{
+	return this->dblval;
+}
+
+// *************************************************************************
+
+ConfigDB::ConfigDB(void)
+{
+	this->db = bmp_cfg_db_open();
+}
+
+ConfigDB::~ConfigDB(void)
+{
+	bmp_cfg_db_close(this->db);
+}
+
+ConfValue *ConfigDB::GetValue(std::string &section, std::string &value, ConfigDB::ValueType type)
+{
+	ConfValue *val = new ConfValue;
+
+	switch(type)
+	{
+		case String:
+			bmp_cfg_db_get_string(this->db, section.c_str(), value.c_str(), &val->strval);
+			break;
+
+		case Int:
+			bmp_cfg_db_get_int(this->db, section.c_str(), value.c_str(), &val->intval);
+			break;
+
+		case Bool:
+			gboolean tmp;
+
+			bmp_cfg_db_get_bool(this->db, section.c_str(), value.c_str(), &tmp);
+
+			if (tmp != 0)
+				val->boolval = true;
+			else
+				val->boolval = false;
+
+			break;
+
+		case Float:
+			bmp_cfg_db_get_float(this->db, section.c_str(), value.c_str(), &val->floatval);
+			break;
+
+		case Double:
+			bmp_cfg_db_get_double(this->db, section.c_str(), value.c_str(), &val->dblval);
+			break;
+
+		default:
+			g_warning("Unknown value passed to Audacious::ConfigDB::GetValue!");
+			break;
+	}
+
+	return val;
+}
+
+void ConfigDB::SetValue(std::string &section, std::string &name, std::string &value)
+{
+	// XXX bmp_cfg_db_set_string should be const char
+	// because it's not, we have to do this:
+
+	gchar *foo = g_strdup(value.c_str());
+
+	bmp_cfg_db_set_string(this->db, section.c_str(), name.c_str(), foo);
+
+	g_free(foo);
+}
+
+void ConfigDB::SetValue(std::string &section, std::string &name, gint value)
+{
+	bmp_cfg_db_set_int(this->db, section.c_str(), name.c_str(), value);
+}
+
+void ConfigDB::SetValue(std::string &section, std::string &name, bool value)
+{
+	bmp_cfg_db_set_bool(this->db, section.c_str(), name.c_str(), value);
+}
+
+void ConfigDB::SetValue(std::string &section, std::string &name, gfloat value)
+{
+	bmp_cfg_db_set_float(this->db, section.c_str(), name.c_str(), value);
+}
+
+void ConfigDB::SetValue(std::string &section, std::string &name, gdouble value)
+{
+	bmp_cfg_db_set_double(this->db, section.c_str(), name.c_str(), value);
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/libaudacious++/configdb.hh	Wed Dec 13 22:46:29 2006 -0800
@@ -0,0 +1,75 @@
+#ifndef CONFIGDB_HH
+#define CONFIGDB_HH
+
+#include <glib.h>
+
+#include <string>
+
+#ifdef _AUDACIOUS_CORE
+# include "libaudacious/configdb.h"
+#else
+# include <audacious/configdb.h>
+#endif
+
+namespace Audacious
+{
+
+	/*
+	 * Usage example:
+	 *
+	 * {
+	 *     Audacious::ConfigDb foo;
+	 *     Audacious::ConfValue *bar;
+	 *
+	 *     bar = foo.GetValue("bar", "filter");
+	 *     std::string filter = bar->asString();
+	 *     delete bar;
+	 *
+	 *     foo.SetValue("bar", "filter", "none");
+	 *
+	 *     foo.RemoveEntry("bar", "baz");
+	 * }
+	 */
+
+	class ConfValue
+	{
+	public:
+		gchar *strval;
+		gint intval;
+		bool boolval;
+		gfloat floatval;
+		gdouble dblval;
+
+		std::string asString(void);
+		gint asInt(void);
+		bool asBool(void);
+		gfloat asFloat(void);
+		gdouble asDouble(void);
+
+		~ConfValue(void);
+	};
+
+	class ConfigDB
+	{
+	private:
+		ConfigDb *db;
+
+	public:
+		enum ValueType { String, Int, Bool, Float, Double };
+
+		ConfValue *GetValue(std::string &section, std::string &name, ConfigDB::ValueType type);
+
+		void SetValue(std::string &section, std::string &name, std::string &value);
+		void SetValue(std::string &section, std::string &name, gint value);
+		void SetValue(std::string &section, std::string &name, bool value);
+		void SetValue(std::string &section, std::string &name, gfloat value);
+		void SetValue(std::string &section, std::string &name, gdouble value);
+
+		void RemoveEntry(std::string &section, std::string &value);
+
+		ConfigDB(void);
+		~ConfigDB(void);
+	};
+};
+
+#endif