diff frontends/primitivus/primitivus @ 173:ec6611445a5b

Primitivus: added Gateways support
author Goffi <goffi@goffi.org>
date Thu, 12 Aug 2010 13:18:22 +0800
parents a2655a0a4eac
children a50953ac6191
line wrap: on
line diff
--- a/frontends/primitivus/primitivus	Thu Aug 12 13:18:11 2010 +0800
+++ b/frontends/primitivus/primitivus	Thu Aug 12 13:18:22 2010 +0800
@@ -28,6 +28,7 @@
 from profile_manager import ProfileManager
 from contact_list import ContactList
 from chat import Chat
+from gateways import GatewaysManager
 import custom_widgets
 import pdb
 import logging
@@ -191,6 +192,7 @@
         menu.addMenu(contact, _("Remove contact"), self.onRemoveContactRequest)
         communication = _("Communication")
         menu.addMenu(communication, _("Join room"), self.onJoinRoomRequest, 'meta j')
+        menu.addMenu(communication, _("Find Gateways"), self.onFindGatewaysRequest, 'meta g')
         #additionals menus
         #FIXME: do this in a more generic way (in quickapp)
         add_menus = self.bridge.getMenus()
@@ -316,12 +318,30 @@
             misc = {}
             #FIXME FIXME FIXME: must clean all this crap !
             title = _('Form')
-            if data['type'] == _('registration'):
+            if data['type'] == 'registration':
                 title = _('Registration')
                 misc['target'] = data['target']
                 misc['action_back'] = self.bridge.gatewayRegister
             ui = XMLUI(self, title=title, xml_data = data['xml'], misc = misc)
-            self.addWindow(ui)
+            if data['type'] == 'registration':
+                ui.show('popup')
+            else:
+                ui.show('window')
+        elif type == "ERROR":
+            self.current_action_ids.remove(id)
+            self.showPopUp(custom_widgets.Alert(_("Error"), unicode(data["message"]), ok_cb=self.removePopUp)) #FIXME: remove unicode here when DBus Bridge will no return dbus.String anymore 
+        elif type == "RESULT":
+            self.current_action_ids.remove(id)
+            if self.current_action_ids_cb.has_key(id):
+                callback = self.current_action_ids_cb[id]
+                del self.current_action_ids_cb[id]
+                callback(data)
+        elif type == "DICT_DICT":
+            self.current_action_ids.remove(id)
+            if self.current_action_ids_cb.has_key(id):
+                callback = self.current_action_ids_cb[id]
+                del self.current_action_ids_cb[id]
+                callback(data)
         else:
             error (_("FIXME FIXME FIXME: type [%s] not implemented") % type)
             raise NotImplementedError
@@ -335,7 +355,7 @@
         else:
             message = _("'%s' is an invalid JID !") % room_jid
             error (message)
-            custom_widgets.Alert(_("Error"), message, ok_cb=self.removePopUp)        
+            self.showPopUp(custom_widgets.Alert(_("Error"), message, ok_cb=self.removePopUp)) 
 
     def onAddContact(self, button, edit):
         self.removePopUp()
@@ -345,14 +365,14 @@
         else:
             message = _("'%s' is an invalid JID !") % jid
             error (message)
-            custom_widgets.Alert(_("Error"), message, ok_cb=self.removePopUp)
+            self.showPopUp(custom_widgets.Alert(_("Error"), message, ok_cb=self.removePopUp))
 
     def onRemoveContact(self, button):
         self.removePopUp()
         info(_("Unsubscribing %s presence"),self.contactList.get_contact())
         self.bridge.delContact(self.contactList.get_contact(), profile_key=self.profile)
 
-    #Menu events#
+    #MENU EVENTS#
     def onConnectRequest(self, menu):
         self.bridge.connect(self.profile)
 
@@ -371,6 +391,12 @@
         pop_up_widget = custom_widgets.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 onFindGatewaysRequest(self, e):
+        debug(_("Find Gateways request"))
+        id = self.bridge.findGateways(self.profiles[self.profile]['whoami'].domain, self.profile)
+        self.current_action_ids.add(id)
+        self.current_action_ids_cb[id] = self.onGatewaysFound
+
     def onAddContactRequest(self, menu):
         pop_up_widget = custom_widgets.InputDialog(_("Adding a contact"), _("Please enter new contact JID"), default_txt = 'name@server.tld', cancel_cb=self.removePopUp, ok_cb=self.onAddContact)
         self.showPopUp(pop_up_widget)
@@ -385,7 +411,15 @@
 
     def onAboutRequest(self, menu):
         self.showPopUp(custom_widgets.Alert(_("About"), const_APP_NAME + " v" + self.bridge.getVersion(), ok_cb=self.removePopUp)) 
-        
+       
+    #MISC CALLBACKS#
+
+    def onGatewaysFound(self, data):
+        """Called when SàT has found the server gateways"""
+        target = data['__private__']['target']
+        del data['__private__']
+        gatewayManager = GatewaysManager(self, data, server=target)
+        self.addWindow(gatewayManager)
 
 sat = PrimitivusApp()
 sat.start()