2 * Copyright 2018 Samsung Electronics Co., Ltd
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
17 #include "SwitchesPage.hpp"
19 #include "Singleton.hpp"
20 #include "setting-accessibility.h"
24 SwitchesPage::SwitchesPage()
25 : context_(Singleton<AppContext>::instance())
27 auto naviframe = context_.navContext_.getNaviframe();
28 switches_ = Widget::make<Genlist>(naviframe);
29 switches_->setMode(ELM_LIST_COMPRESS);
30 switches_->setStyle("dialogue");
32 auto prevBtn = Widget::make<Button>(naviframe,
34 naviframe->removeChild(removeSwitchesPageBtn_);
38 Button::BACK_BUTTON_ARROW_STYLE);
40 naviframe->pushBack("IDS_ACCS_UNIVERSAL_SWITCH_SETTINGS_GROUP_SWITCHES",
43 if (universal_switch_switches_back)
44 universal_switch_switches_back(universal_switch_switches_back_data);
46 universal_switch_switches_back = nullptr;
47 universal_switch_switches_back_data = nullptr;
51 removeSwitchesPageBtn_ = Widget::make<Button>(naviframe,
53 removeSwitchPage_ = std::make_unique<RemoveSwitchPage>();
54 removeSwitchPage_->attachCallback(switchRemovedCb, this);
56 "IDS_ACCS_DELETE_CAPS",
57 "naviframe/title_right");
58 naviframe->setPartContent("title_right_btn", removeSwitchesPageBtn_);
62 void SwitchesPage::attachCallback(back_cb callback, void *data)
64 universal_switch_switches_back = callback;
65 universal_switch_switches_back_data = data;
68 void SwitchesPage::updateSwitchesList()
71 createSwitchesGroup();
72 switches_->appendItem({"type1",
73 "IDS_ACCS_UNIVERSAL_SWITCH_SETTINGS_GROUP_SWITCHES_ADD_SWITCH",
76 addSwitchPage_ = std::make_unique<AddSwitchPage>();
77 addSwitchPage_->attachCallbackOnSwitchAttach(addSwitchCb, this);
79 ACCESSIBILITY_UNIVERSAL_SWITCH_PLUS_ICON});
80 removeSwitchesPageBtn_->disable(context_.config.configuration_items.size() == 0);
83 void SwitchesPage::createSwitchesGroup()
85 for (auto &it : context_.config.configuration_items) {
86 auto activity_name = setting_accessibility_universal_switch_dbus_config_get_activity_name(
87 &context_.config, it->activity_type);
88 switches_->appendItem({"type1", it->user_name, activity_name, [=](auto item) {
89 this->updateSwitchPage_ = std::make_unique<UpdateSwitchPage>(it);
90 this->updateSwitchPage_->attachActionCallback(switchUpdatedCb, this);
95 void SwitchesPage::switchUpdatedCb(
97 const std::string &switch_id,
98 const std::string &switch_action,
99 const std::string &switch_name)
101 RETURN_IF(!data, "Input parameter is NULL");
102 auto self = static_cast<SwitchesPage *>(data);
104 DEBUG("Switch updated, id: %s, name: %s, action: %s.", switch_id.c_str(), switch_name.c_str(), switch_action.c_str());
105 setting_accessibility_universal_switch_dbus_config_updateSwitchConfigurationItem(
106 &self->context_.config, switch_id, switch_name, switch_action);
107 self->updateSwitchesList();
110 void SwitchesPage::switchRemovedCb(
112 const std::string &switch_id,
113 const std::string &switch_action,
114 const std::string &switch_name)
116 RETURN_IF(!data, "Input parameter is NULL");
117 auto self = static_cast<SwitchesPage *>(data);
119 DEBUG("Switch removed, name: %s, id: %s, action: %s.", switch_name.c_str(), switch_id.c_str(), switch_action.c_str());
120 setting_accessibility_universal_switch_dbus_config_removeSwitchConfigurationItem(&self->context_.config, switch_id);
121 self->updateSwitchesList();
124 void SwitchesPage::addSwitchCb(
126 const std::string &switch_id,
127 const std::string &switch_action,
128 const std::string &switch_name)
130 RETURN_IF(!data, "Input parameter is NULL");
131 auto self = static_cast<SwitchesPage *>(data);
133 DEBUG("Add switch, id: %s, name: %s, action: %s.", switch_id.c_str(), switch_name.c_str(), switch_action.c_str());
134 setting_accessibility_universal_switch_dbus_config_addSwitchConfigurationItem(
135 &self->context_.config, switch_id, switch_name, switch_action);
136 self->updateSwitchesList();