Calibre plugin fixes for android (#6996)

* calibre plugin: scan on sdcard too
* calibre plugin: force inbox chooser in android's primary partition
* downloadMgr: override dir
reviewable/pr6999/r1
Martín Fernández 3 years ago committed by GitHub
parent 248e508c7e
commit a90038e4eb
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -14,7 +14,8 @@ Example:
-- reinitialize dialog
end)
end,
}:chooseDir()
}:chooseDir()
end
]]
local PathChooser = require("ui/widget/pathchooser")
@ -37,10 +38,15 @@ end
--- Displays a PathChooser widget for picking a (download) directory.
-- @treturn string path chosen by the user
function DownloadMgr:chooseDir()
local lastdir = G_reader_settings:readSetting("lastdir")
local download_dir = G_reader_settings:readSetting("download_dir")
local path = download_dir and util.realpath(download_dir .. "/..") or lastdir
function DownloadMgr:chooseDir(dir)
local path
if not dir then
local lastdir = G_reader_settings:readSetting("lastdir")
local download_dir = G_reader_settings:readSetting("download_dir")
path = download_dir and util.realpath(download_dir .. "/..") or lastdir
else
path = dir
end
local path_chooser = PathChooser:new{
title = self.title or true, -- use default title if none provided
select_directory = true,

@ -483,14 +483,8 @@ function CalibreSearch:prompt(message)
ok_text = _("Scan") .. " " .. rootdir,
ok_callback = function()
self.libraries = {}
self.last_scan = {}
self:findCalibre(rootdir)
local paths = ""
for i, dir in ipairs(self.last_scan) do
self.libraries[dir.path] = true
paths = paths .. "\n" .. i .. ": " .. dir.path
end
local count = #self.last_scan
local count, paths = self:scan(rootdir)
-- append current wireless dir if it wasn't found on the scan
-- this will happen if it is in a nested dir.
local inbox_dir = G_reader_settings:readSetting("inbox_dir")
@ -501,6 +495,15 @@ function CalibreSearch:prompt(message)
paths = paths .. "\n" .. count .. ": " .. inbox_dir
end
end
-- append libraries in different volumes
local ok, sd_path = Device:hasExternalSD()
if ok then
local sd_count, sd_paths = self:scan(sd_path)
count = count + sd_count
paths = paths .. "\n" .. _("SD card") .. ": " .. sd_paths
end
util.dumpTable(self.libraries, self.user_libraries)
self:invalidateCache()
self.books = self:getMetadata()
@ -515,6 +518,17 @@ function CalibreSearch:prompt(message)
})
end
function CalibreSearch:scan(rootdir)
self.last_scan = {}
self:findCalibre(rootdir)
local paths = ""
for i, dir in ipairs(self.last_scan) do
self.libraries[dir.path] = true
paths = paths .. "\n" .. i .. ": " .. dir.path
end
return #self.last_scan, paths
end
-- find all calibre libraries under a given root dir
function CalibreSearch:findCalibre(root)
-- protect lfs.dir which will raise error on no-permission directory

@ -6,6 +6,7 @@
local BD = require("ui/bidi")
local CalibreMetadata = require("metadata")
local ConfirmBox = require("ui/widget/confirmbox")
local Device = require("device")
local FFIUtil = require("ffi/util")
local InputContainer = require("ui/widget/container/inputcontainer")
local InputDialog = require("ui/widget/inputdialog")
@ -165,7 +166,13 @@ end
-- will callback initCalibreMQ if inbox is confirmed to be set
function CalibreWireless:setInboxDir(host, port)
local force_chooser_dir
if Device:isAndroid() then
force_chooser_dir = Device.home_dir
end
local calibre_device = self
require("ui/downloadmgr"):new{
onConfirm = function(inbox)
local driver = CalibreMetadata:getDeviceInfo(inbox, "device_name")
@ -200,7 +207,7 @@ Do you want to continue? ]]), driver),
save_and_resume()
end
end,
}:chooseDir()
}:chooseDir(force_chooser_dir)
end
function CalibreWireless:connect()

Loading…
Cancel
Save