-
Notifications
You must be signed in to change notification settings - Fork 80
/
muc_room_config_page_others.go
150 lines (116 loc) · 3.72 KB
/
muc_room_config_page_others.go
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
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
package gui
import (
"strconv"
"github.com/coyim/gotk3adapter/glibi"
"github.com/coyim/gotk3adapter/gtki"
)
type roomConfigOthersPage struct {
*roomConfigPageBase
roomMaxHistoryFetchCombo gtki.ComboBoxText `gtk-widget:"room-maxhistoryfetch"`
roomMaxHistoryFetchEntry gtki.Entry `gtk-widget:"room-maxhistoryfetch-entry"`
roomMaxOccupantsCombo gtki.ComboBoxText `gtk-widget:"room-maxoccupants"`
roomMaxOccupantsEntry gtki.Entry `gtk-widget:"room-maxoccupants-entry"`
roomEnableLoggin gtki.Switch `gtk-widget:"room-enablelogging"`
roomMaxHistoryFetch *roomConfigComboEntry
roomMaxOccupants *roomConfigComboEntry
}
func (c *mucRoomConfigComponent) newRoomConfigOthersPage() mucRoomConfigPage {
p := &roomConfigOthersPage{}
p.roomConfigPageBase = c.newConfigPage("others", "MUCRoomConfigPageOthers", p, nil)
p.roomMaxHistoryFetch = newRoomConfigCombo(p.roomMaxHistoryFetchCombo, p.roomMaxHistoryFetchEntry)
p.roomMaxOccupants = newRoomConfigCombo(p.roomMaxOccupantsCombo, p.roomMaxOccupantsEntry)
p.initDefaultValues()
return p
}
func (p *roomConfigOthersPage) initDefaultValues() {
setSwitchActive(p.roomEnableLoggin, p.form.Logged)
p.roomMaxHistoryFetch.updateOptions(p.form.MaxHistoryFetch.Options())
p.roomMaxOccupants.updateOptions(p.form.MaxOccupantsNumber.Options())
}
func (p *roomConfigOthersPage) isNotValid() bool {
return p.roomMaxHistoryFetch.isNotValid() || p.roomMaxOccupants.isNotValid()
}
func (p *roomConfigOthersPage) showValidationErrors() {
p.clearErrors()
if p.roomMaxHistoryFetch.isNotValid() {
p.roomMaxHistoryFetch.focus()
return
}
if p.roomMaxOccupants.isNotValid() {
p.roomMaxOccupants.focus()
return
}
}
func (p *roomConfigOthersPage) collectData() {
p.form.MaxHistoryFetch.UpdateValue(p.roomMaxHistoryFetch.currentValue())
p.form.MaxOccupantsNumber.UpdateValue(p.roomMaxOccupants.currentValue())
p.form.Logged = getSwitchActive(p.roomEnableLoggin)
}
const (
roomMaxHistoryFetchValueColumIndex = iota
roomMaxHistoryFetchLabelColumIndex
)
const (
roomConfigComboOptionValueIndex = iota
roomConfigComboOptionLabelIndex
)
type roomConfigComboEntry struct {
options map[string]string
model gtki.ListStore
comboBox gtki.ComboBoxText
entry gtki.Entry
}
func newRoomConfigCombo(cb gtki.ComboBoxText, e gtki.Entry) *roomConfigComboEntry {
cc := &roomConfigComboEntry{
comboBox: cb,
entry: e,
options: make(map[string]string),
}
// The following is created with two columns, one is for the "value" and the other for the "label"
cc.model, _ = g.gtk.ListStoreNew(glibi.TYPE_STRING, glibi.TYPE_STRING)
cc.comboBox.SetModel(cc.model)
cc.comboBox.SetIDColumn(roomConfigComboOptionValueIndex)
cc.comboBox.SetEntryTextColumn(roomConfigComboOptionLabelIndex)
return cc
}
func (cc *roomConfigComboEntry) updateOptions(options []string) {
cc.model.Clear()
cc.options = make(map[string]string)
for _, o := range options {
label := configOptionToFriendlyMessage(o)
iter := cc.model.Append()
cc.model.SetValue(iter, roomMaxHistoryFetchValueColumIndex, o)
cc.model.SetValue(iter, roomMaxHistoryFetchLabelColumIndex, label)
cc.options[label] = o
}
}
func (cc *roomConfigComboEntry) isNotValid() bool {
ct := getEntryText(cc.entry)
if ct != "" {
_, err := strconv.Atoi(cc.currentValue())
if err != nil {
return true
}
}
return false
}
func (cc *roomConfigComboEntry) currentValue() string {
selected := cc.comboBox.GetActiveID()
if selected != "" {
return selected
}
ok := false
entryText := getEntryText(cc.entry)
selected, ok = cc.options[entryText]
if ok {
return selected
}
_, err := strconv.Atoi(entryText)
if err != nil {
return ""
}
return entryText
}
func (cc *roomConfigComboEntry) focus() {
cc.entry.GrabFocus()
}