summaryrefslogtreecommitdiffhomepage
path: root/mixgtk
diff options
context:
space:
mode:
Diffstat (limited to 'mixgtk')
-rw-r--r--mixgtk/mixgtk_config.c91
1 files changed, 9 insertions, 82 deletions
diff --git a/mixgtk/mixgtk_config.c b/mixgtk/mixgtk_config.c
index dfb1ad8..267b443 100644
--- a/mixgtk/mixgtk_config.c
+++ b/mixgtk/mixgtk_config.c
@@ -26,131 +26,58 @@
#include <sys/types.h>
#include <sys/stat.h>
#include <errno.h>
+#include <mixlib/mix_config.h>
#include "mixgtk.h"
#include "mixgtk_config.h"
-static const gchar *CONFIG_FILENAME = "config";
-static const gchar COMMENT_PREFIX = '#';
-static const gchar *AUTOSAVE_FLAG = "Autosave";
static const gchar *SPLIT_KEY = "Split";
static const gchar *SPLIT_YES = "Yes";
static const gchar *SPLIT_NO = "No";
-
-static GHashTable *items_;
-static gchar *config_ = NULL;
-static gboolean autosave_ = FALSE;
+static mix_config_t *config_ = NULL;
/* load configuration */
gboolean
mixgtk_config_load (void)
{
- const gchar *autosave;
- FILE *f;
- gchar *mixdir = g_strdup_printf ("%s/%s", g_get_home_dir (), MIXGTK_FILES_DIR);
- int k = mkdir (mixdir, S_IRWXU | S_IRWXG | S_IRWXO);
- if (!k) g_message ("Configuration directory %s created\n", mixdir);
- config_ = g_strdup_printf ("%s/%s", mixdir, CONFIG_FILENAME);
- items_ = g_hash_table_new (g_str_hash, g_str_equal);
- f = fopen (config_, "r");
- if (f != NULL)
- {
- enum {LEN = 256};
- gchar buffer[LEN];
- gchar *line = buffer;
- while (!feof (f))
- {
- line = fgets (line, LEN, f);
- if (line) line = g_strstrip (line);
- if (line && line[0] != COMMENT_PREFIX)
- {
- gchar **vals = g_strsplit (line, "=", 2);
- g_hash_table_insert (items_,
- (gpointer)g_strdup (g_strstrip (vals[0])),
- (gpointer)g_strdup (g_strstrip (vals[1])));
- g_strfreev (vals);
- }
- }
- fclose (f);
- }
-
- autosave = mixgtk_config_get (AUTOSAVE_FLAG);
- autosave_ = autosave && !g_strcasecmp (autosave, "True");
- g_free (mixdir);
- return TRUE;
+ if (config_ == NULL) config_ = mix_config_new (NULL, NULL);
+ return (config_ != NULL);
}
/* autosave state */
gboolean
mixgtk_config_is_autosave (void)
{
- return autosave_;
+ return mix_config_is_autosave (config_);
}
void
mixgtk_config_set_autosave (gboolean autosave)
{
- if (autosave != autosave_)
- {
- mixgtk_config_update (AUTOSAVE_FLAG, autosave? "True" : "False");
- autosave_ = autosave;
- }
+ mix_config_set_autosave (config_, autosave);
}
/* update config item */
void
mixgtk_config_update (const gchar *key, const gchar *value)
{
- gpointer tmp = NULL;
-
- g_return_if_fail (key != NULL);
- g_return_if_fail (value != NULL);
-
- tmp = g_hash_table_lookup (items_, key);
- if (tmp)
- {
- g_free (tmp);
- tmp = (gpointer)key;
- }
- else
- {
- tmp = (gpointer)g_strdup (key);
- }
-
- g_hash_table_insert (items_, tmp, g_strdup (value));
+ mix_config_update (config_, key, value);
}
/* get config item */
const gchar *
mixgtk_config_get (const gchar *key)
{
- return (const gchar*)g_hash_table_lookup (items_, key);
+ return mix_config_get (config_, key);
}
-
/* save configuration */
-static void
-save_ (gpointer key, gpointer value, gpointer file)
-{
- fprintf ((FILE *)file, "%s=%s\n", (char *)key, (char *)value);
-}
-
void
mixgtk_config_save (void)
{
- FILE *f = fopen (config_, "w");
- if (!f)
- {
- g_warning ("Unable to open config file %s (%s)",
- config_, g_strerror (errno));
- return;
- }
- g_hash_table_foreach (items_, save_, (gpointer)f);
- fclose (f);
+ mix_config_save (config_);
}
-
-
gboolean
mixgtk_config_is_split (void)
{