diff src/cagou/core/profile_manager.py @ 16:ba14b596b90e

host can now be get as a global value: instead of always copying host from class to class, it can now be gotten from a global class with: from cagou import G then G.host will give host. This will probably be used on the long term on all SàT (backend + frontends). As host is currently needed in several places (most importantly in QuickFrontend), the argument is still present, and must be there even is unused on class inheriting from QuickSomething.
author Goffi <goffi@goffi.org>
date Sat, 09 Jul 2016 18:41:52 +0200
parents 56838ad5c84b
children 817a45e6d7e3
line wrap: on
line diff
--- a/src/cagou/core/profile_manager.py	Sat Jul 09 17:24:01 2016 +0200
+++ b/src/cagou/core/profile_manager.py	Sat Jul 09 18:41:52 2016 +0200
@@ -28,6 +28,7 @@
 from kivy.uix.screenmanager import ScreenManager, Screen
 from kivy.adapters import listadapter
 from kivy import properties
+from cagou import G
 
 
 class ProfileItem(listview.ListItemButton):
@@ -39,7 +40,6 @@
     def __init__(self, pm, *args, **kwargs):
         super(ProfileListAdapter, self).__init__(*args, **kwargs)
         self.pm = pm
-        self.host = pm.host
 
     def closeUI(self, xmlui):
         self.pm.screen_manager.transition.direction = 'right'
@@ -58,9 +58,9 @@
         def authenticate_cb(data, cb_id, profile):
             if C.bool(data.pop('validated', C.BOOL_FALSE)):
                 super(ProfileListAdapter, self).select_item_view(view)
-            self.host.actionManager(data, callback=authenticate_cb, ui_show_cb=self.showUI, profile=profile)
+            G.host.actionManager(data, callback=authenticate_cb, ui_show_cb=self.showUI, profile=profile)
 
-        self.host.launchAction(C.AUTHENTICATE_PROFILE_ID, callback=authenticate_cb, profile=view.text)
+        G.host.launchAction(C.AUTHENTICATE_PROFILE_ID, callback=authenticate_cb, profile=view.text)
 
 
 class ConnectButton(Button):
@@ -80,7 +80,6 @@
     def __init__(self, pm):
         super(NewProfileScreen, self).__init__(name=u'new_profile')
         self.pm = pm
-        self.host = pm.host
 
     def onCreationFailure(self, failure):
         msg = [l for l in unicode(failure).split('\n') if l][-1]
@@ -88,12 +87,12 @@
 
     def onCreationSuccess(self, profile):
         self.pm.profiles_screen.reload()
-        self.host.bridge.profileStartSession(self.password.text, profile, callback=lambda dummy: self._sessionStarted(profile), errback=self.onCreationFailure)
+        G.host.bridge.profileStartSession(self.password.text, profile, callback=lambda dummy: self._sessionStarted(profile), errback=self.onCreationFailure)
 
     def _sessionStarted(self, profile):
         jid = self.jid.text.strip()
-        self.host.bridge.setParam("JabberID", jid, "Connection", -1, profile)
-        self.host.bridge.setParam("Password", self.password.text, "Connection", -1, profile)
+        G.host.bridge.setParam("JabberID", jid, "Connection", -1, profile)
+        G.host.bridge.setParam("Password", self.password.text, "Connection", -1, profile)
         self.pm.screen_manager.transition.direction = 'right'
         self.pm.screen_manager.current = 'profiles'
 
@@ -101,14 +100,13 @@
         name = self.profile_name.text.strip()
         # XXX: we use XMPP password for profile password to simplify
         #      if user want to change profile password, he can do it in preferences
-        self.host.bridge.asyncCreateProfile(name, self.password.text, callback=lambda: self.onCreationSuccess(name), errback=self.onCreationFailure)
+        G.host.bridge.asyncCreateProfile(name, self.password.text, callback=lambda: self.onCreationSuccess(name), errback=self.onCreationFailure)
 
 
 class DeleteProfilesScreen(Screen):
 
     def __init__(self, pm):
         self.pm = pm
-        self.host = pm.host
         super(DeleteProfilesScreen, self).__init__(name=u'delete_profiles')
 
     def doDelete(self):
@@ -125,7 +123,7 @@
 
         for profile in to_delete:
             log.info(u"Deleteing profile [{}]".format(profile))
-            self.host.bridge.asyncDeleteProfile(profile, callback=deleteInc, errback=deleteInc)
+            G.host.bridge.asyncDeleteProfile(profile, callback=deleteInc, errback=deleteInc)
 
 
 class ProfilesScreen(Screen):
@@ -133,7 +131,7 @@
 
     def __init__(self, pm):
         self.pm = pm
-        profiles = pm.host.bridge.getProfilesList()
+        profiles = G.host.bridge.getProfilesList()
         profiles.sort()
         self.list_adapter = ProfileListAdapter(pm,
                                                data=profiles,
@@ -148,15 +146,15 @@
 
     def reload(self):
         """Reload profiles list"""
-        profiles = self.pm.host.bridge.getProfilesList()
+        profiles = G.host.bridge.getProfilesList()
         profiles.sort()
         self.list_adapter.data = profiles
 
 
 class ProfileManager(QuickProfileManager, BoxLayout):
 
-    def __init__(self, host, autoconnect=None):
-        QuickProfileManager.__init__(self, host, autoconnect)
+    def __init__(self, autoconnect=None):
+        QuickProfileManager.__init__(self, G.host, autoconnect)
         BoxLayout.__init__(self, orientation="vertical")
         self.screen_manager = ScreenManager()
         self.profiles_screen = ProfilesScreen(self)