From 4e2897fa05011ab0b53a871686c807709ad9a3fc Mon Sep 17 00:00:00 2001 From: Chris Jones Date: Sat, 14 Jan 2012 20:39:00 +0000 Subject: [PATCH] Allow users to override the URL handler with a custom executable --- doc/terminator_config.5 | 8 +++++ terminatorlib/config.py | 2 ++ terminatorlib/preferences.glade | 56 ++++++++++++++++++++++++++++++++- terminatorlib/prefseditor.py | 23 ++++++++++++++ terminatorlib/terminal.py | 9 ++++++ 5 files changed, 97 insertions(+), 1 deletion(-) diff --git a/doc/terminator_config.5 b/doc/terminator_config.5 index baa85513..96c8d224 100644 --- a/doc/terminator_config.5 +++ b/doc/terminator_config.5 @@ -78,6 +78,14 @@ Default value: \fBFalse\fR If set to True, URL matching regexps will try to use POSIX style first, and fall back on GNU style on failure. If you are on Linux but URL matches don't work, try setting this to True. If you are not on Linux, but you get VTE warnings on startup saying "Error compiling regular expression", set this to False to silence them (they are otherwise harmless). Default value: \fBFalse\fR on Linux, \fBTrue\fR otherwise. .TP +.B use_custom_url_handler \fR(boolean) +If set to True, URL handling will be given over entirely to the program specified by 'custom_url_handler'. +Default value: \fBFalse\fR +.TP +.B custom_url_handler \fR(string) +Path to a program which accepts a URI as an argument and does something relevant with it. This option is ignored unless 'use_custom_url_handler' is set to True. +Default value: unset +.TP .B title_transmit_fg_color Sets the colour of the text shown in the titlebar of the active terminal. Default value: \fB'#FFFFFF'\fR diff --git a/terminatorlib/config.py b/terminatorlib/config.py index 53307641..fc9ed558 100755 --- a/terminatorlib/config.py +++ b/terminatorlib/config.py @@ -91,6 +91,8 @@ DEFAULTS = { 'hide_on_lose_focus' : False, 'sticky' : False, 'try_posix_regexp' : platform.system() != 'Linux', + 'use_custom_url_handler': False, + 'custom_url_handler' : '', 'title_hide_sizetext' : False, 'title_transmit_fg_color' : '#ffffff', 'title_transmit_bg_color' : '#c80003', diff --git a/terminatorlib/preferences.glade b/terminatorlib/preferences.glade index 4ed38cc0..a037824a 100644 --- a/terminatorlib/preferences.glade +++ b/terminatorlib/preferences.glade @@ -382,7 +382,7 @@ True False - 13 + 15 2 6 @@ -803,6 +803,60 @@ 13 + + + True + False + Use custom URL handler + + + 13 + 14 + + + + + True + False + Custom URL handler + + + 14 + 15 + + + + + True + True + False + False + True + + + + 1 + 2 + 13 + 14 + + GTK_EXPAND + + + + + True + True + + + + + 1 + 2 + 14 + 15 + + True diff --git a/terminatorlib/prefseditor.py b/terminatorlib/prefseditor.py index e1e48510..17ef7d8a 100755 --- a/terminatorlib/prefseditor.py +++ b/terminatorlib/prefseditor.py @@ -460,6 +460,13 @@ class PrefsEditor: # Inactive terminal shading widget = guiget('inactive_color_offset') widget.set_value(float(self.config['inactive_color_offset'])) + # Use custom URL handler + widget = guiget('use_custom_url_handler_checkbox') + widget.set_active(self.config['use_custom_url_handler']) + self.on_use_custom_url_handler_checkbutton_toggled(widget) + # Custom URL handler + widget = guiget('custom_url_handler_entry') + widget.set_text(self.config['custom_url_handler']) ## Background tab # Radio values @@ -822,6 +829,11 @@ class PrefsEditor: self.config['exit_action'] = value self.config.save() + def on_custom_url_handler_entry_changed(self, widget): + """Custom URL handler value changed""" + self.config['custom_url_handler'] = widget.get_text() + self.config.save() + def on_custom_command_entry_changed(self, widget): """Custom command value changed""" self.config['custom_command'] = widget.get_text() @@ -1027,6 +1039,17 @@ class PrefsEditor: selection.select_iter(model.get_iter_first()) self.config.save() + def on_use_custom_url_handler_checkbutton_toggled(self, checkbox): + """Toggling the use_custom_url_handler checkbox needs to alter the + sensitivity of the custom_url_handler entrybox""" + guiget = self.builder.get_object + widget = guiget('custom_url_handler_entry') + value = checkbox.get_active() + + widget.set_sensitive(value) + self.config['use_custom_url_handler'] = value + self.config.save() + def on_use_custom_command_checkbutton_toggled(self, checkbox): """Toggling the use_custom_command checkbox needs to alter the sensitivity of the custom_command entrybox""" diff --git a/terminatorlib/terminal.py b/terminatorlib/terminal.py index 1860b9b3..9c3f930f 100755 --- a/terminatorlib/terminal.py +++ b/terminatorlib/terminal.py @@ -1305,6 +1305,15 @@ class Terminal(gtk.VBox): url = self.prepare_url(url) dbg('open_url: URL: %s (prepared: %s)' % (url, prepare)) + if self.config['use_custom_url_handler']: + dbg("Using custom URL handler: %s" % + self.config['custom_url_handler']) + try: + subprocess.Popen([self.config['custom_url_handler'], url]) + return + except: + dbg('custom url handler did not work, falling back to defaults') + if gtk.gtk_version < (2, 14, 0) or \ not hasattr(gtk, 'show_uri') or \ not hasattr(gtk.gdk, 'CURRENT_TIME'):