2
0
mirror of https://github.com/koreader/koreader synced 2024-11-18 03:25:46 +00:00
koreader/frontend/apps/filemanager/filemanagerutil.lua
poire-z 4d18ac1100 Some History fixes and enhancements (#3247)
Made the onHold buttons table similar to the one of File browser.
Added "Purge .sdr" and "Delete" to these buttons.
Moved the purgeSettings and removeFileFromHistoryIfWanted
logic into filemanagerutil functions.
Stay on the same page when manipulating history (previously, we were
always put back on first page).
Really keep deleted files in history (unless setting says otherwise).
Show deleted files in grey or dimmed in classic History and all
CoverBrowser display modes.
2017-09-22 18:24:38 +02:00

63 lines
2.1 KiB
Lua

--[[--
This module contains miscellaneous helper functions for FileManager
]]
local Device = require("device")
local DocSettings = require("docsettings")
local util = require("ffi/util")
local filemanagerutil = {}
function filemanagerutil.getDefaultDir()
if Device:isKindle() then
return "/mnt/us/documents"
elseif Device:isKobo() then
return "/mnt/onboard"
elseif Device:isAndroid() then
return "/sdcard"
else
return "."
end
end
function filemanagerutil.abbreviate(path)
local home_dir_name = G_reader_settings:readSetting("home_dir_display_name")
if home_dir_name ~= nil then
local home_dir = G_reader_settings:readSetting("home_dir") or filemanagerutil.getDefaultDir()
local len = home_dir:len()
local start = path:sub(1, len)
if start == home_dir then
return home_dir_name .. path:sub(len+1)
end
end
return path
end
-- Purge doc settings in sidecar directory,
function filemanagerutil.purgeSettings(file)
local file_abs_path = util.realpath(file)
if file_abs_path then
os.remove(DocSettings:getSidecarFile(file_abs_path))
-- Also remove backup, otherwise it will be used if we re-open this document
-- (it also allows for the sidecar folder to be empty and removed)
os.remove(DocSettings:getSidecarFile(file_abs_path)..".old")
-- If the sidecar folder is empty, os.remove() can delete it.
-- Otherwise, the following statement has no effect.
os.remove(DocSettings:getSidecarDir(file_abs_path))
end
end
-- Remove from history and update lastfile to top item in history
-- if autoremove_deleted_items_from_history is enabled
function filemanagerutil.removeFileFromHistoryIfWanted(file)
if G_reader_settings:readSetting("autoremove_deleted_items_from_history") then
local readhistory = require("readhistory")
readhistory:removeItemByPath(file)
if G_reader_settings:readSetting("lastfile") == file then
G_reader_settings:saveSetting("lastfile", #readhistory.hist > 0 and readhistory.hist[1].file or nil)
end
end
end
return filemanagerutil