2005-05-20 17:58:23 +02:00
|
|
|
## common/helpers.py
|
|
|
|
##
|
|
|
|
## Gajim Team:
|
|
|
|
## - Yann Le Boulanger <asterix@lagaule.org>
|
|
|
|
## - Vincent Hanquez <tab@snarc.org>
|
|
|
|
## - Nikos Kouremenos <kourem@gmail.com>
|
|
|
|
##
|
|
|
|
## 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-05-21 15:19:42 +02:00
|
|
|
from common import i18n
|
|
|
|
_ = i18n._
|
2005-07-02 14:36:21 +02:00
|
|
|
import sre
|
2005-05-21 15:19:42 +02:00
|
|
|
|
2005-05-20 18:31:52 +02:00
|
|
|
def get_uf_show(show):
|
2005-05-20 17:58:23 +02:00
|
|
|
'''returns a userfriendly string for dnd/xa/chat
|
2005-05-26 21:56:04 +02:00
|
|
|
and makes the rest translatable'''
|
2005-05-20 18:31:52 +02:00
|
|
|
if show == 'dnd':
|
2005-05-21 15:19:42 +02:00
|
|
|
uf_show = _('Busy')
|
2005-05-20 18:31:52 +02:00
|
|
|
elif show == 'xa':
|
2005-05-21 15:19:42 +02:00
|
|
|
uf_show = _('Not Available')
|
2005-05-20 18:31:52 +02:00
|
|
|
elif show == 'chat':
|
2005-05-21 15:19:42 +02:00
|
|
|
uf_show = _('Free for Chat')
|
|
|
|
elif show == 'online':
|
2005-05-26 21:56:04 +02:00
|
|
|
uf_show = _('Available')
|
2005-05-21 15:19:42 +02:00
|
|
|
elif show == 'connecting':
|
|
|
|
uf_show = _('Connecting')
|
|
|
|
elif show == 'away':
|
|
|
|
uf_show = _('Away')
|
2005-05-21 15:44:50 +02:00
|
|
|
elif show == 'offline':
|
|
|
|
uf_show = _('Offline')
|
|
|
|
elif show == 'invisible':
|
|
|
|
uf_show = _('Invisible')
|
2005-05-22 01:37:11 +02:00
|
|
|
elif show == 'not in the roster':
|
2005-05-22 01:34:51 +02:00
|
|
|
uf_show = _('Not in the roster')
|
2005-05-23 18:57:35 +02:00
|
|
|
else:
|
|
|
|
uf_show = _('Has errors')
|
2005-06-01 23:40:33 +02:00
|
|
|
return unicode(uf_show)
|
2005-06-06 13:53:07 +02:00
|
|
|
|
|
|
|
def get_sorted_keys(adict):
|
|
|
|
keys = adict.keys()
|
|
|
|
keys.sort()
|
|
|
|
return keys
|
2005-07-02 14:36:21 +02:00
|
|
|
|
|
|
|
def to_one_line(msg):
|
|
|
|
msg = msg.replace('\\', '\\\\')
|
|
|
|
msg = msg.replace('\n', '\\n')
|
|
|
|
# s1 = 'test\ntest\\ntest'
|
|
|
|
# s11 = s1.replace('\\', '\\\\')
|
|
|
|
# s12 = s11.replace('\n', '\\n')
|
|
|
|
# s12
|
|
|
|
# 'test\\ntest\\\\ntest'
|
|
|
|
return msg
|
|
|
|
|
|
|
|
def from_one_line(msg):
|
|
|
|
# (?<!\\) is a lookbehind assertion which asks anything but '\'
|
|
|
|
# to match the regexp that follows it
|
|
|
|
|
|
|
|
# So here match '\\n' but not if you have a '\' before that
|
|
|
|
re = sre.compile(r'(?<!\\)\\n')
|
|
|
|
msg = re.sub('\n', msg)
|
|
|
|
msg = msg.replace('\\\\', '\\')
|
|
|
|
# s12 = 'test\\ntest\\\\ntest'
|
|
|
|
# s13 = re.sub('\n', s12)
|
|
|
|
# s14 s13.replace('\\\\', '\\')
|
|
|
|
# s14
|
|
|
|
# 'test\ntest\\ntest'
|
|
|
|
return msg
|
2005-07-22 16:30:35 +02:00
|
|
|
|
|
|
|
def get_uf_chatstate(chatstate):
|
|
|
|
'''removes chatstate jargon and returns user friendly messages'''
|
|
|
|
if chatstate == 'active':
|
|
|
|
return _('is paying attention to the conversation')
|
|
|
|
elif chatstate == 'inactive':
|
|
|
|
return _('is doing something else')
|
|
|
|
elif chatstate == 'composing':
|
|
|
|
return _('is composing a message...')
|
|
|
|
elif chatstate == 'paused':
|
|
|
|
return _('paused composing a message...')
|
|
|
|
elif chatstate == 'gone':
|
2005-07-22 16:35:34 +02:00
|
|
|
return _('has closed the chat window or tab')
|