52 lines
1.8 KiB
Go
52 lines
1.8 KiB
Go
// Copyright (c) 2026 Storm Dragon
|
|
// SPDX-License-Identifier: GPL-3.0-or-later
|
|
|
|
package voiceprofiles
|
|
|
|
import "git.stormux.org/storm/screenreader-common/quicksettings"
|
|
|
|
// QuickSavedChoice is the quick settings choice for the saved voice, announced
|
|
// as "Default". Profile names are visible text, so this ID cannot collide.
|
|
const QuickSavedChoice = "\x00saved"
|
|
|
|
// QuickChoice names the profile matching current, then QuickSavedChoice when
|
|
// current is the saved voice, and otherwise "" for a voice changed this session.
|
|
// saved is the voice the reader would use without session changes, such as the
|
|
// focused application's saved voice; nil when unknown.
|
|
func (c Collection) QuickChoice(current Profile, saved *Profile) string {
|
|
if name := c.Matching(current); name != "" {
|
|
return name
|
|
}
|
|
if saved != nil && SameVoice(*saved, current) {
|
|
return QuickSavedChoice
|
|
}
|
|
return ""
|
|
}
|
|
|
|
// QuickOptions lists "Custom" only while current matches no saved voice, then
|
|
// "Default" for the saved voice, then each profile by name.
|
|
func (c Collection) QuickOptions(current Profile, saved *Profile) []quicksettings.Option {
|
|
options := []quicksettings.Option{}
|
|
if c.QuickChoice(current, saved) == "" {
|
|
options = append(options, quicksettings.Option{ID: "", Label: "Custom"})
|
|
}
|
|
if saved != nil {
|
|
options = append(options, quicksettings.Option{ID: QuickSavedChoice, Label: "Default"})
|
|
}
|
|
for _, p := range c.Profiles {
|
|
options = append(options, quicksettings.Option{ID: p.Name, Label: p.Name, Literal: true})
|
|
}
|
|
return options
|
|
}
|
|
|
|
// QuickProfile returns the voice a quick settings choice selects.
|
|
func (c Collection) QuickProfile(choice string, saved *Profile) (Profile, bool) {
|
|
if choice == QuickSavedChoice {
|
|
if saved == nil {
|
|
return Profile{}, false
|
|
}
|
|
return *saved, true
|
|
}
|
|
return c.Find(choice)
|
|
}
|