diff --git a/frontend/ui/data/onetime_migration.lua b/frontend/ui/data/onetime_migration.lua index 5707efa50..68c0d66d3 100644 --- a/frontend/ui/data/onetime_migration.lua +++ b/frontend/ui/data/onetime_migration.lua @@ -5,9 +5,10 @@ Centralizes any and all one time migration concerns. local DataStorage = require("datastorage") local lfs = require("libs/libkoreader-lfs") local logger = require("logger") +local _ = require("gettext") -- Date at which the last migration snippet was added -local CURRENT_MIGRATION_DATE = 20230703 +local CURRENT_MIGRATION_DATE = 20230707 -- Retrieve the date of the previous migration, if any local last_migration_date = G_reader_settings:readSetting("last_migration_date", 0) @@ -566,5 +567,23 @@ if last_migration_date < 20230703 then end end +-- 20230707, OPDS, no more special calibre catalog +if last_migration_date < 20230707 then + logger.info("Performing one-time migration for 20230707") + + local calibre_opds = G_reader_settings:readSetting("calibre_opds") + if calibre_opds and calibre_opds.host and calibre_opds.port then + local opds_servers = G_reader_settings:readSetting("opds_servers") or {} + table.insert(opds_servers, 1, { + title = _("Local calibre library"), + url = string.format("http://%s:%d/opds", calibre_opds.host, calibre_opds.port), + username = calibre_opds.username, + password = calibre_opds.password, + }) + G_reader_settings:saveSetting("opds_servers", opds_servers) + G_reader_settings:delSetting("calibre_opds") + end +end + -- We're done, store the current migration date G_reader_settings:saveSetting("last_migration_date", CURRENT_MIGRATION_DATE) diff --git a/frontend/ui/widget/imageviewer.lua b/frontend/ui/widget/imageviewer.lua index 4b0f0ab67..2fdddf91b 100644 --- a/frontend/ui/widget/imageviewer.lua +++ b/frontend/ui/widget/imageviewer.lua @@ -40,6 +40,7 @@ local ImageViewer = InputContainer:extend{ -- the image_disposable provided here. -- Each BlitBuffer in the table (or returned by functions) will be free'd -- if the table itself has an image_disposable field set to true. + images_list_nb = nil, -- if set, overrides #self.image -- With images list, when switching image, whether to keep previous -- image pan & zoom @@ -142,7 +143,7 @@ function ImageViewer:init() self.image = self.image() end self._images_list_cur = 1 - self._images_list_nb = #self._images_list + self._images_list_nb = self.images_list_nb or #self._images_list self._images_orig_scale_factor = self.scale_factor -- also swap disposable status self._images_list_disposable = self.image_disposable diff --git a/plugins/opds.koplugin/opdsbrowser.lua b/plugins/opds.koplugin/opdsbrowser.lua index f50038a7c..179076517 100644 --- a/plugins/opds.koplugin/opdsbrowser.lua +++ b/plugins/opds.koplugin/opdsbrowser.lua @@ -11,7 +11,6 @@ local MultiInputDialog = require("ui/widget/multiinputdialog") local NetworkMgr = require("ui/network/manager") local OPDSParser = require("opdsparser") local OPDSPSE = require("opdspse") -local Screen = require("device").screen local UIManager = require("ui/uimanager") local http = require("socket.http") local lfs = require("libs/libkoreader-lfs") @@ -61,8 +60,6 @@ local OPDSBrowser = Menu:extend{ url = "https://gallica.bnf.fr/opds", }, }), - calibre_name = _("Local calibre library"), - calibre_opds = G_reader_settings:readSetting("calibre_opds", {}), catalog_type = "application/atom%+xml", search_type = "application/opensearchdescription%+xml", @@ -79,8 +76,6 @@ local OPDSBrowser = Menu:extend{ root_catalog_username = nil, root_catalog_password = nil, - width = Screen:getWidth(), - height = Screen:getHeight(), title_shrink_font_to_fit = true, } @@ -96,19 +91,11 @@ end -- Builds the root list of catalogs function OPDSBrowser:genItemTableFromRoot() - local item_table = { - { -- calibre is the first and non-deletable item - text = self.calibre_name, - url = self.calibre_opds.host and self.calibre_opds.port and - string.format("http://%s:%d/opds", self.calibre_opds.host, self.calibre_opds.port), - username = self.calibre_opds.username, - password = self.calibre_opds.password, - searchable = false, - }, - } + local item_table = {} for _, server in ipairs(self.opds_servers) do table.insert(item_table, { text = server.title, + mandatory = server.username and "\u{f2c0}", url = server.url, username = server.username, password = server.password, @@ -119,33 +106,32 @@ function OPDSBrowser:genItemTableFromRoot() end -- Shows dialog to edit properties of the new/existing catalog -function OPDSBrowser:addEditCatalog(item, is_calibre) +function OPDSBrowser:addEditCatalog(item) + local fields = { + { + hint = _("Catalog name"), + }, + { + hint = _("Catalog URL"), + }, + { + hint = _("Username (optional)"), + }, + { + hint = _("Password (optional)"), + text_type = "password", + }, + } local title - local fields = {{}, {}, {}, {}} - if is_calibre then - title = _("Edit local calibre host and port") - fields[1].text = self.calibre_opds.host or "192.168.1.1" - fields[1].hint = _("calibre host") - fields[2].text = self.calibre_opds.port and tostring(self.calibre_opds.port) or "8080" - fields[2].hint = _("calibre port") - fields[3].text = self.calibre_opds.username - fields[4].text = self.calibre_opds.password + if item then + title = _("Edit OPDS catalog") + fields[1].text = item.text + fields[2].text = item.url + fields[3].text = item.username + fields[4].text = item.password else - fields[1].hint = _("Catalog name") - fields[2].hint = _("Catalog URL") - if item then - title = _("Edit OPDS catalog") - fields[1].text = item.text - fields[2].text = item.url - fields[3].text = item.username - fields[4].text = item.password - else - title = _("Add OPDS catalog") - end + title = _("Add OPDS catalog") end - fields[3].hint = _("Username (optional)") - fields[4].hint = _("Password (optional)") - fields[4].text_type = "password" local dialog dialog = MultiInputDialog:new{ @@ -158,19 +144,14 @@ function OPDSBrowser:addEditCatalog(item, is_calibre) id = "close", callback = function() UIManager:close(dialog) - end + end, }, { text = _("Save"), callback = function() - local dialog_fields = dialog:getFields() - if is_calibre then - self:editCalibreFromInput(dialog_fields) - else - self:editCatalogFromInput(dialog_fields, item) - end + self:editCatalogFromInput(dialog:getFields(), item) UIManager:close(dialog) - end + end, }, }, }, @@ -238,17 +219,6 @@ function OPDSBrowser:editCatalogFromInput(fields, item, no_init) end end --- Saves calibre properties from input dialog -function OPDSBrowser:editCalibreFromInput(fields) - self.calibre_opds.host = fields[1] - if tonumber(fields[2]) then - self.calibre_opds.port = fields[2] - end - self.calibre_opds.username = fields[3] ~= "" and fields[3] or nil - self.calibre_opds.password = fields[4] - self:init() -end - -- Deletes catalog from the root list function OPDSBrowser:deleteCatalog(item) for i, server in ipairs(self.opds_servers) do @@ -477,9 +447,6 @@ function OPDSBrowser:genItemTableFromCatalog(catalog, item_url) title = entry.title.div end end - if title == "Unknown" then - logger.info("Cannot handle title", entry.title) - end item.text = title local author = "Unknown Author" if type(entry.author) == "table" and entry.author.name then @@ -841,7 +808,6 @@ end -- Menu action on item long-press (dialog Edit / Delete catalog) function OPDSBrowser:onMenuHold(item) if #self.paths > 0 then return end -- not root list - local is_calibre = item.text == self.calibre_name local dialog dialog = ButtonDialog:new{ title = item.text, @@ -852,12 +818,11 @@ function OPDSBrowser:onMenuHold(item) text = _("Edit"), callback = function() UIManager:close(dialog) - self:addEditCatalog(item, is_calibre) + self:addEditCatalog(item) end, }, { text = _("Delete"), - enabled = not is_calibre, callback = function() UIManager:show(ConfirmBox:new{ text = _("Delete OPDS catalog?"), diff --git a/plugins/opds.koplugin/opdspse.lua b/plugins/opds.koplugin/opdspse.lua index dbdf5e106..97460adc2 100644 --- a/plugins/opds.koplugin/opdspse.lua +++ b/plugins/opds.koplugin/opdspse.lua @@ -12,12 +12,8 @@ local url = require("socket.url") local _ = require("gettext") local T = require("ffi/util").template - - - local OPDSPSE = {} - -- This function attempts to pull chapter progress from Kavita. function OPDSPSE:getLastPage(remote_url, username, password) local last_page = 0 @@ -96,8 +92,6 @@ function OPDSPSE:getLastPage(remote_url, username, password) return last_page; end - - function OPDSPSE:streamPages(remote_url, count, continue, username, password) -- attempt to pull chapter progress from Kavita if user pressed -- "Page Stream" button. @@ -142,7 +136,6 @@ function OPDSPSE:streamPages(remote_url, count, continue, username, password) end local data = table.concat(page_data) - if code == 200 then local page_bb = RenderImage:renderImageData(data, #data, false) or RenderImage:renderImageFile("resources/koreader.png", false) @@ -161,9 +154,8 @@ function OPDSPSE:streamPages(remote_url, count, continue, username, password) fullscreen = true, with_title_bar = false, image_disposable = false, -- instead set page_table image_disposable to true + images_list_nb = count, } - -- in Lua 5.2 we could override __len, but this works too - viewer._images_list_nb = count UIManager:show(viewer) if continue then self:jumpToPage(viewer, count) @@ -179,7 +171,6 @@ function OPDSPSE:jumpToPage(viewer, count) local input_dialog input_dialog = InputDialog:new{ title = _("Enter page number"), - input = "", input_type = "number", input_hint = "(" .. "1 - " .. count .. ")", buttons = {