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 "RemoveSwitchPage.hpp"
19 #include "AccessibilitySettingLog.hpp"
21 #include "Genlist.hpp"
23 #include "Singleton.hpp"
25 #include "setting-accessibility.h"
28 #include <efl_extension.h>
30 #define SWITCH_COUNTER_MAX 99
31 #define SWITCH_COUNTER_TITLE_LENGTH 4
33 RemoveSwitchPage::RemoveSwitchPage()
34 : context_(Singleton<AppContext>::instance())
36 auto naviframe = context_.navContext_.getNaviframe();
37 layout_ = Widget::make<Layout>(naviframe, "edje/accessibility-settings-set-value.edj", "set-value-switches");
38 genlist_ = Widget::make<Genlist>(layout_);
39 genlist_->setMode(ELM_LIST_COMPRESS);
40 genlist_->setStyle("dialogue");
41 layout_->setPartContent("set-value-list", genlist_);
43 allCheckbox_ = Widget::make<Check>(naviframe, false, std::string{}, [this]() {
44 auto genlist_size = genlist_->size();
45 bool all_selected = (switchesToRemoveCounter_ == genlist_size);
47 auto item = genlist_->getFirst();
49 item->setState(!all_selected);
53 switchesToRemoveCounter_ = all_selected ? 0 : genlist_size;
54 removeSwitchPopupBtn_->disable(switchesToRemoveCounter_ ? false : true);
57 removeSwitchPopupBtn_ = Widget::make<Button>(
58 naviframe, [this]() { createPopupForSwitchesRemoving(); }, "IDS_ACCS_DELETE_CAPS", "naviframe/title_right");
59 removeSwitchPopupBtn_->disable(true);
61 naviframe->pushBack("IDS_ACCS_SELECT_ITEMS", layout_, {}, allCheckbox_);
62 naviframe->setPartContent("title_right_btn", removeSwitchPopupBtn_);
64 for (auto i = 0u; i < context_.config.configuration_items.size(); ++i) {
65 auto activity_name = setting_accessibility_universal_switch_dbus_config_get_activity_name(
66 &context_.config, context_.config.configuration_items[i]->activity_type);
67 genlist_->appendItem({"type1",
68 context_.config.configuration_items[i]->user_name,
72 switchesToRemoveCounter_++;
74 switchesToRemoveCounter_--;
76 auto state = switchesToRemoveCounter_ == genlist_->size();
77 allCheckbox_->setState(state);
79 removeSwitchPopupBtn_->disable(switchesToRemoveCounter_ ? false : true);
81 GenlistItem::WidgetType::check});
85 void RemoveSwitchPage::attachCallback(UniversalSwitchCb cb, void *cbData)
87 switch_removed_cb = cb;
88 switch_removed_cb_data = cbData;
91 void RemoveSwitchPage::createPopupForSwitchesRemoving()
93 auto popup = Widget::make<Popup>(context_.navContext_.getNaviframe(), "IDS_ACCS_UNIVERSAL_SWITCH_DELETE_SWITCHES");
95 popup->setOrientation(ELM_POPUP_ORIENT_CENTER);
96 auto areAllSwitchesSelectedToRemove = switchesToRemoveCounter_ == genlist_->size();
98 if (Singleton<VConfInterface>::instance().get(VCONFKEY_SETAPPL_ACCESSIBILITY_UNIVERSAL_SWITCH_INTERACTION_SERVICE, false) &&
99 areAllSwitchesSelectedToRemove) {
100 popup->setText("IDS_ACCS_UNIVERSAL_SWITCH_DELETE_ALL_SWITCHES_DESC");
102 auto s = std::to_string(switchesToRemoveCounter_) + " " +
103 TranslatedString{"IDS_ACCS_UNIVERSAL_SWITCH_DELETE_SWITCHES_DESC"}.str();
106 auto removeCb = [p = popup, nf = context_.navContext_.getNaviframe()]() { nf->removeChild(p); };
107 popup->setEextEventCallback(EEXT_CALLBACK_BACK, removeCb);
108 popup->setEvasSmartCallback("dismissed", removeCb);
109 popup->setEvasSmartCallback("block,clicked", removeCb);
111 auto cancelBtn = Widget::make<Button>(popup, removeCb, "IDS_ST_BUTTON_CANCEL", "bottom");
112 popup->setPartContent("button1", cancelBtn);
114 auto removeSwitchCb = [removeCb, areAllSwitchesSelectedToRemove, this]() {
115 auto item = genlist_->getLast();
116 size_t i = genlist_->size() - 1;
118 if (item->getState())
126 context_.navContext_.getNaviframe()->removeChild(removeSwitchPopupBtn_);
127 context_.navContext_.getNaviframe()->popBack();
129 if (areAllSwitchesSelectedToRemove)
130 Singleton<VConfInterface>::instance().set(VCONFKEY_SETAPPL_ACCESSIBILITY_UNIVERSAL_SWITCH_INTERACTION_SERVICE, false);
133 auto deleteSwitchBtn = Widget::make<Button>(popup, removeSwitchCb, "IDS_ACCS_DELETE", "bottom");
134 popup->setPartContent("button2", deleteSwitchBtn);
137 void RemoveSwitchPage::removeSwitch(size_t item_id)
139 if (item_id >= context_.config.configuration_items.size()) {
140 WARNING("Wrong item id");
144 auto config_item = context_.config.configuration_items[item_id];
145 DEBUG("Removing switch, switch_id: %s", config_item->switch_id.c_str());
147 switch_removed_cb(switch_removed_cb_data,
148 config_item->switch_id,
149 config_item->activity_type,
150 config_item->user_name); // TODO try to do this without callback