X-Git-Url: https://git.cweiske.de/enigma2.git/blobdiff_plain/4df5c9884064664ed716fdd79cdd9d56b74be7e2..319b1d154578f02388b6a7910c5048ed3bab1343:/lib/python/Components/FileList.py diff --git a/lib/python/Components/FileList.py b/lib/python/Components/FileList.py index 961eb09d..d726b833 100644 --- a/lib/python/Components/FileList.py +++ b/lib/python/Components/FileList.py @@ -20,6 +20,7 @@ RT_VALIGN_BOTTOM = 16 EXTENSIONS = { "mp3": "music", "wav": "music", + "ogg": "music", "jpg": "picture", "jpeg": "picture", "png": "picture", @@ -29,28 +30,32 @@ EXTENSIONS = { "mpeg": "movie", } -def FileEntryComponent(name, absolute, isDir = False): +def FileEntryComponent(name, absolute = None, isDir = False): res = [ (absolute, isDir) ] - res.append((eListboxPythonMultiContent.TYPE_TEXT, 35, 1, 200, 20, 0, RT_HALIGN_LEFT ,name)) + res.append((eListboxPythonMultiContent.TYPE_TEXT, 35, 1, 200, 20, 0, RT_HALIGN_LEFT, name)) if isDir: - png = loadPNG(resolveFilename(SCOPE_SKIN_IMAGE, "/extensions/directory.png")) + png = loadPNG(resolveFilename(SCOPE_SKIN_IMAGE, "extensions/directory.png")) else: extension = name.split('.') extension = extension[-1] if EXTENSIONS.has_key(extension): - png = loadPNG(resolveFilename(SCOPE_SKIN_IMAGE, "/extensions/" + EXTENSIONS[extension] + ".png")) + png = loadPNG(resolveFilename(SCOPE_SKIN_IMAGE, "extensions/" + EXTENSIONS[extension] + ".png")) + else: + png = None if png is not None: res.append((eListboxPythonMultiContent.TYPE_PIXMAP_ALPHATEST, 10, 2, 20, 20, png)) return res class FileList(HTMLComponent, GUIComponent, MenuList): - def __init__(self, directory, showDirectories = True, showFiles = True, matchingPattern = None): + def __init__(self, directory, showDirectories = True, showFiles = True, matchingPattern = None, useServiceRef = False, isTop = False): GUIComponent.__init__(self) self.l = eListboxPythonMultiContent() - + + self.useServiceRef = useServiceRef self.showDirectories = showDirectories self.showFiles = showFiles + self.isTop = isTop # example: matching .nfi and .ts files: "^.*\.(nfi|ts)" self.matchingPattern = matchingPattern self.changeDir(directory) @@ -60,37 +65,77 @@ class FileList(HTMLComponent, GUIComponent, MenuList): def getSelection(self): return self.l.getCurrentSelection()[0] + def getFileList(self): + return self.list + def changeDir(self, directory): self.list = [] - files = os.listdir(directory) - files.sort() + directories = [] + files = [] - if directory != "/" and self.showDirectories: - self.list.append(FileEntryComponent(name = "..", absolute = '/'.join(directory.split('/')[:-2]) + '/', isDir = True)) + if self.useServiceRef: + root = eServiceReference("2:0:1:0:0:0:0:0:0:0:" + directory) + serviceHandler = eServiceCenter.getInstance() + list = serviceHandler.list(root) - directories = [] - for x in files: - if os.path.isdir(directory + x): - directories.append(x) - files.remove(x) + while 1: + s = list.getNext() + if not s.valid(): + del list + break + if s.flags & s.mustDescent: + directories.append(s.getPath()) + else: + files.append(s) + print s.getName(), s.flags + else: + files = os.listdir(directory) + files.sort() + tmpfiles = files[:] + for x in tmpfiles: + if os.path.isdir(directory + x): + directories.append(x) + files.remove(x) + + if directory != "/" and self.showDirectories and not self.isTop: + self.list.append(FileEntryComponent(name = "..", absolute = '/'.join(directory.split('/')[:-2]) + '/', isDir = True)) if self.showDirectories: for x in directories: - self.list.append(FileEntryComponent(name = x, absolute = directory + x + "/" , isDir = True)) + name = x.split('/')[-2] + self.list.append(FileEntryComponent(name = name, absolute = x, isDir = True)) - if self.showFiles: for x in files: + if self.useServiceRef: + path = x.getPath() + name = path.split('/')[-1] + else: + path = directory + x + name = x + if self.matchingPattern is not None: - if re.compile(self.matchingPattern).search(x): - self.list.append(FileEntryComponent(name = x, absolute = directory + x , isDir = False)) + if re.compile(self.matchingPattern).search(path): + self.list.append(FileEntryComponent(name = name, absolute = x , isDir = False)) else: - self.list.append(FileEntryComponent(name = x, absolute = directory + x , isDir = False)) + self.list.append(FileEntryComponent(name = name, absolute = x , isDir = False)) self.l.setList(self.list) + + def canDescent(self): + return self.getSelection()[1] + + def descent(self): + self.changeDir(self.getSelection()[0]) + + def getFilename(self): + return self.getSelection()[0].getPath() + + def getServiceRef(self): + return self.getSelection()[0] def GUIcreate(self, parent): self.instance = eListbox(parent) self.instance.setContent(self.l) - self.instance.setItemHeight(23) \ No newline at end of file + self.instance.setItemHeight(23)