// Copyright (c) 2026 Storm Dragon // Authors: Storm Dragon, Angus Kola // SPDX-License-Identifier: GPL-3.0-or-later // Package preferences implements the isolated GTK preferences process and its // bounded, typed protocol. The UI never opens settings files or speech sockets. package preferences import ( "git.stormux.org/storm/cthulhu/internal/config" "git.stormux.org/storm/cthulhu/internal/input" ) func FromSettings(settings config.Settings) Values { return Values{OCR: settings.OCR, Pronunciations: append([]config.PronunciationEntry(nil), settings.Pronunciations...), TextAttributes: config.TextAttributeSettings{Choices: append([]config.TextAttributeChoice(nil), settings.TextAttributes.Choices...), Indicator: settings.TextAttributes.Indicator}, KeyboardLayout: settings.KeyboardLayout, CthulhuModifierKeys: append([]string(nil), settings.CthulhuModifierKeys...), KeyBindings: input.CloneBindingOverrides(settings.KeyBindings), TimeFormat: settings.TimeFormat, DateFormat: settings.DateFormat, EnableSound: settings.EnableSound, EnableBraille: settings.EnableBraille, EnableSpeech: settings.EnableSpeech, SpeechHistoryLimit: settings.SpeechHistoryLimit, SpeechVerbosityLevel: settings.SpeechVerbosityLevel, SayAllStyle: settings.SayAllStyle, EnableContractedBraille: settings.EnableContractedBraille, BrailleContractionTable: settings.BrailleContractionTable, Braille: settings.Braille, SoundVolume: settings.SoundVolume, SoundSink: settings.SoundSink, SoundTheme: settings.SoundTheme, PlaySoundForRole: settings.PlaySoundForRole, PlaySoundForState: settings.PlaySoundForState, PlaySoundForPositionInSet: settings.PlaySoundForPositionInSet, SpatializeObjectSounds: settings.SpatializeObjectSounds, ProgressBar: settings.ProgressBar, RoleSoundPresentation: settings.RoleSoundPresentation, Rate: settings.DefaultVoice.Rate, Pitch: settings.DefaultVoice.AveragePitch, Volume: settings.DefaultVoice.Gain, Punctuation: settings.VerbalizePunctuationStyle, Capitalization: settings.CapitalizationStyle, SpeechOutputModule: settings.SpeechOutputModule, SpeechServerFactory: settings.SpeechServerFactory, HardwareSpeechDevice: settings.HardwareSpeechDevice, HardwareSpeechBaudRate: settings.HardwareSpeechBaudRate, SpeechVoiceFamily: settings.DefaultVoice.Family, UppercaseVoice: settings.UppercaseVoice, HyperlinkVoice: settings.HyperlinkVoice, SystemVoice: settings.SystemVoice, Reading: settings.Reading, SpeakDescription: settings.SpeakDescription, EnableKeyEcho: settings.EnableKeyEcho, EnableAlphabeticKeys: settings.EnableAlphabeticKeys, EnableNumericKeys: settings.EnableNumericKeys, EnablePunctuationKeys: settings.EnablePunctuationKeys, EnableSpace: settings.EnableSpace, EnableModifierKeys: settings.EnableModifierKeys, EnableFunctionKeys: settings.EnableFunctionKeys, EnableActionKeys: settings.EnableActionKeys, EnableNavigationKeys: settings.EnableNavigationKeys, EnableDiacriticalKeys: settings.EnableDiacriticalKeys, EnableEchoByCharacter: settings.EnableEchoByCharacter, EnableEchoByWord: settings.EnableEchoByWord, EnableEchoBySentence: settings.EnableEchoBySentence, UseCustomEchoVoice: settings.UseCustomEchoVoice, UseCustomEchoSpeechServer: settings.UseCustomEchoSpeechServer, UseCustomEchoForKey: settings.UseCustomEchoForKey, UseCustomEchoForCharacter: settings.UseCustomEchoForCharacter, UseCustomEchoForWord: settings.UseCustomEchoForWord, UseCustomEchoForSentence: settings.UseCustomEchoForSentence, EchoVoice: settings.EchoVoice, EchoSpeechServer: settings.EchoSpeechServer, } } func (values Values) Merge(settings config.Settings) (config.Settings, error) { settings.Pronunciations = append([]config.PronunciationEntry(nil), values.Pronunciations...) settings.TextAttributes = config.TextAttributeSettings{Choices: append([]config.TextAttributeChoice(nil), values.TextAttributes.Choices...), Indicator: values.TextAttributes.Indicator} settings.OCR = values.OCR settings.KeyboardLayout = values.KeyboardLayout settings.CthulhuModifierKeys = append([]string(nil), values.CthulhuModifierKeys...) settings.KeyBindings = input.CloneBindingOverrides(values.KeyBindings) settings.TimeFormat = values.TimeFormat settings.DateFormat = values.DateFormat settings.EnableSound = values.EnableSound settings.EnableSpeech = values.EnableSpeech settings.SpeechHistoryLimit = values.SpeechHistoryLimit settings.SpeechVerbosityLevel = values.SpeechVerbosityLevel settings.SayAllStyle = values.SayAllStyle settings.EnableBraille = values.EnableBraille settings.EnableContractedBraille = values.EnableContractedBraille settings.BrailleContractionTable = values.BrailleContractionTable settings.Braille = values.Braille settings.SoundVolume = values.SoundVolume settings.SoundSink = values.SoundSink settings.SoundTheme = values.SoundTheme settings.PlaySoundForRole = values.PlaySoundForRole settings.PlaySoundForState = values.PlaySoundForState settings.PlaySoundForPositionInSet = values.PlaySoundForPositionInSet settings.SpatializeObjectSounds = values.SpatializeObjectSounds settings.ProgressBar = values.ProgressBar settings.RoleSoundPresentation = values.RoleSoundPresentation settings.EnableKeyEcho = values.EnableKeyEcho settings.EnableAlphabeticKeys = values.EnableAlphabeticKeys settings.EnableNumericKeys = values.EnableNumericKeys settings.EnablePunctuationKeys = values.EnablePunctuationKeys settings.EnableSpace = values.EnableSpace settings.EnableModifierKeys = values.EnableModifierKeys settings.EnableFunctionKeys = values.EnableFunctionKeys settings.EnableActionKeys = values.EnableActionKeys settings.EnableNavigationKeys = values.EnableNavigationKeys settings.EnableDiacriticalKeys = values.EnableDiacriticalKeys settings.EnableEchoByCharacter = values.EnableEchoByCharacter settings.EnableEchoByWord = values.EnableEchoByWord settings.EnableEchoBySentence = values.EnableEchoBySentence settings.UseCustomEchoVoice = values.UseCustomEchoVoice settings.UseCustomEchoSpeechServer = values.UseCustomEchoSpeechServer settings.UseCustomEchoForKey = values.UseCustomEchoForKey settings.UseCustomEchoForCharacter = values.UseCustomEchoForCharacter settings.UseCustomEchoForWord = values.UseCustomEchoForWord settings.UseCustomEchoForSentence = values.UseCustomEchoForSentence settings.EchoVoice = values.EchoVoice settings.EchoSpeechServer = values.EchoSpeechServer settings.DefaultVoice.Rate = values.Rate settings.DefaultVoice.AveragePitch = values.Pitch settings.DefaultVoice.Gain = values.Volume settings.SpeechOutputModule = values.SpeechOutputModule settings.SpeechServerFactory = values.SpeechServerFactory settings.HardwareSpeechDevice = values.HardwareSpeechDevice settings.HardwareSpeechBaudRate = values.HardwareSpeechBaudRate settings.DefaultVoice.Family = values.SpeechVoiceFamily settings.UppercaseVoice = values.UppercaseVoice settings.HyperlinkVoice = values.HyperlinkVoice settings.SystemVoice = values.SystemVoice settings.VerbalizePunctuationStyle = values.Punctuation settings.CapitalizationStyle = values.Capitalization settings.Reading = values.Reading settings.SpeakDescription = values.SpeakDescription return settings, config.Validate(settings) }