Made it so that files for conversion are added to the queue.
This commit is contained in:
@@ -4,8 +4,12 @@ import (
|
||||
"fyne.io/fyne/v2"
|
||||
"fyne.io/fyne/v2/canvas"
|
||||
"fyne.io/fyne/v2/container"
|
||||
"fyne.io/fyne/v2/lang"
|
||||
"fyne.io/fyne/v2/theme"
|
||||
"fyne.io/fyne/v2/widget"
|
||||
"git.kor-elf.net/kor-elf/gui-for-ffmpeg/internal/application/convertor"
|
||||
"git.kor-elf.net/kor-elf/gui-for-ffmpeg/internal/ffmpeg"
|
||||
"image/color"
|
||||
"strconv"
|
||||
"strings"
|
||||
)
|
||||
@@ -23,15 +27,17 @@ type queueLayout struct {
|
||||
itemsContainer *fyne.Container
|
||||
queueAllStatistics QueueStatisticsAllContract
|
||||
items map[int]queueLayoutItem
|
||||
ffmpegService ffmpeg.UtilitiesContract
|
||||
}
|
||||
|
||||
func NewQueueLayout() QueueLayoutContract {
|
||||
func NewQueueLayout(ffmpegService ffmpeg.UtilitiesContract) QueueLayoutContract {
|
||||
items := map[int]queueLayoutItem{}
|
||||
|
||||
return &queueLayout{
|
||||
itemsContainer: container.NewVBox(),
|
||||
queueAllStatistics: newQueueAllStatistics(&items),
|
||||
items: items,
|
||||
ffmpegService: ffmpegService,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -43,16 +49,92 @@ func (l *queueLayout) GetQueueStatistics() QueueStatisticsAllContract {
|
||||
return l.queueAllStatistics
|
||||
}
|
||||
|
||||
func (l *queueLayout) AddQueue(key int, queue *convertor.Queue) {
|
||||
func (l *queueLayout) AddQueue(queueID int, queue *convertor.Queue) {
|
||||
|
||||
statusMessage := canvas.NewText(l.getStatusTitle(queue.Status), theme.Color(theme.ColorNamePrimary))
|
||||
messageError := canvas.NewText("", theme.Color(theme.ColorNameError))
|
||||
buttonPlay := widget.NewButtonWithIcon("", theme.Icon(theme.IconNameMediaPlay), func() {
|
||||
|
||||
})
|
||||
buttonPlay.Hide()
|
||||
blockMessageError := container.NewHScroll(messageError)
|
||||
blockMessageError.Hide()
|
||||
|
||||
content := container.NewVBox(
|
||||
container.NewHScroll(widget.NewLabel(queue.Setting.FileInput.Name)),
|
||||
container.NewHBox(
|
||||
buttonPlay,
|
||||
statusMessage,
|
||||
),
|
||||
blockMessageError,
|
||||
container.NewPadded(),
|
||||
canvas.NewLine(theme.Color(theme.ColorNameFocus)),
|
||||
container.NewPadded(),
|
||||
)
|
||||
|
||||
l.addQueueStatistics()
|
||||
if l.GetQueueStatistics().IsChecked(queue.Status) == false {
|
||||
content.Hide()
|
||||
}
|
||||
|
||||
l.items[queueID] = queueLayoutItem{
|
||||
CanvasObject: content,
|
||||
StatusMessage: statusMessage,
|
||||
BlockMessageError: blockMessageError,
|
||||
MessageError: messageError,
|
||||
buttonPlay: buttonPlay,
|
||||
status: queue.Status,
|
||||
}
|
||||
l.itemsContainer.Add(content)
|
||||
}
|
||||
|
||||
func (l *queueLayout) ChangeQueue(key int, queue *convertor.Queue) {
|
||||
l.changeQueueStatistics(queue.Status)
|
||||
func (l *queueLayout) ChangeQueue(queueID int, queue *convertor.Queue) {
|
||||
if item, ok := l.items[queueID]; ok {
|
||||
statusColor := l.getStatusColor(queue.Status)
|
||||
fyne.Do(func() {
|
||||
item.StatusMessage.Text = l.getStatusTitle(queue.Status)
|
||||
item.StatusMessage.Color = statusColor
|
||||
item.StatusMessage.Refresh()
|
||||
})
|
||||
if queue.Error != nil {
|
||||
fyne.Do(func() {
|
||||
item.MessageError.Text = queue.Error.Error()
|
||||
item.MessageError.Color = statusColor
|
||||
item.BlockMessageError.Show()
|
||||
item.MessageError.Refresh()
|
||||
})
|
||||
}
|
||||
if queue.Status == convertor.StatusType(convertor.Completed) {
|
||||
item.buttonPlay.Show()
|
||||
item.buttonPlay.OnTapped = func() {
|
||||
item.buttonPlay.Disable()
|
||||
go func() {
|
||||
ffplay, err := l.ffmpegService.GetFFplay()
|
||||
if err == nil {
|
||||
_ = ffplay.Play(&queue.Setting.FileOut)
|
||||
}
|
||||
fyne.Do(func() {
|
||||
item.buttonPlay.Enable()
|
||||
})
|
||||
}()
|
||||
}
|
||||
}
|
||||
if l.GetQueueStatistics().IsChecked(queue.Status) == false && item.CanvasObject.Visible() == true {
|
||||
item.CanvasObject.Hide()
|
||||
} else if item.CanvasObject.Visible() == false {
|
||||
item.CanvasObject.Show()
|
||||
}
|
||||
|
||||
l.changeQueueStatistics(queue.Status)
|
||||
}
|
||||
}
|
||||
|
||||
func (l *queueLayout) RemoveQueue(key int, status convertor.StatusContract) {
|
||||
l.removeQueueStatistics(status)
|
||||
func (l *queueLayout) RemoveQueue(queueID int, status convertor.StatusContract) {
|
||||
if item, ok := l.items[queueID]; ok {
|
||||
l.itemsContainer.Remove(item.CanvasObject)
|
||||
l.removeQueueStatistics(status)
|
||||
l.items[queueID] = queueLayoutItem{}
|
||||
}
|
||||
}
|
||||
|
||||
func (l *queueLayout) addQueueStatistics() {
|
||||
@@ -104,12 +186,30 @@ func (l *queueLayout) removeQueueStatistics(status convertor.StatusContract) {
|
||||
}
|
||||
}
|
||||
|
||||
func (l *queueLayout) getStatusTitle(status convertor.StatusContract) string {
|
||||
return lang.L(status.Name() + "Queue")
|
||||
}
|
||||
|
||||
func (l *queueLayout) getStatusColor(status convertor.StatusContract) color.Color {
|
||||
if status == convertor.StatusType(convertor.Error) {
|
||||
return theme.Color(theme.ColorNameError)
|
||||
}
|
||||
|
||||
if status == convertor.StatusType(convertor.Completed) {
|
||||
return color.RGBA{R: 49, G: 127, B: 114, A: 255}
|
||||
}
|
||||
|
||||
return theme.Color(theme.ColorNamePrimary)
|
||||
}
|
||||
|
||||
type QueueStatisticsAllContract interface {
|
||||
GetWaiting() QueueStatisticsContract
|
||||
GetInProgress() QueueStatisticsContract
|
||||
GetCompleted() QueueStatisticsContract
|
||||
GetError() QueueStatisticsContract
|
||||
GetTotal() QueueStatisticsContract
|
||||
|
||||
IsChecked(status convertor.StatusContract) bool
|
||||
}
|
||||
|
||||
type queueAllStatistics struct {
|
||||
@@ -203,6 +303,23 @@ func (s *queueAllStatistics) GetTotal() QueueStatisticsContract {
|
||||
return s.total
|
||||
}
|
||||
|
||||
func (s *queueAllStatistics) IsChecked(status convertor.StatusContract) bool {
|
||||
if status == convertor.StatusType(convertor.InProgress) {
|
||||
return s.inProgress.GetCheckbox().Checked
|
||||
}
|
||||
if status == convertor.StatusType(convertor.Completed) {
|
||||
return s.completed.GetCheckbox().Checked
|
||||
}
|
||||
if status == convertor.StatusType(convertor.Error) {
|
||||
return s.error.GetCheckbox().Checked
|
||||
}
|
||||
if status == convertor.StatusType(convertor.Waiting) {
|
||||
return s.waiting.GetCheckbox().Checked
|
||||
}
|
||||
|
||||
return true
|
||||
}
|
||||
|
||||
func (s *queueAllStatistics) redrawingQueueItems(queueItems *map[int]queueLayoutItem) {
|
||||
for _, item := range *queueItems {
|
||||
if s.isChecked(item.status) == true && item.CanvasObject.Visible() == false {
|
||||
|
Reference in New Issue
Block a user