on xenial help sign in
migrate keymap settings
commit5ff1efc69a61a13bf95c9466f40c0231118ee821 authorLukáš Tinkl <lukas.tinkl@canonical.com> dateMon 27 Jun 2016, 14:01 (10 years ago) parentb1a901b
4 files changed+31−2
plugins/AccountsService/AccountsService.cpp+25 plugins/AccountsService/AccountsService.h+3 plugins/AccountsService/CMakeLists.txt+2−2 qml/Components/KeymapSwitcher.qml+1
plugins/AccountsService/AccountsService.cpp+25
@@ -21,8 +21,10 @@
2121#include <QFile>
2222#include <QStringList>
2323#include <QDebug>
24+#include <QSettings>
2425
2526#include <glib.h>
27+#include <gio/gio.h> // for gsettings
2628
2729#define IFACE_ACCOUNTS_USER QStringLiteral("org.freedesktop.Accounts.User")
2830#define IFACE_LOCATION_HERE QStringLiteral("com.ubuntu.location.providers.here.AccountsService")
@@ -284,6 +286,29 @@ QStringList AccountsService::keymaps() const
284286 return {QStringLiteral("us")};
285287}
286288
289+void AccountsService::migrateKeymapSettings()
290+{
291+ QSettings settings;
292+ if (!settings.value(QStringLiteral("KeymapsMigrated")).toBool()) {
293+ auto value = getProperty(IFACE_ACCOUNTS_USER, PROP_INPUT_SOURCES);
294+ QDBusArgument arg = value.value<QDBusArgument>();
295+ StringMapList maps = qdbus_cast<StringMapList>(arg);
296+
297+ // Save the config settings (for the keyboard indicator)
298+ GSettings * sourcesSettings = g_settings_new("org.gnome.desktop.input-sources");
299+ GVariantBuilder builder;
300+ g_variant_builder_init(&builder, G_VARIANT_TYPE("a(ss)"));
301+ Q_FOREACH(const auto & keymapPair, maps) {
302+ g_variant_builder_add(&builder, "(ss)", keymapPair.firstKey().toUtf8().constData(),
303+ keymapPair.first().toUtf8().constData());
304+ }
305+ g_settings_set_value(sourcesSettings, "sources", g_variant_builder_end(&builder));
306+ g_object_unref(sourcesSettings);
307+
308+ settings.setValue(QStringLiteral("KeymapsMigrated"), true);
309+ }
310+}
311+
287312uint AccountsService::failedFingerprintLogins() const
288313{
289314 return getProperty(IFACE_UNITY_PRIVATE, PROP_FAILED_FINGERPRINT_LOGINS).toUInt();
plugins/AccountsService/AccountsService.h+3
@@ -118,6 +118,9 @@ public:
118118 void setEmail(const QString &email);
119119 QStringList keymaps() const;
120120
121+public Q_SLOTS:
122+ Q_INVOKABLE void migrateKeymapSettings();
123+
121124Q_SIGNALS:
122125 void userChanged();
123126 void demoEdgesChanged();
plugins/AccountsService/CMakeLists.txt+2−2
@@ -1,5 +1,5 @@
11add_definitions(-DSM_BUSNAME=systemBus)
2−include_directories(${GLIB_INCLUDE_DIRS})
2+include_directories(${GLIB_INCLUDE_DIRS} ${GIO_INCLUDE_DIRS})
33
44add_library(AccountsService-qml MODULE
55 AccountsService.cpp
@@ -10,7 +10,7 @@ add_library(AccountsService-qml MODULE
1010qt5_use_modules(AccountsService-qml DBus Qml)
1111
1212target_link_libraries(AccountsService-qml
13− ${GLIB_LIBRARIES}
13+ ${GLIB_LIBRARIES} ${GIO_LDFLAGS}
1414 )
1515
1616add_unity8_plugin(AccountsService 0.1 AccountsService TARGETS AccountsService-qml)
qml/Components/KeymapSwitcher.qml+1
@@ -108,6 +108,7 @@ Item {
108108 onKeymapCountChanged: updateIndicatorVisibility();
109109
110110 Component.onCompleted: {
111+ AccountsService.migrateKeymapSettings();
111112 updateIndicatorVisibility();
112113 }
113114}