Methods to get/set list of strings configuration
authorZeeshan Ali (Khattak) <zeeshanak@gnome.org>
Wed, 27 May 2009 14:54:02 +0000 (17:54 +0300)
committerZeeshan Ali (Khattak) <zeeshanak@gnome.org>
Wed, 27 May 2009 14:54:02 +0000 (17:54 +0300)
Provide convenience methods to get/set list of strings from configuration

src/rygel/rygel-configuration.vala

index b91ed28..b4f00df 100644 (file)
@@ -134,6 +134,27 @@ public class Rygel.Configuration {
         return val;
     }
 
+    public Gee.ArrayList<string> get_string_list (string section,
+                                                  string key) {
+        var str_list = new Gee.ArrayList<string> ();
+        var path = ROOT_GCONF_PATH + section + "/" + key;
+
+        try {
+            unowned SList<string> strings = this.gconf.get_list (
+                                                        path,
+                                                        GConf.ValueType.STRING);
+            if (strings != null) {
+                foreach (var str in strings) {
+                    str_list.add (str);
+                }
+            }
+        } catch (GLib.Error error) {
+            warning ("Failed to get value for key: %s\n", path);
+        }
+
+        return str_list;
+    }
+
     public int get_int (string section,
                         string key,
                         int    min,
@@ -187,6 +208,25 @@ public class Rygel.Configuration {
         }
     }
 
+    public void set_string_list (string                section,
+                                 string                key,
+                                 Gee.ArrayList<string> str_list) {
+        var path = ROOT_GCONF_PATH + section + "/" + key;
+
+        // GConf requires us to provide it GLib.SList
+        SList<string> slist = null;
+
+        foreach (var str in str_list) {
+            slist.append (str);
+        }
+
+        try {
+            this.gconf.set_list (path, GConf.ValueType.STRING, slist);
+        } catch (GLib.Error error) {
+            // No big deal
+        }
+    }
+
     public void set_int (string section,
                          string key,
                          int    value) {