summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorAndrei Karas <akaras@inbox.ru>2012-07-22 16:06:06 +0300
committerAndrei Karas <akaras@inbox.ru>2012-07-22 16:06:06 +0300
commit7aa3784a5d62848af60aabc3f82b19fb068b9d79 (patch)
tree6e1538bf378c54a99ff02fe99d7e79ea6ac504f4 /src
parent147696620522270d51d15ff3fd1e7e2431ff61ae (diff)
downloadmv-7aa3784a5d62848af60aabc3f82b19fb068b9d79.tar.gz
mv-7aa3784a5d62848af60aabc3f82b19fb068b9d79.tar.bz2
mv-7aa3784a5d62848af60aabc3f82b19fb068b9d79.tar.xz
mv-7aa3784a5d62848af60aabc3f82b19fb068b9d79.zip
Add new chat commands.
/url LINK - put http link in chat. /openurl LINK - open link in browser.
Diffstat (limited to 'src')
-rw-r--r--src/commandhandler.cpp27
-rw-r--r--src/commandhandler.h4
-rw-r--r--src/gui/chatwindow.cpp11
-rw-r--r--src/gui/widgets/itemlinkhandler.cpp39
-rw-r--r--src/utils/process.cpp2
5 files changed, 63 insertions, 20 deletions
diff --git a/src/commandhandler.cpp b/src/commandhandler.cpp
index af87adafd..8fab8e042 100644
--- a/src/commandhandler.cpp
+++ b/src/commandhandler.cpp
@@ -69,6 +69,7 @@
#endif
#include "utils/gettext.h"
+#include "utils/process.h"
#include "utils/stringutils.h"
#include "debug.h"
@@ -216,6 +217,10 @@ void CommandHandler::handleCommand(const std::string &command, ChatTab *tab)
handleDumpTests(args, tab);
else if (type == "dumpogl")
handleDumpOGL(args, tab);
+ else if (type == "url")
+ handleUrl(args, tab);
+ else if (type == "open")
+ handleOpen(args, tab);
else if (tab->handleCommand(type, args))
;
else if (type == "hack")
@@ -1212,6 +1217,28 @@ void CommandHandler::handleError(const std::string &args A_UNUSED,
logger->log("test %d", *ptr);
}
+void CommandHandler::handleUrl(const std::string &args,
+ ChatTab *tab)
+{
+ if (tab)
+ {
+ std::string url = args;
+ if (!strStartWith(url, "http"))
+ url = "http://" + url;
+ std::string str = strprintf("[@@%s|%s@@]", url.c_str(), args.c_str());
+ outStringNormal(tab, str, str);
+ }
+}
+
+void CommandHandler::handleOpen(const std::string &args,
+ ChatTab *tab A_UNUSED)
+{
+ std::string url = args;
+ if (!strStartWith(url, "http"))
+ url = "http://" + url;
+ openBrowser(url);
+}
+
#ifdef DEBUG_DUMP_LEAKS1
void showRes(std::string str, ResourceManager::Resources *res);
diff --git a/src/commandhandler.h b/src/commandhandler.h
index 478211738..10b3d328a 100644
--- a/src/commandhandler.h
+++ b/src/commandhandler.h
@@ -300,6 +300,10 @@ class CommandHandler
void handleError(const std::string &args, ChatTab *tab);
+ void handleUrl(const std::string &args, ChatTab *tab);
+
+ void handleOpen(const std::string &args, ChatTab *tab);
+
void handleDump(const std::string &args, ChatTab *tab);
void handleDumpGraphics(const std::string &args, ChatTab *tab);
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("<PEOPLE>");
mCommands.push_back("<PARTY>");
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);
}
}
diff --git a/src/utils/process.cpp b/src/utils/process.cpp
index 54f85b066..b02874b0d 100644
--- a/src/utils/process.cpp
+++ b/src/utils/process.cpp
@@ -202,8 +202,6 @@ int execFileWait(std::string pathName, std::string name,
bool execFile(std::string pathName, std::string name,
std::string arg1, std::string arg2)
{
- int status;
-
pid_t pid;
if ((pid = fork()) == -1)
{ // fork error