summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPatrick McDermott <pj@pehjota.net>2017-10-05 15:25:23 (EDT)
committer Patrick McDermott <pj@pehjota.net>2017-10-05 15:25:23 (EDT)
commit98c024f5a7096266b99cba09293c0b474e76d2d6 (patch)
tree01db88f59a71836bd0ebb5d007930c8759633f2c
parent0493875f09621e3495c95199da54b49910cb87fd (diff)
downloadmarquee-98c024f5a7096266b99cba09293c0b474e76d2d6.zip
marquee-98c024f5a7096266b99cba09293c0b474e76d2d6.tar.gz
marquee-98c024f5a7096266b99cba09293c0b474e76d2d6.tar.bz2
mq_config_get_string(), mq_config_set_string(): New functions
-rw-r--r--src/config.c44
-rw-r--r--src/config.h6
2 files changed, 49 insertions, 1 deletions
diff --git a/src/config.c b/src/config.c
index d28b939..96c193c 100644
--- a/src/config.c
+++ b/src/config.c
@@ -34,12 +34,14 @@ enum type {
TYPE_BOOLEAN,
TYPE_INTEGER,
TYPE_DOUBLE,
+ TYPE_STRING,
};
union callback {
void (*boolean_cb)(const gchar *, gboolean, gpointer);
void (*integer_cb)(const gchar *, gint, gpointer);
void (*double_cb)(const gchar *, gdouble, gpointer);
+ void (*string_cb)(const gchar *, gchar *, gpointer);
};
struct callbacks {
@@ -85,6 +87,11 @@ set_type_or_run_callbacks(MqConfig *config, const gchar *name, gpointer value,
*((gdouble *) value),
cbs->user_data);
break;
+ case TYPE_STRING:
+ cbs->cb.string_cb(name,
+ (gchar *) value,
+ cbs->user_data);
+ break;
}
}
}
@@ -93,7 +100,7 @@ set_type_or_run_callbacks(MqConfig *config, const gchar *name, gpointer value,
#define SET_BOOL(NAME, VALUE) mq_config_set_boolean(config, NAME, VALUE)
#define SET_INT( NAME, VALUE) mq_config_set_integer(config, NAME, VALUE)
#define SET_DBL( NAME, VALUE) mq_config_set_double (config, NAME, VALUE)
-#define SET_STR( NAME, VALUE) do { *NAME = *NAME; *VALUE = *VALUE; } while (0)
+#define SET_STR( NAME, VALUE) mq_config_set_string (config, NAME, VALUE)
#define SET_STRL(NAME, VALUE) do { *NAME = *NAME; *VALUE = *VALUE; } while (0)
static void
@@ -300,6 +307,23 @@ mq_config_get_double(MqConfig *config, const gchar *name)
return value;
}
+gchar *
+mq_config_get_string(MqConfig *config, const gchar *name)
+{
+ gchar *group;
+ gchar *key;
+ gchar *value;
+
+ split_name(name, &group, &key);
+
+ /* TODO: Handle value parsing errors? */
+ value = g_key_file_get_string(config->key_file, group, key, NULL);
+
+ g_free(group);
+
+ return value;
+}
+
void
mq_config_set_boolean(MqConfig *config, const gchar *name, gboolean value)
{
@@ -345,6 +369,21 @@ mq_config_set_double(MqConfig *config, const gchar *name, gdouble value)
set_type_or_run_callbacks(config, name, &value, TYPE_DOUBLE);
}
+void
+mq_config_set_string(MqConfig *config, const gchar *name, const gchar *value)
+{
+ gchar *group;
+ gchar *key;
+
+ split_name(name, &group, &key);
+
+ g_key_file_set_string(config->key_file, group, key, value);
+
+ g_free(group);
+
+ set_type_or_run_callbacks(config, name, value, TYPE_STRING);
+}
+
gboolean
mq_config_set(MqConfig *config, const gchar *name, const gchar *value)
{
@@ -377,6 +416,9 @@ mq_config_set(MqConfig *config, const gchar *name, const gchar *value)
}
mq_config_set_double(config, name, double_value);
return TRUE;
+ case TYPE_STRING:
+ mq_config_set_string(config, name, value);
+ return TRUE;
}
g_assert_not_reached();
diff --git a/src/config.h b/src/config.h
index b37c6bb..60aead7 100644
--- a/src/config.h
+++ b/src/config.h
@@ -52,6 +52,9 @@ mq_config_get_integer(MqConfig *config, const gchar *name);
gdouble
mq_config_get_double(MqConfig *config, const gchar *name);
+gchar *
+mq_config_get_string(MqConfig *config, const gchar *name);
+
void
mq_config_set_boolean(MqConfig *config, const gchar *name, gboolean value);
@@ -61,6 +64,9 @@ mq_config_set_integer(MqConfig *config, const gchar *name, gint value);
void
mq_config_set_double(MqConfig *config, const gchar *name, gdouble value);
+void
+mq_config_set_string(MqConfig *config, const gchar *name, const gchar *value);
+
gboolean
mq_config_set(MqConfig *config, const gchar *name, const gchar *value);