diff options
author | Vasily_Makarov <danilka.pro@gmail.com> | 2011-06-15 18:24:14 +0400 |
---|---|---|
committer | Vasily_Makarov <danilka.pro@gmail.com> | 2011-06-15 18:24:14 +0400 |
commit | 6c0a4a2bc3809ee49d55fdff7c55c25d3e6ad4a5 (patch) | |
tree | 8a43922891e4f5eb7909d8d2b80f64235760e18d /saedit/config.c | |
parent | 34dbe2ca8daae2595ee6ff37632a15e68fcc7fc2 (diff) | |
download | evol-tools-6c0a4a2bc3809ee49d55fdff7c55c25d3e6ad4a5.tar.gz evol-tools-6c0a4a2bc3809ee49d55fdff7c55c25d3e6ad4a5.tar.bz2 evol-tools-6c0a4a2bc3809ee49d55fdff7c55c25d3e6ad4a5.tar.xz evol-tools-6c0a4a2bc3809ee49d55fdff7c55c25d3e6ad4a5.zip |
saedit: Review code and add some features
Diffstat (limited to 'saedit/config.c')
-rw-r--r-- | saedit/config.c | 83 |
1 files changed, 83 insertions, 0 deletions
diff --git a/saedit/config.c b/saedit/config.c new file mode 100644 index 0000000..c514e26 --- /dev/null +++ b/saedit/config.c @@ -0,0 +1,83 @@ +/*=======================================*\ +| ____ ____ | +| / \ /\ | | +| \____ / \ |____ | +| \ /____\ | | +| \____/prite / \nimation |____ditor | +| | +| Copyleft Vasily_Makarov 2011 | +| | +\*=======================================*/ + +#include <glib.h> +#include <ibusxml.h> +#include "common.h" +#include "xml.h" +#include "config.h" + +Options *config_options_new() { + return g_new0(Options, 1); +} + +void config_options_load_from_file(Options *options, + gchar *file, + gchar *data_folder) { + options->sprites = NULL; + + XMLNode *node = ibus_xml_parse_file(file); + + if (node != NULL) { + GList *list = node->sub_nodes; + while (TRUE) { + list = g_list_find_custom(list, "option", xml_node_compare_with_name_func); + if (list == NULL) + break; + gchar *name_attr = xml_node_get_attr_value(list->data, "name"); + if (name_attr != NULL) { + if (g_strcmp0(name_attr, "sprites") == 0) + options->sprites = xml_node_get_attr_value(list->data, "value"); + } + list = list->next; + } + } + + if (options->sprites == NULL) options->sprites = OPTION_SPRITES_DEFAULT; + options->sprites = g_strjoin(SEPARATOR_SLASH, data_folder, options->sprites, NULL); +} + +Keys *config_keys_new() { + Keys *keys = g_new0(Keys, 1); + keys->clientdata_folder = KEY_CLIENTDATA_FOLDER_DEFAULT; + keys->show_grid = KEY_SHOW_GRID_DEFAULT; + return keys; +} + +void config_keys_save(Keys *keys) { + GKeyFile *key_file = g_key_file_new(); + g_key_file_set_value(key_file, "General", "ClientdataFolder", + g_strjoin(SEPARATOR_SLASH, + keys->clientdata_folder, + POSTFIX_FOLDER, + NULL)); + g_key_file_set_boolean(key_file, "General", "ShowGrid", keys->show_grid); + g_file_set_contents(KEYS_CONFIG_FILE, + g_key_file_to_data(key_file, NULL, NULL), + -1, + NULL); + g_key_file_free(key_file); +} + +void config_keys_load(Keys *keys) { + GKeyFile *key_file = g_key_file_new(); + + g_key_file_load_from_file(key_file, + KEYS_CONFIG_FILE, + 0, + NULL); + if (g_key_file_has_key(key_file, "General", "ClientdataFolder", NULL)) + keys->clientdata_folder = g_key_file_get_value(key_file, "General", "ClientdataFolder", NULL); + if (g_key_file_has_key(key_file, "General", "ShowGrid", NULL)) + keys->show_grid = g_key_file_get_boolean(key_file, "General", "ShowGrid", NULL); + + g_key_file_free(key_file); +} |