[rygel] core,ui,data: Replace 'ip' config with 'interface'



commit 26168494dbe5b7c3455ab20d15043f4b77e187e7
Author: Zeeshan Ali (Khattak) <zeeshanak gnome org>
Date:   Thu Sep 3 17:49:52 2009 +0300

    core,ui,data: Replace 'ip' config with 'interface'
    
    Replace 'host-ip' configuration key with 'interface'. Also provide an
    ease-to-use UI component to set this key in the user config.

 data/rygel-default.conf                |    6 ++--
 data/rygel-maemo.conf                  |    6 ++--
 data/rygel-preferences.ui              |   37 ++++++++++---------
 src/rygel/rygel-cmdline-config.vala    |   14 +++++---
 src/rygel/rygel-configuration.vala     |    2 +-
 src/rygel/rygel-main.vala              |    6 ++--
 src/rygel/rygel-meta-config.vala       |    4 +-
 src/rygel/rygel-user-config.vala       |   10 +++---
 src/ui/Makefile.am                     |    2 +-
 src/ui/rygel-general-pref-section.vala |   60 ++++++++++++++++++++++++++++---
 10 files changed, 101 insertions(+), 46 deletions(-)
---
diff --git a/data/rygel-default.conf b/data/rygel-default.conf
index 800d67e..4de5fd8 100644
--- a/data/rygel-default.conf
+++ b/data/rygel-default.conf
@@ -21,9 +21,9 @@ enable-lpcm-transcoder=true
 # (mpeg 2 video + audio) transcoding support.
 enable-mp2ts-transcoder=true
 
-# The IP of the network interface to attach rygel to. Leave it blank for
-# dynamic configuration.
-host-ip=
+# The network interface to attach rygel to. Leave it blank for dynamic
+# configuration.
+interface=
 # The port to run HTTP server on. 0 means dynamic.
 port=0
 
diff --git a/data/rygel-maemo.conf b/data/rygel-maemo.conf
index ea96de7..21fa085 100644
--- a/data/rygel-maemo.conf
+++ b/data/rygel-maemo.conf
@@ -21,9 +21,9 @@ enable-lpcm-transcoder=true
 # (mpeg 2 video + audio) transcoding support.
 enable-mp2ts-transcoder=false
 
-# The IP of the network interface to attach rygel to. Leave it blank for
-# dynamic configuration.
-host-ip=
+# The network interface to attach rygel to. Leave it blank for dynamic
+# configuration.
+interface=
 # The port to run HTTP server on. 0 means dynamic.
 port=0
 
diff --git a/data/rygel-preferences.ui b/data/rygel-preferences.ui
index 2a973dd..04da0f8 100644
--- a/data/rygel-preferences.ui
+++ b/data/rygel-preferences.ui
@@ -8,6 +8,12 @@
       <column type="gchararray"/>
     </columns>
   </object>
+  <object class="GtkListStore" id="iface-liststore">
+    <columns>
+      <!-- column-name interface -->
+      <column type="gchararray"/>
+    </columns>
+  </object>
   <object class="GtkDialog" id="preferences-dialog">
     <property name="border_width">5</property>
     <property name="title" translatable="yes">Rygel Preferences</property>
@@ -144,27 +150,12 @@
                           </packing>
                         </child>
                         <child>
-                          <object class="GtkEntry" id="ip-entry">
-                            <property name="visible">True</property>
-                            <property name="can_focus">True</property>
-                            <property name="invisible_char">&#x25CF;</property>
-                          </object>
-                          <packing>
-                            <property name="left_attach">1</property>
-                            <property name="right_attach">2</property>
-                            <property name="top_attach">1</property>
-                            <property name="bottom_attach">2</property>
-                            <property name="y_options">GTK_FILL</property>
-                          </packing>
-                        </child>
-                        <child>
-                          <object class="GtkLabel" id="ip-label">
+                          <object class="GtkLabel" id="iface-label">
                             <property name="visible">True</property>
                             <property name="xalign">0</property>
                             <property name="xpad">12</property>
-                            <property name="label" translatable="yes">_IP Address</property>
+                            <property name="label" translatable="yes">_Interface</property>
                             <property name="use_underline">True</property>
-                            <property name="mnemonic_widget">ip-entry</property>
                           </object>
                           <packing>
                             <property name="top_attach">1</property>
@@ -210,6 +201,18 @@
                             <property name="y_options"></property>
                           </packing>
                         </child>
+                        <child>
+                          <object class="GtkComboBoxEntry" id="iface-entry">
+                            <property name="visible">True</property>
+                            <property name="model">iface-liststore</property>
+                          </object>
+                          <packing>
+                            <property name="left_attach">1</property>
+                            <property name="right_attach">2</property>
+                            <property name="top_attach">1</property>
+                            <property name="bottom_attach">2</property>
+                          </packing>
+                        </child>
                       </object>
                       <packing>
                         <property name="expand">False</property>
diff --git a/src/rygel/rygel-cmdline-config.vala b/src/rygel/rygel-cmdline-config.vala
index 01931cd..962b156 100644
--- a/src/rygel/rygel-cmdline-config.vala
+++ b/src/rygel/rygel-cmdline-config.vala
@@ -33,7 +33,7 @@ public errordomain Rygel.CmdlineConfigError {
  * Manages configuration from Commandline arguments.
  */
 public class Rygel.CmdlineConfig : GLib.Object, Configuration {
-    private static string host_ip;
+    private static string iface;
     private static int port = -1;
 
     private static bool no_transcoding;
@@ -60,8 +60,8 @@ public class Rygel.CmdlineConfig : GLib.Object, Configuration {
 	const OptionEntry[] options = {
         { "version", 0, 0, OptionArg.NONE, ref version,
           "Display version number", null },
-        { "host-ip", 'H', 0, OptionArg.STRING, ref host_ip,
-          "IP address", "IP" },
+        { "network-interface", 'n', 0, OptionArg.STRING, ref iface,
+          "Network Interface", "INTERFACE" },
         { "port", 'p', 0, OptionArg.INT, ref port,
           "Port", "PORT" },
         { "disable-transcoding", 't', 0, OptionArg.NONE, ref no_transcoding,
@@ -112,8 +112,12 @@ public class Rygel.CmdlineConfig : GLib.Object, Configuration {
         throw new ConfigurationError.NO_VALUE_SET ("No value available");
     }
 
-    public string get_host_ip () throws GLib.Error {
-        return host_ip;
+    public string get_interface () throws GLib.Error {
+        if (iface == null) {
+            throw new ConfigurationError.NO_VALUE_SET ("No value available");
+        }
+
+        return iface;
     }
 
     public int get_port () throws GLib.Error {
diff --git a/src/rygel/rygel-configuration.vala b/src/rygel/rygel-configuration.vala
index 20e6038..f10dfd5 100644
--- a/src/rygel/rygel-configuration.vala
+++ b/src/rygel/rygel-configuration.vala
@@ -35,7 +35,7 @@ public errordomain Rygel.ConfigurationError {
 public interface Rygel.Configuration : GLib.Object {
     public abstract bool get_upnp_enabled () throws GLib.Error;
 
-    public abstract string get_host_ip () throws GLib.Error;
+    public abstract string get_interface () throws GLib.Error;
 
     public abstract int get_port () throws GLib.Error;
 
diff --git a/src/rygel/rygel-main.vala b/src/rygel/rygel-main.vala
index 9676875..51bc061 100644
--- a/src/rygel/rygel-main.vala
+++ b/src/rygel/rygel-main.vala
@@ -103,17 +103,17 @@ public class Rygel.Main : Object {
 
     private void on_context_available (GUPnP.ContextManager manager,
                                        GUPnP.Context        context) {
-        string host_ip = null;
+        string iface = null;
 
         debug ("new network context %s (%s) available.",
                context.interface,
                context.host_ip);
 
         try {
-            host_ip = this.config.get_host_ip ();
+            iface = this.config.get_interface ();
         } catch (GLib.Error err) {}
 
-        if (host_ip == null || host_ip == context.host_ip) {
+        if (iface == null || iface == context.interface) {
             var factory = new RootDeviceFactory (context);
             this.factories.add (factory);
 
diff --git a/src/rygel/rygel-meta-config.vala b/src/rygel/rygel-meta-config.vala
index ac830e6..629d399 100644
--- a/src/rygel/rygel-meta-config.vala
+++ b/src/rygel/rygel-meta-config.vala
@@ -77,13 +77,13 @@ public class Rygel.MetaConfig : GLib.Object, Configuration {
         return val;
     }
 
-    public string get_host_ip () throws GLib.Error {
+    public string get_interface () throws GLib.Error {
         string val = null;
         bool unavailable = true;
 
         foreach (var config in this.configs) {
             try {
-                val = config.get_host_ip ();
+                val = config.get_interface ();
                 unavailable = false;
                 break;
             } catch (GLib.Error err) {}
diff --git a/src/rygel/rygel-user-config.vala b/src/rygel/rygel-user-config.vala
index 6802619..c8477ed 100644
--- a/src/rygel/rygel-user-config.vala
+++ b/src/rygel/rygel-user-config.vala
@@ -29,7 +29,7 @@ using CStuff;
  */
 public class Rygel.UserConfig : GLib.Object, Configuration {
     protected static const string CONFIG_FILE = "rygel.conf";
-    protected static const string IP_KEY = "host-ip";
+    protected static const string IFACE_KEY = "interface";
     protected static const string PORT_KEY = "port";
     protected static const string ENABLED_KEY = "enabled";
     protected static const string TITLE_KEY = "title";
@@ -67,12 +67,12 @@ public class Rygel.UserConfig : GLib.Object, Configuration {
         }
     }
 
-    public string get_host_ip () throws GLib.Error {
-        return this.get_string ("general", IP_KEY);
+    public string get_interface () throws GLib.Error {
+        return this.get_string ("general", IFACE_KEY);
     }
 
-    public void set_host_ip (string value) {
-        this.set_string ("general", IP_KEY, value);
+    public void set_interface (string value) {
+        this.set_string ("general", IFACE_KEY, value);
     }
 
     public int get_port () throws GLib.Error {
diff --git a/src/ui/Makefile.am b/src/ui/Makefile.am
index 5bafd9a..9d62e0e 100644
--- a/src/ui/Makefile.am
+++ b/src/ui/Makefile.am
@@ -30,7 +30,7 @@ rygel_preferences_SOURCES = \
 
 rygel.stamp: $(rygel_preferences_VALASOURCES)
 rygel_preferences_VALAFLAGS = \
-	--vapidir=$(rygeldir) \
+	--vapidir=$(rygeldir) --thread \
 	--pkg rygel-1.0 --pkg cstuff --pkg gupnp-1.0 --pkg gupnp-av-1.0 \
 	--pkg dbus-glib-1 --pkg gconf-2.0 --pkg gstreamer-0.10 \
 	--pkg gio-2.0 --pkg gee-1.0 --pkg gtk+-2.0
diff --git a/src/ui/rygel-general-pref-section.vala b/src/ui/rygel-general-pref-section.vala
index 862e19e..bccb21a 100644
--- a/src/ui/rygel-general-pref-section.vala
+++ b/src/ui/rygel-general-pref-section.vala
@@ -21,17 +21,18 @@
  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
  */
 using Gtk;
+using GUPnP;
 
 public class Rygel.GeneralPrefSection : PreferencesSection {
     const string UPNP_CHECKBUTTON = "upnp-checkbutton";
-    const string IP_ENTRY = "ip-entry";
+    const string IFACE_ENTRY = "iface-entry";
     const string PORT_SPINBUTTON = "port-spinbutton";
     const string TRANS_CHECKBUTTON = "transcoding-checkbutton";
     const string MP3_CHECKBUTTON = "mp3-checkbutton";
     const string MP2TS_CHECKBUTTON = "mp2ts-checkbutton";
     const string LPCM_CHECKBUTTON = "lpcm-checkbutton";
 
-    private Entry ip_entry;
+    private ComboBoxEntry iface_entry;
     private SpinButton port_spin;
 
     // Transcoding options
@@ -41,14 +42,16 @@ public class Rygel.GeneralPrefSection : PreferencesSection {
     private CheckButton mp2ts_check;
     private CheckButton lpcm_check;
 
+    private ContextManager context_manager;
+
     public GeneralPrefSection (Builder    builder,
                                UserConfig config) throws Error {
         base (config, "general");
 
         this.upnp_check = (CheckButton) builder.get_object (UPNP_CHECKBUTTON);
         assert (this.upnp_check != null);
-        this.ip_entry = (Entry) builder.get_object (IP_ENTRY);
-        assert (this.ip_entry != null);
+        this.iface_entry = (ComboBoxEntry) builder.get_object (IFACE_ENTRY);
+        assert (this.iface_entry != null);
         this.port_spin = (SpinButton) builder.get_object (PORT_SPINBUTTON);
         assert (this.port_spin != null);
         this.trans_check = (CheckButton) builder.get_object (TRANS_CHECKBUTTON);
@@ -60,8 +63,13 @@ public class Rygel.GeneralPrefSection : PreferencesSection {
         this.lpcm_check = (CheckButton) builder.get_object (LPCM_CHECKBUTTON);
         assert (this.lpcm_check != null);
 
+        this.context_manager = new ContextManager (null, 0);
+
+        // Apparently glade/GtkBuilder is unable to do this for us
+        this.iface_entry.set_text_column (0);
         try {
-            this.ip_entry.set_text (config.get_host_ip ());
+            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.
@@ -86,10 +94,15 @@ public class Rygel.GeneralPrefSection : PreferencesSection {
         } catch (GLib.Error err) {}
 
         this.trans_check.toggled += this.on_trans_check_toggled;
+
+        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_host_ip (this.ip_entry.get_text ());
+        this.config.set_interface (this.iface_entry.get_active_text ());
         this.config.set_port ((int) this.port_spin.get_value ());
 
         this.config.set_upnp_enabled (this.upnp_check.active);
@@ -104,4 +117,39 @@ public class Rygel.GeneralPrefSection : PreferencesSection {
         this.mp2ts_check.sensitive =
         this.lpcm_check.sensitive = trans_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;
+    }
 }



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