2024-01-31 21:02:12 +06:00
|
|
|
package convertor
|
2024-01-18 01:39:20 +06:00
|
|
|
|
|
|
|
import (
|
|
|
|
"fyne.io/fyne/v2"
|
|
|
|
"fyne.io/fyne/v2/canvas"
|
|
|
|
"fyne.io/fyne/v2/container"
|
2024-02-10 20:11:26 +06:00
|
|
|
"fyne.io/fyne/v2/storage"
|
2024-01-18 01:39:20 +06:00
|
|
|
"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-10 20:11:26 +06:00
|
|
|
"path/filepath"
|
2024-01-18 01:39:20 +06:00
|
|
|
)
|
|
|
|
|
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-02-04 20:16:15 +06:00
|
|
|
donwloadFFmpeg func(progressBar *widget.ProgressBar, progressMessage *canvas.Text) error,
|
2024-02-01 00:23:28 +06:00
|
|
|
) {
|
2024-02-01 00:31:28 +06:00
|
|
|
errorMessage := canvas.NewText("", color.RGBA{R: 255, G: 0, B: 0, A: 255})
|
2024-01-18 01:39:20 +06:00
|
|
|
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
|
|
|
{
|
2024-02-17 19:08:58 +06:00
|
|
|
Text: v.app.GetLocalizerService().GetMessage(&i18n.LocalizeConfig{
|
2024-01-28 22:01:16 +06:00
|
|
|
MessageID: "titleDownloadLink",
|
|
|
|
}),
|
|
|
|
Widget: link,
|
|
|
|
},
|
|
|
|
{
|
2024-02-17 19:08:58 +06:00
|
|
|
Text: v.app.GetLocalizerService().GetMessage(&i18n.LocalizeConfig{
|
2024-01-28 22:01:16 +06:00
|
|
|
MessageID: "pathToFfmpeg",
|
|
|
|
}),
|
|
|
|
Widget: buttonFFmpeg,
|
|
|
|
},
|
|
|
|
{
|
2024-02-10 20:11:26 +06:00
|
|
|
Widget: container.NewHScroll(buttonFFmpegMessage),
|
2024-01-28 22:01:16 +06:00
|
|
|
},
|
|
|
|
{
|
2024-02-17 19:08:58 +06:00
|
|
|
Text: v.app.GetLocalizerService().GetMessage(&i18n.LocalizeConfig{
|
2024-01-28 22:01:16 +06:00
|
|
|
MessageID: "pathToFfprobe",
|
|
|
|
}),
|
|
|
|
Widget: buttonFFprobe,
|
|
|
|
},
|
|
|
|
{
|
2024-02-10 20:11:26 +06:00
|
|
|
Widget: container.NewHScroll(buttonFFprobeMessage),
|
2024-01-28 22:01:16 +06:00
|
|
|
},
|
|
|
|
{
|
|
|
|
Widget: errorMessage,
|
|
|
|
},
|
2024-01-18 01:39:20 +06:00
|
|
|
},
|
2024-02-17 19:08:58 +06:00
|
|
|
SubmitText: v.app.GetLocalizerService().GetMessage(&i18n.LocalizeConfig{
|
2024-01-28 22:01:16 +06:00
|
|
|
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
|
2024-02-17 19:08:58 +06:00
|
|
|
form.CancelText = v.app.GetLocalizerService().GetMessage(&i18n.LocalizeConfig{
|
2024-02-01 00:23:28 +06:00
|
|
|
MessageID: "cancel",
|
|
|
|
})
|
|
|
|
}
|
2024-02-17 19:08:58 +06:00
|
|
|
selectFFPathTitle := v.app.GetLocalizerService().GetMessage(&i18n.LocalizeConfig{
|
2024-01-28 22:01:16 +06:00
|
|
|
MessageID: "selectFFPathTitle",
|
|
|
|
})
|
2024-02-04 20:16:15 +06:00
|
|
|
|
2024-02-17 19:08:58 +06:00
|
|
|
v.app.GetWindow().SetContent(widget.NewCard(selectFFPathTitle, "", container.NewVBox(
|
2024-02-04 20:16:15 +06:00
|
|
|
form,
|
|
|
|
v.blockDownloadFFmpeg(donwloadFFmpeg),
|
|
|
|
)))
|
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:29:11 +06:00
|
|
|
buttonMessage = canvas.NewText(path, color.RGBA{R: 49, G: 127, B: 114, A: 255})
|
2024-01-18 01:39:20 +06:00
|
|
|
buttonMessage.TextSize = 16
|
|
|
|
buttonMessage.TextStyle = fyne.TextStyle{Bold: true}
|
|
|
|
|
2024-02-17 19:08:58 +06:00
|
|
|
buttonTitle := v.app.GetLocalizerService().GetMessage(&i18n.LocalizeConfig{
|
2024-01-28 22:01:16 +06:00
|
|
|
MessageID: "choose",
|
|
|
|
})
|
|
|
|
|
2024-02-10 20:11:26 +06:00
|
|
|
var locationURI fyne.ListableURI
|
|
|
|
if len(path) > 0 {
|
|
|
|
listableURI := storage.NewFileURI(filepath.Dir(path))
|
|
|
|
locationURI, _ = storage.ListerForURI(listableURI)
|
|
|
|
}
|
|
|
|
|
2024-01-28 22:01:16 +06:00
|
|
|
button = widget.NewButton(buttonTitle, func() {
|
2024-02-17 19:08:58 +06:00
|
|
|
v.app.GetWindow().NewFileOpen(func(r fyne.URIReadCloser, err error) {
|
|
|
|
if err != nil {
|
|
|
|
buttonMessage.Text = err.Error()
|
|
|
|
setStringErrorStyle(buttonMessage)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
if r == nil {
|
|
|
|
return
|
|
|
|
}
|
2024-01-18 01:39:20 +06:00
|
|
|
|
2024-02-17 19:08:58 +06:00
|
|
|
path = r.URI().Path()
|
2024-01-18 01:39:20 +06:00
|
|
|
|
2024-02-17 19:08:58 +06:00
|
|
|
buttonMessage.Text = r.URI().Path()
|
|
|
|
setStringSuccessStyle(buttonMessage)
|
2024-02-10 20:11:26 +06:00
|
|
|
|
2024-02-17 19:08:58 +06:00
|
|
|
listableURI := storage.NewFileURI(filepath.Dir(r.URI().Path()))
|
|
|
|
locationURI, _ = storage.ListerForURI(listableURI)
|
|
|
|
}, locationURI)
|
2024-01-18 01:39:20 +06:00
|
|
|
})
|
|
|
|
|
|
|
|
return
|
|
|
|
}
|