updated EPGSearch (thx to Sven H)
[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,120" size="820,520">
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,350" enableWrapAround="1" scrollbarMode="showOnDemand"/>
26                 <eLabel position="10,420" size="800,1" backgroundColor="grey"/>
27                 <widget source="help" render="Label" position="10,430" 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, _("How many entries to keep in the search history at most. 0 disables history entirely!")) )
77                 self.list.append( getConfigListEntry(_("Add \"Search\" Button to EPG"), config.plugins.epgsearch.add_search_to_epg , _("If this setting is enabled, the plugin adds a \"Search\" Button to the regular EPG.")) )
78                 self.list.append( getConfigListEntry(_("Search type"), config.plugins.epgsearch.search_type, _("Select \"exact\" match to enforce \"Match title\" to match exactly, \"partial\" if you only want to search for a part of the event title or description or \"Ask user\"")) )
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. So you can filter the 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 most matched channelname in screen-title"), config.plugins.epgsearch.show_sname_in_title, _("Show the most matched channelname in the screen-title. So you have more place to show eventname 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         def getScopeChoicesDefault(self):
88                 scopeChoices_default = "all"
89
90                 for choice in self.scopeChoices:
91                         if config.plugins.epgsearch.search_scope.value == choice[0]:
92                                 scopeChoices_default = config.plugins.epgsearch.search_scope.value
93                                 break
94
95                 return scopeChoices_default
96
97         def getScopeChoices(self):
98                 #set config-values for bouquet-config
99                 config_scope_choices = [("all",_("all services")), ("current",_("current bouquet"))]
100
101                 #get bouquetlist
102                 infoBarInstance = InfoBar.instance
103                 if infoBarInstance is not None:
104                         bouquets = infoBarInstance.servicelist.getBouquetList()
105                         for bouquet in bouquets:
106                                 config_scope_choices.append((bouquet[1].toString(),bouquet[0]))
107
108                 return config_scope_choices
109
110         def keySave(self):
111                 self.saveAll()
112                 #config.plugins.epgsearch.search_current_bouquet.value = self.config_search_current_bouquet.value
113                 config.plugins.epgsearch.search_scope.value = self.config_search_scope.value
114                 config.plugins.epgsearch.save()
115                 self.close()
116
117         def changeConfig(self):
118                 self.list = []
119                 self.buildConfig()
120                 self["config"].setList(self.list)
121
122         def changed(self):
123                 for x in self.onChangedEntry:
124                         x()
125                 current = self["config"].getCurrent()[1]
126                 if (current == config.plugins.epgsearch.show_picon) or (current == self.config_search_scope):
127                         self.changeConfig()
128                         return
129
130         def setCustomTitle(self):
131                 self.setTitle(_("EPGSearch Setup"))
132
133         def updateHelp(self):
134                 cur = self["config"].getCurrent()
135                 if cur:
136                         self["help"].text = cur[2]
137
138         def getCurrentEntry(self):
139                 return self["config"].getCurrent()[0]
140
141         def getCurrentValue(self):
142                 return str(self["config"].getCurrent()[1].getText())
143
144         def createSummary(self):
145                 return SetupSummary