diff src/browser/libervia_main.py @ 478:992b900ab876

browser side: rename and refactor constant UI_PARAMS to CACHED_PARAMS, from a dict of dict to a list of 2-tuple
author souliane <souliane@mailoo.org>
date Thu, 12 Jun 2014 22:37:22 +0200
parents fac8e8bc9a1a
children c21ea1fe3593
line wrap: on
line diff
--- a/src/browser/libervia_main.py	Thu Jun 12 22:32:33 2014 +0200
+++ b/src/browser/libervia_main.py	Thu Jun 12 22:37:22 2014 +0200
@@ -196,7 +196,7 @@
         self._register.call('isRegistered', self._isRegisteredCB)
         self.initialised = False
         self.init_cache = []  # used to cache events until initialisation is done
-        self.ui_params = {key: C.UI_PARAMS[key]['initial_value'] for key in C.UI_PARAMS}
+        self.cached_params = {}
 
     def addSelectedListener(self, callback):
         self._selected_listeners.add(callback)
@@ -278,7 +278,7 @@
     def refresh(self):
         """Refresh the general display."""
         self.panel.refresh()
-        if self.getUIParam('unibox'):
+        if self.getCachedParam(C.COMPOSITION_KEY, C.ENABLE_UNIBOX_PARAM) == 'true':
             self.uni_box = self.panel.unibox_panel.unibox
         else:
             self.uni_box = None
@@ -357,18 +357,15 @@
         self.bridge.call("getNewAccountDomain", (domain_cb, domain_eb))
         self.discuss_panel.addWidget(panels.MicroblogPanel(self, []))
 
-        # get ui params and refresh the display
-        count = 0  # used to do something similar to DeferredList
+        # get cached params and refresh the display
+        def param_cb(cat, name, count):
+            count[0] += 1
+            refresh = count[0] == len(C.CACHED_PARAMS)
+            return lambda value: self._paramUpdate(name, value, cat, refresh)
 
-        def ui_params_cb(param):
-            def cb(value):
-                count += 1
-                refresh = count == len(C.UI_PARAMS)
-                self._paramUpdate(C.UI_PARAMS[param]['name'], value, C.UI_PARAMS[param]['category'], refresh)
-            return cb
-
-        for param in C.UI_PARAMS:
-            self.bridge.call('asyncGetParamA', ui_params_cb(param), C.UI_PARAMS[param]['name'], C.UI_PARAMS[param]['category'])
+        count = [0]  # used to do something similar to DeferredList
+        for cat, name in C.CACHED_PARAMS:
+            self.bridge.call('asyncGetParamA', param_cb(cat, name, count), name, cat)
 
     def _tryAutoConnect(self, skip_validation=False):
         """This method retrieve the eventual URL parameters to auto-connect the user.
@@ -852,19 +849,20 @@
         during initialization when the UI parameters values are retrieved.
         @param refresh: set to True to refresh the general UI
         """
-        for param in C.UI_PARAMS:
-            if name == C.UI_PARAMS[param]['name'] and category == C.UI_PARAMS[param]['category']:
-                self.ui_params[param] = C.UI_PARAMS[param]['cast_from_str'](value)
+        for param_cat, param_name in C.CACHED_PARAMS:
+            if name == param_name and category == param_cat:
+                self.cached_params[(category, name)] = value
                 if refresh:
                     self.refresh()
                 break
 
-    def getUIParam(self, param):
-        """Return UI param cached value
+    def getCachedParam(self, category, name):
+        """Return a parameter cached value (e.g for refreshing the UI)
 
-        @param param: the parameter key
+        @param category (str): the parameter category
+        @pram name (str): the parameter name
         """
-        return self.ui_params[param] if param in self.ui_params else None
+        return self.cached_params[(category, name)] if (category, name) in self.cached_params else None
 
     def sendError(self, errorData):
         dialog.InfoDialog("Error while sending message",