parent
5fa1556588
commit
b502280c06
@ -40,7 +40,7 @@ import qutebrowser
|
||||
from qutebrowser.commands import cmdutils, runners
|
||||
from qutebrowser.config import style, config, websettings
|
||||
from qutebrowser.network import qutescheme, proxy
|
||||
from qutebrowser.browser import quickmarks, cookies, downloads, cache
|
||||
from qutebrowser.browser import quickmarks, cookies, cache
|
||||
from qutebrowser.widgets import mainwindow, crash
|
||||
from qutebrowser.keyinput import modeman
|
||||
from qutebrowser.utils import (log, version, message, readline, utils, qtutils,
|
||||
@ -167,9 +167,6 @@ class Application(QApplication):
|
||||
log.init.debug("Initializing cache...")
|
||||
diskcache = cache.DiskCache(self)
|
||||
objreg.register('cache', diskcache)
|
||||
log.init.debug("Initializing downloads...")
|
||||
download_manager = downloads.DownloadManager(self)
|
||||
objreg.register('download-manager', download_manager)
|
||||
log.init.debug("Initializing main window...")
|
||||
win_id = mainwindow.MainWindow.spawn(
|
||||
False if self._args.nowindow else True)
|
||||
|
@ -864,7 +864,9 @@ class CommandDispatcher:
|
||||
def download_page(self):
|
||||
"""Download the current page."""
|
||||
page = self._current_widget().page()
|
||||
objreg.get('download-manager').get(self._current_url(), page)
|
||||
download_manager = objreg.get('download-manager', scope='window',
|
||||
window=self._win_id)
|
||||
download_manager.get(self._current_url(), page)
|
||||
|
||||
@cmdutils.register(instance='command-dispatcher', scope='window')
|
||||
def view_source(self):
|
||||
|
@ -347,8 +347,9 @@ class DownloadManager(QAbstractListModel):
|
||||
questions: A list of Question objects to not GC them.
|
||||
"""
|
||||
|
||||
def __init__(self, parent=None):
|
||||
def __init__(self, win_id, parent=None):
|
||||
super().__init__(parent)
|
||||
self._win_id = win_id
|
||||
self.downloads = []
|
||||
self.questions = []
|
||||
|
||||
@ -364,13 +365,13 @@ class DownloadManager(QAbstractListModel):
|
||||
page: The QWebPage to get the download from.
|
||||
"""
|
||||
if not url.isValid():
|
||||
urlutils.invalid_url_error('last-focused', url, "start download")
|
||||
urlutils.invalid_url_error(self._win_id, url, "start download")
|
||||
return
|
||||
req = QNetworkRequest(url)
|
||||
reply = page.networkAccessManager().get(req)
|
||||
self.fetch(reply)
|
||||
|
||||
@cmdutils.register(instance='download-manager')
|
||||
@cmdutils.register(instance='download-manager', scope='window')
|
||||
def cancel_download(self, count: {'special': 'count'}=1):
|
||||
"""Cancel the first/[count]th download.
|
||||
|
||||
@ -419,7 +420,7 @@ class DownloadManager(QAbstractListModel):
|
||||
self.questions.append(q)
|
||||
download.cancelled.connect(q.abort)
|
||||
message_bridge = objreg.get('message-bridge', scope='window',
|
||||
window='last-focused')
|
||||
window=self._win_id)
|
||||
message_bridge.ask(q, blocking=False)
|
||||
|
||||
@pyqtSlot(DownloadItem)
|
||||
@ -443,7 +444,7 @@ class DownloadManager(QAbstractListModel):
|
||||
@pyqtSlot(str)
|
||||
def on_error(self, msg):
|
||||
"""Display error message on download errors."""
|
||||
message.error('last-focused', "Download error: {}".format(msg))
|
||||
message.error(self._win_id, "Download error: {}".format(msg))
|
||||
|
||||
def last_index(self):
|
||||
"""Get the last index in the model.
|
||||
@ -468,7 +469,7 @@ class DownloadManager(QAbstractListModel):
|
||||
if index.parent().isValid() or index.column() != 0:
|
||||
return QVariant()
|
||||
|
||||
item = objreg.get('download-manager').downloads[index.row()]
|
||||
item = self.downloads[index.row()]
|
||||
if role == Qt.DisplayRole:
|
||||
data = str(item)
|
||||
elif role == Qt.ForegroundRole:
|
||||
@ -497,4 +498,4 @@ class DownloadManager(QAbstractListModel):
|
||||
if parent.isValid():
|
||||
# We don't have children
|
||||
return 0
|
||||
return len(objreg.get('download-manager').downloads)
|
||||
return len(self.downloads)
|
||||
|
@ -399,7 +399,9 @@ class HintManager(QObject):
|
||||
"No suitable link found for this element.",
|
||||
immediately=True)
|
||||
return
|
||||
objreg.get('download-manager').get(url, elem.webFrame().page())
|
||||
download_manager = objreg.get('download-manager', scope='window',
|
||||
window=self._win_id)
|
||||
download_manager.get(url, elem.webFrame().page())
|
||||
|
||||
def _call_userscript(self, url):
|
||||
"""Call an userscript from a hint."""
|
||||
|
@ -76,7 +76,7 @@ class DownloadView(QListView):
|
||||
}
|
||||
"""
|
||||
|
||||
def __init__(self, parent=None):
|
||||
def __init__(self, win_id, parent=None):
|
||||
super().__init__(parent)
|
||||
style.set_register_stylesheet(self)
|
||||
self.setResizeMode(QListView.Adjust)
|
||||
@ -84,7 +84,7 @@ class DownloadView(QListView):
|
||||
self.setSizePolicy(QSizePolicy.MinimumExpanding, QSizePolicy.Fixed)
|
||||
self.setFlow(QListView.LeftToRight)
|
||||
self._menu = None
|
||||
model = objreg.get('download-manager')
|
||||
model = objreg.get('download-manager', scope='window', window=win_id)
|
||||
model.rowsInserted.connect(functools.partial(update_geometry, self))
|
||||
model.rowsRemoved.connect(functools.partial(update_geometry, self))
|
||||
self.setModel(model)
|
||||
|
@ -30,10 +30,11 @@ from PyQt5.QtWidgets import QWidget, QVBoxLayout
|
||||
from qutebrowser.commands import runners, cmdutils
|
||||
from qutebrowser.config import config
|
||||
from qutebrowser.utils import message, log, usertypes, qtutils, objreg, utils
|
||||
from qutebrowser.widgets import tabbedbrowser, completion, downloads
|
||||
from qutebrowser.widgets import tabbedbrowser, completion
|
||||
from qutebrowser.widgets import downloads as downloadswidget
|
||||
from qutebrowser.widgets.statusbar import bar
|
||||
from qutebrowser.keyinput import modeman
|
||||
from qutebrowser.browser import hints
|
||||
from qutebrowser.browser import hints, downloads
|
||||
|
||||
|
||||
win_id_gen = itertools.count(0)
|
||||
@ -81,7 +82,12 @@ class MainWindow(QWidget):
|
||||
self._vbox.setContentsMargins(0, 0, 0, 0)
|
||||
self._vbox.setSpacing(0)
|
||||
|
||||
self._downloadview = downloads.DownloadView()
|
||||
log.init.debug("Initializing downloads...")
|
||||
download_manager = downloads.DownloadManager(win_id, self)
|
||||
objreg.register('download-manager', download_manager, scope='window',
|
||||
window=win_id)
|
||||
|
||||
self._downloadview = downloadswidget.DownloadView(win_id)
|
||||
self._vbox.addWidget(self._downloadview)
|
||||
self._downloadview.show()
|
||||
|
||||
@ -182,7 +188,6 @@ class MainWindow(QWidget):
|
||||
def _connect_signals(self):
|
||||
"""Connect all mainwindow signals."""
|
||||
# pylint: disable=too-many-locals,too-many-statements
|
||||
download_manager = objreg.get('download-manager')
|
||||
key_config = objreg.get('key-config')
|
||||
|
||||
status = self._get_object('statusbar')
|
||||
@ -195,6 +200,7 @@ class MainWindow(QWidget):
|
||||
message_bridge = self._get_object('message-bridge')
|
||||
mode_manager = self._get_object('mode-manager')
|
||||
prompter = self._get_object('prompter')
|
||||
download_manager = self._get_object('download-manager')
|
||||
|
||||
# misc
|
||||
self._tabbed_browser.close_window.connect(self.close)
|
||||
|
Loading…
Reference in New Issue
Block a user