From f5f3e61782c85d3a45a4df63213b8e075990bdc8 Mon Sep 17 00:00:00 2001 From: WS64 Date: Fri, 22 Aug 2014 09:05:00 +0200 Subject: [PATCH] Removed screensaver functions to new lua file --- frontend/ui/uitoolbox.lua | 125 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 125 insertions(+) create mode 100644 frontend/ui/uitoolbox.lua diff --git a/frontend/ui/uitoolbox.lua b/frontend/ui/uitoolbox.lua new file mode 100644 index 000000000..11fb0320c --- /dev/null +++ b/frontend/ui/uitoolbox.lua @@ -0,0 +1,125 @@ +local InputContainer = require("ui/widget/container/inputcontainer") + +local UIToolbox = InputContainer:new{ +} + +function UIToolbox:getPicture(file) + + local contentopf + local contentpath + local epub_folder = "temp/epub" + + local function check_extension(cover) + if cover then + local itype = string.lower(string.match(cover, ".+%.([^.]+)") or "") + if not (itype == "png" or itype == "jpg" or itype == "jpeg" or itype == "tiff") then + cover = nil + end + end + return cover + end + + local function getValue(zipfile,which_line,to_find,excludecheck) + local f = io.open(zipfile,"r") + local i + + if f then + local line = f:read() + while line and not i do + i = line:lower():find(which_line:lower()) -- found something + if i then + f.close() + line = line:match(to_find .. "\"([^\"]+)\".*") + if not excludecheck then line = check_extension(line) end + if line then + return line + else + i = nil + end + end + if not i then line = f:read() end + end + f.close() + end + end + + local function guess(extension) + local cover = contentpath .. "Images/cover." .. extension + pcall(os.execute("unzip \"" .. file .. "\" \"" .. cover .. "\" -oq -d " .. epub_folder)) + cover = epub_folder .. "/" .. cover + if not io.open(cover,"r") then + cover = nil + end + return cover + end + + local function try_content_opf(which_line,to_find,addimage) + local cover = getValue(epub_folder .. "/" .. contentopf,which_line,to_find) + local imageadd + if cover then + if addimage then + imageadd = "Images/" + else + imageadd = "" + end + cover = contentpath .. imageadd .. cover + pcall(os.execute("unzip \"" .. file .. "\" \"" .. cover .. "\" -oq -d " .. epub_folder)) + cover = epub_folder .. "/" .. cover + if not io.open(cover,"r") then cover = nil end + end + return check_extension(cover) + end + + local cover + if file then + pcall(lfs.mkdir("temp")) + pcall(os.execute("rm -rf " .. epub_folder)) + pcall(lfs.mkdir(epub_folder)) + pcall(os.execute("unzip \"" .. file .. "\" cover.jpeg -oq -d " .. epub_folder)) + if io.open(epub_folder .. "/cover.jpeg","r") then -- picture in main folder + cover = epub_folder .. "/cover.jpeg" -- found one + else + pcall(os.execute("unzip \"" .. file .. "\" \"META-INF/container.xml\" -oq -d " .. epub_folder)) -- read container.xml + contentopf = getValue(epub_folder .. "/META-INF/container.xml","^%s*