@@ -0,0 +1,153 @@
1+/*
2+ * Copyright (C) 2013, 2015 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.3
18+import Ubuntu.Components 1.2
19+import Ubuntu.SystemSettings.LanguagePlugin 1.0
20+import Wizard 0.1
21+import ".." as LocalComponents
22+
23+LocalComponents.Page {
24+ objectName: "languagePage"
25+
26+ title: i18n.tr("Language")
27+ forwardButtonSourceComponent: forwardButton
28+
29+ property string selectedLanguage: ""
30+
31+ UbuntuLanguagePlugin {
32+ id: plugin
33+ }
34+
35+ Component.onCompleted: {
36+ populateModel(); // FIXME pass a list of detected languages here
37+ }
38+
39+ function populateModel(detectedLangs)
40+ {
41+ console.log("LanguagePage::populateModel: detected languages:" + detectedLangs);
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);
47+ });
48+ addLanguagesToModel(remainingLangs); // FIXME this assumes an array
49+ } else {
50+ addLanguagesToModel(allLangs);
51+ }
52+
53+ busyIndicator.running = false;
54+ busyIndicator.visible = false;
55+ }
56+
57+ function addLanguagesToModel(langs)
58+ {
59+ Object.keys(langs).map(function(code) { // prepare the object
60+ return { "code": code, "name": langs[code] };
61+ })
62+ .sort(function(a, b) { // sort by language name, not code
63+ return a.name.localeCompare(b.name);
64+ })
65+ .forEach(function(language) { // build the model
66+ model.append(
67+ { "language": language.name,
68+ "code": language.code
69+ }
70+ );
71+ });
72+ }
73+
74+ ActivityIndicator {
75+ id: busyIndicator;
76+
77+ anchors.centerIn: parent;
78+ running: true;
79+ }
80+
81+ Column {
82+ id: column
83+ anchors.fill: content
84+ spacing: units.gu(1)
85+
86+ ListView {
87+ id: languagesListView;
88+
89+ boundsBehavior: Flickable.StopAtBounds;
90+ clip: true;
91+ currentIndex: -1
92+
93+ anchors {
94+ left: parent.left;
95+ right: parent.right;
96+ topMargin: topMargin;
97+ }
98+
99+ height: column.height - column.spacing - topMargin
100+
101+ section {
102+ property: "language";
103+ criteria: ViewSection.FirstCharacter;
104+ }
105+
106+ model: ListModel {
107+ id: model;
108+ }
109+
110+ delegate: ListItem {
111+ id: itemDelegate;
112+
113+ readonly property bool isCurrent: index === ListView.view.currentIndex
114+
115+ Label {
116+ text: language;
117+
118+ anchors {
119+ left: parent.left;
120+ right: parent.right;
121+ verticalCenter: parent.verticalCenter;
122+ }
123+
124+ fontSize: "medium"
125+ font.weight: itemDelegate.isCurrent ? Font.Normal : Font.Light
126+ }
127+
128+ onClicked: {
129+ selectedLanguage = code
130+ ListView.view.currentIndex = index
131+ print("Selected language: " + selectedLanguage)
132+ print("Current index: " + ListView.view.currentIndex)
133+ }
134+ }
135+ }
136+ }
137+
138+ Component {
139+ id: forwardButton
140+ LocalComponents.StackButton {
141+ text: i18n.tr("Next")
142+ enabled: selectedLanguage !== ""
143+ onClicked: {
144+ if (selectedLanguage !== plugin.languageCodes[plugin.currentLanguage]) {
145+ //plugin.currentLanguage = listview.currentIndex; // setting system language by some magic index? wtf
146+ //System.updateSessionLanguage(selectedLanguage); // TODO
147+ i18n.language = i18n.language; // re-notify of change after above call (for qlocale change)
148+ }
149+ pageStack.next()
150+ }
151+ }
152+ }
153+}