mirror of
https://github.com/koreader/koreader.git
synced 2025-08-10 00:52:38 +00:00
@@ -200,11 +200,19 @@ function FileChooser:choose(ypos, height)
|
||||
pagedirty = true
|
||||
elseif ev.code == KEY_S then -- invoke search input
|
||||
keywords = InputBox:input(height-100, 100, "Search:")
|
||||
if keywords then -- display search result according to keywords
|
||||
FileSearcher:init( self.path )
|
||||
file = FileSearcher:choose(ypos, height, keywords)
|
||||
if file then
|
||||
return file
|
||||
if keywords then
|
||||
-- call FileSearcher
|
||||
--[[
|
||||
This might looks a little bit dirty for using callback.
|
||||
But I cannot come up with a better solution for renewing
|
||||
the height arguemtn according to screen rotation mode.
|
||||
|
||||
The callback might also be useful for calling system
|
||||
settings menu in the future.
|
||||
--]]
|
||||
return nil, function()
|
||||
FileSearcher:init( self.path )
|
||||
FileSearcher:choose(ypos, height, keywords)
|
||||
end
|
||||
end
|
||||
pagedirty = true
|
||||
|
||||
@@ -262,8 +262,20 @@ function FileSearcher:choose(ypos, height, keywords)
|
||||
elseif ev.code == KEY_ENTER or ev.code == KEY_FW_PRESS then
|
||||
file_entry = self.result[perpage*(self.page-1)+self.current]
|
||||
file_full_path = file_entry.dir .. "/" .. file_entry.name
|
||||
|
||||
-- rotation mode might be changed while reading, so
|
||||
-- record height_percent here
|
||||
local height_percent = height/fb.bb:getHeight()
|
||||
openFile(file_full_path)
|
||||
|
||||
--reset height and item index if screen has been rotated
|
||||
local old_perpage = perpage
|
||||
height = math.floor(fb.bb:getHeight()*height_percent)
|
||||
perpage = math.floor(height / self.spacing) - 2
|
||||
self.current = (old_perpage * (self.page - 1) +
|
||||
self.current) % perpage
|
||||
self.page = math.floor(self.items / perpage) + 1
|
||||
|
||||
pagedirty = true
|
||||
elseif ev.code == KEY_BACK or ev.code == KEY_HOME then
|
||||
return nil
|
||||
|
||||
34
keys.lua
34
keys.lua
@@ -178,26 +178,32 @@ function set_emu_keycodes()
|
||||
KEY_VMINUS = 96 -- F12
|
||||
end
|
||||
|
||||
--@TODO rotation does not fit in key module, we should move it
|
||||
-- to some other module in the future. 08.03 2012
|
||||
rotation_mode = {"Up","Right","Down","Left"}
|
||||
|
||||
function getRotationMode()
|
||||
--[[
|
||||
return code for four kinds of rotation mode:
|
||||
|
||||
0 for no rotation,
|
||||
0 for no rotation,
|
||||
1 for landscape with bottom on the right side of screen, etc.
|
||||
|
||||
2
|
||||
+-----------+
|
||||
| +-------+ |
|
||||
| | | |
|
||||
| | | |
|
||||
| | | |
|
||||
3 | | | | 1
|
||||
| | | |
|
||||
| | | |
|
||||
| +-------+ |
|
||||
| |
|
||||
+-----------+
|
||||
0
|
||||
2
|
||||
+--------------+
|
||||
| +----------+ |
|
||||
| | | |
|
||||
| | Freedom! | |
|
||||
| | | |
|
||||
| | | |
|
||||
3 | | | | 1
|
||||
| | | |
|
||||
| | | |
|
||||
| +----------+ |
|
||||
| |
|
||||
| |
|
||||
+--------------+
|
||||
0
|
||||
--]]
|
||||
if KEY_FW_DOWN == 116 then -- in EMU mode always return 0
|
||||
return 0
|
||||
|
||||
12
reader.lua
12
reader.lua
@@ -131,11 +131,15 @@ if ARGV[optind] and lfs.attributes(ARGV[optind], "mode") == "directory" then
|
||||
local running = true
|
||||
FileChooser:setPath(ARGV[optind])
|
||||
while running do
|
||||
local file = FileChooser:choose(0,height)
|
||||
if file ~= nil then
|
||||
running = openFile(file)
|
||||
local file, callback = FileChooser:choose(0,height)
|
||||
if callback then
|
||||
callback()
|
||||
else
|
||||
running = false
|
||||
if file ~= nil then
|
||||
running = openFile(file)
|
||||
else
|
||||
running = false
|
||||
end
|
||||
end
|
||||
end
|
||||
elseif ARGV[optind] and lfs.attributes(ARGV[optind], "mode") == "file" then
|
||||
|
||||
@@ -526,6 +526,28 @@ function UniReader:setrotate(rotate)
|
||||
self:goto(self.pageno)
|
||||
end
|
||||
|
||||
-- @ orien: 1 for clockwise rotate, -1 for anti-clockwise
|
||||
function UniReader:screenRotate(orien)
|
||||
if orien == "clockwise" then
|
||||
orien = 1
|
||||
elseif orien == "anticlockwise" then
|
||||
orien = -1
|
||||
else
|
||||
return
|
||||
end
|
||||
|
||||
fb:close()
|
||||
local mode = rotation_mode[(getRotationMode()+1*orien)%4 + 1]
|
||||
os.execute("lipc-send-event -r 3 com.lab126.hal orientation"..mode)
|
||||
fb = einkfb.open("/dev/fb0")
|
||||
width, height = fb:getSize()
|
||||
|
||||
self:clearcache()
|
||||
--@TODO write a sleep in util module to replace it 08.03 2012
|
||||
os.execute("sleep 2")
|
||||
self:goto(self.pageno)
|
||||
end
|
||||
|
||||
function UniReader:cleanUpTOCTitle(title)
|
||||
return title:gsub("\13", "")
|
||||
end
|
||||
@@ -688,9 +710,17 @@ function UniReader:inputloop()
|
||||
self:showJumpStack()
|
||||
end
|
||||
elseif ev.code == KEY_J then
|
||||
self:setrotate( self.globalrotate + 10 )
|
||||
if Keys.shiftmode then
|
||||
self:screenRotate("anticlockwise")
|
||||
else
|
||||
self:setrotate( self.globalrotate + 10 )
|
||||
end
|
||||
elseif ev.code == KEY_K then
|
||||
self:setrotate( self.globalrotate - 10 )
|
||||
if Keys.shiftmode then
|
||||
self:screenRotate("clockwise")
|
||||
else
|
||||
self:setrotate( self.globalrotate - 10 )
|
||||
end
|
||||
elseif ev.code == KEY_HOME then
|
||||
if Keys.shiftmode or Keys.altmode then
|
||||
-- signal quit
|
||||
|
||||
Reference in New Issue
Block a user