diff frontends/wix/chat.py @ 72:f271fff3a713

MUC implementation: first draft /!\ the experimental muc branche of wokkel must be used - bridge: new roomJoined signal - wix: contact list widget is now in a separate file, and manage different kinds of presentation - wix: chat window now manage group chat (first draft, not working yet) - wix: constants are now in a separate class, so then can be accessible from everywhere - wix: new menu to join room (do nothing yet, except entering in a test room) - new plugin for xep 0045 (MUC), use wokkel experimental MUC branch - plugins: the profile is now given for get_handler, cause it can be used internally by a plugin (e.g.: xep-0045 plugin)
author Goffi <goffi@goffi.org>
date Sun, 21 Mar 2010 10:28:55 +1100
parents 8f2ed279784b
children 7322a41f8a8e
line wrap: on
line diff
--- a/frontends/wix/chat.py	Sat Mar 06 14:57:23 2010 +1100
+++ b/frontends/wix/chat.py	Sun Mar 21 10:28:55 2010 +1100
@@ -27,6 +27,7 @@
 from logging import debug, info, error
 from tools.jid  import JID
 from quick_frontend.quick_chat import QuickChat
+from contact_list import ContactList
 
 
 idSEND           = 1
@@ -34,17 +35,22 @@
 class Chat(wx.Frame, QuickChat):
     """The chat Window for one to one conversations"""
 
-    def __init__(self, to_jid, host):
-        wx.Frame.__init__(self, None, title=to_jid, pos=(0,0), size=(400,200))
-        QuickChat.__init__(self, to_jid, host) 
+    def __init__(self, target, host, type='one2one'):
+        wx.Frame.__init__(self, None, title=target, pos=(0,0), size=(400,200))
+        QuickChat.__init__(self, target, host, type) 
 
-        self.chatWindow = wx.TextCtrl(self, -1, style = wx.TE_MULTILINE | wx.TE_RICH | wx.TE_READONLY)
-        self.textBox = wx.TextCtrl(self, -1, style = wx.TE_PROCESS_ENTER)
-        self.sizer = wx.BoxSizer(wx.VERTICAL)
-        self.sizer.Add(self.chatWindow, 1, flag=wx.EXPAND)
-        self.sizer.Add(self.textBox, flag=wx.EXPAND)
-        self.SetSizer(self.sizer)
-        self.SetAutoLayout(True)
+        self.splitter = wx.SplitterWindow(self, -1)
+        
+        self.conv_panel = wx.Panel(self.splitter)
+        self.conv_panel.sizer = wx.BoxSizer(wx.VERTICAL)
+        self.chatWindow = wx.TextCtrl(self.conv_panel, -1, style = wx.TE_MULTILINE | wx.TE_RICH | wx.TE_READONLY)
+        self.textBox = wx.TextCtrl(self.conv_panel, -1, style = wx.TE_PROCESS_ENTER)
+        self.conv_panel.sizer.Add(self.chatWindow, 1, flag=wx.EXPAND)
+        self.conv_panel.sizer.Add(self.textBox, flag=wx.EXPAND)
+        self.conv_panel.SetSizer(self.conv_panel.sizer)
+        self.splitter.Initialize(self.conv_panel)
+        self.setType(self.type)
+
         self.createMenus()
         
         #events
@@ -61,7 +67,37 @@
         #misc
         self.textBox.SetFocus()
         self.Hide() #We hide because of the show toggle
-    
+   
+    def __createPresents(self):
+        """Create a list of present people in a group chat"""
+        self.present_panel = wx.Panel(self.splitter)
+        self.present_panel.sizer = wx.BoxSizer(wx.VERTICAL)
+        self.present_panel.SetBackgroundColour(wx.BLUE)
+        self.present_panel.presents = ContactList(self.present_panel, self.host, type='nicks')
+        self.present_panel.presents.SetMinSize(wx.Size(80,20))
+        self.present_panel.sizer.Add(self.present_panel.presents, 1, wx.EXPAND)
+        self.present_panel.SetSizer(self.present_panel.sizer)
+        self.splitter.SplitVertically(self.present_panel, self.conv_panel, 80)
+
+    def setType(self, type):
+        QuickChat.setType(self, type)
+        if type is 'group' and not self.splitter.IsSplit():
+            self.__createPresents()
+        elif type is 'one2one' and self.splitter.IsSplit():
+            self.splitter.Unsplit(self.present_panel)
+            del self.present_panel
+
+    def setPresents(self, nicks):
+        """Set the users presents in the contact list for a group chat
+        @param nicks: list of nicknames
+        """
+        debug (_("Adding users %s to room") % nicks)
+        if self.type != "group":
+            error (_("[INTERNAL] trying to set presents nicks for a non group chat window"))
+            return
+        for nick in nicks:
+           self.present_panel.presents.replace(nick)
+
     def createMenus(self):
         info("Creating menus")
         actionMenu = wx.Menu()
@@ -86,7 +122,7 @@
 
     def onEnterPressed(self, event):
         """Behaviour when enter pressed in send line."""
-        self.host.bridge.sendMessage(self.to_jid, event.GetString(), profile_key=self.host.profile)
+        self.host.bridge.sendMessage(self.target, event.GetString(), profile_key=self.host.profile)
         self.textBox.Clear()
 
         
@@ -111,7 +147,7 @@
         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.to_jid)
+            full_jid = self.host.CM.get_full(self.target)
             id = self.host.bridge.sendFile(full_jid, filename)
             self.host.waitProgress(id, _("File Transfer"), _("Copying %s") % os.path.basename(filename))