mirror of
https://github.com/koreader/koreader.git
synced 2025-08-10 00:52:38 +00:00
Dropbox: upload file, create folder (#8610)
This commit is contained in:
@@ -1,14 +1,17 @@
|
||||
local BD = require("ui/bidi")
|
||||
local ButtonDialog = require("ui/widget/buttondialog")
|
||||
local ButtonDialogTitle = require("ui/widget/buttondialogtitle")
|
||||
local CheckButton = require("ui/widget/checkbutton")
|
||||
local ConfirmBox = require("ui/widget/confirmbox")
|
||||
local DataStorage = require("datastorage")
|
||||
local DropBox = require("apps/cloudstorage/dropbox")
|
||||
local FFIUtil = require("ffi/util")
|
||||
local Ftp = require("apps/cloudstorage/ftp")
|
||||
local InfoMessage = require("ui/widget/infomessage")
|
||||
local InputDialog = require("ui/widget/inputdialog")
|
||||
local LuaSettings = require("luasettings")
|
||||
local Menu = require("ui/widget/menu")
|
||||
local PathChooser = require("ui/widget/pathchooser")
|
||||
local UIManager = require("ui/uimanager")
|
||||
local WebDav = require("apps/cloudstorage/webdav")
|
||||
local lfs = require("libs/libkoreader-lfs")
|
||||
@@ -155,14 +158,20 @@ function CloudStorage:openCloudServer(url)
|
||||
end
|
||||
tbl, e = WebDav:run(self.address, self.username, self.password, url)
|
||||
end
|
||||
if tbl and #tbl > 0 then
|
||||
if tbl then
|
||||
self:switchItemTable(url, tbl)
|
||||
self:setTitleBarIconAndText("home")
|
||||
self.onExtraButtonTap = function()
|
||||
self:init()
|
||||
if self.type == "dropbox" then
|
||||
self.onExtraButtonTap = function()
|
||||
self:showPlusMenu(url)
|
||||
end
|
||||
else
|
||||
self:setTitleBarIconAndText("home")
|
||||
self.onExtraButtonTap = function()
|
||||
self:init()
|
||||
end
|
||||
end
|
||||
return true
|
||||
elseif not tbl then
|
||||
else
|
||||
logger.err("CloudStorage:", e)
|
||||
UIManager:show(InfoMessage:new{
|
||||
text = _("Cannot fetch list of folder contents\nPlease check your configuration or network connection."),
|
||||
@@ -170,9 +179,6 @@ function CloudStorage:openCloudServer(url)
|
||||
})
|
||||
table.remove(self.paths)
|
||||
return false
|
||||
else
|
||||
UIManager:show(InfoMessage:new{ text = _("Empty folder") })
|
||||
return false
|
||||
end
|
||||
end
|
||||
|
||||
@@ -371,7 +377,6 @@ function CloudStorage:onMenuHold(item)
|
||||
{
|
||||
{
|
||||
text = _("Info"),
|
||||
enabled = true,
|
||||
callback = function()
|
||||
UIManager:close(cs_server_dialog)
|
||||
self:infoServer(item)
|
||||
@@ -379,7 +384,6 @@ function CloudStorage:onMenuHold(item)
|
||||
},
|
||||
{
|
||||
text = _("Edit"),
|
||||
enabled = true,
|
||||
callback = function()
|
||||
UIManager:close(cs_server_dialog)
|
||||
self:editCloudServer(item)
|
||||
@@ -388,7 +392,6 @@ function CloudStorage:onMenuHold(item)
|
||||
},
|
||||
{
|
||||
text = _("Delete"),
|
||||
enabled = true,
|
||||
callback = function()
|
||||
UIManager:close(cs_server_dialog)
|
||||
self:deleteCloudServer(item)
|
||||
@@ -408,7 +411,6 @@ function CloudStorage:onMenuHold(item)
|
||||
},
|
||||
{
|
||||
text = _("Synchronize settings"),
|
||||
enabled = true,
|
||||
callback = function()
|
||||
UIManager:close(cs_server_dialog)
|
||||
self:synchronizeSettings(item)
|
||||
@@ -565,6 +567,119 @@ function CloudStorage:synchronizeSettings(item)
|
||||
UIManager:show(syn_dialog)
|
||||
end
|
||||
|
||||
function CloudStorage:showPlusMenu(url)
|
||||
local button_dialog
|
||||
button_dialog = ButtonDialog:new{
|
||||
buttons = {
|
||||
{
|
||||
{
|
||||
text = _("Upload file"),
|
||||
callback = function()
|
||||
UIManager:close(button_dialog)
|
||||
self:uploadFile(url)
|
||||
end,
|
||||
},
|
||||
},
|
||||
{
|
||||
{
|
||||
text = _("New folder"),
|
||||
callback = function()
|
||||
UIManager:close(button_dialog)
|
||||
self:createFolder(url)
|
||||
end,
|
||||
},
|
||||
},
|
||||
{},
|
||||
{
|
||||
{
|
||||
text = _("Return to cloud storage list"),
|
||||
callback = function()
|
||||
UIManager:close(button_dialog)
|
||||
self:init()
|
||||
end,
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
UIManager:show(button_dialog)
|
||||
end
|
||||
|
||||
function CloudStorage:uploadFile(url)
|
||||
local path_chooser
|
||||
path_chooser = PathChooser:new{
|
||||
select_directory = false,
|
||||
detailed_file_info = true,
|
||||
path = self.last_path,
|
||||
onConfirm = function(file_path)
|
||||
self.last_path = file_path:match("(.*)/")
|
||||
if self.last_path == "" then self.last_path = "/" end
|
||||
if lfs.attributes(file_path, "size") > 157286400 then
|
||||
UIManager:show(InfoMessage:new{
|
||||
text = _("File size must be less than 150 MB."),
|
||||
})
|
||||
else
|
||||
local callback_close = function()
|
||||
self:openCloudServer(url)
|
||||
end
|
||||
UIManager:nextTick(function()
|
||||
UIManager:show(InfoMessage:new{
|
||||
text = _("Uploading…"),
|
||||
timeout = 1,
|
||||
})
|
||||
end)
|
||||
UIManager:tickAfterNext(function()
|
||||
DropBox:uploadFile(url, self.password, file_path, callback_close)
|
||||
end)
|
||||
end
|
||||
end
|
||||
}
|
||||
UIManager:show(path_chooser)
|
||||
end
|
||||
|
||||
function CloudStorage:createFolder(url)
|
||||
local input_dialog, check_button_enter_folder
|
||||
input_dialog = InputDialog:new{
|
||||
title = _("New folder"),
|
||||
buttons = {
|
||||
{
|
||||
{
|
||||
text = _("Cancel"),
|
||||
callback = function()
|
||||
UIManager:close(input_dialog)
|
||||
end,
|
||||
},
|
||||
{
|
||||
text = _("Create"),
|
||||
is_enter_default = true,
|
||||
callback = function()
|
||||
local folder_name = input_dialog:getInputText()
|
||||
if folder_name == "" then return end
|
||||
UIManager:close(input_dialog)
|
||||
local callback_close = function()
|
||||
if check_button_enter_folder.checked then
|
||||
table.insert(self.paths, {
|
||||
url = url,
|
||||
})
|
||||
url = url .. "/" .. folder_name
|
||||
end
|
||||
self:openCloudServer(url)
|
||||
end
|
||||
DropBox:createFolder(url, self.password, folder_name, callback_close)
|
||||
end,
|
||||
},
|
||||
}
|
||||
},
|
||||
}
|
||||
check_button_enter_folder = CheckButton:new{
|
||||
text = _("Enter folder after creation"),
|
||||
checked = false,
|
||||
parent = input_dialog,
|
||||
}
|
||||
input_dialog:addWidget(check_button_enter_folder)
|
||||
UIManager:show(input_dialog)
|
||||
input_dialog:onShowKeyboard()
|
||||
end
|
||||
|
||||
function CloudStorage:configCloud(type)
|
||||
local callbackAdd = function(fields)
|
||||
local cs_settings = self:readSettings()
|
||||
|
||||
Reference in New Issue
Block a user