[rygel] core: Refactor Configuration.upnp_enabled setter
- From: Zeeshan Ali Khattak <zeeshanak src gnome org>
- To: svn-commits-list gnome org
- Subject: [rygel] core: Refactor Configuration.upnp_enabled setter
- Date: Fri, 12 Jun 2009 12:23:14 -0400 (EDT)
commit e6a3b6744be3268b2a12cbc72662898bdd5d19c6
Author: Zeeshan Ali (Khattak) <zeeshanak gnome org>
Date: Mon Jun 8 17:04:04 2009 +0300
core: Refactor Configuration.upnp_enabled setter
src/rygel/rygel-configuration.vala | 85 +++++++++++++++++-------------------
1 files changed, 40 insertions(+), 45 deletions(-)
---
diff --git a/src/rygel/rygel-configuration.vala b/src/rygel/rygel-configuration.vala
index f661bf3..ebbe846 100644
--- a/src/rygel/rygel-configuration.vala
+++ b/src/rygel/rygel-configuration.vala
@@ -62,51 +62,8 @@ public class Rygel.Configuration : GLib.Object {
return this.get_bool ("general", ENABLED_KEY, true);
}
set {
- if (value && !this.upnp_enabled) {
- try {
- uint32 res;
-
- // Start service first
- this.dbus_obj.StartServiceByName (RYGEL_SERVICE,
- (uint32) 0,
- out res);
-
- // Then symlink the desktop file to user's autostart dir
- var source_path = Path.build_filename (
- BuildConfig.DESKTOP_DIR,
- "rygel.desktop");
- var dest_path = Path.build_filename (
- Environment.get_user_config_dir (),
- "autostart",
- "rygel.desktop");
- var dest = File.new_for_path (dest_path);
-
- dest.make_symbolic_link (source_path, null);
-
- this.set_bool ("general", ENABLED_KEY, value);
- } catch (DBus.Error err) {
- warning ("Failed to start Rygel service: %s\n",
- err.message);
- }
- } else if (!value && this.upnp_enabled) {
- try {
- // Stop service first
- this.rygel_obj.Shutdown ();
-
- // Then delete the symlink from user's autostart dir
- var dest_path = Path.build_filename (
- Environment.get_user_config_dir (),
- "autostart",
- "rygel.desktop");
- var dest = File.new_for_path (dest_path);
-
- dest.delete (null);
-
- this.set_bool ("general", ENABLED_KEY, value);
- } catch (DBus.Error err) {
- warning ("Failed to shutdown Rygel service: %s\n",
- err.message);
- }
+ if (value != this.upnp_enabled) {
+ this.enable_upnp (value);
}
}
}
@@ -360,5 +317,43 @@ public class Rygel.Configuration : GLib.Object {
// 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);
+
+ // 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);
+
+ this.set_bool ("general", ENABLED_KEY, true);
+ } else {
+ // Stop service first
+ this.rygel_obj.Shutdown ();
+
+ // Then delete the symlink from user's autostart dir
+ dest.delete (null);
+
+ this.set_bool ("general", ENABLED_KEY, false);
+ }
+ } catch (DBus.Error err) {
+ warning ("Failed to %s Rygel service: %s\n",
+ enable? "start": "stop",
+ err.message);
+ }
+ }
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]