diff options
author | Eduardo Lima (Etrunko) <eduardo.lima@intel.com> | 2013-09-17 15:25:05 -0300 |
---|---|---|
committer | Eduardo Lima (Etrunko) <eduardo.lima@intel.com> | 2013-09-19 19:45:26 -0300 |
commit | bd06d5ec04df4276af9502aace782157751509a7 (patch) | |
tree | 94222a084edc8e07f80a542f4bd73c3134a82d12 | |
parent | 4498bdc713f906c72a7db3a01ac0207fbed69b80 (diff) | |
download | weekeyboard-bd06d5ec04df4276af9502aace782157751509a7.tar.gz weekeyboard-bd06d5ec04df4276af9502aace782157751509a7.tar.bz2 weekeyboard-bd06d5ec04df4276af9502aace782157751509a7.zip |
Add config_section_get_value and config_section_set_value
Also add two helper functions for returning the section and key according
to the parameters
Signed-off-by: Eduardo Lima (Etrunko) <eduardo.lima@intel.com>
-rw-r--r-- | src/wkb-ibus-config-eet.c | 73 |
1 files changed, 71 insertions, 2 deletions
diff --git a/src/wkb-ibus-config-eet.c b/src/wkb-ibus-config-eet.c index fba6391..37c090b 100644 --- a/src/wkb-ibus-config-eet.c +++ b/src/wkb-ibus-config-eet.c @@ -19,6 +19,7 @@ #include <sys/stat.h> #include <unistd.h> #include <string.h> +#include <strings.h> #include <Eina.h> #include <Eet.h> @@ -75,14 +76,82 @@ _config_section_set_defaults(struct _config_section *base) base->set_defaults(base); } +static struct _config_section * +_config_section_find(struct _config_section *base, const char *section) +{ + Eina_List *node; + struct _config_section *ret = NULL, *sub; + + if (!section) + return NULL; + + if (!strncasecmp(section, base->id, strlen(base->id))) + return base; + + EINA_LIST_FOREACH(base->subsections, node, sub) + if ((ret = _config_section_find(sub, section))) + break; + + return ret; +} + +static struct wkb_config_key * +_config_section_find_key(struct _config_section *base, const char *section, const char *name) +{ + struct wkb_config_key *ret = NULL, *key; + struct _config_section *sec; + const char *key_id; + Eina_List *node; + + if (!(sec = _config_section_find(base, section))) + { + printf("Config section with id '%s' not found\n", section); + goto end; + } + + EINA_LIST_FOREACH(base->keys, node, key) + { + key_id = wkb_config_key_id(key); + if (!strncasecmp(name, key_id, strlen(key_id))) + { + ret = key; + break; + } + } + +end: + return ret; +} + static Eina_Bool _config_section_set_value(struct _config_section *base, const char *section, const char *name, Eldbus_Message_Iter *value) { + Eina_Bool ret = EINA_FALSE; + struct wkb_config_key *key; + + if (!(key = _config_section_find_key(base, section, name))) + { + printf("Config key with id '%s' not found\n", name); + goto end; + } + +end: + return ret; } static void * _config_section_get_value(struct _config_section *base, const char *section, const char *name) { + struct wkb_config_key *key; + + if (!(key = _config_section_find_key(base, section, name))) + { + printf("Config key with id '%s' not found\n", name); + goto end; + } + +end: + return NULL; } static void * @@ -765,7 +834,7 @@ wkb_ibus_config_eet_set_defaults(struct wkb_ibus_config_eet *config_eet) } static struct wkb_ibus_config_eet * -_config_eet_section_init(const char *path) +_config_eet_init(const char *path) { struct wkb_ibus_config_eet *eet = calloc(1, sizeof(*eet)); eet->path = eina_stringshare_add(path); @@ -790,7 +859,7 @@ _config_eet_exists(const char *path) struct wkb_ibus_config_eet * wkb_ibus_config_eet_new(const char *path) { - struct wkb_ibus_config_eet *eet = _config_eet_section_init(path); + struct wkb_ibus_config_eet *eet = _config_eet_init(path); Eet_File *ef = NULL; Eet_File_Mode mode = EET_FILE_MODE_READ_WRITE; |