Update Description
[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 from skin import parseFont
20
21 class VlcPlayList(MenuList):
22         def __init__(self, getPlaylistEntriesCB):
23                 MenuList.__init__(self, list, False, eListboxPythonMultiContent)
24                 self.font = gFont("Regular", 18)
25                 self.l.setFont(0, self.font)
26                 self.l.setItemHeight(23)
27                 self.l.setBuildFunc(self.buildListboxEntry)
28                 self.getPlaylistEntriesCB = getPlaylistEntriesCB
29
30         def applySkin(self, desktop, parent):
31                 attribs = [ ]
32                 if self.skinAttributes is not None:
33                         for (attrib, value) in self.skinAttributes:
34                                 if attrib == "font":
35                                         self.font = parseFont(value, ((1,1),(1,1)))
36                                         self.l.setFont(0, self.font)
37                                 elif attrib == "itemHeight":
38                                         self.l.setItemHeight(int(value))
39                                 else:
40                                         attribs.append((attrib, value))
41                         self.skinAttributes = attribs
42                 return MenuList.applySkin(self, desktop, parent)
43
44
45         def buildListboxEntry(self, name, path):
46                 size = self.l.getItemSize()
47                 height = size.height()
48                 res = [
49                         (path, name),
50                         (eListboxPythonMultiContent.TYPE_TEXT, height + 15, 0, size.width() - height - 15, height, 0, RT_HALIGN_LEFT, name)
51                 ]
52
53                 png = LoadPixmap(resolveFilename(SCOPE_SKIN_IMAGE, "extensions/movie.png"))
54
55                 if png is not None:
56                         res.append((eListboxPythonMultiContent.TYPE_PIXMAP_ALPHATEST, 10, 0, height, height, png))
57
58                 return res
59
60         def update(self):
61                 files = self.getPlaylistEntriesCB()
62                 fileEntries = []
63                 if files is not None:
64                         for file in files:
65                                 name, path = file
66                                 fileEntries.append((name, path))
67                         fileEntries.sort(cmp = lambda x, y: cmp(x[1][7], y[1][7]))
68                 self.list = fileEntries
69                 self.l.setList(self.list)
70                 self.moveToIndex(0)
71
72         def activate(self):
73                 cur = self.getCurrent()
74                 if cur is not None:
75                         return cur
76                 return None, None
77
78         def getNextFile(self):
79                 i = self.getSelectedIndex() + 1
80                 if i < len(self.list):
81                         self.moveToIndex(i)
82                         return self.getCurrent()
83                 return None, None
84
85         def getPrevFile(self):
86                 i = self.getSelectedIndex() - 1
87                 if i < len(self.list):
88                         self.moveToIndex(i)
89                         return self.getCurrent()
90                 return None, None
91