Mercurial > libervia-backend
annotate sat_frontends/primitivus/profile_manager.py @ 3632:7acf19bdca2f
doc: minor typo
author | Goffi <goffi@goffi.org> |
---|---|
date | Fri, 27 Aug 2021 14:59:47 +0200 |
parents | be6d91572633 |
children | 524856bd7b19 |
rev | line source |
---|---|
3137 | 1 #!/usr/bin/env python3 |
2 | |
112 | 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 |
3479 | 5 # Copyright (C) 2009-2021 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 |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
22 |
1265
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1178
diff
changeset
|
23 log = logging.getLogger(__name__) |
1288
7cf32aeeebdb
quick_frontend, primitivus: moved parts of primitivus's profileManager to quick_frontend
Goffi <goffi@goffi.org>
parents:
1265
diff
changeset
|
24 from sat_frontends.quick_frontend.quick_profile_manager import QuickProfileManager |
1034
5197600a1e13
quick_app, primitivus: update the connection mechanism to ask for non empty profile passwords
souliane <souliane@mailoo.org>
parents:
1019
diff
changeset
|
25 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
|
26 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
|
27 from urwid_satext import sat_widgets |
112 | 28 import urwid |
1265
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 |
1288
7cf32aeeebdb
quick_frontend, primitivus: moved parts of primitivus's profileManager to quick_frontend
Goffi <goffi@goffi.org>
parents:
1265
diff
changeset
|
31 class ProfileManager(QuickProfileManager, urwid.WidgetWrap): |
1265
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1178
diff
changeset
|
32 def __init__(self, host, autoconnect=None): |
1288
7cf32aeeebdb
quick_frontend, primitivus: moved parts of primitivus's profileManager to quick_frontend
Goffi <goffi@goffi.org>
parents:
1265
diff
changeset
|
33 QuickProfileManager.__init__(self, host, autoconnect) |
587
952322b1d490
Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
572
diff
changeset
|
34 |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
35 # login & password box must be created before list because of onProfileChange |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
36 self.login_wid = sat_widgets.AdvancedEdit(_("Login:"), align="center") |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
37 self.pass_wid = sat_widgets.Password(_("Password:"), align="center") |
587
952322b1d490
Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
572
diff
changeset
|
38 |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
39 style = ["no_first_select"] |
2146
1bb9bf1b4150
core, frontends: getProfilesList renamed to profilesGetList + behaviour change:
Goffi <goffi@goffi.org>
parents:
2144
diff
changeset
|
40 profiles = host.bridge.profilesListGet() |
1288
7cf32aeeebdb
quick_frontend, primitivus: moved parts of primitivus's profileManager to quick_frontend
Goffi <goffi@goffi.org>
parents:
1265
diff
changeset
|
41 profiles.sort() |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
42 self.list_profile = sat_widgets.List( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
43 profiles, style=style, align="center", on_change=self.onProfileChange |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
44 ) |
113 | 45 |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
46 # new & delete buttons |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
47 buttons = [ |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
48 urwid.Button(_("New"), self.onNewProfile), |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
49 urwid.Button(_("Delete"), self.onDeleteProfile), |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
50 ] |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
51 buttons_flow = urwid.GridFlow( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
52 buttons, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
53 max([len(button.get_label()) for button in buttons]) + 4, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
54 1, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
55 1, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
56 "center", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
57 ) |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
58 |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
59 # second part: login information: |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
60 divider = urwid.Divider("-") |
113 | 61 |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
62 # connect button |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
63 connect_button = sat_widgets.CustomButton( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
64 _("Connect"), self.onConnectProfiles, align="center" |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
65 ) |
113 | 66 |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
67 # we now build the widget |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
68 list_walker = urwid.SimpleFocusListWalker( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
69 [ |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
70 buttons_flow, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
71 self.list_profile, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
72 divider, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
73 self.login_wid, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
74 self.pass_wid, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
75 connect_button, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
76 ] |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
77 ) |
1178
49d39b619e5d
primitivus (profile manager): added FOCUS_UP and FOCUS_DOWN management
Goffi <goffi@goffi.org>
parents:
1161
diff
changeset
|
78 frame_body = urwid.ListBox(list_walker) |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
79 frame = urwid.Frame( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
80 frame_body, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
81 urwid.AttrMap(urwid.Text(_("Profile Manager"), align="center"), "title"), |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
82 ) |
113 | 83 self.main_widget = urwid.LineBox(frame) |
84 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
|
85 |
1288
7cf32aeeebdb
quick_frontend, primitivus: moved parts of primitivus's profileManager to quick_frontend
Goffi <goffi@goffi.org>
parents:
1265
diff
changeset
|
86 self.go(autoconnect) |
1265
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1178
diff
changeset
|
87 |
1161
344bbe6fd1de
primitivus: profile manager now handle APP_QUIT key
Goffi <goffi@goffi.org>
parents:
1139
diff
changeset
|
88 def keypress(self, size, key): |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
89 if key == a_key["APP_QUIT"]: |
1161
344bbe6fd1de
primitivus: profile manager now handle APP_QUIT key
Goffi <goffi@goffi.org>
parents:
1139
diff
changeset
|
90 self.host.onExit() |
344bbe6fd1de
primitivus: profile manager now handle APP_QUIT key
Goffi <goffi@goffi.org>
parents:
1139
diff
changeset
|
91 raise urwid.ExitMainLoop() |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
92 elif key in (a_key["FOCUS_UP"], a_key["FOCUS_DOWN"]): |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
93 focus_diff = 1 if key == a_key["FOCUS_DOWN"] else -1 |
1178
49d39b619e5d
primitivus (profile manager): added FOCUS_UP and FOCUS_DOWN management
Goffi <goffi@goffi.org>
parents:
1161
diff
changeset
|
94 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
|
95 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
|
96 if current_focus is None: |
49d39b619e5d
primitivus (profile manager): added FOCUS_UP and FOCUS_DOWN management
Goffi <goffi@goffi.org>
parents:
1161
diff
changeset
|
97 return |
49d39b619e5d
primitivus (profile manager): added FOCUS_UP and FOCUS_DOWN management
Goffi <goffi@goffi.org>
parents:
1161
diff
changeset
|
98 while True: |
49d39b619e5d
primitivus (profile manager): added FOCUS_UP and FOCUS_DOWN management
Goffi <goffi@goffi.org>
parents:
1161
diff
changeset
|
99 current_focus += focus_diff |
49d39b619e5d
primitivus (profile manager): added FOCUS_UP and FOCUS_DOWN management
Goffi <goffi@goffi.org>
parents:
1161
diff
changeset
|
100 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
|
101 break |
49d39b619e5d
primitivus (profile manager): added FOCUS_UP and FOCUS_DOWN management
Goffi <goffi@goffi.org>
parents:
1161
diff
changeset
|
102 if list_box.body[current_focus].selectable(): |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
103 list_box.set_focus( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
104 current_focus, "above" if focus_diff == 1 else "below" |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
105 ) |
1178
49d39b619e5d
primitivus (profile manager): added FOCUS_UP and FOCUS_DOWN management
Goffi <goffi@goffi.org>
parents:
1161
diff
changeset
|
106 list_box._invalidate() |
49d39b619e5d
primitivus (profile manager): added FOCUS_UP and FOCUS_DOWN management
Goffi <goffi@goffi.org>
parents:
1161
diff
changeset
|
107 return |
1161
344bbe6fd1de
primitivus: profile manager now handle APP_QUIT key
Goffi <goffi@goffi.org>
parents:
1139
diff
changeset
|
108 return super(ProfileManager, self).keypress(size, key) |
344bbe6fd1de
primitivus: profile manager now handle APP_QUIT key
Goffi <goffi@goffi.org>
parents:
1139
diff
changeset
|
109 |
113 | 110 def cancelDialog(self, button): |
117 | 111 self.host.removePopUp() |
113 | 112 |
113 def newProfile(self, button, edit): | |
217 | 114 """Create the profile""" |
113 | 115 name = edit.get_edit_text() |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
116 self.host.bridge.profileCreate( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
117 name, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
118 callback=lambda: self.newProfileCreated(name), |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
119 errback=self.profileCreationFailure, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
120 ) |
421
28e4299d4553
primitivus: profile manager updated to use new asynchronous profile creation
Goffi <goffi@goffi.org>
parents:
413
diff
changeset
|
121 |
1265
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1178
diff
changeset
|
122 def newProfileCreated(self, profile): |
1698
7923dc51143e
primitivus (profile manager): session is started for newly create profiles
Goffi <goffi@goffi.org>
parents:
1609
diff
changeset
|
123 # new profile will be selected, and a selected profile assume the session is started |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
124 self.host.bridge.profileStartSession( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
125 "", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
126 profile, |
2765
378188abe941
misc: replaced all "dummy" by the more conventional and readable "__" ("_" being used for gettext)
Goffi <goffi@goffi.org>
parents:
2624
diff
changeset
|
127 callback=lambda __: self.newProfileSessionStarted(profile), |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
128 errback=self.profileCreationFailure, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
129 ) |
1698
7923dc51143e
primitivus (profile manager): session is started for newly create profiles
Goffi <goffi@goffi.org>
parents:
1609
diff
changeset
|
130 |
7923dc51143e
primitivus (profile manager): session is started for newly create profiles
Goffi <goffi@goffi.org>
parents:
1609
diff
changeset
|
131 def newProfileSessionStarted(self, profile): |
117 | 132 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
|
133 self.refillProfiles() |
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1178
diff
changeset
|
134 self.list_profile.selectValue(profile) |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
135 self.current.profile = profile |
1265
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1178
diff
changeset
|
136 self.getConnectionParams(profile) |
421
28e4299d4553
primitivus: profile manager updated to use new asynchronous profile creation
Goffi <goffi@goffi.org>
parents:
413
diff
changeset
|
137 self.host.redraw() |
28e4299d4553
primitivus: profile manager updated to use new asynchronous profile creation
Goffi <goffi@goffi.org>
parents:
413
diff
changeset
|
138 |
1265
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1178
diff
changeset
|
139 def profileCreationFailure(self, reason): |
421
28e4299d4553
primitivus: profile manager updated to use new asynchronous profile creation
Goffi <goffi@goffi.org>
parents:
413
diff
changeset
|
140 self.host.removePopUp() |
1288
7cf32aeeebdb
quick_frontend, primitivus: moved parts of primitivus's profileManager to quick_frontend
Goffi <goffi@goffi.org>
parents:
1265
diff
changeset
|
141 message = self._getErrorMessage(reason) |
1609
66f0e877625b
primitivus: fixed alert case + alert in profileManager
Goffi <goffi@goffi.org>
parents:
1489
diff
changeset
|
142 self.host.alert(_("Can't create profile"), message) |
113 | 143 |
144 def deleteProfile(self, button): | |
1288
7cf32aeeebdb
quick_frontend, primitivus: moved parts of primitivus's profileManager to quick_frontend
Goffi <goffi@goffi.org>
parents:
1265
diff
changeset
|
145 self._deleteProfile() |
117 | 146 self.host.removePopUp() |
587
952322b1d490
Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
572
diff
changeset
|
147 |
113 | 148 def onNewProfile(self, e): |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
149 pop_up_widget = sat_widgets.InputDialog( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
150 _("New profile"), |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
151 _("Please enter a new profile name"), |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
152 cancel_cb=self.cancelDialog, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
153 ok_cb=self.newProfile, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
154 ) |
117 | 155 self.host.showPopUp(pop_up_widget) |
113 | 156 |
157 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
|
158 if self.current.profile: |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
159 pop_up_widget = sat_widgets.ConfirmDialog( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
160 _("Are you sure you want to delete the profile {} ?").format( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
161 self.current.profile |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
162 ), |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
163 no_cb=self.cancelDialog, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
164 yes_cb=self.deleteProfile, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
165 ) |
1265
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1178
diff
changeset
|
166 self.host.showPopUp(pop_up_widget) |
113 | 167 |
1288
7cf32aeeebdb
quick_frontend, primitivus: moved parts of primitivus's profileManager to quick_frontend
Goffi <goffi@goffi.org>
parents:
1265
diff
changeset
|
168 def onConnectProfiles(self, button): |
7cf32aeeebdb
quick_frontend, primitivus: moved parts of primitivus's profileManager to quick_frontend
Goffi <goffi@goffi.org>
parents:
1265
diff
changeset
|
169 """Connect the profiles and start the main widget |
7cf32aeeebdb
quick_frontend, primitivus: moved parts of primitivus's profileManager to quick_frontend
Goffi <goffi@goffi.org>
parents:
1265
diff
changeset
|
170 |
7cf32aeeebdb
quick_frontend, primitivus: moved parts of primitivus's profileManager to quick_frontend
Goffi <goffi@goffi.org>
parents:
1265
diff
changeset
|
171 @param button: the connect button |
7cf32aeeebdb
quick_frontend, primitivus: moved parts of primitivus's profileManager to quick_frontend
Goffi <goffi@goffi.org>
parents:
1265
diff
changeset
|
172 """ |
7cf32aeeebdb
quick_frontend, primitivus: moved parts of primitivus's profileManager to quick_frontend
Goffi <goffi@goffi.org>
parents:
1265
diff
changeset
|
173 self._onConnectProfiles() |
7cf32aeeebdb
quick_frontend, primitivus: moved parts of primitivus's profileManager to quick_frontend
Goffi <goffi@goffi.org>
parents:
1265
diff
changeset
|
174 |
1265
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1178
diff
changeset
|
175 def resetFields(self): |
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1178
diff
changeset
|
176 """Set profile to None, and reset fields""" |
1288
7cf32aeeebdb
quick_frontend, primitivus: moved parts of primitivus's profileManager to quick_frontend
Goffi <goffi@goffi.org>
parents:
1265
diff
changeset
|
177 super(ProfileManager, self).resetFields() |
1265
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1178
diff
changeset
|
178 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
|
179 |
1288
7cf32aeeebdb
quick_frontend, primitivus: moved parts of primitivus's profileManager to quick_frontend
Goffi <goffi@goffi.org>
parents:
1265
diff
changeset
|
180 def setProfiles(self, profiles): |
7cf32aeeebdb
quick_frontend, primitivus: moved parts of primitivus's profileManager to quick_frontend
Goffi <goffi@goffi.org>
parents:
1265
diff
changeset
|
181 """Update the list of profiles""" |
7cf32aeeebdb
quick_frontend, primitivus: moved parts of primitivus's profileManager to quick_frontend
Goffi <goffi@goffi.org>
parents:
1265
diff
changeset
|
182 self.list_profile.changeValues(profiles) |
7cf32aeeebdb
quick_frontend, primitivus: moved parts of primitivus's profileManager to quick_frontend
Goffi <goffi@goffi.org>
parents:
1265
diff
changeset
|
183 self.host.redraw() |
1034
5197600a1e13
quick_app, primitivus: update the connection mechanism to ask for non empty profile passwords
souliane <souliane@mailoo.org>
parents:
1019
diff
changeset
|
184 |
1288
7cf32aeeebdb
quick_frontend, primitivus: moved parts of primitivus's profileManager to quick_frontend
Goffi <goffi@goffi.org>
parents:
1265
diff
changeset
|
185 def getProfiles(self): |
7cf32aeeebdb
quick_frontend, primitivus: moved parts of primitivus's profileManager to quick_frontend
Goffi <goffi@goffi.org>
parents:
1265
diff
changeset
|
186 return self.list_profile.getSelectedValues() |
1019 | 187 |
1288
7cf32aeeebdb
quick_frontend, primitivus: moved parts of primitivus's profileManager to quick_frontend
Goffi <goffi@goffi.org>
parents:
1265
diff
changeset
|
188 def getJID(self): |
7cf32aeeebdb
quick_frontend, primitivus: moved parts of primitivus's profileManager to quick_frontend
Goffi <goffi@goffi.org>
parents:
1265
diff
changeset
|
189 return self.login_wid.get_edit_text() |
7cf32aeeebdb
quick_frontend, primitivus: moved parts of primitivus's profileManager to quick_frontend
Goffi <goffi@goffi.org>
parents:
1265
diff
changeset
|
190 |
7cf32aeeebdb
quick_frontend, primitivus: moved parts of primitivus's profileManager to quick_frontend
Goffi <goffi@goffi.org>
parents:
1265
diff
changeset
|
191 def getPassword(self): |
7cf32aeeebdb
quick_frontend, primitivus: moved parts of primitivus's profileManager to quick_frontend
Goffi <goffi@goffi.org>
parents:
1265
diff
changeset
|
192 return self.pass_wid.get_edit_text() |
413
dd4caab17008
core: - individual parameters managed through sqlite
Goffi <goffi@goffi.org>
parents:
228
diff
changeset
|
193 |
1288
7cf32aeeebdb
quick_frontend, primitivus: moved parts of primitivus's profileManager to quick_frontend
Goffi <goffi@goffi.org>
parents:
1265
diff
changeset
|
194 def setJID(self, jid_): |
7cf32aeeebdb
quick_frontend, primitivus: moved parts of primitivus's profileManager to quick_frontend
Goffi <goffi@goffi.org>
parents:
1265
diff
changeset
|
195 self.login_wid.set_edit_text(jid_) |
7cf32aeeebdb
quick_frontend, primitivus: moved parts of primitivus's profileManager to quick_frontend
Goffi <goffi@goffi.org>
parents:
1265
diff
changeset
|
196 self.current.login = jid_ |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
197 self.host.redraw() # FIXME: redraw should be avoided |
1034
5197600a1e13
quick_app, primitivus: update the connection mechanism to ask for non empty profile passwords
souliane <souliane@mailoo.org>
parents:
1019
diff
changeset
|
198 |
1288
7cf32aeeebdb
quick_frontend, primitivus: moved parts of primitivus's profileManager to quick_frontend
Goffi <goffi@goffi.org>
parents:
1265
diff
changeset
|
199 def setPassword(self, password): |
7cf32aeeebdb
quick_frontend, primitivus: moved parts of primitivus's profileManager to quick_frontend
Goffi <goffi@goffi.org>
parents:
1265
diff
changeset
|
200 self.pass_wid.set_edit_text(password) |
7cf32aeeebdb
quick_frontend, primitivus: moved parts of primitivus's profileManager to quick_frontend
Goffi <goffi@goffi.org>
parents:
1265
diff
changeset
|
201 self.current.password = password |
7cf32aeeebdb
quick_frontend, primitivus: moved parts of primitivus's profileManager to quick_frontend
Goffi <goffi@goffi.org>
parents:
1265
diff
changeset
|
202 self.host.redraw() |
7cf32aeeebdb
quick_frontend, primitivus: moved parts of primitivus's profileManager to quick_frontend
Goffi <goffi@goffi.org>
parents:
1265
diff
changeset
|
203 |
1488
66d01f29f886
primitivus (ProfileManager): fixed profile change event callback
Goffi <goffi@goffi.org>
parents:
1479
diff
changeset
|
204 def onProfileChange(self, list_wid, widget=None, selected=None): |
1034
5197600a1e13
quick_app, primitivus: update the connection mechanism to ask for non empty profile passwords
souliane <souliane@mailoo.org>
parents:
1019
diff
changeset
|
205 """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
|
206 |
5197600a1e13
quick_app, primitivus: update the connection mechanism to ask for non empty profile passwords
souliane <souliane@mailoo.org>
parents:
1019
diff
changeset
|
207 @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
|
208 """ |
1265
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1178
diff
changeset
|
209 self.updateConnectionParams() |
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1178
diff
changeset
|
210 focused = list_wid.focus |
1479
057f0714f27e
primivitus: fixed profile manager exception when nothing is focused
Goffi <goffi@goffi.org>
parents:
1396
diff
changeset
|
211 selected = focused.getState() if focused is not None else False |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
212 if not selected: # profile was just unselected |
1265
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1178
diff
changeset
|
213 return |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
214 focused.setState( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
215 False, invisible=True |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
216 ) # we don't want the widget to be selected until we are sure we can access it |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
217 |
1489
039d96e131be
frontends: callback are now always used in QuickApp launchAction (before it was only used if validated is present):
Goffi <goffi@goffi.org>
parents:
1488
diff
changeset
|
218 def authenticate_cb(data, cb_id, profile): |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
219 if C.bool(data.pop("validated", C.BOOL_FALSE)): |
1265
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 = profile |
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1178
diff
changeset
|
221 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
|
222 self.getConnectionParams(profile) |
e3a9ea76de35
quick_frontend, primitivus: multi-profiles refactoring part 1 (big commit, sorry :p):
Goffi <goffi@goffi.org>
parents:
1178
diff
changeset
|
223 self.host.redraw() |
1489
039d96e131be
frontends: callback are now always used in QuickApp launchAction (before it was only used if validated is present):
Goffi <goffi@goffi.org>
parents:
1488
diff
changeset
|
224 self.host.actionManager(data, callback=authenticate_cb, profile=profile) |
039d96e131be
frontends: callback are now always used in QuickApp launchAction (before it was only used if validated is present):
Goffi <goffi@goffi.org>
parents:
1488
diff
changeset
|
225 |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
226 self.host.launchAction( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
227 C.AUTHENTICATE_PROFILE_ID, callback=authenticate_cb, profile=focused.text |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
228 ) |