[rygel/config] Introducing PreferencesVBox.



commit 019daaa3b82709c18221321dea125e67810f842e
Author: Zeeshan Ali (Khattak) <zeeshanak gnome org>
Date:   Wed Apr 22 17:52:31 2009 +0300

    Introducing PreferencesVBox.
---
 src/ui/Makefile.am                   |    3 +
 src/ui/rygel-preferences-dialog.vala |   99 +------------------------
 src/ui/rygel-preferences-vbox.vala   |  136 ++++++++++++++++++++++++++++++++++
 3 files changed, 142 insertions(+), 96 deletions(-)

diff --git a/src/ui/Makefile.am b/src/ui/Makefile.am
index 0f423c7..2552676 100644
--- a/src/ui/Makefile.am
+++ b/src/ui/Makefile.am
@@ -22,10 +22,13 @@ bin_PROGRAMS = rygel-preferences
 
 BUILT_SOURCES = rygel.stamp \
 		rygel-preferences-dialog.c \
+		rygel-preferences-vbox.c \
 		rygel-config-editor.c
 
 rygel_preferences_SOURCES = rygel-preferences-dialog.c \
 			    rygel-preferences-dialog.vala \
+				rygel-preferences-vbox.c \
+				rygel-preferences-vbox.vala \
 			    rygel-config-editor.c \
 			    rygel-config-editor.vala
 
diff --git a/src/ui/rygel-preferences-dialog.vala b/src/ui/rygel-preferences-dialog.vala
index 4c49595..fd4a2bd 100644
--- a/src/ui/rygel-preferences-dialog.vala
+++ b/src/ui/rygel-preferences-dialog.vala
@@ -30,20 +30,7 @@ public class Rygel.PreferencesDialog : Dialog {
 
         this.config_editor = new ConfigEditor ();
 
-        this.add_string_pref (ConfigReader.IP_KEY,
-                              "IP",
-                              this.config_editor.host_ip,
-                              "The IP to advertise the UPnP MediaServer on");
-        this.add_int_pref (ConfigReader.PORT_KEY,
-                           "Port",
-                           this.config_editor.port,
-                           uint16.MIN,
-                           uint16.MAX,
-                           "The port to advertise the UPnP MediaServer on");
-        this.add_boolean_pref (ConfigReader.XBOX_KEY,
-                               "XBox support",
-                               this.config_editor.enable_xbox,
-                               "Enable Xbox support");
+        this.vbox.add (new PreferencesVBox (this.config_editor));
 
         this.add_button (STOCK_OK, ResponseType.ACCEPT);
         this.add_button (STOCK_APPLY, ResponseType.APPLY);
@@ -54,65 +41,6 @@ public class Rygel.PreferencesDialog : Dialog {
         this.show_all ();
     }
 
-    private void add_string_pref (string  name,
-                                  string  title,
-                                  string? current_value,
-                                  string  tooltip) {
-        var entry = new Entry ();
-
-        if (current_value != null) {
-            entry.set_text (current_value);
-        }
-
-        this.add_pref_widget (name, title, entry, tooltip);
-    }
-
-    private void add_int_pref (string  name,
-                               string  title,
-                               int     current_value,
-                               int     min,
-                               int     max,
-                               string  tooltip) {
-        var adjustment = new Adjustment (current_value,
-                                         min,
-                                         max,
-                                         1.0,
-                                         10.0,
-                                         10.0);
-
-        var spin = new SpinButton (adjustment, 1.0, 0);
-
-        this.add_pref_widget (name, title, spin, tooltip);
-    }
-
-    private void add_boolean_pref (string  name,
-                                   string  title,
-                                   bool    current_value,
-                                   string  tooltip) {
-        var check = new CheckButton ();
-
-        check.active = current_value;
-
-        this.add_pref_widget (name, title, check, tooltip);
-    }
-
-    private void add_pref_widget (string name,
-                                  string title,
-                                  Widget widget,
-                                  string tooltip) {
-        var hbox = new HBox (true, 6);
-
-        var label = new Label (title);
-
-        hbox.add (label);
-        hbox.add (widget);
-
-        hbox.set_tooltip_text (tooltip);
-        widget.set_name (name);
-
-        this.vbox.add (hbox);
-    }
-
     private void on_response (PreferencesDialog dialog, int response_id) {
         switch (response_id) {
             case ResponseType.REJECT:
@@ -130,32 +58,11 @@ public class Rygel.PreferencesDialog : Dialog {
 
     private void apply_settings () {
         foreach (var child in this.vbox.get_children ()) {
-            if (!(child is HBox)) {
+            if (!(child is PreferencesVBox)) {
                 break;
             }
 
-            var hbox = (HBox) child;
-
-            foreach (var widget in hbox.get_children ()) {
-                if (widget is SpinButton) {
-                        var name = widget.get_name ();
-                        var number = ((SpinButton) widget).get_value ();
-
-                        this.config_editor.set_int ("general",
-                                                    name,
-                                                    (int) number);
-                } else if (widget is Entry) {
-                        var name = widget.get_name ();
-                        var text = ((Entry) widget).get_text ();
-
-                        this.config_editor.set_string ("general", name, text);
-                } else if (widget is CheckButton) {
-                        var name = widget.get_name ();
-                        var active = ((CheckButton) widget).get_active ();
-
-                        this.config_editor.set_bool ("general", name, active);
-                }
-            }
+            ((PreferencesVBox) child).save ();
         }
     }
 
diff --git a/src/ui/rygel-preferences-vbox.vala b/src/ui/rygel-preferences-vbox.vala
new file mode 100644
index 0000000..25ba477
--- /dev/null
+++ b/src/ui/rygel-preferences-vbox.vala
@@ -0,0 +1,136 @@
+/*
+ * Copyright (C) 2009 Nokia Corporation, all rights reserved.
+ *
+ * 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;
+
+public class Rygel.PreferencesVBox : VBox {
+    ConfigEditor config_editor;
+
+    public PreferencesVBox (ConfigEditor config_editor) {
+        this.config_editor = config_editor;
+
+        this.add_string_pref (ConfigReader.IP_KEY,
+                              "IP",
+                              this.config_editor.host_ip,
+                              "The IP to advertise the UPnP MediaServer on");
+        this.add_int_pref (ConfigReader.PORT_KEY,
+                           "Port",
+                           this.config_editor.port,
+                           uint16.MIN,
+                           uint16.MAX,
+                           "The port to advertise the UPnP MediaServer on");
+        this.add_boolean_pref (ConfigReader.XBOX_KEY,
+                               "XBox support",
+                               this.config_editor.enable_xbox,
+                               "Enable Xbox support");
+    }
+
+    private void add_string_pref (string  name,
+                                  string  title,
+                                  string? current_value,
+                                  string  tooltip) {
+        var entry = new Entry ();
+
+        if (current_value != null) {
+            entry.set_text (current_value);
+        }
+
+        this.add_pref_widget (name, title, entry, tooltip);
+    }
+
+    private void add_int_pref (string  name,
+                               string  title,
+                               int     current_value,
+                               int     min,
+                               int     max,
+                               string  tooltip) {
+        var adjustment = new Adjustment (current_value,
+                                         min,
+                                         max,
+                                         1.0,
+                                         10.0,
+                                         10.0);
+
+        var spin = new SpinButton (adjustment, 1.0, 0);
+
+        this.add_pref_widget (name, title, spin, tooltip);
+    }
+
+    private void add_boolean_pref (string  name,
+                                   string  title,
+                                   bool    current_value,
+                                   string  tooltip) {
+        var check = new CheckButton ();
+
+        check.active = current_value;
+
+        this.add_pref_widget (name, title, check, tooltip);
+    }
+
+    private void add_pref_widget (string name,
+                                  string title,
+                                  Widget widget,
+                                  string tooltip) {
+        var hbox = new HBox (true, 6);
+
+        var label = new Label (title);
+
+        hbox.add (label);
+        hbox.add (widget);
+
+        hbox.set_tooltip_text (tooltip);
+        widget.set_name (name);
+
+        this.add (hbox);
+    }
+
+    public void save () {
+        foreach (var child in this.get_children ()) {
+            if (!(child is HBox)) {
+                break;
+            }
+
+            var hbox = (HBox) child;
+
+            foreach (var widget in hbox.get_children ()) {
+                if (widget is SpinButton) {
+                        var name = widget.get_name ();
+                        var number = ((SpinButton) widget).get_value ();
+
+                        this.config_editor.set_int ("general",
+                                                    name,
+                                                    (int) number);
+                } else if (widget is Entry) {
+                        var name = widget.get_name ();
+                        var text = ((Entry) widget).get_text ();
+
+                        this.config_editor.set_string ("general", name, text);
+                } else if (widget is CheckButton) {
+                        var name = widget.get_name ();
+                        var active = ((CheckButton) widget).get_active ();
+
+                        this.config_editor.set_bool ("general", name, active);
+                }
+            }
+        }
+    }
+}



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