[gnome-boxes] wizard-source: Use more convenient developers.redhat.com end-point



commit 8e56dcbe89d10df00caab49cfc35218d2b32cad4
Author: Debarshi Ray <debarshir gnome org>
Date:   Mon Nov 13 20:16:44 2017 +0100

    wizard-source: Use more convenient developers.redhat.com end-point
    
    https://bugzilla.gnome.org/show_bug.cgi?id=790305

 configure.ac             |    1 -
 data/ui/wizard-source.ui |   26 +-----
 meson.build              |    1 -
 src/Makefile.am          |    1 -
 src/meson.build          |    1 -
 src/wizard-source.vala   |  246 +++++-----------------------------------------
 6 files changed, 26 insertions(+), 250 deletions(-)
---
diff --git a/configure.ac b/configure.ac
index f67b5e7..5f47b93 100644
--- a/configure.ac
+++ b/configure.ac
@@ -79,7 +79,6 @@ PKG_CHECK_MODULES(BOXES, [
   libusb-1.0 >= $LIBUSB_MIN_VERSION
   spice-client-gtk-3.0 >= $SPICE_GTK_MIN_VERSION
   gudev-1.0 >= $GUDEV_MIN_VERSION
-  json-glib-1.0
   libosinfo-1.0 >= $OSINFO_MIN_VERSION
   libsoup-2.4 >= $LIBSOUP_REQUIRED
   libarchive >= $LIBARCHIVE_MIN_VERSION
diff --git a/data/ui/wizard-source.ui b/data/ui/wizard-source.ui
index b4054d9..18c87b3 100644
--- a/data/ui/wizard-source.ui
+++ b/data/ui/wizard-source.ui
@@ -301,30 +301,10 @@
 
     <!-- RHEL web view page -->
     <child>
-      <object class="GtkStack" id="rhel_web_view_stack">
+      <object class="BoxesWizardWebView" id="rhel_web_view">
+        <property name="hexpand">True</property>
+        <property name="vexpand">True</property>
         <property name="visible">True</property>
-        <child>
-          <object class="GtkSpinner" id="rhel_web_view_spinner">
-            <property name="halign">center</property>
-            <property name="valign">center</property>
-            <property name="visible">True</property>
-            <property name="width-request">32</property>
-            <property name="height-request">32</property>
-          </object>
-          <packing>
-            <property name="name">spinner</property>
-          </packing>
-        </child>
-        <child>
-          <object class="BoxesWizardWebView" id="rhel_web_view">
-            <property name="hexpand">True</property>
-            <property name="vexpand">True</property>
-            <property name="visible">True</property>
-          </object>
-          <packing>
-            <property name="name">web-view</property>
-          </packing>
-        </child>
       </object>
 
       <packing>
diff --git a/meson.build b/meson.build
index 31b7e88..32d981d 100644
--- a/meson.build
+++ b/meson.build
@@ -15,7 +15,6 @@ govirt = dependency ('govirt-1.0', version: '>= 0.3.4')
 gtk = dependency ('gtk+-3.0', version: '>= 3.19.8')
 gtk_vnc = dependency ('gtk-vnc-2.0', version: '>= 0.4.4')
 gudev = dependency ('gudev-1.0', version: '>= 165')
-json_glib = dependency ('json-glib-1.0')
 libarchive = dependency ('libarchive', version: '>= 3.0.0')
 libosinfo = dependency ('libosinfo-1.0', version: '>= 1.1.0')
 libsecret = dependency ('libsecret-1')
diff --git a/src/Makefile.am b/src/Makefile.am
index 551e611..129e1a2 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -31,7 +31,6 @@ AM_VALAFLAGS =                                                \
        --pkg glib-2.0                                  \
        --pkg gtk-vnc-2.0                               \
        --pkg gudev-1.0                                 \
-       --pkg json-glib-1.0                             \
        --pkg libarchive                                \
        --pkg libsecret-1                               \
        --pkg libsoup-2.4                               \
diff --git a/src/meson.build b/src/meson.build
index 85b1abd..97c9287 100644
--- a/src/meson.build
+++ b/src/meson.build
@@ -116,7 +116,6 @@ dependencies = [
   gobject,
   gtk,
   gtk_vnc,
-  json_glib,
   libgd_dep,
   libgd_vapi_dep,
   libsecret,
diff --git a/src/wizard-source.vala b/src/wizard-source.vala
index ee59d21..9c363cd 100644
--- a/src/wizard-source.vala
+++ b/src/wizard-source.vala
@@ -236,10 +236,6 @@ private class Boxes.WizardSource: Gtk.Stack {
     private Gtk.Image install_rhel_image;
     [GtkChild]
     private Boxes.WizardWebView rhel_web_view;
-    [GtkChild]
-    private Gtk.Spinner rhel_web_view_spinner;
-    [GtkChild]
-    private Gtk.Stack rhel_web_view_stack;
 
     private AppWindow window;
 
@@ -284,7 +280,6 @@ private class Boxes.WizardSource: Gtk.Stack {
         set {
             _page = value;
 
-            rhel_web_view_spinner.stop ();
             if (rhel_cancellable != null) {
                 rhel_cancellable.cancel ();
                 rhel_cancellable = null;
@@ -301,7 +296,6 @@ private class Boxes.WizardSource: Gtk.Stack {
                 main_vbox.grab_focus ();
                 break;
             case SourcePage.RHEL_WEB_VIEW:
-                rhel_web_view_stack.set_visible_child_name ("spinner");
                 break;
             case SourcePage.URL:
                 url_entry.changed ();
@@ -516,230 +510,23 @@ private class Boxes.WizardSource: Gtk.Stack {
         }
     }
 
-    private string rhel_get_authentication_uri_from_json (string contents) throws GLib.Error
-        requires (contents.length > 0) {
-
-        var parser = new Json.Parser ();
-        parser.load_from_data (contents, -1);
-
-        Json.NodeType node_type = Json.NodeType.NULL;
-
-        var root_node = parser.get_root ();
-        node_type = root_node.get_node_type ();
-        if (node_type != Json.NodeType.ARRAY)
-            throw new Boxes.Error.INVALID ("Failed to parse JSON: couldn’t find root array");
-
-        var root_array = root_node.get_array ();
-        if (root_array == null)
-            throw new Boxes.Error.INVALID ("Failed to parse JSON: couldn’t find root array");
-        if (root_array.get_length () == 0)
-            throw new Boxes.Error.INVALID ("Failed to parse JSON: root array is empty");
-
-        var root_array_node_0 = root_array.get_element (0);
-        node_type = root_array_node_0.get_node_type ();
-        if (node_type != Json.NodeType.OBJECT)
-            throw new Boxes.Error.INVALID ("Failed to parse JSON: root array doesn’t have an object");
-
-        var root_array_object_0 = root_array_node_0.get_object ();
-
-        var product_code_node = root_array_object_0.get_member ("productCode");
-        if (product_code_node == null)
-            throw new Boxes.Error.INVALID ("Failed to parse JSON: couldn’t find productCode");
-        node_type = product_code_node.get_node_type ();
-        if (node_type != Json.NodeType.VALUE)
-            throw new Boxes.Error.INVALID ("Failed to parse JSON: productCode is not a VALUE");
-
-        var product_code = product_code_node.get_string ();
-        if (product_code != "rhel")
-            throw new Boxes.Error.INVALID ("Failed to parse JSON: productCode is not rhel");
-
-        var featured_artifact_node = root_array_object_0.get_member ("featuredArtifact");
-        if (featured_artifact_node == null)
-            throw new Boxes.Error.INVALID ("Failed to parse JSON: couldn’t find featuredArtifact");
-        node_type = featured_artifact_node.get_node_type ();
-        if (node_type != Json.NodeType.OBJECT)
-            throw new Boxes.Error.INVALID ("Failed to parse JSON: featuredArtifact is not an OBJECT");
-
-        var featured_artifact_object = featured_artifact_node.get_object ();
-
-        var url_node = featured_artifact_object.get_member ("url");
-        if (url_node == null)
-            throw new Boxes.Error.INVALID ("Failed to parse JSON: couldn’t find featuredArtifact.url");
-        node_type = url_node.get_node_type ();
-        if (node_type != Json.NodeType.VALUE)
-            throw new Boxes.Error.INVALID ("Failed to parse JSON: featuredArtifact.url is not a VALUE");
-
-        var url = url_node.get_string ();
-        if (url == null || url.length == 0)
-            throw new Boxes.Error.INVALID ("Failed to parse JSON: featuredArtifact.url is empty");
-
-        return url;
-    }
-
-    private string rhel_get_authentication_uri_from_xml (string contents) throws GLib.Error
-        requires (contents.length > 0) {
-
-        var product_code = extract_xpath (contents, "string(/products/product/productCode)", true);
-        if (product_code != "rhel")
-            throw new Boxes.Error.INVALID ("Failed to parse XML: productCode is not rhel");
-
-        var url = extract_xpath (contents, "string(/products/product/featuredArtifact/url)", true);
-        if (url.length == 0)
-            throw new Boxes.Error.INVALID ("Failed to parse XML: featuredArtifact.url is empty");
-
-        return url;
-    }
-
-    private void rhel_show_web_view (string cached_path, bool use_cache) {
-        if (!use_cache) {
-            GLib.FileUtils.unlink (cached_path);
-            rhel_web_view_spinner.start ();
-        }
-
-        var downloader = Downloader.get_instance ();
-        var file = GLib.File.new_for_uri 
("https://developers.redhat.com/download-manager/rest/available/rhel";);
-        string[] cached_paths = { cached_path };
-        var progress = new ActivityProgress ();
-        downloader.download.begin (file, cached_paths, progress, rhel_cancellable, (obj, res) => {
-            try {
-                file = downloader.download.end (res);
-            } catch (GLib.IOError.CANCELLED error) {
-                return;
-            } catch (GLib.Error error) {
-                page = SourcePage.MAIN;
-                window.notificationbar.display_error (_("Failed to get authentication URI"));
-                warning (error.message);
-                return;
-            }
-
-            file.load_contents_async.begin (rhel_cancellable, (obj, res) => {
-                uint8[] contents;
-                try {
-                    file.load_contents_async.end (res, out contents, null);
-                } catch (GLib.IOError.CANCELLED error) {
-                    return;
-                } catch (GLib.Error error) {
-                    page = SourcePage.MAIN;
-                    window.notificationbar.display_error (_("Failed to parse response from redhat.com"));
-                    warning (error.message);
-                    return;
-                }
-
-                if (contents.length <= 0) {
-                    if (use_cache) {
-                        rhel_show_web_view (cached_path, false);
-                    } else {
-                        page = SourcePage.MAIN;
-                        window.notificationbar.display_error (_("Failed to parse response from redhat.com"));
-                        warning ("Empty response from redhat.com");
-                    }
-                    return;
-                }
-
-                string? authentication_uri;
-                try {
-                    authentication_uri = rhel_get_authentication_uri_from_json ((string) contents);
-                } catch (Boxes.Error error) {
-                    if (use_cache) {
-                        rhel_show_web_view (cached_path, false);
-                    } else {
-                        page = SourcePage.MAIN;
-                        window.notificationbar.display_error (_("Failed to parse response from redhat.com"));
-                        warning (error.message);
-                    }
-                    return;
-                } catch (GLib.Error json_error) {
-                    debug ("Failed to parse as JSON, could be XML: %s", json_error.message);
-                    try {
-                        authentication_uri = rhel_get_authentication_uri_from_xml ((string) contents);
-                    } catch (GLib.Error xml_error) {
-                        if (use_cache) {
-                            rhel_show_web_view (cached_path, false);
-                        } else {
-                            page = SourcePage.MAIN;
-                            window.notificationbar.display_error (_("Failed to parse response from 
redhat.com"));
-                            warning (xml_error.message);
-                        }
-                        return;
-                    }
-                }
-
-                debug ("RHEL ISO authentication URI: %s", authentication_uri);
-
-                rhel_cancellable = new GLib.Cancellable ();
-                rhel_cancellable.connect(() => {
-                    rhel_web_view.view.stop_loading ();
-                    rhel_web_view.view.load_uri ("about:blank");
-
-                    var data_manager = rhel_web_view.view.get_website_data_manager ();
-                    data_manager.clear.begin (WebKit.WebsiteDataTypes.COOKIES, 0, null);
-                });
-
-                if (rhel_web_view_spinner.active) {
-                    rhel_web_view_stack.set_visible_child_full ("web-view", 
Gtk.StackTransitionType.CROSSFADE);
-                    rhel_web_view_spinner.stop ();
-                } else {
-                    rhel_web_view_stack.set_visible_child_name ("web-view");
-                }
-
-                rhel_web_view.view.load_uri (authentication_uri);
-                filename = GLib.Path.get_basename (authentication_uri);
-            });
-        });
-    }
-
     [GtkCallback]
     private void on_install_rhel_button_clicked () {
         page = SourcePage.RHEL_WEB_VIEW;
-        rhel_cancellable = new GLib.Cancellable ();
 
-        var cached_path = get_cache ("developers.redhat.com", "rhel");
-        var cached_file = GLib.File.new_for_path (cached_path);
-        cached_file.query_info_async.begin (GLib.FileAttribute.TIME_MODIFIED,
-                                            GLib.FileQueryInfoFlags.NONE,
-                                            GLib.Priority.DEFAULT,
-                                            rhel_cancellable,
-                                            (obj, res) => {
-            GLib.FileInfo? info;
-            try {
-                info = cached_file.query_info_async.end (res);
-            } catch (GLib.IOError.CANCELLED error) {
-                return;
-            } catch (GLib.IOError.NOT_FOUND error) {
-                debug ("No cached response from redhat.com");
-                rhel_show_web_view (cached_path, false);
-                return;
-            } catch (GLib.Error error) {
-                warning ("Failed to find cached response from redhat.com: %s", error.message);
-                rhel_show_web_view (cached_path, false);
-                return;
-            }
-
-            var mtime_timeval = info.get_modification_time ();
-            GLib.DateTime? mtime = new GLib.DateTime.from_timeval_utc (mtime_timeval);
-            if (mtime == null) {
-                warning ("Cached response from redhat.com has invalid modification time");
-                rhel_show_web_view (cached_path, false);
-                return;
-            }
+        rhel_cancellable = new GLib.Cancellable ();
+        rhel_cancellable.connect(() => {
+            rhel_web_view.view.stop_loading ();
+            rhel_web_view.view.load_uri ("about:blank");
 
-            GLib.DateTime? now = new GLib.DateTime.now_utc ();
-            if (now == null) {
-                warning ("Failed to read current time");
-                rhel_show_web_view (cached_path, false);
-                return;
-            }
+            var data_manager = rhel_web_view.view.get_website_data_manager ();
+            data_manager.clear.begin (WebKit.WebsiteDataTypes.COOKIES, 0, null);
+        });
 
-            var time_difference = now.difference (mtime);
-            if (time_difference > GLib.TimeSpan.DAY) {
-                debug ("Cached response from redhat.com is more than a day old");
-                rhel_show_web_view (cached_path, false);
-                return;
-            }
+        var authentication_uri = "https://developers.redhat.com/download-manager/rest/featured/file/rhel";;
+        debug ("RHEL ISO authentication URI: %s", authentication_uri);
 
-            debug ("Cached response from redhat.com is less than a day old");
-            rhel_show_web_view (cached_path, true);
-        });
+        rhel_web_view.view.load_uri (authentication_uri);
     }
 
     private bool on_rhel_web_view_decide_policy (WebKit.WebView web_view,
@@ -789,6 +576,19 @@ private class Boxes.WizardSource: Gtk.Stack {
             }
         }
 
+        var soup_download_uri = new Soup.URI (download_uri);
+        var download_path = soup_download_uri.get_path ();
+
+        // Libsoup is supposed to ensure that the path is at least "/".
+        return_val_if_fail (download_path != null, false);
+        return_val_if_fail (download_path.length > 0, false);
+
+        if (!download_path.has_suffix (".iso")) {
+            download_path = "/rhel.iso";
+        }
+
+        filename = GLib.Path.get_basename (download_path);
+
         uri = download_uri;
         activated ();
 


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