[rygel] core: Configuration is now an interface
- From: Zeeshan Ali Khattak <zeeshanak src gnome org>
- To: svn-commits-list gnome org
- Subject: [rygel] core: Configuration is now an interface
- Date: Fri, 12 Jun 2009 12:23:24 -0400 (EDT)
commit 7f852d0f6167ee3040c661bd17d00c9290d9d3a9
Author: Zeeshan Ali (Khattak) <zeeshanak gnome org>
Date: Mon Jun 8 18:37:29 2009 +0300
core: Configuration is now an interface
src/rygel/rygel-configuration.vala | 339 +++---------------------------------
1 files changed, 25 insertions(+), 314 deletions(-)
---
diff --git a/src/rygel/rygel-configuration.vala b/src/rygel/rygel-configuration.vala
index ebbe846..5c86a09 100644
--- a/src/rygel/rygel-configuration.vala
+++ b/src/rygel/rygel-configuration.vala
@@ -26,334 +26,45 @@ using GConf;
using CStuff;
/**
- * Reads the user configuration for Rygel.
+ * Interface for dealing with Rygel configuration.
*/
-public class Rygel.Configuration : GLib.Object {
- protected static const string ROOT_GCONF_PATH = "/apps/rygel/";
- protected static const string IP_KEY = "host-ip";
- protected static const string PORT_KEY = "port";
- protected static const string ENABLED_KEY = "enabled";
- protected static const string TITLE_KEY = "title";
- protected static const string TRANSCODING_KEY = "enable-transcoding";
- protected static const string MP3_TRANSCODER_KEY = "enable-mp3-transcoder";
- protected static const string MP2TS_TRANSCODER_KEY =
- "enable-mp2ts-transcoder";
- protected static const string LPCM_TRANSCODER_KEY =
- "enable-lpcm-transcoder";
+public interface Rygel.Configuration : GLib.Object {
+ public abstract bool upnp_enabled { get; set; }
- private const string DBUS_SERVICE = "org.freedesktop.DBus";
- private const string DBUS_PATH = "/org/freedesktop/DBus";
- private const string DBUS_INTERFACE = "org.freedesktop.DBus";
+ public abstract string host_ip { get; set; }
- private const string RYGEL_SERVICE = "org.gnome.Rygel";
- private const string RYGEL_PATH = "/org/gnome/Rygel";
- private const string RYGEL_INTERFACE = "org.gnome.Rygel";
+ public abstract int port { get; set; }
- // Our singleton
- private static Configuration config;
+ public abstract bool transcoding { get; set; }
- protected GConf.Client gconf;
+ public abstract bool mp3_transcoder { get; set; }
- private dynamic DBus.Object dbus_obj;
- private dynamic DBus.Object rygel_obj;
+ public abstract bool mp2ts_transcoder { get; set; }
- public bool upnp_enabled {
- get {
- return this.get_bool ("general", ENABLED_KEY, true);
- }
- set {
- if (value != this.upnp_enabled) {
- this.enable_upnp (value);
- }
- }
- }
+ public abstract bool lpcm_transcoder { get; set; }
- private string _host_ip;
- public string host_ip {
- get {
- _host_ip = this.get_string ("general", IP_KEY, null);
- return _host_ip;
- }
- set {
- this.set_string ("general", IP_KEY, value);
- }
- }
+ public abstract bool get_enabled (string section);
- public int port {
- get {
- return this.get_int ("general",
- PORT_KEY,
- uint16.MIN,
- uint16.MAX,
- 0);
- }
- set {
- this.set_int ("general", PORT_KEY, value);
- }
- }
+ public abstract string get_title (string section, string default_title);
- public bool transcoding {
- get {
- return this.get_bool ("general", TRANSCODING_KEY, true);
- }
- set {
- this.set_bool ("general", TRANSCODING_KEY, value);
- }
- }
-
- public bool mp3_transcoder {
- get {
- return this.get_bool ("general", MP3_TRANSCODER_KEY, true);
- }
- set {
- this.set_bool ("general", MP3_TRANSCODER_KEY, value);
- }
- }
-
- public bool mp2ts_transcoder {
- get {
- return this.get_bool ("general", MP2TS_TRANSCODER_KEY, true);
- }
- set {
- this.set_bool ("general", MP2TS_TRANSCODER_KEY, value);
- }
- }
-
- public bool lpcm_transcoder {
- get {
- return this.get_bool ("general", LPCM_TRANSCODER_KEY, true);
- }
- set {
- this.set_bool ("general", LPCM_TRANSCODER_KEY, value);
- }
- }
-
- public static Configuration get_default () {
- if (config == null) {
- config = new Configuration ();
- }
-
- return config;
- }
-
- public Configuration () {
- this.gconf = GConf.Client.get_default ();
-
- DBus.Connection connection = DBus.Bus.get (DBus.BusType.SESSION);
-
- // Create proxy to Rygel
- this.rygel_obj = connection.get_object (RYGEL_SERVICE,
- RYGEL_PATH,
- RYGEL_INTERFACE);
- // and DBus
- this.dbus_obj = connection.get_object (DBUS_SERVICE,
- DBUS_PATH,
- DBUS_INTERFACE);
- }
-
- public bool get_enabled (string section) {
- return this.get_bool (section, ENABLED_KEY, true);
- }
-
- public string get_title (string section, string default_title) {
- return this.get_string (section, TITLE_KEY, default_title);
- }
-
- public string? get_string (string section,
+ public abstract string? get_string (string section,
string key,
- string? default_value) {
- string val;
- var path = ROOT_GCONF_PATH + section + "/" + key;
-
- try {
- val = this.gconf.get_string (path);
- } catch (GLib.Error error) {
- val = null;
- }
-
- if (val == null || val == "") {
- val = default_value;
- }
-
- 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,
- int max,
- int default_value) {
- int val;
- var path = ROOT_GCONF_PATH + section + "/" + key;
-
- try {
- val = this.gconf.get_int (path);
- } catch (GLib.Error error) {
- val = default_value;
- }
-
- if (val < min || val > max) {
- val = default_value;
- }
-
- return val;
- }
-
- public Gee.ArrayList<int> get_int_list (string section,
- string key) {
- 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);
- }
- }
- } catch (GLib.Error error) {
- warning ("Failed to get value for key: %s", path);
- }
-
- return int_list;
- }
-
- public bool get_bool (string section,
- string key,
- bool default_value) {
- 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;
- }
-
- return val;
- }
-
- public void set_string (string section,
- string key,
- string value) {
- var path = ROOT_GCONF_PATH + section + "/" + key;
-
- try {
- this.gconf.set_string (path, value);
- } catch (GLib.Error error) {
- // No big deal
- }
- }
-
- 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) {
- if (str != "") {
- 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) {
- var path = ROOT_GCONF_PATH + section + "/" + key;
-
- try {
- this.gconf.set_int (path, value);
- } catch (GLib.Error error) {
- // No big deal
- }
- }
-
- public void set_bool (string section,
- string key,
- bool value) {
- var path = ROOT_GCONF_PATH + section + "/" + key;
-
- try {
- this.gconf.set_bool (path, value);
- } catch (GLib.Error error) {
- // No big deal
- }
- }
-
- private void enable_upnp (bool enable) {
- var dest_path = Path.build_filename (Environment.get_user_config_dir (),
- "autostart",
- "rygel.desktop");
- var dest = File.new_for_path (dest_path);
-
- try {
- if (enable) {
- uint32 res;
-
- // Start service first
- this.dbus_obj.StartServiceByName (RYGEL_SERVICE,
- (uint32) 0,
- out res);
+ string? default_value);
- // Then symlink the desktop file to user's autostart dir
- var source_path = Path.build_filename (
- BuildConfig.DESKTOP_DIR,
- "rygel.desktop");
- dest.make_symbolic_link (source_path, null);
+ public abstract Gee.ArrayList<string> get_string_list (string section,
+ string key);
- this.set_bool ("general", ENABLED_KEY, true);
- } else {
- // Stop service first
- this.rygel_obj.Shutdown ();
+ public abstract int get_int (string section,
+ string key,
+ int min,
+ int max,
+ int default_value);
- // Then delete the symlink from user's autostart dir
- dest.delete (null);
+ public abstract Gee.ArrayList<int> get_int_list (string section,
+ string key);
- this.set_bool ("general", ENABLED_KEY, false);
- }
- } catch (DBus.Error err) {
- warning ("Failed to %s Rygel service: %s\n",
- enable? "start": "stop",
- err.message);
- }
- }
+ public abstract bool get_bool (string section,
+ string key,
+ bool default_value);
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]