From a714a339ac461943236eb1992c38dfb16821d0a1 Mon Sep 17 00:00:00 2001
From: Andrei Karas <akaras@inbox.ru>
Date: Wed, 27 Aug 2014 02:14:39 +0300
Subject: Move chat command /dumpe into actions.

Also move some functions into chatutils.
---
 src/CMakeLists.txt         |  2 +
 src/Makefile.am            |  2 +
 src/actions/actions.cpp    | 21 +++++++++++
 src/actions/actions.h      |  1 +
 src/commands.cpp           | 67 +--------------------------------
 src/commands.h             |  5 +--
 src/input/inputaction.h    |  1 +
 src/input/inputactionmap.h |  9 +++++
 src/input/pages/other.cpp  |  6 +++
 src/utils/chatutils.cpp    | 92 ++++++++++++++++++++++++++++++++++++++++++++++
 src/utils/chatutils.h      | 32 ++++++++++++++++
 11 files changed, 168 insertions(+), 70 deletions(-)
 create mode 100644 src/utils/chatutils.cpp
 create mode 100644 src/utils/chatutils.h

diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
index b36cd5b73..22c5f6b4d 100644
--- a/src/CMakeLists.txt
+++ b/src/CMakeLists.txt
@@ -679,6 +679,8 @@ SET(SRCS
     utils/translation/translationmanager.h
     utils/base64.cpp
     utils/base64.h
+    utils/chatutils.cpp
+    utils/chatutils.h
     utils/checkutils.cpp
     utils/checkutils.h
     utils/copynpaste.cpp
diff --git a/src/Makefile.am b/src/Makefile.am
index 0c8cb0370..637522a85 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -796,6 +796,8 @@ manaplus_SOURCES += gui/widgets/avatarlistbox.cpp \
 	      utils/translation/translationmanager.h \
 	      utils/base64.cpp \
 	      utils/base64.h \
+	      utils/chatutils.cpp \
+	      utils/chatutils.h \
 	      utils/checkutils.cpp \
 	      utils/checkutils.h \
 	      utils/copynpaste.cpp \
diff --git a/src/actions/actions.cpp b/src/actions/actions.cpp
index 397b0225d..4717ff6ab 100644
--- a/src/actions/actions.cpp
+++ b/src/actions/actions.cpp
@@ -21,9 +21,11 @@
 #include "actions/actions.h"
 
 #include "actormanager.h"
+#include "configuration.h"
 #include "dropshortcut.h"
 #include "emoteshortcut.h"
 #include "game.h"
+#include "guild.h"
 #include "itemshortcut.h"
 #include "soundmanager.h"
 
@@ -34,6 +36,7 @@
 #include "being/playerinfo.h"
 #include "being/playerrelations.h"
 
+#include "gui/chatconsts.h"
 #include "gui/dialogsmanager.h"
 #include "gui/gui.h"
 #include "gui/popupmanager.h"
@@ -67,6 +70,7 @@
 #include "gui/windows/updaterwindow.h"
 
 #include "gui/widgets/tabs/chattab.h"
+#include "gui/widgets/tabs/chattabtype.h"
 
 #include "render/graphics.h"
 
@@ -75,6 +79,7 @@
 #include "net/gamehandler.h"
 #include "net/ipc.h"
 #include "net/net.h"
+#include "net/partyhandler.h"
 #include "net/playerhandler.h"
 #include "net/tradehandler.h"
 
@@ -84,6 +89,7 @@
 
 #include "resources/map/map.h"
 
+#include "utils/chatutils.h"
 #include "utils/gettext.h"
 #include "utils/timer.h"
 
@@ -99,6 +105,7 @@ extern ShortcutWindow *spellShortcutWindow;
 extern std::string tradePartnerName;
 extern QuitDialog *quitDialog;
 extern int start_time;
+extern char **environ;
 
 namespace Actions
 {
@@ -932,4 +939,18 @@ impHandler(dumpGraphics)
     return true;
 }
 
+impHandler0(dumpEnvironment)
+{
+    logger->log1("Start environment variables");
+    for (char **env = environ; *env; ++ env)
+        logger->log1(*env);
+    logger->log1("End environment variables");
+    if (debugChatTab)
+    {
+        // TRANSLATORS: dump environment command
+        debugChatTab->chatLog(_("Environment variables dumped"));
+    }
+    return true;
+}
+
 }  // namespace Actions
diff --git a/src/actions/actions.h b/src/actions/actions.h
index d1225a424..773d34e36 100644
--- a/src/actions/actions.h
+++ b/src/actions/actions.h
@@ -73,6 +73,7 @@ namespace Actions
     decHandler(serverUnIgnoreAll);
     decHandler(error) __attribute__ ((noreturn));
     decHandler(dumpGraphics);
+    decHandler(dumpEnvironment);
 }  // namespace Actions
 
 #undef decHandler
diff --git a/src/commands.cpp b/src/commands.cpp
index bb2bbe813..969b73c68 100644
--- a/src/commands.cpp
+++ b/src/commands.cpp
@@ -83,6 +83,7 @@
 
 #include "resources/db/itemdb.h"
 
+#include "utils/chatutils.h"
 #include "utils/delete2.h"
 #include "utils/gettext.h"
 #include "utils/process.h"
@@ -99,78 +100,12 @@ extern char **environ;
 namespace Commands
 {
 
-static void outStringNormal(ChatTab *const tab,
-                            const std::string &str,
-                            const std::string &def)
-{
-    if (!localPlayer)
-        return;
-
-    if (!tab)
-    {
-        Net::getChatHandler()->talk(str, GENERAL_CHANNEL);
-        return;
-    }
-
-    switch (tab->getType())
-    {
-        case ChatTabType::PARTY:
-        {
-            Net::getPartyHandler()->chat(str);
-            break;
-        }
-        case ChatTabType::GUILD:
-        {
-            const Guild *const guild = localPlayer->getGuild();
-            if (guild)
-            {
-                if (guild->getServerGuild())
-                {
-                    if (tmwServerVersion > 0)
-                        return;
-                    Net::getGuildHandler()->chat(guild->getId(), str);
-                }
-                else if (guildManager)
-                {
-                    guildManager->chat(str);
-                }
-            }
-            break;
-        }
-        case ChatTabType::WHISPER:
-        {
-            const WhisperTab *const whisper
-                = static_cast<const WhisperTab *const>(tab);
-            tab->chatLog(localPlayer->getName(), str);
-            Net::getChatHandler()->privateMessage(whisper->getNick(), str);
-            break;
-        }
-        default:
-            Net::getChatHandler()->talk(def, GENERAL_CHANNEL);
-            break;
-    }
-}
-
 impHandler(hack)
 {
     Net::getChatHandler()->sendRaw(event.args);
     return true;
 }
 
-impHandler0(dumpEnvironment)
-{
-    logger->log1("Start environment variables");
-    for (char **env = environ; *env; ++ env)
-        logger->log1(*env);
-    logger->log1("End environment variables");
-    if (debugChatTab)
-    {
-        // TRANSLATORS: dump environment command
-        debugChatTab->chatLog(_("Environment variables dumped"));
-    }
-    return true;
-}
-
 impHandler(dumpTests)
 {
     const std::string str = config.getStringValue("testInfo");
diff --git a/src/commands.h b/src/commands.h
index 3c9437c37..826788887 100644
--- a/src/commands.h
+++ b/src/commands.h
@@ -54,7 +54,6 @@ namespace Commands
     decHandler(hack);
     decHandler(url);
     decHandler(open);
-    decHandler(dumpEnvironment);
     decHandler(dumpTests);
     decHandler(dumpOGL);
     decHandler(dumpGL);
@@ -82,8 +81,7 @@ namespace Commands
 
 enum
 {
-    COMMAND_DUMPE = 0,
-    COMMAND_DUMPT,
+    COMMAND_DUMPT = 0,
     COMMAND_DUMPOGL,
     COMMAND_DUMPGL,
     COMMAND_DUMPMODS,
@@ -112,7 +110,6 @@ enum
 
 static const CommandInfo commands[] =
 {
-    {"dumpe", &Commands::dumpEnvironment, -1, false},
     {"dumpt", &Commands::dumpTests, -1, false},
     {"dumpogl", &Commands::dumpOGL, -1, false},
     {"dumpgl", &Commands::dumpGL, -1, false},
diff --git a/src/input/inputaction.h b/src/input/inputaction.h
index 87cb80914..388898a84 100644
--- a/src/input/inputaction.h
+++ b/src/input/inputaction.h
@@ -399,6 +399,7 @@ namespace InputAction
         SET_DROP,
         ERROR,
         DUMP_GRAPHICS,
+        DUMP_ENVIRONMENT,
         TOTAL
     };
 }  // namespace InputAction
diff --git a/src/input/inputactionmap.h b/src/input/inputactionmap.h
index 7d80d63fe..4cf34d4f3 100644
--- a/src/input/inputactionmap.h
+++ b/src/input/inputactionmap.h
@@ -3360,6 +3360,15 @@ static const InputActionData inputActionData[InputAction::TOTAL] = {
         InputAction::NO_VALUE, 50,
         InputCondition::INGAME,
         "dumpg",
+        false},
+    {"keyDumpe",
+        InputType::UNKNOWN, InputAction::NO_VALUE,
+        InputType::UNKNOWN, InputAction::NO_VALUE,
+        Input::GRP_DEFAULT,
+        &Actions::dumpEnvironment,
+        InputAction::NO_VALUE, 50,
+        InputCondition::INGAME,
+        "dumpe",
         false}
 };
 
diff --git a/src/input/pages/other.cpp b/src/input/pages/other.cpp
index 658c368f2..bf7666457 100644
--- a/src/input/pages/other.cpp
+++ b/src/input/pages/other.cpp
@@ -297,6 +297,12 @@ SetupActionData setupActionDataOther[] =
         InputAction::DUMP_GRAPHICS,
         "",
     },
+    {
+        // TRANSLATORS: input action name
+        N_("Dump environments into log"),
+        InputAction::DUMP_ENVIRONMENT,
+        "",
+    },
     {
         "",
         InputAction::NO_VALUE,
diff --git a/src/utils/chatutils.cpp b/src/utils/chatutils.cpp
new file mode 100644
index 000000000..09c2c69fb
--- /dev/null
+++ b/src/utils/chatutils.cpp
@@ -0,0 +1,92 @@
+/*
+ *  The ManaPlus Client
+ *  Copyright (C) 2012-2014  The ManaPlus Developers
+ *
+ *  This file is part of The ManaPlus Client.
+ *
+ *  This program is free software; you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License as published by
+ *  the Free Software Foundation; either version 2 of the License, or
+ *  any later version.
+ *
+ *  This program is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *  GNU General Public License for more details.
+ *
+ *  You should have received a copy of the GNU General Public License
+ *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include "utils/chatutils.h"
+
+#include "guild.h"
+#include "guildmanager.h"
+
+#include "being/localplayer.h"
+
+#include "gui/chatconsts.h"
+
+#include "gui/widgets/tabs/whispertab.h"
+#include "gui/widgets/tabs/chattabtype.h"
+
+#include "net/chathandler.h"
+#include "net/guildhandler.h"
+#include "net/net.h"
+#include "net/partyhandler.h"
+
+#include "debug.h"
+
+extern unsigned int tmwServerVersion;
+
+void outStringNormal(ChatTab *const tab,
+                     const std::string &str,
+                     const std::string &def)
+{
+    if (!localPlayer)
+        return;
+
+    if (!tab)
+    {
+        Net::getChatHandler()->talk(str, GENERAL_CHANNEL);
+        return;
+    }
+
+    switch (tab->getType())
+    {
+        case ChatTabType::PARTY:
+        {
+            Net::getPartyHandler()->chat(str);
+            break;
+        }
+        case ChatTabType::GUILD:
+        {
+            const Guild *const guild = localPlayer->getGuild();
+            if (guild)
+            {
+                if (guild->getServerGuild())
+                {
+                    if (tmwServerVersion > 0)
+                        return;
+                    Net::getGuildHandler()->chat(guild->getId(), str);
+                }
+                else if (guildManager)
+                {
+                    guildManager->chat(str);
+                }
+            }
+            break;
+        }
+        case ChatTabType::WHISPER:
+        {
+            const WhisperTab *const whisper
+                = static_cast<const WhisperTab *const>(tab);
+            tab->chatLog(localPlayer->getName(), str);
+            Net::getChatHandler()->privateMessage(whisper->getNick(), str);
+            break;
+        }
+        default:
+            Net::getChatHandler()->talk(def, GENERAL_CHANNEL);
+            break;
+    }
+}
diff --git a/src/utils/chatutils.h b/src/utils/chatutils.h
new file mode 100644
index 000000000..976110d9c
--- /dev/null
+++ b/src/utils/chatutils.h
@@ -0,0 +1,32 @@
+/*
+ *  The ManaPlus Client
+ *  Copyright (C) 2011-2014  The ManaPlus Developers
+ *
+ *  This file is part of The ManaPlus Client.
+ *
+ *  This program is free software; you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License as published by
+ *  the Free Software Foundation; either version 2 of the License, or
+ *  any later version.
+ *
+ *  This program is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *  GNU General Public License for more details.
+ *
+ *  You should have received a copy of the GNU General Public License
+ *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef UTILS_CHATUTILS_H
+#define UTILS_CHATUTILS_H
+
+#include <string>
+
+class ChatTab;
+
+void outStringNormal(ChatTab *const tab,
+                     const std::string &str,
+                     const std::string &def);
+
+#endif  // ACTIONS_ACTIONS_H
-- 
cgit v1.2.3-70-g09d2