diff frontends/primitivus/primitivus @ 120:1ca5f254ce41

primitivus group chat & misc primitivus: new widget: SurroundedText (text with a character repeated around it) primitivus: new decorator LabelLine (like lineBox, but with a label on the top line) wix & primitivus & quick_app: group chat method move to quick_chat wix: when new message, window is not raised anymore, but RequestUserAttention is called instead
author Goffi <goffi@goffi.org>
date Thu, 08 Jul 2010 14:12:18 +0800
parents ded2431cea5a
children 961e0898271f
line wrap: on
line diff
--- a/frontends/primitivus/primitivus	Mon Jul 05 19:13:36 2010 +0800
+++ b/frontends/primitivus/primitivus	Thu Jul 08 14:12:18 2010 +0800
@@ -28,7 +28,7 @@
 from profile_manager import ProfileManager
 from contact_list import ContactList
 from chat import Chat
-from custom_widgets import AdvancedEdit,FocusFrame
+from custom_widgets import AdvancedEdit,FocusFrame,InputDialog,Alert
 import pdb
 """from window import Window
 from editbox import EditBox
@@ -39,6 +39,7 @@
 from logging import debug, info, error
 #import locale
 import sys, os
+from tools.jid  import JID
 #from curses import ascii
 #import locale
 #from signal import signal, SIGWINCH 
@@ -104,6 +105,9 @@
             raise urwid.ExitMainLoop()
         elif input == 'ctrl d' and 'D' in self.bridge.getVersion(): #Debug only for dev versions
             self.debug()
+        elif input == 'meta j': #user wants to join a room
+            pop_up_widget = InputDialog(_("Entering a MUC room"), _("Please enter MUC's JID"), default_txt = 'test@conference.necton2.int', cancel_cb=self.removePopUp, ok_cb=self.onJoinRoom)
+            self.showPopUp(pop_up_widget)
   
     def __buildMainWidget(self):
         self.contactList = ContactList(self, self.CM, on_click = self.contactSelected, on_change=lambda w: self.redraw())
@@ -118,7 +122,7 @@
         self.loop.widget = self.__buildMainWidget() 
         QuickApp.plug_profile(self, profile_key)
     
-    def removePopUp(self):
+    def removePopUp(self, widget=None):
         self.loop.widget = self.main_widget
 
     def showPopUp(self, pop_up_widget):
@@ -134,11 +138,26 @@
             self.center_part.widget_list[1] = self.chat_wins[contact]
 
     def onTextEntered(self, editBar):
-        contact = self.contactList.get_contact()
+        """Called when text is entered in the main edit bar"""
+        contact = self.contactList.get_contact() ###Based on the fact that there is currently only one contact selectableat once
         if contact:
-            self.bridge.sendMessage(contact, editBar.get_edit_text(), profile_key=self.profile)
+            chat = self.chat_wins[contact]
+            self.bridge.sendMessage(contact,
+                                    editBar.get_edit_text(),
+                                    type = "groupchat" if chat.type == 'group' else "chat",
+                                    profile_key=self.profile)
             editBar.set_edit_text('')
 
+    def onJoinRoom(self, button, edit):
+        self.removePopUp()
+        room_jid = JID(edit.get_edit_text())
+        if room_jid.is_valid():
+            self.bridge.joinMUC(room_jid.domain, room_jid.node, self.profiles[self.profile]['whoami'].node, self.profile)
+        else:
+            message = _("'%s' is an invalid JID !") % room_jid
+            error (message)
+            Alert(_("Error"), message, ok_cb=self.removePopUp)        
+
 sat = PrimitivusApp()
 sat.start()