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
pull/6999/head
Martín Fernández 4 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 -- reinitialize dialog
end) end)
end, end,
}:chooseDir() }:chooseDir()
end
]] ]]
local PathChooser = require("ui/widget/pathchooser") local PathChooser = require("ui/widget/pathchooser")
@ -37,10 +38,15 @@ end
--- Displays a PathChooser widget for picking a (download) directory. --- Displays a PathChooser widget for picking a (download) directory.
-- @treturn string path chosen by the user -- @treturn string path chosen by the user
function DownloadMgr:chooseDir() function DownloadMgr:chooseDir(dir)
local lastdir = G_reader_settings:readSetting("lastdir") local path
local download_dir = G_reader_settings:readSetting("download_dir") if not dir then
local path = download_dir and util.realpath(download_dir .. "/..") or lastdir 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{ local path_chooser = PathChooser:new{
title = self.title or true, -- use default title if none provided title = self.title or true, -- use default title if none provided
select_directory = true, select_directory = true,

@ -483,14 +483,8 @@ function CalibreSearch:prompt(message)
ok_text = _("Scan") .. " " .. rootdir, ok_text = _("Scan") .. " " .. rootdir,
ok_callback = function() ok_callback = function()
self.libraries = {} self.libraries = {}
self.last_scan = {} local count, paths = self:scan(rootdir)
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
-- append current wireless dir if it wasn't found on the scan -- append current wireless dir if it wasn't found on the scan
-- this will happen if it is in a nested dir. -- this will happen if it is in a nested dir.
local inbox_dir = G_reader_settings:readSetting("inbox_dir") local inbox_dir = G_reader_settings:readSetting("inbox_dir")
@ -501,6 +495,15 @@ function CalibreSearch:prompt(message)
paths = paths .. "\n" .. count .. ": " .. inbox_dir paths = paths .. "\n" .. count .. ": " .. inbox_dir
end end
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) util.dumpTable(self.libraries, self.user_libraries)
self:invalidateCache() self:invalidateCache()
self.books = self:getMetadata() self.books = self:getMetadata()
@ -515,6 +518,17 @@ function CalibreSearch:prompt(message)
}) })
end 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 -- find all calibre libraries under a given root dir
function CalibreSearch:findCalibre(root) function CalibreSearch:findCalibre(root)
-- protect lfs.dir which will raise error on no-permission directory -- protect lfs.dir which will raise error on no-permission directory

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

Loading…
Cancel
Save