Screensaver: fix crash when "Choose screensaver image" (#4799)

Just switched to use the friendly PathChooser instead of
FileChooser (which is more like a superclass and shouldn't
be used directly).
pull/4800/head
poire-z 5 years ago committed by GitHub
parent 645d41eda9
commit 6239d89022
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -99,43 +99,28 @@ function Screensaver:chooseFile()
text = _("Choose screensaver image"), text = _("Choose screensaver image"),
callback = function() callback = function()
UIManager:close(self.choose_dialog) UIManager:close(self.choose_dialog)
local FileChooser = require("ui/widget/filechooser")
local image_chooser = FileChooser:new{
title = _("Choose screensaver image"),
no_title = false,
path = self.root_path,
show_hidden = G_reader_settings:readSetting("show_hidden"),
focused_path = self.focused_file,
collate = G_reader_settings:readSetting("collate") or "strcoll",
reverse_collate = G_reader_settings:isTrue("reverse_collate"),
show_parent = self.show_parent,
width = Screen:getWidth(),
height = Screen:getHeight(),
is_popout = false,
is_borderless = true,
has_close_button = true,
perpage = G_reader_settings:readSetting("items_per_page"),
file_filter = function(filename)
local util = require("util") local util = require("util")
local PathChooser = require("ui/widget/pathchooser")
local path_chooser = PathChooser:new{
select_directory = false,
select_file = true,
file_filter = function(filename)
local suffix = util.getFileNameSuffix(filename) local suffix = util.getFileNameSuffix(filename)
if screensaver_provider[suffix] then if screensaver_provider[suffix] then
return true return true
end end
end, end,
} detailed_file_info = true,
function image_chooser:onFileSelect(file) -- luacheck: ignore path = self.root_path,
local ConfirmBox = require("ui/widget/confirmbox") onConfirm = function(file_path)
UIManager:show(ConfirmBox:new{ G_reader_settings:saveSetting("screensaver_image", file_path)
text = T(_("Set screensaver image to:\n%1"), require("ffi/util").basename(file)), UIManager:show(InfoMessage:new{
ok_callback = function() text = T(_("Screensaver image set to:\n%1"), file_path),
G_reader_settings:saveSetting("screensaver_image", file) timeout = 3,
UIManager:close(image_chooser)
end
}) })
return true
end end
}
UIManager:show(image_chooser) UIManager:show(path_chooser)
end, end,
} }
}) })

Loading…
Cancel
Save