From 6538dbbdf15fd5f66949b0805755ea24e10679de Mon Sep 17 00:00:00 2001 From: Florian Bruhin Date: Thu, 13 Feb 2014 06:58:17 +0100 Subject: [PATCH] Colorize URLs in statusbar, fix hovering. Before, when hovering from an URL to another URL, the old hover-URL was saved as old-url. This is now fixed. --- qutebrowser/utils/config.py | 5 +++ qutebrowser/widgets/mainwindow.py | 2 ++ qutebrowser/widgets/statusbar.py | 59 ++++++++++++++++++++++++++++--- 3 files changed, 62 insertions(+), 4 deletions(-) diff --git a/qutebrowser/utils/config.py b/qutebrowser/utils/config.py index 239137e4a..c46d95dfd 100644 --- a/qutebrowser/utils/config.py +++ b/qutebrowser/utils/config.py @@ -102,6 +102,11 @@ statusbar.progress.bg.error = red statusbar.bg = black statusbar.fg = white statusbar.bg.error = red +statusbar.url.fg = ${statusbar.fg} +statusbar.url.fg.success = lime +statusbar.url.fg.error = orange +statusbar.url.fg.warn = yellow +statusbar.url.fg.hover = aqua tab.bg = grey tab.bg.selected = black tab.fg = white diff --git a/qutebrowser/widgets/mainwindow.py b/qutebrowser/widgets/mainwindow.py index 398179d91..55a399f31 100644 --- a/qutebrowser/widgets/mainwindow.py +++ b/qutebrowser/widgets/mainwindow.py @@ -60,6 +60,8 @@ class MainWindow(QWidget): self.status.moved.connect(self.completion.move_to_bar) self.tabs.cur_progress.connect(self.status.prog.setValue) self.tabs.cur_load_finished.connect(self.status.prog.load_finished) + self.tabs.cur_load_finished.connect( + self.status.url.on_loading_finished) self.tabs.cur_load_started.connect(self.status.prog.on_load_started) self.tabs.cur_scroll_perc_changed.connect( self.status.percentage.set_perc) diff --git a/qutebrowser/widgets/statusbar.py b/qutebrowser/widgets/statusbar.py index 81e5fef39..db6c88110 100644 --- a/qutebrowser/widgets/statusbar.py +++ b/qutebrowser/widgets/statusbar.py @@ -456,26 +456,77 @@ class Url(TextBase): """URL displayed in the statusbar.""" - old_url = '' + _old_url = None + _old_urltype = None + _urltype = None # 'normal', 'ok', 'error', 'warn, 'hover' + + _stylesheet = """ + QLabel#Url[urltype="normal"] {{ + {color[statusbar.url.fg]} + }} + + QLabel#Url[urltype="success"] {{ + {color[statusbar.url.fg.success]} + }} + + QLabel#Url[urltype="error"] {{ + {color[statusbar.url.fg.error]} + }} + + QLabel#Url[urltype="warn"] {{ + {color[statusbar.url.fg.warn]} + }} + + QLabel#Url[urltype="hover"] {{ + {color[statusbar.url.fg.hover]} + }} + """ def __init__(self, bar, elidemode=Qt.ElideMiddle): """Override TextBase::__init__ to elide in the middle by default.""" super().__init__(bar, elidemode) + self.setObjectName(self.__class__.__name__) + self.setStyleSheet(config.get_stylesheet(self._stylesheet)) + + @pyqtProperty(str) + def urltype(self): + """Getter for self.urltype, so it can be used as Qt property.""" + # pylint: disable=method-hidden + return self._urltype + + @urltype.setter + def urltype(self, val): + """Setter for self.urltype, so it can be used as Qt property.""" + self._urltype = val + self.setStyleSheet(config.get_stylesheet(self._stylesheet)) + + def on_loading_finished(self, ok): + """Slot for cur_loading_finished. Colors the URL according to ok.""" + # FIXME: set color to warn if there was an SSL error + self.urltype = 'success' if ok else 'error' def set_url(self, s): """Setter to be used as a Qt slot.""" self.setText(urlstring(s)) + self.urltype = 'normal' def set_hover_url(self, link, title, text): """Setter to be used as a Qt slot. - Saves old shown URL in self.old_url and restores it later if a link is + Saves old shown URL in self._old_url and restores it later if a link is "un-hovered" when it gets called with empty parameters. """ # pylint: disable=unused-argument if link: - self.old_url = self.text() + if self._old_url is None: + self._old_url = self.text() + if self._old_urltype is None: + self._old_urltype = self._urltype + self.urltype = 'hover' self.setText(link) else: - self.setText(self.old_url) + self.setText(self._old_url) + self.urltype = self._old_urltype + self._old_url = None + self._old_urltype = None