on xenial help sign in
try to detect and preselect the language
1b99539Lukáš Tinkl
qml/Wizard/Pages/10-language.qml+41−28
@@ -26,50 +26,61 @@ LocalComponents.Page {
26 title: i18n.tr("Language")
26 title: i18n.tr("Language")
27 forwardButtonSourceComponent: forwardButton
27 forwardButtonSourceComponent: forwardButton
28
28
29+ property var detectedLangs: []
30+
29 UbuntuLanguagePlugin {
31 UbuntuLanguagePlugin {
30 id: plugin
32 id: plugin
31 }
33 }
32
34
33 Component.onCompleted: {
35 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"]);
35 }
38 }
36
39
37− function populateModel(detectedLangs)
40+ function populateModel(onlyDetected, detectedLangs)
38 {
41 {
42+ model.clear()
43+ var index = 0;
39 var langs = LocalePlugin.languages();
44 var langs = LocalePlugin.languages();
40 Object.keys(langs).map(function(code) { // prepare the object
45 Object.keys(langs).map(function(code) { // prepare the object
41 //console.log("Got language:" + code);
46 //console.log("Got language:" + code);
42− return { "code": code, "language": langs[code] || code,
47+
48+ if (onlyDetected) {
43− "dept": detectedLangs.indexOf(code) !== -1 ? i18n.tr("Detected") : i18n.tr("All") };
49+ if (!!detectedLangs && detectedLangs.indexOf(code) !== -1) {
44− })
50+ return { "code": code, "language": langs[code] || code }
45− .sort(function(a, b) { // group by status, sort by language name
51+ }
46− if (a.dept === b.dept) {
52+ } else {
47− return a.language.localeCompare(b.language);
53+ return { "code": code, "language": langs[code] || code }
48− } else if (a.dept === i18n.tr("Detected")) {
49− return -1
50 }
54 }
51− return 1
55+ return
56+ })
57+ .sort(function(a, b) { // sort by language name
58+ return a.language.localeCompare(b.language);
52 })
59 })
53 .forEach(function(lang) { // build the model
60 .forEach(function(lang) { // build the model
54 if (lang.code === "C") {
61 if (lang.code === "C") {
55 return;
62 return;
56 }
63 }
57 model.append(lang);
64 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++;
58 });
70 });
59− busyIndicator.running = false;
60− busyIndicator.visible = false;
61 }
71 }
62
72
63− ActivityIndicator {
73+ function selectLanguage(code, index)
64− id: busyIndicator;
74+ {
65−
75+ root.language = code
66− anchors.centerIn: column;
76+ languagesListView.currentIndex = index
67− running: true;
68 }
77 }
69
78
70 Column {
79 Column {
71 id: column
80 id: column
72 anchors.fill: content
81 anchors.fill: content
82+ anchors.bottomMargin: units.gu(1)
83+ spacing: units.gu(2)
73
84
74 ListView {
85 ListView {
75 id: languagesListView;
86 id: languagesListView;
@@ -84,16 +95,7 @@ LocalComponents.Page {
84 right: parent.right;
95 right: parent.right;
85 }
96 }
86
97
87− height: column.height
98+ height: column.height - column.spacing - (showAll.visible ? showAll.height : 0)
88−
89− section {
90− property: "dept";
91− criteria: ViewSection.FullString;
92− labelPositioning: ViewSection.InlineLabels | ViewSection.CurrentLabelAtStart
93− delegate: Label {
94− fontSize: "large"
95− }
96− }
97
99
98 model: ListModel {
100 model: ListModel {
99 id: model;
101 id: model;
@@ -139,6 +141,17 @@ LocalComponents.Page {
139 }
141 }
140 }
142 }
141 }
143 }
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+ }
142 }
155 }
143
156
144 Component {
157 Component {
qml/Wizard/Pages/20-sim.qml+1−1
@@ -1,5 +1,5 @@
1/*
1/*
2− * Copyright (C) 2013 Canonical, Ltd.
2+ * Copyright (C) 2013-2015 Canonical, Ltd.
3 *
3 *
4 * This program is free software; you can redistribute it and/or modify
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
5 * it under the terms of the GNU General Public License as published by