From 7503fd68c560ba49f0c0e321699033afa8527cef Mon Sep 17 00:00:00 2001
From: Patrick McDermott <pj@pehjota.net>
Date: Sun, 17 Sep 2017 00:31:24 -0400
Subject: load_changed_cb(): New function

This completes the previous commit by hiding the progress bar once the
Web page finishes loading.

It also updates the URI bar when a new Web page is loaded.
---
(limited to 'src')

diff --git a/src/tab-chrome.c b/src/tab-chrome.c
index d71b5c1..6671835 100644
--- a/src/tab-chrome.c
+++ b/src/tab-chrome.c
@@ -88,6 +88,24 @@ mq_tab_chrome_get_container(MqTabChrome *chrome)
 }
 
 static void
+load_changed_cb(WebKitWebView *web_view, WebKitLoadEvent load_event,
+	MqTabChrome *chrome)
+{
+	switch (load_event) {
+		case WEBKIT_LOAD_STARTED:
+		case WEBKIT_LOAD_REDIRECTED:
+		case WEBKIT_LOAD_COMMITTED:
+			gtk_entry_set_text(GTK_ENTRY(chrome->uri_entry),
+				webkit_web_view_get_uri(web_view));
+			break;
+		case WEBKIT_LOAD_FINISHED:
+			gtk_entry_set_progress_fraction(
+				GTK_ENTRY(chrome->uri_entry), 0.0);
+			break;
+	}
+}
+
+static void
 load_progress_cb(WebKitWebView *web_view,
 	GParamSpec __attribute__((unused)) *paramspec, MqTabChrome *chrome)
 {
@@ -98,6 +116,8 @@ load_progress_cb(WebKitWebView *web_view,
 static void
 connect_web_view(MqTabChrome *chrome)
 {
+	g_signal_connect(chrome->web_view, "load-changed",
+		G_CALLBACK(load_changed_cb), chrome);
 	g_signal_connect(chrome->web_view, "notify::estimated-load-progress",
 		G_CALLBACK(load_progress_cb), chrome);
 }
--
cgit v0.9.1