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