From 7d093fc0b9d3c9e50e61136027ba345866474735 Mon Sep 17 00:00:00 2001 From: Robert Date: Fri, 5 Jul 2019 10:35:23 +0200 Subject: [PATCH] [feat] Delete book after reading (#5107) --- frontend/apps/reader/modules/readerstatus.lua | 33 +++++++++++++++++++ .../elements/common_settings_menu_table.lua | 10 +++++- 2 files changed, 42 insertions(+), 1 deletion(-) diff --git a/frontend/apps/reader/modules/readerstatus.lua b/frontend/apps/reader/modules/readerstatus.lua index 52ab51c0f..ec110583b 100644 --- a/frontend/apps/reader/modules/readerstatus.lua +++ b/frontend/apps/reader/modules/readerstatus.lua @@ -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(), diff --git a/frontend/ui/elements/common_settings_menu_table.lua b/frontend/ui/elements/common_settings_menu_table.lua index 4dee307e2..cc1462d44 100644 --- a/frontend/ui/elements/common_settings_menu_table.lua +++ b/frontend/ui/elements/common_settings_menu_table.lua @@ -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, }, - } }, {