-
Notifications
You must be signed in to change notification settings - Fork 80
/
muc_room_warnings.go
105 lines (76 loc) · 2.11 KB
/
muc_room_warnings.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
package gui
import (
"sync"
"github.com/coyim/coyim/i18n"
"github.com/coyim/gotk3adapter/gtki"
)
type roomViewWarning struct {
text string
lock sync.Mutex
bar gtki.Box `gtk-widget:"warning-infobar"`
message gtki.Label `gtk-widget:"message"`
}
func newRoomViewWarning(text string) *roomViewWarning {
w := &roomViewWarning{
text: text,
}
builder := newBuilder("MUCRoomWarning")
panicOnDevError(builder.bindObjects(w))
w.message.SetText(w.text)
return w
}
type roomViewWarningsInfoBar struct {
*notificationBar
}
func (v *roomView) newRoomViewWarningsInfoBar() *roomViewWarningsInfoBar {
ib := &roomViewWarningsInfoBar{
v.u.newNotificationBar(i18n.Local("Please be aware of this room configuration"), gtki.MESSAGE_WARNING),
}
showWarningsButton, _ := g.gtk.ButtonNewWithLabel(i18n.Local("Details"))
showWarningsButton.Connect("clicked", v.showWarnings)
ib.addActionWidget(showWarningsButton, gtki.RESPONSE_NONE)
return ib
}
type roomViewWarningsOverlay struct {
warnings []*roomViewWarning
onClose func()
box gtki.Box `gtk-widget:"warningsBox"`
revealer gtki.Revealer `gtk-widget:"revealer"`
}
func (v *roomView) newRoomViewWarningsOverlay() *roomViewWarningsOverlay {
o := &roomViewWarningsOverlay{
onClose: v.closeNotificationsOverlay,
}
builder := newBuilder("MUCRoomWarningsOverlay")
panicOnDevError(builder.bindObjects(o))
builder.ConnectSignals(map[string]interface{}{
"on_close": o.close,
})
mucStyles.setRoomWarningsBoxStyle(o.box)
v.messagesBox.Add(o.revealer)
return o
}
func (o *roomViewWarningsOverlay) add(text string) {
w := newRoomViewWarning(text)
o.warnings = append(o.warnings, w)
mucStyles.setRoomWarningsMessageBoxStyle(w.bar)
o.box.PackStart(w.bar, false, false, 5)
o.box.ShowAll()
}
func (o *roomViewWarningsOverlay) show() {
o.revealer.SetRevealChild(true)
}
func (o *roomViewWarningsOverlay) hide() {
o.revealer.SetRevealChild(false)
}
func (o *roomViewWarningsOverlay) close() {
o.hide()
o.onClose()
}
func (o *roomViewWarningsOverlay) clear() {
warnings := o.warnings
for _, w := range warnings {
o.box.Remove(w.bar)
}
o.warnings = nil
}