-
Notifications
You must be signed in to change notification settings - Fork 80
/
muc_room_config_page.go
147 lines (117 loc) · 3.9 KB
/
muc_room_config_page.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
package gui
import (
"fmt"
"github.com/coyim/coyim/i18n"
"github.com/coyim/coyim/coylog"
"github.com/coyim/coyim/session/muc"
"github.com/coyim/gotk3adapter/gtki"
log "github.com/sirupsen/logrus"
)
type mucRoomConfigPage interface {
pageView() gtki.Overlay
isNotValid() bool
showValidationErrors()
collectData()
refresh()
notifyError(string)
onConfigurationApply()
onConfigurationApplyError()
onConfigurationCancel()
onConfigurationCancelError()
}
type roomConfigPageBase struct {
u *gtkUI
form *muc.RoomConfigForm
page gtki.Overlay `gtk-widget:"room-config-page-overlay"`
content gtki.Box `gtk-widget:"room-config-page-content"`
notificationsArea gtki.Box `gtk-widget:"notifications-box"`
notifications *notificationsComponent
loadingOverlay *loadingOverlayComponent
onRefresh *callbacksSet
log coylog.Logger
}
func (c *mucRoomConfigComponent) newConfigPage(pageID, pageTemplate string, page interface{}, signals map[string]interface{}) *roomConfigPageBase {
p := &roomConfigPageBase{
u: c.u,
loadingOverlay: c.u.newLoadingOverlayComponent(),
onRefresh: newCallbacksSet(),
form: c.form,
log: c.log.WithFields(log.Fields{
"page": pageID,
"template": pageTemplate,
}),
}
builder := newBuilder("MUCRoomConfigPage")
panicOnDevError(builder.bindObjects(p))
p.notifications = c.u.newNotificationsComponent()
p.loadingOverlay = c.u.newLoadingOverlayComponent()
p.notificationsArea.Add(p.notifications.contentBox())
p.page.AddOverlay(p.loadingOverlay.getOverlay())
p.page.SetHExpand(true)
p.page.SetVExpand(true)
builder = newBuilder(pageTemplate)
panicOnDevError(builder.bindObjects(page))
builder.ConnectSignals(signals)
pc, err := builder.GetObject(fmt.Sprintf("room-config-%s-page", pageID))
if err != nil {
panic(fmt.Sprintf("developer error: the ID for \"%s\" page doesn't exists", pageID))
}
pageContent := pc.(gtki.Box)
pageContent.SetHExpand(false)
p.content.Add(pageContent)
mucStyles.setRoomConfigPageStyle(pageContent)
return p
}
// pageView implements the "mucRoomConfigPage" interface
func (p *roomConfigPageBase) pageView() gtki.Overlay {
return p.page
}
// isNotValid implements the "mucRoomConfigPage" interface
func (p *roomConfigPageBase) isNotValid() bool {
return false
}
// validate implements the "mucRoomConfigPage" interface
func (p *roomConfigPageBase) showValidationErrors() {
}
// Nothing to do, just implement the "mucRoomConfigPage" interface
func (p *roomConfigPageBase) collectData() {}
// refresh MUST be called from the UI thread
func (p *roomConfigPageBase) refresh() {
p.page.ShowAll()
p.hideLoadingOverlay()
p.clearErrors()
p.onRefresh.invokeAll()
}
// clearErrors MUST be called from the ui thread
func (p *roomConfigPageBase) clearErrors() {
p.notifications.clearErrors()
}
// notifyError MUST be called from the ui thread
func (p *roomConfigPageBase) notifyError(m string) {
p.notifications.notifyOnError(m)
}
// onConfigurationApply MUST be called from the ui thread
func (p *roomConfigPageBase) onConfigurationApply() {
p.showLoadingOverlay(i18n.Local("Saving room configuration"))
}
// onConfigurationApplyError MUST be called from the ui thread
func (p *roomConfigPageBase) onConfigurationApplyError() {
p.hideLoadingOverlay()
}
// onConfigurationCancel MUST be called from the ui thread
func (p *roomConfigPageBase) onConfigurationCancel() {
p.showLoadingOverlay(i18n.Local("Aborting room configuration"))
}
// onConfigurationCancelError MUST be called from the ui thread
func (p *roomConfigPageBase) onConfigurationCancelError() {
p.hideLoadingOverlay()
}
// showLoadingOverlay MUST be called from the ui thread
func (p *roomConfigPageBase) showLoadingOverlay(m string) {
p.loadingOverlay.setSolid()
p.loadingOverlay.showWithMessage(m)
}
// hideLoadingOverlay MUST be called from the ui thread
func (p *roomConfigPageBase) hideLoadingOverlay() {
p.loadingOverlay.hide()
}