98 lines
3.0 KiB
Go
98 lines
3.0 KiB
Go
// Copyright (c) 2026 Storm Dragon
|
|
// Authors: Storm Dragon, Angus Kola
|
|
// SPDX-License-Identifier: GPL-3.0-or-later
|
|
|
|
package preferences
|
|
|
|
/*
|
|
#include <stdlib.h>
|
|
#include "native.h"
|
|
*/
|
|
import "C"
|
|
|
|
import (
|
|
"errors"
|
|
"strings"
|
|
"unsafe"
|
|
|
|
"git.stormux.org/storm/cthulhu/internal/config"
|
|
)
|
|
|
|
var textAttributeLabels = map[string]string{
|
|
"size": "Font size", "family-name": "Font family", "weight": "Weight",
|
|
"indent": "Indent", "underline": "Underline", "strikethrough": "Strikethrough",
|
|
"justification": "Justification", "style": "Style", "paragraph-style": "Paragraph style",
|
|
"text-spelling": "Spelling", "fg-color": "Foreground color", "bg-color": "Background color",
|
|
}
|
|
|
|
func setPronunciations(entries []config.PronunciationEntry) {
|
|
C.prefs_pronunciation_clear()
|
|
for _, entry := range entries {
|
|
word, replacement := C.CString(entry.Word), C.CString(entry.Replacement)
|
|
C.prefs_pronunciation_append(word, replacement)
|
|
C.free(unsafe.Pointer(word))
|
|
C.free(unsafe.Pointer(replacement))
|
|
}
|
|
}
|
|
|
|
func getPronunciations() ([]config.PronunciationEntry, error) {
|
|
var entries []config.PronunciationEntry
|
|
for row := 0; row < int(C.prefs_pronunciation_count()); row++ {
|
|
word := C.prefs_pronunciation_value(C.int(row), 0)
|
|
replacement := C.prefs_pronunciation_value(C.int(row), 1)
|
|
entry := config.PronunciationEntry{Word: strings.TrimSpace(C.GoString(word)), Replacement: C.GoString(replacement)}
|
|
C.g_free(C.gpointer(word))
|
|
C.g_free(C.gpointer(replacement))
|
|
if entry.Word == "" && entry.Replacement == "" {
|
|
continue
|
|
}
|
|
if entry.Word == "" || entry.Replacement == "" {
|
|
return nil, errors.New("each pronunciation entry needs a word and a replacement")
|
|
}
|
|
entries = append(entries, entry)
|
|
}
|
|
return entries, nil
|
|
}
|
|
|
|
func setTextAttributes(settings config.TextAttributeSettings) {
|
|
C.prefs_text_attributes_clear()
|
|
for _, choice := range settings.Choices {
|
|
key, label := C.CString(choice.Key), C.CString(textAttributeLabels[choice.Key])
|
|
C.prefs_text_attribute_append(key, label, boolean(choice.Speak), boolean(choice.Braille))
|
|
C.free(unsafe.Pointer(key))
|
|
C.free(unsafe.Pointer(label))
|
|
}
|
|
buttons := []string{"textBrailleNoneButton", "textBraille7Button", "textBraille8Button", "textBrailleBothButton"}
|
|
index := 0
|
|
switch settings.Indicator {
|
|
case 0x40:
|
|
index = 1
|
|
case 0x80:
|
|
index = 2
|
|
case 0xc0:
|
|
index = 3
|
|
}
|
|
setCheck(buttons[index], true)
|
|
}
|
|
|
|
func getTextAttributes() config.TextAttributeSettings {
|
|
settings := config.TextAttributeSettings{}
|
|
for row := 0; row < int(C.prefs_text_attribute_count()); row++ {
|
|
key := C.prefs_text_attribute_key(C.int(row))
|
|
choice := config.TextAttributeChoice{Key: C.GoString(key),
|
|
Speak: C.prefs_text_attribute_enabled(C.int(row), 2) != 0,
|
|
Braille: C.prefs_text_attribute_enabled(C.int(row), 3) != 0}
|
|
C.g_free(C.gpointer(key))
|
|
settings.Choices = append(settings.Choices, choice)
|
|
}
|
|
switch {
|
|
case getCheck("textBraille7Button"):
|
|
settings.Indicator = 0x40
|
|
case getCheck("textBraille8Button"):
|
|
settings.Indicator = 0x80
|
|
case getCheck("textBrailleBothButton"):
|
|
settings.Indicator = 0xc0
|
|
}
|
|
return settings
|
|
}
|