Add crashproof code for adding URL handlers from plugins, and reacting to them

This commit is contained in:
Chris Jones 2009-12-17 23:17:32 +00:00
parent b84f593404
commit 30f5225884
1 changed files with 33 additions and 10 deletions

View File

@ -22,6 +22,7 @@ from titlebar import Titlebar
from terminal_popup_menu import TerminalPopupMenu from terminal_popup_menu import TerminalPopupMenu
from searchbar import Searchbar from searchbar import Searchbar
from translation import _ from translation import _
import plugin
try: try:
import vte import vte
@ -204,10 +205,21 @@ class Terminal(gtk.VBox):
self.matches['nntp'] = self.vte.match_add (lboundry + self.matches['nntp'] = self.vte.match_add (lboundry +
'''news:[-A-Z\^_a-z{|}~!"#$%&'()*+,./0-9;:=?`]+@\ '''news:[-A-Z\^_a-z{|}~!"#$%&'()*+,./0-9;:=?`]+@\
[-A-Za-z0-9.]+(:[0-9]+)?''' + rboundry) [-A-Za-z0-9.]+(:[0-9]+)?''' + rboundry)
# if the url looks like a Launchpad changelog closure entry
# LP: #92953 - make it a url to http://bugs.launchpad.net # Now add any matches from plugins
self.matches['launchpad'] = self.vte.match_add ( try:
'\\bLP:? #?[0-9]+\\b') registry = plugin.PluginRegistry()
registry.load_plugins()
plugins = registry.get_plugins_by_capability('url_handler')
for urlplugin in plugins:
name = urlplugin.handler_name
match = urlplugin.match
self.matches[name] = self.vte.match_add(match)
dbg('Terminal::update_matches: added plugin URL handler \
for %s' % name)
except Exception as ex:
err('Terminal::update_url_matches: %s' % ex)
def connect_signals(self): def connect_signals(self):
"""Connect all the gtk signals and drag-n-drop mechanics""" """Connect all the gtk signals and drag-n-drop mechanics"""
@ -858,12 +870,23 @@ class Terminal(gtk.VBox):
url = 'ftp://' + url url = 'ftp://' + url
elif match == self.matches['addr_only']: elif match == self.matches['addr_only']:
url = 'http://' + url url = 'http://' + url
elif match == self.matches['launchpad']: elif match in self.matches.values():
for item in re.findall(r'[0-9]+', url): # We have a match, but it's not a hard coded one, so it's a plugin
url = 'https://bugs.launchpad.net/bugs/%s' % item try:
return(url) registry = plugin.PluginRegistry()
else: registry.load_plugins()
return(url) plugins = registry.get_plugins_by_capability('url_handler')
for urlplugin in plugins:
if match == self.matches[urlplugin.handler_name]:
newurl = urlplugin.callback(url)
if newurl is not None:
url = newurl
break;
except Exception as ex:
err('Terminal::prepare_url: %s' % ex)
return(url)
def open_url(self, url, prepare=False): def open_url(self, url, prepare=False):
"""Open a given URL, conditionally unpacking it from a VTE match""" """Open a given URL, conditionally unpacking it from a VTE match"""