136 lines
3.3 KiB
Go
136 lines
3.3 KiB
Go
package ui
|
|
|
|
import (
|
|
"fmt"
|
|
|
|
"fyne.io/fyne/v2"
|
|
"fyne.io/fyne/v2/container"
|
|
"fyne.io/fyne/v2/layout"
|
|
"fyne.io/fyne/v2/widget"
|
|
"gitea.mmo.to/ppForge/ppforge/packet"
|
|
"gitea.mmo.to/ppForge/ppforge/protocol"
|
|
"gitea.mmo.to/ppForge/ppforge/protocolctl"
|
|
)
|
|
|
|
type Metadata struct {
|
|
Representation *fyne.Container
|
|
}
|
|
type PacketMetadata struct {
|
|
Metadata
|
|
}
|
|
|
|
type ProtocolMetadata struct {
|
|
Metadata
|
|
NameValue *widget.Entry
|
|
VersionValue *widget.Entry
|
|
ExtendsValue *widget.Entry
|
|
TcpIpLayer *widget.Select
|
|
OsiLayer *widget.Select
|
|
DescValue *widget.Entry
|
|
}
|
|
|
|
func (pmd *ProtocolMetadata) SetChanged(setfunc func(s string)) {
|
|
pmd.NameValue.OnChanged = setfunc
|
|
pmd.ExtendsValue.OnChanged = setfunc
|
|
pmd.DescValue.OnChanged = setfunc
|
|
pmd.VersionValue.OnChanged = setfunc
|
|
pmd.TcpIpLayer.OnChanged = setfunc
|
|
pmd.OsiLayer.OnChanged = setfunc
|
|
}
|
|
|
|
func NewMetadataProtocol() *ProtocolMetadata {
|
|
md := ProtocolMetadata{}
|
|
vbox := container.NewVBox()
|
|
vbox.Add(widget.NewLabel("Protocol Metadata"))
|
|
form := container.New(layout.NewFormLayout())
|
|
form.Add(widget.NewLabel("Name:"))
|
|
md.NameValue = widget.NewEntry()
|
|
form.Add(md.NameValue)
|
|
form.Add(widget.NewLabel("Version:"))
|
|
md.VersionValue = widget.NewEntry()
|
|
form.Add(md.VersionValue)
|
|
form.Add(widget.NewLabel("Extends:"))
|
|
md.ExtendsValue = widget.NewEntry()
|
|
form.Add(md.ExtendsValue)
|
|
md.TcpIpLayer = widget.NewSelect(
|
|
[]string{
|
|
"Network Access",
|
|
"Internet",
|
|
"Transport",
|
|
"Application",
|
|
},
|
|
func(s string) {
|
|
})
|
|
form.Add(widget.NewLabel("TcpIpLayer*:"))
|
|
form.Add(md.TcpIpLayer)
|
|
md.OsiLayer = widget.NewSelect(
|
|
[]string{
|
|
"(Physical)",
|
|
"Data Link",
|
|
"Network",
|
|
"Transport",
|
|
"Session",
|
|
"Presentation",
|
|
"Application",
|
|
},
|
|
func(s string) {
|
|
|
|
})
|
|
form.Add(widget.NewLabel("OSI Layer:"))
|
|
form.Add(md.OsiLayer)
|
|
vbox.Add(form)
|
|
vbox.Add(widget.NewLabel("Description"))
|
|
multiline := widget.NewMultiLineEntry()
|
|
multiline.SetMinRowsVisible(3)
|
|
md.DescValue = multiline
|
|
vbox.Add(multiline)
|
|
md.Representation = vbox
|
|
return &md
|
|
}
|
|
|
|
func (md *ProtocolMetadata) SetProtocol(prot *protocol.ProtocolStructure) {
|
|
setfunc := func(s string) {
|
|
protocolctl.UpdateMetaData(
|
|
prot,
|
|
md.NameValue.Text,
|
|
md.VersionValue.Text,
|
|
uint(md.OsiLayer.SelectedIndex()),
|
|
uint(md.TcpIpLayer.SelectedIndex()),
|
|
md.ExtendsValue.Text,
|
|
md.DescValue.Text,
|
|
)
|
|
fmt.Printf("%s", protocolctl.ToJson(prot))
|
|
}
|
|
md.NameValue.SetText(prot.Metadata.Name)
|
|
md.VersionValue.SetText(prot.Metadata.Version)
|
|
md.DescValue.SetText(prot.Metadata.Description)
|
|
md.ExtendsValue.SetText(prot.Metadata.ExtensionTo)
|
|
md.OsiLayer.SetSelectedIndex(int(prot.Metadata.OSILayer))
|
|
md.TcpIpLayer.SetSelectedIndex(int(prot.Metadata.TCPIPLayer))
|
|
md.SetChanged(setfunc)
|
|
md.Representation.Refresh()
|
|
}
|
|
|
|
func (md *ProtocolMetadata) Unset() {
|
|
md.SetChanged(func(s string) {})
|
|
}
|
|
|
|
func (md *PacketMetadata) SetData(pack *packet.Structure) {
|
|
|
|
}
|
|
|
|
func NewMetadataPacket() *PacketMetadata {
|
|
md := PacketMetadata{}
|
|
vbox := container.NewVBox()
|
|
vbox.Add(widget.NewLabel("Packet Metadata"))
|
|
form := container.New(layout.NewFormLayout())
|
|
form.Add(widget.NewLabel("Name:"))
|
|
form.Add(widget.NewEntry())
|
|
vbox.Add(form)
|
|
vbox.Add(widget.NewLabel("Description:"))
|
|
multiline := widget.NewMultiLineEntry()
|
|
multiline.SetMinRowsVisible(3)
|
|
vbox.Add(multiline)
|
|
return &md
|
|
}
|