2024-01-31 21:02:12 +06:00
|
|
|
package handler
|
|
|
|
|
|
|
|
import (
|
|
|
|
"ffmpegGui/localizer"
|
2024-02-03 17:47:32 +06:00
|
|
|
"ffmpegGui/menu"
|
2024-01-31 21:02:12 +06:00
|
|
|
"fyne.io/fyne/v2"
|
|
|
|
"github.com/nicksnyder/go-i18n/v2/i18n"
|
|
|
|
)
|
|
|
|
|
|
|
|
type MenuHandlerContract interface {
|
|
|
|
GetMainMenu() *fyne.MainMenu
|
|
|
|
LanguageSelection()
|
|
|
|
}
|
|
|
|
|
|
|
|
type menuItems struct {
|
|
|
|
menuItem map[string]*fyne.MenuItem
|
|
|
|
menu map[string]*fyne.Menu
|
|
|
|
}
|
|
|
|
|
|
|
|
type MenuHandler struct {
|
|
|
|
convertorHandler ConvertorHandlerContract
|
2024-02-03 17:47:32 +06:00
|
|
|
menuView menu.ViewContract
|
2024-01-31 21:02:12 +06:00
|
|
|
localizerService localizer.ServiceContract
|
|
|
|
localizerView localizer.ViewContract
|
|
|
|
localizerRepository localizer.RepositoryContract
|
|
|
|
menuItems *menuItems
|
|
|
|
}
|
|
|
|
|
|
|
|
func NewMenuHandler(
|
|
|
|
convertorHandler ConvertorHandlerContract,
|
2024-02-03 17:47:32 +06:00
|
|
|
menuView menu.ViewContract,
|
2024-01-31 21:02:12 +06:00
|
|
|
localizerService localizer.ServiceContract,
|
|
|
|
localizerView localizer.ViewContract,
|
|
|
|
localizerRepository localizer.RepositoryContract,
|
|
|
|
) *MenuHandler {
|
|
|
|
return &MenuHandler{
|
|
|
|
convertorHandler: convertorHandler,
|
2024-02-03 17:47:32 +06:00
|
|
|
menuView: menuView,
|
2024-01-31 21:02:12 +06:00
|
|
|
localizerService: localizerService,
|
|
|
|
localizerView: localizerView,
|
|
|
|
localizerRepository: localizerRepository,
|
|
|
|
menuItems: &menuItems{menuItem: map[string]*fyne.MenuItem{}, menu: map[string]*fyne.Menu{}},
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func (h MenuHandler) GetMainMenu() *fyne.MainMenu {
|
2024-02-03 17:47:32 +06:00
|
|
|
settings := h.getMenuSettings()
|
|
|
|
help := h.getMenuHelp()
|
|
|
|
|
|
|
|
return fyne.NewMainMenu(settings, help)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (h MenuHandler) getMenuSettings() *fyne.Menu {
|
2024-01-31 21:02:12 +06:00
|
|
|
quit := fyne.NewMenuItem(h.localizerService.GetMessage(&i18n.LocalizeConfig{
|
|
|
|
MessageID: "exit",
|
|
|
|
}), nil)
|
|
|
|
quit.IsQuit = true
|
|
|
|
h.menuItems.menuItem["exit"] = quit
|
|
|
|
|
|
|
|
languageSelection := fyne.NewMenuItem(h.localizerService.GetMessage(&i18n.LocalizeConfig{
|
|
|
|
MessageID: "changeLanguage",
|
|
|
|
}), h.LanguageSelection)
|
|
|
|
h.menuItems.menuItem["changeLanguage"] = languageSelection
|
|
|
|
|
2024-02-01 00:23:28 +06:00
|
|
|
ffPathSelection := fyne.NewMenuItem(h.localizerService.GetMessage(&i18n.LocalizeConfig{
|
|
|
|
MessageID: "changeFFPath",
|
|
|
|
}), h.convertorHandler.FfPathSelection)
|
|
|
|
h.menuItems.menuItem["changeFFPath"] = ffPathSelection
|
|
|
|
|
2024-01-31 21:02:12 +06:00
|
|
|
settings := fyne.NewMenu(h.localizerService.GetMessage(&i18n.LocalizeConfig{
|
|
|
|
MessageID: "settings",
|
2024-02-01 00:23:28 +06:00
|
|
|
}), languageSelection, ffPathSelection, quit)
|
2024-01-31 21:02:12 +06:00
|
|
|
h.menuItems.menu["settings"] = settings
|
|
|
|
|
2024-02-03 17:47:32 +06:00
|
|
|
return settings
|
|
|
|
}
|
|
|
|
|
|
|
|
func (h MenuHandler) getMenuHelp() *fyne.Menu {
|
|
|
|
about := fyne.NewMenuItem(h.localizerService.GetMessage(&i18n.LocalizeConfig{
|
|
|
|
MessageID: "about",
|
|
|
|
}), h.openAbout)
|
|
|
|
h.menuItems.menuItem["about"] = about
|
|
|
|
|
|
|
|
help := fyne.NewMenu(h.localizerService.GetMessage(&i18n.LocalizeConfig{
|
|
|
|
MessageID: "help",
|
|
|
|
}), about)
|
|
|
|
h.menuItems.menu["help"] = help
|
|
|
|
|
|
|
|
return help
|
|
|
|
}
|
|
|
|
|
|
|
|
func (h MenuHandler) openAbout() {
|
|
|
|
ffmpeg, err := h.convertorHandler.GetFfmpegVersion()
|
|
|
|
if err != nil {
|
|
|
|
ffmpeg = h.localizerService.GetMessage(&i18n.LocalizeConfig{
|
|
|
|
MessageID: "errorFFmpegVersion",
|
|
|
|
})
|
|
|
|
}
|
|
|
|
ffprobe, err := h.convertorHandler.GetFfprobeVersion()
|
|
|
|
if err != nil {
|
|
|
|
ffprobe = h.localizerService.GetMessage(&i18n.LocalizeConfig{
|
|
|
|
MessageID: "errorFFprobeVersion",
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
h.menuView.About(ffmpeg, ffprobe)
|
2024-01-31 21:02:12 +06:00
|
|
|
}
|
|
|
|
|
|
|
|
func (h MenuHandler) LanguageSelection() {
|
|
|
|
h.localizerView.LanguageSelection(func(lang localizer.Lang) {
|
2024-01-31 21:22:38 +06:00
|
|
|
_, _ = h.localizerRepository.Save(lang.Code)
|
2024-01-31 21:02:12 +06:00
|
|
|
h.menuMessageReload()
|
|
|
|
h.convertorHandler.MainConvertor()
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
func (h MenuHandler) menuMessageReload() {
|
|
|
|
for messageID, menu := range h.menuItems.menuItem {
|
|
|
|
menu.Label = h.localizerService.GetMessage(&i18n.LocalizeConfig{MessageID: messageID})
|
|
|
|
}
|
|
|
|
for messageID, menu := range h.menuItems.menu {
|
|
|
|
menu.Label = h.localizerService.GetMessage(&i18n.LocalizeConfig{MessageID: messageID})
|
|
|
|
menu.Refresh()
|
|
|
|
}
|
|
|
|
}
|