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.15
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 // Skip language autodetection when upgrading, since user probably want
45 // to retain the current language.
46 // Preferably this page shouldn't have to be loaded in that case, but at
47 // the moment it still has to be loaded, to determine `onlyOnInstall`
48 // property above.
49 if (System.isUpdate)
50 return;
51
52 var detectedLang = "";
53 // try to detect the language+country from the SIM card
54 if (root.simManager0.present && root.simManager0.preferredLanguages.length > 0) {
55 detectedLang = root.simManager0.preferredLanguages[0] + "_" + LocalePlugin.mccToCountryCode(root.simManager0.mobileCountryCode);
56 } else if (root.simManager1.present && root.simManager1.preferredLanguages.length > 0) {
57 detectedLang = root.simManager1.preferredLanguages[0] + "_" + LocalePlugin.mccToCountryCode(root.simManager1.mobileCountryCode);
58 } else if (plugin.currentLanguage != -1) {
59 detectedLang = plugin.languageCodes[plugin.currentLanguage].split(".")[0]; // remove the encoding part, after dot (en_US.utf8 -> en_US)
60 } else {
61 detectedLang = "en_US"; // fallback to default lang
62 }
63
64 // preselect the detected language
65 for (var i = 0; i < plugin.languageCodes.length; i++) {
66 var code = plugin.languageCodes[i].split(".")[0]; // remove the encoding part, after dot (en_US.utf8 -> en_US)
67 if (detectedLang === code) {
68 languagesListView.currentIndex = i;
69 languagesListView.positionViewAtIndex(i, ListView.Center);
70 i18n.language = plugin.languageCodes[i];
71 break;
72 }
73 }
74 }
75
76 function applyOSKSettings(locale) {
77 var language = locale.split("_")[0].split(".")[0];
78 var oskLanguage = language;
79
80 if (language === "zh") { // special case for Chinese, select either simplified or traditional
81 if (locale.substr(0, 5) === "zh_CN" || locale.substr(0,5) === "zh_SG") {
82 oskLanguage = "zh-hans"; // Chinese Simplified
83 } else {
84 oskLanguage = "zh-hant"; // Chinese Traditional
85 }
86 }
87
88 oskPlugin.setCurrentLayout(oskLanguage);
89 }
90
91 // splash screen (this has to be on the first page)
92 Image {
93 id: splashImage
94 anchors.top: parent.top
95 anchors.left: parent.left
96 anchors.right: parent.right
97 height: parent.height
98 source: wideMode ? "data/Desktop_splash_screen_bkg.png" : "data/Phone_splash_screen_bkg.png"
99 fillMode: Image.PreserveAspectCrop
100 z: 2
101 visible: opacity > 0
102 Component.onCompleted: splashAnimation.start()
103 }
104
105 SequentialAnimation {
106 id: splashAnimation
107 PauseAnimation { duration: LomiriAnimation.BriskDuration }
108 SmoothedAnimation {
109 target: splashImage
110 property: "height"
111 to: units.gu(16)
112 duration: LomiriAnimation.BriskDuration
113 }
114 NumberAnimation {
115 target: splashImage
116 property: 'opacity'
117 from: 1
118 to: 0
119 }
120 onStopped: init();
121 }
122
123 ListView {
124 id: languagesListView
125 objectName: "languagesListView"
126 clip: true
127 snapMode: ListView.SnapToItem
128
129 anchors {
130 fill: content
131 leftMargin: wideMode ? parent.leftMargin : 0
132 rightMargin: wideMode ? parent.rightMargin : 0
133 topMargin: wideMode ? parent.customMargin : 0
134 }
135
136 model: plugin.languageNames
137
138 delegate: ListItem {
139 id: itemDelegate
140 objectName: "languageDelegate_" + langLabel.text.toLowerCase().replace(/\s+/g, '_')
141 highlightColor: backgroundColor
142 divider.colorFrom: dividerColor
143 divider.colorTo: backgroundColor
144 readonly property bool isCurrent: index === ListView.view.currentIndex
145
146 Label {
147 id: langLabel
148 text: modelData
149
150 anchors {
151 left: parent.left
152 verticalCenter: parent.verticalCenter
153 leftMargin: languagesListView.anchors.leftMargin == 0 ? staticMargin : 0
154 }
155
156 fontSize: "medium"
157 font.weight: itemDelegate.isCurrent ? Font.Normal : Font.Light
158 color: textColor
159 }
160
161 Image {
162 anchors {
163 right: parent.right;
164 verticalCenter: parent.verticalCenter;
165 rightMargin: languagesListView.anchors.rightMargin == 0 ? staticMargin : 0
166 }
167 fillMode: Image.PreserveAspectFit
168 height: units.gu(1.5)
169
170 source: "data/Tick@30.png"
171 visible: itemDelegate.isCurrent
172 }
173
174 onClicked: {
175 languagesListView.currentIndex = index;
176 i18n.language = plugin.languageCodes[index];
177 }
178 }
179 }
180
181 Component {
182 id: forwardButton
183 LocalComponents.StackButton {
184 text: i18n.tr("Next")
185 enabled: languagesListView.currentIndex != -1
186 onClicked: {
187 if (plugin.currentLanguage !== languagesListView.currentIndex) {
188 var locale = plugin.languageCodes[languagesListView.currentIndex];
189 plugin.currentLanguage = languagesListView.currentIndex;
190 applyOSKSettings(locale);
191 System.updateSessionLocale(locale);
192 }
193 i18n.language = plugin.languageCodes[plugin.currentLanguage]; // re-notify of change after above call (for qlocale change)
194
195 if (!root.modemManager.available || !root.modemManager.ready || root.modemManager.modems.length === 0 ||
196 (root.simManager0.present && root.simManager0.ready) || (root.simManager1.present && root.simManager1.ready) ||
197 root.seenSIMPage) { // go to next page
198 pageStack.next();
199 } else {
200 pageStack.load(Qt.resolvedUrl("sim.qml")); // show the SIM page
201 }
202 }
203 }
204 }
205}