annotate libervia/desktop_kivy/plugins/plugin_transfer_file.py @ 514:d78728d7fd6a

plugin wid calls, core: implements WebRTC DataChannel file transfer: - Add a new "file" icon in call UI to send a file via WebRTC. - Handle new preflight mechanism, and WebRTC file transfer. - Native file chooser handling has been moved to new `core.file_chooser` module, and now supports "save" and "dir" modes (based on `plyer`). rel 442
author Goffi <goffi@goffi.org>
date Sat, 06 Apr 2024 13:37:27 +0200
parents b3cedbee561d
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
379
1da3c379205b fixed shebangs
Goffi <goffi@goffi.org>
parents: 378
diff changeset
1 #!/usr/bin/env python3
1da3c379205b fixed shebangs
Goffi <goffi@goffi.org>
parents: 378
diff changeset
2
86
c711be670ecd core, chat: upload plugin system:
Goffi <goffi@goffi.org>
parents:
diff changeset
3
514
d78728d7fd6a plugin wid calls, core: implements WebRTC DataChannel file transfer:
Goffi <goffi@goffi.org>
parents: 493
diff changeset
4 # Libervia Desktop-Kivy
461
3c9ba4a694ef dates update
Goffi <goffi@goffi.org>
parents: 379
diff changeset
5 # Copyright (C) 2016-2021 Jérôme Poisson (goffi@goffi.org)
86
c711be670ecd core, chat: upload plugin system:
Goffi <goffi@goffi.org>
parents:
diff changeset
6
c711be670ecd core, chat: upload plugin system:
Goffi <goffi@goffi.org>
parents:
diff changeset
7 # This program is free software: you can redistribute it and/or modify
c711be670ecd core, chat: upload plugin system:
Goffi <goffi@goffi.org>
parents:
diff changeset
8 # it under the terms of the GNU Affero General Public License as published by
c711be670ecd core, chat: upload plugin system:
Goffi <goffi@goffi.org>
parents:
diff changeset
9 # the Free Software Foundation, either version 3 of the License, or
c711be670ecd core, chat: upload plugin system:
Goffi <goffi@goffi.org>
parents:
diff changeset
10 # (at your option) any later version.
c711be670ecd core, chat: upload plugin system:
Goffi <goffi@goffi.org>
parents:
diff changeset
11
c711be670ecd core, chat: upload plugin system:
Goffi <goffi@goffi.org>
parents:
diff changeset
12 # This program is distributed in the hope that it will be useful,
c711be670ecd core, chat: upload plugin system:
Goffi <goffi@goffi.org>
parents:
diff changeset
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of
c711be670ecd core, chat: upload plugin system:
Goffi <goffi@goffi.org>
parents:
diff changeset
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
c711be670ecd core, chat: upload plugin system:
Goffi <goffi@goffi.org>
parents:
diff changeset
15 # GNU Affero General Public License for more details.
c711be670ecd core, chat: upload plugin system:
Goffi <goffi@goffi.org>
parents:
diff changeset
16
c711be670ecd core, chat: upload plugin system:
Goffi <goffi@goffi.org>
parents:
diff changeset
17 # You should have received a copy of the GNU Affero General Public License
c711be670ecd core, chat: upload plugin system:
Goffi <goffi@goffi.org>
parents:
diff changeset
18 # along with this program. If not, see <http://www.gnu.org/licenses/>.
c711be670ecd core, chat: upload plugin system:
Goffi <goffi@goffi.org>
parents:
diff changeset
19
514
d78728d7fd6a plugin wid calls, core: implements WebRTC DataChannel file transfer:
Goffi <goffi@goffi.org>
parents: 493
diff changeset
20 from functools import partial
279
aea973de55d9 transfer (file): use native file chooser on desktop:
Goffi <goffi@goffi.org>
parents: 126
diff changeset
21 import sys
514
d78728d7fd6a plugin wid calls, core: implements WebRTC DataChannel file transfer:
Goffi <goffi@goffi.org>
parents: 493
diff changeset
22
493
b3cedbee561d refactoring: rename `cagou` to `libervia.desktop_kivy` + update imports and names following backend changes
Goffi <goffi@goffi.org>
parents: 491
diff changeset
23 from libervia.backend.core import log as logging
b3cedbee561d refactoring: rename `cagou` to `libervia.desktop_kivy` + update imports and names following backend changes
Goffi <goffi@goffi.org>
parents: 491
diff changeset
24 from libervia.backend.core.i18n import _
514
d78728d7fd6a plugin wid calls, core: implements WebRTC DataChannel file transfer:
Goffi <goffi@goffi.org>
parents: 493
diff changeset
25
86
c711be670ecd core, chat: upload plugin system:
Goffi <goffi@goffi.org>
parents:
diff changeset
26 from kivy import properties
514
d78728d7fd6a plugin wid calls, core: implements WebRTC DataChannel file transfer:
Goffi <goffi@goffi.org>
parents: 493
diff changeset
27 from kivy.uix.boxlayout import BoxLayout
d78728d7fd6a plugin wid calls, core: implements WebRTC DataChannel file transfer:
Goffi <goffi@goffi.org>
parents: 493
diff changeset
28 from libervia.desktop_kivy.core import file_chooser
279
aea973de55d9 transfer (file): use native file chooser on desktop:
Goffi <goffi@goffi.org>
parents: 126
diff changeset
29
aea973de55d9 transfer (file): use native file chooser on desktop:
Goffi <goffi@goffi.org>
parents: 126
diff changeset
30 log = logging.getLogger(__name__)
86
c711be670ecd core, chat: upload plugin system:
Goffi <goffi@goffi.org>
parents:
diff changeset
31
c711be670ecd core, chat: upload plugin system:
Goffi <goffi@goffi.org>
parents:
diff changeset
32
c711be670ecd core, chat: upload plugin system:
Goffi <goffi@goffi.org>
parents:
diff changeset
33 PLUGIN_INFO = {
312
772c170b47a9 Python3 port:
Goffi <goffi@goffi.org>
parents: 282
diff changeset
34 "name": _("file"),
97
5d2289127bb7 menu (upload): better menu using dedicated widget:
Goffi <goffi@goffi.org>
parents: 86
diff changeset
35 "main": "FileTransmitter",
312
772c170b47a9 Python3 port:
Goffi <goffi@goffi.org>
parents: 282
diff changeset
36 "description": _("transmit a local file"),
772c170b47a9 Python3 port:
Goffi <goffi@goffi.org>
parents: 282
diff changeset
37 "icon_medium": "{media}/icons/muchoslava/png/fichier_50.png",
86
c711be670ecd core, chat: upload plugin system:
Goffi <goffi@goffi.org>
parents:
diff changeset
38 }
c711be670ecd core, chat: upload plugin system:
Goffi <goffi@goffi.org>
parents:
diff changeset
39
c711be670ecd core, chat: upload plugin system:
Goffi <goffi@goffi.org>
parents:
diff changeset
40
279
aea973de55d9 transfer (file): use native file chooser on desktop:
Goffi <goffi@goffi.org>
parents: 126
diff changeset
41 class FileChooserBox(BoxLayout):
aea973de55d9 transfer (file): use native file chooser on desktop:
Goffi <goffi@goffi.org>
parents: 126
diff changeset
42 callback = properties.ObjectProperty()
aea973de55d9 transfer (file): use native file chooser on desktop:
Goffi <goffi@goffi.org>
parents: 126
diff changeset
43 cancel_cb = properties.ObjectProperty()
aea973de55d9 transfer (file): use native file chooser on desktop:
Goffi <goffi@goffi.org>
parents: 126
diff changeset
44 default_path = properties.StringProperty()
aea973de55d9 transfer (file): use native file chooser on desktop:
Goffi <goffi@goffi.org>
parents: 126
diff changeset
45
aea973de55d9 transfer (file): use native file chooser on desktop:
Goffi <goffi@goffi.org>
parents: 126
diff changeset
46
514
d78728d7fd6a plugin wid calls, core: implements WebRTC DataChannel file transfer:
Goffi <goffi@goffi.org>
parents: 493
diff changeset
47 class FileTransmitter(BoxLayout, file_chooser.FileChooser):
d78728d7fd6a plugin wid calls, core: implements WebRTC DataChannel file transfer:
Goffi <goffi@goffi.org>
parents: 493
diff changeset
48 """Widget to transmit files"""
86
c711be670ecd core, chat: upload plugin system:
Goffi <goffi@goffi.org>
parents:
diff changeset
49
279
aea973de55d9 transfer (file): use native file chooser on desktop:
Goffi <goffi@goffi.org>
parents: 126
diff changeset
50 def __init__(self, *args, **kwargs):
514
d78728d7fd6a plugin wid calls, core: implements WebRTC DataChannel file transfer:
Goffi <goffi@goffi.org>
parents: 493
diff changeset
51 if sys.platform == "android":
279
aea973de55d9 transfer (file): use native file chooser on desktop:
Goffi <goffi@goffi.org>
parents: 126
diff changeset
52 self.native_filechooser = False
aea973de55d9 transfer (file): use native file chooser on desktop:
Goffi <goffi@goffi.org>
parents: 126
diff changeset
53 self.default_path = storagepath.get_downloads_dir()
aea973de55d9 transfer (file): use native file chooser on desktop:
Goffi <goffi@goffi.org>
parents: 126
diff changeset
54
514
d78728d7fd6a plugin wid calls, core: implements WebRTC DataChannel file transfer:
Goffi <goffi@goffi.org>
parents: 493
diff changeset
55 super().__init__(*args, **kwargs)
279
aea973de55d9 transfer (file): use native file chooser on desktop:
Goffi <goffi@goffi.org>
parents: 126
diff changeset
56
aea973de55d9 transfer (file): use native file chooser on desktop:
Goffi <goffi@goffi.org>
parents: 126
diff changeset
57 if self.native_filechooser:
514
d78728d7fd6a plugin wid calls, core: implements WebRTC DataChannel file transfer:
Goffi <goffi@goffi.org>
parents: 493
diff changeset
58 self.open()
279
aea973de55d9 transfer (file): use native file chooser on desktop:
Goffi <goffi@goffi.org>
parents: 126
diff changeset
59 else:
514
d78728d7fd6a plugin wid calls, core: implements WebRTC DataChannel file transfer:
Goffi <goffi@goffi.org>
parents: 493
diff changeset
60 self.add_widget(
d78728d7fd6a plugin wid calls, core: implements WebRTC DataChannel file transfer:
Goffi <goffi@goffi.org>
parents: 493
diff changeset
61 FileChooserBox(
d78728d7fd6a plugin wid calls, core: implements WebRTC DataChannel file transfer:
Goffi <goffi@goffi.org>
parents: 493
diff changeset
62 default_path=self.default_path,
d78728d7fd6a plugin wid calls, core: implements WebRTC DataChannel file transfer:
Goffi <goffi@goffi.org>
parents: 493
diff changeset
63 callback=self.on_files,
d78728d7fd6a plugin wid calls, core: implements WebRTC DataChannel file transfer:
Goffi <goffi@goffi.org>
parents: 493
diff changeset
64 cancel_cb=partial(self.cancel_cb, self),
d78728d7fd6a plugin wid calls, core: implements WebRTC DataChannel file transfer:
Goffi <goffi@goffi.org>
parents: 493
diff changeset
65 )
d78728d7fd6a plugin wid calls, core: implements WebRTC DataChannel file transfer:
Goffi <goffi@goffi.org>
parents: 493
diff changeset
66 )