Add update of GenlistItem fields when text and description are changed
[profile/mobile/apps/native/accessibility-setting.git] / src / ScreenReaderPage.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 "ScreenReaderPage.hpp"
18
19 #include "AccessibilitySettingLog.hpp"
20 #include "Genlist.hpp"
21 #include "Singleton.hpp"
22 #include "TextToSpeech.hpp"
23 #include "setting-accessibility.h"
24
25 #include <app.h>
26
27 ScreenReaderPage::ScreenReaderPage()
28         : context_(Singleton<AppContext>::instance())
29 {
30         auto genlist = Widget::make<Genlist>(context_.navContext_.getNaviframe());
31         genlist->setMode(ELM_LIST_COMPRESS);
32         genlist->setStyle("dialogue");
33         genlist->clear(); // TODO check if necessary
34
35         screenReaderItem_ = genlist->appendItem({"type1",
36                 "IDS_ST_MBODY_SCREEN_READER_HTTS",
37                 {},
38                 [this](auto item) {
39                         auto state = item->getState();
40                         Singleton<VConfInterface>::instance().set(VCONFKEY_SETAPPL_ACCESSIBILITY_TTS, state);
41                         if (!state) {
42                                 auto buf = TranslatedString{"IDS_ST_MBODY_SCREEN_READER_HTTS"} + " " + TranslatedString{"IDS_ST_BODY_OFF"};
43                                 Singleton<TextToSpeech>::instance().play(buf.str());
44                         }
45                 },
46                 GenlistItem::WidgetType::toggle});
47
48         auto onVConfValueChangeCb = [this](bool screenReaderState) {
49                 screenReaderItem_->setState(screenReaderState);
50                 screenReaderItem_->setDescription(screenReaderState ? "IDS_ST_BODY_ON" : "IDS_ST_BODY_OFF");
51         };
52         screenReaderStateHandle_ = Singleton<VConfInterface>::instance().registerAndGet<bool>({VCONFKEY_SETAPPL_ACCESSIBILITY_TTS}, false, onVConfValueChangeCb);
53
54         genlist->appendItem({"multiline", {}, "IDS_ACCS_BODY_WHILE_SCREEN_READER_IS_ENABLED_YOUR_PHONE_WILL_PROVIDE_VOICE_FEEDBACK_FOR_EXAMPLE_SCREEN_READER_WILL_MSG"});
55
56         genlist->appendItem({"type1",
57                 "IDS_ST_OPT_SETTINGS",
58                 {},
59                 [this](auto item) {
60                         this->screenReaderSettingsPage_ = std::make_unique<ScreenReaderSettingsPage>();
61                 }});
62
63         context_.navContext_.getNaviframe()->pushBack("IDS_ST_MBODY_SCREEN_READER_HTTS", genlist, [this]() {
64                 screenReaderStateHandle_ = {};
65         });
66 }