From d1635b36d00b7239cbebcf9f78e9c8615ac1d7d5 Mon Sep 17 00:00:00 2001
From: Aqua-sama <aqua@iserlohn-fortress.net>
Date: Wed, 31 Jan 2018 12:30:51 +0100
Subject: Fixed bug where refresh button and loading bar would get stuck in
 loading state

---
 src/mainwindow/widgets/loadingbar.cpp    | 5 ++++-
 src/mainwindow/widgets/loadingbar.h      | 2 +-
 src/mainwindow/widgets/navigationbar.cpp | 3 ++-
 3 files changed, 7 insertions(+), 3 deletions(-)

(limited to 'src/mainwindow')

diff --git a/src/mainwindow/widgets/loadingbar.cpp b/src/mainwindow/widgets/loadingbar.cpp
index 2c12371..76eafc4 100644
--- a/src/mainwindow/widgets/loadingbar.cpp
+++ b/src/mainwindow/widgets/loadingbar.cpp
@@ -22,6 +22,7 @@ void LoadingBar::connectWebView(WebView *view)
 
     disconnect(loadStartedConnection);
     disconnect(loadProgressConnection);
+    disconnect(loadedConnection);
     disconnect(loadFinishedConnection);
 
     if(view->isLoaded()) {
@@ -33,6 +34,9 @@ void LoadingBar::connectWebView(WebView *view)
 
     loadStartedConnection = connect(view, &QWebEngineView::loadStarted, this, &LoadingBar::loadStarted);
     loadProgressConnection = connect(view, &QWebEngineView::loadProgress, this, &QProgressBar::setValue);
+    loadedConnection = connect(view, &WebView::loaded, this, [this]() {
+        QTimer::singleShot(2000, this, &LoadingBar::hide);
+    });
     loadFinishedConnection = connect(view, &QWebEngineView::loadFinished, this, &LoadingBar::loadFinished);
 }
 
@@ -46,5 +50,4 @@ void LoadingBar::loadStarted()
 void LoadingBar::loadFinished(bool ok)
 {
     setFormat(QString("%p% %1").arg(ok ? tr("Finished") : tr("Failed")));
-    QTimer::singleShot(2000, this, SLOT(hide()));
 }
diff --git a/src/mainwindow/widgets/loadingbar.h b/src/mainwindow/widgets/loadingbar.h
index b03a25e..f75e72b 100644
--- a/src/mainwindow/widgets/loadingbar.h
+++ b/src/mainwindow/widgets/loadingbar.h
@@ -24,7 +24,7 @@ private slots:
     void loadFinished(bool ok);
 
 private:
-    QMetaObject::Connection loadStartedConnection, loadProgressConnection, loadFinishedConnection;
+    QMetaObject::Connection loadStartedConnection, loadProgressConnection, loadedConnection, loadFinishedConnection;
 };
 
 #endif // LOADINGBAR_H
diff --git a/src/mainwindow/widgets/navigationbar.cpp b/src/mainwindow/widgets/navigationbar.cpp
index 93711e1..e488d77 100644
--- a/src/mainwindow/widgets/navigationbar.cpp
+++ b/src/mainwindow/widgets/navigationbar.cpp
@@ -9,6 +9,7 @@
 #include "navigationbar.h"
 #include "mainwindow/mainwindow.h"
 #include <QHBoxLayout>
+#include <QMenu>
 #include <QShortcut>
 #include <QStyle>
 #include <QToolBar>
@@ -112,7 +113,7 @@ void NavigationBar::connectWebView(WebView *view)
     }
 
     loadStartedConnection = connect(view, &QWebEngineView::loadStarted, this, &NavigationBar::update_loadStarted);
-    loadFinishedConnection = connect(view, &QWebEngineView::loadFinished, this, &NavigationBar::update_loadFinished);
+    loadFinishedConnection = connect(view, &WebView::loaded, this, &NavigationBar::update_loadFinished);
 }
 
 void NavigationBar::update_loadStarted()
-- 
cgit v1.2.1