Версия 0.3.0 #3

Merged
kor-elf merged 13 commits from develop into main 2024-02-04 20:50:55 +06:00
14 changed files with 240 additions and 46 deletions
Showing only changes of commit 6358d5d8cc - Show all commits

View File

@ -17,6 +17,9 @@ type ViewContract interface {
Main(
runConvert func(setting HandleConvertSetting, progressbar *widget.ProgressBar) error,
)
SelectFFPath(
func(ffmpegPath string, ffprobePath string) error,
)
}
type View struct {

View File

@ -1,8 +1,7 @@
package setting
package convertor
import (
"ffmpegGui/helper"
"ffmpegGui/localizer"
"fyne.io/fyne/v2"
"fyne.io/fyne/v2/canvas"
"fyne.io/fyne/v2/container"
@ -13,22 +12,6 @@ import (
"net/url"
)
type ViewContract interface {
SelectFFPath(func(ffmpegPath string, ffprobePath string) error)
}
type View struct {
w fyne.Window
localizerService localizer.ServiceContract
}
func NewView(w fyne.Window, localizerService localizer.ServiceContract) *View {
return &View{
w: w,
localizerService: localizerService,
}
}
func (v View) SelectFFPath(save func(ffmpegPath string, ffprobePath string) error) {
errorMessage := canvas.NewText("", color.RGBA{255, 0, 0, 255})
errorMessage.TextSize = 16
@ -124,13 +107,3 @@ func (v View) getButtonSelectFile() (filePath *string, button *widget.Button, bu
return
}
func setStringErrorStyle(text *canvas.Text) {
text.Color = color.RGBA{255, 0, 0, 255}
text.Refresh()
}
func setStringSuccessStyle(text *canvas.Text) {
text.Color = color.RGBA{49, 127, 114, 255}
text.Refresh()
}

View File

@ -15,11 +15,13 @@ import (
"strings"
)
type ConvertorHandlerContract interface {
MainConvertor()
}
type ConvertorHandler struct {
convertorService convertor.ServiceContract
convertorView convertor.ViewContract
settingView setting.ViewContract
localizerView localizer.ViewContract
settingRepository setting.RepositoryContract
localizerService localizer.ServiceContract
}
@ -27,33 +29,23 @@ type ConvertorHandler struct {
func NewConvertorHandler(
convertorService convertor.ServiceContract,
convertorView convertor.ViewContract,
settingView setting.ViewContract,
localizerView localizer.ViewContract,
settingRepository setting.RepositoryContract,
localizerService localizer.ServiceContract,
) *ConvertorHandler {
return &ConvertorHandler{
convertorService: convertorService,
convertorView: convertorView,
settingView: settingView,
localizerView: localizerView,
settingRepository: settingRepository,
localizerService: localizerService,
}
}
func (h ConvertorHandler) LanguageSelection() {
h.localizerView.LanguageSelection(func(lang localizer.Lang) {
h.GetConvertor()
})
}
func (h ConvertorHandler) GetConvertor() {
func (h ConvertorHandler) MainConvertor() {
if h.checkingFFPathUtilities() == true {
h.convertorView.Main(h.runConvert)
return
}
h.settingView.SelectFFPath(h.saveSettingFFPath)
h.convertorView.SelectFFPath(h.saveSettingFFPath)
}
func (h ConvertorHandler) runConvert(setting convertor.HandleConvertSetting, progressbar *widget.ProgressBar) error {
@ -124,7 +116,7 @@ func (h ConvertorHandler) saveSettingFFPath(ffmpegPath string, ffprobePath strin
ffprobeEntity := setting.Setting{Code: "ffprobe", Value: ffprobePath}
_, _ = h.settingRepository.Create(ffprobeEntity)
h.GetConvertor()
h.MainConvertor()
return nil
}

37
src/handler/main.go Normal file
View File

@ -0,0 +1,37 @@
package handler
import (
"ffmpegGui/localizer"
)
type MainHandler struct {
convertorHandler ConvertorHandlerContract
menuHandler MenuHandlerContract
localizerRepository localizer.RepositoryContract
localizerService localizer.ServiceContract
}
func NewMainHandler(
convertorHandler ConvertorHandlerContract,
menuHandler MenuHandlerContract,
localizerRepository localizer.RepositoryContract,
localizerService localizer.ServiceContract,
) *MainHandler {
return &MainHandler{
convertorHandler: convertorHandler,
menuHandler: menuHandler,
localizerRepository: localizerRepository,
localizerService: localizerService,
}
}
func (h MainHandler) Start() {
language, err := h.localizerRepository.GetCode()
if err != nil {
h.menuHandler.LanguageSelection()
return
}
_ = h.localizerService.SetCurrentLanguageByCode(language)
h.convertorHandler.MainConvertor()
}

78
src/handler/menu.go Normal file
View File

@ -0,0 +1,78 @@
package handler
import (
"ffmpegGui/localizer"
"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
localizerService localizer.ServiceContract
localizerView localizer.ViewContract
localizerRepository localizer.RepositoryContract
menuItems *menuItems
}
func NewMenuHandler(
convertorHandler ConvertorHandlerContract,
localizerService localizer.ServiceContract,
localizerView localizer.ViewContract,
localizerRepository localizer.RepositoryContract,
) *MenuHandler {
return &MenuHandler{
convertorHandler: convertorHandler,
localizerService: localizerService,
localizerView: localizerView,
localizerRepository: localizerRepository,
menuItems: &menuItems{menuItem: map[string]*fyne.MenuItem{}, menu: map[string]*fyne.Menu{}},
}
}
func (h MenuHandler) GetMainMenu() *fyne.MainMenu {
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
settings := fyne.NewMenu(h.localizerService.GetMessage(&i18n.LocalizeConfig{
MessageID: "settings",
}), languageSelection, quit)
h.menuItems.menu["settings"] = settings
return fyne.NewMainMenu(settings)
}
func (h MenuHandler) LanguageSelection() {
h.localizerView.LanguageSelection(func(lang localizer.Lang) {
h.localizerRepository.Save(lang.Code)
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()
}
}

View File

@ -2,6 +2,10 @@
hash = "sha1-52b13f1b13e82d22e8c4102332db5d4ec551247b"
other = "Folder where it will be saved:"
[changeLanguage]
hash = "sha1-8b276eaf378d485c769fb3d5dcc06dfc25b0c01b"
other = "Change language"
[checkboxOverwriteOutputFilesTitle]
hash = "sha1-5860124bb781e7ef680f573fa93977e96328d4e7"
other = "Allow file to be overwritten"
@ -42,6 +46,10 @@ other = "this is not FFprobe"
hash = "sha1-83da899677cdc90e4344e3b94ee03c46b51bee4c"
other = "You haven't selected a folder to save!"
[exit]
hash = "sha1-c42457057d1ab7950cea00719cbe0b078891775f"
other = "Exit"
[fileVideoForConversionTitle]
hash = "sha1-5e727d4a2ff3f21080e51e81641595b2e668f3be"
other = "File for conversion:"
@ -70,6 +78,10 @@ other = "Save"
hash = "sha1-95581446a28d968ff1a027c623159a7eb08654cf"
other = "Specify the path to FFmpeg and FFprobe"
[settings]
hash = "sha1-7f17c7c62a7fd8d1a508481f4778688927734c2f"
other = "Settings"
[titleDownloadLink]
hash = "sha1-92df86371f6c3a06ca1e4754f113142776a32d49"
other = "You can download it from here"

View File

@ -2,6 +2,10 @@
hash = "sha1-52b13f1b13e82d22e8c4102332db5d4ec551247b"
other = "Файлды сақтауға арналған каталог:"
[changeLanguage]
hash = "sha1-8b276eaf378d485c769fb3d5dcc06dfc25b0c01b"
other = "Тілді өзгерту"
[checkboxOverwriteOutputFilesTitle]
hash = "sha1-5860124bb781e7ef680f573fa93977e96328d4e7"
other = "Файлды қайта жазуға рұқсат беріңіз"
@ -42,6 +46,10 @@ other = "бұл FFprobe емес"
hash = "sha1-83da899677cdc90e4344e3b94ee03c46b51bee4c"
other = "Сіз сақталатын қалтаны таңдамадыңыз!"
[exit]
hash = "sha1-c42457057d1ab7950cea00719cbe0b078891775f"
other = "Шығу"
[fileVideoForConversionTitle]
hash = "sha1-5e727d4a2ff3f21080e51e81641595b2e668f3be"
other = "Түрлендіруге арналған файл:"
@ -70,6 +78,10 @@ other = "Сақтау"
hash = "sha1-95581446a28d968ff1a027c623159a7eb08654cf"
other = "FFmpeg және FFprobe жолын көрсетіңіз"
[settings]
hash = "sha1-7f17c7c62a7fd8d1a508481f4778688927734c2f"
other = "Параметрлер"
[titleDownloadLink]
hash = "sha1-92df86371f6c3a06ca1e4754f113142776a32d49"
other = "Сіз оны осы жерден жүктей аласыз"

View File

@ -1,4 +1,5 @@
buttonForSelectedDirTitle = "Папка куда будет сохраняться:"
changeLanguage = "Поменять язык"
checkboxOverwriteOutputFilesTitle = "Разрешить перезаписать файл"
choose = "выбрать"
converterVideoFilesSubmitTitle = "Конвертировать"
@ -9,6 +10,7 @@ errorDatabase = "не смогли создать файл 'database' в пап
errorFFmpeg = "это не FFmpeg"
errorFFprobe = "это не FFprobe"
errorSelectedFolderSave = "Не выбрали папку для сохранения!"
exit = "Выход"
fileVideoForConversionTitle = "Файл для ковертации:"
languageSelectionFormHead = "Переключить язык"
languageSelectionHead = "Выберите язык"
@ -16,4 +18,5 @@ pathToFfmpeg = "Путь к ffmpeg:"
pathToFfprobe = "Путь к ffprobe:"
save = "Сохранить"
selectFFPathTitle = "Укажите путь к FFmpeg и к FFprobe"
settings = "Настройки"
titleDownloadLink = "Скачать можно от сюда"

View File

@ -0,0 +1,11 @@
[changeLanguage]
hash = "sha1-8b276eaf378d485c769fb3d5dcc06dfc25b0c01b"
other = "Change language"
[exit]
hash = "sha1-c42457057d1ab7950cea00719cbe0b078891775f"
other = "Exit"
[settings]
hash = "sha1-7f17c7c62a7fd8d1a508481f4778688927734c2f"
other = "Settings"

View File

@ -0,0 +1,11 @@
[changeLanguage]
hash = "sha1-8b276eaf378d485c769fb3d5dcc06dfc25b0c01b"
other = "Тілді өзгерту"
[exit]
hash = "sha1-c42457057d1ab7950cea00719cbe0b078891775f"
other = "Шығу"
[settings]
hash = "sha1-7f17c7c62a7fd8d1a508481f4778688927734c2f"
other = "Параметрлер"

View File

@ -0,0 +1,26 @@
package localizer
import (
"ffmpegGui/setting"
)
type RepositoryContract interface {
GetCode() (string, error)
Save(code string) (setting.Setting, error)
}
type Repository struct {
settingRepository setting.RepositoryContract
}
func NewRepository(settingRepository setting.RepositoryContract) *Repository {
return &Repository{settingRepository: settingRepository}
}
func (r Repository) GetCode() (string, error) {
return r.settingRepository.GetValue("language")
}
func (r Repository) Save(code string) (setting.Setting, error) {
return r.settingRepository.CreateOrUpdate("language", code)
}

View File

@ -14,6 +14,7 @@ type ServiceContract interface {
GetLanguages() []Lang
GetMessage(localizeConfig *i18n.LocalizeConfig) string
SetCurrentLanguage(lang Lang) error
SetCurrentLanguageByCode(code string) error
GetCurrentLanguage() *CurrentLanguage
}
@ -101,6 +102,16 @@ func (s Service) SetCurrentLanguage(lang Lang) error {
return nil
}
func (s Service) SetCurrentLanguageByCode(code string) error {
language, err := language.Parse(code)
if err != nil {
return err
}
title := cases.Title(language).String(display.Self.Name(language))
lang := Lang{Code: language.String(), Title: title}
return s.SetCurrentLanguage(lang)
}
func (s Service) GetCurrentLanguage() *CurrentLanguage {
return s.currentLanguage
}

View File

@ -79,12 +79,17 @@ func main() {
localizerView := localizer.NewView(w, localizerService)
convertorView := convertor.NewView(w, localizerService)
settingView := setting.NewView(w, localizerService)
convertorService := convertor.NewService(ffPathUtilities)
defer appCloseWithConvert(convertorService)
mainHandler := handler.NewConvertorHandler(convertorService, convertorView, settingView, localizerView, settingRepository, localizerService)
convertorHandler := handler.NewConvertorHandler(convertorService, convertorView, settingRepository, localizerService)
mainHandler.LanguageSelection()
localizerRepository := localizer.NewRepository(settingRepository)
mainMenu := handler.NewMenuHandler(convertorHandler, localizerService, localizerView, localizerRepository)
mainHandler := handler.NewMainHandler(convertorHandler, mainMenu, localizerRepository, localizerService)
mainHandler.Start()
w.SetMainMenu(mainMenu.GetMainMenu())
w.ShowAndRun()
}

View File

@ -1,11 +1,13 @@
package setting
import (
"errors"
"gorm.io/gorm"
)
type RepositoryContract interface {
Create(setting Setting) (Setting, error)
CreateOrUpdate(code string, value string) (Setting, error)
GetValue(code string) (value string, err error)
}
@ -33,3 +35,21 @@ func (r Repository) Create(setting Setting) (Setting, error) {
}
return setting, err
}
func (r Repository) CreateOrUpdate(code string, value string) (Setting, error) {
var setting Setting
err := r.db.Where("code = ?", code).First(&setting).Error
if err != nil {
if errors.Is(err, gorm.ErrRecordNotFound) == true {
setting = Setting{Code: code, Value: value}
return r.Create(setting)
} else {
return setting, err
}
}
err = r.db.Model(&setting).UpdateColumn("value", value).Error
if err != nil {
return setting, err
}
return setting, err
}