[EasyMedia] - use componentSizes to give skinners more options
[enigma2-plugins.git] / easymedia / src / plugin.py
1 #######################################################################
2 #
3 #    EasyMedia for Dreambox-Enigma2
4 #    Coded by Vali (c)2010-2011
5 #
6 #  This plugin is licensed under the Creative Commons 
7 #  Attribution-NonCommercial-ShareAlike 3.0 Unported License.
8 #  To view a copy of this license, visit http://creativecommons.org/licenses/by-nc-sa/3.0/
9 #  or send a letter to Creative Commons, 559 Nathan Abbott Way, Stanford, California 94305, USA.
10 #
11 #  Alternatively, this plugin may be distributed and executed on hardware which
12 #  is licensed by Dream Property GmbH.
13 #
14 #  This plugin is NOT free software. It is open source, you are allowed to
15 #  modify it (if you keep the license), but it may not be commercially 
16 #  distributed other than under the conditions noted above.
17 #
18 #######################################################################
19
20 from Screens.Screen import Screen
21 from Screens.MessageBox import MessageBox
22 from Screens.InfoBarGenerics import InfoBarPlugins
23 from Screens.InfoBar import InfoBar
24 from Screens.ChoiceBox import ChoiceBox
25 from Plugins.Plugin import PluginDescriptor
26 from Components.ActionMap import ActionMap
27 from Components.MenuList import MenuList
28 from Components.Label import Label
29 from Components.ConfigList import ConfigListScreen
30 from Components.PluginComponent import plugins
31 from Components.PluginList import *
32 from Components.Sources.StaticText import StaticText
33 from Components.config import config, getConfigListEntry, ConfigSubsection, ConfigSelection
34 from Tools.Directories import fileExists, pathExists, resolveFilename, SCOPE_PLUGINS
35 from Tools.LoadPixmap import LoadPixmap
36 from Tools.HardwareInfo import HardwareInfo
37 from enigma import RT_HALIGN_LEFT, RT_WRAP, RT_VALIGN_CENTER, eListboxPythonMultiContent, gFont, getDesktop
38 import pickle
39 from os import system as os_system
40 from os import listdir as os_listdir
41 from skin import TemplatedListFonts, componentSizes
42
43 EMbaseInfoBarPlugins__init__ = None
44 EMStartOnlyOneTime = False
45 EMsession = None
46 InfoBar_instance = None
47
48 config.plugins.easyMedia  = ConfigSubsection()
49 config.plugins.easyMedia.music = ConfigSelection(default="mediaplayer", choices = [("no", _("Disabled")), ("mediaplayer", _("MediaPlayer")), ("merlinmp", _("MerlinMusicPlayer"))])
50 config.plugins.easyMedia.files = ConfigSelection(default="dreamexplorer", choices = [("no", _("Disabled")), ("filebrowser", _("Filebrowser")), ("dreamexplorer", _("DreamExplorer")), ("tuxcom", _("TuxCom"))])
51 config.plugins.easyMedia.videodb = ConfigSelection(default="no", choices = [("no", _("Disabled")), ("yes", _("Enabled"))])
52 config.plugins.easyMedia.bookmarks = ConfigSelection(default="no", choices = [("no", _("Disabled")), ("yes", _("Enabled"))])
53 config.plugins.easyMedia.pictures = ConfigSelection(default="yes", choices = [("no", _("Disabled")), ("yes", _("Enabled"))])
54 config.plugins.easyMedia.mytube = ConfigSelection(default="no", choices = [("no", _("Disabled")), ("yes", _("Enabled"))])
55 config.plugins.easyMedia.vlc = ConfigSelection(default="no", choices = [("no", _("Disabled")), ("yes", _("Enabled"))])
56 config.plugins.easyMedia.dvd = ConfigSelection(default="no", choices = [("no", _("Disabled")), ("yes", _("Enabled"))])
57 config.plugins.easyMedia.weather = ConfigSelection(default="yes", choices = [("no", _("Disabled")), ("yes", _("Enabled"))])
58 config.plugins.easyMedia.iradio = ConfigSelection(default="no", choices = [("no", _("Disabled")), ("yes", _("Enabled"))])
59 config.plugins.easyMedia.idream = ConfigSelection(default="no", choices = [("no", _("Disabled")), ("yes", _("Enabled"))])
60 config.plugins.easyMedia.zdfmedia = ConfigSelection(default="no", choices = [("no", _("Disabled")), ("yes", _("Enabled"))])
61 config.plugins.easyMedia.radio = ConfigSelection(default="yes", choices = [("no", _("Disabled")), ("yes", _("Enabled"))])
62 config.plugins.easyMedia.myvideo = ConfigSelection(default="no", choices = [("no", _("Disabled")), ("yes", _("Enabled"))])
63 config.plugins.easyMedia.timers = ConfigSelection(default="no", choices = [("no", _("Disabled")), ("yes", _("Enabled"))])
64
65 def Plugins(**kwargs):
66         return [PluginDescriptor(where = PluginDescriptor.WHERE_SESSIONSTART, fnc = EasyMediaAutostart),
67                         PluginDescriptor(name="EasyMedia", description=_("Not easy way to start EasyMedia"), where = PluginDescriptor.WHERE_PLUGINMENU, fnc=startFromPluginMenu),]
68
69 def EasyMediaAutostart(reason, **kwargs):
70         global EMbaseInfoBarPlugins__init__
71         if "session" in kwargs:
72                 global EMsession
73                 EMsession = kwargs["session"]
74                 if EMbaseInfoBarPlugins__init__ is None:
75                         EMbaseInfoBarPlugins__init__ = InfoBarPlugins.__init__
76                 InfoBarPlugins.__init__ = InfoBarPlugins__init__
77                 InfoBarPlugins.startWithPvrButton = startWithPvrButton
78
79 def InfoBarPlugins__init__(self):
80         global EMStartOnlyOneTime
81         if not EMStartOnlyOneTime: 
82                 EMStartOnlyOneTime = True
83                 global InfoBar_instance
84                 InfoBar_instance = self
85                 self["EasyMediaActions"] = ActionMap(["EasyMediaActions"],
86                         {"video_but": self.startWithPvrButton}, -1)
87         else:
88                 InfoBarPlugins.__init__ = InfoBarPlugins.__init__
89                 InfoBarPlugins.startWithPvrButton = None
90         EMbaseInfoBarPlugins__init__(self)
91
92 def startWithPvrButton(self):
93         self.session.openWithCallback(MPcallbackFunc, EasyMedia)
94
95 def startFromPluginMenu(session, **kwargs):
96         session.openWithCallback(MPcallbackFunc, EasyMedia)
97
98 class MPanelList(MenuList):
99         SKIN_COMPONENT_KEY = "EasyMediaPanelList"
100         SKIN_COMPONENT_ITEM_HEIGHT = "itemHeight"
101         SKIN_COMPONENT_ITEM_WIDTH = "itemWidth"
102         SKIN_COMPONENT_IMAGE_WIDTH = "imageWidth"
103         SKIN_COMPONENT_IMAGE_HEIGHT = "imageHeight"
104         SKIN_COMPONENT_IMAGE_XOFFSET = "imageXOffset"
105         SKIN_COMPONENT_IMAGE_YOFFSET = "imageYOffset"
106         SKIN_COMPONENT_ICON_WIDTH = "iconWidth"
107         SKIN_COMPONENT_ICON_HEIGHT = "iconHeight"
108         SKIN_COMPONENT_ICON_XOFFSET = "iconXOffset"
109         SKIN_COMPONENT_ICON_YOFFSET = "iconYOffset"
110         SKIN_COMPONENT_TEXT_WIDTH = "textWidth"
111         SKIN_COMPONENT_TEXT_HEIGHT = "textHeight"
112         SKIN_COMPONENT_TEXT_XOFFSET = "textXOffset"
113         SKIN_COMPONENT_TEXT_YOFFSET = "textYOffset"
114
115         def __init__(self, list, selection = 0, enableWrapAround=True):
116                 MenuList.__init__(self, list, enableWrapAround, eListboxPythonMultiContent)
117
118                 isFHD = False
119                 sz_w = getDesktop(0).size().width()
120                 if sz_w >= 1920:
121                         isFHD = True
122                 
123                 sizes = componentSizes[MPanelList.SKIN_COMPONENT_KEY]
124                 self.itemheight = sizes.get(MPanelList.SKIN_COMPONENT_ITEM_HEIGHT, 150 if isFHD else 100)
125                 self.itemwidth = sizes.get(MPanelList.SKIN_COMPONENT_ITEM_WIDTH, 400 if isFHD else 300)
126                 self.imagewidth = sizes.get(MPanelList.SKIN_COMPONENT_IMAGE_WIDTH, 200 if isFHD else 135)
127                 self.imageheight = sizes.get(MPanelList.SKIN_COMPONENT_IMAGE_HEIGHT, 140 if isFHD else 90)
128                 self.imagexoffset = sizes.get(MPanelList.SKIN_COMPONENT_IMAGE_XOFFSET, 25)
129                 self.imageyoffset = sizes.get(MPanelList.SKIN_COMPONENT_IMAGE_YOFFSET, 5)
130                 self.iconwidth = sizes.get(MPanelList.SKIN_COMPONENT_ICON_WIDTH, 5)
131                 self.iconheight = sizes.get(MPanelList.SKIN_COMPONENT_ICON_HEIGHT, 140 if isFHD else 90)
132                 self.iconxoffset = sizes.get(MPanelList.SKIN_COMPONENT_ICON_XOFFSET, 0)
133                 self.iconyoffset = sizes.get(MPanelList.SKIN_COMPONENT_ICON_YOFFSET, 5)
134                 self.textwidth = sizes.get(MPanelList.SKIN_COMPONENT_TEXT_WIDTH, 400 if isFHD else 300)
135                 self.textheight = sizes.get(MPanelList.SKIN_COMPONENT_TEXT_HEIGHT, 150 if isFHD else 100)
136                 self.textxoffset = sizes.get(MPanelList.SKIN_COMPONENT_TEXT_XOFFSET, 300 if isFHD else 200)
137                 self.textyoffset = sizes.get(MPanelList.SKIN_COMPONENT_TEXT_YOFFSET, 5)
138                 
139                 tlf = TemplatedListFonts()
140                 self.l.setFont(0, gFont(tlf.face(tlf.BIG), tlf.size(tlf.BIG)))
141                 self.l.setItemHeight(self.itemheight)
142                 self.l.setItemWidth(self.itemwidth)
143                 self.l.setBuildFunc(self.buildEntry)
144                 self.selection = selection
145                 
146         def postWidgetCreate(self, instance):
147                 MenuList.postWidgetCreate(self, instance)
148                 self.moveToIndex(self.selection)
149
150         def buildEntry(self, key, text, cell):
151                 res = [ text ]
152                 
153                 res.append((eListboxPythonMultiContent.TYPE_TEXT, self.textxoffset, self.textyoffset, self.textwidth, self.textheight, 0, RT_HALIGN_LEFT|RT_WRAP|RT_VALIGN_CENTER, text[0]))
154                 if cell<5:
155                         bpng = LoadPixmap('/usr/lib/enigma2/python/Plugins/Extensions/EasyMedia/key-' + str(cell) + ".png")
156                         if bpng is not None:
157                                 res.append((eListboxPythonMultiContent.TYPE_PIXMAP_ALPHATEST, self.iconxoffset, self.iconyoffset, self.iconwidth, self.iconheight, bpng))
158                 png = LoadPixmap(EasyMedia.EMiconspath + key + '.png')
159                 if png is not None:
160                         res.append((eListboxPythonMultiContent.TYPE_PIXMAP_ALPHATEST, self.imagexoffset, self.imageyoffset, self.imagewidth, self.imageheight, png))
161                 else:
162                         png = LoadPixmap(EasyMedia.EMiconspath + 'default.png')
163                         if png is not None:
164                                 res.append((eListboxPythonMultiContent.TYPE_PIXMAP_ALPHATEST, self.imagexoffset, self.imageyoffset, self.imagewidth, self.imageheight, png))
165                 return res
166                 
167
168 def BookmarksCallback(choice):
169         choice = choice and choice[1]
170         if choice:
171                 config.movielist.last_videodir.value = choice
172                 config.movielist.last_videodir.save()
173                 if InfoBar_instance:
174                         InfoBar_instance.showMovies()
175
176 def TvRadioCallback(choice):
177         choice = choice and choice[1]
178         if choice == "TM":
179                 if InfoBar_instance:
180                         InfoBar_instance.showTv()
181         elif choice == "RM":
182                 if InfoBar_instance:
183                         InfoBar_instance.showRadio()
184
185 class ConfigEasyMedia(ConfigListScreen, Screen):
186         skin = """
187                 <screen name="ConfigEasyMedia" position="center,center" size="600,410" title="EasyMedia settings...">
188                         <widget name="config" position="5,5" scrollbarMode="showOnDemand" size="590,380"/>
189                         <eLabel font="Regular;20" foregroundColor="#00ff4A3C" halign="center" position="20,388" size="140,26" text="Cancel"/>
190                         <eLabel font="Regular;20" foregroundColor="#0056C856" halign="center" position="165,388" size="140,26" text="Save"/>
191                         <eLabel font="Regular;20" foregroundColor="#00f3ca09" halign="center" position="310,388" size="140,26" text="Plugins"/>
192                 </screen>"""
193         def __init__(self, session):
194                 Screen.__init__(self, session)
195                 self.setTitle(_("EasyMedia settings..."))
196                 self.session = session
197                 list = []
198                 list.append(getConfigListEntry(_("Video database:"), config.plugins.easyMedia.videodb))
199                 list.append(getConfigListEntry(_("Music player:"), config.plugins.easyMedia.music))
200                 list.append(getConfigListEntry(_("Files browser:"), config.plugins.easyMedia.files))
201                 list.append(getConfigListEntry(_("Show bookmarks:"), config.plugins.easyMedia.bookmarks))
202                 list.append(getConfigListEntry(_("Timer:"), config.plugins.easyMedia.timers))
203                 list.append(getConfigListEntry(_("PicturePlayer:"), config.plugins.easyMedia.pictures))
204                 list.append(getConfigListEntry(_("Show tv/radio switch:"), config.plugins.easyMedia.radio))
205                 list.append(getConfigListEntry(_("YouTube player:"), config.plugins.easyMedia.mytube))
206                 list.append(getConfigListEntry(_("VLC player:"), config.plugins.easyMedia.vlc))
207                 list.append(getConfigListEntry(_("DVD player:"), config.plugins.easyMedia.dvd))
208                 list.append(getConfigListEntry(_("Weather plugin:"), config.plugins.easyMedia.weather))
209                 list.append(getConfigListEntry(_("InternetRadio player:"), config.plugins.easyMedia.iradio))
210                 list.append(getConfigListEntry(_("Show Merlin-iDream:"), config.plugins.easyMedia.idream))
211                 list.append(getConfigListEntry(_("ZDFmediathek player:"), config.plugins.easyMedia.zdfmedia))
212                 list.append(getConfigListEntry(_("MyVideo player:"), config.plugins.easyMedia.myvideo))
213                 ConfigListScreen.__init__(self, list)
214                 self["actions"] = ActionMap(["OkCancelActions", "ColorActions"], {"green": self.save, "red": self.exit, "cancel": self.exit, "yellow": self.addPlugin}, -1)
215
216         def save(self):
217                 for x in self["config"].list:
218                         x[1].save()
219                 self.close()
220
221         def exit(self):
222                 for x in self["config"].list:
223                         x[1].cancel()
224                 self.close()
225
226         def addPlugin(self):
227                 self.session.open(AddPlug)
228
229 class AddPlug(Screen):
230         skin = """
231                 <screen name="AddPlug" position="center,center" size="440,420" title="EasyMedia...">
232                 <widget source="pluginlist" render="Listbox" position="10,10" size="420,400" scrollbarMode="showOnDemand">
233                         <convert type="TemplatedMultiContent">
234                         {"templates":
235                                 {"default": (50,[
236                                                 MultiContentEntryText(pos = (120, 5), size = (320, 25), font = 0, text = 1), # index 1 is the plugin.name
237                                                 MultiContentEntryText(pos = (120, 26), size = (320, 17), font = 1, text = 2), # index 2 is the plugin.description
238                                                 MultiContentEntryPixmapAlphaTest(pos = (10, 5), size = (100, 40), png = 3), # index 3 is the icon
239                                                 
240                                         ]),
241                                 },
242                                 "fonts": [gFont("Regular", 20), gFont("Regular", 14)],
243                                 "itemHeight": 50
244                         }
245                         </convert>
246                 </widget>
247                 </screen>"""
248         def __init__(self, session):
249                 Screen.__init__(self, session)
250                 self.setTitle(_("Add/remove plugin"))
251                 plugins.readPluginList(resolveFilename(SCOPE_PLUGINS))
252                 self.session = session
253                 self.list = []
254                 self["pluginlist"] = PluginList(self.list)
255                 #self.updateList()
256                 self.pluginlist = []
257                 self["actions"] = ActionMap(["WizardActions"],
258                 {
259                         "ok": self.save,
260                         "back": self.close
261                 }, -1)
262                 self.onExecBegin.append(self.checkWarnings)
263                 self.onShown.append(self.updateList)
264
265         def checkWarnings(self):
266                 if len(plugins.warnings):
267                         text = _("Some plugins are not available:\n")
268                         for (pluginname, error) in plugins.warnings:
269                                 text += _("%s (%s)\n") % (pluginname, error)
270                         plugins.resetWarnings()
271                         self.session.open(MessageBox, text = text, type = MessageBox.TYPE_WARNING)
272
273         def updateList(self):
274                 self.pluginlist = plugins.getPlugins(PluginDescriptor.WHERE_PLUGINMENU)
275                 self.list = [PluginEntryComponent(plugin) for plugin in self.pluginlist]
276                 self["pluginlist"].setList(self.list)
277
278         def save(self):
279                 plugin = self["pluginlist"].getCurrent()[0]
280                 print plugin
281                 plugin.icon = None
282                 if not fileExists("/usr/lib/enigma2/python/Plugins/Extensions/EasyMedia/" + plugin.name + ".plug"):
283                         try:
284                                 outf = open(("/usr/lib/enigma2/python/Plugins/Extensions/EasyMedia/" + plugin.name + ".plug"), 'wb')
285                                 pickle.dump(plugin, outf)
286                                 outf.close()
287                                 self.session.open(MessageBox, text = (plugin.name + _(" added to EasyMedia")), type = MessageBox.TYPE_INFO)
288                         except: self.session.open(MessageBox, text = "Write Error!", type = MessageBox.TYPE_WARNING)
289                 else:
290                         order = 'rm -f \"' + '/usr/lib/enigma2/python/Plugins/Extensions/EasyMedia/' + plugin.name + '.plug' + '\"'
291                         try:
292                                 os_system(order)
293                                 self.session.open(MessageBox, text = (plugin.name + _(" removed from EasyMedia")), type = MessageBox.TYPE_INFO)
294                         except: self.session.open(MessageBox, text = "Write Error!", type = MessageBox.TYPE_WARNING)
295
296 class EasyMediaSummary(Screen):
297         if HardwareInfo().get_device_name() == "dm820":
298                 skin = """
299                         <screen position="0,0" size="96,64" id="2">
300                                 <eLabel text="EasyMedia:" foregroundColor="#fcc000" position="0,0" size="96,24" font="Regular;16"/>
301                                 <widget name="text1" position="0,24" size="96,40" font="Regular;18"/>
302                         </screen>"""
303         elif HardwareInfo().get_device_name() == "dm7080":
304                 skin = """
305                         <screen position="0,0" size="132,64" id="1">
306                                 <eLabel text="EasyMedia:" position="0,0" size="132,24" font="Regular;14"/>
307                                 <widget name="text1" position="0,24" size="132,40" font="Regular;16"/>
308                         </screen>"""
309         elif HardwareInfo().get_device_name() in ('dm900', 'dm920'):
310                 skin = """
311                         <screen position="0,0" size="400,240" id="3">
312                                 <eLabel text="EasyMedia:" position="0,0" size="400,50" font="Regular;40"/>
313                                 <widget name="text1" position="0,50" size="400,190" font="Regular;45"/>
314                         </screen>"""    
315         else:
316                 skin = """
317                         <screen position="0,0" size="132,64" id="1">
318                                 <eLabel text="EasyMedia:" position="0,0" size="132,24" font="Regular;14"/>
319                                 <widget name="text1" position="0,24" size="132,40" font="Regular;16"/>
320                         </screen>"""            
321         
322         def __init__(self, session, parent):
323                 Screen.__init__(self, session)
324                 self["text1"] = Label()
325                 self.onLayoutFinish.append(self.layoutEnd)
326
327         def layoutEnd(self):
328                 self["text1"].setText(_("Movies"))
329
330         def setText(self, text, line):
331                 self["text1"].setText(text)
332
333 class EasyMedia(Screen):
334         sz_w = getDesktop(0).size().width()
335         if sz_w >= 1920:
336                 skin = """
337                 <screen flags="wfNoBorder" position="0,0" size="810,1080" title="Easy Media">
338                         <ePixmap pixmap="/usr/lib/enigma2/python/Plugins/Extensions/EasyMedia/bg.png" position="0,0" size="750,1080"/>
339                         <widget name="list" position="60,30" size="750,1050" scrollbarMode="showNever" transparent="1" zPosition="2"/>
340                 </screen>"""
341         else:
342                 skin = """
343                 <screen flags="wfNoBorder" position="0,0" size="540,720" title="Easy Media">
344                         <ePixmap pixmap="/usr/lib/enigma2/python/Plugins/Extensions/EasyMedia/bg.png" position="0,0" size="480,720" scale="stretch" />
345                         <widget name="list" position="60,20" size="480,700" scrollbarMode="showNever" transparent="1" zPosition="2"/>
346                 </screen>"""
347         if pathExists('/usr/lib/enigma2/python/Plugins/Extensions/EasyMedia/icons/'):
348                 EMiconspath = '/usr/lib/enigma2/python/Plugins/Extensions/EasyMedia/icons/'
349         else:
350                 EMiconspath = '/usr/lib/enigma2/python/Plugins/Extensions/EasyMedia/'
351         def __init__(self, session):
352                 Screen.__init__(self, session)
353                 self.session = session
354
355                 self["actions"] = ActionMap(["WizardActions", "MenuActions", "InfobarActions", "ColorActions"],
356                 {
357                         "ok": self.go,
358                         "back": self.cancel,
359                         "menu": self.openConfig,
360                         "showMovies": lambda: self.go(self.menuItemList[0]),
361                         "green": lambda: self.go(self.menuItemList[2]),
362                         "red": lambda: self.go(self.menuItemList[1]),
363                         "blue": lambda: self.go(self.menuItemList[4]),
364                         "yellow": lambda: self.go(self.menuItemList[3])
365                 }, -1)
366
367                 self.list = []
368                 self.__keys = []                
369                 self["list"] = MPanelList(list = self.list, selection = 0)
370                 self["list"].onSelectionChanged.append(self.updateOLED)
371                 
372                 self["key_pvr"] = StaticText(" ")
373                 self["key_yellow"] = StaticText(" ")
374                 self["key_green"] = StaticText(" ")
375                 self["key_red"] = StaticText(" ")
376                 self["key_blue"] = StaticText(" ")
377         
378                 self.onLayoutFinish.append(self.buildEasyMediaList)
379
380         def buildEasyMediaList(self):
381                 self.list = []
382                 self.__keys = []
383                 self.menuItemList = []
384                 self.__keys.append("movies")
385                 self.menuItemList.append((_("Movies"), "PLAYMOVIES"))
386                 if config.plugins.easyMedia.bookmarks.value != "no":
387                         self.__keys.append("bookmarks")
388                         self.menuItemList.append((_("Bookmarks"), "BOOKMARKS"))
389                 if config.plugins.easyMedia.timers.value != "no":
390                         self.__keys.append("timers")
391                         self.menuItemList.append((_("Timer"), "TIMERS"))
392                 if config.plugins.easyMedia.videodb.value != "no":
393                         self.__keys.append("videodb")
394                         self.menuItemList.append((_("VideoDB"), "VIDEODB"))
395                 if config.plugins.easyMedia.pictures.value != "no":
396                         self.__keys.append("pictures")
397                         self.menuItemList.append((_("Pictures"), "PICTURES"))
398                 if config.plugins.easyMedia.music.value != "no":
399                         self.__keys.append("music")
400                         self.menuItemList.append((_("Music"), "MUSIC"))
401                 if config.plugins.easyMedia.radio.value != "no":
402                         self.__keys.append("radio")
403                         if config.usage.e1like_radio_mode.value:
404                                 self.menuItemList.append((_("Tv/Radio"), "RADIO"))
405                         else:
406                                 self.menuItemList.append((_("Radio"), "RADIO"))
407                 if config.plugins.easyMedia.dvd.value != "no":
408                         self.__keys.append("dvd")
409                         self.menuItemList.append((_("DVD Player"), "DVD"))
410                 if config.plugins.easyMedia.weather.value != "no":
411                         self.__keys.append("weather")
412                         self.menuItemList.append((_("Weather"), "WEATHER"))
413                 if config.plugins.easyMedia.files.value != "no":
414                         self.__keys.append("files")
415                         self.menuItemList.append((_("Files"), "FILES"))
416                 if config.plugins.easyMedia.iradio.value != "no":
417                         self.__keys.append("internetradio")
418                         self.menuItemList.append((_("InternetRadio"), "INTERNETRADIO"))
419                 if config.plugins.easyMedia.idream.value != "no":
420                         self.__keys.append("idream")
421                         self.menuItemList.append((_("iDream"), "IDREAM"))
422                 if config.plugins.easyMedia.mytube.value != "no":
423                         self.__keys.append("mytube")
424                         self.menuItemList.append((_("MyTube Player"), "MYTUBE"))
425                 if config.plugins.easyMedia.vlc.value != "no":
426                         self.__keys.append("vlc")
427                         self.menuItemList.append((_("VLC Player"), "VLC"))
428                 if config.plugins.easyMedia.zdfmedia.value != "no":
429                         self.__keys.append("zdf")
430                         self.menuItemList.append((_("ZDFmediathek"), "ZDF"))
431                 if config.plugins.easyMedia.myvideo.value != "no":
432                         self.__keys.append("myvideo")
433                         self.menuItemList.append((_("MyVideo"), "MYVIDEO"))
434                 plist = os_listdir("/usr/lib/enigma2/python/Plugins/Extensions/EasyMedia")
435                 plist = [x[:-5] for x in plist if x.endswith('.plug')]
436                 plist.sort()
437                 for plugin in plist:
438                         try:
439                                 inputfile = open(("/usr/lib/enigma2/python/Plugins/Extensions/EasyMedia/" + plugin + ".plug"), 'rb')
440                                 binPlug = pickle.load(inputfile)
441                                 inputfile.close()       
442                                 self.__keys.append(binPlug.name)
443                                 self.menuItemList.append((binPlug.name, ("++++" + binPlug.name)))
444                         except: pass
445                 pos = 0
446                 for x in self.menuItemList:
447                         strpos = str(self.__keys[pos])
448                         self.list.append((strpos, x, pos))
449                         if pos==0: self["key_pvr"].setText(self.menuItemList[0][0])
450                         elif pos==1: self["key_red"].setText(self.menuItemList[1][0])
451                         elif pos==2: self["key_green"].setText(self.menuItemList[2][0])
452                         elif pos==3: self["key_yellow"].setText(self.menuItemList[3][0])
453                         elif pos==4: self["key_blue"].setText(self.menuItemList[4][0])
454                         pos += 1
455                                         
456                 self["list"].setList(self.list)
457
458         def cancel(self):
459                 self.close(None)
460
461         def go(self, item=None):
462                 if item is not None:
463                         self.close(item)
464                 cursel = self["list"].l.getCurrentSelection()
465                 if cursel:
466                         entry = cursel[0]
467                         if len(entry) > 2 and isinstance(entry[1], str) and entry[1] == "CALLFUNC":
468                                 arg = self["list"].l.getCurrentSelection()[0]
469                                 entry[2](arg)
470                         else:
471                                 self.close(entry)
472                 else:
473                         self.cancel()
474
475         def openConfig(self):
476                 self.session.openWithCallback(self.buildEasyMediaList, ConfigEasyMedia)
477
478         def createSummary(self):
479                 return EasyMediaSummary
480
481         def updateOLED(self):
482                 text = str(self["list"].l.getCurrentSelection()[0][0])
483                 self.summaries.setText(text, 1)
484
485 def MPcallbackFunc(answer):
486         if EMsession is None:
487                 return
488         answer = answer and answer[1]
489         if answer == "PLAYMOVIES":
490                 if InfoBar_instance:
491                         InfoBar_instance.showMovies()
492         elif answer == "RADIO":
493                 if config.usage.e1like_radio_mode.value:
494                         askBM = []
495                         askBM.append((_("TV-mode"), "TM"))
496                         askBM.append((_("Radio-mode"), "RM"))
497                         askBM.append((_("Nothing"), "NO"))
498                         EMsession.openWithCallback(TvRadioCallback, ChoiceBox, title="EasyMedia...", list = askBM)
499                 else:
500                         if InfoBar_instance:
501                                 InfoBar_instance.showRadio()
502         elif answer == "BOOKMARKS":
503                 tmpBookmarks = config.movielist.videodirs
504                 myBookmarks = tmpBookmarks and tmpBookmarks.value[:] or []
505                 if len(myBookmarks)>0:
506                         askBM = []
507                         for s in myBookmarks:
508                                 askBM.append((s, s))
509                         EMsession.openWithCallback(BookmarksCallback, ChoiceBox, title=_("Select bookmark..."), list = askBM)
510         elif answer == "PICTURES":
511                 if fileExists("/usr/lib/enigma2/python/Plugins/Extensions/PicturePlayer/plugin.pyo"):
512                         from Plugins.Extensions.PicturePlayer.plugin import picshow
513                         EMsession.open(picshow)
514                 else:
515                         EMsession.open(MessageBox, text = _('Picture-player is not installed!'), type = MessageBox.TYPE_ERROR)
516         elif answer == "MUSIC":
517                 if fileExists("/usr/lib/enigma2/python/Plugins/Extensions/MerlinMusicPlayer/plugin.pyo") and (config.plugins.easyMedia.music.value == "merlinmp"):
518                         from Plugins.Extensions.MerlinMusicPlayer.plugin import MerlinMusicPlayerFileList
519                         servicelist = None
520                         EMsession.open(MerlinMusicPlayerFileList, servicelist)
521                 elif fileExists("/usr/lib/enigma2/python/Plugins/Extensions/MediaPlayer/plugin.pyo") and (config.plugins.easyMedia.music.value == "mediaplayer"):
522                         from Plugins.Extensions.MediaPlayer.plugin import MediaPlayer
523                         EMsession.open(MediaPlayer)
524                 else:
525                         EMsession.open(MessageBox, text = _('No Music-Player installed!'), type = MessageBox.TYPE_ERROR)
526         elif answer == "FILES":
527                 if fileExists("/usr/lib/enigma2/python/Plugins/Extensions/Tuxcom/plugin.pyo") and (config.plugins.easyMedia.files.value == "tuxcom"):
528                         from Plugins.Extensions.Tuxcom.plugin import TuxComStarter
529                         EMsession.open(TuxComStarter)
530                 elif fileExists("/usr/lib/enigma2/python/Plugins/Extensions/DreamExplorer/plugin.pyo") and (config.plugins.easyMedia.files.value == "dreamexplorer"):
531                         from Plugins.Extensions.DreamExplorer.plugin import DreamExplorerII
532                         EMsession.open(DreamExplorerII)
533                 elif fileExists("/usr/lib/enigma2/python/Plugins/Extensions/Filebrowser/plugin.pyo") and (config.plugins.easyMedia.files.value == "filebrowser"):
534                         from Plugins.Extensions.Filebrowser.plugin import FilebrowserScreen
535                         EMsession.open(FilebrowserScreen)
536                 else:
537                         EMsession.open(MessageBox, text = _('No File-Manager installed!'), type = MessageBox.TYPE_ERROR)
538         elif answer == "WEATHER":
539                 if fileExists("/usr/lib/enigma2/python/Plugins/Extensions/WeatherPlugin/plugin.pyo"):
540                         from Plugins.Extensions.WeatherPlugin.plugin import MSNWeatherPlugin
541                         EMsession.open(MSNWeatherPlugin)
542                 else:
543                         EMsession.open(MessageBox, text = _('Weather Plugin is not installed!'), type = MessageBox.TYPE_ERROR)
544         elif answer == "DVD":
545                 if fileExists("/usr/lib/enigma2/python/Plugins/Extensions/DVDPlayer/plugin.pyo"):
546                         from Plugins.Extensions.DVDPlayer.plugin import DVDPlayer
547                         EMsession.open(DVDPlayer)
548                 else:
549                         EMsession.open(MessageBox, text = _('DVDPlayer Plugin is not installed!'), type = MessageBox.TYPE_ERROR)
550         elif answer == "MYTUBE":
551                 if fileExists("/usr/lib/enigma2/python/Plugins/Extensions/MyTube/plugin.pyo"):
552                         from Plugins.Extensions.MyTube.plugin import *
553                         MyTubeMain(EMsession)
554                 else:
555                         EMsession.open(MessageBox, text = _('MyTube Plugin is not installed!'), type = MessageBox.TYPE_ERROR)
556         elif answer == "INTERNETRADIO":
557                 if fileExists("/usr/lib/enigma2/python/Plugins/Extensions/InternetRadio/plugin.pyo"):
558                         from Plugins.Extensions.InternetRadio.InternetRadioScreen import InternetRadioScreen
559                         EMsession.open(InternetRadioScreen)
560                 else:
561                         EMsession.open(MessageBox, text = _('SHOUTcast Plugin is not installed!'), type = MessageBox.TYPE_ERROR)
562         elif answer == "ZDF":
563                 if fileExists("/usr/lib/enigma2/python/Plugins/Extensions/ZDFMediathek/plugin.pyo"):
564                         from Plugins.Extensions.ZDFMediathek.plugin import ZDFMediathek
565                         EMsession.open(ZDFMediathek)
566                 else:
567                         EMsession.open(MessageBox, text = _('ZDFmediathek Plugin is not installed!'), type = MessageBox.TYPE_ERROR)
568         elif answer == "VLC":
569                 if fileExists("/usr/lib/enigma2/python/Plugins/Extensions/VlcPlayer/plugin.pyo"):
570                         from Plugins.Extensions.VlcPlayer.plugin import *
571                         main(EMsession)
572                 else:
573                         EMsession.open(MessageBox, text = _('VLC Player is not installed!'), type = MessageBox.TYPE_ERROR)
574         elif answer == "IDREAM":
575                 if fileExists("/usr/lib/enigma2/python/Plugins/Extensions/MerlinMusicPlayer/plugin.pyo"):
576                         from Plugins.Extensions.MerlinMusicPlayer.plugin import iDreamMerlin
577                         servicelist = None
578                         EMsession.open(iDreamMerlin, servicelist)
579                 else:
580                         EMsession.open(MessageBox, text = _('Merlin iDream is not installed!'), type = MessageBox.TYPE_ERROR)
581         elif answer == "MYVIDEO":
582                 if fileExists("/usr/lib/enigma2/python/Plugins/Extensions/MyVideoPlayer/plugin.pyo"):
583                         from Plugins.Extensions.MyVideoPlayer.plugin import Vidtype
584                         EMsession.open(Vidtype)
585                 else:
586                         EMsession.open(MessageBox, text = _('MyVideo Player is not installed!'), type = MessageBox.TYPE_ERROR)
587         elif answer == "VIDEODB":
588                 if fileExists("/usr/lib/enigma2/python/Plugins/Extensions/VideoDB/plugin.pyo"):
589                         from Plugins.Extensions.VideoDB.plugin import main as vdbmain
590                         vdbmain(EMsession)
591                 else:
592                         EMsession.open(MessageBox, text = _('VideoDB is not installed!'), type = MessageBox.TYPE_ERROR)
593         elif answer == "TIMERS":
594                 from Screens.TimerEdit import TimerEditList
595                 EMsession.open(TimerEditList)
596         elif answer is not None and "++++" in answer:
597                 pluginToRun = answer[4:]
598                 try:
599                         inputfile = open(("/usr/lib/enigma2/python/Plugins/Extensions/EasyMedia/" + pluginToRun + ".plug"), 'rb')
600                         runPlugin = pickle.load(inputfile)
601                         inputfile.close()       
602                         runPlugin(session = EMsession)
603                 except: EMsession.open(MessageBox, text = (pluginToRun + " not found!"), type = MessageBox.TYPE_WARNING)