package kernel import ( "fyne.io/fyne/v2" "fyne.io/fyne/v2/canvas" "fyne.io/fyne/v2/container" "fyne.io/fyne/v2/theme" "fyne.io/fyne/v2/widget" "github.com/nicksnyder/go-i18n/v2/i18n" ) type ItemsToConvertContract interface { Add(file *File) GetItems() map[int]ItemToConvertContract AfterAddingQueue() } type ItemsToConvert struct { nextId int items map[int]ItemToConvertContract itemsContainer *fyne.Container ffplayService FFplayContract isAutoRemove bool } func NewItemsToConvert(itemsContainer *fyne.Container, ffplayService FFplayContract, localizerService LocalizerContract) *ItemsToConvert { containerForItems := container.NewVBox() ItemsToConvert := &ItemsToConvert{ nextId: 0, items: map[int]ItemToConvertContract{}, itemsContainer: containerForItems, ffplayService: ffplayService, isAutoRemove: true, } line := canvas.NewLine(theme.Color(theme.ColorNameFocus)) line.StrokeWidth = 5 checkboxAutoRemove := widget.NewCheck(localizerService.GetMessage(&i18n.LocalizeConfig{ MessageID: "autoClearAfterAddingToQueue", }), func(checked bool) { ItemsToConvert.isAutoRemove = checked }) checkboxAutoRemove.SetChecked(ItemsToConvert.isAutoRemove) localizerService.AddChangeCallback("autoClearAfterAddingToQueue", func(text string) { checkboxAutoRemove.Text = text }) buttonClear := widget.NewButton(localizerService.GetMessage(&i18n.LocalizeConfig{ MessageID: "clearAll", }), func() { ItemsToConvert.clear() }) buttonClear.Importance = widget.DangerImportance localizerService.AddChangeCallback("clearAll", func(text string) { buttonClear.Text = text }) itemsContainer.Add(container.NewVBox( container.NewPadded(), container.NewBorder(nil, nil, nil, buttonClear, container.NewHScroll(checkboxAutoRemove)), container.NewPadded(), line, container.NewPadded(), containerForItems, )) return ItemsToConvert } func (items *ItemsToConvert) Add(file *File) { nextId := items.nextId var content *fyne.Container var buttonPlay *widget.Button buttonPlay = widget.NewButtonWithIcon("", theme.Icon(theme.IconNameMediaPlay), func() { buttonPlay.Disable() go func() { _ = items.ffplayService.Run(FFplaySetting{ PathToFile: file.Path, }) fyne.Do(func() { buttonPlay.Enable() }) }() }) buttonRemove := widget.NewButtonWithIcon("", theme.Icon(theme.IconNameDelete), func() { items.itemsContainer.Remove(content) items.itemsContainer.Refresh() delete(items.items, nextId) }) buttonRemove.Importance = widget.DangerImportance content = container.NewVBox( container.NewBorder( nil, nil, buttonPlay, buttonRemove, container.NewHScroll(widget.NewLabel(file.Name)), ), container.NewHScroll(widget.NewLabel(file.Path)), container.NewPadded(), canvas.NewLine(theme.Color(theme.ColorNameFocus)), container.NewPadded(), ) items.itemsContainer.Add(content) items.items[nextId] = NewItemToConvert(file, content) items.nextId++ } func (items *ItemsToConvert) GetItems() map[int]ItemToConvertContract { return items.items } func (items *ItemsToConvert) AfterAddingQueue() { if items.isAutoRemove { items.clear() } } func (items *ItemsToConvert) clear() { items.itemsContainer.RemoveAll() items.items = map[int]ItemToConvertContract{} } type ItemToConvertContract interface { GetFile() *File GetContent() *fyne.Container } type ItemToConvert struct { file *File content *fyne.Container } func NewItemToConvert(file *File, content *fyne.Container) *ItemToConvert { return &ItemToConvert{ file: file, content: content, } } func (item ItemToConvert) GetFile() *File { return item.file } func (item ItemToConvert) GetContent() *fyne.Container { return item.content }