Fix handling boolean VConf keys 33/305833/1 accepted/tizen/8.0/unified/20240213.170447
authorArtur Świgoń <a.swigon@samsung.com>
Thu, 8 Feb 2024 11:56:15 +0000 (12:56 +0100)
committerArtur Świgoń <a.swigon@samsung.com>
Thu, 8 Feb 2024 13:01:32 +0000 (13:01 +0000)
Types 'bool' and 'int' are distinct in VConf, so boolean keys cannot be read
with vconf_get_int() etc. This patch adds the necessary APIs for 'bool',
alongside 'int' and 'str'.

Change-Id: Ib9b8db0848e6918a1f0bf880f32bf7cae7baf2bb

include/screen_reader_vconf.h
src/screen_reader_vconf.c

index 9dfaaba21df2e234a55cece5ded010d2604d9b78..8716c6cac777c5712d36934188103f2ecae975bc 100644 (file)
@@ -1,6 +1,8 @@
 #ifndef SCREEN_READER_VCONF_H_
 #define SCREEN_READER_VCONF_H_
 
+#include <stdbool.h>
+
 typedef Eina_Bool (*TTSVoiceValidatorCb)(const char *tts_language, int tts_voice_type);
 
 /**
@@ -27,11 +29,11 @@ void vc_exit(void);
  *        automatically when values in vconf are changed.
  */
 
-int vc_get_read_description(void);
-int vc_get_read_list_grid_information(void);
-int vc_get_haptic(void);
-int vc_get_keyboard_feedback(void);
-int vc_get_sound_feedback(void);
+bool vc_get_read_description(void);
+bool vc_get_read_list_grid_information(void);
+bool vc_get_haptic(void);
+bool vc_get_keyboard_feedback(void);
+bool vc_get_sound_feedback(void);
 int vc_get_lcd_backlight_timeout(void);
 int vc_get_tts_voice_type(void);
 int vc_get_tts_speed(void);
index d16b375dda5ecd29c0b36d2ce4159986fa2384fb..341a0c50b27582739ed1b2d977f3765742368f26 100644 (file)
 #define VCKEY_LCD_BACKLIGHT_NORMAL  "db/setting/lcd_backlight_normal"
 
 typedef struct {
-       int init;
-       int read_description;
-       int read_list_grid_information;
-       int haptic;
-       int keyboard_feedback;
-       int sound_feedback;
+       bool init;
+       bool read_description;
+       bool read_list_grid_information;
+       bool haptic;
+       bool keyboard_feedback;
+       bool sound_feedback;
        int lcd_backlight_timeout;
        int tts_speed;
        int tts_voice_type;
@@ -108,6 +108,15 @@ static void vcwrap_update_derived_fields(void *destination)
        }
 }
 
+static bool vcwrap_get_key_bool(const char *key, bool def)
+{
+       int result = def; // Needs to be 'int' for vconf_get_bool()
+       if (vconf_get_bool(key, &result)) {
+               ERROR("vconf_get_bool failed! key=%s", key);
+       }
+       return !!result;
+}
+
 static int vcwrap_get_key_int(const char *key, int def)
 {
        int result = def;
@@ -128,6 +137,14 @@ static char *vcwrap_get_key_str(const char *key, const char *def)
        return result;
 }
 
+static void vcwrap_field_updater_bool(keynode_t *node, void *destination)
+{
+       if (!destination)
+               return;
+       *((bool*)destination) = !!vconf_keynode_get_bool(node);
+       vcwrap_update_derived_fields(destination);
+}
+
 static void vcwrap_field_updater_int(keynode_t *node, void *destination)
 {
        if (!destination)
@@ -149,6 +166,12 @@ static void vcwrap_field_updater_str(keynode_t *node, void *destination)
        vcwrap_update_derived_fields(destination);
 }
 
+static void vcwrap_set_field_updater_bool(const char *key, bool *data)
+{
+       if (vconf_notify_key_changed(key, vcwrap_field_updater_bool, data))
+               ERROR("Could not create updater for key=%s", key);
+}
+
 static void vcwrap_set_field_updater_int(const char *key, int *data)
 {
        if (vconf_notify_key_changed(key, vcwrap_field_updater_int, data))
@@ -161,6 +184,12 @@ static void vcwrap_set_field_updater_str(const char *key, char **data)
                ERROR("Could not create updater for key=%s", key);
 }
 
+static void vcwrap_unset_field_updater_bool(const char *key)
+{
+       if (vconf_ignore_key_changed(key, vcwrap_field_updater_bool))
+               DEBUG("Could not delete notify callback for key=%s", key);
+}
+
 static void vcwrap_unset_field_updater_int(const char *key)
 {
        if (vconf_ignore_key_changed(key, vcwrap_field_updater_int))
@@ -182,12 +211,12 @@ static VConfData *vc_get_instance(void)
 
        DEBUG("--------------------- VCONF_init START ---------------------");
 
-       vconf_data.init = 1;
-       vconf_data.read_description = vcwrap_get_key_int(VCKEY_DESCRIPTION, true);
-       vconf_data.read_list_grid_information = vcwrap_get_key_int(VCKEY_LIST_GRID_INFORMATION, true);
-       vconf_data.haptic = vcwrap_get_key_int(VCKEY_HAPTIC, true);
-       vconf_data.keyboard_feedback = vcwrap_get_key_int(VCKEY_KEYBOARD_FEEDBACK, true);
-       vconf_data.sound_feedback = vcwrap_get_key_int(VCKEY_SOUND_FEEDBACK, true);
+       vconf_data.init = true;
+       vconf_data.read_description = vcwrap_get_key_bool(VCKEY_DESCRIPTION, true);
+       vconf_data.read_list_grid_information = vcwrap_get_key_bool(VCKEY_LIST_GRID_INFORMATION, true);
+       vconf_data.haptic = vcwrap_get_key_bool(VCKEY_HAPTIC, true);
+       vconf_data.keyboard_feedback = vcwrap_get_key_bool(VCKEY_KEYBOARD_FEEDBACK, true);
+       vconf_data.sound_feedback = vcwrap_get_key_bool(VCKEY_SOUND_FEEDBACK, true);
        vconf_data.lcd_backlight_timeout = vcwrap_get_key_int(VCKEY_LCD_BACKLIGHT_NORMAL, -1);
        vconf_data.tts_speed = vcwrap_get_key_int(VCKEY_TTS_SPEED, 0);
        vconf_data.tts_language = vcwrap_get_key_str(VCKEY_TTS_VOICE, NULL);
@@ -197,11 +226,11 @@ static VConfData *vc_get_instance(void)
 
        appcore_set_event_callback(APPCORE_EVENT_LANG_CHANGE, display_language_changed_cb, NULL);
 
-       vcwrap_set_field_updater_int(VCKEY_DESCRIPTION, &(vconf_data.read_description));
-       vcwrap_set_field_updater_int(VCKEY_LIST_GRID_INFORMATION, &(vconf_data.read_list_grid_information));
-       vcwrap_set_field_updater_int(VCKEY_HAPTIC, &(vconf_data.haptic));
-       vcwrap_set_field_updater_int(VCKEY_KEYBOARD_FEEDBACK, &(vconf_data.keyboard_feedback));
-       vcwrap_set_field_updater_int(VCKEY_SOUND_FEEDBACK, &(vconf_data.sound_feedback));
+       vcwrap_set_field_updater_bool(VCKEY_DESCRIPTION, &(vconf_data.read_description));
+       vcwrap_set_field_updater_bool(VCKEY_LIST_GRID_INFORMATION, &(vconf_data.read_list_grid_information));
+       vcwrap_set_field_updater_bool(VCKEY_HAPTIC, &(vconf_data.haptic));
+       vcwrap_set_field_updater_bool(VCKEY_KEYBOARD_FEEDBACK, &(vconf_data.keyboard_feedback));
+       vcwrap_set_field_updater_bool(VCKEY_SOUND_FEEDBACK, &(vconf_data.sound_feedback));
        vcwrap_set_field_updater_int(VCKEY_LCD_BACKLIGHT_NORMAL, &(vconf_data.lcd_backlight_timeout));
        vcwrap_set_field_updater_int(VCKEY_TTS_SPEED, &(vconf_data.tts_speed));
        vcwrap_set_field_updater_str(VCKEY_TTS_VOICE, &(vconf_data.tts_language));
@@ -219,15 +248,15 @@ void vc_init(void)
 void vc_exit(void)
 {
        VConfData *vconf_data = vc_get_instance();
-       vconf_data->init = 0;
+       vconf_data->init = false;
 
        appcore_set_event_callback(APPCORE_EVENT_LANG_CHANGE, NULL, NULL);
 
-       vcwrap_unset_field_updater_int(VCKEY_KEYBOARD_FEEDBACK);
-       vcwrap_unset_field_updater_int(VCKEY_HAPTIC);
-       vcwrap_unset_field_updater_int(VCKEY_DESCRIPTION);
-       vcwrap_unset_field_updater_int(VCKEY_LIST_GRID_INFORMATION);
-       vcwrap_unset_field_updater_int(VCKEY_SOUND_FEEDBACK);
+       vcwrap_unset_field_updater_bool(VCKEY_KEYBOARD_FEEDBACK);
+       vcwrap_unset_field_updater_bool(VCKEY_HAPTIC);
+       vcwrap_unset_field_updater_bool(VCKEY_DESCRIPTION);
+       vcwrap_unset_field_updater_bool(VCKEY_LIST_GRID_INFORMATION);
+       vcwrap_unset_field_updater_bool(VCKEY_SOUND_FEEDBACK);
        vcwrap_unset_field_updater_int(VCKEY_LCD_BACKLIGHT_NORMAL);
        vcwrap_unset_field_updater_int(VCKEY_TTS_SPEED);
        vcwrap_unset_field_updater_str(VCKEY_TTS_VOICE);
@@ -236,27 +265,27 @@ void vc_exit(void)
        vconf_data->tts_language = NULL;
 }
 
-int vc_get_read_description(void)
+bool vc_get_read_description(void)
 {
        return vc_get_instance()->read_description;
 }
 
-int vc_get_read_list_grid_information(void)
+bool vc_get_read_list_grid_information(void)
 {
        return vc_get_instance()->read_list_grid_information;
 }
 
-int vc_get_haptic(void)
+bool vc_get_haptic(void)
 {
        return vc_get_instance()->haptic;
 }
 
-int vc_get_keyboard_feedback(void)
+bool vc_get_keyboard_feedback(void)
 {
        return vc_get_instance()->keyboard_feedback;
 }
 
-int vc_get_sound_feedback(void)
+bool vc_get_sound_feedback(void)
 {
        return vc_get_instance()->sound_feedback;
 }
@@ -288,4 +317,4 @@ void vc_tts_voice_validator_register(TTSVoiceValidatorCb cb)
        vconf_data->tts_voice_validator_cb = cb;
        if (cb)
                vcwrap_update_derived_fields(&(vconf_data->tts_language));
-}
\ No newline at end of file
+}