frontend improved to take into account new SàT features

- quick_frontend: better use of contact management, it now manages nicks, avatars, and connected status
- quick_frontend: disconnect and remove are now 2 separate methods for contact list
- wix: new contact list using HTML items, and showing avatars. Groups are not showed for now
- wix: contact status now use tuples, to keep order, human readable status and color of contact
- wix: contact list is updated when avatar or nick is found
- wix: fixed 'question' dialog, which is renamed in 'yes/no'
- wix: action result are now ignored for unkwnown id
- sortilege refactored to work again
This commit is contained in:
Goffi 2010-01-07 00:17:27 +11:00
commit 3b2d29b632

View file

@ -43,6 +43,7 @@ from boxsizer import BoxSizer
from quick_frontend.quick_chat_list import QuickChatList
from quick_frontend.quick_contact_list import QuickContactList
from quick_frontend.quick_app import QuickApp
from quick_frontend.quick_contact_management import QuickContactManagement
### logging configuration FIXME: put this elsewhere ###
logging.basicConfig(level=logging.CRITICAL, #TODO: configure it top put messages in a log file
@ -80,8 +81,10 @@ class ChatList(QuickChatList):
class ContactList(Window, QuickContactList):
def __init__(self):
QuickContactList.__init__(self)
def __init__(self, host, CM):
QuickContactList.__init__(self, CM)
self.host = host
self.jid_list = []
self.__index=0 #indicate which contact is selected (ie: where we are)
Window.__init__(self, stdscr, stdscr.getmaxyx()[0]-2,const_CONTACT_WIDTH,0,0, True, "Contact List", code=code)
@ -98,14 +101,15 @@ class ContactList(Window, QuickContactList):
def registerEnterCB(self, CB):
self.__enterCB=CB
def replace(self, jid, name="", show="", status="", group=""):
def replace(self, jid):
"""add a contact to the list"""
self.jid_ids[jid] = name or jid
name = self.CM.getAttr(jid,'name')
self.jid_list.append(jid.short)
self.update()
def indexUp(self):
"""increment select contact index"""
if self.__index < len(self.jid_ids)-1: #we dont want to select a missing contact
if self.__index < len(self.jid_list)-1: #we dont want to select a missing contact
self.__index = self.__index + 1
self.update()
@ -115,11 +119,15 @@ class ContactList(Window, QuickContactList):
self.__index = self.__index - 1
self.update()
def disconnect(self, jid):
"""for now, we just remove the contact"""
self.remove(jid)
def remove(self, jid):
"""remove a contact from the list"""
del self.jid_ids[jid]
if self.__index >= len(self.jid_ids) and self.__index > 0: #if select index is out of border, we put it on the last contact
self.__index = len(self.jid_ids)-1
self.jid_list.remove(jid.short)
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.update()
def update(self):
@ -127,13 +135,10 @@ class ContactList(Window, QuickContactList):
if self.isHidden():
return
Window.update(self)
viewList=[]
for jid in self.jid_ids:
viewList.append(self.jid_ids[jid])
viewList.sort()
self.jid_list.sort()
begin=0 if self.__index<self.rHeight else self.__index-self.rHeight+1
idx=0
for item in viewList[begin:self.rHeight+begin]:
for item in self.jid_list[begin:self.rHeight+begin]:
attr = curses.A_REVERSE if ( self.isActive() and (idx+begin) == self.__index ) else 0
centered = item.center(self.rWidth) ## it's nicer in the center :)
self.addYXStr(idx, 0, centered, attr)
@ -147,10 +152,10 @@ class ContactList(Window, QuickContactList):
elif k == curses.KEY_DOWN:
self.indexUp()
elif k == ascii.NL:
if not self.jid_ids:
if not self.jid_list:
return
try:
self.__enterCB(self.jid_ids.keys()[self.__index])
self.__enterCB(self.jid_list[self.__index])
except NameError:
pass # TODO: thrown an error here
@ -170,6 +175,7 @@ class SortilegeApp(QuickApp):
gobject.io_add_watch(0, gobject.IO_IN, self.loopCB)
## misc init stuff ##
self.CM = QuickContactManagement()
self.listWins=[]
self.chatParams={'timestamp':True,
'color':True,
@ -190,7 +196,7 @@ class SortilegeApp(QuickApp):
self.color(True)
## windows ##
self.contactList = ContactList()
self.contactList = ContactList(self, self.CM)
self.editBar = EditBox(stdscr, "> ", self.code)
self.editBar.activate(False)
self.statusBar = StatusBar(stdscr, self.code)
@ -237,10 +243,10 @@ class SortilegeApp(QuickApp):
def showChat(self, chat):
debug ("show chat")
if self.currentChat:
debug ("hide de %s", self.currentChat)
debug ("hiding %s", self.currentChat)
self.chat_wins[self.currentChat].hide()
self.currentChat=chat
debug ("show de %s", self.currentChat)
debug ("showing %s", self.currentChat)
self.chat_wins[self.currentChat].show()
self.chat_wins[self.currentChat].update()
@ -268,8 +274,8 @@ class SortilegeApp(QuickApp):
pass
def presenceUpdate(self, jabber_id, type, show, status, priority):
QuickApp.presenceUpdate(self, jabber_id, type, show, status, priority)
def presenceUpdate(self, jabber_id, show, priority, statuses):
QuickApp.presenceUpdate(self, jabber_id, show, priority, statuses)
self.editBar.replace_cur()
curses.doupdate()