[rygel/config] ConfigReader + ConfigEditor = Configuration



commit 3ca65b8889a511f78c1d90bdfc36fa44c5c17d34
Author: Zeeshan Ali (Khattak) <zeeshanak gnome org>
Date:   Fri Apr 24 15:36:10 2009 +0300

    ConfigReader + ConfigEditor = Configuration
    
    Merge ConfigEditor into ConfigReader and name it 'Configuration'.
---
 src/rygel/Makefile.am                              |    6 +-
 ...config-reader.vala => rygel-configuration.vala} |   40 ++++++++++-
 src/rygel/rygel-media-server-factory.vala          |   18 +++---
 src/ui/Makefile.am                                 |    7 +--
 src/ui/rygel-config-editor.vala                    |   72 --------------------
 src/ui/rygel-general-pref-vbox.vala                |   12 ++--
 src/ui/rygel-plugin-pref-vbox.vala                 |   18 +++---
 src/ui/rygel-preferences-dialog.vala               |   10 ++--
 src/ui/rygel-preferences-vbox.vala                 |   22 ++----
 9 files changed, 80 insertions(+), 125 deletions(-)

diff --git a/src/rygel/Makefile.am b/src/rygel/Makefile.am
index 8f0f3d4..424f591 100644
--- a/src/rygel/Makefile.am
+++ b/src/rygel/Makefile.am
@@ -28,7 +28,7 @@ BUILT_SOURCES = rygel-1.0.vapi \
 		rygel.h \
 		rygel-media-server.c \
 		rygel-media-server-factory.c \
-		rygel-config-reader.c \
+		rygel-configuration.c \
 		rygel-main.c \
 		rygel-content-directory.c \
 		rygel-browse.c \
@@ -108,7 +108,7 @@ rygel_LDFLAGS = -export-dynamic
 
 VAPI_FILES = rygel-1.0.vapi
 
-VAPI_SOURCE_FILES = rygel-config-reader.vala \
+VAPI_SOURCE_FILES = rygel-configuration.vala \
 		    rygel-content-directory.vala \
 		    rygel-connection-manager.vala \
 		    rygel-media-receiver-registrar.vala \
@@ -145,7 +145,7 @@ rygel-1.0.vapi: $(VAPI_SOURCE_FILES)
 
 noinst_LIBRARIES = librygel-configuration.a
 
-librygel_configuration_a_SOURCES = rygel-config-reader.c \
+librygel_configuration_a_SOURCES = rygel-configuration.c \
 				   cstuff.c \
                                    cstuff.h
 
diff --git a/src/rygel/rygel-config-reader.vala b/src/rygel/rygel-configuration.vala
similarity index 79%
rename from src/rygel/rygel-config-reader.vala
rename to src/rygel/rygel-configuration.vala
index 7ab2cde..69c94f3 100644
--- a/src/rygel/rygel-config-reader.vala
+++ b/src/rygel/rygel-configuration.vala
@@ -28,7 +28,7 @@ using CStuff;
 /**
  * Reads the user configuration for Rygel.
  */
-public class Rygel.ConfigReader {
+public class Rygel.Configuration {
     protected static const string ROOT_GCONF_PATH = "/apps/rygel/";
     protected static const string IP_KEY = "host-ip";
     protected static const string PORT_KEY = "port";
@@ -43,7 +43,7 @@ public class Rygel.ConfigReader {
     public string host_ip;
     public int port;
 
-    public ConfigReader () {
+    public Configuration () {
         this.gconf = GConf.Client.get_default ();
 
         this.enable_xbox = this.get_bool ("general", XBOX_KEY, false);
@@ -128,5 +128,41 @@ public class Rygel.ConfigReader {
 
         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_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
+        }
+    }
 }
 
diff --git a/src/rygel/rygel-media-server-factory.vala b/src/rygel/rygel-media-server-factory.vala
index 9a09a37..f216043 100644
--- a/src/rygel/rygel-media-server-factory.vala
+++ b/src/rygel/rygel-media-server-factory.vala
@@ -40,18 +40,18 @@ public class Rygel.MediaServerFactory {
     public static const string XBOX_DESC_DOC = "xml/description-xbox360.xml";
     public static const string DESC_PREFIX = "Rygel";
 
-    private ConfigReader config_reader;
+    private Configuration config;
     private GUPnP.Context context;
 
     public MediaServerFactory () throws GLib.Error {
-        this.config_reader = new ConfigReader ();
+        this.config = new Configuration ();
 
         /* Set up GUPnP context */
         this.context = create_upnp_context ();
     }
 
     public MediaServer create_media_server (Plugin plugin) throws GLib.Error {
-        if (!this.config_reader.get_enabled (plugin.name)) {
+        if (!this.config.get_enabled (plugin.name)) {
             throw new MediaServerFactoryError.PLUGIN_DISABLED (
                             "Plugin disabled in user configuration.");
         }
@@ -79,7 +79,7 @@ public class Rygel.MediaServerFactory {
                                    string desc_path) throws GLib.Error {
         string orig_desc_path;
 
-        if (this.config_reader.enable_xbox)
+        if (this.config.enable_xbox)
             /* Use Xbox 360 specific description */
             orig_desc_path = Path.build_filename (BuildConfig.DATA_DIR,
                                                   XBOX_DESC_DOC);
@@ -97,7 +97,7 @@ public class Rygel.MediaServerFactory {
         /* Modify description to include Plugin-specific stuff */
         this.prepare_desc_for_plugin (doc, plugin);
 
-        if (this.config_reader.enable_xbox)
+        if (this.config.enable_xbox)
             /* Put/Set XboX specific stuff to description */
             add_xbox_specifics (doc);
 
@@ -108,8 +108,8 @@ public class Rygel.MediaServerFactory {
 
     private GUPnP.Context create_upnp_context () throws GLib.Error {
         GUPnP.Context context = new GUPnP.Context (null,
-                                                   this.config_reader.host_ip,
-                                                   this.config_reader.port);
+                                                   this.config.host_ip,
+                                                   this.config.port);
 
         /* Host UPnP dir */
         context.host_path (BuildConfig.DATA_DIR, "");
@@ -173,7 +173,7 @@ public class Rygel.MediaServerFactory {
             return;
         }
 
-        element->set_content (this.config_reader.get_title (plugin_name));
+        element->set_content (this.config.get_title (plugin_name));
 
         /* UDN */
         element = Utils.get_xml_element (device_element, "UDN");
@@ -183,7 +183,7 @@ public class Rygel.MediaServerFactory {
             return;
         }
 
-        element->set_content (this.config_reader.get_udn (plugin_name));
+        element->set_content (this.config.get_udn (plugin_name));
     }
 
     private void add_services_to_desc (Xml.Node *device_element,
diff --git a/src/ui/Makefile.am b/src/ui/Makefile.am
index 09b2b7c..17e24d2 100644
--- a/src/ui/Makefile.am
+++ b/src/ui/Makefile.am
@@ -24,8 +24,7 @@ BUILT_SOURCES = rygel.stamp \
 		rygel-preferences-dialog.c \
 		rygel-preferences-vbox.c \
 		rygel-general-pref-vbox.c \
-		rygel-plugin-pref-vbox.c \
-		rygel-config-editor.c
+		rygel-plugin-pref-vbox.c
 
 rygel_preferences_SOURCES = rygel-preferences-dialog.c \
 			    rygel-preferences-dialog.vala \
@@ -34,9 +33,7 @@ rygel_preferences_SOURCES = rygel-preferences-dialog.c \
 			    rygel-general-pref-vbox.c \
 			    rygel-general-pref-vbox.vala \
 			    rygel-plugin-pref-vbox.c \
-			    rygel-plugin-pref-vbox.vala \
-			    rygel-config-editor.c \
-			    rygel-config-editor.vala
+			    rygel-plugin-pref-vbox.vala
 
 rygel.stamp: $(filter %.vala,$(rygel_preferences_SOURCES))
 	$(VALAC) -C --vapidir=$(rygeldir) \
diff --git a/src/ui/rygel-config-editor.vala b/src/ui/rygel-config-editor.vala
deleted file mode 100644
index ab94975..0000000
--- a/src/ui/rygel-config-editor.vala
+++ /dev/null
@@ -1,72 +0,0 @@
-/*
- * Copyright (C) 2008,2009 Nokia Corporation, all rights reserved.
- * Copyright (C) 2008,2009 Zeeshan Ali (Khattak) <zeeshanak gnome org>.
- *
- * Author: Zeeshan Ali (Khattak) <zeeshanak gnome org>
- *                               <zeeshan ali nokia com>
- *
- * This file is part of Rygel.
- *
- * Rygel is free software; you can redistribute it and/or modify
- * it under the terms of the GNU Lesser General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- *
- * Rygel is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public License
- * along with this program; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- */
-
-using GConf;
-using CStuff;
-
-/**
- * User configuration editor for Rygel.
- */
-public class Rygel.ConfigEditor : ConfigReader {
-    public ConfigEditor () {
-        base ();
-    }
-
-    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_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
-        }
-    }
-}
-
diff --git a/src/ui/rygel-general-pref-vbox.vala b/src/ui/rygel-general-pref-vbox.vala
index 85b2b31..547d55d 100644
--- a/src/ui/rygel-general-pref-vbox.vala
+++ b/src/ui/rygel-general-pref-vbox.vala
@@ -23,16 +23,16 @@
 using Gtk;
 
 public class Rygel.GeneralPrefVBox : PreferencesVBox {
-    public GeneralPrefVBox (ConfigEditor config_editor) {
-        base (config_editor, "General", "general");
+    public GeneralPrefVBox (Configuration config) {
+        base (config, "General", "general");
 
-        this.add_string_pref (ConfigReader.IP_KEY,
+        this.add_string_pref (Configuration.IP_KEY,
                               "IP",
-                              this.config_editor.host_ip,
+                              this.config.host_ip,
                               "The IP to advertise the UPnP MediaServer on");
-        this.add_int_pref (ConfigReader.PORT_KEY,
+        this.add_int_pref (Configuration.PORT_KEY,
                            "Port",
-                           this.config_editor.port,
+                           this.config.port,
                            uint16.MIN,
                            uint16.MAX,
                            "The port to advertise the UPnP MediaServer on");
diff --git a/src/ui/rygel-plugin-pref-vbox.vala b/src/ui/rygel-plugin-pref-vbox.vala
index b3c135e..7c3e5aa 100644
--- a/src/ui/rygel-plugin-pref-vbox.vala
+++ b/src/ui/rygel-plugin-pref-vbox.vala
@@ -23,26 +23,26 @@
 using Gtk;
 
 public class Rygel.PluginPrefVBox : PreferencesVBox {
-    public PluginPrefVBox (ConfigEditor config_editor,
-                           string       section) {
-        base (config_editor, section, section);
+    public PluginPrefVBox (Configuration config,
+                           string        section) {
+        base (config, section, section);
 
-        var enabled = config_editor.get_enabled (section);
-        var title = config_editor.get_title (section);
-        var udn = config_editor.get_udn (section);
+        var enabled = config.get_enabled (section);
+        var title = config.get_title (section);
+        var udn = config.get_udn (section);
 
-        this.add_boolean_pref (ConfigReader.ENABLED_KEY,
+        this.add_boolean_pref (Configuration.ENABLED_KEY,
                                "Enabled",
                                enabled,
                                "Enable/Disable this plugin");
 
-        this.add_string_pref (ConfigReader.TITLE_KEY,
+        this.add_string_pref (Configuration.TITLE_KEY,
                               "Title",
                               title,
                               "This is the name that will appear on the " +
                               "client UIs to");
 
-        this.add_string_pref (ConfigReader.UDN_KEY,
+        this.add_string_pref (Configuration.UDN_KEY,
                               "UDN",
                               udn,
                               "The Unique Device Name (UDN) for this plugin." +
diff --git a/src/ui/rygel-preferences-dialog.vala b/src/ui/rygel-preferences-dialog.vala
index 0498409..434bd62 100644
--- a/src/ui/rygel-preferences-dialog.vala
+++ b/src/ui/rygel-preferences-dialog.vala
@@ -28,13 +28,13 @@ public class Rygel.PreferencesDialog : Dialog {
     public PreferencesDialog () {
         this.title = "Rygel Preferences";
 
-        var config_editor = new ConfigEditor ();
+        var config = new Configuration ();
 
         this.notebook = new Notebook ();
-        this.add_pref_page (new GeneralPrefVBox (config_editor));
-        this.add_pref_page (new PluginPrefVBox (config_editor, "Tracker"));
-        this.add_pref_page (new PluginPrefVBox (config_editor, "DVB"));
-        this.add_pref_page (new PluginPrefVBox (config_editor, "Test"));
+        this.add_pref_page (new GeneralPrefVBox (config));
+        this.add_pref_page (new PluginPrefVBox (config, "Tracker"));
+        this.add_pref_page (new PluginPrefVBox (config, "DVB"));
+        this.add_pref_page (new PluginPrefVBox (config, "Test"));
 
         this.vbox.add (this.notebook);
 
diff --git a/src/ui/rygel-preferences-vbox.vala b/src/ui/rygel-preferences-vbox.vala
index 51ce1b6..ebddb64 100644
--- a/src/ui/rygel-preferences-vbox.vala
+++ b/src/ui/rygel-preferences-vbox.vala
@@ -23,18 +23,18 @@
 using Gtk;
 
 public class Rygel.PreferencesVBox : VBox {
-    protected ConfigEditor config_editor;
+    protected Configuration config;
 
     public string title;
     public string section;
 
-    public PreferencesVBox (ConfigEditor config_editor,
-                            string       title,
-                            string       section) {
+    public PreferencesVBox (Configuration config,
+                            string        title,
+                            string        section) {
         this.section = section;
         this.title = title;
 
-        this.config_editor = config_editor;
+        this.config = config;
     }
 
     protected void add_string_pref (string  name,
@@ -109,23 +109,17 @@ public class Rygel.PreferencesVBox : VBox {
                         var name = widget.get_name ();
                         var number = ((SpinButton) widget).get_value ();
 
-                        this.config_editor.set_int (this.section,
-                                                    name,
-                                                    (int) number);
+                        this.config.set_int (this.section, name, (int) number);
                 } else if (widget is Entry) {
                         var name = widget.get_name ();
                         var text = ((Entry) widget).get_text ();
 
-                        this.config_editor.set_string (this.section,
-                                                       name,
-                                                       text);
+                        this.config.set_string (this.section, name, text);
                 } else if (widget is CheckButton) {
                         var name = widget.get_name ();
                         var active = ((CheckButton) widget).get_active ();
 
-                        this.config_editor.set_bool (this.section,
-                                                     name,
-                                                     active);
+                        this.config.set_bool (this.section, name, active);
                 }
             }
         }



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]