Commit 7af87739 authored by Yann Leboulanger's avatar Yann Leboulanger

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

parent 203f8c76
......@@ -35,6 +35,7 @@
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
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 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
# kind = 'url' or 'mail'
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 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'):
......
......@@ -504,9 +504,7 @@ def create_av_combobox(opt_name, device_dict, config_name=None,
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 @@ def on_applications_combobox_changed(self, widget):
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):
......
......@@ -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
......
......@@ -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)
......
......@@ -2649,9 +2649,6 @@ def __init__(self):
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)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment