Add update of GenlistItem fields when text and description are changed
[profile/mobile/apps/native/accessibility-setting.git] / src / ActionPage.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 "ActionPage.hpp"
18
19 #include "AccessibilitySettingLog.hpp"
20 #include "Singleton.hpp"
21 #include "setting-accessibility.h"
22
23 #include <app.h>
24
25 ActionPage::ActionPage(NaviframeItem targetItem)
26         : context_(Singleton<AppContext>::instance())
27 {
28         setValuePage_ = std::make_unique<SetValuePage>(ValueEditorType::RADIOS, "IDS_ACCS_UNIVERSAL_SWITCH_SELECT_ACTION", targetItem);
29         setValuePage_->addRadioItemChangedCb([this](auto val) { this->actionChangedCb(val); });
30         for (auto i = 0u; i < context_.config.activity_types.size(); ++i)
31                 setValuePage_->addRadioItem(context_.config.activity_types[i]->name, i, false);
32 }
33
34 void ActionPage::actionChangedCb(size_t item_id)
35 {
36         if (item_id >= context_.config.activity_types.size()) {
37                 DEBUG("Unknown item id");
38                 return;
39         }
40
41         auto activity = context_.config.activity_types[item_id];
42         DEBUG("Selected activity type, id: %s, name: %s, description: %s",
43                 activity->id.c_str(),
44                 activity->name.c_str(),
45                 activity->description.c_str());
46         if (actionCb_)
47                 actionCb_(activity->id, actionCbData_);
48 }
49
50 void ActionPage::attachCallback(switch_action_cb cb, void *user_data)
51 {
52         actionCb_ = cb;
53         actionCbData_ = user_data;
54 }