[gnome-boxes] wizard: Keep user in 'setup' until all data is provided



commit 2b22dfee04f6558d07cf84e1a74c23900beec72f
Author: Zeeshan Ali (Khattak) <zeeshanak gnome org>
Date:   Tue Aug 7 04:24:19 2012 +0300

    wizard: Keep user in 'setup' until all data is provided
    
    We used to fail with an appropriate error message when user tried to hit
    'continue' in setup page without providing needed data. Recently we had a
    regression in that regard so user was only getting a "VM setup failed"
    error.
    
    This patch fixes the regression but with an alternative solution: Keep the
    'continue' button disabled as long as user hasn't provided all the needed
    data.
    
    Also now that fedora express install doesn't require password, username
    is the only field that is mandatory now.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=680825

 src/installer-media.vala      |    9 +++------
 src/unattended-installer.vala |   38 +++++++++++++++++++++++---------------
 src/wizard.vala               |    4 +++-
 3 files changed, 29 insertions(+), 22 deletions(-)
---
diff --git a/src/installer-media.vala b/src/installer-media.vala
index 27025c6..c8f20f0 100644
--- a/src/installer-media.vala
+++ b/src/installer-media.vala
@@ -13,11 +13,9 @@ private class Boxes.InstallerMedia : GLib.Object {
     public string mount_point;
     public bool from_image;
 
-    public virtual bool need_user_input_for_vm_creation {
-        get {
-            return false;
-        }
-    }
+    public virtual bool need_user_input_for_vm_creation { get { return false; } }
+    public virtual bool user_data_for_vm_creation_available { get { return true; } }
+
     public bool live { get { return os_media == null || os_media.live; } }
 
     public InstallerMedia.from_iso_info (string           path,
@@ -86,7 +84,6 @@ private class Boxes.InstallerMedia : GLib.Object {
     }
 
     public virtual void populate_setup_vbox (Gtk.VBox setup_vbox) {}
-    public virtual void check_needed_info () throws UnattendedInstallerError.SETUP_INCOMPLETE {}
 
     public virtual GLib.List<Pair<string,string>> get_vm_properties () {
         var properties = new GLib.List<Pair<string,string>> ();
diff --git a/src/unattended-installer.vala b/src/unattended-installer.vala
index 6893461..cdff9bf 100644
--- a/src/unattended-installer.vala
+++ b/src/unattended-installer.vala
@@ -13,6 +13,12 @@ private abstract class Boxes.UnattendedInstaller: InstallerMedia {
         }
     }
 
+    public override bool user_data_for_vm_creation_available {
+        get {
+            return !express_toggle.active || username != "";
+        }
+    }
+
     public bool express_install {
         get { return express_toggle.active; }
     }
@@ -159,15 +165,6 @@ private abstract class Boxes.UnattendedInstaller: InstallerMedia {
         setup_vbox.show_all ();
     }
 
-    // Ensure needed information was provided by user
-    public override void check_needed_info () throws UnattendedInstallerError.SETUP_INCOMPLETE {
-        if (!express_toggle.active)
-            return;
-
-        if (username == "")
-            throw new UnattendedInstallerError.SETUP_INCOMPLETE (_("No username provided"));
-    }
-
     public override List<Pair> get_vm_properties () {
         var properties = base.get_vm_properties ();
 
@@ -223,6 +220,7 @@ private abstract class Boxes.UnattendedInstaller: InstallerMedia {
         express_toggle.active = !os_media.live;
         express_toggle.halign = Gtk.Align.START;
         express_toggle.valign = Gtk.Align.CENTER;
+        express_toggle.notify["active"].connect (() => { notify_property ("user-data-for-vm-creation-available"); });
         setup_table.attach_defaults (express_toggle, 2, 3, 0, 1);
 
         // 2nd row (while user avatar spans over 2 rows)
@@ -236,8 +234,7 @@ private abstract class Boxes.UnattendedInstaller: InstallerMedia {
         label.halign = Gtk.Align.END;
         label.valign = Gtk.Align.CENTER;
         setup_table.attach_defaults (label, 1, 2, 1, 2);
-        username_entry = new Gtk.Entry ();
-        username_entry.text = Environment.get_user_name ();
+        username_entry = create_input_entry (Environment.get_user_name ());
         username_entry.halign = Gtk.Align.START;
         username_entry.valign = Gtk.Align.CENTER;
         setup_table.attach_defaults (username_entry, 2, 3, 1, 2);
@@ -256,10 +253,7 @@ private abstract class Boxes.UnattendedInstaller: InstallerMedia {
         var button = new Gtk.Button.with_mnemonic (_("_Add Password"));
         button.visible = true;
         notebook.append_page (button);
-        password_entry = new Gtk.Entry ();
-        password_entry.visibility = false;
-        password_entry.visible = true;
-        password_entry.text = "";
+        password_entry = create_input_entry ("", false, false);
         notebook.append_page (password_entry);
         button.clicked.connect (() => {
             notebook.next_page ();
@@ -303,6 +297,20 @@ private abstract class Boxes.UnattendedInstaller: InstallerMedia {
         unattended_files.append (file);
     }
 
+    protected Gtk.Entry create_input_entry (string text, bool mandatory = true, bool visibility = true) {
+        var entry = new Gtk.Entry ();
+        entry.visibility = visibility;
+        entry.visible = true;
+        entry.text = text;
+
+        if (mandatory)
+            entry.notify["text"].connect (() => {
+                notify_property ("user-data-for-vm-creation-available");
+            });
+
+        return entry;
+    }
+
     private async void create_disk_image (Cancellable? cancellable) throws GLib.Error {
         var disk_path = get_user_unattended ("unattended.img");
         disk_file = File.new_for_path (disk_path);
diff --git a/src/wizard.vala b/src/wizard.vala
index ee3727d..a5ba4b8 100644
--- a/src/wizard.vala
+++ b/src/wizard.vala
@@ -293,6 +293,9 @@ private class Boxes.Wizard: Boxes.UI {
 
         return_if_fail (vm_creator != null);
 
+        vm_creator.install_media.bind_property ("user-data-for-vm-creation-available",
+                                                next_button, "sensitive",
+                                                BindingFlags.SYNC_CREATE);
         vm_creator.install_media.populate_setup_vbox (setup_vbox);
 
         return true;
@@ -304,7 +307,6 @@ private class Boxes.Wizard: Boxes.UI {
 
         if (vm_creator != null) {
             try {
-                vm_creator.install_media.check_needed_info ();
                 machine = yield vm_creator.create_vm (null);
             } catch (IOError.CANCELLED cancel_error) { // We did this, so ignore!
                 return false;



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