Open with: images (#10561)

reviewable/pr10574/r1
hius07 11 months ago committed by GitHub
parent c95b17410b
commit 46933035c5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -274,14 +274,26 @@ function FileManager:setupLayout()
text = _("Open with…"),
callback = function()
UIManager:close(self.file_dialog)
local one_time_providers = {
{
provider_name = _("Text viewer"),
local one_time_providers = {}
if DocumentRegistry:isImageFile(file) then
table.insert(one_time_providers, {
provider_name = _("Image viewer"),
callback = function()
file_manager:openTextViewer(file)
local ImageViewer = require("ui/widget/imageviewer")
UIManager:show(ImageViewer:new{
file = file,
fullscreen = true,
with_title_bar = false,
})
end,
},
}
})
end
table.insert(one_time_providers, {
provider_name = _("Text viewer"),
callback = function()
file_manager:openTextViewer(file)
end,
})
if file_manager.texteditor then
table.insert(one_time_providers, {
provider_name = _("Text editor"),
@ -1238,7 +1250,6 @@ function FileManager:onShowFolderMenu()
end
button_dialog = ButtonDialog:new{
width = math.floor(Screen:getWidth() * 0.9),
shrink_unneeded_width = true,
buttons = buttons,
anchor = function()

@ -342,7 +342,7 @@ function BookInfo:setCustomBookCover(file, book_props, metadata_updated_caller_c
local path_chooser = PathChooser:new{
select_directory = false,
file_filter = function(filename)
return util.arrayContains(DocSettings.cover_ext, util.getFileNameSuffix(filename))
return DocumentRegistry:isImageFile(filename)
end,
onConfirm = function(image_file)
local sidecar_dir
@ -358,7 +358,7 @@ function BookInfo:setCustomBookCover(file, book_props, metadata_updated_caller_c
sidecar_dir = DocSettings:getSidecarDir(file) .. "/"
util.makePath(sidecar_dir)
end
local new_cover_file = sidecar_dir .. "cover." .. util.getFileNameSuffix(image_file)
local new_cover_file = sidecar_dir .. "cover." .. util.getFileNameSuffix(image_file):lower()
if ffiutil.copyFile(image_file, new_cover_file) == nil then
kvp_update()
end

@ -262,7 +262,8 @@ function ReaderZooming:onReadSettings(config)
or G_reader_settings:readSetting("kopt_zoom_overlap_v") or self.zoom_overlap_v
-- update zoom direction parameters
local zoom_direction_setting = self.zoom_direction_settings[self.document.configurable.zoom_direction]
local zoom_direction_setting = self.zoom_direction_settings[self.document.configurable.zoom_direction
or G_reader_settings:readSetting("kopt_zoom_direction") or 7]
self.zoom_bottom_to_top = zoom_direction_setting.zoom_bottom_to_top
self.zoom_direction_vertical = zoom_direction_setting.zoom_direction_vertical
end

@ -12,9 +12,7 @@ local lfs = require("libs/libkoreader-lfs")
local logger = require("logger")
local util = require("util")
local DocSettings = LuaSettings:extend{
cover_ext = { "png", "jpg", "jpeg", "gif", "tif", "tiff", "svg" },
}
local DocSettings = LuaSettings:extend{}
local HISTORY_DIR = DataStorage:getHistoryDir()
local DOCSETTINGS_DIR = DataStorage:getDocSettingsDir()
@ -165,10 +163,8 @@ function DocSettings:_findCoverFileInDir(dir)
local ok, iter, dir_obj = pcall(lfs.dir, dir)
if ok then
for f in iter, dir_obj do
for _, ext in ipairs(self.cover_ext) do
if f == "cover." .. ext then
return dir .. "/" .. f
end
if util.splitFileNameSuffix(f) == "cover" then
return dir .. "/" .. f
end
end
end

@ -12,6 +12,16 @@ local DocumentRegistry = {
providers = {},
filetype_provider = {},
mimetype_ext = {},
image_ext = {
gif = true,
jpeg = true,
jpg = true,
png = true,
svg = true,
tif = true,
tiff = true,
webp = true,
},
}
function DocumentRegistry:addProvider(extension, mimetype, provider, weight)
@ -246,6 +256,10 @@ function DocumentRegistry:getReferenceCount(file)
end
end
function DocumentRegistry:isImageFile(file)
return self.image_ext[util.getFileNameSuffix(file):lower()] and true or false
end
-- load implementations:
require("document/credocument"):register(DocumentRegistry)
require("document/pdfdocument"):register(DocumentRegistry)

@ -1,6 +1,6 @@
local BD = require("ui/bidi")
local Blitbuffer = require("ffi/blitbuffer")
local ButtonDialogTitle = require("ui/widget/buttondialogtitle")
local ButtonDialog = require("ui/widget/buttondialog")
local BookStatusWidget = require("ui/widget/bookstatuswidget")
local BottomContainer = require("ui/widget/container/bottomcontainer")
local Device = require("device")
@ -58,16 +58,6 @@ if G_reader_settings:hasNot("screensaver_hide_fallback_msg") then
end
local Screensaver = {
screensaver_provider = {
gif = true,
jpg = true,
jpeg = true,
png = true,
svg = true,
tif = true,
tiff = true,
webp = true,
},
default_screensaver_message = _("Sleeping"),
-- State values
@ -103,12 +93,10 @@ function Screensaver:_getRandomImage(dir)
if ok then
for f in iter, dir_obj do
-- Always ignore macOS resource forks, too.
if lfs.attributes(dir .. f, "mode") == "file" and not util.stringStartsWith(f, "._") then
local extension = string.lower(string.match(f, ".+%.([^.]+)") or "")
if self.screensaver_provider[extension] then
i = i + 1
pics[i] = f
end
if lfs.attributes(dir .. f, "mode") == "file" and not util.stringStartsWith(f, "._")
and DocumentRegistry:isImageFile(f) then
i = i + 1
pics[i] = f
end
end
if i == 0 then
@ -317,7 +305,7 @@ function Screensaver:chooseFolder()
})
local screensaver_dir = G_reader_settings:readSetting("screensaver_dir")
or _("N/A")
choose_dialog = ButtonDialogTitle:new{
choose_dialog = ButtonDialog:new{
title = T(_("Current screensaver image folder:\n%1"), BD.dirpath(screensaver_dir)),
buttons = buttons
}
@ -337,12 +325,8 @@ function Screensaver:chooseFile(document_cover)
local path_chooser = PathChooser:new{
select_directory = false,
file_filter = function(filename)
local suffix = util.getFileNameSuffix(filename)
if document_cover and DocumentRegistry:hasProvider(filename) then
return true
elseif self.screensaver_provider[suffix] then
return true
end
return document_cover and DocumentRegistry:hasProvider(filename)
or DocumentRegistry:isImageFile(filename)
end,
path = self.root_path,
onConfirm = function(file_path)
@ -379,7 +363,7 @@ function Screensaver:chooseFile(document_cover)
or _("N/A")
local title = document_cover and T(_("Current screensaver document cover:\n%1"), BD.filepath(screensaver_document_cover))
or T(_("Current screensaver image:\n%1"), BD.filepath(screensaver_image))
choose_dialog = ButtonDialogTitle:new{
choose_dialog = ButtonDialog:new{
title = title,
buttons = buttons
}

@ -271,12 +271,9 @@ function ImageViewer:init()
end
end
if self._images_list then
if self._images_list and self._images_list_nb > 1 then
-- progress bar
local percent = 1
if self._images_list and self._images_list_nb > 1 then
percent = (self._images_list_cur - 1) / (self._images_list_nb - 1)
end
local percent = (self._images_list_cur - 1) / (self._images_list_nb - 1)
self.progress_bar = ProgressWidget:new{
width = self.width - 2*self.button_padding,
height = Screen:scaleBySize(5),
@ -346,11 +343,8 @@ function ImageViewer:update()
-- Image container (we'll insert it once all others are added and we know the height remaining)
local image_container_idx = #self.frame_elements + 1
-- Progress bar
if self._images_list then
local percent = 1
if self._images_list_nb > 1 then
percent = (self._images_list_cur - 1) / (self._images_list_nb - 1)
end
if self._images_list and self._images_list_nb > 1 then
local percent = (self._images_list_cur - 1) / (self._images_list_nb - 1)
self.progress_bar:setPercentage(percent)
table.insert(self.frame_elements, self.progress_container)
end
@ -431,6 +425,7 @@ function ImageViewer:_new_image_wg()
file = self.file,
image = self.image,
image_disposable = false, -- we may re-use self.image
file_do_cache = false,
alpha = true, -- we might be showing images with an alpha channel (e.g., from Wikipedia)
width = max_image_w,
height = max_image_h,
@ -846,7 +841,7 @@ function ImageViewer:onCloseWidget()
self.captioned_title_bar:free()
end
end
if self._images_list then
if self._images_list and self._images_list_nb > 1 then
self.progress_container:free()
end
self.button_container:free()

@ -22,12 +22,14 @@ Show image from memory example:
local Blitbuffer = require("ffi/blitbuffer")
local Cache = require("cache")
local DocumentRegistry = require("document/documentregistry")
local Geom = require("ui/geometry")
local RenderImage = require("ui/renderimage")
local Screen = require("device").screen
local UIManager = require("ui/uimanager")
local Widget = require("ui/widget/widget")
local logger = require("logger")
local util = require("util")
-- DPI_SCALE can't change without a restart, so let's compute it now
local function get_dpi_scale()
@ -129,9 +131,7 @@ function ImageWidget:_loadimage()
end
function ImageWidget:_loadfile()
local itype = string.lower(string.match(self.file, ".+%.([^.]+)") or "")
if itype == "svg" or itype == "png" or itype == "jpg" or itype == "jpeg"
or itype == "gif" or itype == "tiff" or itype == "tif" then
if DocumentRegistry:isImageFile(self.file) then
-- In our use cases for files (icons), we either provide width and height,
-- or just scale_for_dpi, and scale_factor should stay nil.
-- Other combinations will result in double scaling, and unexpected results.
@ -159,7 +159,7 @@ function ImageWidget:_loadfile()
self._bb_disposable = false -- don't touch or free a cached _bb
self._is_straight_alpha = cached.is_straight_alpha
else
if itype == "svg" then
if util.getFileNameSuffix(self.file) == "svg" then
local zoom
if scale_for_dpi_here then
zoom = DPI_SCALE
@ -399,7 +399,6 @@ function ImageWidget:getScaleFactorExtrema()
-- Compute dynamic limits for the scale factor, based on the screen's area and available memory (if possible).
-- Extrema eyeballed to be somewhat sensible given our usual screen dimensions and available RAM.
local util = require("util")
local memfree, _ = util.calcFreeMem()
local screen_area = Screen:getWidth() * Screen:getHeight()

Loading…
Cancel
Save