From 9ae6062150d7df2f64a5962a7871d26b47d291b5 Mon Sep 17 00:00:00 2001 From: Thorbjørn Lindeijer Date: Tue, 12 Mar 2024 13:26:25 +0100 Subject: Added SDL version check for SDL_OpenURL Ubuntu 20.04 had SDL 2.0.10, and it is still supported. Also added error handling to the SDL_OpenURL call, just in case. --- src/gui/widgets/itemlinkhandler.cpp | 23 ++++++++++++++++++++--- src/gui/widgets/itemlinkhandler.h | 2 -- 2 files changed, 20 insertions(+), 5 deletions(-) diff --git a/src/gui/widgets/itemlinkhandler.cpp b/src/gui/widgets/itemlinkhandler.cpp index e15aa6d0..f596fc82 100644 --- a/src/gui/widgets/itemlinkhandler.cpp +++ b/src/gui/widgets/itemlinkhandler.cpp @@ -22,8 +22,13 @@ #include #include +#include + +#if SDL_VERSION_ATLEAST(2, 0, 14) #include "gui/confirmdialog.h" +#endif #include "gui/itempopup.h" +#include "gui/okdialog.h" #include "gui/viewport.h" #include "gui/widgets/itemlinkhandler.h" @@ -54,8 +59,13 @@ void ItemLinkHandler::handleLink(const std::string &link) { mLink = link; - mConfirmDialog = new ConfirmDialog(_("Open URL?"), link, mParent); - mConfirmDialog->addActionListener(this); +#if SDL_VERSION_ATLEAST(2, 0, 14) + auto confirmDialog = new ConfirmDialog(_("Open URL?"), link, mParent); + confirmDialog->addActionListener(this); +#else + new OkDialog(_("Open URL Failed"), + _("Opening of URLs requires SDL 2.0.14."), true, mParent); +#endif return; } @@ -78,5 +88,12 @@ void ItemLinkHandler::handleLink(const std::string &link) void ItemLinkHandler::action(const gcn::ActionEvent &actionEvent) { if (actionEvent.getId() == "yes") - SDL_OpenURL(mLink.c_str()); + { +#if SDL_VERSION_ATLEAST(2, 0, 14) + if (SDL_OpenURL(mLink.c_str()) == -1) + { + new OkDialog(_("Open URL Failed"), SDL_GetError(), true, mParent); + } +#endif + } } diff --git a/src/gui/widgets/itemlinkhandler.h b/src/gui/widgets/itemlinkhandler.h index 3bb0b557..28e9c11c 100644 --- a/src/gui/widgets/itemlinkhandler.h +++ b/src/gui/widgets/itemlinkhandler.h @@ -28,7 +28,6 @@ #include -class ConfirmDialog; class ItemPopup; class Window; @@ -46,7 +45,6 @@ class ItemLinkHandler : public LinkHandler, gcn::ActionListener private: std::unique_ptr mItemPopup; - ConfirmDialog *mConfirmDialog = nullptr; Window *mParent = nullptr; std::string mLink; -- cgit v1.2.3-70-g09d2