<s> """<STR_LIT>""" <EOL> from twisted . words . im . locals import OFFLINE , ONLINE , AWAY <EOL> class ContactsList : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , chatui ) : <EOL> """<STR_LIT>""" <EOL> self . chatui = chatui <EOL> self . contacts = { } <EOL> self . onlineContacts = { } <EOL> self . clients = [ ] <EOL> def setContactStatus ( self , person ) : <EOL> """<STR_LIT>""" <EOL> if not self . contacts . has_key ( person . name ) : <EOL> self . contacts [ person . name ] = person <EOL> if not self . onlineContacts . has_key ( person . name ) and ( person . status == ONLINE or person . status == AWAY ) : <EOL> self . onlineContacts [ person . name ] = person <EOL> if self . onlineContacts . has_key ( person . name ) and person . status == OFFLINE : <EOL> del self . onlineContacts [ person . name ] <EOL> def registerAccountClient ( self , client ) : <EOL> """<STR_LIT>""" <EOL> if not client in self . clients : <EOL> self . clients . append ( client ) <EOL> def unregisterAccountClient ( self , client ) : <EOL> """<STR_LIT>""" <EOL> if client in self . clients : <EOL> self . clients . remove ( client ) <EOL> def contactChangedNick ( self , person , newnick ) : <EOL> oldname = person . name <EOL> if self . contacts . has_key ( oldname ) : <EOL> del self . contacts [ oldname ] <EOL> person . name = newnick <EOL> self . contacts [ newnick ] = person <EOL> if self . onlineContacts . has_key ( oldname ) : <EOL> del self . onlineContacts [ oldname ] <EOL> self . onlineContacts [ newnick ] = person <EOL> class Conversation : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , person , chatui ) : <EOL> """<STR_LIT>""" <EOL> self . chatui = chatui <EOL> self . person = person <EOL> def show ( self ) : <EOL> """<STR_LIT>""" <EOL> raise NotImplementedError ( "<STR_LIT>" ) <EOL> def hide ( self ) : <EOL> """<STR_LIT>""" <EOL> raise NotImplementedError ( "<STR_LIT>" ) <EOL> def sendText ( self , text ) : <EOL> """<STR_LIT>""" <EOL> self . person . sendMessage ( text , None ) <EOL> def showMessage ( self , text , metadata = None ) : <EOL> """<STR_LIT>""" <EOL> raise NotImplementedError ( "<STR_LIT>" ) <EOL> def contactChangedNick ( self , person , newnick ) : <EOL> """<STR_LIT>""" <EOL> self . person . name = newnick <EOL> class GroupConversation : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , group , chatui ) : <EOL> """<STR_LIT>""" <EOL> self . chatui = chatui <EOL> self . group = group <EOL> self . members = [ ] <EOL> def show ( self ) : <EOL> """<STR_LIT>""" <EOL> raise NotImplementedError ( "<STR_LIT>" ) <EOL> def hide ( self ) : <EOL> """<STR_LIT>""" <EOL> raise NotImplementedError ( "<STR_LIT>" ) <EOL> def sendText ( self , text ) : <EOL> """<STR_LIT>""" <EOL> self . group . sendGroupMessage ( text , None ) <EOL> def showGroupMessage ( self , sender , text , metadata = None ) : <EOL> """<STR_LIT>""" <EOL> raise NotImplementedError ( "<STR_LIT>" ) <EOL> def setGroupMembers ( self , members ) : <EOL> """<STR_LIT>""" <EOL> self . members = members <EOL> def setTopic ( self , topic , author ) : <EOL> """<STR_LIT>""" <EOL> raise NotImplementedError ( "<STR_LIT>" ) <EOL> def memberJoined ( self , member ) : <EOL> """<STR_LIT>""" <EOL> if not member in self . members : <EOL> self . members . append ( member ) <EOL> def memberChangedNick ( self , oldnick , newnick ) : <EOL> """<STR_LIT>""" <EOL> if oldnick in self . members : <EOL> self . members . remove ( oldnick ) <EOL> self . members . append ( newnick ) <EOL> def memberLeft ( self , member ) : <EOL> """<STR_LIT>""" <EOL> if member in self . members : <EOL> self . members . remove ( member ) <EOL> class ChatUI : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self ) : <EOL> self . conversations = { } <EOL> self . groupConversations = { } <EOL> self . persons = { } <EOL> self . groups = { } <EOL> self . onlineClients = [ ] <EOL> self . contactsList = ContactsList ( self ) <EOL> def registerAccountClient ( self , client ) : <EOL> """<STR_LIT>""" <EOL> print "<STR_LIT>" , client . accountName <EOL> self . onlineClients . append ( client ) <EOL> self . contactsList . registerAccountClient ( client ) <EOL> return client <EOL> def unregisterAccountClient ( self , client ) : <EOL> """<STR_LIT>""" <EOL> print "<STR_LIT>" , client . accountName <EOL> self . onlineClients . remove ( client ) <EOL> self . contactsList . unregisterAccountClient ( client ) <EOL> def getContactsList ( self ) : <EOL> """<STR_LIT>""" <EOL> return self . contactsList <EOL> def getConversation ( self , person , Class = Conversation , stayHidden = <NUM_LIT:0> ) : <EOL> """<STR_LIT>""" <EOL> conv = self . conversations . get ( person ) <EOL> if not conv : <EOL> conv = Class ( person , self ) <EOL> self . conversations [ person ] = conv <EOL> if stayHidden : <EOL> conv . hide ( ) <EOL> else : <EOL> conv . show ( ) <EOL> return conv <EOL> def getGroupConversation ( self , group , Class = GroupConversation , stayHidden = <NUM_LIT:0> ) : <EOL> """<STR_LIT>""" <EOL> conv = self . groupConversations . get ( group ) <EOL> if not conv : <EOL> conv = Class ( group , self ) <EOL> self . groupConversations [ group ] = conv <EOL> if stayHidden : <EOL> conv . hide ( ) <EOL> else : <EOL> conv . show ( ) <EOL> return conv <EOL> def getPerson ( self , name , client ) : <EOL> """<STR_LIT>""" <EOL> account = client . account <EOL> p = self . persons . get ( ( name , account ) ) <EOL> if not p : <EOL> p = account . getPerson ( name ) <EOL> self . persons [ name , account ] = p <EOL> return p <EOL> def getGroup ( self , name , client ) : <EOL> """<STR_LIT>""" <EOL> account = client . account <EOL> g = self . groups . get ( ( name , account ) ) <EOL> if not g : <EOL> g = account . getGroup ( name ) <EOL> self . groups [ name , account ] = g <EOL> return g <EOL> def contactChangedNick ( self , person , newnick ) : <EOL> """<STR_LIT>""" <EOL> oldnick = person . name <EOL> if self . persons . has_key ( ( oldnick , person . account ) ) : <EOL> conv = self . conversations . get ( person ) <EOL> if conv : <EOL> conv . contactChangedNick ( person , newnick ) <EOL> self . contactsList . contactChangedNick ( person , newnick ) <EOL> del self . persons [ oldnick , person . account ] <EOL> person . name = newnick <EOL> self . persons [ person . name , person . account ] = person </s>
