Moved the right part of the program from the old version. Slightly reworked the structure.
192 lines
5.5 KiB
Go
192 lines
5.5 KiB
Go
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"
|
|
)
|
|
|
|
type WindowContract interface {
|
|
SetContent(content fyne.CanvasObject)
|
|
Show()
|
|
InitLayout()
|
|
NewFileOpen(callback func(fyne.URIReadCloser, error), location fyne.ListableURI) *dialog.FileDialog
|
|
}
|
|
|
|
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, 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(), w.itemsToConvert, w.queueLayout)
|
|
layout := container.NewAdaptiveGrid(2, widget.NewLabel(""), rContainer.GetCanvasObject())
|
|
w.fyneWindow.SetContent(layout)
|
|
|
|
w.layout = layout
|
|
})
|
|
}
|
|
|
|
func (w *mainWindow) NewFileOpen(callback func(fyne.URIReadCloser, error), location fyne.ListableURI) *dialog.FileDialog {
|
|
fileDialog := dialog.NewFileOpen(callback, w.fyneWindow)
|
|
utils.FileDialogResize(fileDialog, w.fyneWindow)
|
|
fileDialog.Show()
|
|
if location != nil {
|
|
fileDialog.SetLocation(location)
|
|
}
|
|
return fileDialog
|
|
}
|
|
|
|
func (w *mainWindow) SetContent(content fyne.CanvasObject) {
|
|
fyne.Do(func() {
|
|
if w.layout == nil {
|
|
w.fyneWindow.SetContent(content)
|
|
return
|
|
}
|
|
|
|
w.layout.Objects[0] = content
|
|
w.fyneWindow.SetContent(w.layout)
|
|
})
|
|
}
|
|
|
|
func (w *mainWindow) Show() {
|
|
w.fyneWindow.Show()
|
|
}
|
|
|
|
type RightMainContainerContract interface {
|
|
GetCanvasObject() fyne.CanvasObject
|
|
GetTabs() *container.AppTabs
|
|
SelectFileQueueTab()
|
|
SelectAddedFilesTab()
|
|
}
|
|
|
|
type rightMainContainer struct {
|
|
container fyne.CanvasObject
|
|
tabs *container.AppTabs
|
|
addedFilesTab *container.TabItem
|
|
fileQueueTab *container.TabItem
|
|
}
|
|
|
|
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,
|
|
fileQueueTab,
|
|
)
|
|
|
|
rightContainer := container.NewBorder(
|
|
container.NewVBox(
|
|
blockProgressbar,
|
|
widget.NewSeparator(),
|
|
),
|
|
nil,
|
|
nil,
|
|
nil,
|
|
tabs,
|
|
)
|
|
|
|
return &rightMainContainer{
|
|
container: rightContainer,
|
|
tabs: tabs,
|
|
addedFilesTab: addedFilesTab,
|
|
fileQueueTab: fileQueueTab,
|
|
}
|
|
}
|
|
|
|
func (r *rightMainContainer) GetCanvasObject() fyne.CanvasObject {
|
|
return r.container
|
|
}
|
|
|
|
func (r *rightMainContainer) GetTabs() *container.AppTabs {
|
|
return r.tabs
|
|
}
|
|
|
|
func (r *rightMainContainer) SelectFileQueueTab() {
|
|
fyne.Do(func() {
|
|
r.tabs.Select(r.fileQueueTab)
|
|
})
|
|
}
|
|
|
|
func (r *rightMainContainer) SelectAddedFilesTab() {
|
|
fyne.Do(func() {
|
|
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(),
|
|
)
|
|
}
|