redesign with playlist support. thanks to voc
[enigma2-plugins.git] / vlcplayer / src / VlcPlayList.py
1 # -*- coding: ISO-8859-1 -*-
2 #===============================================================================
3 # VLC Player Plugin by A. Lätsch 2007
4 #                   modified by Volker Christian 2008
5 #
6 # This is free software; you can redistribute it and/or modify it under
7 # the terms of the GNU General Public License as published by the Free
8 # Software Foundation; either version 2, or (at your option) any later
9 # version.
10 #===============================================================================
11
12
13 from enigma import eListboxPythonMultiContent, RT_HALIGN_LEFT, gFont
14
15 from Tools.LoadPixmap import LoadPixmap
16 from Tools.Directories import SCOPE_SKIN_IMAGE, resolveFilename
17 from Components.MenuList import MenuList
18
19
20 def VlcPlayListEntry(name, path, id):
21         res = [ (path, id) ]
22         res.append((eListboxPythonMultiContent.TYPE_TEXT, 35, 1, 470, 20, 0, RT_HALIGN_LEFT, name))
23
24         png = LoadPixmap(resolveFilename(SCOPE_SKIN_IMAGE, "extensions/movie.png"))
25
26         if png is not None:
27                 res.append((eListboxPythonMultiContent.TYPE_PIXMAP_ALPHATEST, 10, 2, 20, 20, png))
28
29         return res
30
31
32 class VlcPlayList(MenuList):
33         def __init__(self, server):
34                 MenuList.__init__(self, list, False, eListboxPythonMultiContent)
35                 self.l.setFont(0, gFont("Regular", 18))
36                 self.l.setItemHeight(23)
37                 self.server = server
38
39         def update(self):
40                 files = self.server.getPlaylistEntries()
41                 fileEntries = []
42                 for file in files:
43                         [name, path, id, isCurrent] = file
44                         fileEntries.append(VlcPlayListEntry(name, path, id))
45                 fileEntries.sort(cmp = lambda x, y: cmp(x[0], y[0]))
46                 self.list = fileEntries
47                 self.l.setList(self.list)
48                 self.moveToIndex(0)
49
50         def activate(self):
51                 if self.getCurrent() is not None:
52                         ret = self.getCurrent()[0][0], self.getCurrent()[1][7]
53                 return ret
54
55         def getNextFile(self):
56                 i = self.getSelectedIndex() + 1
57                 if i < len(self.list):
58                         self.moveToIndex(i)
59                         return self.getCurrent()[0][0], self.getCurrent()[1][7]
60                 return None, None
61
62         def getPrevFile(self):
63                 i = self.getSelectedIndex() - 1
64                 if i < len(self.list):
65                         self.moveToIndex(i)
66                         return self.getCurrent()[0][0], self.getCurrent()[1][7]
67                 return None, None