2 * Copyright (C) 2013-2016 Canonical, Ltd.
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.
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.
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/>.
18 import Ubuntu.Components 1.3
19 import Ubuntu.Components.ListItems 1.3
20 import Ubuntu.SystemSettings.LanguagePlugin 1.0
22 import ".." as LocalComponents
24 LocalComponents.Page {
25 objectName: "languagePage"
27 title: i18n.tr("Language")
28 forwardButtonSourceComponent: forwardButton
30 UbuntuLanguagePlugin {
34 OnScreenKeyboardPlugin {
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)
49 detectedLang = "en_US"; // fallback to default lang
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];
64 // splash screen (this has to be on the first page)
67 anchors.top: parent.top
68 anchors.left: parent.left
69 anchors.right: parent.right
71 source: wideMode ? "data/Desktop_splash_screen_bkg.png" : "data/Phone_splash_screen_bkg.png"
72 fillMode: Image.PreserveAspectCrop
75 Component.onCompleted: splashAnimation.start()
80 PauseAnimation { duration: UbuntuAnimation.BriskDuration }
85 duration: UbuntuAnimation.BriskDuration
99 snapMode: ListView.SnapToItem
103 leftMargin: wideMode ? parent.leftMargin : 0
104 rightMargin: wideMode ? parent.rightMargin : 0
105 topMargin: wideMode ? parent.customMargin : 0
108 model: plugin.languageNames
112 objectName: "languageDelegate" + index
113 highlightColor: backgroundColor
114 divider.colorFrom: dividerColor
115 divider.colorTo: backgroundColor
116 readonly property bool isCurrent: index === ListView.view.currentIndex
124 verticalCenter: parent.verticalCenter
125 leftMargin: languagesListView.anchors.leftMargin == 0 ? staticMargin : 0
129 font.weight: itemDelegate.isCurrent ? Font.Normal : Font.Light
136 verticalCenter: parent.verticalCenter;
137 rightMargin: languagesListView.anchors.rightMargin == 0 ? staticMargin : 0
139 fillMode: Image.PreserveAspectFit
140 height: units.gu(1.5)
142 source: "data/Tick@30.png"
143 visible: itemDelegate.isCurrent
147 languagesListView.currentIndex = index;
148 i18n.language = plugin.languageCodes[index];
155 LocalComponents.StackButton {
156 text: i18n.tr("Next")
157 enabled: languagesListView.currentIndex != -1
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);
166 i18n.language = plugin.languageCodes[plugin.currentLanguage]; // re-notify of change after above call (for qlocale change)
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
174 pageStack.load(Qt.resolvedUrl("sim.qml")); // show the SIM page