From 0d5cfab38d25f6d8ae1a8b5456cd1f9b16ac6bbb Mon Sep 17 00:00:00 2001 From: Leonid Nikitin Date: Thu, 1 Feb 2024 00:23:28 +0600 Subject: [PATCH] Made it possible to change the path to FFmpeg and FFprobe. --- src/convertor/repository.go | 36 +++++++++++++++++++++++++++++ src/convertor/view.go | 5 ++++- src/convertor/view_setting.go | 24 ++++++++++++++------ src/handler/convertor.go | 40 +++++++++++++++++---------------- src/handler/menu.go | 7 +++++- src/languages/active.en.toml | 8 +++++++ src/languages/active.kk.toml | 8 +++++++ src/languages/active.ru.toml | 2 ++ src/languages/translate.en.toml | 14 +++--------- src/languages/translate.kk.toml | 14 +++--------- src/main.go | 7 +++--- 11 files changed, 112 insertions(+), 53 deletions(-) create mode 100644 src/convertor/repository.go diff --git a/src/convertor/repository.go b/src/convertor/repository.go new file mode 100644 index 0000000..1444a49 --- /dev/null +++ b/src/convertor/repository.go @@ -0,0 +1,36 @@ +package convertor + +import ( + "ffmpegGui/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) +} diff --git a/src/convertor/view.go b/src/convertor/view.go index 669514e..3ef51a9 100644 --- a/src/convertor/view.go +++ b/src/convertor/view.go @@ -18,7 +18,10 @@ type ViewContract interface { runConvert func(setting HandleConvertSetting, progressbar *widget.ProgressBar) error, ) SelectFFPath( - func(ffmpegPath string, ffprobePath string) error, + ffmpegPath string, + ffprobePath string, + save func(ffmpegPath string, ffprobePath string) error, + cancel func(), ) } diff --git a/src/convertor/view_setting.go b/src/convertor/view_setting.go index 0d29a09..86fb549 100644 --- a/src/convertor/view_setting.go +++ b/src/convertor/view_setting.go @@ -12,13 +12,18 @@ import ( "net/url" ) -func (v View) SelectFFPath(save func(ffmpegPath string, ffprobePath string) error) { +func (v View) SelectFFPath( + currentPathFfmpeg string, + currentPathFfprobe string, + save func(ffmpegPath string, ffprobePath string) error, + cancel func(), +) { errorMessage := canvas.NewText("", color.RGBA{255, 0, 0, 255}) errorMessage.TextSize = 16 errorMessage.TextStyle = fyne.TextStyle{Bold: true} - ffmpegPath, buttonFFmpeg, buttonFFmpegMessage := v.getButtonSelectFile() - ffprobePath, buttonFFprobe, buttonFFprobeMessage := v.getButtonSelectFile() + ffmpegPath, buttonFFmpeg, buttonFFmpegMessage := v.getButtonSelectFile(currentPathFfmpeg) + ffprobePath, buttonFFprobe, buttonFFprobeMessage := v.getButtonSelectFile(currentPathFfprobe) link := widget.NewHyperlink("https://ffmpeg.org/download.html", &url.URL{ Scheme: "https", @@ -60,23 +65,28 @@ func (v View) SelectFFPath(save func(ffmpegPath string, ffprobePath string) erro MessageID: "save", }), OnSubmit: func() { - err := save(string(*ffmpegPath), string(*ffprobePath)) + 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))) } -func (v View) getButtonSelectFile() (filePath *string, button *widget.Button, buttonMessage *canvas.Text) { - path := "" +func (v View) getButtonSelectFile(path string) (filePath *string, button *widget.Button, buttonMessage *canvas.Text) { filePath = &path - buttonMessage = canvas.NewText("", color.RGBA{255, 0, 0, 255}) + buttonMessage = canvas.NewText(path, color.RGBA{49, 127, 114, 255}) buttonMessage.TextSize = 16 buttonMessage.TextStyle = fyne.TextStyle{Bold: true} diff --git a/src/handler/convertor.go b/src/handler/convertor.go index dbe9f2e..c588812 100644 --- a/src/handler/convertor.go +++ b/src/handler/convertor.go @@ -6,7 +6,6 @@ import ( "ffmpegGui/convertor" "ffmpegGui/helper" "ffmpegGui/localizer" - "ffmpegGui/setting" "fyne.io/fyne/v2/widget" "github.com/nicksnyder/go-i18n/v2/i18n" "io" @@ -17,26 +16,27 @@ import ( type ConvertorHandlerContract interface { MainConvertor() + FfPathSelection() } type ConvertorHandler struct { - convertorService convertor.ServiceContract - convertorView convertor.ViewContract - settingRepository setting.RepositoryContract - localizerService localizer.ServiceContract + convertorService convertor.ServiceContract + convertorView convertor.ViewContract + convertorRepository convertor.RepositoryContract + localizerService localizer.ServiceContract } func NewConvertorHandler( convertorService convertor.ServiceContract, convertorView convertor.ViewContract, - settingRepository setting.RepositoryContract, + convertorRepository convertor.RepositoryContract, localizerService localizer.ServiceContract, ) *ConvertorHandler { return &ConvertorHandler{ - convertorService: convertorService, - convertorView: convertorView, - settingRepository: settingRepository, - localizerService: localizerService, + convertorService: convertorService, + convertorView: convertorView, + convertorRepository: convertorRepository, + localizerService: localizerService, } } @@ -45,7 +45,13 @@ func (h ConvertorHandler) MainConvertor() { h.convertorView.Main(h.runConvert) return } - h.convertorView.SelectFFPath(h.saveSettingFFPath) + h.convertorView.SelectFFPath("", "", h.saveSettingFFPath, nil) +} + +func (h ConvertorHandler) FfPathSelection() { + ffmpeg, _ := h.convertorRepository.GetPathFfmpeg() + ffprobe, _ := h.convertorRepository.GetPathFfprobe() + h.convertorView.SelectFFPath(ffmpeg, ffprobe, h.saveSettingFFPath, h.MainConvertor) } func (h ConvertorHandler) runConvert(setting convertor.HandleConvertSetting, progressbar *widget.ProgressBar) error { @@ -84,10 +90,8 @@ func (h ConvertorHandler) checkingFFPathUtilities() bool { if ffprobeChecking == false { continue } - ffmpegEntity := setting.Setting{Code: "ffmpeg", Value: item.FFmpeg} - _, _ = h.settingRepository.Create(ffmpegEntity) - ffprobeEntity := setting.Setting{Code: "ffprobe", Value: item.FFprobe} - _, _ = h.settingRepository.Create(ffprobeEntity) + _, _ = h.convertorRepository.SavePathFfmpeg(item.FFmpeg) + _, _ = h.convertorRepository.SavePathFfprobe(item.FFprobe) return true } @@ -111,10 +115,8 @@ func (h ConvertorHandler) saveSettingFFPath(ffmpegPath string, ffprobePath strin return errors.New(errorText) } - ffmpegEntity := setting.Setting{Code: "ffmpeg", Value: ffmpegPath} - _, _ = h.settingRepository.Create(ffmpegEntity) - ffprobeEntity := setting.Setting{Code: "ffprobe", Value: ffprobePath} - _, _ = h.settingRepository.Create(ffprobeEntity) + _, _ = h.convertorRepository.SavePathFfmpeg(ffmpegPath) + _, _ = h.convertorRepository.SavePathFfprobe(ffprobePath) h.MainConvertor() diff --git a/src/handler/menu.go b/src/handler/menu.go index 495a3b8..acf3ea1 100644 --- a/src/handler/menu.go +++ b/src/handler/menu.go @@ -51,9 +51,14 @@ func (h MenuHandler) GetMainMenu() *fyne.MainMenu { }), h.LanguageSelection) h.menuItems.menuItem["changeLanguage"] = languageSelection + ffPathSelection := fyne.NewMenuItem(h.localizerService.GetMessage(&i18n.LocalizeConfig{ + MessageID: "changeFFPath", + }), h.convertorHandler.FfPathSelection) + h.menuItems.menuItem["changeFFPath"] = ffPathSelection + settings := fyne.NewMenu(h.localizerService.GetMessage(&i18n.LocalizeConfig{ MessageID: "settings", - }), languageSelection, quit) + }), languageSelection, ffPathSelection, quit) h.menuItems.menu["settings"] = settings return fyne.NewMainMenu(settings) diff --git a/src/languages/active.en.toml b/src/languages/active.en.toml index cd9dfee..befaf9b 100644 --- a/src/languages/active.en.toml +++ b/src/languages/active.en.toml @@ -2,6 +2,14 @@ hash = "sha1-52b13f1b13e82d22e8c4102332db5d4ec551247b" other = "Folder where it will be saved:" +[cancel] +hash = "sha1-0ec753be8df955a117404fb634b01b45eb386e2a" +other = "Cancel" + +[changeFFPath] +hash = "sha1-46793a2844600d0eb19fa3540fb9564ee5705491" +other = "FFmpeg and FFprobe" + [changeLanguage] hash = "sha1-8b276eaf378d485c769fb3d5dcc06dfc25b0c01b" other = "Change language" diff --git a/src/languages/active.kk.toml b/src/languages/active.kk.toml index 6e443e3..e6dbed0 100644 --- a/src/languages/active.kk.toml +++ b/src/languages/active.kk.toml @@ -2,6 +2,14 @@ hash = "sha1-52b13f1b13e82d22e8c4102332db5d4ec551247b" other = "Файлды сақтауға арналған каталог:" +[cancel] +hash = "sha1-0ec753be8df955a117404fb634b01b45eb386e2a" +other = "Болдырмау" + +[changeFFPath] +hash = "sha1-46793a2844600d0eb19fa3540fb9564ee5705491" +other = "FFmpeg және FFprobe" + [changeLanguage] hash = "sha1-8b276eaf378d485c769fb3d5dcc06dfc25b0c01b" other = "Тілді өзгерту" diff --git a/src/languages/active.ru.toml b/src/languages/active.ru.toml index 11e08c5..be7cc00 100644 --- a/src/languages/active.ru.toml +++ b/src/languages/active.ru.toml @@ -1,4 +1,6 @@ buttonForSelectedDirTitle = "Папка куда будет сохраняться:" +cancel = "Отмена" +changeFFPath = "FFmpeg и FFprobe" changeLanguage = "Поменять язык" checkboxOverwriteOutputFilesTitle = "Разрешить перезаписать файл" choose = "выбрать" diff --git a/src/languages/translate.en.toml b/src/languages/translate.en.toml index 5adccc4..959b136 100644 --- a/src/languages/translate.en.toml +++ b/src/languages/translate.en.toml @@ -1,11 +1,3 @@ -[changeLanguage] -hash = "sha1-8b276eaf378d485c769fb3d5dcc06dfc25b0c01b" -other = "Change language" - -[exit] -hash = "sha1-c42457057d1ab7950cea00719cbe0b078891775f" -other = "Exit" - -[settings] -hash = "sha1-7f17c7c62a7fd8d1a508481f4778688927734c2f" -other = "Settings" +[changeFFPath] +hash = "sha1-46793a2844600d0eb19fa3540fb9564ee5705491" +other = "FFmpeg and FFprobe" diff --git a/src/languages/translate.kk.toml b/src/languages/translate.kk.toml index 863f5ce..cc14cef 100644 --- a/src/languages/translate.kk.toml +++ b/src/languages/translate.kk.toml @@ -1,11 +1,3 @@ -[changeLanguage] -hash = "sha1-8b276eaf378d485c769fb3d5dcc06dfc25b0c01b" -other = "Тілді өзгерту" - -[exit] -hash = "sha1-c42457057d1ab7950cea00719cbe0b078891775f" -other = "Шығу" - -[settings] -hash = "sha1-7f17c7c62a7fd8d1a508481f4778688927734c2f" -other = "Параметрлер" +[changeFFPath] +hash = "sha1-46793a2844600d0eb19fa3540fb9564ee5705491" +other = "FFmpeg және FFprobe" diff --git a/src/main.go b/src/main.go index ec369ce..c127694 100644 --- a/src/main.go +++ b/src/main.go @@ -62,13 +62,14 @@ func main() { } settingRepository := setting.NewRepository(db) - pathFFmpeg, err := settingRepository.GetValue("ffmpeg") + convertorRepository := convertor.NewRepository(settingRepository) + pathFFmpeg, err := convertorRepository.GetPathFfmpeg() if err != nil && errors.Is(err, gorm.ErrRecordNotFound) == false { errorView.PanicError(err) w.ShowAndRun() return } - pathFFprobe, err := settingRepository.GetValue("ffprobe") + pathFFprobe, err := convertorRepository.GetPathFfprobe() if err != nil && errors.Is(err, gorm.ErrRecordNotFound) == false { errorView.PanicError(err) w.ShowAndRun() @@ -81,7 +82,7 @@ func main() { convertorView := convertor.NewView(w, localizerService) convertorService := convertor.NewService(ffPathUtilities) defer appCloseWithConvert(convertorService) - convertorHandler := handler.NewConvertorHandler(convertorService, convertorView, settingRepository, localizerService) + convertorHandler := handler.NewConvertorHandler(convertorService, convertorView, convertorRepository, localizerService) localizerRepository := localizer.NewRepository(settingRepository) mainMenu := handler.NewMenuHandler(convertorHandler, localizerService, localizerView, localizerRepository)