From ae1dd3b3806db856aaa7e956e4b07c602f313bfc Mon Sep 17 00:00:00 2001 From: chrox Date: Wed, 5 Nov 2014 16:58:09 +0800 Subject: [PATCH 1/4] screenshot to PNG files by default --- .../apps/reader/modules/readerscreenshot.lua | 21 ++++++----- frontend/device/screen.lua | 6 +++- spec/unit/filemanager_spec.lua | 13 +++++++ spec/unit/readerscreenshot_spec.lua | 36 +++++++++++++++++++ spec/unit/readerui_spec.lua | 6 ++++ 5 files changed, 70 insertions(+), 12 deletions(-) create mode 100644 spec/unit/filemanager_spec.lua create mode 100644 spec/unit/readerscreenshot_spec.lua diff --git a/frontend/apps/reader/modules/readerscreenshot.lua b/frontend/apps/reader/modules/readerscreenshot.lua index 0698c468f..8fad7d925 100644 --- a/frontend/apps/reader/modules/readerscreenshot.lua +++ b/frontend/apps/reader/modules/readerscreenshot.lua @@ -7,7 +7,9 @@ local InfoMessage = require("ui/widget/infomessage") local _ = require("gettext") local DEBUG = require("dbg") -local ReaderScreenshot = InputContainer:new{} +local ReaderScreenshot = InputContainer:new{ + datetime_name = "screenshots/Screenshot_%Y-%b-%d_%Hh%M.png", +} function ReaderScreenshot:init() local diagonal = math.sqrt( @@ -32,16 +34,13 @@ function ReaderScreenshot:init() } end -function ReaderScreenshot:onScreenshot() - if os.execute("screenshot") ~= 0 then - local screenshot_name = os.date("screenshots/Screenshot_%Y-%B-%d_%Hh%M.pam") - UIManager:show(InfoMessage:new{ - text = _("Writing screen to ")..screenshot_name, - timeout = 2, - }) - Screen.bb:writePAM(screenshot_name) - DEBUG(screenshot_name) - end +function ReaderScreenshot:onScreenshot(filename) + local screenshot_name = filename or os.date(self.datetime_name) + UIManager:show(InfoMessage:new{ + text = _("Writing screen to ")..screenshot_name, + timeout = 2, + }) + Screen:shot(screenshot_name) UIManager.full_refresh = true return true end diff --git a/frontend/device/screen.lua b/frontend/device/screen.lua index 81ef62f9d..d755bb3cc 100644 --- a/frontend/device/screen.lua +++ b/frontend/device/screen.lua @@ -174,10 +174,14 @@ function Screen:restoreFromSavedBB() end end +function Screen:shot(filename) + DEBUG("write PNG file", filename) + self.bb:writePNG(filename) +end + function Screen:close() DEBUG("close screen framebuffer") self.fb:close() end - return Screen diff --git a/spec/unit/filemanager_spec.lua b/spec/unit/filemanager_spec.lua new file mode 100644 index 000000000..87e6666bc --- /dev/null +++ b/spec/unit/filemanager_spec.lua @@ -0,0 +1,13 @@ +require("commonrequire") +local FileManager = require("apps/filemanager/filemanager") +local UIManager = require("ui/uimanager") +local Screen = require("device").screen +local DEBUG = require("dbg") + +describe("FileManager module", function() + it("should show file manager", function() + FileManager:showFiles("../../test") + UIManager:scheduleIn(1, function() UIManager:quit() end) + UIManager:run() + end) +end) diff --git a/spec/unit/readerscreenshot_spec.lua b/spec/unit/readerscreenshot_spec.lua new file mode 100644 index 000000000..82462bdc9 --- /dev/null +++ b/spec/unit/readerscreenshot_spec.lua @@ -0,0 +1,36 @@ +require("commonrequire") +local DocumentRegistry = require("document/documentregistry") +local ReaderUI = require("apps/reader/readerui") +local lfs = require("libs/libkoreader-lfs") +local UIManager = require("ui/uimanager") +local Screen = require("device").screen +local Event = require("ui/event") +local DEBUG = require("dbg") + +describe("ReaderScreenshot module", function() + local sample_epub = "spec/front/unit/data/leaves.epub" + local readerui + setup(function() + readerui = ReaderUI:new{ + document = DocumentRegistry:openDocument(sample_epub), + } + end) + it("should get screenshot in portrait", function() + local name = "screenshots/reader_screenshot_portrait.png" + readerui:handleEvent(Event:new("ChangeScreenMode", "portrait")) + UIManager:show(readerui) + UIManager:scheduleIn(1, function() UIManager:close(readerui) end) + UIManager:run() + readerui.screenshot:onScreenshot(name) + assert.truthy(lfs.attributes(name, "mode")) + end) + it("should get screenshot in landscape", function() + local name = "screenshots/reader_screenshot_landscape.png" + readerui:handleEvent(Event:new("ChangeScreenMode", "landscape")) + UIManager:show(readerui) + UIManager:scheduleIn(2, function() UIManager:close(readerui) end) + UIManager:run() + readerui.screenshot:onScreenshot(name) + assert.truthy(lfs.attributes(name, "mode")) + end) +end) diff --git a/spec/unit/readerui_spec.lua b/spec/unit/readerui_spec.lua index 241797d20..4e13a433f 100644 --- a/spec/unit/readerui_spec.lua +++ b/spec/unit/readerui_spec.lua @@ -2,6 +2,7 @@ require("commonrequire") local DocumentRegistry = require("document/documentregistry") local ReaderUI = require("apps/reader/readerui") local DocSettings = require("docsettings") +local UIManager = require("ui/uimanager") local DEBUG = require("dbg") describe("Readerui module", function() @@ -21,6 +22,11 @@ describe("Readerui module", function() assert.are.same(doc_settings.data.last_xpointer, readerui.doc_settings.data.last_xpointer) end) + it("should show reader", function() + UIManager:show(readerui) + UIManager:scheduleIn(1, function() UIManager:close(readerui) end) + UIManager:run() + end) it("should close document", function() readerui:closeDocument() assert(readerui.document == nil) From b401bca59adb987a25021f2684944cd8628a1848 Mon Sep 17 00:00:00 2001 From: chrox Date: Wed, 5 Nov 2014 16:58:48 +0800 Subject: [PATCH 2/4] get rid of unneccessary requirements --- plugins/zsync.koplugin/main.lua | 3 --- 1 file changed, 3 deletions(-) diff --git a/plugins/zsync.koplugin/main.lua b/plugins/zsync.koplugin/main.lua index 61f0f6eff..ae724abe5 100644 --- a/plugins/zsync.koplugin/main.lua +++ b/plugins/zsync.koplugin/main.lua @@ -1,8 +1,5 @@ -local FileManagerHistory = require("apps/filemanager/filemanagerhistory") -local FileManagerMenu = require("apps/filemanager/filemanagermenu") local InputContainer = require("ui/widget/container/inputcontainer") local FrameContainer = require("ui/widget/container/framecontainer") -local FileManager = require("apps/filemanager/filemanager") local VerticalGroup = require("ui/widget/verticalgroup") local VerticalSpan = require("ui/widget/verticalspan") local ButtonDialog = require("ui/widget/buttondialog") From ab3708e64aeb76eec32de70231982560d5948a72 Mon Sep 17 00:00:00 2001 From: chrox Date: Wed, 5 Nov 2014 16:59:07 +0800 Subject: [PATCH 3/4] update koreader-base --- base | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/base b/base index 5a83d4aad..f342e7fed 160000 --- a/base +++ b/base @@ -1 +1 @@ -Subproject commit 5a83d4aaded90420306380613ccdc4613a53a9ce +Subproject commit f342e7fedabe46dde7a54f30e25d555d4d311879 From 616ef3ba8e4dd601e6f3f6b61ccd8b93f0361184 Mon Sep 17 00:00:00 2001 From: chrox Date: Wed, 5 Nov 2014 18:06:05 +0800 Subject: [PATCH 4/4] quit uimanager before run uimanager in test --- spec/unit/filemanager_spec.lua | 9 +++++++-- spec/unit/readerscreenshot_spec.lua | 2 ++ spec/unit/readerui_spec.lua | 10 +++++++--- 3 files changed, 16 insertions(+), 5 deletions(-) diff --git a/spec/unit/filemanager_spec.lua b/spec/unit/filemanager_spec.lua index 87e6666bc..9eded5650 100644 --- a/spec/unit/filemanager_spec.lua +++ b/spec/unit/filemanager_spec.lua @@ -6,8 +6,13 @@ local DEBUG = require("dbg") describe("FileManager module", function() it("should show file manager", function() - FileManager:showFiles("../../test") - UIManager:scheduleIn(1, function() UIManager:quit() end) + UIManager:quit() + local filemanager = FileManager:new{ + dimen = Screen:getSize(), + root_path = "../../test", + } + UIManager:show(filemanager) + UIManager:scheduleIn(1, function() UIManager:close(filemanager) end) UIManager:run() end) end) diff --git a/spec/unit/readerscreenshot_spec.lua b/spec/unit/readerscreenshot_spec.lua index 82462bdc9..245b43559 100644 --- a/spec/unit/readerscreenshot_spec.lua +++ b/spec/unit/readerscreenshot_spec.lua @@ -18,6 +18,7 @@ describe("ReaderScreenshot module", function() it("should get screenshot in portrait", function() local name = "screenshots/reader_screenshot_portrait.png" readerui:handleEvent(Event:new("ChangeScreenMode", "portrait")) + UIManager:quit() UIManager:show(readerui) UIManager:scheduleIn(1, function() UIManager:close(readerui) end) UIManager:run() @@ -27,6 +28,7 @@ describe("ReaderScreenshot module", function() it("should get screenshot in landscape", function() local name = "screenshots/reader_screenshot_landscape.png" readerui:handleEvent(Event:new("ChangeScreenMode", "landscape")) + UIManager:quit() UIManager:show(readerui) UIManager:scheduleIn(2, function() UIManager:close(readerui) end) UIManager:run() diff --git a/spec/unit/readerui_spec.lua b/spec/unit/readerui_spec.lua index 4e13a433f..9b349c7ed 100644 --- a/spec/unit/readerui_spec.lua +++ b/spec/unit/readerui_spec.lua @@ -7,9 +7,12 @@ local DEBUG = require("dbg") describe("Readerui module", function() local sample_epub = "spec/front/unit/data/leaves.epub" - local readerui = ReaderUI:new{ - document = DocumentRegistry:openDocument(sample_epub), - } + local readerui + setup(function() + readerui = ReaderUI:new{ + document = DocumentRegistry:openDocument(sample_epub), + } + end) it("should save settings", function() -- remove history settings and sidecar settings DocSettings:open(sample_epub):clear() @@ -23,6 +26,7 @@ describe("Readerui module", function() readerui.doc_settings.data.last_xpointer) end) it("should show reader", function() + UIManager:quit() UIManager:show(readerui) UIManager:scheduleIn(1, function() UIManager:close(readerui) end) UIManager:run()