Add update of GenlistItem fields when text and description are changed
[profile/mobile/apps/native/accessibility-setting.git] / src / CameraSwitchesPage.cpp
1 /*
2  * Copyright 2018 Samsung Electronics Co., Ltd
3  *
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
7  *
8  *  http://www.apache.org/licenses/LICENSE-2.0
9
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.
15  */
16
17 #include "CameraSwitchesPage.hpp"
18
19 #include "AccessibilitySettingLog.hpp"
20 #include "Button.hpp"
21 #include "Genlist.hpp"
22 #include "Singleton.hpp"
23 #include "setting-accessibility.h"
24
25 #include <app.h>
26
27 CameraSwitchesPage::CameraSwitchesPage(NaviframeItem targetItem)
28         : context_(Singleton<AppContext>::instance()), targetItem_(targetItem)
29 {
30         auto naviframe = context_.navContext_.getNaviframe();
31         auto genlist = Widget::make<Genlist>(naviframe);
32         genlist->setMode(ELM_LIST_COMPRESS);
33         genlist->setStyle("dialogue");
34         genlist->clear(); // TODO check if necessary
35
36         genlist->appendItem({"multiline", {}, "IDS_ACCS_UNIVERSAL_SWITCH_ADD_SWITCH_CAMERA_COMMENT", GenlistItem::Type::regular});
37         genlist->appendItem({"group_index", "IDS_ACCS_UNIVERSAL_SWITCH_ADD_SWITCH_CAMERA_GROUP_HEAD"});
38
39         auto switches = setting_accessibility_universal_switch_dbus_config_get_switches(
40                 &context_.config, ACCESSIBILITY_UNIVERSAL_SWITCH_CAMERA_SWITCH_PROVIDER);
41         for (auto &it : switches) {
42                 auto item = genlist->appendItem({"multiline", it->name, it->description, [=](auto item) {
43                                                                                          this->chosenSwitch_ = it;
44                                                                                          DEBUG("Camera switch, id: %s, name: %s",
45                                                                                                  this->chosenSwitch_->id.c_str(),
46                                                                                                  this->chosenSwitch_->name.c_str());
47                                                                                          this->actionPage_ = std::make_unique<ActionPage>(this->targetItem_);
48                                                                                          this->actionPage_->attachCallback(switchActionCb, this);
49                                                                                  }});
50
51                 for (auto &it2 : context_.config.configuration_items) {
52                         if (it->id == it2->switch_id)
53                                 item->disable();
54                 }
55         }
56
57         auto prevBtn = Widget::make<Button>(
58                 naviframe, [naviframe]() { naviframe->popBack(); }, std::string{}, Button::BACK_BUTTON_ARROW_STYLE);
59         naviframe->pushBack("IDS_ACCS_UNIVERSAL_SWITCH_ADD_SWITCH_CAMERA_TITLE", genlist, {}, prevBtn);
60 }
61
62 void CameraSwitchesPage::attachActionCallback(UniversalSwitchCb cb, void *cbData)
63 {
64         camera_switch_added_cb = cb;
65         camera_switch_added_cb_data = cbData;
66 }
67
68 void CameraSwitchesPage::switchActionCb(const std::string &action, void *user_data)
69 {
70         RETURN_IF(!user_data, "User data parameter is NULL");
71         auto self = static_cast<CameraSwitchesPage *>(user_data);
72
73         if (self->camera_switch_added_cb)
74                 self->camera_switch_added_cb(
75                         self->camera_switch_added_cb_data, self->chosenSwitch_->id, action, self->chosenSwitch_->name);
76         self->chosenSwitch_ = nullptr;
77 }