annotate cagou/plugins/plugin_wid_remote.py @ 290:a7b80552ca8d

core: don't change mouse setting on Android, this is causing a touch bug: when changing setting to avoid multitouch emulation with mouse, Kivy is doing several touch event on Android. cf. https://github.com/kivy/kivy/issues/6229
author Goffi <goffi@goffi.org>
date Sun, 07 Apr 2019 21:09:27 +0200
parents 1b835bcfa663
children b2727877bad4
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
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
282
1b835bcfa663 date update
Goffi <goffi@goffi.org>
parents: 239
diff changeset
5 # Copyright (C) 2016-2019 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 log = logging.getLogger(__name__)
7918a5668304 plugin remote: remote controllers plugin first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
23 from sat.core.i18n import _
7918a5668304 plugin remote: remote controllers plugin first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
24 from sat_frontends.quick_frontend import quick_widgets
7918a5668304 plugin remote: remote controllers plugin first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
25 from cagou.core import cagou_widget
7918a5668304 plugin remote: remote controllers plugin first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
26 from cagou.core.constants import Const as C
7918a5668304 plugin remote: remote controllers plugin first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
27 from cagou.core.menu import TouchMenuBehaviour
7918a5668304 plugin remote: remote controllers plugin first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
28 from cagou.core.utils import FilterBehavior
7918a5668304 plugin remote: remote controllers plugin first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
29 from cagou.core.common_widgets import (Identities, ItemWidget, DeviceWidget,
7918a5668304 plugin remote: remote controllers plugin first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
30 CategorySeparator)
7918a5668304 plugin remote: remote controllers plugin first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
31 from sat.tools.common import template_xmlui
7918a5668304 plugin remote: remote controllers plugin first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
32 from cagou.core import xmlui
7918a5668304 plugin remote: remote controllers plugin first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
33 from sat_frontends.tools import jid
7918a5668304 plugin remote: remote controllers plugin first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
34 from kivy import properties
7918a5668304 plugin remote: remote controllers plugin first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
35 from kivy.uix.label import Label
7918a5668304 plugin remote: remote controllers plugin first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
36 from kivy.uix.boxlayout import BoxLayout
7918a5668304 plugin remote: remote controllers plugin first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
37 from kivy.core.window import Window
7918a5668304 plugin remote: remote controllers plugin first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
38 from cagou import G
7918a5668304 plugin remote: remote controllers plugin first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
39 from functools import partial
7918a5668304 plugin remote: remote controllers plugin first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
40
7918a5668304 plugin remote: remote controllers plugin first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
41
7918a5668304 plugin remote: remote controllers plugin first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
42 PLUGIN_INFO = {
7918a5668304 plugin remote: remote controllers plugin first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
43 "name": _(u"remote control"),
7918a5668304 plugin remote: remote controllers plugin first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
44 "main": "RemoteControl",
7918a5668304 plugin remote: remote controllers plugin first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
45 "description": _(u"universal remote control"),
7918a5668304 plugin remote: remote controllers plugin first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
46 "icon_symbol": u"signal",
7918a5668304 plugin remote: remote controllers plugin first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
47 }
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 NOTE_TITLE = _(u"Media Player Remote Control")
7918a5668304 plugin remote: remote controllers plugin first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
50
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 class RemoteItemWidget(ItemWidget):
7918a5668304 plugin remote: remote controllers plugin first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
53
7918a5668304 plugin remote: remote controllers plugin first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
54 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
55 self.device_jid = device_jid
7918a5668304 plugin remote: remote controllers plugin first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
56 self.node = node
7918a5668304 plugin remote: remote controllers plugin first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
57 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
58
7918a5668304 plugin remote: remote controllers plugin first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
59 def do_item_action(self, touch):
7918a5668304 plugin remote: remote controllers plugin first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
60 self.main_wid.layout.clear_widgets()
7918a5668304 plugin remote: remote controllers plugin first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
61 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
62 self.main_wid.layout.add_widget(player_wid)
7918a5668304 plugin remote: remote controllers plugin first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
63
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 class MediaPlayerControlWidget(BoxLayout):
7918a5668304 plugin remote: remote controllers plugin first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
66 main_wid = properties.ObjectProperty()
7918a5668304 plugin remote: remote controllers plugin first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
67 remote_item = properties.ObjectProperty()
7918a5668304 plugin remote: remote controllers plugin first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
68 status = properties.OptionProperty(u"play", options=(u"play", u"pause", u"stop"))
7918a5668304 plugin remote: remote controllers plugin first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
69 title = properties.StringProperty()
7918a5668304 plugin remote: remote controllers plugin first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
70 identity = properties.StringProperty()
7918a5668304 plugin remote: remote controllers plugin first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
71 command = properties.DictProperty()
7918a5668304 plugin remote: remote controllers plugin first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
72 ui_tpl = properties.ObjectProperty()
7918a5668304 plugin remote: remote controllers plugin first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
73
7918a5668304 plugin remote: remote controllers plugin first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
74 @property
7918a5668304 plugin remote: remote controllers plugin first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
75 def profile(self):
7918a5668304 plugin remote: remote controllers plugin first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
76 return self.main_wid.profile
7918a5668304 plugin remote: remote controllers plugin first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
77
7918a5668304 plugin remote: remote controllers plugin first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
78 def updateUI(self, action_data):
7918a5668304 plugin remote: remote controllers plugin first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
79 xmlui_raw = action_data['xmlui']
7918a5668304 plugin remote: remote controllers plugin first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
80 ui_tpl = template_xmlui.create(G.host, xmlui_raw)
7918a5668304 plugin remote: remote controllers plugin first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
81 self.ui_tpl = ui_tpl
7918a5668304 plugin remote: remote controllers plugin first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
82 for prop in ('Title', 'Identity'):
7918a5668304 plugin remote: remote controllers plugin first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
83 try:
7918a5668304 plugin remote: remote controllers plugin first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
84 setattr(self, prop.lower(), ui_tpl.widgets[prop].value)
7918a5668304 plugin remote: remote controllers plugin first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
85 except KeyError:
7918a5668304 plugin remote: remote controllers plugin first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
86 log.warning(_(u"Missing field: {name}").format(name=prop))
7918a5668304 plugin remote: remote controllers plugin first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
87 playback_status = self.ui_tpl.widgets['PlaybackStatus'].value
7918a5668304 plugin remote: remote controllers plugin first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
88 if playback_status == u"Playing":
7918a5668304 plugin remote: remote controllers plugin first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
89 self.status = u"pause"
7918a5668304 plugin remote: remote controllers plugin first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
90 elif playback_status == u"Paused":
7918a5668304 plugin remote: remote controllers plugin first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
91 self.status = u"play"
7918a5668304 plugin remote: remote controllers plugin first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
92 elif playback_status == u"Stopped":
7918a5668304 plugin remote: remote controllers plugin first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
93 self.status = u"play"
7918a5668304 plugin remote: remote controllers plugin first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
94 else:
7918a5668304 plugin remote: remote controllers plugin first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
95 G.host.addNote(
7918a5668304 plugin remote: remote controllers plugin first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
96 title=NOTE_TITLE,
7918a5668304 plugin remote: remote controllers plugin first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
97 message=_(u"Unknown playback status: playback_status")
7918a5668304 plugin remote: remote controllers plugin first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
98 .format(playback_status=playback_status),
7918a5668304 plugin remote: remote controllers plugin first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
99 level=C.XMLUI_DATA_LVL_WARNING)
7918a5668304 plugin remote: remote controllers plugin first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
100 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
101
7918a5668304 plugin remote: remote controllers plugin first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
102 def adHocRunCb(self, xmlui_raw):
7918a5668304 plugin remote: remote controllers plugin first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
103 ui_tpl = template_xmlui.create(G.host, xmlui_raw)
7918a5668304 plugin remote: remote controllers plugin first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
104 data = {xmlui.XMLUIPanel.escape(u"media_player"): self.remote_item.node,
7918a5668304 plugin remote: remote controllers plugin first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
105 u"session_id": ui_tpl.session_id}
7918a5668304 plugin remote: remote controllers plugin first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
106 G.host.bridge.launchAction(
7918a5668304 plugin remote: remote controllers plugin first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
107 ui_tpl.submit_id, data, self.profile,
7918a5668304 plugin remote: remote controllers plugin first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
108 callback=self.updateUI,
7918a5668304 plugin remote: remote controllers plugin first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
109 errback=self.main_wid.errback)
7918a5668304 plugin remote: remote controllers plugin first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
110
7918a5668304 plugin remote: remote controllers plugin first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
111 def on_remote_item(self, __, remote):
7918a5668304 plugin remote: remote controllers plugin first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
112 NS_MEDIA_PLAYER = G.host.ns_map[u"mediaplayer"]
7918a5668304 plugin remote: remote controllers plugin first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
113 G.host.bridge.adHocRun(remote.device_jid, NS_MEDIA_PLAYER, self.profile,
7918a5668304 plugin remote: remote controllers plugin first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
114 callback=self.adHocRunCb,
7918a5668304 plugin remote: remote controllers plugin first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
115 errback=self.main_wid.errback)
7918a5668304 plugin remote: remote controllers plugin first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
116
7918a5668304 plugin remote: remote controllers plugin first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
117 def do_cmd(self, command):
7918a5668304 plugin remote: remote controllers plugin first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
118 try:
7918a5668304 plugin remote: remote controllers plugin first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
119 cmd_value = self.commands[command]
7918a5668304 plugin remote: remote controllers plugin first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
120 except KeyError:
7918a5668304 plugin remote: remote controllers plugin first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
121 G.host.addNote(
7918a5668304 plugin remote: remote controllers plugin first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
122 title=NOTE_TITLE,
7918a5668304 plugin remote: remote controllers plugin first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
123 message=_(u"{command} command is not managed").format(command=command),
7918a5668304 plugin remote: remote controllers plugin first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
124 level=C.XMLUI_DATA_LVL_WARNING)
7918a5668304 plugin remote: remote controllers plugin first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
125 else:
7918a5668304 plugin remote: remote controllers plugin first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
126 data = {xmlui.XMLUIPanel.escape(u"command"): cmd_value,
7918a5668304 plugin remote: remote controllers plugin first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
127 u"session_id": self.ui_tpl.session_id}
7918a5668304 plugin remote: remote controllers plugin first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
128 # hidden values are normally transparently managed by XMLUIPanel
7918a5668304 plugin remote: remote controllers plugin first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
129 # but here we have to add them by hand
7918a5668304 plugin remote: remote controllers plugin first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
130 hidden = {xmlui.XMLUIPanel.escape(k):v
7918a5668304 plugin remote: remote controllers plugin first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
131 for k,v in self.ui_tpl.hidden.iteritems()}
7918a5668304 plugin remote: remote controllers plugin first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
132 data.update(hidden)
7918a5668304 plugin remote: remote controllers plugin first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
133 G.host.bridge.launchAction(
7918a5668304 plugin remote: remote controllers plugin first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
134 self.ui_tpl.submit_id, data, self.profile,
7918a5668304 plugin remote: remote controllers plugin first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
135 callback=self.updateUI,
7918a5668304 plugin remote: remote controllers plugin first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
136 errback=self.main_wid.errback)
7918a5668304 plugin remote: remote controllers plugin first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
137
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 class RemoteDeviceWidget(DeviceWidget):
7918a5668304 plugin remote: remote controllers plugin first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
140
7918a5668304 plugin remote: remote controllers plugin first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
141 def xmluiCb(self, data, cb_id, profile):
7918a5668304 plugin remote: remote controllers plugin first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
142 if u'xmlui' in data:
7918a5668304 plugin remote: remote controllers plugin first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
143 xml_ui = xmlui.create(
7918a5668304 plugin remote: remote controllers plugin first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
144 G.host, data[u'xmlui'], callback=self.xmluiCb, profile=profile)
7918a5668304 plugin remote: remote controllers plugin first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
145 if isinstance(xml_ui, xmlui.XMLUIDialog):
7918a5668304 plugin remote: remote controllers plugin first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
146 self.main_wid.showRootWidget()
7918a5668304 plugin remote: remote controllers plugin first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
147 xml_ui.show()
7918a5668304 plugin remote: remote controllers plugin first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
148 else:
7918a5668304 plugin remote: remote controllers plugin first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
149 xml_ui.size_hint_y = None
7918a5668304 plugin remote: remote controllers plugin first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
150 self.main_wid.layout.clear_widgets()
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:
7918a5668304 plugin remote: remote controllers plugin first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
154 log.warning(_(u"Unhandled data: {data}").format(data=data))
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
7918a5668304 plugin remote: remote controllers plugin first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
157 def adHocRunCb(self, data):
7918a5668304 plugin remote: remote controllers plugin first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
158 xml_ui = xmlui.create(G.host, data, callback=self.xmluiCb, profile=self.profile)
7918a5668304 plugin remote: remote controllers plugin first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
159 xml_ui.size_hint_y = None
7918a5668304 plugin remote: remote controllers plugin first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
160 self.main_wid.layout.add_widget(xml_ui)
7918a5668304 plugin remote: remote controllers plugin first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
161
7918a5668304 plugin remote: remote controllers plugin first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
162 def do_item_action(self, touch):
7918a5668304 plugin remote: remote controllers plugin first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
163 self.main_wid.layout.clear_widgets()
7918a5668304 plugin remote: remote controllers plugin first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
164 G.host.bridge.adHocRun(self.entity_jid, u'', self.profile,
7918a5668304 plugin remote: remote controllers plugin first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
165 callback=self.adHocRunCb, errback=self.main_wid.errback)
7918a5668304 plugin remote: remote controllers plugin first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
166
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 class RemoteControl(quick_widgets.QuickWidget, cagou_widget.CagouWidget, FilterBehavior,
7918a5668304 plugin remote: remote controllers plugin first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
169 TouchMenuBehaviour):
7918a5668304 plugin remote: remote controllers plugin first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
170 SINGLE=False
7918a5668304 plugin remote: remote controllers plugin first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
171 layout = properties.ObjectProperty()
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 def __init__(self, host, target, profiles):
7918a5668304 plugin remote: remote controllers plugin first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
174 quick_widgets.QuickWidget.__init__(self, host, target, profiles)
7918a5668304 plugin remote: remote controllers plugin first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
175 cagou_widget.CagouWidget.__init__(self)
7918a5668304 plugin remote: remote controllers plugin first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
176 FilterBehavior.__init__(self)
7918a5668304 plugin remote: remote controllers plugin first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
177 TouchMenuBehaviour.__init__(self)
7918a5668304 plugin remote: remote controllers plugin first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
178 Window.bind(on_keyboard=self.key_input)
7918a5668304 plugin remote: remote controllers plugin first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
179 self.showRootWidget()
7918a5668304 plugin remote: remote controllers plugin first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
180
7918a5668304 plugin remote: remote controllers plugin first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
181 def errback(self, failure_):
7918a5668304 plugin remote: remote controllers plugin first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
182 """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
183 G.host.addNote(
7918a5668304 plugin remote: remote controllers plugin first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
184 title=NOTE_TITLE,
7918a5668304 plugin remote: remote controllers plugin first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
185 message=_(u"Can't use remote control: {reason}").format(reason=failure_),
7918a5668304 plugin remote: remote controllers plugin first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
186 level=C.XMLUI_DATA_LVL_WARNING)
7918a5668304 plugin remote: remote controllers plugin first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
187 self.showRootWidget()
7918a5668304 plugin remote: remote controllers plugin first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
188
7918a5668304 plugin remote: remote controllers plugin first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
189 def key_input(self, window, key, scancode, codepoint, modifier):
7918a5668304 plugin remote: remote controllers plugin first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
190 if key == 27:
7918a5668304 plugin remote: remote controllers plugin first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
191 self.showRootWidget()
7918a5668304 plugin remote: remote controllers plugin first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
192 return True
7918a5668304 plugin remote: remote controllers plugin first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
193
7918a5668304 plugin remote: remote controllers plugin first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
194 def showRootWidget(self):
7918a5668304 plugin remote: remote controllers plugin first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
195 self.layout.clear_widgets()
7918a5668304 plugin remote: remote controllers plugin first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
196 found = []
7918a5668304 plugin remote: remote controllers plugin first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
197 self.get_remotes(found)
7918a5668304 plugin remote: remote controllers plugin first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
198 self.discover_devices(found)
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 adHocRemotesGetCb(self, remotes_data, found):
7918a5668304 plugin remote: remote controllers plugin first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
201 found.insert(0, remotes_data)
7918a5668304 plugin remote: remote controllers plugin first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
202 if len(found) == 2:
7918a5668304 plugin remote: remote controllers plugin first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
203 self.show_devices(found)
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 adHocRemotesGetEb(self, failure_, found):
7918a5668304 plugin remote: remote controllers plugin first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
206 G.host.errback(failure_, title=_(u"discovery error"),
7918a5668304 plugin remote: remote controllers plugin first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
207 message=_(u"can't check remote controllers: {msg}"))
7918a5668304 plugin remote: remote controllers plugin first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
208 found.insert(0, [])
7918a5668304 plugin remote: remote controllers plugin first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
209 if len(found) == 2:
7918a5668304 plugin remote: remote controllers plugin first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
210 self.show_devices(found)
7918a5668304 plugin remote: remote controllers plugin first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
211
7918a5668304 plugin remote: remote controllers plugin first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
212 def get_remotes(self, found):
7918a5668304 plugin remote: remote controllers plugin first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
213 self.host.bridge.adHocRemotesGet(
7918a5668304 plugin remote: remote controllers plugin first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
214 self.profile,
7918a5668304 plugin remote: remote controllers plugin first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
215 callback=partial(self.adHocRemotesGetCb, found=found),
7918a5668304 plugin remote: remote controllers plugin first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
216 errback=partial(self.adHocRemotesGetEb,found=found))
7918a5668304 plugin remote: remote controllers plugin first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
217
7918a5668304 plugin remote: remote controllers plugin first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
218 def _discoFindByFeaturesCb(self, data, found):
7918a5668304 plugin remote: remote controllers plugin first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
219 found.append(data)
7918a5668304 plugin remote: remote controllers plugin first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
220 if len(found) == 2:
7918a5668304 plugin remote: remote controllers plugin first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
221 self.show_devices(found)
7918a5668304 plugin remote: remote controllers plugin first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
222
7918a5668304 plugin remote: remote controllers plugin first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
223 def _discoFindByFeaturesEb(self, failure_, found):
7918a5668304 plugin remote: remote controllers plugin first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
224 G.host.errback(failure_, title=_(u"discovery error"),
7918a5668304 plugin remote: remote controllers plugin first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
225 message=_(u"can't check devices: {msg}"))
7918a5668304 plugin remote: remote controllers plugin first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
226 found.append(({}, {}, {}))
7918a5668304 plugin remote: remote controllers plugin first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
227 if len(found) == 2:
7918a5668304 plugin remote: remote controllers plugin first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
228 self.show_devices(found)
7918a5668304 plugin remote: remote controllers plugin first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
229
7918a5668304 plugin remote: remote controllers plugin first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
230 def discover_devices(self, found):
7918a5668304 plugin remote: remote controllers plugin first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
231 """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
232 try:
7918a5668304 plugin remote: remote controllers plugin first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
233 namespace = self.host.ns_map['commands']
7918a5668304 plugin remote: remote controllers plugin first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
234 except KeyError:
239
a2af4c1e9c6f plugin remote: fixed error message
Goffi <goffi@goffi.org>
parents: 238
diff changeset
235 msg = _(u"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
236 log.warning(msg)
7918a5668304 plugin remote: remote controllers plugin first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
237 G.host.addNote(_(u"missing plugin"), msg, C.XMLUI_DATA_LVL_ERROR)
7918a5668304 plugin remote: remote controllers plugin first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
238 return
7918a5668304 plugin remote: remote controllers plugin first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
239 self.host.bridge.discoFindByFeatures(
7918a5668304 plugin remote: remote controllers plugin first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
240 [namespace], [], False, True, True, True, False, self.profile,
7918a5668304 plugin remote: remote controllers plugin first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
241 callback=partial(self._discoFindByFeaturesCb, found=found),
7918a5668304 plugin remote: remote controllers plugin first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
242 errback=partial(self._discoFindByFeaturesEb, found=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 show_devices(self, found):
7918a5668304 plugin remote: remote controllers plugin first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
245 remotes_data, (entities_services, entities_own, entities_roster) = found
7918a5668304 plugin remote: remote controllers plugin first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
246 if remotes_data:
7918a5668304 plugin remote: remote controllers plugin first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
247 title = _(u"media players remote controls")
7918a5668304 plugin remote: remote controllers plugin first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
248 self.layout.add_widget(CategorySeparator(text=title))
7918a5668304 plugin remote: remote controllers plugin first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
249
7918a5668304 plugin remote: remote controllers plugin first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
250 for remote_data in remotes_data:
7918a5668304 plugin remote: remote controllers plugin first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
251 device_jid, node, name = remote_data
7918a5668304 plugin remote: remote controllers plugin first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
252 wid = RemoteItemWidget(device_jid, node, name, self)
7918a5668304 plugin remote: remote controllers plugin first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
253 self.layout.add_widget(wid)
7918a5668304 plugin remote: remote controllers plugin first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
254
7918a5668304 plugin remote: remote controllers plugin first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
255 for entities_map, title in ((entities_services,
7918a5668304 plugin remote: remote controllers plugin first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
256 _(u'services')),
7918a5668304 plugin remote: remote controllers plugin first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
257 (entities_own,
7918a5668304 plugin remote: remote controllers plugin first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
258 _(u'your devices')),
7918a5668304 plugin remote: remote controllers plugin first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
259 (entities_roster,
7918a5668304 plugin remote: remote controllers plugin first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
260 _(u'your contacts devices'))):
7918a5668304 plugin remote: remote controllers plugin first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
261 if entities_map:
7918a5668304 plugin remote: remote controllers plugin first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
262 self.layout.add_widget(CategorySeparator(text=title))
7918a5668304 plugin remote: remote controllers plugin first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
263 for entity_str, entity_ids in entities_map.iteritems():
7918a5668304 plugin remote: remote controllers plugin first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
264 entity_jid = jid.JID(entity_str)
7918a5668304 plugin remote: remote controllers plugin first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
265 item = RemoteDeviceWidget(
7918a5668304 plugin remote: remote controllers plugin first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
266 self, entity_jid, Identities(entity_ids))
7918a5668304 plugin remote: remote controllers plugin first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
267 self.layout.add_widget(item)
7918a5668304 plugin remote: remote controllers plugin first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
268 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
269 and not entities_roster):
7918a5668304 plugin remote: remote controllers plugin first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
270 self.layout.add_widget(Label(
7918a5668304 plugin remote: remote controllers plugin first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
271 size_hint=(1, 1),
7918a5668304 plugin remote: remote controllers plugin first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
272 halign='center',
7918a5668304 plugin remote: remote controllers plugin first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
273 text_size=self.size,
7918a5668304 plugin remote: remote controllers plugin first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
274 text=_(u"No sharing device found")))