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,
|
2020-12-14 23:46:38 +00:00
|
|
|
}:chooseDir()
|
|
|
|
end
|
2017-05-05 14:04:50 +00:00
|
|
|
]]
|
|
|
|
|
2014-10-28 09:14:06 +00:00
|
|
|
local PathChooser = require("ui/widget/pathchooser")
|
|
|
|
local UIManager = require("ui/uimanager")
|
|
|
|
local util = require("ffi/util")
|
|
|
|
local _ = require("gettext")
|
|
|
|
|
|
|
|
local DownloadMgr = {
|
|
|
|
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
|
2020-12-14 23:46:38 +00:00
|
|
|
function DownloadMgr:chooseDir(dir)
|
|
|
|
local path
|
2022-09-20 09:54:57 +00:00
|
|
|
if dir then
|
|
|
|
path = dir
|
|
|
|
else
|
2020-12-14 23:46:38 +00:00
|
|
|
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
|
|
|
|
end
|
2014-10-28 09:14:06 +00:00
|
|
|
local path_chooser = PathChooser:new{
|
2018-08-06 18:59:01 +00:00
|
|
|
select_file = false,
|
|
|
|
show_files = false,
|
|
|
|
path = path,
|
|
|
|
onConfirm = function(dir_path)
|
|
|
|
self.onConfirm(dir_path)
|
2014-10-28 09:14:06 +00:00
|
|
|
end
|
|
|
|
}
|
|
|
|
UIManager:show(path_chooser)
|
|
|
|
end
|
|
|
|
|
2022-09-20 09:54:57 +00:00
|
|
|
function DownloadMgr:chooseCloudDir()
|
|
|
|
local cloud_storage = require("apps/cloudstorage/cloudstorage"):new{
|
|
|
|
item = self.item,
|
|
|
|
onConfirm = function(dir_path)
|
|
|
|
self.onConfirm(dir_path)
|
|
|
|
end,
|
|
|
|
}
|
|
|
|
UIManager:show(cloud_storage)
|
|
|
|
end
|
|
|
|
|
2014-10-28 09:14:06 +00:00
|
|
|
return DownloadMgr
|