Fix unintended induced whitespaces
[openblackhole/openblackhole-enigma2.git] / lib / python / Screens / Hotkey.py
1 from Components.ActionMap import ActionMap, HelpableActionMap, NumberActionMap
2 from Components.Button import Button
3 from Components.ChoiceList import ChoiceList, ChoiceEntryComponent
4 from Components.SystemInfo import SystemInfo
5 from Components.config import config, ConfigSubsection, ConfigText, ConfigYesNo
6 from Components.PluginComponent import plugins
7 from Screens.ChoiceBox import ChoiceBox
8 from Screens.Screen import Screen
9 from Screens.MessageBox import MessageBox
10 from Plugins.Plugin import PluginDescriptor
11 from Tools.BoundFunction import boundFunction
12 from ServiceReference import ServiceReference
13 from enigma import eServiceReference
14 import os
15
16 def getHotkeys():
17         return [(_("Red") + " " + _("long"), "red_long", ""),
18                 (_("Green") + " " + _("long"), "green_long", ""),
19                 (_("Yellow") + " " + _("long"), "yellow_long", ""),
20                 (_("Blue") + " " + _("long"), "blue_long", "Plugins/PLi/SoftcamSetup/1"),
21                 ("F1/LAN", "f1", ""),
22                 ("F1" + " " + _("long"), "f1_long", ""),
23                 ("F2", "f2", ""),
24                 ("F2" + " " + _("long"), "f2_long", ""),
25                 ("F3", "f3", ""),
26                 ("F3" + " " + _("long"), "f3_long", ""),
27                 (_("Red"), "red", ""),
28                 (_("Green"), "green", ""),
29                 (_("Yellow"), "yellow", ""),
30                 (_("Blue"), "blue", ""),
31                 ("Rec", "rec", ""),
32                 ("Radio", "radio", ""),
33                 ("Radio" + " " + _("long"), "radio_long", ""),
34                 ("TV", "showTv", ""),
35                 ("TV" + " " + _("long"), "showTv_long", SystemInfo["LcdLiveTV"] and "Infobar/ToggleLCDLiveTV" or ""),
36                 ("Teletext", "text", ""),
37                 ("Help", "displayHelp", ""),
38                 ("Help" + " " + _("long"), "displayHelp_long", ""),
39                 ("Subtitle", "subtitle", ""),
40                 ("Menu", "mainMenu", ""),
41                 ("Info (EPG)", "info", "Infobar/openEventView"),
42                 ("Info (EPG)" + " " + _("long"), "info_long", "Infobar/showEventInfoPlugins"),
43                 ("List/Fav/PVR", "list", ""),
44                 ("Back/Recall", "back", ""),
45                 ("Back/Recall" + " " + _("long"), "back_long", ""),
46                 ("End", "end", ""),
47                 ("Epg/Guide", "epg", "Plugins/Extensions/GraphMultiEPG/1"),
48                 ("Epg/Guide" + " " + _("long"), "epg_long", "Infobar/showEventInfoPlugins"),
49                 ("Left", "cross_left", ""),
50                 ("Right", "cross_right", ""),
51                 ("Up", "cross_up", ""),
52                 ("Down", "cross_down", ""),
53                 ("Ok", "ok", ""),
54                 ("Channel up", "channelup", ""),
55                 ("Channel down", "channeldown", ""),
56                 ("Next", "next", ""),
57                 ("Previous", "previous", ""),
58                 ("Audio", "audio", ""),
59                 ("Play", "play", ""),
60                 ("Playpause", "playpause", ""),
61                 ("Stop", "stop", ""),
62                 ("Pause", "pause", ""),
63                 ("Rewind", "rewind", ""),
64                 ("Fastforward", "fastforward", ""),
65                 ("Skip back", "skip_back", ""),
66                 ("Skip forward", "skip_forward", ""),
67                 ("activatePiP", "activatePiP", ""),
68                 ("Timer", "timer", ""),
69                 ("Timer" + " " + _("long"), "timer_long", ""),
70                 ("Playlist", "playlist", ""),
71                 ("Timeshift", "timeshift", ""),
72                 ("Search", "search", ""),
73                 ("Search" + " " + _("long"), "search_long", ""),
74                 ("Slow", "slow", ""),
75                 ("Mark/Portal/Playlist", "mark", ""),
76                 ("Mark/Portal/Playlist" + " " + _("long"), "mark_long", ""),
77                 ("Sleep", "sleep", ""),
78                 ("Sleep" + " " + _("long"), "sleep_long", ""),
79                 ("Context", "contextmenu", ""),
80                 ("Context" + " " + _("long"), "contextmenu_long", ""),
81                 ("Video Mode", "vmode", ""),
82                 ("Video Mode" + " " + _("long"), "vmode_long", ""),
83                 ("Home", "home", ""),
84                 ("Power", "power", ""),
85                 ("Power" + " " + _("long"), "power_long", ""),
86                 ("HDMIin", "HDMIin", "Infobar/HDMIIn"),
87                 ("HDMIin" + " " + _("long"), "HDMIin_long", "")]
88
89 config.misc.hotkey = ConfigSubsection()
90 config.misc.hotkey.additional_keys = ConfigYesNo(default=False)
91 for x in getHotkeys():
92         exec "config.misc.hotkey." + x[1] + " = ConfigText(default='" + x[2] + "')"
93
94 def getHotkeyFunctions():
95         hotkeyFunctions = []
96         twinPlugins = []
97         twinPaths = {}
98         pluginlist = plugins.getPlugins(PluginDescriptor.WHERE_EVENTINFO)
99         pluginlist.sort(key=lambda p: p.name)
100         for plugin in pluginlist:
101                 if plugin.name not in twinPlugins and plugin.path and 'selectedevent' not in plugin.__call__.func_code.co_varnames:
102                         if twinPaths.has_key(plugin.path[24:]):
103                                 twinPaths[plugin.path[24:]] += 1
104                         else:
105                                 twinPaths[plugin.path[24:]] = 1
106                         hotkeyFunctions.append((plugin.name, plugin.path[24:] + "/" + str(twinPaths[plugin.path[24:]]) , "EPG"))
107                         twinPlugins.append(plugin.name)
108         pluginlist = plugins.getPlugins([PluginDescriptor.WHERE_PLUGINMENU, PluginDescriptor.WHERE_EXTENSIONSMENU])
109         pluginlist.sort(key=lambda p: p.name)
110         for plugin in pluginlist:
111                 if plugin.name not in twinPlugins and plugin.path:
112                         if twinPaths.has_key(plugin.path[24:]):
113                                 twinPaths[plugin.path[24:]] += 1
114                         else:
115                                 twinPaths[plugin.path[24:]] = 1
116                         hotkeyFunctions.append((plugin.name, plugin.path[24:] + "/" + str(twinPaths[plugin.path[24:]]) , "Plugins"))
117                         twinPlugins.append(plugin.name)
118         hotkeyFunctions.append((_("Main menu"), "Infobar/mainMenu", "InfoBar"))
119         hotkeyFunctions.append((_("Show help"), "Infobar/showHelp", "InfoBar"))
120         hotkeyFunctions.append((_("Show extension selection"), "Infobar/showExtensionSelection", "InfoBar"))
121         hotkeyFunctions.append((_("Zap down"), "Infobar/zapDown", "InfoBar"))
122         hotkeyFunctions.append((_("Zap up"), "Infobar/zapUp", "InfoBar"))
123         hotkeyFunctions.append((_("Switch channel up"), "Infobar/switchChannelUp", "InfoBar"))
124         hotkeyFunctions.append((_("Switch channel down"), "Infobar/switchChannelDown", "InfoBar"))
125         hotkeyFunctions.append((_("Show service list"), "Infobar/openServiceList", "InfoBar"))
126         hotkeyFunctions.append((_("Show movies"), "Infobar/showMovies", "InfoBar"))
127         hotkeyFunctions.append((_("Show servicelist or movies"), "Infobar/showServiceListOrMovies", "InfoBar"))
128         hotkeyFunctions.append((_("Show favourites list"), "Infobar/openFavouritesList", "InfoBar"))
129         hotkeyFunctions.append((_("History back"), "Infobar/historyBack", "InfoBar"))
130         hotkeyFunctions.append((_("History next"), "Infobar/historyNext", "InfoBar"))
131         hotkeyFunctions.append((_("Recall to previous service"), "Infobar/servicelist/recallPrevService", "InfoBar"))
132         hotkeyFunctions.append((_("Show eventinfo plugins"), "Infobar/showEventInfoPlugins", "EPG"))
133         hotkeyFunctions.append((_("Show event details"), "Infobar/openEventView", "EPG"))
134         hotkeyFunctions.append((_("Show single service EPG"), "Infobar/openSingleServiceEPG", "EPG"))
135         hotkeyFunctions.append((_("Show multi channel EPG"), "Infobar/openMultiServiceEPG", "EPG"))
136         hotkeyFunctions.append((_("Show Audioselection"), "Infobar/audioSelection", "InfoBar"))
137         hotkeyFunctions.append((_("Switch to radio mode"), "Infobar/showRadio", "InfoBar"))
138         hotkeyFunctions.append((_("Switch to TV mode"), "Infobar/showTv", "InfoBar"))
139         hotkeyFunctions.append((_("Instant record"), "Infobar/instantRecord", "InfoBar"))
140         hotkeyFunctions.append((_("Start instant recording"), "Infobar/startInstantRecording", "InfoBar"))
141         hotkeyFunctions.append((_("Activate timeshift End"), "Infobar/activateTimeshiftEnd", "InfoBar"))
142         hotkeyFunctions.append((_("Activate timeshift end and pause"), "Infobar/activateTimeshiftEndAndPause", "InfoBar"))
143         hotkeyFunctions.append((_("Start timeshift"), "Infobar/startTimeshift", "InfoBar"))
144         hotkeyFunctions.append((_("Stop timeshift"), "Infobar/stopTimeshift", "InfoBar"))
145         hotkeyFunctions.append((_("Start teletext"), "Infobar/startTeletext", "InfoBar"))
146         hotkeyFunctions.append((_("Show subservice selection"), "Infobar/subserviceSelection", "InfoBar"))
147         hotkeyFunctions.append((_("Show subtitle selection"), "Infobar/subtitleSelection", "InfoBar"))
148         hotkeyFunctions.append((_("Show InfoBar"), "Infobar/showFirstInfoBar", "InfoBar"))
149         hotkeyFunctions.append((_("Show second InfoBar"), "Infobar/showSecondInfoBar", "InfoBar"))
150         hotkeyFunctions.append((_("Toggle infoBar"), "Infobar/toggleShow", "InfoBar"))
151         hotkeyFunctions.append((_("Letterbox zoom"), "Infobar/vmodeSelection", "InfoBar"))
152         if SystemInfo["PIPAvailable"]:
153                 hotkeyFunctions.append((_("Show PIP"), "Infobar/showPiP", "InfoBar"))
154                 hotkeyFunctions.append((_("Swap PIP"), "Infobar/swapPiP", "InfoBar"))
155                 hotkeyFunctions.append((_("Move PIP"), "Infobar/movePiP", "InfoBar"))
156                 hotkeyFunctions.append((_("Toggle PIPzap"), "Infobar/togglePipzap", "InfoBar"))
157         hotkeyFunctions.append((_("Activate HbbTV (Redbutton)"), "Infobar/activateRedButton", "InfoBar"))
158         hotkeyFunctions.append((_("Toggle HDMI In"), "Infobar/HDMIIn", "InfoBar"))
159         if SystemInfo["LcdLiveTV"]:
160                 hotkeyFunctions.append((_("Toggle LCD LiveTV"), "Infobar/ToggleLCDLiveTV", "InfoBar"))
161         hotkeyFunctions.append((_("Do nothing"), "Void", "InfoBar"))
162         hotkeyFunctions.append((_("HotKey Setup"), "Module/Screens.Hotkey/HotkeySetup", "Setup"))
163         hotkeyFunctions.append((_("Software update"), "Module/Screens.SoftwareUpdate/UpdatePlugin", "Setup"))
164         hotkeyFunctions.append((_("Latest Commits"), "Module/Screens.About/CommitInfo", "Setup"))
165         hotkeyFunctions.append((_("CI (Common Interface) Setup"), "Module/Screens.Ci/CiSelection", "Setup"))
166         hotkeyFunctions.append((_("Tuner Configuration"), "Module/Screens.Satconfig/NimSelection", "Scanning"))
167         hotkeyFunctions.append((_("Manual Scan"), "Module/Screens.ScanSetup/ScanSetup", "Scanning"))
168         hotkeyFunctions.append((_("Automatic Scan"), "Module/Screens.ScanSetup/ScanSimple", "Scanning"))
169         for plugin in plugins.getPluginsForMenu("scan"):
170                 hotkeyFunctions.append((plugin[0], "MenuPlugin/scan/" + plugin[2], "Scanning"))
171         hotkeyFunctions.append((_("Network"), "Module/Screens.NetworkSetup/NetworkAdapterSelection", "Setup"))
172         hotkeyFunctions.append((_("Plugin Browser"), "Module/Screens.PluginBrowser/PluginBrowser", "Setup"))
173         hotkeyFunctions.append((_("Sleeptimer edit"), "Module/Screens.SleepTimerEdit/SleepTimerEdit", "Setup"))
174         hotkeyFunctions.append((_("Channel Info"), "Module/Screens.ServiceInfo/ServiceInfo", "Setup"))
175         hotkeyFunctions.append((_("Timer"), "Module/Screens.TimerEdit/TimerEditList", "Setup"))
176         for plugin in plugins.getPluginsForMenu("system"):
177                 if plugin[2]:
178                         hotkeyFunctions.append((plugin[0], "MenuPlugin/system/" + plugin[2], "Setup"))
179         hotkeyFunctions.append((_("Standby"), "Module/Screens.Standby/Standby", "Power"))
180         hotkeyFunctions.append((_("Restart"), "Module/Screens.Standby/TryQuitMainloop/2", "Power"))
181         hotkeyFunctions.append((_("Restart enigma"), "Module/Screens.Standby/TryQuitMainloop/3", "Power"))
182         hotkeyFunctions.append((_("Deep standby"), "Module/Screens.Standby/TryQuitMainloop/1", "Power"))
183         hotkeyFunctions.append((_("Usage Setup"), "Setup/usage", "Setup"))
184         hotkeyFunctions.append((_("User interface"), "Setup/userinterface", "Setup"))
185         hotkeyFunctions.append((_("Recording Setup"), "Setup/recording", "Setup"))
186         hotkeyFunctions.append((_("Harddisk Setup"), "Setup/harddisk", "Setup"))
187         hotkeyFunctions.append((_("Subtitles Settings"), "Setup/subtitlesetup", "Setup"))
188         hotkeyFunctions.append((_("Language"), "Module/Screens.LanguageSelection/LanguageSelection", "Setup"))
189         hotkeyFunctions.append((_("Skin setup"), "Module/Screens.SkinSelector/SkinSelector", "Setup"))
190         hotkeyFunctions.append((_("Memory Info"), "Module/Screens.About/MemoryInfo", "Setup"))
191         if os.path.isdir("/etc/ppanels"):
192                 for x in [x for x in os.listdir("/etc/ppanels") if x.endswith(".xml")]:
193                         x = x[:-4]
194                         hotkeyFunctions.append((_("PPanel") + " " + x, "PPanel/" + x, "PPanels"))
195         if os.path.isdir("/usr/script"):
196                 for x in [x for x in os.listdir("/usr/script") if x.endswith(".sh")]:
197                         x = x[:-3]
198                         hotkeyFunctions.append((_("Shellscript") + " " + x, "Shellscript/" + x, "Shellscripts"))
199         return hotkeyFunctions
200
201 class HotkeySetup(Screen):
202         def __init__(self, session, args=None):
203                 Screen.__init__(self, session)
204                 self.session = session
205                 self.setTitle(_("Hotkey Setup"))
206                 self["key_red"] = Button(_("Exit"))
207                 self["key_green"] = Button(_("Toggle Extra Keys"))
208                 self.list = []
209                 self.hotkeys = getHotkeys()
210                 self.hotkeyFunctions = getHotkeyFunctions()
211                 for x in self.hotkeys:
212                         self.list.append(ChoiceEntryComponent('',(x[0], x[1])))
213                 self["list"] = ChoiceList(list=self.list[:config.misc.hotkey.additional_keys.value and len(self.hotkeys) or 10], selection = 0)
214                 self["choosen"] = ChoiceList(list=[])
215                 self["actions"] = ActionMap(["OkCancelActions", "ColorActions", "DirectionActions", "MenuActions"],
216                 {
217                         "ok": self.keyOk,
218                         "cancel": self.close,
219                         "red": self.close,
220                         "green": self.toggleAdditionalKeys,
221                         "up": self.keyUp,
222                         "down": self.keyDown,
223                         "left": self.keyLeft,
224                         "right": self.keyRight,
225                         "menu": boundFunction(self.close, True),
226                 }, -1)
227                 self["NumberActions"] = NumberActionMap(["NumberActions"],
228                 {
229                         "0": self.keyNumberGlobal
230                 })
231                 self["HotkeyButtonActions"] = hotkeyActionMap(["HotkeyActions"], dict((x[1], self.hotkeyGlobal) for x in self.hotkeys))
232                 self.longkeyPressed = False
233                 self.onLayoutFinish.append(self.__layoutFinished)
234                 self.onExecBegin.append(self.getFunctions)
235
236         def __layoutFinished(self):
237                 self["choosen"].selectionEnabled(0)
238
239         def hotkeyGlobal(self, key):
240                 if self.longkeyPressed:
241                         self.longkeyPressed = False
242                 else:
243                         index = 0
244                         for x in self.list[:config.misc.hotkey.additional_keys.value and len(self.hotkeys) or 10]:
245                                 if key == x[0][1]:
246                                         self["list"].moveToIndex(index)
247                                         if key.endswith("_long"):
248                                                 self.longkeyPressed = True
249                                         break
250                                 index += 1
251                         self.getFunctions()
252
253         def keyOk(self):
254                 self.session.openWithCallback(self.HotkeySetupSelectCallback, HotkeySetupSelect, self["list"].l.getCurrentSelection())
255
256         def HotkeySetupSelectCallback(self, answer):
257                 if answer:
258                         self.close(True)
259
260         def keyLeft(self):
261                 self["list"].instance.moveSelection(self["list"].instance.pageUp)
262                 self.getFunctions()
263
264         def keyRight(self):
265                 self["list"].instance.moveSelection(self["list"].instance.pageDown)
266                 self.getFunctions()
267
268         def keyUp(self):
269                 self["list"].instance.moveSelection(self["list"].instance.moveUp)
270                 self.getFunctions()
271
272         def keyDown(self):
273                 self["list"].instance.moveSelection(self["list"].instance.moveDown)
274                 self.getFunctions()
275
276         def setDefaultHotkey(self, answer):
277                 if answer:
278                         for x in getHotkeys():
279                                 current_config = eval("config.misc.hotkey." + x[1])
280                                 current_config.value = str(x[2])
281                                 current_config.save()
282                         self.getFunctions()
283
284         def keyNumberGlobal(self, number):
285                 self.session.openWithCallback(self.setDefaultHotkey, MessageBox, _("Set all hotkey to default?"), MessageBox.TYPE_YESNO)
286
287         def toggleAdditionalKeys(self):
288                 config.misc.hotkey.additional_keys.value = not config.misc.hotkey.additional_keys.value
289                 config.misc.hotkey.additional_keys.save()
290                 self["list"].setList(self.list[:config.misc.hotkey.additional_keys.value and len(self.hotkeys) or 10])
291
292         def getFunctions(self):
293                 key = self["list"].l.getCurrentSelection()[0][1]
294                 if key:
295                         selected = []
296                         for x in eval("config.misc.hotkey." + key + ".value.split(',')"):
297                                 if x.startswith("ZapPanic"):
298                                         selected.append(ChoiceEntryComponent('',((_("Panic to") + " " + ServiceReference(eServiceReference(x.split("/", 1)[1]).toString()).getServiceName()), x)))
299                                 elif x.startswith("Zap"):
300                                         selected.append(ChoiceEntryComponent('',((_("Zap to") + " " + ServiceReference(eServiceReference(x.split("/", 1)[1]).toString()).getServiceName()), x)))
301                                 else:
302                                         function = list(function for function in self.hotkeyFunctions if function[1] == x )
303                                         if function:
304                                                 selected.append(ChoiceEntryComponent('',((function[0][0]), function[0][1])))
305                         self["choosen"].setList(selected)
306
307 class HotkeySetupSelect(Screen):
308         def __init__(self, session, key, args=None):
309                 Screen.__init__(self, session)
310                 self.skinName="HotkeySetup"
311                 self.session = session
312                 self.key = key
313                 self.setTitle(_("Hotkey Setup") + " " + key[0][0])
314                 self["key_red"] = Button(_("Cancel"))
315                 self["key_green"] = Button(_("Save"))
316                 self.mode = "list"
317                 self.hotkeyFunctions = getHotkeyFunctions()
318                 self.config = eval("config.misc.hotkey." + key[0][1])
319                 self.expanded = []
320                 self.selected = []
321                 for x in self.config.value.split(','):
322                         if x.startswith("ZapPanic"):
323                                 self.selected.append(ChoiceEntryComponent('',((_("Panic to") + " " + ServiceReference(eServiceReference(x.split("/", 1)[1]).toString()).getServiceName()), x)))
324                         elif x.startswith("Zap"):
325                                 self.selected.append(ChoiceEntryComponent('',((_("Zap to") + " " + ServiceReference(eServiceReference(x.split("/", 1)[1]).toString()).getServiceName()), x)))
326                         else:
327                                 function = list(function for function in self.hotkeyFunctions if function[1] == x )
328                                 if function:
329                                         self.selected.append(ChoiceEntryComponent('',((function[0][0]), function[0][1])))
330                 self.prevselected = self.selected[:]
331                 self["choosen"] = ChoiceList(list=self.selected, selection=0)
332                 self["list"] = ChoiceList(list=self.getFunctionList(), selection=0)
333                 self["actions"] = ActionMap(["OkCancelActions", "ColorActions", "DirectionActions", "KeyboardInputActions", "MenuActions"],
334                 {
335                         "ok": self.keyOk,
336                         "cancel": self.cancel,
337                         "red": self.cancel,
338                         "green": self.save,
339                         "up": self.keyUp,
340                         "down": self.keyDown,
341                         "left": self.keyLeft,
342                         "right": self.keyRight,
343                         "upRepeated": self.keyUp,
344                         "downRepeated": self.keyDown,
345                         "leftRepeated": self.keyLeft,
346                         "rightRepeated": self.keyRight,
347                         "pageUp": self.toggleMode,
348                         "pageDown": self.toggleMode,
349                         "moveUp": self.moveUp,
350                         "moveDown": self.moveDown,
351                         "menu": boundFunction(self.close, True),
352                 }, -1)
353                 self.onLayoutFinish.append(self.__layoutFinished)
354
355         def __layoutFinished(self):
356                 self["choosen"].selectionEnabled(0)
357
358         def getFunctionList(self):
359                 functionslist = []
360                 catagories = {}
361                 for function in self.hotkeyFunctions:
362                         if not catagories.has_key(function[2]):
363                                 catagories[function[2]] = []
364                         catagories[function[2]].append(function)
365                 for catagorie in sorted(list(catagories)):
366                         if catagorie in self.expanded:
367                                 functionslist.append(ChoiceEntryComponent('expanded',((catagorie), "Expander")))
368                                 for function in catagories[catagorie]:
369                                         functionslist.append(ChoiceEntryComponent('verticalline',((function[0]), function[1])))
370                                 if catagorie == "InfoBar":
371                                         functionslist.append(ChoiceEntryComponent('verticalline',((_("Zap to")), "Zap")))
372                                         functionslist.append(ChoiceEntryComponent('verticalline',((_("Panic to")), "ZapPanic")))
373                         else:
374                                 functionslist.append(ChoiceEntryComponent('expandable',((catagorie), "Expander")))
375                 return functionslist
376
377         def toggleMode(self):
378                 if self.mode == "list" and self.selected:
379                         self.mode = "choosen"
380                         self["choosen"].selectionEnabled(1)
381                         self["list"].selectionEnabled(0)
382                 elif self.mode == "choosen":
383                         self.mode = "list"
384                         self["choosen"].selectionEnabled(0)
385                         self["list"].selectionEnabled(1)
386
387         def keyOk(self):
388                 if self.mode == "list":
389                         currentSelected = self["list"].l.getCurrentSelection()
390                         if currentSelected[0][1] == "Expander":
391                                 if currentSelected[0][0] in self.expanded:
392                                         self.expanded.remove(currentSelected[0][0])
393                                 else:
394                                         self.expanded.append(currentSelected[0][0])
395                                 self["list"].setList(self.getFunctionList())
396                         else:
397                                 if currentSelected[:2] in self.selected:
398                                         self.selected.remove(currentSelected[:2])
399                                 else:
400                                         if currentSelected[0][1].startswith("ZapPanic"):
401                                                 from Screens.ChannelSelection import SimpleChannelSelection
402                                                 self.session.openWithCallback(self.zaptoCallback, SimpleChannelSelection, _("Hotkey Panic") + " " + self.key[0][0], currentBouquet=True)
403                                         elif currentSelected[0][1].startswith("Zap"):
404                                                 from Screens.ChannelSelection import SimpleChannelSelection
405                                                 self.session.openWithCallback(self.zaptoCallback, SimpleChannelSelection, _("Hotkey zap") + " " + self.key[0][0], currentBouquet=True)
406                                         else:
407                                                 self.selected.append(currentSelected[:2])
408                 elif self.selected:
409                         self.selected.remove(self["choosen"].l.getCurrentSelection())
410                         if not self.selected:
411                                 self.toggleMode()
412                 self["choosen"].setList(self.selected)
413
414         def zaptoCallback(self, *args):
415                 if args:
416                         currentSelected = self["list"].l.getCurrentSelection()[:]
417                         currentSelected[1]=currentSelected[1][:-1] + (currentSelected[0][0] + " " + ServiceReference(args[0]).getServiceName(),)
418                         self.selected.append([(currentSelected[0][0], currentSelected[0][1] + "/" + args[0].toString()), currentSelected[1]])
419
420         def keyLeft(self):
421                 self[self.mode].instance.moveSelection(self[self.mode].instance.pageUp)
422
423         def keyRight(self):
424                 self[self.mode].instance.moveSelection(self[self.mode].instance.pageDown)
425
426         def keyUp(self):
427                 self[self.mode].instance.moveSelection(self[self.mode].instance.moveUp)
428
429         def keyDown(self):
430                 self[self.mode].instance.moveSelection(self[self.mode].instance.moveDown)
431
432         def moveUp(self):
433                 self.moveChoosen(self.keyUp)
434
435         def moveDown(self):
436                 self.moveChoosen(self.keyDown)
437
438         def moveChoosen(self, direction):
439                 if self.mode == "choosen":
440                         currentIndex = self["choosen"].getSelectionIndex()
441                         swapIndex = (currentIndex + (direction == self.keyDown and 1 or -1)) % len(self["choosen"].list)
442                         self["choosen"].list[currentIndex], self["choosen"].list[swapIndex] = self["choosen"].list[swapIndex], self["choosen"].list[currentIndex]
443                         self["choosen"].setList(self["choosen"].list)
444                         direction()
445                 else:
446                         return 0
447
448         def save(self):
449                 configValue = []
450                 for x in self.selected:
451                         configValue.append(x[0][1])
452                 self.config.value = ",".join(configValue)
453                 self.config.save()
454                 self.close(False)
455
456         def cancel(self):
457                 if self.selected != self.prevselected:
458                         self.session.openWithCallback(self.cancelCallback, MessageBox, _("are you sure to cancel all changes"), default=False)
459                 else:
460                         self.close(None)
461
462         def cancelCallback(self, answer):
463                 answer and self.close(None)
464
465 class hotkeyActionMap(ActionMap):
466         def action(self, contexts, action):
467                 if (action in tuple(x[1] for x in getHotkeys()) and self.actions.has_key(action)):
468                         res = self.actions[action](action)
469                         if res is not None:
470                                 return res
471                         return 1
472                 else:
473                         return ActionMap.action(self, contexts, action)
474
475 class helpableHotkeyActionMap(HelpableActionMap):
476         def action(self, contexts, action):
477                 if (action in tuple(x[1] for x in getHotkeys()) and self.actions.has_key(action)):
478                         res = self.actions[action](action)
479                         if res is not None:
480                                 return res
481                         return 1
482                 else:
483                         return ActionMap.action(self, contexts, action)
484
485 class InfoBarHotkey():
486         def __init__(self):
487                 self.hotkeys = getHotkeys()
488                 self["HotkeyButtonActions"] = helpableHotkeyActionMap(self, "HotkeyActions",
489                         dict((x[1],(self.hotkeyGlobal, boundFunction(self.getHelpText, x[1]))) for x in self.hotkeys), -10)
490                 self.onExecBegin.append(self.clearLongkeyPressed)
491
492         def clearLongkeyPressed(self):
493                 self.longkeyPressed = False
494
495         def getKeyFunctions(self, key):
496                 if key in ("play", "playpause", "Stop", "stop", "pause", "rewind", "next", "previous", "fastforward", "skip_back", "skip_forward") and (self.__class__.__name__ == "MoviePlayer" or hasattr(self, "timeshiftActivated") and self.timeshiftActivated()):
497                         return False
498                 selection = eval("config.misc.hotkey." + key + ".value.split(',')")
499                 selected = []
500                 for x in selection:
501                         if x.startswith("ZapPanic"):
502                                 selected.append(((_("Panic to") + " " + ServiceReference(eServiceReference(x.split("/", 1)[1]).toString()).getServiceName()), x))
503                         elif x.startswith("Zap"):
504                                 selected.append(((_("Zap to") + " " + ServiceReference(eServiceReference(x.split("/", 1)[1]).toString()).getServiceName()), x))
505                         else:
506                                 function = list(function for function in getHotkeyFunctions() if function[1] == x )
507                                 if function:
508                                         selected.append(function[0])
509                 return selected
510
511         def getHelpText(self, key):
512                 selected = self.getKeyFunctions(key)
513                 if not selected:
514                         return
515                 if len(selected) == 1:
516                         return selected[0][0]
517                 else:
518                         return _("Hotkey") + " " + tuple(x[0] for x in self.hotkeys if x[1] == key)[0]
519
520         def hotkeyGlobal(self, key):
521                 if self.longkeyPressed:
522                         self.longkeyPressed = False
523                 else:
524                         selected = self.getKeyFunctions(key)
525                         if not selected:
526                                 return 0
527                         elif len(selected) == 1:
528                                 self.longkeyPressed = key.endswith("_long")
529                                 return self.execHotkey(selected[0])
530                         else:
531                                 key = tuple(x[0] for x in self.hotkeys if x[1] == key)[0]
532                                 self.session.openWithCallback(self.execHotkey, ChoiceBox, _("Hotkey") + " " + key, selected)
533
534         def execHotkey(self, selected):
535                 if selected:
536                         selected = selected[1].split("/")
537                         if selected[0] == "Plugins":
538                                 twinPlugins = []
539                                 twinPaths = {}
540                                 pluginlist = plugins.getPlugins(PluginDescriptor.WHERE_EVENTINFO)
541                                 pluginlist.sort(key=lambda p: p.name)
542                                 for plugin in pluginlist:
543                                         if plugin.name not in twinPlugins and plugin.path and 'selectedevent' not in plugin.__call__.func_code.co_varnames:
544                                                 if twinPaths.has_key(plugin.path[24:]):
545                                                         twinPaths[plugin.path[24:]] += 1
546                                                 else:
547                                                         twinPaths[plugin.path[24:]] = 1
548                                                 if plugin.path[24:] + "/" + str(twinPaths[plugin.path[24:]]) == "/".join(selected):
549                                                         self.runPlugin(plugin)
550                                                         return
551                                                 twinPlugins.append(plugin.name)
552                                 pluginlist = plugins.getPlugins([PluginDescriptor.WHERE_PLUGINMENU, PluginDescriptor.WHERE_EXTENSIONSMENU])
553                                 pluginlist.sort(key=lambda p: p.name)
554                                 for plugin in pluginlist:
555                                         if plugin.name not in twinPlugins and plugin.path:
556                                                 if twinPaths.has_key(plugin.path[24:]):
557                                                         twinPaths[plugin.path[24:]] += 1
558                                                 else:
559                                                         twinPaths[plugin.path[24:]] = 1
560                                                 if plugin.path[24:] + "/" + str(twinPaths[plugin.path[24:]]) == "/".join(selected):
561                                                         self.runPlugin(plugin)
562                                                         return
563                                                 twinPlugins.append(plugin.name)
564                         elif selected[0] == "MenuPlugin":
565                                 for plugin in plugins.getPluginsForMenu(selected[1]):
566                                         if plugin[2] == selected[2]:
567                                                 self.runPlugin(plugin[1])
568                                                 return
569                         elif selected[0] == "Infobar":
570                                 if hasattr(self, selected[1]):
571                                         exec "self." + ".".join(selected[1:]) + "()"
572                                 else:
573                                         return 0
574                         elif selected[0] == "Module":
575                                 try:
576                                         exec "from " + selected[1] + " import *"
577                                         exec "self.session.open(" + ",".join(selected[2:]) + ")"
578                                 except:
579                                         print "[Hotkey] error during executing module %s, screen %s" % (selected[1], selected[2])
580                         elif selected[0] == "Setup":
581                                 exec "from Screens.Setup import *"
582                                 exec "self.session.open(Setup, \"" + selected[1] + "\")"
583                         elif selected[0].startswith("Zap"):
584                                 if selected[0] == "ZapPanic":
585                                         self.servicelist.history = []
586                                         self.pipShown() and self.showPiP()
587                                 self.servicelist.servicelist.setCurrent(eServiceReference("/".join(selected[1:])))
588                                 self.servicelist.zap(enable_pipzap = True)
589                                 if hasattr(self, "lastservice"):
590                                         self.lastservice = eServiceReference("/".join(selected[1:]))
591                                         self.close()
592                                 else:
593                                         self.show()
594                                 from Screens.MovieSelection import defaultMoviePath
595                                 moviepath = defaultMoviePath()
596                                 if moviepath:
597                                         config.movielist.last_videodir.value = moviepath
598                         elif selected[0] == "PPanel":
599                                 ppanelFileName = '/etc/ppanels/' + selected[1] + ".xml"
600                                 if os.path.isfile(ppanelFileName) and os.path.isdir('/usr/lib/enigma2/python/Plugins/Extensions/PPanel'):
601                                         from Plugins.Extensions.PPanel.ppanel import PPanel
602                                         self.session.open(PPanel, name=selected[1] + ' PPanel', node=None, filename=ppanelFileName, deletenode=None)
603                         elif selected[0] == "Shellscript":
604                                 command = '/usr/script/' + selected[1] + ".sh"
605                                 if os.path.isfile(command) and os.path.isdir('/usr/lib/enigma2/python/Plugins/Extensions/PPanel'):
606                                         from Plugins.Extensions.PPanel.ppanel import Execute
607                                         self.session.open(Execute, selected[1] + " shellscript", None, command)
608
609         def showServiceListOrMovies(self):
610                 if hasattr(self, "openServiceList"):
611                         self.openServiceList()
612                 elif hasattr(self, "showMovies"):
613                         self.showMovies()
614
615         def ToggleLCDLiveTV(self):
616                 config.lcd.showTv.value = not config.lcd.showTv.value