Add access to ibus-config settings from the application. 67/28667/2
authorRobert Erickson <rerickso@jaguarlandrover.com>
Mon, 13 Oct 2014 18:24:01 +0000 (11:24 -0700)
committerEduardo Lima (Etrunko) <eduardo.lima@intel.com>
Wed, 22 Oct 2014 22:25:43 +0000 (20:25 -0200)
Change-Id: Id9ad93d5d3f71226675cc65247f51d749442c15e
Signed-off-by: Eduardo Lima (Etrunko) <eduardo.lima@intel.com>
AUTHORS
src/Makefile.am
src/wkb-ibus-config-eet.c
src/wkb-ibus-config-eet.h
src/wkb-ibus-config-key.c
src/wkb-ibus-config-key.h
src/wkb-ibus-config.c
src/wkb-ibus-config.h [new file with mode: 0644]

diff --git a/AUTHORS b/AUTHORS
index 5e006385c61116742d5f6a086c381778bfe98b3b..fc6cbd8b973eac2803cda8562d091fca725ffa6f 100644 (file)
--- a/AUTHORS
+++ b/AUTHORS
@@ -1 +1,2 @@
 Eduardo Lima (Etrunko) <eduardo.lima@intel.com>
+Robert Erickson <rerickso@jaguarlandrover.com>
index b9d641fce1b5daf004eff1916edb32b31447a111..4dab4ee5dbd5c05a1c50de7fc702b27128e5836c 100644 (file)
@@ -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                   \
index 1ce0d80b7bfa73bbc67ec58a1ececf4c8b2e452a..ed0f8e9372739741b372cac0ef520e88f8979ac1 100644 (file)
@@ -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
index 205c6bb718d523b038997f398ad87cbf79e0583d..1d10905bfa044d8f98ce1fd05c7c17a53537d178 100644 (file)
@@ -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
index 606a4ce9f67d417b78c024ed7325b5f92d6e249c..94c3a8da44e7220579be17ca82a90fac12fab16e 100644 (file)
@@ -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 <sys/stat.h>
 #include <unistd.h>
 #include <string.h>
+#include <assert.h>
 
 #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);
+}
+
index 1343fb543fa23091f818baf413eb615a45757b5c..fc8352ab242fa946fae11cc79f175312d8461b86 100644 (file)
@@ -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
index c0d6c162bdd98725157d42bffa35b47ef16c7ec8..408abeae676d1760b3d10a1548ea1cba43fde360 100644 (file)
@@ -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 <Eina.h>
 #include <Eldbus.h>
 
+#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", &section, &name, &value))
diff --git a/src/wkb-ibus-config.h b/src/wkb-ibus-config.h
new file mode 100644 (file)
index 0000000..c329c37
--- /dev/null
@@ -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 <Eina.h>
+#include <Eldbus.h>
+
+#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_ */