From 30b69cd85a4fee4e76dbf45df4aafb32ff6426ed Mon Sep 17 00:00:00 2001 From: Alex Dedul Date: Mon, 16 Jul 2007 15:26:37 +0000 Subject: [PATCH] open_url_in_browser() tweaks. --- plugins/TorrentSearch/plugin.py | 2 +- src/common.py | 7 ++++++- src/dialogs.py | 8 +++++--- src/interface.py | 4 ++-- 4 files changed, 14 insertions(+), 7 deletions(-) diff --git a/plugins/TorrentSearch/plugin.py b/plugins/TorrentSearch/plugin.py index 3ad3484f7..c5d348d9f 100644 --- a/plugins/TorrentSearch/plugin.py +++ b/plugins/TorrentSearch/plugin.py @@ -126,7 +126,7 @@ class plugin_Search: url = url.replace('${query}', entry) print 'URL =', url print 'Entry =', entry - common.open_url_in_browser(None, url) + common.open_url_in_browser(url) def populate_search_menu(self): import gtk diff --git a/src/common.py b/src/common.py index 3502550be..6f7a0c1fe 100644 --- a/src/common.py +++ b/src/common.py @@ -113,7 +113,7 @@ def get_glade_file(fname): def get_pixmap(fname): return os.path.join(PIXMAP_DIR, fname) -def open_url_in_browser(dialog, link): +def open_url_in_browser(link): class LaunchBrowser(threading.Thread): def run(self): try: @@ -122,6 +122,11 @@ def open_url_in_browser(dialog, link): print _("Error: no webbrowser found") LaunchBrowser().start() +def is_url(url): + import re + + return bool(re.search('^(https?|ftp)://', url)) + def fetch_url(url): import urllib diff --git a/src/dialogs.py b/src/dialogs.py index 18d3535ad..104230c2d 100644 --- a/src/dialogs.py +++ b/src/dialogs.py @@ -150,8 +150,7 @@ class PreferencesDlg: return r def TestPort(self, widget): - common.open_url_in_browser(self.dialog, - 'http://www.deluge-torrent.org/test-port.php?port=%s' % self.active_port) + common.open_url_in_browser('http://www.deluge-torrent.org/test-port.php?port=%s' % self.active_port) def tray_toggle(self, widget): @@ -273,7 +272,10 @@ class PluginDlg: def show_about_dialog(parent=None): - gtk.about_dialog_set_url_hook(common.open_url_in_browser) + def url_hook(dialog, url): + common.open_url_in_browser(url) + + gtk.about_dialog_set_url_hook(url_hook) abt = gtk.glade.XML(common.get_glade_file("aboutdialog.glade")).get_widget("aboutdialog") abt.set_name(common.PROGRAM_NAME) abt.set_version(common.PROGRAM_VERSION) diff --git a/src/interface.py b/src/interface.py index 36d3de457..846dcd635 100644 --- a/src/interface.py +++ b/src/interface.py @@ -1109,7 +1109,7 @@ class DelugeGTK: self.torrent_model_append(unique_id) def launchpad(self, obj=None): - common.open_url_in_browser('self', 'https://translations.launchpad.net/deluge/trunk/+pots/deluge') + common.open_url_in_browser('https://translations.launchpad.net/deluge/trunk/+pots/deluge') def add_torrent_clicked(self, obj=None): torrent = dialogs.show_file_open_dialog() @@ -1130,7 +1130,7 @@ class DelugeGTK: text = clip.wait_for_text() if text: text = text.strip() - if re.search('^(https?|ftp)://', text): + if common.is_url(text): entry.set_text(text) dlg.show_all() result = dlg.run()