Skip to content

Commit 7df06b8

Browse files
committed
refactor: Consistently name callbacks everywhere
Signed-off-by: Felicitas Pojtinger <[email protected]>
1 parent 230c321 commit 7df06b8

File tree

8 files changed

+107
-109
lines changed

8 files changed

+107
-109
lines changed

internal/components/controls.go

Lines changed: 56 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -389,45 +389,45 @@ func OpenControlsWindow(
389389
watchingWithTitleLabel.SetText(fmt.Sprintf(L("You're currently watching with %v other people."), *connectedPeers))
390390
}
391391

392-
copyStreamCodeCallback := func(gtk.Button) {
392+
onCopyStreamCode := func(gtk.Button) {
393393
window.GetClipboard().SetText(streamCodeInput.GetText())
394394
}
395-
copyStreamCodeButton.ConnectClicked(&copyStreamCodeCallback)
395+
copyStreamCodeButton.ConnectClicked(&onCopyStreamCode)
396396

397-
stopButtonCallback := func(gtk.Button) {
397+
onStopButton := func(gtk.Button) {
398398
window.Close()
399399

400400
mainWindow := NewMainWindow(ctx, app, manager, apiAddr, apiUsername, apiPassword, settings, gateway, cancel, tmpDir)
401401

402402
app.AddWindow(&mainWindow.ApplicationWindow.Window)
403403
mainWindow.SetVisible(true)
404404
}
405-
stopButton.ConnectClicked(&stopButtonCallback)
405+
stopButton.ConnectClicked(&onStopButton)
406406

407-
mediaInfoButtonCallback := func(gtk.Button) {
407+
onMediaInfoButton := func(gtk.Button) {
408408
descriptionWindow.SetVisible(true)
409409
}
410-
mediaInfoButton.ConnectClicked(&mediaInfoButtonCallback)
410+
mediaInfoButton.ConnectClicked(&onMediaInfoButton)
411411

412412
ctrl := gtk.NewEventControllerKey()
413413
descriptionWindow.AddController(&ctrl.EventController)
414414
descriptionWindow.SetTransientFor(&window.Window)
415415

416-
descCloseRequestCallback := func(gtk.Window) bool {
416+
onDescCloseRequest := func(gtk.Window) bool {
417417
descriptionWindow.Close()
418418
descriptionWindow.SetVisible(false)
419419

420420
return true
421421
}
422-
descriptionWindow.ConnectCloseRequest(&descCloseRequestCallback)
422+
descriptionWindow.ConnectCloseRequest(&onDescCloseRequest)
423423

424-
descKeyReleasedCallback := func(ctrl gtk.EventControllerKey, keyval, keycode uint, state gdk.ModifierType) {
424+
onDescKeyReleased := func(ctrl gtk.EventControllerKey, keyval, keycode uint, state gdk.ModifierType) {
425425
if keycode == keycodeEscape {
426426
descriptionWindow.Close()
427427
descriptionWindow.SetVisible(false)
428428
}
429429
}
430-
ctrl.ConnectKeyReleased(&descKeyReleasedCallback)
430+
ctrl.ConnectKeyReleased(&onDescKeyReleased)
431431

432432
descriptionWindow.Text().SetWrapMode(gtk.WrapWordValue)
433433
if !utf8.Valid([]byte(torrentReadme)) || strings.TrimSpace(torrentReadme) == "" {
@@ -490,15 +490,15 @@ func OpenControlsWindow(
490490
}
491491
}()
492492

493-
prepCloseRequestCallback := func(gtk.Window) bool {
493+
onPrepCloseRequest := func(gtk.Window) bool {
494494
preparingWindow.Close()
495495
preparingWindow.SetVisible(false)
496496

497497
return true
498498
}
499-
preparingWindow.ConnectCloseRequest(&prepCloseRequestCallback)
499+
preparingWindow.ConnectCloseRequest(&onPrepCloseRequest)
500500

501-
prepCancelCallback := func(gtk.Button) {
501+
onPrepCancel := func(gtk.Button) {
502502
adapter.Close()
503503
cancelAdapterCtx()
504504

@@ -519,7 +519,7 @@ func OpenControlsWindow(
519519
app.AddWindow(&mainWindow.ApplicationWindow.Window)
520520
mainWindow.SetVisible(true)
521521
}
522-
preparingCancelButton.ConnectClicked(&prepCancelCallback)
522+
preparingCancelButton.ConnectClicked(&onPrepCancel)
523523

524524
usernameAndPassword := base64.StdEncoding.EncodeToString([]byte(fmt.Sprintf("%v:%v", apiUsername, apiPassword)))
525525

@@ -582,7 +582,7 @@ func OpenControlsWindow(
582582
window.Close()
583583
}()
584584

585-
showCallback := func(gtk.Widget) {
585+
onShow := func(gtk.Widget) {
586586
preparingWindow.SetVisible(true)
587587

588588
go func() {
@@ -595,7 +595,7 @@ func OpenControlsWindow(
595595
}
596596
}()
597597

598-
closeRequestCallback := func(gtk.Window) bool {
598+
onCloseRequest := func(gtk.Window) bool {
599599
adapter.Close()
600600
cancelAdapterCtx()
601601

@@ -621,7 +621,7 @@ func OpenControlsWindow(
621621

622622
return true
623623
}
624-
window.ConnectCloseRequest(&closeRequestCallback)
624+
window.ConnectCloseRequest(&onCloseRequest)
625625

626626
go func() {
627627
<-ready
@@ -1072,7 +1072,7 @@ func OpenControlsWindow(
10721072
p := file.priority
10731073
sid := file.id
10741074
j := i
1075-
subtitleActivateCallback := func(gtk.CheckButton) {
1075+
onSubtitleActivate := func(gtk.CheckButton) {
10761076
defer func() {
10771077
if len(subtitleActivators) <= 1 {
10781078
activator.SetActive(true)
@@ -1203,7 +1203,7 @@ func OpenControlsWindow(
12031203
}
12041204
}()
12051205
}
1206-
activator.ConnectActivate(&subtitleActivateCallback)
1206+
activator.ConnectActivate(&onSubtitleActivate)
12071207

12081208
if i == 0 {
12091209
row.SetTitle(file.name)
@@ -1254,7 +1254,7 @@ func OpenControlsWindow(
12541254

12551255
a := audiotrack
12561256
j := i
1257-
audiotrackActivateCallback := func(gtk.CheckButton) {
1257+
onAudiotrackActivate := func(gtk.CheckButton) {
12581258
defer func() {
12591259
if len(audiotrackActivators) <= 1 {
12601260
activator.SetActive(true)
@@ -1304,7 +1304,7 @@ func OpenControlsWindow(
13041304
return
13051305
}
13061306
}
1307-
activator.ConnectActivate(&audiotrackActivateCallback)
1307+
activator.ConnectActivate(&onAudiotrackActivate)
13081308

13091309
if j == 0 {
13101310
row.SetSubtitle(L("Disable audio"))
@@ -1331,24 +1331,24 @@ func OpenControlsWindow(
13311331
}
13321332

13331333
ctrl := gtk.NewEventControllerMotion()
1334-
enterCallback := func(gtk.EventControllerMotion, float64, float64) {
1334+
onEnter := func(gtk.EventControllerMotion, float64, float64) {
13351335
seekerIsUnderPointer = true
13361336
}
1337-
ctrl.ConnectEnter(&enterCallback)
1338-
leaveCallback := func(gtk.EventControllerMotion) {
1337+
ctrl.ConnectEnter(&onEnter)
1338+
onLeave := func(gtk.EventControllerMotion) {
13391339
seekerIsUnderPointer = false
13401340
}
1341-
ctrl.ConnectLeave(&leaveCallback)
1341+
ctrl.ConnectLeave(&onLeave)
13421342
seeker.AddController(&ctrl.EventController)
13431343

1344-
changeValueCallback := func(r gtk.Range, scroll gtk.ScrollType, value float64) bool {
1344+
onChangeValue := func(r gtk.Range, scroll gtk.ScrollType, value float64) bool {
13451345
seekToPosition(value)
13461346

13471347
positions.Broadcast(value)
13481348

13491349
return true
13501350
}
1351-
seeker.ConnectChangeValue(&changeValueCallback)
1351+
seeker.ConnectChangeValue(&onChangeValue)
13521352

13531353
preparingClosed := false
13541354
done := make(chan struct{})
@@ -1472,16 +1472,16 @@ func OpenControlsWindow(
14721472
}
14731473
}()
14741474

1475-
volumeMuteClickedCallback := func(gtk.Button) {
1475+
onVolumeMuteClicked := func(gtk.Button) {
14761476
if volumeScale.GetValue() <= 0 {
14771477
volumeScale.SetValue(1)
14781478
} else {
14791479
volumeScale.SetValue(0)
14801480
}
14811481
}
1482-
volumeMuteButton.ConnectClicked(&volumeMuteClickedCallback)
1482+
volumeMuteButton.ConnectClicked(&onVolumeMuteClicked)
14831483

1484-
volumeValueChangedCallback := func(gtk.Range) {
1484+
onVolumeValueChanged := func(gtk.Range) {
14851485
value := volumeScale.GetValue()
14861486

14871487
if value <= 0 {
@@ -1514,17 +1514,17 @@ func OpenControlsWindow(
15141514
OpenErrorDialog(ctx, &window, err)
15151515
}
15161516
}
1517-
volumeScale.ConnectValueChanged(&volumeValueChangedCallback)
1517+
volumeScale.ConnectValueChanged(&onVolumeValueChanged)
15181518

1519-
subtitleClickedCallback := func(gtk.Button) {
1519+
onSubtitleClicked := func(gtk.Button) {
15201520
subtitlesDialog.Present()
15211521
}
1522-
subtitleButton.ConnectClicked(&subtitleClickedCallback)
1522+
subtitleButton.ConnectClicked(&onSubtitleClicked)
15231523

1524-
audiotracksClickedCallback := func(gtk.Button) {
1524+
onAudiotracksClicked := func(gtk.Button) {
15251525
audiotracksDialog.Present()
15261526
}
1527-
audiotracksButton.ConnectClicked(&audiotracksClickedCallback)
1527+
audiotracksButton.ConnectClicked(&onAudiotracksClicked)
15281528

15291529
for _, d := range []adw.Window{subtitlesDialog, audiotracksDialog} {
15301530
dialog := d
@@ -1533,16 +1533,16 @@ func OpenControlsWindow(
15331533
dialog.AddController(&escCtrl.EventController)
15341534
dialog.SetTransientFor(&window.Window)
15351535

1536-
escKeyReleasedCallback := func(ctrl gtk.EventControllerKey, keyval, keycode uint, state gdk.ModifierType) {
1536+
onEscKeyReleased := func(ctrl gtk.EventControllerKey, keyval, keycode uint, state gdk.ModifierType) {
15371537
if keycode == keycodeEscape {
15381538
dialog.Close()
15391539
dialog.SetVisible(false)
15401540
}
15411541
}
1542-
escCtrl.ConnectKeyReleased(&escKeyReleasedCallback)
1542+
escCtrl.ConnectKeyReleased(&onEscKeyReleased)
15431543
}
15441544

1545-
subtitlesCancelClickedCallback := func(gtk.Button) {
1545+
onSubtitlesCancelClicked := func(gtk.Button) {
15461546
log.Info().
15471547
Msg("Disabling subtitles")
15481548

@@ -1561,35 +1561,35 @@ func OpenControlsWindow(
15611561

15621562
subtitlesDialog.Close()
15631563
}
1564-
subtitlesCancelButton.ConnectClicked(&subtitlesCancelClickedCallback)
1564+
subtitlesCancelButton.ConnectClicked(&onSubtitlesCancelClicked)
15651565

1566-
subtitlesOKClickedCallback := func(gtk.Button) {
1566+
onSubtitlesOKClicked := func(gtk.Button) {
15671567
subtitlesDialog.Close()
15681568
subtitlesDialog.SetVisible(false)
15691569
}
1570-
subtitlesOKButton.ConnectClicked(&subtitlesOKClickedCallback)
1570+
subtitlesOKButton.ConnectClicked(&onSubtitlesOKClicked)
15711571

1572-
audiotracksCancelClickedCallback := func(gtk.Button) {
1572+
onAudiotracksCancelClicked := func(gtk.Button) {
15731573
audiotracksDialog.Close()
15741574
subtitlesDialog.SetVisible(false)
15751575
}
1576-
audiotracksCancelButton.ConnectClicked(&audiotracksCancelClickedCallback)
1576+
audiotracksCancelButton.ConnectClicked(&onAudiotracksCancelClicked)
15771577

1578-
audiotracksOKClickedCallback := func(gtk.Button) {
1578+
onAudiotracksOKClicked := func(gtk.Button) {
15791579
audiotracksDialog.Close()
15801580
subtitlesDialog.SetVisible(false)
15811581
}
1582-
audiotracksOKButton.ConnectClicked(&audiotracksOKClickedCallback)
1582+
audiotracksOKButton.ConnectClicked(&onAudiotracksOKClicked)
15831583

1584-
addSubtitlesFromFileClickedCallback := func(gtk.Button) {
1584+
onAddSubtitlesFromFileClicked := func(gtk.Button) {
15851585
filePicker := gtk.NewFileChooserNative(
15861586
"Select storage location",
15871587
&window.Window,
15881588
gtk.FileChooserActionOpenValue,
15891589
"",
15901590
"")
15911591
filePicker.SetModal(true)
1592-
filePickerResponseCallback := func(dialog gtk.NativeDialog, responseId int) {
1592+
onFilePickerResponse := func(dialog gtk.NativeDialog, responseId int) {
15931593
if responseId == int(gtk.ResponseAcceptValue) {
15941594
log.Info().
15951595
Str("path", filePicker.GetFile().GetPath()).
@@ -1618,7 +1618,7 @@ func OpenControlsWindow(
16181618
subtitleActivators = append(subtitleActivators, *activator)
16191619

16201620
activator.SetActive(true)
1621-
fileSubtitleActivateCallback := func(gtk.CheckButton) {
1621+
onFileSubtitleActivate := func(gtk.CheckButton) {
16221622
m := filePicker.GetFile().GetPath()
16231623
subtitlesFile, err := os.Open(m)
16241624
if err != nil {
@@ -1634,7 +1634,7 @@ func OpenControlsWindow(
16341634
return
16351635
}
16361636
}
1637-
activator.ConnectActivate(&fileSubtitleActivateCallback)
1637+
activator.ConnectActivate(&onFileSubtitleActivate)
16381638

16391639
row.SetTitle(filePicker.GetFile().GetBasename())
16401640
row.SetSubtitle(L("Manually added"))
@@ -1649,13 +1649,13 @@ func OpenControlsWindow(
16491649

16501650
filePicker.Destroy()
16511651
}
1652-
filePicker.ConnectResponse(&filePickerResponseCallback)
1652+
filePicker.ConnectResponse(&onFilePickerResponse)
16531653

16541654
filePicker.Show()
16551655
}
1656-
addSubtitlesFromFileButton.ConnectClicked(&addSubtitlesFromFileClickedCallback)
1656+
addSubtitlesFromFileButton.ConnectClicked(&onAddSubtitlesFromFileClicked)
16571657

1658-
fullscreenClickedCallback := func(gtk.Button) {
1658+
onFullscreenClicked := func(gtk.Button) {
16591659
if fullscreenButton.GetActive() {
16601660
if err := mpvClient.ExecuteMPVRequest(ipcFile, func(encoder *json.Encoder, decoder *json.Decoder) error {
16611661
log.Info().Msg("Enabling fullscreen")
@@ -1690,9 +1690,9 @@ func OpenControlsWindow(
16901690
return
16911691
}
16921692
}
1693-
fullscreenButton.ConnectClicked(&fullscreenClickedCallback)
1693+
fullscreenButton.ConnectClicked(&onFullscreenClicked)
16941694

1695-
playClickedCallback := func(gtk.Button) {
1695+
onPlayClicked := func(gtk.Button) {
16961696
if !headerbarSpinner.GetSpinning() {
16971697
if playButton.GetIconName() == playIcon {
16981698
pauses.Broadcast(false)
@@ -1707,7 +1707,7 @@ func OpenControlsWindow(
17071707
pausePlayback()
17081708
}
17091709
}
1710-
playButton.ConnectClicked(&playClickedCallback)
1710+
playButton.ConnectClicked(&onPlayClicked)
17111711

17121712
go func() {
17131713
if err := command.Wait(); err != nil && err.Error() != errKilled.Error() {
@@ -1724,7 +1724,7 @@ func OpenControlsWindow(
17241724
playButton.GrabFocus()
17251725
}()
17261726
}
1727-
window.ConnectShow(&showCallback)
1727+
window.ConnectShow(&onShow)
17281728

17291729
window.SetVisible(true)
17301730

internal/components/description_window.go

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -100,28 +100,28 @@ func init() {
100100
ctrl := gtk.NewEventControllerKey()
101101
parent.AddController(&ctrl.EventController)
102102

103-
closeRequestCallback := func(gtk.Window) bool {
103+
onCloseRequest := func(gtk.Window) bool {
104104
parent.Close()
105105
parent.SetVisible(false)
106106
return true
107107
}
108-
parent.ConnectCloseRequest(&closeRequestCallback)
108+
parent.ConnectCloseRequest(&onCloseRequest)
109109

110-
keyReleasedCallback := func(ctrl gtk.EventControllerKey, keyval, keycode uint, state gdk.ModifierType) {
110+
onKeyReleased := func(ctrl gtk.EventControllerKey, keyval, keycode uint, state gdk.ModifierType) {
111111
if keycode == keycodeEscape {
112112
parent.Close()
113113
parent.SetVisible(false)
114114
}
115115
}
116-
ctrl.ConnectKeyReleased(&keyReleasedCallback)
116+
ctrl.ConnectKeyReleased(&onKeyReleased)
117117

118118
var pinner runtime.Pinner
119119
pinner.Pin(w)
120120

121-
var cleanupCallback glib.DestroyNotify = func(data uintptr) {
121+
onCleanup := glib.DestroyNotify(func(data uintptr) {
122122
pinner.Unpin()
123-
}
124-
o.SetDataFull(dataKeyGoInstance, uintptr(unsafe.Pointer(w)), &cleanupCallback)
123+
})
124+
o.SetDataFull(dataKeyGoInstance, uintptr(unsafe.Pointer(w)), &onCleanup)
125125
})
126126
}
127127

0 commit comments

Comments
 (0)