1 from HTMLComponent import HTMLComponent
2 from GUIComponent import GUIComponent
5 from os import path as os_path, listdir
6 from MenuList import MenuList
7 from Components.Harddisk import harddiskmanager
9 from Tools.Directories import SCOPE_SKIN_IMAGE, resolveFilename
11 from enigma import RT_HALIGN_LEFT, loadPNG, eListbox, eListboxPythonMultiContent, \
12 eServiceReference, eServiceCenter, gFont
28 def FileEntryComponent(name, absolute = None, isDir = False):
29 res = [ (absolute, isDir) ]
30 res.append((eListboxPythonMultiContent.TYPE_TEXT, 35, 1, 470, 20, 0, RT_HALIGN_LEFT, name))
32 png = loadPNG(resolveFilename(SCOPE_SKIN_IMAGE, "extensions/directory.png"))
34 extension = name.split('.')
35 extension = extension[-1].lower()
36 if EXTENSIONS.has_key(extension):
37 png = loadPNG(resolveFilename(SCOPE_SKIN_IMAGE, "extensions/" + EXTENSIONS[extension] + ".png"))
41 res.append((eListboxPythonMultiContent.TYPE_PIXMAP_ALPHATEST, 10, 2, 20, 20, png))
45 class FileList(MenuList, HTMLComponent, GUIComponent):
46 def __init__(self, directory, showDirectories = True, showFiles = True, matchingPattern = None, useServiceRef = False, isTop = False):
47 GUIComponent.__init__(self)
48 self.l = eListboxPythonMultiContent()
50 self.mount_point = None
51 self.current_directory = None
52 self.useServiceRef = useServiceRef
53 self.showDirectories = showDirectories
54 self.showFiles = showFiles
56 # example: matching .nfi and .ts files: "^.*\.(nfi|ts)"
57 self.matchingPattern = matchingPattern
58 self.changeDir(directory)
60 self.l.setFont(0, gFont("Regular", 18))
61 self.l.setItemHeight(23)
62 self.serviceHandler = eServiceCenter.getInstance()
64 def getSelection(self):
65 if self.l.getCurrentSelection() is None:
67 return self.l.getCurrentSelection()[0]
69 def getSelectionIndex(self):
70 return self.l.getCurrentSelectionIndex()
72 def getCurrentEvent(self):
73 l = self.l.getCurrentSelection()
74 if not l or l[0][1] == True:
77 return self.serviceHandler.info(l[0][0]).getEvent(l[0][0])
79 def getFileList(self):
82 def changeDir(self, directory, select = None):
85 # if we are just entering from the list of mount points:
86 if self.current_directory is None:
87 self.mount_point = directory
88 self.current_directory = directory
92 if directory is None: # present available mountpoints
93 print "listing partitions:"
94 for p in harddiskmanager.getMountedPartitions():
95 if p.mountpoint == "/":
96 self.list.append(FileEntryComponent(name = p.description, absolute = p.mountpoint, isDir = True))
98 self.list.append(FileEntryComponent(name = p.description, absolute = p.mountpoint + "/", isDir = True))
101 elif self.useServiceRef:
102 root = eServiceReference("2:0:1:0:0:0:0:0:0:0:" + directory)
103 serviceHandler = eServiceCenter.getInstance()
104 list = serviceHandler.list(root)
111 if s.flags & s.mustDescent:
112 directories.append(s.getPath())
115 print s.getName(), s.flags
119 files = listdir(directory)
123 if os_path.isdir(directory + x):
124 directories.append(directory + x + "/")
127 if directory is not None and self.showDirectories and not self.isTop:
128 if directory == self.mount_point:
129 self.list.append(FileEntryComponent(name = ".. (" +_("List of Storage Devices") + ")", absolute = None, isDir = True))
131 self.list.append(FileEntryComponent(name = "..", absolute = '/'.join(directory.split('/')[:-2]) + '/', isDir = True))
133 if self.showDirectories:
134 for x in directories:
135 name = x.split('/')[-2]
136 self.list.append(FileEntryComponent(name = name, absolute = x, isDir = True))
140 if self.useServiceRef:
142 name = path.split('/')[-1]
147 if self.matchingPattern is not None:
148 if re.compile(self.matchingPattern).search(path):
149 self.list.append(FileEntryComponent(name = name, absolute = x , isDir = False))
151 self.list.append(FileEntryComponent(name = name, absolute = x , isDir = False))
153 self.l.setList(self.list)
155 if select is not None:
161 if isinstance(p, eServiceReference):
168 def getCurrentDirectory(self):
169 return self.current_directory
171 def canDescent(self):
172 if self.getSelection() is None:
174 return self.getSelection()[1]
177 if self.getSelection() is None:
179 self.changeDir(self.getSelection()[0], select = self.current_directory)
181 def getFilename(self):
182 if self.getSelection() is None:
184 x = self.getSelection()[0]
185 if isinstance(x, eServiceReference):
189 def getServiceRef(self):
190 if self.getSelection() is None:
192 x = self.getSelection()[0]
193 if isinstance(x, eServiceReference):
197 GUI_WIDGET = eListbox
199 def postWidgetCreate(self, instance):
200 instance.setContent(self.l)
203 harddiskmanager.on_partition_list_change.append(self.partitionListChanged)
206 harddiskmanager.on_partition_list_change.remove(self.partitionListChanged)
209 self.changeDir(self.current_directory, self.getFilename())
211 def partitionListChanged(self, action, device):
212 if self.current_directory is None: