make fetch URL configurable, add fetch from directory
This commit is contained in:
58
gui.go
58
gui.go
@ -4,6 +4,7 @@ import (
|
|||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"log"
|
"log"
|
||||||
"os"
|
"os"
|
||||||
|
"strings"
|
||||||
|
|
||||||
"fyne.io/fyne"
|
"fyne.io/fyne"
|
||||||
"fyne.io/fyne/app"
|
"fyne.io/fyne/app"
|
||||||
@ -25,10 +26,12 @@ type GUI struct {
|
|||||||
messageList *widget.ScrollContainer
|
messageList *widget.ScrollContainer
|
||||||
contentArea *widget.ScrollContainer
|
contentArea *widget.ScrollContainer
|
||||||
|
|
||||||
pagination int
|
pagination int
|
||||||
selectedChannel string
|
selectedChannel string
|
||||||
channelNeedle int
|
channelNeedle int
|
||||||
selectedMessage int
|
selectedMessage int
|
||||||
|
selectedFetchArchive *widget.Entry
|
||||||
|
selectedFetchMethod string
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewGUI creates a new GUI
|
// NewGUI creates a new GUI
|
||||||
@ -63,7 +66,12 @@ func (client *GUI) repaint() {
|
|||||||
|
|
||||||
func (client *GUI) loadMainMenu() {
|
func (client *GUI) loadMainMenu() {
|
||||||
main := fyne.NewMenu("File",
|
main := fyne.NewMenu("File",
|
||||||
fyne.NewMenuItem("Fetch", func() {
|
fyne.NewMenuItem("Fetch from URL", func() {
|
||||||
|
client.selectedFetchMethod = "URL"
|
||||||
|
client.fetchFromArchiveServer()
|
||||||
|
}),
|
||||||
|
fyne.NewMenuItem("Fetch from directory", func() {
|
||||||
|
client.selectedFetchMethod = "directory"
|
||||||
client.fetchFromArchiveServer()
|
client.fetchFromArchiveServer()
|
||||||
}),
|
}),
|
||||||
)
|
)
|
||||||
@ -71,24 +79,50 @@ func (client *GUI) loadMainMenu() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (client *GUI) fetchFromArchiveServer() {
|
func (client *GUI) fetchFromArchiveServer() {
|
||||||
content := widget.NewLabel("Press Fetch to sync from http://localhost:8080/")
|
content := widget.NewVBox()
|
||||||
|
client.selectedFetchArchive = widget.NewEntry()
|
||||||
|
content.Append(widget.NewLabel("Press fetch to pull messages from the " + client.selectedFetchMethod + " below"))
|
||||||
|
if client.selectedFetchMethod == "URL" {
|
||||||
|
client.selectedFetchArchive.SetPlaceHolder("http://localhost:8080/")
|
||||||
|
}
|
||||||
|
if client.selectedFetchMethod == "directory" {
|
||||||
|
client.selectedFetchArchive.SetPlaceHolder("~/.syndie/archive")
|
||||||
|
}
|
||||||
dialog.NewCustomConfirm("Fetch", "Fetch", "Cancel", content, client.fetch, client.window)
|
dialog.NewCustomConfirm("Fetch", "Fetch", "Cancel", content, client.fetch, client.window)
|
||||||
|
content.Append(client.selectedFetchArchive)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (client *GUI) fetch(fetch bool) {
|
func (client *GUI) fetch(fetch bool) {
|
||||||
|
if client.selectedFetchArchive.Text == "" {
|
||||||
|
client.selectedFetchArchive.Text = client.selectedFetchArchive.PlaceHolder
|
||||||
|
}
|
||||||
|
if client.selectedFetchMethod == "URL" {
|
||||||
|
client.selectedFetchArchive.Text = "http://" + strings.TrimLeft(client.selectedFetchArchive.Text, "http://")
|
||||||
|
}
|
||||||
dir, err := ioutil.TempDir("", "syndie")
|
dir, err := ioutil.TempDir("", "syndie")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatalf("Unable to create a temporary directory: %s", err)
|
log.Fatalf("Unable to create a temporary directory: %s", err)
|
||||||
}
|
}
|
||||||
defer os.RemoveAll(dir)
|
defer os.RemoveAll(dir)
|
||||||
if fetch {
|
if fetch {
|
||||||
progress := dialog.NewProgressInfinite("Fetching", "Fetching from http://localhost:8080/", client.window)
|
progress := dialog.NewProgressInfinite("Fetching", "Fetching from "+client.selectedFetchArchive.Text, client.window)
|
||||||
f := fetcher.New("http://localhost:8080/", dir, 60, 50)
|
f := fetcher.New(client.selectedFetchArchive.Text, dir, 60, 50)
|
||||||
progress.Show()
|
progress.Show()
|
||||||
err := f.RemoteFetch()
|
if client.selectedFetchMethod == "URL" {
|
||||||
if err != nil {
|
err := f.RemoteFetch()
|
||||||
progress.Hide()
|
if err != nil {
|
||||||
dialog.NewError(err, client.window)
|
progress.Hide()
|
||||||
|
dialog.NewError(err, client.window)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if client.selectedFetchMethod == "directory" {
|
||||||
|
client.selectedFetchArchive.Text = strings.TrimRight(client.selectedFetchArchive.Text, "/") + "/"
|
||||||
|
err := f.LocalDir(client.selectedFetchArchive.Text)
|
||||||
|
log.Printf("Checking: %s", client.selectedFetchArchive.Text)
|
||||||
|
if err != nil {
|
||||||
|
progress.Hide()
|
||||||
|
dialog.NewError(err, client.window)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
client.db.reload()
|
client.db.reload()
|
||||||
progress.Hide()
|
progress.Hide()
|
||||||
|
Reference in New Issue
Block a user