2024-01-31 21:02:12 +06:00
|
|
|
package convertor
|
2024-01-18 01:39:20 +06:00
|
|
|
|
|
|
|
import (
|
2024-01-23 21:33:01 +06:00
|
|
|
"ffmpegGui/helper"
|
2024-01-18 01:39:20 +06:00
|
|
|
"fyne.io/fyne/v2"
|
|
|
|
"fyne.io/fyne/v2/canvas"
|
|
|
|
"fyne.io/fyne/v2/container"
|
|
|
|
"fyne.io/fyne/v2/dialog"
|
|
|
|
"fyne.io/fyne/v2/widget"
|
2024-01-28 22:01:16 +06:00
|
|
|
"github.com/nicksnyder/go-i18n/v2/i18n"
|
2024-01-18 01:39:20 +06:00
|
|
|
"image/color"
|
|
|
|
"net/url"
|
|
|
|
)
|
|
|
|
|
2024-02-01 00:23:28 +06:00
|
|
|
func (v View) SelectFFPath(
|
|
|
|
currentPathFfmpeg string,
|
|
|
|
currentPathFfprobe string,
|
|
|
|
save func(ffmpegPath string, ffprobePath string) error,
|
|
|
|
cancel func(),
|
|
|
|
) {
|
2024-01-18 01:39:20 +06:00
|
|
|
errorMessage := canvas.NewText("", color.RGBA{255, 0, 0, 255})
|
|
|
|
errorMessage.TextSize = 16
|
|
|
|
errorMessage.TextStyle = fyne.TextStyle{Bold: true}
|
|
|
|
|
2024-02-01 00:23:28 +06:00
|
|
|
ffmpegPath, buttonFFmpeg, buttonFFmpegMessage := v.getButtonSelectFile(currentPathFfmpeg)
|
|
|
|
ffprobePath, buttonFFprobe, buttonFFprobeMessage := v.getButtonSelectFile(currentPathFfprobe)
|
2024-01-18 01:39:20 +06:00
|
|
|
|
|
|
|
link := widget.NewHyperlink("https://ffmpeg.org/download.html", &url.URL{
|
|
|
|
Scheme: "https",
|
|
|
|
Host: "ffmpeg.org",
|
|
|
|
Path: "download.html",
|
|
|
|
})
|
|
|
|
|
|
|
|
form := &widget.Form{
|
|
|
|
Items: []*widget.FormItem{
|
2024-01-28 22:01:16 +06:00
|
|
|
{
|
|
|
|
Text: v.localizerService.GetMessage(&i18n.LocalizeConfig{
|
|
|
|
MessageID: "titleDownloadLink",
|
|
|
|
}),
|
|
|
|
Widget: link,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
Text: v.localizerService.GetMessage(&i18n.LocalizeConfig{
|
|
|
|
MessageID: "pathToFfmpeg",
|
|
|
|
}),
|
|
|
|
Widget: buttonFFmpeg,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
Widget: buttonFFmpegMessage,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
Text: v.localizerService.GetMessage(&i18n.LocalizeConfig{
|
|
|
|
MessageID: "pathToFfprobe",
|
|
|
|
}),
|
|
|
|
Widget: buttonFFprobe,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
Widget: buttonFFprobeMessage,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
Widget: errorMessage,
|
|
|
|
},
|
2024-01-18 01:39:20 +06:00
|
|
|
},
|
2024-01-28 22:01:16 +06:00
|
|
|
SubmitText: v.localizerService.GetMessage(&i18n.LocalizeConfig{
|
|
|
|
MessageID: "save",
|
|
|
|
}),
|
2024-01-18 01:39:20 +06:00
|
|
|
OnSubmit: func() {
|
2024-02-01 00:23:28 +06:00
|
|
|
err := save(*ffmpegPath, *ffprobePath)
|
2024-01-18 01:39:20 +06:00
|
|
|
if err != nil {
|
|
|
|
errorMessage.Text = err.Error()
|
|
|
|
}
|
|
|
|
},
|
|
|
|
}
|
2024-02-01 00:23:28 +06:00
|
|
|
if cancel != nil {
|
|
|
|
form.OnCancel = cancel
|
|
|
|
form.CancelText = v.localizerService.GetMessage(&i18n.LocalizeConfig{
|
|
|
|
MessageID: "cancel",
|
|
|
|
})
|
|
|
|
}
|
2024-01-28 22:01:16 +06:00
|
|
|
selectFFPathTitle := v.localizerService.GetMessage(&i18n.LocalizeConfig{
|
|
|
|
MessageID: "selectFFPathTitle",
|
|
|
|
})
|
|
|
|
v.w.SetContent(widget.NewCard(selectFFPathTitle, "", container.NewVBox(form)))
|
2024-01-18 01:39:20 +06:00
|
|
|
}
|
|
|
|
|
2024-02-01 00:23:28 +06:00
|
|
|
func (v View) getButtonSelectFile(path string) (filePath *string, button *widget.Button, buttonMessage *canvas.Text) {
|
2024-01-18 01:39:20 +06:00
|
|
|
filePath = &path
|
|
|
|
|
2024-02-01 00:23:28 +06:00
|
|
|
buttonMessage = canvas.NewText(path, color.RGBA{49, 127, 114, 255})
|
2024-01-18 01:39:20 +06:00
|
|
|
buttonMessage.TextSize = 16
|
|
|
|
buttonMessage.TextStyle = fyne.TextStyle{Bold: true}
|
|
|
|
|
2024-01-28 22:01:16 +06:00
|
|
|
buttonTitle := v.localizerService.GetMessage(&i18n.LocalizeConfig{
|
|
|
|
MessageID: "choose",
|
|
|
|
})
|
|
|
|
|
|
|
|
button = widget.NewButton(buttonTitle, func() {
|
2024-01-18 01:39:20 +06:00
|
|
|
fileDialog := dialog.NewFileOpen(
|
|
|
|
func(r fyne.URIReadCloser, err error) {
|
|
|
|
if err != nil {
|
|
|
|
buttonMessage.Text = err.Error()
|
|
|
|
setStringErrorStyle(buttonMessage)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
if r == nil {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
path = r.URI().Path()
|
|
|
|
|
|
|
|
buttonMessage.Text = r.URI().Path()
|
|
|
|
setStringSuccessStyle(buttonMessage)
|
|
|
|
}, v.w)
|
2024-01-23 21:33:01 +06:00
|
|
|
helper.FileDialogResize(fileDialog, v.w)
|
2024-01-18 01:39:20 +06:00
|
|
|
fileDialog.Show()
|
|
|
|
})
|
|
|
|
|
|
|
|
return
|
|
|
|
}
|