From 7b75c61b1fc2a8d49e10c141fdc255f83ef8da94 Mon Sep 17 00:00:00 2001 From: Robert Erickson Date: Mon, 13 Oct 2014 11:24:01 -0700 Subject: [PATCH] Add access to ibus-config settings from the application. Change-Id: Id9ad93d5d3f71226675cc65247f51d749442c15e Signed-off-by: Eduardo Lima (Etrunko) --- AUTHORS | 1 + src/Makefile.am | 4 +-- src/wkb-ibus-config-eet.c | 55 +++++++++++++++++++++++++++++++++++---- src/wkb-ibus-config-eet.h | 4 +++ src/wkb-ibus-config-key.c | 30 +++++++++++++++++++++ src/wkb-ibus-config-key.h | 5 ++++ src/wkb-ibus-config.c | 32 +++++++++++++++++++++++ src/wkb-ibus-config.h | 35 +++++++++++++++++++++++++ 8 files changed, 159 insertions(+), 7 deletions(-) create mode 100644 src/wkb-ibus-config.h diff --git a/AUTHORS b/AUTHORS index 5e00638..fc6cbd8 100644 --- a/AUTHORS +++ b/AUTHORS @@ -1 +1,2 @@ Eduardo Lima (Etrunko) +Robert Erickson diff --git a/src/Makefile.am b/src/Makefile.am index b9d641f..4dab4ee 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -23,6 +23,7 @@ weekeyboard_SOURCES= \ wkb-ibus-defs.h \ wkb-ibus-panel.c \ wkb-ibus-config.c \ + wkb-ibus-config.h \ wkb-ibus-config-key.c \ wkb-ibus-config-key.h \ wkb-ibus-config-eet.c \ @@ -32,7 +33,6 @@ weekeyboard_SOURCES= \ text-protocol.c \ text-client-protocol.h - noinst_PROGRAMS = \ weekeyboard-config-eet-test \ weekeyboard-ibus-test @@ -46,7 +46,6 @@ weekeyboard_config_eet_test_SOURCES = \ wkb-ibus-config-eet.h \ wkb-ibus-config-eet-test.c - weekeyboard_ibus_test_SOURCES = \ wkb-ibus.h \ wkb-ibus.c \ @@ -57,6 +56,7 @@ weekeyboard_ibus_test_SOURCES = \ wkb-ibus-defs.h \ wkb-ibus-panel.c \ wkb-ibus-config.c \ + wkb-ibus-config.h \ wkb-ibus-config-key.c \ wkb-ibus-config-key.h \ wkb-ibus-config-eet.c \ diff --git a/src/wkb-ibus-config-eet.c b/src/wkb-ibus-config-eet.c index 1ce0d80..ed0f8e9 100644 --- a/src/wkb-ibus-config-eet.c +++ b/src/wkb-ibus-config-eet.c @@ -1,5 +1,6 @@ /* * Copyright © 2013 Intel Corporation + * Copyright © 2014 Jaguar Landrover * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -821,19 +822,63 @@ end: Eina_Bool wkb_ibus_config_eet_get_value(struct wkb_ibus_config_eet *config_eet, const char *section, const char *name, Eldbus_Message_Iter *reply) { - Eina_Bool ret = EINA_FALSE; struct wkb_config_key *key; if (!(key = _config_section_find_key(config_eet->ibus_config, section, name))) { ERR("Config key with id '%s' not found", name); - goto end; + return EINA_FALSE; } - ret = wkb_config_key_get(key, reply); + return wkb_config_key_get(key, reply); +} -end: - return ret; +int +wkb_ibus_config_eet_get_value_int(struct wkb_ibus_config_eet *config_eet, const char *section, const char *name) +{ + struct wkb_config_key *key; + + if (!(key = _config_section_find_key(config_eet->ibus_config, section, name))) + { + ERR("Config key with id '%s' not found", name); + return -1; + } + + DBG("Found key: section = <%s> name = <%s>", section, name); + + return wkb_config_key_get_int(key); +} + +Eina_Bool +wkb_ibus_config_eet_get_value_bool(struct wkb_ibus_config_eet *config_eet, const char *section, const char *name) +{ + struct wkb_config_key *key; + + if (!(key = _config_section_find_key(config_eet->ibus_config, section, name))) + { + ERR("Config key with id '%s' not found", name); + return EINA_FALSE; + } + + DBG("Found key: section = <%s> name = <%s>", section, name); + + return wkb_config_key_get_bool(key); +} + +const char * +wkb_ibus_config_eet_get_value_string(struct wkb_ibus_config_eet *config_eet, const char *section, const char *name) +{ + struct wkb_config_key *key; + + if (!(key = _config_section_find_key(config_eet->ibus_config, section, name))) + { + ERR("Config key with id '%s' not found", name); + return NULL; + } + + DBG("Found key: section = <%s> name = <%s>", section, name); + + return wkb_config_key_get_string(key); } Eina_Bool diff --git a/src/wkb-ibus-config-eet.h b/src/wkb-ibus-config-eet.h index 205c6bb..1d10905 100644 --- a/src/wkb-ibus-config-eet.h +++ b/src/wkb-ibus-config-eet.h @@ -1,5 +1,6 @@ /* * Copyright © 2013 Intel Corporation + * Copyright © 2014 Jaguar Landrover * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -38,6 +39,9 @@ void wkb_ibus_config_eet_free(struct wkb_ibus_config_eet *config_eet); int wkb_ibus_config_eet_init(void); void wkb_ibus_config_eet_shutdown(void); +int wkb_ibus_config_eet_get_value_int(struct wkb_ibus_config_eet *config_eet, const char *section, const char *name); +Eina_Bool wkb_ibus_config_eet_get_value_bool(struct wkb_ibus_config_eet *config_eet, const char *section, const char *name); +const char *wkb_ibus_config_eet_get_value_string(struct wkb_ibus_config_eet *config_eet, const char *section, const char *name); #ifdef __cplusplus } #endif diff --git a/src/wkb-ibus-config-key.c b/src/wkb-ibus-config-key.c index 606a4ce..94c3a8d 100644 --- a/src/wkb-ibus-config-key.c +++ b/src/wkb-ibus-config-key.c @@ -1,5 +1,6 @@ /* * Copyright © 2013 Intel Corporation + * Copyright © 2014 Jaguar Landrover * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -19,6 +20,7 @@ #include #include #include +#include #include "wkb-ibus-config-key.h" #include "wkb-log.h" @@ -116,6 +118,7 @@ _key_string_set(struct wkb_config_key *key, Eldbus_Message_Iter *iter) ERR("Error decoding string value using 's'"); return EINA_FALSE; } + DBG("Setting key <%s> to <%s>", key->id, str); if ((field = (const char **) key->field)) _key_string_free(field); @@ -262,3 +265,30 @@ wkb_config_key_get(struct wkb_config_key *key, Eldbus_Message_Iter *reply) return ret; } +int +wkb_config_key_get_int(struct wkb_config_key* key) +{ + assert(!strcmp(key->signature, "i")); + + return *((int *) key->field); +} + +Eina_Bool +wkb_config_key_get_bool(struct wkb_config_key* key) +{ + assert(!strcmp(key->signature, "b")); + + return *((Eina_Bool *) key->field); +} + +const char * +wkb_config_key_get_string(struct wkb_config_key* key) +{ + DBG("Found key: id = <%s> signature = <%s> field = 0x%p", key->id, key->signature, key->field); + DBG("Found key: id = <%s> signature = <%s> field as string = <%s>", key->id, key->signature, *(const char **)key->field); + + assert(!strcmp(key->signature, "s")); + + return *((const char **) key->field); +} + diff --git a/src/wkb-ibus-config-key.h b/src/wkb-ibus-config-key.h index 1343fb5..fc8352a 100644 --- a/src/wkb-ibus-config-key.h +++ b/src/wkb-ibus-config-key.h @@ -1,5 +1,6 @@ /* * Copyright © 2013 Intel Corporation + * Copyright © 2014 Jaguar Landrover * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -37,6 +38,10 @@ const char *wkb_config_key_signature(struct wkb_config_key *key); Eina_Bool wkb_config_key_set(struct wkb_config_key * key, Eldbus_Message_Iter *iter); Eina_Bool wkb_config_key_get(struct wkb_config_key *key, Eldbus_Message_Iter *reply); +int wkb_config_key_get_int(struct wkb_config_key* key); +Eina_Bool wkb_config_key_get_bool(struct wkb_config_key* key); +const char *wkb_config_key_get_string(struct wkb_config_key* key); + #ifdef __cplusplus } #endif diff --git a/src/wkb-ibus-config.c b/src/wkb-ibus-config.c index c0d6c16..408abea 100644 --- a/src/wkb-ibus-config.c +++ b/src/wkb-ibus-config.c @@ -1,5 +1,6 @@ /* * Copyright © 2013 Intel Corporation + * Copyright © 2014 Jaguar Landrover * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -21,6 +22,8 @@ #include #include +#include "wkb-ibus-config.h" + #include "wkb-ibus.h" #include "wkb-ibus-defs.h" #include "wkb-ibus-config-eet.h" @@ -40,12 +43,41 @@ static struct wkb_ibus_config_eet *_conf_eet = NULL; DBG("Message '%s' with signature '%s'", eldbus_message_member_get(_msg), eldbus_message_signature_get(_msg)); \ } while (0) +int +wkb_ibus_config_get_value_int(const char *section, const char *name) +{ + if (!_conf_eet) + return -1; + + return wkb_ibus_config_eet_get_value_int(_conf_eet, section, name); +} + +Eina_Bool +wkb_ibus_config_get_value_bool(const char *section, const char *name) +{ + if (!_conf_eet) + return EINA_FALSE; + + return wkb_ibus_config_eet_get_value_bool(_conf_eet, section, name); +} + +const char * +wkb_ibus_config_get_value_string(const char *section, const char *name) +{ + if (!_conf_eet) + return NULL; + + return wkb_ibus_config_eet_get_value_string(_conf_eet, section, name); +} + static Eldbus_Message * _config_set_value(const Eldbus_Service_Interface *iface, const Eldbus_Message *msg) { const char *section, *name; Eldbus_Message_Iter *value; + DBG("in _config_set_value"); + _config_check_message_errors(msg); if (!eldbus_message_arguments_get(msg, "ssv", §ion, &name, &value)) diff --git a/src/wkb-ibus-config.h b/src/wkb-ibus-config.h new file mode 100644 index 0000000..c329c37 --- /dev/null +++ b/src/wkb-ibus-config.h @@ -0,0 +1,35 @@ +/* + * Copyright © 2014 Jaguar Landrover + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef _WKB_IBUS_CONFIG_H_ +#define _WKB_IBUS_CONFIG_H_ + +#include +#include + +#ifdef __cplusplus +extern "C" { +#endif + +int wkb_ibus_config_get_value_int(const char *section, const char *name); +Eina_Bool wkb_ibus_config_get_value_bool(const char *section, const char *name); +const char *wkb_ibus_config_get_value_string(const char *section, const char *name); + +#ifdef __cplusplus +} +#endif + +#endif /* _WKB_IBUS_CONFIG_H_ */ -- 2.34.1