2005-07-21 23:39:47 +02:00
|
|
|
## gtkgui_helpers.py
|
|
|
|
##
|
|
|
|
## Gajim Team:
|
|
|
|
## - Yann Le Boulanger <asterix@lagaule.org>
|
|
|
|
## - Vincent Hanquez <tab@snarc.org>
|
|
|
|
## - Nikos Kouremenos <kourem@gmail.com>
|
|
|
|
## - Dimitur Kirov <dkirov@gmail.com>
|
|
|
|
##
|
|
|
|
## This file was initially written by Dimitur Kirov
|
|
|
|
##
|
|
|
|
## Copyright (C) 2003-2005 Gajim Team
|
|
|
|
##
|
|
|
|
## This program is free software; you can redistribute it and/or modify
|
|
|
|
## it under the terms of the GNU General Public License as published
|
|
|
|
## by the Free Software Foundation; version 2 only.
|
|
|
|
##
|
|
|
|
## This program is distributed in the hope that it will be useful,
|
|
|
|
## but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
## GNU General Public License for more details.
|
|
|
|
##
|
|
|
|
|
2005-07-23 14:45:17 +02:00
|
|
|
import xml.sax.saxutils
|
2005-07-23 15:09:36 +02:00
|
|
|
import gtk
|
2005-07-30 12:20:24 +02:00
|
|
|
from common import i18n
|
2005-07-21 23:39:47 +02:00
|
|
|
|
2005-07-30 12:20:24 +02:00
|
|
|
_ = i18n._
|
|
|
|
APP = i18n.APP
|
|
|
|
gtk.glade.bindtextdomain (APP, i18n.DIR)
|
|
|
|
gtk.glade.textdomain (APP)
|
|
|
|
|
|
|
|
def convert_bytes(string):
|
|
|
|
suffix = ''
|
|
|
|
bytes = int(string)
|
|
|
|
if bytes >= 1024:
|
|
|
|
bytes /= 1024
|
|
|
|
if bytes >= 1024:
|
|
|
|
bytes /= 1024
|
|
|
|
if bytes >= 1024:
|
|
|
|
bytes /= 1024
|
|
|
|
suffix = _('%s Gb')
|
|
|
|
else:
|
|
|
|
suffix = _('%s Mb')
|
|
|
|
else:
|
|
|
|
suffix = _('%s Kb')
|
|
|
|
else:
|
|
|
|
if bytes == 1:
|
|
|
|
suffix = _('%s byte')
|
|
|
|
else:
|
|
|
|
suffix = _('%s bytes')
|
|
|
|
return suffix % str(bytes)
|
|
|
|
|
2005-07-21 23:39:47 +02:00
|
|
|
def escape_for_pango_markup(string):
|
2005-07-23 14:45:17 +02:00
|
|
|
# escapes < > & \ "
|
|
|
|
# for pango markup not to break
|
|
|
|
if string is None:
|
|
|
|
return
|
|
|
|
if gtk.pygtk_version >= (2, 8, 0) and gtk.gtk_version >= (2, 8, 0):
|
|
|
|
escaped_str = gobject.markup_escape_text(string)
|
|
|
|
else:
|
|
|
|
escaped_str =xml.sax.saxutils.escape(string, {'\\': ''',
|
|
|
|
'"': '"'})
|
|
|
|
|
|
|
|
return escaped_str
|
2005-07-25 16:38:21 +02:00
|
|
|
|
|
|
|
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')
|