code adaption for ChannelSelection.py update from 23-12-09
[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 from Components.ChoiceList import ChoiceEntryComponent
26
27 # for localized messages
28 from . import _
29
30 #config for lastservice
31 config.startupservice = ConfigSubsection()
32 config.startupservice.lastservice = ConfigText(default = "")
33 config.startupservice.lastroot = ConfigText(default = "")
34 config.startupservice.lastmode = ConfigText(default = "tv")
35
36 def main(session, **kwargs):
37         # copy startupservice data to config.tv or config.radio if available
38         if config.startupservice.lastservice.value != "" and config.startupservice.lastroot.value != "":
39                 config.servicelist = ConfigSubsection()
40                 config.servicelist.lastmode = ConfigText(default = "tv")
41                 config.servicelist.lastmode.value = config.startupservice.lastmode.value
42                 config.servicelist.lastmode.save()
43                 if config.startupservice.lastmode.value == "tv":
44                         config.tv = ConfigSubsection()
45                         config.tv.lastservice = ConfigText()
46                         config.tv.lastroot = ConfigText()
47                         config.tv.lastservice.value = config.startupservice.lastservice.value
48                         config.tv.lastroot.value = config.startupservice.lastroot.value
49                         config.tv.save()
50                 else:
51                         config.radio = ConfigSubsection()
52                         config.radio.lastservice = ConfigText()
53                         config.radio.lastroot = ConfigText()
54                         config.radio.lastservice.value = config.startupservice.lastservice.value
55                         config.radio.lastroot.value = config.startupservice.lastroot.value
56                         config.radio.save()
57         try: startUpServiceInit()
58         except: pass
59 \r
60 ###########################################
61 # ChannelContextMenu
62 ###########################################
63 baseChannelContextMenu__init__ = None
64 def startUpServiceInit():
65         global baseChannelContextMenu__init__\r
66         if baseChannelContextMenu__init__ is None:
67                 baseChannelContextMenu__init__ = ChannelContextMenu.__init__
68         ChannelContextMenu.__init__ = startUpService__init__
69         # new methods
70         ChannelContextMenu.newStartUpServiceSelected = newStartUpServiceSelected
71         ChannelContextMenu.resetStartUpService = resetStartUpService
72
73 def startUpService__init__(self, session, csel):
74         baseChannelContextMenu__init__(self, session, csel)
75         current = csel.getCurrentSelection()
76         current_root = csel.getRoot()
77         inBouquetRootList = current_root and current_root.getPath().find('FROM BOUQUET "bouquets.') != -1 #FIXME HACK
78         if csel.bouquet_mark_edit == 0 and not csel.movemode:
79                 if not inBouquetRootList:
80                         if not (current.flags & (eServiceReference.isMarker|eServiceReference.isDirectory)):
81                                 self["menu"].list.insert(1, ChoiceEntryComponent(text = (_("set as startup service"), self.newStartUpServiceSelected)))
82                                 self["menu"].list.insert(2, ChoiceEntryComponent(text = (_("reset startup service"), self.resetStartUpService)))
83
84 def newStartUpServiceSelected(self):
85         current = self.csel.getCurrentSelection()
86         current_root = self.csel.getRoot()
87         if current.type == eServiceReference.idDVB and current.getData(0) in (2, 10):   
88                 config.startupservice.lastroot.value = "1:7:2:0:0:0:0:0:0:0:%s;" % (current_root.getPath())
89                 config.startupservice.lastmode.value = "radio"
90         else:
91                 config.startupservice.lastroot.value = "1:7:1:0:0:0:0:0:0:0:%s;" % (current_root.getPath())
92                 config.startupservice.lastmode.value = "tv"
93         config.startupservice.lastservice.value = current.toString()
94         config.startupservice.save()
95         self.close()
96
97 def resetStartUpService(self):
98         config.startupservice.lastroot.value = ""
99         config.startupservice.lastmode.value = "tv"
100         config.startupservice.lastservice.value = ""
101         config.startupservice.save()
102         self.close()
103
104 def Plugins(**kwargs):\r
105         return [PluginDescriptor(name="StartUpService", description="set startup service", where = PluginDescriptor.WHERE_SESSIONSTART, fnc=main)]
106