-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Reset settings/cover/metadata separately #10866
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
caller_callback() | ||
end, | ||
} | ||
check_button_settings = CheckButton:new{ | ||
text = _("document settings, progress, bookmarks, highlights, notes"), | ||
checked = sidecar_file and true or false, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
But sidecar_file is already true
or false
? :-) (Since it's hasSidecarFile())
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
koreader/frontend/docsettings.lua
Lines 93 to 97 in ed2ea68
--- Returns path of `metadata.lua` file if it exists, or nil. | |
-- @string doc_path path to the document (e.g., `/foo/bar.pdf`) | |
-- @bool no_legacy set to true to skip check of the legacy history file | |
-- @treturn string | |
function DocSettings:hasSidecarFile(doc_path, no_legacy) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Er, that function name should be changed to get ASAP if that's the case imho.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
But anyway, at the very least I'd do has_sidecar_file = hasSidecarFile() and true or false
rather than doing it over and over where it's used so that the workaround is contained.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
IIRC, there's precedent for this because of that very inconsistency in name vs. function (which has come up multiple times before, so, for once, I'd bite the bullet and fix all the things the right way there ;p).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(Might be just a matter of renaming the existing DocSettings:hasSidecarFile
to DocSettings:getExistingSidecarFilepath
(or a better sounding name), and just create a wrapper DocSettings:hasSidecarFile(......) return self:getExistingSidecarFilepath(......) and true or false
- and not change all the things, just the ones that expect the filepath ?)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Depending on the current callers, yeah, a wrapper (one way or the other) is not a bad idea (and tail calls are basically free in LuaJIT, so it's pretty harmless).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
IIRC, there's precedent for this because of that very inconsistency in name vs. function (which has come up multiple times before, so, for once, I'd bite the bullet and fix all the things the right way there ;p).
The pattern under discussion is unique to this PR (and should not exist), except it seems to have unfortunately been used with this very same function before since it became misnamed.
$ rg "has[A-Z][a-z]*\([a-zA-Z]*\) and"
plugins/gestures.koplugin/defaults.lua
9: tap_left_bottom_corner = Device:hasFrontlight() and {toggle_frontlight = true,} or nil,
14: one_finger_swipe_left_edge_down = Device:hasFrontlight() and {decrease_frontlight = 0,} or nil,
15: one_finger_swipe_left_edge_up = Device:hasFrontlight() and {increase_frontlight = 0,} or nil,
61: two_finger_swipe_south = Device:hasFrontlight() and {decrease_frontlight = 0,} or nil,
62: two_finger_swipe_north = Device:hasFrontlight() and {increase_frontlight = 0,} or nil,
76: tap_left_bottom_corner = Device:hasFrontlight() and {toggle_frontlight = true,} or nil,
81: one_finger_swipe_left_edge_down = Device:hasFrontlight() and {decrease_frontlight = 0,} or nil,
82: one_finger_swipe_left_edge_up = Device:hasFrontlight() and {increase_frontlight = 0,} or nil,
128: two_finger_swipe_south = Device:hasFrontlight() and {decrease_frontlight = 0,} or nil,
129: two_finger_swipe_north = Device:hasFrontlight() and {increase_frontlight = 0,} or nil,
frontend/apps/reader/readerui.lua
579: if not DocumentRegistry:hasProvider(file) and provider == nil then
frontend/device/generic/device.lua
149: if self:hasKeys() and self.input and self.input.event_map then
frontend/dispatcher.lua
80: toggle_key_repeat = {category="none", event="ToggleKeyRepeat", title=_("Toggle key repeat"), device=true, condition=Device:hasKeys() and Device:canKeyRepeat(), separator=true},
frontend/docsettings.lua
Outdated
if data_to_purge.doc_settings or data_to_purge.custom_cover_file or data_to_purge.custom_metadata_file then | ||
if lfs.attributes(self.doc_sidecar_dir, "mode") == "directory" then | ||
os.remove(self.doc_sidecar_dir) -- keep parent folders | ||
end | ||
if lfs.attributes(self.dir_sidecar_dir, "mode") == "directory" then | ||
util.removePath(self.dir_sidecar_dir) -- remove empty parent folders |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
May be a comment to mention that these will silently do nothing if the directory(ies) is not empty? (If that's the case.)
function DocSettings:purge(sidecar_to_keep, data_to_purge) | ||
local custom_cover_file, custom_metadata_file | ||
if sidecar_to_keep == nil then |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Remind me when/for what this sidecar_to_keep
is used?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
koreader/frontend/docsettings.lua
Line 289 in ed2ea68
self:purge(sidecar_file) -- remove old candidates and empty sidecar folders |
In
:flush
, to keep the actual sidecar file only.
local custom_cover_file = DocSettings:findCoverFile(file) | ||
local custom_metadata_file = DocSettings:getCustomMetadataFile(file) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just wondering: any reason for these 2 methods (somehow similar in purpose) are named differently?
Why not findCoverFile
and findCustomMedatadaFile
- or getCoverFile
and getCustomMedataFile
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We use
koreader/frontend/docsettings.lua
Line 429 in ed2ea68
function DocSettings:getCoverFile(reset_cache) |
when we have opened doc_settings (to use the cache).
custom_cover_file = check_button_cover.checked and custom_cover_file, | ||
custom_metadata_file = check_button_metadata.checked and custom_metadata_file, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There is not .old (backup) of these, right? So we can pass directly the files we have found, right?
But :purge() will find them again if we pass no arg, right?
(Feels a bit odd that 2 places do the same work, but ok.)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Right.
We must do this work to enable/disable the ConfirmBox checkbuttons, prior to purge.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok, but we could just pass custom_cover_file=true
and custom_metadata_file=true
(booleans, like the 3rd one doc_settings = true
is, for consistency), and let :purge() do again its normal work of finding them (again, yes, but this may not need that optimisation).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we should avoid double scanning the drive to find custom cover and metadata files again.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OK, not insisting :) as all this is quite localized and used only by these 2 modules.
(For a cleaner API, we would accept custom_cover_file=true (so all 3 keys can be booleans), and when it is a boolean, find the filepath - but when it is a string, assume it's the filepath that has already been searched and found, and use that as an optimization.)
if lfs.attributes(self.dir_sidecar_dir, "mode") == "directory" then | ||
util.removePath(self.dir_sidecar_dir) -- remove empty parent folders | ||
end | ||
end |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So, no more return value from this :purge()
- or its user filemanagerutil.purgeSettings(file)
. Sure there was no other places that made use of it?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, reset was the only user of the return value, to update the coverbrowser cache.
Actually there is some (historical) mess with the names: The worst is And our |
(^ no real problem for me, as long as it's documented in the docstrings/comments.) |
It slipped by me, but this change was bad. ;-) |
Thanks for the changes! I think that about does it? |
} | ||
confirmbox:addWidget(check_button_cover) | ||
check_button_metadata = CheckButton:new{ | ||
text = _("custom book properties"), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We handlle book metadata as book_props
internally.
Dunno if we should use "book properties" or "book metadata" in the UI. "book property" feels more vague than metadata to me.
(Also in the previous PR allowing editing, we show "Book property: title" and "Edit book property: Title".)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Another "Metadata" is explained here
Book view settings, reading progress, highlights, bookmarks and notes (collectively known as metadata) are stored in a separate folder named <book-filename>.sdr (".sdr" meaning "sidecar"). |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Amazon says "metadata fields":
https://kdp.amazon.com/en_US/help/topic/G201097560
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I guess we felt the need to mention "metadata" in "(collectively known as metadata)" because our docsettings ("docsettings.epub.lua" would have been a quite good name) file is named metadata.epub.lua
, as a way to indicate to the user who has met them in some file browser that this file is what we are talking about.
Too late to rename all these metadata.epub.lua
:) (and external tools expect them named liked that) but I would have called that doc settings or doc properties.
And I would, as Amazon, name the book metadata fields... book metadata :)
The simpler would be to remove "(collectively known as metadata)" from that string. Do we mention "metadata" elsewhere?
Or find another user facing name for these title/authors/language/keywords...
Dunno.
Needs more input.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I vaguely recall some discussion about that string, but not why "collectively known as metadata" is in there.
local confirmbox = ConfirmBox:new{ | ||
text = T(_("Reset this document?") .. "\n\n%1\n\n" .. | ||
_("Document progress, settings, bookmarks, highlights, notes and custom cover image will be permanently lost."), | ||
_("Resetted information will be permanently lost."), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Late to the party, but: Reset
, set
is an irregular verb (set/set/set ;)).
Which possibly makes this turn of phrase slightly clunky, so I'd drop it entirely, e.g., Information will be permanently lost
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I believed so as well but googled and got
https://en.wiktionary.org/wiki/resetted
https://www.wordsense.eu/resetted/
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Note that over on https://www.wordsense.eu/reset/#English it explicitly says reset
as the simple past. The other one is broadcasting that some people use resetted (and broadcasted), which is one of those it's technically wrong but often clearer kind of things.
But all that as an aside. Information will be permanently lost
or Information will be permanently lost after resetting
sounds better anyway.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed in #10869.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I believed so as well but googled and got https://en.wiktionary.org/wiki/resetted https://www.wordsense.eu/resetted/
Huh. That's another meaning entirely, in a very specific field (and a chiefly local one at that), but a fun quirk I wasn't aware of nonetheless ;).
This change is