add SOUTcast, MyTube and DVDPlayer
[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
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         MPaskList = [(_("Movies"), "PLAYMOVIES"),
82                                 (_("Pictures"), "PICTURES"),
83                                 (_("Music"), "MUSIC"),
84                                 (_("DVD Player"), "DVD"),
85                                 (_("Weather"), "WEATHER"),
86                                 (_("Files"), "FILES"),
87                                 (_("SHOUTcast"), "SHOUTCAST"),
88                                 (_("MyTube Player"), "MYTUBE")]
89         self.session.openWithCallback(MPcallbackFunc, EasyMedia, list=MPaskList)
90
91
92
93 def MPanelEntryComponent(key, text):
94         res = [ text ]
95         res.append((eListboxPythonMultiContent.TYPE_TEXT, 160, 15, 300, 60, 0, RT_HALIGN_LEFT, text[0]))
96         png = LoadPixmap('/usr/lib/enigma2/python/Plugins/Extensions/EasyMedia/' + key + ".png")
97         if png is not None:
98                 res.append((eListboxPythonMultiContent.TYPE_PIXMAP_ALPHATEST, 30, 5, 100, 50, png))
99         return res
100
101
102
103 class MPanelList(MenuList):
104         def __init__(self, list, selection = 0, enableWrapAround=True):
105                 MenuList.__init__(self, list, enableWrapAround, eListboxPythonMultiContent)
106                 self.l.setFont(0, gFont("Regular", 24))
107                 self.l.setItemHeight(60)
108                 self.selection = selection
109         def postWidgetCreate(self, instance):
110                 MenuList.postWidgetCreate(self, instance)
111                 self.moveToIndex(self.selection)
112
113
114
115 class EasyMedia(Screen):
116         skin = """
117         <screen position="center,center" size="420,380" title="Easy Media">
118                 <widget name="list" position="10,10" size="400,360" scrollbarMode="showOnDemand" />
119         </screen>"""
120         def __init__(self, session, list = []):
121                 Screen.__init__(self, session)
122                 self.list = []
123                 self.__keys = [ "movies", "pictures", "music", "dvd", "weather", "files", "shoutcast", "mytube" ]
124                 self.keymap = {}
125                 pos = 0
126                 for x in list:
127                         strpos = str(self.__keys[pos])
128                         self.list.append(MPanelEntryComponent(key = strpos, text = x))
129                         if self.__keys[pos] != "":
130                                 self.keymap[self.__keys[pos]] = list[pos]
131                         pos += 1
132                 self["list"] = MPanelList(list = self.list, selection = 0)
133                 self["actions"] = ActionMap(["WizardActions"],
134                 {
135                         "ok": self.go,
136                         "back": self.cancel
137                 }, -1)
138
139         def cancel(self):
140                 self.close(None)
141
142         def go(self):
143                 cursel = self["list"].l.getCurrentSelection()
144                 if cursel:
145                         self.goEntry(cursel[0])
146                 else:
147                         self.cancel()
148
149         def goEntry(self, entry):
150                 if len(entry) > 2 and isinstance(entry[1], str) and entry[1] == "CALLFUNC":
151                         arg = self["list"].l.getCurrentSelection()[0]
152                         entry[2](arg)
153                 else:
154                         self.close(entry)
155
156
157
158 def MPcallbackFunc(answer):
159         answer = answer and answer[1]
160         if answer == "PLAYMOVIES":
161                 if InfoBar and InfoBar.instance:
162                         InfoBar.showMovies(InfoBar.instance)
163         elif answer == "PICTURES":
164                 if fileExists("/usr/lib/enigma2/python/Plugins/Extensions/PicturePlayer/plugin.pyo"):
165                         from Plugins.Extensions.PicturePlayer.plugin import picshow
166                         EMsession.open(picshow)
167                 else:
168                         EMsession.open(MessageBox, text = _('Picture-player is not installed!'), type = MessageBox.TYPE_ERROR)
169         elif answer == "MUSIC":
170                 if fileExists("/usr/lib/enigma2/python/Plugins/Extensions/MerlinMusicPlayer/plugin.pyo"):
171                         from Plugins.Extensions.MerlinMusicPlayer.plugin import MerlinMusicPlayerFileList
172                         servicelist = None
173                         EMsession.open(MerlinMusicPlayerFileList, servicelist)
174                 elif fileExists("/usr/lib/enigma2/python/Plugins/Extensions/MediaPlayer/plugin.pyo"):
175                         from Plugins.Extensions.MediaPlayer.plugin import MediaPlayer
176                         EMsession.open(MediaPlayer)
177                 else:
178                         EMsession.open(MessageBox, text = _('No Music-Player installed!'), type = MessageBox.TYPE_ERROR)
179         elif answer == "FILES":
180                 if fileExists("/usr/lib/enigma2/python/Plugins/Extensions/Tuxcom/plugin.pyo"):
181                         from Plugins.Extensions.Tuxcom.plugin import TuxComStarter
182                         EMsession.open(TuxComStarter)
183                 elif fileExists("/usr/lib/enigma2/python/Plugins/Extensions/DreamExplorer/plugin.pyo"):
184                         from Plugins.Extensions.DreamExplorer.plugin import DreamExplorerII
185                         EMsession.open(DreamExplorerII)
186                 elif fileExists("/usr/lib/enigma2/python/Plugins/Extensions/Filebrowser/plugin.pyo"):
187                         from Plugins.Extensions.Filebrowser.plugin import FilebrowserScreen
188                         EMsession.open(FilebrowserScreen)
189                 else:
190                         EMsession.open(MessageBox, text = _('No File-Manager installed!'), type = MessageBox.TYPE_ERROR)
191         elif answer == "WEATHER":
192                 if fileExists("/usr/lib/enigma2/python/Plugins/Extensions/WeatherPlugin/plugin.pyo"):
193                         from Plugins.Extensions.WeatherPlugin.plugin import WeatherPlugin
194                         EMsession.open(WeatherPlugin)
195                 else:
196                         EMsession.open(MessageBox, text = _('Weather Plugin is not installed!'), type = MessageBox.TYPE_ERROR)
197         elif answer == "DVD":
198                 if fileExists("/usr/lib/enigma2/python/Plugins/Extensions/DVDPlayer/plugin.pyo"):
199                         from Plugins.Extensions.DVDPlayer.plugin import DVDPlayer
200                         EMsession.open(DVDPlayer)
201                 else:
202                         EMsession.open(MessageBox, text = _('DVDPlayer Plugin is not installed!'), type = MessageBox.TYPE_ERROR)
203         elif answer == "MYTUBE":
204                 if fileExists("/usr/lib/enigma2/python/Plugins/Extensions/MyTube/plugin.pyo"):
205                         from Plugins.Extensions.MyTube.plugin import *
206                         MyTubeMain(EMsession)
207                 else:
208                         EMsession.open(MessageBox, text = _('MyTube Plugin is not installed!'), type = MessageBox.TYPE_ERROR)
209         elif answer == "SHOUTCAST":
210                 if fileExists("/usr/lib/enigma2/python/Plugins/Extensions/SHOUTcast/plugin.pyo"):
211                         from Plugins.Extensions.SHOUTcast.plugin import SHOUTcastWidget
212                         EMsession.open(SHOUTcastWidget)
213                 else:
214                         EMsession.open(MessageBox, text = _('SHOUTcast Plugin is not installed!'), type = MessageBox.TYPE_ERROR)
215         
216
217