core,ui: Diff between read-only and writable config
authorZeeshan Ali (Khattak) <zeeshanak@gnome.org>
Wed, 24 Jun 2009 21:20:47 +0000 (00:20 +0300)
committerZeeshan Ali (Khattak) <zeeshanak@gnome.org>
Fri, 3 Jul 2009 21:44:58 +0000 (00:44 +0300)
read-only: Reads config from system-installed config file as well and
           doesn't support saving of changes.
writable:  Reads config only from user's config file and supports saving
           of changes.

src/rygel/rygel-user-config.vala
src/ui/rygel-preferences-dialog.vala

index 25f6a9c..da681d8 100644 (file)
@@ -123,12 +123,15 @@ public class Rygel.UserConfig : GLib.Object, Configuration {
         return config;
     }
 
-    public UserConfig () throws Error {
+    public UserConfig (bool read_only=true) throws Error {
         this.key_file = new KeyFile ();
 
         var dirs = new string[2];
         dirs[0] = Environment.get_user_config_dir ();
-        dirs[1] = BuildConfig.SYS_CONFIG_DIR;
+        if (!read_only) {
+            // We only write to user config
+            dirs[1] = BuildConfig.SYS_CONFIG_DIR;
+        }
 
         this.key_file.load_from_dirs (CONFIG_FILE,
                                       dirs,
@@ -136,6 +139,9 @@ public class Rygel.UserConfig : GLib.Object, Configuration {
                                       KeyFileFlags.KEEP_COMMENTS |
                                       KeyFileFlags.KEEP_TRANSLATIONS);
         debug ("Loaded user configuration from file '%s'", this.path);
+        if (read_only) {
+            this.path = null; // No need to keep the path around
+        }
 
         DBus.Connection connection = DBus.Bus.get (DBus.BusType.SESSION);
 
@@ -150,6 +156,8 @@ public class Rygel.UserConfig : GLib.Object, Configuration {
     }
 
     public void save () {
+        return_if_fail (this.path != null);
+
         size_t length;
         var data = this.key_file.to_data (out length);
 
index 22019c1..c53edeb 100644 (file)
@@ -34,7 +34,7 @@ public class Rygel.PreferencesDialog : GLib.Object {
     ArrayList<PreferencesSection> sections;
 
     public PreferencesDialog () throws Error {
-        this.config = new UserConfig ();
+        this.config = new UserConfig (false);
         this.builder = new Builder ();
 
         this.builder.add_from_file (UI_FILE);