core, quick_frontend, primitivus, wix: Contacts List refactoring phase 1:
- QuickContactManagement is not used anymore and will be removed, ContactList + Core are used instead - disconnected contacts are now displayed in Primitivus (M-d to show/hide them) - avatars are temporary unavailable in wix - new bridge method: getContactsFromGroup
This commit is contained in:
parent
97420f39d5
commit
b44412ec0d
3 changed files with 207 additions and 130 deletions
|
|
@ -258,7 +258,12 @@ class Chat(wx.Frame, QuickChat):
|
|||
filename = wx.FileSelector(_("Choose a file to send"), flags = wx.FD_FILE_MUST_EXIST)
|
||||
if filename:
|
||||
debug(_("filename: %s"),filename)
|
||||
full_jid = self.host.CM.get_full(self.target)
|
||||
#FIXME: check last_resource: what if self.target.resource exists ?
|
||||
last_resource = self.host.bridge.getLastResource(unicode(self.target.short), self.host.profile)
|
||||
if last_resource:
|
||||
full_jid = JID("%s/%s" % (self.target.short, last_resource))
|
||||
else:
|
||||
full_jid = self.target
|
||||
id = self.host.bridge.sendFile(full_jid, filename, {}, self.host.profile)
|
||||
self.host.waitProgress(id, _("File Transfer"), _("Copying %s") % os.path.basename(filename))
|
||||
|
||||
|
|
|
|||
|
|
@ -44,7 +44,7 @@ class ContactList(wx.SimpleHtmlListBox, QuickContactList):
|
|||
"CUSTOM" for a customized contact list (self.__presentItem must then be overrided)
|
||||
"""
|
||||
wx.SimpleHtmlListBox.__init__(self, parent, -1)
|
||||
QuickContactList.__init__(self, host.CM)
|
||||
QuickContactList.__init__(self)
|
||||
self.host = host
|
||||
self.type = type
|
||||
self.__typeSwitch()
|
||||
|
|
@ -72,17 +72,19 @@ class ContactList(wx.SimpleHtmlListBox, QuickContactList):
|
|||
result.append(i)
|
||||
return result
|
||||
|
||||
def replace(self, contact, groups=None):
|
||||
def update_jid(self, jid):
|
||||
self.replace(jid)
|
||||
|
||||
def replace(self, contact, groups=None, attributes=None):
|
||||
debug(_("update %s") % contact)
|
||||
if not self.__find_idx(contact):
|
||||
self.add(contact, groups)
|
||||
else:
|
||||
for i in self.__find_idx(contact):
|
||||
self.SetString(i, self.__presentItem(contact))
|
||||
_present = self.__presentItem(contact)
|
||||
if _present != None:
|
||||
self.SetString(i, _present)
|
||||
|
||||
def disconnect(self, contact):
|
||||
self.remove(contact) #for now, we only show online contacts
|
||||
|
||||
def __eraseGroup(self, group):
|
||||
"""Erase all contacts in group
|
||||
@param group: group to erase
|
||||
|
|
@ -108,15 +110,19 @@ class ContactList(wx.SimpleHtmlListBox, QuickContactList):
|
|||
|
||||
def __presentItemJID(self, jid):
|
||||
"""Make a nice presentation of the contact in the list for JID contacts."""
|
||||
name = self.CM.getAttr(jid,'name')
|
||||
nick = self.CM.getAttr(jid,'nick')
|
||||
show = filter(lambda x:x[0]==self.CM.getAttr(jid,'show'), const_STATUS)[0]
|
||||
name = self.getCache(jid,'name')
|
||||
nick = self.getCache(jid,'nick')
|
||||
_show = self.getCache(jid,'show')
|
||||
if _show == None or _show == 'unavailable':
|
||||
return None
|
||||
show = filter(lambda x : x[0] == _show, const_STATUS)[0]
|
||||
|
||||
#show[0]==shortcut
|
||||
#show[1]==human readable
|
||||
#show[2]==color (or None)
|
||||
show_html = "<font color='%s'>[%s]</font>" % (show[2], show[1]) if show[2] else ""
|
||||
status = self.CM.getAttr(jid,'status') or ''
|
||||
avatar = self.CM.getAttr(jid,'avatar') or self.empty_avatar #XXX: there is a weird bug here: if the image has an extension (i.e. empty_avatar.png),
|
||||
status = self.getCache(jid,'status') or ''
|
||||
avatar = self.getCache(jid,'avatar') or self.empty_avatar #XXX: there is a weird bug here: if the image has an extension (i.e. empty_avatar.png),
|
||||
#WxPython segfault, and it doesn't without nothing. I couldn't reproduce the case with a basic test script, so it need further investigation before reporting it
|
||||
#to WxPython dev. Anyway, the program crash with a segfault, not a python exception, so there is definitely something wrong with WxPython.
|
||||
#The case seems to happen when SimpleHtmlListBox parse the HTML with the <img> tag
|
||||
|
|
@ -138,7 +144,7 @@ class ContactList(wx.SimpleHtmlListBox, QuickContactList):
|
|||
|
||||
return html
|
||||
|
||||
def clear_contacts(self):
|
||||
def clearContacts(self):
|
||||
"""Clear all the contact list"""
|
||||
self.Clear()
|
||||
|
||||
|
|
@ -146,7 +152,9 @@ class ContactList(wx.SimpleHtmlListBox, QuickContactList):
|
|||
"""add a contact to the list"""
|
||||
debug (_("adding %s"),contact)
|
||||
if not groups:
|
||||
idx = self.Insert(self.__presentItem(contact), 0, contact)
|
||||
_present = self.__presentItem(contact)
|
||||
if _present:
|
||||
idx = self.Insert(_present, 0, contact)
|
||||
else:
|
||||
for group in groups:
|
||||
indexes = self.__find_idx(group)
|
||||
|
|
@ -156,7 +164,9 @@ class ContactList(wx.SimpleHtmlListBox, QuickContactList):
|
|||
else:
|
||||
gp_idx = indexes[0]
|
||||
|
||||
self.Insert(self.__presentItem(contact), gp_idx+1, contact)
|
||||
_present = self.__presentItem(contact)
|
||||
if _present:
|
||||
self.Insert(_present, gp_idx+1, contact)
|
||||
|
||||
|
||||
|
||||
|
|
@ -176,11 +186,13 @@ class ContactList(wx.SimpleHtmlListBox, QuickContactList):
|
|||
group = self.GetClientData(self.GetSelection())
|
||||
erased = self.__eraseGroup(group)
|
||||
if not erased: #the group was already erased, we can add again the contacts
|
||||
contacts = self.CM.getContFromGroup(group)
|
||||
contacts = [JID(contact) for contact in self.host.bridge.getContactsFromGroup(group, self.host.profile)]
|
||||
contacts.sort()
|
||||
id_insert = self.GetSelection()+1
|
||||
for contact in contacts:
|
||||
self.Insert(self.__presentItem(contact), id_insert, contact)
|
||||
_present = self.__presentItem(contact)
|
||||
if _present:
|
||||
self.Insert(_present, id_insert, contact)
|
||||
self.SetSelection(wx.NOT_FOUND)
|
||||
self.ScrollToLine(first_visible)
|
||||
event.Skip(False)
|
||||
|
|
|
|||
|
|
@ -64,17 +64,16 @@ class MainWindow(wx.Frame, QuickApp):
|
|||
def __init__(self):
|
||||
QuickApp.__init__(self)
|
||||
wx.Frame.__init__(self,None, title="SàT Wix", size=(300,500))
|
||||
self.CM = QuickContactManagement() #FIXME: not the best place
|
||||
|
||||
#sizer
|
||||
self.sizer = wx.BoxSizer(wx.VERTICAL)
|
||||
self.SetSizer(self.sizer)
|
||||
|
||||
#Frame elements
|
||||
self.contactList = ContactList(self, self)
|
||||
self.contactList.registerActivatedCB(self.onContactActivated)
|
||||
self.contactList.Hide()
|
||||
self.sizer.Add(self.contactList, 1, flag=wx.EXPAND)
|
||||
self.contact_list = ContactList(self, self)
|
||||
self.contact_list.registerActivatedCB(self.onContactActivated)
|
||||
self.contact_list.Hide()
|
||||
self.sizer.Add(self.contact_list, 1, flag=wx.EXPAND)
|
||||
|
||||
self.chat_wins=ChatList(self)
|
||||
self.CreateStatusBar()
|
||||
|
|
@ -120,7 +119,7 @@ class MainWindow(wx.Frame, QuickApp):
|
|||
"""Hide profile panel then plug profile"""
|
||||
debug (_('plugin profile %s' % profile_key))
|
||||
self.profile_pan.Hide()
|
||||
self.contactList.Show()
|
||||
self.contact_list.Show()
|
||||
self.sizer.Layout()
|
||||
for i in range(self.menuBar.GetMenuCount()):
|
||||
self.menuBar.EnableTop(i, True)
|
||||
|
|
@ -410,7 +409,7 @@ class MainWindow(wx.Frame, QuickApp):
|
|||
|
||||
def onRemoveContact(self, e):
|
||||
debug(_("Remove contact request"))
|
||||
target = self.contactList.getSelection()
|
||||
target = self.contact_list.getSelection()
|
||||
if not target:
|
||||
dlg = wx.MessageDialog(self, _("You haven't selected any contact !"),
|
||||
_('Error'),
|
||||
|
|
@ -433,7 +432,7 @@ class MainWindow(wx.Frame, QuickApp):
|
|||
|
||||
def onShowProfile(self, e):
|
||||
debug(_("Show contact's profile request"))
|
||||
target = self.contactList.getSelection()
|
||||
target = self.contact_list.getSelection()
|
||||
if not target:
|
||||
dlg = wx.MessageDialog(self, _("You haven't selected any contact !"),
|
||||
_('Error'),
|
||||
|
|
|
|||
Loading…
Reference in a new issue