on xenial help sign in
filtering based on language
commitafff8a88a091f2448c5d95b538634dafa7a78dd5 authorLukáš Tinkl <lukas.tinkl@canonical.com> dateWed 18 May 2016, 00:13 (10 years ago) parentc402237
5 files changed+88−44
plugins/Wizard/keyboardLayoutsModel.cpp+11−24 plugins/Wizard/keyboardLayoutsModel.h+1−2 qml/Wizard/Pages/10-welcome.qml+1 qml/Wizard/Pages/20-keyboard.qml+72−16 tests/mocks/Ubuntu/SystemSettings/LanguagePlugin/MockLanguagePlugin.qml+3−2
plugins/Wizard/keyboardLayoutsModel.cpp+11−24
@@ -25,8 +25,7 @@ Q_DECLARE_METATYPE(StringMapList)
2525struct KeyboardLayoutInfo {
2626 QString id;
2727 QString displayName;
28− QString shortName; // language
29− QString layoutAndVariant;
28+ QString language;
3029};
3130
3231KeyboardLayoutsModel::KeyboardLayoutsModel(QObject *parent)
@@ -35,8 +34,7 @@ KeyboardLayoutsModel::KeyboardLayoutsModel(QObject *parent)
3534 m_roleNames = {
3635 {LayoutIdRole, "layoutId"},
3736 {DisplayNameRole, "displayName"},
38− {ShortNameRole, "shortName"},
39− {LayoutAndVariantRole, "layoutAndVariant"}
37+ {LanguageRole, "language"}
4038 };
4139
4240 qDBusRegisterMetaType<StringMapList>();
@@ -73,8 +71,8 @@ static bool compareLayouts(const KeyboardLayoutInfo &layout0, const KeyboardLayo
7371 QString name1(layout1.displayName);
7472
7573 if (name0 == name1) {
76− name0 = layout0.shortName;
77− name1 = layout1.shortName;
74+ name0 = layout0.language;
75+ name1 = layout1.language;
7876
7977 if (name0 == name1) {
8078 name0 = layout0.id;
@@ -89,23 +87,15 @@ void KeyboardLayoutsModel::buildModel()
8987{
9088 beginResetModel();
9189
92−
9390 GList *sources, *tmp;
9491 const gchar *display_name;
9592 const gchar *short_name;
9693 const gchar *xkb_layout;
9794 const gchar *xkb_variant;
9895
99− if (m_language.isEmpty()) {
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− }
96+ sources = gnome_xkb_info_get_all_layouts(m_xkbInfo);
10497
10598 m_layouts.clear();
106− m_layouts.reserve(g_list_length(sources));
107−
108− qDebug() << "!!! Got" << m_layouts.count() << "layouts";
10999
110100 for (tmp = sources; tmp != NULL; tmp = tmp->next) {
111101 gboolean result = gnome_xkb_info_get_layout_info(m_xkbInfo, (const gchar *)tmp->data,
@@ -117,17 +107,16 @@ void KeyboardLayoutsModel::buildModel()
117107
118108 KeyboardLayoutInfo layout;
119109 layout.id = QString::fromUtf8((const gchar *)tmp->data);
120− layout.shortName = QString::fromUtf8(short_name);
110+ layout.language = QString::fromUtf8(short_name);
121111 layout.displayName = QString::fromUtf8(display_name);
122− layout.layoutAndVariant = QString::fromUtf8(g_strconcat(xkb_layout, "+", xkb_variant, NULL));
123112
124− if (!layout.shortName.isEmpty()) {
125− qDebug() << "!!! Appending layout with id:" << layout.id;
113+ if (layout.language.isEmpty() || layout.language == m_language) {
126114 m_layouts.append(layout);
115+ qDebug() << "Inserted layout:" << layout.id << ", language:" << layout.language;
127116 }
128−
129117 }
130118 g_list_free(sources);
119+
131120 std::sort(m_layouts.begin(), m_layouts.end(), compareLayouts);
132121
133122 endResetModel();
@@ -156,10 +145,8 @@ QVariant KeyboardLayoutsModel::data(const QModelIndex &index, int role) const
156145 return layout.displayName;
157146 case LayoutIdRole:
158147 return layout.id;
159− case ShortNameRole:
160− return layout.shortName;
161− case LayoutAndVariantRole:
162− return layout.layoutAndVariant;
148+ case LanguageRole:
149+ return layout.language;
163150 default: {
164151 qWarning() << Q_FUNC_INFO << "unsupported data role";
165152 return QVariant();
plugins/Wizard/keyboardLayoutsModel.h+1−2
@@ -37,8 +37,7 @@ public:
3737 enum Roles {
3838 LayoutIdRole = Qt::UserRole + 1,
3939 DisplayNameRole,
40− ShortNameRole,
41− LayoutAndVariantRole,
40+ LanguageRole
4241 };
4342
4443 QString language() const;
qml/Wizard/Pages/10-welcome.qml+1
@@ -160,6 +160,7 @@ LocalComponents.Page {
160160 var locale = plugin.languageCodes[languagesListView.currentIndex];
161161 var language = locale.split("_")[0].split(".")[0];
162162 plugin.currentLanguage = languagesListView.currentIndex;
163+ print("Setting current language to:", plugin.currentLanguage)
163164 oskPlugin.setCurrentLayout(language);
164165 System.updateSessionLocale(locale);
165166 }
qml/Wizard/Pages/20-keyboard.qml+72−16
@@ -15,8 +15,10 @@
1515 */
1616
1717import QtQuick 2.4
18+import QtQuick.Layouts 1.1
1819import Ubuntu.Components 1.3
1920import Ubuntu.Components.ListItems 1.3
21+import Ubuntu.SystemSettings.LanguagePlugin 1.0
2022import Wizard 0.1
2123import ".." as LocalComponents
2224
@@ -26,42 +28,96 @@ LocalComponents.Page {
2628 title: i18n.tr("Hardware Keyboard")
2729 forwardButtonSourceComponent: forwardButton
2830
31+ UbuntuLanguagePlugin {
32+ id: langPlugin
33+ }
34+
2935 KeyboardLayoutsModel {
30− id: allLayoutsModel
36+ id: layoutsModel
37+ language: selectedLanguage
38+ }
39+
40+ Component.onCompleted: print("Initial language:", i18n.language)
41+
42+ readonly property string selectedLanguage: langPlugin.languageCodes[langSelector.selectedIndex].split("_")[0].split(".")[0]
43+
44+ onSelectedLanguageChanged: {
45+ print("Selected language:", selectedLanguage)
3146 }
3247
33− ListView {
34− id: keyboardListView
35− clip: true
36− snapMode: ListView.SnapToItem
48+ ColumnLayout {
49+ id: column
50+ spacing: units.gu(2)
3751
3852 anchors {
3953 fill: content
4054 leftMargin: wideMode ? parent.leftMargin : 0
4155 rightMargin: wideMode ? parent.rightMargin : 0
4256 topMargin: wideMode ? parent.customMargin : 0
57+ bottomMargin: units.gu(2)
4358 }
4459
45− model: allLayoutsModel
60+ ItemSelector {
61+ id: langSelector
62+ anchors.left: parent.left
63+ anchors.right: parent.right
64+ text: i18n.tr("Keyboard Language")
65+ model: langPlugin.languageNames
66+ selectedIndex: langPlugin.languageCodes.indexOf(i18n.language)
67+ onSelectedIndexChanged: keyboardListView.currentIndex = -1
68+ }
69+
70+ ListView {
71+ Layout.fillHeight: true
72+ id: keyboardListView
73+ clip: true
74+ anchors.left: parent.left
75+ anchors.right: parent.right
76+ snapMode: ListView.SnapToItem
77+ model: layoutsModel
78+ currentIndex: -1
79+
80+ delegate: ListItem {
81+ id: itemDelegate
82+ objectName: "kbdDelegate" + index
83+ height: layout.height + (divider.visible ? divider.height : 0)
84+ readonly property bool isCurrent: index === ListView.view.currentIndex
4685
47− delegate: ListItem {
48− objectName: "kbdDelegate" + index
49− height: layout.height + (divider.visible ? divider.height : 0)
86+ ListItemLayout {
87+ id: layout
88+ title.text: displayName
89+ subtitle.text: layoutId
90+ Image {
91+ SlotsLayout.position: SlotsLayout.Trailing
92+ SlotsLayout.overrideVerticalPositioning: true
93+ fillMode: Image.PreserveAspectFit
94+ anchors.verticalCenter: parent.verticalCenter
95+ height: units.gu(1.5)
96+ source: "data/Tick@30.png"
97+ visible: itemDelegate.isCurrent
98+ }
99+ }
50100
51− ListItemLayout {
52− id: layout
53− title.text: displayName
54− subtitle.text: layoutId
55− CheckBox { SlotsLayout.position: SlotsLayout.Leading }
101+ onClicked: {
102+ keyboardListView.currentIndex = index;
103+ }
56104 }
57105 }
106+
107+ TextField {
108+ id: tester
109+ anchors.left: parent.left
110+ anchors.leftMargin: column.anchors.leftMargin == 0 ? units.gu(2) : 0
111+ anchors.right: parent.right
112+ anchors.rightMargin: column.anchors.rightMargin == 0 ? units.gu(2) : 0
113+ placeholderText: i18n.tr("Type here to test your keyboard")
114+ }
58115 }
59116
60117 Component {
61118 id: forwardButton
62119 LocalComponents.StackButton {
63− text: i18n.tr("Next")
64− enabled: true
120+ text: keyboardListView.currentIndex != -1 ? i18n.tr("Next") : i18n.tr("Skip")
65121 onClicked: pageStack.next();
66122 }
67123 }
tests/mocks/Ubuntu/SystemSettings/LanguagePlugin/MockLanguagePlugin.qml+3−2
@@ -17,7 +17,8 @@
1717import QtQuick 2.4
1818
1919Item {
20− property var languageNames: ["English (United States)", "French (France)", "Spanish (Spain)"]
21− property var languageCodes: ["en_US", "fr_FR", "es_ES"]
20+ property var languageNames: ["English (United States)", "French (France)", "Spanish (Spain)", "Spanish (Mexico)",
21+ "German (Switzerland)", "Czech (Czechia)"]
22+ property var languageCodes: ["en_US", "fr_FR", "es_ES", "es_MX", "de_CH", "cs_CZ"]
2223 property int currentLanguage: 0
2324}