IMDb: fix single result
[enigma2-plugins.git] / epgsearch / src / EPGSearchSetup.py
1 # for localized messages
2 # GUI (Screens)
3 from Screens.Screen import Screen
4 from Components.ConfigList import ConfigListScreen
5 from Components.config import ConfigSelection, NoSave
6
7 # GUI (Summary)
8 from Screens.Setup import SetupSummary
9 from Screens.InfoBar import InfoBar
10
11 # GUI (Components)
12 from Components.ActionMap import ActionMap
13 from Components.Sources.StaticText import StaticText
14
15 # Configuration
16 from Components.config import config, getConfigListEntry
17
18 class EPGSearchSetup(Screen, ConfigListScreen):
19         skin = """<screen name="EPGSearchSetup" position="center,90" size="820,570">
20                 <ePixmap pixmap="skin_default/buttons/red.png" position="10,5" size="200,40"/>
21                 <ePixmap pixmap="skin_default/buttons/green.png" position="210,5" size="200,40"/>
22                 <widget source="key_red" render="Label" position="10,5" size="200,40" zPosition="1" font="Regular;20" halign="center" valign="center" backgroundColor="#9f1313" transparent="1" foregroundColor="white" shadowColor="black" shadowOffset="-2,-2"/>
23                 <widget source="key_green" render="Label" position="210,5" size="200,40" zPosition="1" font="Regular;20" halign="center" valign="center" backgroundColor="#1f771f" transparent="1" foregroundColor="white" shadowColor="black" shadowOffset="-2,-2"/>
24                 <eLabel position="10,50" size="800,1" backgroundColor="grey"/>
25                 <widget name="config" position="10,60" size="800,400" enableWrapAround="1" scrollbarMode="showOnDemand"/>
26                 <eLabel position="10,470" size="800,1" backgroundColor="grey"/>
27                 <widget source="help" render="Label" position="10,480" size="800,80" font="Regular;21" />
28                 </screen>"""
29
30         def __init__(self, session):
31                 Screen.__init__(self, session)
32
33                 # Summary
34                 self.setup_title = _("EPGSearch Setup")
35                 self.onChangedEntry = []
36
37                 #set config-values for search_scope-config
38                 self.scopeChoices = self.getScopeChoices()
39                 self.scopeChoices_default = self.getScopeChoicesDefault()
40                 self.config_search_scope = NoSave( ConfigSelection(choices=self.scopeChoices, default=self.scopeChoices_default) )
41
42                 self.list = []
43                 self.buildConfig()
44                 ConfigListScreen.__init__(self, self.list, session = session, on_change = self.changed)
45
46                 def selectionChanged():
47                         if self["config"].current:
48                                 self["config"].current[1].onDeselect(self.session)
49                         self["config"].current = self["config"].getCurrent()
50                         if self["config"].current:
51                                 self["config"].current[1].onSelect(self.session)
52                         for x in self["config"].onSelectionChanged:
53                                 x()
54                 self["config"].selectionChanged = selectionChanged
55                 self["config"].onSelectionChanged.append(self.updateHelp)
56
57                 # Initialize widgets
58                 self["key_green"] = StaticText(_("OK"))
59                 self["key_red"] = StaticText(_("Cancel"))
60                 self["help"] = StaticText()
61
62                 # Define Actions
63                 self["actions"] = ActionMap(["SetupActions"],
64                         {
65                                 "cancel": self.keyCancel,
66                                 "save": self.keySave,
67                         }
68                 )
69
70                 # Trigger change
71                 self.changed()
72
73                 self.onLayoutFinish.append(self.setCustomTitle)
74
75         def buildConfig(self):
76                 self.list.append( getConfigListEntry(_("Length of History"), config.plugins.epgsearch.history_length, _("Number of entries to retain in the search history at most. Set to 0 to disable history entirely.")) )
77                 self.list.append( getConfigListEntry(_("Add search text to history when opening plugin"), config.plugins.epgsearch.add_history_onOpen , _("Enable to add search text to history when opening the plugin.")) )
78                 self.list.append( getConfigListEntry(_("Search type"), config.plugins.epgsearch.search_type, _("Select \"exact match of title\" for a perfect match or \"partial match\" if you want to search for a part of the title or the description. Select \"Ask user\" to choose when searching.")) )
79                 self.list.append( getConfigListEntry(_("Search scope"), self.config_search_scope, _("Search will return only matches from services in the selected bouquet.")) )
80                 if self.config_search_scope.value != "all":
81                         self.list.append( getConfigListEntry(_("Show events"), config.plugins.epgsearch.show_events, _("Show 'all', 'current', 'future' or 'current & future' events. This allows filtering matches by the event time.")) )
82                 self.list.append( getConfigListEntry(_("Show Picons"), config.plugins.epgsearch.show_picon, _("Show the the picon of the channel instead of channelname. Use the picon path from the channelselection settings.")) )
83                 if not config.plugins.epgsearch.show_picon.value:
84                         self.list.append( getConfigListEntry(_("Show best matching channelname in screen title"), config.plugins.epgsearch.show_sname_in_title, _("Shows the best matching channelname in the screen title to have more space to display event name and short description.")) )
85                 self.list.append( getConfigListEntry(_("Show short description"), config.plugins.epgsearch.show_shortdesc, _("Add the short description of the event to the search result.")) )
86                 
87                 self.list.append(getConfigListEntry(_("BUTTONS"), )) 
88                 self.list.append( getConfigListEntry(_("Buttons for 'Search EPG'"), config.plugins.epgsearch.searchEPG_menu, _("Select the buttons, which show this menu item (on change GUI-restart is necessary).")) )
89                 self.list.append( getConfigListEntry(_("Buttons for 'open EPGSearch search list'"), config.plugins.epgsearch.openSearchFilter_menu, _("Select the buttons, which show this menu item (on change GUI-restart is necessary).")) )
90                 
91                 from EPGSearch import autoTimerAvailable
92                 if autoTimerAvailable:
93                         self.list.append( getConfigListEntry(_("Buttons for 'add search filter to EPGSearch'"), config.plugins.epgsearch.addSearchFilter_menu, _("Select the buttons, which show this menu item (on change GUI-restart is necessary).")) )
94                         self.list.append( getConfigListEntry(_("Blue button function (search list)"), config.plugins.epgsearch.blue_function, _("Select the search list to show on blue button in the EPGSearch match list (default = text search history and search filter list).")) )
95                         
96
97         def getScopeChoicesDefault(self):
98                 scopeChoices_default = "all"
99
100                 for choice in self.scopeChoices:
101                         if config.plugins.epgsearch.search_scope.value == choice[0]:
102                                 scopeChoices_default = config.plugins.epgsearch.search_scope.value
103                                 break
104
105                 return scopeChoices_default
106
107         def getScopeChoices(self):
108                 #set config-values for bouquet-config
109                 config_scope_choices = [("all",_("all services")), ("current",_("current bouquet"))]
110
111                 #get bouquetlist
112                 infoBarInstance = InfoBar.instance
113                 if infoBarInstance is not None:
114                         bouquets = infoBarInstance.servicelist.getBouquetList()
115                         for bouquet in bouquets:
116                                 config_scope_choices.append((bouquet[1].toString(),bouquet[0]))
117
118                 return config_scope_choices
119
120         def keySave(self):
121                 self.saveAll()
122                 #config.plugins.epgsearch.search_current_bouquet.value = self.config_search_current_bouquet.value
123                 config.plugins.epgsearch.search_scope.value = self.config_search_scope.value
124                 config.plugins.epgsearch.save()
125                 self.close()
126
127         def changeConfig(self):
128                 self.list = []
129                 self.buildConfig()
130                 self["config"].setList(self.list)
131
132         def changed(self):
133                 for x in self.onChangedEntry:
134                         x()
135                 current = self["config"].getCurrent()[1]
136                 if (current == config.plugins.epgsearch.show_picon) or (current == self.config_search_scope):
137                         self.changeConfig()
138                         return
139
140         def setCustomTitle(self):
141                 self.setTitle(_("EPGSearch Setup"))
142
143         def updateHelp(self):
144                 cur = self["config"].getCurrent()
145                 if cur:
146                         self["help"].text = cur[2]
147
148         def getCurrentEntry(self):
149                 return self["config"].getCurrent()[0]
150
151         def getCurrentValue(self):
152                 return str(self["config"].getCurrent()[1].getText())
153
154         def createSummary(self):
155                 return SetupSummary