From 512625cee105762dcaa97a9589c1c51880ed2321 Mon Sep 17 00:00:00 2001 From: Florian Bruhin Date: Mon, 12 May 2014 18:00:44 +0200 Subject: [PATCH] Support to show SSL status with URL color --- qutebrowser/app.py | 2 ++ qutebrowser/network/networkmanager.py | 2 +- qutebrowser/widgets/_statusbar.py | 19 +++++++++++++++++-- qutebrowser/widgets/_tabbedbrowser.py | 3 +++ qutebrowser/widgets/webview.py | 2 ++ 5 files changed, 25 insertions(+), 3 deletions(-) diff --git a/qutebrowser/app.py b/qutebrowser/app.py index 5411b41bf..ba8851b91 100644 --- a/qutebrowser/app.py +++ b/qutebrowser/app.py @@ -346,7 +346,9 @@ class QuteBrowser(QApplication): # statusbar tabs.cur_progress.connect(status.prog.setValue) tabs.cur_load_finished.connect(status.prog.hide) + tabs.cur_load_started.connect(status.url.on_loading_started) tabs.cur_load_finished.connect(status.url.on_loading_finished) + tabs.cur_ssl_errors.connect(status.url.on_ssl_errors) tabs.cur_load_started.connect(status.prog.on_load_started) tabs.cur_scroll_perc_changed.connect(status.percentage.set_perc) tabs.cur_statusbar_message.connect(status.txt.on_statusbar_message) diff --git a/qutebrowser/network/networkmanager.py b/qutebrowser/network/networkmanager.py index bb6ac8ce7..b97fef601 100644 --- a/qutebrowser/network/networkmanager.py +++ b/qutebrowser/network/networkmanager.py @@ -50,7 +50,7 @@ class NetworkManager(QNetworkAccessManager): for request in self._requests.values(): request.abort() - @pyqtSlot('QNetworkReply', 'QList') + @pyqtSlot('QNetworkReply*', 'QList') def on_ssl_errors(self, reply, errors): """Decide if SSL errors should be ignored or not. diff --git a/qutebrowser/widgets/_statusbar.py b/qutebrowser/widgets/_statusbar.py index 21269050d..51d29ed64 100644 --- a/qutebrowser/widgets/_statusbar.py +++ b/qutebrowser/widgets/_statusbar.py @@ -601,6 +601,7 @@ class _Url(TextBase): _old_urltype: The type of the URL displayed before the hover URL. _urltype: The current URL type. One of normal/ok/error/warn/hover. Accessed via the urltype property. + _ssl_errors: Whether SSL errors occured while loading. """ STYLESHEET = """ @@ -638,6 +639,7 @@ class _Url(TextBase): self._urltype = None self._old_urltype = None self._old_url = None + self._ssl_errors = False @pyqtProperty(str) def urltype(self): @@ -651,6 +653,15 @@ class _Url(TextBase): self._urltype = val self.setStyleSheet(get_stylesheet(self.STYLESHEET)) + @pyqtSlot() + def on_loading_started(self): + """Slot to clear SSL errors when loading started.""" + self._ssl_errors = False + + @pyqtSlot('QNetworkReply*', 'QList') + def on_ssl_errors(self, _reply, _errors): + self._ssl_errors = True + @pyqtSlot(bool) def on_loading_finished(self, ok): """Slot for cur_loading_finished. Colors the URL according to ok. @@ -658,8 +669,12 @@ class _Url(TextBase): Args: ok: Whether loading finished successfully (True) or not (False). """ - # FIXME: set color to warn if there was an SSL error - self.urltype = 'success' if ok else 'error' + if ok and not self._ssl_errors: + self.urltype = 'success' + elif ok: + self.urltype = 'warn' + else: + self.urltype = 'error' @pyqtSlot(str) def set_url(self, s): diff --git a/qutebrowser/widgets/_tabbedbrowser.py b/qutebrowser/widgets/_tabbedbrowser.py index a2aaeb0bb..0d3462faa 100644 --- a/qutebrowser/widgets/_tabbedbrowser.py +++ b/qutebrowser/widgets/_tabbedbrowser.py @@ -61,6 +61,7 @@ class TabbedBrowser(TabWidget): cur_progress: Progress of the current tab changed (loadProgress). cur_load_started: Current tab started loading (loadStarted) cur_load_finished: Current tab finished loading (loadFinished) + cur_ssl_errors: Current tab encountered SSL errors. cur_statusbar_message: Current tab got a statusbar message (statusBarMessage) cur_url_changed: Current URL changed (urlChanged) @@ -84,6 +85,7 @@ class TabbedBrowser(TabWidget): cur_url_changed = pyqtSignal('QUrl') cur_link_hovered = pyqtSignal(str, str, str) cur_scroll_perc_changed = pyqtSignal(int, int) + cur_ssl_errors = pyqtSignal('QNetworkReply*', 'QList') hint_strings_updated = pyqtSignal(list) shutdown_complete = pyqtSignal() quit = pyqtSignal() @@ -126,6 +128,7 @@ class TabbedBrowser(TabWidget): tab.linkHovered.connect(self._filter.create(self.cur_link_hovered)) tab.loadProgress.connect(self._filter.create(self.cur_progress)) tab.loadFinished.connect(self._filter.create(self.cur_load_finished)) + tab.ssl_errors.connect(self._filter.create(self.cur_ssl_errors)) tab.page().mainFrame().loadStarted.connect(partial( self.on_load_started, tab)) tab.loadStarted.connect(self._filter.create(self.cur_load_started)) diff --git a/qutebrowser/widgets/webview.py b/qutebrowser/widgets/webview.py index 11b6d0165..ad97add1d 100644 --- a/qutebrowser/widgets/webview.py +++ b/qutebrowser/widgets/webview.py @@ -69,6 +69,7 @@ class WebView(QWebView): scroll_pos_changed = pyqtSignal(int, int) linkHovered = pyqtSignal(str, str, str) + ssl_errors = pyqtSignal('QNetworkReply*', 'QList') def __init__(self, parent): super().__init__(parent) @@ -88,6 +89,7 @@ class WebView(QWebView): self.signal_cache = SignalCache(uncached=['linkHovered']) self.page_.setLinkDelegationPolicy(QWebPage.DelegateAllLinks) self.page_.linkHovered.connect(self.linkHovered) + self.page_.networkAccessManager().sslErrors.connect(self.ssl_errors) self.linkClicked.connect(self.on_link_clicked) self.page_.mainFrame().loadStarted.connect( lambda: modeman.maybe_leave('insert', 'load started'))