summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/config.c62
-rw-r--r--src/config.h9
2 files changed, 70 insertions, 1 deletions
diff --git a/src/config.c b/src/config.c
index cf2d154..d4de2af 100644
--- a/src/config.c
+++ b/src/config.c
@@ -28,10 +28,14 @@
enum type {
TYPE_BOOLEAN,
+ TYPE_INTEGER,
+ TYPE_DOUBLE,
};
union callback {
void (*boolean_cb)(const gchar *, gboolean, gpointer);
+ void (*integer_cb)(const gchar *, gint, gpointer);
+ void (*double_cb)(const gchar *, gdouble, gpointer);
};
struct callbacks {
@@ -76,6 +80,16 @@ set_type_or_run_callbacks(MqConfig *config, const gchar *name, gpointer value,
*((gboolean *) value),
cbs->user_data);
break;
+ case TYPE_INTEGER:
+ cbs->cb.integer_cb(name,
+ *((gint *) value),
+ cbs->user_data);
+ break;
+ case TYPE_DOUBLE:
+ cbs->cb.double_cb(name,
+ *((gdouble *) value),
+ cbs->user_data);
+ break;
}
}
}
@@ -136,9 +150,38 @@ mq_config_set_boolean(MqConfig *config, const gchar *name, gboolean value)
}
void
+mq_config_set_integer(MqConfig *config, const gchar *name, gint value)
+{
+ gchar *group;
+ gchar *key;
+
+ split_name(name, &group, &key);
+
+ g_key_file_set_integer(config->key_file, group, name, value);
+
+ set_type_or_run_callbacks(config, name, &value, TYPE_INTEGER);
+}
+
+void
+mq_config_set_double(MqConfig *config, const gchar *name, gdouble value)
+{
+ gchar *group;
+ gchar *key;
+
+ split_name(name, &group, &key);
+
+ g_key_file_set_double(config->key_file, group, name, value);
+
+ set_type_or_run_callbacks(config, name, &value, TYPE_DOUBLE);
+}
+
+gboolean
mq_config_set(MqConfig *config, const gchar *name, const gchar *value)
{
struct item *item;
+ gint integer_value;
+ gdouble double_value;
+ gchar *endptr;
item = g_hash_table_lookup(config->types_and_cbs, name);
g_assert(item);
@@ -149,6 +192,23 @@ mq_config_set(MqConfig *config, const gchar *name, const gchar *value)
* mq_html_input_checkbox()). */
mq_config_set_boolean(config, name,
value[1] == 'n' ? TRUE : FALSE);
- break;
+ return TRUE;
+ case TYPE_INTEGER:
+ integer_value = strtol(value, &endptr, 10);
+ if (*endptr != '\0') {
+ return FALSE;
+ }
+ mq_config_set_integer(config, name, integer_value);
+ return TRUE;
+ case TYPE_DOUBLE:
+ double_value = strtod(value, &endptr);
+ if (*endptr != '\0') {
+ return FALSE;
+ }
+ mq_config_set_double(config, name, double_value);
+ return TRUE;
}
+
+ g_assert_not_reached();
+ return FALSE;
}
diff --git a/src/config.h b/src/config.h
index f7e285c..126e790 100644
--- a/src/config.h
+++ b/src/config.h
@@ -39,4 +39,13 @@ mq_config_new(const gchar *profile);
void
mq_config_set_boolean(MqConfig *config, const gchar *name, gboolean value);
+void
+mq_config_set_integer(MqConfig *config, const gchar *name, gint value);
+
+void
+mq_config_set_double(MqConfig *config, const gchar *name, gdouble value);
+
+gboolean
+mq_config_set(MqConfig *config, const gchar *name, const gchar *value);
+
#endif