Support to show SSL status with URL color

This commit is contained in:
Florian Bruhin 2014-05-12 18:00:44 +02:00
parent 7c1ba7ab48
commit 512625cee1
5 changed files with 25 additions and 3 deletions

View File

@ -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)

View File

@ -50,7 +50,7 @@ class NetworkManager(QNetworkAccessManager):
for request in self._requests.values():
request.abort()
@pyqtSlot('QNetworkReply', 'QList<QSslError>')
@pyqtSlot('QNetworkReply*', 'QList<QSslError>')
def on_ssl_errors(self, reply, errors):
"""Decide if SSL errors should be ignored or not.

View File

@ -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<QSslError>')
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):

View File

@ -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<QSslError>')
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))

View File

@ -69,6 +69,7 @@ class WebView(QWebView):
scroll_pos_changed = pyqtSignal(int, int)
linkHovered = pyqtSignal(str, str, str)
ssl_errors = pyqtSignal('QNetworkReply*', 'QList<QSslError>')
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'))