From c2a5d3f3f30edbcbd2a0db89a8aa8986b750874d Mon Sep 17 00:00:00 2001 From: poire-z Date: Mon, 17 Feb 2020 16:53:09 +0100 Subject: [PATCH] FileManager: tell plugins to save settings on close (#5872) So that Statistics settings modified while in FileManager are saved. Also allows resetting statistics when in FileManager (where there is no current book id to exclude). --- frontend/apps/filemanager/filemanager.lua | 1 + frontend/apps/reader/modules/readerdictionary.lua | 8 +++++--- plugins/statistics.koplugin/main.lua | 7 +++++-- 3 files changed, 11 insertions(+), 5 deletions(-) diff --git a/frontend/apps/filemanager/filemanager.lua b/frontend/apps/filemanager/filemanager.lua index 1e6f09c68..37eebe1a8 100644 --- a/frontend/apps/filemanager/filemanager.lua +++ b/frontend/apps/filemanager/filemanager.lua @@ -664,6 +664,7 @@ end function FileManager:onClose() logger.dbg("close filemanager") + self:handleEvent(Event:new("SaveSettings")) G_reader_settings:flush() UIManager:close(self) if self.onExit then diff --git a/frontend/apps/reader/modules/readerdictionary.lua b/frontend/apps/reader/modules/readerdictionary.lua index e5bb38cd3..902c8f050 100644 --- a/frontend/apps/reader/modules/readerdictionary.lua +++ b/frontend/apps/reader/modules/readerdictionary.lua @@ -972,9 +972,11 @@ function ReaderDictionary:onReadSettings(config) end function ReaderDictionary:onSaveSettings() - logger.dbg("save default dictionary", self.default_dictionary) - self.ui.doc_settings:saveSetting("default_dictionary", self.default_dictionary) - self.ui.doc_settings:saveSetting("disable_fuzzy_search", self.disable_fuzzy_search) + if self.ui.doc_settings then + logger.dbg("save default dictionary", self.default_dictionary) + self.ui.doc_settings:saveSetting("default_dictionary", self.default_dictionary) + self.ui.doc_settings:saveSetting("disable_fuzzy_search", self.disable_fuzzy_search) + end end function ReaderDictionary:toggleFuzzyDefault() diff --git a/plugins/statistics.koplugin/main.lua b/plugins/statistics.koplugin/main.lua index c8223c3e2..1f0e5c529 100644 --- a/plugins/statistics.koplugin/main.lua +++ b/plugins/statistics.koplugin/main.lua @@ -1808,6 +1808,9 @@ function ReaderStatistics:deleteBooksByTotalDuration(max_total_duration_mn) max_total_duration_mn), max_total_duration_mn), ok_text = _("Remove"), ok_callback = function() + -- Allow following SQL statements to work even when doc less by + -- using -1 as the book id, as real book ids are positive. + local id_curr_book = self.id_curr_book or -1 local conn = SQ3.open(db_location) local sql_stmt = [[ DELETE from page_stat @@ -1816,13 +1819,13 @@ function ReaderStatistics:deleteBooksByTotalDuration(max_total_duration_mn) ) ]] local stmt = conn:prepare(sql_stmt) - stmt:reset():bind(self.id_curr_book, max_total_duration_sec):step() + stmt:reset():bind(id_curr_book, max_total_duration_sec):step() sql_stmt = [[ DELETE from book WHERE id != ? and (total_read_time is NULL or total_read_time < ?) ]] stmt = conn:prepare(sql_stmt) - stmt:reset():bind(self.id_curr_book, max_total_duration_sec):step() + stmt:reset():bind(id_curr_book, max_total_duration_sec):step() stmt:close() -- Get nb of deleted books sql_stmt = [[