[feat] Delete book after reading (#5107)

pull/5088/head
Robert 5 years ago committed by Frans de Jonge
parent a3356483ba
commit 7d093fc0b9

@ -4,6 +4,7 @@ local InfoMessage = require("ui/widget/infomessage")
local InputContainer = require("ui/widget/container/inputcontainer")
local UIManager = require("ui/uimanager")
local _ = require("gettext")
local T = require("ffi/util").template
local ReaderStatus = InputContainer:new {
document = nil,
@ -68,6 +69,13 @@ function ReaderStatus:onEndOfBook()
},
{
{
text = _("Delete file"),
callback = function()
self:deleteFile(self.document.file, false)
UIManager:close(choose_action)
end,
},
{
text = _("Open next file"),
enabled = collate,
@ -76,6 +84,8 @@ function ReaderStatus:onEndOfBook()
UIManager:close(choose_action)
end,
},
},
{
{
text = _("File browser"),
callback = function()
@ -113,6 +123,8 @@ function ReaderStatus:onEndOfBook()
elseif settings == "book_status_file_browser" then
local before_show_callback = function() self:openFileBrowser() end
self:onShowBookStatus(before_show_callback)
elseif settings == "delete_file" then
self:deleteFile(self.document.file, true)
end
end
@ -141,6 +153,27 @@ function ReaderStatus:openNextFile(next_file)
end
end
function ReaderStatus:deleteFile(file, text_end_book)
local ConfirmBox = require("ui/widget/confirmbox")
local message_end_book = ""
if text_end_book then
message_end_book = "You've reached the end of the document.\n"
end
UIManager:show(ConfirmBox:new{
text = T(_("%1Are you sure that you want to delete this file?\n%2\nIf you delete a file, it is permanently lost."), message_end_book, file),
ok_text = _("Delete"),
ok_callback = function()
local FileManager = require("apps/filemanager/filemanager")
local filemanagerutil = require("apps/filemanager/filemanagerutil")
self:openFileBrowser()
FileManager:deleteFile(file)
filemanagerutil.removeFileFromHistoryIfWanted(file)
filemanagerutil.ensureLastFileExists()
FileManager.instance.file_chooser:refreshPath()
end,
})
end
function ReaderStatus:onShowBookStatus(before_show_callback)
local status_page = BookStatusWidget:new {
thumbnail = self.document:getCoverPageImage(),

@ -364,6 +364,15 @@ common_settings.document = {
G_reader_settings:saveSetting("end_document_action", "book_status")
end,
},
{
text = _("Delete file"),
checked_func = function()
return G_reader_settings:readSetting("end_document_action") == "delete_file"
end,
callback = function()
G_reader_settings:saveSetting("end_document_action", "delete_file")
end,
},
{
text = _("Open next file"),
enabled_func = function()
@ -395,7 +404,6 @@ common_settings.document = {
G_reader_settings:saveSetting("end_document_action", "book_status_file_browser")
end,
},
}
},
{

Loading…
Cancel
Save