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  // splash screen (this has to be on the first page)
65  Image {
66  id: splashImage
67  anchors.top: parent.top
68  anchors.left: parent.left
69  anchors.right: parent.right
70  height: parent.height
71  source: wideMode ? "data/Desktop_splash_screen_bkg.png" : "data/Phone_splash_screen_bkg.png"
72  fillMode: Image.PreserveAspectCrop
73  z: 2
74  visible: opacity > 0
75  Component.onCompleted: splashAnimation.start()
76  }
77 
78  SequentialAnimation {
79  id: splashAnimation
80  PauseAnimation { duration: UbuntuAnimation.BriskDuration }
81  SmoothedAnimation {
82  target: splashImage
83  property: "height"
84  to: units.gu(16)
85  duration: UbuntuAnimation.BriskDuration
86  }
87  NumberAnimation {
88  target: splashImage
89  property: 'opacity'
90  from: 1
91  to: 0
92  }
93  onStopped: init();
94  }
95 
96  ListView {
97  id: languagesListView
98  clip: true
99  snapMode: ListView.SnapToItem
100 
101  anchors {
102  fill: content
103  leftMargin: wideMode ? parent.leftMargin : 0
104  rightMargin: wideMode ? parent.rightMargin : 0
105  topMargin: wideMode ? parent.customMargin : 0
106  }
107 
108  model: plugin.languageNames
109 
110  delegate: ListItem {
111  id: itemDelegate
112  objectName: "languageDelegate" + index
113  highlightColor: backgroundColor
114  divider.colorFrom: dividerColor
115  divider.colorTo: backgroundColor
116  readonly property bool isCurrent: index === ListView.view.currentIndex
117 
118  Label {
119  id: langLabel
120  text: modelData
121 
122  anchors {
123  left: parent.left
124  verticalCenter: parent.verticalCenter
125  leftMargin: languagesListView.anchors.leftMargin == 0 ? staticMargin : 0
126  }
127 
128  fontSize: "medium"
129  font.weight: itemDelegate.isCurrent ? Font.Normal : Font.Light
130  color: textColor
131  }
132 
133  Image {
134  anchors {
135  right: parent.right;
136  verticalCenter: parent.verticalCenter;
137  rightMargin: languagesListView.anchors.rightMargin == 0 ? staticMargin : 0
138  }
139  fillMode: Image.PreserveAspectFit
140  height: units.gu(1.5)
141 
142  source: "data/Tick@30.png"
143  visible: itemDelegate.isCurrent
144  }
145 
146  onClicked: {
147  languagesListView.currentIndex = index;
148  i18n.language = plugin.languageCodes[index];
149  }
150  }
151  }
152 
153  Component {
154  id: forwardButton
155  LocalComponents.StackButton {
156  text: i18n.tr("Next")
157  enabled: languagesListView.currentIndex != -1
158  onClicked: {
159  if (plugin.currentLanguage !== languagesListView.currentIndex) {
160  var locale = plugin.languageCodes[languagesListView.currentIndex];
161  var language = locale.split("_")[0].split(".")[0];
162  plugin.currentLanguage = languagesListView.currentIndex;
163  oskPlugin.setCurrentLayout(language);
164  System.updateSessionLocale(locale);
165  }
166  i18n.language = plugin.languageCodes[plugin.currentLanguage]; // re-notify of change after above call (for qlocale change)
167 
168  if (!root.modemManager.available || !root.modemManager.ready || root.modemManager.modems.length === 0 ||
169  (root.simManager0.present && root.simManager0.ready) || (root.simManager1.present && root.simManager1.ready) ||
170  root.seenSIMPage) { // go to next page
171  pageStack.next();
172  }
173  else {
174  pageStack.load(Qt.resolvedUrl("sim.qml")); // show the SIM page
175  }
176  }
177  }
178  }
179 }