From 3e2bfd67a300e2a79b0094d7f475066a182e06da Mon Sep 17 00:00:00 2001 From: Yann Leboulanger Date: Wed, 8 Sep 2010 15:25:36 +0200 Subject: [PATCH] use xdg-open if available. Thanks to polymorphm forthe initial patch. Fixes #5874 --- autogen.sh | 2 +- data/gui/preferences_window.ui | 11 +---------- src/common/config.py | 2 +- src/common/defs.py | 2 +- src/common/helpers.py | 18 ++++++------------ src/common/optparser.py | 13 ++++++++++++- src/config.py | 25 ++++++------------------- src/gtkgui_helpers.py | 8 +++++++- 8 files changed, 35 insertions(+), 46 deletions(-) diff --git a/autogen.sh b/autogen.sh index f852dfe90..eee074b5d 100755 --- a/autogen.sh +++ b/autogen.sh @@ -1,5 +1,5 @@ #!/usr/bin/env bash - gajimversion="0.13.90.1" + gajimversion="0.14.0.1" if [ -d ".hg" ]; then node=$(hg tip --template "{node}") hgversion="-${node:0:12}" diff --git a/data/gui/preferences_window.ui b/data/gui/preferences_window.ui index a36c198b4..155b5e1a1 100644 --- a/data/gui/preferences_window.ui +++ b/data/gui/preferences_window.ui @@ -9,16 +9,7 @@ - Autodetect on every Gajim startup - - - Always use GNOME default applications - - - Always use KDE default applications - - - Always use Xfce default applications + Use default applications Custom diff --git a/src/common/config.py b/src/common/config.py index e8cc999a4..0f625cc44 100644 --- a/src/common/config.py +++ b/src/common/config.py @@ -59,7 +59,7 @@ class Config: DEFAULT_ICONSET = 'dcraven' DEFAULT_MOOD_ICONSET = 'default' DEFAULT_ACTIVITY_ICONSET = 'default' - DEFAULT_OPENWITH = 'gnome-open' + DEFAULT_OPENWITH = 'xdg-open' DEFAULT_BROWSER = 'firefox' DEFAULT_MAILAPP = 'mozilla-thunderbird -compose' DEFAULT_FILE_MANAGER = 'xffm' diff --git a/src/common/defs.py b/src/common/defs.py index 5a988d8bc..44a66691d 100644 --- a/src/common/defs.py +++ b/src/common/defs.py @@ -27,7 +27,7 @@ docdir = '../' basedir = '../' localedir = '../po' -version = '0.13.90.1' +version = '0.14.0.1' import subprocess try: node = subprocess.Popen('hg tip --template {node}', shell=True, diff --git a/src/common/helpers.py b/src/common/helpers.py index 71426bee3..8ac12bfb4 100644 --- a/src/common/helpers.py +++ b/src/common/helpers.py @@ -683,12 +683,9 @@ def launch_browser_mailer(kind, uri): if kind == 'url' and uri.startswith('www.'): uri = 'http://' + uri - if gajim.config.get('openwith') == 'gnome-open': - command = 'gnome-open' - elif gajim.config.get('openwith') == 'kfmclient exec': - command = 'kfmclient exec' - elif gajim.config.get('openwith') == 'exo-open': - command = 'exo-open' + 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') @@ -710,12 +707,9 @@ def launch_file_manager(path_to_open): except Exception: pass else: - if gajim.config.get('openwith') == 'gnome-open': - command = 'gnome-open' - elif gajim.config.get('openwith') == 'kfmclient exec': - command = 'kfmclient exec' - elif gajim.config.get('openwith') == 'exo-open': - command = 'exo-open' + 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') if command == '': # if no app is configured diff --git a/src/common/optparser.py b/src/common/optparser.py index 31f41daa1..606196086 100644 --- a/src/common/optparser.py +++ b/src/common/optparser.py @@ -222,6 +222,8 @@ class OptionsParser: self.update_config_to_013101() if old < [0, 13, 90, 1] and new >= [0, 13, 90, 1]: self.update_config_to_013901() + if old < [0, 14, 0, 1] and new >= [0, 14, 0, 1]: + self.update_config_to_01401() gajim.logger.init_vars() gajim.logger.attach_cache_database() @@ -892,4 +894,13 @@ class OptionsParser: def update_config_to_013901(self): schemes = 'aaa:// aaas:// acap:// cap:// cid: crid:// data: dav: dict:// dns: fax: file:/ ftp:// geo: go: gopher:// h323: http:// https:// iax: icap:// im: imap:// info: ipp:// iris: iris.beep: iris.xpc: iris.xpcs: iris.lwz: ldap:// mid: modem: msrp:// msrps:// mtqp:// mupdate:// news: nfs:// nntp:// opaquelocktoken: pop:// pres: prospero:// rtsp:// service: shttp:// sip: sips: sms: snmp:// soap.beep:// soap.beeps:// tag: tel: telnet:// tftp:// thismessage:/ tip:// tv: urn:// vemmi:// xmlrpc.beep:// xmlrpc.beeps:// z39.50r:// z39.50s:// about: apt: cvs:// daap:// ed2k:// feed: fish:// git:// iax2: irc:// ircs:// ldaps:// magnet: mms:// rsync:// ssh:// svn:// sftp:// smb:// webcal://' gajim.config.set('uri_schemes', schemes) - gajim.config.set('version', '0.13.90.1') \ No newline at end of file + gajim.config.set('version', '0.13.90.1') + + def update_config_to_01401(self): + if 'autodetect_browser_mailer' not in self.old_values or 'openwith' \ + not in self.old_values or \ + (self.old_values['autodetect_browser_mailer'] == 'False' and \ + self.old_values['openwith'] != 'custom'): + gajim.config.set('autodetect_browser_mailer', True) + gajim.config.set('openwith', gajim.config.DEFAULT_OPENWITH) + gajim.config.set('version', '0.14.0.1') diff --git a/src/config.py b/src/config.py index 36730092b..280f6dc84 100644 --- a/src/config.py +++ b/src/config.py @@ -497,14 +497,8 @@ class PreferencesWindow: 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') == 'gnome-open': - self.applications_combobox.set_active(1) - elif gajim.config.get('openwith') == 'kfmclient exec': - self.applications_combobox.set_active(2) - elif gajim.config.get('openwith') == 'exo-open': - self.applications_combobox.set_active(3) elif gajim.config.get('openwith') == 'custom': - self.applications_combobox.set_active(4) + self.applications_combobox.set_active(1) self.xml.get_object('custom_apps_frame').show() self.xml.get_object('custom_browser_entry').set_text( @@ -1133,20 +1127,13 @@ class PreferencesWindow: gajim.config.set('stun_server', widget.get_text().decode('utf-8')) def on_applications_combobox_changed(self, widget): - gajim.config.set('autodetect_browser_mailer', False) - if widget.get_active() == 4: + if widget.get_active() == 0: + gajim.config.set('autodetect_browser_mailer', True) + self.xml.get_object('custom_apps_frame').hide() + 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') - else: - if widget.get_active() == 0: - gajim.config.set('autodetect_browser_mailer', True) - elif widget.get_active() == 1: - gajim.config.set('openwith', 'gnome-open') - elif widget.get_active() == 2: - gajim.config.set('openwith', 'kfmclient exec') - elif widget.get_active() == 3: - gajim.config.set('openwith', 'exo-open') - self.xml.get_object('custom_apps_frame').hide() gajim.interface.save_config() def on_custom_browser_entry_changed(self, widget): diff --git a/src/gtkgui_helpers.py b/src/gtkgui_helpers.py index 5f9aa3d56..470cd84a0 100644 --- a/src/gtkgui_helpers.py +++ b/src/gtkgui_helpers.py @@ -223,7 +223,9 @@ def get_default_font(): def autodetect_browser_mailer(): # recognize the environment and set appropriate browser/mailer - if user_runs_gnome(): + 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') @@ -232,6 +234,10 @@ def autodetect_browser_mailer(): 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()