summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJeff Carr <[email protected]>2024-01-07 05:46:59 -0600
committerJeff Carr <[email protected]>2024-01-07 05:46:59 -0600
commit930bdc941b1181460f4c38dc708dc53d583ab5d3 (patch)
tree725fc54433bcc5a5947922bae0fee2a6b830b346
parent82b5717f48f258f6ea792cd4e895c0ba99cf1e11 (diff)
remove debugging options
Signed-off-by: Jeff Carr <[email protected]>
-rw-r--r--errorBox.go47
-rw-r--r--fix.go24
-rw-r--r--gui.go20
-rw-r--r--main.go7
-rw-r--r--smartwindow/args.go30
-rw-r--r--smartwindow/common.go24
-rw-r--r--smartwindow/new.go32
-rw-r--r--smartwindow/postReady.go59
-rw-r--r--smartwindow/preReady.go84
-rw-r--r--smartwindow/structs.go21
-rw-r--r--structs.go2
11 files changed, 328 insertions, 22 deletions
diff --git a/errorBox.go b/errorBox.go
new file mode 100644
index 0000000..ea31f6a
--- /dev/null
+++ b/errorBox.go
@@ -0,0 +1,47 @@
+/*
+ Show a box for a configuration error
+*/
+
+package main
+
+import (
+ "go.wit.com/log"
+ "go.wit.com/gui/gui"
+ "go.wit.com/gui/gadgets"
+)
+
+type errorBox struct {
+ name string // the problem name
+
+ parent *gui.Node
+ group *gui.Node
+ grid *gui.Node
+
+ l *gui.Node
+ b *gui.Node
+
+ something *gadgets.OneLiner
+}
+
+func NewErrorBox(p *gui.Node, name string) *errorBox {
+ var eb *errorBox
+ eb = new(errorBox)
+ eb.parent = p
+ // eb.group = p.NewGroup("eg")
+ // eb.grid = eb.group.NewGrid("labels", 2, 1)
+
+ eb.l = p.NewLabel("click to fix")
+ eb.b = p.NewButton("fix", func() {
+ log.Log(WARN, "should try to fix here")
+ })
+ eb.something = gadgets.NewOneLiner(eb.grid, "something")
+
+ return eb
+}
+
+func (eb *errorBox) update() bool {
+ return false
+}
+
+func (eb *errorBox) toggle() {
+}
diff --git a/fix.go b/fix.go
index 2fe22ec..dc50f65 100644
--- a/fix.go
+++ b/fix.go
@@ -4,6 +4,7 @@ package main
import (
"go.wit.com/log"
"go.wit.com/gui/cloudflare"
+ "go.wit.com/control-panels/dns/smartwindow"
)
func fix() bool {
@@ -65,13 +66,16 @@ func fixIPv6dns() bool {
// remove old DNS entries first
for aaaa, _ := range dnsAAAA {
if osAAAA[aaaa] == "dns" {
- log.Log(INFO, "DNS AAAA is not in OS", aaaa)
broken = true
+ log.Log(INFO, "DNS AAAA is not in OS", aaaa)
+ addToFixWindow("DELETE", aaaa)
+ /*
if deleteFromDNS(aaaa) {
log.Log(INFO, "Delete AAAA", aaaa, "Worked")
} else {
log.Log(INFO, "Delete AAAA", aaaa, "Failed")
}
+ */
} else {
log.Log(INFO, "DNS AAAA is in OS", aaaa)
}
@@ -84,11 +88,14 @@ func fixIPv6dns() bool {
} else {
broken = true
log.Log(INFO, "OS AAAA is not in DNS", aaaa)
+ addToFixWindow("CREATE", aaaa)
+ /*
if addToDNS(aaaa) {
log.Log(INFO, "Add AAAA", aaaa, "Worked")
} else {
log.Log(INFO, "Add AAAA", aaaa, "Failed")
}
+ */
}
}
@@ -119,3 +126,18 @@ func exists(m map[string]bool, s string) bool {
}
return false
}
+
+func addToFixWindow(t string, ip string) {
+ if me.fixWindow == nil {
+ me.fixWindow = smartwindow.New()
+ me.fixWindow.SetParent(me.myGui)
+ me.fixWindow.InitWindow()
+ me.fixWindow.Title("fix window")
+ me.fixWindow.SetDraw(drawFixWindow)
+ me.fixWindow.Make()
+ }
+}
+
+func drawFixWindow(sw *smartwindow.SmartWindow) {
+ log.Log(WARN, "drawFixWindow() START")
+}
diff --git a/gui.go b/gui.go
index 2d66f44..40a6ffe 100644
--- a/gui.go
+++ b/gui.go
@@ -149,26 +149,6 @@ func mainWindow(title string) {
if ! me.statusDNS.Ready() {return}
me.statusDNS.window.Toggle()
})
-
- gr.NewButton("linuxstatus.New()", func () {
- if (me.statusOS == nil) {
- me.statusOS = linuxstatus.New()
- }
- me.statusOS.SetParent(me.myGui)
- me.statusOS.InitWindow()
- me.statusOS.Make()
- me.statusOS.Draw2()
- })
- gr.NewButton("statusOS.Ready()", func () {
- me.statusOS.Ready()
- })
- gr.NewButton("statusOS.Draw()", func () {
- me.statusOS.Draw()
- me.statusOS.Draw2()
- })
- gr.NewButton("statusOS.Update()", func () {
- me.statusOS.Update()
- })
gr.NewButton("Linux Status", func () {
me.statusOS.Toggle()
})
diff --git a/main.go b/main.go
index a421c71..1cf0621 100644
--- a/main.go
+++ b/main.go
@@ -48,7 +48,12 @@ func main() {
me.digStatus = NewDigStatusWindow(me.myGui)
me.statusDNS = NewHostnameStatusWindow(me.myGui)
- linuxstatus.New()
+ me.statusOS = linuxstatus.New()
+ me.statusOS.SetParent(me.myGui)
+ me.statusOS.InitWindow()
+ me.statusOS.Make()
+ me.statusOS.Draw()
+ me.statusOS.Draw2()
if debugger.ArgDebug() {
log.Sleep(2)
diff --git a/smartwindow/args.go b/smartwindow/args.go
new file mode 100644
index 0000000..2481b9b
--- /dev/null
+++ b/smartwindow/args.go
@@ -0,0 +1,30 @@
+package smartwindow
+
+/*
+ this enables command line options from other packages like 'gui' and 'log'
+*/
+
+import (
+ "go.wit.com/log"
+)
+
+var NOW log.LogFlag
+var INFO log.LogFlag
+var SPEW log.LogFlag
+var WARN log.LogFlag
+
+func myreg(f *log.LogFlag, b bool, name string, desc string) {
+ f.B = b
+ f.Subsystem = "go.wit.com/gadgets/smartwindow"
+ f.Short = "smartWin"
+ f.Desc = desc
+ f.Name = name
+ f.Register()
+}
+
+func init() {
+ myreg(&NOW, true, "NOW", "temp debugging stuff")
+ myreg(&INFO, false, "INFO", "normal debugging stuff")
+ myreg(&SPEW, false, "SPEW", "spew stuff")
+ myreg(&WARN, true, "WARN", "bad things")
+}
diff --git a/smartwindow/common.go b/smartwindow/common.go
new file mode 100644
index 0000000..772a790
--- /dev/null
+++ b/smartwindow/common.go
@@ -0,0 +1,24 @@
+// This creates a 'smart window'
+// it should work even when it is hidden
+// from the gui toolkit plugins
+package smartwindow
+
+import (
+ "go.wit.com/log"
+)
+
+func (sw *SmartWindow) Ready() bool {
+ log.Log(WARN, "Ready() maybe not ready? sw =", sw)
+ if sw == nil {return false}
+ if sw == nil {return false}
+ if sw.window == nil {return false}
+ return sw.ready
+}
+
+func (sw *SmartWindow) Initialized() bool {
+ log.Log(WARN, "checking Initialized()")
+ if sw == nil {return false}
+ if sw == nil {return false}
+ if sw.parent == nil {return false}
+ return true
+}
diff --git a/smartwindow/new.go b/smartwindow/new.go
new file mode 100644
index 0000000..016d10b
--- /dev/null
+++ b/smartwindow/new.go
@@ -0,0 +1,32 @@
+package smartwindow
+
+import (
+ "go.wit.com/log"
+
+ "go.wit.com/gui/gadgets"
+)
+
+func New() *SmartWindow {
+ sw := SmartWindow {
+ hidden: true,
+ ready: false,
+ }
+
+ return &sw
+}
+
+func (sw *SmartWindow) InitWindow() {
+ if sw == nil {
+ log.Log(WARN, "not initalized yet (no parent for the window?)")
+ return
+ }
+ if sw.window != nil {
+ log.Log(WARN, "You already have a SmartWindow")
+ sw.ready = true
+ return
+ }
+
+ log.Log(WARN, "Creating the Window")
+ sw.window = gadgets.NewBasicWindow(sw.parent, sw.title)
+ sw.ready = true
+}
diff --git a/smartwindow/postReady.go b/smartwindow/postReady.go
new file mode 100644
index 0000000..bb3eab8
--- /dev/null
+++ b/smartwindow/postReady.go
@@ -0,0 +1,59 @@
+// This creates a 'smart window'
+// it should work even when it is hidden
+// from the gui toolkit plugins
+package smartwindow
+
+import (
+ "go.wit.com/log"
+ "go.wit.com/gui/gui"
+)
+
+/*
+ all these functions run after the window is Ready()
+ so they should all start with that check
+*/
+
+// reports externally if something has changed
+// since the last time it was asked about it
+func (sw *SmartWindow) Changed() bool {
+ if ! sw.Ready() {return false}
+
+ if sw.changed {
+ sw.changed = false
+ return true
+ }
+ return false
+}
+
+func (sw *SmartWindow) Show() {
+ if ! sw.Ready() {return}
+
+ log.Log(WARN, "Show() window ready =", sw.ready)
+ sw.window.Show()
+ sw.hidden = false
+}
+
+func (sw *SmartWindow) Hide() {
+ if ! sw.Ready() {return}
+
+ log.Log(WARN, "Hide() window ready =", sw.ready)
+ sw.window.Hide()
+ sw.hidden = true
+}
+
+func (sw *SmartWindow) Toggle() {
+ if ! sw.Ready() {return}
+
+ log.Log(WARN, "Toggle() window ready =", sw.ready)
+ if sw.hidden {
+ sw.Show()
+ } else {
+ sw.Hide()
+ }
+}
+
+func (sw *SmartWindow) Box() *gui.Node {
+ if ! sw.Ready() {return nil}
+
+ return sw.window.Box()
+}
diff --git a/smartwindow/preReady.go b/smartwindow/preReady.go
new file mode 100644
index 0000000..5009d54
--- /dev/null
+++ b/smartwindow/preReady.go
@@ -0,0 +1,84 @@
+// these are things you can config
+package smartwindow
+
+import (
+ "go.wit.com/log"
+ "go.wit.com/gui/gui"
+)
+
+/* for now, run these before the window is ready
+ That is, they all start with:
+
+ if ! sw.Initialized() {return}
+ if sw.Ready() {return}
+*/
+
+func (sw *SmartWindow) Title(title string) {
+ if ! sw.Initialized() {return}
+ if sw.Ready() {return}
+
+ log.Log(WARN, "Title() =", title)
+ sw.title = title
+}
+
+func (sw *SmartWindow) SetParent(p *gui.Node) {
+ if ! sw.Initialized() {return}
+ if sw.Ready() {return}
+
+ log.Log(WARN, "SetParent")
+ if sw.parent == nil {
+ log.Log(WARN, "SetParent =", p)
+ sw.parent = p
+ return
+ } else {
+ log.Log(WARN, "SetParent was already set. TODO: Move to new parent")
+ }
+}
+
+func (sw *SmartWindow) SetDraw(f func(*SmartWindow)) {
+ if ! sw.Initialized() {return}
+ if sw.Ready() {return}
+
+ sw.populate = f
+}
+
+func (sw *SmartWindow) Make() {
+ if ! sw.Initialized() {return}
+ if sw.Ready() {return}
+
+ log.Log(WARN, "Make() window ready =", sw.ready)
+ sw.window.Make()
+ if (sw.populate != nil) {
+ log.Log(WARN, "Make() trying to run Custom sw.populate() here")
+ sw.populate(sw)
+ }
+ sw.ready = true
+}
+
+func (sw *SmartWindow) Draw() {
+ if ! sw.Initialized() {return}
+ if sw.Ready() {return}
+
+ log.Log(WARN, "Draw() window ready =", sw.ready)
+ sw.window.Draw()
+ if (sw.populate != nil) {
+ log.Log(WARN, "Make() trying to run Custom sw.populate() here")
+ sw.populate(sw)
+ }
+ sw.ready = true
+}
+
+
+func (sw *SmartWindow) Vertical() {
+ if ! sw.Initialized() {return}
+ if sw.Ready() {return}
+
+ log.Log(WARN, "Draw() window ready =", sw.ready)
+ sw.window.Draw()
+ if (sw.populate != nil) {
+ log.Log(WARN, "Make() trying to run Custom sw.populate() here")
+ sw.populate(sw)
+ }
+ sw.ready = true
+}
+
diff --git a/smartwindow/structs.go b/smartwindow/structs.go
new file mode 100644
index 0000000..d70ea3c
--- /dev/null
+++ b/smartwindow/structs.go
@@ -0,0 +1,21 @@
+package smartwindow
+
+import (
+ "go.wit.com/gui/gui"
+ "go.wit.com/gui/gadgets"
+)
+
+type SmartWindow struct {
+ ready bool // track if the window is ready
+ hidden bool // track if the window is hidden from the toolkits
+ changed bool // track if something changed in the window
+
+ title string // what the user sees as the name
+ name string // the programatic name aka: "CALANDAR"
+
+ parent *gui.Node // where to place the window if you try to draw it
+ window *gadgets.BasicWindow // the underlying BasicWindow
+ box *gui.Node // the box inside the window // get this from BasicWindow() ?
+
+ populate func(*SmartWindow) // the function to generate the widgets
+}
diff --git a/structs.go b/structs.go
index e060cb7..0e2a52c 100644
--- a/structs.go
+++ b/structs.go
@@ -8,6 +8,7 @@ import (
"go.wit.com/gui/gadgets"
// "go.wit.com/gui/cloudflare"
"go.wit.com/control-panels/dns/linuxstatus"
+ "go.wit.com/control-panels/dns/smartwindow"
"github.com/miekg/dns"
)
@@ -60,6 +61,7 @@ type Host struct {
digStatusButton *gui.Node
witcom *gadgets.BasicWindow
fixButton *gui.Node
+ fixWindow *smartwindow.SmartWindow
}
type IPtype struct {