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:
parent
c60b9f7b0c
commit
57637606c0
@ -2,6 +2,7 @@ package application
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"fyne.io/fyne/v2"
|
"fyne.io/fyne/v2"
|
||||||
|
"git.kor-elf.net/kor-elf/gui-for-ffmpeg/internal/application/convertor"
|
||||||
"git.kor-elf.net/kor-elf/gui-for-ffmpeg/internal/application/setting"
|
"git.kor-elf.net/kor-elf/gui-for-ffmpeg/internal/application/setting"
|
||||||
"git.kor-elf.net/kor-elf/gui-for-ffmpeg/internal/ffmpeg"
|
"git.kor-elf.net/kor-elf/gui-for-ffmpeg/internal/ffmpeg"
|
||||||
)
|
)
|
||||||
@ -11,6 +12,8 @@ type AppContract interface {
|
|||||||
GetSetting() setting.SettingContract
|
GetSetting() setting.SettingContract
|
||||||
GetProgressBarService() ProgressBarContract
|
GetProgressBarService() ProgressBarContract
|
||||||
GetFFmpegService() ffmpeg.UtilitiesContract
|
GetFFmpegService() ffmpeg.UtilitiesContract
|
||||||
|
GetItemsToConvert() convertor.ItemsToConvertContract
|
||||||
|
GetQueueService() convertor.QueueListContract
|
||||||
Run()
|
Run()
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -19,14 +22,25 @@ type application struct {
|
|||||||
setting setting.SettingContract
|
setting setting.SettingContract
|
||||||
progressBarService ProgressBarContract
|
progressBarService ProgressBarContract
|
||||||
ffmpegService ffmpeg.UtilitiesContract
|
ffmpegService ffmpeg.UtilitiesContract
|
||||||
|
itemsToConvert convertor.ItemsToConvertContract
|
||||||
|
queueService convertor.QueueListContract
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewApp(fyneApp fyne.App, setting setting.SettingContract, progressBarService ProgressBarContract, ffmpegService ffmpeg.UtilitiesContract) AppContract {
|
func NewApp(
|
||||||
|
fyneApp fyne.App,
|
||||||
|
setting setting.SettingContract,
|
||||||
|
progressBarService ProgressBarContract,
|
||||||
|
ffmpegService ffmpeg.UtilitiesContract,
|
||||||
|
itemsToConvert convertor.ItemsToConvertContract,
|
||||||
|
queueService convertor.QueueListContract,
|
||||||
|
) AppContract {
|
||||||
return &application{
|
return &application{
|
||||||
fyneApp: fyneApp,
|
fyneApp: fyneApp,
|
||||||
setting: setting,
|
setting: setting,
|
||||||
progressBarService: progressBarService,
|
progressBarService: progressBarService,
|
||||||
ffmpegService: ffmpegService,
|
ffmpegService: ffmpegService,
|
||||||
|
itemsToConvert: itemsToConvert,
|
||||||
|
queueService: queueService,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -46,6 +60,14 @@ func (a *application) GetFFmpegService() ffmpeg.UtilitiesContract {
|
|||||||
return a.ffmpegService
|
return a.ffmpegService
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (a *application) GetItemsToConvert() convertor.ItemsToConvertContract {
|
||||||
|
return a.itemsToConvert
|
||||||
|
}
|
||||||
|
|
||||||
|
func (a *application) GetQueueService() convertor.QueueListContract {
|
||||||
|
return a.queueService
|
||||||
|
}
|
||||||
|
|
||||||
func (a *application) Run() {
|
func (a *application) Run() {
|
||||||
a.fyneApp.Run()
|
a.fyneApp.Run()
|
||||||
}
|
}
|
||||||
|
133
internal/application/convertor/items_to_convert.go
Normal file
133
internal/application/convertor/items_to_convert.go
Normal file
@ -0,0 +1,133 @@
|
|||||||
|
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
|
||||||
|
}
|
148
internal/application/convertor/queue.go
Normal file
148
internal/application/convertor/queue.go
Normal file
@ -0,0 +1,148 @@
|
|||||||
|
package convertor
|
||||||
|
|
||||||
|
import "errors"
|
||||||
|
|
||||||
|
type Queue struct {
|
||||||
|
Setting *ConvertSetting
|
||||||
|
Status StatusContract
|
||||||
|
Error error
|
||||||
|
}
|
||||||
|
|
||||||
|
type StatusContract interface {
|
||||||
|
Name() string
|
||||||
|
Ordinal() int
|
||||||
|
}
|
||||||
|
|
||||||
|
const (
|
||||||
|
Waiting = iota
|
||||||
|
InProgress
|
||||||
|
Completed
|
||||||
|
Error
|
||||||
|
)
|
||||||
|
|
||||||
|
type StatusType uint
|
||||||
|
|
||||||
|
var statusTypeStrings = []string{
|
||||||
|
"waiting",
|
||||||
|
"inProgress",
|
||||||
|
"completed",
|
||||||
|
"error",
|
||||||
|
}
|
||||||
|
|
||||||
|
func (status StatusType) Name() string {
|
||||||
|
return statusTypeStrings[status]
|
||||||
|
}
|
||||||
|
|
||||||
|
func (status StatusType) Ordinal() int {
|
||||||
|
return int(status)
|
||||||
|
}
|
||||||
|
|
||||||
|
type QueueListenerContract interface {
|
||||||
|
AddQueue(key int, queue *Queue)
|
||||||
|
ChangeQueue(key int, queue *Queue)
|
||||||
|
RemoveQueue(key int, status StatusContract)
|
||||||
|
}
|
||||||
|
|
||||||
|
type QueueListContract interface {
|
||||||
|
AddListener(queueListener QueueListenerContract)
|
||||||
|
GetItems() map[int]*Queue
|
||||||
|
Add(setting *ConvertSetting)
|
||||||
|
EventChangeQueue(key int, queue *Queue)
|
||||||
|
Remove(key int)
|
||||||
|
GetItem(key int) (*Queue, error)
|
||||||
|
Next() (key int, queue *Queue)
|
||||||
|
}
|
||||||
|
|
||||||
|
type queueList struct {
|
||||||
|
currentKey int
|
||||||
|
items map[int]*Queue
|
||||||
|
queue map[int]int
|
||||||
|
queueListener map[int]QueueListenerContract
|
||||||
|
}
|
||||||
|
|
||||||
|
func NewQueueList() QueueListContract {
|
||||||
|
return &queueList{
|
||||||
|
currentKey: 0,
|
||||||
|
items: map[int]*Queue{},
|
||||||
|
queueListener: map[int]QueueListenerContract{},
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (l *queueList) GetItems() map[int]*Queue {
|
||||||
|
return l.items
|
||||||
|
}
|
||||||
|
|
||||||
|
func (l *queueList) Add(setting *ConvertSetting) {
|
||||||
|
queue := Queue{
|
||||||
|
Setting: setting,
|
||||||
|
Status: StatusType(Waiting),
|
||||||
|
}
|
||||||
|
|
||||||
|
l.currentKey += 1
|
||||||
|
l.items[l.currentKey] = &queue
|
||||||
|
l.queue[l.currentKey] = l.currentKey
|
||||||
|
|
||||||
|
l.eventAdd(l.currentKey, &queue)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (l *queueList) EventChangeQueue(key int, queue *Queue) {
|
||||||
|
l.eventChange(key, queue)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (l *queueList) Remove(key int) {
|
||||||
|
if _, ok := l.queue[key]; ok {
|
||||||
|
delete(l.queue, key)
|
||||||
|
}
|
||||||
|
|
||||||
|
if _, ok := l.items[key]; ok {
|
||||||
|
status := l.items[key].Status
|
||||||
|
l.eventRemove(key, status)
|
||||||
|
delete(l.items, key)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (l *queueList) GetItem(key int) (*Queue, error) {
|
||||||
|
if item, ok := l.items[key]; ok {
|
||||||
|
return item, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil, errors.New("key not found")
|
||||||
|
}
|
||||||
|
|
||||||
|
func (l *queueList) AddListener(queueListener QueueListenerContract) {
|
||||||
|
l.queueListener[len(l.queueListener)] = queueListener
|
||||||
|
}
|
||||||
|
|
||||||
|
func (l *queueList) Next() (key int, queue *Queue) {
|
||||||
|
statusWaiting := StatusType(Waiting)
|
||||||
|
for key, queueId := range l.queue {
|
||||||
|
if queue, ok := l.items[queueId]; ok {
|
||||||
|
if queue.Status == statusWaiting {
|
||||||
|
return queueId, queue
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if _, ok := l.queue[key]; ok {
|
||||||
|
delete(l.queue, key)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return -1, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (l *queueList) eventAdd(key int, queue *Queue) {
|
||||||
|
for _, listener := range l.queueListener {
|
||||||
|
listener.AddQueue(key, queue)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (l *queueList) eventChange(key int, queue *Queue) {
|
||||||
|
for _, listener := range l.queueListener {
|
||||||
|
listener.ChangeQueue(key, queue)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (l *queueList) eventRemove(key int, status StatusContract) {
|
||||||
|
for _, listener := range l.queueListener {
|
||||||
|
listener.RemoveQueue(key, status)
|
||||||
|
}
|
||||||
|
}
|
@ -18,10 +18,12 @@ type controller struct {
|
|||||||
|
|
||||||
func NewController(app application.AppContract) ControllerContract {
|
func NewController(app application.AppContract) ControllerContract {
|
||||||
fyneWindow := app.FyneApp().NewWindow(app.FyneApp().Metadata().Name)
|
fyneWindow := app.FyneApp().NewWindow(app.FyneApp().Metadata().Name)
|
||||||
|
queueLayout := window.NewQueueLayout()
|
||||||
|
app.GetQueueService().AddListener(queueLayout)
|
||||||
|
|
||||||
return &controller{
|
return &controller{
|
||||||
app: app,
|
app: app,
|
||||||
window: window.NewMainWindow(fyneWindow, app.GetProgressBarService()),
|
window: window.NewMainWindow(fyneWindow, app.GetProgressBarService(), app.GetItemsToConvert(), queueLayout),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2,11 +2,14 @@ package window
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"fyne.io/fyne/v2"
|
"fyne.io/fyne/v2"
|
||||||
|
"fyne.io/fyne/v2/canvas"
|
||||||
"fyne.io/fyne/v2/container"
|
"fyne.io/fyne/v2/container"
|
||||||
"fyne.io/fyne/v2/dialog"
|
"fyne.io/fyne/v2/dialog"
|
||||||
"fyne.io/fyne/v2/lang"
|
"fyne.io/fyne/v2/lang"
|
||||||
|
"fyne.io/fyne/v2/theme"
|
||||||
"fyne.io/fyne/v2/widget"
|
"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"
|
||||||
|
"git.kor-elf.net/kor-elf/gui-for-ffmpeg/internal/application/convertor"
|
||||||
"git.kor-elf.net/kor-elf/gui-for-ffmpeg/internal/utils"
|
"git.kor-elf.net/kor-elf/gui-for-ffmpeg/internal/utils"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -20,22 +23,26 @@ type WindowContract interface {
|
|||||||
type mainWindow struct {
|
type mainWindow struct {
|
||||||
fyneWindow fyne.Window
|
fyneWindow fyne.Window
|
||||||
layout *fyne.Container
|
layout *fyne.Container
|
||||||
|
itemsToConvert convertor.ItemsToConvertContract
|
||||||
progressBarService application.ProgressBarContract
|
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.Resize(fyne.Size{Width: 1039, Height: 599})
|
||||||
fyneWindow.CenterOnScreen()
|
fyneWindow.CenterOnScreen()
|
||||||
|
|
||||||
return &mainWindow{
|
return &mainWindow{
|
||||||
fyneWindow: fyneWindow,
|
fyneWindow: fyneWindow,
|
||||||
progressBarService: progressBarService,
|
progressBarService: progressBarService,
|
||||||
|
itemsToConvert: itemsToConvert,
|
||||||
|
queueLayout: queueLayout,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (w *mainWindow) InitLayout() {
|
func (w *mainWindow) InitLayout() {
|
||||||
fyne.Do(func() {
|
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())
|
layout := container.NewAdaptiveGrid(2, widget.NewLabel(""), rContainer.GetCanvasObject())
|
||||||
w.fyneWindow.SetContent(layout)
|
w.fyneWindow.SetContent(layout)
|
||||||
|
|
||||||
@ -72,31 +79,20 @@ func (w *mainWindow) Show() {
|
|||||||
type RightMainContainerContract interface {
|
type RightMainContainerContract interface {
|
||||||
GetCanvasObject() fyne.CanvasObject
|
GetCanvasObject() fyne.CanvasObject
|
||||||
GetTabs() *container.AppTabs
|
GetTabs() *container.AppTabs
|
||||||
GetAddedFilesContainer() *fyne.Container
|
|
||||||
GetFileQueueContainer() *fyne.Container
|
|
||||||
SelectFileQueueTab()
|
SelectFileQueueTab()
|
||||||
SelectAddedFilesTab()
|
SelectAddedFilesTab()
|
||||||
}
|
}
|
||||||
|
|
||||||
type rightMainContainer struct {
|
type rightMainContainer struct {
|
||||||
container fyne.CanvasObject
|
container fyne.CanvasObject
|
||||||
|
tabs *container.AppTabs
|
||||||
tabs *container.AppTabs
|
addedFilesTab *container.TabItem
|
||||||
|
fileQueueTab *container.TabItem
|
||||||
addedFilesContainer *fyne.Container
|
|
||||||
addedFilesTab *container.TabItem
|
|
||||||
|
|
||||||
fileQueueContainer *fyne.Container
|
|
||||||
fileQueueTab *container.TabItem
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func newRightContainer(blockProgressbar *fyne.Container) RightMainContainerContract {
|
func newRightContainer(blockProgressbar *fyne.Container, itemsToConvert convertor.ItemsToConvertContract, queueLayout QueueLayoutContract) RightMainContainerContract {
|
||||||
|
addedFilesTab := container.NewTabItem(lang.L("addedFilesTitle"), addedFilesContainer(itemsToConvert))
|
||||||
addedFilesContainer := container.NewVBox()
|
fileQueueTab := container.NewTabItem(lang.L("fileQueueTitle"), fileQueueContainer(queueLayout))
|
||||||
addedFilesTab := container.NewTabItem(lang.L("addedFilesTitle"), addedFilesContainer)
|
|
||||||
|
|
||||||
fileQueueContainer := container.NewVBox()
|
|
||||||
fileQueueTab := container.NewTabItem(lang.L("fileQueueTitle"), fileQueueContainer)
|
|
||||||
|
|
||||||
tabs := container.NewAppTabs(
|
tabs := container.NewAppTabs(
|
||||||
addedFilesTab,
|
addedFilesTab,
|
||||||
@ -115,12 +111,10 @@ func newRightContainer(blockProgressbar *fyne.Container) RightMainContainerContr
|
|||||||
)
|
)
|
||||||
|
|
||||||
return &rightMainContainer{
|
return &rightMainContainer{
|
||||||
container: rightContainer,
|
container: rightContainer,
|
||||||
tabs: tabs,
|
tabs: tabs,
|
||||||
addedFilesContainer: addedFilesContainer,
|
addedFilesTab: addedFilesTab,
|
||||||
addedFilesTab: addedFilesTab,
|
fileQueueTab: fileQueueTab,
|
||||||
fileQueueContainer: fileQueueContainer,
|
|
||||||
fileQueueTab: fileQueueTab,
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -132,14 +126,6 @@ func (r *rightMainContainer) GetTabs() *container.AppTabs {
|
|||||||
return r.tabs
|
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() {
|
func (r *rightMainContainer) SelectFileQueueTab() {
|
||||||
fyne.Do(func() {
|
fyne.Do(func() {
|
||||||
r.tabs.Select(r.fileQueueTab)
|
r.tabs.Select(r.fileQueueTab)
|
||||||
@ -151,3 +137,55 @@ func (r *rightMainContainer) SelectAddedFilesTab() {
|
|||||||
r.tabs.Select(r.addedFilesTab)
|
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
|
||||||
|
}
|
5
main.go
5
main.go
@ -4,6 +4,7 @@ import (
|
|||||||
"fyne.io/fyne/v2"
|
"fyne.io/fyne/v2"
|
||||||
"fyne.io/fyne/v2/app"
|
"fyne.io/fyne/v2/app"
|
||||||
"git.kor-elf.net/kor-elf/gui-for-ffmpeg/internal/application"
|
"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/application/setting"
|
"git.kor-elf.net/kor-elf/gui-for-ffmpeg/internal/application/setting"
|
||||||
"git.kor-elf.net/kor-elf/gui-for-ffmpeg/internal/controller"
|
"git.kor-elf.net/kor-elf/gui-for-ffmpeg/internal/controller"
|
||||||
"git.kor-elf.net/kor-elf/gui-for-ffmpeg/internal/ffmpeg"
|
"git.kor-elf.net/kor-elf/gui-for-ffmpeg/internal/ffmpeg"
|
||||||
@ -22,7 +23,9 @@ func main() {
|
|||||||
progressBarService := application.NewProgressBar()
|
progressBarService := application.NewProgressBar()
|
||||||
appSetting := setting.NewSetting(fyneApp)
|
appSetting := setting.NewSetting(fyneApp)
|
||||||
ffmpegService := ffmpeg.NewUtilities(appSetting)
|
ffmpegService := ffmpeg.NewUtilities(appSetting)
|
||||||
myApp := application.NewApp(fyneApp, appSetting, progressBarService, ffmpegService)
|
itemsToConvert := convertor.NewItemsToConvert(ffmpegService)
|
||||||
|
queue := convertor.NewQueueList()
|
||||||
|
myApp := application.NewApp(fyneApp, appSetting, progressBarService, ffmpegService, itemsToConvert, queue)
|
||||||
mainController := controller.NewController(myApp)
|
mainController := controller.NewController(myApp)
|
||||||
mainController.Start()
|
mainController.Start()
|
||||||
myApp.Run()
|
myApp.Run()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user