Bug 1356718 - Query gtk settings schemas to avoid crashing when schema is missing. r=jfkthame
MozReview-Commit-ID: 2rqO4XpLbfO
--- a/intl/locale/gtk/OSPreferences_gtk.cpp
+++ b/intl/locale/gtk/OSPreferences_gtk.cpp
@@ -56,17 +56,30 @@ HourCycle()
if (env && strcmp(env, "Unity") == 0) {
schema = "com.canonical.indicator.datetime";
key = "time-format";
} else {
schema = "org.gnome.desktop.interface";
key = "clock-format";
}
- GSettings* settings = g_settings_new(schema);
+ // This is a workaround for old GTK versions.
+ // Once we bump the minimum version to 2.40 we should replace
+ // this with g_settings_schme_source_lookup.
+ // See bug 1356718 for details.
+ const char* const* schemas = g_settings_list_schemas();
+ GSettings* settings = nullptr;
+
+ for (uint32_t i = 0; schemas[i] != nullptr; i++) {
+ if (strcmp(schemas[i], schema) == 0) {
+ settings = g_settings_new(schema);
+ break;
+ }
+ }
+
if (settings) {
// We really want to use g_settings_get_user_value which will
// only want to take it if user manually changed the value.
// But this requires glib 2.40, and we still support older glib versions,
// so we have to check whether it's available and fall back to the older
// g_settings_get_value if not.
static get_value_fn_t sGetValueFunction = FindGetValueFunction();
GVariant* value = sGetValueFunction(settings, key);