Much improved error handling
[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, server, getPlaylistEntriesCB):
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                 self.getPlaylistEntriesCB = getPlaylistEntriesCB
39
40         def update(self):
41                 files = self.getPlaylistEntriesCB()
42                 fileEntries = []
43                 if files is not None:
44                         for file in files:
45                                 [name, path] = file
46                                 fileEntries.append(VlcPlayListEntry(name, path))
47                         fileEntries.sort(cmp = lambda x, y: cmp(x[1][7], y[1][7]))
48                 self.list = fileEntries
49                 self.l.setList(self.list)
50                 self.moveToIndex(0)
51
52         def activate(self):
53                 if self.getCurrent() is not None:
54                         ret = self.getCurrent()[0], self.getCurrent()[1][7]
55                 return ret
56
57         def getNextFile(self):
58                 i = self.getSelectedIndex() + 1
59                 if i < len(self.list):
60                         self.moveToIndex(i)
61                         return self.getCurrent()[0], self.getCurrent()[1][7]
62                 return None, None
63
64         def getPrevFile(self):
65                 i = self.getSelectedIndex() - 1
66                 if i < len(self.list):
67                         self.moveToIndex(i)
68                         return self.getCurrent()[0], self.getCurrent()[1][7]
69                 return None, None