-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path2-list-folder.lua
More file actions
229 lines (189 loc) · 7.16 KB
/
Copy path2-list-folder.lua
File metadata and controls
229 lines (189 loc) · 7.16 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
local Device = require("device")
local Screen = Device.screen
local ImageWidget = require("ui/widget/imagewidget")
local FrameContainer = require("ui/widget/container/framecontainer")
local CenterContainer = require("ui/widget/container/centercontainer")
local HorizontalGroup = require("ui/widget/horizontalgroup")
local VerticalGroup = require("ui/widget/verticalgroup")
local HorizontalSpan = require("ui/widget/horizontalspan")
local VerticalSpan = require("ui/widget/verticalspan")
local TextBoxWidget = require("ui/widget/textboxwidget")
local Font = require("ui/font")
local BD = require("ui/bidi")
local util = require("util")
local Size = require("ui/size")
local Blitbuffer = require("ffi/blitbuffer")
local userpatch = require("userpatch")
local _ = require("gettext")
------------------------------------------------------------
-- Folder cover helper
------------------------------------------------------------
local FolderCover = {
name = ".cover",
exts = { ".jpg", ".jpeg", ".png", ".webp", ".gif" },
}
local function findFolderCover(dir)
local base = dir .. "/" .. FolderCover.name
for _, ext in ipairs(FolderCover.exts) do
local path = base .. ext
if util.fileExists(path) then
return path
end
end
end
------------------------------------------------------------
-- Fonts (KOReader v2025.10 matching)
------------------------------------------------------------
local TITLE_FACE = Font:getFace("cfont", 24)
local META_FACE = Font:getFace("cfont", 18)
------------------------------------------------------------
-- Patch
------------------------------------------------------------
local function patchCoverBrowser()
local ListMenu = require("listmenu")
local ListMenuItem =
userpatch.getUpValue(ListMenu._updateItemsBuildUI, "ListMenuItem")
if not ListMenuItem then return end
local BookInfoManager =
userpatch.getUpValue(ListMenuItem.update, "BookInfoManager")
local orig_update = ListMenuItem.update
function ListMenuItem:update(...)
orig_update(self, ...)
-- folders only
if not self.entry or self.entry.is_file or self.entry.file then
return
end
if self._folder_row_done then return end
self._folder_row_done = true
local dir = self.entry.path
if not dir then return end
local cover_file
local cover_data, cover_w, cover_h
local authors
local book_count = 0
cover_file = findFolderCover(dir)
self.menu._dummy = true
local entries = self.menu:genItemTableFromPath(dir)
self.menu._dummy = false
if entries then
for _, e in ipairs(entries) do
if e.is_file or e.file then
book_count = book_count + 1
local info = BookInfoManager:getBookInfo(e.path, true)
if info then
if not cover_file and not cover_data
and info.has_cover and info.cover_bb
then
cover_data = info.cover_bb
cover_w = info.cover_w
cover_h = info.cover_h
end
if not authors and info.authors then
if type(info.authors) == "table" then
authors = table.concat(info.authors, ", ")
elseif type(info.authors) == "string" then
authors = info.authors
end
end
end
end
end
end
if not cover_file and not cover_data then
return
end
self:_setFolderRow {
file = cover_file,
data = cover_data,
w = cover_w,
h = cover_h,
authors = authors,
count = book_count,
}
end
--------------------------------------------------------
-- Folder row
--------------------------------------------------------
function ListMenuItem:_setFolderRow(img)
local left_inset = Size.padding.large * 2
local border = Size.border.thin
local cover_height = self.height - Size.padding.small * 2
local cover_width = math.floor(cover_height * 0.67)
local image = ImageWidget:new {
file = img.file,
image = img.data,
scale_factor = (img.w and img.h)
and math.min(
(cover_width - border * 2) / img.w,
(cover_height - border * 2) / img.h
)
or nil,
}
local framed_cover = FrameContainer:new {
padding = 0,
bordersize = border,
background = Blitbuffer.COLOR_WHITE,
image,
}
local cover = CenterContainer:new {
dimen = { w = cover_width, h = self.height },
framed_cover,
}
local text_width =
self.width - cover_width - left_inset - Size.padding.large
local title = TextBoxWidget:new {
text = BD.directory(self.text:gsub("/$", "")),
face = TITLE_FACE,
bold = true,
width = text_width,
}
local author
if img.authors then
author = TextBoxWidget:new {
text = img.authors,
face = META_FACE,
width = text_width,
color = Blitbuffer.COLOR_GRAY_6,
}
end
local bookcount = TextBoxWidget:new {
text = string.format(
"%d %s",
img.count,
img.count == 1 and _("book") or _("books")
),
face = META_FACE,
alignment = "right",
color = Blitbuffer.COLOR_GRAY_6,
}
----------------------------------------------------
-- TEXT BLOCK (unchanged logic)
----------------------------------------------------
local text_block = VerticalGroup:new {
VerticalSpan:new { height = Screen:scaleBySize(6) },
title,
author and VerticalSpan:new { height = Screen:scaleBySize(3) } or nil,
author,
VerticalSpan:new { height = Screen:scaleBySize(8) },
bookcount,
}
----------------------------------------------------
-- ✅ KOReader-style LEFT PADDING (ONLY CHANGE)
----------------------------------------------------
local padded_text_block = HorizontalGroup:new {
HorizontalSpan:new { width = Screen:scaleBySize(10) },
text_block,
}
local row = HorizontalGroup:new {
HorizontalSpan:new { width = left_inset },
cover,
HorizontalSpan:new { width = Size.padding.large },
padded_text_block,
}
if self._underline_container and self._underline_container[1] then
self._underline_container[1]:free()
end
self._underline_container[1] = row
end
end
userpatch.registerPatchPluginFunc("coverbrowser", patchCoverBrowser)