@@ -26,62 +26,50 @@ LocalComponents.Page {
2626 title: i18n.tr("Language")
2727 forwardButtonSourceComponent: forwardButton
2828
29− property string selectedLanguage: ""
30−
3129 UbuntuLanguagePlugin {
3230 id: plugin
3331 }
3432
3533 Component.onCompleted: {
36− populateModel(); // FIXME pass a list of detected languages here
34+ populateModel(["fr", "de"]); // FIXME pass a list of detected languages here
3735 }
3836
3937 function populateModel(detectedLangs)
4038 {
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− {
39+ var langs = LocalePlugin.languages();
5940 Object.keys(langs).map(function(code) { // prepare the object
60− return { "code": code, "name": langs[code] };
41+ //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") };
6144 })
62− .sort(function(a, b) { // sort by language name, not code
63− return a.name.localeCompare(b.name);
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
50+ }
51+ return 1
6452 })
65− .forEach(function(language) { // build the model
66− model.append(
67− { "language": language.name,
68− "code": language.code
69− }
70− );
53+ .forEach(function(lang) { // build the model
54+ if (lang.code === "C") {
55+ return;
56+ }
57+ model.append(lang);
7158 });
59+ busyIndicator.running = false;
60+ busyIndicator.visible = false;
7261 }
7362
7463 ActivityIndicator {
7564 id: busyIndicator;
7665
77− anchors.centerIn: parent;
66+ anchors.centerIn: column;
7867 running: true;
7968 }
8069
8170 Column {
8271 id: column
8372 anchors.fill: content
84− spacing: units.gu(1)
8573
8674 ListView {
8775 id: languagesListView;
@@ -89,18 +77,26 @@ LocalComponents.Page {
8977 boundsBehavior: Flickable.StopAtBounds;
9078 clip: true;
9179 currentIndex: -1
80+ snapMode: ListView.SnapToItem
9281
9382 anchors {
9483 left: parent.left;
9584 right: parent.right;
96− topMargin: topMargin;
9785 }
9886
99− height: column.height - column.spacing - topMargin
87+ height: column.height
10088
10189 section {
102− property: "language";
103− criteria: ViewSection.FirstCharacter;
90+ property: "dept";
91+ criteria: ViewSection.FullString;
92+ labelPositioning: ViewSection.InlineLabels | ViewSection.CurrentLabelAtStart
93+ delegate: Component {
94+ Label {
95+ text: section
96+ fontSize: "large"
97+ color: "black"
98+ }
99+ }
104100 }
105101
106102 model: ListModel {
@@ -113,6 +109,7 @@ LocalComponents.Page {
113109 readonly property bool isCurrent: index === ListView.view.currentIndex
114110
115111 Label {
112+ id: langLabel
116113 text: language;
117114
118115 anchors {
@@ -123,12 +120,25 @@ LocalComponents.Page {
123120
124121 fontSize: "medium"
125122 font.weight: itemDelegate.isCurrent ? Font.Normal : Font.Light
123+ color: "black" // FIXME proper color from the theme
124+ }
125+
126+ Image {
127+ anchors {
128+ right: parent.right;
129+ verticalCenter: parent.verticalCenter;
130+ }
131+ fillMode: Image.PreserveAspectFit
132+ height: langLabel.paintedHeight
133+
134+ source: "image://theme/select"
135+ visible: itemDelegate.isCurrent
126136 }
127137
128138 onClicked: {
129− selectedLanguage = code
139+ root.language = code
130140 ListView.view.currentIndex = index
131− print("Selected language: " + selectedLanguage)
141+ print("Selected language: " + root.language)
132142 print("Current index: " + ListView.view.currentIndex)
133143 }
134144 }
@@ -139,9 +149,9 @@ LocalComponents.Page {
139149 id: forwardButton
140150 LocalComponents.StackButton {
141151 text: i18n.tr("Next")
142− enabled: selectedLanguage !== ""
152+ enabled: root.language !== ""
143153 onClicked: {
144− if (selectedLanguage !== plugin.languageCodes[plugin.currentLanguage]) {
154+ if (root.language !== plugin.languageCodes[plugin.currentLanguage]) {
145155 //plugin.currentLanguage = listview.currentIndex; // setting system language by some magic index? wtf
146156 //System.updateSessionLanguage(selectedLanguage); // TODO
147157 i18n.language = i18n.language; // re-notify of change after above call (for qlocale change)