diff options
author | Juhani Krekelä | 2021-07-24 19:15:13 +0300 |
---|---|---|
committer | Wolfgang Müller | 2021-11-27 14:05:19 +0100 |
commit | a9706ec27edc0aef03f72daba28647aca1c42070 (patch) | |
tree | a6589cc410f91fb45e1093423fde9170de43e83f /configreader.vala | |
parent | 78e1e14fa676a6c995d9dc61ad038a9906f37bf7 (diff) | |
download | weltschmerz-a9706ec27edc0aef03f72daba28647aca1c42070.tar.gz |
Add ability to specify additional URI handlers
This commit adds a new section, open-with, to the configuration file.
The options specified there will be added as "Open with …" menu items in
the URI context menu. This is to make it easier to perform other actions
on the URI than opening it in the system default browser; a user might
for example add another browser, media player, or a script that
preprocesses the URI before opening it.
Diffstat (limited to '')
-rw-r--r-- | configreader.vala | 38 |
1 files changed, 38 insertions, 0 deletions
diff --git a/configreader.vala b/configreader.vala index 46f6b1f..8336637 100644 --- a/configreader.vala +++ b/configreader.vala @@ -208,4 +208,42 @@ class ConfigReader { return SYSTEM; } } + + public OpenWithProgram[] read_open_with(OpenWithProgram[] default) { + if (keyfile == null) + return default; + + OpenWithProgram[] programs = {}; + + string[] keys; + try { + keys = keyfile.get_keys("open-with"); + } catch (GLib.KeyFileError e) { + return default; + } + + foreach (var name in keys) { + var command_string = read_string("open-with", name, null); + if (command_string == null) + continue; + + string[] command; + try { + Shell.parse_argv(command_string, out command); + } catch (ShellError e) { + append_warning(_("ignoring open-with.%s due to malformed command: %s").printf(name, e.message)); + continue; + } + + if (!("%" in command)) { + append_warning(_("ignoring command in open-with.%s: missing '%%'").printf(name)); + continue; + } + + OpenWithProgram program = {name, command}; + programs += program; + } + + return programs; + } } |