[gnome-boxes/wip/rishi/rhel: 14/15] wizard-source: Add a WebView with progress indication
- From: Debarshi Ray <debarshir src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-boxes/wip/rishi/rhel: 14/15] wizard-source: Add a WebView with progress indication
- Date: Mon, 25 Sep 2017 16:26:36 +0000 (UTC)
commit b6d00fe81725404bfabfce117cf5b5c1845f5439
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 | 35 ++++++++++++++
src/wizard-source.vala | 100 ++++++++++++++++++++++++++++++++++++++++
3 files changed, 136 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..8f74105
--- /dev/null
+++ b/data/ui/wizard-web-view.ui
@@ -0,0 +1,35 @@
+<?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="context-menu" handler="on_context_menu" />
+ <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 1abfd48..1fba644 100644
--- a/src/wizard-source.vala
+++ b/src/wizard-source.vala
@@ -94,6 +94,106 @@ 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 bool on_context_menu (WebKit.WebView web_view,
+ WebKit.ContextMenu context_menu,
+ Gdk.Event event,
+ WebKit.HitTestResult hit_test_result) {
+ var items_to_remove = new GLib.List<WebKit.ContextMenuItem> ();
+
+ foreach (var item in context_menu.get_items ()) {
+ var action = item.get_stock_action ();
+ if (action == WebKit.ContextMenuAction.GO_BACK ||
+ action == WebKit.ContextMenuAction.GO_FORWARD ||
+ action == WebKit.ContextMenuAction.DOWNLOAD_AUDIO_TO_DISK ||
+ action == WebKit.ContextMenuAction.DOWNLOAD_IMAGE_TO_DISK ||
+ action == WebKit.ContextMenuAction.DOWNLOAD_LINK_TO_DISK ||
+ action == WebKit.ContextMenuAction.DOWNLOAD_VIDEO_TO_DISK ||
+ action == WebKit.ContextMenuAction.OPEN_AUDIO_IN_NEW_WINDOW ||
+ action == WebKit.ContextMenuAction.OPEN_FRAME_IN_NEW_WINDOW ||
+ action == WebKit.ContextMenuAction.OPEN_IMAGE_IN_NEW_WINDOW ||
+ action == WebKit.ContextMenuAction.OPEN_LINK_IN_NEW_WINDOW ||
+ action == WebKit.ContextMenuAction.OPEN_VIDEO_IN_NEW_WINDOW ||
+ action == WebKit.ContextMenuAction.RELOAD ||
+ action == WebKit.ContextMenuAction.STOP) {
+ items_to_remove.prepend (item);
+ }
+ }
+
+ foreach (var item in items_to_remove) {
+ context_menu.remove (item);
+ }
+
+ var separators_to_remove = new GLib.List<WebKit.ContextMenuItem> ();
+ WebKit.ContextMenuAction previous_action = WebKit.ContextMenuAction.NO_ACTION; // same as a separator
+
+ foreach (var item in context_menu.get_items ()) {
+ var action = item.get_stock_action ();
+ if (action == WebKit.ContextMenuAction.NO_ACTION && action == previous_action)
+ separators_to_remove.prepend (item);
+
+ previous_action = action;
+ }
+
+ foreach (var item in separators_to_remove) {
+ context_menu.remove (item);
+ }
+
+ var n_items = context_menu.get_n_items ();
+ return n_items == 0;
+ }
+
+ [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]