annotate libervia/desktop_kivy/plugins/plugin_transfer_file.py @ 499:f387992d8e37

plugins: new "call" plugin for A/V calls: this is the base implementation for calls plugin, handling one2one calls. For now, the interface is very basic, call is done by specifying the bare jid of the destinee, then press the "call" button. Incoming calls are automatically accepted. rel 424
author Goffi <goffi@goffi.org>
date Wed, 04 Oct 2023 22:54:36 +0200
parents b3cedbee561d
children d78728d7fd6a
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
493
b3cedbee561d refactoring: rename `cagou` to `libervia.desktop_kivy` + update imports and names following backend changes
Goffi <goffi@goffi.org>
parents: 491
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
279
aea973de55d9 transfer (file): use native file chooser on desktop:
Goffi <goffi@goffi.org>
parents: 126
diff changeset
20 import threading
aea973de55d9 transfer (file): use native file chooser on desktop:
Goffi <goffi@goffi.org>
parents: 126
diff changeset
21 import sys
aea973de55d9 transfer (file): use native file chooser on desktop:
Goffi <goffi@goffi.org>
parents: 126
diff changeset
22 from functools import partial
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 _
86
c711be670ecd core, chat: upload plugin system:
Goffi <goffi@goffi.org>
parents:
diff changeset
25 from kivy.uix.boxlayout import BoxLayout
c711be670ecd core, chat: upload plugin system:
Goffi <goffi@goffi.org>
parents:
diff changeset
26 from kivy import properties
279
aea973de55d9 transfer (file): use native file chooser on desktop:
Goffi <goffi@goffi.org>
parents: 126
diff changeset
27 from kivy.clock import Clock
aea973de55d9 transfer (file): use native file chooser on desktop:
Goffi <goffi@goffi.org>
parents: 126
diff changeset
28 from plyer import filechooser, storagepath
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
97
5d2289127bb7 menu (upload): better menu using dedicated widget:
Goffi <goffi@goffi.org>
parents: 86
diff changeset
47 class FileTransmitter(BoxLayout):
86
c711be670ecd core, chat: upload plugin system:
Goffi <goffi@goffi.org>
parents:
diff changeset
48 callback = properties.ObjectProperty()
c711be670ecd core, chat: upload plugin system:
Goffi <goffi@goffi.org>
parents:
diff changeset
49 cancel_cb = properties.ObjectProperty()
279
aea973de55d9 transfer (file): use native file chooser on desktop:
Goffi <goffi@goffi.org>
parents: 126
diff changeset
50 native_filechooser = True
aea973de55d9 transfer (file): use native file chooser on desktop:
Goffi <goffi@goffi.org>
parents: 126
diff changeset
51 default_path = storagepath.get_home_dir()
86
c711be670ecd core, chat: upload plugin system:
Goffi <goffi@goffi.org>
parents:
diff changeset
52
279
aea973de55d9 transfer (file): use native file chooser on desktop:
Goffi <goffi@goffi.org>
parents: 126
diff changeset
53 def __init__(self, *args, **kwargs):
aea973de55d9 transfer (file): use native file chooser on desktop:
Goffi <goffi@goffi.org>
parents: 126
diff changeset
54 if sys.platform == 'android':
aea973de55d9 transfer (file): use native file chooser on desktop:
Goffi <goffi@goffi.org>
parents: 126
diff changeset
55 self.native_filechooser = False
aea973de55d9 transfer (file): use native file chooser on desktop:
Goffi <goffi@goffi.org>
parents: 126
diff changeset
56 self.default_path = storagepath.get_downloads_dir()
aea973de55d9 transfer (file): use native file chooser on desktop:
Goffi <goffi@goffi.org>
parents: 126
diff changeset
57
aea973de55d9 transfer (file): use native file chooser on desktop:
Goffi <goffi@goffi.org>
parents: 126
diff changeset
58 super(FileTransmitter, self).__init__(*args, **kwargs)
aea973de55d9 transfer (file): use native file chooser on desktop:
Goffi <goffi@goffi.org>
parents: 126
diff changeset
59
aea973de55d9 transfer (file): use native file chooser on desktop:
Goffi <goffi@goffi.org>
parents: 126
diff changeset
60 if self.native_filechooser:
491
203755bbe0fe massive refactoring from camelCase -> snake_case. See backend commit log for more details
Goffi <goffi@goffi.org>
parents: 461
diff changeset
61 thread = threading.Thread(target=self._native_file_chooser)
279
aea973de55d9 transfer (file): use native file chooser on desktop:
Goffi <goffi@goffi.org>
parents: 126
diff changeset
62 thread.start()
aea973de55d9 transfer (file): use native file chooser on desktop:
Goffi <goffi@goffi.org>
parents: 126
diff changeset
63 else:
aea973de55d9 transfer (file): use native file chooser on desktop:
Goffi <goffi@goffi.org>
parents: 126
diff changeset
64 self.add_widget(FileChooserBox(default_path = self.default_path,
491
203755bbe0fe massive refactoring from camelCase -> snake_case. See backend commit log for more details
Goffi <goffi@goffi.org>
parents: 461
diff changeset
65 callback=self.on_files,
279
aea973de55d9 transfer (file): use native file chooser on desktop:
Goffi <goffi@goffi.org>
parents: 126
diff changeset
66 cancel_cb=partial(self.cancel_cb, self)))
aea973de55d9 transfer (file): use native file chooser on desktop:
Goffi <goffi@goffi.org>
parents: 126
diff changeset
67
491
203755bbe0fe massive refactoring from camelCase -> snake_case. See backend commit log for more details
Goffi <goffi@goffi.org>
parents: 461
diff changeset
68 def _native_file_chooser(self, *args, **kwargs):
312
772c170b47a9 Python3 port:
Goffi <goffi@goffi.org>
parents: 282
diff changeset
69 title=_("Please select a file to upload")
279
aea973de55d9 transfer (file): use native file chooser on desktop:
Goffi <goffi@goffi.org>
parents: 126
diff changeset
70 files = filechooser.open_file(title=title,
aea973de55d9 transfer (file): use native file chooser on desktop:
Goffi <goffi@goffi.org>
parents: 126
diff changeset
71 path=self.default_path,
aea973de55d9 transfer (file): use native file chooser on desktop:
Goffi <goffi@goffi.org>
parents: 126
diff changeset
72 multiple=False,
aea973de55d9 transfer (file): use native file chooser on desktop:
Goffi <goffi@goffi.org>
parents: 126
diff changeset
73 preview=True)
491
203755bbe0fe massive refactoring from camelCase -> snake_case. See backend commit log for more details
Goffi <goffi@goffi.org>
parents: 461
diff changeset
74 # we want to leave the thread when calling on_files, so we use Clock
203755bbe0fe massive refactoring from camelCase -> snake_case. See backend commit log for more details
Goffi <goffi@goffi.org>
parents: 461
diff changeset
75 Clock.schedule_once(lambda *args: self.on_files(files=files), 0)
279
aea973de55d9 transfer (file): use native file chooser on desktop:
Goffi <goffi@goffi.org>
parents: 126
diff changeset
76
491
203755bbe0fe massive refactoring from camelCase -> snake_case. See backend commit log for more details
Goffi <goffi@goffi.org>
parents: 461
diff changeset
77 def on_files(self, files):
279
aea973de55d9 transfer (file): use native file chooser on desktop:
Goffi <goffi@goffi.org>
parents: 126
diff changeset
78 if files:
aea973de55d9 transfer (file): use native file chooser on desktop:
Goffi <goffi@goffi.org>
parents: 126
diff changeset
79 self.callback(files[0])
aea973de55d9 transfer (file): use native file chooser on desktop:
Goffi <goffi@goffi.org>
parents: 126
diff changeset
80 else:
aea973de55d9 transfer (file): use native file chooser on desktop:
Goffi <goffi@goffi.org>
parents: 126
diff changeset
81 self.cancel_cb(self)