added MultiRC plugin to control different dreamboxes with different remotes
[enigma2-plugins.git] / multirc / src / plugin.py
1 from Plugins.Plugin import PluginDescriptor
2 from Screens.Screen import Screen
3 from Screens.MessageBox import MessageBox
4 from Components.ConfigList import ConfigListScreen
5 from Components.ActionMap import ActionMap
6 from Components.Label import Label
7 from Components.config import *
8
9 CONFIGS = [("1", "layer 1"),
10            ("2", "layer 2"),
11            ("4", "layer 3"),
12            ("8", "layer 4"),
13            ("f", "any RC")]
14
15 config.plugins.MultiRC = ConfigSubsection()
16 config.plugins.MultiRC.mask = ConfigSelection(choices = CONFIGS, default = "f")
17
18 # config file for IR mask
19 MASK = "/proc/stb/ir/rc/mask0"
20
21 class MultiRCSetup(ConfigListScreen, Screen):
22         skin = """
23                 <screen position="170,150" size="420,280" title="Multi RemoteControl" >
24                 <widget name="config" position="10,10" size="400,40" scrollbarMode="showOnDemand" />
25                 <widget name="warning" position="10,50" size="400,220" font="Regular;20" halign="center"/>
26                 </screen>"""
27
28         # most of the following is black magic copied from other plugins.
29         # e2 devs should really make some best practices or wrapper for this!
30         def __init__(self, session, args = None):
31                 Screen.__init__(self, session)
32                 self.list = [getConfigListEntry("Listen on Remote Control", config.plugins.MultiRC.mask)]
33                 ConfigListScreen.__init__(self, self.list)
34                 self["warning"] = Label("""WARNING!
35 After changing this and pressing <Ok>, your Remote Control might stop working!
36
37 Information about re-configuring the RC is available at http://www.dream-multimedia-tv.de/board/thread.php?threadid=5613""")
38                 self["config"].list = self.list
39                 self["config"].setList(self.list)
40                 self["setupActions"] = ActionMap(["SetupActions"],
41                 {
42                         "save": self.ask_save,
43                         "cancel": self.cancel,
44                         "ok": self.ask_save,
45                 }, -2)
46
47         def ask_save(self):
48                 set_mask()
49                 # mask value 0xf allows all RCs, no need to verify
50                 if config.plugins.MultiRC.mask.value == "f":
51                         self.confirm_save(True)
52                 else:
53                         self.session.openWithCallback(self.confirm_save, MessageBox,
54                                 "Is the RC still working?", MessageBox.TYPE_YESNO,
55                                 timeout = 20, default = False)
56
57         def confirm_save(self, confirmed):
58                 if confirmed:
59                         for x in self["config"].list:
60                                 x[1].save()
61                         set_mask()
62                         self.close()
63                 else:
64                         # input failed, reset to any RC
65                         set_mask("f")
66
67         def cancel(self):
68                 for x in self["config"].list:
69                         x[1].cancel()
70                 set_mask()
71                 self.close()
72
73 def set_mask(mask=None):
74         if not mask:
75                 mask = config.plugins.MultiRC.mask.value
76         f = open(MASK, "w")
77         f.write(mask)
78         f.close()
79
80 def multirc_setup(session, **kwargs):
81         session.open(MultiRCSetup)
82
83 def multirc_autostart(reason, **kwargs):
84         # on startup, set correct remote mask
85         if reason == 0:
86                 set_mask()
87                 pass
88
89 def Plugins(**kwargs):
90         return [PluginDescriptor(name="Multi RemoteControl",
91                                 description="Multi Dreambox RC layer setup",
92                                 where=PluginDescriptor.WHERE_PLUGINMENU,
93                                 fnc = multirc_setup),
94
95                 PluginDescriptor(where=PluginDescriptor.WHERE_AUTOSTART,
96                                 fnc = multirc_autostart)]
97
98