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