Mercurial > libervia-desktop-kivy
annotate cagou/core/menu.py @ 485:f046092ba883
install (setup.py): update dependencies
author | Goffi <goffi@goffi.org> |
---|---|
date | Fri, 23 Sep 2022 18:03:58 +0200 |
parents | 3693c662fa88 |
children | 203755bbe0fe |
rev | line source |
---|---|
379 | 1 #!/usr/bin/env python3 |
2 | |
51 | 3 |
4 # Cagou: desktop/mobile frontend for Salut à Toi XMPP client | |
461 | 5 # Copyright (C) 2016-2021 Jérôme Poisson (goffi@goffi.org) |
51 | 6 |
7 # This program is free software: you can redistribute it and/or modify | |
8 # it under the terms of the GNU Affero General Public License as published by | |
9 # the Free Software Foundation, either version 3 of the License, or | |
10 # (at your option) any later version. | |
11 | |
12 # This program is distributed in the hope that it will be useful, | |
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of | |
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
15 # GNU Affero General Public License for more details. | |
16 | |
17 # You should have received a copy of the GNU Affero General Public License | |
18 # along with this program. If not, see <http://www.gnu.org/licenses/>. | |
19 | |
20 | |
21 from sat.core.i18n import _ | |
22 from sat.core import log as logging | |
23 from cagou.core.constants import Const as C | |
197
c7d15ef4bfa8
core (menu): new EntitiesSelectorMenu:
Goffi <goffi@goffi.org>
parents:
184
diff
changeset
|
24 from cagou.core.common import JidToggle |
85
c2a7234d13d2
menu: use of garden's contextmenu for menus
Goffi <goffi@goffi.org>
parents:
53
diff
changeset
|
25 from kivy.uix.boxlayout import BoxLayout |
51 | 26 from kivy.uix.label import Label |
376 | 27 from kivy.uix.button import Button |
51 | 28 from kivy.uix.popup import Popup |
404
f7476818f9fb
core (common): JidSelector + behaviors various improvments:
Goffi <goffi@goffi.org>
parents:
400
diff
changeset
|
29 from .behaviors import FilterBehavior |
51 | 30 from kivy import properties |
168
397f2fb67aab
core (menu): animate transfer menu opening/closing + close it on [ESC]/back
Goffi <goffi@goffi.org>
parents:
126
diff
changeset
|
31 from kivy.core.window import Window |
397f2fb67aab
core (menu): animate transfer menu opening/closing + close it on [ESC]/back
Goffi <goffi@goffi.org>
parents:
126
diff
changeset
|
32 from kivy.animation import Animation |
197
c7d15ef4bfa8
core (menu): new EntitiesSelectorMenu:
Goffi <goffi@goffi.org>
parents:
184
diff
changeset
|
33 from kivy.metrics import dp |
51 | 34 from cagou import G |
222 | 35 from functools import partial |
51 | 36 import webbrowser |
37 | |
302
f55b60659ec1
core (about): improved "about" popup:
Goffi <goffi@goffi.org>
parents:
282
diff
changeset
|
38 log = logging.getLogger(__name__) |
f55b60659ec1
core (about): improved "about" popup:
Goffi <goffi@goffi.org>
parents:
282
diff
changeset
|
39 |
467
3693c662fa88
core (menu): update "about" text following renaming
Goffi <goffi@goffi.org>
parents:
461
diff
changeset
|
40 ABOUT_TITLE = _("About {}").format(C.APP_NAME) |
3693c662fa88
core (menu): update "about" text following renaming
Goffi <goffi@goffi.org>
parents:
461
diff
changeset
|
41 ABOUT_CONTENT = _("""[b]{app_name} ({app_name_alt})[/b] |
302
f55b60659ec1
core (about): improved "about" popup:
Goffi <goffi@goffi.org>
parents:
282
diff
changeset
|
42 |
467
3693c662fa88
core (menu): update "about" text following renaming
Goffi <goffi@goffi.org>
parents:
461
diff
changeset
|
43 [u]{app_name} version[/u]: |
302
f55b60659ec1
core (about): improved "about" popup:
Goffi <goffi@goffi.org>
parents:
282
diff
changeset
|
44 {version} |
f55b60659ec1
core (about): improved "about" popup:
Goffi <goffi@goffi.org>
parents:
282
diff
changeset
|
45 |
f55b60659ec1
core (about): improved "about" popup:
Goffi <goffi@goffi.org>
parents:
282
diff
changeset
|
46 [u]backend version[/u]: |
f55b60659ec1
core (about): improved "about" popup:
Goffi <goffi@goffi.org>
parents:
282
diff
changeset
|
47 {backend_version} |
51 | 48 |
467
3693c662fa88
core (menu): update "about" text following renaming
Goffi <goffi@goffi.org>
parents:
461
diff
changeset
|
49 {app_name} is a libre communication tool based on libre standard XMPP. |
51 | 50 |
467
3693c662fa88
core (menu): update "about" text following renaming
Goffi <goffi@goffi.org>
parents:
461
diff
changeset
|
51 {app_name} is part of the "Libervia" project ({app_component} frontend) |
51 | 52 more informations at [color=5500ff][ref=website]salut-a-toi.org[/ref][/color] |
246 | 53 """) |
51 | 54 |
55 | |
56 class AboutContent(Label): | |
57 | |
58 def on_ref_press(self, value): | |
59 if value == "website": | |
60 webbrowser.open("https://salut-a-toi.org") | |
61 | |
62 | |
63 class AboutPopup(Popup): | |
64 | |
65 def on_touch_down(self, touch): | |
66 if self.collide_point(*touch.pos): | |
67 self.dismiss() | |
68 return super(AboutPopup, self).on_touch_down(touch) | |
69 | |
70 | |
97
5d2289127bb7
menu (upload): better menu using dedicated widget:
Goffi <goffi@goffi.org>
parents:
88
diff
changeset
|
71 class TransferItem(BoxLayout): |
5d2289127bb7
menu (upload): better menu using dedicated widget:
Goffi <goffi@goffi.org>
parents:
88
diff
changeset
|
72 plug_info = properties.DictProperty() |
5d2289127bb7
menu (upload): better menu using dedicated widget:
Goffi <goffi@goffi.org>
parents:
88
diff
changeset
|
73 |
5d2289127bb7
menu (upload): better menu using dedicated widget:
Goffi <goffi@goffi.org>
parents:
88
diff
changeset
|
74 def on_touch_up(self, touch): |
5d2289127bb7
menu (upload): better menu using dedicated widget:
Goffi <goffi@goffi.org>
parents:
88
diff
changeset
|
75 if not self.collide_point(*touch.pos): |
5d2289127bb7
menu (upload): better menu using dedicated widget:
Goffi <goffi@goffi.org>
parents:
88
diff
changeset
|
76 return super(TransferItem, self).on_touch_up(touch) |
5d2289127bb7
menu (upload): better menu using dedicated widget:
Goffi <goffi@goffi.org>
parents:
88
diff
changeset
|
77 else: |
5d2289127bb7
menu (upload): better menu using dedicated widget:
Goffi <goffi@goffi.org>
parents:
88
diff
changeset
|
78 transfer_menu = self.parent |
5d2289127bb7
menu (upload): better menu using dedicated widget:
Goffi <goffi@goffi.org>
parents:
88
diff
changeset
|
79 while not isinstance(transfer_menu, TransferMenu): |
5d2289127bb7
menu (upload): better menu using dedicated widget:
Goffi <goffi@goffi.org>
parents:
88
diff
changeset
|
80 transfer_menu = transfer_menu.parent |
5d2289127bb7
menu (upload): better menu using dedicated widget:
Goffi <goffi@goffi.org>
parents:
88
diff
changeset
|
81 transfer_menu.do_callback(self.plug_info) |
5d2289127bb7
menu (upload): better menu using dedicated widget:
Goffi <goffi@goffi.org>
parents:
88
diff
changeset
|
82 return True |
5d2289127bb7
menu (upload): better menu using dedicated widget:
Goffi <goffi@goffi.org>
parents:
88
diff
changeset
|
83 |
5d2289127bb7
menu (upload): better menu using dedicated widget:
Goffi <goffi@goffi.org>
parents:
88
diff
changeset
|
84 |
197
c7d15ef4bfa8
core (menu): new EntitiesSelectorMenu:
Goffi <goffi@goffi.org>
parents:
184
diff
changeset
|
85 class SideMenu(BoxLayout): |
216
e42e0c45d384
core (menu): allow to specify size in SideMenu:
Goffi <goffi@goffi.org>
parents:
197
diff
changeset
|
86 size_hint_close = (0, 1) |
e42e0c45d384
core (menu): allow to specify size in SideMenu:
Goffi <goffi@goffi.org>
parents:
197
diff
changeset
|
87 size_hint_open = (0.4, 1) |
e42e0c45d384
core (menu): allow to specify size in SideMenu:
Goffi <goffi@goffi.org>
parents:
197
diff
changeset
|
88 size_close = (100, 100) |
e42e0c45d384
core (menu): allow to specify size in SideMenu:
Goffi <goffi@goffi.org>
parents:
197
diff
changeset
|
89 size_open = (0, 0) |
197
c7d15ef4bfa8
core (menu): new EntitiesSelectorMenu:
Goffi <goffi@goffi.org>
parents:
184
diff
changeset
|
90 bg_color = properties.ListProperty([0, 0, 0, 1]) |
c7d15ef4bfa8
core (menu): new EntitiesSelectorMenu:
Goffi <goffi@goffi.org>
parents:
184
diff
changeset
|
91 # callback will be called with arguments relevant to menu |
86 | 92 callback = properties.ObjectProperty() |
197
c7d15ef4bfa8
core (menu): new EntitiesSelectorMenu:
Goffi <goffi@goffi.org>
parents:
184
diff
changeset
|
93 # call do_callback even when menu is cancelled |
c7d15ef4bfa8
core (menu): new EntitiesSelectorMenu:
Goffi <goffi@goffi.org>
parents:
184
diff
changeset
|
94 callback_on_close = properties.BooleanProperty(False) |
86 | 95 # cancel callback need to remove the widget for UI |
96 # will be called with the widget to remove as argument | |
97 cancel_cb = properties.ObjectProperty() | |
98 | |
99 def __init__(self, **kwargs): | |
197
c7d15ef4bfa8
core (menu): new EntitiesSelectorMenu:
Goffi <goffi@goffi.org>
parents:
184
diff
changeset
|
100 super(SideMenu, self).__init__(**kwargs) |
86 | 101 if self.cancel_cb is None: |
197
c7d15ef4bfa8
core (menu): new EntitiesSelectorMenu:
Goffi <goffi@goffi.org>
parents:
184
diff
changeset
|
102 self.cancel_cb = self.onMenuCancelled |
86 | 103 |
216
e42e0c45d384
core (menu): allow to specify size in SideMenu:
Goffi <goffi@goffi.org>
parents:
197
diff
changeset
|
104 def _set_anim_kw(self, kw, size_hint, size): |
e42e0c45d384
core (menu): allow to specify size in SideMenu:
Goffi <goffi@goffi.org>
parents:
197
diff
changeset
|
105 """Set animation keywords |
e42e0c45d384
core (menu): allow to specify size in SideMenu:
Goffi <goffi@goffi.org>
parents:
197
diff
changeset
|
106 |
e42e0c45d384
core (menu): allow to specify size in SideMenu:
Goffi <goffi@goffi.org>
parents:
197
diff
changeset
|
107 for each value of size_hint it is used if not None, |
e42e0c45d384
core (menu): allow to specify size in SideMenu:
Goffi <goffi@goffi.org>
parents:
197
diff
changeset
|
108 else size is used. |
e42e0c45d384
core (menu): allow to specify size in SideMenu:
Goffi <goffi@goffi.org>
parents:
197
diff
changeset
|
109 If one value of size is bigger than the respective one of Window |
e42e0c45d384
core (menu): allow to specify size in SideMenu:
Goffi <goffi@goffi.org>
parents:
197
diff
changeset
|
110 the one of Window is used |
e42e0c45d384
core (menu): allow to specify size in SideMenu:
Goffi <goffi@goffi.org>
parents:
197
diff
changeset
|
111 """ |
e42e0c45d384
core (menu): allow to specify size in SideMenu:
Goffi <goffi@goffi.org>
parents:
197
diff
changeset
|
112 size_hint_x, size_hint_y = size_hint |
e42e0c45d384
core (menu): allow to specify size in SideMenu:
Goffi <goffi@goffi.org>
parents:
197
diff
changeset
|
113 width, height = size |
e42e0c45d384
core (menu): allow to specify size in SideMenu:
Goffi <goffi@goffi.org>
parents:
197
diff
changeset
|
114 if size_hint_x is not None: |
e42e0c45d384
core (menu): allow to specify size in SideMenu:
Goffi <goffi@goffi.org>
parents:
197
diff
changeset
|
115 kw['size_hint_x'] = size_hint_x |
e42e0c45d384
core (menu): allow to specify size in SideMenu:
Goffi <goffi@goffi.org>
parents:
197
diff
changeset
|
116 elif width is not None: |
e42e0c45d384
core (menu): allow to specify size in SideMenu:
Goffi <goffi@goffi.org>
parents:
197
diff
changeset
|
117 kw['width'] = min(width, Window.width) |
e42e0c45d384
core (menu): allow to specify size in SideMenu:
Goffi <goffi@goffi.org>
parents:
197
diff
changeset
|
118 |
e42e0c45d384
core (menu): allow to specify size in SideMenu:
Goffi <goffi@goffi.org>
parents:
197
diff
changeset
|
119 if size_hint_y is not None: |
e42e0c45d384
core (menu): allow to specify size in SideMenu:
Goffi <goffi@goffi.org>
parents:
197
diff
changeset
|
120 kw['size_hint_y'] = size_hint_y |
e42e0c45d384
core (menu): allow to specify size in SideMenu:
Goffi <goffi@goffi.org>
parents:
197
diff
changeset
|
121 elif height is not None: |
e42e0c45d384
core (menu): allow to specify size in SideMenu:
Goffi <goffi@goffi.org>
parents:
197
diff
changeset
|
122 kw['height'] = min(height, Window.height) |
e42e0c45d384
core (menu): allow to specify size in SideMenu:
Goffi <goffi@goffi.org>
parents:
197
diff
changeset
|
123 |
86 | 124 def show(self, caller_wid=None): |
168
397f2fb67aab
core (menu): animate transfer menu opening/closing + close it on [ESC]/back
Goffi <goffi@goffi.org>
parents:
126
diff
changeset
|
125 Window.bind(on_keyboard=self.key_input) |
97
5d2289127bb7
menu (upload): better menu using dedicated widget:
Goffi <goffi@goffi.org>
parents:
88
diff
changeset
|
126 G.host.app.root.add_widget(self) |
216
e42e0c45d384
core (menu): allow to specify size in SideMenu:
Goffi <goffi@goffi.org>
parents:
197
diff
changeset
|
127 kw = {'d': 0.3, 't': 'out_back'} |
e42e0c45d384
core (menu): allow to specify size in SideMenu:
Goffi <goffi@goffi.org>
parents:
197
diff
changeset
|
128 self._set_anim_kw(kw, self.size_hint_open, self.size_open) |
e42e0c45d384
core (menu): allow to specify size in SideMenu:
Goffi <goffi@goffi.org>
parents:
197
diff
changeset
|
129 Animation(**kw).start(self) |
168
397f2fb67aab
core (menu): animate transfer menu opening/closing + close it on [ESC]/back
Goffi <goffi@goffi.org>
parents:
126
diff
changeset
|
130 |
430
edb240ff7936
core (menu): avoid crash when removing SideMenu from parent if it has already been removed
Goffi <goffi@goffi.org>
parents:
429
diff
changeset
|
131 def _removeFromParent(self, anim, menu): |
edb240ff7936
core (menu): avoid crash when removing SideMenu from parent if it has already been removed
Goffi <goffi@goffi.org>
parents:
429
diff
changeset
|
132 # self.parent can already be None if the widget has been removed by a callback |
edb240ff7936
core (menu): avoid crash when removing SideMenu from parent if it has already been removed
Goffi <goffi@goffi.org>
parents:
429
diff
changeset
|
133 # before the animation started. |
edb240ff7936
core (menu): avoid crash when removing SideMenu from parent if it has already been removed
Goffi <goffi@goffi.org>
parents:
429
diff
changeset
|
134 if self.parent is not None: |
edb240ff7936
core (menu): avoid crash when removing SideMenu from parent if it has already been removed
Goffi <goffi@goffi.org>
parents:
429
diff
changeset
|
135 self.parent.remove_widget(self) |
edb240ff7936
core (menu): avoid crash when removing SideMenu from parent if it has already been removed
Goffi <goffi@goffi.org>
parents:
429
diff
changeset
|
136 |
168
397f2fb67aab
core (menu): animate transfer menu opening/closing + close it on [ESC]/back
Goffi <goffi@goffi.org>
parents:
126
diff
changeset
|
137 def hide(self): |
397f2fb67aab
core (menu): animate transfer menu opening/closing + close it on [ESC]/back
Goffi <goffi@goffi.org>
parents:
126
diff
changeset
|
138 Window.unbind(on_keyboard=self.key_input) |
216
e42e0c45d384
core (menu): allow to specify size in SideMenu:
Goffi <goffi@goffi.org>
parents:
197
diff
changeset
|
139 kw = {'d': 0.2} |
e42e0c45d384
core (menu): allow to specify size in SideMenu:
Goffi <goffi@goffi.org>
parents:
197
diff
changeset
|
140 self._set_anim_kw(kw, self.size_hint_close, self.size_close) |
e42e0c45d384
core (menu): allow to specify size in SideMenu:
Goffi <goffi@goffi.org>
parents:
197
diff
changeset
|
141 anim = Animation(**kw) |
430
edb240ff7936
core (menu): avoid crash when removing SideMenu from parent if it has already been removed
Goffi <goffi@goffi.org>
parents:
429
diff
changeset
|
142 anim.bind(on_complete=self._removeFromParent) |
168
397f2fb67aab
core (menu): animate transfer menu opening/closing + close it on [ESC]/back
Goffi <goffi@goffi.org>
parents:
126
diff
changeset
|
143 anim.start(self) |
197
c7d15ef4bfa8
core (menu): new EntitiesSelectorMenu:
Goffi <goffi@goffi.org>
parents:
184
diff
changeset
|
144 if self.callback_on_close: |
c7d15ef4bfa8
core (menu): new EntitiesSelectorMenu:
Goffi <goffi@goffi.org>
parents:
184
diff
changeset
|
145 self.do_callback() |
97
5d2289127bb7
menu (upload): better menu using dedicated widget:
Goffi <goffi@goffi.org>
parents:
88
diff
changeset
|
146 |
5d2289127bb7
menu (upload): better menu using dedicated widget:
Goffi <goffi@goffi.org>
parents:
88
diff
changeset
|
147 def on_touch_down(self, touch): |
5d2289127bb7
menu (upload): better menu using dedicated widget:
Goffi <goffi@goffi.org>
parents:
88
diff
changeset
|
148 # we remove the menu if we click outside |
5d2289127bb7
menu (upload): better menu using dedicated widget:
Goffi <goffi@goffi.org>
parents:
88
diff
changeset
|
149 # else we want to handle the event, but not |
5d2289127bb7
menu (upload): better menu using dedicated widget:
Goffi <goffi@goffi.org>
parents:
88
diff
changeset
|
150 # transmit it to parents |
5d2289127bb7
menu (upload): better menu using dedicated widget:
Goffi <goffi@goffi.org>
parents:
88
diff
changeset
|
151 if not self.collide_point(*touch.pos): |
168
397f2fb67aab
core (menu): animate transfer menu opening/closing + close it on [ESC]/back
Goffi <goffi@goffi.org>
parents:
126
diff
changeset
|
152 self.hide() |
86 | 153 else: |
197
c7d15ef4bfa8
core (menu): new EntitiesSelectorMenu:
Goffi <goffi@goffi.org>
parents:
184
diff
changeset
|
154 return super(SideMenu, self).on_touch_down(touch) |
97
5d2289127bb7
menu (upload): better menu using dedicated widget:
Goffi <goffi@goffi.org>
parents:
88
diff
changeset
|
155 return True |
86 | 156 |
168
397f2fb67aab
core (menu): animate transfer menu opening/closing + close it on [ESC]/back
Goffi <goffi@goffi.org>
parents:
126
diff
changeset
|
157 def key_input(self, window, key, scancode, codepoint, modifier): |
397f2fb67aab
core (menu): animate transfer menu opening/closing + close it on [ESC]/back
Goffi <goffi@goffi.org>
parents:
126
diff
changeset
|
158 if key == 27: |
397f2fb67aab
core (menu): animate transfer menu opening/closing + close it on [ESC]/back
Goffi <goffi@goffi.org>
parents:
126
diff
changeset
|
159 self.hide() |
397f2fb67aab
core (menu): animate transfer menu opening/closing + close it on [ESC]/back
Goffi <goffi@goffi.org>
parents:
126
diff
changeset
|
160 return True |
397f2fb67aab
core (menu): animate transfer menu opening/closing + close it on [ESC]/back
Goffi <goffi@goffi.org>
parents:
126
diff
changeset
|
161 |
197
c7d15ef4bfa8
core (menu): new EntitiesSelectorMenu:
Goffi <goffi@goffi.org>
parents:
184
diff
changeset
|
162 def onMenuCancelled(self, wid, cleaning_cb=None): |
c7d15ef4bfa8
core (menu): new EntitiesSelectorMenu:
Goffi <goffi@goffi.org>
parents:
184
diff
changeset
|
163 self._closeUI(wid) |
c7d15ef4bfa8
core (menu): new EntitiesSelectorMenu:
Goffi <goffi@goffi.org>
parents:
184
diff
changeset
|
164 if cleaning_cb is not None: |
c7d15ef4bfa8
core (menu): new EntitiesSelectorMenu:
Goffi <goffi@goffi.org>
parents:
184
diff
changeset
|
165 cleaning_cb() |
c7d15ef4bfa8
core (menu): new EntitiesSelectorMenu:
Goffi <goffi@goffi.org>
parents:
184
diff
changeset
|
166 |
86 | 167 def _closeUI(self, wid): |
168 G.host.closeUI() | |
169 | |
197
c7d15ef4bfa8
core (menu): new EntitiesSelectorMenu:
Goffi <goffi@goffi.org>
parents:
184
diff
changeset
|
170 def do_callback(self, *args, **kwargs): |
312 | 171 log.warning("callback not implemented") |
197
c7d15ef4bfa8
core (menu): new EntitiesSelectorMenu:
Goffi <goffi@goffi.org>
parents:
184
diff
changeset
|
172 |
c7d15ef4bfa8
core (menu): new EntitiesSelectorMenu:
Goffi <goffi@goffi.org>
parents:
184
diff
changeset
|
173 |
376 | 174 class ExtraMenuItem(Button): |
175 pass | |
176 | |
177 | |
178 class ExtraSideMenu(SideMenu): | |
179 """Menu with general app actions like showing the about widget""" | |
180 | |
181 def __init__(self, **kwargs): | |
182 super().__init__(**kwargs) | |
183 G.local_platform.on_extra_menu_init(self) | |
184 | |
185 def addItem(self, label, callback): | |
186 self.add_widget( | |
187 ExtraMenuItem( | |
188 text=label, | |
189 on_press=partial(self.onItemPress, callback=callback), | |
190 ), | |
191 # we want the new item above "About" and last empty Widget | |
192 index=2) | |
193 | |
194 def onItemPress(self, *args, callback): | |
195 self.hide() | |
196 callback() | |
197 | |
198 def onAbout(self): | |
199 self.hide() | |
200 about = AboutPopup() | |
201 about.title = ABOUT_TITLE | |
202 about.content = AboutContent( | |
203 text=ABOUT_CONTENT.format( | |
467
3693c662fa88
core (menu): update "about" text following renaming
Goffi <goffi@goffi.org>
parents:
461
diff
changeset
|
204 app_name = C.APP_NAME, |
3693c662fa88
core (menu): update "about" text following renaming
Goffi <goffi@goffi.org>
parents:
461
diff
changeset
|
205 app_name_alt = C.APP_NAME_ALT, |
3693c662fa88
core (menu): update "about" text following renaming
Goffi <goffi@goffi.org>
parents:
461
diff
changeset
|
206 app_component = C.APP_COMPONENT, |
376 | 207 backend_version = G.host.backend_version, |
467
3693c662fa88
core (menu): update "about" text following renaming
Goffi <goffi@goffi.org>
parents:
461
diff
changeset
|
208 version=G.host.version |
3693c662fa88
core (menu): update "about" text following renaming
Goffi <goffi@goffi.org>
parents:
461
diff
changeset
|
209 ), |
376 | 210 markup=True) |
211 about.open() | |
212 | |
213 | |
197
c7d15ef4bfa8
core (menu): new EntitiesSelectorMenu:
Goffi <goffi@goffi.org>
parents:
184
diff
changeset
|
214 class TransferMenu(SideMenu): |
c7d15ef4bfa8
core (menu): new EntitiesSelectorMenu:
Goffi <goffi@goffi.org>
parents:
184
diff
changeset
|
215 """transfer menu which handle display and callbacks""" |
c7d15ef4bfa8
core (menu): new EntitiesSelectorMenu:
Goffi <goffi@goffi.org>
parents:
184
diff
changeset
|
216 # callback will be called with path to file to transfer |
c7d15ef4bfa8
core (menu): new EntitiesSelectorMenu:
Goffi <goffi@goffi.org>
parents:
184
diff
changeset
|
217 # profiles if set will be sent to transfer widget, may be used to get specific files |
c7d15ef4bfa8
core (menu): new EntitiesSelectorMenu:
Goffi <goffi@goffi.org>
parents:
184
diff
changeset
|
218 profiles = properties.ObjectProperty() |
417
5b50b7ef2617
menu (TransferMenu): UI improvments:
Goffi <goffi@goffi.org>
parents:
415
diff
changeset
|
219 transfer_txt = properties.StringProperty() |
5b50b7ef2617
menu (TransferMenu): UI improvments:
Goffi <goffi@goffi.org>
parents:
415
diff
changeset
|
220 transfer_info = properties.ObjectProperty() |
5b50b7ef2617
menu (TransferMenu): UI improvments:
Goffi <goffi@goffi.org>
parents:
415
diff
changeset
|
221 upload_btn = properties.ObjectProperty() |
5b50b7ef2617
menu (TransferMenu): UI improvments:
Goffi <goffi@goffi.org>
parents:
415
diff
changeset
|
222 encrypted = properties.BooleanProperty(False) |
197
c7d15ef4bfa8
core (menu): new EntitiesSelectorMenu:
Goffi <goffi@goffi.org>
parents:
184
diff
changeset
|
223 items_layout = properties.ObjectProperty() |
216
e42e0c45d384
core (menu): allow to specify size in SideMenu:
Goffi <goffi@goffi.org>
parents:
197
diff
changeset
|
224 size_hint_close = (1, 0) |
e42e0c45d384
core (menu): allow to specify size in SideMenu:
Goffi <goffi@goffi.org>
parents:
197
diff
changeset
|
225 size_hint_open = (1, 0.5) |
197
c7d15ef4bfa8
core (menu): new EntitiesSelectorMenu:
Goffi <goffi@goffi.org>
parents:
184
diff
changeset
|
226 |
c7d15ef4bfa8
core (menu): new EntitiesSelectorMenu:
Goffi <goffi@goffi.org>
parents:
184
diff
changeset
|
227 def __init__(self, **kwargs): |
c7d15ef4bfa8
core (menu): new EntitiesSelectorMenu:
Goffi <goffi@goffi.org>
parents:
184
diff
changeset
|
228 super(TransferMenu, self).__init__(**kwargs) |
c7d15ef4bfa8
core (menu): new EntitiesSelectorMenu:
Goffi <goffi@goffi.org>
parents:
184
diff
changeset
|
229 if self.profiles is None: |
c7d15ef4bfa8
core (menu): new EntitiesSelectorMenu:
Goffi <goffi@goffi.org>
parents:
184
diff
changeset
|
230 self.profiles = iter(G.host.profiles) |
c7d15ef4bfa8
core (menu): new EntitiesSelectorMenu:
Goffi <goffi@goffi.org>
parents:
184
diff
changeset
|
231 for plug_info in G.host.getPluggedWidgets(type_=C.PLUG_TYPE_TRANSFER): |
c7d15ef4bfa8
core (menu): new EntitiesSelectorMenu:
Goffi <goffi@goffi.org>
parents:
184
diff
changeset
|
232 item = TransferItem( |
c7d15ef4bfa8
core (menu): new EntitiesSelectorMenu:
Goffi <goffi@goffi.org>
parents:
184
diff
changeset
|
233 plug_info = plug_info |
c7d15ef4bfa8
core (menu): new EntitiesSelectorMenu:
Goffi <goffi@goffi.org>
parents:
184
diff
changeset
|
234 ) |
c7d15ef4bfa8
core (menu): new EntitiesSelectorMenu:
Goffi <goffi@goffi.org>
parents:
184
diff
changeset
|
235 self.items_layout.add_widget(item) |
86 | 236 |
417
5b50b7ef2617
menu (TransferMenu): UI improvments:
Goffi <goffi@goffi.org>
parents:
415
diff
changeset
|
237 def on_kv_post(self, __): |
5b50b7ef2617
menu (TransferMenu): UI improvments:
Goffi <goffi@goffi.org>
parents:
415
diff
changeset
|
238 self.updateTransferInfo() |
5b50b7ef2617
menu (TransferMenu): UI improvments:
Goffi <goffi@goffi.org>
parents:
415
diff
changeset
|
239 |
5b50b7ef2617
menu (TransferMenu): UI improvments:
Goffi <goffi@goffi.org>
parents:
415
diff
changeset
|
240 def getTransferInfo(self): |
5b50b7ef2617
menu (TransferMenu): UI improvments:
Goffi <goffi@goffi.org>
parents:
415
diff
changeset
|
241 if self.upload_btn.state == "down": |
5b50b7ef2617
menu (TransferMenu): UI improvments:
Goffi <goffi@goffi.org>
parents:
415
diff
changeset
|
242 # upload |
5b50b7ef2617
menu (TransferMenu): UI improvments:
Goffi <goffi@goffi.org>
parents:
415
diff
changeset
|
243 if self.encrypted: |
5b50b7ef2617
menu (TransferMenu): UI improvments:
Goffi <goffi@goffi.org>
parents:
415
diff
changeset
|
244 return _( |
5b50b7ef2617
menu (TransferMenu): UI improvments:
Goffi <goffi@goffi.org>
parents:
415
diff
changeset
|
245 "The file will be [color=00aa00][b]encrypted[/b][/color] and sent to " |
5b50b7ef2617
menu (TransferMenu): UI improvments:
Goffi <goffi@goffi.org>
parents:
415
diff
changeset
|
246 "your server\nServer admin(s) can delete the file, but they won't be " |
5b50b7ef2617
menu (TransferMenu): UI improvments:
Goffi <goffi@goffi.org>
parents:
415
diff
changeset
|
247 "able to see its content" |
5b50b7ef2617
menu (TransferMenu): UI improvments:
Goffi <goffi@goffi.org>
parents:
415
diff
changeset
|
248 ) |
5b50b7ef2617
menu (TransferMenu): UI improvments:
Goffi <goffi@goffi.org>
parents:
415
diff
changeset
|
249 else: |
5b50b7ef2617
menu (TransferMenu): UI improvments:
Goffi <goffi@goffi.org>
parents:
415
diff
changeset
|
250 return _( |
5b50b7ef2617
menu (TransferMenu): UI improvments:
Goffi <goffi@goffi.org>
parents:
415
diff
changeset
|
251 "Beware! The file will be sent to your server and stay " |
5b50b7ef2617
menu (TransferMenu): UI improvments:
Goffi <goffi@goffi.org>
parents:
415
diff
changeset
|
252 "[color=ff0000][b]unencrypted[/b][/color] there\nServer admin(s) " |
5b50b7ef2617
menu (TransferMenu): UI improvments:
Goffi <goffi@goffi.org>
parents:
415
diff
changeset
|
253 "can see the file, and they choose how, when and if it will be " |
5b50b7ef2617
menu (TransferMenu): UI improvments:
Goffi <goffi@goffi.org>
parents:
415
diff
changeset
|
254 "deleted" |
5b50b7ef2617
menu (TransferMenu): UI improvments:
Goffi <goffi@goffi.org>
parents:
415
diff
changeset
|
255 ) |
5b50b7ef2617
menu (TransferMenu): UI improvments:
Goffi <goffi@goffi.org>
parents:
415
diff
changeset
|
256 else: |
5b50b7ef2617
menu (TransferMenu): UI improvments:
Goffi <goffi@goffi.org>
parents:
415
diff
changeset
|
257 # P2P |
5b50b7ef2617
menu (TransferMenu): UI improvments:
Goffi <goffi@goffi.org>
parents:
415
diff
changeset
|
258 if self.encrypted: |
5b50b7ef2617
menu (TransferMenu): UI improvments:
Goffi <goffi@goffi.org>
parents:
415
diff
changeset
|
259 return _( |
5b50b7ef2617
menu (TransferMenu): UI improvments:
Goffi <goffi@goffi.org>
parents:
415
diff
changeset
|
260 "The file will be sent [color=ff0000][b]unencrypted[/b][/color] " |
5b50b7ef2617
menu (TransferMenu): UI improvments:
Goffi <goffi@goffi.org>
parents:
415
diff
changeset
|
261 "directly to your contact (it may be transiting by the " |
5b50b7ef2617
menu (TransferMenu): UI improvments:
Goffi <goffi@goffi.org>
parents:
415
diff
changeset
|
262 "server if direct connection is not possible).\n[color=ff0000]" |
451 | 263 "Please note that end-to-end encryption is not yet implemented for " |
417
5b50b7ef2617
menu (TransferMenu): UI improvments:
Goffi <goffi@goffi.org>
parents:
415
diff
changeset
|
264 "P2P transfer." |
5b50b7ef2617
menu (TransferMenu): UI improvments:
Goffi <goffi@goffi.org>
parents:
415
diff
changeset
|
265 ) |
5b50b7ef2617
menu (TransferMenu): UI improvments:
Goffi <goffi@goffi.org>
parents:
415
diff
changeset
|
266 else: |
5b50b7ef2617
menu (TransferMenu): UI improvments:
Goffi <goffi@goffi.org>
parents:
415
diff
changeset
|
267 return _( |
5b50b7ef2617
menu (TransferMenu): UI improvments:
Goffi <goffi@goffi.org>
parents:
415
diff
changeset
|
268 "The file will be sent [color=ff0000][b]unencrypted[/b][/color] " |
5b50b7ef2617
menu (TransferMenu): UI improvments:
Goffi <goffi@goffi.org>
parents:
415
diff
changeset
|
269 "directly to your contact (it [i]may be[/i] transiting by the " |
5b50b7ef2617
menu (TransferMenu): UI improvments:
Goffi <goffi@goffi.org>
parents:
415
diff
changeset
|
270 "server if direct connection is not possible)." |
5b50b7ef2617
menu (TransferMenu): UI improvments:
Goffi <goffi@goffi.org>
parents:
415
diff
changeset
|
271 ) |
5b50b7ef2617
menu (TransferMenu): UI improvments:
Goffi <goffi@goffi.org>
parents:
415
diff
changeset
|
272 |
5b50b7ef2617
menu (TransferMenu): UI improvments:
Goffi <goffi@goffi.org>
parents:
415
diff
changeset
|
273 def updateTransferInfo(self): |
5b50b7ef2617
menu (TransferMenu): UI improvments:
Goffi <goffi@goffi.org>
parents:
415
diff
changeset
|
274 self.transfer_info.text = self.getTransferInfo() |
5b50b7ef2617
menu (TransferMenu): UI improvments:
Goffi <goffi@goffi.org>
parents:
415
diff
changeset
|
275 |
429
cebf657d78ef
core (menu): fixed transfer callback arguments order
Goffi <goffi@goffi.org>
parents:
417
diff
changeset
|
276 def _onTransferCb(self, file_path, cleaning_cb=None, external=False, wid_cont=None): |
400
71f51198478c
android: handle runtime permissions:
Goffi <goffi@goffi.org>
parents:
379
diff
changeset
|
277 if not external: |
71f51198478c
android: handle runtime permissions:
Goffi <goffi@goffi.org>
parents:
379
diff
changeset
|
278 wid = wid_cont[0] |
71f51198478c
android: handle runtime permissions:
Goffi <goffi@goffi.org>
parents:
379
diff
changeset
|
279 self._closeUI(wid) |
71f51198478c
android: handle runtime permissions:
Goffi <goffi@goffi.org>
parents:
379
diff
changeset
|
280 self.callback( |
71f51198478c
android: handle runtime permissions:
Goffi <goffi@goffi.org>
parents:
379
diff
changeset
|
281 file_path, |
71f51198478c
android: handle runtime permissions:
Goffi <goffi@goffi.org>
parents:
379
diff
changeset
|
282 transfer_type = (C.TRANSFER_UPLOAD |
71f51198478c
android: handle runtime permissions:
Goffi <goffi@goffi.org>
parents:
379
diff
changeset
|
283 if self.ids['upload_btn'].state == "down" else C.TRANSFER_SEND), |
71f51198478c
android: handle runtime permissions:
Goffi <goffi@goffi.org>
parents:
379
diff
changeset
|
284 cleaning_cb=cleaning_cb, |
71f51198478c
android: handle runtime permissions:
Goffi <goffi@goffi.org>
parents:
379
diff
changeset
|
285 ) |
71f51198478c
android: handle runtime permissions:
Goffi <goffi@goffi.org>
parents:
379
diff
changeset
|
286 |
71f51198478c
android: handle runtime permissions:
Goffi <goffi@goffi.org>
parents:
379
diff
changeset
|
287 def _check_plugin_permissions_cb(self, plug_info): |
71f51198478c
android: handle runtime permissions:
Goffi <goffi@goffi.org>
parents:
379
diff
changeset
|
288 external = plug_info.get('external', False) |
71f51198478c
android: handle runtime permissions:
Goffi <goffi@goffi.org>
parents:
379
diff
changeset
|
289 wid_cont = [] |
71f51198478c
android: handle runtime permissions:
Goffi <goffi@goffi.org>
parents:
379
diff
changeset
|
290 wid_cont.append(plug_info['factory']( |
71f51198478c
android: handle runtime permissions:
Goffi <goffi@goffi.org>
parents:
379
diff
changeset
|
291 plug_info, |
71f51198478c
android: handle runtime permissions:
Goffi <goffi@goffi.org>
parents:
379
diff
changeset
|
292 partial(self._onTransferCb, external=external, wid_cont=wid_cont), |
71f51198478c
android: handle runtime permissions:
Goffi <goffi@goffi.org>
parents:
379
diff
changeset
|
293 self.cancel_cb, |
71f51198478c
android: handle runtime permissions:
Goffi <goffi@goffi.org>
parents:
379
diff
changeset
|
294 self.profiles)) |
71f51198478c
android: handle runtime permissions:
Goffi <goffi@goffi.org>
parents:
379
diff
changeset
|
295 if not external: |
71f51198478c
android: handle runtime permissions:
Goffi <goffi@goffi.org>
parents:
379
diff
changeset
|
296 G.host.showExtraUI(wid_cont[0]) |
71f51198478c
android: handle runtime permissions:
Goffi <goffi@goffi.org>
parents:
379
diff
changeset
|
297 |
86 | 298 def do_callback(self, plug_info): |
97
5d2289127bb7
menu (upload): better menu using dedicated widget:
Goffi <goffi@goffi.org>
parents:
88
diff
changeset
|
299 self.parent.remove_widget(self) |
86 | 300 if self.callback is None: |
312 | 301 log.warning("TransferMenu callback is not set") |
86 | 302 else: |
400
71f51198478c
android: handle runtime permissions:
Goffi <goffi@goffi.org>
parents:
379
diff
changeset
|
303 G.local_platform.check_plugin_permissions( |
71f51198478c
android: handle runtime permissions:
Goffi <goffi@goffi.org>
parents:
379
diff
changeset
|
304 plug_info, |
71f51198478c
android: handle runtime permissions:
Goffi <goffi@goffi.org>
parents:
379
diff
changeset
|
305 callback=partial(self._check_plugin_permissions_cb, plug_info), |
71f51198478c
android: handle runtime permissions:
Goffi <goffi@goffi.org>
parents:
379
diff
changeset
|
306 errback=lambda: G.host.addNote( |
71f51198478c
android: handle runtime permissions:
Goffi <goffi@goffi.org>
parents:
379
diff
changeset
|
307 _("permission refused"), |
71f51198478c
android: handle runtime permissions:
Goffi <goffi@goffi.org>
parents:
379
diff
changeset
|
308 _("this transfer menu can't be used if you refuse the requested " |
71f51198478c
android: handle runtime permissions:
Goffi <goffi@goffi.org>
parents:
379
diff
changeset
|
309 "permission"), |
71f51198478c
android: handle runtime permissions:
Goffi <goffi@goffi.org>
parents:
379
diff
changeset
|
310 C.XMLUI_DATA_LVL_WARNING) |
71f51198478c
android: handle runtime permissions:
Goffi <goffi@goffi.org>
parents:
379
diff
changeset
|
311 ) |
197
c7d15ef4bfa8
core (menu): new EntitiesSelectorMenu:
Goffi <goffi@goffi.org>
parents:
184
diff
changeset
|
312 |
c7d15ef4bfa8
core (menu): new EntitiesSelectorMenu:
Goffi <goffi@goffi.org>
parents:
184
diff
changeset
|
313 |
c7d15ef4bfa8
core (menu): new EntitiesSelectorMenu:
Goffi <goffi@goffi.org>
parents:
184
diff
changeset
|
314 class EntitiesSelectorMenu(SideMenu, FilterBehavior): |
c7d15ef4bfa8
core (menu): new EntitiesSelectorMenu:
Goffi <goffi@goffi.org>
parents:
184
diff
changeset
|
315 """allow to select entities from roster""" |
c7d15ef4bfa8
core (menu): new EntitiesSelectorMenu:
Goffi <goffi@goffi.org>
parents:
184
diff
changeset
|
316 profiles = properties.ObjectProperty() |
c7d15ef4bfa8
core (menu): new EntitiesSelectorMenu:
Goffi <goffi@goffi.org>
parents:
184
diff
changeset
|
317 layout = properties.ObjectProperty() |
312 | 318 instructions = properties.StringProperty(_("Please select entities")) |
197
c7d15ef4bfa8
core (menu): new EntitiesSelectorMenu:
Goffi <goffi@goffi.org>
parents:
184
diff
changeset
|
319 filter_input = properties.ObjectProperty() |
216
e42e0c45d384
core (menu): allow to specify size in SideMenu:
Goffi <goffi@goffi.org>
parents:
197
diff
changeset
|
320 size_hint_close = (None, 1) |
e42e0c45d384
core (menu): allow to specify size in SideMenu:
Goffi <goffi@goffi.org>
parents:
197
diff
changeset
|
321 size_hint_open = (None, 1) |
e42e0c45d384
core (menu): allow to specify size in SideMenu:
Goffi <goffi@goffi.org>
parents:
197
diff
changeset
|
322 size_open = (dp(250), 100) |
e42e0c45d384
core (menu): allow to specify size in SideMenu:
Goffi <goffi@goffi.org>
parents:
197
diff
changeset
|
323 size_close = (0, 100) |
197
c7d15ef4bfa8
core (menu): new EntitiesSelectorMenu:
Goffi <goffi@goffi.org>
parents:
184
diff
changeset
|
324 |
c7d15ef4bfa8
core (menu): new EntitiesSelectorMenu:
Goffi <goffi@goffi.org>
parents:
184
diff
changeset
|
325 def __init__(self, **kwargs): |
c7d15ef4bfa8
core (menu): new EntitiesSelectorMenu:
Goffi <goffi@goffi.org>
parents:
184
diff
changeset
|
326 super(EntitiesSelectorMenu, self).__init__(**kwargs) |
c7d15ef4bfa8
core (menu): new EntitiesSelectorMenu:
Goffi <goffi@goffi.org>
parents:
184
diff
changeset
|
327 self.filter_input.bind(text=self.do_filter_input) |
c7d15ef4bfa8
core (menu): new EntitiesSelectorMenu:
Goffi <goffi@goffi.org>
parents:
184
diff
changeset
|
328 if self.profiles is None: |
c7d15ef4bfa8
core (menu): new EntitiesSelectorMenu:
Goffi <goffi@goffi.org>
parents:
184
diff
changeset
|
329 self.profiles = iter(G.host.profiles) |
c7d15ef4bfa8
core (menu): new EntitiesSelectorMenu:
Goffi <goffi@goffi.org>
parents:
184
diff
changeset
|
330 for profile in self.profiles: |
c7d15ef4bfa8
core (menu): new EntitiesSelectorMenu:
Goffi <goffi@goffi.org>
parents:
184
diff
changeset
|
331 for jid_, jid_data in G.host.contact_lists[profile].all_iter: |
c7d15ef4bfa8
core (menu): new EntitiesSelectorMenu:
Goffi <goffi@goffi.org>
parents:
184
diff
changeset
|
332 jid_wid = JidToggle( |
c7d15ef4bfa8
core (menu): new EntitiesSelectorMenu:
Goffi <goffi@goffi.org>
parents:
184
diff
changeset
|
333 jid=jid_, |
c7d15ef4bfa8
core (menu): new EntitiesSelectorMenu:
Goffi <goffi@goffi.org>
parents:
184
diff
changeset
|
334 profile=profile) |
c7d15ef4bfa8
core (menu): new EntitiesSelectorMenu:
Goffi <goffi@goffi.org>
parents:
184
diff
changeset
|
335 self.layout.add_widget(jid_wid) |
c7d15ef4bfa8
core (menu): new EntitiesSelectorMenu:
Goffi <goffi@goffi.org>
parents:
184
diff
changeset
|
336 |
c7d15ef4bfa8
core (menu): new EntitiesSelectorMenu:
Goffi <goffi@goffi.org>
parents:
184
diff
changeset
|
337 def do_callback(self): |
c7d15ef4bfa8
core (menu): new EntitiesSelectorMenu:
Goffi <goffi@goffi.org>
parents:
184
diff
changeset
|
338 if self.callback is not None: |
c7d15ef4bfa8
core (menu): new EntitiesSelectorMenu:
Goffi <goffi@goffi.org>
parents:
184
diff
changeset
|
339 jids = [c.jid for c in self.layout.children if c.state == 'down'] |
c7d15ef4bfa8
core (menu): new EntitiesSelectorMenu:
Goffi <goffi@goffi.org>
parents:
184
diff
changeset
|
340 self.callback(jids) |
c7d15ef4bfa8
core (menu): new EntitiesSelectorMenu:
Goffi <goffi@goffi.org>
parents:
184
diff
changeset
|
341 |
c7d15ef4bfa8
core (menu): new EntitiesSelectorMenu:
Goffi <goffi@goffi.org>
parents:
184
diff
changeset
|
342 def do_filter_input(self, filter_input, text): |
c7d15ef4bfa8
core (menu): new EntitiesSelectorMenu:
Goffi <goffi@goffi.org>
parents:
184
diff
changeset
|
343 self.layout.spacing = 0 if text else dp(5) |
404
f7476818f9fb
core (common): JidSelector + behaviors various improvments:
Goffi <goffi@goffi.org>
parents:
400
diff
changeset
|
344 self.do_filter(self.layout, |
197
c7d15ef4bfa8
core (menu): new EntitiesSelectorMenu:
Goffi <goffi@goffi.org>
parents:
184
diff
changeset
|
345 text, |
c7d15ef4bfa8
core (menu): new EntitiesSelectorMenu:
Goffi <goffi@goffi.org>
parents:
184
diff
changeset
|
346 lambda c: c.jid, |
c7d15ef4bfa8
core (menu): new EntitiesSelectorMenu:
Goffi <goffi@goffi.org>
parents:
184
diff
changeset
|
347 width_cb=lambda c: c.width, |
c7d15ef4bfa8
core (menu): new EntitiesSelectorMenu:
Goffi <goffi@goffi.org>
parents:
184
diff
changeset
|
348 height_cb=lambda c: dp(70)) |