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