From 57c46085d8061bd8015d7379d511aef3863c8cd8 Mon Sep 17 00:00:00 2001 From: Lukasz Wlazly Date: Thu, 27 Sep 2018 12:41:15 +0200 Subject: [PATCH 01/16] [Cpp refactor] Change chosen types to provided by STL This patch change collections (like Eina_List) or some kind of variables (e.g. char*) to object implementation provided by STL Change-Id: I1dd150039bdb04cb0ec106daed0abdda6ee6674b --- ...tting-accessibility-universal-switch-action.cpp | 17 +-- ...ity-universal-switch-add-switch-accessories.cpp | 8 +- ...sibility-universal-switch-add-switch-camera.cpp | 32 ++--- ...sibility-universal-switch-add-switch-screen.cpp | 6 +- ...g-accessibility-universal-switch-add-switch.cpp | 38 ++---- ...ing-accessibility-universal-switch-add-switch.h | 3 +- ...setting-accessibility-universal-switch-dbus.cpp | 152 +++++++++------------ src/setting-accessibility-universal-switch-dbus.h | 38 +++--- ...ccessibility-universal-switch-remove-switch.cpp | 18 +-- ...ibility-universal-switch-settings-set-value.cpp | 32 ++--- ...ssibility-universal-switch-settings-set-value.h | 4 +- ...ing-accessibility-universal-switch-switches.cpp | 19 +-- ...ccessibility-universal-switch-update-switch.cpp | 10 +- src/setting-accessibility.h | 21 +-- 14 files changed, 142 insertions(+), 256 deletions(-) diff --git a/src/setting-accessibility-universal-switch-action.cpp b/src/setting-accessibility-universal-switch-action.cpp index aee224a..94fbab4 100644 --- a/src/setting-accessibility-universal-switch-action.cpp +++ b/src/setting-accessibility-universal-switch-action.cpp @@ -35,14 +35,13 @@ static void __action_changed_cb(SettingAccessibility *ad, int item_id) retm_if(ad == NULL, "Input parameter is NULL"); - if (item_id < 0 || item_id >= (int)eina_array_count(ad->config.activity_types)) { + if (item_id < 0 || item_id >= ad->config.activity_types.size()) { SETTING_TRACE_END; return; } - UniversalSwitchActivityType *activity; - activity = (UniversalSwitchActivityType *)eina_array_data_get(ad->config.activity_types, item_id); - SETTING_TRACE_DEBUG("Selected activity type, id: %s, name: %s, description: %s", activity->id, activity->name, activity->description); + auto activity = ad->config.activity_types[item_id]; + // SETTING_TRACE_DEBUG("Selected activity type, id: %s, name: %s, description: %s", activity->id, activity->name, activity->description); if (_action_cb) _action_cb(ad, activity->id, _action_user_data); @@ -57,14 +56,8 @@ void setting_accessibility_universal_switch_action_page_create(SettingAccessibil setting_accessibility_universal_switch_settings_set_value_page_create(ad, VT_RADIOS, _(DEVOPTION_STR_ACCESSIBILITY_UNIVERSAL_SWITCH_SELECT_ACTION)); setting_accessibility_universal_switch_settings_set_value_add_radio_item_change_cb(ad, __action_changed_cb); - Eina_Array_Iterator iterator; - UniversalSwitchActivityType *activity; - unsigned int i; - EINA_ARRAY_ITER_NEXT(ad->config.activity_types, i, activity, iterator, UniversalSwitchActivityType) { - setting_accessibility_universal_switch_settings_set_value_radio_item_add(ad, activity->name, i, false); - } - - + for (auto i = 0u; i < ad->config.activity_types.size(); ++i) + setting_accessibility_universal_switch_settings_set_value_radio_item_add(ad, ad->config.activity_types[i]->name, i, false); } void setting_accessibility_universal_switch_action_callback_attach(SettingAccessibility *ad, switch_action_cb cb, void *user_data) diff --git a/src/setting-accessibility-universal-switch-add-switch-accessories.cpp b/src/setting-accessibility-universal-switch-add-switch-accessories.cpp index b3ed781..b60aecb 100755 --- a/src/setting-accessibility-universal-switch-add-switch-accessories.cpp +++ b/src/setting-accessibility-universal-switch-add-switch-accessories.cpp @@ -154,13 +154,9 @@ static void __capture_switch_cb(void *user_data, const char *switch_id) retm_if(switch_id == NULL, "switch_id is NULL"); SettingAccessibility *ad = (SettingAccessibility *)user_data; - Eina_Array_Iterator iterator; - UniversalSwitchConfigurationItem *config_item; - unsigned int i; - EINA_ARRAY_ITER_NEXT(ad->config.configuration_items, i, config_item, iterator, UniversalSwitchConfigurationItem) { - if (strlen(switch_id) == strlen(config_item->switch_id) && strncmp(switch_id, config_item->switch_id, strlen(switch_id)) == 0) { + for (auto &it : ad->config.configuration_items) { + if (strlen(switch_id) == it->switch_id.size() && strncmp(switch_id, it->switch_id.c_str(), strlen(switch_id)) == 0) { __switch_already_mapped_popup(ad); - SETTING_TRACE_END; return; } } diff --git a/src/setting-accessibility-universal-switch-add-switch-camera.cpp b/src/setting-accessibility-universal-switch-add-switch-camera.cpp index 5d9da6b..8090f4f 100755 --- a/src/setting-accessibility-universal-switch-add-switch-camera.cpp +++ b/src/setting-accessibility-universal-switch-add-switch-camera.cpp @@ -41,7 +41,7 @@ static void __switch_action_cb(SettingAccessibility *ad, switch_action_t action, { retm_if(user_data == NULL, "User data parameter is NULL"); - UniversalSwitchSwitchType * camera_switch = (UniversalSwitchSwitchType *)user_data; + UniversalSwitchInfoType * camera_switch = (UniversalSwitchInfoType *)user_data; if (ad->us_configuration.camera_switch_added_cb) ad->us_configuration.camera_switch_added_cb(ad, camera_switch->id, action, camera_switch->name); @@ -49,7 +49,7 @@ static void __switch_action_cb(SettingAccessibility *ad, switch_action_t action, } -static void __create_action_page(SettingAccessibility *ad, UniversalSwitchSwitchType * camera_switch) +static void __create_action_page(SettingAccessibility *ad, UniversalSwitchInfoType * camera_switch) { retm_if(ad == NULL, "Data argument is NULL"); @@ -70,7 +70,7 @@ static void __add_camera_switch_cb(void *data, Evas_Object *obj, void *event_inf Setting_GenGroupItem_Data *settings_item = (Setting_GenGroupItem_Data *)elm_object_item_data_get(item); SettingAccessibility *ad = (SettingAccessibility *)settings_item->userdata; retm_if(ad == NULL, "Input argument is NULL"); - UniversalSwitchSwitchType * camera_switch = (UniversalSwitchSwitchType *)data; + UniversalSwitchInfoType * camera_switch = (UniversalSwitchInfoType *)data; __create_action_page(ad, camera_switch); @@ -99,26 +99,14 @@ void setting_accessibility_universal_switch_add_switch_camera_page_create(Settin elm_genlist_item_select_mode_set(ad->universal_switch_camera_comment->item, ELM_OBJECT_SELECT_MODE_DISPLAY_ONLY); setting_create_Gendial_field_titleItem(genlist, &itc_group_item, DEVOPTION_STR_ACCESSIBILITY_UNIVERSAL_SWITCH_ADD_SWITCH_CAMERA_GROUP_HEAD, NULL); - Eina_Array * switches = setting_accessibility_universal_switch_dbus_config_get_switches(&ad->config, ACCESSIBILITY_UNIVERSAL_SWITCH_CAMERA_SWITCH_PROVIDER); - if (switches != NULL) { - Eina_Array_Iterator iterator; - UniversalSwitchSwitchType *camer_switch; - unsigned int i; - EINA_ARRAY_ITER_NEXT(switches, i, camer_switch, iterator, UniversalSwitchSwitchType) - { - Setting_GenGroupItem_Data *item; - const char * description = camer_switch->description; - if (strlen(description) == 0) - description = NULL; - - item = setting_create_Gendial_field_def(genlist, &ad->itc_multiline_sub, __add_camera_switch_cb, camer_switch, - SWALLOW_Type_INVALID, NULL, NULL, 0, camer_switch->name, description, NULL); - - if (item) { - item->userdata = ad; - setting_accessibility_universal_switch_disable_already_mapped_switch(ad->config.configuration_items, camer_switch->id, item->item); - } + auto switches = setting_accessibility_universal_switch_dbus_config_get_switches(&ad->config, ACCESSIBILITY_UNIVERSAL_SWITCH_CAMERA_SWITCH_PROVIDER); + for (auto &it : switches) { + auto item = setting_create_Gendial_field_def(genlist, &ad->itc_multiline_sub, __add_camera_switch_cb, it, + SWALLOW_Type_INVALID, NULL, NULL, 0, it->name.c_str(), it->description.c_str(), NULL); + if (item) { + item->userdata = ad; + setting_accessibility_universal_switch_disable_already_mapped_switch(ad->config.configuration_items, it->id, item->item); } } diff --git a/src/setting-accessibility-universal-switch-add-switch-screen.cpp b/src/setting-accessibility-universal-switch-add-switch-screen.cpp index c2fa02a..8643070 100644 --- a/src/setting-accessibility-universal-switch-add-switch-screen.cpp +++ b/src/setting-accessibility-universal-switch-add-switch-screen.cpp @@ -27,9 +27,9 @@ static void __screen_switch_action_cb(SettingAccessibility *ad, switch_action_t if (ad->us_configuration.screen_switch_added_cb) { - Eina_Array * switches = setting_accessibility_universal_switch_dbus_config_get_switches(&ad->config, ACCESSIBILITY_UNIVERSAL_SWITCH_SCREEN_SWITCH_PROVIDER); - retm_if(switches == NULL || eina_array_count(switches) < 1, "Screen switch not found"); - UniversalSwitchSwitchType * screen_switch = (UniversalSwitchSwitchType *)eina_array_data_get(switches, 0); + auto switches = setting_accessibility_universal_switch_dbus_config_get_switches(&ad->config, ACCESSIBILITY_UNIVERSAL_SWITCH_SCREEN_SWITCH_PROVIDER); + retm_if(switches.size() < 1, "Screen switch not found"); + auto screen_switch = switches[0]; ad->us_configuration.screen_switch_added_cb(ad, screen_switch->id, action, ACCESSIBILITY_UNIVERSAL_SWITCH_SCREEN); } diff --git a/src/setting-accessibility-universal-switch-add-switch.cpp b/src/setting-accessibility-universal-switch-add-switch.cpp index 0f3ad85..1518fe5 100755 --- a/src/setting-accessibility-universal-switch-add-switch.cpp +++ b/src/setting-accessibility-universal-switch-add-switch.cpp @@ -73,40 +73,33 @@ static void __add_switch_cb(void *data, Evas_Object *obj, void *event_info) Setting_GenGroupItem_Data *settings_item = (Setting_GenGroupItem_Data *)elm_object_item_data_get(item); SettingAccessibility *ad = (SettingAccessibility *)settings_item->userdata; retm_if(ad == NULL, "Input argument is NULL"); - const char * providerId = (const char *)data; + auto providerId = *static_cast(data); - __add_switch_page_create(ad, providerId); + __add_switch_page_create(ad, providerId.c_str()); } -void setting_accessibility_universal_switch_disable_already_mapped_switch(Eina_Array *configuration_items, const char *switch_id, Elm_Object_Item *item) +void setting_accessibility_universal_switch_disable_already_mapped_switch(const std::vector &configuration_items, const std::string& switch_id, Elm_Object_Item *item) { - retm_if(configuration_items == NULL, "Input parameter is NULL"); - retm_if(switch_id == NULL, "Input parameter is NULL"); retm_if(item == NULL, "Input parameter is NULL"); - Eina_Array_Iterator already_mapped_iterator; - UniversalSwitchConfigurationItem *config_item; - unsigned int i; - EINA_ARRAY_ITER_NEXT(configuration_items, i, config_item, already_mapped_iterator, UniversalSwitchConfigurationItem) { - if (strcmp(switch_id, config_item->switch_id) == 0) + for (auto &it : configuration_items) { + if (switch_id == it->switch_id) elm_object_item_disabled_set(item, EINA_TRUE); } - } -static void __disable_screen_switch_provider_when_screen_switches_is_mapped(Eina_Array *configuration_items, UniversalSwitchSwitchProvider *switch_provider, Elm_Object_Item *item) +static void __disable_screen_switch_provider_when_screen_switches_is_mapped(const std::vector& configuration_items, UniversalSwitchSwitchProvider *switch_provider, Elm_Object_Item *item) { - retm_if(configuration_items == NULL, "Input parameter is NULL"); retm_if(switch_provider == NULL, "Input parameter is NULL"); retm_if(item == NULL, "Input parameter is NULL"); SETTING_TRACE_DEBUG("provider_id %s", switch_provider->info->id); - if (strcmp(switch_provider->info->id, ACCESSIBILITY_UNIVERSAL_SWITCH_SCREEN_SWITCH_PROVIDER) == 0) + if (switch_provider->info->id == ACCESSIBILITY_UNIVERSAL_SWITCH_SCREEN_SWITCH_PROVIDER) setting_accessibility_universal_switch_disable_already_mapped_switch(configuration_items, ACCESSIBILITY_UNIVERSAL_SWITCH_SCREEN_SWITCH_ID, item); @@ -123,22 +116,17 @@ void setting_accessibility_universal_switch_add_switch_page_create(SettingAccess elm_object_style_set(genlist, "dialogue"); elm_genlist_clear(genlist); - Eina_Array_Iterator iterator; - UniversalSwitchSwitchProvider *switch_provider; - unsigned int i; - EINA_ARRAY_ITER_NEXT(ad->config.switch_providers, i, switch_provider, iterator, UniversalSwitchSwitchProvider) { - Setting_GenGroupItem_Data *item; - - item = setting_create_Gendial_field_def( + for (auto &it : ad->config.switch_providers) { + auto item = setting_create_Gendial_field_def( genlist, &ad->itc_multiline_sub, - __add_switch_cb, switch_provider->info->id, + __add_switch_cb, &it->info->id, SWALLOW_Type_INVALID, NULL, NULL, 0, - switch_provider->info->name, - switch_provider->info->description, NULL); + it->info->name.c_str(), + it->info->description.c_str(), NULL); if (item) { item->userdata = ad; - __disable_screen_switch_provider_when_screen_switches_is_mapped(ad->config.configuration_items, switch_provider, item->item); + __disable_screen_switch_provider_when_screen_switches_is_mapped(ad->config.configuration_items, it, item->item); } } diff --git a/src/setting-accessibility-universal-switch-add-switch.h b/src/setting-accessibility-universal-switch-add-switch.h index d607dba..1b50946 100644 --- a/src/setting-accessibility-universal-switch-add-switch.h +++ b/src/setting-accessibility-universal-switch-add-switch.h @@ -5,7 +5,6 @@ void setting_accessibility_universal_switch_add_switch_page_create(SettingAccessibility *ad); void setting_accessibility_universal_switch_add_switch_new_switch_callback_attach(SettingAccessibility *ad, UniversalSwitchUpdateCb cb); -void setting_accessibility_universal_switch_disable_already_mapped_switch(Eina_Array *configuration_items, const char *switch_id, Elm_Object_Item *item); +void setting_accessibility_universal_switch_disable_already_mapped_switch(const std::vector &configuration_items, const std::string& switch_id, Elm_Object_Item *item); #endif /* SETTINGACCESSIBILITYUNIVERSALSWITCHADDSWITCH_H */ - diff --git a/src/setting-accessibility-universal-switch-dbus.cpp b/src/setting-accessibility-universal-switch-dbus.cpp index 3e00fa6..39e5562 100755 --- a/src/setting-accessibility-universal-switch-dbus.cpp +++ b/src/setting-accessibility-universal-switch-dbus.cpp @@ -27,7 +27,6 @@ #define PATH "/org/tizen/UniversalSwitch" #define IFACE "org.tizen.UniversalSwitch" #define ELDBUS_TIMEOUT 100.0 -#define EINA_ARRAY_STEPS 4 static void __bus_name_acquired(void *data, const char *bus, const char *old_id, const char *new_id); @@ -85,7 +84,7 @@ static void __eldbus_shutdown(UniversalSwitchDbusConfig *config) eldbus_shutdown(); } -static void __eldbus_getInfoArray(Eina_Array *infoTypes, Eldbus_Message *reply) +static void __eldbus_getInfoArray(std::vector& infoTypes, Eldbus_Message *reply) { Eldbus_Message_Iter *array; Eldbus_Message_Iter *struct_sss; @@ -94,40 +93,46 @@ static void __eldbus_getInfoArray(Eina_Array *infoTypes, Eldbus_Message *reply) return; } while (eldbus_message_iter_get_and_next(array, 'r', &struct_sss)) { - const char *id, *name, *description; + char *id = NULL; + char *name = NULL; + char *description = NULL; if (!eldbus_message_iter_arguments_get(struct_sss, "sss", &id, &name, &description)) { SETTING_TRACE_ERROR("Error on eldbus_message_arguments_get()"); return; } - UniversalSwitchInfoType *info = (UniversalSwitchInfoType *)calloc(1, sizeof(UniversalSwitchInfoType)); + auto info = new UniversalSwitchInfoType; if (!info) { SETTING_TRACE_ERROR("Out of memory"); return; } + SETTING_TRACE_DEBUG("deadbeef: %s| %s| %s|", id, name, description); + info->id = strdup(id); info->name = strdup(name); + SETTING_TRACE_DEBUG("deadbeef: description: %p, len: %u", description, strlen(description)); info->description = strdup(description); - eina_array_push(infoTypes, info); + SETTING_TRACE_DEBUG("deadbeef: ~~~~~~~~~~~~~~~~~~~~~~~"); + infoTypes.push_back(info); } } -static Eina_Array * __eldbus_getAllSwitchesByProviderId(UniversalSwitchEldbus *eldbus, const char * provider_id) +static std::vector __eldbus_getAllSwitchesByProviderId(UniversalSwitchEldbus *eldbus, const char * provider_id) { Eldbus_Message *req = NULL; Eldbus_Message *reply = NULL; Eldbus_Message_Iter *iter = NULL; const char *errname = NULL; const char *errmsg = NULL; - Eina_Array *switches = eina_array_new(EINA_ARRAY_STEPS); if (!(req = eldbus_proxy_method_call_new(eldbus->proxy, "getAllSwitchesByProviderId"))) { SETTING_TRACE_ERROR("Failed to create method call on " IFACE ".getAllSwitchesByProviderId"); - return switches; + return {}; } iter = eldbus_message_iter_get(req); eldbus_message_iter_arguments_append(iter, "s", provider_id); + std::vector switches; reply = eldbus_proxy_send_and_block(eldbus->proxy, req, ELDBUS_TIMEOUT); if (!reply || eldbus_message_error_get(reply, &errname, &errmsg)) SETTING_TRACE_ERROR("Unable to call method " IFACE ".getAllSwitchesByProviderId: %s %s", errname, errmsg); @@ -140,42 +145,34 @@ static Eina_Array * __eldbus_getAllSwitchesByProviderId(UniversalSwitchEldbus *e return switches; } -static Eina_Array * __eldbus_getAllSwitchProviders(UniversalSwitchEldbus *eldbus) +static std::vector __eldbus_getAllSwitchProviders(UniversalSwitchEldbus *eldbus) { Eldbus_Message *req = NULL; Eldbus_Message *reply = NULL; const char *errname = NULL; const char *errmsg = NULL; - Eina_Array *switch_providers = eina_array_new(EINA_ARRAY_STEPS); if (!(req = eldbus_proxy_method_call_new(eldbus->proxy, "getAllSwitchProviders"))) { SETTING_TRACE_ERROR("Failed to create method call on " IFACE ".getAllSwitchProviders"); - return switch_providers; + return {}; } + std::vector switch_providers; reply = eldbus_proxy_send_and_block(eldbus->proxy, req, ELDBUS_TIMEOUT); if (!reply || eldbus_message_error_get(reply, &errname, &errmsg)) { SETTING_TRACE_ERROR("Unable to call method " IFACE ".getAllSwitchProviders: %s %s", errname, errmsg); } else { - Eina_Array *switch_providers_info = eina_array_new(EINA_ARRAY_STEPS); - if (switch_providers_info) { + std::vector switch_providers_info; + if (true) { __eldbus_getInfoArray(switch_providers_info, reply); - Eina_Array_Iterator iterator; - UniversalSwitchSwitchProviderInfoType *provider_info; - unsigned int i; - EINA_ARRAY_ITER_NEXT(switch_providers_info, i, provider_info, iterator, UniversalSwitchSwitchProviderInfoType) { - UniversalSwitchSwitchProvider *switch_provider = (UniversalSwitchSwitchProvider *)calloc(1, sizeof(UniversalSwitchSwitchProvider)); - if (!switch_provider) { - SETTING_TRACE_ERROR("Out of memory"); - break; - } - switch_provider->info = provider_info; - switch_provider->switches = __eldbus_getAllSwitchesByProviderId(eldbus, provider_info->id); - eina_array_push(switch_providers, switch_provider); + for (auto &it : switch_providers_info) { + auto switch_provider = new UniversalSwitchSwitchProvider; + switch_provider->info = it; + switch_provider->switches = __eldbus_getAllSwitchesByProviderId(eldbus, it->id.c_str()); + switch_providers.push_back(switch_provider); } - eina_array_free(switch_providers_info); } else SETTING_TRACE_ERROR("Switch Providers could not be initialized!"); } @@ -187,19 +184,19 @@ static Eina_Array * __eldbus_getAllSwitchProviders(UniversalSwitchEldbus *eldbus } -static Eina_Array * __eldbus_getBindableActivityTypes(UniversalSwitchEldbus *eldbus) +static std::vector __eldbus_getBindableActivityTypes(UniversalSwitchEldbus *eldbus) { Eldbus_Message *req = NULL; Eldbus_Message *reply = NULL; const char *errname = NULL; const char *errmsg = NULL; - Eina_Array *activity_types = eina_array_new(EINA_ARRAY_STEPS); if (!(req = eldbus_proxy_method_call_new(eldbus->proxy, "getBindableActivityTypes"))) { SETTING_TRACE_ERROR("Failed to create method call on " IFACE ".getBindableActivityTypes"); - return activity_types; + return {}; } + std::vector activity_types; reply = eldbus_proxy_send_and_block(eldbus->proxy, req, ELDBUS_TIMEOUT); if (!reply || eldbus_message_error_get(reply, &errname, &errmsg)) { SETTING_TRACE_ERROR("Unable to call method " IFACE ".getBindableActivityTypes: %s %s", errname, errmsg); @@ -213,7 +210,7 @@ static Eina_Array * __eldbus_getBindableActivityTypes(UniversalSwitchEldbus *eld return activity_types; } -static void __eldbus_getAllSwitchConfigurationItemsArray(Eina_Array *infoTypes, Eldbus_Message *reply) +static void __eldbus_getAllSwitchConfigurationItemsArray(std::vector& infoTypes, Eldbus_Message *reply) { Eldbus_Message_Iter *array; @@ -239,7 +236,7 @@ static void __eldbus_getAllSwitchConfigurationItemsArray(Eina_Array *infoTypes, return; } size_t provider_id_size = pointer_to_end_of_switch_provider_str - switchId; - UniversalSwitchConfigurationItem *item = (UniversalSwitchConfigurationItem *)calloc(1, sizeof(UniversalSwitchConfigurationItem)); + auto item = new UniversalSwitchConfigurationItem; if (!item) { SETTING_TRACE_ERROR("Out of memory"); return; @@ -248,24 +245,24 @@ static void __eldbus_getAllSwitchConfigurationItemsArray(Eina_Array *infoTypes, item->switch_id = strdup(switchId); item->user_name = strdup(userName); item->activity_type = strdup(activityType); - eina_array_push(infoTypes, item); + infoTypes.push_back(item); } } -static Eina_Array * __eldbus_getAllSwitchConfigurationItems(UniversalSwitchEldbus *eldbus) +static std::vector __eldbus_getAllSwitchConfigurationItems(UniversalSwitchEldbus *eldbus) { Eldbus_Message *req = NULL; Eldbus_Message *reply = NULL; const char *errname = NULL; const char *errmsg = NULL; - Eina_Array *configurationItems = eina_array_new(EINA_ARRAY_STEPS); if (!(req = eldbus_proxy_method_call_new(eldbus->proxy, "getAllSwitchConfigurationItems"))) { SETTING_TRACE_ERROR("Failed to create method call on " IFACE ".getAllSwitchConfigurationItems"); - return configurationItems; + return {}; } + std::vector configurationItems; reply = eldbus_proxy_send_and_block(eldbus->proxy, req, ELDBUS_TIMEOUT); if (!reply || eldbus_message_error_get(reply, &errname, &errmsg)) { SETTING_TRACE_ERROR("Unable to call method " IFACE ".getAllSwitchConfigurationItems: %s %s", errname, errmsg); @@ -281,19 +278,11 @@ static Eina_Array * __eldbus_getAllSwitchConfigurationItems(UniversalSwitchEldbu static void __relese_configuration_items(UniversalSwitchDbusConfig *config) { - if (!config->configuration_items) - return; - - while (eina_array_count(config->configuration_items)) { - UniversalSwitchConfigurationItem *item = (UniversalSwitchConfigurationItem *)eina_array_pop(config->configuration_items); - free(item->switch_id); - free(item->user_name); - free(item->activity_type); - free(item->provider_id); - free(item); + for (auto &it : config->configuration_items) { + delete it; } - eina_array_free(config->configuration_items); - config->configuration_items = NULL; + + config->configuration_items = {}; } static void __relese_info_type(UniversalSwitchInfoType *info) @@ -301,48 +290,38 @@ static void __relese_info_type(UniversalSwitchInfoType *info) if (!info) return; - free(info->id); - free(info->name); - free(info->description); - free(info); + delete info; } -static void __relese_info_type_array(Eina_Array *infoArray) +static void __relese_info_type_array(std::vector& infoArray) { - if (!infoArray) - return; - - while (eina_array_count(infoArray)) { - UniversalSwitchInfoType *info = (UniversalSwitchInfoType *)eina_array_pop(infoArray); - __relese_info_type(info); - } - eina_array_free(infoArray); + for (auto &it : infoArray) + delete it; + infoArray = {}; } static void __relese_activity_types(UniversalSwitchDbusConfig *config) { - if (!config->activity_types) + if (config->activity_types.empty()) return; __relese_info_type_array(config->activity_types); - config->activity_types = NULL; + config->activity_types = {}; } static void __relese_switch_providers(UniversalSwitchDbusConfig *config) { - if (!config->switch_providers) + if (config->switch_providers.empty()) return; - while (eina_array_count(config->switch_providers)) { - UniversalSwitchSwitchProvider *switch_provider = (UniversalSwitchSwitchProvider *)eina_array_pop(config->switch_providers); - __relese_info_type(switch_provider->info); - __relese_info_type_array(switch_provider->switches); - free(switch_provider); + for (auto &it : config->switch_providers) { + __relese_info_type(it->info); + __relese_info_type_array(it->switches); + delete it; } - __relese_info_type_array(config->switch_providers); - config->switch_providers = NULL; + config->switch_providers = {}; } static void __update_configuration_items(UniversalSwitchDbusConfig *config) @@ -385,8 +364,6 @@ static void __bus_name_acquired(void *data, const char *bus, const char *old_id, Eina_Bool setting_accessibility_universal_switch_dbus_config_init(UniversalSwitchDbusConfig *config, init_done_cb callback, void *callback_data) { - config->activity_types = NULL; - config->configuration_items = NULL; config->eldbus.init_done_callback = callback; config->eldbus.init_done_callback_data = callback_data; Eina_Bool v = __eldbus_init(config); @@ -396,7 +373,7 @@ Eina_Bool setting_accessibility_universal_switch_dbus_config_init(UniversalSwitc int setting_accessibility_universal_switch_dbus_config_get_switch_count(UniversalSwitchDbusConfig *config) { - return eina_array_count(config->configuration_items); + return config->configuration_items.size(); } void setting_accessibility_universal_switch_dbus_config_addSwitchConfigurationItem(UniversalSwitchDbusConfig *config, const char *switch_id, const char *user_name, const char *activity_type) @@ -428,27 +405,20 @@ void setting_accessibility_universal_switch_dbus_config_shutdown(UniversalSwitch __eldbus_shutdown(config); } -const char * setting_accessibility_universal_switch_dbus_config_get_activity_name(UniversalSwitchDbusConfig *config, const char * activity_id) +std::string setting_accessibility_universal_switch_dbus_config_get_activity_name(UniversalSwitchDbusConfig *config, const std::string& activity_id) { - Eina_Array_Iterator iterator; - UniversalSwitchActivityType *activity; - unsigned int i; - EINA_ARRAY_ITER_NEXT(config->activity_types, i, activity, iterator, UniversalSwitchActivityType) { - if (strcmp(activity->id, activity_id) == 0) - return activity->name; - } - return NULL; + for (auto &it : config->activity_types) + if (it->id == activity_id) + return it->name; + + return {}; } -Eina_Array * setting_accessibility_universal_switch_dbus_config_get_switches(UniversalSwitchDbusConfig *config, const char * provider_id) +std::vector setting_accessibility_universal_switch_dbus_config_get_switches(UniversalSwitchDbusConfig *config, const char * provider_id) { - Eina_Array_Iterator iterator; - UniversalSwitchSwitchProvider *switch_provider; - unsigned int i; - EINA_ARRAY_ITER_NEXT(config->switch_providers, i, switch_provider, iterator, UniversalSwitchSwitchProvider) { - if (strcmp(switch_provider->info->id, provider_id) == 0) - return switch_provider->switches; - } - return NULL; + for (auto &it : config->switch_providers) + if (strcmp(it->info->id.c_str(), provider_id) == 0) + return it->switches; + return {}; } static void __eldbus_on_capture_switch(void *data EINA_UNUSED, const Eldbus_Message *msg, Eldbus_Pending *pending EINA_UNUSED) diff --git a/src/setting-accessibility-universal-switch-dbus.h b/src/setting-accessibility-universal-switch-dbus.h index 8a31086..8da50ab 100644 --- a/src/setting-accessibility-universal-switch-dbus.h +++ b/src/setting-accessibility-universal-switch-dbus.h @@ -25,6 +25,9 @@ #include +#include +#include + typedef void (*capture_switch_cb)(void *data, const char *switch_id); typedef void (*init_done_cb)(void *data); @@ -45,40 +48,35 @@ struct UniversalSwitchEldbus { Eina_Bool is_init; }; -struct _UniversalSwitchInfoType { - char *id; - char *name; - char *description; +struct UniversalSwitchInfoType { + std::string id; + std::string name; + std::string description; }; -typedef struct _UniversalSwitchInfoType UniversalSwitchInfoType; -typedef struct _UniversalSwitchInfoType UniversalSwitchActivityType; -typedef struct _UniversalSwitchInfoType UniversalSwitchSwitchProviderInfoType; -typedef struct _UniversalSwitchInfoType UniversalSwitchSwitchType; - struct UniversalSwitchConfigurationItem { - char *switch_id; - char *user_name; - char *activity_type; - char *provider_id; + std::string switch_id; + std::string user_name; + std::string activity_type; + std::string provider_id; }; struct UniversalSwitchSwitchProvider { - UniversalSwitchSwitchProviderInfoType *info; - Eina_Array *switches; + UniversalSwitchInfoType *info; + std::vector switches; }; struct UniversalSwitchDbusConfig { UniversalSwitchEldbus eldbus; - Eina_Array *activity_types; - Eina_Array *configuration_items; - Eina_Array *switch_providers; + std::vector activity_types; + std::vector configuration_items; + std::vector switch_providers; }; Eina_Bool setting_accessibility_universal_switch_dbus_config_init(UniversalSwitchDbusConfig *config, init_done_cb callback, void *callback_data); int setting_accessibility_universal_switch_dbus_config_get_switch_count(UniversalSwitchDbusConfig *config); -const char * setting_accessibility_universal_switch_dbus_config_get_activity_name(UniversalSwitchDbusConfig *config, const char * activity_id); -Eina_Array * setting_accessibility_universal_switch_dbus_config_get_switches(UniversalSwitchDbusConfig *config, const char * provider_id); +std::string setting_accessibility_universal_switch_dbus_config_get_activity_name(UniversalSwitchDbusConfig *config, const std::string& activity_id); +std::vector setting_accessibility_universal_switch_dbus_config_get_switches(UniversalSwitchDbusConfig *config, const char * provider_id); void setting_accessibility_universal_switch_dbus_config_shutdown(UniversalSwitchDbusConfig *config); void setting_accessibility_universal_switch_dbus_config_addSwitchConfigurationItem(UniversalSwitchDbusConfig *config, const char *switch_id, const char *user_name, const char *activity_type); void setting_accessibility_universal_switch_dbus_config_updateSwitchConfigurationItem(UniversalSwitchDbusConfig *config, const char *switch_id, const char *user_name, const char *activity_type); diff --git a/src/setting-accessibility-universal-switch-remove-switch.cpp b/src/setting-accessibility-universal-switch-remove-switch.cpp index d577143..fdcd374 100644 --- a/src/setting-accessibility-universal-switch-remove-switch.cpp +++ b/src/setting-accessibility-universal-switch-remove-switch.cpp @@ -40,14 +40,13 @@ static void __remove_switch(SettingAccessibility *ad, int item_id) retm_if(ad->us_configuration.switch_removed_cb == NULL, "Remove callback not set"); - if (item_id < 0 || item_id >= (int)eina_array_count(ad->config.configuration_items)) { + if (item_id < 0 || item_id >= ad->config.configuration_items.size()) { SETTING_TRACE_END; return; } - UniversalSwitchConfigurationItem *config_item; - config_item = (UniversalSwitchConfigurationItem *)eina_array_data_get(ad->config.configuration_items, item_id); - SETTING_TRACE_DEBUG("Removing switch, switch_id: %s", config_item->switch_id); + auto config_item = ad->config.configuration_items[item_id]; + SETTING_TRACE_DEBUG("Removing switch, switch_id: %s", config_item->switch_id.c_str()); ad->us_configuration.switch_removed_cb(ad, config_item->switch_id, config_item->activity_type, config_item->user_name); @@ -211,15 +210,10 @@ void setting_accessibility_universal_switch_remove_switch_page_create(SettingAcc elm_layout_content_set(ad->md.getNaviframe(), "title_right_btn", ad->remove_switches_popup_button); elm_object_disabled_set(ad->remove_switches_popup_button, EINA_TRUE); - Eina_Array_Iterator iterator; - UniversalSwitchConfigurationItem *config_item; - unsigned int i; - EINA_ARRAY_ITER_NEXT(ad->config.configuration_items, i, config_item, iterator, UniversalSwitchConfigurationItem) { - const char *activity_name = setting_accessibility_universal_switch_dbus_config_get_activity_name(&ad->config, config_item->activity_type); - setting_accessibility_universal_switch_settings_set_value_remove_switch_item_add(ad, config_item->user_name, activity_name, i, false); + for (auto i = 0u; i < ad->config.configuration_items.size(); ++i) { + auto activity_name = setting_accessibility_universal_switch_dbus_config_get_activity_name(&ad->config, ad->config.configuration_items[i]->activity_type); + setting_accessibility_universal_switch_settings_set_value_remove_switch_item_add(ad, ad->config.configuration_items[i]->user_name, activity_name, i, false); } - - } void setting_accessibility_universal_switch_remove_switch_callback_attach(SettingAccessibility *ad, UniversalSwitchUpdateCb cb) diff --git a/src/setting-accessibility-universal-switch-settings-set-value.cpp b/src/setting-accessibility-universal-switch-settings-set-value.cpp index dc9e40b..08bd5f4 100755 --- a/src/setting-accessibility-universal-switch-settings-set-value.cpp +++ b/src/setting-accessibility-universal-switch-settings-set-value.cpp @@ -537,7 +537,7 @@ static void __gendial_radio_item_selected_cb(void *data, Evas_Object *obj, void } -void setting_accessibility_universal_switch_settings_set_value_radio_item_add(SettingAccessibility *ad, const char *caption, int id, bool selected) +void setting_accessibility_universal_switch_settings_set_value_radio_item_add(SettingAccessibility *ad, const std::string& caption, int id, bool selected) { retm_if(ad == NULL, "Input parameter is NULL"); @@ -545,7 +545,7 @@ void setting_accessibility_universal_switch_settings_set_value_radio_item_add(Se Setting_GenGroupItem_Data *item = setting_create_Gendial_field_def(ad->set_value_layout.getGenlist(), &itc_1text_1icon_3, __gendial_radio_item_selected_cb, NULL, SWALLOW_Type_1RADIO_1TEXT, NULL, NULL, selected ? 0 : -1, - caption, NULL, + caption.c_str(), NULL, __gendial_radio_change_cb); if (item) { @@ -556,8 +556,8 @@ void setting_accessibility_universal_switch_settings_set_value_radio_item_add(Se } -void setting_accessibility_universal_switch_settings_set_value_remove_switch_item_add(SettingAccessibility *ad, const char *caption, - const char *subtext, int id, bool state) +void setting_accessibility_universal_switch_settings_set_value_remove_switch_item_add(SettingAccessibility *ad, const std::string& caption, + const std::string& subtext, int id, bool state) { retm_if(ad == NULL, "Input parameter is NULL"); @@ -565,7 +565,7 @@ void setting_accessibility_universal_switch_settings_set_value_remove_switch_ite Setting_GenGroupItem_Data *item = setting_create_Gendial_field_def(ad->set_value_layout.getGenlist(), &itc_1text_1icon_3, __gendial_remove_item_selected_cb, NULL, SWALLOW_Type_1CHECK, NULL, NULL, (int)state, - caption, subtext, + caption.c_str(), subtext.c_str(), __gendial_remove_item_checkbox_cb); if (item) { @@ -669,21 +669,6 @@ static void __close_update_accessories_switch_page(void *data, Evas_Object *obj, if (event_info == ad->save_object_item) __update_accessories_switch_save_changes(ad); - if (ad->config_item_to_update.switch_id) { - free(ad->config_item_to_update.switch_id); - ad->config_item_to_update.switch_id = NULL; - } - - if (ad->config_item_to_update.activity_type) { - free(ad->config_item_to_update.activity_type); - ad->config_item_to_update.activity_type = NULL; - } - - if (ad->config_item_to_update.user_name) { - free(ad->config_item_to_update.user_name); - ad->config_item_to_update.user_name = NULL; - } - elm_naviframe_item_pop(ad->md.getNaviframe()); } @@ -703,8 +688,7 @@ static void __update_action_gendial_field(SettingAccessibility *ad) static void __update_accessible_switch_choose_action(SettingAccessibility *ad, switch_action_t action, void *user_data) { - free(ad->config_item_to_update.activity_type); - ad->config_item_to_update.activity_type = strdup(action); + ad->config_item_to_update.activity_type = action; __update_action_gendial_field(ad); elm_naviframe_item_pop(ad->md.getNaviframe()); @@ -729,7 +713,7 @@ static void __add_action_gendial_field(SettingAccessibility *ad) __update_accessible_switch_action, ad, SWALLOW_Type_INVALID, NULL, NULL, 0, _(DEVOPTION_STR_ACCESSIBILITY_UNIVERSAL_SWITCH_ACTION), - setting_accessibility_universal_switch_dbus_config_get_activity_name(&ad->config, ad->config_item_to_update.activity_type), + setting_accessibility_universal_switch_dbus_config_get_activity_name(&ad->config, ad->config_item_to_update.activity_type).c_str(), NULL); } @@ -752,7 +736,7 @@ void setting_accessibility_universal_switch_settings_create_update_accesories_sw ad->set_value_layout.setLayout(__create_layout(ad->md.getNaviframe(), GRP_SET_VALUE_UPDATE_ACCESSORIES_SWITCH)); ad->entry = elm_entry_add(ad->set_value_layout.getLayout()); - elm_entry_entry_set(ad->entry, ad->config_item_to_update.user_name); + elm_entry_entry_set(ad->entry, ad->config_item_to_update.user_name.c_str()); elm_entry_cursor_end_set(ad->entry); evas_object_show(ad->entry); elm_object_part_content_set(ad->set_value_layout.getLayout(), PRT_SET_VALUE_ENTRY, ad->entry); diff --git a/src/setting-accessibility-universal-switch-settings-set-value.h b/src/setting-accessibility-universal-switch-settings-set-value.h index 4b5d7d8..83e8d31 100644 --- a/src/setting-accessibility-universal-switch-settings-set-value.h +++ b/src/setting-accessibility-universal-switch-settings-set-value.h @@ -19,9 +19,9 @@ void setting_accessibility_universal_switch_settings_set_value_description_set(S void setting_accessibility_universal_switch_settings_set_value_range_set(SettingAccessibility *ad, double min, double max, double step); void setting_accessibility_universal_switch_settings_set_value_value_set(SettingAccessibility *ad, double value, const char *units); void setting_accessibility_universal_switch_settings_set_value_switch_set(SettingAccessibility *ad, bool state); -void setting_accessibility_universal_switch_settings_set_value_radio_item_add(SettingAccessibility *ad, const char *caption, int id, bool selected); +void setting_accessibility_universal_switch_settings_set_value_radio_item_add(SettingAccessibility *ad, const std::string& caption, int id, bool selected); void setting_accessibility_universal_switch_settings_set_value_switch_item_add(SettingAccessibility *ad, const char *caption, const char *sub_desc, int id, bool state, setting_call_back_func gl_sel); -void setting_accessibility_universal_switch_settings_set_value_remove_switch_item_add(SettingAccessibility *ad, const char *caption, const char *subtext, int id, bool state); +void setting_accessibility_universal_switch_settings_set_value_remove_switch_item_add(SettingAccessibility *ad, const std::string& caption, const std::string& subtext, int id, bool state); Setting_GenGroupItem_Data* setting_accessibility_universal_switch_settings_set_value_radio_list_item_add(SettingAccessibility *ad, const char *main_text, const char *sub_text, int option_id); void setting_accessibility_universal_switch_settings_set_value_add_value_change_cb(SettingAccessibility *ad, changeValueCb cb); void setting_accessibility_universal_switch_settings_set_value_add_switch_change_cb(SettingAccessibility *ad, changeSwitchCb cb); diff --git a/src/setting-accessibility-universal-switch-switches.cpp b/src/setting-accessibility-universal-switch-switches.cpp index d179743..ba1faf7 100644 --- a/src/setting-accessibility-universal-switch-switches.cpp +++ b/src/setting-accessibility-universal-switch-switches.cpp @@ -61,8 +61,8 @@ static Eina_Bool __naviframe_pop_cb(void *data, Elm_Object_Item *it) return EINA_TRUE; } -static Setting_GenGroupItem_Data *__add_mapped_switch_menu_item(SettingAccessibility *ad, Evas_Object *genlist, const char *main_text, - const char *sub_text, setting_call_back_func item_cb, void *user_data) +static Setting_GenGroupItem_Data *__add_mapped_switch_menu_item(SettingAccessibility *ad, Evas_Object *genlist, const std::string& main_text, + const std::string& sub_text, setting_call_back_func item_cb, void *user_data) { retvm_if(ad == NULL, NULL, "Input argument is NULL"); @@ -72,7 +72,7 @@ static Setting_GenGroupItem_Data *__add_mapped_switch_menu_item(SettingAccessibi item = (Setting_GenGroupItem_Data *)setting_create_Gendial_field_def(genlist, &itc_2text_1icon_3, item_cb, ad, SWALLOW_Type_INVALID, NULL, NULL, 0, - main_text, sub_text, + main_text.c_str(), sub_text.c_str(), NULL); if (item) @@ -171,16 +171,11 @@ static void __create_switches_group(SettingAccessibility *ad, Evas_Object *genli retm_if(ad == NULL, "Input argument is NULL"); - Eina_Array_Iterator iterator; - UniversalSwitchConfigurationItem *config_item; - unsigned int i; - EINA_ARRAY_ITER_NEXT(ad->config.configuration_items, i, config_item, iterator, UniversalSwitchConfigurationItem) { - SETTING_TRACE_DEBUG("Switch: %d. switch_id: %s, provider_id: %s, user_name: %s, activity_type: %s.", i, config_item->switch_id, config_item->provider_id, config_item->user_name, config_item->activity_type); - const char * activity_name = setting_accessibility_universal_switch_dbus_config_get_activity_name(&ad->config, config_item->activity_type); - __add_mapped_switch_menu_item(ad, genlist, config_item->user_name, activity_name, __switch_click_cb, config_item); + for (auto &it : ad->config.configuration_items) { + auto activity_name = setting_accessibility_universal_switch_dbus_config_get_activity_name(&ad->config, it->activity_type); + __add_mapped_switch_menu_item(ad, genlist, it->user_name, activity_name, __switch_click_cb, it); } - } static void __create_add_switch_button_in_genlist(SettingAccessibility *ad, Evas_Object *genlist) @@ -209,7 +204,7 @@ static void __update_switches_list(SettingAccessibility *ad, Evas_Object *genlis elm_genlist_clear(genlist); __create_switches_group(ad, genlist); __create_add_switch_button_in_genlist(ad, genlist); - elm_object_disabled_set(ad->remove_switches_page_button, eina_array_count_get(ad->config.configuration_items) == 0); + elm_object_disabled_set(ad->remove_switches_page_button, ad->config.configuration_items.size() == 0); } diff --git a/src/setting-accessibility-universal-switch-update-switch.cpp b/src/setting-accessibility-universal-switch-update-switch.cpp index db0e580..6c5b3b0 100644 --- a/src/setting-accessibility-universal-switch-update-switch.cpp +++ b/src/setting-accessibility-universal-switch-update-switch.cpp @@ -40,12 +40,12 @@ void setting_accessibility_universal_switch_update_switch_page_create(SettingAcc retm_if(ad == NULL, "Input parameter is NULL"); - if (strlen(config_item->provider_id) == strlen(ACCESSIBILITY_UNIVERSAL_SWITCH_ACCESSORIES_SWITCH_PROVIDER) - && !strncmp(config_item->provider_id, ACCESSIBILITY_UNIVERSAL_SWITCH_ACCESSORIES_SWITCH_PROVIDER, strlen(ACCESSIBILITY_UNIVERSAL_SWITCH_ACCESSORIES_SWITCH_PROVIDER)) != 0) { + if (strlen(config_item->provider_id.c_str()) == strlen(ACCESSIBILITY_UNIVERSAL_SWITCH_ACCESSORIES_SWITCH_PROVIDER) + && !strncmp(config_item->provider_id.c_str(), ACCESSIBILITY_UNIVERSAL_SWITCH_ACCESSORIES_SWITCH_PROVIDER, strlen(ACCESSIBILITY_UNIVERSAL_SWITCH_ACCESSORIES_SWITCH_PROVIDER)) != 0) { - ad->config_item_to_update.activity_type = strdup(config_item->activity_type); - ad->config_item_to_update.switch_id = strdup(config_item->switch_id); - ad->config_item_to_update.user_name = strdup(config_item->user_name); + ad->config_item_to_update.activity_type = config_item->activity_type; + ad->config_item_to_update.switch_id = config_item->switch_id; + ad->config_item_to_update.user_name = config_item->user_name; setting_accessibility_universal_switch_settings_create_update_accesories_switch_page(ad); } else { setting_accessibility_universal_switch_action_page_create(ad); diff --git a/src/setting-accessibility.h b/src/setting-accessibility.h index 8de5ec8..c470409 100755 --- a/src/setting-accessibility.h +++ b/src/setting-accessibility.h @@ -220,7 +220,7 @@ typedef enum {MANAGE_GESTURES, MANAGE_ACTIONS, MANAGE_SETTINGS, MANAGE_RECENT_APPS, MANAGE_HOME_SCREEN, MANAGE_BACK, MANAGE_BUTTONS_AND_KEYS, MANAGE_CONTEXTUAL_MENU} manage_options_type_t; -typedef const char * switch_action_t; +typedef const std::string& switch_action_t; struct SettingAccessibility; @@ -295,23 +295,4 @@ struct SettingAccessibility { extern setting_view setting_view_accessibility_main; -#ifdef EINA_ARRAY_ITER_NEXT -#undef EINA_ARRAY_ITER_NEXT -#define EINA_ARRAY_ITER_NEXT(array, index, item, iterator, type) \ - for (index = 0, iterator = (array)->data; \ - (index < eina_array_count(array)) && ((item = (type*)*((iterator)++))); \ - ++(index)) -#endif - -#ifdef EINA_LIST_FREE -#undef EINA_LIST_FREE -#define EINA_LIST_FREE(list, data, type) \ - for (data = (type *)eina_list_data_get(list), \ - list ? EINA_PREFETCH(((Eina_List *)list)->next) : EINA_PREFETCH(list); \ - list; \ - list = eina_list_remove_list(list, list), \ - list ? EINA_PREFETCH(((Eina_List *)list)->next) : EINA_PREFETCH(list), \ - data = (type *)eina_list_data_get(list)) -#endif - #endif /*__SETTING_ACCESSIBILITY_H__ */ -- 2.7.4 From 0d5ce4b5ded1720e190daceb46805105e820de70 Mon Sep 17 00:00:00 2001 From: Lukasz Wlazly Date: Fri, 28 Sep 2018 13:36:35 +0200 Subject: [PATCH 02/16] [Cpp refactor] Remove needless dependencies Change-Id: I83caf73b87137a47a5b83274ab89baef92ef425e --- CMakeLists.txt | 4 ---- packaging/org.tizen.accessibility-setting.spec | 5 ----- src/setting-common-general-func.cpp | 2 -- 3 files changed, 11 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 9efb373..241c2cf 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -28,13 +28,9 @@ pkg_check_modules(pkgs REQUIRED glib-2.0 capi-system-info capi-system-system-settings - pkgmgr-info - libxml-2.0 tts tts-setting notification - json-glib-1.0 - openssl ) FOREACH(flag ${pkgs_CFLAGS}) diff --git a/packaging/org.tizen.accessibility-setting.spec b/packaging/org.tizen.accessibility-setting.spec index 23d587e..97c4543 100644 --- a/packaging/org.tizen.accessibility-setting.spec +++ b/packaging/org.tizen.accessibility-setting.spec @@ -21,15 +21,10 @@ BuildRequires: pkgconfig(capi-appfw-preference) BuildRequires: pkgconfig(tts) BuildRequires: pkgconfig(tts-setting) BuildRequires: pkgconfig(glib-2.0) -BuildRequires: pkgconfig(libxml-2.0) BuildRequires: pkgconfig(capi-system-info) BuildRequires: pkgconfig(capi-system-system-settings) -BuildRequires: pkgconfig(pkgmgr-info) BuildRequires: pkgconfig(tts-setting) BuildRequires: pkgconfig(notification) -BuildRequires: pkgconfig(json-glib-1.0) -BuildRequires: pkgconfig(openssl) -BuildRequires: gdb %description Accessibility setting application. diff --git a/src/setting-common-general-func.cpp b/src/setting-common-general-func.cpp index 08460de..74e70ba 100755 --- a/src/setting-common-general-func.cpp +++ b/src/setting-common-general-func.cpp @@ -21,10 +21,8 @@ #include "setting-common-general-func.h" -#include #include #include -#include #include /*remove sub string from a parent string */ -- 2.7.4 From ba3470068da31f4660994c1344f07b63fcbdb997 Mon Sep 17 00:00:00 2001 From: Lukasz Wlazly Date: Mon, 1 Oct 2018 09:28:41 +0200 Subject: [PATCH 03/16] [Cpp refactor] Add GenGroupItemData class This patch remove needless class members Change-Id: I941468dc8b8bc5322f41dd554e426b9098dbdaf1 --- src/GenGroupItemData.hpp | 89 ++++ src/MainData.cpp | 5 +- ...etting-accessibility-accessibility-launcher.cpp | 30 +- src/setting-accessibility-main.cpp | 16 +- ...etting-accessibility-screen-reader-settings.cpp | 63 ++- src/setting-accessibility-screen-reader.cpp | 16 +- ...sibility-universal-switch-add-switch-camera.cpp | 6 +- ...g-accessibility-universal-switch-add-switch.cpp | 4 +- ...ccessibility-universal-switch-remove-switch.cpp | 4 +- ...ibility-universal-switch-settings-set-value.cpp | 36 +- ...ssibility-universal-switch-settings-set-value.h | 4 +- ...ing-accessibility-universal-switch-settings.cpp | 129 ++---- ...ing-accessibility-universal-switch-switches.cpp | 16 +- src/setting-accessibility-universal-switch.cpp | 11 +- src/setting-accessibility.cpp | 22 +- src/setting-accessibility.h | 70 +-- src/setting-common-data-type.h | 165 +------ src/setting-common-draw-genlist.cpp | 502 ++++++--------------- src/setting-common-draw-popup.cpp | 10 +- src/setting-common-draw-widget.cpp | 152 +------ src/setting-common-draw-widget.h | 52 +-- src/setting-common-general-func.cpp | 19 - src/setting-common-general-func.h | 1 - 23 files changed, 452 insertions(+), 970 deletions(-) create mode 100644 src/GenGroupItemData.hpp diff --git a/src/GenGroupItemData.hpp b/src/GenGroupItemData.hpp new file mode 100644 index 0000000..eb2b239 --- /dev/null +++ b/src/GenGroupItemData.hpp @@ -0,0 +1,89 @@ +#ifndef GEN_GROUP_ITEM_DATA_HPP +#define GEN_GROUP_ITEM_DATA_HPP + +#include + +enum class SwallowType : int { + INVALID = -1, + ICON_RADIO = 2, + CHECK = 3, + CHECK_RIGHT = 4, + CHECKICON = 5, + RADIO = 6, + TOGGLE = 7, + CHECK_RIGHT_INVISIBLE, + ICON_DOTTOOGLE, + ICON_SMALL_ICON, + ICON_IMAGE, + GIF, + BUTTON, + RADIO_RIGHT_PROPAGATE_EVENTS_SET, + RADIO_RIGHT, + RADIO_1BTN, + RADIO_1TEXT, + LINE_LAYOUT, + LAYOUT_EDITFIELD, + LAYOUT_SIMPLE_PASSWORD, /* for simple password */ + LAYOUT_DATEFIELD, + LAYOUT_SLIDER, + LAYOUT_5STEP_SLIDER, + LAYOUT_SPECIALIZTION, + LAYOUT_SPECIALIZTION_X,/*extension */ + + MAX +}; + +using SettingCallback = void (*)(void*, Evas_Object*, void*); + +/** + * an item node in genlist + * @todo begings_to is requried? + */ +class GenGroupItemData { +public: + void **pBack = nullptr; + Evas_Object *window = nullptr; + Evas *evas = nullptr; + + Elm_Object_Item *item = nullptr; + + SwallowType swallow_type; + std::string l_swallow_path; /**< left image */ + std::string r_swallow_path; /**< right image */ + + /* output */ + /**< slider, button, check, editfield, datefield */ + Evas_Object *eo_check = nullptr; + /**< represent check value, slider value, datefield value etc.. */ + int chk_status; + int chk_id; + SettingCallback chk_change_cb; + + /* radio button */ + /**< radio button */ + Evas_Object *rgd = nullptr; + + std::string keyStr; /**< title */ + std::string sub_desc; /**< sub text */ + + /* for input panel */ + /**< input panel type */ + Elm_Input_Panel_Layout input_type; + /** the return key type in input method panel*/ + Elm_Input_Panel_Return_Key_Type return_key_type; + bool input_panel_disable_flag; + /** do not autocapital the first char in edit field*/ + int disable_auto_cap; + + void *userdata = nullptr; /**< just a reference, do not need release. */ + + /* popup */ + Evas_Object *notify = nullptr; /**< act as any popup to show user any message */ + + /*record itc style for all genlist item with check/radio/toggle */ + std::string itc; + +private: +}; + +#endif diff --git a/src/MainData.cpp b/src/MainData.cpp index 8c77d10..d40795d 100644 --- a/src/MainData.cpp +++ b/src/MainData.cpp @@ -138,9 +138,6 @@ void MainData::onAllGenlistRealizedCb(void *data, Evas_Object *obj, void *event_ __gl_realized_cb(data, obj, event_info); setting_retm_if(event_info == NULL, "invalid parameter: event_info is NULL"); Elm_Object_Item *item = (Elm_Object_Item *)event_info; - Setting_GenGroupItem_Data *item_data = (Setting_GenGroupItem_Data *)elm_object_item_data_get(item); + GenGroupItemData *item_data = (GenGroupItemData *)elm_object_item_data_get(item); ret_if(!item_data); - - if (item_data->isPlaying) - elm_object_item_signal_emit(item_data->item, "elm,state,expanded", "elm"); } diff --git a/src/setting-accessibility-accessibility-launcher.cpp b/src/setting-accessibility-accessibility-launcher.cpp index 7e4f8f3..9ecf677 100644 --- a/src/setting-accessibility-accessibility-launcher.cpp +++ b/src/setting-accessibility-accessibility-launcher.cpp @@ -29,7 +29,7 @@ struct __Item_Wrapper{ char name[NAME_MAX_LENGTH]; - Setting_GenGroupItem_Data *item; + GenGroupItemData *item; }; static Eina_Bool __naviframe_pop_cb(void *data, Elm_Object_Item *it) @@ -65,7 +65,7 @@ static void __accessibility_launcher_item_checkbox_cb(void *data, Evas_Object *o { retm_if(data == NULL, "Input parameter is NULL"); - Setting_GenGroupItem_Data *list_item = (Setting_GenGroupItem_Data *)data; + GenGroupItemData *list_item = (GenGroupItemData *)data; list_item->chk_status = !list_item->chk_status; __update_vconf((__Item_Wrapper*)list_item->userdata); @@ -77,28 +77,26 @@ static void __accessibility_launcher_item_selected(void *data, Evas_Object *obj, retm_if(event_info == NULL, "Invalid argument: event_info is NULL"); Elm_Object_Item *item = (Elm_Object_Item *)event_info; elm_genlist_item_selected_set(item, EINA_FALSE); - Setting_GenGroupItem_Data *list_item = (Setting_GenGroupItem_Data *)elm_object_item_data_get(item); + GenGroupItemData *list_item = (GenGroupItemData *)elm_object_item_data_get(item); setting_update_gl_item_chk_status(list_item, list_item->chk_status ? 0 : 1); __update_vconf((__Item_Wrapper*)list_item->userdata); } -static void __accessibility_launcher_state_update_name(Setting_GenGroupItem_Data *item) +static void __accessibility_launcher_state_update_name(GenGroupItemData *item) { - char *item_label = item->chk_status ? - _(DEVOPTION_STR_ACCESSIBILITY_ACCESSIBILITY_LAUNCHER_ON) : _(DEVOPTION_STR_ACCESSIBILITY_ACCESSIBILITY_LAUNCHER_OFF); + char *item_label = item->chk_status ? _(DEVOPTION_STR_ACCESSIBILITY_ACCESSIBILITY_LAUNCHER_ON) : _(DEVOPTION_STR_ACCESSIBILITY_ACCESSIBILITY_LAUNCHER_OFF); if (item_label && strlen(item_label) > 0) { - free(item->keyStr); - item->keyStr = strdup(item_label); + item->keyStr = item_label; } elm_genlist_item_update(item->item); } -static void __updete_main_switch(Setting_GenGroupItem_Data *list_item) +static void __updete_main_switch(GenGroupItemData *list_item) { retm_if(list_item == NULL, "Data parameter is NULL"); @@ -116,7 +114,7 @@ static void __accessibility_launcher_checkbox_cb(void *data, Evas_Object *obj, v { retm_if(data == NULL, "Data parameter is NULL"); - Setting_GenGroupItem_Data *list_item = (Setting_GenGroupItem_Data *)data; + GenGroupItemData *list_item = (GenGroupItemData *)data; list_item->chk_status = !list_item->chk_status; __updete_main_switch(list_item); @@ -128,7 +126,7 @@ static void __accessibility_launcher_off_mouse_up_Gendial_list_cb(void *data, Ev retm_if(data == NULL, "Invalid argument: data is NULL"); Elm_Object_Item *item = (Elm_Object_Item *)event_info; elm_genlist_item_selected_set(item, EINA_FALSE); - Setting_GenGroupItem_Data *list_item = (Setting_GenGroupItem_Data *)elm_object_item_data_get(item); + GenGroupItemData *list_item = (GenGroupItemData *)elm_object_item_data_get(item); setting_update_gl_item_chk_status(list_item, list_item->chk_status ? 0 : 1); __updete_main_switch(list_item); @@ -146,7 +144,7 @@ void setting_accessibility_accessibility_launcher_page_create(SettingAccessibili int ret; int state = 0; - Setting_GenGroupItem_Data *item = NULL; + GenGroupItemData *item = NULL; Evas_Object *genlist = elm_genlist_add(ad->md.getNaviframe()); if (genlist == NULL) { SETTING_TRACE_ERROR("Cannot set genlist object as content of layout"); @@ -166,7 +164,7 @@ void setting_accessibility_accessibility_launcher_page_create(SettingAccessibili item = setting_create_Gendial_field_def( genlist, &itc_1text_1icon, __accessibility_launcher_off_mouse_up_Gendial_list_cb, - items, SWALLOW_Type_1ICON_1RADIO, NULL, + items, SwallowType::ICON_RADIO, NULL, NULL, state, state ? _(DEVOPTION_STR_ACCESSIBILITY_ACCESSIBILITY_LAUNCHER_ON) : _(DEVOPTION_STR_ACCESSIBILITY_ACCESSIBILITY_LAUNCHER_OFF), NULL, __accessibility_launcher_checkbox_cb); @@ -175,7 +173,7 @@ void setting_accessibility_accessibility_launcher_page_create(SettingAccessibili item = setting_create_Gendial_field_def( genlist, &ad->itc_multiline_sub, - NULL, ad, SWALLOW_Type_INVALID, NULL, + NULL, ad, SwallowType::INVALID, NULL, NULL, 0, NULL, _(DEVOPTION_STR_ACCESSIBILITY_ACCESSIBILITY_LAUNCHER_COMMENT), @@ -192,10 +190,10 @@ void setting_accessibility_accessibility_launcher_page_create(SettingAccessibili } int i; for (i = 0; i < ITEMS_COUNT; i++) { - Setting_GenGroupItem_Data *item = setting_create_Gendial_field_def( + GenGroupItemData *item = setting_create_Gendial_field_def( genlist, &itc_1text_1icon, __accessibility_launcher_item_selected, - ad, SWALLOW_Type_1ICON_1RADIO, NULL, + ad, SwallowType::ICON_RADIO, NULL, NULL, vconf_state & (1 << i), items[i].name, NULL, __accessibility_launcher_item_checkbox_cb); diff --git a/src/setting-accessibility-main.cpp b/src/setting-accessibility-main.cpp index 1f53649..c88c650 100644 --- a/src/setting-accessibility-main.cpp +++ b/src/setting-accessibility-main.cpp @@ -42,12 +42,8 @@ static void setting_accessibility_screen_reader_key_change_vconf_cb( keynode_t *key, void *user_data) { - Setting_GenGroupItem_Data *screen_reader_item = (Setting_GenGroupItem_Data *)user_data; - if (screen_reader_item->sub_desc) - free(screen_reader_item->sub_desc); - screen_reader_item->sub_desc = strdup(vconf_keynode_get_bool(key) ? - _(DEVOPTION_STR_ACCESSIBILITY_SCREEN_READER_ON) : - _(DEVOPTION_STR_ACCESSIBILITY_SCREEN_READER_OFF)); + GenGroupItemData *screen_reader_item = (GenGroupItemData *)user_data; + screen_reader_item->sub_desc = vconf_keynode_get_bool(key) ? _(DEVOPTION_STR_ACCESSIBILITY_SCREEN_READER_ON) : _(DEVOPTION_STR_ACCESSIBILITY_SCREEN_READER_OFF); elm_genlist_item_update(screen_reader_item->item); } @@ -127,7 +123,7 @@ int setting_accessibility_main_generate_genlist(void *data) ad->screen_reader_item = setting_create_Gendial_field_def( scroller, &itc_2text, setting_accessibility_vision_screen_reader_mouse_up_Gendial_list_cb, - ad, SWALLOW_Type_INVALID, NULL, + ad, SwallowType::INVALID, NULL, NULL, 1, _(DEVOPTION_STR_ACCESSIBILITY_SCREENREADER), screen_reader ? _(DEVOPTION_STR_ACCESSIBILITY_SCREEN_READER_ON) : _(DEVOPTION_STR_ACCESSIBILITY_SCREEN_READER_OFF), @@ -140,7 +136,7 @@ int setting_accessibility_main_generate_genlist(void *data) ad->universal_switch_item = setting_create_Gendial_field_def( scroller, &ad->itc_multiline_sub, setting_accessibility_universal_switch_mouse_up_Gendial_list_cb, - ad, SWALLOW_Type_INVALID, NULL, + ad, SwallowType::INVALID, NULL, NULL, 1, _(DEVOPTION_STR_ACCESSIBILITY_UNIVERSAL_SWITCH), _(DEVOPTION_STR_ACCESSIBILITY_UNIVERSAL_SWITCH_HINT), NULL); @@ -149,10 +145,10 @@ int setting_accessibility_main_generate_genlist(void *data) __BACK_POINTER_SET(ad->universal_switch_item); } - Setting_GenGroupItem_Data *item = setting_create_Gendial_field_def( + GenGroupItemData *item = setting_create_Gendial_field_def( scroller, &ad->itc_multiline_sub, setting_accessibility_accessibility_launcher_mouse_up_Gendial_list_cb, - ad, SWALLOW_Type_INVALID, NULL, + ad, SwallowType::INVALID, NULL, NULL, 1, _(DEVOPTION_STR_ACCESSIBILITY_ACCESSIBILITY_LAUNCHER), _(DEVOPTION_STR_ACCESSIBILITY_ACCESSIBILITY_LAUNCHER_HINT), NULL); diff --git a/src/setting-accessibility-screen-reader-settings.cpp b/src/setting-accessibility-screen-reader-settings.cpp index cdcdb2e..27dfe2d 100755 --- a/src/setting-accessibility-screen-reader-settings.cpp +++ b/src/setting-accessibility-screen-reader-settings.cpp @@ -69,9 +69,9 @@ vconf_check_data_s vconf_check_data[] = { .status = NULL } }; -static std::vector items; +static std::vector items; -static Setting_GenGroupItem_Data *speech_rate_list_item = NULL; +static GenGroupItemData *speech_rate_list_item = NULL; static Eina_Bool __page_hide(void *data, Elm_Object_Item *it) { @@ -162,11 +162,9 @@ static void _check_state_changed_cb(void *data, Evas_Object *obj, return; } - Setting_GenGroupItem_Data *item_data = - (Setting_GenGroupItem_Data *)data; + GenGroupItemData *item_data = (GenGroupItemData *)data; item_data->chk_status = elm_check_state_get(obj); - LOGE("Check changed: %s; status: %d, %p", item_data->keyStr, - item_data->chk_status, &item_data->chk_status); + LOGE("Check changed: %s; status: %d, %p", item_data->keyStr.c_str(), item_data->chk_status, &item_data->chk_status); } @@ -201,11 +199,11 @@ static void _list_item_clicked_cb(void *data, Evas_Object *obj, elm_genlist_item_selected_set(item, EINA_FALSE); - Setting_GenGroupItem_Data *list_item = (Setting_GenGroupItem_Data *) + GenGroupItemData *list_item = (GenGroupItemData *) elm_object_item_data_get(item); retm_if(!list_item, "list_item == NULL"); - LOGI("ITEM SELECTED: %s", list_item->keyStr); + LOGI("ITEM SELECTED: %s", list_item->keyStr.c_str()); setting_update_gl_item_chk_status(list_item, !list_item->chk_status); @@ -231,8 +229,7 @@ static void _on_popup_del(void *data, Evas *e, Evas_Object *obj, double s_speed_percent = (((double)speed_val - (double)s_speed_min)/((double)s_speed_max - (double)s_speed_min)) * 100; snprintf(buf, sizeof(buf), "%.0f%%", s_speed_percent); SETTING_TRACE("Updating speed to %s", buf); - G_FREE(speech_rate_list_item->sub_desc); - speech_rate_list_item->sub_desc = (char *)g_strdup(buf); + speech_rate_list_item->sub_desc = buf; elm_genlist_item_update(speech_rate_list_item->item); } @@ -310,8 +307,8 @@ static void __tts_setting_speed_changed_cb(int speed, void *user_data) { SETTING_TRACE("=== Speed changed to (%d)", speed); - Setting_GenGroupItem_Data *speech_rate_item = - (Setting_GenGroupItem_Data *)user_data; + GenGroupItemData *speech_rate_item = + (GenGroupItemData *)user_data; char buf[256]; snprintf(buf, sizeof(buf), "%d", speed); @@ -344,8 +341,8 @@ static void _keyboard_feedback_check_update(void *data, Evas_Object *obj, { retm_if(data == NULL, "Data parameter is NULL"); - Setting_GenGroupItem_Data *list_item = - (Setting_GenGroupItem_Data *)data; + GenGroupItemData *list_item = + (GenGroupItemData *)data; /* for genlist update status */ list_item->chk_status = elm_check_state_get(obj); @@ -361,7 +358,7 @@ static void _keyboard_feedback_mouse_up_Gendial_list_cb( { Elm_Object_Item *item = (Elm_Object_Item *)event_info; - Setting_GenGroupItem_Data *list_item = (Setting_GenGroupItem_Data *) + GenGroupItemData *list_item = (GenGroupItemData *) elm_object_item_data_get(item); elm_genlist_item_selected_set(item, EINA_FALSE); @@ -380,8 +377,8 @@ static void _hints_check_update(void *data, Evas_Object *obj, void *event_info) { retm_if(data == NULL, "Data parameter is NULL"); - Setting_GenGroupItem_Data *list_item = - (Setting_GenGroupItem_Data *)data; + GenGroupItemData *list_item = + (GenGroupItemData *)data; /* for genlist update status */ list_item->chk_status = elm_check_state_get(obj); @@ -397,7 +394,7 @@ static void _hints_mouse_up_Gendial_list_cb( { Elm_Object_Item *item = (Elm_Object_Item *)event_info; - Setting_GenGroupItem_Data *list_item = (Setting_GenGroupItem_Data *) + GenGroupItemData *list_item = (GenGroupItemData *) elm_object_item_data_get(item); elm_genlist_item_selected_set(item, EINA_FALSE); @@ -417,8 +414,8 @@ static void _sound_feedback_check_update(void *data, Evas_Object *obj, { retm_if(data == NULL, "Data parameter is NULL"); - Setting_GenGroupItem_Data *list_item = - (Setting_GenGroupItem_Data *)data; + GenGroupItemData *list_item = + (GenGroupItemData *)data; /* for genlist update status */ list_item->chk_status = elm_check_state_get(obj); @@ -435,7 +432,7 @@ static void _sound_feedback_mouse_up_Gendial_list_cb(void *data, { Elm_Object_Item *item = (Elm_Object_Item *)event_info; - Setting_GenGroupItem_Data *list_item = (Setting_GenGroupItem_Data *) + GenGroupItemData *list_item = (GenGroupItemData *) elm_object_item_data_get(item); elm_genlist_item_selected_set(item, EINA_FALSE); @@ -455,8 +452,8 @@ static void _vibration_feedback_check_update(void *data, Evas_Object *obj, { retm_if(data == NULL, "Data parameter is NULL"); - Setting_GenGroupItem_Data *list_item = - (Setting_GenGroupItem_Data *)data; + GenGroupItemData *list_item = + (GenGroupItemData *)data; /* for genlist update status */ list_item->chk_status = elm_check_state_get(obj); @@ -473,7 +470,7 @@ static void _vibration_feedback_mouse_up_Gendial_list_cb( { Elm_Object_Item *item = (Elm_Object_Item *)event_info; - Setting_GenGroupItem_Data *list_item = (Setting_GenGroupItem_Data *) + GenGroupItemData *list_item = (GenGroupItemData *) elm_object_item_data_get(item); elm_genlist_item_selected_set(item, EINA_FALSE); @@ -493,7 +490,7 @@ static void _status_bar_info_mouse_up_Gendial_list_cb( Evas_Object *popup; Evas_Object *box; Evas_Object *genlist; - Setting_GenGroupItem_Data *screenreader_checkbox = NULL; + GenGroupItemData *screenreader_checkbox = NULL; int i; int size = sizeof(vconf_check_data) / sizeof(vconf_check_data[0]); @@ -526,7 +523,7 @@ static void _status_bar_info_mouse_up_Gendial_list_cb( screenreader_checkbox = setting_create_Gendial_field_def( genlist, &itc_1text_1icon, _list_item_clicked_cb, ad, - SWALLOW_Type_1ICON_1RADIO, NULL, + SwallowType::ICON_RADIO, NULL, NULL, status, _(vconf_check_data[i].label), NULL, _check_state_changed_cb); @@ -611,7 +608,7 @@ void setting_accessibility_screen_reader_settings_page_create( ad->speech_rate_item = setting_create_Gendial_field_def( genlist, &itc_2text, _speech_rate_mouse_up_Gendial_list_cb, - ad, SWALLOW_Type_INVALID, NULL, + ad, SwallowType::INVALID, NULL, NULL, 1, _(DEVOPTION_STR_ACCESSIBILITY_SCREEN_READER_SETTINGS_SPEECH_RATE), buf, @@ -637,7 +634,7 @@ void setting_accessibility_screen_reader_settings_page_create( ad->keyboard_feedback_item = setting_create_Gendial_field_def( genlist, &itc_multiline_2text, _keyboard_feedback_mouse_up_Gendial_list_cb, - ad, SWALLOW_Type_1ICON_1RADIO, NULL, + ad, SwallowType::ICON_RADIO, NULL, NULL, vconf_val ? 1 : 0, _(DEVOPTION_STR_ACCESSIBILITY_SCREEN_READER_SETTINGS_KEYBOARD_FEEDBACK), _(DEVOPTION_STR_ACCESSIBILITY_SCREEN_READER_SETTINGS_KEYBOARD_FEEDBACK_INFO), @@ -661,7 +658,7 @@ void setting_accessibility_screen_reader_settings_page_create( ad->hints_item = setting_create_Gendial_field_def( genlist, &itc_1text_1icon, _hints_mouse_up_Gendial_list_cb, - ad, SWALLOW_Type_1ICON_1RADIO, NULL, + ad, SwallowType::ICON_RADIO, NULL, NULL, vconf_val ? 1 : 0, _(DEVOPTION_STR_ACCESSIBILITY_SCREEN_READER_SETTINGS_HINTS), NULL, @@ -685,7 +682,7 @@ void setting_accessibility_screen_reader_settings_page_create( ad->vibration_feedback_item = setting_create_Gendial_field_def( genlist, &itc_1text_1icon, _vibration_feedback_mouse_up_Gendial_list_cb, - ad, SWALLOW_Type_1ICON_1RADIO, NULL, + ad, SwallowType::ICON_RADIO, NULL, NULL, vconf_val ? 1 : 0, _(DEVOPTION_STR_ACCESSIBILITY_SCREEN_READER_SETTINGS_VIBRATION_FEEDBACK), NULL, @@ -709,7 +706,7 @@ void setting_accessibility_screen_reader_settings_page_create( ad->sound_feedback_item = setting_create_Gendial_field_def( genlist, &itc_1text_1icon, _sound_feedback_mouse_up_Gendial_list_cb, - ad, SWALLOW_Type_1ICON_1RADIO, NULL, + ad, SwallowType::ICON_RADIO, NULL, NULL, vconf_val ? 1 : 0, _(DEVOPTION_STR_ACCESSIBILITY_SCREEN_READER_SETTINGS_SOUND_FEEDBACK), NULL, @@ -724,7 +721,7 @@ void setting_accessibility_screen_reader_settings_page_create( ad->status_bar_information_item = setting_create_Gendial_field_def( genlist, &itc_1text, _status_bar_info_mouse_up_Gendial_list_cb, - ad, SWALLOW_Type_INVALID, NULL, + ad, SwallowType::INVALID, NULL, NULL, 1, _(DEVOPTION_STR_ACCESSIBILITY_SCREEN_READER_SETTINGS_STATUS_BAR_INFORMATION), NULL, @@ -737,7 +734,7 @@ void setting_accessibility_screen_reader_settings_page_create( ad->multiline_status_bar_information_description = setting_create_Gendial_field_def( genlist, &ad->itc_multiline_sub, - NULL, ad, SWALLOW_Type_INVALID, NULL, + NULL, ad, SwallowType::INVALID, NULL, NULL, 0, NULL, _(DEVOPTION_STR_ACCESSIBILITY_SCREEN_READER_SETTINGS_STATUS_BAR_INFORMATION_DESCRIPTION), diff --git a/src/setting-accessibility-screen-reader.cpp b/src/setting-accessibility-screen-reader.cpp index 24b4b71..a6ff51a 100644 --- a/src/setting-accessibility-screen-reader.cpp +++ b/src/setting-accessibility-screen-reader.cpp @@ -28,7 +28,7 @@ static void screen_reader_key_change_vconf_cb(keynode_t *node, void *user_data) { - Setting_GenGroupItem_Data *screenReaderItem = (Setting_GenGroupItem_Data *)user_data; + GenGroupItemData *screenReaderItem = (GenGroupItemData *)user_data; /*SETTING_TRACE_DEBUG("check_status: %i, node->value.i: %i", * screenReaderItem->chk_status, node->value.i); */ /* I don't know why following code does not update check box to @@ -74,8 +74,8 @@ static void setting_accessibility_main_chk_screenreader_cb(void *data, { retm_if(data == NULL, "Data parameter is NULL"); - Setting_GenGroupItem_Data *list_item = - (Setting_GenGroupItem_Data *)data; + GenGroupItemData *list_item = + (GenGroupItemData *)data; /* for genlist update status */ list_item->chk_status = elm_check_state_get(obj); @@ -111,8 +111,8 @@ static void setting_accessibility_screenreader_mouse_up_Gendial_list_cb( elm_genlist_item_selected_set(item, EINA_FALSE); - Setting_GenGroupItem_Data *list_item = - (Setting_GenGroupItem_Data *)elm_object_item_data_get( + GenGroupItemData *list_item = + (GenGroupItemData *)elm_object_item_data_get( item); setting_retm_if(data == NULL, "Data parameter is NULL"); setting_update_gl_item_chk_status(list_item, @@ -136,7 +136,7 @@ void setting_accessibility_screen_reader_page_create( ad->screenreader_checkbox = setting_create_Gendial_field_def( genlist, &itc_1text_1icon, setting_accessibility_screenreader_mouse_up_Gendial_list_cb, - ad, SWALLOW_Type_1ICON_1RADIO, NULL, + ad, SwallowType::ICON_RADIO, NULL, NULL, 1, _(DEVOPTION_STR_ACCESSIBILITY_SCREENREADER), NULL, setting_accessibility_main_chk_screenreader_cb); if (ad->screenreader_checkbox) { @@ -160,7 +160,7 @@ void setting_accessibility_screen_reader_page_create( ad->multiline_screen_reader_comment = setting_create_Gendial_field_def( genlist, &ad->itc_multiline_sub, - NULL, ad, SWALLOW_Type_INVALID, NULL, + NULL, ad, SwallowType::INVALID, NULL, NULL, 0, NULL, _(DEVOPTION_STR_ACCESSIBILITY_SCREEN_READER_DESCRIPTION), @@ -175,7 +175,7 @@ void setting_accessibility_screen_reader_page_create( ad->screen_reader_settings = setting_create_Gendial_field_def( genlist, &itc_1text, setting_accessibility_screenreader_settings_mouse_up_Gendial_list_cb, - ad, SWALLOW_Type_INVALID, NULL, + ad, SwallowType::INVALID, NULL, NULL, 0, DEVOPTION_STR_ACCESSIBILITY_SCREEN_READER_SETTINGS, NULL, NULL); diff --git a/src/setting-accessibility-universal-switch-add-switch-camera.cpp b/src/setting-accessibility-universal-switch-add-switch-camera.cpp index 8090f4f..e1068c0 100755 --- a/src/setting-accessibility-universal-switch-add-switch-camera.cpp +++ b/src/setting-accessibility-universal-switch-add-switch-camera.cpp @@ -67,7 +67,7 @@ static void __add_camera_switch_cb(void *data, Evas_Object *obj, void *event_inf Elm_Object_Item *item = (Elm_Object_Item *)event_info; elm_genlist_item_selected_set(item, EINA_FALSE); - Setting_GenGroupItem_Data *settings_item = (Setting_GenGroupItem_Data *)elm_object_item_data_get(item); + GenGroupItemData *settings_item = (GenGroupItemData *)elm_object_item_data_get(item); SettingAccessibility *ad = (SettingAccessibility *)settings_item->userdata; retm_if(ad == NULL, "Input argument is NULL"); UniversalSwitchInfoType * camera_switch = (UniversalSwitchInfoType *)data; @@ -90,7 +90,7 @@ void setting_accessibility_universal_switch_add_switch_camera_page_create(Settin ad->universal_switch_camera_comment = setting_create_Gendial_field_def( genlist, &ad->itc_multiline_sub, - NULL, ad, SWALLOW_Type_INVALID, NULL, + NULL, ad, SwallowType::INVALID, NULL, NULL, 0, NULL, _(DEVOPTION_STR_ACCESSIBILITY_UNIVERSAL_SWITCH_ADD_SWITCH_CAMERA_COMMENT), @@ -102,7 +102,7 @@ void setting_accessibility_universal_switch_add_switch_camera_page_create(Settin auto switches = setting_accessibility_universal_switch_dbus_config_get_switches(&ad->config, ACCESSIBILITY_UNIVERSAL_SWITCH_CAMERA_SWITCH_PROVIDER); for (auto &it : switches) { auto item = setting_create_Gendial_field_def(genlist, &ad->itc_multiline_sub, __add_camera_switch_cb, it, - SWALLOW_Type_INVALID, NULL, NULL, 0, it->name.c_str(), it->description.c_str(), NULL); + SwallowType::INVALID, NULL, NULL, 0, it->name.c_str(), it->description.c_str(), NULL); if (item) { item->userdata = ad; diff --git a/src/setting-accessibility-universal-switch-add-switch.cpp b/src/setting-accessibility-universal-switch-add-switch.cpp index 1518fe5..891fb10 100755 --- a/src/setting-accessibility-universal-switch-add-switch.cpp +++ b/src/setting-accessibility-universal-switch-add-switch.cpp @@ -70,7 +70,7 @@ static void __add_switch_cb(void *data, Evas_Object *obj, void *event_info) Elm_Object_Item *item = (Elm_Object_Item *)event_info; elm_genlist_item_selected_set(item, EINA_FALSE); - Setting_GenGroupItem_Data *settings_item = (Setting_GenGroupItem_Data *)elm_object_item_data_get(item); + GenGroupItemData *settings_item = (GenGroupItemData *)elm_object_item_data_get(item); SettingAccessibility *ad = (SettingAccessibility *)settings_item->userdata; retm_if(ad == NULL, "Input argument is NULL"); auto providerId = *static_cast(data); @@ -120,7 +120,7 @@ void setting_accessibility_universal_switch_add_switch_page_create(SettingAccess auto item = setting_create_Gendial_field_def( genlist, &ad->itc_multiline_sub, __add_switch_cb, &it->info->id, - SWALLOW_Type_INVALID, NULL, NULL, 0, + SwallowType::INVALID, NULL, NULL, 0, it->info->name.c_str(), it->info->description.c_str(), NULL); diff --git a/src/setting-accessibility-universal-switch-remove-switch.cpp b/src/setting-accessibility-universal-switch-remove-switch.cpp index fdcd374..b220cb1 100644 --- a/src/setting-accessibility-universal-switch-remove-switch.cpp +++ b/src/setting-accessibility-universal-switch-remove-switch.cpp @@ -71,7 +71,7 @@ static void __remove_selected_switches_cb(void *data, Evas_Object *obj, void *ev Elm_Object_Item *item = elm_genlist_last_item_get(ad->set_value_layout.getGenlist()); while (item != NULL) { - Setting_GenGroupItem_Data *list_item = (Setting_GenGroupItem_Data *)elm_object_item_data_get(item); + GenGroupItemData *list_item = (GenGroupItemData *)elm_object_item_data_get(item); item = elm_genlist_item_prev_get(item); if (list_item->chk_status) __remove_switch(ad, list_item->chk_id); @@ -170,7 +170,7 @@ static void __all_button_clicked_cb(void *data, Evas_Object *obj, void *event_in Elm_Object_Item *item = elm_genlist_first_item_get(ad->set_value_layout.getGenlist()); while (item != NULL) { - Setting_GenGroupItem_Data *list_item = (Setting_GenGroupItem_Data *)elm_object_item_data_get(item); + GenGroupItemData *list_item = (GenGroupItemData *)elm_object_item_data_get(item); setting_update_gl_item_chk_status(list_item, !all_selected); item = elm_genlist_item_next_get(item); } diff --git a/src/setting-accessibility-universal-switch-settings-set-value.cpp b/src/setting-accessibility-universal-switch-settings-set-value.cpp index 08bd5f4..3c0a200 100755 --- a/src/setting-accessibility-universal-switch-settings-set-value.cpp +++ b/src/setting-accessibility-universal-switch-settings-set-value.cpp @@ -422,7 +422,7 @@ static void __switch_item_checkbox_cb(void *data, Evas_Object *obj, void *event_ { retm_if(data == NULL, "Input parameter is NULL"); - Setting_GenGroupItem_Data *list_item = (Setting_GenGroupItem_Data *)data; + GenGroupItemData *list_item = (GenGroupItemData *)data; SettingAccessibility *ad = (SettingAccessibility *)list_item->userdata; if (ad->set_value_layout.switch_item_change_cb) { @@ -437,7 +437,7 @@ static void __gendial_remove_item_checkbox_cb(void *data, Evas_Object *obj, void { retm_if(data == NULL, "Input parameter is NULL"); - Setting_GenGroupItem_Data *list_item = (Setting_GenGroupItem_Data *)data; + GenGroupItemData *list_item = (GenGroupItemData *)data; SettingAccessibility *ad = (SettingAccessibility *)list_item->userdata; if (elm_check_state_get(list_item->eo_check)) ad->switches_to_remove_counter++; @@ -457,7 +457,7 @@ static void __gendial_remove_item_selected_cb(void *data, Evas_Object *obj, void elm_genlist_item_selected_set(item, 0); - Setting_GenGroupItem_Data *list_item = (Setting_GenGroupItem_Data *)elm_object_item_data_get(item); + GenGroupItemData *list_item = (GenGroupItemData *)elm_object_item_data_get(item); setting_update_gl_item_chk_status(list_item, list_item->chk_status ? 0 : 1); @@ -474,14 +474,14 @@ static void __gendial_remove_item_selected_cb(void *data, Evas_Object *obj, void } void setting_accessibility_universal_switch_settings_set_value_switch_item_add(SettingAccessibility *ad, const char *caption, const char *sub_desc, - int id, bool state, setting_call_back_func gl_sel) + int id, bool state, SettingCallback gl_sel) { retm_if(ad == NULL, "Input parameter is NULL"); - Setting_GenGroupItem_Data *item = (Setting_GenGroupItem_Data *)setting_create_Gendial_field_def(ad->set_value_layout.getGenlist(), &ad->itc_multiline_sub, + GenGroupItemData *item = (GenGroupItemData *)setting_create_Gendial_field_def(ad->set_value_layout.getGenlist(), &ad->itc_multiline_sub, gl_sel, NULL, - SWALLOW_Type_1ICON_1RADIO, NULL, NULL, (int)state, + SwallowType::ICON_RADIO, NULL, NULL, (int)state, caption, sub_desc, __switch_item_checkbox_cb); @@ -492,7 +492,7 @@ void setting_accessibility_universal_switch_settings_set_value_switch_item_add(S } -static void __call_radio_item_change_cb_and_pop_nf(Setting_GenGroupItem_Data *list_item) +static void __call_radio_item_change_cb_and_pop_nf(GenGroupItemData *list_item) { retm_if(list_item == NULL, "Input parameter is NULL"); @@ -515,7 +515,7 @@ static void __gendial_radio_change_cb(void *data, Evas_Object *obj, void *event_ { retm_if(data == NULL, "Input parameter is NULL"); - Setting_GenGroupItem_Data *list_item = (Setting_GenGroupItem_Data *)data; + GenGroupItemData *list_item = (GenGroupItemData *)data; __call_radio_item_change_cb_and_pop_nf(list_item); } @@ -528,8 +528,8 @@ static void __gendial_radio_item_selected_cb(void *data, Evas_Object *obj, void elm_genlist_item_selected_set(item, 0); - Setting_GenGroupItem_Data *list_item = - (Setting_GenGroupItem_Data *)elm_object_item_data_get(item); + GenGroupItemData *list_item = + (GenGroupItemData *)elm_object_item_data_get(item); if (list_item->chk_status) setting_update_gl_item_chk_status(list_item, 0); @@ -542,9 +542,9 @@ void setting_accessibility_universal_switch_settings_set_value_radio_item_add(Se retm_if(ad == NULL, "Input parameter is NULL"); - Setting_GenGroupItem_Data *item = setting_create_Gendial_field_def(ad->set_value_layout.getGenlist(), &itc_1text_1icon_3, + GenGroupItemData *item = setting_create_Gendial_field_def(ad->set_value_layout.getGenlist(), &itc_1text_1icon_3, __gendial_radio_item_selected_cb, NULL, - SWALLOW_Type_1RADIO_1TEXT, NULL, NULL, selected ? 0 : -1, + SwallowType::RADIO_1TEXT, NULL, NULL, selected ? 0 : -1, caption.c_str(), NULL, __gendial_radio_change_cb); @@ -562,9 +562,9 @@ void setting_accessibility_universal_switch_settings_set_value_remove_switch_ite retm_if(ad == NULL, "Input parameter is NULL"); - Setting_GenGroupItem_Data *item = setting_create_Gendial_field_def(ad->set_value_layout.getGenlist(), &itc_1text_1icon_3, + GenGroupItemData *item = setting_create_Gendial_field_def(ad->set_value_layout.getGenlist(), &itc_1text_1icon_3, __gendial_remove_item_selected_cb, NULL, - SWALLOW_Type_1CHECK, NULL, NULL, (int)state, + SwallowType::CHECK, NULL, NULL, (int)state, caption.c_str(), subtext.c_str(), __gendial_remove_item_checkbox_cb); @@ -576,7 +576,7 @@ void setting_accessibility_universal_switch_settings_set_value_remove_switch_ite } -Setting_GenGroupItem_Data* setting_accessibility_universal_switch_settings_set_value_radio_list_item_add(SettingAccessibility *ad, const char *main_text, const char *sub_text, int option_id) +GenGroupItemData* setting_accessibility_universal_switch_settings_set_value_radio_list_item_add(SettingAccessibility *ad, const char *main_text, const char *sub_text, int option_id) { retvm_if(ad == NULL, NULL, "Input parameter is NULL"); @@ -589,9 +589,9 @@ Setting_GenGroupItem_Data* setting_accessibility_universal_switch_settings_set_v ad->set_value_layout.getOptionsData().push_back(opt_item); - Setting_GenGroupItem_Data *item = setting_create_Gendial_field_def(ad->set_value_layout.getGenlist(), &itc_2text, + GenGroupItemData *item = setting_create_Gendial_field_def(ad->set_value_layout.getGenlist(), &itc_2text, __list_item_click_cb, opt_item, - SWALLOW_Type_INVALID, NULL, NULL, 0, + SwallowType::INVALID, NULL, NULL, 0, main_text, sub_text, NULL); if (item) @@ -711,7 +711,7 @@ static void __add_action_gendial_field(SettingAccessibility *ad) setting_create_Gendial_field_def(ad->update_accessories_action_genlist, &itc_1text, __update_accessible_switch_action, ad, - SWALLOW_Type_INVALID, NULL, NULL, 0, + SwallowType::INVALID, NULL, NULL, 0, _(DEVOPTION_STR_ACCESSIBILITY_UNIVERSAL_SWITCH_ACTION), setting_accessibility_universal_switch_dbus_config_get_activity_name(&ad->config, ad->config_item_to_update.activity_type).c_str(), NULL); diff --git a/src/setting-accessibility-universal-switch-settings-set-value.h b/src/setting-accessibility-universal-switch-settings-set-value.h index 83e8d31..d65ac43 100644 --- a/src/setting-accessibility-universal-switch-settings-set-value.h +++ b/src/setting-accessibility-universal-switch-settings-set-value.h @@ -20,9 +20,9 @@ void setting_accessibility_universal_switch_settings_set_value_range_set(Setting void setting_accessibility_universal_switch_settings_set_value_value_set(SettingAccessibility *ad, double value, const char *units); void setting_accessibility_universal_switch_settings_set_value_switch_set(SettingAccessibility *ad, bool state); void setting_accessibility_universal_switch_settings_set_value_radio_item_add(SettingAccessibility *ad, const std::string& caption, int id, bool selected); -void setting_accessibility_universal_switch_settings_set_value_switch_item_add(SettingAccessibility *ad, const char *caption, const char *sub_desc, int id, bool state, setting_call_back_func gl_sel); +void setting_accessibility_universal_switch_settings_set_value_switch_item_add(SettingAccessibility *ad, const char *caption, const char *sub_desc, int id, bool state, SettingCallback gl_sel); void setting_accessibility_universal_switch_settings_set_value_remove_switch_item_add(SettingAccessibility *ad, const std::string& caption, const std::string& subtext, int id, bool state); -Setting_GenGroupItem_Data* setting_accessibility_universal_switch_settings_set_value_radio_list_item_add(SettingAccessibility *ad, const char *main_text, const char *sub_text, int option_id); +GenGroupItemData* setting_accessibility_universal_switch_settings_set_value_radio_list_item_add(SettingAccessibility *ad, const char *main_text, const char *sub_text, int option_id); void setting_accessibility_universal_switch_settings_set_value_add_value_change_cb(SettingAccessibility *ad, changeValueCb cb); void setting_accessibility_universal_switch_settings_set_value_add_switch_change_cb(SettingAccessibility *ad, changeSwitchCb cb); void setting_accessibility_universal_switch_settings_set_value_add_radio_item_change_cb(SettingAccessibility *ad, changeRadioItemCb cb); diff --git a/src/setting-accessibility-universal-switch-settings.cpp b/src/setting-accessibility-universal-switch-settings.cpp index 3ef72c6..385272a 100755 --- a/src/setting-accessibility-universal-switch-settings.cpp +++ b/src/setting-accessibility-universal-switch-settings.cpp @@ -147,12 +147,12 @@ static void __auto_scan_checkbox_cb(void *data, Evas_Object *obj, void *event_in static void __feedback_sound_checkbox_cb(void *data, Evas_Object *obj, void *event_info); static void __feedback_voice_checkbox_cb(void *data, Evas_Object *obj, void *event_info); -static void __synchronize_checkbox_with_vconf(keynode_t *node, void *user_data, setting_call_back_func cb_func) +static void __synchronize_checkbox_with_vconf(keynode_t *node, void *user_data, SettingCallback cb_func) { retm_if(user_data == NULL, "Data parameter is NULL"); retm_if(node == NULL, "Data parameter is NULL"); - Setting_GenGroupItem_Data *list_item = (Setting_GenGroupItem_Data *)user_data; + GenGroupItemData *list_item = (GenGroupItemData *)user_data; int ret = vconf_keynode_get_bool(node); retm_if(ret < 0, "FAIL: vconf_keynode_get_bool"); if (list_item->chk_status != ret) { @@ -235,7 +235,7 @@ static void __auto_scan_checkbox_cb(void *data, Evas_Object *obj, void *event_in { retm_if(data == NULL, "Data parameter is NULL"); - Setting_GenGroupItem_Data *list_item = (Setting_GenGroupItem_Data *)data; + GenGroupItemData *list_item = (GenGroupItemData *)data; SettingAccessibility *ad = (SettingAccessibility *)list_item->userdata; retm_if(ad == NULL, "View data parameter is NULL"); @@ -260,8 +260,7 @@ static void __ctxpopup_scan_method_click_cb(void *data, Evas_Object *obj, void * if (__update_vconf_value(VCONFKEY_SETAPPL_ACCESSIBILITY_UNIVERSAL_SWITCH_SETTINGS_SCAN_METHOD, NULL, (int *)&scan_method, NULL)) { ad->us_configuration.scan_method = scan_method; - free(ad->universal_switch_scan_method->sub_desc); - ad->universal_switch_scan_method->sub_desc = strdup(__get_scan_method_text(scan_method)); + ad->universal_switch_scan_method->sub_desc = __get_scan_method_text(scan_method); elm_genlist_item_update(ad->universal_switch_scan_method->item); } @@ -281,8 +280,7 @@ static void __ctxpopup_scan_dir_click_cb(void *data, Evas_Object *obj, void *eve if (!__update_vconf_value(VCONFKEY_SETAPPL_ACCESSIBILITY_UNIVERSAL_SWITCH_SETTINGS_SCAN_DIR_HORIZONTAL, NULL, (int *)&scan_dir, NULL)) SETTING_TRACE_ERROR("Only one of vconf keys was successfully set. The scanner may malfunction"); ad->us_configuration.scan_dir = scan_dir; - free(ad->universal_switch_scan_dir->sub_desc); - ad->universal_switch_scan_dir->sub_desc = strdup(__get_scan_direction_text(scan_dir)); + ad->universal_switch_scan_dir->sub_desc = __get_scan_direction_text(scan_dir); elm_genlist_item_update(ad->universal_switch_scan_dir->item); } @@ -301,8 +299,7 @@ static void __auto_scan_interval_changed_cb(SettingAccessibility *ad, double val __update_vconf_value(VCONFKEY_SETAPPL_ACCESSIBILITY_UNIVERSAL_SWITCH_SETTINGS_AUTO_SCAN_INT, NULL, NULL, &value); str = __get_value_unit_text(NULL, &value, _(DEVOPTION_STR_ACCESSIBILITY_UNIVERSAL_SWITCH_SETTINGS_SECONDS), false, NULL); - free(ad->universal_switch_auto_scan_int->sub_desc); - ad->universal_switch_auto_scan_int->sub_desc = strdup(str); + ad->universal_switch_auto_scan_int->sub_desc = str ? str : std::string{}; elm_genlist_item_update(ad->universal_switch_auto_scan_int->item); @@ -335,8 +332,7 @@ static void __scans_num_changed_cb(SettingAccessibility *ad, double value) __update_vconf_value(VCONFKEY_SETAPPL_ACCESSIBILITY_UNIVERSAL_SWITCH_SETTINGS_NUM_OF_SCANS, NULL, &int_value, NULL); str = __get_value_unit_text(&int_value, NULL, NULL, false, NULL); - free(ad->universal_switch_scans_num->sub_desc); - ad->universal_switch_scans_num->sub_desc = strdup(str); + ad->universal_switch_scans_num->sub_desc = str ? str : std::string{}; elm_genlist_item_update(ad->universal_switch_scans_num->item); @@ -409,8 +405,7 @@ static void __scan_speed_changed_cb(SettingAccessibility *ad, double value) __update_vconf_value(VCONFKEY_SETAPPL_ACCESSIBILITY_UNIVERSAL_SWITCH_SETTINGS_SCAN_PT_SPEED, NULL, &int_value, NULL); str = __get_value_unit_text(&int_value, NULL, NULL, false, NULL); - free(ad->universal_switch_scan_speed->sub_desc); - ad->universal_switch_scan_speed->sub_desc = strdup(str); + ad->universal_switch_scan_speed->sub_desc = str ? str : std::string{}; elm_genlist_item_update(ad->universal_switch_scan_speed->item); @@ -436,7 +431,7 @@ static void __pause_on_first_checkbox_cb(void *data, Evas_Object *obj, void *eve { retm_if(data == NULL, "Data parameter is NULL"); - Setting_GenGroupItem_Data *list_item = (Setting_GenGroupItem_Data *)data; + GenGroupItemData *list_item = (GenGroupItemData *)data; SettingAccessibility *ad = (SettingAccessibility *)list_item->userdata; retm_if(ad == NULL, "View data parameter is NULL"); @@ -446,8 +441,7 @@ static void __pause_on_first_checkbox_cb(void *data, Evas_Object *obj, void *eve const char *str = __get_value_unit_text(NULL, &ad->us_configuration.pause_on_first_value, _(DEVOPTION_STR_ACCESSIBILITY_UNIVERSAL_SWITCH_SETTINGS_SECONDS), !ad->us_configuration.pause_on_first_state, _(DEVOPTION_STR_ACCESSIBILITY_UNIVERSAL_SWITCH_SETTINGS_OFF)); - free(ad->universal_switch_pause_on_first->sub_desc); - ad->universal_switch_pause_on_first->sub_desc = strdup(str); + ad->universal_switch_pause_on_first->sub_desc = str ? str : std::string{}; elm_genlist_item_update(ad->universal_switch_pause_on_first->item); __update_vconf_value(VCONFKEY_SETAPPL_ACCESSIBILITY_UNIVERSAL_SWITCH_SETTINGS_PAUSE_ON_FIRST_STATE, (bool *)&list_item->chk_status, NULL, NULL); @@ -467,8 +461,7 @@ static void __pause_on_first_value_changed_cb(SettingAccessibility *ad, double v str = __get_value_unit_text(NULL, &ad->us_configuration.pause_on_first_value, _(DEVOPTION_STR_ACCESSIBILITY_UNIVERSAL_SWITCH_SETTINGS_SECONDS), !ad->us_configuration.pause_on_first_state, _(DEVOPTION_STR_ACCESSIBILITY_UNIVERSAL_SWITCH_SETTINGS_OFF)); - free(ad->universal_switch_pause_on_first->sub_desc); - ad->universal_switch_pause_on_first->sub_desc = strdup(str); + ad->universal_switch_pause_on_first->sub_desc = str ? str : std::string{}; elm_genlist_item_update(ad->universal_switch_pause_on_first->item); @@ -488,8 +481,7 @@ static void __pause_on_first_switch_changed_cb(SettingAccessibility *ad, bool st ad->universal_switch_pause_on_first->chk_status = state; elm_check_state_set(ad->universal_switch_pause_on_first->eo_check, state); - free(ad->universal_switch_pause_on_first->sub_desc); - ad->universal_switch_pause_on_first->sub_desc = strdup(str); + ad->universal_switch_pause_on_first->sub_desc = str ? str : std::string{}; elm_genlist_item_update(ad->universal_switch_pause_on_first->item); @@ -520,7 +512,7 @@ static void __tap_duration_checkbox_cb(void *data, Evas_Object *obj, void *event { retm_if(data == NULL, "Data parameter is NULL"); - Setting_GenGroupItem_Data *list_item = (Setting_GenGroupItem_Data *)data; + GenGroupItemData *list_item = (GenGroupItemData *)data; SettingAccessibility *ad = (SettingAccessibility *)list_item->userdata; retm_if(ad == NULL, "View data parameter is NULL"); @@ -529,8 +521,7 @@ static void __tap_duration_checkbox_cb(void *data, Evas_Object *obj, void *event const char *str = __get_value_unit_text(NULL, &ad->us_configuration.tap_duration_value, _(DEVOPTION_STR_ACCESSIBILITY_UNIVERSAL_SWITCH_SETTINGS_SECONDS), !ad->us_configuration.tap_duration_state, _(DEVOPTION_STR_ACCESSIBILITY_UNIVERSAL_SWITCH_SETTINGS_OFF)); - free(ad->universal_switch_tap_duration->sub_desc); - ad->universal_switch_tap_duration->sub_desc = strdup(str); + ad->universal_switch_tap_duration->sub_desc = str ? str : std::string{}; elm_genlist_item_update(ad->universal_switch_tap_duration->item); __update_vconf_value(VCONFKEY_SETAPPL_ACCESSIBILITY_UNIVERSAL_SWITCH_SETTINGS_TAP_DURATION_STATE, (bool *)&list_item->chk_status, NULL, NULL); @@ -550,8 +541,7 @@ static void __tap_duration_value_changed_cb(SettingAccessibility *ad, double val str = __get_value_unit_text(NULL, &ad->us_configuration.tap_duration_value, _(DEVOPTION_STR_ACCESSIBILITY_UNIVERSAL_SWITCH_SETTINGS_SECONDS), !ad->us_configuration.tap_duration_state, _(DEVOPTION_STR_ACCESSIBILITY_UNIVERSAL_SWITCH_SETTINGS_OFF)); - free(ad->universal_switch_tap_duration->sub_desc); - ad->universal_switch_tap_duration->sub_desc = strdup(str); + ad->universal_switch_tap_duration->sub_desc = str ? str : std::string{}; elm_genlist_item_update(ad->universal_switch_tap_duration->item); @@ -571,8 +561,7 @@ static void __tap_duration_switch_changed_cb(SettingAccessibility *ad, bool stat ad->universal_switch_tap_duration->chk_status = state; elm_check_state_set(ad->universal_switch_tap_duration->eo_check, state); - free(ad->universal_switch_tap_duration->sub_desc); - ad->universal_switch_tap_duration->sub_desc = strdup(str); + ad->universal_switch_tap_duration->sub_desc = str ? str : std::string{}; elm_genlist_item_update(ad->universal_switch_tap_duration->item); @@ -600,7 +589,7 @@ static void __sgl_iaction_int_checkbox_cb(void *data, Evas_Object *obj, void *ev { retm_if(data == NULL, "Data parameter is NULL"); - Setting_GenGroupItem_Data *list_item = (Setting_GenGroupItem_Data *)data; + GenGroupItemData *list_item = (GenGroupItemData *)data; SettingAccessibility *ad = (SettingAccessibility *)list_item->userdata; retm_if(ad == NULL, "View data parameter is NULL"); @@ -609,8 +598,7 @@ static void __sgl_iaction_int_checkbox_cb(void *data, Evas_Object *obj, void *ev const char *str = __get_value_unit_text(NULL, &ad->us_configuration.sgl_iaction_int_value, _(DEVOPTION_STR_ACCESSIBILITY_UNIVERSAL_SWITCH_SETTINGS_SECONDS), !ad->us_configuration.sgl_iaction_int_state, _(DEVOPTION_STR_ACCESSIBILITY_UNIVERSAL_SWITCH_SETTINGS_OFF)); - free(ad->universal_switch_sgl_iaction_int->sub_desc); - ad->universal_switch_sgl_iaction_int->sub_desc = strdup(str); + ad->universal_switch_sgl_iaction_int->sub_desc = str ? str : std::string{}; elm_genlist_item_update(ad->universal_switch_sgl_iaction_int->item); __update_vconf_value(VCONFKEY_SETAPPL_ACCESSIBILITY_UNIVERSAL_SWITCH_SETTINGS_SGL_IACTION_INT_STATE, (bool *)&list_item->chk_status, NULL, NULL); @@ -630,8 +618,7 @@ static void __sgl_iaction_int_value_changed_cb(SettingAccessibility *ad, double str = __get_value_unit_text(NULL, &ad->us_configuration.sgl_iaction_int_value, _(DEVOPTION_STR_ACCESSIBILITY_UNIVERSAL_SWITCH_SETTINGS_SECONDS), !ad->us_configuration.sgl_iaction_int_state, _(DEVOPTION_STR_ACCESSIBILITY_UNIVERSAL_SWITCH_SETTINGS_OFF)); - free(ad->universal_switch_sgl_iaction_int->sub_desc); - ad->universal_switch_sgl_iaction_int->sub_desc = strdup(str); + ad->universal_switch_sgl_iaction_int->sub_desc = str ? str : std::string{}; elm_genlist_item_update(ad->universal_switch_sgl_iaction_int->item); @@ -651,8 +638,7 @@ static void __sgl_iaction_int_switch_changed_cb(SettingAccessibility *ad, bool s ad->universal_switch_sgl_iaction_int->chk_status = state; elm_check_state_set(ad->universal_switch_sgl_iaction_int->eo_check, state); - free(ad->universal_switch_sgl_iaction_int->sub_desc); - ad->universal_switch_sgl_iaction_int->sub_desc = strdup(str); + ad->universal_switch_sgl_iaction_int->sub_desc = str ? str : std::string{}; elm_genlist_item_update(ad->universal_switch_sgl_iaction_int->item); @@ -680,7 +666,7 @@ static void __auto_tap_checkbox_cb(void *data, Evas_Object *obj, void *event_inf { retm_if(data == NULL, "Data parameter is NULL"); - Setting_GenGroupItem_Data *list_item = (Setting_GenGroupItem_Data *)data; + GenGroupItemData *list_item = (GenGroupItemData *)data; SettingAccessibility *ad = (SettingAccessibility *)list_item->userdata; retm_if(ad == NULL, "View data parameter is NULL"); @@ -689,8 +675,7 @@ static void __auto_tap_checkbox_cb(void *data, Evas_Object *obj, void *event_inf const char *str = __get_value_unit_text(NULL, &ad->us_configuration.auto_tap_value, _(DEVOPTION_STR_ACCESSIBILITY_UNIVERSAL_SWITCH_SETTINGS_SECONDS), !ad->us_configuration.auto_tap_state, _(DEVOPTION_STR_ACCESSIBILITY_UNIVERSAL_SWITCH_SETTINGS_OFF)); - free(ad->universal_switch_auto_tap->sub_desc); - ad->universal_switch_auto_tap->sub_desc = strdup(str); + ad->universal_switch_auto_tap->sub_desc = str ? str : std::string{}; elm_genlist_item_update(ad->universal_switch_auto_tap->item); __update_vconf_value(VCONFKEY_SETAPPL_ACCESSIBILITY_UNIVERSAL_SWITCH_SETTINGS_AUTO_TAP_STATE, (bool *)&list_item->chk_status, NULL, NULL); @@ -710,8 +695,7 @@ static void __auto_tap_value_changed_cb(SettingAccessibility *ad, double value) str = __get_value_unit_text(NULL, &ad->us_configuration.auto_tap_value, _(DEVOPTION_STR_ACCESSIBILITY_UNIVERSAL_SWITCH_SETTINGS_SECONDS), !ad->us_configuration.auto_tap_state, _(DEVOPTION_STR_ACCESSIBILITY_UNIVERSAL_SWITCH_SETTINGS_OFF)); - free(ad->universal_switch_auto_tap->sub_desc); - ad->universal_switch_auto_tap->sub_desc = strdup(str); + ad->universal_switch_auto_tap->sub_desc = str ? str : std::string{}; elm_genlist_item_update(ad->universal_switch_auto_tap->item); @@ -731,8 +715,7 @@ static void __auto_tap_switch_changed_cb(SettingAccessibility *ad, bool state) ad->universal_switch_auto_tap->chk_status = state; elm_check_state_set(ad->universal_switch_auto_tap->eo_check, state); - free(ad->universal_switch_auto_tap->sub_desc); - ad->universal_switch_auto_tap->sub_desc = strdup(str); + ad->universal_switch_auto_tap->sub_desc = str ? str : std::string{}; elm_genlist_item_update(ad->universal_switch_auto_tap->item); @@ -760,7 +743,7 @@ static void __auto_move_interval_checkbox_cb(void *data, Evas_Object *obj, void { retm_if(data == NULL, "Data parameter is NULL"); - Setting_GenGroupItem_Data *list_item = (Setting_GenGroupItem_Data *)data; + GenGroupItemData *list_item = (GenGroupItemData *)data; SettingAccessibility *ad = (SettingAccessibility *)list_item->userdata; retm_if(ad == NULL, "View data parameter is NULL"); @@ -769,8 +752,7 @@ static void __auto_move_interval_checkbox_cb(void *data, Evas_Object *obj, void const char *str = __get_value_unit_text(NULL, &ad->us_configuration.auto_move_int_value, _(DEVOPTION_STR_ACCESSIBILITY_UNIVERSAL_SWITCH_SETTINGS_SECONDS), !ad->us_configuration.auto_move_int_state, _(DEVOPTION_STR_ACCESSIBILITY_UNIVERSAL_SWITCH_SETTINGS_OFF)); - free(ad->universal_switch_auto_move_int->sub_desc); - ad->universal_switch_auto_move_int->sub_desc = strdup(str); + ad->universal_switch_auto_move_int->sub_desc = str ? str : std::string{}; elm_genlist_item_update(ad->universal_switch_auto_move_int->item); __update_vconf_value(VCONFKEY_SETAPPL_ACCESSIBILITY_UNIVERSAL_SWITCH_SETTINGS_AUTO_MOVE_INT_STATE, (bool *)&list_item->chk_status, NULL, NULL); @@ -790,8 +772,7 @@ static void __auto_move_int_value_changed_cb(SettingAccessibility *ad, double va str = __get_value_unit_text(NULL, &ad->us_configuration.auto_move_int_value, _(DEVOPTION_STR_ACCESSIBILITY_UNIVERSAL_SWITCH_SETTINGS_SECONDS), !ad->us_configuration.auto_move_int_state, _(DEVOPTION_STR_ACCESSIBILITY_UNIVERSAL_SWITCH_SETTINGS_OFF)); - free(ad->universal_switch_auto_move_int->sub_desc); - ad->universal_switch_auto_move_int->sub_desc = strdup(str); + ad->universal_switch_auto_move_int->sub_desc = str ? str : std::string{}; elm_genlist_item_update(ad->universal_switch_auto_move_int->item); @@ -811,8 +792,7 @@ static void __auto_move_int_switch_changed_cb(SettingAccessibility *ad, bool sta ad->universal_switch_auto_move_int->chk_status = state; elm_check_state_set(ad->universal_switch_auto_move_int->eo_check, state); - free(ad->universal_switch_auto_move_int->sub_desc); - ad->universal_switch_auto_move_int->sub_desc = strdup(str); + ad->universal_switch_auto_move_int->sub_desc = str ? str : std::string{}; elm_genlist_item_update(ad->universal_switch_auto_move_int->item); @@ -840,7 +820,7 @@ static void __auto_tap_kbd_checkbox_cb(void *data, Evas_Object *obj, void *event { retm_if(data == NULL, "Data parameter is NULL"); - Setting_GenGroupItem_Data *list_item = (Setting_GenGroupItem_Data *)data; + GenGroupItemData *list_item = (GenGroupItemData *)data; SettingAccessibility *ad = (SettingAccessibility *)list_item->userdata; retm_if(ad == NULL, "View data parameter is NULL"); @@ -861,8 +841,7 @@ static void __cursor_color_list_item_changed_cb(SettingAccessibility *ad, int it ad->us_configuration.cursor_color = _cursor_color[item_id].id; __update_vconf_value(VCONFKEY_SETAPPL_ACCESSIBILITY_UNIVERSAL_SWITCH_SETTINGS_FEEDBACK_CURSOR_COLOR, NULL, &ad->us_configuration.cursor_color, NULL); - free(ad->universal_switch_feedback_cursor_cl->sub_desc); - ad->universal_switch_feedback_cursor_cl->sub_desc = strdup(_cursor_color[item_id].key); + ad->universal_switch_feedback_cursor_cl->sub_desc = _cursor_color[item_id].key ? _cursor_color[item_id].key : std::string{}; elm_genlist_item_update(ad->universal_switch_feedback_cursor_cl->item); @@ -890,7 +869,7 @@ static void __feedback_sound_checkbox_cb(void *data, Evas_Object *obj, void *eve { retm_if(data == NULL, "Data parameter is NULL"); - Setting_GenGroupItem_Data *list_item = (Setting_GenGroupItem_Data *)data; + GenGroupItemData *list_item = (GenGroupItemData *)data; SettingAccessibility *ad = (SettingAccessibility *)list_item->userdata; list_item->chk_status = elm_check_state_get(obj); @@ -900,8 +879,7 @@ static void __feedback_sound_checkbox_cb(void *data, Evas_Object *obj, void *eve const char *str = __get_boolean_text(ad->us_configuration.feedback_sound_state, _(DEVOPTION_STR_ACCESSIBILITY_UNIVERSAL_SWITCH_SETTINGS_ON), _(DEVOPTION_STR_ACCESSIBILITY_UNIVERSAL_SWITCH_SETTINGS_OFF)); - free(ad->universal_switch_feedback_sound->sub_desc); - ad->universal_switch_feedback_sound->sub_desc = strdup(str); + ad->universal_switch_feedback_sound->sub_desc = str ? str : std::string{}; elm_genlist_item_update(ad->universal_switch_feedback_sound->item); } @@ -926,8 +904,7 @@ static void __feedback_sound_switch_changed_cb(SettingAccessibility *ad, bool st ad->universal_switch_feedback_sound->chk_status = state; elm_check_state_set(ad->universal_switch_feedback_sound->eo_check, state); - free(ad->universal_switch_feedback_sound->sub_desc); - ad->universal_switch_feedback_sound->sub_desc = strdup(str); + ad->universal_switch_feedback_sound->sub_desc = str ? str : std::string{}; elm_genlist_item_update(ad->universal_switch_feedback_sound->item); @@ -943,8 +920,7 @@ static void __feedback_sound_volume_changed_cb(SettingAccessibility *ad, int ite double media_level = _media_level[item_id].id / 100.0; __update_vconf_value(VCONFKEY_SETAPPL_ACCESSIBILITY_UNIVERSAL_SWITCH_SETTINGS_FEEDBACK_SOUND_VOLUME, NULL, NULL, &media_level); - free(ad->universal_switch_feedback_sound_volume->sub_desc); - ad->universal_switch_feedback_sound_volume->sub_desc = strdup(_media_level[item_id].key); + ad->universal_switch_feedback_sound_volume->sub_desc = _media_level[item_id].key ? _media_level[item_id].key : std::string{}; elm_genlist_item_update(ad->universal_switch_feedback_sound_volume->item); @@ -993,7 +969,7 @@ static void __feedback_voice_checkbox_cb(void *data, Evas_Object *obj, void *eve { retm_if(data == NULL, "Data parameter is NULL"); - Setting_GenGroupItem_Data *list_item = (Setting_GenGroupItem_Data *)data; + GenGroupItemData *list_item = (GenGroupItemData *)data; SettingAccessibility *ad = (SettingAccessibility *)list_item->userdata; list_item->chk_status = elm_check_state_get(obj); @@ -1003,8 +979,7 @@ static void __feedback_voice_checkbox_cb(void *data, Evas_Object *obj, void *eve const char *str = __get_boolean_text(ad->us_configuration.feedback_voice_state, _(DEVOPTION_STR_ACCESSIBILITY_UNIVERSAL_SWITCH_SETTINGS_ON), _(DEVOPTION_STR_ACCESSIBILITY_UNIVERSAL_SWITCH_SETTINGS_OFF)); - free(ad->universal_switch_feedback_voice->sub_desc); - ad->universal_switch_feedback_voice->sub_desc = strdup(str); + ad->universal_switch_feedback_voice->sub_desc = str ? str : std::string{}; elm_genlist_item_update(ad->universal_switch_feedback_voice->item); } @@ -1029,8 +1004,7 @@ static void __feedback_voice_switch_changed_cb(SettingAccessibility *ad, bool st ad->universal_switch_feedback_voice->chk_status = state; elm_check_state_set(ad->universal_switch_feedback_voice->eo_check, state); - free(ad->universal_switch_feedback_voice->sub_desc); - ad->universal_switch_feedback_voice->sub_desc = strdup(str); + ad->universal_switch_feedback_voice->sub_desc = str ? str : std::string{}; elm_genlist_item_update(ad->universal_switch_feedback_voice->item); @@ -1046,8 +1020,7 @@ static void __feedback_voice_speech_rate_changed_cb(SettingAccessibility *ad, in double media_level = _media_level[item_id].id / 100.0; __update_vconf_value(VCONFKEY_SETAPPL_ACCESSIBILITY_UNIVERSAL_SWITCH_SETTINGS_FEEDBACK_VOICE_SPEECH_RATE, NULL, NULL, &media_level); - free(ad->universal_switch_feedback_voice_speech_rate->sub_desc); - ad->universal_switch_feedback_voice_speech_rate->sub_desc = strdup(_media_level[item_id].key); + ad->universal_switch_feedback_voice_speech_rate->sub_desc = _media_level[item_id].key ? _media_level[item_id].key : std::string{}; elm_genlist_item_update(ad->universal_switch_feedback_voice_speech_rate->item); @@ -1063,8 +1036,7 @@ static void __feedback_voice_speech_volume_changed_cb(SettingAccessibility *ad, double media_level = _media_level[item_id].id / 100.0; __update_vconf_value(VCONFKEY_SETAPPL_ACCESSIBILITY_UNIVERSAL_SWITCH_SETTINGS_FEEDBACK_VOICE_SPEECH_VOLUME, NULL, NULL, &media_level); - free(ad->universal_switch_feedback_voice_speech_volume->sub_desc); - ad->universal_switch_feedback_voice_speech_volume->sub_desc = strdup(_media_level[item_id].key); + ad->universal_switch_feedback_voice_speech_volume->sub_desc = _media_level[item_id].key ? _media_level[item_id].key : std::string{}; elm_genlist_item_update(ad->universal_switch_feedback_voice_speech_volume->item); @@ -1148,7 +1120,7 @@ static void __manage_options_item_selected(void *data, Evas_Object *obj, void *e Elm_Object_Item *item = (Elm_Object_Item *)event_info; elm_genlist_item_selected_set(item, EINA_FALSE); - Setting_GenGroupItem_Data *list_item = (Setting_GenGroupItem_Data *)elm_object_item_data_get(item); + GenGroupItemData *list_item = (GenGroupItemData *)elm_object_item_data_get(item); setting_retm_if(list_item == NULL, "Data parameter is NULL"); SettingAccessibility *ad = (SettingAccessibility *)list_item->userdata; @@ -1186,8 +1158,7 @@ static void __update_switches_count(SettingAccessibility *ad) int switch_count = setting_accessibility_universal_switch_dbus_config_get_switch_count(&ad->config); const char *str = __get_value_unit_text(&switch_count, NULL, _(DEVOPTION_STR_ACCESSIBILITY_UNIVERSAL_SWITCH_SETTINGS_SWITCHES), false, NULL); - free(ad->universal_switch_settings_switches->sub_desc); - ad->universal_switch_settings_switches->sub_desc = strdup(str); + ad->universal_switch_settings_switches->sub_desc = str ? str : std::string{}; elm_genlist_item_update(ad->universal_switch_settings_switches->item); @@ -1322,21 +1293,21 @@ static void __get_vconf_settings(SettingAccessibility *ad) } -static Setting_GenGroupItem_Data *__add_menu_item(SettingAccessibility *ad, Evas_Object *genlist, const char *main_text, const char *sub_text, - setting_call_back_func item_cb, bool chk, bool chk_state, setting_call_back_func chk_cb) +static GenGroupItemData *__add_menu_item(SettingAccessibility *ad, Evas_Object *genlist, const char *main_text, const char *sub_text, + SettingCallback item_cb, bool chk, bool chk_state, SettingCallback chk_cb) { retvm_if(ad == NULL, NULL, "Input argument is NULL"); retvm_if(genlist == NULL, NULL, "Input genlist argument is NULL"); - int item_type = SWALLOW_Type_INVALID; - Setting_GenGroupItem_Data *item; + int item_type = static_cast(SwallowType::INVALID); + GenGroupItemData *item; if (chk) - item_type = SWALLOW_Type_1ICON_1RADIO; + item_type = static_cast(SwallowType::ICON_RADIO); item = setting_create_Gendial_field_def(genlist, &ad->itc_multiline_sub, item_cb, ad, - (SWALLOW_Type)item_type, NULL, NULL, (int)chk_state, + (SwallowType)item_type, NULL, NULL, (int)chk_state, main_text, sub_text, chk_cb); @@ -1450,7 +1421,7 @@ static void __auto_scan_menu_item_selected(void *data, Evas_Object *obj, void *e elm_genlist_item_selected_set(item, EINA_FALSE); - Setting_GenGroupItem_Data *list_item = (Setting_GenGroupItem_Data *)elm_object_item_data_get(item); + GenGroupItemData *list_item = (GenGroupItemData *)elm_object_item_data_get(item); setting_retm_if(list_item == NULL, "Data parameter is NULL"); setting_update_gl_item_chk_status(list_item, list_item->chk_status ? 0 : 1); @@ -1473,7 +1444,7 @@ static void __create_scanning_group(SettingAccessibility *ad, Evas_Object *genli setting_create_Gendial_field_titleItem(genlist, &itc_group_item, DEVOPTION_STR_ACCESSIBILITY_UNIVERSAL_SWITCH_SETTINGS_GROUP_SCANNING, NULL); - Setting_GenGroupItem_Data *item = __add_menu_item(ad, genlist, _(DEVOPTION_STR_ACCESSIBILITY_UNIVERSAL_SWITCH_SETTINGS_GROUP_SCANNING_AUTO_SCAN), NULL, __auto_scan_menu_item_selected, true, ad->us_configuration.auto_scan, __auto_scan_checkbox_cb); + GenGroupItemData *item = __add_menu_item(ad, genlist, _(DEVOPTION_STR_ACCESSIBILITY_UNIVERSAL_SWITCH_SETTINGS_GROUP_SCANNING_AUTO_SCAN), NULL, __auto_scan_menu_item_selected, true, ad->us_configuration.auto_scan, __auto_scan_checkbox_cb); int vconf_ret = vconf_notify_key_changed(VCONFKEY_SETAPPL_ACCESSIBILITY_UNIVERSAL_SWITCH_SETTINGS_AUTO_SCAN_ENABLED, __synchronize_auto_scan_with_vconf, item); if (vconf_ret) SETTING_TRACE_ERROR("FAIL: vconf_notify_key_changed(VCONFKEY_SETAPPL_ACCESSIBILITY_UNIVERSAL_SWITCH_SETTINGS_AUTO_SCAN_ENABLED)"); @@ -1511,7 +1482,7 @@ static void __auto_tap_kbd_menu_item_selected(void *data, Evas_Object *obj, void elm_genlist_item_selected_set(item, EINA_FALSE); - Setting_GenGroupItem_Data *list_item = (Setting_GenGroupItem_Data *)elm_object_item_data_get(item); + GenGroupItemData *list_item = (GenGroupItemData *)elm_object_item_data_get(item); setting_retm_if(list_item == NULL, "Data parameter is NULL"); setting_update_gl_item_chk_status(list_item, list_item->chk_status ? 0 : 1); diff --git a/src/setting-accessibility-universal-switch-switches.cpp b/src/setting-accessibility-universal-switch-switches.cpp index ba1faf7..6e238bc 100644 --- a/src/setting-accessibility-universal-switch-switches.cpp +++ b/src/setting-accessibility-universal-switch-switches.cpp @@ -61,17 +61,17 @@ static Eina_Bool __naviframe_pop_cb(void *data, Elm_Object_Item *it) return EINA_TRUE; } -static Setting_GenGroupItem_Data *__add_mapped_switch_menu_item(SettingAccessibility *ad, Evas_Object *genlist, const std::string& main_text, - const std::string& sub_text, setting_call_back_func item_cb, void *user_data) +static GenGroupItemData *__add_mapped_switch_menu_item(SettingAccessibility *ad, Evas_Object *genlist, const std::string& main_text, + const std::string& sub_text, SettingCallback item_cb, void *user_data) { retvm_if(ad == NULL, NULL, "Input argument is NULL"); retvm_if(genlist == NULL, NULL, "Input genlist argument is NULL"); - Setting_GenGroupItem_Data *item; + GenGroupItemData *item; - item = (Setting_GenGroupItem_Data *)setting_create_Gendial_field_def(genlist, &itc_2text_1icon_3, + item = (GenGroupItemData *)setting_create_Gendial_field_def(genlist, &itc_2text_1icon_3, item_cb, ad, - SWALLOW_Type_INVALID, NULL, NULL, 0, + SwallowType::INVALID, NULL, NULL, 0, main_text.c_str(), sub_text.c_str(), NULL); @@ -128,7 +128,7 @@ static void __switch_click_cb(void *data, Evas_Object *obj, void *event_info) elm_genlist_item_selected_set(item, EINA_FALSE); retm_if(data == NULL, "Data argument is NULL"); - Setting_GenGroupItem_Data *list_item = (Setting_GenGroupItem_Data *)elm_object_item_data_get(item); + GenGroupItemData *list_item = (GenGroupItemData *)elm_object_item_data_get(item); UniversalSwitchConfigurationItem *config_item = (UniversalSwitchConfigurationItem *)list_item->userdata; SettingAccessibility *ad = (SettingAccessibility *)data; @@ -183,9 +183,9 @@ static void __create_add_switch_button_in_genlist(SettingAccessibility *ad, Evas retm_if(ad == NULL, "Input argument is NULL"); - Setting_GenGroupItem_Data *item = (Setting_GenGroupItem_Data *)setting_create_Gendial_field_def(genlist, &itc_1text_1icon_3, + GenGroupItemData *item = (GenGroupItemData *)setting_create_Gendial_field_def(genlist, &itc_1text_1icon_3, __add_switch_click_cb, ad, - SWALLOW_Type_1ICON_1IMAGE, (const char*)ACCESSIBILITY_UNIVERSAL_SWITCH_PLUS_ICON, NULL, 0, + SwallowType::ICON_IMAGE, (const char*)ACCESSIBILITY_UNIVERSAL_SWITCH_PLUS_ICON, NULL, 0, _((const char*)DEVOPTION_STR_ACCESSIBILITY_UNIVERSAL_SWITCH_SETTINGS_GROUP_SWITCHES_ADD_SWITCH), NULL, NULL); diff --git a/src/setting-accessibility-universal-switch.cpp b/src/setting-accessibility-universal-switch.cpp index ca292d4..4ade40b 100644 --- a/src/setting-accessibility-universal-switch.cpp +++ b/src/setting-accessibility-universal-switch.cpp @@ -53,7 +53,7 @@ static void __universal_switch_checkbox_cb(void *data, Evas_Object *obj, void *e { retm_if(data == NULL, "Data parameter is NULL"); - Setting_GenGroupItem_Data *list_item = (Setting_GenGroupItem_Data *)data; + GenGroupItemData *list_item = (GenGroupItemData *)data; list_item->chk_status = elm_check_state_get(obj); @@ -72,7 +72,7 @@ static void __universal_switch_off_mouse_up_Gendial_list_cb(void *data, Evas_Obj elm_genlist_item_selected_set(item, EINA_FALSE); - Setting_GenGroupItem_Data *list_item = (Setting_GenGroupItem_Data *)elm_object_item_data_get(item); + GenGroupItemData *list_item = (GenGroupItemData *)elm_object_item_data_get(item); setting_retm_if(data == NULL, "Data parameter is NULL"); setting_update_gl_item_chk_status(list_item, list_item->chk_status ? 0 : 1); __universal_switch_vconf_key_update(list_item->chk_status ? 1 : 0, list_item->userdata); @@ -228,8 +228,7 @@ static void __universal_switch_state_display(SettingAccessibility *ad, bool stat item_label = _(DEVOPTION_STR_ACCESSIBILITY_UNIVERSAL_SWITCH_OFF); if (item_label && strlen(item_label) > 0) { - free(ad->universal_switch_off_checkbox->keyStr); - ad->universal_switch_off_checkbox->keyStr = strdup(item_label); + ad->universal_switch_off_checkbox->keyStr = item_label; } setting_update_gl_item_chk_status(ad->universal_switch_off_checkbox, (int) state); @@ -289,7 +288,7 @@ void setting_accessibility_universal_switch_page_create(SettingAccessibility *ad ad->universal_switch_off_checkbox = setting_create_Gendial_field_def( genlist, &itc_1text_1icon, __universal_switch_off_mouse_up_Gendial_list_cb, - ad, SWALLOW_Type_1ICON_1RADIO, NULL, + ad, SwallowType::ICON_RADIO, NULL, NULL, state, _(DEVOPTION_STR_ACCESSIBILITY_UNIVERSAL_SWITCH_OFF), NULL, __universal_switch_checkbox_cb); @@ -302,7 +301,7 @@ void setting_accessibility_universal_switch_page_create(SettingAccessibility *ad ad->universal_switch_comment = setting_create_Gendial_field_def( genlist, &ad->itc_multiline_sub, - NULL, ad, SWALLOW_Type_INVALID, NULL, + NULL, ad, SwallowType::INVALID, NULL, NULL, 0, NULL, _(DEVOPTION_STR_ACCESSIBILITY_UNIVERSAL_SWITCH_COMMENT), diff --git a/src/setting-accessibility.cpp b/src/setting-accessibility.cpp index 2ce0708..82921ee 100644 --- a/src/setting-accessibility.cpp +++ b/src/setting-accessibility.cpp @@ -95,27 +95,25 @@ destroy_tts_handle(SettingAccessibility *ad) static char *_universal_switch_gendial_new_text_get(void *data, Evas_Object *obj, const char *part) { - Setting_GenGroupItem_Data *item_data = (Setting_GenGroupItem_Data *)data; - if (!safeStrCmp(item_data->itc, "multiline")) { + GenGroupItemData *item_data = (GenGroupItemData *)data; + if (!safeStrCmp(item_data->itc.c_str(), "multiline")) { if (!safeStrCmp(part, "elm.text")) { - if (item_data->keyStr) { - return (char *)g_strdup( - _(item_data->keyStr)); + if (!item_data->keyStr.empty()) { + return (char *)g_strdup(_(item_data->keyStr.c_str())); } } else if (!safeStrCmp(part, "elm.text.multiline")) { - if (item_data->sub_desc) { - return (char *)g_strdup( - _(item_data->sub_desc)); + if (!item_data->sub_desc.empty()) { + return (char *)g_strdup(_(item_data->sub_desc.c_str())); } } } else { if (!safeStrCmp(part, "elm.text")) { - if (item_data->keyStr) { - return (char *)g_strdup(_(item_data->keyStr)); + if (!item_data->keyStr.empty()) { + return (char *)g_strdup(_(item_data->keyStr.c_str())); } } else if (!safeStrCmp(part, "elm.text.sub")) { - if (item_data->sub_desc) { - return (char *)g_strdup(_(item_data->sub_desc)); + if (!item_data->sub_desc.empty()) { + return (char *)g_strdup(_(item_data->sub_desc.c_str())); } } } diff --git a/src/setting-accessibility.h b/src/setting-accessibility.h index c470409..d441885 100755 --- a/src/setting-accessibility.h +++ b/src/setting-accessibility.h @@ -245,41 +245,41 @@ struct SettingAccessibility { Elm_Object_Item *naviframe_it; SetValueLayout set_value_layout; - Setting_GenGroupItem_Data *speech_rate_item; - Setting_GenGroupItem_Data *keyboard_feedback_item; - Setting_GenGroupItem_Data *hints_item; - Setting_GenGroupItem_Data *vibration_feedback_item; - Setting_GenGroupItem_Data *sound_feedback_item; - Setting_GenGroupItem_Data *status_bar_information_item; - Setting_GenGroupItem_Data *multiline_status_bar_information_description; - Setting_GenGroupItem_Data *screenreader_checkbox; - Setting_GenGroupItem_Data *multiline_screen_reader_comment; - Setting_GenGroupItem_Data *screen_reader_settings; - Setting_GenGroupItem_Data *screen_reader_item; - Setting_GenGroupItem_Data *universal_switch_item; - Setting_GenGroupItem_Data *universal_switch_off_checkbox; - Setting_GenGroupItem_Data *universal_switch_comment; - Setting_GenGroupItem_Data *universal_switch_add_switch_screen; - Setting_GenGroupItem_Data *universal_switch_add_switch_accessories; - Setting_GenGroupItem_Data *universal_switch_add_switch_camera; - Setting_GenGroupItem_Data *universal_switch_camera_comment; - Setting_GenGroupItem_Data *universal_switch_settings_switches; - Setting_GenGroupItem_Data *universal_switch_auto_scan_int; - Setting_GenGroupItem_Data *universal_switch_scans_num; - Setting_GenGroupItem_Data *universal_switch_scan_method; - Setting_GenGroupItem_Data *universal_switch_scan_dir; - Setting_GenGroupItem_Data *universal_switch_scan_speed; - Setting_GenGroupItem_Data *universal_switch_pause_on_first; - Setting_GenGroupItem_Data *universal_switch_tap_duration; - Setting_GenGroupItem_Data *universal_switch_sgl_iaction_int; - Setting_GenGroupItem_Data *universal_switch_auto_tap; - Setting_GenGroupItem_Data *universal_switch_auto_move_int; - Setting_GenGroupItem_Data *universal_switch_feedback_cursor_cl; - Setting_GenGroupItem_Data *universal_switch_feedback_sound; - Setting_GenGroupItem_Data *universal_switch_feedback_sound_volume; - Setting_GenGroupItem_Data *universal_switch_feedback_voice; - Setting_GenGroupItem_Data *universal_switch_feedback_voice_speech_rate; - Setting_GenGroupItem_Data *universal_switch_feedback_voice_speech_volume; + GenGroupItemData *speech_rate_item; + GenGroupItemData *keyboard_feedback_item; + GenGroupItemData *hints_item; + GenGroupItemData *vibration_feedback_item; + GenGroupItemData *sound_feedback_item; + GenGroupItemData *status_bar_information_item; + GenGroupItemData *multiline_status_bar_information_description; + GenGroupItemData *screenreader_checkbox; + GenGroupItemData *multiline_screen_reader_comment; + GenGroupItemData *screen_reader_settings; + GenGroupItemData *screen_reader_item; + GenGroupItemData *universal_switch_item; + GenGroupItemData *universal_switch_off_checkbox; + GenGroupItemData *universal_switch_comment; + GenGroupItemData *universal_switch_add_switch_screen; + GenGroupItemData *universal_switch_add_switch_accessories; + GenGroupItemData *universal_switch_add_switch_camera; + GenGroupItemData *universal_switch_camera_comment; + GenGroupItemData *universal_switch_settings_switches; + GenGroupItemData *universal_switch_auto_scan_int; + GenGroupItemData *universal_switch_scans_num; + GenGroupItemData *universal_switch_scan_method; + GenGroupItemData *universal_switch_scan_dir; + GenGroupItemData *universal_switch_scan_speed; + GenGroupItemData *universal_switch_pause_on_first; + GenGroupItemData *universal_switch_tap_duration; + GenGroupItemData *universal_switch_sgl_iaction_int; + GenGroupItemData *universal_switch_auto_tap; + GenGroupItemData *universal_switch_auto_move_int; + GenGroupItemData *universal_switch_feedback_cursor_cl; + GenGroupItemData *universal_switch_feedback_sound; + GenGroupItemData *universal_switch_feedback_sound_volume; + GenGroupItemData *universal_switch_feedback_voice; + GenGroupItemData *universal_switch_feedback_voice_speech_rate; + GenGroupItemData *universal_switch_feedback_voice_speech_volume; Elm_Genlist *universal_switch_switches; back_cb universal_switch_switches_back; diff --git a/src/setting-common-data-type.h b/src/setting-common-data-type.h index 4c7b293..8a5f4c1 100644 --- a/src/setting-common-data-type.h +++ b/src/setting-common-data-type.h @@ -35,6 +35,7 @@ #include "setting-common-resource.h" /* including another class of data type */ #include "setting-common-data-error.h" +#include "GenGroupItemData.hpp" #define SETTING_GENLIST_1ICON_STYLE "full" #define SETTING_GENLIST_GROUP_INDEX_STYLE "group_index" @@ -74,9 +75,6 @@ * @return vo return */ -typedef void (*setting_call_back_func)( - void *data, Evas_Object *obj, void *event_info); - #define WIDGET_SCALE_FACTOR (elm_config_scale_get()) @@ -112,14 +110,6 @@ typedef void (*setting_call_back_func)( #define MIN_MOVE_DISTANCE 30 -#ifdef __LP64__ -typedef int64_t int_of_ptr_size; -#else -typedef int int_of_ptr_size; -#endif - - - enum ButtonState { SETTING_ON_OFF_BTN_OFF = 0, SETTING_ON_OFF_BTN_ON, @@ -133,163 +123,10 @@ struct setting_lang_entry { char *mcc; }; -enum SWALLOW_Type { - SWALLOW_Type_INVALID = -1, - SWALLOW_Type_1ICON_1RADIO = 2, - SWALLOW_Type_1CHECK = 3, - SWALLOW_Type_1CHECK_RIGHT = 4, - SWALLOW_Type_1CHECKICON = 5, - SWALLOW_Type_1RADIO = 6, - SWALLOW_Type_1TOGGLE = 7, - SWALLOW_Type_1CHECK_RIGHT_INVISIBLE, - SWALLOW_Type_1ICON_1DOTTOOGLE, - SWALLOW_Type_1ICON_SMALL_ICON, - - SWALLOW_Type_1ICON_1IMAGE, - SWALLOW_Type_1GIF, - SWALLOW_Type_1BUTTON, - - SWALLOW_TYPE_1RADIO_RIGHT_PROPAGATE_EVENTS_SET, - SWALLOW_Type_1RADIO_RIGHT, - SWALLOW_Type_1RADIO_1BTN, - SWALLOW_Type_1RADIO_1TEXT, - - SWALLOW_Type_1LINE_LAYOUT, - SWALLOW_Type_LAYOUT_EDITFIELD, - SWALLOW_Type_LAYOUT_SIMPLE_PASSWORD, /* for simple password */ - SWALLOW_Type_LAYOUT_DATEFIELD, - SWALLOW_Type_LAYOUT_SLIDER, - SWALLOW_Type_LAYOUT_5STEP_SLIDER, - SWALLOW_Type_LAYOUT_SPECIALIZTION, - SWALLOW_Type_LAYOUT_SPECIALIZTION_X,/*extension */ - - SWALLOW_Type_MAX -}; - enum POPUP_BTN_RESPONSE_TYPE { POPUP_RESPONSE_INVALID = -1, POPUP_RESPONSE_OK = 0, POPUP_RESPONSE_CANCEL = 1, } ; -/** - * an item node in genlist - * @todo begings_to is requried? - * @todo isItemDisableFlag is required? - * @todo isSinglelineFlag is requred? - */ -struct Setting_GenGroupItem_Data { - - void **pBack; - Evas_Object *window; - Evas *evas; - - Elm_Object_Item *item; - - SWALLOW_Type swallow_type; - const char *l_swallow_path; /**< left image */ - const char *r_swallow_path; /**< right image */ - - /* output */ - /**< slider, button, check, editfield, datefield */ - Evas_Object *eo_check; - /**< represent check value, slider value, datefield value etc.. */ - int chk_status; - int chk_id; - setting_call_back_func chk_change_cb; - - /* radio button */ - /**< radio button */ - Evas_Object *rgd; - - char *keyStr; /**< title */ - char *keyStr2; /**< title for font name expanlist item*/ - char *sub_desc; /**< sub text */ - char *guide_text; /**< guide text for editfield */ - - /* for slider control */ - bool isIndicatorVisible;/**< indicator option (displaying number) */ - double slider_min; /**< to swallow a slider */ - double slider_max; /**< to swallow a slider */ - - setting_call_back_func start_change_cb; - setting_call_back_func stop_change_cb; - setting_call_back_func maxlength_reached_cb; - setting_call_back_func focus_cb; /**< for entry */ - setting_call_back_func activated_cb; /**< for entry */ - setting_call_back_func mouse_up_cb; - - void *x_callback_cb; - - /* sound/vibration */ - /**< 1: slider belongs to sound group. - * 0: slider belongs to vibration group */ - int_of_ptr_size belongs_to; - - - /* for input panel */ - /**< input panel type */ - Elm_Input_Panel_Layout input_type; - /** the return key type in input method panel*/ - Elm_Input_Panel_Return_Key_Type return_key_type; - bool input_panel_disable_flag; - /** do not autocapital the first char in edit field*/ - int disable_auto_cap; - - void *userdata; /**< just a reference, do not need release. */ - - bool isPasswordFlag; - bool isFocusFlag; - bool isItemDisableFlag; /**< date/time UG only */ - bool isSinglelineFlag; - bool maxLengthReachFlag; - /**< for about UG, enter or space key are not allowed, if they are - * pressed, it is true */ - bool enterKeyPressFlag; - /***/ - bool spaceKeyPressFlag; - - bool isItemHideFlag; /**< setting > storage only */ - - /**< its relative vconf value must increase from 0, and step is 1. - * eg, 0, 1, 2, 3.. */ - int_of_ptr_size int_slp_setting_binded; - - /*for enty, if this is true, then entry will be focus state when the - * entry is created*/ - bool entry_auto_focus; - - /* popup */ - Evas_Object *notify; /**< act as any popup to show user any message */ - - Elm_Entry_Filter_Accept_Set *digits_filter_data; - Elm_Entry_Filter_Limit_Size *limit_filter_data; - - bool focus_unallowed; - - /*for incoming call*/ - Eina_Bool isPlaying; - - /* for disable item*/ - Eina_Bool disableflag; - - /*record itc style for all genlist item with check/radio/toggle */ - char *itc; - - /* storage item style */ - /* 2: app, 3: pic,video, 4: audio, 5: Misc files, 6: Avail space */ - int color; - - /* Sound, ringtone ug, fullpath */ - char *filepath; - - /* elm_datetime new */ - Evas_Object *btn_left; - Evas_Object *btn_right; - - Evas_Object *nf; - -}; - #endif /* __SETTING_COMMON_DATA_TYPE_H__ */ diff --git a/src/setting-common-draw-genlist.cpp b/src/setting-common-draw-genlist.cpp index bca14fe..a5c48c2 100644 --- a/src/setting-common-draw-genlist.cpp +++ b/src/setting-common-draw-genlist.cpp @@ -32,7 +32,7 @@ static char *_gl_Gendial_new_text_get(void *data, Evas_Object *obj, const char *part); static void _gl_Gendial_del(void *data, Evas_Object *obj); -static Evas_Object *__add_entry_padding(Setting_GenGroupItem_Data *item_data, +static Evas_Object *__add_entry_padding(GenGroupItemData *item_data, Evas_Object *parent); #define DEFINE_ITC1(style, name) \ @@ -79,16 +79,16 @@ DEFINE_ITC1(SETTING_GENLIST_GROUP_INDEX_STYLE, itc_group_item); static void __radio_changed(void *data, Evas_Object *obj, void *event_info) { retm_if(data == NULL, "Data parameter is NULL"); - Setting_GenGroupItem_Data *list_item = - (Setting_GenGroupItem_Data *)data; + GenGroupItemData *list_item = + (GenGroupItemData *)data; list_item->chk_status = elm_radio_value_get(obj); /* for update */ } static void __chk_changed(void *data, Evas_Object *obj, void *event_info) { retm_if(data == NULL, "Data parameter is NULL"); - Setting_GenGroupItem_Data *list_item = - (Setting_GenGroupItem_Data *)data; + GenGroupItemData *list_item = + (GenGroupItemData *)data; list_item->chk_status = elm_check_state_get(obj); /* for update */ } @@ -104,8 +104,8 @@ static void _gl_Gendial_sel(void *data, Evas_Object *obj, void *event_info) static char *_gl_Gendial_new_text_get(void *data, Evas_Object *obj, const char *part) { - Setting_GenGroupItem_Data *item_data = - (Setting_GenGroupItem_Data *)data; + GenGroupItemData *item_data = + (GenGroupItemData *)data; char *ret_str = NULL; /*------------------------------------------------------------- */ @@ -114,49 +114,42 @@ static char *_gl_Gendial_new_text_get(void *data, Evas_Object *obj, /* style != multiline ---------> "elm.text" */ /* "elm.text.sub" */ /*------------------------------------------------------------- */ - if (!safeStrCmp(item_data->itc, "multiline")) { - + if (!safeStrCmp(item_data->itc.c_str(), "multiline")) { if (!safeStrCmp(part, "elm.text.multiline")) { - if (item_data->keyStr) { - ret_str = (char *)g_strdup( - _(item_data->keyStr)); + if (!item_data->keyStr.empty()) { + ret_str = (char *)g_strdup(_(item_data->keyStr.c_str())); } } } else { if (!safeStrCmp(part, "elm.text")) { - if (item_data->keyStr) { - ret_str = (char *)g_strdup( - _(item_data->keyStr)); + if (!item_data->keyStr.empty()) { + ret_str = (char *)g_strdup(_(item_data->keyStr.c_str())); } } else if (!safeStrCmp(part, "elm.text.sub")) { - if (item_data->sub_desc) { - ret_str = (char *)g_strdup( - _(item_data->sub_desc)); + if (!item_data->sub_desc.empty()) { + ret_str = (char *)g_strdup(_(item_data->sub_desc.c_str())); } } else if (!safeStrCmp(part, "elm.text.main") || !safeStrCmp(part, "elm.text.main.left") || !safeStrCmp(part, "elm.text.main.left.top")) { /* title */ - if (item_data->keyStr) { - ret_str = (char *)g_strdup( - _(item_data->keyStr)); + if (!item_data->keyStr.empty()) { + ret_str = (char *)g_strdup(_(item_data->keyStr.c_str())); } } else if (!safeStrCmp(part, "elm.text.2") || !safeStrCmp(part, "elm.text.sub.left.bottom")) { /* bottom or right */ - if (item_data->sub_desc) { - ret_str = (char *)g_strdup( - _(item_data->sub_desc)); + if (!item_data->sub_desc.empty()) { + ret_str = (char *)g_strdup(_(item_data->sub_desc.c_str())); } } else if (!safeStrCmp(part, "elm.text.multiline")) { /* title */ - if (item_data->keyStr) { - ret_str = (char *)g_strdup( - _(item_data->keyStr)); + if (!item_data->keyStr.empty()) { + ret_str = (char *)g_strdup(_(item_data->keyStr.c_str())); } } else { FREE(ret_str); @@ -166,20 +159,13 @@ static char *_gl_Gendial_new_text_get(void *data, Evas_Object *obj, return ret_str; } -static Evas_Object *__add_check_invisible(Setting_GenGroupItem_Data *item_data, +static Evas_Object *__add_check_invisible(GenGroupItemData *item_data, Evas_Object *parent) { retv_if(!item_data || !parent, NULL); - if (item_data->isItemHideFlag) - return NULL; - Evas_Object *check = elm_check_add(parent); - /* To fix check button flicker issue when rotate the screen*/ - if (item_data->isItemDisableFlag) - elm_object_disabled_set(check, EINA_FALSE); - elm_check_state_set(check, item_data->chk_status); evas_object_propagate_events_set(check, 0); evas_object_size_hint_align_set(check, EVAS_HINT_FILL, EVAS_HINT_FILL); @@ -202,24 +188,20 @@ static Evas_Object *__add_check_invisible(Setting_GenGroupItem_Data *item_data, return check; } -static Evas_Object *__add_check(Setting_GenGroupItem_Data *item_data, +static Evas_Object *__add_check(GenGroupItemData *item_data, Evas_Object *parent) { retv_if(!item_data || !parent, NULL); Evas_Object *check = elm_check_add(parent); - /* To fix check button flicker issue when rotate the screen */ - if (item_data->isItemDisableFlag) - elm_object_disabled_set(check, EINA_FALSE); - elm_check_state_set(check, item_data->chk_status); evas_object_propagate_events_set(check, 0); evas_object_size_hint_align_set(check, EVAS_HINT_FILL, EVAS_HINT_FILL); evas_object_size_hint_weight_set(check, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND); - if (SWALLOW_Type_1CHECK == item_data->swallow_type) { + if (SwallowType::CHECK == item_data->swallow_type) { elm_check_state_pointer_set(check, (Eina_Bool *)(&(item_data->chk_status))); evas_object_pass_events_set(check, 1); @@ -241,23 +223,19 @@ static Evas_Object *__add_check(Setting_GenGroupItem_Data *item_data, return check; } -static Evas_Object *__add_toggle(Setting_GenGroupItem_Data *item_data, +static Evas_Object *__add_toggle(GenGroupItemData *item_data, Evas_Object *parent) { retv_if(!item_data || !parent, NULL); Evas_Object *check = elm_check_add(parent); - /* To fix check button flicker issue when rotate the screen */ - if (item_data->isItemDisableFlag) - elm_object_disabled_set(check, EINA_FALSE); - elm_check_state_set(check, item_data->chk_status); evas_object_propagate_events_set(check, 0); evas_object_size_hint_align_set(check, EVAS_HINT_FILL, EVAS_HINT_FILL); evas_object_size_hint_weight_set(check, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND); - if (SWALLOW_Type_1CHECK == item_data->swallow_type) { + if (SwallowType::CHECK == item_data->swallow_type) { elm_check_state_pointer_set(check, (Eina_Bool *)(&(item_data->chk_status))); evas_object_pass_events_set(check, 1); @@ -286,13 +264,13 @@ static Evas_Object *__add_toggle(Setting_GenGroupItem_Data *item_data, return check; } -static Evas_Object *__add_dot_toggle(Setting_GenGroupItem_Data *item_data, +static Evas_Object *__add_dot_toggle(GenGroupItemData *item_data, Evas_Object *parent) { return NULL; } -static Evas_Object *__add_radio(Setting_GenGroupItem_Data *item_data, +static Evas_Object *__add_radio(GenGroupItemData *item_data, Evas_Object *parent) { retv_if(!item_data || !parent, NULL); @@ -325,7 +303,7 @@ static Evas_Object *__add_radio(Setting_GenGroupItem_Data *item_data, * evas_object_propagate_events_set(... FALSE) */ static Evas_Object *__add_radio_right_propagate_events_set( - Setting_GenGroupItem_Data *item_data, Evas_Object *parent) + GenGroupItemData *item_data, Evas_Object *parent) { retv_if(!item_data || !parent, NULL); @@ -351,7 +329,7 @@ static Evas_Object *__add_radio_right_propagate_events_set( return radio; } -static Evas_Object *__add_radio_right(Setting_GenGroupItem_Data *item_data, +static Evas_Object *__add_radio_right(GenGroupItemData *item_data, Evas_Object *parent) { retv_if(!item_data || !parent, NULL); @@ -376,7 +354,7 @@ static Evas_Object *__add_radio_right(Setting_GenGroupItem_Data *item_data, return radio; } -static Evas_Object *__add_radio_text(Setting_GenGroupItem_Data *item_data, +static Evas_Object *__add_radio_text(GenGroupItemData *item_data, Evas_Object *parent) { retv_if(!item_data || !parent, NULL); @@ -401,55 +379,34 @@ static Evas_Object *__add_radio_text(Setting_GenGroupItem_Data *item_data, return radio; } -static Evas_Object *__add_button(Setting_GenGroupItem_Data *item_data, +static Evas_Object *__add_button(GenGroupItemData *item_data, Evas_Object *parent) { retv_if(!item_data || !parent, NULL); Evas_Object *btn = elm_button_add(parent); elm_object_text_set(btn, _("IDS_ST_BODY_EDIT")); evas_object_show(btn); - if (item_data->r_swallow_path) - elm_object_style_set(btn, item_data->r_swallow_path); + if (!item_data->r_swallow_path.empty()) + elm_object_style_set(btn, item_data->r_swallow_path.c_str()); - if (item_data->keyStr - && item_data->swallow_type - != SWALLOW_Type_1RADIO_1BTN) { - elm_object_text_set(btn, _(item_data->keyStr)); + if (!item_data->keyStr.empty() && item_data->swallow_type != SwallowType::RADIO_1BTN) { + elm_object_text_set(btn, _(item_data->keyStr.c_str())); } evas_object_propagate_events_set(btn, EINA_FALSE); - if (item_data->stop_change_cb) { /* just only for 1radio_1btn type */ - - evas_object_smart_callback_add(btn, "clicked", - item_data->stop_change_cb, item_data); - } else if (item_data->chk_change_cb) { /* for other types */ - evas_object_smart_callback_add(btn, "clicked", - item_data->chk_change_cb, item_data); + if (item_data->chk_change_cb) { /* for other types */ + evas_object_smart_callback_add(btn, "clicked", item_data->chk_change_cb, item_data); } return btn; } -static Evas_Object *__add_gif(Setting_GenGroupItem_Data *item_data, +static Evas_Object *__add_gif(GenGroupItemData *item_data, Evas_Object *parent) { - retv_if(!item_data || !parent, NULL); - Evas_Object *image = NULL; - const char **png_list = (const char **)item_data->belongs_to; - - if (png_list && *png_list) { - if (png_list[1]) { - /*png_list is an array end with 'NULL', and it has at - * least 2 png file, */ - image = setting_create_gif(parent, png_list); - } else { /*png_list just has one png file, */ - image = setting_create_image(parent, *png_list); - } - } - - return image; + return NULL; } -static Evas_Object *__add_5step_slider(Setting_GenGroupItem_Data *item_data, +static Evas_Object *__add_5step_slider(GenGroupItemData *item_data, Evas_Object *parent) { @@ -458,15 +415,15 @@ static Evas_Object *__add_5step_slider(Setting_GenGroupItem_Data *item_data, Evas_Object *li_slider = setting_create_5step_slider( parent, item_data->evas, - item_data->l_swallow_path, - item_data->r_swallow_path, + item_data->l_swallow_path.c_str(), + item_data->r_swallow_path.c_str(), item_data->chk_status, - item_data->isIndicatorVisible, - item_data->slider_min, - item_data->slider_max, + false, + 0.0, + 0.0, item_data->chk_change_cb, - item_data->start_change_cb, - item_data->stop_change_cb, + NULL, + NULL, item_data); evas_object_pass_events_set(li_slider, 1); evas_object_propagate_events_set(li_slider, 0); @@ -474,7 +431,7 @@ static Evas_Object *__add_5step_slider(Setting_GenGroupItem_Data *item_data, return li_slider; } -static Evas_Object *__add_slider(Setting_GenGroupItem_Data *item_data, +static Evas_Object *__add_slider(GenGroupItemData *item_data, Evas_Object *parent) { retv_if(!item_data || !parent, NULL); @@ -485,36 +442,36 @@ static Evas_Object *__add_slider(Setting_GenGroupItem_Data *item_data, return li_slider; } -static Evas_Object *__add_left_default(Setting_GenGroupItem_Data *item_data, +static Evas_Object *__add_left_default(GenGroupItemData *item_data, Evas_Object *parent) { retv_if(!item_data || !parent, NULL); - if (!item_data->l_swallow_path) + if (item_data->l_swallow_path.empty()) return NULL; - if (SWALLOW_Type_1ICON_1DOTTOOGLE == item_data->swallow_type - || SWALLOW_Type_1ICON_1IMAGE + if (SwallowType::ICON_DOTTOOGLE == item_data->swallow_type + || SwallowType::ICON_IMAGE == item_data->swallow_type) { Evas_Object *icon = elm_icon_add(parent); setting_decorate_image_RGBA(icon, 15, 41, 73, 255); - elm_image_file_set(icon, item_data->l_swallow_path, NULL); + elm_image_file_set(icon, item_data->l_swallow_path.c_str(), NULL); evas_object_size_hint_aspect_set(icon, EVAS_ASPECT_CONTROL_VERTICAL, 1, 1); return icon; - } else if (SWALLOW_Type_1ICON_SMALL_ICON == item_data->swallow_type) { + } else if (SwallowType::ICON_SMALL_ICON == item_data->swallow_type) { Evas_Object *c = elm_image_add(parent); - elm_image_file_set(c, item_data->l_swallow_path, NULL); + elm_image_file_set(c, item_data->l_swallow_path.c_str(), NULL); evas_object_size_hint_align_set(c, EVAS_HINT_FILL, EVAS_HINT_FILL); evas_object_size_hint_weight_set(c, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND); return c; - } else if (SWALLOW_Type_1CHECK_RIGHT_INVISIBLE + } else if (SwallowType::CHECK_RIGHT_INVISIBLE == item_data->swallow_type) { Evas_Object *icon = elm_icon_add(parent); - elm_image_file_set(icon, item_data->l_swallow_path, NULL); + elm_image_file_set(icon, item_data->l_swallow_path.c_str(), NULL); evas_object_size_hint_aspect_set(icon, EVAS_ASPECT_CONTROL_VERTICAL, 1, 1); elm_image_resizable_set(icon, EINA_TRUE, EINA_TRUE); @@ -523,7 +480,7 @@ static Evas_Object *__add_left_default(Setting_GenGroupItem_Data *item_data, } else { Evas_Object * c = elm_image_add(parent); - elm_image_file_set(c, item_data->l_swallow_path, NULL); + elm_image_file_set(c, item_data->l_swallow_path.c_str(), NULL); setting_decorate_image_RGBA(c, 14, 41, 73, 255); evas_object_size_hint_align_set(c, EVAS_HINT_FILL, EVAS_HINT_FILL); @@ -534,23 +491,21 @@ static Evas_Object *__add_left_default(Setting_GenGroupItem_Data *item_data, } -static Evas_Object *__add_right_default(Setting_GenGroupItem_Data *item_data, +static Evas_Object *__add_right_default(GenGroupItemData *item_data, Evas_Object *parent) { retv_if(!item_data || !parent, NULL); - if (!item_data->r_swallow_path) + if (item_data->r_swallow_path.empty()) return NULL; Evas_Object *icon = elm_image_add(parent); - if (!safeStrCmp(item_data->r_swallow_path, - SETTING_IMAGE_PATH_CFG"00_list_button_expand_closed.png")) + if (item_data->r_swallow_path == SETTING_IMAGE_PATH_CFG"00_list_button_expand_closed.png") setting_decorate_image_RGBA(icon, 14, 41, 73, 255); - else if (!safeStrCmp(item_data->r_swallow_path, - SETTING_IMAGE_PATH_CFG"00_list_button_expand_opened.png")) + else if (item_data->r_swallow_path == SETTING_IMAGE_PATH_CFG"00_list_button_expand_opened.png") setting_decorate_image_RGBA(icon, 14, 41, 73, 255); - elm_image_file_set(icon, item_data->r_swallow_path, NULL); + elm_image_file_set(icon, item_data->r_swallow_path.c_str(), NULL); evas_object_size_hint_align_set(icon, 0.0, EVAS_HINT_FILL); evas_object_size_hint_weight_set(icon, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND); @@ -559,43 +514,43 @@ static Evas_Object *__add_right_default(Setting_GenGroupItem_Data *item_data, } /* draw handler */ -typedef Evas_Object *(*__drawer_fp)(Setting_GenGroupItem_Data *item_data, +typedef Evas_Object *(*__drawer_fp)(GenGroupItemData *item_data, Evas_Object *parent); typedef struct { - SWALLOW_Type type; /* ui type */ + SwallowType type; /* ui type */ __drawer_fp draw; } __Content_Drawer; -static __Content_Drawer __cd_left[SWALLOW_Type_MAX] = { +static __Content_Drawer __cd_left[static_cast(SwallowType::MAX)] = { /*base objects */ - { SWALLOW_Type_1CHECK, __add_check }, + { SwallowType::CHECK, __add_check }, /* setting-network, security-sim-setting */ - { SWALLOW_Type_1TOGGLE, __add_toggle }, - { SWALLOW_Type_1RADIO, __add_radio }, /* many */ - { SWALLOW_Type_1RADIO_1BTN, __add_radio }, - { SWALLOW_Type_1BUTTON, __add_button }, - { SWALLOW_Type_1GIF, __add_gif }, + { SwallowType::TOGGLE, __add_toggle }, + { SwallowType::RADIO, __add_radio }, /* many */ + { SwallowType::RADIO_1BTN, __add_radio }, + { SwallowType::BUTTON, __add_button }, + { SwallowType::GIF, __add_gif }, /*base objects in an layout */ - { SWALLOW_Type_LAYOUT_SLIDER, __add_slider }, - { SWALLOW_Type_LAYOUT_5STEP_SLIDER, __add_5step_slider }, + { SwallowType::LAYOUT_SLIDER, __add_slider }, + { SwallowType::LAYOUT_5STEP_SLIDER, __add_5step_slider }, /*other compelx objects */ /* setting-network */ - { SWALLOW_Type_1RADIO_1TEXT, __add_radio_text }, + { SwallowType::RADIO_1TEXT, __add_radio_text }, /*left part object of the type */ - { SWALLOW_Type_1ICON_SMALL_ICON, __add_left_default }, + { SwallowType::ICON_SMALL_ICON, __add_left_default }, }; -static __Content_Drawer __cd_right[SWALLOW_Type_MAX] = { +static __Content_Drawer __cd_right[static_cast(SwallowType::MAX)] = { /*right part object of the type */ - { SWALLOW_Type_1CHECK_RIGHT, __add_check }, - { SWALLOW_Type_1ICON_1RADIO, __add_toggle }, - { SWALLOW_Type_1ICON_1DOTTOOGLE, __add_dot_toggle }, - { SWALLOW_TYPE_1RADIO_RIGHT_PROPAGATE_EVENTS_SET, + { SwallowType::CHECK_RIGHT, __add_check }, + { SwallowType::ICON_RADIO, __add_toggle }, + { SwallowType::ICON_DOTTOOGLE, __add_dot_toggle }, + { SwallowType::RADIO_RIGHT_PROPAGATE_EVENTS_SET, __add_radio_right_propagate_events_set }, - { SWALLOW_Type_1RADIO_RIGHT, __add_radio_right }, - { SWALLOW_Type_1CHECK_RIGHT_INVISIBLE, __add_check_invisible }, + { SwallowType::RADIO_RIGHT, __add_radio_right }, + { SwallowType::CHECK_RIGHT_INVISIBLE, __add_check_invisible }, }; @@ -603,7 +558,7 @@ static __Content_Drawer __cd_right[SWALLOW_Type_MAX] = { static void __multiline_eraser_clicked(void *data, Evas_Object *obj, void *event_info) { - Setting_GenGroupItem_Data *list_item = (Setting_GenGroupItem_Data *)data; + GenGroupItemData *list_item = (GenGroupItemData *)data; Evas_Object *entry = (Evas_Object *)elm_object_item_part_content_get(list_item->item, "elm.icon.entry"); /* After button is clicked, entry should get focus again. */ @@ -614,7 +569,7 @@ static void __multiline_eraser_clicked(void *data, Evas_Object *obj, static Evas_Object *_gl_Gendial_content_get(void *data, Evas_Object *obj, const char *part) { - Setting_GenGroupItem_Data *item_data = (Setting_GenGroupItem_Data *)data; + GenGroupItemData *item_data = (GenGroupItemData *)data; __Content_Drawer *cd_list = NULL; __drawer_fp fp = NULL; retv_if(!item_data, NULL); @@ -628,16 +583,10 @@ static Evas_Object *_gl_Gendial_content_get(void *data, Evas_Object *obj, cd_list = __cd_right; } else if (!safeStrCmp(part, "elm.icon.1")) { /* LEFT AREA */ - if (item_data->swallow_type == SWALLOW_Type_LAYOUT_EDITFIELD - && item_data->isPasswordFlag == TRUE) - return NULL; fp = __add_left_default; /*hold default drawer */ cd_list = __cd_left; } else if (!safeStrCmp(part, "elm.icon.2")) { /* RIGHT AREA */ - if (item_data->swallow_type == SWALLOW_Type_LAYOUT_EDITFIELD - && item_data->isPasswordFlag == TRUE) - return NULL; fp = __add_right_default; /*hold default drawer */ cd_list = __cd_right; @@ -646,7 +595,7 @@ static Evas_Object *_gl_Gendial_content_get(void *data, Evas_Object *obj, cd_list = __cd_left; } else if (!safeStrCmp(part, "elm.icon.entry")) { - if (item_data->swallow_type != SWALLOW_Type_LAYOUT_DATEFIELD) + if (item_data->swallow_type != SwallowType::LAYOUT_DATEFIELD) fp = __add_entry_padding; } else if (!safeStrCmp(part, "elm.icon.eraser")) { @@ -668,7 +617,7 @@ static Evas_Object *_gl_Gendial_content_get(void *data, Evas_Object *obj, if (cd_list) { int idx = 0; - for (; idx < SWALLOW_Type_MAX; idx++) { + for (; idx < static_cast(SwallowType::MAX); idx++) { /*match using swallow type */ if (item_data->swallow_type == cd_list[idx].type) { fp = cd_list[idx].draw; @@ -681,51 +630,36 @@ static Evas_Object *_gl_Gendial_content_get(void *data, Evas_Object *obj, static void _gl_Gendial_del(void *data, Evas_Object *obj) { - Setting_GenGroupItem_Data *item_data = - (Setting_GenGroupItem_Data *)data; + GenGroupItemData *item_data = (GenGroupItemData *)data; if (item_data) { item_data->eo_check = NULL;/*set to NULL at once */ - G_FREE(item_data->keyStr); - G_FREE(item_data->sub_desc); - G_FREE(item_data->guide_text); - G_FREE((item_data->l_swallow_path)); - G_FREE((item_data->r_swallow_path)); - G_FREE((item_data->itc)); - - if (item_data->digits_filter_data) { - G_FREE(item_data->digits_filter_data->accepted); - G_FREE(item_data->digits_filter_data->rejected); - FREE(item_data->digits_filter_data); - } + item_data->itc = {}; if (item_data->notify) { evas_object_del(item_data->notify); item_data->notify = NULL; } - FREE(item_data->limit_filter_data); __BACK_POINTER_UNSET(item_data); - FREE(item_data); + delete item_data; } } /** * Create separator style item with title * - * @return a pointer to Setting_GenGroupItem_Data + * @return a pointer to GenGroupItemData */ EXPORT_PUBLIC -Setting_GenGroupItem_Data *setting_create_Gendial_field_titleItem( +GenGroupItemData *setting_create_Gendial_field_titleItem( Evas_Object *genlist, const Elm_Genlist_Item_Class *itc, - const char *keyStr, setting_call_back_func gl_sel) + const char *keyStr, SettingCallback gl_sel) { - Setting_GenGroupItem_Data *item_data = - (Setting_GenGroupItem_Data *)calloc( - 1, sizeof(Setting_GenGroupItem_Data)); - setting_retvm_if(!item_data, NULL, "calloc failed"); - item_data->keyStr = (char *)g_strdup(keyStr); + auto item_data = new GenGroupItemData; + setting_retvm_if(!item_data, NULL, "new failed"); + item_data->keyStr = keyStr ? keyStr : std::string{}; if (itc && itc->item_style) - item_data->itc = (char *)g_strdup(itc->item_style); + item_data->itc = itc->item_style; if (gl_sel) { item_data->item = elm_genlist_item_append(genlist, itc, @@ -745,7 +679,7 @@ Setting_GenGroupItem_Data *setting_create_Gendial_field_titleItem( static void __entry_without_layout_unfocused_cb(void *data, Evas_Object *obj, void *event_info) { - Setting_GenGroupItem_Data *id = (Setting_GenGroupItem_Data *)data; + GenGroupItemData *id = (GenGroupItemData *)data; setting_retm_if(data == NULL, "invalid parameter: data is NULL"); @@ -757,18 +691,6 @@ static void __entry_without_layout_unfocused_cb(void *data, Evas_Object *obj, } -static void __error_popup_response_cb(void *data, Evas_Object *obj, - void *event_info) -{ - Setting_GenGroupItem_Data *list_item = (Setting_GenGroupItem_Data *)data; - - - retm_if(data == NULL, "Data parameter is NULL"); - - evas_object_del(list_item->notify); - list_item->notify = NULL; -} - /* Focused callback will show X marked button and hide guidetext. */ static void __entry_without_layout_focused_cb(void *data, Evas_Object *obj, void *ei) @@ -778,7 +700,7 @@ static void __entry_without_layout_focused_cb(void *data, Evas_Object *obj, Eina_Stringshare *str = NULL; - Setting_GenGroupItem_Data *id = (Setting_GenGroupItem_Data *)data; + GenGroupItemData *id = (GenGroupItemData *)data; if (!elm_entry_is_empty(obj)) { elm_object_item_signal_emit(id->item, "elm,state,eraser,show", ""); @@ -804,49 +726,39 @@ static void __entry_without_layout_focused_cb(void *data, Evas_Object *obj, static void __entry_keydown(void *data, Evas *e, Evas_Object *obj, void *event_info) { - Setting_GenGroupItem_Data *list_item = NULL; Evas_Event_Key_Down *ev = NULL; retm_if(data == NULL, "Data parameter is NULL"); retm_if(event_info == NULL, "event_info is NULL"); - list_item = (Setting_GenGroupItem_Data *)data; ev = (Evas_Event_Key_Down *)event_info; - list_item->enterKeyPressFlag = FALSE; - list_item->spaceKeyPressFlag = FALSE; /*it is for Japanese keyboard to fix N_SE-10719 */ /*to disable the 'Enter' orginal function */ if (safeStrCmp(ev->key, "KP_Enter") == 0 || safeStrCmp(ev->key, "Return") == 0) { SETTING_TRACE("ENTER %s ev->key:%s", __FUNCTION__, ev->key); - list_item->enterKeyPressFlag = TRUE; /*hide the eraser button */ /*format like:xx
*/ - if (list_item->isSinglelineFlag == FALSE) { - auto entry_str = remove_first_substring( - elm_entry_entry_get(obj), "
"); - elm_entry_entry_set(obj, entry_str); - FREE(entry_str); - elm_entry_cursor_end_set(obj); - } + auto entry_str = remove_first_substring( + elm_entry_entry_get(obj), "
"); + elm_entry_entry_set(obj, entry_str); + FREE(entry_str); + elm_entry_cursor_end_set(obj); + setting_hide_input_pannel_cb(obj); - } else { - if (safeStrCmp(ev->key, "space") == 0) - list_item->spaceKeyPressFlag = TRUE; - else - list_item->spaceKeyPressFlag = FALSE; } } static void __entry_changed(void *data, Evas_Object *obj, void *event_info) { - Setting_GenGroupItem_Data *list_item = NULL; + GenGroupItemData *list_item = NULL; Evas_Object *entry_container = NULL; retm_if(data == NULL, "Data parameter is NULL"); - list_item = (Setting_GenGroupItem_Data *)data; - list_item->sub_desc = (char *)g_strdup(elm_entry_entry_get(obj)); + list_item = (GenGroupItemData *)data; + auto str = elm_entry_entry_get(obj); + list_item->sub_desc = str ? str : std::string{}; entry_container = elm_object_parent_widget_get(obj); if (entry_container) { @@ -867,64 +779,21 @@ static void __entry_changed(void *data, Evas_Object *obj, void *event_info) } } -static void __max_len_reached(void *data, Evas_Object *obj, void *event_info) -{ - Setting_GenGroupItem_Data *list_item = NULL; - - - - retm_if(data == NULL, "Data parameter is NULL"); - /*notify only when entry is being focused on. */ - retm_if(!elm_object_focus_get(obj), "Entry is not focused"); - - list_item = (Setting_GenGroupItem_Data *)data; - - if (!list_item->notify) { - list_item->notify = setting_create_popup(list_item, - list_item->window, - NULL, EXCEED_LIMITATION_STR, - __error_popup_response_cb, - POPUP_INTERVAL, FALSE, FALSE, 0); - elm_object_focus_set(list_item->eo_check, EINA_FALSE); - } else { - /*postpone 2 seconds again */ - elm_popup_timeout_set(list_item->notify, POPUP_INTERVAL); - } - -} - -static void __rejected_char_cb(void *data, Evas_Object *obj, void *event_info) -{ - - - setting_create_popup(NULL, elm_object_parent_widget_get(obj), NULL, - _("IDS_ST_BODY_PASSWORD_CONTAINS_INVALID_CHARACTER_ABB"), - NULL, 0, false, false, 0); -} - static Evas_Object *__add_entry_without_layout( - Setting_GenGroupItem_Data *item_data, Evas_Object *parent) + GenGroupItemData *item_data, Evas_Object *parent) { Evas_Object *entry = NULL; - Ecore_IMF_Context *imf_context = NULL; /* resolve abnormal height issue */ elm_genlist_mode_set(parent, ELM_LIST_COMPRESS); item_data->eo_check = entry = elm_entry_add(parent); - if (item_data->isPasswordFlag) - elm_entry_password_set(entry, EINA_TRUE); - else if (item_data->isSinglelineFlag) - elm_entry_single_line_set(entry, EINA_TRUE); - else - elm_entry_single_line_set(entry, EINA_FALSE); + elm_entry_single_line_set(entry, EINA_FALSE); evas_object_size_hint_weight_set(entry, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND); evas_object_size_hint_align_set(entry, EVAS_HINT_FILL, EVAS_HINT_FILL); - if (item_data->focus_unallowed) - elm_object_focus_allow_set(entry, EINA_FALSE); elm_entry_input_panel_layout_set(entry, item_data->input_type); elm_entry_prediction_allow_set(entry, FALSE); @@ -935,69 +804,12 @@ static Evas_Object *__add_entry_without_layout( ELM_AUTOCAPITAL_TYPE_NONE); } - if (item_data->isSinglelineFlag) { - elm_entry_scrollable_set(entry, EINA_TRUE); - elm_entry_single_line_set(entry, EINA_TRUE); - elm_object_signal_emit(entry, "elm,state,scroll,enabled", ""); - } - - if (item_data->isPasswordFlag) { - elm_entry_password_set(entry, EINA_TRUE); - static Elm_Entry_Filter_Accept_Set accept_filter_data; - accept_filter_data.accepted = "ABCDEFGHIJKLMNOPQRSTUVWXYZ" - "abcdefghijklmnopqrstuvwxyz" - "0123456789" - "!#$%&'()*+,-./:;<=>?@[]\\^_`{|}~"; - accept_filter_data.rejected = NULL; - elm_entry_markup_filter_append(entry, - elm_entry_filter_accept_set, - &accept_filter_data); - - evas_object_smart_callback_add(entry, "rejected", - __rejected_char_cb, item_data); - } - - if (item_data->limit_filter_data) { - elm_entry_markup_filter_append(entry, - elm_entry_filter_limit_size, - item_data->limit_filter_data); + evas_object_smart_callback_add(entry, "unfocused", __entry_without_layout_unfocused_cb, item_data); - if (item_data->maxlength_reached_cb) { - evas_object_smart_callback_add(entry, - "maxlength,reached", - item_data->maxlength_reached_cb, - item_data); - } else { - evas_object_smart_callback_add(entry, - "maxlength,reached", __max_len_reached, - item_data); - } - } - - if (item_data->stop_change_cb) {/*invoked when stop focusing on */ - evas_object_smart_callback_add(entry, "unfocused", - item_data->stop_change_cb, item_data); - } else { - evas_object_smart_callback_add(entry, "unfocused", - __entry_without_layout_unfocused_cb, item_data); - } - if (item_data->digits_filter_data) { - elm_entry_markup_filter_append(entry, - elm_entry_filter_accept_set, - item_data->digits_filter_data); - } - - if (item_data->sub_desc && safeStrLen(item_data->sub_desc) > 0) { - elm_entry_entry_set(entry, item_data->sub_desc); + if (!item_data->sub_desc.empty()) { + elm_entry_entry_set(entry, item_data->sub_desc.c_str()); } else { - if (item_data->guide_text) { - /* Add guide text to elm_entry. */ - elm_object_part_text_set(entry, "elm.guide", - _(item_data->guide_text)); - } else { - elm_object_part_text_set(entry, "elm.guide", - _("IDS_ST_BODY_TAP_TO_INSERT")); - } + elm_object_part_text_set(entry, "elm.guide", _("IDS_ST_BODY_TAP_TO_INSERT")); } /* for Setting App, All the entrys's context popup shouldn't be able */ @@ -1015,49 +827,17 @@ static Evas_Object *__add_entry_without_layout( __entry_changed, item_data); } - /* callback for handling enter key */ - if (item_data->activated_cb) { - evas_object_smart_callback_add(entry, "activated", - item_data->activated_cb, item_data); - } - - if (item_data->focus_cb) { - evas_object_smart_callback_add(entry, "focused", - item_data->focus_cb, item_data); - } else { - evas_object_smart_callback_add(entry, "focused", - __entry_without_layout_focused_cb, item_data); - } + evas_object_smart_callback_add(entry, "focused", __entry_without_layout_focused_cb, item_data); - if (item_data->start_change_cb) { - evas_object_event_callback_add(entry, EVAS_CALLBACK_KEY_DOWN, - (Evas_Object_Event_Cb)( - item_data->start_change_cb), - item_data->userdata); - } else { - evas_object_event_callback_add(entry, EVAS_CALLBACK_KEY_DOWN, - __entry_keydown, item_data); - } + evas_object_event_callback_add(entry, EVAS_CALLBACK_KEY_DOWN, __entry_keydown, item_data); - imf_context = (Ecore_IMF_Context *)elm_entry_imf_context_get(entry); - typedef void (*imf_callback_t)(void*, Ecore_IMF_Context*, int); - if (imf_context && item_data->x_callback_cb) { - ecore_imf_context_input_panel_event_callback_add(imf_context, - ECORE_IMF_INPUT_PANEL_STATE_EVENT, - (imf_callback_t)item_data->x_callback_cb, item_data->userdata); - } if (item_data->input_panel_disable_flag) elm_entry_input_panel_enabled_set(entry, EINA_FALSE); - if (entry && item_data->entry_auto_focus) { - evas_object_show(entry); - elm_object_focus_set(entry, EINA_TRUE); - } - return entry; } -static Evas_Object *__add_entry_padding(Setting_GenGroupItem_Data *item_data, +static Evas_Object *__add_entry_padding(GenGroupItemData *item_data, Evas_Object *parent) { Evas_Object *layout = NULL; @@ -1117,42 +897,36 @@ static char *_handle_special_str(const char *keyStr) /** * Create common style item with menu icon * - * @return a pointer to Setting_GenGroupItem_Data + * @return a pointer to GenGroupItemData */ -static Setting_GenGroupItem_Data *setting_create_Gendial_field_groupitem( +static GenGroupItemData *setting_create_Gendial_field_groupitem( Evas_Object *genlist, const Elm_Genlist_Item_Class *itc, - Elm_Object_Item *parent, setting_call_back_func gl_sel, - void *sel_data, SWALLOW_Type swallow_type, const char *l_icon_path, + Elm_Object_Item *parent, SettingCallback gl_sel, + void *sel_data, SwallowType swallow_type, const char *l_icon_path, const char *r_icon_path, int chk_status, const char *keyStr, - const char *sub_desc, setting_call_back_func chk_change_cb) + const char *sub_desc, SettingCallback chk_change_cb) { - Setting_GenGroupItem_Data *item_data = - (Setting_GenGroupItem_Data *)calloc( - 1, sizeof(Setting_GenGroupItem_Data)); - setting_retvm_if(!item_data, NULL, "calloc failed"); + auto item_data = new GenGroupItemData; + setting_retvm_if(!item_data, NULL, "new failed"); /* to do formatting customizition in one place */ - if (SWALLOW_Type_LAYOUT_SPECIALIZTION == swallow_type - || SWALLOW_Type_LAYOUT_SPECIALIZTION_X - == swallow_type) { + if (SwallowType::LAYOUT_SPECIALIZTION == swallow_type || SwallowType::LAYOUT_SPECIALIZTION_X == swallow_type) { elm_genlist_mode_set(genlist, ELM_LIST_COMPRESS); item_data->keyStr = _handle_special_str(keyStr); } else { - item_data->keyStr = (char *)g_strdup(keyStr); + item_data->keyStr = keyStr ? keyStr : std::string{}; } - item_data->sub_desc = NULL; - if (sub_desc) - item_data->sub_desc = (char *)g_strdup(sub_desc); + item_data->sub_desc = sub_desc ? sub_desc : std::string{}; item_data->swallow_type = swallow_type; - item_data->l_swallow_path = (char *)g_strdup(l_icon_path); - item_data->r_swallow_path = (char *)g_strdup(r_icon_path); + item_data->l_swallow_path = l_icon_path ? l_icon_path : std::string{}; + item_data->r_swallow_path = r_icon_path ? r_icon_path : std::string{}; item_data->chk_status = chk_status; item_data->chk_change_cb = chk_change_cb; if (itc && itc->item_style) - item_data->itc = (char *)g_strdup(itc->item_style); + item_data->itc = itc->item_style; const char *insert_type = (const char *)evas_object_data_get(genlist, "InsertType"); @@ -1176,7 +950,7 @@ static Setting_GenGroupItem_Data *setting_create_Gendial_field_groupitem( gl_sel, sel_data); } /*help text clicking issue */ - if (SWALLOW_Type_LAYOUT_SPECIALIZTION_X == swallow_type) + if (SwallowType::LAYOUT_SPECIALIZTION_X == swallow_type) elm_genlist_item_select_mode_set(item_data->item, ELM_OBJECT_SELECT_MODE_DISPLAY_ONLY); /*redundant process,it should be due to invokers,but maybe they @@ -1187,15 +961,15 @@ static Setting_GenGroupItem_Data *setting_create_Gendial_field_groupitem( } /** * Common function to create a genlist item - * @return a pointer to Setting_GenGroupItem_Data + * @return a pointer to GenGroupItemData */ EXPORT_PUBLIC -Setting_GenGroupItem_Data *setting_create_Gendial_field_def( +GenGroupItemData *setting_create_Gendial_field_def( Evas_Object *genlist, const Elm_Genlist_Item_Class *itc, - setting_call_back_func gl_sel, void *sel_data, - SWALLOW_Type swallow_type, const char *l_icon_path, const char *r_icon_path, + SettingCallback gl_sel, void *sel_data, + SwallowType swallow_type, const char *l_icon_path, const char *r_icon_path, int chk_status, const char *keyStr, const char *sub_desc, - setting_call_back_func chk_change_cb) + SettingCallback chk_change_cb) { return setting_create_Gendial_field_groupitem(genlist, itc, NULL, gl_sel, sel_data, swallow_type, l_icon_path, @@ -1215,7 +989,7 @@ void __gl_realized_cb(void *data, Evas_Object *obj, void *event_info) /*for check,radio,slider etc.. */ EXPORT_PUBLIC -void setting_update_gl_item_chk_status(Setting_GenGroupItem_Data *item_data, +void setting_update_gl_item_chk_status(GenGroupItemData *item_data, int status) { if (item_data && item_data->chk_status != status) { diff --git a/src/setting-common-draw-popup.cpp b/src/setting-common-draw-popup.cpp index 2cce152..c25e2e1 100644 --- a/src/setting-common-draw-popup.cpp +++ b/src/setting-common-draw-popup.cpp @@ -203,7 +203,6 @@ EXPORT_PUBLIC void __popup_keygrab_del_cb(void *data, Evas *e, Evas_Object *obj, #ifdef ECORE_X - Ecore_X_Display *disp = ecore_x_display_get(); Ecore_X_Window xwin = elm_win_xwindow_get(obj); /*ungrab the "Home key" */ @@ -227,9 +226,9 @@ static void __ignore_back_key_cb(void *data, Evas_Object *obj, void *event_info) } EXPORT_PUBLIC void setting_popup_event_set2(Evas_Object *popup, void *data, - setting_call_back_func response_cb, + SettingCallback response_cb, /*to control the timeout time */ - setting_call_back_func back_cb, int timeout, + SettingCallback back_cb, int timeout, bool blocked_flag,/*to control whether to block the screen */ bool keygrab_flag/*to control whether to block the 'Home key' */ ) @@ -256,7 +255,6 @@ EXPORT_PUBLIC void setting_popup_event_set2(Evas_Object *popup, void *data, if (keygrab_flag) { #ifdef ECORE_X - Ecore_X_Display *disp = ecore_x_display_get(); Ecore_X_Window xwin = elm_win_xwindow_get(popup); int ret = eext_win_keygrab_set(xwin, "XF86Home"); @@ -277,7 +275,7 @@ EXPORT_PUBLIC void setting_popup_event_set2(Evas_Object *popup, void *data, EXPORT_PUBLIC void setting_popup_event_set(Evas_Object *popup, void *data, /*to control the timeout time */ - setting_call_back_func response_cb, int timeout, + SettingCallback response_cb, int timeout, bool blocked_flag,/*to control whether to block the screen */ bool keygrab_flag/*to control whether to block the 'Home key' */ ) @@ -305,7 +303,7 @@ EXPORT_PUBLIC void setting_popup_event_set(Evas_Object *popup, void *data, EXPORT_PUBLIC Evas_Object *setting_create_popup(void *data, Evas_Object *parent, const char *title, const char *text, - setting_call_back_func response_cb, int timeout, + SettingCallback response_cb, int timeout, bool blocked_flag, bool keygrab_flag, int btn_num, ...) { diff --git a/src/setting-common-draw-widget.cpp b/src/setting-common-draw-widget.cpp index d016b9f..35fcb6c 100644 --- a/src/setting-common-draw-widget.cpp +++ b/src/setting-common-draw-widget.cpp @@ -107,9 +107,9 @@ EXPORT_PUBLIC Evas_Object *setting_create_5step_slider( bool indicator, double slider_min, double slider_max, - setting_call_back_func slider_change_cb, - setting_call_back_func slider_start_change_cb, - setting_call_back_func slider_stop_change_cb, + SettingCallback slider_change_cb, + SettingCallback slider_start_change_cb, + SettingCallback slider_stop_change_cb, void *cb_data) { char path_str[PATH_MAX] = {'\0',}; @@ -182,61 +182,40 @@ EXPORT_PUBLIC Evas_Object *setting_create_5step_slider( */ EXPORT_PUBLIC Evas_Object *setting_create_slider( Evas_Object *parent, - Setting_GenGroupItem_Data *item_data) + GenGroupItemData *item_data) { /* "elm/slider/horizontal/default" */ Evas_Object *slider = elm_slider_add(parent); retv_if(slider == NULL, NULL); - if (item_data->isIndicatorVisible) { - elm_slider_indicator_format_set(slider, "%1.0f"); - elm_slider_indicator_show_set(slider, EINA_TRUE); - } else { - /* for brightness slider */ - elm_slider_indicator_show_set(slider, EINA_FALSE); - } + /* for brightness slider */ + elm_slider_indicator_show_set(slider, EINA_FALSE); evas_object_size_hint_weight_set(slider, EVAS_HINT_EXPAND, 0.0); evas_object_size_hint_align_set(slider, EVAS_HINT_FILL, 0.5); - double step = _step_size_calculate( - slider, item_data->slider_min, item_data->slider_max); - elm_slider_step_set(slider, step); - SETTING_TRACE("slider_change_cb:%p", item_data->chk_change_cb); if (item_data->chk_change_cb) evas_object_smart_callback_add( slider, "changed", item_data->chk_change_cb, item_data); - if (item_data->stop_change_cb) - evas_object_smart_callback_add( - slider, "slider,drag,stop", - item_data->stop_change_cb, item_data); - - if (item_data->start_change_cb) - evas_object_smart_callback_add( - slider, "slider,drag,start", - item_data->start_change_cb, item_data); - - if (item_data->l_swallow_path) { + if (!item_data->l_swallow_path.empty()) { Evas_Object *icon1 = elm_icon_add(slider); - elm_image_file_set(icon1, item_data->l_swallow_path, NULL); + elm_image_file_set(icon1, item_data->l_swallow_path.c_str(), NULL); evas_object_size_hint_aspect_set( icon1, EVAS_ASPECT_CONTROL_VERTICAL, 1, 1); elm_object_content_set(slider, icon1); } - if (item_data->r_swallow_path) { + if (!item_data->r_swallow_path.empty()) { Evas_Object *icon2 = elm_icon_add(slider); - elm_image_file_set(icon2, item_data->r_swallow_path, NULL); + elm_image_file_set(icon2, item_data->r_swallow_path.c_str(), NULL); evas_object_size_hint_aspect_set( icon2, EVAS_ASPECT_CONTROL_VERTICAL, 1, 1); elm_object_part_content_set(slider, "end", icon2); } - elm_slider_min_max_set( - slider, item_data->slider_min, item_data->slider_max); elm_slider_value_set(slider, item_data->chk_status); return slider; } @@ -245,119 +224,8 @@ EXPORT_PUBLIC Evas_Object *setting_create_slider( typedef struct _setting_gif_data { Ecore_Timer *update_timer; const char **png_list; - int cur_png_idx; } setting_gif_data; -static void __gif_del_cb( - void *data, Evas *e, Evas_Object *obj, void *event_info) -{ - - ret_if(!data); - setting_gif_data *gif_data = (setting_gif_data *)data; - if (gif_data->update_timer) {/*first delete the timer */ - ecore_timer_del(gif_data->update_timer); - gif_data->update_timer = NULL; - } - FREE(gif_data);/*delete the date. */ - evas_object_data_set(obj, "gif_data", NULL); -} - -Eina_Bool __gif_updater(void *data) -{ - retv_if(!data, FALSE); - Evas_Object *gif = (Evas_Object *)data; - setting_gif_data *gif_data = (setting_gif_data *)evas_object_data_get(gif, "gif_data"); - retv_if(!gif_data, FALSE); - /*SETTING_TRACE_BEGIN; */ - - gif_data->cur_png_idx++; - /*the last element of current array. */ - if (NULL == gif_data->png_list[gif_data->cur_png_idx]) - gif_data->cur_png_idx = 0; - - elm_image_file_set( - gif, gif_data->png_list[gif_data->cur_png_idx], NULL); - int w = 0; - int h = 0; - elm_image_object_size_get(gif, &w, &h); - setting_resize_object(gif, w, h); - - return TRUE; -} - -EXPORT_PUBLIC -Evas_Object *setting_create_image(Evas_Object *parent, const char *img_path) -{ - Evas_Object *image = elm_image_add(parent); - elm_image_file_set(image, img_path, NULL); - elm_image_resizable_set(image, EINA_TRUE, EINA_TRUE); - - int w = 0; - int h = 0; - elm_image_object_size_get(image, &w, &h); - setting_resize_object(image, w, h); - evas_object_show(image); - return image; -} - -/* @png_list is an array end with 'NULL'. like , - const char *png_list[] = { - SETTING_ICON_PATH_CFG"motions/motion_overturn_01.png", - SETTING_ICON_PATH_CFG"motions/motion_overturn_02.png", - SETTING_ICON_PATH_CFG"motions/motion_overturn_03.png", - SETTING_ICON_PATH_CFG"motions/motion_overturn_04.png", - SETTING_ICON_PATH_CFG"motions/motion_overturn_05.png", - NULL //must end with 'NULL' - }; -*/ -EXPORT_PUBLIC -Evas_Object *setting_create_gif(Evas_Object *parent, const char **png_list) -{ - retv_if(!png_list, NULL); - setting_gif_data *gif_data = (setting_gif_data *)calloc(1, sizeof(setting_gif_data)); - setting_retvm_if(!gif_data, NULL, "calloc failed"); - gif_data->cur_png_idx = 0; - gif_data->png_list = png_list; - - - - /*the first element */ - Evas_Object *gif = setting_create_image(parent, *png_list); - /*bind object data */ - evas_object_data_set(gif, "gif_data", gif_data); - evas_object_event_callback_add( - gif, EVAS_CALLBACK_DEL, __gif_del_cb, gif_data); - - if (gif_data->update_timer) { - ecore_timer_del(gif_data->update_timer); - gif_data->update_timer = NULL; - } - gif_data->update_timer = ecore_timer_add( - DEMO_STEP, (Ecore_Task_Cb)__gif_updater, gif); - - /* W011:bg, T051:text */ - setting_decorate_image_RGBA(gif, 14, 41, 73, 255); - return gif; -} - -/** -* To resize a evas object, such as, icon, button.. -* -* @param[in] obj -* @param[in] w -* @param[in] h -*/ -EXPORT_PUBLIC -void setting_resize_object(Evas_Object *obj, Evas_Coord w, Evas_Coord h) -{ - if (obj) { - evas_object_size_hint_min_set( - obj, ELM_SCALE_SIZE(w), ELM_SCALE_SIZE(h)); - evas_object_size_hint_max_set(obj, w, h); - evas_object_resize(obj, w, h); - } -} - EXPORT_PUBLIC void setting_conformant_keypad_state( Evas_Object *window, bool enable) { diff --git a/src/setting-common-draw-widget.h b/src/setting-common-draw-widget.h index 51ea9f7..c8afafc 100755 --- a/src/setting-common-draw-widget.h +++ b/src/setting-common-draw-widget.h @@ -65,29 +65,29 @@ extern void setting_hide_input_pannel_cb(Evas_Object *entry); /** * Create separator style item with title - * @return a pointer to Setting_GenGroupItem_Data + * @return a pointer to GenGroupItemData */ -extern Setting_GenGroupItem_Data *setting_create_Gendial_field_titleItem( +extern GenGroupItemData *setting_create_Gendial_field_titleItem( Evas_Object *genlist, const Elm_Genlist_Item_Class *itc, - const char *keyStr, setting_call_back_func gl_sel); + const char *keyStr, SettingCallback gl_sel); /** * Common function to create a genlist item - * @return a pointer to Setting_GenGroupItem_Data + * @return a pointer to GenGroupItemData */ -Setting_GenGroupItem_Data *setting_create_Gendial_field_def( +GenGroupItemData *setting_create_Gendial_field_def( Evas_Object *genlist, const Elm_Genlist_Item_Class *itc, - setting_call_back_func gl_sel, void *sel_data, - SWALLOW_Type swallow_type, const char *l_icon_path, const char *r_icon_path, + SettingCallback gl_sel, void *sel_data, + SwallowType swallow_type, const char *l_icon_path, const char *r_icon_path, int chk_status, const char *keyStr, const char *sub_desc, - setting_call_back_func chk_change_cb); + SettingCallback chk_change_cb); /** * To create slider object of a genlist item * @return a slider container object */ extern Evas_Object *setting_create_slider(Evas_Object *window, - Setting_GenGroupItem_Data *item_data); + GenGroupItemData *item_data); /** * To create slider object of a genlist item @@ -97,23 +97,9 @@ extern Evas_Object *setting_create_5step_slider(Evas_Object *window, Evas *evas, const char *l_swallow_path, const char *r_swallow_path, double value, bool indicator, double slider_min, double slider_max, - setting_call_back_func slider_change_cb, - setting_call_back_func slider_start_change_cb, - setting_call_back_func slider_stop_change_cb, void *cb_data); - -/** - * The API to Create an object to show an image - * @return an object to show an image - */ -extern Evas_Object *setting_create_image(Evas_Object *parent, - const char *img_path); - -/** - * The API to Create an object to show anamition image - * @return an object to show anamition image - */ -extern Evas_Object *setting_create_gif(Evas_Object *parent, - const char **png_list); + SettingCallback slider_change_cb, + SettingCallback slider_start_change_cb, + SettingCallback slider_stop_change_cb, void *cb_data); /** * The API to Create a button @@ -123,16 +109,10 @@ extern Evas_Object *setting_create_button(Evas_Object *parent, const char *btn_str, const char *btn_style, Evas_Smart_Cb btn_click_cb, void *cb_data); -/** - * To resize a evas object, such as, icon, button.. - * - */ -extern void setting_resize_object(Evas_Object *obj, Evas_Coord w, Evas_Coord h); - extern void __gl_realized_cb(void *data, Evas_Object *obj, void *event_info); extern void setting_update_gl_item_chk_status( - Setting_GenGroupItem_Data *item_data, int status); + GenGroupItemData *item_data, int status); extern void setting_conformant_keypad_state(Evas_Object *conform, bool enable); @@ -142,7 +122,7 @@ extern void setting_decorate_image_RGBA(Evas_Object *obj, int r, int g, int b, extern void setting_popup_del_cb(void *data, Evas_Object *obj, void *event_info); extern void setting_popup_event_set(Evas_Object *popup, void *data, - setting_call_back_func response_cb, + SettingCallback response_cb, int timeout,/*to control the timeout time */ bool blocked_flag,/*to control whether to block the screen */ bool keygrab_flag/*to control whether to block the 'Home key' */ @@ -166,7 +146,7 @@ extern void setting_popup_event_set(Evas_Object *popup, void *data, **********************************************************/ EXPORT_PUBLIC Evas_Object *setting_create_popup(void *data, Evas_Object *parent, const char *title, const char *text, - setting_call_back_func response_cb, int timeout, + SettingCallback response_cb, int timeout, bool blocked_flag, bool keygrab_flag, int btn_num, ...); @@ -187,7 +167,7 @@ EXPORT_PUBLIC Evas_Object *setting_create_popup(void *data, Evas_Object *parent, EXPORT_PUBLIC Evas_Object *setting_create_popup_with_list( Evas_Object **genlist, void *data, Evas_Object *parent, const char *title, - setting_call_back_func response_cb, int timeout, + SettingCallback response_cb, int timeout, bool blocked_flag, bool keygrab_flag, int btn_num, ...); diff --git a/src/setting-common-general-func.cpp b/src/setting-common-general-func.cpp index 74e70ba..0b5d55c 100755 --- a/src/setting-common-general-func.cpp +++ b/src/setting-common-general-func.cpp @@ -106,25 +106,6 @@ int safeStrNCmp(const char *s1, const char *s2, int len) } EXPORT_PUBLIC -char *safeCopyStr(char *dst, const char *src, int maxlen) -{ - if (maxlen < 0) - return NULL; - - if (dst) { - int len = 0; - - if (src) { - int temp = (int)safeStrLen(src); - len = (temp <= maxlen) ? temp : maxlen; - memcpy(dst, src, len); - } - dst[len] = '\0'; - } - return dst; -} - -EXPORT_PUBLIC int safeStrLen(const char *str) { if (isEmptyStr(str)) { diff --git a/src/setting-common-general-func.h b/src/setting-common-general-func.h index cb50e48..40b1518 100755 --- a/src/setting-common-general-func.h +++ b/src/setting-common-general-func.h @@ -33,7 +33,6 @@ /*****/ int safeStrCmp(const char *s1, const char *s2); int safeStrNCmp(const char *s1, const char *s2, int len); -char *safeCopyStr(char *dst, const char *src, int maxlen); bool isEmptyStr(const char *str); char *remove_first_substring(const char *parent, const char *pat); int safeStrLen(const char *str); -- 2.7.4 From e9018720a3d6568313c64e66104d2283b6ce9b1b Mon Sep 17 00:00:00 2001 From: Lukasz Wlazly Date: Tue, 2 Oct 2018 10:22:38 +0200 Subject: [PATCH 04/16] [Cpp refactor] Refactor of Item_Wrapper class Change-Id: I8a7a5568618c085e2ba5027c1bbb8dacc6dc23b2 --- ...etting-accessibility-accessibility-launcher.cpp | 67 +++++++++------------- src/setting-common-string.h | 2 - src/utils.hpp | 11 ++++ 3 files changed, 39 insertions(+), 41 deletions(-) create mode 100644 src/utils.hpp diff --git a/src/setting-accessibility-accessibility-launcher.cpp b/src/setting-accessibility-accessibility-launcher.cpp index 9ecf677..ac9301e 100644 --- a/src/setting-accessibility-accessibility-launcher.cpp +++ b/src/setting-accessibility-accessibility-launcher.cpp @@ -20,15 +20,23 @@ */ #include "setting-accessibility-accessibility-launcher.h" +#include "utils.hpp" #include #include -#define ITEMS_COUNT 3 -#define NAME_MAX_LENGTH 64 +#include -struct __Item_Wrapper{ - char name[NAME_MAX_LENGTH]; +namespace { + const std::string LAUNCHER_NAMES[3] = { + _("IDS_ST_BODY_ACCESSIBILITY"), + _("IDS_ST_MBODY_SCREEN_READER_HTTS"), + _(DEVOPTION_STR_ACCESSIBILITY_UNIVERSAL_SWITCH) + }; +} + +struct ItemWrapper{ + std::string name; GenGroupItemData *item; }; @@ -36,8 +44,8 @@ static Eina_Bool __naviframe_pop_cb(void *data, Elm_Object_Item *it) { retv_if(data == NULL, EINA_TRUE); - __Item_Wrapper *items = (__Item_Wrapper *)data; - free(items); + ItemWrapper *items = (ItemWrapper *)data; + delete[] items; return EINA_TRUE; } @@ -51,11 +59,10 @@ static void __back_cb(void *data, Evas_Object *obj, void *event_info) } -static void __update_vconf(__Item_Wrapper *items) +static void __update_vconf(ItemWrapper *items) { int value = 0; - int i; - for (i = 0; i < ITEMS_COUNT; i++) + for (auto i = 0u; i < utils::lenOf(LAUNCHER_NAMES); i++) if (items[i].item->chk_status) value = value | (1 << i); vconf_set_int(VCONFKEY_SETAPPL_ACCESSIBILITY_ACCESSIBILITY_LAUNCHER_LAUNCH, value); @@ -67,7 +74,7 @@ static void __accessibility_launcher_item_checkbox_cb(void *data, Evas_Object *o retm_if(data == NULL, "Input parameter is NULL"); GenGroupItemData *list_item = (GenGroupItemData *)data; list_item->chk_status = !list_item->chk_status; - __update_vconf((__Item_Wrapper*)list_item->userdata); + __update_vconf((ItemWrapper*)list_item->userdata); } @@ -79,68 +86,51 @@ static void __accessibility_launcher_item_selected(void *data, Evas_Object *obj, elm_genlist_item_selected_set(item, EINA_FALSE); GenGroupItemData *list_item = (GenGroupItemData *)elm_object_item_data_get(item); setting_update_gl_item_chk_status(list_item, list_item->chk_status ? 0 : 1); - __update_vconf((__Item_Wrapper*)list_item->userdata); + __update_vconf((ItemWrapper*)list_item->userdata); } static void __accessibility_launcher_state_update_name(GenGroupItemData *item) { - - char *item_label = item->chk_status ? _(DEVOPTION_STR_ACCESSIBILITY_ACCESSIBILITY_LAUNCHER_ON) : _(DEVOPTION_STR_ACCESSIBILITY_ACCESSIBILITY_LAUNCHER_OFF); - - if (item_label && strlen(item_label) > 0) { - item->keyStr = item_label; - } - + item->keyStr = item->chk_status ? _(DEVOPTION_STR_ACCESSIBILITY_ACCESSIBILITY_LAUNCHER_ON) : _(DEVOPTION_STR_ACCESSIBILITY_ACCESSIBILITY_LAUNCHER_OFF); elm_genlist_item_update(item->item); - } static void __updete_main_switch(GenGroupItemData *list_item) { - retm_if(list_item == NULL, "Data parameter is NULL"); __accessibility_launcher_state_update_name(list_item); vconf_set_bool(VCONFKEY_SETAPPL_ACCESSIBILITY_ACCESSIBILITY_LAUNCHER_STATE, list_item->chk_status); - __Item_Wrapper *items = (__Item_Wrapper *)list_item->userdata; - int i; - for (i = 0; i < ITEMS_COUNT; i++) + ItemWrapper *items = (ItemWrapper *)list_item->userdata; + for (auto i = 0u; i < utils::lenOf(LAUNCHER_NAMES); i++) elm_object_item_disabled_set(items[i].item->item, list_item->chk_status ? EINA_FALSE : EINA_TRUE); - - } static void __accessibility_launcher_checkbox_cb(void *data, Evas_Object *obj, void *event_info) { - retm_if(data == NULL, "Data parameter is NULL"); GenGroupItemData *list_item = (GenGroupItemData *)data; list_item->chk_status = !list_item->chk_status; __updete_main_switch(list_item); - } static void __accessibility_launcher_off_mouse_up_Gendial_list_cb(void *data, Evas_Object *obj, void *event_info) { - retm_if(data == NULL, "Invalid argument: data is NULL"); Elm_Object_Item *item = (Elm_Object_Item *)event_info; elm_genlist_item_selected_set(item, EINA_FALSE); GenGroupItemData *list_item = (GenGroupItemData *)elm_object_item_data_get(item); setting_update_gl_item_chk_status(list_item, list_item->chk_status ? 0 : 1); __updete_main_switch(list_item); - } void setting_accessibility_accessibility_launcher_page_create(SettingAccessibility *ad) { + auto items = new ItemWrapper[utils::lenOf(LAUNCHER_NAMES)]; - - __Item_Wrapper *items = (__Item_Wrapper *)calloc(sizeof(__Item_Wrapper), ITEMS_COUNT); - retm_if(items == NULL, "calloc failed"); - strncpy(items[0].name, _(KeyStr_Accessibility), NAME_MAX_LENGTH); - strncpy(items[1].name, _("IDS_ST_MBODY_SCREEN_READER_HTTS"), NAME_MAX_LENGTH); - strncpy(items[2].name, _(DEVOPTION_STR_ACCESSIBILITY_UNIVERSAL_SWITCH), NAME_MAX_LENGTH); + retm_if(items == NULL, "new failed"); + for (auto i = 0u; i < utils::lenOf(LAUNCHER_NAMES); ++i) + items[i].name = LAUNCHER_NAMES[i]; int ret; int state = 0; @@ -148,7 +138,7 @@ void setting_accessibility_accessibility_launcher_page_create(SettingAccessibili Evas_Object *genlist = elm_genlist_add(ad->md.getNaviframe()); if (genlist == NULL) { SETTING_TRACE_ERROR("Cannot set genlist object as content of layout"); - free(items); + delete[] items; return; } @@ -188,13 +178,12 @@ void setting_accessibility_accessibility_launcher_page_create(SettingAccessibili if (ret != VCONF_OK) { SETTING_TRACE("FAIL: vconf_get_int(VCONFKEY_SETAPPL_ACCESSIBILITY_ACCESSIBILITY_LAUNCHER_LAUNCH)"); } - int i; - for (i = 0; i < ITEMS_COUNT; i++) { + for (auto i = 0u; i < utils::lenOf(LAUNCHER_NAMES); i++) { GenGroupItemData *item = setting_create_Gendial_field_def( genlist, &itc_1text_1icon, __accessibility_launcher_item_selected, ad, SwallowType::ICON_RADIO, NULL, - NULL, vconf_state & (1 << i), items[i].name, + NULL, vconf_state & (1 << i), items[i].name.c_str(), NULL, __accessibility_launcher_item_checkbox_cb); if (item) { diff --git a/src/setting-common-string.h b/src/setting-common-string.h index b4cfcc9..8c2493f 100755 --- a/src/setting-common-string.h +++ b/src/setting-common-string.h @@ -34,8 +34,6 @@ #define SETTING_IMAGE_PATH_CFG TZ_SYS_RO_APP_D"/org.tizen.setting/res/images/" -#define KeyStr_Accessibility "IDS_ST_BODY_ACCESSIBILITY" - #define KeyStr_Save "IDS_ST_BODY_SAVE" #endif /* __SETTING_COMMON_STRING_H__ */ diff --git a/src/utils.hpp b/src/utils.hpp new file mode 100644 index 0000000..82521ea --- /dev/null +++ b/src/utils.hpp @@ -0,0 +1,11 @@ +#ifndef UTILS_HPP +#define UTILS_HPP + +namespace utils +{ + template + size_t lenOf(const T(&)[len]) { return len; } +} + + +#endif -- 2.7.4 From 81c7ca7d917408ad72e44fdc39758dfbe4eb24c0 Mon Sep 17 00:00:00 2001 From: Lukasz Wlazly Date: Tue, 2 Oct 2018 11:09:54 +0200 Subject: [PATCH 05/16] [Cpp refactor] Refactor of v_conf_check_data class Change-Id: I12e6cb81c16a4635c50870a2fe1aa49432e97270 --- ...etting-accessibility-screen-reader-settings.cpp | 83 +++++++++------------- 1 file changed, 32 insertions(+), 51 deletions(-) diff --git a/src/setting-accessibility-screen-reader-settings.cpp b/src/setting-accessibility-screen-reader-settings.cpp index 27dfe2d..04320cb 100755 --- a/src/setting-accessibility-screen-reader-settings.cpp +++ b/src/setting-accessibility-screen-reader-settings.cpp @@ -19,59 +19,41 @@ * */ + #include #include #include #include #include +#include "utils.hpp" + #include "setting-accessibility-screen-reader-settings.h" #include +#include #define POPUP_CONTENT_BASE_SIZE 120 -struct vconf_check_data_s{ - const char *label; - const char *vconf_key; - int *status; +struct VConfCheckData{ + std::string label; + std::string vconf_key; + int *status = nullptr; }; - -vconf_check_data_s vconf_check_data[] = { - { - .label = DEVOPTION_STR_ACCESSIBILITY_INDICATOR_TIME, - .vconf_key = VCONFKEY_SETAPPL_ACCESSIBILITY_TTS_INDICATOR_INFORMATION_TIME, - .status = NULL - }, - { - .label = DEVOPTION_STR_ACCESSIBILITY_INDICATOR_DATE, - .vconf_key = VCONFKEY_SETAPPL_ACCESSIBILITY_TTS_INDICATOR_INFORMATION_DATE, - .status = NULL - }, - { - .label = DEVOPTION_STR_ACCESSIBILITY_INDICATOR_BATTERY, - .vconf_key = VCONFKEY_SETAPPL_ACCESSIBILITY_TTS_INDICATOR_INFORMATION_BATTERY, - .status = NULL - }, - { - .label = DEVOPTION_STR_ACCESSIBILITY_INDICATOR_SIGNAL_STRENGTH, - .vconf_key = VCONFKEY_SETAPPL_ACCESSIBILITY_TTS_INDICATOR_INFORMATION_SIGNAL_STRENGHT, - .status = NULL - }, - { - .label = DEVOPTION_STR_ACCESSIBILITY_INDICATOR_BLUETOOTH, - .vconf_key = VCONFKEY_SETAPPL_ACCESSIBILITY_TTS_INDICATOR_INFORMATION_BLUETOOTH, - .status = NULL - }, - { - .label = DEVOPTION_STR_ACCESSIBILITY_INDICATOR_MISSED_EVENTS, - .vconf_key = VCONFKEY_SETAPPL_ACCESSIBILITY_TTS_INDICATOR_INFORMATION_MISSED_EVENTS, - .status = NULL - } -}; -static std::vector items; - -static GenGroupItemData *speech_rate_list_item = NULL; +namespace { + VConfCheckData vConfCheckData[] = { + { DEVOPTION_STR_ACCESSIBILITY_INDICATOR_TIME, VCONFKEY_SETAPPL_ACCESSIBILITY_TTS_INDICATOR_INFORMATION_TIME }, + { DEVOPTION_STR_ACCESSIBILITY_INDICATOR_DATE, VCONFKEY_SETAPPL_ACCESSIBILITY_TTS_INDICATOR_INFORMATION_DATE }, + { DEVOPTION_STR_ACCESSIBILITY_INDICATOR_BATTERY, VCONFKEY_SETAPPL_ACCESSIBILITY_TTS_INDICATOR_INFORMATION_BATTERY }, + { DEVOPTION_STR_ACCESSIBILITY_INDICATOR_SIGNAL_STRENGTH, VCONFKEY_SETAPPL_ACCESSIBILITY_TTS_INDICATOR_INFORMATION_SIGNAL_STRENGHT }, + { DEVOPTION_STR_ACCESSIBILITY_INDICATOR_BLUETOOTH, VCONFKEY_SETAPPL_ACCESSIBILITY_TTS_INDICATOR_INFORMATION_BLUETOOTH }, + { DEVOPTION_STR_ACCESSIBILITY_INDICATOR_MISSED_EVENTS, VCONFKEY_SETAPPL_ACCESSIBILITY_TTS_INDICATOR_INFORMATION_MISSED_EVENTS } + }; + + std::vector items; + + GenGroupItemData *speech_rate_list_item = NULL; +} static Eina_Bool __page_hide(void *data, Elm_Object_Item *it) { @@ -122,12 +104,11 @@ static void _vconf_key_value_set(const char *key, int value) static void _vconf_key_foreach_check_set(void) { int i; - int size = sizeof(vconf_check_data) / sizeof(vconf_check_data[0]); + int size = utils::lenOf(vConfCheckData); for (i = 0; i < size; ++i) { - const char *key = vconf_check_data[i].vconf_key; - auto status = *(vconf_check_data[i].status); - _vconf_key_value_set(key, status); + auto status = *(vConfCheckData[i].status); + _vconf_key_value_set(vConfCheckData[i].vconf_key.c_str(), status); } } @@ -227,7 +208,7 @@ static void _on_popup_del(void *data, Evas *e, Evas_Object *obj, if (0 != tts_setting_get_speed_range(&s_speed_min, &s_speed_normal, &s_speed_max)) SETTING_TRACE("Fail to get speed range"); double s_speed_percent = (((double)speed_val - (double)s_speed_min)/((double)s_speed_max - (double)s_speed_min)) * 100; - snprintf(buf, sizeof(buf), "%.0f%%", s_speed_percent); + snprintf(buf, utils::lenOf(buf), "%.0f%%", s_speed_percent); SETTING_TRACE("Updating speed to %s", buf); speech_rate_list_item->sub_desc = buf; elm_genlist_item_update(speech_rate_list_item->item); @@ -311,7 +292,7 @@ static void __tts_setting_speed_changed_cb(int speed, void *user_data) (GenGroupItemData *)user_data; char buf[256]; - snprintf(buf, sizeof(buf), "%d", speed); + snprintf(buf, utils::lenOf(buf), "%d", speed); elm_object_item_part_text_set(speech_rate_item->item, "elm.text.2", buf); @@ -492,7 +473,7 @@ static void _status_bar_info_mouse_up_Gendial_list_cb( Evas_Object *genlist; GenGroupItemData *screenreader_checkbox = NULL; int i; - int size = sizeof(vconf_check_data) / sizeof(vconf_check_data[0]); + int size = utils::lenOf(vConfCheckData); elm_genlist_item_selected_set(item, EINA_FALSE); @@ -518,16 +499,16 @@ static void _status_bar_info_mouse_up_Gendial_list_cb( EVAS_HINT_FILL); for (i = 0; i < size; ++i) { - auto status = _vconf_key_value_get(vconf_check_data[i].vconf_key); + auto status = _vconf_key_value_get(vConfCheckData[i].vconf_key.c_str()); screenreader_checkbox = setting_create_Gendial_field_def( genlist, &itc_1text_1icon, _list_item_clicked_cb, ad, SwallowType::ICON_RADIO, NULL, - NULL, status, _(vconf_check_data[i].label), + NULL, status, _(vConfCheckData[i].label.c_str()), NULL, _check_state_changed_cb); - vconf_check_data[i].status = &screenreader_checkbox->chk_status; + vConfCheckData[i].status = &screenreader_checkbox->chk_status; items.push_back(screenreader_checkbox); } @@ -601,7 +582,7 @@ void setting_accessibility_screen_reader_settings_page_create( if (0 != tts_setting_get_speed_range(&s_speed_min, &s_speed_normal, &s_speed_max)) SETTING_TRACE("Fail to get speed range"); double s_speed_percent = (((double)s_speed - (double)s_speed_min)/((double)s_speed_max - (double)s_speed_min)) * 100; - snprintf(buf, sizeof(buf), "%.0f%%", s_speed_percent); + snprintf(buf, utils::lenOf(buf), "%.0f%%", s_speed_percent); SETTING_TRACE("TTS rate is %.0f", s_speed_percent); /* Item 1 : Speech Rate */ -- 2.7.4 From 2231e2c20d50259d075789e235b9a628f3cd2dd1 Mon Sep 17 00:00:00 2001 From: Lukasz Wlazly Date: Wed, 3 Oct 2018 09:01:39 +0200 Subject: [PATCH 06/16] [Cpp refactor] Add method to MainData class Change-Id: Id3b88186af9023bcd5c156484708a5fb702d502c --- src/MainData.cpp | 17 +++++++++++ src/MainData.hpp | 2 ++ src/setting-accessibility-main.cpp | 2 +- src/setting-common-draw-naviframe.cpp | 53 ----------------------------------- src/setting-common-draw-naviframe.h | 37 ------------------------ src/setting-common-draw-widget.h | 1 - 6 files changed, 20 insertions(+), 92 deletions(-) delete mode 100644 src/setting-common-draw-naviframe.cpp delete mode 100644 src/setting-common-draw-naviframe.h diff --git a/src/MainData.cpp b/src/MainData.cpp index d40795d..ae7959c 100644 --- a/src/MainData.cpp +++ b/src/MainData.cpp @@ -1,8 +1,11 @@ #include "MainData.hpp" + #include "setting-common-general-func.h" #include "setting-common-draw-widget.h" #include "setting-debug.h" + #include +#include int MainData::initApp(const std::string &name) { @@ -141,3 +144,17 @@ void MainData::onAllGenlistRealizedCb(void *data, Evas_Object *obj, void *event_ GenGroupItemData *item_data = (GenGroupItemData *)elm_object_item_data_get(item); ret_if(!item_data); } + +void MainData::addBackButton(Elm_Naviframe_Item_Pop_Cb view_pop_cb, void *ad) const +{ + auto back_button = setting_create_button(naviframe, _("IDS_ST_BUTTON_BACK"), NAVI_BACK_ARROW_BUTTON_STYLE, softkeyBackClickCb, naviframe); + elm_layout_content_set(naviframe, "prev_btn", back_button); + elm_naviframe_item_pop_cb_set(naviframe_it, view_pop_cb, ad); +} + +void MainData::softkeyBackClickCb(void *data, Evas_Object *obj, void *event_inf) +{ + auto naviframe = static_cast(data); + ret_if(!naviframe); + elm_naviframe_item_pop(naviframe); +} diff --git a/src/MainData.hpp b/src/MainData.hpp index 93e1653..00453e8 100644 --- a/src/MainData.hpp +++ b/src/MainData.hpp @@ -13,6 +13,7 @@ public: Evas_Object* getWindow() const; Evas_Object* getNaviframe() const; Evas_Object* getGenlist() const; + void addBackButton(Elm_Naviframe_Item_Pop_Cb view_pop_cb, void *ad) const; Elm_Object_Item *naviframe_it; private: @@ -21,6 +22,7 @@ private: void prepareViewList(); void createMainWindow(const std::string &name); static void onAllGenlistRealizedCb(void *data, Evas_Object *obj, void *event_info); + static void softkeyBackClickCb(void *data, Evas_Object *obj, void *event_inf); Evas *evas; Evas_Object *window; diff --git a/src/setting-accessibility-main.cpp b/src/setting-accessibility-main.cpp index c88c650..3ba8726 100644 --- a/src/setting-accessibility-main.cpp +++ b/src/setting-accessibility-main.cpp @@ -179,7 +179,7 @@ static int setting_accessibility_main_create(void *cb) ad->md.initView(_("IDS_ST_BODY_ACCESSIBILITY")); elm_object_style_set(ad->md.getGenlist(), "dialogue"); - setting_add_back_button(&ad->md, _cancel_cb, ad); + ad->md.addBackButton(_cancel_cb, ad); setting_accessibility_main_generate_genlist((void *)ad); diff --git a/src/setting-common-draw-naviframe.cpp b/src/setting-common-draw-naviframe.cpp deleted file mode 100644 index b47c99c..0000000 --- a/src/setting-common-draw-naviframe.cpp +++ /dev/null @@ -1,53 +0,0 @@ -/* - * setting - * - * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. - * - * Contact: MyoungJune Park - * - * 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. - * - */ - -#include -#include -#include "setting-common-draw-widget.h" - -#include - -/** - * default back softkey callback func needed in setting_add_back_button() - * @param data: naviframe to do item_pop on it - */ -static void __softkey_back_click_cb(void *data, Evas_Object *obj, - void *event_info) -{ - - Evas_Object *naviframe = (Evas_Object *)data; - ret_if(!naviframe); - elm_naviframe_item_pop(naviframe); -} - -/** - * The general API to add back button with callback - */ -EXPORT_PUBLIC -void setting_add_back_button(MainData *md, - Elm_Naviframe_Item_Pop_Cb view_pop_cb, void *ad) -{ - Evas_Object *back_button = NULL; - - back_button = setting_create_button(md->getNaviframe(), _("IDS_ST_BUTTON_BACK"), NAVI_BACK_ARROW_BUTTON_STYLE, __softkey_back_click_cb, md->getNaviframe()); - elm_layout_content_set(md->getNaviframe(), "prev_btn", back_button); - elm_naviframe_item_pop_cb_set(md->naviframe_it, view_pop_cb, ad); -} diff --git a/src/setting-common-draw-naviframe.h b/src/setting-common-draw-naviframe.h deleted file mode 100644 index 13a48b7..0000000 --- a/src/setting-common-draw-naviframe.h +++ /dev/null @@ -1,37 +0,0 @@ -/* - * setting - * - * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. - * - * Contact: MyoungJune Park - * - * 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. - * - */ -/** - *default group setting-common-draw-naviframe - *common UI code for reuse - */ -#ifndef __SETTING_COMMON_DRAW_NAVIFRAME_H__ -#define __SETTING_COMMON_DRAW_NAVIFRAME_H__ - -#include "MainData.hpp" - -/** - * The general API to add back button with callback - */ -EXPORT_PUBLIC -void setting_add_back_button(MainData *md, - Elm_Naviframe_Item_Pop_Cb view_pop_cb, void *ad); - -#endif /* __SETTING_COMMON_DRAW_NAVIFRAME_H__ */ diff --git a/src/setting-common-draw-widget.h b/src/setting-common-draw-widget.h index c8afafc..c1fb297 100755 --- a/src/setting-common-draw-widget.h +++ b/src/setting-common-draw-widget.h @@ -27,7 +27,6 @@ #include "setting-common-data-type.h" #include "setting-common-general-func.h" -#include "setting-common-draw-naviframe.h" #define SETTING_COMMON_DRAW_WIDGET_CONTROLBAR_ITEM_LEN 3 #define POPUP_INTERVAL 2.0 -- 2.7.4 From 0254eb3c2eb27ad0d6ce21d9dfa822d1db4e572e Mon Sep 17 00:00:00 2001 From: Lukasz Wlazly Date: Wed, 3 Oct 2018 12:05:54 +0200 Subject: [PATCH 07/16] [Cpp refactor] Refactor of SettingAccessibility class Change-Id: I818317cea43f170c21ef907c6fc0e86de321777f --- src/SettingAccessibility.hpp | 76 ++++++++++++++++++++++++++++++++++++ src/UniversalSwitchConfiguration.hpp | 1 + src/setting-accessibility.h | 71 +-------------------------------- 3 files changed, 78 insertions(+), 70 deletions(-) create mode 100644 src/SettingAccessibility.hpp diff --git a/src/SettingAccessibility.hpp b/src/SettingAccessibility.hpp new file mode 100644 index 0000000..e7952cf --- /dev/null +++ b/src/SettingAccessibility.hpp @@ -0,0 +1,76 @@ +#ifndef SETTING_ACCESSIBILITY_HPP +#define SETTING_ACCESSIBILITY_HPP + +#include "MainData.hpp" +#include "SetValueLayout.hpp" +#include "UniversalSwitchConfiguration.hpp" + +typedef void (*back_cb)(SettingAccessibility *ad); + +struct SettingAccessibility { + MainData md; + Elm_Genlist_Item_Class itc_1text; + Elm_Genlist_Item_Class itc_multiline_sub; + Evas_Object *popup; + Evas_Object *entry; + Evas_Object *all_checkbox; + Evas_Object *remove_switches_page_button; + Evas_Object *remove_switches_popup_button; + Evas_Object *update_accessories_action_genlist; + Evas_Object *universal_switch_settings_btn; + + Elm_Object_Item *save_object_item; + Elm_Object_Item *universal_switch_main_item; + Elm_Object_Item *universal_switch_settings_item; + Elm_Object_Item *naviframe_it; + SetValueLayout set_value_layout; + + GenGroupItemData *speech_rate_item; + GenGroupItemData *keyboard_feedback_item; + GenGroupItemData *hints_item; + GenGroupItemData *vibration_feedback_item; + GenGroupItemData *sound_feedback_item; + GenGroupItemData *status_bar_information_item; + GenGroupItemData *multiline_status_bar_information_description; + GenGroupItemData *screenreader_checkbox; + GenGroupItemData *multiline_screen_reader_comment; + GenGroupItemData *screen_reader_settings; + GenGroupItemData *screen_reader_item; + GenGroupItemData *universal_switch_item; + GenGroupItemData *universal_switch_off_checkbox; + GenGroupItemData *universal_switch_comment; + GenGroupItemData *universal_switch_add_switch_screen; + GenGroupItemData *universal_switch_add_switch_accessories; + GenGroupItemData *universal_switch_add_switch_camera; + GenGroupItemData *universal_switch_camera_comment; + GenGroupItemData *universal_switch_settings_switches; + GenGroupItemData *universal_switch_auto_scan_int; + GenGroupItemData *universal_switch_scans_num; + GenGroupItemData *universal_switch_scan_method; + GenGroupItemData *universal_switch_scan_dir; + GenGroupItemData *universal_switch_scan_speed; + GenGroupItemData *universal_switch_pause_on_first; + GenGroupItemData *universal_switch_tap_duration; + GenGroupItemData *universal_switch_sgl_iaction_int; + GenGroupItemData *universal_switch_auto_tap; + GenGroupItemData *universal_switch_auto_move_int; + GenGroupItemData *universal_switch_feedback_cursor_cl; + GenGroupItemData *universal_switch_feedback_sound; + GenGroupItemData *universal_switch_feedback_sound_volume; + GenGroupItemData *universal_switch_feedback_voice; + GenGroupItemData *universal_switch_feedback_voice_speech_rate; + GenGroupItemData *universal_switch_feedback_voice_speech_volume; + + Elm_Genlist *universal_switch_switches; + back_cb universal_switch_switches_back; + + tts_h tts; + + UniversalSwitchDbusConfig config; + UniversalSwitchConfigurationItem config_item_to_update; + UniversalSwitchConfiguration us_configuration; + int switches_to_remove_counter; + bool launched_by_app_control; +}; + +#endif diff --git a/src/UniversalSwitchConfiguration.hpp b/src/UniversalSwitchConfiguration.hpp index b95ecac..100488e 100644 --- a/src/UniversalSwitchConfiguration.hpp +++ b/src/UniversalSwitchConfiguration.hpp @@ -16,6 +16,7 @@ enum class ScanDirection TO_TOP }; +class SettingAccessibility; using UniversalSwitchUpdateCb = std::function; class UniversalSwitchConfiguration diff --git a/src/setting-accessibility.h b/src/setting-accessibility.h index d441885..7cc8d86 100755 --- a/src/setting-accessibility.h +++ b/src/setting-accessibility.h @@ -27,10 +27,8 @@ #include "setting-common-draw-widget.h" #include "setting-common-view.h" -#include "MainData.hpp" -#include "SetValueLayout.hpp" #include "setting-accessibility-universal-switch-dbus.h" -#include "UniversalSwitchConfiguration.hpp" +#include "SettingAccessibility.hpp" #define VCONFKEY_SETAPPL_ACCESSIBILITY_UNIVERSAL_SWITCH_CONFIGURATION_SERVICE "db/setting/accessibility/universal-switch/configuration-service" #define VCONFKEY_SETAPPL_ACCESSIBILITY_UNIVERSAL_SWITCH_INTERACTION_SERVICE "db/setting/accessibility/universal-switch/interaction-service" @@ -225,73 +223,6 @@ typedef const std::string& switch_action_t; struct SettingAccessibility; typedef void (*switch_action_cb)(SettingAccessibility *ad, switch_action_t action, void *user_data); -typedef void (*back_cb)(SettingAccessibility *ad); - -struct SettingAccessibility { - MainData md; - Elm_Genlist_Item_Class itc_1text; - Elm_Genlist_Item_Class itc_multiline_sub; - Evas_Object *popup; - Evas_Object *entry; - Evas_Object *all_checkbox; - Evas_Object *remove_switches_page_button; - Evas_Object *remove_switches_popup_button; - Evas_Object *update_accessories_action_genlist; - Evas_Object *universal_switch_settings_btn; - - Elm_Object_Item *save_object_item; - Elm_Object_Item *universal_switch_main_item; - Elm_Object_Item *universal_switch_settings_item; - Elm_Object_Item *naviframe_it; - SetValueLayout set_value_layout; - - GenGroupItemData *speech_rate_item; - GenGroupItemData *keyboard_feedback_item; - GenGroupItemData *hints_item; - GenGroupItemData *vibration_feedback_item; - GenGroupItemData *sound_feedback_item; - GenGroupItemData *status_bar_information_item; - GenGroupItemData *multiline_status_bar_information_description; - GenGroupItemData *screenreader_checkbox; - GenGroupItemData *multiline_screen_reader_comment; - GenGroupItemData *screen_reader_settings; - GenGroupItemData *screen_reader_item; - GenGroupItemData *universal_switch_item; - GenGroupItemData *universal_switch_off_checkbox; - GenGroupItemData *universal_switch_comment; - GenGroupItemData *universal_switch_add_switch_screen; - GenGroupItemData *universal_switch_add_switch_accessories; - GenGroupItemData *universal_switch_add_switch_camera; - GenGroupItemData *universal_switch_camera_comment; - GenGroupItemData *universal_switch_settings_switches; - GenGroupItemData *universal_switch_auto_scan_int; - GenGroupItemData *universal_switch_scans_num; - GenGroupItemData *universal_switch_scan_method; - GenGroupItemData *universal_switch_scan_dir; - GenGroupItemData *universal_switch_scan_speed; - GenGroupItemData *universal_switch_pause_on_first; - GenGroupItemData *universal_switch_tap_duration; - GenGroupItemData *universal_switch_sgl_iaction_int; - GenGroupItemData *universal_switch_auto_tap; - GenGroupItemData *universal_switch_auto_move_int; - GenGroupItemData *universal_switch_feedback_cursor_cl; - GenGroupItemData *universal_switch_feedback_sound; - GenGroupItemData *universal_switch_feedback_sound_volume; - GenGroupItemData *universal_switch_feedback_voice; - GenGroupItemData *universal_switch_feedback_voice_speech_rate; - GenGroupItemData *universal_switch_feedback_voice_speech_volume; - - Elm_Genlist *universal_switch_switches; - back_cb universal_switch_switches_back; - - tts_h tts; - - UniversalSwitchDbusConfig config; - UniversalSwitchConfigurationItem config_item_to_update; - UniversalSwitchConfiguration us_configuration; - int switches_to_remove_counter; - bool launched_by_app_control; -}; extern setting_view setting_view_accessibility_main; -- 2.7.4 From 0b5994f092af8f4b746bcdd8d18a23848c2b312d Mon Sep 17 00:00:00 2001 From: Lukasz Wlazly Date: Thu, 4 Oct 2018 09:12:26 +0200 Subject: [PATCH 08/16] [Cpp refactor] Add AccessibilityLauncherPage class Change-Id: Id51455673149125ef8a8c22784e286effcc92e65 --- ...-launcher.cpp => AccessibilityLauncherPage.cpp} | 204 +++++++++------------ src/AccessibilityLauncherPage.hpp | 31 ++++ src/SettingAccessibility.hpp | 5 + src/setting-accessibility-accessibility-launcher.h | 8 - src/setting-accessibility-main.cpp | 3 +- 5 files changed, 123 insertions(+), 128 deletions(-) rename src/{setting-accessibility-accessibility-launcher.cpp => AccessibilityLauncherPage.cpp} (68%) create mode 100644 src/AccessibilityLauncherPage.hpp delete mode 100644 src/setting-accessibility-accessibility-launcher.h diff --git a/src/setting-accessibility-accessibility-launcher.cpp b/src/AccessibilityLauncherPage.cpp similarity index 68% rename from src/setting-accessibility-accessibility-launcher.cpp rename to src/AccessibilityLauncherPage.cpp index ac9301e..dfcefcb 100644 --- a/src/setting-accessibility-accessibility-launcher.cpp +++ b/src/AccessibilityLauncherPage.cpp @@ -1,26 +1,6 @@ -/* - * accessibility - * - * Copyright (c) 2017 Samsung Electronics Co., Ltd. - * - * Contact: Michal Pawluk - * - * 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. - * - */ - -#include "setting-accessibility-accessibility-launcher.h" +#include "AccessibilityLauncherPage.hpp" #include "utils.hpp" +#include "setting-accessibility.h" #include #include @@ -35,98 +15,10 @@ namespace { }; } -struct ItemWrapper{ - std::string name; - GenGroupItemData *item; -}; -static Eina_Bool __naviframe_pop_cb(void *data, Elm_Object_Item *it) +AccessibilityLauncherPage::AccessibilityLauncherPage(SettingAccessibility *ad) { - - retv_if(data == NULL, EINA_TRUE); - ItemWrapper *items = (ItemWrapper *)data; - delete[] items; - - return EINA_TRUE; -} - -static void __back_cb(void *data, Evas_Object *obj, void *event_info) -{ - - retm_if(data == NULL, "Data argument is NULL"); - SettingAccessibility *ad = (SettingAccessibility *)data; - elm_naviframe_item_pop(ad->md.getNaviframe()); - -} - -static void __update_vconf(ItemWrapper *items) -{ - int value = 0; - for (auto i = 0u; i < utils::lenOf(LAUNCHER_NAMES); i++) - if (items[i].item->chk_status) - value = value | (1 << i); - vconf_set_int(VCONFKEY_SETAPPL_ACCESSIBILITY_ACCESSIBILITY_LAUNCHER_LAUNCH, value); -} - -static void __accessibility_launcher_item_checkbox_cb(void *data, Evas_Object *obj, void *event_info) -{ - - retm_if(data == NULL, "Input parameter is NULL"); - GenGroupItemData *list_item = (GenGroupItemData *)data; - list_item->chk_status = !list_item->chk_status; - __update_vconf((ItemWrapper*)list_item->userdata); - -} - -static void __accessibility_launcher_item_selected(void *data, Evas_Object *obj, void *event_info) -{ - - retm_if(event_info == NULL, "Invalid argument: event_info is NULL"); - Elm_Object_Item *item = (Elm_Object_Item *)event_info; - elm_genlist_item_selected_set(item, EINA_FALSE); - GenGroupItemData *list_item = (GenGroupItemData *)elm_object_item_data_get(item); - setting_update_gl_item_chk_status(list_item, list_item->chk_status ? 0 : 1); - __update_vconf((ItemWrapper*)list_item->userdata); - -} - -static void __accessibility_launcher_state_update_name(GenGroupItemData *item) -{ - item->keyStr = item->chk_status ? _(DEVOPTION_STR_ACCESSIBILITY_ACCESSIBILITY_LAUNCHER_ON) : _(DEVOPTION_STR_ACCESSIBILITY_ACCESSIBILITY_LAUNCHER_OFF); - elm_genlist_item_update(item->item); -} - -static void __updete_main_switch(GenGroupItemData *list_item) -{ - retm_if(list_item == NULL, "Data parameter is NULL"); - __accessibility_launcher_state_update_name(list_item); - vconf_set_bool(VCONFKEY_SETAPPL_ACCESSIBILITY_ACCESSIBILITY_LAUNCHER_STATE, list_item->chk_status); - ItemWrapper *items = (ItemWrapper *)list_item->userdata; - for (auto i = 0u; i < utils::lenOf(LAUNCHER_NAMES); i++) - elm_object_item_disabled_set(items[i].item->item, list_item->chk_status ? EINA_FALSE : EINA_TRUE); -} - -static void __accessibility_launcher_checkbox_cb(void *data, Evas_Object *obj, void *event_info) -{ - retm_if(data == NULL, "Data parameter is NULL"); - GenGroupItemData *list_item = (GenGroupItemData *)data; - list_item->chk_status = !list_item->chk_status; - __updete_main_switch(list_item); -} - -static void __accessibility_launcher_off_mouse_up_Gendial_list_cb(void *data, Evas_Object *obj, void *event_info) -{ - retm_if(data == NULL, "Invalid argument: data is NULL"); - Elm_Object_Item *item = (Elm_Object_Item *)event_info; - elm_genlist_item_selected_set(item, EINA_FALSE); - GenGroupItemData *list_item = (GenGroupItemData *)elm_object_item_data_get(item); - setting_update_gl_item_chk_status(list_item, list_item->chk_status ? 0 : 1); - __updete_main_switch(list_item); -} - -void setting_accessibility_accessibility_launcher_page_create(SettingAccessibility *ad) -{ - auto items = new ItemWrapper[utils::lenOf(LAUNCHER_NAMES)]; + auto items = new ItemWrapper[utils::lenOf(LAUNCHER_NAMES)]; retm_if(items == NULL, "new failed"); for (auto i = 0u; i < utils::lenOf(LAUNCHER_NAMES); ++i) @@ -153,10 +45,10 @@ void setting_accessibility_accessibility_launcher_page_create(SettingAccessibili item = setting_create_Gendial_field_def( genlist, &itc_1text_1icon, - __accessibility_launcher_off_mouse_up_Gendial_list_cb, + onMouseUpGendialListCb, items, SwallowType::ICON_RADIO, NULL, NULL, state, state ? _(DEVOPTION_STR_ACCESSIBILITY_ACCESSIBILITY_LAUNCHER_ON) : _(DEVOPTION_STR_ACCESSIBILITY_ACCESSIBILITY_LAUNCHER_OFF), - NULL, __accessibility_launcher_checkbox_cb); + NULL, checkboxCb); if (item) item->userdata = items; @@ -181,10 +73,10 @@ void setting_accessibility_accessibility_launcher_page_create(SettingAccessibili for (auto i = 0u; i < utils::lenOf(LAUNCHER_NAMES); i++) { GenGroupItemData *item = setting_create_Gendial_field_def( genlist, &itc_1text_1icon, - __accessibility_launcher_item_selected, + onItemSelectedCb, ad, SwallowType::ICON_RADIO, NULL, NULL, vconf_state & (1 << i), items[i].name.c_str(), - NULL, __accessibility_launcher_item_checkbox_cb); + NULL, onCheckboxChangeCb); if (item) { item->userdata = items; @@ -196,10 +88,86 @@ void setting_accessibility_accessibility_launcher_page_create(SettingAccessibili } ad->md.naviframe_it = elm_naviframe_item_push(ad->md.getNaviframe(), _(DEVOPTION_STR_ACCESSIBILITY_ACCESSIBILITY_LAUNCHER), NULL, NULL, genlist, NULL); - elm_naviframe_item_pop_cb_set(ad->md.naviframe_it, __naviframe_pop_cb, items); + elm_naviframe_item_pop_cb_set(ad->md.naviframe_it, onNaviframePopCb, items); elm_object_item_domain_text_translatable_set(ad->md.naviframe_it, PACKAGE, EINA_TRUE); - Evas_Object *back_btn = setting_create_button(ad->md.getNaviframe(), NULL, NAVI_BACK_ARROW_BUTTON_STYLE, __back_cb, ad); + Evas_Object *back_btn = setting_create_button(ad->md.getNaviframe(), NULL, NAVI_BACK_ARROW_BUTTON_STYLE, onBackButtonCb, ad); elm_layout_content_set(ad->md.getNaviframe(), "prev_btn", back_btn); +} +Eina_Bool AccessibilityLauncherPage::onNaviframePopCb(void *data, Elm_Object_Item *it) +{ + retv_if(data == NULL, EINA_TRUE); + ItemWrapper *items = (ItemWrapper *)data; + delete[] items; + + return EINA_TRUE; +} + +void AccessibilityLauncherPage::onBackButtonCb(void *data, Evas_Object *obj, void *event_info) +{ + retm_if(data == NULL, "Data argument is NULL"); + SettingAccessibility *ad = (SettingAccessibility *)data; + elm_naviframe_item_pop(ad->md.getNaviframe()); +} + +void AccessibilityLauncherPage::updateVconf(ItemWrapper *items) +{ + int value = 0; + for (auto i = 0u; i < utils::lenOf(LAUNCHER_NAMES); i++) + if (items[i].item->chk_status) + value = value | (1 << i); + vconf_set_int(VCONFKEY_SETAPPL_ACCESSIBILITY_ACCESSIBILITY_LAUNCHER_LAUNCH, value); +} + +void AccessibilityLauncherPage::onCheckboxChangeCb(void *data, Evas_Object *obj, void *event_info) +{ + retm_if(data == NULL, "Input parameter is NULL"); + GenGroupItemData *list_item = (GenGroupItemData *)data; + list_item->chk_status = !list_item->chk_status; + updateVconf((ItemWrapper*)list_item->userdata); +} + +void AccessibilityLauncherPage::onItemSelectedCb(void *data, Evas_Object *obj, void *event_info) +{ + retm_if(event_info == NULL, "Invalid argument: event_info is NULL"); + Elm_Object_Item *item = (Elm_Object_Item *)event_info; + elm_genlist_item_selected_set(item, EINA_FALSE); + GenGroupItemData *list_item = (GenGroupItemData *)elm_object_item_data_get(item); + setting_update_gl_item_chk_status(list_item, list_item->chk_status ? 0 : 1); + updateVconf((ItemWrapper*)list_item->userdata); +} + +void AccessibilityLauncherPage::updateName(GenGroupItemData *item) +{ + item->keyStr = item->chk_status ? _(DEVOPTION_STR_ACCESSIBILITY_ACCESSIBILITY_LAUNCHER_ON) : _(DEVOPTION_STR_ACCESSIBILITY_ACCESSIBILITY_LAUNCHER_OFF); + elm_genlist_item_update(item->item); +} + +void AccessibilityLauncherPage::updateMainSwitch(GenGroupItemData *list_item) +{ + retm_if(list_item == NULL, "Data parameter is NULL"); + updateName(list_item); + vconf_set_bool(VCONFKEY_SETAPPL_ACCESSIBILITY_ACCESSIBILITY_LAUNCHER_STATE, list_item->chk_status); + ItemWrapper *items = (ItemWrapper *)list_item->userdata; + for (auto i = 0u; i < utils::lenOf(LAUNCHER_NAMES); i++) + elm_object_item_disabled_set(items[i].item->item, list_item->chk_status ? EINA_FALSE : EINA_TRUE); +} + +void AccessibilityLauncherPage::checkboxCb(void *data, Evas_Object *obj, void *event_info) +{ + retm_if(data == NULL, "Data parameter is NULL"); + GenGroupItemData *list_item = (GenGroupItemData *)data; + list_item->chk_status = !list_item->chk_status; + updateMainSwitch(list_item); +} + +void AccessibilityLauncherPage::onMouseUpGendialListCb(void *data, Evas_Object *obj, void *event_info) +{ + retm_if(data == NULL, "Invalid argument: data is NULL"); + Elm_Object_Item *item = (Elm_Object_Item *)event_info; + elm_genlist_item_selected_set(item, EINA_FALSE); + GenGroupItemData *list_item = (GenGroupItemData *)elm_object_item_data_get(item); + setting_update_gl_item_chk_status(list_item, list_item->chk_status ? 0 : 1); + updateMainSwitch(list_item); } diff --git a/src/AccessibilityLauncherPage.hpp b/src/AccessibilityLauncherPage.hpp new file mode 100644 index 0000000..9f6dba1 --- /dev/null +++ b/src/AccessibilityLauncherPage.hpp @@ -0,0 +1,31 @@ +#ifndef ACCESSIBILITY_LAUNCHER_PAGE_HPP +#define ACCESSIBILITY_LAUNCHER_PAGE_HPP + +#include +#include "GenGroupItemData.hpp" + +struct ItemWrapper{ + std::string name; + GenGroupItemData *item; +}; + +class SettingAccessibility; + +class AccessibilityLauncherPage +{ +public: + AccessibilityLauncherPage(SettingAccessibility *ad); + +private: + static Eina_Bool onNaviframePopCb(void *data, Elm_Object_Item *it); + static void onBackButtonCb(void *data, Evas_Object *obj, void *event_info); + static void updateVconf(ItemWrapper *items); + static void onCheckboxChangeCb(void *data, Evas_Object *obj, void *event_info); + static void onItemSelectedCb(void *data, Evas_Object *obj, void *event_info); + static void updateName(GenGroupItemData *item); + static void updateMainSwitch(GenGroupItemData *list_item); + static void checkboxCb(void *data, Evas_Object *obj, void *event_info); + static void onMouseUpGendialListCb(void *data, Evas_Object *obj, void *event_info); +}; + +#endif diff --git a/src/SettingAccessibility.hpp b/src/SettingAccessibility.hpp index e7952cf..3547af5 100644 --- a/src/SettingAccessibility.hpp +++ b/src/SettingAccessibility.hpp @@ -4,6 +4,9 @@ #include "MainData.hpp" #include "SetValueLayout.hpp" #include "UniversalSwitchConfiguration.hpp" +#include "AccessibilityLauncherPage.hpp" + +#include typedef void (*back_cb)(SettingAccessibility *ad); @@ -71,6 +74,8 @@ struct SettingAccessibility { UniversalSwitchConfiguration us_configuration; int switches_to_remove_counter; bool launched_by_app_control; + + std::unique_ptr accessibilityLauncherPage_; }; #endif diff --git a/src/setting-accessibility-accessibility-launcher.h b/src/setting-accessibility-accessibility-launcher.h deleted file mode 100644 index 78e024b..0000000 --- a/src/setting-accessibility-accessibility-launcher.h +++ /dev/null @@ -1,8 +0,0 @@ -#ifndef SETTINGACCESSIBILITYACCESSIBILITYLAUNCHER_H -#define SETTINGACCESSIBILITYACCESSIBILITYLAUNCHER_H - -#include "setting-accessibility.h" - -void setting_accessibility_accessibility_launcher_page_create(SettingAccessibility *data); - -#endif /* SETTINGACCESSIBILITYACCESSIBILITYLAUNCHER_H */ \ No newline at end of file diff --git a/src/setting-accessibility-main.cpp b/src/setting-accessibility-main.cpp index 3ba8726..73345f1 100644 --- a/src/setting-accessibility-main.cpp +++ b/src/setting-accessibility-main.cpp @@ -22,7 +22,6 @@ #include "setting-accessibility.h" #include "setting-accessibility-screen-reader.h" #include "setting-accessibility-universal-switch.h" -#include "setting-accessibility-accessibility-launcher.h" #include #include @@ -93,7 +92,7 @@ static void setting_accessibility_accessibility_launcher_mouse_up_Gendial_list_c Elm_Object_Item *item = (Elm_Object_Item *)event_info; SettingAccessibility *ad = (SettingAccessibility *)data; elm_genlist_item_selected_set(item, EINA_FALSE); - setting_accessibility_accessibility_launcher_page_create(ad); + ad->accessibilityLauncherPage_ = std::make_unique(ad); } -- 2.7.4 From e202c136a7e9974decb4c81845fd502ec8d7b519 Mon Sep 17 00:00:00 2001 From: Lukasz Wlazly Date: Thu, 4 Oct 2018 14:36:15 +0200 Subject: [PATCH 09/16] [Cpp refactor] Add ScreenReaderSettingsPage class Change-Id: I79628d265c688edce170219052c5ca769209bff3 --- ...r-settings.cpp => ScreenReaderSettingsPage.cpp} | 955 +++++++++------------ src/ScreenReaderSettingsPage.hpp | 44 + src/SettingAccessibility.hpp | 7 + src/setting-accessibility-screen-reader-settings.h | 10 - src/setting-accessibility-screen-reader.cpp | 3 +- 5 files changed, 471 insertions(+), 548 deletions(-) rename src/{setting-accessibility-screen-reader-settings.cpp => ScreenReaderSettingsPage.cpp} (71%) mode change 100755 => 100644 create mode 100644 src/ScreenReaderSettingsPage.hpp delete mode 100644 src/setting-accessibility-screen-reader-settings.h diff --git a/src/setting-accessibility-screen-reader-settings.cpp b/src/ScreenReaderSettingsPage.cpp old mode 100755 new mode 100644 similarity index 71% rename from src/setting-accessibility-screen-reader-settings.cpp rename to src/ScreenReaderSettingsPage.cpp index 04320cb..12c8bd0 --- a/src/setting-accessibility-screen-reader-settings.cpp +++ b/src/ScreenReaderSettingsPage.cpp @@ -1,46 +1,20 @@ -/* - * accessibility - * - * Copyright (c) 2015 Samsung Electronics Co., Ltd. - * - * Contact: Tomasz Olszak - * - * 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. - * - */ - +#include "ScreenReaderSettingsPage.hpp" +#include "setting-accessibility.h" +#include "utils.hpp" #include #include -#include #include #include +#include -#include "utils.hpp" - -#include "setting-accessibility-screen-reader-settings.h" - -#include -#include - -#define POPUP_CONTENT_BASE_SIZE 120 - -struct VConfCheckData{ - std::string label; - std::string vconf_key; - int *status = nullptr; -}; namespace { + struct VConfCheckData{ + std::string label; + std::string vconf_key; + int *status = nullptr; + }; + VConfCheckData vConfCheckData[] = { { DEVOPTION_STR_ACCESSIBILITY_INDICATOR_TIME, VCONFKEY_SETAPPL_ACCESSIBILITY_TTS_INDICATOR_INFORMATION_TIME }, { DEVOPTION_STR_ACCESSIBILITY_INDICATOR_DATE, VCONFKEY_SETAPPL_ACCESSIBILITY_TTS_INDICATOR_INFORMATION_DATE }, @@ -50,328 +24,334 @@ namespace { { DEVOPTION_STR_ACCESSIBILITY_INDICATOR_MISSED_EVENTS, VCONFKEY_SETAPPL_ACCESSIBILITY_TTS_INDICATOR_INFORMATION_MISSED_EVENTS } }; - std::vector items; + static const size_t POPUP_CONTENT_BASE_SIZE = 120; - GenGroupItemData *speech_rate_list_item = NULL; + std::vector items; + GenGroupItemData *speech_rate_list_item = nullptr; } -static Eina_Bool __page_hide(void *data, Elm_Object_Item *it) +ScreenReaderSettingsPage::ScreenReaderSettingsPage(SettingAccessibility *data) { + SettingAccessibility *ad = static_cast(data); - /* error check */ - retv_if(data == NULL, EINA_TRUE); - SettingAccessibility *ad = (SettingAccessibility *)data; - - if (0 != tts_setting_unset_speed_changed_cb()) - SETTING_TRACE("Fail to unset speed changed cb"); + char buf[256]; + int s_speed = -1; + int s_speed_normal = -1; + int s_speed_max = -1; + int s_speed_min = -1; + int vconf_val = 0; + int vconf_ret; - if (0 != tts_setting_unset_voice_changed_cb()) - SETTING_TRACE("Fail to unset voice changed cb"); + Evas_Object *genlist = elm_genlist_add(ad->md.getNaviframe()); + retm_if(genlist == NULL, "Cannot set genlist object as content of layout"); + elm_genlist_mode_set(genlist, ELM_LIST_COMPRESS); + elm_object_style_set(genlist, "dialogue"); + elm_genlist_clear(genlist); - if (0 != tts_setting_finalize()) { - LOGE("Fail to setting finalize"); - return -1; - } - elm_naviframe_item_pop(ad->md.getNaviframe()); + SETTING_TRACE("Creating items"); - return EINA_TRUE; -} + if (0 != tts_setting_initialize()) + SETTING_TRACE("Fail to setting initialize"); -static Eina_Bool _vconf_key_value_get(const char *key) -{ - retvm_if(!key, EINA_FALSE, "Key is NULL"); - int value = 0; - int ret = vconf_get_bool(key, &value); - if (ret != 0) { - LOGE("Failed to get vconf bool value %s. Error: %d", key, ret); - return EINA_FALSE; - } - return (value != 0); -} + SETTING_TRACE("tts initialized"); + if (0 != tts_setting_get_speed(&s_speed)) + SETTING_TRACE("Fail to get speed"); -static void _vconf_key_value_set(const char *key, int value) -{ - retm_if(!key, "key == NULL"); + if (0 != tts_setting_get_speed_range(&s_speed_min, &s_speed_normal, &s_speed_max)) + SETTING_TRACE("Fail to get speed range"); + double s_speed_percent = (((double)s_speed - (double)s_speed_min)/((double)s_speed_max - (double)s_speed_min)) * 100; + snprintf(buf, utils::lenOf(buf), "%.0f%%", s_speed_percent); + SETTING_TRACE("TTS rate is %.0f", s_speed_percent); - int ret = vconf_set_bool(key, value); + /* Item 1 : Speech Rate */ + ad->speech_rate_item = setting_create_Gendial_field_def( + genlist, &itc_2text, + speechRateCb, + ad, SwallowType::INVALID, NULL, + NULL, 1, + _(DEVOPTION_STR_ACCESSIBILITY_SCREEN_READER_SETTINGS_SPEECH_RATE), + buf, + NULL); + tts_setting_set_speed_changed_cb(ttsSpeedChangedCb, ad->speech_rate_item); + if (ad->speech_rate_item) { + ad->speech_rate_item->userdata = ad; + __BACK_POINTER_SET(ad->speech_rate_item); + speech_rate_list_item = ad->speech_rate_item; + SETTING_TRACE("Speech rate Item added"); + } - if (ret != 0) { - LOGE("Failed to set vconf key %s. Error: %d", key, ret); - return; + /* Item 2 : Keyboard feedback */ + vconf_ret = vconf_get_bool( + VCONFKEY_SETAPPL_ACCESSIBILITY_SCREEN_READER_KEYBOARD_FEEDBACK, + &vconf_val); + if (vconf_ret != 0) { + LOGE("Failed to get vconf bool value VCONFKEY_SETAPPL_ACCESSIBILITY_SCREEN_READER_KEYBOARD_FEEDBACK. Error: %d", + vconf_ret); } -} -static void _vconf_key_foreach_check_set(void) -{ - int i; - int size = utils::lenOf(vConfCheckData); + ad->keyboard_feedback_item = setting_create_Gendial_field_def( + genlist, &itc_multiline_2text, + keyboardFeedbackCb, + ad, SwallowType::ICON_RADIO, NULL, + NULL, vconf_val ? 1 : 0, + _(DEVOPTION_STR_ACCESSIBILITY_SCREEN_READER_SETTINGS_KEYBOARD_FEEDBACK), + _(DEVOPTION_STR_ACCESSIBILITY_SCREEN_READER_SETTINGS_KEYBOARD_FEEDBACK_INFO), + updateKeyboardFeedbackCheck); - for (i = 0; i < size; ++i) { - auto status = *(vConfCheckData[i].status); - _vconf_key_value_set(vConfCheckData[i].vconf_key.c_str(), status); + if (ad->keyboard_feedback_item) { + ad->keyboard_feedback_item->userdata = ad; + __BACK_POINTER_SET(ad->keyboard_feedback_item); + SETTING_TRACE("Keyboard feedback Item added"); } -} -static void _cancel_button_clicked_cb(void *data, Evas_Object *obj, - void *event_info) -{ + /* Item 3 : Hints */ + vconf_ret = vconf_get_bool( + VCONFKEY_SETAPPL_ACCESSIBILITY_SCREEN_READER_DESCRIPTION, + &vconf_val); + if (vconf_ret != 0) { + LOGE("Failed to get vconf bool value VCONFKEY_SETAPPL_ACCESSIBILITY_SCREEN_READER_DESCRIPTION. Error: %d", + vconf_ret); + } - Evas_Object *popup = (Evas_Object *)data; - retm_if(!popup, "popup == NULL"); - evas_object_del(popup); + ad->hints_item = setting_create_Gendial_field_def( + genlist, &itc_1text_1icon, + hintsCb, + ad, SwallowType::ICON_RADIO, NULL, + NULL, vconf_val ? 1 : 0, + _(DEVOPTION_STR_ACCESSIBILITY_SCREEN_READER_SETTINGS_HINTS), + NULL, + updateHintsCheck); -} + if (ad->hints_item) { + ad->hints_item->userdata = ad; + __BACK_POINTER_SET(ad->hints_item); + SETTING_TRACE("Hints Item added"); + } -static void _done_button_clicked_cb(void *data, Evas_Object *obj, - void *event_info) -{ + /* Item 4 : Vibration Feedback */ + vconf_ret = vconf_get_bool( + VCONFKEY_SETAPPL_ACCESSIBILITY_SCREEN_READER_HAPTIC, + &vconf_val); + if (vconf_ret != 0) { + LOGE("Failed to get vconf bool value VCONFKEY_SETAPPL_ACCESSIBILITY_SCREEN_READER_HAPTIC. Error: %d", + vconf_ret); + } - Evas_Object *popup = (Evas_Object *)data; - retm_if(!popup, "popup == NULL"); - evas_object_del(popup); + ad->vibration_feedback_item = setting_create_Gendial_field_def( + genlist, &itc_1text_1icon, + vibrationFeedbackCb, + ad, SwallowType::ICON_RADIO, NULL, + NULL, vconf_val ? 1 : 0, + _(DEVOPTION_STR_ACCESSIBILITY_SCREEN_READER_SETTINGS_VIBRATION_FEEDBACK), + NULL, + updateVibrationFeedbackCheck); - _vconf_key_foreach_check_set(); + if (ad->vibration_feedback_item) { + ad->vibration_feedback_item->userdata = ad; + __BACK_POINTER_SET(ad->vibration_feedback_item); + SETTING_TRACE("Vibration feedback Item added"); + } -} + /* Item 5 : Sound Feedback */ + vconf_ret = vconf_get_bool( + VCONFKEY_SETAPPL_ACCESSIBILITY_SCREEN_READER_SOUND_FEEDBACK, + &vconf_val); + if (vconf_ret != 0) { + LOGE("Failed to get vconf bool value VCONFKEY_SETAPPL_ACCESSIBILITY_SCREEN_READER_SOUND_FEEDBACK. Error: %d", + vconf_ret); + } -static void _check_state_changed_cb(void *data, Evas_Object *obj, - void *event_info) -{ + ad->sound_feedback_item = setting_create_Gendial_field_def( + genlist, &itc_1text_1icon, + soundFeedbackCb, + ad, SwallowType::ICON_RADIO, NULL, + NULL, vconf_val ? 1 : 0, + _(DEVOPTION_STR_ACCESSIBILITY_SCREEN_READER_SETTINGS_SOUND_FEEDBACK), + NULL, + updateSoundFeedbackCheck); - if (!data) { - LOGD("data == NULL"); - return; + if (ad->sound_feedback_item) { + ad->sound_feedback_item->userdata = ad; + __BACK_POINTER_SET(ad->sound_feedback_item); + SETTING_TRACE("Sound feedback Item added"); } - GenGroupItemData *item_data = (GenGroupItemData *)data; - item_data->chk_status = elm_check_state_get(obj); - LOGE("Check changed: %s; status: %d, %p", item_data->keyStr.c_str(), item_data->chk_status, &item_data->chk_status); - + ad->status_bar_information_item = setting_create_Gendial_field_def( + genlist, &itc_1text, + mouseUpGendialListCb, + ad, SwallowType::INVALID, NULL, + NULL, 1, + _(DEVOPTION_STR_ACCESSIBILITY_SCREEN_READER_SETTINGS_STATUS_BAR_INFORMATION), + NULL, + NULL); -} + if (ad->status_bar_information_item) { + ad->status_bar_information_item->userdata = ad; + __BACK_POINTER_SET(ad->status_bar_information_item); + } -static void _speech_rate_popup_done_button_clicked_cb(void *data, - Evas_Object *obj, void *event_info) -{ + ad->multiline_status_bar_information_description = setting_create_Gendial_field_def( + genlist, &ad->itc_multiline_sub, + NULL, ad, SwallowType::INVALID, NULL, + NULL, 0, + NULL, + _(DEVOPTION_STR_ACCESSIBILITY_SCREEN_READER_SETTINGS_STATUS_BAR_INFORMATION_DESCRIPTION), + NULL); - Evas_Object *slider; - Evas_Object *layout; - int val; - Evas_Object *popup = (Evas_Object *)data; - retm_if(!popup, "popup == NULL"); - layout = elm_object_content_get(popup); - slider = elm_object_part_content_get(layout, "slider"); + if (ad->multiline_status_bar_information_description) { + ad->multiline_status_bar_information_description->userdata = ad; + __BACK_POINTER_SET(ad->multiline_status_bar_information_description); - val = (int)elm_slider_value_get(slider); - if (0 != tts_setting_set_speed(val)) - SETTING_TRACE("Setting speed to tts engine failed"); + elm_genlist_item_select_mode_set( + ad->multiline_status_bar_information_description->item, + ELM_OBJECT_SELECT_MODE_DISPLAY_ONLY); + } - evas_object_del(popup); + Elm_Object_Item *navi_it = elm_naviframe_item_push(ad->md.getNaviframe(), _(DEVOPTION_STR_ACCESSIBILITY_SCREEN_READER_SETTINGS), NULL, NULL, genlist, NULL); + elm_object_item_domain_text_translatable_set(navi_it, PACKAGE, EINA_TRUE); + elm_naviframe_item_pop_cb_set(navi_it, hidePage, ad); } -static void _list_item_clicked_cb(void *data, Evas_Object *obj, - void *event_info) +void ScreenReaderSettingsPage::mouseUpGendialListCb(void *data, Evas_Object *obj, void *event_info) { - - + retm_if(data == NULL, "Invalid argument: data is NULL"); + retm_if(event_info == NULL, "Invalid argument: event_info is NULL"); Elm_Object_Item *item = (Elm_Object_Item *)event_info; - retm_if(!item, "item == NULL"); + SettingAccessibility *ad = (SettingAccessibility *)data; + Evas_Object *popup; + Evas_Object *box; + Evas_Object *genlist; + GenGroupItemData *screenreader_checkbox = NULL; + int i; + int size = utils::lenOf(vConfCheckData); elm_genlist_item_selected_set(item, EINA_FALSE); - GenGroupItemData *list_item = (GenGroupItemData *) - elm_object_item_data_get(item); - retm_if(!list_item, "list_item == NULL"); - - LOGI("ITEM SELECTED: %s", list_item->keyStr.c_str()); - setting_update_gl_item_chk_status(list_item, !list_item->chk_status); + popup = elm_popup_add(ad->md.getWindow()); + elm_popup_align_set(popup, ELM_NOTIFY_ALIGN_FILL, 1.0); + /* eext_object_event_callback_add(popup, EEXT_CALLBACK_BACK, + * eext_popup_back_cb, NULL); */ + elm_object_part_text_set(popup, "title,text", + _(DEVOPTION_STR_ACCESSIBILITY_SCREEN_READER_SETTINGS_STATUS_BAR_INFORMATION)); + evas_object_size_hint_weight_set(popup, EVAS_HINT_EXPAND, + EVAS_HINT_EXPAND); + /* box */ + box = elm_box_add(popup); + evas_object_size_hint_weight_set(box, EVAS_HINT_EXPAND, + EVAS_HINT_EXPAND); -} + /* genlist */ + genlist = elm_genlist_add(box); + evas_object_size_hint_weight_set(genlist, EVAS_HINT_EXPAND, + EVAS_HINT_EXPAND); + evas_object_size_hint_align_set(genlist, EVAS_HINT_FILL, + EVAS_HINT_FILL); -static void _on_popup_del(void *data, Evas *e, Evas_Object *obj, - void *event_info) -{ - if (!speech_rate_list_item) - return; + for (i = 0; i < size; ++i) { + auto status = vconfValueGet(vConfCheckData[i].vconf_key.c_str()); - char buf[256]; - int speed_val = -1; - int s_speed_normal = -1; - int s_speed_max = -1; - int s_speed_min = -1; - - if (0 != tts_setting_get_speed(&speed_val)) - SETTING_TRACE("Failed to get speed"); - - if (0 != tts_setting_get_speed_range(&s_speed_min, &s_speed_normal, &s_speed_max)) - SETTING_TRACE("Fail to get speed range"); - double s_speed_percent = (((double)speed_val - (double)s_speed_min)/((double)s_speed_max - (double)s_speed_min)) * 100; - snprintf(buf, utils::lenOf(buf), "%.0f%%", s_speed_percent); - SETTING_TRACE("Updating speed to %s", buf); - speech_rate_list_item->sub_desc = buf; - elm_genlist_item_update(speech_rate_list_item->item); -} - -static void _speech_rate_popup_create(void *data, void *item) -{ - SettingAccessibility *ad = (SettingAccessibility *)data; - Evas_Object *popup; - Evas_Object *layout; - Evas_Object *slider; - Evas_Object *btn1, *btn2; - int val = -1; + screenreader_checkbox = setting_create_Gendial_field_def( + genlist, &itc_1text_1icon, + onListItemClicked, ad, + SwallowType::ICON_RADIO, NULL, + NULL, status, _(vConfCheckData[i].label.c_str()), + NULL, onCheckStateChanged); - popup = elm_popup_add(ad->md.getWindow()); - elm_popup_align_set(popup, ELM_NOTIFY_ALIGN_FILL, 1.0); - /* eext_object_event_callback_add(popup, EEXT_CALLBACK_BACK, - * eext_popup_back_cb, NULL); */ - elm_object_part_text_set(popup, "title,text", - _(DEVOPTION_STR_ACCESSIBILITY_SCREEN_READER_SETTINGS_SPEECH_RATE)); - evas_object_size_hint_weight_set(popup, EVAS_HINT_EXPAND, - EVAS_HINT_EXPAND); + vConfCheckData[i].status = &screenreader_checkbox->chk_status; + items.push_back(screenreader_checkbox); + } - /* layout */ - layout = elm_layout_add(popup); - elm_layout_file_set(layout, SETTINGS_EDJ, - "popup_text_slider_view_layout"); - elm_object_part_text_set(layout, "elm.text.description", - _(DEVOPTION_STR_ACCESSIBILITY_SCREEN_READER_SETTINGS_SPEECH_RATE_POPUP_DESCRIPTION)); - evas_object_size_hint_weight_set(layout, EVAS_HINT_EXPAND, - EVAS_HINT_EXPAND); - elm_object_content_set(popup, layout); + elm_scroller_movement_block_set(genlist, + Elm_Scroller_Movement_Block(ELM_SCROLLER_MOVEMENT_BLOCK_VERTICAL | ELM_SCROLLER_MOVEMENT_BLOCK_HORIZONTAL)); + elm_scroller_policy_set(genlist, ELM_SCROLLER_POLICY_OFF, + ELM_SCROLLER_POLICY_OFF); - /* slider */ - slider = elm_slider_add(layout); - elm_slider_indicator_show_set(slider, EINA_TRUE); - evas_object_size_hint_weight_set(slider, EVAS_HINT_EXPAND, - EVAS_HINT_EXPAND); - evas_object_size_hint_align_set(slider, EVAS_HINT_FILL, EVAS_HINT_FILL); + evas_object_show(genlist); + elm_box_pack_end(box, genlist); + evas_object_size_hint_min_set(box, -1, + ELM_SCALE_SIZE(POPUP_CONTENT_BASE_SIZE) * size); + evas_object_size_hint_max_set(box, -1, + ELM_SCALE_SIZE(POPUP_CONTENT_BASE_SIZE) * size); + elm_object_content_set(popup, box); - elm_slider_indicator_format_set(slider, "%1.0f"); - elm_slider_min_max_set(slider, 1, 15); - if (0 != tts_setting_get_speed(&val)) - SETTING_TRACE("Fail to get speed"); + const char *btnCancelText = _("IDS_MSG_ACBUTTON_CANCEL_ABB"); + const char *btnDoneText = _("IDS_MSG_ACBUTTON_DONE_ABB"); - elm_slider_step_set(slider, 2); - elm_slider_value_set(slider, val); - elm_object_part_content_set(layout, "slider", slider); + Evas_Object *btnCancel = setting_create_button(popup, btnCancelText, NULL, onCancelButtonClicked, popup); + elm_object_style_set(btnCancel, "popup"); + elm_object_part_content_set(popup, _("button1"), btnCancel); + evas_object_data_set(popup, _("button1"), btnCancelText); - /* ok button */ - btn1 = elm_button_add(popup); - elm_object_style_set(btn1, "bottom"); - elm_object_text_set(btn1, - _(DEVOPTION_STR_ACCESSIBILITY_SCREEN_READER_SETTINGS_SPEECH_RATE_POPUP_CANCEL)); - elm_object_part_content_set(popup, "button1", btn1); - evas_object_smart_callback_add(btn1, "clicked", - _cancel_button_clicked_cb, popup); - eext_object_event_callback_add(popup, EEXT_CALLBACK_BACK, - _cancel_button_clicked_cb, popup); + Evas_Object *btnDone = setting_create_button(popup, btnDoneText, NULL, onDoneButtonClicked, popup); + elm_object_style_set(btnDone, "popup"); - btn2 = elm_button_add(popup); - elm_object_style_set(btn2, "bottom"); - elm_object_text_set(btn2, - _(DEVOPTION_STR_ACCESSIBILITY_SCREEN_READER_SETTINGS_SPEECH_RATE_POPUP_DONE)); - elm_object_part_content_set(popup, "button2", btn2); - evas_object_smart_callback_add(btn2, "clicked", - _speech_rate_popup_done_button_clicked_cb, popup); + elm_object_part_content_set(popup, _("button2"), btnDone); + evas_object_data_set(popup, _("button2"), btnDoneText); - evas_object_event_callback_add(popup, EVAS_CALLBACK_DEL, _on_popup_del, - item); + eext_object_event_callback_add(popup, EEXT_CALLBACK_BACK, onCancelButtonClicked, popup); evas_object_show(popup); - } -static void __tts_setting_speed_changed_cb(int speed, void *user_data) +void ScreenReaderSettingsPage::vibrationFeedbackCb(void *data, Evas_Object *obj, void *event_info) { - - SETTING_TRACE("=== Speed changed to (%d)", speed); - GenGroupItemData *speech_rate_item = - (GenGroupItemData *)user_data; - char buf[256]; - - snprintf(buf, utils::lenOf(buf), "%d", speed); - elm_object_item_part_text_set(speech_rate_item->item, "elm.text.2", - buf); - -} - -static void _speech_rate_mouse_up_Gendial_list_cb(void *data, Evas_Object *obj, - void *event_info) -{ - Elm_Object_Item *item = (Elm_Object_Item *)event_info; - SettingAccessibility *ad = (SettingAccessibility *)data; + GenGroupItemData *list_item = (GenGroupItemData *) + elm_object_item_data_get(item); elm_genlist_item_selected_set(item, EINA_FALSE); - _speech_rate_popup_create( - ad, item); - - -} - -static void _keyboard_feedback_vconf_update(int state) -{ - vconf_set_bool(VCONFKEY_SETAPPL_ACCESSIBILITY_SCREEN_READER_KEYBOARD_FEEDBACK, state ? 1 : 0); + setting_update_gl_item_chk_status(list_item, + list_item->chk_status ? 0 : 1); + updateVibrationFeedbackVconf(list_item->chk_status ? 1 : 0); } -static void _keyboard_feedback_check_update(void *data, Evas_Object *obj, - void *event_info) +void ScreenReaderSettingsPage::updateVibrationFeedbackCheck(void *data, Evas_Object *obj, void *event_info) { - retm_if(data == NULL, "Data parameter is NULL"); - GenGroupItemData *list_item = - (GenGroupItemData *)data; + GenGroupItemData *list_item = (GenGroupItemData *)data; /* for genlist update status */ list_item->chk_status = elm_check_state_get(obj); SETTING_TRACE_DEBUG("check_status: %i", list_item->chk_status); - _keyboard_feedback_vconf_update( - list_item->chk_status); - + updateVibrationFeedbackVconf(list_item->chk_status); } -static void _keyboard_feedback_mouse_up_Gendial_list_cb( - void *data, Evas_Object *obj, void *event_info) +void ScreenReaderSettingsPage::updateVibrationFeedbackVconf(int state) { + vconf_set_bool(VCONFKEY_SETAPPL_ACCESSIBILITY_SCREEN_READER_HAPTIC, state ? 1 : 0); +} +void ScreenReaderSettingsPage::soundFeedbackCb(void *data, Evas_Object *obj, void *event_info) +{ Elm_Object_Item *item = (Elm_Object_Item *)event_info; - GenGroupItemData *list_item = (GenGroupItemData *) - elm_object_item_data_get(item); + GenGroupItemData *list_item = (GenGroupItemData *) elm_object_item_data_get(item); elm_genlist_item_selected_set(item, EINA_FALSE); - setting_update_gl_item_chk_status(list_item, - list_item->chk_status ? 0 : 1); - _keyboard_feedback_vconf_update(list_item->chk_status ? 1 : 0); + setting_update_gl_item_chk_status(list_item, list_item->chk_status ? 0 : 1); + updateSoundFeedbackVconf(list_item->chk_status ? 1 : 0); } -static void _hints_vconf_update(int state) +void ScreenReaderSettingsPage::updateSoundFeedbackCheck(void *data, Evas_Object *obj, void *event_info) { - vconf_set_bool(VCONFKEY_SETAPPL_ACCESSIBILITY_SCREEN_READER_DESCRIPTION, - state ? 1 : 0); -} - -static void _hints_check_update(void *data, Evas_Object *obj, void *event_info) -{ - retm_if(data == NULL, "Data parameter is NULL"); - GenGroupItemData *list_item = - (GenGroupItemData *)data; + GenGroupItemData *list_item = (GenGroupItemData *)data; /* for genlist update status */ list_item->chk_status = elm_check_state_get(obj); SETTING_TRACE_DEBUG("check_status: %i", list_item->chk_status); - _hints_vconf_update( - list_item->chk_status); + updateSoundFeedbackVconf(list_item->chk_status); +} +void ScreenReaderSettingsPage::updateSoundFeedbackVconf(int state) +{ + vconf_set_bool(VCONFKEY_SETAPPL_ACCESSIBILITY_SCREEN_READER_SOUND_FEEDBACK, state ? 1 : 0); } -static void _hints_mouse_up_Gendial_list_cb( - void *data, Evas_Object *obj, void *event_info) +void ScreenReaderSettingsPage::hintsCb(void *data, Evas_Object *obj, void *event_info) { Elm_Object_Item *item = (Elm_Object_Item *)event_info; @@ -381,364 +361,267 @@ static void _hints_mouse_up_Gendial_list_cb( elm_genlist_item_selected_set(item, EINA_FALSE); setting_update_gl_item_chk_status(list_item, list_item->chk_status ? 0 : 1); - _hints_vconf_update(list_item->chk_status ? 1 : 0); + updateHintsVconf(list_item->chk_status ? 1 : 0); } -static inline void _sound_feedback_vconf_update(int state) +void ScreenReaderSettingsPage::updateHintsCheck(void *data, Evas_Object *obj, void *event_info) { - vconf_set_bool(VCONFKEY_SETAPPL_ACCESSIBILITY_SCREEN_READER_SOUND_FEEDBACK, - state ? 1 : 0); -} - -static void _sound_feedback_check_update(void *data, Evas_Object *obj, - void *event_info) -{ - retm_if(data == NULL, "Data parameter is NULL"); - GenGroupItemData *list_item = - (GenGroupItemData *)data; + GenGroupItemData *list_item = (GenGroupItemData *)data; /* for genlist update status */ list_item->chk_status = elm_check_state_get(obj); SETTING_TRACE_DEBUG("check_status: %i", list_item->chk_status); - _sound_feedback_vconf_update( - list_item->chk_status); - + updateHintsVconf(list_item->chk_status); } - -static void _sound_feedback_mouse_up_Gendial_list_cb(void *data, - Evas_Object *obj, void *event_info) +void ScreenReaderSettingsPage::updateHintsVconf(int state) { + vconf_set_bool(VCONFKEY_SETAPPL_ACCESSIBILITY_SCREEN_READER_DESCRIPTION, state ? 1 : 0); +} +void ScreenReaderSettingsPage::keyboardFeedbackCb(void *data, Evas_Object *obj, void *event_info) +{ Elm_Object_Item *item = (Elm_Object_Item *)event_info; - GenGroupItemData *list_item = (GenGroupItemData *) - elm_object_item_data_get(item); + GenGroupItemData *list_item = (GenGroupItemData *)elm_object_item_data_get(item); elm_genlist_item_selected_set(item, EINA_FALSE); - setting_update_gl_item_chk_status(list_item, - list_item->chk_status ? 0 : 1); - _sound_feedback_vconf_update(list_item->chk_status ? 1 : 0); + setting_update_gl_item_chk_status(list_item, list_item->chk_status ? 0 : 1); + updateKeyboardFeedbackVconf(list_item->chk_status ? 1 : 0); } -static void _vibration_feedback_vconf_update(int state) +void ScreenReaderSettingsPage::updateKeyboardFeedbackCheck(void *data, Evas_Object *obj, void *event_info) { - vconf_set_bool(VCONFKEY_SETAPPL_ACCESSIBILITY_SCREEN_READER_HAPTIC, - state ? 1 : 0); -} - -static void _vibration_feedback_check_update(void *data, Evas_Object *obj, - void *event_info) -{ - retm_if(data == NULL, "Data parameter is NULL"); - GenGroupItemData *list_item = - (GenGroupItemData *)data; + GenGroupItemData *list_item = (GenGroupItemData *)data; /* for genlist update status */ list_item->chk_status = elm_check_state_get(obj); SETTING_TRACE_DEBUG("check_status: %i", list_item->chk_status); - _vibration_feedback_vconf_update( - list_item->chk_status); - + updateKeyboardFeedbackVconf(list_item->chk_status); } - -static void _vibration_feedback_mouse_up_Gendial_list_cb( - void *data, Evas_Object *obj, void *event_info) +void ScreenReaderSettingsPage::updateKeyboardFeedbackVconf(int state) { + vconf_set_bool(VCONFKEY_SETAPPL_ACCESSIBILITY_SCREEN_READER_KEYBOARD_FEEDBACK, state ? 1 : 0); +} +void ScreenReaderSettingsPage::speechRateCb(void *data, Evas_Object *obj, void *event_info) +{ Elm_Object_Item *item = (Elm_Object_Item *)event_info; - GenGroupItemData *list_item = (GenGroupItemData *) - elm_object_item_data_get(item); + SettingAccessibility *ad = (SettingAccessibility *)data; elm_genlist_item_selected_set(item, EINA_FALSE); - setting_update_gl_item_chk_status(list_item, - list_item->chk_status ? 0 : 1); - _vibration_feedback_vconf_update(list_item->chk_status ? 1 : 0); + createSpeechRatePopup(ad, item); } -static void _status_bar_info_mouse_up_Gendial_list_cb( - void *data, Evas_Object *obj, void *event_info) +void ScreenReaderSettingsPage::ttsSpeedChangedCb(int speed, void *user_data) { + SETTING_TRACE("=== Speed changed to (%d)", speed); + GenGroupItemData *speech_rate_item = (GenGroupItemData *)user_data; + char buf[256]; - retm_if(data == NULL, "Invalid argument: data is NULL"); - retm_if(event_info == NULL, "Invalid argument: event_info is NULL"); - Elm_Object_Item *item = (Elm_Object_Item *)event_info; + snprintf(buf, utils::lenOf(buf), "%d", speed); + elm_object_item_part_text_set(speech_rate_item->item, "elm.text.2", buf); +} + +void ScreenReaderSettingsPage::createSpeechRatePopup(void *data, void *item) +{ SettingAccessibility *ad = (SettingAccessibility *)data; Evas_Object *popup; - Evas_Object *box; - Evas_Object *genlist; - GenGroupItemData *screenreader_checkbox = NULL; - int i; - int size = utils::lenOf(vConfCheckData); - - elm_genlist_item_selected_set(item, EINA_FALSE); + Evas_Object *layout; + Evas_Object *slider; + Evas_Object *btn1, *btn2; + int val = -1; popup = elm_popup_add(ad->md.getWindow()); elm_popup_align_set(popup, ELM_NOTIFY_ALIGN_FILL, 1.0); /* eext_object_event_callback_add(popup, EEXT_CALLBACK_BACK, * eext_popup_back_cb, NULL); */ elm_object_part_text_set(popup, "title,text", - _(DEVOPTION_STR_ACCESSIBILITY_SCREEN_READER_SETTINGS_STATUS_BAR_INFORMATION)); + _(DEVOPTION_STR_ACCESSIBILITY_SCREEN_READER_SETTINGS_SPEECH_RATE)); evas_object_size_hint_weight_set(popup, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND); - /* box */ - box = elm_box_add(popup); - evas_object_size_hint_weight_set(box, EVAS_HINT_EXPAND, + /* layout */ + layout = elm_layout_add(popup); + elm_layout_file_set(layout, SETTINGS_EDJ, + "popup_text_slider_view_layout"); + elm_object_part_text_set(layout, "elm.text.description", + _(DEVOPTION_STR_ACCESSIBILITY_SCREEN_READER_SETTINGS_SPEECH_RATE_POPUP_DESCRIPTION)); + evas_object_size_hint_weight_set(layout, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND); + elm_object_content_set(popup, layout); - /* genlist */ - genlist = elm_genlist_add(box); - evas_object_size_hint_weight_set(genlist, EVAS_HINT_EXPAND, + /* slider */ + slider = elm_slider_add(layout); + elm_slider_indicator_show_set(slider, EINA_TRUE); + evas_object_size_hint_weight_set(slider, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND); - evas_object_size_hint_align_set(genlist, EVAS_HINT_FILL, - EVAS_HINT_FILL); - - for (i = 0; i < size; ++i) { - auto status = _vconf_key_value_get(vConfCheckData[i].vconf_key.c_str()); - - screenreader_checkbox = setting_create_Gendial_field_def( - genlist, &itc_1text_1icon, - _list_item_clicked_cb, ad, - SwallowType::ICON_RADIO, NULL, - NULL, status, _(vConfCheckData[i].label.c_str()), - NULL, _check_state_changed_cb); - - vConfCheckData[i].status = &screenreader_checkbox->chk_status; - items.push_back(screenreader_checkbox); - } - - elm_scroller_movement_block_set(genlist, - Elm_Scroller_Movement_Block(ELM_SCROLLER_MOVEMENT_BLOCK_VERTICAL | ELM_SCROLLER_MOVEMENT_BLOCK_HORIZONTAL)); - elm_scroller_policy_set(genlist, ELM_SCROLLER_POLICY_OFF, - ELM_SCROLLER_POLICY_OFF); - - evas_object_show(genlist); - elm_box_pack_end(box, genlist); - evas_object_size_hint_min_set(box, -1, - ELM_SCALE_SIZE(POPUP_CONTENT_BASE_SIZE) * size); - evas_object_size_hint_max_set(box, -1, - ELM_SCALE_SIZE(POPUP_CONTENT_BASE_SIZE) * size); - elm_object_content_set(popup, box); + evas_object_size_hint_align_set(slider, EVAS_HINT_FILL, EVAS_HINT_FILL); - const char *btnCancelText = _("IDS_MSG_ACBUTTON_CANCEL_ABB"); - const char *btnDoneText = _("IDS_MSG_ACBUTTON_DONE_ABB"); + elm_slider_indicator_format_set(slider, "%1.0f"); + elm_slider_min_max_set(slider, 1, 15); + if (0 != tts_setting_get_speed(&val)) + SETTING_TRACE("Fail to get speed"); - Evas_Object *btnCancel = setting_create_button(popup, btnCancelText, - NULL, _cancel_button_clicked_cb, popup); - elm_object_style_set(btnCancel, "popup"); - elm_object_part_content_set(popup, _("button1"), btnCancel); - evas_object_data_set(popup, _("button1"), btnCancelText); + elm_slider_step_set(slider, 2); + elm_slider_value_set(slider, val); + elm_object_part_content_set(layout, "slider", slider); - Evas_Object *btnDone = setting_create_button(popup, btnDoneText, NULL, - _done_button_clicked_cb, popup); - elm_object_style_set(btnDone, "popup"); + /* ok button */ + btn1 = elm_button_add(popup); + elm_object_style_set(btn1, "bottom"); + elm_object_text_set(btn1, + _(DEVOPTION_STR_ACCESSIBILITY_SCREEN_READER_SETTINGS_SPEECH_RATE_POPUP_CANCEL)); + elm_object_part_content_set(popup, "button1", btn1); + evas_object_smart_callback_add(btn1, "clicked", onCancelButtonClicked, popup); + eext_object_event_callback_add(popup, EEXT_CALLBACK_BACK, onCancelButtonClicked, popup); - elm_object_part_content_set(popup, _("button2"), btnDone); - evas_object_data_set(popup, _("button2"), btnDoneText); + btn2 = elm_button_add(popup); + elm_object_style_set(btn2, "bottom"); + elm_object_text_set(btn2, _(DEVOPTION_STR_ACCESSIBILITY_SCREEN_READER_SETTINGS_SPEECH_RATE_POPUP_DONE)); + elm_object_part_content_set(popup, "button2", btn2); + evas_object_smart_callback_add(btn2, "clicked", onPopupDoneButtonClicked, popup); - eext_object_event_callback_add(popup, EEXT_CALLBACK_BACK, - _cancel_button_clicked_cb, popup); + evas_object_event_callback_add(popup, EVAS_CALLBACK_DEL, onPopupDel, item); evas_object_show(popup); - - } -void setting_accessibility_screen_reader_settings_page_create( - SettingAccessibility *data) +void ScreenReaderSettingsPage::onPopupDel(void *data, Evas *e, Evas_Object *obj, void *event_info) { - - SettingAccessibility *ad = (SettingAccessibility *)data; + if (!speech_rate_list_item) + return; char buf[256]; - int s_speed = -1; + int speed_val = -1; int s_speed_normal = -1; int s_speed_max = -1; int s_speed_min = -1; - int vconf_val = 0; - int vconf_ret; - - Evas_Object *genlist = elm_genlist_add(ad->md.getNaviframe()); - retm_if(genlist == NULL, - "Cannot set genlist object as content of layout"); - elm_genlist_mode_set(genlist, ELM_LIST_COMPRESS); - elm_object_style_set(genlist, "dialogue"); - elm_genlist_clear(genlist); - - SETTING_TRACE("Creating items"); - - if (0 != tts_setting_initialize()) - SETTING_TRACE("Fail to setting initialize"); - SETTING_TRACE("tts initialized"); - if (0 != tts_setting_get_speed(&s_speed)) - SETTING_TRACE("Fail to get speed"); + if (0 != tts_setting_get_speed(&speed_val)) + SETTING_TRACE("Failed to get speed"); if (0 != tts_setting_get_speed_range(&s_speed_min, &s_speed_normal, &s_speed_max)) SETTING_TRACE("Fail to get speed range"); - double s_speed_percent = (((double)s_speed - (double)s_speed_min)/((double)s_speed_max - (double)s_speed_min)) * 100; + double s_speed_percent = (((double)speed_val - (double)s_speed_min)/((double)s_speed_max - (double)s_speed_min)) * 100; snprintf(buf, utils::lenOf(buf), "%.0f%%", s_speed_percent); - SETTING_TRACE("TTS rate is %.0f", s_speed_percent); + SETTING_TRACE("Updating speed to %s", buf); + speech_rate_list_item->sub_desc = buf; + elm_genlist_item_update(speech_rate_list_item->item); +} - /* Item 1 : Speech Rate */ - ad->speech_rate_item = setting_create_Gendial_field_def( - genlist, &itc_2text, - _speech_rate_mouse_up_Gendial_list_cb, - ad, SwallowType::INVALID, NULL, - NULL, 1, - _(DEVOPTION_STR_ACCESSIBILITY_SCREEN_READER_SETTINGS_SPEECH_RATE), - buf, - NULL); - tts_setting_set_speed_changed_cb(__tts_setting_speed_changed_cb, - ad->speech_rate_item); - if (ad->speech_rate_item) { - ad->speech_rate_item->userdata = ad; - __BACK_POINTER_SET(ad->speech_rate_item); - speech_rate_list_item = ad->speech_rate_item; - SETTING_TRACE("Speech rate Item added"); - } +void ScreenReaderSettingsPage::onListItemClicked(void *data, Evas_Object *obj, void *event_info) +{ + Elm_Object_Item *item = (Elm_Object_Item *)event_info; + retm_if(!item, "item == NULL"); - /* Item 2 : Keyboard feedback */ - vconf_ret = vconf_get_bool( - VCONFKEY_SETAPPL_ACCESSIBILITY_SCREEN_READER_KEYBOARD_FEEDBACK, - &vconf_val); - if (vconf_ret != 0) { - LOGE("Failed to get vconf bool value VCONFKEY_SETAPPL_ACCESSIBILITY_SCREEN_READER_KEYBOARD_FEEDBACK. Error: %d", - vconf_ret); - } + elm_genlist_item_selected_set(item, EINA_FALSE); - ad->keyboard_feedback_item = setting_create_Gendial_field_def( - genlist, &itc_multiline_2text, - _keyboard_feedback_mouse_up_Gendial_list_cb, - ad, SwallowType::ICON_RADIO, NULL, - NULL, vconf_val ? 1 : 0, - _(DEVOPTION_STR_ACCESSIBILITY_SCREEN_READER_SETTINGS_KEYBOARD_FEEDBACK), - _(DEVOPTION_STR_ACCESSIBILITY_SCREEN_READER_SETTINGS_KEYBOARD_FEEDBACK_INFO), - _keyboard_feedback_check_update); + GenGroupItemData *list_item = (GenGroupItemData *) + elm_object_item_data_get(item); + retm_if(!list_item, "list_item == NULL"); - if (ad->keyboard_feedback_item) { - ad->keyboard_feedback_item->userdata = ad; - __BACK_POINTER_SET(ad->keyboard_feedback_item); - SETTING_TRACE("Keyboard feedback Item added"); - } + LOGI("ITEM SELECTED: %s", list_item->keyStr.c_str()); + setting_update_gl_item_chk_status(list_item, !list_item->chk_status); +} - /* Item 3 : Hints */ - vconf_ret = vconf_get_bool( - VCONFKEY_SETAPPL_ACCESSIBILITY_SCREEN_READER_DESCRIPTION, - &vconf_val); - if (vconf_ret != 0) { - LOGE("Failed to get vconf bool value VCONFKEY_SETAPPL_ACCESSIBILITY_SCREEN_READER_DESCRIPTION. Error: %d", - vconf_ret); - } +void ScreenReaderSettingsPage::onPopupDoneButtonClicked(void *data, Evas_Object *obj, void *event_info) +{ + Evas_Object *slider; + Evas_Object *layout; + int val; + Evas_Object *popup = (Evas_Object *)data; + retm_if(!popup, "popup == NULL"); + layout = elm_object_content_get(popup); + slider = elm_object_part_content_get(layout, "slider"); - ad->hints_item = setting_create_Gendial_field_def( - genlist, &itc_1text_1icon, - _hints_mouse_up_Gendial_list_cb, - ad, SwallowType::ICON_RADIO, NULL, - NULL, vconf_val ? 1 : 0, - _(DEVOPTION_STR_ACCESSIBILITY_SCREEN_READER_SETTINGS_HINTS), - NULL, - _hints_check_update); + val = (int)elm_slider_value_get(slider); + if (0 != tts_setting_set_speed(val)) + SETTING_TRACE("Setting speed to tts engine failed"); - if (ad->hints_item) { - ad->hints_item->userdata = ad; - __BACK_POINTER_SET(ad->hints_item); - SETTING_TRACE("Hints Item added"); - } + evas_object_del(popup); +} - /* Item 4 : Vibration Feedback */ - vconf_ret = vconf_get_bool( - VCONFKEY_SETAPPL_ACCESSIBILITY_SCREEN_READER_HAPTIC, - &vconf_val); - if (vconf_ret != 0) { - LOGE("Failed to get vconf bool value VCONFKEY_SETAPPL_ACCESSIBILITY_SCREEN_READER_HAPTIC. Error: %d", - vconf_ret); +void ScreenReaderSettingsPage::onCheckStateChanged(void *data, Evas_Object *obj, void *event_info) +{ + if (!data) { + LOGD("data == NULL"); + return; } - ad->vibration_feedback_item = setting_create_Gendial_field_def( - genlist, &itc_1text_1icon, - _vibration_feedback_mouse_up_Gendial_list_cb, - ad, SwallowType::ICON_RADIO, NULL, - NULL, vconf_val ? 1 : 0, - _(DEVOPTION_STR_ACCESSIBILITY_SCREEN_READER_SETTINGS_VIBRATION_FEEDBACK), - NULL, - _vibration_feedback_check_update); + GenGroupItemData *item_data = (GenGroupItemData *)data; + item_data->chk_status = elm_check_state_get(obj); + LOGE("Check changed: %s; status: %d, %p", item_data->keyStr.c_str(), item_data->chk_status, &item_data->chk_status); +} - if (ad->vibration_feedback_item) { - ad->vibration_feedback_item->userdata = ad; - __BACK_POINTER_SET(ad->vibration_feedback_item); - SETTING_TRACE("Vibration feedback Item added"); - } +void ScreenReaderSettingsPage::onDoneButtonClicked(void *data, Evas_Object *obj, void *event_info) +{ + Evas_Object *popup = (Evas_Object *)data; + retm_if(!popup, "popup == NULL"); + evas_object_del(popup); - /* Item 5 : Sound Feedback */ - vconf_ret = vconf_get_bool( - VCONFKEY_SETAPPL_ACCESSIBILITY_SCREEN_READER_SOUND_FEEDBACK, - &vconf_val); - if (vconf_ret != 0) { - LOGE("Failed to get vconf bool value VCONFKEY_SETAPPL_ACCESSIBILITY_SCREEN_READER_SOUND_FEEDBACK. Error: %d", - vconf_ret); - } + foreachVconfKeyCheckSet(); +} - ad->sound_feedback_item = setting_create_Gendial_field_def( - genlist, &itc_1text_1icon, - _sound_feedback_mouse_up_Gendial_list_cb, - ad, SwallowType::ICON_RADIO, NULL, - NULL, vconf_val ? 1 : 0, - _(DEVOPTION_STR_ACCESSIBILITY_SCREEN_READER_SETTINGS_SOUND_FEEDBACK), - NULL, - _sound_feedback_check_update); +void ScreenReaderSettingsPage::onCancelButtonClicked(void *data, Evas_Object *obj, void *event_info) +{ + Evas_Object *popup = (Evas_Object *)data; + retm_if(!popup, "popup == NULL"); + evas_object_del(popup); +} - if (ad->sound_feedback_item) { - ad->sound_feedback_item->userdata = ad; - __BACK_POINTER_SET(ad->sound_feedback_item); - SETTING_TRACE("Sound feedback Item added"); +void ScreenReaderSettingsPage::foreachVconfKeyCheckSet() +{ + for (int i = 0; i < utils::lenOf(vConfCheckData); ++i) { + auto status = *(vConfCheckData[i].status); + vconfKeyValueSet(vConfCheckData[i].vconf_key.c_str(), status); } +} - ad->status_bar_information_item = setting_create_Gendial_field_def( - genlist, &itc_1text, - _status_bar_info_mouse_up_Gendial_list_cb, - ad, SwallowType::INVALID, NULL, - NULL, 1, - _(DEVOPTION_STR_ACCESSIBILITY_SCREEN_READER_SETTINGS_STATUS_BAR_INFORMATION), - NULL, - NULL); - - if (ad->status_bar_information_item) { - ad->status_bar_information_item->userdata = ad; - __BACK_POINTER_SET(ad->status_bar_information_item); - } +void ScreenReaderSettingsPage::vconfKeyValueSet(const char *key, int value) +{ + retm_if(!key, "key == NULL"); - ad->multiline_status_bar_information_description = setting_create_Gendial_field_def( - genlist, &ad->itc_multiline_sub, - NULL, ad, SwallowType::INVALID, NULL, - NULL, 0, - NULL, - _(DEVOPTION_STR_ACCESSIBILITY_SCREEN_READER_SETTINGS_STATUS_BAR_INFORMATION_DESCRIPTION), - NULL); + int ret = vconf_set_bool(key, value); - if (ad->multiline_status_bar_information_description) { - ad->multiline_status_bar_information_description->userdata = ad; - __BACK_POINTER_SET(ad->multiline_status_bar_information_description); + if (ret != 0) { + LOGE("Failed to set vconf key %s. Error: %d", key, ret); + return; + } +} - elm_genlist_item_select_mode_set( - ad->multiline_status_bar_information_description->item, - ELM_OBJECT_SELECT_MODE_DISPLAY_ONLY); +Eina_Bool ScreenReaderSettingsPage::vconfValueGet(const char *key) +{ + retvm_if(!key, EINA_FALSE, "Key is NULL"); + int value = 0; + int ret = vconf_get_bool(key, &value); + if (ret != 0) { + LOGE("Failed to get vconf bool value %s. Error: %d", key, ret); + return EINA_FALSE; } + return (value != 0); +} - Elm_Object_Item *navi_it = elm_naviframe_item_push(ad->md.getNaviframe(), - _(DEVOPTION_STR_ACCESSIBILITY_SCREEN_READER_SETTINGS), - NULL, NULL, genlist, NULL); - elm_object_item_domain_text_translatable_set(navi_it, PACKAGE, - EINA_TRUE); +Eina_Bool ScreenReaderSettingsPage::hidePage(void *data, Elm_Object_Item *it) +{ + retv_if(data == NULL, EINA_TRUE); + SettingAccessibility *ad = (SettingAccessibility *)data; - elm_naviframe_item_pop_cb_set(navi_it, - __page_hide, - ad); + if (0 != tts_setting_unset_speed_changed_cb()) + SETTING_TRACE("Fail to unset speed changed cb"); + + if (0 != tts_setting_unset_voice_changed_cb()) + SETTING_TRACE("Fail to unset voice changed cb"); + if (0 != tts_setting_finalize()) { + LOGE("Fail to setting finalize"); + return -1; + } + elm_naviframe_item_pop(ad->md.getNaviframe()); + return EINA_TRUE; } diff --git a/src/ScreenReaderSettingsPage.hpp b/src/ScreenReaderSettingsPage.hpp new file mode 100644 index 0000000..0511477 --- /dev/null +++ b/src/ScreenReaderSettingsPage.hpp @@ -0,0 +1,44 @@ +#ifndef SCREEN_READER_SETTINGS_PAGE_HPP +#define SCREEN_READER_SETTINGS_PAGE_HPP + +#include "SettingAccessibility.hpp" + +#include + +#include + +class ScreenReaderSettingsPage +{ +public: + ScreenReaderSettingsPage(SettingAccessibility *data); + +private: + static void mouseUpGendialListCb(void *data, Evas_Object *obj, void *event_info); + static void vibrationFeedbackCb(void *data, Evas_Object *obj, void *event_info); + static void updateVibrationFeedbackCheck(void *data, Evas_Object *obj, void *event_info); + static void updateVibrationFeedbackVconf(int state); + static void soundFeedbackCb(void *data, Evas_Object *obj, void *event_info); + static void updateSoundFeedbackCheck(void *data, Evas_Object *obj, void *event_info); + static void updateSoundFeedbackVconf(int state); + static void hintsCb(void *data, Evas_Object *obj, void *event_info); + static void updateHintsCheck(void *data, Evas_Object *obj, void *event_info); + static void updateHintsVconf(int state); + static void keyboardFeedbackCb(void *data, Evas_Object *obj, void *event_info); + static void updateKeyboardFeedbackCheck(void *data, Evas_Object *obj, void *event_info); + static void updateKeyboardFeedbackVconf(int state); + static void speechRateCb(void *data, Evas_Object *obj, void *event_info); + static void ttsSpeedChangedCb(int speed, void *user_data); + static void createSpeechRatePopup(void *data, void *item); + static void onPopupDel(void *data, Evas *e, Evas_Object *obj, void *event_info); + static void onListItemClicked(void *data, Evas_Object *obj, void *event_info); + static void onPopupDoneButtonClicked(void *data, Evas_Object *obj, void *event_info); + static void onCheckStateChanged(void *data, Evas_Object *obj, void *event_info); + static void onDoneButtonClicked(void *data, Evas_Object *obj, void *event_info); + static void onCancelButtonClicked(void *data, Evas_Object *obj, void *event_info); + static void foreachVconfKeyCheckSet(); + static void vconfKeyValueSet(const char *key, int value); + static Eina_Bool vconfValueGet(const char *key); + static Eina_Bool hidePage(void *data, Elm_Object_Item *it); +}; + +#endif diff --git a/src/SettingAccessibility.hpp b/src/SettingAccessibility.hpp index 3547af5..706ae5a 100644 --- a/src/SettingAccessibility.hpp +++ b/src/SettingAccessibility.hpp @@ -5,9 +5,15 @@ #include "SetValueLayout.hpp" #include "UniversalSwitchConfiguration.hpp" #include "AccessibilityLauncherPage.hpp" +#include "ScreenReaderSettingsPage.hpp" +#include "setting-accessibility-universal-switch-dbus.h" + +#include #include +class ScreenReaderSettingsPage; + typedef void (*back_cb)(SettingAccessibility *ad); struct SettingAccessibility { @@ -76,6 +82,7 @@ struct SettingAccessibility { bool launched_by_app_control; std::unique_ptr accessibilityLauncherPage_; + std::unique_ptr screenReaderSettingsPage_; }; #endif diff --git a/src/setting-accessibility-screen-reader-settings.h b/src/setting-accessibility-screen-reader-settings.h deleted file mode 100644 index 8f575d5..0000000 --- a/src/setting-accessibility-screen-reader-settings.h +++ /dev/null @@ -1,10 +0,0 @@ -#ifndef SETTING_ACCESSIBILITY_SCREEN_READER_SETTINGS_H -#define SETTING_ACCESSIBILITY_SCREEN_READER_SETTINGS_H - -#include "setting-accessibility.h" - -void setting_accessibility_screen_reader_settings_page_create( - SettingAccessibility *data); - -#endif /* SETTING_ACCESSIBILITY_SCREEN_READER_SETTINGS_H */ - diff --git a/src/setting-accessibility-screen-reader.cpp b/src/setting-accessibility-screen-reader.cpp index a6ff51a..635d776 100644 --- a/src/setting-accessibility-screen-reader.cpp +++ b/src/setting-accessibility-screen-reader.cpp @@ -20,7 +20,6 @@ */ #include "setting-accessibility-screen-reader.h" -#include "setting-accessibility-screen-reader-settings.h" #include #include @@ -96,7 +95,7 @@ static void setting_accessibility_screenreader_settings_mouse_up_Gendial_list_cb elm_genlist_item_selected_set(item, EINA_FALSE); - setting_accessibility_screen_reader_settings_page_create(ad); + ad->screenReaderSettingsPage_ = std::make_unique(ad); } -- 2.7.4 From 255669be745cc756a0279c1f2e2101455a7973af Mon Sep 17 00:00:00 2001 From: Lukasz Wlazly Date: Fri, 5 Oct 2018 09:16:57 +0200 Subject: [PATCH 10/16] [Cpp refactor] Add ScreenReaderPage class Change-Id: Ieee3e82f4752419e695faa603cd230603b2fbedb --- ...lity-screen-reader.cpp => ScreenReaderPage.cpp} | 221 ++++++++------------- src/ScreenReaderPage.hpp | 23 +++ src/SettingAccessibility.hpp | 3 + src/setting-accessibility-main.cpp | 3 +- src/setting-accessibility-screen-reader.h | 10 - 5 files changed, 114 insertions(+), 146 deletions(-) rename src/{setting-accessibility-screen-reader.cpp => ScreenReaderPage.cpp} (61%) create mode 100644 src/ScreenReaderPage.hpp delete mode 100644 src/setting-accessibility-screen-reader.h diff --git a/src/setting-accessibility-screen-reader.cpp b/src/ScreenReaderPage.cpp similarity index 61% rename from src/setting-accessibility-screen-reader.cpp rename to src/ScreenReaderPage.cpp index 635d776..ac2e3aa 100644 --- a/src/setting-accessibility-screen-reader.cpp +++ b/src/ScreenReaderPage.cpp @@ -1,143 +1,24 @@ -/* - * accessibility - * - * Copyright (c) 2015 Samsung Electronics Co., Ltd. - * - * Contact: Tomasz Olszak - * - * 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. - * - */ - -#include "setting-accessibility-screen-reader.h" - -#include -#include - -static void screen_reader_key_change_vconf_cb(keynode_t *node, void *user_data) -{ - - GenGroupItemData *screenReaderItem = (GenGroupItemData *)user_data; - /*SETTING_TRACE_DEBUG("check_status: %i, node->value.i: %i", - * screenReaderItem->chk_status, node->value.i); */ - /* I don't know why following code does not update check box to - * checked/unchecked */ - /* setting_update_gl_item_chk_status(screenReaderItem, - * node->value.b ? 1 : 0); */ - elm_genlist_item_update(screenReaderItem->item); - -} +#include "ScreenReaderPage.hpp" -static Eina_Bool __setting_accessibility_screen_reader_page_hide(void *data, - Elm_Object_Item *it) -{ - - /* error check */ - retv_if(data == NULL, EINA_TRUE); - SettingAccessibility *ad = (SettingAccessibility *)data; - vconf_ignore_key_changed(VCONFKEY_SETAPPL_ACCESSIBILITY_TTS, - screen_reader_key_change_vconf_cb); - elm_naviframe_item_pop(ad->md.getNaviframe()); - - return EINA_TRUE; -} - -static void setting_accessibility_main_chk_screenreader_vconf_update(int state, void* data) -{ - retm_if(data == NULL, "Data parameter is NULL"); - SettingAccessibility *ad = (SettingAccessibility *)data; - vconf_set_bool(VCONFKEY_SETAPPL_ACCESSIBILITY_TTS, state); - if (!state) { - char buf[255] = ""; - snprintf(buf, sizeof(buf), "%s %s", _(DEVOPTION_STR_ACCESSIBILITY_SCREENREADER), _(DEVOPTION_STR_ACCESSIBILITY_SCREEN_READER_OFF)); - int utterance_id; - int ret = tts_add_text(ad->tts, buf, NULL, TTS_VOICE_TYPE_AUTO, TTS_SPEED_AUTO, &utterance_id); - SETTING_TRACE_DEBUG("tts_add_text %d", ret); - ret = tts_play(ad->tts); - SETTING_TRACE_DEBUG("tts_play %d", ret); - } -} - -static void setting_accessibility_main_chk_screenreader_cb(void *data, - Evas_Object *obj, void *event_info) -{ - - retm_if(data == NULL, "Data parameter is NULL"); - GenGroupItemData *list_item = - (GenGroupItemData *)data; - - /* for genlist update status */ - list_item->chk_status = elm_check_state_get(obj); - - SETTING_TRACE_DEBUG("check_status: %i", list_item->chk_status); - setting_accessibility_main_chk_screenreader_vconf_update( - list_item->chk_status, list_item->userdata); - -} -static void setting_accessibility_screenreader_settings_mouse_up_Gendial_list_cb( - void *data, Evas_Object *obj, void *event_info) -{ - - retm_if(data == NULL, "Invalid argument: data is NULL"); - retm_if(event_info == NULL, "Invalid argument: event_info is NULL"); - Elm_Object_Item *item = (Elm_Object_Item *)event_info; - SettingAccessibility *ad = (SettingAccessibility *)data; - - elm_genlist_item_selected_set(item, EINA_FALSE); - - ad->screenReaderSettingsPage_ = std::make_unique(ad); - - -} - -static void setting_accessibility_screenreader_mouse_up_Gendial_list_cb( - void *data, Evas_Object *obj, void *event_info) -{ - - retm_if(data == NULL, "Invalid argument: data is NULL"); - retm_if(event_info == NULL, "Invalid argument: event_info is NULL"); - Elm_Object_Item *item = (Elm_Object_Item *)event_info; - - elm_genlist_item_selected_set(item, EINA_FALSE); +#include "setting-accessibility.h" - GenGroupItemData *list_item = - (GenGroupItemData *)elm_object_item_data_get( - item); - setting_retm_if(data == NULL, "Data parameter is NULL"); - setting_update_gl_item_chk_status(list_item, - list_item->chk_status ? 0 : 1); - setting_accessibility_main_chk_screenreader_vconf_update( - (list_item->chk_status ? 1 : 0), list_item->userdata); - -} +#include -void setting_accessibility_screen_reader_page_create( - SettingAccessibility *data) +ScreenReaderPage::ScreenReaderPage(SettingAccessibility *data) { SettingAccessibility *ad = (SettingAccessibility *)data; Evas_Object *genlist = elm_genlist_add(ad->md.getNaviframe()); - retm_if(genlist == NULL, - "Cannot set genlist object as content of layout"); + retm_if(genlist == NULL, "Cannot set genlist object as content of layout"); elm_genlist_mode_set(genlist, ELM_LIST_COMPRESS); elm_object_style_set(genlist, "dialogue"); elm_genlist_clear(genlist); ad->screenreader_checkbox = setting_create_Gendial_field_def( genlist, &itc_1text_1icon, - setting_accessibility_screenreader_mouse_up_Gendial_list_cb, + listCb, ad, SwallowType::ICON_RADIO, NULL, NULL, 1, _(DEVOPTION_STR_ACCESSIBILITY_SCREENREADER), - NULL, setting_accessibility_main_chk_screenreader_cb); + NULL, screenReaderCheckCb); if (ad->screenreader_checkbox) { ad->screenreader_checkbox->userdata = ad; __BACK_POINTER_SET(ad->screenreader_checkbox); @@ -150,7 +31,7 @@ void setting_accessibility_screen_reader_page_create( /*---------------------------------------------------------------------------------------------- */ int vconf_ret = vconf_notify_key_changed( VCONFKEY_SETAPPL_ACCESSIBILITY_TTS, - screen_reader_key_change_vconf_cb, + onVconfChangedCb, ad->screenreader_checkbox); if (vconf_ret != 0) { SETTING_TRACE("FAIL: vconf_notify_key_changed(VCONFKEY_SETAPPL_ACCESSIBILITY_TTS)"); @@ -173,7 +54,7 @@ void setting_accessibility_screen_reader_page_create( ad->screen_reader_settings = setting_create_Gendial_field_def( genlist, &itc_1text, - setting_accessibility_screenreader_settings_mouse_up_Gendial_list_cb, + settingsListCb, ad, SwallowType::INVALID, NULL, NULL, 0, DEVOPTION_STR_ACCESSIBILITY_SCREEN_READER_SETTINGS, @@ -183,13 +64,85 @@ void setting_accessibility_screen_reader_page_create( __BACK_POINTER_SET(ad->screen_reader_settings); } - Elm_Object_Item *navi_it = elm_naviframe_item_push(ad->md.getNaviframe(), - _(DEVOPTION_STR_ACCESSIBILITY_SCREENREADER), NULL, NULL, - genlist, NULL); + Elm_Object_Item *navi_it = elm_naviframe_item_push(ad->md.getNaviframe(), _(DEVOPTION_STR_ACCESSIBILITY_SCREENREADER), NULL, NULL, genlist, NULL); elm_object_item_domain_text_translatable_set(navi_it, PACKAGE, EINA_TRUE); - elm_naviframe_item_pop_cb_set(navi_it, - __setting_accessibility_screen_reader_page_hide, - ad); + elm_naviframe_item_pop_cb_set(navi_it, hideScreenReaderPage, ad); +} + +void ScreenReaderPage::listCb(void *data, Evas_Object *obj, void *event_info) +{ + retm_if(data == NULL, "Invalid argument: data is NULL"); + retm_if(event_info == NULL, "Invalid argument: event_info is NULL"); + Elm_Object_Item *item = (Elm_Object_Item *)event_info; + + elm_genlist_item_selected_set(item, EINA_FALSE); + + GenGroupItemData *list_item = (GenGroupItemData *)elm_object_item_data_get(item); + setting_retm_if(data == NULL, "Data parameter is NULL"); + setting_update_gl_item_chk_status(list_item, list_item->chk_status ? 0 : 1); + updateScreenReaderVconfCheck((list_item->chk_status ? 1 : 0), list_item->userdata); +} + +void ScreenReaderPage::settingsListCb(void *data, Evas_Object *obj, void *event_info) +{ + retm_if(data == NULL, "Invalid argument: data is NULL"); + retm_if(event_info == NULL, "Invalid argument: event_info is NULL"); + Elm_Object_Item *item = (Elm_Object_Item *)event_info; + SettingAccessibility *ad = (SettingAccessibility *)data; + + elm_genlist_item_selected_set(item, EINA_FALSE); + + ad->screenReaderSettingsPage_ = std::make_unique(ad); +} + +void ScreenReaderPage::screenReaderCheckCb(void *data, Evas_Object *obj, void *event_info) +{ + retm_if(data == NULL, "Data parameter is NULL"); + GenGroupItemData *list_item = (GenGroupItemData *)data; + + /* for genlist update status */ + list_item->chk_status = elm_check_state_get(obj); + + SETTING_TRACE_DEBUG("check_status: %i", list_item->chk_status); + updateScreenReaderVconfCheck(list_item->chk_status, list_item->userdata); +} + +void ScreenReaderPage::updateScreenReaderVconfCheck(int state, void* data) +{ + retm_if(data == NULL, "Data parameter is NULL"); + SettingAccessibility *ad = (SettingAccessibility *)data; + vconf_set_bool(VCONFKEY_SETAPPL_ACCESSIBILITY_TTS, state); + if (!state) { + char buf[255] = ""; + snprintf(buf, sizeof(buf), "%s %s", _(DEVOPTION_STR_ACCESSIBILITY_SCREENREADER), _(DEVOPTION_STR_ACCESSIBILITY_SCREEN_READER_OFF)); + int utterance_id; + int ret = tts_add_text(ad->tts, buf, NULL, TTS_VOICE_TYPE_AUTO, TTS_SPEED_AUTO, &utterance_id); + SETTING_TRACE_DEBUG("tts_add_text %d", ret); + ret = tts_play(ad->tts); + SETTING_TRACE_DEBUG("tts_play %d", ret); + } +} + +Eina_Bool ScreenReaderPage::hideScreenReaderPage(void *data, Elm_Object_Item *it) +{ + retv_if(data == NULL, EINA_TRUE); + SettingAccessibility *ad = (SettingAccessibility *)data; + vconf_ignore_key_changed(VCONFKEY_SETAPPL_ACCESSIBILITY_TTS, onVconfChangedCb); + elm_naviframe_item_pop(ad->md.getNaviframe()); + + return EINA_TRUE; +} + +void ScreenReaderPage::onVconfChangedCb(keynode_t *node, void *user_data) +{ + GenGroupItemData *screenReaderItem = (GenGroupItemData *)user_data; + /*SETTING_TRACE_DEBUG("check_status: %i, node->value.i: %i", + * screenReaderItem->chk_status, node->value.i); */ + /* I don't know why following code does not update check box to + * checked/unchecked */ + /* setting_update_gl_item_chk_status(screenReaderItem, + * node->value.b ? 1 : 0); */ + elm_genlist_item_update(screenReaderItem->item); } diff --git a/src/ScreenReaderPage.hpp b/src/ScreenReaderPage.hpp new file mode 100644 index 0000000..ca25649 --- /dev/null +++ b/src/ScreenReaderPage.hpp @@ -0,0 +1,23 @@ +#ifndef SCREEN_READER_PAGE_HPP +#define SCREEN_READER_PAGE_HPP + +#include "SettingAccessibility.hpp" + +#include +#include + +class ScreenReaderPage +{ +public: + ScreenReaderPage(SettingAccessibility *data); + +private: + static void listCb(void *data, Evas_Object *obj, void *event_info); + static void settingsListCb(void *data, Evas_Object *obj, void *event_info); + static void screenReaderCheckCb(void *data, Evas_Object *obj, void *event_info); + static void updateScreenReaderVconfCheck(int state, void* data); + static Eina_Bool hideScreenReaderPage(void *data, Elm_Object_Item *it); + static void onVconfChangedCb(keynode_t *node, void *user_data); +}; + +#endif diff --git a/src/SettingAccessibility.hpp b/src/SettingAccessibility.hpp index 706ae5a..6445087 100644 --- a/src/SettingAccessibility.hpp +++ b/src/SettingAccessibility.hpp @@ -7,12 +7,14 @@ #include "AccessibilityLauncherPage.hpp" #include "ScreenReaderSettingsPage.hpp" #include "setting-accessibility-universal-switch-dbus.h" +#include "ScreenReaderPage.hpp" #include #include class ScreenReaderSettingsPage; +class ScreenReaderPage; typedef void (*back_cb)(SettingAccessibility *ad); @@ -83,6 +85,7 @@ struct SettingAccessibility { std::unique_ptr accessibilityLauncherPage_; std::unique_ptr screenReaderSettingsPage_; + std::unique_ptr screenReaderPage_; }; #endif diff --git a/src/setting-accessibility-main.cpp b/src/setting-accessibility-main.cpp index 73345f1..4bcdf7d 100644 --- a/src/setting-accessibility-main.cpp +++ b/src/setting-accessibility-main.cpp @@ -20,7 +20,6 @@ */ #include "setting-accessibility.h" -#include "setting-accessibility-screen-reader.h" #include "setting-accessibility-universal-switch.h" #include @@ -72,7 +71,7 @@ static void setting_accessibility_vision_screen_reader_mouse_up_Gendial_list_cb( Elm_Object_Item *item = (Elm_Object_Item *)event_info; SettingAccessibility *ad = (SettingAccessibility *)data; elm_genlist_item_selected_set(item, EINA_FALSE); - setting_accessibility_screen_reader_page_create(ad); + ad->screenReaderPage_ = std::make_unique(ad); } diff --git a/src/setting-accessibility-screen-reader.h b/src/setting-accessibility-screen-reader.h deleted file mode 100644 index 9c89e38..0000000 --- a/src/setting-accessibility-screen-reader.h +++ /dev/null @@ -1,10 +0,0 @@ -#ifndef SETTINGACCESSIBILITYSCREENREADER_H -#define SETTINGACCESSIBILITYSCREENREADER_H - -#include "setting-accessibility.h" - -void setting_accessibility_screen_reader_page_create( - SettingAccessibility *data); - -#endif /* SETTINGACCESSIBILITYSCREENREADER_H */ - -- 2.7.4 From 9c9038e5180a32c255c1a62d3f727118e5bd402a Mon Sep 17 00:00:00 2001 From: Lukasz Wlazly Date: Fri, 5 Oct 2018 11:18:46 +0200 Subject: [PATCH 11/16] [Cpp refactor] Add CameraSwitchesPage class Change-Id: I010ac96cc02420276715bf63fe5ece1784d7e66e --- ...dd-switch-camera.cpp => CameraSwitchesPage.cpp} | 123 +++++++-------------- src/CameraSwitchesPage.hpp | 19 ++++ src/SettingAccessibility.hpp | 3 + ...ity-universal-switch-add-switch-accessories.cpp | 2 +- ...essibility-universal-switch-add-switch-camera.h | 10 -- ...sibility-universal-switch-add-switch-screen.cpp | 2 +- ...g-accessibility-universal-switch-add-switch.cpp | 5 +- ...ibility-universal-switch-settings-set-value.cpp | 2 +- ...ccessibility-universal-switch-update-switch.cpp | 2 +- src/setting-accessibility.h | 4 +- 10 files changed, 71 insertions(+), 101 deletions(-) rename src/{setting-accessibility-universal-switch-add-switch-camera.cpp => CameraSwitchesPage.cpp} (66%) mode change 100755 => 100644 create mode 100644 src/CameraSwitchesPage.hpp delete mode 100644 src/setting-accessibility-universal-switch-add-switch-camera.h diff --git a/src/setting-accessibility-universal-switch-add-switch-camera.cpp b/src/CameraSwitchesPage.cpp old mode 100755 new mode 100644 similarity index 66% rename from src/setting-accessibility-universal-switch-add-switch-camera.cpp rename to src/CameraSwitchesPage.cpp index e1068c0..35dea4b --- a/src/setting-accessibility-universal-switch-add-switch-camera.cpp +++ b/src/CameraSwitchesPage.cpp @@ -1,85 +1,12 @@ -/* - * accessibility - * - * Copyright (c) 2017 Samsung Electronics Co., Ltd. - * - * Contact: Michal Pawluk - * - * 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. - * - */ - -#include "setting-accessibility-universal-switch-add-switch-camera.h" +#include "CameraSwitchesPage.hpp" + #include "setting-accessibility-universal-switch-action.h" #include "setting-accessibility-universal-switch-add-switch.h" #include - -static void __back_cb(void *data, Evas_Object *obj, void *event_info) -{ - - retm_if(data == NULL, "Data argument is NULL"); - SettingAccessibility *ad = (SettingAccessibility *)data; - - elm_naviframe_item_pop(ad->md.getNaviframe()); - - -} - -static void __switch_action_cb(SettingAccessibility *ad, switch_action_t action, void *user_data) -{ - - retm_if(user_data == NULL, "User data parameter is NULL"); - UniversalSwitchInfoType * camera_switch = (UniversalSwitchInfoType *)user_data; - - if (ad->us_configuration.camera_switch_added_cb) - ad->us_configuration.camera_switch_added_cb(ad, camera_switch->id, action, camera_switch->name); - - -} - -static void __create_action_page(SettingAccessibility *ad, UniversalSwitchInfoType * camera_switch) -{ - - retm_if(ad == NULL, "Data argument is NULL"); - - SETTING_TRACE_DEBUG("Camera switch, id: %s, name: %s", camera_switch->id, camera_switch->name); - - setting_accessibility_universal_switch_action_page_create(ad); - setting_accessibility_universal_switch_action_callback_attach(ad, __switch_action_cb, camera_switch); - - -} - -static void __add_camera_switch_cb(void *data, Evas_Object *obj, void *event_info) -{ - - Elm_Object_Item *item = (Elm_Object_Item *)event_info; - elm_genlist_item_selected_set(item, EINA_FALSE); - GenGroupItemData *settings_item = (GenGroupItemData *)elm_object_item_data_get(item); - SettingAccessibility *ad = (SettingAccessibility *)settings_item->userdata; - retm_if(ad == NULL, "Input argument is NULL"); - UniversalSwitchInfoType * camera_switch = (UniversalSwitchInfoType *)data; - - __create_action_page(ad, camera_switch); - - -} - -void setting_accessibility_universal_switch_add_switch_camera_page_create(SettingAccessibility *ad) +CameraSwitchesPage::CameraSwitchesPage(SettingAccessibility *ad) { - retm_if(ad == NULL, "Input parameter is NULL"); Evas_Object *genlist = elm_genlist_add(ad->md.getNaviframe()); retm_if(genlist == NULL, "Cannot set genlist object as content of layout"); @@ -101,7 +28,7 @@ void setting_accessibility_universal_switch_add_switch_camera_page_create(Settin auto switches = setting_accessibility_universal_switch_dbus_config_get_switches(&ad->config, ACCESSIBILITY_UNIVERSAL_SWITCH_CAMERA_SWITCH_PROVIDER); for (auto &it : switches) { - auto item = setting_create_Gendial_field_def(genlist, &ad->itc_multiline_sub, __add_camera_switch_cb, it, + auto item = setting_create_Gendial_field_def(genlist, &ad->itc_multiline_sub, addSwitchCb, it, SwallowType::INVALID, NULL, NULL, 0, it->name.c_str(), it->description.c_str(), NULL); if (item) { @@ -113,18 +40,52 @@ void setting_accessibility_universal_switch_add_switch_camera_page_create(Settin Elm_Object_Item *navi_it = elm_naviframe_item_push(ad->md.getNaviframe(), _(DEVOPTION_STR_ACCESSIBILITY_UNIVERSAL_SWITCH_ADD_SWITCH_CAMERA_TITLE), NULL, NULL, genlist, NULL); elm_object_item_domain_text_translatable_set(navi_it, PACKAGE, EINA_TRUE); - Evas_Object *back_btn = setting_create_button(ad->md.getNaviframe(), NULL, NAVI_BACK_ARROW_BUTTON_STYLE, __back_cb, ad); + Evas_Object *back_btn = setting_create_button(ad->md.getNaviframe(), NULL, NAVI_BACK_ARROW_BUTTON_STYLE, backCb, ad); elm_layout_content_set(ad->md.getNaviframe(), "prev_btn", back_btn); +} +void CameraSwitchesPage::newSwitchCb(SettingAccessibility *ad, UniversalSwitchUpdateCb cb) +{ + retm_if(ad == NULL, "Input parameter is NULL"); + ad->us_configuration.camera_switch_added_cb = cb; } -void setting_accessibility_universal_switch_add_switch_camera_new_switch_callback_attach(SettingAccessibility *ad, UniversalSwitchUpdateCb cb) +void CameraSwitchesPage::addSwitchCb(void *data, Evas_Object *obj, void *event_info) { + Elm_Object_Item *item = (Elm_Object_Item *)event_info; + elm_genlist_item_selected_set(item, EINA_FALSE); + GenGroupItemData *settings_item = (GenGroupItemData *)elm_object_item_data_get(item); + SettingAccessibility *ad = (SettingAccessibility *)settings_item->userdata; + retm_if(ad == NULL, "Input argument is NULL"); + UniversalSwitchInfoType * camera_switch = (UniversalSwitchInfoType *)data; - retm_if(ad == NULL, "Input parameter is NULL"); + createActionPage(ad, camera_switch); +} - ad->us_configuration.camera_switch_added_cb = cb; +void CameraSwitchesPage::createActionPage(SettingAccessibility *ad, UniversalSwitchInfoType * camera_switch) +{ + retm_if(ad == NULL, "Data argument is NULL"); + + SETTING_TRACE_DEBUG("Camera switch, id: %s, name: %s", camera_switch->id, camera_switch->name); + + setting_accessibility_universal_switch_action_page_create(ad); + setting_accessibility_universal_switch_action_callback_attach(ad, switchActionCb, camera_switch); +} + +void CameraSwitchesPage::switchActionCb(SettingAccessibility *ad, const std::string& action, void *user_data) +{ + retm_if(user_data == NULL, "User data parameter is NULL"); + UniversalSwitchInfoType * camera_switch = (UniversalSwitchInfoType *)user_data; + + if (ad->us_configuration.camera_switch_added_cb) + ad->us_configuration.camera_switch_added_cb(ad, camera_switch->id, action, camera_switch->name); +} +void CameraSwitchesPage::backCb(void *data, Evas_Object *obj, void *event_info) +{ + retm_if(data == NULL, "Data argument is NULL"); + SettingAccessibility *ad = (SettingAccessibility *)data; + elm_naviframe_item_pop(ad->md.getNaviframe()); } diff --git a/src/CameraSwitchesPage.hpp b/src/CameraSwitchesPage.hpp new file mode 100644 index 0000000..b5cce4a --- /dev/null +++ b/src/CameraSwitchesPage.hpp @@ -0,0 +1,19 @@ +#ifndef CAMERA_SWITCHES_PAGE +#define CAMERA_SWITCHES_PAGE value + +#include "SettingAccessibility.hpp" + +class CameraSwitchesPage +{ +public: + CameraSwitchesPage(SettingAccessibility *ad); + static void newSwitchCb(SettingAccessibility *ad, UniversalSwitchUpdateCb cb); + +private: + static void addSwitchCb(void *data, Evas_Object *obj, void *event_info); + static void createActionPage(SettingAccessibility *ad, UniversalSwitchInfoType * camera_switch); + static void switchActionCb(SettingAccessibility *ad, const std::string& action, void *user_data); + static void backCb(void *data, Evas_Object *obj, void *event_info); +}; + +#endif diff --git a/src/SettingAccessibility.hpp b/src/SettingAccessibility.hpp index 6445087..87216cb 100644 --- a/src/SettingAccessibility.hpp +++ b/src/SettingAccessibility.hpp @@ -8,6 +8,7 @@ #include "ScreenReaderSettingsPage.hpp" #include "setting-accessibility-universal-switch-dbus.h" #include "ScreenReaderPage.hpp" +#include "CameraSwitchesPage.hpp" #include @@ -15,6 +16,7 @@ class ScreenReaderSettingsPage; class ScreenReaderPage; +class CameraSwitchesPage; typedef void (*back_cb)(SettingAccessibility *ad); @@ -86,6 +88,7 @@ struct SettingAccessibility { std::unique_ptr accessibilityLauncherPage_; std::unique_ptr screenReaderSettingsPage_; std::unique_ptr screenReaderPage_; + std::unique_ptr cameraSwitchesPage_; }; #endif diff --git a/src/setting-accessibility-universal-switch-add-switch-accessories.cpp b/src/setting-accessibility-universal-switch-add-switch-accessories.cpp index b60aecb..89c536f 100755 --- a/src/setting-accessibility-universal-switch-add-switch-accessories.cpp +++ b/src/setting-accessibility-universal-switch-add-switch-accessories.cpp @@ -72,7 +72,7 @@ static Eina_Bool __renew_capture_switch_cb(void *data, Elm_Object_Item *it) return EINA_TRUE; } -static void __accessory_switch_action_cb(SettingAccessibility *ad, switch_action_t action, void *user_data) +static void __accessory_switch_action_cb(SettingAccessibility *ad, const std::string& action, void *user_data) { retm_if(user_data == NULL, "User data parameter is NULL"); diff --git a/src/setting-accessibility-universal-switch-add-switch-camera.h b/src/setting-accessibility-universal-switch-add-switch-camera.h deleted file mode 100644 index 3522a4d..0000000 --- a/src/setting-accessibility-universal-switch-add-switch-camera.h +++ /dev/null @@ -1,10 +0,0 @@ -#ifndef SETTINGACCESSIBILITYUNIVERSALSWITCHADDSWITCHCAMERA_H -#define SETTINGACCESSIBILITYUNIVERSALSWITCHADDSWITCHCAMERA_H - -#include "setting-accessibility.h" - -void setting_accessibility_universal_switch_add_switch_camera_page_create(SettingAccessibility *ad); -void setting_accessibility_universal_switch_add_switch_camera_new_switch_callback_attach(SettingAccessibility *ad, UniversalSwitchUpdateCb cb); - -#endif /* SETTINGACCESSIBILITYUNIVERSALSWITCHADDSWITCHCAMERA_H */ - diff --git a/src/setting-accessibility-universal-switch-add-switch-screen.cpp b/src/setting-accessibility-universal-switch-add-switch-screen.cpp index 8643070..acaad44 100644 --- a/src/setting-accessibility-universal-switch-add-switch-screen.cpp +++ b/src/setting-accessibility-universal-switch-add-switch-screen.cpp @@ -22,7 +22,7 @@ #include "setting-accessibility-universal-switch-add-switch-screen.h" #include "setting-accessibility-universal-switch-action.h" -static void __screen_switch_action_cb(SettingAccessibility *ad, switch_action_t action, void *user_data) +static void __screen_switch_action_cb(SettingAccessibility *ad, const std::string& action, void *user_data) { diff --git a/src/setting-accessibility-universal-switch-add-switch.cpp b/src/setting-accessibility-universal-switch-add-switch.cpp index 891fb10..85e6ca7 100755 --- a/src/setting-accessibility-universal-switch-add-switch.cpp +++ b/src/setting-accessibility-universal-switch-add-switch.cpp @@ -22,7 +22,6 @@ #include "setting-accessibility-universal-switch-add-switch.h" #include "setting-accessibility-universal-switch-add-switch-screen.h" #include "setting-accessibility-universal-switch-add-switch-accessories.h" -#include "setting-accessibility-universal-switch-add-switch-camera.h" #include @@ -58,7 +57,7 @@ static void __add_switch_page_create(SettingAccessibility *ad, const char * prov if (strncmp(providerId, ACCESSIBILITY_UNIVERSAL_SWITCH_SCREEN_SWITCH_PROVIDER, sizeof(ACCESSIBILITY_UNIVERSAL_SWITCH_SCREEN_SWITCH_PROVIDER)) == 0) setting_accessibility_universal_switch_add_switch_screen_page_create(ad); else if (strncmp(providerId, ACCESSIBILITY_UNIVERSAL_SWITCH_CAMERA_SWITCH_PROVIDER, sizeof(ACCESSIBILITY_UNIVERSAL_SWITCH_SCREEN_SWITCH_PROVIDER)) == 0) - setting_accessibility_universal_switch_add_switch_camera_page_create(ad); + ad->cameraSwitchesPage_ = std::make_unique(ad); else if (strncmp(providerId, ACCESSIBILITY_UNIVERSAL_SWITCH_ACCESSORIES_SWITCH_PROVIDER, sizeof(ACCESSIBILITY_UNIVERSAL_SWITCH_ACCESSORIES_SWITCH_PROVIDER)) == 0) setting_accessibility_universal_switch_add_switch_accessories_page_create(ad); else @@ -146,7 +145,7 @@ void setting_accessibility_universal_switch_add_switch_new_switch_callback_attac setting_accessibility_universal_switch_add_switch_screen_new_switch_callback_attach(ad, cb); setting_accessibility_universal_switch_add_switch_accessories_new_switch_callback_attach(ad, cb); - setting_accessibility_universal_switch_add_switch_camera_new_switch_callback_attach(ad, cb); + CameraSwitchesPage::newSwitchCb(ad, cb); } diff --git a/src/setting-accessibility-universal-switch-settings-set-value.cpp b/src/setting-accessibility-universal-switch-settings-set-value.cpp index 3c0a200..5742198 100755 --- a/src/setting-accessibility-universal-switch-settings-set-value.cpp +++ b/src/setting-accessibility-universal-switch-settings-set-value.cpp @@ -685,7 +685,7 @@ static void __update_action_gendial_field(SettingAccessibility *ad) } -static void __update_accessible_switch_choose_action(SettingAccessibility *ad, switch_action_t action, void *user_data) +static void __update_accessible_switch_choose_action(SettingAccessibility *ad, const std::string& action, void *user_data) { ad->config_item_to_update.activity_type = action; diff --git a/src/setting-accessibility-universal-switch-update-switch.cpp b/src/setting-accessibility-universal-switch-update-switch.cpp index 6c5b3b0..28d80ab 100644 --- a/src/setting-accessibility-universal-switch-update-switch.cpp +++ b/src/setting-accessibility-universal-switch-update-switch.cpp @@ -23,7 +23,7 @@ #include "setting-accessibility-universal-switch-action.h" #include "setting-accessibility-universal-switch-settings-set-value.h" -static void __update_switch_action_cb(SettingAccessibility *ad, switch_action_t action, void *user_data) +static void __update_switch_action_cb(SettingAccessibility *ad, const std::string& action, void *user_data) { diff --git a/src/setting-accessibility.h b/src/setting-accessibility.h index 7cc8d86..2505045 100755 --- a/src/setting-accessibility.h +++ b/src/setting-accessibility.h @@ -218,11 +218,9 @@ typedef enum {MANAGE_GESTURES, MANAGE_ACTIONS, MANAGE_SETTINGS, MANAGE_RECENT_APPS, MANAGE_HOME_SCREEN, MANAGE_BACK, MANAGE_BUTTONS_AND_KEYS, MANAGE_CONTEXTUAL_MENU} manage_options_type_t; -typedef const std::string& switch_action_t; - struct SettingAccessibility; -typedef void (*switch_action_cb)(SettingAccessibility *ad, switch_action_t action, void *user_data); +typedef void (*switch_action_cb)(SettingAccessibility *ad, const std::string& action, void *user_data); extern setting_view setting_view_accessibility_main; -- 2.7.4 From 767f994172e40ac1435027bae46bfc7aa646b1e9 Mon Sep 17 00:00:00 2001 From: Lukasz Wlazly Date: Fri, 5 Oct 2018 13:14:09 +0200 Subject: [PATCH 12/16] [Cpp refactor] Add AccessoriesSwitchesPage class Change-Id: I791d488c6409cd8a6a3333bbc65827f79fa08a60 --- ...accessories.cpp => AccessoriesSwitchesPage.cpp} | 270 +++++++++------------ src/AccessoriesSwitchesPage.hpp | 27 +++ src/CameraSwitchesPage.cpp | 2 +- src/CameraSwitchesPage.hpp | 2 +- src/SettingAccessibility.hpp | 3 + ...ility-universal-switch-add-switch-accessories.h | 10 - ...g-accessibility-universal-switch-add-switch.cpp | 7 +- 7 files changed, 143 insertions(+), 178 deletions(-) rename src/{setting-accessibility-universal-switch-add-switch-accessories.cpp => AccessoriesSwitchesPage.cpp} (62%) mode change 100755 => 100644 create mode 100644 src/AccessoriesSwitchesPage.hpp delete mode 100644 src/setting-accessibility-universal-switch-add-switch-accessories.h diff --git a/src/setting-accessibility-universal-switch-add-switch-accessories.cpp b/src/AccessoriesSwitchesPage.cpp old mode 100755 new mode 100644 similarity index 62% rename from src/setting-accessibility-universal-switch-add-switch-accessories.cpp rename to src/AccessoriesSwitchesPage.cpp index 89c536f..46746f3 --- a/src/setting-accessibility-universal-switch-add-switch-accessories.cpp +++ b/src/AccessoriesSwitchesPage.cpp @@ -1,162 +1,84 @@ -/* - * accessibility - * - * Copyright (c) 2017 Samsung Electronics Co., Ltd. - * - * Contact: Michal Pawluk - * - * 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. - * - */ - -#include -#include "setting-accessibility-universal-switch-add-switch-accessories.h" +#include "AccessoriesSwitchesPage.hpp" + +#include "setting-accessibility.h" #include "setting-accessibility-universal-switch-action.h" #include #define EDJ_ACCESSORY "edje/accessibility-smart-switch-accessory.edj" -#define GRP_ACCESSORY "accessory" #define PRT_ACCESSORY_LABEL "accessory_label" - #define EDJ_ACCESSORY_POPUP "edje/accessibility-smart-switch-accessory-popup.edj" +#define PRT_ACCESSORY_POPUP_ENTRY "accessory_popup_entry" #define GRP_ACCESSORY_POPUP "accessory_popup" +#define GRP_ACCESSORY "accessory" #define PRT_ACCESSORY_POPUP_LABEL "accessory_popup_label" -#define PRT_ACCESSORY_POPUP_ENTRY "accessory_popup_entry" - - -static Evas_Object *__create_layout(Evas_Object *parent, const char *edj_file, const char *group); -static Evas_Object *__create_entry(Evas_Object *parent, const char *part_name); -static void __capture_switch_cb(void *user_data, const char *switch_id); - -static void __back_cb(void *data, Evas_Object *obj, void *event_info) -{ - - retm_if(data == NULL, "Data argument is NULL"); - SettingAccessibility *ad = (SettingAccessibility *)data; - elm_naviframe_item_pop(ad->md.getNaviframe()); - -} - -static Eina_Bool __naviframe_pop_cb(void *data, Elm_Object_Item *it) +AccessoriesSwitchesPage::AccessoriesSwitchesPage(SettingAccessibility *ad) { - retv_if(data == NULL, EINA_TRUE); - SettingAccessibility *ad = (SettingAccessibility *)data; + retm_if(ad == NULL, "Input parameter is NULL"); + Evas_Object *layout = createLayout(ad->md.getNaviframe(), EDJ_ACCESSORY, GRP_ACCESSORY); - setting_accessibility_universal_switch_dbus_config_cancelCaptureSwitch(&ad->config); ad->us_configuration.switch_id = {}; + elm_layout_text_set(layout, PRT_ACCESSORY_LABEL, _(DEVOPTION_STR_ACCESSIBILITY_UNIVERSAL_SWITCH_ADD_SWITCH_ACCESSORIES_DESC)); - return EINA_TRUE; -} - -static Eina_Bool __renew_capture_switch_cb(void *data, Elm_Object_Item *it) -{ - - retv_if(data == NULL, EINA_TRUE); - SettingAccessibility *ad = (SettingAccessibility *)data; - - setting_accessibility_universal_switch_dbus_config_captureSwitch(&ad->config, ACCESSIBILITY_UNIVERSAL_SWITCH_ACCESSORIES_SWITCH_PROVIDER, -1, __capture_switch_cb, ad); - - - return EINA_TRUE; -} - -static void __accessory_switch_action_cb(SettingAccessibility *ad, const std::string& action, void *user_data) -{ - - retm_if(user_data == NULL, "User data parameter is NULL"); - - if (ad->us_configuration.accessories_switch_added_cb) { - char *switch_name = (char *)user_data; - ad->us_configuration.accessories_switch_added_cb(ad, ad->us_configuration.switch_id.c_str(), action, switch_name); - free(switch_name); - } + Elm_Object_Item *navi_it = elm_naviframe_item_push(ad->md.getNaviframe(), _(DEVOPTION_STR_ACCESSIBILITY_UNIVERSAL_SWITCH_ADD_SWITCH_ACCESSORIES_TITLE), NULL, NULL, layout, NULL); + elm_naviframe_item_pop_cb_set(navi_it, naviframPopCb, ad); + elm_object_item_domain_text_translatable_set(navi_it, PACKAGE, EINA_TRUE); + Evas_Object *back_btn = setting_create_button(ad->md.getNaviframe(), NULL, NAVI_BACK_ARROW_BUTTON_STYLE, backCb, ad); + elm_layout_content_set(ad->md.getNaviframe(), "prev_btn", back_btn); + setting_accessibility_universal_switch_dbus_config_captureSwitch(&ad->config, ACCESSIBILITY_UNIVERSAL_SWITCH_ACCESSORIES_SWITCH_PROVIDER, -1, captureSwitchCb, ad); } -static void __popup_response_cb(void *data, Evas_Object *obj, void *event_info) +void AccessoriesSwitchesPage::attachActionCallback(SettingAccessibility *ad, UniversalSwitchUpdateCb cb) { + retm_if(ad == NULL, "Input parameter is NULL"); - retm_if(data == NULL, "Data parameter is NULL"); - SettingAccessibility *ad = (SettingAccessibility *)data; - int response_type = btn_type(obj); - - if (response_type == POPUP_RESPONSE_OK) { - const char *switch_name = elm_entry_entry_get(ad->entry); - if (strlen(switch_name) == 0) { - SETTING_TRACE_END; - return; - } - - setting_accessibility_universal_switch_action_page_create(ad); - elm_naviframe_item_pop_cb_set(elm_naviframe_top_item_get(ad->md.getNaviframe()), __renew_capture_switch_cb, ad); - setting_accessibility_universal_switch_action_callback_attach(ad, __accessory_switch_action_cb, (void *)strdup(switch_name)); - } else { - __renew_capture_switch_cb(ad, NULL); - } - - evas_object_del(ad->popup); - ad->popup = NULL; - ad->entry = NULL; - - + ad->us_configuration.accessories_switch_added_cb = cb; } -static void __ok_response_cb(void *data, Evas_Object *obj, void *event_info) +Evas_Object* AccessoriesSwitchesPage::createEntry(Evas_Object *parent, const char *part_name) { + Evas_Object *entry = elm_entry_add(parent); + evas_object_size_hint_weight_set(entry, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND); + elm_object_part_content_set(parent, part_name, entry); + evas_object_show(entry); - retm_if(data == NULL, "Data parameter is NULL"); - SettingAccessibility *ad = (SettingAccessibility *)data; - - __renew_capture_switch_cb(ad, NULL); - - evas_object_del(ad->popup); - ad->popup = NULL; - - + return entry; } -static void __switch_already_mapped_popup(SettingAccessibility *ad) +Evas_Object *AccessoriesSwitchesPage::createLayout(Evas_Object *parent, const char *edj_file, const char *group) { + Evas_Object *layout; + char *res_path; + char edj_path[PATH_MAX] = {0, }; + retvm_if(parent == NULL, NULL, "Input parameter is NULL"); + res_path = app_get_resource_path(); + if (res_path) { + snprintf(edj_path, sizeof(edj_path), "%s%s", res_path, edj_file); + free(res_path); + } - ad->popup = setting_create_popup(ad, ad->md.getNaviframe(), - _(DEVOPTION_STR_ACCESSIBILITY_UNIVERSAL_SWITCH_UNABLE_TO_ADD), NULL, - __ok_response_cb, 0, - true, - true, - 1, DEVOPTION_STR_ACCESSIBILITY_UNIVERSAL_SWITCH_OK); - - Evas_Object *layout = __create_layout(ad->popup, EDJ_ACCESSORY_POPUP, GRP_ACCESSORY_POPUP); - - elm_object_part_text_set(layout, PRT_ACCESSORY_POPUP_LABEL, DEVOPTION_STR_ACCESSIBILITY_UNIVERSAL_SWITCH_ALREADY_ADDED); - elm_object_content_set(ad->popup, layout); + layout = elm_layout_add(parent); + elm_layout_file_set(layout, edj_path, group); + evas_object_size_hint_weight_set(layout, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND); + evas_object_show(layout); + return layout; } -static void __capture_switch_cb(void *user_data, const char *switch_id) +void AccessoriesSwitchesPage::captureSwitchCb(void *user_data, const char *switch_id) { - retm_if(user_data == NULL, "Input argument is NULL"); retm_if(switch_id == NULL, "switch_id is NULL"); SettingAccessibility *ad = (SettingAccessibility *)user_data; for (auto &it : ad->config.configuration_items) { if (strlen(switch_id) == it->switch_id.size() && strncmp(switch_id, it->switch_id.c_str(), strlen(switch_id)) == 0) { - __switch_already_mapped_popup(ad); + alreadyMappedSwitchPopup(ad); return; } } @@ -164,82 +86,106 @@ static void __capture_switch_cb(void *user_data, const char *switch_id) ad->us_configuration.switch_id = switch_id; ad->popup = setting_create_popup(ad, ad->md.getNaviframe(), _(DEVOPTION_STR_ACCESSIBILITY_UNIVERSAL_SWITCH_ADD_SWITCH), NULL, - __popup_response_cb, 0, + popupResponseCb, 0, true, true, 2, DEVOPTION_STR_ACCESSIBILITY_UNIVERSAL_SWITCH_CANCEL, DEVOPTION_STR_ACCESSIBILITY_UNIVERSAL_SWITCH_SAVE); - Evas_Object *layout = __create_layout(ad->popup, EDJ_ACCESSORY_POPUP, GRP_ACCESSORY_POPUP); + Evas_Object *layout = createLayout(ad->popup, EDJ_ACCESSORY_POPUP, GRP_ACCESSORY_POPUP); - ad->entry = __create_entry(layout, PRT_ACCESSORY_POPUP_ENTRY); + ad->entry = createEntry(layout, PRT_ACCESSORY_POPUP_ENTRY); elm_object_part_text_set(ad->entry, "guide", _(DEVOPTION_STR_ACCESSIBILITY_UNIVERSAL_SWITCH_ADD_SWITCH_NAME)); elm_object_content_set(ad->popup, layout); - - } -static Evas_Object *__create_layout(Evas_Object *parent, const char *edj_file, const char *group) +void AccessoriesSwitchesPage::alreadyMappedSwitchPopup(SettingAccessibility *ad) { + ad->popup = setting_create_popup(ad, ad->md.getNaviframe(), + _(DEVOPTION_STR_ACCESSIBILITY_UNIVERSAL_SWITCH_UNABLE_TO_ADD), NULL, + okResponseCb, 0, + true, + true, + 1, DEVOPTION_STR_ACCESSIBILITY_UNIVERSAL_SWITCH_OK); - Evas_Object *layout; - char *res_path; - char edj_path[PATH_MAX] = {0, }; - retvm_if(parent == NULL, NULL, "Input parameter is NULL"); + Evas_Object *layout = createLayout(ad->popup, EDJ_ACCESSORY_POPUP, GRP_ACCESSORY_POPUP); - res_path = app_get_resource_path(); - if (res_path) { - snprintf(edj_path, sizeof(edj_path), "%s%s", res_path, edj_file); - free(res_path); - } + elm_object_part_text_set(layout, PRT_ACCESSORY_POPUP_LABEL, DEVOPTION_STR_ACCESSIBILITY_UNIVERSAL_SWITCH_ALREADY_ADDED); + elm_object_content_set(ad->popup, layout); +} - layout = elm_layout_add(parent); - elm_layout_file_set(layout, edj_path, group); - evas_object_size_hint_weight_set(layout, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND); - evas_object_show(layout); +void AccessoriesSwitchesPage::okResponseCb(void *data, Evas_Object *obj, void *event_info) +{ + retm_if(data == NULL, "Data parameter is NULL"); + SettingAccessibility *ad = (SettingAccessibility *)data; + renewCaptureSwitchCb(ad, NULL); - return layout; + evas_object_del(ad->popup); + ad->popup = NULL; } -static Evas_Object *__create_entry(Evas_Object *parent, const char *part_name) +void AccessoriesSwitchesPage::popupResponseCb(void *data, Evas_Object *obj, void *event_info) { + retm_if(data == NULL, "Data parameter is NULL"); + SettingAccessibility *ad = (SettingAccessibility *)data; + int response_type = btn_type(obj); - Evas_Object *entry = elm_entry_add(parent); - evas_object_size_hint_weight_set(entry, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND); - elm_object_part_content_set(parent, part_name, entry); - evas_object_show(entry); + if (response_type == POPUP_RESPONSE_OK) { + const char *switch_name = elm_entry_entry_get(ad->entry); + if (strlen(switch_name) == 0) { + SETTING_TRACE_END; + return; + } - return entry; + setting_accessibility_universal_switch_action_page_create(ad); + elm_naviframe_item_pop_cb_set(elm_naviframe_top_item_get(ad->md.getNaviframe()), renewCaptureSwitchCb, ad); + setting_accessibility_universal_switch_action_callback_attach(ad, accessorySwitchActionCb, (void *)strdup(switch_name)); + } else { + renewCaptureSwitchCb(ad, NULL); + } + + evas_object_del(ad->popup); + ad->popup = NULL; + ad->entry = NULL; } -void setting_accessibility_universal_switch_add_switch_accessories_page_create(SettingAccessibility *ad) +void AccessoriesSwitchesPage::accessorySwitchActionCb(SettingAccessibility *ad, const std::string& action, void *user_data) { + retm_if(user_data == NULL, "User data parameter is NULL"); - retm_if(ad == NULL, "Input parameter is NULL"); - Evas_Object *layout = __create_layout(ad->md.getNaviframe(), EDJ_ACCESSORY, GRP_ACCESSORY); - - ad->us_configuration.switch_id = {}; - elm_layout_text_set(layout, PRT_ACCESSORY_LABEL, _(DEVOPTION_STR_ACCESSIBILITY_UNIVERSAL_SWITCH_ADD_SWITCH_ACCESSORIES_DESC)); - - Elm_Object_Item *navi_it = elm_naviframe_item_push(ad->md.getNaviframe(), _(DEVOPTION_STR_ACCESSIBILITY_UNIVERSAL_SWITCH_ADD_SWITCH_ACCESSORIES_TITLE), NULL, NULL, layout, NULL); - elm_naviframe_item_pop_cb_set(navi_it, __naviframe_pop_cb, ad); - elm_object_item_domain_text_translatable_set(navi_it, PACKAGE, EINA_TRUE); + if (ad->us_configuration.accessories_switch_added_cb) { + char *switch_name = (char *)user_data; + ad->us_configuration.accessories_switch_added_cb(ad, ad->us_configuration.switch_id.c_str(), action, switch_name); + free(switch_name); + } +} - Evas_Object *back_btn = setting_create_button(ad->md.getNaviframe(), NULL, NAVI_BACK_ARROW_BUTTON_STYLE, __back_cb, ad); - elm_layout_content_set(ad->md.getNaviframe(), "prev_btn", back_btn); +Eina_Bool AccessoriesSwitchesPage::renewCaptureSwitchCb(void *data, Elm_Object_Item *it) +{ + retv_if(data == NULL, EINA_TRUE); + SettingAccessibility *ad = (SettingAccessibility *)data; - setting_accessibility_universal_switch_dbus_config_captureSwitch(&ad->config, ACCESSIBILITY_UNIVERSAL_SWITCH_ACCESSORIES_SWITCH_PROVIDER, -1, __capture_switch_cb, ad); + setting_accessibility_universal_switch_dbus_config_captureSwitch(&ad->config, ACCESSIBILITY_UNIVERSAL_SWITCH_ACCESSORIES_SWITCH_PROVIDER, -1, captureSwitchCb, ad); + return EINA_TRUE; } -void setting_accessibility_universal_switch_add_switch_accessories_new_switch_callback_attach(SettingAccessibility *ad, UniversalSwitchUpdateCb cb) +Eina_Bool AccessoriesSwitchesPage::naviframPopCb(void *data, Elm_Object_Item *it) { + retv_if(data == NULL, EINA_TRUE); + SettingAccessibility *ad = (SettingAccessibility *)data; - retm_if(ad == NULL, "Input parameter is NULL"); - - ad->us_configuration.accessories_switch_added_cb = cb; + setting_accessibility_universal_switch_dbus_config_cancelCaptureSwitch(&ad->config); + ad->us_configuration.switch_id = {}; + return EINA_TRUE; +} +void AccessoriesSwitchesPage::backCb(void *data, Evas_Object *obj, void *event_info) +{ + retm_if(data == NULL, "Data argument is NULL"); + SettingAccessibility *ad = (SettingAccessibility *)data; + elm_naviframe_item_pop(ad->md.getNaviframe()); } diff --git a/src/AccessoriesSwitchesPage.hpp b/src/AccessoriesSwitchesPage.hpp new file mode 100644 index 0000000..06e06f8 --- /dev/null +++ b/src/AccessoriesSwitchesPage.hpp @@ -0,0 +1,27 @@ +#ifndef ACCESSORIES_SWITCHES_PAGE_HPP +#define ACCESSORIES_SWITCHES_PAGE_HPP + +#include "SettingAccessibility.hpp" + +#include + +class AccessoriesSwitchesPage +{ +public: + AccessoriesSwitchesPage(SettingAccessibility *ad); + static void attachActionCallback(SettingAccessibility *ad, UniversalSwitchUpdateCb cb); + +private: + static Evas_Object* createEntry(Evas_Object *parent, const char *part_name); + static Evas_Object *createLayout(Evas_Object *parent, const char *edj_file, const char *group); + static void captureSwitchCb(void *user_data, const char *switch_id); + static void alreadyMappedSwitchPopup(SettingAccessibility *ad); + static void okResponseCb(void *data, Evas_Object *obj, void *event_info); + static void popupResponseCb(void *data, Evas_Object *obj, void *event_info); + static void accessorySwitchActionCb(SettingAccessibility *ad, const std::string& action, void *user_data); + static Eina_Bool renewCaptureSwitchCb(void *data, Elm_Object_Item *it); + static Eina_Bool naviframPopCb(void *data, Elm_Object_Item *it); + static void backCb(void *data, Evas_Object *obj, void *event_info); +}; + +#endif diff --git a/src/CameraSwitchesPage.cpp b/src/CameraSwitchesPage.cpp index 35dea4b..2eb5d3c 100644 --- a/src/CameraSwitchesPage.cpp +++ b/src/CameraSwitchesPage.cpp @@ -44,7 +44,7 @@ CameraSwitchesPage::CameraSwitchesPage(SettingAccessibility *ad) elm_layout_content_set(ad->md.getNaviframe(), "prev_btn", back_btn); } -void CameraSwitchesPage::newSwitchCb(SettingAccessibility *ad, UniversalSwitchUpdateCb cb) +void CameraSwitchesPage::attachActionCallback(SettingAccessibility *ad, UniversalSwitchUpdateCb cb) { retm_if(ad == NULL, "Input parameter is NULL"); diff --git a/src/CameraSwitchesPage.hpp b/src/CameraSwitchesPage.hpp index b5cce4a..282413b 100644 --- a/src/CameraSwitchesPage.hpp +++ b/src/CameraSwitchesPage.hpp @@ -7,7 +7,7 @@ class CameraSwitchesPage { public: CameraSwitchesPage(SettingAccessibility *ad); - static void newSwitchCb(SettingAccessibility *ad, UniversalSwitchUpdateCb cb); + static void attachActionCallback(SettingAccessibility *ad, UniversalSwitchUpdateCb cb); private: static void addSwitchCb(void *data, Evas_Object *obj, void *event_info); diff --git a/src/SettingAccessibility.hpp b/src/SettingAccessibility.hpp index 87216cb..f1db942 100644 --- a/src/SettingAccessibility.hpp +++ b/src/SettingAccessibility.hpp @@ -9,6 +9,7 @@ #include "setting-accessibility-universal-switch-dbus.h" #include "ScreenReaderPage.hpp" #include "CameraSwitchesPage.hpp" +#include "AccessoriesSwitchesPage.hpp" #include @@ -17,6 +18,7 @@ class ScreenReaderSettingsPage; class ScreenReaderPage; class CameraSwitchesPage; +class AccessoriesSwitchesPage; typedef void (*back_cb)(SettingAccessibility *ad); @@ -89,6 +91,7 @@ struct SettingAccessibility { std::unique_ptr screenReaderSettingsPage_; std::unique_ptr screenReaderPage_; std::unique_ptr cameraSwitchesPage_; + std::unique_ptr accessoriesSwitchesPage_; }; #endif diff --git a/src/setting-accessibility-universal-switch-add-switch-accessories.h b/src/setting-accessibility-universal-switch-add-switch-accessories.h deleted file mode 100644 index 686f55f..0000000 --- a/src/setting-accessibility-universal-switch-add-switch-accessories.h +++ /dev/null @@ -1,10 +0,0 @@ -#ifndef SETTINGACCESSIBILITYUNIVERSALSWITCHADDSWITCHACCESSORIES_H -#define SETTINGACCESSIBILITYUNIVERSALSWITCHADDSWITCHACCESSORIES_H - -#include "setting-accessibility.h" - -void setting_accessibility_universal_switch_add_switch_accessories_page_create(SettingAccessibility *ad); -void setting_accessibility_universal_switch_add_switch_accessories_new_switch_callback_attach(SettingAccessibility *ad, UniversalSwitchUpdateCb cb); - -#endif /* SETTINGACCESSIBILITYUNIVERSALSWITCHADDSWITCHACCESSORIES_H */ - diff --git a/src/setting-accessibility-universal-switch-add-switch.cpp b/src/setting-accessibility-universal-switch-add-switch.cpp index 85e6ca7..083d7d5 100755 --- a/src/setting-accessibility-universal-switch-add-switch.cpp +++ b/src/setting-accessibility-universal-switch-add-switch.cpp @@ -21,7 +21,6 @@ #include "setting-accessibility-universal-switch-add-switch.h" #include "setting-accessibility-universal-switch-add-switch-screen.h" -#include "setting-accessibility-universal-switch-add-switch-accessories.h" #include @@ -59,7 +58,7 @@ static void __add_switch_page_create(SettingAccessibility *ad, const char * prov else if (strncmp(providerId, ACCESSIBILITY_UNIVERSAL_SWITCH_CAMERA_SWITCH_PROVIDER, sizeof(ACCESSIBILITY_UNIVERSAL_SWITCH_SCREEN_SWITCH_PROVIDER)) == 0) ad->cameraSwitchesPage_ = std::make_unique(ad); else if (strncmp(providerId, ACCESSIBILITY_UNIVERSAL_SWITCH_ACCESSORIES_SWITCH_PROVIDER, sizeof(ACCESSIBILITY_UNIVERSAL_SWITCH_ACCESSORIES_SWITCH_PROVIDER)) == 0) - setting_accessibility_universal_switch_add_switch_accessories_page_create(ad); + ad->accessoriesSwitchesPage_ = std::make_unique(ad); else SETTING_TRACE_ERROR("Unknown provider: %s", providerId); } @@ -144,8 +143,8 @@ void setting_accessibility_universal_switch_add_switch_new_switch_callback_attac setting_accessibility_universal_switch_add_switch_screen_new_switch_callback_attach(ad, cb); - setting_accessibility_universal_switch_add_switch_accessories_new_switch_callback_attach(ad, cb); - CameraSwitchesPage::newSwitchCb(ad, cb); + AccessoriesSwitchesPage::attachActionCallback(ad, cb); + CameraSwitchesPage::attachActionCallback(ad, cb); } -- 2.7.4 From 41cf035f68acefa1fea7c6a00b7df0940ab8650f Mon Sep 17 00:00:00 2001 From: Lukasz Wlazly Date: Fri, 5 Oct 2018 14:03:26 +0200 Subject: [PATCH 13/16] [Cpp refactor] Add ScreenSwitchPage class Change-Id: Ic137ca02db9aa0674087e9507b9ee7407d97f9f1 --- src/ScreenSwitchPage.cpp | 29 +++++++++++ src/ScreenSwitchPage.hpp | 16 ++++++ src/SettingAccessibility.hpp | 3 ++ ...sibility-universal-switch-add-switch-screen.cpp | 58 ---------------------- ...essibility-universal-switch-add-switch-screen.h | 10 ---- ...g-accessibility-universal-switch-add-switch.cpp | 9 +--- 6 files changed, 50 insertions(+), 75 deletions(-) create mode 100644 src/ScreenSwitchPage.cpp create mode 100644 src/ScreenSwitchPage.hpp delete mode 100644 src/setting-accessibility-universal-switch-add-switch-screen.cpp delete mode 100644 src/setting-accessibility-universal-switch-add-switch-screen.h diff --git a/src/ScreenSwitchPage.cpp b/src/ScreenSwitchPage.cpp new file mode 100644 index 0000000..5724240 --- /dev/null +++ b/src/ScreenSwitchPage.cpp @@ -0,0 +1,29 @@ +#include "ScreenSwitchPage.hpp" + +#include "setting-accessibility.h" +#include "setting-accessibility-universal-switch-action.h" + +ScreenSwitchPage::ScreenSwitchPage(SettingAccessibility *ad) +{ + retm_if(ad == NULL, "Input parameter is NULL"); + + setting_accessibility_universal_switch_action_page_create(ad); + setting_accessibility_universal_switch_action_callback_attach(ad, actionCb, NULL); +} + +void ScreenSwitchPage::attachActionCallback(SettingAccessibility *ad, UniversalSwitchUpdateCb cb) +{ + retm_if(ad == NULL, "Input parameter is NULL"); + + ad->us_configuration.screen_switch_added_cb = cb; +} + +void ScreenSwitchPage::actionCb(SettingAccessibility *ad, const std::string& action, void *user_data) +{ + if (ad->us_configuration.screen_switch_added_cb) { + auto switches = setting_accessibility_universal_switch_dbus_config_get_switches(&ad->config, ACCESSIBILITY_UNIVERSAL_SWITCH_SCREEN_SWITCH_PROVIDER); + retm_if(switches.size() < 1, "Screen switch not found"); + auto screen_switch = switches[0]; + ad->us_configuration.screen_switch_added_cb(ad, screen_switch->id, action, ACCESSIBILITY_UNIVERSAL_SWITCH_SCREEN); + } +} diff --git a/src/ScreenSwitchPage.hpp b/src/ScreenSwitchPage.hpp new file mode 100644 index 0000000..9f7e105 --- /dev/null +++ b/src/ScreenSwitchPage.hpp @@ -0,0 +1,16 @@ +#ifndef SCREEN_SWITCH_PAGE_HPP +#define SCREEN_SWITCH_PAGE_HPP + +#include "SettingAccessibility.hpp" + +class ScreenSwitchPage +{ +public: + ScreenSwitchPage(SettingAccessibility *ad); + static void attachActionCallback(SettingAccessibility *ad, UniversalSwitchUpdateCb cb); + +private: + static void actionCb(SettingAccessibility *ad, const std::string& action, void *user_data); +}; + +#endif diff --git a/src/SettingAccessibility.hpp b/src/SettingAccessibility.hpp index f1db942..4d364fe 100644 --- a/src/SettingAccessibility.hpp +++ b/src/SettingAccessibility.hpp @@ -10,6 +10,7 @@ #include "ScreenReaderPage.hpp" #include "CameraSwitchesPage.hpp" #include "AccessoriesSwitchesPage.hpp" +#include "ScreenSwitchPage.hpp" #include @@ -19,6 +20,7 @@ class ScreenReaderSettingsPage; class ScreenReaderPage; class CameraSwitchesPage; class AccessoriesSwitchesPage; +class ScreenSwitchPage; typedef void (*back_cb)(SettingAccessibility *ad); @@ -92,6 +94,7 @@ struct SettingAccessibility { std::unique_ptr screenReaderPage_; std::unique_ptr cameraSwitchesPage_; std::unique_ptr accessoriesSwitchesPage_; + std::unique_ptr screenSwitchPage_; }; #endif diff --git a/src/setting-accessibility-universal-switch-add-switch-screen.cpp b/src/setting-accessibility-universal-switch-add-switch-screen.cpp deleted file mode 100644 index acaad44..0000000 --- a/src/setting-accessibility-universal-switch-add-switch-screen.cpp +++ /dev/null @@ -1,58 +0,0 @@ -/* - * accessibility - * - * Copyright (c) 2017 Samsung Electronics Co., Ltd. - * - * Contact: Michal Pawluk - * - * 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. - * - */ - -#include "setting-accessibility-universal-switch-add-switch-screen.h" -#include "setting-accessibility-universal-switch-action.h" - -static void __screen_switch_action_cb(SettingAccessibility *ad, const std::string& action, void *user_data) -{ - - - if (ad->us_configuration.screen_switch_added_cb) { - auto switches = setting_accessibility_universal_switch_dbus_config_get_switches(&ad->config, ACCESSIBILITY_UNIVERSAL_SWITCH_SCREEN_SWITCH_PROVIDER); - retm_if(switches.size() < 1, "Screen switch not found"); - auto screen_switch = switches[0]; - ad->us_configuration.screen_switch_added_cb(ad, screen_switch->id, action, ACCESSIBILITY_UNIVERSAL_SWITCH_SCREEN); - } - - -} - -void setting_accessibility_universal_switch_add_switch_screen_page_create(SettingAccessibility *ad) -{ - - retm_if(ad == NULL, "Input parameter is NULL"); - - setting_accessibility_universal_switch_action_page_create(ad); - setting_accessibility_universal_switch_action_callback_attach(ad, __screen_switch_action_cb, NULL); - - -} - -void setting_accessibility_universal_switch_add_switch_screen_new_switch_callback_attach(SettingAccessibility *ad, UniversalSwitchUpdateCb cb) -{ - - retm_if(ad == NULL, "Input parameter is NULL"); - - ad->us_configuration.screen_switch_added_cb = cb; - - -} diff --git a/src/setting-accessibility-universal-switch-add-switch-screen.h b/src/setting-accessibility-universal-switch-add-switch-screen.h deleted file mode 100644 index 4efbc2f..0000000 --- a/src/setting-accessibility-universal-switch-add-switch-screen.h +++ /dev/null @@ -1,10 +0,0 @@ -#ifndef SETTINGACCESSIBILITYUNIVERSALSWITCHADDSWITCHSCREEN_H -#define SETTINGACCESSIBILITYUNIVERSALSWITCHADDSWITCHSCREEN_H - -#include "setting-accessibility.h" - -void setting_accessibility_universal_switch_add_switch_screen_page_create(SettingAccessibility *ad); -void setting_accessibility_universal_switch_add_switch_screen_new_switch_callback_attach(SettingAccessibility *ad, UniversalSwitchUpdateCb cb); - -#endif /* SETTINGACCESSIBILITYUNIVERSALSWITCHADDSWITCHSCREEN_H */ - diff --git a/src/setting-accessibility-universal-switch-add-switch.cpp b/src/setting-accessibility-universal-switch-add-switch.cpp index 083d7d5..f7b68ee 100755 --- a/src/setting-accessibility-universal-switch-add-switch.cpp +++ b/src/setting-accessibility-universal-switch-add-switch.cpp @@ -20,7 +20,6 @@ */ #include "setting-accessibility-universal-switch-add-switch.h" -#include "setting-accessibility-universal-switch-add-switch-screen.h" #include @@ -54,7 +53,7 @@ static void __add_switch_page_create(SettingAccessibility *ad, const char * prov SETTING_TRACE_DEBUG("Create add switch page for %s", providerId); if (strncmp(providerId, ACCESSIBILITY_UNIVERSAL_SWITCH_SCREEN_SWITCH_PROVIDER, sizeof(ACCESSIBILITY_UNIVERSAL_SWITCH_SCREEN_SWITCH_PROVIDER)) == 0) - setting_accessibility_universal_switch_add_switch_screen_page_create(ad); + ad->screenSwitchPage_ = std::make_unique(ad); else if (strncmp(providerId, ACCESSIBILITY_UNIVERSAL_SWITCH_CAMERA_SWITCH_PROVIDER, sizeof(ACCESSIBILITY_UNIVERSAL_SWITCH_SCREEN_SWITCH_PROVIDER)) == 0) ad->cameraSwitchesPage_ = std::make_unique(ad); else if (strncmp(providerId, ACCESSIBILITY_UNIVERSAL_SWITCH_ACCESSORIES_SWITCH_PROVIDER, sizeof(ACCESSIBILITY_UNIVERSAL_SWITCH_ACCESSORIES_SWITCH_PROVIDER)) == 0) @@ -140,11 +139,7 @@ void setting_accessibility_universal_switch_add_switch_page_create(SettingAccess void setting_accessibility_universal_switch_add_switch_new_switch_callback_attach(SettingAccessibility *ad, UniversalSwitchUpdateCb cb) { - - - setting_accessibility_universal_switch_add_switch_screen_new_switch_callback_attach(ad, cb); + ScreenSwitchPage::attachActionCallback(ad, cb); AccessoriesSwitchesPage::attachActionCallback(ad, cb); CameraSwitchesPage::attachActionCallback(ad, cb); - - } -- 2.7.4 From 2379bd03673c028d6fd2a0cac13a822099e9922f Mon Sep 17 00:00:00 2001 From: Lukasz Wlazly Date: Mon, 8 Oct 2018 09:00:38 +0200 Subject: [PATCH 14/16] [Cpp refactor] Add AddSwitchPage class Change-Id: I720f8fdff660fd7c9bc506f9e2c50c707d52b370 --- ...sal-switch-add-switch.cpp => AddSwitchPage.cpp} | 171 +++++++++------------ src/AddSwitchPage.hpp | 24 +++ src/CameraSwitchesPage.cpp | 3 +- src/SettingAccessibility.hpp | 3 + ...ing-accessibility-universal-switch-add-switch.h | 10 -- ...ccessibility-universal-switch-remove-switch.cpp | 1 - ...ing-accessibility-universal-switch-settings.cpp | 1 - ...ing-accessibility-universal-switch-switches.cpp | 5 +- src/setting-accessibility-universal-switch.cpp | 5 +- 9 files changed, 101 insertions(+), 122 deletions(-) rename src/{setting-accessibility-universal-switch-add-switch.cpp => AddSwitchPage.cpp} (60%) mode change 100755 => 100644 create mode 100644 src/AddSwitchPage.hpp delete mode 100644 src/setting-accessibility-universal-switch-add-switch.h diff --git a/src/setting-accessibility-universal-switch-add-switch.cpp b/src/AddSwitchPage.cpp old mode 100755 new mode 100644 similarity index 60% rename from src/setting-accessibility-universal-switch-add-switch.cpp rename to src/AddSwitchPage.cpp index f7b68ee..569f0d8 --- a/src/setting-accessibility-universal-switch-add-switch.cpp +++ b/src/AddSwitchPage.cpp @@ -1,70 +1,71 @@ -/* - * accessibility - * - * Copyright (c) 2017 Samsung Electronics Co., Ltd. - * - * Contact: Michal Pawluk - * - * 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. - * - */ - -#include "setting-accessibility-universal-switch-add-switch.h" +#include "AddSwitchPage.hpp" + +#include "setting-accessibility.h" #include -static Eina_Bool __naviframe_pop_cb(void *data, Elm_Object_Item *it) +AddSwitchPage::AddSwitchPage(SettingAccessibility *ad) { + retm_if(ad == NULL, "Input parameter is NULL"); + Evas_Object *genlist = elm_genlist_add(ad->md.getNaviframe()); + retm_if(genlist == NULL, "Cannot set genlist object as content of layout"); - retv_if(data == NULL, EINA_TRUE); - SettingAccessibility *ad = (SettingAccessibility *)data; + elm_genlist_mode_set(genlist, ELM_LIST_COMPRESS); + elm_object_style_set(genlist, "dialogue"); + elm_genlist_clear(genlist); - ad->us_configuration.screen_switch_added_cb = NULL; - ad->us_configuration.camera_switch_added_cb = NULL; - ad->us_configuration.accessories_switch_added_cb = NULL; + for (auto &it : ad->config.switch_providers) { + auto item = setting_create_Gendial_field_def( + genlist, &ad->itc_multiline_sub, + onSwitchAddition, &it->info->id, + SwallowType::INVALID, NULL, NULL, 0, + it->info->name.c_str(), + it->info->description.c_str(), NULL); + if (item) { + item->userdata = ad; + disableScreenSwitchProviderIfSwitchMapped(ad->config.configuration_items, it, item->item); + } + } - return EINA_TRUE; + Elm_Object_Item *navi_it = elm_naviframe_item_push(ad->md.getNaviframe(), _(DEVOPTION_STR_ACCESSIBILITY_UNIVERSAL_SWITCH_ADD_SWITCH), NULL, NULL, genlist, NULL); + elm_naviframe_item_pop_cb_set(navi_it, onNaviframePopCb, ad); + elm_object_item_domain_text_translatable_set(navi_it, PACKAGE, EINA_TRUE); + + Evas_Object *back_btn = setting_create_button(ad->md.getNaviframe(), NULL, NAVI_BACK_ARROW_BUTTON_STYLE, backCb, ad); + elm_layout_content_set(ad->md.getNaviframe(), "prev_btn", back_btn); } -static void __back_cb(void *data, Evas_Object *obj, void *event_info) +void AddSwitchPage::attachCallbackOnSwitchAttach(SettingAccessibility *ad, UniversalSwitchUpdateCb cb) { + ScreenSwitchPage::attachActionCallback(ad, cb); + AccessoriesSwitchesPage::attachActionCallback(ad, cb); + CameraSwitchesPage::attachActionCallback(ad, cb); +} - retm_if(data == NULL, "Data argument is NULL"); - SettingAccessibility *ad = (SettingAccessibility *)data; - - elm_naviframe_item_pop(ad->md.getNaviframe()); +void AddSwitchPage::disableScreenSwitchProviderIfSwitchMapped(const std::vector& configuration_items, UniversalSwitchSwitchProvider *switch_provider, Elm_Object_Item *item) +{ + retm_if(switch_provider == NULL, "Input parameter is NULL"); + retm_if(item == NULL, "Input parameter is NULL"); + SETTING_TRACE_DEBUG("provider_id %s", switch_provider->info->id); + if (switch_provider->info->id == ACCESSIBILITY_UNIVERSAL_SWITCH_SCREEN_SWITCH_PROVIDER) + disableAlreadyMappedSwitch(configuration_items, ACCESSIBILITY_UNIVERSAL_SWITCH_SCREEN_SWITCH_ID, item); } -static void __add_switch_page_create(SettingAccessibility *ad, const char * providerId) +void AddSwitchPage::disableAlreadyMappedSwitch(const std::vector &configuration_items, const std::string& switch_id, Elm_Object_Item *item) { - SETTING_TRACE_DEBUG("Create add switch page for %s", providerId); + retm_if(item == NULL, "Input parameter is NULL"); - if (strncmp(providerId, ACCESSIBILITY_UNIVERSAL_SWITCH_SCREEN_SWITCH_PROVIDER, sizeof(ACCESSIBILITY_UNIVERSAL_SWITCH_SCREEN_SWITCH_PROVIDER)) == 0) - ad->screenSwitchPage_ = std::make_unique(ad); - else if (strncmp(providerId, ACCESSIBILITY_UNIVERSAL_SWITCH_CAMERA_SWITCH_PROVIDER, sizeof(ACCESSIBILITY_UNIVERSAL_SWITCH_SCREEN_SWITCH_PROVIDER)) == 0) - ad->cameraSwitchesPage_ = std::make_unique(ad); - else if (strncmp(providerId, ACCESSIBILITY_UNIVERSAL_SWITCH_ACCESSORIES_SWITCH_PROVIDER, sizeof(ACCESSIBILITY_UNIVERSAL_SWITCH_ACCESSORIES_SWITCH_PROVIDER)) == 0) - ad->accessoriesSwitchesPage_ = std::make_unique(ad); - else - SETTING_TRACE_ERROR("Unknown provider: %s", providerId); + for (auto &it : configuration_items) { + if (switch_id == it->switch_id) + elm_object_item_disabled_set(item, EINA_TRUE); + } } -static void __add_switch_cb(void *data, Evas_Object *obj, void *event_info) +void AddSwitchPage::onSwitchAddition(void *data, Evas_Object *obj, void *event_info) { - Elm_Object_Item *item = (Elm_Object_Item *)event_info; elm_genlist_item_selected_set(item, EINA_FALSE); GenGroupItemData *settings_item = (GenGroupItemData *)elm_object_item_data_get(item); @@ -72,74 +73,40 @@ static void __add_switch_cb(void *data, Evas_Object *obj, void *event_info) retm_if(ad == NULL, "Input argument is NULL"); auto providerId = *static_cast(data); - __add_switch_page_create(ad, providerId.c_str()); - - + showSwitchesPage(ad, providerId.c_str()); } -void setting_accessibility_universal_switch_disable_already_mapped_switch(const std::vector &configuration_items, const std::string& switch_id, Elm_Object_Item *item) +void AddSwitchPage::showSwitchesPage(SettingAccessibility *ad, const char * providerId) { + SETTING_TRACE_DEBUG("Create add switch page for %s", providerId); - retm_if(item == NULL, "Input parameter is NULL"); - - for (auto &it : configuration_items) { - if (switch_id == it->switch_id) - elm_object_item_disabled_set(item, EINA_TRUE); - } + if (strncmp(providerId, ACCESSIBILITY_UNIVERSAL_SWITCH_SCREEN_SWITCH_PROVIDER, sizeof(ACCESSIBILITY_UNIVERSAL_SWITCH_SCREEN_SWITCH_PROVIDER)) == 0) + ad->screenSwitchPage_ = std::make_unique(ad); + else if (strncmp(providerId, ACCESSIBILITY_UNIVERSAL_SWITCH_CAMERA_SWITCH_PROVIDER, sizeof(ACCESSIBILITY_UNIVERSAL_SWITCH_SCREEN_SWITCH_PROVIDER)) == 0) + ad->cameraSwitchesPage_ = std::make_unique(ad); + else if (strncmp(providerId, ACCESSIBILITY_UNIVERSAL_SWITCH_ACCESSORIES_SWITCH_PROVIDER, sizeof(ACCESSIBILITY_UNIVERSAL_SWITCH_ACCESSORIES_SWITCH_PROVIDER)) == 0) + ad->accessoriesSwitchesPage_ = std::make_unique(ad); + else + SETTING_TRACE_ERROR("Unknown provider: %s", providerId); } -static void __disable_screen_switch_provider_when_screen_switches_is_mapped(const std::vector& configuration_items, UniversalSwitchSwitchProvider *switch_provider, Elm_Object_Item *item) +void AddSwitchPage::backCb(void *data, Evas_Object *obj, void *event_info) { + retm_if(data == NULL, "Data argument is NULL"); + SettingAccessibility *ad = (SettingAccessibility *)data; - retm_if(switch_provider == NULL, "Input parameter is NULL"); - retm_if(item == NULL, "Input parameter is NULL"); - - SETTING_TRACE_DEBUG("provider_id %s", switch_provider->info->id); - - if (switch_provider->info->id == ACCESSIBILITY_UNIVERSAL_SWITCH_SCREEN_SWITCH_PROVIDER) - setting_accessibility_universal_switch_disable_already_mapped_switch(configuration_items, ACCESSIBILITY_UNIVERSAL_SWITCH_SCREEN_SWITCH_ID, item); - - + elm_naviframe_item_pop(ad->md.getNaviframe()); } -void setting_accessibility_universal_switch_add_switch_page_create(SettingAccessibility *ad) +Eina_Bool AddSwitchPage::onNaviframePopCb(void *data, Elm_Object_Item *it) { + retv_if(data == NULL, EINA_TRUE); + SettingAccessibility *ad = (SettingAccessibility *)data; - retm_if(ad == NULL, "Input parameter is NULL"); - Evas_Object *genlist = elm_genlist_add(ad->md.getNaviframe()); - retm_if(genlist == NULL, "Cannot set genlist object as content of layout"); - - elm_genlist_mode_set(genlist, ELM_LIST_COMPRESS); - elm_object_style_set(genlist, "dialogue"); - elm_genlist_clear(genlist); - - for (auto &it : ad->config.switch_providers) { - auto item = setting_create_Gendial_field_def( - genlist, &ad->itc_multiline_sub, - __add_switch_cb, &it->info->id, - SwallowType::INVALID, NULL, NULL, 0, - it->info->name.c_str(), - it->info->description.c_str(), NULL); - - if (item) { - item->userdata = ad; - __disable_screen_switch_provider_when_screen_switches_is_mapped(ad->config.configuration_items, it, item->item); - } - } - - Elm_Object_Item *navi_it = elm_naviframe_item_push(ad->md.getNaviframe(), _(DEVOPTION_STR_ACCESSIBILITY_UNIVERSAL_SWITCH_ADD_SWITCH), NULL, NULL, genlist, NULL); - elm_naviframe_item_pop_cb_set(navi_it, __naviframe_pop_cb, ad); - elm_object_item_domain_text_translatable_set(navi_it, PACKAGE, EINA_TRUE); - - Evas_Object *back_btn = setting_create_button(ad->md.getNaviframe(), NULL, NAVI_BACK_ARROW_BUTTON_STYLE, __back_cb, ad); - elm_layout_content_set(ad->md.getNaviframe(), "prev_btn", back_btn); - + ad->us_configuration.screen_switch_added_cb = NULL; + ad->us_configuration.camera_switch_added_cb = NULL; + ad->us_configuration.accessories_switch_added_cb = NULL; -} -void setting_accessibility_universal_switch_add_switch_new_switch_callback_attach(SettingAccessibility *ad, UniversalSwitchUpdateCb cb) -{ - ScreenSwitchPage::attachActionCallback(ad, cb); - AccessoriesSwitchesPage::attachActionCallback(ad, cb); - CameraSwitchesPage::attachActionCallback(ad, cb); + return EINA_TRUE; } diff --git a/src/AddSwitchPage.hpp b/src/AddSwitchPage.hpp new file mode 100644 index 0000000..f5fd60d --- /dev/null +++ b/src/AddSwitchPage.hpp @@ -0,0 +1,24 @@ +#ifndef ADD_SWITCH_PAGE_HPP +#define ADD_SWITCH_PAGE_HPP + +#include "SettingAccessibility.hpp" + +#include + +class AddSwitchPage +{ +public: + AddSwitchPage(SettingAccessibility *ad); + static void attachCallbackOnSwitchAttach(SettingAccessibility *ad, UniversalSwitchUpdateCb cb); //TODO: rename + static void disableAlreadyMappedSwitch(const std::vector &configuration_items, const std::string& switch_id, Elm_Object_Item *item); + + +private: + static void disableScreenSwitchProviderIfSwitchMapped(const std::vector& configuration_items, UniversalSwitchSwitchProvider *switch_provider, Elm_Object_Item *item); + static void onSwitchAddition(void *data, Evas_Object *obj, void *event_info); + static void showSwitchesPage(SettingAccessibility *ad, const char * providerId); + static void backCb(void *data, Evas_Object *obj, void *event_info); + static Eina_Bool onNaviframePopCb(void *data, Elm_Object_Item *it); +}; + +#endif diff --git a/src/CameraSwitchesPage.cpp b/src/CameraSwitchesPage.cpp index 2eb5d3c..0536ac0 100644 --- a/src/CameraSwitchesPage.cpp +++ b/src/CameraSwitchesPage.cpp @@ -1,7 +1,6 @@ #include "CameraSwitchesPage.hpp" #include "setting-accessibility-universal-switch-action.h" -#include "setting-accessibility-universal-switch-add-switch.h" #include @@ -33,7 +32,7 @@ CameraSwitchesPage::CameraSwitchesPage(SettingAccessibility *ad) if (item) { item->userdata = ad; - setting_accessibility_universal_switch_disable_already_mapped_switch(ad->config.configuration_items, it->id, item->item); + AddSwitchPage::disableAlreadyMappedSwitch(ad->config.configuration_items, it->id, item->item); } } diff --git a/src/SettingAccessibility.hpp b/src/SettingAccessibility.hpp index 4d364fe..1e0abe0 100644 --- a/src/SettingAccessibility.hpp +++ b/src/SettingAccessibility.hpp @@ -11,6 +11,7 @@ #include "CameraSwitchesPage.hpp" #include "AccessoriesSwitchesPage.hpp" #include "ScreenSwitchPage.hpp" +#include "AddSwitchPage.hpp" #include @@ -21,6 +22,7 @@ class ScreenReaderPage; class CameraSwitchesPage; class AccessoriesSwitchesPage; class ScreenSwitchPage; +class AddSwitchPage; typedef void (*back_cb)(SettingAccessibility *ad); @@ -95,6 +97,7 @@ struct SettingAccessibility { std::unique_ptr cameraSwitchesPage_; std::unique_ptr accessoriesSwitchesPage_; std::unique_ptr screenSwitchPage_; + std::unique_ptr addSwitchPage_; }; #endif diff --git a/src/setting-accessibility-universal-switch-add-switch.h b/src/setting-accessibility-universal-switch-add-switch.h deleted file mode 100644 index 1b50946..0000000 --- a/src/setting-accessibility-universal-switch-add-switch.h +++ /dev/null @@ -1,10 +0,0 @@ -#ifndef SETTINGACCESSIBILITYUNIVERSALSWITCHADDSWITCH_H -#define SETTINGACCESSIBILITYUNIVERSALSWITCHADDSWITCH_H - -#include "setting-accessibility.h" - -void setting_accessibility_universal_switch_add_switch_page_create(SettingAccessibility *ad); -void setting_accessibility_universal_switch_add_switch_new_switch_callback_attach(SettingAccessibility *ad, UniversalSwitchUpdateCb cb); -void setting_accessibility_universal_switch_disable_already_mapped_switch(const std::vector &configuration_items, const std::string& switch_id, Elm_Object_Item *item); - -#endif /* SETTINGACCESSIBILITYUNIVERSALSWITCHADDSWITCH_H */ diff --git a/src/setting-accessibility-universal-switch-remove-switch.cpp b/src/setting-accessibility-universal-switch-remove-switch.cpp index b220cb1..15047d1 100644 --- a/src/setting-accessibility-universal-switch-remove-switch.cpp +++ b/src/setting-accessibility-universal-switch-remove-switch.cpp @@ -23,7 +23,6 @@ #include #include "setting-accessibility-universal-switch-settings.h" -#include "setting-accessibility-universal-switch-add-switch.h" #include "setting-accessibility-universal-switch-action.h" #include "setting-accessibility-universal-switch-settings-set-value.h" #include "setting-accessibility-universal-switch-dbus.h" diff --git a/src/setting-accessibility-universal-switch-settings.cpp b/src/setting-accessibility-universal-switch-settings.cpp index 385272a..339fb83 100755 --- a/src/setting-accessibility-universal-switch-settings.cpp +++ b/src/setting-accessibility-universal-switch-settings.cpp @@ -22,7 +22,6 @@ #include #include -#include "setting-accessibility-universal-switch-add-switch.h" #include "setting-accessibility-universal-switch-settings-set-value.h" #include "setting-accessibility-universal-switch-settings.h" #include "setting-accessibility-universal-switch-switches.h" diff --git a/src/setting-accessibility-universal-switch-switches.cpp b/src/setting-accessibility-universal-switch-switches.cpp index 6e238bc..e46ec8c 100644 --- a/src/setting-accessibility-universal-switch-switches.cpp +++ b/src/setting-accessibility-universal-switch-switches.cpp @@ -24,7 +24,6 @@ #include "setting-accessibility.h" #include "setting-accessibility-universal-switch-settings.h" -#include "setting-accessibility-universal-switch-add-switch.h" #include "setting-accessibility-universal-switch-remove-switch.h" #include "setting-accessibility-universal-switch-update-switch.h" @@ -147,8 +146,8 @@ static void __add_switch_click_cb(void *data, Evas_Object *obj, void *event_info retm_if(data == NULL, "Data argument is NULL"); SettingAccessibility *ad = (SettingAccessibility *)data; - setting_accessibility_universal_switch_add_switch_new_switch_callback_attach(ad, setting_accessibility_universal_switch_add_switch_cb); - setting_accessibility_universal_switch_add_switch_page_create(ad); + AddSwitchPage::attachCallbackOnSwitchAttach(ad, setting_accessibility_universal_switch_add_switch_cb); + ad->addSwitchPage_ = std::make_unique(ad); } diff --git a/src/setting-accessibility-universal-switch.cpp b/src/setting-accessibility-universal-switch.cpp index 4ade40b..e73eea9 100644 --- a/src/setting-accessibility-universal-switch.cpp +++ b/src/setting-accessibility-universal-switch.cpp @@ -22,7 +22,6 @@ #include #include "setting-accessibility-universal-switch.h" #include "setting-accessibility-universal-switch-settings.h" -#include "setting-accessibility-universal-switch-add-switch.h" #include "setting-accessibility-universal-switch-action.h" #include "setting-accessibility-universal-switch-switches.h" @@ -242,8 +241,8 @@ static void __universal_switch_new_switch_add(SettingAccessibility *ad) retm_if(ad == NULL, "Input parameter is NULL"); - setting_accessibility_universal_switch_add_switch_new_switch_callback_attach(ad, __universal_switch_new_switch_added_cb); - setting_accessibility_universal_switch_add_switch_page_create(ad); + AddSwitchPage::attachCallbackOnSwitchAttach(ad, __universal_switch_new_switch_added_cb); + ad->addSwitchPage_ = std::make_unique(ad); } -- 2.7.4 From 85d59ba8fed27c614ac138772b68a68f69b6bad9 Mon Sep 17 00:00:00 2001 From: Lukasz Wlazly Date: Mon, 8 Oct 2018 10:27:55 +0200 Subject: [PATCH 15/16] [Cpp refactor] Add UpdateSwitchPage class Change-Id: I7494c6f8f7823d3f2dfa8a8596c5cd278fa15a87 --- src/SettingAccessibility.hpp | 3 ++ ...itch-update-switch.cpp => UpdateSwitchPage.cpp} | 55 +++++----------------- src/UpdateSwitchPage.hpp | 17 +++++++ ...ing-accessibility-universal-switch-switches.cpp | 5 +- ...-accessibility-universal-switch-update-switch.h | 10 ---- 5 files changed, 35 insertions(+), 55 deletions(-) rename src/{setting-accessibility-universal-switch-update-switch.cpp => UpdateSwitchPage.cpp} (53%) create mode 100644 src/UpdateSwitchPage.hpp delete mode 100644 src/setting-accessibility-universal-switch-update-switch.h diff --git a/src/SettingAccessibility.hpp b/src/SettingAccessibility.hpp index 1e0abe0..11f6989 100644 --- a/src/SettingAccessibility.hpp +++ b/src/SettingAccessibility.hpp @@ -12,6 +12,7 @@ #include "AccessoriesSwitchesPage.hpp" #include "ScreenSwitchPage.hpp" #include "AddSwitchPage.hpp" +#include "UpdateSwitchPage.hpp" #include @@ -23,6 +24,7 @@ class CameraSwitchesPage; class AccessoriesSwitchesPage; class ScreenSwitchPage; class AddSwitchPage; +class UpdateSwitchPage; typedef void (*back_cb)(SettingAccessibility *ad); @@ -98,6 +100,7 @@ struct SettingAccessibility { std::unique_ptr accessoriesSwitchesPage_; std::unique_ptr screenSwitchPage_; std::unique_ptr addSwitchPage_; + std::unique_ptr updateSwitchPage_; }; #endif diff --git a/src/setting-accessibility-universal-switch-update-switch.cpp b/src/UpdateSwitchPage.cpp similarity index 53% rename from src/setting-accessibility-universal-switch-update-switch.cpp rename to src/UpdateSwitchPage.cpp index 28d80ab..e6bd4ea 100644 --- a/src/setting-accessibility-universal-switch-update-switch.cpp +++ b/src/UpdateSwitchPage.cpp @@ -1,43 +1,11 @@ -/* - * accessibility - * - * Copyright (c) 2017 Samsung Electronics Co., Ltd. - * - * Contact: Pawel Kurowski - * - * 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. - * - */ +#include "UpdateSwitchPage.hpp" -#include "setting-accessibility-universal-switch-update-switch.h" -#include "setting-accessibility-universal-switch-action.h" +#include "setting-accessibility.h" #include "setting-accessibility-universal-switch-settings-set-value.h" +#include "setting-accessibility-universal-switch-action.h" -static void __update_switch_action_cb(SettingAccessibility *ad, const std::string& action, void *user_data) -{ - - - if (ad->us_configuration.switch_updated_cb) { - UniversalSwitchConfigurationItem *config_item = (UniversalSwitchConfigurationItem *)user_data; - ad->us_configuration.switch_updated_cb(ad, config_item->switch_id, action, config_item->user_name); - } - - -} - -void setting_accessibility_universal_switch_update_switch_page_create(SettingAccessibility *ad, UniversalSwitchConfigurationItem *config_item) +UpdateSwitchPage::UpdateSwitchPage(SettingAccessibility *ad, UniversalSwitchConfigurationItem *config_item) { - retm_if(ad == NULL, "Input parameter is NULL"); if (strlen(config_item->provider_id.c_str()) == strlen(ACCESSIBILITY_UNIVERSAL_SWITCH_ACCESSORIES_SWITCH_PROVIDER) @@ -49,18 +17,21 @@ void setting_accessibility_universal_switch_update_switch_page_create(SettingAcc setting_accessibility_universal_switch_settings_create_update_accesories_switch_page(ad); } else { setting_accessibility_universal_switch_action_page_create(ad); - setting_accessibility_universal_switch_action_callback_attach(ad, __update_switch_action_cb, config_item); + setting_accessibility_universal_switch_action_callback_attach(ad, onActionUpdate, config_item); } - - } -void setting_accessibility_universal_switch_update_switch_callback_attach(SettingAccessibility *ad, UniversalSwitchUpdateCb cb) +void UpdateSwitchPage::attachActionCallback(SettingAccessibility *ad, UniversalSwitchUpdateCb cb) { - retm_if(ad == NULL, "Input parameter is NULL"); ad->us_configuration.switch_updated_cb = cb; +} - +void UpdateSwitchPage::onActionUpdate(SettingAccessibility *ad, const std::string& action, void *user_data) +{ + if (ad->us_configuration.switch_updated_cb) { + UniversalSwitchConfigurationItem *config_item = (UniversalSwitchConfigurationItem *)user_data; + ad->us_configuration.switch_updated_cb(ad, config_item->switch_id, action, config_item->user_name); + } } diff --git a/src/UpdateSwitchPage.hpp b/src/UpdateSwitchPage.hpp new file mode 100644 index 0000000..df44bbb --- /dev/null +++ b/src/UpdateSwitchPage.hpp @@ -0,0 +1,17 @@ +#ifndef UPDATE_SWITCH_PAGE_HPP +#define UPDATE_SWITCH_PAGE_HPP + +#include "SettingAccessibility.hpp" + + +class UpdateSwitchPage +{ +public: + UpdateSwitchPage(SettingAccessibility *ad, UniversalSwitchConfigurationItem *config_item); + static void attachActionCallback(SettingAccessibility *ad, UniversalSwitchUpdateCb cb); + +private: + static void onActionUpdate(SettingAccessibility *ad, const std::string& action, void *user_data); +}; + +#endif diff --git a/src/setting-accessibility-universal-switch-switches.cpp b/src/setting-accessibility-universal-switch-switches.cpp index e46ec8c..8084d46 100644 --- a/src/setting-accessibility-universal-switch-switches.cpp +++ b/src/setting-accessibility-universal-switch-switches.cpp @@ -25,7 +25,6 @@ #include "setting-accessibility.h" #include "setting-accessibility-universal-switch-settings.h" #include "setting-accessibility-universal-switch-remove-switch.h" -#include "setting-accessibility-universal-switch-update-switch.h" #include @@ -131,8 +130,8 @@ static void __switch_click_cb(void *data, Evas_Object *obj, void *event_info) UniversalSwitchConfigurationItem *config_item = (UniversalSwitchConfigurationItem *)list_item->userdata; SettingAccessibility *ad = (SettingAccessibility *)data; - setting_accessibility_universal_switch_update_switch_callback_attach(ad, __switch_updated_cb); - setting_accessibility_universal_switch_update_switch_page_create(ad, config_item); + UpdateSwitchPage::attachActionCallback(ad, __switch_updated_cb); + ad->updateSwitchPage_ = std::make_unique(ad, config_item); } diff --git a/src/setting-accessibility-universal-switch-update-switch.h b/src/setting-accessibility-universal-switch-update-switch.h deleted file mode 100644 index 9f0bf07..0000000 --- a/src/setting-accessibility-universal-switch-update-switch.h +++ /dev/null @@ -1,10 +0,0 @@ -#ifndef SETTINGACCESSIBILITYUNIVERSALSWITCHUPDATESWITCH_H -#define SETTINGACCESSIBILITYUNIVERSALSWITCHUPDATESWITCH_H - -#include "setting-accessibility.h" - -void setting_accessibility_universal_switch_update_switch_page_create(SettingAccessibility *ad, UniversalSwitchConfigurationItem *config_item); -void setting_accessibility_universal_switch_update_switch_callback_attach(SettingAccessibility *ad, UniversalSwitchUpdateCb cb); - -#endif /* SETTINGACCESSIBILITYUNIVERSALSWITCHUPDATESWITCH_H */ - -- 2.7.4 From 96b5ceb3771c01240d5998341c256b8a0091c9b2 Mon Sep 17 00:00:00 2001 From: Lukasz Wlazly Date: Mon, 8 Oct 2018 11:56:01 +0200 Subject: [PATCH 16/16] [Cpp refactor] Add RemoveSwitchPage class Change-Id: I6905276e2c3c26ce4533609eb95b33edc70dcd27 --- ...itch-remove-switch.cpp => RemoveSwitchPage.cpp} | 212 +++++++++------------ src/RemoveSwitchPage.hpp | 26 +++ src/SettingAccessibility.hpp | 3 + ...-accessibility-universal-switch-remove-switch.h | 12 -- ...ibility-universal-switch-settings-set-value.cpp | 5 +- ...ing-accessibility-universal-switch-switches.cpp | 7 +- 6 files changed, 120 insertions(+), 145 deletions(-) rename src/{setting-accessibility-universal-switch-remove-switch.cpp => RemoveSwitchPage.cpp} (70%) create mode 100644 src/RemoveSwitchPage.hpp delete mode 100644 src/setting-accessibility-universal-switch-remove-switch.h diff --git a/src/setting-accessibility-universal-switch-remove-switch.cpp b/src/RemoveSwitchPage.cpp similarity index 70% rename from src/setting-accessibility-universal-switch-remove-switch.cpp rename to src/RemoveSwitchPage.cpp index 15047d1..9a73f4d 100644 --- a/src/setting-accessibility-universal-switch-remove-switch.cpp +++ b/src/RemoveSwitchPage.cpp @@ -1,90 +1,92 @@ -/* - * accessibility - * - * Copyright (c) 2017 Samsung Electronics Co., Ltd. - * - * Contact: Michal Pawluk - * - * 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. - * - */ - -#include -#include +#include "RemoveSwitchPage.hpp" -#include "setting-accessibility-universal-switch-settings.h" -#include "setting-accessibility-universal-switch-action.h" +#include "setting-accessibility.h" #include "setting-accessibility-universal-switch-settings-set-value.h" -#include "setting-accessibility-universal-switch-dbus.h" #include +#include #define SWITCH_COUNTER_MAX 99 #define SWITCH_COUNTER_TITLE_LENGTH 4 -static void __remove_switch(SettingAccessibility *ad, int item_id) +RemoveSwitchPage::RemoveSwitchPage(SettingAccessibility *ad) { - retm_if(ad == NULL, "Input parameter is NULL"); - retm_if(ad->us_configuration.switch_removed_cb == NULL, "Remove callback not set"); - - if (item_id < 0 || item_id >= ad->config.configuration_items.size()) { - SETTING_TRACE_END; - return; - } + ad->switches_to_remove_counter = 0; - auto config_item = ad->config.configuration_items[item_id]; - SETTING_TRACE_DEBUG("Removing switch, switch_id: %s", config_item->switch_id.c_str()); + setting_accessibility_universal_switch_settings_set_value_page_create(ad, VT_SWITCHES, _(DEVOPTION_STR_ACCESSIBILITY_SELECT_ITEMS)); - ad->us_configuration.switch_removed_cb(ad, config_item->switch_id, config_item->activity_type, config_item->user_name); + ad->all_checkbox = elm_check_add(ad->md.getNaviframe()); + evas_object_smart_callback_add(ad->all_checkbox, "changed", onAllButtonsClicked, ad); + elm_layout_content_set(ad->md.getNaviframe(), "prev_btn", ad->all_checkbox); + ad->remove_switches_popup_button = setting_create_button(ad->md.getNaviframe(), _(DEVOPTION_STR_ACCESSIBILITY_DELETE_CAPS), "naviframe/title_right", onDeleteButtonClicked, ad); + elm_layout_content_set(ad->md.getNaviframe(), "title_right_btn", ad->remove_switches_popup_button); + elm_object_disabled_set(ad->remove_switches_popup_button, EINA_TRUE); + for (auto i = 0u; i < ad->config.configuration_items.size(); ++i) { + auto activity_name = setting_accessibility_universal_switch_dbus_config_get_activity_name(&ad->config, ad->config.configuration_items[i]->activity_type); + setting_accessibility_universal_switch_settings_set_value_remove_switch_item_add(ad, ad->config.configuration_items[i]->user_name, activity_name, i, false); + } } -static void __remove_popup_cb(void *data, Evas_Object *obj, void *event_info) +void RemoveSwitchPage::attachCallback(SettingAccessibility *ad, UniversalSwitchUpdateCb cb) { - evas_object_del(obj); + retm_if(ad == NULL, "Input parameter is NULL"); + + ad->us_configuration.switch_removed_cb = cb; } -static void __cancel_button_clicked_remove_popup_cb(void *data, Evas_Object *obj, void *event_info) +void RemoveSwitchPage::onDeleteButtonClicked(void *data, Evas_Object *obj, void *event_info) { - Evas_Object *popup = (Evas_Object *)data; - evas_object_del(popup); + SettingAccessibility *ad = (SettingAccessibility *)data; + retm_if(ad == NULL, "Input parameter is NULL"); + retm_if(ad->set_value_layout.getGenlist() == NULL, "No genlist provided"); + + createPopupForSwitchesRemoving(ad); } -static void __remove_selected_switches_cb(void *data, Evas_Object *obj, void *event_info) +void RemoveSwitchPage::onAllButtonsClicked(void *data, Evas_Object *obj, void *event_info) { SettingAccessibility *ad = (SettingAccessibility *)data; - bool disable_universal_switch = (ad->switches_to_remove_counter == (int)elm_genlist_items_count(ad->set_value_layout.getGenlist())); + retm_if(ad == NULL, "Input parameter is NULL"); + retm_if(ad->set_value_layout.getGenlist() == NULL, "No genlist provided"); - Elm_Object_Item *item = elm_genlist_last_item_get(ad->set_value_layout.getGenlist()); + int genlist_size = elm_genlist_items_count(ad->set_value_layout.getGenlist()); + bool all_selected = (ad->switches_to_remove_counter == genlist_size); + + Elm_Object_Item *item = elm_genlist_first_item_get(ad->set_value_layout.getGenlist()); while (item != NULL) { GenGroupItemData *list_item = (GenGroupItemData *)elm_object_item_data_get(item); - item = elm_genlist_item_prev_get(item); - if (list_item->chk_status) - __remove_switch(ad, list_item->chk_id); + setting_update_gl_item_chk_status(list_item, !all_selected); + item = elm_genlist_item_next_get(item); } - evas_object_del(ad->popup); - ad->popup = NULL; - elm_naviframe_item_pop(ad->md.getNaviframe()); + ad->switches_to_remove_counter = all_selected ? 0 : genlist_size; + useNaviframeTitleAsCounter(ad); +} - if (disable_universal_switch && vconf_set_bool(VCONFKEY_SETAPPL_ACCESSIBILITY_UNIVERSAL_SWITCH_INTERACTION_SERVICE, 0)) - LOGE("Failed to set vconf key %s.", VCONFKEY_SETAPPL_ACCESSIBILITY_UNIVERSAL_SWITCH_INTERACTION_SERVICE); +void RemoveSwitchPage::useNaviframeTitleAsCounter(SettingAccessibility *ad) +{ + retm_if(ad == NULL, "Input parameter is NULL"); + + elm_check_state_set(ad->all_checkbox, ad->switches_to_remove_counter == (int)elm_genlist_items_count(ad->set_value_layout.getGenlist())); + + char array[SWITCH_COUNTER_TITLE_LENGTH]; + char *title = array; + if (ad->switches_to_remove_counter > SWITCH_COUNTER_MAX) { + snprintf(title, SWITCH_COUNTER_TITLE_LENGTH, "%d+", SWITCH_COUNTER_MAX); + } else if (ad->switches_to_remove_counter > 0) { + snprintf(title, SWITCH_COUNTER_TITLE_LENGTH, "%d", ad->switches_to_remove_counter); + } else { + title = _(DEVOPTION_STR_ACCESSIBILITY_SELECT_ITEMS); + } + elm_object_disabled_set(ad->remove_switches_popup_button, ad->switches_to_remove_counter ? EINA_FALSE : EINA_TRUE); + elm_layout_text_set(ad->md.getNaviframe(), "default", title); } -static void __confirm_removing_switches_create_popup(SettingAccessibility *ad) +void RemoveSwitchPage::createPopupForSwitchesRemoving(SettingAccessibility *ad) { ad->popup = elm_popup_add(ad->md.getNaviframe()); retm_if(!ad->popup, "Popup creation failure"); @@ -105,9 +107,9 @@ static void __confirm_removing_switches_create_popup(SettingAccessibility *ad) elm_object_text_set(ad->popup, s); } - eext_object_event_callback_add(ad->popup, EEXT_CALLBACK_BACK, __remove_popup_cb, NULL); - evas_object_smart_callback_add(ad->popup, "dismissed", __remove_popup_cb, NULL); - evas_object_smart_callback_add(ad->popup, "block,clicked", __remove_popup_cb, NULL); + eext_object_event_callback_add(ad->popup, EEXT_CALLBACK_BACK, onRemovePopup, NULL); + evas_object_smart_callback_add(ad->popup, "dismissed", onRemovePopup, NULL); + evas_object_smart_callback_add(ad->popup, "block,clicked", onRemovePopup, NULL); Evas_Object *btn = elm_button_add(ad->popup); @@ -119,7 +121,7 @@ static void __confirm_removing_switches_create_popup(SettingAccessibility *ad) elm_object_style_set(btn, "bottom"); elm_object_text_set(btn, _("IDS_ST_BUTTON_CANCEL")); elm_object_part_content_set(ad->popup, "button1", btn); - evas_object_smart_callback_add(btn, "clicked", __cancel_button_clicked_remove_popup_cb, ad->popup); + evas_object_smart_callback_add(btn, "clicked", onCancelPopupButtonClicked, ad->popup); btn = elm_button_add(ad->popup); @@ -131,96 +133,56 @@ static void __confirm_removing_switches_create_popup(SettingAccessibility *ad) elm_object_style_set(btn, "bottom"); elm_object_text_set(btn, _(DEVOPTION_STR_ACCESSIBILITY_DELETE)); elm_object_part_content_set(ad->popup, "button2", btn); - evas_object_smart_callback_add(btn, "clicked", __remove_selected_switches_cb, ad); + evas_object_smart_callback_add(btn, "clicked", onRemoveSelectedSwitches, ad); evas_object_show(ad->popup); } -void setting_accessibility_universal_switch_use_naviframe_title_as_counter(SettingAccessibility *ad) +void RemoveSwitchPage::onRemoveSelectedSwitches(void *data, Evas_Object *obj, void *event_info) { - - retm_if(ad == NULL, "Input parameter is NULL"); - - elm_check_state_set(ad->all_checkbox, ad->switches_to_remove_counter == (int)elm_genlist_items_count(ad->set_value_layout.getGenlist())); - - char array[SWITCH_COUNTER_TITLE_LENGTH]; - char *title = array; - if (ad->switches_to_remove_counter > SWITCH_COUNTER_MAX) { - snprintf(title, SWITCH_COUNTER_TITLE_LENGTH, "%d+", SWITCH_COUNTER_MAX); - } else if (ad->switches_to_remove_counter > 0) { - snprintf(title, SWITCH_COUNTER_TITLE_LENGTH, "%d", ad->switches_to_remove_counter); - } else { - title = _(DEVOPTION_STR_ACCESSIBILITY_SELECT_ITEMS); - } - elm_object_disabled_set(ad->remove_switches_popup_button, ad->switches_to_remove_counter ? EINA_FALSE : EINA_TRUE); - elm_layout_text_set(ad->md.getNaviframe(), "default", title); - -} - -static void __all_button_clicked_cb(void *data, Evas_Object *obj, void *event_info) -{ - SettingAccessibility *ad = (SettingAccessibility *)data; - retm_if(ad == NULL, "Input parameter is NULL"); - retm_if(ad->set_value_layout.getGenlist() == NULL, "No genlist provided"); - - int genlist_size = elm_genlist_items_count(ad->set_value_layout.getGenlist()); - bool all_selected = (ad->switches_to_remove_counter == genlist_size); + bool disable_universal_switch = (ad->switches_to_remove_counter == (int)elm_genlist_items_count(ad->set_value_layout.getGenlist())); - Elm_Object_Item *item = elm_genlist_first_item_get(ad->set_value_layout.getGenlist()); + Elm_Object_Item *item = elm_genlist_last_item_get(ad->set_value_layout.getGenlist()); while (item != NULL) { GenGroupItemData *list_item = (GenGroupItemData *)elm_object_item_data_get(item); - setting_update_gl_item_chk_status(list_item, !all_selected); - item = elm_genlist_item_next_get(item); + item = elm_genlist_item_prev_get(item); + if (list_item->chk_status) + removeSwitch(ad, list_item->chk_id); } - ad->switches_to_remove_counter = all_selected ? 0 : genlist_size; - setting_accessibility_universal_switch_use_naviframe_title_as_counter(ad); - + evas_object_del(ad->popup); + ad->popup = NULL; + elm_naviframe_item_pop(ad->md.getNaviframe()); + if (disable_universal_switch && vconf_set_bool(VCONFKEY_SETAPPL_ACCESSIBILITY_UNIVERSAL_SWITCH_INTERACTION_SERVICE, 0)) + LOGE("Failed to set vconf key %s.", VCONFKEY_SETAPPL_ACCESSIBILITY_UNIVERSAL_SWITCH_INTERACTION_SERVICE); } -static void __delete_button_clicked_cb(void *data, Evas_Object *obj, void *event_info) +void RemoveSwitchPage::onCancelPopupButtonClicked(void *data, Evas_Object *obj, void *event_info) { - - SettingAccessibility *ad = (SettingAccessibility *)data; - retm_if(ad == NULL, "Input parameter is NULL"); - retm_if(ad->set_value_layout.getGenlist() == NULL, "No genlist provided"); - - __confirm_removing_switches_create_popup(ad); - - + Evas_Object *popup = (Evas_Object *)data; + evas_object_del(popup); } -void setting_accessibility_universal_switch_remove_switch_page_create(SettingAccessibility *ad) +void RemoveSwitchPage::onRemovePopup(void *data, Evas_Object *obj, void *event_info) { - - retm_if(ad == NULL, "Input parameter is NULL"); - - ad->switches_to_remove_counter = 0; - - setting_accessibility_universal_switch_settings_set_value_page_create(ad, VT_SWITCHES, _(DEVOPTION_STR_ACCESSIBILITY_SELECT_ITEMS)); - - ad->all_checkbox = elm_check_add(ad->md.getNaviframe()); - evas_object_smart_callback_add(ad->all_checkbox, "changed", __all_button_clicked_cb, ad); - elm_layout_content_set(ad->md.getNaviframe(), "prev_btn", ad->all_checkbox); - - ad->remove_switches_popup_button = setting_create_button(ad->md.getNaviframe(), _(DEVOPTION_STR_ACCESSIBILITY_DELETE_CAPS), "naviframe/title_right", __delete_button_clicked_cb, ad); - elm_layout_content_set(ad->md.getNaviframe(), "title_right_btn", ad->remove_switches_popup_button); - elm_object_disabled_set(ad->remove_switches_popup_button, EINA_TRUE); - - for (auto i = 0u; i < ad->config.configuration_items.size(); ++i) { - auto activity_name = setting_accessibility_universal_switch_dbus_config_get_activity_name(&ad->config, ad->config.configuration_items[i]->activity_type); - setting_accessibility_universal_switch_settings_set_value_remove_switch_item_add(ad, ad->config.configuration_items[i]->user_name, activity_name, i, false); - } + evas_object_del(obj); } -void setting_accessibility_universal_switch_remove_switch_callback_attach(SettingAccessibility *ad, UniversalSwitchUpdateCb cb) +void RemoveSwitchPage::removeSwitch(SettingAccessibility *ad, int item_id) { - retm_if(ad == NULL, "Input parameter is NULL"); + retm_if(ad->us_configuration.switch_removed_cb == NULL, "Remove callback not set"); - ad->us_configuration.switch_removed_cb = cb; + if (item_id < 0 || item_id >= ad->config.configuration_items.size()) { + SETTING_TRACE_END; + return; + } + auto config_item = ad->config.configuration_items[item_id]; + SETTING_TRACE_DEBUG("Removing switch, switch_id: %s", config_item->switch_id.c_str()); + + ad->us_configuration.switch_removed_cb(ad, config_item->switch_id, config_item->activity_type, config_item->user_name); } diff --git a/src/RemoveSwitchPage.hpp b/src/RemoveSwitchPage.hpp new file mode 100644 index 0000000..ccf0202 --- /dev/null +++ b/src/RemoveSwitchPage.hpp @@ -0,0 +1,26 @@ +#ifndef REMOVE_SWITCH_PAGE_HPP +#define REMOVE_SWITCH_PAGE_HPP + +#include "SettingAccessibility.hpp" + +class RemoveSwitchPage +{ +public: + RemoveSwitchPage(SettingAccessibility *ad); + static void attachCallback(SettingAccessibility *ad, UniversalSwitchUpdateCb cb); + static void useNaviframeTitleAsCounter(SettingAccessibility *ad); + +private: + static void onDeleteButtonClicked(void *data, Evas_Object *obj, void *event_info); + static void onAllButtonsClicked(void *data, Evas_Object *obj, void *event_info); + static void createPopupForSwitchesRemoving(SettingAccessibility *ad); + static void onRemoveSelectedSwitches(void *data, Evas_Object *obj, void *event_info); + static void onCancelPopupButtonClicked(void *data, Evas_Object *obj, void *event_info); + static void onRemovePopup(void *data, Evas_Object *obj, void *event_info); + static void removeSwitch(SettingAccessibility *ad, int item_id); + + +}; + + +#endif diff --git a/src/SettingAccessibility.hpp b/src/SettingAccessibility.hpp index 11f6989..53173b8 100644 --- a/src/SettingAccessibility.hpp +++ b/src/SettingAccessibility.hpp @@ -13,6 +13,7 @@ #include "ScreenSwitchPage.hpp" #include "AddSwitchPage.hpp" #include "UpdateSwitchPage.hpp" +#include "RemoveSwitchPage.hpp" #include @@ -25,6 +26,7 @@ class AccessoriesSwitchesPage; class ScreenSwitchPage; class AddSwitchPage; class UpdateSwitchPage; +class RemoveSwitchPage; typedef void (*back_cb)(SettingAccessibility *ad); @@ -101,6 +103,7 @@ struct SettingAccessibility { std::unique_ptr screenSwitchPage_; std::unique_ptr addSwitchPage_; std::unique_ptr updateSwitchPage_; + std::unique_ptr removeSwitchPage_; }; #endif diff --git a/src/setting-accessibility-universal-switch-remove-switch.h b/src/setting-accessibility-universal-switch-remove-switch.h deleted file mode 100644 index 8128edc..0000000 --- a/src/setting-accessibility-universal-switch-remove-switch.h +++ /dev/null @@ -1,12 +0,0 @@ -#ifndef SETTINGACCESSIBILITYUNIVERSALSWITCHREMOVESWITCH_H -#define SETTINGACCESSIBILITYUNIVERSALSWITCHREMOVESWITCH_H - -#include "setting-accessibility.h" - -void setting_accessibility_universal_switch_remove_switch_page_create(SettingAccessibility *ad); -void setting_accessibility_universal_switch_use_naviframe_title_as_counter(SettingAccessibility *ad); -void setting_accessibility_universal_switch_remove_switch_callback_attach(SettingAccessibility *ad, UniversalSwitchUpdateCb cb); - - -#endif /* SETTINGACCESSIBILITYUNIVERSALSWITCHREMOVESWITCH_H */ - diff --git a/src/setting-accessibility-universal-switch-settings-set-value.cpp b/src/setting-accessibility-universal-switch-settings-set-value.cpp index 5742198..5f11c6e 100755 --- a/src/setting-accessibility-universal-switch-settings-set-value.cpp +++ b/src/setting-accessibility-universal-switch-settings-set-value.cpp @@ -23,7 +23,6 @@ #include #include "setting-accessibility-universal-switch-settings-set-value.h" -#include "setting-accessibility-universal-switch-remove-switch.h" #include "setting-accessibility-universal-switch-action.h" #include "setting-accessibility-universal-switch-settings.h" @@ -444,7 +443,7 @@ static void __gendial_remove_item_checkbox_cb(void *data, Evas_Object *obj, void else ad->switches_to_remove_counter--; - setting_accessibility_universal_switch_use_naviframe_title_as_counter(ad); + RemoveSwitchPage::useNaviframeTitleAsCounter(ad); } @@ -468,7 +467,7 @@ static void __gendial_remove_item_selected_cb(void *data, Evas_Object *obj, void else ad->switches_to_remove_counter--; - setting_accessibility_universal_switch_use_naviframe_title_as_counter(ad); + RemoveSwitchPage::useNaviframeTitleAsCounter(ad); } diff --git a/src/setting-accessibility-universal-switch-switches.cpp b/src/setting-accessibility-universal-switch-switches.cpp index 8084d46..55a398e 100644 --- a/src/setting-accessibility-universal-switch-switches.cpp +++ b/src/setting-accessibility-universal-switch-switches.cpp @@ -24,7 +24,6 @@ #include "setting-accessibility.h" #include "setting-accessibility-universal-switch-settings.h" -#include "setting-accessibility-universal-switch-remove-switch.h" #include @@ -158,10 +157,8 @@ static void __create_remove_page_cb(void *data, Evas_Object *obj, void *event_in retm_if(data == NULL, "Data argument is NULL"); SettingAccessibility *ad = (SettingAccessibility *)data; - setting_accessibility_universal_switch_remove_switch_page_create(ad); - setting_accessibility_universal_switch_remove_switch_callback_attach(ad, __switch_removed_cb); - - + ad->removeSwitchPage_ = std::make_unique(ad); + RemoveSwitchPage::attachCallback(ad, __switch_removed_cb); } static void __create_switches_group(SettingAccessibility *ad, Evas_Object *genlist) -- 2.7.4