Removed dependency on a reference to a server-instance
[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):
21         res = [ path ]
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, getPlaylistEntriesCB):
34                 MenuList.__init__(self, list, False, eListboxPythonMultiContent)
35                 self.l.setFont(0, gFont("Regular", 18))
36                 self.l.setItemHeight(23)
37                 self.getPlaylistEntriesCB = getPlaylistEntriesCB
38
39         def update(self):
40                 files = self.getPlaylistEntriesCB()
41                 fileEntries = []
42                 if files is not None:
43                         for file in files:
44                                 [name, path] = file
45                                 fileEntries.append(VlcPlayListEntry(name, path))
46                         fileEntries.sort(cmp = lambda x, y: cmp(x[1][7], y[1][7]))
47                 self.list = fileEntries
48                 self.l.setList(self.list)
49                 self.moveToIndex(0)
50
51         def activate(self):
52                 if self.getCurrent() is not None:
53                         ret = self.getCurrent()[0], self.getCurrent()[1][7]
54                 return ret
55
56         def getNextFile(self):
57                 i = self.getSelectedIndex() + 1
58                 if i < len(self.list):
59                         self.moveToIndex(i)
60                         return self.getCurrent()[0], self.getCurrent()[1][7]
61                 return None, None
62
63         def getPrevFile(self):
64                 i = self.getSelectedIndex() - 1
65                 if i < len(self.list):
66                         self.moveToIndex(i)
67                         return self.getCurrent()[0], self.getCurrent()[1][7]
68                 return None, None