2017-05-05 14:04:50 +00:00
|
|
|
--[[--
|
|
|
|
This module displays a PathChooser widget to choose a download directory.
|
|
|
|
|
|
|
|
It can be used as a callback on a button or menu item.
|
|
|
|
|
|
|
|
Example:
|
|
|
|
callback = function()
|
|
|
|
require("ui/downloadmgr"):new{
|
|
|
|
title = _("Choose download directory"),
|
|
|
|
onConfirm = function(path)
|
|
|
|
logger.dbg("set download directory to", path)
|
|
|
|
G_reader_settings:saveSetting("download_dir", path)
|
|
|
|
UIManager:nextTick(function()
|
|
|
|
-- reinitialize dialog
|
|
|
|
end)
|
|
|
|
end,
|
|
|
|
}:chooseDir()
|
|
|
|
]]
|
|
|
|
|
2014-10-28 09:14:06 +00:00
|
|
|
local PathChooser = require("ui/widget/pathchooser")
|
|
|
|
local UIManager = require("ui/uimanager")
|
2014-11-25 09:43:28 +00:00
|
|
|
local Screen = require("device").screen
|
2014-10-28 09:14:06 +00:00
|
|
|
local util = require("ffi/util")
|
|
|
|
local _ = require("gettext")
|
|
|
|
|
|
|
|
local DownloadMgr = {
|
2014-11-25 10:19:30 +00:00
|
|
|
title = _("Long press to choose download directory"),
|
2014-10-28 09:14:06 +00:00
|
|
|
onConfirm = function() end,
|
|
|
|
}
|
|
|
|
|
2016-02-16 02:08:04 +00:00
|
|
|
function DownloadMgr:new(from_o)
|
|
|
|
local o = from_o or {}
|
2014-10-28 09:14:06 +00:00
|
|
|
setmetatable(o, self)
|
|
|
|
self.__index = self
|
|
|
|
return o
|
|
|
|
end
|
|
|
|
|
2017-05-05 14:04:50 +00:00
|
|
|
--- Displays a PathChooser widget for picking a (download) directory.
|
|
|
|
-- @treturn string path chosen by the user
|
2014-10-28 09:14:06 +00:00
|
|
|
function DownloadMgr:chooseDir()
|
|
|
|
local lastdir = G_reader_settings:readSetting("lastdir")
|
|
|
|
local download_dir = G_reader_settings:readSetting("download_dir")
|
|
|
|
local path_chooser = PathChooser:new{
|
|
|
|
title = self.title,
|
2014-11-25 09:43:28 +00:00
|
|
|
height = Screen:getHeight(),
|
2014-10-28 09:14:06 +00:00
|
|
|
path = download_dir and (download_dir .. "/..") or lastdir,
|
|
|
|
show_hidden = G_reader_settings:readSetting("show_hidden"),
|
|
|
|
onConfirm = function(path)
|
|
|
|
-- hack to remove additional parent
|
|
|
|
if path:sub(-3, -1) == "/.." then
|
|
|
|
path = path:sub(1, -4)
|
|
|
|
end
|
|
|
|
self.onConfirm(util.realpath(path))
|
|
|
|
end
|
|
|
|
}
|
|
|
|
UIManager:show(path_chooser)
|
|
|
|
end
|
|
|
|
|
|
|
|
return DownloadMgr
|