summaryrefslogtreecommitdiff
path: root/vmWindow.go
blob: 75b703a82d45c0101992973fe5a22a77159bd808 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
package gui

import "log"
import "fmt"

import "github.com/andlabs/ui"
import _ "github.com/andlabs/ui/winmanifest"

import "github.com/davecgh/go-spew/spew"

import pb "git.wit.com/wit/witProtobuf"

func ShowVM() {
	name := Data.CurrentVM
	log.Println("ShowVM() START Data.CurrentVM=", Data.CurrentVM)
	VMwin := ui.NewWindow("VM " + name, 500, 300, false)
	VMwin.OnClosing(func(*ui.Window) bool {
		return true
	})
	ui.OnShouldQuit(func() bool {
		VMwin.Destroy()
		VMwin = nil
		return true
	})

	VMtab := ui.NewTab()
	VMwin.SetChild(VMtab)
	VMwin.SetMargined(true)

	createVmBox(VMtab, buttonVmClick, Data.CurrentPbVM)
//	vmBox := createVmBox(buttonVmClick)
//	VMtab.Append(Data.CurrentVM, vmBox)
//	VMtab.SetMargined(0, true)

	VMwin.Show()
}

func AddVmConfigureTab(name string, pbVM *pb.Event_VM) {
	createVmBox(Data.cloudTab, buttonVmClick, Data.CurrentPbVM)
//	vmBox := createVmBox(Data.cloudTab, buttonVmClick)
//	Data.cloudTab.Append(name, vmBox)
//	Data.cloudTab.SetMargined(0, true)
}

// makeEntryBox(box, "hostname:", "blah.foo.org") {
func makeEntryBox(hbox *ui.Box, a string, b string, edit bool) {
	// Start 'Nickname' vertical box
	vboxN := ui.NewVerticalBox()
	vboxN.SetPadded(true)
	vboxN.Append(ui.NewLabel(a), false)

	entryNick := ui.NewEntry()
	entryNick.SetText(b)
	if (edit == false) {
		entryNick.SetReadOnly(true)
	}

	vboxN.Append(entryNick, false)

	entryNick.OnChanged(func(*ui.Entry) {
		log.Println("OK. TEXT WAS CHANGED TO =", entryNick.Text())
		// Data.AccNick = entryNick.Text()
	})
	hbox.Append(vboxN, false)
	// End 'Nickname' vertical box
}

func createVmBox(tab *ui.Tab, custom func(b *ButtonMap,s string), pbVM *pb.Event_VM) {
	log.Println("createVmBox() START")
	log.Println("createVmBox() pbVM.Name", pbVM.Name)
	spew.Dump(pbVM)
	if (Data.Debug) {
		spew.Dump(pbVM)
	}
	vbox := ui.NewVerticalBox()
	vbox.SetPadded(true)

	hboxAccount := ui.NewHorizontalBox()
	hboxAccount.SetPadded(true)
	vbox.Append(hboxAccount, false)

	// Add hostname entry box
	makeEntryBox(hboxAccount, "hostname:",	pbVM.Hostname,			true)
	makeEntryBox(hboxAccount, "IPv6:",	pbVM.IPv6,			true)
	makeEntryBox(hboxAccount, "RAM:",	fmt.Sprintf("%d",pbVM.Memory),	true)
	makeEntryBox(hboxAccount, "CPU:",	fmt.Sprintf("%d",pbVM.Cpus),	true)
	makeEntryBox(hboxAccount, "Disk (GB):",	fmt.Sprintf("%d",pbVM.Disk),	true)
	makeEntryBox(hboxAccount, "OS Image:",	pbVM.BaseImage,			true)

	vbox.Append(ui.NewHorizontalSeparator(), false)

	hboxButtons := ui.NewHorizontalBox()
	hboxButtons.SetPadded(true)
	vbox.Append(hboxButtons, false)

	hboxButtons.Append(CreateButton("Power On",  "POWERON",  custom), false)
	hboxButtons.Append(CreateButton("Power Off", "POWEROFF", custom), false)
	hboxButtons.Append(CreateButton("Destroy",   "DESTROY",  custom), false)
	hboxButtons.Append(CreateButton("Console",   "XTERM",    runTestExecClick), false)
	hboxButtons.Append(CreateButton("Save",      "SAVE",     custom), false)
	hboxButtons.Append(CreateButton("Done",      "DONE",     custom), false)

	tab.Append(Data.CurrentVM, vbox)
	tab.SetMargined(0, true)
}

func buttonVmClick(b *ButtonMap, s string) {
	log.Println("gui.buttonVmClick() START")
	if (Data.MouseClick != nil) {
		log.Println("Data.ButtonClick() START")
		Data.MouseClick(nil)
	}
}