121 lines
2.7 KiB
Go
121 lines
2.7 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/ProtocolPacketForger/ppf/protocol"
|
||
|
"gitea.mmo.to/ProtocolPacketForger/ppf/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 CreateMetadataProtocol() *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 SetProtocolMetadata(prot *protocol.ProtocolStructure) {
|
||
|
md := PPF.ProtocolMeta
|
||
|
setfunc := func(s string) {
|
||
|
protocolctl.UpdateMetaData(
|
||
|
prot,
|
||
|
md.NameValue.Text,
|
||
|
md.VersionValue.Text,
|
||
|
0,
|
||
|
0,
|
||
|
md.ExtendsValue.Text,
|
||
|
md.DescValue.Text,
|
||
|
)
|
||
|
fmt.Printf("%s", protocolctl.ToJson(prot))
|
||
|
}
|
||
|
md.SetChanged(setfunc)
|
||
|
}
|
||
|
|
||
|
func CreateMetadataPacket() *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
|
||
|
}
|