[gnome-maps] settings: Load settings if the app is not installed



commit a7353be3986fc3db657a2316f11a7c21af6e7f7f
Author: Damián Nohales <damiannohales gmail com>
Date:   Mon Dec 22 17:30:13 2014 -0300

    settings: Load settings if the app is not installed
    
    https://bugzilla.gnome.org/show_bug.cgi?id=733411

 src/application.js |    2 +-
 src/settings.js    |   31 +++++++++++++++++++++++++++++--
 2 files changed, 30 insertions(+), 3 deletions(-)
---
diff --git a/src/application.js b/src/application.js
index b59e87e..b9be224 100644
--- a/src/application.js
+++ b/src/application.js
@@ -139,7 +139,7 @@ const Application = new Lang.Class({
     },
 
     _initServices: function() {
-        settings       = new Settings.Settings('org.gnome.Maps');
+        settings       = Settings.getSettings('org.gnome.Maps');
         routeService   = new RouteService.GraphHopper();
         geoclue        = new Geoclue.Geoclue();
         geocodeService = new GeocodeService.GeocodeService();
diff --git a/src/settings.js b/src/settings.js
index 10d1221..29e0e91 100644
--- a/src/settings.js
+++ b/src/settings.js
@@ -23,6 +23,7 @@
 const GLib = imports.gi.GLib;
 const Gio = imports.gi.Gio;
 const Lang = imports.lang;
+const System = imports.system;
 
 const Settings = new Lang.Class({
     Name: "Settings",
@@ -31,8 +32,8 @@ const Settings = new Lang.Class({
     // The GVariant types of the settings
     _keyTypes: {},
 
-    _init: function(schema) {
-        this.parent({ schema_id: schema });
+    _init: function(params) {
+        this.parent(params);
         this.list_keys().forEach((function(key) {
             this._keyTypes[key] = this.get_value(key)
                                       .get_type()
@@ -48,3 +49,29 @@ const Settings = new Lang.Class({
         this.set_value(name, GLib.Variant.new (this._keyTypes[name], value));
     }
 });
+
+function getSettings(schemaId, path) {
+    const GioSSS = Gio.SettingsSchemaSource;
+    let schemaSource;
+
+    if (!pkg.moduledir.startsWith('resource://')) {
+        // Running from the source tree
+        schemaSource = GioSSS.new_from_directory(pkg.pkgdatadir,
+                                                 GioSSS.get_default(),
+                                                 false);
+    } else {
+        schemaSource = GioSSS.get_default();
+    }
+
+    let schemaObj = schemaSource.lookup(schemaId, true);
+    if (!schemaObj) {
+        log('Missing GSettings schema ' + schemaId);
+        System.exit(1);
+    }
+
+    if (path === undefined)
+        return new Settings({ settings_schema: schemaObj });
+    else
+        return new Settings({ settings_schema: schemaObj,
+                              path: path });
+}


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]