changeset 78:ace2af8abc5a

Added method to know which MUC are joined, and which subjects were received. - plugin xep-0045: new methods getRoomJoined and getRoomSubjects - wix: room joined are openned and subjects are set on profile plug
author Goffi <goffi@goffi.org>
date Wed, 31 Mar 2010 17:16:27 +1100
parents 1ae680f9682e
children db0a0f000e37
files frontends/quick_frontend/quick_app.py frontends/sat_bridge_frontend/DBus.py frontends/wix/chat.py plugins/plugin_xep_0045.py
diffstat 4 files changed, 54 insertions(+), 6 deletions(-) [+]
line wrap: on
line diff
--- a/frontends/quick_frontend/quick_app.py	Tue Mar 30 16:08:44 2010 +1100
+++ b/frontends/quick_frontend/quick_app.py	Wed Mar 31 17:16:27 2010 +1100
@@ -104,10 +104,18 @@
                 statuses = presences[contact][res][2]
                 self.presenceUpdate(jabber_id, show, priority, statuses, profile)
 
+        #The waiting subscription requests
         waitingSub = self.bridge.getWaitingSub(profile)
         for sub in waitingSub:
             self.subscribe(waitingSub[sub], sub, profile)
 
+        #Now we open the MUC window when we already are:
+        for room_args in self.bridge.getRoomJoined(profile):
+            self.roomJoined(*room_args, profile=profile)
+
+        for subject_args in self.bridge.getRoomSubjects(profile):
+            self.roomNewSubject(*subject_args, profile=profile)
+
     def unplug_profile(self, profile):
         """Tell the application to not follow anymore the profile"""
         if not profile in self.profiles:
--- a/frontends/sat_bridge_frontend/DBus.py	Tue Mar 30 16:08:44 2010 +1100
+++ b/frontends/sat_bridge_frontend/DBus.py	Wed Mar 31 17:16:27 2010 +1100
@@ -110,6 +110,12 @@
         return self.db_req_iface.confirmationAnswer(id, accepted, data)
 
 #methods from plugins
+    def getRoomJoined(self, profile_key='@DEFAULT@'):
+        return self.db_comm_iface.getRoomJoined(profile_key)
+
+    def getRoomSubjects(self, profile_key='@DEFAULT@'):
+        return self.db_comm_iface.getRoomSubjects(profile_key)
+
     def joinMUC(self, service, roomId, nick, profile_key='@DEFAULT@'):
         return self.db_comm_iface.joinMUC(service, roomId, nick, profile_key)
 
--- a/frontends/wix/chat.py	Tue Mar 30 16:08:44 2010 +1100
+++ b/frontends/wix/chat.py	Wed Mar 31 17:16:27 2010 +1100
@@ -51,9 +51,8 @@
         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.SetMenuBar(wx.MenuBar())
         self.setType(self.type)
-
-        self.__createMenus()
         
         #events
         self.Bind(wx.EVT_CLOSE, self.onClose, self)
@@ -86,11 +85,17 @@
         if type is 'group' and not self.splitter.IsSplit():
             self.__createPresents()
             self.subjectBox.Show()
+            self.__eraseMenus()
+
         elif type is 'one2one' and self.splitter.IsSplit():
             self.splitter.Unsplit(self.present_panel)
             del self.present_panel
+            self.GetMenuBar().Show()
+            self.subjectBox.Hide()
+            self.__createMenus_O2O()
         else:
             self.subjectBox.Hide()
+            self.__createMenus_O2O()
 
     def setPresents(self, nicks):
         """Set the users presents in the contact list for a group chat
@@ -129,13 +134,20 @@
         self.subjectBox.SetValue(subject)
 
 
-    def __createMenus(self):
+    def __eraseMenus(self):
+        """erase all menus"""
+        menuBar = self.GetMenuBar()
+        for i in range(menuBar.GetMenuCount()):
+            menuBar.Remove(i)
+    
+    def __createMenus_O2O(self):
+        """create menu bar for one 2 one chat"""
         info("Creating menus")
+        self.__eraseMenus()
+        menuBar = self.GetMenuBar()
         actionMenu = wx.Menu()
         actionMenu.Append(idSEND, _("&SendFile	CTRL-s"),_(" Send a file to contact"))
-        menuBar = wx.MenuBar()
         menuBar.Append(actionMenu,_("&Action"))
-        self.SetMenuBar(menuBar)
 
         #events
         wx.EVT_MENU(self, idSEND, self.onSendFile)
--- a/plugins/plugin_xep_0045.py	Tue Mar 30 16:08:44 2010 +1100
+++ b/plugins/plugin_xep_0045.py	Wed Mar 31 17:16:27 2010 +1100
@@ -69,6 +69,8 @@
         self.host = host
         self.clients={}
         host.bridge.addMethod("joinMUC", ".communication", in_sign='ssss', out_sign='', method=self.join)
+        host.bridge.addMethod("getRoomJoined", ".communication", in_sign='s', out_sign='a(ssass)', method=self.getRoomJoined)
+        host.bridge.addMethod("getRoomSubjects", ".communication", in_sign='s', out_sign='a(sss)', method=self.getRoomSubjects)
         host.bridge.addSignal("roomJoined", ".communication", signature='ssasss') #args: room_id, room_service, room_nicks, user_nick, profile
         host.bridge.addSignal("roomUserJoined", ".communication", signature='sssa{ss}s') #args: room_id, room_service, user_nick, user_data, profile
         host.bridge.addSignal("roomUserLeft", ".communication", signature='sssa{ss}s') #args: room_id, room_service, user_nick, user_data, profile
@@ -98,6 +100,23 @@
         error ("Error when joining the room")
         #TODO: gof: send an error message throught the bridge
 
+    def getRoomJoined(self, profile_key='@DEFAULT@'):
+        """Return room where user is"""
+        profile = self.host.memory.getProfileName(profile_key)
+        result = []
+        if not self.__check_profile(profile):
+            return result
+        for room in self.clients[profile].joined_rooms.values():
+            result.append((room.roomIdentifier, room.service, [user.nick for user in room.roster.values()], room.nick))
+        return result
+
+    def getRoomSubjects(self, profile_key='@DEFAULT@'):
+        """Return received subjects of rooms"""
+        profile = self.host.memory.getProfileName(profile_key)
+        if not self.__check_profile(profile):
+            return []
+        return self.clients[profile].rec_subjects.values()
+
     def join(self, service, roomId, nick, profile_key='@DEFAULT@'):
         profile = self.host.memory.getProfileName(profile_key)
         if not self.__check_profile(profile):
@@ -123,7 +142,8 @@
         self.plugin_parent = plugin_parent
         self.host = plugin_parent.host
         muc.MUCClient.__init__(self)
-        self.joined_rooms = {} #FIXME gof: check if necessary
+        self.joined_rooms = {}
+        self.rec_subjects = {}
         print "init SatMUCClient OK"
     
     def receivedGroupChat(self, room, user, body):
@@ -145,6 +165,8 @@
 
     def receivedSubject(self, room, subject):
         debug (_("New subject for room (%(room_id)s): %(subject)s") % {'room_id':room.occupantJID.userhost(),'subject':subject})
+        room_jid = room.roomIdentifier+'@'+room.service
+        self.rec_subjects[room_jid] = (room.roomIdentifier, room.service, subject)
         self.host.bridge.roomNewSubject(room.roomIdentifier, room.service, subject, self.parent.profile)
 
     #def connectionInitialized(self):