commit workspace
This commit is contained in:
5
README.md
Normal file
5
README.md
Normal file
@ -0,0 +1,5 @@
|
||||
# syndie-gui
|
||||
Major WIP, not much to see here. Expect major refactoring and breaking changes.
|
||||
|
||||
# Warning
|
||||
This is highly experimental software that you should not use in this state.
|
31
channels.go
Normal file
31
channels.go
Normal file
@ -0,0 +1,31 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"strconv"
|
||||
|
||||
"fyne.io/fyne"
|
||||
"fyne.io/fyne/canvas"
|
||||
"fyne.io/fyne/widget"
|
||||
)
|
||||
|
||||
func (client *GUI) renderChannelList() fyne.CanvasObject {
|
||||
right := widget.NewVBox()
|
||||
for _, channel := range client.db.Channels {
|
||||
row := widget.NewHBox()
|
||||
numOfMessages := strconv.Itoa(len(client.db.chanList[channel.IdentHash]))
|
||||
test := canvas.NewImageFromImage(client.db.getAvatar(channel.IdentHash))
|
||||
test.SetMinSize(fyne.NewSize(32, 32))
|
||||
test.FillMode = canvas.ImageFillContain
|
||||
row.Append(test)
|
||||
row.Append(widget.NewLabel(channel.Name + " " + shortIdent(channel.IdentHash) + " " + numOfMessages + "/" + numOfMessages))
|
||||
right.Append(row)
|
||||
}
|
||||
return right
|
||||
}
|
||||
|
||||
func shortIdent(i string) string {
|
||||
if len(i) > 6 {
|
||||
return "[" + i[0:6] + "]"
|
||||
}
|
||||
return ""
|
||||
}
|
87
database.go
Normal file
87
database.go
Normal file
@ -0,0 +1,87 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"image"
|
||||
"image/jpeg"
|
||||
"io/ioutil"
|
||||
|
||||
"github.com/boltdb/bolt"
|
||||
|
||||
"github.com/kpetku/libsyndie/syndieutil"
|
||||
"github.com/kpetku/syndie-core/data"
|
||||
)
|
||||
|
||||
type database struct {
|
||||
chanList map[string][]data.Message
|
||||
avatars map[string]*image.Image
|
||||
|
||||
Channels []data.Channel
|
||||
Messages []data.Message
|
||||
}
|
||||
|
||||
func NewDatabase() *database {
|
||||
return new(database)
|
||||
}
|
||||
|
||||
func (db *database) openDB(path string) error {
|
||||
db.chanList = make(map[string][]data.Message)
|
||||
err := data.OpenDB(path)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return data.InitDB()
|
||||
}
|
||||
|
||||
func (db *database) loadChannels() {
|
||||
data.DB.View(func(tx *bolt.Tx) error {
|
||||
b := tx.Bucket([]byte("channels"))
|
||||
b.ForEach(func(k, v []byte) error {
|
||||
c := data.Channel{}
|
||||
c.Decode(v)
|
||||
cHash, _ := syndieutil.ChanHash(c.Identity)
|
||||
c.IdentHash = cHash
|
||||
db.Channels = append(db.Channels, c)
|
||||
return nil
|
||||
})
|
||||
return nil
|
||||
})
|
||||
}
|
||||
|
||||
func (db *database) loadMessages() {
|
||||
data.DB.View(func(tx *bolt.Tx) error {
|
||||
b := tx.Bucket([]byte("messages"))
|
||||
b.ForEach(func(k, v []byte) error {
|
||||
m := data.Message{}
|
||||
m.Decode(v)
|
||||
db.Messages = append(db.Messages, m)
|
||||
db.chanList[m.TargetChannel] = append(db.chanList[m.TargetChannel], m)
|
||||
return nil
|
||||
})
|
||||
return nil
|
||||
})
|
||||
}
|
||||
|
||||
func (db *database) loadAvatars() {
|
||||
db.avatars = make(map[string]*image.Image)
|
||||
|
||||
empty, _ := ioutil.ReadFile("resources/jpeg.jpg")
|
||||
emptyAvatar, _ := jpeg.Decode(bytes.NewReader(empty))
|
||||
db.avatars["empty"] = &emptyAvatar
|
||||
|
||||
for _, channel := range db.Channels {
|
||||
if len(channel.Avatar) > 0 {
|
||||
avatar, _ := jpeg.Decode(bytes.NewReader(channel.Avatar))
|
||||
db.avatars[channel.IdentHash] = &avatar
|
||||
} else {
|
||||
db.avatars[channel.IdentHash] = &emptyAvatar
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func (db *database) getAvatar(identhash string) image.Image {
|
||||
if _, ok := db.avatars[identhash]; ok {
|
||||
return *db.avatars[identhash]
|
||||
}
|
||||
return *db.avatars["empty"]
|
||||
}
|
29
gui.go
Normal file
29
gui.go
Normal file
@ -0,0 +1,29 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"fyne.io/fyne/app"
|
||||
"fyne.io/fyne/widget"
|
||||
)
|
||||
|
||||
type GUI struct {
|
||||
db *database
|
||||
}
|
||||
|
||||
func NewGUI() *GUI {
|
||||
return new(GUI)
|
||||
}
|
||||
|
||||
func (client *GUI) Start(path string) {
|
||||
client.db = NewDatabase()
|
||||
client.db.openDB(path)
|
||||
client.db.loadChannels()
|
||||
client.db.loadMessages()
|
||||
client.db.loadAvatars()
|
||||
|
||||
a := app.New()
|
||||
|
||||
w := a.NewWindow("Syndie GUI")
|
||||
rightSideBar := widget.NewVScrollContainer(client.renderChannelList())
|
||||
w.SetContent(rightSideBar)
|
||||
w.ShowAndRun()
|
||||
}
|
BIN
resources/empty.jpg
Normal file
BIN
resources/empty.jpg
Normal file
Binary file not shown.
After Width: | Height: | Size: 107 B |
Reference in New Issue
Block a user