From 482b50833f67257d04153c9b8e23113115da4f8a Mon Sep 17 00:00:00 2001 From: Lukasz Wlazly Date: Thu, 13 Dec 2018 12:23:44 +0100 Subject: [PATCH] Extract SwitchesPage data from context class Change-Id: I164eb74403be6a054df42612f27d94193af9f9c0 --- src/AccessoriesSwitchesPage.cpp | 5 +- src/AccessoriesSwitchesPage.hpp | 2 +- src/AddSwitchPage.cpp | 9 +-- src/AddSwitchPage.hpp | 2 +- src/CameraSwitchesPage.cpp | 5 +- src/CameraSwitchesPage.hpp | 2 +- src/RemoveSwitchPage.cpp | 5 +- src/RemoveSwitchPage.hpp | 2 +- src/ScreenSwitchPage.cpp | 5 +- src/ScreenSwitchPage.hpp | 2 +- src/SettingAccessibility.hpp | 7 -- src/SwitchesPage.cpp | 122 +++++++++++++++++------------------ src/SwitchesPage.hpp | 31 ++++++--- src/UniversalSwitchConfiguration.hpp | 7 +- src/UniversalSwitchPage.cpp | 7 +- src/UniversalSwitchPage.hpp | 2 +- src/UniversalSwitchSettingsPage.cpp | 2 +- src/UpdateSwitchPage.cpp | 5 +- src/UpdateSwitchPage.hpp | 2 +- 19 files changed, 119 insertions(+), 105 deletions(-) diff --git a/src/AccessoriesSwitchesPage.cpp b/src/AccessoriesSwitchesPage.cpp index 0039995..781facc 100644 --- a/src/AccessoriesSwitchesPage.cpp +++ b/src/AccessoriesSwitchesPage.cpp @@ -47,11 +47,12 @@ AccessoriesSwitchesPage::AccessoriesSwitchesPage(SettingAccessibility *ad) setting_accessibility_universal_switch_dbus_config_captureSwitch(&ad->config, ACCESSIBILITY_UNIVERSAL_SWITCH_ACCESSORIES_SWITCH_PROVIDER, -1, captureSwitchCb, ad); } -void AccessoriesSwitchesPage::attachActionCallback(SettingAccessibility *ad, UniversalSwitchUpdateCb cb) +void AccessoriesSwitchesPage::attachActionCallback(SettingAccessibility *ad, UniversalSwitchUpdateCb cb, void *cbData) { retm_if(ad == NULL, "Input parameter is NULL"); ad->us_configuration.accessories_switch_added_cb = cb; + ad->us_configuration.accessories_switch_added_cb_data = cbData; } Evas_Object *AccessoriesSwitchesPage::createEntry(Evas_Object *parent, const char *part_name) @@ -170,7 +171,7 @@ void AccessoriesSwitchesPage::accessorySwitchActionCb(SettingAccessibility *ad, 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); + ad->us_configuration.accessories_switch_added_cb(ad->us_configuration.accessories_switch_added_cb_data, ad->us_configuration.switch_id.c_str(), action, switch_name); free(switch_name); } } diff --git a/src/AccessoriesSwitchesPage.hpp b/src/AccessoriesSwitchesPage.hpp index 7c9a905..48876e3 100644 --- a/src/AccessoriesSwitchesPage.hpp +++ b/src/AccessoriesSwitchesPage.hpp @@ -34,7 +34,7 @@ class AccessoriesSwitchesPage { public: AccessoriesSwitchesPage(SettingAccessibility *ad); - static void attachActionCallback(SettingAccessibility *ad, UniversalSwitchUpdateCb cb); + static void attachActionCallback(SettingAccessibility *ad, UniversalSwitchUpdateCb cb, void *cbData); private: static Evas_Object *createEntry(Evas_Object *parent, const char *part_name); diff --git a/src/AddSwitchPage.cpp b/src/AddSwitchPage.cpp index ac543a5..838b6ec 100644 --- a/src/AddSwitchPage.cpp +++ b/src/AddSwitchPage.cpp @@ -54,11 +54,11 @@ AddSwitchPage::AddSwitchPage(SettingAccessibility *ad) elm_layout_content_set(ad->md.getNaviframe()->getObject(), "prev_btn", back_btn); } -void AddSwitchPage::attachCallbackOnSwitchAttach(SettingAccessibility *ad, UniversalSwitchUpdateCb cb) +void AddSwitchPage::attachCallbackOnSwitchAttach(SettingAccessibility *ad, UniversalSwitchUpdateCb cb, void *cbData) { - ScreenSwitchPage::attachActionCallback(ad, cb); - AccessoriesSwitchesPage::attachActionCallback(ad, cb); - CameraSwitchesPage::attachActionCallback(ad, cb); + ScreenSwitchPage::attachActionCallback(ad, cb, cbData); + AccessoriesSwitchesPage::attachActionCallback(ad, cb, cbData); + CameraSwitchesPage::attachActionCallback(ad, cb, cbData); } void AddSwitchPage::disableScreenSwitchProviderIfSwitchMapped(const std::vector &configuration_items, UniversalSwitchSwitchProvider *switch_provider, Elm_Object_Item *item) @@ -122,6 +122,7 @@ Eina_Bool AddSwitchPage::onNaviframePopCb(void *data, Elm_Object_Item *it) auto ad = static_cast(data); ad->us_configuration.screen_switch_added_cb = NULL; + ad->us_configuration.screen_switch_added_cb_data = nullptr; ad->us_configuration.camera_switch_added_cb = NULL; ad->us_configuration.accessories_switch_added_cb = NULL; diff --git a/src/AddSwitchPage.hpp b/src/AddSwitchPage.hpp index 6c17d98..6c6f5df 100644 --- a/src/AddSwitchPage.hpp +++ b/src/AddSwitchPage.hpp @@ -34,7 +34,7 @@ class AddSwitchPage { public: AddSwitchPage(SettingAccessibility *ad); - static void attachCallbackOnSwitchAttach(SettingAccessibility *ad, UniversalSwitchUpdateCb cb); //TODO: rename + static void attachCallbackOnSwitchAttach(SettingAccessibility *ad, UniversalSwitchUpdateCb cb, void *cbData); //TODO: rename static void disableAlreadyMappedSwitch(const std::vector &configuration_items, const std::string &switch_id, Elm_Object_Item *item); diff --git a/src/CameraSwitchesPage.cpp b/src/CameraSwitchesPage.cpp index 345f2ad..d0aebab 100644 --- a/src/CameraSwitchesPage.cpp +++ b/src/CameraSwitchesPage.cpp @@ -66,11 +66,12 @@ CameraSwitchesPage::CameraSwitchesPage(SettingAccessibility *ad) elm_layout_content_set(ad->md.getNaviframe()->getObject(), "prev_btn", back_btn); } -void CameraSwitchesPage::attachActionCallback(SettingAccessibility *ad, UniversalSwitchUpdateCb cb) +void CameraSwitchesPage::attachActionCallback(SettingAccessibility *ad, UniversalSwitchUpdateCb cb, void *cbData) { retm_if(ad == NULL, "Input parameter is NULL"); ad->us_configuration.camera_switch_added_cb = cb; + ad->us_configuration.camera_switch_added_cb_data = cbData; } void CameraSwitchesPage::addSwitchCb(void *data, Evas_Object *obj, void *event_info) @@ -101,7 +102,7 @@ void CameraSwitchesPage::switchActionCb(SettingAccessibility *ad, const std::str auto camera_switch = static_cast(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); + ad->us_configuration.camera_switch_added_cb(ad->us_configuration.camera_switch_added_cb_data, camera_switch->id, action, camera_switch->name); } void CameraSwitchesPage::backCb(void *data, Evas_Object *obj, void *event_info) diff --git a/src/CameraSwitchesPage.hpp b/src/CameraSwitchesPage.hpp index ac689d9..9187f37 100644 --- a/src/CameraSwitchesPage.hpp +++ b/src/CameraSwitchesPage.hpp @@ -33,7 +33,7 @@ class CameraSwitchesPage { public: CameraSwitchesPage(SettingAccessibility *ad); - static void attachActionCallback(SettingAccessibility *ad, UniversalSwitchUpdateCb cb); + static void attachActionCallback(SettingAccessibility *ad, UniversalSwitchUpdateCb cb, void *cbData); private: static void addSwitchCb(void *data, Evas_Object *obj, void *event_info); diff --git a/src/RemoveSwitchPage.cpp b/src/RemoveSwitchPage.cpp index c556648..39501dd 100644 --- a/src/RemoveSwitchPage.cpp +++ b/src/RemoveSwitchPage.cpp @@ -46,11 +46,12 @@ RemoveSwitchPage::RemoveSwitchPage(SettingAccessibility *ad) } } -void RemoveSwitchPage::attachCallback(SettingAccessibility *ad, UniversalSwitchUpdateCb cb) +void RemoveSwitchPage::attachCallback(SettingAccessibility *ad, UniversalSwitchUpdateCb cb, void *cbData) { retm_if(ad == NULL, "Input parameter is NULL"); ad->us_configuration.switch_removed_cb = cb; + ad->us_configuration.switch_removed_cb_data = cbData; } void RemoveSwitchPage::onDeleteButtonClicked(void *data, Evas_Object *obj, void *event_info) @@ -189,5 +190,5 @@ void RemoveSwitchPage::removeSwitch(SettingAccessibility *ad, size_t item_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); + ad->us_configuration.switch_removed_cb(ad->us_configuration.switch_removed_cb_data, config_item->switch_id, config_item->activity_type, config_item->user_name); } diff --git a/src/RemoveSwitchPage.hpp b/src/RemoveSwitchPage.hpp index cf897ad..b81da0b 100644 --- a/src/RemoveSwitchPage.hpp +++ b/src/RemoveSwitchPage.hpp @@ -34,7 +34,7 @@ class RemoveSwitchPage { public: RemoveSwitchPage(SettingAccessibility *ad); - static void attachCallback(SettingAccessibility *ad, UniversalSwitchUpdateCb cb); + static void attachCallback(SettingAccessibility *ad, UniversalSwitchUpdateCb cb, void *cbData); static void useNaviframeTitleAsCounter(SettingAccessibility *ad); private: diff --git a/src/ScreenSwitchPage.cpp b/src/ScreenSwitchPage.cpp index defe3b4..37ed1de 100644 --- a/src/ScreenSwitchPage.cpp +++ b/src/ScreenSwitchPage.cpp @@ -26,11 +26,12 @@ ScreenSwitchPage::ScreenSwitchPage(SettingAccessibility *ad) ActionPage::attachCallback(ad, actionCb, NULL); } -void ScreenSwitchPage::attachActionCallback(SettingAccessibility *ad, UniversalSwitchUpdateCb cb) +void ScreenSwitchPage::attachActionCallback(SettingAccessibility *ad, UniversalSwitchUpdateCb cb, void *cbData) { retm_if(ad == NULL, "Input parameter is NULL"); ad->us_configuration.screen_switch_added_cb = cb; + ad->us_configuration.screen_switch_added_cb_data = cbData; } void ScreenSwitchPage::actionCb(SettingAccessibility *ad, const std::string &action, void *user_data) @@ -39,6 +40,6 @@ void ScreenSwitchPage::actionCb(SettingAccessibility *ad, const std::string &act 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); + ad->us_configuration.screen_switch_added_cb(ad->us_configuration.screen_switch_added_cb_data, screen_switch->id, action, ACCESSIBILITY_UNIVERSAL_SWITCH_SCREEN); } } diff --git a/src/ScreenSwitchPage.hpp b/src/ScreenSwitchPage.hpp index b780d86..8084b76 100644 --- a/src/ScreenSwitchPage.hpp +++ b/src/ScreenSwitchPage.hpp @@ -35,7 +35,7 @@ class ScreenSwitchPage { public: ScreenSwitchPage(SettingAccessibility *ad); - static void attachActionCallback(SettingAccessibility *ad, UniversalSwitchUpdateCb cb); + static void attachActionCallback(SettingAccessibility *ad, UniversalSwitchUpdateCb cb, void *cbData); private: static void actionCb(SettingAccessibility *ad, const std::string &action, void *user_data); diff --git a/src/SettingAccessibility.hpp b/src/SettingAccessibility.hpp index 87b201a..d3b04b6 100644 --- a/src/SettingAccessibility.hpp +++ b/src/SettingAccessibility.hpp @@ -64,7 +64,6 @@ struct SettingAccessibility { 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; @@ -72,10 +71,6 @@ struct SettingAccessibility { Elm_Object_Item *naviframe_it; SetValueLayout set_value_layout; - Elm_Genlist *universal_switch_switches; - back_cb universal_switch_switches_back; - void *universal_switch_switches_back_data = nullptr; - tts_h tts; UniversalSwitchDbusConfig config; @@ -88,8 +83,6 @@ struct SettingAccessibility { std::unique_ptr accessoriesSwitchesPage_; std::unique_ptr screenSwitchPage_; std::unique_ptr addSwitchPage_; - std::unique_ptr updateSwitchPage_; - std::unique_ptr removeSwitchPage_; std::unique_ptr actionPage_; std::unique_ptr setValuePage_; std::unique_ptr settingPopup_; //TODO: change this variable name when all popups would be unified diff --git a/src/SwitchesPage.cpp b/src/SwitchesPage.cpp index a3bf850..a01afd4 100644 --- a/src/SwitchesPage.cpp +++ b/src/SwitchesPage.cpp @@ -22,53 +22,48 @@ #include SwitchesPage::SwitchesPage(SettingAccessibility *ad) + : context_(ad) { - retm_if(ad == NULL, "Input parameter is NULL"); - Evas_Object *genlist = elm_genlist_add(ad->md.getNaviframe()->getObject()); + Evas_Object *genlist = elm_genlist_add(context_->md.getNaviframe()->getObject()); retm_if(genlist == NULL, "Cannot set genlist object as content of layout"); - ad->md.naviframe_it = elm_naviframe_item_push(ad->md.getNaviframe()->getObject(), _("IDS_ACCS_UNIVERSAL_SWITCH_SETTINGS_GROUP_SWITCHES"), NULL, NULL, genlist, NULL); - elm_naviframe_item_pop_cb_set(ad->md.naviframe_it, naviframePopCb, ad); - elm_object_item_domain_text_translatable_set(ad->md.naviframe_it, PACKAGE, EINA_TRUE); + context_->md.naviframe_it = elm_naviframe_item_push(context_->md.getNaviframe()->getObject(), _("IDS_ACCS_UNIVERSAL_SWITCH_SETTINGS_GROUP_SWITCHES"), NULL, NULL, genlist, NULL); + elm_naviframe_item_pop_cb_set(context_->md.naviframe_it, naviframePopCb, this); + elm_object_item_domain_text_translatable_set(context_->md.naviframe_it, PACKAGE, EINA_TRUE); - Evas_Object *back_btn = WidgetFactory::createButton(ad->md.getNaviframe()->getObject(), {}, WidgetFactory::BACK_BUTTON_ARROW_STYLE, backCb, ad); - elm_layout_content_set(ad->md.getNaviframe()->getObject(), "prev_btn", back_btn); + Evas_Object *back_btn = WidgetFactory::createButton(context_->md.getNaviframe()->getObject(), {}, WidgetFactory::BACK_BUTTON_ARROW_STYLE, backCb, ad); + elm_layout_content_set(context_->md.getNaviframe()->getObject(), "prev_btn", back_btn); - ad->remove_switches_page_button = WidgetFactory::createButton(ad->md.getNaviframe()->getObject(), "IDS_ACCS_DELETE_CAPS", "naviframe/title_right", createRemovePageCb, ad); - elm_layout_content_set(ad->md.getNaviframe()->getObject(), "title_right_btn", ad->remove_switches_page_button); + remove_switches_page_button = WidgetFactory::createButton(context_->md.getNaviframe()->getObject(), "IDS_ACCS_DELETE_CAPS", "naviframe/title_right", createRemovePageCb, this); + elm_layout_content_set(context_->md.getNaviframe()->getObject(), "title_right_btn", remove_switches_page_button); elm_genlist_mode_set(genlist, ELM_LIST_COMPRESS); elm_object_style_set(genlist, "dialogue"); - updateSwitchesList(ad, genlist); - ad->universal_switch_switches = genlist; + updateSwitchesList(genlist); + universal_switch_switches = genlist; } -void SwitchesPage::attachCallback(SettingAccessibility *ad, back_cb callback, void *data) +void SwitchesPage::attachCallback(back_cb callback, void *data) { - retm_if(ad == NULL, "Input parameter is NULL"); - - ad->universal_switch_switches_back = callback; - ad->universal_switch_switches_back_data = data; + universal_switch_switches_back = callback; + universal_switch_switches_back_data = data; } -void SwitchesPage::updateSwitchesList(SettingAccessibility *ad, Evas_Object *genlist) +void SwitchesPage::updateSwitchesList(Evas_Object *genlist) { - retm_if(ad == NULL, "Input argument is NULL"); retm_if(genlist == NULL, "Input argument is NULL"); elm_genlist_clear(genlist); - createSwitchesGroup(ad, genlist); - createAddButton(ad, genlist); - elm_object_disabled_set(ad->remove_switches_page_button, ad->config.configuration_items.size() == 0); + createSwitchesGroup(genlist); + createAddButton(genlist); + elm_object_disabled_set(remove_switches_page_button, context_->config.configuration_items.size() == 0); } -void SwitchesPage::createAddButton(SettingAccessibility *ad, Evas_Object *genlist) +void SwitchesPage::createAddButton(Evas_Object *genlist) { - retm_if(ad == NULL, "Input argument is NULL"); - GenGroupItemData *item = createGendialGroupItem(genlist, &itc_1text_1icon_3, - addSwitchClickedCb, ad, + addSwitchClickedCb, this, SwallowType::ICON_IMAGE, 0, "IDS_ACCS_UNIVERSAL_SWITCH_SETTINGS_GROUP_SWITCHES_ADD_SWITCH", {}, @@ -76,37 +71,35 @@ void SwitchesPage::createAddButton(SettingAccessibility *ad, Evas_Object *genlis if (item) { item->l_swallow_path = ACCESSIBILITY_UNIVERSAL_SWITCH_PLUS_ICON; - item->userdata = ad; + item->userdata = context_; } } -void SwitchesPage::createSwitchesGroup(SettingAccessibility *ad, Evas_Object *genlist) +void SwitchesPage::createSwitchesGroup(Evas_Object *genlist) { - retm_if(ad == NULL, "Input argument is NULL"); - - for (auto &it : ad->config.configuration_items) { - auto activity_name = setting_accessibility_universal_switch_dbus_config_get_activity_name(&ad->config, it->activity_type); - addMappedSwitchMenuItem(ad, genlist, it->user_name, activity_name, switchClickCb, it); + for (auto &it : context_->config.configuration_items) { + auto activity_name = setting_accessibility_universal_switch_dbus_config_get_activity_name(&context_->config, it->activity_type); + addMappedSwitchMenuItem(genlist, it->user_name, activity_name, switchClickCb, it); } } void SwitchesPage::createRemovePageCb(void *data, Evas_Object *obj, void *event_info) { retm_if(data == NULL, "Data argument is NULL"); - auto ad = static_cast(data); + auto self = static_cast(data); - ad->removeSwitchPage_ = std::make_unique(ad); - RemoveSwitchPage::attachCallback(ad, switchRemovedCb); + self->removeSwitchPage_ = std::make_unique(self->context_); + RemoveSwitchPage::attachCallback(self->context_, switchRemovedCb, self); } void SwitchesPage::addSwitchClickedCb(void *data, Evas_Object *obj, void *event_info) { elm_genlist_item_selected_set((Elm_Object_Item *)event_info, EINA_FALSE); retm_if(data == NULL, "Data argument is NULL"); - auto ad = static_cast(data); + auto self = static_cast(data); - AddSwitchPage::attachCallbackOnSwitchAttach(ad, addSwitchCb); - ad->addSwitchPage_ = std::make_unique(ad); + self->addSwitchPage_ = std::make_unique(self->context_); + AddSwitchPage::attachCallbackOnSwitchAttach(self->context_, addSwitchCb, self); } void SwitchesPage::switchClickCb(void *data, Evas_Object *obj, void *event_info) @@ -119,46 +112,48 @@ void SwitchesPage::switchClickCb(void *data, Evas_Object *obj, void *event_info) auto list_item = static_cast(elm_object_item_data_get(item)); auto config_item = static_cast(list_item->userdata); - auto ad = static_cast(data); - UpdateSwitchPage::attachActionCallback(ad, switchUpdatedCb); - ad->updateSwitchPage_ = std::make_unique(ad, config_item); + auto self = static_cast(data); + UpdateSwitchPage::attachActionCallback(self->context_, switchUpdatedCb, self); + self->updateSwitchPage_ = std::make_unique(self->context_, config_item); } -void SwitchesPage::switchUpdatedCb(SettingAccessibility *ad, const std::string &switch_id, const std::string &switch_action, const std::string &switch_name) +void SwitchesPage::switchUpdatedCb(void *data, const std::string &switch_id, const std::string &switch_action, const std::string &switch_name) { - retm_if(ad == NULL, "Input parameter is NULL"); + retm_if(data == NULL, "Input parameter is NULL"); + auto self = static_cast(data); SETTING_TRACE_DEBUG("Switch updated, id: %s, name: %s, action: %s.", switch_id.c_str(), switch_name.c_str(), switch_action.c_str()); - setting_accessibility_universal_switch_dbus_config_updateSwitchConfigurationItem(&ad->config, switch_id.c_str(), switch_name.c_str(), switch_action.c_str()); - updateSwitchesList(ad, ad->universal_switch_switches); + setting_accessibility_universal_switch_dbus_config_updateSwitchConfigurationItem(&self->context_->config, switch_id.c_str(), switch_name.c_str(), switch_action.c_str()); + self->updateSwitchesList(self->universal_switch_switches); } -void SwitchesPage::switchRemovedCb(SettingAccessibility *ad, const std::string &switch_id, const std::string &switch_action, const std::string &switch_name) +void SwitchesPage::switchRemovedCb(void *data, const std::string &switch_id, const std::string &switch_action, const std::string &switch_name) { - retm_if(ad == NULL, "Input parameter is NULL"); + retm_if(data == NULL, "Input parameter is NULL"); + auto self = static_cast(data); SETTING_TRACE_DEBUG("Switch removed, name: %s, id: %s, action: %s.", switch_name.c_str(), switch_id.c_str(), switch_action.c_str()); - setting_accessibility_universal_switch_dbus_config_removeSwitchConfigurationItem(&ad->config, switch_id.c_str()); - updateSwitchesList(ad, ad->universal_switch_switches); + setting_accessibility_universal_switch_dbus_config_removeSwitchConfigurationItem(&self->context_->config, switch_id.c_str()); + self->updateSwitchesList(self->universal_switch_switches); } -void SwitchesPage::addSwitchCb(SettingAccessibility *ad, const std::string &switch_id, const std::string &switch_action, const std::string &switch_name) +void SwitchesPage::addSwitchCb(void *data, const std::string &switch_id, const std::string &switch_action, const std::string &switch_name) { - retm_if(ad == NULL, "Input parameter is NULL"); + retm_if(data == NULL, "Input parameter is NULL"); + auto self = static_cast(data); SETTING_TRACE_DEBUG("Add switch, id: %s, name: %s, action: %s.", switch_id.c_str(), switch_name.c_str(), switch_action.c_str()); - setting_accessibility_universal_switch_dbus_config_addSwitchConfigurationItem(&ad->config, switch_id.c_str(), switch_name.c_str(), switch_action.c_str()); - updateSwitchesList(ad, ad->universal_switch_switches); + setting_accessibility_universal_switch_dbus_config_addSwitchConfigurationItem(&self->context_->config, switch_id.c_str(), switch_name.c_str(), switch_action.c_str()); + self->updateSwitchesList(self->universal_switch_switches); } -GenGroupItemData *SwitchesPage::addMappedSwitchMenuItem(SettingAccessibility *ad, Evas_Object *genlist, const std::string &main_text, +GenGroupItemData *SwitchesPage::addMappedSwitchMenuItem(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"); auto item = createGendialGroupItem(genlist, &itc_2text_1icon_3, - item_cb, ad, + item_cb, this, SwallowType::INVALID, 0, main_text, sub_text, @@ -173,16 +168,15 @@ GenGroupItemData *SwitchesPage::addMappedSwitchMenuItem(SettingAccessibility *ad Eina_Bool SwitchesPage::naviframePopCb(void *data, Elm_Object_Item *it) { retv_if(data == NULL, EINA_TRUE); - auto ad = static_cast(data); - - if (ad->universal_switch_switches_back) - ad->universal_switch_switches_back(ad->universal_switch_switches_back_data); + auto self = static_cast(data); - ad->universal_switch_switches_back = NULL; - ad->universal_switch_switches_back = nullptr; - ad->universal_switch_switches = NULL; - ad->md.naviframe_it = NULL; + if (self->universal_switch_switches_back) + self->universal_switch_switches_back(self->universal_switch_switches_back_data); + self->universal_switch_switches_back = NULL; + self->universal_switch_switches_back_data = nullptr; + self->universal_switch_switches = nullptr; + self->context_->md.naviframe_it = NULL; return EINA_TRUE; } diff --git a/src/SwitchesPage.hpp b/src/SwitchesPage.hpp index 7dfe399..e9603f6 100644 --- a/src/SwitchesPage.hpp +++ b/src/SwitchesPage.hpp @@ -19,6 +19,13 @@ #include "SettingAccessibility.hpp" #include "GenGroupItemData.hpp" +#include "RemoveSwitchPage.hpp" +#include "AddSwitchPage.hpp" +#include "UpdateSwitchPage.hpp" + +class RemoveSwitchPage; +class AddSwitchPage; +class UpdateSwitchPage; /** * View displaying already configured switches and allowing @@ -35,23 +42,31 @@ class SwitchesPage public: using back_cb = void(*)(void *ad); //TODO: probably remove SwitchesPage(SettingAccessibility *ad); - static void attachCallback(SettingAccessibility *ad, back_cb callback, void *data); - static void addSwitchCb(SettingAccessibility *ad, const std::string &switch_id, const std::string &switch_action, const std::string &switch_name); + void attachCallback(back_cb callback, void *data); + static void addSwitchCb(void *data, const std::string &switch_id, const std::string &switch_action, const std::string &switch_name); private: - static void updateSwitchesList(SettingAccessibility *ad, Evas_Object *genlist); - static void createAddButton(SettingAccessibility *ad, Evas_Object *genlist); - static void createSwitchesGroup(SettingAccessibility *ad, Evas_Object *genlist); + void updateSwitchesList(Evas_Object *genlist); + void createAddButton(Evas_Object *genlist); + void createSwitchesGroup(Evas_Object *genlist); static void createRemovePageCb(void *data, Evas_Object *obj, void *event_info); static void addSwitchClickedCb(void *data, Evas_Object *obj, void *event_info); static void switchClickCb(void *data, Evas_Object *obj, void *event_info); - static void switchUpdatedCb(SettingAccessibility *ad, const std::string &switch_id, const std::string &switch_action, const std::string &switch_name); - static void switchRemovedCb(SettingAccessibility *ad, const std::string &switch_id, const std::string &switch_action, const std::string &switch_name); - static GenGroupItemData *addMappedSwitchMenuItem(SettingAccessibility *ad, Evas_Object *genlist, const std::string &main_text, + static void switchUpdatedCb(void *data, const std::string &switch_id, const std::string &switch_action, const std::string &switch_name); + static void switchRemovedCb(void *data, const std::string &switch_id, const std::string &switch_action, const std::string &switch_name); + GenGroupItemData *addMappedSwitchMenuItem(Evas_Object *genlist, const std::string &main_text, const std::string &sub_text, SettingCallback item_cb, void *user_data); static Eina_Bool naviframePopCb(void *data, Elm_Object_Item *it); static void backCb(void *data, Evas_Object *obj, void *event_info); + SettingAccessibility *context_ = nullptr; + Evas_Object *remove_switches_page_button = nullptr; + back_cb universal_switch_switches_back = nullptr; + void *universal_switch_switches_back_data = nullptr; + Elm_Genlist *universal_switch_switches; + std::unique_ptr removeSwitchPage_; + std::unique_ptr addSwitchPage_; + std::unique_ptr updateSwitchPage_; }; #endif diff --git a/src/UniversalSwitchConfiguration.hpp b/src/UniversalSwitchConfiguration.hpp index 1815d35..cc761c4 100644 --- a/src/UniversalSwitchConfiguration.hpp +++ b/src/UniversalSwitchConfiguration.hpp @@ -31,7 +31,7 @@ enum class ScanDirection { }; class SettingAccessibility; -using UniversalSwitchUpdateCb = std::function; +using UniversalSwitchUpdateCb = std::function; /** * Class containing cached parameteres required by Universal Switch @@ -74,10 +74,15 @@ public: bool manage_options_state[MANAGE_OPTIONS_COUNT] = {false}; UniversalSwitchUpdateCb screen_switch_added_cb; + void *screen_switch_added_cb_data = nullptr; UniversalSwitchUpdateCb camera_switch_added_cb; + void *camera_switch_added_cb_data = nullptr; UniversalSwitchUpdateCb accessories_switch_added_cb; + void *accessories_switch_added_cb_data = nullptr; UniversalSwitchUpdateCb switch_removed_cb; + void *switch_removed_cb_data = nullptr; UniversalSwitchUpdateCb switch_updated_cb; + void *switch_updated_cb_data = nullptr; private: }; diff --git a/src/UniversalSwitchPage.cpp b/src/UniversalSwitchPage.cpp index 2522000..1add25c 100644 --- a/src/UniversalSwitchPage.cpp +++ b/src/UniversalSwitchPage.cpp @@ -93,7 +93,7 @@ void UniversalSwitchPage::createSettingsPage(void *data, Evas_Object *obj, void void UniversalSwitchPage::addNewSwitch() { - AddSwitchPage::attachCallbackOnSwitchAttach(context_, onNewSwitchAddition); + AddSwitchPage::attachCallbackOnSwitchAttach(context_, onNewSwitchAddition, context_); context_->addSwitchPage_ = std::make_unique(context_); } @@ -139,9 +139,10 @@ void UniversalSwitchPage::updateVconfKey(int state) } } -void UniversalSwitchPage::onNewSwitchAddition(SettingAccessibility *ad, const std::string &switch_id, const std::string &switch_action, const std::string &switch_name) +void UniversalSwitchPage::onNewSwitchAddition(void *data, const std::string &switch_id, const std::string &switch_action, const std::string &switch_name) { - retm_if(ad == NULL, "Input parameter is NULL"); + retm_if(data == NULL, "Input parameter is NULL"); + auto ad = static_cast(data); SwitchesPage::addSwitchCb(ad, switch_id, switch_action, switch_name); int switch_count = setting_accessibility_universal_switch_dbus_config_get_switch_count(&ad->config); diff --git a/src/UniversalSwitchPage.hpp b/src/UniversalSwitchPage.hpp index 6d18b0e..a543101 100644 --- a/src/UniversalSwitchPage.hpp +++ b/src/UniversalSwitchPage.hpp @@ -44,7 +44,7 @@ private: void displayState(bool state); static bool setState(bool state); void updateVconfKey(int state); //TODO rename - static void onNewSwitchAddition(SettingAccessibility *ad, const std::string &switch_id, const std::string &switch_action, const std::string &switch_name); + static void onNewSwitchAddition(void *data, const std::string &switch_id, const std::string &switch_action, const std::string &switch_name); static void popupResponseCb(void *data, Evas_Object *obj, void *event_info); static void backCb(void *data, Evas_Object *obj, void *event_info); static Eina_Bool naviframePopCb(void *data, Elm_Object_Item *it); diff --git a/src/UniversalSwitchSettingsPage.cpp b/src/UniversalSwitchSettingsPage.cpp index d23595c..d381aae 100644 --- a/src/UniversalSwitchSettingsPage.cpp +++ b/src/UniversalSwitchSettingsPage.cpp @@ -1241,7 +1241,7 @@ void UniversalSwitchSettingsPage::switchesClickCb(void *data, Evas_Object *obj, auto self = static_cast(data); self->switchesPage_ = std::make_unique(self->context_); - SwitchesPage::attachCallback(self->context_, updateSwitchesCount, self); + self->switchesPage_->attachCallback(updateSwitchesCount, self); } void UniversalSwitchSettingsPage::ctxPopupDelCb(void *data, Evas_Object *obj, void *event_info) diff --git a/src/UpdateSwitchPage.cpp b/src/UpdateSwitchPage.cpp index db9402c..63988a1 100644 --- a/src/UpdateSwitchPage.cpp +++ b/src/UpdateSwitchPage.cpp @@ -35,17 +35,18 @@ UpdateSwitchPage::UpdateSwitchPage(SettingAccessibility *ad, UniversalSwitchConf } } -void UpdateSwitchPage::attachActionCallback(SettingAccessibility *ad, UniversalSwitchUpdateCb cb) +void UpdateSwitchPage::attachActionCallback(SettingAccessibility *ad, UniversalSwitchUpdateCb cb, void *cbData) { retm_if(ad == NULL, "Input parameter is NULL"); ad->us_configuration.switch_updated_cb = cb; + ad->us_configuration.switch_updated_cb_data = cbData; } void UpdateSwitchPage::onActionUpdate(SettingAccessibility *ad, const std::string &action, void *user_data) { if (ad->us_configuration.switch_updated_cb) { auto config_item = static_cast(user_data); - ad->us_configuration.switch_updated_cb(ad, config_item->switch_id, action, config_item->user_name); + ad->us_configuration.switch_updated_cb(ad->us_configuration.switch_updated_cb_data, config_item->switch_id, action, config_item->user_name); } } diff --git a/src/UpdateSwitchPage.hpp b/src/UpdateSwitchPage.hpp index 6d20745..e880aa8 100644 --- a/src/UpdateSwitchPage.hpp +++ b/src/UpdateSwitchPage.hpp @@ -33,7 +33,7 @@ class UpdateSwitchPage { public: UpdateSwitchPage(SettingAccessibility *ad, UniversalSwitchConfigurationItem *config_item); - static void attachActionCallback(SettingAccessibility *ad, UniversalSwitchUpdateCb cb); + static void attachActionCallback(SettingAccessibility *ad, UniversalSwitchUpdateCb cb, void *cbData); private: static void onActionUpdate(SettingAccessibility *ad, const std::string &action, void *user_data); -- 2.7.4