control file for StartUpService
[enigma2-plugins.git] / startupservice / src / plugin.py
1 #
2 #  StartUpService E2
3 #
4 #  $Id$
5 #
6 #  Coded by Dr.Best (c) 2009
7 #  Support: www.dreambox-tools.info
8 #
9 #  This program is free software; you can redistribute it and/or
10 #  modify it under the terms of the GNU General Public License
11 #  as published by the Free Software Foundation; either version 2
12 #  of the License, or (at your option) any later version.
13 #
14 #  This program is distributed in the hope that it will be useful,
15 #  but WITHOUT ANY WARRANTY; without even the implied warranty of
16 #  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17 #  GNU General Public License for more details.
18 #
19
20 from Plugins.Plugin import PluginDescriptor\r
21 from Components.config import config, ConfigSubsection, ConfigText\r
22 from Screens.Screen import Screen\r
23 from Screens.ChannelSelection import ChannelContextMenu
24 from enigma import eServiceReference
25
26 # for localized messages
27 from . import _
28
29 #config for lastservice
30 config.startupservice = ConfigSubsection()
31 config.startupservice.lastservice = ConfigText(default = "")
32 config.startupservice.lastroot = ConfigText(default = "")
33 config.startupservice.lastmode = ConfigText(default = "tv")
34
35 def main(session, **kwargs):
36         # copy startupservice data to config.tv or config.radio if available
37         if config.startupservice.lastservice.value != "" and config.startupservice.lastroot.value != "":
38                 config.servicelist = ConfigSubsection()
39                 config.servicelist.lastmode = ConfigText(default = "tv")
40                 config.servicelist.lastmode.value = config.startupservice.lastmode.value
41                 config.servicelist.lastmode.save()
42                 if config.startupservice.lastmode.value == "tv":
43                         config.tv = ConfigSubsection()
44                         config.tv.lastservice = ConfigText()
45                         config.tv.lastroot = ConfigText()
46                         config.tv.lastservice.value = config.startupservice.lastservice.value
47                         config.tv.lastroot.value = config.startupservice.lastroot.value
48                         config.tv.save()
49                 else:
50                         config.radio = ConfigSubsection()
51                         config.radio.lastservice = ConfigText()
52                         config.radio.lastroot = ConfigText()
53                         config.radio.lastservice.value = config.startupservice.lastservice.value
54                         config.radio.lastroot.value = config.startupservice.lastroot.value
55                         config.radio.save()
56         try: startUpServiceInit()
57         except: pass
58 \r
59 ###########################################
60 # ChannelContextMenu
61 ###########################################
62 baseChannelContextMenu__init__ = None
63 def startUpServiceInit():
64         global baseChannelContextMenu__init__\r
65         if baseChannelContextMenu__init__ is None:
66                 baseChannelContextMenu__init__ = ChannelContextMenu.__init__
67         ChannelContextMenu.__init__ = startUpService__init__
68         # new methods
69         ChannelContextMenu.newStartUpServiceSelected = newStartUpServiceSelected
70         ChannelContextMenu.resetStartUpService = resetStartUpService
71
72 def startUpService__init__(self, session, csel):
73         baseChannelContextMenu__init__(self, session, csel)
74         current = csel.getCurrentSelection()
75         current_root = csel.getRoot()
76         inBouquetRootList = current_root and current_root.getPath().find('FROM BOUQUET "bouquets.') != -1 #FIXME HACK
77         if csel.bouquet_mark_edit == 0 and not csel.movemode:
78                 if not inBouquetRootList:
79                         if not (current.flags & (eServiceReference.isMarker|eServiceReference.isDirectory)):
80                                 self["menu"].list.insert(1, (_("set as startup service"), self.newStartUpServiceSelected))
81                                 self["menu"].list.insert(2, (_("reset startup service"), self.resetStartUpService))
82
83 def newStartUpServiceSelected(self):
84         current = self.csel.getCurrentSelection()
85         current_root = self.csel.getRoot()
86         if current.type == eServiceReference.idDVB and current.getData(0) in (2, 10):   
87                 config.startupservice.lastroot.value = "1:7:2:0:0:0:0:0:0:0:%s;" % (current_root.getPath())
88                 config.startupservice.lastmode.value = "radio"
89         else:
90                 config.startupservice.lastroot.value = "1:7:1:0:0:0:0:0:0:0:%s;" % (current_root.getPath())
91                 config.startupservice.lastmode.value = "tv"
92         config.startupservice.lastservice.value = current.toString()
93         config.startupservice.save()
94         self.close()
95
96 def resetStartUpService(self):
97         config.startupservice.lastroot.value = ""
98         config.startupservice.lastmode.value = "tv"
99         config.startupservice.lastservice.value = ""
100         config.startupservice.save()
101         self.close()
102
103 def Plugins(**kwargs):\r
104         return [PluginDescriptor(name="StartUpService", description="set startup service", where = PluginDescriptor.WHERE_SESSIONSTART, fnc=main)]
105