use webbrowser module to open uri instead of using popen. Fixes #5751
This commit is contained in:
parent
203f8c76a0
commit
7af87739bc
5 changed files with 24 additions and 70 deletions
|
@ -35,6 +35,7 @@ import locale
|
||||||
import os
|
import os
|
||||||
import subprocess
|
import subprocess
|
||||||
import urllib
|
import urllib
|
||||||
|
import webbrowser
|
||||||
import errno
|
import errno
|
||||||
import select
|
import select
|
||||||
import base64
|
import base64
|
||||||
|
@ -671,30 +672,20 @@ def get_contact_dict_for_account(account):
|
||||||
return contacts_dict
|
return contacts_dict
|
||||||
|
|
||||||
def launch_browser_mailer(kind, uri):
|
def launch_browser_mailer(kind, uri):
|
||||||
#kind = 'url' or 'mail'
|
# kind = 'url' or 'mail'
|
||||||
if os.name == 'nt':
|
if kind in ('mail', 'sth_at_sth') and not uri.startswith('mailto:'):
|
||||||
try:
|
uri = 'mailto:' + uri
|
||||||
os.startfile(uri) # if pywin32 is installed we open
|
|
||||||
except Exception:
|
|
||||||
pass
|
|
||||||
|
|
||||||
else:
|
if kind == 'url' and uri.startswith('www.'):
|
||||||
if kind in ('mail', 'sth_at_sth') and not uri.startswith('mailto:'):
|
uri = 'http://' + uri
|
||||||
uri = 'mailto:' + uri
|
|
||||||
|
|
||||||
if kind == 'url' and uri.startswith('www.'):
|
if not gajim.config.get('autodetect_browser_mailer'):
|
||||||
uri = 'http://' + uri
|
if kind == 'url':
|
||||||
|
command = gajim.config.get('custombrowser')
|
||||||
if gajim.config.get('openwith') in ('xdg-open', 'gnome-open',
|
elif kind in ('mail', 'sth_at_sth'):
|
||||||
'kfmclient exec', 'exo-open'):
|
command = gajim.config.get('custommailapp')
|
||||||
command = gajim.config.get('openwith')
|
if command == '': # if no app is configured
|
||||||
elif gajim.config.get('openwith') == 'custom':
|
return
|
||||||
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)
|
command = build_command(command, uri)
|
||||||
try:
|
try:
|
||||||
|
@ -702,18 +693,14 @@ def launch_browser_mailer(kind, uri):
|
||||||
except Exception:
|
except Exception:
|
||||||
pass
|
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:
|
else:
|
||||||
if gajim.config.get('openwith') in ('xdg-open', 'gnome-open',
|
webbrowser.open(uri)
|
||||||
'kfmclient exec', 'exo-open'):
|
|
||||||
command = gajim.config.get('openwith')
|
|
||||||
elif gajim.config.get('openwith') == 'custom':
|
def launch_file_manager(path_to_open):
|
||||||
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
|
if command == '': # if no app is configured
|
||||||
return
|
return
|
||||||
command = build_command(command, path_to_open)
|
command = build_command(command, path_to_open)
|
||||||
|
@ -721,6 +708,8 @@ def launch_file_manager(path_to_open):
|
||||||
exec_command(command)
|
exec_command(command)
|
||||||
except Exception:
|
except Exception:
|
||||||
pass
|
pass
|
||||||
|
else:
|
||||||
|
webbrowser.open(uri)
|
||||||
|
|
||||||
def play_sound(event):
|
def play_sound(event):
|
||||||
if not gajim.config.get('sounds_on'):
|
if not gajim.config.get('sounds_on'):
|
||||||
|
|
|
@ -504,9 +504,7 @@ class PreferencesWindow:
|
||||||
|
|
||||||
if gajim.config.get('autodetect_browser_mailer'):
|
if gajim.config.get('autodetect_browser_mailer'):
|
||||||
self.applications_combobox.set_active(0)
|
self.applications_combobox.set_active(0)
|
||||||
# else autodetect_browser_mailer is False.
|
else:
|
||||||
# so user has 'Always Use GNOME/KDE/Xfce' or Custom
|
|
||||||
elif gajim.config.get('openwith') == 'custom':
|
|
||||||
self.applications_combobox.set_active(1)
|
self.applications_combobox.set_active(1)
|
||||||
self.xml.get_object('custom_apps_frame').show()
|
self.xml.get_object('custom_apps_frame').show()
|
||||||
|
|
||||||
|
@ -1146,7 +1144,6 @@ class PreferencesWindow:
|
||||||
elif widget.get_active() == 1:
|
elif widget.get_active() == 1:
|
||||||
gajim.config.set('autodetect_browser_mailer', False)
|
gajim.config.set('autodetect_browser_mailer', False)
|
||||||
self.xml.get_object('custom_apps_frame').show()
|
self.xml.get_object('custom_apps_frame').show()
|
||||||
gajim.config.set('openwith', 'custom')
|
|
||||||
gajim.interface.save_config()
|
gajim.interface.save_config()
|
||||||
|
|
||||||
def on_custom_browser_entry_changed(self, widget):
|
def on_custom_browser_entry_changed(self, widget):
|
||||||
|
|
|
@ -40,7 +40,7 @@ demandimport.enable()
|
||||||
demandimport.ignore += ['gobject._gobject', 'libasyncns', 'i18n',
|
demandimport.ignore += ['gobject._gobject', 'libasyncns', 'i18n',
|
||||||
'logging.NullHandler', 'dbus.glib', 'dbus.service',
|
'logging.NullHandler', 'dbus.glib', 'dbus.service',
|
||||||
'command_system.implementation.standard', 'OpenSSL.SSL', 'OpenSSL.crypto',
|
'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 os
|
||||||
import sys
|
import sys
|
||||||
|
|
|
@ -221,35 +221,6 @@ def get_default_font():
|
||||||
|
|
||||||
return None
|
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():
|
def get_running_processes():
|
||||||
"""
|
"""
|
||||||
Return running processes or None (if /proc does not exist)
|
Return running processes or None (if /proc does not exist)
|
||||||
|
|
|
@ -2649,9 +2649,6 @@ class Interface:
|
||||||
gajim.config.set_per('themes', theme_name, o,
|
gajim.config.set_per('themes', theme_name, o,
|
||||||
theme[d.index(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()
|
gajim.idlequeue = idlequeue.get_idlequeue()
|
||||||
# resolve and keep current record of resolved hosts
|
# resolve and keep current record of resolved hosts
|
||||||
gajim.resolver = resolver.get_resolver(gajim.idlequeue)
|
gajim.resolver = resolver.get_resolver(gajim.idlequeue)
|
||||||
|
|
Loading…
Add table
Reference in a new issue