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