remove locale directory from cvs
[vuplus_dvbapp-plugin] / easymedia / src / plugin.py
1 #######################################################################
2 #
3 #    EasyMedia for Dreambox-Enigma2
4 #    Coded by Vali (c)2010
5 #    Support: www.dreambox-tools.info
6 #
7 #
8 #  This plugin is licensed under the Creative Commons 
9 #  Attribution-NonCommercial-ShareAlike 3.0 Unported License.
10 #  To view a copy of this license, visit http://creativecommons.org/licenses/by-nc-sa/3.0/
11 #  or send a letter to Creative Commons, 559 Nathan Abbott Way, Stanford, California 94305, USA.
12 #
13 #  Alternatively, this plugin may be distributed and executed on hardware which
14 #  is licensed by Dream Multimedia GmbH.
15 #
16 #
17 #  This plugin is NOT free software. It is open source, you are allowed to
18 #  modify it (if you keep the license), but it may not be commercially 
19 #  distributed other than under the conditions noted above.
20 #
21 #
22 #######################################################################
23
24
25
26 from __init__ import _
27 from Screens.Screen import Screen
28 from Screens.MessageBox import MessageBox
29 from Screens.InfoBarGenerics import InfoBarPlugins
30 from Screens.InfoBar import InfoBar
31 from Screens.ChoiceBox import ChoiceBox
32 from Plugins.Plugin import PluginDescriptor
33 from Components.ActionMap import ActionMap
34 from Components.MenuList import MenuList
35 from Components.ConfigList import ConfigListScreen
36 from Components.config import config, getConfigListEntry, ConfigSubsection, ConfigSelection
37 from Tools.Directories import fileExists
38 from Tools.LoadPixmap import LoadPixmap
39 from enigma import RT_HALIGN_LEFT, eListboxPythonMultiContent, gFont, getDesktop
40
41
42
43 EMbaseInfoBarPlugins__init__ = None
44 EMStartOnlyOneTime = False
45 EMsession = None
46 InfoBar_instance = None
47
48
49
50 config.plugins.easyMedia  = ConfigSubsection()
51 config.plugins.easyMedia.music = ConfigSelection(default="mediaplayer", choices = [("no", _("Disabled")), ("mediaplayer", _("MediaPlayer")), ("merlinmp", _("MerlinMusicPlayer"))])
52 config.plugins.easyMedia.files = ConfigSelection(default="dreamexplorer", choices = [("no", _("Disabled")), ("filebrowser", _("Filebrowser")), ("dreamexplorer", _("DreamExplorer")), ("tuxcom", _("TuxCom"))])
53 config.plugins.easyMedia.bookmarks = ConfigSelection(default="no", 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
62
63
64 def Plugins(**kwargs):
65         return [PluginDescriptor(where = PluginDescriptor.WHERE_SESSIONSTART, fnc = EasyMediaAutostart),
66                         PluginDescriptor(name="EasyMedia", description=_("Not easy way to start EasyMedia"), where = PluginDescriptor.WHERE_PLUGINMENU, fnc=notEasy),]
67
68
69
70 def EasyMediaAutostart(reason, **kwargs):
71         global EMbaseInfoBarPlugins__init__
72         if "session" in kwargs:
73                 global EMsession
74                 EMsession = kwargs["session"]
75                 if EMbaseInfoBarPlugins__init__ is None:
76                         EMbaseInfoBarPlugins__init__ = InfoBarPlugins.__init__
77                 InfoBarPlugins.__init__ = InfoBarPlugins__init__
78                 InfoBarPlugins.pvr = pvr
79
80
81
82 def InfoBarPlugins__init__(self):
83         global EMStartOnlyOneTime
84         if not EMStartOnlyOneTime: 
85                 EMStartOnlyOneTime = True
86                 global InfoBar_instance
87                 InfoBar_instance = self
88                 self["EasyMediaActions"] = ActionMap(["EasyMediaActions"],
89                         {"video_but": self.pvr}, -1)
90         else:
91                 InfoBarPlugins.__init__ = InfoBarPlugins.__init__
92                 InfoBarPlugins.pvr = None
93         EMbaseInfoBarPlugins__init__(self)
94
95
96
97 def pvr(self):
98         self.session.openWithCallback(MPcallbackFunc, EasyMedia)
99
100
101
102 def notEasy(session, **kwargs):
103         session.openWithCallback(MPcallbackFunc, EasyMedia)
104
105
106
107 def MPanelEntryComponent(key, text):
108         res = [ text ]
109         res.append((eListboxPythonMultiContent.TYPE_TEXT, 160, 15, 300, 60, 0, RT_HALIGN_LEFT, text[0]))
110         png = LoadPixmap('/usr/lib/enigma2/python/Plugins/Extensions/EasyMedia/' + key + ".png")
111         if png is not None:
112                 res.append((eListboxPythonMultiContent.TYPE_PIXMAP_ALPHATEST, 30, 5, 100, 50, png))
113         return res
114
115
116
117 class MPanelList(MenuList):
118         def __init__(self, list, selection = 0, enableWrapAround=True):
119                 MenuList.__init__(self, list, enableWrapAround, eListboxPythonMultiContent)
120                 self.l.setFont(0, gFont("Regular", 24))
121                 self.l.setItemHeight(60)
122                 self.selection = selection
123         def postWidgetCreate(self, instance):
124                 MenuList.postWidgetCreate(self, instance)
125                 self.moveToIndex(self.selection)
126
127
128
129 def BookmarksCallback(choice):
130         choice = choice and choice[1]
131         if choice:
132                 config.movielist.last_videodir.value = choice
133                 config.movielist.last_videodir.save()
134                 if InfoBar_instance:
135                         InfoBar_instance.showMovies()
136
137
138
139 class ConfigEasyMedia(ConfigListScreen, Screen):
140         skin = """
141                 <screen name="ConfigEasyMedia" position="center,center" size="600,410" title="EasyMedia settings...">
142                         <widget name="config" position="5,5" scrollbarMode="showOnDemand" size="590,380"/>
143                         <eLabel font="Regular;20" foregroundColor="#00ff4A3C" halign="center" position="20,388" size="120,26" text="Cancel"/>
144                         <eLabel font="Regular;20" foregroundColor="#0056C856" halign="center" position="165,388" size="120,26" text="Save"/>
145                 </screen>"""
146         def __init__(self, session):
147                 Screen.__init__(self, session)
148                 self.setTitle(_("EasyMedia settings..."))
149                 list = []
150                 list.append(getConfigListEntry(_("Music player:"), config.plugins.easyMedia.music))
151                 list.append(getConfigListEntry(_("Files browser:"), config.plugins.easyMedia.files))
152                 list.append(getConfigListEntry(_("Show bookmarks:"), config.plugins.easyMedia.bookmarks))
153                 list.append(getConfigListEntry(_("YouTube player:"), config.plugins.easyMedia.mytube))
154                 list.append(getConfigListEntry(_("VLC player:"), config.plugins.easyMedia.vlc))
155                 list.append(getConfigListEntry(_("DVD player:"), config.plugins.easyMedia.dvd))
156                 list.append(getConfigListEntry(_("Weather plugin:"), config.plugins.easyMedia.weather))
157                 list.append(getConfigListEntry(_("NetRadio player:"), config.plugins.easyMedia.iradio))
158                 list.append(getConfigListEntry(_("Show Merlin-iDream:"), config.plugins.easyMedia.idream))
159                 list.append(getConfigListEntry(_("ZDFmediathek player:"), config.plugins.easyMedia.zdfmedia))
160                 ConfigListScreen.__init__(self, list)
161                 self["actions"] = ActionMap(["OkCancelActions", "ColorActions"], {"green": self.save, "red": self.exit, "cancel": self.exit}, -1)
162
163         def save(self):
164                 for x in self["config"].list:
165                         x[1].save()
166                 self.close()
167
168         def exit(self):
169                 for x in self["config"].list:
170                         x[1].cancel()
171                 self.close()
172
173
174
175 class EasyMedia(Screen):
176         sz_w = getDesktop(0).size().width()
177         if sz_w > 1100:
178                 skin = """
179                 <screen flags="wfNoBorder" position="0,0" size="450,720" title="Easy Media">
180                         <ePixmap pixmap="/usr/lib/enigma2/python/Plugins/Extensions/EasyMedia/bg.png" position="0,0" size="450,576"/>
181                         <ePixmap pixmap="/usr/lib/enigma2/python/Plugins/Extensions/EasyMedia/bg.png" position="0,576" size="450,145"/>
182                         <widget name="list" position="60,30" size="350,660" scrollbarMode="showNever" transparent="1" zPosition="2"/>
183                 </screen>"""
184         elif sz_w > 1000:
185                 skin = """
186                 <screen flags="wfNoBorder" position="-20,0" size="450,576" title="Easy Media">
187                         <ePixmap pixmap="/usr/lib/enigma2/python/Plugins/Extensions/EasyMedia/bg.png" position="0,0" size="450,576"/>
188                         <widget name="list" position="70,48" size="320,480" scrollbarMode="showNever" transparent="1" zPosition="2"/>
189                 </screen>"""
190         else:
191                 skin = """
192                 <screen position="center,center" size="320,440" title="Easy Media">
193                         <widget name="list" position="10,10" size="300,420" scrollbarMode="showOnDemand" />
194                 </screen>"""
195         def __init__(self, session):
196                 Screen.__init__(self, session)
197                 self.session = session
198                 self.list = []
199                 self.__keys = []
200                 MPaskList = []
201                 if True:
202                         self.__keys.append("movies")
203                         MPaskList.append((_("Movies"), "PLAYMOVIES"))
204                 if config.plugins.easyMedia.bookmarks.value != "no":
205                         self.__keys.append("bookmarks")
206                         MPaskList.append((_("Bookmarks"), "BOOKMARKS"))
207                 if True:
208                         self.__keys.append("pictures")
209                         MPaskList.append((_("Pictures"), "PICTURES"))
210                 if config.plugins.easyMedia.music.value != "no":
211                         self.__keys.append("music")
212                         MPaskList.append((_("Music"), "MUSIC"))
213                 if config.plugins.easyMedia.dvd.value != "no":
214                         self.__keys.append("dvd")
215                         MPaskList.append((_("DVD Player"), "DVD"))
216                 if config.plugins.easyMedia.weather.value != "no":
217                         self.__keys.append("weather")
218                         MPaskList.append((_("Weather"), "WEATHER"))
219                 if config.plugins.easyMedia.files.value != "no":
220                         self.__keys.append("files")
221                         MPaskList.append((_("Files"), "FILES"))
222                 if config.plugins.easyMedia.iradio.value != "no":
223                         self.__keys.append("shoutcast")
224                         MPaskList.append((_("SHOUTcast"), "SHOUTCAST"))
225                 if config.plugins.easyMedia.idream.value != "no":
226                         self.__keys.append("idream")
227                         MPaskList.append((_("iDream"), "IDREAM"))
228                 if config.plugins.easyMedia.mytube.value != "no":
229                         self.__keys.append("mytube")
230                         MPaskList.append((_("MyTube Player"), "MYTUBE"))
231                 if config.plugins.easyMedia.vlc.value != "no":
232                         self.__keys.append("vlc")
233                         MPaskList.append((_("VLC Player"), "VLC"))
234                 if config.plugins.easyMedia.zdfmedia.value != "no":
235                         self.__keys.append("zdf")
236                         MPaskList.append((_("ZDFmediathek"), "ZDF"))
237                 self.keymap = {}
238                 pos = 0
239                 for x in MPaskList:
240                         strpos = str(self.__keys[pos])
241                         self.list.append(MPanelEntryComponent(key = strpos, text = x))
242                         if self.__keys[pos] != "":
243                                 self.keymap[self.__keys[pos]] = MPaskList[pos]
244                         pos += 1
245                 self["list"] = MPanelList(list = self.list, selection = 0)
246                 self["actions"] = ActionMap(["WizardActions", "MenuActions"],
247                 {
248                         "ok": self.go,
249                         "back": self.cancel,
250                         "menu": self.emContextMenu
251                 }, -1)
252
253         def cancel(self):
254                 self.close(None)
255
256         def go(self):
257                 cursel = self["list"].l.getCurrentSelection()
258                 if cursel:
259                         self.goEntry(cursel[0])
260                 else:
261                         self.cancel()
262
263         def goEntry(self, entry):
264                 if len(entry) > 2 and isinstance(entry[1], str) and entry[1] == "CALLFUNC":
265                         arg = self["list"].l.getCurrentSelection()[0]
266                         entry[2](arg)
267                 else:
268                         self.close(entry)
269
270         def emContextMenu(self):
271                 self.session.open(ConfigEasyMedia)
272
273
274
275 def MPcallbackFunc(answer):
276         answer = answer and answer[1]
277         if answer == "PLAYMOVIES":
278                 if InfoBar_instance:
279                         InfoBar_instance.showMovies()
280         elif answer == "BOOKMARKS":
281                 tmpBookmarks = config.movielist.videodirs
282                 myBookmarks = tmpBookmarks and tmpBookmarks.value[:] or []
283                 if len(myBookmarks)>0:
284                         askBM = []
285                         for s in myBookmarks:
286                                 askBM.append((s, s))
287                         EMsession.openWithCallback(BookmarksCallback, ChoiceBox, title=_("Select bookmark..."), list = askBM)
288         elif answer == "PICTURES":
289                 if fileExists("/usr/lib/enigma2/python/Plugins/Extensions/PicturePlayer/plugin.pyo"):
290                         from Plugins.Extensions.PicturePlayer.plugin import picshow
291                         EMsession.open(picshow)
292                 else:
293                         EMsession.open(MessageBox, text = _('Picture-player is not installed!'), type = MessageBox.TYPE_ERROR)
294         elif answer == "MUSIC":
295                 if fileExists("/usr/lib/enigma2/python/Plugins/Extensions/MerlinMusicPlayer/plugin.pyo") and (config.plugins.easyMedia.music.value == "merlinmp"):
296                         from Plugins.Extensions.MerlinMusicPlayer.plugin import MerlinMusicPlayerFileList
297                         servicelist = None
298                         EMsession.open(MerlinMusicPlayerFileList, servicelist)
299                 elif fileExists("/usr/lib/enigma2/python/Plugins/Extensions/MediaPlayer/plugin.pyo") and (config.plugins.easyMedia.music.value == "mediaplayer"):
300                         from Plugins.Extensions.MediaPlayer.plugin import MediaPlayer
301                         EMsession.open(MediaPlayer)
302                 else:
303                         EMsession.open(MessageBox, text = _('No Music-Player installed!'), type = MessageBox.TYPE_ERROR)
304         elif answer == "FILES":
305                 if fileExists("/usr/lib/enigma2/python/Plugins/Extensions/Tuxcom/plugin.pyo") and (config.plugins.easyMedia.files.value == "tuxcom"):
306                         from Plugins.Extensions.Tuxcom.plugin import TuxComStarter
307                         EMsession.open(TuxComStarter)
308                 elif fileExists("/usr/lib/enigma2/python/Plugins/Extensions/DreamExplorer/plugin.pyo") and (config.plugins.easyMedia.files.value == "dreamexplorer"):
309                         from Plugins.Extensions.DreamExplorer.plugin import DreamExplorerII
310                         EMsession.open(DreamExplorerII)
311                 elif fileExists("/usr/lib/enigma2/python/Plugins/Extensions/Filebrowser/plugin.pyo") and (config.plugins.easyMedia.files.value == "filebrowser"):
312                         from Plugins.Extensions.Filebrowser.plugin import FilebrowserScreen
313                         EMsession.open(FilebrowserScreen)
314                 else:
315                         EMsession.open(MessageBox, text = _('No File-Manager installed!'), type = MessageBox.TYPE_ERROR)
316         elif answer == "WEATHER":
317                 if fileExists("/usr/lib/enigma2/python/Plugins/Extensions/WeatherPlugin/plugin.pyo"):
318                         from Plugins.Extensions.WeatherPlugin.plugin import WeatherPlugin
319                         EMsession.open(WeatherPlugin)
320                 else:
321                         EMsession.open(MessageBox, text = _('Weather Plugin is not installed!'), type = MessageBox.TYPE_ERROR)
322         elif answer == "DVD":
323                 if fileExists("/usr/lib/enigma2/python/Plugins/Extensions/DVDPlayer/plugin.pyo"):
324                         from Plugins.Extensions.DVDPlayer.plugin import DVDPlayer
325                         EMsession.open(DVDPlayer)
326                 else:
327                         EMsession.open(MessageBox, text = _('DVDPlayer Plugin is not installed!'), type = MessageBox.TYPE_ERROR)
328         elif answer == "MYTUBE":
329                 if fileExists("/usr/lib/enigma2/python/Plugins/Extensions/MyTube/plugin.pyo"):
330                         from Plugins.Extensions.MyTube.plugin import *
331                         MyTubeMain(EMsession)
332                 else:
333                         EMsession.open(MessageBox, text = _('MyTube Plugin is not installed!'), type = MessageBox.TYPE_ERROR)
334         elif answer == "SHOUTCAST":
335                 if fileExists("/usr/lib/enigma2/python/Plugins/Extensions/SHOUTcast/plugin.pyo"):
336                         from Plugins.Extensions.SHOUTcast.plugin import SHOUTcastWidget
337                         EMsession.open(SHOUTcastWidget)
338                 else:
339                         EMsession.open(MessageBox, text = _('SHOUTcast Plugin is not installed!'), type = MessageBox.TYPE_ERROR)
340         elif answer == "ZDF":
341                 if fileExists("/usr/lib/enigma2/python/Plugins/Extensions/ZDFMediathek/plugin.pyo"):
342                         from Plugins.Extensions.ZDFMediathek.plugin import ZDFMediathek
343                         EMsession.open(ZDFMediathek)
344                 else:
345                         EMsession.open(MessageBox, text = _('ZDFmediathek Plugin is not installed!'), type = MessageBox.TYPE_ERROR)
346         elif answer == "VLC":
347                 if fileExists("/usr/lib/enigma2/python/Plugins/Extensions/VlcPlayer/plugin.pyo"):
348                         from Plugins.Extensions.VlcPlayer.plugin import *
349                         main(EMsession)
350                 else:
351                         EMsession.open(MessageBox, text = _('VLC Player is not installed!'), type = MessageBox.TYPE_ERROR)
352         elif answer == "IDREAM":
353                 if fileExists("/usr/lib/enigma2/python/Plugins/Extensions/MerlinMusicPlayer/plugin.pyo"):
354                         from Plugins.Extensions.MerlinMusicPlayer.plugin import iDreamMerlin
355                         servicelist = None
356                         EMsession.open(iDreamMerlin, servicelist)
357                 else:
358                         EMsession.open(MessageBox, text = _('Merlin iDream is not installed!'), type = MessageBox.TYPE_ERROR)
359
360
361
362
363
364
365
366
367
368
369
370
371
372