[gnome-boxes] wizard: update the URL page when entry is updated



commit b2add0bad1aa8fff4b041c01cdf0dcd23b9f612d
Author: Marc-Andrà Lureau <marcandre lureau gmail com>
Date:   Thu Feb 2 01:19:42 2012 +0100

    wizard: update the URL page when entry is updated
    
    Update the URL page depending on the URI.
    
    We currently do simple guesses based on simple URI parsing, but
    later on, we could query the URI to gather informations etc..
    
    https://bugzilla.gnome.org/show_bug.cgi?id=669409

 configure.ac           |    2 +-
 src/wizard-source.vala |   28 +++++++++++++++++++---------
 src/wizard.vala        |   44 ++++++++++++++++++++++++++++----------------
 3 files changed, 48 insertions(+), 26 deletions(-)
---
diff --git a/configure.ac b/configure.ac
index bf08f98..1b99bcb 100644
--- a/configure.ac
+++ b/configure.ac
@@ -48,7 +48,7 @@ GTK_VNC_MIN_VERSION=0.4.4
 LIBVIRT_GLIB_MIN_VERSION=0.0.4
 LIBVIRT_GCONFIG_MIN_VERSION=0.0.4
 LIBXML2_MIN_VERSION=2.7.8
-SPICE_GTK_MIN_VERSION=0.7.98
+SPICE_GTK_MIN_VERSION=0.9
 GUDEV_MIN_VERSION=147
 OSINFO_MIN_VERSION=0.0.6
 
diff --git a/src/wizard-source.vala b/src/wizard-source.vala
index 7bd4f64..dd65ccb 100644
--- a/src/wizard-source.vala
+++ b/src/wizard-source.vala
@@ -37,10 +37,13 @@ private class Boxes.WizardSource: GLib.Object {
 
     private Boxes.MenuBox menubox;
     private Gtk.Notebook notebook;
+    private Gtk.Label url_label;
+    private Gtk.Image url_image;
     public Gtk.Entry url_entry;
 
     public WizardSource () {
         notebook = new Gtk.Notebook ();
+        notebook.width_request = 500;
         notebook.get_style_context ().add_class ("boxes-source-nb");
         notebook.show_tabs = false;
 
@@ -84,20 +87,27 @@ private class Boxes.WizardSource: GLib.Object {
         url_entry = new Gtk.Entry ();
         hbox.add (url_entry);
         hbox = add_entry (menubox);
-        var image = new Gtk.Image.from_icon_name ("network-workgroup", 0);
+
+        url_image = new Gtk.Image.from_icon_name ("network-workgroup", 0);
         // var image = new Gtk.Image.from_icon_name ("krfb", 0);
-        image.pixel_size = 96;
-        hbox.pack_start (image, false, false);
-        label = new Gtk.Label (null);
-        label.xalign = 0.0f;
-        label.set_markup (_("<b>Desktop Access</b>\n\nWill add boxes for all systems available from this account."));
-        label.set_use_markup (true);
-        label.wrap = true;
-        hbox.pack_start (label, true, true);
+        url_image.pixel_size = 96;
+        hbox.pack_start (url_image, false, false);
+
+        url_label = new Gtk.Label (null);
+        url_label.xalign = 0.0f;
+        url_label.set_markup (_("<b>Desktop Access</b>\n\nWill add boxes for all systems available from this account."));
+        url_label.set_use_markup (true);
+        url_label.wrap = true;
+        hbox.pack_start (url_label, true, true);
 
         notebook.show_all ();
     }
 
+    public void update_url_page(string title, string text, string icon_name) {
+        url_label.set_markup ("<b>"  + title + "</b>\n\n" + text);
+        url_image.icon_name = icon_name;
+    }
+
     private Gtk.HBox add_entry (MenuBox box, ClickedFunc? clicked = null) {
         var hbox = new Gtk.HBox (false, 20);
         var item = new MenuBox.Item (hbox);
diff --git a/src/wizard.vala b/src/wizard.vala
index 798dab5..5f78203 100644
--- a/src/wizard.vala
+++ b/src/wizard.vala
@@ -109,9 +109,26 @@ private class Boxes.Wizard: Boxes.UI {
                 next_button.sensitive = false;
         });
         wizard_source.url_entry.changed.connect (() => {
-            // FIXME: add uri checker
             next_button.sensitive = wizard_source.uri.length != 0;
+
+            var text = _("Please enter desktop or collection URI");
+            var icon = "preferences-desktop-remote-desktop";
+            try {
+                prepare_for_location (this.wizard_source.uri, true);
+
+                if (source != null && source.source_type == "libvirt") {
+                    text = _("Will add boxes for all systems available from this account.");
+                    icon = "network-workgroup";
+                } else
+                    text = _("Will add a single box.");
+
+            } catch (GLib.Error error) {
+                // ignore any parsing error
+            }
+
+            wizard_source.update_url_page (_("Desktop Access"), text, icon);
         });
+
         wizard_source.url_entry.activate.connect(() => {
             page = page + 1;
         });
@@ -149,16 +166,19 @@ private class Boxes.Wizard: Boxes.UI {
         return true;
     }
 
-    private void prepare_for_location (string location) throws GLib.Error {
+    private void prepare_for_location (string location, bool probing = false) throws GLib.Error {
+        source = null;
+
         if (location == "")
             throw new Boxes.Error.INVALID ("empty location");
 
         var file = File.new_for_commandline_arg (location);
 
-        if (file.is_native ())
+        if (file.is_native ()) {
             // FIXME: We should able to handle non-local URIs here too
-            prepare_for_installer (file.get_path ());
-        else {
+            if (!probing)
+                prepare_for_installer (file.get_path ());
+        } else {
             bool uncertain;
             var uri = file.get_uri ();
 
@@ -177,16 +197,10 @@ private class Boxes.Wizard: Boxes.UI {
         if (uri == null || uri.server == null)
             throw new Boxes.Error.INVALID ("the URI is invalid");
 
-        source = new CollectionSource (uri.server, uri.scheme, uri_as_text);
+        source = new CollectionSource (uri.server ?? uri_as_text, uri.scheme, uri_as_text);
 
-        if (uri.scheme == "spice") {
-            if (uri.query_raw == null && uri.query == null)
-                throw new Boxes.Error.INVALID ("the Spice URI is incomplete");
-
-            if (uri.port > 0)
-                throw new Boxes.Error.INVALID ("the Spice URI is invalid");
-        } else if (uri.scheme == "vnc") {
-            // accept any vnc:// uri
+        if (uri.scheme == "spice" || uri.scheme == "vnc") {
+            // accept any spice:// or vnc:// uri
         } else
             throw new Boxes.Error.INVALID ("Unsupported protocol %s".printf (uri.scheme));
     }
@@ -220,8 +234,6 @@ private class Boxes.Wizard: Boxes.UI {
     }
 
     private void prepare () throws GLib.Error {
-        source = null;
-
         if (this.wizard_source.page == Boxes.SourcePage.URL ||
             this.wizard_source.page == Boxes.SourcePage.FILE)
             prepare_for_location (this.wizard_source.uri);



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