implement optional download-open handler setting

- adds new `general` -> `default-open-dispatcher` setting (string)
- if set, will be used instead of QDesktopServices.openUrl (xdg-open backend)
- fixes the 'download handlers' part of issue #841
- note that this is only relevent to the `:download-open` command and other
  methods of opening downloaded files from qutebrowser
This commit is contained in:
Samuel Walladge 2016-12-16 21:54:04 +10:30
parent e1b5f6a64e
commit f6c73f3ad6
No known key found for this signature in database
GPG Key ID: 44E2319D42B72AA6
3 changed files with 28 additions and 3 deletions

View File

@ -11,6 +11,7 @@
|<<general-ignore-case,ignore-case>>|Whether to find text on a page case-insensitively.
|<<general-startpage,startpage>>|The default page(s) to open at the start, separated by commas.
|<<general-yank-ignored-url-parameters,yank-ignored-url-parameters>>|The URL parameters to strip with :yank url, separated by commas.
|<<general-default-open-dispatcher,default-open-dispatcher>>|The default program used to open downloads. Set to an empty string to use the default internal handler.
|<<general-default-page,default-page>>|The page to open if :open -t/-b/-w is used without URL. Use `about:blank` for a blank page.
|<<general-auto-search,auto-search>>|Whether to start a search when something else than a URL is entered.
|<<general-auto-save-config,auto-save-config>>|Whether to save the config automatically on quit.
@ -331,6 +332,14 @@ The URL parameters to strip with :yank url, separated by commas.
Default: +pass:[ref,utm_source,utm_medium,utm_campaign,utm_term,utm_content]+
[[general-default-open-dispatcher]]
=== default-open-dispatcher
The default program used to open downloads. Set to an empty string to use the default internal handler.
Any {} in the string will be expanded to the filename, else the filename will be appended.
Default: empty
[[general-default-page]]
=== default-page
The page to open if :open -t/-b/-w is used without URL. Use `about:blank` for a blank page.

View File

@ -512,8 +512,8 @@ class AbstractDownloadItem(QObject):
Args:
cmdline: The command to use as string. A `{}` is expanded to the
filename. None means to use the system's default
application. If no `{}` is found, the filename is appended
to the cmdline.
application or `default-open-dispatcher` if set. If no
`{}` is found, the filename is appended to the cmdline.
"""
assert self.successful
filename = self._get_open_filename()
@ -521,13 +521,22 @@ class AbstractDownloadItem(QObject):
log.downloads.error("No filename to open the download!")
return
if cmdline is None:
# the default program to open downloads with - will be empty string
# if we want to use the default
override = config.get('general', 'default-open-dispatcher')
# precedence order: supplied cmdline > default-open-dispatcher > openUrl
if cmdline is None and not override:
log.downloads.debug("Opening {} with the system application"
.format(filename))
url = QUrl.fromLocalFile(filename)
QDesktopServices.openUrl(url)
return
if cmdline is None and override:
cmdline = override
cmd, *args = shlex.split(cmdline)
args = [arg.replace('{}', filename) for arg in args]
if '{}' not in cmdline:

View File

@ -147,6 +147,13 @@ def data(readonly=False):
"The URL parameters to strip with :yank url, separated by "
"commas."),
('default-open-dispatcher',
SettingValue(typ.String(none_ok=True), ''),
"The default program used to open downloads. Set to an empty "
"string to use the default internal handler.\n\n"
"Any {} in the string will be expanded to the filename, else "
"the filename will be appended."),
('default-page',
SettingValue(typ.FuzzyUrl(), '${startpage}'),
"The page to open if :open -t/-b/-w is used without URL. Use "