def delete(self, *args):
item = self.getCurrentSelection()
if not item or args and (not args[0]):
# cancelled by user (passing any arg means it's a dialog return)
return
current = item[0]
info = item[1]
cur_path = os.path.realpath(current.getPath())
if not os.path.exists(cur_path):
# file does not exist.
return
st = os.stat(cur_path)
name = info and info.getName(current) or _("this recording")
are_you_sure = ""
pathtest = info and info.getName(current)
if not pathtest:
return
if item and isTrashFolder(item[0]):
# Red button to empty trashcan...
self.purgeAll()
return
if current.flags & eServiceReference.mustDescent:
files = 0
subdirs = 0
if '.Trash' not in cur_path and config.usage.movielist_trashcan.value:
if isFolder(item):
are_you_sure = _("Do you really want to move to the trash can ?")
# subdirs += 1 Causes spurious subdirectory to be reported, and hence requires are you sure for empty directories!
# However with this change but without other changes below an empty directory is not deleted
else:
args = True
if args:
trash = Tools.Trashcan.createTrashFolder(cur_path)
if trash:
try:
moveServiceFiles(current, trash, name, allowCopy=True)
self["list"].removeService(current)
self.showActionFeedback(_("Deleted") + " " + name)
return
except:
msg = _("Cannot move to the trash can") + "\n"
are_you_sure = _("Do you really want to delete %s ?") % name
else:
msg = _("Cannot move to the trash can") + "\n"
are_you_sure = _("Do you really want to delete %s ?") % name
for fn in os.listdir(cur_path):
if (fn != '.') and (fn != '..'):
ffn = os.path.join(cur_path, fn)
if os.path.isdir(ffn):
subdirs += 1
else:
if ffn.endswith(".ts"): # New condition to only count recordings rather than number of files (can be up to six files per recording, I think)
files += 1
if files or subdirs:
folder_filename = os.path.split(os.path.split(name)[0])[1]
# Was mbox=self.session.openWithCallback(self.delete, MessageBox, _("'%s' contains %d file(s) and %d sub-directories.\n") % (folder_filename,files,subdirs) + are_you_sure)
# Replacement line to reflect it is now a recording rather than file count:
mbox=self.session.openWithCallback(self.delete, MessageBox, _("'%s' contains %d recording(s) and %d sub-directories.\n") % (folder_filename,files,subdirs) + are_you_sure)
mbox.setTitle(self.getTitle())
return
# New code to delete empty directories without an "are you sure" question
else:
try:
os.rmdir(cur_path)
except Exception, e:
print "[MovieSelection] Failed delete", e
self.session.open(MessageBox, _("Delete failed!") + "\n" + str(e), MessageBox.TYPE_ERROR)
else:
self["list"].removeService(current)
self.showActionFeedback(_("Deleted") + " " + name)
from Screens.InfoBarGenerics import delResumePoint
delResumePoint(current)
return
# End of new code
else: # Deleting from trash can or no trash can "installed"
if '.Trash' in cur_path:
etc
etc