Moved the code from src to the root.
This commit is contained in:
36
convertor/repository.go
Normal file
36
convertor/repository.go
Normal file
@@ -0,0 +1,36 @@
|
||||
package convertor
|
||||
|
||||
import (
|
||||
"git.kor-elf.net/kor-elf/gui-for-ffmpeg/setting"
|
||||
)
|
||||
|
||||
type RepositoryContract interface {
|
||||
GetPathFfmpeg() (string, error)
|
||||
SavePathFfmpeg(code string) (setting.Setting, error)
|
||||
GetPathFfprobe() (string, error)
|
||||
SavePathFfprobe(code string) (setting.Setting, error)
|
||||
}
|
||||
|
||||
type Repository struct {
|
||||
settingRepository setting.RepositoryContract
|
||||
}
|
||||
|
||||
func NewRepository(settingRepository setting.RepositoryContract) *Repository {
|
||||
return &Repository{settingRepository: settingRepository}
|
||||
}
|
||||
|
||||
func (r Repository) GetPathFfmpeg() (string, error) {
|
||||
return r.settingRepository.GetValue("ffmpeg")
|
||||
}
|
||||
|
||||
func (r Repository) SavePathFfmpeg(path string) (setting.Setting, error) {
|
||||
return r.settingRepository.CreateOrUpdate("ffmpeg", path)
|
||||
}
|
||||
|
||||
func (r Repository) GetPathFfprobe() (string, error) {
|
||||
return r.settingRepository.GetValue("ffprobe")
|
||||
}
|
||||
|
||||
func (r Repository) SavePathFfprobe(path string) (setting.Setting, error) {
|
||||
return r.settingRepository.CreateOrUpdate("ffprobe", path)
|
||||
}
|
173
convertor/service.go
Normal file
173
convertor/service.go
Normal file
@@ -0,0 +1,173 @@
|
||||
package convertor
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"git.kor-elf.net/kor-elf/gui-for-ffmpeg/helper"
|
||||
"io"
|
||||
"os/exec"
|
||||
"regexp"
|
||||
"strconv"
|
||||
"strings"
|
||||
)
|
||||
|
||||
type ServiceContract interface {
|
||||
RunConvert(setting ConvertSetting, progress ProgressContract) error
|
||||
GetTotalDuration(file *File) (float64, error)
|
||||
GetFFmpegVesrion() (string, error)
|
||||
GetFFprobeVersion() (string, error)
|
||||
ChangeFFmpegPath(path string) (bool, error)
|
||||
ChangeFFprobePath(path string) (bool, error)
|
||||
GetRunningProcesses() map[int]*exec.Cmd
|
||||
}
|
||||
|
||||
type ProgressContract interface {
|
||||
GetProtocole() string
|
||||
Run(stdOut io.ReadCloser, stdErr io.ReadCloser) error
|
||||
}
|
||||
|
||||
type FFPathUtilities struct {
|
||||
FFmpeg string
|
||||
FFprobe string
|
||||
}
|
||||
|
||||
type runningProcesses struct {
|
||||
items map[int]*exec.Cmd
|
||||
numberOfStarts int
|
||||
}
|
||||
|
||||
type Service struct {
|
||||
ffPathUtilities *FFPathUtilities
|
||||
runningProcesses runningProcesses
|
||||
}
|
||||
|
||||
type File struct {
|
||||
Path string
|
||||
Name string
|
||||
Ext string
|
||||
}
|
||||
|
||||
type ConvertSetting struct {
|
||||
VideoFileInput *File
|
||||
VideoFileOut *File
|
||||
OverwriteOutputFiles bool
|
||||
}
|
||||
|
||||
type ConvertData struct {
|
||||
totalDuration float64
|
||||
}
|
||||
|
||||
func NewService(ffPathUtilities FFPathUtilities) *Service {
|
||||
return &Service{
|
||||
ffPathUtilities: &ffPathUtilities,
|
||||
runningProcesses: runningProcesses{items: map[int]*exec.Cmd{}, numberOfStarts: 0},
|
||||
}
|
||||
}
|
||||
|
||||
func (s Service) RunConvert(setting ConvertSetting, progress ProgressContract) error {
|
||||
overwriteOutputFiles := "-n"
|
||||
if setting.OverwriteOutputFiles == true {
|
||||
overwriteOutputFiles = "-y"
|
||||
}
|
||||
args := []string{overwriteOutputFiles, "-i", setting.VideoFileInput.Path, "-c:v", "libx264", "-progress", progress.GetProtocole(), setting.VideoFileOut.Path}
|
||||
cmd := exec.Command(s.ffPathUtilities.FFmpeg, args...)
|
||||
helper.PrepareBackgroundCommand(cmd)
|
||||
|
||||
stdOut, err := cmd.StdoutPipe()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
stdErr, err := cmd.StderrPipe()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
err = cmd.Start()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
index := s.runningProcesses.numberOfStarts
|
||||
s.runningProcesses.numberOfStarts++
|
||||
s.runningProcesses.items[index] = cmd
|
||||
|
||||
errProgress := progress.Run(stdOut, stdErr)
|
||||
|
||||
err = cmd.Wait()
|
||||
delete(s.runningProcesses.items, index)
|
||||
if errProgress != nil {
|
||||
return errProgress
|
||||
}
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (s Service) 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}
|
||||
cmd := exec.Command(s.ffPathUtilities.FFprobe, args...)
|
||||
helper.PrepareBackgroundCommand(cmd)
|
||||
out, err := cmd.CombinedOutput()
|
||||
if err != nil {
|
||||
errString := strings.TrimSpace(string(out))
|
||||
if len(errString) > 1 {
|
||||
return 0, errors.New(errString)
|
||||
}
|
||||
return 0, err
|
||||
}
|
||||
return strconv.ParseFloat(strings.TrimSpace(string(out)), 64)
|
||||
}
|
||||
|
||||
func (s Service) GetFFmpegVesrion() (string, error) {
|
||||
cmd := exec.Command(s.ffPathUtilities.FFmpeg, "-version")
|
||||
helper.PrepareBackgroundCommand(cmd)
|
||||
out, err := cmd.CombinedOutput()
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
text := regexp.MustCompile("\r?\n").Split(strings.TrimSpace(string(out)), -1)
|
||||
return text[0], nil
|
||||
}
|
||||
|
||||
func (s Service) GetFFprobeVersion() (string, error) {
|
||||
cmd := exec.Command(s.ffPathUtilities.FFprobe, "-version")
|
||||
helper.PrepareBackgroundCommand(cmd)
|
||||
out, err := cmd.CombinedOutput()
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
text := regexp.MustCompile("\r?\n").Split(strings.TrimSpace(string(out)), -1)
|
||||
return text[0], nil
|
||||
}
|
||||
|
||||
func (s Service) ChangeFFmpegPath(path string) (bool, error) {
|
||||
cmd := exec.Command(path, "-version")
|
||||
helper.PrepareBackgroundCommand(cmd)
|
||||
out, err := cmd.CombinedOutput()
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
if strings.Contains(strings.TrimSpace(string(out)), "ffmpeg") == false {
|
||||
return false, nil
|
||||
}
|
||||
s.ffPathUtilities.FFmpeg = path
|
||||
return true, nil
|
||||
}
|
||||
|
||||
func (s Service) ChangeFFprobePath(path string) (bool, error) {
|
||||
cmd := exec.Command(path, "-version")
|
||||
helper.PrepareBackgroundCommand(cmd)
|
||||
out, err := cmd.CombinedOutput()
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
if strings.Contains(strings.TrimSpace(string(out)), "ffprobe") == false {
|
||||
return false, nil
|
||||
}
|
||||
s.ffPathUtilities.FFprobe = path
|
||||
return true, nil
|
||||
}
|
||||
|
||||
func (s Service) GetRunningProcesses() map[int]*exec.Cmd {
|
||||
return s.runningProcesses.items
|
||||
}
|
253
convertor/view.go
Normal file
253
convertor/view.go
Normal file
@@ -0,0 +1,253 @@
|
||||
package convertor
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"fyne.io/fyne/v2"
|
||||
"fyne.io/fyne/v2/canvas"
|
||||
"fyne.io/fyne/v2/container"
|
||||
"fyne.io/fyne/v2/dialog"
|
||||
"fyne.io/fyne/v2/storage"
|
||||
"fyne.io/fyne/v2/widget"
|
||||
"git.kor-elf.net/kor-elf/gui-for-ffmpeg/helper"
|
||||
"git.kor-elf.net/kor-elf/gui-for-ffmpeg/localizer"
|
||||
"github.com/nicksnyder/go-i18n/v2/i18n"
|
||||
"image/color"
|
||||
"path/filepath"
|
||||
)
|
||||
|
||||
type ViewContract interface {
|
||||
Main(
|
||||
runConvert func(setting HandleConvertSetting, progressbar *widget.ProgressBar) error,
|
||||
)
|
||||
SelectFFPath(
|
||||
ffmpegPath string,
|
||||
ffprobePath string,
|
||||
save func(ffmpegPath string, ffprobePath string) error,
|
||||
cancel func(),
|
||||
donwloadFFmpeg func(progressBar *widget.ProgressBar, progressMessage *canvas.Text) error,
|
||||
)
|
||||
}
|
||||
|
||||
type View struct {
|
||||
w fyne.Window
|
||||
localizerService localizer.ServiceContract
|
||||
}
|
||||
|
||||
type HandleConvertSetting struct {
|
||||
VideoFileInput *File
|
||||
DirectoryForSave string
|
||||
OverwriteOutputFiles bool
|
||||
}
|
||||
|
||||
type enableFormConversionStruct struct {
|
||||
fileVideoForConversion *widget.Button
|
||||
buttonForSelectedDir *widget.Button
|
||||
form *widget.Form
|
||||
}
|
||||
|
||||
func NewView(w fyne.Window, localizerService localizer.ServiceContract) *View {
|
||||
return &View{
|
||||
w: w,
|
||||
localizerService: localizerService,
|
||||
}
|
||||
}
|
||||
|
||||
func (v View) Main(
|
||||
runConvert func(setting HandleConvertSetting, progressbar *widget.ProgressBar) error,
|
||||
) {
|
||||
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}
|
||||
|
||||
progress := widget.NewProgressBar()
|
||||
|
||||
fileVideoForConversion, fileVideoForConversionMessage, fileInput := v.getButtonFileVideoForConversion(form, progress, conversionMessage)
|
||||
buttonForSelectedDir, buttonForSelectedDirMessage, pathToSaveDirectory := v.getButtonForSelectingDirectoryForSaving()
|
||||
|
||||
isOverwriteOutputFiles := false
|
||||
checkboxOverwriteOutputFilesTitle := v.localizerService.GetMessage(&i18n.LocalizeConfig{
|
||||
MessageID: "checkboxOverwriteOutputFilesTitle",
|
||||
})
|
||||
checkboxOverwriteOutputFiles := widget.NewCheck(checkboxOverwriteOutputFilesTitle, func(b bool) {
|
||||
isOverwriteOutputFiles = b
|
||||
})
|
||||
|
||||
form.Items = []*widget.FormItem{
|
||||
{
|
||||
Text: v.localizerService.GetMessage(&i18n.LocalizeConfig{MessageID: "fileVideoForConversionTitle"}),
|
||||
Widget: fileVideoForConversion,
|
||||
},
|
||||
{
|
||||
Widget: container.NewHScroll(fileVideoForConversionMessage),
|
||||
},
|
||||
{
|
||||
Text: v.localizerService.GetMessage(&i18n.LocalizeConfig{MessageID: "buttonForSelectedDirTitle"}),
|
||||
Widget: buttonForSelectedDir,
|
||||
},
|
||||
{
|
||||
Widget: container.NewHScroll(buttonForSelectedDirMessage),
|
||||
},
|
||||
{
|
||||
Widget: checkboxOverwriteOutputFiles,
|
||||
},
|
||||
}
|
||||
form.SubmitText = v.localizerService.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.localizerService.GetMessage(&i18n.LocalizeConfig{
|
||||
MessageID: "errorSelectedFolderSave",
|
||||
})))
|
||||
enableFormConversion(enableFormConversionStruct)
|
||||
return
|
||||
}
|
||||
conversionMessage.Text = ""
|
||||
|
||||
fileVideoForConversion.Disable()
|
||||
buttonForSelectedDir.Disable()
|
||||
form.Disable()
|
||||
|
||||
setting := HandleConvertSetting{
|
||||
VideoFileInput: fileInput,
|
||||
DirectoryForSave: *pathToSaveDirectory,
|
||||
OverwriteOutputFiles: isOverwriteOutputFiles,
|
||||
}
|
||||
err := runConvert(setting, progress)
|
||||
if err != nil {
|
||||
showConversionMessage(conversionMessage, err)
|
||||
enableFormConversion(enableFormConversionStruct)
|
||||
return
|
||||
}
|
||||
enableFormConversion(enableFormConversionStruct)
|
||||
}
|
||||
|
||||
converterVideoFilesTitle := v.localizerService.GetMessage(&i18n.LocalizeConfig{
|
||||
MessageID: "converterVideoFilesTitle",
|
||||
})
|
||||
v.w.SetContent(widget.NewCard(converterVideoFilesTitle, "", container.NewVBox(form, conversionMessage, progress)))
|
||||
form.Disable()
|
||||
}
|
||||
|
||||
func (v View) getButtonFileVideoForConversion(form *widget.Form, progress *widget.ProgressBar, conversionMessage *canvas.Text) (*widget.Button, *canvas.Text, *File) {
|
||||
fileInput := &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.localizerService.GetMessage(&i18n.LocalizeConfig{
|
||||
MessageID: "choose",
|
||||
})
|
||||
|
||||
var locationURI fyne.ListableURI
|
||||
|
||||
button := widget.NewButton(buttonTitle, func() {
|
||||
fileDialog := dialog.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()
|
||||
progress.Value = 0
|
||||
progress.Refresh()
|
||||
conversionMessage.Text = ""
|
||||
|
||||
listableURI := storage.NewFileURI(filepath.Dir(r.URI().Path()))
|
||||
locationURI, err = storage.ListerForURI(listableURI)
|
||||
}, v.w)
|
||||
helper.FileDialogResize(fileDialog, v.w)
|
||||
fileDialog.Show()
|
||||
if locationURI != nil {
|
||||
fileDialog.SetLocation(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.localizerService.GetMessage(&i18n.LocalizeConfig{
|
||||
MessageID: "choose",
|
||||
})
|
||||
|
||||
var locationURI fyne.ListableURI
|
||||
|
||||
button = widget.NewButton(buttonTitle, func() {
|
||||
fileDialog := dialog.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)
|
||||
|
||||
}, v.w)
|
||||
helper.FileDialogResize(fileDialog, v.w)
|
||||
fileDialog.Show()
|
||||
if locationURI != nil {
|
||||
fileDialog.SetLocation(locationURI)
|
||||
}
|
||||
})
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
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)
|
||||
}
|
||||
|
||||
func enableFormConversion(enableFormConversionStruct enableFormConversionStruct) {
|
||||
enableFormConversionStruct.fileVideoForConversion.Enable()
|
||||
enableFormConversionStruct.buttonForSelectedDir.Enable()
|
||||
enableFormConversionStruct.form.Enable()
|
||||
}
|
138
convertor/view_setting.go
Normal file
138
convertor/view_setting.go
Normal file
@@ -0,0 +1,138 @@
|
||||
package convertor
|
||||
|
||||
import (
|
||||
"fyne.io/fyne/v2"
|
||||
"fyne.io/fyne/v2/canvas"
|
||||
"fyne.io/fyne/v2/container"
|
||||
"fyne.io/fyne/v2/dialog"
|
||||
"fyne.io/fyne/v2/storage"
|
||||
"fyne.io/fyne/v2/widget"
|
||||
"git.kor-elf.net/kor-elf/gui-for-ffmpeg/helper"
|
||||
"github.com/nicksnyder/go-i18n/v2/i18n"
|
||||
"image/color"
|
||||
"net/url"
|
||||
"path/filepath"
|
||||
)
|
||||
|
||||
func (v View) SelectFFPath(
|
||||
currentPathFfmpeg string,
|
||||
currentPathFfprobe string,
|
||||
save func(ffmpegPath string, ffprobePath string) error,
|
||||
cancel func(),
|
||||
donwloadFFmpeg func(progressBar *widget.ProgressBar, progressMessage *canvas.Text) error,
|
||||
) {
|
||||
errorMessage := canvas.NewText("", color.RGBA{R: 255, G: 0, B: 0, A: 255})
|
||||
errorMessage.TextSize = 16
|
||||
errorMessage.TextStyle = fyne.TextStyle{Bold: true}
|
||||
|
||||
ffmpegPath, buttonFFmpeg, buttonFFmpegMessage := v.getButtonSelectFile(currentPathFfmpeg)
|
||||
ffprobePath, buttonFFprobe, buttonFFprobeMessage := v.getButtonSelectFile(currentPathFfprobe)
|
||||
|
||||
link := widget.NewHyperlink("https://ffmpeg.org/download.html", &url.URL{
|
||||
Scheme: "https",
|
||||
Host: "ffmpeg.org",
|
||||
Path: "download.html",
|
||||
})
|
||||
|
||||
form := &widget.Form{
|
||||
Items: []*widget.FormItem{
|
||||
{
|
||||
Text: v.localizerService.GetMessage(&i18n.LocalizeConfig{
|
||||
MessageID: "titleDownloadLink",
|
||||
}),
|
||||
Widget: link,
|
||||
},
|
||||
{
|
||||
Text: v.localizerService.GetMessage(&i18n.LocalizeConfig{
|
||||
MessageID: "pathToFfmpeg",
|
||||
}),
|
||||
Widget: buttonFFmpeg,
|
||||
},
|
||||
{
|
||||
Widget: container.NewHScroll(buttonFFmpegMessage),
|
||||
},
|
||||
{
|
||||
Text: v.localizerService.GetMessage(&i18n.LocalizeConfig{
|
||||
MessageID: "pathToFfprobe",
|
||||
}),
|
||||
Widget: buttonFFprobe,
|
||||
},
|
||||
{
|
||||
Widget: container.NewHScroll(buttonFFprobeMessage),
|
||||
},
|
||||
{
|
||||
Widget: errorMessage,
|
||||
},
|
||||
},
|
||||
SubmitText: v.localizerService.GetMessage(&i18n.LocalizeConfig{
|
||||
MessageID: "save",
|
||||
}),
|
||||
OnSubmit: func() {
|
||||
err := save(*ffmpegPath, *ffprobePath)
|
||||
if err != nil {
|
||||
errorMessage.Text = err.Error()
|
||||
}
|
||||
},
|
||||
}
|
||||
if cancel != nil {
|
||||
form.OnCancel = cancel
|
||||
form.CancelText = v.localizerService.GetMessage(&i18n.LocalizeConfig{
|
||||
MessageID: "cancel",
|
||||
})
|
||||
}
|
||||
selectFFPathTitle := v.localizerService.GetMessage(&i18n.LocalizeConfig{
|
||||
MessageID: "selectFFPathTitle",
|
||||
})
|
||||
|
||||
v.w.SetContent(widget.NewCard(selectFFPathTitle, "", container.NewVBox(
|
||||
form,
|
||||
v.blockDownloadFFmpeg(donwloadFFmpeg),
|
||||
)))
|
||||
}
|
||||
|
||||
func (v View) getButtonSelectFile(path string) (filePath *string, button *widget.Button, buttonMessage *canvas.Text) {
|
||||
filePath = &path
|
||||
|
||||
buttonMessage = canvas.NewText(path, color.RGBA{R: 49, G: 127, B: 114, A: 255})
|
||||
buttonMessage.TextSize = 16
|
||||
buttonMessage.TextStyle = fyne.TextStyle{Bold: true}
|
||||
|
||||
buttonTitle := v.localizerService.GetMessage(&i18n.LocalizeConfig{
|
||||
MessageID: "choose",
|
||||
})
|
||||
|
||||
var locationURI fyne.ListableURI
|
||||
if len(path) > 0 {
|
||||
listableURI := storage.NewFileURI(filepath.Dir(path))
|
||||
locationURI, _ = storage.ListerForURI(listableURI)
|
||||
}
|
||||
|
||||
button = widget.NewButton(buttonTitle, func() {
|
||||
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)
|
||||
|
||||
listableURI := storage.NewFileURI(filepath.Dir(r.URI().Path()))
|
||||
locationURI, _ = storage.ListerForURI(listableURI)
|
||||
}, v.w)
|
||||
helper.FileDialogResize(fileDialog, v.w)
|
||||
fileDialog.Show()
|
||||
if locationURI != nil {
|
||||
fileDialog.SetLocation(locationURI)
|
||||
}
|
||||
})
|
||||
|
||||
return
|
||||
}
|
17
convertor/view_setting_button_download_ffmpeg_anyos.go
Normal file
17
convertor/view_setting_button_download_ffmpeg_anyos.go
Normal file
@@ -0,0 +1,17 @@
|
||||
//go:build !windows
|
||||
// +build !windows
|
||||
|
||||
package convertor
|
||||
|
||||
import (
|
||||
"fyne.io/fyne/v2"
|
||||
"fyne.io/fyne/v2/canvas"
|
||||
"fyne.io/fyne/v2/container"
|
||||
"fyne.io/fyne/v2/widget"
|
||||
)
|
||||
|
||||
func (v View) blockDownloadFFmpeg(
|
||||
donwloadFFmpeg func(progressBar *widget.ProgressBar, progressMessage *canvas.Text) error,
|
||||
) *fyne.Container {
|
||||
return container.NewVBox()
|
||||
}
|
63
convertor/view_setting_button_download_ffmpeg_windows.go
Normal file
63
convertor/view_setting_button_download_ffmpeg_windows.go
Normal file
@@ -0,0 +1,63 @@
|
||||
//go:build windows
|
||||
// +build windows
|
||||
|
||||
package convertor
|
||||
|
||||
import (
|
||||
"fyne.io/fyne/v2"
|
||||
"fyne.io/fyne/v2/canvas"
|
||||
"fyne.io/fyne/v2/container"
|
||||
"fyne.io/fyne/v2/widget"
|
||||
"github.com/nicksnyder/go-i18n/v2/i18n"
|
||||
"golang.org/x/image/colornames"
|
||||
"image/color"
|
||||
)
|
||||
|
||||
func (v View) blockDownloadFFmpeg(
|
||||
donwloadFFmpeg func(progressBar *widget.ProgressBar, progressMessage *canvas.Text) error,
|
||||
) *fyne.Container {
|
||||
|
||||
errorDownloadFFmpegMessage := canvas.NewText("", color.RGBA{R: 255, G: 0, B: 0, A: 255})
|
||||
errorDownloadFFmpegMessage.TextSize = 16
|
||||
errorDownloadFFmpegMessage.TextStyle = fyne.TextStyle{Bold: true}
|
||||
|
||||
progressDownloadFFmpegMessage := canvas.NewText("", color.RGBA{R: 49, G: 127, B: 114, A: 255})
|
||||
progressDownloadFFmpegMessage.TextSize = 16
|
||||
progressDownloadFFmpegMessage.TextStyle = fyne.TextStyle{Bold: true}
|
||||
|
||||
progressBar := widget.NewProgressBar()
|
||||
|
||||
var buttonDownloadFFmpeg *widget.Button
|
||||
|
||||
buttonDownloadFFmpeg = widget.NewButton(v.localizerService.GetMessage(&i18n.LocalizeConfig{
|
||||
MessageID: "download",
|
||||
}), func() {
|
||||
buttonDownloadFFmpeg.Disable()
|
||||
|
||||
err := donwloadFFmpeg(progressBar, progressDownloadFFmpegMessage)
|
||||
if err != nil {
|
||||
errorDownloadFFmpegMessage.Text = err.Error()
|
||||
}
|
||||
|
||||
buttonDownloadFFmpeg.Enable()
|
||||
})
|
||||
|
||||
downloadFFmpegFromSiteMessage := v.localizerService.GetMessage(&i18n.LocalizeConfig{
|
||||
MessageID: "downloadFFmpegFromSite",
|
||||
})
|
||||
|
||||
return container.NewVBox(
|
||||
canvas.NewLine(colornames.Darkgreen),
|
||||
widget.NewCard(v.localizerService.GetMessage(&i18n.LocalizeConfig{
|
||||
MessageID: "buttonDownloadFFmpeg",
|
||||
}), "", container.NewVBox(
|
||||
widget.NewRichTextFromMarkdown(
|
||||
downloadFFmpegFromSiteMessage+" [https://github.com/BtbN/FFmpeg-Builds/releases](https://github.com/BtbN/FFmpeg-Builds/releases)",
|
||||
),
|
||||
buttonDownloadFFmpeg,
|
||||
errorDownloadFFmpegMessage,
|
||||
progressDownloadFFmpegMessage,
|
||||
progressBar,
|
||||
)),
|
||||
)
|
||||
}
|
Reference in New Issue
Block a user