1
# This file is part of emesene.
3
# Emesene is free software; you can redistribute it and/or modify
4
# it under the terms of the GNU General Public License as published by
5
# the Free Software Foundation; either version 2 of the License, or
6
# (at your option) any later version.
8
# emesene is distributed in the hope that it will be useful,
9
# but WITHOUT ANY WARRANTY; without even the implied warranty of
10
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11
# GNU General Public License for more details.
13
# You should have received a copy of the GNU General Public License
14
# along with emesene; if not, write to the Free Software
15
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
21
from htmlentitydefs import codepoint2name
24
# Global variables for use throughout the program
32
'''a namespace for paths'''
36
if hasattr(sys, "frozen"):
37
APP_PATH = os.path.dirname(sys.executable)
39
APP_PATH = os.path.abspath(os.path.dirname(__file__))
41
HOME_DIR = os.path.expanduser('~')
42
CONF_DIR_NAME = '.config' + DIR_SEP + 'emesene1.0'
43
CONFIG_DIR = HOME_DIR + DIR_SEP + CONF_DIR_NAME
45
THEME_HOME_PATH = CONFIG_DIR + DIR_SEP + 'themes'
46
THEME_SYSTEM_WIDE_PATH = APP_PATH + DIR_SEP + 'themes'
47
DEFAULT_THEME_PATH = THEME_SYSTEM_WIDE_PATH + DIR_SEP + 'default' + DIR_SEP
49
PLUGINS_HOME = 'pluginsEmesene'
50
PLUGINS_SYSTEM_WIDE = 'plugins_base'
51
PLUGIN_SYSTEM_WIDE_PATH = APP_PATH + DIR_SEP + PLUGINS_SYSTEM_WIDE
52
PLUGIN_HOME_PATH = CONFIG_DIR + DIR_SEP + PLUGINS_HOME
54
SMILIES_SYSTEM_WIDE_PATH = APP_PATH + DIR_SEP + 'smilies'
55
SMILIES_HOME_PATH = CONFIG_DIR + DIR_SEP + 'smilies'
56
DEFAULT_SMILIES_PATH = SMILIES_SYSTEM_WIDE_PATH + DIR_SEP + 'default' + DIR_SEP
58
CONVTHEMES_SYSTEM_WIDE_PATH = APP_PATH + DIR_SEP + 'conversation_themes'
59
CONVTHEMES_HOME_PATH = CONFIG_DIR + DIR_SEP + 'conversation_themes'
60
DEFAULT_CONVTHEMES_PATH = CONVTHEMES_SYSTEM_WIDE_PATH + DIR_SEP + 'default' + DIR_SEP
62
LANG_PATH = APP_PATH + DIR_SEP + 'po'
63
SOUNDS_PATH = APP_PATH + DIR_SEP + 'sound_themes'
65
# workaround for pluginsEmesene/__init__.py
66
PLUGINS_HOME = PATH.PLUGINS_HOME
67
PLUGIN_SYSTEM_WIDE_PATH = PATH.PLUGIN_SYSTEM_WIDE_PATH
70
RESPONSE_DELETE_ALIAS = 50
71
RESPONSE_NO_AVATAR = -50
72
MAX_MESSAGE_LENGTH = 1100
75
urlRe = re.compile("(^|[^A-Za-z0-9])(https?\:\/\/|ftp\:\/\/|www\.)([A-Za-z0-9\$_\.\+!\*':\(\|\)@,;\/\?&%=~#^`\\\-]+)")
76
reUnencode = re.compile( '=\\?([^\\?]+)\\?Q\\?([^\\?]+)\\?=' )
77
reChar = re.compile( '=([A-z0-9]{2})' )
83
def htmlEncode(string):
84
'''this method return a string whit html tags encoded'''
85
for i,j in codepoint2name.iteritems():
86
if i <= 256 and str(chr(i)) in string:
87
string = string.replace(chr(i), j)
90
def rgbToHexa( color ):
91
'''take a gtk.gdk.Color end returns a string with html way color. Eg.: #FFCC00'''
94
green = color.green >> 8
95
blue = color.blue >> 8
97
return '#'+'%02X%02X%02X' % ( red , green , blue )
100
'''Sorts a list in alphabetical order without regard of the capitalization'''
103
list.sort( key= lambda x: str.lower( x ) )
106
def getLinks( text ):
108
text = re.sub( urlRe, _searchAnchors, text.replace('%','%%') )
111
def _searchAnchors( data ):
112
s, w, url = data.groups()
115
href = 'http://'+href