Add update of GenlistItem fields when text and description are changed
[profile/mobile/apps/native/accessibility-setting.git] / src / ScreenSwitchPage.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 "ScreenSwitchPage.hpp"
18
19 #include "AccessibilitySettingLog.hpp"
20 #include "Singleton.hpp"
21 #include "setting-accessibility.h"
22
23 ScreenSwitchPage::ScreenSwitchPage(NaviframeItem targetItem)
24         : context_(Singleton<AppContext>::instance())
25 {
26         actionPage_ = std::make_unique<ActionPage>(targetItem);
27         actionPage_->attachCallback(actionCb, this);
28 }
29
30 void ScreenSwitchPage::attachActionCallback(UniversalSwitchCb cb, void *cbData)
31 {
32         switch_added_cb = cb;
33         switch_added_cb_data = cbData;
34 }
35
36 void ScreenSwitchPage::actionCb(const std::string &action, void *user_data)
37 {
38         auto self = static_cast<ScreenSwitchPage *>(user_data);
39
40         if (self->switch_added_cb) {
41                 auto switches = setting_accessibility_universal_switch_dbus_config_get_switches(
42                         &self->context_.config, ACCESSIBILITY_UNIVERSAL_SWITCH_SCREEN_SWITCH_PROVIDER);
43                 ASSERT(!switches.empty(), "Screen switch not found");
44                 auto screen_switch = switches[0];
45                 self->switch_added_cb(self->switch_added_cb_data, screen_switch->id, action, ACCESSIBILITY_UNIVERSAL_SWITCH_SCREEN);
46         }
47 }