Mercurial > libervia-desktop-kivy
annotate cagou/plugins/plugin_wid_remote.py @ 378:4d660b252487
dates update
author | Goffi <goffi@goffi.org> |
---|---|
date | Wed, 29 Jan 2020 09:52:46 +0100 |
parents | 33244f944bd8 |
children | 1da3c379205b |
rev | line source |
---|---|
238
7918a5668304
plugin remote: remote controllers plugin first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
1 #!/usr/bin/env python2 |
7918a5668304
plugin remote: remote controllers plugin first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
2 # -*- coding: utf-8 -*- |
7918a5668304
plugin remote: remote controllers plugin first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
3 |
7918a5668304
plugin remote: remote controllers plugin first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
4 # Cagou: desktop/mobile frontend for Salut à Toi XMPP client |
378 | 5 # Copyright (C) 2016-2020 Jérôme Poisson (goffi@goffi.org) |
238
7918a5668304
plugin remote: remote controllers plugin first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
6 |
7918a5668304
plugin remote: remote controllers plugin first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
7 # This program is free software: you can redistribute it and/or modify |
7918a5668304
plugin remote: remote controllers plugin first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
8 # it under the terms of the GNU Affero General Public License as published by |
7918a5668304
plugin remote: remote controllers plugin first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
9 # the Free Software Foundation, either version 3 of the License, or |
7918a5668304
plugin remote: remote controllers plugin first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
10 # (at your option) any later version. |
7918a5668304
plugin remote: remote controllers plugin first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
11 |
7918a5668304
plugin remote: remote controllers plugin first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
12 # This program is distributed in the hope that it will be useful, |
7918a5668304
plugin remote: remote controllers plugin first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of |
7918a5668304
plugin remote: remote controllers plugin first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
7918a5668304
plugin remote: remote controllers plugin first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
15 # GNU Affero General Public License for more details. |
7918a5668304
plugin remote: remote controllers plugin first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
16 |
7918a5668304
plugin remote: remote controllers plugin first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
17 # You should have received a copy of the GNU Affero General Public License |
7918a5668304
plugin remote: remote controllers plugin first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
18 # along with this program. If not, see <http://www.gnu.org/licenses/>. |
7918a5668304
plugin remote: remote controllers plugin first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
19 |
7918a5668304
plugin remote: remote controllers plugin first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
20 |
7918a5668304
plugin remote: remote controllers plugin first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
21 from sat.core import log as logging |
7918a5668304
plugin remote: remote controllers plugin first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
22 from sat.core.i18n import _ |
7918a5668304
plugin remote: remote controllers plugin first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
23 from sat_frontends.quick_frontend import quick_widgets |
7918a5668304
plugin remote: remote controllers plugin first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
24 from cagou.core import cagou_widget |
7918a5668304
plugin remote: remote controllers plugin first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
25 from cagou.core.constants import Const as C |
7918a5668304
plugin remote: remote controllers plugin first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
26 from cagou.core.menu import TouchMenuBehaviour |
7918a5668304
plugin remote: remote controllers plugin first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
27 from cagou.core.utils import FilterBehavior |
7918a5668304
plugin remote: remote controllers plugin first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
28 from cagou.core.common_widgets import (Identities, ItemWidget, DeviceWidget, |
7918a5668304
plugin remote: remote controllers plugin first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
29 CategorySeparator) |
7918a5668304
plugin remote: remote controllers plugin first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
30 from sat.tools.common import template_xmlui |
7918a5668304
plugin remote: remote controllers plugin first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
31 from cagou.core import xmlui |
7918a5668304
plugin remote: remote controllers plugin first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
32 from sat_frontends.tools import jid |
7918a5668304
plugin remote: remote controllers plugin first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
33 from kivy import properties |
7918a5668304
plugin remote: remote controllers plugin first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
34 from kivy.uix.label import Label |
7918a5668304
plugin remote: remote controllers plugin first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
35 from kivy.uix.boxlayout import BoxLayout |
305
b2727877bad4
remote: fixed workflow and size for XMLUI panel used with Ad-Hoc commands:
Goffi <goffi@goffi.org>
parents:
282
diff
changeset
|
36 from kivy.uix.floatlayout import FloatLayout |
238
7918a5668304
plugin remote: remote controllers plugin first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
37 from cagou import G |
7918a5668304
plugin remote: remote controllers plugin first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
38 from functools import partial |
7918a5668304
plugin remote: remote controllers plugin first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
39 |
7918a5668304
plugin remote: remote controllers plugin first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
40 |
322
e2b51663d8b8
core, android: new share widget + added Cagou to "share" menu:
Goffi <goffi@goffi.org>
parents:
312
diff
changeset
|
41 log = logging.getLogger(__name__) |
e2b51663d8b8
core, android: new share widget + added Cagou to "share" menu:
Goffi <goffi@goffi.org>
parents:
312
diff
changeset
|
42 |
238
7918a5668304
plugin remote: remote controllers plugin first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
43 PLUGIN_INFO = { |
312 | 44 "name": _("remote control"), |
238
7918a5668304
plugin remote: remote controllers plugin first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
45 "main": "RemoteControl", |
312 | 46 "description": _("universal remote control"), |
47 "icon_symbol": "signal", | |
238
7918a5668304
plugin remote: remote controllers plugin first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
48 } |
7918a5668304
plugin remote: remote controllers plugin first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
49 |
312 | 50 NOTE_TITLE = _("Media Player Remote Control") |
238
7918a5668304
plugin remote: remote controllers plugin first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
51 |
7918a5668304
plugin remote: remote controllers plugin first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
52 |
7918a5668304
plugin remote: remote controllers plugin first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
53 class RemoteItemWidget(ItemWidget): |
7918a5668304
plugin remote: remote controllers plugin first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
54 |
7918a5668304
plugin remote: remote controllers plugin first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
55 def __init__(self, device_jid, node, name, main_wid, **kw): |
7918a5668304
plugin remote: remote controllers plugin first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
56 self.device_jid = device_jid |
7918a5668304
plugin remote: remote controllers plugin first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
57 self.node = node |
7918a5668304
plugin remote: remote controllers plugin first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
58 super(RemoteItemWidget, self).__init__(name=name, main_wid=main_wid, **kw) |
7918a5668304
plugin remote: remote controllers plugin first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
59 |
7918a5668304
plugin remote: remote controllers plugin first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
60 def do_item_action(self, touch): |
7918a5668304
plugin remote: remote controllers plugin first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
61 self.main_wid.layout.clear_widgets() |
7918a5668304
plugin remote: remote controllers plugin first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
62 player_wid = MediaPlayerControlWidget(main_wid=self.main_wid, remote_item=self) |
7918a5668304
plugin remote: remote controllers plugin first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
63 self.main_wid.layout.add_widget(player_wid) |
7918a5668304
plugin remote: remote controllers plugin first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
64 |
7918a5668304
plugin remote: remote controllers plugin first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
65 |
7918a5668304
plugin remote: remote controllers plugin first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
66 class MediaPlayerControlWidget(BoxLayout): |
7918a5668304
plugin remote: remote controllers plugin first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
67 main_wid = properties.ObjectProperty() |
7918a5668304
plugin remote: remote controllers plugin first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
68 remote_item = properties.ObjectProperty() |
312 | 69 status = properties.OptionProperty("play", options=("play", "pause", "stop")) |
238
7918a5668304
plugin remote: remote controllers plugin first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
70 title = properties.StringProperty() |
7918a5668304
plugin remote: remote controllers plugin first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
71 identity = properties.StringProperty() |
7918a5668304
plugin remote: remote controllers plugin first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
72 command = properties.DictProperty() |
7918a5668304
plugin remote: remote controllers plugin first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
73 ui_tpl = properties.ObjectProperty() |
7918a5668304
plugin remote: remote controllers plugin first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
74 |
7918a5668304
plugin remote: remote controllers plugin first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
75 @property |
7918a5668304
plugin remote: remote controllers plugin first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
76 def profile(self): |
7918a5668304
plugin remote: remote controllers plugin first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
77 return self.main_wid.profile |
7918a5668304
plugin remote: remote controllers plugin first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
78 |
7918a5668304
plugin remote: remote controllers plugin first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
79 def updateUI(self, action_data): |
7918a5668304
plugin remote: remote controllers plugin first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
80 xmlui_raw = action_data['xmlui'] |
7918a5668304
plugin remote: remote controllers plugin first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
81 ui_tpl = template_xmlui.create(G.host, xmlui_raw) |
7918a5668304
plugin remote: remote controllers plugin first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
82 self.ui_tpl = ui_tpl |
7918a5668304
plugin remote: remote controllers plugin first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
83 for prop in ('Title', 'Identity'): |
7918a5668304
plugin remote: remote controllers plugin first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
84 try: |
7918a5668304
plugin remote: remote controllers plugin first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
85 setattr(self, prop.lower(), ui_tpl.widgets[prop].value) |
7918a5668304
plugin remote: remote controllers plugin first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
86 except KeyError: |
312 | 87 log.warning(_("Missing field: {name}").format(name=prop)) |
238
7918a5668304
plugin remote: remote controllers plugin first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
88 playback_status = self.ui_tpl.widgets['PlaybackStatus'].value |
312 | 89 if playback_status == "Playing": |
90 self.status = "pause" | |
91 elif playback_status == "Paused": | |
92 self.status = "play" | |
93 elif playback_status == "Stopped": | |
94 self.status = "play" | |
238
7918a5668304
plugin remote: remote controllers plugin first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
95 else: |
7918a5668304
plugin remote: remote controllers plugin first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
96 G.host.addNote( |
7918a5668304
plugin remote: remote controllers plugin first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
97 title=NOTE_TITLE, |
312 | 98 message=_("Unknown playback status: playback_status") |
238
7918a5668304
plugin remote: remote controllers plugin first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
99 .format(playback_status=playback_status), |
7918a5668304
plugin remote: remote controllers plugin first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
100 level=C.XMLUI_DATA_LVL_WARNING) |
7918a5668304
plugin remote: remote controllers plugin first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
101 self.commands = {v:k for k,v in ui_tpl.widgets['command'].options} |
7918a5668304
plugin remote: remote controllers plugin first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
102 |
7918a5668304
plugin remote: remote controllers plugin first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
103 def adHocRunCb(self, xmlui_raw): |
7918a5668304
plugin remote: remote controllers plugin first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
104 ui_tpl = template_xmlui.create(G.host, xmlui_raw) |
312 | 105 data = {xmlui.XMLUIPanel.escape("media_player"): self.remote_item.node, |
106 "session_id": ui_tpl.session_id} | |
238
7918a5668304
plugin remote: remote controllers plugin first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
107 G.host.bridge.launchAction( |
7918a5668304
plugin remote: remote controllers plugin first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
108 ui_tpl.submit_id, data, self.profile, |
7918a5668304
plugin remote: remote controllers plugin first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
109 callback=self.updateUI, |
7918a5668304
plugin remote: remote controllers plugin first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
110 errback=self.main_wid.errback) |
7918a5668304
plugin remote: remote controllers plugin first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
111 |
7918a5668304
plugin remote: remote controllers plugin first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
112 def on_remote_item(self, __, remote): |
312 | 113 NS_MEDIA_PLAYER = G.host.ns_map["mediaplayer"] |
114 G.host.bridge.adHocRun(str(remote.device_jid), NS_MEDIA_PLAYER, self.profile, | |
238
7918a5668304
plugin remote: remote controllers plugin first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
115 callback=self.adHocRunCb, |
7918a5668304
plugin remote: remote controllers plugin first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
116 errback=self.main_wid.errback) |
7918a5668304
plugin remote: remote controllers plugin first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
117 |
7918a5668304
plugin remote: remote controllers plugin first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
118 def do_cmd(self, command): |
7918a5668304
plugin remote: remote controllers plugin first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
119 try: |
7918a5668304
plugin remote: remote controllers plugin first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
120 cmd_value = self.commands[command] |
7918a5668304
plugin remote: remote controllers plugin first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
121 except KeyError: |
7918a5668304
plugin remote: remote controllers plugin first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
122 G.host.addNote( |
7918a5668304
plugin remote: remote controllers plugin first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
123 title=NOTE_TITLE, |
312 | 124 message=_("{command} command is not managed").format(command=command), |
238
7918a5668304
plugin remote: remote controllers plugin first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
125 level=C.XMLUI_DATA_LVL_WARNING) |
7918a5668304
plugin remote: remote controllers plugin first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
126 else: |
312 | 127 data = {xmlui.XMLUIPanel.escape("command"): cmd_value, |
128 "session_id": self.ui_tpl.session_id} | |
238
7918a5668304
plugin remote: remote controllers plugin first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
129 # hidden values are normally transparently managed by XMLUIPanel |
7918a5668304
plugin remote: remote controllers plugin first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
130 # but here we have to add them by hand |
7918a5668304
plugin remote: remote controllers plugin first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
131 hidden = {xmlui.XMLUIPanel.escape(k):v |
312 | 132 for k,v in self.ui_tpl.hidden.items()} |
238
7918a5668304
plugin remote: remote controllers plugin first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
133 data.update(hidden) |
7918a5668304
plugin remote: remote controllers plugin first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
134 G.host.bridge.launchAction( |
7918a5668304
plugin remote: remote controllers plugin first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
135 self.ui_tpl.submit_id, data, self.profile, |
7918a5668304
plugin remote: remote controllers plugin first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
136 callback=self.updateUI, |
7918a5668304
plugin remote: remote controllers plugin first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
137 errback=self.main_wid.errback) |
7918a5668304
plugin remote: remote controllers plugin first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
138 |
7918a5668304
plugin remote: remote controllers plugin first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
139 |
7918a5668304
plugin remote: remote controllers plugin first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
140 class RemoteDeviceWidget(DeviceWidget): |
7918a5668304
plugin remote: remote controllers plugin first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
141 |
7918a5668304
plugin remote: remote controllers plugin first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
142 def xmluiCb(self, data, cb_id, profile): |
312 | 143 if 'xmlui' in data: |
238
7918a5668304
plugin remote: remote controllers plugin first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
144 xml_ui = xmlui.create( |
312 | 145 G.host, data['xmlui'], callback=self.xmluiCb, profile=profile) |
238
7918a5668304
plugin remote: remote controllers plugin first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
146 if isinstance(xml_ui, xmlui.XMLUIDialog): |
7918a5668304
plugin remote: remote controllers plugin first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
147 self.main_wid.showRootWidget() |
7918a5668304
plugin remote: remote controllers plugin first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
148 xml_ui.show() |
7918a5668304
plugin remote: remote controllers plugin first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
149 else: |
305
b2727877bad4
remote: fixed workflow and size for XMLUI panel used with Ad-Hoc commands:
Goffi <goffi@goffi.org>
parents:
282
diff
changeset
|
150 xml_ui.setCloseCb(self.onClose) |
238
7918a5668304
plugin remote: remote controllers plugin first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
151 self.main_wid.layout.add_widget(xml_ui) |
7918a5668304
plugin remote: remote controllers plugin first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
152 else: |
7918a5668304
plugin remote: remote controllers plugin first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
153 if data: |
312 | 154 log.warning(_("Unhandled data: {data}").format(data=data)) |
238
7918a5668304
plugin remote: remote controllers plugin first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
155 self.main_wid.showRootWidget() |
7918a5668304
plugin remote: remote controllers plugin first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
156 |
305
b2727877bad4
remote: fixed workflow and size for XMLUI panel used with Ad-Hoc commands:
Goffi <goffi@goffi.org>
parents:
282
diff
changeset
|
157 def onClose(self, __, reason): |
b2727877bad4
remote: fixed workflow and size for XMLUI panel used with Ad-Hoc commands:
Goffi <goffi@goffi.org>
parents:
282
diff
changeset
|
158 if reason == C.XMLUI_DATA_CANCELLED: |
b2727877bad4
remote: fixed workflow and size for XMLUI panel used with Ad-Hoc commands:
Goffi <goffi@goffi.org>
parents:
282
diff
changeset
|
159 self.main_wid.showRootWidget() |
b2727877bad4
remote: fixed workflow and size for XMLUI panel used with Ad-Hoc commands:
Goffi <goffi@goffi.org>
parents:
282
diff
changeset
|
160 else: |
b2727877bad4
remote: fixed workflow and size for XMLUI panel used with Ad-Hoc commands:
Goffi <goffi@goffi.org>
parents:
282
diff
changeset
|
161 self.main_wid.layout.clear_widgets() |
b2727877bad4
remote: fixed workflow and size for XMLUI panel used with Ad-Hoc commands:
Goffi <goffi@goffi.org>
parents:
282
diff
changeset
|
162 |
238
7918a5668304
plugin remote: remote controllers plugin first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
163 def adHocRunCb(self, data): |
7918a5668304
plugin remote: remote controllers plugin first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
164 xml_ui = xmlui.create(G.host, data, callback=self.xmluiCb, profile=self.profile) |
305
b2727877bad4
remote: fixed workflow and size for XMLUI panel used with Ad-Hoc commands:
Goffi <goffi@goffi.org>
parents:
282
diff
changeset
|
165 xml_ui.setCloseCb(self.onClose) |
238
7918a5668304
plugin remote: remote controllers plugin first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
166 self.main_wid.layout.add_widget(xml_ui) |
7918a5668304
plugin remote: remote controllers plugin first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
167 |
7918a5668304
plugin remote: remote controllers plugin first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
168 def do_item_action(self, touch): |
7918a5668304
plugin remote: remote controllers plugin first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
169 self.main_wid.layout.clear_widgets() |
312 | 170 G.host.bridge.adHocRun(str(self.entity_jid), '', self.profile, |
238
7918a5668304
plugin remote: remote controllers plugin first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
171 callback=self.adHocRunCb, errback=self.main_wid.errback) |
7918a5668304
plugin remote: remote controllers plugin first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
172 |
7918a5668304
plugin remote: remote controllers plugin first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
173 |
305
b2727877bad4
remote: fixed workflow and size for XMLUI panel used with Ad-Hoc commands:
Goffi <goffi@goffi.org>
parents:
282
diff
changeset
|
174 class DevicesLayout(FloatLayout): |
b2727877bad4
remote: fixed workflow and size for XMLUI panel used with Ad-Hoc commands:
Goffi <goffi@goffi.org>
parents:
282
diff
changeset
|
175 """Layout used to show devices""" |
b2727877bad4
remote: fixed workflow and size for XMLUI panel used with Ad-Hoc commands:
Goffi <goffi@goffi.org>
parents:
282
diff
changeset
|
176 layout = properties.ObjectProperty() |
b2727877bad4
remote: fixed workflow and size for XMLUI panel used with Ad-Hoc commands:
Goffi <goffi@goffi.org>
parents:
282
diff
changeset
|
177 |
b2727877bad4
remote: fixed workflow and size for XMLUI panel used with Ad-Hoc commands:
Goffi <goffi@goffi.org>
parents:
282
diff
changeset
|
178 |
238
7918a5668304
plugin remote: remote controllers plugin first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
179 class RemoteControl(quick_widgets.QuickWidget, cagou_widget.CagouWidget, FilterBehavior, |
7918a5668304
plugin remote: remote controllers plugin first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
180 TouchMenuBehaviour): |
7918a5668304
plugin remote: remote controllers plugin first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
181 SINGLE=False |
7918a5668304
plugin remote: remote controllers plugin first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
182 layout = properties.ObjectProperty() |
7918a5668304
plugin remote: remote controllers plugin first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
183 |
7918a5668304
plugin remote: remote controllers plugin first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
184 def __init__(self, host, target, profiles): |
7918a5668304
plugin remote: remote controllers plugin first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
185 quick_widgets.QuickWidget.__init__(self, host, target, profiles) |
7918a5668304
plugin remote: remote controllers plugin first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
186 cagou_widget.CagouWidget.__init__(self) |
7918a5668304
plugin remote: remote controllers plugin first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
187 FilterBehavior.__init__(self) |
7918a5668304
plugin remote: remote controllers plugin first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
188 TouchMenuBehaviour.__init__(self) |
305
b2727877bad4
remote: fixed workflow and size for XMLUI panel used with Ad-Hoc commands:
Goffi <goffi@goffi.org>
parents:
282
diff
changeset
|
189 self.stack_layout = None |
238
7918a5668304
plugin remote: remote controllers plugin first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
190 self.showRootWidget() |
7918a5668304
plugin remote: remote controllers plugin first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
191 |
7918a5668304
plugin remote: remote controllers plugin first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
192 def errback(self, failure_): |
7918a5668304
plugin remote: remote controllers plugin first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
193 """Generic errback which add a warning note and go back to root widget""" |
7918a5668304
plugin remote: remote controllers plugin first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
194 G.host.addNote( |
7918a5668304
plugin remote: remote controllers plugin first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
195 title=NOTE_TITLE, |
312 | 196 message=_("Can't use remote control: {reason}").format(reason=failure_), |
238
7918a5668304
plugin remote: remote controllers plugin first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
197 level=C.XMLUI_DATA_LVL_WARNING) |
7918a5668304
plugin remote: remote controllers plugin first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
198 self.showRootWidget() |
7918a5668304
plugin remote: remote controllers plugin first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
199 |
7918a5668304
plugin remote: remote controllers plugin first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
200 def key_input(self, window, key, scancode, codepoint, modifier): |
7918a5668304
plugin remote: remote controllers plugin first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
201 if key == 27: |
7918a5668304
plugin remote: remote controllers plugin first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
202 self.showRootWidget() |
7918a5668304
plugin remote: remote controllers plugin first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
203 return True |
7918a5668304
plugin remote: remote controllers plugin first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
204 |
7918a5668304
plugin remote: remote controllers plugin first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
205 def showRootWidget(self): |
7918a5668304
plugin remote: remote controllers plugin first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
206 self.layout.clear_widgets() |
305
b2727877bad4
remote: fixed workflow and size for XMLUI panel used with Ad-Hoc commands:
Goffi <goffi@goffi.org>
parents:
282
diff
changeset
|
207 devices_layout = DevicesLayout() |
b2727877bad4
remote: fixed workflow and size for XMLUI panel used with Ad-Hoc commands:
Goffi <goffi@goffi.org>
parents:
282
diff
changeset
|
208 self.stack_layout = devices_layout.layout |
b2727877bad4
remote: fixed workflow and size for XMLUI panel used with Ad-Hoc commands:
Goffi <goffi@goffi.org>
parents:
282
diff
changeset
|
209 self.layout.add_widget(devices_layout) |
238
7918a5668304
plugin remote: remote controllers plugin first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
210 found = [] |
7918a5668304
plugin remote: remote controllers plugin first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
211 self.get_remotes(found) |
7918a5668304
plugin remote: remote controllers plugin first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
212 self.discover_devices(found) |
7918a5668304
plugin remote: remote controllers plugin first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
213 |
7918a5668304
plugin remote: remote controllers plugin first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
214 def adHocRemotesGetCb(self, remotes_data, found): |
7918a5668304
plugin remote: remote controllers plugin first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
215 found.insert(0, remotes_data) |
7918a5668304
plugin remote: remote controllers plugin first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
216 if len(found) == 2: |
7918a5668304
plugin remote: remote controllers plugin first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
217 self.show_devices(found) |
7918a5668304
plugin remote: remote controllers plugin first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
218 |
7918a5668304
plugin remote: remote controllers plugin first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
219 def adHocRemotesGetEb(self, failure_, found): |
312 | 220 G.host.errback(failure_, title=_("discovery error"), |
221 message=_("can't check remote controllers: {msg}")) | |
238
7918a5668304
plugin remote: remote controllers plugin first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
222 found.insert(0, []) |
7918a5668304
plugin remote: remote controllers plugin first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
223 if len(found) == 2: |
7918a5668304
plugin remote: remote controllers plugin first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
224 self.show_devices(found) |
7918a5668304
plugin remote: remote controllers plugin first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
225 |
7918a5668304
plugin remote: remote controllers plugin first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
226 def get_remotes(self, found): |
7918a5668304
plugin remote: remote controllers plugin first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
227 self.host.bridge.adHocRemotesGet( |
7918a5668304
plugin remote: remote controllers plugin first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
228 self.profile, |
7918a5668304
plugin remote: remote controllers plugin first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
229 callback=partial(self.adHocRemotesGetCb, found=found), |
7918a5668304
plugin remote: remote controllers plugin first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
230 errback=partial(self.adHocRemotesGetEb,found=found)) |
7918a5668304
plugin remote: remote controllers plugin first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
231 |
7918a5668304
plugin remote: remote controllers plugin first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
232 def _discoFindByFeaturesCb(self, data, found): |
7918a5668304
plugin remote: remote controllers plugin first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
233 found.append(data) |
7918a5668304
plugin remote: remote controllers plugin first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
234 if len(found) == 2: |
7918a5668304
plugin remote: remote controllers plugin first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
235 self.show_devices(found) |
7918a5668304
plugin remote: remote controllers plugin first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
236 |
7918a5668304
plugin remote: remote controllers plugin first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
237 def _discoFindByFeaturesEb(self, failure_, found): |
312 | 238 G.host.errback(failure_, title=_("discovery error"), |
239 message=_("can't check devices: {msg}")) | |
238
7918a5668304
plugin remote: remote controllers plugin first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
240 found.append(({}, {}, {})) |
7918a5668304
plugin remote: remote controllers plugin first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
241 if len(found) == 2: |
7918a5668304
plugin remote: remote controllers plugin first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
242 self.show_devices(found) |
7918a5668304
plugin remote: remote controllers plugin first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
243 |
7918a5668304
plugin remote: remote controllers plugin first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
244 def discover_devices(self, found): |
7918a5668304
plugin remote: remote controllers plugin first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
245 """Looks for devices handling file "File Information Sharing" and display them""" |
7918a5668304
plugin remote: remote controllers plugin first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
246 try: |
7918a5668304
plugin remote: remote controllers plugin first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
247 namespace = self.host.ns_map['commands'] |
7918a5668304
plugin remote: remote controllers plugin first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
248 except KeyError: |
312 | 249 msg = _("can't find ad-hoc commands namespace, is the plugin running?") |
238
7918a5668304
plugin remote: remote controllers plugin first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
250 log.warning(msg) |
312 | 251 G.host.addNote(_("missing plugin"), msg, C.XMLUI_DATA_LVL_ERROR) |
238
7918a5668304
plugin remote: remote controllers plugin first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
252 return |
7918a5668304
plugin remote: remote controllers plugin first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
253 self.host.bridge.discoFindByFeatures( |
7918a5668304
plugin remote: remote controllers plugin first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
254 [namespace], [], False, True, True, True, False, self.profile, |
7918a5668304
plugin remote: remote controllers plugin first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
255 callback=partial(self._discoFindByFeaturesCb, found=found), |
7918a5668304
plugin remote: remote controllers plugin first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
256 errback=partial(self._discoFindByFeaturesEb, found=found)) |
7918a5668304
plugin remote: remote controllers plugin first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
257 |
7918a5668304
plugin remote: remote controllers plugin first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
258 def show_devices(self, found): |
7918a5668304
plugin remote: remote controllers plugin first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
259 remotes_data, (entities_services, entities_own, entities_roster) = found |
7918a5668304
plugin remote: remote controllers plugin first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
260 if remotes_data: |
312 | 261 title = _("media players remote controls") |
305
b2727877bad4
remote: fixed workflow and size for XMLUI panel used with Ad-Hoc commands:
Goffi <goffi@goffi.org>
parents:
282
diff
changeset
|
262 self.stack_layout.add_widget(CategorySeparator(text=title)) |
238
7918a5668304
plugin remote: remote controllers plugin first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
263 |
7918a5668304
plugin remote: remote controllers plugin first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
264 for remote_data in remotes_data: |
7918a5668304
plugin remote: remote controllers plugin first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
265 device_jid, node, name = remote_data |
7918a5668304
plugin remote: remote controllers plugin first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
266 wid = RemoteItemWidget(device_jid, node, name, self) |
305
b2727877bad4
remote: fixed workflow and size for XMLUI panel used with Ad-Hoc commands:
Goffi <goffi@goffi.org>
parents:
282
diff
changeset
|
267 self.stack_layout.add_widget(wid) |
238
7918a5668304
plugin remote: remote controllers plugin first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
268 |
7918a5668304
plugin remote: remote controllers plugin first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
269 for entities_map, title in ((entities_services, |
312 | 270 _('services')), |
238
7918a5668304
plugin remote: remote controllers plugin first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
271 (entities_own, |
312 | 272 _('your devices')), |
238
7918a5668304
plugin remote: remote controllers plugin first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
273 (entities_roster, |
312 | 274 _('your contacts devices'))): |
238
7918a5668304
plugin remote: remote controllers plugin first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
275 if entities_map: |
305
b2727877bad4
remote: fixed workflow and size for XMLUI panel used with Ad-Hoc commands:
Goffi <goffi@goffi.org>
parents:
282
diff
changeset
|
276 self.stack_layout.add_widget(CategorySeparator(text=title)) |
312 | 277 for entity_str, entity_ids in entities_map.items(): |
238
7918a5668304
plugin remote: remote controllers plugin first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
278 entity_jid = jid.JID(entity_str) |
7918a5668304
plugin remote: remote controllers plugin first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
279 item = RemoteDeviceWidget( |
7918a5668304
plugin remote: remote controllers plugin first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
280 self, entity_jid, Identities(entity_ids)) |
305
b2727877bad4
remote: fixed workflow and size for XMLUI panel used with Ad-Hoc commands:
Goffi <goffi@goffi.org>
parents:
282
diff
changeset
|
281 self.stack_layout.add_widget(item) |
238
7918a5668304
plugin remote: remote controllers plugin first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
282 if (not remotes_data and not entities_services and not entities_own |
7918a5668304
plugin remote: remote controllers plugin first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
283 and not entities_roster): |
305
b2727877bad4
remote: fixed workflow and size for XMLUI panel used with Ad-Hoc commands:
Goffi <goffi@goffi.org>
parents:
282
diff
changeset
|
284 self.stack_layout.add_widget(Label( |
238
7918a5668304
plugin remote: remote controllers plugin first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
285 size_hint=(1, 1), |
7918a5668304
plugin remote: remote controllers plugin first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
286 halign='center', |
7918a5668304
plugin remote: remote controllers plugin first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
287 text_size=self.size, |
312 | 288 text=_("No sharing device found"))) |