Revive the right block of the program
Moved the right part of the program from the old version. Slightly reworked the structure.
This commit is contained in:
@@ -2,11 +2,14 @@ package window
|
||||
|
||||
import (
|
||||
"fyne.io/fyne/v2"
|
||||
"fyne.io/fyne/v2/canvas"
|
||||
"fyne.io/fyne/v2/container"
|
||||
"fyne.io/fyne/v2/dialog"
|
||||
"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"
|
||||
"git.kor-elf.net/kor-elf/gui-for-ffmpeg/internal/application/convertor"
|
||||
"git.kor-elf.net/kor-elf/gui-for-ffmpeg/internal/utils"
|
||||
)
|
||||
|
||||
@@ -20,22 +23,26 @@ type WindowContract interface {
|
||||
type mainWindow struct {
|
||||
fyneWindow fyne.Window
|
||||
layout *fyne.Container
|
||||
itemsToConvert convertor.ItemsToConvertContract
|
||||
progressBarService application.ProgressBarContract
|
||||
queueLayout QueueLayoutContract
|
||||
}
|
||||
|
||||
func NewMainWindow(fyneWindow fyne.Window, progressBarService application.ProgressBarContract) WindowContract {
|
||||
func NewMainWindow(fyneWindow fyne.Window, progressBarService application.ProgressBarContract, itemsToConvert convertor.ItemsToConvertContract, queueLayout QueueLayoutContract) WindowContract {
|
||||
fyneWindow.Resize(fyne.Size{Width: 1039, Height: 599})
|
||||
fyneWindow.CenterOnScreen()
|
||||
|
||||
return &mainWindow{
|
||||
fyneWindow: fyneWindow,
|
||||
progressBarService: progressBarService,
|
||||
itemsToConvert: itemsToConvert,
|
||||
queueLayout: queueLayout,
|
||||
}
|
||||
}
|
||||
|
||||
func (w *mainWindow) InitLayout() {
|
||||
fyne.Do(func() {
|
||||
rContainer := newRightContainer(w.progressBarService.GetContainer())
|
||||
rContainer := newRightContainer(w.progressBarService.GetContainer(), w.itemsToConvert, w.queueLayout)
|
||||
layout := container.NewAdaptiveGrid(2, widget.NewLabel(""), rContainer.GetCanvasObject())
|
||||
w.fyneWindow.SetContent(layout)
|
||||
|
||||
@@ -72,31 +79,20 @@ func (w *mainWindow) Show() {
|
||||
type RightMainContainerContract interface {
|
||||
GetCanvasObject() fyne.CanvasObject
|
||||
GetTabs() *container.AppTabs
|
||||
GetAddedFilesContainer() *fyne.Container
|
||||
GetFileQueueContainer() *fyne.Container
|
||||
SelectFileQueueTab()
|
||||
SelectAddedFilesTab()
|
||||
}
|
||||
|
||||
type rightMainContainer struct {
|
||||
container fyne.CanvasObject
|
||||
|
||||
tabs *container.AppTabs
|
||||
|
||||
addedFilesContainer *fyne.Container
|
||||
addedFilesTab *container.TabItem
|
||||
|
||||
fileQueueContainer *fyne.Container
|
||||
fileQueueTab *container.TabItem
|
||||
container fyne.CanvasObject
|
||||
tabs *container.AppTabs
|
||||
addedFilesTab *container.TabItem
|
||||
fileQueueTab *container.TabItem
|
||||
}
|
||||
|
||||
func newRightContainer(blockProgressbar *fyne.Container) RightMainContainerContract {
|
||||
|
||||
addedFilesContainer := container.NewVBox()
|
||||
addedFilesTab := container.NewTabItem(lang.L("addedFilesTitle"), addedFilesContainer)
|
||||
|
||||
fileQueueContainer := container.NewVBox()
|
||||
fileQueueTab := container.NewTabItem(lang.L("fileQueueTitle"), fileQueueContainer)
|
||||
func newRightContainer(blockProgressbar *fyne.Container, itemsToConvert convertor.ItemsToConvertContract, queueLayout QueueLayoutContract) RightMainContainerContract {
|
||||
addedFilesTab := container.NewTabItem(lang.L("addedFilesTitle"), addedFilesContainer(itemsToConvert))
|
||||
fileQueueTab := container.NewTabItem(lang.L("fileQueueTitle"), fileQueueContainer(queueLayout))
|
||||
|
||||
tabs := container.NewAppTabs(
|
||||
addedFilesTab,
|
||||
@@ -115,12 +111,10 @@ func newRightContainer(blockProgressbar *fyne.Container) RightMainContainerContr
|
||||
)
|
||||
|
||||
return &rightMainContainer{
|
||||
container: rightContainer,
|
||||
tabs: tabs,
|
||||
addedFilesContainer: addedFilesContainer,
|
||||
addedFilesTab: addedFilesTab,
|
||||
fileQueueContainer: fileQueueContainer,
|
||||
fileQueueTab: fileQueueTab,
|
||||
container: rightContainer,
|
||||
tabs: tabs,
|
||||
addedFilesTab: addedFilesTab,
|
||||
fileQueueTab: fileQueueTab,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -132,14 +126,6 @@ func (r *rightMainContainer) GetTabs() *container.AppTabs {
|
||||
return r.tabs
|
||||
}
|
||||
|
||||
func (r *rightMainContainer) GetAddedFilesContainer() *fyne.Container {
|
||||
return r.addedFilesContainer
|
||||
}
|
||||
|
||||
func (r *rightMainContainer) GetFileQueueContainer() *fyne.Container {
|
||||
return r.fileQueueContainer
|
||||
}
|
||||
|
||||
func (r *rightMainContainer) SelectFileQueueTab() {
|
||||
fyne.Do(func() {
|
||||
r.tabs.Select(r.fileQueueTab)
|
||||
@@ -151,3 +137,55 @@ func (r *rightMainContainer) SelectAddedFilesTab() {
|
||||
r.tabs.Select(r.addedFilesTab)
|
||||
})
|
||||
}
|
||||
|
||||
func addedFilesContainer(itemsToConvert convertor.ItemsToConvertContract) *fyne.Container {
|
||||
line := canvas.NewLine(theme.Color(theme.ColorNameFocus))
|
||||
line.StrokeWidth = 5
|
||||
checkboxAutoRemove := widget.NewCheck(
|
||||
lang.L("autoClearAfterAddingToQueue"),
|
||||
func(checked bool) {
|
||||
itemsToConvert.SetIsAutoRemove(checked)
|
||||
},
|
||||
)
|
||||
checkboxAutoRemove.SetChecked(itemsToConvert.GetIsAutoRemove())
|
||||
|
||||
buttonClear := widget.NewButton(
|
||||
lang.L("clearAll"),
|
||||
func() {
|
||||
itemsToConvert.Clear()
|
||||
},
|
||||
)
|
||||
buttonClear.Importance = widget.DangerImportance
|
||||
return container.NewVBox(
|
||||
container.NewPadded(),
|
||||
container.NewBorder(nil, nil, nil, buttonClear, container.NewHScroll(checkboxAutoRemove)),
|
||||
container.NewPadded(),
|
||||
line,
|
||||
container.NewPadded(),
|
||||
itemsToConvert.GetItemsContainer(),
|
||||
)
|
||||
}
|
||||
|
||||
func fileQueueContainer(queueLayout QueueLayoutContract) *fyne.Container {
|
||||
title := widget.NewLabel(lang.L("queue"))
|
||||
title.TextStyle.Bold = true
|
||||
|
||||
line := canvas.NewLine(theme.Color(theme.ColorNameFocus))
|
||||
line.StrokeWidth = 5
|
||||
|
||||
queueLayout.GetQueueStatistics().GetWaiting().SetTitle(lang.L("waitingQueue"))
|
||||
queueLayout.GetQueueStatistics().GetInProgress().SetTitle(lang.L("inProgressQueue"))
|
||||
queueLayout.GetQueueStatistics().GetCompleted().SetTitle(lang.L("completedQueue"))
|
||||
queueLayout.GetQueueStatistics().GetError().SetTitle(lang.L("errorQueue"))
|
||||
queueLayout.GetQueueStatistics().GetTotal().SetTitle(lang.L("total"))
|
||||
|
||||
return container.NewVBox(
|
||||
container.NewPadded(),
|
||||
container.NewHBox(title, queueLayout.GetQueueStatistics().GetCompleted().GetCheckbox(), queueLayout.GetQueueStatistics().GetError().GetCheckbox()),
|
||||
container.NewHBox(queueLayout.GetQueueStatistics().GetInProgress().GetCheckbox(), queueLayout.GetQueueStatistics().GetWaiting().GetCheckbox(), queueLayout.GetQueueStatistics().GetTotal().GetCheckbox()),
|
||||
container.NewPadded(),
|
||||
line,
|
||||
container.NewPadded(),
|
||||
queueLayout.GetItemsContainer(),
|
||||
)
|
||||
}
|
||||
|
357
internal/gui/window/queue.go
Normal file
357
internal/gui/window/queue.go
Normal file
@@ -0,0 +1,357 @@
|
||||
package window
|
||||
|
||||
import (
|
||||
"fyne.io/fyne/v2"
|
||||
"fyne.io/fyne/v2/canvas"
|
||||
"fyne.io/fyne/v2/container"
|
||||
"fyne.io/fyne/v2/widget"
|
||||
"git.kor-elf.net/kor-elf/gui-for-ffmpeg/internal/application/convertor"
|
||||
"strconv"
|
||||
"strings"
|
||||
)
|
||||
|
||||
type QueueLayoutContract interface {
|
||||
GetItemsContainer() *fyne.Container
|
||||
GetQueueStatistics() QueueStatisticsAllContract
|
||||
|
||||
AddQueue(key int, queue *convertor.Queue)
|
||||
ChangeQueue(key int, queue *convertor.Queue)
|
||||
RemoveQueue(key int, status convertor.StatusContract)
|
||||
}
|
||||
|
||||
type queueLayout struct {
|
||||
itemsContainer *fyne.Container
|
||||
queueAllStatistics QueueStatisticsAllContract
|
||||
items map[int]queueLayoutItem
|
||||
}
|
||||
|
||||
func NewQueueLayout() QueueLayoutContract {
|
||||
items := map[int]queueLayoutItem{}
|
||||
|
||||
return &queueLayout{
|
||||
itemsContainer: container.NewVBox(),
|
||||
queueAllStatistics: newQueueAllStatistics(&items),
|
||||
items: items,
|
||||
}
|
||||
}
|
||||
|
||||
func (l *queueLayout) GetItemsContainer() *fyne.Container {
|
||||
return l.itemsContainer
|
||||
}
|
||||
|
||||
func (l *queueLayout) GetQueueStatistics() QueueStatisticsAllContract {
|
||||
return l.queueAllStatistics
|
||||
}
|
||||
|
||||
func (l *queueLayout) AddQueue(key int, queue *convertor.Queue) {
|
||||
l.addQueueStatistics()
|
||||
}
|
||||
|
||||
func (l *queueLayout) ChangeQueue(key int, queue *convertor.Queue) {
|
||||
l.changeQueueStatistics(queue.Status)
|
||||
}
|
||||
|
||||
func (l *queueLayout) RemoveQueue(key int, status convertor.StatusContract) {
|
||||
l.removeQueueStatistics(status)
|
||||
}
|
||||
|
||||
func (l *queueLayout) addQueueStatistics() {
|
||||
l.GetQueueStatistics().GetWaiting().Add()
|
||||
l.GetQueueStatistics().GetTotal().Add()
|
||||
}
|
||||
|
||||
func (l *queueLayout) changeQueueStatistics(status convertor.StatusContract) {
|
||||
if status == convertor.StatusType(convertor.InProgress) {
|
||||
l.GetQueueStatistics().GetWaiting().Remove()
|
||||
l.GetQueueStatistics().GetInProgress().Add()
|
||||
return
|
||||
}
|
||||
|
||||
if status == convertor.StatusType(convertor.Completed) {
|
||||
l.GetQueueStatistics().GetInProgress().Remove()
|
||||
l.GetQueueStatistics().GetCompleted().Add()
|
||||
return
|
||||
}
|
||||
|
||||
if status == convertor.StatusType(convertor.Error) {
|
||||
l.GetQueueStatistics().GetInProgress().Remove()
|
||||
l.GetQueueStatistics().GetError().Add()
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
func (l *queueLayout) removeQueueStatistics(status convertor.StatusContract) {
|
||||
l.GetQueueStatistics().GetTotal().Remove()
|
||||
|
||||
if status == convertor.StatusType(convertor.Completed) {
|
||||
l.GetQueueStatistics().GetCompleted().Remove()
|
||||
return
|
||||
}
|
||||
|
||||
if status == convertor.StatusType(convertor.Error) {
|
||||
l.GetQueueStatistics().GetError().Remove()
|
||||
return
|
||||
}
|
||||
|
||||
if status == convertor.StatusType(convertor.InProgress) {
|
||||
l.GetQueueStatistics().GetInProgress().Remove()
|
||||
return
|
||||
}
|
||||
|
||||
if status == convertor.StatusType(convertor.Waiting) {
|
||||
l.GetQueueStatistics().GetWaiting().Remove()
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
type QueueStatisticsAllContract interface {
|
||||
GetWaiting() QueueStatisticsContract
|
||||
GetInProgress() QueueStatisticsContract
|
||||
GetCompleted() QueueStatisticsContract
|
||||
GetError() QueueStatisticsContract
|
||||
GetTotal() QueueStatisticsContract
|
||||
}
|
||||
|
||||
type queueAllStatistics struct {
|
||||
waiting QueueStatisticsContract
|
||||
inProgress QueueStatisticsContract
|
||||
completed QueueStatisticsContract
|
||||
error QueueStatisticsContract
|
||||
total QueueStatisticsContract
|
||||
}
|
||||
|
||||
func newQueueAllStatistics(queueItems *map[int]queueLayoutItem) QueueStatisticsAllContract {
|
||||
checkboxWaiting := newQueueStatistics()
|
||||
checkboxInProgress := newQueueStatistics()
|
||||
checkboxCompleted := newQueueStatistics()
|
||||
checkboxError := newQueueStatistics()
|
||||
CheckboxTotal := newQueueStatistics()
|
||||
|
||||
queueAllStatistics := &queueAllStatistics{
|
||||
waiting: checkboxWaiting,
|
||||
inProgress: checkboxInProgress,
|
||||
completed: checkboxCompleted,
|
||||
error: checkboxError,
|
||||
total: CheckboxTotal,
|
||||
}
|
||||
|
||||
CheckboxTotal.GetCheckbox().OnChanged = func(b bool) {
|
||||
if b == true {
|
||||
queueAllStatistics.allCheckboxChecked()
|
||||
} else {
|
||||
queueAllStatistics.allUnCheckboxChecked()
|
||||
}
|
||||
queueAllStatistics.redrawingQueueItems(queueItems)
|
||||
}
|
||||
|
||||
checkboxWaiting.GetCheckbox().OnChanged = func(b bool) {
|
||||
if b == true {
|
||||
queueAllStatistics.checkboxChecked()
|
||||
} else {
|
||||
queueAllStatistics.unCheckboxChecked()
|
||||
}
|
||||
queueAllStatistics.redrawingQueueItems(queueItems)
|
||||
}
|
||||
|
||||
checkboxInProgress.GetCheckbox().OnChanged = func(b bool) {
|
||||
if b == true {
|
||||
queueAllStatistics.checkboxChecked()
|
||||
} else {
|
||||
queueAllStatistics.unCheckboxChecked()
|
||||
}
|
||||
queueAllStatistics.redrawingQueueItems(queueItems)
|
||||
}
|
||||
|
||||
checkboxCompleted.GetCheckbox().OnChanged = func(b bool) {
|
||||
if b == true {
|
||||
queueAllStatistics.checkboxChecked()
|
||||
} else {
|
||||
queueAllStatistics.unCheckboxChecked()
|
||||
}
|
||||
queueAllStatistics.redrawingQueueItems(queueItems)
|
||||
}
|
||||
|
||||
checkboxError.GetCheckbox().OnChanged = func(b bool) {
|
||||
if b == true {
|
||||
queueAllStatistics.checkboxChecked()
|
||||
} else {
|
||||
queueAllStatistics.unCheckboxChecked()
|
||||
}
|
||||
queueAllStatistics.redrawingQueueItems(queueItems)
|
||||
}
|
||||
|
||||
return queueAllStatistics
|
||||
}
|
||||
|
||||
func (s *queueAllStatistics) GetWaiting() QueueStatisticsContract {
|
||||
return s.waiting
|
||||
}
|
||||
|
||||
func (s *queueAllStatistics) GetInProgress() QueueStatisticsContract {
|
||||
return s.inProgress
|
||||
}
|
||||
|
||||
func (s *queueAllStatistics) GetCompleted() QueueStatisticsContract {
|
||||
return s.completed
|
||||
}
|
||||
|
||||
func (s *queueAllStatistics) GetError() QueueStatisticsContract {
|
||||
return s.error
|
||||
}
|
||||
|
||||
func (s *queueAllStatistics) GetTotal() QueueStatisticsContract {
|
||||
return s.total
|
||||
}
|
||||
|
||||
func (s *queueAllStatistics) redrawingQueueItems(queueItems *map[int]queueLayoutItem) {
|
||||
for _, item := range *queueItems {
|
||||
if s.isChecked(item.status) == true && item.CanvasObject.Visible() == false {
|
||||
item.CanvasObject.Show()
|
||||
continue
|
||||
}
|
||||
if s.isChecked(item.status) == false && item.CanvasObject.Visible() == true {
|
||||
item.CanvasObject.Hide()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
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) checkboxChecked() {
|
||||
if s.total.GetCheckbox().Checked == true {
|
||||
return
|
||||
}
|
||||
|
||||
if s.waiting.GetCheckbox().Checked == false {
|
||||
return
|
||||
}
|
||||
|
||||
if s.inProgress.GetCheckbox().Checked == false {
|
||||
return
|
||||
}
|
||||
|
||||
if s.completed.GetCheckbox().Checked == false {
|
||||
return
|
||||
}
|
||||
|
||||
if s.error.GetCheckbox().Checked == false {
|
||||
return
|
||||
}
|
||||
|
||||
s.total.GetCheckbox().Checked = true
|
||||
s.total.GetCheckbox().Refresh()
|
||||
}
|
||||
|
||||
func (s *queueAllStatistics) unCheckboxChecked() {
|
||||
if s.total.GetCheckbox().Checked == false {
|
||||
return
|
||||
}
|
||||
|
||||
s.total.GetCheckbox().Checked = false
|
||||
s.total.GetCheckbox().Refresh()
|
||||
}
|
||||
|
||||
func (s *queueAllStatistics) allCheckboxChecked() {
|
||||
s.waiting.GetCheckbox().Checked = true
|
||||
s.waiting.GetCheckbox().Refresh()
|
||||
|
||||
s.inProgress.GetCheckbox().Checked = true
|
||||
s.inProgress.GetCheckbox().Refresh()
|
||||
|
||||
s.completed.GetCheckbox().Checked = true
|
||||
s.completed.GetCheckbox().Refresh()
|
||||
|
||||
s.error.GetCheckbox().Checked = true
|
||||
s.error.GetCheckbox().Refresh()
|
||||
}
|
||||
|
||||
func (s *queueAllStatistics) allUnCheckboxChecked() {
|
||||
s.waiting.GetCheckbox().Checked = false
|
||||
s.waiting.GetCheckbox().Refresh()
|
||||
|
||||
s.inProgress.GetCheckbox().Checked = false
|
||||
s.inProgress.GetCheckbox().Refresh()
|
||||
|
||||
s.completed.GetCheckbox().Checked = false
|
||||
s.completed.GetCheckbox().Refresh()
|
||||
|
||||
s.error.GetCheckbox().Checked = false
|
||||
s.error.GetCheckbox().Refresh()
|
||||
}
|
||||
|
||||
type QueueStatisticsContract interface {
|
||||
SetTitle(title string)
|
||||
GetCheckbox() *widget.Check
|
||||
Add()
|
||||
Remove()
|
||||
}
|
||||
|
||||
type queueStatistics struct {
|
||||
checkbox *widget.Check
|
||||
title string
|
||||
count int64
|
||||
}
|
||||
|
||||
func newQueueStatistics() QueueStatisticsContract {
|
||||
checkbox := widget.NewCheck(": 0", nil)
|
||||
checkbox.Checked = true
|
||||
|
||||
return &queueStatistics{
|
||||
checkbox: checkbox,
|
||||
title: "",
|
||||
count: 0,
|
||||
}
|
||||
}
|
||||
|
||||
func (s *queueStatistics) SetTitle(title string) {
|
||||
s.title = strings.ToLower(title)
|
||||
s.checkbox.Text = title + ": " + strconv.FormatInt(s.count, 10)
|
||||
}
|
||||
|
||||
func (s *queueStatistics) GetCheckbox() *widget.Check {
|
||||
return s.checkbox
|
||||
}
|
||||
|
||||
func (s *queueStatistics) Add() {
|
||||
s.count += 1
|
||||
s.formatText()
|
||||
}
|
||||
|
||||
func (s *queueStatistics) Remove() {
|
||||
if s.count == 0 {
|
||||
return
|
||||
}
|
||||
s.count -= 1
|
||||
s.formatText()
|
||||
}
|
||||
|
||||
func (s *queueStatistics) formatText() {
|
||||
fyne.Do(func() {
|
||||
s.checkbox.Text = s.title + ": " + strconv.FormatInt(s.count, 10)
|
||||
s.checkbox.Refresh()
|
||||
})
|
||||
}
|
||||
|
||||
type queueLayoutItem struct {
|
||||
CanvasObject fyne.CanvasObject
|
||||
BlockMessageError *container.Scroll
|
||||
StatusMessage *canvas.Text
|
||||
MessageError *canvas.Text
|
||||
buttonPlay *widget.Button
|
||||
status convertor.StatusContract
|
||||
}
|
Reference in New Issue
Block a user