mirror of
https://github.com/koreader/koreader.git
synced 2025-08-10 00:52:38 +00:00
#1710 FR: Add support of statistics plugin for pdf
This commit is contained in:
@@ -17,7 +17,7 @@ local ReaderStatus = InputContainer:new {
|
||||
}
|
||||
|
||||
function ReaderStatus:init()
|
||||
if self.ui.document.is_djvu or self.ui.document.is_pdf or self.ui.document.is_pic then
|
||||
if self.ui.document.is_djvu or self.ui.document.is_pic then
|
||||
self.enabled = false
|
||||
return
|
||||
end
|
||||
@@ -43,6 +43,7 @@ function ReaderStatus:showStatus()
|
||||
props = self.document:getProps(),
|
||||
document = self.document,
|
||||
settings = self.settings,
|
||||
view = self.view,
|
||||
}
|
||||
UIManager:show(statusWidget)
|
||||
end
|
||||
|
||||
@@ -265,9 +265,6 @@ function ReaderUI:init()
|
||||
self:handleEvent(Event:new("PreRenderDocument", self.doc_settings))
|
||||
|
||||
self.document:render()
|
||||
|
||||
-- CREngine only reports correct page count after rendering is done
|
||||
self:handleEvent(Event:new("PostRenderDocument", self.doc_settings))
|
||||
end)
|
||||
-- typeset controller
|
||||
self:registerModule("typeset", ReaderTypeset:new{
|
||||
@@ -304,6 +301,7 @@ function ReaderUI:init()
|
||||
self:registerModule("status", ReaderStatus:new{
|
||||
ui = self,
|
||||
document = self.document,
|
||||
view = self.view,
|
||||
})
|
||||
|
||||
-- koreader plugins
|
||||
@@ -324,6 +322,11 @@ function ReaderUI:init()
|
||||
for _,v in ipairs(self.postInitCallback) do
|
||||
v()
|
||||
end
|
||||
|
||||
-- After initialisation notify that document is loaded
|
||||
-- CREngine only reports correct page count after rendering is done
|
||||
-- Need the same event for PDF document
|
||||
self:handleEvent(Event:new("ReaderReady", self.doc_settings))
|
||||
end
|
||||
|
||||
function ReaderUI:showReader(file)
|
||||
|
||||
@@ -2,9 +2,9 @@ local Cache = require("cache")
|
||||
local CacheItem = require("cacheitem")
|
||||
local KoptOptions = require("ui/data/koptoptions")
|
||||
local Document = require("document/document")
|
||||
local Configurable = require("configurable")
|
||||
local DrawContext = require("ffi/drawcontext")
|
||||
local DEBUG = require("dbg")
|
||||
local util = require("util")
|
||||
|
||||
local PdfDocument = Document:new{
|
||||
_document = false,
|
||||
@@ -160,6 +160,22 @@ function PdfDocument:close()
|
||||
Document.close(self)
|
||||
end
|
||||
|
||||
function PdfDocument:getProps()
|
||||
local props = self._document:getMetadata()
|
||||
if props.title == "" then
|
||||
local startPos = util.lastIndexOf(self.file, "%/")
|
||||
if startPos > 0 then
|
||||
props.title = string.sub(self.file, startPos + 1, -5) --remove extension .pdf
|
||||
else
|
||||
props.title = string.sub(self.file, 0, -5)
|
||||
end
|
||||
end
|
||||
props.authors = props.author
|
||||
props.series = ""
|
||||
props.language = ""
|
||||
return props
|
||||
end
|
||||
|
||||
function PdfDocument:getLinkFromPosition(pageno, pos)
|
||||
return self.koptinterface:getLinkFromPosition(self, pageno, pos)
|
||||
end
|
||||
|
||||
@@ -97,7 +97,7 @@ function StatusWidget:showStatus()
|
||||
img_height = Screen:scaleBySize(184)
|
||||
end
|
||||
|
||||
local thumb = nil
|
||||
local thumb
|
||||
if self.thumbnail then
|
||||
thumb = ImageWidget:new{
|
||||
image = self.thumbnail,
|
||||
@@ -127,7 +127,7 @@ function StatusWidget:showStatus()
|
||||
img_height,
|
||||
self.props.title,
|
||||
self.props.authors,
|
||||
self.document:getCurrentPage(),
|
||||
self.view.state.page, --current page
|
||||
self.document:getPageCount()))
|
||||
table.insert(cover_with_title_and_author_container, cover_with_title_and_author_group)
|
||||
|
||||
@@ -312,8 +312,10 @@ end
|
||||
|
||||
|
||||
function StatusWidget:saveSummary()
|
||||
self.settings:saveSetting("summary", self.summary)
|
||||
self.settings:flush()
|
||||
if self.summary then
|
||||
self.settings:saveSetting("summary", self.summary)
|
||||
self.settings:flush()
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
|
||||
@@ -8,7 +8,7 @@ function util.stripePunctuations(word)
|
||||
if not word then return end
|
||||
-- strip ASCII punctuation characters around word
|
||||
-- and strip any generic punctuation (U+2000 - U+206F) in the word
|
||||
return word:gsub("\226[\128-\131][\128-\191]",''):gsub("^%p+",''):gsub("%p+$",'')
|
||||
return word:gsub("\226[\128-\131][\128-\191]", ''):gsub("^%p+", ''):gsub("%p+$", '')
|
||||
end
|
||||
|
||||
--[[
|
||||
@@ -81,9 +81,17 @@ end
|
||||
|
||||
-- append all elements from t2 into t1
|
||||
function util.arrayAppend(t1, t2)
|
||||
for _,v in ipairs(t2) do
|
||||
for _, v in ipairs(t2) do
|
||||
table.insert(t1, v)
|
||||
end
|
||||
end
|
||||
|
||||
-- Returns the index within this string of the last occurrence of the specified character
|
||||
-- or -1 if the character does not occur.
|
||||
-- To find . you need to escape it.
|
||||
function util.lastIndexOf(string, ch)
|
||||
local i = string:match(".*" .. ch .. "()")
|
||||
if i == nil then return -1 else return i - 1 end
|
||||
end
|
||||
|
||||
return util
|
||||
|
||||
@@ -7,8 +7,6 @@ local Menu = require("ui/widget/menu")
|
||||
local Font = require("ui/font")
|
||||
local TimeVal = require("ui/timeval")
|
||||
local DataStorage = require("datastorage")
|
||||
local DocSettings = require("docsettings")
|
||||
local dump = require("dump")
|
||||
local lfs = require("libs/libkoreader-lfs")
|
||||
local DEBUG = require("dbg")
|
||||
local T = require("ffi/util").template
|
||||
@@ -39,7 +37,7 @@ local ReaderStatistics = InputContainer:new {
|
||||
}
|
||||
|
||||
function ReaderStatistics:init()
|
||||
if self.ui.document.is_djvu or self.ui.document.is_pdf or self.ui.document.is_pic then
|
||||
if self.ui.document.is_djvu or self.ui.document.is_pic then
|
||||
return
|
||||
end
|
||||
|
||||
@@ -234,7 +232,7 @@ function ReaderStatistics:updateCurrentStat()
|
||||
end
|
||||
|
||||
local read_pages = util.tableSize(self.data.performance_in_pages)
|
||||
local current_page = self.ui.document:getCurrentPage()
|
||||
local current_page = self.view.state.page --get current page from the view
|
||||
local average_time_per_page = self.data.total_time_in_sec / read_pages
|
||||
|
||||
table.insert(stats, { text = _("Current period"), mandatory = util.secondsToClock(self.current_period, false) })
|
||||
@@ -316,7 +314,6 @@ function ReaderStatistics:updateTotalStat()
|
||||
|
||||
total_books_time = total_books_time + tonumber(self.data.total_time_in_sec)
|
||||
|
||||
DEBUG ("TOTALSTATS", total_stats)
|
||||
table.insert(total_stats, 1, { text = _("Total hours read"), mandatory = util.secondsToClock(total_books_time, false) })
|
||||
table.insert(total_stats, 2, { text = "-" })
|
||||
table.insert(total_stats, 3, {
|
||||
@@ -384,7 +381,7 @@ end
|
||||
function ReaderStatistics:getBookProperties()
|
||||
local props = self.view.document:getProps()
|
||||
if props.title == "No document" or props.title == "" then --sometime crengine returns "No document" try to get one more time
|
||||
props = self.view.document:getProps()
|
||||
props = self.view.document:getProps()
|
||||
end
|
||||
return props
|
||||
end
|
||||
@@ -491,7 +488,7 @@ function ReaderStatistics:onReadSettings(config)
|
||||
self.data = config.data.stats
|
||||
end
|
||||
|
||||
function ReaderStatistics:onPostRenderDocument()
|
||||
function ReaderStatistics:onReaderReady()
|
||||
-- we have correct page count now, do the actual initialization work
|
||||
self:initData()
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user