calibre: gui to choose default extension

pull/8169/head
Martín Fdez 3 years ago committed by Martín Fernández
parent 3b6f521e26
commit a63c22b6fb

@ -1,37 +1,80 @@
--[[ --[[
File formats supported by KOReader. These are reported when the device talks with calibre wireless server. File formats supported by KOReader. These are reported when the device talks with calibre wireless server.
Note that the server can allow or restrict file formats based on calibre configuration for each device. calibre assumes that the list is in desired order.
Optionally KOReader users can set their own supported formats to report to the server. When sending documents if no format on the list exists then calibre converts the book to the first format.
See https://www.mobileread.com/forums/showthread.php?t=341423
--]] --]]
local user_path = require("datastorage"):getDataDir() .. "/calibre-extensions.lua" local valid_ext = {
local ok, extensions = pcall(dofile, user_path) "epub",
"fb2",
if ok then "mobi",
return extensions "azw",
else "xps",
return { "doc",
"azw", "docx",
"cbz", "djv",
"chm", "djvu",
"djv", "pdf",
"djvu", "cbz",
"doc", "htm",
"docx", "html",
"epub", "xhtml",
"fb2", "pdb",
"htm", "prc",
"html", "rtf",
"md", "txt",
"mobi", "md",
"pdb", "chm",
"pdf", "zip",
"prc", }
"rtf",
"txt", -- if the file "calibre-extensions.lua", under dataDir, returns a table
"xhtml", -- then use it instead of default extensions.
"xps", local function getCustomConfig()
"zip", local path = require("datastorage"):getDataDir()
} local ok, extensions = pcall(dofile, string.format("%s/%s", path, "calibre-extensions.lua"))
if ok then return extensions end
end
local CalibreExtensions = {
outputs = { "epub", "mobi", "docx", "fb2", "pdf", "txt" },
default_output = G_reader_settings:readSetting("calibre_wireless_default_format") or "epub",
user_overrides = getCustomConfig(),
}
function CalibreExtensions:get()
if type(self.user_overrides) == "table" then
return self.user_overrides
else
local sorted = {}
sorted[1] = self.default_output
for _, v in ipairs(valid_ext) do
if v ~= self.default_output then
sorted[#sorted+1] = v
end
end
return sorted
end
end end
function CalibreExtensions:getInfo()
local str = ""
local t = self:get()
for i, v in ipairs(t) do
if i == #t then
str = str .. v
else
str = str .. v .. ", "
end
end
return str
end
function CalibreExtensions:isCustom()
return self.user_overrides ~= nil
end
return CalibreExtensions

@ -8,6 +8,7 @@
--]] --]]
local BD = require("ui/bidi") local BD = require("ui/bidi")
local CalibreExtensions = require("extensions")
local CalibreSearch = require("search") local CalibreSearch = require("search")
local CalibreWireless = require("wireless") local CalibreWireless = require("wireless")
local Dispatcher = require("dispatcher") local Dispatcher = require("dispatcher")
@ -225,7 +226,8 @@ function Calibre:getWirelessMenuTable()
local enabled = G_reader_settings:nilOrTrue("calibre_wireless") local enabled = G_reader_settings:nilOrTrue("calibre_wireless")
return enabled and not CalibreWireless.calibre_socket return enabled and not CalibreWireless.calibre_socket
end end
return {
local t = {
{ {
text = _("Enable wireless client"), text = _("Enable wireless client"),
separator = true, separator = true,
@ -335,6 +337,49 @@ function Calibre:getWirelessMenuTable()
}, },
}, },
} }
if not CalibreExtensions:isCustom() then
table.insert(t, 2, {
text = _("File formats"),
enabled_func = isEnabled,
sub_item_table_func = function()
local submenu = {
{
text = _("About formats"),
keep_menu_open = true,
separator = true,
callback = function()
UIManager:show(InfoMessage:new{
text = string.format("%s: %s \n\n%s",
_("Supported file formats"),
CalibreExtensions:getInfo(),
_("Unsupported formats will be converted by calibre to the first format of the list."))
})
end,
}
}
for i, v in ipairs(CalibreExtensions.outputs) do
table.insert(submenu, {})
submenu[i+1].text = v
submenu[i+1].checked_func = function()
if v == CalibreExtensions.default_output then
return true
end
return false
end
submenu[i+1].callback = function()
if type(v) == "string" and v ~= CalibreExtensions.default_output then
CalibreExtensions.default_output = v
G_reader_settings:saveSetting("calibre_wireless_default_format", CalibreExtensions.default_output)
end
end
end
return submenu
end,
})
end
return t
end end
return Calibre return Calibre

@ -4,6 +4,7 @@
--]] --]]
local BD = require("ui/bidi") local BD = require("ui/bidi")
local CalibreExtensions = require("extensions")
local CalibreMetadata = require("metadata") local CalibreMetadata = require("metadata")
local CalibreSearch = require("search") local CalibreSearch = require("search")
local ConfirmBox = require("ui/widget/confirmbox") local ConfirmBox = require("ui/widget/confirmbox")
@ -25,7 +26,8 @@ local T = FFIUtil.template
require("ffi/zeromq_h") require("ffi/zeromq_h")
-- supported formats -- supported formats
local extensions = require("extensions") local extensions = CalibreExtensions:get()
local function getExtensionPathLengths() local function getExtensionPathLengths()
local t = {} local t = {}
for _, v in ipairs(extensions) do for _, v in ipairs(extensions) do

Loading…
Cancel
Save