2020-01-04 00:18:51 +00:00
|
|
|
local BD = require("ui/bidi")
|
2019-09-17 11:01:40 +00:00
|
|
|
local ButtonDialogTitle = require("ui/widget/buttondialogtitle")
|
2018-07-28 18:18:31 +00:00
|
|
|
local ConfirmBox = require("ui/widget/confirmbox")
|
2015-10-03 06:18:47 +00:00
|
|
|
local DataStorage = require("datastorage")
|
2018-07-28 18:18:31 +00:00
|
|
|
local GestureRange = require("ui/gesturerange")
|
2019-09-17 11:01:40 +00:00
|
|
|
local InfoMessage = require("ui/widget/infomessage")
|
2018-07-28 18:18:31 +00:00
|
|
|
local InputContainer = require("ui/widget/container/inputcontainer")
|
2013-10-18 20:38:07 +00:00
|
|
|
local UIManager = require("ui/uimanager")
|
2015-10-03 06:18:47 +00:00
|
|
|
local Screen = require("device").screen
|
2014-11-28 13:10:37 +00:00
|
|
|
local T = require("ffi/util").template
|
|
|
|
local _ = require("gettext")
|
2013-03-06 14:36:51 +00:00
|
|
|
|
2016-01-03 08:47:01 +00:00
|
|
|
local Screenshoter = InputContainer:new{
|
|
|
|
prefix = 'Screenshot',
|
2014-11-05 08:58:09 +00:00
|
|
|
}
|
2013-03-06 14:36:51 +00:00
|
|
|
|
2016-01-03 08:47:01 +00:00
|
|
|
function Screenshoter:init()
|
2014-03-13 13:52:43 +00:00
|
|
|
local diagonal = math.sqrt(
|
|
|
|
math.pow(Screen:getWidth(), 2) +
|
|
|
|
math.pow(Screen:getHeight(), 2)
|
|
|
|
)
|
|
|
|
self.ges_events = {
|
2014-06-17 13:12:42 +00:00
|
|
|
TapDiagonal = {
|
2014-03-13 13:52:43 +00:00
|
|
|
GestureRange:new{
|
|
|
|
ges = "two_finger_tap",
|
2014-11-20 22:07:39 +00:00
|
|
|
scale = {diagonal - Screen:scaleBySize(200), diagonal},
|
2014-03-13 13:52:43 +00:00
|
|
|
rate = 1.0,
|
|
|
|
}
|
|
|
|
},
|
2014-06-17 13:12:42 +00:00
|
|
|
SwipeDiagonal = {
|
|
|
|
GestureRange:new{
|
|
|
|
ges = "swipe",
|
2014-11-20 22:07:39 +00:00
|
|
|
scale = {diagonal - Screen:scaleBySize(200), diagonal},
|
2014-06-17 13:12:42 +00:00
|
|
|
rate = 1.0,
|
|
|
|
}
|
|
|
|
},
|
2014-03-13 13:52:43 +00:00
|
|
|
}
|
2013-03-06 14:36:51 +00:00
|
|
|
end
|
|
|
|
|
2016-01-03 08:47:01 +00:00
|
|
|
function Screenshoter:onScreenshot(filename)
|
2019-09-17 11:01:40 +00:00
|
|
|
local screenshots_dir = G_reader_settings:readSetting("screenshot_dir") or DataStorage:getDataDir() .. "/screenshots/"
|
2020-04-22 07:07:48 +00:00
|
|
|
self.screenshot_fn_fmt = screenshots_dir .. self.prefix .. "_%Y-%m-%d_%H%M%S.png"
|
2016-01-03 08:47:01 +00:00
|
|
|
local screenshot_name = filename or os.date(self.screenshot_fn_fmt)
|
2018-08-19 18:21:03 +00:00
|
|
|
Screen:shot(screenshot_name)
|
2018-07-28 18:18:31 +00:00
|
|
|
local widget = ConfirmBox:new{
|
2020-01-04 00:18:51 +00:00
|
|
|
text = T( _("Saved screenshot to %1.\nWould you like to set it as screensaver?"), BD.filepath(screenshot_name)),
|
2018-07-28 18:18:31 +00:00
|
|
|
ok_text = _("Yes"),
|
|
|
|
ok_callback = function()
|
|
|
|
G_reader_settings:saveSetting("screensaver_type", "image_file")
|
|
|
|
G_reader_settings:saveSetting("screensaver_image", screenshot_name)
|
|
|
|
end,
|
|
|
|
cancel_text = _("No"),
|
|
|
|
}
|
|
|
|
UIManager:show(widget)
|
2014-11-30 00:12:00 +00:00
|
|
|
-- trigger full refresh
|
|
|
|
UIManager:setDirty(nil, "full")
|
2014-03-13 13:52:43 +00:00
|
|
|
return true
|
2013-03-06 14:36:51 +00:00
|
|
|
end
|
|
|
|
|
2019-09-17 11:01:40 +00:00
|
|
|
function Screenshoter:chooseFolder()
|
|
|
|
local buttons = {}
|
|
|
|
table.insert(buttons, {
|
|
|
|
{
|
|
|
|
text = _("Choose screenshot directory"),
|
|
|
|
callback = function()
|
|
|
|
UIManager:close(self.choose_dialog)
|
|
|
|
require("ui/downloadmgr"):new{
|
|
|
|
onConfirm = function(path)
|
|
|
|
G_reader_settings:saveSetting("screenshot_dir", path .. "/")
|
|
|
|
UIManager:show(InfoMessage:new{
|
2020-01-04 00:18:51 +00:00
|
|
|
text = T(_("Screenshot directory set to:\n%1"), BD.dirpath(path)),
|
2019-09-17 11:01:40 +00:00
|
|
|
timeout = 3,
|
|
|
|
})
|
|
|
|
end,
|
|
|
|
}:chooseDir()
|
|
|
|
end,
|
|
|
|
}
|
|
|
|
})
|
|
|
|
table.insert(buttons, {
|
|
|
|
{
|
|
|
|
text = _("Close"),
|
|
|
|
callback = function()
|
|
|
|
UIManager:close(self.choose_dialog)
|
|
|
|
end,
|
|
|
|
}
|
|
|
|
})
|
|
|
|
local screenshot_dir = G_reader_settings:readSetting("screenshot_dir") or DataStorage:getDataDir() .. "/screenshots/"
|
|
|
|
self.choose_dialog = ButtonDialogTitle:new{
|
2020-01-04 00:18:51 +00:00
|
|
|
title = T(_("Current screenshot directory:\n%1"), BD.dirpath(screenshot_dir)),
|
2019-09-17 11:01:40 +00:00
|
|
|
buttons = buttons
|
|
|
|
}
|
|
|
|
UIManager:show(self.choose_dialog)
|
|
|
|
end
|
|
|
|
|
2016-01-03 08:47:01 +00:00
|
|
|
function Screenshoter:onTapDiagonal()
|
2014-06-17 13:12:42 +00:00
|
|
|
return self:onScreenshot()
|
|
|
|
end
|
|
|
|
|
2016-01-03 08:47:01 +00:00
|
|
|
function Screenshoter:onSwipeDiagonal()
|
2014-06-17 13:12:42 +00:00
|
|
|
return self:onScreenshot()
|
|
|
|
end
|
|
|
|
|
2016-01-03 08:47:01 +00:00
|
|
|
return Screenshoter
|