Merge lp:~3v1n0/unity/lockscreen-accelerator-checks into lp:unity

Proposed by Marco Trevisan (Treviño)
Status: Merged
Approved by: Andrea Azzarone
Approved revision: no longer in the source branch.
Merged at revision: 4140
Proposed branch: lp:~3v1n0/unity/lockscreen-accelerator-checks
Merge into: lp:unity
Diff against target: 45 lines (+22/-0)
1 file modified
lockscreen/LockScreenAcceleratorController.cpp (+22/-0)
To merge this branch: bzr merge lp:~3v1n0/unity/lockscreen-accelerator-checks
Reviewer Review Type Date Requested Status
Andrea Azzarone (community) Approve
PS Jenkins bot continuous-integration Pending
Review via email: mp+298893@code.launchpad.net

Commit message

LockScreenAcceleratorController: check if a setting key is available instead of crashing

To post a comment you must log in.
Revision history for this message
Andrea Azzarone (azzar1) wrote :

+1

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'lockscreen/LockScreenAcceleratorController.cpp'
2--- lockscreen/LockScreenAcceleratorController.cpp 2016-06-21 11:20:05 +0000
3+++ lockscreen/LockScreenAcceleratorController.cpp 2016-07-01 12:56:44 +0000
4@@ -70,6 +70,22 @@
5 "XF86Touchpad",
6 };
7
8+bool IsSettingKeyAvailable(glib::Object<GSettings> const& settings, std::string const& key)
9+{
10+ bool available = false;
11+ GSettingsSchema* schema;
12+
13+ g_object_get(glib::object_cast<GObject>(settings), "settings-schema", &schema, nullptr);
14+
15+ if (schema)
16+ {
17+ available = g_settings_schema_has_key(schema, key.c_str());
18+ g_settings_schema_unref(schema);
19+ }
20+
21+ return available;
22+}
23+
24 bool IsKeyBindingAllowed(std::string const& key)
25 {
26 if (std::find(begin(ALLOWED_XF86_KEYS), end(ALLOWED_XF86_KEYS), key) != end(ALLOWED_XF86_KEYS))
27@@ -80,6 +96,9 @@
28
29 for (auto const& setting : ALLOWED_MEDIA_KEYS)
30 {
31+ if (!IsSettingKeyAvailable(media_settings, setting))
32+ continue;
33+
34 Accelerator media_key(glib::String(g_settings_get_string(media_settings, setting.c_str())).Str());
35 if (media_key == key_accelerator)
36 return true;
37@@ -89,6 +108,9 @@
38
39 for (auto const& setting : ALLOWED_WM_KEYS)
40 {
41+ if (!IsSettingKeyAvailable(wm_settings, setting))
42+ continue;
43+
44 glib::Variant accels(g_settings_get_value(wm_settings, setting.c_str()), glib::StealRef());
45 auto children = g_variant_n_children(accels);
46