Add directory selection for saving converted files
Introduce logic and UI for selecting and persisting a directory to save converted files. Extend existing components with directory selection buttons, message updates, and storage preferences.
This commit is contained in:
parent
394824ce88
commit
6c0abac1c5
@ -10,10 +10,16 @@ type SettingContract interface {
|
|||||||
GetLanguages() []Lang
|
GetLanguages() []Lang
|
||||||
GetCurrentLangOrDefaultLang() (currentLang Lang, isDefault bool)
|
GetCurrentLangOrDefaultLang() (currentLang Lang, isDefault bool)
|
||||||
SetLang(language Lang) error
|
SetLang(language Lang) error
|
||||||
|
|
||||||
|
GetDirectoryForSaving() string
|
||||||
|
SetDirectoryForSaving(path string)
|
||||||
|
|
||||||
GetFFmpegPath() string
|
GetFFmpegPath() string
|
||||||
SetFFmpegPath(path string)
|
SetFFmpegPath(path string)
|
||||||
|
|
||||||
GetFFprobePath() string
|
GetFFprobePath() string
|
||||||
SetFFprobePath(path string)
|
SetFFprobePath(path string)
|
||||||
|
|
||||||
GetFFplayPath() string
|
GetFFplayPath() string
|
||||||
SetFFplayPath(path string)
|
SetFFplayPath(path string)
|
||||||
}
|
}
|
||||||
@ -63,3 +69,11 @@ func (s *setting) SetLang(language Lang) error {
|
|||||||
s.fyneApp.Preferences().SetString("language", language.Code)
|
s.fyneApp.Preferences().SetString("language", language.Code)
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (s *setting) GetDirectoryForSaving() string {
|
||||||
|
return s.fyneApp.Preferences().String("directoryForSaving")
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *setting) SetDirectoryForSaving(path string) {
|
||||||
|
s.fyneApp.Preferences().SetString("directoryForSaving", path)
|
||||||
|
}
|
||||||
|
@ -7,7 +7,12 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func (c *controller) convertor() {
|
func (c *controller) convertor() {
|
||||||
content := view.Convertor(c.window, c.addFileForConversion)
|
content := view.Convertor(
|
||||||
|
c.window,
|
||||||
|
c.addFileForConversion,
|
||||||
|
c.app.GetSetting().GetDirectoryForSaving(),
|
||||||
|
c.setDirectoryForSaving,
|
||||||
|
)
|
||||||
c.window.SetContent(content)
|
c.window.SetContent(content)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -16,6 +21,10 @@ func (c *controller) addFileForConversion(file ffmpeg.File) {
|
|||||||
c.window.GetLayout().GetRContainer().SelectAddedFilesTab()
|
c.window.GetLayout().GetRContainer().SelectAddedFilesTab()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (c *controller) setDirectoryForSaving(path string) {
|
||||||
|
c.app.GetSetting().SetDirectoryForSaving(path)
|
||||||
|
}
|
||||||
|
|
||||||
func (c *controller) settingConvertor(isAllowCancellation bool) {
|
func (c *controller) settingConvertor(isAllowCancellation bool) {
|
||||||
ffmpegPath := c.app.GetFFmpegService().GetFFmpegPath()
|
ffmpegPath := c.app.GetFFmpegService().GetFFmpegPath()
|
||||||
ffprobePath := c.app.GetFFmpegService().GetFFprobePath()
|
ffprobePath := c.app.GetFFmpegService().GetFFprobePath()
|
||||||
|
@ -17,8 +17,18 @@ import (
|
|||||||
"path/filepath"
|
"path/filepath"
|
||||||
)
|
)
|
||||||
|
|
||||||
func Convertor(window window.WindowContract, addFileForConversion func(file ffmpeg.File)) fyne.CanvasObject {
|
func Convertor(
|
||||||
form := newFormConvertor(window, addFileForConversion)
|
window window.WindowContract,
|
||||||
|
addFileForConversion func(file ffmpeg.File),
|
||||||
|
directoryForSavingPath string,
|
||||||
|
directoryForSaving func(path string),
|
||||||
|
) fyne.CanvasObject {
|
||||||
|
form := newFormConvertor(
|
||||||
|
window,
|
||||||
|
addFileForConversion,
|
||||||
|
directoryForSavingPath,
|
||||||
|
directoryForSaving,
|
||||||
|
)
|
||||||
|
|
||||||
converterVideoFilesTitle := lang.L("converterVideoFilesTitle")
|
converterVideoFilesTitle := lang.L("converterVideoFilesTitle")
|
||||||
return widget.NewCard(converterVideoFilesTitle, "", container.NewVScroll(form.getForm()))
|
return widget.NewCard(converterVideoFilesTitle, "", container.NewVScroll(form.getForm()))
|
||||||
@ -30,9 +40,15 @@ type formConvertor struct {
|
|||||||
|
|
||||||
window window.WindowContract
|
window window.WindowContract
|
||||||
addFileForConversion func(file ffmpeg.File)
|
addFileForConversion func(file ffmpeg.File)
|
||||||
|
directoryForSaving func(path string)
|
||||||
}
|
}
|
||||||
|
|
||||||
func newFormConvertor(window window.WindowContract, addFileForConversion func(file ffmpeg.File)) *formConvertor {
|
func newFormConvertor(
|
||||||
|
window window.WindowContract,
|
||||||
|
addFileForConversion func(file ffmpeg.File),
|
||||||
|
directoryForSavingPath string,
|
||||||
|
directoryForSaving func(path string),
|
||||||
|
) *formConvertor {
|
||||||
f := widget.NewForm()
|
f := widget.NewForm()
|
||||||
f.SubmitText = lang.L("converterVideoFilesSubmitTitle")
|
f.SubmitText = lang.L("converterVideoFilesSubmitTitle")
|
||||||
|
|
||||||
@ -40,9 +56,11 @@ func newFormConvertor(window window.WindowContract, addFileForConversion func(fi
|
|||||||
form: f,
|
form: f,
|
||||||
window: window,
|
window: window,
|
||||||
addFileForConversion: addFileForConversion,
|
addFileForConversion: addFileForConversion,
|
||||||
|
directoryForSaving: directoryForSaving,
|
||||||
}
|
}
|
||||||
|
|
||||||
fileForConversion := formConvertor.newFileForConversion()
|
fileForConversion := formConvertor.newFileForConversion()
|
||||||
|
directoryForSavingButton := formConvertor.newDirectoryForSaving(directoryForSavingPath)
|
||||||
|
|
||||||
items := []*widget.FormItem{
|
items := []*widget.FormItem{
|
||||||
{
|
{
|
||||||
@ -52,6 +70,14 @@ func newFormConvertor(window window.WindowContract, addFileForConversion func(fi
|
|||||||
{
|
{
|
||||||
Widget: container.NewHScroll(fileForConversion.message),
|
Widget: container.NewHScroll(fileForConversion.message),
|
||||||
},
|
},
|
||||||
|
|
||||||
|
{
|
||||||
|
Text: lang.L("buttonForSelectedDirTitle"),
|
||||||
|
Widget: directoryForSavingButton.button,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
Widget: container.NewHScroll(directoryForSavingButton.message),
|
||||||
|
},
|
||||||
}
|
}
|
||||||
formConvertor.form.Items = items
|
formConvertor.form.Items = items
|
||||||
formConvertor.items = items
|
formConvertor.items = items
|
||||||
@ -161,6 +187,57 @@ func (f *formConvertor) newFileForConversion() *fileForConversion {
|
|||||||
return fileForConversion
|
return fileForConversion
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type directoryForSaving struct {
|
||||||
|
button *widget.Button
|
||||||
|
message *canvas.Text
|
||||||
|
path string
|
||||||
|
}
|
||||||
|
|
||||||
|
func (f *formConvertor) newDirectoryForSaving(directoryForSavingPath string) *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 := lang.L("choose")
|
||||||
|
|
||||||
|
locationURI, err := utils.PathToListableURI(directoryForSavingPath)
|
||||||
|
if err == nil {
|
||||||
|
directoryForSaving.path = locationURI.Path()
|
||||||
|
directoryForSaving.message.Text = locationURI.Path()
|
||||||
|
utils.SetStringSuccessStyle(directoryForSaving.message)
|
||||||
|
}
|
||||||
|
|
||||||
|
directoryForSaving.button = widget.NewButton(buttonTitle, func() {
|
||||||
|
f.window.NewFolderOpen(func(r fyne.ListableURI, err error) {
|
||||||
|
if err != nil {
|
||||||
|
directoryForSaving.message.Text = err.Error()
|
||||||
|
utils.SetStringErrorStyle(directoryForSaving.message)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
if r == nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
directoryForSaving.path = r.Path()
|
||||||
|
|
||||||
|
directoryForSaving.message.Text = r.Path()
|
||||||
|
utils.SetStringSuccessStyle(directoryForSaving.message)
|
||||||
|
locationURI, err = storage.ListerForURI(r)
|
||||||
|
|
||||||
|
if err == nil {
|
||||||
|
f.directoryForSaving(locationURI.Path())
|
||||||
|
}
|
||||||
|
|
||||||
|
}, locationURI)
|
||||||
|
})
|
||||||
|
|
||||||
|
return directoryForSaving
|
||||||
|
}
|
||||||
|
|
||||||
func (c *fileForConversion) addChangeCallback(callback func(err error)) {
|
func (c *fileForConversion) addChangeCallback(callback func(err error)) {
|
||||||
c.changeCallbacks[len(c.changeCallbacks)] = callback
|
c.changeCallbacks[len(c.changeCallbacks)] = callback
|
||||||
}
|
}
|
||||||
|
19
internal/utils/path.go
Normal file
19
internal/utils/path.go
Normal file
@ -0,0 +1,19 @@
|
|||||||
|
package utils
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fyne.io/fyne/v2"
|
||||||
|
"fyne.io/fyne/v2/storage"
|
||||||
|
)
|
||||||
|
|
||||||
|
func PathToListableURI(path string) (fyne.ListableURI, error) {
|
||||||
|
if len(path) > 0 {
|
||||||
|
path = "file://" + path
|
||||||
|
}
|
||||||
|
|
||||||
|
uri, err := storage.ParseURI(path)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
return storage.ListerForURI(uri)
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user