diff src/core/sat_main.py @ 412:62b17854254e

database integration: first draft - using SQLite as backend /!\ Not finished yet, break execution. SàT CAN'T LAUNCH PROPERLY IN THE CURRENT STATE
author Goffi <goffi@goffi.org>
date Sun, 30 Oct 2011 23:13:40 +0100
parents 3ed53803b3b3
children dd4caab17008
line wrap: on
line diff
--- a/src/core/sat_main.py	Sat Oct 08 21:03:02 2011 +0200
+++ b/src/core/sat_main.py	Sun Oct 30 23:13:40 2011 +0100
@@ -112,7 +112,6 @@
 
         self.trigger = TriggerManager() #trigger are used to change SàT behaviour 
         
-
         self.bridge=DBusBridge()
         self.bridge.register("getVersion", lambda: self.get_const('client_version'))
         self.bridge.register("getProfileName", self.memory.getProfileName)
@@ -148,7 +147,12 @@
         self.bridge.register("getMenus", self.getMenus)
         self.bridge.register("getMenuHelp", self.getMenuHelp)
         self.bridge.register("callMenu", self.callMenu)
+    
+        self.memory.initialized.addCallback(self._postMemoryInit) 
 
+    def _postMemoryInit(self, ignore):
+        """Method called after memory initialization is done"""
+        info(_("Memory initialised"))
         self._import_plugins()
 
 
@@ -156,8 +160,8 @@
         """Import all plugins found in plugins directory"""
         import sat.plugins
         plugins_path = os.path.dirname(sat.plugins.__file__) 
-        plug_lst = [os.path.splitext(plugin)[0] for plugin in map(os.path.basename,glob (os.path.join(plugins_path,"plugin*.py")))]
-        __plugins_to_import = {} #plugins will still have to import
+        plug_lst = [os.path.splitext(plugin)[0] for plugin in map(os.path.basename,glob(os.path.join(plugins_path,"plugin*.py")))]
+        __plugins_to_import = {} #plugins we still have to import
         for plug in plug_lst:
             plugin_path = 'sat.plugins.'+plug
             __import__(plugin_path)
@@ -215,37 +219,44 @@
             if callback:
                 callback()
             return
-        current = self.profiles[profile] = xmpp.SatXMPPClient(self, profile,
-            jid.JID(self.memory.getParamA("JabberID", "Connection", profile_key = profile), profile),
-            self.memory.getParamA("Password", "Connection", profile_key = profile),
-            self.memory.getParamA("Server", "Connection", profile_key = profile), 5222)
+
+        def afterMemoryInit(ignore):
+            """This part must be called when we have loaded individual parameters from memory"""
+            current = self.profiles[profile] = xmpp.SatXMPPClient(self, profile,
+                jid.JID(self.memory.getParamA("JabberID", "Connection", profile_key = profile), profile),
+                self.memory.getParamA("Password", "Connection", profile_key = profile),
+                self.memory.getParamA("Server", "Connection", profile_key = profile), 5222)
 
-        if callback and errback:
-            current.getConnectionDeferred().addCallbacks(lambda x:callback(), errback)
+            if callback and errback:
+                current.getConnectionDeferred().addCallbacks(lambda x:callback(), errback)
 
-        current.messageProt = xmpp.SatMessageProtocol(self)
-        current.messageProt.setHandlerParent(current)
-        
-        current.roster = xmpp.SatRosterProtocol(self)
-        current.roster.setHandlerParent(current)
+            current.messageProt = xmpp.SatMessageProtocol(self)
+            current.messageProt.setHandlerParent(current)
+            
+            current.roster = xmpp.SatRosterProtocol(self)
+            current.roster.setHandlerParent(current)
 
-        current.presence = xmpp.SatPresenceProtocol(self)
-        current.presence.setHandlerParent(current)
+            current.presence = xmpp.SatPresenceProtocol(self)
+            current.presence.setHandlerParent(current)
 
-        current.fallBack = xmpp.SatFallbackHandler(self)
-        current.fallBack.setHandlerParent(current)
+            current.fallBack = xmpp.SatFallbackHandler(self)
+            current.fallBack.setHandlerParent(current)
+
+            current.versionHandler = xmpp.SatVersionHandler(self.get_const('client_name'),
+                                                         self.get_const('client_version'))
+            current.versionHandler.setHandlerParent(current)
 
-        current.versionHandler = xmpp.SatVersionHandler(self.get_const('client_name'),
-                                                     self.get_const('client_version'))
-        current.versionHandler.setHandlerParent(current)
+            debug (_("setting plugins parents"))
+            
+            for plugin in self.plugins.iteritems():
+                if plugin[1].is_handler:
+                    plugin[1].getHandler(profile).setHandlerParent(current)
 
-        debug (_("setting plugins parents"))
-        
-        for plugin in self.plugins.iteritems():
-            if plugin[1].is_handler:
-                plugin[1].getHandler(profile).setHandlerParent(current)
+            current.startService()
 
-        current.startService()
+        params_defer = self.memory.loadIndividualParams(profile).addCallback(afterMemoryInit)
+        if errback:
+            params_defer.addErrback(errback)
 
     def disconnect(self, profile_key):
         """disconnect from jabber server"""