From 3a76ec91fdb8c1b1a5b839f9330da181accca0af Mon Sep 17 00:00:00 2001 From: NuPogodi Date: Sat, 19 May 2012 12:59:38 +0200 Subject: [PATCH] integrate rest of @NuPogodi changes #166 - long lines (filenames in 'Document Info') are now splitted in more human-readable way (by spaces, dots, slashes or some other characters - see screenshot) - the selection of fonts in filemanager (key 'F' or 'Aa') looks now more user-friendly - fixed too long strings in most menues (TOC, Bookmarks, Fonts...) and in the popup with the reading progress (called by key 'Menu') - the position inside the cr-documents (epub, mobi...) now remain nearly the same after rescaling the document (i.e. changing the font face, size, boldface and interline distance) - when you open TOC-menu or Fonts Menu, it highlights the current item (i.e. current chapter and current fontface). - i've a bit changed the way to read the battery level values, it might now work even without Amazon Kindle framework. --- crereader.lua | 92 +++++----- extentions.lua | 24 +++ filechooser.lua | 216 +++++++++++++++++++---- filehistory.lua | 391 +++++++++++++++++++++++++++++++++++++++++ fileinfo.lua | 304 ++++++++++++++++++++++++++++++++ filesearcher.lua | 153 ++++++++++++---- helppage.lua | 31 +++- reader.lua | 10 +- resources/azw.png | Bin 0 -> 259 bytes resources/cbz.png | Bin 0 -> 288 bytes resources/chm.png | Bin 0 -> 321 bytes resources/djvu.png | Bin 0 -> 237 bytes resources/epub.png | Bin 0 -> 249 bytes resources/fb2.png | Bin 0 -> 191 bytes resources/folder.png | Bin 0 -> 326 bytes resources/html.png | Bin 0 -> 311 bytes resources/info-i.png | Bin 1107 -> 538 bytes resources/mobi.png | Bin 0 -> 268 bytes resources/other.png | Bin 0 -> 276 bytes resources/pdf.png | Bin 0 -> 269 bytes resources/rtf.png | Bin 0 -> 266 bytes resources/txt.png | Bin 0 -> 276 bytes resources/upfolder.png | Bin 0 -> 304 bytes resources/xps.png | Bin 0 -> 292 bytes resources/zip.png | Bin 0 -> 334 bytes selectmenu.lua | 90 ++++++---- settings.lua | 33 +++- 27 files changed, 1179 insertions(+), 165 deletions(-) create mode 100644 extentions.lua create mode 100644 filehistory.lua create mode 100644 fileinfo.lua create mode 100644 resources/azw.png create mode 100644 resources/cbz.png create mode 100644 resources/chm.png create mode 100644 resources/djvu.png create mode 100644 resources/epub.png create mode 100644 resources/fb2.png create mode 100644 resources/folder.png create mode 100644 resources/html.png create mode 100644 resources/mobi.png create mode 100644 resources/other.png create mode 100644 resources/pdf.png create mode 100644 resources/rtf.png create mode 100644 resources/txt.png create mode 100644 resources/upfolder.png create mode 100644 resources/xps.png create mode 100644 resources/zip.png diff --git a/crereader.lua b/crereader.lua index 6b8dbe4a4..4b6e45376 100644 --- a/crereader.lua +++ b/crereader.lua @@ -38,29 +38,24 @@ function CREReader:open(filename) local ok local file_type = string.lower(string.match(filename, ".+%.([^.]+)")) + -- try to find double extentions like fb2.zip or htm.zip + if file_type == "zip" then + -- remove zip-extention + local fn = string.lower(string.sub(filename,0,-4)) + -- if no double extention then default file_type + file_type = string.lower(string.match(fn, ".+%.([^.]+)") or "cr3") + end + -- these two format use the same css file if file_type == "html" then file_type = "htm" end - - -- detect file type for documents inside zip file - -- @TODO do the detection after the file is unzipped 30.04 2012 (houqp) - if file_type == "zip" then - -- store filename without zip-extention to fn - local fn = string.lower(string.sub(filename,0,-4)) - -- if no double extention then default file_type - file_type = string.lower(string.match(fn, ".+%.([^.]+)") or "fb2") - end - - local style_sheet = "./data/"..file_type..".css" - -- if native css-file doesn't exist, one needs to use default cr3.css - -- (TODO! at first, i have to upload cr3.css) - -- if not io.open("./data/"..file_type..".css") then - -- file_type = "cr3" - -- end - - ok, self.doc = pcall(cre.openDocument, filename, style_sheet, + if not io.open("./data/"..file_type..".css") then + file_type = "cr3" + end + local style_sheet = "./data/"..file_type..".css" + ok, self.doc = pcall(cre.openDocument, filename, style_sheet, G_width, G_height) if not ok then return false, self.doc -- will contain error message @@ -76,7 +71,7 @@ end ---------------------------------------------------- function CREReader:loadSpecialSettings() local font_face = self.settings:readSetting("font_face") - self.font_face = font_face or "Droid Sans Fallback" + self.font_face = font_face or "Droid Sans" self.doc:setFontFace(self.font_face) local gamma_index = self.settings:readSetting("gamma_index") @@ -96,6 +91,8 @@ function CREReader:loadSpecialSettings() i=i-1 end end + -- define the original document height + self.old_doc_height = self.doc:getFullHeight() end function CREReader:getLastPageOrPos() @@ -190,6 +187,8 @@ function CREReader:goto(pos, is_ignore_jump, pos_type) self.pos = pos self.pageno = self.doc:getCurrentPage() self.percent = self.doc:getCurrentPercent() + -- NuPogodi, 18.05.12: storing new document height + self.old_doc_height = self.doc:getFullHeight() end function CREReader:gotoPercent(percent) @@ -314,7 +313,9 @@ function CREReader:_drawReadingInfo() fb.bb:paintRect(0, ypos, G_width, 50, 0) ypos = ypos + 15 - local face = Font:getFace("rifont", 22) + -- NuPogodi 15.05.12: a bit smaller font 20 instead of 22 + local face = Font:getFace("rifont", 20) + local cur_section = self:getTocTitleOfCurrentPage() if cur_section ~= "" then cur_section = "Section: "..cur_section @@ -331,8 +332,7 @@ function CREReader:_drawReadingInfo() -- end of changes (NuPogodi) ypos = ypos + 15 - blitbuffer.progressBar(fb.bb, 10, ypos, G_width - 20, 15, - 5, 4, load_percent/100, 8) + blitbuffer.progressBar(fb.bb, 10, ypos, G_width - 20, 15, 5, 4, load_percent/100, 8) end @@ -384,13 +384,14 @@ function CREReader:adjustCreReaderCommands() delta = -1 change = "decrease" end - InfoMessage:show(change.." font size", 0) - -- NuPogodi, 17.05.12: storing old document height + self.font_zoom = self.font_zoom + delta + InfoMessage:show(change.." font size to "..self.font_zoom, 0) + -- NuPogodi, 15.05.12: storing old document height self.old_doc_height = self.doc:getFullHeight() + -- end of changes (NuPogodi) self.doc:zoomFont(delta) self:redrawCurrentPage() - -- NuPogodi, 17.05.12: storing new document height - self.old_doc_height = self.doc:getFullHeight() + -- NuPogodi, 18.05.12: storing new height of document & refreshing TOC self:fillToc() end ) @@ -401,23 +402,19 @@ function CREReader:adjustCreReaderCommands() function(self) if keydef.keycode == KEY_PGBCK or keydef.keycode == KEY_LPGBCK then self.line_space_percent = self.line_space_percent - 10 - if self.line_space_percent < 100 then - self.line_space_percent = 100 - end + -- NuPogodi, 15.05.12: reduce lowest space_percent to 80 + self.line_space_percent = math.max(self.line_space_percent, 80) else self.line_space_percent = self.line_space_percent + 10 - if self.line_space_percent > 200 then - self.line_space_percent = 200 - end + self.line_space_percent = math.min(self.line_space_percent, 200) end - InfoMessage:show("line spacing "..self.line_space_percent.."%", 0) + InfoMessage:show("line spacing "..self.line_space_percent.."\%", 0) debug("line spacing set to", self.line_space_percent) -- NuPogodi, 17.05.12: storing old document height self.old_doc_height = self.doc:getFullHeight() self.doc:setDefaultInterlineSpace(self.line_space_percent) self:redrawCurrentPage() - -- NuPogodi, 17.05.12: storing new document height - self.old_doc_height = self.doc:getFullHeight() + -- NuPogodi, 18.05.12: storing new height of document & refreshing TOC self:fillToc() end ) @@ -434,20 +431,21 @@ function CREReader:adjustCreReaderCommands() self:goto(math.floor(self.doc:getFullHeight()*(keydef.keycode-KEY_1)/9)) end ) - self.commands:add(KEY_F, nil, "F", + self.commands:add({KEY_F, KEY_AA}, nil, "F", "change document font", function(self) Screen:saveCurrentBB() local face_list = cre.getFontFaces() - + -- NuPogodi, 18.05.12: define the number of the current font in face_list + local item_no = 0 + while face_list[item_no] ~= self.font_face and item_no < #face_list do + item_no = item_no + 1 + end local fonts_menu = SelectMenu:new{ - -- NuPogodi, 16.05.12: DO NOT REMOVE the last space in the menu_title! - -- it will tell to function fonts_menu:choose (in selectmenu.lua) - --- that the fonts should be drawn not by own glyphs, - -- but by the standard cface... - menu_title = "Fonts Menu ", -- not just "Fonts Menu" - item_array = face_list, + menu_title = "Fonts Menu ", + item_array = face_list, + current_entry = item_no - 1, } local item_no = fonts_menu:choose(0, G_height) @@ -461,8 +459,7 @@ function CREReader:adjustCreReaderCommands() InfoMessage:show("Redrawing with "..face_list[item_no], 0) end self:redrawCurrentPage() - -- NuPogodi, 17.05.12: storing new document height - self.old_doc_height = self.doc:getFullHeight() + -- NuPogodi, 18.05.12: storing new height of document & refreshing TOC self:fillToc() end ) @@ -473,8 +470,7 @@ function CREReader:adjustCreReaderCommands() self.old_doc_height = self.doc:getFullHeight() self.doc:toggleFontBolder() self:redrawCurrentPage() - -- NuPogodi, 17.05.12: storing new document height - self.old_doc_height = self.doc:getFullHeight() + -- NuPogodi, 18.05.12: storing new height of document & refreshing TOC self:fillToc() end ) @@ -524,6 +520,8 @@ function CREReader:adjustCreReaderCommands() cre.setGammaIndex(self.gamma_index+delta) self.gamma_index = cre.getGammaIndex() self:redrawCurrentPage() + -- NuPogodi, 16.05.12: FIXED! gamma_index -> self.gamma_index + showInfoMsgWithDelay("Redraw with gamma = "..self.gamma_index, 2000, 1) end ) self.commands:add(KEY_FW_UP, nil, "joypad up", diff --git a/extentions.lua b/extentions.lua new file mode 100644 index 000000000..7994a5f6a --- /dev/null +++ b/extentions.lua @@ -0,0 +1,24 @@ +-- List of acceptable extentions + +ext = { + djvuRead = ";djvu;", + pdfRead = ";pdf;xps;cbz;", + creRead = ";epub;txt;rtf;htm;html;mobi;prc;azw;fb2;chm;pdb;doc;tcr;zip;" + -- seems to accept pdb-files for PalmDoc only +} + +function ext:getReader(ftype) + local s = ";" + if ftype == "" then + return nil + elseif string.find(self.djvuRead,s..ftype..s) then + return DJVUReader + elseif string.find(self.pdfRead,s..ftype..s) then + return PDFReader + elseif string.find(self.creRead,s..ftype..s) then + return CREReader + else + return nil + end +end + diff --git a/filechooser.lua b/filechooser.lua index acde51dfe..19e60a979 100644 --- a/filechooser.lua +++ b/filechooser.lua @@ -3,14 +3,22 @@ require "keys" require "graphics" require "font" require "filesearcher" +require "filehistory" +require "fileinfo" require "inputbox" require "selectmenu" +require "dialog" +require "extentions" FileChooser = { - -- Class vars: - + -- title height + title_H = 40, -- spacing between lines - spacing = 40, + spacing = 36, + -- foot height + foot_H = 28, + -- horisontal margin + margin_H = 10, -- state buffer dirs = nil, @@ -22,6 +30,66 @@ FileChooser = { oldcurrent = 0, exception_message = nil } +-- to duplicate visual info by speaking +function say(text) + os.execute("say ".."\""..text.."\"") +end +-- make long headers for fit in title width by removing first characters +function getProperTitleLength(txt,font_face,max_width) + local tw = TextWidget:new({ text = txt, face = font_face}) + -- 1st approximation for a point where to start title + local n = math.floor(string.len(txt) * (1 - max_width / tw:getSize().w)) - 2 + n = math.max(n, 1) + while tw:getSize().w >= max_width do + tw:free() + tw = TextWidget:new({ text = string.sub(txt,n,-1), face = font_face}) + n = n + 1 + end + return string.sub(txt,n-1,-1) +end + +function BatteryLevel() + local fn, battery = "./data/temporary", "?" + -- NuPogodi, 18.05.12: This command seems to work even without Amazon Kindle framework + os.execute("\(gasgauge-info ".."-s\) ".."> "..fn) + if io.open(fn,"r") then + for lines in io.lines(fn) do battery = " " .. lines end + else + battery = "" + end + return battery +end + +function DrawTitle(text,lmargin,y,height,color,font_face) + fb.bb:paintRect(lmargin, y+10, fb.bb:getWidth() - lmargin*2, height, color) + -- to have a horisontal gap between text & background rectangle + lmargin = lmargin + 10 + t = BatteryLevel() .. os.date(" %H:%M") + local tw = TextWidget:new({ text = t, face = font_face}) + twidth = tw:getSize().w + renderUtf8Text(fb.bb, fb.bb:getWidth()-twidth-lmargin, y + height, font_face, t, true) + tw:free() + + tw = TextWidget:new({ text = text, face = font_face}) + local max_width = fb.bb:getWidth() - 2 * lmargin - twidth + if tw:getSize().w < max_width then + renderUtf8Text(fb.bb, lmargin, y + height, font_face, text, true) + else + tw:free() + -- separately draw the title prefix = ... + local tw = TextWidget:new({ text = "...", face = font_face}) + renderUtf8Text(fb.bb, lmargin, y + height, font_face, "...", true) + -- then define proper text length and draw it + local txt = getProperTitleLength(text,font_face,max_width-tw:getSize().w) + renderUtf8Text(fb.bb, lmargin+tw:getSize().w, y + height, font_face, txt, true) + end +end + +function DrawFooter(text,font_face,h) + y = G_height - 7 + x = (G_width / 2) - 50 + renderUtf8Text(fb.bb, x, y, font_face, text, true) +end function getAbsolutePath(aPath) local abs_path @@ -49,23 +117,19 @@ function FileChooser:readDir() self.dirs = {} self.files = {} for f in lfs.dir(self.path) do - if lfs.attributes(self.path.."/"..f, "mode") == "directory" and f ~= "." and not (f==".." and self.path=="/") and not string.match(f, "^%.[^.]") then - --debug(self.path.." -> adding: '"..f.."'") - table.insert(self.dirs, f) - else + if lfs.attributes(self.path.."/"..f, "mode") == "directory" and f ~= "." and f~=".." + and not string.match(f, "^%.[^.]") then + table.insert(self.dirs, f) + elseif lfs.attributes(self.path.."/"..f, "mode") == "file" + and not string.match(f, "^%.[^.]") then local file_type = string.lower(string.match(f, ".+%.([^.]+)") or "") - if file_type == "djvu" - or file_type == "pdf" or file_type == "xps" or file_type == "cbz" - or file_type == "epub" or file_type == "txt" or file_type == "rtf" - or file_type == "htm" or file_type == "html" or file_type == "mobi" or file_type == "prc" - or file_type == "fb2" or file_type == "chm" or file_type == "doc" - or file_type == "zip" then + if ext:getReader(file_type) then table.insert(self.files, f) end end end - --@TODO make sure .. is sortted to the first item 16.02 2012 table.sort(self.dirs) + if self.path~="/" then table.insert(self.dirs,1,"..") end table.sort(self.files) end @@ -88,6 +152,28 @@ function FileChooser:setPath(newPath) end end +function DrawFileItem(name,x,y,image) + -- define icon file for + if name == ".." then image = "upfolder" end + local fn = "./resources/"..image..".png" + -- check whether the icon file exists or not + if not io.open(fn, "r") then fn = "./resources/other.png" end + local iw = ImageWidget:new({ file = fn }) + iw:paintTo(fb.bb, x, y - iw:getSize().h + 1) + -- then drawing filenames + local cface = Font:getFace("cfont", 22) + local xleft = x + iw:getSize().w + 9 -- 8-10 pixels = the gap between icon & filename + local width = fb.bb:getWidth() - xleft - x + -- now printing the name + if sizeUtf8Text(xleft, fb.bb:getWidth() - x, cface, name, true).x < width then + renderUtf8Text(fb.bb, xleft, y, cface, name, true) + else + local lgap = sizeUtf8Text(0, width, cface, " ...", true).x + local handle = renderUtf8TextWidth(fb.bb, xleft, y, cface, name, true, width - lgap - x) + renderUtf8Text(fb.bb, handle.x + lgap + x, y, cface, " ...", true) + end +end + function FileChooser:choose(ypos, height) local perpage = math.floor(height / self.spacing) - 2 local pagedirty = true @@ -123,40 +209,46 @@ function FileChooser:choose(ypos, height) end while true do - local cface = Font:getFace("cfont", 25) + local tface = Font:getFace("tfont", 25) local fface = Font:getFace("ffont", 16) + local cface = Font:getFace("cfont", 22) if pagedirty then + -- starttime was to optimize drawing process + --local starttime = os.clock() fb.bb:paintRect(0, ypos, fb.bb:getWidth(), height, 0) local c for c = 1, perpage do local i = (self.page - 1) * perpage + c if i <= #self.dirs then - -- resembles display in midnight commander: adds "/" prefix for directories - renderUtf8Text(fb.bb, 39, ypos + self.spacing*c, cface, "/", true) - renderUtf8Text(fb.bb, 50, ypos + self.spacing*c, cface, self.dirs[i], true) + DrawFileItem(self.dirs[i],self.margin_H,ypos+self.title_H+self.spacing*c,"folder") elseif i <= self.items then - renderUtf8Text(fb.bb, 50, ypos + self.spacing*c, cface, self.files[i-#self.dirs], true) + local file_type = string.lower(string.match(self.files[i-#self.dirs], ".+%.([^.]+)") or "") + DrawFileItem(self.files[i-#self.dirs],self.margin_H,ypos+self.title_H+self.spacing*c,file_type) end end + -- draw footer all_page = math.ceil(self.items/perpage) - renderUtf8Text(fb.bb, 5, ypos + self.spacing * perpage + 42, fface, - "Page "..self.page.." of "..all_page, true) - local msg = self.exception_message and self.exception_message:match("[^%:]+:%d+: (.*)") or "Path: "..self.path + DrawFooter("Page "..self.page.." of "..all_page,fface,self.foot_H) + -- draw menu title + local msg = self.exception_message and self.exception_message:match("[^%:]+:%d+: (.*)") or self.path self.exception_message = nil - renderUtf8Text(fb.bb, 5, ypos + self.spacing * (perpage+1) + 27, fface, msg, true) + -- draw header + DrawTitle(msg,self.margin_H,ypos,self.title_H,4,tface) + --say("The page was drawn in "..string.format("%.2f",os.clock()-starttime).." seconds.") markerdirty = true end if markerdirty then + local ymarker = ypos + 8 + self.title_H if not pagedirty then if self.oldcurrent > 0 then - fb.bb:paintRect(30, ypos + self.spacing*self.oldcurrent + 10, fb.bb:getWidth() - 60, 3, 0) - fb:refresh(1, 30, ypos + self.spacing*self.oldcurrent + 10, fb.bb:getWidth() - 60, 3) + fb.bb:paintRect(self.margin_H, ymarker+self.spacing*self.oldcurrent, fb.bb:getWidth()-2*self.margin_H, 3, 0) + fb:refresh(1, self.margin_H, ymarker+self.spacing*self.oldcurrent, fb.bb:getWidth() - 2*self.margin_H, 3) end end - fb.bb:paintRect(30, ypos + self.spacing*self.current + 10, fb.bb:getWidth() - 60, 3, 15) + fb.bb:paintRect(self.margin_H, ymarker+self.spacing*self.current, fb.bb:getWidth()-2*self.margin_H, 3, 15) if not pagedirty then - fb:refresh(1, 30, ypos + self.spacing*self.current + 10, fb.bb:getWidth() - 60, 3) + fb:refresh(1, self.margin_H, ymarker+self.spacing*self.current, fb.bb:getWidth()-2*self.margin_H, 3) end self.oldcurrent = self.current markerdirty = false @@ -174,10 +266,19 @@ function FileChooser:choose(ypos, height) prevItem() elseif ev.code == KEY_FW_DOWN then nextItem() - elseif ev.code == KEY_F then -- invoke fontchooser menu + elseif ev.code == KEY_F or ev.code == KEY_AA then -- invoke fontchooser menu + -- NuPogodi, 18.05.12: define the number of the current font in face_list + local item_no = 0 + local face_list = Font:getFontList() + while face_list[item_no] ~= Font.fontmap.cfont and item_no < #face_list do + item_no = item_no + 1 + end + local fonts_menu = SelectMenu:new{ menu_title = "Fonts Menu", - item_array = Font:getFontList(), + item_array = face_list, + -- NuPogodi, 18.05.12: define selected item + current_entry = item_no - 1, } local re, font = fonts_menu:choose(0, height) if re then @@ -198,12 +299,21 @@ function FileChooser:choose(ypos, height) settings menu in the future. --]] return nil, function() - InfoMessage:show("Searching...",0) + InfoMessage:show("Searching... ",0) FileSearcher:init( self.path ) FileSearcher:choose(keywords) end end pagedirty = true + elseif ev.code == KEY_L then -- last opened files + InfoMessage:show("Searching last docs... ",0) + if true then + return nil, function() + FileHistory:init() + FileHistory:choose("") -- show all files + end + end + pagedirty = true elseif ev.code == KEY_PGFWD or ev.code == KEY_LPGFWD then if self.page < (self.items / perpage) then if self.current + self.page*perpage > self.items then @@ -235,6 +345,52 @@ function FileChooser:choose(ypos, height) return self.path.."/"..self.files[perpage*(self.page-1)+self.current - #self.dirs] end pagedirty = true + elseif ev.code == KEY_P then -- make screenshot + os.execute("mkdir ".."/mnt/us/kindlepdfviewer/screenshots") + local d = os.date("%Y%m%d%H%M%S") + showInfoMsgWithDelay("making screenshot... ", 1000, 1) + os.execute("dd ".."if=/dev/fb0 ".."of=/mnt/us/kindlepdfviewer/screenshots/" .. d .. ".raw") + pagedirty = true + elseif ev.code == KEY_FW_RIGHT or ev.code == KEY_I then -- show file info + return nil, function() + local newdir = self.dirs[perpage*(self.page-1)+self.current] + if newdir == ".." then + showInfoMsgWithDelay("",1000,1) + elseif newdir then + showInfoMsgWithDelay("",1000,1) + else + FileInfo:show(self.path,self.files[perpage*(self.page-1)+self.current - #self.dirs]) + pagedirty = true + end + end + elseif ev.code == KEY_SPACE then -- manual refresh + pagedirty = true + elseif ev.code == KEY_DEL then + local dir_to_del = self.dirs[perpage*(self.page-1)+self.current] + if dir_to_del == ".." then + showInfoMsgWithDelay("",1000,1) + elseif dir_to_del then + showInfoMsgWithDelay("",1000,1) + else + local file_to_del=self.path.."/"..self.files[perpage*(self.page-1)+self.current - #self.dirs] + InfoMessage:show("Press \'Y\' to confirm deleting... ",0) + while true do + ev = input.saveWaitForEvent() + ev.code = adjustKeyEvents(ev) + if ev.type == EV_KEY and ev.value ~= EVENT_VALUE_KEY_RELEASE then + if ev.code == KEY_Y then + -- delete the file itself + os.execute("rm \""..file_to_del.."\"") + -- and its history file, if any + os.execute("rm \""..DocToHistory(file_to_del).."\"") + -- to avoid showing just deleted file + self:setPath(self.path) + end + pagedirty = true + break + end + end -- while + end elseif ev.code == KEY_BACK or ev.code == KEY_HOME then return nil end diff --git a/filehistory.lua b/filehistory.lua new file mode 100644 index 000000000..1ed59b3d7 --- /dev/null +++ b/filehistory.lua @@ -0,0 +1,391 @@ +require "rendertext" +require "keys" +require "graphics" +require "font" +require "inputbox" +require "dialog" +require "filesearcher" +require "settings" + +FileHistory = { + -- title height + title_H = 40, + -- spacing between lines + spacing = 36, + -- foot height + foot_H = 28, + -- horisontal margin + margin_H = 10, + + -- state buffer + history_files = {}, + files = {}, + result = {}, + items = 0, + page = 0, + current = 1, + oldcurrent = 1, +} + +function FileHistory:init(history_path) + if history_path then + self:setPath(history_path) + else + self:setPath("./history") + end + self:addAllCommands() +end + +function FileHistory:setPath(newPath) + self.path = newPath + self:readDir("-c ") + self.items = #self.files + if self.items == 0 then + return nil + end + self.page = 1 + self.current = 1 + return true +end + +function FileHistory:readDir(order_criteria) + self.history_files = {} + self.files = {} + local listfile = self.path.."/.history.txt" + os.execute("ls "..order_criteria.."-1 "..self.path.." > "..listfile) + for f in io.lines(listfile) do + -- insert history files + file_entry = {dir=self.path, name=f} + table.insert(self.history_files, file_entry) + -- and corresponding path & file items + file_entry = {dir=HistoryToPath(f), name=HistoryToName(f)} + table.insert(self.files, file_entry) + end +end + +function FileHistory:setSearchResult(keywords) + self.result = {} + if keywords == "" or keywords == " " then + -- show all history + self.result = self.files + else + -- select history files with keywords in the filename + for __,f in pairs(self.files) do + if string.find(string.lower(f.name), keywords) then + table.insert(self.result,f) + end + end + end + self.keywords = keywords + self.items = #self.result + self.page = 1 + self.current = 1 +end + +function FileHistory:prevItem() + if self.current == 1 then + if self.page > 1 then + self.current = self.perpage + self.page = self.page - 1 + self.pagedirty = true + end + else + self.current = self.current - 1 + self.markerdirty = true + end +end + +function FileHistory:nextItem() + if self.current == self.perpage then + if self.page < (self.items / self.perpage) then + self.current = 1 + self.page = self.page + 1 + self.pagedirty = true + end + else + if self.page ~= math.floor(self.items / self.perpage) + 1 + or self.current + (self.page-1)*self.perpage < self.items then + self.current = self.current + 1 + self.markerdirty = true + end + end +end + +function FileHistory:addAllCommands() + self.commands = Commands:new{} + -- search among last documents + self.commands:add(KEY_S, nil, "S", + "search among files", + function(self) + old_keywords = self.keywords + self.keywords = InputBox:input(G_height - 100, 100, + "Search:", old_keywords) + if self.keywords then + self:setSearchResult(self.keywords) + else + self.keywords = old_keywords + end + self.pagedirty = true + end + ) + -- last documents + self.commands:add(KEY_L, nil, "L", + "last documents", + function(self) + self:setSearchResult("") + self.pagedirty = true + end + ) + -- show help page + self.commands:add(KEY_H, nil, "H", + "show help page", + function(self) + HelpPage:show(0, G_height, self.commands) + self.pagedirty = true + end + ) + -- make screenshot + self.commands:add(KEY_P, MOD_SHIFT, "P", + "make screenshot", + function(self) + os.execute("mkdir ".."/mnt/us/kindlepdfviewer/screenshots") + local d = os.date("%Y%m%d%H%M%S") + showInfoMsgWithDelay("making screenshot... ", 1000, 1) + os.execute("dd ".."if=/dev/fb0 ".."of=/mnt/us/kindlepdfviewer/screenshots/" .. d .. ".raw") + end + ) + + -- file info + self.commands:add({KEY_FW_RIGHT, KEY_I}, nil, "joypad right", + "document details", + function(self) + file_entry = self.result[self.perpage*(self.page-1)+self.current] + FileInfo:show(file_entry.dir,file_entry.name) + self.pagedirty = true + end + ) + + self.commands:add(KEY_FW_UP, nil, "joypad up", + "goto previous item", + function(self) + self:prevItem() + end + ) + self.commands:add(KEY_FW_DOWN, nil, "joypad down", + "goto next item", + function(self) + self:nextItem() + end + ) + self.commands:add({KEY_PGFWD, KEY_LPGFWD}, nil, ">", + "next page", + function(self) + if self.page < (self.items / self.perpage) then + if self.current + self.page*self.perpage > self.items then + self.current = self.items - self.page*self.perpage + end + self.page = self.page + 1 + self.pagedirty = true + else + self.current = self.items - (self.page-1)*self.perpage + self.markerdirty = true + end + end + ) + self.commands:add({KEY_PGBCK, KEY_LPGBCK}, nil, "<", + "previous page", + function(self) + if self.page > 1 then + self.page = self.page - 1 + self.pagedirty = true + else + self.current = 1 + self.markerdirty = true + end + end + ) + self.commands:add({KEY_F, KEY_AA}, nil, "F", + "font menu", + function(self) + -- NuPogodi, 18.05.12: define the number of the current font in face_list + local item_no = 0 + local face_list = Font:getFontList() + while face_list[item_no] ~= Font.fontmap.cfont and item_no < #face_list do + item_no = item_no + 1 + end + + local fonts_menu = SelectMenu:new{ + menu_title = "Fonts Menu", + item_array = face_list, + -- NuPogodi, 18.05.12: define selected item + current_entry = item_no - 1, + } + local re, font = fonts_menu:choose(0, G_height) + if re then + Font.fontmap["cfont"] = font + Font:update() + end + self.pagedirty = true + end + ) + + self.commands:add({KEY_ENTER, KEY_FW_PRESS}, nil, "Enter", + "open selected item", + function(self) + file_entry = self.result[self.perpage*(self.page-1)+self.current] + file_full_path = file_entry.dir .. "/" .. file_entry.name + + openFile(file_full_path) + --reset height and item index if screen has been rotated + local item_no = self.perpage * (self.page - 1) + self.current + self.perpage = math.floor(G_height / self.spacing) - 2 + self.current = item_no % self.perpage + self.page = math.floor(item_no / self.perpage) + 1 + + self.pagedirty = true + end + ) + self.commands:add({KEY_BACK, KEY_HOME}, nil, "Back", + "back", + function(self) + return "break" + end + ) + self.commands:add({KEY_DEL}, nil, "Del", + "delete document", + function(self) + file_entry = self.result[self.perpage*(self.page-1)+self.current] + local file_to_del = file_entry.dir .. "/" .. file_entry.name + InfoMessage:show("Press \'Y\' to confirm deleting... ",0) + while true do + ev = input.saveWaitForEvent() + ev.code = adjustKeyEvents(ev) + if ev.type == EV_KEY and ev.value ~= EVENT_VALUE_KEY_RELEASE then + if ev.code == KEY_Y then + -- delete the file itself + os.execute("rm \""..file_to_del.."\"") + -- and its history file, if any + os.execute("rm \""..DocToHistory(file_to_del).."\"") + -- to avoid showing just deleted file + self:init() + self:setSearchResult(self.keywords) + end + self.pagedirty = true + break + end -- if ev.type == EV_KEY + end -- while + end + ) + self.commands:add({KEY_SPACE}, nil, "Space", + "refresh page manually", + function(self) + self.pagedirty = true + end + ) +--[[ self.commands:add({KEY_B}, nil, "B", + "file browser", + function(self) + --FileChooser:setPath(".") + FileChooser:choose(0, G_height) + self.pagedirty = true + end + )]] +end + +function FileHistory:choose(keywords) + self.perpage = math.floor(G_height / self.spacing) - 2 + self.pagedirty = true + self.markerdirty = false + + self:setSearchResult(keywords) + + while true do + local cface = Font:getFace("cfont", 22) + local tface = Font:getFace("tfont", 25) + local fface = Font:getFace("ffont", 16) + + if self.pagedirty then + self.markerdirty = true + fb.bb:paintRect(0, 0, G_width, G_height, 0) + + -- draw header + local header = "Last Documents" + if self.keywords ~= "" and self.keywords ~= " " then + --header = header .. " (filter: \'" .. string.upper(self.keywords) .. "\')" + header = "Search Results for \'"..string.upper(self.keywords).."\'" + end + DrawTitle(header,self.margin_H,0,self.title_H,4,tface) + + -- draw found results + local c + if self.items == 0 then -- nothing found + y = self.title_H + self.spacing * 2 + renderUtf8Text(fb.bb, self.margin_H, y, cface, + "Sorry, no files found.", true) + self.markerdirty = false + else -- found something, draw it + for c = 1, self.perpage do + local i = (self.page - 1) * self.perpage + c + if i <= self.items then + y = self.title_H + (self.spacing * c) + 4 + local ftype = string.lower(string.match(self.result[i].name, ".+%.([^.]+)") or "") + DrawFileItem(self.result[i].name,self.margin_H,y,ftype) + end + end + end + + -- draw footer + all_page = math.ceil(self.items/self.perpage) + DrawFooter("Page "..self.page.." of "..all_page,fface,self.foot_H) + + end + + if self.markerdirty then + if not self.pagedirty then + if self.oldcurrent > 0 then + y = self.title_H + (self.spacing * self.oldcurrent) + 12 + fb.bb:paintRect(self.margin_H, y, G_width - 2 * self.margin_H, 3, 0) + fb:refresh(1, self.margin_H, y, G_width - 2 * self.margin_H, 3) + end + end + -- draw new marker line + y = self.title_H + (self.spacing * self.current) + 12 + fb.bb:paintRect(self.margin_H, y, G_width - 2 * self.margin_H, 3, 15) + if not self.pagedirty then + fb:refresh(1, self.margin_H, y, G_width - 2 * self.margin_H, 3) + end + self.oldcurrent = self.current + self.markerdirty = false + end + + if self.pagedirty then + fb:refresh(0) + self.pagedirty = false + end + + local ev = input.saveWaitForEvent() + ev.code = adjustKeyEvents(ev) + if ev.type == EV_KEY and ev.value ~= EVENT_VALUE_KEY_RELEASE then + keydef = Keydef:new(ev.code, getKeyModifier()) + debug("key pressed: "..tostring(keydef)) + + command = self.commands:getByKeydef(keydef) + if command ~= nil then + debug("command to execute: "..tostring(command)) + ret_code = command.func(self, keydef) + else + debug("command not found: "..tostring(command)) + end + + if ret_code == "break" then + break + end + + if self.selected_item ~= nil then + debug("# selected "..self.selected_item) + return self.selected_item + end + end -- if + end -- while true + return nil +end diff --git a/fileinfo.lua b/fileinfo.lua new file mode 100644 index 000000000..f09e5e7b3 --- /dev/null +++ b/fileinfo.lua @@ -0,0 +1,304 @@ +require "rendertext" +require "keys" +require "graphics" +require "font" +require "inputbox" +require "dialog" +require "settings" +--require "extentions" + +FileInfo = { + -- title height + title_H = 40, + -- spacing between lines + spacing = 36, + -- foot height + foot_H = 28, + -- horisontal margin + margin_H = 10, + + -- state buffer + result = {}, + files = {}, + lcolumn_width = 0, + items = 0, + page = 1, + current = 1, + pathfile = "", +} + +function FileInfo:FileCreated(fname,attr) + return os.date("%d %b %Y, %H:%M:%S", lfs.attributes(fname,attr)) +end + +function FileInfo:FileSize(fname) + local size = lfs.attributes(fname,"size") + if size < 1024 then + return size.." Bytes" + elseif size < 1048576 then + return string.format("%.2f", size/1024).."KB \("..size.." Bytes\)" + else + return string.format("%.2f", size/1048576).."MB \("..size.." Bytes\)" + end +end + +function FileInfo:init(path,fname) + self.pathfile = path.."/"..fname + self.result = {} + self:addAllCommands() + + local info_entry = {dir = "Name", name = fname} + table.insert(self.result, info_entry) + info_entry = {dir = "Path", name = path} + table.insert(self.result, info_entry) + info_entry = {dir = "Size", name = FileInfo:FileSize(self.pathfile)} + table.insert(self.result, info_entry) + -- empty line + --info_entry = {dir = " ", name = " "} + --table.insert(self.result, info_entry) + info_entry = {dir = "Created", name = FileInfo:FileCreated(self.pathfile,"change")} + table.insert(self.result, info_entry) + info_entry = {dir = "Modified", name = FileInfo:FileCreated(self.pathfile,"modification")} + table.insert(self.result, info_entry) + + -- if the document was already opened + local history = DocToHistory(self.pathfile) + local file, msg = io.open(history,"r") + if not file then + info_entry = {dir = "Last Read", name = "Never"} + table.insert(self.result, info_entry) + else + info_entry = {dir = "Last Read", name = FileInfo:FileCreated(history,"change")} + table.insert(self.result, info_entry) + local file_type = string.lower(string.match(self.pathfile, ".+%.([^.]+)")) + local to_search, add, factor = "\[\"last_percent\"\]", "\%", 100 + if ext:getReader(file_type) ~= CREReader then + to_search = "\[\"last_page\"\]" + add = " pages" + factor = 1 + end + for line in io.lines(history) do + if string.match(line,"%b[]") == to_search then + local cdc = tonumber(string.match(line, "%d+")) / factor + info_entry = {dir = "Completed", name = string.format("%d",cdc)..add } + table.insert(self.result, info_entry) + end + end + end + + self.items = #self.result + -- now calculating the horizontal space for left column + local tw, width + for i = 1, self.items do + tw = TextWidget:new({text = self.result[i].dir, face = Font:getFace("tfont", 22)}) + width = tw:getSize().w + if width > self.lcolumn_width then self.lcolumn_width = width end + tw:free() + end +end + +function FileInfo:show(path,name) + -- at first, one has to test whether the file still exists or not + -- it's necessary for last documents + if not io.open(path.."/"..name,"r") then return nil end + -- then goto main functions + self.perpage = math.floor(G_height / self.spacing) - 2 + self.pagedirty = true + self.markerdirty = false + FileInfo:init(path,name) + + + while true do + local cface = Font:getFace("cfont", 22) + local lface = Font:getFace("tfont", 22) + local tface = Font:getFace("tfont", 25) + local fface = Font:getFace("ffont", 16) + + if self.pagedirty then + self.markerdirty = true + -- gap between title rectangle left & left text drawing point + local xgap = 10 + fb.bb:paintRect(0, 0, G_width, G_height, 0) + -- draw menu title + DrawTitle("Document Information",self.margin_H,0,self.title_H,3,tface) + local c + -- position of left column + local x1 = self.margin_H + xgap + -- position of right column + its width + a small gap between columns + local x2 = x1 + self.lcolumn_width + 15 + -- y-position correction because of the multiline drawing + local dy = 5 + for c = 1, self.perpage do + local i = (self.page - 1) * self.perpage + c + if i <= self.items then + y = self.title_H + self.spacing * c + dy + renderUtf8Text(fb.bb, x1, y, lface, self.result[i].dir, true) + -- set interline spacing = 1.65 of the char height + -- or directly in pixels (if it exceeds 5) + dy = dy + renderUtf8Multiline(fb.bb, x2, y, cface, self.result[i].name, true, + G_width - self.margin_H - x2 - xgap, 1.65).y - y + end + end + -- draw footer + all_page = math.ceil(self.items/self.perpage) + DrawFooter("Page "..self.page.." of "..all_page,fface,self.foot_H) + end + +--[[ -- may be used in future for selecting some of displayed items + if self.markerdirty then + if not self.pagedirty then + if self.oldcurrent > 0 then + y = self.title_H + (self.spacing * self.oldcurrent) + 12 + fb.bb:paintRect(self.margin_H, y, G_width - 2 * self.margin_H, 3, 15) + fb:refresh(1, self.margin_H, y, G_width - 2 * self.margin_H, 3) + end + end + -- draw new marker line + y = self.title_H + (self.spacing * self.current) + 12 + fb.bb:paintRect(self.margin_H, y, G_width - 2 * self.margin_H, 3, 15) + if not self.pagedirty then + fb:refresh(1, self.margin_H, y, G_width - 2 * self.margin_H, 3) + end + self.oldcurrent = self.current + self.markerdirty = false + end ]] + + if self.pagedirty then + fb:refresh(0) + self.pagedirty = false + end + + local ev = input.saveWaitForEvent() + ev.code = adjustKeyEvents(ev) + if ev.type == EV_KEY and ev.value ~= EVENT_VALUE_KEY_RELEASE then + keydef = Keydef:new(ev.code, getKeyModifier()) + debug("key pressed: "..tostring(keydef)) + + command = self.commands:getByKeydef(keydef) + if command ~= nil then + debug("command to execute: "..tostring(command)) + ret_code = command.func(self, keydef) + else + debug("command not found: "..tostring(command)) + end + + if ret_code == "break" then break end + + if self.selected_item ~= nil then + debug("# selected "..self.selected_item) + return self.selected_item + end + end -- if + end -- while true + return nil +end + +function FileInfo:addAllCommands() + self.commands = Commands:new{} + -- show help page + self.commands:add(KEY_H,nil,"H", + "show help page", + function(self) + HelpPage:show(0, G_height, self.commands) + self.pagedirty = true + end + ) + -- make screenshot + self.commands:add(KEY_P, MOD_SHIFT, "P", + "make screenshot", + function(self) + os.execute("mkdir ".."/mnt/us/kindlepdfviewer/screenshots") + local d = os.date("%Y%m%d%H%M%S") + showInfoMsgWithDelay("making screenshot... ", 1000, 1) + os.execute("dd ".."if=/dev/fb0 ".."of=/mnt/us/kindlepdfviewer/screenshots/" .. d .. ".raw") + end + ) + -- recent documents + self.commands:add(KEY_L, nil, "L", + "last documents", + function(self) + FileHistory:init() + FileHistory:choose("") + self.pagedirty = true + end + ) + -- fonts + self.commands:add({KEY_F, KEY_AA}, nil, "F", + "font menu", + function(self) + -- NuPogodi, 18.05.12: define the number of the current font in face_list + local item_no = 0 + local face_list = Font:getFontList() + while face_list[item_no] ~= Font.fontmap.cfont and item_no < #face_list do + item_no = item_no + 1 + end + + local fonts_menu = SelectMenu:new{ + menu_title = "Fonts Menu", + item_array = face_list, + -- NuPogodi, 18.05.12: define selected item + current_entry = item_no - 1, + } + local re, font = fonts_menu:choose(0, G_height) + if re then + Font.fontmap["cfont"] = font + Font:update() + end + self.pagedirty = true + end + ) + self.commands:add({KEY_PGFWD, KEY_LPGFWD}, nil, ">", + "next page", + function(self) + if self.page < (self.items / self.perpage) then + if self.current + self.page*self.perpage > self.items then + self.current = self.items - self.page*self.perpage + end + self.page = self.page + 1 + self.pagedirty = true + else + self.current = self.items - (self.page-1)*self.perpage + self.markerdirty = true + end + end + ) + self.commands:add({KEY_PGBCK, KEY_LPGBCK}, nil, "<", + "previous page", + function(self) + if self.page > 1 then + self.page = self.page - 1 + self.pagedirty = true + else + self.current = 1 + self.markerdirty = true + end + end + ) + self.commands:add({KEY_ENTER, KEY_FW_PRESS}, nil, "Enter", + "open document", + function(self) + openFile(self.pathfile) + self.pagedirty = true + end + ) + self.commands:add({KEY_BACK, KEY_HOME}, nil, "Back", + "back", + function(self) + return "break" + end + ) + self.commands:add({KEY_SPACE}, nil, "Space", + "refresh page manually", + function(self) + self.pagedirty = true + end + ) +--[[ self.commands:add({KEY_B}, nil, "B", + "file browser", + function(self) + --FileChooser:setPath(".") + FileChooser:choose(0, G_height) + self.pagedirty = true + end + )]] +end diff --git a/filesearcher.lua b/filesearcher.lua index 63118172b..edfe99bf7 100644 --- a/filesearcher.lua +++ b/filesearcher.lua @@ -2,14 +2,19 @@ require "rendertext" require "keys" require "graphics" require "font" +require "inputbox" +require "dialog" +require "extentions" FileSearcher = { -- title height - title_H = 45, + title_H = 40, -- spacing between lines - spacing = 40, + spacing = 36, -- foot height - foot_H = 27, + foot_H = 28, + -- horisontal margin + margin_H = 10, -- state buffer dirs = {}, @@ -31,16 +36,9 @@ function FileSearcher:readDir() -- handle files in d for f in lfs.dir(d) do local file_type = string.lower(string.match(f, ".+%.([^.]+)") or "") - if lfs.attributes(d.."/"..f, "mode") == "directory" - and f ~= "." and f~= ".." and not string.match(f, "^%.[^.]") then + if lfs.attributes(d.."/"..f, "mode") == "directory" and f ~= "." and f~= ".." then table.insert(new_dirs, d.."/"..f) - elseif file_type == "djvu" or file_type == "pdf" - or file_type == "xps" or file_type == "cbz" - or file_type == "epub" or file_type == "txt" - or file_type == "rtf" or file_type == "htm" - or file_type == "html" or file_type == "mobi" or file_type == "prc" - or file_type == "fb2" or file_type == "chm" - or file_type == "doc" or file_type == "zip" then + elseif ext:getReader(file_type) then file_entry = {dir=d, name=f,} table.insert(self.files, file_entry) --debug("file:"..d.."/"..f) @@ -121,7 +119,44 @@ end function FileSearcher:addAllCommands() self.commands = Commands:new{} - + -- last documents + self.commands:add(KEY_L, nil, "L", + "last documents", + function(self) + FileHistory:init() + FileHistory:choose("") + self.pagedirty = true + end + ) + -- show help page + self.commands:add(KEY_H, nil, "H", + "show help page", + function(self) + HelpPage:show(0, G_height, self.commands) + self.pagedirty = true + end + ) + -- make screenshot + self.commands:add(KEY_P, MOD_SHIFT, "P", + "make screenshot", + function(self) + os.execute("mkdir ".."/mnt/us/kindlepdfviewer/screenshots") + local d = os.date("%Y%m%d%H%M%S") + showInfoMsgWithDelay("making screenshot... ", 1000, 1) + os.execute("dd ".."if=/dev/fb0 ".."of=/mnt/us/kindlepdfviewer/screenshots/" .. d .. ".raw") + end + ) + + -- file info + self.commands:add({KEY_FW_RIGHT, KEY_I}, nil, "joypad right", + "document details", + function(self) + file_entry = self.result[self.perpage*(self.page-1)+self.current] + FileInfo:show(file_entry.dir,file_entry.name) + self.pagedirty = true + end + ) + self.commands:add(KEY_FW_UP, nil, "joypad up", "goto previous item", function(self) @@ -175,12 +210,21 @@ function FileSearcher:addAllCommands() self.pagedirty = true end ) - self.commands:add(KEY_F, nil, "F", + self.commands:add({KEY_F, KEY_AA}, nil, "F", "font menu", function(self) - local fonts_menu = SelectMenu:new{ + -- NuPogodi, 18.05.12: define the number of the current font in face_list + local item_no = 0 + local face_list = Font:getFontList() + while face_list[item_no] ~= Font.fontmap.cfont and item_no < #face_list do + item_no = item_no + 1 + end + + local fonts_menu = SelectMenu:new{ menu_title = "Fonts Menu", - item_array = Font:getFontList(), + item_array = face_list, + -- NuPogodi, 18.05.12: define selected item + current_entry = item_no - 1, } local re, font = fonts_menu:choose(0, G_height) if re then @@ -190,8 +234,8 @@ function FileSearcher:addAllCommands() self.pagedirty = true end ) - self.commands:add({KEY_ENTER, KEY_FW_PRESS}, nil, "", - "select item", + self.commands:add({KEY_ENTER, KEY_FW_PRESS}, nil, "Enter", + "open selected item", function(self) file_entry = self.result[self.perpage*(self.page-1)+self.current] file_full_path = file_entry.dir .. "/" .. file_entry.name @@ -206,12 +250,50 @@ function FileSearcher:addAllCommands() self.pagedirty = true end ) - self.commands:add({KEY_BACK, KEY_HOME}, nil, "", - "back to file browser", + self.commands:add({KEY_BACK, KEY_HOME}, nil, "Back", + "back", function(self) return "break" end ) + self.commands:add({KEY_DEL}, nil, "Del", + "delete document", + function(self) + file_entry = self.result[self.perpage*(self.page-1)+self.current] + local file_to_del = file_entry.dir .. "/" .. file_entry.name + InfoMessage:show("Press \'Y\' to confirm deleting... ",0) + while true do + ev = input.saveWaitForEvent() + ev.code = adjustKeyEvents(ev) + if ev.type == EV_KEY and ev.value ~= EVENT_VALUE_KEY_RELEASE then + if ev.code == KEY_Y then + -- delete the file itself + os.execute("rm \""..file_to_del.."\"") + -- and its history file, if any + os.execute("rm \""..DocToHistory(file_to_del).."\"") + -- to avoid showing just deleted file + self:init( self.path ) + self:choose(self.keywords) + end + self.pagedirty = true + break + end -- if ev.type == EV_KEY + end -- while + end + ) self.commands:add({KEY_SPACE}, nil, "Space", + "refresh page manually", + function(self) + self.pagedirty = true + end + ) +--[[ self.commands:add({KEY_B}, nil, "B", + "file browser", + function(self) + --FileChooser:setPath(".") + FileChooser:choose(0, G_height) + self.pagedirty = true + end + )]] end function FileSearcher:choose(keywords) @@ -236,50 +318,47 @@ function FileSearcher:choose(keywords) fb.bb:paintRect(0, 0, G_width, G_height, 0) -- draw menu title - renderUtf8Text(fb.bb, 30, 0 + self.title_H, tface, - "Search Result for: "..self.keywords, true) + DrawTitle("Search Results for \'"..string.upper(self.keywords).."\'",self.margin_H,0,self.title_H,4,tface) -- draw results local c if self.items == 0 then -- nothing found y = self.title_H + self.spacing * 2 - renderUtf8Text(fb.bb, 20, y, cface, + renderUtf8Text(fb.bb, self.margin_H, y, cface, "Sorry, no match found.", true) - renderUtf8Text(fb.bb, 20, y + self.spacing, cface, + renderUtf8Text(fb.bb, self.margin_H, y + self.spacing, cface, "Please try a different keyword.", true) self.markerdirty = false else -- found something, draw it for c = 1, self.perpage do local i = (self.page - 1) * self.perpage + c if i <= self.items then - y = self.title_H + (self.spacing * c) - renderUtf8Text(fb.bb, 50, y, cface, - self.result[i].name, true) + y = self.title_H + (self.spacing * c) + 4 + local ftype = string.lower(string.match(self.result[i].name, ".+%.([^.]+)") or "") + DrawFileItem(self.result[i].name,self.margin_H,y,ftype) end end end -- draw footer - y = self.title_H + (self.spacing * self.perpage) + self.foot_H - x = (G_width / 2) - 50 all_page = math.ceil(self.items/self.perpage) - renderUtf8Text(fb.bb, x, y, fface, - "Page "..self.page.." of "..all_page, true) + DrawFooter("Page "..self.page.." of "..all_page,fface,self.foot_H) + end if self.markerdirty then if not self.pagedirty then if self.oldcurrent > 0 then - y = self.title_H + (self.spacing * self.oldcurrent) + 10 - fb.bb:paintRect(30, y, G_width - 60, 3, 0) - fb:refresh(1, 30, y, G_width - 60, 3) + y = self.title_H + (self.spacing * self.oldcurrent) + 12 + fb.bb:paintRect(self.margin_H, y, G_width - 2 * self.margin_H, 3, 0) + fb:refresh(1, self.margin_H, y, G_width - 2 * self.margin_H, 3) end end -- draw new marker line - y = self.title_H + (self.spacing * self.current) + 10 - fb.bb:paintRect(30, y, G_width - 60, 3, 15) + y = self.title_H + (self.spacing * self.current) + 12 + fb.bb:paintRect(self.margin_H, y, G_width - 2 * self.margin_H, 3, 15) if not self.pagedirty then - fb:refresh(1, 30, y, G_width - 60, 3) + fb:refresh(1, self.margin_H, y, G_width - 2 * self.margin_H, 3) end self.oldcurrent = self.current self.markerdirty = false diff --git a/helppage.lua b/helppage.lua index 2bc374d28..1acddca84 100644 --- a/helppage.lua +++ b/helppage.lua @@ -9,6 +9,14 @@ require "commands" HelpPage = { -- Other Class vars: + -- title height + title_H = 40, + -- horisontal margin + margin_H = 10, + -- foot height + foot_H = 28, + -- background color + bg_color = 4, -- spacing between lines spacing = 25, @@ -58,17 +66,20 @@ function HelpPage:show(ypos, height, commands) fface_height = math.ceil(fface_height) fface_ascender = math.ceil(fface_ascender) local spacing = face_height + 5 + local vert_S = self.title_H + 12 - local perpage = math.floor( (height - ypos - 1 * (fface_height + 5)) / spacing ) + local perpage = math.floor( (height - ypos - 1 * (fface_height + 5) - vert_S) / spacing ) local is_pagedirty = true while true do if is_pagedirty then fb.bb:paintRect(0, ypos, fb.bb:getWidth(), height, 0) + -- draw header + DrawTitle("Active Hotkeys",self.margin_H,0,self.title_H,self.bg_color,Font:getFace("tfont", 25)) local c local max_x = 0 for c = 1, perpage do - local x = 5 + local x = self.margin_H local i = (self.page - 1) * perpage + c if i <= self.items then local key = self.commands[i].shortcut @@ -78,16 +89,16 @@ function HelpPage:show(ypos, height, commands) if(modStart ~= nil) then key = key:sub(1,modStart-1)..key:sub(modEnd+1) local box = sizeUtf8Text( x, fb.bb:getWidth(), self.face, aMod.d, true) - fb.bb:paintRect(x, ypos + spacing*c - box.y_top, box.x, box.y_top + box.y_bottom, 4) - local pen_x = renderUtf8Text(fb.bb, x, ypos + spacing*c, self.face, aMod.d.." + ", true) + fb.bb:paintRect(x, ypos + spacing*c - box.y_top + vert_S, box.x + self.title_H, box.y_top + box.y_bottom, self.bg_color) + local pen_x = renderUtf8Text(fb.bb, x, ypos + spacing*c + vert_S, self.face, aMod.d.." + ", true) x = x + pen_x max_x = math.max(max_x, pen_x) end end debug("key:"..key) local box = sizeUtf8Text( x, fb.bb:getWidth(), self.face, key , true) - fb.bb:paintRect(x, ypos + spacing*c - box.y_top, box.x, box.y_top + box.y_bottom, 4) - local pen_x = renderUtf8Text(fb.bb, x, ypos + spacing*c, self.face, key, true) + fb.bb:paintRect(x, ypos + spacing*c - box.y_top + vert_S, box.x, box.y_top + box.y_bottom, self.bg_color) + local pen_x = renderUtf8Text(fb.bb, x, ypos + spacing*c + vert_S, self.face, key, true) x = x + pen_x max_x = math.max(max_x, x) end @@ -95,11 +106,13 @@ function HelpPage:show(ypos, height, commands) for c = 1, perpage do local i = (self.page - 1) * perpage + c if i <= self.items then - renderUtf8Text(fb.bb, max_x + 20, ypos + spacing*c, self.hface, self.commands[i].help, true) + renderUtf8Text(fb.bb, max_x + 20, ypos + spacing*c + vert_S, self.hface, self.commands[i].help, true) end end - renderUtf8Text(fb.bb, 5, height - fface_height + fface_ascender - 5, self.fface, - "Page "..self.page.." of "..math.ceil(self.items / perpage).." - Back to close this page", true) + -- draw footer + local footer = "Page "..self.page.." of "..math.ceil(self.items / perpage).." - Back to close this page" + -- DrawFooter(footer,Font:getFace("ffont", 16),self.foot_H) -- + renderUtf8Text(fb.bb, self.margin_H, height-7, self.fface, footer, true) end if is_pagedirty then fb:refresh(0, 0, ypos, fb.bb:getWidth(), height) diff --git a/reader.lua b/reader.lua index 3141c582d..dabcfd8ef 100755 --- a/reader.lua +++ b/reader.lua @@ -27,6 +27,7 @@ require "screen" require "keys" require "commands" require "dialog" +require "extentions" -- option parsing: longopts = { @@ -40,13 +41,8 @@ longopts = { function openFile(filename) local file_type = string.lower(string.match(filename, ".+%.([^.]+)")) local reader = nil - if file_type == "djvu" then - reader = DJVUReader - elseif file_type == "pdf" or file_type == "xps" or file_type == "cbz" then - reader = PDFReader - elseif file_type == "epub" or file_type == "txt" or file_type == "rtf" or file_type == "htm" or file_type == "html" or file_type == "fb2" or file_type == "chm" or file_type == "mobi" or file_type == "prc" or file_type == "doc" or file_type == "zip" then - reader = CREReader - end + + reader = ext:getReader(file_type) if reader then InfoMessage:show("Opening document, please wait... ", 0) reader:preLoadSettings(filename) diff --git a/resources/azw.png b/resources/azw.png new file mode 100644 index 0000000000000000000000000000000000000000..8f537c238fee9aaeb753cfc9daf3aee51feeb5a1 GIT binary patch literal 259 zcmV+e0sQ`nP)xN#0000#P)t-s{r&v} z1O!J%M@2^?czBzen~aQ%OG``9(b50^ z|KH!=0|NuBrmQ;v004hUL_t(|UWLs^4#O}E1yK&wC6~1OpEVI8(6+M3EI%GddE8vQ zHafrz;|^vHh^`O6-Z}UcM2a)002ov JPDHLkV1h`zYGMEY literal 0 HcmV?d00001 diff --git a/resources/cbz.png b/resources/cbz.png new file mode 100644 index 0000000000000000000000000000000000000000..1174c697788df3b2b9cae614b40c89ff8eb7de35 GIT binary patch literal 288 zcmV+*0pI?KP)mF8xfrf6j&=_$bI;KlfNWWU^L!nCl;uBXj;Uk! z1PJSiRHDw#%&pjDcwo%jg-7>WGmE~8&_sVs-BGuO&|~I8ecmh2Ii5s>0n=habVtC9 m5D;AvG64`th?c_zPx1wlaYZ*cc>1OQ0000JlarHOU0wbC{oQ%XkpKVy&q+i< zRCr!ZkD-pjKoExe1QIq!axPDi|6A>q;kBQ=ilJie?|G(Vde?0q{pOvZc zl0&aQ`ajiP?%}rL-dg=R8C#l9hH&;5$5kG=@c6(L@jFU6zY34;ZRb1F%AfG^WD9r0 xy;sI^#t*NZZ#&eQq2E%y@KT>s=S|Pu`W{y^SlmCqUjuX!gQu&X%Q~loCID{-X|@0W literal 0 HcmV?d00001 diff --git a/resources/fb2.png b/resources/fb2.png new file mode 100644 index 0000000000000000000000000000000000000000..60db6f39e5d43ec0055f856c0177b4c9954ad267 GIT binary patch literal 191 zcmeAS@N?(olHy`uVBq!ia0vp^A|TAd3?%E9GuQzsp#Yx{S7v7BzkmPw`ubK^SL^EP zhK7bt;V?S|l+EyTaSW-5EA2bU+iJk$@;CUP#p%D+Ap*XvQy7AN<+o1w!6fwli^(UW zpkI~Wq$e*r_wj<&#_3W9AZZ-w&R3aR ox4qN4*8PKD={;Y3?e5L--PKZW=VFVdQ&MBb@0Nut&Bme*a literal 0 HcmV?d00001 diff --git a/resources/folder.png b/resources/folder.png new file mode 100644 index 0000000000000000000000000000000000000000..badd49ab640daa3a369e4e52e40d70337976cb4c GIT binary patch literal 326 zcmV-M0lEH(P)iSae}F2rKIrqnONIo3AkNU_ZcGOoj#9g@FN!*fxq^ zV9Sc|f^dcd&md?L2TfuSZ&nYF`<4HX-+K`M@y}bX>wfYz0x$Z1$#Ha$i$I5i)4R|5nkO;RB zyyl*fLfcQnFqCur(C^?EL(HVMw1HogM4b~s^~KK9Q7Mh~7{PZJrIJ!A{RIoSbG)77 YAN$~Mu#zL(cmMzZ07*qoM6N<$g7@~1i2wiq literal 0 HcmV?d00001 diff --git a/resources/html.png b/resources/html.png new file mode 100644 index 0000000000000000000000000000000000000000..f0196da64801b5e1dbb627029c1eee35b08fe992 GIT binary patch literal 311 zcmV-70m%M|P)vHlarJE{ryWn>l^?80LV#1K~#8N zP0ulk!ax)T;9OuE7Y$+;38NPXh*+52A}m-2$0AigO<@s&PTGu_o!NAWm0(IwVBrD0 zK_HM6xr;BO#s1aD&*Sl)QlH<+mAZMw0pf@d)fX)bAtPI)5<)}+tc2jF$)+Xd#2C?^ z9k3MR5Sdm0taut1vB_sGuaw0)c40QLG)(7V0PPX!OmFCyQrmx2ql}1NghOqh5wwAWPX{o%yiWac&*YyL^7g(~ZHsKh6I=^aP85Xj@}R*9ZUr002ov JPDHLkV1lW7g^&OM literal 0 HcmV?d00001 diff --git a/resources/info-i.png b/resources/info-i.png index bf68406f42bc48324af3357b1ece2d1357c78556..69192d4ed5c74babd5465540786b0d7e85ea9638 100644 GIT binary patch delta 525 zcmV+o0`mRS2$}?t7=Hu<0002U(!@ak001yhOjJb!0|SMHg-uOO%*@Q`>FF*mE^TdX zq@<)>U0oa;9GaS%*Votm{r$SSx;8d8e0+RJD|prb00E^*L_t(|UX|6cP9jkh2H;;H zh{&RaCKeRd#=-}f7z;Wnd;kl2EhsiyS!h2-AAk^|FJPjLfqz0AvI}9r#Ci&{yN!mz z2e5EvxXeFyuAJykb@DOHo#CEy;fjg#aN`ANoOz#e_X;Xo6_cG)M9Eo69t28nC-@Co zR&?G)BLCw22S!d}ylV0S`3Yw5u9z2_mqWYrYrFf*yDQ$&9;XJCwBj*T?0|nmr8s3S z%nR7z;zGWO>VN595tYj!^KFOP<(m(9fGBPK$6@*0V|g6#W4wmD$8s^?D(j5TO)%$` z{dF*TpEof#DW4(4#SmJGM>Q}WIxHH0FRm+Y2TTckt{-Ysg0V5eECqKOFcb7KOWou; z9{5$03uL6$L3J(Dv4 P0000- z6vuDV+O(#WqDzg|K?)AmfLQ1vPEyDqDjggOU4oOFx;R)j^A9*=aVXNIo47a#LI(#) z9JF-t2ME$dti}Ey*AnuE<~^U1HtD@-XwF=|_d|Nlx#!1qseh^poMs+;iLbA(VzDTS zVyRSme0;1_D%EPW*=!O7;rIK;#>Qxxjz*)gSS%ioFE1~9yyIGbM1ff=|As>wbElCo`aecAs(sLXqNz%Zf%jI%9own9N)9G}%Tpkp3Hk%z> zY-O`qi=ib+N`E90gU$(wM8c%E7(?fBIZXHM%h7YW94<7^^Y*7ZfXlmX38|dZ=w8%R=JX91#_n1PV zfS~DiyLI!44m4VJOQll1qi1`28!ZnSLn8;@)zwvR=zp7=8>@m6{JN!)pbMxZj;_dCN-EP~Xic%~VwGo0SipWC2U@#mGkB*K~6cq>r!r}1bvd>Xm`^LRY1R?8$bgwT>c zQuFCbrGh3gF)`uy`%V7Xg2B>XR004{tya+_LZOh&2}DCxRh1wJG>JeUu)e;2baeFc z@?xs>$2Ni>G@nL>{%1a)@AC4}R%nW%@a2}4mTZ8gC`yBlL?ZZdfk40p=tv}@We=LB z@qgtSjfM?@*g+)#0MTgFDLa4;Dggk9#bQo@?w}F?fOtIa6le|A!qRlmf%u~|^?JR@ zWODdFb26Fi)B@VIvbMH1{LtT!RyDSRb`PD#7Jr05lB6LtNs?BM5b%dJG))^qPfbl( zJgmWNVOCdH4WW?-)m_J8I0MK~C}d_ab$@qvH$FaY@cH7Hi z$mjEY&8iJXz5Nc=T`t$>=O@CR7((drn0iZKYN+1V`oc``b+hT|X)|fg?E1p|qG*18 z9vPZp7(@MTiz5C1D3i%lDwX~HeZwxR(P+rB3?YONDt}G)n{|vNNs=UeKA&OE=0kZt zlgadbjX7`m>C`o|Qy2P9eLCUPM=B0}4&>B_S3~l|&4u4@+W(l)0%-f~4{=RNV~;0d QqyPW_07*qoM6N<$f;&bgUjP6A diff --git a/resources/mobi.png b/resources/mobi.png new file mode 100644 index 0000000000000000000000000000000000000000..e0631ad7a111854617537ee43b7f6787b9edbd1f GIT binary patch literal 268 zcmV+n0rUQeP)r!F_o2-`T6Q%DYUAVMwY9a~-Q5@%7=3+xHVccR0001& zNklF(?3YvQb9%J}DL`{)MLW0=b zXqyZ0t1n;wq;1izazfEUj^bqj(U(r~wH?#+Hr(9Eguz0000EPZ)$STDlYe%~jYP3E^CnkKAv~=lGW@hHn z(o!8Aod*vdaB*=dDk{du#~(Owpr@zj@87?srlzc{th_NYF+e>tJY5_^D&k!Gb@>h@ z2(VW3pKDlgU_li-3ty+AD90zE7oQ`V9&o7a;Bw-~oG8t*E&GQF<3Uz~ntEM-U$xnu zW|_+hD=$g>xTv(?C})XzuFZ9n3i z61Qq^e)DdPUi|FGyFPupmi%T~zC-OB!>UW?5^YzmXj>P}@%Phz=fCnnmy3V%%5d8P P-N@kS>gTe~DWM4f)oo)D literal 0 HcmV?d00001 diff --git a/resources/rtf.png b/resources/rtf.png new file mode 100644 index 0000000000000000000000000000000000000000..58ba9750b864dc852fc958e33a055a22a6e471bb GIT binary patch literal 266 zcmeAS@N?(olHy`uVBq!ia0vp^A|TAd3?%E9GuQzs-2k5uS7v7B#fukTzI@r&*Z24D z-^Inn*4Ea$ckjM?_pY?G^x3m#YinymLqnfFefk#&PWGPyYMkNe;uum9=h|<`byz{9 z&DN1$(5OWBl41&XF6X+V(k*?qE`nO?=EfX#j4|G~QT@d%<|i_L?<-Hp|MlaCYv}9b z$1AU$X1fwHA*)UAYtGxd&phw)1bO*RYfOu}w(P&)S-z^Z%gxU&YJSEPZ)$STDlYe%~jYP3E^C;hFE8)kzkgS+UTth_?CtGcT3Q+%9eq?o z_8L&*N>3NZkcv3hbGBTE90XV&hxH)$jm*UK=M8QK2{WZN zJT4r{o2k|-rro&p%sa_DJ@xBld|=(-x+!J1`|yjp@t5m2ERw z8GiB{>ExakwN%OYnAJ}l#W&|vVqM#91pH@d yP5jWN`m!&>Fu%}7r1)8yp~pJ+XJsObE{S_xD*R@*EwL8pXa-MLKbLh*2~7ZU&~@Pe literal 0 HcmV?d00001 diff --git a/resources/xps.png b/resources/xps.png new file mode 100644 index 0000000000000000000000000000000000000000..efcc1321d5e0ddb2476a6e23ef7f45d3d4543614 GIT binary patch literal 292 zcmV+<0o(qGP)6^Buxz^oX;%kM4t@^#kyk1$dZ36&pr?m|OV5AE(x}7_@M!}=HZ(K-M qI^djZQXB{=qkiehKXnBe;ExabKZa^ZG~22G0000WOnfY literal 0 HcmV?d00001 diff --git a/resources/zip.png b/resources/zip.png new file mode 100644 index 0000000000000000000000000000000000000000..4cb0bf5aa13183e5c0ca40f15777a75a979554d8 GIT binary patch literal 334 zcmV-U0kQsxP)4S#@=FJv}|q(a|q2FO7|jr5N(#0002l zNkl4?Baiy)+rzp;?}6&rhG&UZQcL4b6l<$W#pH)pv=^MJd^~C9dh&8LAcD grt7+E{et2@e-BY!eDft>pa1{>07*qoM6N<$f=h6Vf&c&j literal 0 HcmV?d00001 diff --git a/selectmenu.lua b/selectmenu.lua index dae914d0d..b137119ef 100644 --- a/selectmenu.lua +++ b/selectmenu.lua @@ -20,6 +20,10 @@ SelectMenu = { spacing = 36, -- foot height foot_H = 27, + -- horisontal margin + margin_H = 10, + -- NuPogodi, 18.05.12: new parameter + current_entry = 0, menu_title = "No Title", no_item_msg = "No items found.", @@ -225,30 +229,41 @@ function SelectMenu:choose(ypos, height) self.pagedirty = true self.markerdirty = false self.last_shortcut = 0 - + + -- NuPogodi, 18.02.12: let us define the starting position + -- If it was, certainly, send before by SelectMenu:new() via current_entry + self.current_entry = math.min(self.current_entry,self.items) + -- self.current_entry = math.max(self.current_entry,1) + -- now calculating the page & cursor + self.page = math.floor(self.current_entry / self.perpage) + 1 + self.page = math.max(1, self.page) + self.current = self.current_entry - (self.page - 1) * self.perpage + 1 + self.current = math.max(1, self.current) + -- end of changes (NuPogodi) + while true do local cface = Font:getFace("cfont", 22) local tface = Font:getFace("tfont", 25) local fface = Font:getFace("ffont", 16) - + + local lx = self.margin_H + 40 + local fw = fb.bb:getWidth() - lx - self.margin_H + if self.pagedirty then + fb.bb:paintRect(0, ypos, fb.bb:getWidth(), height, 0) self.markerdirty = true - -- draw menu title - fb.bb:paintRect(0, ypos, fb.bb:getWidth(), self.title_H + 10, 0) - fb.bb:paintRect(10, ypos + 10, fb.bb:getWidth() - 20, self.title_H, 5) - - local x = 20 - local y = ypos + self.title_H - renderUtf8Text(fb.bb, x, y, tface, self.menu_title, true) - + -- draw menu title (new version with clock & battery) + DrawTitle(self.menu_title,self.margin_H,0,self.title_H,4,tface) + + -- draw items - fb.bb:paintRect(0, ypos + self.title_H + 10, fb.bb:getWidth(), height - self.title_H, 0) + fb.bb:paintRect(0, ypos + self.title_H + self.margin_H, fb.bb:getWidth(), height - self.title_H, 0) if self.items == 0 then y = ypos + self.title_H + (self.spacing * 2) - renderUtf8Text(fb.bb, 30, y, cface, + renderUtf8Text(fb.bb, self.margin_H + 20, y, cface, "Oops... Bad news for you:", true) y = y + self.spacing - renderUtf8Text(fb.bb, 30, y, cface, + renderUtf8Text(fb.bb, self.margin_H + 20, y, cface, self.no_item_msg, true) self.markerdirty = false self:clearCommands() @@ -257,54 +272,63 @@ function SelectMenu:choose(ypos, height) for c = 1, self.perpage do local i = (self.page - 1) * self.perpage + c if i <= self.items then - y = ypos + self.title_H + (self.spacing * c) + y = ypos + self.title_H + (self.spacing * c) + 4 -- paint shortcut indications if c <= 10 or c > 20 then - blitbuffer.paintBorder(fb.bb, 10, y-22, 29, 29, 2, 15) + blitbuffer.paintBorder(fb.bb, self.margin_H, y-22, 29, 29, 2, 15) else - fb.bb:paintRect(10, y-22, 29, 29, 3) + fb.bb:paintRect(self.margin_H, y-22, 29, 29, 3) end if self.item_shortcuts[c] ~= nil and string.len(self.item_shortcuts[c]) == 3 then -- debug "Del", "Sym and "Ent" - renderUtf8Text(fb.bb, 13, y, fface, + renderUtf8Text(fb.bb, self.margin_H + 3, y, fface, self.item_shortcuts[c], true) else - renderUtf8Text(fb.bb, 18, y, self.sface, + renderUtf8Text(fb.bb, self.margin_H + 8, y, self.sface, self.item_shortcuts[c], true) end self.last_shortcut = c - - renderUtf8Text(fb.bb, 50, y, cface, - self.item_array[i], true) + -- NuPogodi, 15.05.12: paint items by own glyphs if the menu title == 'Fonts Menu', + -- but not "Fonts Menu " (crereader.lua); the problem is crereader creates own list + -- with the font families, rather then filenames of available fonts + local own_face = cface + if self.menu_title == "Fonts Menu" then + own_face = Font:getFace(self.item_array[i], 22) + end + -- NuPogodi, 18.05.12: rendering menu items ( fixed too long strings) + if sizeUtf8Text(lx,fb.bb:getWidth(),own_face,self.item_array[i],true).x < (fw - 10) then + renderUtf8Text(fb.bb,lx,y,own_face,self.item_array[i],true) + else + local gapx = sizeUtf8Text(0,fb.bb:getWidth(),own_face,"...", true).x + gapx = lx + renderUtf8TextWidth(fb.bb,lx,y,own_face,self.item_array[i],true,fw-gapx-15).x + renderUtf8Text(fb.bb,gapx,y,own_face,"...",true) + end + -- end of changes (NuPogodi) end -- if i <= self.items end -- for c=1, self.perpage end -- if self.items == 0 -- draw footer - y = ypos + self.title_H + (self.spacing * self.perpage) - + self.foot_H + 5 - x = (fb.bb:getWidth() / 2) - 50 - renderUtf8Text(fb.bb, x, y, fface, - "Page "..self.page.." of ".. - (math.ceil(self.items / self.perpage)), true) + DrawFooter("Page "..self.page.." of "..(math.ceil(self.items / self.perpage)),fface,self.foot_H) + end if self.markerdirty then if not self.pagedirty then if self.oldcurrent > 0 then - y = ypos + self.title_H + (self.spacing * self.oldcurrent) + 8 - fb.bb:paintRect(45, y, fb.bb:getWidth() - 60, 3, 0) - fb:refresh(1, 45, y, fb.bb:getWidth() - 60, 3) + y = ypos + self.title_H + (self.spacing * self.oldcurrent) + 12 + fb.bb:paintRect( lx, y, fw, 3, 0) + fb:refresh(1, lx, y, fw, 3) end end -- draw new marker line - y = ypos + self.title_H + (self.spacing * self.current) + 8 - fb.bb:paintRect(45, y, fb.bb:getWidth() - 60, 3, 15) + y = ypos + self.title_H + (self.spacing * self.current) + 12 + fb.bb:paintRect(lx, y, fw, 3, 15) if not self.pagedirty then - fb:refresh(1, 45, y, fb.bb:getWidth() - 60, 3) + fb:refresh(1, lx, y, fw, 3) end self.oldcurrent = self.current self.markerdirty = false diff --git a/settings.lua b/settings.lua index 7a15b6be9..532522bbd 100644 --- a/settings.lua +++ b/settings.lua @@ -1,7 +1,36 @@ -DocSettings = {} +DocSettings = { + } + +function DocToHistory(fullname) + local i,j = 1,0 + while i ~= nil do + i = string.find(fullname,"/",i+1) + if i==nil then break end + j = i + end + local f = string.sub(fullname,j+1,-1) + if j>0 then return "./history/\["..string.gsub(string.sub(fullname,1,j),"/","#").."\] "..f..".lua" + else return "./settings"..f..".lua" end +end + +function HistoryToName(history) + -- at first, search for path length + local s = string.len(string.match(history,"%b[]")) + -- and return the rest of string without 4 last characters (".lua") + return string.sub(history, s+2, -5) +end + +function HistoryToPath(history) + -- 1. select everything included in brackets + local s = string.match(history,"%b[]") + -- 2. crop the bracket-sign from both sides + -- 3. and finally replace decorative signs '#' to dir-char '/' + return string.gsub(string.sub(s,2,-3),"#","/") +end function DocSettings:open(docfile) - local new = { file = docfile..".kpdfview.lua", data = {} } + lfs.mkdir("./history") + local new = { file = DocToHistory(docfile), data = {} } local ok, stored = pcall(dofile,new.file) if ok then new.data = stored