Share saved and custom quick voice profile choices
This commit is contained in:
1 parent
8a61bfff04
commit
ed6951f4cd
4 files changed
+121
-6
No files matched your search
@@ -0,0 +1,51 @@
|
||||
// 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"
|
||||
|
||||
// Quick_choice 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) Quick_choice(current Profile, saved *Profile) string {
|
||||
if name := c.Matching(current); name != "" {
|
||||
return name
|
||||
}
|
||||
if saved != nil && Same_voice(*saved, current) {
|
||||
return QuickSavedChoice
|
||||
}
|
||||
return ""
|
||||
}
|
||||
|
||||
// Quick_options lists "Custom" only while current matches no saved voice, then
|
||||
// "Default" for the saved voice, then each profile by name.
|
||||
func (c Collection) Quick_options(current Profile, saved *Profile) []quicksettings.Option {
|
||||
options := []quicksettings.Option{}
|
||||
if c.Quick_choice(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
|
||||
}
|
||||
|
||||
// Quick_profile returns the voice a quick settings choice selects.
|
||||
func (c Collection) Quick_profile(choice string, saved *Profile) (Profile, bool) {
|
||||
if choice == QuickSavedChoice {
|
||||
if saved == nil {
|
||||
return Profile{}, false
|
||||
}
|
||||
return *saved, true
|
||||
}
|
||||
return c.Find(choice)
|
||||
}
|
||||
Reference in new issue
Block a user