Mercurial > libervia-desktop-kivy
comparison cagou/core/profile_manager.py @ 491:203755bbe0fe
massive refactoring from camelCase -> snake_case. See backend commit log for more details
author | Goffi <goffi@goffi.org> |
---|---|
date | Sat, 08 Apr 2023 13:44:32 +0200 |
parents | 3c9ba4a694ef |
children |
comparison
equal
deleted
inserted
replaced
490:962d17c4078c | 491:203755bbe0fe |
---|---|
43 | 43 |
44 def __init__(self, pm): | 44 def __init__(self, pm): |
45 super(NewProfileScreen, self).__init__(name='new_profile') | 45 super(NewProfileScreen, self).__init__(name='new_profile') |
46 self.pm = pm | 46 self.pm = pm |
47 | 47 |
48 def onCreationFailure(self, failure): | 48 def on_creation_failure(self, failure): |
49 msg = [l for l in str(failure).split('\n') if l][-1] | 49 msg = [l for l in str(failure).split('\n') if l][-1] |
50 self.error_msg = str(msg) | 50 self.error_msg = str(msg) |
51 | 51 |
52 def onCreationSuccess(self, profile): | 52 def on_creation_success(self, profile): |
53 self.pm.profiles_screen.reload() | 53 self.pm.profiles_screen.reload() |
54 G.host.bridge.profileStartSession( | 54 G.host.bridge.profile_start_session( |
55 self.password.text, profile, | 55 self.password.text, profile, |
56 callback=lambda __: self._sessionStarted(profile), | 56 callback=lambda __: self._session_started(profile), |
57 errback=self.onCreationFailure) | 57 errback=self.on_creation_failure) |
58 | 58 |
59 def _sessionStarted(self, profile): | 59 def _session_started(self, profile): |
60 jid = self.jid.text.strip() | 60 jid = self.jid.text.strip() |
61 G.host.bridge.setParam("JabberID", jid, "Connection", -1, profile) | 61 G.host.bridge.param_set("JabberID", jid, "Connection", -1, profile) |
62 G.host.bridge.setParam("Password", self.password.text, "Connection", -1, profile) | 62 G.host.bridge.param_set("Password", self.password.text, "Connection", -1, profile) |
63 self.pm.screen_manager.transition.direction = 'right' | 63 self.pm.screen_manager.transition.direction = 'right' |
64 self.pm.screen_manager.current = 'profiles' | 64 self.pm.screen_manager.current = 'profiles' |
65 | 65 |
66 def doCreate(self): | 66 def doCreate(self): |
67 name = self.profile_name.text.strip() | 67 name = self.profile_name.text.strip() |
68 # XXX: we use XMPP password for profile password to simplify | 68 # XXX: we use XMPP password for profile password to simplify |
69 # if user want to change profile password, he can do it in preferences | 69 # if user want to change profile password, he can do it in preferences |
70 G.host.bridge.profileCreate( | 70 G.host.bridge.profile_create( |
71 name, self.password.text, '', | 71 name, self.password.text, '', |
72 callback=lambda: self.onCreationSuccess(name), | 72 callback=lambda: self.on_creation_success(name), |
73 errback=self.onCreationFailure) | 73 errback=self.on_creation_failure) |
74 | 74 |
75 | 75 |
76 class DeleteProfilesScreen(Screen): | 76 class DeleteProfilesScreen(Screen): |
77 | 77 |
78 def __init__(self, pm): | 78 def __init__(self, pm): |
79 self.pm = pm | 79 self.pm = pm |
80 super(DeleteProfilesScreen, self).__init__(name='delete_profiles') | 80 super(DeleteProfilesScreen, self).__init__(name='delete_profiles') |
81 | 81 |
82 def doDelete(self): | 82 def do_delete(self): |
83 """This method will delete *ALL* selected profiles""" | 83 """This method will delete *ALL* selected profiles""" |
84 to_delete = self.pm.getProfiles() | 84 to_delete = self.pm.get_profiles() |
85 deleted = [0] | 85 deleted = [0] |
86 | 86 |
87 def deleteInc(): | 87 def delete_inc(): |
88 deleted[0] += 1 | 88 deleted[0] += 1 |
89 if deleted[0] == len(to_delete): | 89 if deleted[0] == len(to_delete): |
90 self.pm.profiles_screen.reload() | 90 self.pm.profiles_screen.reload() |
91 self.pm.screen_manager.transition.direction = 'right' | 91 self.pm.screen_manager.transition.direction = 'right' |
92 self.pm.screen_manager.current = 'profiles' | 92 self.pm.screen_manager.current = 'profiles' |
93 | 93 |
94 for profile in to_delete: | 94 for profile in to_delete: |
95 log.info("Deleteing profile [{}]".format(profile)) | 95 log.info("Deleteing profile [{}]".format(profile)) |
96 G.host.bridge.asyncDeleteProfile( | 96 G.host.bridge.profile_delete_async( |
97 profile, callback=deleteInc, errback=deleteInc) | 97 profile, callback=delete_inc, errback=delete_inc) |
98 | 98 |
99 | 99 |
100 class ProfilesScreen(Screen): | 100 class ProfilesScreen(Screen): |
101 layout = properties.ObjectProperty(None) | 101 layout = properties.ObjectProperty(None) |
102 profiles = properties.ListProperty() | 102 profiles = properties.ListProperty() |
104 def __init__(self, pm): | 104 def __init__(self, pm): |
105 self.pm = pm | 105 self.pm = pm |
106 super(ProfilesScreen, self).__init__(name='profiles') | 106 super(ProfilesScreen, self).__init__(name='profiles') |
107 self.reload() | 107 self.reload() |
108 | 108 |
109 def _profilesListGetCb(self, profiles): | 109 def _profiles_list_get_cb(self, profiles): |
110 profiles.sort() | 110 profiles.sort() |
111 self.profiles = profiles | 111 self.profiles = profiles |
112 for idx, profile in enumerate(profiles): | 112 for idx, profile in enumerate(profiles): |
113 item = ProfileItem(ps=self, index=idx, text=profile, group='profiles') | 113 item = ProfileItem(ps=self, index=idx, text=profile, group='profiles') |
114 self.layout.add_widget(item) | 114 self.layout.add_widget(item) |
119 'height': sp(40)} | 119 'height': sp(40)} |
120 | 120 |
121 def reload(self): | 121 def reload(self): |
122 """Reload profiles list""" | 122 """Reload profiles list""" |
123 self.layout.clear_widgets() | 123 self.layout.clear_widgets() |
124 G.host.bridge.profilesListGet(callback=self._profilesListGetCb) | 124 G.host.bridge.profiles_list_get(callback=self._profiles_list_get_cb) |
125 | 125 |
126 | 126 |
127 class ProfileManager(QuickProfileManager, BoxLayout): | 127 class ProfileManager(QuickProfileManager, BoxLayout): |
128 selected = properties.ObjectProperty(None) | 128 selected = properties.ObjectProperty(None) |
129 | 129 |
139 self.screen_manager.add_widget(self.xmlui_screen) | 139 self.screen_manager.add_widget(self.xmlui_screen) |
140 self.screen_manager.add_widget(self.new_profile_screen) | 140 self.screen_manager.add_widget(self.new_profile_screen) |
141 self.screen_manager.add_widget(self.delete_profiles_screen) | 141 self.screen_manager.add_widget(self.delete_profiles_screen) |
142 self.add_widget(self.screen_manager) | 142 self.add_widget(self.screen_manager) |
143 | 143 |
144 def closeUI(self, xmlui, reason=None): | 144 def close_ui(self, xmlui, reason=None): |
145 self.screen_manager.transition.direction = 'right' | 145 self.screen_manager.transition.direction = 'right' |
146 self.screen_manager.current = 'profiles' | 146 self.screen_manager.current = 'profiles' |
147 | 147 |
148 def showUI(self, xmlui): | 148 def show_ui(self, xmlui): |
149 xmlui.setCloseCb(self.closeUI) | 149 xmlui.set_close_cb(self.close_ui) |
150 if xmlui.type == 'popup': | 150 if xmlui.type == 'popup': |
151 xmlui.bind(on_touch_up=lambda obj, value: self.closeUI(xmlui)) | 151 xmlui.bind(on_touch_up=lambda obj, value: self.close_ui(xmlui)) |
152 self.xmlui_screen.clear_widgets() | 152 self.xmlui_screen.clear_widgets() |
153 self.xmlui_screen.add_widget(xmlui) | 153 self.xmlui_screen.add_widget(xmlui) |
154 self.screen_manager.transition.direction = 'left' | 154 self.screen_manager.transition.direction = 'left' |
155 self.screen_manager.current = 'xmlui' | 155 self.screen_manager.current = 'xmlui' |
156 | 156 |
157 def selectProfile(self, profile_item): | 157 def select_profile(self, profile_item): |
158 if not profile_item.selected: | 158 if not profile_item.selected: |
159 return | 159 return |
160 def authenticate_cb(data, cb_id, profile): | 160 def authenticate_cb(data, cb_id, profile): |
161 if not C.bool(data.pop('validated', C.BOOL_FALSE)): | 161 if not C.bool(data.pop('validated', C.BOOL_FALSE)): |
162 # profile didn't validate, we unselect it | 162 # profile didn't validate, we unselect it |
164 self.selected = '' | 164 self.selected = '' |
165 else: | 165 else: |
166 # state may have been modified so we need to be sure it's down | 166 # state may have been modified so we need to be sure it's down |
167 profile_item.state = 'down' | 167 profile_item.state = 'down' |
168 self.selected = profile_item | 168 self.selected = profile_item |
169 G.host.actionManager(data, callback=authenticate_cb, ui_show_cb=self.showUI, | 169 G.host.action_manager(data, callback=authenticate_cb, ui_show_cb=self.show_ui, |
170 profile=profile) | 170 profile=profile) |
171 | 171 |
172 G.host.launchAction(C.AUTHENTICATE_PROFILE_ID, callback=authenticate_cb, | 172 G.host.action_launch(C.AUTHENTICATE_PROFILE_ID, callback=authenticate_cb, |
173 profile=profile_item.text) | 173 profile=profile_item.text) |
174 | 174 |
175 def getProfiles(self): | 175 def get_profiles(self): |
176 # for now we restrict to a single profile in Cagou | 176 # for now we restrict to a single profile in Cagou |
177 # TODO: handle multi-profiles | 177 # TODO: handle multi-profiles |
178 return [self.selected.text] if self.selected else [] | 178 return [self.selected.text] if self.selected else [] |