[gnome-boxes] wizard-window: API to show resource customization UI



commit b550b77770795cc0699951dba78c410d8b43c60e
Author: Zeeshan Ali (Khattak) <zeeshanak gnome org>
Date:   Wed Dec 3 17:31:11 2014 +0000

    wizard-window: API to show resource customization UI
    
    Add a view and API to show resources customization UI.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=741046

 data/ui/wizard-window.ui |   39 +++++++++++++++++++++++++-
 src/wizard-window.vala   |   68 ++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 105 insertions(+), 2 deletions(-)
---
diff --git a/data/ui/wizard-window.ui b/data/ui/wizard-window.ui
index b2c5082..76c7e76 100644
--- a/data/ui/wizard-window.ui
+++ b/data/ui/wizard-window.ui
@@ -10,7 +10,11 @@
         |    |
         |    |-> notificationbar = Boxes.Notificationbar ();
         |    |
-        |    |-> wizard = new Boxes.Wizard ();
+        |    |-> view = Gtk.Stack ();
+        |         |
+        |         |-> wizard = new Boxes.Wizard ();
+        |         |
+        |         |-> customization_grid = new Gtk.Grid ();
         |
         |-> topbar = new Boxes.WizardTopbar (); // as titlebar
   -->
@@ -35,10 +39,41 @@
         </child>
 
         <child>
-          <object class="BoxesWizard" id="wizard">
+          <object class="GtkStack" id="view">
             <property name="visible">True</property>
+            <property name="transition-type">slide-left-right</property>
+            <property name="transition-duration">400</property>
+            <style>
+              <class name="content-bg"/>
+            </style>
+
+            <child>
+              <object class="BoxesWizard" id="wizard">
+                <property name="visible">True</property>
+              </object>
+
+              <packing>
+                <property name="name">main</property>
+              </packing>
+            </child>
+
+            <child>
+              <object class="GtkGrid" id="customization_grid">
+                <property name="visible">True</property>
+                <property name="margin-start">20</property>
+                <property name="margin-end">20</property>
+                <property name="margin-top">20</property>
+                <property name="margin-bottom">20</property>
+              </object>
+
+              <packing>
+                <property name="name">customization</property>
+              </packing>
+            </child>
+
           </object>
         </child>
+
       </object>
     </child>
 
diff --git a/src/wizard-window.vala b/src/wizard-window.vala
index b6a390b..b0c1611 100644
--- a/src/wizard-window.vala
+++ b/src/wizard-window.vala
@@ -1,18 +1,50 @@
 // This file is part of GNOME Boxes. License: LGPLv2+
 using Gtk;
 
+private enum Boxes.WizardWindowPage {
+    MAIN,
+    CUSTOMIZATION,
+}
+
 [GtkTemplate (ui = "/org/gnome/Boxes/ui/wizard-window.ui")]
 private class Boxes.WizardWindow : Gtk.Window, Boxes.UI {
+    public const string[] page_names = { "main", "customization" };
+
     public UIState previous_ui_state { get; protected set; }
     public UIState ui_state { get; protected set; }
 
+    private WizardWindowPage _page;
+    public WizardWindowPage page {
+        get { return _page; }
+        set {
+            if (_page == WizardWindowPage.CUSTOMIZATION && value != WizardWindowPage.CUSTOMIZATION &&
+                resource_properties != null && resource_properties.length () > 0) {
+                foreach (var property in resource_properties)
+                    property.flush ();
+                resource_properties = null;
+
+                wizard.review.begin ();
+            }
+
+            _page = value;
+
+            view.visible_child_name = page_names[value];
+        }
+    }
+
+    [GtkChild]
+    public Gtk.Stack view;
     [GtkChild]
     public Wizard wizard;
     [GtkChild]
+    public Gtk.Grid customization_grid;
+    [GtkChild]
     public WizardToolbar topbar;
     [GtkChild]
     public Notificationbar notificationbar;
 
+    private GLib.List<Boxes.Property> resource_properties;
+
     public WizardWindow (AppWindow app_window) {
         wizard.setup_ui (app_window, this);
 
@@ -21,6 +53,42 @@ private class Boxes.WizardWindow : Gtk.Window, Boxes.UI {
         notify["ui-state"].connect (ui_state_changed);
     }
 
+    public void show_customization_page (LibvirtMachine machine) {
+        resource_properties = new GLib.List<Boxes.Property> ();
+        machine.properties.get_resources_properties (ref resource_properties);
+
+        return_if_fail (resource_properties.length () > 0);
+
+        foreach (var child in customization_grid.get_children ())
+            customization_grid.remove (child);
+
+        var current_row = 0;
+        foreach (var property in resource_properties) {
+            if (property.widget == null || property.extra_widget == null || property.description == null) {
+                warn_if_reached ();
+
+                continue;
+            }
+
+            var label_name = new Gtk.Label (property.description);
+            label_name.get_style_context ().add_class ("boxes-property-name-label");
+            label_name.halign = Gtk.Align.START;
+            label_name.hexpand = false;
+            customization_grid.attach (label_name, 0, current_row, 1, 1);
+
+            property.widget.hexpand = true;
+            customization_grid.attach (property.widget, 1, current_row, 1, 1);
+
+            property.extra_widget.hexpand = true;
+            customization_grid.attach (property.extra_widget, 0, current_row + 1, 2, 1);
+
+            current_row += 2;
+        }
+        customization_grid.show_all ();
+
+        page = WizardWindowPage.CUSTOMIZATION;
+    }
+
     private void ui_state_changed () {
         wizard.set_state (ui_state);
 


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