set /etc/localtime link when change the timezone too
[enigma2.git] / lib / python / Components / MediaPlayer.py
1 from HTMLComponent import HTMLComponent
2 from GUIComponent import GUIComponent
3
4 from MenuList import MenuList
5
6 from Tools.Directories import SCOPE_SKIN_IMAGE, resolveFilename
7 from os import path
8
9 from enigma import eListboxPythonMultiContent, eListbox, RT_VALIGN_CENTER, loadPNG, gFont, eServiceCenter
10
11 STATE_PLAY = 0
12 STATE_PAUSE = 1
13 STATE_STOP = 2
14 STATE_REWIND = 3
15 STATE_FORWARD = 4
16 STATE_NONE = 5
17
18 PlayIcon = loadPNG(resolveFilename(SCOPE_SKIN_IMAGE, "ico_mp_play.png"))
19 PauseIcon = loadPNG(resolveFilename(SCOPE_SKIN_IMAGE, "ico_mp_pause.png"))
20 StopIcon = loadPNG(resolveFilename(SCOPE_SKIN_IMAGE, "ico_mp_stop.png"))
21 RewindIcon = loadPNG(resolveFilename(SCOPE_SKIN_IMAGE, "ico_mp_rewind.png"))
22 ForwardIcon = loadPNG(resolveFilename(SCOPE_SKIN_IMAGE, "ico_mp_forward.png"))
23
24 def PlaylistEntryComponent(serviceref, state):
25         res = [ serviceref ]
26         res.append((eListboxPythonMultiContent.TYPE_TEXT,25, 0, 470, 32, 0, RT_VALIGN_CENTER, path.split(serviceref.getPath().split('/')[-1])[1]))
27         png = None
28         if state == STATE_PLAY:
29                 png = PlayIcon
30         elif state == STATE_PAUSE:
31                 png = PauseIcon
32         elif state == STATE_STOP:
33                 png = StopIcon
34         elif state == STATE_REWIND:
35                 png = RewindIcon
36         elif state == STATE_FORWARD:
37                 png = ForwardIcon
38
39         if png is not None:
40                 res.append((eListboxPythonMultiContent.TYPE_PIXMAP_ALPHATEST, 5, 0, 16, 16, png))
41     
42         return res
43
44 class PlayList(MenuList, HTMLComponent, GUIComponent):
45         def __init__(self):
46                 GUIComponent.__init__(self)
47                 self.l = eListboxPythonMultiContent()
48                 self.list = []
49                 self.l.setList(self.list)
50                 self.l.setFont(0, gFont("Regular", 18))
51                 self.l.setItemHeight(22)
52                 self.currPlaying = -1
53                 self.oldCurrPlaying = -1
54                 self.serviceHandler = eServiceCenter.getInstance()
55         
56         def clear(self):
57                 del self.list[:]
58                 self.l.setList(self.list)
59                 self.currPlaying = -1
60                 self.oldCurrPlaying = -1
61
62         GUI_WIDGET = eListbox
63
64         def postWidgetCreate(self, instance):
65                 instance.setContent(self.l)
66
67         def getSelection(self):
68                 return self.l.getCurrentSelection()[0]
69                 
70         def getSelectionIndex(self):
71                 return self.l.getCurrentSelectionIndex()
72
73         def addFile(self, serviceref):
74                 self.list.append(PlaylistEntryComponent(serviceref, STATE_NONE))
75
76         def deleteFile(self, index):
77                 if self.currPlaying >= index:
78                         self.currPlaying -= 1
79                 del self.list[index]
80
81         def setCurrentPlaying(self, index):
82                 self.oldCurrPlaying = self.currPlaying
83                 self.currPlaying = index
84         
85         def updateState(self, state):
86                 if len(self.list) > self.oldCurrPlaying and self.oldCurrPlaying != -1:
87                         self.list[self.oldCurrPlaying] = PlaylistEntryComponent(self.list[self.oldCurrPlaying][0], STATE_NONE)
88                 if self.currPlaying != -1 and self.currPlaying < len(self.list):
89                         self.list[self.currPlaying] = PlaylistEntryComponent(self.list[self.currPlaying][0], state)
90                 self.updateList()
91
92         def playFile(self):
93                 self.updateState(STATE_PLAY)
94
95         def pauseFile(self):
96                 self.updateState(STATE_PAUSE)
97                 
98         def stopFile(self):
99                 self.updateState(STATE_STOP)
100
101         def rewindFile(self):
102                 self.updateState(STATE_REWIND)
103                 
104         def forwardFile(self):
105                 self.updateState(STATE_FORWARD)
106         
107         def updateList(self):
108                 self.l.setList(self.list)
109                 
110         def getCurrentIndex(self):
111                 return self.currPlaying
112
113         def getCurrentEvent(self):
114                 l = self.l.getCurrentSelection()
115                 return l and self.serviceHandler.info(l[0]).getEvent(l[0])
116
117         def getCurrent(self):
118                 l = self.l.getCurrentSelection()
119                 return l and l[0]
120         
121         def getServiceRefList(self):
122                 return [ x[0] for x in self.list ]
123         
124         def __len__(self):
125                 return len(self.list)