diff options
Diffstat (limited to 'src/gui/widgets/itemlinkhandler.cpp')
-rw-r--r-- | src/gui/widgets/itemlinkhandler.cpp | 27 |
1 files changed, 27 insertions, 0 deletions
diff --git a/src/gui/widgets/itemlinkhandler.cpp b/src/gui/widgets/itemlinkhandler.cpp index f596fc82..d9d6f506 100644 --- a/src/gui/widgets/itemlinkhandler.cpp +++ b/src/gui/widgets/itemlinkhandler.cpp @@ -33,6 +33,7 @@ #include "gui/widgets/itemlinkhandler.h" +#include "client.h" #include "resources/iteminfo.h" #include "resources/itemdb.h" #include "utils/gettext.h" @@ -42,6 +43,7 @@ ItemLinkHandler::ItemLinkHandler(Window *parent) : mParent(parent) { mItemPopup = std::make_unique<ItemPopup>(); + mItemPopup->addDeathListener(this); } ItemLinkHandler::~ItemLinkHandler() = default; @@ -55,6 +57,24 @@ static bool isUrl(const std::string &link) void ItemLinkHandler::handleLink(const std::string &link) { +#if SDL_VERSION_ATLEAST(2, 0, 14) + // Handle screenshots by constructing full file path + if (startsWith(link, "screenshot:")) + { + std::string filename = link.substr(11); // Remove "screenshot:" prefix + + // Prevent directory traversal attacks or opening malicious files + if (filename.find("..") == std::string::npos && endsWith(filename, ".png")) + { + std::string fileUrl = "file://" + Client::getScreenshotDirectory() + "/" + filename; + if (SDL_OpenURL(fileUrl.c_str()) == -1) + new OkDialog(_("Open URL Failed"), SDL_GetError(), true, mParent); + } + + return; + } +#endif + if (isUrl(link)) { mLink = link; @@ -97,3 +117,10 @@ void ItemLinkHandler::action(const gcn::ActionEvent &actionEvent) #endif } } + +void ItemLinkHandler::death(const gcn::Event &event) +{ + // If somebody else killed the PopupUp, make sure we don't also try to delete it + if (event.getSource() == mItemPopup.get()) + mItemPopup.release(); +} |