[rygel] core,ui: Turn Configuration props into getter/setter
- From: Zeeshan Ali Khattak <zeeshanak src gnome org>
- To: svn-commits-list gnome org
- Subject: [rygel] core,ui: Turn Configuration props into getter/setter
- Date: Fri, 12 Jun 2009 12:23:44 -0400 (EDT)
commit 388fa88a1029b10634d1f2845aff7d0e9dc37130
Author: Zeeshan Ali (Khattak) <zeeshanak gnome org>
Date: Tue Jun 9 17:49:38 2009 +0300
core,ui: Turn Configuration props into getter/setter
This is mainly to allow for throwing errors from getters.
src/rygel/rygel-configuration.vala | 18 +++---
src/rygel/rygel-content-directory.vala | 10 +++-
src/rygel/rygel-http-server.vala | 2 +-
src/rygel/rygel-root-device-factory.vala | 4 +-
src/rygel/rygel-transcode-manager.vala | 10 ++--
src/rygel/rygel-user-config.vala | 99 +++++++++++++-----------------
src/ui/rygel-general-pref-section.vala | 35 ++++++-----
7 files changed, 88 insertions(+), 90 deletions(-)
---
diff --git a/src/rygel/rygel-configuration.vala b/src/rygel/rygel-configuration.vala
index 6772e48..d8faa29 100644
--- a/src/rygel/rygel-configuration.vala
+++ b/src/rygel/rygel-configuration.vala
@@ -34,23 +34,23 @@ public errordomain Rygel.ConfigurationError {
* Interface for dealing with Rygel configuration.
*/
public interface Rygel.Configuration : GLib.Object {
- public abstract bool upnp_enabled { get; set; }
+ public abstract bool get_upnp_enabled () throws GLib.Error;
- public abstract string host_ip { get; set; }
+ public abstract string get_host_ip () throws GLib.Error;
- public abstract int port { get; set; }
+ public abstract int get_port () throws GLib.Error;
- public abstract bool transcoding { get; set; }
+ public abstract bool get_transcoding () throws GLib.Error;
- public abstract bool mp3_transcoder { get; set; }
+ public abstract bool get_mp3_transcoder () throws GLib.Error;
- public abstract bool mp2ts_transcoder { get; set; }
+ public abstract bool get_mp2ts_transcoder () throws GLib.Error;
- public abstract bool lpcm_transcoder { get; set; }
+ public abstract bool get_lpcm_transcoder () throws GLib.Error;
- public abstract bool get_enabled (string section);
+ public abstract bool get_enabled (string section) throws GLib.Error;
- public abstract string get_title (string section, string default_title);
+ public abstract string get_title (string section) throws GLib.Error;
public abstract string get_string (string section,
string key) throws GLib.Error;
diff --git a/src/rygel/rygel-content-directory.vala b/src/rygel/rygel-content-directory.vala
index c61fd01..2faa80f 100644
--- a/src/rygel/rygel-content-directory.vala
+++ b/src/rygel/rygel-content-directory.vala
@@ -70,7 +70,15 @@ public class Rygel.ContentDirectory: Service {
this.cancellable = new Cancellable ();
this.root_container = this.create_root_container ();
- this.http_server = new HTTPServer (this, this.get_type ().name ());
+
+ try {
+ this.http_server = new HTTPServer (this, this.get_type ().name ());
+ } catch (GLib.Error err) {
+ critical ("Failed to create HTTP server for %s: %s",
+ this.get_type ().name (),
+ err.message);
+ return;
+ }
this.browses = new ArrayList<Browse> ();
this.updated_containers = new ArrayList<MediaContainer> ();
diff --git a/src/rygel/rygel-http-server.vala b/src/rygel/rygel-http-server.vala
index 5501b62..af7e1f7 100644
--- a/src/rygel/rygel-http-server.vala
+++ b/src/rygel/rygel-http-server.vala
@@ -38,7 +38,7 @@ internal class Rygel.HTTPServer : Rygel.TranscodeManager, Rygel.StateMachine {
private Cancellable cancellable;
public HTTPServer (ContentDirectory content_dir,
- string name) {
+ string name) throws GLib.Error {
base ();
this.root_container = content_dir.root_container;
diff --git a/src/rygel/rygel-root-device-factory.vala b/src/rygel/rygel-root-device-factory.vala
index b80cd93..edb99fa 100644
--- a/src/rygel/rygel-root-device-factory.vala
+++ b/src/rygel/rygel-root-device-factory.vala
@@ -100,8 +100,8 @@ public class Rygel.RootDeviceFactory {
private GUPnP.Context create_upnp_context () throws GLib.Error {
GUPnP.Context context = new GUPnP.Context (null,
- this.config.host_ip,
- this.config.port);
+ this.config.get_host_ip (),
+ this.config.get_port ());
/* Host UPnP dir */
context.host_path (BuildConfig.DATA_DIR, "");
diff --git a/src/rygel/rygel-transcode-manager.vala b/src/rygel/rygel-transcode-manager.vala
index 4ac7006..47e5319 100644
--- a/src/rygel/rygel-transcode-manager.vala
+++ b/src/rygel/rygel-transcode-manager.vala
@@ -34,19 +34,19 @@ using Gst;
internal abstract class Rygel.TranscodeManager : GLib.Object {
private ArrayList<Transcoder> transcoders;
- public TranscodeManager () {
+ public TranscodeManager () throws GLib.Error {
transcoders = new ArrayList<Transcoder> ();
var config = UserConfig.get_default ();
- if (config.transcoding) {
- if (config.lpcm_transcoder) {
+ if (config.get_transcoding ()) {
+ if (config.get_lpcm_transcoder ()) {
transcoders.add (new L16Transcoder (Endianness.BIG));
}
- if (config.mp3_transcoder) {
+ if (config.get_mp3_transcoder ()) {
transcoders.add (new MP3Transcoder (MP3Layer.THREE));
}
- if (config.mp2ts_transcoder) {
+ if (config.get_mp2ts_transcoder ()) {
transcoders.add (new MP2TSTranscoder(MP2TSProfile.SD));
transcoders.add (new MP2TSTranscoder(MP2TSProfile.HD));
}
diff --git a/src/rygel/rygel-user-config.vala b/src/rygel/rygel-user-config.vala
index 9a56690..7f2a736 100644
--- a/src/rygel/rygel-user-config.vala
+++ b/src/rygel/rygel-user-config.vala
@@ -57,75 +57,62 @@ public class Rygel.UserConfig : GLib.Object, Configuration {
private dynamic DBus.Object dbus_obj;
private dynamic DBus.Object rygel_obj;
- public bool upnp_enabled {
- get {
- return this.get_bool ("general", ENABLED_KEY, true);
- }
- set {
- if (value != this.upnp_enabled) {
- this.enable_upnp (value);
- }
- }
+ public bool get_upnp_enabled () throws GLib.Error {
+ return this.get_bool ("general", ENABLED_KEY);
}
- 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 void set_upnp_enabled (bool value) {
+ if (value != this.get_upnp_enabled ()) {
+ this.enable_upnp (value);
}
}
- 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 string get_host_ip () throws GLib.Error {
+ return this.get_string ("general", IP_KEY);
}
- public bool transcoding {
- get {
- return this.get_bool ("general", TRANSCODING_KEY, true);
- }
- set {
- this.set_bool ("general", TRANSCODING_KEY, value);
- }
+ public void set_host_ip (string value) {
+ this.set_string ("general", IP_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 int get_port () throws GLib.Error {
+ return this.get_int ("general", PORT_KEY, uint16.MIN, uint16.MAX);
}
- public bool mp2ts_transcoder {
- get {
- return this.get_bool ("general", MP2TS_TRANSCODER_KEY, true);
- }
- set {
- this.set_bool ("general", MP2TS_TRANSCODER_KEY, value);
- }
+ public void set_port (int value) {
+ this.set_int ("general", PORT_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 bool get_transcoding () throws GLib.Error {
+ return this.get_bool ("general", TRANSCODING_KEY);
+ }
+
+ public void set_transcoding (bool value) {
+ this.set_bool ("general", TRANSCODING_KEY, value);
+ }
+
+ public bool get_mp3_transcoder () throws GLib.Error {
+ return this.get_bool ("general", MP3_TRANSCODER_KEY);
+ }
+
+ public void set_mp3_transcoder (bool value) {
+ this.set_bool ("general", MP3_TRANSCODER_KEY, value);
+ }
+
+ public bool get_mp2ts_transcoder () throws GLib.Error {
+ return this.get_bool ("general", MP2TS_TRANSCODER_KEY);
+ }
+
+ public void set_mp2ts_transcoder (bool value) {
+ this.set_bool ("general", MP2TS_TRANSCODER_KEY, value);
+ }
+
+ public bool get_lpcm_transcoder () throws GLib.Error {
+ return this.get_bool ("general", LPCM_TRANSCODER_KEY);
+ }
+
+ public void set_lpcm_transcoder (bool value) {
+ this.set_bool ("general", LPCM_TRANSCODER_KEY, value);
}
public static UserConfig get_default () {
diff --git a/src/ui/rygel-general-pref-section.vala b/src/ui/rygel-general-pref-section.vala
index 705f13c..4e306b4 100644
--- a/src/ui/rygel-general-pref-section.vala
+++ b/src/ui/rygel-general-pref-section.vala
@@ -60,29 +60,32 @@ public class Rygel.GeneralPrefSection : PreferencesSection {
this.lpcm_check = (CheckButton) builder.get_object (LPCM_CHECKBUTTON);
assert (this.lpcm_check != null);
- if (config.host_ip != null) {
- this.ip_entry.set_text (config.host_ip);
- }
- this.port_spin.set_value (config.port);
+ try {
+ this.ip_entry.set_text (config.get_host_ip ());
+ this.port_spin.set_value (config.get_port ());
- this.upnp_check.active = this.config.upnp_enabled;
- this.trans_check.active = this.config.transcoding;
- this.mp3_check.active = this.config.mp3_transcoder;
- this.mp2ts_check.active = this.config.mp2ts_transcoder;
- this.lpcm_check.active = this.config.lpcm_transcoder;
+ this.upnp_check.active = this.config.get_upnp_enabled ();
+ this.trans_check.active = this.config.get_transcoding ();
+ this.mp3_check.active = this.config.get_mp3_transcoder ();
+ this.mp2ts_check.active = this.config.get_mp2ts_transcoder ();
+ this.lpcm_check.active = this.config.get_lpcm_transcoder ();
+ } catch (GLib.Error err) {
+ // No problem if we fail to read the config, the default values
+ // will do just fine
+ }
this.trans_check.toggled += this.on_trans_check_toggled;
}
public override void save () {
- this.config.host_ip = this.ip_entry.get_text ();
- this.config.port = (int) this.port_spin.get_value ();
+ this.config.set_host_ip (this.ip_entry.get_text ());
+ this.config.set_port ((int) this.port_spin.get_value ());
- this.config.upnp_enabled = this.upnp_check.active;
- this.config.transcoding = this.trans_check.active;
- this.config.mp3_transcoder = this.mp3_check.active;
- this.config.mp2ts_transcoder = this.mp2ts_check.active;
- this.config.lpcm_transcoder = this.lpcm_check.active;
+ this.config.set_upnp_enabled (this.upnp_check.active);
+ this.config.set_transcoding (this.trans_check.active);
+ this.config.set_mp3_transcoder (this.mp3_check.active);
+ this.config.set_mp2ts_transcoder (this.mp2ts_check.active);
+ this.config.set_lpcm_transcoder (this.lpcm_check.active);
}
private void on_trans_check_toggled (CheckButton trans_check) {
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]