on xenial help sign in
address review comments
commit557267c84c3da234f173bf9a6aadce25ba9f6820 authorLukáš Tinkl <lukas.tinkl@canonical.com> dateTue 2 Aug 2016, 15:55 (10 years ago) parent60ac115
4 files changed+17−32
plugins/Wizard/keyboardLayoutsModel.cpp+10−18 plugins/Wizard/keyboardLayoutsModel.h+6−6 qml/Wizard/Pages/20-keyboard.qml−7 qml/Wizard/WizardItemSelector.qml+1−1
plugins/Wizard/keyboardLayoutsModel.cpp+10−18
@@ -17,17 +17,14 @@
1717#include <QDBusMetaType>
1818#include <QDebug>
1919
20+#define GNOME_DESKTOP_USE_UNSTABLE_API
21+#include <libgnome-desktop/gnome-xkb-info.h>
22+
2023#include "keyboardLayoutsModel.h"
2124
2225typedef QList<QMap<QString, QString>> StringMapList;
2326Q_DECLARE_METATYPE(StringMapList)
2427
25−struct KeyboardLayoutInfo {
26− QString id;
27− QString displayName;
28− QString language;
29−};
30−
3128KeyboardLayoutsModel::KeyboardLayoutsModel(QObject *parent)
3229 : QAbstractListModel(parent)
3330{
@@ -38,19 +35,11 @@ KeyboardLayoutsModel::KeyboardLayoutsModel(QObject *parent)
3835 };
3936
4037 qDBusRegisterMetaType<StringMapList>();
41− m_xkbInfo = gnome_xkb_info_new();
4238
4339 buildModel();
4440 connect(this, &KeyboardLayoutsModel::languageChanged, this, &KeyboardLayoutsModel::updateModel);
4541}
4642
47−KeyboardLayoutsModel::~KeyboardLayoutsModel()
48−{
49− if (m_xkbInfo != nullptr) {
50− g_object_unref(m_xkbInfo);
51− }
52−}
53−
5443QString KeyboardLayoutsModel::language() const
5544{
5645 return m_language;
@@ -91,13 +80,15 @@ void KeyboardLayoutsModel::buildModel()
9180 const gchar *xkb_layout;
9281 const gchar *xkb_variant;
9382
94− sources = gnome_xkb_info_get_all_layouts(m_xkbInfo);
83+ GnomeXkbInfo * xkbInfo(gnome_xkb_info_new());
84+
85+ sources = gnome_xkb_info_get_all_layouts(xkbInfo);
9586
9687 for (tmp = sources; tmp != NULL; tmp = tmp->next) {
97− gboolean result = gnome_xkb_info_get_layout_info(m_xkbInfo, (const gchar *)tmp->data,
88+ gboolean result = gnome_xkb_info_get_layout_info(xkbInfo, (const gchar *)tmp->data,
9889 &display_name, &short_name, &xkb_layout, &xkb_variant);
9990 if (!result) {
100− qWarning() << "!!! Skipping invalid layout";
91+ qWarning() << "Skipping invalid layout";
10192 continue;
10293 }
10394
@@ -109,6 +100,7 @@ void KeyboardLayoutsModel::buildModel()
109100 m_db.append(layout);
110101 }
111102 g_list_free(sources);
103+ g_object_unref(xkbInfo);
112104
113105 std::sort(m_db.begin(), m_db.end(), compareLayouts);
114106}
@@ -148,7 +140,7 @@ QVariant KeyboardLayoutsModel::data(const QModelIndex &index, int role) const
148140 return QVariant();
149141 }
150142
151− KeyboardLayoutInfo layout = m_layouts.at(row);
143+ const KeyboardLayoutInfo &layout = m_layouts.at(row);
152144
153145 switch (role) {
154146 case Qt::DisplayRole:
plugins/Wizard/keyboardLayoutsModel.h+6−6
@@ -19,10 +19,11 @@
1919
2020#include <QAbstractListModel>
2121
22−#define GNOME_DESKTOP_USE_UNSTABLE_API
23−#include <libgnome-desktop/gnome-xkb-info.h>
24−
25−struct KeyboardLayoutInfo;
22+struct KeyboardLayoutInfo {
23+ QString id;
24+ QString displayName;
25+ QString language;
26+};
2627
2728class KeyboardLayoutsModel: public QAbstractListModel
2829{
@@ -32,7 +33,7 @@ class KeyboardLayoutsModel: public QAbstractListModel
3233
3334public:
3435 explicit KeyboardLayoutsModel(QObject * parent = nullptr);
35− ~KeyboardLayoutsModel();
36+ ~KeyboardLayoutsModel() = default;
3637
3738 enum Roles {
3839 LayoutIdRole = Qt::UserRole + 1,
@@ -60,7 +61,6 @@ private:
6061 QHash<int, QByteArray> m_roleNames;
6162 QVector<KeyboardLayoutInfo> m_layouts;
6263 QVector<KeyboardLayoutInfo> m_db;
63− GnomeXkbInfo *m_xkbInfo = nullptr;
6464};
6565
6666#endif
qml/Wizard/Pages/20-keyboard.qml−7
@@ -48,14 +48,8 @@ LocalComponents.Page {
4848 Component.onCompleted: skipValid = true;
4949 }
5050
51− Component.onCompleted: print("Initial language:", i18n.language)
52−
5351 readonly property string selectedLanguage: langPlugin.languageCodes[langSelector.selectedIndex].split(".")[0] // chop off the codeset (.UTF-8)
5452
55− onSelectedLanguageChanged: {
56− print("Selected language:", selectedLanguage)
57− }
58−
5953 property string selectedKeymap: ""
6054
6155 Column {
@@ -157,7 +151,6 @@ LocalComponents.Page {
157151 text: keyboardListView.currentIndex != -1 ? i18n.tr("Next") : i18n.tr("Skip")
158152 onClicked: {
159153 if (keyboardListView.currentIndex != -1) {
160− print("Saving keymap:", selectedKeymap);
161154 AccountsService.keymaps = selectedKeymap;
162155 }
163156 pageStack.next();
qml/Wizard/WizardItemSelector.qml+1−1
@@ -25,7 +25,7 @@ Rectangle {
2525 property var model
2626 property int selectedIndex: -1
2727 readonly property double itemHeight: units.gu(4)
28− property int maxVisibleItems: 6
28+ readonly property int maxVisibleItems: 6
2929
3030 color: theme.palette.normal.foreground
3131 height: expanded ? maxVisibleItems * itemHeight : itemHeight