changeset 22ffe33e941a in /home/hg/repos/gajim
details:http://hg.gajim.org/gajim?cmd=changeset;node=22ffe33e941a description: use webbrowser module to open uri instead of using popen. Fixes #5751
diffstat:
src/common/helpers.py | 55 ++++++++++++++++++++------------------------------ src/config.py | 5 +--- src/gajim.py | 2 +- src/gtkgui_helpers.py | 29 -------------------------- src/gui_interface.py | 3 -- 5 files changed, 24 insertions(+), 70 deletions(-)
diffs (175 lines):
diff -r 1880b5dd2cdb -r 22ffe33e941a src/common/helpers.py --- a/src/common/helpers.py Tue Apr 19 08:54:41 2011 +0200 +++ b/src/common/helpers.py Tue Apr 19 14:36:22 2011 +0200 @@ -35,6 +35,7 @@ import os import subprocess import urllib +import webbrowser import errno import select import base64 @@ -671,30 +672,20 @@ return contacts_dict
def launch_browser_mailer(kind, uri): - #kind = 'url' or 'mail' - if os.name == 'nt': - try: - os.startfile(uri) # if pywin32 is installed we open - except Exception: - pass + # kind = 'url' or 'mail' + if kind in ('mail', 'sth_at_sth') and not uri.startswith('mailto:'): + uri = 'mailto:' + uri
- else: - if kind in ('mail', 'sth_at_sth') and not uri.startswith('mailto:'): - uri = 'mailto:' + uri + if kind == 'url' and uri.startswith('www.'): + uri = 'http://' + uri
- if kind == 'url' and uri.startswith('www.'): - uri = 'http://' + uri - - if gajim.config.get('openwith') in ('xdg-open', 'gnome-open', - 'kfmclient exec', 'exo-open'): - command = gajim.config.get('openwith') - elif gajim.config.get('openwith') == 'custom': - if kind == 'url': - command = gajim.config.get('custombrowser') - elif kind in ('mail', 'sth_at_sth'): - command = gajim.config.get('custommailapp') - if command == '': # if no app is configured - return + if not gajim.config.get('autodetect_browser_mailer'): + if kind == 'url': + command = gajim.config.get('custombrowser') + elif kind in ('mail', 'sth_at_sth'): + command = gajim.config.get('custommailapp') + if command == '': # if no app is configured + return
command = build_command(command, uri) try: @@ -702,18 +693,14 @@ except Exception: pass
+ else: + webbrowser.open(uri) + + def launch_file_manager(path_to_open): - if os.name == 'nt': - try: - os.startfile(path_to_open) # if pywin32 is installed we open - except Exception: - pass - else: - if gajim.config.get('openwith') in ('xdg-open', 'gnome-open', - 'kfmclient exec', 'exo-open'): - command = gajim.config.get('openwith') - elif gajim.config.get('openwith') == 'custom': - command = gajim.config.get('custom_file_manager') + uri = 'file://' + path_to_open + if not gajim.config.get('autodetect_browser_mailer'): + command = gajim.config.get('custom_file_manager') if command == '': # if no app is configured return command = build_command(command, path_to_open) @@ -721,6 +708,8 @@ exec_command(command) except Exception: pass + else: + webbrowser.open(uri)
def play_sound(event): if not gajim.config.get('sounds_on'): diff -r 1880b5dd2cdb -r 22ffe33e941a src/config.py --- a/src/config.py Tue Apr 19 08:54:41 2011 +0200 +++ b/src/config.py Tue Apr 19 14:36:22 2011 +0200 @@ -504,9 +504,7 @@
if gajim.config.get('autodetect_browser_mailer'): self.applications_combobox.set_active(0) - # else autodetect_browser_mailer is False. - # so user has 'Always Use GNOME/KDE/Xfce' or Custom - elif gajim.config.get('openwith') == 'custom': + else: self.applications_combobox.set_active(1) self.xml.get_object('custom_apps_frame').show()
@@ -1146,7 +1144,6 @@ elif widget.get_active() == 1: gajim.config.set('autodetect_browser_mailer', False) self.xml.get_object('custom_apps_frame').show() - gajim.config.set('openwith', 'custom') gajim.interface.save_config()
def on_custom_browser_entry_changed(self, widget): diff -r 1880b5dd2cdb -r 22ffe33e941a src/gajim.py --- a/src/gajim.py Tue Apr 19 08:54:41 2011 +0200 +++ b/src/gajim.py Tue Apr 19 14:36:22 2011 +0200 @@ -40,7 +40,7 @@ demandimport.ignore += ['gobject._gobject', 'libasyncns', 'i18n', 'logging.NullHandler', 'dbus.glib', 'dbus.service', 'command_system.implementation.standard', 'OpenSSL.SSL', 'OpenSSL.crypto', - 'common.sleepy', 'DLFCN', 'dl', 'xml.sax', 'xml.sax.handler'] + 'common.sleepy', 'DLFCN', 'dl', 'xml.sax', 'xml.sax.handler', 'ic']
import os import sys diff -r 1880b5dd2cdb -r 22ffe33e941a src/gtkgui_helpers.py --- a/src/gtkgui_helpers.py Tue Apr 19 08:54:41 2011 +0200 +++ b/src/gtkgui_helpers.py Tue Apr 19 14:36:22 2011 +0200 @@ -221,35 +221,6 @@
return None
-def autodetect_browser_mailer(): - # recognize the environment and set appropriate browser/mailer - if user_supports_xdg_open(): - gajim.config.set('openwith', 'xdg-open') - elif user_runs_gnome(): - gajim.config.set('openwith', 'gnome-open') - elif user_runs_kde(): - gajim.config.set('openwith', 'kfmclient exec') - elif user_runs_xfce(): - gajim.config.set('openwith', 'exo-open') - else: - gajim.config.set('openwith', 'custom') - -def user_supports_xdg_open(): - import os.path - return os.path.isfile('/usr/bin/xdg-open') - -def user_runs_gnome(): - return 'gnome-session' in get_running_processes() - -def user_runs_kde(): - return 'startkde' in get_running_processes() - -def user_runs_xfce(): - procs = get_running_processes() - if 'startxfce4' in procs or 'xfce4-session' in procs: - return True - return False - def get_running_processes(): """ Return running processes or None (if /proc does not exist) diff -r 1880b5dd2cdb -r 22ffe33e941a src/gui_interface.py --- a/src/gui_interface.py Tue Apr 19 08:54:41 2011 +0200 +++ b/src/gui_interface.py Tue Apr 19 14:36:22 2011 +0200 @@ -2649,9 +2649,6 @@ gajim.config.set_per('themes', theme_name, o, theme[d.index(o)])
- if gajim.config.get('autodetect_browser_mailer') or not cfg_was_read: - gtkgui_helpers.autodetect_browser_mailer() - gajim.idlequeue = idlequeue.get_idlequeue() # resolve and keep current record of resolved hosts gajim.resolver = resolver.get_resolver(gajim.idlequeue)