[EPGSearch] - some changes for searchfilter
[enigma2-plugins.git] / epgsearch / src / plugin.py
1 from enigma import eServiceCenter
2 from Components.config import config
3
4 # Plugin
5 from EPGSearch import EPGSearch, EPGSearchEPGSelection, searchEvent, pzyP4TInit, autoTimerAvailable
6 from EPGSearchFilter import searchEventWithFilter, openSearchFilterList
7
8 # Plugin definition
9 from Plugins.Plugin import PluginDescriptor
10
11 # Autostart
12 def autostart(reason, **kwargs):
13         if reason == 0:
14                 try:
15                         # for blue and audio key activating in EPG-Screens
16                         pzyP4TInit()
17                 except Exception:
18                         import traceback
19                         traceback.print_exc()
20
21 # Mainfunction
22 def main(session, *args, **kwargs):
23         s = session.nav.getCurrentService()
24         if s:
25                 info = s.info()
26                 event = info.getEvent(0) # 0 = now, 1 = next
27                 name = event and event.getEventName() or ''
28                 session.open(EPGSearch, name, config.plugins.epgsearch.add_history_onOpen.value)
29         else:
30                 session.open(EPGSearch)
31
32 # Event Info
33 def eventinfo(session, *args, **kwargs):
34         ref = session.nav.getCurrentlyPlayingServiceReference()
35         session.open(EPGSearchEPGSelection, ref, True)
36
37 # Movielist
38 def movielist(session, service, **kwargs):
39         serviceHandler = eServiceCenter.getInstance()
40         info = serviceHandler.info(service)
41         name = info and info.getName(service) or ''
42
43         session.open(EPGSearch, name, config.plugins.epgsearch.add_history_onOpen.value)
44
45 def Plugins(**kwargs):
46         l = [
47                 PluginDescriptor(
48                         name=_("Search EPG"),
49                         where = [PluginDescriptor.WHERE_EPG_SELECTION_SINGLE_BLUE, PluginDescriptor.WHERE_CHANNEL_SELECTION_RED, PluginDescriptor.WHERE_EVENTVIEW],
50                         fnc = searchEvent
51                 ),
52                 PluginDescriptor(
53                         where = PluginDescriptor.WHERE_AUTOSTART,
54                         fnc = autostart,
55                         needsRestart = False,
56                 ),
57                 PluginDescriptor(
58                         name = "EPGSearch",
59                         # TRANSLATORS: description of EPGSearch in PluginBrowser
60                         description = _("Search EPG"),
61                         where = PluginDescriptor.WHERE_PLUGINMENU,
62                         fnc = main,
63                         icon = "EPGSearch.png",
64                         needsRestart = False,
65                 ),
66                 PluginDescriptor(
67                         # TRANSLATORS: EPGSearch title in EventInfo dialog (requires the user to select an event to search for)
68                         name = _("search EPG..."),
69                         where = PluginDescriptor.WHERE_EVENTINFO,
70                         fnc = eventinfo,
71                         needsRestart = False,
72                 ),
73                 PluginDescriptor(
74                         # TRANSLATORS: EPGSearch title in MovieList (does not require further user interaction)
75                         description = _("search EPG"),
76                         where = PluginDescriptor.WHERE_MOVIELIST,
77                         fnc = movielist,
78                         needsRestart = False,
79                 ),
80         ]
81         
82         #add only if AutoTimer-Plugin is found
83         if autoTimerAvailable:
84                 l.append(PluginDescriptor(
85                         name=_("add search filter to EPGSearch"),
86                         where = [PluginDescriptor.WHERE_EPG_SELECTION_SINGLE_BLUE, PluginDescriptor.WHERE_CHANNEL_SELECTION_RED, PluginDescriptor.WHERE_EVENTVIEW],
87                         fnc = searchEventWithFilter
88                         ))
89                 l.append(PluginDescriptor(
90                         name=_("open EPGSearch filterlist"),
91                         where = [PluginDescriptor.WHERE_EPG_SELECTION_SINGLE_BLUE, PluginDescriptor.WHERE_CHANNEL_SELECTION_RED, PluginDescriptor.WHERE_EVENTVIEW],
92                         fnc = openSearchFilterList
93                         ))
94         
95         return l
96