package convertor 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" "git.kor-elf.net/kor-elf/gui-for-ffmpeg/internal/ffmpeg" ) type ItemsToConvertContract interface { Add(file *File) Clear() GetItems() map[int]ItemToConvertContract GetItemsContainer() *fyne.Container AfterAddingQueue() GetIsAutoRemove() bool SetIsAutoRemove(isAutoRemove bool) } type itemsToConvert struct { ffmpeg ffmpeg.UtilitiesContract nextId int items map[int]ItemToConvertContract itemsContainer *fyne.Container isAutoRemove bool } func NewItemsToConvert(ffmpeg ffmpeg.UtilitiesContract) ItemsToConvertContract { return &itemsToConvert{ ffmpeg: ffmpeg, nextId: 0, items: map[int]ItemToConvertContract{}, itemsContainer: container.NewVBox(), isAutoRemove: true, } } func (items *itemsToConvert) GetItemsContainer() *fyne.Container { return items.itemsContainer } 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) GetIsAutoRemove() bool { return items.isAutoRemove } func (items *itemsToConvert) SetIsAutoRemove(isAutoRemove bool) { items.isAutoRemove = isAutoRemove } 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) ItemToConvertContract { return &itemToConvert{ file: file, content: content, } } func (item *itemToConvert) GetFile() *File { return item.file } func (item *itemToConvert) GetContent() *fyne.Container { return item.content }