annotate cagou/core/profile_manager.py @ 409:2caea63ae2ab

chat: show attachments as clickable icons
author Goffi <goffi@goffi.org>
date Wed, 19 Feb 2020 09:49:21 +0100
parents 1da3c379205b
children ff5516adc1f5
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
379
1da3c379205b fixed shebangs
Goffi <goffi@goffi.org>
parents: 378
diff changeset
1 #!/usr/bin/env python3
1da3c379205b fixed shebangs
Goffi <goffi@goffi.org>
parents: 378
diff changeset
2
0
160cc95ad7ea initial commit:
Goffi <goffi@goffi.org>
parents:
diff changeset
3
160cc95ad7ea initial commit:
Goffi <goffi@goffi.org>
parents:
diff changeset
4 # Cagou: desktop/mobile frontend for Salut à Toi XMPP client
378
4d660b252487 dates update
Goffi <goffi@goffi.org>
parents: 312
diff changeset
5 # Copyright (C) 2016-2020 Jérôme Poisson (goffi@goffi.org)
0
160cc95ad7ea initial commit:
Goffi <goffi@goffi.org>
parents:
diff changeset
6
160cc95ad7ea initial commit:
Goffi <goffi@goffi.org>
parents:
diff changeset
7 # This program is free software: you can redistribute it and/or modify
160cc95ad7ea initial commit:
Goffi <goffi@goffi.org>
parents:
diff changeset
8 # it under the terms of the GNU Affero General Public License as published by
160cc95ad7ea initial commit:
Goffi <goffi@goffi.org>
parents:
diff changeset
9 # the Free Software Foundation, either version 3 of the License, or
160cc95ad7ea initial commit:
Goffi <goffi@goffi.org>
parents:
diff changeset
10 # (at your option) any later version.
160cc95ad7ea initial commit:
Goffi <goffi@goffi.org>
parents:
diff changeset
11
160cc95ad7ea initial commit:
Goffi <goffi@goffi.org>
parents:
diff changeset
12 # This program is distributed in the hope that it will be useful,
160cc95ad7ea initial commit:
Goffi <goffi@goffi.org>
parents:
diff changeset
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of
160cc95ad7ea initial commit:
Goffi <goffi@goffi.org>
parents:
diff changeset
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
160cc95ad7ea initial commit:
Goffi <goffi@goffi.org>
parents:
diff changeset
15 # GNU Affero General Public License for more details.
160cc95ad7ea initial commit:
Goffi <goffi@goffi.org>
parents:
diff changeset
16
160cc95ad7ea initial commit:
Goffi <goffi@goffi.org>
parents:
diff changeset
17 # You should have received a copy of the GNU Affero General Public License
160cc95ad7ea initial commit:
Goffi <goffi@goffi.org>
parents:
diff changeset
18 # along with this program. If not, see <http://www.gnu.org/licenses/>.
160cc95ad7ea initial commit:
Goffi <goffi@goffi.org>
parents:
diff changeset
19
160cc95ad7ea initial commit:
Goffi <goffi@goffi.org>
parents:
diff changeset
20
2
8f9ed634a5eb Profile manager: profile(s) deletion is handled
Goffi <goffi@goffi.org>
parents: 1
diff changeset
21 from sat.core import log as logging
8f9ed634a5eb Profile manager: profile(s) deletion is handled
Goffi <goffi@goffi.org>
parents: 1
diff changeset
22 log = logging.getLogger(__name__)
56
817a45e6d7e3 core (profile_manager): fixed bad import
Goffi <goffi@goffi.org>
parents: 16
diff changeset
23 from .constants import Const as C
0
160cc95ad7ea initial commit:
Goffi <goffi@goffi.org>
parents:
diff changeset
24 from sat_frontends.quick_frontend.quick_profile_manager import QuickProfileManager
160cc95ad7ea initial commit:
Goffi <goffi@goffi.org>
parents:
diff changeset
25 from kivy.uix.boxlayout import BoxLayout
270
89ba66464329 profile manager: don't use anymore deprecated ListView + use dp() for sizes of buttons instead of relative size.
Goffi <goffi@goffi.org>
parents: 139
diff changeset
26 from kivy.uix.togglebutton import ToggleButton
0
160cc95ad7ea initial commit:
Goffi <goffi@goffi.org>
parents:
diff changeset
27 from kivy.uix.screenmanager import ScreenManager, Screen
62
1922506846be design fixes:
Goffi <goffi@goffi.org>
parents: 56
diff changeset
28 from kivy.metrics import sp
1
189b76859110 Profile manager: new profile creation is handled
Goffi <goffi@goffi.org>
parents: 0
diff changeset
29 from kivy import properties
16
ba14b596b90e host can now be get as a global value:
Goffi <goffi@goffi.org>
parents: 15
diff changeset
30 from cagou import G
0
160cc95ad7ea initial commit:
Goffi <goffi@goffi.org>
parents:
diff changeset
31
160cc95ad7ea initial commit:
Goffi <goffi@goffi.org>
parents:
diff changeset
32
270
89ba66464329 profile manager: don't use anymore deprecated ListView + use dp() for sizes of buttons instead of relative size.
Goffi <goffi@goffi.org>
parents: 139
diff changeset
33 class ProfileItem(ToggleButton):
89ba66464329 profile manager: don't use anymore deprecated ListView + use dp() for sizes of buttons instead of relative size.
Goffi <goffi@goffi.org>
parents: 139
diff changeset
34 ps = properties.ObjectProperty()
89ba66464329 profile manager: don't use anymore deprecated ListView + use dp() for sizes of buttons instead of relative size.
Goffi <goffi@goffi.org>
parents: 139
diff changeset
35 index = properties.NumericProperty(0)
0
160cc95ad7ea initial commit:
Goffi <goffi@goffi.org>
parents:
diff changeset
36
160cc95ad7ea initial commit:
Goffi <goffi@goffi.org>
parents:
diff changeset
37
1
189b76859110 Profile manager: new profile creation is handled
Goffi <goffi@goffi.org>
parents: 0
diff changeset
38 class NewProfileScreen(Screen):
189b76859110 Profile manager: new profile creation is handled
Goffi <goffi@goffi.org>
parents: 0
diff changeset
39 profile_name = properties.ObjectProperty(None)
189b76859110 Profile manager: new profile creation is handled
Goffi <goffi@goffi.org>
parents: 0
diff changeset
40 jid = properties.ObjectProperty(None)
189b76859110 Profile manager: new profile creation is handled
Goffi <goffi@goffi.org>
parents: 0
diff changeset
41 password = properties.ObjectProperty(None)
189b76859110 Profile manager: new profile creation is handled
Goffi <goffi@goffi.org>
parents: 0
diff changeset
42 error_msg = properties.StringProperty('')
0
160cc95ad7ea initial commit:
Goffi <goffi@goffi.org>
parents:
diff changeset
43
160cc95ad7ea initial commit:
Goffi <goffi@goffi.org>
parents:
diff changeset
44 def __init__(self, pm):
312
772c170b47a9 Python3 port:
Goffi <goffi@goffi.org>
parents: 305
diff changeset
45 super(NewProfileScreen, self).__init__(name='new_profile')
1
189b76859110 Profile manager: new profile creation is handled
Goffi <goffi@goffi.org>
parents: 0
diff changeset
46 self.pm = pm
189b76859110 Profile manager: new profile creation is handled
Goffi <goffi@goffi.org>
parents: 0
diff changeset
47
189b76859110 Profile manager: new profile creation is handled
Goffi <goffi@goffi.org>
parents: 0
diff changeset
48 def onCreationFailure(self, failure):
312
772c170b47a9 Python3 port:
Goffi <goffi@goffi.org>
parents: 305
diff changeset
49 msg = [l for l in str(failure).split('\n') if l][-1]
772c170b47a9 Python3 port:
Goffi <goffi@goffi.org>
parents: 305
diff changeset
50 self.error_msg = str(msg)
1
189b76859110 Profile manager: new profile creation is handled
Goffi <goffi@goffi.org>
parents: 0
diff changeset
51
189b76859110 Profile manager: new profile creation is handled
Goffi <goffi@goffi.org>
parents: 0
diff changeset
52 def onCreationSuccess(self, profile):
189b76859110 Profile manager: new profile creation is handled
Goffi <goffi@goffi.org>
parents: 0
diff changeset
53 self.pm.profiles_screen.reload()
270
89ba66464329 profile manager: don't use anymore deprecated ListView + use dp() for sizes of buttons instead of relative size.
Goffi <goffi@goffi.org>
parents: 139
diff changeset
54 G.host.bridge.profileStartSession(
89ba66464329 profile manager: don't use anymore deprecated ListView + use dp() for sizes of buttons instead of relative size.
Goffi <goffi@goffi.org>
parents: 139
diff changeset
55 self.password.text, profile,
284
ca4daced4638 misc: replaced "dummy" by "__"
Goffi <goffi@goffi.org>
parents: 282
diff changeset
56 callback=lambda __: self._sessionStarted(profile),
270
89ba66464329 profile manager: don't use anymore deprecated ListView + use dp() for sizes of buttons instead of relative size.
Goffi <goffi@goffi.org>
parents: 139
diff changeset
57 errback=self.onCreationFailure)
1
189b76859110 Profile manager: new profile creation is handled
Goffi <goffi@goffi.org>
parents: 0
diff changeset
58
189b76859110 Profile manager: new profile creation is handled
Goffi <goffi@goffi.org>
parents: 0
diff changeset
59 def _sessionStarted(self, profile):
189b76859110 Profile manager: new profile creation is handled
Goffi <goffi@goffi.org>
parents: 0
diff changeset
60 jid = self.jid.text.strip()
16
ba14b596b90e host can now be get as a global value:
Goffi <goffi@goffi.org>
parents: 15
diff changeset
61 G.host.bridge.setParam("JabberID", jid, "Connection", -1, profile)
ba14b596b90e host can now be get as a global value:
Goffi <goffi@goffi.org>
parents: 15
diff changeset
62 G.host.bridge.setParam("Password", self.password.text, "Connection", -1, profile)
1
189b76859110 Profile manager: new profile creation is handled
Goffi <goffi@goffi.org>
parents: 0
diff changeset
63 self.pm.screen_manager.transition.direction = 'right'
189b76859110 Profile manager: new profile creation is handled
Goffi <goffi@goffi.org>
parents: 0
diff changeset
64 self.pm.screen_manager.current = 'profiles'
189b76859110 Profile manager: new profile creation is handled
Goffi <goffi@goffi.org>
parents: 0
diff changeset
65
189b76859110 Profile manager: new profile creation is handled
Goffi <goffi@goffi.org>
parents: 0
diff changeset
66 def doCreate(self):
189b76859110 Profile manager: new profile creation is handled
Goffi <goffi@goffi.org>
parents: 0
diff changeset
67 name = self.profile_name.text.strip()
189b76859110 Profile manager: new profile creation is handled
Goffi <goffi@goffi.org>
parents: 0
diff changeset
68 # XXX: we use XMPP password for profile password to simplify
189b76859110 Profile manager: new profile creation is handled
Goffi <goffi@goffi.org>
parents: 0
diff changeset
69 # if user want to change profile password, he can do it in preferences
270
89ba66464329 profile manager: don't use anymore deprecated ListView + use dp() for sizes of buttons instead of relative size.
Goffi <goffi@goffi.org>
parents: 139
diff changeset
70 G.host.bridge.profileCreate(
312
772c170b47a9 Python3 port:
Goffi <goffi@goffi.org>
parents: 305
diff changeset
71 name, self.password.text, '',
270
89ba66464329 profile manager: don't use anymore deprecated ListView + use dp() for sizes of buttons instead of relative size.
Goffi <goffi@goffi.org>
parents: 139
diff changeset
72 callback=lambda: self.onCreationSuccess(name),
89ba66464329 profile manager: don't use anymore deprecated ListView + use dp() for sizes of buttons instead of relative size.
Goffi <goffi@goffi.org>
parents: 139
diff changeset
73 errback=self.onCreationFailure)
1
189b76859110 Profile manager: new profile creation is handled
Goffi <goffi@goffi.org>
parents: 0
diff changeset
74
189b76859110 Profile manager: new profile creation is handled
Goffi <goffi@goffi.org>
parents: 0
diff changeset
75
2
8f9ed634a5eb Profile manager: profile(s) deletion is handled
Goffi <goffi@goffi.org>
parents: 1
diff changeset
76 class DeleteProfilesScreen(Screen):
8f9ed634a5eb Profile manager: profile(s) deletion is handled
Goffi <goffi@goffi.org>
parents: 1
diff changeset
77
8f9ed634a5eb Profile manager: profile(s) deletion is handled
Goffi <goffi@goffi.org>
parents: 1
diff changeset
78 def __init__(self, pm):
8f9ed634a5eb Profile manager: profile(s) deletion is handled
Goffi <goffi@goffi.org>
parents: 1
diff changeset
79 self.pm = pm
312
772c170b47a9 Python3 port:
Goffi <goffi@goffi.org>
parents: 305
diff changeset
80 super(DeleteProfilesScreen, self).__init__(name='delete_profiles')
2
8f9ed634a5eb Profile manager: profile(s) deletion is handled
Goffi <goffi@goffi.org>
parents: 1
diff changeset
81
8f9ed634a5eb Profile manager: profile(s) deletion is handled
Goffi <goffi@goffi.org>
parents: 1
diff changeset
82 def doDelete(self):
8f9ed634a5eb Profile manager: profile(s) deletion is handled
Goffi <goffi@goffi.org>
parents: 1
diff changeset
83 """This method will delete *ALL* selected profiles"""
5
33b619506832 profile manger: launch plug process when "Connect" button is pressed (full plugging is not working yet)
Goffi <goffi@goffi.org>
parents: 4
diff changeset
84 to_delete = self.pm.getProfiles()
2
8f9ed634a5eb Profile manager: profile(s) deletion is handled
Goffi <goffi@goffi.org>
parents: 1
diff changeset
85 deleted = [0]
8f9ed634a5eb Profile manager: profile(s) deletion is handled
Goffi <goffi@goffi.org>
parents: 1
diff changeset
86
8f9ed634a5eb Profile manager: profile(s) deletion is handled
Goffi <goffi@goffi.org>
parents: 1
diff changeset
87 def deleteInc():
8f9ed634a5eb Profile manager: profile(s) deletion is handled
Goffi <goffi@goffi.org>
parents: 1
diff changeset
88 deleted[0] += 1
5
33b619506832 profile manger: launch plug process when "Connect" button is pressed (full plugging is not working yet)
Goffi <goffi@goffi.org>
parents: 4
diff changeset
89 if deleted[0] == len(to_delete):
2
8f9ed634a5eb Profile manager: profile(s) deletion is handled
Goffi <goffi@goffi.org>
parents: 1
diff changeset
90 self.pm.profiles_screen.reload()
8f9ed634a5eb Profile manager: profile(s) deletion is handled
Goffi <goffi@goffi.org>
parents: 1
diff changeset
91 self.pm.screen_manager.transition.direction = 'right'
8f9ed634a5eb Profile manager: profile(s) deletion is handled
Goffi <goffi@goffi.org>
parents: 1
diff changeset
92 self.pm.screen_manager.current = 'profiles'
8f9ed634a5eb Profile manager: profile(s) deletion is handled
Goffi <goffi@goffi.org>
parents: 1
diff changeset
93
5
33b619506832 profile manger: launch plug process when "Connect" button is pressed (full plugging is not working yet)
Goffi <goffi@goffi.org>
parents: 4
diff changeset
94 for profile in to_delete:
312
772c170b47a9 Python3 port:
Goffi <goffi@goffi.org>
parents: 305
diff changeset
95 log.info("Deleteing profile [{}]".format(profile))
270
89ba66464329 profile manager: don't use anymore deprecated ListView + use dp() for sizes of buttons instead of relative size.
Goffi <goffi@goffi.org>
parents: 139
diff changeset
96 G.host.bridge.asyncDeleteProfile(
89ba66464329 profile manager: don't use anymore deprecated ListView + use dp() for sizes of buttons instead of relative size.
Goffi <goffi@goffi.org>
parents: 139
diff changeset
97 profile, callback=deleteInc, errback=deleteInc)
2
8f9ed634a5eb Profile manager: profile(s) deletion is handled
Goffi <goffi@goffi.org>
parents: 1
diff changeset
98
8f9ed634a5eb Profile manager: profile(s) deletion is handled
Goffi <goffi@goffi.org>
parents: 1
diff changeset
99
1
189b76859110 Profile manager: new profile creation is handled
Goffi <goffi@goffi.org>
parents: 0
diff changeset
100 class ProfilesScreen(Screen):
189b76859110 Profile manager: new profile creation is handled
Goffi <goffi@goffi.org>
parents: 0
diff changeset
101 layout = properties.ObjectProperty(None)
270
89ba66464329 profile manager: don't use anymore deprecated ListView + use dp() for sizes of buttons instead of relative size.
Goffi <goffi@goffi.org>
parents: 139
diff changeset
102 profiles = properties.ListProperty()
1
189b76859110 Profile manager: new profile creation is handled
Goffi <goffi@goffi.org>
parents: 0
diff changeset
103
189b76859110 Profile manager: new profile creation is handled
Goffi <goffi@goffi.org>
parents: 0
diff changeset
104 def __init__(self, pm):
189b76859110 Profile manager: new profile creation is handled
Goffi <goffi@goffi.org>
parents: 0
diff changeset
105 self.pm = pm
312
772c170b47a9 Python3 port:
Goffi <goffi@goffi.org>
parents: 305
diff changeset
106 super(ProfilesScreen, self).__init__(name='profiles')
63
af4f986d86f0 core: pb bridge implementation:
Goffi <goffi@goffi.org>
parents: 62
diff changeset
107 self.reload()
af4f986d86f0 core: pb bridge implementation:
Goffi <goffi@goffi.org>
parents: 62
diff changeset
108
124
7f7f3b8eb154 profile manager: fixed profilesListGet bridge call following name change in bridge
Goffi <goffi@goffi.org>
parents: 63
diff changeset
109 def _profilesListGetCb(self, profiles):
63
af4f986d86f0 core: pb bridge implementation:
Goffi <goffi@goffi.org>
parents: 62
diff changeset
110 profiles.sort()
270
89ba66464329 profile manager: don't use anymore deprecated ListView + use dp() for sizes of buttons instead of relative size.
Goffi <goffi@goffi.org>
parents: 139
diff changeset
111 self.profiles = profiles
89ba66464329 profile manager: don't use anymore deprecated ListView + use dp() for sizes of buttons instead of relative size.
Goffi <goffi@goffi.org>
parents: 139
diff changeset
112 for idx, profile in enumerate(profiles):
89ba66464329 profile manager: don't use anymore deprecated ListView + use dp() for sizes of buttons instead of relative size.
Goffi <goffi@goffi.org>
parents: 139
diff changeset
113 item = ProfileItem(ps=self, index=idx, text=profile, group='profiles')
89ba66464329 profile manager: don't use anymore deprecated ListView + use dp() for sizes of buttons instead of relative size.
Goffi <goffi@goffi.org>
parents: 139
diff changeset
114 self.layout.add_widget(item)
0
160cc95ad7ea initial commit:
Goffi <goffi@goffi.org>
parents:
diff changeset
115
62
1922506846be design fixes:
Goffi <goffi@goffi.org>
parents: 56
diff changeset
116 def converter(self, row_idx, obj):
1922506846be design fixes:
Goffi <goffi@goffi.org>
parents: 56
diff changeset
117 return {'text': obj,
1922506846be design fixes:
Goffi <goffi@goffi.org>
parents: 56
diff changeset
118 'size_hint_y': None,
1922506846be design fixes:
Goffi <goffi@goffi.org>
parents: 56
diff changeset
119 'height': sp(40)}
1922506846be design fixes:
Goffi <goffi@goffi.org>
parents: 56
diff changeset
120
1
189b76859110 Profile manager: new profile creation is handled
Goffi <goffi@goffi.org>
parents: 0
diff changeset
121 def reload(self):
189b76859110 Profile manager: new profile creation is handled
Goffi <goffi@goffi.org>
parents: 0
diff changeset
122 """Reload profiles list"""
270
89ba66464329 profile manager: don't use anymore deprecated ListView + use dp() for sizes of buttons instead of relative size.
Goffi <goffi@goffi.org>
parents: 139
diff changeset
123 self.layout.clear_widgets()
124
7f7f3b8eb154 profile manager: fixed profilesListGet bridge call following name change in bridge
Goffi <goffi@goffi.org>
parents: 63
diff changeset
124 G.host.bridge.profilesListGet(callback=self._profilesListGetCb)
1
189b76859110 Profile manager: new profile creation is handled
Goffi <goffi@goffi.org>
parents: 0
diff changeset
125
0
160cc95ad7ea initial commit:
Goffi <goffi@goffi.org>
parents:
diff changeset
126
160cc95ad7ea initial commit:
Goffi <goffi@goffi.org>
parents:
diff changeset
127 class ProfileManager(QuickProfileManager, BoxLayout):
270
89ba66464329 profile manager: don't use anymore deprecated ListView + use dp() for sizes of buttons instead of relative size.
Goffi <goffi@goffi.org>
parents: 139
diff changeset
128 selected = properties.ObjectProperty(None)
0
160cc95ad7ea initial commit:
Goffi <goffi@goffi.org>
parents:
diff changeset
129
16
ba14b596b90e host can now be get as a global value:
Goffi <goffi@goffi.org>
parents: 15
diff changeset
130 def __init__(self, autoconnect=None):
ba14b596b90e host can now be get as a global value:
Goffi <goffi@goffi.org>
parents: 15
diff changeset
131 QuickProfileManager.__init__(self, G.host, autoconnect)
0
160cc95ad7ea initial commit:
Goffi <goffi@goffi.org>
parents:
diff changeset
132 BoxLayout.__init__(self, orientation="vertical")
160cc95ad7ea initial commit:
Goffi <goffi@goffi.org>
parents:
diff changeset
133 self.screen_manager = ScreenManager()
1
189b76859110 Profile manager: new profile creation is handled
Goffi <goffi@goffi.org>
parents: 0
diff changeset
134 self.profiles_screen = ProfilesScreen(self)
189b76859110 Profile manager: new profile creation is handled
Goffi <goffi@goffi.org>
parents: 0
diff changeset
135 self.new_profile_screen = NewProfileScreen(self)
2
8f9ed634a5eb Profile manager: profile(s) deletion is handled
Goffi <goffi@goffi.org>
parents: 1
diff changeset
136 self.delete_profiles_screen = DeleteProfilesScreen(self)
312
772c170b47a9 Python3 port:
Goffi <goffi@goffi.org>
parents: 305
diff changeset
137 self.xmlui_screen = Screen(name='xmlui')
0
160cc95ad7ea initial commit:
Goffi <goffi@goffi.org>
parents:
diff changeset
138 self.screen_manager.add_widget(self.profiles_screen)
160cc95ad7ea initial commit:
Goffi <goffi@goffi.org>
parents:
diff changeset
139 self.screen_manager.add_widget(self.xmlui_screen)
1
189b76859110 Profile manager: new profile creation is handled
Goffi <goffi@goffi.org>
parents: 0
diff changeset
140 self.screen_manager.add_widget(self.new_profile_screen)
2
8f9ed634a5eb Profile manager: profile(s) deletion is handled
Goffi <goffi@goffi.org>
parents: 1
diff changeset
141 self.screen_manager.add_widget(self.delete_profiles_screen)
0
160cc95ad7ea initial commit:
Goffi <goffi@goffi.org>
parents:
diff changeset
142 self.add_widget(self.screen_manager)
270
89ba66464329 profile manager: don't use anymore deprecated ListView + use dp() for sizes of buttons instead of relative size.
Goffi <goffi@goffi.org>
parents: 139
diff changeset
143 self.bind(selected=self.onProfileSelect)
89ba66464329 profile manager: don't use anymore deprecated ListView + use dp() for sizes of buttons instead of relative size.
Goffi <goffi@goffi.org>
parents: 139
diff changeset
144
305
b2727877bad4 remote: fixed workflow and size for XMLUI panel used with Ad-Hoc commands:
Goffi <goffi@goffi.org>
parents: 284
diff changeset
145 def closeUI(self, xmlui, reason=None):
270
89ba66464329 profile manager: don't use anymore deprecated ListView + use dp() for sizes of buttons instead of relative size.
Goffi <goffi@goffi.org>
parents: 139
diff changeset
146 self.screen_manager.transition.direction = 'right'
89ba66464329 profile manager: don't use anymore deprecated ListView + use dp() for sizes of buttons instead of relative size.
Goffi <goffi@goffi.org>
parents: 139
diff changeset
147 self.screen_manager.current = 'profiles'
89ba66464329 profile manager: don't use anymore deprecated ListView + use dp() for sizes of buttons instead of relative size.
Goffi <goffi@goffi.org>
parents: 139
diff changeset
148
89ba66464329 profile manager: don't use anymore deprecated ListView + use dp() for sizes of buttons instead of relative size.
Goffi <goffi@goffi.org>
parents: 139
diff changeset
149 def showUI(self, xmlui):
89ba66464329 profile manager: don't use anymore deprecated ListView + use dp() for sizes of buttons instead of relative size.
Goffi <goffi@goffi.org>
parents: 139
diff changeset
150 xmlui.setCloseCb(self.closeUI)
89ba66464329 profile manager: don't use anymore deprecated ListView + use dp() for sizes of buttons instead of relative size.
Goffi <goffi@goffi.org>
parents: 139
diff changeset
151 if xmlui.type == 'popup':
89ba66464329 profile manager: don't use anymore deprecated ListView + use dp() for sizes of buttons instead of relative size.
Goffi <goffi@goffi.org>
parents: 139
diff changeset
152 xmlui.bind(on_touch_up=lambda obj, value: self.closeUI(xmlui))
89ba66464329 profile manager: don't use anymore deprecated ListView + use dp() for sizes of buttons instead of relative size.
Goffi <goffi@goffi.org>
parents: 139
diff changeset
153 self.xmlui_screen.clear_widgets()
89ba66464329 profile manager: don't use anymore deprecated ListView + use dp() for sizes of buttons instead of relative size.
Goffi <goffi@goffi.org>
parents: 139
diff changeset
154 self.xmlui_screen.add_widget(xmlui)
89ba66464329 profile manager: don't use anymore deprecated ListView + use dp() for sizes of buttons instead of relative size.
Goffi <goffi@goffi.org>
parents: 139
diff changeset
155 self.screen_manager.transition.direction = 'left'
89ba66464329 profile manager: don't use anymore deprecated ListView + use dp() for sizes of buttons instead of relative size.
Goffi <goffi@goffi.org>
parents: 139
diff changeset
156 self.screen_manager.current = 'xmlui'
89ba66464329 profile manager: don't use anymore deprecated ListView + use dp() for sizes of buttons instead of relative size.
Goffi <goffi@goffi.org>
parents: 139
diff changeset
157
89ba66464329 profile manager: don't use anymore deprecated ListView + use dp() for sizes of buttons instead of relative size.
Goffi <goffi@goffi.org>
parents: 139
diff changeset
158 def onProfileSelect(self, __, selected):
89ba66464329 profile manager: don't use anymore deprecated ListView + use dp() for sizes of buttons instead of relative size.
Goffi <goffi@goffi.org>
parents: 139
diff changeset
159 if not selected:
89ba66464329 profile manager: don't use anymore deprecated ListView + use dp() for sizes of buttons instead of relative size.
Goffi <goffi@goffi.org>
parents: 139
diff changeset
160 return
89ba66464329 profile manager: don't use anymore deprecated ListView + use dp() for sizes of buttons instead of relative size.
Goffi <goffi@goffi.org>
parents: 139
diff changeset
161 def authenticate_cb(data, cb_id, profile):
89ba66464329 profile manager: don't use anymore deprecated ListView + use dp() for sizes of buttons instead of relative size.
Goffi <goffi@goffi.org>
parents: 139
diff changeset
162 if not C.bool(data.pop('validated', C.BOOL_FALSE)):
89ba66464329 profile manager: don't use anymore deprecated ListView + use dp() for sizes of buttons instead of relative size.
Goffi <goffi@goffi.org>
parents: 139
diff changeset
163 # profile didn't validate, we unselect it
89ba66464329 profile manager: don't use anymore deprecated ListView + use dp() for sizes of buttons instead of relative size.
Goffi <goffi@goffi.org>
parents: 139
diff changeset
164 selected.state = 'normal'
89ba66464329 profile manager: don't use anymore deprecated ListView + use dp() for sizes of buttons instead of relative size.
Goffi <goffi@goffi.org>
parents: 139
diff changeset
165 self.selected = ''
89ba66464329 profile manager: don't use anymore deprecated ListView + use dp() for sizes of buttons instead of relative size.
Goffi <goffi@goffi.org>
parents: 139
diff changeset
166 else:
89ba66464329 profile manager: don't use anymore deprecated ListView + use dp() for sizes of buttons instead of relative size.
Goffi <goffi@goffi.org>
parents: 139
diff changeset
167 # state may have been modified so we need to be sure it's down
89ba66464329 profile manager: don't use anymore deprecated ListView + use dp() for sizes of buttons instead of relative size.
Goffi <goffi@goffi.org>
parents: 139
diff changeset
168 selected.state = 'down'
89ba66464329 profile manager: don't use anymore deprecated ListView + use dp() for sizes of buttons instead of relative size.
Goffi <goffi@goffi.org>
parents: 139
diff changeset
169 self.selected = selected
89ba66464329 profile manager: don't use anymore deprecated ListView + use dp() for sizes of buttons instead of relative size.
Goffi <goffi@goffi.org>
parents: 139
diff changeset
170 G.host.actionManager(data, callback=authenticate_cb, ui_show_cb=self.showUI,
89ba66464329 profile manager: don't use anymore deprecated ListView + use dp() for sizes of buttons instead of relative size.
Goffi <goffi@goffi.org>
parents: 139
diff changeset
171 profile=profile)
89ba66464329 profile manager: don't use anymore deprecated ListView + use dp() for sizes of buttons instead of relative size.
Goffi <goffi@goffi.org>
parents: 139
diff changeset
172
89ba66464329 profile manager: don't use anymore deprecated ListView + use dp() for sizes of buttons instead of relative size.
Goffi <goffi@goffi.org>
parents: 139
diff changeset
173 G.host.launchAction(C.AUTHENTICATE_PROFILE_ID, callback=authenticate_cb,
89ba66464329 profile manager: don't use anymore deprecated ListView + use dp() for sizes of buttons instead of relative size.
Goffi <goffi@goffi.org>
parents: 139
diff changeset
174 profile=selected.text)
0
160cc95ad7ea initial commit:
Goffi <goffi@goffi.org>
parents:
diff changeset
175
5
33b619506832 profile manger: launch plug process when "Connect" button is pressed (full plugging is not working yet)
Goffi <goffi@goffi.org>
parents: 4
diff changeset
176 def getProfiles(self):
270
89ba66464329 profile manager: don't use anymore deprecated ListView + use dp() for sizes of buttons instead of relative size.
Goffi <goffi@goffi.org>
parents: 139
diff changeset
177 # for now we restrict to a single profile in Cagou
89ba66464329 profile manager: don't use anymore deprecated ListView + use dp() for sizes of buttons instead of relative size.
Goffi <goffi@goffi.org>
parents: 139
diff changeset
178 # TODO: handle multi-profiles
89ba66464329 profile manager: don't use anymore deprecated ListView + use dp() for sizes of buttons instead of relative size.
Goffi <goffi@goffi.org>
parents: 139
diff changeset
179 return [self.selected.text] if self.selected else []