[rygel] core,ui: Error out if value not available in config
- From: Zeeshan Ali Khattak <zeeshanak src gnome org>
- To: svn-commits-list gnome org
- Subject: [rygel] core,ui: Error out if value not available in config
- Date: Fri, 12 Jun 2009 12:23:39 -0400 (EDT)
commit 640be66f01304c919768c4043ff4fae996826bc0
Author: Zeeshan Ali (Khattak) <zeeshanak gnome org>
Date: Tue Jun 9 17:48:57 2009 +0300
core,ui: Error out if value not available in config
src/rygel/rygel-configuration.vala | 22 ++++---
src/rygel/rygel-root-device-factory.vala | 8 ++-
src/rygel/rygel-user-config.vala | 97 +++++++++++++-----------------
src/ui/rygel-plugin-pref-section.vala | 9 +++-
4 files changed, 70 insertions(+), 66 deletions(-)
---
diff --git a/src/rygel/rygel-configuration.vala b/src/rygel/rygel-configuration.vala
index 3d370ce..6772e48 100644
--- a/src/rygel/rygel-configuration.vala
+++ b/src/rygel/rygel-configuration.vala
@@ -52,24 +52,26 @@ public interface Rygel.Configuration : GLib.Object {
public abstract string get_title (string section, string default_title);
- public abstract string? get_string (string section,
- string key,
- string? default_value);
+ public abstract string get_string (string section,
+ string key) throws GLib.Error;
- public abstract Gee.ArrayList<string> get_string_list (string section,
- string key);
+ public abstract Gee.ArrayList<string> get_string_list (
+ string section,
+ string key)
+ throws GLib.Error;
public abstract int get_int (string section,
string key,
int min,
- int max,
- int default_value);
+ int max)
+ throws GLib.Error;
public abstract Gee.ArrayList<int> get_int_list (string section,
- string key);
+ string key)
+ throws GLib.Error;
public abstract bool get_bool (string section,
- string key,
- bool default_value);
+ string key)
+ throws GLib.Error;
}
diff --git a/src/rygel/rygel-root-device-factory.vala b/src/rygel/rygel-root-device-factory.vala
index 0453004..b80cd93 100644
--- a/src/rygel/rygel-root-device-factory.vala
+++ b/src/rygel/rygel-root-device-factory.vala
@@ -151,7 +151,13 @@ public class Rygel.RootDeviceFactory {
return;
}
- var title = this.config.get_title (plugin_name, plugin_title);
+ string title;
+ try {
+ title = this.config.get_title (plugin_name);
+ } catch (GLib.Error err) {
+ title = plugin_title;
+ }
+
title = title.replace ("@REALNAME@", Environment.get_real_name ());
title = title.replace ("@USERNAME@", Environment.get_user_name ());
title = title.replace ("@HOSTNAME@", Environment.get_host_name ());
diff --git a/src/rygel/rygel-user-config.vala b/src/rygel/rygel-user-config.vala
index 6a9934e..9a56690 100644
--- a/src/rygel/rygel-user-config.vala
+++ b/src/rygel/rygel-user-config.vala
@@ -151,49 +151,45 @@ public class Rygel.UserConfig : GLib.Object, Configuration {
DBUS_INTERFACE);
}
- public bool get_enabled (string section) {
- return this.get_bool (section, ENABLED_KEY, true);
+ public bool get_enabled (string section) throws GLib.Error {
+ return this.get_bool (section, ENABLED_KEY);
}
- public string get_title (string section, string default_title) {
- return this.get_string (section, TITLE_KEY, default_title);
+ public string get_title (string section) throws GLib.Error {
+ return this.get_string (section, TITLE_KEY);
}
- public string? get_string (string section,
- string key,
- string? default_value) {
+ public string get_string (string section,
+ string key) throws GLib.Error {
string val;
var path = ROOT_GCONF_PATH + section + "/" + key;
- try {
- val = this.gconf.get_string (path);
- } catch (GLib.Error error) {
- val = null;
- }
+ val = this.gconf.get_string (path);
if (val == null || val == "") {
- val = default_value;
+ throw new ConfigurationError.NO_VALUE_SET (
+ "No value available for '%s'", key);
}
return val;
}
public Gee.ArrayList<string> get_string_list (string section,
- string key) {
+ string key)
+ throws GLib.Error {
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);
- }
+ 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);
+ } else {
+ throw new ConfigurationError.NO_VALUE_SET (
+ "No value available for '%s'", key);
}
return str_list;
@@ -202,60 +198,53 @@ public class Rygel.UserConfig : GLib.Object, Configuration {
public int get_int (string section,
string key,
int min,
- int max,
- int default_value) {
+ int max)
+ throws GLib.Error {
int val;
var path = ROOT_GCONF_PATH + section + "/" + key;
- try {
- val = this.gconf.get_int (path);
- } catch (GLib.Error error) {
- val = default_value;
- }
+ val = this.gconf.get_int (path);
if (val < min || val > max) {
- val = default_value;
+ throw new ConfigurationError.VALUE_OUT_OF_RANGE (
+ "Value of '%s' out of range", key);
}
return val;
}
public Gee.ArrayList<int> get_int_list (string section,
- string key) {
+ string key)
+ throws GLib.Error {
var int_list = new Gee.ArrayList<int> ();
var path = ROOT_GCONF_PATH + section + "/" + key;
- try {
- unowned SList<int> ints = this.gconf.get_list (
- path,
- GConf.ValueType.INT);
- if (ints != null) {
- foreach (var num in ints) {
- int_list.add (num);
- }
+ unowned SList<int> ints = this.gconf.get_list (path,
+ GConf.ValueType.INT);
+ if (ints != null) {
+ foreach (var num in ints) {
+ int_list.add (num);
}
- } catch (GLib.Error error) {
- warning ("Failed to get value for key: %s", path);
+ } else {
+ throw new ConfigurationError.NO_VALUE_SET (
+ "No value available for '%s'", key);
}
return int_list;
}
public bool get_bool (string section,
- string key,
- bool default_value) {
+ string key)
+ throws GLib.Error {
bool val;
var path = ROOT_GCONF_PATH + section + "/" + key;
- try {
- unowned GConf.Value value = this.gconf.get (path);
- if (value != null) {
- val = value.get_bool ();
- } else {
- val = default_value;
- }
- } catch (GLib.Error error) {
- val = default_value;
+ unowned GConf.Value value = this.gconf.get (path);
+ if (value != null) {
+ val = value.get_bool ();
+ } else {
+ throw new ConfigurationError.NO_VALUE_SET (
+ "No value available for '%s'", key);
}
return val;
diff --git a/src/ui/rygel-plugin-pref-section.vala b/src/ui/rygel-plugin-pref-section.vala
index ce597b6..729c89b 100644
--- a/src/ui/rygel-plugin-pref-section.vala
+++ b/src/ui/rygel-plugin-pref-section.vala
@@ -43,7 +43,14 @@ public class Rygel.PluginPrefSection : PreferencesSection {
this.enabled_check.active = config.get_enabled (name);
- var title = config.get_title (name, name).replace ("@REALNAME@", "%n");
+ string title;
+ try {
+ title = config.get_title (name);
+ } catch (GLib.Error err) {
+ title = name;
+ }
+
+ title = title.replace ("@REALNAME@", "%n");
title = title.replace ("@USERNAME@", "%u");
title = title.replace ("@HOSTNAME@", "%h");
this.title_entry.set_text (title);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]