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 "UpdateSwitchPage.hpp"
19 #include "AccessibilitySettingLog.hpp"
20 #include "Singleton.hpp"
21 #include "Toolbar.hpp"
22 #include "setting-accessibility.h"
26 #define GRP_SET_VALUE_UPDATE_ACCESSORIES_SWITCH "set-value-update-accessories-switch"
27 #define PRT_SET_VALUE_ENTRY "set-value-entry"
28 #define PRT_SET_VALUE_DESC "set-value-desc"
29 #define EDJ_SET_VALUE "edje/accessibility-settings-set-value.edj"
30 #define PRT_SET_VALUE_LIST "set-value-list"
32 UpdateSwitchPage::UpdateSwitchPage(UniversalSwitchConfigurationItem *config_item)
33 : context_(Singleton<AppContext>::instance())
35 config_item_to_update_.activity_type = config_item->activity_type;
36 config_item_to_update_.switch_id = config_item->switch_id;
37 config_item_to_update_.user_name = config_item->user_name;
39 if (config_item->provider_id == ACCESSIBILITY_UNIVERSAL_SWITCH_ACCESSORIES_SWITCH_PROVIDER) {
40 createUpdateAccessoriesSwitchPage();
42 actionPage_ = std::make_unique<ActionPage>();
43 actionPage_->attachCallback(onActionUpdate, this);
47 void UpdateSwitchPage::attachActionCallback(UniversalSwitchCb cb, void *cbData)
49 switch_updated_cb = cb;
50 switch_updated_cb_data = cbData;
53 void UpdateSwitchPage::onActionUpdate(const std::string &action, void *user_data)
55 auto self = static_cast<UpdateSwitchPage *>(user_data);
56 if (self->switch_updated_cb) {
57 self->switch_updated_cb(self->switch_updated_cb_data,
58 self->config_item_to_update_.switch_id,
60 self->config_item_to_update_.user_name);
64 void UpdateSwitchPage::createUpdateAccessoriesSwitchPage()
66 auto naviframe = context_.navContext_.getNaviframe();
67 layout_ = Widget::make<Layout>(
68 naviframe, "edje/accessibility-settings-set-value.edj", GRP_SET_VALUE_UPDATE_ACCESSORIES_SWITCH);
69 layout_->setPartText(PRT_SET_VALUE_DESC, "IDS_ACCS_UNIVERSAL_SWITCH_NAME");
71 auto tabbar = Widget::make<Toolbar>(naviframe);
72 auto backCb = [naviframe, tabbar]() {
74 naviframe->removeChild(tabbar);
77 tabbar->addItem("IDS_ACCS_UNIVERSAL_SWITCH_CANCEL", backCb);
78 tabbar->addItem("IDS_ACCS_UNIVERSAL_SWITCH_SAVE", [this, backCb]() {
79 if (switch_updated_cb) {
80 switch_updated_cb(switch_updated_cb_data,
81 config_item_to_update_.switch_id,
82 config_item_to_update_.activity_type,
83 entry_->getEntryText());
88 entry_ = Widget::make<Entry>(layout_);
89 entry_->setEntryText(config_item_to_update_.user_name);
90 entry_->moveCursorToEnd();
91 layout_->setPartContent(PRT_SET_VALUE_ENTRY, entry_);
93 updateAccessoriesActionGenlist_ = createGenlist(layout_, {});
94 updateAccessoriesActionGenlist_->appendItem({"type1",
95 "IDS_ACCS_UNIVERSAL_SWITCH_ACTION",
96 setting_accessibility_universal_switch_dbus_config_get_activity_name(
97 &context_.config, config_item_to_update_.activity_type),
98 [this](auto item) { this->updateSwitchAction(); }});
100 auto naviItem = naviframe->pushBack({}, layout_, {}, nullptr, "tabbar/notitle");
101 naviItem.setPartContent("tabbar", tabbar);
104 Genlist *UpdateSwitchPage::createGenlist(Widget *parent, std::string title)
106 auto genlist = Widget::make<Genlist>(parent);
107 genlist->setMode(ELM_LIST_COMPRESS);
108 genlist->setStyle("dialogue");
111 genlist->appendItem({"group_index", std::move(title)});
113 parent->setPartContent(PRT_SET_VALUE_LIST, genlist);
118 void UpdateSwitchPage::updateSwitchAction()
120 actionPage_ = std::make_unique<ActionPage>();
121 actionPage_->attachCallback(updateSwitchChooseAction, this);
124 void UpdateSwitchPage::updateSwitchChooseAction(const std::string &action, void *user_data)
126 auto self = static_cast<UpdateSwitchPage *>(user_data);
128 self->config_item_to_update_.activity_type = action;
129 self->updateAccessoriesActionGenlist_->clear();
131 self->updateAccessoriesActionGenlist_->appendItem({"type1",
132 "IDS_ACCS_UNIVERSAL_SWITCH_ACTION",
133 setting_accessibility_universal_switch_dbus_config_get_activity_name(
134 &self->context_.config, self->config_item_to_update_.activity_type),
135 [self](auto item) { self->updateSwitchAction(); }});
137 self->context_.navContext_.getNaviframe()->popBack();