Allow users to override the URL handler with a custom executable

This commit is contained in:
Chris Jones 2012-01-14 20:39:00 +00:00
parent 1dd4d562ff
commit 4e2897fa05
5 changed files with 97 additions and 1 deletions

View File

@ -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). 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. Default value: \fBFalse\fR on Linux, \fBTrue\fR otherwise.
.TP .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 .B title_transmit_fg_color
Sets the colour of the text shown in the titlebar of the active terminal. Sets the colour of the text shown in the titlebar of the active terminal.
Default value: \fB'#FFFFFF'\fR Default value: \fB'#FFFFFF'\fR

View File

@ -91,6 +91,8 @@ DEFAULTS = {
'hide_on_lose_focus' : False, 'hide_on_lose_focus' : False,
'sticky' : False, 'sticky' : False,
'try_posix_regexp' : platform.system() != 'Linux', 'try_posix_regexp' : platform.system() != 'Linux',
'use_custom_url_handler': False,
'custom_url_handler' : '',
'title_hide_sizetext' : False, 'title_hide_sizetext' : False,
'title_transmit_fg_color' : '#ffffff', 'title_transmit_fg_color' : '#ffffff',
'title_transmit_bg_color' : '#c80003', 'title_transmit_bg_color' : '#c80003',

View File

@ -382,7 +382,7 @@
<object class="GtkTable" id="global_config_table"> <object class="GtkTable" id="global_config_table">
<property name="visible">True</property> <property name="visible">True</property>
<property name="can_focus">False</property> <property name="can_focus">False</property>
<property name="n_rows">13</property> <property name="n_rows">15</property>
<property name="n_columns">2</property> <property name="n_columns">2</property>
<property name="column_spacing">6</property> <property name="column_spacing">6</property>
<child> <child>
@ -803,6 +803,60 @@
<property name="bottom_attach">13</property> <property name="bottom_attach">13</property>
</packing> </packing>
</child> </child>
<child>
<object class="GtkLabel" id="label31">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="label" translatable="yes">Use custom URL handler</property>
</object>
<packing>
<property name="top_attach">13</property>
<property name="bottom_attach">14</property>
</packing>
</child>
<child>
<object class="GtkLabel" id="label33">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="label" translatable="yes">Custom URL handler</property>
</object>
<packing>
<property name="top_attach">14</property>
<property name="bottom_attach">15</property>
</packing>
</child>
<child>
<object class="GtkCheckButton" id="use_custom_url_handler_checkbox">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="receives_default">False</property>
<property name="use_action_appearance">False</property>
<property name="draw_indicator">True</property>
<signal name="toggled" handler="on_use_custom_url_handler_checkbutton_toggled" swapped="no"/>
</object>
<packing>
<property name="left_attach">1</property>
<property name="right_attach">2</property>
<property name="top_attach">13</property>
<property name="bottom_attach">14</property>
<property name="x_options"></property>
<property name="y_options">GTK_EXPAND</property>
</packing>
</child>
<child>
<object class="GtkEntry" id="custom_url_handler_entry">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="invisible_char">•</property>
<signal name="changed" handler="on_custom_url_handler_entry_changed" swapped="no"/>
</object>
<packing>
<property name="left_attach">1</property>
<property name="right_attach">2</property>
<property name="top_attach">14</property>
<property name="bottom_attach">15</property>
</packing>
</child>
</object> </object>
<packing> <packing>
<property name="expand">True</property> <property name="expand">True</property>

View File

@ -460,6 +460,13 @@ class PrefsEditor:
# Inactive terminal shading # Inactive terminal shading
widget = guiget('inactive_color_offset') widget = guiget('inactive_color_offset')
widget.set_value(float(self.config['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 ## Background tab
# Radio values # Radio values
@ -822,6 +829,11 @@ class PrefsEditor:
self.config['exit_action'] = value self.config['exit_action'] = value
self.config.save() 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): def on_custom_command_entry_changed(self, widget):
"""Custom command value changed""" """Custom command value changed"""
self.config['custom_command'] = widget.get_text() self.config['custom_command'] = widget.get_text()
@ -1027,6 +1039,17 @@ class PrefsEditor:
selection.select_iter(model.get_iter_first()) selection.select_iter(model.get_iter_first())
self.config.save() 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): def on_use_custom_command_checkbutton_toggled(self, checkbox):
"""Toggling the use_custom_command checkbox needs to alter the """Toggling the use_custom_command checkbox needs to alter the
sensitivity of the custom_command entrybox""" sensitivity of the custom_command entrybox"""

View File

@ -1305,6 +1305,15 @@ class Terminal(gtk.VBox):
url = self.prepare_url(url) url = self.prepare_url(url)
dbg('open_url: URL: %s (prepared: %s)' % (url, prepare)) 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 \ if gtk.gtk_version < (2, 14, 0) or \
not hasattr(gtk, 'show_uri') or \ not hasattr(gtk, 'show_uri') or \
not hasattr(gtk.gdk, 'CURRENT_TIME'): not hasattr(gtk.gdk, 'CURRENT_TIME'):