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 "AccessoriesSwitchesPage.hpp"
19 #include "AccessibilitySettingLog.hpp"
24 #include "Singleton.hpp"
26 AccessoriesSwitchesPage::AccessoriesSwitchesPage(NaviframeItem targetItem)
27 : context_(Singleton<AppContext>::instance()), targetItem_(targetItem)
29 auto naviframe = context_.navContext_.getNaviframe();
30 auto layout = Widget::make<Layout>(naviframe, EDJ_ACCESSORY, GRP_ACCESSORY);
31 layout->setText(PRT_ACCESSORY_LABEL, "IDS_ACCS_UNIVERSAL_SWITCH_ADD_SWITCH_ACCESSORIES_DESC");
33 naviframe->pushBack("IDS_ACCS_UNIVERSAL_SWITCH_ADD_SWITCH_ACCESSORIES_TITLE", layout, [this]() {
34 setting_accessibility_universal_switch_dbus_config_cancelCaptureSwitch(&context_.config);
38 auto prevBtn = Widget::make<Button>(
39 naviframe, [naviframe]() { naviframe->popBack(); }, std::string{}, Button::BACK_BUTTON_ARROW_STYLE);
40 naviframe->setPartContent("prev_btn", prevBtn);
42 setting_accessibility_universal_switch_dbus_config_captureSwitch(
43 &context_.config, ACCESSIBILITY_UNIVERSAL_SWITCH_ACCESSORIES_SWITCH_PROVIDER, -1, captureSwitchCb, this);
46 void AccessoriesSwitchesPage::attachActionCallback(UniversalSwitchCb cb, void *cbData)
48 accessories_switch_added_cb = cb;
49 accessories_switch_added_cb_data = cbData;
52 void AccessoriesSwitchesPage::captureSwitchCb(void *user_data, const std::string &switch_id)
54 RETURN_IF(!user_data, "Input argument user_data is NULL");
55 RETURN_IF(switch_id.empty(), "Input argument switch_id is an empty string");
57 auto self = static_cast<AccessoriesSwitchesPage *>(user_data);
59 for (auto &it : self->context_.config.configuration_items) {
60 if (switch_id == it->switch_id) {
61 self->alreadyMappedSwitchPopup();
65 self->switchId = switch_id;
66 self->newSwitchPopup();
69 void AccessoriesSwitchesPage::newSwitchPopup()
71 auto popup = Widget::make<Popup>(context_.navContext_.getNaviframe(), "IDS_ACCS_UNIVERSAL_SWITCH_ADD_SWITCH");
72 popup->setEextEventCallback(EEXT_CALLBACK_BACK, []() {});
74 auto layout = Widget::make<Layout>(popup, EDJ_ACCESSORY_POPUP, GRP_ACCESSORY_POPUP);
75 popup->setContent(layout);
77 auto entry = Widget::make<Entry>(layout);
78 entry->setWeightHint(EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
79 entry->setPartText("guide", "IDS_ACCS_UNIVERSAL_SWITCH_ADD_SWITCH_NAME");
80 layout->setPartContent(PRT_ACCESSORY_POPUP_ENTRY, entry);
82 auto cancelBtnCb = [popup, this]() {
83 auto parent = popup->getParent();
84 parent->removeChild(popup);
85 setting_accessibility_universal_switch_dbus_config_captureSwitch(
86 &context_.config, ACCESSIBILITY_UNIVERSAL_SWITCH_ACCESSORIES_SWITCH_PROVIDER, -1, captureSwitchCb, this);
89 auto cancelBtn = Widget::make<Button>(popup, cancelBtnCb, "IDS_ACCS_UNIVERSAL_SWITCH_CANCEL");
90 cancelBtn->setStyle("popup");
91 popup->setPartContent("button1", cancelBtn);
93 auto saveBtnCb = [popup, entry, this]() {
94 if ((switchName_ = entry->getEntryText()).empty()) {
95 DEBUG("Empty switch name entry");
99 actionPage_ = std::make_unique<ActionPage>(targetItem_);
100 actionPage_->attachCallback(accessorySwitchActionCb, this);
101 elm_naviframe_item_pop_cb_set(
102 elm_naviframe_top_item_get(context_.navContext_.getNaviframe()->getObject()), renewCaptureSwitchCb, this); // TODO
104 auto parent = popup->getParent();
105 parent->removeChild(popup);
108 auto saveBtn = Widget::make<Button>(popup, saveBtnCb, "IDS_ACCS_UNIVERSAL_SWITCH_SAVE");
109 saveBtn->setStyle("popup");
110 popup->setPartContent("button2", saveBtn);
113 void AccessoriesSwitchesPage::alreadyMappedSwitchPopup()
115 auto popup = Widget::make<Popup>(context_.navContext_.getNaviframe(), "IDS_ACCS_UNIVERSAL_SWITCH_UNABLE_TO_ADD");
116 popup->setEextEventCallback(EEXT_CALLBACK_BACK, []() {});
118 auto okBtnCb = [popup, this]() {
119 setting_accessibility_universal_switch_dbus_config_captureSwitch(
120 &context_.config, ACCESSIBILITY_UNIVERSAL_SWITCH_ACCESSORIES_SWITCH_PROVIDER, -1, captureSwitchCb, this);
121 auto parent = popup->getParent();
122 parent->removeChild(popup);
125 auto okBtn = Widget::make<Button>(popup, okBtnCb, "IDS_ACCS_UNIVERSAL_SWITCH_OK");
126 okBtn->setStyle("popup");
127 popup->setPartContent("button1", okBtn);
129 auto layout = Widget::make<Layout>(popup, EDJ_ACCESSORY_POPUP, GRP_ACCESSORY_POPUP);
130 layout->setPartText(PRT_ACCESSORY_POPUP_LABEL, "IDS_ACCS_UNIVERSAL_SWITCH_ALREADY_ADDED");
131 popup->setContent(layout);
134 void AccessoriesSwitchesPage::accessorySwitchActionCb(const std::string &action, void *user_data)
136 auto self = static_cast<AccessoriesSwitchesPage *>(user_data);
138 if (self->accessories_switch_added_cb)
139 self->accessories_switch_added_cb(self->accessories_switch_added_cb_data,
140 self->switchId.c_str(),
142 self->switchName_.c_str());
145 Eina_Bool AccessoriesSwitchesPage::renewCaptureSwitchCb(void *data, Elm_Object_Item *it)
147 RETURN_DEFAULT_IF(!data, "Input is empty");
148 auto self = static_cast<AccessoriesSwitchesPage *>(data);
149 setting_accessibility_universal_switch_dbus_config_captureSwitch(
150 &self->context_.config, ACCESSIBILITY_UNIVERSAL_SWITCH_ACCESSORIES_SWITCH_PROVIDER, -1, captureSwitchCb, self);