Make it possible to drag and drop multiple files
It is now possible to add multiple files before sending them to the processing queue.
This commit is contained in:
185
kernel/layout.go
185
kernel/layout.go
@@ -1,8 +1,6 @@
|
||||
package kernel
|
||||
|
||||
import (
|
||||
"bufio"
|
||||
"errors"
|
||||
"fyne.io/fyne/v2"
|
||||
"fyne.io/fyne/v2/canvas"
|
||||
"fyne.io/fyne/v2/container"
|
||||
@@ -10,31 +8,31 @@ import (
|
||||
"fyne.io/fyne/v2/widget"
|
||||
"github.com/nicksnyder/go-i18n/v2/i18n"
|
||||
"image/color"
|
||||
"io"
|
||||
"regexp"
|
||||
"strconv"
|
||||
"strings"
|
||||
)
|
||||
|
||||
type LayoutContract interface {
|
||||
SetContent(content fyne.CanvasObject) *fyne.Container
|
||||
NewProgressbar(queueId int, totalDuration float64) ProgressContract
|
||||
ChangeQueueStatus(queueId int, queue *Queue)
|
||||
GetRightTabs() RightTabsContract
|
||||
}
|
||||
|
||||
type Layout struct {
|
||||
layout *fyne.Container
|
||||
queueLayoutObject QueueLayoutObjectContract
|
||||
localizerService LocalizerContract
|
||||
rightTabsService RightTabsContract
|
||||
}
|
||||
|
||||
func NewLayout(queueLayoutObject QueueLayoutObjectContract, localizerService LocalizerContract) *Layout {
|
||||
layout := container.NewAdaptiveGrid(2, widget.NewLabel(""), container.NewVScroll(queueLayoutObject.GetCanvasObject()))
|
||||
func NewLayout(queueLayoutObject QueueLayoutObjectContract, localizerService LocalizerContract, rightTabsService RightTabsContract) *Layout {
|
||||
layout := container.NewAdaptiveGrid(2, widget.NewLabel(""), queueLayoutObject.GetCanvasObject())
|
||||
|
||||
return &Layout{
|
||||
layout: layout,
|
||||
queueLayoutObject: queueLayoutObject,
|
||||
localizerService: localizerService,
|
||||
rightTabsService: rightTabsService,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -43,18 +41,16 @@ func (l Layout) SetContent(content fyne.CanvasObject) *fyne.Container {
|
||||
return l.layout
|
||||
}
|
||||
|
||||
func (l Layout) NewProgressbar(queueId int, totalDuration float64) ProgressContract {
|
||||
progressbar := l.queueLayoutObject.GetProgressbar(queueId)
|
||||
return NewProgress(totalDuration, progressbar, l.localizerService)
|
||||
}
|
||||
|
||||
func (l Layout) ChangeQueueStatus(queueId int, queue *Queue) {
|
||||
l.queueLayoutObject.ChangeQueueStatus(queueId, queue)
|
||||
}
|
||||
|
||||
func (l Layout) GetRightTabs() RightTabsContract {
|
||||
return l.rightTabsService
|
||||
}
|
||||
|
||||
type QueueLayoutObjectContract interface {
|
||||
GetCanvasObject() fyne.CanvasObject
|
||||
GetProgressbar(queueId int) *widget.ProgressBar
|
||||
ChangeQueueStatus(queueId int, queue *Queue)
|
||||
}
|
||||
|
||||
@@ -63,6 +59,7 @@ type QueueLayoutObject struct {
|
||||
|
||||
queue QueueListContract
|
||||
container *fyne.Container
|
||||
containerItems *fyne.Container
|
||||
items map[int]QueueLayoutItem
|
||||
localizerService LocalizerContract
|
||||
queueStatisticsFormat *queueStatisticsFormat
|
||||
@@ -70,16 +67,16 @@ type QueueLayoutObject struct {
|
||||
}
|
||||
|
||||
type QueueLayoutItem struct {
|
||||
CanvasObject fyne.CanvasObject
|
||||
ProgressBar *widget.ProgressBar
|
||||
StatusMessage *canvas.Text
|
||||
MessageError *canvas.Text
|
||||
buttonPlay *widget.Button
|
||||
CanvasObject fyne.CanvasObject
|
||||
BlockMessageError *container.Scroll
|
||||
StatusMessage *canvas.Text
|
||||
MessageError *canvas.Text
|
||||
buttonPlay *widget.Button
|
||||
|
||||
status *StatusContract
|
||||
}
|
||||
|
||||
func NewQueueLayoutObject(queue QueueListContract, localizerService LocalizerContract, ffplayService FFplayContract) *QueueLayoutObject {
|
||||
func NewQueueLayoutObject(queue QueueListContract, localizerService LocalizerContract, ffplayService FFplayContract, rightTabsService RightTabsContract, blockProgressbar *fyne.Container) *QueueLayoutObject {
|
||||
title := widget.NewLabel(localizerService.GetMessage(&i18n.LocalizeConfig{MessageID: "queue"}))
|
||||
title.TextStyle.Bold = true
|
||||
|
||||
@@ -91,12 +88,27 @@ func NewQueueLayoutObject(queue QueueListContract, localizerService LocalizerCon
|
||||
items := map[int]QueueLayoutItem{}
|
||||
queueStatisticsFormat := newQueueStatisticsFormat(localizerService, &items)
|
||||
|
||||
line := canvas.NewLine(theme.Color(theme.ColorNameFocus))
|
||||
line.StrokeWidth = 5
|
||||
|
||||
rightTabsService.GetFileQueueContainer().Add(container.NewVBox(
|
||||
container.NewPadded(),
|
||||
container.NewHBox(title, queueStatisticsFormat.completed.widget, queueStatisticsFormat.error.widget),
|
||||
container.NewHBox(queueStatisticsFormat.inProgress.widget, queueStatisticsFormat.waiting.widget, queueStatisticsFormat.total.widget),
|
||||
container.NewPadded(),
|
||||
line,
|
||||
container.NewPadded(),
|
||||
))
|
||||
queueLayoutObject := &QueueLayoutObject{
|
||||
queue: queue,
|
||||
container: container.NewVBox(
|
||||
container.NewHBox(title, queueStatisticsFormat.completed.widget, queueStatisticsFormat.error.widget),
|
||||
container.NewHBox(queueStatisticsFormat.inProgress.widget, queueStatisticsFormat.waiting.widget, queueStatisticsFormat.total.widget),
|
||||
container: container.NewBorder(
|
||||
container.NewVBox(
|
||||
blockProgressbar,
|
||||
widget.NewSeparator(),
|
||||
),
|
||||
nil, nil, nil, container.NewVScroll(rightTabsService.GetTabs()),
|
||||
),
|
||||
containerItems: rightTabsService.GetFileQueueContainer(),
|
||||
items: items,
|
||||
localizerService: localizerService,
|
||||
queueStatisticsFormat: queueStatisticsFormat,
|
||||
@@ -112,31 +124,24 @@ func (o QueueLayoutObject) GetCanvasObject() fyne.CanvasObject {
|
||||
return o.container
|
||||
}
|
||||
|
||||
func (o QueueLayoutObject) GetProgressbar(queueId int) *widget.ProgressBar {
|
||||
if item, ok := o.items[queueId]; ok {
|
||||
return item.ProgressBar
|
||||
}
|
||||
return widget.NewProgressBar()
|
||||
}
|
||||
|
||||
func (o QueueLayoutObject) Add(id int, queue *Queue) {
|
||||
progressBar := widget.NewProgressBar()
|
||||
|
||||
statusMessage := canvas.NewText(o.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.VideoFileInput.Name)),
|
||||
progressBar,
|
||||
container.NewHScroll(container.NewHBox(
|
||||
container.NewHBox(
|
||||
buttonPlay,
|
||||
statusMessage,
|
||||
)),
|
||||
container.NewHScroll(messageError),
|
||||
),
|
||||
blockMessageError,
|
||||
container.NewPadded(),
|
||||
canvas.NewLine(theme.Color(theme.ColorNameFocus)),
|
||||
container.NewPadded(),
|
||||
)
|
||||
@@ -147,14 +152,14 @@ func (o QueueLayoutObject) Add(id int, queue *Queue) {
|
||||
}
|
||||
|
||||
o.items[id] = QueueLayoutItem{
|
||||
CanvasObject: content,
|
||||
ProgressBar: progressBar,
|
||||
StatusMessage: statusMessage,
|
||||
MessageError: messageError,
|
||||
buttonPlay: buttonPlay,
|
||||
status: &queue.Status,
|
||||
CanvasObject: content,
|
||||
StatusMessage: statusMessage,
|
||||
BlockMessageError: blockMessageError,
|
||||
MessageError: messageError,
|
||||
buttonPlay: buttonPlay,
|
||||
status: &queue.Status,
|
||||
}
|
||||
o.container.Add(content)
|
||||
o.containerItems.Add(content)
|
||||
}
|
||||
|
||||
func (o QueueLayoutObject) Remove(id int) {
|
||||
@@ -177,6 +182,7 @@ func (o QueueLayoutObject) ChangeQueueStatus(queueId int, queue *Queue) {
|
||||
item.MessageError.Text = queue.Error.Error()
|
||||
item.MessageError.Color = statusColor
|
||||
fyne.Do(func() {
|
||||
item.BlockMessageError.Show()
|
||||
item.MessageError.Refresh()
|
||||
})
|
||||
}
|
||||
@@ -219,101 +225,6 @@ func (o QueueLayoutObject) getStatusTitle(status StatusContract) string {
|
||||
return o.localizerService.GetMessage(&i18n.LocalizeConfig{MessageID: status.Name() + "Queue"})
|
||||
}
|
||||
|
||||
type Progress struct {
|
||||
totalDuration float64
|
||||
progressbar *widget.ProgressBar
|
||||
protocol string
|
||||
localizerService LocalizerContract
|
||||
}
|
||||
|
||||
func NewProgress(totalDuration float64, progressbar *widget.ProgressBar, localizerService LocalizerContract) Progress {
|
||||
return Progress{
|
||||
totalDuration: totalDuration,
|
||||
progressbar: progressbar,
|
||||
protocol: "pipe:",
|
||||
localizerService: localizerService,
|
||||
}
|
||||
}
|
||||
|
||||
func (p Progress) GetProtocole() string {
|
||||
return p.protocol
|
||||
}
|
||||
|
||||
func (p Progress) Run(stdOut io.ReadCloser, stdErr io.ReadCloser) error {
|
||||
isProcessCompleted := false
|
||||
var errorText string
|
||||
|
||||
p.progressbar.Value = 0
|
||||
p.progressbar.Max = p.totalDuration
|
||||
fyne.Do(func() {
|
||||
p.progressbar.Refresh()
|
||||
})
|
||||
progress := 0.0
|
||||
|
||||
go func() {
|
||||
scannerErr := bufio.NewReader(stdErr)
|
||||
for {
|
||||
line, _, err := scannerErr.ReadLine()
|
||||
if err != nil {
|
||||
if err == io.EOF {
|
||||
break
|
||||
}
|
||||
continue
|
||||
}
|
||||
data := strings.TrimSpace(string(line))
|
||||
errorText = data
|
||||
}
|
||||
}()
|
||||
|
||||
scannerOut := bufio.NewReader(stdOut)
|
||||
for {
|
||||
line, _, err := scannerOut.ReadLine()
|
||||
if err != nil {
|
||||
if err == io.EOF {
|
||||
break
|
||||
}
|
||||
continue
|
||||
}
|
||||
data := strings.TrimSpace(string(line))
|
||||
if strings.Contains(data, "progress=end") {
|
||||
p.progressbar.Value = p.totalDuration
|
||||
fyne.Do(func() {
|
||||
p.progressbar.Refresh()
|
||||
})
|
||||
isProcessCompleted = true
|
||||
break
|
||||
}
|
||||
|
||||
re := regexp.MustCompile(`frame=(\d+)`)
|
||||
a := re.FindAllStringSubmatch(data, -1)
|
||||
|
||||
if len(a) > 0 && len(a[len(a)-1]) > 0 {
|
||||
c, err := strconv.Atoi(a[len(a)-1][len(a[len(a)-1])-1])
|
||||
if err != nil {
|
||||
continue
|
||||
}
|
||||
progress = float64(c)
|
||||
}
|
||||
if p.progressbar.Value != progress {
|
||||
p.progressbar.Value = progress
|
||||
fyne.Do(func() {
|
||||
p.progressbar.Refresh()
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
if isProcessCompleted == false {
|
||||
if len(errorText) == 0 {
|
||||
errorText = p.localizerService.GetMessage(&i18n.LocalizeConfig{
|
||||
MessageID: "errorConverter",
|
||||
})
|
||||
}
|
||||
return errors.New(errorText)
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
type queueStatistics struct {
|
||||
widget *widget.Check
|
||||
title string
|
||||
|
||||
Reference in New Issue
Block a user