Lomiri
Loading...
Searching...
No Matches
10-welcome.qml
1/*
2 * Copyright (C) 2018 The UBports project
3 * Copyright (C) 2013-2016 Canonical Ltd.
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; version 3.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program. If not, see <http://www.gnu.org/licenses/>.
16 */
17
18import QtQuick 2.12
19import Lomiri.Components 1.3
20import Lomiri.Components.ListItems 1.3
21import Lomiri.SystemSettings.LanguagePlugin 1.0
22import Wizard 0.1
23import ".." as LocalComponents
24import "../../Components"
25
26LocalComponents.Page {
27 objectName: "languagePage"
28
29 title: i18n.tr("Language")
30 forwardButtonSourceComponent: forwardButton
31 hasBackButton: false
32 onlyOnInstall: true
33
34 LomiriLanguagePlugin {
35 id: plugin
36 }
37
38 OnScreenKeyboardPlugin {
39 id: oskPlugin
40 }
41
42 function init()
43 {
44 var detectedLang = "";
45 // try to detect the language+country from the SIM card
46 if (root.simManager0.present && root.simManager0.preferredLanguages.length > 0) {
47 detectedLang = root.simManager0.preferredLanguages[0] + "_" + LocalePlugin.mccToCountryCode(root.simManager0.mobileCountryCode);
48 } else if (root.simManager1.present && root.simManager1.preferredLanguages.length > 0) {
49 detectedLang = root.simManager1.preferredLanguages[0] + "_" + LocalePlugin.mccToCountryCode(root.simManager1.mobileCountryCode);
50 } else if (plugin.currentLanguage != -1) {
51 detectedLang = plugin.languageCodes[plugin.currentLanguage].split(".")[0]; // remove the encoding part, after dot (en_US.utf8 -> en_US)
52 } else {
53 detectedLang = "en_US"; // fallback to default lang
54 }
55
56 // preselect the detected language
57 for (var i = 0; i < plugin.languageCodes.length; i++) {
58 var code = plugin.languageCodes[i].split(".")[0]; // remove the encoding part, after dot (en_US.utf8 -> en_US)
59 if (detectedLang === code) {
60 languagesListView.currentIndex = i;
61 languagesListView.positionViewAtIndex(i, ListView.Center);
62 i18n.language = plugin.languageCodes[i];
63 break;
64 }
65 }
66 }
67
68 function applyOSKSettings(locale) {
69 var language = locale.split("_")[0].split(".")[0];
70 var oskLanguage = language;
71
72 if (language === "zh") { // special case for Chinese, select either simplified or traditional
73 if (locale.substr(0, 5) === "zh_CN" || locale.substr(0,5) === "zh_SG") {
74 oskLanguage = "zh-hans"; // Chinese Simplified
75 } else {
76 oskLanguage = "zh-hant"; // Chinese Traditional
77 }
78 }
79
80 oskPlugin.setCurrentLayout(oskLanguage);
81 }
82
83 // splash screen (this has to be on the first page)
84 Image {
85 id: splashImage
86 anchors.top: parent.top
87 anchors.left: parent.left
88 anchors.right: parent.right
89 height: parent.height
90 source: wideMode ? "data/Desktop_splash_screen_bkg.png" : "data/Phone_splash_screen_bkg.png"
91 fillMode: Image.PreserveAspectCrop
92 z: 2
93 visible: opacity > 0
94 Component.onCompleted: splashAnimation.start()
95 }
96
97 SequentialAnimation {
98 id: splashAnimation
99 PauseAnimation { duration: LomiriAnimation.BriskDuration }
100 SmoothedAnimation {
101 target: splashImage
102 property: "height"
103 to: units.gu(16)
104 duration: LomiriAnimation.BriskDuration
105 }
106 NumberAnimation {
107 target: splashImage
108 property: 'opacity'
109 from: 1
110 to: 0
111 }
112 onStopped: init();
113 }
114
115 ListView {
116 id: languagesListView
117 objectName: "languagesListView"
118 clip: true
119 snapMode: ListView.SnapToItem
120
121 anchors {
122 fill: content
123 leftMargin: wideMode ? parent.leftMargin : 0
124 rightMargin: wideMode ? parent.rightMargin : 0
125 topMargin: wideMode ? parent.customMargin : 0
126 }
127
128 model: plugin.languageNames
129
130 delegate: ListItem {
131 id: itemDelegate
132 objectName: "languageDelegate_" + langLabel.text.toLowerCase().replace(/\s+/g, '_')
133 highlightColor: backgroundColor
134 divider.colorFrom: dividerColor
135 divider.colorTo: backgroundColor
136 readonly property bool isCurrent: index === ListView.view.currentIndex
137
138 Label {
139 id: langLabel
140 text: modelData
141
142 anchors {
143 left: parent.left
144 verticalCenter: parent.verticalCenter
145 leftMargin: languagesListView.anchors.leftMargin == 0 ? staticMargin : 0
146 }
147
148 fontSize: "medium"
149 font.weight: itemDelegate.isCurrent ? Font.Normal : Font.Light
150 color: textColor
151 }
152
153 Image {
154 anchors {
155 right: parent.right;
156 verticalCenter: parent.verticalCenter;
157 rightMargin: languagesListView.anchors.rightMargin == 0 ? staticMargin : 0
158 }
159 fillMode: Image.PreserveAspectFit
160 height: units.gu(1.5)
161
162 source: "data/Tick@30.png"
163 visible: itemDelegate.isCurrent
164 }
165
166 onClicked: {
167 languagesListView.currentIndex = index;
168 i18n.language = plugin.languageCodes[index];
169 }
170 }
171 }
172
173 Component {
174 id: forwardButton
175 LocalComponents.StackButton {
176 text: i18n.tr("Next")
177 enabled: languagesListView.currentIndex != -1
178 onClicked: {
179 if (plugin.currentLanguage !== languagesListView.currentIndex) {
180 var locale = plugin.languageCodes[languagesListView.currentIndex];
181 plugin.currentLanguage = languagesListView.currentIndex;
182 applyOSKSettings(locale);
183 System.updateSessionLocale(locale);
184 }
185 i18n.language = plugin.languageCodes[plugin.currentLanguage]; // re-notify of change after above call (for qlocale change)
186
187 if (!root.modemManager.available || !root.modemManager.ready || root.modemManager.modems.length === 0 ||
188 (root.simManager0.present && root.simManager0.ready) || (root.simManager1.present && root.simManager1.ready) ||
189 root.seenSIMPage) { // go to next page
190 pageStack.next();
191 } else {
192 pageStack.load(Qt.resolvedUrl("sim.qml")); // show the SIM page
193 }
194 }
195 }
196 }
197}