use webbrowser module to open uri instead of using popen. Fixes #5751

This commit is contained in:
Yann Leboulanger 2011-04-19 14:36:22 +02:00
parent 203f8c76a0
commit 7af87739bc
5 changed files with 24 additions and 70 deletions

View File

@ -35,6 +35,7 @@ import locale
import os
import subprocess
import urllib
import webbrowser
import errno
import select
import base64
@ -671,30 +672,20 @@ def get_contact_dict_for_account(account):
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 @@ def launch_browser_mailer(kind, uri):
except Exception:
pass
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')
webbrowser.open(uri)
def launch_file_manager(path_to_open):
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 @@ def launch_file_manager(path_to_open):
exec_command(command)
except Exception:
pass
else:
webbrowser.open(uri)
def play_sound(event):
if not gajim.config.get('sounds_on'):

View File

@ -504,9 +504,7 @@ class PreferencesWindow:
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 @@ class PreferencesWindow:
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):

View File

@ -40,7 +40,7 @@ demandimport.enable()
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

View File

@ -221,35 +221,6 @@ def get_default_font():
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)

View File

@ -2649,9 +2649,6 @@ class Interface:
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)