[gnome-boxes/wip/rishi/rhel: 17/18] wizard-source: Add a WebView with progress indication



commit a982ed528bc836bc0ffc70a1643736d6b5048d18
Author: Debarshi Ray <debarshir gnome org>
Date:   Fri Sep 15 17:31:09 2017 +0200

    wizard-source: Add a WebView with progress indication
    
    In a following patch, this will be used to download a gratis,
    unsupported copy of Red Hat Enterprise Linux.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=786679

 data/gnome-boxes.gresource.xml |    1 +
 data/ui/wizard-web-view.ui     |   34 ++++++++++++++++++++++++++
 src/wizard-source.vala         |   51 ++++++++++++++++++++++++++++++++++++++++
 3 files changed, 86 insertions(+), 0 deletions(-)
---
diff --git a/data/gnome-boxes.gresource.xml b/data/gnome-boxes.gresource.xml
index 751e6e2..40eaba1 100644
--- a/data/gnome-boxes.gresource.xml
+++ b/data/gnome-boxes.gresource.xml
@@ -36,6 +36,7 @@
     <file preprocess="xml-stripblanks">ui/wizard-source.ui</file>
     <file preprocess="xml-stripblanks">ui/wizard-summary.ui</file>
     <file preprocess="xml-stripblanks">ui/wizard-toolbar.ui</file>
+    <file preprocess="xml-stripblanks">ui/wizard-web-view.ui</file>
     <file preprocess="xml-stripblanks">ui/wizard-window.ui</file>
   </gresource>
 </gresources>
diff --git a/data/ui/wizard-web-view.ui b/data/ui/wizard-web-view.ui
new file mode 100644
index 0000000..c9ba6ef
--- /dev/null
+++ b/data/ui/wizard-web-view.ui
@@ -0,0 +1,34 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<interface>
+  <template class="BoxesWizardWebView" parent="GtkBin">
+    <property name="visible">True</property>
+    <child>
+      <object class="GtkOverlay" id="overlay">
+        <property name="visible">True</property>
+
+        <child type="overlay">
+          <object class="GtkProgressBar" id="progress_bar">
+            <property name="no-show-all">True</property>
+            <property name="valign">start</property>
+            <style>
+              <class name="osd"/>
+            </style>
+          </object>
+        </child>
+
+        <child>
+          <!-- https://bugzilla.gnome.org/show_bug.cgi?id=786932 -->
+          <!-- https://bugzilla.gnome.org/show_bug.cgi?id=787033 -->
+          <!-- https://bugs.webkit.org/show_bug.cgi?id=175937 -->
+          <object class="WebKitWebView" type-func="webkit_web_view_get_type" id="web_view">
+            <property name="hexpand">True</property>
+            <property name="vexpand">True</property>
+            <property name="visible">True</property>
+            <signal name="notify::estimated-load-progress" handler="on_notify_estimated_load_progress" />
+          </object>
+        </child>
+
+      </object>
+    </child>
+  </template>
+</interface>
diff --git a/src/wizard-source.vala b/src/wizard-source.vala
index aeb1cbc..bb27efb 100644
--- a/src/wizard-source.vala
+++ b/src/wizard-source.vala
@@ -94,6 +94,57 @@ private class Boxes.WizardMediaEntry : Gtk.Button {
     }
 }
 
+[GtkTemplate (ui = "/org/gnome/Boxes/ui/wizard-web-view.ui")]
+private class Boxes.WizardWebView : Gtk.Bin {
+    [GtkChild]
+    private Gtk.ProgressBar progress_bar;
+    [GtkChild]
+    private WebKit.WebView web_view;
+
+    private uint hide_progress_bar_id;
+    private const uint progress_bar_id_timeout = 500;  // 500ms
+
+    public WebKit.WebView view {
+        get { return web_view; }
+    }
+
+    public override void dispose () {
+        if (hide_progress_bar_id != 0) {
+            GLib.Source.remove (hide_progress_bar_id);
+            hide_progress_bar_id = 0;
+        }
+
+        base.dispose ();
+    }
+
+    [GtkCallback]
+    private void on_notify_estimated_load_progress () {
+        if (hide_progress_bar_id != 0) {
+            GLib.Source.remove (hide_progress_bar_id);
+            hide_progress_bar_id = 0;
+        }
+
+        string? uri = web_view.get_uri ();
+        if (uri == null || uri == "about:blank")
+            return;
+
+        var progress = web_view.get_estimated_load_progress ();
+        bool loading = web_view.is_loading;
+
+        if (progress == 1.0 || !loading) {
+            hide_progress_bar_id = GLib.Timeout.add (progress_bar_id_timeout, () => {
+                progress_bar.hide ();
+                hide_progress_bar_id = 0;
+                return GLib.Source.REMOVE;
+            });
+        } else {
+            progress_bar.show ();
+        }
+
+        progress_bar.set_fraction (loading || progress == 1.0 ? progress : 0.0);
+    }
+}
+
 [GtkTemplate (ui = "/org/gnome/Boxes/ui/wizard-source.ui")]
 private class Boxes.WizardSource: Gtk.Stack {
     private const string[] page_names = { "main-page", "url-page" };


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