[rygel] ui: Separate class for network configuration



commit 8b876c3bdd1cb5da9262766ae1e9d100973e98c1
Author: Zeeshan Ali (Khattak) <zeeshanak gnome org>
Date:   Thu Feb 17 16:57:36 2011 +0200

    ui: Separate class for network configuration

 src/ui/Makefile.am                     |    3 +-
 src/ui/rygel-general-pref-section.vala |   60 --------------------
 src/ui/rygel-network-pref-section.vala |   96 ++++++++++++++++++++++++++++++++
 src/ui/rygel-preferences-dialog.vala   |    1 +
 4 files changed, 99 insertions(+), 61 deletions(-)
---
diff --git a/src/ui/Makefile.am b/src/ui/Makefile.am
index 0680585..1e48c63 100644
--- a/src/ui/Makefile.am
+++ b/src/ui/Makefile.am
@@ -28,7 +28,8 @@ rygel_preferences_SOURCES = \
 			    rygel-preferences-section.vala \
 			    rygel-general-pref-section.vala \
 			    rygel-media-export-pref-section.vala \
-			    rygel-writable-user-config.vala
+			    rygel-writable-user-config.vala \
+			    rygel-network-pref-section.vala
 
 rygel.stamp: $(rygel_preferences_VALASOURCES)
 rygel_preferences_VALAFLAGS = \
diff --git a/src/ui/rygel-general-pref-section.vala b/src/ui/rygel-general-pref-section.vala
index 283e05d..85286d3 100644
--- a/src/ui/rygel-general-pref-section.vala
+++ b/src/ui/rygel-general-pref-section.vala
@@ -25,82 +25,22 @@ using GUPnP;
 
 public class Rygel.GeneralPrefSection : PreferencesSection {
     const string UPNP_CHECKBUTTON = "upnp-checkbutton";
-    const string IFACE_ENTRY = "iface-entry";
-
-    private ComboBoxText iface_entry;
 
     private CheckButton upnp_check;
 
-    private ContextManager context_manager;
-
     public GeneralPrefSection (Builder            builder,
                                WritableUserConfig config) throws Error {
         base (config, "general");
 
         this.upnp_check = (CheckButton) builder.get_object (UPNP_CHECKBUTTON);
         assert (this.upnp_check != null);
-        this.iface_entry = (ComboBoxText) builder.get_object (IFACE_ENTRY);
-        assert (this.iface_entry != null);
-
-        this.context_manager = new ContextManager (null, 0);
 
-        // Apparently glade/GtkBuilder is unable to do this for us
-        this.iface_entry.set_entry_text_column (0);
-        try {
-            this.iface_entry.append_text (config.get_interface ());
-            this.iface_entry.set_active (0);
-        } catch (GLib.Error err) {
-            // No problem if we fail to read the config, the default values
-            // will do just fine. Same goes for rest of the keys.
-        }
         try {
             this.upnp_check.active = this.config.get_upnp_enabled ();
         } catch (GLib.Error err) {}
-
-        this.context_manager.context_available.connect
-                                        (this.on_context_available);
-        this.context_manager.context_unavailable.connect
-                                        (this.on_context_unavailable);
     }
 
     public override void save () {
-        this.config.set_interface (this.iface_entry.get_active_text ());
-
         this.config.set_upnp_enabled (this.upnp_check.active);
     }
-
-    private void on_context_available (GUPnP.ContextManager manager,
-                                       GUPnP.Context        context) {
-        TreeIter iter;
-
-        if (!this.find_interface (context.interface, out iter)) {
-            this.iface_entry.append_text (context.interface);
-        }
-    }
-
-    private void on_context_unavailable (GUPnP.ContextManager manager,
-                                         GUPnP.Context        context) {
-        TreeIter iter;
-
-        if (this.find_interface (context.interface, out iter)) {
-            var list_store = this.iface_entry.model as ListStore;
-            list_store.remove (iter);
-        }
-    }
-
-    private bool find_interface (string iface, out TreeIter iter) {
-        var model = this.iface_entry.model;
-        var more = model.get_iter_first (out iter);
-        while (more) {
-            model.get (iter, 0, &name, -1);
-
-            if (name == iface) {
-                break;
-            }
-
-            more = model.iter_next (ref iter);
-        }
-
-        return more;
-    }
 }
diff --git a/src/ui/rygel-network-pref-section.vala b/src/ui/rygel-network-pref-section.vala
new file mode 100644
index 0000000..94ad487
--- /dev/null
+++ b/src/ui/rygel-network-pref-section.vala
@@ -0,0 +1,96 @@
+/*
+ * Copyright (C) 2009,2011 Nokia Corporation.
+ *
+ * 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 Gtk;
+using GUPnP;
+
+public class Rygel.NetworkPrefSection : PreferencesSection {
+    const string IFACE_ENTRY = "iface-entry";
+
+    private ComboBoxText iface_entry;
+
+    private ContextManager context_manager;
+
+    public NetworkPrefSection (Builder            builder,
+                               WritableUserConfig config) throws Error {
+        base (config, "general");
+
+        this.iface_entry = (ComboBoxText) builder.get_object (IFACE_ENTRY);
+        assert (this.iface_entry != null);
+
+        this.context_manager = new ContextManager (null, 0);
+
+        // Apparently glade/GtkBuilder is unable to do this for us
+        this.iface_entry.set_entry_text_column (0);
+        try {
+            this.iface_entry.append_text (config.get_interface ());
+            this.iface_entry.set_active (0);
+        } catch (GLib.Error err) {
+            // No problem if we fail to read the config, the default values
+            // will do just fine. Same goes for rest of the keys.
+        }
+
+        this.context_manager.context_available.connect
+                                        (this.on_context_available);
+        this.context_manager.context_unavailable.connect
+                                        (this.on_context_unavailable);
+    }
+
+    public override void save () {
+        this.config.set_interface (this.iface_entry.get_active_text ());
+    }
+
+    private void on_context_available (GUPnP.ContextManager manager,
+                                       GUPnP.Context        context) {
+        TreeIter iter;
+
+        if (!this.find_interface (context.interface, out iter)) {
+            this.iface_entry.append_text (context.interface);
+        }
+    }
+
+    private void on_context_unavailable (GUPnP.ContextManager manager,
+                                         GUPnP.Context        context) {
+        TreeIter iter;
+
+        if (this.find_interface (context.interface, out iter)) {
+            var list_store = this.iface_entry.model as ListStore;
+            list_store.remove (iter);
+        }
+    }
+
+    private bool find_interface (string iface, out TreeIter iter) {
+        var model = this.iface_entry.model;
+        var more = model.get_iter_first (out iter);
+        while (more) {
+            model.get (iter, 0, &name, -1);
+
+            if (name == iface) {
+                break;
+            }
+
+            more = model.iter_next (ref iter);
+        }
+
+        return more;
+    }
+}
diff --git a/src/ui/rygel-preferences-dialog.vala b/src/ui/rygel-preferences-dialog.vala
index 492f2ae..5c0796c 100644
--- a/src/ui/rygel-preferences-dialog.vala
+++ b/src/ui/rygel-preferences-dialog.vala
@@ -46,6 +46,7 @@ public class Rygel.PreferencesDialog : GLib.Object {
 
         this.sections = new ArrayList<PreferencesSection> ();
         this.sections.add (new GeneralPrefSection (this.builder, this.config));
+        this.sections.add (new NetworkPrefSection (this.builder, this.config));
         this.sections.add (new MediaExportPrefSection (this.builder,
                                                        this.config));
     }



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