Italian locale updated
[enigma2-plugins.git] / vlcplayer / src / VlcFileList.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 import re
14
15 from enigma import eListboxPythonMultiContent, RT_HALIGN_LEFT, gFont
16 from Tools.LoadPixmap import LoadPixmap
17 from Tools.Directories import SCOPE_SKIN_IMAGE, SCOPE_PLUGINS, resolveFilename
18 from Components.MenuList import MenuList
19
20 from pyexpat import ExpatError
21
22
23 MEDIA_EXTENSIONS = {
24                 "mp3": "music",
25                 "wav": "music",
26                 "ogg": "music",
27                 "ts": "movie",
28                 "avi": "movie",
29                 "mpg": "movie",
30                 "mpeg": "movie",
31                 "wmv": "movie",
32                 "mov": "movie",
33                 "iso": "movie",
34                 "flv": "movie"
35         }
36
37
38 PLAYLIST_EXTENSIONS = {
39                 "m3u": "playlist.png",
40                 "pls": "playlist.png",
41                 "xspf": "playlist.png",
42         }
43
44
45 def VlcFileListEntry(name, path, isDir = False):
46         res = [ (path, isDir) ]
47         res.append((eListboxPythonMultiContent.TYPE_TEXT, 35, 1, 470, 20, 0, RT_HALIGN_LEFT, name))
48         if isDir:
49                 png = LoadPixmap(resolveFilename(SCOPE_SKIN_IMAGE, "extensions/directory.png"))
50         else:
51                 extension = name.split('.')
52                 extension = extension[-1].lower()
53                 if MEDIA_EXTENSIONS.has_key(extension):
54                         png = LoadPixmap(resolveFilename(SCOPE_SKIN_IMAGE, "extensions/" + MEDIA_EXTENSIONS[extension] + ".png"))
55                 elif PLAYLIST_EXTENSIONS.has_key(extension):
56                         png = LoadPixmap(resolveFilename(SCOPE_PLUGINS, "Extensions/VlcPlayer/") + PLAYLIST_EXTENSIONS[extension])
57                 else:
58                         png = None
59         if png is not None:
60                 res.append((eListboxPythonMultiContent.TYPE_PIXMAP_ALPHATEST, 10, 2, 20, 20, png))
61
62         return res
63
64
65 class VlcFileList(MenuList):
66         def __init__(self, getFilesAndDirsCB, baseDir, matchingPattern):
67                 MenuList.__init__(self, list, False, eListboxPythonMultiContent)
68                 self.l.setFont(0, gFont("Regular", 18))
69                 self.l.setItemHeight(23)
70                 self.currentDirectory = baseDir
71                 self.getFilesAndDirsCB = getFilesAndDirsCB
72                 self.changeRegex(matchingPattern)
73
74         def update(self):
75                 success = False
76                 filelistEntries = self.getFilesAndDirsCB(self.currentDirectory, self.regex)
77                 fileEntries = []
78                 directoryEntries = []
79                 if filelistEntries is not None:
80                         files, directories = filelistEntries
81                         for file in files:
82                                 [name, path] = file
83                                 fileEntries.append(VlcFileListEntry(name, path))
84                         for directory in directories:
85                                 [name, path] = directory
86                                 directoryEntries.append(VlcFileListEntry(name, path, True))
87                         fileEntries.sort(cmp = lambda x, y: cmp(x[0], y[0]))
88                         directoryEntries.sort(cmp = lambda x, y: cmp(x[0], y[0]))
89                         success = True
90                 self.list = directoryEntries + fileEntries
91                 self.l.setList(self.list)
92                 self.moveToIndex(0)
93                 return success
94
95         def isVideoTS(self):
96                 for e in self.list:
97                         if e[0][1] == True and e[0][0].upper().endswith("VIDEO_TS"):
98                                 return True
99                 return False
100
101         def changeDirectory(self, directory):
102                 previousDirectory = self.currentDirectory
103                 self.currentDirectory = directory
104                 try:
105                         if self.update():
106                                 if self.isVideoTS():
107                                         ret = "dvdsimple://" + self.currentDirectory + "/VIDEO_TS", self.currentDirectory
108                                         self.currentDirectory = previousDirectory
109                                         self.update()
110                                 else:
111                                         ret = None, self.currentDirectory
112                         else:
113                                 self.currentDirectory = previousDirectory
114                                 ret = None, None
115                 except ExpatError, e:
116                         self.currentDirectory = previousDirectory
117                         self.update()
118                         ret = None, self.currentDirectory
119                 return ret
120
121         def activate(self):
122                 if self.getCurrent() is not None:
123                         if self.getCurrent()[0][1]:
124                                 ret = self.changeDirectory(self.getCurrent()[0][0])
125                         else:
126                                 ret = self.getCurrent()[0][0], self.getCurrent()[1][7]
127                 else:
128                         ret = None, None
129                 return ret
130
131         def changeRegex(self, matchingPattern):
132                 if matchingPattern is not None:
133                         self.regex = re.compile(matchingPattern)
134                 else:
135                         self.regex = None
136
137         def getNextFile(self):
138                 i = self.getSelectedIndex() + 1
139                 while i < len(self.list):
140                         if self.list[i][0][1] == False:
141                                 self.moveToIndex(i)
142                                 return self.getCurrent()[0][0], self.getCurrent()[1][7]
143                         i = i + 1
144                 return None, None
145
146         def getPrevFile(self):
147                 i = self.getSelectedIndex() - 1
148                 while i >= 0:
149                         if self.list[i][0][1] == False:
150                                 self.moveToIndex(i)
151                                 return self.getCurrent()[0][0], self.getCurrent()[1][7]
152                         i = i - 1
153                 return None, None