redesign screen, add VLC player and ZDFmediatheck
[enigma2-plugins.git] / 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 Screens.Screen import Screen
27 from Screens.MessageBox import MessageBox
28 from Screens.InfoBarGenerics import InfoBarPlugins
29 from Screens.InfoBar import InfoBar
30 from Plugins.Plugin import PluginDescriptor
31 from Components.ActionMap import ActionMap
32 from Components.MenuList import MenuList
33 from Tools.Directories import fileExists
34 from Tools.LoadPixmap import LoadPixmap
35 from enigma import RT_HALIGN_LEFT, eListboxPythonMultiContent, gFont, getDesktop
36
37
38
39 EMbaseInfoBarPlugins__init__ = None
40 EMStartOnlyOneTime = False
41 EMsession = None
42
43
44
45 def Plugins(**kwargs):
46         return [PluginDescriptor(where = PluginDescriptor.WHERE_SESSIONSTART, fnc = EasyMediaAutostart)]
47
48
49
50 def EasyMediaAutostart(reason, **kwargs):
51         global EMbaseInfoBarPlugins__init__
52         if "session" in kwargs:
53                 global EMsession
54                 EMsession = kwargs["session"]
55                 if EMbaseInfoBarPlugins__init__ is None:
56                         EMbaseInfoBarPlugins__init__ = InfoBarPlugins.__init__
57                 InfoBarPlugins.__init__ = InfoBarPlugins__init__
58                 InfoBarPlugins.pvr = pvr
59
60
61
62 def InfoBarPlugins__init__(self):
63         global EMStartOnlyOneTime
64         if not EMStartOnlyOneTime: 
65                 EMStartOnlyOneTime = True
66                 self["EasyMediaActions"] = ActionMap(["EasyMediaActions"],
67                         {"video_but": self.pvr}, -1)
68         else:
69                 InfoBarPlugins.__init__ = InfoBarPlugins.__init__
70                 InfoBarPlugins.green = None
71                 InfoBarPlugins.yellow = None
72                 InfoBarPlugins.red = None
73                 InfoBarPlugins.blue = None
74                 InfoBarPlugins.pvr = None
75                 InfoBarPlugins.radio = None
76         EMbaseInfoBarPlugins__init__(self)
77
78
79
80 def pvr(self):
81         self.session.openWithCallback(MPcallbackFunc, EasyMedia)
82
83
84
85 def MPanelEntryComponent(key, text):
86         res = [ text ]
87         res.append((eListboxPythonMultiContent.TYPE_TEXT, 160, 15, 300, 60, 0, RT_HALIGN_LEFT, text[0]))
88         png = LoadPixmap('/usr/lib/enigma2/python/Plugins/Extensions/EasyMedia/' + key + ".png")
89         if png is not None:
90                 res.append((eListboxPythonMultiContent.TYPE_PIXMAP_ALPHATEST, 30, 5, 100, 50, png))
91         return res
92
93
94
95 class MPanelList(MenuList):
96         def __init__(self, list, selection = 0, enableWrapAround=True):
97                 MenuList.__init__(self, list, enableWrapAround, eListboxPythonMultiContent)
98                 self.l.setFont(0, gFont("Regular", 24))
99                 self.l.setItemHeight(60)
100                 self.selection = selection
101         def postWidgetCreate(self, instance):
102                 MenuList.postWidgetCreate(self, instance)
103                 self.moveToIndex(self.selection)
104
105
106
107 class EasyMedia(Screen):
108         sz_w = getDesktop(0).size().width()
109         if sz_w > 1100:
110                 skin = """
111                 <screen flags="wfNoBorder" position="0,0" size="450,720" title="Easy Media">
112                         <ePixmap pixmap="/usr/lib/enigma2/python/Plugins/Extensions/EasyMedia/bg.png" position="0,0" size="450,576"/>
113                         <ePixmap pixmap="/usr/lib/enigma2/python/Plugins/Extensions/EasyMedia/bg.png" position="0,576" size="450,145"/>
114                         <widget name="list" position="60,30" size="350,660" scrollbarMode="showNever" transparent="1" zPosition="2"/>
115                 </screen>"""
116         elif sz_w > 1000:
117                 skin = """
118                 <screen flags="wfNoBorder" position="-20,0" size="450,576" title="Easy Media">
119                         <ePixmap pixmap="/usr/lib/enigma2/python/Plugins/Extensions/EasyMedia/bg.png" position="0,0" size="450,576"/>
120                         <widget name="list" position="70,48" size="320,480" scrollbarMode="showNever" transparent="1" zPosition="2"/>
121                 </screen>"""
122         else:
123                 skin = """
124                 <screen position="center,center" size="320,440" title="Easy Media">
125                         <widget name="list" position="10,10" size="300,420" scrollbarMode="showOnDemand" />
126                 </screen>"""
127         def __init__(self, session):
128                 Screen.__init__(self, session)
129                 self.list = []
130                 self.__keys = [ "movies", "pictures", "music", "weather", "files" ]
131                 MPaskList = [(_("Movies"), "PLAYMOVIES"),(_("Pictures"), "PICTURES"),(_("Music"), "MUSIC"),(_("Weather"), "WEATHER"),(_("Files"), "FILES")]
132                 if fileExists("/usr/lib/enigma2/python/Plugins/Extensions/DVDPlayer/plugin.pyo"):
133                         self.__keys.append("dvd")
134                         MPaskList.append((_("DVD Player"), "DVD"))
135                 if fileExists("/usr/lib/enigma2/python/Plugins/Extensions/SHOUTcast/plugin.pyo"):
136                         self.__keys.append("shoutcast")
137                         MPaskList.append((_("SHOUTcast"), "SHOUTCAST"))
138                 if fileExists("/usr/lib/enigma2/python/Plugins/Extensions/MyTube/plugin.pyo"):
139                         self.__keys.append("mytube")
140                         MPaskList.append((_("MyTube Player"), "MYTUBE"))
141                 if fileExists("/usr/lib/enigma2/python/Plugins/Extensions/VlcPlayer/plugin.pyo"):
142                         self.__keys.append("vlc")
143                         MPaskList.append((_("VLC Player"), "VLC"))
144                 if fileExists("/usr/lib/enigma2/python/Plugins/Extensions/ZDFMediathek/plugin.pyo"):
145                         self.__keys.append("zdf")
146                         MPaskList.append((_("ZDFmediathek"), "ZDF"))
147                 self.keymap = {}
148                 pos = 0
149                 for x in MPaskList:
150                         strpos = str(self.__keys[pos])
151                         self.list.append(MPanelEntryComponent(key = strpos, text = x))
152                         if self.__keys[pos] != "":
153                                 self.keymap[self.__keys[pos]] = MPaskList[pos]
154                         pos += 1
155                 self["list"] = MPanelList(list = self.list, selection = 0)
156                 self["actions"] = ActionMap(["WizardActions", "EPGSelectActions"],
157                 {
158                         "ok": self.go,
159                         "back": self.cancel,
160                         "showMovies": self.cancel
161                 }, -1)
162
163         def cancel(self):
164                 self.close(None)
165
166         def go(self):
167                 cursel = self["list"].l.getCurrentSelection()
168                 if cursel:
169                         self.goEntry(cursel[0])
170                 else:
171                         self.cancel()
172
173         def goEntry(self, entry):
174                 if len(entry) > 2 and isinstance(entry[1], str) and entry[1] == "CALLFUNC":
175                         arg = self["list"].l.getCurrentSelection()[0]
176                         entry[2](arg)
177                 else:
178                         self.close(entry)
179
180
181
182 def MPcallbackFunc(answer):
183         answer = answer and answer[1]
184         if answer == "PLAYMOVIES":
185                 if InfoBar and InfoBar.instance:
186                         InfoBar.showMovies(InfoBar.instance)
187         elif answer == "PICTURES":
188                 if fileExists("/usr/lib/enigma2/python/Plugins/Extensions/PicturePlayer/plugin.pyo"):
189                         from Plugins.Extensions.PicturePlayer.plugin import picshow
190                         EMsession.open(picshow)
191                 else:
192                         EMsession.open(MessageBox, text = _('Picture-player is not installed!'), type = MessageBox.TYPE_ERROR)
193         elif answer == "MUSIC":
194                 if fileExists("/usr/lib/enigma2/python/Plugins/Extensions/MerlinMusicPlayer/plugin.pyo"):
195                         from Plugins.Extensions.MerlinMusicPlayer.plugin import MerlinMusicPlayerFileList
196                         servicelist = None
197                         EMsession.open(MerlinMusicPlayerFileList, servicelist)
198                 elif fileExists("/usr/lib/enigma2/python/Plugins/Extensions/MediaPlayer/plugin.pyo"):
199                         from Plugins.Extensions.MediaPlayer.plugin import MediaPlayer
200                         EMsession.open(MediaPlayer)
201                 else:
202                         EMsession.open(MessageBox, text = _('No Music-Player installed!'), type = MessageBox.TYPE_ERROR)
203         elif answer == "FILES":
204                 if fileExists("/usr/lib/enigma2/python/Plugins/Extensions/Tuxcom/plugin.pyo"):
205                         from Plugins.Extensions.Tuxcom.plugin import TuxComStarter
206                         EMsession.open(TuxComStarter)
207                 elif fileExists("/usr/lib/enigma2/python/Plugins/Extensions/DreamExplorer/plugin.pyo"):
208                         from Plugins.Extensions.DreamExplorer.plugin import DreamExplorerII
209                         EMsession.open(DreamExplorerII)
210                 elif fileExists("/usr/lib/enigma2/python/Plugins/Extensions/Filebrowser/plugin.pyo"):
211                         from Plugins.Extensions.Filebrowser.plugin import FilebrowserScreen
212                         EMsession.open(FilebrowserScreen)
213                 else:
214                         EMsession.open(MessageBox, text = _('No File-Manager installed!'), type = MessageBox.TYPE_ERROR)
215         elif answer == "WEATHER":
216                 if fileExists("/usr/lib/enigma2/python/Plugins/Extensions/WeatherPlugin/plugin.pyo"):
217                         from Plugins.Extensions.WeatherPlugin.plugin import WeatherPlugin
218                         EMsession.open(WeatherPlugin)
219                 else:
220                         EMsession.open(MessageBox, text = _('Weather Plugin is not installed!'), type = MessageBox.TYPE_ERROR)
221         elif answer == "DVD":
222                 if fileExists("/usr/lib/enigma2/python/Plugins/Extensions/DVDPlayer/plugin.pyo"):
223                         from Plugins.Extensions.DVDPlayer.plugin import DVDPlayer
224                         EMsession.open(DVDPlayer)
225                 else:
226                         EMsession.open(MessageBox, text = _('DVDPlayer Plugin is not installed!'), type = MessageBox.TYPE_ERROR)
227         elif answer == "MYTUBE":
228                 if fileExists("/usr/lib/enigma2/python/Plugins/Extensions/MyTube/plugin.pyo"):
229                         from Plugins.Extensions.MyTube.plugin import *
230                         MyTubeMain(EMsession)
231                 else:
232                         EMsession.open(MessageBox, text = _('MyTube Plugin is not installed!'), type = MessageBox.TYPE_ERROR)
233         elif answer == "SHOUTCAST":
234                 if fileExists("/usr/lib/enigma2/python/Plugins/Extensions/SHOUTcast/plugin.pyo"):
235                         from Plugins.Extensions.SHOUTcast.plugin import SHOUTcastWidget
236                         EMsession.open(SHOUTcastWidget)
237                 else:
238                         EMsession.open(MessageBox, text = _('SHOUTcast Plugin is not installed!'), type = MessageBox.TYPE_ERROR)
239         elif answer == "ZDF":
240                 if fileExists("/usr/lib/enigma2/python/Plugins/Extensions/ZDFMediathek/plugin.pyo"):
241                         from Plugins.Extensions.ZDFMediathek.plugin import ZDFMediathek
242                         EMsession.open(ZDFMediathek)
243                 else:
244                         EMsession.open(MessageBox, text = _('ZDFmediathek Plugin is not installed!'), type = MessageBox.TYPE_ERROR)
245         elif answer == "VLC":
246                 if fileExists("/usr/lib/enigma2/python/Plugins/Extensions/VlcPlayer/plugin.pyo"):
247                         from Plugins.Extensions.VlcPlayer.plugin import *
248                         main(EMsession)
249                 else:
250                         EMsession.open(MessageBox, text = _('VLC Player is not installed!'), type = MessageBox.TYPE_ERROR)
251         
252
253