on xenial help sign in
add a sample page
c402237Lukáš Tinkl
plugins/Wizard/keyboardLayoutsModel.cpp+31−23
@@ -89,38 +89,46 @@ void KeyboardLayoutsModel::buildModel()
89{
89{
90 beginResetModel();
90 beginResetModel();
91
91
92+
93+ GList *sources, *tmp;
94+ const gchar *display_name;
95+ const gchar *short_name;
96+ const gchar *xkb_layout;
97+ const gchar *xkb_variant;
98+
92 if (m_language.isEmpty()) {
99 if (m_language.isEmpty()) {
93− GList *sources, *tmp;
94− const gchar *display_name;
95− const gchar *short_name;
96− const gchar *xkb_layout;
97− const gchar *xkb_variant;
98 sources = gnome_xkb_info_get_all_layouts(m_xkbInfo);
100 sources = gnome_xkb_info_get_all_layouts(m_xkbInfo);
101+ } else {
102+ sources = gnome_xkb_info_get_layouts_for_language(m_xkbInfo, m_language.toUtf8().constData());
103+ }
99
104
100− m_layouts.clear();
105+ m_layouts.clear();
101− m_layouts.reserve(g_list_length(sources));
106+ m_layouts.reserve(g_list_length(sources));
102
107
103− for (tmp = sources; tmp != NULL; tmp = tmp->next) {
108+ qDebug() << "!!! Got" << m_layouts.count() << "layouts";
104− gnome_xkb_info_get_layout_info(m_xkbInfo, (const gchar *)tmp->data,
105− &display_name, &short_name, &xkb_layout, &xkb_variant);
106
109
107− KeyboardLayoutInfo layout;
110+ for (tmp = sources; tmp != NULL; tmp = tmp->next) {
108− layout.id = QString::fromUtf8((const gchar *)tmp->data);
111+ gboolean result = gnome_xkb_info_get_layout_info(m_xkbInfo, (const gchar *)tmp->data,
109− layout.shortName = QString::fromUtf8(short_name);
112+ &display_name, &short_name, &xkb_layout, &xkb_variant);
110− layout.displayName = QString::fromUtf8(display_name);
113+ if (!result) {
111− layout.layoutAndVariant = QString::fromUtf8(g_strconcat(xkb_layout, "+", xkb_variant, NULL));
114+ qWarning() << "!!! Skipping invalid layout";
115+ continue;
116+ }
112
117
118+ KeyboardLayoutInfo layout;
119+ layout.id = QString::fromUtf8((const gchar *)tmp->data);
113− if (!layout.shortName.isEmpty()) {
120+ layout.shortName = QString::fromUtf8(short_name);
114− qDebug() << "Appending layout with id:" << layout.id;
121+ layout.displayName = QString::fromUtf8(display_name);
115− m_layouts.append(layout);
122+ layout.layoutAndVariant = QString::fromUtf8(g_strconcat(xkb_layout, "+", xkb_variant, NULL));
116− }
117
123
124+ if (!layout.shortName.isEmpty()) {
125+ qDebug() << "!!! Appending layout with id:" << layout.id;
126+ m_layouts.append(layout);
118 }
127 }
119− g_list_free(sources);
128+
120− std::sort(m_layouts.begin(), m_layouts.end(), compareLayouts);
121− } else {
122− // TODO
123 }
129 }
130+ g_list_free(sources);
131+ std::sort(m_layouts.begin(), m_layouts.end(), compareLayouts);
124
132
125 endResetModel();
133 endResetModel();
126}
134}
qml/Wizard/Pages/20-keyboard.qmlnew file+68
@@ -0,0 +1,68 @@
1+/*
2+ * Copyright (C) 2016 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.4
18+import Ubuntu.Components 1.3
19+import Ubuntu.Components.ListItems 1.3
20+import Wizard 0.1
21+import ".." as LocalComponents
22+
23+LocalComponents.Page {
24+ objectName: "keyboardPage"
25+
26+ title: i18n.tr("Hardware Keyboard")
27+ forwardButtonSourceComponent: forwardButton
28+
29+ KeyboardLayoutsModel {
30+ id: allLayoutsModel
31+ }
32+
33+ ListView {
34+ id: keyboardListView
35+ clip: true
36+ snapMode: ListView.SnapToItem
37+
38+ anchors {
39+ fill: content
40+ leftMargin: wideMode ? parent.leftMargin : 0
41+ rightMargin: wideMode ? parent.rightMargin : 0
42+ topMargin: wideMode ? parent.customMargin : 0
43+ }
44+
45+ model: allLayoutsModel
46+
47+ delegate: ListItem {
48+ objectName: "kbdDelegate" + index
49+ height: layout.height + (divider.visible ? divider.height : 0)
50+
51+ ListItemLayout {
52+ id: layout
53+ title.text: displayName
54+ subtitle.text: layoutId
55+ CheckBox { SlotsLayout.position: SlotsLayout.Leading }
56+ }
57+ }
58+ }
59+
60+ Component {
61+ id: forwardButton
62+ LocalComponents.StackButton {
63+ text: i18n.tr("Next")
64+ enabled: true
65+ onClicked: pageStack.next();
66+ }
67+ }
68+}
tests/mocks/Wizard/Wizard.qmltypesdeleted−37
@@ -1,37 +0,0 @@
1−import QtQuick.tooling 1.1
2−
3−// This file describes the plugin-supplied types contained in the library.
4−// It is used for QML tooling purposes only.
5−//
6−// This file was auto-generated by:
7−// 'qmlplugindump -notrelocatable Wizard 0.1 tests/mocks'
8−
9−Module {
10− Component {
11− name: "MockSystem"
12− prototype: "QObject"
13− exports: ["Wizard/System 0.1"]
14− isCreatable: false
15− isSingleton: true
16− exportMetaObjectRevisions: [0]
17− Property { name: "wizardEnabled"; type: "bool" }
18− Signal {
19− name: "updateSessionLanguageCalled"
20− Parameter { name: "locale"; type: "string" }
21− }
22− Method {
23− name: "updateSessionLanguage"
24− Parameter { name: "locale"; type: "string" }
25− }
26− }
27− Component {
28− name: "PageList"
29− prototype: "QObject"
30− exports: ["Wizard/PageList 0.1"]
31− exportMetaObjectRevisions: [0]
32− Property { name: "index"; type: "int"; isReadonly: true }
33− Property { name: "numPages"; type: "int"; isReadonly: true }
34− Method { name: "prev"; type: "string" }
35− Method { name: "next"; type: "string" }
36− }
37−}