summaryrefslogtreecommitdiff
path: root/src/gui/widgets/itemlinkhandler.cpp
diff options
context:
space:
mode:
authorThorbjørn Lindeijer <bjorn@lindeijer.nl>2024-03-11 21:10:53 +0100
committerThorbjørn Lindeijer <bjorn@lindeijer.nl>2024-03-11 21:10:53 +0100
commit66599a9896e0cf69b58c0a73152aba4750d87af2 (patch)
tree034b6b4a05ea1b4fc87887f48734f630e757e6f7 /src/gui/widgets/itemlinkhandler.cpp
parent0694d89c4147882561ff44c6d0d80e7414dcb24a (diff)
downloadmana-66599a9896e0cf69b58c0a73152aba4750d87af2.tar.gz
mana-66599a9896e0cf69b58c0a73152aba4750d87af2.tar.bz2
mana-66599a9896e0cf69b58c0a73152aba4750d87af2.tar.xz
mana-66599a9896e0cf69b58c0a73152aba4750d87af2.zip
Implemented ability to open external links in news and chat
* Use ConfirmDialog to confirm the opening of the external link. * ConfirmDialog now centers on its parent window when provided. * Reset hovered link when mouse exits the BrowserBox.
Diffstat (limited to 'src/gui/widgets/itemlinkhandler.cpp')
-rw-r--r--src/gui/widgets/itemlinkhandler.cpp34
1 files changed, 28 insertions, 6 deletions
diff --git a/src/gui/widgets/itemlinkhandler.cpp b/src/gui/widgets/itemlinkhandler.cpp
index 81fa2ba7..e15aa6d0 100644
--- a/src/gui/widgets/itemlinkhandler.cpp
+++ b/src/gui/widgets/itemlinkhandler.cpp
@@ -22,6 +22,7 @@
#include <sstream>
#include <string>
+#include "gui/confirmdialog.h"
#include "gui/itempopup.h"
#include "gui/viewport.h"
@@ -29,22 +30,37 @@
#include "resources/iteminfo.h"
#include "resources/itemdb.h"
+#include "utils/gettext.h"
+#include "utils/stringutils.h"
-ItemLinkHandler::ItemLinkHandler()
+ItemLinkHandler::ItemLinkHandler(Window *parent)
+ : mParent(parent)
{
- mItemPopup = new ItemPopup;
+ mItemPopup = std::make_unique<ItemPopup>();
}
-ItemLinkHandler::~ItemLinkHandler()
+ItemLinkHandler::~ItemLinkHandler() = default;
+
+static bool isUrl(const std::string &link)
{
- delete mItemPopup;
+ return startsWith(link, "https://") ||
+ startsWith(link, "http://") ||
+ startsWith(link, "ftp://");
}
void ItemLinkHandler::handleLink(const std::string &link)
{
+ if (isUrl(link))
+ {
+ mLink = link;
+
+ mConfirmDialog = new ConfirmDialog(_("Open URL?"), link, mParent);
+ mConfirmDialog->addActionListener(this);
+ return;
+ }
+
int id = 0;
- std::stringstream stream;
- stream << link;
+ std::istringstream stream(link);
stream >> id;
if (id > 0)
@@ -58,3 +74,9 @@ void ItemLinkHandler::handleLink(const std::string &link)
mItemPopup->position(viewport->getMouseX(), viewport->getMouseY());
}
}
+
+void ItemLinkHandler::action(const gcn::ActionEvent &actionEvent)
+{
+ if (actionEvent.getId() == "yes")
+ SDL_OpenURL(mLink.c_str());
+}