Refactoring.
I have moved the conversion form to a separate conversion file.
This commit is contained in:
parent
7b7c15ad27
commit
3f358c8b7d
@ -1,24 +1,18 @@
|
||||
package convertor
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"fyne.io/fyne/v2"
|
||||
"fyne.io/fyne/v2/canvas"
|
||||
"fyne.io/fyne/v2/container"
|
||||
"fyne.io/fyne/v2/storage"
|
||||
"fyne.io/fyne/v2/widget"
|
||||
encoder2 "git.kor-elf.net/kor-elf/gui-for-ffmpeg/encoder"
|
||||
"git.kor-elf.net/kor-elf/gui-for-ffmpeg/convertor/view"
|
||||
"git.kor-elf.net/kor-elf/gui-for-ffmpeg/kernel"
|
||||
"git.kor-elf.net/kor-elf/gui-for-ffmpeg/kernel/encoder"
|
||||
"github.com/nicksnyder/go-i18n/v2/i18n"
|
||||
"image/color"
|
||||
"path/filepath"
|
||||
)
|
||||
|
||||
type ViewContract interface {
|
||||
Main(
|
||||
runConvert func(setting HandleConvertSetting),
|
||||
formats encoder.ConvertorFormatsContract,
|
||||
formConversion view.ConversionContract,
|
||||
)
|
||||
SelectFFPath(
|
||||
ffmpegPath string,
|
||||
@ -33,275 +27,18 @@ type View struct {
|
||||
app kernel.AppContract
|
||||
}
|
||||
|
||||
type HandleConvertSetting struct {
|
||||
VideoFileInput kernel.File
|
||||
DirectoryForSave string
|
||||
OverwriteOutputFiles bool
|
||||
Format string
|
||||
Encoder encoder2.EncoderContract
|
||||
}
|
||||
|
||||
type enableFormConversionStruct struct {
|
||||
fileVideoForConversion *widget.Button
|
||||
buttonForSelectedDir *widget.Button
|
||||
form *widget.Form
|
||||
}
|
||||
|
||||
func NewView(app kernel.AppContract) *View {
|
||||
return &View{
|
||||
app: app,
|
||||
}
|
||||
}
|
||||
|
||||
func (v View) Main(
|
||||
runConvert func(setting HandleConvertSetting),
|
||||
formats encoder.ConvertorFormatsContract,
|
||||
) {
|
||||
form := &widget.Form{}
|
||||
|
||||
conversionMessage := canvas.NewText("", color.RGBA{R: 255, G: 0, B: 0, A: 255})
|
||||
conversionMessage.TextSize = 16
|
||||
conversionMessage.TextStyle = fyne.TextStyle{Bold: true}
|
||||
|
||||
fileVideoForConversion, fileVideoForConversionMessage, fileInput := v.getButtonFileVideoForConversion(form, conversionMessage)
|
||||
buttonForSelectedDir, buttonForSelectedDirMessage, pathToSaveDirectory := v.getButtonForSelectingDirectoryForSaving()
|
||||
|
||||
isOverwriteOutputFiles := false
|
||||
checkboxOverwriteOutputFilesTitle := v.app.GetLocalizerService().GetMessage(&i18n.LocalizeConfig{
|
||||
MessageID: "checkboxOverwriteOutputFilesTitle",
|
||||
})
|
||||
checkboxOverwriteOutputFiles := widget.NewCheck(checkboxOverwriteOutputFilesTitle, func(b bool) {
|
||||
isOverwriteOutputFiles = b
|
||||
})
|
||||
|
||||
selectEncoder := v.getSelectFormat(formats)
|
||||
|
||||
form.Items = []*widget.FormItem{
|
||||
{
|
||||
Text: v.app.GetLocalizerService().GetMessage(&i18n.LocalizeConfig{MessageID: "fileForConversionTitle"}),
|
||||
Widget: fileVideoForConversion,
|
||||
},
|
||||
{
|
||||
Widget: container.NewHScroll(fileVideoForConversionMessage),
|
||||
},
|
||||
{
|
||||
Text: v.app.GetLocalizerService().GetMessage(&i18n.LocalizeConfig{MessageID: "buttonForSelectedDirTitle"}),
|
||||
Widget: buttonForSelectedDir,
|
||||
},
|
||||
{
|
||||
Widget: container.NewHScroll(buttonForSelectedDirMessage),
|
||||
},
|
||||
{
|
||||
Widget: checkboxOverwriteOutputFiles,
|
||||
},
|
||||
{
|
||||
Widget: selectEncoder.SelectFileType,
|
||||
},
|
||||
{
|
||||
Text: v.app.GetLocalizerService().GetMessage(&i18n.LocalizeConfig{MessageID: "selectFormat"}),
|
||||
Widget: selectEncoder.SelectFormat,
|
||||
},
|
||||
{
|
||||
Text: v.app.GetLocalizerService().GetMessage(&i18n.LocalizeConfig{MessageID: "selectEncoder"}),
|
||||
Widget: selectEncoder.SelectEncoder,
|
||||
},
|
||||
}
|
||||
form.SubmitText = v.app.GetLocalizerService().GetMessage(&i18n.LocalizeConfig{
|
||||
MessageID: "converterVideoFilesSubmitTitle",
|
||||
})
|
||||
|
||||
enableFormConversionStruct := enableFormConversionStruct{
|
||||
fileVideoForConversion: fileVideoForConversion,
|
||||
buttonForSelectedDir: buttonForSelectedDir,
|
||||
form: form,
|
||||
}
|
||||
|
||||
form.OnSubmit = func() {
|
||||
if len(*pathToSaveDirectory) == 0 {
|
||||
showConversionMessage(conversionMessage, errors.New(v.app.GetLocalizerService().GetMessage(&i18n.LocalizeConfig{
|
||||
MessageID: "errorSelectedFolderSave",
|
||||
})))
|
||||
enableFormConversion(enableFormConversionStruct)
|
||||
return
|
||||
}
|
||||
if len(selectEncoder.SelectFormat.Selected) == 0 {
|
||||
showConversionMessage(conversionMessage, errors.New(v.app.GetLocalizerService().GetMessage(&i18n.LocalizeConfig{
|
||||
MessageID: "errorSelectedFormat",
|
||||
})))
|
||||
return
|
||||
}
|
||||
if selectEncoder.Encoder == nil {
|
||||
showConversionMessage(conversionMessage, errors.New(v.app.GetLocalizerService().GetMessage(&i18n.LocalizeConfig{
|
||||
MessageID: "errorSelectedEncoder",
|
||||
})))
|
||||
return
|
||||
}
|
||||
conversionMessage.Text = ""
|
||||
|
||||
fileVideoForConversion.Disable()
|
||||
buttonForSelectedDir.Disable()
|
||||
form.Disable()
|
||||
|
||||
setting := HandleConvertSetting{
|
||||
VideoFileInput: *fileInput,
|
||||
DirectoryForSave: *pathToSaveDirectory,
|
||||
OverwriteOutputFiles: isOverwriteOutputFiles,
|
||||
Format: selectEncoder.SelectFormat.Selected,
|
||||
Encoder: selectEncoder.Encoder,
|
||||
}
|
||||
runConvert(setting)
|
||||
enableFormConversion(enableFormConversionStruct)
|
||||
|
||||
fileVideoForConversionMessage.Text = ""
|
||||
form.Disable()
|
||||
}
|
||||
|
||||
func (v View) Main(formConversion view.ConversionContract) {
|
||||
converterVideoFilesTitle := v.app.GetLocalizerService().GetMessage(&i18n.LocalizeConfig{
|
||||
MessageID: "converterVideoFilesTitle",
|
||||
})
|
||||
v.app.GetWindow().SetContent(widget.NewCard(converterVideoFilesTitle, "", container.NewVBox(form, conversionMessage)))
|
||||
form.Disable()
|
||||
}
|
||||
|
||||
func (v View) getButtonFileVideoForConversion(form *widget.Form, conversionMessage *canvas.Text) (*widget.Button, *canvas.Text, *kernel.File) {
|
||||
fileInput := &kernel.File{}
|
||||
|
||||
fileVideoForConversionMessage := canvas.NewText("", color.RGBA{R: 255, G: 0, B: 0, A: 255})
|
||||
fileVideoForConversionMessage.TextSize = 16
|
||||
fileVideoForConversionMessage.TextStyle = fyne.TextStyle{Bold: true}
|
||||
|
||||
buttonTitle := v.app.GetLocalizerService().GetMessage(&i18n.LocalizeConfig{
|
||||
MessageID: "choose",
|
||||
})
|
||||
|
||||
var locationURI fyne.ListableURI
|
||||
|
||||
button := widget.NewButton(buttonTitle, func() {
|
||||
v.app.GetWindow().NewFileOpen(func(r fyne.URIReadCloser, err error) {
|
||||
if err != nil {
|
||||
fileVideoForConversionMessage.Text = err.Error()
|
||||
setStringErrorStyle(fileVideoForConversionMessage)
|
||||
return
|
||||
}
|
||||
if r == nil {
|
||||
return
|
||||
}
|
||||
|
||||
fileInput.Path = r.URI().Path()
|
||||
fileInput.Name = r.URI().Name()
|
||||
fileInput.Ext = r.URI().Extension()
|
||||
|
||||
fileVideoForConversionMessage.Text = r.URI().Path()
|
||||
setStringSuccessStyle(fileVideoForConversionMessage)
|
||||
|
||||
form.Enable()
|
||||
conversionMessage.Text = ""
|
||||
|
||||
listableURI := storage.NewFileURI(filepath.Dir(r.URI().Path()))
|
||||
locationURI, err = storage.ListerForURI(listableURI)
|
||||
}, locationURI)
|
||||
})
|
||||
|
||||
return button, fileVideoForConversionMessage, fileInput
|
||||
}
|
||||
|
||||
func (v View) getButtonForSelectingDirectoryForSaving() (button *widget.Button, buttonMessage *canvas.Text, dirPath *string) {
|
||||
buttonMessage = canvas.NewText("", color.RGBA{R: 255, G: 0, B: 0, A: 255})
|
||||
buttonMessage.TextSize = 16
|
||||
buttonMessage.TextStyle = fyne.TextStyle{Bold: true}
|
||||
|
||||
path := ""
|
||||
dirPath = &path
|
||||
|
||||
buttonTitle := v.app.GetLocalizerService().GetMessage(&i18n.LocalizeConfig{
|
||||
MessageID: "choose",
|
||||
})
|
||||
|
||||
var locationURI fyne.ListableURI
|
||||
|
||||
button = widget.NewButton(buttonTitle, func() {
|
||||
v.app.GetWindow().NewFolderOpen(func(r fyne.ListableURI, err error) {
|
||||
if err != nil {
|
||||
buttonMessage.Text = err.Error()
|
||||
setStringErrorStyle(buttonMessage)
|
||||
return
|
||||
}
|
||||
if r == nil {
|
||||
return
|
||||
}
|
||||
|
||||
path = r.Path()
|
||||
|
||||
buttonMessage.Text = r.Path()
|
||||
setStringSuccessStyle(buttonMessage)
|
||||
locationURI, _ = storage.ListerForURI(r)
|
||||
|
||||
}, locationURI)
|
||||
})
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
type selectEncoder struct {
|
||||
SelectFileType *widget.RadioGroup
|
||||
SelectFormat *widget.Select
|
||||
SelectEncoder *widget.Select
|
||||
Encoder encoder2.EncoderContract
|
||||
}
|
||||
|
||||
func (v View) getSelectFormat(formats encoder.ConvertorFormatsContract) *selectEncoder {
|
||||
selectEncoder := &selectEncoder{}
|
||||
|
||||
encoders := map[int]encoder2.EncoderDataContract{}
|
||||
selectEncoder.SelectEncoder = widget.NewSelect([]string{}, func(s string) {
|
||||
if encoders[selectEncoder.SelectEncoder.SelectedIndex()] == nil {
|
||||
return
|
||||
}
|
||||
selectEncoder.Encoder = encoders[selectEncoder.SelectEncoder.SelectedIndex()].NewEncoder()
|
||||
})
|
||||
|
||||
formatSelected := ""
|
||||
selectEncoder.SelectFormat = widget.NewSelect([]string{}, func(s string) {
|
||||
if formatSelected == s {
|
||||
return
|
||||
}
|
||||
formatSelected = s
|
||||
format, err := formats.GetFormat(s)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
encoderOptions := []string{}
|
||||
encoders = format.GetEncoders()
|
||||
for _, e := range encoders {
|
||||
encoderOptions = append(encoderOptions, v.app.GetLocalizerService().GetMessage(&i18n.LocalizeConfig{MessageID: "encoder_" + e.GetTitle()}))
|
||||
}
|
||||
selectEncoder.SelectEncoder.SetOptions(encoderOptions)
|
||||
selectEncoder.SelectEncoder.SetSelectedIndex(0)
|
||||
})
|
||||
|
||||
fileTypeOptions := []string{}
|
||||
for _, fileType := range encoder2.GetListFileType() {
|
||||
fileTypeOptions = append(fileTypeOptions, fileType.Name())
|
||||
}
|
||||
selectEncoder.SelectFileType = widget.NewRadioGroup([]string{"video", "audio", "image"}, func(s string) {
|
||||
formatOptions := []string{}
|
||||
for _, f := range formats.GetFormats() {
|
||||
if s != f.GetFileType().Name() {
|
||||
continue
|
||||
}
|
||||
formatOptions = append(formatOptions, f.GetTitle())
|
||||
}
|
||||
selectEncoder.SelectFormat.SetOptions(formatOptions)
|
||||
if s == encoder2.FileType(encoder2.Video).Name() {
|
||||
selectEncoder.SelectFormat.SetSelected("mp4")
|
||||
} else {
|
||||
selectEncoder.SelectFormat.SetSelectedIndex(0)
|
||||
}
|
||||
})
|
||||
selectEncoder.SelectFileType.Horizontal = true
|
||||
selectEncoder.SelectFileType.SetSelected("video")
|
||||
|
||||
return selectEncoder
|
||||
v.app.GetWindow().SetContent(widget.NewCard(converterVideoFilesTitle, "", container.NewVScroll(formConversion.GetContent())))
|
||||
formConversion.AfterViewContent()
|
||||
}
|
||||
|
||||
func setStringErrorStyle(text *canvas.Text) {
|
||||
@ -313,14 +50,3 @@ func setStringSuccessStyle(text *canvas.Text) {
|
||||
text.Color = color.RGBA{R: 49, G: 127, B: 114, A: 255}
|
||||
text.Refresh()
|
||||
}
|
||||
|
||||
func showConversionMessage(conversionMessage *canvas.Text, err error) {
|
||||
conversionMessage.Text = err.Error()
|
||||
setStringErrorStyle(conversionMessage)
|
||||
}
|
||||
|
||||
func enableFormConversion(enableFormConversionStruct enableFormConversionStruct) {
|
||||
enableFormConversionStruct.fileVideoForConversion.Enable()
|
||||
enableFormConversionStruct.buttonForSelectedDir.Enable()
|
||||
enableFormConversionStruct.form.Enable()
|
||||
}
|
||||
|
385
convertor/view/conversion.go
Normal file
385
convertor/view/conversion.go
Normal file
@ -0,0 +1,385 @@
|
||||
package view
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"fyne.io/fyne/v2"
|
||||
"fyne.io/fyne/v2/canvas"
|
||||
"fyne.io/fyne/v2/container"
|
||||
"fyne.io/fyne/v2/storage"
|
||||
"fyne.io/fyne/v2/widget"
|
||||
encoder2 "git.kor-elf.net/kor-elf/gui-for-ffmpeg/encoder"
|
||||
"git.kor-elf.net/kor-elf/gui-for-ffmpeg/kernel"
|
||||
"git.kor-elf.net/kor-elf/gui-for-ffmpeg/kernel/encoder"
|
||||
"github.com/nicksnyder/go-i18n/v2/i18n"
|
||||
"image/color"
|
||||
"path/filepath"
|
||||
)
|
||||
|
||||
type ConversionContract interface {
|
||||
GetContent() fyne.CanvasObject
|
||||
AfterViewContent()
|
||||
}
|
||||
|
||||
type Conversion struct {
|
||||
app kernel.AppContract
|
||||
form *widget.Form
|
||||
conversionMessage *canvas.Text
|
||||
fileForConversion *fileForConversion
|
||||
directoryForSaving *directoryForSaving
|
||||
overwriteOutputFiles *overwriteOutputFiles
|
||||
selectEncoder *selectEncoder
|
||||
runConvert func(setting HandleConvertSetting)
|
||||
}
|
||||
|
||||
type HandleConvertSetting struct {
|
||||
FileInput kernel.File
|
||||
DirectoryForSave string
|
||||
OverwriteOutputFiles bool
|
||||
Format string
|
||||
Encoder encoder2.EncoderContract
|
||||
}
|
||||
|
||||
func NewConversion(app kernel.AppContract, formats encoder.ConvertorFormatsContract, runConvert func(setting HandleConvertSetting)) *Conversion {
|
||||
conversionMessage := canvas.NewText("", color.RGBA{R: 255, G: 0, B: 0, A: 255})
|
||||
conversionMessage.TextSize = 16
|
||||
conversionMessage.TextStyle = fyne.TextStyle{Bold: true}
|
||||
|
||||
fileForConversion := newFileForConversion(app)
|
||||
directoryForSaving := newDirectoryForSaving(app)
|
||||
overwriteOutputFiles := newOverwriteOutputFiles(app)
|
||||
selectEncoder := newSelectEncoder(app, formats)
|
||||
|
||||
form := widget.NewForm()
|
||||
form.Items = []*widget.FormItem{
|
||||
{
|
||||
Text: app.GetLocalizerService().GetMessage(&i18n.LocalizeConfig{MessageID: "fileForConversionTitle"}),
|
||||
Widget: fileForConversion.button,
|
||||
},
|
||||
{
|
||||
Widget: container.NewHScroll(fileForConversion.message),
|
||||
},
|
||||
{
|
||||
Text: app.GetLocalizerService().GetMessage(&i18n.LocalizeConfig{MessageID: "buttonForSelectedDirTitle"}),
|
||||
Widget: directoryForSaving.button,
|
||||
},
|
||||
{
|
||||
Widget: container.NewHScroll(directoryForSaving.message),
|
||||
},
|
||||
{
|
||||
Widget: overwriteOutputFiles.checkbox,
|
||||
},
|
||||
{
|
||||
Widget: selectEncoder.SelectFileType,
|
||||
},
|
||||
{
|
||||
Text: app.GetLocalizerService().GetMessage(&i18n.LocalizeConfig{MessageID: "selectFormat"}),
|
||||
Widget: selectEncoder.SelectFormat,
|
||||
},
|
||||
{
|
||||
Text: app.GetLocalizerService().GetMessage(&i18n.LocalizeConfig{MessageID: "selectEncoder"}),
|
||||
Widget: selectEncoder.SelectEncoder,
|
||||
},
|
||||
}
|
||||
form.SubmitText = app.GetLocalizerService().GetMessage(&i18n.LocalizeConfig{
|
||||
MessageID: "converterVideoFilesSubmitTitle",
|
||||
})
|
||||
|
||||
return &Conversion{
|
||||
app: app,
|
||||
form: form,
|
||||
conversionMessage: conversionMessage,
|
||||
fileForConversion: fileForConversion,
|
||||
directoryForSaving: directoryForSaving,
|
||||
overwriteOutputFiles: overwriteOutputFiles,
|
||||
selectEncoder: selectEncoder,
|
||||
runConvert: runConvert,
|
||||
}
|
||||
}
|
||||
|
||||
func (c Conversion) GetContent() fyne.CanvasObject {
|
||||
c.form.OnSubmit = c.submit
|
||||
c.fileForConversion.AddChangeCallback(c.selectFileForConversion)
|
||||
|
||||
return container.NewVBox(
|
||||
c.form,
|
||||
c.conversionMessage,
|
||||
)
|
||||
}
|
||||
|
||||
func (c Conversion) AfterViewContent() {
|
||||
c.form.Disable()
|
||||
}
|
||||
|
||||
func (c Conversion) selectFileForConversion(err error) {
|
||||
c.conversionMessage.Text = ""
|
||||
if err != nil {
|
||||
c.form.Disable()
|
||||
return
|
||||
}
|
||||
|
||||
c.form.Enable()
|
||||
}
|
||||
|
||||
func (c Conversion) submit() {
|
||||
if len(c.directoryForSaving.path) == 0 {
|
||||
showConversionMessage(c.conversionMessage, errors.New(c.app.GetLocalizerService().GetMessage(&i18n.LocalizeConfig{
|
||||
MessageID: "errorSelectedFolderSave",
|
||||
})))
|
||||
c.enableFormConversion()
|
||||
return
|
||||
}
|
||||
if len(c.selectEncoder.SelectFormat.Selected) == 0 {
|
||||
showConversionMessage(c.conversionMessage, errors.New(c.app.GetLocalizerService().GetMessage(&i18n.LocalizeConfig{
|
||||
MessageID: "errorSelectedFormat",
|
||||
})))
|
||||
return
|
||||
}
|
||||
if c.selectEncoder.Encoder == nil {
|
||||
showConversionMessage(c.conversionMessage, errors.New(c.app.GetLocalizerService().GetMessage(&i18n.LocalizeConfig{
|
||||
MessageID: "errorSelectedEncoder",
|
||||
})))
|
||||
return
|
||||
}
|
||||
c.conversionMessage.Text = ""
|
||||
|
||||
c.fileForConversion.button.Disable()
|
||||
c.directoryForSaving.button.Disable()
|
||||
c.form.Disable()
|
||||
|
||||
setting := HandleConvertSetting{
|
||||
FileInput: *c.fileForConversion.file,
|
||||
DirectoryForSave: c.directoryForSaving.path,
|
||||
OverwriteOutputFiles: c.overwriteOutputFiles.IsChecked(),
|
||||
Format: c.selectEncoder.SelectFormat.Selected,
|
||||
Encoder: c.selectEncoder.Encoder,
|
||||
}
|
||||
c.runConvert(setting)
|
||||
c.enableFormConversion()
|
||||
|
||||
c.fileForConversion.message.Text = ""
|
||||
c.form.Disable()
|
||||
}
|
||||
|
||||
func (c Conversion) enableFormConversion() {
|
||||
c.fileForConversion.button.Enable()
|
||||
c.directoryForSaving.button.Enable()
|
||||
c.form.Enable()
|
||||
}
|
||||
|
||||
type fileForConversion struct {
|
||||
button *widget.Button
|
||||
message *canvas.Text
|
||||
file *kernel.File
|
||||
|
||||
changeCallbacks map[int]func(err error)
|
||||
}
|
||||
|
||||
func newFileForConversion(app kernel.AppContract) *fileForConversion {
|
||||
fileForConversion := &fileForConversion{
|
||||
file: &kernel.File{},
|
||||
changeCallbacks: map[int]func(err error){},
|
||||
}
|
||||
|
||||
buttonTitle := app.GetLocalizerService().GetMessage(&i18n.LocalizeConfig{
|
||||
MessageID: "choose",
|
||||
})
|
||||
|
||||
fileForConversion.message = canvas.NewText("", color.RGBA{R: 255, G: 0, B: 0, A: 255})
|
||||
fileForConversion.message.TextSize = 16
|
||||
fileForConversion.message.TextStyle = fyne.TextStyle{Bold: true}
|
||||
|
||||
var locationURI fyne.ListableURI
|
||||
|
||||
fileForConversion.button = widget.NewButton(buttonTitle, func() {
|
||||
app.GetWindow().NewFileOpen(func(r fyne.URIReadCloser, err error) {
|
||||
if err != nil {
|
||||
fileForConversion.message.Text = err.Error()
|
||||
setStringErrorStyle(fileForConversion.message)
|
||||
fileForConversion.eventSelectFile(err)
|
||||
return
|
||||
}
|
||||
if r == nil {
|
||||
return
|
||||
}
|
||||
|
||||
fileForConversion.file.Path = r.URI().Path()
|
||||
fileForConversion.file.Name = r.URI().Name()
|
||||
fileForConversion.file.Ext = r.URI().Extension()
|
||||
|
||||
fileForConversion.message.Text = r.URI().Path()
|
||||
setStringSuccessStyle(fileForConversion.message)
|
||||
|
||||
fileForConversion.eventSelectFile(nil)
|
||||
|
||||
listableURI := storage.NewFileURI(filepath.Dir(r.URI().Path()))
|
||||
locationURI, err = storage.ListerForURI(listableURI)
|
||||
}, locationURI)
|
||||
})
|
||||
|
||||
return fileForConversion
|
||||
}
|
||||
|
||||
func (c fileForConversion) AddChangeCallback(callback func(err error)) {
|
||||
c.changeCallbacks[len(c.changeCallbacks)] = callback
|
||||
}
|
||||
|
||||
func (c fileForConversion) eventSelectFile(err error) {
|
||||
for _, changeCallback := range c.changeCallbacks {
|
||||
changeCallback(err)
|
||||
}
|
||||
}
|
||||
|
||||
type directoryForSaving struct {
|
||||
button *widget.Button
|
||||
message *canvas.Text
|
||||
path string
|
||||
}
|
||||
|
||||
func newDirectoryForSaving(app kernel.AppContract) *directoryForSaving {
|
||||
directoryForSaving := &directoryForSaving{
|
||||
path: "",
|
||||
}
|
||||
|
||||
directoryForSaving.message = canvas.NewText("", color.RGBA{R: 255, G: 0, B: 0, A: 255})
|
||||
directoryForSaving.message.TextSize = 16
|
||||
directoryForSaving.message.TextStyle = fyne.TextStyle{Bold: true}
|
||||
|
||||
buttonTitle := app.GetLocalizerService().GetMessage(&i18n.LocalizeConfig{
|
||||
MessageID: "choose",
|
||||
})
|
||||
|
||||
var locationURI fyne.ListableURI
|
||||
|
||||
directoryForSaving.button = widget.NewButton(buttonTitle, func() {
|
||||
app.GetWindow().NewFolderOpen(func(r fyne.ListableURI, err error) {
|
||||
if err != nil {
|
||||
directoryForSaving.message.Text = err.Error()
|
||||
setStringErrorStyle(directoryForSaving.message)
|
||||
return
|
||||
}
|
||||
if r == nil {
|
||||
return
|
||||
}
|
||||
|
||||
directoryForSaving.path = r.Path()
|
||||
|
||||
directoryForSaving.message.Text = r.Path()
|
||||
setStringSuccessStyle(directoryForSaving.message)
|
||||
locationURI, _ = storage.ListerForURI(r)
|
||||
|
||||
}, locationURI)
|
||||
})
|
||||
|
||||
return directoryForSaving
|
||||
}
|
||||
|
||||
type overwriteOutputFiles struct {
|
||||
checkbox *widget.Check
|
||||
isChecked bool
|
||||
}
|
||||
|
||||
func newOverwriteOutputFiles(app kernel.AppContract) *overwriteOutputFiles {
|
||||
overwriteOutputFiles := &overwriteOutputFiles{
|
||||
isChecked: false,
|
||||
}
|
||||
checkboxOverwriteOutputFilesTitle := app.GetLocalizerService().GetMessage(&i18n.LocalizeConfig{
|
||||
MessageID: "checkboxOverwriteOutputFilesTitle",
|
||||
})
|
||||
overwriteOutputFiles.checkbox = widget.NewCheck(checkboxOverwriteOutputFilesTitle, func(b bool) {
|
||||
overwriteOutputFiles.isChecked = b
|
||||
})
|
||||
|
||||
return overwriteOutputFiles
|
||||
}
|
||||
|
||||
func (receiver overwriteOutputFiles) IsChecked() bool {
|
||||
return receiver.isChecked
|
||||
}
|
||||
|
||||
type selectEncoder struct {
|
||||
SelectFileType *widget.RadioGroup
|
||||
SelectFormat *widget.Select
|
||||
SelectEncoder *widget.Select
|
||||
Encoder encoder2.EncoderContract
|
||||
}
|
||||
|
||||
func newSelectEncoder(app kernel.AppContract, formats encoder.ConvertorFormatsContract) *selectEncoder {
|
||||
selectEncoder := &selectEncoder{}
|
||||
|
||||
encoders := map[int]encoder2.EncoderDataContract{}
|
||||
selectEncoder.SelectEncoder = widget.NewSelect([]string{}, func(s string) {
|
||||
if encoders[selectEncoder.SelectEncoder.SelectedIndex()] == nil {
|
||||
return
|
||||
}
|
||||
selectEncoder.Encoder = encoders[selectEncoder.SelectEncoder.SelectedIndex()].NewEncoder()
|
||||
})
|
||||
|
||||
formatSelected := ""
|
||||
selectEncoder.SelectFormat = widget.NewSelect([]string{}, func(s string) {
|
||||
if formatSelected == s {
|
||||
return
|
||||
}
|
||||
formatSelected = s
|
||||
format, err := formats.GetFormat(s)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
encoderOptions := []string{}
|
||||
encoders = format.GetEncoders()
|
||||
for _, e := range encoders {
|
||||
encoderOptions = append(encoderOptions, app.GetLocalizerService().GetMessage(&i18n.LocalizeConfig{MessageID: "encoder_" + e.GetTitle()}))
|
||||
}
|
||||
selectEncoder.SelectEncoder.SetOptions(encoderOptions)
|
||||
selectEncoder.SelectEncoder.SetSelectedIndex(0)
|
||||
})
|
||||
|
||||
fileTypeOptions := []string{}
|
||||
for _, fileType := range encoder2.GetListFileType() {
|
||||
fileTypeOptions = append(fileTypeOptions, fileType.Name())
|
||||
}
|
||||
|
||||
encoderGroupVideo := app.GetLocalizerService().GetMessage(&i18n.LocalizeConfig{MessageID: "encoderGroupVideo"})
|
||||
encoderGroupAudio := app.GetLocalizerService().GetMessage(&i18n.LocalizeConfig{MessageID: "encoderGroupAudio"})
|
||||
encoderGroupImage := app.GetLocalizerService().GetMessage(&i18n.LocalizeConfig{MessageID: "encoderGroupImage"})
|
||||
encoderGroup := map[string]string{
|
||||
encoderGroupVideo: "video",
|
||||
encoderGroupAudio: "audio",
|
||||
encoderGroupImage: "image",
|
||||
}
|
||||
selectEncoder.SelectFileType = widget.NewRadioGroup([]string{encoderGroupVideo, encoderGroupAudio, encoderGroupImage}, func(s string) {
|
||||
groupCode := encoderGroup[s]
|
||||
|
||||
formatOptions := []string{}
|
||||
for _, f := range formats.GetFormats() {
|
||||
if groupCode != f.GetFileType().Name() {
|
||||
continue
|
||||
}
|
||||
formatOptions = append(formatOptions, f.GetTitle())
|
||||
}
|
||||
selectEncoder.SelectFormat.SetOptions(formatOptions)
|
||||
if groupCode == encoder2.FileType(encoder2.Video).Name() {
|
||||
selectEncoder.SelectFormat.SetSelected("mp4")
|
||||
} else {
|
||||
selectEncoder.SelectFormat.SetSelectedIndex(0)
|
||||
}
|
||||
})
|
||||
selectEncoder.SelectFileType.Horizontal = true
|
||||
selectEncoder.SelectFileType.SetSelected(encoderGroupVideo)
|
||||
|
||||
return selectEncoder
|
||||
}
|
||||
|
||||
func setStringErrorStyle(text *canvas.Text) {
|
||||
text.Color = color.RGBA{R: 255, G: 0, B: 0, A: 255}
|
||||
text.Refresh()
|
||||
}
|
||||
|
||||
func setStringSuccessStyle(text *canvas.Text) {
|
||||
text.Color = color.RGBA{R: 49, G: 127, B: 114, A: 255}
|
||||
text.Refresh()
|
||||
}
|
||||
|
||||
func showConversionMessage(conversionMessage *canvas.Text, err error) {
|
||||
conversionMessage.Text = err.Error()
|
||||
setStringErrorStyle(conversionMessage)
|
||||
}
|
@ -3,6 +3,7 @@ package handler
|
||||
import (
|
||||
"errors"
|
||||
"git.kor-elf.net/kor-elf/gui-for-ffmpeg/convertor"
|
||||
"git.kor-elf.net/kor-elf/gui-for-ffmpeg/convertor/view"
|
||||
error2 "git.kor-elf.net/kor-elf/gui-for-ffmpeg/error"
|
||||
"git.kor-elf.net/kor-elf/gui-for-ffmpeg/helper"
|
||||
"git.kor-elf.net/kor-elf/gui-for-ffmpeg/kernel"
|
||||
@ -44,7 +45,8 @@ func (h ConvertorHandler) MainConvertor() {
|
||||
h.errorView.PanicError(err)
|
||||
return
|
||||
}
|
||||
h.convertorView.Main(h.runConvert, formats)
|
||||
conversion := view.NewConversion(h.app, formats, h.runConvert)
|
||||
h.convertorView.Main(conversion)
|
||||
return
|
||||
}
|
||||
h.convertorView.SelectFFPath("", "", h.saveSettingFFPath, nil, h.downloadFFmpeg)
|
||||
@ -64,12 +66,12 @@ func (h ConvertorHandler) GetFfprobeVersion() (string, error) {
|
||||
return h.app.GetConvertorService().GetFFprobeVersion()
|
||||
}
|
||||
|
||||
func (h ConvertorHandler) runConvert(setting convertor.HandleConvertSetting) {
|
||||
func (h ConvertorHandler) runConvert(setting view.HandleConvertSetting) {
|
||||
h.app.GetQueue().Add(&kernel.ConvertSetting{
|
||||
VideoFileInput: setting.VideoFileInput,
|
||||
VideoFileInput: setting.FileInput,
|
||||
VideoFileOut: kernel.File{
|
||||
Path: setting.DirectoryForSave + helper.PathSeparator() + setting.VideoFileInput.Name + "." + setting.Format,
|
||||
Name: setting.VideoFileInput.Name,
|
||||
Path: setting.DirectoryForSave + helper.PathSeparator() + setting.FileInput.Name + "." + setting.Format,
|
||||
Name: setting.FileInput.Name,
|
||||
Ext: "." + setting.Format,
|
||||
},
|
||||
OverwriteOutputFiles: setting.OverwriteOutputFiles,
|
||||
|
@ -15,8 +15,8 @@ hash = "sha1-c223c2e15171156192bc3146aee91e6094bb475b"
|
||||
other = "Download FFmpeg automatically"
|
||||
|
||||
[buttonForSelectedDirTitle]
|
||||
hash = "sha1-52b13f1b13e82d22e8c4102332db5d4ec551247b"
|
||||
other = "Folder where it will be saved:"
|
||||
hash = "sha1-8cbe5c67bcf89e4624635a79cbea104227faedda"
|
||||
other = "Save to folder:"
|
||||
|
||||
[cancel]
|
||||
hash = "sha1-0ec753be8df955a117404fb634b01b45eb386e2a"
|
||||
@ -62,6 +62,18 @@ other = "Will be downloaded from the site:"
|
||||
hash = "sha1-55f87f114628fa2d5d8e67d1e1cda22c0e4f9271"
|
||||
other = "Downloading..."
|
||||
|
||||
[encoderGroupAudio]
|
||||
hash = "sha1-24321cb5400df96be8f3e2131918bebdb3a01bba"
|
||||
other = "Audio"
|
||||
|
||||
[encoderGroupImage]
|
||||
hash = "sha1-a7e528bc7ac9538aec87d1593c38b80be95d4745"
|
||||
other = "Images"
|
||||
|
||||
[encoderGroupVideo]
|
||||
hash = "sha1-8e7b9894c7ef0f57ac0bf910f6a8aac1c8a53683"
|
||||
other = "Video"
|
||||
|
||||
[encoder_apng]
|
||||
hash = "sha1-1cbd9abfef96d5614a7e569161b41bd6ad87bbaf"
|
||||
other = "APNG image"
|
||||
@ -251,8 +263,8 @@ hash = "sha1-45f772b2eca5098cd6d31f2d1dc6edec1987a617"
|
||||
other = "**FFmpeg** is a trademark of **[Fabrice Bellard](http://bellard.org/)**, originator of the **[FFmpeg](https://ffmpeg.org/about.html)** project."
|
||||
|
||||
[fileForConversionTitle]
|
||||
hash = "sha1-981bf090072a487e538d00780d337b47ca877372"
|
||||
other = "File to convert:"
|
||||
hash = "sha1-96ac799e1086b31fd8f5f8d4c801829d6c853f08"
|
||||
other = "File:"
|
||||
|
||||
[help]
|
||||
hash = "sha1-6a45cef900c668effcb2ab10da05855c1fd10f6f"
|
||||
@ -303,16 +315,16 @@ hash = "sha1-4864057d626a868fa60f999bed3191d61d045ddc"
|
||||
other = "Save"
|
||||
|
||||
[selectEncoder]
|
||||
hash = "sha1-07beb734a090830bedf8e038e3b45c73d64b5696"
|
||||
other = "Select a converter"
|
||||
hash = "sha1-db41d1c87b2fbe561bbdcc03919d3a55360bb7d8"
|
||||
other = "Converter:"
|
||||
|
||||
[selectFFPathTitle]
|
||||
hash = "sha1-95581446a28d968ff1a027c623159a7eb08654cf"
|
||||
other = "Specify the path to FFmpeg and FFprobe"
|
||||
|
||||
[selectFormat]
|
||||
hash = "sha1-5e59b9376d321a49e73063eb7355b555d89bdd55"
|
||||
other = "Select file extension"
|
||||
hash = "sha1-f3809b0b48886570cd4cf1d7099de6da5b6d4524"
|
||||
other = "File extension:"
|
||||
|
||||
[settings]
|
||||
hash = "sha1-7f17c7c62a7fd8d1a508481f4778688927734c2f"
|
||||
|
@ -15,8 +15,8 @@ hash = "sha1-c223c2e15171156192bc3146aee91e6094bb475b"
|
||||
other = "FFmpeg автоматты түрде жүктеп алыңыз"
|
||||
|
||||
[buttonForSelectedDirTitle]
|
||||
hash = "sha1-52b13f1b13e82d22e8c4102332db5d4ec551247b"
|
||||
other = "Файлды сақтауға арналған каталог:"
|
||||
hash = "sha1-8cbe5c67bcf89e4624635a79cbea104227faedda"
|
||||
other = "Қалтаға сақтаңыз:"
|
||||
|
||||
[cancel]
|
||||
hash = "sha1-0ec753be8df955a117404fb634b01b45eb386e2a"
|
||||
@ -62,6 +62,18 @@ other = "Сайттан жүктеледі:"
|
||||
hash = "sha1-55f87f114628fa2d5d8e67d1e1cda22c0e4f9271"
|
||||
other = "Жүктеп алынуда..."
|
||||
|
||||
[encoderGroupAudio]
|
||||
hash = "sha1-24321cb5400df96be8f3e2131918bebdb3a01bba"
|
||||
other = "Аудио"
|
||||
|
||||
[encoderGroupImage]
|
||||
hash = "sha1-a7e528bc7ac9538aec87d1593c38b80be95d4745"
|
||||
other = "Суреттер"
|
||||
|
||||
[encoderGroupVideo]
|
||||
hash = "sha1-8e7b9894c7ef0f57ac0bf910f6a8aac1c8a53683"
|
||||
other = "Бейне"
|
||||
|
||||
[encoder_apng]
|
||||
hash = "sha1-1cbd9abfef96d5614a7e569161b41bd6ad87bbaf"
|
||||
other = "APNG image"
|
||||
@ -251,8 +263,8 @@ hash = "sha1-45f772b2eca5098cd6d31f2d1dc6edec1987a617"
|
||||
other = "FFmpeg — **[FFmpeg](https://ffmpeg.org/about.html)** жобасын жасаушы **[Fabrice Bellard](http://bellard.org/)** сауда белгісі."
|
||||
|
||||
[fileForConversionTitle]
|
||||
hash = "sha1-981bf090072a487e538d00780d337b47ca877372"
|
||||
other = "Түрлендіруге арналған файл:"
|
||||
hash = "sha1-96ac799e1086b31fd8f5f8d4c801829d6c853f08"
|
||||
other = "Файл:"
|
||||
|
||||
[help]
|
||||
hash = "sha1-6a45cef900c668effcb2ab10da05855c1fd10f6f"
|
||||
@ -303,16 +315,16 @@ hash = "sha1-4864057d626a868fa60f999bed3191d61d045ddc"
|
||||
other = "Сақтау"
|
||||
|
||||
[selectEncoder]
|
||||
hash = "sha1-07beb734a090830bedf8e038e3b45c73d64b5696"
|
||||
other = "Түрлендіргішті таңдаңыз"
|
||||
hash = "sha1-db41d1c87b2fbe561bbdcc03919d3a55360bb7d8"
|
||||
other = "Түрлендіргіш:"
|
||||
|
||||
[selectFFPathTitle]
|
||||
hash = "sha1-95581446a28d968ff1a027c623159a7eb08654cf"
|
||||
other = "FFmpeg және FFprobe жолын көрсетіңіз"
|
||||
|
||||
[selectFormat]
|
||||
hash = "sha1-5e59b9376d321a49e73063eb7355b555d89bdd55"
|
||||
other = "Файл кеңейтімін таңдаңыз"
|
||||
hash = "sha1-f3809b0b48886570cd4cf1d7099de6da5b6d4524"
|
||||
other = "Файл кеңейтімі:"
|
||||
|
||||
[settings]
|
||||
hash = "sha1-7f17c7c62a7fd8d1a508481f4778688927734c2f"
|
||||
|
@ -2,7 +2,7 @@ AlsoUsedProgram = "Также в программе используется:"
|
||||
about = "О программе"
|
||||
aboutText = "Простенький интерфейс для консольной утилиты FFmpeg. \nНо я не являюсь автором самой утилиты FFmpeg."
|
||||
buttonDownloadFFmpeg = "Скачать автоматически FFmpeg"
|
||||
buttonForSelectedDirTitle = "Папка куда будет сохраняться:"
|
||||
buttonForSelectedDirTitle = "Сохранить в папку:"
|
||||
cancel = "Отмена"
|
||||
changeFFPath = "FFmpeg и FFprobe"
|
||||
changeLanguage = "Поменять язык"
|
||||
@ -14,6 +14,9 @@ converterVideoFilesTitle = "Конвертер видео, аудио и кар
|
||||
download = "Скачать"
|
||||
downloadFFmpegFromSite = "Будет скачано с сайта:"
|
||||
downloadRun = "Скачивается..."
|
||||
encoderGroupAudio = "Аудио"
|
||||
encoderGroupImage = "Картинки"
|
||||
encoderGroupVideo = "Видео"
|
||||
encoder_apng = "APNG image"
|
||||
encoder_bmp = "BMP image"
|
||||
encoder_flv = "FLV"
|
||||
@ -61,7 +64,7 @@ errorSelectedFormat = "Расширение файла не выбрана"
|
||||
exit = "Выход"
|
||||
ffmpegLGPL = "Это программное обеспечение использует библиотеки из проекта **FFmpeg** под **[LGPLv2.1](http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html)**."
|
||||
ffmpegTrademark = "**FFmpeg** — торговая марка **[Fabrice Bellard](http://bellard.org/)** , создателя проекта **[FFmpeg](https://ffmpeg.org/about.html)**."
|
||||
fileForConversionTitle = "Файл для конвертации:"
|
||||
fileForConversionTitle = "Файл:"
|
||||
help = "Справка"
|
||||
inProgressQueue = "Выполняется"
|
||||
languageSelectionFormHead = "Переключить язык"
|
||||
@ -74,9 +77,9 @@ programmLink = "Сайт проекта"
|
||||
programmVersion = "**Версия программы:** {{.Version}}"
|
||||
queue = "Очередь"
|
||||
save = "Сохранить"
|
||||
selectEncoder = "Выберите конвертер"
|
||||
selectEncoder = "Конвертер:"
|
||||
selectFFPathTitle = "Укажите путь к FFmpeg и к FFprobe"
|
||||
selectFormat = "Выберите расширение файла"
|
||||
selectFormat = "Расширение файла:"
|
||||
settings = "Настройки"
|
||||
testFF = "Проверка FFmpeg на работоспособность..."
|
||||
titleDownloadLink = "Скачать можно от сюда"
|
||||
|
Loading…
Reference in New Issue
Block a user