summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorWilliam Wilgus <me.theuser@yahoo.com>2019-07-31 22:59:24 -0500
committerWilliam Wilgus <me.theuser@yahoo.com>2019-08-02 05:16:43 +0200
commit9d2af8777fc179573867bf03a803e5188025eda7 (patch)
tree4bad318a430e125279e29695d7c65a4d414fc811
parent501404d7032d8330c7e11a99711c65a41744be67 (diff)
downloadrockbox-9d2af8777fc179573867bf03a803e5188025eda7.tar.gz
rockbox-9d2af8777fc179573867bf03a803e5188025eda7.tar.bz2
rockbox-9d2af8777fc179573867bf03a803e5188025eda7.zip
lua update tagnav.lua with reload menu and bug fixes
Change-Id: I0e7364a3432bf867cb368c131bf83643115f9d0b
-rw-r--r--apps/plugins/lua_scripts/dbgettags.lua14
-rw-r--r--apps/plugins/lua_scripts/tagnav.lua72
2 files changed, 61 insertions, 25 deletions
diff --git a/apps/plugins/lua_scripts/dbgettags.lua b/apps/plugins/lua_scripts/dbgettags.lua
index 06fa6e8830..ec6e29a330 100644
--- a/apps/plugins/lua_scripts/dbgettags.lua
+++ b/apps/plugins/lua_scripts/dbgettags.lua
@@ -1,4 +1,4 @@
---dbgettags.lua Bilgus 2018
+-- dbgettags.lua Bilgus 2017
--[[
/***************************************************************************
* __________ __ ___.
@@ -48,10 +48,11 @@ end
-- uses database files to retrieve database tags
-- adds all unique tags into a lua table
-function get_tags(filename, hstr)
+-- ftable is optional
+function get_tags(filename, hstr, ftable)
if not filename then return end
-
+ if not ftable then ftable = {} end
hstr = hstr or filename
local file = io.open('/' .. filename or "", "r") --read
@@ -70,6 +71,7 @@ function get_tags(filename, hstr)
return file:read(count)
end
+ -- check the header and get size + #entries
local tagcache_header = readchrs(DATASZ) or ""
local tagcache_sz = readchrs(DATASZ) or ""
local tagcache_entries = readchrs(DATASZ) or ""
@@ -82,8 +84,8 @@ function get_tags(filename, hstr)
-- local tag_entries = bytesLE_n(tagcache_entries)
- local ftable = {}
- table.insert(ftable, 1, hstr)
+ for k, v in pairs(ftable) do ftable[k] = nil end -- clear table
+ ftable[1] = hstr
local tline = #ftable + 1
ftable[tline] = ""
@@ -94,7 +96,7 @@ function get_tags(filename, hstr)
tag_len = bytesLE_n(readchrs(DATASZ))
readchrs(DATASZ) -- idx = bytesLE_n(readchrs(DATASZ))
str = readchrs(tag_len) or ""
- str = string.match(str, "(%Z+)%z")
+ str = string.match(str, "(%Z+)%z") -- \0 terminated string
if str then
if ftable[tline - 1] ~= str then -- Remove dupes
diff --git a/apps/plugins/lua_scripts/tagnav.lua b/apps/plugins/lua_scripts/tagnav.lua
index 35e691045d..f62f27973b 100644
--- a/apps/plugins/lua_scripts/tagnav.lua
+++ b/apps/plugins/lua_scripts/tagnav.lua
@@ -1,4 +1,26 @@
--- BILGUS 2018
+-- tagnav.lua BILGUS 2018
+--[[
+/***************************************************************************
+ * __________ __ ___.
+ * Open \______ \ ____ ____ | | _\_ |__ _______ ___
+ * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
+ * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
+ * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
+ * \/ \/ \/ \/ \/
+ * $Id$
+ *
+ * Copyright (C) 2018 William Wilgus
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
+ * KIND, either express or implied.
+ *
+ ****************************************************************************/
+]]
--local scrpath = rb.current_path()"
@@ -18,10 +40,12 @@ local sERRORMENUENTRY = "Error finding menu entry"
local sBLANKLINE = "##sBLANKLINE##"
local sDEFAULTMENU = "customfilter"
-local sFILEOUT = "/.rockbox/tagnavi_custom.config"
-local sFILEHEADER = "#! rockbox/tagbrowser/2.0"
-local sMENUSTART = "%menu_start \"custom\" \"Database\""
-local sMENUTITLE = "title = \"fmt_title\""
+local sFILEOUT = "/.rockbox/tagnavi_custom.config"
+local sFILEHEADER = "#! rockbox/tagbrowser/2.0"
+local sMENUSTART = "%menu_start \"custom\" \"Database\""
+local sMENUTITLE = "title = \"fmt_title\""
+local sRELOADSEARCH = "^\"Reload\.\.\.\"%s*%->.+"
+local sRELOADMENU = "\"Reload...\" -> %reload"
local TAG_ARTIST, TAG_ALBARTIST, TAG_ALBUM, TAG_GENRE, TAG_COMPOSER = 1, 2, 3, 4, 5
local ts_TAGTYPE = {"Artist", "AlbumArtist", "Album", "Genre", "Composer"}
@@ -121,7 +145,7 @@ local function savedata(filename, ts_tags, cond, menuname)
if rb.file_exists(filename) ~= true then
lines_next(sFILEHEADER)
lines_next("#")
- lines_next("# MAIN MENU")
+ lines_next("# CUSTOM MENU")
lines_next(sMENUSTART)
else
local file = io.open(filename, "r") -- read
@@ -130,6 +154,7 @@ local function savedata(filename, ts_tags, cond, menuname)
return
end
+ -- copy all existing lines to table we will overwrite existing file
for line in file:lines() do
lines_next(line)
end
@@ -144,17 +169,22 @@ local function savedata(filename, ts_tags, cond, menuname)
replaceemptylines(lines, sBLANKLINE, menupos)
+ -- remove reload menu, we will add it at the end
+ replacelines(lines, sRELOADSEARCH, sBLANKLINE)
+
local existmenupos = checkexistingmenu(lines, menuname)
if existmenupos and existmenupos < 1 then return end -- user canceled
local lastcond = ""
local n_cond = COND_OR
local tags, tagtype
+ local tagpos = 0
local function buildtag(e_tagtype)
if ts_tags[e_tagtype] then
+ tagpos = tagpos + 1
n_cond = (cond[e_tagtype] or COND_OR)
- if e_tagtype > 1 then
+ if tagpos > 1 then
lines_append(" " .. ts_CONDSYMBOLS[n_cond])
end
tags = ts_tags[e_tagtype]
@@ -183,10 +213,12 @@ local function savedata(filename, ts_tags, cond, menuname)
buildtag(TAG_ALBUM)
buildtag(TAG_GENRE)
buildtag(TAG_COMPOSER)
+ -- add reload menu
+ lines_next(sRELOADMENU .. "\n")
- lines_next("\n")
else
rb.splash(rb.HZ, "Nothing to save")
+ return
end
local file = io.open(filename, "w+") -- overwrite
@@ -219,7 +251,7 @@ local function print_tags(ftable, settings, t_selected)
if not settings then
settings = {}
- settings.justify = "center"
+ settings.justify = "left"
settings.wrap = true
settings.msel = true
end
@@ -249,7 +281,7 @@ end -- print_tags
-- uses print_table to display a menu
function main_menu()
local menuname = sDEFAULTMENU
- local t_tags
+ local t_tags = {}
local ts_tags = {}
local cond = {}
local sel = {}
@@ -265,8 +297,9 @@ function main_menu()
[9] = ts_TAGTYPE[TAG_GENRE],
[10] = ts_CONDITIONALS[cond[TAG_COMPOSER] or COND_OR],
[11] = ts_TAGTYPE[TAG_COMPOSER],
- [12] = "Save to Tagnav",
- [13] = "Exit"
+ [12] = "",
+ [13] = "Save to Tagnav",
+ [14] = "Exit"
}
local function sel_cond(item, item_mt)
@@ -277,7 +310,7 @@ function main_menu()
end
local function sel_tag(item, item_mt, t_tags)
- t_tags = get_tags(rb.ROCKBOX_DIR .. "/" .. ts_DBPATH[item], ts_TAGTYPE[item])
+ t_tags = get_tags(rb.ROCKBOX_DIR .. "/" .. ts_DBPATH[item], ts_TAGTYPE[item], t_tags)
sel[item], ts_tags[item] = print_tags(t_tags, nil, sel[item])
if ts_tags[item] then
mt[item_mt] = ts_TAGTYPE[item] .. " [" .. #sel[item] .. "]"
@@ -319,16 +352,17 @@ function main_menu()
[11] = function(COMP)
sel_tag(TAG_COMPOSER, COMP, t_tags)
end,
-
- [12] = function(SAVET)
+ [12] = function(B) mt[B] = "TNC Bilgus 2018" end,
+ [13] = function(SAVET)
menuname = menuname or sDEFAULTMENU
menuname = rb.kbd_input(menuname)
- menuname = string.match(menuname, "%w+")
+ menuname = string.match(menuname or "", "%w+")
if menuname == "" then menuname = nil end
- menuname = menuname or sDEFAULTMENU
- savedata(sFILEOUT, ts_tags, cond, menuname)
+ if menuname then
+ savedata(sFILEOUT, ts_tags, cond, menuname)
+ end
end,
- [13] = function(EXIT_) return true end
+ [14] = function(EXIT_) return true end
}
print_menu(mt, ft, 2) --start at item 2