Mercurial > libervia-backend
annotate frontends/src/primitivus/profile_manager.py @ 1265:e3a9ea76de35 frontends_multi_profiles
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
This refactoring allow primitivus to manage correctly several profiles at once, with various other improvments:
- profile_manager can now plug several profiles at once, requesting password when needed. No more profile plug specific method is used anymore in backend, instead a "validated" key is used in actions
- Primitivus widget are now based on a common "PrimitivusWidget" classe which mainly manage the decoration so far
- all widgets are treated in the same way (contactList, Chat, Progress, etc), no more chat_wins specific behaviour
- widgets are created in a dedicated manager, with facilities to react on new widget creation or other events
- quick_frontend introduce a new QuickWidget class, which aims to be as generic and flexible as possible. It can manage several targets (jids or something else), and several profiles
- each widget class return a Hash according to its target. For example if given a target jid and a profile, a widget class return a hash like (target.bare, profile), the same widget will be used for all resources of the same jid
- better management of CHAT_GROUP mode for Chat widgets
- some code moved from Primitivus to QuickFrontend, the final goal is to have most non backend code in QuickFrontend, and just graphic code in subclasses
- no more (un)escapePrivate/PRIVATE_PREFIX
- contactList improved a lot: entities not in roster and special entities (private MUC conversations) are better managed
- resources can be displayed in Primitivus, and their status messages
- profiles are managed in QuickFrontend with dedicated managers
This is work in progress, other frontends are broken. Urwid SàText need to be updated. Most of features of Primitivus should work as before (or in a better way ;))
author | Goffi <goffi@goffi.org> |
---|---|
date | Wed, 10 Dec 2014 19:00:09 +0100 |
parents | 49d39b619e5d |
children | 7cf32aeeebdb |
rev | line source |
---|---|
112 | 1 #!/usr/bin/python |
2 # -*- coding: utf-8 -*- | |
3 | |
609
84a6e83157c2
fixed licences in docstrings (they are now in comments)
Goffi <goffi@goffi.org>
parents:
587
diff
changeset
|
4 # Primitivus: a SAT frontend |
811 | 5 # Copyright (C) 2009, 2010, 2011, 2012, 2013, 2014 Jérôme Poisson (goffi@goffi.org) |
112 | 6 |
609
84a6e83157c2
fixed licences in docstrings (they are now in comments)
Goffi <goffi@goffi.org>
parents:
587
diff
changeset
|
7 # This program is free software: you can redistribute it and/or modify |
84a6e83157c2
fixed licences in docstrings (they are now in comments)
Goffi <goffi@goffi.org>
parents:
587
diff
changeset
|
8 # it under the terms of the GNU Affero General Public License as published by |
84a6e83157c2
fixed licences in docstrings (they are now in comments)
Goffi <goffi@goffi.org>
parents:
587
diff
changeset
|
9 # the Free Software Foundation, either version 3 of the License, or |
84a6e83157c2
fixed licences in docstrings (they are now in comments)
Goffi <goffi@goffi.org>
parents:
587
diff
changeset
|
10 # (at your option) any later version. |
112 | 11 |
609
84a6e83157c2
fixed licences in docstrings (they are now in comments)
Goffi <goffi@goffi.org>
parents:
587
diff
changeset
|
12 # This program is distributed in the hope that it will be useful, |
84a6e83157c2
fixed licences in docstrings (they are now in comments)
Goffi <goffi@goffi.org>
parents:
587
diff
changeset
|
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of |
84a6e83157c2
fixed licences in docstrings (they are now in comments)
Goffi <goffi@goffi.org>
parents:
587
diff
changeset
|
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
84a6e83157c2
fixed licences in docstrings (they are now in comments)
Goffi <goffi@goffi.org>
parents:
587
diff
changeset
|
15 # GNU Affero General Public License for more details. |
112 | 16 |
609
84a6e83157c2
fixed licences in docstrings (they are now in comments)
Goffi <goffi@goffi.org>
parents:
587
diff
changeset
|
17 # You should have received a copy of the GNU Affero General Public License |
84a6e83157c2
fixed licences in docstrings (they are now in comments)
Goffi <goffi@goffi.org>
parents:
587
diff
changeset
|
18 # along with this program. If not, see <http://www.gnu.org/licenses/>. |
112 | 19 |
771 | 20 from sat.core.i18n import _ |
1265
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1178
diff
changeset
|
21 from sat.core import log as logging |
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1178
diff
changeset
|
22 log = logging.getLogger(__name__) |
1034
5197600a1e13
quick_app, primitivus: update the connection mechanism to ask for non empty profile passwords
souliane <souliane@mailoo.org>
parents:
1019
diff
changeset
|
23 from sat_frontends.primitivus.constants import Const as C |
1265
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1178
diff
changeset
|
24 from sat_frontends.primitivus.keys import action_key_map as a_key |
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1178
diff
changeset
|
25 from urwid_satext import sat_widgets |
112 | 26 import urwid |
1265
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1178
diff
changeset
|
27 |
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1178
diff
changeset
|
28 class ProfileRecord(object): |
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1178
diff
changeset
|
29 |
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1178
diff
changeset
|
30 def __init__(self, profile=None, login=None, password=None): |
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1178
diff
changeset
|
31 self._profile = profile |
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1178
diff
changeset
|
32 self._login = login |
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1178
diff
changeset
|
33 self._password = password |
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1178
diff
changeset
|
34 |
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1178
diff
changeset
|
35 @property |
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1178
diff
changeset
|
36 def profile(self): |
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1178
diff
changeset
|
37 return self._profile |
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1178
diff
changeset
|
38 |
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1178
diff
changeset
|
39 @profile.setter |
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1178
diff
changeset
|
40 def profile(self, value): |
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1178
diff
changeset
|
41 self._profile = value |
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1178
diff
changeset
|
42 # if we change the profile, |
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1178
diff
changeset
|
43 # we must have no login/password until backend give them |
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1178
diff
changeset
|
44 self._login = self._password = None |
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1178
diff
changeset
|
45 |
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1178
diff
changeset
|
46 @property |
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1178
diff
changeset
|
47 def login(self): |
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1178
diff
changeset
|
48 return self._login |
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1178
diff
changeset
|
49 |
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1178
diff
changeset
|
50 @login.setter |
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1178
diff
changeset
|
51 def login(self, value): |
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1178
diff
changeset
|
52 self._login = value |
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1178
diff
changeset
|
53 |
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1178
diff
changeset
|
54 @property |
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1178
diff
changeset
|
55 def password(self): |
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1178
diff
changeset
|
56 return self._password |
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1178
diff
changeset
|
57 |
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1178
diff
changeset
|
58 @password.setter |
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1178
diff
changeset
|
59 def password(self, value): |
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1178
diff
changeset
|
60 self._password = value |
112 | 61 |
62 | |
63 class ProfileManager(urwid.WidgetWrap): | |
1265
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1178
diff
changeset
|
64 """Class with manage profiles creation/deletion/connection""" |
112 | 65 |
1265
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1178
diff
changeset
|
66 def __init__(self, host, autoconnect=None): |
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1178
diff
changeset
|
67 """Create the manager |
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1178
diff
changeset
|
68 |
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1178
diff
changeset
|
69 @param host: %(doc_host)s |
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1178
diff
changeset
|
70 @param autoconnect(iterable): list of profiles to connect automatically |
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1178
diff
changeset
|
71 """ |
112 | 72 self.host = host |
1265
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1178
diff
changeset
|
73 self._autoconnect = bool(autoconnect) |
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1178
diff
changeset
|
74 self.current = ProfileRecord() |
112 | 75 profiles = self.host.bridge.getProfilesList() |
113 | 76 profiles.sort() |
587
952322b1d490
Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
572
diff
changeset
|
77 |
113 | 78 #login & password box must be created before list because of onProfileChange |
1265
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1178
diff
changeset
|
79 self.login_wid = sat_widgets.AdvancedEdit(_('Login:'), align='center') |
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1178
diff
changeset
|
80 self.pass_wid = sat_widgets.Password(_('Password:'), align='center') |
587
952322b1d490
Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
572
diff
changeset
|
81 |
1265
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1178
diff
changeset
|
82 style = ['no_first_select'] |
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1178
diff
changeset
|
83 self.list_profile = sat_widgets.List(profiles, style=style, align='center', on_change=self.onProfileChange) |
113 | 84 |
85 #new & delete buttons | |
86 buttons = [urwid.Button(_("New"), self.onNewProfile), | |
87 urwid.Button(_("Delete"), self.onDeleteProfile)] | |
88 buttons_flow = urwid.GridFlow(buttons, max([len(button.get_label()) for button in buttons])+4, 1, 1, 'center') | |
89 | |
90 #second part: login information: | |
91 divider = urwid.Divider('-') | |
92 | |
93 #connect button | |
1265
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1178
diff
changeset
|
94 connect_button = sat_widgets.CustomButton(_("Connect"), self.onConnectProfiles, align='center') |
113 | 95 |
96 #we now build the widget | |
1265
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1178
diff
changeset
|
97 list_walker = urwid.SimpleFocusListWalker([buttons_flow,self.list_profile, divider, self.login_wid, self.pass_wid, connect_button]) |
1178
49d39b619e5d
primitivus (profile manager): added FOCUS_UP and FOCUS_DOWN management
Goffi <goffi@goffi.org>
parents:
1161
diff
changeset
|
98 frame_body = urwid.ListBox(list_walker) |
115
eed4f77c942e
primitivus: Profile Manager should now be fully fonctionnal
Goffi <goffi@goffi.org>
parents:
113
diff
changeset
|
99 frame = urwid.Frame(frame_body,urwid.AttrMap(urwid.Text(_("Profile Manager"),align='center'),'title')) |
113 | 100 self.main_widget = urwid.LineBox(frame) |
101 urwid.WidgetWrap.__init__(self, self.main_widget) | |
1265
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1178
diff
changeset
|
102 if self._autoconnect: |
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1178
diff
changeset
|
103 self.autoconnect(autoconnect) |
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1178
diff
changeset
|
104 |
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1178
diff
changeset
|
105 def autoconnect(self, profile_keys): |
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1178
diff
changeset
|
106 """Automatically connect profiles |
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1178
diff
changeset
|
107 |
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1178
diff
changeset
|
108 @param profile_keys(iterable): list of profile keys to connect |
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1178
diff
changeset
|
109 """ |
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1178
diff
changeset
|
110 if not profile_keys: |
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1178
diff
changeset
|
111 log.warning("No profile given to autoconnect") |
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1178
diff
changeset
|
112 return |
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1178
diff
changeset
|
113 self._autoconnect = True |
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1178
diff
changeset
|
114 self._autoconnect_profiles=[] |
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1178
diff
changeset
|
115 self._do_autoconnect(profile_keys) |
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1178
diff
changeset
|
116 |
113 | 117 |
1161
344bbe6fd1de
primitivus: profile manager now handle APP_QUIT key
Goffi <goffi@goffi.org>
parents:
1139
diff
changeset
|
118 def keypress(self, size, key): |
344bbe6fd1de
primitivus: profile manager now handle APP_QUIT key
Goffi <goffi@goffi.org>
parents:
1139
diff
changeset
|
119 if key == a_key['APP_QUIT']: |
344bbe6fd1de
primitivus: profile manager now handle APP_QUIT key
Goffi <goffi@goffi.org>
parents:
1139
diff
changeset
|
120 self.host.onExit() |
344bbe6fd1de
primitivus: profile manager now handle APP_QUIT key
Goffi <goffi@goffi.org>
parents:
1139
diff
changeset
|
121 raise urwid.ExitMainLoop() |
1178
49d39b619e5d
primitivus (profile manager): added FOCUS_UP and FOCUS_DOWN management
Goffi <goffi@goffi.org>
parents:
1161
diff
changeset
|
122 elif key in (a_key['FOCUS_UP'], a_key['FOCUS_DOWN']): |
49d39b619e5d
primitivus (profile manager): added FOCUS_UP and FOCUS_DOWN management
Goffi <goffi@goffi.org>
parents:
1161
diff
changeset
|
123 focus_diff = 1 if key==a_key['FOCUS_DOWN'] else -1 |
49d39b619e5d
primitivus (profile manager): added FOCUS_UP and FOCUS_DOWN management
Goffi <goffi@goffi.org>
parents:
1161
diff
changeset
|
124 list_box = self.main_widget.base_widget.body |
49d39b619e5d
primitivus (profile manager): added FOCUS_UP and FOCUS_DOWN management
Goffi <goffi@goffi.org>
parents:
1161
diff
changeset
|
125 current_focus = list_box.body.get_focus()[1] |
49d39b619e5d
primitivus (profile manager): added FOCUS_UP and FOCUS_DOWN management
Goffi <goffi@goffi.org>
parents:
1161
diff
changeset
|
126 if current_focus is None: |
49d39b619e5d
primitivus (profile manager): added FOCUS_UP and FOCUS_DOWN management
Goffi <goffi@goffi.org>
parents:
1161
diff
changeset
|
127 return |
49d39b619e5d
primitivus (profile manager): added FOCUS_UP and FOCUS_DOWN management
Goffi <goffi@goffi.org>
parents:
1161
diff
changeset
|
128 while True: |
49d39b619e5d
primitivus (profile manager): added FOCUS_UP and FOCUS_DOWN management
Goffi <goffi@goffi.org>
parents:
1161
diff
changeset
|
129 current_focus += focus_diff |
49d39b619e5d
primitivus (profile manager): added FOCUS_UP and FOCUS_DOWN management
Goffi <goffi@goffi.org>
parents:
1161
diff
changeset
|
130 if current_focus < 0 or current_focus >= len(list_box.body): |
49d39b619e5d
primitivus (profile manager): added FOCUS_UP and FOCUS_DOWN management
Goffi <goffi@goffi.org>
parents:
1161
diff
changeset
|
131 break |
49d39b619e5d
primitivus (profile manager): added FOCUS_UP and FOCUS_DOWN management
Goffi <goffi@goffi.org>
parents:
1161
diff
changeset
|
132 if list_box.body[current_focus].selectable(): |
49d39b619e5d
primitivus (profile manager): added FOCUS_UP and FOCUS_DOWN management
Goffi <goffi@goffi.org>
parents:
1161
diff
changeset
|
133 list_box.set_focus(current_focus, 'above' if focus_diff == 1 else 'below') |
49d39b619e5d
primitivus (profile manager): added FOCUS_UP and FOCUS_DOWN management
Goffi <goffi@goffi.org>
parents:
1161
diff
changeset
|
134 list_box._invalidate() |
49d39b619e5d
primitivus (profile manager): added FOCUS_UP and FOCUS_DOWN management
Goffi <goffi@goffi.org>
parents:
1161
diff
changeset
|
135 return |
1161
344bbe6fd1de
primitivus: profile manager now handle APP_QUIT key
Goffi <goffi@goffi.org>
parents:
1139
diff
changeset
|
136 return super(ProfileManager, self).keypress(size, key) |
344bbe6fd1de
primitivus: profile manager now handle APP_QUIT key
Goffi <goffi@goffi.org>
parents:
1139
diff
changeset
|
137 |
1265
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1178
diff
changeset
|
138 def _do_autoconnect(self, profile_keys): |
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1178
diff
changeset
|
139 """Connect automatically given profiles |
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1178
diff
changeset
|
140 |
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1178
diff
changeset
|
141 @param profile_kes(iterable): profiles to connect |
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1178
diff
changeset
|
142 """ |
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1178
diff
changeset
|
143 assert self._autoconnect |
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1178
diff
changeset
|
144 |
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1178
diff
changeset
|
145 def authenticate_cb(callback_id, data, profile): |
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1178
diff
changeset
|
146 |
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1178
diff
changeset
|
147 if C.bool(data['validated']): |
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1178
diff
changeset
|
148 self._autoconnect_profiles.append(profile) |
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1178
diff
changeset
|
149 if len(self._autoconnect_profiles) == len(profile_keys): |
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1178
diff
changeset
|
150 # all the profiles have been validated |
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1178
diff
changeset
|
151 self.host.plug_profiles(self._autoconnect_profiles) |
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1178
diff
changeset
|
152 else: |
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1178
diff
changeset
|
153 # a profile is not validated, we go to manual mode |
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1178
diff
changeset
|
154 self._autoconnect=False |
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1178
diff
changeset
|
155 |
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1178
diff
changeset
|
156 for profile_key in profile_keys: |
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1178
diff
changeset
|
157 profile = self.host.bridge.getProfileName(profile_key) |
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1178
diff
changeset
|
158 if not profile: |
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1178
diff
changeset
|
159 self._autoconnect = False # manual mode |
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1178
diff
changeset
|
160 msg = _("Trying to plug an unknown profile key ({})".format(profile_key)) |
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1178
diff
changeset
|
161 log.warning(msg) |
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1178
diff
changeset
|
162 popup = sat_widgets.Alert(_("Profile plugging in error"), msg, ok_cb=self.host.removePopUp) |
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1178
diff
changeset
|
163 self.host.showPopUp(popup) |
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1178
diff
changeset
|
164 break |
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1178
diff
changeset
|
165 self.host.launchAction(C.AUTHENTICATE_PROFILE_ID, callback=authenticate_cb, profile=profile) |
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1178
diff
changeset
|
166 |
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1178
diff
changeset
|
167 def refillProfiles(self): |
113 | 168 """Update the list of profiles""" |
169 profiles = self.host.bridge.getProfilesList() | |
170 profiles.sort() | |
171 self.list_profile.changeValues(profiles) | |
1265
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1178
diff
changeset
|
172 self.host.redraw() |
112 | 173 |
113 | 174 def cancelDialog(self, button): |
117 | 175 self.host.removePopUp() |
113 | 176 |
177 def newProfile(self, button, edit): | |
217 | 178 """Create the profile""" |
113 | 179 name = edit.get_edit_text() |
1265
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1178
diff
changeset
|
180 self.host.bridge.asyncCreateProfile(name, callback=lambda: self.newProfileCreated(name), errback=self.profileCreationFailure) |
421
28e4299d4553
primitivus: profile manager updated to use new asynchronous profile creation
Goffi <goffi@goffi.org>
parents:
413
diff
changeset
|
181 |
1265
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1178
diff
changeset
|
182 def newProfileCreated(self, profile): |
117 | 183 self.host.removePopUp() |
1265
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1178
diff
changeset
|
184 self.refillProfiles() |
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1178
diff
changeset
|
185 self.list_profile.selectValue(profile) |
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1178
diff
changeset
|
186 self.current.profile=profile |
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1178
diff
changeset
|
187 self.getConnectionParams(profile) |
421
28e4299d4553
primitivus: profile manager updated to use new asynchronous profile creation
Goffi <goffi@goffi.org>
parents:
413
diff
changeset
|
188 self.host.redraw() |
28e4299d4553
primitivus: profile manager updated to use new asynchronous profile creation
Goffi <goffi@goffi.org>
parents:
413
diff
changeset
|
189 |
1265
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1178
diff
changeset
|
190 def profileCreationFailure(self, reason): |
421
28e4299d4553
primitivus: profile manager updated to use new asynchronous profile creation
Goffi <goffi@goffi.org>
parents:
413
diff
changeset
|
191 self.host.removePopUp() |
1063
6ec513ad92c2
frontends: async failures are more detailed (full class name + error message)
souliane <souliane@mailoo.org>
parents:
1034
diff
changeset
|
192 if reason == "ConflictError": |
6ec513ad92c2
frontends: async failures are more detailed (full class name + error message)
souliane <souliane@mailoo.org>
parents:
1034
diff
changeset
|
193 message = _("A profile with this name already exists") |
6ec513ad92c2
frontends: async failures are more detailed (full class name + error message)
souliane <souliane@mailoo.org>
parents:
1034
diff
changeset
|
194 elif reason == "CancelError": |
6ec513ad92c2
frontends: async failures are more detailed (full class name + error message)
souliane <souliane@mailoo.org>
parents:
1034
diff
changeset
|
195 message = _("Profile creation cancelled by backend") |
1265
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1178
diff
changeset
|
196 elif reason == "ValueError": |
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1178
diff
changeset
|
197 message = _("You profile name is not valid") # TODO: print a more informative message (empty name, name starting with '@') |
421
28e4299d4553
primitivus: profile manager updated to use new asynchronous profile creation
Goffi <goffi@goffi.org>
parents:
413
diff
changeset
|
198 else: |
1265
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1178
diff
changeset
|
199 message = _("Can't create profile ({})").format(reason) |
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1178
diff
changeset
|
200 popup = sat_widgets.Alert(_("Can't create profile"), message, ok_cb=self.host.removePopUp) |
421
28e4299d4553
primitivus: profile manager updated to use new asynchronous profile creation
Goffi <goffi@goffi.org>
parents:
413
diff
changeset
|
201 self.host.showPopUp(popup) |
113 | 202 |
203 def deleteProfile(self, button): | |
1265
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1178
diff
changeset
|
204 if self.current.profile: |
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1178
diff
changeset
|
205 self.host.bridge.asyncDeleteProfile(self.current.profile, callback=self.refillProfiles) |
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1178
diff
changeset
|
206 self.resetFields() |
117 | 207 self.host.removePopUp() |
587
952322b1d490
Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
572
diff
changeset
|
208 |
113 | 209 def onNewProfile(self, e): |
1265
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1178
diff
changeset
|
210 pop_up_widget = sat_widgets.InputDialog(_("New profile"), _("Please enter a new profile name"), cancel_cb=self.cancelDialog, ok_cb=self.newProfile) |
117 | 211 self.host.showPopUp(pop_up_widget) |
113 | 212 |
213 def onDeleteProfile(self, e): | |
1265
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1178
diff
changeset
|
214 if self.current.profile: |
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1178
diff
changeset
|
215 pop_up_widget = sat_widgets.ConfirmDialog(_("Are you sure you want to delete the profile {} ?").format(self.current.profile), no_cb=self.cancelDialog, yes_cb=self.deleteProfile) |
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1178
diff
changeset
|
216 self.host.showPopUp(pop_up_widget) |
113 | 217 |
1265
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1178
diff
changeset
|
218 def resetFields(self): |
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1178
diff
changeset
|
219 """Set profile to None, and reset fields""" |
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1178
diff
changeset
|
220 self.current.profile=None |
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1178
diff
changeset
|
221 self.login_wid.set_edit_text("") |
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1178
diff
changeset
|
222 self.pass_wid.set_edit_text("") |
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1178
diff
changeset
|
223 self.list_profile.unselectAll(invisible=True) |
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1178
diff
changeset
|
224 |
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1178
diff
changeset
|
225 def getConnectionParams(self, profile): |
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1178
diff
changeset
|
226 """Get login and password and display them |
1034
5197600a1e13
quick_app, primitivus: update the connection mechanism to ask for non empty profile passwords
souliane <souliane@mailoo.org>
parents:
1019
diff
changeset
|
227 |
5197600a1e13
quick_app, primitivus: update the connection mechanism to ask for non empty profile passwords
souliane <souliane@mailoo.org>
parents:
1019
diff
changeset
|
228 @param profile: %(doc_profile)s |
5197600a1e13
quick_app, primitivus: update the connection mechanism to ask for non empty profile passwords
souliane <souliane@mailoo.org>
parents:
1019
diff
changeset
|
229 """ |
413
dd4caab17008
core: - individual parameters managed through sqlite
Goffi <goffi@goffi.org>
parents:
228
diff
changeset
|
230 def setJID(jabberID): |
dd4caab17008
core: - individual parameters managed through sqlite
Goffi <goffi@goffi.org>
parents:
228
diff
changeset
|
231 self.login_wid.set_edit_text(jabberID) |
1265
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1178
diff
changeset
|
232 self.current.login = jabberID |
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1178
diff
changeset
|
233 self.host.redraw() # FIXME: redraw should be avoided |
1019 | 234 |
413
dd4caab17008
core: - individual parameters managed through sqlite
Goffi <goffi@goffi.org>
parents:
228
diff
changeset
|
235 def setPassword(password): |
dd4caab17008
core: - individual parameters managed through sqlite
Goffi <goffi@goffi.org>
parents:
228
diff
changeset
|
236 self.pass_wid.set_edit_text(password) |
1265
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1178
diff
changeset
|
237 self.current.password = password |
446
39a8ca1a2675
Primitivus: fixed redraw on profile change in profile manager
Goffi <goffi@goffi.org>
parents:
423
diff
changeset
|
238 self.host.redraw() |
413
dd4caab17008
core: - individual parameters managed through sqlite
Goffi <goffi@goffi.org>
parents:
228
diff
changeset
|
239 |
1034
5197600a1e13
quick_app, primitivus: update the connection mechanism to ask for non empty profile passwords
souliane <souliane@mailoo.org>
parents:
1019
diff
changeset
|
240 self.host.bridge.asyncGetParamA("JabberID", "Connection", profile_key=profile, callback=setJID, errback=self.getParamError) |
5197600a1e13
quick_app, primitivus: update the connection mechanism to ask for non empty profile passwords
souliane <souliane@mailoo.org>
parents:
1019
diff
changeset
|
241 self.host.bridge.asyncGetParamA("Password", "Connection", profile_key=profile, callback=setPassword, errback=self.getParamError) |
5197600a1e13
quick_app, primitivus: update the connection mechanism to ask for non empty profile passwords
souliane <souliane@mailoo.org>
parents:
1019
diff
changeset
|
242 |
1265
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1178
diff
changeset
|
243 def updateConnectionParams(self): |
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1178
diff
changeset
|
244 """Check if connection parameters have changed, and update them if so""" |
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1178
diff
changeset
|
245 if self.current.profile: |
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1178
diff
changeset
|
246 login = self.login_wid.get_edit_text() |
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1178
diff
changeset
|
247 password = self.pass_wid.get_edit_text() |
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1178
diff
changeset
|
248 if login != self.current.login and self.current.login is not None: |
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1178
diff
changeset
|
249 self.current.login = login |
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1178
diff
changeset
|
250 self.host.bridge.setParam("JabberID", login, "Connection", profile_key=self.current.profile) |
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1178
diff
changeset
|
251 log.info("login updated for profile [{}]".format(self.current.profile)) |
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1178
diff
changeset
|
252 if password != self.current.password and self.current.password is not None: |
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1178
diff
changeset
|
253 self.current.password = password |
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1178
diff
changeset
|
254 self.host.bridge.setParam("Password", password, "Connection", profile_key=self.current.profile) |
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1178
diff
changeset
|
255 log.info("password updated for profile [{}]".format(self.current.profile)) |
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1178
diff
changeset
|
256 |
1034
5197600a1e13
quick_app, primitivus: update the connection mechanism to ask for non empty profile passwords
souliane <souliane@mailoo.org>
parents:
1019
diff
changeset
|
257 def onProfileChange(self, list_wid): |
5197600a1e13
quick_app, primitivus: update the connection mechanism to ask for non empty profile passwords
souliane <souliane@mailoo.org>
parents:
1019
diff
changeset
|
258 """This is called when a profile is selected in the profile list. |
5197600a1e13
quick_app, primitivus: update the connection mechanism to ask for non empty profile passwords
souliane <souliane@mailoo.org>
parents:
1019
diff
changeset
|
259 |
5197600a1e13
quick_app, primitivus: update the connection mechanism to ask for non empty profile passwords
souliane <souliane@mailoo.org>
parents:
1019
diff
changeset
|
260 @param list_wid: the List widget who sent the event |
5197600a1e13
quick_app, primitivus: update the connection mechanism to ask for non empty profile passwords
souliane <souliane@mailoo.org>
parents:
1019
diff
changeset
|
261 """ |
1265
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1178
diff
changeset
|
262 self.updateConnectionParams() |
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1178
diff
changeset
|
263 focused = list_wid.focus |
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1178
diff
changeset
|
264 selected = focused.getState() |
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1178
diff
changeset
|
265 if not selected: # profile was just unselected |
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1178
diff
changeset
|
266 return |
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1178
diff
changeset
|
267 focused.setState(False, invisible=True) # we don't want the widget to be selected until we are sure we can access it |
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1178
diff
changeset
|
268 def authenticate_cb(callback_id, data, profile): |
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1178
diff
changeset
|
269 if C.bool(data['validated']): |
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1178
diff
changeset
|
270 self.current.profile = profile |
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1178
diff
changeset
|
271 focused.setState(True, invisible=True) |
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1178
diff
changeset
|
272 self.getConnectionParams(profile) |
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1178
diff
changeset
|
273 self.host.redraw() |
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1178
diff
changeset
|
274 self.host.launchAction(C.AUTHENTICATE_PROFILE_ID, callback=authenticate_cb, profile=focused.text) |
587
952322b1d490
Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
572
diff
changeset
|
275 |
1265
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1178
diff
changeset
|
276 def onConnectProfiles(self, button): |
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1178
diff
changeset
|
277 """Connect the profiles and start the main widget |
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1178
diff
changeset
|
278 |
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1178
diff
changeset
|
279 @param button: the connect button |
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1178
diff
changeset
|
280 """ |
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1178
diff
changeset
|
281 if self._autoconnect: |
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1178
diff
changeset
|
282 pop_up_widget = sat_widgets.Alert(_('Internal error'), _('You can connect manually and automatically at the same time'), ok_cb=self.cancelDialog) |
117 | 283 self.host.showPopUp(pop_up_widget) |
1265
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1178
diff
changeset
|
284 return |
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1178
diff
changeset
|
285 self.updateConnectionParams() |
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1178
diff
changeset
|
286 profiles = self.list_profile.getSelectedValues() |
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1178
diff
changeset
|
287 if not profiles: |
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1178
diff
changeset
|
288 pop_up_widget = sat_widgets.Alert(_('No profile selected'), _('You need to create and select at least one profile before connecting'), ok_cb=self.cancelDialog) |
117 | 289 self.host.showPopUp(pop_up_widget) |
115
eed4f77c942e
primitivus: Profile Manager should now be fully fonctionnal
Goffi <goffi@goffi.org>
parents:
113
diff
changeset
|
290 else: |
1265
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1178
diff
changeset
|
291 # All profiles in the list are already validated, so we can plug them directly |
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1178
diff
changeset
|
292 self.host.plug_profiles(profiles) |
587
952322b1d490
Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
572
diff
changeset
|
293 |
1265
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1178
diff
changeset
|
294 def getParamError(self, dummy): |
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1178
diff
changeset
|
295 popup = sat_widgets.Alert("Error", _("Can't get profile parameter"), ok_cb=self.host.removePopUp) |
423
6c20c76abdcc
backend: - bridge async D-Bus method now automatically manage callback and errback, we just have to return a deferred
Goffi <goffi@goffi.org>
parents:
422
diff
changeset
|
296 self.host.showPopUp(popup) |