summaryrefslogtreecommitdiff
path: root/src/configuration.c
diff options
context:
space:
mode:
authorCyrille Bagard <nocbos@gmail.com>2009-07-14 11:54:46 (GMT)
committerCyrille Bagard <nocbos@gmail.com>2009-07-14 11:54:46 (GMT)
commit24d7c72a124df20339a50bb61e66385352e68a1b (patch)
treebe215cb28b1ee8e146d7ec6e86401fd792ce61a7 /src/configuration.c
parentc9465acd65e197e48da8648eb8d1ef602d6772ed (diff)
Loaded the last project at startup.
git-svn-id: svn://svn.gna.org/svn/chrysalide/trunk@92 abbe820e-26c8-41b2-8c08-b7b2b41f8b0a
Diffstat (limited to 'src/configuration.c')
-rw-r--r--src/configuration.c94
1 files changed, 85 insertions, 9 deletions
diff --git a/src/configuration.c b/src/configuration.c
index f7cdfbe..de4f2f1 100644
--- a/src/configuration.c
+++ b/src/configuration.c
@@ -29,12 +29,12 @@
#include <string.h>
+#include "xdg.h"
#include "xml.h"
#include "common/extstr.h"
-
/* Paramètres de configuration */
struct _configuration
{
@@ -50,8 +50,6 @@ struct _configuration
-
-
/******************************************************************************
* *
* Paramètres : name = désignation de la configuration. *
@@ -69,22 +67,41 @@ struct _configuration
configuration *load_configuration(const char *name, config_param *params, unsigned int count)
{
configuration *result; /* Structure à retourner */
- char *home; /* Répertoire de l'utilisateur */
+ char *suffix; /* Fin du nom de fichier */
+ unsigned int i; /* Boucle de parcours */
+ char *strval; /* Valeur en chaîne de carac. */
result = (configuration *)calloc(1, sizeof(configuration));
result->params = params;
result->count = count;
- /* FIXME : créer le répertoire, et en XDG */
- home = strdup(getenv("HOME") != NULL ? getenv("HOME") : "");
- result->filename = stradd(home, "/.openida/");
- result->filename = stradd(result->filename, name);
- result->filename = stradd(result->filename, ".xml");
+ suffix = strdup("openida/");
+ suffix = stradd(suffix, name);
+ suffix = stradd(suffix, ".xml");
+
+ result->filename = get_xdg_config_dir(suffix);
+
+ free(suffix);
if (!open_xml_file(result->filename, &result->xdoc, &result->context))
create_new_xml_file(&result->xdoc, &result->context);
+ else
+ for (i = 0; i < count; i++)
+ switch (params[i].type)
+ {
+ case CVT_STRING:
+ strval = get_node_text_value(result->context, params[i].path);
+ set_string_config_value(result, i, strval);
+ if (strval != NULL) free(strval);
+ break;
+
+ default:
+ break;
+
+ }
+
return result;
}
@@ -123,3 +140,62 @@ void unload_configuration(configuration *config)
free(config);
}
+
+
+/******************************************************************************
+* *
+* Paramètres : config = configuration à venir consulter. *
+* index = indice de l'élément à traiter. *
+* value = valeur à considérer comme valeur courante. *
+* *
+* Description : Définit une chaîne de caractères dans la configuration. *
+* *
+* Retour : - *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+bool set_string_config_value(configuration *config, unsigned int index, const char *value)
+{
+ if (index >= config->count) return false;
+ if (config->params[index].type != CVT_STRING) return false;
+
+ config->params[index].defined = true;
+
+ if (config->params[index].cur.string != NULL)
+ free(config->params[index].cur.string);
+
+ config->params[index].cur.string = (value != NULL ? strdup(value) : NULL);
+
+ return true;
+
+}
+
+
+/******************************************************************************
+* *
+* Paramètres : config = configuration à venir consulter. *
+* index = indice de l'élément à traiter. *
+* *
+* Description : Fournit une chaîne de caractères issue de la configuration. *
+* *
+* Retour : Valeur courante ou par défaut de la configuration. *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+const char *get_string_config_value(configuration *config, unsigned int index)
+{
+ const char *result; /* Valeur à retourner */
+
+ if (index >= config->count) return NULL;
+ if (config->params[index].type != CVT_STRING) return NULL;
+
+ if (config->params[index].defined) result = config->params[index].cur.string;
+ else result = config->params[index].def.string;
+
+ return result;
+
+}