From 8f982faa7ba472df4c957a341b1934f32604b9b5 Mon Sep 17 00:00:00 2001 From: chrox Date: Sun, 11 May 2014 20:19:00 +0800 Subject: [PATCH 1/4] fix page to screen rect transform for highlighting --- frontend/apps/reader/modules/readerlink.lua | 4 +++- frontend/apps/reader/modules/readerview.lua | 1 - 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/frontend/apps/reader/modules/readerlink.lua b/frontend/apps/reader/modules/readerlink.lua index c43a73d29..39f8a18a3 100644 --- a/frontend/apps/reader/modules/readerlink.lua +++ b/frontend/apps/reader/modules/readerlink.lua @@ -61,10 +61,12 @@ function ReaderLink:onTap(arg, ges) if self.ui.document.info.has_pages then local pos = self.view:screenToPageTransform(ges.pos) if pos then + -- link box in native page local link, lbox = self.ui.document:getLinkFromPosition(pos.page, pos) if link and lbox then -- screen box that holds the link - local sbox = self.view:pageToScreenTransform(pos.page, lbox) + local sbox = self.view:pageToScreenTransform(pos.page, + self.ui.document:nativeToPageRectTransform(pos.page, lbox)) if sbox then UIManager:show(LinkBox:new{ box = sbox, diff --git a/frontend/apps/reader/modules/readerview.lua b/frontend/apps/reader/modules/readerview.lua index c96f9d5e7..e6c806295 100644 --- a/frontend/apps/reader/modules/readerview.lua +++ b/frontend/apps/reader/modules/readerview.lua @@ -167,7 +167,6 @@ Given rectangle in original page return rectangle on the screen ]]-- function ReaderView:pageToScreenTransform(page, rect) if self.ui.document.info.has_pages then - rect = self.ui.document:nativeToPageRectTransform(page, rect) if self.page_scroll then return self:getScrollPageRect(page, rect) else From 6bf1a9d0334213307ede77f56059a06ce627ce16 Mon Sep 17 00:00:00 2001 From: chrox Date: Sun, 11 May 2014 20:57:18 +0800 Subject: [PATCH 2/4] use setStringProperty method to set font face This should fix #569. --- frontend/document/credocument.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/frontend/document/credocument.lua b/frontend/document/credocument.lua index 7501be049..a17da20bd 100644 --- a/frontend/document/credocument.lua +++ b/frontend/document/credocument.lua @@ -272,7 +272,7 @@ end function CreDocument:setFontFace(new_font_face) if new_font_face then DEBUG("CreDocument: set font face", new_font_face) - self._document:setFontFace(new_font_face) + self._document:setStringProperty("font.face.default", new_font_face) end end From 3b1e05bb7ff4b5257b3d21db0a0fdbef1cdc8cb8 Mon Sep 17 00:00:00 2001 From: chrox Date: Mon, 12 May 2014 15:47:11 +0800 Subject: [PATCH 3/4] switch to setIntProperty api for setting page margins --- frontend/document/credocument.lua | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/frontend/document/credocument.lua b/frontend/document/credocument.lua index a17da20bd..f7ab6d6f0 100644 --- a/frontend/document/credocument.lua +++ b/frontend/document/credocument.lua @@ -127,7 +127,6 @@ function CreDocument:loadDocument() end function CreDocument:close() - self._document:saveDefaults() Document.close(self) end @@ -335,13 +334,17 @@ function CreDocument:setStyleSheet(new_css) end function CreDocument:setEmbeddedStyleSheet(toggle) + -- FIXME: occasional segmentation fault when switching embedded style sheet DEBUG("CreDocument: set embedded style sheet", toggle) - self._document:setEmbeddedStyleSheet(toggle) + self._document:setIntProperty("crengine.doc.embedded.styles.enabled", toggle) end function CreDocument:setPageMargins(left, top, right, bottom) DEBUG("CreDocument: set page margins", left, top, right, bottom) - self._document:setPageMargins(left, top, right, bottom) + self._document:setIntProperty("crengine.page.margin.left", left) + self._document:setIntProperty("crengine.page.margin.top", top) + self._document:setIntProperty("crengine.page.margin.right", right) + self._document:setIntProperty("crengine.page.margin.bottom", bottom) end function CreDocument:setFloatingPunctuation(enabled) From 6a9adbacca67f54a6fd39cde4087f2ef239166d6 Mon Sep 17 00:00:00 2001 From: chrox Date: Mon, 12 May 2014 18:07:20 +0800 Subject: [PATCH 4/4] incremental exporting of all notes --- plugins/evernote.koplugin/main.lua | 62 +++++++++++++++++++++--------- 1 file changed, 44 insertions(+), 18 deletions(-) diff --git a/plugins/evernote.koplugin/main.lua b/plugins/evernote.koplugin/main.lua index 0342561fe..ded2d555b 100644 --- a/plugins/evernote.koplugin/main.lua +++ b/plugins/evernote.koplugin/main.lua @@ -1,6 +1,7 @@ local InputContainer = require("ui/widget/container/inputcontainer") local LoginDialog = require("ui/widget/logindialog") local InfoMessage = require("ui/widget/infomessage") +local DocSettings = require("docsettings") local UIManager = require("ui/uimanager") local Screen = require("ui/screen") local Event = require("ui/event") @@ -33,6 +34,7 @@ function EvernoteExporter:init() history_dir = "./history", } self.template = slt2.loadfile(self.path.."/note.tpl") + self.config = DocSettings:open(self.path) end function EvernoteExporter:addToMainMenu(tab_item_table) @@ -230,6 +232,24 @@ function EvernoteExporter:exportCurrentNotes(view) self:exportClippings(client, clippings) end +function EvernoteExporter:updateClippings(clippings, new_clippings) + for title, booknotes in pairs(new_clippings) do + for chapter_index, chapternotes in ipairs(booknotes) do + for note_index, note in ipairs(chapternotes) do + if clippings[title] == nil or clippings[title][chapter_index] == nil + or clippings[title][chapter_index][note_index] == nil + or clippings[title][chapter_index][note_index].page ~= note.page + or clippings[title][chapter_index][note_index].time ~= note.time + or clippings[title][chapter_index][note_index].text ~= note.text + or clippings[title][chapter_index][note_index].note ~= note.note then + clippings[title] = booknotes + end + end + end + end + return clippings +end + function EvernoteExporter:exportAllNotes() local EvernoteClient = require("EvernoteClient") local client = EvernoteClient:new{ @@ -237,10 +257,9 @@ function EvernoteExporter:exportAllNotes() authToken = self.evernote_token, } - local clippings = self.parser:parseMyClippings() - if next(clippings) == nil then - clippings = self.parser:parseHistory() - end + local clippings = self.config:readSetting("clippings") or {} + clippings = self:updateClippings(clippings, self.parser:parseMyClippings()) + clippings = self:updateClippings(clippings, self.parser:parseHistory()) -- remove blank entries for title, booknotes in pairs(clippings) do -- chapter number is zero @@ -250,45 +269,52 @@ function EvernoteExporter:exportAllNotes() end --DEBUG("clippings", clippings) self:exportClippings(client, clippings) + self.config:saveSetting("clippings", clippings) + self.config:flush() end function EvernoteExporter:exportClippings(client, clippings) local export_count, error_count = 0, 0 local export_title, error_title for title, booknotes in pairs(clippings) do - local ok, err = pcall(self.exportBooknotes, self, client, title, booknotes) - - -- error reporting - if not ok then - DEBUG("Error occurs when exporting book:", title, err) - error_count = error_count + 1 - error_title = title + -- skip exported booknotes + if booknotes.exported ~= true then + local ok, err = pcall(self.exportBooknotes, self, + client, title, booknotes) + -- error reporting + if not ok then + DEBUG("Error occurs when exporting book:", title, err) + error_count = error_count + 1 + error_title = title + else + DEBUG("Exported notes in book:", title) + export_count = export_count + 1 + export_title = title + booknotes.exported = true + end else - DEBUG("Exported notes in book:", title) - export_count = export_count + 1 - export_title = title + DEBUG("Skip exporting notes in book:", title) end end - local msg = "" + local msg = "Not exported anything." local all_count = export_count + error_count if export_count > 0 and error_count == 0 then if all_count == 1 then msg = _("Exported notes in book:") .. "\n" .. export_title else msg = _("Exported notes in book:") .. "\n" .. export_title - msg = msg .. "\n" .. _("and ") .. all_count-1 .. _("others.") + msg = msg .. "\n" .. _("and ") .. all_count-1 .. _(" others.") end elseif error_count > 0 then if all_count == 1 then msg = _("Error occurs when exporting book:") .. "\n" .. error_title else msg = _("Errors occur when exporting book:") .. "\n" .. error_title - msg = msg .. "\n" .. _("and ") .. error_count-1 .. ("others.") + msg = msg .. "\n" .. _("and ") .. error_count-1 .. (" others.") end end UIManager:show(InfoMessage:new{ text = msg }) - end function EvernoteExporter:exportBooknotes(client, title, booknotes)