tools: renamed tools.jid.JID attribute "short" to "bare"

This commit is contained in:
souliane 2013-10-29 16:26:55 +01:00
commit 36cea6fc91
16 changed files with 94 additions and 94 deletions

View file

@ -82,7 +82,7 @@ class Chat(Window, QuickChat):
header=self.__getHeader(self.content[idx]) header=self.__getHeader(self.content[idx])
msg=self.content[idx][2] msg=self.content[idx][2]
part=0 #part of the text part=0 #part of the text
if JID(self.content[idx][1]).short==self.host.profiles[self.host.profile]['whoami'].short: if JID(self.content[idx][1]).bare==self.host.profiles[self.host.profile]['whoami'].bare:
att_header=curses.color_pair(1) att_header=curses.color_pair(1)
else: else:
att_header=curses.color_pair(2) att_header=curses.color_pair(2)
@ -140,7 +140,7 @@ class Chat(Window, QuickChat):
timestamp=str(current_time) timestamp=str(current_time)
if self.last_history and current_time - float(self.last_history) < 5: #FIXME: Q&D fix to avoid double print on new chat window if self.last_history and current_time - float(self.last_history) < 5: #FIXME: Q&D fix to avoid double print on new chat window
return return
self.content.append([timestamp,jid.short,msg]) self.content.append([timestamp,jid.bare,msg])
self.update() self.update()
def handleKey(self, k): def handleKey(self, k):

View file

@ -110,7 +110,7 @@ class ContactList(Window, QuickContactList):
def replace(self, jid, groups=None): def replace(self, jid, groups=None):
"""add a contact to the list""" """add a contact to the list"""
name = self.CM.getAttr(jid,'name') name = self.CM.getAttr(jid,'name')
self.jid_list.append(jid.short) self.jid_list.append(jid.bare)
self.update() self.update()
def indexUp(self): def indexUp(self):
@ -131,7 +131,7 @@ class ContactList(Window, QuickContactList):
def remove(self, jid): def remove(self, jid):
"""remove a contact from the list""" """remove a contact from the list"""
self.jid_list.remove(jid.short) self.jid_list.remove(jid.bare)
if self.__index >= len(self.jid_list) and self.__index > 0: #if select index is out of border, we put it on the last contact if self.__index >= len(self.jid_list) and self.__index > 0: #if select index is out of border, we put it on the last contact
self.__index = len(self.jid_list)-1 self.__index = len(self.jid_list)-1
self.update() self.update()
@ -264,8 +264,8 @@ class SortilegeApp(QuickApp):
"""Called when a contact is selected in contact list.""" """Called when a contact is selected in contact list."""
jid=JID(jid_txt) jid=JID(jid_txt)
debug (_("contact choosed: %s"), jid) debug (_("contact choosed: %s"), jid)
self.showChat(jid.short) self.showChat(jid.bare)
self.statusBar.remove_item(jid.short) self.statusBar.remove_item(jid.bare)
if len(self.statusBar)==0: if len(self.statusBar)==0:
self.statusBar.hide() self.statusBar.hide()
self.sizer.update() self.sizer.update()
@ -298,14 +298,14 @@ class SortilegeApp(QuickApp):
QuickApp.newMessage(self, from_jid, msg, type, to_jid, profile) QuickApp.newMessage(self, from_jid, msg, type, to_jid, profile)
sender=JID(from_jid) sender=JID(from_jid)
addr=JID(to_jid) addr=JID(to_jid)
win = addr if sender.short == self.whoami.short else sender #FIXME: duplicate code with QuickApp win = addr if sender.bare == self.whoami.bare else sender #FIXME: duplicate code with QuickApp
if (self.currentChat==None): if (self.currentChat==None):
self.currentChat=win.short self.currentChat=win.bare
self.showChat(win.short) self.showChat(win.bare)
# we show the window in the status bar # we show the window in the status bar
if not self.currentChat == win.short: if not self.currentChat == win.bare:
self.statusBar.add_item(win.short) self.statusBar.add_item(win.bare)
self.statusBar.show() self.statusBar.show()
self.sizer.update() self.sizer.update()
self.statusBar.update() self.statusBar.update()

View file

@ -321,7 +321,7 @@ class JP(object):
#if the resource is not given, we try to add the last known resource #if the resource is not given, we try to add the last known resource
last_resource = self.bridge.getLastResource(param_jid, self.options.profile) last_resource = self.bridge.getLastResource(param_jid, self.options.profile)
if last_resource: if last_resource:
return "%s/%s" % (_jid.short, last_resource) return "%s/%s" % (_jid.bare, last_resource)
return param_jid return param_jid
@ -334,7 +334,7 @@ class JP(object):
if confirm_type == "FILE_TRANSFER": if confirm_type == "FILE_TRANSFER":
if not self.options.wait_file: if not self.options.wait_file:
return return
if self.dest_jids and not JID(data['from']).short in [JID(_jid).short for _jid in self.dest_jids]: if self.dest_jids and not JID(data['from']).bare in [JID(_jid).bare for _jid in self.dest_jids]:
return #file is not sent by a filtered jid return #file is not sent by a filtered jid
answer_data["dest_path"] = os.getcwd()+'/'+data['filename'] answer_data["dest_path"] = os.getcwd()+'/'+data['filename']
@ -354,7 +354,7 @@ class JP(object):
elif confirm_type == "PIPE_TRANSFER": elif confirm_type == "PIPE_TRANSFER":
if not self.options.pipe_in: if not self.options.pipe_in:
return return
if self.dest_jids and not JID(data['from']).short in [JID(_jid).short for _jid in self.dest_jids]: if self.dest_jids and not JID(data['from']).bare in [JID(_jid).bare for _jid in self.dest_jids]:
return #pipe stream is not sent by a filtered jid return #pipe stream is not sent by a filtered jid
tmp_dir = tempfile.mkdtemp() tmp_dir = tempfile.mkdtemp()

View file

@ -190,7 +190,7 @@ class Chat(urwid.WidgetWrap, QuickChat):
#We ignore click on our own nick #We ignore click on our own nick
return return
#we have a click on a nick, we add the private conversation to the contact_list #we have a click on a nick, we add the private conversation to the contact_list
full_jid = JID("%s/%s" % (self.target.short, nick)) full_jid = JID("%s/%s" % (self.target.bare, nick))
new_jid = escapePrivate(full_jid) new_jid = escapePrivate(full_jid)
if new_jid not in self.host.contact_list: if new_jid not in self.host.contact_list:
self.host.contact_list.add(new_jid) self.host.contact_list.add(new_jid)
@ -340,9 +340,9 @@ class Chat(urwid.WidgetWrap, QuickChat):
def onFileSelected(self, filepath): def onFileSelected(self, filepath):
self.host.removePopUp() self.host.removePopUp()
#FIXME: check last_resource: what if self.target.resource exists ? #FIXME: check last_resource: what if self.target.resource exists ?
last_resource = self.host.bridge.getLastResource(unicode(self.target.short), self.host.profile) last_resource = self.host.bridge.getLastResource(unicode(self.target.bare), self.host.profile)
if last_resource: if last_resource:
full_jid = JID("%s/%s" % (self.target.short, last_resource)) full_jid = JID("%s/%s" % (self.target.bare, last_resource))
else: else:
full_jid = self.target full_jid = self.target
progress_id = self.host.bridge.sendFile(full_jid, filepath, {}, self.host.profile) progress_id = self.host.bridge.sendFile(full_jid, filepath, {}, self.host.profile)

View file

@ -70,7 +70,7 @@ class ContactList(urwid.WidgetWrap, QuickContactList):
def __contains__(self, jid): def __contains__(self, jid):
for group in self.groups: for group in self.groups:
if jid.short in self.groups[group][1]: if jid.bare in self.groups[group][1]:
return True return True
return False return False
@ -108,7 +108,7 @@ class ContactList(urwid.WidgetWrap, QuickContactList):
def putAlert(self, jid): def putAlert(self, jid):
"""Put an alert on the jid to get attention from user (e.g. for new message)""" """Put an alert on the jid to get attention from user (e.g. for new message)"""
self.alert_jid.add(jid.short) self.alert_jid.add(jid.bare)
self.update() self.update()
def __groupClicked(self, group_wid): def __groupClicked(self, group_wid):
@ -153,7 +153,7 @@ class ContactList(urwid.WidgetWrap, QuickContactList):
and not contact in self.alert_jid and contact != self.selected): and not contact in self.alert_jid and contact != self.selected):
continue continue
show_icon, show_attr = const_SHOW_ICON.get(show,('','default')) show_icon, show_attr = const_SHOW_ICON.get(show,('','default'))
contact_disp = ('alert' if contact in self.alert_jid else show_attr, nick or name or jid.node or jid.short) contact_disp = ('alert' if contact in self.alert_jid else show_attr, nick or name or jid.node or jid.bare)
display = [ show_icon + " " , contact_disp] display = [ show_icon + " " , contact_disp]
if self.show_status: if self.show_status:
status_disp = ('status',"\n " + status) if status else "" status_disp = ('status',"\n " + status) if status else ""
@ -180,7 +180,7 @@ class ContactList(urwid.WidgetWrap, QuickContactList):
jid=JID(special) jid=JID(special)
name = self.getCache(jid, 'name') name = self.getCache(jid, 'name')
nick = self.getCache(jid, 'nick') nick = self.getCache(jid, 'nick')
special_disp = ('alert' if special in self.alert_jid else 'default', nick or name or jid.node or jid.short) special_disp = ('alert' if special in self.alert_jid else 'default', nick or name or jid.node or jid.bare)
display = [ " " , special_disp] display = [ " " , special_disp]
header = '(*) ' if special in self.alert_jid else '' header = '(*) ' if special in self.alert_jid else ''
widget = sat_widgets.SelectableText(display, widget = sat_widgets.SelectableText(display,
@ -233,7 +233,7 @@ class ContactList(urwid.WidgetWrap, QuickContactList):
def replace(self, jid, groups=None, attributes=None): def replace(self, jid, groups=None, attributes=None):
"""add a contact to the list if doesn't exist, else update it""" """add a contact to the list if doesn't exist, else update it"""
QuickContactList.replace(self, jid, groups, attributes) QuickContactList.replace(self, jid, groups, attributes)
if jid.short in self.specials: if jid.bare in self.specials:
return return
if not groups: if not groups:
groups = [None] groups = [None]
@ -244,7 +244,7 @@ class ContactList(urwid.WidgetWrap, QuickContactList):
for group in groups: for group in groups:
if not self.groups.has_key(group): if not self.groups.has_key(group):
self.groups[group] = [True,set()] #[unfold,list_of_contacts] self.groups[group] = [True,set()] #[unfold,list_of_contacts]
self.groups[group][1].add(jid.short) self.groups[group][1].add(jid.bare)
self.update() self.update()
def remove(self, jid): def remove(self, jid):
@ -253,8 +253,8 @@ class ContactList(urwid.WidgetWrap, QuickContactList):
groups_to_remove = [] groups_to_remove = []
for group in self.groups: for group in self.groups:
contacts = self.groups[group][1] contacts = self.groups[group][1]
if jid.short in contacts: if jid.bare in contacts:
contacts.remove(jid.short) contacts.remove(jid.bare)
if not len(contacts): if not len(contacts):
groups_to_remove.append(group) groups_to_remove.append(group)
for group in groups_to_remove: for group in groups_to_remove:
@ -275,7 +275,7 @@ class ContactList(urwid.WidgetWrap, QuickContactList):
if None in self.groups: if None in self.groups:
folded, group_jids = self.groups[None] folded, group_jids = self.groups[None]
for group_jid in group_jids: for group_jid in group_jids:
if JID(group_jid).short == special_jid.short: if JID(group_jid).bare == special_jid.bare:
group_jids.remove(group_jid) group_jids.remove(group_jid)
break break
self.update() self.update()
@ -286,5 +286,5 @@ class ContactList(urwid.WidgetWrap, QuickContactList):
def updatePresence(self, jid, show, priority, statuses): def updatePresence(self, jid, show, priority, statuses):
#XXX: for the moment, we ignore presence updates for special entities #XXX: for the moment, we ignore presence updates for special entities
if jid.short not in self.specials: if jid.bare not in self.specials:
QuickContactList.updatePresence(self, jid, show, priority, statuses) QuickContactList.updatePresence(self, jid, show, priority, statuses)

View file

@ -374,13 +374,13 @@ class PrimitivusApp(QuickApp, InputHistory):
def newMessage(self, from_jid, to_jid, msg, _type, extra, profile): def newMessage(self, from_jid, to_jid, msg, _type, extra, profile):
QuickApp.newMessage(self, from_jid, to_jid, msg, _type, extra, profile) QuickApp.newMessage(self, from_jid, to_jid, msg, _type, extra, profile)
if not from_jid in self.contact_list and from_jid.short != self.profiles[profile]['whoami'].short: if not from_jid in self.contact_list and from_jid.bare != self.profiles[profile]['whoami'].bare:
#XXX: needed to show entities which haven't sent any #XXX: needed to show entities which haven't sent any
# presence information and which are not in roster # presence information and which are not in roster
#TODO: put these entities in a "not in roster" list #TODO: put these entities in a "not in roster" list
self.contact_list.replace(from_jid) self.contact_list.replace(from_jid)
if JID(self.contact_list.selected).short != from_jid.short: if JID(self.contact_list.selected).bare != from_jid.bare:
self.contact_list.putAlert(from_jid) self.contact_list.putAlert(from_jid)
def _dialogOkCb(self, widget, data): def _dialogOkCb(self, widget, data):
@ -518,7 +518,7 @@ class PrimitivusApp(QuickApp, InputHistory):
self.removePopUp() self.removePopUp()
jid=JID(edit.get_edit_text()) jid=JID(edit.get_edit_text())
if jid.is_valid(): if jid.is_valid():
self.bridge.addContact(jid.short, profile_key=self.profile) self.bridge.addContact(jid.bare, profile_key=self.profile)
else: else:
message = _("'%s' is an invalid JID !") % jid message = _("'%s' is an invalid JID !") % jid
error (message) error (message)
@ -623,7 +623,7 @@ class PrimitivusApp(QuickApp, InputHistory):
self.chat_wins[win].updateChatState(state) self.chat_wins[win].updateChatState(state)
return return
from_bare = JID(from_jid_s).short from_bare = JID(from_jid_s).bare
if from_bare in self.chat_wins: if from_bare in self.chat_wins:
self.chat_wins[from_bare].updateChatState(state) self.chat_wins[from_bare].updateChatState(state)

View file

@ -254,7 +254,7 @@ class QuickApp(object):
from_jid = JID(from_jid_s) from_jid = JID(from_jid_s)
to_jid = JID(to_jid_s) to_jid = JID(to_jid_s)
from_me = from_jid.short == self.profiles[profile]['whoami'].short from_me = from_jid.bare == self.profiles[profile]['whoami'].bare
win = to_jid if from_me else from_jid win = to_jid if from_me else from_jid
if _type != "groupchat" and self.contact_list.getSpecial(win) == "MUC": if _type != "groupchat" and self.contact_list.getSpecial(win) == "MUC":
@ -273,14 +273,14 @@ class QuickApp(object):
self.newMessage(from_jid, to_jid, msg, _type, extra, profile) self.newMessage(from_jid, to_jid, msg, _type, extra, profile)
def newMessage(self, from_jid, to_jid, msg, _type, extra, profile): def newMessage(self, from_jid, to_jid, msg, _type, extra, profile):
from_me = from_jid.short == self.profiles[profile]['whoami'].short from_me = from_jid.bare == self.profiles[profile]['whoami'].bare
win = to_jid if from_me else from_jid win = to_jid if from_me else from_jid
self.current_action_ids = set() self.current_action_ids = set()
self.current_action_ids_cb = {} self.current_action_ids_cb = {}
timestamp = extra.get('archive') timestamp = extra.get('archive')
self.chat_wins[win.short].printMessage(from_jid, msg, profile, float(timestamp) if timestamp else '') self.chat_wins[win.bare].printMessage(from_jid, msg, profile, float(timestamp) if timestamp else '')
def sendMessage(self, to_jid, message, subject='', mess_type="auto", options={}, profile_key="@NONE@"): def sendMessage(self, to_jid, message, subject='', mess_type="auto", options={}, profile_key="@NONE@"):
if to_jid.startswith(const_PRIVATE_PREFIX): if to_jid.startswith(const_PRIVATE_PREFIX):
@ -303,9 +303,9 @@ class QuickApp(object):
return return
debug (_("presence update for %(jid)s (show=%(show)s, priority=%(priority)s, statuses=%(statuses)s) [profile:%(profile)s]") % {'jid':jabber_id, 'show':show, 'priority':priority, 'statuses':statuses, 'profile':profile}) debug (_("presence update for %(jid)s (show=%(show)s, priority=%(priority)s, statuses=%(statuses)s) [profile:%(profile)s]") % {'jid':jabber_id, 'show':show, 'priority':priority, 'statuses':statuses, 'profile':profile})
from_jid=JID(jabber_id) from_jid=JID(jabber_id)
debug ("from_jid.short=%(from_jid)s whoami.short=%(whoami)s" % {'from_jid':from_jid.short, 'whoami':self.profiles[profile]['whoami'].short}) debug ("from_jid.bare=%(from_jid)s whoami.bare=%(whoami)s" % {'from_jid':from_jid.bare, 'whoami':self.profiles[profile]['whoami'].bare})
if from_jid.short==self.profiles[profile]['whoami'].short: if from_jid.bare==self.profiles[profile]['whoami'].bare:
if not type: if not type:
self.setStatusOnline(True) self.setStatusOnline(True)
elif type=="unavailable": elif type=="unavailable":
@ -317,8 +317,8 @@ class QuickApp(object):
if show != 'unavailable': if show != 'unavailable':
#FIXME: must be moved in a plugin #FIXME: must be moved in a plugin
if from_jid.short in self.profiles[profile]['watched'] and not from_jid.short in self.profiles[profile]['onlineContact']: if from_jid.bare in self.profiles[profile]['watched'] and not from_jid.bare in self.profiles[profile]['onlineContact']:
self.showAlert(_("Watched jid [%s] is connected !") % from_jid.short) self.showAlert(_("Watched jid [%s] is connected !") % from_jid.bare)
self.profiles[profile]['onlineContact'].add(from_jid) #FIXME onlineContact is useless with CM, must be removed self.profiles[profile]['onlineContact'].add(from_jid) #FIXME onlineContact is useless with CM, must be removed
@ -498,9 +498,9 @@ class QuickApp(object):
def _subscribe_cb(self, answer, data): def _subscribe_cb(self, answer, data):
entity, profile = data entity, profile = data
if answer: if answer:
self.bridge.subscription("subscribed", entity.short, profile_key = profile) self.bridge.subscription("subscribed", entity.bare, profile_key = profile)
else: else:
self.bridge.subscription("unsubscribed", entity.short, profile_key = profile) self.bridge.subscription("unsubscribed", entity.bare, profile_key = profile)
def subscribe(self, type, raw_jid, profile): def subscribe(self, type, raw_jid, profile):
"""Called when a subsciption management signal is received""" """Called when a subsciption management signal is received"""
@ -509,13 +509,13 @@ class QuickApp(object):
entity = JID(raw_jid) entity = JID(raw_jid)
if type=="subscribed": if type=="subscribed":
# this is a subscription confirmation, we just have to inform user # this is a subscription confirmation, we just have to inform user
self.showDialog(_("The contact %s has accepted your subscription") % entity.short, _('Subscription confirmation')) self.showDialog(_("The contact %s has accepted your subscription") % entity.bare, _('Subscription confirmation'))
elif type=="unsubscribed": elif type=="unsubscribed":
# this is a subscription refusal, we just have to inform user # this is a subscription refusal, we just have to inform user
self.showDialog(_("The contact %s has refused your subscription") % entity.short, _('Subscription refusal'), 'error') self.showDialog(_("The contact %s has refused your subscription") % entity.bare, _('Subscription refusal'), 'error')
elif type=="subscribe": elif type=="subscribe":
# this is a subscriptionn request, we have to ask for user confirmation # this is a subscriptionn request, we have to ask for user confirmation
answer = self.showDialog(_("The contact %s wants to subscribe to your presence.\nDo you accept ?") % entity.short, _('Subscription confirmation'), 'yes/no', answer_cb = self._subscribe_cb, answer_data=(entity, profile)) answer = self.showDialog(_("The contact %s wants to subscribe to your presence.\nDo you accept ?") % entity.bare, _('Subscription confirmation'), 'yes/no', answer_cb = self._subscribe_cb, answer_data=(entity, profile))
def showDialog(self, message, title, type="info", answer_cb = None): def showDialog(self, message, title, type="info", answer_cb = None):
raise NotImplementedError raise NotImplementedError
@ -539,7 +539,7 @@ class QuickApp(object):
target = JID(jid) target = JID(jid)
self.contact_list.remove(target) self.contact_list.remove(target)
try: try:
self.profiles[profile]['onlineContact'].remove(target.short) self.profiles[profile]['onlineContact'].remove(target.bare)
except KeyError: except KeyError:
pass pass

View file

@ -110,15 +110,15 @@ class QuickChat(object):
if self.target.startswith(const_PRIVATE_PREFIX): if self.target.startswith(const_PRIVATE_PREFIX):
target = unescapePrivate(self.target) target = unescapePrivate(self.target)
else: else:
target = self.target.short target = self.target.bare
self.host.bridge.getHistory(self.host.profiles[profile]['whoami'].short, target, 20, profile=profile, callback=onHistory, errback=onHistoryError) self.host.bridge.getHistory(self.host.profiles[profile]['whoami'].bare, target, 20, profile=profile, callback=onHistory, errback=onHistoryError)
def _get_nick(self, jid): def _get_nick(self, jid):
"""Return nick of this jid when possible""" """Return nick of this jid when possible"""
if self.target.startswith(const_PRIVATE_PREFIX): if self.target.startswith(const_PRIVATE_PREFIX):
unescaped = unescapePrivate(self.target) unescaped = unescapePrivate(self.target)
if jid.startswith(const_PRIVATE_PREFIX) or unescaped.short == jid.short: if jid.startswith(const_PRIVATE_PREFIX) or unescaped.bare == jid.bare:
return unescaped.resource return unescaped.resource
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) 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)
@ -126,7 +126,7 @@ class QuickChat(object):
"""Print message in chat window. Must be implemented by child class""" """Print message in chat window. Must be implemented by child class"""
jid=JID(from_jid) jid=JID(from_jid)
nick = self._get_nick(jid) nick = self._get_nick(jid)
mymess = (jid.resource == self.nick) if self.type == "group" else (jid.short == self.host.profiles[profile]['whoami'].short) #mymess = True if message comes from local user mymess = (jid.resource == self.nick) if self.type == "group" else (jid.bare == self.host.profiles[profile]['whoami'].bare) #mymess = True if message comes from local user
if msg.startswith('/me '): if msg.startswith('/me '):
self.printInfo('* %s %s' % (nick, msg[4:]),type='me', timestamp=timestamp) self.printInfo('* %s %s' % (nick, msg[4:]),type='me', timestamp=timestamp)
return return

View file

@ -30,10 +30,10 @@ class QuickChatList(dict):
def __getitem__(self, to_jid): def __getitem__(self, to_jid):
target = JID(to_jid) target = JID(to_jid)
if not target.short in self: if not target.bare in self:
#we have to create the chat win #we have to create the chat win
self[target.short] = self.createChat(target) self[target.bare] = self.createChat(target)
return dict.__getitem__(self, target.short) return dict.__getitem__(self, target.bare)
def createChat(self, target): def createChat(self, target):
raise NotImplementedError raise NotImplementedError

View file

@ -34,7 +34,7 @@ class QuickContactList(object):
def getCache(self, jid, name): def getCache(self, jid, name):
try: try:
jid_cache = self._cache[jid.short] jid_cache = self._cache[jid.bare]
if name == 'status': #XXX: we get the first status for 'status' key if name == 'status': #XXX: we get the first status for 'status' key
return jid_cache['statuses'].get('default','') return jid_cache['statuses'].get('default','')
return jid_cache[name] return jid_cache[name]
@ -42,7 +42,7 @@ class QuickContactList(object):
return None return None
def setCache(self, jid, name, value): def setCache(self, jid, name, value):
jid_cache = self._cache.setdefault(jid.short, {}) jid_cache = self._cache.setdefault(jid.bare, {})
jid_cache[name] = value jid_cache[name] = value
def __contains__(self, jid): def __contains__(self, jid):
@ -60,7 +60,7 @@ class QuickContactList(object):
def remove(self, jid): def remove(self, jid):
"""remove a contact from the list""" """remove a contact from the list"""
try: try:
del self.specials[jid.short] del self.specials[jid.bare]
except KeyError: except KeyError:
pass pass
@ -70,7 +70,7 @@ class QuickContactList(object):
def getSpecial(self, jid): def getSpecial(self, jid):
"""Return special type of jid, or None if it's not special""" """Return special type of jid, or None if it's not special"""
return self.specials.get(jid.short) return self.specials.get(jid.bare)
def setSpecial(self, jid, _type, show=False): def setSpecial(self, jid, _type, show=False):
"""Set entity as a special """Set entity as a special
@ -78,7 +78,7 @@ class QuickContactList(object):
@param _type: special type (e.g.: "MUC") @param _type: special type (e.g.: "MUC")
@param show: True to display the dialog to chat with this entity @param show: True to display the dialog to chat with this entity
""" """
self.specials[jid.short] = _type self.specials[jid.bare] = _type
def updatePresence(self, jid, show, priority, statuses): def updatePresence(self, jid, show, priority, statuses):
"""Update entity's presence status """Update entity's presence status

View file

@ -30,7 +30,7 @@ class QuickContactManagement(object):
self.__contactlist = {} self.__contactlist = {}
def __contains__(self, entity): def __contains__(self, entity):
return entity.short in self.__contactlist return entity.bare in self.__contactlist
def clear(self): def clear(self):
"""Clear all the contact list""" """Clear all the contact list"""
@ -38,13 +38,13 @@ class QuickContactManagement(object):
def add(self, entity): def add(self, entity):
"""Add contact to the list, update resources""" """Add contact to the list, update resources"""
if not self.__contactlist.has_key(entity.short): if not self.__contactlist.has_key(entity.bare):
self.__contactlist[entity.short] = {'resources':[]} self.__contactlist[entity.bare] = {'resources':[]}
if not entity.resource: if not entity.resource:
return return
if entity.resource in self.__contactlist[entity.short]['resources']: if entity.resource in self.__contactlist[entity.bare]['resources']:
self.__contactlist[entity.short]['resources'].remove(entity.resource) self.__contactlist[entity.bare]['resources'].remove(entity.resource)
self.__contactlist[entity.short]['resources'].append(entity.resource) self.__contactlist[entity.bare]['resources'].append(entity.resource)
def getContFromGroup(self, group): def getContFromGroup(self, group):
"""Return all contacts which are in given group""" """Return all contacts which are in given group"""
@ -60,28 +60,28 @@ class QuickContactManagement(object):
@param entity: jid of the contact @param entity: jid of the contact
@param name: name of the attribute @param name: name of the attribute
@return: asked attribute""" @return: asked attribute"""
if self.__contactlist.has_key(entity.short): if self.__contactlist.has_key(entity.bare):
if name == 'status': #FIXME: for the moment, we only use the first status if name == 'status': #FIXME: for the moment, we only use the first status
if self.__contactlist[entity.short]['statuses']: if self.__contactlist[entity.bare]['statuses']:
return self.__contactlist[entity.short]['statuses'].values()[0] return self.__contactlist[entity.bare]['statuses'].values()[0]
if self.__contactlist[entity.short].has_key(name): if self.__contactlist[entity.bare].has_key(name):
return self.__contactlist[entity.short][name] return self.__contactlist[entity.bare][name]
else: else:
debug(_('Trying to get attribute for an unknown contact')) debug(_('Trying to get attribute for an unknown contact'))
return None return None
def isConnected(self, entity): def isConnected(self, entity):
"""Tell if the contact is online""" """Tell if the contact is online"""
return self.__contactlist.has_key(entity.short) return self.__contactlist.has_key(entity.bare)
def remove(self, entity): def remove(self, entity):
"""remove resource. If no more resource is online or is no resource is specified, contact is deleted""" """remove resource. If no more resource is online or is no resource is specified, contact is deleted"""
try: try:
if entity.resource: if entity.resource:
self.__contactlist[entity.short]['resources'].remove(entity.resource) self.__contactlist[entity.bare]['resources'].remove(entity.resource)
if not entity.resource or not self.__contactlist[entity.short]['resources']: if not entity.resource or not self.__contactlist[entity.bare]['resources']:
#no more resource available: the contact seems really disconnected #no more resource available: the contact seems really disconnected
del self.__contactlist[entity.short] del self.__contactlist[entity.bare]
except KeyError: except KeyError:
error(_('INTERNAL ERROR: Key error')) error(_('INTERNAL ERROR: Key error'))
raise raise
@ -92,11 +92,11 @@ class QuickContactManagement(object):
@param key: name of the attribute @param key: name of the attribute
@param value: value of the attribute @param value: value of the attribute
""" """
if self.__contactlist.has_key(entity.short): if self.__contactlist.has_key(entity.bare):
self.__contactlist[entity.short][key] = value self.__contactlist[entity.bare][key] = value
else: else:
debug (_('Trying to update an unknown contact: %s'), entity.short) debug (_('Trying to update an unknown contact: %s'), entity.bare)
def get_full(self, entity): def get_full(self, entity):
return entity.short+'/'+self.__contactlist[entity.short]['resources'][-1] return entity.bare+'/'+self.__contactlist[entity.bare]['resources'][-1]

View file

@ -22,7 +22,7 @@ from os.path import exists, splitext
def escapePrivate(ori_jid): def escapePrivate(ori_jid):
"""Escape a private jid""" """Escape a private jid"""
return JID(const_PRIVATE_PREFIX + ori_jid.short + '@' + ori_jid.resource) return JID(const_PRIVATE_PREFIX + ori_jid.bare + '@' + ori_jid.resource)
def unescapePrivate(escaped_jid): def unescapePrivate(escaped_jid):
if not escaped_jid.startswith(const_PRIVATE_PREFIX): if not escaped_jid.startswith(const_PRIVATE_PREFIX):

View file

@ -199,7 +199,7 @@ class Chat(wx.Frame, QuickChat):
def onEnterPressed(self, event): def onEnterPressed(self, event):
"""Behaviour when enter pressed in send line.""" """Behaviour when enter pressed in send line."""
self.host.sendMessage(self.target.short if self.type == 'group' else self.target, self.host.sendMessage(self.target.bare if self.type == 'group' else self.target,
event.GetString(), event.GetString(),
mess_type="groupchat" if self.type == 'group' else "chat", mess_type="groupchat" if self.type == 'group' else "chat",
profile_key=self.host.profile) profile_key=self.host.profile)
@ -257,9 +257,9 @@ class Chat(wx.Frame, QuickChat):
if filename: if filename:
debug(_("filename: %s"),filename) debug(_("filename: %s"),filename)
#FIXME: check last_resource: what if self.target.resource exists ? #FIXME: check last_resource: what if self.target.resource exists ?
last_resource = self.host.bridge.getLastResource(unicode(self.target.short), self.host.profile) last_resource = self.host.bridge.getLastResource(unicode(self.target.bare), self.host.profile)
if last_resource: if last_resource:
full_jid = JID("%s/%s" % (self.target.short, last_resource)) full_jid = JID("%s/%s" % (self.target.bare, last_resource))
else: else:
full_jid = self.target full_jid = self.target
id = self.host.bridge.sendFile(full_jid, filename, {}, self.host.profile) id = self.host.bridge.sendFile(full_jid, filename, {}, self.host.profile)

View file

@ -65,7 +65,7 @@ class ContactList(wx.SimpleHtmlListBox, QuickContactList):
@return: list of indexes""" @return: list of indexes"""
result=[] result=[]
for i in range(self.GetCount()): for i in range(self.GetCount()):
if (type(entity) == JID and type(self.GetClientData(i)) == JID and self.GetClientData(i).short == entity.short) or\ if (type(entity) == JID and type(self.GetClientData(i)) == JID and self.GetClientData(i).bare == entity.bare) or\
self.GetClientData(i) == entity: self.GetClientData(i) == entity:
result.append(i) result.append(i)
return result return result
@ -136,7 +136,7 @@ class ContactList(wx.SimpleHtmlListBox, QuickContactList):
</td> </td>
</table> </table>
""" % (avatar, """ % (avatar,
escape(nick or name or jid.node or jid.short), escape(nick or name or jid.node or jid.bare),
show_html, show_html,
escape(status)) escape(status))

View file

@ -339,10 +339,10 @@ class MainWindow(wx.Frame, QuickApp):
def onContactActivated(self, jid): def onContactActivated(self, jid):
debug (_("onContactActivated: %s"), jid) debug (_("onContactActivated: %s"), jid)
if self.chat_wins[jid.short].IsShown(): if self.chat_wins[jid.bare].IsShown():
self.chat_wins[jid.short].Hide() self.chat_wins[jid.bare].Hide()
else: else:
self.chat_wins[jid.short].Show() self.chat_wins[jid.bare].Show()
def onConnectRequest(self, e): def onConnectRequest(self, e):
self.bridge.connect(self.profile) self.bridge.connect(self.profile)
@ -394,7 +394,7 @@ class MainWindow(wx.Frame, QuickApp):
if dlg.ShowModal() == wx.ID_OK: if dlg.ShowModal() == wx.ID_OK:
jid=JID(dlg.GetValue()) jid=JID(dlg.GetValue())
if jid.is_valid(): if jid.is_valid():
self.bridge.addContact(jid.short, profile_key=self.profile) self.bridge.addContact(jid.bare, profile_key=self.profile)
else: else:
error (_("'%s' is an invalid JID !"), jid) error (_("'%s' is an invalid JID !"), jid)
#TODO: notice the user #TODO: notice the user
@ -413,14 +413,14 @@ class MainWindow(wx.Frame, QuickApp):
dlg.Destroy() dlg.Destroy()
return return
dlg = wx.MessageDialog(self, _("Are you sure you want to delete %s from your roster list ?") % target.short, dlg = wx.MessageDialog(self, _("Are you sure you want to delete %s from your roster list ?") % target.bare,
_('Contact suppression'), _('Contact suppression'),
wx.YES_NO | wx.ICON_QUESTION wx.YES_NO | wx.ICON_QUESTION
) )
if dlg.ShowModal() == wx.ID_YES: if dlg.ShowModal() == wx.ID_YES:
info(_("Unsubscribing %s presence"), target.short) info(_("Unsubscribing %s presence"), target.bare)
self.bridge.delContact(target.short, profile_key=self.profile) self.bridge.delContact(target.bare, profile_key=self.profile)
dlg.Destroy() dlg.Destroy()
@ -435,7 +435,7 @@ class MainWindow(wx.Frame, QuickApp):
dlg.ShowModal() dlg.ShowModal()
dlg.Destroy() dlg.Destroy()
return return
_id = self.bridge.getCard(target.short, profile_key=self.profile) _id = self.bridge.getCard(target.bare, profile_key=self.profile)
self.current_action_ids.add(_id) self.current_action_ids.add(_id)
self.current_action_ids_cb[_id] = self.onProfileReceived self.current_action_ids_cb[_id] = self.onProfileReceived

View file

@ -27,7 +27,7 @@ class JID(unicode):
return self return self
def __parse(self): def __parse(self):
"""find node domaine and resource""" """find node domain and resource"""
node_end = self.find('@') node_end = self.find('@')
if node_end < 0: if node_end < 0:
node_end = 0 node_end = 0
@ -38,11 +38,11 @@ class JID(unicode):
self.domain = self[(node_end + 1) if node_end else 0:domain_end] self.domain = self[(node_end + 1) if node_end else 0:domain_end]
self.resource = self[domain_end + 1:] self.resource = self[domain_end + 1:]
if not node_end: if not node_end:
self.short = self self.bare = self
else: else:
self.short = self.node + '@' + self.domain self.bare = self.node + '@' + self.domain
def is_valid(self): def is_valid(self):
"""return True if the jid is xmpp compliant""" """return True if the jid is xmpp compliant"""
#FIXME: always return True for the moment #TODO: implement real check, according to RFCs
return True return self.domain != ""