diff --git a/frontend/ui/data/creoptions.lua b/frontend/ui/data/creoptions.lua index 6fb7913a0..ec8b38b99 100644 --- a/frontend/ui/data/creoptions.lua +++ b/frontend/ui/data/creoptions.lua @@ -1,6 +1,9 @@ local Device = require("device") +local InfoMessage = require("ui/widget/infomessage") local S = require("ui/data/strings") +local UIManager = require("ui/uimanager") local Screen = Device.screen +local T = require("ffi/util").template local _ = require("gettext") @@ -19,6 +22,107 @@ local function enable_if_equals(configurable, option, value) return configurable[option] == value end +local function showValues(configurable, option) + local default = G_reader_settings:readSetting("copt_"..option.name) + local current = configurable[option.name] + local value_default, value_current + local suffix = option.name_text_suffix or "" + if option.name == "screen_mode" then + current = Screen:getScreenMode() + end + local arg_table = {} + if option.toggle and option.values then + for i=1,#option.toggle do + arg_table[option.values[i]] = option.toggle[i] + end + end + if not default then + default = "not set" + if option.toggle then + value_current = current + current = arg_table[current] + end + elseif option.toggle and option.values then + value_current = current + value_default = default + default = arg_table[default] + current = arg_table[current] + end + if option.name_text_true_values and option.toggle and option.values and value_default then + UIManager:show(InfoMessage:new{ + text = T(_("%1:\nCurrent value: %2 (%5%4)\nDefault value: %3 (%6%4)"), option.name_text, + current, default, suffix, value_current, value_default) + }) + elseif option.name_text_true_values and option.toggle and option.values and not value_default then + UIManager:show(InfoMessage:new{ + text = T(_("%1:\nCurrent value: %2 (%5%4)\nDefault value: %3"), option.name_text, + current, default, suffix, value_current) + }) + else + UIManager:show(InfoMessage:new{ + text = T(_("%1:\nCurrent value: %2%4\nDefault value: %3%4"), option.name_text, current, + default, suffix) + }) + end +end + +local function tableComp(a,b) + if #a ~= #b then return false end + for i=1,#a do + if a[i] ~= b[i] then return false end + end + return true +end + +local function showValuesMargins(configurable, option) + local default = G_reader_settings:readSetting("copt_"..option.name) + local current = configurable[option.name] + local current_string + for i=1,#option.toggle do + if tableComp(current, option.values[i]) then + current_string = option.toggle[i] + break + end + end + if not default then + UIManager:show(InfoMessage:new{ + text = T(_([[ +%1: +Current value: %2 + left: %3 + top: %4 + right: %5 + bottom: %6 +Default value: not set]]), + option.name_text, current_string, current[1], current[2], current[3], current[4]) + }) + else + local default_string + for i=1,#option.toggle do + if tableComp(default, option.values[i]) then + default_string = option.toggle[i] + break + end + end + UIManager:show(InfoMessage:new{ + text = T(_([[ +%1: +Current value: %2 + left: %3 + top: %4 + right: %5 + bottom: %6 +Default value: %7 + left: %8 + top: %9 + right: %10 + bottom: %11]]), + option.name_text, current_string, current[1], current[2], current[3], current[4], + default_string, default[1], default[2], default[3], default[4]) + }) + end +end + local CreOptions = { prefix = 'copt', { @@ -33,6 +137,7 @@ local CreOptions = { default_arg = "portrait", current_func = function() return Screen:getScreenMode() end, event = "ChangeScreenMode", + name_text_hold_callback = showValues, } } }, @@ -48,6 +153,7 @@ local CreOptions = { args = {"scroll", "page"}, default_arg = "page", event = "SetViewMode", + name_text_hold_callback = showValues, }, { name = "line_spacing", @@ -65,6 +171,10 @@ local CreOptions = { DCREREADER_CONFIG_LINE_SPACE_PERCENT_MEDIUM, DCREREADER_CONFIG_LINE_SPACE_PERCENT_LARGE, }, + name_text_hold_callback = showValues, + -- used by showValues + name_text_suffix = "%", + name_text_true_values = true, }, { name = "page_margins", @@ -82,6 +192,7 @@ local CreOptions = { DCREREADER_CONFIG_MARGIN_SIZES_MEDIUM, DCREREADER_CONFIG_MARGIN_SIZES_LARGE, }, + name_text_hold_callback = showValuesMargins, }, } }, @@ -107,6 +218,13 @@ local CreOptions = { event = "ChangeSize", args = {"decrease", "increase"}, alternate = false, + name_text_hold_callback = function(configurable) + local opt = { + name = "font_size", + name_text = _("Font Size"), + } + showValues(configurable, opt) + end } } }, @@ -121,6 +239,7 @@ local CreOptions = { default_value = 0, args = {0, 1}, event = "ToggleFontBolder", + name_text_hold_callback = showValues, }, { name = "font_gamma", @@ -133,6 +252,7 @@ local CreOptions = { args = {10, 15, 25, 30, 36, 43, 49, 56}, -- gamma values for these indexes are: labels = {0.8, 1.0, 1.45, 1.90, 2.50, 4.0, 8.0, 15.0}, + name_text_hold_callback = showValues, }, { name = "font_hinting", @@ -142,6 +262,7 @@ local CreOptions = { default_value = 2, args = {0, 1, 2}, event = "SetFontHinting", + name_text_hold_callback = showValues, } } }, @@ -157,6 +278,7 @@ local CreOptions = { args = {0, 1}, default_arg = DCREREADER_PROGRESS_BAR, event = "SetStatusLine", + name_text_hold_callback = showValues, }, { name = "embedded_css", @@ -167,6 +289,7 @@ local CreOptions = { args = {true, false}, default_arg = nil, event = "ToggleEmbeddedStyleSheet", + name_text_hold_callback = showValues, }, { name = "embedded_fonts", @@ -180,6 +303,7 @@ local CreOptions = { enabled_func = function(configurable) return enable_if_equals(configurable, "embedded_css", 1) end, + name_text_hold_callback = showValues, }, }, }, diff --git a/frontend/ui/widget/configdialog.lua b/frontend/ui/widget/configdialog.lua index 85953a1fe..069bde8cd 100644 --- a/frontend/ui/widget/configdialog.lua +++ b/frontend/ui/widget/configdialog.lua @@ -233,7 +233,11 @@ function ConfigOption:init() text_font_face = name_font_face, text_font_size = name_font_size, text_font_bold = false, - hold_callback = self.options[c].name_text_hold_callback, + hold_callback = function() + if self.options[c].name_text_hold_callback then + self.options[c].name_text_hold_callback(self.config.configurable, self.options[c]) + end + end, } table.insert(option_name_container, option_name) table.insert(horizontal_group, option_name_container)