package main import ( "fmt" "os" "runtime" "sync" "fyne.io/fyne/v2" "fyne.io/fyne/v2/app" "fyne.io/fyne/v2/container" "fyne.io/fyne/v2/data/binding" "fyne.io/fyne/v2/dialog" "fyne.io/fyne/v2/theme" "fyne.io/fyne/v2/widget" ) var supported = []string{"jpg", "jpeg", "png", "bmp", "webp"} func main() { a := app.New() w := a.NewWindow("Photomator") a.SetIcon(resourceLogoPng) w.CenterOnScreen() w.SetIcon(resourceLogoPng) w.Resize(fyne.NewSize(600, 600)) folderEntry := widget.NewEntry() folderEntry.SetPlaceHolder("Bilderordner") folderEntry.ActionItem = widget.NewButtonWithIcon("", theme.FolderOpenIcon(), func() { selectFolder("Bilderordner", a, folderEntry, w) }) outputEntry := widget.NewEntry() outputEntry.SetPlaceHolder("Zielordner") outputEntry.ActionItem = widget.NewButtonWithIcon("", theme.FolderOpenIcon(), func() { selectFolder("Zielordner", a, outputEntry, w) }) runButton := widget.NewButtonWithIcon("Ausführen", theme.MediaPlayIcon(), func() { images, err := os.ReadDir(folderEntry.Text) if checkError(err, w) { return } outputPath := outputEntry.Text _, err = os.Stat(outputPath) if err != nil { if checkError(os.Mkdir(outputPath, 0777), w) { return } } unconverted := binding.NewStringList() progress := binding.NewFloat() d := dialog.NewCustomWithoutButtons("Konvertierung läuft...", widget.NewProgressBarWithData(progress), w) d.Show() n := runtime.NumCPU() var wg sync.WaitGroup for i := 0; i < n; i++ { wg.Add(1) go convertRange(folderEntry.Text, outputPath, images, n, i, progress, unconverted, &wg) } wg.Wait() d.Hide() if unconverted.Length() == 0 { dialog.ShowInformation("Konvertierung abgeschlossen", "Alle Bilder wurden erfolgreich konvertiert", w) } else { label := widget.NewLabel("Folgende Dateien konnten nicht konvertiert werden:") list := widget.NewList( func() int { return unconverted.Length() }, func() fyne.CanvasObject { return widget.NewLabel("template") }, func(i widget.ListItemID, o fyne.CanvasObject) { item, _ := unconverted.GetValue(i) o.(*widget.Label).SetText(item) }, ) d := dialog.NewCustom("Konvertierung abgeschlossen", "Schließen", container.NewVBox( label, container.NewWithoutLayout( list, ), ), w) list.Resize(fyne.NewSize(label.MinSize().Width, 630)) d.Resize(fyne.NewSize(d.MinSize().Width, 800)) d.Show() } }) w.SetContent(container.NewPadded(container.NewVBox( folderEntry, outputEntry, runButton, widget.NewSeparator(), ))) w.ShowAndRun() } func selectFolder(title string, a fyne.App, i *widget.Entry, w fyne.Window) { fdw := a.NewWindow(fmt.Sprintf("%s wählen", title)) fdw.CenterOnScreen() fdw.SetIcon(resourceLogoPng) fdw.Resize(fyne.NewSize(1600, 900)) fd := dialog.NewFolderOpen(func(lu fyne.ListableURI, err error) { fdw.Close() if checkError(err, w) || lu == nil { return } i.SetText(lu.Path()) }, fdw) fd.Resize(fyne.NewSize(1600, 900)) fd.SetOnClosed(func() {}) fd.SetConfirmText("Öffnen") fd.SetDismissText("Abbrechen") fdw.Show() fd.Show() } func checkError(err error, w fyne.Window) bool { if err != nil { dialog.ShowError(err, w) return true } return false }