From 888a3d7a8c313481de4004a5a1766f85c0dd7f20 Mon Sep 17 00:00:00 2001 From: Jose Antonio Ortega Ruiz Date: Mon, 9 Jul 2001 22:49:55 +0000 Subject: history file --- mixlib/mix_config.c | 70 ++++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 69 insertions(+), 1 deletion(-) (limited to 'mixlib/mix_config.c') diff --git a/mixlib/mix_config.c b/mixlib/mix_config.c index 871af91..ba9ad19 100644 --- a/mixlib/mix_config.c +++ b/mixlib/mix_config.c @@ -34,7 +34,9 @@ static const gchar *DEF_DIR_ = ".mdk"; static const gchar *AUTOSAVE_KEY_ = "Autosave"; static const gchar *AUTOSAVE_YES_ = "True"; static const gchar *AUTOSAVE_NO_ = "False"; -static const gchar *DEVICES_KEY_ = "DevicesDir"; +static const gchar *DEVICES_KEY_ = "Devices.dir"; +static const gchar *HISTORY_KEY_ = "History.file"; +static const gchar *HISTORY_SIZE_KEY_ = "History.size"; /* the config type */ struct mix_config_t @@ -126,6 +128,17 @@ mix_config_get (const mix_config_t *config, const gchar *key) } +gint +mix_config_get_integer (const mix_config_t *config, const gchar *key) +{ + const gchar *val; + g_return_val_if_fail (config != NULL, 0); + g_return_val_if_fail (key != NULL, 0); + val = mix_config_get (config, key); + if (!val) return 0; + return atoi (val); +} + /* update (or create if it does not exist) a new config item */ void mix_config_update (mix_config_t *config, const gchar *key, const gchar *value) @@ -150,6 +163,20 @@ mix_config_update (mix_config_t *config, const gchar *key, const gchar *value) g_hash_table_insert (config->items, tmp, g_strdup (value)); } +void +mix_config_update_integer (mix_config_t *config, const gchar *key, gint value) +{ + gchar *val; + + g_return_if_fail (config != NULL); + g_return_if_fail (key != NULL); + g_return_if_fail (value != NULL); + + val = g_strdup_printf ("%d", value); + mix_config_update (config, key, val); + g_free (val); +} + /* save the current configuration */ static void save_ (gpointer key, gpointer value, gpointer file) @@ -209,3 +236,44 @@ mix_config_get_devices_dir (const mix_config_t *config) return mix_config_get (config, DEVICES_KEY_); } +/* history file. if relative path, config dir taken as root */ +void +mix_config_set_history_file (mix_config_t *config, const gchar *path) +{ + g_return_if_fail (config != NULL); + g_return_if_fail (path != NULL); + if (g_path_is_absolute (path)) + { + mix_config_update (config, HISTORY_KEY_, path); + } + else + { + gchar *base = g_dirname (config->filename); + gchar *hf = g_strconcat (base, G_DIR_SEPARATOR_S, path, NULL); + mix_config_update (config, HISTORY_KEY_, hf); + g_free (hf); + g_free (base); + } +} + +const gchar * +mix_config_get_history_file (const mix_config_t *config) +{ + g_return_val_if_fail (config != NULL, NULL); + return mix_config_get (config, HISTORY_KEY_); +} + +void +mix_config_set_history_size (mix_config_t *config, gint s) +{ + g_return_if_fail (config != NULL); + g_return_if_fail (s >= 0); + mix_config_update_integer (config, HISTORY_SIZE_KEY_, s); +} + +gint +mix_config_get_history_size (const mix_config_t *config) +{ + g_return_val_if_fail (config != NULL, 0); + return mix_config_get_integer (config, HISTORY_SIZE_KEY_); +} -- cgit v1.2.3