forked from coyim/coyim
-
Notifications
You must be signed in to change notification settings - Fork 0
/
global_preferences.go
196 lines (165 loc) · 5.94 KB
/
global_preferences.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
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
package gui
import (
"strings"
"github.com/twstrike/coyim/Godeps/_workspace/src/github.com/twstrike/gotk3adapter/gtki"
)
type settingsPanel struct {
b *builder
dialog gtki.Dialog
notebook gtki.Notebook
singleWindow gtki.CheckButton
renderSlashMe gtki.CheckButton
showEmptyGroups gtki.CheckButton
sendWithShiftEnter gtki.CheckButton
notificationsType gtki.ComboBox
urgentNotifications gtki.CheckButton
expireNotifications gtki.CheckButton
notificationCommand gtki.Entry
notificationTimeout gtki.SpinButton
rawLogFile gtki.Entry
notificationCommandLabel gtki.Label
notificationTimeoutLabel gtki.Label
rawLogFileLabel gtki.Label
}
func createSettingsPanel() *settingsPanel {
p := &settingsPanel{b: newBuilder("GlobalPreferences")}
p.b.getItems(
"GlobalPreferences", &p.dialog,
"notebook1", &p.notebook,
"singleWindow", &p.singleWindow,
"slashMe", &p.renderSlashMe,
"sendWithShiftEnter", &p.sendWithShiftEnter,
"notificationsType", &p.notificationsType,
"notificationUrgent", &p.urgentNotifications,
"notificationExpires", &p.expireNotifications,
"notificationCommand", &p.notificationCommand,
"notificationTimeout", &p.notificationTimeout,
"rawLogFile", &p.rawLogFile,
"notificationCommandLabel", &p.notificationCommandLabel,
"notificationTimeoutLabel", &p.notificationTimeoutLabel,
"rawLogFileLabel", &p.rawLogFileLabel,
"showEmptyGroups", &p.showEmptyGroups,
)
return p
}
var notificationsTypes = []string{
"off",
"only-presence-of-new-information",
"with-author-but-no-content",
"with-content",
}
func indexOfNotificationType(s string) int {
for ix, v := range notificationsTypes {
if s == v {
return ix
}
}
return -1
}
func valOr(v, def int) int {
if v == 0 {
return def
}
return v
}
func notifyCommand(cmd []string) string {
return strings.Join(cmd, " ")
}
func (u *gtkUI) showGlobalPreferences() {
settings := u.settings
config := u.config
panel := createSettingsPanel()
orgSingleWindow := settings.GetSingleWindow()
panel.singleWindow.SetActive(orgSingleWindow)
orgSlashMe := settings.GetSlashMe()
panel.renderSlashMe.SetActive(orgSlashMe)
orgShiftEnter := settings.GetShiftEnterForSend()
panel.sendWithShiftEnter.SetActive(orgShiftEnter)
orgShowEmptyGroups := settings.GetShowEmptyGroups()
panel.showEmptyGroups.SetActive(orgShowEmptyGroups)
orgUrgentNot := settings.GetNotificationUrgency()
panel.urgentNotifications.SetActive(orgUrgentNot)
orgExpireNot := settings.GetNotificationExpires()
panel.expireNotifications.SetActive(orgExpireNot)
orgExpireType := settings.GetNotificationStyle()
panel.notificationsType.SetActive(indexOfNotificationType(orgExpireType))
if config != nil {
panel.notificationCommand.SetText(notifyCommand(config.NotifyCommand))
panel.notificationTimeout.SetValue(float64(valOr(config.IdleSecondsBeforeNotification, 60)))
panel.rawLogFile.SetText(config.RawLogFile)
} else {
panel.notificationCommand.SetSensitive(false)
panel.notificationCommandLabel.SetSensitive(false)
panel.notificationTimeout.SetSensitive(false)
panel.notificationTimeoutLabel.SetSensitive(false)
panel.rawLogFile.SetSensitive(false)
panel.rawLogFileLabel.SetSensitive(false)
}
panel.b.ConnectSignals(map[string]interface{}{
"on_save_signal": func() {
if newSingleWindow := panel.singleWindow.GetActive(); newSingleWindow != orgSingleWindow {
settings.SetSingleWindow(newSingleWindow)
}
if newSlashMe := panel.renderSlashMe.GetActive(); newSlashMe != orgSlashMe {
settings.SetSlashMe(newSlashMe)
}
if newShiftEnter := panel.sendWithShiftEnter.GetActive(); newShiftEnter != orgShiftEnter {
settings.SetShiftEnterForSend(newShiftEnter)
}
if newShowEmptyGroups := panel.showEmptyGroups.GetActive(); newShowEmptyGroups != orgShowEmptyGroups {
settings.SetShowEmptyGroups(newShowEmptyGroups)
}
if newUrgentNot := panel.urgentNotifications.GetActive(); newUrgentNot != orgUrgentNot {
settings.SetNotificationUrgency(newUrgentNot)
}
if newExpireNot := panel.expireNotifications.GetActive(); newExpireNot != orgExpireNot {
settings.SetNotificationExpires(newExpireNot)
}
newExpireType := panel.notificationsType.GetActive()
if newExpireType >= 0 && newExpireType < len(notificationsTypes) && notificationsTypes[newExpireType] != orgExpireType {
settings.SetNotificationStyle(notificationsTypes[newExpireType])
}
if config != nil {
tx, _ := panel.notificationCommand.GetText()
if strings.TrimSpace(tx) != "" {
config.NotifyCommand = strings.Split(tx, " ")
} else {
config.NotifyCommand = nil
}
val := panel.notificationTimeout.GetValueAsInt()
if val == 60 {
val = 0
}
config.IdleSecondsBeforeNotification = val
tx, _ = panel.rawLogFile.GetText()
tx = strings.TrimSpace(tx)
config.RawLogFile = tx
u.saveConfigOnly()
}
panel.dialog.Destroy()
u.roster.redraw()
u.roster.deNotify.updateWith(settings)
},
"on_cancel_signal": func() {
panel.dialog.Destroy()
},
})
panel.dialog.SetTransientFor(u.window)
panel.dialog.ShowAll()
if notificationFeaturesSupported¬ificationUrgency == 0 {
panel.b.get("notificationUrgencyInstructions").(gtki.Widget).SetVisible(false)
panel.b.get("notificationUrgentLabel").(gtki.Widget).SetVisible(false)
panel.urgentNotifications.SetVisible(false)
}
if notificationFeaturesSupported¬ificationExpiry == 0 {
panel.b.get("notificationExpiryInstructions").(gtki.Widget).SetVisible(false)
panel.b.get("notificationExpiresLabel").(gtki.Widget).SetVisible(false)
panel.expireNotifications.SetVisible(false)
}
if notificationFeaturesSupported¬ificationStyles == 0 {
panel.b.get("notificationTypeLabel").(gtki.Widget).SetVisible(false)
panel.b.get("notificationTypeInstructions").(gtki.Widget).SetVisible(false)
panel.notificationsType.SetVisible(false)
}
panel.notebook.SetCurrentPage(0)
}