From: Zeeshan Ali (Khattak) Date: Thu, 17 Feb 2011 14:57:36 +0000 (+0200) Subject: ui: Separate class for network configuration X-Git-Tag: RYGEL_0_9_9~28 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=8b876c3bdd1cb5da9262766ae1e9d100973e98c1;p=profile%2Fivi%2Frygel.git ui: Separate class for network configuration --- 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) + * + * + * 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 (); 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)); }