diff --git a/src/config.py b/src/config.py index 8f56ffe73f781d3c4a709ca40e4d3a18e0d21b18..2ed005caa42dd1292be2cdc2f8cc7e17ed7d097c 100644 --- a/src/config.py +++ b/src/config.py @@ -24,6 +24,7 @@ import os import common.config import common.sleepy +import gtkgui_helpers import dialogs import cell_renderer_image import cell_renderer_image @@ -358,12 +359,17 @@ class PreferencesWindow: self.links_frame.set_no_show_all(True) else: self.links_open_with_combobox = self.xml.get_widget('links_open_with_combobox') - if gajim.config.get('openwith') == 'gnome-open': + if gajim.config.get('autodetect_browser_mailer'): self.links_open_with_combobox.set_active(0) + gtkgui_helpers.plugin.autodetect_browser_mailer() + # autodetect_browser_mailer is now False. + # so user has 'Always Use GNOME/KDE' or Custom + elif gajim.config.get('openwith') == 'gnome-open': + self.links_open_with_combobox.set_active(1) elif gajim.config.get('openwith') == 'kfmclient exec': - self.links_open_with_combobox.set_active(True) - elif gajim.config.get('openwith') == 'custom': self.links_open_with_combobox.set_active(2) + elif gajim.config.get('openwith') == 'custom': + self.links_open_with_combobox.set_active(3) self.xml.get_widget('custom_apps_frame').set_sensitive(True) self.xml.get_widget('custom_browser_entry').set_text( gajim.config.get('custombrowser')) @@ -779,13 +785,16 @@ class PreferencesWindow: self.save_status_messages(model) def on_links_open_with_combobox_changed(self, widget): + gajim.config.set('autodetect_browser_mailer', False) if widget.get_active() == 2: self.xml.get_widget('custom_apps_frame').set_sensitive(True) 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') - if widget.get_active() == 1: + elif widget.get_active() == 2: gajim.config.set('openwith', 'kfmclient exec') self.xml.get_widget('custom_apps_frame').set_sensitive(False) self.plugin.save_config() diff --git a/src/gajim.py b/src/gajim.py index 2df43264176f8cf90148a47ab9e21b54a72603e7..6729751ce99dc1f42d0840f047bf31a6d69b7405 100755 --- a/src/gajim.py +++ b/src/gajim.py @@ -30,6 +30,7 @@ except RuntimeError, msg: if str(msg) == 'could not open display': print 'Gajim needs Xserver to run. Exiting...' sys.exit() + import gtk.glade import gobject import os @@ -37,6 +38,7 @@ import sre import signal import getopt import time +import gtkgui_helpers from common import i18n i18n.init() @@ -937,6 +939,10 @@ class Interface: gajim.config.set_per('themes', theme, o, default[theme][d.index(o)]) + + if gajim.config.get('autodetect_browser_mailer'): + gtkgui_helpers.plugin.autodetect_browser_mailer() + if gajim.verbose: gajim.log.setLevel(gajim.logging.DEBUG) else: diff --git a/src/gtkgui.glade b/src/gtkgui.glade index ce77b8a20c8f3e9a8a03af1c3018c9d0b31b5fe9..c93fb476f9e735fd6b948664ebdfe8d3daf7260d 100644 --- a/src/gtkgui.glade +++ b/src/gtkgui.glade @@ -5169,8 +5169,9 @@ <child> <widget class="GtkComboBox" id="links_open_with_combobox"> <property name="visible">True</property> - <property name="items" translatable="yes">GNOME default applications -KDE default applications + <property name="items" translatable="yes">Autodetect +Always use GNOME default applications +Always use KDE default applications Custom</property> <signal name="changed" handler="on_links_open_with_combobox_changed" last_modification_time="Sat, 05 Mar 2005 16:44:57 GMT"/> </widget> diff --git a/src/gtkgui_helpers.py b/src/gtkgui_helpers.py index eb0fcea5d3fc384275f19bf540d8e3e788eaf003..afa0ccde857579f1707b1dabac00da349713d62f 100644 --- a/src/gtkgui_helpers.py +++ b/src/gtkgui_helpers.py @@ -35,3 +35,41 @@ def escape_for_pango_markup(string): '"': '"'}) return escaped_str + +def autodetect_browser_mailer(self): + #recognize the environment for appropriate browser/mailer + if os.path.isdir('/proc'): + # under Linux: checking if 'gnome-session' or + # 'startkde' programs were run before gajim, by + # checking /proc (if it exists) + # + # if something is unclear, read `man proc`; + # if /proc exists, directories that have only numbers + # in their names contain data about processes. + # /proc/[xxx]/exe is a symlink to executable started + # as process number [xxx]. + # filter out everything that we are not interested in: + files = os.listdir('/proc') + + # files that doesn't have only digits in names... + files = filter(str.isdigit, files) + + # files that aren't directories... + files = filter(lambda f:os.path.isdir('/proc/' + f), files) + + # processes owned by somebody not running gajim... + # (we check if we have access to that file) + files = filter(lambda f:os.access('/proc/' + f +'/exe', os.F_OK), files) + + # be sure that /proc/[number]/exe is really a symlink + # to avoid TBs in incorrectly configured systems + files = filter(lambda f:os.path.islink('/proc/' + f + '/exe'), files) + + # list of processes + processes = [os.path.basename(os.readlink('/proc/' + f +'/exe')) for f in files] + if 'gnome-session' in processes: + gajim.config.set('openwith', 'gnome-open') + elif 'startkde' in processes: + gajim.config.set('openwith', 'kfmclient exec') + else: + gajim.config.set('openwith', 'custom')