@@ -0,0 +1,153 @@
2+ * Copyright (C) 2013, 2015 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.2
19+import Ubuntu.SystemSettings.LanguagePlugin 1.0
21+import ".." as LocalComponents
23+LocalComponents.Page {
24+ objectName: "languagePage"
26+ title: i18n.tr("Language")
27+ forwardButtonSourceComponent: forwardButton
29+ property string selectedLanguage: ""
31+ UbuntuLanguagePlugin {
35+ Component.onCompleted: {
36+ populateModel(); // FIXME pass a list of detected languages here
39+ function populateModel(detectedLangs)
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);
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
60+ return { "code": code, "name": langs[code] };
62+ .sort(function(a, b) { // sort by language name, not code
63+ return a.name.localeCompare(b.name);
65+ .forEach(function(language) { // build the model
67+ { "language": language.name,
68+ "code": language.code
77+ anchors.centerIn: parent;
83+ anchors.fill: content
87+ id: languagesListView;
89+ boundsBehavior: Flickable.StopAtBounds;
96+ topMargin: topMargin;
99+ height: column.height - column.spacing - topMargin
102+ property: "language";
103+ criteria: ViewSection.FirstCharacter;
110+ delegate: ListItem {
113+ readonly property bool isCurrent: index === ListView.view.currentIndex
120+ right: parent.right;
121+ verticalCenter: parent.verticalCenter;
125+ font.weight: itemDelegate.isCurrent ? Font.Normal : Font.Light
129+ selectedLanguage = code
130+ ListView.view.currentIndex = index
131+ print("Selected language: " + selectedLanguage)
132+ print("Current index: " + ListView.view.currentIndex)
140+ LocalComponents.StackButton {
141+ text: i18n.tr("Next")
142+ enabled: selectedLanguage !== ""
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)