Persist thumbnail settings and set 4x8 default
This commit is contained in:
parent
027049ff76
commit
83fdae4e3b
96
thumb_config.go
Normal file
96
thumb_config.go
Normal file
|
|
@ -0,0 +1,96 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"os"
|
||||
"path/filepath"
|
||||
|
||||
"git.leaktechnologies.dev/stu/VideoTools/internal/logging"
|
||||
)
|
||||
|
||||
type thumbConfig struct {
|
||||
ContactSheet bool `json:"contactSheet"`
|
||||
ShowTimestamps bool `json:"showTimestamps"`
|
||||
Count int `json:"count"`
|
||||
Width int `json:"width"`
|
||||
SheetWidth int `json:"sheetWidth"`
|
||||
Columns int `json:"columns"`
|
||||
Rows int `json:"rows"`
|
||||
}
|
||||
|
||||
func defaultThumbConfig() thumbConfig {
|
||||
return thumbConfig{
|
||||
ContactSheet: false,
|
||||
ShowTimestamps: false,
|
||||
Count: 24,
|
||||
Width: 320,
|
||||
SheetWidth: 360,
|
||||
Columns: 4,
|
||||
Rows: 8,
|
||||
}
|
||||
}
|
||||
|
||||
func loadPersistedThumbConfig() (thumbConfig, error) {
|
||||
var cfg thumbConfig
|
||||
path := moduleConfigPath("thumb")
|
||||
data, err := os.ReadFile(path)
|
||||
if err != nil {
|
||||
return cfg, err
|
||||
}
|
||||
if err := json.Unmarshal(data, &cfg); err != nil {
|
||||
return cfg, err
|
||||
}
|
||||
if cfg.Count == 0 {
|
||||
cfg.Count = 24
|
||||
}
|
||||
if cfg.Width == 0 {
|
||||
cfg.Width = 320
|
||||
}
|
||||
if cfg.SheetWidth == 0 {
|
||||
cfg.SheetWidth = 360
|
||||
}
|
||||
if cfg.Columns == 0 {
|
||||
cfg.Columns = 4
|
||||
}
|
||||
if cfg.Rows == 0 {
|
||||
cfg.Rows = 8
|
||||
}
|
||||
return cfg, nil
|
||||
}
|
||||
|
||||
func savePersistedThumbConfig(cfg thumbConfig) error {
|
||||
path := moduleConfigPath("thumb")
|
||||
if err := os.MkdirAll(filepath.Dir(path), 0o755); err != nil {
|
||||
return err
|
||||
}
|
||||
data, err := json.MarshalIndent(cfg, "", " ")
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return os.WriteFile(path, data, 0o644)
|
||||
}
|
||||
|
||||
func (s *appState) applyThumbConfig(cfg thumbConfig) {
|
||||
s.thumbContactSheet = cfg.ContactSheet
|
||||
s.thumbShowTimestamps = cfg.ShowTimestamps
|
||||
s.thumbCount = cfg.Count
|
||||
s.thumbWidth = cfg.Width
|
||||
s.thumbSheetWidth = cfg.SheetWidth
|
||||
s.thumbColumns = cfg.Columns
|
||||
s.thumbRows = cfg.Rows
|
||||
}
|
||||
|
||||
func (s *appState) persistThumbConfig() {
|
||||
cfg := thumbConfig{
|
||||
ContactSheet: s.thumbContactSheet,
|
||||
ShowTimestamps: s.thumbShowTimestamps,
|
||||
Count: s.thumbCount,
|
||||
Width: s.thumbWidth,
|
||||
SheetWidth: s.thumbSheetWidth,
|
||||
Columns: s.thumbColumns,
|
||||
Rows: s.thumbRows,
|
||||
}
|
||||
if err := savePersistedThumbConfig(cfg); err != nil {
|
||||
logging.Debug(logging.CatSystem, "failed to persist thumb config: %v", err)
|
||||
}
|
||||
}
|
||||
|
|
@ -24,6 +24,9 @@ func (s *appState) showThumbView() {
|
|||
s.stopPreview()
|
||||
s.lastModule = s.active
|
||||
s.active = "thumb"
|
||||
if cfg, err := loadPersistedThumbConfig(); err == nil {
|
||||
s.applyThumbConfig(cfg)
|
||||
}
|
||||
s.setContent(buildThumbView(s))
|
||||
}
|
||||
|
||||
|
|
@ -81,7 +84,7 @@ func buildThumbView(state *appState) fyne.CanvasObject {
|
|||
state.thumbColumns = 4 // 4 columns works well for widescreen videos
|
||||
}
|
||||
if state.thumbRows == 0 {
|
||||
state.thumbRows = 6 // 4x6 = 24 thumbnails
|
||||
state.thumbRows = 8 // 4x8 = 32 thumbnails
|
||||
}
|
||||
|
||||
// File label and video preview
|
||||
|
|
@ -129,6 +132,7 @@ func buildThumbView(state *appState) fyne.CanvasObject {
|
|||
// Contact sheet checkbox (wrapped)
|
||||
contactSheetCheck := widget.NewCheck("", func(checked bool) {
|
||||
state.thumbContactSheet = checked
|
||||
state.persistThumbConfig()
|
||||
state.showThumbView()
|
||||
})
|
||||
contactSheetCheck.Checked = state.thumbContactSheet
|
||||
|
|
@ -141,6 +145,7 @@ func buildThumbView(state *appState) fyne.CanvasObject {
|
|||
|
||||
timestampCheck := widget.NewCheck("", func(checked bool) {
|
||||
state.thumbShowTimestamps = checked
|
||||
state.persistThumbConfig()
|
||||
})
|
||||
timestampCheck.Checked = state.thumbShowTimestamps
|
||||
timestampLabel := widget.NewLabel("Show timestamps on thumbnails")
|
||||
|
|
@ -169,6 +174,7 @@ func buildThumbView(state *appState) fyne.CanvasObject {
|
|||
state.thumbColumns = int(val)
|
||||
colLabel.SetText(fmt.Sprintf("Columns: %d", int(val)))
|
||||
totalLabel.SetText(fmt.Sprintf("Total thumbnails: %d", state.thumbColumns*state.thumbRows))
|
||||
state.persistThumbConfig()
|
||||
}
|
||||
|
||||
rowSlider := widget.NewSlider(2, 12)
|
||||
|
|
@ -178,6 +184,7 @@ func buildThumbView(state *appState) fyne.CanvasObject {
|
|||
state.thumbRows = int(val)
|
||||
rowLabel.SetText(fmt.Sprintf("Rows: %d", int(val)))
|
||||
totalLabel.SetText(fmt.Sprintf("Total thumbnails: %d", state.thumbColumns*state.thumbRows))
|
||||
state.persistThumbConfig()
|
||||
}
|
||||
|
||||
sizeOptions := []string{"240 px", "300 px", "360 px", "420 px", "480 px"}
|
||||
|
|
@ -194,6 +201,7 @@ func buildThumbView(state *appState) fyne.CanvasObject {
|
|||
case "480 px":
|
||||
state.thumbSheetWidth = 480
|
||||
}
|
||||
state.persistThumbConfig()
|
||||
})
|
||||
switch state.thumbSheetWidth {
|
||||
case 240:
|
||||
|
|
@ -228,6 +236,7 @@ func buildThumbView(state *appState) fyne.CanvasObject {
|
|||
countSlider.OnChanged = func(val float64) {
|
||||
state.thumbCount = int(val)
|
||||
countLabel.SetText(fmt.Sprintf("Thumbnail Count: %d", int(val)))
|
||||
state.persistThumbConfig()
|
||||
}
|
||||
|
||||
widthLabel := widget.NewLabel(fmt.Sprintf("Thumbnail Width: %d px", state.thumbWidth))
|
||||
|
|
@ -237,6 +246,7 @@ func buildThumbView(state *appState) fyne.CanvasObject {
|
|||
widthSlider.OnChanged = func(val float64) {
|
||||
state.thumbWidth = int(val)
|
||||
widthLabel.SetText(fmt.Sprintf("Thumbnail Width: %d px", int(val)))
|
||||
state.persistThumbConfig()
|
||||
}
|
||||
|
||||
settingsOptions = container.NewVBox(
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user