annotate libervia/desktop_kivy/core/cagou_main.py @ 514:d78728d7fd6a default tip

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 bbef1a413515
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
322
e2b51663d8b8 core, android: new share widget + added Cagou to "share" menu:
Goffi <goffi@goffi.org>
parents: 318
diff changeset
1 #!/usr/bin/env python3
0
160cc95ad7ea initial commit:
Goffi <goffi@goffi.org>
parents:
diff changeset
2
493
b3cedbee561d refactoring: rename `cagou` to `libervia.desktop_kivy` + update imports and names following backend changes
Goffi <goffi@goffi.org>
parents: 491
diff changeset
3 #Libervia Desktop-Kivy
461
3c9ba4a694ef dates update
Goffi <goffi@goffi.org>
parents: 445
diff changeset
4 # Copyright (C) 2016-2021 Jérôme Poisson (goffi@goffi.org)
0
160cc95ad7ea initial commit:
Goffi <goffi@goffi.org>
parents:
diff changeset
5
160cc95ad7ea initial commit:
Goffi <goffi@goffi.org>
parents:
diff changeset
6 # This program is free software: you can redistribute it and/or modify
160cc95ad7ea initial commit:
Goffi <goffi@goffi.org>
parents:
diff changeset
7 # it under the terms of the GNU Affero General Public License as published by
160cc95ad7ea initial commit:
Goffi <goffi@goffi.org>
parents:
diff changeset
8 # the Free Software Foundation, either version 3 of the License, or
160cc95ad7ea initial commit:
Goffi <goffi@goffi.org>
parents:
diff changeset
9 # (at your option) any later version.
160cc95ad7ea initial commit:
Goffi <goffi@goffi.org>
parents:
diff changeset
10
160cc95ad7ea initial commit:
Goffi <goffi@goffi.org>
parents:
diff changeset
11 # This program is distributed in the hope that it will be useful,
160cc95ad7ea initial commit:
Goffi <goffi@goffi.org>
parents:
diff changeset
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
160cc95ad7ea initial commit:
Goffi <goffi@goffi.org>
parents:
diff changeset
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
160cc95ad7ea initial commit:
Goffi <goffi@goffi.org>
parents:
diff changeset
14 # GNU Affero General Public License for more details.
160cc95ad7ea initial commit:
Goffi <goffi@goffi.org>
parents:
diff changeset
15
160cc95ad7ea initial commit:
Goffi <goffi@goffi.org>
parents:
diff changeset
16 # You should have received a copy of the GNU Affero General Public License
160cc95ad7ea initial commit:
Goffi <goffi@goffi.org>
parents:
diff changeset
17 # along with this program. If not, see <http://www.gnu.org/licenses/>.
160cc95ad7ea initial commit:
Goffi <goffi@goffi.org>
parents:
diff changeset
18
160cc95ad7ea initial commit:
Goffi <goffi@goffi.org>
parents:
diff changeset
19
498
3b627382e681 core: support async methods and bridge
Goffi <goffi@goffi.org>
parents: 497
diff changeset
20 import asyncio
285
3f7e227aab00 core: disable multitouch emulation with mouse
Goffi <goffi@goffi.org>
parents: 284
diff changeset
21 import os.path
3f7e227aab00 core: disable multitouch emulation with mouse
Goffi <goffi@goffi.org>
parents: 284
diff changeset
22 import glob
3f7e227aab00 core: disable multitouch emulation with mouse
Goffi <goffi@goffi.org>
parents: 284
diff changeset
23 import sys
414
72a6b06728ab core: file dropping:
Goffi <goffi@goffi.org>
parents: 402
diff changeset
24 from pathlib import Path
514
d78728d7fd6a plugin wid calls, core: implements WebRTC DataChannel file transfer:
Goffi <goffi@goffi.org>
parents: 505
diff changeset
25 from typing import Callable
420
83d184393fe1 core: downloadURL helper method
Goffi <goffi@goffi.org>
parents: 419
diff changeset
26 from urllib import parse as urlparse
388
de066b72f5a8 core: cache MUC bookmarks on startup
Goffi <goffi@goffi.org>
parents: 385
diff changeset
27 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
28 from libervia.backend.core.i18n import _
514
d78728d7fd6a plugin wid calls, core: implements WebRTC DataChannel file transfer:
Goffi <goffi@goffi.org>
parents: 505
diff changeset
29
d78728d7fd6a plugin wid calls, core: implements WebRTC DataChannel file transfer:
Goffi <goffi@goffi.org>
parents: 505
diff changeset
30 # `do_hack` msut be run before any Kivy import!
119
1bbbe26846f4 buildozer: moved sat.conf in a specific dir (platform/android), so it's not used on desktop
Goffi <goffi@goffi.org>
parents: 112
diff changeset
31 from . import kivy_hack
48
028a98983e46 core: avoid kivy arguments hijacking so QuickApp arguments parsing can be used
Goffi <goffi@goffi.org>
parents: 44
diff changeset
32 kivy_hack.do_hack()
312
772c170b47a9 Python3 port:
Goffi <goffi@goffi.org>
parents: 302
diff changeset
33 from .constants import Const as C
493
b3cedbee561d refactoring: rename `cagou` to `libervia.desktop_kivy` + update imports and names following backend changes
Goffi <goffi@goffi.org>
parents: 491
diff changeset
34 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
35 from libervia.backend.core import exceptions
514
d78728d7fd6a plugin wid calls, core: implements WebRTC DataChannel file transfer:
Goffi <goffi@goffi.org>
parents: 505
diff changeset
36 from libervia.desktop_kivy.core.file_chooser import FileChooser
493
b3cedbee561d refactoring: rename `cagou` to `libervia.desktop_kivy` + update imports and names following backend changes
Goffi <goffi@goffi.org>
parents: 491
diff changeset
37 from libervia.frontends.quick_frontend.quick_app import QuickApp
b3cedbee561d refactoring: rename `cagou` to `libervia.desktop_kivy` + update imports and names following backend changes
Goffi <goffi@goffi.org>
parents: 491
diff changeset
38 from libervia.frontends.quick_frontend import quick_widgets
b3cedbee561d refactoring: rename `cagou` to `libervia.desktop_kivy` + update imports and names following backend changes
Goffi <goffi@goffi.org>
parents: 491
diff changeset
39 from libervia.frontends.quick_frontend import quick_chat
b3cedbee561d refactoring: rename `cagou` to `libervia.desktop_kivy` + update imports and names following backend changes
Goffi <goffi@goffi.org>
parents: 491
diff changeset
40 from libervia.frontends.quick_frontend import quick_utils
514
d78728d7fd6a plugin wid calls, core: implements WebRTC DataChannel file transfer:
Goffi <goffi@goffi.org>
parents: 505
diff changeset
41 from libervia.frontends.tools import aio, jid
493
b3cedbee561d refactoring: rename `cagou` to `libervia.desktop_kivy` + update imports and names following backend changes
Goffi <goffi@goffi.org>
parents: 491
diff changeset
42 from libervia.backend.tools import utils as libervia_utils
b3cedbee561d refactoring: rename `cagou` to `libervia.desktop_kivy` + update imports and names following backend changes
Goffi <goffi@goffi.org>
parents: 491
diff changeset
43 from libervia.backend.tools import config
b3cedbee561d refactoring: rename `cagou` to `libervia.desktop_kivy` + update imports and names following backend changes
Goffi <goffi@goffi.org>
parents: 491
diff changeset
44 from libervia.backend.tools.common import data_format
b3cedbee561d refactoring: rename `cagou` to `libervia.desktop_kivy` + update imports and names following backend changes
Goffi <goffi@goffi.org>
parents: 491
diff changeset
45 from libervia.backend.tools.common import dynamic_import
b3cedbee561d refactoring: rename `cagou` to `libervia.desktop_kivy` + update imports and names following backend changes
Goffi <goffi@goffi.org>
parents: 491
diff changeset
46 from libervia.backend.tools.common import files_utils
0
160cc95ad7ea initial commit:
Goffi <goffi@goffi.org>
parents:
diff changeset
47 import kivy
322
e2b51663d8b8 core, android: new share widget + added Cagou to "share" menu:
Goffi <goffi@goffi.org>
parents: 318
diff changeset
48 kivy.require('1.11.0')
0
160cc95ad7ea initial commit:
Goffi <goffi@goffi.org>
parents:
diff changeset
49 import kivy.support
491
203755bbe0fe massive refactoring from camelCase -> snake_case. See backend commit log for more details
Goffi <goffi@goffi.org>
parents: 487
diff changeset
50 main_config = config.parse_main_conf(log_filenames=True)
203755bbe0fe massive refactoring from camelCase -> snake_case. See backend commit log for more details
Goffi <goffi@goffi.org>
parents: 487
diff changeset
51 bridge_name = config.config_get(main_config, '', 'bridge', 'dbus')
60
35abe494e6c7 core: bridge selection + improvments for android
Goffi <goffi@goffi.org>
parents: 52
diff changeset
52 # FIXME: event loop is choosen according to bridge_name, a better way should be used
63
af4f986d86f0 core: pb bridge implementation:
Goffi <goffi@goffi.org>
parents: 61
diff changeset
53 if 'dbus' in bridge_name:
af4f986d86f0 core: pb bridge implementation:
Goffi <goffi@goffi.org>
parents: 61
diff changeset
54 kivy.support.install_gobject_iteration()
af4f986d86f0 core: pb bridge implementation:
Goffi <goffi@goffi.org>
parents: 61
diff changeset
55 elif bridge_name in ('pb', 'embedded'):
60
35abe494e6c7 core: bridge selection + improvments for android
Goffi <goffi@goffi.org>
parents: 52
diff changeset
56 kivy.support.install_twisted_reactor()
0
160cc95ad7ea initial commit:
Goffi <goffi@goffi.org>
parents:
diff changeset
57 from kivy.app import App
14
21a432afd06d plugin system, first draft:
Goffi <goffi@goffi.org>
parents: 13
diff changeset
58 from kivy.lang import Builder
29
8b5827c43155 notes first draft:
Goffi <goffi@goffi.org>
parents: 28
diff changeset
59 from kivy import properties
312
772c170b47a9 Python3 port:
Goffi <goffi@goffi.org>
parents: 302
diff changeset
60 from . import xmlui
772c170b47a9 Python3 port:
Goffi <goffi@goffi.org>
parents: 302
diff changeset
61 from .profile_manager import ProfileManager
29
8b5827c43155 notes first draft:
Goffi <goffi@goffi.org>
parents: 28
diff changeset
62 from kivy.clock import Clock
8b5827c43155 notes first draft:
Goffi <goffi@goffi.org>
parents: 28
diff changeset
63 from kivy.uix.label import Label
9
7b0a53d2afd3 contact list: first draft
Goffi <goffi@goffi.org>
parents: 6
diff changeset
64 from kivy.uix.boxlayout import BoxLayout
85
c2a7234d13d2 menu: use of garden's contextmenu for menus
Goffi <goffi@goffi.org>
parents: 78
diff changeset
65 from kivy.uix.floatlayout import FloatLayout
220
24f8ab7c08be core: implemented showDialog so message/dialogs from QuickFrontend are displayed
Goffi <goffi@goffi.org>
parents: 208
diff changeset
66 from kivy.uix.screenmanager import (ScreenManager, Screen,
24f8ab7c08be core: implemented showDialog so message/dialogs from QuickFrontend are displayed
Goffi <goffi@goffi.org>
parents: 208
diff changeset
67 FallOutTransition, RiseInTransition)
29
8b5827c43155 notes first draft:
Goffi <goffi@goffi.org>
parents: 28
diff changeset
68 from kivy.uix.dropdown import DropDown
250
ff1efdeff53f core: notifs can now have a custom icon and be clickable:
Goffi <goffi@goffi.org>
parents: 249
diff changeset
69 from kivy.uix.behaviors import ButtonBehavior
166
37220459e93d core: hide/show menu on M-m + disable menu on Android
Goffi <goffi@goffi.org>
parents: 165
diff changeset
70 from kivy.core.window import Window
37220459e93d core: hide/show menu on M-m + disable menu on Android
Goffi <goffi@goffi.org>
parents: 165
diff changeset
71 from kivy.animation import Animation
37220459e93d core: hide/show menu on M-m + disable menu on Android
Goffi <goffi@goffi.org>
parents: 165
diff changeset
72 from kivy.metrics import dp
493
b3cedbee561d refactoring: rename `cagou` to `libervia.desktop_kivy` + update imports and names following backend changes
Goffi <goffi@goffi.org>
parents: 491
diff changeset
73 from .cagou_widget import LiberviaDesktopKivyWidget
322
e2b51663d8b8 core, android: new share widget + added Cagou to "share" menu:
Goffi <goffi@goffi.org>
parents: 318
diff changeset
74 from .share_widget import ShareWidget
38
9f45098289cc widgets handler, core: hidden widgets can now be shown with swipes:
Goffi <goffi@goffi.org>
parents: 34
diff changeset
75 from . import widgets_handler
29
8b5827c43155 notes first draft:
Goffi <goffi@goffi.org>
parents: 28
diff changeset
76 from .common import IconButton
220
24f8ab7c08be core: implemented showDialog so message/dialogs from QuickFrontend are displayed
Goffi <goffi@goffi.org>
parents: 208
diff changeset
77 from . import dialog
14
21a432afd06d plugin system, first draft:
Goffi <goffi@goffi.org>
parents: 13
diff changeset
78 from importlib import import_module
493
b3cedbee561d refactoring: rename `cagou` to `libervia.desktop_kivy` + update imports and names following backend changes
Goffi <goffi@goffi.org>
parents: 491
diff changeset
79 import libervia.backend
b3cedbee561d refactoring: rename `cagou` to `libervia.desktop_kivy` + update imports and names following backend changes
Goffi <goffi@goffi.org>
parents: 491
diff changeset
80 import libervia.desktop_kivy
b3cedbee561d refactoring: rename `cagou` to `libervia.desktop_kivy` + update imports and names following backend changes
Goffi <goffi@goffi.org>
parents: 491
diff changeset
81 import libervia.desktop_kivy.plugins
b3cedbee561d refactoring: rename `cagou` to `libervia.desktop_kivy` + update imports and names following backend changes
Goffi <goffi@goffi.org>
parents: 491
diff changeset
82 import libervia.desktop_kivy.kv
322
e2b51663d8b8 core, android: new share widget + added Cagou to "share" menu:
Goffi <goffi@goffi.org>
parents: 318
diff changeset
83
e2b51663d8b8 core, android: new share widget + added Cagou to "share" menu:
Goffi <goffi@goffi.org>
parents: 318
diff changeset
84
e2b51663d8b8 core, android: new share widget + added Cagou to "share" menu:
Goffi <goffi@goffi.org>
parents: 318
diff changeset
85 log = logging.getLogger(__name__)
e2b51663d8b8 core, android: new share widget + added Cagou to "share" menu:
Goffi <goffi@goffi.org>
parents: 318
diff changeset
86
e2b51663d8b8 core, android: new share widget + added Cagou to "share" menu:
Goffi <goffi@goffi.org>
parents: 318
diff changeset
87
184
c63922860f80 chat: show desktop notification and/or note when suitable
Goffi <goffi@goffi.org>
parents: 176
diff changeset
88 try:
c63922860f80 chat: show desktop notification and/or note when suitable
Goffi <goffi@goffi.org>
parents: 176
diff changeset
89 from plyer import notification
c63922860f80 chat: show desktop notification and/or note when suitable
Goffi <goffi@goffi.org>
parents: 176
diff changeset
90 except ImportError:
c63922860f80 chat: show desktop notification and/or note when suitable
Goffi <goffi@goffi.org>
parents: 176
diff changeset
91 notification = None
312
772c170b47a9 Python3 port:
Goffi <goffi@goffi.org>
parents: 302
diff changeset
92 log.warning(_("Can't import plyer, some features disabled"))
131
36fc269e2a32 core: changed default background color to white
Goffi <goffi@goffi.org>
parents: 130
diff changeset
93
286
4772ba26623f xmlui: many improvments:
Goffi <goffi@goffi.org>
parents: 285
diff changeset
94
4772ba26623f xmlui: many improvments:
Goffi <goffi@goffi.org>
parents: 285
diff changeset
95 ## platform specific settings ##
4772ba26623f xmlui: many improvments:
Goffi <goffi@goffi.org>
parents: 285
diff changeset
96
342
89799148f894 core: use classes and factory to handle platform specific behaviours in a generic way
Goffi <goffi@goffi.org>
parents: 331
diff changeset
97 from . import platform_
89799148f894 core: use classes and factory to handle platform specific behaviours in a generic way
Goffi <goffi@goffi.org>
parents: 331
diff changeset
98 local_platform = platform_.create()
89799148f894 core: use classes and factory to handle platform specific behaviours in a generic way
Goffi <goffi@goffi.org>
parents: 331
diff changeset
99 local_platform.init_platform()
259
4601793b0dee core: use new unix socket mechanism to set frontend state
Goffi <goffi@goffi.org>
parents: 250
diff changeset
100
4601793b0dee core: use new unix socket mechanism to set frontend state
Goffi <goffi@goffi.org>
parents: 250
diff changeset
101
286
4772ba26623f xmlui: many improvments:
Goffi <goffi@goffi.org>
parents: 285
diff changeset
102 ## General Configuration ##
4772ba26623f xmlui: many improvments:
Goffi <goffi@goffi.org>
parents: 285
diff changeset
103
259
4601793b0dee core: use new unix socket mechanism to set frontend state
Goffi <goffi@goffi.org>
parents: 250
diff changeset
104 # we want white background by default
4601793b0dee core: use new unix socket mechanism to set frontend state
Goffi <goffi@goffi.org>
parents: 250
diff changeset
105 Window.clearcolor = (1, 1, 1, 1)
9
7b0a53d2afd3 contact list: first draft
Goffi <goffi@goffi.org>
parents: 6
diff changeset
106
7b0a53d2afd3 contact list: first draft
Goffi <goffi@goffi.org>
parents: 6
diff changeset
107
33
c21d1be2e54c core: XMLUI notifications coming from backend are handled:
Goffi <goffi@goffi.org>
parents: 32
diff changeset
108 class NotifsIcon(IconButton):
c21d1be2e54c core: XMLUI notifications coming from backend are handled:
Goffi <goffi@goffi.org>
parents: 32
diff changeset
109 notifs = properties.ListProperty()
29
8b5827c43155 notes first draft:
Goffi <goffi@goffi.org>
parents: 28
diff changeset
110
8b5827c43155 notes first draft:
Goffi <goffi@goffi.org>
parents: 28
diff changeset
111 def on_release(self):
33
c21d1be2e54c core: XMLUI notifications coming from backend are handled:
Goffi <goffi@goffi.org>
parents: 32
diff changeset
112 callback, args, kwargs = self.notifs.pop(0)
c21d1be2e54c core: XMLUI notifications coming from backend are handled:
Goffi <goffi@goffi.org>
parents: 32
diff changeset
113 callback(*args, **kwargs)
c21d1be2e54c core: XMLUI notifications coming from backend are handled:
Goffi <goffi@goffi.org>
parents: 32
diff changeset
114
491
203755bbe0fe massive refactoring from camelCase -> snake_case. See backend commit log for more details
Goffi <goffi@goffi.org>
parents: 487
diff changeset
115 def add_notif(self, callback, *args, **kwargs):
33
c21d1be2e54c core: XMLUI notifications coming from backend are handled:
Goffi <goffi@goffi.org>
parents: 32
diff changeset
116 self.notifs.append((callback, args, kwargs))
29
8b5827c43155 notes first draft:
Goffi <goffi@goffi.org>
parents: 28
diff changeset
117
505
bbef1a413515 core (main): add methods to deleted notifications:
Goffi <goffi@goffi.org>
parents: 498
diff changeset
118 def del_notif(self, callback, *args, **kwargs):
bbef1a413515 core (main): add methods to deleted notifications:
Goffi <goffi@goffi.org>
parents: 498
diff changeset
119 try:
bbef1a413515 core (main): add methods to deleted notifications:
Goffi <goffi@goffi.org>
parents: 498
diff changeset
120 self.notifs.remove((callback, args, kwargs))
bbef1a413515 core (main): add methods to deleted notifications:
Goffi <goffi@goffi.org>
parents: 498
diff changeset
121 except ValueError:
bbef1a413515 core (main): add methods to deleted notifications:
Goffi <goffi@goffi.org>
parents: 498
diff changeset
122 log.debug("The notification to delete doesn't exist anymore.")
bbef1a413515 core (main): add methods to deleted notifications:
Goffi <goffi@goffi.org>
parents: 498
diff changeset
123
29
8b5827c43155 notes first draft:
Goffi <goffi@goffi.org>
parents: 28
diff changeset
124
8b5827c43155 notes first draft:
Goffi <goffi@goffi.org>
parents: 28
diff changeset
125 class Note(Label):
8b5827c43155 notes first draft:
Goffi <goffi@goffi.org>
parents: 28
diff changeset
126 title = properties.StringProperty()
8b5827c43155 notes first draft:
Goffi <goffi@goffi.org>
parents: 28
diff changeset
127 message = properties.StringProperty()
220
24f8ab7c08be core: implemented showDialog so message/dialogs from QuickFrontend are displayed
Goffi <goffi@goffi.org>
parents: 208
diff changeset
128 level = properties.OptionProperty(C.XMLUI_DATA_LVL_DEFAULT,
24f8ab7c08be core: implemented showDialog so message/dialogs from QuickFrontend are displayed
Goffi <goffi@goffi.org>
parents: 208
diff changeset
129 options=list(C.XMLUI_DATA_LVLS))
250
ff1efdeff53f core: notifs can now have a custom icon and be clickable:
Goffi <goffi@goffi.org>
parents: 249
diff changeset
130 symbol = properties.StringProperty()
ff1efdeff53f core: notifs can now have a custom icon and be clickable:
Goffi <goffi@goffi.org>
parents: 249
diff changeset
131 action = properties.ObjectProperty()
29
8b5827c43155 notes first draft:
Goffi <goffi@goffi.org>
parents: 28
diff changeset
132
8b5827c43155 notes first draft:
Goffi <goffi@goffi.org>
parents: 28
diff changeset
133
250
ff1efdeff53f core: notifs can now have a custom icon and be clickable:
Goffi <goffi@goffi.org>
parents: 249
diff changeset
134 class NoteDrop(ButtonBehavior, BoxLayout):
208
c5c1dd7f88e1 root widget: improved notes:
Goffi <goffi@goffi.org>
parents: 190
diff changeset
135 title = properties.StringProperty()
c5c1dd7f88e1 root widget: improved notes:
Goffi <goffi@goffi.org>
parents: 190
diff changeset
136 message = properties.StringProperty()
220
24f8ab7c08be core: implemented showDialog so message/dialogs from QuickFrontend are displayed
Goffi <goffi@goffi.org>
parents: 208
diff changeset
137 level = properties.OptionProperty(C.XMLUI_DATA_LVL_DEFAULT,
24f8ab7c08be core: implemented showDialog so message/dialogs from QuickFrontend are displayed
Goffi <goffi@goffi.org>
parents: 208
diff changeset
138 options=list(C.XMLUI_DATA_LVLS))
250
ff1efdeff53f core: notifs can now have a custom icon and be clickable:
Goffi <goffi@goffi.org>
parents: 249
diff changeset
139 symbol = properties.StringProperty()
ff1efdeff53f core: notifs can now have a custom icon and be clickable:
Goffi <goffi@goffi.org>
parents: 249
diff changeset
140 action = properties.ObjectProperty()
ff1efdeff53f core: notifs can now have a custom icon and be clickable:
Goffi <goffi@goffi.org>
parents: 249
diff changeset
141
ff1efdeff53f core: notifs can now have a custom icon and be clickable:
Goffi <goffi@goffi.org>
parents: 249
diff changeset
142 def on_press(self):
ff1efdeff53f core: notifs can now have a custom icon and be clickable:
Goffi <goffi@goffi.org>
parents: 249
diff changeset
143 if self.action is not None:
ff1efdeff53f core: notifs can now have a custom icon and be clickable:
Goffi <goffi@goffi.org>
parents: 249
diff changeset
144 self.parent.parent.select(self.action)
29
8b5827c43155 notes first draft:
Goffi <goffi@goffi.org>
parents: 28
diff changeset
145
8b5827c43155 notes first draft:
Goffi <goffi@goffi.org>
parents: 28
diff changeset
146
8b5827c43155 notes first draft:
Goffi <goffi@goffi.org>
parents: 28
diff changeset
147 class NotesDrop(DropDown):
8b5827c43155 notes first draft:
Goffi <goffi@goffi.org>
parents: 28
diff changeset
148 clear_btn = properties.ObjectProperty()
8b5827c43155 notes first draft:
Goffi <goffi@goffi.org>
parents: 28
diff changeset
149
8b5827c43155 notes first draft:
Goffi <goffi@goffi.org>
parents: 28
diff changeset
150 def __init__(self, notes):
8b5827c43155 notes first draft:
Goffi <goffi@goffi.org>
parents: 28
diff changeset
151 super(NotesDrop, self).__init__()
8b5827c43155 notes first draft:
Goffi <goffi@goffi.org>
parents: 28
diff changeset
152 self.notes = notes
8b5827c43155 notes first draft:
Goffi <goffi@goffi.org>
parents: 28
diff changeset
153
8b5827c43155 notes first draft:
Goffi <goffi@goffi.org>
parents: 28
diff changeset
154 def open(self, widget):
8b5827c43155 notes first draft:
Goffi <goffi@goffi.org>
parents: 28
diff changeset
155 self.clear_widgets()
8b5827c43155 notes first draft:
Goffi <goffi@goffi.org>
parents: 28
diff changeset
156 for n in self.notes:
250
ff1efdeff53f core: notifs can now have a custom icon and be clickable:
Goffi <goffi@goffi.org>
parents: 249
diff changeset
157 kwargs = {
312
772c170b47a9 Python3 port:
Goffi <goffi@goffi.org>
parents: 302
diff changeset
158 'title': n.title,
772c170b47a9 Python3 port:
Goffi <goffi@goffi.org>
parents: 302
diff changeset
159 'message': n.message,
772c170b47a9 Python3 port:
Goffi <goffi@goffi.org>
parents: 302
diff changeset
160 'level': n.level
250
ff1efdeff53f core: notifs can now have a custom icon and be clickable:
Goffi <goffi@goffi.org>
parents: 249
diff changeset
161 }
ff1efdeff53f core: notifs can now have a custom icon and be clickable:
Goffi <goffi@goffi.org>
parents: 249
diff changeset
162 if n.symbol is not None:
312
772c170b47a9 Python3 port:
Goffi <goffi@goffi.org>
parents: 302
diff changeset
163 kwargs['symbol'] = n.symbol
250
ff1efdeff53f core: notifs can now have a custom icon and be clickable:
Goffi <goffi@goffi.org>
parents: 249
diff changeset
164 if n.action is not None:
312
772c170b47a9 Python3 port:
Goffi <goffi@goffi.org>
parents: 302
diff changeset
165 kwargs['action'] = n.action
250
ff1efdeff53f core: notifs can now have a custom icon and be clickable:
Goffi <goffi@goffi.org>
parents: 249
diff changeset
166 self.add_widget(NoteDrop(title=n.title, message=n.message, level=n.level,
ff1efdeff53f core: notifs can now have a custom icon and be clickable:
Goffi <goffi@goffi.org>
parents: 249
diff changeset
167 symbol=n.symbol, action=n.action))
29
8b5827c43155 notes first draft:
Goffi <goffi@goffi.org>
parents: 28
diff changeset
168 self.add_widget(self.clear_btn)
8b5827c43155 notes first draft:
Goffi <goffi@goffi.org>
parents: 28
diff changeset
169 super(NotesDrop, self).open(widget)
8b5827c43155 notes first draft:
Goffi <goffi@goffi.org>
parents: 28
diff changeset
170
250
ff1efdeff53f core: notifs can now have a custom icon and be clickable:
Goffi <goffi@goffi.org>
parents: 249
diff changeset
171 def on_select(self, action_kwargs):
ff1efdeff53f core: notifs can now have a custom icon and be clickable:
Goffi <goffi@goffi.org>
parents: 249
diff changeset
172 app = App.get_running_app()
491
203755bbe0fe massive refactoring from camelCase -> snake_case. See backend commit log for more details
Goffi <goffi@goffi.org>
parents: 487
diff changeset
173 app.host.do_action(**action_kwargs)
250
ff1efdeff53f core: notifs can now have a custom icon and be clickable:
Goffi <goffi@goffi.org>
parents: 249
diff changeset
174
29
8b5827c43155 notes first draft:
Goffi <goffi@goffi.org>
parents: 28
diff changeset
175
8b5827c43155 notes first draft:
Goffi <goffi@goffi.org>
parents: 28
diff changeset
176 class RootHeadWidget(BoxLayout):
8b5827c43155 notes first draft:
Goffi <goffi@goffi.org>
parents: 28
diff changeset
177 """Notifications widget"""
8b5827c43155 notes first draft:
Goffi <goffi@goffi.org>
parents: 28
diff changeset
178 manager = properties.ObjectProperty()
33
c21d1be2e54c core: XMLUI notifications coming from backend are handled:
Goffi <goffi@goffi.org>
parents: 32
diff changeset
179 notifs_icon = properties.ObjectProperty()
29
8b5827c43155 notes first draft:
Goffi <goffi@goffi.org>
parents: 28
diff changeset
180 notes = properties.ListProperty()
172
7103655647aa core: hide notifications header on M-n
Goffi <goffi@goffi.org>
parents: 166
diff changeset
181 HEIGHT = dp(35)
29
8b5827c43155 notes first draft:
Goffi <goffi@goffi.org>
parents: 28
diff changeset
182
8b5827c43155 notes first draft:
Goffi <goffi@goffi.org>
parents: 28
diff changeset
183 def __init__(self):
8b5827c43155 notes first draft:
Goffi <goffi@goffi.org>
parents: 28
diff changeset
184 super(RootHeadWidget, self).__init__()
8b5827c43155 notes first draft:
Goffi <goffi@goffi.org>
parents: 28
diff changeset
185 self.notes_last = None
8b5827c43155 notes first draft:
Goffi <goffi@goffi.org>
parents: 28
diff changeset
186 self.notes_event = None
33
c21d1be2e54c core: XMLUI notifications coming from backend are handled:
Goffi <goffi@goffi.org>
parents: 32
diff changeset
187 self.notes_drop = NotesDrop(self.notes)
29
8b5827c43155 notes first draft:
Goffi <goffi@goffi.org>
parents: 28
diff changeset
188
491
203755bbe0fe massive refactoring from camelCase -> snake_case. See backend commit log for more details
Goffi <goffi@goffi.org>
parents: 487
diff changeset
189 def add_notif(self, callback, *args, **kwargs):
220
24f8ab7c08be core: implemented showDialog so message/dialogs from QuickFrontend are displayed
Goffi <goffi@goffi.org>
parents: 208
diff changeset
190 """add a notification with a callback attached
24f8ab7c08be core: implemented showDialog so message/dialogs from QuickFrontend are displayed
Goffi <goffi@goffi.org>
parents: 208
diff changeset
191
24f8ab7c08be core: implemented showDialog so message/dialogs from QuickFrontend are displayed
Goffi <goffi@goffi.org>
parents: 208
diff changeset
192 when notification is pressed, callback is called
24f8ab7c08be core: implemented showDialog so message/dialogs from QuickFrontend are displayed
Goffi <goffi@goffi.org>
parents: 208
diff changeset
193 @param *args, **kwargs: arguments of callback
24f8ab7c08be core: implemented showDialog so message/dialogs from QuickFrontend are displayed
Goffi <goffi@goffi.org>
parents: 208
diff changeset
194 """
491
203755bbe0fe massive refactoring from camelCase -> snake_case. See backend commit log for more details
Goffi <goffi@goffi.org>
parents: 487
diff changeset
195 self.notifs_icon.add_notif(callback, *args, **kwargs)
29
8b5827c43155 notes first draft:
Goffi <goffi@goffi.org>
parents: 28
diff changeset
196
491
203755bbe0fe massive refactoring from camelCase -> snake_case. See backend commit log for more details
Goffi <goffi@goffi.org>
parents: 487
diff changeset
197 def add_note(self, title, message, level, symbol, action):
250
ff1efdeff53f core: notifs can now have a custom icon and be clickable:
Goffi <goffi@goffi.org>
parents: 249
diff changeset
198 kwargs = {
312
772c170b47a9 Python3 port:
Goffi <goffi@goffi.org>
parents: 302
diff changeset
199 'title': title,
772c170b47a9 Python3 port:
Goffi <goffi@goffi.org>
parents: 302
diff changeset
200 'message': message,
772c170b47a9 Python3 port:
Goffi <goffi@goffi.org>
parents: 302
diff changeset
201 'level': level
250
ff1efdeff53f core: notifs can now have a custom icon and be clickable:
Goffi <goffi@goffi.org>
parents: 249
diff changeset
202 }
ff1efdeff53f core: notifs can now have a custom icon and be clickable:
Goffi <goffi@goffi.org>
parents: 249
diff changeset
203 if symbol is not None:
312
772c170b47a9 Python3 port:
Goffi <goffi@goffi.org>
parents: 302
diff changeset
204 kwargs['symbol'] = symbol
250
ff1efdeff53f core: notifs can now have a custom icon and be clickable:
Goffi <goffi@goffi.org>
parents: 249
diff changeset
205 if action is not None:
312
772c170b47a9 Python3 port:
Goffi <goffi@goffi.org>
parents: 302
diff changeset
206 kwargs['action'] = action
250
ff1efdeff53f core: notifs can now have a custom icon and be clickable:
Goffi <goffi@goffi.org>
parents: 249
diff changeset
207 note = Note(**kwargs)
29
8b5827c43155 notes first draft:
Goffi <goffi@goffi.org>
parents: 28
diff changeset
208 self.notes.append(note)
8b5827c43155 notes first draft:
Goffi <goffi@goffi.org>
parents: 28
diff changeset
209 if self.notes_event is None:
491
203755bbe0fe massive refactoring from camelCase -> snake_case. See backend commit log for more details
Goffi <goffi@goffi.org>
parents: 487
diff changeset
210 self.notes_event = Clock.schedule_interval(self._display_next_note, 5)
203755bbe0fe massive refactoring from camelCase -> snake_case. See backend commit log for more details
Goffi <goffi@goffi.org>
parents: 487
diff changeset
211 self._display_next_note()
29
8b5827c43155 notes first draft:
Goffi <goffi@goffi.org>
parents: 28
diff changeset
212
491
203755bbe0fe massive refactoring from camelCase -> snake_case. See backend commit log for more details
Goffi <goffi@goffi.org>
parents: 487
diff changeset
213 def add_notif_ui(self, ui):
203755bbe0fe massive refactoring from camelCase -> snake_case. See backend commit log for more details
Goffi <goffi@goffi.org>
parents: 487
diff changeset
214 self.notifs_icon.add_notif(ui.show, force=True)
33
c21d1be2e54c core: XMLUI notifications coming from backend are handled:
Goffi <goffi@goffi.org>
parents: 32
diff changeset
215
491
203755bbe0fe massive refactoring from camelCase -> snake_case. See backend commit log for more details
Goffi <goffi@goffi.org>
parents: 487
diff changeset
216 def add_notif_widget(self, widget):
220
24f8ab7c08be core: implemented showDialog so message/dialogs from QuickFrontend are displayed
Goffi <goffi@goffi.org>
parents: 208
diff changeset
217 app = App.get_running_app()
491
203755bbe0fe massive refactoring from camelCase -> snake_case. See backend commit log for more details
Goffi <goffi@goffi.org>
parents: 487
diff changeset
218 self.notifs_icon.add_notif(app.host.show_extra_ui, widget=widget)
220
24f8ab7c08be core: implemented showDialog so message/dialogs from QuickFrontend are displayed
Goffi <goffi@goffi.org>
parents: 208
diff changeset
219
505
bbef1a413515 core (main): add methods to deleted notifications:
Goffi <goffi@goffi.org>
parents: 498
diff changeset
220 def del_notif_widget(self, widget):
bbef1a413515 core (main): add methods to deleted notifications:
Goffi <goffi@goffi.org>
parents: 498
diff changeset
221 app = App.get_running_app()
bbef1a413515 core (main): add methods to deleted notifications:
Goffi <goffi@goffi.org>
parents: 498
diff changeset
222 self.notifs_icon.del_notif(app.host.show_extra_ui, widget=widget)
bbef1a413515 core (main): add methods to deleted notifications:
Goffi <goffi@goffi.org>
parents: 498
diff changeset
223
491
203755bbe0fe massive refactoring from camelCase -> snake_case. See backend commit log for more details
Goffi <goffi@goffi.org>
parents: 487
diff changeset
224 def _display_next_note(self, __=None):
29
8b5827c43155 notes first draft:
Goffi <goffi@goffi.org>
parents: 28
diff changeset
225 screen = Screen()
8b5827c43155 notes first draft:
Goffi <goffi@goffi.org>
parents: 28
diff changeset
226 try:
8b5827c43155 notes first draft:
Goffi <goffi@goffi.org>
parents: 28
diff changeset
227 idx = self.notes.index(self.notes_last) + 1
8b5827c43155 notes first draft:
Goffi <goffi@goffi.org>
parents: 28
diff changeset
228 except ValueError:
8b5827c43155 notes first draft:
Goffi <goffi@goffi.org>
parents: 28
diff changeset
229 idx = 0
8b5827c43155 notes first draft:
Goffi <goffi@goffi.org>
parents: 28
diff changeset
230 try:
8b5827c43155 notes first draft:
Goffi <goffi@goffi.org>
parents: 28
diff changeset
231 note = self.notes_last = self.notes[idx]
8b5827c43155 notes first draft:
Goffi <goffi@goffi.org>
parents: 28
diff changeset
232 except IndexError:
8b5827c43155 notes first draft:
Goffi <goffi@goffi.org>
parents: 28
diff changeset
233 self.notes_event.cancel()
8b5827c43155 notes first draft:
Goffi <goffi@goffi.org>
parents: 28
diff changeset
234 self.notes_event = None
8b5827c43155 notes first draft:
Goffi <goffi@goffi.org>
parents: 28
diff changeset
235 else:
8b5827c43155 notes first draft:
Goffi <goffi@goffi.org>
parents: 28
diff changeset
236 screen.add_widget(note)
8b5827c43155 notes first draft:
Goffi <goffi@goffi.org>
parents: 28
diff changeset
237 self.manager.switch_to(screen)
8b5827c43155 notes first draft:
Goffi <goffi@goffi.org>
parents: 28
diff changeset
238
8b5827c43155 notes first draft:
Goffi <goffi@goffi.org>
parents: 28
diff changeset
239
85
c2a7234d13d2 menu: use of garden's contextmenu for menus
Goffi <goffi@goffi.org>
parents: 78
diff changeset
240 class RootBody(BoxLayout):
c2a7234d13d2 menu: use of garden's contextmenu for menus
Goffi <goffi@goffi.org>
parents: 78
diff changeset
241 pass
c2a7234d13d2 menu: use of garden's contextmenu for menus
Goffi <goffi@goffi.org>
parents: 78
diff changeset
242
c2a7234d13d2 menu: use of garden's contextmenu for menus
Goffi <goffi@goffi.org>
parents: 78
diff changeset
243
493
b3cedbee561d refactoring: rename `cagou` to `libervia.desktop_kivy` + update imports and names following backend changes
Goffi <goffi@goffi.org>
parents: 491
diff changeset
244 class LiberviaDesktopKivyRootWidget(FloatLayout):
85
c2a7234d13d2 menu: use of garden's contextmenu for menus
Goffi <goffi@goffi.org>
parents: 78
diff changeset
245 root_body = properties.ObjectProperty
9
7b0a53d2afd3 contact list: first draft
Goffi <goffi@goffi.org>
parents: 6
diff changeset
246
29
8b5827c43155 notes first draft:
Goffi <goffi@goffi.org>
parents: 28
diff changeset
247 def __init__(self, main_widget):
493
b3cedbee561d refactoring: rename `cagou` to `libervia.desktop_kivy` + update imports and names following backend changes
Goffi <goffi@goffi.org>
parents: 491
diff changeset
248 super(LiberviaDesktopKivyRootWidget, self).__init__()
29
8b5827c43155 notes first draft:
Goffi <goffi@goffi.org>
parents: 28
diff changeset
249 # header
172
7103655647aa core: hide notifications header on M-n
Goffi <goffi@goffi.org>
parents: 166
diff changeset
250 self.head_widget = RootHeadWidget()
7103655647aa core: hide notifications header on M-n
Goffi <goffi@goffi.org>
parents: 166
diff changeset
251 self.root_body.add_widget(self.head_widget)
29
8b5827c43155 notes first draft:
Goffi <goffi@goffi.org>
parents: 28
diff changeset
252 # body
8b5827c43155 notes first draft:
Goffi <goffi@goffi.org>
parents: 28
diff changeset
253 self._manager = ScreenManager()
33
c21d1be2e54c core: XMLUI notifications coming from backend are handled:
Goffi <goffi@goffi.org>
parents: 32
diff changeset
254 # main widgets
29
8b5827c43155 notes first draft:
Goffi <goffi@goffi.org>
parents: 28
diff changeset
255 main_screen = Screen(name='main')
8b5827c43155 notes first draft:
Goffi <goffi@goffi.org>
parents: 28
diff changeset
256 main_screen.add_widget(main_widget)
8b5827c43155 notes first draft:
Goffi <goffi@goffi.org>
parents: 28
diff changeset
257 self._manager.add_widget(main_screen)
33
c21d1be2e54c core: XMLUI notifications coming from backend are handled:
Goffi <goffi@goffi.org>
parents: 32
diff changeset
258 # backend XMLUI (popups, forms, etc)
c21d1be2e54c core: XMLUI notifications coming from backend are handled:
Goffi <goffi@goffi.org>
parents: 32
diff changeset
259 xmlui_screen = Screen(name='xmlui')
c21d1be2e54c core: XMLUI notifications coming from backend are handled:
Goffi <goffi@goffi.org>
parents: 32
diff changeset
260 self._manager.add_widget(xmlui_screen)
78
46d962910801 chat: file upload first draft:
Goffi <goffi@goffi.org>
parents: 77
diff changeset
261 # extra (file chooser, audio record, etc)
46d962910801 chat: file upload first draft:
Goffi <goffi@goffi.org>
parents: 77
diff changeset
262 extra_screen = Screen(name='extra')
46d962910801 chat: file upload first draft:
Goffi <goffi@goffi.org>
parents: 77
diff changeset
263 self._manager.add_widget(extra_screen)
85
c2a7234d13d2 menu: use of garden's contextmenu for menus
Goffi <goffi@goffi.org>
parents: 78
diff changeset
264 self.root_body.add_widget(self._manager)
29
8b5827c43155 notes first draft:
Goffi <goffi@goffi.org>
parents: 28
diff changeset
265
491
203755bbe0fe massive refactoring from camelCase -> snake_case. See backend commit log for more details
Goffi <goffi@goffi.org>
parents: 487
diff changeset
266 def change_widget(self, widget, screen_name="main"):
29
8b5827c43155 notes first draft:
Goffi <goffi@goffi.org>
parents: 28
diff changeset
267 """change main widget"""
52
647f32d0a004 core: workaround issue happening when root widget is changed too quickly (during a transition)
Goffi <goffi@goffi.org>
parents: 51
diff changeset
268 if self._manager.transition.is_active:
647f32d0a004 core: workaround issue happening when root widget is changed too quickly (during a transition)
Goffi <goffi@goffi.org>
parents: 51
diff changeset
269 # FIXME: workaround for what seems a Kivy bug
647f32d0a004 core: workaround issue happening when root widget is changed too quickly (during a transition)
Goffi <goffi@goffi.org>
parents: 51
diff changeset
270 # TODO: report this upstream
647f32d0a004 core: workaround issue happening when root widget is changed too quickly (during a transition)
Goffi <goffi@goffi.org>
parents: 51
diff changeset
271 self._manager.transition.stop()
33
c21d1be2e54c core: XMLUI notifications coming from backend are handled:
Goffi <goffi@goffi.org>
parents: 32
diff changeset
272 screen = self._manager.get_screen(screen_name)
c21d1be2e54c core: XMLUI notifications coming from backend are handled:
Goffi <goffi@goffi.org>
parents: 32
diff changeset
273 screen.clear_widgets()
c21d1be2e54c core: XMLUI notifications coming from backend are handled:
Goffi <goffi@goffi.org>
parents: 32
diff changeset
274 screen.add_widget(widget)
c21d1be2e54c core: XMLUI notifications coming from backend are handled:
Goffi <goffi@goffi.org>
parents: 32
diff changeset
275
c21d1be2e54c core: XMLUI notifications coming from backend are handled:
Goffi <goffi@goffi.org>
parents: 32
diff changeset
276 def show(self, screen="main"):
52
647f32d0a004 core: workaround issue happening when root widget is changed too quickly (during a transition)
Goffi <goffi@goffi.org>
parents: 51
diff changeset
277 if self._manager.transition.is_active:
647f32d0a004 core: workaround issue happening when root widget is changed too quickly (during a transition)
Goffi <goffi@goffi.org>
parents: 51
diff changeset
278 # FIXME: workaround for what seems a Kivy bug
647f32d0a004 core: workaround issue happening when root widget is changed too quickly (during a transition)
Goffi <goffi@goffi.org>
parents: 51
diff changeset
279 # TODO: report this upstream
647f32d0a004 core: workaround issue happening when root widget is changed too quickly (during a transition)
Goffi <goffi@goffi.org>
parents: 51
diff changeset
280 self._manager.transition.stop()
33
c21d1be2e54c core: XMLUI notifications coming from backend are handled:
Goffi <goffi@goffi.org>
parents: 32
diff changeset
281 if self._manager.current == screen:
c21d1be2e54c core: XMLUI notifications coming from backend are handled:
Goffi <goffi@goffi.org>
parents: 32
diff changeset
282 return
c21d1be2e54c core: XMLUI notifications coming from backend are handled:
Goffi <goffi@goffi.org>
parents: 32
diff changeset
283 if screen == "main":
c21d1be2e54c core: XMLUI notifications coming from backend are handled:
Goffi <goffi@goffi.org>
parents: 32
diff changeset
284 self._manager.transition = FallOutTransition()
c21d1be2e54c core: XMLUI notifications coming from backend are handled:
Goffi <goffi@goffi.org>
parents: 32
diff changeset
285 else:
c21d1be2e54c core: XMLUI notifications coming from backend are handled:
Goffi <goffi@goffi.org>
parents: 32
diff changeset
286 self._manager.transition = RiseInTransition()
c21d1be2e54c core: XMLUI notifications coming from backend are handled:
Goffi <goffi@goffi.org>
parents: 32
diff changeset
287 self._manager.current = screen
29
8b5827c43155 notes first draft:
Goffi <goffi@goffi.org>
parents: 28
diff changeset
288
491
203755bbe0fe massive refactoring from camelCase -> snake_case. See backend commit log for more details
Goffi <goffi@goffi.org>
parents: 487
diff changeset
289 def new_action(self, handler, action_data, id_, security_limit, profile):
29
8b5827c43155 notes first draft:
Goffi <goffi@goffi.org>
parents: 28
diff changeset
290 """Add a notification for an action"""
491
203755bbe0fe massive refactoring from camelCase -> snake_case. See backend commit log for more details
Goffi <goffi@goffi.org>
parents: 487
diff changeset
291 self.head_widget.add_notif(handler, action_data, id_, security_limit, profile)
29
8b5827c43155 notes first draft:
Goffi <goffi@goffi.org>
parents: 28
diff changeset
292
491
203755bbe0fe massive refactoring from camelCase -> snake_case. See backend commit log for more details
Goffi <goffi@goffi.org>
parents: 487
diff changeset
293 def add_note(self, title, message, level, symbol, action):
203755bbe0fe massive refactoring from camelCase -> snake_case. See backend commit log for more details
Goffi <goffi@goffi.org>
parents: 487
diff changeset
294 self.head_widget.add_note(title, message, level, symbol, action)
0
160cc95ad7ea initial commit:
Goffi <goffi@goffi.org>
parents:
diff changeset
295
491
203755bbe0fe massive refactoring from camelCase -> snake_case. See backend commit log for more details
Goffi <goffi@goffi.org>
parents: 487
diff changeset
296 def add_notif_ui(self, ui):
203755bbe0fe massive refactoring from camelCase -> snake_case. See backend commit log for more details
Goffi <goffi@goffi.org>
parents: 487
diff changeset
297 self.head_widget.add_notif_ui(ui)
33
c21d1be2e54c core: XMLUI notifications coming from backend are handled:
Goffi <goffi@goffi.org>
parents: 32
diff changeset
298
491
203755bbe0fe massive refactoring from camelCase -> snake_case. See backend commit log for more details
Goffi <goffi@goffi.org>
parents: 487
diff changeset
299 def add_notif_widget(self, widget):
203755bbe0fe massive refactoring from camelCase -> snake_case. See backend commit log for more details
Goffi <goffi@goffi.org>
parents: 487
diff changeset
300 self.head_widget.add_notif_widget(widget)
220
24f8ab7c08be core: implemented showDialog so message/dialogs from QuickFrontend are displayed
Goffi <goffi@goffi.org>
parents: 208
diff changeset
301
505
bbef1a413515 core (main): add methods to deleted notifications:
Goffi <goffi@goffi.org>
parents: 498
diff changeset
302 def del_notif_widget(self, widget):
bbef1a413515 core (main): add methods to deleted notifications:
Goffi <goffi@goffi.org>
parents: 498
diff changeset
303 self.head_widget.del_notif_widget(widget)
bbef1a413515 core (main): add methods to deleted notifications:
Goffi <goffi@goffi.org>
parents: 498
diff changeset
304
0
160cc95ad7ea initial commit:
Goffi <goffi@goffi.org>
parents:
diff changeset
305
493
b3cedbee561d refactoring: rename `cagou` to `libervia.desktop_kivy` + update imports and names following backend changes
Goffi <goffi@goffi.org>
parents: 491
diff changeset
306 class LiberviaDesktopKivyApp(App):
b3cedbee561d refactoring: rename `cagou` to `libervia.desktop_kivy` + update imports and names following backend changes
Goffi <goffi@goffi.org>
parents: 491
diff changeset
307 """Kivy App for LiberviaDesktopKivy"""
176
2cfef8fbfd4e core: moved main colors to constants
Goffi <goffi@goffi.org>
parents: 174
diff changeset
308 c_prim = properties.ListProperty(C.COLOR_PRIM)
2cfef8fbfd4e core: moved main colors to constants
Goffi <goffi@goffi.org>
parents: 174
diff changeset
309 c_prim_light = properties.ListProperty(C.COLOR_PRIM_LIGHT)
2cfef8fbfd4e core: moved main colors to constants
Goffi <goffi@goffi.org>
parents: 174
diff changeset
310 c_prim_dark = properties.ListProperty(C.COLOR_PRIM_DARK)
2cfef8fbfd4e core: moved main colors to constants
Goffi <goffi@goffi.org>
parents: 174
diff changeset
311 c_sec = properties.ListProperty(C.COLOR_SEC)
2cfef8fbfd4e core: moved main colors to constants
Goffi <goffi@goffi.org>
parents: 174
diff changeset
312 c_sec_light = properties.ListProperty(C.COLOR_SEC_LIGHT)
2cfef8fbfd4e core: moved main colors to constants
Goffi <goffi@goffi.org>
parents: 174
diff changeset
313 c_sec_dark = properties.ListProperty(C.COLOR_SEC_DARK)
346
7b9a0e57df53 core: new "connected" property in CagouApp
Goffi <goffi@goffi.org>
parents: 342
diff changeset
314 connected = properties.BooleanProperty(False)
274
7d5297984191 core, chat: UI improvments:
Goffi <goffi@goffi.org>
parents: 272
diff changeset
315 # we have to put those constants here and not in core/constants.py
7d5297984191 core, chat: UI improvments:
Goffi <goffi@goffi.org>
parents: 272
diff changeset
316 # because of the use of dp(), which would import Kivy too early
7d5297984191 core, chat: UI improvments:
Goffi <goffi@goffi.org>
parents: 272
diff changeset
317 # and prevent the log hack
7d5297984191 core, chat: UI improvments:
Goffi <goffi@goffi.org>
parents: 272
diff changeset
318 MARGIN_LEFT = MARGIN_RIGHT = dp(10)
0
160cc95ad7ea initial commit:
Goffi <goffi@goffi.org>
parents:
diff changeset
319
152
b9fd83292fc4 core: disabled Kivy's default behaviour of displaying settings on F1
Goffi <goffi@goffi.org>
parents: 143
diff changeset
320 def _install_settings_keys(self, window):
b9fd83292fc4 core: disabled Kivy's default behaviour of displaying settings on F1
Goffi <goffi@goffi.org>
parents: 143
diff changeset
321 # we don't want default Kivy's behaviour of displaying
b9fd83292fc4 core: disabled Kivy's default behaviour of displaying settings on F1
Goffi <goffi@goffi.org>
parents: 143
diff changeset
322 # a settings screen when pressing F1 or platform specific key
b9fd83292fc4 core: disabled Kivy's default behaviour of displaying settings on F1
Goffi <goffi@goffi.org>
parents: 143
diff changeset
323 return
b9fd83292fc4 core: disabled Kivy's default behaviour of displaying settings on F1
Goffi <goffi@goffi.org>
parents: 143
diff changeset
324
0
160cc95ad7ea initial commit:
Goffi <goffi@goffi.org>
parents:
diff changeset
325 def build(self):
498
3b627382e681 core: support async methods and bridge
Goffi <goffi@goffi.org>
parents: 497
diff changeset
326 # we connect async bridge here as we must have a running loop
3b627382e681 core: support async methods and bridge
Goffi <goffi@goffi.org>
parents: 497
diff changeset
327 self.host.a_bridge.bridge_connect()
3b627382e681 core: support async methods and bridge
Goffi <goffi@goffi.org>
parents: 497
diff changeset
328
143
05d602be0120 core: [esc] key handling is disabled (for now)
Goffi <goffi@goffi.org>
parents: 142
diff changeset
329 Window.bind(on_keyboard=self.key_input)
414
72a6b06728ab core: file dropping:
Goffi <goffi@goffi.org>
parents: 402
diff changeset
330 Window.bind(on_dropfile=self.on_dropfile)
493
b3cedbee561d refactoring: rename `cagou` to `libervia.desktop_kivy` + update imports and names following backend changes
Goffi <goffi@goffi.org>
parents: 491
diff changeset
331 wid = LiberviaDesktopKivyRootWidget(Label(text=_("Loading please wait")))
342
89799148f894 core: use classes and factory to handle platform specific behaviours in a generic way
Goffi <goffi@goffi.org>
parents: 331
diff changeset
332 local_platform.on_app_build(wid)
166
37220459e93d core: hide/show menu on M-m + disable menu on Android
Goffi <goffi@goffi.org>
parents: 165
diff changeset
333 return wid
60
35abe494e6c7 core: bridge selection + improvments for android
Goffi <goffi@goffi.org>
parents: 52
diff changeset
334
491
203755bbe0fe massive refactoring from camelCase -> snake_case. See backend commit log for more details
Goffi <goffi@goffi.org>
parents: 487
diff changeset
335 def show_profile_manager(self):
49
fd9cbf6ae663 core: postInit() is now called, allowing automatic profile connection
Goffi <goffi@goffi.org>
parents: 48
diff changeset
336 self._profile_manager = ProfileManager()
491
203755bbe0fe massive refactoring from camelCase -> snake_case. See backend commit log for more details
Goffi <goffi@goffi.org>
parents: 487
diff changeset
337 self.root.change_widget(self._profile_manager)
0
160cc95ad7ea initial commit:
Goffi <goffi@goffi.org>
parents:
diff changeset
338
31
4f9e701d76b4 core: expand now accepts extra arguments, which will be used in format
Goffi <goffi@goffi.org>
parents: 29
diff changeset
339 def expand(self, path, *args, **kwargs):
28
9f9532eb835f core: added expand method to expand filename with magic values, specially useful in kv
Goffi <goffi@goffi.org>
parents: 25
diff changeset
340 """expand path and replace known values
9f9532eb835f core: added expand method to expand filename with magic values, specially useful in kv
Goffi <goffi@goffi.org>
parents: 25
diff changeset
341
32
fdaf914e2729 minor docstring fix
Goffi <goffi@goffi.org>
parents: 31
diff changeset
342 useful in kv. Values which can be used:
fdaf914e2729 minor docstring fix
Goffi <goffi@goffi.org>
parents: 31
diff changeset
343 - {media}: media dir
31
4f9e701d76b4 core: expand now accepts extra arguments, which will be used in format
Goffi <goffi@goffi.org>
parents: 29
diff changeset
344 @param path(unicode): path to expand
4f9e701d76b4 core: expand now accepts extra arguments, which will be used in format
Goffi <goffi@goffi.org>
parents: 29
diff changeset
345 @param *args: additional arguments used in format
4f9e701d76b4 core: expand now accepts extra arguments, which will be used in format
Goffi <goffi@goffi.org>
parents: 29
diff changeset
346 @param **kwargs: additional keyword arguments used in format
28
9f9532eb835f core: added expand method to expand filename with magic values, specially useful in kv
Goffi <goffi@goffi.org>
parents: 25
diff changeset
347 """
31
4f9e701d76b4 core: expand now accepts extra arguments, which will be used in format
Goffi <goffi@goffi.org>
parents: 29
diff changeset
348 return os.path.expanduser(path).format(*args, media=self.host.media_dir, **kwargs)
28
9f9532eb835f core: added expand method to expand filename with magic values, specially useful in kv
Goffi <goffi@goffi.org>
parents: 25
diff changeset
349
491
203755bbe0fe massive refactoring from camelCase -> snake_case. See backend commit log for more details
Goffi <goffi@goffi.org>
parents: 487
diff changeset
350 def init_frontend_state(self):
259
4601793b0dee core: use new unix socket mechanism to set frontend state
Goffi <goffi@goffi.org>
parents: 250
diff changeset
351 """Init state to handle paused/stopped/running on mobile OSes"""
491
203755bbe0fe massive refactoring from camelCase -> snake_case. See backend commit log for more details
Goffi <goffi@goffi.org>
parents: 487
diff changeset
352 local_platform.on_init_frontend_state()
73
674b1fa3c945 core: use memory map on a file to indicate pause/resume status, so backend can now it
Goffi <goffi@goffi.org>
parents: 72
diff changeset
353
65
1c738621bc8d core: on_pause/on_resume handling (needed for Android)
Goffi <goffi@goffi.org>
parents: 64
diff changeset
354 def on_pause(self):
342
89799148f894 core: use classes and factory to handle platform specific behaviours in a generic way
Goffi <goffi@goffi.org>
parents: 331
diff changeset
355 return local_platform.on_pause()
65
1c738621bc8d core: on_pause/on_resume handling (needed for Android)
Goffi <goffi@goffi.org>
parents: 64
diff changeset
356
1c738621bc8d core: on_pause/on_resume handling (needed for Android)
Goffi <goffi@goffi.org>
parents: 64
diff changeset
357 def on_resume(self):
342
89799148f894 core: use classes and factory to handle platform specific behaviours in a generic way
Goffi <goffi@goffi.org>
parents: 331
diff changeset
358 return local_platform.on_resume()
73
674b1fa3c945 core: use memory map on a file to indicate pause/resume status, so backend can now it
Goffi <goffi@goffi.org>
parents: 72
diff changeset
359
674b1fa3c945 core: use memory map on a file to indicate pause/resume status, so backend can now it
Goffi <goffi@goffi.org>
parents: 72
diff changeset
360 def on_stop(self):
342
89799148f894 core: use classes and factory to handle platform specific behaviours in a generic way
Goffi <goffi@goffi.org>
parents: 331
diff changeset
361 return local_platform.on_stop()
65
1c738621bc8d core: on_pause/on_resume handling (needed for Android)
Goffi <goffi@goffi.org>
parents: 64
diff changeset
362
491
203755bbe0fe massive refactoring from camelCase -> snake_case. See backend commit log for more details
Goffi <goffi@goffi.org>
parents: 487
diff changeset
363 def show_head_widget(self, show=None, animation=True):
423
f8ba934ea462 core: new showHeadWidget method to show/hide notifications header.
Goffi <goffi@goffi.org>
parents: 420
diff changeset
364 """Show/Hide the head widget
f8ba934ea462 core: new showHeadWidget method to show/hide notifications header.
Goffi <goffi@goffi.org>
parents: 420
diff changeset
365
f8ba934ea462 core: new showHeadWidget method to show/hide notifications header.
Goffi <goffi@goffi.org>
parents: 420
diff changeset
366 @param show(bool, None): True to show, False to hide, None to switch
f8ba934ea462 core: new showHeadWidget method to show/hide notifications header.
Goffi <goffi@goffi.org>
parents: 420
diff changeset
367 @param animation(bool): animate the show/hide if True
f8ba934ea462 core: new showHeadWidget method to show/hide notifications header.
Goffi <goffi@goffi.org>
parents: 420
diff changeset
368 """
f8ba934ea462 core: new showHeadWidget method to show/hide notifications header.
Goffi <goffi@goffi.org>
parents: 420
diff changeset
369 head = self.root.head_widget
f8ba934ea462 core: new showHeadWidget method to show/hide notifications header.
Goffi <goffi@goffi.org>
parents: 420
diff changeset
370 if bool(self.root.head_widget.height) == show:
f8ba934ea462 core: new showHeadWidget method to show/hide notifications header.
Goffi <goffi@goffi.org>
parents: 420
diff changeset
371 return
f8ba934ea462 core: new showHeadWidget method to show/hide notifications header.
Goffi <goffi@goffi.org>
parents: 420
diff changeset
372 if head.height:
f8ba934ea462 core: new showHeadWidget method to show/hide notifications header.
Goffi <goffi@goffi.org>
parents: 420
diff changeset
373 if animation:
f8ba934ea462 core: new showHeadWidget method to show/hide notifications header.
Goffi <goffi@goffi.org>
parents: 420
diff changeset
374 Animation(height=0, opacity=0, duration=0.3).start(head)
f8ba934ea462 core: new showHeadWidget method to show/hide notifications header.
Goffi <goffi@goffi.org>
parents: 420
diff changeset
375 else:
f8ba934ea462 core: new showHeadWidget method to show/hide notifications header.
Goffi <goffi@goffi.org>
parents: 420
diff changeset
376 head.height = head.opacity = 0
f8ba934ea462 core: new showHeadWidget method to show/hide notifications header.
Goffi <goffi@goffi.org>
parents: 420
diff changeset
377 else:
f8ba934ea462 core: new showHeadWidget method to show/hide notifications header.
Goffi <goffi@goffi.org>
parents: 420
diff changeset
378 if animation:
f8ba934ea462 core: new showHeadWidget method to show/hide notifications header.
Goffi <goffi@goffi.org>
parents: 420
diff changeset
379 Animation(height=head.HEIGHT, opacity=1, duration=0.3).start(head)
f8ba934ea462 core: new showHeadWidget method to show/hide notifications header.
Goffi <goffi@goffi.org>
parents: 420
diff changeset
380 else:
f8ba934ea462 core: new showHeadWidget method to show/hide notifications header.
Goffi <goffi@goffi.org>
parents: 420
diff changeset
381 head.height = head.HEIGHT
f8ba934ea462 core: new showHeadWidget method to show/hide notifications header.
Goffi <goffi@goffi.org>
parents: 420
diff changeset
382 head.opacity = 1
f8ba934ea462 core: new showHeadWidget method to show/hide notifications header.
Goffi <goffi@goffi.org>
parents: 420
diff changeset
383
143
05d602be0120 core: [esc] key handling is disabled (for now)
Goffi <goffi@goffi.org>
parents: 142
diff changeset
384 def key_input(self, window, key, scancode, codepoint, modifier):
349
33244f944bd8 core: "key_input" method is now checked and used if suitable in selected widget.
Goffi <goffi@goffi.org>
parents: 346
diff changeset
385
33244f944bd8 core: "key_input" method is now checked and used if suitable in selected widget.
Goffi <goffi@goffi.org>
parents: 346
diff changeset
386 # we first check if selected widget handles the key
33244f944bd8 core: "key_input" method is now checked and used if suitable in selected widget.
Goffi <goffi@goffi.org>
parents: 346
diff changeset
387 if ((self.host.selected_widget is not None
33244f944bd8 core: "key_input" method is now checked and used if suitable in selected widget.
Goffi <goffi@goffi.org>
parents: 346
diff changeset
388 and hasattr(self.host.selected_widget, 'key_input')
33244f944bd8 core: "key_input" method is now checked and used if suitable in selected widget.
Goffi <goffi@goffi.org>
parents: 346
diff changeset
389 and self.host.selected_widget.key_input(window, key, scancode, codepoint,
33244f944bd8 core: "key_input" method is now checked and used if suitable in selected widget.
Goffi <goffi@goffi.org>
parents: 346
diff changeset
390 modifier))):
33244f944bd8 core: "key_input" method is now checked and used if suitable in selected widget.
Goffi <goffi@goffi.org>
parents: 346
diff changeset
391 return True
33244f944bd8 core: "key_input" method is now checked and used if suitable in selected widget.
Goffi <goffi@goffi.org>
parents: 346
diff changeset
392
143
05d602be0120 core: [esc] key handling is disabled (for now)
Goffi <goffi@goffi.org>
parents: 142
diff changeset
393 if key == 27:
357
4d3a0c4f2430 core: better back key (ESC) management:
Goffi <goffi@goffi.org>
parents: 356
diff changeset
394 if ((self.host.selected_widget is None
4d3a0c4f2430 core: better back key (ESC) management:
Goffi <goffi@goffi.org>
parents: 356
diff changeset
395 or self.host.selected_widget.__class__ == self.host.default_class)):
4d3a0c4f2430 core: better back key (ESC) management:
Goffi <goffi@goffi.org>
parents: 356
diff changeset
396 # we are on root widget, or nothing is selected
4d3a0c4f2430 core: better back key (ESC) management:
Goffi <goffi@goffi.org>
parents: 356
diff changeset
397 return local_platform.on_key_back_root()
4d3a0c4f2430 core: better back key (ESC) management:
Goffi <goffi@goffi.org>
parents: 356
diff changeset
398
166
37220459e93d core: hide/show menu on M-m + disable menu on Android
Goffi <goffi@goffi.org>
parents: 165
diff changeset
399 # we disable [esc] handling, because default action is to quit app
143
05d602be0120 core: [esc] key handling is disabled (for now)
Goffi <goffi@goffi.org>
parents: 142
diff changeset
400 return True
165
e6ec8ff62d87 core: toggle fullscreen on F11
Goffi <goffi@goffi.org>
parents: 154
diff changeset
401 elif key == 292:
166
37220459e93d core: hide/show menu on M-m + disable menu on Android
Goffi <goffi@goffi.org>
parents: 165
diff changeset
402 # F11: full screen
165
e6ec8ff62d87 core: toggle fullscreen on F11
Goffi <goffi@goffi.org>
parents: 154
diff changeset
403 if not Window.fullscreen:
322
e2b51663d8b8 core, android: new share widget + added Cagou to "share" menu:
Goffi <goffi@goffi.org>
parents: 318
diff changeset
404 Window.fullscreen = 'auto'
165
e6ec8ff62d87 core: toggle fullscreen on F11
Goffi <goffi@goffi.org>
parents: 154
diff changeset
405 else:
322
e2b51663d8b8 core, android: new share widget + added Cagou to "share" menu:
Goffi <goffi@goffi.org>
parents: 318
diff changeset
406 Window.fullscreen = False
165
e6ec8ff62d87 core: toggle fullscreen on F11
Goffi <goffi@goffi.org>
parents: 154
diff changeset
407 return True
375
ae9059b791fe core: fixed handling of M-n if other modifier (e.g. numlock) are present
Goffi <goffi@goffi.org>
parents: 373
diff changeset
408 elif key == 110 and 'alt' in modifier:
172
7103655647aa core: hide notifications header on M-n
Goffi <goffi@goffi.org>
parents: 166
diff changeset
409 # M-n we hide/show notifications
491
203755bbe0fe massive refactoring from camelCase -> snake_case. See backend commit log for more details
Goffi <goffi@goffi.org>
parents: 487
diff changeset
410 self.show_head_widget()
172
7103655647aa core: hide notifications header on M-n
Goffi <goffi@goffi.org>
parents: 166
diff changeset
411 return True
143
05d602be0120 core: [esc] key handling is disabled (for now)
Goffi <goffi@goffi.org>
parents: 142
diff changeset
412 else:
05d602be0120 core: [esc] key handling is disabled (for now)
Goffi <goffi@goffi.org>
parents: 142
diff changeset
413 return False
05d602be0120 core: [esc] key handling is disabled (for now)
Goffi <goffi@goffi.org>
parents: 142
diff changeset
414
414
72a6b06728ab core: file dropping:
Goffi <goffi@goffi.org>
parents: 402
diff changeset
415 def on_dropfile(self, __, file_path):
72a6b06728ab core: file dropping:
Goffi <goffi@goffi.org>
parents: 402
diff changeset
416 if self.host.selected_widget is not None:
72a6b06728ab core: file dropping:
Goffi <goffi@goffi.org>
parents: 402
diff changeset
417 try:
72a6b06728ab core: file dropping:
Goffi <goffi@goffi.org>
parents: 402
diff changeset
418 on_drop_file = self.host.selected_widget.on_drop_file
72a6b06728ab core: file dropping:
Goffi <goffi@goffi.org>
parents: 402
diff changeset
419 except AttributeError:
72a6b06728ab core: file dropping:
Goffi <goffi@goffi.org>
parents: 402
diff changeset
420 log.info(
72a6b06728ab core: file dropping:
Goffi <goffi@goffi.org>
parents: 402
diff changeset
421 f"Select widget {self.host.selected_widget} doesn't handle file "
72a6b06728ab core: file dropping:
Goffi <goffi@goffi.org>
parents: 402
diff changeset
422 f"dropping")
72a6b06728ab core: file dropping:
Goffi <goffi@goffi.org>
parents: 402
diff changeset
423 else:
72a6b06728ab core: file dropping:
Goffi <goffi@goffi.org>
parents: 402
diff changeset
424 on_drop_file(Path(file_path.decode()))
72a6b06728ab core: file dropping:
Goffi <goffi@goffi.org>
parents: 402
diff changeset
425
0
160cc95ad7ea initial commit:
Goffi <goffi@goffi.org>
parents:
diff changeset
426
493
b3cedbee561d refactoring: rename `cagou` to `libervia.desktop_kivy` + update imports and names following backend changes
Goffi <goffi@goffi.org>
parents: 491
diff changeset
427 class LiberviaDesktopKivy(QuickApp):
0
160cc95ad7ea initial commit:
Goffi <goffi@goffi.org>
parents:
diff changeset
428 MB_HANDLE = False
265
805c4103dac5 core: resync widgets only when they are visible:
Goffi <goffi@goffi.org>
parents: 264
diff changeset
429 AUTO_RESYNC = False
0
160cc95ad7ea initial commit:
Goffi <goffi@goffi.org>
parents:
diff changeset
430
160cc95ad7ea initial commit:
Goffi <goffi@goffi.org>
parents:
diff changeset
431 def __init__(self):
60
35abe494e6c7 core: bridge selection + improvments for android
Goffi <goffi@goffi.org>
parents: 52
diff changeset
432 if bridge_name == 'embedded':
493
b3cedbee561d refactoring: rename `cagou` to `libervia.desktop_kivy` + update imports and names following backend changes
Goffi <goffi@goffi.org>
parents: 491
diff changeset
433 from libervia.backend.core import main
b3cedbee561d refactoring: rename `cagou` to `libervia.desktop_kivy` + update imports and names following backend changes
Goffi <goffi@goffi.org>
parents: 491
diff changeset
434 self.libervia_backend = main.LiberviaBackend()
64
8e16abcadbb8 core: launch SàT backend as a service on Android and wait for it on pb bridge connection.
Goffi <goffi@goffi.org>
parents: 63
diff changeset
435
493
b3cedbee561d refactoring: rename `cagou` to `libervia.desktop_kivy` + update imports and names following backend changes
Goffi <goffi@goffi.org>
parents: 491
diff changeset
436 bridge_module = dynamic_import.bridge(bridge_name, 'libervia.frontends.bridge')
60
35abe494e6c7 core: bridge selection + improvments for android
Goffi <goffi@goffi.org>
parents: 52
diff changeset
437 if bridge_module is None:
316
86566968837a android (p4a): updated P4A option to use Python 3:
Goffi <goffi@goffi.org>
parents: 312
diff changeset
438 log.error(f"Can't import {bridge_name} bridge")
72
1a324c682d8a core: use onBridgeConnected and exit code 3 when bridge can't be imported
Goffi <goffi@goffi.org>
parents: 65
diff changeset
439 sys.exit(3)
60
35abe494e6c7 core: bridge selection + improvments for android
Goffi <goffi@goffi.org>
parents: 52
diff changeset
440 else:
316
86566968837a android (p4a): updated P4A option to use Python 3:
Goffi <goffi@goffi.org>
parents: 312
diff changeset
441 log.debug(f"Loading {bridge_name} bridge")
498
3b627382e681 core: support async methods and bridge
Goffi <goffi@goffi.org>
parents: 497
diff changeset
442 super(LiberviaDesktopKivy, self).__init__(
3b627382e681 core: support async methods and bridge
Goffi <goffi@goffi.org>
parents: 497
diff changeset
443 bridge_factory=bridge_module.bridge,
3b627382e681 core: support async methods and bridge
Goffi <goffi@goffi.org>
parents: 497
diff changeset
444 xmlui=xmlui,
3b627382e681 core: support async methods and bridge
Goffi <goffi@goffi.org>
parents: 497
diff changeset
445 check_options=quick_utils.check_options,
3b627382e681 core: support async methods and bridge
Goffi <goffi@goffi.org>
parents: 497
diff changeset
446 connect_bridge=False,
3b627382e681 core: support async methods and bridge
Goffi <goffi@goffi.org>
parents: 497
diff changeset
447 async_bridge_factory = bridge_module.AIOBridge
3b627382e681 core: support async methods and bridge
Goffi <goffi@goffi.org>
parents: 497
diff changeset
448 )
15
56838ad5c84b files reorganisation, cagou is now launched with python2 cagou.py in src/
Goffi <goffi@goffi.org>
parents: 14
diff changeset
449 self._import_kv()
493
b3cedbee561d refactoring: rename `cagou` to `libervia.desktop_kivy` + update imports and names following backend changes
Goffi <goffi@goffi.org>
parents: 491
diff changeset
450 self.app = LiberviaDesktopKivyApp()
29
8b5827c43155 notes first draft:
Goffi <goffi@goffi.org>
parents: 28
diff changeset
451 self.app.host = self
497
232a723aae45 core: set log level according to configuration
Goffi <goffi@goffi.org>
parents: 493
diff changeset
452 log_level = config.config_get(
232a723aae45 core: set log level according to configuration
Goffi <goffi@goffi.org>
parents: 493
diff changeset
453 main_config,
232a723aae45 core: set log level according to configuration
Goffi <goffi@goffi.org>
parents: 493
diff changeset
454 C.CONFIG_SECTION,
232a723aae45 core: set log level according to configuration
Goffi <goffi@goffi.org>
parents: 493
diff changeset
455 "log_level",
232a723aae45 core: set log level according to configuration
Goffi <goffi@goffi.org>
parents: 493
diff changeset
456 "INFO"
232a723aae45 core: set log level according to configuration
Goffi <goffi@goffi.org>
parents: 493
diff changeset
457 ).strip().upper()
232a723aae45 core: set log level according to configuration
Goffi <goffi@goffi.org>
parents: 493
diff changeset
458 root_logger = logging.getLogger()
232a723aae45 core: set log level according to configuration
Goffi <goffi@goffi.org>
parents: 493
diff changeset
459 root_logger.setLevel(log_level)
491
203755bbe0fe massive refactoring from camelCase -> snake_case. See backend commit log for more details
Goffi <goffi@goffi.org>
parents: 487
diff changeset
460 self.media_dir = self.app.media_dir = config.config_get(main_config, '',
220
24f8ab7c08be core: implemented showDialog so message/dialogs from QuickFrontend are displayed
Goffi <goffi@goffi.org>
parents: 208
diff changeset
461 'media_dir')
491
203755bbe0fe massive refactoring from camelCase -> snake_case. See backend commit log for more details
Goffi <goffi@goffi.org>
parents: 487
diff changeset
462 self.downloads_dir = self.app.downloads_dir = config.config_get(main_config, '',
220
24f8ab7c08be core: implemented showDialog so message/dialogs from QuickFrontend are displayed
Goffi <goffi@goffi.org>
parents: 208
diff changeset
463 'downloads_dir')
188
0abd24ab81b1 core: retrieve downloads_dir on startup
Goffi <goffi@goffi.org>
parents: 184
diff changeset
464 if not os.path.exists(self.downloads_dir):
0abd24ab81b1 core: retrieve downloads_dir on startup
Goffi <goffi@goffi.org>
parents: 184
diff changeset
465 try:
0abd24ab81b1 core: retrieve downloads_dir on startup
Goffi <goffi@goffi.org>
parents: 184
diff changeset
466 os.makedirs(self.downloads_dir)
0abd24ab81b1 core: retrieve downloads_dir on startup
Goffi <goffi@goffi.org>
parents: 184
diff changeset
467 except OSError as e:
312
772c170b47a9 Python3 port:
Goffi <goffi@goffi.org>
parents: 302
diff changeset
468 log.warnings(_("Can't create downloads dir: {reason}").format(reason=e))
25
d09bd16dbbe2 code (cagou widget), selector: icons handling + use of new muchoslava icon set
Goffi <goffi@goffi.org>
parents: 19
diff changeset
469 self.app.default_avatar = os.path.join(self.media_dir, "misc/default_avatar.png")
487
38ca44d96752 core: title is now `C.APP_NAME`
Goffi <goffi@goffi.org>
parents: 486
diff changeset
470 self.app.icon = os.path.join(
38ca44d96752 core: title is now `C.APP_NAME`
Goffi <goffi@goffi.org>
parents: 486
diff changeset
471 self.media_dir, "icons/muchoslava/png/cagou_profil_bleu_96.png"
38ca44d96752 core: title is now `C.APP_NAME`
Goffi <goffi@goffi.org>
parents: 486
diff changeset
472 )
38ca44d96752 core: title is now `C.APP_NAME`
Goffi <goffi@goffi.org>
parents: 486
diff changeset
473 self.app.title = C.APP_NAME
360
a77386b73e55 core: change selected_widget when root screen widget is changed
Goffi <goffi@goffi.org>
parents: 358
diff changeset
474 # main widgets plugins
a77386b73e55 core: change selected_widget when root screen widget is changed
Goffi <goffi@goffi.org>
parents: 358
diff changeset
475 self._plg_wids = []
a77386b73e55 core: change selected_widget when root screen widget is changed
Goffi <goffi@goffi.org>
parents: 358
diff changeset
476 # transfer widgets plugins
a77386b73e55 core: change selected_widget when root screen widget is changed
Goffi <goffi@goffi.org>
parents: 358
diff changeset
477 self._plg_wids_transfer = []
505
bbef1a413515 core (main): add methods to deleted notifications:
Goffi <goffi@goffi.org>
parents: 498
diff changeset
478
bbef1a413515 core (main): add methods to deleted notifications:
Goffi <goffi@goffi.org>
parents: 498
diff changeset
479 Clock.schedule_once(lambda __: self._import_plugins(), 0)
360
a77386b73e55 core: change selected_widget when root screen widget is changed
Goffi <goffi@goffi.org>
parents: 358
diff changeset
480 # visible widgets by classes
a77386b73e55 core: change selected_widget when root screen widget is changed
Goffi <goffi@goffi.org>
parents: 358
diff changeset
481 self._visible_widgets = {}
a77386b73e55 core: change selected_widget when root screen widget is changed
Goffi <goffi@goffi.org>
parents: 358
diff changeset
482 # used to keep track of last selected widget in "main" screen when changing
a77386b73e55 core: change selected_widget when root screen widget is changed
Goffi <goffi@goffi.org>
parents: 358
diff changeset
483 # root screen
a77386b73e55 core: change selected_widget when root screen widget is changed
Goffi <goffi@goffi.org>
parents: 358
diff changeset
484 self._selected_widget_main = None
493
b3cedbee561d refactoring: rename `cagou` to `libervia.desktop_kivy` + update imports and names following backend changes
Goffi <goffi@goffi.org>
parents: 491
diff changeset
485 self.backend_version = libervia.backend.__version__ # will be replaced by version_get()
302
f55b60659ec1 core (about): improved "about" popup:
Goffi <goffi@goffi.org>
parents: 298
diff changeset
486 if C.APP_VERSION.endswith('D'):
f55b60659ec1 core (about): improved "about" popup:
Goffi <goffi@goffi.org>
parents: 298
diff changeset
487 self.version = "{} {}".format(
f55b60659ec1 core (about): improved "about" popup:
Goffi <goffi@goffi.org>
parents: 298
diff changeset
488 C.APP_VERSION,
493
b3cedbee561d refactoring: rename `cagou` to `libervia.desktop_kivy` + update imports and names following backend changes
Goffi <goffi@goffi.org>
parents: 491
diff changeset
489 libervia_utils.get_repository_data(libervia.desktop_kivy)
302
f55b60659ec1 core (about): improved "about" popup:
Goffi <goffi@goffi.org>
parents: 298
diff changeset
490 )
f55b60659ec1 core (about): improved "about" popup:
Goffi <goffi@goffi.org>
parents: 298
diff changeset
491 else:
f55b60659ec1 core (about): improved "about" popup:
Goffi <goffi@goffi.org>
parents: 298
diff changeset
492 self.version = C.APP_VERSION
38
9f45098289cc widgets handler, core: hidden widgets can now be shown with swipes:
Goffi <goffi@goffi.org>
parents: 34
diff changeset
493
491
203755bbe0fe massive refactoring from camelCase -> snake_case. See backend commit log for more details
Goffi <goffi@goffi.org>
parents: 487
diff changeset
494 self.tls_validation = not C.bool(config.config_get(main_config,
281
ef77423ce500 core: store tls_validation flag in host and use if for file upload.
Goffi <goffi@goffi.org>
parents: 280
diff changeset
495 C.CONFIG_SECTION,
ef77423ce500 core: store tls_validation flag in host and use if for file upload.
Goffi <goffi@goffi.org>
parents: 280
diff changeset
496 'no_certificate_validation',
ef77423ce500 core: store tls_validation flag in host and use if for file upload.
Goffi <goffi@goffi.org>
parents: 280
diff changeset
497 C.BOOL_FALSE))
ef77423ce500 core: store tls_validation flag in host and use if for file upload.
Goffi <goffi@goffi.org>
parents: 280
diff changeset
498 if not self.tls_validation:
493
b3cedbee561d refactoring: rename `cagou` to `libervia.desktop_kivy` + update imports and names following backend changes
Goffi <goffi@goffi.org>
parents: 491
diff changeset
499 from libervia.desktop_kivy.core import patches
438
58d3ea442f9c core (patches): renamed `apply` to `disable_tls_validation` which suits better
Goffi <goffi@goffi.org>
parents: 423
diff changeset
500 patches.disable_tls_validation()
312
772c170b47a9 Python3 port:
Goffi <goffi@goffi.org>
parents: 302
diff changeset
501 log.warning("SSL certificate validation is disabled, this is unsecure!")
280
b0461363bc65 core: certificate validation can be disabled:
Goffi <goffi@goffi.org>
parents: 276
diff changeset
502
342
89799148f894 core: use classes and factory to handle platform specific behaviours in a generic way
Goffi <goffi@goffi.org>
parents: 331
diff changeset
503 local_platform.on_host_init(self)
322
e2b51663d8b8 core, android: new share widget + added Cagou to "share" menu:
Goffi <goffi@goffi.org>
parents: 318
diff changeset
504
38
9f45098289cc widgets handler, core: hidden widgets can now be shown with swipes:
Goffi <goffi@goffi.org>
parents: 34
diff changeset
505 @property
9f45098289cc widgets handler, core: hidden widgets can now be shown with swipes:
Goffi <goffi@goffi.org>
parents: 34
diff changeset
506 def visible_widgets(self):
312
772c170b47a9 Python3 port:
Goffi <goffi@goffi.org>
parents: 302
diff changeset
507 for w_list in self._visible_widgets.values():
38
9f45098289cc widgets handler, core: hidden widgets can now be shown with swipes:
Goffi <goffi@goffi.org>
parents: 34
diff changeset
508 for w in w_list:
9f45098289cc widgets handler, core: hidden widgets can now be shown with swipes:
Goffi <goffi@goffi.org>
parents: 34
diff changeset
509 yield w
0
160cc95ad7ea initial commit:
Goffi <goffi@goffi.org>
parents:
diff changeset
510
357
4d3a0c4f2430 core: better back key (ESC) management:
Goffi <goffi@goffi.org>
parents: 356
diff changeset
511 @property
4d3a0c4f2430 core: better back key (ESC) management:
Goffi <goffi@goffi.org>
parents: 356
diff changeset
512 def default_class(self):
4d3a0c4f2430 core: better back key (ESC) management:
Goffi <goffi@goffi.org>
parents: 356
diff changeset
513 if self.default_wid is None:
4d3a0c4f2430 core: better back key (ESC) management:
Goffi <goffi@goffi.org>
parents: 356
diff changeset
514 return None
4d3a0c4f2430 core: better back key (ESC) management:
Goffi <goffi@goffi.org>
parents: 356
diff changeset
515 return self.default_wid['main']
4d3a0c4f2430 core: better back key (ESC) management:
Goffi <goffi@goffi.org>
parents: 356
diff changeset
516
265
805c4103dac5 core: resync widgets only when they are visible:
Goffi <goffi@goffi.org>
parents: 264
diff changeset
517 @QuickApp.sync.setter
805c4103dac5 core: resync widgets only when they are visible:
Goffi <goffi@goffi.org>
parents: 264
diff changeset
518 def sync(self, state):
805c4103dac5 core: resync widgets only when they are visible:
Goffi <goffi@goffi.org>
parents: 264
diff changeset
519 QuickApp.sync.fset(self, state)
491
203755bbe0fe massive refactoring from camelCase -> snake_case. See backend commit log for more details
Goffi <goffi@goffi.org>
parents: 487
diff changeset
520 # widget are resynchronised in on_visible event,
265
805c4103dac5 core: resync widgets only when they are visible:
Goffi <goffi@goffi.org>
parents: 264
diff changeset
521 # so we must call resync for widgets which are already visible
805c4103dac5 core: resync widgets only when they are visible:
Goffi <goffi@goffi.org>
parents: 264
diff changeset
522 if state:
805c4103dac5 core: resync widgets only when they are visible:
Goffi <goffi@goffi.org>
parents: 264
diff changeset
523 for w in self.visible_widgets:
272
c4990a7d5dbd core: check if resync exist in widget before calling it
Goffi <goffi@goffi.org>
parents: 267
diff changeset
524 try:
c4990a7d5dbd core: check if resync exist in widget before calling it
Goffi <goffi@goffi.org>
parents: 267
diff changeset
525 resync = w.resync
c4990a7d5dbd core: check if resync exist in widget before calling it
Goffi <goffi@goffi.org>
parents: 267
diff changeset
526 except AttributeError:
c4990a7d5dbd core: check if resync exist in widget before calling it
Goffi <goffi@goffi.org>
parents: 267
diff changeset
527 pass
c4990a7d5dbd core: check if resync exist in widget before calling it
Goffi <goffi@goffi.org>
parents: 267
diff changeset
528 else:
c4990a7d5dbd core: check if resync exist in widget before calling it
Goffi <goffi@goffi.org>
parents: 267
diff changeset
529 resync()
291
04e4cd7c9351 core: refill contact lists on resync
Goffi <goffi@goffi.org>
parents: 290
diff changeset
530 self.contact_lists.fill()
265
805c4103dac5 core: resync widgets only when they are visible:
Goffi <goffi@goffi.org>
parents: 264
diff changeset
531
491
203755bbe0fe massive refactoring from camelCase -> snake_case. See backend commit log for more details
Goffi <goffi@goffi.org>
parents: 487
diff changeset
532 def config_get(self, section, name, default=None):
203755bbe0fe massive refactoring from camelCase -> snake_case. See backend commit log for more details
Goffi <goffi@goffi.org>
parents: 487
diff changeset
533 return config.config_get(main_config, section, name, default)
381
eb3f622d8791 android: create/clean a temporary directory on startup:
Goffi <goffi@goffi.org>
parents: 378
diff changeset
534
491
203755bbe0fe massive refactoring from camelCase -> snake_case. See backend commit log for more details
Goffi <goffi@goffi.org>
parents: 487
diff changeset
535 def on_bridge_connected(self):
493
b3cedbee561d refactoring: rename `cagou` to `libervia.desktop_kivy` + update imports and names following backend changes
Goffi <goffi@goffi.org>
parents: 491
diff changeset
536 super(LiberviaDesktopKivy, self).on_bridge_connected()
491
203755bbe0fe massive refactoring from camelCase -> snake_case. See backend commit log for more details
Goffi <goffi@goffi.org>
parents: 487
diff changeset
537 self.register_signal("otr_state", iface="plugin")
63
af4f986d86f0 core: pb bridge implementation:
Goffi <goffi@goffi.org>
parents: 61
diff changeset
538
491
203755bbe0fe massive refactoring from camelCase -> snake_case. See backend commit log for more details
Goffi <goffi@goffi.org>
parents: 487
diff changeset
539 def _bridge_eb(self, failure):
64
8e16abcadbb8 core: launch SàT backend as a service on Android and wait for it on pb bridge connection.
Goffi <goffi@goffi.org>
parents: 63
diff changeset
540 if bridge_name == "pb" and sys.platform == "android":
8e16abcadbb8 core: launch SàT backend as a service on Android and wait for it on pb bridge connection.
Goffi <goffi@goffi.org>
parents: 63
diff changeset
541 try:
8e16abcadbb8 core: launch SàT backend as a service on Android and wait for it on pb bridge connection.
Goffi <goffi@goffi.org>
parents: 63
diff changeset
542 self.retried += 1
8e16abcadbb8 core: launch SàT backend as a service on Android and wait for it on pb bridge connection.
Goffi <goffi@goffi.org>
parents: 63
diff changeset
543 except AttributeError:
8e16abcadbb8 core: launch SàT backend as a service on Android and wait for it on pb bridge connection.
Goffi <goffi@goffi.org>
parents: 63
diff changeset
544 self.retried = 1
317
4b0fa73caad4 core: bridge are now raising generic BridgeExceptionNoService
Goffi <goffi@goffi.org>
parents: 316
diff changeset
545 if ((isinstance(failure, exceptions.BridgeExceptionNoService)
4b0fa73caad4 core: bridge are now raising generic BridgeExceptionNoService
Goffi <goffi@goffi.org>
parents: 316
diff changeset
546 and self.retried < 100)):
64
8e16abcadbb8 core: launch SàT backend as a service on Android and wait for it on pb bridge connection.
Goffi <goffi@goffi.org>
parents: 63
diff changeset
547 if self.retried % 20 == 0:
8e16abcadbb8 core: launch SàT backend as a service on Android and wait for it on pb bridge connection.
Goffi <goffi@goffi.org>
parents: 63
diff changeset
548 log.debug("backend not ready, retrying ({})".format(self.retried))
491
203755bbe0fe massive refactoring from camelCase -> snake_case. See backend commit log for more details
Goffi <goffi@goffi.org>
parents: 487
diff changeset
549 Clock.schedule_once(lambda __: self.connect_bridge(), 0.05)
64
8e16abcadbb8 core: launch SàT backend as a service on Android and wait for it on pb bridge connection.
Goffi <goffi@goffi.org>
parents: 63
diff changeset
550 return
493
b3cedbee561d refactoring: rename `cagou` to `libervia.desktop_kivy` + update imports and names following backend changes
Goffi <goffi@goffi.org>
parents: 491
diff changeset
551 super(LiberviaDesktopKivy, self)._bridge_eb(failure)
64
8e16abcadbb8 core: launch SàT backend as a service on Android and wait for it on pb bridge connection.
Goffi <goffi@goffi.org>
parents: 63
diff changeset
552
0
160cc95ad7ea initial commit:
Goffi <goffi@goffi.org>
parents:
diff changeset
553 def run(self):
491
203755bbe0fe massive refactoring from camelCase -> snake_case. See backend commit log for more details
Goffi <goffi@goffi.org>
parents: 487
diff changeset
554 self.connect_bridge()
60
35abe494e6c7 core: bridge selection + improvments for android
Goffi <goffi@goffi.org>
parents: 52
diff changeset
555 self.app.bind(on_stop=self.onStop)
498
3b627382e681 core: support async methods and bridge
Goffi <goffi@goffi.org>
parents: 497
diff changeset
556 loop = asyncio.get_event_loop()
3b627382e681 core: support async methods and bridge
Goffi <goffi@goffi.org>
parents: 497
diff changeset
557 loop.run_until_complete(
3b627382e681 core: support async methods and bridge
Goffi <goffi@goffi.org>
parents: 497
diff changeset
558 self.app.async_run("asyncio")
3b627382e681 core: support async methods and bridge
Goffi <goffi@goffi.org>
parents: 497
diff changeset
559 )
0
160cc95ad7ea initial commit:
Goffi <goffi@goffi.org>
parents:
diff changeset
560
60
35abe494e6c7 core: bridge selection + improvments for android
Goffi <goffi@goffi.org>
parents: 52
diff changeset
561 def onStop(self, obj):
35abe494e6c7 core: bridge selection + improvments for android
Goffi <goffi@goffi.org>
parents: 52
diff changeset
562 try:
493
b3cedbee561d refactoring: rename `cagou` to `libervia.desktop_kivy` + update imports and names following backend changes
Goffi <goffi@goffi.org>
parents: 491
diff changeset
563 libervia_instance = self.libervia_backend
60
35abe494e6c7 core: bridge selection + improvments for android
Goffi <goffi@goffi.org>
parents: 52
diff changeset
564 except AttributeError:
35abe494e6c7 core: bridge selection + improvments for android
Goffi <goffi@goffi.org>
parents: 52
diff changeset
565 pass
35abe494e6c7 core: bridge selection + improvments for android
Goffi <goffi@goffi.org>
parents: 52
diff changeset
566 else:
493
b3cedbee561d refactoring: rename `cagou` to `libervia.desktop_kivy` + update imports and names following backend changes
Goffi <goffi@goffi.org>
parents: 491
diff changeset
567 libervia_instance.stopService()
60
35abe494e6c7 core: bridge selection + improvments for android
Goffi <goffi@goffi.org>
parents: 52
diff changeset
568
491
203755bbe0fe massive refactoring from camelCase -> snake_case. See backend commit log for more details
Goffi <goffi@goffi.org>
parents: 487
diff changeset
569 def _get_version_cb(self, version):
302
f55b60659ec1 core (about): improved "about" popup:
Goffi <goffi@goffi.org>
parents: 298
diff changeset
570 self.backend_version = version
246
15e47bbb192c about: show full version of SàT
Goffi <goffi@goffi.org>
parents: 244
diff changeset
571
491
203755bbe0fe massive refactoring from camelCase -> snake_case. See backend commit log for more details
Goffi <goffi@goffi.org>
parents: 487
diff changeset
572 def on_backend_ready(self):
203755bbe0fe massive refactoring from camelCase -> snake_case. See backend commit log for more details
Goffi <goffi@goffi.org>
parents: 487
diff changeset
573 super().on_backend_ready()
203755bbe0fe massive refactoring from camelCase -> snake_case. See backend commit log for more details
Goffi <goffi@goffi.org>
parents: 487
diff changeset
574 self.app.show_profile_manager()
203755bbe0fe massive refactoring from camelCase -> snake_case. See backend commit log for more details
Goffi <goffi@goffi.org>
parents: 487
diff changeset
575 self.bridge.version_get(callback=self._get_version_cb)
203755bbe0fe massive refactoring from camelCase -> snake_case. See backend commit log for more details
Goffi <goffi@goffi.org>
parents: 487
diff changeset
576 self.app.init_frontend_state()
203755bbe0fe massive refactoring from camelCase -> snake_case. See backend commit log for more details
Goffi <goffi@goffi.org>
parents: 487
diff changeset
577 if local_platform.do_post_init():
203755bbe0fe massive refactoring from camelCase -> snake_case. See backend commit log for more details
Goffi <goffi@goffi.org>
parents: 487
diff changeset
578 self.post_init()
60
35abe494e6c7 core: bridge selection + improvments for android
Goffi <goffi@goffi.org>
parents: 52
diff changeset
579
491
203755bbe0fe massive refactoring from camelCase -> snake_case. See backend commit log for more details
Goffi <goffi@goffi.org>
parents: 487
diff changeset
580 def post_init(self, __=None):
276
a0835f0212d8 chat: multi-lines input:
Goffi <goffi@goffi.org>
parents: 274
diff changeset
581 # FIXME: resize doesn't work with SDL2 on android, so we use below_target for now
61
0b7f10de416e android: android build first draft:
Goffi <goffi@goffi.org>
parents: 60
diff changeset
582 self.app.root_window.softinput_mode = "below_target"
49
fd9cbf6ae663 core: postInit() is now called, allowing automatic profile connection
Goffi <goffi@goffi.org>
parents: 48
diff changeset
583 profile_manager = self.app._profile_manager
fd9cbf6ae663 core: postInit() is now called, allowing automatic profile connection
Goffi <goffi@goffi.org>
parents: 48
diff changeset
584 del self.app._profile_manager
493
b3cedbee561d refactoring: rename `cagou` to `libervia.desktop_kivy` + update imports and names following backend changes
Goffi <goffi@goffi.org>
parents: 491
diff changeset
585 super(LiberviaDesktopKivy, self).post_init(profile_manager)
49
fd9cbf6ae663 core: postInit() is now called, allowing automatic profile connection
Goffi <goffi@goffi.org>
parents: 48
diff changeset
586
491
203755bbe0fe massive refactoring from camelCase -> snake_case. See backend commit log for more details
Goffi <goffi@goffi.org>
parents: 487
diff changeset
587 def profile_plugged(self, profile):
203755bbe0fe massive refactoring from camelCase -> snake_case. See backend commit log for more details
Goffi <goffi@goffi.org>
parents: 487
diff changeset
588 super().profile_plugged(profile)
439
12d188cb1206 core: use of new profileConnected method:
Goffi <goffi@goffi.org>
parents: 438
diff changeset
589 # FIXME: this won't work with multiple profiles
12d188cb1206 core: use of new profileConnected method:
Goffi <goffi@goffi.org>
parents: 438
diff changeset
590 self.app.connected = self.profiles[profile].connected
12d188cb1206 core: use of new profileConnected method:
Goffi <goffi@goffi.org>
parents: 438
diff changeset
591
491
203755bbe0fe massive refactoring from camelCase -> snake_case. See backend commit log for more details
Goffi <goffi@goffi.org>
parents: 487
diff changeset
592 def _bookmarks_list_cb(self, bookmarks_dict, profile):
388
de066b72f5a8 core: cache MUC bookmarks on startup
Goffi <goffi@goffi.org>
parents: 385
diff changeset
593 bookmarks = set()
de066b72f5a8 core: cache MUC bookmarks on startup
Goffi <goffi@goffi.org>
parents: 385
diff changeset
594 for data in bookmarks_dict.values():
de066b72f5a8 core: cache MUC bookmarks on startup
Goffi <goffi@goffi.org>
parents: 385
diff changeset
595 bookmarks.update({jid.JID(k) for k in data.keys()})
de066b72f5a8 core: cache MUC bookmarks on startup
Goffi <goffi@goffi.org>
parents: 385
diff changeset
596 self.profiles[profile]._bookmarks = sorted(bookmarks)
de066b72f5a8 core: cache MUC bookmarks on startup
Goffi <goffi@goffi.org>
parents: 385
diff changeset
597
491
203755bbe0fe massive refactoring from camelCase -> snake_case. See backend commit log for more details
Goffi <goffi@goffi.org>
parents: 487
diff changeset
598 def profile_connected(self, profile):
203755bbe0fe massive refactoring from camelCase -> snake_case. See backend commit log for more details
Goffi <goffi@goffi.org>
parents: 487
diff changeset
599 self.bridge.bookmarks_list(
388
de066b72f5a8 core: cache MUC bookmarks on startup
Goffi <goffi@goffi.org>
parents: 385
diff changeset
600 "muc", "all", profile,
491
203755bbe0fe massive refactoring from camelCase -> snake_case. See backend commit log for more details
Goffi <goffi@goffi.org>
parents: 487
diff changeset
601 callback=partial(self._bookmarks_list_cb, profile=profile),
388
de066b72f5a8 core: cache MUC bookmarks on startup
Goffi <goffi@goffi.org>
parents: 385
diff changeset
602 errback=partial(self.errback, title=_("Bookmark error")))
346
7b9a0e57df53 core: new "connected" property in CagouApp
Goffi <goffi@goffi.org>
parents: 342
diff changeset
603
491
203755bbe0fe massive refactoring from camelCase -> snake_case. See backend commit log for more details
Goffi <goffi@goffi.org>
parents: 487
diff changeset
604 def _default_factory_main(self, plugin_info, target, profiles):
86
c711be670ecd core, chat: upload plugin system:
Goffi <goffi@goffi.org>
parents: 85
diff changeset
605 """default factory used to create main widgets instances
c711be670ecd core, chat: upload plugin system:
Goffi <goffi@goffi.org>
parents: 85
diff changeset
606
c711be670ecd core, chat: upload plugin system:
Goffi <goffi@goffi.org>
parents: 85
diff changeset
607 used when PLUGIN_INFO["factory"] is not set
c711be670ecd core, chat: upload plugin system:
Goffi <goffi@goffi.org>
parents: 85
diff changeset
608 @param plugin_info(dict): plugin datas
c711be670ecd core, chat: upload plugin system:
Goffi <goffi@goffi.org>
parents: 85
diff changeset
609 @param target: QuickWidget target
c711be670ecd core, chat: upload plugin system:
Goffi <goffi@goffi.org>
parents: 85
diff changeset
610 @param profiles(iterable): list of profiles
c711be670ecd core, chat: upload plugin system:
Goffi <goffi@goffi.org>
parents: 85
diff changeset
611 """
14
21a432afd06d plugin system, first draft:
Goffi <goffi@goffi.org>
parents: 13
diff changeset
612 main_cls = plugin_info['main']
491
203755bbe0fe massive refactoring from camelCase -> snake_case. See backend commit log for more details
Goffi <goffi@goffi.org>
parents: 487
diff changeset
613 return self.widgets.get_or_create_widget(main_cls,
220
24f8ab7c08be core: implemented showDialog so message/dialogs from QuickFrontend are displayed
Goffi <goffi@goffi.org>
parents: 208
diff changeset
614 target,
24f8ab7c08be core: implemented showDialog so message/dialogs from QuickFrontend are displayed
Goffi <goffi@goffi.org>
parents: 208
diff changeset
615 on_new_widget=None,
24f8ab7c08be core: implemented showDialog so message/dialogs from QuickFrontend are displayed
Goffi <goffi@goffi.org>
parents: 208
diff changeset
616 profiles=iter(self.profiles))
14
21a432afd06d plugin system, first draft:
Goffi <goffi@goffi.org>
parents: 13
diff changeset
617
491
203755bbe0fe massive refactoring from camelCase -> snake_case. See backend commit log for more details
Goffi <goffi@goffi.org>
parents: 487
diff changeset
618 def _default_factory_transfer(self, plugin_info, callback, cancel_cb, profiles):
97
5d2289127bb7 menu (upload): better menu using dedicated widget:
Goffi <goffi@goffi.org>
parents: 91
diff changeset
619 """default factory used to create transfer widgets instances
86
c711be670ecd core, chat: upload plugin system:
Goffi <goffi@goffi.org>
parents: 85
diff changeset
620
c711be670ecd core, chat: upload plugin system:
Goffi <goffi@goffi.org>
parents: 85
diff changeset
621 @param plugin_info(dict): plugin datas
97
5d2289127bb7 menu (upload): better menu using dedicated widget:
Goffi <goffi@goffi.org>
parents: 91
diff changeset
622 @param callback(callable): method to call with path to file to transfer
5d2289127bb7 menu (upload): better menu using dedicated widget:
Goffi <goffi@goffi.org>
parents: 91
diff changeset
623 @param cancel_cb(callable): call when transfer is cancelled
5d2289127bb7 menu (upload): better menu using dedicated widget:
Goffi <goffi@goffi.org>
parents: 91
diff changeset
624 transfer widget must be used as first argument
86
c711be670ecd core, chat: upload plugin system:
Goffi <goffi@goffi.org>
parents: 85
diff changeset
625 @param profiles(iterable): list of profiles
c711be670ecd core, chat: upload plugin system:
Goffi <goffi@goffi.org>
parents: 85
diff changeset
626 None if not specified
c711be670ecd core, chat: upload plugin system:
Goffi <goffi@goffi.org>
parents: 85
diff changeset
627 """
c711be670ecd core, chat: upload plugin system:
Goffi <goffi@goffi.org>
parents: 85
diff changeset
628 main_cls = plugin_info['main']
c711be670ecd core, chat: upload plugin system:
Goffi <goffi@goffi.org>
parents: 85
diff changeset
629 return main_cls(callback=callback, cancel_cb=cancel_cb)
c711be670ecd core, chat: upload plugin system:
Goffi <goffi@goffi.org>
parents: 85
diff changeset
630
29
8b5827c43155 notes first draft:
Goffi <goffi@goffi.org>
parents: 28
diff changeset
631 ## plugins & kv import ##
8b5827c43155 notes first draft:
Goffi <goffi@goffi.org>
parents: 28
diff changeset
632
15
56838ad5c84b files reorganisation, cagou is now launched with python2 cagou.py in src/
Goffi <goffi@goffi.org>
parents: 14
diff changeset
633 def _import_kv(self):
493
b3cedbee561d refactoring: rename `cagou` to `libervia.desktop_kivy` + update imports and names following backend changes
Goffi <goffi@goffi.org>
parents: 491
diff changeset
634 """import all kv files in libervia.desktop_kivy.kv"""
b3cedbee561d refactoring: rename `cagou` to `libervia.desktop_kivy` + update imports and names following backend changes
Goffi <goffi@goffi.org>
parents: 491
diff changeset
635 path = os.path.dirname(libervia.desktop_kivy.kv.__file__)
130
0ec3c3c0ed92 core (kv): new base.kv to handle default properties overriding on Kivy widgets
Goffi <goffi@goffi.org>
parents: 126
diff changeset
636 kv_files = glob.glob(os.path.join(path, "*.kv"))
0ec3c3c0ed92 core (kv): new base.kv to handle default properties overriding on Kivy widgets
Goffi <goffi@goffi.org>
parents: 126
diff changeset
637 # we want to be sure that base.kv is loaded first
0ec3c3c0ed92 core (kv): new base.kv to handle default properties overriding on Kivy widgets
Goffi <goffi@goffi.org>
parents: 126
diff changeset
638 # as it override some Kivy widgets properties
0ec3c3c0ed92 core (kv): new base.kv to handle default properties overriding on Kivy widgets
Goffi <goffi@goffi.org>
parents: 126
diff changeset
639 for kv_file in kv_files:
0ec3c3c0ed92 core (kv): new base.kv to handle default properties overriding on Kivy widgets
Goffi <goffi@goffi.org>
parents: 126
diff changeset
640 if kv_file.endswith('base.kv'):
0ec3c3c0ed92 core (kv): new base.kv to handle default properties overriding on Kivy widgets
Goffi <goffi@goffi.org>
parents: 126
diff changeset
641 kv_files.remove(kv_file)
0ec3c3c0ed92 core (kv): new base.kv to handle default properties overriding on Kivy widgets
Goffi <goffi@goffi.org>
parents: 126
diff changeset
642 kv_files.insert(0, kv_file)
0ec3c3c0ed92 core (kv): new base.kv to handle default properties overriding on Kivy widgets
Goffi <goffi@goffi.org>
parents: 126
diff changeset
643 break
0ec3c3c0ed92 core (kv): new base.kv to handle default properties overriding on Kivy widgets
Goffi <goffi@goffi.org>
parents: 126
diff changeset
644 else:
0ec3c3c0ed92 core (kv): new base.kv to handle default properties overriding on Kivy widgets
Goffi <goffi@goffi.org>
parents: 126
diff changeset
645 raise exceptions.InternalError("base.kv is missing")
0ec3c3c0ed92 core (kv): new base.kv to handle default properties overriding on Kivy widgets
Goffi <goffi@goffi.org>
parents: 126
diff changeset
646
0ec3c3c0ed92 core (kv): new base.kv to handle default properties overriding on Kivy widgets
Goffi <goffi@goffi.org>
parents: 126
diff changeset
647 for kv_file in kv_files:
0ec3c3c0ed92 core (kv): new base.kv to handle default properties overriding on Kivy widgets
Goffi <goffi@goffi.org>
parents: 126
diff changeset
648 Builder.load_file(kv_file)
316
86566968837a android (p4a): updated P4A option to use Python 3:
Goffi <goffi@goffi.org>
parents: 312
diff changeset
649 log.debug(f"kv file {kv_file} loaded")
15
56838ad5c84b files reorganisation, cagou is now launched with python2 cagou.py in src/
Goffi <goffi@goffi.org>
parents: 14
diff changeset
650
14
21a432afd06d plugin system, first draft:
Goffi <goffi@goffi.org>
parents: 13
diff changeset
651 def _import_plugins(self):
15
56838ad5c84b files reorganisation, cagou is now launched with python2 cagou.py in src/
Goffi <goffi@goffi.org>
parents: 14
diff changeset
652 """import all plugins"""
14
21a432afd06d plugin system, first draft:
Goffi <goffi@goffi.org>
parents: 13
diff changeset
653 self.default_wid = None
493
b3cedbee561d refactoring: rename `cagou` to `libervia.desktop_kivy` + update imports and names following backend changes
Goffi <goffi@goffi.org>
parents: 491
diff changeset
654 plugins_path = os.path.dirname(libervia.desktop_kivy.plugins.__file__)
312
772c170b47a9 Python3 port:
Goffi <goffi@goffi.org>
parents: 302
diff changeset
655 plugin_glob = "plugin*." + C.PLUGIN_EXT
220
24f8ab7c08be core: implemented showDialog so message/dialogs from QuickFrontend are displayed
Goffi <goffi@goffi.org>
parents: 208
diff changeset
656 plug_lst = [os.path.splitext(p)[0] for p in
24f8ab7c08be core: implemented showDialog so message/dialogs from QuickFrontend are displayed
Goffi <goffi@goffi.org>
parents: 208
diff changeset
657 map(os.path.basename, glob.glob(os.path.join(plugins_path,
24f8ab7c08be core: implemented showDialog so message/dialogs from QuickFrontend are displayed
Goffi <goffi@goffi.org>
parents: 208
diff changeset
658 plugin_glob)))]
61
0b7f10de416e android: android build first draft:
Goffi <goffi@goffi.org>
parents: 60
diff changeset
659
220
24f8ab7c08be core: implemented showDialog so message/dialogs from QuickFrontend are displayed
Goffi <goffi@goffi.org>
parents: 208
diff changeset
660 imported_names_main = set() # used to avoid loading 2 times
24f8ab7c08be core: implemented showDialog so message/dialogs from QuickFrontend are displayed
Goffi <goffi@goffi.org>
parents: 208
diff changeset
661 # plugin with same import name
97
5d2289127bb7 menu (upload): better menu using dedicated widget:
Goffi <goffi@goffi.org>
parents: 91
diff changeset
662 imported_names_transfer = set()
14
21a432afd06d plugin system, first draft:
Goffi <goffi@goffi.org>
parents: 13
diff changeset
663 for plug in plug_lst:
493
b3cedbee561d refactoring: rename `cagou` to `libervia.desktop_kivy` + update imports and names following backend changes
Goffi <goffi@goffi.org>
parents: 491
diff changeset
664 plugin_path = 'libervia.desktop_kivy.plugins.' + plug
86
c711be670ecd core, chat: upload plugin system:
Goffi <goffi@goffi.org>
parents: 85
diff changeset
665
c711be670ecd core, chat: upload plugin system:
Goffi <goffi@goffi.org>
parents: 85
diff changeset
666 # we get type from plugin name
c711be670ecd core, chat: upload plugin system:
Goffi <goffi@goffi.org>
parents: 85
diff changeset
667 suff = plug[7:]
312
772c170b47a9 Python3 port:
Goffi <goffi@goffi.org>
parents: 302
diff changeset
668 if '_' not in suff:
772c170b47a9 Python3 port:
Goffi <goffi@goffi.org>
parents: 302
diff changeset
669 log.error("invalid plugin name: {}, skipping".format(plug))
86
c711be670ecd core, chat: upload plugin system:
Goffi <goffi@goffi.org>
parents: 85
diff changeset
670 continue
312
772c170b47a9 Python3 port:
Goffi <goffi@goffi.org>
parents: 302
diff changeset
671 plugin_type = suff[:suff.find('_')]
86
c711be670ecd core, chat: upload plugin system:
Goffi <goffi@goffi.org>
parents: 85
diff changeset
672
c711be670ecd core, chat: upload plugin system:
Goffi <goffi@goffi.org>
parents: 85
diff changeset
673 # and select the variable to use according to type
c711be670ecd core, chat: upload plugin system:
Goffi <goffi@goffi.org>
parents: 85
diff changeset
674 if plugin_type == C.PLUG_TYPE_WID:
c711be670ecd core, chat: upload plugin system:
Goffi <goffi@goffi.org>
parents: 85
diff changeset
675 imported_names = imported_names_main
491
203755bbe0fe massive refactoring from camelCase -> snake_case. See backend commit log for more details
Goffi <goffi@goffi.org>
parents: 487
diff changeset
676 default_factory = self._default_factory_main
97
5d2289127bb7 menu (upload): better menu using dedicated widget:
Goffi <goffi@goffi.org>
parents: 91
diff changeset
677 elif plugin_type == C.PLUG_TYPE_TRANSFER:
5d2289127bb7 menu (upload): better menu using dedicated widget:
Goffi <goffi@goffi.org>
parents: 91
diff changeset
678 imported_names = imported_names_transfer
491
203755bbe0fe massive refactoring from camelCase -> snake_case. See backend commit log for more details
Goffi <goffi@goffi.org>
parents: 487
diff changeset
679 default_factory = self._default_factory_transfer
86
c711be670ecd core, chat: upload plugin system:
Goffi <goffi@goffi.org>
parents: 85
diff changeset
680 else:
312
772c170b47a9 Python3 port:
Goffi <goffi@goffi.org>
parents: 302
diff changeset
681 log.error("unknown plugin type {type_} for plugin {file_}, skipping"
220
24f8ab7c08be core: implemented showDialog so message/dialogs from QuickFrontend are displayed
Goffi <goffi@goffi.org>
parents: 208
diff changeset
682 .format(
86
c711be670ecd core, chat: upload plugin system:
Goffi <goffi@goffi.org>
parents: 85
diff changeset
683 type_ = plugin_type,
c711be670ecd core, chat: upload plugin system:
Goffi <goffi@goffi.org>
parents: 85
diff changeset
684 file_ = plug
c711be670ecd core, chat: upload plugin system:
Goffi <goffi@goffi.org>
parents: 85
diff changeset
685 ))
c711be670ecd core, chat: upload plugin system:
Goffi <goffi@goffi.org>
parents: 85
diff changeset
686 continue
491
203755bbe0fe massive refactoring from camelCase -> snake_case. See backend commit log for more details
Goffi <goffi@goffi.org>
parents: 487
diff changeset
687 plugins_set = self._get_plugins_set(plugin_type)
86
c711be670ecd core, chat: upload plugin system:
Goffi <goffi@goffi.org>
parents: 85
diff changeset
688
15
56838ad5c84b files reorganisation, cagou is now launched with python2 cagou.py in src/
Goffi <goffi@goffi.org>
parents: 14
diff changeset
689 mod = import_module(plugin_path)
14
21a432afd06d plugin system, first draft:
Goffi <goffi@goffi.org>
parents: 13
diff changeset
690 try:
21a432afd06d plugin system, first draft:
Goffi <goffi@goffi.org>
parents: 13
diff changeset
691 plugin_info = mod.PLUGIN_INFO
21a432afd06d plugin system, first draft:
Goffi <goffi@goffi.org>
parents: 13
diff changeset
692 except AttributeError:
21a432afd06d plugin system, first draft:
Goffi <goffi@goffi.org>
parents: 13
diff changeset
693 plugin_info = {}
21a432afd06d plugin system, first draft:
Goffi <goffi@goffi.org>
parents: 13
diff changeset
694
86
c711be670ecd core, chat: upload plugin system:
Goffi <goffi@goffi.org>
parents: 85
diff changeset
695 plugin_info['plugin_file'] = plug
c711be670ecd core, chat: upload plugin system:
Goffi <goffi@goffi.org>
parents: 85
diff changeset
696 plugin_info['plugin_type'] = plugin_type
c711be670ecd core, chat: upload plugin system:
Goffi <goffi@goffi.org>
parents: 85
diff changeset
697
c711be670ecd core, chat: upload plugin system:
Goffi <goffi@goffi.org>
parents: 85
diff changeset
698 if 'platforms' in plugin_info:
c711be670ecd core, chat: upload plugin system:
Goffi <goffi@goffi.org>
parents: 85
diff changeset
699 if sys.platform not in plugin_info['platforms']:
312
772c170b47a9 Python3 port:
Goffi <goffi@goffi.org>
parents: 302
diff changeset
700 log.info("{plugin_file} is not used on this platform, skipping"
220
24f8ab7c08be core: implemented showDialog so message/dialogs from QuickFrontend are displayed
Goffi <goffi@goffi.org>
parents: 208
diff changeset
701 .format(**plugin_info))
86
c711be670ecd core, chat: upload plugin system:
Goffi <goffi@goffi.org>
parents: 85
diff changeset
702 continue
c711be670ecd core, chat: upload plugin system:
Goffi <goffi@goffi.org>
parents: 85
diff changeset
703
14
21a432afd06d plugin system, first draft:
Goffi <goffi@goffi.org>
parents: 13
diff changeset
704 # import name is used to differentiate plugins
21a432afd06d plugin system, first draft:
Goffi <goffi@goffi.org>
parents: 13
diff changeset
705 if 'import_name' not in plugin_info:
21a432afd06d plugin system, first draft:
Goffi <goffi@goffi.org>
parents: 13
diff changeset
706 plugin_info['import_name'] = plug
86
c711be670ecd core, chat: upload plugin system:
Goffi <goffi@goffi.org>
parents: 85
diff changeset
707 if plugin_info['import_name'] in imported_names:
312
772c170b47a9 Python3 port:
Goffi <goffi@goffi.org>
parents: 302
diff changeset
708 log.warning(_("there is already a plugin named {}, "
772c170b47a9 Python3 port:
Goffi <goffi@goffi.org>
parents: 302
diff changeset
709 "ignoring new one").format(plugin_info['import_name']))
14
21a432afd06d plugin system, first draft:
Goffi <goffi@goffi.org>
parents: 13
diff changeset
710 continue
21a432afd06d plugin system, first draft:
Goffi <goffi@goffi.org>
parents: 13
diff changeset
711 if plugin_info['import_name'] == C.WID_SELECTOR:
86
c711be670ecd core, chat: upload plugin system:
Goffi <goffi@goffi.org>
parents: 85
diff changeset
712 if plugin_type != C.PLUG_TYPE_WID:
312
772c170b47a9 Python3 port:
Goffi <goffi@goffi.org>
parents: 302
diff changeset
713 log.error("{import_name} import name can only be used with {type_} "
772c170b47a9 Python3 port:
Goffi <goffi@goffi.org>
parents: 302
diff changeset
714 "type, skipping {name}".format(type_=C.PLUG_TYPE_WID,
220
24f8ab7c08be core: implemented showDialog so message/dialogs from QuickFrontend are displayed
Goffi <goffi@goffi.org>
parents: 208
diff changeset
715 **plugin_info))
86
c711be670ecd core, chat: upload plugin system:
Goffi <goffi@goffi.org>
parents: 85
diff changeset
716 continue
14
21a432afd06d plugin system, first draft:
Goffi <goffi@goffi.org>
parents: 13
diff changeset
717 # if WidgetSelector exists, it will be our default widget
21a432afd06d plugin system, first draft:
Goffi <goffi@goffi.org>
parents: 13
diff changeset
718 self.default_wid = plugin_info
21a432afd06d plugin system, first draft:
Goffi <goffi@goffi.org>
parents: 13
diff changeset
719
21a432afd06d plugin system, first draft:
Goffi <goffi@goffi.org>
parents: 13
diff changeset
720 # we want everything optional, so we use plugin file name
21a432afd06d plugin system, first draft:
Goffi <goffi@goffi.org>
parents: 13
diff changeset
721 # if actual name is not found
21a432afd06d plugin system, first draft:
Goffi <goffi@goffi.org>
parents: 13
diff changeset
722 if 'name' not in plugin_info:
86
c711be670ecd core, chat: upload plugin system:
Goffi <goffi@goffi.org>
parents: 85
diff changeset
723 name_start = 8 + len(plugin_type)
c711be670ecd core, chat: upload plugin system:
Goffi <goffi@goffi.org>
parents: 85
diff changeset
724 plugin_info['name'] = plug[name_start:]
14
21a432afd06d plugin system, first draft:
Goffi <goffi@goffi.org>
parents: 13
diff changeset
725
21a432afd06d plugin system, first draft:
Goffi <goffi@goffi.org>
parents: 13
diff changeset
726 # we need to load the kv file
21a432afd06d plugin system, first draft:
Goffi <goffi@goffi.org>
parents: 13
diff changeset
727 if 'kv_file' not in plugin_info:
312
772c170b47a9 Python3 port:
Goffi <goffi@goffi.org>
parents: 302
diff changeset
728 plugin_info['kv_file'] = '{}.kv'.format(plug)
15
56838ad5c84b files reorganisation, cagou is now launched with python2 cagou.py in src/
Goffi <goffi@goffi.org>
parents: 14
diff changeset
729 kv_path = os.path.join(plugins_path, plugin_info['kv_file'])
89
d249df379fa3 core: kv files are not mandatory anymore for plugins
Goffi <goffi@goffi.org>
parents: 87
diff changeset
730 if not os.path.exists(kv_path):
312
772c170b47a9 Python3 port:
Goffi <goffi@goffi.org>
parents: 302
diff changeset
731 log.debug("no kv found for {plugin_file}".format(**plugin_info))
89
d249df379fa3 core: kv files are not mandatory anymore for plugins
Goffi <goffi@goffi.org>
parents: 87
diff changeset
732 else:
d249df379fa3 core: kv files are not mandatory anymore for plugins
Goffi <goffi@goffi.org>
parents: 87
diff changeset
733 Builder.load_file(kv_path)
14
21a432afd06d plugin system, first draft:
Goffi <goffi@goffi.org>
parents: 13
diff changeset
734
21a432afd06d plugin system, first draft:
Goffi <goffi@goffi.org>
parents: 13
diff changeset
735 # what is the main class ?
21a432afd06d plugin system, first draft:
Goffi <goffi@goffi.org>
parents: 13
diff changeset
736 main_cls = getattr(mod, plugin_info['main'])
21a432afd06d plugin system, first draft:
Goffi <goffi@goffi.org>
parents: 13
diff changeset
737 plugin_info['main'] = main_cls
21a432afd06d plugin system, first draft:
Goffi <goffi@goffi.org>
parents: 13
diff changeset
738
21a432afd06d plugin system, first draft:
Goffi <goffi@goffi.org>
parents: 13
diff changeset
739 # factory is used to create the instance
491
203755bbe0fe massive refactoring from camelCase -> snake_case. See backend commit log for more details
Goffi <goffi@goffi.org>
parents: 487
diff changeset
740 # if not found, we use a defaut one with get_or_create_widget
14
21a432afd06d plugin system, first draft:
Goffi <goffi@goffi.org>
parents: 13
diff changeset
741 if 'factory' not in plugin_info:
86
c711be670ecd core, chat: upload plugin system:
Goffi <goffi@goffi.org>
parents: 85
diff changeset
742 plugin_info['factory'] = default_factory
14
21a432afd06d plugin system, first draft:
Goffi <goffi@goffi.org>
parents: 13
diff changeset
743
25
d09bd16dbbe2 code (cagou widget), selector: icons handling + use of new muchoslava icon set
Goffi <goffi@goffi.org>
parents: 19
diff changeset
744 # icons
d09bd16dbbe2 code (cagou widget), selector: icons handling + use of new muchoslava icon set
Goffi <goffi@goffi.org>
parents: 19
diff changeset
745 for size in ('small', 'medium'):
312
772c170b47a9 Python3 port:
Goffi <goffi@goffi.org>
parents: 302
diff changeset
746 key = 'icon_{}'.format(size)
25
d09bd16dbbe2 code (cagou widget), selector: icons handling + use of new muchoslava icon set
Goffi <goffi@goffi.org>
parents: 19
diff changeset
747 try:
d09bd16dbbe2 code (cagou widget), selector: icons handling + use of new muchoslava icon set
Goffi <goffi@goffi.org>
parents: 19
diff changeset
748 path = plugin_info[key]
d09bd16dbbe2 code (cagou widget), selector: icons handling + use of new muchoslava icon set
Goffi <goffi@goffi.org>
parents: 19
diff changeset
749 except KeyError:
d09bd16dbbe2 code (cagou widget), selector: icons handling + use of new muchoslava icon set
Goffi <goffi@goffi.org>
parents: 19
diff changeset
750 path = C.DEFAULT_WIDGET_ICON.format(media=self.media_dir)
d09bd16dbbe2 code (cagou widget), selector: icons handling + use of new muchoslava icon set
Goffi <goffi@goffi.org>
parents: 19
diff changeset
751 else:
d09bd16dbbe2 code (cagou widget), selector: icons handling + use of new muchoslava icon set
Goffi <goffi@goffi.org>
parents: 19
diff changeset
752 path = path.format(media=self.media_dir)
d09bd16dbbe2 code (cagou widget), selector: icons handling + use of new muchoslava icon set
Goffi <goffi@goffi.org>
parents: 19
diff changeset
753 if not os.path.isfile(path):
d09bd16dbbe2 code (cagou widget), selector: icons handling + use of new muchoslava icon set
Goffi <goffi@goffi.org>
parents: 19
diff changeset
754 path = C.DEFAULT_WIDGET_ICON.format(media=self.media_dir)
d09bd16dbbe2 code (cagou widget), selector: icons handling + use of new muchoslava icon set
Goffi <goffi@goffi.org>
parents: 19
diff changeset
755 plugin_info[key] = path
d09bd16dbbe2 code (cagou widget), selector: icons handling + use of new muchoslava icon set
Goffi <goffi@goffi.org>
parents: 19
diff changeset
756
86
c711be670ecd core, chat: upload plugin system:
Goffi <goffi@goffi.org>
parents: 85
diff changeset
757 plugins_set.append(plugin_info)
14
21a432afd06d plugin system, first draft:
Goffi <goffi@goffi.org>
parents: 13
diff changeset
758 if not self._plg_wids:
312
772c170b47a9 Python3 port:
Goffi <goffi@goffi.org>
parents: 302
diff changeset
759 log.error(_("no widget plugin found"))
14
21a432afd06d plugin system, first draft:
Goffi <goffi@goffi.org>
parents: 13
diff changeset
760 return
21a432afd06d plugin system, first draft:
Goffi <goffi@goffi.org>
parents: 13
diff changeset
761
21a432afd06d plugin system, first draft:
Goffi <goffi@goffi.org>
parents: 13
diff changeset
762 # we want widgets sorted by names
21a432afd06d plugin system, first draft:
Goffi <goffi@goffi.org>
parents: 13
diff changeset
763 self._plg_wids.sort(key=lambda p: p['name'].lower())
97
5d2289127bb7 menu (upload): better menu using dedicated widget:
Goffi <goffi@goffi.org>
parents: 91
diff changeset
764 self._plg_wids_transfer.sort(key=lambda p: p['name'].lower())
14
21a432afd06d plugin system, first draft:
Goffi <goffi@goffi.org>
parents: 13
diff changeset
765
21a432afd06d plugin system, first draft:
Goffi <goffi@goffi.org>
parents: 13
diff changeset
766 if self.default_wid is None:
21a432afd06d plugin system, first draft:
Goffi <goffi@goffi.org>
parents: 13
diff changeset
767 # we have no selector widget, we use the first widget as default
21a432afd06d plugin system, first draft:
Goffi <goffi@goffi.org>
parents: 13
diff changeset
768 self.default_wid = self._plg_wids[0]
21a432afd06d plugin system, first draft:
Goffi <goffi@goffi.org>
parents: 13
diff changeset
769
491
203755bbe0fe massive refactoring from camelCase -> snake_case. See backend commit log for more details
Goffi <goffi@goffi.org>
parents: 487
diff changeset
770 def _get_plugins_set(self, type_):
86
c711be670ecd core, chat: upload plugin system:
Goffi <goffi@goffi.org>
parents: 85
diff changeset
771 if type_ == C.PLUG_TYPE_WID:
c711be670ecd core, chat: upload plugin system:
Goffi <goffi@goffi.org>
parents: 85
diff changeset
772 return self._plg_wids
97
5d2289127bb7 menu (upload): better menu using dedicated widget:
Goffi <goffi@goffi.org>
parents: 91
diff changeset
773 elif type_ == C.PLUG_TYPE_TRANSFER:
5d2289127bb7 menu (upload): better menu using dedicated widget:
Goffi <goffi@goffi.org>
parents: 91
diff changeset
774 return self._plg_wids_transfer
86
c711be670ecd core, chat: upload plugin system:
Goffi <goffi@goffi.org>
parents: 85
diff changeset
775 else:
312
772c170b47a9 Python3 port:
Goffi <goffi@goffi.org>
parents: 302
diff changeset
776 raise KeyError("{} plugin type is unknown".format(type_))
86
c711be670ecd core, chat: upload plugin system:
Goffi <goffi@goffi.org>
parents: 85
diff changeset
777
491
203755bbe0fe massive refactoring from camelCase -> snake_case. See backend commit log for more details
Goffi <goffi@goffi.org>
parents: 487
diff changeset
778 def get_plugged_widgets(self, type_=C.PLUG_TYPE_WID, except_cls=None):
14
21a432afd06d plugin system, first draft:
Goffi <goffi@goffi.org>
parents: 13
diff changeset
779 """get available widgets plugin infos
21a432afd06d plugin system, first draft:
Goffi <goffi@goffi.org>
parents: 13
diff changeset
780
86
c711be670ecd core, chat: upload plugin system:
Goffi <goffi@goffi.org>
parents: 85
diff changeset
781 @param type_(unicode): type of widgets to get
c711be670ecd core, chat: upload plugin system:
Goffi <goffi@goffi.org>
parents: 85
diff changeset
782 one of C.PLUG_TYPE_* constant
14
21a432afd06d plugin system, first draft:
Goffi <goffi@goffi.org>
parents: 13
diff changeset
783 @param except_cls(None, class): if not None,
21a432afd06d plugin system, first draft:
Goffi <goffi@goffi.org>
parents: 13
diff changeset
784 widgets from this class will be excluded
41
7cac2d1a6f20 core: new getPluginInfo method to retrieve plugin info corresponding to filter(s)
Goffi <goffi@goffi.org>
parents: 40
diff changeset
785 @return (iter[dict]): available widgets plugin infos
14
21a432afd06d plugin system, first draft:
Goffi <goffi@goffi.org>
parents: 13
diff changeset
786 """
491
203755bbe0fe massive refactoring from camelCase -> snake_case. See backend commit log for more details
Goffi <goffi@goffi.org>
parents: 487
diff changeset
787 plugins_set = self._get_plugins_set(type_)
86
c711be670ecd core, chat: upload plugin system:
Goffi <goffi@goffi.org>
parents: 85
diff changeset
788 for plugin_data in plugins_set:
19
c58b522607f4 main: fixed profiles value in _defaultFactory + getPluggedWidgets is now a generator
Goffi <goffi@goffi.org>
parents: 16
diff changeset
789 if plugin_data['main'] == except_cls:
c58b522607f4 main: fixed profiles value in _defaultFactory + getPluggedWidgets is now a generator
Goffi <goffi@goffi.org>
parents: 16
diff changeset
790 continue
c58b522607f4 main: fixed profiles value in _defaultFactory + getPluggedWidgets is now a generator
Goffi <goffi@goffi.org>
parents: 16
diff changeset
791 yield plugin_data
14
21a432afd06d plugin system, first draft:
Goffi <goffi@goffi.org>
parents: 13
diff changeset
792
491
203755bbe0fe massive refactoring from camelCase -> snake_case. See backend commit log for more details
Goffi <goffi@goffi.org>
parents: 487
diff changeset
793 def get_plugin_info(self, type_=C.PLUG_TYPE_WID, **kwargs):
41
7cac2d1a6f20 core: new getPluginInfo method to retrieve plugin info corresponding to filter(s)
Goffi <goffi@goffi.org>
parents: 40
diff changeset
794 """get first plugin info corresponding to filters
7cac2d1a6f20 core: new getPluginInfo method to retrieve plugin info corresponding to filter(s)
Goffi <goffi@goffi.org>
parents: 40
diff changeset
795
86
c711be670ecd core, chat: upload plugin system:
Goffi <goffi@goffi.org>
parents: 85
diff changeset
796 @param type_(unicode): type of widgets to get
c711be670ecd core, chat: upload plugin system:
Goffi <goffi@goffi.org>
parents: 85
diff changeset
797 one of C.PLUG_TYPE_* constant
41
7cac2d1a6f20 core: new getPluginInfo method to retrieve plugin info corresponding to filter(s)
Goffi <goffi@goffi.org>
parents: 40
diff changeset
798 @param **kwargs: filter(s) to use, each key present here must also
7cac2d1a6f20 core: new getPluginInfo method to retrieve plugin info corresponding to filter(s)
Goffi <goffi@goffi.org>
parents: 40
diff changeset
799 exist and be of the same value in requested plugin info
7cac2d1a6f20 core: new getPluginInfo method to retrieve plugin info corresponding to filter(s)
Goffi <goffi@goffi.org>
parents: 40
diff changeset
800 @return (dict, None): found plugin info or None
7cac2d1a6f20 core: new getPluginInfo method to retrieve plugin info corresponding to filter(s)
Goffi <goffi@goffi.org>
parents: 40
diff changeset
801 """
491
203755bbe0fe massive refactoring from camelCase -> snake_case. See backend commit log for more details
Goffi <goffi@goffi.org>
parents: 487
diff changeset
802 plugins_set = self._get_plugins_set(type_)
86
c711be670ecd core, chat: upload plugin system:
Goffi <goffi@goffi.org>
parents: 85
diff changeset
803 for plugin_info in plugins_set:
312
772c170b47a9 Python3 port:
Goffi <goffi@goffi.org>
parents: 302
diff changeset
804 for k, w in kwargs.items():
41
7cac2d1a6f20 core: new getPluginInfo method to retrieve plugin info corresponding to filter(s)
Goffi <goffi@goffi.org>
parents: 40
diff changeset
805 try:
7cac2d1a6f20 core: new getPluginInfo method to retrieve plugin info corresponding to filter(s)
Goffi <goffi@goffi.org>
parents: 40
diff changeset
806 if plugin_info[k] != w:
7cac2d1a6f20 core: new getPluginInfo method to retrieve plugin info corresponding to filter(s)
Goffi <goffi@goffi.org>
parents: 40
diff changeset
807 continue
7cac2d1a6f20 core: new getPluginInfo method to retrieve plugin info corresponding to filter(s)
Goffi <goffi@goffi.org>
parents: 40
diff changeset
808 except KeyError:
7cac2d1a6f20 core: new getPluginInfo method to retrieve plugin info corresponding to filter(s)
Goffi <goffi@goffi.org>
parents: 40
diff changeset
809 continue
7cac2d1a6f20 core: new getPluginInfo method to retrieve plugin info corresponding to filter(s)
Goffi <goffi@goffi.org>
parents: 40
diff changeset
810 return plugin_info
7cac2d1a6f20 core: new getPluginInfo method to retrieve plugin info corresponding to filter(s)
Goffi <goffi@goffi.org>
parents: 40
diff changeset
811
29
8b5827c43155 notes first draft:
Goffi <goffi@goffi.org>
parents: 28
diff changeset
812 ## widgets handling
9
7b0a53d2afd3 contact list: first draft
Goffi <goffi@goffi.org>
parents: 6
diff changeset
813
491
203755bbe0fe massive refactoring from camelCase -> snake_case. See backend commit log for more details
Goffi <goffi@goffi.org>
parents: 487
diff changeset
814 def new_widget(self, widget):
312
772c170b47a9 Python3 port:
Goffi <goffi@goffi.org>
parents: 302
diff changeset
815 log.debug("new widget created: {}".format(widget))
43
12fdc7d1feb1 core: newWidget implementation, it only display a not when a MUC room has been joined
Goffi <goffi@goffi.org>
parents: 41
diff changeset
816 if isinstance(widget, quick_chat.QuickChat) and widget.type == C.CHAT_GROUP:
491
203755bbe0fe massive refactoring from camelCase -> snake_case. See backend commit log for more details
Goffi <goffi@goffi.org>
parents: 487
diff changeset
817 self.add_note("", _("room {} has been joined").format(widget.target))
43
12fdc7d1feb1 core: newWidget implementation, it only display a not when a MUC room has been joined
Goffi <goffi@goffi.org>
parents: 41
diff changeset
818
491
203755bbe0fe massive refactoring from camelCase -> snake_case. See backend commit log for more details
Goffi <goffi@goffi.org>
parents: 487
diff changeset
819 def switch_widget(self, old, new=None):
11
49d30fc15884 core: added switchWidget method, to change a CagouWidget for an other one
Goffi <goffi@goffi.org>
parents: 9
diff changeset
820 """Replace old widget by new one
49d30fc15884 core: added switchWidget method, to change a CagouWidget for an other one
Goffi <goffi@goffi.org>
parents: 9
diff changeset
821
493
b3cedbee561d refactoring: rename `cagou` to `libervia.desktop_kivy` + update imports and names following backend changes
Goffi <goffi@goffi.org>
parents: 491
diff changeset
822 @param old(LiberviaDesktopKivyWidget, None): LiberviaDesktopKivyWidget instance or a child
250
ff1efdeff53f core: notifs can now have a custom icon and be clickable:
Goffi <goffi@goffi.org>
parents: 249
diff changeset
823 None to select automatically widget to switch
493
b3cedbee561d refactoring: rename `cagou` to `libervia.desktop_kivy` + update imports and names following backend changes
Goffi <goffi@goffi.org>
parents: 491
diff changeset
824 @param new(LiberviaDesktopKivyWidget): new widget instance
350
1ac40d3121f6 core (Cagou): "new" arg can be None in switchWidget, in which case default widget is used.
Goffi <goffi@goffi.org>
parents: 349
diff changeset
825 None to use default widget
493
b3cedbee561d refactoring: rename `cagou` to `libervia.desktop_kivy` + update imports and names following backend changes
Goffi <goffi@goffi.org>
parents: 491
diff changeset
826 @return (LiberviaDesktopKivyWidget): new widget
11
49d30fc15884 core: added switchWidget method, to change a CagouWidget for an other one
Goffi <goffi@goffi.org>
parents: 9
diff changeset
827 """
250
ff1efdeff53f core: notifs can now have a custom icon and be clickable:
Goffi <goffi@goffi.org>
parents: 249
diff changeset
828 if old is None:
491
203755bbe0fe massive refactoring from camelCase -> snake_case. See backend commit log for more details
Goffi <goffi@goffi.org>
parents: 487
diff changeset
829 old = self.get_widget_to_switch()
350
1ac40d3121f6 core (Cagou): "new" arg can be None in switchWidget, in which case default widget is used.
Goffi <goffi@goffi.org>
parents: 349
diff changeset
830 if new is None:
1ac40d3121f6 core (Cagou): "new" arg can be None in switchWidget, in which case default widget is used.
Goffi <goffi@goffi.org>
parents: 349
diff changeset
831 factory = self.default_wid['factory']
358
8efed1d47d9f core: don't crash when a widget without profiles switch to default widget
Goffi <goffi@goffi.org>
parents: 357
diff changeset
832 try:
8efed1d47d9f core: don't crash when a widget without profiles switch to default widget
Goffi <goffi@goffi.org>
parents: 357
diff changeset
833 profiles = old.profiles
8efed1d47d9f core: don't crash when a widget without profiles switch to default widget
Goffi <goffi@goffi.org>
parents: 357
diff changeset
834 except AttributeError:
8efed1d47d9f core: don't crash when a widget without profiles switch to default widget
Goffi <goffi@goffi.org>
parents: 357
diff changeset
835 profiles = None
8efed1d47d9f core: don't crash when a widget without profiles switch to default widget
Goffi <goffi@goffi.org>
parents: 357
diff changeset
836 new = factory(self.default_wid, None, profiles=profiles)
14
21a432afd06d plugin system, first draft:
Goffi <goffi@goffi.org>
parents: 13
diff changeset
837 to_change = None
493
b3cedbee561d refactoring: rename `cagou` to `libervia.desktop_kivy` + update imports and names following backend changes
Goffi <goffi@goffi.org>
parents: 491
diff changeset
838 if isinstance(old, LiberviaDesktopKivyWidget):
14
21a432afd06d plugin system, first draft:
Goffi <goffi@goffi.org>
parents: 13
diff changeset
839 to_change = old
21a432afd06d plugin system, first draft:
Goffi <goffi@goffi.org>
parents: 13
diff changeset
840 else:
21a432afd06d plugin system, first draft:
Goffi <goffi@goffi.org>
parents: 13
diff changeset
841 for w in old.walk_reverse():
493
b3cedbee561d refactoring: rename `cagou` to `libervia.desktop_kivy` + update imports and names following backend changes
Goffi <goffi@goffi.org>
parents: 491
diff changeset
842 if isinstance(w, LiberviaDesktopKivyWidget):
14
21a432afd06d plugin system, first draft:
Goffi <goffi@goffi.org>
parents: 13
diff changeset
843 to_change = w
21a432afd06d plugin system, first draft:
Goffi <goffi@goffi.org>
parents: 13
diff changeset
844 break
21a432afd06d plugin system, first draft:
Goffi <goffi@goffi.org>
parents: 13
diff changeset
845
21a432afd06d plugin system, first draft:
Goffi <goffi@goffi.org>
parents: 13
diff changeset
846 if to_change is None:
493
b3cedbee561d refactoring: rename `cagou` to `libervia.desktop_kivy` + update imports and names following backend changes
Goffi <goffi@goffi.org>
parents: 491
diff changeset
847 raise exceptions.InternalError("no LiberviaDesktopKivyWidget found when "
312
772c170b47a9 Python3 port:
Goffi <goffi@goffi.org>
parents: 302
diff changeset
848 "trying to switch widget")
154
a5e8833184c6 widget handler: refactoring:
Goffi <goffi@goffi.org>
parents: 152
diff changeset
849
491
203755bbe0fe massive refactoring from camelCase -> snake_case. See backend commit log for more details
Goffi <goffi@goffi.org>
parents: 487
diff changeset
850 # selected_widget can be modified in change_widget, so we need to set it before
357
4d3a0c4f2430 core: better back key (ESC) management:
Goffi <goffi@goffi.org>
parents: 356
diff changeset
851 self.selected_widget = new
445
9b73a1879989 core: fixed doAction when new widget is already existing and visible:
Goffi <goffi@goffi.org>
parents: 439
diff changeset
852 if to_change == new:
491
203755bbe0fe massive refactoring from camelCase -> snake_case. See backend commit log for more details
Goffi <goffi@goffi.org>
parents: 487
diff changeset
853 log.debug("switch_widget called with old==new, nothing to do")
445
9b73a1879989 core: fixed doAction when new widget is already existing and visible:
Goffi <goffi@goffi.org>
parents: 439
diff changeset
854 return new
491
203755bbe0fe massive refactoring from camelCase -> snake_case. See backend commit log for more details
Goffi <goffi@goffi.org>
parents: 487
diff changeset
855 to_change.whwrapper.change_widget(new)
385
6dacaf81339a core: return newly switched widget in switchWidget and doAction
Goffi <goffi@goffi.org>
parents: 381
diff changeset
856 return new
38
9f45098289cc widgets handler, core: hidden widgets can now be shown with swipes:
Goffi <goffi@goffi.org>
parents: 34
diff changeset
857
491
203755bbe0fe massive refactoring from camelCase -> snake_case. See backend commit log for more details
Goffi <goffi@goffi.org>
parents: 487
diff changeset
858 def _add_visible_widget(self, widget):
38
9f45098289cc widgets handler, core: hidden widgets can now be shown with swipes:
Goffi <goffi@goffi.org>
parents: 34
diff changeset
859 """declare a widget visible
9f45098289cc widgets handler, core: hidden widgets can now be shown with swipes:
Goffi <goffi@goffi.org>
parents: 34
diff changeset
860
9f45098289cc widgets handler, core: hidden widgets can now be shown with swipes:
Goffi <goffi@goffi.org>
parents: 34
diff changeset
861 for internal use only!
9f45098289cc widgets handler, core: hidden widgets can now be shown with swipes:
Goffi <goffi@goffi.org>
parents: 34
diff changeset
862 """
493
b3cedbee561d refactoring: rename `cagou` to `libervia.desktop_kivy` + update imports and names following backend changes
Goffi <goffi@goffi.org>
parents: 491
diff changeset
863 assert isinstance(widget, LiberviaDesktopKivyWidget)
352
434f770fe55b core (Cagou): add debug log for widget visibility + ignore_missing:
Goffi <goffi@goffi.org>
parents: 351
diff changeset
864 log.debug(f"Visible widget: {widget}")
434f770fe55b core (Cagou): add debug log for widget visibility + ignore_missing:
Goffi <goffi@goffi.org>
parents: 351
diff changeset
865 self._visible_widgets.setdefault(widget.__class__, set()).add(widget)
491
203755bbe0fe massive refactoring from camelCase -> snake_case. See backend commit log for more details
Goffi <goffi@goffi.org>
parents: 487
diff changeset
866 log.debug(f"visible widgets list: {self.get_visible_list(None)}")
203755bbe0fe massive refactoring from camelCase -> snake_case. See backend commit log for more details
Goffi <goffi@goffi.org>
parents: 487
diff changeset
867 widget.on_visible()
38
9f45098289cc widgets handler, core: hidden widgets can now be shown with swipes:
Goffi <goffi@goffi.org>
parents: 34
diff changeset
868
491
203755bbe0fe massive refactoring from camelCase -> snake_case. See backend commit log for more details
Goffi <goffi@goffi.org>
parents: 487
diff changeset
869 def _remove_visible_widget(self, widget, ignore_missing=False):
38
9f45098289cc widgets handler, core: hidden widgets can now be shown with swipes:
Goffi <goffi@goffi.org>
parents: 34
diff changeset
870 """declare a widget not visible anymore
9f45098289cc widgets handler, core: hidden widgets can now be shown with swipes:
Goffi <goffi@goffi.org>
parents: 34
diff changeset
871
9f45098289cc widgets handler, core: hidden widgets can now be shown with swipes:
Goffi <goffi@goffi.org>
parents: 34
diff changeset
872 for internal use only!
9f45098289cc widgets handler, core: hidden widgets can now be shown with swipes:
Goffi <goffi@goffi.org>
parents: 34
diff changeset
873 """
352
434f770fe55b core (Cagou): add debug log for widget visibility + ignore_missing:
Goffi <goffi@goffi.org>
parents: 351
diff changeset
874 log.debug(f"Widget not visible anymore: {widget}")
434f770fe55b core (Cagou): add debug log for widget visibility + ignore_missing:
Goffi <goffi@goffi.org>
parents: 351
diff changeset
875 try:
434f770fe55b core (Cagou): add debug log for widget visibility + ignore_missing:
Goffi <goffi@goffi.org>
parents: 351
diff changeset
876 self._visible_widgets[widget.__class__].remove(widget)
434f770fe55b core (Cagou): add debug log for widget visibility + ignore_missing:
Goffi <goffi@goffi.org>
parents: 351
diff changeset
877 except KeyError as e:
434f770fe55b core (Cagou): add debug log for widget visibility + ignore_missing:
Goffi <goffi@goffi.org>
parents: 351
diff changeset
878 if not ignore_missing:
434f770fe55b core (Cagou): add debug log for widget visibility + ignore_missing:
Goffi <goffi@goffi.org>
parents: 351
diff changeset
879 log.error(f"trying to remove a not visible widget ({widget}): {e}")
434f770fe55b core (Cagou): add debug log for widget visibility + ignore_missing:
Goffi <goffi@goffi.org>
parents: 351
diff changeset
880 return
491
203755bbe0fe massive refactoring from camelCase -> snake_case. See backend commit log for more details
Goffi <goffi@goffi.org>
parents: 487
diff changeset
881 log.debug(f"visible widgets list: {self.get_visible_list(None)}")
493
b3cedbee561d refactoring: rename `cagou` to `libervia.desktop_kivy` + update imports and names following backend changes
Goffi <goffi@goffi.org>
parents: 491
diff changeset
882 if isinstance(widget, LiberviaDesktopKivyWidget):
491
203755bbe0fe massive refactoring from camelCase -> snake_case. See backend commit log for more details
Goffi <goffi@goffi.org>
parents: 487
diff changeset
883 widget.on_not_visible()
264
3e11b5d923e2 core: call new methods onVisible and onNotVisible when a widget is displayed or hidden + fixed a deletion bug on _removeVisibleWidget
Goffi <goffi@goffi.org>
parents: 262
diff changeset
884 if isinstance(widget, quick_widgets.QuickWidget):
491
203755bbe0fe massive refactoring from camelCase -> snake_case. See backend commit log for more details
Goffi <goffi@goffi.org>
parents: 487
diff changeset
885 self.widgets.delete_widget(widget)
38
9f45098289cc widgets handler, core: hidden widgets can now be shown with swipes:
Goffi <goffi@goffi.org>
parents: 34
diff changeset
886
491
203755bbe0fe massive refactoring from camelCase -> snake_case. See backend commit log for more details
Goffi <goffi@goffi.org>
parents: 487
diff changeset
887 def get_visible_list(self, cls):
38
9f45098289cc widgets handler, core: hidden widgets can now be shown with swipes:
Goffi <goffi@goffi.org>
parents: 34
diff changeset
888 """get list of visible widgets for a given class
9f45098289cc widgets handler, core: hidden widgets can now be shown with swipes:
Goffi <goffi@goffi.org>
parents: 34
diff changeset
889
248
b6e33b35538b core, widgets handler: visible_widgets now keep all CagouWidgets, not only QuickWidgets. visible_quick_widgets can be used if only QuickWidgets are desired.
Goffi <goffi@goffi.org>
parents: 247
diff changeset
890 @param cls(type): type of widgets to get
351
e9d3c3793f94 core (Cagou): "None" can be used in getVisibleList's cls to get all visible widgets
Goffi <goffi@goffi.org>
parents: 350
diff changeset
891 None to get all visible widgets
e9d3c3793f94 core (Cagou): "None" can be used in getVisibleList's cls to get all visible widgets
Goffi <goffi@goffi.org>
parents: 350
diff changeset
892 @return (set[type]): visible widgets of this class
38
9f45098289cc widgets handler, core: hidden widgets can now be shown with swipes:
Goffi <goffi@goffi.org>
parents: 34
diff changeset
893 """
351
e9d3c3793f94 core (Cagou): "None" can be used in getVisibleList's cls to get all visible widgets
Goffi <goffi@goffi.org>
parents: 350
diff changeset
894 if cls is None:
e9d3c3793f94 core (Cagou): "None" can be used in getVisibleList's cls to get all visible widgets
Goffi <goffi@goffi.org>
parents: 350
diff changeset
895 ret = set()
e9d3c3793f94 core (Cagou): "None" can be used in getVisibleList's cls to get all visible widgets
Goffi <goffi@goffi.org>
parents: 350
diff changeset
896 for widgets in self._visible_widgets.values():
e9d3c3793f94 core (Cagou): "None" can be used in getVisibleList's cls to get all visible widgets
Goffi <goffi@goffi.org>
parents: 350
diff changeset
897 for w in widgets:
e9d3c3793f94 core (Cagou): "None" can be used in getVisibleList's cls to get all visible widgets
Goffi <goffi@goffi.org>
parents: 350
diff changeset
898 ret.add(w)
e9d3c3793f94 core (Cagou): "None" can be used in getVisibleList's cls to get all visible widgets
Goffi <goffi@goffi.org>
parents: 350
diff changeset
899 return ret
38
9f45098289cc widgets handler, core: hidden widgets can now be shown with swipes:
Goffi <goffi@goffi.org>
parents: 34
diff changeset
900 try:
9f45098289cc widgets handler, core: hidden widgets can now be shown with swipes:
Goffi <goffi@goffi.org>
parents: 34
diff changeset
901 return self._visible_widgets[cls]
9f45098289cc widgets handler, core: hidden widgets can now be shown with swipes:
Goffi <goffi@goffi.org>
parents: 34
diff changeset
902 except KeyError:
351
e9d3c3793f94 core (Cagou): "None" can be used in getVisibleList's cls to get all visible widgets
Goffi <goffi@goffi.org>
parents: 350
diff changeset
903 return set()
38
9f45098289cc widgets handler, core: hidden widgets can now be shown with swipes:
Goffi <goffi@goffi.org>
parents: 34
diff changeset
904
491
203755bbe0fe massive refactoring from camelCase -> snake_case. See backend commit log for more details
Goffi <goffi@goffi.org>
parents: 487
diff changeset
905 def delete_unused_widget_instances(self, widget):
353
19422bbd9c8e core (widgets handler): refactoring:
Goffi <goffi@goffi.org>
parents: 352
diff changeset
906 """Delete instance of this widget which are not attached to a WHWrapper
260
145c29b5f2b5 core: improved getOrClone + use in chat and widgets_handler:
Goffi <goffi@goffi.org>
parents: 259
diff changeset
907
145c29b5f2b5 core: improved getOrClone + use in chat and widgets_handler:
Goffi <goffi@goffi.org>
parents: 259
diff changeset
908 @param widget(quick_widgets.QuickWidget): reference widget
145c29b5f2b5 core: improved getOrClone + use in chat and widgets_handler:
Goffi <goffi@goffi.org>
parents: 259
diff changeset
909 other instance of this widget will be deleted if they have no parent
145c29b5f2b5 core: improved getOrClone + use in chat and widgets_handler:
Goffi <goffi@goffi.org>
parents: 259
diff changeset
910 """
145c29b5f2b5 core: improved getOrClone + use in chat and widgets_handler:
Goffi <goffi@goffi.org>
parents: 259
diff changeset
911 to_delete = []
267
896f78760b63 core: fixed crash when calling deleteUnusedWidgetInstances on widgets not inheriting from QuickWidget
Goffi <goffi@goffi.org>
parents: 266
diff changeset
912 if isinstance(widget, quick_widgets.QuickWidget):
491
203755bbe0fe massive refactoring from camelCase -> snake_case. See backend commit log for more details
Goffi <goffi@goffi.org>
parents: 487
diff changeset
913 for w in self.widgets.get_widget_instances(widget):
353
19422bbd9c8e core (widgets handler): refactoring:
Goffi <goffi@goffi.org>
parents: 352
diff changeset
914 if w.whwrapper is None and w != widget:
267
896f78760b63 core: fixed crash when calling deleteUnusedWidgetInstances on widgets not inheriting from QuickWidget
Goffi <goffi@goffi.org>
parents: 266
diff changeset
915 to_delete.append(w)
896f78760b63 core: fixed crash when calling deleteUnusedWidgetInstances on widgets not inheriting from QuickWidget
Goffi <goffi@goffi.org>
parents: 266
diff changeset
916 for w in to_delete:
312
772c170b47a9 Python3 port:
Goffi <goffi@goffi.org>
parents: 302
diff changeset
917 log.debug("cleaning widget: {wid}".format(wid=w))
491
203755bbe0fe massive refactoring from camelCase -> snake_case. See backend commit log for more details
Goffi <goffi@goffi.org>
parents: 487
diff changeset
918 self.widgets.delete_widget(w)
260
145c29b5f2b5 core: improved getOrClone + use in chat and widgets_handler:
Goffi <goffi@goffi.org>
parents: 259
diff changeset
919
491
203755bbe0fe massive refactoring from camelCase -> snake_case. See backend commit log for more details
Goffi <goffi@goffi.org>
parents: 487
diff changeset
920 def get_or_clone(self, widget, **kwargs):
353
19422bbd9c8e core (widgets handler): refactoring:
Goffi <goffi@goffi.org>
parents: 352
diff changeset
921 """Get a QuickWidget if it is not in a WHWrapper, else clone it
260
145c29b5f2b5 core: improved getOrClone + use in chat and widgets_handler:
Goffi <goffi@goffi.org>
parents: 259
diff changeset
922
353
19422bbd9c8e core (widgets handler): refactoring:
Goffi <goffi@goffi.org>
parents: 352
diff changeset
923 if an other instance of this widget exist without being in a WHWrapper
19422bbd9c8e core (widgets handler): refactoring:
Goffi <goffi@goffi.org>
parents: 352
diff changeset
924 (i.e. if it is not already in use) it will be used.
260
145c29b5f2b5 core: improved getOrClone + use in chat and widgets_handler:
Goffi <goffi@goffi.org>
parents: 259
diff changeset
925 """
353
19422bbd9c8e core (widgets handler): refactoring:
Goffi <goffi@goffi.org>
parents: 352
diff changeset
926 if widget.whwrapper is None:
19422bbd9c8e core (widgets handler): refactoring:
Goffi <goffi@goffi.org>
parents: 352
diff changeset
927 if widget.parent is not None:
19422bbd9c8e core (widgets handler): refactoring:
Goffi <goffi@goffi.org>
parents: 352
diff changeset
928 widget.parent.remove_widget(widget)
491
203755bbe0fe massive refactoring from camelCase -> snake_case. See backend commit log for more details
Goffi <goffi@goffi.org>
parents: 487
diff changeset
929 self.delete_unused_widget_instances(widget)
38
9f45098289cc widgets handler, core: hidden widgets can now be shown with swipes:
Goffi <goffi@goffi.org>
parents: 34
diff changeset
930 return widget
491
203755bbe0fe massive refactoring from camelCase -> snake_case. See backend commit log for more details
Goffi <goffi@goffi.org>
parents: 487
diff changeset
931 for w in self.widgets.get_widget_instances(widget):
353
19422bbd9c8e core (widgets handler): refactoring:
Goffi <goffi@goffi.org>
parents: 352
diff changeset
932 if w.whwrapper is None:
19422bbd9c8e core (widgets handler): refactoring:
Goffi <goffi@goffi.org>
parents: 352
diff changeset
933 if w.parent is not None:
19422bbd9c8e core (widgets handler): refactoring:
Goffi <goffi@goffi.org>
parents: 352
diff changeset
934 w.parent.remove_widget(w)
491
203755bbe0fe massive refactoring from camelCase -> snake_case. See backend commit log for more details
Goffi <goffi@goffi.org>
parents: 487
diff changeset
935 self.delete_unused_widget_instances(w)
260
145c29b5f2b5 core: improved getOrClone + use in chat and widgets_handler:
Goffi <goffi@goffi.org>
parents: 259
diff changeset
936 return w
38
9f45098289cc widgets handler, core: hidden widgets can now be shown with swipes:
Goffi <goffi@goffi.org>
parents: 34
diff changeset
937 targets = list(widget.targets)
491
203755bbe0fe massive refactoring from camelCase -> snake_case. See backend commit log for more details
Goffi <goffi@goffi.org>
parents: 487
diff changeset
938 w = self.widgets.get_or_create_widget(widget.__class__,
220
24f8ab7c08be core: implemented showDialog so message/dialogs from QuickFrontend are displayed
Goffi <goffi@goffi.org>
parents: 208
diff changeset
939 targets[0],
24f8ab7c08be core: implemented showDialog so message/dialogs from QuickFrontend are displayed
Goffi <goffi@goffi.org>
parents: 208
diff changeset
940 on_new_widget=None,
24f8ab7c08be core: implemented showDialog so message/dialogs from QuickFrontend are displayed
Goffi <goffi@goffi.org>
parents: 208
diff changeset
941 on_existing_widget=C.WIDGET_RECREATE,
353
19422bbd9c8e core (widgets handler): refactoring:
Goffi <goffi@goffi.org>
parents: 352
diff changeset
942 profiles=widget.profiles,
19422bbd9c8e core (widgets handler): refactoring:
Goffi <goffi@goffi.org>
parents: 352
diff changeset
943 **kwargs)
38
9f45098289cc widgets handler, core: hidden widgets can now be shown with swipes:
Goffi <goffi@goffi.org>
parents: 34
diff changeset
944 for t in targets[1:]:
491
203755bbe0fe massive refactoring from camelCase -> snake_case. See backend commit log for more details
Goffi <goffi@goffi.org>
parents: 487
diff changeset
945 w.add_target(t)
38
9f45098289cc widgets handler, core: hidden widgets can now be shown with swipes:
Goffi <goffi@goffi.org>
parents: 34
diff changeset
946 return w
29
8b5827c43155 notes first draft:
Goffi <goffi@goffi.org>
parents: 28
diff changeset
947
491
203755bbe0fe massive refactoring from camelCase -> snake_case. See backend commit log for more details
Goffi <goffi@goffi.org>
parents: 487
diff changeset
948 def get_widget_to_switch(self):
250
ff1efdeff53f core: notifs can now have a custom icon and be clickable:
Goffi <goffi@goffi.org>
parents: 249
diff changeset
949 """Choose best candidate when we need to switch widget and old is not specified
ff1efdeff53f core: notifs can now have a custom icon and be clickable:
Goffi <goffi@goffi.org>
parents: 249
diff changeset
950
493
b3cedbee561d refactoring: rename `cagou` to `libervia.desktop_kivy` + update imports and names following backend changes
Goffi <goffi@goffi.org>
parents: 491
diff changeset
951 @return (LiberviaDesktopKivyWidget): widget to switch
250
ff1efdeff53f core: notifs can now have a custom icon and be clickable:
Goffi <goffi@goffi.org>
parents: 249
diff changeset
952 """
385
6dacaf81339a core: return newly switched widget in switchWidget and doAction
Goffi <goffi@goffi.org>
parents: 381
diff changeset
953 if (self._selected_widget_main is not None
6dacaf81339a core: return newly switched widget in switchWidget and doAction
Goffi <goffi@goffi.org>
parents: 381
diff changeset
954 and self._selected_widget_main.whwrapper is not None):
363
816a0c880f52 core: use selected widget from main screen in getWidgetToSwitch:
Goffi <goffi@goffi.org>
parents: 360
diff changeset
955 # we are not on the main screen, we want to switch a widget from main screen
816a0c880f52 core: use selected widget from main screen in getWidgetToSwitch:
Goffi <goffi@goffi.org>
parents: 360
diff changeset
956 return self._selected_widget_main
385
6dacaf81339a core: return newly switched widget in switchWidget and doAction
Goffi <goffi@goffi.org>
parents: 381
diff changeset
957 elif (self.selected_widget is not None
493
b3cedbee561d refactoring: rename `cagou` to `libervia.desktop_kivy` + update imports and names following backend changes
Goffi <goffi@goffi.org>
parents: 491
diff changeset
958 and isinstance(self.selected_widget, LiberviaDesktopKivyWidget)
385
6dacaf81339a core: return newly switched widget in switchWidget and doAction
Goffi <goffi@goffi.org>
parents: 381
diff changeset
959 and self.selected_widget.whwrapper is not None):
250
ff1efdeff53f core: notifs can now have a custom icon and be clickable:
Goffi <goffi@goffi.org>
parents: 249
diff changeset
960 return self.selected_widget
ff1efdeff53f core: notifs can now have a custom icon and be clickable:
Goffi <goffi@goffi.org>
parents: 249
diff changeset
961 # no widget is selected we check if we have any default widget
357
4d3a0c4f2430 core: better back key (ESC) management:
Goffi <goffi@goffi.org>
parents: 356
diff changeset
962 default_cls = self.default_class
250
ff1efdeff53f core: notifs can now have a custom icon and be clickable:
Goffi <goffi@goffi.org>
parents: 249
diff changeset
963 for w in self.visible_widgets:
ff1efdeff53f core: notifs can now have a custom icon and be clickable:
Goffi <goffi@goffi.org>
parents: 249
diff changeset
964 if isinstance(w, default_cls):
ff1efdeff53f core: notifs can now have a custom icon and be clickable:
Goffi <goffi@goffi.org>
parents: 249
diff changeset
965 return w
ff1efdeff53f core: notifs can now have a custom icon and be clickable:
Goffi <goffi@goffi.org>
parents: 249
diff changeset
966
ff1efdeff53f core: notifs can now have a custom icon and be clickable:
Goffi <goffi@goffi.org>
parents: 249
diff changeset
967 # no default widget found, we return the first widget
ff1efdeff53f core: notifs can now have a custom icon and be clickable:
Goffi <goffi@goffi.org>
parents: 249
diff changeset
968 return next(iter(self.visible_widgets))
ff1efdeff53f core: notifs can now have a custom icon and be clickable:
Goffi <goffi@goffi.org>
parents: 249
diff changeset
969
491
203755bbe0fe massive refactoring from camelCase -> snake_case. See backend commit log for more details
Goffi <goffi@goffi.org>
parents: 487
diff changeset
970 def do_action(self, action, target, profiles):
250
ff1efdeff53f core: notifs can now have a custom icon and be clickable:
Goffi <goffi@goffi.org>
parents: 249
diff changeset
971 """Launch an action handler by a plugin
ff1efdeff53f core: notifs can now have a custom icon and be clickable:
Goffi <goffi@goffi.org>
parents: 249
diff changeset
972
ff1efdeff53f core: notifs can now have a custom icon and be clickable:
Goffi <goffi@goffi.org>
parents: 249
diff changeset
973 @param action(unicode): action to do, can be:
ff1efdeff53f core: notifs can now have a custom icon and be clickable:
Goffi <goffi@goffi.org>
parents: 249
diff changeset
974 - chat: open a chat widget
ff1efdeff53f core: notifs can now have a custom icon and be clickable:
Goffi <goffi@goffi.org>
parents: 249
diff changeset
975 @param target(unicode): target of the action
ff1efdeff53f core: notifs can now have a custom icon and be clickable:
Goffi <goffi@goffi.org>
parents: 249
diff changeset
976 @param profiles(list[unicode]): profiles to use
493
b3cedbee561d refactoring: rename `cagou` to `libervia.desktop_kivy` + update imports and names following backend changes
Goffi <goffi@goffi.org>
parents: 491
diff changeset
977 @return (LiberviaDesktopKivyWidget, None): new widget
250
ff1efdeff53f core: notifs can now have a custom icon and be clickable:
Goffi <goffi@goffi.org>
parents: 249
diff changeset
978 """
ff1efdeff53f core: notifs can now have a custom icon and be clickable:
Goffi <goffi@goffi.org>
parents: 249
diff changeset
979 try:
ff1efdeff53f core: notifs can now have a custom icon and be clickable:
Goffi <goffi@goffi.org>
parents: 249
diff changeset
980 # FIXME: Q&D way to get chat plugin, should be replaced by a clean method
ff1efdeff53f core: notifs can now have a custom icon and be clickable:
Goffi <goffi@goffi.org>
parents: 249
diff changeset
981 # in host
491
203755bbe0fe massive refactoring from camelCase -> snake_case. See backend commit log for more details
Goffi <goffi@goffi.org>
parents: 487
diff changeset
982 plg_infos = [p for p in self.get_plugged_widgets()
250
ff1efdeff53f core: notifs can now have a custom icon and be clickable:
Goffi <goffi@goffi.org>
parents: 249
diff changeset
983 if action in p['import_name']][0]
ff1efdeff53f core: notifs can now have a custom icon and be clickable:
Goffi <goffi@goffi.org>
parents: 249
diff changeset
984 except IndexError:
312
772c170b47a9 Python3 port:
Goffi <goffi@goffi.org>
parents: 302
diff changeset
985 log.warning("No plugin widget found to do {action}".format(action=action))
250
ff1efdeff53f core: notifs can now have a custom icon and be clickable:
Goffi <goffi@goffi.org>
parents: 249
diff changeset
986 else:
445
9b73a1879989 core: fixed doAction when new widget is already existing and visible:
Goffi <goffi@goffi.org>
parents: 439
diff changeset
987 try:
9b73a1879989 core: fixed doAction when new widget is already existing and visible:
Goffi <goffi@goffi.org>
parents: 439
diff changeset
988 # does the widget already exist?
491
203755bbe0fe massive refactoring from camelCase -> snake_case. See backend commit log for more details
Goffi <goffi@goffi.org>
parents: 487
diff changeset
989 wid = next(self.widgets.get_widgets(
445
9b73a1879989 core: fixed doAction when new widget is already existing and visible:
Goffi <goffi@goffi.org>
parents: 439
diff changeset
990 plg_infos['main'],
9b73a1879989 core: fixed doAction when new widget is already existing and visible:
Goffi <goffi@goffi.org>
parents: 439
diff changeset
991 target=target,
9b73a1879989 core: fixed doAction when new widget is already existing and visible:
Goffi <goffi@goffi.org>
parents: 439
diff changeset
992 profiles=profiles))
9b73a1879989 core: fixed doAction when new widget is already existing and visible:
Goffi <goffi@goffi.org>
parents: 439
diff changeset
993 except StopIteration:
9b73a1879989 core: fixed doAction when new widget is already existing and visible:
Goffi <goffi@goffi.org>
parents: 439
diff changeset
994 # no, let's create a new one
9b73a1879989 core: fixed doAction when new widget is already existing and visible:
Goffi <goffi@goffi.org>
parents: 439
diff changeset
995 factory = plg_infos['factory']
9b73a1879989 core: fixed doAction when new widget is already existing and visible:
Goffi <goffi@goffi.org>
parents: 439
diff changeset
996 wid = factory(plg_infos, target=target, profiles=profiles)
9b73a1879989 core: fixed doAction when new widget is already existing and visible:
Goffi <goffi@goffi.org>
parents: 439
diff changeset
997
491
203755bbe0fe massive refactoring from camelCase -> snake_case. See backend commit log for more details
Goffi <goffi@goffi.org>
parents: 487
diff changeset
998 return self.switch_widget(None, wid)
250
ff1efdeff53f core: notifs can now have a custom icon and be clickable:
Goffi <goffi@goffi.org>
parents: 249
diff changeset
999
122
dcd6fbb3f010 chat: handle new OTR state signal and change encryption icon consequently
Goffi <goffi@goffi.org>
parents: 119
diff changeset
1000 ## bridge handlers ##
dcd6fbb3f010 chat: handle new OTR state signal and change encryption icon consequently
Goffi <goffi@goffi.org>
parents: 119
diff changeset
1001
514
d78728d7fd6a plugin wid calls, core: implements WebRTC DataChannel file transfer:
Goffi <goffi@goffi.org>
parents: 505
diff changeset
1002 async def _on_webrtc_file(
d78728d7fd6a plugin wid calls, core: implements WebRTC DataChannel file transfer:
Goffi <goffi@goffi.org>
parents: 505
diff changeset
1003 self,
d78728d7fd6a plugin wid calls, core: implements WebRTC DataChannel file transfer:
Goffi <goffi@goffi.org>
parents: 505
diff changeset
1004 action_data: dict,
d78728d7fd6a plugin wid calls, core: implements WebRTC DataChannel file transfer:
Goffi <goffi@goffi.org>
parents: 505
diff changeset
1005 action_id: str|None,
d78728d7fd6a plugin wid calls, core: implements WebRTC DataChannel file transfer:
Goffi <goffi@goffi.org>
parents: 505
diff changeset
1006 profile: str
d78728d7fd6a plugin wid calls, core: implements WebRTC DataChannel file transfer:
Goffi <goffi@goffi.org>
parents: 505
diff changeset
1007 ) -> None:
d78728d7fd6a plugin wid calls, core: implements WebRTC DataChannel file transfer:
Goffi <goffi@goffi.org>
parents: 505
diff changeset
1008 assert action_id is not None
d78728d7fd6a plugin wid calls, core: implements WebRTC DataChannel file transfer:
Goffi <goffi@goffi.org>
parents: 505
diff changeset
1009 try:
d78728d7fd6a plugin wid calls, core: implements WebRTC DataChannel file transfer:
Goffi <goffi@goffi.org>
parents: 505
diff changeset
1010 xmlui_data = action_data["xmlui"]
d78728d7fd6a plugin wid calls, core: implements WebRTC DataChannel file transfer:
Goffi <goffi@goffi.org>
parents: 505
diff changeset
1011 except KeyError:
d78728d7fd6a plugin wid calls, core: implements WebRTC DataChannel file transfer:
Goffi <goffi@goffi.org>
parents: 505
diff changeset
1012 raise exceptions.InternalError("Missing XMLUI in file action.")
d78728d7fd6a plugin wid calls, core: implements WebRTC DataChannel file transfer:
Goffi <goffi@goffi.org>
parents: 505
diff changeset
1013
d78728d7fd6a plugin wid calls, core: implements WebRTC DataChannel file transfer:
Goffi <goffi@goffi.org>
parents: 505
diff changeset
1014 try:
d78728d7fd6a plugin wid calls, core: implements WebRTC DataChannel file transfer:
Goffi <goffi@goffi.org>
parents: 505
diff changeset
1015 from_jid = jid.JID(action_data["from_jid"])
d78728d7fd6a plugin wid calls, core: implements WebRTC DataChannel file transfer:
Goffi <goffi@goffi.org>
parents: 505
diff changeset
1016 except KeyError:
d78728d7fd6a plugin wid calls, core: implements WebRTC DataChannel file transfer:
Goffi <goffi@goffi.org>
parents: 505
diff changeset
1017 raise exceptions.InternalError(
d78728d7fd6a plugin wid calls, core: implements WebRTC DataChannel file transfer:
Goffi <goffi@goffi.org>
parents: 505
diff changeset
1018 f"Missing 'from_jid' key: {action_data!r}"
d78728d7fd6a plugin wid calls, core: implements WebRTC DataChannel file transfer:
Goffi <goffi@goffi.org>
parents: 505
diff changeset
1019 )
d78728d7fd6a plugin wid calls, core: implements WebRTC DataChannel file transfer:
Goffi <goffi@goffi.org>
parents: 505
diff changeset
1020 from libervia.frontends.tools.webrtc_file import WebRTCFileReceiver
d78728d7fd6a plugin wid calls, core: implements WebRTC DataChannel file transfer:
Goffi <goffi@goffi.org>
parents: 505
diff changeset
1021 confirm_msg = WebRTCFileReceiver.format_confirm_msg(action_data, from_jid)
d78728d7fd6a plugin wid calls, core: implements WebRTC DataChannel file transfer:
Goffi <goffi@goffi.org>
parents: 505
diff changeset
1022
d78728d7fd6a plugin wid calls, core: implements WebRTC DataChannel file transfer:
Goffi <goffi@goffi.org>
parents: 505
diff changeset
1023 file_accepted = action_data.get("file_accepted", False)
d78728d7fd6a plugin wid calls, core: implements WebRTC DataChannel file transfer:
Goffi <goffi@goffi.org>
parents: 505
diff changeset
1024 if file_accepted:
d78728d7fd6a plugin wid calls, core: implements WebRTC DataChannel file transfer:
Goffi <goffi@goffi.org>
parents: 505
diff changeset
1025 accepted = True
d78728d7fd6a plugin wid calls, core: implements WebRTC DataChannel file transfer:
Goffi <goffi@goffi.org>
parents: 505
diff changeset
1026 else:
d78728d7fd6a plugin wid calls, core: implements WebRTC DataChannel file transfer:
Goffi <goffi@goffi.org>
parents: 505
diff changeset
1027 accepted = await self.ask_confirmation(confirm_msg, _("File Request"))
d78728d7fd6a plugin wid calls, core: implements WebRTC DataChannel file transfer:
Goffi <goffi@goffi.org>
parents: 505
diff changeset
1028
d78728d7fd6a plugin wid calls, core: implements WebRTC DataChannel file transfer:
Goffi <goffi@goffi.org>
parents: 505
diff changeset
1029 xmlui_data = {"answer": C.bool_const(accepted)}
d78728d7fd6a plugin wid calls, core: implements WebRTC DataChannel file transfer:
Goffi <goffi@goffi.org>
parents: 505
diff changeset
1030 if accepted:
d78728d7fd6a plugin wid calls, core: implements WebRTC DataChannel file transfer:
Goffi <goffi@goffi.org>
parents: 505
diff changeset
1031 file_data = action_data.get("file_data") or {}
d78728d7fd6a plugin wid calls, core: implements WebRTC DataChannel file transfer:
Goffi <goffi@goffi.org>
parents: 505
diff changeset
1032 file_name = file_data.get("name", "received_file")
d78728d7fd6a plugin wid calls, core: implements WebRTC DataChannel file transfer:
Goffi <goffi@goffi.org>
parents: 505
diff changeset
1033 dest_path_s = await FileChooser.a_open(
d78728d7fd6a plugin wid calls, core: implements WebRTC DataChannel file transfer:
Goffi <goffi@goffi.org>
parents: 505
diff changeset
1034 mode="save",
d78728d7fd6a plugin wid calls, core: implements WebRTC DataChannel file transfer:
Goffi <goffi@goffi.org>
parents: 505
diff changeset
1035 title=_("Please select the destination for file {file_name!r}.").format(
d78728d7fd6a plugin wid calls, core: implements WebRTC DataChannel file transfer:
Goffi <goffi@goffi.org>
parents: 505
diff changeset
1036 file_name=file_name
d78728d7fd6a plugin wid calls, core: implements WebRTC DataChannel file transfer:
Goffi <goffi@goffi.org>
parents: 505
diff changeset
1037 ),
d78728d7fd6a plugin wid calls, core: implements WebRTC DataChannel file transfer:
Goffi <goffi@goffi.org>
parents: 505
diff changeset
1038 # FIXME: It doesn't seem to be a way to specify destination file name,
d78728d7fd6a plugin wid calls, core: implements WebRTC DataChannel file transfer:
Goffi <goffi@goffi.org>
parents: 505
diff changeset
1039 # ``path`` doesn't work this way, at least on Linux/KDE.
d78728d7fd6a plugin wid calls, core: implements WebRTC DataChannel file transfer:
Goffi <goffi@goffi.org>
parents: 505
diff changeset
1040 default_path=f"./{file_name}"
d78728d7fd6a plugin wid calls, core: implements WebRTC DataChannel file transfer:
Goffi <goffi@goffi.org>
parents: 505
diff changeset
1041 )
d78728d7fd6a plugin wid calls, core: implements WebRTC DataChannel file transfer:
Goffi <goffi@goffi.org>
parents: 505
diff changeset
1042 if dest_path_s is None:
d78728d7fd6a plugin wid calls, core: implements WebRTC DataChannel file transfer:
Goffi <goffi@goffi.org>
parents: 505
diff changeset
1043 accepted = False
d78728d7fd6a plugin wid calls, core: implements WebRTC DataChannel file transfer:
Goffi <goffi@goffi.org>
parents: 505
diff changeset
1044 else:
d78728d7fd6a plugin wid calls, core: implements WebRTC DataChannel file transfer:
Goffi <goffi@goffi.org>
parents: 505
diff changeset
1045 dest_path = Path(dest_path_s)
d78728d7fd6a plugin wid calls, core: implements WebRTC DataChannel file transfer:
Goffi <goffi@goffi.org>
parents: 505
diff changeset
1046 try:
d78728d7fd6a plugin wid calls, core: implements WebRTC DataChannel file transfer:
Goffi <goffi@goffi.org>
parents: 505
diff changeset
1047 session_id = action_data["session_id"]
d78728d7fd6a plugin wid calls, core: implements WebRTC DataChannel file transfer:
Goffi <goffi@goffi.org>
parents: 505
diff changeset
1048 except KeyError:
d78728d7fd6a plugin wid calls, core: implements WebRTC DataChannel file transfer:
Goffi <goffi@goffi.org>
parents: 505
diff changeset
1049 raise exceptions.InternalError("'session_id' is missing.")
d78728d7fd6a plugin wid calls, core: implements WebRTC DataChannel file transfer:
Goffi <goffi@goffi.org>
parents: 505
diff changeset
1050 file_receiver = WebRTCFileReceiver(
d78728d7fd6a plugin wid calls, core: implements WebRTC DataChannel file transfer:
Goffi <goffi@goffi.org>
parents: 505
diff changeset
1051 self.a_bridge,
d78728d7fd6a plugin wid calls, core: implements WebRTC DataChannel file transfer:
Goffi <goffi@goffi.org>
parents: 505
diff changeset
1052 profile,
d78728d7fd6a plugin wid calls, core: implements WebRTC DataChannel file transfer:
Goffi <goffi@goffi.org>
parents: 505
diff changeset
1053 on_close_cb=lambda: self.add_note(
d78728d7fd6a plugin wid calls, core: implements WebRTC DataChannel file transfer:
Goffi <goffi@goffi.org>
parents: 505
diff changeset
1054 _("File Received"),
d78728d7fd6a plugin wid calls, core: implements WebRTC DataChannel file transfer:
Goffi <goffi@goffi.org>
parents: 505
diff changeset
1055 _('The file "{file_name}" has been successfuly received.').format(
d78728d7fd6a plugin wid calls, core: implements WebRTC DataChannel file transfer:
Goffi <goffi@goffi.org>
parents: 505
diff changeset
1056 file_name = file_data.get("name", "")
d78728d7fd6a plugin wid calls, core: implements WebRTC DataChannel file transfer:
Goffi <goffi@goffi.org>
parents: 505
diff changeset
1057 )
d78728d7fd6a plugin wid calls, core: implements WebRTC DataChannel file transfer:
Goffi <goffi@goffi.org>
parents: 505
diff changeset
1058 )
d78728d7fd6a plugin wid calls, core: implements WebRTC DataChannel file transfer:
Goffi <goffi@goffi.org>
parents: 505
diff changeset
1059 )
d78728d7fd6a plugin wid calls, core: implements WebRTC DataChannel file transfer:
Goffi <goffi@goffi.org>
parents: 505
diff changeset
1060 await file_receiver.receive_file_webrtc(
d78728d7fd6a plugin wid calls, core: implements WebRTC DataChannel file transfer:
Goffi <goffi@goffi.org>
parents: 505
diff changeset
1061 from_jid,
d78728d7fd6a plugin wid calls, core: implements WebRTC DataChannel file transfer:
Goffi <goffi@goffi.org>
parents: 505
diff changeset
1062 session_id,
d78728d7fd6a plugin wid calls, core: implements WebRTC DataChannel file transfer:
Goffi <goffi@goffi.org>
parents: 505
diff changeset
1063 dest_path,
d78728d7fd6a plugin wid calls, core: implements WebRTC DataChannel file transfer:
Goffi <goffi@goffi.org>
parents: 505
diff changeset
1064 file_data
d78728d7fd6a plugin wid calls, core: implements WebRTC DataChannel file transfer:
Goffi <goffi@goffi.org>
parents: 505
diff changeset
1065 )
d78728d7fd6a plugin wid calls, core: implements WebRTC DataChannel file transfer:
Goffi <goffi@goffi.org>
parents: 505
diff changeset
1066
d78728d7fd6a plugin wid calls, core: implements WebRTC DataChannel file transfer:
Goffi <goffi@goffi.org>
parents: 505
diff changeset
1067 await self.a_bridge.action_launch(
d78728d7fd6a plugin wid calls, core: implements WebRTC DataChannel file transfer:
Goffi <goffi@goffi.org>
parents: 505
diff changeset
1068 action_id, data_format.serialise(xmlui_data), profile_key=profile
d78728d7fd6a plugin wid calls, core: implements WebRTC DataChannel file transfer:
Goffi <goffi@goffi.org>
parents: 505
diff changeset
1069 )
d78728d7fd6a plugin wid calls, core: implements WebRTC DataChannel file transfer:
Goffi <goffi@goffi.org>
parents: 505
diff changeset
1070
d78728d7fd6a plugin wid calls, core: implements WebRTC DataChannel file transfer:
Goffi <goffi@goffi.org>
parents: 505
diff changeset
1071 def action_manager(
d78728d7fd6a plugin wid calls, core: implements WebRTC DataChannel file transfer:
Goffi <goffi@goffi.org>
parents: 505
diff changeset
1072 self,
d78728d7fd6a plugin wid calls, core: implements WebRTC DataChannel file transfer:
Goffi <goffi@goffi.org>
parents: 505
diff changeset
1073 action_data: dict,
d78728d7fd6a plugin wid calls, core: implements WebRTC DataChannel file transfer:
Goffi <goffi@goffi.org>
parents: 505
diff changeset
1074 callback: Callable|None = None,
d78728d7fd6a plugin wid calls, core: implements WebRTC DataChannel file transfer:
Goffi <goffi@goffi.org>
parents: 505
diff changeset
1075 ui_show_cb: Callable|None = None,
d78728d7fd6a plugin wid calls, core: implements WebRTC DataChannel file transfer:
Goffi <goffi@goffi.org>
parents: 505
diff changeset
1076 user_action: bool = True,
d78728d7fd6a plugin wid calls, core: implements WebRTC DataChannel file transfer:
Goffi <goffi@goffi.org>
parents: 505
diff changeset
1077 action_id: str|None = None,
d78728d7fd6a plugin wid calls, core: implements WebRTC DataChannel file transfer:
Goffi <goffi@goffi.org>
parents: 505
diff changeset
1078 progress_cb: Callable|None = None,
d78728d7fd6a plugin wid calls, core: implements WebRTC DataChannel file transfer:
Goffi <goffi@goffi.org>
parents: 505
diff changeset
1079 progress_eb: Callable|None = None,
d78728d7fd6a plugin wid calls, core: implements WebRTC DataChannel file transfer:
Goffi <goffi@goffi.org>
parents: 505
diff changeset
1080 profile: str = C.PROF_KEY_NONE
d78728d7fd6a plugin wid calls, core: implements WebRTC DataChannel file transfer:
Goffi <goffi@goffi.org>
parents: 505
diff changeset
1081 ) -> None:
d78728d7fd6a plugin wid calls, core: implements WebRTC DataChannel file transfer:
Goffi <goffi@goffi.org>
parents: 505
diff changeset
1082 if (
d78728d7fd6a plugin wid calls, core: implements WebRTC DataChannel file transfer:
Goffi <goffi@goffi.org>
parents: 505
diff changeset
1083 action_data.get("type") == C.META_TYPE_FILE
d78728d7fd6a plugin wid calls, core: implements WebRTC DataChannel file transfer:
Goffi <goffi@goffi.org>
parents: 505
diff changeset
1084 and action_data.get("webrtc", False)
d78728d7fd6a plugin wid calls, core: implements WebRTC DataChannel file transfer:
Goffi <goffi@goffi.org>
parents: 505
diff changeset
1085 ):
d78728d7fd6a plugin wid calls, core: implements WebRTC DataChannel file transfer:
Goffi <goffi@goffi.org>
parents: 505
diff changeset
1086 aio.run_async(self._on_webrtc_file(action_data, action_id, profile))
d78728d7fd6a plugin wid calls, core: implements WebRTC DataChannel file transfer:
Goffi <goffi@goffi.org>
parents: 505
diff changeset
1087 else:
d78728d7fd6a plugin wid calls, core: implements WebRTC DataChannel file transfer:
Goffi <goffi@goffi.org>
parents: 505
diff changeset
1088 super().action_manager(
d78728d7fd6a plugin wid calls, core: implements WebRTC DataChannel file transfer:
Goffi <goffi@goffi.org>
parents: 505
diff changeset
1089 action_data, callback, ui_show_cb, user_action, action_id, progress_cb,
d78728d7fd6a plugin wid calls, core: implements WebRTC DataChannel file transfer:
Goffi <goffi@goffi.org>
parents: 505
diff changeset
1090 progress_eb, profile
d78728d7fd6a plugin wid calls, core: implements WebRTC DataChannel file transfer:
Goffi <goffi@goffi.org>
parents: 505
diff changeset
1091 )
d78728d7fd6a plugin wid calls, core: implements WebRTC DataChannel file transfer:
Goffi <goffi@goffi.org>
parents: 505
diff changeset
1092
491
203755bbe0fe massive refactoring from camelCase -> snake_case. See backend commit log for more details
Goffi <goffi@goffi.org>
parents: 487
diff changeset
1093 def otr_state_handler(self, state, dest_jid, profile):
122
dcd6fbb3f010 chat: handle new OTR state signal and change encryption icon consequently
Goffi <goffi@goffi.org>
parents: 119
diff changeset
1094 """OTR state has changed for on destinee"""
dcd6fbb3f010 chat: handle new OTR state signal and change encryption icon consequently
Goffi <goffi@goffi.org>
parents: 119
diff changeset
1095 # XXX: this method could be in QuickApp but it's here as
493
b3cedbee561d refactoring: rename `cagou` to `libervia.desktop_kivy` + update imports and names following backend changes
Goffi <goffi@goffi.org>
parents: 491
diff changeset
1096 # it's only used by LiberviaDesktopKivy so far
244
5bd94bc08f5c plugin chat: fixed OTR State filtering + removed some legacy code
Goffi <goffi@goffi.org>
parents: 240
diff changeset
1097 dest_jid = jid.JID(dest_jid)
5bd94bc08f5c plugin chat: fixed OTR State filtering + removed some legacy code
Goffi <goffi@goffi.org>
parents: 240
diff changeset
1098 bare_jid = dest_jid.bare
491
203755bbe0fe massive refactoring from camelCase -> snake_case. See backend commit log for more details
Goffi <goffi@goffi.org>
parents: 487
diff changeset
1099 for widget in self.widgets.get_widgets(quick_chat.QuickChat, profiles=(profile,)):
244
5bd94bc08f5c plugin chat: fixed OTR State filtering + removed some legacy code
Goffi <goffi@goffi.org>
parents: 240
diff changeset
1100 if widget.type == C.CHAT_ONE2ONE and widget.target == bare_jid:
491
203755bbe0fe massive refactoring from camelCase -> snake_case. See backend commit log for more details
Goffi <goffi@goffi.org>
parents: 487
diff changeset
1101 widget.on_otr_state(state, dest_jid, profile)
122
dcd6fbb3f010 chat: handle new OTR state signal and change encryption icon consequently
Goffi <goffi@goffi.org>
parents: 119
diff changeset
1102
491
203755bbe0fe massive refactoring from camelCase -> snake_case. See backend commit log for more details
Goffi <goffi@goffi.org>
parents: 487
diff changeset
1103 def _debug_handler(self, action, parameters, profile):
312
772c170b47a9 Python3 port:
Goffi <goffi@goffi.org>
parents: 302
diff changeset
1104 if action == "visible_widgets_dump":
266
b3f97729e983 core (debug): added "visible_widgets_dump" action to new _debug signal
Goffi <goffi@goffi.org>
parents: 265
diff changeset
1105 from pprint import pformat
312
772c170b47a9 Python3 port:
Goffi <goffi@goffi.org>
parents: 302
diff changeset
1106 log.info("Visible widgets dump:\n{data}".format(
266
b3f97729e983 core (debug): added "visible_widgets_dump" action to new _debug signal
Goffi <goffi@goffi.org>
parents: 265
diff changeset
1107 data=pformat(self._visible_widgets)))
b3f97729e983 core (debug): added "visible_widgets_dump" action to new _debug signal
Goffi <goffi@goffi.org>
parents: 265
diff changeset
1108 else:
493
b3cedbee561d refactoring: rename `cagou` to `libervia.desktop_kivy` + update imports and names following backend changes
Goffi <goffi@goffi.org>
parents: 491
diff changeset
1109 return super(LiberviaDesktopKivy, self)._debug_handler(action, parameters, profile)
266
b3f97729e983 core (debug): added "visible_widgets_dump" action to new _debug signal
Goffi <goffi@goffi.org>
parents: 265
diff changeset
1110
491
203755bbe0fe massive refactoring from camelCase -> snake_case. See backend commit log for more details
Goffi <goffi@goffi.org>
parents: 487
diff changeset
1111 def connected_handler(self, jid_s, profile):
346
7b9a0e57df53 core: new "connected" property in CagouApp
Goffi <goffi@goffi.org>
parents: 342
diff changeset
1112 # FIXME: this won't work with multiple profiles
491
203755bbe0fe massive refactoring from camelCase -> snake_case. See backend commit log for more details
Goffi <goffi@goffi.org>
parents: 487
diff changeset
1113 super().connected_handler(jid_s, profile)
346
7b9a0e57df53 core: new "connected" property in CagouApp
Goffi <goffi@goffi.org>
parents: 342
diff changeset
1114 self.app.connected = True
7b9a0e57df53 core: new "connected" property in CagouApp
Goffi <goffi@goffi.org>
parents: 342
diff changeset
1115
491
203755bbe0fe massive refactoring from camelCase -> snake_case. See backend commit log for more details
Goffi <goffi@goffi.org>
parents: 487
diff changeset
1116 def disconnected_handler(self, profile):
346
7b9a0e57df53 core: new "connected" property in CagouApp
Goffi <goffi@goffi.org>
parents: 342
diff changeset
1117 # FIXME: this won't work with multiple profiles
491
203755bbe0fe massive refactoring from camelCase -> snake_case. See backend commit log for more details
Goffi <goffi@goffi.org>
parents: 487
diff changeset
1118 super().disconnected_handler(profile)
346
7b9a0e57df53 core: new "connected" property in CagouApp
Goffi <goffi@goffi.org>
parents: 342
diff changeset
1119 self.app.connected = False
7b9a0e57df53 core: new "connected" property in CagouApp
Goffi <goffi@goffi.org>
parents: 342
diff changeset
1120
29
8b5827c43155 notes first draft:
Goffi <goffi@goffi.org>
parents: 28
diff changeset
1121 ## misc ##
8b5827c43155 notes first draft:
Goffi <goffi@goffi.org>
parents: 28
diff changeset
1122
8b5827c43155 notes first draft:
Goffi <goffi@goffi.org>
parents: 28
diff changeset
1123 def plugging_profiles(self):
356
307c2501d8b2 chat: keep as many instances of opened chat as there are active WHWrapper, instead of just one:
Goffi <goffi@goffi.org>
parents: 353
diff changeset
1124 self.widgets_handler = widgets_handler.WidgetsHandler()
491
203755bbe0fe massive refactoring from camelCase -> snake_case. See backend commit log for more details
Goffi <goffi@goffi.org>
parents: 487
diff changeset
1125 self.app.root.change_widget(self.widgets_handler)
29
8b5827c43155 notes first draft:
Goffi <goffi@goffi.org>
parents: 28
diff changeset
1126
491
203755bbe0fe massive refactoring from camelCase -> snake_case. See backend commit log for more details
Goffi <goffi@goffi.org>
parents: 487
diff changeset
1127 def set_presence_status(self, show='', status=None, profile=C.PROF_KEY_NONE):
312
772c170b47a9 Python3 port:
Goffi <goffi@goffi.org>
parents: 302
diff changeset
1128 log.info("Profile presence status set to {show}/{status}".format(show=show,
220
24f8ab7c08be core: implemented showDialog so message/dialogs from QuickFrontend are displayed
Goffi <goffi@goffi.org>
parents: 208
diff changeset
1129 status=status))
29
8b5827c43155 notes first draft:
Goffi <goffi@goffi.org>
parents: 28
diff changeset
1130
220
24f8ab7c08be core: implemented showDialog so message/dialogs from QuickFrontend are displayed
Goffi <goffi@goffi.org>
parents: 208
diff changeset
1131 def errback(self, failure_, title=_('error'),
312
772c170b47a9 Python3 port:
Goffi <goffi@goffi.org>
parents: 302
diff changeset
1132 message=_('error while processing: {msg}')):
491
203755bbe0fe massive refactoring from camelCase -> snake_case. See backend commit log for more details
Goffi <goffi@goffi.org>
parents: 487
diff changeset
1133 self.add_note(title, message.format(msg=failure_), level=C.XMLUI_DATA_LVL_WARNING)
190
33ac2d2ce5d7 core: new errback method which can be use as a generic way to show error as notes
Goffi <goffi@goffi.org>
parents: 189
diff changeset
1134
491
203755bbe0fe massive refactoring from camelCase -> snake_case. See backend commit log for more details
Goffi <goffi@goffi.org>
parents: 487
diff changeset
1135 def add_note(self, title, message, level=C.XMLUI_DATA_LVL_INFO, symbol=None,
250
ff1efdeff53f core: notifs can now have a custom icon and be clickable:
Goffi <goffi@goffi.org>
parents: 249
diff changeset
1136 action=None):
29
8b5827c43155 notes first draft:
Goffi <goffi@goffi.org>
parents: 28
diff changeset
1137 """add a note (message which disappear) to root widget's header"""
491
203755bbe0fe massive refactoring from camelCase -> snake_case. See backend commit log for more details
Goffi <goffi@goffi.org>
parents: 487
diff changeset
1138 self.app.root.add_note(title, message, level, symbol, action)
29
8b5827c43155 notes first draft:
Goffi <goffi@goffi.org>
parents: 28
diff changeset
1139
491
203755bbe0fe massive refactoring from camelCase -> snake_case. See backend commit log for more details
Goffi <goffi@goffi.org>
parents: 487
diff changeset
1140 def add_notif_ui(self, ui):
33
c21d1be2e54c core: XMLUI notifications coming from backend are handled:
Goffi <goffi@goffi.org>
parents: 32
diff changeset
1141 """add a notification with a XMLUI attached
c21d1be2e54c core: XMLUI notifications coming from backend are handled:
Goffi <goffi@goffi.org>
parents: 32
diff changeset
1142
c21d1be2e54c core: XMLUI notifications coming from backend are handled:
Goffi <goffi@goffi.org>
parents: 32
diff changeset
1143 @param ui(xmlui.XMLUIPanel): XMLUI instance to show when notification is selected
c21d1be2e54c core: XMLUI notifications coming from backend are handled:
Goffi <goffi@goffi.org>
parents: 32
diff changeset
1144 """
491
203755bbe0fe massive refactoring from camelCase -> snake_case. See backend commit log for more details
Goffi <goffi@goffi.org>
parents: 487
diff changeset
1145 self.app.root.add_notif_ui(ui)
29
8b5827c43155 notes first draft:
Goffi <goffi@goffi.org>
parents: 28
diff changeset
1146
491
203755bbe0fe massive refactoring from camelCase -> snake_case. See backend commit log for more details
Goffi <goffi@goffi.org>
parents: 487
diff changeset
1147 def add_notif_widget(self, widget):
220
24f8ab7c08be core: implemented showDialog so message/dialogs from QuickFrontend are displayed
Goffi <goffi@goffi.org>
parents: 208
diff changeset
1148 """add a notification with a Kivy widget attached
24f8ab7c08be core: implemented showDialog so message/dialogs from QuickFrontend are displayed
Goffi <goffi@goffi.org>
parents: 208
diff changeset
1149
24f8ab7c08be core: implemented showDialog so message/dialogs from QuickFrontend are displayed
Goffi <goffi@goffi.org>
parents: 208
diff changeset
1150 @param widget(kivy.uix.Widget): widget to attach to notification
24f8ab7c08be core: implemented showDialog so message/dialogs from QuickFrontend are displayed
Goffi <goffi@goffi.org>
parents: 208
diff changeset
1151 """
491
203755bbe0fe massive refactoring from camelCase -> snake_case. See backend commit log for more details
Goffi <goffi@goffi.org>
parents: 487
diff changeset
1152 self.app.root.add_notif_widget(widget)
220
24f8ab7c08be core: implemented showDialog so message/dialogs from QuickFrontend are displayed
Goffi <goffi@goffi.org>
parents: 208
diff changeset
1153
505
bbef1a413515 core (main): add methods to deleted notifications:
Goffi <goffi@goffi.org>
parents: 498
diff changeset
1154 def del_notif_widget(self, widget):
bbef1a413515 core (main): add methods to deleted notifications:
Goffi <goffi@goffi.org>
parents: 498
diff changeset
1155 """del a notification with a Kivy widget attached
bbef1a413515 core (main): add methods to deleted notifications:
Goffi <goffi@goffi.org>
parents: 498
diff changeset
1156
bbef1a413515 core (main): add methods to deleted notifications:
Goffi <goffi@goffi.org>
parents: 498
diff changeset
1157 @param widget(kivy.uix.Widget): widget to attach to notification
bbef1a413515 core (main): add methods to deleted notifications:
Goffi <goffi@goffi.org>
parents: 498
diff changeset
1158 """
bbef1a413515 core (main): add methods to deleted notifications:
Goffi <goffi@goffi.org>
parents: 498
diff changeset
1159 if self.selected_widget == widget:
bbef1a413515 core (main): add methods to deleted notifications:
Goffi <goffi@goffi.org>
parents: 498
diff changeset
1160 self.close_ui()
bbef1a413515 core (main): add methods to deleted notifications:
Goffi <goffi@goffi.org>
parents: 498
diff changeset
1161 else:
bbef1a413515 core (main): add methods to deleted notifications:
Goffi <goffi@goffi.org>
parents: 498
diff changeset
1162 self.app.root.del_notif_widget(widget)
bbef1a413515 core (main): add methods to deleted notifications:
Goffi <goffi@goffi.org>
parents: 498
diff changeset
1163
491
203755bbe0fe massive refactoring from camelCase -> snake_case. See backend commit log for more details
Goffi <goffi@goffi.org>
parents: 487
diff changeset
1164 def show_ui(self, ui):
78
46d962910801 chat: file upload first draft:
Goffi <goffi@goffi.org>
parents: 77
diff changeset
1165 """show a XMLUI"""
491
203755bbe0fe massive refactoring from camelCase -> snake_case. See backend commit log for more details
Goffi <goffi@goffi.org>
parents: 487
diff changeset
1166 self.app.root.change_widget(ui, "xmlui")
33
c21d1be2e54c core: XMLUI notifications coming from backend are handled:
Goffi <goffi@goffi.org>
parents: 32
diff changeset
1167 self.app.root.show("xmlui")
360
a77386b73e55 core: change selected_widget when root screen widget is changed
Goffi <goffi@goffi.org>
parents: 358
diff changeset
1168 self._selected_widget_main = self.selected_widget
a77386b73e55 core: change selected_widget when root screen widget is changed
Goffi <goffi@goffi.org>
parents: 358
diff changeset
1169 self.selected_widget = ui
33
c21d1be2e54c core: XMLUI notifications coming from backend are handled:
Goffi <goffi@goffi.org>
parents: 32
diff changeset
1170
491
203755bbe0fe massive refactoring from camelCase -> snake_case. See backend commit log for more details
Goffi <goffi@goffi.org>
parents: 487
diff changeset
1171 def show_extra_ui(self, widget):
78
46d962910801 chat: file upload first draft:
Goffi <goffi@goffi.org>
parents: 77
diff changeset
1172 """show any extra widget"""
491
203755bbe0fe massive refactoring from camelCase -> snake_case. See backend commit log for more details
Goffi <goffi@goffi.org>
parents: 487
diff changeset
1173 self.app.root.change_widget(widget, "extra")
78
46d962910801 chat: file upload first draft:
Goffi <goffi@goffi.org>
parents: 77
diff changeset
1174 self.app.root.show("extra")
360
a77386b73e55 core: change selected_widget when root screen widget is changed
Goffi <goffi@goffi.org>
parents: 358
diff changeset
1175 self._selected_widget_main = self.selected_widget
a77386b73e55 core: change selected_widget when root screen widget is changed
Goffi <goffi@goffi.org>
parents: 358
diff changeset
1176 self.selected_widget = widget
78
46d962910801 chat: file upload first draft:
Goffi <goffi@goffi.org>
parents: 77
diff changeset
1177
491
203755bbe0fe massive refactoring from camelCase -> snake_case. See backend commit log for more details
Goffi <goffi@goffi.org>
parents: 487
diff changeset
1178 def close_ui(self):
505
bbef1a413515 core (main): add methods to deleted notifications:
Goffi <goffi@goffi.org>
parents: 498
diff changeset
1179 """Close current UI in extra screen"""
33
c21d1be2e54c core: XMLUI notifications coming from backend are handled:
Goffi <goffi@goffi.org>
parents: 32
diff changeset
1180 self.app.root.show()
360
a77386b73e55 core: change selected_widget when root screen widget is changed
Goffi <goffi@goffi.org>
parents: 358
diff changeset
1181 self.selected_widget = self._selected_widget_main
a77386b73e55 core: change selected_widget when root screen widget is changed
Goffi <goffi@goffi.org>
parents: 358
diff changeset
1182 self._selected_widget_main = None
322
e2b51663d8b8 core, android: new share widget + added Cagou to "share" menu:
Goffi <goffi@goffi.org>
parents: 318
diff changeset
1183 screen = self.app.root._manager.get_screen("extra")
e2b51663d8b8 core, android: new share widget + added Cagou to "share" menu:
Goffi <goffi@goffi.org>
parents: 318
diff changeset
1184 screen.clear_widgets()
44
7819e9efa250 chat: avatar and nick are now displayed, need further aesthetic improvments
Goffi <goffi@goffi.org>
parents: 43
diff changeset
1185
491
203755bbe0fe massive refactoring from camelCase -> snake_case. See backend commit log for more details
Goffi <goffi@goffi.org>
parents: 487
diff changeset
1186 def get_default_avatar(self, entity=None):
44
7819e9efa250 chat: avatar and nick are now displayed, need further aesthetic improvments
Goffi <goffi@goffi.org>
parents: 43
diff changeset
1187 return self.app.default_avatar
61
0b7f10de416e android: android build first draft:
Goffi <goffi@goffi.org>
parents: 60
diff changeset
1188
220
24f8ab7c08be core: implemented showDialog so message/dialogs from QuickFrontend are displayed
Goffi <goffi@goffi.org>
parents: 208
diff changeset
1189 def _dialog_cb(self, cb, *args, **kwargs):
24f8ab7c08be core: implemented showDialog so message/dialogs from QuickFrontend are displayed
Goffi <goffi@goffi.org>
parents: 208
diff changeset
1190 """generic dialog callback
24f8ab7c08be core: implemented showDialog so message/dialogs from QuickFrontend are displayed
Goffi <goffi@goffi.org>
parents: 208
diff changeset
1191
24f8ab7c08be core: implemented showDialog so message/dialogs from QuickFrontend are displayed
Goffi <goffi@goffi.org>
parents: 208
diff changeset
1192 close dialog then call the callback with given arguments
24f8ab7c08be core: implemented showDialog so message/dialogs from QuickFrontend are displayed
Goffi <goffi@goffi.org>
parents: 208
diff changeset
1193 """
24f8ab7c08be core: implemented showDialog so message/dialogs from QuickFrontend are displayed
Goffi <goffi@goffi.org>
parents: 208
diff changeset
1194 def callback():
491
203755bbe0fe massive refactoring from camelCase -> snake_case. See backend commit log for more details
Goffi <goffi@goffi.org>
parents: 487
diff changeset
1195 self.close_ui()
220
24f8ab7c08be core: implemented showDialog so message/dialogs from QuickFrontend are displayed
Goffi <goffi@goffi.org>
parents: 208
diff changeset
1196 cb(*args, **kwargs)
24f8ab7c08be core: implemented showDialog so message/dialogs from QuickFrontend are displayed
Goffi <goffi@goffi.org>
parents: 208
diff changeset
1197 return callback
24f8ab7c08be core: implemented showDialog so message/dialogs from QuickFrontend are displayed
Goffi <goffi@goffi.org>
parents: 208
diff changeset
1198
514
d78728d7fd6a plugin wid calls, core: implements WebRTC DataChannel file transfer:
Goffi <goffi@goffi.org>
parents: 505
diff changeset
1199 def show_dialog(
d78728d7fd6a plugin wid calls, core: implements WebRTC DataChannel file transfer:
Goffi <goffi@goffi.org>
parents: 505
diff changeset
1200 self,
d78728d7fd6a plugin wid calls, core: implements WebRTC DataChannel file transfer:
Goffi <goffi@goffi.org>
parents: 505
diff changeset
1201 message: str,
d78728d7fd6a plugin wid calls, core: implements WebRTC DataChannel file transfer:
Goffi <goffi@goffi.org>
parents: 505
diff changeset
1202 title: str,
d78728d7fd6a plugin wid calls, core: implements WebRTC DataChannel file transfer:
Goffi <goffi@goffi.org>
parents: 505
diff changeset
1203 type: str = "info",
d78728d7fd6a plugin wid calls, core: implements WebRTC DataChannel file transfer:
Goffi <goffi@goffi.org>
parents: 505
diff changeset
1204 answer_cb: Callable|None = None,
d78728d7fd6a plugin wid calls, core: implements WebRTC DataChannel file transfer:
Goffi <goffi@goffi.org>
parents: 505
diff changeset
1205 answer_data: dict|None = None
d78728d7fd6a plugin wid calls, core: implements WebRTC DataChannel file transfer:
Goffi <goffi@goffi.org>
parents: 505
diff changeset
1206 ):
d78728d7fd6a plugin wid calls, core: implements WebRTC DataChannel file transfer:
Goffi <goffi@goffi.org>
parents: 505
diff changeset
1207 """Show a dialog to the user.
d78728d7fd6a plugin wid calls, core: implements WebRTC DataChannel file transfer:
Goffi <goffi@goffi.org>
parents: 505
diff changeset
1208
d78728d7fd6a plugin wid calls, core: implements WebRTC DataChannel file transfer:
Goffi <goffi@goffi.org>
parents: 505
diff changeset
1209 @param message: The main text of the dialog.
d78728d7fd6a plugin wid calls, core: implements WebRTC DataChannel file transfer:
Goffi <goffi@goffi.org>
parents: 505
diff changeset
1210 @param title: Title of the dialog.
d78728d7fd6a plugin wid calls, core: implements WebRTC DataChannel file transfer:
Goffi <goffi@goffi.org>
parents: 505
diff changeset
1211 @param type: Type of dialog (info, warning, error, yes/no).
d78728d7fd6a plugin wid calls, core: implements WebRTC DataChannel file transfer:
Goffi <goffi@goffi.org>
parents: 505
diff changeset
1212 @param answer_cb: A callback that will be called when the user answers to the dialog.
d78728d7fd6a plugin wid calls, core: implements WebRTC DataChannel file transfer:
Goffi <goffi@goffi.org>
parents: 505
diff changeset
1213 You can pass an asynchronous function as well.
d78728d7fd6a plugin wid calls, core: implements WebRTC DataChannel file transfer:
Goffi <goffi@goffi.org>
parents: 505
diff changeset
1214 @param answer_data: Additional data for the dialog.
d78728d7fd6a plugin wid calls, core: implements WebRTC DataChannel file transfer:
Goffi <goffi@goffi.org>
parents: 505
diff changeset
1215
d78728d7fd6a plugin wid calls, core: implements WebRTC DataChannel file transfer:
Goffi <goffi@goffi.org>
parents: 505
diff changeset
1216 """
220
24f8ab7c08be core: implemented showDialog so message/dialogs from QuickFrontend are displayed
Goffi <goffi@goffi.org>
parents: 208
diff changeset
1217 if type in ('info', 'warning', 'error'):
491
203755bbe0fe massive refactoring from camelCase -> snake_case. See backend commit log for more details
Goffi <goffi@goffi.org>
parents: 487
diff changeset
1218 self.add_note(title, message, type)
220
24f8ab7c08be core: implemented showDialog so message/dialogs from QuickFrontend are displayed
Goffi <goffi@goffi.org>
parents: 208
diff changeset
1219 elif type == "yes/no":
24f8ab7c08be core: implemented showDialog so message/dialogs from QuickFrontend are displayed
Goffi <goffi@goffi.org>
parents: 208
diff changeset
1220 wid = dialog.ConfirmDialog(title=title, message=message,
24f8ab7c08be core: implemented showDialog so message/dialogs from QuickFrontend are displayed
Goffi <goffi@goffi.org>
parents: 208
diff changeset
1221 yes_cb=self._dialog_cb(answer_cb,
24f8ab7c08be core: implemented showDialog so message/dialogs from QuickFrontend are displayed
Goffi <goffi@goffi.org>
parents: 208
diff changeset
1222 True,
24f8ab7c08be core: implemented showDialog so message/dialogs from QuickFrontend are displayed
Goffi <goffi@goffi.org>
parents: 208
diff changeset
1223 answer_data),
24f8ab7c08be core: implemented showDialog so message/dialogs from QuickFrontend are displayed
Goffi <goffi@goffi.org>
parents: 208
diff changeset
1224 no_cb=self._dialog_cb(answer_cb,
24f8ab7c08be core: implemented showDialog so message/dialogs from QuickFrontend are displayed
Goffi <goffi@goffi.org>
parents: 208
diff changeset
1225 False,
24f8ab7c08be core: implemented showDialog so message/dialogs from QuickFrontend are displayed
Goffi <goffi@goffi.org>
parents: 208
diff changeset
1226 answer_data)
24f8ab7c08be core: implemented showDialog so message/dialogs from QuickFrontend are displayed
Goffi <goffi@goffi.org>
parents: 208
diff changeset
1227 )
491
203755bbe0fe massive refactoring from camelCase -> snake_case. See backend commit log for more details
Goffi <goffi@goffi.org>
parents: 487
diff changeset
1228 self.add_notif_widget(wid)
505
bbef1a413515 core (main): add methods to deleted notifications:
Goffi <goffi@goffi.org>
parents: 498
diff changeset
1229 return wid
220
24f8ab7c08be core: implemented showDialog so message/dialogs from QuickFrontend are displayed
Goffi <goffi@goffi.org>
parents: 208
diff changeset
1230 else:
312
772c170b47a9 Python3 port:
Goffi <goffi@goffi.org>
parents: 302
diff changeset
1231 log.warning(_("unknown dialog type: {dialog_type}").format(dialog_type=type))
184
c63922860f80 chat: show desktop notification and/or note when suitable
Goffi <goffi@goffi.org>
parents: 176
diff changeset
1232
514
d78728d7fd6a plugin wid calls, core: implements WebRTC DataChannel file transfer:
Goffi <goffi@goffi.org>
parents: 505
diff changeset
1233 async def a_show_dialog(
d78728d7fd6a plugin wid calls, core: implements WebRTC DataChannel file transfer:
Goffi <goffi@goffi.org>
parents: 505
diff changeset
1234 self,
d78728d7fd6a plugin wid calls, core: implements WebRTC DataChannel file transfer:
Goffi <goffi@goffi.org>
parents: 505
diff changeset
1235 message: str,
d78728d7fd6a plugin wid calls, core: implements WebRTC DataChannel file transfer:
Goffi <goffi@goffi.org>
parents: 505
diff changeset
1236 title: str,
d78728d7fd6a plugin wid calls, core: implements WebRTC DataChannel file transfer:
Goffi <goffi@goffi.org>
parents: 505
diff changeset
1237 type: str = "info",
d78728d7fd6a plugin wid calls, core: implements WebRTC DataChannel file transfer:
Goffi <goffi@goffi.org>
parents: 505
diff changeset
1238 answer_data: dict|None = None
d78728d7fd6a plugin wid calls, core: implements WebRTC DataChannel file transfer:
Goffi <goffi@goffi.org>
parents: 505
diff changeset
1239 ) -> bool|None:
d78728d7fd6a plugin wid calls, core: implements WebRTC DataChannel file transfer:
Goffi <goffi@goffi.org>
parents: 505
diff changeset
1240 """Shows a dialog asynchronously and returns the user's response for 'yes/no' dialogs.
d78728d7fd6a plugin wid calls, core: implements WebRTC DataChannel file transfer:
Goffi <goffi@goffi.org>
parents: 505
diff changeset
1241
d78728d7fd6a plugin wid calls, core: implements WebRTC DataChannel file transfer:
Goffi <goffi@goffi.org>
parents: 505
diff changeset
1242 This method wraps the synchronous ``show_dialog`` method to work in an
d78728d7fd6a plugin wid calls, core: implements WebRTC DataChannel file transfer:
Goffi <goffi@goffi.org>
parents: 505
diff changeset
1243 asynchronous context.
d78728d7fd6a plugin wid calls, core: implements WebRTC DataChannel file transfer:
Goffi <goffi@goffi.org>
parents: 505
diff changeset
1244 It is specifically useful for 'yes/no' type dialogs, returning True for 'yes' and
d78728d7fd6a plugin wid calls, core: implements WebRTC DataChannel file transfer:
Goffi <goffi@goffi.org>
parents: 505
diff changeset
1245 False for 'no'. For other types, it returns None immediately after showing the
d78728d7fd6a plugin wid calls, core: implements WebRTC DataChannel file transfer:
Goffi <goffi@goffi.org>
parents: 505
diff changeset
1246 dialog.
d78728d7fd6a plugin wid calls, core: implements WebRTC DataChannel file transfer:
Goffi <goffi@goffi.org>
parents: 505
diff changeset
1247
d78728d7fd6a plugin wid calls, core: implements WebRTC DataChannel file transfer:
Goffi <goffi@goffi.org>
parents: 505
diff changeset
1248 See [show_dialog] for params.
d78728d7fd6a plugin wid calls, core: implements WebRTC DataChannel file transfer:
Goffi <goffi@goffi.org>
parents: 505
diff changeset
1249 @return: True if the user clicked 'yes', False if 'no', and None for other dialog types.
d78728d7fd6a plugin wid calls, core: implements WebRTC DataChannel file transfer:
Goffi <goffi@goffi.org>
parents: 505
diff changeset
1250 """
d78728d7fd6a plugin wid calls, core: implements WebRTC DataChannel file transfer:
Goffi <goffi@goffi.org>
parents: 505
diff changeset
1251 future = asyncio.Future()
d78728d7fd6a plugin wid calls, core: implements WebRTC DataChannel file transfer:
Goffi <goffi@goffi.org>
parents: 505
diff changeset
1252
d78728d7fd6a plugin wid calls, core: implements WebRTC DataChannel file transfer:
Goffi <goffi@goffi.org>
parents: 505
diff changeset
1253 def answer_cb(answer: bool, data: dict):
d78728d7fd6a plugin wid calls, core: implements WebRTC DataChannel file transfer:
Goffi <goffi@goffi.org>
parents: 505
diff changeset
1254 if not future.done():
d78728d7fd6a plugin wid calls, core: implements WebRTC DataChannel file transfer:
Goffi <goffi@goffi.org>
parents: 505
diff changeset
1255 future.set_result(answer)
d78728d7fd6a plugin wid calls, core: implements WebRTC DataChannel file transfer:
Goffi <goffi@goffi.org>
parents: 505
diff changeset
1256
d78728d7fd6a plugin wid calls, core: implements WebRTC DataChannel file transfer:
Goffi <goffi@goffi.org>
parents: 505
diff changeset
1257 if type == "yes/no":
d78728d7fd6a plugin wid calls, core: implements WebRTC DataChannel file transfer:
Goffi <goffi@goffi.org>
parents: 505
diff changeset
1258 self.show_dialog(message, title, type, answer_cb, answer_data)
d78728d7fd6a plugin wid calls, core: implements WebRTC DataChannel file transfer:
Goffi <goffi@goffi.org>
parents: 505
diff changeset
1259 return await future
d78728d7fd6a plugin wid calls, core: implements WebRTC DataChannel file transfer:
Goffi <goffi@goffi.org>
parents: 505
diff changeset
1260 else:
d78728d7fd6a plugin wid calls, core: implements WebRTC DataChannel file transfer:
Goffi <goffi@goffi.org>
parents: 505
diff changeset
1261 self.show_dialog(message, title, type)
d78728d7fd6a plugin wid calls, core: implements WebRTC DataChannel file transfer:
Goffi <goffi@goffi.org>
parents: 505
diff changeset
1262 return None
d78728d7fd6a plugin wid calls, core: implements WebRTC DataChannel file transfer:
Goffi <goffi@goffi.org>
parents: 505
diff changeset
1263
d78728d7fd6a plugin wid calls, core: implements WebRTC DataChannel file transfer:
Goffi <goffi@goffi.org>
parents: 505
diff changeset
1264 async def ask_confirmation(
d78728d7fd6a plugin wid calls, core: implements WebRTC DataChannel file transfer:
Goffi <goffi@goffi.org>
parents: 505
diff changeset
1265 self,
d78728d7fd6a plugin wid calls, core: implements WebRTC DataChannel file transfer:
Goffi <goffi@goffi.org>
parents: 505
diff changeset
1266 message: str,
d78728d7fd6a plugin wid calls, core: implements WebRTC DataChannel file transfer:
Goffi <goffi@goffi.org>
parents: 505
diff changeset
1267 title: str,
d78728d7fd6a plugin wid calls, core: implements WebRTC DataChannel file transfer:
Goffi <goffi@goffi.org>
parents: 505
diff changeset
1268 answer_data: dict|None = None
d78728d7fd6a plugin wid calls, core: implements WebRTC DataChannel file transfer:
Goffi <goffi@goffi.org>
parents: 505
diff changeset
1269 ) -> bool:
d78728d7fd6a plugin wid calls, core: implements WebRTC DataChannel file transfer:
Goffi <goffi@goffi.org>
parents: 505
diff changeset
1270 ret = await self.a_show_dialog(message, title, "yes/no", answer_data)
d78728d7fd6a plugin wid calls, core: implements WebRTC DataChannel file transfer:
Goffi <goffi@goffi.org>
parents: 505
diff changeset
1271 assert ret is bool
d78728d7fd6a plugin wid calls, core: implements WebRTC DataChannel file transfer:
Goffi <goffi@goffi.org>
parents: 505
diff changeset
1272 return ret
d78728d7fd6a plugin wid calls, core: implements WebRTC DataChannel file transfer:
Goffi <goffi@goffi.org>
parents: 505
diff changeset
1273
322
e2b51663d8b8 core, android: new share widget + added Cagou to "share" menu:
Goffi <goffi@goffi.org>
parents: 318
diff changeset
1274 def share(self, media_type, data):
e2b51663d8b8 core, android: new share widget + added Cagou to "share" menu:
Goffi <goffi@goffi.org>
parents: 318
diff changeset
1275 share_wid = ShareWidget(media_type=media_type, data=data)
e2b51663d8b8 core, android: new share widget + added Cagou to "share" menu:
Goffi <goffi@goffi.org>
parents: 318
diff changeset
1276 try:
491
203755bbe0fe massive refactoring from camelCase -> snake_case. See backend commit log for more details
Goffi <goffi@goffi.org>
parents: 487
diff changeset
1277 self.show_extra_ui(share_wid)
322
e2b51663d8b8 core, android: new share widget + added Cagou to "share" menu:
Goffi <goffi@goffi.org>
parents: 318
diff changeset
1278 except Exception as e:
e2b51663d8b8 core, android: new share widget + added Cagou to "share" menu:
Goffi <goffi@goffi.org>
parents: 318
diff changeset
1279 log.error(e)
491
203755bbe0fe massive refactoring from camelCase -> snake_case. See backend commit log for more details
Goffi <goffi@goffi.org>
parents: 487
diff changeset
1280 self.close_ui()
184
c63922860f80 chat: show desktop notification and/or note when suitable
Goffi <goffi@goffi.org>
parents: 176
diff changeset
1281
491
203755bbe0fe massive refactoring from camelCase -> snake_case. See backend commit log for more details
Goffi <goffi@goffi.org>
parents: 487
diff changeset
1282 def download_url(
420
83d184393fe1 core: downloadURL helper method
Goffi <goffi@goffi.org>
parents: 419
diff changeset
1283 self, url, callback, errback=None, options=None, dest=C.FILE_DEST_DOWNLOAD,
83d184393fe1 core: downloadURL helper method
Goffi <goffi@goffi.org>
parents: 419
diff changeset
1284 profile=C.PROF_KEY_NONE):
83d184393fe1 core: downloadURL helper method
Goffi <goffi@goffi.org>
parents: 419
diff changeset
1285 """Download an URL (decrypt it if necessary)
83d184393fe1 core: downloadURL helper method
Goffi <goffi@goffi.org>
parents: 419
diff changeset
1286
83d184393fe1 core: downloadURL helper method
Goffi <goffi@goffi.org>
parents: 419
diff changeset
1287 @param url(str, parse.SplitResult): url to download
83d184393fe1 core: downloadURL helper method
Goffi <goffi@goffi.org>
parents: 419
diff changeset
1288 @param callback(callable): method to call when download is complete
83d184393fe1 core: downloadURL helper method
Goffi <goffi@goffi.org>
parents: 419
diff changeset
1289 @param errback(callable, None): method to call in case of error
83d184393fe1 core: downloadURL helper method
Goffi <goffi@goffi.org>
parents: 419
diff changeset
1290 if None, default errback will be called
83d184393fe1 core: downloadURL helper method
Goffi <goffi@goffi.org>
parents: 419
diff changeset
1291 @param dest(str): where the file should be downloaded:
83d184393fe1 core: downloadURL helper method
Goffi <goffi@goffi.org>
parents: 419
diff changeset
1292 - C.FILE_DEST_DOWNLOAD: in platform download directory
83d184393fe1 core: downloadURL helper method
Goffi <goffi@goffi.org>
parents: 419
diff changeset
1293 - C.FILE_DEST_CACHE: in SàT cache
491
203755bbe0fe massive refactoring from camelCase -> snake_case. See backend commit log for more details
Goffi <goffi@goffi.org>
parents: 487
diff changeset
1294 @param options(dict, None): options to pass to bridge.file_download_complete
420
83d184393fe1 core: downloadURL helper method
Goffi <goffi@goffi.org>
parents: 419
diff changeset
1295 """
83d184393fe1 core: downloadURL helper method
Goffi <goffi@goffi.org>
parents: 419
diff changeset
1296 if not isinstance(url, urlparse.ParseResult):
83d184393fe1 core: downloadURL helper method
Goffi <goffi@goffi.org>
parents: 419
diff changeset
1297 url = urlparse.urlparse(url)
83d184393fe1 core: downloadURL helper method
Goffi <goffi@goffi.org>
parents: 419
diff changeset
1298 if errback is None:
83d184393fe1 core: downloadURL helper method
Goffi <goffi@goffi.org>
parents: 419
diff changeset
1299 errback = partial(
83d184393fe1 core: downloadURL helper method
Goffi <goffi@goffi.org>
parents: 419
diff changeset
1300 self.errback,
83d184393fe1 core: downloadURL helper method
Goffi <goffi@goffi.org>
parents: 419
diff changeset
1301 title=_("Download error"),
83d184393fe1 core: downloadURL helper method
Goffi <goffi@goffi.org>
parents: 419
diff changeset
1302 message=_("Error while downloading {url}: {{msg}}").format(url=url.geturl()))
83d184393fe1 core: downloadURL helper method
Goffi <goffi@goffi.org>
parents: 419
diff changeset
1303 name = Path(url.path).name.strip() or C.FILE_DEFAULT_NAME
83d184393fe1 core: downloadURL helper method
Goffi <goffi@goffi.org>
parents: 419
diff changeset
1304 log.info(f"downloading/decrypting file {name!r}")
83d184393fe1 core: downloadURL helper method
Goffi <goffi@goffi.org>
parents: 419
diff changeset
1305 if dest == C.FILE_DEST_DOWNLOAD:
83d184393fe1 core: downloadURL helper method
Goffi <goffi@goffi.org>
parents: 419
diff changeset
1306 dest_path = files_utils.get_unique_name(Path(self.downloads_dir)/name)
83d184393fe1 core: downloadURL helper method
Goffi <goffi@goffi.org>
parents: 419
diff changeset
1307 elif dest == C.FILE_DEST_CACHE:
83d184393fe1 core: downloadURL helper method
Goffi <goffi@goffi.org>
parents: 419
diff changeset
1308 dest_path = ''
83d184393fe1 core: downloadURL helper method
Goffi <goffi@goffi.org>
parents: 419
diff changeset
1309 else:
83d184393fe1 core: downloadURL helper method
Goffi <goffi@goffi.org>
parents: 419
diff changeset
1310 raise exceptions.InternalError(f"Invalid dest_path: {dest_path!r}")
491
203755bbe0fe massive refactoring from camelCase -> snake_case. See backend commit log for more details
Goffi <goffi@goffi.org>
parents: 487
diff changeset
1311 self.bridge.file_download_complete(
486
f826ebb7f605 code: update `fileDownloadComplete` bridge call, following backend change
Goffi <goffi@goffi.org>
parents: 463
diff changeset
1312 data_format.serialise({"uri": url.geturl()}),
420
83d184393fe1 core: downloadURL helper method
Goffi <goffi@goffi.org>
parents: 419
diff changeset
1313 str(dest_path),
83d184393fe1 core: downloadURL helper method
Goffi <goffi@goffi.org>
parents: 419
diff changeset
1314 '' if not options else data_format.serialise(options),
83d184393fe1 core: downloadURL helper method
Goffi <goffi@goffi.org>
parents: 419
diff changeset
1315 profile,
83d184393fe1 core: downloadURL helper method
Goffi <goffi@goffi.org>
parents: 419
diff changeset
1316 callback=callback,
83d184393fe1 core: downloadURL helper method
Goffi <goffi@goffi.org>
parents: 419
diff changeset
1317 errback=errback
83d184393fe1 core: downloadURL helper method
Goffi <goffi@goffi.org>
parents: 419
diff changeset
1318 )
83d184393fe1 core: downloadURL helper method
Goffi <goffi@goffi.org>
parents: 419
diff changeset
1319
396
ae6f7fd1cb0e chat: use QuickApp.notify and clear notifications when selected.
Goffi <goffi@goffi.org>
parents: 388
diff changeset
1320 def notify(self, type_, entity=None, message=None, subject=None, callback=None,
ae6f7fd1cb0e chat: use QuickApp.notify and clear notifications when selected.
Goffi <goffi@goffi.org>
parents: 388
diff changeset
1321 cb_args=None, widget=None, profile=C.PROF_KEY_NONE):
ae6f7fd1cb0e chat: use QuickApp.notify and clear notifications when selected.
Goffi <goffi@goffi.org>
parents: 388
diff changeset
1322 super().notify(
ae6f7fd1cb0e chat: use QuickApp.notify and clear notifications when selected.
Goffi <goffi@goffi.org>
parents: 388
diff changeset
1323 type_=type_, entity=entity, message=message, subject=subject,
ae6f7fd1cb0e chat: use QuickApp.notify and clear notifications when selected.
Goffi <goffi@goffi.org>
parents: 388
diff changeset
1324 callback=callback, cb_args=cb_args, widget=widget, profile=profile)
ae6f7fd1cb0e chat: use QuickApp.notify and clear notifications when selected.
Goffi <goffi@goffi.org>
parents: 388
diff changeset
1325 self.desktop_notif(message, title=subject)
ae6f7fd1cb0e chat: use QuickApp.notify and clear notifications when selected.
Goffi <goffi@goffi.org>
parents: 388
diff changeset
1326
419
b047d14e4be5 notifs: fixed desktop notification duration
Goffi <goffi@goffi.org>
parents: 414
diff changeset
1327 def desktop_notif(self, message, title='', duration=5):
312
772c170b47a9 Python3 port:
Goffi <goffi@goffi.org>
parents: 302
diff changeset
1328 global notification
184
c63922860f80 chat: show desktop notification and/or note when suitable
Goffi <goffi@goffi.org>
parents: 176
diff changeset
1329 if notification is not None:
229
ab523cc967bb core(notification): display a warning and disable notifications if something is going wrong
Goffi <goffi@goffi.org>
parents: 228
diff changeset
1330 try:
396
ae6f7fd1cb0e chat: use QuickApp.notify and clear notifications when selected.
Goffi <goffi@goffi.org>
parents: 388
diff changeset
1331 log.debug(
ae6f7fd1cb0e chat: use QuickApp.notify and clear notifications when selected.
Goffi <goffi@goffi.org>
parents: 388
diff changeset
1332 f"sending desktop notification (duration: {duration}):\n"
ae6f7fd1cb0e chat: use QuickApp.notify and clear notifications when selected.
Goffi <goffi@goffi.org>
parents: 388
diff changeset
1333 f"{title}\n"
ae6f7fd1cb0e chat: use QuickApp.notify and clear notifications when selected.
Goffi <goffi@goffi.org>
parents: 388
diff changeset
1334 f"{message}"
ae6f7fd1cb0e chat: use QuickApp.notify and clear notifications when selected.
Goffi <goffi@goffi.org>
parents: 388
diff changeset
1335 )
229
ab523cc967bb core(notification): display a warning and disable notifications if something is going wrong
Goffi <goffi@goffi.org>
parents: 228
diff changeset
1336 notification.notify(title=title,
ab523cc967bb core(notification): display a warning and disable notifications if something is going wrong
Goffi <goffi@goffi.org>
parents: 228
diff changeset
1337 message=message,
ab523cc967bb core(notification): display a warning and disable notifications if something is going wrong
Goffi <goffi@goffi.org>
parents: 228
diff changeset
1338 app_name=C.APP_NAME,
ab523cc967bb core(notification): display a warning and disable notifications if something is going wrong
Goffi <goffi@goffi.org>
parents: 228
diff changeset
1339 app_icon=self.app.icon,
396
ae6f7fd1cb0e chat: use QuickApp.notify and clear notifications when selected.
Goffi <goffi@goffi.org>
parents: 388
diff changeset
1340 timeout=duration)
229
ab523cc967bb core(notification): display a warning and disable notifications if something is going wrong
Goffi <goffi@goffi.org>
parents: 228
diff changeset
1341 except Exception as e:
312
772c170b47a9 Python3 port:
Goffi <goffi@goffi.org>
parents: 302
diff changeset
1342 log.warning(_("Can't use notifications, disabling: {msg}").format(
229
ab523cc967bb core(notification): display a warning and disable notifications if something is going wrong
Goffi <goffi@goffi.org>
parents: 228
diff changeset
1343 msg = e))
ab523cc967bb core(notification): display a warning and disable notifications if something is going wrong
Goffi <goffi@goffi.org>
parents: 228
diff changeset
1344 notification = None
322
e2b51663d8b8 core, android: new share widget + added Cagou to "share" menu:
Goffi <goffi@goffi.org>
parents: 318
diff changeset
1345
491
203755bbe0fe massive refactoring from camelCase -> snake_case. See backend commit log for more details
Goffi <goffi@goffi.org>
parents: 487
diff changeset
1346 def get_parent_wh_wrapper(self, wid):
353
19422bbd9c8e core (widgets handler): refactoring:
Goffi <goffi@goffi.org>
parents: 352
diff changeset
1347 """Retrieve parent WHWrapper instance managing a widget
19422bbd9c8e core (widgets handler): refactoring:
Goffi <goffi@goffi.org>
parents: 352
diff changeset
1348
19422bbd9c8e core (widgets handler): refactoring:
Goffi <goffi@goffi.org>
parents: 352
diff changeset
1349 @param wid(Widget): widget to check
19422bbd9c8e core (widgets handler): refactoring:
Goffi <goffi@goffi.org>
parents: 352
diff changeset
1350 @return (WHWrapper, None): found instance if any, else None
19422bbd9c8e core (widgets handler): refactoring:
Goffi <goffi@goffi.org>
parents: 352
diff changeset
1351 """
491
203755bbe0fe massive refactoring from camelCase -> snake_case. See backend commit log for more details
Goffi <goffi@goffi.org>
parents: 487
diff changeset
1352 wh = self.get_ancestor_widget(wid, widgets_handler.WHWrapper)
353
19422bbd9c8e core (widgets handler): refactoring:
Goffi <goffi@goffi.org>
parents: 352
diff changeset
1353 if wh is None:
19422bbd9c8e core (widgets handler): refactoring:
Goffi <goffi@goffi.org>
parents: 352
diff changeset
1354 # we may have a screen
19422bbd9c8e core (widgets handler): refactoring:
Goffi <goffi@goffi.org>
parents: 352
diff changeset
1355 try:
19422bbd9c8e core (widgets handler): refactoring:
Goffi <goffi@goffi.org>
parents: 352
diff changeset
1356 sm = wid.screen_manager
19422bbd9c8e core (widgets handler): refactoring:
Goffi <goffi@goffi.org>
parents: 352
diff changeset
1357 except (exceptions.InternalError, exceptions.NotFound):
19422bbd9c8e core (widgets handler): refactoring:
Goffi <goffi@goffi.org>
parents: 352
diff changeset
1358 return None
19422bbd9c8e core (widgets handler): refactoring:
Goffi <goffi@goffi.org>
parents: 352
diff changeset
1359 else:
491
203755bbe0fe massive refactoring from camelCase -> snake_case. See backend commit log for more details
Goffi <goffi@goffi.org>
parents: 487
diff changeset
1360 wh = self.get_ancestor_widget(sm, widgets_handler.WHWrapper)
353
19422bbd9c8e core (widgets handler): refactoring:
Goffi <goffi@goffi.org>
parents: 352
diff changeset
1361 return wh
19422bbd9c8e core (widgets handler): refactoring:
Goffi <goffi@goffi.org>
parents: 352
diff changeset
1362
491
203755bbe0fe massive refactoring from camelCase -> snake_case. See backend commit log for more details
Goffi <goffi@goffi.org>
parents: 487
diff changeset
1363 def get_ancestor_widget(self, wid, cls):
322
e2b51663d8b8 core, android: new share widget + added Cagou to "share" menu:
Goffi <goffi@goffi.org>
parents: 318
diff changeset
1364 """Retrieve an ancestor of given class
e2b51663d8b8 core, android: new share widget + added Cagou to "share" menu:
Goffi <goffi@goffi.org>
parents: 318
diff changeset
1365
e2b51663d8b8 core, android: new share widget + added Cagou to "share" menu:
Goffi <goffi@goffi.org>
parents: 318
diff changeset
1366 @param wid(Widget): current widget
e2b51663d8b8 core, android: new share widget + added Cagou to "share" menu:
Goffi <goffi@goffi.org>
parents: 318
diff changeset
1367 @param cls(type): class of the ancestor to retrieve
e2b51663d8b8 core, android: new share widget + added Cagou to "share" menu:
Goffi <goffi@goffi.org>
parents: 318
diff changeset
1368 @return (Widget, None): found instance or None
e2b51663d8b8 core, android: new share widget + added Cagou to "share" menu:
Goffi <goffi@goffi.org>
parents: 318
diff changeset
1369 """
e2b51663d8b8 core, android: new share widget + added Cagou to "share" menu:
Goffi <goffi@goffi.org>
parents: 318
diff changeset
1370 parent = wid.parent
331
d36040493434 core: fixed handling of classes with multiple inheritances in getAncestorWidget
Goffi <goffi@goffi.org>
parents: 323
diff changeset
1371 while parent and not isinstance(parent, cls):
322
e2b51663d8b8 core, android: new share widget + added Cagou to "share" menu:
Goffi <goffi@goffi.org>
parents: 318
diff changeset
1372 parent = parent.parent
e2b51663d8b8 core, android: new share widget + added Cagou to "share" menu:
Goffi <goffi@goffi.org>
parents: 318
diff changeset
1373 return parent