2020-06-19 21:38:53 +00:00
local CreOptions = require ( " ui/data/creoptions " )
2020-07-14 21:39:03 +00:00
local Device = require ( " device " )
2020-06-19 21:38:53 +00:00
local Event = require ( " ui/event " )
local Screen = require ( " device " ) . screen
local UIManager = require ( " ui/uimanager " )
local _ = require ( " gettext " )
2020-08-17 07:55:03 +00:00
local C_ = _.pgettext
local T = require ( " ffi/util " ) . template
2020-06-19 21:38:53 +00:00
local Dispatcher = {
initialized = false ,
}
--[[--
contains a list of a dispatchable settings
each setting contains :
2020-07-14 21:39:03 +00:00
category : one of
none : a direct event call
arg : a event that expects a gesture object or an argument
absolutenumber : event that sets a number
incrementalnumber : event that increments a number & accepts a gesture object
string : event with a list of arguments to chose from
2020-06-19 21:38:53 +00:00
event : what to call .
title : for use in ui .
2020-07-14 21:39:03 +00:00
section : under which menu to display ( currently : device , filemanager , rolling , paging )
2020-06-19 21:38:53 +00:00
and optionally
min / max : for number
default
args : allowed values for string .
toggle : display name for args
2020-07-14 21:39:03 +00:00
separator : put a separator after in the menu list
2020-06-19 21:38:53 +00:00
--]]--
local settingsList = {
2020-07-14 21:39:03 +00:00
-- Device settings
show_frontlight_dialog = { category = " none " , event = " ShowFlDialog " , title = _ ( " Show frontlight dialog " ) , device = true , condition = Device : hasFrontlight ( ) , } ,
toggle_frontlight = { category = " none " , event = " ToggleFrontlight " , title = _ ( " Toggle frontlight " ) , device = true , condition = Device : hasFrontlight ( ) , } ,
2020-08-17 07:55:03 +00:00
set_frontlight = { category = " absolutenumber " , event = " SetFlIntensity " , min = 0 , max = Device : getPowerDevice ( ) . fl_max , title = _ ( " Set frontlight brightness to %1 " ) , device = true , condition = Device : hasFrontlight ( ) , } ,
increase_frontlight = { category = " incrementalnumber " , event = " IncreaseFlIntensity " , min = 1 , max = Device : getPowerDevice ( ) . fl_max , title = _ ( " Increase frontlight brightness by %1 " ) , device = true , condition = Device : hasFrontlight ( ) , } ,
decrease_frontlight = { category = " incrementalnumber " , event = " DecreaseFlIntensity " , min = 1 , max = Device : getPowerDevice ( ) . fl_max , title = _ ( " Decrease frontlight brightness by %1 " ) , device = true , condition = Device : hasFrontlight ( ) , } ,
set_frontlight_warmth = { category = " absolutenumber " , event = " SetFlWarmth " , min = 0 , max = 100 , title = _ ( " Set frontlight warmth to %1 " ) , device = true , condition = Device : hasNaturalLight ( ) , } ,
increase_frontlight_warmth = { category = " incrementalnumber " , event = " IncreaseFlWarmth " , min = 1 , max = Device : getPowerDevice ( ) . fl_warmth_max , title = _ ( " Increase frontlight warmth by %1 " ) , device = true , condition = Device : hasNaturalLight ( ) , } ,
decrease_frontlight_warmth = { category = " incrementalnumber " , event = " DecreaseFlWarmth " , min = 1 , max = Device : getPowerDevice ( ) . fl_warmth_max , title = _ ( " Decrease frontlight warmth by %1 " ) , device = true , condition = Device : hasNaturalLight ( ) , separator = true , } ,
2020-07-14 21:39:03 +00:00
toggle_gsensor = { category = " none " , event = " ToggleGSensor " , title = _ ( " Toggle accelerometer " ) , device = true , condition = Device : canToggleGSensor ( ) , } ,
wifi_on = { category = " none " , event = " InfoWifiOn " , title = _ ( " Turn on Wi-Fi " ) , device = true , condition = Device : hasWifiToggle ( ) , } ,
wifi_off = { category = " none " , event = " InfoWifiOff " , title = _ ( " Turn off Wi-Fi " ) , device = true , condition = Device : hasWifiToggle ( ) , } ,
2020-07-28 18:49:55 +00:00
toggle_wifi = { category = " none " , event = " ToggleWifi " , title = _ ( " Toggle Wi-Fi " ) , device = true , condition = Device : hasWifiToggle ( ) , separator = true , } ,
2020-07-14 21:39:03 +00:00
reading_progress = { category = " none " , event = " ShowReaderProgress " , title = _ ( " Reading progress " ) , device = true , } ,
2020-07-28 18:49:55 +00:00
stats_calendar_view = { category = " none " , event = " ShowCalendarView " , title = _ ( " Statistics calendar view " ) , device = true , separator = true , } ,
2020-07-14 21:39:03 +00:00
history = { category = " none " , event = " ShowHist " , title = _ ( " History " ) , device = true , } ,
open_previous_document = { category = " none " , event = " OpenLastDoc " , title = _ ( " Open previous document " ) , device = true , } ,
filemanager = { category = " none " , event = " Home " , title = _ ( " File browser " ) , device = true , } ,
dictionary_lookup = { category = " none " , event = " ShowDictionaryLookup " , title = _ ( " Dictionary lookup " ) , device = true , } ,
wikipedia_lookup = { category = " none " , event = " ShowWikipediaLookup " , title = _ ( " Wikipedia lookup " ) , device = true , } ,
fulltext_search = { category = " none " , event = " ShowFulltextSearchInput " , title = _ ( " Fulltext search " ) , device = true , } ,
2020-07-28 18:49:55 +00:00
file_search = { category = " none " , event = " ShowFileSearch " , title = _ ( " File search " ) , device = true , separator = true , } ,
2020-07-14 21:39:03 +00:00
full_refresh = { category = " none " , event = " FullRefresh " , title = _ ( " Full screen refresh " ) , device = true , } ,
2020-07-17 06:54:21 +00:00
night_mode = { category = " none " , event = " ToggleNightMode " , title = _ ( " Toggle night mode " ) , device = true , } ,
set_night_mode = { category = " string " , event = " SetNightMode " , title = _ ( " Set night mode " ) , device = true , args = { true , false } , toggle = { _ ( " On " ) , _ ( " Off " ) } , } ,
2020-07-14 21:39:03 +00:00
suspend = { category = " none " , event = " SuspendEvent " , title = _ ( " Suspend " ) , device = true , } ,
exit = { category = " none " , event = " Exit " , title = _ ( " Exit KOReader " ) , device = true , } ,
restart = { category = " none " , event = " Restart " , title = _ ( " Restart KOReader " ) , device = true , condition = Device : canRestart ( ) , } ,
reboot = { category = " none " , event = " Reboot " , title = _ ( " Reboot the device " ) , device = true , condition = Device : canReboot ( ) , } ,
2020-07-28 18:49:55 +00:00
poweroff = { category = " none " , event = " PowerOff " , title = _ ( " Power off " ) , device = true , condition = Device : canPowerOff ( ) , separator = true , } ,
2020-07-14 21:39:03 +00:00
show_menu = { category = " none " , event = " ShowMenu " , title = _ ( " Show menu " ) , device = true , } ,
2020-08-20 11:38:48 +00:00
toggle_hold_corners = { category = " none " , event = " IgnoreHoldCorners " , title = _ ( " Toggle hold corners " ) , device = true , separator = true , } ,
toggle_rotation = { category = " none " , event = " SwapRotation " , title = _ ( " Toggle orientation " ) , device = true , } ,
invert_rotation = { category = " none " , event = " InvertRotation " , title = _ ( " Invert rotation " ) , device = true , } ,
iterate_rotation = { category = " none " , event = " IterateRotation " , title = _ ( " Rotate by 90° CW " ) , device = true , separator = true , } ,
2020-08-21 12:33:08 +00:00
set_refresh_rate = { category = " absolutenumber " , event = " SetBothRefreshRates " , min =- 1 , max = 200 , title = _ ( " Flash every %1 pages (always) " ) , device = true , } ,
set_day_refresh_rate = { category = " absolutenumber " , event = " SetDayRefreshRate " , min =- 1 , max = 200 , title = _ ( " Flash every %1 pages (not in night mode) " ) , device = true , } ,
set_night_refresh_rate = { category = " absolutenumber " , event = " SetNightRefreshRate " , min =- 1 , max = 200 , title = _ ( " Flash every %1 pages (in night mode) " ) , device = true , } ,
set_flash_on_chapter_boundaries = { category = " string " , event = " SetFlashOnChapterBoundaries " , title = _ ( " Always flash on chapter boundaries " ) , device = true , args = { true , false } , toggle = { _ ( " On " ) , _ ( " Off " ) } , } ,
toggle_flash_on_chapter_boundaries = { category = " none " , event = " ToggleFlashOnChapterBoundaries " , title = _ ( " Toggle flashing on chapter boundaries " ) , device = true , } ,
set_no_flash_on_second_chapter_page = { category = " string " , event = " SetNoFlashOnSecondChapterPage " , title = _ ( " Never flash on chapter's 2nd page " ) , device = true , args = { true , false } , toggle = { _ ( " On " ) , _ ( " Off " ) } , } ,
toggle_no_flash_on_second_chapter_page = { category = " none " , event = " ToggleNoFlashOnSecondChapterPage " , title = _ ( " Toggle flashing on chapter's 2nd page " ) , device = true , separator = true , } ,
2020-07-14 21:39:03 +00:00
wallabag_download = { category = " none " , event = " SynchronizeWallabag " , title = _ ( " Wallabag retrieval " ) , device = true , } ,
calibre_search = { category = " none " , event = " CalibreSearch " , title = _ ( " Search in calibre metadata " ) , device = true , } ,
calibre_browse_tags = { category = " none " , event = " CalibreBrowseTags " , title = _ ( " Browse all calibre tags " ) , device = true , } ,
2020-07-28 18:49:55 +00:00
calibre_browse_series = { category = " none " , event = " CalibreBrowseSeries " , title = _ ( " Browse all calibre series " ) , device = true , separator = true , } ,
2020-09-02 23:14:06 +00:00
show_terminal = { category = " none " , event = " TerminalStart " , title = _ ( " Show terminal " ) , device = true , } ,
2020-09-02 14:09:27 +00:00
edit_last_edited_file = { category = " none " , event = " OpenLastEditedFile " , title = _ ( " Texteditor: open last file " ) , device = true , separator = true , } ,
2020-08-18 10:41:58 +00:00
favorites = { category = " none " , event = " ShowColl " , arg = " favorites " , title = _ ( " Favorites " ) , device = true , } ,
2020-07-14 21:39:03 +00:00
-- filemanager settings
folder_up = { category = " none " , event = " FolderUp " , title = _ ( " Folder up " ) , filemanager = true } ,
show_plus_menu = { category = " none " , event = " ShowPlusMenu " , title = _ ( " Show plus menu " ) , filemanager = true } ,
2020-07-28 18:49:55 +00:00
folder_shortcuts = { category = " none " , event = " ShowFolderShortcutsDialog " , title = _ ( " Folder shortcuts " ) , filemanager = true , separator = true , } ,
2020-07-14 21:39:03 +00:00
-- reader settings
prev_chapter = { category = " none " , event = " GotoPrevChapter " , title = _ ( " Previous chapter " ) , rolling = true , paging = true , } ,
next_chapter = { category = " none " , event = " GotoNextChapter " , title = _ ( " Next chapter " ) , rolling = true , paging = true , } ,
first_page = { category = " none " , event = " GoToBeginning " , title = _ ( " First page " ) , rolling = true , paging = true , } ,
last_page = { category = " none " , event = " GoToEnd " , title = _ ( " Last page " ) , rolling = true , paging = true , } ,
prev_bookmark = { category = " none " , event = " GotoPreviousBookmarkFromPage " , title = _ ( " Previous bookmark " ) , rolling = true , paging = true , } ,
next_bookmark = { category = " none " , event = " GotoNextBookmarkFromPage " , title = _ ( " Next bookmark " ) , rolling = true , paging = true , } ,
go_to = { category = " none " , event = " ShowGotoDialog " , title = _ ( " Go to " ) , rolling = true , paging = true , } ,
skim = { category = " none " , event = " ShowSkimtoDialog " , title = _ ( " Skim " ) , rolling = true , paging = true , } ,
back = { category = " none " , event = " Back " , title = _ ( " Back " ) , rolling = true , paging = true , } ,
2020-08-18 10:41:58 +00:00
previous_location = { category = " none " , event = " GoBackLink " , arg = true , title = _ ( " Back to previous location " ) , rolling = true , paging = true , } ,
2020-07-14 21:39:03 +00:00
latest_bookmark = { category = " none " , event = " GoToLatestBookmark " , title = _ ( " Go to latest bookmark " ) , rolling = true , paging = true , } ,
follow_nearest_link = { category = " arg " , event = " GoToPageLink " , arg = { pos = { x = 0 , y = 0 } } , title = _ ( " Follow nearest link " ) , rolling = true , paging = true , } ,
follow_nearest_internal_link = { category = " arg " , event = " GoToInternalPageLink " , arg = { pos = { x = 0 , y = 0 } } , title = _ ( " Follow nearest internal link " ) , rolling = true , paging = true , } ,
2020-08-18 10:41:58 +00:00
clear_location_history = { category = " none " , event = " ClearLocationStack " , arg = true , title = _ ( " Clear location history " ) , rolling = true , paging = true , separator = true , } ,
2020-07-14 21:39:03 +00:00
toc = { category = " none " , event = " ShowToc " , title = _ ( " Table of contents " ) , rolling = true , paging = true , } ,
bookmarks = { category = " none " , event = " ShowBookmark " , title = _ ( " Bookmarks " ) , rolling = true , paging = true , } ,
2020-07-28 18:49:55 +00:00
book_statistics = { category = " none " , event = " ShowBookStats " , title = _ ( " Book statistics " ) , rolling = true , paging = true , separator = true , } ,
2020-07-14 21:39:03 +00:00
book_status = { category = " none " , event = " ShowBookStatus " , title = _ ( " Book status " ) , rolling = true , paging = true , } ,
book_info = { category = " none " , event = " ShowBookInfo " , title = _ ( " Book information " ) , rolling = true , paging = true , } ,
book_description = { category = " none " , event = " ShowBookDescription " , title = _ ( " Book description " ) , rolling = true , paging = true , } ,
2020-07-28 18:49:55 +00:00
book_cover = { category = " none " , event = " ShowBookCover " , title = _ ( " Book cover " ) , rolling = true , paging = true , separator = true , } ,
2020-07-14 21:39:03 +00:00
show_config_menu = { category = " none " , event = " ShowConfigMenu " , title = _ ( " Show bottom menu " ) , rolling = true , paging = true , } ,
toggle_bookmark = { category = " none " , event = " ToggleBookmark " , title = _ ( " Toggle bookmark " ) , rolling = true , paging = true , } ,
toggle_inverse_reading_order = { category = " none " , event = " ToggleReadingOrder " , title = _ ( " Toggle page turn direction " ) , rolling = true , paging = true , } ,
cycle_highlight_action = { category = " none " , event = " CycleHighlightAction " , title = _ ( " Cycle highlight action " ) , rolling = true , paging = true , } ,
2020-07-28 18:49:55 +00:00
cycle_highlight_style = { category = " none " , event = " CycleHighlightStyle " , title = _ ( " Cycle highlight style " ) , rolling = true , paging = true , separator = true , } ,
2020-07-14 21:39:03 +00:00
kosync_push_progress = { category = " none " , event = " KOSyncPushProgress " , title = _ ( " Push progress from this device " ) , rolling = true , paging = true , } ,
2020-07-28 18:49:55 +00:00
kosync_pull_progress = { category = " none " , event = " KOSyncPullProgress " , title = _ ( " Pull progress from other devices " ) , rolling = true , paging = true , separator = true , } ,
page_jmp = { category = " absolutenumber " , event = " GotoViewRel " , min =- 100 , max = 100 , title = _ ( " Go %1 pages " ) , rolling = true , paging = true , } ,
2020-07-14 21:39:03 +00:00
-- rolling reader settings
2020-08-17 07:55:03 +00:00
increase_font = { category = " incrementalnumber " , event = " IncreaseFontSize " , min = 1 , max = 255 , title = _ ( " Increase font size by %1 " ) , rolling = true , } ,
decrease_font = { category = " incrementalnumber " , event = " DecreaseFontSize " , min = 1 , max = 255 , title = _ ( " Decrease font size by %1 " ) , rolling = true , } ,
2020-07-14 21:39:03 +00:00
-- paging reader settings
toggle_page_flipping = { category = " none " , event = " TogglePageFlipping " , title = _ ( " Toggle page flipping " ) , paging = true , } ,
toggle_reflow = { category = " none " , event = " ToggleReflow " , title = _ ( " Toggle reflow " ) , paging = true , } ,
zoom = { category = " string " , event = " SetZoomMode " , title = _ ( " Zoom to " ) , args = { " contentwidth " , " contentheight " , " pagewidth " , " pageheight " , " column " , " content " , " page " } , toggle = { " content width " , " content height " , " page width " , " page height " , " column " , " content " , " page " } , paging = true , } ,
-- parsed from CreOptions
-- the rest of the table elements are built from their counterparts in CreOptions
2020-07-28 18:49:55 +00:00
rotation_mode = { category = " string " , device = true , separator = true , } ,
visible_pages = { category = " string " , rolling = true , separator = true , } ,
2020-07-14 21:39:03 +00:00
h_page_margins = { category = " string " , rolling = true } ,
sync_t_b_page_margins = { category = " string " , rolling = true } ,
t_page_margin = { category = " absolutenumber " , rolling = true } ,
2020-07-28 18:49:55 +00:00
b_page_margin = { category = " absolutenumber " , rolling = true , separator = true , } ,
2020-07-14 21:39:03 +00:00
view_mode = { category = " string " , rolling = true } ,
block_rendering_mode = { category = " string " , rolling = true } ,
render_dpi = { category = " string " , rolling = true } ,
2020-07-28 18:49:55 +00:00
line_spacing = { category = " absolutenumber " , rolling = true , separator = true , } ,
2020-08-17 07:55:03 +00:00
font_size = { category = " absolutenumber " , title = _ ( " Set font size to %1 " ) , rolling = true } ,
2020-07-14 21:39:03 +00:00
font_weight = { category = " string " , rolling = true } ,
2020-09-21 21:51:12 +00:00
font_gamma = { category = " string " , rolling = true } ,
2020-07-14 21:39:03 +00:00
font_hinting = { category = " string " , rolling = true } ,
2020-07-28 18:49:55 +00:00
font_kerning = { category = " string " , rolling = true , separator = true , } ,
2020-07-14 21:39:03 +00:00
status_line = { category = " string " , rolling = true } ,
embedded_css = { category = " string " , rolling = true } ,
embedded_fonts = { category = " string " , rolling = true } ,
smooth_scaling = { category = " string " , rolling = true } ,
nightmode_images = { category = " string " , rolling = true } ,
}
-- array for item order in menu
local dispatcher_menu_order = {
-- device
" reading_progress " ,
" history " ,
" open_previous_document " ,
" favorites " ,
" filemanager " ,
" stats_calendar_view " ,
" dictionary_lookup " ,
" wikipedia_lookup " ,
" fulltext_search " ,
" file_search " ,
" full_refresh " ,
" night_mode " ,
2020-07-17 06:54:21 +00:00
" set_night_mode " ,
2020-07-14 21:39:03 +00:00
" suspend " ,
" exit " ,
" restart " ,
" reboot " ,
" poweroff " ,
" show_menu " ,
" show_config_menu " ,
" show_frontlight_dialog " ,
" toggle_frontlight " ,
2020-07-29 21:48:28 +00:00
" set_frontlight " ,
2020-07-14 21:39:03 +00:00
" increase_frontlight " ,
" decrease_frontlight " ,
2020-07-29 21:48:28 +00:00
" set_frontlight_warmth " ,
2020-07-14 21:39:03 +00:00
" increase_frontlight_warmth " ,
" decrease_frontlight_warmth " ,
" toggle_hold_corners " ,
2020-08-21 12:33:08 +00:00
2020-07-14 21:39:03 +00:00
" toggle_gsensor " ,
" toggle_rotation " ,
2020-08-20 11:38:48 +00:00
" invert_rotation " ,
" iterate_rotation " ,
2020-07-14 21:39:03 +00:00
2020-08-21 12:33:08 +00:00
" set_refresh_rate " ,
" set_day_refresh_rate " ,
" set_night_refresh_rate " ,
" set_flash_on_chapter_boundaries " ,
" toggle_flash_on_chapter_boundaries " ,
" set_no_flash_on_second_chapter_page " ,
" toggle_no_flash_on_second_chapter_page " ,
2020-07-14 21:39:03 +00:00
" wifi_on " ,
" wifi_off " ,
" toggle_wifi " ,
" wallabag_download " ,
" calibre_search " ,
" calibre_browse_tags " ,
" calibre_browse_series " ,
2020-09-02 23:14:06 +00:00
" show_terminal " ,
2020-08-31 09:47:37 +00:00
" edit_last_edited_file " ,
2020-07-14 21:39:03 +00:00
" rotation_mode " ,
-- filemanager
" folder_up " ,
" show_plus_menu " ,
" folder_shortcuts " ,
-- reader
" page_jmp " ,
" prev_chapter " ,
" next_chapter " ,
" first_page " ,
" last_page " ,
" prev_bookmark " ,
" next_bookmark " ,
" go_to " ,
" skim " ,
" back " ,
" previous_location " ,
" latest_bookmark " ,
" follow_nearest_link " ,
" follow_nearest_internal_link " ,
" clear_location_history " ,
" toc " ,
" bookmarks " ,
" book_statistics " ,
" book_status " ,
" book_info " ,
" book_description " ,
" book_cover " ,
" increase_font " ,
" decrease_font " ,
" font_size " ,
2020-09-21 21:51:12 +00:00
" font_gamma " ,
2020-07-14 21:39:03 +00:00
" font_weight " ,
" font_hinting " ,
" font_kerning " ,
" toggle_bookmark " ,
" toggle_page_flipping " ,
" toggle_reflow " ,
" toggle_inverse_reading_order " ,
" zoom " ,
" cycle_highlight_action " ,
" cycle_highlight_style " ,
" kosync_push_progress " ,
" kosync_pull_progress " ,
" visible_pages " ,
" h_page_margins " ,
" sync_t_b_page_margins " ,
" t_page_margin " ,
" b_page_margin " ,
" view_mode " ,
" block_rendering_mode " ,
" render_dpi " ,
" line_spacing " ,
" status_line " ,
" embedded_css " ,
" embedded_fonts " ,
" smooth_scaling " ,
" nightmode_images " ,
2020-06-19 21:38:53 +00:00
}
--[[--
add settings from CreOptions / KoptOptions
--]]--
function Dispatcher : init ( )
2020-09-22 00:05:02 +00:00
if Dispatcher.initialized then return end
2020-06-19 21:38:53 +00:00
local parseoptions = function ( base , i )
for y = 1 , # base [ i ] . options do
local option = base [ i ] . options [ y ]
if settingsList [ option.name ] ~= nil then
if settingsList [ option.name ] . event == nil then
settingsList [ option.name ] . event = option.event
end
if settingsList [ option.name ] . title == nil then
settingsList [ option.name ] . title = option.name_text
end
if settingsList [ option.name ] . category == " string " then
if settingsList [ option.name ] . toggle == nil then
2020-06-28 10:18:45 +00:00
settingsList [ option.name ] . toggle = option.toggle or option.labels
if settingsList [ option.name ] . toggle == nil then
settingsList [ option.name ] . toggle = { }
for z = 1 , # option.values do
if type ( option.values [ z ] ) == " table " then
settingsList [ option.name ] . toggle [ z ] = option.values [ z ] [ 1 ]
end
2020-06-19 21:38:53 +00:00
end
end
end
if settingsList [ option.name ] . args == nil then
settingsList [ option.name ] . args = option.args or option.values
end
elseif settingsList [ option.name ] . category == " absolutenumber " then
if settingsList [ option.name ] . min == nil then
settingsList [ option.name ] . min = option.args [ 1 ]
end
if settingsList [ option.name ] . max == nil then
settingsList [ option.name ] . max = option.args [ # option.args ]
end
if settingsList [ option.name ] . default == nil then
settingsList [ option.name ] . default = option.default_value
end
end
end
end
end
for i = 1 , # CreOptions do
parseoptions ( CreOptions , i )
end
Dispatcher.initialized = true
end
2020-07-28 18:49:55 +00:00
-- Returns a display name for the item.
function Dispatcher : getNameFromItem ( item , location , settings )
local amount
if location [ settings ] ~= nil and location [ settings ] [ item ] ~= nil then
amount = location [ settings ] [ item ]
end
2020-08-17 07:55:03 +00:00
if amount == nil
or ( amount == 0 and settingsList [ item ] . category == " incrementalnumber " )
then
amount = C_ ( " Number placeholder " , " # " )
2020-07-28 18:49:55 +00:00
end
return T ( settingsList [ item ] . title , amount )
end
2020-08-04 22:19:28 +00:00
function Dispatcher : addItem ( caller , menu , location , settings , section )
2020-07-14 21:39:03 +00:00
for _ , k in ipairs ( dispatcher_menu_order ) do
if settingsList [ k ] [ section ] == true and
( settingsList [ k ] . condition == nil or settingsList [ k ] . condition )
then
if settingsList [ k ] . category == " none " or settingsList [ k ] . category == " arg " then
2020-06-19 21:38:53 +00:00
table.insert ( menu , {
2020-07-14 21:39:03 +00:00
text = settingsList [ k ] . title ,
2020-06-19 21:38:53 +00:00
checked_func = function ( )
2020-07-28 01:26:56 +00:00
return location [ settings ] ~= nil and location [ settings ] [ k ] ~= nil
2020-06-19 21:38:53 +00:00
end ,
callback = function ( touchmenu_instance )
2020-07-28 18:49:55 +00:00
if location [ settings ] == nil then
location [ settings ] = { }
end
if location [ settings ] [ k ] then
2020-07-28 01:26:56 +00:00
location [ settings ] [ k ] = nil
2020-07-14 21:39:03 +00:00
else
2020-07-28 01:26:56 +00:00
location [ settings ] [ k ] = true
2020-07-14 21:39:03 +00:00
end
2020-08-04 22:19:28 +00:00
caller.updated = true
2020-06-19 21:38:53 +00:00
if touchmenu_instance then touchmenu_instance : updateItems ( ) end
2020-07-14 21:39:03 +00:00
end ,
separator = settingsList [ k ] . separator ,
} )
2020-06-19 21:38:53 +00:00
elseif settingsList [ k ] . category == " absolutenumber " then
table.insert ( menu , {
text_func = function ( )
2020-07-28 18:49:55 +00:00
return Dispatcher : getNameFromItem ( k , location , settings )
2020-06-19 21:38:53 +00:00
end ,
checked_func = function ( )
2020-07-28 01:26:56 +00:00
return location [ settings ] ~= nil and location [ settings ] [ k ] ~= nil
2020-06-19 21:38:53 +00:00
end ,
callback = function ( touchmenu_instance )
local SpinWidget = require ( " ui/widget/spinwidget " )
local items = SpinWidget : new {
2020-07-28 18:49:55 +00:00
width = math.floor ( Screen : getWidth ( ) * 0.6 ) ,
value = location [ settings ] ~= nil and location [ settings ] [ k ] or settingsList [ k ] . default or 0 ,
2020-06-19 21:38:53 +00:00
value_min = settingsList [ k ] . min ,
value_step = 1 ,
value_hold_step = 2 ,
value_max = settingsList [ k ] . max ,
default_value = 0 ,
2020-07-28 18:49:55 +00:00
title_text = Dispatcher : getNameFromItem ( k , location , settings ) ,
2020-06-19 21:38:53 +00:00
callback = function ( spin )
2020-07-28 18:49:55 +00:00
if location [ settings ] == nil then
location [ settings ] = { }
end
2020-07-28 01:26:56 +00:00
location [ settings ] [ k ] = spin.value
2020-08-04 22:19:28 +00:00
caller.updated = true
2020-06-19 21:38:53 +00:00
if touchmenu_instance then
touchmenu_instance : updateItems ( )
end
end
}
UIManager : show ( items )
end ,
hold_callback = function ( touchmenu_instance )
2020-07-28 18:49:55 +00:00
if location [ settings ] ~= nil and location [ settings ] [ k ] ~= nil then
location [ settings ] [ k ] = nil
2020-08-04 22:19:28 +00:00
caller.updated = true
2020-07-28 18:49:55 +00:00
end
2020-06-19 21:38:53 +00:00
if touchmenu_instance then touchmenu_instance : updateItems ( ) end
end ,
2020-07-14 21:39:03 +00:00
separator = settingsList [ k ] . separator ,
2020-06-19 21:38:53 +00:00
} )
elseif settingsList [ k ] . category == " incrementalnumber " then
table.insert ( menu , {
text_func = function ( )
2020-07-28 18:49:55 +00:00
return Dispatcher : getNameFromItem ( k , location , settings )
2020-06-19 21:38:53 +00:00
end ,
checked_func = function ( )
2020-07-28 01:26:56 +00:00
return location [ settings ] ~= nil and location [ settings ] [ k ] ~= nil
2020-06-19 21:38:53 +00:00
end ,
callback = function ( touchmenu_instance )
2020-07-14 21:39:03 +00:00
local _ = require ( " gettext " )
2020-06-19 21:38:53 +00:00
local SpinWidget = require ( " ui/widget/spinwidget " )
local items = SpinWidget : new {
2020-07-28 18:49:55 +00:00
width = math.floor ( Screen : getWidth ( ) * 0.6 ) ,
value = location [ settings ] ~= nil and location [ settings ] [ k ] or 0 ,
2020-06-19 21:38:53 +00:00
value_min = settingsList [ k ] . min ,
value_step = 1 ,
value_hold_step = 2 ,
value_max = settingsList [ k ] . max ,
default_value = 0 ,
2020-07-28 18:49:55 +00:00
title_text = Dispatcher : getNameFromItem ( k , location , settings ) ,
2020-07-14 21:39:03 +00:00
info_text = _ ( [[If called by a gesture the amount of the gesture will be used]] ) ,
2020-06-19 21:38:53 +00:00
callback = function ( spin )
2020-07-28 18:49:55 +00:00
if location [ settings ] == nil then
location [ settings ] = { }
end
2020-07-28 01:26:56 +00:00
location [ settings ] [ k ] = spin.value
2020-08-04 22:19:28 +00:00
caller.updated = true
2020-06-19 21:38:53 +00:00
if touchmenu_instance then
touchmenu_instance : updateItems ( )
end
end
}
UIManager : show ( items )
end ,
hold_callback = function ( touchmenu_instance )
2020-07-28 18:49:55 +00:00
if location [ settings ] ~= nil and location [ settings ] [ k ] ~= nil then
location [ settings ] [ k ] = nil
2020-08-04 22:19:28 +00:00
caller.updated = true
2020-07-28 18:49:55 +00:00
end
2020-06-19 21:38:53 +00:00
if touchmenu_instance then
touchmenu_instance : updateItems ( )
end
end ,
2020-07-14 21:39:03 +00:00
separator = settingsList [ k ] . separator ,
2020-06-19 21:38:53 +00:00
} )
elseif settingsList [ k ] . category == " string " then
local sub_item_table = { }
for i = 1 , # settingsList [ k ] . args do
table.insert ( sub_item_table , {
text = tostring ( settingsList [ k ] . toggle [ i ] ) ,
checked_func = function ( )
2020-07-28 01:26:56 +00:00
return location [ settings ] ~= nil
and location [ settings ] [ k ] ~= nil
and location [ settings ] [ k ] == settingsList [ k ] . args [ i ]
2020-06-19 21:38:53 +00:00
end ,
callback = function ( )
2020-07-28 18:49:55 +00:00
if location [ settings ] == nil then
location [ settings ] = { }
end
2020-07-28 01:26:56 +00:00
location [ settings ] [ k ] = settingsList [ k ] . args [ i ]
2020-08-04 22:19:28 +00:00
caller.updated = true
2020-06-19 21:38:53 +00:00
end ,
} )
end
table.insert ( menu , {
text_func = function ( )
2020-07-28 18:49:55 +00:00
return Dispatcher : getNameFromItem ( k , location , settings )
2020-06-19 21:38:53 +00:00
end ,
checked_func = function ( )
2020-07-28 18:49:55 +00:00
return location [ settings ] ~= nil and location [ settings ] [ k ] ~= nil
2020-06-19 21:38:53 +00:00
end ,
sub_item_table = sub_item_table ,
keep_menu_open = true ,
hold_callback = function ( touchmenu_instance )
2020-07-28 18:49:55 +00:00
if location [ settings ] ~= nil and location [ settings ] [ k ] ~= nil then
location [ settings ] [ k ] = nil
2020-08-04 22:19:28 +00:00
caller.updated = true
2020-07-28 18:49:55 +00:00
end
2020-06-19 21:38:53 +00:00
if touchmenu_instance then
touchmenu_instance : updateItems ( )
end
end ,
2020-07-14 21:39:03 +00:00
separator = settingsList [ k ] . separator ,
2020-06-19 21:38:53 +00:00
} )
end
end
2020-07-14 21:39:03 +00:00
end
end
--[[--
Add a submenu to edit which items are dispatched
arguments are :
2020-08-04 22:19:28 +00:00
1 ) the caller so dispatcher can set the updated flag
2 ) the table representing the submenu ( can be empty )
3 ) the object ( table ) in which the settings table is found
4 ) the name of the settings table
2020-07-14 21:39:03 +00:00
example usage :
2020-08-04 22:19:28 +00:00
Dispatcher.addSubMenu ( self , sub_items , self.data , " profile1 " )
2020-07-14 21:39:03 +00:00
--]]--
2020-08-04 22:19:28 +00:00
function Dispatcher : addSubMenu ( caller , menu , location , settings )
2020-09-22 00:05:02 +00:00
Dispatcher : init ( )
2020-07-14 21:39:03 +00:00
table.insert ( menu , {
2020-07-28 18:49:55 +00:00
text = _ ( " Nothing " ) ,
2020-07-14 21:39:03 +00:00
separator = true ,
checked_func = function ( )
2020-07-28 18:49:55 +00:00
return location [ settings ] ~= nil and next ( location [ settings ] ) == nil
2020-07-14 21:39:03 +00:00
end ,
callback = function ( touchmenu_instance )
2020-07-28 01:26:56 +00:00
location [ settings ] = { }
2020-08-04 22:19:28 +00:00
caller.updated = true
2020-07-14 21:39:03 +00:00
if touchmenu_instance then touchmenu_instance : updateItems ( ) end
end ,
} )
local section_list = {
{ " device " , _ ( " Device " ) } ,
2020-07-17 07:57:46 +00:00
{ " filemanager " , _ ( " File browser " ) } ,
2020-07-14 21:39:03 +00:00
{ " rolling " , _ ( " Reflowable documents (epub, fb2, txt…) " ) } ,
{ " paging " , _ ( " Fixed layout documents (pdf, djvu, pics…) " ) } ,
}
for _ , section in ipairs ( section_list ) do
local submenu = { }
2020-08-04 22:19:28 +00:00
Dispatcher : addItem ( caller , submenu , location , settings , section [ 1 ] )
2020-07-14 21:39:03 +00:00
table.insert ( menu , {
text = section [ 2 ] ,
2020-07-28 18:49:55 +00:00
checked_func = function ( )
if location [ settings ] ~= nil then
for k , _ in pairs ( location [ settings ] ) do
if settingsList [ k ] [ section [ 1 ] ] == true and
( settingsList [ k ] . condition == nil or settingsList [ k ] . condition )
then return true end
end
end
end ,
hold_callback = function ( touchmenu_instance )
if location [ settings ] ~= nil then
for k , _ in pairs ( location [ settings ] ) do
if settingsList [ k ] [ section [ 1 ] ] == true then
location [ settings ] [ k ] = nil
2020-08-04 22:19:28 +00:00
caller.updated = true
2020-07-28 18:49:55 +00:00
end
end
if touchmenu_instance then touchmenu_instance : updateItems ( ) end
end
end ,
2020-07-14 21:39:03 +00:00
sub_item_table = submenu ,
} )
end
2020-06-19 21:38:53 +00:00
end
2020-07-28 01:26:56 +00:00
--[[--
Calls the events in a settings list
arguments are :
1 ) a reference to the uimanager
2 ) the settings table
3 ) optionally a ` gestures ` object
--]]--
function Dispatcher : execute ( ui , settings , gesture )
2020-06-19 21:38:53 +00:00
for k , v in pairs ( settings ) do
if settingsList [ k ] . conditions == nil or settingsList [ k ] . conditions == true then
if settingsList [ k ] . category == " none " then
2020-08-18 10:41:58 +00:00
if settingsList [ k ] . arg ~= nil then
ui : handleEvent ( Event : new ( settingsList [ k ] . event , settingsList [ k ] . arg ) )
else
ui : handleEvent ( Event : new ( settingsList [ k ] . event ) )
end
2020-06-19 21:38:53 +00:00
end
2020-07-14 21:39:03 +00:00
if settingsList [ k ] . category == " absolutenumber "
or settingsList [ k ] . category == " string "
then
2020-07-28 01:26:56 +00:00
ui : handleEvent ( Event : new ( settingsList [ k ] . event , v ) )
2020-06-19 21:38:53 +00:00
end
2020-07-14 21:39:03 +00:00
-- the event can accept a gesture object or an argument
if settingsList [ k ] . category == " arg " then
local arg = gesture or settingsList [ k ] . arg
2020-07-28 01:26:56 +00:00
ui : handleEvent ( Event : new ( settingsList [ k ] . event , arg ) )
2020-07-14 21:39:03 +00:00
end
-- the event can accept a gesture object or a number
2020-06-19 21:38:53 +00:00
if settingsList [ k ] . category == " incrementalnumber " then
2020-08-25 19:07:17 +00:00
local arg = v ~= 0 and v or gesture or 0
2020-07-28 01:26:56 +00:00
ui : handleEvent ( Event : new ( settingsList [ k ] . event , arg ) )
2020-06-19 21:38:53 +00:00
end
end
end
end
return Dispatcher