Skip to content

Commit 0e8a24e

Browse files
committed
refactor: Port warning dialog to AdwAlertDialog
Signed-off-by: Felicitas Pojtinger <felicitas@pojtinger.com>
1 parent f042a0c commit 0e8a24e

File tree

5 files changed

+42
-35
lines changed

5 files changed

+42
-35
lines changed

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,4 @@ vendor
77
!audiotracks.ui
88
!subtitles.ui
99
!error.ui
10+
!warning.ui

internal/components/assistant.go

+23-31
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,10 @@ const (
4545
applyPreferencesActionName = "applypreferences"
4646
openDownloadsActionName = "opendownloads"
4747
copyMagnetLinkActionName = "copymagnetlink"
48+
49+
responseDownloadFlathub = "download-flathub"
50+
responseDownloadWebsite = "download-website"
51+
responseManualConfiguration = "manual-configuration"
4852
)
4953

5054
func OpenAssistantWindow(
@@ -89,10 +93,7 @@ func OpenAssistantWindow(
8993
descriptionHeaderbarSubtitle := descriptionBuilder.GetObject("headerbar-subtitle").Cast().(*gtk.Label)
9094

9195
warningBuilder := gtk.NewBuilderFromResource(resources.GResourceWarningPath)
92-
warningDialog := warningBuilder.GetObject("warning-dialog").Cast().(*gtk.MessageDialog)
93-
mpvFlathubDownloadButton := warningBuilder.GetObject("mpv-download-flathub-button").Cast().(*gtk.Button)
94-
mpvWebsiteDownloadButton := warningBuilder.GetObject("mpv-download-website-button").Cast().(*gtk.Button)
95-
mpvManualConfigurationButton := warningBuilder.GetObject("mpv-manual-configuration-button").Cast().(*gtk.Button)
96+
warningDialog := warningBuilder.GetObject("warning-dialog").Cast().(*adw.AlertDialog)
9697

9798
magnetLink := ""
9899
torrentTitle := ""
@@ -721,41 +722,32 @@ func OpenAssistantWindow(
721722
})
722723

723724
if runtime.GOOS == "linux" {
724-
mpvFlathubDownloadButton.SetVisible(true)
725-
warningDialog.SetDefaultWidget(mpvFlathubDownloadButton)
726-
} else {
727-
warningDialog.SetDefaultWidget(mpvWebsiteDownloadButton)
725+
warningDialog.SetResponseEnabled(responseDownloadFlathub, true)
726+
warningDialog.SetDefaultResponse(responseDownloadFlathub)
728727
}
729728

730-
mpvFlathubDownloadButton.ConnectClicked(func() {
731-
_ = openuri.OpenURI("", mpvFlathubURL, nil)
732-
733-
warningDialog.Close()
734-
735-
os.Exit(0)
736-
})
729+
warningDialog.ConnectResponse(func(response string) {
730+
switch response {
731+
case responseDownloadFlathub:
732+
_ = openuri.OpenURI("", mpvFlathubURL, nil)
737733

738-
mpvWebsiteDownloadButton.ConnectClicked(func() {
739-
_ = openuri.OpenURI("", mpvWebsiteURL, nil)
734+
warningDialog.Close()
740735

741-
warningDialog.Close()
736+
os.Exit(0)
742737

743-
os.Exit(0)
744-
})
738+
case responseDownloadWebsite:
739+
_ = openuri.OpenURI("", mpvWebsiteURL, nil)
745740

746-
mpvManualConfigurationButton.ConnectClicked(func() {
747-
warningDialog.Close()
741+
warningDialog.Close()
748742

749-
preferencesDialog.Present(&window.Window)
750-
mpvCommandInput.GrabFocus()
751-
})
743+
os.Exit(0)
752744

753-
warningDialog.SetTransientFor(&window.Window)
754-
warningDialog.ConnectCloseRequest(func() (ok bool) {
755-
warningDialog.Close()
756-
warningDialog.SetVisible(false)
745+
default:
746+
warningDialog.Close()
757747

758-
return ok
748+
preferencesDialog.Present(&window.Window)
749+
mpvCommandInput.GrabFocus()
750+
}
759751
})
760752

761753
app.AddWindow(&window.Window)
@@ -764,7 +756,7 @@ func OpenAssistantWindow(
764756
if oldMPVCommand := settings.String(resources.GSchemaMPVKey); strings.TrimSpace(oldMPVCommand) == "" {
765757
newMPVCommand, err := mpvClient.DiscoverMPVExecutable()
766758
if err != nil {
767-
warningDialog.SetVisible(true)
759+
warningDialog.Present(&window.Window)
768760

769761
return
770762
}

internal/resources/error.ui

-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
<requires lib="gtk" version="4.0" />
44
<object class="AdwAlertDialog" id="error-dialog">
55
<property name="heading">A Fatal Error Occured</property>
6-
<property name="body"></property>
76
<property name="default-response">save</property>
87
<property name="close-response">report</property>
98

internal/resources/resources.go

+1-3
Original file line numberDiff line numberDiff line change
@@ -38,9 +38,6 @@ var GResourceControlsPath = path.Join(gResourceAppPath, "controls.ui")
3838
//go:generate blueprint-compiler compile --output description.ui description.blp
3939
var GResourceDescriptionPath = path.Join(gResourceAppPath, "description.ui")
4040

41-
//go:generate blueprint-compiler compile --output warning.ui warning.blp
42-
var GResourceWarningPath = path.Join(gResourceAppPath, "warning.ui")
43-
4441
//go:generate blueprint-compiler compile --output menu.ui menu.blp
4542
var GResourceMenuPath = path.Join(gResourceAppPath, "menu.ui")
4643

@@ -51,6 +48,7 @@ var GResourcePreferencesPath = path.Join(gResourceAppPath, "preferences.ui")
5148
var GResourcePreparingPath = path.Join(gResourceAppPath, "preparing.ui")
5249

5350
var GResourceErrorPath = path.Join(gResourceAppPath, "error.ui")
51+
var GResourceWarningPath = path.Join(gResourceAppPath, "warning.ui")
5452
var GResourceSubtitlesPath = path.Join(gResourceAppPath, "subtitles.ui")
5553
var GResourceAudiotracksPath = path.Join(gResourceAppPath, "audiotracks.ui")
5654

internal/resources/warning.ui

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<interface>
3+
<requires lib="gtk" version="4.0" />
4+
<requires lib="adwaita" version="1.0" />
5+
<object class="AdwAlertDialog" id="warning-dialog">
6+
<property name="heading">No Media Player Could Be Found</property>
7+
<property name="body">Please install mpv or configure the existing installation to be able to play media.</property>
8+
<property name="default-response">download-website</property>
9+
<property name="close-response">manual-configuration</property>
10+
11+
<responses>
12+
<response id="download-flathub" appearance="suggested" enabled="false">Get from Flathub</response>
13+
<response id="download-website">Get from mpv.io</response>
14+
<response id="manual-configuration">Manual configuration</response>
15+
</responses>
16+
</object>
17+
</interface>

0 commit comments

Comments
 (0)