2
0
mirror of https://github.com/koreader/koreader synced 2024-10-31 21:20:20 +00:00

Switch unireader.lua to new InfoMessage:inform()

This commit is contained in:
NuPogodi 2012-10-05 11:10:26 +01:00 committed by Tigran Aivazian
parent 55f4c278b7
commit 81cb3a1f25

View File

@ -3,6 +3,7 @@ require "settings"
require "selectmenu" require "selectmenu"
require "commands" require "commands"
require "helppage" require "helppage"
require "dialog"
UniReader = { UniReader = {
-- "constants": -- "constants":
@ -130,7 +131,7 @@ end
function UniReader:init() function UniReader:init()
-- initialize commands -- initialize commands
InfoMessage:show("Registering fonts...", 1) InfoMessage:inform("Registering fonts...", nil, 1, MSG_AUX)
self:addAllCommands() self:addAllCommands()
end end
@ -387,7 +388,7 @@ end
function UniReader:startHighLightMode() function UniReader:startHighLightMode()
local t = self:getText(self.pageno) local t = self:getText(self.pageno)
if not t or #t == 0 then if not t or #t == 0 then
showInfoMsgWithDelay("No text available", 1000, 1); InfoMessage:inform("No text available ", 1000, 1, MSG_WARN);
return nil return nil
end end
@ -398,7 +399,7 @@ function UniReader:startHighLightMode()
end end
end end
showInfoMsgWithDelay("No visible text", 1000, 1); InfoMessage:inform("No visible text ", 1000, 1, MSG_WARN);
Debug("_findFirstWordInView none found in", t) Debug("_findFirstWordInView none found in", t)
return nil return nil
@ -1607,7 +1608,7 @@ end
function UniReader:modifyGamma(factor) function UniReader:modifyGamma(factor)
Debug("modifyGamma, gamma=", self.globalgamma, " factor=", factor) Debug("modifyGamma, gamma=", self.globalgamma, " factor=", factor)
self.globalgamma = self.globalgamma * factor; self.globalgamma = self.globalgamma * factor;
InfoMessage:show("New gamma = "..self.globalgamma, 1) -- we don't want delay here InfoMessage:inform("Changing gamma to "..self.globalgamma..". ", nil, 1, MSG_AUX)
self:redrawCurrentPage() self:redrawCurrentPage()
end end
@ -1825,7 +1826,7 @@ function UniReader:showToc()
end end
if #self.toc == 0 then if #self.toc == 0 then
showInfoMsgWithDelay("No Table of Contents", 1500, 1) InfoMessage:inform("No Table of Contents ", 1500, 1, MSG_WARN)
return self:redrawCurrentPage() return self:redrawCurrentPage()
end end
@ -1844,7 +1845,7 @@ function UniReader:showToc()
local toc_entry = self.toc[self.toc_curidx_to_x[ret_code]] local toc_entry = self.toc[self.toc_curidx_to_x[ret_code]]
local pagenum = toc_entry.page local pagenum = toc_entry.page
if pagenum < 1 or pagenum > self.doc:getPages() then if pagenum < 1 or pagenum > self.doc:getPages() then
showInfoMsgWithDelay("External links unsupported", 1500, 1) InfoMessage:inform("External links unsupported ", 1500, 1, MSG_WARN)
self.toc_curitem = ret_code self.toc_curitem = ret_code
else else
return self:gotoTocEntry(toc_entry) return self:gotoTocEntry(toc_entry)
@ -1883,7 +1884,7 @@ function UniReader:showJumpHist()
end end
if #menu_items == 0 then if #menu_items == 0 then
showInfoMsgWithDelay("No jump history found.", 2000, 1) InfoMessage:inform("No jump history found ", 2000, 1, MSG_WARN)
else else
-- if cur points to head, draw entry for current page -- if cur points to head, draw entry for current page
if self.jump_history.cur > #self.jump_history then if self.jump_history.cur > #self.jump_history then
@ -1920,7 +1921,7 @@ function UniReader:showBookMarks()
"Page "..v.page.." "..v.notes.." @ "..v.datetime) "Page "..v.page.." "..v.notes.." @ "..v.datetime)
end end
if #menu_items == 0 then if #menu_items == 0 then
return showInfoMsgWithDelay("No bookmarks found", 1500, 1) return InfoMessage:inform("No bookmarks found ", 1500, 1, MSG_WARN)
end end
while true do while true do
bm_menu = SelectMenu:new{ bm_menu = SelectMenu:new{
@ -1983,7 +1984,7 @@ function UniReader:showHighLight()
end end
if #menu_items == 0 then if #menu_items == 0 then
return showInfoMsgWithDelay("No HighLights found", 1000, 1) return InfoMessage:inform("No HighLights found ", 1000, 1, MSG_WARN)
end end
while true do while true do
@ -2090,14 +2091,14 @@ function UniReader:searchHighLight(search)
self:goto(self.pageno) -- show highlights, remove input self:goto(self.pageno) -- show highlights, remove input
if found > 0 then if found > 0 then
showInfoMsgWithDelay( found.." hits '"..search.."' page "..self.pageno, 2000, 1) InfoMessage:inform( found.." hits '"..search.."' page "..self.pageno, 2000, 1, MSG_WARN)
self.last_search = { self.last_search = {
pageno = self.pageno, pageno = self.pageno,
search = search, search = search,
hits = found, hits = found,
} }
else else
showInfoMsgWithDelay( "'"..search.."' not found in document", 2000, 1) InfoMessage:inform( "'"..search.."' not found in document ", 2000, 1, MSG_WARN)
end end
self.highlight = old_highlight -- will not remove search highlights until page refresh self.highlight = old_highlight -- will not remove search highlights until page refresh
@ -2269,15 +2270,15 @@ function UniReader:addAllCommands()
if keydef.keycode == KEY_PGFWD or keydef.keycode == KEY_LPGFWD then if keydef.keycode == KEY_PGFWD or keydef.keycode == KEY_LPGFWD then
unireader.step_manual_zoom = unireader.step_manual_zoom * 2 unireader.step_manual_zoom = unireader.step_manual_zoom * 2
self.settings:saveSetting("step_manual_zoom", self.step_manual_zoom) self.settings:saveSetting("step_manual_zoom", self.step_manual_zoom)
--showInfoMsgWithDelay("New zoom step is "..unireader.step_manual_zoom.."%. ", 2000, 1) InfoMessage:inform("New zoom step is "..unireader.step_manual_zoom.."%. ", 2000, 1, MSG_WARN)
else else
local minstep = 1 local minstep = 1
if unireader.step_manual_zoom > 2*minstep then if unireader.step_manual_zoom > 2*minstep then
unireader.step_manual_zoom = unireader.step_manual_zoom / 2 unireader.step_manual_zoom = unireader.step_manual_zoom / 2
self.settings:saveSetting("step_manual_zoom", self.step_manual_zoom) self.settings:saveSetting("step_manual_zoom", self.step_manual_zoom)
--showInfoMsgWithDelay("New zoom step is "..unireader.step_manual_zoom.."%. ", 2000, 1) InfoMessage:inform("New zoom step is "..unireader.step_manual_zoom.."%. ", 2000, 1, MSG_WARN)
else else
showInfoMsgWithDelay("Minimum zoom step is "..minstep.."%. ", 2000, 1) InfoMessage:inform("Minimum zoom step is "..minstep.."%. ", 2000, 1, MSG_WARN)
end end
end end
end) end)
@ -2297,7 +2298,7 @@ function UniReader:addAllCommands()
unireader.jump_history.cur = prev_jump_no unireader.jump_history.cur = prev_jump_no
unireader:goto(unireader.jump_history[prev_jump_no].page, true) unireader:goto(unireader.jump_history[prev_jump_no].page, true)
else else
showInfoMsgWithDelay("Already first jump!", 2000, 1) InfoMessage:inform("Already first jump ", 2000, 1, MSG_WARN)
end end
end) end)
self.commands:add(KEY_BACK,MOD_SHIFT,"Back", self.commands:add(KEY_BACK,MOD_SHIFT,"Back",
@ -2312,10 +2313,9 @@ function UniReader:addAllCommands()
unireader.jump_history.cur = unireader.jump_history.cur + 1 unireader.jump_history.cur = unireader.jump_history.cur + 1
end end
else else
showInfoMsgWithDelay("Already last jump!", 2000, 1) InfoMessage:inform("Already last jump ", 2000, 1, MSG_WARN)
end end
end) end)
-- NuPogodi, 03.09.12 : moved the exit commands from here to the end of hotkey list
self.commands:addGroup("vol-/+",{Keydef:new(KEY_VPLUS,nil),Keydef:new(KEY_VMINUS,nil)}, self.commands:addGroup("vol-/+",{Keydef:new(KEY_VPLUS,nil),Keydef:new(KEY_VMINUS,nil)},
"decrease/increase gamma 10%", "decrease/increase gamma 10%",
function(unireader,keydef) function(unireader,keydef)
@ -2325,7 +2325,7 @@ function UniReader:addAllCommands()
local numeric_keydefs = {} local numeric_keydefs = {}
for i=1,10 do numeric_keydefs[i]=Keydef:new(KEY_1+i-1,nil,tostring(i%10)) end for i=1,10 do numeric_keydefs[i]=Keydef:new(KEY_1+i-1,nil,tostring(i%10)) end
self.commands:addGroup("[1, 2 .. 9, 0]",numeric_keydefs, self.commands:addGroup("[1, 2 .. 9, 0]",numeric_keydefs,
"jump to 10%, 20% .. 90%, 100% of document", "jump to 0%, 10% .. 90%, 100% of document",
function(unireader,keydef) function(unireader,keydef)
Debug('jump to page:', math.max(math.floor(unireader.doc:getPages()*(keydef.keycode-KEY_1)/9),1), '/', unireader.doc:getPages()) Debug('jump to page:', math.max(math.floor(unireader.doc:getPages()*(keydef.keycode-KEY_1)/9),1), '/', unireader.doc:getPages())
unireader:goto(math.max(math.floor(unireader.doc:getPages()*(keydef.keycode-KEY_1)/9),1)) unireader:goto(math.max(math.floor(unireader.doc:getPages()*(keydef.keycode-KEY_1)/9),1))
@ -2436,9 +2436,9 @@ function UniReader:addAllCommands()
function(unireader) function(unireader)
ok = unireader:addBookmark(self.pageno) ok = unireader:addBookmark(self.pageno)
if not ok then if not ok then
showInfoMsgWithDelay("Page already marked!", 1500, 1) InfoMessage:inform("Page already marked ", 1500, 1, MSG_WARN)
else else
showInfoMsgWithDelay("Page marked", 1500, 1) InfoMessage:inform("Page marked ", 1500, 1, MSG_WARN)
end end
end) end)
self.commands:add(KEY_B,MOD_SHIFT,"B", self.commands:add(KEY_B,MOD_SHIFT,"B",
@ -2449,11 +2449,15 @@ function UniReader:addAllCommands()
self.commands:add(KEY_J,MOD_SHIFT,"J", self.commands:add(KEY_J,MOD_SHIFT,"J",
"rotate 10° clockwise", "rotate 10° clockwise",
function(unireader) function(unireader)
-- NuPogodi, 29.09.12: added MSG_AUX -- not sure
InfoMessage:inform("Rotating 10° clockwise...", nil, 1, MSG_AUX)
unireader:setRotate( unireader.globalrotate + 10 ) unireader:setRotate( unireader.globalrotate + 10 )
end) end)
self.commands:add(KEY_J,nil,"J", self.commands:add(KEY_J,nil,"J",
"rotate screen 90° clockwise", "rotate screen 90° clockwise",
function(unireader) function(unireader)
-- NuPogodi, 29.09.12: added MSG_AUX -- not sure
InfoMessage:inform("Rotating 90° clockwise...", nil, 1, MSG_AUX)
unireader:screenRotate("clockwise") unireader:screenRotate("clockwise")
if self.globalzoom_mode == self.ZOOM_FIT_TO_CONTENT_WIDTH_PAN then if self.globalzoom_mode == self.ZOOM_FIT_TO_CONTENT_WIDTH_PAN then
self:setglobalzoom_mode(self.ZOOM_FIT_TO_CONTENT_WIDTH) self:setglobalzoom_mode(self.ZOOM_FIT_TO_CONTENT_WIDTH)
@ -2464,11 +2468,15 @@ function UniReader:addAllCommands()
self.commands:add(KEY_K,MOD_SHIFT,"K", self.commands:add(KEY_K,MOD_SHIFT,"K",
"rotate 10° counterclockwise", "rotate 10° counterclockwise",
function(unireader) function(unireader)
-- NuPogodi, 29.09.12: added MSG_AUX -- not sure
InfoMessage:inform("Rotating 10° counterclockwise", nil, 1, MSG_AUX)
unireader:setRotate( unireader.globalrotate - 10 ) unireader:setRotate( unireader.globalrotate - 10 )
end) end)
self.commands:add(KEY_K,nil,"K", self.commands:add(KEY_K,nil,"K",
"rotate screen 90° counterclockwise", "rotate screen 90° counterclockwise",
function(unireader) function(unireader)
-- NuPogodi, 29.09.12: added MSG_AUX -- not sure
InfoMessage:inform("Rotating 90° counterclockwise", nil, 1, MSG_AUX)
unireader:screenRotate("anticlockwise") unireader:screenRotate("anticlockwise")
if self.globalzoom_mode == self.ZOOM_FIT_TO_CONTENT_WIDTH_PAN then if self.globalzoom_mode == self.ZOOM_FIT_TO_CONTENT_WIDTH_PAN then
self:setglobalzoom_mode(self.ZOOM_FIT_TO_CONTENT_WIDTH) self:setglobalzoom_mode(self.ZOOM_FIT_TO_CONTENT_WIDTH)
@ -2497,15 +2505,7 @@ function UniReader:addAllCommands()
-- now, perform full screen refresh -- now, perform full screen refresh
self.rcount = self.rcountmax self.rcount = self.rcountmax
self:redrawCurrentPage() self:redrawCurrentPage()
--[[ eink will not refresh if nothing is changed on the screen
-- so we fake a change here.
fb.bb:invertRect(0, 0, 1, 1)
fb:refresh(1)
fb.bb:invertRect(0, 0, 1, 1)
fb:refresh(0)
unireader.rcount = 0 ]]
end) end)
self.commands:add(KEY_Z,nil,"Z", self.commands:add(KEY_Z,nil,"Z",
"set crop mode", "set crop mode",
function(unireader) function(unireader)
@ -2521,13 +2521,13 @@ function UniReader:addAllCommands()
unireader.bbox.enabled = true unireader.bbox.enabled = true
Debug("bbox", unireader.pageno, unireader.bbox) Debug("bbox", unireader.pageno, unireader.bbox)
unireader.globalzoom_mode = unireader.ZOOM_FIT_TO_CONTENT -- use bbox unireader.globalzoom_mode = unireader.ZOOM_FIT_TO_CONTENT -- use bbox
showInfoMsgWithDelay("Manual crop setting saved.", 2000, 1) InfoMessage:inform("Manual crop setting saved. ", 2000, 1, MSG_WARN)
end) end)
self.commands:add(KEY_Z,MOD_SHIFT,"Z", self.commands:add(KEY_Z,MOD_SHIFT,"Z",
"reset crop", "reset crop",
function(unireader) function(unireader)
unireader.bbox[unireader.pageno] = nil; unireader.bbox[unireader.pageno] = nil;
showInfoMsgWithDelay("Manual crop setting removed.", 2000, 1) InfoMessage:inform("Manual crop setting removed. ", 2000, 1, MSG_WARN)
Debug("bbox remove", unireader.pageno, unireader.bbox); Debug("bbox remove", unireader.pageno, unireader.bbox);
end) end)
self.commands:add(KEY_Z,MOD_ALT,"Z", self.commands:add(KEY_Z,MOD_ALT,"Z",
@ -2535,9 +2535,9 @@ function UniReader:addAllCommands()
function(unireader) function(unireader)
unireader.bbox.enabled = not unireader.bbox.enabled; unireader.bbox.enabled = not unireader.bbox.enabled;
if unireader.bbox.enabled then if unireader.bbox.enabled then
showInfoMsgWithDelay("Manual crop enabled.", 2000, 1) InfoMessage:inform("Manual crop enabled. ", 2000, 1, MSG_WARN)
else else
showInfoMsgWithDelay("Manual crop disabled.", 2000, 1) InfoMessage:inform("Manual crop disabled. ", 2000, 1, MSG_WARN)
end end
Debug("bbox override", unireader.bbox.enabled); Debug("bbox override", unireader.bbox.enabled);
end) end)
@ -2567,7 +2567,8 @@ function UniReader:addAllCommands()
fb.bb:invertRect( 0,y_s, G_width,1 ) fb.bb:invertRect( 0,y_s, G_width,1 )
fb.bb:invertRect( x_s,0, 1,G_height ) fb.bb:invertRect( x_s,0, 1,G_height )
InfoMessage:show(running_corner.." bbox"); InfoMessage:inform(running_corner.." bbox ", nil, 1, MSG_WARN,
running_corner.." bounding box")
fb:refresh(1) fb:refresh(1)
local last_direction = { x = 0, y = 0 } local last_direction = { x = 0, y = 0 }
@ -2602,7 +2603,8 @@ function UniReader:addAllCommands()
Debug("change top-left", bbox, "to", new_bbox) Debug("change top-left", bbox, "to", new_bbox)
running_corner = "bottom-right" running_corner = "bottom-right"
Screen:restoreFromSavedBB() Screen:restoreFromSavedBB()
InfoMessage:show(running_corner.." bbox") InfoMessage:inform(running_corner.." bbox ", nil, 1, MSG_WARN,
running_corner.." bounding box")
fb:refresh(1) fb:refresh(1)
x_s = x+w x_s = x+w
y_s = y+h y_s = y+h
@ -2717,7 +2719,7 @@ function UniReader:addAllCommands()
x,y,w,h = unireader:getRectInScreen( new_bbox["x0"], new_bbox["y0"], new_bbox["x1"], new_bbox["y1"] ) x,y,w,h = unireader:getRectInScreen( new_bbox["x0"], new_bbox["y0"], new_bbox["x1"], new_bbox["y1"] )
fb.bb:invertRect( x,y, w,h ) fb.bb:invertRect( x,y, w,h )
--fb.bb:invertRect( x+1,y+1, w-2,h-2 ) -- just border? --fb.bb:invertRect( x+1,y+1, w-2,h-2 ) -- just border?
showInfoMsgWithDelay("new page bbox", 2000, 1); InfoMessage:inform("New page bbox ", 2000, 1, MSG_WARN, "New page bounding box")
self:redrawCurrentPage() self:redrawCurrentPage()
self.rcount = self.rcountmax -- force next full refresh self.rcount = self.rcountmax -- force next full refresh
@ -2839,7 +2841,7 @@ function UniReader:addAllCommands()
end end
end end
end) end)
-- NuPogodi, 03.09.2012: functions to change panning steps -- functions to change panning steps
self.commands:addGroup("Shift + left/right", {Keydef:new(KEY_FW_LEFT,MOD_SHIFT), Keydef:new(KEY_FW_RIGHT,MOD_SHIFT)}, self.commands:addGroup("Shift + left/right", {Keydef:new(KEY_FW_LEFT,MOD_SHIFT), Keydef:new(KEY_FW_RIGHT,MOD_SHIFT)},
"increase/decrease X-panning step", "increase/decrease X-panning step",
function(unireader,keydef) function(unireader,keydef)
@ -2849,17 +2851,17 @@ function UniReader:addAllCommands()
unireader.shift_x = unireader.shift_x * 2 unireader.shift_x = unireader.shift_x * 2
if unireader.shift_x >= G_width then if unireader.shift_x >= G_width then
unireader.shift_x = G_width unireader.shift_x = G_width
showInfoMsgWithDelay("Maximum X-panning step is "..G_width..". ", 2000, 1) InfoMessage:inform("Maximum X-panning step is "..G_width..". ", 2000, 1, MSG_WARN)
end end
self.settings:saveSetting("shift_x", self.shift_x) self.settings:saveSetting("shift_x", self.shift_x)
--showInfoMsgWithDelay("New X-panning step is "..unireader.shift_x..". ", 2000, 1) InfoMessage:inform("New X-panning step is "..unireader.shift_x..". ", 2000, 1, MSG_WARN)
else else
if unireader.shift_x >= 2*minstep then if unireader.shift_x >= 2*minstep then
unireader.shift_x = math.ceil(unireader.shift_x / 2) unireader.shift_x = math.ceil(unireader.shift_x / 2)
self.settings:saveSetting("shift_x", self.shift_x) self.settings:saveSetting("shift_x", self.shift_x)
--showInfoMsgWithDelay("New X-panning step is "..unireader.shift_x..". ", 2000, 1) InfoMessage:inform("New X-panning step is "..unireader.shift_x..". ", 2000, 1, MSG_WARN)
else else
showInfoMsgWithDelay("Minimum X-panning step is "..minstep..". ", 2000, 1) InfoMessage:inform("Minimum X-panning step is "..minstep..". ", 2000, 1, MSG_WARN)
end end
end end
end) end)
@ -2872,17 +2874,17 @@ function UniReader:addAllCommands()
unireader.shift_y = unireader.shift_y * 2 unireader.shift_y = unireader.shift_y * 2
if unireader.shift_y >= G_height then if unireader.shift_y >= G_height then
unireader.shift_y = G_height unireader.shift_y = G_height
showInfoMsgWithDelay("Maximum Y-panning step is "..G_height..". ", 2000, 1) InfoMessage:inform("Maximum Y-panning step is "..G_height..". ", 2000, 1, MSG_WARN)
end end
self.settings:saveSetting("shift_y", self.shift_y) self.settings:saveSetting("shift_y", self.shift_y)
--showInfoMsgWithDelay("New Y-panning step is "..unireader.shift_y..". ", 2000, 1) InfoMessage:inform("New Y-panning step is "..unireader.shift_y..". ", 2000, 1, MSG_WARN)
else else
if unireader.shift_y >= 2*minstep then if unireader.shift_y >= 2*minstep then
unireader.shift_y = math.ceil(unireader.shift_y / 2) unireader.shift_y = math.ceil(unireader.shift_y / 2)
self.settings:saveSetting("shift_y", self.shift_y) self.settings:saveSetting("shift_y", self.shift_y)
--showInfoMsgWithDelay("New Y-panning step is "..unireader.shift_y..". ", 2000, 1) InfoMessage:inform("New Y-panning step is "..unireader.shift_y..". ", 2000, 1, MSG_WARN)
else else
showInfoMsgWithDelay("Minimum Y-panning step is "..minstep..". ", 2000, 1) InfoMessage:inform("Minimum Y-panning step is "..minstep..". ", 2000, 1, MSG_WARN)
end end
end end
end) end)
@ -2923,7 +2925,7 @@ function UniReader:addAllCommands()
function(unireader) function(unireader)
local links = unireader:getPageLinks( unireader.pageno ) local links = unireader:getPageLinks( unireader.pageno )
if links == nil or next(links) == nil then if links == nil or next(links) == nil then
showInfoMsgWithDelay("No links on this page", 2000, 1) InfoMessage:inform("No links on this page ", 2000, 1, MSG_WARN)
else else
local font_size = math.ceil( (links[1].y1 - links[1].y0 - 2) * unireader.globalzoom ) local font_size = math.ceil( (links[1].y1 - links[1].y0 - 2) * unireader.globalzoom )
Debug("font_size",font_size) Debug("font_size",font_size)
@ -2942,7 +2944,7 @@ function UniReader:addAllCommands()
end end
if page_links == 0 then if page_links == 0 then
showInfoMsgWithDelay("No links on this page", 2000, 1) InfoMessage:inform("No links on this page ", 2000, 1, MSG_WARN)
return return
end end
@ -3029,6 +3031,28 @@ function UniReader:addAllCommands()
end end
end end
) )
-- NuPogodi, 02.10.12: added functions to switch kpdfviewer mode from readers
self.commands:add(KEY_M, MOD_ALT, "M",
"select reader mode",
function(unireader)
Screen:saveCurrentBB()
FileChooser:changeFileChooserMode()
Screen:restoreFromSavedBB()
end
)
self.commands:add(KEY_I, nil, "I",
"change the way to inform about events",
function(unireader)
if FileChooser.filemanager_expert_mode == FileChooser.ROOT_MODE then
Screen:saveCurrentBB()
InfoMessage:chooseNotificatonMethods()
Screen:restoreFromSavedBB()
else
InfoMessage:inform("Unstable... For experts only ", -1, 1, MSG_WARN,
"This function is still under development and available only for experts and beta testers.")
end
end
)
self.commands:add(KEY_BACK,MOD_ALT,"Back", self.commands:add(KEY_BACK,MOD_ALT,"Back",
"close document", "close document",
function(unireader) function(unireader)