@@ -26,62 +26,50 @@ LocalComponents.Page {
26 title: i18n.tr("Language")
26 title: i18n.tr("Language")
27 forwardButtonSourceComponent: forwardButton
27 forwardButtonSourceComponent: forwardButton
29− property string selectedLanguage: ""
31 UbuntuLanguagePlugin {
29 UbuntuLanguagePlugin {
32 id: plugin
30 id: plugin
35 Component.onCompleted: {
33 Component.onCompleted: {
36− populateModel(); // FIXME pass a list of detected languages here
34+ populateModel(["fr", "de"]); // FIXME pass a list of detected languages here
39 function populateModel(detectedLangs)
37 function populateModel(detectedLangs)
41− console.log("LanguagePage::populateModel: detected languages:" + detectedLangs);
39+ var langs = LocalePlugin.languages();
42− var allLangs = LocalePlugin.languages();
43− if (!!detectedLangs) {
44− addLanguagesToModel(detectedLangs);
45− var remainingLangs = Object.keys(allLangs).filter(function(lang) {
46− return (detectedLangs.indexOf(lang) === -1);
48− addLanguagesToModel(remainingLangs); // FIXME this assumes an array
50− addLanguagesToModel(allLangs);
53− busyIndicator.running = false;
54− busyIndicator.visible = false;
57− function addLanguagesToModel(langs)
59 Object.keys(langs).map(function(code) { // prepare the object
40 Object.keys(langs).map(function(code) { // prepare the object
41+ //console.log("Got language:" + code);
60− return { "code": code, "name": langs[code] };
42+ return { "code": code, "language": langs[code] || code,
43+ "dept": detectedLangs.indexOf(code) !== -1 ? i18n.tr("Detected") : i18n.tr("All") };
62− .sort(function(a, b) { // sort by language name, not code
45+ .sort(function(a, b) { // group by status, sort by language name
46+ if (a.dept === b.dept) {
63− return a.name.localeCompare(b.name);
47+ return a.language.localeCompare(b.language);
48+ } else if (a.dept === i18n.tr("Detected")) {
65− .forEach(function(language) { // build the model
53+ .forEach(function(lang) { // build the model
66− model.append(
54+ if (lang.code === "C") {
67− { "language": language.name,
55+ return;
68− "code": language.code
70− );
57+ model.append(lang);
59+ busyIndicator.running = false;
60+ busyIndicator.visible = false;
74 ActivityIndicator {
63 ActivityIndicator {
75 id: busyIndicator;
64 id: busyIndicator;
77− anchors.centerIn: parent;
66+ anchors.centerIn: column;
78 running: true;
67 running: true;
82 id: column
71 id: column
83 anchors.fill: content
72 anchors.fill: content
86 ListView {
74 ListView {
87 id: languagesListView;
75 id: languagesListView;
@@ -89,18 +77,26 @@ LocalComponents.Page {
89 boundsBehavior: Flickable.StopAtBounds;
77 boundsBehavior: Flickable.StopAtBounds;
90 clip: true;
78 clip: true;
91 currentIndex: -1
79 currentIndex: -1
80+ snapMode: ListView.SnapToItem
94 left: parent.left;
83 left: parent.left;
95 right: parent.right;
84 right: parent.right;
96− topMargin: topMargin;
99− height: column.height - column.spacing - topMargin
87+ height: column.height
101 section {
89 section {
102− property: "language";
90+ property: "dept";
103− criteria: ViewSection.FirstCharacter;
91+ criteria: ViewSection.FullString;
92+ labelPositioning: ViewSection.InlineLabels | ViewSection.CurrentLabelAtStart
93+ delegate: Component {
106 model: ListModel {
102 model: ListModel {
@@ -113,6 +109,7 @@ LocalComponents.Page {
113 readonly property bool isCurrent: index === ListView.view.currentIndex
109 readonly property bool isCurrent: index === ListView.view.currentIndex
116 text: language;
113 text: language;
118 anchors {
115 anchors {
@@ -123,12 +120,25 @@ LocalComponents.Page {
124 fontSize: "medium"
121 fontSize: "medium"
125 font.weight: itemDelegate.isCurrent ? Font.Normal : Font.Light
122 font.weight: itemDelegate.isCurrent ? Font.Normal : Font.Light
123+ color: "black" // FIXME proper color from the theme
128+ right: parent.right;
129+ verticalCenter: parent.verticalCenter;
131+ fillMode: Image.PreserveAspectFit
132+ height: langLabel.paintedHeight
134+ source: "image://theme/select"
135+ visible: itemDelegate.isCurrent
128 onClicked: {
138 onClicked: {
129− selectedLanguage = code
139+ root.language = code
130 ListView.view.currentIndex = index
140 ListView.view.currentIndex = index
131− print("Selected language: " + selectedLanguage)
141+ print("Selected language: " + root.language)
132 print("Current index: " + ListView.view.currentIndex)
142 print("Current index: " + ListView.view.currentIndex)
@@ -139,9 +149,9 @@ LocalComponents.Page {
139 id: forwardButton
149 id: forwardButton
140 LocalComponents.StackButton {
150 LocalComponents.StackButton {
141 text: i18n.tr("Next")
151 text: i18n.tr("Next")
142− enabled: selectedLanguage !== ""
152+ enabled: root.language !== ""
143 onClicked: {
153 onClicked: {
144− if (selectedLanguage !== plugin.languageCodes[plugin.currentLanguage]) {
154+ if (root.language !== plugin.languageCodes[plugin.currentLanguage]) {
145 //plugin.currentLanguage = listview.currentIndex; // setting system language by some magic index? wtf
155 //plugin.currentLanguage = listview.currentIndex; // setting system language by some magic index? wtf
146 //System.updateSessionLanguage(selectedLanguage); // TODO
156 //System.updateSessionLanguage(selectedLanguage); // TODO
147 i18n.language = i18n.language; // re-notify of change after above call (for qlocale change)
157 i18n.language = i18n.language; // re-notify of change after above call (for qlocale change)