diff options
Diffstat (limited to 'browser.py')
-rwxr-xr-x | browser.py | 19 |
1 files changed, 10 insertions, 9 deletions
@@ -20,42 +20,43 @@ class GViewport(QtWidgets.QTextBrowser): def mouseMoveEvent(self, event): cur = self.cursorForPosition(event.localPos().toPoint()) hover_url = cur.charFormat().anchorHref() - hover_url = gemini.absolute_url(self._current_url, QtCore.QUrl(hover_url)) + hover_url = gemini.urljoin(self._current_url, hover_url) if hover_url != self._hover_url: self._hover_url = hover_url - self.hoverUrlChanged.emit(self._hover_url.toString()) + self.hoverUrlChanged.emit(self._hover_url) return super().mouseMoveEvent(event) def loadResource(self, type_, url): + current_url = QtCore.QUrl(self._current_url) if self._last_redirect[0].toString() == url.toString(): gem = self._last_redirect[1] else: if not url.scheme(): - url.setScheme(self._current_url.scheme()) + url.setScheme(current_url.scheme()) if not url.host(): - url.setHost(self._current_url.host()) + url.setHost(current_url.host()) if url.port() == -1: url.setPort(1965) if not url.path().startswith('/'): - url.setPath(self._current_url.path().rsplit('/', 1)[0] + '/' + url.path()) - gem = gemini.get(gemini.absolute_url(self._current_url, url)) + url.setPath(current_url.path().rsplit('/', 1)[0] + '/' + url.path()) + gem = gemini.get(gemini.urljoin(current_url.toString(), url.toString())) if 'body' in gem: html = gemini.gem2html(gem['body']) else: html = '<h1>{} {}</h1>'.format(gem['status'], gem['meta']) - self._current_url = url + self._current_url = url.toString() return html def setSource(self, url): if url.scheme() != 'gemini': return - gem = gemini.get(gemini.absolute_url(self._current_url, url)) + gem = gemini.get(gemini.urljoin(self._current_url, url.toString())) while gem['status'][0] == '3': url = QtCore.QUrl(gem['meta']) if url.port() == 1965: url.setPort(-1) print('redirect: {}'.format(url)) - gem = gemini.get(gemini.absolute_url(self._current_url, url)) + gem = gemini.get(gemini.urljoin(self._current_url, url.toString())) self._last_redirect = (url, gem) if url.port() == 1965: url.setPort(-1) |