2024-01-31 21:02:12 +06:00
|
|
|
package handler
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fyne.io/fyne/v2"
|
2024-02-17 19:08:58 +06:00
|
|
|
"git.kor-elf.net/kor-elf/gui-for-ffmpeg/kernel"
|
2024-02-12 22:21:47 +06:00
|
|
|
"git.kor-elf.net/kor-elf/gui-for-ffmpeg/localizer"
|
|
|
|
"git.kor-elf.net/kor-elf/gui-for-ffmpeg/menu"
|
2024-01-31 21:02:12 +06:00
|
|
|
"github.com/nicksnyder/go-i18n/v2/i18n"
|
|
|
|
)
|
|
|
|
|
|
|
|
type MenuHandlerContract interface {
|
|
|
|
GetMainMenu() *fyne.MainMenu
|
|
|
|
LanguageSelection()
|
|
|
|
}
|
|
|
|
|
|
|
|
type MenuHandler struct {
|
2024-02-17 19:08:58 +06:00
|
|
|
app kernel.AppContract
|
2024-01-31 21:02:12 +06:00
|
|
|
convertorHandler ConvertorHandlerContract
|
2024-02-03 17:47:32 +06:00
|
|
|
menuView menu.ViewContract
|
2024-01-31 21:02:12 +06:00
|
|
|
localizerView localizer.ViewContract
|
|
|
|
localizerRepository localizer.RepositoryContract
|
2024-02-17 19:08:58 +06:00
|
|
|
localizerListener localizerListenerContract
|
2024-01-31 21:02:12 +06:00
|
|
|
}
|
|
|
|
|
|
|
|
func NewMenuHandler(
|
2024-02-17 19:08:58 +06:00
|
|
|
app kernel.AppContract,
|
2024-01-31 21:02:12 +06:00
|
|
|
convertorHandler ConvertorHandlerContract,
|
2024-02-03 17:47:32 +06:00
|
|
|
menuView menu.ViewContract,
|
2024-01-31 21:02:12 +06:00
|
|
|
localizerView localizer.ViewContract,
|
|
|
|
localizerRepository localizer.RepositoryContract,
|
2024-02-17 19:08:58 +06:00
|
|
|
localizerListener localizerListenerContract,
|
2024-01-31 21:02:12 +06:00
|
|
|
) *MenuHandler {
|
|
|
|
return &MenuHandler{
|
2024-02-17 19:08:58 +06:00
|
|
|
app: app,
|
2024-01-31 21:02:12 +06:00
|
|
|
convertorHandler: convertorHandler,
|
2024-02-03 17:47:32 +06:00
|
|
|
menuView: menuView,
|
2024-01-31 21:02:12 +06:00
|
|
|
localizerView: localizerView,
|
|
|
|
localizerRepository: localizerRepository,
|
2024-02-17 19:08:58 +06:00
|
|
|
localizerListener: localizerListener,
|
2024-01-31 21:02:12 +06:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
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-02-17 19:08:58 +06:00
|
|
|
quit := fyne.NewMenuItem(h.app.GetLocalizerService().GetMessage(&i18n.LocalizeConfig{
|
2024-01-31 21:02:12 +06:00
|
|
|
MessageID: "exit",
|
|
|
|
}), nil)
|
|
|
|
quit.IsQuit = true
|
2024-02-17 19:08:58 +06:00
|
|
|
h.localizerListener.AddMenuItem("exit", quit)
|
2024-01-31 21:02:12 +06:00
|
|
|
|
2024-02-17 19:08:58 +06:00
|
|
|
languageSelection := fyne.NewMenuItem(h.app.GetLocalizerService().GetMessage(&i18n.LocalizeConfig{
|
2024-01-31 21:02:12 +06:00
|
|
|
MessageID: "changeLanguage",
|
|
|
|
}), h.LanguageSelection)
|
2024-02-17 19:08:58 +06:00
|
|
|
h.localizerListener.AddMenuItem("changeLanguage", languageSelection)
|
2024-01-31 21:02:12 +06:00
|
|
|
|
2024-02-17 19:08:58 +06:00
|
|
|
ffPathSelection := fyne.NewMenuItem(h.app.GetLocalizerService().GetMessage(&i18n.LocalizeConfig{
|
2024-02-01 00:23:28 +06:00
|
|
|
MessageID: "changeFFPath",
|
|
|
|
}), h.convertorHandler.FfPathSelection)
|
2024-02-17 19:08:58 +06:00
|
|
|
h.localizerListener.AddMenuItem("changeFFPath", ffPathSelection)
|
2024-02-01 00:23:28 +06:00
|
|
|
|
2024-02-17 19:08:58 +06:00
|
|
|
settings := fyne.NewMenu(h.app.GetLocalizerService().GetMessage(&i18n.LocalizeConfig{
|
2024-01-31 21:02:12 +06:00
|
|
|
MessageID: "settings",
|
2024-02-01 00:23:28 +06:00
|
|
|
}), languageSelection, ffPathSelection, quit)
|
2024-02-17 19:08:58 +06:00
|
|
|
h.localizerListener.AddMenu("settings", settings)
|
2024-01-31 21:02:12 +06:00
|
|
|
|
2024-02-03 17:47:32 +06:00
|
|
|
return settings
|
|
|
|
}
|
|
|
|
|
|
|
|
func (h MenuHandler) getMenuHelp() *fyne.Menu {
|
2024-02-17 19:08:58 +06:00
|
|
|
about := fyne.NewMenuItem(h.app.GetLocalizerService().GetMessage(&i18n.LocalizeConfig{
|
2024-02-03 17:47:32 +06:00
|
|
|
MessageID: "about",
|
|
|
|
}), h.openAbout)
|
2024-02-17 19:08:58 +06:00
|
|
|
h.localizerListener.AddMenuItem("about", about)
|
2024-02-03 17:47:32 +06:00
|
|
|
|
2024-02-17 19:08:58 +06:00
|
|
|
help := fyne.NewMenu(h.app.GetLocalizerService().GetMessage(&i18n.LocalizeConfig{
|
2024-02-03 17:47:32 +06:00
|
|
|
MessageID: "help",
|
|
|
|
}), about)
|
2024-02-17 19:08:58 +06:00
|
|
|
h.localizerListener.AddMenu("help", help)
|
2024-02-03 17:47:32 +06:00
|
|
|
|
|
|
|
return help
|
|
|
|
}
|
|
|
|
|
|
|
|
func (h MenuHandler) openAbout() {
|
|
|
|
ffmpeg, err := h.convertorHandler.GetFfmpegVersion()
|
|
|
|
if err != nil {
|
2024-02-17 19:08:58 +06:00
|
|
|
ffmpeg = h.app.GetLocalizerService().GetMessage(&i18n.LocalizeConfig{
|
2024-02-03 17:47:32 +06:00
|
|
|
MessageID: "errorFFmpegVersion",
|
|
|
|
})
|
|
|
|
}
|
|
|
|
ffprobe, err := h.convertorHandler.GetFfprobeVersion()
|
|
|
|
if err != nil {
|
2024-02-17 19:08:58 +06:00
|
|
|
ffprobe = h.app.GetLocalizerService().GetMessage(&i18n.LocalizeConfig{
|
2024-02-03 17:47:32 +06:00
|
|
|
MessageID: "errorFFprobeVersion",
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
h.menuView.About(ffmpeg, ffprobe)
|
2024-01-31 21:02:12 +06:00
|
|
|
}
|
|
|
|
|
|
|
|
func (h MenuHandler) LanguageSelection() {
|
2024-02-17 19:08:58 +06:00
|
|
|
h.localizerView.LanguageSelection(func(lang kernel.Lang) {
|
2024-01-31 21:22:38 +06:00
|
|
|
_, _ = h.localizerRepository.Save(lang.Code)
|
2024-01-31 21:02:12 +06:00
|
|
|
h.convertorHandler.MainConvertor()
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2024-02-17 19:08:58 +06:00
|
|
|
type menuItems struct {
|
|
|
|
menuItem map[string]*fyne.MenuItem
|
|
|
|
menu map[string]*fyne.Menu
|
|
|
|
}
|
|
|
|
|
|
|
|
type LocalizerListener struct {
|
|
|
|
menuItems *menuItems
|
|
|
|
}
|
|
|
|
|
|
|
|
type localizerListenerContract interface {
|
|
|
|
AddMenu(messageID string, menu *fyne.Menu)
|
|
|
|
AddMenuItem(messageID string, menuItem *fyne.MenuItem)
|
|
|
|
}
|
|
|
|
|
|
|
|
func NewLocalizerListener() *LocalizerListener {
|
|
|
|
return &LocalizerListener{
|
|
|
|
&menuItems{menuItem: map[string]*fyne.MenuItem{}, menu: map[string]*fyne.Menu{}},
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func (l LocalizerListener) AddMenu(messageID string, menu *fyne.Menu) {
|
|
|
|
l.menuItems.menu[messageID] = menu
|
|
|
|
}
|
|
|
|
|
|
|
|
func (l LocalizerListener) AddMenuItem(messageID string, menuItem *fyne.MenuItem) {
|
|
|
|
l.menuItems.menuItem[messageID] = menuItem
|
|
|
|
}
|
|
|
|
|
|
|
|
func (l LocalizerListener) Change(localizerService kernel.LocalizerContract) {
|
|
|
|
for messageID, menu := range l.menuItems.menuItem {
|
|
|
|
menu.Label = localizerService.GetMessage(&i18n.LocalizeConfig{MessageID: messageID})
|
2024-01-31 21:02:12 +06:00
|
|
|
}
|
2024-02-17 19:08:58 +06:00
|
|
|
for messageID, menu := range l.menuItems.menu {
|
|
|
|
menu.Label = localizerService.GetMessage(&i18n.LocalizeConfig{MessageID: messageID})
|
2024-01-31 21:02:12 +06:00
|
|
|
menu.Refresh()
|
|
|
|
}
|
|
|
|
}
|