From 7aa3784a5d62848af60aabc3f82b19fb068b9d79 Mon Sep 17 00:00:00 2001 From: Andrei Karas Date: Sun, 22 Jul 2012 16:06:06 +0300 Subject: Add new chat commands. /url LINK - put http link in chat. /openurl LINK - open link in browser. --- src/gui/chatwindow.cpp | 11 ++++++++--- src/gui/widgets/itemlinkhandler.cpp | 39 +++++++++++++++++++++++-------------- 2 files changed, 32 insertions(+), 18 deletions(-) (limited to 'src/gui') diff --git a/src/gui/chatwindow.cpp b/src/gui/chatwindow.cpp index f3255af97..75ec6d09c 100644 --- a/src/gui/chatwindow.cpp +++ b/src/gui/chatwindow.cpp @@ -329,6 +329,8 @@ void ChatWindow::fillCommands() mCommands.push_back(""); mCommands.push_back(""); mCommands.push_back("/setdrop "); + mCommands.push_back("/url "); + mCommands.push_back("/open "); } void ChatWindow::loadGMCommands() @@ -1404,9 +1406,12 @@ void ChatWindow::resortChatLog(std::string line, Own own, size_t idx3 = line.find("@@", idx2); if (idx3 != std::string::npos) { - tradeChatTab->chatLog(line, own, ignoreRecord, - tryRemoveColors); - return; + if (line.find("http", idx1) != idx1 + 2) + { + tradeChatTab->chatLog(line, own, ignoreRecord, + tryRemoveColors); + return; + } } } } diff --git a/src/gui/widgets/itemlinkhandler.cpp b/src/gui/widgets/itemlinkhandler.cpp index 98d820164..c09aea04c 100644 --- a/src/gui/widgets/itemlinkhandler.cpp +++ b/src/gui/widgets/itemlinkhandler.cpp @@ -30,6 +30,8 @@ #include "gui/widgets/itemlinkhandler.h" +#include "utils/process.h" + #include "resources/itemdb.h" #include "debug.h" @@ -48,23 +50,30 @@ ItemLinkHandler::~ItemLinkHandler() void ItemLinkHandler::handleLink(const std::string &link, gcn::MouseEvent *event A_UNUSED) { - if (!mItemPopup) - return; + if (!strStartWith(link, "http://")) + { + if (!mItemPopup) + return; - int id = 0; - std::stringstream stream; - stream << link; - stream >> id; + int id = 0; + std::stringstream stream; + stream << link; + stream >> id; - if (id > 0) - { - const ItemInfo &itemInfo = ItemDB::get(id); - //+++ need add color to links? - mItemPopup->setItem(itemInfo, 1, true); + if (id > 0) + { + const ItemInfo &itemInfo = ItemDB::get(id); + //+++ need add color to links? + mItemPopup->setItem(itemInfo, 1, true); - if (mItemPopup->isVisible()) - mItemPopup->setVisible(false); - else if (viewport) - mItemPopup->position(viewport->getMouseX(), viewport->getMouseY()); + if (mItemPopup->isVisible()) + mItemPopup->setVisible(false); + else if (viewport) + mItemPopup->position(viewport->getMouseX(), viewport->getMouseY()); + } + } + else + { + openBrowser(link); } } -- cgit v1.2.3-70-g09d2