diff options
author | Thorbjørn Lindeijer <bjorn@lindeijer.nl> | 2024-03-12 13:26:25 +0100 |
---|---|---|
committer | Thorbjørn Lindeijer <bjorn@lindeijer.nl> | 2024-03-13 09:33:44 +0100 |
commit | 9ae6062150d7df2f64a5962a7871d26b47d291b5 (patch) | |
tree | f3d32666dcdc6cedf61d815da742a6c15c22857d /src/gui/widgets | |
parent | 306ad2effe4d0897453e61ad787e01dc47c33076 (diff) | |
download | mana-9ae6062150d7df2f64a5962a7871d26b47d291b5.tar.gz mana-9ae6062150d7df2f64a5962a7871d26b47d291b5.tar.bz2 mana-9ae6062150d7df2f64a5962a7871d26b47d291b5.tar.xz mana-9ae6062150d7df2f64a5962a7871d26b47d291b5.zip |
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.
Diffstat (limited to 'src/gui/widgets')
-rw-r--r-- | src/gui/widgets/itemlinkhandler.cpp | 23 | ||||
-rw-r--r-- | 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 <sstream> #include <string> +#include <SDL.h> + +#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 <memory> -class ConfirmDialog; class ItemPopup; class Window; @@ -46,7 +45,6 @@ class ItemLinkHandler : public LinkHandler, gcn::ActionListener private: std::unique_ptr<ItemPopup> mItemPopup; - ConfirmDialog *mConfirmDialog = nullptr; Window *mParent = nullptr; std::string mLink; |