Use QUrls everywhere in browser.py
This commit is contained in:
parent
b4cfb7dbf2
commit
adb0644674
@ -4,6 +4,7 @@ from PyQt5.QtCore import QUrl, pyqtSignal, Qt, QPoint, QEvent
|
|||||||
from PyQt5.QtPrintSupport import QPrintPreviewDialog
|
from PyQt5.QtPrintSupport import QPrintPreviewDialog
|
||||||
from PyQt5.QtWebKitWidgets import QWebView, QWebPage
|
from PyQt5.QtWebKitWidgets import QWebView, QWebPage
|
||||||
|
|
||||||
|
import qutebrowser.utils as utils
|
||||||
from qutebrowser.widgets.tabbar import TabWidget
|
from qutebrowser.widgets.tabbar import TabWidget
|
||||||
|
|
||||||
class TabbedBrowser(TabWidget):
|
class TabbedBrowser(TabWidget):
|
||||||
@ -19,13 +20,14 @@ class TabbedBrowser(TabWidget):
|
|||||||
def __init__(self, parent):
|
def __init__(self, parent):
|
||||||
super().__init__(parent)
|
super().__init__(parent)
|
||||||
self.currentChanged.connect(self._currentChanged_handler)
|
self.currentChanged.connect(self._currentChanged_handler)
|
||||||
self.tabopen("http://ddg.gg/")
|
self.tabopen(QUrl("http://ddg.gg/"))
|
||||||
|
|
||||||
def tabopen(self, url):
|
def tabopen(self, url):
|
||||||
"""Opens a new tab with a given url"""
|
"""Opens a new tab with a given url"""
|
||||||
|
url = utils.qurl(url)
|
||||||
tab = BrowserTab(self)
|
tab = BrowserTab(self)
|
||||||
tab.openurl(url)
|
tab.openurl(url)
|
||||||
self.addTab(tab, url)
|
self.addTab(tab, url.url())
|
||||||
self.setCurrentWidget(tab)
|
self.setCurrentWidget(tab)
|
||||||
self.cur_progress.emit(tab.progress)
|
self.cur_progress.emit(tab.progress)
|
||||||
tab.loadProgress.connect(
|
tab.loadProgress.connect(
|
||||||
@ -43,8 +45,7 @@ class TabbedBrowser(TabWidget):
|
|||||||
|
|
||||||
def openurl(self, url):
|
def openurl(self, url):
|
||||||
"""Opens an url in the current tab"""
|
"""Opens an url in the current tab"""
|
||||||
tab = self.currentWidget()
|
self.currentWidget().openurl(url)
|
||||||
tab.openurl(url)
|
|
||||||
|
|
||||||
def undo_close(self):
|
def undo_close(self):
|
||||||
"""Undos closing a tab"""
|
"""Undos closing a tab"""
|
||||||
@ -56,9 +57,8 @@ class TabbedBrowser(TabWidget):
|
|||||||
if self.count() > 1:
|
if self.count() > 1:
|
||||||
idx = self.currentIndex()
|
idx = self.currentIndex()
|
||||||
tab = self.currentWidget()
|
tab = self.currentWidget()
|
||||||
# FIXME maybe we should add the QUrl object here and deal with QUrls everywhere
|
|
||||||
# FIXME maybe we actually should store the webview objects here
|
# FIXME maybe we actually should store the webview objects here
|
||||||
self._url_stack.append(tab.url().url())
|
self._url_stack.append(tab.url())
|
||||||
self.removeTab(idx)
|
self.removeTab(idx)
|
||||||
else:
|
else:
|
||||||
# FIXME
|
# FIXME
|
||||||
@ -188,7 +188,7 @@ class BrowserTab(QWebView):
|
|||||||
scroll_pos_changed = pyqtSignal(int, int)
|
scroll_pos_changed = pyqtSignal(int, int)
|
||||||
_scroll_pos = (-1, -1)
|
_scroll_pos = (-1, -1)
|
||||||
midbutton = False # if the middle button was pressed
|
midbutton = False # if the middle button was pressed
|
||||||
open_tab = pyqtSignal(str)
|
open_tab = pyqtSignal('QUrl')
|
||||||
|
|
||||||
def __init__(self, parent):
|
def __init__(self, parent):
|
||||||
super().__init__(parent)
|
super().__init__(parent)
|
||||||
@ -201,15 +201,11 @@ class BrowserTab(QWebView):
|
|||||||
|
|
||||||
def openurl(self, url):
|
def openurl(self, url):
|
||||||
"""Opens an URL in the browser"""
|
"""Opens an URL in the browser"""
|
||||||
if isinstance(url, QUrl):
|
return self.load(utils.qurl(url))
|
||||||
return self.load(url)
|
|
||||||
if not url.startswith('http://'):
|
|
||||||
url = 'http://' + url
|
|
||||||
return self.load(QUrl(url))
|
|
||||||
|
|
||||||
def link_handler(self, url):
|
def link_handler(self, url):
|
||||||
if self.midbutton:
|
if self.midbutton:
|
||||||
self.open_tab.emit(url.url())
|
self.open_tab.emit(url)
|
||||||
else:
|
else:
|
||||||
self.openurl(url)
|
self.openurl(url)
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user