comparison frontends/src/quick_frontend/quick_chat.py @ 736:6246eb6d64a0

frontends: define the constants with classes and inheritance instance of using __builtin__
author souliane <souliane@mailoo.org>
date Sat, 23 Nov 2013 10:21:40 +0100
parents f7878ad3c846
children bfabeedbf32e
comparison
equal deleted inserted replaced
735:682933ca304c 736:6246eb6d64a0
18 # along with this program. If not, see <http://www.gnu.org/licenses/>. 18 # along with this program. If not, see <http://www.gnu.org/licenses/>.
19 19
20 from logging import debug, info, warning, error 20 from logging import debug, info, warning, error
21 from sat.tools.jid import JID 21 from sat.tools.jid import JID
22 from sat_frontends.quick_frontend.quick_utils import unescapePrivate 22 from sat_frontends.quick_frontend.quick_utils import unescapePrivate
23 from sat_frontends.quick_frontend.constants import Const
23 24
24 25
25 class QuickChat(object): 26 class QuickChat(object):
26 27
27 def __init__(self, target, host, type='one2one'): 28 def __init__(self, target, host, type='one2one'):
105 self.printMessage(JID(from_jid), message, profile, timestamp) 106 self.printMessage(JID(from_jid), message, profile, timestamp)
106 107
107 def onHistoryError(err): 108 def onHistoryError(err):
108 error (_("Can't get history")) 109 error (_("Can't get history"))
109 110
110 if self.target.startswith(const_PRIVATE_PREFIX): 111 if self.target.startswith(Const.PRIVATE_PREFIX):
111 target = unescapePrivate(self.target) 112 target = unescapePrivate(self.target)
112 else: 113 else:
113 target = self.target.bare 114 target = self.target.bare
114 115
115 self.host.bridge.getHistory(self.host.profiles[profile]['whoami'].bare, target, 20, profile=profile, callback=onHistory, errback=onHistoryError) 116 self.host.bridge.getHistory(self.host.profiles[profile]['whoami'].bare, target, 20, profile=profile, callback=onHistory, errback=onHistoryError)
116 117
117 def _get_nick(self, jid): 118 def _get_nick(self, jid):
118 """Return nick of this jid when possible""" 119 """Return nick of this jid when possible"""
119 if self.target.startswith(const_PRIVATE_PREFIX): 120 if self.target.startswith(Const.PRIVATE_PREFIX):
120 unescaped = unescapePrivate(self.target) 121 unescaped = unescapePrivate(self.target)
121 if jid.startswith(const_PRIVATE_PREFIX) or unescaped.bare == jid.bare: 122 if jid.startswith(Const.PRIVATE_PREFIX) or unescaped.bare == jid.bare:
122 return unescaped.resource 123 return unescaped.resource
123 return jid.resource if self.type == "group" else (self.host.contact_list.getCache(jid,'nick') or self.host.contact_list.getCache(jid,'name') or jid.node) 124 return jid.resource if self.type == "group" else (self.host.contact_list.getCache(jid,'nick') or self.host.contact_list.getCache(jid,'name') or jid.node)
124 125
125 def printMessage(self, from_jid, msg, profile, timestamp = ''): 126 def printMessage(self, from_jid, msg, profile, timestamp = ''):
126 """Print message in chat window. Must be implemented by child class""" 127 """Print message in chat window. Must be implemented by child class"""