From d3cf30aab29cbf5c69a7a65f3dba333fbc2d21e9 Mon Sep 17 00:00:00 2001 From: chrox Date: Thu, 1 May 2014 10:06:50 +0800 Subject: [PATCH 1/5] update koreader-base --- koreader-base | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/koreader-base b/koreader-base index 3b5663851..c78c2cd4a 160000 --- a/koreader-base +++ b/koreader-base @@ -1 +1 @@ -Subproject commit 3b566385128b722594cde00fa599f035621168fa +Subproject commit c78c2cd4a8824f855a330ff50b631d554f830120 From 659e5f6bddd9610759cd9e59a58b8f0604248a45 Mon Sep 17 00:00:00 2001 From: chrox Date: Thu, 1 May 2014 11:58:05 +0800 Subject: [PATCH 2/5] use buildin LuaJIT profiler --- koreader-base | 2 +- reader.lua | 18 ++++-------------- 2 files changed, 5 insertions(+), 15 deletions(-) diff --git a/koreader-base b/koreader-base index c78c2cd4a..362a1c51b 160000 --- a/koreader-base +++ b/koreader-base @@ -1 +1 @@ -Subproject commit c78c2cd4a8824f855a330ff50b631d554f830120 +Subproject commit 362a1c51b186339270733edae3206666c583bfab diff --git a/reader.lua b/reader.lua index 2cb04dfa7..ccc405307 100755 --- a/reader.lua +++ b/reader.lua @@ -26,14 +26,9 @@ local Screen = require("ui/screen") local ReaderUI = require("apps/reader/readerui") -Profiler = nil +local Profiler = nil function exitReader() - if Profiler ~= nil then - Profiler:stop() - Profiler:dump("./profile.html") - end - G_reader_settings:close() input.closeAll() @@ -56,6 +51,7 @@ function exitReader() end end + if Profiler then Profiler.stop() end os.exit(0) end @@ -146,14 +142,8 @@ while argidx <= #ARGV do elseif arg == "-d" then DEBUG:turnOn() elseif arg == "-p" then - local lulip = require("ffi/lulip") - Profiler = lulip:new() - pcall(function() - -- set maxrows only if the optional arg is numeric - Profiler:maxrows(ARGV[argidx] + 0) - argidx = argidx + 1 - end) - Profiler:start() + Profiler = require("jit.p") + Profiler.start("la") else -- not a recognized option, should be a filename argidx = argidx - 1 From 877cff29334ee9569d7e50b6249804addcce962f Mon Sep 17 00:00:00 2001 From: chrox Date: Thu, 1 May 2014 18:37:12 +0800 Subject: [PATCH 3/5] invert button on tap --- .../apps/reader/modules/readercropping.lua | 2 ++ frontend/ui/widget/button.lua | 10 +++++- frontend/ui/widget/buttondialog.lua | 1 + frontend/ui/widget/buttontable.lua | 1 + frontend/ui/widget/confirmbox.lua | 2 ++ frontend/ui/widget/dictquicklookup.lua | 15 +++++---- frontend/ui/widget/inputdialog.lua | 1 + frontend/ui/widget/menu.lua | 2 ++ frontend/ui/widget/touchmenu.lua | 33 ++++++++++++++++--- 9 files changed, 55 insertions(+), 12 deletions(-) diff --git a/frontend/apps/reader/modules/readercropping.lua b/frontend/apps/reader/modules/readercropping.lua index 439176474..df2a07fee 100644 --- a/frontend/apps/reader/modules/readercropping.lua +++ b/frontend/apps/reader/modules/readercropping.lua @@ -32,6 +32,7 @@ function PageCropDialog:init() radius = 7, text_font_face = "cfont", text_font_size = 20, + show_parent = self, } local cancel_button = Button:new{ text = self.cancel_text, @@ -41,6 +42,7 @@ function PageCropDialog:init() radius = 7, text_font_face = "cfont", text_font_size = 20, + show_parent = self, } local ok_container = RightContainer:new{ dimen = Geom:new{ w = Screen:getWidth()*0.33, h = Screen:getHeight()/12}, diff --git a/frontend/ui/widget/button.lua b/frontend/ui/widget/button.lua index eb7415b4a..fb77eae03 100644 --- a/frontend/ui/widget/button.lua +++ b/frontend/ui/widget/button.lua @@ -6,7 +6,9 @@ local Geom = require("ui/geometry") local GestureRange = require("ui/gesturerange") local FrameContainer = require("ui/widget/container/framecontainer") local CenterContainer = require("ui/widget/container/centercontainer") +local UIManager = require("ui/uimanager") local Device = require("ui/device") +local DEBUG = require("dbg") local _ = require("gettext") --[[ @@ -139,7 +141,13 @@ end function Button:onTapSelect() if self.enabled then - self.callback() + self[1].invert = true + UIManager:setDirty(self.show_parent, "partial") + UIManager:scheduleIn(0.1, function() + self.callback() + self[1].invert = false + UIManager:setDirty(self.show_parent, "partial") + end) end return true end diff --git a/frontend/ui/widget/buttondialog.lua b/frontend/ui/widget/buttondialog.lua index 611b8369c..ad4794acd 100644 --- a/frontend/ui/widget/buttondialog.lua +++ b/frontend/ui/widget/buttondialog.lua @@ -39,6 +39,7 @@ function ButtonDialog:init() ButtonTable:new{ width = Screen:getWidth()*0.9, buttons = self.buttons, + show_parent = self, }, background = 0, bordersize = 2, diff --git a/frontend/ui/widget/buttontable.lua b/frontend/ui/widget/buttontable.lua index 36ead3d11..e431c1d56 100644 --- a/frontend/ui/widget/buttontable.lua +++ b/frontend/ui/widget/buttontable.lua @@ -42,6 +42,7 @@ function ButtonTable:init() padding = 0, text_font_face = self.button_font_face, text_font_size = self.button_font_size, + show_parent = self.show_parent, } local button_dim = button:getSize() local vertical_sep = LineWidget:new{ diff --git a/frontend/ui/widget/confirmbox.lua b/frontend/ui/widget/confirmbox.lua index 86cc44c40..9fa53c281 100644 --- a/frontend/ui/widget/confirmbox.lua +++ b/frontend/ui/widget/confirmbox.lua @@ -43,6 +43,7 @@ function ConfirmBox:init() self.ok_callback() UIManager:close(self) end, + show_parent = self, } local cancel_button = Button:new{ text = self.cancel_text, @@ -51,6 +52,7 @@ function ConfirmBox:init() self.cancel_callback() UIManager:close(self) end, + show_parent = self, } self.layout = { { ok_button, cancel_button } } diff --git a/frontend/ui/widget/dictquicklookup.lua b/frontend/ui/widget/dictquicklookup.lua index b5688adff..7d6f1b082 100644 --- a/frontend/ui/widget/dictquicklookup.lua +++ b/frontend/ui/widget/dictquicklookup.lua @@ -34,7 +34,7 @@ local DictQuickLookup = InputContainer:new{ content_face = Font:getFace("cfont", DDICT_FONT_SIZE), width = nil, height = nil, - + title_padding = Screen:scaleByDPI(5), title_margin = Screen:scaleByDPI(2), word_padding = Screen:scaleByDPI(2), @@ -113,13 +113,13 @@ function DictQuickLookup:update() height = self.height*0.7, dialog = self, }, - } + } local button_table = ButtonTable:new{ width = math.max(self.width, definition:getSize().w), button_font_face = "cfont", button_font_size = 20, buttons = { - { + { { text = _("<<"), enabled = self:isPrevDictAvaiable(), @@ -153,6 +153,7 @@ function DictQuickLookup:update() }, }, zero_sep = true, + show_parent = self, } local title_bar = LineWidget:new{ --background = 8, @@ -161,12 +162,12 @@ function DictQuickLookup:update() h = Screen:scaleByDPI(2), } } - + self.dict_bar = OverlapGroup:new{ dimen = {w = button_table:getSize().w, h = self.dict_title:getSize().h}, self.dict_title, } - + self.dict_frame = FrameContainer:new{ radius = 8, bordersize = 3, @@ -237,7 +238,7 @@ function DictQuickLookup:changeDictionary(index) self.dictionary = self.results[index].dict self.lookupword = self.results[index].word self.definition = self.results[index].definition - + local orig_dimen = self.dict_frame and self.dict_frame.dimen or Geom:new{} self:update() @@ -248,7 +249,7 @@ function DictQuickLookup:changeDictionary(index) end end -function DictQuickLookup:changeToDefaultDict() +function DictQuickLookup:changeToDefaultDict() if self.dictionary then -- dictionaries that have definition of the first word(accurate word) -- excluding Fuzzy queries. diff --git a/frontend/ui/widget/inputdialog.lua b/frontend/ui/widget/inputdialog.lua index a4cdb86c8..7e32a132d 100644 --- a/frontend/ui/widget/inputdialog.lua +++ b/frontend/ui/widget/inputdialog.lua @@ -59,6 +59,7 @@ function InputDialog:init() button_font_size = 20, buttons = self.buttons, zero_sep = true, + show_parent = self, } self.title_bar = LineWidget:new{ --background = 8, diff --git a/frontend/ui/widget/menu.lua b/frontend/ui/widget/menu.lua index a96d11f93..d88e300b0 100644 --- a/frontend/ui/widget/menu.lua +++ b/frontend/ui/widget/menu.lua @@ -355,11 +355,13 @@ function Menu:init() icon = "resources/icons/appbar.chevron.left.png", callback = function() self:onPrevPage() end, bordersize = 0, + show_parent = self, } self.page_info_right_chev = Button:new{ icon = "resources/icons/appbar.chevron.right.png", callback = function() self:onNextPage() end, bordersize = 0, + show_parent = self, } self.page_info_left_chev:hide() self.page_info_right_chev:hide() diff --git a/frontend/ui/widget/touchmenu.lua b/frontend/ui/widget/touchmenu.lua index 3d0c3bdd8..cb6de71cd 100644 --- a/frontend/ui/widget/touchmenu.lua +++ b/frontend/ui/widget/touchmenu.lua @@ -41,6 +41,10 @@ function TouchMenuItem:init() }, } + local item_enabled = self.item.enabled + if self.item.enabled_func then + item_enabled = self.item.enabled_func() + end self.item_frame = FrameContainer:new{ width = self.dimen.w, bordersize = 0, @@ -50,6 +54,8 @@ function TouchMenuItem:init() HorizontalSpan:new{ width = 10 }, TextWidget:new{ text = self.item.text or self.item.text_func(), + bgcolor = 0.0, + fgcolor = item_enabled ~= false and 1.0 or 0.5, face = self.face, }, }, @@ -58,6 +64,12 @@ function TouchMenuItem:init() end function TouchMenuItem:onTapSelect(arg, ges) + local enabled = self.item.enabled + if self.item.enabled_func then + enabled = self.item.enabled_func() + end + if enabled == false then return end + self.item_frame.invert = true UIManager:setDirty(self.show_parent, "partial") UIManager:scheduleIn(0.5, function() @@ -401,18 +413,31 @@ function TouchMenu:onSwipe(arg, ges_ev) end function TouchMenu:onMenuSelect(item) - if item.sub_item_table == nil then - if item.callback then + local enabled = item.enabled + if item.enabled_func then + enabled = item.enabled_func() + end + if enabled == false then return end + local sub_item_table = item.sub_item_table + if item.sub_item_table_func then + sub_item_table = item.sub_item_table_func() + end + if sub_item_table == nil then + local callback = item.callback + if item.callback_func then + callback = item.callback_func() + end + if callback then -- put stuff in scheduler so we can See -- the effect of inverted menu item UIManager:scheduleIn(0.1, function() self:closeMenu() - item.callback() + callback() end) end else table.insert(self.item_table_stack, self.item_table) - self.item_table = item.sub_item_table + self.item_table = sub_item_table self:updateItems() end return true From 8e4eda579e7c40845029b0283b079d865360aba0 Mon Sep 17 00:00:00 2001 From: chrox Date: Thu, 1 May 2014 18:38:43 +0800 Subject: [PATCH 4/5] add option to export notes to Yinxiang --- koreader-base | 2 +- plugins/evernote.koplugin/main.lua | 67 +++++++++++++++++++++++------- 2 files changed, 54 insertions(+), 15 deletions(-) diff --git a/koreader-base b/koreader-base index 362a1c51b..5521a8786 160000 --- a/koreader-base +++ b/koreader-base @@ -1 +1 @@ -Subproject commit 362a1c51b186339270733edae3206666c583bfab +Subproject commit 5521a8786a1e148625c4ca31d3626be5b92814cb diff --git a/plugins/evernote.koplugin/main.lua b/plugins/evernote.koplugin/main.lua index b30244125..0342561fe 100644 --- a/plugins/evernote.koplugin/main.lua +++ b/plugins/evernote.koplugin/main.lua @@ -9,13 +9,11 @@ local _ = require("gettext") local slt2 = require('slt2') local MyClipping = require("clip") -local EvernoteOAuth = require("EvernoteOAuth") -local EvernoteClient = require("EvernoteClient") local EvernoteExporter = InputContainer:new{ login_title = _("Login to Evernote"), notebook_name = _("Koreader Notes"), - --evernote_domain = "sandbox", + evernote_domain = nil, evernote_token, notebook_guid, @@ -25,6 +23,7 @@ function EvernoteExporter:init() self.ui.menu:registerToMainMenu(self) local settings = G_reader_settings:readSetting("evernote") or {} + self.evernote_domain = settings.domain self.evernote_username = settings.username or "" self.evernote_token = settings.token self.notebook_guid = settings.notebook @@ -37,23 +36,50 @@ function EvernoteExporter:init() end function EvernoteExporter:addToMainMenu(tab_item_table) + local domain = nil + if self.evernote_domain == "sandbox" then + domain = _("Sandbox") + elseif self.evernote_domain == "yinxiang" then + domain = _("Yinxiang") + else + domain = _("Evernote") + end table.insert(tab_item_table.plugins, { text = _("Evernote"), sub_item_table = { { text_func = function() - return self.evernote_token and _("Logout") or _("Login") + return self.evernote_token and (_("Logout") .. " " .. domain) + or _("Login") + end, + callback_func = function() + return self.evernote_token and function() self:logout() end + or nil + end, + sub_item_table_func = function() + return not self.evernote_token and { + { + text = _("Evernote"), + callback = function() + self.evernote_domain = nil + self:login() + end + }, + { + text = _("Yinxiang"), + callback = function() + self.evernote_domain = "yinxiang" + self:login() + end + } + } or nil end, - callback = function() - if self.evernote_token then - self:logout() - else - self:login() - end - end }, { text = _("Export all notes in this book"), + enabled_func = function() + return self.evernote_token ~= nil + end, callback = function() UIManager:scheduleIn(0.5, function() self:exportCurrentNotes(self.view) @@ -61,12 +87,15 @@ function EvernoteExporter:addToMainMenu(tab_item_table) UIManager:show(InfoMessage:new{ text = _("This may take several seconds..."), - timeout = 3, + timeout = 1, }) end }, { text = _("Export all notes in your library"), + enabled_func = function() + return self.evernote_token ~= nil + end, callback = function() UIManager:scheduleIn(0.5, function() self:exportAllNotes() @@ -74,7 +103,7 @@ function EvernoteExporter:addToMainMenu(tab_item_table) UIManager:show(InfoMessage:new{ text = _("This may take several minutes..."), - timeout = 3, + timeout = 1, }) end }, @@ -104,6 +133,11 @@ function EvernoteExporter:login() UIManager:scheduleIn(0.5, function() self:doLogin(username, password) end) + + UIManager:show(InfoMessage:new{ + text = _("Logging in please wait..."), + timeout = 1, + }) end, }, }, @@ -126,7 +160,8 @@ function EvernoteExporter:getCredential() end function EvernoteExporter:doLogin(username, password) - self:closeDialog() + local EvernoteOAuth = require("EvernoteOAuth") + local EvernoteClient = require("EvernoteClient") local oauth = EvernoteOAuth:new{ domain = self.evernote_domain, @@ -165,11 +200,13 @@ end function EvernoteExporter:logout() self.evernote_token = nil self.notebook_guid = nil + self.evernote_domain = nil self:saveSettings() end function EvernoteExporter:saveSettings() local settings = { + domain = self.evernote_domain, username = self.evernote_username, token = self.evernote_token, notebook = self.notebook_guid, @@ -183,6 +220,7 @@ function EvernoteExporter:getExportNotebook(client) end function EvernoteExporter:exportCurrentNotes(view) + local EvernoteClient = require("EvernoteClient") local client = EvernoteClient:new{ domain = self.evernote_domain, authToken = self.evernote_token, @@ -193,6 +231,7 @@ function EvernoteExporter:exportCurrentNotes(view) end function EvernoteExporter:exportAllNotes() + local EvernoteClient = require("EvernoteClient") local client = EvernoteClient:new{ domain = self.evernote_domain, authToken = self.evernote_token, From eeb81f1c3997db403318156ba1b1935bef8d7ec5 Mon Sep 17 00:00:00 2001 From: chrox Date: Thu, 1 May 2014 18:51:48 +0800 Subject: [PATCH 5/5] persistent reader footer mode --- frontend/apps/reader/modules/readerfooter.lua | 3 +++ 1 file changed, 3 insertions(+) diff --git a/frontend/apps/reader/modules/readerfooter.lua b/frontend/apps/reader/modules/readerfooter.lua index 232ea22f3..bb718e00d 100644 --- a/frontend/apps/reader/modules/readerfooter.lua +++ b/frontend/apps/reader/modules/readerfooter.lua @@ -81,6 +81,8 @@ function ReaderFooter:init() }, } end + self.mode = G_reader_settings:readSetting("reader_footer_mode") or self.mode + self:applyFooterMode() end function ReaderFooter:updateFooterPage() @@ -150,6 +152,7 @@ function ReaderFooter:onTapFooter(arg, ges) self:updateFooterPos() end UIManager:setDirty(self.view.dialog, "partial") + G_reader_settings:saveSetting("reader_footer_mode", self.mode) return true end