(group *adw.PreferencesGroup)
| 200 | } |
| 201 | |
| 202 | func populateTimerGroup(group *adw.PreferencesGroup) { |
| 203 | textEntry := adw.NewEntryRow() |
| 204 | volumeRow := adw.NewActionRow() |
| 205 | volumeSlider := gtk.NewScaleWithRange(gtk.OrientationHorizontal, 0, 100, 1) |
| 206 | customSoundSwitch := adw.NewSwitchRow() |
| 207 | |
| 208 | soundSwitch := adw.NewSwitchRow() |
| 209 | soundSwitch.SetTitle("Enable sound") |
| 210 | soundSwitch.SetSubtitle("Try clicking volume slider") |
| 211 | soundSwitch.SetActive(core.UserPrefs.EnableSound) |
| 212 | soundSwitch.Connect("notify::active", func() { |
| 213 | core.SetEnableSound(soundSwitch.Active()) |
| 214 | volumeRow.SetVisible(core.UserPrefs.EnableSound) |
| 215 | customSoundSwitch.SetVisible(core.UserPrefs.EnableSound) |
| 216 | }) |
| 217 | |
| 218 | customSoundSwitch = adw.NewSwitchRow() |
| 219 | customSoundSwitch.SetTitle("Default sound") |
| 220 | customSoundSwitch.SetVisible(core.UserPrefs.EnableSound) |
| 221 | customSoundSwitch.SetActive(core.UserPrefs.SoundFilename == "") |
| 222 | customSoundSwitch.Connect("notify::active", func() { |
| 223 | if customSoundSwitch.Active() { |
| 224 | core.SetSoundFilename("") |
| 225 | } else { |
| 226 | dialog := gtk.NewFileDialog() |
| 227 | dialog.SetModal(true) |
| 228 | dialog.SetTitle("MP3 sound") |
| 229 | |
| 230 | filter := gtk.NewFileFilter() |
| 231 | filter.AddSuffix("mp3") |
| 232 | filter.AddMIMEType("audio/mpeg") |
| 233 | |
| 234 | model := gioutil.NewListModel[*gtk.FileFilter]() |
| 235 | model.Append(filter) |
| 236 | |
| 237 | dialog.SetFilters(model) |
| 238 | dialog.SetDefaultFilter(filter) |
| 239 | dialog.Open(context.Background(), &prefsWin.Window, func(r gio.AsyncResulter) { |
| 240 | file, err := dialog.OpenFinish(r) |
| 241 | if err == nil { |
| 242 | core.SetSoundFilename(file.Path()) |
| 243 | _ = core.PlaySound() |
| 244 | } |
| 245 | }) |
| 246 | } |
| 247 | }) |
| 248 | |
| 249 | volumePreviewCtrl := gtk.NewGestureClick() |
| 250 | volumePreviewCtrl.SetPropagationPhase(gtk.PhaseCapture) |
| 251 | volumePreviewCtrl.ConnectReleased(func(_ int, _ float64, _ float64) { |
| 252 | go func() { _ = core.PlaySound() }() |
| 253 | }) |
| 254 | |
| 255 | volumeRow.SetTitle("Sound volume") |
| 256 | volumeRow.SetSubtitle(fmt.Sprintf("%v%%", int(core.Overrides.Volume*100))) |
| 257 | volumeRow.SetVisible(core.UserPrefs.EnableSound) |
| 258 | volumeRow.AddSuffix(volumeSlider) |
| 259 | volumeRow.AddController(volumePreviewCtrl) |
no test coverage detected