Add rapid hinting for downloads.
This commit is contained in:
parent
c715b24bd3
commit
46f3be2df7
@ -36,6 +36,7 @@ Added
|
|||||||
used download directory.
|
used download directory.
|
||||||
- New setting `storage -> prompt-download-directory` to download all downloads
|
- New setting `storage -> prompt-download-directory` to download all downloads
|
||||||
without asking.
|
without asking.
|
||||||
|
- Rapid hinting is now also possible for downloads.
|
||||||
|
|
||||||
Changed
|
Changed
|
||||||
~~~~~~~
|
~~~~~~~
|
||||||
|
@ -663,7 +663,7 @@ class DownloadManager(QAbstractListModel):
|
|||||||
|
|
||||||
@pyqtSlot('QUrl', 'QWebPage')
|
@pyqtSlot('QUrl', 'QWebPage')
|
||||||
def get(self, url, page=None, fileobj=None, filename=None,
|
def get(self, url, page=None, fileobj=None, filename=None,
|
||||||
auto_remove=False):
|
auto_remove=False, prompt_download_directory=None):
|
||||||
"""Start a download with a link URL.
|
"""Start a download with a link URL.
|
||||||
|
|
||||||
Args:
|
Args:
|
||||||
@ -673,6 +673,9 @@ class DownloadManager(QAbstractListModel):
|
|||||||
filename: A path to write the data to.
|
filename: A path to write the data to.
|
||||||
auto_remove: Whether to remove the download even if
|
auto_remove: Whether to remove the download even if
|
||||||
ui -> remove-finished-downloads is set to false.
|
ui -> remove-finished-downloads is set to false.
|
||||||
|
prompt_download_directory: Whether to prompt for the download dir
|
||||||
|
or automatically download. If None, the
|
||||||
|
config is used.
|
||||||
|
|
||||||
Return:
|
Return:
|
||||||
If the download could start immediately, (fileobj/filename given),
|
If the download could start immediately, (fileobj/filename given),
|
||||||
@ -686,10 +689,11 @@ class DownloadManager(QAbstractListModel):
|
|||||||
urlutils.invalid_url_error(self._win_id, url, "start download")
|
urlutils.invalid_url_error(self._win_id, url, "start download")
|
||||||
return
|
return
|
||||||
req = QNetworkRequest(url)
|
req = QNetworkRequest(url)
|
||||||
return self.get_request(req, page, fileobj, filename, auto_remove)
|
return self.get_request(req, page, fileobj, filename, auto_remove,
|
||||||
|
prompt_download_directory)
|
||||||
|
|
||||||
def get_request(self, request, page=None, fileobj=None, filename=None,
|
def get_request(self, request, page=None, fileobj=None, filename=None,
|
||||||
auto_remove=False):
|
auto_remove=False, prompt_download_directory=None):
|
||||||
"""Start a download with a QNetworkRequest.
|
"""Start a download with a QNetworkRequest.
|
||||||
|
|
||||||
Args:
|
Args:
|
||||||
@ -699,6 +703,9 @@ class DownloadManager(QAbstractListModel):
|
|||||||
filename: A path to write the data to.
|
filename: A path to write the data to.
|
||||||
auto_remove: Whether to remove the download even if
|
auto_remove: Whether to remove the download even if
|
||||||
ui -> remove-finished-downloads is set to false.
|
ui -> remove-finished-downloads is set to false.
|
||||||
|
prompt_download_directory: Whether to prompt for the download dir
|
||||||
|
or automatically download. If None, the
|
||||||
|
config is used.
|
||||||
|
|
||||||
Return:
|
Return:
|
||||||
If the download could start immediately, (fileobj/filename given),
|
If the download could start immediately, (fileobj/filename given),
|
||||||
@ -714,8 +721,9 @@ class DownloadManager(QAbstractListModel):
|
|||||||
QNetworkRequest.AlwaysNetwork)
|
QNetworkRequest.AlwaysNetwork)
|
||||||
suggested_fn = urlutils.filename_from_url(request.url())
|
suggested_fn = urlutils.filename_from_url(request.url())
|
||||||
|
|
||||||
prompt_download_directory = config.get('storage',
|
if prompt_download_directory is None:
|
||||||
'prompt-download-directory')
|
prompt_download_directory = config.get(
|
||||||
|
'storage', 'prompt-download-directory')
|
||||||
if not prompt_download_directory:
|
if not prompt_download_directory:
|
||||||
filename = config.get('storage', 'download-directory')
|
filename = config.get('storage', 'download-directory')
|
||||||
|
|
||||||
@ -763,7 +771,7 @@ class DownloadManager(QAbstractListModel):
|
|||||||
|
|
||||||
@pyqtSlot('QNetworkReply')
|
@pyqtSlot('QNetworkReply')
|
||||||
def fetch(self, reply, fileobj=None, filename=None, auto_remove=False,
|
def fetch(self, reply, fileobj=None, filename=None, auto_remove=False,
|
||||||
suggested_filename=None):
|
suggested_filename=None, prompt_download_directory=None):
|
||||||
"""Download a QNetworkReply to disk.
|
"""Download a QNetworkReply to disk.
|
||||||
|
|
||||||
Args:
|
Args:
|
||||||
|
@ -514,9 +514,15 @@ class HintManager(QObject):
|
|||||||
if url is None:
|
if url is None:
|
||||||
self._show_url_error()
|
self._show_url_error()
|
||||||
return
|
return
|
||||||
|
if context.rapid:
|
||||||
|
prompt = False
|
||||||
|
else:
|
||||||
|
prompt = None
|
||||||
|
|
||||||
download_manager = objreg.get('download-manager', scope='window',
|
download_manager = objreg.get('download-manager', scope='window',
|
||||||
window=self._win_id)
|
window=self._win_id)
|
||||||
download_manager.get(url, elem.webFrame().page())
|
download_manager.get(url, elem.webFrame().page(),
|
||||||
|
prompt_download_directory=prompt)
|
||||||
|
|
||||||
def _call_userscript(self, elem, context):
|
def _call_userscript(self, elem, context):
|
||||||
"""Call a userscript from a hint.
|
"""Call a userscript from a hint.
|
||||||
@ -764,7 +770,8 @@ class HintManager(QObject):
|
|||||||
|
|
||||||
if rapid:
|
if rapid:
|
||||||
if target in [Target.tab_bg, Target.window, Target.run,
|
if target in [Target.tab_bg, Target.window, Target.run,
|
||||||
Target.hover, Target.userscript, Target.spawn]:
|
Target.hover, Target.userscript, Target.spawn,
|
||||||
|
Target.download]:
|
||||||
pass
|
pass
|
||||||
elif (target == Target.tab and
|
elif (target == Target.tab and
|
||||||
config.get('tabs', 'background-tabs')):
|
config.get('tabs', 'background-tabs')):
|
||||||
|
Loading…
Reference in New Issue
Block a user