Added queues.
Reworked the architecture.
This commit is contained in:
parent
c4ec958576
commit
a1c9143685
@ -5,11 +5,9 @@ import (
|
|||||||
"fyne.io/fyne/v2"
|
"fyne.io/fyne/v2"
|
||||||
"fyne.io/fyne/v2/canvas"
|
"fyne.io/fyne/v2/canvas"
|
||||||
"fyne.io/fyne/v2/container"
|
"fyne.io/fyne/v2/container"
|
||||||
"fyne.io/fyne/v2/dialog"
|
|
||||||
"fyne.io/fyne/v2/storage"
|
"fyne.io/fyne/v2/storage"
|
||||||
"fyne.io/fyne/v2/widget"
|
"fyne.io/fyne/v2/widget"
|
||||||
"git.kor-elf.net/kor-elf/gui-for-ffmpeg/helper"
|
"git.kor-elf.net/kor-elf/gui-for-ffmpeg/kernel"
|
||||||
"git.kor-elf.net/kor-elf/gui-for-ffmpeg/localizer"
|
|
||||||
"github.com/nicksnyder/go-i18n/v2/i18n"
|
"github.com/nicksnyder/go-i18n/v2/i18n"
|
||||||
"image/color"
|
"image/color"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
@ -17,7 +15,7 @@ import (
|
|||||||
|
|
||||||
type ViewContract interface {
|
type ViewContract interface {
|
||||||
Main(
|
Main(
|
||||||
runConvert func(setting HandleConvertSetting, progressbar *widget.ProgressBar) error,
|
runConvert func(setting HandleConvertSetting),
|
||||||
)
|
)
|
||||||
SelectFFPath(
|
SelectFFPath(
|
||||||
ffmpegPath string,
|
ffmpegPath string,
|
||||||
@ -29,12 +27,11 @@ type ViewContract interface {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type View struct {
|
type View struct {
|
||||||
w fyne.Window
|
app kernel.AppContract
|
||||||
localizerService localizer.ServiceContract
|
|
||||||
}
|
}
|
||||||
|
|
||||||
type HandleConvertSetting struct {
|
type HandleConvertSetting struct {
|
||||||
VideoFileInput *File
|
VideoFileInput kernel.File
|
||||||
DirectoryForSave string
|
DirectoryForSave string
|
||||||
OverwriteOutputFiles bool
|
OverwriteOutputFiles bool
|
||||||
}
|
}
|
||||||
@ -45,15 +42,14 @@ type enableFormConversionStruct struct {
|
|||||||
form *widget.Form
|
form *widget.Form
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewView(w fyne.Window, localizerService localizer.ServiceContract) *View {
|
func NewView(app kernel.AppContract) *View {
|
||||||
return &View{
|
return &View{
|
||||||
w: w,
|
app: app,
|
||||||
localizerService: localizerService,
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (v View) Main(
|
func (v View) Main(
|
||||||
runConvert func(setting HandleConvertSetting, progressbar *widget.ProgressBar) error,
|
runConvert func(setting HandleConvertSetting),
|
||||||
) {
|
) {
|
||||||
form := &widget.Form{}
|
form := &widget.Form{}
|
||||||
|
|
||||||
@ -61,13 +57,11 @@ func (v View) Main(
|
|||||||
conversionMessage.TextSize = 16
|
conversionMessage.TextSize = 16
|
||||||
conversionMessage.TextStyle = fyne.TextStyle{Bold: true}
|
conversionMessage.TextStyle = fyne.TextStyle{Bold: true}
|
||||||
|
|
||||||
progress := widget.NewProgressBar()
|
fileVideoForConversion, fileVideoForConversionMessage, fileInput := v.getButtonFileVideoForConversion(form, conversionMessage)
|
||||||
|
|
||||||
fileVideoForConversion, fileVideoForConversionMessage, fileInput := v.getButtonFileVideoForConversion(form, progress, conversionMessage)
|
|
||||||
buttonForSelectedDir, buttonForSelectedDirMessage, pathToSaveDirectory := v.getButtonForSelectingDirectoryForSaving()
|
buttonForSelectedDir, buttonForSelectedDirMessage, pathToSaveDirectory := v.getButtonForSelectingDirectoryForSaving()
|
||||||
|
|
||||||
isOverwriteOutputFiles := false
|
isOverwriteOutputFiles := false
|
||||||
checkboxOverwriteOutputFilesTitle := v.localizerService.GetMessage(&i18n.LocalizeConfig{
|
checkboxOverwriteOutputFilesTitle := v.app.GetLocalizerService().GetMessage(&i18n.LocalizeConfig{
|
||||||
MessageID: "checkboxOverwriteOutputFilesTitle",
|
MessageID: "checkboxOverwriteOutputFilesTitle",
|
||||||
})
|
})
|
||||||
checkboxOverwriteOutputFiles := widget.NewCheck(checkboxOverwriteOutputFilesTitle, func(b bool) {
|
checkboxOverwriteOutputFiles := widget.NewCheck(checkboxOverwriteOutputFilesTitle, func(b bool) {
|
||||||
@ -76,14 +70,14 @@ func (v View) Main(
|
|||||||
|
|
||||||
form.Items = []*widget.FormItem{
|
form.Items = []*widget.FormItem{
|
||||||
{
|
{
|
||||||
Text: v.localizerService.GetMessage(&i18n.LocalizeConfig{MessageID: "fileVideoForConversionTitle"}),
|
Text: v.app.GetLocalizerService().GetMessage(&i18n.LocalizeConfig{MessageID: "fileVideoForConversionTitle"}),
|
||||||
Widget: fileVideoForConversion,
|
Widget: fileVideoForConversion,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
Widget: container.NewHScroll(fileVideoForConversionMessage),
|
Widget: container.NewHScroll(fileVideoForConversionMessage),
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
Text: v.localizerService.GetMessage(&i18n.LocalizeConfig{MessageID: "buttonForSelectedDirTitle"}),
|
Text: v.app.GetLocalizerService().GetMessage(&i18n.LocalizeConfig{MessageID: "buttonForSelectedDirTitle"}),
|
||||||
Widget: buttonForSelectedDir,
|
Widget: buttonForSelectedDir,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
@ -93,7 +87,7 @@ func (v View) Main(
|
|||||||
Widget: checkboxOverwriteOutputFiles,
|
Widget: checkboxOverwriteOutputFiles,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
form.SubmitText = v.localizerService.GetMessage(&i18n.LocalizeConfig{
|
form.SubmitText = v.app.GetLocalizerService().GetMessage(&i18n.LocalizeConfig{
|
||||||
MessageID: "converterVideoFilesSubmitTitle",
|
MessageID: "converterVideoFilesSubmitTitle",
|
||||||
})
|
})
|
||||||
|
|
||||||
@ -105,7 +99,7 @@ func (v View) Main(
|
|||||||
|
|
||||||
form.OnSubmit = func() {
|
form.OnSubmit = func() {
|
||||||
if len(*pathToSaveDirectory) == 0 {
|
if len(*pathToSaveDirectory) == 0 {
|
||||||
showConversionMessage(conversionMessage, errors.New(v.localizerService.GetMessage(&i18n.LocalizeConfig{
|
showConversionMessage(conversionMessage, errors.New(v.app.GetLocalizerService().GetMessage(&i18n.LocalizeConfig{
|
||||||
MessageID: "errorSelectedFolderSave",
|
MessageID: "errorSelectedFolderSave",
|
||||||
})))
|
})))
|
||||||
enableFormConversion(enableFormConversionStruct)
|
enableFormConversion(enableFormConversionStruct)
|
||||||
@ -118,71 +112,61 @@ func (v View) Main(
|
|||||||
form.Disable()
|
form.Disable()
|
||||||
|
|
||||||
setting := HandleConvertSetting{
|
setting := HandleConvertSetting{
|
||||||
VideoFileInput: fileInput,
|
VideoFileInput: *fileInput,
|
||||||
DirectoryForSave: *pathToSaveDirectory,
|
DirectoryForSave: *pathToSaveDirectory,
|
||||||
OverwriteOutputFiles: isOverwriteOutputFiles,
|
OverwriteOutputFiles: isOverwriteOutputFiles,
|
||||||
}
|
}
|
||||||
err := runConvert(setting, progress)
|
runConvert(setting)
|
||||||
if err != nil {
|
|
||||||
showConversionMessage(conversionMessage, err)
|
|
||||||
enableFormConversion(enableFormConversionStruct)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
enableFormConversion(enableFormConversionStruct)
|
enableFormConversion(enableFormConversionStruct)
|
||||||
|
|
||||||
|
fileVideoForConversionMessage.Text = ""
|
||||||
|
form.Disable()
|
||||||
}
|
}
|
||||||
|
|
||||||
converterVideoFilesTitle := v.localizerService.GetMessage(&i18n.LocalizeConfig{
|
converterVideoFilesTitle := v.app.GetLocalizerService().GetMessage(&i18n.LocalizeConfig{
|
||||||
MessageID: "converterVideoFilesTitle",
|
MessageID: "converterVideoFilesTitle",
|
||||||
})
|
})
|
||||||
v.w.SetContent(widget.NewCard(converterVideoFilesTitle, "", container.NewVBox(form, conversionMessage, progress)))
|
v.app.GetWindow().SetContent(widget.NewCard(converterVideoFilesTitle, "", container.NewVBox(form, conversionMessage)))
|
||||||
form.Disable()
|
form.Disable()
|
||||||
}
|
}
|
||||||
|
|
||||||
func (v View) getButtonFileVideoForConversion(form *widget.Form, progress *widget.ProgressBar, conversionMessage *canvas.Text) (*widget.Button, *canvas.Text, *File) {
|
func (v View) getButtonFileVideoForConversion(form *widget.Form, conversionMessage *canvas.Text) (*widget.Button, *canvas.Text, *kernel.File) {
|
||||||
fileInput := &File{}
|
fileInput := &kernel.File{}
|
||||||
|
|
||||||
fileVideoForConversionMessage := canvas.NewText("", color.RGBA{R: 255, G: 0, B: 0, A: 255})
|
fileVideoForConversionMessage := canvas.NewText("", color.RGBA{R: 255, G: 0, B: 0, A: 255})
|
||||||
fileVideoForConversionMessage.TextSize = 16
|
fileVideoForConversionMessage.TextSize = 16
|
||||||
fileVideoForConversionMessage.TextStyle = fyne.TextStyle{Bold: true}
|
fileVideoForConversionMessage.TextStyle = fyne.TextStyle{Bold: true}
|
||||||
|
|
||||||
buttonTitle := v.localizerService.GetMessage(&i18n.LocalizeConfig{
|
buttonTitle := v.app.GetLocalizerService().GetMessage(&i18n.LocalizeConfig{
|
||||||
MessageID: "choose",
|
MessageID: "choose",
|
||||||
})
|
})
|
||||||
|
|
||||||
var locationURI fyne.ListableURI
|
var locationURI fyne.ListableURI
|
||||||
|
|
||||||
button := widget.NewButton(buttonTitle, func() {
|
button := widget.NewButton(buttonTitle, func() {
|
||||||
fileDialog := dialog.NewFileOpen(
|
v.app.GetWindow().NewFileOpen(func(r fyne.URIReadCloser, err error) {
|
||||||
func(r fyne.URIReadCloser, err error) {
|
if err != nil {
|
||||||
if err != nil {
|
fileVideoForConversionMessage.Text = err.Error()
|
||||||
fileVideoForConversionMessage.Text = err.Error()
|
setStringErrorStyle(fileVideoForConversionMessage)
|
||||||
setStringErrorStyle(fileVideoForConversionMessage)
|
return
|
||||||
return
|
}
|
||||||
}
|
if r == nil {
|
||||||
if r == nil {
|
return
|
||||||
return
|
}
|
||||||
}
|
|
||||||
|
|
||||||
fileInput.Path = r.URI().Path()
|
fileInput.Path = r.URI().Path()
|
||||||
fileInput.Name = r.URI().Name()
|
fileInput.Name = r.URI().Name()
|
||||||
fileInput.Ext = r.URI().Extension()
|
fileInput.Ext = r.URI().Extension()
|
||||||
|
|
||||||
fileVideoForConversionMessage.Text = r.URI().Path()
|
fileVideoForConversionMessage.Text = r.URI().Path()
|
||||||
setStringSuccessStyle(fileVideoForConversionMessage)
|
setStringSuccessStyle(fileVideoForConversionMessage)
|
||||||
|
|
||||||
form.Enable()
|
form.Enable()
|
||||||
progress.Value = 0
|
conversionMessage.Text = ""
|
||||||
progress.Refresh()
|
|
||||||
conversionMessage.Text = ""
|
|
||||||
|
|
||||||
listableURI := storage.NewFileURI(filepath.Dir(r.URI().Path()))
|
listableURI := storage.NewFileURI(filepath.Dir(r.URI().Path()))
|
||||||
locationURI, err = storage.ListerForURI(listableURI)
|
locationURI, err = storage.ListerForURI(listableURI)
|
||||||
}, v.w)
|
}, locationURI)
|
||||||
helper.FileDialogResize(fileDialog, v.w)
|
|
||||||
fileDialog.Show()
|
|
||||||
if locationURI != nil {
|
|
||||||
fileDialog.SetLocation(locationURI)
|
|
||||||
}
|
|
||||||
})
|
})
|
||||||
|
|
||||||
return button, fileVideoForConversionMessage, fileInput
|
return button, fileVideoForConversionMessage, fileInput
|
||||||
@ -196,36 +180,30 @@ func (v View) getButtonForSelectingDirectoryForSaving() (button *widget.Button,
|
|||||||
path := ""
|
path := ""
|
||||||
dirPath = &path
|
dirPath = &path
|
||||||
|
|
||||||
buttonTitle := v.localizerService.GetMessage(&i18n.LocalizeConfig{
|
buttonTitle := v.app.GetLocalizerService().GetMessage(&i18n.LocalizeConfig{
|
||||||
MessageID: "choose",
|
MessageID: "choose",
|
||||||
})
|
})
|
||||||
|
|
||||||
var locationURI fyne.ListableURI
|
var locationURI fyne.ListableURI
|
||||||
|
|
||||||
button = widget.NewButton(buttonTitle, func() {
|
button = widget.NewButton(buttonTitle, func() {
|
||||||
fileDialog := dialog.NewFolderOpen(
|
v.app.GetWindow().NewFolderOpen(func(r fyne.ListableURI, err error) {
|
||||||
func(r fyne.ListableURI, err error) {
|
if err != nil {
|
||||||
if err != nil {
|
buttonMessage.Text = err.Error()
|
||||||
buttonMessage.Text = err.Error()
|
setStringErrorStyle(buttonMessage)
|
||||||
setStringErrorStyle(buttonMessage)
|
return
|
||||||
return
|
}
|
||||||
}
|
if r == nil {
|
||||||
if r == nil {
|
return
|
||||||
return
|
}
|
||||||
}
|
|
||||||
|
|
||||||
path = r.Path()
|
path = r.Path()
|
||||||
|
|
||||||
buttonMessage.Text = r.Path()
|
buttonMessage.Text = r.Path()
|
||||||
setStringSuccessStyle(buttonMessage)
|
setStringSuccessStyle(buttonMessage)
|
||||||
locationURI, _ = storage.ListerForURI(r)
|
locationURI, _ = storage.ListerForURI(r)
|
||||||
|
|
||||||
}, v.w)
|
}, locationURI)
|
||||||
helper.FileDialogResize(fileDialog, v.w)
|
|
||||||
fileDialog.Show()
|
|
||||||
if locationURI != nil {
|
|
||||||
fileDialog.SetLocation(locationURI)
|
|
||||||
}
|
|
||||||
})
|
})
|
||||||
|
|
||||||
return
|
return
|
||||||
|
@ -4,10 +4,8 @@ import (
|
|||||||
"fyne.io/fyne/v2"
|
"fyne.io/fyne/v2"
|
||||||
"fyne.io/fyne/v2/canvas"
|
"fyne.io/fyne/v2/canvas"
|
||||||
"fyne.io/fyne/v2/container"
|
"fyne.io/fyne/v2/container"
|
||||||
"fyne.io/fyne/v2/dialog"
|
|
||||||
"fyne.io/fyne/v2/storage"
|
"fyne.io/fyne/v2/storage"
|
||||||
"fyne.io/fyne/v2/widget"
|
"fyne.io/fyne/v2/widget"
|
||||||
"git.kor-elf.net/kor-elf/gui-for-ffmpeg/helper"
|
|
||||||
"github.com/nicksnyder/go-i18n/v2/i18n"
|
"github.com/nicksnyder/go-i18n/v2/i18n"
|
||||||
"image/color"
|
"image/color"
|
||||||
"net/url"
|
"net/url"
|
||||||
@ -37,13 +35,13 @@ func (v View) SelectFFPath(
|
|||||||
form := &widget.Form{
|
form := &widget.Form{
|
||||||
Items: []*widget.FormItem{
|
Items: []*widget.FormItem{
|
||||||
{
|
{
|
||||||
Text: v.localizerService.GetMessage(&i18n.LocalizeConfig{
|
Text: v.app.GetLocalizerService().GetMessage(&i18n.LocalizeConfig{
|
||||||
MessageID: "titleDownloadLink",
|
MessageID: "titleDownloadLink",
|
||||||
}),
|
}),
|
||||||
Widget: link,
|
Widget: link,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
Text: v.localizerService.GetMessage(&i18n.LocalizeConfig{
|
Text: v.app.GetLocalizerService().GetMessage(&i18n.LocalizeConfig{
|
||||||
MessageID: "pathToFfmpeg",
|
MessageID: "pathToFfmpeg",
|
||||||
}),
|
}),
|
||||||
Widget: buttonFFmpeg,
|
Widget: buttonFFmpeg,
|
||||||
@ -52,7 +50,7 @@ func (v View) SelectFFPath(
|
|||||||
Widget: container.NewHScroll(buttonFFmpegMessage),
|
Widget: container.NewHScroll(buttonFFmpegMessage),
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
Text: v.localizerService.GetMessage(&i18n.LocalizeConfig{
|
Text: v.app.GetLocalizerService().GetMessage(&i18n.LocalizeConfig{
|
||||||
MessageID: "pathToFfprobe",
|
MessageID: "pathToFfprobe",
|
||||||
}),
|
}),
|
||||||
Widget: buttonFFprobe,
|
Widget: buttonFFprobe,
|
||||||
@ -64,7 +62,7 @@ func (v View) SelectFFPath(
|
|||||||
Widget: errorMessage,
|
Widget: errorMessage,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
SubmitText: v.localizerService.GetMessage(&i18n.LocalizeConfig{
|
SubmitText: v.app.GetLocalizerService().GetMessage(&i18n.LocalizeConfig{
|
||||||
MessageID: "save",
|
MessageID: "save",
|
||||||
}),
|
}),
|
||||||
OnSubmit: func() {
|
OnSubmit: func() {
|
||||||
@ -76,15 +74,15 @@ func (v View) SelectFFPath(
|
|||||||
}
|
}
|
||||||
if cancel != nil {
|
if cancel != nil {
|
||||||
form.OnCancel = cancel
|
form.OnCancel = cancel
|
||||||
form.CancelText = v.localizerService.GetMessage(&i18n.LocalizeConfig{
|
form.CancelText = v.app.GetLocalizerService().GetMessage(&i18n.LocalizeConfig{
|
||||||
MessageID: "cancel",
|
MessageID: "cancel",
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
selectFFPathTitle := v.localizerService.GetMessage(&i18n.LocalizeConfig{
|
selectFFPathTitle := v.app.GetLocalizerService().GetMessage(&i18n.LocalizeConfig{
|
||||||
MessageID: "selectFFPathTitle",
|
MessageID: "selectFFPathTitle",
|
||||||
})
|
})
|
||||||
|
|
||||||
v.w.SetContent(widget.NewCard(selectFFPathTitle, "", container.NewVBox(
|
v.app.GetWindow().SetContent(widget.NewCard(selectFFPathTitle, "", container.NewVBox(
|
||||||
form,
|
form,
|
||||||
v.blockDownloadFFmpeg(donwloadFFmpeg),
|
v.blockDownloadFFmpeg(donwloadFFmpeg),
|
||||||
)))
|
)))
|
||||||
@ -97,7 +95,7 @@ func (v View) getButtonSelectFile(path string) (filePath *string, button *widget
|
|||||||
buttonMessage.TextSize = 16
|
buttonMessage.TextSize = 16
|
||||||
buttonMessage.TextStyle = fyne.TextStyle{Bold: true}
|
buttonMessage.TextStyle = fyne.TextStyle{Bold: true}
|
||||||
|
|
||||||
buttonTitle := v.localizerService.GetMessage(&i18n.LocalizeConfig{
|
buttonTitle := v.app.GetLocalizerService().GetMessage(&i18n.LocalizeConfig{
|
||||||
MessageID: "choose",
|
MessageID: "choose",
|
||||||
})
|
})
|
||||||
|
|
||||||
@ -108,30 +106,24 @@ func (v View) getButtonSelectFile(path string) (filePath *string, button *widget
|
|||||||
}
|
}
|
||||||
|
|
||||||
button = widget.NewButton(buttonTitle, func() {
|
button = widget.NewButton(buttonTitle, func() {
|
||||||
fileDialog := dialog.NewFileOpen(
|
v.app.GetWindow().NewFileOpen(func(r fyne.URIReadCloser, err error) {
|
||||||
func(r fyne.URIReadCloser, err error) {
|
if err != nil {
|
||||||
if err != nil {
|
buttonMessage.Text = err.Error()
|
||||||
buttonMessage.Text = err.Error()
|
setStringErrorStyle(buttonMessage)
|
||||||
setStringErrorStyle(buttonMessage)
|
return
|
||||||
return
|
}
|
||||||
}
|
if r == nil {
|
||||||
if r == nil {
|
return
|
||||||
return
|
}
|
||||||
}
|
|
||||||
|
|
||||||
path = r.URI().Path()
|
path = r.URI().Path()
|
||||||
|
|
||||||
buttonMessage.Text = r.URI().Path()
|
buttonMessage.Text = r.URI().Path()
|
||||||
setStringSuccessStyle(buttonMessage)
|
setStringSuccessStyle(buttonMessage)
|
||||||
|
|
||||||
listableURI := storage.NewFileURI(filepath.Dir(r.URI().Path()))
|
listableURI := storage.NewFileURI(filepath.Dir(r.URI().Path()))
|
||||||
locationURI, _ = storage.ListerForURI(listableURI)
|
locationURI, _ = storage.ListerForURI(listableURI)
|
||||||
}, v.w)
|
}, locationURI)
|
||||||
helper.FileDialogResize(fileDialog, v.w)
|
|
||||||
fileDialog.Show()
|
|
||||||
if locationURI != nil {
|
|
||||||
fileDialog.SetLocation(locationURI)
|
|
||||||
}
|
|
||||||
})
|
})
|
||||||
|
|
||||||
return
|
return
|
||||||
|
@ -1,9 +1,9 @@
|
|||||||
package error
|
package error
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fyne.io/fyne/v2"
|
|
||||||
"fyne.io/fyne/v2/container"
|
"fyne.io/fyne/v2/container"
|
||||||
"fyne.io/fyne/v2/widget"
|
"fyne.io/fyne/v2/widget"
|
||||||
|
"git.kor-elf.net/kor-elf/gui-for-ffmpeg/kernel"
|
||||||
"git.kor-elf.net/kor-elf/gui-for-ffmpeg/localizer"
|
"git.kor-elf.net/kor-elf/gui-for-ffmpeg/localizer"
|
||||||
"github.com/nicksnyder/go-i18n/v2/i18n"
|
"github.com/nicksnyder/go-i18n/v2/i18n"
|
||||||
)
|
)
|
||||||
@ -13,23 +13,21 @@ type ViewContract interface {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type View struct {
|
type View struct {
|
||||||
w fyne.Window
|
app kernel.AppContract
|
||||||
localizerService localizer.ServiceContract
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewView(w fyne.Window, localizerService localizer.ServiceContract) *View {
|
func NewView(app kernel.AppContract) *View {
|
||||||
return &View{
|
return &View{
|
||||||
w: w,
|
app: app,
|
||||||
localizerService: localizerService,
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (v View) PanicError(err error) {
|
func (v View) PanicError(err error) {
|
||||||
messageHead := v.localizerService.GetMessage(&i18n.LocalizeConfig{
|
messageHead := v.app.GetLocalizerService().GetMessage(&i18n.LocalizeConfig{
|
||||||
MessageID: "error",
|
MessageID: "error",
|
||||||
})
|
})
|
||||||
|
|
||||||
v.w.SetContent(container.NewBorder(
|
v.app.GetWindow().SetContent(container.NewBorder(
|
||||||
container.NewVBox(
|
container.NewVBox(
|
||||||
widget.NewLabel(messageHead),
|
widget.NewLabel(messageHead),
|
||||||
widget.NewLabel(err.Error()),
|
widget.NewLabel(err.Error()),
|
||||||
@ -37,21 +35,21 @@ func (v View) PanicError(err error) {
|
|||||||
nil,
|
nil,
|
||||||
nil,
|
nil,
|
||||||
nil,
|
nil,
|
||||||
localizer.LanguageSelectionForm(v.localizerService, func(lang localizer.Lang) {
|
localizer.LanguageSelectionForm(v.app.GetLocalizerService(), func(lang kernel.Lang) {
|
||||||
v.PanicError(err)
|
v.PanicError(err)
|
||||||
}),
|
}),
|
||||||
))
|
))
|
||||||
}
|
}
|
||||||
|
|
||||||
func (v View) PanicErrorWriteDirectoryData() {
|
func (v View) PanicErrorWriteDirectoryData() {
|
||||||
message := v.localizerService.GetMessage(&i18n.LocalizeConfig{
|
message := v.app.GetLocalizerService().GetMessage(&i18n.LocalizeConfig{
|
||||||
MessageID: "errorDatabase",
|
MessageID: "errorDatabase",
|
||||||
})
|
})
|
||||||
messageHead := v.localizerService.GetMessage(&i18n.LocalizeConfig{
|
messageHead := v.app.GetLocalizerService().GetMessage(&i18n.LocalizeConfig{
|
||||||
MessageID: "error",
|
MessageID: "error",
|
||||||
})
|
})
|
||||||
|
|
||||||
v.w.SetContent(container.NewBorder(
|
v.app.GetWindow().SetContent(container.NewBorder(
|
||||||
container.NewVBox(
|
container.NewVBox(
|
||||||
widget.NewLabel(messageHead),
|
widget.NewLabel(messageHead),
|
||||||
widget.NewLabel(message),
|
widget.NewLabel(message),
|
||||||
@ -59,7 +57,7 @@ func (v View) PanicErrorWriteDirectoryData() {
|
|||||||
nil,
|
nil,
|
||||||
nil,
|
nil,
|
||||||
nil,
|
nil,
|
||||||
localizer.LanguageSelectionForm(v.localizerService, func(lang localizer.Lang) {
|
localizer.LanguageSelectionForm(v.app.GetLocalizerService(), func(lang kernel.Lang) {
|
||||||
v.PanicErrorWriteDirectoryData()
|
v.PanicErrorWriteDirectoryData()
|
||||||
}),
|
}),
|
||||||
))
|
))
|
||||||
|
@ -1,17 +1,11 @@
|
|||||||
package handler
|
package handler
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"bufio"
|
|
||||||
"errors"
|
"errors"
|
||||||
"fyne.io/fyne/v2/widget"
|
|
||||||
"git.kor-elf.net/kor-elf/gui-for-ffmpeg/convertor"
|
"git.kor-elf.net/kor-elf/gui-for-ffmpeg/convertor"
|
||||||
"git.kor-elf.net/kor-elf/gui-for-ffmpeg/helper"
|
"git.kor-elf.net/kor-elf/gui-for-ffmpeg/helper"
|
||||||
"git.kor-elf.net/kor-elf/gui-for-ffmpeg/localizer"
|
"git.kor-elf.net/kor-elf/gui-for-ffmpeg/kernel"
|
||||||
"github.com/nicksnyder/go-i18n/v2/i18n"
|
"github.com/nicksnyder/go-i18n/v2/i18n"
|
||||||
"io"
|
|
||||||
"regexp"
|
|
||||||
"strconv"
|
|
||||||
"strings"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
type ConvertorHandlerContract interface {
|
type ConvertorHandlerContract interface {
|
||||||
@ -22,23 +16,20 @@ type ConvertorHandlerContract interface {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type ConvertorHandler struct {
|
type ConvertorHandler struct {
|
||||||
convertorService convertor.ServiceContract
|
app kernel.AppContract
|
||||||
convertorView convertor.ViewContract
|
convertorView convertor.ViewContract
|
||||||
convertorRepository convertor.RepositoryContract
|
convertorRepository convertor.RepositoryContract
|
||||||
localizerService localizer.ServiceContract
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewConvertorHandler(
|
func NewConvertorHandler(
|
||||||
convertorService convertor.ServiceContract,
|
app kernel.AppContract,
|
||||||
convertorView convertor.ViewContract,
|
convertorView convertor.ViewContract,
|
||||||
convertorRepository convertor.RepositoryContract,
|
convertorRepository convertor.RepositoryContract,
|
||||||
localizerService localizer.ServiceContract,
|
|
||||||
) *ConvertorHandler {
|
) *ConvertorHandler {
|
||||||
return &ConvertorHandler{
|
return &ConvertorHandler{
|
||||||
convertorService: convertorService,
|
app: app,
|
||||||
convertorView: convertorView,
|
convertorView: convertorView,
|
||||||
convertorRepository: convertorRepository,
|
convertorRepository: convertorRepository,
|
||||||
localizerService: localizerService,
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -57,32 +48,23 @@ func (h ConvertorHandler) FfPathSelection() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (h ConvertorHandler) GetFfmpegVersion() (string, error) {
|
func (h ConvertorHandler) GetFfmpegVersion() (string, error) {
|
||||||
return h.convertorService.GetFFmpegVesrion()
|
return h.app.GetConvertorService().GetFFmpegVesrion()
|
||||||
}
|
}
|
||||||
|
|
||||||
func (h ConvertorHandler) GetFfprobeVersion() (string, error) {
|
func (h ConvertorHandler) GetFfprobeVersion() (string, error) {
|
||||||
return h.convertorService.GetFFprobeVersion()
|
return h.app.GetConvertorService().GetFFprobeVersion()
|
||||||
}
|
}
|
||||||
|
|
||||||
func (h ConvertorHandler) runConvert(setting convertor.HandleConvertSetting, progressbar *widget.ProgressBar) error {
|
func (h ConvertorHandler) runConvert(setting convertor.HandleConvertSetting) {
|
||||||
totalDuration, err := h.convertorService.GetTotalDuration(setting.VideoFileInput)
|
h.app.GetQueue().Add(&kernel.ConvertSetting{
|
||||||
if err != nil {
|
VideoFileInput: setting.VideoFileInput,
|
||||||
return err
|
VideoFileOut: kernel.File{
|
||||||
}
|
Path: setting.DirectoryForSave + helper.PathSeparator() + setting.VideoFileInput.Name + ".mp4",
|
||||||
progress := NewProgress(totalDuration, progressbar, h.localizerService)
|
Name: setting.VideoFileInput.Name,
|
||||||
|
Ext: ".mp4",
|
||||||
return h.convertorService.RunConvert(
|
|
||||||
convertor.ConvertSetting{
|
|
||||||
VideoFileInput: setting.VideoFileInput,
|
|
||||||
VideoFileOut: &convertor.File{
|
|
||||||
Path: setting.DirectoryForSave + helper.PathSeparator() + setting.VideoFileInput.Name + ".mp4",
|
|
||||||
Name: setting.VideoFileInput.Name,
|
|
||||||
Ext: ".mp4",
|
|
||||||
},
|
|
||||||
OverwriteOutputFiles: setting.OverwriteOutputFiles,
|
|
||||||
},
|
},
|
||||||
progress,
|
OverwriteOutputFiles: setting.OverwriteOutputFiles,
|
||||||
)
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
func (h ConvertorHandler) checkingFFPathUtilities() bool {
|
func (h ConvertorHandler) checkingFFPathUtilities() bool {
|
||||||
@ -92,11 +74,11 @@ func (h ConvertorHandler) checkingFFPathUtilities() bool {
|
|||||||
|
|
||||||
pathsToFF := getPathsToFF()
|
pathsToFF := getPathsToFF()
|
||||||
for _, item := range pathsToFF {
|
for _, item := range pathsToFF {
|
||||||
ffmpegChecking, _ := h.convertorService.ChangeFFmpegPath(item.FFmpeg)
|
ffmpegChecking, _ := h.app.GetConvertorService().ChangeFFmpegPath(item.FFmpeg)
|
||||||
if ffmpegChecking == false {
|
if ffmpegChecking == false {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
ffprobeChecking, _ := h.convertorService.ChangeFFprobePath(item.FFprobe)
|
ffprobeChecking, _ := h.app.GetConvertorService().ChangeFFprobePath(item.FFprobe)
|
||||||
if ffprobeChecking == false {
|
if ffprobeChecking == false {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
@ -109,17 +91,17 @@ func (h ConvertorHandler) checkingFFPathUtilities() bool {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (h ConvertorHandler) saveSettingFFPath(ffmpegPath string, ffprobePath string) error {
|
func (h ConvertorHandler) saveSettingFFPath(ffmpegPath string, ffprobePath string) error {
|
||||||
ffmpegChecking, _ := h.convertorService.ChangeFFmpegPath(ffmpegPath)
|
ffmpegChecking, _ := h.app.GetConvertorService().ChangeFFmpegPath(ffmpegPath)
|
||||||
if ffmpegChecking == false {
|
if ffmpegChecking == false {
|
||||||
errorText := h.localizerService.GetMessage(&i18n.LocalizeConfig{
|
errorText := h.app.GetLocalizerService().GetMessage(&i18n.LocalizeConfig{
|
||||||
MessageID: "errorFFmpeg",
|
MessageID: "errorFFmpeg",
|
||||||
})
|
})
|
||||||
return errors.New(errorText)
|
return errors.New(errorText)
|
||||||
}
|
}
|
||||||
|
|
||||||
ffprobeChecking, _ := h.convertorService.ChangeFFprobePath(ffprobePath)
|
ffprobeChecking, _ := h.app.GetConvertorService().ChangeFFprobePath(ffprobePath)
|
||||||
if ffprobeChecking == false {
|
if ffprobeChecking == false {
|
||||||
errorText := h.localizerService.GetMessage(&i18n.LocalizeConfig{
|
errorText := h.app.GetLocalizerService().GetMessage(&i18n.LocalizeConfig{
|
||||||
MessageID: "errorFFprobe",
|
MessageID: "errorFFprobe",
|
||||||
})
|
})
|
||||||
return errors.New(errorText)
|
return errors.New(errorText)
|
||||||
@ -134,105 +116,15 @@ func (h ConvertorHandler) saveSettingFFPath(ffmpegPath string, ffprobePath strin
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (h ConvertorHandler) checkingFFPath() bool {
|
func (h ConvertorHandler) checkingFFPath() bool {
|
||||||
_, err := h.convertorService.GetFFmpegVesrion()
|
_, err := h.app.GetConvertorService().GetFFmpegVesrion()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
_, err = h.convertorService.GetFFprobeVersion()
|
_, err = h.app.GetConvertorService().GetFFprobeVersion()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
type Progress struct {
|
|
||||||
totalDuration float64
|
|
||||||
progressbar *widget.ProgressBar
|
|
||||||
protocol string
|
|
||||||
localizerService localizer.ServiceContract
|
|
||||||
}
|
|
||||||
|
|
||||||
func NewProgress(totalDuration float64, progressbar *widget.ProgressBar, localizerService localizer.ServiceContract) 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
|
|
||||||
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
|
|
||||||
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
|
|
||||||
p.progressbar.Refresh()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if isProcessCompleted == false {
|
|
||||||
if len(errorText) == 0 {
|
|
||||||
errorText = p.localizerService.GetMessage(&i18n.LocalizeConfig{
|
|
||||||
MessageID: "errorConverter",
|
|
||||||
})
|
|
||||||
}
|
|
||||||
return errors.New(errorText)
|
|
||||||
}
|
|
||||||
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
@ -6,11 +6,11 @@ package handler
|
|||||||
import (
|
import (
|
||||||
"fyne.io/fyne/v2/canvas"
|
"fyne.io/fyne/v2/canvas"
|
||||||
"fyne.io/fyne/v2/widget"
|
"fyne.io/fyne/v2/widget"
|
||||||
"git.kor-elf.net/kor-elf/gui-for-ffmpeg/convertor"
|
"git.kor-elf.net/kor-elf/gui-for-ffmpeg/kernel"
|
||||||
)
|
)
|
||||||
|
|
||||||
func getPathsToFF() []convertor.FFPathUtilities {
|
func getPathsToFF() []kernel.FFPathUtilities {
|
||||||
return []convertor.FFPathUtilities{{"ffmpeg/bin/ffmpeg", "ffmpeg/bin/ffprobe"}, {"ffmpeg", "ffprobe"}}
|
return []kernel.FFPathUtilities{{"ffmpeg/bin/ffmpeg", "ffmpeg/bin/ffprobe"}, {"ffmpeg", "ffprobe"}}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (h ConvertorHandler) downloadFFmpeg(progressBar *widget.ProgressBar, progressMessage *canvas.Text) (err error) {
|
func (h ConvertorHandler) downloadFFmpeg(progressBar *widget.ProgressBar, progressMessage *canvas.Text) (err error) {
|
||||||
|
@ -8,7 +8,7 @@ import (
|
|||||||
"errors"
|
"errors"
|
||||||
"fyne.io/fyne/v2/canvas"
|
"fyne.io/fyne/v2/canvas"
|
||||||
"fyne.io/fyne/v2/widget"
|
"fyne.io/fyne/v2/widget"
|
||||||
"git.kor-elf.net/kor-elf/gui-for-ffmpeg/src/convertor"
|
"git.kor-elf.net/kor-elf/gui-for-ffmpeg/kernel"
|
||||||
"github.com/nicksnyder/go-i18n/v2/i18n"
|
"github.com/nicksnyder/go-i18n/v2/i18n"
|
||||||
"io"
|
"io"
|
||||||
"net/http"
|
"net/http"
|
||||||
@ -17,8 +17,8 @@ import (
|
|||||||
"strings"
|
"strings"
|
||||||
)
|
)
|
||||||
|
|
||||||
func getPathsToFF() []convertor.FFPathUtilities {
|
func getPathsToFF() []kernel.FFPathUtilities {
|
||||||
return []convertor.FFPathUtilities{{"ffmpeg\\bin\\ffmpeg.exe", "ffmpeg\\bin\\ffprobe.exe"}}
|
return []kernel.FFPathUtilities{{"ffmpeg\\bin\\ffmpeg.exe", "ffmpeg\\bin\\ffprobe.exe"}}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (h ConvertorHandler) downloadFFmpeg(progressBar *widget.ProgressBar, progressMessage *canvas.Text) (err error) {
|
func (h ConvertorHandler) downloadFFmpeg(progressBar *widget.ProgressBar, progressMessage *canvas.Text) (err error) {
|
||||||
|
@ -1,27 +1,28 @@
|
|||||||
package handler
|
package handler
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"git.kor-elf.net/kor-elf/gui-for-ffmpeg/kernel"
|
||||||
"git.kor-elf.net/kor-elf/gui-for-ffmpeg/localizer"
|
"git.kor-elf.net/kor-elf/gui-for-ffmpeg/localizer"
|
||||||
)
|
)
|
||||||
|
|
||||||
type MainHandler struct {
|
type MainHandler struct {
|
||||||
|
app kernel.AppContract
|
||||||
convertorHandler ConvertorHandlerContract
|
convertorHandler ConvertorHandlerContract
|
||||||
menuHandler MenuHandlerContract
|
menuHandler MenuHandlerContract
|
||||||
localizerRepository localizer.RepositoryContract
|
localizerRepository localizer.RepositoryContract
|
||||||
localizerService localizer.ServiceContract
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewMainHandler(
|
func NewMainHandler(
|
||||||
|
app kernel.AppContract,
|
||||||
convertorHandler ConvertorHandlerContract,
|
convertorHandler ConvertorHandlerContract,
|
||||||
menuHandler MenuHandlerContract,
|
menuHandler MenuHandlerContract,
|
||||||
localizerRepository localizer.RepositoryContract,
|
localizerRepository localizer.RepositoryContract,
|
||||||
localizerService localizer.ServiceContract,
|
|
||||||
) *MainHandler {
|
) *MainHandler {
|
||||||
return &MainHandler{
|
return &MainHandler{
|
||||||
|
app: app,
|
||||||
convertorHandler: convertorHandler,
|
convertorHandler: convertorHandler,
|
||||||
menuHandler: menuHandler,
|
menuHandler: menuHandler,
|
||||||
localizerRepository: localizerRepository,
|
localizerRepository: localizerRepository,
|
||||||
localizerService: localizerService,
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -31,7 +32,7 @@ func (h MainHandler) Start() {
|
|||||||
h.menuHandler.LanguageSelection()
|
h.menuHandler.LanguageSelection()
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
_ = h.localizerService.SetCurrentLanguageByCode(language)
|
_ = h.app.GetLocalizerService().SetCurrentLanguageByCode(language)
|
||||||
|
|
||||||
h.convertorHandler.MainConvertor()
|
h.convertorHandler.MainConvertor()
|
||||||
}
|
}
|
||||||
|
@ -2,6 +2,7 @@ package handler
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"fyne.io/fyne/v2"
|
"fyne.io/fyne/v2"
|
||||||
|
"git.kor-elf.net/kor-elf/gui-for-ffmpeg/kernel"
|
||||||
"git.kor-elf.net/kor-elf/gui-for-ffmpeg/localizer"
|
"git.kor-elf.net/kor-elf/gui-for-ffmpeg/localizer"
|
||||||
"git.kor-elf.net/kor-elf/gui-for-ffmpeg/menu"
|
"git.kor-elf.net/kor-elf/gui-for-ffmpeg/menu"
|
||||||
"github.com/nicksnyder/go-i18n/v2/i18n"
|
"github.com/nicksnyder/go-i18n/v2/i18n"
|
||||||
@ -12,34 +13,30 @@ type MenuHandlerContract interface {
|
|||||||
LanguageSelection()
|
LanguageSelection()
|
||||||
}
|
}
|
||||||
|
|
||||||
type menuItems struct {
|
|
||||||
menuItem map[string]*fyne.MenuItem
|
|
||||||
menu map[string]*fyne.Menu
|
|
||||||
}
|
|
||||||
|
|
||||||
type MenuHandler struct {
|
type MenuHandler struct {
|
||||||
|
app kernel.AppContract
|
||||||
convertorHandler ConvertorHandlerContract
|
convertorHandler ConvertorHandlerContract
|
||||||
menuView menu.ViewContract
|
menuView menu.ViewContract
|
||||||
localizerService localizer.ServiceContract
|
|
||||||
localizerView localizer.ViewContract
|
localizerView localizer.ViewContract
|
||||||
localizerRepository localizer.RepositoryContract
|
localizerRepository localizer.RepositoryContract
|
||||||
menuItems *menuItems
|
localizerListener localizerListenerContract
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewMenuHandler(
|
func NewMenuHandler(
|
||||||
|
app kernel.AppContract,
|
||||||
convertorHandler ConvertorHandlerContract,
|
convertorHandler ConvertorHandlerContract,
|
||||||
menuView menu.ViewContract,
|
menuView menu.ViewContract,
|
||||||
localizerService localizer.ServiceContract,
|
|
||||||
localizerView localizer.ViewContract,
|
localizerView localizer.ViewContract,
|
||||||
localizerRepository localizer.RepositoryContract,
|
localizerRepository localizer.RepositoryContract,
|
||||||
|
localizerListener localizerListenerContract,
|
||||||
) *MenuHandler {
|
) *MenuHandler {
|
||||||
return &MenuHandler{
|
return &MenuHandler{
|
||||||
|
app: app,
|
||||||
convertorHandler: convertorHandler,
|
convertorHandler: convertorHandler,
|
||||||
menuView: menuView,
|
menuView: menuView,
|
||||||
localizerService: localizerService,
|
|
||||||
localizerView: localizerView,
|
localizerView: localizerView,
|
||||||
localizerRepository: localizerRepository,
|
localizerRepository: localizerRepository,
|
||||||
menuItems: &menuItems{menuItem: map[string]*fyne.MenuItem{}, menu: map[string]*fyne.Menu{}},
|
localizerListener: localizerListener,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -51,40 +48,40 @@ func (h MenuHandler) GetMainMenu() *fyne.MainMenu {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (h MenuHandler) getMenuSettings() *fyne.Menu {
|
func (h MenuHandler) getMenuSettings() *fyne.Menu {
|
||||||
quit := fyne.NewMenuItem(h.localizerService.GetMessage(&i18n.LocalizeConfig{
|
quit := fyne.NewMenuItem(h.app.GetLocalizerService().GetMessage(&i18n.LocalizeConfig{
|
||||||
MessageID: "exit",
|
MessageID: "exit",
|
||||||
}), nil)
|
}), nil)
|
||||||
quit.IsQuit = true
|
quit.IsQuit = true
|
||||||
h.menuItems.menuItem["exit"] = quit
|
h.localizerListener.AddMenuItem("exit", quit)
|
||||||
|
|
||||||
languageSelection := fyne.NewMenuItem(h.localizerService.GetMessage(&i18n.LocalizeConfig{
|
languageSelection := fyne.NewMenuItem(h.app.GetLocalizerService().GetMessage(&i18n.LocalizeConfig{
|
||||||
MessageID: "changeLanguage",
|
MessageID: "changeLanguage",
|
||||||
}), h.LanguageSelection)
|
}), h.LanguageSelection)
|
||||||
h.menuItems.menuItem["changeLanguage"] = languageSelection
|
h.localizerListener.AddMenuItem("changeLanguage", languageSelection)
|
||||||
|
|
||||||
ffPathSelection := fyne.NewMenuItem(h.localizerService.GetMessage(&i18n.LocalizeConfig{
|
ffPathSelection := fyne.NewMenuItem(h.app.GetLocalizerService().GetMessage(&i18n.LocalizeConfig{
|
||||||
MessageID: "changeFFPath",
|
MessageID: "changeFFPath",
|
||||||
}), h.convertorHandler.FfPathSelection)
|
}), h.convertorHandler.FfPathSelection)
|
||||||
h.menuItems.menuItem["changeFFPath"] = ffPathSelection
|
h.localizerListener.AddMenuItem("changeFFPath", ffPathSelection)
|
||||||
|
|
||||||
settings := fyne.NewMenu(h.localizerService.GetMessage(&i18n.LocalizeConfig{
|
settings := fyne.NewMenu(h.app.GetLocalizerService().GetMessage(&i18n.LocalizeConfig{
|
||||||
MessageID: "settings",
|
MessageID: "settings",
|
||||||
}), languageSelection, ffPathSelection, quit)
|
}), languageSelection, ffPathSelection, quit)
|
||||||
h.menuItems.menu["settings"] = settings
|
h.localizerListener.AddMenu("settings", settings)
|
||||||
|
|
||||||
return settings
|
return settings
|
||||||
}
|
}
|
||||||
|
|
||||||
func (h MenuHandler) getMenuHelp() *fyne.Menu {
|
func (h MenuHandler) getMenuHelp() *fyne.Menu {
|
||||||
about := fyne.NewMenuItem(h.localizerService.GetMessage(&i18n.LocalizeConfig{
|
about := fyne.NewMenuItem(h.app.GetLocalizerService().GetMessage(&i18n.LocalizeConfig{
|
||||||
MessageID: "about",
|
MessageID: "about",
|
||||||
}), h.openAbout)
|
}), h.openAbout)
|
||||||
h.menuItems.menuItem["about"] = about
|
h.localizerListener.AddMenuItem("about", about)
|
||||||
|
|
||||||
help := fyne.NewMenu(h.localizerService.GetMessage(&i18n.LocalizeConfig{
|
help := fyne.NewMenu(h.app.GetLocalizerService().GetMessage(&i18n.LocalizeConfig{
|
||||||
MessageID: "help",
|
MessageID: "help",
|
||||||
}), about)
|
}), about)
|
||||||
h.menuItems.menu["help"] = help
|
h.localizerListener.AddMenu("help", help)
|
||||||
|
|
||||||
return help
|
return help
|
||||||
}
|
}
|
||||||
@ -92,13 +89,13 @@ func (h MenuHandler) getMenuHelp() *fyne.Menu {
|
|||||||
func (h MenuHandler) openAbout() {
|
func (h MenuHandler) openAbout() {
|
||||||
ffmpeg, err := h.convertorHandler.GetFfmpegVersion()
|
ffmpeg, err := h.convertorHandler.GetFfmpegVersion()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ffmpeg = h.localizerService.GetMessage(&i18n.LocalizeConfig{
|
ffmpeg = h.app.GetLocalizerService().GetMessage(&i18n.LocalizeConfig{
|
||||||
MessageID: "errorFFmpegVersion",
|
MessageID: "errorFFmpegVersion",
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
ffprobe, err := h.convertorHandler.GetFfprobeVersion()
|
ffprobe, err := h.convertorHandler.GetFfprobeVersion()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ffprobe = h.localizerService.GetMessage(&i18n.LocalizeConfig{
|
ffprobe = h.app.GetLocalizerService().GetMessage(&i18n.LocalizeConfig{
|
||||||
MessageID: "errorFFprobeVersion",
|
MessageID: "errorFFprobeVersion",
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
@ -107,19 +104,46 @@ func (h MenuHandler) openAbout() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (h MenuHandler) LanguageSelection() {
|
func (h MenuHandler) LanguageSelection() {
|
||||||
h.localizerView.LanguageSelection(func(lang localizer.Lang) {
|
h.localizerView.LanguageSelection(func(lang kernel.Lang) {
|
||||||
_, _ = h.localizerRepository.Save(lang.Code)
|
_, _ = h.localizerRepository.Save(lang.Code)
|
||||||
h.menuMessageReload()
|
|
||||||
h.convertorHandler.MainConvertor()
|
h.convertorHandler.MainConvertor()
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
func (h MenuHandler) menuMessageReload() {
|
type menuItems struct {
|
||||||
for messageID, menu := range h.menuItems.menuItem {
|
menuItem map[string]*fyne.MenuItem
|
||||||
menu.Label = h.localizerService.GetMessage(&i18n.LocalizeConfig{MessageID: messageID})
|
menu map[string]*fyne.Menu
|
||||||
|
}
|
||||||
|
|
||||||
|
type LocalizerListener struct {
|
||||||
|
menuItems *menuItems
|
||||||
|
}
|
||||||
|
|
||||||
|
type localizerListenerContract interface {
|
||||||
|
AddMenu(messageID string, menu *fyne.Menu)
|
||||||
|
AddMenuItem(messageID string, menuItem *fyne.MenuItem)
|
||||||
|
}
|
||||||
|
|
||||||
|
func NewLocalizerListener() *LocalizerListener {
|
||||||
|
return &LocalizerListener{
|
||||||
|
&menuItems{menuItem: map[string]*fyne.MenuItem{}, menu: map[string]*fyne.Menu{}},
|
||||||
}
|
}
|
||||||
for messageID, menu := range h.menuItems.menu {
|
}
|
||||||
menu.Label = h.localizerService.GetMessage(&i18n.LocalizeConfig{MessageID: messageID})
|
|
||||||
|
func (l LocalizerListener) AddMenu(messageID string, menu *fyne.Menu) {
|
||||||
|
l.menuItems.menu[messageID] = menu
|
||||||
|
}
|
||||||
|
|
||||||
|
func (l LocalizerListener) AddMenuItem(messageID string, menuItem *fyne.MenuItem) {
|
||||||
|
l.menuItems.menuItem[messageID] = menuItem
|
||||||
|
}
|
||||||
|
|
||||||
|
func (l LocalizerListener) Change(localizerService kernel.LocalizerContract) {
|
||||||
|
for messageID, menu := range l.menuItems.menuItem {
|
||||||
|
menu.Label = localizerService.GetMessage(&i18n.LocalizeConfig{MessageID: messageID})
|
||||||
|
}
|
||||||
|
for messageID, menu := range l.menuItems.menu {
|
||||||
|
menu.Label = localizerService.GetMessage(&i18n.LocalizeConfig{MessageID: messageID})
|
||||||
menu.Refresh()
|
menu.Refresh()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
105
kernel/app.go
Normal file
105
kernel/app.go
Normal file
@ -0,0 +1,105 @@
|
|||||||
|
package kernel
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fyne.io/fyne/v2"
|
||||||
|
"fyne.io/fyne/v2/app"
|
||||||
|
"time"
|
||||||
|
)
|
||||||
|
|
||||||
|
type AppContract interface {
|
||||||
|
GetAppFyne() fyne.App
|
||||||
|
GetWindow() WindowContract
|
||||||
|
GetQueue() QueueListContract
|
||||||
|
GetLocalizerService() LocalizerContract
|
||||||
|
GetConvertorService() ConvertorContract
|
||||||
|
AfterClosing()
|
||||||
|
RunConvertor()
|
||||||
|
}
|
||||||
|
|
||||||
|
type App struct {
|
||||||
|
AppFyne fyne.App
|
||||||
|
Window WindowContract
|
||||||
|
Queue QueueListContract
|
||||||
|
|
||||||
|
localizerService LocalizerContract
|
||||||
|
convertorService ConvertorContract
|
||||||
|
}
|
||||||
|
|
||||||
|
func NewApp(
|
||||||
|
metadata *fyne.AppMetadata,
|
||||||
|
localizerService LocalizerContract,
|
||||||
|
queue QueueListContract,
|
||||||
|
queueLayoutObject QueueLayoutObjectContract,
|
||||||
|
convertorService ConvertorContract,
|
||||||
|
) *App {
|
||||||
|
app.SetMetadata(*metadata)
|
||||||
|
a := app.New()
|
||||||
|
|
||||||
|
return &App{
|
||||||
|
AppFyne: a,
|
||||||
|
Window: newWindow(a.NewWindow("GUI for FFmpeg"), NewLayout(queueLayoutObject, localizerService)),
|
||||||
|
Queue: queue,
|
||||||
|
|
||||||
|
localizerService: localizerService,
|
||||||
|
convertorService: convertorService,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (a App) GetAppFyne() fyne.App {
|
||||||
|
return a.AppFyne
|
||||||
|
}
|
||||||
|
|
||||||
|
func (a App) GetQueue() QueueListContract {
|
||||||
|
return a.Queue
|
||||||
|
}
|
||||||
|
|
||||||
|
func (a App) GetWindow() WindowContract {
|
||||||
|
return a.Window
|
||||||
|
}
|
||||||
|
|
||||||
|
func (a App) GetLocalizerService() LocalizerContract {
|
||||||
|
return a.localizerService
|
||||||
|
}
|
||||||
|
|
||||||
|
func (a App) GetConvertorService() ConvertorContract {
|
||||||
|
return a.convertorService
|
||||||
|
}
|
||||||
|
|
||||||
|
func (a App) AfterClosing() {
|
||||||
|
for _, cmd := range a.convertorService.GetRunningProcesses() {
|
||||||
|
_ = cmd.Process.Kill()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (a App) RunConvertor() {
|
||||||
|
go func() {
|
||||||
|
for {
|
||||||
|
time.Sleep(time.Millisecond * 3000)
|
||||||
|
queueId, queue := a.Queue.Next()
|
||||||
|
if queue == nil {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
queue.Status = StatusType(InProgress)
|
||||||
|
a.Window.GetLayout().ChangeQueueStatus(queueId, queue)
|
||||||
|
|
||||||
|
totalDuration, err := a.convertorService.GetTotalDuration(&queue.Setting.VideoFileInput)
|
||||||
|
if err != nil {
|
||||||
|
queue.Status = StatusType(Error)
|
||||||
|
queue.Error = err
|
||||||
|
a.Window.GetLayout().ChangeQueueStatus(queueId, queue)
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
progress := a.Window.GetLayout().NewProgressbar(queueId, totalDuration)
|
||||||
|
|
||||||
|
err = a.convertorService.RunConvert(*queue.Setting, progress)
|
||||||
|
if err != nil {
|
||||||
|
queue.Status = StatusType(Error)
|
||||||
|
queue.Error = err
|
||||||
|
a.Window.GetLayout().ChangeQueueStatus(queueId, queue)
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
queue.Status = StatusType(Completed)
|
||||||
|
a.Window.GetLayout().ChangeQueueStatus(queueId, queue)
|
||||||
|
}
|
||||||
|
}()
|
||||||
|
}
|
@ -1,4 +1,4 @@
|
|||||||
package convertor
|
package kernel
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"errors"
|
"errors"
|
||||||
@ -10,7 +10,7 @@ import (
|
|||||||
"strings"
|
"strings"
|
||||||
)
|
)
|
||||||
|
|
||||||
type ServiceContract interface {
|
type ConvertorContract interface {
|
||||||
RunConvert(setting ConvertSetting, progress ProgressContract) error
|
RunConvert(setting ConvertSetting, progress ProgressContract) error
|
||||||
GetTotalDuration(file *File) (float64, error)
|
GetTotalDuration(file *File) (float64, error)
|
||||||
GetFFmpegVesrion() (string, error)
|
GetFFmpegVesrion() (string, error)
|
||||||
@ -35,35 +35,23 @@ type runningProcesses struct {
|
|||||||
numberOfStarts int
|
numberOfStarts int
|
||||||
}
|
}
|
||||||
|
|
||||||
type Service struct {
|
type Convertor struct {
|
||||||
ffPathUtilities *FFPathUtilities
|
ffPathUtilities *FFPathUtilities
|
||||||
runningProcesses runningProcesses
|
runningProcesses runningProcesses
|
||||||
}
|
}
|
||||||
|
|
||||||
type File struct {
|
|
||||||
Path string
|
|
||||||
Name string
|
|
||||||
Ext string
|
|
||||||
}
|
|
||||||
|
|
||||||
type ConvertSetting struct {
|
|
||||||
VideoFileInput *File
|
|
||||||
VideoFileOut *File
|
|
||||||
OverwriteOutputFiles bool
|
|
||||||
}
|
|
||||||
|
|
||||||
type ConvertData struct {
|
type ConvertData struct {
|
||||||
totalDuration float64
|
totalDuration float64
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewService(ffPathUtilities FFPathUtilities) *Service {
|
func NewService(ffPathUtilities *FFPathUtilities) *Convertor {
|
||||||
return &Service{
|
return &Convertor{
|
||||||
ffPathUtilities: &ffPathUtilities,
|
ffPathUtilities: ffPathUtilities,
|
||||||
runningProcesses: runningProcesses{items: map[int]*exec.Cmd{}, numberOfStarts: 0},
|
runningProcesses: runningProcesses{items: map[int]*exec.Cmd{}, numberOfStarts: 0},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s Service) RunConvert(setting ConvertSetting, progress ProgressContract) error {
|
func (s Convertor) RunConvert(setting ConvertSetting, progress ProgressContract) error {
|
||||||
overwriteOutputFiles := "-n"
|
overwriteOutputFiles := "-n"
|
||||||
if setting.OverwriteOutputFiles == true {
|
if setting.OverwriteOutputFiles == true {
|
||||||
overwriteOutputFiles = "-y"
|
overwriteOutputFiles = "-y"
|
||||||
@ -103,7 +91,7 @@ func (s Service) RunConvert(setting ConvertSetting, progress ProgressContract) e
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s Service) GetTotalDuration(file *File) (duration float64, err error) {
|
func (s Convertor) GetTotalDuration(file *File) (duration float64, err error) {
|
||||||
args := []string{"-v", "error", "-select_streams", "v:0", "-count_packets", "-show_entries", "stream=nb_read_packets", "-of", "csv=p=0", file.Path}
|
args := []string{"-v", "error", "-select_streams", "v:0", "-count_packets", "-show_entries", "stream=nb_read_packets", "-of", "csv=p=0", file.Path}
|
||||||
cmd := exec.Command(s.ffPathUtilities.FFprobe, args...)
|
cmd := exec.Command(s.ffPathUtilities.FFprobe, args...)
|
||||||
helper.PrepareBackgroundCommand(cmd)
|
helper.PrepareBackgroundCommand(cmd)
|
||||||
@ -118,7 +106,7 @@ func (s Service) GetTotalDuration(file *File) (duration float64, err error) {
|
|||||||
return strconv.ParseFloat(strings.TrimSpace(string(out)), 64)
|
return strconv.ParseFloat(strings.TrimSpace(string(out)), 64)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s Service) GetFFmpegVesrion() (string, error) {
|
func (s Convertor) GetFFmpegVesrion() (string, error) {
|
||||||
cmd := exec.Command(s.ffPathUtilities.FFmpeg, "-version")
|
cmd := exec.Command(s.ffPathUtilities.FFmpeg, "-version")
|
||||||
helper.PrepareBackgroundCommand(cmd)
|
helper.PrepareBackgroundCommand(cmd)
|
||||||
out, err := cmd.CombinedOutput()
|
out, err := cmd.CombinedOutput()
|
||||||
@ -129,7 +117,7 @@ func (s Service) GetFFmpegVesrion() (string, error) {
|
|||||||
return text[0], nil
|
return text[0], nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s Service) GetFFprobeVersion() (string, error) {
|
func (s Convertor) GetFFprobeVersion() (string, error) {
|
||||||
cmd := exec.Command(s.ffPathUtilities.FFprobe, "-version")
|
cmd := exec.Command(s.ffPathUtilities.FFprobe, "-version")
|
||||||
helper.PrepareBackgroundCommand(cmd)
|
helper.PrepareBackgroundCommand(cmd)
|
||||||
out, err := cmd.CombinedOutput()
|
out, err := cmd.CombinedOutput()
|
||||||
@ -140,7 +128,7 @@ func (s Service) GetFFprobeVersion() (string, error) {
|
|||||||
return text[0], nil
|
return text[0], nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s Service) ChangeFFmpegPath(path string) (bool, error) {
|
func (s Convertor) ChangeFFmpegPath(path string) (bool, error) {
|
||||||
cmd := exec.Command(path, "-version")
|
cmd := exec.Command(path, "-version")
|
||||||
helper.PrepareBackgroundCommand(cmd)
|
helper.PrepareBackgroundCommand(cmd)
|
||||||
out, err := cmd.CombinedOutput()
|
out, err := cmd.CombinedOutput()
|
||||||
@ -154,7 +142,7 @@ func (s Service) ChangeFFmpegPath(path string) (bool, error) {
|
|||||||
return true, nil
|
return true, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s Service) ChangeFFprobePath(path string) (bool, error) {
|
func (s Convertor) ChangeFFprobePath(path string) (bool, error) {
|
||||||
cmd := exec.Command(path, "-version")
|
cmd := exec.Command(path, "-version")
|
||||||
helper.PrepareBackgroundCommand(cmd)
|
helper.PrepareBackgroundCommand(cmd)
|
||||||
out, err := cmd.CombinedOutput()
|
out, err := cmd.CombinedOutput()
|
||||||
@ -168,6 +156,6 @@ func (s Service) ChangeFFprobePath(path string) (bool, error) {
|
|||||||
return true, nil
|
return true, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s Service) GetRunningProcesses() map[int]*exec.Cmd {
|
func (s Convertor) GetRunningProcesses() map[int]*exec.Cmd {
|
||||||
return s.runningProcesses.items
|
return s.runningProcesses.items
|
||||||
}
|
}
|
20
kernel/error.go
Normal file
20
kernel/error.go
Normal file
@ -0,0 +1,20 @@
|
|||||||
|
package kernel
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fyne.io/fyne/v2"
|
||||||
|
"fyne.io/fyne/v2/app"
|
||||||
|
"fyne.io/fyne/v2/container"
|
||||||
|
"fyne.io/fyne/v2/widget"
|
||||||
|
)
|
||||||
|
|
||||||
|
func PanicErrorLang(err error, metadata *fyne.AppMetadata) {
|
||||||
|
app.SetMetadata(*metadata)
|
||||||
|
a := app.New()
|
||||||
|
window := a.NewWindow("GUI for FFmpeg")
|
||||||
|
window.SetContent(container.NewVBox(
|
||||||
|
widget.NewLabel("Произошла ошибка!"),
|
||||||
|
widget.NewLabel("произошла ошибка при получении языковых переводах. \n\r"+err.Error()),
|
||||||
|
))
|
||||||
|
window.ShowAndRun()
|
||||||
|
panic(err.Error())
|
||||||
|
}
|
288
kernel/layout.go
Normal file
288
kernel/layout.go
Normal file
@ -0,0 +1,288 @@
|
|||||||
|
package kernel
|
||||||
|
|
||||||
|
import (
|
||||||
|
"bufio"
|
||||||
|
"errors"
|
||||||
|
"fyne.io/fyne/v2"
|
||||||
|
"fyne.io/fyne/v2/canvas"
|
||||||
|
"fyne.io/fyne/v2/container"
|
||||||
|
"fyne.io/fyne/v2/theme"
|
||||||
|
"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)
|
||||||
|
}
|
||||||
|
|
||||||
|
type Layout struct {
|
||||||
|
layout *fyne.Container
|
||||||
|
queueLayoutObject QueueLayoutObjectContract
|
||||||
|
localizerService LocalizerContract
|
||||||
|
}
|
||||||
|
|
||||||
|
func NewLayout(queueLayoutObject QueueLayoutObjectContract, localizerService LocalizerContract) *Layout {
|
||||||
|
layout := container.NewAdaptiveGrid(2, widget.NewLabel(""), container.NewVScroll(queueLayoutObject.GetCanvasObject()))
|
||||||
|
|
||||||
|
return &Layout{
|
||||||
|
layout: layout,
|
||||||
|
queueLayoutObject: queueLayoutObject,
|
||||||
|
localizerService: localizerService,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (l Layout) SetContent(content fyne.CanvasObject) *fyne.Container {
|
||||||
|
l.layout.Objects[0] = content
|
||||||
|
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)
|
||||||
|
}
|
||||||
|
|
||||||
|
type QueueLayoutObjectContract interface {
|
||||||
|
GetCanvasObject() fyne.CanvasObject
|
||||||
|
GetProgressbar(queueId int) *widget.ProgressBar
|
||||||
|
ChangeQueueStatus(queueId int, queue *Queue)
|
||||||
|
}
|
||||||
|
|
||||||
|
type QueueLayoutObject struct {
|
||||||
|
QueueListContract QueueListContract
|
||||||
|
|
||||||
|
queue QueueListContract
|
||||||
|
container *fyne.Container
|
||||||
|
items map[int]QueueLayoutItem
|
||||||
|
localizerService LocalizerContract
|
||||||
|
layoutLocalizerListener LayoutLocalizerListenerContract
|
||||||
|
}
|
||||||
|
|
||||||
|
type QueueLayoutItem struct {
|
||||||
|
CanvasObject fyne.CanvasObject
|
||||||
|
ProgressBar *widget.ProgressBar
|
||||||
|
StatusMessage *canvas.Text
|
||||||
|
MessageError *canvas.Text
|
||||||
|
}
|
||||||
|
|
||||||
|
func NewQueueLayoutObject(queue QueueListContract, localizerService LocalizerContract, layoutLocalizerListener LayoutLocalizerListenerContract) *QueueLayoutObject {
|
||||||
|
title := widget.NewLabel(localizerService.GetMessage(&i18n.LocalizeConfig{MessageID: "queue"}) + ":")
|
||||||
|
title.TextStyle.Bold = true
|
||||||
|
|
||||||
|
layoutLocalizerListener.AddItem("queue", title)
|
||||||
|
|
||||||
|
queueLayoutObject := &QueueLayoutObject{
|
||||||
|
queue: queue,
|
||||||
|
container: container.NewVBox(title),
|
||||||
|
items: map[int]QueueLayoutItem{},
|
||||||
|
localizerService: localizerService,
|
||||||
|
layoutLocalizerListener: layoutLocalizerListener,
|
||||||
|
}
|
||||||
|
|
||||||
|
queue.AddListener(queueLayoutObject)
|
||||||
|
|
||||||
|
return queueLayoutObject
|
||||||
|
}
|
||||||
|
|
||||||
|
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.PrimaryColor())
|
||||||
|
messageError := canvas.NewText("", theme.ErrorColor())
|
||||||
|
|
||||||
|
content := container.NewVBox(
|
||||||
|
container.NewHScroll(widget.NewLabel(queue.Setting.VideoFileInput.Name)),
|
||||||
|
progressBar,
|
||||||
|
container.NewHScroll(statusMessage),
|
||||||
|
container.NewHScroll(messageError),
|
||||||
|
canvas.NewLine(theme.FocusColor()),
|
||||||
|
container.NewPadded(),
|
||||||
|
)
|
||||||
|
o.items[id] = QueueLayoutItem{
|
||||||
|
CanvasObject: content,
|
||||||
|
ProgressBar: progressBar,
|
||||||
|
StatusMessage: statusMessage,
|
||||||
|
MessageError: messageError,
|
||||||
|
}
|
||||||
|
o.container.Add(content)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (o QueueLayoutObject) Remove(id int) {
|
||||||
|
if item, ok := o.items[id]; ok {
|
||||||
|
o.container.Remove(item.CanvasObject)
|
||||||
|
o.items[id] = QueueLayoutItem{}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (o QueueLayoutObject) ChangeQueueStatus(queueId int, queue *Queue) {
|
||||||
|
if item, ok := o.items[queueId]; ok {
|
||||||
|
statusColor := o.getStatusColor(queue.Status)
|
||||||
|
item.StatusMessage.Text = o.getStatusTitle(queue.Status)
|
||||||
|
item.StatusMessage.Color = statusColor
|
||||||
|
item.StatusMessage.Refresh()
|
||||||
|
if queue.Error != nil {
|
||||||
|
item.MessageError.Text = queue.Error.Error()
|
||||||
|
item.MessageError.Color = statusColor
|
||||||
|
item.MessageError.Refresh()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (o QueueLayoutObject) getStatusColor(status StatusContract) color.Color {
|
||||||
|
if status == StatusType(Error) {
|
||||||
|
return theme.ErrorColor()
|
||||||
|
}
|
||||||
|
|
||||||
|
if status == StatusType(Completed) {
|
||||||
|
return color.RGBA{R: 49, G: 127, B: 114, A: 255}
|
||||||
|
}
|
||||||
|
|
||||||
|
return theme.PrimaryColor()
|
||||||
|
}
|
||||||
|
|
||||||
|
func (o QueueLayoutObject) getStatusTitle(status StatusContract) string {
|
||||||
|
return o.localizerService.GetMessage(&i18n.LocalizeConfig{MessageID: status.name()})
|
||||||
|
}
|
||||||
|
|
||||||
|
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
|
||||||
|
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
|
||||||
|
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
|
||||||
|
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 LayoutLocalizerItem struct {
|
||||||
|
messageID string
|
||||||
|
object *widget.Label
|
||||||
|
}
|
||||||
|
|
||||||
|
type LayoutLocalizerListener struct {
|
||||||
|
itemCurrentId int
|
||||||
|
items map[int]*LayoutLocalizerItem
|
||||||
|
}
|
||||||
|
|
||||||
|
type LayoutLocalizerListenerContract interface {
|
||||||
|
AddItem(messageID string, object *widget.Label)
|
||||||
|
}
|
||||||
|
|
||||||
|
func NewLayoutLocalizerListener() *LayoutLocalizerListener {
|
||||||
|
return &LayoutLocalizerListener{
|
||||||
|
itemCurrentId: 0,
|
||||||
|
items: map[int]*LayoutLocalizerItem{},
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (l LayoutLocalizerListener) AddItem(messageID string, object *widget.Label) {
|
||||||
|
l.itemCurrentId += 1
|
||||||
|
l.items[l.itemCurrentId] = &LayoutLocalizerItem{messageID: messageID, object: object}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (l LayoutLocalizerListener) Change(localizerService LocalizerContract) {
|
||||||
|
for _, item := range l.items {
|
||||||
|
item.object.Text = localizerService.GetMessage(&i18n.LocalizeConfig{MessageID: item.messageID})
|
||||||
|
item.object.Refresh()
|
||||||
|
}
|
||||||
|
}
|
@ -1,4 +1,4 @@
|
|||||||
package localizer
|
package kernel
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/BurntSushi/toml"
|
"github.com/BurntSushi/toml"
|
||||||
@ -10,12 +10,17 @@ import (
|
|||||||
"sort"
|
"sort"
|
||||||
)
|
)
|
||||||
|
|
||||||
type ServiceContract interface {
|
type LocalizerContract interface {
|
||||||
GetLanguages() []Lang
|
GetLanguages() []Lang
|
||||||
GetMessage(localizeConfig *i18n.LocalizeConfig) string
|
GetMessage(localizeConfig *i18n.LocalizeConfig) string
|
||||||
SetCurrentLanguage(lang Lang) error
|
SetCurrentLanguage(lang Lang) error
|
||||||
SetCurrentLanguageByCode(code string) error
|
SetCurrentLanguageByCode(code string) error
|
||||||
GetCurrentLanguage() *CurrentLanguage
|
GetCurrentLanguage() *CurrentLanguage
|
||||||
|
AddListener(listener LocalizerListenerContract)
|
||||||
|
}
|
||||||
|
|
||||||
|
type LocalizerListenerContract interface {
|
||||||
|
Change(localizerService LocalizerContract)
|
||||||
}
|
}
|
||||||
|
|
||||||
type Lang struct {
|
type Lang struct {
|
||||||
@ -29,13 +34,14 @@ type CurrentLanguage struct {
|
|||||||
localizerDefault *i18n.Localizer
|
localizerDefault *i18n.Localizer
|
||||||
}
|
}
|
||||||
|
|
||||||
type Service struct {
|
type Localizer struct {
|
||||||
bundle *i18n.Bundle
|
bundle *i18n.Bundle
|
||||||
languages []Lang
|
languages []Lang
|
||||||
currentLanguage *CurrentLanguage
|
currentLanguage *CurrentLanguage
|
||||||
|
localizerListener map[int]LocalizerListenerContract
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewService(directory string, languageDefault language.Tag) (*Service, error) {
|
func NewLocalizer(directory string, languageDefault language.Tag) (*Localizer, error) {
|
||||||
bundle := i18n.NewBundle(languageDefault)
|
bundle := i18n.NewBundle(languageDefault)
|
||||||
bundle.RegisterUnmarshalFunc("toml", toml.Unmarshal)
|
bundle.RegisterUnmarshalFunc("toml", toml.Unmarshal)
|
||||||
|
|
||||||
@ -46,7 +52,7 @@ func NewService(directory string, languageDefault language.Tag) (*Service, error
|
|||||||
|
|
||||||
localizerDefault := i18n.NewLocalizer(bundle, languageDefault.String())
|
localizerDefault := i18n.NewLocalizer(bundle, languageDefault.String())
|
||||||
|
|
||||||
return &Service{
|
return &Localizer{
|
||||||
bundle: bundle,
|
bundle: bundle,
|
||||||
languages: languages,
|
languages: languages,
|
||||||
currentLanguage: &CurrentLanguage{
|
currentLanguage: &CurrentLanguage{
|
||||||
@ -57,6 +63,7 @@ func NewService(directory string, languageDefault language.Tag) (*Service, error
|
|||||||
localizer: localizerDefault,
|
localizer: localizerDefault,
|
||||||
localizerDefault: localizerDefault,
|
localizerDefault: localizerDefault,
|
||||||
},
|
},
|
||||||
|
localizerListener: map[int]LocalizerListenerContract{},
|
||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -81,14 +88,14 @@ func initLanguages(directory string, bundle *i18n.Bundle) ([]Lang, error) {
|
|||||||
return languages, nil
|
return languages, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s Service) GetLanguages() []Lang {
|
func (l Localizer) GetLanguages() []Lang {
|
||||||
return s.languages
|
return l.languages
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s Service) GetMessage(localizeConfig *i18n.LocalizeConfig) string {
|
func (l Localizer) GetMessage(localizeConfig *i18n.LocalizeConfig) string {
|
||||||
message, err := s.GetCurrentLanguage().localizer.Localize(localizeConfig)
|
message, err := l.GetCurrentLanguage().localizer.Localize(localizeConfig)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
message, err = s.GetCurrentLanguage().localizerDefault.Localize(localizeConfig)
|
message, err = l.GetCurrentLanguage().localizerDefault.Localize(localizeConfig)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err.Error()
|
return err.Error()
|
||||||
}
|
}
|
||||||
@ -96,23 +103,34 @@ func (s Service) GetMessage(localizeConfig *i18n.LocalizeConfig) string {
|
|||||||
return message
|
return message
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s Service) SetCurrentLanguage(lang Lang) error {
|
func (l Localizer) SetCurrentLanguage(lang Lang) error {
|
||||||
s.currentLanguage.Lang = lang
|
l.currentLanguage.Lang = lang
|
||||||
s.currentLanguage.localizer = i18n.NewLocalizer(s.bundle, lang.Code)
|
l.currentLanguage.localizer = i18n.NewLocalizer(l.bundle, lang.Code)
|
||||||
|
l.eventSetCurrentLanguage()
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s Service) SetCurrentLanguageByCode(code string) error {
|
func (l Localizer) SetCurrentLanguageByCode(code string) error {
|
||||||
lang, err := language.Parse(code)
|
lang, err := language.Parse(code)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
title := cases.Title(lang).String(display.Self.Name(lang))
|
title := cases.Title(lang).String(display.Self.Name(lang))
|
||||||
return s.SetCurrentLanguage(Lang{Code: lang.String(), Title: title})
|
return l.SetCurrentLanguage(Lang{Code: lang.String(), Title: title})
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s Service) GetCurrentLanguage() *CurrentLanguage {
|
func (l Localizer) GetCurrentLanguage() *CurrentLanguage {
|
||||||
return s.currentLanguage
|
return l.currentLanguage
|
||||||
|
}
|
||||||
|
|
||||||
|
func (l Localizer) AddListener(listener LocalizerListenerContract) {
|
||||||
|
l.localizerListener[len(l.localizerListener)] = listener
|
||||||
|
}
|
||||||
|
|
||||||
|
func (l Localizer) eventSetCurrentLanguage() {
|
||||||
|
for _, listener := range l.localizerListener {
|
||||||
|
listener.Change(l)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
type languagesSort []Lang
|
type languagesSort []Lang
|
137
kernel/queue.go
Normal file
137
kernel/queue.go
Normal file
@ -0,0 +1,137 @@
|
|||||||
|
package kernel
|
||||||
|
|
||||||
|
import (
|
||||||
|
"errors"
|
||||||
|
)
|
||||||
|
|
||||||
|
type Queue struct {
|
||||||
|
Setting *ConvertSetting
|
||||||
|
Status StatusContract
|
||||||
|
Error error
|
||||||
|
}
|
||||||
|
|
||||||
|
type File struct {
|
||||||
|
Path string
|
||||||
|
Name string
|
||||||
|
Ext string
|
||||||
|
}
|
||||||
|
|
||||||
|
type ConvertSetting struct {
|
||||||
|
VideoFileInput File
|
||||||
|
VideoFileOut File
|
||||||
|
OverwriteOutputFiles bool
|
||||||
|
}
|
||||||
|
|
||||||
|
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 {
|
||||||
|
Add(key int, queue *Queue)
|
||||||
|
Remove(key int)
|
||||||
|
}
|
||||||
|
|
||||||
|
type QueueListContract interface {
|
||||||
|
AddListener(queueListener QueueListenerContract)
|
||||||
|
GetItems() map[int]*Queue
|
||||||
|
Add(setting *ConvertSetting)
|
||||||
|
Remove(key int)
|
||||||
|
GetItem(key int) (*Queue, error)
|
||||||
|
Next() (key int, queue *Queue)
|
||||||
|
}
|
||||||
|
|
||||||
|
type QueueList struct {
|
||||||
|
currentKey *int
|
||||||
|
items map[int]*Queue
|
||||||
|
queueListener map[int]QueueListenerContract
|
||||||
|
}
|
||||||
|
|
||||||
|
func NewQueueList() *QueueList {
|
||||||
|
currentKey := 0
|
||||||
|
return &QueueList{
|
||||||
|
currentKey: ¤tKey,
|
||||||
|
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.eventAdd(*l.currentKey, &queue)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (l QueueList) Remove(key int) {
|
||||||
|
if _, ok := l.items[key]; ok {
|
||||||
|
delete(l.items, key)
|
||||||
|
l.eventRemove(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) eventAdd(key int, queue *Queue) {
|
||||||
|
for _, listener := range l.queueListener {
|
||||||
|
listener.Add(key, queue)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (l QueueList) eventRemove(key int) {
|
||||||
|
for _, listener := range l.queueListener {
|
||||||
|
listener.Remove(key)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (l QueueList) Next() (key int, queue *Queue) {
|
||||||
|
statusWaiting := StatusType(Waiting)
|
||||||
|
for key, item := range l.items {
|
||||||
|
if item.Status == statusWaiting {
|
||||||
|
return key, item
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return -1, nil
|
||||||
|
}
|
67
kernel/window.go
Normal file
67
kernel/window.go
Normal file
@ -0,0 +1,67 @@
|
|||||||
|
package kernel
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fyne.io/fyne/v2"
|
||||||
|
"fyne.io/fyne/v2/dialog"
|
||||||
|
"git.kor-elf.net/kor-elf/gui-for-ffmpeg/helper"
|
||||||
|
)
|
||||||
|
|
||||||
|
type WindowContract interface {
|
||||||
|
SetContent(content fyne.CanvasObject)
|
||||||
|
SetMainMenu(menu *fyne.MainMenu)
|
||||||
|
NewFileOpen(callback func(fyne.URIReadCloser, error), location fyne.ListableURI) *dialog.FileDialog
|
||||||
|
NewFolderOpen(callback func(fyne.ListableURI, error), location fyne.ListableURI) *dialog.FileDialog
|
||||||
|
ShowAndRun()
|
||||||
|
GetLayout() LayoutContract
|
||||||
|
}
|
||||||
|
|
||||||
|
type Window struct {
|
||||||
|
windowFyne fyne.Window
|
||||||
|
layout LayoutContract
|
||||||
|
}
|
||||||
|
|
||||||
|
func newWindow(w fyne.Window, layout LayoutContract) Window {
|
||||||
|
w.Resize(fyne.Size{Width: 799, Height: 599})
|
||||||
|
w.CenterOnScreen()
|
||||||
|
|
||||||
|
return Window{
|
||||||
|
windowFyne: w,
|
||||||
|
layout: layout,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (w Window) SetContent(content fyne.CanvasObject) {
|
||||||
|
w.windowFyne.SetContent(w.layout.SetContent(content))
|
||||||
|
}
|
||||||
|
|
||||||
|
func (w Window) NewFileOpen(callback func(fyne.URIReadCloser, error), location fyne.ListableURI) *dialog.FileDialog {
|
||||||
|
fileDialog := dialog.NewFileOpen(callback, w.windowFyne)
|
||||||
|
helper.FileDialogResize(fileDialog, w.windowFyne)
|
||||||
|
fileDialog.Show()
|
||||||
|
if location != nil {
|
||||||
|
fileDialog.SetLocation(location)
|
||||||
|
}
|
||||||
|
return fileDialog
|
||||||
|
}
|
||||||
|
|
||||||
|
func (w Window) NewFolderOpen(callback func(fyne.ListableURI, error), location fyne.ListableURI) *dialog.FileDialog {
|
||||||
|
fileDialog := dialog.NewFolderOpen(callback, w.windowFyne)
|
||||||
|
helper.FileDialogResize(fileDialog, w.windowFyne)
|
||||||
|
fileDialog.Show()
|
||||||
|
if location != nil {
|
||||||
|
fileDialog.SetLocation(location)
|
||||||
|
}
|
||||||
|
return fileDialog
|
||||||
|
}
|
||||||
|
|
||||||
|
func (w Window) SetMainMenu(menu *fyne.MainMenu) {
|
||||||
|
w.windowFyne.SetMainMenu(menu)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (w Window) ShowAndRun() {
|
||||||
|
w.windowFyne.ShowAndRun()
|
||||||
|
}
|
||||||
|
|
||||||
|
func (w Window) GetLayout() LayoutContract {
|
||||||
|
return w.layout
|
||||||
|
}
|
@ -38,6 +38,10 @@ other = "Allow file to be overwritten"
|
|||||||
hash = "sha1-f60bb5f761024d973834b5e9d25ceebce2c85f94"
|
hash = "sha1-f60bb5f761024d973834b5e9d25ceebce2c85f94"
|
||||||
other = "choose"
|
other = "choose"
|
||||||
|
|
||||||
|
[completed]
|
||||||
|
hash = "sha1-398c7d4f7b0d522afb930769c0fbb1a9f4b61fbe"
|
||||||
|
other = "Completed"
|
||||||
|
|
||||||
[converterVideoFilesSubmitTitle]
|
[converterVideoFilesSubmitTitle]
|
||||||
hash = "sha1-7ac460f3c24c9952082f2db6e4d62f752598709c"
|
hash = "sha1-7ac460f3c24c9952082f2db6e4d62f752598709c"
|
||||||
other = "Convert"
|
other = "Convert"
|
||||||
@ -110,6 +114,10 @@ other = "File for conversion:"
|
|||||||
hash = "sha1-6a45cef900c668effcb2ab10da05855c1fd10f6f"
|
hash = "sha1-6a45cef900c668effcb2ab10da05855c1fd10f6f"
|
||||||
other = "Help"
|
other = "Help"
|
||||||
|
|
||||||
|
[inProgress]
|
||||||
|
hash = "sha1-eff79c40e2100ae5fadf3a7d99336025edcca8b5"
|
||||||
|
other = "In Progress"
|
||||||
|
|
||||||
[languageSelectionFormHead]
|
[languageSelectionFormHead]
|
||||||
hash = "sha1-0ff5fa82cf684112660128cba1711297acf11003"
|
hash = "sha1-0ff5fa82cf684112660128cba1711297acf11003"
|
||||||
other = "Switch language"
|
other = "Switch language"
|
||||||
@ -142,6 +150,10 @@ other = "Project website"
|
|||||||
hash = "sha1-fa2e4994a301bb24bc2a8fa166e5486ea95a7475"
|
hash = "sha1-fa2e4994a301bb24bc2a8fa166e5486ea95a7475"
|
||||||
other = "**Program version:** {{.Version}}"
|
other = "**Program version:** {{.Version}}"
|
||||||
|
|
||||||
|
[queue]
|
||||||
|
hash = "sha1-aec93b16baeaf55fed871075c9494a460e4a91b8"
|
||||||
|
other = "Queue"
|
||||||
|
|
||||||
[save]
|
[save]
|
||||||
hash = "sha1-4864057d626a868fa60f999bed3191d61d045ddc"
|
hash = "sha1-4864057d626a868fa60f999bed3191d61d045ddc"
|
||||||
other = "Save"
|
other = "Save"
|
||||||
@ -165,3 +177,7 @@ other = "You can download it from here"
|
|||||||
[unzipRun]
|
[unzipRun]
|
||||||
hash = "sha1-c554dad13026668a1f6adf3171837c5d51bbac36"
|
hash = "sha1-c554dad13026668a1f6adf3171837c5d51bbac36"
|
||||||
other = "Unpacked..."
|
other = "Unpacked..."
|
||||||
|
|
||||||
|
[waiting]
|
||||||
|
hash = "sha1-307429dd84150877080c4bbff2b340d1e7dadff2"
|
||||||
|
other = "Waiting"
|
||||||
|
@ -38,6 +38,10 @@ other = "Файлды қайта жазуға рұқсат беріңіз"
|
|||||||
hash = "sha1-f60bb5f761024d973834b5e9d25ceebce2c85f94"
|
hash = "sha1-f60bb5f761024d973834b5e9d25ceebce2c85f94"
|
||||||
other = "таңдау"
|
other = "таңдау"
|
||||||
|
|
||||||
|
[completed]
|
||||||
|
hash = "sha1-398c7d4f7b0d522afb930769c0fbb1a9f4b61fbe"
|
||||||
|
other = "Дайын"
|
||||||
|
|
||||||
[converterVideoFilesSubmitTitle]
|
[converterVideoFilesSubmitTitle]
|
||||||
hash = "sha1-7ac460f3c24c9952082f2db6e4d62f752598709c"
|
hash = "sha1-7ac460f3c24c9952082f2db6e4d62f752598709c"
|
||||||
other = "Файлды түрлендіру"
|
other = "Файлды түрлендіру"
|
||||||
@ -110,6 +114,10 @@ other = "Түрлендіруге арналған файл:"
|
|||||||
hash = "sha1-6a45cef900c668effcb2ab10da05855c1fd10f6f"
|
hash = "sha1-6a45cef900c668effcb2ab10da05855c1fd10f6f"
|
||||||
other = "Анықтама"
|
other = "Анықтама"
|
||||||
|
|
||||||
|
[inProgress]
|
||||||
|
hash = "sha1-eff79c40e2100ae5fadf3a7d99336025edcca8b5"
|
||||||
|
other = "Орындалуда"
|
||||||
|
|
||||||
[languageSelectionFormHead]
|
[languageSelectionFormHead]
|
||||||
hash = "sha1-0ff5fa82cf684112660128cba1711297acf11003"
|
hash = "sha1-0ff5fa82cf684112660128cba1711297acf11003"
|
||||||
other = "Тілді ауыстыру"
|
other = "Тілді ауыстыру"
|
||||||
@ -142,6 +150,10 @@ other = "Жобаның веб-сайты"
|
|||||||
hash = "sha1-fa2e4994a301bb24bc2a8fa166e5486ea95a7475"
|
hash = "sha1-fa2e4994a301bb24bc2a8fa166e5486ea95a7475"
|
||||||
other = "**Бағдарлама нұсқасы:** {{.Version}}"
|
other = "**Бағдарлама нұсқасы:** {{.Version}}"
|
||||||
|
|
||||||
|
[queue]
|
||||||
|
hash = "sha1-aec93b16baeaf55fed871075c9494a460e4a91b8"
|
||||||
|
other = "Кезек"
|
||||||
|
|
||||||
[save]
|
[save]
|
||||||
hash = "sha1-4864057d626a868fa60f999bed3191d61d045ddc"
|
hash = "sha1-4864057d626a868fa60f999bed3191d61d045ddc"
|
||||||
other = "Сақтау"
|
other = "Сақтау"
|
||||||
@ -165,3 +177,7 @@ other = "Сіз оны осы жерден жүктей аласыз"
|
|||||||
[unzipRun]
|
[unzipRun]
|
||||||
hash = "sha1-c554dad13026668a1f6adf3171837c5d51bbac36"
|
hash = "sha1-c554dad13026668a1f6adf3171837c5d51bbac36"
|
||||||
other = "Орамнан шығарылуда..."
|
other = "Орамнан шығарылуда..."
|
||||||
|
|
||||||
|
[waiting]
|
||||||
|
hash = "sha1-307429dd84150877080c4bbff2b340d1e7dadff2"
|
||||||
|
other = "Күту"
|
||||||
|
@ -8,6 +8,7 @@ changeFFPath = "FFmpeg и FFprobe"
|
|||||||
changeLanguage = "Поменять язык"
|
changeLanguage = "Поменять язык"
|
||||||
checkboxOverwriteOutputFilesTitle = "Разрешить перезаписать файл"
|
checkboxOverwriteOutputFilesTitle = "Разрешить перезаписать файл"
|
||||||
choose = "выбрать"
|
choose = "выбрать"
|
||||||
|
completed = "Готово"
|
||||||
converterVideoFilesSubmitTitle = "Конвертировать"
|
converterVideoFilesSubmitTitle = "Конвертировать"
|
||||||
converterVideoFilesTitle = "Конвертор видео файлов в mp4"
|
converterVideoFilesTitle = "Конвертор видео файлов в mp4"
|
||||||
download = "Скачать"
|
download = "Скачать"
|
||||||
@ -26,6 +27,7 @@ ffmpegLGPL = "Это программное обеспечение исполь
|
|||||||
ffmpegTrademark = "**FFmpeg** — торговая марка **[Fabrice Bellard](http://bellard.org/)** , создателя проекта **[FFmpeg](https://ffmpeg.org/about.html)**."
|
ffmpegTrademark = "**FFmpeg** — торговая марка **[Fabrice Bellard](http://bellard.org/)** , создателя проекта **[FFmpeg](https://ffmpeg.org/about.html)**."
|
||||||
fileVideoForConversionTitle = "Файл для ковертации:"
|
fileVideoForConversionTitle = "Файл для ковертации:"
|
||||||
help = "Справка"
|
help = "Справка"
|
||||||
|
inProgress = "Выполняется"
|
||||||
languageSelectionFormHead = "Переключить язык"
|
languageSelectionFormHead = "Переключить язык"
|
||||||
languageSelectionHead = "Выберите язык"
|
languageSelectionHead = "Выберите язык"
|
||||||
licenseLink = "Сведения о лицензии"
|
licenseLink = "Сведения о лицензии"
|
||||||
@ -34,9 +36,11 @@ pathToFfmpeg = "Путь к FFmpeg:"
|
|||||||
pathToFfprobe = "Путь к FFprobe:"
|
pathToFfprobe = "Путь к FFprobe:"
|
||||||
programmLink = "Сайт проекта"
|
programmLink = "Сайт проекта"
|
||||||
programmVersion = "**Версия программы:** {{.Version}}"
|
programmVersion = "**Версия программы:** {{.Version}}"
|
||||||
|
queue = "Очередь"
|
||||||
save = "Сохранить"
|
save = "Сохранить"
|
||||||
selectFFPathTitle = "Укажите путь к FFmpeg и к FFprobe"
|
selectFFPathTitle = "Укажите путь к FFmpeg и к FFprobe"
|
||||||
settings = "Настройки"
|
settings = "Настройки"
|
||||||
testFF = "Проверка FFmpeg на работоспособность..."
|
testFF = "Проверка FFmpeg на работоспособность..."
|
||||||
titleDownloadLink = "Скачать можно от сюда"
|
titleDownloadLink = "Скачать можно от сюда"
|
||||||
unzipRun = "Распаковывается..."
|
unzipRun = "Распаковывается..."
|
||||||
|
waiting = "В очереди"
|
||||||
|
@ -1,3 +1,15 @@
|
|||||||
[testFF]
|
[completed]
|
||||||
hash = "sha1-f5b8ed88e9609963035d2235be0a79bbec619976"
|
hash = "sha1-398c7d4f7b0d522afb930769c0fbb1a9f4b61fbe"
|
||||||
other = "Checking FFmpeg for serviceability..."
|
other = "Completed"
|
||||||
|
|
||||||
|
[inProgress]
|
||||||
|
hash = "sha1-eff79c40e2100ae5fadf3a7d99336025edcca8b5"
|
||||||
|
other = "In Progress"
|
||||||
|
|
||||||
|
[queue]
|
||||||
|
hash = "sha1-aec93b16baeaf55fed871075c9494a460e4a91b8"
|
||||||
|
other = "Queue"
|
||||||
|
|
||||||
|
[waiting]
|
||||||
|
hash = "sha1-307429dd84150877080c4bbff2b340d1e7dadff2"
|
||||||
|
other = "Waiting"
|
||||||
|
@ -1,3 +1,15 @@
|
|||||||
[testFF]
|
[completed]
|
||||||
hash = "sha1-f5b8ed88e9609963035d2235be0a79bbec619976"
|
hash = "sha1-398c7d4f7b0d522afb930769c0fbb1a9f4b61fbe"
|
||||||
other = "FFmpeg функционалдығы тексерілуде..."
|
other = "Дайын"
|
||||||
|
|
||||||
|
[inProgress]
|
||||||
|
hash = "sha1-eff79c40e2100ae5fadf3a7d99336025edcca8b5"
|
||||||
|
other = "Орындалуда"
|
||||||
|
|
||||||
|
[queue]
|
||||||
|
hash = "sha1-aec93b16baeaf55fed871075c9494a460e4a91b8"
|
||||||
|
other = "Кезек"
|
||||||
|
|
||||||
|
[waiting]
|
||||||
|
hash = "sha1-307429dd84150877080c4bbff2b340d1e7dadff2"
|
||||||
|
other = "Күту"
|
||||||
|
@ -3,27 +3,26 @@ package localizer
|
|||||||
import (
|
import (
|
||||||
"fyne.io/fyne/v2"
|
"fyne.io/fyne/v2"
|
||||||
"fyne.io/fyne/v2/widget"
|
"fyne.io/fyne/v2/widget"
|
||||||
|
"git.kor-elf.net/kor-elf/gui-for-ffmpeg/kernel"
|
||||||
"github.com/nicksnyder/go-i18n/v2/i18n"
|
"github.com/nicksnyder/go-i18n/v2/i18n"
|
||||||
)
|
)
|
||||||
|
|
||||||
type ViewContract interface {
|
type ViewContract interface {
|
||||||
LanguageSelection(funcSelected func(lang Lang))
|
LanguageSelection(funcSelected func(lang kernel.Lang))
|
||||||
}
|
}
|
||||||
|
|
||||||
type View struct {
|
type View struct {
|
||||||
w fyne.Window
|
app kernel.AppContract
|
||||||
localizerService ServiceContract
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewView(w fyne.Window, localizerService ServiceContract) *View {
|
func NewView(app kernel.AppContract) *View {
|
||||||
return &View{
|
return &View{
|
||||||
w: w,
|
app: app,
|
||||||
localizerService: localizerService,
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (v View) LanguageSelection(funcSelected func(lang Lang)) {
|
func (v View) LanguageSelection(funcSelected func(lang kernel.Lang)) {
|
||||||
languages := v.localizerService.GetLanguages()
|
languages := v.app.GetLocalizerService().GetLanguages()
|
||||||
listView := widget.NewList(
|
listView := widget.NewList(
|
||||||
func() int {
|
func() int {
|
||||||
return len(languages)
|
return len(languages)
|
||||||
@ -36,18 +35,17 @@ func (v View) LanguageSelection(funcSelected func(lang Lang)) {
|
|||||||
block.SetText(languages[i].Title)
|
block.SetText(languages[i].Title)
|
||||||
})
|
})
|
||||||
listView.OnSelected = func(id widget.ListItemID) {
|
listView.OnSelected = func(id widget.ListItemID) {
|
||||||
_ = v.localizerService.SetCurrentLanguage(languages[id])
|
_ = v.app.GetLocalizerService().SetCurrentLanguage(languages[id])
|
||||||
funcSelected(languages[id])
|
funcSelected(languages[id])
|
||||||
}
|
}
|
||||||
|
|
||||||
messageHead := v.localizerService.GetMessage(&i18n.LocalizeConfig{
|
messageHead := v.app.GetLocalizerService().GetMessage(&i18n.LocalizeConfig{
|
||||||
MessageID: "languageSelectionHead",
|
MessageID: "languageSelectionHead",
|
||||||
})
|
})
|
||||||
|
v.app.GetWindow().SetContent(widget.NewCard(messageHead, "", listView))
|
||||||
v.w.SetContent(widget.NewCard(messageHead, "", listView))
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func LanguageSelectionForm(localizerService ServiceContract, funcSelected func(lang Lang)) fyne.CanvasObject {
|
func LanguageSelectionForm(localizerService kernel.LocalizerContract, funcSelected func(lang kernel.Lang)) fyne.CanvasObject {
|
||||||
languages := localizerService.GetLanguages()
|
languages := localizerService.GetLanguages()
|
||||||
currentLanguage := localizerService.GetCurrentLanguage()
|
currentLanguage := localizerService.GetCurrentLanguage()
|
||||||
listView := widget.NewList(
|
listView := widget.NewList(
|
||||||
|
104
main.go
104
main.go
@ -3,12 +3,10 @@ package main
|
|||||||
import (
|
import (
|
||||||
"errors"
|
"errors"
|
||||||
"fyne.io/fyne/v2"
|
"fyne.io/fyne/v2"
|
||||||
"fyne.io/fyne/v2/app"
|
|
||||||
"fyne.io/fyne/v2/container"
|
|
||||||
"fyne.io/fyne/v2/widget"
|
|
||||||
"git.kor-elf.net/kor-elf/gui-for-ffmpeg/convertor"
|
"git.kor-elf.net/kor-elf/gui-for-ffmpeg/convertor"
|
||||||
error2 "git.kor-elf.net/kor-elf/gui-for-ffmpeg/error"
|
error2 "git.kor-elf.net/kor-elf/gui-for-ffmpeg/error"
|
||||||
"git.kor-elf.net/kor-elf/gui-for-ffmpeg/handler"
|
"git.kor-elf.net/kor-elf/gui-for-ffmpeg/handler"
|
||||||
|
"git.kor-elf.net/kor-elf/gui-for-ffmpeg/kernel"
|
||||||
"git.kor-elf.net/kor-elf/gui-for-ffmpeg/localizer"
|
"git.kor-elf.net/kor-elf/gui-for-ffmpeg/localizer"
|
||||||
"git.kor-elf.net/kor-elf/gui-for-ffmpeg/menu"
|
"git.kor-elf.net/kor-elf/gui-for-ffmpeg/menu"
|
||||||
"git.kor-elf.net/kor-elf/gui-for-ffmpeg/migration"
|
"git.kor-elf.net/kor-elf/gui-for-ffmpeg/migration"
|
||||||
@ -20,36 +18,50 @@ import (
|
|||||||
"os"
|
"os"
|
||||||
)
|
)
|
||||||
|
|
||||||
const appVersion string = "0.3.1"
|
var app kernel.AppContract
|
||||||
|
var ffPathUtilities *kernel.FFPathUtilities
|
||||||
|
|
||||||
|
func init() {
|
||||||
|
iconResource, _ := fyne.LoadResourceFromPath("icon.png")
|
||||||
|
appMetadata := &fyne.AppMetadata{
|
||||||
|
ID: "net.kor-elf.projects.gui-for-ffmpeg",
|
||||||
|
Name: "GUI for FFmpeg",
|
||||||
|
Version: "0.4.0",
|
||||||
|
Icon: iconResource,
|
||||||
|
}
|
||||||
|
|
||||||
|
localizerService, err := kernel.NewLocalizer("languages", language.Russian)
|
||||||
|
if err != nil {
|
||||||
|
kernel.PanicErrorLang(err, appMetadata)
|
||||||
|
}
|
||||||
|
|
||||||
|
ffPathUtilities = &kernel.FFPathUtilities{FFmpeg: "", FFprobe: ""}
|
||||||
|
convertorService := kernel.NewService(ffPathUtilities)
|
||||||
|
layoutLocalizerListener := kernel.NewLayoutLocalizerListener()
|
||||||
|
localizerService.AddListener(layoutLocalizerListener)
|
||||||
|
|
||||||
|
queue := kernel.NewQueueList()
|
||||||
|
app = kernel.NewApp(
|
||||||
|
appMetadata,
|
||||||
|
localizerService,
|
||||||
|
queue,
|
||||||
|
kernel.NewQueueLayoutObject(queue, localizerService, layoutLocalizerListener),
|
||||||
|
convertorService,
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
a := app.New()
|
errorView := error2.NewView(app)
|
||||||
iconResource, err := fyne.LoadResourceFromPath("icon.png")
|
|
||||||
if err == nil {
|
|
||||||
a.SetIcon(iconResource)
|
|
||||||
}
|
|
||||||
w := a.NewWindow("GUI for FFmpeg")
|
|
||||||
w.Resize(fyne.Size{Width: 800, Height: 600})
|
|
||||||
w.CenterOnScreen()
|
|
||||||
|
|
||||||
localizerService, err := localizer.NewService("languages", language.Russian)
|
|
||||||
if err != nil {
|
|
||||||
panicErrorLang(w, err)
|
|
||||||
w.ShowAndRun()
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
errorView := error2.NewView(w, localizerService)
|
|
||||||
if canCreateFile("data/database") != true {
|
if canCreateFile("data/database") != true {
|
||||||
errorView.PanicErrorWriteDirectoryData()
|
errorView.PanicErrorWriteDirectoryData()
|
||||||
w.ShowAndRun()
|
app.GetWindow().ShowAndRun()
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
db, err := gorm.Open(sqlite.Open("data/database"), &gorm.Config{})
|
db, err := gorm.Open(sqlite.Open("data/database"), &gorm.Config{})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
errorView.PanicError(err)
|
errorView.PanicError(err)
|
||||||
w.ShowAndRun()
|
app.GetWindow().ShowAndRun()
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -58,7 +70,7 @@ func main() {
|
|||||||
err = migration.Run(db)
|
err = migration.Run(db)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
errorView.PanicError(err)
|
errorView.PanicError(err)
|
||||||
w.ShowAndRun()
|
app.GetWindow().ShowAndRun()
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -67,34 +79,37 @@ func main() {
|
|||||||
pathFFmpeg, err := convertorRepository.GetPathFfmpeg()
|
pathFFmpeg, err := convertorRepository.GetPathFfmpeg()
|
||||||
if err != nil && errors.Is(err, gorm.ErrRecordNotFound) == false {
|
if err != nil && errors.Is(err, gorm.ErrRecordNotFound) == false {
|
||||||
errorView.PanicError(err)
|
errorView.PanicError(err)
|
||||||
w.ShowAndRun()
|
app.GetWindow().ShowAndRun()
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
ffPathUtilities.FFmpeg = pathFFmpeg
|
||||||
|
|
||||||
pathFFprobe, err := convertorRepository.GetPathFfprobe()
|
pathFFprobe, err := convertorRepository.GetPathFfprobe()
|
||||||
if err != nil && errors.Is(err, gorm.ErrRecordNotFound) == false {
|
if err != nil && errors.Is(err, gorm.ErrRecordNotFound) == false {
|
||||||
errorView.PanicError(err)
|
errorView.PanicError(err)
|
||||||
w.ShowAndRun()
|
app.GetWindow().ShowAndRun()
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
ffPathUtilities.FFprobe = pathFFprobe
|
||||||
|
|
||||||
ffPathUtilities := convertor.FFPathUtilities{FFmpeg: pathFFmpeg, FFprobe: pathFFprobe}
|
app.RunConvertor()
|
||||||
|
defer app.AfterClosing()
|
||||||
|
|
||||||
localizerView := localizer.NewView(w, localizerService)
|
localizerView := localizer.NewView(app)
|
||||||
convertorView := convertor.NewView(w, localizerService)
|
convertorView := convertor.NewView(app)
|
||||||
convertorService := convertor.NewService(ffPathUtilities)
|
convertorHandler := handler.NewConvertorHandler(app, convertorView, convertorRepository)
|
||||||
defer appCloseWithConvert(convertorService)
|
|
||||||
convertorHandler := handler.NewConvertorHandler(convertorService, convertorView, convertorRepository, localizerService)
|
|
||||||
|
|
||||||
localizerRepository := localizer.NewRepository(settingRepository)
|
localizerRepository := localizer.NewRepository(settingRepository)
|
||||||
menuView := menu.NewView(w, a, appVersion, localizerService)
|
menuView := menu.NewView(app)
|
||||||
mainMenu := handler.NewMenuHandler(convertorHandler, menuView, localizerService, localizerView, localizerRepository)
|
localizerListener := handler.NewLocalizerListener()
|
||||||
|
app.GetLocalizerService().AddListener(localizerListener)
|
||||||
|
mainMenu := handler.NewMenuHandler(app, convertorHandler, menuView, localizerView, localizerRepository, localizerListener)
|
||||||
|
|
||||||
mainHandler := handler.NewMainHandler(convertorHandler, mainMenu, localizerRepository, localizerService)
|
mainHandler := handler.NewMainHandler(app, convertorHandler, mainMenu, localizerRepository)
|
||||||
mainHandler.Start()
|
mainHandler.Start()
|
||||||
|
|
||||||
w.SetMainMenu(mainMenu.GetMainMenu())
|
app.GetWindow().SetMainMenu(mainMenu.GetMainMenu())
|
||||||
|
app.GetWindow().ShowAndRun()
|
||||||
w.ShowAndRun()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func appCloseWithDb(db *gorm.DB) {
|
func appCloseWithDb(db *gorm.DB) {
|
||||||
@ -104,12 +119,6 @@ func appCloseWithDb(db *gorm.DB) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func appCloseWithConvert(convertorService convertor.ServiceContract) {
|
|
||||||
for _, cmd := range convertorService.GetRunningProcesses() {
|
|
||||||
_ = cmd.Process.Kill()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func canCreateFile(path string) bool {
|
func canCreateFile(path string) bool {
|
||||||
file, err := os.OpenFile(path, os.O_CREATE|os.O_WRONLY, 0666)
|
file, err := os.OpenFile(path, os.O_CREATE|os.O_WRONLY, 0666)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -118,10 +127,3 @@ func canCreateFile(path string) bool {
|
|||||||
_ = file.Close()
|
_ = file.Close()
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
func panicErrorLang(w fyne.Window, err error) {
|
|
||||||
w.SetContent(container.NewVBox(
|
|
||||||
widget.NewLabel("Произошла ошибка!"),
|
|
||||||
widget.NewLabel("произошла ошибка при получении языковых переводах. \n\r"+err.Error()),
|
|
||||||
))
|
|
||||||
}
|
|
||||||
|
42
menu/view.go
42
menu/view.go
@ -5,7 +5,7 @@ import (
|
|||||||
"fyne.io/fyne/v2/canvas"
|
"fyne.io/fyne/v2/canvas"
|
||||||
"fyne.io/fyne/v2/container"
|
"fyne.io/fyne/v2/container"
|
||||||
"fyne.io/fyne/v2/widget"
|
"fyne.io/fyne/v2/widget"
|
||||||
"git.kor-elf.net/kor-elf/gui-for-ffmpeg/localizer"
|
"git.kor-elf.net/kor-elf/gui-for-ffmpeg/kernel"
|
||||||
"github.com/nicksnyder/go-i18n/v2/i18n"
|
"github.com/nicksnyder/go-i18n/v2/i18n"
|
||||||
"golang.org/x/image/colornames"
|
"golang.org/x/image/colornames"
|
||||||
"net/url"
|
"net/url"
|
||||||
@ -16,23 +16,17 @@ type ViewContract interface {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type View struct {
|
type View struct {
|
||||||
w fyne.Window
|
app kernel.AppContract
|
||||||
app fyne.App
|
|
||||||
appVersion string
|
|
||||||
localizerService localizer.ServiceContract
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewView(w fyne.Window, app fyne.App, appVersion string, localizerService localizer.ServiceContract) *View {
|
func NewView(app kernel.AppContract) *View {
|
||||||
return &View{
|
return &View{
|
||||||
w: w,
|
app: app,
|
||||||
app: app,
|
|
||||||
appVersion: appVersion,
|
|
||||||
localizerService: localizerService,
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (v View) About(ffmpegVersion string, ffprobeVersion string) {
|
func (v View) About(ffmpegVersion string, ffprobeVersion string) {
|
||||||
view := v.app.NewWindow(v.localizerService.GetMessage(&i18n.LocalizeConfig{
|
view := v.app.GetAppFyne().NewWindow(v.app.GetLocalizerService().GetMessage(&i18n.LocalizeConfig{
|
||||||
MessageID: "about",
|
MessageID: "about",
|
||||||
}))
|
}))
|
||||||
view.Resize(fyne.Size{Width: 793, Height: 550})
|
view.Resize(fyne.Size{Width: 793, Height: 550})
|
||||||
@ -42,7 +36,7 @@ func (v View) About(ffmpegVersion string, ffprobeVersion string) {
|
|||||||
programmName.TextStyle = fyne.TextStyle{Bold: true}
|
programmName.TextStyle = fyne.TextStyle{Bold: true}
|
||||||
programmName.TextSize = 20
|
programmName.TextSize = 20
|
||||||
|
|
||||||
programmLink := widget.NewHyperlink(v.localizerService.GetMessage(&i18n.LocalizeConfig{
|
programmLink := widget.NewHyperlink(v.app.GetLocalizerService().GetMessage(&i18n.LocalizeConfig{
|
||||||
MessageID: "programmLink",
|
MessageID: "programmLink",
|
||||||
}), &url.URL{
|
}), &url.URL{
|
||||||
Scheme: "https",
|
Scheme: "https",
|
||||||
@ -50,7 +44,7 @@ func (v View) About(ffmpegVersion string, ffprobeVersion string) {
|
|||||||
Path: "kor-elf/gui-for-ffmpeg/releases",
|
Path: "kor-elf/gui-for-ffmpeg/releases",
|
||||||
})
|
})
|
||||||
|
|
||||||
licenseLink := widget.NewHyperlink(v.localizerService.GetMessage(&i18n.LocalizeConfig{
|
licenseLink := widget.NewHyperlink(v.app.GetLocalizerService().GetMessage(&i18n.LocalizeConfig{
|
||||||
MessageID: "licenseLink",
|
MessageID: "licenseLink",
|
||||||
}), &url.URL{
|
}), &url.URL{
|
||||||
Scheme: "https",
|
Scheme: "https",
|
||||||
@ -58,7 +52,7 @@ func (v View) About(ffmpegVersion string, ffprobeVersion string) {
|
|||||||
Path: "kor-elf/gui-for-ffmpeg/src/branch/main/LICENSE",
|
Path: "kor-elf/gui-for-ffmpeg/src/branch/main/LICENSE",
|
||||||
})
|
})
|
||||||
|
|
||||||
licenseLinkOther := widget.NewHyperlink(v.localizerService.GetMessage(&i18n.LocalizeConfig{
|
licenseLinkOther := widget.NewHyperlink(v.app.GetLocalizerService().GetMessage(&i18n.LocalizeConfig{
|
||||||
MessageID: "licenseLinkOther",
|
MessageID: "licenseLinkOther",
|
||||||
}), &url.URL{
|
}), &url.URL{
|
||||||
Scheme: "https",
|
Scheme: "https",
|
||||||
@ -66,16 +60,16 @@ func (v View) About(ffmpegVersion string, ffprobeVersion string) {
|
|||||||
Path: "kor-elf/gui-for-ffmpeg/src/branch/main/LICENSE-3RD-PARTY.txt",
|
Path: "kor-elf/gui-for-ffmpeg/src/branch/main/LICENSE-3RD-PARTY.txt",
|
||||||
})
|
})
|
||||||
|
|
||||||
programmVersion := widget.NewRichTextFromMarkdown(v.localizerService.GetMessage(&i18n.LocalizeConfig{
|
programmVersion := widget.NewRichTextFromMarkdown(v.app.GetLocalizerService().GetMessage(&i18n.LocalizeConfig{
|
||||||
MessageID: "programmVersion",
|
MessageID: "programmVersion",
|
||||||
TemplateData: map[string]string{
|
TemplateData: map[string]string{
|
||||||
"Version": v.appVersion,
|
"Version": v.app.GetAppFyne().Metadata().Version,
|
||||||
},
|
},
|
||||||
}))
|
}))
|
||||||
|
|
||||||
aboutText := widget.NewRichText(
|
aboutText := widget.NewRichText(
|
||||||
&widget.TextSegment{
|
&widget.TextSegment{
|
||||||
Text: v.localizerService.GetMessage(&i18n.LocalizeConfig{
|
Text: v.app.GetLocalizerService().GetMessage(&i18n.LocalizeConfig{
|
||||||
MessageID: "aboutText",
|
MessageID: "aboutText",
|
||||||
}),
|
}),
|
||||||
},
|
},
|
||||||
@ -84,10 +78,10 @@ func (v View) About(ffmpegVersion string, ffprobeVersion string) {
|
|||||||
image.SetMinSize(fyne.Size{Width: 100, Height: 100})
|
image.SetMinSize(fyne.Size{Width: 100, Height: 100})
|
||||||
image.FillMode = canvas.ImageFillContain
|
image.FillMode = canvas.ImageFillContain
|
||||||
|
|
||||||
ffmpegTrademark := widget.NewRichTextFromMarkdown(v.localizerService.GetMessage(&i18n.LocalizeConfig{
|
ffmpegTrademark := widget.NewRichTextFromMarkdown(v.app.GetLocalizerService().GetMessage(&i18n.LocalizeConfig{
|
||||||
MessageID: "ffmpegTrademark",
|
MessageID: "ffmpegTrademark",
|
||||||
}))
|
}))
|
||||||
ffmpegLGPL := widget.NewRichTextFromMarkdown(v.localizerService.GetMessage(&i18n.LocalizeConfig{
|
ffmpegLGPL := widget.NewRichTextFromMarkdown(v.app.GetLocalizerService().GetMessage(&i18n.LocalizeConfig{
|
||||||
MessageID: "ffmpegLGPL",
|
MessageID: "ffmpegLGPL",
|
||||||
}))
|
}))
|
||||||
|
|
||||||
@ -105,7 +99,7 @@ func (v View) About(ffmpegVersion string, ffprobeVersion string) {
|
|||||||
)),
|
)),
|
||||||
v.getAboutFfmpeg(ffmpegVersion),
|
v.getAboutFfmpeg(ffmpegVersion),
|
||||||
v.getAboutFfprobe(ffprobeVersion),
|
v.getAboutFfprobe(ffprobeVersion),
|
||||||
widget.NewCard(v.localizerService.GetMessage(&i18n.LocalizeConfig{
|
widget.NewCard(v.app.GetLocalizerService().GetMessage(&i18n.LocalizeConfig{
|
||||||
MessageID: "AlsoUsedProgram",
|
MessageID: "AlsoUsedProgram",
|
||||||
}), "", v.getOther()),
|
}), "", v.getOther()),
|
||||||
)),
|
)),
|
||||||
@ -123,7 +117,7 @@ func (v View) getAboutFfmpeg(version string) *fyne.Container {
|
|||||||
programmName.TextStyle = fyne.TextStyle{Bold: true}
|
programmName.TextStyle = fyne.TextStyle{Bold: true}
|
||||||
programmName.TextSize = 20
|
programmName.TextSize = 20
|
||||||
|
|
||||||
programmLink := widget.NewHyperlink(v.localizerService.GetMessage(&i18n.LocalizeConfig{
|
programmLink := widget.NewHyperlink(v.app.GetLocalizerService().GetMessage(&i18n.LocalizeConfig{
|
||||||
MessageID: "programmLink",
|
MessageID: "programmLink",
|
||||||
}), &url.URL{
|
}), &url.URL{
|
||||||
Scheme: "https",
|
Scheme: "https",
|
||||||
@ -131,7 +125,7 @@ func (v View) getAboutFfmpeg(version string) *fyne.Container {
|
|||||||
Path: "",
|
Path: "",
|
||||||
})
|
})
|
||||||
|
|
||||||
licenseLink := widget.NewHyperlink(v.localizerService.GetMessage(&i18n.LocalizeConfig{
|
licenseLink := widget.NewHyperlink(v.app.GetLocalizerService().GetMessage(&i18n.LocalizeConfig{
|
||||||
MessageID: "licenseLink",
|
MessageID: "licenseLink",
|
||||||
}), &url.URL{
|
}), &url.URL{
|
||||||
Scheme: "https",
|
Scheme: "https",
|
||||||
@ -153,7 +147,7 @@ func (v View) getAboutFfprobe(version string) *fyne.Container {
|
|||||||
programmName.TextStyle = fyne.TextStyle{Bold: true}
|
programmName.TextStyle = fyne.TextStyle{Bold: true}
|
||||||
programmName.TextSize = 20
|
programmName.TextSize = 20
|
||||||
|
|
||||||
programmLink := widget.NewHyperlink(v.localizerService.GetMessage(&i18n.LocalizeConfig{
|
programmLink := widget.NewHyperlink(v.app.GetLocalizerService().GetMessage(&i18n.LocalizeConfig{
|
||||||
MessageID: "programmLink",
|
MessageID: "programmLink",
|
||||||
}), &url.URL{
|
}), &url.URL{
|
||||||
Scheme: "https",
|
Scheme: "https",
|
||||||
@ -161,7 +155,7 @@ func (v View) getAboutFfprobe(version string) *fyne.Container {
|
|||||||
Path: "ffprobe.html",
|
Path: "ffprobe.html",
|
||||||
})
|
})
|
||||||
|
|
||||||
licenseLink := widget.NewHyperlink(v.localizerService.GetMessage(&i18n.LocalizeConfig{
|
licenseLink := widget.NewHyperlink(v.app.GetLocalizerService().GetMessage(&i18n.LocalizeConfig{
|
||||||
MessageID: "licenseLink",
|
MessageID: "licenseLink",
|
||||||
}), &url.URL{
|
}), &url.URL{
|
||||||
Scheme: "https",
|
Scheme: "https",
|
||||||
|
Loading…
Reference in New Issue
Block a user