add an application param for prompt-open-download
This commit is contained in:
parent
716ce701f5
commit
fa6c552d7b
@ -1168,8 +1168,15 @@ Answer no to a yes/no prompt.
|
|||||||
|
|
||||||
[[prompt-open-download]]
|
[[prompt-open-download]]
|
||||||
=== prompt-open-download
|
=== prompt-open-download
|
||||||
|
Syntax: +:prompt-open-download ['cmdline']+
|
||||||
|
|
||||||
Immediately open a download.
|
Immediately open a download.
|
||||||
|
|
||||||
|
==== positional arguments
|
||||||
|
* +'cmdline'+: The command line string to execute. The default will use the system's application to open the file, depending on
|
||||||
|
the filetype.
|
||||||
|
|
||||||
|
|
||||||
[[prompt-yes]]
|
[[prompt-yes]]
|
||||||
=== prompt-yes
|
=== prompt-yes
|
||||||
Answer yes to a yes/no prompt.
|
Answer yes to a yes/no prompt.
|
||||||
|
@ -22,6 +22,7 @@
|
|||||||
import io
|
import io
|
||||||
import os
|
import os
|
||||||
import sys
|
import sys
|
||||||
|
import shlex
|
||||||
import os.path
|
import os.path
|
||||||
import shutil
|
import shutil
|
||||||
import functools
|
import functools
|
||||||
@ -40,6 +41,7 @@ from qutebrowser.config import config
|
|||||||
from qutebrowser.commands import cmdexc, cmdutils
|
from qutebrowser.commands import cmdexc, cmdutils
|
||||||
from qutebrowser.utils import (message, usertypes, log, utils, urlutils,
|
from qutebrowser.utils import (message, usertypes, log, utils, urlutils,
|
||||||
objreg, standarddir, qtutils)
|
objreg, standarddir, qtutils)
|
||||||
|
from qutebrowser.misc import guiprocess
|
||||||
from qutebrowser.browser.webkit import http
|
from qutebrowser.browser.webkit import http
|
||||||
from qutebrowser.browser.webkit.network import networkmanager
|
from qutebrowser.browser.webkit.network import networkmanager
|
||||||
|
|
||||||
@ -955,19 +957,39 @@ class DownloadManager(QAbstractListModel):
|
|||||||
download.cancel()
|
download.cancel()
|
||||||
return
|
return
|
||||||
download.finished.connect(
|
download.finished.connect(
|
||||||
functools.partial(self._open_download, download))
|
functools.partial(self._open_download, download,
|
||||||
|
target.cmdline))
|
||||||
download.autoclose = True
|
download.autoclose = True
|
||||||
download.set_fileobj(fobj)
|
download.set_fileobj(fobj)
|
||||||
else:
|
else:
|
||||||
log.downloads.error("Unknown download target: {}".format(target))
|
log.downloads.error("Unknown download target: {}".format(target))
|
||||||
|
|
||||||
def _open_download(self, download):
|
def _open_download(self, download, cmdline):
|
||||||
"""Open the given download but only if it was successful."""
|
"""Open the given download but only if it was successful.
|
||||||
if download.successful:
|
|
||||||
download.open_file()
|
Args:
|
||||||
else:
|
download: The DownloadItem to use.
|
||||||
|
cmdline: The command to use, or None for the system's default
|
||||||
|
program.
|
||||||
|
"""
|
||||||
|
if not download.successful:
|
||||||
log.downloads.debug("{} finished but not successful, not opening!"
|
log.downloads.debug("{} finished but not successful, not opening!"
|
||||||
.format(download))
|
.format(download))
|
||||||
|
if cmdline is None:
|
||||||
|
download.open_file()
|
||||||
|
return
|
||||||
|
|
||||||
|
cmd, *args = shlex.split(cmdline)
|
||||||
|
filename = download._filename
|
||||||
|
if filename is None:
|
||||||
|
filename = getattr(download.fileobj, 'name', None)
|
||||||
|
if filename is None:
|
||||||
|
raise ValueError("Download has no filename to open")
|
||||||
|
args = [filename if arg == '{}' else arg for arg in args]
|
||||||
|
|
||||||
|
proc = guiprocess.GUIProcess(self._win_id, what='process')
|
||||||
|
proc.start_detached(cmd, args)
|
||||||
|
|
||||||
|
|
||||||
def raise_no_download(self, count):
|
def raise_no_download(self, count):
|
||||||
"""Raise an exception that the download doesn't exist.
|
"""Raise an exception that the download doesn't exist.
|
||||||
|
@ -312,13 +312,20 @@ class Prompter(QObject):
|
|||||||
self._question.done()
|
self._question.done()
|
||||||
|
|
||||||
@cmdutils.register(instance='prompter', hide=True, scope='window',
|
@cmdutils.register(instance='prompter', hide=True, scope='window',
|
||||||
modes=[usertypes.KeyMode.prompt])
|
modes=[usertypes.KeyMode.prompt], maxsplit=0)
|
||||||
def prompt_open_download(self):
|
def prompt_open_download(self, cmdline: str=None):
|
||||||
"""Immediately open a download."""
|
"""Immediately open a download.
|
||||||
|
|
||||||
|
Args:
|
||||||
|
cmdline: The command line string to execute. The default will use
|
||||||
|
the system's application to open the file, depending on
|
||||||
|
the filetype. A `{}` is expanded to the temporary file
|
||||||
|
name.
|
||||||
|
"""
|
||||||
if self._question.mode != usertypes.PromptMode.download:
|
if self._question.mode != usertypes.PromptMode.download:
|
||||||
# We just ignore this if we don't have a download question.
|
# We just ignore this if we don't have a download question.
|
||||||
return
|
return
|
||||||
self._question.answer = usertypes.OpenFileDownloadTarget()
|
self._question.answer = usertypes.OpenFileDownloadTarget(cmdline)
|
||||||
modeman.maybe_leave(self._win_id, usertypes.KeyMode.prompt,
|
modeman.maybe_leave(self._win_id, usertypes.KeyMode.prompt,
|
||||||
'download open')
|
'download open')
|
||||||
self._question.done()
|
self._question.done()
|
||||||
|
@ -297,11 +297,16 @@ class FileObjDownloadTarget(DownloadTarget):
|
|||||||
|
|
||||||
class OpenFileDownloadTarget(DownloadTarget):
|
class OpenFileDownloadTarget(DownloadTarget):
|
||||||
|
|
||||||
"""Save the download in a temp dir and directly open it."""
|
"""Save the download in a temp dir and directly open it.
|
||||||
|
|
||||||
def __init__(self):
|
Attributes:
|
||||||
|
cmdline: The command to use as string. A {} is expanded to th
|
||||||
|
filename. None means use the system's default.
|
||||||
|
"""
|
||||||
|
|
||||||
|
def __init__(self, cmdline=None):
|
||||||
# pylint: disable=super-init-not-called
|
# pylint: disable=super-init-not-called
|
||||||
pass
|
self.cmdline = cmdline
|
||||||
|
|
||||||
|
|
||||||
class Question(QObject):
|
class Question(QObject):
|
||||||
|
Loading…
Reference in New Issue
Block a user