on xenial help sign in
try to detect and preselect the language
commit1b99539601d1a6934ff57956ec212aa8989a7624 authorLukáš Tinkl <lukas.tinkl@canonical.com> dateWed 1 Jul 2015, 23:50 (11 years ago) parentf6e7e4f
2 files changed+42−29
qml/Wizard/Pages/10-language.qml+41−28 qml/Wizard/Pages/20-sim.qml+1−1
qml/Wizard/Pages/10-language.qml+41−28
@@ -26,50 +26,61 @@ LocalComponents.Page {
2626 title: i18n.tr("Language")
2727 forwardButtonSourceComponent: forwardButton
2828
29+ property var detectedLangs: []
30+
2931 UbuntuLanguagePlugin {
3032 id: plugin
3133 }
3234
3335 Component.onCompleted: {
34− populateModel(["fr", "de"]); // FIXME pass a list of detected languages here
36+ detectedLangs = ["fr", "de", "it"] // FIXME pass a list of detected languages here
37+ populateModel(detectedLangs.length > 0 ? true : false, detectedLangs.length > 0 ? detectedLangs : ["en"]);
3538 }
3639
37− function populateModel(detectedLangs)
40+ function populateModel(onlyDetected, detectedLangs)
3841 {
42+ model.clear()
43+ var index = 0;
3944 var langs = LocalePlugin.languages();
4045 Object.keys(langs).map(function(code) { // prepare the object
4146 //console.log("Got language:" + code);
42− return { "code": code, "language": langs[code] || code,
43− "dept": detectedLangs.indexOf(code) !== -1 ? i18n.tr("Detected") : i18n.tr("All") };
44− })
45− .sort(function(a, b) { // group by status, sort by language name
46− if (a.dept === b.dept) {
47− return a.language.localeCompare(b.language);
48− } else if (a.dept === i18n.tr("Detected")) {
49− return -1
47+
48+ if (onlyDetected) {
49+ if (!!detectedLangs && detectedLangs.indexOf(code) !== -1) {
50+ return { "code": code, "language": langs[code] || code }
51+ }
52+ } else {
53+ return { "code": code, "language": langs[code] || code }
5054 }
51− return 1
55+ return
56+ })
57+ .sort(function(a, b) { // sort by language name
58+ return a.language.localeCompare(b.language);
5259 })
5360 .forEach(function(lang) { // build the model
5461 if (lang.code === "C") {
5562 return;
5663 }
5764 model.append(lang);
65+ if (!onlyDetected && detectedLangs.length > 0 && lang.code === detectedLangs[0]) { // preselect the first of detected languages
66+ selectLanguage(lang.code, index)
67+ languagesListView.positionViewAtIndex(index, ListView.Beginning)
68+ }
69+ index++;
5870 });
59− busyIndicator.running = false;
60− busyIndicator.visible = false;
6171 }
6272
63− ActivityIndicator {
64− id: busyIndicator;
65−
66− anchors.centerIn: column;
67− running: true;
73+ function selectLanguage(code, index)
74+ {
75+ root.language = code
76+ languagesListView.currentIndex = index
6877 }
6978
7079 Column {
7180 id: column
7281 anchors.fill: content
82+ anchors.bottomMargin: units.gu(1)
83+ spacing: units.gu(2)
7384
7485 ListView {
7586 id: languagesListView;
@@ -84,16 +95,7 @@ LocalComponents.Page {
8495 right: parent.right;
8596 }
8697
87− height: column.height
88−
89− section {
90− property: "dept";
91− criteria: ViewSection.FullString;
92− labelPositioning: ViewSection.InlineLabels | ViewSection.CurrentLabelAtStart
93− delegate: Label {
94− fontSize: "large"
95− }
96− }
98+ height: column.height - column.spacing - (showAll.visible ? showAll.height : 0)
9799
98100 model: ListModel {
99101 id: model;
@@ -139,6 +141,17 @@ LocalComponents.Page {
139141 }
140142 }
141143 }
144+
145+ Button {
146+ id: showAll
147+ //anchors.horizontalCenter: parent.horizontalCenter
148+ text: i18n.tr("Show all languages...")
149+ visible: detectedLangs.length > 0
150+ onClicked: {
151+ populateModel(false, root.language !== "" ? [root.language] : ["en"]) // show all langs
152+ showAll.visible = false
153+ }
154+ }
142155 }
143156
144157 Component {
qml/Wizard/Pages/20-sim.qml+1−1
@@ -1,5 +1,5 @@
11/*
2− * Copyright (C) 2013 Canonical, Ltd.
2+ * Copyright (C) 2013-2015 Canonical, Ltd.
33 *
44 * This program is free software; you can redistribute it and/or modify
55 * it under the terms of the GNU General Public License as published by